test/tools/javac/processing/model/TestSymtabItems.java

Print this page




   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  * @test
  26  * @bug 7021183
  27  * @summary 269: assertion failure getting enclosing element of an undefined name
  28  */
  29 
  30 import java.lang.reflect.Field;
  31 import javax.lang.model.element.Element;
  32 import javax.lang.model.element.ExecutableElement;
  33 import javax.lang.model.element.PackageElement;
  34 import javax.lang.model.element.TypeElement;
  35 import javax.lang.model.element.TypeParameterElement;
  36 import javax.lang.model.element.UnknownElementException;
  37 import javax.lang.model.element.VariableElement;
  38 import javax.lang.model.type.TypeMirror;
  39 import javax.lang.model.type.UnknownTypeException;
  40 import javax.lang.model.util.ElementScanner7;
  41 import javax.lang.model.util.SimpleTypeVisitor7;
  42 import javax.lang.model.util.Types;
  43 
  44 import com.sun.tools.javac.code.Symbol.ClassSymbol;
  45 import com.sun.tools.javac.code.Symtab;
  46 import com.sun.tools.javac.file.JavacFileManager;
  47 import com.sun.tools.javac.main.JavaCompiler;
  48 import com.sun.tools.javac.model.JavacTypes;
  49 import com.sun.tools.javac.util.Context;
  50 
  51 /**
  52  * Scan javac Symtab looking for TypeMirrors and Elements, and ensure that
  53  * no exceptions are thrown when used with javax.lang.model visitors.
  54  *
  55  */
  56 public class TestSymtabItems {
  57     public static void main(String... args) throws Exception {
  58         new TestSymtabItems().run();
  59     }
  60 
  61     void run() throws Exception {
  62         Context c = new Context();


  95         ElemPrinter ep = new ElemPrinter();
  96         System.err.println("Test " + label);
  97         ep.visit(e);
  98         System.err.println();
  99     }
 100 
 101     void print(String label, TypeMirror t, Types types) {
 102         TypePrinter tp = new TypePrinter();
 103         System.err.println("Test " + label);
 104         tp.visit(t, types);
 105         System.err.println();
 106     }
 107 
 108     void error(String msg) {
 109         System.err.println("Error: " + msg);
 110         errors++;
 111     }
 112 
 113     int errors;
 114 
 115     class ElemPrinter extends ElementScanner7<Void, Void> {
 116         @Override
 117         public Void visitPackage(PackageElement e, Void p) {
 118             show("package", e);
 119             indent(+1);
 120             super.visitPackage(e, p);
 121             indent(-1);
 122             return null;
 123         }
 124 
 125         @Override
 126         public Void visitType(TypeElement e, Void p) {
 127             show("type", e);
 128             indent(+1);
 129             super.visitType(e, p);
 130             indent(-1);
 131             return null;
 132         }
 133 
 134         @Override
 135         public Void visitVariable(VariableElement e, Void p) {




   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  * @test
  26  * @bug 7021183 7025809
  27  * @summary 269: assertion failure getting enclosing element of an undefined name
  28  */
  29 
  30 import java.lang.reflect.Field;
  31 import javax.lang.model.element.Element;
  32 import javax.lang.model.element.ExecutableElement;
  33 import javax.lang.model.element.PackageElement;
  34 import javax.lang.model.element.TypeElement;
  35 import javax.lang.model.element.TypeParameterElement;
  36 import javax.lang.model.element.UnknownElementException;
  37 import javax.lang.model.element.VariableElement;
  38 import javax.lang.model.type.TypeMirror;
  39 import javax.lang.model.type.UnknownTypeException;
  40 import javax.lang.model.util.*;


  41 
  42 import com.sun.tools.javac.code.Symbol.ClassSymbol;
  43 import com.sun.tools.javac.code.Symtab;
  44 import com.sun.tools.javac.file.JavacFileManager;
  45 import com.sun.tools.javac.main.JavaCompiler;
  46 import com.sun.tools.javac.model.JavacTypes;
  47 import com.sun.tools.javac.util.Context;
  48 
  49 /**
  50  * Scan javac Symtab looking for TypeMirrors and Elements, and ensure that
  51  * no exceptions are thrown when used with javax.lang.model visitors.
  52  *
  53  */
  54 public class TestSymtabItems {
  55     public static void main(String... args) throws Exception {
  56         new TestSymtabItems().run();
  57     }
  58 
  59     void run() throws Exception {
  60         Context c = new Context();


  93         ElemPrinter ep = new ElemPrinter();
  94         System.err.println("Test " + label);
  95         ep.visit(e);
  96         System.err.println();
  97     }
  98 
  99     void print(String label, TypeMirror t, Types types) {
 100         TypePrinter tp = new TypePrinter();
 101         System.err.println("Test " + label);
 102         tp.visit(t, types);
 103         System.err.println();
 104     }
 105 
 106     void error(String msg) {
 107         System.err.println("Error: " + msg);
 108         errors++;
 109     }
 110 
 111     int errors;
 112 
 113     class ElemPrinter extends ElementScanner8<Void, Void> {
 114         @Override
 115         public Void visitPackage(PackageElement e, Void p) {
 116             show("package", e);
 117             indent(+1);
 118             super.visitPackage(e, p);
 119             indent(-1);
 120             return null;
 121         }
 122 
 123         @Override
 124         public Void visitType(TypeElement e, Void p) {
 125             show("type", e);
 126             indent(+1);
 127             super.visitType(e, p);
 128             indent(-1);
 129             return null;
 130         }
 131 
 132         @Override
 133         public Void visitVariable(VariableElement e, Void p) {