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