Search in sources :

Example 11 with TypeRef

use of aQute.bnd.osgi.Descriptors.TypeRef in project bnd by bndtools.

the class Clazz method getMethodDef.

/**
	 * Called when crawling the byte code and a method reference is found
	 */
void getMethodDef(int access, int methodRefPoolIndex) {
    if (methodRefPoolIndex == 0)
        return;
    Object o = pool[methodRefPoolIndex];
    if (o instanceof Assoc) {
        Assoc assoc = (Assoc) o;
        if (assoc.tag == CONSTANT.Methodref) {
            int string_index = intPool[assoc.a];
            TypeRef className = analyzer.getTypeRef((String) pool[string_index]);
            int name_and_type_index = assoc.b;
            Assoc name_and_type = (Assoc) pool[name_and_type_index];
            if (name_and_type.tag == CONSTANT.NameAndType) {
                // Name and Type
                int name_index = name_and_type.a;
                int type_index = name_and_type.b;
                String method = (String) pool[name_index];
                String descriptor = (String) pool[type_index];
                cd.referenceMethod(access, className, method, descriptor);
            } else
                throw new IllegalArgumentException("Invalid class file (or parsing is wrong), assoc is not type + name (12)");
        } else
            throw new IllegalArgumentException("Invalid class file (or parsing is wrong), Assoc is not method ref! (10)");
    } else
        throw new IllegalArgumentException("Invalid class file (or parsing is wrong), Not an assoc at a method ref");
}
Also used : TypeRef(aQute.bnd.osgi.Descriptors.TypeRef)

Example 12 with TypeRef

use of aQute.bnd.osgi.Descriptors.TypeRef in project bnd by bndtools.

the class Clazz method doInnerClasses.

/**
	 * <pre>
	 *  InnerClasses_attribute { u2 attribute_name_index; u4
	 * attribute_length; u2 number_of_classes; { u2 inner_class_info_index; u2
	 * outer_class_info_index; u2 inner_name_index; u2 inner_class_access_flags;
	 * } classes[number_of_classes]; }
	 * </pre>
	 * 
	 * @param in
	 * @throws Exception
	 */
private void doInnerClasses(DataInput in) throws Exception {
    int number_of_classes = in.readUnsignedShort();
    for (int i = 0; i < number_of_classes; i++) {
        int inner_class_info_index = in.readUnsignedShort();
        int outer_class_info_index = in.readUnsignedShort();
        int inner_name_index = in.readUnsignedShort();
        int inner_class_access_flags = in.readUnsignedShort();
        if (cd != null) {
            TypeRef innerClass = null;
            TypeRef outerClass = null;
            String innerName = null;
            if (inner_class_info_index != 0) {
                int nameIndex = intPool[inner_class_info_index];
                innerClass = analyzer.getTypeRef((String) pool[nameIndex]);
            }
            if (outer_class_info_index != 0) {
                int nameIndex = intPool[outer_class_info_index];
                outerClass = analyzer.getTypeRef((String) pool[nameIndex]);
            }
            if (inner_name_index != 0)
                innerName = (String) pool[inner_name_index];
            cd.innerClass(innerClass, outerClass, innerName, inner_class_access_flags);
        }
    }
}
Also used : TypeRef(aQute.bnd.osgi.Descriptors.TypeRef)

Example 13 with TypeRef

use of aQute.bnd.osgi.Descriptors.TypeRef in project bnd by bndtools.

the class Target method testNestedAnnotations.

@SuppressWarnings({ "rawtypes", "unchecked" })
public static void testNestedAnnotations() throws Exception {
    try (Analyzer analyzer = new Analyzer()) {
        TypeRef typeref = analyzer.getTypeRefFromFQN(ActualAnnotation.class.getName());
        Map<String, Object> annMap = (Map) Collections.singletonMap("a", 5);
        Annotation annotation = new Annotation(typeref, annMap, ElementType.FIELD, RetentionPolicy.RUNTIME);
        Map<String, Object> properties = (Map) Collections.singletonMap("ann", annotation);
        ConfigurableInterface a = Configurable.createConfigurable(ConfigurableInterface.class, properties);
        assertNotNull(a);
        assertNotNull(a.ann());
        assertEquals(5, a.ann().a());
    }
}
Also used : TypeRef(aQute.bnd.osgi.Descriptors.TypeRef) Analyzer(aQute.bnd.osgi.Analyzer) Map(java.util.Map) Annotation(aQute.bnd.osgi.Annotation)

Example 14 with TypeRef

use of aQute.bnd.osgi.Descriptors.TypeRef in project bnd by bndtools.

the class MetatypeAnnotations method analyzeJar.

