com.android.dx.cf.iface.AttributeList Java Examples

The following examples show how to use com.android.dx.cf.iface.AttributeList. 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: AttributeTranslator.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
    Annotation sourceDebugExtension = getSourceDebugExtension(attribs);

    if (signature != null) {
        result = Annotations.combine(result, signature);
    }

    if (sourceDebugExtension != null) {
        result = Annotations.combine(result, sourceDebugExtension);
    }

    return result;
}
 
Example #2
Source File: AttributeTranslator.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
    Annotation sourceDebugExtension = getSourceDebugExtension(attribs);

    if (signature != null) {
        result = Annotations.combine(result, signature);
    }

    if (sourceDebugExtension != null) {
        result = Annotations.combine(result, sourceDebugExtension);
    }

    return result;
}
 
Example #3
Source File: AttributeTranslator.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * 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());
}
 
Example #4
Source File: AttributeTranslator.java    From J2ME-Loader with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the {@code EnclosingMethod} attribute out of a given
 * {@link AttributeList}, if any, translating it to an annotation.
 * If the class really has an enclosing method, this returns an
 * {@code EnclosingMethod} annotation; if not, this returns
 * an {@code EnclosingClass} annotation.
 *
 * @param attribs {@code non-null;} the attributes list to search in
 * @return {@code null-ok;} the converted {@code EnclosingMethod} or
 * {@code EnclosingClass} annotation, if there was an
 * attribute to translate
 */
private static Annotation translateEnclosingMethod(AttributeList attribs) {
    AttEnclosingMethod enclosingMethod = (AttEnclosingMethod)
        attribs.findFirst(AttEnclosingMethod.ATTRIBUTE_NAME);

    if (enclosingMethod == null) {
        return null;
    }

    CstType enclosingClass = enclosingMethod.getEnclosingClass();
    CstNat nat = enclosingMethod.getMethod();

    if (nat == null) {
        /*
         * Dalvik doesn't use EnclosingMethod annotations unless
         * there really is an enclosing method. Anonymous classes
         * are unambiguously identified by having an InnerClass
         * annotation with an empty name along with an appropriate
         * EnclosingClass.
         */
        return AnnotationUtils.makeEnclosingClass(enclosingClass);
    }

    return AnnotationUtils.makeEnclosingMethod(
            new CstMethodRef(enclosingClass, nat));
}
 
Example #5
Source File: AttributeTranslator.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the {@code EnclosingMethod} attribute out of a given
 * {@link AttributeList}, if any, translating it to an annotation.
 * If the class really has an enclosing method, this returns an
 * {@code EnclosingMethod} annotation; if not, this returns
 * an {@code EnclosingClass} annotation.
 *
 * @param attribs {@code non-null;} the attributes list to search in
 * @return {@code null-ok;} the converted {@code EnclosingMethod} or
 * {@code EnclosingClass} annotation, if there was an
 * attribute to translate
 */
private static Annotation translateEnclosingMethod(AttributeList attribs) {
    AttEnclosingMethod enclosingMethod = (AttEnclosingMethod)
        attribs.findFirst(AttEnclosingMethod.ATTRIBUTE_NAME);

    if (enclosingMethod == null) {
        return null;
    }

    CstType enclosingClass = enclosingMethod.getEnclosingClass();
    CstNat nat = enclosingMethod.getMethod();

    if (nat == null) {
        /*
         * Dalvik doesn't use EnclosingMethod annotations unless
         * there really is an enclosing method. Anonymous classes
         * are unambiguously identified by having an InnerClass
         * annotation with an empty name along with an appropriate
         * EnclosingClass.
         */
        return AnnotationUtils.makeEnclosingClass(enclosingClass);
    }

    return AnnotationUtils.makeEnclosingMethod(
            new CstMethodRef(enclosingClass, nat));
}
 
