Mon, 16 Sep 2013 14:13:44 +0200
8021112: Spurious unchecked warning reported by javac
6480588: No way to suppress deprecation warnings when implementing deprecated interface
Summary: Fixing DeferredLintHandler configuration, so lint warnings are reported with correct @SuppressWarnings settings
Reviewed-by: jjg, vromero
jjg@110 | 1 | /* |
jjg@904 | 2 | * Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved. |
jjg@110 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
jjg@110 | 4 | * |
jjg@110 | 5 | * This code is free software; you can redistribute it and/or modify it |
jjg@110 | 6 | * under the terms of the GNU General Public License version 2 only, as |
jjg@110 | 7 | * published by the Free Software Foundation. |
jjg@110 | 8 | * |
jjg@110 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
jjg@110 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
jjg@110 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
jjg@110 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
jjg@110 | 13 | * accompanied this code). |
jjg@110 | 14 | * |
jjg@110 | 15 | * You should have received a copy of the GNU General Public License version |
jjg@110 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
jjg@110 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
jjg@110 | 18 | * |
ohair@554 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ohair@554 | 20 | * or visit www.oracle.com if you need additional information or have any |
ohair@554 | 21 | * questions. |
jjg@110 | 22 | */ |
jjg@110 | 23 | |
jjg@110 | 24 | |
jjg@110 | 25 | /* |
jjg@110 | 26 | * @test |
jjg@110 | 27 | * @bug 6557752 |
jjg@110 | 28 | * @summary Test for wrapping the original type in ErrorType. |
jjg@110 | 29 | * @library ../lib |
jjg@110 | 30 | * @compile T6557752.java |
jjg@110 | 31 | * @run main T6557752 |
jjg@110 | 32 | */ |
jjg@110 | 33 | |
jjg@110 | 34 | import com.sun.source.tree.AssignmentTree; |
jjg@110 | 35 | import com.sun.source.tree.CompilationUnitTree; |
jjg@110 | 36 | import com.sun.source.tree.MethodInvocationTree; |
jjg@110 | 37 | import com.sun.source.util.JavacTask; |
jjg@110 | 38 | import com.sun.source.util.TreePath; |
jjg@110 | 39 | import com.sun.source.util.TreePathScanner; |
jjg@110 | 40 | import com.sun.source.util.Trees; |
jjg@110 | 41 | import com.sun.tools.javac.api.JavacTaskImpl; |
jjg@110 | 42 | import com.sun.tools.javac.util.List; |
jjg@110 | 43 | import java.io.IOException; |
jjg@110 | 44 | import java.net.URI; |
jjg@110 | 45 | import javax.lang.model.type.ErrorType; |
jjg@110 | 46 | import javax.lang.model.type.TypeKind; |
jjg@110 | 47 | import javax.lang.model.type.TypeMirror; |
jjg@110 | 48 | import javax.tools.JavaCompiler; |
jjg@110 | 49 | import javax.tools.JavaFileObject; |
jjg@110 | 50 | import javax.tools.SimpleJavaFileObject; |
jjg@110 | 51 | import javax.tools.ToolProvider; |
jjg@110 | 52 | import javax.lang.model.util.Types; |
jjg@110 | 53 | |
jjg@110 | 54 | public class T6557752 { |
jjg@110 | 55 | static class MyFileObject extends SimpleJavaFileObject { |
jjg@110 | 56 | public MyFileObject() { |
jjg@110 | 57 | super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE); |
jjg@110 | 58 | } |
jjg@110 | 59 | public CharSequence getCharContent(boolean ignoreEncodingErrors) { |
jjg@110 | 60 | return "import java.util.*;\n" |
jjg@110 | 61 | + "public class Test {\n" |
jjg@110 | 62 | + " void foobar() {\n" |
jjg@110 | 63 | + " Iterator<Number> itr = null;\n" |
jjg@110 | 64 | + " String str = itr.next();\n" |
jjg@110 | 65 | + " FooBar fooBar = FooBar.foobar();\n" |
jjg@110 | 66 | + " }\n" |
jjg@110 | 67 | + "}"; |
jjg@110 | 68 | } |
jjg@110 | 69 | } |
jjg@110 | 70 | static Trees trees; |
jjg@110 | 71 | static JavacTask task = null; |
jjg@110 | 72 | public static void main(String[] args) throws IOException { |
jjg@110 | 73 | JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); |
jjg@110 | 74 | task = (JavacTask) compiler.getTask(null, null, null, null, null, List.of(new MyFileObject())); |
jjg@110 | 75 | Iterable<? extends CompilationUnitTree> asts = task.parse(); |
jjg@110 | 76 | task.analyze(); |
jjg@110 | 77 | trees = Trees.instance(task); |
jjg@110 | 78 | MyVisitor myVisitor = new MyVisitor(); |
jjg@110 | 79 | for (CompilationUnitTree ast : asts) { |
jjg@110 | 80 | myVisitor.compilationUnit = ast; |
jjg@110 | 81 | myVisitor.scan(ast, null); |
jjg@110 | 82 | } |
jjg@110 | 83 | |
jjg@110 | 84 | if (!myVisitor.foundError) { |
jjg@110 | 85 | throw new AssertionError("Expected error not found!"); |
jjg@110 | 86 | } |
jjg@110 | 87 | } |
jjg@110 | 88 | |
jjg@110 | 89 | static class MyVisitor extends TreePathScanner<Void,Void> { |
jjg@110 | 90 | public boolean foundError = false; |
jjg@110 | 91 | CompilationUnitTree compilationUnit = null; |
jjg@110 | 92 | int i = 0; |
jjg@110 | 93 | @Override |
jjg@110 | 94 | public Void visitMethodInvocation(MethodInvocationTree node, Void ignored) { |
jjg@110 | 95 | TreePath path = TreePath.getPath(compilationUnit, node); |
jjg@110 | 96 | TypeMirror typeMirror = trees.getTypeMirror(path); |
jjg@110 | 97 | if (typeMirror.getKind() == TypeKind.ERROR) { |
jjg@110 | 98 | if (i == 0) { |
jjg@110 | 99 | String str1 = trees.getOriginalType((ErrorType)typeMirror).toString(); |
jjg@110 | 100 | if (!str1.equals("java.lang.Number")) { |
jjg@110 | 101 | throw new AssertionError("Trees.getOriginalType() error!"); |
jjg@110 | 102 | } |
jjg@110 | 103 | |
jjg@110 | 104 | Types types = task.getTypes(); |
jjg@110 | 105 | |
jjg@110 | 106 | str1 = types.asElement(trees.getOriginalType((ErrorType)typeMirror)).toString(); |
jjg@110 | 107 | if (!str1.equals("java.lang.Number")) { |
jjg@110 | 108 | throw new AssertionError("Types.asElement() error!"); |
jjg@110 | 109 | } |
jjg@110 | 110 | |
jjg@110 | 111 | i++; |
jjg@110 | 112 | } |
jjg@110 | 113 | else if (i == 1) { |
jjg@110 | 114 | String str1 = trees.getOriginalType((ErrorType)typeMirror).toString(); |
jjg@110 | 115 | if (!str1.equals("FooBar")) { |
jjg@110 | 116 | throw new AssertionError("Trees.getOriginalType() error!"); |
jjg@110 | 117 | } |
jjg@110 | 118 | |
jjg@110 | 119 | Types types = task.getTypes(); |
jjg@110 | 120 | |
jjg@928 | 121 | str1 = types.asElement(trees.getOriginalType((ErrorType)typeMirror)).toString(); |
jjg@928 | 122 | if (!str1.equals("FooBar")) { |
jjg@904 | 123 | throw new AssertionError("Types.asElement() error!"); |
jjg@110 | 124 | } |
jjg@110 | 125 | foundError = true; |
jjg@110 | 126 | } |
jjg@110 | 127 | } |
jjg@110 | 128 | |
jjg@110 | 129 | |
jjg@110 | 130 | return null; |
jjg@110 | 131 | } |
jjg@110 | 132 | |
jjg@110 | 133 | } |
jjg@110 | 134 | } |