public boolean analyzeJar(Analyzer analyzer) throws Exception {
    this.minVersion = MetatypeVersion.VERSION_1_2;
    Parameters header = OSGiHeader.parseHeader(analyzer.getProperty(Constants.METATYPE_ANNOTATIONS, "*"));
    if (header.size() == 0)
        return false;
    Parameters optionsHeader = OSGiHeader.parseHeader(analyzer.getProperty(Constants.METATYPE_ANNOTATIONS_OPTIONS));
    EnumSet<Options> options = EnumSet.noneOf(Options.class);
    for (Map.Entry<String, Attrs> entry : optionsHeader.entrySet()) {
        try {
            Options.parseOption(entry, options, this);
        } catch (IllegalArgumentException e) {
            analyzer.error("Unrecognized %s value %s with attributes %s, expected values are %s", Constants.METATYPE_ANNOTATIONS_OPTIONS, entry.getKey(), entry.getValue(), EnumSet.allOf(Options.class));
        }
    }
    Map<TypeRef, OCDDef> classToOCDMap = new HashMap<TypeRef, OCDDef>();
    Set<String> ocdIds = new HashSet<String>();
    Set<String> pids = new HashSet<String>();
    Instructions instructions = new Instructions(header);
    XMLAttributeFinder finder = new XMLAttributeFinder(analyzer);
    List<Clazz> list = Create.list();
    for (Clazz c : analyzer.getClassspace().values()) {
        for (Instruction instruction : instructions.keySet()) {
            if (instruction.matches(c.getFQN())) {
                if (!instruction.isNegated()) {
                    list.add(c);
                    OCDDef definition = OCDReader.getOCDDef(c, analyzer, options, finder, minVersion);
                    if (definition != null) {
                        classToOCDMap.put(c.getClassName(), definition);
                    }
                }
                break;
            }
        }
    }
    // process Designate annotations after OCD annotations
    for (Clazz c : list) {
        DesignateReader.getDesignate(c, analyzer, classToOCDMap, finder);
    }
    for (Map.Entry<TypeRef, OCDDef> entry : classToOCDMap.entrySet()) {
        TypeRef c = entry.getKey();
        OCDDef definition = entry.getValue();
        definition.prepare(analyzer);
        if (!ocdIds.add(definition.id)) {
            analyzer.error("Duplicate OCD id %s from class %s; known ids %s", definition.id, c.getFQN(), ocdIds);
        }
        for (DesignateDef dDef : definition.designates) {
            if (dDef.pid != null && !pids.add(dDef.pid)) {
                analyzer.error("Duplicate pid %s from class %s", dDef.pid, c.getFQN());
            }
        }
        String name = "OSGI-INF/metatype/" + analyzer.validResourcePath(definition.id, "Invalid resource name") + ".xml";
        analyzer.getJar().putResource(name, new TagResource(definition.getTag()));
    }
    return false;
}
Also used : Parameters(aQute.bnd.header.Parameters) HashMap(java.util.HashMap) TagResource(aQute.bnd.component.TagResource) TypeRef(aQute.bnd.osgi.Descriptors.TypeRef) Attrs(aQute.bnd.header.Attrs) Instructions(aQute.bnd.osgi.Instructions) Instruction(aQute.bnd.osgi.Instruction) XMLAttributeFinder(aQute.bnd.xmlattribute.XMLAttributeFinder) Clazz(aQute.bnd.osgi.Clazz) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 15 with TypeRef

use of aQute.bnd.osgi.Descriptors.TypeRef in project bnd by bndtools.

the class OCDReader method parseExtends.

private void parseExtends(Clazz clazz) {
    TypeRef[] inherits = clazz.getInterfaces();
    if (inherits != null) {
        for (TypeRef typeRef : inherits) {
            if (!typeRef.isJava() && analyzed.add(typeRef)) {
                try {
                    Clazz inherit = analyzer.findClass(typeRef);
                    if (inherit != null) {
                        inherit.parseClassFileWithCollector(new OCDDataCollector(ocd));
                        parseExtends(inherit);
                    } else {
                        analyzer.error("Could not obtain super class %s of class %s", typeRef.getFQN(), clazz.getClassName().getFQN());
                    }
                } catch (Exception e) {
                    analyzer.exception(e, "Could not obtain super class %s of class %s; exception %s", typeRef.getFQN(), clazz.getClassName().getFQN(), e);
                }
            }
        }
    }
}
Also used : TypeRef(aQute.bnd.osgi.Descriptors.TypeRef) Clazz(aQute.bnd.osgi.Clazz)

Aggregations

TypeRef (aQute.bnd.osgi.Descriptors.TypeRef)42 Clazz (aQute.bnd.osgi.Clazz)12 PackageRef (aQute.bnd.osgi.Descriptors.PackageRef)7 HashMap (java.util.HashMap)6 LinkedHashMap (java.util.LinkedHashMap)6 Map (java.util.Map)6 Analyzer (aQute.bnd.osgi.Analyzer)5 ClassDataCollector (aQute.bnd.osgi.ClassDataCollector)5 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)5 HashSet (java.util.HashSet)5 Matcher (java.util.regex.Matcher)5 DeclarativeServicesAnnotationError (aQute.bnd.component.error.DeclarativeServicesAnnotationError)4 Attrs (aQute.bnd.header.Attrs)4 Annotation (aQute.bnd.osgi.Annotation)4 MultiMap (aQute.lib.collections.MultiMap)4 MethodDef (aQute.bnd.osgi.Clazz.MethodDef)3 Instructions (aQute.bnd.osgi.Instructions)3 Resource (aQute.bnd.osgi.Resource)3 Tag (aQute.lib.tag.Tag)3