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


Java JavacTrees.instance方法代码示例

本文整理汇总了Java中com.sun.tools.javac.api.JavacTrees.instance方法的典型用法代码示例。如果您正苦于以下问题:Java JavacTrees.instance方法的具体用法?Java JavacTrees.instance怎么用?Java JavacTrees.instance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.sun.tools.javac.api.JavacTrees的用法示例。


在下文中一共展示了JavacTrees.instance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getTrees

import com.sun.tools.javac.api.JavacTrees; //导入方法依赖的package包/类
/**
 * Return the {@link Trees} service of the javac represented by this {@link CompilationInfo}.
 * @return javac Trees service
 */
public synchronized @NonNull Trees getTrees() {
    checkConfinement();
    if (trees == null) {
        //use a working init order:
        com.sun.tools.javac.main.JavaCompiler.instance(impl.getJavacTask().getContext());
        trees = JavacTrees.instance(impl.getJavacTask().getContext());
        Snapshot snapshot = impl.getSnapshot();
        Document doc = snapshot != null ? snapshot.getSource().getDocument(false) : null;
        WrapperFactory factory = doc != null ? (WrapperFactory)doc.getProperty(WrapperFactory.class) : null;
        if (factory != null) {
            trees = factory.wrapTrees(trees);
        }
    }
    return trees;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:CompilationInfo.java

示例2: ToolEnvironment

import com.sun.tools.javac.api.JavacTrees; //导入方法依赖的package包/类
/**
 * Constructor
 *
 * @param context      Context for this javadoc instance.
 */
protected ToolEnvironment(Context context) {
    context.put(ToolEnvKey, this);
    this.context = context;

    messager = Messager.instance0(context);
    syms = Symtab.instance(context);
    finder = JavadocClassFinder.instance(context);
    enter = JavadocEnter.instance(context);
    names = Names.instance(context);
    externalizableSym = syms.enterClass(syms.java_base, names.fromString("java.io.Externalizable"));
    chk = Check.instance(context);
    types = com.sun.tools.javac.code.Types.instance(context);
    fileManager = context.get(JavaFileManager.class);
    if (fileManager instanceof JavacFileManager) {
        ((JavacFileManager)fileManager).setSymbolFileEnabled(false);
    }
    docTrees = JavacTrees.instance(context);
    source = Source.instance(context);
    elements =  JavacElements.instance(context);
    typeutils = JavacTypes.instance(context);
    elementToTreePath = new HashMap<>();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:28,代码来源:ToolEnvironment.java

示例3: 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

示例4: 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

示例5: run

import com.sun.tools.javac.api.JavacTrees; //导入方法依赖的package包/类
void run() throws Exception {
    Context context = new Context();
    JavacFileManager.preRegister(context);
    Trees trees = JavacTrees.instance(context);
    StringWriter strOut = new StringWriter();
    PrintWriter pw = new PrintWriter(strOut);
    DPrinter dprinter = new DPrinter(pw, trees);
    final JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
    JavacTask ct = (JavacTask)tool.getTask(null, null, null, null, null, Arrays.asList(new JavaSource()));
    Iterable<? extends CompilationUnitTree> elements = ct.parse();
    ct.analyze();
    Assert.check(elements.iterator().hasNext());
    dprinter.treeTypes(true).printTree("", (JCTree)elements.iterator().next());
    String output = strOut.toString();
    Assert.check(!output.contains("java.lang.Object"), "there shouldn't be any type instantiated to Object");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:InferenceRegressionTest02.java

示例6: 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

示例7: DocEnv

import com.sun.tools.javac.api.JavacTrees; //导入方法依赖的package包/类
/**
 * Constructor
 *
 * @param context      Context for this javadoc instance.
 */
protected DocEnv(Context context) {
    context.put(docEnvKey, this);
    this.context = context;

    messager = Messager.instance0(context);
    syms = Symtab.instance(context);
    finder = JavadocClassFinder.instance(context);
    enter = JavadocEnter.instance(context);
    names = Names.instance(context);
    externalizableSym = syms.enterClass(syms.java_base, names.fromString("java.io.Externalizable"));
    chk = Check.instance(context);
    types = com.sun.tools.javac.code.Types.instance(context);
    fileManager = context.get(JavaFileManager.class);
    if (fileManager instanceof JavacFileManager) {
        ((JavacFileManager)fileManager).setSymbolFileEnabled(false);
    }
    docTrees = JavacTrees.instance(context);
    source = Source.instance(context);
    elements =  JavacElements.instance(context);
    typeutils = JavacTypes.instance(context);
    elementToTreePath = new HashMap<>();
}
 
开发者ID:campolake,项目名称:openjdk9,代码行数:28,代码来源:DocEnv.java

示例8: 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

示例9: init

import com.sun.tools.javac.api.JavacTrees; //导入方法依赖的package包/类
public void init(ProcessingEnvironment procEnv) {
    javacProcessingEnv = (JavacProcessingEnvironment) procEnv;
    maker = TreeMaker.instance(javacProcessingEnv.getContext());
    parserFactory = ParserFactory.instance(javacProcessingEnv.getContext());
    utils = javacProcessingEnv.getElementUtils();
    typeUtils = javacProcessingEnv.getTypeUtils();
    trees = JavacTrees.instance(javacProcessingEnv);
    types = Types.instance(javacProcessingEnv.getContext());

    voidType = maker.Type((Type) typeUtils.getNoType(TypeKind.VOID));
    objectClass = utils.getTypeElement("java.lang.Object");

    debugMode = Boolean.parseBoolean(getOption(DEBUG_MODE_OPTION_NAME));

    // reflection
    try {
        newParserMethod = ParserFactory.class.getMethod("newParser", CharSequence.class, Boolean.TYPE, Boolean.TYPE, Boolean.TYPE);
    } catch (NoSuchMethodException ignored) {
    }
}
 
开发者ID:ixkor,项目名称:genaroid,代码行数:21,代码来源:GenaroidEnvironment.java

示例10: DocTreeMaker

import com.sun.tools.javac.api.JavacTrees; //导入方法依赖的package包/类
/** Create a tree maker with NOPOS as initial position.
 */
protected DocTreeMaker(Context context) {
    context.put(treeMakerKey, this);
    diags = JCDiagnostic.Factory.instance(context);
    this.pos = Position.NOPOS;
    trees = JavacTrees.instance(context);
    referenceParser = new ReferenceParser(ParserFactory.instance(context));
    sentenceBreakTags = EnumSet.of(H1, H2, H3, H4, H5, H6, PRE, P);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:11,代码来源:DocTreeMaker.java

示例11: getDiagSource

import com.sun.tools.javac.api.JavacTrees; //导入方法依赖的package包/类
private String getDiagSource(DocTreePath path) {
    if (path == null || path.getTreePath() == null) {
        return programName;
    }
    JavacTrees trees = JavacTrees.instance(context);
    DocSourcePositions sourcePositions = trees.getSourcePositions();
    CompilationUnitTree cu = path.getTreePath().getCompilationUnit();
    long spos = sourcePositions.getStartPosition(cu, path.getDocComment(), path.getLeaf());
    long lineNumber = cu.getLineMap().getLineNumber(spos);
    String fname = cu.getSourceFile().getName();
    String posString = fname + ":" + lineNumber;
    return posString;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:14,代码来源:Messager.java

示例12: runTest

import com.sun.tools.javac.api.JavacTrees; //导入方法依赖的package包/类
void runTest(Stream<Path> inputs) {
    JavacTool tool = JavacTool.create();
    try (JavacFileManager fm = tool.getStandardFileManager(null, null, null)) {
        Path classes = Paths.get(System.getProperty("test.classes"));
        Iterable<? extends JavaFileObject> reconFiles =
                fm.getJavaFileObjectsFromFiles(inputs.sorted().map(p -> p.toFile()) :: iterator);
        List<String> options = Arrays.asList("-classpath", classes.toAbsolutePath().toString());
        JavacTask reconTask = tool.getTask(null, fm, null, options, null, reconFiles);
        Iterable<? extends CompilationUnitTree> reconUnits = reconTask.parse();
        JavacTrees reconTrees = JavacTrees.instance(reconTask);
        SearchAnnotations scanner = new SearchAnnotations(reconTrees,
                                                          reconTask.getElements());
        List<JavaFileObject> validateFiles = new ArrayList<>();

        reconTask.analyze();
        scanner.scan(reconUnits, null);

        for (CompilationUnitTree cut : reconUnits) {
            validateFiles.add(ClearAnnotations.clearAnnotations(reconTrees, cut));
        }

        Context validateContext = new Context();
        TestDependencies.preRegister(validateContext);
        JavacTask validateTask =
                tool.getTask(null, fm, null, options, null, validateFiles, validateContext);

        validateTask.analyze();

        TestDependencies deps = (TestDependencies) Dependencies.instance(validateContext);

        if (!scanner.topLevel2Expected.equals(deps.topLevel2Completing)) {
            throw new IllegalStateException(  "expected=" + scanner.topLevel2Expected +
                                            "; actual=" + deps.topLevel2Completing);
        }
    } catch (IOException ex) {
        throw new IllegalStateException(ex);
    } finally {
        inputs.close();
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:41,代码来源:DependenciesTest.java

示例13: getDiagSource

import com.sun.tools.javac.api.JavacTrees; //导入方法依赖的package包/类
private String getDiagSource(DocTreePath path) {
    if (path == null) {
        return programName;
    }
    JavacTrees trees = JavacTrees.instance(context);
    DocSourcePositions sourcePositions = trees.getSourcePositions();
    CompilationUnitTree cu = path.getTreePath().getCompilationUnit();
    long spos = sourcePositions.getStartPosition(cu, path.getDocComment(), path.getLeaf());
    long lineNumber = cu.getLineMap().getLineNumber(spos);
    String fname = cu.getSourceFile().getName();
    String posString = fname + ":" + lineNumber;
    return posString;
}
 
开发者ID:campolake,项目名称:openjdk9,代码行数:14,代码来源:Messager.java

示例14: JavadocClassFinder

import com.sun.tools.javac.api.JavacTrees; //导入方法依赖的package包/类
public JavadocClassFinder(Context context) {
    super(context);
    toolEnv = ToolEnvironment.instance(context);
    preferSource = true;
    trees = JavacTrees.instance(context);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:7,代码来源:JavadocClassFinder.java

示例15: DPrinter

import com.sun.tools.javac.api.JavacTrees; //导入方法依赖的package包/类
protected DPrinter(Context context) {
    context.put(DPrinter.class, this);
    out = context.get(Log.logKey).getWriter(Log.WriterKind.STDERR);
    trees = JavacTrees.instance(context);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:6,代码来源:DPrinter.java


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