74 import javax.tools.ToolProvider; |
74 import javax.tools.ToolProvider; |
75 import static javax.tools.Diagnostic.Kind.*; |
75 import static javax.tools.Diagnostic.Kind.*; |
76 |
76 |
77 import com.sun.tools.javac.code.Symbol.CompletionFailure; |
77 import com.sun.tools.javac.code.Symbol.CompletionFailure; |
78 import com.sun.tools.javac.main.CommandLine; |
78 import com.sun.tools.javac.main.CommandLine; |
|
79 import com.sun.tools.javac.util.DefinedBy; |
|
80 import com.sun.tools.javac.util.DefinedBy.Api; |
79 |
81 |
80 /** |
82 /** |
81 * Javah generates support files for native methods. |
83 * Javah generates support files for native methods. |
82 * Parse commandline options and invokes javadoc to execute those commands. |
84 * Parse commandline options and invokes javadoc to execute those commands. |
83 * |
85 * |
311 } |
313 } |
312 |
314 |
313 private DiagnosticListener<JavaFileObject> getDiagnosticListenerForWriter(Writer w) { |
315 private DiagnosticListener<JavaFileObject> getDiagnosticListenerForWriter(Writer w) { |
314 final PrintWriter pw = getPrintWriterForWriter(w); |
316 final PrintWriter pw = getPrintWriterForWriter(w); |
315 return new DiagnosticListener<JavaFileObject> () { |
317 return new DiagnosticListener<JavaFileObject> () { |
|
318 @DefinedBy(Api.COMPILER) |
316 public void report(Diagnostic<? extends JavaFileObject> diagnostic) { |
319 public void report(Diagnostic<? extends JavaFileObject> diagnostic) { |
317 if (diagnostic.getKind() == Diagnostic.Kind.ERROR) { |
320 if (diagnostic.getKind() == Diagnostic.Kind.ERROR) { |
318 pw.print(getMessage("err.prefix")); |
321 pw.print(getMessage("err.prefix")); |
319 pw.print(" "); |
322 pw.print(" "); |
320 } |
323 } |
568 } |
571 } |
569 } |
572 } |
570 |
573 |
571 private Diagnostic<JavaFileObject> createDiagnostic(final String key, final Object... args) { |
574 private Diagnostic<JavaFileObject> createDiagnostic(final String key, final Object... args) { |
572 return new Diagnostic<JavaFileObject>() { |
575 return new Diagnostic<JavaFileObject>() { |
|
576 @DefinedBy(Api.COMPILER) |
573 public Kind getKind() { |
577 public Kind getKind() { |
574 return Diagnostic.Kind.ERROR; |
578 return Diagnostic.Kind.ERROR; |
575 } |
579 } |
576 |
580 |
|
581 @DefinedBy(Api.COMPILER) |
577 public JavaFileObject getSource() { |
582 public JavaFileObject getSource() { |
578 return null; |
583 return null; |
579 } |
584 } |
580 |
585 |
|
586 @DefinedBy(Api.COMPILER) |
581 public long getPosition() { |
587 public long getPosition() { |
582 return Diagnostic.NOPOS; |
588 return Diagnostic.NOPOS; |
583 } |
589 } |
584 |
590 |
|
591 @DefinedBy(Api.COMPILER) |
585 public long getStartPosition() { |
592 public long getStartPosition() { |
586 return Diagnostic.NOPOS; |
593 return Diagnostic.NOPOS; |
587 } |
594 } |
588 |
595 |
|
596 @DefinedBy(Api.COMPILER) |
589 public long getEndPosition() { |
597 public long getEndPosition() { |
590 return Diagnostic.NOPOS; |
598 return Diagnostic.NOPOS; |
591 } |
599 } |
592 |
600 |
|
601 @DefinedBy(Api.COMPILER) |
593 public long getLineNumber() { |
602 public long getLineNumber() { |
594 return Diagnostic.NOPOS; |
603 return Diagnostic.NOPOS; |
595 } |
604 } |
596 |
605 |
|
606 @DefinedBy(Api.COMPILER) |
597 public long getColumnNumber() { |
607 public long getColumnNumber() { |
598 return Diagnostic.NOPOS; |
608 return Diagnostic.NOPOS; |
599 } |
609 } |
600 |
610 |
|
611 @DefinedBy(Api.COMPILER) |
601 public String getCode() { |
612 public String getCode() { |
602 return key; |
613 return key; |
603 } |
614 } |
604 |
615 |
|
616 @DefinedBy(Api.COMPILER) |
605 public String getMessage(Locale locale) { |
617 public String getMessage(Locale locale) { |
606 return JavahTask.this.getMessage(locale, key, args); |
618 return JavahTask.this.getMessage(locale, key, args); |
607 } |
619 } |
608 |
620 |
609 }; |
621 }; |
673 |
685 |
674 JavahProcessor(Gen g) { |
686 JavahProcessor(Gen g) { |
675 this.g = g; |
687 this.g = g; |
676 } |
688 } |
677 |
689 |
678 @Override |
690 @Override @DefinedBy(Api.ANNOTATION_PROCESSING) |
679 public SourceVersion getSupportedSourceVersion() { |
691 public SourceVersion getSupportedSourceVersion() { |
680 // since this is co-bundled with javac, we can assume it supports |
692 // since this is co-bundled with javac, we can assume it supports |
681 // the latest source version |
693 // the latest source version |
682 return SourceVersion.latest(); |
694 return SourceVersion.latest(); |
683 } |
695 } |
684 |
696 |
685 @Override |
697 @Override @DefinedBy(Api.ANNOTATION_PROCESSING) |
686 public void init(ProcessingEnvironment pEnv) { |
698 public void init(ProcessingEnvironment pEnv) { |
687 super.init(pEnv); |
699 super.init(pEnv); |
688 messager = processingEnv.getMessager(); |
700 messager = processingEnv.getMessager(); |
689 } |
701 } |
690 |
702 |
|
703 @DefinedBy(Api.ANNOTATION_PROCESSING) |
691 public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { |
704 public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { |
692 try { |
705 try { |
693 Set<TypeElement> classes = getAllClasses(ElementFilter.typesIn(roundEnv.getRootElements())); |
706 Set<TypeElement> classes = getAllClasses(ElementFilter.typesIn(roundEnv.getRootElements())); |
694 if (classes.size() > 0) { |
707 if (classes.size() > 0) { |
695 checkMethodParameters(classes); |
708 checkMethodParameters(classes); |
737 } |
750 } |
738 } |
751 } |
739 |
752 |
740 private TypeVisitor<Void,Types> checkMethodParametersVisitor = |
753 private TypeVisitor<Void,Types> checkMethodParametersVisitor = |
741 new SimpleTypeVisitor9<Void,Types>() { |
754 new SimpleTypeVisitor9<Void,Types>() { |
742 @Override |
755 @Override @DefinedBy(Api.LANGUAGE_MODEL) |
743 public Void visitArray(ArrayType t, Types types) { |
756 public Void visitArray(ArrayType t, Types types) { |
744 visit(t.getComponentType(), types); |
757 visit(t.getComponentType(), types); |
745 return null; |
758 return null; |
746 } |
759 } |
747 @Override |
760 @Override @DefinedBy(Api.LANGUAGE_MODEL) |
748 public Void visitDeclared(DeclaredType t, Types types) { |
761 public Void visitDeclared(DeclaredType t, Types types) { |
749 t.asElement().getKind(); // ensure class exists |
762 t.asElement().getKind(); // ensure class exists |
750 for (TypeMirror st: types.directSupertypes(t)) |
763 for (TypeMirror st: types.directSupertypes(t)) |
751 visit(st, types); |
764 visit(st, types); |
752 return null; |
765 return null; |