Example #6
Source File: AttributeTranslator.java    From buck with Apache License 2.0 6 votes vote down vote up
/**
 * 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());
}
 
Example #7
Source File: AttributeTranslator.java    From J2ME-Loader with Apache License 2.0 6 votes vote down vote up
/**
 * 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());
}
 
Example #8
Source File: AttributeTranslator.java    From buck with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the {@code EnclosingMethod} attribute out of a given
 * {@link AttributeList}, if any, translating it to an annotation.
 * If the class really has an enclosing method, this returns an
 * {@code EnclosingMethod} annotation; if not, this returns
 * an {@code EnclosingClass} annotation.
 *
 * @param attribs {@code non-null;} the attributes list to search in
 * @return {@code null-ok;} the converted {@code EnclosingMethod} or
 * {@code EnclosingClass} annotation, if there was an
 * attribute to translate
 */
private static Annotation translateEnclosingMethod(AttributeList attribs) {
    AttEnclosingMethod enclosingMethod = (AttEnclosingMethod)
        attribs.findFirst(AttEnclosingMethod.ATTRIBUTE_NAME);

    if (enclosingMethod == null) {
        return null;
    }

    CstType enclosingClass = enclosingMethod.getEnclosingClass();
    CstNat nat = enclosingMethod.getMethod();

    if (nat == null) {
        /*
         * Dalvik doesn't use EnclosingMethod annotations unless
         * there really is an enclosing method. Anonymous classes
         * are unambiguously identified by having an InnerClass
         * annotation with an empty name along with an appropriate
         * EnclosingClass.
         */
        return AnnotationUtils.makeEnclosingClass(enclosingClass);
    }

    return AnnotationUtils.makeEnclosingMethod(
            new CstMethodRef(enclosingClass, nat));
}
 
Example #9
Source File: AttributeTranslator.java    From J2ME-Loader with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
    Annotation sourceDebugExtension = getSourceDebugExtension(attribs);

    if (signature != null) {
        result = Annotations.combine(result, signature);
    }

    if (sourceDebugExtension != null) {
        result = Annotations.combine(result, sourceDebugExtension);
    }

    return result;
}
 
Example #10
Source File: AttributeTranslator.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the {@code EnclosingMethod} attribute out of a given
 * {@link AttributeList}, if any, translating it to an annotation.
 * If the class really has an enclosing method, this returns an
 * {@code EnclosingMethod} annotation; if not, this returns
 * an {@code EnclosingClass} annotation.
 *
 * @param attribs {@code non-null;} the attributes list to search in
 * @return {@code null-ok;} the converted {@code EnclosingMethod} or
 * {@code EnclosingClass} annotation, if there was an
 * attribute to translate
 */
private static Annotation translateEnclosingMethod(AttributeList attribs) {
    AttEnclosingMethod enclosingMethod = (AttEnclosingMethod)
        attribs.findFirst(AttEnclosingMethod.ATTRIBUTE_NAME);

    if (enclosingMethod == null) {
        return null;
    }

    CstType enclosingClass = enclosingMethod.getEnclosingClass();
    CstNat nat = enclosingMethod.getMethod();

    if (nat == null) {
        /*
         * Dalvik doesn't use EnclosingMethod annotations unless
         * there really is an enclosing method. Anonymous classes
         * are unambiguously identified by having an InnerClass
         * annotation with an empty name along with an appropriate
         * EnclosingClass.
         */
        return AnnotationUtils.makeEnclosingClass(enclosingClass);
    }

    return AnnotationUtils.makeEnclosingMethod(
            new CstMethodRef(enclosingClass, nat));
}
 
Example #11
Source File: AttributeTranslator.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * 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());
}
 
