From eb26a0c8dbf4b8e49a14756344d1d3e9214bc137 Mon Sep 17 00:00:00 2001 From: Bruce Eckel Date: Sat, 25 Apr 2015 18:27:58 -0700 Subject: [PATCH] Attempts to fix, probably fruitless --- README.md | 8 ++- annotations/InterfaceExtractorProcessor.java | 53 +++++++++++++------ .../InterfaceExtractorProcessorFactory.java | 36 ++++++++++--- .../TableCreationProcessorFactory.java | 2 +- 4 files changed, 72 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index b0c2b141..766dbd4f 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ # Thinking in Java 4e (Refreshed) Code Examples -for Java 8 +---------- +(for Java 8) ### *Initial draft; not working yet* @@ -17,4 +18,7 @@ for Java 8 1. Start a command prompt in the directory where you installed the examples. If your installation is successful, you should be able to type **ant build** and build everything. **ant run** will build AND run the examples. You will initially get some error messages instructing you to install specified packages, but eventually you should get through the whole build process successfully. -Report bugs in the examples or in the book [here](https://github.com/BruceEckel/TIJ4-Refreshed-Examples/issues). \ No newline at end of file +Report bugs in the examples or in the book [here](https://github.com/BruceEckel/TIJ4-Refreshed-Examples/issues). + +---------- +**Copyright ©2015 Bruce Eckel, MindView LLC. All Rights Reserved. You may use the examples for teaching, as long as they are not republished without permission.** \ No newline at end of file diff --git a/annotations/InterfaceExtractorProcessor.java b/annotations/InterfaceExtractorProcessor.java index fed73918..4749243e 100644 --- a/annotations/InterfaceExtractorProcessor.java +++ b/annotations/InterfaceExtractorProcessor.java @@ -4,26 +4,35 @@ // annotations.InterfaceExtractorProcessorFactory // Multiplier.java -s ../annotations} package annotations; -import com.sun.mirror.apt.*; -import com.sun.mirror.declaration.*; +//import com.sun.mirror.apt.*; +import javax.annotation.processing.*; +//import com.sun.mirror.declaration.*; +import javax.lang.model.element.*; +import javax.lang.model.SourceVersion; import java.io.*; import java.util.*; public class InterfaceExtractorProcessor - implements AnnotationProcessor { - private final AnnotationProcessorEnvironment env; - private ArrayList interfaceMethods = - new ArrayList(); + implements Processor { + private final ProcessingEnvironment env; + private ArrayList interfaceMethods = + new ArrayList(); + public void init(ProcessingEnvironment processingEnv) { + + } + public SourceVersion getSupportedSourceVersion() { + return SourceVersion.RELEASE_7; + } public InterfaceExtractorProcessor( - AnnotationProcessorEnvironment env) { this.env = env; } - public void process() { - for(TypeDeclaration typeDecl : - env.getSpecifiedTypeDeclarations()) { + ProcessingEnvironment env) { this.env = env; } + public boolean process(Set annotations, + RoundEnvironment roundEnv) { + for(TypeElement typeElem : env.getElementUtils()) { ExtractInterface annot = - typeDecl.getAnnotation(ExtractInterface.class); + typeElem.getAnnotation(ExtractInterface.class); if(annot == null) break; - for(MethodDeclaration m : typeDecl.getMethods()) + for(ExecutableElement m : typeElem.getMethods()) if(m.getModifiers().contains(Modifier.PUBLIC) && !(m.getModifiers().contains(Modifier.STATIC))) interfaceMethods.add(m); @@ -32,17 +41,17 @@ public class InterfaceExtractorProcessor PrintWriter writer = env.getFiler().createSourceFile(annot.value()); writer.println("package " + - typeDecl.getPackage().getQualifiedName() +";"); + typeElem.getPackage().getQualifiedName() +";"); writer.println("public interface " + annot.value() + " {"); - for(MethodDeclaration m : interfaceMethods) { + for(ExecutableElement m : interfaceMethods) { writer.print(" public "); writer.print(m.getReturnType() + " "); writer.print(m.getSimpleName() + " ("); int i = 0; - for(ParameterDeclaration parm : + for(VariableElement parm : m.getParameters()) { - writer.print(parm.getType() + " " + + writer.print(parm.getKind() + " " + parm.getSimpleName()); if(++i < m.getParameters().size()) writer.print(", "); @@ -57,4 +66,16 @@ public class InterfaceExtractorProcessor } } } + public Set getSupportedAnnotationTypes() { + return + Collections.singleton("annotations.ExtractInterface"); + } + public Set getSupportedOptions() { + return Collections.emptySet(); + } + public Iterable getCompletions( + Element element, AnnotationMirror annotation, + ExecutableElement member, String userText) { + return Collections.emptyList(); + } } ///:~ diff --git a/annotations/InterfaceExtractorProcessorFactory.java b/annotations/InterfaceExtractorProcessorFactory.java index a5025633..a6804a2f 100644 --- a/annotations/InterfaceExtractorProcessorFactory.java +++ b/annotations/InterfaceExtractorProcessorFactory.java @@ -1,22 +1,42 @@ //: annotations/InterfaceExtractorProcessorFactory.java // APT-based annotation processing. package annotations; -import com.sun.mirror.apt.*; -import com.sun.mirror.declaration.*; +//import com.sun.mirror.apt.*; +import javax.annotation.processing.*; +//import com.sun.mirror.declaration.*; +import javax.lang.model.element.*; +import javax.lang.model.SourceVersion; import java.util.*; public class InterfaceExtractorProcessorFactory - implements AnnotationProcessorFactory { - public AnnotationProcessor getProcessorFor( - Set atds, - AnnotationProcessorEnvironment env) { +// implements AnnotationProcessorFactory { + implements Processor { + public void init(ProcessingEnvironment processingEnv) { + + } + public SourceVersion getSupportedSourceVersion() { + return SourceVersion.RELEASE_7; + } +// public AnnotationProcessor getProcessorFor( + public Processor getProcessorFor( + Set atds, + ProcessingEnvironment env) { return new InterfaceExtractorProcessor(env); } - public Collection supportedAnnotationTypes() { + public boolean process(Set annotations, + RoundEnvironment roundEnv) { + return new InterfaceExtractorProcessor(env); + } + public Set getSupportedAnnotationTypes() { return Collections.singleton("annotations.ExtractInterface"); } - public Collection supportedOptions() { + public Set getSupportedOptions() { return Collections.emptySet(); } + public Iterable getCompletions( + Element element, AnnotationMirror annotation, + ExecutableElement member, String userText) { + return Collections.emptyList(); + } } ///:~ diff --git a/annotations/database/TableCreationProcessorFactory.java b/annotations/database/TableCreationProcessorFactory.java index 36eee132..ed736347 100644 --- a/annotations/database/TableCreationProcessorFactory.java +++ b/annotations/database/TableCreationProcessorFactory.java @@ -7,8 +7,8 @@ package annotations.database; import com.sun.mirror.apt.*; import com.sun.mirror.declaration.*; import com.sun.mirror.util.*; -import java.util.*; import static com.sun.mirror.util.DeclarationVisitors.*; +import java.util.*; public class TableCreationProcessorFactory implements AnnotationProcessorFactory {