本文整理汇总了Java中com.android.dx.rop.annotation.Annotations类的典型用法代码示例。如果您正苦于以下问题:Java Annotations类的具体用法?Java Annotations怎么用?Java Annotations使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Annotations类属于com.android.dx.rop.annotation包,在下文中一共展示了Annotations类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getAnnotations0
import com.android.dx.rop.annotation.Annotations; //导入依赖的package包/类
/**
* Helper method for {@link #getAnnotations} which just gets the
* existing annotations, per se.
*
* @param attribs {@code non-null;} the attributes list to search in
* @return {@code non-null;} the set of annotations, which may be empty
*/
private static Annotations getAnnotations0(AttributeList attribs) {
AttRuntimeVisibleAnnotations visible =
(AttRuntimeVisibleAnnotations)
attribs.findFirst(AttRuntimeVisibleAnnotations.ATTRIBUTE_NAME);
AttRuntimeInvisibleAnnotations invisible =
(AttRuntimeInvisibleAnnotations)
attribs.findFirst(AttRuntimeInvisibleAnnotations.ATTRIBUTE_NAME);
if (visible == null) {
if (invisible == null) {
return Annotations.EMPTY;
}
return invisible.getAnnotations();
}
if (invisible == null) {
return visible.getAnnotations();
}
// Both are non-null, so combine them.
return Annotations.combine(visible.getAnnotations(),
invisible.getAnnotations());
}
示例2: BaseAnnotations
import com.android.dx.rop.annotation.Annotations; //导入依赖的package包/类
/**
* Constructs an instance.
*
* @param attributeName {@code non-null;} the name of the attribute
* @param annotations {@code non-null;} the list of annotations
* @param byteLength {@code >= 0;} attribute data length in the original
* classfile (not including the attribute header)
*/
public BaseAnnotations(String attributeName, Annotations annotations,
int byteLength) {
super(attributeName);
try {
if (annotations.isMutable()) {
throw new MutabilityException("annotations.isMutable()");
}
} catch (NullPointerException ex) {
// Translate the exception.
throw new NullPointerException("annotations == null");
}
this.annotations = annotations;
this.byteLength = byteLength;
}
示例3: parseAnnotationAttribute
import com.android.dx.rop.annotation.Annotations; //导入依赖的package包/类
/**
* Parses an annotation attribute, per se.
*
* @param visibility {@code non-null;} visibility of the parsed annotations
* @return {@code non-null;} the list of annotations read from the attribute
* data
*/
public Annotations parseAnnotationAttribute(
AnnotationVisibility visibility) {
Annotations result;
try {
result = parseAnnotations(visibility);
if (input.available() != 0) {
throw new ParseException("extra data in attribute");
}
} catch (IOException ex) {
// ByteArray.MyDataInputStream should never throw.
throw new RuntimeException("shouldn't happen", ex);
}
return result;
}
示例4: getAnnotations
import com.android.dx.rop.annotation.Annotations; //导入依赖的package包/类
/**
* Gets the annotations out of a given {@link AttributeList}. This
* combines both visible and invisible annotations into a single
* result set and also adds in a system annotation for the
* {@code Signature} attribute if present.
*
* @param attribs {@code non-null;} the attributes list to search in
* @return {@code non-null;} the set of annotations, which may be empty
*/
public static Annotations getAnnotations(AttributeList attribs) {
Annotations result = getAnnotations0(attribs);
Annotation signature = getSignature(attribs);
if (signature != null) {
result = Annotations.combine(result, signature);
}
return result;
}
示例5: getClassAnnotations
import com.android.dx.rop.annotation.Annotations; //导入依赖的package包/类
/**
* Gets the annotations out of a given class, similar to {@link
* #getAnnotations}, also including annotations for translations
* of class-level attributes {@code EnclosingMethod} and
* {@code InnerClasses}, if present. Additionally, if the
* class is an annotation class, then this also includes a
* representation of all the {@code AnnotationDefault}
* values.
*
* @param cf {@code non-null;} the class in question
* @param args {@code non-null;} the high-level options
* @return {@code non-null;} the set of annotations, which may be empty
*/
public static Annotations getClassAnnotations(DirectClassFile cf,
CfOptions args) {
CstType thisClass = cf.getThisClass();
AttributeList attribs = cf.getAttributes();
Annotations result = getAnnotations(attribs);
Annotation enclosingMethod = translateEnclosingMethod(attribs);
try {
Annotations innerClassAnnotations =
translateInnerClasses(thisClass, attribs,
enclosingMethod == null);
if (innerClassAnnotations != null) {
result = Annotations.combine(result, innerClassAnnotations);
}
} catch (Warning warn) {
args.warn.println("warning: " + warn.getMessage());
}
if (enclosingMethod != null) {
result = Annotations.combine(result, enclosingMethod);
}
if (AccessFlags.isAnnotation(cf.getAccessFlags())) {
Annotation annotationDefault =
translateAnnotationDefaults(cf);
if (annotationDefault != null) {
result = Annotations.combine(result, annotationDefault);
}
}
return result;
}
示例6: getMethodAnnotations
import com.android.dx.rop.annotation.Annotations; //导入依赖的package包/类
/**
* Gets the annotations out of a given method, similar to {@link
* #getAnnotations}, also including an annotation for the translation
* of the method-specific attribute {@code Exceptions}.
*
* @param method {@code non-null;} the method in question
* @return {@code non-null;} the set of annotations, which may be empty
*/
public static Annotations getMethodAnnotations(Method method) {
Annotations result = getAnnotations(method.getAttributes());
TypeList exceptions = getExceptions(method);
if (exceptions.size() != 0) {
Annotation throwsAnnotation =
AnnotationUtils.makeThrows(exceptions);
result = Annotations.combine(result, throwsAnnotation);
}
return result;
}
示例7: AnnotationSetItem
import com.android.dx.rop.annotation.Annotations; //导入依赖的package包/类
/**
* Constructs an instance.
*
* @param annotations {@code non-null;} set of annotations
* @param dexFile {@code non-null;} dex output
*/
public AnnotationSetItem(Annotations annotations, DexFile dexFile) {
super(ALIGNMENT, writeSize(annotations));
this.annotations = annotations;
this.items = new AnnotationItem[annotations.size()];
int at = 0;
for (Annotation a : annotations.getAnnotations()) {
items[at] = new AnnotationItem(a, dexFile);
at++;
}
}
示例8: writeSize
import com.android.dx.rop.annotation.Annotations; //导入依赖的package包/类
/**
* Gets the write size for the given set.
*
* @param annotations {@code non-null;} the set
* @return {@code > 0;} the write size
*/
private static int writeSize(Annotations annotations) {
// This includes an int size at the start of the list.
try {
return (annotations.size() * ENTRY_WRITE_SIZE) + 4;
} catch (NullPointerException ex) {
// Elucidate the exception.
throw new NullPointerException("list == null");
}
}
示例9: setClassAnnotations
import com.android.dx.rop.annotation.Annotations; //导入依赖的package包/类
/**
* Sets the direct annotations on this instance. These are annotations
* made on the class, per se, as opposed to on one of its members.
* It is only valid to call this method at most once per instance.
*
* @param annotations {@code non-null;} annotations to set for this class
* @param dexFile {@code non-null;} dex output
*/
public void setClassAnnotations(Annotations annotations, DexFile dexFile) {
if (annotations == null) {
throw new NullPointerException("annotations == null");
}
if (classAnnotations != null) {
throw new UnsupportedOperationException(
"class annotations already set");
}
classAnnotations = new AnnotationSetItem(annotations, dexFile);
}
示例10: addFieldAnnotations
import com.android.dx.rop.annotation.Annotations; //导入依赖的package包/类
/**
* Adds a field annotations item to this instance.
*
* @param field {@code non-null;} field in question
* @param annotations {@code non-null;} associated annotations to add
* @param dexFile {@code non-null;} dex output
*/
public void addFieldAnnotations(CstFieldRef field,
Annotations annotations, DexFile dexFile) {
if (fieldAnnotations == null) {
fieldAnnotations = new ArrayList<FieldAnnotationStruct>();
}
fieldAnnotations.add(new FieldAnnotationStruct(field,
new AnnotationSetItem(annotations, dexFile)));
}
示例11: addMethodAnnotations
import com.android.dx.rop.annotation.Annotations; //导入依赖的package包/类
/**
* Adds a method annotations item to this instance.
*
* @param method {@code non-null;} method in question
* @param annotations {@code non-null;} associated annotations to add
* @param dexFile {@code non-null;} dex output
*/
public void addMethodAnnotations(CstMethodRef method,
Annotations annotations, DexFile dexFile) {
if (methodAnnotations == null) {
methodAnnotations = new ArrayList<MethodAnnotationStruct>();
}
methodAnnotations.add(new MethodAnnotationStruct(method,
new AnnotationSetItem(annotations, dexFile)));
}
示例12: getMethodAnnotations
import com.android.dx.rop.annotation.Annotations; //导入依赖的package包/类
/**
* Gets the method annotations for a given method, if any. This is
* meant for use by debugging / dumping code.
*
* @param method {@code non-null;} the method
* @return {@code null-ok;} the method annotations, if any
*/
public Annotations getMethodAnnotations(CstMethodRef method) {
if (methodAnnotations == null) {
return null;
}
for (MethodAnnotationStruct item : methodAnnotations) {
if (item.getMethod().equals(method)) {
return item.getAnnotations();
}
}
return null;
}
示例13: ParameterAnnotationStruct
import com.android.dx.rop.annotation.Annotations; //导入依赖的package包/类
/**
* Constructs an instance.
*
* @param method {@code non-null;} the method in question
* @param annotationsList {@code non-null;} the associated annotations list
* @param dexFile {@code non-null;} dex output
*/
public ParameterAnnotationStruct(CstMethodRef method,
AnnotationsList annotationsList, DexFile dexFile) {
if (method == null) {
throw new NullPointerException("method == null");
}
if (annotationsList == null) {
throw new NullPointerException("annotationsList == null");
}
this.method = method;
this.annotationsList = annotationsList;
/*
* Construct an item for the annotations list. TODO: This
* requires way too much copying; fix it.
*/
int size = annotationsList.size();
ArrayList<AnnotationSetRefItem> arrayList = new
ArrayList<AnnotationSetRefItem>(size);
for (int i = 0; i < size; i++) {
Annotations annotations = annotationsList.get(i);
AnnotationSetItem item = new AnnotationSetItem(annotations, dexFile);
arrayList.add(new AnnotationSetRefItem(item));
}
this.annotationsItem = new UniformListItem<AnnotationSetRefItem>(
ItemType.TYPE_ANNOTATION_SET_REF_LIST, arrayList);
}
示例14: parseAnnotationsList
import com.android.dx.rop.annotation.Annotations; //导入依赖的package包/类
/**
* Parses a list of annotation lists.
*
* @param visibility {@code non-null;} visibility of the parsed annotations
* @return {@code non-null;} the list of annotation lists read from the attribute
* data
*/
private AnnotationsList parseAnnotationsList(
AnnotationVisibility visibility) throws IOException {
int count = input.readUnsignedByte();
if (observer != null) {
parsed(1, "num_parameters: " + Hex.u1(count));
}
AnnotationsList outerList = new AnnotationsList(count);
for (int i = 0; i < count; i++) {
if (observer != null) {
parsed(0, "parameter_annotations[" + i + "]:");
changeIndent(1);
}
Annotations annotations = parseAnnotations(visibility);
outerList.set(i, annotations);
if (observer != null) {
observer.changeIndent(-1);
}
}
outerList.setImmutable();
return outerList;
}
示例15: parseAnnotations
import com.android.dx.rop.annotation.Annotations; //导入依赖的package包/类
/**
* Parses an annotation list.
*
* @param visibility {@code non-null;} visibility of the parsed annotations
* @return {@code non-null;} the list of annotations read from the attribute
* data
*/
private Annotations parseAnnotations(AnnotationVisibility visibility)
throws IOException {
int count = input.readUnsignedShort();
if (observer != null) {
parsed(2, "num_annotations: " + Hex.u2(count));
}
Annotations annotations = new Annotations();
for (int i = 0; i < count; i++) {
if (observer != null) {
parsed(0, "annotations[" + i + "]:");
changeIndent(1);
}
Annotation annotation = parseAnnotation(visibility);
annotations.add(annotation);
if (observer != null) {
observer.changeIndent(-1);
}
}
annotations.setImmutable();
return annotations;
}