本文整理汇总了Java中com.sun.tools.javac.api.JavacTrees.getPath方法的典型用法代码示例。如果您正苦于以下问题:Java JavacTrees.getPath方法的具体用法?Java JavacTrees.getPath怎么用?Java JavacTrees.getPath使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sun.tools.javac.api.JavacTrees
的用法示例。
在下文中一共展示了JavacTrees.getPath方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testTreePathForModuleDecl
import com.sun.tools.javac.api.JavacTrees; //导入方法依赖的package包/类
@Test
public void testTreePathForModuleDecl(Path base) throws Exception {
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
try (StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null)) {
Path src = base.resolve("src");
tb.writeJavaFiles(src, "/** Test module */ module m1x {}");
Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(findJavaFiles(src));
JavacTask task = (JavacTask) compiler.getTask(null, fm, null, null, null, files);
task.analyze();
JavacTrees trees = JavacTrees.instance(task);
ModuleElement mdle = (ModuleElement) task.getElements().getModuleElement("m1x");
TreePath path = trees.getPath(mdle);
assertNotNull("path", path);
ModuleElement mdle1 = (ModuleElement) trees.getElement(path);
assertNotNull("mdle1", mdle1);
DocCommentTree docCommentTree = trees.getDocCommentTree(mdle);
assertNotNull("docCommentTree", docCommentTree);
}
}
示例2: testTreePathForModuleDeclWithImport
import com.sun.tools.javac.api.JavacTrees; //导入方法依赖的package包/类
@Test
public void testTreePathForModuleDeclWithImport(Path base) throws Exception {
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
try (StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null)) {
Path src = base.resolve("src");
tb.writeJavaFiles(src, "import java.lang.Deprecated; /** Test module */ @Deprecated module m1x {}");
Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(findJavaFiles(src));
JavacTask task = (JavacTask) compiler.getTask(null, fm, null, null, null, files);
task.analyze();
JavacTrees trees = JavacTrees.instance(task);
ModuleElement mdle = (ModuleElement) task.getElements().getModuleElement("m1x");
TreePath path = trees.getPath(mdle);
assertNotNull("path", path);
ModuleElement mdle1 = (ModuleElement) trees.getElement(path);
assertNotNull("mdle1", mdle1);
DocCommentTree docCommentTree = trees.getDocCommentTree(mdle);
assertNotNull("docCommentTree", docCommentTree);
}
}
示例3: getClassSymbol
import com.sun.tools.javac.api.JavacTrees; //导入方法依赖的package包/类
public Pair<Symbol.ClassSymbol, JCTree.JCCompilationUnit> getClassSymbol( BasicJavacTask javacTask, String fqn )
{
JavacElements elementUtils = JavacElements.instance( javacTask.getContext() );
Symbol.ClassSymbol typeElement = elementUtils.getTypeElement( fqn );
JavacTrees trees = JavacTrees.instance( javacTask.getContext() );
TreePath path = trees.getPath( typeElement );
if( path != null )
{
return new Pair<>( typeElement, (JCTree.JCCompilationUnit)path.getCompilationUnit() );
}
else
{
// TreePath is only applicable to a source file;
// if fqn is not a source file, there is no compilation unit available
return new Pair<>( typeElement, null );
}
}
示例4: testTreePathForModuleDecl
import com.sun.tools.javac.api.JavacTrees; //导入方法依赖的package包/类
@Test
public void testTreePathForModuleDecl(Path base) throws Exception {
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
try (StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null)) {
Path src = base.resolve("src");
tb.writeJavaFiles(src, "/** Test module */ module m1 {}");
Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(findJavaFiles(src));
JavacTask task = (JavacTask) compiler.getTask(null, fm, null, null, null, files);
task.analyze();
JavacTrees trees = JavacTrees.instance(task);
ModuleElement mdle = (ModuleElement) task.getElements().getModuleElement("m1");
TreePath path = trees.getPath(mdle);
assertNotNull("path", path);
ModuleElement mdle1 = (ModuleElement) trees.getElement(path);
assertNotNull("mdle1", mdle1);
DocCommentTree docCommentTree = trees.getDocCommentTree(mdle);
assertNotNull("docCommentTree", docCommentTree);
}
}
示例5: getDiagSource
import com.sun.tools.javac.api.JavacTrees; //导入方法依赖的package包/类
private String getDiagSource(Element e) {
if (e == null) {
return programName;
}
JavacTrees trees = JavacTrees.instance(context);
TreePath path = trees.getPath(e);
DocSourcePositions sourcePositions = trees.getSourcePositions();
JCTree tree = trees.getTree(e);
CompilationUnitTree cu = path.getCompilationUnit();
long spos = sourcePositions.getStartPosition(cu, tree);
long lineNumber = cu.getLineMap().getLineNumber(spos);
String fname = cu.getSourceFile().getName();
String posString = fname + ":" + lineNumber;
return posString;
}