Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ public MethodVisitor visitMethod(int access, String name, String descriptor, Str

@Override
public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
if (includeTypes && ((this.access & Opcodes.ACC_PUBLIC) != 0) && annotationClassDescriptor.equals(desc)) {
if (includeTypes && ((this.access & Opcodes.ACC_PUBLIC) != 0) && (this.access & Opcodes.ACC_ABSTRACT) == 0
&& annotationClassDescriptor.equals(desc)) {
classNames.add(className);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public class AnnotatedClassTemplate implements ClassTemplate {

private static final String PLACEHOLDER_IMPORTS = "<imports>";

private static final String PLACEHOLDER_VISIBILITY = "<visibility>";

private static final String PLACEHOLDER_CLASS_NAME = "<ClassName>";

private static final String PLACEHOLDER_TYPE_ANNOTATION = "<TypeAnnotation>";
Expand All @@ -23,6 +25,8 @@ public class AnnotatedClassTemplate implements ClassTemplate {

private static final String PLACEHOLDER_METHOD_ANNOTATION = "<MethodAnnotation>";

private final String visibility;

private final String packageName;

private final String simpleClassName;
Expand Down Expand Up @@ -55,6 +59,19 @@ public AnnotatedClassTemplate(String simpleClassName) throws IOException {
* @throws IOException Template file could not be read
*/
public AnnotatedClassTemplate(String simpleClassName, String packageName) throws IOException {
this(null, simpleClassName, packageName);
}

/**
* Creates a dummy annotated class
*
* @param visibility The visibility of the class (public, private, protected, default)
* @param simpleClassName The simple class name of the new class
* @param packageName The package name of the class. Pass null for default package
* @throws IOException Template file could not be read
*/
public AnnotatedClassTemplate(String visibility, String simpleClassName, String packageName) throws IOException {
this.visibility = visibility != null ? visibility : "public";
this.packageName = packageName;
this.simpleClassName = simpleClassName;
this.template = TEST_RESOURCES.getRelated("AnnotatedClass.java.template").toString();
Expand Down Expand Up @@ -98,7 +115,8 @@ public String reifyTemplate() {
packageNameReplacement = "package " + packageName + ";";
}

return template.replace(PLACEHOLDER_CLASS_NAME, simpleClassName)
return template.replace(PLACEHOLDER_VISIBILITY, visibility)
.replace(PLACEHOLDER_CLASS_NAME, simpleClassName)
.replace(PLACEHOLDER_IMPORTS, buildImportString()).replace(PLACEHOLDER_PACKAGE, packageNameReplacement)
.replace(PLACEHOLDER_TYPE_ANNOTATION, Optional.ofNullable(typeAnnotation).orElse(""))
.replace(PLACEHOLDER_FIELD_ANNOTATION, Optional.ofNullable(fieldAnnotation).orElse(""))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ void scanWithPredicateJarFile(Vertx vertx, VertxTestContext testContext) throws
void scanForAnnotation(Vertx vertx, VertxTestContext testContext) throws IOException {
BasicJar jarWithTypeAnnotatedClass =
new AnnotatedClassTemplate("Hodor", "type").setTypeAnnotation("@Deprecated").asJar();
BasicJar jarWithAbstractTypeAnnotatedClass =
new AnnotatedClassTemplate("public abstract", "AbstractHodor", "type").setTypeAnnotation("@Deprecated")
.asJar();
BasicJar jarWithFieldAnnotatedClass =
new AnnotatedClassTemplate("Hodor", "field").setFieldAnnotation("@Deprecated").asJar();
BasicJar jarWithMethodAnnotatedClass =
Expand All @@ -135,16 +138,18 @@ void scanForAnnotation(Vertx vertx, VertxTestContext testContext) throws IOExcep
.setMethodAnnotation("@Transient").setImports(List.of("java.beans.Transient")).asJar();

URL[] urlc = Stream
.of(jarWithTypeAnnotatedClass.writeToTempURL(), jarWithFieldAnnotatedClass.writeToTempURL(),
jarWithMethodAnnotatedClass.writeToTempURL(), jarWithMethodAnnotatedClass2.writeToTempURL())
.of(jarWithTypeAnnotatedClass.writeToTempURL(),
jarWithAbstractTypeAnnotatedClass.writeToTempURL(),
jarWithFieldAnnotatedClass.writeToTempURL(),
jarWithMethodAnnotatedClass.writeToTempURL(),
jarWithMethodAnnotatedClass2.writeToTempURL())
.flatMap(Stream::of).toArray(URL[]::new);
ClassPathScanner cps = new ClassPathScanner(new URLClassLoader(urlc, null));

Checkpoint annotationsScanned = testContext.checkpoint(5);

futureContainsExactly(testContext, annotationsScanned, cps.scanForAnnotation(vertx, Deprecated.class, TYPE),
"type.Hodor");

futureContainsExactly(testContext, annotationsScanned, cps.scanForAnnotation(vertx, Deprecated.class, FIELD),
"field.Hodor");
futureContainsExactly(testContext, annotationsScanned, cps.scanForAnnotation(vertx, Deprecated.class, METHOD),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<imports>

<TypeAnnotation>
public class <ClassName> {
<visibility> class <ClassName> {

<FieldAnnotation>
private String hodor = "hodor";
Expand Down
Loading