com.android.dx.rop.annotation.AnnotationVisibility Java Examples
The following examples show how to use
com.android.dx.rop.annotation.AnnotationVisibility.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AnnotationParser.java From Box with Apache License 2.0 | 6 votes |
/** * Parses a parameter annotation attribute. * * @param visibility {@code non-null;} visibility of the parsed annotations * @return {@code non-null;} the parsed list of lists of annotations */ public AnnotationsList parseParameterAttribute( AnnotationVisibility visibility) { AnnotationsList result; try { result = parseAnnotationsList(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; }
Example #2
Source File: AnnotationParser.java From J2ME-Loader with Apache License 2.0 | 6 votes |
/** * Parses a parameter annotation attribute. * * @param visibility {@code non-null;} visibility of the parsed annotations * @return {@code non-null;} the parsed list of lists of annotations */ public AnnotationsList parseParameterAttribute( AnnotationVisibility visibility) { AnnotationsList result; try { result = parseAnnotationsList(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; }
Example #3
Source File: AnnotationParser.java From J2ME-Loader with Apache License 2.0 | 6 votes |
/** * 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; }
Example #4
Source File: AnnotationParser.java From Box with Apache License 2.0 | 6 votes |
/** * 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; }
Example #5
Source File: AnnotationParser.java From buck with Apache License 2.0 | 6 votes |
/** * Parses a parameter annotation attribute. * * @param visibility {@code non-null;} visibility of the parsed annotations * @return {@code non-null;} the parsed list of lists of annotations */ public AnnotationsList parseParameterAttribute( AnnotationVisibility visibility) { AnnotationsList result; try { result = parseAnnotationsList(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; }
Example #6
Source File: AnnotationParser.java From buck with Apache License 2.0 | 6 votes |
/** * 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; }
Example #7
Source File: AnnotationParser.java From Box with Apache License 2.0 | 6 votes |
/** * Parses a parameter annotation attribute. * * @param visibility {@code non-null;} visibility of the parsed annotations * @return {@code non-null;} the parsed list of lists of annotations */ public AnnotationsList parseParameterAttribute( AnnotationVisibility visibility) { AnnotationsList result; try { result = parseAnnotationsList(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; }
Example #8
Source File: AnnotationParser.java From Box with Apache License 2.0 | 6 votes |
/** * 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; }
Example #9
Source File: AnnotationId.java From dexmaker with Apache License 2.0 | 5 votes |
/** * 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.equals(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()); } } }
Example #10
Source File: StdAttributeFactory.java From buck with Apache License 2.0 | 5 votes |
/** * Parses a {@code RuntimeVisibleParameterAnnotations} attribute. */ private Attribute runtimeVisibleParameterAnnotations(DirectClassFile cf, int offset, int length, ParseObserver observer) { if (length < 2) { throwSeverelyTruncated(); } AnnotationParser ap = new AnnotationParser(cf, offset, length, observer); AnnotationsList list = ap.parseParameterAttribute(AnnotationVisibility.RUNTIME); return new AttRuntimeVisibleParameterAnnotations(list, length); }
Example #11
Source File: AnnotationParser.java From J2ME-Loader with Apache License 2.0 | 5 votes |
/** * 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; }
Example #12
Source File: AnnotationParser.java From J2ME-Loader with Apache License 2.0 | 5 votes |
/** * 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; }
Example #13
Source File: AnnotationParser.java From J2ME-Loader with Apache License 2.0 | 5 votes |
/** * 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; }
Example #14
Source File: StdAttributeFactory.java From J2ME-Loader with Apache License 2.0 | 5 votes |
/** * Parses a {@code RuntimeInvisibleAnnotations} attribute. */ private Attribute runtimeInvisibleAnnotations(DirectClassFile cf, int offset, int length, ParseObserver observer) { if (length < 2) { throwSeverelyTruncated(); } AnnotationParser ap = new AnnotationParser(cf, offset, length, observer); Annotations annotations = ap.parseAnnotationAttribute(AnnotationVisibility.BUILD); return new AttRuntimeInvisibleAnnotations(annotations, length); }
Example #15
Source File: StdAttributeFactory.java From J2ME-Loader with Apache License 2.0 | 5 votes |
/** * Parses a {@code RuntimeVisibleAnnotations} attribute. */ private Attribute runtimeVisibleAnnotations(DirectClassFile cf, int offset, int length, ParseObserver observer) { if (length < 2) { throwSeverelyTruncated(); } AnnotationParser ap = new AnnotationParser(cf, offset, length, observer); Annotations annotations = ap.parseAnnotationAttribute(AnnotationVisibility.RUNTIME); return new AttRuntimeVisibleAnnotations(annotations, length); }
Example #16
Source File: StdAttributeFactory.java From J2ME-Loader with Apache License 2.0 | 5 votes |
/** * Parses a {@code RuntimeInvisibleParameterAnnotations} attribute. */ private Attribute runtimeInvisibleParameterAnnotations(DirectClassFile cf, int offset, int length, ParseObserver observer) { if (length < 2) { throwSeverelyTruncated(); } AnnotationParser ap = new AnnotationParser(cf, offset, length, observer); AnnotationsList list = ap.parseParameterAttribute(AnnotationVisibility.BUILD); return new AttRuntimeInvisibleParameterAnnotations(list, length); }
Example #17
Source File: StdAttributeFactory.java From J2ME-Loader with Apache License 2.0 | 5 votes |
/** * Parses a {@code RuntimeVisibleParameterAnnotations} attribute. */ private Attribute runtimeVisibleParameterAnnotations(DirectClassFile cf, int offset, int length, ParseObserver observer) { if (length < 2) { throwSeverelyTruncated(); } AnnotationParser ap = new AnnotationParser(cf, offset, length, observer); AnnotationsList list = ap.parseParameterAttribute(AnnotationVisibility.RUNTIME); return new AttRuntimeVisibleParameterAnnotations(list, length); }
Example #18
Source File: StdAttributeFactory.java From buck with Apache License 2.0 | 5 votes |
/** * Parses a {@code RuntimeInvisibleAnnotations} attribute. */ private Attribute runtimeInvisibleAnnotations(DirectClassFile cf, int offset, int length, ParseObserver observer) { if (length < 2) { throwSeverelyTruncated(); } AnnotationParser ap = new AnnotationParser(cf, offset, length, observer); Annotations annotations = ap.parseAnnotationAttribute(AnnotationVisibility.BUILD); return new AttRuntimeInvisibleAnnotations(annotations, length); }
Example #19
Source File: AttributeTranslator.java From buck with Apache License 2.0 | 5 votes |
/** * 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); }
Example #20
Source File: AnnotationItem.java From Box with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @Override protected void writeTo0(DexFile file, AnnotatedOutput out) { boolean annotates = out.annotates(); AnnotationVisibility visibility = annotation.getVisibility(); if (annotates) { out.annotate(0, offsetString() + " annotation"); out.annotate(1, " visibility: VISBILITY_" + visibility); } switch (visibility) { case BUILD: out.writeByte(VISIBILITY_BUILD); break; case RUNTIME: out.writeByte(VISIBILITY_RUNTIME); break; case SYSTEM: out.writeByte(VISIBILITY_SYSTEM); break; default: { // EMBEDDED shouldn't appear at the top level. throw new RuntimeException("shouldn't happen"); } } if (annotates) { /* * The output is to be annotated, so redo the work previously * done by place0(), except this time annotations will actually * get emitted. */ ValueEncoder encoder = new ValueEncoder(file, out); encoder.writeAnnotation(annotation, true); } else { out.write(encodedForm); } }
Example #21
Source File: AnnotationItem.java From buck with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @Override protected void writeTo0(DexFile file, AnnotatedOutput out) { boolean annotates = out.annotates(); AnnotationVisibility visibility = annotation.getVisibility(); if (annotates) { out.annotate(0, offsetString() + " annotation"); out.annotate(1, " visibility: VISBILITY_" + visibility); } switch (visibility) { case BUILD: out.writeByte(VISIBILITY_BUILD); break; case RUNTIME: out.writeByte(VISIBILITY_RUNTIME); break; case SYSTEM: out.writeByte(VISIBILITY_SYSTEM); break; default: { // EMBEDDED shouldn't appear at the top level. throw new RuntimeException("shouldn't happen"); } } if (annotates) { /* * The output is to be annotated, so redo the work previously * done by place0(), except this time annotations will actually * get emitted. */ ValueEncoder encoder = new ValueEncoder(file, out); encoder.writeAnnotation(annotation, true); } else { out.write(encodedForm); } }
Example #22
Source File: StdAttributeFactory.java From buck with Apache License 2.0 | 5 votes |
/** * Parses a {@code RuntimeInvisibleParameterAnnotations} attribute. */ private Attribute runtimeInvisibleParameterAnnotations(DirectClassFile cf, int offset, int length, ParseObserver observer) { if (length < 2) { throwSeverelyTruncated(); } AnnotationParser ap = new AnnotationParser(cf, offset, length, observer); AnnotationsList list = ap.parseParameterAttribute(AnnotationVisibility.BUILD); return new AttRuntimeInvisibleParameterAnnotations(list, length); }
Example #23
Source File: StdAttributeFactory.java From buck with Apache License 2.0 | 5 votes |
/** * Parses a {@code RuntimeVisibleAnnotations} attribute. */ private Attribute runtimeVisibleAnnotations(DirectClassFile cf, int offset, int length, ParseObserver observer) { if (length < 2) { throwSeverelyTruncated(); } AnnotationParser ap = new AnnotationParser(cf, offset, length, observer); Annotations annotations = ap.parseAnnotationAttribute(AnnotationVisibility.RUNTIME); return new AttRuntimeVisibleAnnotations(annotations, length); }
Example #24
Source File: AnnotationParser.java From buck with Apache License 2.0 | 5 votes |
/** * 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; }
Example #25
Source File: AnnotationParser.java From buck with Apache License 2.0 | 5 votes |
/** * 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; }
Example #26
Source File: AnnotationParser.java From buck with Apache License 2.0 | 5 votes |
/** * 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; }
Example #27
Source File: AnnotationParser.java From Box with Apache License 2.0 | 5 votes |
/** * 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; }
Example #28
Source File: AttributeTranslator.java From Box with Apache License 2.0 | 5 votes |
/** * 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); }
Example #29
Source File: AnnotationParser.java From Box with Apache License 2.0 | 5 votes |
/** * 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; }
Example #30
Source File: AnnotationParser.java From Box with Apache License 2.0 | 5 votes |
/** * 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; }