Example #12
Source File: AttributeTranslator.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
/**
 * 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 #13
Source File: AttributeTranslator.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #14
Source File: DirectClassFile.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
   @Override
public CstString getSourceFile() {
       AttributeList attribs = getAttributes();
       Attribute attSf = attribs.findFirst(AttSourceFile.ATTRIBUTE_NAME);

       if (attSf instanceof AttSourceFile) {
           return ((AttSourceFile) attSf).getSourceFile();
       }

       return null;
   }
 
Example #15
Source File: MethodListParser.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
protected Member set(int n, int accessFlags, CstNat nat,
                     AttributeList attributes) {
    StdMethod meth =
        new StdMethod(getDefiner(), accessFlags, nat, attributes);

    methods.set(n, meth);
    return meth;
}
 
Example #16
Source File: FieldListParser.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
protected Member set(int n, int accessFlags, CstNat nat,
                     AttributeList attributes) {
    StdField field =
        new StdField(getDefiner(), accessFlags, nat, attributes);

    fields.set(n, field);
    return field;
}
 
Example #17
Source File: AttributeTranslator.java    From buck with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the {@code Signature} attribute out of a given
 * {@link AttributeList}, if any, translating it to an annotation.
 *
 * @param attribs {@code non-null;} the attributes list to search in
 * @return {@code null-ok;} the converted {@code Signature} annotation,
 * if there was an attribute to translate
 */
private static Annotation getSignature(AttributeList attribs) {
    AttSignature signature = (AttSignature)
        attribs.findFirst(AttSignature.ATTRIBUTE_NAME);

    if (signature == null) {
        return null;
    }

    return AnnotationUtils.makeSignature(signature.getSignature());
}
 
Example #18
Source File: AttributeTranslator.java    From buck with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the parameter annotations out of a given method. This
 * combines both visible and invisible annotations into a single
 * result set.
 *
 * @param method {@code non-null;} the method in question
 * @return {@code non-null;} the list of annotation sets, which may be
 * empty
 */
public static AnnotationsList getParameterAnnotations(Method method) {
    AttributeList attribs = method.getAttributes();
    AttRuntimeVisibleParameterAnnotations visible =
        (AttRuntimeVisibleParameterAnnotations)
        attribs.findFirst(
                AttRuntimeVisibleParameterAnnotations.ATTRIBUTE_NAME);
    AttRuntimeInvisibleParameterAnnotations invisible =
        (AttRuntimeInvisibleParameterAnnotations)
        attribs.findFirst(
                AttRuntimeInvisibleParameterAnnotations.ATTRIBUTE_NAME);

    if (visible == null) {
        if (invisible == null) {
            return AnnotationsList.EMPTY;
        }
        return invisible.getParameterAnnotations();
    }

    if (invisible == null) {
        return visible.getParameterAnnotations();
    }

    // Both are non-null, so combine them.

    return AnnotationsList.combine(visible.getParameterAnnotations(),
            invisible.getParameterAnnotations());
}
 
Example #19
Source File: AttributeTranslator.java    From buck with Apache License 2.0 5 votes vote down vote up
/**
 * 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: MethodListParser.java    From buck with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
protected Member set(int n, int accessFlags, CstNat nat,
                     AttributeList attributes) {
    StdMethod meth =
        new StdMethod(getDefiner(), accessFlags, nat, attributes);

    methods.set(n, meth);
    return meth;
}
 
Example #21
Source File: DirectClassFile.java    From buck with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
public CstString getSourceFile() {
    AttributeList attribs = getAttributes();
    Attribute attSf = attribs.findFirst(AttSourceFile.ATTRIBUTE_NAME);

    if (attSf instanceof AttSourceFile) {
        return ((AttSourceFile) attSf).getSourceFile();
    }

    return null;
}
 
Example #22
Source File: AttributeTranslator.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the list of thrown exceptions for a given method.
 *
 * @param method {@code non-null;} the method in question
 * @return {@code non-null;} the list of thrown exceptions
 */
public static TypeList getExceptions(Method method) {
    AttributeList attribs = method.getAttributes();
    AttExceptions exceptions = (AttExceptions)
        attribs.findFirst(AttExceptions.ATTRIBUTE_NAME);

    if (exceptions == null) {
        return StdTypeList.EMPTY;
    }

    return exceptions.getExceptions();
}
 
