Tue, 28 Sep 2010 22:46:36 +0530
6967842: Element not returned from tree API for ARM resource variables.
Reviewed-by: jjg, darcy
1.1 --- a/src/share/classes/com/sun/tools/javac/code/Symbol.java Mon Sep 27 17:28:49 2010 -0700 1.2 +++ b/src/share/classes/com/sun/tools/javac/code/Symbol.java Tue Sep 28 22:46:36 2010 +0530 1.3 @@ -1,5 +1,5 @@ 1.4 /* 1.5 - * Copyright (c) 1999, 2008, Oracle and/or its affiliates. All rights reserved. 1.6 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 1.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.8 * 1.9 * This code is free software; you can redistribute it and/or modify it 1.10 @@ -960,6 +960,8 @@ 1.11 return ElementKind.ENUM_CONSTANT; 1.12 } else if (owner.kind == TYP || owner.kind == ERR) { 1.13 return ElementKind.FIELD; 1.14 + } else if (isResourceVariable()) { 1.15 + return ElementKind.RESOURCE_VARIABLE; 1.16 } else { 1.17 return ElementKind.LOCAL_VARIABLE; 1.18 }
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/test/tools/javac/processing/model/element/TestResourceElement.java Tue Sep 28 22:46:36 2010 +0530 2.3 @@ -0,0 +1,96 @@ 2.4 +/* 2.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 2.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 2.7 + * 2.8 + * This code is free software; you can redistribute it and/or modify it 2.9 + * under the terms of the GNU General Public License version 2 only, as 2.10 + * published by the Free Software Foundation. 2.11 + * 2.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 2.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 2.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 2.15 + * version 2 for more details (a copy is included in the LICENSE file that 2.16 + * accompanied this code). 2.17 + * 2.18 + * You should have received a copy of the GNU General Public License version 2.19 + * 2 along with this work; if not, write to the Free Software Foundation, 2.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2.21 + * 2.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2.23 + * or visit www.oracle.com if you need additional information or have any 2.24 + * questions. 2.25 + */ 2.26 + 2.27 +/* 2.28 + * @test 2.29 + * @bug 6967842 2.30 + * @summary Element not returned from tree API for ARM resource variables. 2.31 + * @author A. Sundararajan 2.32 + * @build TestResourceElement 2.33 + * @compile -processor TestResourceElement -proc:only TestResourceElement.java 2.34 + */ 2.35 + 2.36 +import javax.annotation.processing.*; 2.37 +import javax.lang.model.*; 2.38 +import javax.lang.model.element.*; 2.39 +import java.util.*; 2.40 +import com.sun.source.tree.*; 2.41 +import com.sun.source.util.*; 2.42 + 2.43 +@SupportedAnnotationTypes("*") 2.44 +public class TestResourceElement extends AbstractProcessor implements AutoCloseable { 2.45 + public boolean process(Set<? extends TypeElement> annotations, 2.46 + RoundEnvironment roundEnv) { 2.47 + if (!roundEnv.processingOver()) { 2.48 + Trees trees = Trees.instance(processingEnv); 2.49 + 2.50 + for(Element rootElement : roundEnv.getRootElements()) { 2.51 + TreePath treePath = trees.getPath(rootElement); 2.52 + 2.53 + VariableScanner varScanner = new VariableScanner(trees); 2.54 + varScanner.scan(trees.getTree(rootElement), 2.55 + treePath.getCompilationUnit()); 2.56 + if (varScanner.getTrvElement() == null) { 2.57 + throw new AssertionError("Element is null for 'trv'"); 2.58 + } 2.59 + } 2.60 + } 2.61 + return true; 2.62 + } 2.63 + 2.64 + @Override 2.65 + public void close() {} 2.66 + 2.67 + private void test1() { 2.68 + // The resource variable "trv"'s Element is checked. 2.69 + // Do not change the name of the variable. 2.70 + try(TestResourceElement trv = this) {} 2.71 + } 2.72 + 2.73 + class VariableScanner extends TreeScanner<Void, CompilationUnitTree> { 2.74 + private Trees trees; 2.75 + private Element trvElement; 2.76 + 2.77 + public VariableScanner(Trees trees) { 2.78 + super(); 2.79 + this.trees = trees; 2.80 + } 2.81 + @Override 2.82 + public Void visitVariable(VariableTree node, CompilationUnitTree cu) { 2.83 + // if this is "trv", get it's element. 2.84 + if (node.getName().contentEquals("trv")) { 2.85 + trvElement = trees.getElement(trees.getPath(cu, node)); 2.86 + } 2.87 + return super.visitVariable(node, cu); 2.88 + } 2.89 + 2.90 + Element getTrvElement() { 2.91 + return trvElement; 2.92 + } 2.93 + } 2.94 + 2.95 + @Override 2.96 + public SourceVersion getSupportedSourceVersion() { 2.97 + return SourceVersion.latest(); 2.98 + } 2.99 +}
3.1 --- a/test/tools/javac/processing/model/element/TestResourceVariable.java Mon Sep 27 17:28:49 2010 -0700 3.2 +++ b/test/tools/javac/processing/model/element/TestResourceVariable.java Tue Sep 28 22:46:36 2010 +0530 3.3 @@ -23,11 +23,11 @@ 3.4 3.5 /* 3.6 * @test 3.7 - * @bug 6911256 6964740 3.8 + * @bug 6911256 6964740 6967842 3.9 * @summary Test that the resource variable kind is appropriately set 3.10 * @author Joseph D. Darcy 3.11 * @build TestResourceVariable 3.12 - * @compile/fail -processor TestResourceVariable -proc:only TestResourceVariable.java 3.13 + * @compile -processor TestResourceVariable -proc:only TestResourceVariable.java 3.14 */ 3.15 3.16 // Bug should be filed for this misbehavior