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;
}
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);
}
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")));
}
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));
}
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")));
}
Aggregations