Example #23
Source File: AttributeTranslator.java    From buck with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #24
Source File: DirectClassFile.java    From Box with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public CstString getSourceFile() {
    AttributeList attribs = getAttributes();
    Attribute attSf = attribs.findFirst(AttSourceFile.ATTRIBUTE_NAME);

    if (attSf instanceof AttSourceFile) {
        return ((AttSourceFile) attSf).getSourceFile();
    }

    return null;
}
 
Example #25
Source File: AttributeTranslator.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the parameter annotations out of a given method. This
 * combines both visible and invisible annotations into a single
 * result set.
 *
 * @param method {@code non-null;} the method in question
 * @return {@code non-null;} the list of annotation sets, which may be
 * empty
 */
public static AnnotationsList getParameterAnnotations(Method method) {
    AttributeList attribs = method.getAttributes();
    AttRuntimeVisibleParameterAnnotations visible =
        (AttRuntimeVisibleParameterAnnotations)
        attribs.findFirst(
                AttRuntimeVisibleParameterAnnotations.ATTRIBUTE_NAME);
    AttRuntimeInvisibleParameterAnnotations invisible =
        (AttRuntimeInvisibleParameterAnnotations)
        attribs.findFirst(
                AttRuntimeInvisibleParameterAnnotations.ATTRIBUTE_NAME);

    if (visible == null) {
        if (invisible == null) {
            return AnnotationsList.EMPTY;
        }
        return invisible.getParameterAnnotations();
    }

    if (invisible == null) {
        return visible.getParameterAnnotations();
    }

    // Both are non-null, so combine them.

    return AnnotationsList.combine(visible.getParameterAnnotations(),
            invisible.getParameterAnnotations());
}
 
Example #26
Source File: FieldListParser.java    From buck with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
protected Member set(int n, int accessFlags, CstNat nat,
                     AttributeList attributes) {
    StdField field =
        new StdField(getDefiner(), accessFlags, nat, attributes);

    fields.set(n, field);
    return field;
}
 
Example #27
Source File: AttributeTranslator.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
private static Annotation getSourceDebugExtension(AttributeList attribs) {
    AttSourceDebugExtension extension = (AttSourceDebugExtension)
        attribs.findFirst(AttSourceDebugExtension.ATTRIBUTE_NAME);

    if (extension == null) {
        return null;
    }

    return AnnotationUtils.makeSourceDebugExtension(extension.getSmapString());
}
 
Example #28
Source File: FieldListParser.java    From Box with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
protected Member set(int n, int accessFlags, CstNat nat,
                     AttributeList attributes) {
    StdField field =
        new StdField(getDefiner(), accessFlags, nat, attributes);

    fields.set(n, field);
    return field;
}
 
Example #29
Source File: AttributeTranslator.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the {@code Signature} attribute out of a given
 * {@link AttributeList}, if any, translating it to an annotation.
 *
 * @param attribs {@code non-null;} the attributes list to search in
 * @return {@code null-ok;} the converted {@code Signature} annotation,
 * if there was an attribute to translate
 */
private static Annotation getSignature(AttributeList attribs) {
    AttSignature signature = (AttSignature)
        attribs.findFirst(AttSignature.ATTRIBUTE_NAME);

    if (signature == null) {
        return null;
    }

    return AnnotationUtils.makeSignature(signature.getSignature());
}
 
Example #30
Source File: AttributeTranslator.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the list of thrown exceptions for a given method.
 *
 * @param method {@code non-null;} the method in question
 * @return {@code non-null;} the list of thrown exceptions
 */
public static TypeList getExceptions(Method method) {
    AttributeList attribs = method.getAttributes();
    AttExceptions exceptions = (AttExceptions)
        attribs.findFirst(AttExceptions.ATTRIBUTE_NAME);

    if (exceptions == null) {
        return StdTypeList.EMPTY;
    }

    return exceptions.getExceptions();
}