Thu, 25 Jul 2013 14:51:40 +0100
8020843: javac crashes on accessibility check with method reference with typevar receiver
Summary: method reference overload check doesn't walk through type-variable receivers
Reviewed-by: jjg
duke@1 | 1 | /* |
ohair@798 | 2 | * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved. |
duke@1 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@1 | 4 | * |
duke@1 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@1 | 6 | * under the terms of the GNU General Public License version 2 only, as |
duke@1 | 7 | * published by the Free Software Foundation. |
duke@1 | 8 | * |
duke@1 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@1 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@1 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@1 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@1 | 13 | * accompanied this code). |
duke@1 | 14 | * |
duke@1 | 15 | * You should have received a copy of the GNU General Public License version |
duke@1 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@1 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@1 | 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. |
duke@1 | 22 | */ |
duke@1 | 23 | |
duke@1 | 24 | /* |
duke@1 | 25 | * @test |
duke@1 | 26 | * @bug 6403466 |
duke@1 | 27 | * @summary javac TaskListener should be informed when annotation processing occurs |
duke@1 | 28 | */ |
duke@1 | 29 | |
duke@1 | 30 | import com.sun.source.util.*; |
duke@1 | 31 | import java.io.*; |
duke@1 | 32 | import java.lang.annotation.*; |
duke@1 | 33 | import java.util.*; |
duke@1 | 34 | import javax.annotation.processing.*; |
duke@1 | 35 | import javax.lang.model.*; |
duke@1 | 36 | import javax.lang.model.element.*; |
duke@1 | 37 | import javax.lang.model.type.*; |
duke@1 | 38 | import javax.lang.model.util.*; |
duke@1 | 39 | import javax.tools.*; |
duke@1 | 40 | import com.sun.tools.javac.api.JavacTool; |
duke@1 | 41 | |
duke@1 | 42 | @Wrap |
duke@1 | 43 | @SupportedAnnotationTypes("Wrap") |
duke@1 | 44 | public class T6403466 extends AbstractProcessor { |
duke@1 | 45 | |
duke@1 | 46 | static final String testSrcDir = System.getProperty("test.src"); |
duke@1 | 47 | static final String testClassDir = System.getProperty("test.classes"); |
duke@1 | 48 | static final String self = T6403466.class.getName(); |
duke@1 | 49 | static PrintWriter out = new PrintWriter(System.err, true); |
duke@1 | 50 | |
duke@1 | 51 | public static void main(String[] args) throws IOException { |
duke@1 | 52 | JavacTool tool = JavacTool.create(); |
duke@1 | 53 | |
duke@1 | 54 | StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null); |
duke@1 | 55 | Iterable<? extends JavaFileObject> files = |
duke@1 | 56 | fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrcDir, self + ".java"))); |
duke@1 | 57 | |
duke@1 | 58 | Iterable<String> options = Arrays.asList("-processorpath", testClassDir, |
duke@1 | 59 | "-processor", self, |
duke@1 | 60 | "-s", ".", |
duke@1 | 61 | "-d", "."); |
duke@1 | 62 | JavacTask task = tool.getTask(out, fm, null, options, null, files); |
duke@1 | 63 | |
duke@1 | 64 | VerifyingTaskListener vtl = new VerifyingTaskListener(new File(testSrcDir, self + ".out")); |
duke@1 | 65 | task.setTaskListener(vtl); |
duke@1 | 66 | |
duke@1 | 67 | if (!task.call()) |
duke@1 | 68 | throw new AssertionError("compilation failed"); |
duke@1 | 69 | |
duke@1 | 70 | if (vtl.iter.hasNext() || vtl.errors) |
duke@1 | 71 | throw new AssertionError("comparison against golden file failed."); |
duke@1 | 72 | } |
duke@1 | 73 | |
duke@1 | 74 | public boolean process(Set<? extends TypeElement> annos, RoundEnvironment rEnv) { |
darcy@494 | 75 | if (!rEnv.processingOver()) { |
darcy@494 | 76 | Filer filer = processingEnv.getFiler(); |
darcy@494 | 77 | for (TypeElement anno: annos) { |
darcy@494 | 78 | Set<? extends Element> elts = rEnv.getElementsAnnotatedWith(anno); |
darcy@494 | 79 | System.err.println("anno: " + anno); |
darcy@494 | 80 | System.err.println("elts: " + elts); |
darcy@494 | 81 | for (TypeElement te: ElementFilter.typesIn(elts)) { |
darcy@494 | 82 | try { |
darcy@494 | 83 | Writer out = filer.createSourceFile(te.getSimpleName() + "Wrapper").openWriter(); |
darcy@494 | 84 | out.write("class " + te.getSimpleName() + "Wrapper { }"); |
darcy@494 | 85 | out.close(); |
darcy@494 | 86 | } catch (IOException ex) { |
darcy@494 | 87 | ex.printStackTrace(); |
darcy@494 | 88 | } |
duke@1 | 89 | } |
darcy@494 | 90 | |
duke@1 | 91 | } |
duke@1 | 92 | } |
duke@1 | 93 | return true; |
duke@1 | 94 | } |
darcy@494 | 95 | |
darcy@494 | 96 | @Override |
darcy@494 | 97 | public SourceVersion getSupportedSourceVersion() { |
darcy@494 | 98 | return SourceVersion.latest(); |
darcy@494 | 99 | } |
duke@1 | 100 | } |
duke@1 | 101 | |
duke@1 | 102 | @Retention(RetentionPolicy.SOURCE) |
duke@1 | 103 | @Target(ElementType.TYPE) |
duke@1 | 104 | @interface Wrap { |
duke@1 | 105 | } |
duke@1 | 106 | |
duke@1 | 107 | |
duke@1 | 108 | class VerifyingTaskListener implements TaskListener { |
duke@1 | 109 | VerifyingTaskListener(File ref) throws IOException { |
duke@1 | 110 | BufferedReader in = new BufferedReader(new FileReader(ref)); |
duke@1 | 111 | String line; |
duke@1 | 112 | List<String> lines = new ArrayList<String>(); |
duke@1 | 113 | while ((line = in.readLine()) != null) |
duke@1 | 114 | lines.add(line); |
duke@1 | 115 | in.close(); |
duke@1 | 116 | iter = lines.iterator(); |
duke@1 | 117 | } |
duke@1 | 118 | |
duke@1 | 119 | public void started(TaskEvent e) { |
duke@1 | 120 | check("Started " + toString(e)); |
duke@1 | 121 | } |
duke@1 | 122 | public void finished(TaskEvent e) { |
duke@1 | 123 | check("Finished " + toString(e)); |
duke@1 | 124 | } |
duke@1 | 125 | |
duke@1 | 126 | // similar to TaskEvent.toString(), but just prints basename of the file |
duke@1 | 127 | private String toString(TaskEvent e) { |
duke@1 | 128 | JavaFileObject file = e.getSourceFile(); |
duke@1 | 129 | return "TaskEvent[" |
duke@1 | 130 | + e.getKind() + "," |
duke@1 | 131 | + (file == null ? null : new File(file.toUri().getPath()).getName()) + "," |
duke@1 | 132 | // the compilation unit is identified by the file |
duke@1 | 133 | + e.getTypeElement() + "]"; |
duke@1 | 134 | } |
duke@1 | 135 | |
duke@1 | 136 | private void check(String s) { |
duke@1 | 137 | System.out.println(s); // write a reference copy of expected output to stdout |
duke@1 | 138 | |
duke@1 | 139 | String ref = iter.hasNext() ? iter.next() : null; |
duke@1 | 140 | line++; |
duke@1 | 141 | if (!s.equals(ref)) { |
duke@1 | 142 | if (ref != null) |
duke@1 | 143 | System.err.println(line + ": expected: " + ref); |
duke@1 | 144 | System.err.println(line + ": found: " + s); |
duke@1 | 145 | errors = true; |
duke@1 | 146 | } |
duke@1 | 147 | } |
duke@1 | 148 | |
duke@1 | 149 | Iterator<String> iter; |
duke@1 | 150 | int line; |
duke@1 | 151 | boolean errors; |
duke@1 | 152 | } |