com.sun.tools.javac.util.JCDiagnostic Java Examples
The following examples show how to use
com.sun.tools.javac.util.JCDiagnostic.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ResolveHarness.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
@Override void process(Diagnostic<? extends JavaFileObject> diagnostic) { Element siteSym = getSiteSym(diagnostic); if (siteSym.getSimpleName().length() != 0 && ((Symbol)siteSym).outermostClass().getAnnotation(TraceResolve.class) == null) { return; } int candidateIdx = 0; for (JCDiagnostic d : subDiagnostics(diagnostic)) { boolean isMostSpecific = candidateIdx++ == mostSpecific(diagnostic); VerboseCandidateSubdiagProcessor subProc = new VerboseCandidateSubdiagProcessor(isMostSpecific, phase(diagnostic), success(diagnostic)); if (subProc.matches(d)) { subProc.process(d); } else { throw new AssertionError("Bad subdiagnostic: " + d.getCode()); } } }
Example #2
Source File: JavacProcessingEnvironment.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
/** Return whether or not an unrecoverable error has occurred. */ boolean unrecoverableError() { if (messager.errorRaised()) return true; for (JCDiagnostic d: deferredDiagnosticHandler.getDiagnostics()) { switch (d.getKind()) { case WARNING: if (werror) return true; break; case ERROR: if (fatalErrors || !d.isFlagSet(RECOVERABLE)) return true; break; } } return false; }
Example #3
Source File: ResolveHarness.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
@Override void process(Diagnostic<? extends JavaFileObject> diagnostic) { Element siteSym = getSiteSym(diagnostic); if (siteSym.getSimpleName().length() != 0 && ((Symbol)siteSym).outermostClass().getAnnotation(TraceResolve.class) == null) { return; } int candidateIdx = 0; for (JCDiagnostic d : subDiagnostics(diagnostic)) { boolean isMostSpecific = candidateIdx++ == mostSpecific(diagnostic); VerboseCandidateSubdiagProcessor subProc = new VerboseCandidateSubdiagProcessor(isMostSpecific, phase(diagnostic), success(diagnostic)); if (subProc.matches(d)) { subProc.process(d); } else { throw new AssertionError("Bad subdiagnostic: " + d.getCode()); } } }
Example #4
Source File: BadClassfile.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
private static void test(String classname, String expected) throws Exception { File classfile = new File(System.getProperty("test.classes", "."), classname + ".class"); ClassFile cf = ClassFile.read(classfile); cf = new ClassFile(cf.magic, Target.JDK1_7.minorVersion, Target.JDK1_7.majorVersion, cf.constant_pool, cf.access_flags, cf.this_class, cf.super_class, cf.interfaces, cf.fields, cf.methods, cf.attributes); new ClassWriter().write(cf, classfile); JavaCompiler c = ToolProvider.getSystemJavaCompiler(); JavacTaskImpl task = (JavacTaskImpl) c.getTask(null, null, null, Arrays.asList("-classpath", System.getProperty("test.classes", ".")), null, null); try { Symbol clazz = com.sun.tools.javac.main.JavaCompiler.instance(task.getContext()).resolveIdent(classname); clazz.complete(); } catch (BadClassFile f) { JCDiagnostic embeddedDiag = (JCDiagnostic) f.diag.getArgs()[1]; assertEquals(expected, embeddedDiag.getCode()); assertEquals(Integer.toString(Target.JDK1_7.majorVersion), embeddedDiag.getArgs()[0]); assertEquals(Integer.toString(Target.JDK1_7.minorVersion), embeddedDiag.getArgs()[1]); } }
Example #5
Source File: ResolveHarness.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
@Override void process(Diagnostic<? extends JavaFileObject> diagnostic) { Element siteSym = getSiteSym(diagnostic); if (siteSym.getSimpleName().length() != 0 && ((Symbol)siteSym).outermostClass().getAnnotation(TraceResolve.class) == null) { return; } int candidateIdx = 0; for (JCDiagnostic d : subDiagnostics(diagnostic)) { boolean isMostSpecific = candidateIdx++ == mostSpecific(diagnostic); VerboseCandidateSubdiagProcessor subProc = new VerboseCandidateSubdiagProcessor(isMostSpecific, phase(diagnostic), success(diagnostic)); if (subProc.matches(d)) { subProc.process(d); } else { throw new AssertionError("Bad subdiagnostic: " + d.getCode()); } } }
Example #6
Source File: StringConcat.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public Item makeConcat(JCTree.JCBinary tree) { JCDiagnostic.DiagnosticPosition pos = tree.pos(); // Create a string builder. newStringBuilder(tree); // Append all strings to builder. List<JCTree> args = collectAll(tree); for (JCTree t : args) { gen.genExpr(t, t.type).load(); appendString(t); } // Convert builder to string. builderToString(pos); return gen.getItems().makeStackItem(syms.stringType); }
Example #7
Source File: StringLiteralTemplateProcessor.java From manifold with Apache License 2.0 | 6 votes |
private boolean transferParseErrors( int literalOffset, StringLiteralTemplateParser.Expr comp, JCTree.JCExpression expr, DiagnosticCollector<JavaFileObject> errorHandler ) { if( expr == null || errorHandler.getDiagnostics().stream().anyMatch( e -> e.getKind() == Diagnostic.Kind.ERROR ) ) { for( Diagnostic<? extends JavaFileObject> diag : errorHandler.getDiagnostics() ) { if( diag.getKind() == Diagnostic.Kind.ERROR ) { JCDiagnostic jcDiag = ((ClientCodeWrapper.DiagnosticSourceUnwrapper)diag).d; String code = debaseMsgCode( diag ); IDynamicJdk.instance().logError( Log.instance( _javacTask.getContext() ), new JCDiagnostic.SimpleDiagnosticPosition( literalOffset + 1 + comp.getOffset() ), code, jcDiag.getArgs() ); } } return true; } return false; }
Example #8
Source File: JavacProcessingEnvironment.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
/** Return whether or not an unrecoverable error has occurred. */ boolean unrecoverableError() { if (messager.errorRaised()) return true; for (JCDiagnostic d: deferredDiagnosticHandler.getDiagnostics()) { switch (d.getKind()) { case WARNING: if (werror) return true; break; case ERROR: if (fatalErrors || !d.isFlagSet(RECOVERABLE)) return true; break; } } return false; }
Example #9
Source File: StructuralMostSpecificTest.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
public void report(Diagnostic<? extends JavaFileObject> diagnostic) { try { if (diagnostic.getKind() == Diagnostic.Kind.ERROR && diagnostic.getCode().equals("compiler.err.ref.ambiguous")) { ambiguityFound = true; } else if (diagnostic.getKind() == Diagnostic.Kind.NOTE && diagnostic.getCode() .equals("compiler.note.verbose.resolve.multi")) { ClientCodeWrapper.DiagnosticSourceUnwrapper dsu = (ClientCodeWrapper.DiagnosticSourceUnwrapper)diagnostic; JCDiagnostic.MultilineDiagnostic mdiag = (JCDiagnostic.MultilineDiagnostic)dsu.d; int mostSpecificIndex = (Integer)mdiag.getArgs()[2]; mostSpecificSig = ((JCDiagnostic)mdiag.getSubdiagnostics() .get(mostSpecificIndex)).getArgs()[1].toString(); } } catch (RuntimeException t) { t.printStackTrace(); throw t; } }
Example #10
Source File: JavacProcessingEnvironment.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** Return whether or not an unrecoverable error has occurred. */ boolean unrecoverableError() { if (messager.errorRaised()) return true; for (JCDiagnostic d: deferredDiagnosticHandler.getDiagnostics()) { switch (d.getKind()) { case WARNING: if (werror) return true; break; case ERROR: if (fatalErrors || !d.isFlagSet(RECOVERABLE)) return true; break; } } return false; }
Example #11
Source File: StructuralMostSpecificTest.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
public void report(Diagnostic<? extends JavaFileObject> diagnostic) { try { if (diagnostic.getKind() == Diagnostic.Kind.ERROR && diagnostic.getCode().equals("compiler.err.ref.ambiguous")) { ambiguityFound = true; } else if (diagnostic.getKind() == Diagnostic.Kind.NOTE && diagnostic.getCode() .equals("compiler.note.verbose.resolve.multi")) { ClientCodeWrapper.DiagnosticSourceUnwrapper dsu = (ClientCodeWrapper.DiagnosticSourceUnwrapper)diagnostic; JCDiagnostic.MultilineDiagnostic mdiag = (JCDiagnostic.MultilineDiagnostic)dsu.d; int mostSpecificIndex = (Integer)mdiag.getArgs()[2]; mostSpecificSig = ((JCDiagnostic)mdiag.getSubdiagnostics() .get(mostSpecificIndex)).getArgs()[1].toString(); } } catch (RuntimeException t) { t.printStackTrace(); throw t; } }
Example #12
Source File: LambdaToMethod.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 6 votes |
private LambdaToMethod(Context context) { context.put(unlambdaKey, this); diags = JCDiagnostic.Factory.instance(context); log = Log.instance(context); lower = Lower.instance(context); names = Names.instance(context); syms = Symtab.instance(context); rs = Resolve.instance(context); operators = Operators.instance(context); make = TreeMaker.instance(context); types = Types.instance(context); transTypes = TransTypes.instance(context); analyzer = new LambdaAnalyzerPreprocessor(); Options options = Options.instance(context); dumpLambdaToMethodStats = options.isSet("debug.dumpLambdaToMethodStats"); attr = Attr.instance(context); forceSerializable = options.isSet("forceSerializable"); }
Example #13
Source File: JavacProcessingEnvironment.java From javaide with GNU General Public License v3.0 | 6 votes |
/** Return whether or not an unrecoverable error has occurred. */ boolean unrecoverableError() { if (messager.errorRaised()) return true; for (JCDiagnostic d: log.deferredDiagnostics) { switch (d.getKind()) { case WARNING: if (werror) return true; break; case ERROR: if (fatalErrors || !d.isFlagSet(RECOVERABLE)) return true; break; } } return false; }
Example #14
Source File: ResolveHarness.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
@Override void process(Diagnostic<? extends JavaFileObject> diagnostic) { Element siteSym = getSiteSym(diagnostic); if (siteSym.getSimpleName().length() != 0 && ((Symbol)siteSym).outermostClass().getAnnotation(TraceResolve.class) == null) { return; } int candidateIdx = 0; for (JCDiagnostic d : subDiagnostics(diagnostic)) { boolean isMostSpecific = candidateIdx++ == mostSpecific(diagnostic); VerboseCandidateSubdiagProcessor subProc = new VerboseCandidateSubdiagProcessor(isMostSpecific, phase(diagnostic), success(diagnostic)); if (subProc.matches(d)) { subProc.process(d); } else { throw new AssertionError("Bad subdiagnostic: " + d.getCode()); } } }
Example #15
Source File: JavacTrees.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
private void printMessage(Diagnostic.Kind kind, CharSequence msg, JCDiagnostic.DiagnosticPosition pos, com.sun.source.tree.CompilationUnitTree root) { JavaFileObject oldSource = null; JavaFileObject newSource = null; newSource = root.getSourceFile(); if (newSource == null) { pos = null; } else { oldSource = log.useSource(newSource); } try { switch (kind) { case ERROR: boolean prev = log.multipleErrors; try { log.error(pos, "proc.messager", msg.toString()); } finally { log.multipleErrors = prev; } break; case WARNING: log.warning(pos, "proc.messager", msg.toString()); break; case MANDATORY_WARNING: log.mandatoryWarning(pos, "proc.messager", msg.toString()); break; default: log.note(pos, "proc.messager", msg.toString()); } } finally { if (oldSource != null) log.useSource(oldSource); } }
Example #16
Source File: JavacProcessingEnvironment.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
void showDiagnostics(boolean showAll) { Set<JCDiagnostic.Kind> kinds = EnumSet.allOf(JCDiagnostic.Kind.class); if (!showAll) { // suppress errors, which are all presumed to be transient resolve errors kinds.remove(JCDiagnostic.Kind.ERROR); } deferredDiagnosticHandler.reportDeferredDiagnostics(kinds); log.popDiagnosticHandler(deferredDiagnosticHandler); }
Example #17
Source File: ClientCodeWrapper.java From hottub with GNU General Public License v2.0 | 5 votes |
@SuppressWarnings("unchecked") private <T> Diagnostic<T> unwrap(final Diagnostic<T> diagnostic) { if (diagnostic instanceof JCDiagnostic) { JCDiagnostic d = (JCDiagnostic) diagnostic; return (Diagnostic<T>) new DiagnosticSourceUnwrapper(d); } else { return diagnostic; } }
Example #18
Source File: Example.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
/** * Scan a diagnostic for resource keys. This will not detect additional * sub diagnostics that might be generated by a rich diagnostic formatter. */ private static void scanForKeys(JCDiagnostic d, Set<String> keys) { keys.add(d.getCode()); for (Object o: d.getArgs()) { if (o instanceof JCDiagnostic) { scanForKeys((JCDiagnostic) o, keys); } } for (JCDiagnostic sd: d.getSubdiagnostics()) scanForKeys(sd, keys); }
Example #19
Source File: JavacProcessingEnvironment.java From java-n-IDE-for-Android with Apache License 2.0 | 5 votes |
/** * Free resources related to annotation processing. */ public void close() { filer.close(); if (discoveredProcs != null) // Make calling close idempotent discoveredProcs.close(); discoveredProcs = null; if (processorClassLoader != null && processorClassLoader instanceof Closeable) { try { ((Closeable) processorClassLoader).close(); } catch (IOException e) { JCDiagnostic msg = diags.fragment("fatal.err.cant.close.loader"); throw new FatalError(msg, e); } } }
Example #20
Source File: TestLog.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
public void visitIf(JCTree.JCIf tree) { JCDiagnostic.DiagnosticPosition nil = null; // generate dummy messages to exercise the log API log.error("not.stmt"); log.error(tree.pos, "not.stmt"); log.error(tree.pos(), "not.stmt"); log.error(nil, "not.stmt"); log.warning("div.zero"); log.warning(tree.pos, "div.zero"); log.warning(tree.pos(), "div.zero"); log.warning(nil, "div.zero"); }
Example #21
Source File: FormattedDiagnostic.java From bazel with Apache License 2.0 | 5 votes |
@Override public void report(Diagnostic<? extends JavaFileObject> diagnostic) { DiagnosticFormatter<JCDiagnostic> formatter = Log.instance(context).getDiagnosticFormatter(); Locale locale = JavacMessages.instance(context).getCurrentLocale(); String formatted = formatter.format((JCDiagnostic) diagnostic, locale); LintCategory lintCategory = ((JCDiagnostic) diagnostic).getLintCategory(); FormattedDiagnostic formattedDiagnostic = new FormattedDiagnostic( diagnostic, formatted, lintCategory != null ? lintCategory.option : null); diagnostics.add(formattedDiagnostic); if (failFast && diagnostic.getKind().equals(Diagnostic.Kind.ERROR)) { throw new FailFastException(formatted); } }
Example #22
Source File: ClientCodeWrapper.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
@SuppressWarnings("unchecked") private <T> Diagnostic<T> unwrap(final Diagnostic<T> diagnostic) { if (diagnostic instanceof JCDiagnostic) { JCDiagnostic d = (JCDiagnostic) diagnostic; return (Diagnostic<T>) new DiagnosticSourceUnwrapper(d); } else { return diagnostic; } }
Example #23
Source File: TestSuppression.java From hottub with GNU General Public License v2.0 | 5 votes |
private JCDiagnostic unwrap(Diagnostic<? extends JavaFileObject> diagnostic) { if (diagnostic instanceof JCDiagnostic) return (JCDiagnostic) diagnostic; if (diagnostic instanceof ClientCodeWrapper.DiagnosticSourceUnwrapper) return ((ClientCodeWrapper.DiagnosticSourceUnwrapper)diagnostic).d; throw new IllegalArgumentException(); }
Example #24
Source File: T7116676.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
public void testThroughFormatterFormat() throws IOException { final JavaCompiler tool = ToolProvider.getSystemJavaCompiler(); DiagnosticChecker dc = new DiagnosticChecker("compiler.err.prob.found.req"); JavacTask ct = (JavacTask)tool.getTask(null, null, dc, null, null, Arrays.asList(new JavaSource())); ct.analyze(); DiagnosticFormatter<JCDiagnostic> formatter = Log.instance(((JavacTaskImpl) ct).getContext()).getDiagnosticFormatter(); String msg = formatter.formatMessage(dc.diag, Locale.getDefault()); //no redundant package qualifiers Assert.check(msg.indexOf("java.") == -1, msg); }
Example #25
Source File: Messager.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * Constructor * @param programName Name of the program (for error messages). * @param errWriter Stream for error messages * @param warnWriter Stream for warnings * @param noticeWriter Stream for other messages */ @SuppressWarnings("deprecation") protected Messager(Context context, String programName, PrintWriter errWriter, PrintWriter warnWriter, PrintWriter noticeWriter) { super(context, errWriter, warnWriter, noticeWriter); messages = JavacMessages.instance(context); messages.add(locale -> ResourceBundle.getBundle("com.sun.tools.javadoc.resources.javadoc", locale)); javadocDiags = new JCDiagnostic.Factory(messages, "javadoc"); this.programName = programName; }
Example #26
Source File: JavacProcessingEnvironment.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
void showDiagnostics(boolean showAll) { Set<JCDiagnostic.Kind> kinds = EnumSet.allOf(JCDiagnostic.Kind.class); if (!showAll) { // suppress errors, which are all presumed to be transient resolve errors kinds.remove(JCDiagnostic.Kind.ERROR); } deferredDiagnosticHandler.reportDeferredDiagnostics(kinds); log.popDiagnosticHandler(deferredDiagnosticHandler); }
Example #27
Source File: TestMetafactoryBridges.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
JCDiagnostic asJCDiagnostic(Diagnostic<? extends JavaFileObject> diagnostic) { if (diagnostic instanceof JCDiagnostic) { return (JCDiagnostic)diagnostic; } else if (diagnostic instanceof DiagnosticSourceUnwrapper) { return ((DiagnosticSourceUnwrapper)diagnostic).d; } else { throw new AssertionError("Cannot convert diagnostic to JCDiagnostic: " + diagnostic.getClass().getName()); } }
Example #28
Source File: AbstractCodingRulesAnalyzer.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public AbstractCodingRulesAnalyzer(JavacTask task) { BasicJavacTask impl = (BasicJavacTask)task; Context context = impl.getContext(); log = Log.instance(context); options = Options.instance(context); rawDiagnostics = options.isSet("rawDiagnostics"); diags = JCDiagnostic.Factory.instance(context); messages = new Messages(); syms = Symtab.instance(context); elements = JavacElements.instance(context); types = JavacTypes.instance(context); }
Example #29
Source File: ResolveHarness.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
MethodType getSig(Diagnostic<? extends JavaFileObject> diagnostic) { JCDiagnostic details = (JCDiagnostic)asJCDiagnostic(diagnostic).getArgs()[2]; if (details == null) { return null; } else if (details instanceof JCDiagnostic) { return details.getCode().equals("compiler.misc.full.inst.sig") ? (MethodType)details.getArgs()[0] : null; } else { throw new AssertionError("Bad diagnostic arg: " + details); } }
Example #30
Source File: Utilities.java From netbeans with Apache License 2.0 | 5 votes |
private static TypeMirror attributeTree(JavacTaskImpl jti, Tree tree, Scope scope, final List<Diagnostic<? extends JavaFileObject>> errors) { Log log = Log.instance(jti.getContext()); JavaFileObject prev = log.useSource(new DummyJFO()); Log.DiagnosticHandler discardHandler = new Log.DiscardDiagnosticHandler(log) { @Override public void report(JCDiagnostic diag) { errors.add(diag); } }; NBResolve resolve = NBResolve.instance(jti.getContext()); resolve.disableAccessibilityChecks(); // Enter enter = Enter.instance(jti.getContext()); // enter.shadowTypeEnvs(true); // ArgumentAttr argumentAttr = ArgumentAttr.instance(jti.getContext()); // ArgumentAttr.LocalCacheContext cacheContext = argumentAttr.withLocalCacheContext(); try { Attr attr = Attr.instance(jti.getContext()); Env<AttrContext> env = ((JavacScope) scope).getEnv(); if (tree instanceof JCExpression) return attr.attribExpr((JCTree) tree,env, Type.noType); return attr.attribStat((JCTree) tree,env); } finally { // cacheContext.leave(); log.useSource(prev); log.popDiagnosticHandler(discardHandler); resolve.restoreAccessbilityChecks(); // enter.shadowTypeEnvs(false); } }