本文整理匯總了Java中com.sun.source.tree.CompilationUnitTree.getSourceFile方法的典型用法代碼示例。如果您正苦於以下問題:Java CompilationUnitTree.getSourceFile方法的具體用法?Java CompilationUnitTree.getSourceFile怎麽用?Java CompilationUnitTree.getSourceFile使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.sun.source.tree.CompilationUnitTree
的用法示例。
在下文中一共展示了CompilationUnitTree.getSourceFile方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: TaskEvent
import com.sun.source.tree.CompilationUnitTree; //導入方法依賴的package包/類
public TaskEvent(Kind kind, CompilationUnitTree unit) {
this(kind, unit.getSourceFile(), unit, null);
}
示例2: printMessage
import com.sun.source.tree.CompilationUnitTree; //導入方法依賴的package包/類
/**
* Prints a message of the specified kind at the location of the
* tree within the provided compilation unit
*
* @param kind the kind of message
* @param msg the message, or an empty string if none
* @param t the tree to use as a position hint
* @param root the compilation unit that contains tree
*/
public void printMessage(Diagnostic.Kind kind, CharSequence msg,
Tree t,
CompilationUnitTree root) {
JavaFileObject oldSource = null;
JavaFileObject newSource = null;
JCDiagnostic.DiagnosticPosition pos = null;
newSource = root.getSourceFile();
if (newSource != null) {
oldSource = log.useSource(newSource);
pos = ((JCTree) t).pos();
}
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);
}
}
示例3: TaskEvent
import com.sun.source.tree.CompilationUnitTree; //導入方法依賴的package包/類
/**
* Creates a task event for a given kind and compilation unit.
* The source file is set from the compilation unit,
* and the type element is set to {@code null}.
* @param kind the kind of the event
* @param unit the compilation unit
*/
public TaskEvent(Kind kind, CompilationUnitTree unit) {
this(kind, unit.getSourceFile(), unit, null);
}