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


Java JavacTrees类代码示例

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


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

示例1: adjustSpans

import com.sun.tools.javac.api.JavacTrees; //导入依赖的package包/类
private void adjustSpans(Iterable<? extends Tree> original, String code) {
    if (tree2Tag == null) {
        return; //nothing to  copy
    }
    
    java.util.List<Tree> linearized = new LinkedList<Tree>();
    if (!new Linearize().scan(original, linearized) != Boolean.TRUE) {
        return; //nothing to  copy
    }
    
        ClassPath empty = ClassPathSupport.createClassPath(new URL[0]);
        ClasspathInfo cpInfo = ClasspathInfo.create(JavaPlatformManager.getDefault().getDefaultPlatform().getBootstrapLibraries(), empty, empty);
        JavacTaskImpl javacTask = JavacParser.createJavacTask(cpInfo, null, null, null, null, null, null, null, Arrays.asList(FileObjects.memoryFileObject("", "Scratch.java", code)));
        com.sun.tools.javac.util.Context ctx = javacTask.getContext();
        JavaCompiler.instance(ctx).genEndPos = true;
        CompilationUnitTree tree = javacTask.parse().iterator().next(); //NOI18N
        SourcePositions sp = JavacTrees.instance(ctx).getSourcePositions();
        ClassTree clazz = (ClassTree) tree.getTypeDecls().get(0);

        new CopyTags(tree, sp).scan(clazz.getModifiers().getAnnotations(), linearized);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:22,代码来源:VeryPretty.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: reformat

import com.sun.tools.javac.api.JavacTrees; //导入依赖的package包/类
public static String reformat(String text, CodeStyle style, int rightMargin) {
    StringBuilder sb = new StringBuilder(text);
        ClassPath empty = ClassPathSupport.createClassPath(new URL[0]);
        ClasspathInfo cpInfo = ClasspathInfo.create(JavaPlatformManager.getDefault().getDefaultPlatform().getBootstrapLibraries(), empty, empty);
        JavacTaskImpl javacTask = JavacParser.createJavacTask(cpInfo, null, null, null, null, null, null, null, Arrays.asList(FileObjects.memoryFileObject("","Scratch.java", text)));
        com.sun.tools.javac.util.Context ctx = javacTask.getContext();
        JavaCompiler.instance(ctx).genEndPos = true;
        CompilationUnitTree tree = javacTask.parse().iterator().next(); //NOI18N
        SourcePositions sp = JavacTrees.instance(ctx).getSourcePositions();
        TokenSequence<JavaTokenId> tokens = TokenHierarchy.create(text, JavaTokenId.language()).tokenSequence(JavaTokenId.language());
        for (Diff diff : Pretty.reformat(text, tokens, new TreePath(tree), sp, style, rightMargin)) {
            int start = diff.getStartOffset();
            int end = diff.getEndOffset();
            sb.delete(start, end);
            String t = diff.getText();
            if (t != null && t.length() > 0) {
                sb.insert(start, t);
            }
        }

    return sb.toString();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:Reformatter.java

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

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

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

示例7: process

import com.sun.tools.javac.api.JavacTrees; //导入依赖的package包/类
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    round++;

    JavacProcessingEnvironment jpe = (JavacProcessingEnvironment) processingEnv;
    Context c = jpe.getContext();
    check(c.get(JavacElements.class), eltUtils);
    check(c.get(JavacTypes.class), typeUtils);
    check(c.get(JavacTrees.class), treeUtils);

    final int MAXROUNDS = 3;
    if (round < MAXROUNDS)
        generateSource("Gen" + round);

    return true;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:TestContext.java

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

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

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

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

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

示例13: qualifyDocReference

import com.sun.tools.javac.api.JavacTrees; //导入依赖的package包/类
/**
 * Fully qualifies a javadoc reference, e.g. for replacing {@code {@link List}} with {@code {@link
 * java.util.List}}
 *
 * @param fix the fix builder to add to
 * @param docPath the path to a {@link DCTree.DCReference} element
 */
public static void qualifyDocReference(
    SuggestedFix.Builder fix, DocTreePath docPath, VisitorState state) {

  DocTree leaf = docPath.getLeaf();
  checkArgument(
      leaf.getKind() == DocTree.Kind.REFERENCE,
      "expected a path to a reference, got %s instead",
      leaf.getKind());
  DCTree.DCReference reference = (DCTree.DCReference) leaf;

  Symbol sym = (Symbol) JavacTrees.instance(state.context).getElement(docPath);
  if (sym == null) {
    return;
  }
  String refString = reference.toString();
  String qualifiedName;
  int idx = refString.indexOf('#');
  if (idx >= 0) {
    qualifiedName = sym.owner.getQualifiedName() + refString.substring(idx, refString.length());
  } else {
    qualifiedName = sym.getQualifiedName().toString();
  }

  replaceDocTree(fix, docPath, qualifiedName);
}
 
开发者ID:google,项目名称:error-prone,代码行数:33,代码来源:SuggestedFixes.java

示例14: TreeScannerStateful

import com.sun.tools.javac.api.JavacTrees; //导入依赖的package包/类
public TreeScannerStateful(CompilationTask task, JCCompilationUnit jcc) {
  	this.jcc = jcc ;
      trees = Trees.instance(task);
      treesC = (JavacTrees)trees;
              
      //Rabbit hole to Wonderland
      context = ((BasicJavacTask)task).getContext() ;
this.task = ((BasicJavacTask)task) ;
      
      //Initialize magical classes !
      make = TreeMaker.instance(context) ;
      names = Names.instance(context) ;
      syms = Symtab.instance(context);
      types = Types.instance(context) ;
      typesC = JavacTypes.instance(context) ;
      attr = Attr.instance(context) ;
      enter = Enter.instance(context) ;
      resolve = Resolve.instance(context) ;
      memberEnter = MemberEnter.instance(context) ;
javacElements = JavacElements.instance(context) ;
info = TreeInfo.instance(context) ;

      sourcePositions = trees.getSourcePositions();
      elements = ((JavacTask)task).getElements();
      elementsC = (JavacElements)elements;
}
 
开发者ID:metabrain,项目名称:java8-plugin-persitent-local-vars,代码行数:27,代码来源:TreeScannerStateful.java

示例15: getPluginServices

import com.sun.tools.javac.api.JavacTrees; //导入依赖的package包/类
@NonNull
private Lookup getPluginServices(final JavacTaskImpl jt) {
    return Lookups.fixed(
        jt.getElements(),
        jt.getTypes(),
        JavacTrees.instance(jt.getContext()),
        JavaSourceAccessor.getINSTANCE().createElementUtilities(jt));
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:9,代码来源:JavaParsingContext.java


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