Skip to content

Commit 8bbd4f8

Browse files
committed
Adapt instances of AnnotationValue in the annotation processor
Kevin Mader reported that certain @interfaces were not handled gracefully because the annotation processor would encounter AnnotationValue instances and not know how to handle them. This fixes #130. Without these changes, the example provided below yielded the following exception: error: java.io.IOException: Cannot handle object of type class com.sun.tools.javac.code.Attribute$Constant at org.scijava.annotations.AbstractIndexWriter.writeObject(AbstractIndexWriter.java:252) at org.scijava.annotations.AbstractIndexWriter.writeArray(AbstractIndexWriter.java:306) at org.scijava.annotations.AbstractIndexWriter.writeObject(AbstractIndexWriter.java:243) at org.scijava.annotations.AbstractIndexWriter.writeMap(AbstractIndexWriter.java:288) at org.scijava.annotations.AbstractIndexWriter.writeObject(AbstractIndexWriter.java:249) at org.scijava.annotations.AbstractIndexWriter.writeMap(AbstractIndexWriter.java:288) at org.scijava.annotations.AbstractIndexWriter.writeObject(AbstractIndexWriter.java:249) at org.scijava.annotations.AbstractIndexWriter.write(AbstractIndexWriter.java:99) at org.scijava.annotations.AnnotationProcessor.process(AnnotationProcessor.java:91) at com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:627) ... -- snip BlockIdentity.java -- import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import org.scijava.annotations.Indexable; @target(ElementType.TYPE) @retention(RetentionPolicy.RUNTIME) @indexable public @interface BlockIdentity { String blockName(); String desc() default ""; String[] inputNames(); String[] outputNames(); } -- snap -- -- snip Test.java -- @Blockidentity(blockName = "GrowRegionsBlock", inputNames= {"labeled image", "mask image"}, outputNames= {"filled labels", "filled neighborhood"}) public class Test {} -- snap -- Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent 8e11e2e commit 8bbd4f8

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/main/java/org/scijava/annotations/AbstractIndexWriter.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@
4545
import java.util.Map.Entry;
4646
import java.util.TreeMap;
4747

48+
import javax.lang.model.element.AnnotationValue;
49+
4850
/**
4951
* Writes annotations as JSON-formatted files.
5052
* <p>
@@ -170,6 +172,9 @@ protected Object adapt(final Object o) {
170172
if (o instanceof Annotation) {
171173
return adapt((Annotation) o);
172174
}
175+
else if (o instanceof AnnotationValue) {
176+
return adapt(((AnnotationValue) o).getValue());
177+
}
173178
else if (o instanceof Enum) {
174179
return adapt((Enum<?>) o);
175180
}

0 commit comments

Comments
 (0)