提交 5c99f602 编写于 作者: J jjg

6986246: Trees object is round-specific

Reviewed-by: darcy
上级 bd1900ef
/*
* Copyright (c) 2005, 2008, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
......@@ -56,7 +56,6 @@ import com.sun.tools.javac.comp.Env;
import com.sun.tools.javac.comp.MemberEnter;
import com.sun.tools.javac.comp.Resolve;
import com.sun.tools.javac.model.JavacElements;
import com.sun.tools.javac.processing.JavacMessager;
import com.sun.tools.javac.processing.JavacProcessingEnvironment;
import com.sun.tools.javac.tree.JCTree.*;
import com.sun.tools.javac.tree.JCTree;
......@@ -81,14 +80,15 @@ import com.sun.tools.javac.util.Pair;
*/
public class JavacTrees extends Trees {
private final Resolve resolve;
private final Enter enter;
private final Log log;
private final MemberEnter memberEnter;
private final Attr attr;
private final TreeMaker treeMaker;
private final JavacElements elements;
private final JavacTaskImpl javacTaskImpl;
// in a world of a single context per compilation, these would all be final
private Resolve resolve;
private Enter enter;
private Log log;
private MemberEnter memberEnter;
private Attr attr;
private TreeMaker treeMaker;
private JavacElements elements;
private JavacTaskImpl javacTaskImpl;
public static JavacTrees instance(JavaCompiler.CompilationTask task) {
if (!(task instanceof JavacTaskImpl))
......@@ -111,6 +111,14 @@ public class JavacTrees extends Trees {
private JavacTrees(Context context) {
context.put(JavacTrees.class, this);
init(context);
}
public void updateContext(Context context) {
init(context);
}
private void init(Context context) {
attr = Attr.instance(context);
enter = Enter.instance(context);
elements = JavacElements.instance(context);
......@@ -337,6 +345,7 @@ public class JavacTrees extends Trees {
super(M);
}
@Override
public <T extends JCTree> T copy(T t, JCTree leaf) {
T t2 = super.copy(t, leaf);
if (t == leaf)
......
/*
* Copyright (c) 2005, 2009, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
......@@ -49,6 +49,7 @@ import javax.tools.StandardJavaFileManager;
import javax.tools.JavaFileObject;
import javax.tools.DiagnosticListener;
import com.sun.tools.javac.api.JavacTrees;
import com.sun.source.util.AbstractTypeProcessor;
import com.sun.source.util.TaskEvent;
import com.sun.source.util.TaskListener;
......@@ -1104,6 +1105,12 @@ public class JavacProcessingEnvironment implements ProcessingEnvironment, Closea
task.updateContext(next);
}
JavacTrees trees = context.get(JavacTrees.class);
if (trees != null) {
next.put(JavacTrees.class, trees);
trees.updateContext(next);
}
context.clear();
return next;
}
......
......@@ -23,7 +23,7 @@
/*
* @test
* @bug 6877202
* @bug 6877202 6986246
* @summary Elements.getDocComment() is not getting JavaDocComments
*/
......@@ -139,6 +139,7 @@ public class TestDocComments extends AbstractProcessor {
Filer filer;
Messager messager;
Elements elements;
Trees trees;
ScanKind skind;
int round = 0;
......@@ -155,6 +156,7 @@ public class TestDocComments extends AbstractProcessor {
filer = pEnv.getFiler();
messager = pEnv.getMessager();
elements = pEnv.getElementUtils();
trees = Trees.instance(processingEnv);
skind = ScanKind.valueOf(options.get("scan"));
}
......@@ -167,7 +169,6 @@ public class TestDocComments extends AbstractProcessor {
for (Element e: roundEnv.getRootElements()) {
System.err.println("scan " + skind + " " + e.getKind() + " " + e.getSimpleName());
if (skind == ScanKind.TREE) {
Trees trees = Trees.instance(processingEnv); // cannot cache this across rounds
new TestTreeScanner().scan(trees.getPath(e), trees);
} else
new TestElementScanner().scan(e);
......
......@@ -23,7 +23,7 @@
/*
* @test
* @bug 6985205
* @bug 6985205 6986246
* @summary access to tree positions and doc comments may be lost across annotation processing rounds
* @build TreePosRoundsTest
* @compile -proc:only -processor TreePosRoundsTest TreePosRoundsTest.java
......@@ -70,6 +70,7 @@ public class TreePosRoundsTest extends AbstractProcessor {
Filer filer;
Messager messager;
Trees trees;
@Override
public SourceVersion getSupportedSourceVersion() {
......@@ -81,6 +82,7 @@ public class TreePosRoundsTest extends AbstractProcessor {
super.init(pEnv);
filer = pEnv.getFiler();
messager = pEnv.getMessager();
trees = Trees.instance(pEnv);
}
int round = 0;
......@@ -92,7 +94,6 @@ public class TreePosRoundsTest extends AbstractProcessor {
// Scan trees for elements, verifying source tree positions
for (Element e: roundEnv.getRootElements()) {
try {
Trees trees = Trees.instance(processingEnv); // cannot cache this across rounds
TreePath p = trees.getPath(e);
new TestTreeScanner(p.getCompilationUnit(), trees).scan(trees.getPath(e), null);
} catch (IOException ex) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册