Fri, 03 Sep 2010 12:00:21 -0700
Merge
1.1 --- a/src/share/classes/com/sun/tools/javac/comp/Attr.java Thu Sep 02 22:11:39 2010 -0700 1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java Fri Sep 03 12:00:21 2010 -0700 1.3 @@ -328,6 +328,12 @@ 1.4 attribExpr(expr, env); 1.5 } catch (BreakAttr b) { 1.6 return b.env; 1.7 + } catch (AssertionError ae) { 1.8 + if (ae.getCause() instanceof BreakAttr) { 1.9 + return ((BreakAttr)(ae.getCause())).env; 1.10 + } else { 1.11 + throw ae; 1.12 + } 1.13 } finally { 1.14 breakTree = null; 1.15 log.useSource(prev); 1.16 @@ -342,6 +348,12 @@ 1.17 attribStat(stmt, env); 1.18 } catch (BreakAttr b) { 1.19 return b.env; 1.20 + } catch (AssertionError ae) { 1.21 + if (ae.getCause() instanceof BreakAttr) { 1.22 + return ((BreakAttr)(ae.getCause())).env; 1.23 + } else { 1.24 + throw ae; 1.25 + } 1.26 } finally { 1.27 breakTree = null; 1.28 log.useSource(prev);
2.1 --- a/src/share/classes/com/sun/tools/javac/tree/TreeInfo.java Thu Sep 02 22:11:39 2010 -0700 2.2 +++ b/src/share/classes/com/sun/tools/javac/tree/TreeInfo.java Fri Sep 03 12:00:21 2010 -0700 2.3 @@ -501,6 +501,10 @@ 2.4 if (that.sym == sym) result = that; 2.5 else super.visitVarDef(that); 2.6 } 2.7 + public void visitTypeParameter(JCTypeParameter that) { 2.8 + if (that.type.tsym == sym) result = that; 2.9 + else super.visitTypeParameter(that); 2.10 + } 2.11 } 2.12 DeclScanner s = new DeclScanner(); 2.13 tree.accept(s);
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/test/tools/javac/T6458823/MyProcessor.java Fri Sep 03 12:00:21 2010 -0700 3.3 @@ -0,0 +1,55 @@ 3.4 + /* 3.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 3.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3.7 + * 3.8 + * This code is free software; you can redistribute it and/or modify it 3.9 + * under the terms of the GNU General Public License version 2 only, as 3.10 + * published by the Free Software Foundation. 3.11 + * 3.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 3.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 3.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 3.15 + * version 2 for more details (a copy is included in the LICENSE file that 3.16 + * accompanied this code). 3.17 + * 3.18 + * You should have received a copy of the GNU General Public License version 3.19 + * 2 along with this work; if not, write to the Free Software Foundation, 3.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 3.21 + * 3.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 3.23 + * or visit www.oracle.com if you need additional information or have any 3.24 + * questions. 3.25 + */ 3.26 + 3.27 +import java.util.Set; 3.28 +import javax.annotation.processing.*; 3.29 +import javax.lang.model.element.*; 3.30 +import javax.lang.model.util.ElementFilter; 3.31 +import javax.lang.model.SourceVersion; 3.32 +import static javax.tools.Diagnostic.Kind.*; 3.33 + 3.34 +@SupportedAnnotationTypes("*") 3.35 +public class MyProcessor extends AbstractProcessor { 3.36 + private Messager messager; 3.37 + public void init(ProcessingEnvironment processingEnv) { 3.38 + this.messager = processingEnv.getMessager(); 3.39 + } 3.40 + 3.41 + public boolean process(Set<? extends TypeElement> tes, RoundEnvironment renv) { 3.42 + if (!renv.processingOver()) { 3.43 + for(TypeElement e : ElementFilter.typesIn(renv.getRootElements())) { 3.44 + for (TypeParameterElement tp : e.getTypeParameters()) { 3.45 + if (tp.getSimpleName().toString().length() > 1) { 3.46 + messager.printMessage(WARNING, 3.47 + "Type param names should be of length 1", tp); 3.48 + } 3.49 + } 3.50 + } 3.51 + } 3.52 + return true; 3.53 + } 3.54 + 3.55 + public SourceVersion getSupportedSourceVersion() { 3.56 + return SourceVersion.latest(); 3.57 + } 3.58 +}
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 4.2 +++ b/test/tools/javac/T6458823/T6458823.java Fri Sep 03 12:00:21 2010 -0700 4.3 @@ -0,0 +1,87 @@ 4.4 +/* 4.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 4.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4.7 + * 4.8 + * This code is free software; you can redistribute it and/or modify it 4.9 + * under the terms of the GNU General Public License version 2 only, as 4.10 + * published by the Free Software Foundation. 4.11 + * 4.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 4.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 4.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 4.15 + * version 2 for more details (a copy is included in the LICENSE file that 4.16 + * accompanied this code). 4.17 + * 4.18 + * You should have received a copy of the GNU General Public License version 4.19 + * 2 along with this work; if not, write to the Free Software Foundation, 4.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 4.21 + * 4.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 4.23 + * or visit www.oracle.com if you need additional information or have any 4.24 + * questions. 4.25 + */ 4.26 + 4.27 +/* 4.28 + * @test 4.29 + * @bug 6458823 4.30 + * @summary Messager messages on TypeParamterElements to not include position information. 4.31 + * 4.32 + * @compile MyProcessor.java T6458823.java 4.33 + * @run main T6458823 4.34 + */ 4.35 + 4.36 +import java.io.File; 4.37 +import java.io.IOException; 4.38 +import java.io.Writer; 4.39 +import java.net.URISyntaxException; 4.40 +import java.util.ArrayList; 4.41 +import java.util.HashMap; 4.42 +import java.util.List; 4.43 +import java.util.Map; 4.44 +import java.util.Set; 4.45 +import javax.tools.Diagnostic; 4.46 +import javax.tools.DiagnosticCollector; 4.47 +import javax.tools.JavaCompiler; 4.48 +import javax.tools.JavaCompiler.CompilationTask; 4.49 +import javax.tools.JavaFileObject; 4.50 +import javax.tools.StandardJavaFileManager; 4.51 +import javax.tools.ToolProvider; 4.52 + 4.53 +public class T6458823 { 4.54 + public static void main(String[] args) throws Exception { 4.55 + JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); 4.56 + if (compiler == null) { 4.57 + throw new RuntimeException("can't get javax.tools.JavaCompiler!"); 4.58 + } 4.59 + DiagnosticCollector<JavaFileObject> diagColl = 4.60 + new DiagnosticCollector<JavaFileObject>(); 4.61 + StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null); 4.62 + List<String> options = new ArrayList<String>(); 4.63 + options.add("-processor"); 4.64 + options.add("MyProcessor"); 4.65 + options.add("-proc:only"); 4.66 + List<File> files = new ArrayList<File>(); 4.67 + files.add(new File(T6458823.class.getResource("TestClass.java").toURI())); 4.68 + final CompilationTask task = compiler.getTask(null, fm, diagColl, 4.69 + options, null, fm.getJavaFileObjectsFromFiles(files)); 4.70 + task.call(); 4.71 + int diagCount = 0; 4.72 + for (Diagnostic<? extends JavaFileObject> diag : diagColl.getDiagnostics()) { 4.73 + if (diag.getKind() != Diagnostic.Kind.WARNING) { 4.74 + throw new AssertionError("Only warnings expected"); 4.75 + } 4.76 + System.out.println(diag); 4.77 + if (diag.getPosition() == Diagnostic.NOPOS) { 4.78 + throw new AssertionError("No position info in message"); 4.79 + } 4.80 + if (diag.getSource() == null) { 4.81 + throw new AssertionError("No source info in message"); 4.82 + } 4.83 + diagCount++; 4.84 + } 4.85 + if (diagCount != 2) { 4.86 + throw new AssertionError("unexpected number of warnings: " + 4.87 + diagCount + ", expected: 2"); 4.88 + } 4.89 + } 4.90 +}
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 5.2 +++ b/test/tools/javac/T6458823/TestClass.java Fri Sep 03 12:00:21 2010 -0700 5.3 @@ -0,0 +1,25 @@ 5.4 +/* 5.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 5.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5.7 + * 5.8 + * This code is free software; you can redistribute it and/or modify it 5.9 + * under the terms of the GNU General Public License version 2 only, as 5.10 + * published by the Free Software Foundation. 5.11 + * 5.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 5.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 5.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 5.15 + * version 2 for more details (a copy is included in the LICENSE file that 5.16 + * accompanied this code). 5.17 + * 5.18 + * You should have received a copy of the GNU General Public License version 5.19 + * 2 along with this work; if not, write to the Free Software Foundation, 5.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 5.21 + * 5.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 5.23 + * or visit www.oracle.com if you need additional information or have any 5.24 + * questions. 5.25 + */ 5.26 + 5.27 +class TestClass<XYZ, ABC> { 5.28 +}
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 6.2 +++ b/test/tools/javac/T6956462/T6956462.java Fri Sep 03 12:00:21 2010 -0700 6.3 @@ -0,0 +1,126 @@ 6.4 +/* 6.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 6.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 6.7 + * 6.8 + * This code is free software; you can redistribute it and/or modify it 6.9 + * under the terms of the GNU General Public License version 2 only, as 6.10 + * published by the Free Software Foundation. 6.11 + * 6.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 6.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 6.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 6.15 + * version 2 for more details (a copy is included in the LICENSE file that 6.16 + * accompanied this code). 6.17 + * 6.18 + * You should have received a copy of the GNU General Public License version 6.19 + * 2 along with this work; if not, write to the Free Software Foundation, 6.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 6.21 + * 6.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 6.23 + * or visit www.oracle.com if you need additional information or have any 6.24 + * questions. 6.25 + */ 6.26 + 6.27 +/* 6.28 + * @test 6.29 + * @bug 6956462 6.30 + * @summary AssertionError exception throws in the Compiler Tree API in JDK 7. 6.31 + * 6.32 + * @build TestClass T6956462 6.33 + * @run main T6956462 6.34 + */ 6.35 + 6.36 +import java.io.*; 6.37 +import java.net.URISyntaxException; 6.38 +import java.util.*; 6.39 +import javax.tools.*; 6.40 +import javax.tools.JavaCompiler.CompilationTask; 6.41 +import com.sun.source.tree.*; 6.42 +import com.sun.source.util.*; 6.43 + 6.44 +public class T6956462 { 6.45 + public static void main(String[] args) throws Exception { 6.46 + JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); 6.47 + if (compiler == null) { 6.48 + throw new RuntimeException("can't get javax.tools.JavaCompiler!"); 6.49 + } 6.50 + StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null); 6.51 + List<File> files = new ArrayList<File>(); 6.52 + files.add(new File(T6956462.class.getResource("TestClass.java").toURI())); 6.53 + final CompilationTask task = compiler.getTask(null, fm, null, 6.54 + null, null, fm.getJavaFileObjectsFromFiles(files)); 6.55 + JavacTask javacTask = (JavacTask) task; 6.56 + for (CompilationUnitTree cu : javacTask.parse()) { 6.57 + cu.accept(new MyVisitor(javacTask), null); 6.58 + } 6.59 + } 6.60 + 6.61 + private static class MyVisitor extends SimpleTreeVisitor<Tree, Void> { 6.62 + private final Trees trees; 6.63 + private CompilationUnitTree file; 6.64 + 6.65 + private MyVisitor(JavacTask javac) { 6.66 + this.trees = Trees.instance(javac); 6.67 + } 6.68 + 6.69 + @Override 6.70 + public Tree visitCompilationUnit(CompilationUnitTree file, Void v) { 6.71 + this.file = file; 6.72 + for (Tree typeDecl : file.getTypeDecls()) { 6.73 + typeDecl.accept(this, v); 6.74 + } 6.75 + return null; 6.76 + } 6.77 + 6.78 + @Override 6.79 + public Tree visitImport(ImportTree imp, Void v) { 6.80 + return null; 6.81 + } 6.82 + 6.83 + @Override 6.84 + public Tree visitMethodInvocation(MethodInvocationTree invoke, Void v) { 6.85 + invoke.getMethodSelect().accept(this, v); 6.86 + return null; 6.87 + } 6.88 + 6.89 + @Override 6.90 + public Tree visitBlock(BlockTree block, Void v) { 6.91 + for (StatementTree stat : block.getStatements()) { 6.92 + stat.accept(this, v); 6.93 + } 6.94 + return null; 6.95 + } 6.96 + 6.97 + @Override 6.98 + public Tree visitClass(ClassTree clazz, Void v) { 6.99 + for (Tree member : clazz.getMembers()) { 6.100 + member.accept(this, v); 6.101 + } 6.102 + return null; 6.103 + } 6.104 + 6.105 + @Override 6.106 + public Tree visitIdentifier(IdentifierTree ident, Void v) { 6.107 + trees.getScope(trees.getPath(file, ident)); 6.108 + return null; 6.109 + } 6.110 + 6.111 + @Override 6.112 + public Tree visitMethod(MethodTree method, Void v) { 6.113 + method.getBody().accept(this, v); 6.114 + return null; 6.115 + } 6.116 + 6.117 + @Override 6.118 + public Tree visitMemberSelect(MemberSelectTree select, Void v) { 6.119 + select.getExpression().accept(this, v); 6.120 + return null; 6.121 + } 6.122 + 6.123 + @Override 6.124 + public Tree visitVariable(VariableTree var, Void v) { 6.125 + var.getInitializer().accept(this, v); 6.126 + return null; 6.127 + } 6.128 + } 6.129 +}
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 7.2 +++ b/test/tools/javac/T6956462/TestClass.java Fri Sep 03 12:00:21 2010 -0700 7.3 @@ -0,0 +1,30 @@ 7.4 +/* 7.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 7.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 7.7 + * 7.8 + * This code is free software; you can redistribute it and/or modify it 7.9 + * under the terms of the GNU General Public License version 2 only, as 7.10 + * published by the Free Software Foundation. 7.11 + * 7.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 7.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 7.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 7.15 + * version 2 for more details (a copy is included in the LICENSE file that 7.16 + * accompanied this code). 7.17 + * 7.18 + * You should have received a copy of the GNU General Public License version 7.19 + * 2 along with this work; if not, write to the Free Software Foundation, 7.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 7.21 + * 7.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 7.23 + * or visit www.oracle.com if you need additional information or have any 7.24 + * questions. 7.25 + */ 7.26 + 7.27 +import java.io.PrintStream; 7.28 + 7.29 +abstract class TestClass { 7.30 + private void test() { 7.31 + final PrintStream out = System.out; 7.32 + } 7.33 +}