Attempts to fix, probably fruitless

This commit is contained in:
Bruce Eckel 2015-04-25 18:27:58 -07:00
parent 79ca89bd2e
commit eb26a0c8db
4 changed files with 72 additions and 27 deletions

View File

@ -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).
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.**

View File

@ -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<MethodDeclaration> interfaceMethods =
new ArrayList<MethodDeclaration>();
implements Processor {
private final ProcessingEnvironment env;
private ArrayList<ExecutableElement> interfaceMethods =
new ArrayList<ExecutableElement>();
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<? extends TypeElement> 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<String> getSupportedAnnotationTypes() {
return
Collections.singleton("annotations.ExtractInterface");
}
public Set<String> getSupportedOptions() {
return Collections.emptySet();
}
public Iterable<? extends Completion> getCompletions(
Element element, AnnotationMirror annotation,
ExecutableElement member, String userText) {
return Collections.emptyList();
}
} ///:~

View File

@ -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<AnnotationTypeDeclaration> 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<TypeElement> atds,
ProcessingEnvironment env) {
return new InterfaceExtractorProcessor(env);
}
public Collection<String> supportedAnnotationTypes() {
public boolean process(Set<? extends TypeElement> annotations,
RoundEnvironment roundEnv) {
return new InterfaceExtractorProcessor(env);
}
public Set<String> getSupportedAnnotationTypes() {
return
Collections.singleton("annotations.ExtractInterface");
}
public Collection<String> supportedOptions() {
public Set<String> getSupportedOptions() {
return Collections.emptySet();
}
public Iterable<? extends Completion> getCompletions(
Element element, AnnotationMirror annotation,
ExecutableElement member, String userText) {
return Collections.emptyList();
}
} ///:~

View File

@ -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 {