Java Code Examples for com.sun.tools.javac.model.JavacElements#getTreeAndTopLevel()
The following examples show how to use
com.sun.tools.javac.model.JavacElements#getTreeAndTopLevel() .
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: JavacMessager.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
/** * Prints a message of the specified kind at the location of the * annotation value inside the annotation mirror of the annotated * element. * * @param kind the kind of message * @param msg the message, or an empty string if none * @param e the annotated element * @param a the annotation containing the annotaiton value * @param v the annotation value to use as a position hint */ public void printMessage(Diagnostic.Kind kind, CharSequence msg, Element e, AnnotationMirror a, AnnotationValue v) { JavaFileObject oldSource = null; JavaFileObject newSource = null; JCDiagnostic.DiagnosticPosition pos = null; JavacElements elemUtils = processingEnv.getElementUtils(); Pair<JCTree, JCCompilationUnit> treeTop = elemUtils.getTreeAndTopLevel(e, a, v); if (treeTop != null) { newSource = treeTop.snd.sourcefile; if (newSource != null) { // save the old version and reinstate it later oldSource = log.useSource(newSource); pos = treeTop.fst.pos(); } } try { switch (kind) { case ERROR: errorCount++; boolean prev = log.multipleErrors; log.multipleErrors = true; try { log.error(pos, "proc.messager", msg.toString()); } finally { log.multipleErrors = prev; } break; case WARNING: warningCount++; log.warning(pos, "proc.messager", msg.toString()); break; case MANDATORY_WARNING: warningCount++; log.mandatoryWarning(pos, "proc.messager", msg.toString()); break; default: log.note(pos, "proc.messager", msg.toString()); break; } } finally { // reinstate the saved version, only if it was saved earlier if (newSource != null) log.useSource(oldSource); } }
Example 2
Source File: JavacMessager.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
/** * Prints a message of the specified kind at the location of the * annotation value inside the annotation mirror of the annotated * element. * * @param kind the kind of message * @param msg the message, or an empty string if none * @param e the annotated element * @param a the annotation containing the annotaiton value * @param v the annotation value to use as a position hint */ public void printMessage(Diagnostic.Kind kind, CharSequence msg, Element e, AnnotationMirror a, AnnotationValue v) { JavaFileObject oldSource = null; JavaFileObject newSource = null; JCDiagnostic.DiagnosticPosition pos = null; JavacElements elemUtils = processingEnv.getElementUtils(); Pair<JCTree, JCCompilationUnit> treeTop = elemUtils.getTreeAndTopLevel(e, a, v); if (treeTop != null) { newSource = treeTop.snd.sourcefile; if (newSource != null) { // save the old version and reinstate it later oldSource = log.useSource(newSource); pos = treeTop.fst.pos(); } } try { switch (kind) { case ERROR: errorCount++; boolean prev = log.multipleErrors; log.multipleErrors = true; try { log.error(pos, "proc.messager", msg.toString()); } finally { log.multipleErrors = prev; } break; case WARNING: warningCount++; log.warning(pos, "proc.messager", msg.toString()); break; case MANDATORY_WARNING: warningCount++; log.mandatoryWarning(pos, "proc.messager", msg.toString()); break; default: log.note(pos, "proc.messager", msg.toString()); break; } } finally { // reinstate the saved version, only if it was saved earlier if (newSource != null) log.useSource(oldSource); } }
Example 3
Source File: JavacMessager.java From java-n-IDE-for-Android with Apache License 2.0 | 4 votes |
/** * Prints a message of the specified kind at the location of the * annotation value inside the annotation mirror of the annotated * element. * * @param kind the kind of message * @param msg the message, or an empty string if none * @param e the annotated element * @param a the annotation containing the annotaiton value * @param v the annotation value to use as a position hint */ public void printMessage(Diagnostic.Kind kind, CharSequence msg, Element e, AnnotationMirror a, AnnotationValue v) { JavaFileObject oldSource = null; JavaFileObject newSource = null; JCDiagnostic.DiagnosticPosition pos = null; JavacElements elemUtils = processingEnv.getElementUtils(); Pair<JCTree, JCCompilationUnit> treeTop = elemUtils.getTreeAndTopLevel(e, a, v); if (treeTop != null) { newSource = treeTop.snd.sourcefile; if (newSource != null) { oldSource = log.useSource(newSource); pos = treeTop.fst.pos(); } } try { switch (kind) { case ERROR: errorCount++; boolean prev = log.multipleErrors; log.multipleErrors = true; try { log.error(pos, "proc.messager", msg.toString()); } finally { log.multipleErrors = prev; } break; case WARNING: warningCount++; log.warning(pos, "proc.messager", msg.toString()); break; case MANDATORY_WARNING: warningCount++; log.mandatoryWarning(pos, "proc.messager", msg.toString()); break; default: log.note(pos, "proc.messager", msg.toString()); break; } } finally { if (oldSource != null) log.useSource(oldSource); } }
Example 4
Source File: JavacMessager.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
/** * Prints a message of the specified kind at the location of the * annotation value inside the annotation mirror of the annotated * element. * * @param kind the kind of message * @param msg the message, or an empty string if none * @param e the annotated element * @param a the annotation containing the annotaiton value * @param v the annotation value to use as a position hint */ public void printMessage(Diagnostic.Kind kind, CharSequence msg, Element e, AnnotationMirror a, AnnotationValue v) { JavaFileObject oldSource = null; JavaFileObject newSource = null; JCDiagnostic.DiagnosticPosition pos = null; JavacElements elemUtils = processingEnv.getElementUtils(); Pair<JCTree, JCCompilationUnit> treeTop = elemUtils.getTreeAndTopLevel(e, a, v); if (treeTop != null) { newSource = treeTop.snd.sourcefile; if (newSource != null) { // save the old version and reinstate it later oldSource = log.useSource(newSource); pos = treeTop.fst.pos(); } } try { switch (kind) { case ERROR: errorCount++; boolean prev = log.multipleErrors; log.multipleErrors = true; try { log.error(pos, "proc.messager", msg.toString()); } finally { log.multipleErrors = prev; } break; case WARNING: warningCount++; log.warning(pos, "proc.messager", msg.toString()); break; case MANDATORY_WARNING: warningCount++; log.mandatoryWarning(pos, "proc.messager", msg.toString()); break; default: log.note(pos, "proc.messager", msg.toString()); break; } } finally { // reinstate the saved version, only if it was saved earlier if (newSource != null) log.useSource(oldSource); } }
Example 5
Source File: JavacMessager.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * Prints a message of the specified kind at the location of the * annotation value inside the annotation mirror of the annotated * element. * * @param kind the kind of message * @param msg the message, or an empty string if none * @param e the annotated element * @param a the annotation containing the annotaiton value * @param v the annotation value to use as a position hint */ @DefinedBy(Api.ANNOTATION_PROCESSING) public void printMessage(Diagnostic.Kind kind, CharSequence msg, Element e, AnnotationMirror a, AnnotationValue v) { JavaFileObject oldSource = null; JavaFileObject newSource = null; JCDiagnostic.DiagnosticPosition pos = null; JavacElements elemUtils = processingEnv.getElementUtils(); Pair<JCTree, JCCompilationUnit> treeTop = elemUtils.getTreeAndTopLevel(e, a, v); if (treeTop != null) { newSource = treeTop.snd.sourcefile; if (newSource != null) { // save the old version and reinstate it later oldSource = log.useSource(newSource); pos = treeTop.fst.pos(); } } try { switch (kind) { case ERROR: errorCount++; log.error(DiagnosticFlag.MULTIPLE, pos, Errors.ProcMessager(msg.toString())); break; case WARNING: warningCount++; log.warning(pos, Warnings.ProcMessager(msg.toString())); break; case MANDATORY_WARNING: warningCount++; log.mandatoryWarning(pos, Warnings.ProcMessager(msg.toString())); break; default: log.note(pos, Notes.ProcMessager(msg.toString())); break; } } finally { // reinstate the saved version, only if it was saved earlier if (newSource != null) log.useSource(oldSource); } }
Example 6
Source File: JavacMessager.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
/** * Prints a message of the specified kind at the location of the * annotation value inside the annotation mirror of the annotated * element. * * @param kind the kind of message * @param msg the message, or an empty string if none * @param e the annotated element * @param a the annotation containing the annotaiton value * @param v the annotation value to use as a position hint */ public void printMessage(Diagnostic.Kind kind, CharSequence msg, Element e, AnnotationMirror a, AnnotationValue v) { JavaFileObject oldSource = null; JavaFileObject newSource = null; JCDiagnostic.DiagnosticPosition pos = null; JavacElements elemUtils = processingEnv.getElementUtils(); Pair<JCTree, JCCompilationUnit> treeTop = elemUtils.getTreeAndTopLevel(e, a, v); if (treeTop != null) { newSource = treeTop.snd.sourcefile; if (newSource != null) { // save the old version and reinstate it later oldSource = log.useSource(newSource); pos = treeTop.fst.pos(); } } try { switch (kind) { case ERROR: errorCount++; boolean prev = log.multipleErrors; log.multipleErrors = true; try { log.error(pos, "proc.messager", msg.toString()); } finally { log.multipleErrors = prev; } break; case WARNING: warningCount++; log.warning(pos, "proc.messager", msg.toString()); break; case MANDATORY_WARNING: warningCount++; log.mandatoryWarning(pos, "proc.messager", msg.toString()); break; default: log.note(pos, "proc.messager", msg.toString()); break; } } finally { // reinstate the saved version, only if it was saved earlier if (newSource != null) log.useSource(oldSource); } }
Example 7
Source File: JavacMessager.java From javaide with GNU General Public License v3.0 | 4 votes |
/** * Prints a message of the specified kind at the location of the * annotation value inside the annotation mirror of the annotated * element. * * @param kind the kind of message * @param msg the message, or an empty string if none * @param e the annotated element * @param a the annotation containing the annotaiton value * @param v the annotation value to use as a position hint */ public void printMessage(Diagnostic.Kind kind, CharSequence msg, Element e, AnnotationMirror a, AnnotationValue v) { JavaFileObject oldSource = null; JavaFileObject newSource = null; JCDiagnostic.DiagnosticPosition pos = null; JavacElements elemUtils = processingEnv.getElementUtils(); Pair<JCTree, JCCompilationUnit> treeTop = elemUtils.getTreeAndTopLevel(e, a, v); if (treeTop != null) { newSource = treeTop.snd.sourcefile; if (newSource != null) { oldSource = log.useSource(newSource); pos = treeTop.fst.pos(); } } try { switch (kind) { case ERROR: errorCount++; boolean prev = log.multipleErrors; log.multipleErrors = true; try { log.error(pos, "proc.messager", msg.toString()); } finally { log.multipleErrors = prev; } break; case WARNING: warningCount++; log.warning(pos, "proc.messager", msg.toString()); break; case MANDATORY_WARNING: warningCount++; log.mandatoryWarning(pos, "proc.messager", msg.toString()); break; default: log.note(pos, "proc.messager", msg.toString()); break; } } finally { if (oldSource != null) log.useSource(oldSource); } }
Example 8
Source File: JavacMessager.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
/** * Prints a message of the specified kind at the location of the * annotation value inside the annotation mirror of the annotated * element. * * @param kind the kind of message * @param msg the message, or an empty string if none * @param e the annotated element * @param a the annotation containing the annotaiton value * @param v the annotation value to use as a position hint */ @DefinedBy(Api.ANNOTATION_PROCESSING) public void printMessage(Diagnostic.Kind kind, CharSequence msg, Element e, AnnotationMirror a, AnnotationValue v) { JavaFileObject oldSource = null; JavaFileObject newSource = null; JCDiagnostic.DiagnosticPosition pos = null; JavacElements elemUtils = processingEnv.getElementUtils(); Pair<JCTree, JCCompilationUnit> treeTop = elemUtils.getTreeAndTopLevel(e, a, v); if (treeTop != null) { newSource = treeTop.snd.sourcefile; if (newSource != null) { // save the old version and reinstate it later oldSource = log.useSource(newSource); pos = treeTop.fst.pos(); } } try { switch (kind) { case ERROR: errorCount++; log.error(DiagnosticFlag.MULTIPLE, pos, "proc.messager", msg.toString()); break; case WARNING: warningCount++; log.warning(pos, "proc.messager", msg.toString()); break; case MANDATORY_WARNING: warningCount++; log.mandatoryWarning(pos, "proc.messager", msg.toString()); break; default: log.note(pos, "proc.messager", msg.toString()); break; } } finally { // reinstate the saved version, only if it was saved earlier if (newSource != null) log.useSource(oldSource); } }
Example 9
Source File: JavacMessager.java From hottub with GNU General Public License v2.0 | 4 votes |
/** * Prints a message of the specified kind at the location of the * annotation value inside the annotation mirror of the annotated * element. * * @param kind the kind of message * @param msg the message, or an empty string if none * @param e the annotated element * @param a the annotation containing the annotaiton value * @param v the annotation value to use as a position hint */ public void printMessage(Diagnostic.Kind kind, CharSequence msg, Element e, AnnotationMirror a, AnnotationValue v) { JavaFileObject oldSource = null; JavaFileObject newSource = null; JCDiagnostic.DiagnosticPosition pos = null; JavacElements elemUtils = processingEnv.getElementUtils(); Pair<JCTree, JCCompilationUnit> treeTop = elemUtils.getTreeAndTopLevel(e, a, v); if (treeTop != null) { newSource = treeTop.snd.sourcefile; if (newSource != null) { // save the old version and reinstate it later oldSource = log.useSource(newSource); pos = treeTop.fst.pos(); } } try { switch (kind) { case ERROR: errorCount++; boolean prev = log.multipleErrors; log.multipleErrors = true; try { log.error(pos, "proc.messager", msg.toString()); } finally { log.multipleErrors = prev; } break; case WARNING: warningCount++; log.warning(pos, "proc.messager", msg.toString()); break; case MANDATORY_WARNING: warningCount++; log.mandatoryWarning(pos, "proc.messager", msg.toString()); break; default: log.note(pos, "proc.messager", msg.toString()); break; } } finally { // reinstate the saved version, only if it was saved earlier if (newSource != null) log.useSource(oldSource); } }
Example 10
Source File: JavacMessager.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
/** * Prints a message of the specified kind at the location of the * annotation value inside the annotation mirror of the annotated * element. * * @param kind the kind of message * @param msg the message, or an empty string if none * @param e the annotated element * @param a the annotation containing the annotaiton value * @param v the annotation value to use as a position hint */ public void printMessage(Diagnostic.Kind kind, CharSequence msg, Element e, AnnotationMirror a, AnnotationValue v) { JavaFileObject oldSource = null; JavaFileObject newSource = null; JCDiagnostic.DiagnosticPosition pos = null; JavacElements elemUtils = processingEnv.getElementUtils(); Pair<JCTree, JCCompilationUnit> treeTop = elemUtils.getTreeAndTopLevel(e, a, v); if (treeTop != null) { newSource = treeTop.snd.sourcefile; if (newSource != null) { // save the old version and reinstate it later oldSource = log.useSource(newSource); pos = treeTop.fst.pos(); } } try { switch (kind) { case ERROR: errorCount++; boolean prev = log.multipleErrors; log.multipleErrors = true; try { log.error(pos, "proc.messager", msg.toString()); } finally { log.multipleErrors = prev; } break; case WARNING: warningCount++; log.warning(pos, "proc.messager", msg.toString()); break; case MANDATORY_WARNING: warningCount++; log.mandatoryWarning(pos, "proc.messager", msg.toString()); break; default: log.note(pos, "proc.messager", msg.toString()); break; } } finally { // reinstate the saved version, only if it was saved earlier if (newSource != null) log.useSource(oldSource); } }
Example 11
Source File: JavacMessager.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
/** * Prints a message of the specified kind at the location of the * annotation value inside the annotation mirror of the annotated * element. * * @param kind the kind of message * @param msg the message, or an empty string if none * @param e the annotated element * @param a the annotation containing the annotaiton value * @param v the annotation value to use as a position hint */ public void printMessage(Diagnostic.Kind kind, CharSequence msg, Element e, AnnotationMirror a, AnnotationValue v) { JavaFileObject oldSource = null; JavaFileObject newSource = null; JCDiagnostic.DiagnosticPosition pos = null; JavacElements elemUtils = processingEnv.getElementUtils(); Pair<JCTree, JCCompilationUnit> treeTop = elemUtils.getTreeAndTopLevel(e, a, v); if (treeTop != null) { newSource = treeTop.snd.sourcefile; if (newSource != null) { // save the old version and reinstate it later oldSource = log.useSource(newSource); pos = treeTop.fst.pos(); } } try { switch (kind) { case ERROR: errorCount++; boolean prev = log.multipleErrors; log.multipleErrors = true; try { log.error(pos, "proc.messager", msg.toString()); } finally { log.multipleErrors = prev; } break; case WARNING: warningCount++; log.warning(pos, "proc.messager", msg.toString()); break; case MANDATORY_WARNING: warningCount++; log.mandatoryWarning(pos, "proc.messager", msg.toString()); break; default: log.note(pos, "proc.messager", msg.toString()); break; } } finally { // reinstate the saved version, only if it was saved earlier if (newSource != null) log.useSource(oldSource); } }