Search in sources :

Example 36 with Clazz

use of aQute.bnd.osgi.Clazz in project sling by apache.

the class ModelsScannerPlugin method getClassesWithAnnotation.

/**
     * Get all classes that implement the given annotation via bnd Analyzer.
     * @param analyzer Analyzer
     * @param annotation Annotation
     * @return Class names
     */
private Collection<String> getClassesWithAnnotation(String annotationClassName, Analyzer analyzer) {
    SortedSet<String> classNames = new TreeSet<>();
    Collection<Clazz> clazzes = analyzer.getClassspace().values();
    Instruction instruction = new Instruction(annotationClassName);
    try {
        for (Clazz clazz : clazzes) {
            if (clazz.is(QUERY.ANNOTATED, instruction, analyzer)) {
                classNames.add(clazz.getClassName().getFQN());
            }
        }
    } catch (Exception ex) {
        reporter.exception(ex, "Error querying for classes with annotation: " + annotationClassName);
    }
    return classNames;
}
Also used : TreeSet(java.util.TreeSet) Clazz(aQute.bnd.osgi.Clazz) Instruction(aQute.bnd.osgi.Instruction)

Example 37 with Clazz

use of aQute.bnd.osgi.Clazz in project bnd by bndtools.

the class Target method testSimple.

public void testSimple() throws Exception {
    Analyzer analyzer = new Analyzer();
    Clazz clazz = new Clazz(analyzer, "", null);
    ClassDataCollector cd = new ClassDataCollector() {

        @Override
        public void addReference(TypeRef token) {
        }

        @Override
        public void annotation(Annotation annotation) {
            System.err.println("Annotation " + annotation);
        }

        @Override
        public void classBegin(int access, TypeRef name) {
            System.err.println("Class " + name);
        }

        @Override
        public void classEnd() {
            System.err.println("Class end ");
        }

        @Override
        public void extendsClass(TypeRef name) {
            System.err.println("extends " + name);
        }

        @Override
        public void implementsInterfaces(TypeRef[] name) {
            System.err.println("implements " + Arrays.toString(name));
        }

        @Override
        public void parameter(int p) {
            System.err.println("parameter " + p);
        }
    };
    clazz.parseClassFile(getClass().getResourceAsStream("Target.class"), cd);
}
Also used : TypeRef(aQute.bnd.osgi.Descriptors.TypeRef) Clazz(aQute.bnd.osgi.Clazz) Analyzer(aQute.bnd.osgi.Analyzer) ClassDataCollector(aQute.bnd.osgi.ClassDataCollector) Annotation(aQute.bnd.osgi.Annotation)

Example 38 with Clazz

use of aQute.bnd.osgi.Clazz in project bnd by bndtools.

the class ClassParserTest method testMissingPackage2.

public void testMissingPackage2() throws Exception {
    InputStream in = getClass().getResourceAsStream("JobsService.clazz");
    assertNotNull(in);
    Clazz clazz = new Clazz(a, "test", null);
    clazz.parseClassFile(in);
    assertTrue(clazz.getReferred().contains(a.getPackageRef("com/linkedin/member2/pub/profile/core/view")));
}
Also used : InputStream(java.io.InputStream) Clazz(aQute.bnd.osgi.Clazz)

Example 39 with Clazz

use of aQute.bnd.osgi.Clazz in project bnd by bndtools.

the class ClassParserTest method testSimple.

public void testSimple() throws Exception {
    InputStream in = getClass().getResourceAsStream("WithAnnotations.jclass");
    assertNotNull(in);
    Clazz clazz = new Clazz(a, "test", null);
    clazz.parseClassFile(in);
    Set<PackageRef> set = clazz.getReferred();
    PackageRef test = a.getPackageRef("test");
    PackageRef testAnnotations = a.getPackageRef("test/annotations");
    assertTrue(set.contains(test));
    assertTrue(set.contains(testAnnotations));
}
Also used : InputStream(java.io.InputStream) Clazz(aQute.bnd.osgi.Clazz) PackageRef(aQute.bnd.osgi.Descriptors.PackageRef)

Example 40 with Clazz

use of aQute.bnd.osgi.Clazz in project bnd by bndtools.

the class ClassParserTest method testGenericsSignature2.

public static void testGenericsSignature2() throws Exception {
    Clazz c = new Clazz(a, "genericstest", new FileResource(IO.getFile("src/test/generics.clazz")));
    c.parseClassFile();
    assertTrue(c.getReferred().contains(a.getPackageRef("javax/swing/table")));
    assertTrue(c.getReferred().contains(a.getPackageRef("javax/swing")));
}
Also used : FileResource(aQute.bnd.osgi.FileResource) Clazz(aQute.bnd.osgi.Clazz)

Aggregations

Clazz (aQute.bnd.osgi.Clazz)56 Analyzer (aQute.bnd.osgi.Analyzer)14 ClassDataCollector (aQute.bnd.osgi.ClassDataCollector)14 TypeRef (aQute.bnd.osgi.Descriptors.TypeRef)12 PackageRef (aQute.bnd.osgi.Descriptors.PackageRef)8 InputStream (java.io.InputStream)8 FileResource (aQute.bnd.osgi.FileResource)7 File (java.io.File)7 HashMap (java.util.HashMap)7 FileInputStream (java.io.FileInputStream)6 Resource (aQute.bnd.osgi.Resource)5 MethodDef (aQute.bnd.osgi.Clazz.MethodDef)4 Descriptors (aQute.bnd.osgi.Descriptors)4 Instruction (aQute.bnd.osgi.Instruction)4 Jar (aQute.bnd.osgi.Jar)4 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 Map (java.util.Map)4 TreeSet (java.util.TreeSet)4 Parameters (aQute.bnd.header.Parameters)3