Search in sources :

Example 11 with Clazz

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

the class ClazzTest method testRecursiveAnnotation.

public void testRecursiveAnnotation() throws Exception {
    File file = IO.getFile("bin/test/ClazzTest$RecursiveAnno.class");
    try (Analyzer analyzer = new Analyzer()) {
        Clazz clazz = new Clazz(analyzer, file.getPath(), new FileResource(file));
        clazz.parseClassFile();
        analyzer.getClassspace().put(clazz.getClassName(), clazz);
        AnnotationReader.getDefinition(clazz, analyzer, EnumSet.noneOf(DSAnnotations.Options.class), new XMLAttributeFinder(analyzer), AnnotationReader.V1_3);
    }
}
Also used : XMLAttributeFinder(aQute.bnd.xmlattribute.XMLAttributeFinder) FileResource(aQute.bnd.osgi.FileResource) Clazz(aQute.bnd.osgi.Clazz) Analyzer(aQute.bnd.osgi.Analyzer) File(java.io.File)

Example 12 with Clazz

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

the class ClassParserTest method testGenericsSignature.

public static void testGenericsSignature() 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)

Example 13 with Clazz

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

the class ClassParserTest method testMissingPackage1.

public void testMissingPackage1() throws Exception {
    InputStream in = getClass().getResourceAsStream("JobsService.clazz");
    assertNotNull(in);
    Clazz clazz = new Clazz(a, "test", null);
    clazz.parseClassFile(in);
    System.err.println(clazz.getReferred());
    clazz.parseDescriptor("(IILcom/linkedin/member2/pub/profile/core/view/I18nPositionViews;)Lcom/linkedin/leo/cloud/overlap/api/OverlapQuery;", 0);
    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 14 with Clazz

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

the class ClassParserTest method testConstantValues.

/**
	 * Test the constant values
	 * 
	 * @throws Exception
	 */
public void testConstantValues() throws Exception {
    final Map<String, Object> values = new HashMap<String, Object>();
    Clazz c = new Clazz(a, "ConstantValues", new FileResource(IO.getFile(new File("").getAbsoluteFile(), "bin/test/ConstantValues.class")));
    c.parseClassFileWithCollector(new ClassDataCollector() {

        Clazz.FieldDef last;

        @Override
        public void field(Clazz.FieldDef referenced) {
            last = referenced;
        }

        @Override
        public void constant(Object value) {
            values.put(last.getName(), value);
        }
    });
    assertEquals(1, values.get("t"));
    assertEquals(0, values.get("f"));
    assertEquals((int) Byte.MAX_VALUE, values.get("bt"));
    assertEquals((int) Short.MAX_VALUE, values.get("shrt"));
    assertEquals((int) Character.MAX_VALUE, values.get("chr"));
    assertEquals(Integer.MAX_VALUE, values.get("intgr"));
    assertEquals(Long.MAX_VALUE, values.get("lng"));
    assertEquals(Float.MAX_VALUE, values.get("flt"));
    assertEquals(Double.MAX_VALUE, values.get("dbl"));
    assertEquals("blabla", values.get("strng"));
// Classes are special
// assertEquals("java.lang.Object", ((Clazz.ClassConstant)
// values.get("clss")).getName());
}
Also used : HashMap(java.util.HashMap) FileResource(aQute.bnd.osgi.FileResource) Clazz(aQute.bnd.osgi.Clazz) ClassDataCollector(aQute.bnd.osgi.ClassDataCollector) File(java.io.File)

Example 15 with Clazz

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

the class ClassParserTest method testGenericsSignature3.

public void testGenericsSignature3() throws Exception {
    Clazz c = new Clazz(a, "genericstest", null);
    c.parseClassFile(getClass().getResourceAsStream("Generics.class"));
    assertTrue(c.getReferred().contains(a.getPackageRef("test")));
    assertTrue(c.getReferred().contains(a.getPackageRef("aQute/bnd/osgi")));
}
Also used : 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