Search in sources :

Example 11 with ClassDataCollector

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

the class ClazzTest method testUnusedClassConstant.

/**
	 * There is an unused class constant in the This actually looks wrong since
	 */
public void testUnusedClassConstant() throws Exception {
    try (Analyzer a = new Analyzer()) {
        Clazz c = new Clazz(a, "", null);
        c.parseClassFile(new FileInputStream("testresources/TestWeavingHook.jclass"), new ClassDataCollector() {
        });
        // TODO test someething here
        System.out.println(c.getReferred());
    }
}
Also used : Clazz(aQute.bnd.osgi.Clazz) Analyzer(aQute.bnd.osgi.Analyzer) ClassDataCollector(aQute.bnd.osgi.ClassDataCollector) FileInputStream(java.io.FileInputStream)

Example 12 with ClassDataCollector

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

the class ClazzTest method testModuleInfo.

public void testModuleInfo() throws Exception {
    try (Analyzer a = new Analyzer()) {
        Clazz c = new Clazz(a, "", null);
        c.parseClassFile(new FileInputStream("jar/module-info.jclass"), new ClassDataCollector() {
        });
        assertTrue(c.isModule());
        Set<PackageRef> referred = c.getReferred();
        Descriptors d = new Descriptors();
        assertFalse(referred.contains(d.getPackageRef("")));
    }
}
Also used : Clazz(aQute.bnd.osgi.Clazz) Descriptors(aQute.bnd.osgi.Descriptors) Analyzer(aQute.bnd.osgi.Analyzer) ClassDataCollector(aQute.bnd.osgi.ClassDataCollector) PackageRef(aQute.bnd.osgi.Descriptors.PackageRef) FileInputStream(java.io.FileInputStream)

Example 13 with ClassDataCollector

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

the class ClazzTest method testAnalyzerCrawlInvokeInterfaceAIOOBException.

public void testAnalyzerCrawlInvokeInterfaceAIOOBException() throws Exception {
    try (Analyzer a = new Analyzer()) {
        Clazz c = new Clazz(a, "", null);
        c.parseClassFile(new FileInputStream("jar/AnalyzerCrawlInvokerInterfaceAIOOBTest.jclass"), new ClassDataCollector() {
        });
        Set<PackageRef> referred = c.getReferred();
        System.out.println(referred);
    }
}
Also used : Clazz(aQute.bnd.osgi.Clazz) Analyzer(aQute.bnd.osgi.Analyzer) ClassDataCollector(aQute.bnd.osgi.ClassDataCollector) PackageRef(aQute.bnd.osgi.Descriptors.PackageRef) FileInputStream(java.io.FileInputStream)

Example 14 with ClassDataCollector

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

the class ParseSignatureBuilder method parse.

public void parse(InputStream in) throws Exception {
    Analyzer analyzer = new Analyzer();
    Clazz clazz = new Clazz(analyzer, "", null);
    clazz.parseClassFile(in, new ClassDataCollector() {

        Scope s;

        Scope enclosing;

        Scope declaring;

        @Override
        public void classBegin(int access, TypeRef name) {
            s = root.getScope(name.getBinary());
            s.access = Access.modifier(access);
            s.kind = Kind.CLASS;
        }

        @Override
        public void extendsClass(TypeRef name) {
        // s.setBase(new GenericType(name));
        }

        @Override
        public void implementsInterfaces(TypeRef[] names) {
            s.setParameterTypes(convert(names));
        }

        GenericType[] convert(TypeRef[] names) {
            GenericType[] tss = new GenericType[names.length];
            for (int i = 0; i < names.length; i++) {
            // tss[i] = new GenericType(names[i]);
            }
            return tss;
        }

        @Override
        public void method(Clazz.MethodDef defined) {
            String descriptor;
            Kind kind;
            if (defined.isConstructor()) {
                descriptor = ":" + defined.getDescriptor();
                kind = Kind.CONSTRUCTOR;
            } else {
                descriptor = defined.getName() + ":" + defined.getDescriptor();
                kind = Kind.METHOD;
            }
            Scope m = s.getScope(descriptor);
            m.access = Access.modifier(defined.getAccess());
            m.kind = kind;
            m.declaring = s;
            s.add(m);
        }

        @Override
        public void field(Clazz.FieldDef defined) {
            String descriptor = defined.getName() + ":" + defined.getDescriptor();
            Kind kind = Kind.FIELD;
            Scope m = s.getScope(descriptor);
            m.access = Access.modifier(defined.getAccess());
            m.kind = kind;
            m.declaring = s;
            s.add(m);
        }

        @Override
        public void classEnd() {
            if (enclosing != null)
                s.setEnclosing(enclosing);
            if (declaring != null)
                s.setDeclaring(declaring);
        }

        @Override
        public void enclosingMethod(TypeRef cName, String mName, String mDescriptor) {
            enclosing = root.getScope(cName.getBinary());
            if (mName != null) {
                enclosing = enclosing.getScope(Scope.methodIdentity(mName, mDescriptor));
            }
        }

        @Override
        public void innerClass(TypeRef innerClass, TypeRef outerClass, String innerName, int innerClassAccessFlags) {
            if (outerClass != null && innerClass != null && innerClass.getBinary().equals(s.name))
                declaring = root.getScope(outerClass.getBinary());
        }
    });
}
Also used : TypeRef(aQute.bnd.osgi.Descriptors.TypeRef) Clazz(aQute.bnd.osgi.Clazz) Analyzer(aQute.bnd.osgi.Analyzer) ClassDataCollector(aQute.bnd.osgi.ClassDataCollector)

Aggregations

ClassDataCollector (aQute.bnd.osgi.ClassDataCollector)14 Clazz (aQute.bnd.osgi.Clazz)14 Analyzer (aQute.bnd.osgi.Analyzer)8 FileInputStream (java.io.FileInputStream)6 TypeRef (aQute.bnd.osgi.Descriptors.TypeRef)5 PackageRef (aQute.bnd.osgi.Descriptors.PackageRef)4 MethodDef (aQute.bnd.osgi.Clazz.MethodDef)3 Descriptors (aQute.bnd.osgi.Descriptors)3 Annotation (aQute.bnd.osgi.Annotation)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Set (java.util.Set)2 FileResource (aQute.bnd.osgi.FileResource)1 Instructions (aQute.bnd.osgi.Instructions)1 Delta (aQute.bnd.service.diff.Delta)1 Type (aQute.bnd.service.diff.Type)1 MultiMap (aQute.lib.collections.MultiMap)1 File (java.io.File)1 Collection (java.util.Collection)1 LinkedHashMap (java.util.LinkedHashMap)1