1 /* |
1 /* |
2 * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
25 * @test |
25 * @test |
26 * @bug 7115052 |
26 * @bug 7115052 |
27 * @bug 8003280 |
27 * @bug 8003280 |
28 * @summary Add lambda tests |
28 * @summary Add lambda tests |
29 * Add parser support for method references |
29 * Add parser support for method references |
|
30 * @library ../lib |
|
31 * @build JavacTestingAbstractThreadedTest |
|
32 * @run main MethodReferenceParserTest |
30 */ |
33 */ |
31 |
34 |
32 import com.sun.source.util.JavacTask; |
|
33 import java.net.URI; |
35 import java.net.URI; |
34 import java.util.Arrays; |
36 import java.util.Arrays; |
35 import javax.tools.Diagnostic; |
37 import javax.tools.Diagnostic; |
36 import javax.tools.JavaCompiler; |
|
37 import javax.tools.JavaFileObject; |
38 import javax.tools.JavaFileObject; |
38 import javax.tools.SimpleJavaFileObject; |
39 import javax.tools.SimpleJavaFileObject; |
39 import javax.tools.StandardJavaFileManager; |
40 import com.sun.source.util.JavacTask; |
40 import javax.tools.ToolProvider; |
41 |
41 |
42 public class MethodReferenceParserTest |
42 public class MethodReferenceParserTest { |
43 extends JavacTestingAbstractThreadedTest |
43 |
44 implements Runnable { |
44 static int checkCount = 0; |
|
45 |
45 |
46 enum ReferenceKind { |
46 enum ReferenceKind { |
47 METHOD_REF("#Q::#Gm"), |
47 METHOD_REF("#Q::#Gm"), |
48 CONSTRUCTOR_REF("#Q::#Gnew"), |
48 CONSTRUCTOR_REF("#Q::#Gnew"), |
49 FALSE_REF("min < max"), |
49 FALSE_REF("min < max"), |
86 |
86 |
87 ContextKind(String contextTemplate) { |
87 ContextKind(String contextTemplate) { |
88 this.contextTemplate = contextTemplate; |
88 this.contextTemplate = contextTemplate; |
89 } |
89 } |
90 |
90 |
91 String contextString(ExprKind ek, ReferenceKind rk, QualifierKind qk, GenericKind gk, SubExprKind sk) { |
91 String contextString(ExprKind ek, ReferenceKind rk, QualifierKind qk, |
|
92 GenericKind gk, SubExprKind sk) { |
92 return contextTemplate.replaceAll("#E", ek.expressionString(rk, qk, gk, sk)); |
93 return contextTemplate.replaceAll("#E", ek.expressionString(rk, qk, gk, sk)); |
93 } |
94 } |
94 } |
95 } |
95 |
96 |
96 enum GenericKind { |
97 enum GenericKind { |
163 this.subExpression = subExpression; |
164 this.subExpression = subExpression; |
164 } |
165 } |
165 } |
166 } |
166 |
167 |
167 public static void main(String... args) throws Exception { |
168 public static void main(String... args) throws Exception { |
168 |
|
169 //create default shared JavaCompiler - reused across multiple compilations |
|
170 JavaCompiler comp = ToolProvider.getSystemJavaCompiler(); |
|
171 StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null); |
|
172 |
|
173 for (ReferenceKind rk : ReferenceKind.values()) { |
169 for (ReferenceKind rk : ReferenceKind.values()) { |
174 for (QualifierKind qk : QualifierKind.values()) { |
170 for (QualifierKind qk : QualifierKind.values()) { |
175 for (GenericKind gk : GenericKind.values()) { |
171 for (GenericKind gk : GenericKind.values()) { |
176 for (SubExprKind sk : SubExprKind.values()) { |
172 for (SubExprKind sk : SubExprKind.values()) { |
177 for (ExprKind ek : ExprKind.values()) { |
173 for (ExprKind ek : ExprKind.values()) { |
178 for (ContextKind ck : ContextKind.values()) { |
174 for (ContextKind ck : ContextKind.values()) { |
179 new MethodReferenceParserTest(rk, qk, gk, sk, ek, ck).run(comp, fm); |
175 pool.execute(new MethodReferenceParserTest(rk, qk, gk, sk, ek, ck)); |
180 } |
176 } |
181 } |
177 } |
182 } |
178 } |
183 } |
179 } |
184 } |
180 } |
185 } |
181 } |
186 System.out.println("Total check executed: " + checkCount); |
182 |
|
183 checkAfterExec(); |
187 } |
184 } |
188 |
185 |
189 ReferenceKind rk; |
186 ReferenceKind rk; |
190 QualifierKind qk; |
187 QualifierKind qk; |
191 GenericKind gk; |
188 GenericKind gk; |
225 public CharSequence getCharContent(boolean ignoreEncodingErrors) { |
222 public CharSequence getCharContent(boolean ignoreEncodingErrors) { |
226 return source; |
223 return source; |
227 } |
224 } |
228 } |
225 } |
229 |
226 |
230 void run(JavaCompiler tool, StandardJavaFileManager fm) throws Exception { |
227 @Override |
231 JavacTask ct = (JavacTask)tool.getTask(null, fm, diagChecker, |
228 public void run() { |
|
229 JavacTask ct = (JavacTask)comp.getTask(null, fm.get(), diagChecker, |
232 null, null, Arrays.asList(source)); |
230 null, null, Arrays.asList(source)); |
233 try { |
231 try { |
234 ct.parse(); |
232 ct.parse(); |
235 } catch (Throwable ex) { |
233 } catch (Throwable ex) { |
236 throw new AssertionError("Error thrown when parsing the following source:\n" + source.getCharContent(true)); |
234 processException(ex); |
|
235 return; |
237 } |
236 } |
238 check(); |
237 check(); |
239 } |
238 } |
240 |
239 |
241 void check() { |
240 void check() { |
242 checkCount++; |
241 checkCount.incrementAndGet(); |
243 |
242 |
244 if (diagChecker.errorFound != rk.erroneous()) { |
243 if (diagChecker.errorFound != rk.erroneous()) { |
245 throw new Error("invalid diagnostics for source:\n" + |
244 throw new Error("invalid diagnostics for source:\n" + |
246 source.getCharContent(true) + |
245 source.getCharContent(true) + |
247 "\nFound error: " + diagChecker.errorFound + |
246 "\nFound error: " + diagChecker.errorFound + |