本文整理汇总了Java中com.android.dx.rop.annotation.Annotation.add方法的典型用法代码示例。如果您正苦于以下问题:Java Annotation.add方法的具体用法?Java Annotation.add怎么用?Java Annotation.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.android.dx.rop.annotation.Annotation
的用法示例。
在下文中一共展示了Annotation.add方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: translateAnnotationDefaults
import com.android.dx.rop.annotation.Annotation; //导入方法依赖的package包/类
/**
* Gets the {@code AnnotationDefault} attributes out of a
* given class, if any, reforming them as an
* {@code AnnotationDefault} annotation.
*
* @param cf {@code non-null;} the class in question
* @return {@code null-ok;} an appropriately-constructed
* {@code AnnotationDefault} annotation, if there were any
* annotation defaults in the class, or {@code null} if not
*/
private static Annotation translateAnnotationDefaults(DirectClassFile cf) {
CstType thisClass = cf.getThisClass();
MethodList methods = cf.getMethods();
int sz = methods.size();
Annotation result =
new Annotation(thisClass, AnnotationVisibility.EMBEDDED);
boolean any = false;
for (int i = 0; i < sz; i++) {
Method one = methods.get(i);
AttributeList attribs = one.getAttributes();
AttAnnotationDefault oneDefault = (AttAnnotationDefault)
attribs.findFirst(AttAnnotationDefault.ATTRIBUTE_NAME);
if (oneDefault != null) {
NameValuePair pair = new NameValuePair(
one.getNat().getName(),
oneDefault.getValue());
result.add(pair);
any = true;
}
}
if (! any) {
return null;
}
result.setImmutable();
return AnnotationUtils.makeAnnotationDefault(result);
}
示例2: parseAnnotation
import com.android.dx.rop.annotation.Annotation; //导入方法依赖的package包/类
/**
* Parses a single annotation.
*
* @param visibility {@code non-null;} visibility of the parsed annotation
* @return {@code non-null;} the parsed annotation
*/
private Annotation parseAnnotation(AnnotationVisibility visibility)
throws IOException {
requireLength(4);
int typeIndex = input.readUnsignedShort();
int numElements = input.readUnsignedShort();
CstString typeString = (CstString) pool.get(typeIndex);
CstType type = new CstType(Type.intern(typeString.getString()));
if (observer != null) {
parsed(2, "type: " + type.toHuman());
parsed(2, "num_elements: " + numElements);
}
Annotation annotation = new Annotation(type, visibility);
for (int i = 0; i < numElements; i++) {
if (observer != null) {
parsed(0, "elements[" + i + "]:");
changeIndent(1);
}
NameValuePair element = parseElement();
annotation.add(element);
if (observer != null) {
changeIndent(-1);
}
}
annotation.setImmutable();
return annotation;
}
示例3: addToMethod
import com.android.dx.rop.annotation.Annotation; //导入方法依赖的package包/类
/**
* Add this annotation to a method.
*
* @param dexMaker DexMaker instance.
* @param method Method to be added to.
*/
public void addToMethod(DexMaker dexMaker, MethodId<?, ?> method) {
if (annotatedElement != ElementType.METHOD) {
throw new IllegalStateException("This annotation is not for method");
}
if (method.declaringType != declaringType) {
throw new IllegalArgumentException("Method" + method + "'s declaring type is inconsistent with" + this);
}
ClassDefItem classDefItem = dexMaker.getTypeDeclaration(declaringType).toClassDefItem();
if (classDefItem == null) {
throw new NullPointerException("No class defined item is found");
} else {
CstMethodRef cstMethodRef = method.constant;
if (cstMethodRef == null) {
throw new NullPointerException("Method reference is NULL");
} else {
// Generate CstType
CstType cstType = CstType.intern(type.ropType);
// Generate Annotation
Annotation annotation = new Annotation(cstType, AnnotationVisibility.RUNTIME);
// Add generated annotation
Annotations annotations = new Annotations();
for (NameValuePair nvp : elements.values()) {
annotation.add(nvp);
}
annotations.add(annotation);
classDefItem.addMethodAnnotations(cstMethodRef, annotations, dexMaker.getDexFile());
}
}
}