< prev index next >
src/jdk.compiler/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java
Print this page
@@ -29,10 +29,11 @@
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.lang.reflect.Method;
+import java.lang.reflect.Constructor;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.file.Path;
import java.util.*;
import java.util.regex.*;
@@ -280,13 +281,11 @@
private void initProcessorIterator(Iterable<? extends Processor> processors) {
Iterator<? extends Processor> processorIterator;
if (options.isSet(XPRINT)) {
try {
- @SuppressWarnings("deprecation")
- Processor processor = PrintingProcessor.class.newInstance();
- processorIterator = List.of(processor).iterator();
+ processorIterator = List.of(new PrintingProcessor()).iterator();
} catch (Throwable t) {
AssertionError assertError =
new AssertionError("Problem instantiating PrintingProcessor.");
assertError.initCause(t);
throw assertError;
@@ -538,43 +537,45 @@
public boolean hasNext() {
if (nextProc != null)
return true;
else {
- if (!names.hasNext())
+ if (!names.hasNext()) {
return false;
- else {
- String processorName = names.next();
+ } else {
+ Processor processor = getNextProcessor(names.next());
+ if (processor == null) {
+ return false;
+ } else {
+ nextProc = processor;
+ return true;
+ }
+ }
+ }
+ }
- Processor processor;
+ private Processor getNextProcessor(String processorName) {
try {
try {
Class<?> processorClass = processorCL.loadClass(processorName);
ensureReadable(processorClass);
- @SuppressWarnings("deprecation")
- Object tmp = processorClass.newInstance();
- processor = (Processor) tmp;
+ return (Processor) processorClass.getConstructor().newInstance();
} catch (ClassNotFoundException cnfe) {
log.error("proc.processor.not.found", processorName);
- return false;
+ return null;
} catch (ClassCastException cce) {
log.error("proc.processor.wrong.type", processorName);
- return false;
+ return null;
} catch (Exception e ) {
log.error("proc.processor.cant.instantiate", processorName);
- return false;
+ return null;
}
- } catch(ClientCodeException e) {
+ } catch (ClientCodeException e) {
throw e;
- } catch(Throwable t) {
+ } catch (Throwable t) {
throw new AnnotationProcessingError(t);
}
- nextProc = processor;
- return true;
- }
-
- }
}
public Processor next() {
if (hasNext()) {
Processor p = nextProc;
< prev index next >