当前位置: 首页>>代码示例>>Java>>正文


Java JavacTrees.getPath方法代码示例

本文整理汇总了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);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:26,代码来源:ModuleInfoTreeAccess.java

示例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);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:25,代码来源:ModuleInfoTreeAccess.java

示例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 );
  }
}
 
开发者ID:manifold-systems,项目名称:manifold,代码行数:18,代码来源:ClassSymbols.java

示例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);
    }
}
 
开发者ID:campolake,项目名称:openjdk9,代码行数:26,代码来源:ModuleInfoTreeAccess.java

示例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;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:16,代码来源:Messager.java


注:本文中的com.sun.tools.javac.api.JavacTrees.getPath方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。