本文整理汇总了Java中com.sun.tools.javac.model.JavacElements.getTreeAndTopLevel方法的典型用法代码示例。如果您正苦于以下问题:Java JavacElements.getTreeAndTopLevel方法的具体用法?Java JavacElements.getTreeAndTopLevel怎么用?Java JavacElements.getTreeAndTopLevel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sun.tools.javac.model.JavacElements
的用法示例。
在下文中一共展示了JavacElements.getTreeAndTopLevel方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: printMessage
import com.sun.tools.javac.model.JavacElements; //导入方法依赖的package包/类
/**
* 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);
}
}
示例2: printMessage
import com.sun.tools.javac.model.JavacElements; //导入方法依赖的package包/类
/**
* 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);
}
}
示例3: printMessage
import com.sun.tools.javac.model.JavacElements; //导入方法依赖的package包/类
/**
* 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);
}
}
示例4: printMessage
import com.sun.tools.javac.model.JavacElements; //导入方法依赖的package包/类
/**
* 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);
}
}
示例5: printMessage
import com.sun.tools.javac.model.JavacElements; //导入方法依赖的package包/类
/**
* 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:
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());
break;
}
} finally {
if (oldSource != null)
log.useSource(oldSource);
}
}