Tue, 20 Nov 2012 09:58:55 -0800
8003639: convert lambda testng tests to jtreg and add them
Reviewed-by: mcimadamore
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/test/tools/javac/defaultMethodExecution/DefaultMethodRegressionTests.java Tue Nov 20 09:58:55 2012 -0800 1.3 @@ -0,0 +1,137 @@ 1.4 +/* 1.5 + * Copyright (c) 2012 Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. Oracle designates this 1.11 + * particular file as subject to the "Classpath" exception as provided 1.12 + * by Oracle in the LICENSE file that accompanied this code. 1.13 + * 1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.17 + * version 2 for more details (a copy is included in the LICENSE file that 1.18 + * accompanied this code). 1.19 + * 1.20 + * You should have received a copy of the GNU General Public License version 1.21 + * 2 along with this work; if not, write to the Free Software Foundation, 1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.23 + * 1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.25 + * or visit www.oracle.com if you need additional information or have any 1.26 + * questions. 1.27 + */ 1.28 + 1.29 +/** 1.30 + * @test 1.31 + * @bug 8003639 1.32 + * @summary convert lambda testng tests to jtreg and add them 1.33 + * @run testng DefaultMethodRegressionTests 1.34 + */ 1.35 + 1.36 +import java.util.ArrayList; 1.37 +import java.util.Arrays; 1.38 +import java.util.List; 1.39 +import org.testng.annotations.Test; 1.40 + 1.41 +import static org.testng.Assert.*; 1.42 + 1.43 +/** 1.44 + * This set of classes/interfaces (K/I/C) is specially designed to expose a 1.45 + * bug in the JVM where it did not find some overloaded methods in some 1.46 + * specific situations. (fixed by hotspot changeset ffb9316fd9ed) 1.47 + */ 1.48 +interface K { 1.49 + int bbb(Long l); 1.50 +} 1.51 + 1.52 +interface I extends K { 1.53 + default void aaa() {} 1.54 + default void aab() {} 1.55 + default void aac() {} 1.56 + 1.57 + default int bbb(Integer i) { return 22; } 1.58 + default int bbb(Float f) { return 33; } 1.59 + default int bbb(Long l) { return 44; } 1.60 + default int bbb(Double d) { return 55; } 1.61 + default int bbb(String s) { return 66; } 1.62 + 1.63 + default void caa() {} 1.64 + default void cab() {} 1.65 + default void cac() {} 1.66 +} 1.67 + 1.68 +class C implements I {} 1.69 + 1.70 +public class DefaultMethodRegressionTests { 1.71 + 1.72 + @Test(groups = "vm") 1.73 + public void testLostOverloadedMethod() { 1.74 + C c = new C(); 1.75 + assertEquals(c.bbb(new Integer(1)), 22); 1.76 + assertEquals(c.bbb(new Float(1.1)), 33); 1.77 + assertEquals(c.bbb(new Long(1L)), 44); 1.78 + assertEquals(c.bbb(new Double(0.01)), 55); 1.79 + assertEquals(c.bbb(new String("")), 66); 1.80 + } 1.81 + 1.82 + // Test to ensure that the inference verifier accepts older classfiles 1.83 + // with classes that implement interfaces with defaults. 1.84 + @Test(groups = "vm") 1.85 + public void testInferenceVerifier() { 1.86 + // interface I { int m() default { return 99; } } 1.87 + byte I_bytes[] = { 1.88 + (byte)0xca, (byte)0xfe, (byte)0xba, (byte)0xbe, 0x00, 0x00, 0x00, 0x33, 1.89 + 0x00, 0x08, 0x07, 0x00, 0x06, 0x07, 0x00, 0x07, 1.90 + 0x01, 0x00, 0x03, 0x66, 0x6f, 0x6f, 0x01, 0x00, 1.91 + 0x03, 0x28, 0x29, 0x49, 0x01, 0x00, 0x04, 0x43, 1.92 + 0x6f, 0x64, 0x65, 0x01, 0x00, 0x01, 0x49, 0x01, 1.93 + 0x00, 0x10, 0x6a, 0x61, 0x76, 0x61, 0x2f, 0x6c, 1.94 + 0x61, 0x6e, 0x67, 0x2f, 0x4f, 0x62, 0x6a, 0x65, 1.95 + 0x63, 0x74, 0x06, 0x00, 0x00, 0x01, 0x00, 0x02, 1.96 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x01, 1.97 + 0x00, 0x03, 0x00, 0x04, 0x00, 0x01, 0x00, 0x05, 1.98 + 0x00, 0x00, 0x00, 0x0f, 0x00, 0x01, 0x00, 0x01, 1.99 + 0x00, 0x00, 0x00, 0x03, 0x10, 0x63, (byte)0xac, 0x00, 1.100 + 0x00, 0x00, 0x00, 0x00, 0x00 1.101 + }; 1.102 + // public class C implements I {} /* -target 1.5 */ 1.103 + byte C_bytes[] = { 1.104 + (byte)0xca, (byte)0xfe, (byte)0xba, (byte)0xbe, 0x00, 0x00, 0x00, 0x31, 1.105 + 0x00, 0x0c, 0x0a, 0x00, 0x03, 0x00, 0x08, 0x07, 1.106 + 0x00, 0x09, 0x07, 0x00, 0x0a, 0x07, 0x00, 0x0b, 1.107 + 0x01, 0x00, 0x06, 0x3c, 0x69, 0x6e, 0x69, 0x74, 1.108 + 0x3e, 0x01, 0x00, 0x03, 0x28, 0x29, 0x56, 0x01, 1.109 + 0x00, 0x04, 0x43, 0x6f, 0x64, 0x65, 0x0c, 0x00, 1.110 + 0x05, 0x00, 0x06, 0x01, 0x00, 0x01, 0x43, 0x01, 1.111 + 0x00, 0x10, 0x6a, 0x61, 0x76, 0x61, 0x2f, 0x6c, 1.112 + 0x61, 0x6e, 0x67, 0x2f, 0x4f, 0x62, 0x6a, 0x65, 1.113 + 0x63, 0x74, 0x01, 0x00, 0x01, 0x49, 0x00, 0x21, 1.114 + 0x00, 0x02, 0x00, 0x03, 0x00, 0x01, 0x00, 0x04, 1.115 + 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x05, 1.116 + 0x00, 0x06, 0x00, 0x01, 0x00, 0x07, 0x00, 0x00, 1.117 + 0x00, 0x11, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 1.118 + 0x00, 0x05, 0x2a, (byte)0xb7, 0x00, 0x01, (byte)0xb1, 0x00, 1.119 + 0x00, 0x00, 0x00, 0x00, 0x00 1.120 + }; 1.121 + 1.122 + ClassLoader cl = new ClassLoader() { 1.123 + protected Class<?> findClass(String name) { 1.124 + if (name.equals("I")) { 1.125 + return defineClass("I", I_bytes, 0, I_bytes.length); 1.126 + } else if (name.equals("C")) { 1.127 + return defineClass("C", C_bytes, 0, C_bytes.length); 1.128 + } else { 1.129 + return null; 1.130 + } 1.131 + } 1.132 + }; 1.133 + try { 1.134 + Class.forName("C", true, cl); 1.135 + } catch (Exception e) { 1.136 + // unmodified verifier will throw VerifyError 1.137 + fail("No exception should be thrown"); 1.138 + } 1.139 + } 1.140 +}
2.1 --- a/test/tools/javac/defaultMethods/fd/FDTest.java Tue Nov 20 15:43:28 2012 +0000 2.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 2.3 @@ -1,147 +0,0 @@ 2.4 -/* 2.5 - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 2.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 2.7 - * 2.8 - * This code is free software; you can redistribute it and/or modify it 2.9 - * under the terms of the GNU General Public License version 2 only, as 2.10 - * published by the Free Software Foundation. 2.11 - * 2.12 - * This code is distributed in the hope that it will be useful, but WITHOUT 2.13 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 2.14 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 2.15 - * version 2 for more details (a copy is included in the LICENSE file that 2.16 - * accompanied this code). 2.17 - * 2.18 - * You should have received a copy of the GNU General Public License version 2.19 - * 2 along with this work; if not, write to the Free Software Foundation, 2.20 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2.21 - * 2.22 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2.23 - * or visit www.oracle.com if you need additional information or have any 2.24 - * questions. 2.25 - */ 2.26 - 2.27 -/* 2.28 - * @test 2.29 - * @summary Automatic test for checking correctness of default resolution 2.30 - */ 2.31 - 2.32 -import shapegen.*; 2.33 - 2.34 -import com.sun.source.util.JavacTask; 2.35 - 2.36 -import java.net.URI; 2.37 -import java.util.Arrays; 2.38 -import java.util.ArrayList; 2.39 -import java.util.Collection; 2.40 -import java.util.List; 2.41 - 2.42 -import javax.tools.Diagnostic; 2.43 -import javax.tools.JavaCompiler; 2.44 -import javax.tools.JavaFileObject; 2.45 -import javax.tools.SimpleJavaFileObject; 2.46 -import javax.tools.StandardJavaFileManager; 2.47 -import javax.tools.ToolProvider; 2.48 - 2.49 -public class FDTest { 2.50 - 2.51 - enum TestKind { 2.52 - POSITIVE, 2.53 - NEGATIVE; 2.54 - 2.55 - Collection<Hierarchy> getHierarchy(HierarchyGenerator hg) { 2.56 - return this == POSITIVE ? 2.57 - hg.getOK() : hg.getErr(); 2.58 - } 2.59 - } 2.60 - 2.61 - public static void main(String[] args) throws Exception { 2.62 - //create default shared JavaCompiler - reused across multiple compilations 2.63 - JavaCompiler comp = ToolProvider.getSystemJavaCompiler(); 2.64 - StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null); 2.65 - 2.66 - HierarchyGenerator hg = new HierarchyGenerator(); 2.67 - for (TestKind tk : TestKind.values()) { 2.68 - for (Hierarchy hs : tk.getHierarchy(hg)) { 2.69 - new FDTest(tk, hs).run(comp, fm); 2.70 - } 2.71 - } 2.72 - } 2.73 - 2.74 - TestKind tk; 2.75 - Hierarchy hs; 2.76 - DefenderTestSource source; 2.77 - DiagnosticChecker diagChecker; 2.78 - 2.79 - FDTest(TestKind tk, Hierarchy hs) { 2.80 - this.tk = tk; 2.81 - this.hs = hs; 2.82 - this.source = new DefenderTestSource(); 2.83 - this.diagChecker = new DiagnosticChecker(); 2.84 - } 2.85 - 2.86 - void run(JavaCompiler tool, StandardJavaFileManager fm) throws Exception { 2.87 - JavacTask ct = (JavacTask)tool.getTask(null, fm, diagChecker, 2.88 - null, null, Arrays.asList(source)); 2.89 - try { 2.90 - ct.analyze(); 2.91 - } catch (Throwable ex) { 2.92 - throw new AssertionError("Error thrown when analyzing the following source:\n" + source.getCharContent(true)); 2.93 - } 2.94 - check(); 2.95 - } 2.96 - 2.97 - void check() { 2.98 - boolean errorExpected = tk == TestKind.NEGATIVE; 2.99 - if (errorExpected != diagChecker.errorFound) { 2.100 - throw new AssertionError("problem in source: \n" + 2.101 - "\nerror found = " + diagChecker.errorFound + 2.102 - "\nerror expected = " + errorExpected + 2.103 - "\n" + dumpHierarchy() + 2.104 - "\n" + source.getCharContent(true)); 2.105 - } 2.106 - } 2.107 - 2.108 - String dumpHierarchy() { 2.109 - StringBuilder buf = new StringBuilder(); 2.110 - buf.append("root = " + hs.root + "\n"); 2.111 - for (ClassCase cc : hs.all) { 2.112 - buf.append(" class name = " + cc.getName() + "\n"); 2.113 - buf.append(" class OK = " + cc.get_OK() + "\n"); 2.114 - buf.append(" prov = " + cc.get_mprov() + "\n"); 2.115 - 2.116 - } 2.117 - return buf.toString(); 2.118 - } 2.119 - 2.120 - class DefenderTestSource extends SimpleJavaFileObject { 2.121 - 2.122 - String source; 2.123 - 2.124 - public DefenderTestSource() { 2.125 - super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE); 2.126 - StringBuilder buf = new StringBuilder(); 2.127 - List<ClassCase> defaultRef = new ArrayList<>(); 2.128 - for (ClassCase cc : hs.all) { 2.129 - hs.genClassDef(buf, cc, null, defaultRef); 2.130 - } 2.131 - source = buf.toString(); 2.132 - } 2.133 - 2.134 - @Override 2.135 - public CharSequence getCharContent(boolean ignoreEncodingErrors) { 2.136 - return source; 2.137 - } 2.138 - } 2.139 - 2.140 - static class DiagnosticChecker implements javax.tools.DiagnosticListener<JavaFileObject> { 2.141 - 2.142 - boolean errorFound; 2.143 - 2.144 - public void report(Diagnostic<? extends JavaFileObject> diagnostic) { 2.145 - if (diagnostic.getKind() == Diagnostic.Kind.ERROR) { 2.146 - errorFound = true; 2.147 - } 2.148 - } 2.149 - } 2.150 -}
3.1 --- a/test/tools/javac/defaultMethods/fd/shapegen/ClassCase.java Tue Nov 20 15:43:28 2012 +0000 3.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 3.3 @@ -1,310 +0,0 @@ 3.4 -/* 3.5 - * Copyright (c) 2012, 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. Oracle designates this 3.11 - * particular file as subject to the "Classpath" exception as provided 3.12 - * by Oracle in the LICENSE file that accompanied this code. 3.13 - * 3.14 - * This code is distributed in the hope that it will be useful, but WITHOUT 3.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 3.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 3.17 - * version 2 for more details (a copy is included in the LICENSE file that 3.18 - * accompanied this code). 3.19 - * 3.20 - * You should have received a copy of the GNU General Public License version 3.21 - * 2 along with this work; if not, write to the Free Software Foundation, 3.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 3.23 - * 3.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 3.25 - * or visit www.oracle.com if you need additional information or have any 3.26 - * questions. 3.27 - */ 3.28 - 3.29 -package shapegen; 3.30 - 3.31 -import java.util.ArrayList; 3.32 -import java.util.HashSet; 3.33 -import java.util.List; 3.34 -import java.util.Map; 3.35 -import java.util.Set; 3.36 - 3.37 -/** 3.38 - * 3.39 - * @author Robert Field 3.40 - */ 3.41 -public class ClassCase { 3.42 - 3.43 - public enum Kind { 3.44 - IVAC (true, "v"), 3.45 - IPRESENT (true, "p"), 3.46 - IDEFAULT (true, "d"), 3.47 - CNONE (false, "n"), 3.48 - CABSTRACT (false, "a"), 3.49 - CCONCRETE (false, "c"); 3.50 - 3.51 - private final String prefix; 3.52 - public final boolean isInterface; 3.53 - 3.54 - Kind(boolean isInterface, String prefix) { 3.55 - this.isInterface = isInterface; 3.56 - this.prefix = prefix; 3.57 - } 3.58 - } 3.59 - 3.60 - public final Kind kind; 3.61 - private final ClassCase superclass; 3.62 - private final List<ClassCase> supertypes; 3.63 - 3.64 - private String name; 3.65 - private boolean _OK; 3.66 - private boolean _HasClassMethod; 3.67 - private Set<ClassCase> _mprov; 3.68 - private boolean _IsConcrete; 3.69 - private boolean _HasDefault; 3.70 - private ClassCase _mres; 3.71 - private ClassCase _mdefend; 3.72 - 3.73 - private Set<RuleGroup> executed = new HashSet<RuleGroup>() {}; 3.74 - 3.75 - public ClassCase(Kind kind, ClassCase superclass, List<ClassCase> interfaces) { 3.76 - this.kind = kind; 3.77 - this.superclass = superclass; 3.78 - 3.79 - // Set supertypes from superclass (if any) and interfaces 3.80 - List<ClassCase> lc; 3.81 - if (superclass == null) { 3.82 - lc = interfaces; 3.83 - } else { 3.84 - lc = new ArrayList<>(); 3.85 - lc.add(superclass); 3.86 - lc.addAll(interfaces); 3.87 - } 3.88 - this.supertypes = lc; 3.89 - } 3.90 - 3.91 - public final boolean isInterface() { return kind.isInterface; } 3.92 - public final boolean isClass() { return !kind.isInterface; } 3.93 - 3.94 - public Set<ClassCase> get_mprov() { 3.95 - exec(RuleGroup.PROVENENCE); 3.96 - return _mprov; 3.97 - } 3.98 - 3.99 - public void set_mprov(ClassCase cc) { 3.100 - Set<ClassCase> s = new HashSet<>(); 3.101 - s.add(cc); 3.102 - _mprov = s; 3.103 - } 3.104 - 3.105 - public void set_mprov(Set<ClassCase> s) { 3.106 - _mprov = s; 3.107 - } 3.108 - 3.109 - public ClassCase get_mres() { 3.110 - exec(RuleGroup.RESOLUTION); 3.111 - return _mres; 3.112 - } 3.113 - 3.114 - public void set_mres(ClassCase cc) { 3.115 - _mres = cc; 3.116 - } 3.117 - 3.118 - public ClassCase get_mdefend() { 3.119 - exec(RuleGroup.DEFENDER); 3.120 - return _mdefend; 3.121 - } 3.122 - 3.123 - public void set_mdefend(ClassCase cc) { 3.124 - _mdefend = cc; 3.125 - } 3.126 - 3.127 - public boolean get_HasClassMethod() { 3.128 - exec(RuleGroup.PROVENENCE); 3.129 - return _HasClassMethod; 3.130 - } 3.131 - 3.132 - public void set_HasClassMethod(boolean bool) { 3.133 - _HasClassMethod = bool; 3.134 - } 3.135 - 3.136 - public boolean get_HasDefault() { 3.137 - exec(RuleGroup.MARKER); 3.138 - return _HasDefault; 3.139 - } 3.140 - 3.141 - public void set_HasDefault(boolean bool) { 3.142 - _HasDefault = bool; 3.143 - } 3.144 - 3.145 - public boolean get_IsConcrete() { 3.146 - exec(RuleGroup.MARKER); 3.147 - return _IsConcrete; 3.148 - } 3.149 - 3.150 - public void set_IsConcrete(boolean bool) { 3.151 - _IsConcrete = bool; 3.152 - } 3.153 - 3.154 - public boolean get_OK() { 3.155 - exec(RuleGroup.CHECKING); 3.156 - return _OK; 3.157 - } 3.158 - 3.159 - public void set_OK(boolean bool) { 3.160 - _OK = bool; 3.161 - } 3.162 - 3.163 - public boolean isMethodDefined() { 3.164 - for (ClassCase cc : supertypes) { 3.165 - if (cc.isMethodDefined()) { 3.166 - return true; 3.167 - } 3.168 - } 3.169 - switch (kind) { 3.170 - case CCONCRETE: 3.171 - case CABSTRACT: 3.172 - case IPRESENT: 3.173 - case IDEFAULT: 3.174 - return true; 3.175 - default: 3.176 - return false; 3.177 - } 3.178 - } 3.179 - 3.180 - public boolean isAbstract() { 3.181 - return isMethodDefined() && (get_mres()==null); 3.182 - } 3.183 - 3.184 - public boolean hasSuperclass() { 3.185 - return superclass != null; 3.186 - } 3.187 - 3.188 - public ClassCase getSuperclass() { 3.189 - return superclass; 3.190 - } 3.191 - 3.192 - public List<ClassCase> getSupertypes() { 3.193 - return supertypes; 3.194 - } 3.195 - 3.196 - public List<ClassCase> getInterfaces() { 3.197 - if (superclass != null) { 3.198 - if (supertypes.get(0) != superclass) { 3.199 - throw new AssertionError("superclass missing from supertypes"); 3.200 - } 3.201 - return supertypes.subList(1, supertypes.size()); 3.202 - } else { 3.203 - return supertypes; 3.204 - } 3.205 - } 3.206 - 3.207 - public boolean isSubtypeOf(ClassCase cc) { 3.208 - // S-Refl 3.209 - if (cc.equals(this)) { 3.210 - return true; 3.211 - } 3.212 - 3.213 - // S-Def 3.214 - for (ClassCase sp : getSupertypes()) { 3.215 - if (cc.equals(sp)) { 3.216 - return true; 3.217 - } 3.218 - } 3.219 - 3.220 - // _S-Trans 3.221 - for (ClassCase sp : getSupertypes()) { 3.222 - if (sp.isSubtypeOf(cc)) { 3.223 - return true; 3.224 - } 3.225 - } 3.226 - 3.227 - return false; 3.228 - } 3.229 - 3.230 - public void init(Map<String, Integer> namingContext) { 3.231 - if (name != null) { 3.232 - return; // Already inited 3.233 - } 3.234 - 3.235 - for (ClassCase sup : supertypes) { 3.236 - sup.init(namingContext); 3.237 - } 3.238 - 3.239 - // Build name 3.240 - StringBuilder sb = new StringBuilder(); 3.241 - if (!supertypes.isEmpty()) { 3.242 - sb.append(isInterface() ? "I" : "C"); 3.243 - for (ClassCase cc : supertypes) { 3.244 - sb.append(cc.getName()); 3.245 - } 3.246 - sb.append(kind.isInterface ? "i" : "c"); 3.247 - } 3.248 - sb.append(kind.prefix); 3.249 - String pname = sb.toString(); 3.250 - Integer icnt = namingContext.get(pname); 3.251 - int cnt = icnt == null ? 0 : icnt; 3.252 - ++cnt; 3.253 - namingContext.put(pname, cnt); 3.254 - if (cnt > 1) { 3.255 - sb.append(cnt); 3.256 - } 3.257 - this.name = sb.toString(); 3.258 - } 3.259 - 3.260 - public boolean isa(Kind... kinds) { 3.261 - for (Kind k : kinds) { 3.262 - if (kind == k) { 3.263 - return true; 3.264 - } 3.265 - } 3.266 - return false; 3.267 - } 3.268 - 3.269 - private void exec(RuleGroup rg ) { 3.270 - if (!executed.contains(rg)) { 3.271 - rg.exec(this); 3.272 - executed.add(rg); 3.273 - } 3.274 - } 3.275 - 3.276 - public void collectClasses(Set<ClassCase> seen) { 3.277 - seen.add(this); 3.278 - for (ClassCase cc : supertypes) { 3.279 - cc.collectClasses(seen); 3.280 - } 3.281 - } 3.282 - 3.283 - public String getID() { 3.284 - if (name == null) { 3.285 - throw new Error("Access to uninitialized ClassCase"); 3.286 - } else { 3.287 - return name; 3.288 - } 3.289 - } 3.290 - 3.291 - public final String getName() { 3.292 - if (name == null) { 3.293 - return "ClassCase uninited@" + hashCode(); 3.294 - } else { 3.295 - return name; 3.296 - } 3.297 - } 3.298 - 3.299 - @Override 3.300 - public boolean equals(Object obj) { 3.301 - return obj instanceof ClassCase && getID().equals(((ClassCase)obj).getID()); 3.302 - } 3.303 - 3.304 - @Override 3.305 - public int hashCode() { 3.306 - return getID().hashCode(); 3.307 - } 3.308 - 3.309 - @Override 3.310 - public String toString() { 3.311 - return getName(); 3.312 - } 3.313 -}
4.1 --- a/test/tools/javac/defaultMethods/fd/shapegen/Hierarchy.java Tue Nov 20 15:43:28 2012 +0000 4.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 4.3 @@ -1,143 +0,0 @@ 4.4 -/* 4.5 - * Copyright (c) 2012, 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. Oracle designates this 4.11 - * particular file as subject to the "Classpath" exception as provided 4.12 - * by Oracle in the LICENSE file that accompanied this code. 4.13 - * 4.14 - * This code is distributed in the hope that it will be useful, but WITHOUT 4.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 4.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 4.17 - * version 2 for more details (a copy is included in the LICENSE file that 4.18 - * accompanied this code). 4.19 - * 4.20 - * You should have received a copy of the GNU General Public License version 4.21 - * 2 along with this work; if not, write to the Free Software Foundation, 4.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 4.23 - * 4.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 4.25 - * or visit www.oracle.com if you need additional information or have any 4.26 - * questions. 4.27 - */ 4.28 - 4.29 -package shapegen; 4.30 - 4.31 -import java.util.List; 4.32 -import java.util.HashMap; 4.33 -import java.util.HashSet; 4.34 -import java.util.Set; 4.35 - 4.36 -import static shapegen.ClassCase.Kind.*; 4.37 - 4.38 -/** 4.39 - * 4.40 - * @author Robert Field 4.41 - */ 4.42 -public class Hierarchy { 4.43 - 4.44 - public final ClassCase root; 4.45 - public final Set<ClassCase> all; 4.46 - 4.47 - public Hierarchy(ClassCase root) { 4.48 - this.root = root; 4.49 - root.init(new HashMap<String,Integer>()); 4.50 - Set<ClassCase> allClasses = new HashSet<>(); 4.51 - root.collectClasses(allClasses); 4.52 - this.all = allClasses; 4.53 - } 4.54 - 4.55 - public boolean anyDefaults() { 4.56 - for (ClassCase cc : all) { 4.57 - if (cc.kind == IDEFAULT) { 4.58 - return true; 4.59 - } 4.60 - } 4.61 - return false; 4.62 - } 4.63 - 4.64 - public boolean get_OK() { 4.65 - return root.get_OK(); 4.66 - } 4.67 - 4.68 - public String testName() { 4.69 - return root + "Test"; 4.70 - } 4.71 - 4.72 - private static void genInterfaceList(StringBuilder buf, String prefix, List<ClassCase> interfaces) { 4.73 - if (!interfaces.isEmpty()) { 4.74 - buf.append(" "); 4.75 - buf.append(prefix); 4.76 - buf.append(" "); 4.77 - buf.append(interfaces.get(0)); 4.78 - for (int i = 1; i < interfaces.size(); ++i) { 4.79 - buf.append(", " + interfaces.get(i)); 4.80 - } 4.81 - } 4.82 - } 4.83 - 4.84 - public static void genClassDef(StringBuilder buf, ClassCase cc, String implClass, List<ClassCase> defaultRef) { 4.85 - if (cc.isInterface()) { 4.86 - buf.append("interface "); 4.87 - buf.append(cc.getName() + " "); 4.88 - genInterfaceList(buf, "extends", cc.getInterfaces()); 4.89 - buf.append(" {\n"); 4.90 - 4.91 - switch (cc.kind) { 4.92 - case IDEFAULT: 4.93 - buf.append(" default String m() { return \"\"; }\n"); 4.94 - defaultRef.add(cc); 4.95 - break; 4.96 - case IPRESENT: 4.97 - buf.append(" String m();\n"); 4.98 - break; 4.99 - case IVAC: 4.100 - break; 4.101 - default: 4.102 - throw new AssertionError("Unexpected kind"); 4.103 - } 4.104 - buf.append("}\n\n"); 4.105 - } else { 4.106 - buf.append((cc.isAbstract()? "abstract " : "")); 4.107 - buf.append(" class " + cc.getName()); 4.108 - if (cc.getSuperclass() != null) { 4.109 - buf.append(" extends " + cc.getSuperclass()); 4.110 - } 4.111 - 4.112 - genInterfaceList(buf, "implements", cc.getInterfaces()); 4.113 - buf.append(" {\n"); 4.114 - 4.115 - switch (cc.kind) { 4.116 - case CCONCRETE: 4.117 - buf.append(" public String m() { return \"\"; }\n"); 4.118 - break; 4.119 - case CABSTRACT: 4.120 - buf.append(" public abstract String m();\n"); 4.121 - break; 4.122 - case CNONE: 4.123 - break; 4.124 - default: 4.125 - throw new AssertionError("Unexpected kind"); 4.126 - } 4.127 - buf.append("}\n\n"); 4.128 - } 4.129 - } 4.130 - 4.131 - @Override 4.132 - public boolean equals(Object obj) { 4.133 - return obj instanceof Hierarchy && root.getID().equals(((Hierarchy)obj).root.getID()); 4.134 - } 4.135 - 4.136 - @Override 4.137 - public int hashCode() { 4.138 - return root.getID().hashCode(); 4.139 - } 4.140 - 4.141 - @Override 4.142 - public String toString() { 4.143 - return root.getName(); 4.144 - } 4.145 - 4.146 -}
5.1 --- a/test/tools/javac/defaultMethods/fd/shapegen/HierarchyGenerator.java Tue Nov 20 15:43:28 2012 +0000 5.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 5.3 @@ -1,190 +0,0 @@ 5.4 -/* 5.5 - * Copyright (c) 2012, 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. Oracle designates this 5.11 - * particular file as subject to the "Classpath" exception as provided 5.12 - * by Oracle in the LICENSE file that accompanied this code. 5.13 - * 5.14 - * This code is distributed in the hope that it will be useful, but WITHOUT 5.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 5.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 5.17 - * version 2 for more details (a copy is included in the LICENSE file that 5.18 - * accompanied this code). 5.19 - * 5.20 - * You should have received a copy of the GNU General Public License version 5.21 - * 2 along with this work; if not, write to the Free Software Foundation, 5.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 5.23 - * 5.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 5.25 - * or visit www.oracle.com if you need additional information or have any 5.26 - * questions. 5.27 - */ 5.28 - 5.29 -package shapegen; 5.30 - 5.31 -import shapegen.ClassCase.Kind; 5.32 - 5.33 -import java.util.Collection; 5.34 -import java.util.Set; 5.35 -import java.util.HashSet; 5.36 -import java.util.Collections; 5.37 -import java.util.ArrayList; 5.38 -import java.util.List; 5.39 - 5.40 -import static shapegen.ClassCase.Kind.*; 5.41 - 5.42 -import static java.lang.Math.pow; 5.43 - 5.44 -/** 5.45 - * 5.46 - * @author Robert Field 5.47 - */ 5.48 -public final class HierarchyGenerator { 5.49 - 5.50 - private static int okcnt = 0; 5.51 - private static int errcnt = 0; 5.52 - private static Set<Hierarchy> uniqueOK = new HashSet<>(); 5.53 - private static Set<Hierarchy> uniqueErr = new HashSet<>(); 5.54 - 5.55 - /** 5.56 - * @param args the command line arguments 5.57 - */ 5.58 - public HierarchyGenerator() { 5.59 - organize("exhaustive interface", iExhaustive(2)); 5.60 - organize("exhaustive class", cExhaustive()); 5.61 - organize("shapes interface", iShapes()); 5.62 - organize("shapes class/interface", ciShapes()); 5.63 - 5.64 - System.out.printf("\nExpect OK: %d -- unique %d", okcnt, uniqueOK.size()); 5.65 - System.out.printf("\nExpect Error: %d -- unique %d\n", errcnt, uniqueErr.size()); 5.66 - } 5.67 - 5.68 - public Collection<Hierarchy> getOK() { 5.69 - return uniqueOK; 5.70 - } 5.71 - 5.72 - public Collection<Hierarchy> getErr() { 5.73 - return uniqueErr; 5.74 - } 5.75 - 5.76 - private void organize(String tname, List<Hierarchy> totest) { 5.77 - System.out.printf("\nTesting %s....\n", tname); 5.78 - int nodefault = 0; 5.79 - List<Hierarchy> ok = new ArrayList<>(); 5.80 - List<Hierarchy> err = new ArrayList<>(); 5.81 - for (Hierarchy cc : totest) { 5.82 - if (cc.anyDefaults()) { 5.83 - //System.out.printf(" %s\n", cc); 5.84 - if (cc.get_OK()) { 5.85 - ok.add(cc); 5.86 - } else { 5.87 - err.add(cc); 5.88 - } 5.89 - } else { 5.90 - ++nodefault; 5.91 - } 5.92 - } 5.93 - 5.94 - errcnt += err.size(); 5.95 - okcnt += ok.size(); 5.96 - uniqueErr.addAll(err); 5.97 - uniqueOK.addAll(ok); 5.98 - 5.99 - System.out.printf(" %5d No default\n %5d Error\n %5d OK\n %5d Total\n", 5.100 - nodefault, err.size(), ok.size(), totest.size()); 5.101 - } 5.102 - 5.103 - public List<Hierarchy> iExhaustive(int idepth) { 5.104 - List<ClassCase> current = new ArrayList<>(); 5.105 - for (int i = 0; i < idepth; ++i) { 5.106 - current = ilayer(current); 5.107 - } 5.108 - return wrapInClassAndHierarchy(current); 5.109 - } 5.110 - 5.111 - private List<ClassCase> ilayer(List<ClassCase> srcLayer) { 5.112 - List<ClassCase> lay = new ArrayList<>(); 5.113 - for (int i = (int) pow(2, srcLayer.size()) - 1; i >= 0; --i) { 5.114 - List<ClassCase> itfs = new ArrayList<>(); 5.115 - for (int b = srcLayer.size() - 1; b >= 0; --b) { 5.116 - if ((i & (1<<b)) != 0) { 5.117 - itfs.add(srcLayer.get(b)); 5.118 - } 5.119 - } 5.120 - lay.add(new ClassCase(IVAC, null, itfs)); 5.121 - lay.add(new ClassCase(IPRESENT, null, itfs)); 5.122 - lay.add(new ClassCase(IDEFAULT, null, itfs)); 5.123 - lay.add(new ClassCase(IDEFAULT, null, itfs)); 5.124 - } 5.125 - return lay; 5.126 - } 5.127 - 5.128 - public List<Hierarchy> cExhaustive() { 5.129 - final Kind[] iKinds = new Kind[]{IDEFAULT, IVAC, IPRESENT, null}; 5.130 - final Kind[] cKinds = new Kind[]{CNONE, CABSTRACT, CCONCRETE}; 5.131 - List<Hierarchy> totest = new ArrayList<>(); 5.132 - for (int i1 = 0; i1 < iKinds.length; ++i1) { 5.133 - for (int i2 = 0; i2 < iKinds.length; ++i2) { 5.134 - for (int i3 = 0; i3 < iKinds.length; ++i3) { 5.135 - for (int c1 = 0; c1 < cKinds.length; ++c1) { 5.136 - for (int c2 = 0; c2 < cKinds.length; ++c2) { 5.137 - for (int c3 = 0; c3 < cKinds.length; ++c3) { 5.138 - totest.add( new Hierarchy( 5.139 - new ClassCase(cKinds[c1], 5.140 - new ClassCase(cKinds[c2], 5.141 - new ClassCase(cKinds[c3], 5.142 - null, 5.143 - iList(iKinds[i1]) 5.144 - ), 5.145 - iList(iKinds[i2]) 5.146 - ), 5.147 - iList(iKinds[i3]) 5.148 - ))); 5.149 - } 5.150 - } 5.151 - } 5.152 - } 5.153 - } 5.154 - } 5.155 - return totest; 5.156 - } 5.157 - 5.158 - private List<ClassCase> iList(Kind kind) { 5.159 - if (kind == null) { 5.160 - return Collections.EMPTY_LIST; 5.161 - } else { 5.162 - List<ClassCase> itfs = new ArrayList<>(); 5.163 - itfs.add(new ClassCase(kind, null, Collections.EMPTY_LIST)); 5.164 - return itfs; 5.165 - } 5.166 - } 5.167 - 5.168 - public List<Hierarchy> ciShapes() { 5.169 - return wrapInHierarchy(TTShape.allCases(true)); 5.170 - } 5.171 - 5.172 - public List<Hierarchy> iShapes() { 5.173 - return wrapInClassAndHierarchy(TTShape.allCases(false)); 5.174 - } 5.175 - 5.176 - public List<Hierarchy> wrapInClassAndHierarchy(List<ClassCase> ihs) { 5.177 - List<Hierarchy> totest = new ArrayList<>(); 5.178 - for (ClassCase cc : ihs) { 5.179 - List<ClassCase> interfaces = new ArrayList<>(); 5.180 - interfaces.add(cc); 5.181 - totest.add(new Hierarchy(new ClassCase(CNONE, null, interfaces))); 5.182 - } 5.183 - return totest; 5.184 - } 5.185 - 5.186 - public List<Hierarchy> wrapInHierarchy(List<ClassCase> ihs) { 5.187 - List<Hierarchy> totest = new ArrayList<>(); 5.188 - for (ClassCase cc : ihs) { 5.189 - totest.add(new Hierarchy(cc)); 5.190 - } 5.191 - return totest; 5.192 - } 5.193 -}
6.1 --- a/test/tools/javac/defaultMethods/fd/shapegen/Rule.java Tue Nov 20 15:43:28 2012 +0000 6.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 6.3 @@ -1,48 +0,0 @@ 6.4 -/* 6.5 - * Copyright (c) 2012, 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. Oracle designates this 6.11 - * particular file as subject to the "Classpath" exception as provided 6.12 - * by Oracle in the LICENSE file that accompanied this code. 6.13 - * 6.14 - * This code is distributed in the hope that it will be useful, but WITHOUT 6.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 6.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 6.17 - * version 2 for more details (a copy is included in the LICENSE file that 6.18 - * accompanied this code). 6.19 - * 6.20 - * You should have received a copy of the GNU General Public License version 6.21 - * 2 along with this work; if not, write to the Free Software Foundation, 6.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 6.23 - * 6.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 6.25 - * or visit www.oracle.com if you need additional information or have any 6.26 - * questions. 6.27 - */ 6.28 - 6.29 -package shapegen; 6.30 - 6.31 -/** 6.32 - * 6.33 - * @author Robert Field 6.34 - */ 6.35 -public abstract class Rule { 6.36 - 6.37 - public final String name; 6.38 - 6.39 - public Rule(String name) { 6.40 - this.name = name; 6.41 - } 6.42 - 6.43 - abstract boolean guard(ClassCase cc); 6.44 - 6.45 - abstract void eval(ClassCase cc); 6.46 - 6.47 - @Override 6.48 - public String toString() { 6.49 - return name; 6.50 - } 6.51 -}
7.1 --- a/test/tools/javac/defaultMethods/fd/shapegen/RuleGroup.java Tue Nov 20 15:43:28 2012 +0000 7.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 7.3 @@ -1,206 +0,0 @@ 7.4 -/* 7.5 - * Copyright (c) 2012, 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. Oracle designates this 7.11 - * particular file as subject to the "Classpath" exception as provided 7.12 - * by Oracle in the LICENSE file that accompanied this code. 7.13 - * 7.14 - * This code is distributed in the hope that it will be useful, but WITHOUT 7.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 7.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 7.17 - * version 2 for more details (a copy is included in the LICENSE file that 7.18 - * accompanied this code). 7.19 - * 7.20 - * You should have received a copy of the GNU General Public License version 7.21 - * 2 along with this work; if not, write to the Free Software Foundation, 7.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 7.23 - * 7.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 7.25 - * or visit www.oracle.com if you need additional information or have any 7.26 - * questions. 7.27 - */ 7.28 - 7.29 -package shapegen; 7.30 - 7.31 -import java.util.HashSet; 7.32 -import java.util.Set; 7.33 - 7.34 -import static shapegen.ClassCase.Kind.*; 7.35 - 7.36 -/** 7.37 - * 7.38 - * @author Robert Field 7.39 - */ 7.40 -public class RuleGroup { 7.41 - 7.42 - final String name; 7.43 - private final Rule[] rules; 7.44 - 7.45 - public RuleGroup(String name, Rule[] rules) { 7.46 - this.name = name; 7.47 - this.rules = rules; 7.48 - } 7.49 - 7.50 - public boolean exec(ClassCase cc) { 7.51 - boolean found = false; 7.52 - for (Rule rule : rules) { 7.53 - if (rule.guard(cc)) { 7.54 - if (found) { 7.55 - throw new RuntimeException("Bad rules -- multiple matches " + toString() + " for " + cc); 7.56 - } else { 7.57 - rule.eval(cc); 7.58 - found = true; 7.59 - } 7.60 - } 7.61 - } 7.62 - return found; 7.63 - } 7.64 - 7.65 - @Override 7.66 - public String toString() { 7.67 - return name; 7.68 - } 7.69 - 7.70 - public static RuleGroup PROVENENCE = new RuleGroup("Provenence", new Rule[] { 7.71 - new Rule("P-CDeclare") { 7.72 - boolean guard(ClassCase cc) { 7.73 - return cc.isa(CCONCRETE, CABSTRACT); 7.74 - } 7.75 - 7.76 - void eval(ClassCase cc) { 7.77 - cc.set_mprov(cc); 7.78 - cc.set_HasClassMethod(true); 7.79 - } 7.80 - }, 7.81 - 7.82 - new Rule("P-IDeclare") { 7.83 - boolean guard(ClassCase cc) { 7.84 - return cc.isa(IDEFAULT, IPRESENT); 7.85 - } 7.86 - 7.87 - void eval(ClassCase cc) { 7.88 - cc.set_mprov(cc); 7.89 - } 7.90 - }, 7.91 - 7.92 - new Rule("P-IntfInh") { 7.93 - boolean guard(ClassCase cc) { 7.94 - return cc.isa(IVAC, CNONE) && !(cc.hasSuperclass() && cc.getSuperclass().get_HasClassMethod()); 7.95 - } 7.96 - 7.97 - void eval(ClassCase cc) { 7.98 - Set<ClassCase> _S = new HashSet<>(); 7.99 - for (ClassCase t : cc.getSupertypes()) { 7.100 - _S.addAll(t.get_mprov()); 7.101 - } 7.102 - Set<ClassCase> tops = new HashSet<>(); 7.103 - for (ClassCase _W : _S) { 7.104 - for (ClassCase _V : _S) { 7.105 - if (_V.equals(_W) || !(_V.isSubtypeOf(_W))) { 7.106 - tops.add(_W); 7.107 - } 7.108 - } 7.109 - } 7.110 - cc.set_mprov(tops); 7.111 - } 7.112 - }, 7.113 - 7.114 - new Rule("P-ClassInh") { 7.115 - boolean guard(ClassCase cc) { 7.116 - return cc.isa(CNONE) && (cc.hasSuperclass() && cc.getSuperclass().get_HasClassMethod()); 7.117 - } 7.118 - 7.119 - void eval(ClassCase cc) { 7.120 - cc.set_mprov(cc.getSuperclass()); 7.121 - cc.set_HasClassMethod(true); 7.122 - } 7.123 - }, 7.124 - 7.125 - }); 7.126 - 7.127 - public static RuleGroup MARKER = new RuleGroup("Marker", new Rule[] { 7.128 - new Rule("M-Default") { 7.129 - boolean guard(ClassCase cc) { 7.130 - return cc.isa(IDEFAULT); 7.131 - } 7.132 - 7.133 - void eval(ClassCase cc) { 7.134 - cc.set_HasDefault(true); 7.135 - } 7.136 - }, 7.137 - 7.138 - new Rule("M-Conc") { 7.139 - boolean guard(ClassCase cc) { 7.140 - return cc.isa(CCONCRETE); 7.141 - } 7.142 - 7.143 - void eval(ClassCase cc) { 7.144 - cc.set_IsConcrete(true); 7.145 - } 7.146 - }, 7.147 - 7.148 - }); 7.149 - 7.150 - public static RuleGroup RESOLUTION = new RuleGroup("Resolution", new Rule[] { 7.151 - new Rule("R-Resolve") { 7.152 - boolean guard(ClassCase cc) { 7.153 - if (!(cc.isClass() && cc.get_mprov().size() == 1)) { 7.154 - return false; 7.155 - } 7.156 - ClassCase _V = cc.get_mprov().iterator().next(); 7.157 - return _V.get_IsConcrete() || _V.get_HasDefault(); 7.158 - } 7.159 - 7.160 - void eval(ClassCase cc) { 7.161 - ClassCase _V = cc.get_mprov().iterator().next(); 7.162 - cc.set_mres(_V); 7.163 - } 7.164 - }, 7.165 - 7.166 - }); 7.167 - 7.168 - public static RuleGroup DEFENDER = new RuleGroup("Defender", new Rule[] { 7.169 - new Rule("D-Defend") { 7.170 - boolean guard(ClassCase cc) { 7.171 - ClassCase mresSuper = cc.hasSuperclass() ? cc.getSuperclass().get_mres() : null; 7.172 - boolean eq = cc.get_mres() == null ? mresSuper == null : cc.get_mres().equals(mresSuper); 7.173 - return cc.isa(CNONE) && !eq; 7.174 - } 7.175 - 7.176 - void eval(ClassCase cc) { 7.177 - cc.set_mdefend(cc.get_mres()); 7.178 - } 7.179 - }, 7.180 - 7.181 - }); 7.182 - 7.183 - public static RuleGroup CHECKING = new RuleGroup("Checking", new Rule[] { 7.184 - new Rule("C-Check") { 7.185 - boolean guard(ClassCase cc) { 7.186 - for (ClassCase t : cc.getSupertypes()) { 7.187 - if (! t.get_OK()) { 7.188 - return false; 7.189 - } 7.190 - } 7.191 - int defenderCount = 0; 7.192 - int provCount = 0; 7.193 - for (ClassCase prov : cc.get_mprov()) { 7.194 - if (prov.get_HasDefault()) { 7.195 - defenderCount++; 7.196 - } 7.197 - provCount++; 7.198 - } 7.199 - return provCount <= 1 || defenderCount == 0; 7.200 - } 7.201 - 7.202 - void eval(ClassCase cc) { 7.203 - cc.set_OK(true); 7.204 - } 7.205 - }, 7.206 - 7.207 - }); 7.208 - 7.209 -}
8.1 --- a/test/tools/javac/defaultMethods/fd/shapegen/TTNode.java Tue Nov 20 15:43:28 2012 +0000 8.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 8.3 @@ -1,126 +0,0 @@ 8.4 -/* 8.5 - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 8.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 8.7 - * 8.8 - * This code is free software; you can redistribute it and/or modify it 8.9 - * under the terms of the GNU General Public License version 2 only, as 8.10 - * published by the Free Software Foundation. Oracle designates this 8.11 - * particular file as subject to the "Classpath" exception as provided 8.12 - * by Oracle in the LICENSE file that accompanied this code. 8.13 - * 8.14 - * This code is distributed in the hope that it will be useful, but WITHOUT 8.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 8.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 8.17 - * version 2 for more details (a copy is included in the LICENSE file that 8.18 - * accompanied this code). 8.19 - * 8.20 - * You should have received a copy of the GNU General Public License version 8.21 - * 2 along with this work; if not, write to the Free Software Foundation, 8.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 8.23 - * 8.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 8.25 - * or visit www.oracle.com if you need additional information or have any 8.26 - * questions. 8.27 - */ 8.28 - 8.29 -package shapegen; 8.30 - 8.31 -import shapegen.ClassCase.Kind; 8.32 - 8.33 -import java.util.ArrayList; 8.34 -import java.util.List; 8.35 -import java.util.Set; 8.36 - 8.37 -import static shapegen.ClassCase.Kind.*; 8.38 - 8.39 -/** 8.40 - * Type Template Node 8.41 - * 8.42 - * @author Robert Field 8.43 - */ 8.44 -public class TTNode { 8.45 - 8.46 - final List<TTNode> supertypes; 8.47 - final boolean canBeClass; 8.48 - 8.49 - private int currentKindIndex; 8.50 - private Kind[] kinds; 8.51 - 8.52 - public TTNode(List<TTNode> subtypes, boolean canBeClass) { 8.53 - this.supertypes = subtypes; 8.54 - this.canBeClass = canBeClass; 8.55 - } 8.56 - 8.57 - public void start(boolean includeClasses) { 8.58 - kinds = 8.59 - supertypes.isEmpty()? 8.60 - (new Kind[]{IDEFAULT, IPRESENT}) 8.61 - : ((includeClasses && canBeClass)? 8.62 - new Kind[]{CNONE, IVAC, IDEFAULT, IPRESENT} 8.63 - : new Kind[]{IVAC, IDEFAULT, IPRESENT}); 8.64 - currentKindIndex = 0; 8.65 - 8.66 - for (TTNode sub : supertypes) { 8.67 - sub.start(includeClasses); 8.68 - } 8.69 - } 8.70 - 8.71 - public boolean next() { 8.72 - ++currentKindIndex; 8.73 - if (currentKindIndex >= kinds.length) { 8.74 - currentKindIndex = 0; 8.75 - return false; 8.76 - } else { 8.77 - return true; 8.78 - } 8.79 - } 8.80 - 8.81 - public void collectAllSubtypes(Set<TTNode> subs) { 8.82 - subs.add(this); 8.83 - for (TTNode n : supertypes) { 8.84 - n.collectAllSubtypes(subs); 8.85 - } 8.86 - } 8.87 - 8.88 - private Kind getKind() { 8.89 - return kinds[currentKindIndex]; 8.90 - } 8.91 - 8.92 - boolean isInterface() { 8.93 - return getKind().isInterface; 8.94 - } 8.95 - 8.96 - boolean isClass() { 8.97 - return !isInterface(); 8.98 - } 8.99 - 8.100 - boolean hasDefault() { 8.101 - return getKind() == IDEFAULT; 8.102 - } 8.103 - 8.104 - public boolean isValid() { 8.105 - for (TTNode n : supertypes) { 8.106 - if (!n.isValid() || (isInterface() && n.isClass())) { 8.107 - return false; 8.108 - } 8.109 - } 8.110 - return true; 8.111 - } 8.112 - 8.113 - public ClassCase genCase() { 8.114 - ClassCase subclass; 8.115 - List<TTNode> ttintfs; 8.116 - if (isClass() && !supertypes.isEmpty() && supertypes.get(0).isClass()) { 8.117 - subclass = supertypes.get(0).genCase(); 8.118 - ttintfs = supertypes.subList(1, supertypes.size()); 8.119 - } else { 8.120 - subclass = null; 8.121 - ttintfs = supertypes; 8.122 - } 8.123 - List<ClassCase> intfs = new ArrayList<>(); 8.124 - for (TTNode node : ttintfs) { 8.125 - intfs.add(node.genCase()); 8.126 - } 8.127 - return new ClassCase(getKind(), subclass, intfs); 8.128 - } 8.129 -}
9.1 --- a/test/tools/javac/defaultMethods/fd/shapegen/TTParser.java Tue Nov 20 15:43:28 2012 +0000 9.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 9.3 @@ -1,100 +0,0 @@ 9.4 -/* 9.5 - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 9.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 9.7 - * 9.8 - * This code is free software; you can redistribute it and/or modify it 9.9 - * under the terms of the GNU General Public License version 2 only, as 9.10 - * published by the Free Software Foundation. Oracle designates this 9.11 - * particular file as subject to the "Classpath" exception as provided 9.12 - * by Oracle in the LICENSE file that accompanied this code. 9.13 - * 9.14 - * This code is distributed in the hope that it will be useful, but WITHOUT 9.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 9.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 9.17 - * version 2 for more details (a copy is included in the LICENSE file that 9.18 - * accompanied this code). 9.19 - * 9.20 - * You should have received a copy of the GNU General Public License version 9.21 - * 2 along with this work; if not, write to the Free Software Foundation, 9.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 9.23 - * 9.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 9.25 - * or visit www.oracle.com if you need additional information or have any 9.26 - * questions. 9.27 - */ 9.28 - 9.29 -package shapegen; 9.30 - 9.31 -import java.util.ArrayList; 9.32 -import java.util.HashMap; 9.33 -import java.util.List; 9.34 -import java.util.Map; 9.35 -import java.io.IOException; 9.36 -import java.io.StringReader; 9.37 - 9.38 -import static java.lang.Character.isLetter; 9.39 -import static java.lang.Character.isUpperCase; 9.40 -import static java.lang.Character.isWhitespace; 9.41 - 9.42 -/** 9.43 - * Parse a type template definition string 9.44 - * 9.45 - * input :: classDef 9.46 - * classDef :: letter [ ( classDef* ) ] 9.47 - * 9.48 - * @author Robert Field 9.49 - */ 9.50 -public class TTParser extends StringReader { 9.51 - 9.52 - private Map<Character, TTNode> letterMap = new HashMap<>(); 9.53 - private char ch; 9.54 - 9.55 - private final String def; 9.56 - 9.57 - public TTParser(String s) { 9.58 - super(s); 9.59 - this.def = s; 9.60 - } 9.61 - 9.62 - private void advance() throws IOException { 9.63 - do { 9.64 - ch = (char)read(); 9.65 - } while (isWhitespace(ch)); 9.66 - } 9.67 - 9.68 - public TTNode parse() { 9.69 - try { 9.70 - advance(); 9.71 - return classDef(); 9.72 - } catch (IOException t) { 9.73 - throw new RuntimeException(t); 9.74 - } 9.75 - } 9.76 - 9.77 - private TTNode classDef() throws IOException { 9.78 - if (!isLetter(ch)) { 9.79 - if (ch == (char)-1) { 9.80 - throw new IOException("Unexpected end of type template in " + def); 9.81 - } else { 9.82 - throw new IOException("Unexpected character in type template: " + (Character)ch + " in " + def); 9.83 - } 9.84 - } 9.85 - char nodeCh = ch; 9.86 - TTNode node = letterMap.get(nodeCh); 9.87 - boolean canBeClass = isUpperCase(nodeCh); 9.88 - advance(); 9.89 - if (node == null) { 9.90 - List<TTNode> subtypes = new ArrayList<>(); 9.91 - if (ch == '(') { 9.92 - advance(); 9.93 - while (ch != ')') { 9.94 - subtypes.add(classDef()); 9.95 - } 9.96 - advance(); 9.97 - } 9.98 - node = new TTNode(subtypes, canBeClass); 9.99 - letterMap.put(nodeCh, node); 9.100 - } 9.101 - return node; 9.102 - } 9.103 -}
10.1 --- a/test/tools/javac/defaultMethods/fd/shapegen/TTShape.java Tue Nov 20 15:43:28 2012 +0000 10.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 10.3 @@ -1,104 +0,0 @@ 10.4 -/* 10.5 - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 10.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 10.7 - * 10.8 - * This code is free software; you can redistribute it and/or modify it 10.9 - * under the terms of the GNU General Public License version 2 only, as 10.10 - * published by the Free Software Foundation. Oracle designates this 10.11 - * particular file as subject to the "Classpath" exception as provided 10.12 - * by Oracle in the LICENSE file that accompanied this code. 10.13 - * 10.14 - * This code is distributed in the hope that it will be useful, but WITHOUT 10.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 10.17 - * version 2 for more details (a copy is included in the LICENSE file that 10.18 - * accompanied this code). 10.19 - * 10.20 - * You should have received a copy of the GNU General Public License version 10.21 - * 2 along with this work; if not, write to the Free Software Foundation, 10.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 10.23 - * 10.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 10.25 - * or visit www.oracle.com if you need additional information or have any 10.26 - * questions. 10.27 - */ 10.28 - 10.29 -package shapegen; 10.30 - 10.31 -import java.util.ArrayList; 10.32 -import java.util.HashSet; 10.33 -import java.util.List; 10.34 -import java.util.Set; 10.35 - 10.36 -/** 10.37 - * 10.38 - * @author Robert Field 10.39 - */ 10.40 -public class TTShape { 10.41 - 10.42 - private final TTNode root; 10.43 - private final TTNode[] nodes; 10.44 - 10.45 - TTShape(TTNode root) { 10.46 - this.root = root; 10.47 - Set<TTNode> subs = new HashSet<>(); 10.48 - root.collectAllSubtypes(subs); 10.49 - nodes = subs.toArray(new TTNode[subs.size()]); 10.50 - } 10.51 - 10.52 - private List<ClassCase> toCases(boolean includeClasses) { 10.53 - List<ClassCase> ccs = new ArrayList<>(); 10.54 - root.start(includeClasses); 10.55 - int i; 10.56 - outer: 10.57 - while (true) { 10.58 - if (root.isValid()) { 10.59 - ClassCase cc = root.genCase(); 10.60 - //System.out.println(cc); 10.61 - ccs.add(cc); 10.62 - } 10.63 - 10.64 - i = 0; 10.65 - do { 10.66 - if (i >= nodes.length) { 10.67 - break outer; 10.68 - } 10.69 - } while(!nodes[i++].next()); 10.70 - } 10.71 - return ccs; 10.72 - } 10.73 - 10.74 - public static List<ClassCase> allCases(boolean includeClasses) { 10.75 - List<ClassCase> ccs = new ArrayList<>(); 10.76 - for (TTShape shape : SHAPES) { 10.77 - ccs.addAll(shape.toCases(includeClasses)); 10.78 - } 10.79 - return ccs; 10.80 - } 10.81 - 10.82 - public static TTShape parse(String s) { 10.83 - return new TTShape(new TTParser(s).parse()); 10.84 - } 10.85 - 10.86 - public static final TTShape[] SHAPES = new TTShape[] { 10.87 - parse("a"), 10.88 - parse("a(b)"), 10.89 - parse("A(bb)"), 10.90 - parse("A(B(d)c(d))"), 10.91 - parse("A(b(c))"), 10.92 - parse("A(B(cd)d)"), 10.93 - parse("A(B(c)c)"), 10.94 - parse("A(B(Ce)d(e))"), 10.95 - parse("A(B(C)d(e))"), 10.96 - parse("A(Bc(d))"), 10.97 - parse("A(B(d)dc)"), 10.98 - parse("A(B(dc)dc)"), 10.99 - parse("A(B(c(d))d)"), 10.100 - parse("A(B(C(d))d)"), 10.101 - parse("A(B(C(e)d(e))e)"), 10.102 - parse("A(B(c(d))c)"), 10.103 - parse("A(B(dc(d))c)"), 10.104 - parse("A(B(C(d))d)"), 10.105 - }; 10.106 - 10.107 -}
11.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 11.2 +++ b/test/tools/javac/lambda/lambdaExecution/InInterface.java Tue Nov 20 09:58:55 2012 -0800 11.3 @@ -0,0 +1,64 @@ 11.4 +/* 11.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 11.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 11.7 + * 11.8 + * This code is free software; you can redistribute it and/or modify it 11.9 + * under the terms of the GNU General Public License version 2 only, as 11.10 + * published by the Free Software Foundation. Oracle designates this 11.11 + * particular file as subject to the "Classpath" exception as provided 11.12 + * by Oracle in the LICENSE file that accompanied this code. 11.13 + * 11.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 11.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 11.17 + * version 2 for more details (a copy is included in the LICENSE file that 11.18 + * accompanied this code). 11.19 + * 11.20 + * You should have received a copy of the GNU General Public License version 11.21 + * 2 along with this work; if not, write to the Free Software Foundation, 11.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 11.23 + * 11.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 11.25 + * or visit www.oracle.com if you need additional information or have any 11.26 + * questions. 11.27 + */ 11.28 + 11.29 +/** 11.30 + * @test 11.31 + * @bug 8003639 11.32 + * @summary convert lambda testng tests to jtreg and add them 11.33 + * @run testng InInterface 11.34 + */ 11.35 + 11.36 +import static org.testng.Assert.assertEquals; 11.37 +import org.testng.annotations.Test; 11.38 + 11.39 +interface LTII { 11.40 + 11.41 + interface ILsp1 { 11.42 + String m(); 11.43 + } 11.44 + 11.45 + interface ILsp2 { 11.46 + String m(String x); 11.47 + } 11.48 + 11.49 + default ILsp1 t1() { 11.50 + return () -> { return "yo"; }; 11.51 + } 11.52 + 11.53 + default ILsp2 t2() { 11.54 + return (x) -> { return "snur" + x; }; 11.55 + } 11.56 + 11.57 +} 11.58 + 11.59 +@Test 11.60 +public class InInterface implements LTII { 11.61 + 11.62 + public void testLambdaInDefaultMethod() { 11.63 + assertEquals(t1().m(), "yo"); 11.64 + assertEquals(t2().m("p"), "snurp"); 11.65 + } 11.66 + 11.67 +}
12.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 12.2 +++ b/test/tools/javac/lambda/lambdaExecution/InnerConstructor.java Tue Nov 20 09:58:55 2012 -0800 12.3 @@ -0,0 +1,75 @@ 12.4 +/* 12.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 12.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 12.7 + * 12.8 + * This code is free software; you can redistribute it and/or modify it 12.9 + * under the terms of the GNU General Public License version 2 only, as 12.10 + * published by the Free Software Foundation. Oracle designates this 12.11 + * particular file as subject to the "Classpath" exception as provided 12.12 + * by Oracle in the LICENSE file that accompanied this code. 12.13 + * 12.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 12.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12.17 + * version 2 for more details (a copy is included in the LICENSE file that 12.18 + * accompanied this code). 12.19 + * 12.20 + * You should have received a copy of the GNU General Public License version 12.21 + * 2 along with this work; if not, write to the Free Software Foundation, 12.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 12.23 + * 12.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 12.25 + * or visit www.oracle.com if you need additional information or have any 12.26 + * questions. 12.27 + */ 12.28 + 12.29 +/** 12.30 + * @test 12.31 + * @bug 8003639 12.32 + * @summary convert lambda testng tests to jtreg and add them 12.33 + * @run testng InnerConstructor 12.34 + */ 12.35 + 12.36 +import static org.testng.Assert.assertEquals; 12.37 +import org.testng.annotations.Test; 12.38 + 12.39 +@Test 12.40 +public class InnerConstructor { 12.41 + 12.42 + public void testLambdaWithInnerConstructor() { 12.43 + assertEquals(seq1().m().toString(), "Cbl:nada"); 12.44 + assertEquals(seq2().m("rats").toString(), "Cbl:rats"); 12.45 + } 12.46 + 12.47 + Ib1 seq1() { 12.48 + return () -> { return new Cbl(); }; 12.49 + } 12.50 + 12.51 + Ib2 seq2() { 12.52 + return (x) -> { return new Cbl(x); }; 12.53 + } 12.54 + 12.55 + class Cbl { 12.56 + String val; 12.57 + 12.58 + Cbl() { 12.59 + this.val = "nada"; 12.60 + } 12.61 + 12.62 + Cbl(String z) { 12.63 + this.val = z; 12.64 + } 12.65 + 12.66 + public String toString() { 12.67 + return "Cbl:" + val; 12.68 + } 12.69 + } 12.70 + 12.71 + interface Ib1 { 12.72 + Object m(); 12.73 + } 12.74 + 12.75 + interface Ib2 { 12.76 + Object m(String x); 12.77 + } 12.78 +}
13.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 13.2 +++ b/test/tools/javac/lambda/lambdaExecution/LambdaTranslationTest1.java Tue Nov 20 09:58:55 2012 -0800 13.3 @@ -0,0 +1,234 @@ 13.4 +/* 13.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 13.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 13.7 + * 13.8 + * This code is free software; you can redistribute it and/or modify it 13.9 + * under the terms of the GNU General Public License version 2 only, as 13.10 + * published by the Free Software Foundation. Oracle designates this 13.11 + * particular file as subject to the "Classpath" exception as provided 13.12 + * by Oracle in the LICENSE file that accompanied this code. 13.13 + * 13.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 13.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13.17 + * version 2 for more details (a copy is included in the LICENSE file that 13.18 + * accompanied this code). 13.19 + * 13.20 + * You should have received a copy of the GNU General Public License version 13.21 + * 2 along with this work; if not, write to the Free Software Foundation, 13.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 13.23 + * 13.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 13.25 + * or visit www.oracle.com if you need additional information or have any 13.26 + * questions. 13.27 + */ 13.28 + 13.29 +/** 13.30 + * @test 13.31 + * @bug 8003639 13.32 + * @summary convert lambda testng tests to jtreg and add them 13.33 + * @run testng LambdaTranslationTest1 13.34 + */ 13.35 + 13.36 +import org.testng.annotations.Test; 13.37 + 13.38 +import static org.testng.Assert.assertEquals; 13.39 + 13.40 +@Test 13.41 +public class LambdaTranslationTest1 extends LT1Sub { 13.42 + 13.43 + String cntxt = "blah"; 13.44 + 13.45 + private static final ThreadLocal<Object> result = new ThreadLocal<>(); 13.46 + 13.47 + private static void setResult(Object s) { result.set(s); } 13.48 + private static void appendResult(Object s) { result.set(result.get().toString() + s); } 13.49 + 13.50 + private static void assertResult(String expected) { 13.51 + assertEquals(result.get().toString(), expected); 13.52 + } 13.53 + 13.54 + static Integer count(String s) { 13.55 + return s.length(); 13.56 + } 13.57 + 13.58 + static int icount(String s) { 13.59 + return s.length(); 13.60 + } 13.61 + 13.62 + static void eye(Integer i) { 13.63 + setResult(String.format("I:%d", i)); 13.64 + } 13.65 + 13.66 + static void ieye(int i) { 13.67 + setResult(String.format("i:%d", i)); 13.68 + } 13.69 + 13.70 + static void deye(double d) { 13.71 + setResult(String.format("d:%f", d)); 13.72 + } 13.73 + 13.74 + public void testLambdas() { 13.75 + TBlock<Object> b = t -> {setResult("Sink0::" + t);}; 13.76 + b.apply("Howdy"); 13.77 + assertResult("Sink0::Howdy"); 13.78 + 13.79 + TBlock<String> b1 = t -> {setResult("Sink1::" + t);}; 13.80 + b1.apply("Rowdy"); 13.81 + assertResult("Sink1::Rowdy"); 13.82 + 13.83 + for (int i = 5; i < 10; ++i) { 13.84 + TBlock<Integer> b2 = t -> {setResult("Sink2::" + t);}; 13.85 + b2.apply(i); 13.86 + assertResult("Sink2::" + i); 13.87 + } 13.88 + 13.89 + TBlock<Integer> b3 = t -> {setResult("Sink3::" + t);}; 13.90 + for (int i = 900; i > 0; i -= 100) { 13.91 + b3.apply(i); 13.92 + assertResult("Sink3::" + i); 13.93 + } 13.94 + 13.95 + cntxt = "blah"; 13.96 + TBlock<String> b4 = t -> {setResult(String.format("b4: %s .. %s", cntxt, t));}; 13.97 + b4.apply("Yor"); 13.98 + assertResult("b4: blah .. Yor"); 13.99 + 13.100 + String flaw = "flaw"; 13.101 + TBlock<String> b5 = t -> {setResult(String.format("b5: %s .. %s", flaw, t));}; 13.102 + b5.apply("BB"); 13.103 + assertResult("b5: flaw .. BB"); 13.104 + 13.105 + cntxt = "flew"; 13.106 + TBlock<String> b6 = t -> {setResult(String.format("b6: %s .. %s .. %s", t, cntxt, flaw));}; 13.107 + b6.apply("flee"); 13.108 + assertResult("b6: flee .. flew .. flaw"); 13.109 + 13.110 + TBlock<String> b7 = t -> {setResult(String.format("b7: %s %s", t, this.protectedSuperclassMethod()));}; 13.111 + b7.apply("this:"); 13.112 + assertResult("b7: this: instance:flew"); 13.113 + 13.114 + TBlock<String> b8 = t -> {setResult(String.format("b8: %s %s", t, super.protectedSuperclassMethod()));}; 13.115 + b8.apply("super:"); 13.116 + assertResult("b8: super: I'm the sub"); 13.117 + 13.118 + TBlock<String> b7b = t -> {setResult(String.format("b9: %s %s", t, protectedSuperclassMethod()));}; 13.119 + b7b.apply("implicit this:"); 13.120 + assertResult("b9: implicit this: instance:flew"); 13.121 + 13.122 + TBlock<Object> b10 = t -> {setResult(String.format("b10: new LT1Thing: %s", (new LT1Thing(t)).str));}; 13.123 + b10.apply("thing"); 13.124 + assertResult("b10: new LT1Thing: thing"); 13.125 + 13.126 + TBlock<Object> b11 = t -> {setResult(String.format("b11: %s", (new LT1Thing(t) { 13.127 + String get() { 13.128 + return "*" + str.toString() + "*"; 13.129 + } 13.130 + }).get()));}; 13.131 + b11.apply(999); 13.132 + assertResult("b11: *999*"); 13.133 + } 13.134 + 13.135 + public void testMethodRefs() { 13.136 + LT1IA ia = LambdaTranslationTest1::eye; 13.137 + ia.doit(1234); 13.138 + assertResult("I:1234"); 13.139 + 13.140 + LT1IIA iia = LambdaTranslationTest1::ieye; 13.141 + iia.doit(1234); 13.142 + assertResult("i:1234"); 13.143 + 13.144 + LT1IA da = LambdaTranslationTest1::deye; 13.145 + da.doit(1234); 13.146 + assertResult("d:1234.000000"); 13.147 + 13.148 + LT1SA a = LambdaTranslationTest1::count; 13.149 + assertEquals((Integer) 5, a.doit("howdy")); 13.150 + 13.151 + a = LambdaTranslationTest1::icount; 13.152 + assertEquals((Integer) 6, a.doit("shower")); 13.153 + } 13.154 + 13.155 + public void testInner() throws Exception { 13.156 + (new In()).doInner(); 13.157 + } 13.158 + 13.159 + protected String protectedSuperclassMethod() { 13.160 + return "instance:" + cntxt; 13.161 + } 13.162 + 13.163 + private class In { 13.164 + 13.165 + private int that = 1234; 13.166 + 13.167 + void doInner() { 13.168 + TBlock<String> i4 = t -> {setResult(String.format("i4: %d .. %s", that, t));}; 13.169 + i4.apply("=1234"); 13.170 + assertResult("i4: 1234 .. =1234"); 13.171 + 13.172 + TBlock<String> i5 = t -> {setResult(""); appendResult(t); appendResult(t);}; 13.173 + i5.apply("fruit"); 13.174 + assertResult("fruitfruit"); 13.175 + 13.176 + cntxt = "human"; 13.177 + TBlock<String> b4 = t -> {setResult(String.format("b4: %s .. %s", cntxt, t));}; 13.178 + b4.apply("bin"); 13.179 + assertResult("b4: human .. bin"); 13.180 + 13.181 + final String flaw = "flaw"; 13.182 + 13.183 +/** 13.184 + Callable<String> c5 = () -> "["+flaw+"]" ; 13.185 + System.out.printf("c5: %s\n", c5.call() ); 13.186 + **/ 13.187 + 13.188 + TBlock<String> b5 = t -> {setResult(String.format("b5: %s .. %s", flaw, t));}; 13.189 + b5.apply("BB"); 13.190 + assertResult("b5: flaw .. BB"); 13.191 + 13.192 + cntxt = "borg"; 13.193 + TBlock<String> b6 = t -> {setResult(String.format("b6: %s .. %s .. %s", t, cntxt, flaw));}; 13.194 + b6.apply("flee"); 13.195 + assertResult("b6: flee .. borg .. flaw"); 13.196 + 13.197 + TBlock<String> b7b = t -> {setResult(String.format("b7b: %s %s", t, protectedSuperclassMethod()));}; 13.198 + b7b.apply("implicit outer this"); 13.199 + assertResult("b7b: implicit outer this instance:borg"); 13.200 + 13.201 + /** 13.202 + TBlock<Object> b9 = t -> { System.out.printf("New: %s\n", (new LT1Thing(t)).str); }; 13.203 + b9.apply("thing"); 13.204 + 13.205 + TBlock<Object> ba = t -> { System.out.printf("Def: %s\n", (new LT1Thing(t) { String get() { return "*" + str.toString() +"*";}}).get() ); }; 13.206 + ba.apply(999); 13.207 + 13.208 + */ 13.209 + } 13.210 + } 13.211 +} 13.212 + 13.213 +class LT1Sub { 13.214 + protected String protectedSuperclassMethod() { 13.215 + return "I'm the sub"; 13.216 + } 13.217 +} 13.218 + 13.219 +class LT1Thing { 13.220 + final Object str; 13.221 + 13.222 + LT1Thing(Object s) { 13.223 + str = s; 13.224 + } 13.225 +} 13.226 + 13.227 +interface LT1SA { 13.228 + Integer doit(String s); 13.229 +} 13.230 + 13.231 +interface LT1IA { 13.232 + void doit(int i); 13.233 +} 13.234 + 13.235 +interface LT1IIA { 13.236 + void doit(Integer i); 13.237 +}
14.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 14.2 +++ b/test/tools/javac/lambda/lambdaExecution/LambdaTranslationTest2.java Tue Nov 20 09:58:55 2012 -0800 14.3 @@ -0,0 +1,355 @@ 14.4 +/* 14.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 14.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 14.7 + * 14.8 + * This code is free software; you can redistribute it and/or modify it 14.9 + * under the terms of the GNU General Public License version 2 only, as 14.10 + * published by the Free Software Foundation. Oracle designates this 14.11 + * particular file as subject to the "Classpath" exception as provided 14.12 + * by Oracle in the LICENSE file that accompanied this code. 14.13 + * 14.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 14.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 14.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14.17 + * version 2 for more details (a copy is included in the LICENSE file that 14.18 + * accompanied this code). 14.19 + * 14.20 + * You should have received a copy of the GNU General Public License version 14.21 + * 2 along with this work; if not, write to the Free Software Foundation, 14.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 14.23 + * 14.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 14.25 + * or visit www.oracle.com if you need additional information or have any 14.26 + * questions. 14.27 + */ 14.28 + 14.29 +/** 14.30 + * @test 14.31 + * @bug 8003639 14.32 + * @summary convert lambda testng tests to jtreg and add them 14.33 + * @run testng LambdaTranslationTest2 14.34 + */ 14.35 + 14.36 +import org.testng.annotations.Test; 14.37 + 14.38 +import java.util.ArrayList; 14.39 +import java.util.List; 14.40 + 14.41 +import static org.testng.Assert.assertEquals; 14.42 +import static org.testng.Assert.assertTrue; 14.43 + 14.44 +/** 14.45 + * LambdaTranslationTest2 -- end-to-end smoke tests for lambda evaluation 14.46 + */ 14.47 + 14.48 +@Test 14.49 +public class LambdaTranslationTest2 { 14.50 + 14.51 + final String dummy = "dummy"; 14.52 + 14.53 + public void testLambdas() { 14.54 + TPredicate<String> isEmpty = s -> s.isEmpty(); 14.55 + assertTrue(isEmpty.test("")); 14.56 + assertTrue(!isEmpty.test("foo")); 14.57 + 14.58 + TPredicate<Object> oIsEmpty = s -> ((String) s).isEmpty(); 14.59 + assertTrue(oIsEmpty.test("")); 14.60 + assertTrue(!oIsEmpty.test("foo")); 14.61 + 14.62 + TPredicate<Object> alwaysTrue = o -> true; 14.63 + assertTrue(alwaysTrue.test("")); 14.64 + assertTrue(alwaysTrue.test(null)); 14.65 + 14.66 + TPredicate<Object> alwaysFalse = o -> false; 14.67 + assertTrue(!alwaysFalse.test("")); 14.68 + assertTrue(!alwaysFalse.test(null)); 14.69 + 14.70 + // tests local capture 14.71 + String foo = "foo"; 14.72 + TPredicate<String> equalsFoo = s -> s.equals(foo); 14.73 + assertTrue(!equalsFoo.test("")); 14.74 + assertTrue(equalsFoo.test("foo")); 14.75 + 14.76 + // tests instance capture 14.77 + TPredicate<String> equalsDummy = s -> s.equals(dummy); 14.78 + assertTrue(!equalsDummy.test("")); 14.79 + assertTrue(equalsDummy.test("dummy")); 14.80 + 14.81 + TMapper<Object, Object> ident = s -> s; 14.82 + 14.83 + assertEquals("blarf", ident.map("blarf")); 14.84 + assertEquals("wooga", ident.map("wooga")); 14.85 + assertTrue("wooga" == ident.map("wooga")); 14.86 + 14.87 + // constant capture 14.88 + TMapper<Object, Object> prefixer = s -> "p" + s; 14.89 + assertEquals("pblarf", prefixer.map("blarf")); 14.90 + assertEquals("pwooga", prefixer.map("wooga")); 14.91 + 14.92 + // instance capture 14.93 + TMapper<Object, Object> prefixer2 = s -> dummy + s; 14.94 + assertEquals("dummyblarf", prefixer2.map("blarf")); 14.95 + assertEquals("dummywooga", prefixer2.map("wooga")); 14.96 + } 14.97 + 14.98 + interface Factory<T> { 14.99 + T make(); 14.100 + } 14.101 + 14.102 + interface StringFactory extends Factory<String> { } 14.103 + 14.104 + interface StringFactory2 extends Factory<String> { 14.105 + String make(); 14.106 + } 14.107 + 14.108 + public void testBridges() { 14.109 + Factory<String> of = () -> "y"; 14.110 + Factory<?> ef = () -> "z"; 14.111 + 14.112 + assertEquals("y", of.make()); 14.113 + assertEquals("y", ((Factory<?>) of).make()); 14.114 + assertEquals("y", ((Factory) of).make()); 14.115 + 14.116 + assertEquals("z", ef.make()); 14.117 + assertEquals("z", ((Factory) ef).make()); 14.118 + } 14.119 + 14.120 + public void testBridgesImplicitSpecialization() { 14.121 + StringFactory sf = () -> "x"; 14.122 + 14.123 + assertEquals("x", sf.make()); 14.124 + assertEquals("x", ((Factory<String>) sf).make()); 14.125 + assertEquals("x", ((Factory<?>) sf).make()); 14.126 + assertEquals("x", ((Factory) sf).make()); 14.127 + } 14.128 + 14.129 + public void testBridgesExplicitSpecialization() { 14.130 + StringFactory2 sf = () -> "x"; 14.131 + 14.132 + assertEquals("x", sf.make()); 14.133 + assertEquals("x", ((Factory<String>) sf).make()); 14.134 + assertEquals("x", ((Factory<?>) sf).make()); 14.135 + assertEquals("x", ((Factory) sf).make()); 14.136 + } 14.137 + 14.138 + public void testSuperCapture() { 14.139 + class A { 14.140 + String make() { return "x"; } 14.141 + } 14.142 + 14.143 + class B extends A { 14.144 + void testSuperCapture() { 14.145 + StringFactory sf = () -> super.make(); 14.146 + assertEquals("x", sf.make()); 14.147 + } 14.148 + } 14.149 + 14.150 + new B().testSuperCapture(); 14.151 + } 14.152 + 14.153 + interface WidenD { 14.154 + public String m(float a0, double a1); 14.155 + } 14.156 + 14.157 + interface WidenS { 14.158 + public String m(byte a0, short a1); 14.159 + } 14.160 + 14.161 + interface WidenI { 14.162 + public String m(byte a0, short a1, char a2, int a3); 14.163 + } 14.164 + 14.165 + interface WidenL { 14.166 + public String m(byte a0, short a1, char a2, int a3, long a4); 14.167 + } 14.168 + 14.169 + interface Box { 14.170 + public String m(byte a0, short a1, char a2, int a3, long a4, boolean a5, float a6, double a7); 14.171 + } 14.172 + 14.173 + static String pb(Byte a0, Short a1, Character a2, Integer a3, Long a4, Boolean a5, Float a6, Double a7) { 14.174 + return String.format("b%d s%d c%c i%d j%d z%b f%f d%f", a0, a1, a2, a3, a4, a5, a6, a7); 14.175 + } 14.176 + 14.177 + static String pwI1(int a0, int a1, int a2, int a3) { 14.178 + return String.format("b%d s%d c%d i%d", a0, a1, a2, a3); 14.179 + } 14.180 + 14.181 + static String pwI2(Integer a0, Integer a1, Integer a2, Integer a3) { 14.182 + return String.format("b%d s%d c%d i%d", a0, a1, a2, a3); 14.183 + } 14.184 + 14.185 + static String pwL1(long a0, long a1, long a2, long a3, long a4) { 14.186 + return String.format("b%d s%d c%d i%d j%d", a0, a1, a2, a3, a4); 14.187 + } 14.188 + 14.189 + static String pwL2(Long a0, Long a1, Long a2, Long a3, Long a4) { 14.190 + return String.format("b%d s%d c%d i%d j%d", a0, a1, a2, a3, a4); 14.191 + } 14.192 + 14.193 + static String pwS1(short a0, short a1) { 14.194 + return String.format("b%d s%d", a0, a1); 14.195 + } 14.196 + 14.197 + static String pwS2(Short a0, Short a1) { 14.198 + return String.format("b%d s%d", a0, a1); 14.199 + } 14.200 + 14.201 + static String pwD1(double a0, double a1) { 14.202 + return String.format("f%f d%f", a0, a1); 14.203 + } 14.204 + 14.205 + static String pwD2(Double a0, Double a1) { 14.206 + return String.format("f%f d%f", a0, a1); 14.207 + } 14.208 + 14.209 + public void testPrimitiveWidening() { 14.210 + WidenS ws1 = LambdaTranslationTest2::pwS1; 14.211 + assertEquals("b1 s2", ws1.m((byte) 1, (short) 2)); 14.212 + 14.213 + WidenD wd1 = LambdaTranslationTest2::pwD1; 14.214 + assertEquals("f1.000000 d2.000000", wd1.m(1.0f, 2.0)); 14.215 + 14.216 + WidenI wi1 = LambdaTranslationTest2::pwI1; 14.217 + assertEquals("b1 s2 c3 i4", wi1.m((byte) 1, (short) 2, (char) 3, 4)); 14.218 + 14.219 + WidenL wl1 = LambdaTranslationTest2::pwL1; 14.220 + assertEquals("b1 s2 c3 i4 j5", wl1.m((byte) 1, (short) 2, (char) 3, 4, 5L)); 14.221 + 14.222 + // @@@ TODO: clarify spec on widen+box conversion 14.223 + } 14.224 + 14.225 + interface Unbox { 14.226 + public String m(Byte a0, Short a1, Character a2, Integer a3, Long a4, Boolean a5, Float a6, Double a7); 14.227 + } 14.228 + 14.229 + static String pu(byte a0, short a1, char a2, int a3, long a4, boolean a5, float a6, double a7) { 14.230 + return String.format("b%d s%d c%c i%d j%d z%b f%f d%f", a0, a1, a2, a3, a4, a5, a6, a7); 14.231 + } 14.232 + 14.233 + public void testUnboxing() { 14.234 + Unbox u = LambdaTranslationTest2::pu; 14.235 + assertEquals("b1 s2 cA i4 j5 ztrue f6.000000 d7.000000", u.m((byte)1, (short) 2, 'A', 4, 5L, true, 6.0f, 7.0)); 14.236 + } 14.237 + 14.238 + public void testBoxing() { 14.239 + Box b = LambdaTranslationTest2::pb; 14.240 + assertEquals("b1 s2 cA i4 j5 ztrue f6.000000 d7.000000", b.m((byte) 1, (short) 2, 'A', 4, 5L, true, 6.0f, 7.0)); 14.241 + } 14.242 + 14.243 + static boolean cc(Object o) { 14.244 + return ((String) o).equals("foo"); 14.245 + } 14.246 + 14.247 + public void testArgCastingAdaptation() { 14.248 + TPredicate<String> p = LambdaTranslationTest2::cc; 14.249 + assertTrue(p.test("foo")); 14.250 + assertTrue(!p.test("bar")); 14.251 + } 14.252 + 14.253 + interface SonOfPredicate<T> extends TPredicate<T> { } 14.254 + 14.255 + public void testExtendsSAM() { 14.256 + SonOfPredicate<String> p = s -> s.isEmpty(); 14.257 + assertTrue(p.test("")); 14.258 + assertTrue(!p.test("foo")); 14.259 + } 14.260 + 14.261 + public void testConstructorRef() { 14.262 + Factory<List<String>> lf = ArrayList<String>::new; 14.263 + List<String> list = lf.make(); 14.264 + assertTrue(list instanceof ArrayList); 14.265 + assertTrue(list != lf.make()); 14.266 + list.add("a"); 14.267 + assertEquals("[a]", list.toString()); 14.268 + } 14.269 + 14.270 + private static String privateMethod() { 14.271 + return "private"; 14.272 + } 14.273 + 14.274 + public void testPrivateMethodRef() { 14.275 + Factory<String> sf = LambdaTranslationTest2::privateMethod; 14.276 + assertEquals("private", sf.make()); 14.277 + } 14.278 + 14.279 + private interface PrivateIntf { 14.280 + String make(); 14.281 + } 14.282 + 14.283 + public void testPrivateIntf() { 14.284 + PrivateIntf p = () -> "foo"; 14.285 + assertEquals("foo", p.make()); 14.286 + } 14.287 + 14.288 + interface Op<T> { 14.289 + public T op(T a, T b); 14.290 + } 14.291 + 14.292 + public void testBoxToObject() { 14.293 + Op<Integer> maxer = Math::max; 14.294 + for (int i=-100000; i < 100000; i += 100) 14.295 + for (int j=-100000; j < 100000; j += 99) { 14.296 + assertEquals((int) maxer.op(i,j), Math.max(i,j)); 14.297 + } 14.298 + } 14.299 + 14.300 + protected static String protectedMethod() { 14.301 + return "protected"; 14.302 + } 14.303 + 14.304 + public void testProtectedMethodRef() { 14.305 + Factory<String> sf = LambdaTranslationTest2::protectedMethod; 14.306 + assertEquals("protected", sf.make()); 14.307 + } 14.308 + 14.309 + class Inner1 { 14.310 + String m1() { 14.311 + return "Inner1.m1()"; 14.312 + } 14.313 + 14.314 + class Inner2 { 14.315 + public String m1() { 14.316 + return "Inner1.Inner2.m1()"; 14.317 + } 14.318 + 14.319 + protected String m2() { 14.320 + return "Inner1.Inner2.m2()"; 14.321 + } 14.322 + 14.323 + String m3() { 14.324 + return "Inner1.Inner2.m3()"; 14.325 + } 14.326 + 14.327 + class Inner3<T> { 14.328 + T t = null; 14.329 + Inner3(T t) { 14.330 + this.t = t; 14.331 + } 14.332 + T m1() { 14.333 + return t; 14.334 + } 14.335 + } 14.336 + } 14.337 + } 14.338 + 14.339 + public void testInnerClassMethodRef() { 14.340 + Factory<String> fs = new Inner1()::m1; 14.341 + assertEquals("Inner1.m1()", fs.make()); 14.342 + 14.343 + fs = new Inner1().new Inner2()::m1; 14.344 + assertEquals("Inner1.Inner2.m1()", fs.make()); 14.345 + 14.346 + fs = new Inner1().new Inner2()::m2; 14.347 + assertEquals("Inner1.Inner2.m2()", fs.make()); 14.348 + 14.349 + fs = new Inner1().new Inner2()::m3; 14.350 + assertEquals("Inner1.Inner2.m3()", fs.make()); 14.351 + 14.352 + fs = new Inner1().new Inner2().new Inner3<String>("Inner1.Inner2.Inner3")::m1; 14.353 + assertEquals("Inner1.Inner2.Inner3", fs.make()); 14.354 + 14.355 + Factory<Integer> fsi = new Inner1().new Inner2().new Inner3<Integer>(100)::m1; 14.356 + assertEquals(100, (int)fsi.make()); 14.357 + } 14.358 +}
15.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 15.2 +++ b/test/tools/javac/lambda/lambdaExecution/TBlock.java Tue Nov 20 09:58:55 2012 -0800 15.3 @@ -0,0 +1,36 @@ 15.4 +/** 15.5 + * Performs operations upon an input object which may modify that object and/or 15.6 + * external state (other objects). 15.7 + * 15.8 + * <p>All block implementations are expected to: 15.9 + * <ul> 15.10 + * <li>When used for aggregate operations upon many elements blocks 15.11 + * should not assume that the {@code apply} operation will be called upon 15.12 + * elements in any specific order.</li> 15.13 + * </ul> 15.14 + * 15.15 + * @param <T> The type of input objects to {@code apply}. 15.16 + */ 15.17 +public interface TBlock<T> { 15.18 + 15.19 + /** 15.20 + * Performs operations upon the provided object which may modify that object 15.21 + * and/or external state. 15.22 + * 15.23 + * @param t an input object 15.24 + */ 15.25 + void apply(T t); 15.26 + 15.27 + /** 15.28 + * Returns a Block which performs in sequence the {@code apply} methods of 15.29 + * multiple Blocks. This Block's {@code apply} method is performed followed 15.30 + * by the {@code apply} method of the specified Block operation. 15.31 + * 15.32 + * @param other an additional Block which will be chained after this Block 15.33 + * @return a Block which performs in sequence the {@code apply} method of 15.34 + * this Block and the {@code apply} method of the specified Block operation 15.35 + */ 15.36 + public default TBlock<T> chain(TBlock<? super T> other) { 15.37 + return (T t) -> { apply(t); other.apply(t); }; 15.38 + } 15.39 +}
16.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 16.2 +++ b/test/tools/javac/lambda/lambdaExecution/TMapper.java Tue Nov 20 09:58:55 2012 -0800 16.3 @@ -0,0 +1,68 @@ 16.4 +/* 16.5 + * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved. 16.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 16.7 + * 16.8 + * This code is free software; you can redistribute it and/or modify it 16.9 + * under the terms of the GNU General Public License version 2 only, as 16.10 + * published by the Free Software Foundation. Oracle designates this 16.11 + * particular file as subject to the "Classpath" exception as provided 16.12 + * by Oracle in the LICENSE file that accompanied this code. 16.13 + * 16.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 16.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 16.17 + * version 2 for more details (a copy is included in the LICENSE file that 16.18 + * accompanied this code). 16.19 + * 16.20 + * You should have received a copy of the GNU General Public License version 16.21 + * 2 along with this work; if not, write to the Free Software Foundation, 16.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 16.23 + * 16.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 16.25 + * or visit www.oracle.com if you need additional information or have any 16.26 + * questions. 16.27 + */ 16.28 + 16.29 +/** 16.30 + * Given an input object maps to an appropriate output object. A mapper may 16.31 + * variously provide a mapping between types, object instances or keys and 16.32 + * values or any other form of transformation upon the input. 16.33 + * 16.34 + * <p/>All mapper implementations are expected to: 16.35 + * <ul> 16.36 + * <li>Provide stable results such that for any {@code t} the result of two 16.37 + * {@code map} operations are always equivalent. ie.<pre> 16.38 + * Foo one = mapper.map(a); 16.39 + * Foo two = mapper.map(a); 16.40 + * 16.41 + * assert one.equals(two) && two.equals(one); 16.42 + * </pre></li> 16.43 + * <li>Equivalent input objects should map to equivalent output objects. ie.<pre> 16.44 + * assert a.equals(b); // a and b are equivalent 16.45 + * 16.46 + * Foo x = mapper.map(a); 16.47 + * Foo y = mapper.map(b); 16.48 + * 16.49 + * assert x.equals(y); // their mapped results should be as equivalent. 16.50 + * </pre></li> 16.51 + * <li>The mapper should not modify the input object in any way that would 16.52 + * change the mapping.</li> 16.53 + * <li>When used for aggregate operations upon many elements mappers 16.54 + * should not assume that the {@code map} operation will be called upon elements 16.55 + * in any specific order.</li> 16.56 + * </ul> 16.57 + * 16.58 + * @param <R> the type of output objects from {@code map} operation. May be the 16.59 + * @param <T> the type of input objects provided to the {@code map} operation. 16.60 + * same type as {@code <T>}. 16.61 + */ 16.62 +public interface TMapper<R, T> { 16.63 + 16.64 + /** 16.65 + * Map the provided input object to an appropriate output object. 16.66 + * 16.67 + * @param t the input object to be mapped. 16.68 + * @return the mapped output object. 16.69 + */ 16.70 + R map(T t); 16.71 +}
17.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 17.2 +++ b/test/tools/javac/lambda/lambdaExecution/TPredicate.java Tue Nov 20 09:58:55 2012 -0800 17.3 @@ -0,0 +1,64 @@ 17.4 +/* 17.5 + * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved. 17.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 17.7 + * 17.8 + * This code is free software; you can redistribute it and/or modify it 17.9 + * under the terms of the GNU General Public License version 2 only, as 17.10 + * published by the Free Software Foundation. Oracle designates this 17.11 + * particular file as subject to the "Classpath" exception as provided 17.12 + * by Oracle in the LICENSE file that accompanied this code. 17.13 + * 17.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 17.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 17.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 17.17 + * version 2 for more details (a copy is included in the LICENSE file that 17.18 + * accompanied this code). 17.19 + * 17.20 + * You should have received a copy of the GNU General Public License version 17.21 + * 2 along with this work; if not, write to the Free Software Foundation, 17.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 17.23 + * 17.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 17.25 + * or visit www.oracle.com if you need additional information or have any 17.26 + * questions. 17.27 + */ 17.28 + 17.29 +/** 17.30 + * Determines if the input object matches some criteria. 17.31 + * 17.32 + * <p>All predicate implementations are expected to: 17.33 + * <ul> 17.34 + * <li>Provide stable results such that for any {@code t} the result of two 17.35 + * {@code eval} operations are always equivalent. ie.<pre> 17.36 + * boolean one = predicate.test(a); 17.37 + * boolean two = predicate.test(a); 17.38 + * 17.39 + * assert one == two; 17.40 + * </pre></li> 17.41 + * <li>Equivalent input objects should map to equivalent output objects. ie.<pre> 17.42 + * assert a.equals(b); // a and b are equivalent 17.43 + * 17.44 + * boolean x = predicate.test(a); 17.45 + * boolean y = predicate.test(ab; 17.46 + * 17.47 + * assert x == y; // their test results should be the same. 17.48 + * </pre></li> 17.49 + * <li>The predicate should not modify the input object in any way that would 17.50 + * change the evaluation.</li> 17.51 + * <li>When used for aggregate operations upon many elements predicates 17.52 + * should not assume that the {@code test} operation will be called upon 17.53 + * elements in any specific order.</li> 17.54 + * </ul> 17.55 + * 17.56 + * @param <T> the type of input objects provided to {@code test}. 17.57 + */ 17.58 +public interface TPredicate<T> { 17.59 + 17.60 + /** 17.61 + * Return {@code true} if the input object matches some criteria. 17.62 + * 17.63 + * @param t the input object. 17.64 + * @return {@code true} if the input object matched some criteria. 17.65 + */ 17.66 + boolean test(T t); 17.67 +}
18.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 18.2 +++ b/test/tools/javac/lambda/methodReferenceExecution/MethodReferenceTestFDCCE.java Tue Nov 20 09:58:55 2012 -0800 18.3 @@ -0,0 +1,154 @@ 18.4 +/* 18.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 18.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 18.7 + * 18.8 + * This code is free software; you can redistribute it and/or modify it 18.9 + * under the terms of the GNU General Public License version 2 only, as 18.10 + * published by the Free Software Foundation. Oracle designates this 18.11 + * particular file as subject to the "Classpath" exception as provided 18.12 + * by Oracle in the LICENSE file that accompanied this code. 18.13 + * 18.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 18.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 18.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 18.17 + * version 2 for more details (a copy is included in the LICENSE file that 18.18 + * accompanied this code). 18.19 + * 18.20 + * You should have received a copy of the GNU General Public License version 18.21 + * 2 along with this work; if not, write to the Free Software Foundation, 18.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18.23 + * 18.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 18.25 + * or visit www.oracle.com if you need additional information or have any 18.26 + * questions. 18.27 + */ 18.28 + 18.29 +/** 18.30 + * @test 18.31 + * @bug 8003639 18.32 + * @summary convert lambda testng tests to jtreg and add them 18.33 + * @run testng MethodReferenceTestFDCCE 18.34 + */ 18.35 + 18.36 +import org.testng.annotations.Test; 18.37 +import java.lang.reflect.Array; 18.38 + 18.39 +import static org.testng.Assert.assertEquals; 18.40 +import static org.testng.Assert.assertTrue; 18.41 +import static org.testng.Assert.fail; 18.42 + 18.43 +/** 18.44 + * Method references and raw types. 18.45 + * @author Robert Field 18.46 + */ 18.47 + 18.48 +@Test 18.49 +@SuppressWarnings({"rawtypes", "unchecked"}) 18.50 +public class MethodReferenceTestFDCCE { 18.51 + 18.52 + static void assertCCE(Throwable t) { 18.53 + assertEquals(t.getClass().getName(), "java.lang.ClassCastException"); 18.54 + } 18.55 + 18.56 + interface Pred<T> { boolean accept(T x); } 18.57 + 18.58 + interface Ps { boolean accept(short x); } 18.59 + 18.60 + interface Oo { Object too(int x); } 18.61 + 18.62 + interface Reto<T> { T m(); } 18.63 + 18.64 + class A {} 18.65 + class B extends A {} 18.66 + 18.67 + static boolean isMinor(int x) { 18.68 + return x < 18; 18.69 + } 18.70 + 18.71 + static boolean tst(A x) { 18.72 + return true; 18.73 + } 18.74 + 18.75 + static Object otst(Object x) { 18.76 + return x; 18.77 + } 18.78 + 18.79 + static boolean stst(Short x) { 18.80 + return x < 18; 18.81 + } 18.82 + 18.83 + static short ritst() { 18.84 + return 123; 18.85 + } 18.86 + 18.87 + public void testMethodReferenceFDPrim1() { 18.88 + Pred<Byte> p = MethodReferenceTestFDCCE::isMinor; 18.89 + Pred p2 = p; 18.90 + assertTrue(p2.accept((Byte)(byte)15)); 18.91 + } 18.92 + 18.93 + public void testMethodReferenceFDPrim2() { 18.94 + Pred<Byte> p = MethodReferenceTestFDCCE::isMinor; 18.95 + Pred p2 = p; 18.96 + assertTrue(p2.accept((byte)15)); 18.97 + } 18.98 + 18.99 + public void testMethodReferenceFDPrimICCE() { 18.100 + Pred<Byte> p = MethodReferenceTestFDCCE::isMinor; 18.101 + Pred p2 = p; 18.102 + try { 18.103 + p2.accept(15); // should throw CCE 18.104 + fail("Exception should have been thrown"); 18.105 + } catch (Throwable t) { 18.106 + assertCCE(t); 18.107 + } 18.108 + } 18.109 + 18.110 + public void testMethodReferenceFDPrimOCCE() { 18.111 + Pred<Byte> p = MethodReferenceTestFDCCE::isMinor; 18.112 + Pred p2 = p; 18.113 + try { 18.114 + p2.accept(new Object()); // should throw CCE 18.115 + fail("Exception should have been thrown"); 18.116 + } catch (Throwable t) { 18.117 + assertCCE(t); 18.118 + } 18.119 + } 18.120 + 18.121 + public void testMethodReferenceFDRef() { 18.122 + Pred<B> p = MethodReferenceTestFDCCE::tst; 18.123 + Pred p2 = p; 18.124 + assertTrue(p2.accept(new B())); 18.125 + } 18.126 + 18.127 + public void testMethodReferenceFDRefCCE() { 18.128 + Pred<B> p = MethodReferenceTestFDCCE::tst; 18.129 + Pred p2 = p; 18.130 + try { 18.131 + p2.accept(new A()); // should throw CCE 18.132 + fail("Exception should have been thrown"); 18.133 + } catch (Throwable t) { 18.134 + assertCCE(t); 18.135 + } 18.136 + } 18.137 + 18.138 + public void testMethodReferenceFDPrimPrim() { 18.139 + Ps p = MethodReferenceTestFDCCE::isMinor; 18.140 + assertTrue(p.accept((byte)15)); 18.141 + } 18.142 + 18.143 + public void testMethodReferenceFDPrimBoxed() { 18.144 + Ps p = MethodReferenceTestFDCCE::stst; 18.145 + assertTrue(p.accept((byte)15)); 18.146 + } 18.147 + 18.148 + public void testMethodReferenceFDPrimRef() { 18.149 + Oo p = MethodReferenceTestFDCCE::otst; 18.150 + assertEquals(p.too(15).getClass().getName(), "java.lang.Integer"); 18.151 + } 18.152 + 18.153 + public void testMethodReferenceFDRet1() { 18.154 + Reto<Short> p = MethodReferenceTestFDCCE::ritst; 18.155 + assertEquals(p.m(), (Short)(short)123); 18.156 + } 18.157 +}
19.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 19.2 +++ b/test/tools/javac/lambda/methodReferenceExecution/MethodReferenceTestInnerDefault.java Tue Nov 20 09:58:55 2012 -0800 19.3 @@ -0,0 +1,88 @@ 19.4 +/* 19.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 19.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 19.7 + * 19.8 + * This code is free software; you can redistribute it and/or modify it 19.9 + * under the terms of the GNU General Public License version 2 only, as 19.10 + * published by the Free Software Foundation. Oracle designates this 19.11 + * particular file as subject to the "Classpath" exception as provided 19.12 + * by Oracle in the LICENSE file that accompanied this code. 19.13 + * 19.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 19.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 19.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 19.17 + * version 2 for more details (a copy is included in the LICENSE file that 19.18 + * accompanied this code). 19.19 + * 19.20 + * You should have received a copy of the GNU General Public License version 19.21 + * 2 along with this work; if not, write to the Free Software Foundation, 19.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 19.23 + * 19.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 19.25 + * or visit www.oracle.com if you need additional information or have any 19.26 + * questions. 19.27 + */ 19.28 + 19.29 +/** 19.30 + * @test 19.31 + * @bug 8003639 19.32 + * @summary convert lambda testng tests to jtreg and add them 19.33 + * @run testng MethodReferenceTestInnerDefault 19.34 + */ 19.35 + 19.36 +import org.testng.annotations.Test; 19.37 + 19.38 +import static org.testng.Assert.assertEquals; 19.39 + 19.40 +/** 19.41 + * @author Robert Field 19.42 + */ 19.43 + 19.44 +interface IDSs { String m(String a); } 19.45 + 19.46 +interface InDefA { 19.47 + default String xsA__(String s) { 19.48 + return "A__xsA:" + s; 19.49 + } 19.50 + 19.51 + default String xsAB_(String s) { 19.52 + return "AB_xsA:" + s; 19.53 + } 19.54 + 19.55 +} 19.56 + 19.57 +interface InDefB extends InDefA { 19.58 + 19.59 + default String xsAB_(String s) { 19.60 + return "AB_xsB:" + s; 19.61 + } 19.62 + 19.63 + default String xs_B_(String s) { 19.64 + return "_B_xsB:" + s; 19.65 + } 19.66 +} 19.67 + 19.68 +@Test 19.69 +public class MethodReferenceTestInnerDefault implements InDefB { 19.70 + 19.71 + public void testMethodReferenceInnerDefault() { 19.72 + (new In()).testMethodReferenceInnerDefault(); 19.73 + } 19.74 + 19.75 + class In { 19.76 + 19.77 + public void testMethodReferenceInnerDefault() { 19.78 + IDSs q; 19.79 + 19.80 + q = MethodReferenceTestInnerDefault.this::xsA__; 19.81 + assertEquals(q.m("*"), "A__xsA:*"); 19.82 + 19.83 + q = MethodReferenceTestInnerDefault.this::xsAB_; 19.84 + assertEquals(q.m("*"), "AB_xsB:*"); 19.85 + 19.86 + q = MethodReferenceTestInnerDefault.this::xs_B_; 19.87 + assertEquals(q.m("*"), "_B_xsB:*"); 19.88 + } 19.89 + } 19.90 + 19.91 +}
20.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 20.2 +++ b/test/tools/javac/lambda/methodReferenceExecution/MethodReferenceTestInnerInstance.java Tue Nov 20 09:58:55 2012 -0800 20.3 @@ -0,0 +1,95 @@ 20.4 +/* 20.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 20.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 20.7 + * 20.8 + * This code is free software; you can redistribute it and/or modify it 20.9 + * under the terms of the GNU General Public License version 2 only, as 20.10 + * published by the Free Software Foundation. Oracle designates this 20.11 + * particular file as subject to the "Classpath" exception as provided 20.12 + * by Oracle in the LICENSE file that accompanied this code. 20.13 + * 20.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 20.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 20.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 20.17 + * version 2 for more details (a copy is included in the LICENSE file that 20.18 + * accompanied this code). 20.19 + * 20.20 + * You should have received a copy of the GNU General Public License version 20.21 + * 2 along with this work; if not, write to the Free Software Foundation, 20.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20.23 + * 20.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20.25 + * or visit www.oracle.com if you need additional information or have any 20.26 + * questions. 20.27 + */ 20.28 + 20.29 +/** 20.30 + * @test 20.31 + * @bug 8003639 20.32 + * @summary convert lambda testng tests to jtreg and add them 20.33 + * @run testng MethodReferenceTestInnerInstance 20.34 + */ 20.35 + 20.36 +import org.testng.annotations.Test; 20.37 + 20.38 +import static org.testng.Assert.assertEquals; 20.39 + 20.40 +/** 20.41 + * @author Robert Field 20.42 + */ 20.43 + 20.44 +@Test 20.45 +public class MethodReferenceTestInnerInstance { 20.46 + 20.47 + public void testMethodReferenceInnerInstance() { 20.48 + cia().cib().testMethodReferenceInstance(); 20.49 + } 20.50 + 20.51 + public void testMethodReferenceInnerExternal() { 20.52 + cia().cib().testMethodReferenceExternal(); 20.53 + } 20.54 + 20.55 + interface SI { 20.56 + String m(Integer a); 20.57 + } 20.58 + 20.59 + class CIA { 20.60 + 20.61 + String xI(Integer i) { 20.62 + return "xI:" + i; 20.63 + } 20.64 + 20.65 + public class CIB { 20.66 + 20.67 + public void testMethodReferenceInstance() { 20.68 + SI q; 20.69 + 20.70 + q = CIA.this::xI; 20.71 + assertEquals(q.m(55), "xI:55"); 20.72 + } 20.73 + 20.74 + public void testMethodReferenceExternal() { 20.75 + SI q; 20.76 + 20.77 + q = (new E())::xI; 20.78 + assertEquals(q.m(77), "ExI:77"); 20.79 + } 20.80 + } 20.81 + 20.82 + CIB cib() { 20.83 + return new CIB(); 20.84 + } 20.85 + 20.86 + class E { 20.87 + 20.88 + String xI(Integer i) { 20.89 + return "ExI:" + i; 20.90 + } 20.91 + } 20.92 + 20.93 + } 20.94 + 20.95 + CIA cia() { 20.96 + return new CIA(); 20.97 + } 20.98 +}
21.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 21.2 +++ b/test/tools/javac/lambda/methodReferenceExecution/MethodReferenceTestInnerVarArgsThis.java Tue Nov 20 09:58:55 2012 -0800 21.3 @@ -0,0 +1,250 @@ 21.4 +/* 21.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 21.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 21.7 + * 21.8 + * This code is free software; you can redistribute it and/or modify it 21.9 + * under the terms of the GNU General Public License version 2 only, as 21.10 + * published by the Free Software Foundation. Oracle designates this 21.11 + * particular file as subject to the "Classpath" exception as provided 21.12 + * by Oracle in the LICENSE file that accompanied this code. 21.13 + * 21.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 21.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 21.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 21.17 + * version 2 for more details (a copy is included in the LICENSE file that 21.18 + * accompanied this code). 21.19 + * 21.20 + * You should have received a copy of the GNU General Public License version 21.21 + * 2 along with this work; if not, write to the Free Software Foundation, 21.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 21.23 + * 21.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 21.25 + * or visit www.oracle.com if you need additional information or have any 21.26 + * questions. 21.27 + */ 21.28 + 21.29 +/** 21.30 + * @test 21.31 + * @bug 8003639 21.32 + * @summary convert lambda testng tests to jtreg and add them 21.33 + * @run testng MethodReferenceTestInnerVarArgsThis 21.34 + */ 21.35 + 21.36 +import org.testng.annotations.Test; 21.37 +import java.lang.reflect.Array; 21.38 + 21.39 +import static org.testng.Assert.assertEquals; 21.40 + 21.41 +/** 21.42 + * @author Robert Field 21.43 + */ 21.44 + 21.45 +@Test 21.46 +public class MethodReferenceTestInnerVarArgsThis { 21.47 + 21.48 + interface NsII { 21.49 + 21.50 + String m(Integer a, Integer b); 21.51 + } 21.52 + 21.53 + interface Nsiii { 21.54 + 21.55 + String m(int a, int b, int c); 21.56 + } 21.57 + 21.58 + interface Nsi { 21.59 + 21.60 + String m(int a); 21.61 + } 21.62 + 21.63 + interface NsaO { 21.64 + 21.65 + String m(Object[] a); 21.66 + } 21.67 + 21.68 + interface Nsai { 21.69 + 21.70 + String m(int[] a); 21.71 + } 21.72 + 21.73 + interface Nsvi { 21.74 + 21.75 + String m(int... va); 21.76 + } 21.77 + 21.78 + class CIA { 21.79 + 21.80 + String xvI(Integer... vi) { 21.81 + StringBuilder sb = new StringBuilder("xvI:"); 21.82 + for (Integer i : vi) { 21.83 + sb.append(i); 21.84 + sb.append("-"); 21.85 + } 21.86 + return sb.toString(); 21.87 + } 21.88 + 21.89 + String xIvI(Integer f, Integer... vi) { 21.90 + StringBuilder sb = new StringBuilder("xIvI:"); 21.91 + sb.append(f); 21.92 + for (Integer i : vi) { 21.93 + sb.append(i); 21.94 + sb.append("-"); 21.95 + } 21.96 + return sb.toString(); 21.97 + } 21.98 + 21.99 + String xvi(int... vi) { 21.100 + int sum = 0; 21.101 + for (int i : vi) { 21.102 + sum += i; 21.103 + } 21.104 + return "xvi:" + sum; 21.105 + } 21.106 + 21.107 + String xIvi(Integer f, int... vi) { 21.108 + int sum = 0; 21.109 + for (int i : vi) { 21.110 + sum += i; 21.111 + } 21.112 + return "xIvi:(" + f + ")" + sum; 21.113 + } 21.114 + 21.115 + String xvO(Object... vi) { 21.116 + StringBuilder sb = new StringBuilder("xvO:"); 21.117 + for (Object i : vi) { 21.118 + if (i.getClass().isArray()) { 21.119 + sb.append("["); 21.120 + int len = Array.getLength(i); 21.121 + for (int x = 0; x < len; ++x) { 21.122 + sb.append(Array.get(i, x)); 21.123 + sb.append(","); 21.124 + } 21.125 + sb.append("]"); 21.126 + 21.127 + } else { 21.128 + sb.append(i); 21.129 + } 21.130 + sb.append("*"); 21.131 + } 21.132 + return sb.toString(); 21.133 + } 21.134 + 21.135 + public class CIB { 21.136 + 21.137 + // These should be processed as var args 21.138 + public void testVarArgsNsSuperclass() { 21.139 + NsII q; 21.140 + 21.141 + q = CIA.this::xvO; 21.142 + assertEquals(q.m(55, 66), "xvO:55*66*"); 21.143 + } 21.144 + 21.145 + public void testVarArgsNsArray() { 21.146 + Nsai q; 21.147 + 21.148 + q = CIA.this::xvO; 21.149 + assertEquals(q.m(new int[]{55, 66}), "xvO:[55,66,]*"); 21.150 + } 21.151 + 21.152 + public void testVarArgsNsII() { 21.153 + NsII q; 21.154 + 21.155 + q = CIA.this::xvI; 21.156 + assertEquals(q.m(33, 7), "xvI:33-7-"); 21.157 + 21.158 + q = CIA.this::xIvI; 21.159 + assertEquals(q.m(50, 40), "xIvI:5040-"); 21.160 + 21.161 + q = CIA.this::xvi; 21.162 + assertEquals(q.m(100, 23), "xvi:123"); 21.163 + 21.164 + q = CIA.this::xIvi; 21.165 + assertEquals(q.m(9, 21), "xIvi:(9)21"); 21.166 + } 21.167 + 21.168 + public void testVarArgsNsiii() { 21.169 + Nsiii q; 21.170 + 21.171 + q = CIA.this::xvI; 21.172 + assertEquals(q.m(3, 2, 1), "xvI:3-2-1-"); 21.173 + 21.174 + q = CIA.this::xIvI; 21.175 + assertEquals(q.m(888, 99, 2), "xIvI:88899-2-"); 21.176 + 21.177 + q = CIA.this::xvi; 21.178 + assertEquals(q.m(900, 80, 7), "xvi:987"); 21.179 + 21.180 + q = CIA.this::xIvi; 21.181 + assertEquals(q.m(333, 27, 72), "xIvi:(333)99"); 21.182 + } 21.183 + 21.184 + public void testVarArgsNsi() { 21.185 + Nsi q; 21.186 + 21.187 + q = CIA.this::xvI; 21.188 + assertEquals(q.m(3), "xvI:3-"); 21.189 + 21.190 + q = CIA.this::xIvI; 21.191 + assertEquals(q.m(888), "xIvI:888"); 21.192 + 21.193 + q = CIA.this::xvi; 21.194 + assertEquals(q.m(900), "xvi:900"); 21.195 + 21.196 + q = CIA.this::xIvi; 21.197 + assertEquals(q.m(333), "xIvi:(333)0"); 21.198 + } 21.199 + 21.200 + // These should NOT be processed as var args 21.201 + public void testVarArgsNsaO() { 21.202 + NsaO q; 21.203 + 21.204 + q = CIA.this::xvO; 21.205 + assertEquals(q.m(new String[]{"yo", "there", "dude"}), "xvO:yo*there*dude*"); 21.206 + } 21.207 + } 21.208 + 21.209 + CIB cib() { 21.210 + return new CIB(); 21.211 + } 21.212 + 21.213 + class E { 21.214 + 21.215 + String xI(Integer i) { 21.216 + return "ExI:" + i; 21.217 + } 21.218 + } 21.219 + } 21.220 + 21.221 + CIA cia() { 21.222 + return new CIA(); 21.223 + } 21.224 + 21.225 + // These should be processed as var args 21.226 + public void testVarArgsNsSuperclass() { 21.227 + cia().cib().testVarArgsNsSuperclass(); 21.228 + } 21.229 + 21.230 + public void testVarArgsNsArray() { 21.231 + cia().cib().testVarArgsNsArray(); 21.232 + } 21.233 + 21.234 + public void testVarArgsNsII() { 21.235 + cia().cib().testVarArgsNsII(); 21.236 + } 21.237 + 21.238 + public void testVarArgsNsiii() { 21.239 + cia().cib().testVarArgsNsiii(); 21.240 + } 21.241 + 21.242 + public void testVarArgsNsi() { 21.243 + cia().cib().testVarArgsNsi(); 21.244 + } 21.245 + 21.246 + // These should NOT be processed as var args 21.247 + 21.248 + public void testVarArgsNsaO() { 21.249 + cia().cib().testVarArgsNsaO(); 21.250 + } 21.251 + 21.252 + 21.253 +}
22.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 22.2 +++ b/test/tools/javac/lambda/methodReferenceExecution/MethodReferenceTestInstance.java Tue Nov 20 09:58:55 2012 -0800 22.3 @@ -0,0 +1,70 @@ 22.4 +/* 22.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 22.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 22.7 + * 22.8 + * This code is free software; you can redistribute it and/or modify it 22.9 + * under the terms of the GNU General Public License version 2 only, as 22.10 + * published by the Free Software Foundation. Oracle designates this 22.11 + * particular file as subject to the "Classpath" exception as provided 22.12 + * by Oracle in the LICENSE file that accompanied this code. 22.13 + * 22.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 22.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 22.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 22.17 + * version 2 for more details (a copy is included in the LICENSE file that 22.18 + * accompanied this code). 22.19 + * 22.20 + * You should have received a copy of the GNU General Public License version 22.21 + * 2 along with this work; if not, write to the Free Software Foundation, 22.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 22.23 + * 22.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22.25 + * or visit www.oracle.com if you need additional information or have any 22.26 + * questions. 22.27 + */ 22.28 + 22.29 +/** 22.30 + * @test 22.31 + * @bug 8003639 22.32 + * @summary convert lambda testng tests to jtreg and add them 22.33 + * @run testng MethodReferenceTestInstance 22.34 + */ 22.35 + 22.36 +import org.testng.annotations.Test; 22.37 + 22.38 +import static org.testng.Assert.assertEquals; 22.39 + 22.40 +/** 22.41 + * @author Robert Field 22.42 + */ 22.43 + 22.44 +class MethodReferenceTestInstance_E { 22.45 + String xI(Integer i) { 22.46 + return "ExI:" + i; 22.47 + } 22.48 +} 22.49 + 22.50 +@Test 22.51 +public class MethodReferenceTestInstance { 22.52 + 22.53 + interface SI { String m(Integer a); } 22.54 + 22.55 + String xI(Integer i) { 22.56 + return "xI:" + i; 22.57 + } 22.58 + 22.59 + public void testMethodReferenceInstance() { 22.60 + SI q; 22.61 + 22.62 + q = this::xI; 22.63 + assertEquals(q.m(55), "xI:55"); 22.64 + } 22.65 + 22.66 + public void testMethodReferenceExternal() { 22.67 + SI q; 22.68 + 22.69 + q = (new MethodReferenceTestInstance_E())::xI; 22.70 + assertEquals(q.m(77), "ExI:77"); 22.71 + } 22.72 + 22.73 +}
23.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 23.2 +++ b/test/tools/javac/lambda/methodReferenceExecution/MethodReferenceTestKinds.java Tue Nov 20 09:58:55 2012 -0800 23.3 @@ -0,0 +1,194 @@ 23.4 +/* 23.5 + * Copyright (c) 2012 Oracle and/or its affiliates. All rights reserved. 23.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 23.7 + * 23.8 + * This code is free software; you can redistribute it and/or modify it 23.9 + * under the terms of the GNU General Public License version 2 only, as 23.10 + * published by the Free Software Foundation. Oracle designates this 23.11 + * particular file as subject to the "Classpath" exception as provided 23.12 + * by Oracle in the LICENSE file that accompanied this code. 23.13 + * 23.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 23.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 23.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 23.17 + * version 2 for more details (a copy is included in the LICENSE file that 23.18 + * accompanied this code). 23.19 + * 23.20 + * You should have received a copy of the GNU General Public License version 23.21 + * 2 along with this work; if not, write to the Free Software Foundation, 23.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 23.23 + * 23.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 23.25 + * or visit www.oracle.com if you need additional information or have any 23.26 + * questions. 23.27 + */ 23.28 + 23.29 +/** 23.30 + * @test 23.31 + * @bug 8003639 23.32 + * @summary convert lambda testng tests to jtreg and add them 23.33 + * @run testng MethodReferenceTestKinds 23.34 + */ 23.35 + 23.36 +import org.testng.annotations.Test; 23.37 + 23.38 +import static org.testng.Assert.assertEquals; 23.39 + 23.40 +/** 23.41 + * @author Robert Field 23.42 + */ 23.43 + 23.44 +@Test 23.45 +public class MethodReferenceTestKinds extends MethodReferenceTestKindsSup { 23.46 + 23.47 + interface S0 { String get(); } 23.48 + interface S1 { String get(MethodReferenceTestKinds x); } 23.49 + interface S2 { String get(MethodReferenceTestKinds x, MethodReferenceTestKinds y); } 23.50 + 23.51 + interface SXN0 { MethodReferenceTestKindsBase make(MethodReferenceTestKinds x); } 23.52 + interface SXN1 { MethodReferenceTestKindsBase make(MethodReferenceTestKinds x, String str); } 23.53 + 23.54 + interface SN0 { MethodReferenceTestKindsBase make(); } 23.55 + interface SN1 { MethodReferenceTestKindsBase make(String x); } 23.56 + 23.57 + class In extends MethodReferenceTestKindsBase { 23.58 + In(String val) { 23.59 + this.val = val; 23.60 + } 23.61 + 23.62 + In() { 23.63 + this("blank"); 23.64 + } 23.65 + } 23.66 + 23.67 + String instanceMethod0() { return "IM:0-" + this; } 23.68 + String instanceMethod1(MethodReferenceTestKinds x) { return "IM:1-" + this + x; } 23.69 + 23.70 + static String staticMethod0() { return "SM:0"; } 23.71 + static String staticMethod1(MethodReferenceTestKinds x) { return "SM:1-" + x; } 23.72 + 23.73 + MethodReferenceTestKinds(String val) { 23.74 + super(val); 23.75 + } 23.76 + 23.77 + MethodReferenceTestKinds() { 23.78 + super("blank"); 23.79 + } 23.80 + 23.81 + MethodReferenceTestKinds inst(String val) { 23.82 + return new MethodReferenceTestKinds(val); 23.83 + } 23.84 + 23.85 + public void testMRBound() { 23.86 + S0 var = this::instanceMethod0; 23.87 + assertEquals(var.get(), "IM:0-MethodReferenceTestKinds(blank)"); 23.88 + } 23.89 + 23.90 + public void testMRBoundArg() { 23.91 + S1 var = this::instanceMethod1; 23.92 + assertEquals(var.get(inst("arg")), "IM:1-MethodReferenceTestKinds(blank)MethodReferenceTestKinds(arg)"); 23.93 + } 23.94 + 23.95 + public void testMRUnbound() { 23.96 + S1 var = MethodReferenceTestKinds::instanceMethod0; 23.97 + assertEquals(var.get(inst("rcvr")), "IM:0-MethodReferenceTestKinds(rcvr)"); 23.98 + } 23.99 + 23.100 + public void testMRUnboundArg() { 23.101 + S2 var = MethodReferenceTestKinds::instanceMethod1; 23.102 + assertEquals(var.get(inst("rcvr"), inst("arg")), "IM:1-MethodReferenceTestKinds(rcvr)MethodReferenceTestKinds(arg)"); 23.103 + } 23.104 + 23.105 + public void testMRSuper() { 23.106 + S0 var = super::instanceMethod0; 23.107 + assertEquals(var.get(), "SIM:0-MethodReferenceTestKinds(blank)"); 23.108 + } 23.109 + 23.110 + public void testMRSuperArg() { 23.111 + S1 var = super::instanceMethod1; 23.112 + assertEquals(var.get(inst("arg")), "SIM:1-MethodReferenceTestKinds(blank)MethodReferenceTestKinds(arg)"); 23.113 + } 23.114 + 23.115 + public void testMRStatic() { 23.116 + S0 var = MethodReferenceTestKinds::staticMethod0; 23.117 + assertEquals(var.get(), "SM:0"); 23.118 + } 23.119 + 23.120 + public void testMRStaticArg() { 23.121 + S1 var = MethodReferenceTestKinds::staticMethod1; 23.122 + assertEquals(var.get(inst("arg")), "SM:1-MethodReferenceTestKinds(arg)"); 23.123 + } 23.124 + 23.125 + public void testMRStaticEval() { 23.126 + MethodReferenceTestKinds evalCheck; 23.127 + S0 var = (evalCheck = inst("discard"))::staticMethod0; 23.128 + assertEquals(evalCheck.toString(), "MethodReferenceTestKinds(discard)"); 23.129 + assertEquals(var.get(), "SM:0"); 23.130 + } 23.131 + 23.132 + public void testMRStaticEvalArg() { 23.133 + MethodReferenceTestKinds evalCheck; 23.134 + S1 var = (evalCheck = inst("discard"))::staticMethod1; 23.135 + assertEquals(evalCheck.toString(), "MethodReferenceTestKinds(discard)"); 23.136 + assertEquals(var.get(inst("arg")), "SM:1-MethodReferenceTestKinds(arg)"); 23.137 + } 23.138 + 23.139 + public void testMRTopLevel() { 23.140 + SN0 var = MethodReferenceTestKindsBase::new; 23.141 + assertEquals(var.make().toString(), "MethodReferenceTestKindsBase(blank)"); 23.142 + } 23.143 + 23.144 + public void testMRTopLevelArg() { 23.145 + SN1 var = MethodReferenceTestKindsBase::new; 23.146 + assertEquals(var.make("name").toString(), "MethodReferenceTestKindsBase(name)"); 23.147 + } 23.148 +/* unbound inner case not supported anymore (dropped by EG) 23.149 + public void testMRUnboundInner() { 23.150 + SXN0 var = MethodReferenceTestKinds.In::new; 23.151 + assertEquals(var.make(inst("out")).toString(), "In(blank)"); 23.152 + } 23.153 + 23.154 + public void testMRUnboundInnerArg() { 23.155 + SXN1 var = MethodReferenceTestKinds.In::new; 23.156 + assertEquals(var.make(inst("out"), "name").toString(), "In(name)"); 23.157 + } 23.158 +*/ 23.159 + public void testMRImplicitInner() { 23.160 + SN0 var = MethodReferenceTestKinds.In::new; 23.161 + assertEquals(var.make().toString(), "In(blank)"); 23.162 + } 23.163 + 23.164 + public void testMRImplicitInnerArg() { 23.165 + SN1 var = MethodReferenceTestKinds.In::new; 23.166 + assertEquals(var.make("name").toString(), "In(name)"); 23.167 + } 23.168 + 23.169 +} 23.170 + 23.171 + 23.172 +class MethodReferenceTestKindsBase { 23.173 + String val = "unset"; 23.174 + 23.175 + public String toString() { 23.176 + return getClass().getSimpleName() + "(" + val + ")"; 23.177 + } 23.178 + 23.179 + MethodReferenceTestKindsBase(String val) { 23.180 + this.val = val; 23.181 + } 23.182 + 23.183 + MethodReferenceTestKindsBase() { 23.184 + this("blank"); 23.185 + } 23.186 + 23.187 +} 23.188 + 23.189 +class MethodReferenceTestKindsSup extends MethodReferenceTestKindsBase { 23.190 + String instanceMethod0() { return "SIM:0-" + this; } 23.191 + String instanceMethod1(MethodReferenceTestKinds x) { return "SIM:1-" + this + x; } 23.192 + 23.193 + MethodReferenceTestKindsSup(String val) { 23.194 + super(val); 23.195 + } 23.196 + 23.197 +}
24.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 24.2 +++ b/test/tools/javac/lambda/methodReferenceExecution/MethodReferenceTestNew.java Tue Nov 20 09:58:55 2012 -0800 24.3 @@ -0,0 +1,138 @@ 24.4 +/* 24.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 24.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 24.7 + * 24.8 + * This code is free software; you can redistribute it and/or modify it 24.9 + * under the terms of the GNU General Public License version 2 only, as 24.10 + * published by the Free Software Foundation. Oracle designates this 24.11 + * particular file as subject to the "Classpath" exception as provided 24.12 + * by Oracle in the LICENSE file that accompanied this code. 24.13 + * 24.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 24.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 24.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 24.17 + * version 2 for more details (a copy is included in the LICENSE file that 24.18 + * accompanied this code). 24.19 + * 24.20 + * You should have received a copy of the GNU General Public License version 24.21 + * 2 along with this work; if not, write to the Free Software Foundation, 24.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 24.23 + * 24.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 24.25 + * or visit www.oracle.com if you need additional information or have any 24.26 + * questions. 24.27 + */ 24.28 + 24.29 +/** 24.30 + * @test 24.31 + * @bug 8003639 24.32 + * @summary convert lambda testng tests to jtreg and add them 24.33 + * @run testng MethodReferenceTestNew 24.34 + */ 24.35 + 24.36 +import org.testng.annotations.Test; 24.37 + 24.38 +import static org.testng.Assert.assertEquals; 24.39 + 24.40 +/** 24.41 + * @author Robert Field 24.42 + */ 24.43 + 24.44 +@Test 24.45 +public class MethodReferenceTestNew { 24.46 + 24.47 + interface M0<T> { 24.48 + 24.49 + T m(); 24.50 + } 24.51 + 24.52 + static class N0 { 24.53 + 24.54 + N0() { 24.55 + } 24.56 + } 24.57 + 24.58 + interface M1<T> { 24.59 + 24.60 + T m(Integer a); 24.61 + } 24.62 + 24.63 + static class N1 { 24.64 + 24.65 + int i; 24.66 + 24.67 + N1(int i) { 24.68 + this.i = i; 24.69 + } 24.70 + } 24.71 + 24.72 + interface M2<T> { 24.73 + 24.74 + T m(Integer n, String o); 24.75 + } 24.76 + 24.77 + static class N2 { 24.78 + 24.79 + Number n; 24.80 + Object o; 24.81 + 24.82 + N2(Number n, Object o) { 24.83 + this.n = n; 24.84 + this.o = o; 24.85 + } 24.86 + 24.87 + public String toString() { 24.88 + return "N2(" + n + "," + o + ")"; 24.89 + } 24.90 + } 24.91 + 24.92 + interface MV { 24.93 + 24.94 + NV m(Integer ai, int i); 24.95 + } 24.96 + 24.97 + static class NV { 24.98 + 24.99 + int i; 24.100 + 24.101 + NV(int... v) { 24.102 + i = 0; 24.103 + for (int x : v) { 24.104 + i += x; 24.105 + } 24.106 + } 24.107 + 24.108 + public String toString() { 24.109 + return "NV(" + i + ")"; 24.110 + } 24.111 + } 24.112 + 24.113 + public void testConstructorReference0() { 24.114 + M0<N0> q; 24.115 + 24.116 + q = N0::new; 24.117 + assertEquals(q.m().getClass().getSimpleName(), "N0"); 24.118 + } 24.119 + 24.120 + public void testConstructorReference1() { 24.121 + M1<N1> q; 24.122 + 24.123 + q = N1::new; 24.124 + assertEquals(q.m(14).getClass().getSimpleName(), "N1"); 24.125 + } 24.126 + 24.127 + public void testConstructorReference2() { 24.128 + M2<N2> q; 24.129 + 24.130 + q = N2::new; 24.131 + assertEquals(q.m(7, "hi").toString(), "N2(7,hi)"); 24.132 + } 24.133 + 24.134 + public void testConstructorReferenceVarArgs() { 24.135 + MV q; 24.136 + 24.137 + q = NV::new; 24.138 + assertEquals(q.m(5, 45).toString(), "NV(50)"); 24.139 + } 24.140 + 24.141 +}
25.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 25.2 +++ b/test/tools/javac/lambda/methodReferenceExecution/MethodReferenceTestNewInner.java Tue Nov 20 09:58:55 2012 -0800 25.3 @@ -0,0 +1,157 @@ 25.4 +/* 25.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 25.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 25.7 + * 25.8 + * This code is free software; you can redistribute it and/or modify it 25.9 + * under the terms of the GNU General Public License version 2 only, as 25.10 + * published by the Free Software Foundation. Oracle designates this 25.11 + * particular file as subject to the "Classpath" exception as provided 25.12 + * by Oracle in the LICENSE file that accompanied this code. 25.13 + * 25.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 25.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 25.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 25.17 + * version 2 for more details (a copy is included in the LICENSE file that 25.18 + * accompanied this code). 25.19 + * 25.20 + * You should have received a copy of the GNU General Public License version 25.21 + * 2 along with this work; if not, write to the Free Software Foundation, 25.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 25.23 + * 25.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 25.25 + * or visit www.oracle.com if you need additional information or have any 25.26 + * questions. 25.27 + */ 25.28 + 25.29 +/** 25.30 + * @test 25.31 + * @bug 8003639 25.32 + * @summary convert lambda testng tests to jtreg and add them 25.33 + * @run testng MethodReferenceTestNewInner 25.34 + */ 25.35 + 25.36 +import org.testng.annotations.Test; 25.37 + 25.38 +import static org.testng.Assert.assertEquals; 25.39 + 25.40 +/** 25.41 + * @author Robert Field 25.42 + */ 25.43 + 25.44 +@Test 25.45 +public class MethodReferenceTestNewInner { 25.46 + 25.47 + String note = "NO NOTE"; 25.48 + 25.49 + interface M0<T> { 25.50 + 25.51 + T m(); 25.52 + } 25.53 + 25.54 + interface MP<T> { 25.55 + 25.56 + T m(MethodReferenceTestNewInner m); 25.57 + } 25.58 + 25.59 + class N0 { 25.60 + 25.61 + N0() { 25.62 + } 25.63 + } 25.64 + 25.65 + interface M1<T> { 25.66 + 25.67 + T m(Integer a); 25.68 + } 25.69 + 25.70 + class N1 { 25.71 + 25.72 + int i; 25.73 + 25.74 + N1(int i) { 25.75 + this.i = i; 25.76 + } 25.77 + } 25.78 + 25.79 + interface M2<T> { 25.80 + 25.81 + T m(Integer n, String o); 25.82 + } 25.83 + 25.84 + class N2 { 25.85 + 25.86 + Number n; 25.87 + Object o; 25.88 + 25.89 + N2(Number n, Object o) { 25.90 + this.n = n; 25.91 + this.o = o; 25.92 + } 25.93 + 25.94 + public String toString() { 25.95 + return note + ":N2(" + n + "," + o + ")"; 25.96 + } 25.97 + } 25.98 + 25.99 + interface MV { 25.100 + 25.101 + NV m(Integer ai, int i); 25.102 + } 25.103 + 25.104 + class NV { 25.105 + 25.106 + int i; 25.107 + 25.108 + NV(int... v) { 25.109 + i = 0; 25.110 + for (int x : v) { 25.111 + i += x; 25.112 + } 25.113 + } 25.114 + 25.115 + public String toString() { 25.116 + return note + ":NV(" + i + ")"; 25.117 + } 25.118 + } 25.119 + 25.120 +/* unbound constructor case not supported anymore (dropped by EG) 25.121 + public static void testConstructorReferenceP() { 25.122 + MP<N0> q; 25.123 + 25.124 + q = N0::new; 25.125 + assertEquals(q.m(new MethodReferenceTestNewInner()).getClass().getSimpleName(), "N0"); 25.126 + } 25.127 +*/ 25.128 + public void testConstructorReference0() { 25.129 + M0<N0> q; 25.130 + 25.131 + q = N0::new; 25.132 + assertEquals(q.m().getClass().getSimpleName(), "N0"); 25.133 + } 25.134 + 25.135 + public void testConstructorReference1() { 25.136 + M1<N1> q; 25.137 + 25.138 + q = N1::new; 25.139 + assertEquals(q.m(14).getClass().getSimpleName(), "N1"); 25.140 + } 25.141 + 25.142 + public void testConstructorReference2() { 25.143 + M2<N2> q; 25.144 + 25.145 + note = "T2"; 25.146 + q = N2::new; 25.147 + assertEquals(q.m(7, "hi").toString(), "T2:N2(7,hi)"); 25.148 + } 25.149 + 25.150 + /*** 25.151 + public void testConstructorReferenceVarArgs() { 25.152 + MV q; 25.153 + 25.154 + note = "TVA"; 25.155 + q = NV::new; 25.156 + assertEquals(q.m(5, 45).toString(), "TNV:NV(50)"); 25.157 + } 25.158 + ***/ 25.159 + 25.160 +}
26.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 26.2 +++ b/test/tools/javac/lambda/methodReferenceExecution/MethodReferenceTestSueCase1.java Tue Nov 20 09:58:55 2012 -0800 26.3 @@ -0,0 +1,54 @@ 26.4 +/* 26.5 + * Copyright (c) 2012 Oracle and/or its affiliates. All rights reserved. 26.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 26.7 + * 26.8 + * This code is free software; you can redistribute it and/or modify it 26.9 + * under the terms of the GNU General Public License version 2 only, as 26.10 + * published by the Free Software Foundation. Oracle designates this 26.11 + * particular file as subject to the "Classpath" exception as provided 26.12 + * by Oracle in the LICENSE file that accompanied this code. 26.13 + * 26.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 26.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 26.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 26.17 + * version 2 for more details (a copy is included in the LICENSE file that 26.18 + * accompanied this code). 26.19 + * 26.20 + * You should have received a copy of the GNU General Public License version 26.21 + * 2 along with this work; if not, write to the Free Software Foundation, 26.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 26.23 + * 26.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 26.25 + * or visit www.oracle.com if you need additional information or have any 26.26 + * questions. 26.27 + */ 26.28 + 26.29 +/** 26.30 + * @test 26.31 + * @bug 8003639 26.32 + * @summary convert lambda testng tests to jtreg and add them 26.33 + * @run testng MethodReferenceTestSueCase1 26.34 + */ 26.35 + 26.36 +import org.testng.annotations.Test; 26.37 + 26.38 +import static org.testng.Assert.assertEquals; 26.39 + 26.40 +/** 26.41 + * @author Robert Field 26.42 + */ 26.43 + 26.44 +@Test 26.45 +public class MethodReferenceTestSueCase1 { 26.46 + 26.47 + public interface Sam2<T> { public String get(T target, String s); } 26.48 + 26.49 + String instanceMethod(String s) { return "2"; } 26.50 + Sam2<MethodReferenceTestSueCase1> var = MethodReferenceTestSueCase1::instanceMethod; 26.51 + 26.52 + String m() { return var.get(new MethodReferenceTestSueCase1(), ""); } 26.53 + 26.54 + public void testSueCase1() { 26.55 + assertEquals(m(), "2"); 26.56 + } 26.57 +}
27.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 27.2 +++ b/test/tools/javac/lambda/methodReferenceExecution/MethodReferenceTestSueCase2.java Tue Nov 20 09:58:55 2012 -0800 27.3 @@ -0,0 +1,54 @@ 27.4 +/* 27.5 + * Copyright (c) 2012 Oracle and/or its affiliates. All rights reserved. 27.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 27.7 + * 27.8 + * This code is free software; you can redistribute it and/or modify it 27.9 + * under the terms of the GNU General Public License version 2 only, as 27.10 + * published by the Free Software Foundation. Oracle designates this 27.11 + * particular file as subject to the "Classpath" exception as provided 27.12 + * by Oracle in the LICENSE file that accompanied this code. 27.13 + * 27.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 27.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 27.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 27.17 + * version 2 for more details (a copy is included in the LICENSE file that 27.18 + * accompanied this code). 27.19 + * 27.20 + * You should have received a copy of the GNU General Public License version 27.21 + * 2 along with this work; if not, write to the Free Software Foundation, 27.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 27.23 + * 27.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 27.25 + * or visit www.oracle.com if you need additional information or have any 27.26 + * questions. 27.27 + */ 27.28 + 27.29 +/** 27.30 + * @test 27.31 + * @bug 8003639 27.32 + * @summary convert lambda testng tests to jtreg and add them 27.33 + * @run testng MethodReferenceTestSueCase2 27.34 + */ 27.35 + 27.36 +import org.testng.annotations.Test; 27.37 + 27.38 +import static org.testng.Assert.assertEquals; 27.39 + 27.40 +/** 27.41 + * @author Robert Field 27.42 + */ 27.43 + 27.44 +@Test 27.45 +public class MethodReferenceTestSueCase2 { 27.46 + 27.47 + public interface Sam2<T> { public String get(T target, String s); } 27.48 + 27.49 + String instanceMethod(String s) { return "2"; } 27.50 + static Sam2<MethodReferenceTestSueCase2> var = MethodReferenceTestSueCase2::instanceMethod; 27.51 + 27.52 + String m() { return var.get(new MethodReferenceTestSueCase2(), ""); } 27.53 + 27.54 + public void testSueCase2() { 27.55 + assertEquals(m(), "2"); 27.56 + } 27.57 +}
28.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 28.2 +++ b/test/tools/javac/lambda/methodReferenceExecution/MethodReferenceTestSueCase4.java Tue Nov 20 09:58:55 2012 -0800 28.3 @@ -0,0 +1,59 @@ 28.4 +/* 28.5 + * Copyright (c) 2012 Oracle and/or its affiliates. All rights reserved. 28.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 28.7 + * 28.8 + * This code is free software; you can redistribute it and/or modify it 28.9 + * under the terms of the GNU General Public License version 2 only, as 28.10 + * published by the Free Software Foundation. Oracle designates this 28.11 + * particular file as subject to the "Classpath" exception as provided 28.12 + * by Oracle in the LICENSE file that accompanied this code. 28.13 + * 28.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 28.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 28.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 28.17 + * version 2 for more details (a copy is included in the LICENSE file that 28.18 + * accompanied this code). 28.19 + * 28.20 + * You should have received a copy of the GNU General Public License version 28.21 + * 2 along with this work; if not, write to the Free Software Foundation, 28.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 28.23 + * 28.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 28.25 + * or visit www.oracle.com if you need additional information or have any 28.26 + * questions. 28.27 + */ 28.28 + 28.29 +/** 28.30 + * @test 28.31 + * @bug 8003639 28.32 + * @summary convert lambda testng tests to jtreg and add them 28.33 + * @run testng MethodReferenceTestSueCase4 28.34 + */ 28.35 + 28.36 +import org.testng.annotations.Test; 28.37 + 28.38 +import static org.testng.Assert.assertEquals; 28.39 + 28.40 +/** 28.41 + * @author Robert Field 28.42 + */ 28.43 + 28.44 +@Test 28.45 +public class MethodReferenceTestSueCase4 { 28.46 + 28.47 + public interface Sam2<T> { public String get(T target, String s); } 28.48 + 28.49 + Sam2<Target> var = new Object().equals(new Object()) ? Target::instanceMethod : Target::instanceMethod; 28.50 + 28.51 + String m() { 28.52 + return var.get(new Target(), ""); 28.53 + } 28.54 + 28.55 + static class Target { 28.56 + String instanceMethod(String s) { return "2"; } 28.57 + } 28.58 + 28.59 + public void testSueCase4() { 28.60 + assertEquals(m(), "2"); 28.61 + } 28.62 +}
29.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 29.2 +++ b/test/tools/javac/lambda/methodReferenceExecution/MethodReferenceTestSuper.java Tue Nov 20 09:58:55 2012 -0800 29.3 @@ -0,0 +1,120 @@ 29.4 +/* 29.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 29.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 29.7 + * 29.8 + * This code is free software; you can redistribute it and/or modify it 29.9 + * under the terms of the GNU General Public License version 2 only, as 29.10 + * published by the Free Software Foundation. Oracle designates this 29.11 + * particular file as subject to the "Classpath" exception as provided 29.12 + * by Oracle in the LICENSE file that accompanied this code. 29.13 + * 29.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 29.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 29.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 29.17 + * version 2 for more details (a copy is included in the LICENSE file that 29.18 + * accompanied this code). 29.19 + * 29.20 + * You should have received a copy of the GNU General Public License version 29.21 + * 2 along with this work; if not, write to the Free Software Foundation, 29.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 29.23 + * 29.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 29.25 + * or visit www.oracle.com if you need additional information or have any 29.26 + * questions. 29.27 + */ 29.28 + 29.29 +/** 29.30 + * @test 29.31 + * @bug 8003639 29.32 + * @summary convert lambda testng tests to jtreg and add them 29.33 + * @run testng MethodReferenceTestSuper 29.34 + */ 29.35 + 29.36 +import org.testng.annotations.Test; 29.37 + 29.38 +import static org.testng.Assert.assertEquals; 29.39 + 29.40 +/** 29.41 + * @author Robert Field 29.42 + */ 29.43 + 29.44 +interface SPRI { String m(String a); } 29.45 + 29.46 +class SPRA { 29.47 + String xsA__(String s) { 29.48 + return "A__xsA:" + s; 29.49 + } 29.50 + 29.51 + String xsA_M(String s) { 29.52 + return "A_MxsA:" + s; 29.53 + } 29.54 + 29.55 + String xsAB_(String s) { 29.56 + return "AB_xsA:" + s; 29.57 + } 29.58 + 29.59 + String xsABM(String s) { 29.60 + return "ABMxsA:" + s; 29.61 + } 29.62 + 29.63 +} 29.64 + 29.65 +class SPRB extends SPRA { 29.66 + 29.67 + String xsAB_(String s) { 29.68 + return "AB_xsB:" + s; 29.69 + } 29.70 + 29.71 + String xsABM(String s) { 29.72 + return "ABMxsB:" + s; 29.73 + } 29.74 + 29.75 + String xs_B_(String s) { 29.76 + return "_B_xsB:" + s; 29.77 + } 29.78 + 29.79 + String xs_BM(String s) { 29.80 + return "_BMxsB:" + s; 29.81 + } 29.82 + 29.83 +} 29.84 + 29.85 +@Test 29.86 +public class MethodReferenceTestSuper extends SPRB { 29.87 + 29.88 + String xsA_M(String s) { 29.89 + return "A_MxsM:" + s; 29.90 + } 29.91 + 29.92 + 29.93 + String xsABM(String s) { 29.94 + return "ABMxsM:" + s; 29.95 + } 29.96 + 29.97 + String xs_BM(String s) { 29.98 + return "_BMxsM:" + s; 29.99 + } 29.100 + 29.101 + public void testMethodReferenceSuper() { 29.102 + SPRI q; 29.103 + 29.104 + q = super::xsA__; 29.105 + assertEquals(q.m("*"), "A__xsA:*"); 29.106 + 29.107 + q = super::xsA_M; 29.108 + assertEquals(q.m("*"), "A_MxsA:*"); 29.109 + 29.110 + q = super::xsAB_; 29.111 + assertEquals(q.m("*"), "AB_xsB:*"); 29.112 + 29.113 + q = super::xsABM; 29.114 + assertEquals(q.m("*"), "ABMxsB:*"); 29.115 + 29.116 + q = super::xs_B_; 29.117 + assertEquals(q.m("*"), "_B_xsB:*"); 29.118 + 29.119 + q = super::xs_BM; 29.120 + assertEquals(q.m("*"), "_BMxsB:*"); 29.121 + } 29.122 + 29.123 +}
30.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 30.2 +++ b/test/tools/javac/lambda/methodReferenceExecution/MethodReferenceTestSuperDefault.java Tue Nov 20 09:58:55 2012 -0800 30.3 @@ -0,0 +1,82 @@ 30.4 +/* 30.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 30.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 30.7 + * 30.8 + * This code is free software; you can redistribute it and/or modify it 30.9 + * under the terms of the GNU General Public License version 2 only, as 30.10 + * published by the Free Software Foundation. Oracle designates this 30.11 + * particular file as subject to the "Classpath" exception as provided 30.12 + * by Oracle in the LICENSE file that accompanied this code. 30.13 + * 30.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 30.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 30.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 30.17 + * version 2 for more details (a copy is included in the LICENSE file that 30.18 + * accompanied this code). 30.19 + * 30.20 + * You should have received a copy of the GNU General Public License version 30.21 + * 2 along with this work; if not, write to the Free Software Foundation, 30.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 30.23 + * 30.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 30.25 + * or visit www.oracle.com if you need additional information or have any 30.26 + * questions. 30.27 + */ 30.28 + 30.29 +/** 30.30 + * @test 30.31 + * @bug 8003639 30.32 + * @summary convert lambda testng tests to jtreg and add them 30.33 + * @run testng MethodReferenceTestSuperDefault 30.34 + */ 30.35 + 30.36 +import org.testng.annotations.Test; 30.37 + 30.38 +import static org.testng.Assert.assertEquals; 30.39 + 30.40 +/** 30.41 + * @author Robert Field 30.42 + */ 30.43 + 30.44 +interface DSPRI { String m(String a); } 30.45 + 30.46 +interface DSPRA { 30.47 + default String xsA__(String s) { 30.48 + return "A__xsA:" + s; 30.49 + } 30.50 + 30.51 + default String xsAB_(String s) { 30.52 + return "AB_xsA:" + s; 30.53 + } 30.54 + 30.55 +} 30.56 + 30.57 +interface DSPRB extends DSPRA { 30.58 + 30.59 + default String xsAB_(String s) { 30.60 + return "AB_xsB:" + s; 30.61 + } 30.62 + 30.63 + default String xs_B_(String s) { 30.64 + return "_B_xsB:" + s; 30.65 + } 30.66 + 30.67 +} 30.68 + 30.69 +@Test 30.70 +public class MethodReferenceTestSuperDefault implements DSPRB { 30.71 + 30.72 + public void testMethodReferenceSuper() { 30.73 + DSPRI q; 30.74 + 30.75 + q = DSPRB.super::xsA__; 30.76 + assertEquals(q.m("*"), "A__xsA:*"); 30.77 + 30.78 + q = DSPRB.super::xsAB_; 30.79 + assertEquals(q.m("*"), "AB_xsB:*"); 30.80 + 30.81 + q = DSPRB.super::xs_B_; 30.82 + assertEquals(q.m("*"), "_B_xsB:*"); 30.83 + } 30.84 + 30.85 +}
31.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 31.2 +++ b/test/tools/javac/lambda/methodReferenceExecution/MethodReferenceTestTypeConversion.java Tue Nov 20 09:58:55 2012 -0800 31.3 @@ -0,0 +1,62 @@ 31.4 +/* 31.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 31.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 31.7 + * 31.8 + * This code is free software; you can redistribute it and/or modify it 31.9 + * under the terms of the GNU General Public License version 2 only, as 31.10 + * published by the Free Software Foundation. Oracle designates this 31.11 + * particular file as subject to the "Classpath" exception as provided 31.12 + * by Oracle in the LICENSE file that accompanied this code. 31.13 + * 31.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 31.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 31.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 31.17 + * version 2 for more details (a copy is included in the LICENSE file that 31.18 + * accompanied this code). 31.19 + * 31.20 + * You should have received a copy of the GNU General Public License version 31.21 + * 2 along with this work; if not, write to the Free Software Foundation, 31.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 31.23 + * 31.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 31.25 + * or visit www.oracle.com if you need additional information or have any 31.26 + * questions. 31.27 + */ 31.28 + 31.29 +/** 31.30 + * @test 31.31 + * @bug 8003639 31.32 + * @summary convert lambda testng tests to jtreg and add them 31.33 + * @run testng MethodReferenceTestTypeConversion 31.34 + */ 31.35 + 31.36 +import org.testng.annotations.Test; 31.37 + 31.38 +import static org.testng.Assert.assertEquals; 31.39 + 31.40 +/** 31.41 + * @author Robert Field 31.42 + */ 31.43 + 31.44 +class MethodReferenceTestTypeConversion_E<T> { 31.45 + T xI(T t) { return t; } 31.46 +} 31.47 + 31.48 +@Test 31.49 +public class MethodReferenceTestTypeConversion { 31.50 + 31.51 + interface ISi { int m(Short a); } 31.52 + 31.53 + interface ICc { char m(Character a); } 31.54 + 31.55 + public void testUnboxObjectToNumberWiden() { 31.56 + ISi q = (new MethodReferenceTestTypeConversion_E<Short>())::xI; 31.57 + assertEquals(q.m((short)77), (short)77); 31.58 + } 31.59 + 31.60 + public void testUnboxObjectToChar() { 31.61 + ICc q = (new MethodReferenceTestTypeConversion_E<Character>())::xI; 31.62 + assertEquals(q.m('@'), '@'); 31.63 + } 31.64 + 31.65 +}
32.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 32.2 +++ b/test/tools/javac/lambda/methodReferenceExecution/MethodReferenceTestVarArgs.java Tue Nov 20 09:58:55 2012 -0800 32.3 @@ -0,0 +1,204 @@ 32.4 +/* 32.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 32.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 32.7 + * 32.8 + * This code is free software; you can redistribute it and/or modify it 32.9 + * under the terms of the GNU General Public License version 2 only, as 32.10 + * published by the Free Software Foundation. Oracle designates this 32.11 + * particular file as subject to the "Classpath" exception as provided 32.12 + * by Oracle in the LICENSE file that accompanied this code. 32.13 + * 32.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 32.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 32.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 32.17 + * version 2 for more details (a copy is included in the LICENSE file that 32.18 + * accompanied this code). 32.19 + * 32.20 + * You should have received a copy of the GNU General Public License version 32.21 + * 2 along with this work; if not, write to the Free Software Foundation, 32.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 32.23 + * 32.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 32.25 + * or visit www.oracle.com if you need additional information or have any 32.26 + * questions. 32.27 + */ 32.28 + 32.29 +/** 32.30 + * @test 32.31 + * @bug 8003639 32.32 + * @summary convert lambda testng tests to jtreg and add them 32.33 + * @run testng MethodReferenceTestVarArgs 32.34 + */ 32.35 + 32.36 +import org.testng.annotations.Test; 32.37 +import java.lang.reflect.Array; 32.38 + 32.39 +import static org.testng.Assert.assertEquals; 32.40 + 32.41 +/** 32.42 + * @author Robert Field 32.43 + */ 32.44 + 32.45 +@Test 32.46 +public class MethodReferenceTestVarArgs { 32.47 + 32.48 + interface SII { 32.49 + 32.50 + String m(Integer a, Integer b); 32.51 + } 32.52 + 32.53 + interface Siii { 32.54 + 32.55 + String m(int a, int b, int c); 32.56 + } 32.57 + 32.58 + interface Si { 32.59 + 32.60 + String m(int a); 32.61 + } 32.62 + 32.63 + interface SaO { 32.64 + 32.65 + String m(Object[] a); 32.66 + } 32.67 + 32.68 + interface Sai { 32.69 + 32.70 + String m(int[] a); 32.71 + } 32.72 + 32.73 + interface Svi { 32.74 + 32.75 + String m(int... va); 32.76 + } 32.77 + 32.78 + // These should be processed as var args 32.79 + 32.80 + static String xvI(Integer... vi) { 32.81 + StringBuilder sb = new StringBuilder("xvI:"); 32.82 + for (Integer i : vi) { 32.83 + sb.append(i); 32.84 + sb.append("-"); 32.85 + } 32.86 + return sb.toString(); 32.87 + } 32.88 + 32.89 + static String xIvI(Integer f, Integer... vi) { 32.90 + StringBuilder sb = new StringBuilder("xIvI:"); 32.91 + sb.append(f); 32.92 + for (Integer i : vi) { 32.93 + sb.append(i); 32.94 + sb.append("-"); 32.95 + } 32.96 + return sb.toString(); 32.97 + } 32.98 + 32.99 + static String xvi(int... vi) { 32.100 + int sum = 0; 32.101 + for (int i : vi) { 32.102 + sum += i; 32.103 + } 32.104 + return "xvi:" + sum; 32.105 + } 32.106 + 32.107 + static String xIvi(Integer f, int... vi) { 32.108 + int sum = 0; 32.109 + for (int i : vi) { 32.110 + sum += i; 32.111 + } 32.112 + return "xIvi:(" + f + ")" + sum; 32.113 + } 32.114 + 32.115 + static String xvO(Object... vi) { 32.116 + StringBuilder sb = new StringBuilder("xvO:"); 32.117 + for (Object i : vi) { 32.118 + if (i.getClass().isArray()) { 32.119 + sb.append("["); 32.120 + int len = Array.getLength(i); 32.121 + for (int x = 0; x < len; ++x) { 32.122 + sb.append(Array.get(i, x)); 32.123 + sb.append(","); 32.124 + } 32.125 + sb.append("]"); 32.126 + 32.127 + } else { 32.128 + sb.append(i); 32.129 + } 32.130 + sb.append("*"); 32.131 + } 32.132 + return sb.toString(); 32.133 + } 32.134 + 32.135 + public void testVarArgsSuperclass() { 32.136 + SII q; 32.137 + 32.138 + q = MethodReferenceTestVarArgs::xvO; 32.139 + assertEquals(q.m(55,66), "xvO:55*66*"); 32.140 + } 32.141 + 32.142 + public void testVarArgsArray() { 32.143 + Sai q; 32.144 + 32.145 + q = MethodReferenceTestVarArgs::xvO; 32.146 + assertEquals(q.m(new int[] { 55,66 } ), "xvO:[55,66,]*"); 32.147 + } 32.148 + 32.149 + public void testVarArgsII() { 32.150 + SII q; 32.151 + 32.152 + q = MethodReferenceTestVarArgs::xvI; 32.153 + assertEquals(q.m(33,7), "xvI:33-7-"); 32.154 + 32.155 + q = MethodReferenceTestVarArgs::xIvI; 32.156 + assertEquals(q.m(50,40), "xIvI:5040-"); 32.157 + 32.158 + q = MethodReferenceTestVarArgs::xvi; 32.159 + assertEquals(q.m(100,23), "xvi:123"); 32.160 + 32.161 + q = MethodReferenceTestVarArgs::xIvi; 32.162 + assertEquals(q.m(9,21), "xIvi:(9)21"); 32.163 + } 32.164 + 32.165 + public void testVarArgsiii() { 32.166 + Siii q; 32.167 + 32.168 + q = MethodReferenceTestVarArgs::xvI; 32.169 + assertEquals(q.m(3, 2, 1), "xvI:3-2-1-"); 32.170 + 32.171 + q = MethodReferenceTestVarArgs::xIvI; 32.172 + assertEquals(q.m(888, 99, 2), "xIvI:88899-2-"); 32.173 + 32.174 + q = MethodReferenceTestVarArgs::xvi; 32.175 + assertEquals(q.m(900,80,7), "xvi:987"); 32.176 + 32.177 + q = MethodReferenceTestVarArgs::xIvi; 32.178 + assertEquals(q.m(333,27, 72), "xIvi:(333)99"); 32.179 + } 32.180 + 32.181 + public void testVarArgsi() { 32.182 + Si q; 32.183 + 32.184 + q = MethodReferenceTestVarArgs::xvI; 32.185 + assertEquals(q.m(3), "xvI:3-"); 32.186 + 32.187 + q = MethodReferenceTestVarArgs::xIvI; 32.188 + assertEquals(q.m(888), "xIvI:888"); 32.189 + 32.190 + q = MethodReferenceTestVarArgs::xvi; 32.191 + assertEquals(q.m(900), "xvi:900"); 32.192 + 32.193 + q = MethodReferenceTestVarArgs::xIvi; 32.194 + assertEquals(q.m(333), "xIvi:(333)0"); 32.195 + } 32.196 + 32.197 + // These should NOT be processed as var args 32.198 + 32.199 + public void testVarArgsaO() { 32.200 + SaO q; 32.201 + 32.202 + q = MethodReferenceTestVarArgs::xvO; 32.203 + assertEquals(q.m(new String[] { "yo", "there", "dude" }), "xvO:yo*there*dude*"); 32.204 + } 32.205 + 32.206 + 32.207 +}
33.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 33.2 +++ b/test/tools/javac/lambda/methodReferenceExecution/MethodReferenceTestVarArgsExt.java Tue Nov 20 09:58:55 2012 -0800 33.3 @@ -0,0 +1,191 @@ 33.4 +/* 33.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 33.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 33.7 + * 33.8 + * This code is free software; you can redistribute it and/or modify it 33.9 + * under the terms of the GNU General Public License version 2 only, as 33.10 + * published by the Free Software Foundation. Oracle designates this 33.11 + * particular file as subject to the "Classpath" exception as provided 33.12 + * by Oracle in the LICENSE file that accompanied this code. 33.13 + * 33.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 33.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 33.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 33.17 + * version 2 for more details (a copy is included in the LICENSE file that 33.18 + * accompanied this code). 33.19 + * 33.20 + * You should have received a copy of the GNU General Public License version 33.21 + * 2 along with this work; if not, write to the Free Software Foundation, 33.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 33.23 + * 33.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 33.25 + * or visit www.oracle.com if you need additional information or have any 33.26 + * questions. 33.27 + */ 33.28 + 33.29 +/** 33.30 + * @test 33.31 + * @bug 8003639 33.32 + * @summary convert lambda testng tests to jtreg and add them 33.33 + * @run testng MethodReferenceTestVarArgsExt 33.34 + */ 33.35 + 33.36 +import org.testng.annotations.Test; 33.37 +import java.lang.reflect.Array; 33.38 + 33.39 +import static org.testng.Assert.assertEquals; 33.40 + 33.41 +/** 33.42 + * @author Robert Field 33.43 + */ 33.44 + 33.45 +interface NXII { String m(Integer a, Integer b); } 33.46 + 33.47 +interface NXiii { String m(int a, int b, int c); } 33.48 + 33.49 +interface NXi { String m(int a); } 33.50 + 33.51 +interface NXaO { String m(Object[] a); } 33.52 + 33.53 +interface NXai { String m(int[] a); } 33.54 + 33.55 +interface NXvi { String m(int... va); } 33.56 + 33.57 +@Test 33.58 +public class MethodReferenceTestVarArgsExt { 33.59 + 33.60 + // These should be processed as var args 33.61 + 33.62 + public void testVarArgsNXSuperclass() { 33.63 + NXII q; 33.64 + 33.65 + q = (new Ext())::xvO; 33.66 + assertEquals(q.m(55,66), "xvO:55*66*"); 33.67 + } 33.68 + 33.69 + public void testVarArgsNXArray() { 33.70 + NXai q; 33.71 + 33.72 + q = (new Ext())::xvO; 33.73 + assertEquals(q.m(new int[] { 55,66 } ), "xvO:[55,66,]*"); 33.74 + } 33.75 + 33.76 + public void testVarArgsNXII() { 33.77 + NXII q; 33.78 + 33.79 + q = (new Ext())::xvI; 33.80 + assertEquals(q.m(33,7), "xvI:33-7-"); 33.81 + 33.82 + q = (new Ext())::xIvI; 33.83 + assertEquals(q.m(50,40), "xIvI:5040-"); 33.84 + 33.85 + q = (new Ext())::xvi; 33.86 + assertEquals(q.m(100,23), "xvi:123"); 33.87 + 33.88 + q = (new Ext())::xIvi; 33.89 + assertEquals(q.m(9,21), "xIvi:(9)21"); 33.90 + } 33.91 + 33.92 + public void testVarArgsNXiii() { 33.93 + NXiii q; 33.94 + 33.95 + q = (new Ext())::xvI; 33.96 + assertEquals(q.m(3, 2, 1), "xvI:3-2-1-"); 33.97 + 33.98 + q = (new Ext())::xIvI; 33.99 + assertEquals(q.m(888, 99, 2), "xIvI:88899-2-"); 33.100 + 33.101 + q = (new Ext())::xvi; 33.102 + assertEquals(q.m(900,80,7), "xvi:987"); 33.103 + 33.104 + q = (new Ext())::xIvi; 33.105 + assertEquals(q.m(333,27, 72), "xIvi:(333)99"); 33.106 + } 33.107 + 33.108 + public void testVarArgsNXi() { 33.109 + NXi q; 33.110 + 33.111 + q = (new Ext())::xvI; 33.112 + assertEquals(q.m(3), "xvI:3-"); 33.113 + 33.114 + q = (new Ext())::xIvI; 33.115 + assertEquals(q.m(888), "xIvI:888"); 33.116 + 33.117 + q = (new Ext())::xvi; 33.118 + assertEquals(q.m(900), "xvi:900"); 33.119 + 33.120 + q = (new Ext())::xIvi; 33.121 + assertEquals(q.m(333), "xIvi:(333)0"); 33.122 + } 33.123 + 33.124 + // These should NOT be processed as var args 33.125 + 33.126 + public void testVarArgsNXaO() { 33.127 + NXaO q; 33.128 + 33.129 + q = (new Ext())::xvO; 33.130 + assertEquals(q.m(new String[] { "yo", "there", "dude" }), "xvO:yo*there*dude*"); 33.131 + } 33.132 + 33.133 + 33.134 +} 33.135 + 33.136 +class Ext { 33.137 + 33.138 + String xvI(Integer... vi) { 33.139 + StringBuilder sb = new StringBuilder("xvI:"); 33.140 + for (Integer i : vi) { 33.141 + sb.append(i); 33.142 + sb.append("-"); 33.143 + } 33.144 + return sb.toString(); 33.145 + } 33.146 + 33.147 + String xIvI(Integer f, Integer... vi) { 33.148 + StringBuilder sb = new StringBuilder("xIvI:"); 33.149 + sb.append(f); 33.150 + for (Integer i : vi) { 33.151 + sb.append(i); 33.152 + sb.append("-"); 33.153 + } 33.154 + return sb.toString(); 33.155 + } 33.156 + 33.157 + String xvi(int... vi) { 33.158 + int sum = 0; 33.159 + for (int i : vi) { 33.160 + sum += i; 33.161 + } 33.162 + return "xvi:" + sum; 33.163 + } 33.164 + 33.165 + String xIvi(Integer f, int... vi) { 33.166 + int sum = 0; 33.167 + for (int i : vi) { 33.168 + sum += i; 33.169 + } 33.170 + return "xIvi:(" + f + ")" + sum; 33.171 + } 33.172 + 33.173 + String xvO(Object... vi) { 33.174 + StringBuilder sb = new StringBuilder("xvO:"); 33.175 + for (Object i : vi) { 33.176 + if (i.getClass().isArray()) { 33.177 + sb.append("["); 33.178 + int len = Array.getLength(i); 33.179 + for (int x = 0; x < len; ++x) { 33.180 + sb.append(Array.get(i, x)); 33.181 + sb.append(","); 33.182 + } 33.183 + sb.append("]"); 33.184 + 33.185 + } else { 33.186 + sb.append(i); 33.187 + } 33.188 + sb.append("*"); 33.189 + } 33.190 + return sb.toString(); 33.191 + } 33.192 + 33.193 + 33.194 +}
34.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 34.2 +++ b/test/tools/javac/lambda/methodReferenceExecution/MethodReferenceTestVarArgsSuper.java Tue Nov 20 09:58:55 2012 -0800 34.3 @@ -0,0 +1,207 @@ 34.4 +/* 34.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 34.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 34.7 + * 34.8 + * This code is free software; you can redistribute it and/or modify it 34.9 + * under the terms of the GNU General Public License version 2 only, as 34.10 + * published by the Free Software Foundation. Oracle designates this 34.11 + * particular file as subject to the "Classpath" exception as provided 34.12 + * by Oracle in the LICENSE file that accompanied this code. 34.13 + * 34.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 34.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 34.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 34.17 + * version 2 for more details (a copy is included in the LICENSE file that 34.18 + * accompanied this code). 34.19 + * 34.20 + * You should have received a copy of the GNU General Public License version 34.21 + * 2 along with this work; if not, write to the Free Software Foundation, 34.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 34.23 + * 34.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 34.25 + * or visit www.oracle.com if you need additional information or have any 34.26 + * questions. 34.27 + */ 34.28 + 34.29 +/** 34.30 + * @test 34.31 + * @bug 8003639 34.32 + * @summary convert lambda testng tests to jtreg and add them 34.33 + * @run testng MethodReferenceTestVarArgsSuper 34.34 + */ 34.35 + 34.36 +import org.testng.annotations.Test; 34.37 +import java.lang.reflect.Array; 34.38 + 34.39 +import static org.testng.Assert.assertEquals; 34.40 + 34.41 +/** 34.42 + * @author Robert Field 34.43 + */ 34.44 + 34.45 +class MethodReferenceTestVarArgsSuper_Sub { 34.46 + 34.47 + String xvI(Integer... vi) { 34.48 + StringBuilder sb = new StringBuilder("xvI:"); 34.49 + for (Integer i : vi) { 34.50 + sb.append(i); 34.51 + sb.append("-"); 34.52 + } 34.53 + return sb.toString(); 34.54 + } 34.55 + 34.56 + String xIvI(Integer f, Integer... vi) { 34.57 + StringBuilder sb = new StringBuilder("xIvI:"); 34.58 + sb.append(f); 34.59 + for (Integer i : vi) { 34.60 + sb.append(i); 34.61 + sb.append("-"); 34.62 + } 34.63 + return sb.toString(); 34.64 + } 34.65 + 34.66 + String xvi(int... vi) { 34.67 + int sum = 0; 34.68 + for (int i : vi) { 34.69 + sum += i; 34.70 + } 34.71 + return "xvi:" + sum; 34.72 + } 34.73 + 34.74 + String xIvi(Integer f, int... vi) { 34.75 + int sum = 0; 34.76 + for (int i : vi) { 34.77 + sum += i; 34.78 + } 34.79 + return "xIvi:(" + f + ")" + sum; 34.80 + } 34.81 + 34.82 + String xvO(Object... vi) { 34.83 + StringBuilder sb = new StringBuilder("xvO:"); 34.84 + for (Object i : vi) { 34.85 + if (i.getClass().isArray()) { 34.86 + sb.append("["); 34.87 + int len = Array.getLength(i); 34.88 + for (int x = 0; x < len; ++x) { 34.89 + sb.append(Array.get(i, x)); 34.90 + sb.append(","); 34.91 + } 34.92 + sb.append("]"); 34.93 + 34.94 + } else { 34.95 + sb.append(i); 34.96 + } 34.97 + sb.append("*"); 34.98 + } 34.99 + return sb.toString(); 34.100 + } 34.101 +} 34.102 + 34.103 +@Test 34.104 +public class MethodReferenceTestVarArgsSuper extends MethodReferenceTestVarArgsSuper_Sub { 34.105 + 34.106 + interface SPRII { String m(Integer a, Integer b); } 34.107 + 34.108 + interface SPRiii { String m(int a, int b, int c); } 34.109 + 34.110 + interface SPRi { String m(int a); } 34.111 + 34.112 + interface SPRaO { String m(Object[] a); } 34.113 + 34.114 + interface SPRai { String m(int[] a); } 34.115 + 34.116 + interface SPRvi { String m(int... va); } 34.117 + 34.118 + String xvI(Integer... vi) { 34.119 + return "ERROR"; 34.120 + } 34.121 + 34.122 + String xIvI(Integer f, Integer... vi) { 34.123 + return "ERROR"; 34.124 + } 34.125 + 34.126 + String xvi(int... vi) { 34.127 + return "ERROR"; 34.128 + } 34.129 + 34.130 + String xIvi(Integer f, int... vi) { 34.131 + return "ERROR"; 34.132 + } 34.133 + 34.134 + String xvO(Object... vi) { 34.135 + return "ERROR"; 34.136 + } 34.137 + 34.138 + // These should be processed as var args 34.139 + 34.140 + public void testVarArgsSPRSuperclass() { 34.141 + SPRII q; 34.142 + 34.143 + q = super::xvO; 34.144 + assertEquals(q.m(55,66), "xvO:55*66*"); 34.145 + } 34.146 + 34.147 + public void testVarArgsSPRArray() { 34.148 + SPRai q; 34.149 + 34.150 + q = super::xvO; 34.151 + assertEquals(q.m(new int[] { 55,66 } ), "xvO:[55,66,]*"); 34.152 + } 34.153 + 34.154 + public void testVarArgsSPRII() { 34.155 + SPRII q; 34.156 + 34.157 + q = super::xvI; 34.158 + assertEquals(q.m(33,7), "xvI:33-7-"); 34.159 + 34.160 + q = super::xIvI; 34.161 + assertEquals(q.m(50,40), "xIvI:5040-"); 34.162 + 34.163 + q = super::xvi; 34.164 + assertEquals(q.m(100,23), "xvi:123"); 34.165 + 34.166 + q = super::xIvi; 34.167 + assertEquals(q.m(9,21), "xIvi:(9)21"); 34.168 + } 34.169 + 34.170 + public void testVarArgsSPRiii() { 34.171 + SPRiii q; 34.172 + 34.173 + q = super::xvI; 34.174 + assertEquals(q.m(3, 2, 1), "xvI:3-2-1-"); 34.175 + 34.176 + q = super::xIvI; 34.177 + assertEquals(q.m(888, 99, 2), "xIvI:88899-2-"); 34.178 + 34.179 + q = super::xvi; 34.180 + assertEquals(q.m(900,80,7), "xvi:987"); 34.181 + 34.182 + q = super::xIvi; 34.183 + assertEquals(q.m(333,27, 72), "xIvi:(333)99"); 34.184 + } 34.185 + 34.186 + public void testVarArgsSPRi() { 34.187 + SPRi q; 34.188 + 34.189 + q = super::xvI; 34.190 + assertEquals(q.m(3), "xvI:3-"); 34.191 + 34.192 + q = super::xIvI; 34.193 + assertEquals(q.m(888), "xIvI:888"); 34.194 + 34.195 + q = super::xvi; 34.196 + assertEquals(q.m(900), "xvi:900"); 34.197 + 34.198 + q = super::xIvi; 34.199 + assertEquals(q.m(333), "xIvi:(333)0"); 34.200 + } 34.201 + 34.202 + // These should NOT be processed as var args 34.203 + 34.204 + public void testVarArgsSPRaO() { 34.205 + SPRaO q; 34.206 + 34.207 + q = super::xvO; 34.208 + assertEquals(q.m(new String[] { "yo", "there", "dude" }), "xvO:yo*there*dude*"); 34.209 + } 34.210 +}
35.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 35.2 +++ b/test/tools/javac/lambda/methodReferenceExecution/MethodReferenceTestVarArgsSuperDefault.java Tue Nov 20 09:58:55 2012 -0800 35.3 @@ -0,0 +1,189 @@ 35.4 +/* 35.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 35.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 35.7 + * 35.8 + * This code is free software; you can redistribute it and/or modify it 35.9 + * under the terms of the GNU General Public License version 2 only, as 35.10 + * published by the Free Software Foundation. Oracle designates this 35.11 + * particular file as subject to the "Classpath" exception as provided 35.12 + * by Oracle in the LICENSE file that accompanied this code. 35.13 + * 35.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 35.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 35.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 35.17 + * version 2 for more details (a copy is included in the LICENSE file that 35.18 + * accompanied this code). 35.19 + * 35.20 + * You should have received a copy of the GNU General Public License version 35.21 + * 2 along with this work; if not, write to the Free Software Foundation, 35.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 35.23 + * 35.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 35.25 + * or visit www.oracle.com if you need additional information or have any 35.26 + * questions. 35.27 + */ 35.28 + 35.29 +/** 35.30 + * @test 35.31 + * @bug 8003639 35.32 + * @summary convert lambda testng tests to jtreg and add them 35.33 + * @run testng MethodReferenceTestVarArgsSuperDefault 35.34 + */ 35.35 + 35.36 +import org.testng.annotations.Test; 35.37 +import java.lang.reflect.Array; 35.38 + 35.39 +import static org.testng.Assert.assertEquals; 35.40 + 35.41 +/** 35.42 + * @author Robert Field 35.43 + */ 35.44 + 35.45 +interface MethodReferenceTestVarArgsSuperDefault_I { 35.46 + 35.47 + default String xvI(Integer... vi) { 35.48 + StringBuilder sb = new StringBuilder("xvI:"); 35.49 + for (Integer i : vi) { 35.50 + sb.append(i); 35.51 + sb.append("-"); 35.52 + } 35.53 + return sb.toString(); 35.54 + } 35.55 + 35.56 + default String xIvI(Integer f, Integer... vi) { 35.57 + StringBuilder sb = new StringBuilder("xIvI:"); 35.58 + sb.append(f); 35.59 + for (Integer i : vi) { 35.60 + sb.append(i); 35.61 + sb.append("-"); 35.62 + } 35.63 + return sb.toString(); 35.64 + } 35.65 + 35.66 + default String xvi(int... vi) { 35.67 + int sum = 0; 35.68 + for (int i : vi) { 35.69 + sum += i; 35.70 + } 35.71 + return "xvi:" + sum; 35.72 + } 35.73 + 35.74 + default String xIvi(Integer f, int... vi) { 35.75 + int sum = 0; 35.76 + for (int i : vi) { 35.77 + sum += i; 35.78 + } 35.79 + return "xIvi:(" + f + ")" + sum; 35.80 + } 35.81 + 35.82 + default String xvO(Object... vi) { 35.83 + StringBuilder sb = new StringBuilder("xvO:"); 35.84 + for (Object i : vi) { 35.85 + if (i.getClass().isArray()) { 35.86 + sb.append("["); 35.87 + int len = Array.getLength(i); 35.88 + for (int x = 0; x < len; ++x) { 35.89 + sb.append(Array.get(i, x)); 35.90 + sb.append(","); 35.91 + } 35.92 + sb.append("]"); 35.93 + 35.94 + } else { 35.95 + sb.append(i); 35.96 + } 35.97 + sb.append("*"); 35.98 + } 35.99 + return sb.toString(); 35.100 + } 35.101 +} 35.102 + 35.103 +@Test 35.104 +public class MethodReferenceTestVarArgsSuperDefault implements MethodReferenceTestVarArgsSuperDefault_I { 35.105 + 35.106 + interface DSPRII { String m(Integer a, Integer b); } 35.107 + 35.108 + interface DSPRiii { String m(int a, int b, int c); } 35.109 + 35.110 + interface DSPRi { String m(int a); } 35.111 + 35.112 + interface DSPRaO { String m(Object[] a); } 35.113 + 35.114 + interface DSPRai { String m(int[] a); } 35.115 + 35.116 + interface DSPRvi { String m(int... va); } 35.117 + 35.118 + // These should be processed as var args 35.119 + 35.120 + public void testVarArgsSPRSuperclass() { 35.121 + DSPRII q; 35.122 + 35.123 + q = MethodReferenceTestVarArgsSuperDefault_I.super::xvO; 35.124 + assertEquals(q.m(55,66), "xvO:55*66*"); 35.125 + } 35.126 + 35.127 + public void testVarArgsSPRArray() { 35.128 + DSPRai q; 35.129 + 35.130 + q = MethodReferenceTestVarArgsSuperDefault_I.super::xvO; 35.131 + assertEquals(q.m(new int[] { 55,66 } ), "xvO:[55,66,]*"); 35.132 + } 35.133 + 35.134 + public void testVarArgsSPRII() { 35.135 + DSPRII q; 35.136 + 35.137 + q = MethodReferenceTestVarArgsSuperDefault_I.super::xvI; 35.138 + assertEquals(q.m(33,7), "xvI:33-7-"); 35.139 + 35.140 + q = MethodReferenceTestVarArgsSuperDefault_I.super::xIvI; 35.141 + assertEquals(q.m(50,40), "xIvI:5040-"); 35.142 + 35.143 + q = MethodReferenceTestVarArgsSuperDefault_I.super::xvi; 35.144 + assertEquals(q.m(100,23), "xvi:123"); 35.145 + 35.146 + q = MethodReferenceTestVarArgsSuperDefault_I.super::xIvi; 35.147 + assertEquals(q.m(9,21), "xIvi:(9)21"); 35.148 + } 35.149 + 35.150 + public void testVarArgsSPRiii() { 35.151 + DSPRiii q; 35.152 + 35.153 + q = MethodReferenceTestVarArgsSuperDefault_I.super::xvI; 35.154 + assertEquals(q.m(3, 2, 1), "xvI:3-2-1-"); 35.155 + 35.156 + q = MethodReferenceTestVarArgsSuperDefault_I.super::xIvI; 35.157 + assertEquals(q.m(888, 99, 2), "xIvI:88899-2-"); 35.158 + 35.159 + q = MethodReferenceTestVarArgsSuperDefault_I.super::xvi; 35.160 + assertEquals(q.m(900,80,7), "xvi:987"); 35.161 + 35.162 + q = MethodReferenceTestVarArgsSuperDefault_I.super::xIvi; 35.163 + assertEquals(q.m(333,27, 72), "xIvi:(333)99"); 35.164 + } 35.165 + 35.166 + public void testVarArgsSPRi() { 35.167 + DSPRi q; 35.168 + 35.169 + q = MethodReferenceTestVarArgsSuperDefault_I.super::xvI; 35.170 + assertEquals(q.m(3), "xvI:3-"); 35.171 + 35.172 + q = MethodReferenceTestVarArgsSuperDefault_I.super::xIvI; 35.173 + assertEquals(q.m(888), "xIvI:888"); 35.174 + 35.175 + q = MethodReferenceTestVarArgsSuperDefault_I.super::xvi; 35.176 + assertEquals(q.m(900), "xvi:900"); 35.177 + 35.178 + q = MethodReferenceTestVarArgsSuperDefault_I.super::xIvi; 35.179 + assertEquals(q.m(333), "xIvi:(333)0"); 35.180 + } 35.181 + 35.182 + // These should NOT be processed as var args 35.183 + 35.184 + public void testVarArgsSPRaO() { 35.185 + DSPRaO q; 35.186 + 35.187 + q = MethodReferenceTestVarArgsSuperDefault_I.super::xvO; 35.188 + assertEquals(q.m(new String[] { "yo", "there", "dude" }), "xvO:yo*there*dude*"); 35.189 + } 35.190 + 35.191 + 35.192 +}
36.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 36.2 +++ b/test/tools/javac/lambda/methodReferenceExecution/MethodReferenceTestVarArgsThis.java Tue Nov 20 09:58:55 2012 -0800 36.3 @@ -0,0 +1,186 @@ 36.4 +/* 36.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 36.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 36.7 + * 36.8 + * This code is free software; you can redistribute it and/or modify it 36.9 + * under the terms of the GNU General Public License version 2 only, as 36.10 + * published by the Free Software Foundation. Oracle designates this 36.11 + * particular file as subject to the "Classpath" exception as provided 36.12 + * by Oracle in the LICENSE file that accompanied this code. 36.13 + * 36.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 36.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 36.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 36.17 + * version 2 for more details (a copy is included in the LICENSE file that 36.18 + * accompanied this code). 36.19 + * 36.20 + * You should have received a copy of the GNU General Public License version 36.21 + * 2 along with this work; if not, write to the Free Software Foundation, 36.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 36.23 + * 36.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 36.25 + * or visit www.oracle.com if you need additional information or have any 36.26 + * questions. 36.27 + */ 36.28 + 36.29 +/** 36.30 + * @test 36.31 + * @bug 8003639 36.32 + * @summary convert lambda testng tests to jtreg and add them 36.33 + * @run testng MethodReferenceTestVarArgsThis 36.34 + */ 36.35 + 36.36 +import org.testng.annotations.Test; 36.37 +import java.lang.reflect.Array; 36.38 + 36.39 +import static org.testng.Assert.assertEquals; 36.40 + 36.41 +/** 36.42 + * @author Robert Field 36.43 + */ 36.44 + 36.45 +interface NsII { String m(Integer a, Integer b); } 36.46 + 36.47 +interface Nsiii { String m(int a, int b, int c); } 36.48 + 36.49 +interface Nsi { String m(int a); } 36.50 + 36.51 +interface NsaO { String m(Object[] a); } 36.52 + 36.53 +interface Nsai { String m(int[] a); } 36.54 + 36.55 +interface Nsvi { String m(int... va); } 36.56 + 36.57 +@Test 36.58 +public class MethodReferenceTestVarArgsThis { 36.59 + 36.60 + // These should be processed as var args 36.61 + 36.62 + String xvI(Integer... vi) { 36.63 + StringBuilder sb = new StringBuilder("xvI:"); 36.64 + for (Integer i : vi) { 36.65 + sb.append(i); 36.66 + sb.append("-"); 36.67 + } 36.68 + return sb.toString(); 36.69 + } 36.70 + 36.71 + String xIvI(Integer f, Integer... vi) { 36.72 + StringBuilder sb = new StringBuilder("xIvI:"); 36.73 + sb.append(f); 36.74 + for (Integer i : vi) { 36.75 + sb.append(i); 36.76 + sb.append("-"); 36.77 + } 36.78 + return sb.toString(); 36.79 + } 36.80 + 36.81 + String xvi(int... vi) { 36.82 + int sum = 0; 36.83 + for (int i : vi) { 36.84 + sum += i; 36.85 + } 36.86 + return "xvi:" + sum; 36.87 + } 36.88 + 36.89 + String xIvi(Integer f, int... vi) { 36.90 + int sum = 0; 36.91 + for (int i : vi) { 36.92 + sum += i; 36.93 + } 36.94 + return "xIvi:(" + f + ")" + sum; 36.95 + } 36.96 + 36.97 + String xvO(Object... vi) { 36.98 + StringBuilder sb = new StringBuilder("xvO:"); 36.99 + for (Object i : vi) { 36.100 + if (i.getClass().isArray()) { 36.101 + sb.append("["); 36.102 + int len = Array.getLength(i); 36.103 + for (int x = 0; x < len; ++x) { 36.104 + sb.append(Array.get(i, x)); 36.105 + sb.append(","); 36.106 + } 36.107 + sb.append("]"); 36.108 + 36.109 + } else { 36.110 + sb.append(i); 36.111 + } 36.112 + sb.append("*"); 36.113 + } 36.114 + return sb.toString(); 36.115 + } 36.116 + 36.117 + public void testVarArgsNsSuperclass() { 36.118 + NsII q; 36.119 + 36.120 + q = this::xvO; 36.121 + assertEquals(q.m(55,66), "xvO:55*66*"); 36.122 + } 36.123 + 36.124 + public void testVarArgsNsArray() { 36.125 + Nsai q; 36.126 + 36.127 + q = this::xvO; 36.128 + assertEquals(q.m(new int[] { 55,66 } ), "xvO:[55,66,]*"); 36.129 + } 36.130 + 36.131 + public void testVarArgsNsII() { 36.132 + NsII q; 36.133 + 36.134 + q = this::xvI; 36.135 + assertEquals(q.m(33,7), "xvI:33-7-"); 36.136 + 36.137 + q = this::xIvI; 36.138 + assertEquals(q.m(50,40), "xIvI:5040-"); 36.139 + 36.140 + q = this::xvi; 36.141 + assertEquals(q.m(100,23), "xvi:123"); 36.142 + 36.143 + q = this::xIvi; 36.144 + assertEquals(q.m(9,21), "xIvi:(9)21"); 36.145 + } 36.146 + 36.147 + public void testVarArgsNsiii() { 36.148 + Nsiii q; 36.149 + 36.150 + q = this::xvI; 36.151 + assertEquals(q.m(3, 2, 1), "xvI:3-2-1-"); 36.152 + 36.153 + q = this::xIvI; 36.154 + assertEquals(q.m(888, 99, 2), "xIvI:88899-2-"); 36.155 + 36.156 + q = this::xvi; 36.157 + assertEquals(q.m(900,80,7), "xvi:987"); 36.158 + 36.159 + q = this::xIvi; 36.160 + assertEquals(q.m(333,27, 72), "xIvi:(333)99"); 36.161 + } 36.162 + 36.163 + public void testVarArgsNsi() { 36.164 + Nsi q; 36.165 + 36.166 + q = this::xvI; 36.167 + assertEquals(q.m(3), "xvI:3-"); 36.168 + 36.169 + q = this::xIvI; 36.170 + assertEquals(q.m(888), "xIvI:888"); 36.171 + 36.172 + q = this::xvi; 36.173 + assertEquals(q.m(900), "xvi:900"); 36.174 + 36.175 + q = this::xIvi; 36.176 + assertEquals(q.m(333), "xIvi:(333)0"); 36.177 + } 36.178 + 36.179 + // These should NOT be processed as var args 36.180 + 36.181 + public void testVarArgsNsaO() { 36.182 + NsaO q; 36.183 + 36.184 + q = this::xvO; 36.185 + assertEquals(q.m(new String[] { "yo", "there", "dude" }), "xvO:yo*there*dude*"); 36.186 + } 36.187 + 36.188 + 36.189 +}
37.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 37.2 +++ b/test/tools/javac/lambdaShapes/TEST.properties Tue Nov 20 09:58:55 2012 -0800 37.3 @@ -0,0 +1,2 @@ 37.4 +TestNG.dirs = tools/javac/lambdaShapes 37.5 +
38.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 38.2 +++ b/test/tools/javac/lambdaShapes/org/openjdk/tests/javac/FDTest.java Tue Nov 20 09:58:55 2012 -0800 38.3 @@ -0,0 +1,193 @@ 38.4 +/* 38.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 38.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 38.7 + * 38.8 + * This code is free software; you can redistribute it and/or modify it 38.9 + * under the terms of the GNU General Public License version 2 only, as 38.10 + * published by the Free Software Foundation. 38.11 + * 38.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 38.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 38.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 38.15 + * version 2 for more details (a copy is included in the LICENSE file that 38.16 + * accompanied this code). 38.17 + * 38.18 + * You should have received a copy of the GNU General Public License version 38.19 + * 2 along with this work; if not, write to the Free Software Foundation, 38.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 38.21 + * 38.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 38.23 + * or visit www.oracle.com if you need additional information or have any 38.24 + * questions. 38.25 + */ 38.26 + 38.27 +package org.openjdk.tests.javac; 38.28 + 38.29 +import org.openjdk.tests.shapegen.*; 38.30 + 38.31 +import com.sun.source.util.JavacTask; 38.32 +import com.sun.tools.javac.util.Pair; 38.33 + 38.34 +import java.net.URI; 38.35 +import java.util.Arrays; 38.36 +import java.util.ArrayList; 38.37 +import java.util.Collection; 38.38 +import java.util.List; 38.39 + 38.40 +import javax.tools.Diagnostic; 38.41 +import javax.tools.JavaCompiler; 38.42 +import javax.tools.JavaFileObject; 38.43 +import javax.tools.SimpleJavaFileObject; 38.44 +import javax.tools.StandardJavaFileManager; 38.45 +import javax.tools.ToolProvider; 38.46 + 38.47 +import org.testng.annotations.Test; 38.48 +import org.testng.annotations.BeforeSuite; 38.49 +import org.testng.annotations.DataProvider; 38.50 +import static org.testng.Assert.*; 38.51 + 38.52 +public class FDTest { 38.53 + 38.54 + public enum TestKind { 38.55 + POSITIVE, 38.56 + NEGATIVE; 38.57 + 38.58 + Collection<Hierarchy> getHierarchy(HierarchyGenerator hg) { 38.59 + return this == POSITIVE ? 38.60 + hg.getOK() : hg.getErr(); 38.61 + } 38.62 + } 38.63 + 38.64 + public static JavaCompiler comp; 38.65 + public static StandardJavaFileManager fm; 38.66 + 38.67 + @BeforeSuite 38.68 + static void init() { 38.69 + // create default shared JavaCompiler - reused across multiple 38.70 + // compilations 38.71 + 38.72 + comp = ToolProvider.getSystemJavaCompiler(); 38.73 + fm = comp.getStandardFileManager(null, null, null); 38.74 + } 38.75 + 38.76 + public static void main(String[] args) throws Exception { 38.77 + init(); 38.78 + 38.79 + for (Pair<TestKind,Hierarchy> fdtest : generateCases()) { 38.80 + runTest(fdtest.fst, fdtest.snd, comp, fm); 38.81 + } 38.82 + } 38.83 + 38.84 + @Test(dataProvider = "fdCases") 38.85 + public void testOneCase(TestKind tk, Hierarchy hs) 38.86 + throws Exception { 38.87 + FDTest.runTest(tk, hs, comp, fm); 38.88 + } 38.89 + 38.90 + @DataProvider(name = "fdCases") 38.91 + public Object[][] caseGenerator() { 38.92 + List<Pair<TestKind, Hierarchy>> cases = generateCases(); 38.93 + Object[][] fdCases = new Object[cases.size()][]; 38.94 + for (int i = 0; i < cases.size(); ++i) { 38.95 + fdCases[i] = new Object[2]; 38.96 + fdCases[i][0] = cases.get(i).fst; 38.97 + fdCases[i][1] = cases.get(i).snd; 38.98 + } 38.99 + return fdCases; 38.100 + } 38.101 + 38.102 + public static List<Pair<TestKind, Hierarchy>> generateCases() { 38.103 + ArrayList<Pair<TestKind,Hierarchy>> list = new ArrayList<>(); 38.104 + HierarchyGenerator hg = new HierarchyGenerator(); 38.105 + for (TestKind tk : TestKind.values()) { 38.106 + for (Hierarchy hs : tk.getHierarchy(hg)) { 38.107 + list.add(new Pair<>(tk, hs)); 38.108 + } 38.109 + } 38.110 + return list; 38.111 + } 38.112 + 38.113 + public static void runTest(TestKind tk, Hierarchy hs, 38.114 + JavaCompiler comp, StandardJavaFileManager fm) throws Exception { 38.115 + new FDTest(tk, hs).run(comp, fm); 38.116 + } 38.117 + 38.118 + TestKind tk; 38.119 + Hierarchy hs; 38.120 + DefenderTestSource source; 38.121 + DiagnosticChecker diagChecker; 38.122 + 38.123 + public FDTest() {} 38.124 + 38.125 + FDTest(TestKind tk, Hierarchy hs) { 38.126 + this.tk = tk; 38.127 + this.hs = hs; 38.128 + this.source = new DefenderTestSource(); 38.129 + this.diagChecker = new DiagnosticChecker(); 38.130 + } 38.131 + 38.132 + void run(JavaCompiler tool, StandardJavaFileManager fm) throws Exception { 38.133 + JavacTask ct = (JavacTask)tool.getTask(null, fm, diagChecker, 38.134 + null, null, Arrays.asList(source)); 38.135 + try { 38.136 + ct.analyze(); 38.137 + } catch (Throwable ex) { 38.138 + fail("Error thrown when analyzing the following source:\n" + source.getCharContent(true)); 38.139 + } 38.140 + check(); 38.141 + } 38.142 + 38.143 + void check() { 38.144 + boolean errorExpected = tk == TestKind.NEGATIVE; 38.145 + if (errorExpected != diagChecker.errorFound) { 38.146 + fail("problem in source: \n" + 38.147 + "\nerror found = " + diagChecker.errorFound + 38.148 + "\nerror expected = " + errorExpected + 38.149 + "\n" + dumpHierarchy() + 38.150 + "\n" + source.getCharContent(true)); 38.151 + } 38.152 + } 38.153 + 38.154 + String dumpHierarchy() { 38.155 + StringBuilder buf = new StringBuilder(); 38.156 + buf.append("root = " + hs.root + "\n"); 38.157 + for (ClassCase cc : hs.all) { 38.158 + buf.append(" class name = " + cc.getName() + "\n"); 38.159 + buf.append(" class OK = " + cc.get_OK() + "\n"); 38.160 + buf.append(" prov = " + cc.get_mprov() + "\n"); 38.161 + 38.162 + } 38.163 + return buf.toString(); 38.164 + } 38.165 + 38.166 + class DefenderTestSource extends SimpleJavaFileObject { 38.167 + 38.168 + String source; 38.169 + 38.170 + public DefenderTestSource() { 38.171 + super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE); 38.172 + StringBuilder buf = new StringBuilder(); 38.173 + List<ClassCase> defaultRef = new ArrayList<>(); 38.174 + for (ClassCase cc : hs.all) { 38.175 + Hierarchy.genClassDef(buf, cc, null, defaultRef); 38.176 + } 38.177 + source = buf.toString(); 38.178 + } 38.179 + 38.180 + @Override 38.181 + public CharSequence getCharContent(boolean ignoreEncodingErrors) { 38.182 + return source; 38.183 + } 38.184 + } 38.185 + 38.186 + static class DiagnosticChecker implements javax.tools.DiagnosticListener<JavaFileObject> { 38.187 + 38.188 + boolean errorFound; 38.189 + 38.190 + public void report(Diagnostic<? extends JavaFileObject> diagnostic) { 38.191 + if (diagnostic.getKind() == Diagnostic.Kind.ERROR) { 38.192 + errorFound = true; 38.193 + } 38.194 + } 38.195 + } 38.196 +}
39.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 39.2 +++ b/test/tools/javac/lambdaShapes/org/openjdk/tests/separate/AttributeInjector.java Tue Nov 20 09:58:55 2012 -0800 39.3 @@ -0,0 +1,73 @@ 39.4 +/* 39.5 + * Copyright (c) 2012 Oracle and/or its affiliates. All rights reserved. 39.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 39.7 + * 39.8 + * This code is free software; you can redistribute it and/or modify it 39.9 + * under the terms of the GNU General Public License version 2 only, as 39.10 + * published by the Free Software Foundation. Oracle designates this 39.11 + * particular file as subject to the "Classpath" exception as provided 39.12 + * by Oracle in the LICENSE file that accompanied this code. 39.13 + * 39.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 39.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 39.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 39.17 + * version 2 for more details (a copy is included in the LICENSE file that 39.18 + * accompanied this code). 39.19 + * 39.20 + * You should have received a copy of the GNU General Public License version 39.21 + * 2 along with this work; if not, write to the Free Software Foundation, 39.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 39.23 + * 39.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 39.25 + * or visit www.oracle.com if you need additional information or have any 39.26 + * questions. 39.27 + */ 39.28 + 39.29 +package org.openjdk.tests.separate; 39.30 + 39.31 +import java.io.*; 39.32 + 39.33 +public class AttributeInjector implements ClassFilePreprocessor { 39.34 + 39.35 + private String attributeName; 39.36 + private byte[] attributeData; 39.37 + 39.38 + public AttributeInjector(String attributeName, byte[] attributeData) { 39.39 + this.attributeName = attributeName; 39.40 + this.attributeData = attributeData; 39.41 + } 39.42 + 39.43 + public byte[] preprocess(String name, byte[] cf) { 39.44 + ClassFile classfile = new ClassFile(cf); 39.45 + 39.46 + short cpIndex = (short)classfile.constant_pool.size(); 39.47 + 39.48 + ClassFile.CpUtf8 entry = new ClassFile.CpUtf8(); 39.49 + entry.bytes = new byte[attributeName.length()]; 39.50 + for (int i = 0; i < attributeName.length(); ++i) { 39.51 + entry.bytes[i] = (byte)attributeName.charAt(i); 39.52 + } 39.53 + 39.54 + classfile.constant_pool.add(entry); 39.55 + 39.56 + ClassFile.Attribute attr = new ClassFile.Attribute(); 39.57 + attr.attribute_name_index = cpIndex; 39.58 + attr.info = attributeData; 39.59 + 39.60 + classfile.attributes.add(attr); 39.61 + return classfile.toByteArray(); 39.62 + } 39.63 + 39.64 +/* 39.65 + public static void main(String argv[]) throws Exception { 39.66 + File input = new File(argv[0]); 39.67 + byte[] buffer = new byte[(int)input.length()]; 39.68 + new FileInputStream(input).read(buffer); 39.69 + 39.70 + ClassFilePreprocessor cfp = 39.71 + new AttributeInjector("RequiresBridges", new byte[0]); 39.72 + byte[] cf = cfp.preprocess(argv[0], buffer); 39.73 + new FileOutputStream(argv[0] + ".mod").write(cf); 39.74 + } 39.75 +*/ 39.76 +}
40.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 40.2 +++ b/test/tools/javac/lambdaShapes/org/openjdk/tests/separate/ClassFile.java Tue Nov 20 09:58:55 2012 -0800 40.3 @@ -0,0 +1,454 @@ 40.4 +/* 40.5 + * Copyright (c) 2012 Oracle and/or its affiliates. All rights reserved. 40.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 40.7 + * 40.8 + * This code is free software; you can redistribute it and/or modify it 40.9 + * under the terms of the GNU General Public License version 2 only, as 40.10 + * published by the Free Software Foundation. Oracle designates this 40.11 + * particular file as subject to the "Classpath" exception as provided 40.12 + * by Oracle in the LICENSE file that accompanied this code. 40.13 + * 40.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 40.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 40.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 40.17 + * version 2 for more details (a copy is included in the LICENSE file that 40.18 + * accompanied this code). 40.19 + * 40.20 + * You should have received a copy of the GNU General Public License version 40.21 + * 2 along with this work; if not, write to the Free Software Foundation, 40.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 40.23 + * 40.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 40.25 + * or visit www.oracle.com if you need additional information or have any 40.26 + * questions. 40.27 + */ 40.28 + 40.29 +package org.openjdk.tests.separate; 40.30 + 40.31 +import java.io.*; 40.32 +import java.util.*; 40.33 + 40.34 +class CfInputStream extends ByteArrayInputStream { 40.35 + private int ct; 40.36 + public CfInputStream(byte[] input) { 40.37 + super(input); 40.38 + } 40.39 + 40.40 + byte u1() { return (byte)read(); } 40.41 + short u2() { 40.42 + int b0 = read() << 8; 40.43 + int b1 = read(); 40.44 + return (short)(b0 | b1); 40.45 + } 40.46 + int u4() { 40.47 + int b0 = read() << 24; 40.48 + int b1 = read() << 16; 40.49 + int b2 = read() << 8; 40.50 + int b3 = read(); 40.51 + return b0 | b1 | b2 | b3; 40.52 + } 40.53 + byte[] array(int count) { 40.54 + byte[] ret = new byte[count]; 40.55 + read(ret, 0, count); 40.56 + return ret; 40.57 + } 40.58 +}; 40.59 + 40.60 +class CfOutputStream extends ByteArrayOutputStream { 40.61 + void u1(byte b) { write((int)b); } 40.62 + void u2(short s) { 40.63 + write((s >> 8) & 0xff); 40.64 + write(s & 0xff); 40.65 + } 40.66 + void u4(int i) { 40.67 + write((i >> 24) & 0xff); 40.68 + write((i >> 16) & 0xff); 40.69 + write((i >> 8) & 0xff); 40.70 + write(i & 0xff); 40.71 + } 40.72 + void array(byte[] a) { 40.73 + write(a, 0, a.length); 40.74 + } 40.75 + 40.76 + public byte[] toByteArray() { return super.toByteArray(); } 40.77 +}; 40.78 + 40.79 +// A quick and dirty class file parser and representation 40.80 +public class ClassFile { 40.81 + 40.82 + int magic; 40.83 + short minor_version; 40.84 + short major_version; 40.85 + ArrayList<CpEntry> constant_pool; 40.86 + short access_flags; 40.87 + short this_class; 40.88 + short super_class; 40.89 + ArrayList<Interface> interfaces; 40.90 + ArrayList<Field> fields; 40.91 + ArrayList<Method> methods; 40.92 + ArrayList<Attribute> attributes; 40.93 + 40.94 + ClassFile(byte[] cf) { 40.95 + CfInputStream in = new CfInputStream(cf); 40.96 + 40.97 + magic = in.u4(); 40.98 + minor_version = in.u2(); 40.99 + major_version = in.u2(); 40.100 + 40.101 + short cpCount = in.u2(); 40.102 + constant_pool = new ArrayList<>(); 40.103 + constant_pool.add(new CpNull()); 40.104 + for (int i = 1; i < cpCount; ++i) { 40.105 + constant_pool.add(CpEntry.newCpEntry(in)); 40.106 + } 40.107 + 40.108 + access_flags = in.u2(); 40.109 + this_class = in.u2(); 40.110 + super_class = in.u2(); 40.111 + 40.112 + short ifaceCount = in.u2(); 40.113 + interfaces = new ArrayList<>(); 40.114 + for (int i = 0; i < ifaceCount; ++i) { 40.115 + interfaces.add(new Interface(in)); 40.116 + } 40.117 + 40.118 + short fieldCount = in.u2(); 40.119 + fields = new ArrayList<>(); 40.120 + for (int i = 0; i < fieldCount; ++i) { 40.121 + fields.add(new Field(in)); 40.122 + } 40.123 + 40.124 + short methodCount = in.u2(); 40.125 + methods = new ArrayList<>(); 40.126 + for (int i = 0; i < methodCount; ++i) { 40.127 + methods.add(new Method(in)); 40.128 + } 40.129 + 40.130 + short attributeCount = in.u2(); 40.131 + attributes = new ArrayList<>(); 40.132 + for (int i = 0; i < attributeCount; ++i) { 40.133 + attributes.add(new Attribute(in)); 40.134 + } 40.135 + } 40.136 + 40.137 + byte[] toByteArray() { 40.138 + CfOutputStream out = new CfOutputStream(); 40.139 + 40.140 + out.u4(magic); 40.141 + out.u2(minor_version); 40.142 + out.u2(major_version); 40.143 + 40.144 + out.u2((short)(constant_pool.size())); 40.145 + for (CpEntry cp : constant_pool) { 40.146 + cp.write(out); 40.147 + } 40.148 + 40.149 + out.u2(access_flags); 40.150 + out.u2(this_class); 40.151 + out.u2(super_class); 40.152 + 40.153 + out.u2((short)interfaces.size()); 40.154 + for (Interface iface : interfaces) { 40.155 + iface.write(out); 40.156 + } 40.157 + 40.158 + out.u2((short)fields.size()); 40.159 + for (Field field : fields) { 40.160 + field.write(out); 40.161 + } 40.162 + 40.163 + out.u2((short)methods.size()); 40.164 + for (Method method : methods) { 40.165 + method.write(out); 40.166 + } 40.167 + 40.168 + out.u2((short)attributes.size()); 40.169 + for (Attribute attribute : attributes) { 40.170 + attribute.write(out); 40.171 + } 40.172 + 40.173 + return out.toByteArray(); 40.174 + } 40.175 + 40.176 + static abstract class CpEntry { 40.177 + byte tag; 40.178 + 40.179 + CpEntry(byte t) { tag = t; } 40.180 + void write(CfOutputStream out) { 40.181 + out.u1(tag); 40.182 + } 40.183 + 40.184 + static CpEntry newCpEntry(CfInputStream in) { 40.185 + byte tag = in.u1(); 40.186 + switch (tag) { 40.187 + case CpUtf8.TAG: return new CpUtf8(in); 40.188 + case CpInteger.TAG: return new CpInteger(in); 40.189 + case CpFloat.TAG: return new CpFloat(in); 40.190 + case CpLong.TAG: return new CpLong(in); 40.191 + case CpDouble.TAG: return new CpDouble(in); 40.192 + case CpClass.TAG: return new CpClass(in); 40.193 + case CpString.TAG: return new CpString(in); 40.194 + case CpFieldRef.TAG: return new CpFieldRef(in); 40.195 + case CpMethodRef.TAG: return new CpMethodRef(in); 40.196 + case CpInterfaceMethodRef.TAG: 40.197 + return new CpInterfaceMethodRef(in); 40.198 + case CpNameAndType.TAG: return new CpNameAndType(in); 40.199 + case CpMethodHandle.TAG: return new CpMethodHandle(in); 40.200 + case CpMethodType.TAG: return new CpMethodType(in); 40.201 + case CpInvokeDynamic.TAG: return new CpInvokeDynamic(in); 40.202 + default: throw new RuntimeException("Bad cp entry tag: " + tag); 40.203 + } 40.204 + } 40.205 + } 40.206 + 40.207 + static class CpNull extends CpEntry { 40.208 + CpNull() { super((byte)0); } 40.209 + CpNull(CfInputStream in) { super((byte)0); } 40.210 + void write(CfOutputStream out) {} 40.211 + } 40.212 + 40.213 + static class CpUtf8 extends CpEntry { 40.214 + static final byte TAG = 1; 40.215 + byte[] bytes; 40.216 + 40.217 + CpUtf8() { super(TAG); } 40.218 + CpUtf8(CfInputStream in) { 40.219 + this(); 40.220 + short length = in.u2(); 40.221 + bytes = in.array(length); 40.222 + } 40.223 + void write(CfOutputStream out) { 40.224 + super.write(out); 40.225 + out.u2((short)bytes.length); 40.226 + out.array(bytes); 40.227 + } 40.228 + } 40.229 + 40.230 + static class CpU4Constant extends CpEntry { 40.231 + byte[] bytes; 40.232 + 40.233 + CpU4Constant(byte tag) { super(tag); } 40.234 + CpU4Constant(byte tag, CfInputStream in) { 40.235 + this(tag); 40.236 + bytes = in.array(4); 40.237 + } 40.238 + void write(CfOutputStream out) { super.write(out); out.array(bytes); } 40.239 + } 40.240 + static class CpInteger extends CpU4Constant { 40.241 + static final byte TAG = 3; 40.242 + CpInteger() { super(TAG); } 40.243 + CpInteger(CfInputStream in) { super(TAG, in); } 40.244 + } 40.245 + static class CpFloat extends CpU4Constant { 40.246 + static final byte TAG = 4; 40.247 + CpFloat() { super(TAG); } 40.248 + CpFloat(CfInputStream in) { super(TAG, in); } 40.249 + } 40.250 + 40.251 + static class CpU8Constant extends CpEntry { 40.252 + byte[] bytes; 40.253 + 40.254 + CpU8Constant(byte tag) { super(tag); } 40.255 + CpU8Constant(byte tag, CfInputStream in) { 40.256 + this(tag); 40.257 + bytes = in.array(8); 40.258 + } 40.259 + void write(CfOutputStream out) { super.write(out); out.array(bytes); } 40.260 + } 40.261 + static class CpLong extends CpU8Constant { 40.262 + static final byte TAG = 5; 40.263 + CpLong() { super(TAG); } 40.264 + CpLong(CfInputStream in) { super(TAG, in); } 40.265 + } 40.266 + static class CpDouble extends CpU8Constant { 40.267 + static final byte TAG = 6; 40.268 + CpDouble() { super(TAG); } 40.269 + CpDouble(CfInputStream in) { super(TAG, in); } 40.270 + } 40.271 + 40.272 + static class CpClass extends CpEntry { 40.273 + static final byte TAG = 7; 40.274 + short name_index; 40.275 + 40.276 + CpClass() { super(TAG); } 40.277 + CpClass(CfInputStream in) { super(TAG); name_index = in.u2(); } 40.278 + void write(CfOutputStream out) { 40.279 + super.write(out); 40.280 + out.u2(name_index); 40.281 + } 40.282 + } 40.283 + 40.284 + static class CpString extends CpEntry { 40.285 + static final byte TAG = 8; 40.286 + short string_index; 40.287 + 40.288 + CpString() { super(TAG); } 40.289 + CpString(CfInputStream in) { super(TAG); string_index = in.u2(); } 40.290 + void write(CfOutputStream out) { 40.291 + super.write(out); 40.292 + out.u2(string_index); 40.293 + } 40.294 + } 40.295 + 40.296 + static class CpRef extends CpEntry { 40.297 + short class_index; 40.298 + short name_and_type_index; 40.299 + 40.300 + CpRef(byte tag) { super(tag); } 40.301 + CpRef(byte tag, CfInputStream in) { 40.302 + this(tag); 40.303 + class_index = in.u2(); 40.304 + name_and_type_index = in.u2(); 40.305 + } 40.306 + void write(CfOutputStream out) { 40.307 + super.write(out); 40.308 + out.u2(class_index); 40.309 + out.u2(name_and_type_index); 40.310 + } 40.311 + } 40.312 + static class CpFieldRef extends CpRef { 40.313 + static final byte TAG = 9; 40.314 + CpFieldRef() { super(TAG); } 40.315 + CpFieldRef(CfInputStream in) { super(TAG, in); } 40.316 + } 40.317 + static class CpMethodRef extends CpRef { 40.318 + static final byte TAG = 10; 40.319 + CpMethodRef() { super(TAG); } 40.320 + CpMethodRef(CfInputStream in) { super(TAG, in); } 40.321 + } 40.322 + static class CpInterfaceMethodRef extends CpRef { 40.323 + static final byte TAG = 11; 40.324 + CpInterfaceMethodRef() { super(TAG); } 40.325 + CpInterfaceMethodRef(CfInputStream in) { super(TAG, in); } 40.326 + } 40.327 + 40.328 + static class CpNameAndType extends CpEntry { 40.329 + static final byte TAG = 12; 40.330 + short name_index; 40.331 + short descriptor_index; 40.332 + 40.333 + CpNameAndType() { super(TAG); } 40.334 + CpNameAndType(CfInputStream in) { 40.335 + this(); 40.336 + name_index = in.u2(); 40.337 + descriptor_index = in.u2(); 40.338 + } 40.339 + void write(CfOutputStream out) { 40.340 + super.write(out); 40.341 + out.u2(name_index); 40.342 + out.u2(descriptor_index); 40.343 + } 40.344 + } 40.345 + 40.346 + static class CpMethodHandle extends CpEntry { 40.347 + static final byte TAG = 15; 40.348 + byte reference_kind; 40.349 + short reference_index; 40.350 + 40.351 + CpMethodHandle() { super(TAG); } 40.352 + CpMethodHandle(CfInputStream in) { 40.353 + this(); 40.354 + reference_kind = in.u1(); 40.355 + reference_index = in.u2(); 40.356 + } 40.357 + void write(CfOutputStream out) { 40.358 + super.write(out); 40.359 + out.u1(reference_kind); 40.360 + out.u2(reference_index); 40.361 + } 40.362 + } 40.363 + 40.364 + static class CpMethodType extends CpEntry { 40.365 + static final byte TAG = 16; 40.366 + short descriptor_index; 40.367 + 40.368 + CpMethodType() { super(TAG); } 40.369 + CpMethodType(CfInputStream in) { 40.370 + this(); 40.371 + descriptor_index = in.u2(); 40.372 + } 40.373 + void write(CfOutputStream out) { 40.374 + super.write(out); 40.375 + out.u2(descriptor_index); 40.376 + } 40.377 + } 40.378 + 40.379 + static class CpInvokeDynamic extends CpEntry { 40.380 + static final byte TAG = 18; 40.381 + short bootstrap_index; 40.382 + short name_and_type_index; 40.383 + 40.384 + CpInvokeDynamic() { super(TAG); } 40.385 + CpInvokeDynamic(CfInputStream in) { 40.386 + this(); 40.387 + bootstrap_index = in.u2(); 40.388 + name_and_type_index = in.u2(); 40.389 + } 40.390 + void write(CfOutputStream out) { 40.391 + super.write(out); 40.392 + out.u2(bootstrap_index); 40.393 + out.u2(name_and_type_index); 40.394 + } 40.395 + } 40.396 + 40.397 + static class Interface { 40.398 + short index; 40.399 + 40.400 + Interface() {} 40.401 + Interface(CfInputStream in) { index = in.u2(); } 40.402 + void write(CfOutputStream out) { out.u2(index); } 40.403 + } 40.404 + 40.405 + static class FieldOrMethod { 40.406 + short access_flags; 40.407 + short name_index; 40.408 + short descriptor_index; 40.409 + ArrayList<Attribute> attributes; 40.410 + 40.411 + FieldOrMethod() { attributes = new ArrayList<>(); } 40.412 + FieldOrMethod(CfInputStream in) { 40.413 + access_flags = in.u2(); 40.414 + name_index = in.u2(); 40.415 + descriptor_index = in.u2(); 40.416 + 40.417 + short attrCount = in.u2(); 40.418 + attributes = new ArrayList<>(); 40.419 + for (int i = 0; i < attrCount; ++i) { 40.420 + attributes.add(new Attribute(in)); 40.421 + } 40.422 + } 40.423 + void write(CfOutputStream out) { 40.424 + out.u2(access_flags); 40.425 + out.u2(name_index); 40.426 + out.u2(descriptor_index); 40.427 + out.u2((short)attributes.size()); 40.428 + for (Attribute attribute : attributes) { attribute.write(out); } 40.429 + } 40.430 + } 40.431 + 40.432 + static class Field extends FieldOrMethod { 40.433 + Field() {} 40.434 + Field(CfInputStream in) { super(in); } 40.435 + } 40.436 + static class Method extends FieldOrMethod { 40.437 + Method() {} 40.438 + Method(CfInputStream in) { super(in); } 40.439 + } 40.440 + 40.441 + static class Attribute { 40.442 + short attribute_name_index; 40.443 + byte[] info; 40.444 + 40.445 + Attribute() { info = new byte[0]; } 40.446 + Attribute(CfInputStream in) { 40.447 + attribute_name_index = in.u2(); 40.448 + int length = in.u4(); 40.449 + info = in.array(length); 40.450 + } 40.451 + void write(CfOutputStream out) { 40.452 + out.u2(attribute_name_index); 40.453 + out.u4(info.length); 40.454 + out.array(info); 40.455 + } 40.456 + } 40.457 +}
41.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 41.2 +++ b/test/tools/javac/lambdaShapes/org/openjdk/tests/separate/ClassFilePreprocessor.java Tue Nov 20 09:58:55 2012 -0800 41.3 @@ -0,0 +1,30 @@ 41.4 +/* 41.5 + * Copyright (c) 2012 Oracle and/or its affiliates. All rights reserved. 41.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 41.7 + * 41.8 + * This code is free software; you can redistribute it and/or modify it 41.9 + * under the terms of the GNU General Public License version 2 only, as 41.10 + * published by the Free Software Foundation. Oracle designates this 41.11 + * particular file as subject to the "Classpath" exception as provided 41.12 + * by Oracle in the LICENSE file that accompanied this code. 41.13 + * 41.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 41.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 41.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 41.17 + * version 2 for more details (a copy is included in the LICENSE file that 41.18 + * accompanied this code). 41.19 + * 41.20 + * You should have received a copy of the GNU General Public License version 41.21 + * 2 along with this work; if not, write to the Free Software Foundation, 41.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 41.23 + * 41.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 41.25 + * or visit www.oracle.com if you need additional information or have any 41.26 + * questions. 41.27 + */ 41.28 + 41.29 +package org.openjdk.tests.separate; 41.30 + 41.31 +public interface ClassFilePreprocessor { 41.32 + public byte[] preprocess(String name, byte[] classfile); 41.33 +};
42.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 42.2 +++ b/test/tools/javac/lambdaShapes/org/openjdk/tests/separate/ClassToInterfaceConverter.java Tue Nov 20 09:58:55 2012 -0800 42.3 @@ -0,0 +1,94 @@ 42.4 +/* 42.5 + * Copyright (c) 2012 Oracle and/or its affiliates. All rights reserved. 42.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 42.7 + * 42.8 + * This code is free software; you can redistribute it and/or modify it 42.9 + * under the terms of the GNU General Public License version 2 only, as 42.10 + * published by the Free Software Foundation. Oracle designates this 42.11 + * particular file as subject to the "Classpath" exception as provided 42.12 + * by Oracle in the LICENSE file that accompanied this code. 42.13 + * 42.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 42.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 42.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 42.17 + * version 2 for more details (a copy is included in the LICENSE file that 42.18 + * accompanied this code). 42.19 + * 42.20 + * You should have received a copy of the GNU General Public License version 42.21 + * 2 along with this work; if not, write to the Free Software Foundation, 42.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 42.23 + * 42.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 42.25 + * or visit www.oracle.com if you need additional information or have any 42.26 + * questions. 42.27 + */ 42.28 + 42.29 +package org.openjdk.tests.separate; 42.30 + 42.31 +import java.io.*; 42.32 +import java.util.*; 42.33 + 42.34 +public class ClassToInterfaceConverter implements ClassFilePreprocessor { 42.35 + 42.36 + private String whichClass; 42.37 + 42.38 + public ClassToInterfaceConverter(String className) { 42.39 + this.whichClass = className; 42.40 + } 42.41 + 42.42 + private boolean utf8Matches(ClassFile.CpEntry entry, String v) { 42.43 + if (!(entry instanceof ClassFile.CpUtf8)) { 42.44 + return false; 42.45 + } 42.46 + ClassFile.CpUtf8 utf8 = (ClassFile.CpUtf8)entry; 42.47 + if (v.length() != utf8.bytes.length) { 42.48 + return false; 42.49 + } 42.50 + for (int i = 0; i < v.length(); ++i) { 42.51 + if (v.charAt(i) != utf8.bytes[i]) { 42.52 + return false; 42.53 + } 42.54 + } 42.55 + return true; 42.56 + } 42.57 + 42.58 + private void convertToInterface(ClassFile cf) { 42.59 + cf.access_flags = 0x0601; // ACC_INTERFACE | ACC_ABSTRACT | ACC_PUBLIC 42.60 + ArrayList<ClassFile.Method> new_methods = new ArrayList<>(); 42.61 + // Find <init> method and delete it 42.62 + for (int i = 0; i < cf.methods.size(); ++i) { 42.63 + ClassFile.Method method = cf.methods.get(i); 42.64 + ClassFile.CpEntry name = cf.constant_pool.get(method.name_index); 42.65 + if (!utf8Matches(name, "<init>")) { 42.66 + new_methods.add(method); 42.67 + } 42.68 + } 42.69 + cf.methods = new_methods; 42.70 + } 42.71 + 42.72 + public byte[] preprocess(String classname, byte[] bytes) { 42.73 + ClassFile cf = new ClassFile(bytes); 42.74 + 42.75 + ClassFile.CpEntry entry = cf.constant_pool.get(cf.this_class); 42.76 + ClassFile.CpEntry name = cf.constant_pool.get( 42.77 + ((ClassFile.CpClass)entry).name_index); 42.78 + if (utf8Matches(name, whichClass)) { 42.79 + convertToInterface(cf); 42.80 + return cf.toByteArray(); 42.81 + } else { 42.82 + return bytes; // unmodified 42.83 + } 42.84 + } 42.85 + 42.86 +/* 42.87 + public static void main(String argv[]) throws Exception { 42.88 + File input = new File(argv[0]); 42.89 + byte[] buffer = new byte[(int)input.length()]; 42.90 + new FileInputStream(input).read(buffer); 42.91 + 42.92 + ClassFilePreprocessor cfp = new ClassToInterfaceConverter("Hello"); 42.93 + byte[] cf = cfp.preprocess(argv[0], buffer); 42.94 + new FileOutputStream(argv[0] + ".mod").write(cf); 42.95 + } 42.96 +*/ 42.97 +}
43.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 43.2 +++ b/test/tools/javac/lambdaShapes/org/openjdk/tests/separate/Compiler.java Tue Nov 20 09:58:55 2012 -0800 43.3 @@ -0,0 +1,232 @@ 43.4 +/* 43.5 + * Copyright (c) 2012 Oracle and/or its affiliates. All rights reserved. 43.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 43.7 + * 43.8 + * This code is free software; you can redistribute it and/or modify it 43.9 + * under the terms of the GNU General Public License version 2 only, as 43.10 + * published by the Free Software Foundation. Oracle designates this 43.11 + * particular file as subject to the "Classpath" exception as provided 43.12 + * by Oracle in the LICENSE file that accompanied this code. 43.13 + * 43.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 43.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 43.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 43.17 + * version 2 for more details (a copy is included in the LICENSE file that 43.18 + * accompanied this code). 43.19 + * 43.20 + * You should have received a copy of the GNU General Public License version 43.21 + * 2 along with this work; if not, write to the Free Software Foundation, 43.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 43.23 + * 43.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 43.25 + * or visit www.oracle.com if you need additional information or have any 43.26 + * questions. 43.27 + */ 43.28 + 43.29 +package org.openjdk.tests.separate; 43.30 + 43.31 +import java.util.*; 43.32 +import java.util.concurrent.atomic.AtomicInteger; 43.33 +import java.util.concurrent.ConcurrentHashMap; 43.34 +import java.io.*; 43.35 +import java.net.URI; 43.36 +import javax.tools.*; 43.37 + 43.38 +import com.sun.source.util.JavacTask; 43.39 + 43.40 +import static org.openjdk.tests.separate.SourceModel.Type; 43.41 +import static org.openjdk.tests.separate.SourceModel.Class; 43.42 +import static org.openjdk.tests.separate.SourceModel.Extends; 43.43 +import static org.openjdk.tests.separate.SourceModel.SourceProcessor; 43.44 + 43.45 +public class Compiler { 43.46 + 43.47 + public enum Flags { 43.48 + VERBOSE, // Prints out files as they are compiled 43.49 + USECACHE // Keeps results around for reuse. Only use this is 43.50 + // you're sure that each compilation name maps to the 43.51 + // same source code 43.52 + }; 43.53 + 43.54 + private static final AtomicInteger counter = new AtomicInteger(); 43.55 + private static final String targetDir = "gen-separate"; 43.56 + private static final File root = new File(targetDir); 43.57 + private static ConcurrentHashMap<String,File> cache = 43.58 + new ConcurrentHashMap<>(); 43.59 + 43.60 + Set<Flags> flags; 43.61 + 43.62 + private JavaCompiler systemJavaCompiler; 43.63 + private StandardJavaFileManager fm; 43.64 + private List<File> tempDirs; 43.65 + private List<ClassFilePreprocessor> postprocessors; 43.66 + 43.67 + private static class SourceFile extends SimpleJavaFileObject { 43.68 + private final String content; 43.69 + 43.70 + public SourceFile(String name, String content) { 43.71 + super(URI.create("myfo:/" + name + ".java"), Kind.SOURCE); 43.72 + this.content = content; 43.73 + } 43.74 + 43.75 + public CharSequence getCharContent(boolean ignoreEncodingErrors) { 43.76 + return toString(); 43.77 + } 43.78 + 43.79 + public String toString() { return this.content; } 43.80 + } 43.81 + 43.82 + public Compiler(Flags ... flags) { 43.83 + setFlags(flags); 43.84 + this.tempDirs = new ArrayList<>(); 43.85 + this.postprocessors = new ArrayList<>(); 43.86 + this.systemJavaCompiler = ToolProvider.getSystemJavaCompiler(); 43.87 + this.fm = systemJavaCompiler.getStandardFileManager(null, null, null); 43.88 + } 43.89 + 43.90 + public void setFlags(Flags ... flags) { 43.91 + this.flags = new HashSet<Flags>(Arrays.asList(flags)); 43.92 + } 43.93 + 43.94 + public void addPostprocessor(ClassFilePreprocessor cfp) { 43.95 + this.postprocessors.add(cfp); 43.96 + } 43.97 + 43.98 + /** 43.99 + * Compile hierarchies starting with each of the 'types' and return 43.100 + * a ClassLoader that can be used to load the compiled classes. 43.101 + */ 43.102 + public ClassLoader compile(Type ... types) { 43.103 + ClassFilePreprocessor[] cfps = this.postprocessors.toArray( 43.104 + new ClassFilePreprocessor[0]); 43.105 + 43.106 + DirectedClassLoader dcl = new DirectedClassLoader(cfps); 43.107 + 43.108 + for (Type t : types) { 43.109 + for (Map.Entry<String,File> each : compileHierarchy(t).entrySet()) { 43.110 + dcl.setLocationFor(each.getKey(), each.getValue()); 43.111 + } 43.112 + } 43.113 + return dcl; 43.114 + } 43.115 + 43.116 + /** 43.117 + * Compiles and loads a hierarchy, starting at 'type' 43.118 + */ 43.119 + public java.lang.Class<?> compileAndLoad(Type type) 43.120 + throws ClassNotFoundException { 43.121 + 43.122 + ClassLoader loader = compile(type); 43.123 + return java.lang.Class.forName(type.getName(), false, loader); 43.124 + } 43.125 + 43.126 + /** 43.127 + * Compiles a hierarchy, starting at 'type' and return a mapping of the 43.128 + * name to the location where the classfile for that type resides. 43.129 + */ 43.130 + private Map<String,File> compileHierarchy(Type type) { 43.131 + HashMap<String,File> outputDirs = new HashMap<>(); 43.132 + 43.133 + File outDir = compileOne(type); 43.134 + outputDirs.put(type.getName(), outDir); 43.135 + 43.136 + Class superClass = type.getSuperclass(); 43.137 + if (superClass != null) { 43.138 + for( Map.Entry<String,File> each : compileHierarchy(superClass).entrySet()) { 43.139 + outputDirs.put(each.getKey(), each.getValue()); 43.140 + } 43.141 + } 43.142 + for (Extends ext : type.getSupertypes()) { 43.143 + Type iface = ext.getType(); 43.144 + for( Map.Entry<String,File> each : compileHierarchy(iface).entrySet()) { 43.145 + outputDirs.put(each.getKey(), each.getValue()); 43.146 + } 43.147 + } 43.148 + 43.149 + return outputDirs; 43.150 + } 43.151 + 43.152 + private File compileOne(Type type) { 43.153 + if (this.flags.contains(Flags.USECACHE)) { 43.154 + File dir = cache.get(type.getName()); 43.155 + if (dir != null) { 43.156 + return dir; 43.157 + } 43.158 + } 43.159 + List<JavaFileObject> files = new ArrayList<>(); 43.160 + SourceProcessor accum = 43.161 + (name, src) -> { files.add(new SourceFile(name, src)); }; 43.162 + 43.163 + for (Type dep : type.typeDependencies()) { 43.164 + dep.generateAsDependency(accum, type.methodDependencies()); 43.165 + } 43.166 + 43.167 + type.generate(accum); 43.168 + 43.169 + JavacTask ct = (JavacTask)this.systemJavaCompiler.getTask( 43.170 + null, this.fm, null, null, null, files); 43.171 + File destDir = null; 43.172 + do { 43.173 + int value = counter.incrementAndGet(); 43.174 + destDir = new File(root, Integer.toString(value)); 43.175 + } while (destDir.exists()); 43.176 + 43.177 + if (this.flags.contains(Flags.VERBOSE)) { 43.178 + System.out.println("Compilation unit for " + type.getName() + 43.179 + " : compiled into " + destDir); 43.180 + for (JavaFileObject jfo : files) { 43.181 + System.out.println(jfo.toString()); 43.182 + } 43.183 + } 43.184 + 43.185 + try { 43.186 + destDir.mkdirs(); 43.187 + this.fm.setLocation( 43.188 + StandardLocation.CLASS_OUTPUT, Arrays.asList(destDir)); 43.189 + } catch (IOException e) { 43.190 + throw new RuntimeException( 43.191 + "IOException encountered during compilation"); 43.192 + } 43.193 + Boolean result = ct.call(); 43.194 + if (result == Boolean.FALSE) { 43.195 + throw new RuntimeException( 43.196 + "Compilation failure in " + type.getName() + " unit"); 43.197 + } 43.198 + if (this.flags.contains(Flags.USECACHE)) { 43.199 + File existing = cache.putIfAbsent(type.getName(), destDir); 43.200 + if (existing != null) { 43.201 + deleteDir(destDir); 43.202 + return existing; 43.203 + } 43.204 + } else { 43.205 + this.tempDirs.add(destDir); 43.206 + } 43.207 + return destDir; 43.208 + } 43.209 + 43.210 + private static void deleteDir(File dir) { 43.211 + for (File f : dir.listFiles()) { 43.212 + f.delete(); 43.213 + }; 43.214 + dir.delete(); 43.215 + } 43.216 + 43.217 + public void cleanup() { 43.218 + if (!this.flags.contains(Flags.USECACHE)) { 43.219 + for (File d : tempDirs) { 43.220 + deleteDir(d); 43.221 + }; 43.222 + tempDirs = new ArrayList<>(); 43.223 + } 43.224 + } 43.225 + 43.226 + // Removes all of the elements in the cache and deletes the associated 43.227 + // output directories. This may not actually empty the cache if there 43.228 + // are concurrent users of it. 43.229 + public static void purgeCache() { 43.230 + for (Map.Entry<String,File> entry : cache.entrySet()) { 43.231 + cache.remove(entry.getKey()); 43.232 + deleteDir(entry.getValue()); 43.233 + } 43.234 + } 43.235 +}
44.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 44.2 +++ b/test/tools/javac/lambdaShapes/org/openjdk/tests/separate/DirectedClassLoader.java Tue Nov 20 09:58:55 2012 -0800 44.3 @@ -0,0 +1,101 @@ 44.4 +/* 44.5 + * Copyright (c) 2012 Oracle and/or its affiliates. All rights reserved. 44.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 44.7 + * 44.8 + * This code is free software; you can redistribute it and/or modify it 44.9 + * under the terms of the GNU General Public License version 2 only, as 44.10 + * published by the Free Software Foundation. Oracle designates this 44.11 + * particular file as subject to the "Classpath" exception as provided 44.12 + * by Oracle in the LICENSE file that accompanied this code. 44.13 + * 44.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 44.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 44.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 44.17 + * version 2 for more details (a copy is included in the LICENSE file that 44.18 + * accompanied this code). 44.19 + * 44.20 + * You should have received a copy of the GNU General Public License version 44.21 + * 2 along with this work; if not, write to the Free Software Foundation, 44.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 44.23 + * 44.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 44.25 + * or visit www.oracle.com if you need additional information or have any 44.26 + * questions. 44.27 + */ 44.28 + 44.29 +package org.openjdk.tests.separate; 44.30 + 44.31 +import java.util.HashMap; 44.32 +import java.io.File; 44.33 +import java.io.FileInputStream; 44.34 +import java.io.IOException; 44.35 + 44.36 +class DirectedClassLoader extends ClassLoader { 44.37 + 44.38 + private HashMap<String,File> loadLocations; 44.39 + private File defaultLocation; 44.40 + private ClassFilePreprocessor[] preprocessors; 44.41 + 44.42 + public DirectedClassLoader( 44.43 + HashMap<String,File> locations, File fallback, 44.44 + ClassFilePreprocessor ... preprocessors) { 44.45 + loadLocations = new HashMap<>(locations); 44.46 + defaultLocation = fallback; 44.47 + this.preprocessors = preprocessors; 44.48 + } 44.49 + 44.50 + public DirectedClassLoader( 44.51 + File fallback, ClassFilePreprocessor ... preprocessors) { 44.52 + loadLocations = new HashMap<>(); 44.53 + defaultLocation = fallback; 44.54 + this.preprocessors = preprocessors; 44.55 + } 44.56 + 44.57 + public DirectedClassLoader(ClassFilePreprocessor ... preprocessors) { 44.58 + this((File)null, preprocessors); 44.59 + } 44.60 + 44.61 + public void setDefaultLocation(File dir) { this.defaultLocation = dir; } 44.62 + public void setLocationFor(String name, File dir) { 44.63 + loadLocations.put(name, dir); 44.64 + } 44.65 + 44.66 + @Override 44.67 + protected Class<?> findClass(String name) { 44.68 + String path = name.replace(".", File.separator) + ".class"; 44.69 + 44.70 + File location = loadLocations.get(name); 44.71 + if (location == null || !(new File(location, path)).exists()) { 44.72 + File def = new File(defaultLocation, path); 44.73 + if (def.exists()) { 44.74 + return defineFrom(name, new File(location, path)); 44.75 + } 44.76 + } else { 44.77 + return defineFrom(name, new File(location, path)); 44.78 + } 44.79 + return null; 44.80 + } 44.81 + 44.82 + private Class<?> defineFrom(String name, File file) { 44.83 + FileInputStream fis = null; 44.84 + try { 44.85 + try { 44.86 + fis = new FileInputStream(file); 44.87 + byte[] bytes = new byte[fis.available()]; 44.88 + int read = fis.read(bytes); 44.89 + if (read != bytes.length) { 44.90 + return null; 44.91 + } 44.92 + if (preprocessors != null) { 44.93 + for (ClassFilePreprocessor cfp : preprocessors) { 44.94 + bytes = cfp.preprocess(name, bytes); 44.95 + } 44.96 + } 44.97 + return defineClass(name, bytes, 0, bytes.length); 44.98 + } finally { 44.99 + fis.close(); 44.100 + } 44.101 + } catch (IOException e) {} 44.102 + return null; 44.103 + } 44.104 +}
45.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 45.2 +++ b/test/tools/javac/lambdaShapes/org/openjdk/tests/separate/SourceModel.java Tue Nov 20 09:58:55 2012 -0800 45.3 @@ -0,0 +1,582 @@ 45.4 +/* 45.5 + * Copyright (c) 2012 Oracle and/or its affiliates. All rights reserved. 45.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 45.7 + * 45.8 + * This code is free software; you can redistribute it and/or modify it 45.9 + * under the terms of the GNU General Public License version 2 only, as 45.10 + * published by the Free Software Foundation. Oracle designates this 45.11 + * particular file as subject to the "Classpath" exception as provided 45.12 + * by Oracle in the LICENSE file that accompanied this code. 45.13 + * 45.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 45.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 45.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 45.17 + * version 2 for more details (a copy is included in the LICENSE file that 45.18 + * accompanied this code). 45.19 + * 45.20 + * You should have received a copy of the GNU General Public License version 45.21 + * 2 along with this work; if not, write to the Free Software Foundation, 45.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 45.23 + * 45.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 45.25 + * or visit www.oracle.com if you need additional information or have any 45.26 + * questions. 45.27 + */ 45.28 + 45.29 +package org.openjdk.tests.separate; 45.30 + 45.31 +import java.util.*; 45.32 +import java.io.StringWriter; 45.33 +import java.io.PrintWriter; 45.34 + 45.35 +public class SourceModel { 45.36 + 45.37 + public static final String stdMethodName = "m"; 45.38 + 45.39 + public static interface SourceProcessor { 45.40 + // Called with a generated source file 45.41 + void process(String name, String content); 45.42 + } 45.43 + 45.44 + public static abstract class Element { 45.45 + 45.46 + protected abstract void generate(PrintWriter pw); 45.47 + 45.48 + public String toString() { 45.49 + StringWriter sw = new StringWriter(); 45.50 + PrintWriter pw = new PrintWriter(sw); 45.51 + generate(pw); 45.52 + return sw.toString(); 45.53 + } 45.54 + }; 45.55 + 45.56 + public static class AccessFlag extends Element { 45.57 + private String flag; 45.58 + 45.59 + public AccessFlag(String name) { flag = name; } 45.60 + 45.61 + protected void generate(PrintWriter pw) { 45.62 + pw.print(flag); 45.63 + } 45.64 + 45.65 + public String toString() { return flag; } 45.66 + 45.67 + public static final AccessFlag PUBLIC = new AccessFlag("public"); 45.68 + public static final AccessFlag PRIVATE = new AccessFlag("private"); 45.69 + public static final AccessFlag PROTECTED = new AccessFlag("protected"); 45.70 + public static final AccessFlag STATIC = new AccessFlag("static"); 45.71 + public static final AccessFlag FINAL = new AccessFlag("final"); 45.72 + public static final AccessFlag SYNCHRONIZED = new AccessFlag("synchronized"); 45.73 + public static final AccessFlag VOLATILE = new AccessFlag("volatile"); 45.74 + public static final AccessFlag NATIVE = new AccessFlag("native"); 45.75 + public static final AccessFlag ABSTRACT = new AccessFlag("abstract"); 45.76 + public static final AccessFlag STRICTFP = new AccessFlag("strictfp"); 45.77 + public static final AccessFlag DEFAULT = new AccessFlag("default"); 45.78 + } 45.79 + 45.80 + public static class TypeParameter extends Element { 45.81 + private String parameter; 45.82 + 45.83 + public TypeParameter(String str) { 45.84 + this.parameter = str; 45.85 + } 45.86 + 45.87 + protected void generate(PrintWriter pw) { 45.88 + pw.print(parameter); 45.89 + } 45.90 + } 45.91 + 45.92 + public static class TypeArgument extends Element { 45.93 + private String argument; 45.94 + 45.95 + public TypeArgument(String str) { 45.96 + this.argument = str; 45.97 + } 45.98 + 45.99 + protected void generate(PrintWriter pw) { 45.100 + pw.print(argument); 45.101 + } 45.102 + } 45.103 + 45.104 + public static class MethodParameter extends Element { 45.105 + private String type; 45.106 + private String name; 45.107 + 45.108 + public MethodParameter(String type, String name) { 45.109 + this.type = type; 45.110 + this.name = name; 45.111 + } 45.112 + 45.113 + protected void generate(PrintWriter pw) { 45.114 + pw.printf("%s %s", this.type, this.name); 45.115 + } 45.116 + 45.117 + public String toString() { return type + " " + name; } 45.118 + } 45.119 + 45.120 + public static abstract class Type extends Element { 45.121 + private String name; 45.122 + private List<AccessFlag> accessFlags; 45.123 + private List<TypeParameter> parameters; 45.124 + private List<Extends> supertypes; 45.125 + private List<Method> methods; 45.126 + 45.127 + // methods from superclasses that are required for compilation 45.128 + // (and thus will be present in stubs) 45.129 + private Set<Method> methodDependencies; 45.130 + private List<Type> typeDependencies; 45.131 + 45.132 + protected Type(String name, 45.133 + List<AccessFlag> flags, List<TypeParameter> params, 45.134 + List<Extends> ifaces, List<Method> methods) { 45.135 + this.name = name; 45.136 + this.accessFlags = flags == null ? new ArrayList<>() : flags; 45.137 + this.parameters = params == null ? new ArrayList<>() : params; 45.138 + this.supertypes = ifaces == null ? new ArrayList<>() : ifaces; 45.139 + this.methods = methods == null ? new ArrayList<>() : methods; 45.140 + this.methodDependencies = new HashSet<>(); 45.141 + this.typeDependencies = new ArrayList<>(); 45.142 + } 45.143 + 45.144 + public String getName() { return this.name; } 45.145 + public List<AccessFlag> getAccessFlags() { return this.accessFlags; } 45.146 + public List<TypeParameter> getParameters() { return this.parameters; } 45.147 + public List<Extends> getSupertypes() { return this.supertypes; } 45.148 + public List<Method> getMethods() { return this.methods; } 45.149 + public Set<Method> methodDependencies() { 45.150 + return this.methodDependencies; 45.151 + } 45.152 + 45.153 + public Class getSuperclass() { return null; } 45.154 + protected abstract void setSuperClass(Extends supertype); 45.155 + 45.156 + public void addSuperType(Extends sup) { 45.157 + assert sup.getType() instanceof Interface : "Must be an interface"; 45.158 + this.supertypes.add(sup); 45.159 + } 45.160 + public void addSuperType(Interface iface) { 45.161 + this.supertypes.add(new Extends(iface)); 45.162 + } 45.163 + 45.164 + public void addMethod(Method m) { 45.165 + this.methods.add(m); 45.166 + } 45.167 + 45.168 + public void addAccessFlag(AccessFlag f) { 45.169 + this.accessFlags.add(f); 45.170 + } 45.171 + 45.172 + // Convenience method for creation. Parameters are interpreted 45.173 + // according to their type. Class (or Extends with a Class type) is 45.174 + // considered a superclass (only one allowed). TypeParameters are 45.175 + // generic parameter names. Interface (or Extends with an Interface 45.176 + // type) is an implemented supertype. Methods are methods (duh!). 45.177 + protected void addComponent(Element p) { 45.178 + if (p instanceof Class) { 45.179 + setSuperClass(new Extends((Class)p)); 45.180 + } else if (p instanceof Extends) { 45.181 + Extends ext = (Extends)p; 45.182 + if (ext.supertype instanceof Class) { 45.183 + setSuperClass(ext); 45.184 + } else if (ext.supertype instanceof Interface) { 45.185 + addSuperType(ext); 45.186 + } else { 45.187 + assert false : "What is this thing?"; 45.188 + } 45.189 + } else if (p instanceof Interface) { 45.190 + addSuperType((Interface)p); 45.191 + } else if (p instanceof TypeParameter) { 45.192 + this.parameters.add((TypeParameter)p); 45.193 + } else if (p instanceof Method) { 45.194 + addMethod((Method)p); 45.195 + } else if (p instanceof AccessFlag) { 45.196 + addAccessFlag((AccessFlag)p); 45.197 + } else { 45.198 + assert false : "What is this thing?"; 45.199 + } 45.200 + } 45.201 + 45.202 + // Find and return the first method that has name 'name' 45.203 + public Method findMethod(String name) { 45.204 + for (Method m : methods) { 45.205 + if (m.name.equals(name)) { 45.206 + return m; 45.207 + } 45.208 + } 45.209 + return null; 45.210 + } 45.211 + 45.212 + public void addCompilationDependency(Type t) { 45.213 + typeDependencies.add(t); 45.214 + } 45.215 + 45.216 + public void addCompilationDependency(Method m) { 45.217 + methodDependencies.add(m); 45.218 + } 45.219 + 45.220 + // Convenience method for creating an Extends object using this 45.221 + // class and specified type arguments. 45.222 + public Extends with(String ... args) { 45.223 + return new Extends(this, args); 45.224 + } 45.225 + 45.226 + public abstract void generate(SourceProcessor sp); 45.227 + public abstract void generateAsDependency( 45.228 + SourceProcessor sp, Set<Method> neededMethods); 45.229 + 45.230 + protected void generateName(PrintWriter pw) { 45.231 + pw.print(this.name); 45.232 + toJoinedString(this.parameters, ",", "<", ">", ""); 45.233 + pw.print(toJoinedString(this.parameters, ",", "<", ">", "")); 45.234 + pw.print(" "); 45.235 + } 45.236 + 45.237 + protected void generateBody(PrintWriter pw, String superSpec) { 45.238 + pw.print(toJoinedString(this.supertypes, ",", superSpec + " ", " ", "")); 45.239 + pw.println("{ "); 45.240 + pw.print(toJoinedString(this.methods, "\n ", "\n ", "\n", "")); 45.241 + pw.println("}"); 45.242 + } 45.243 + 45.244 + protected void generateAccessFlags(PrintWriter pw) { 45.245 + pw.print(toJoinedString(this.accessFlags, " ", "", " ")); 45.246 + } 45.247 + 45.248 + protected void generateBodyAsDependency( 45.249 + PrintWriter pw, Set<Method> neededMethods) { 45.250 + pw.println(" {"); 45.251 + for (Method m : this.methods) { 45.252 + if (neededMethods.contains(m)) { 45.253 + pw.print(" "); 45.254 + m.generate(pw); 45.255 + pw.println(); 45.256 + } 45.257 + } 45.258 + pw.println("}"); 45.259 + } 45.260 + 45.261 + public Collection<Type> typeDependencies() { 45.262 + HashMap<String,Type> dependencies = new HashMap<>(); 45.263 + Type superclass = getSuperclass(); 45.264 + if (superclass != null) { 45.265 + dependencies.put(superclass.getName(), superclass); 45.266 + } 45.267 + for (Extends e : getSupertypes()) 45.268 + dependencies.put(e.getType().getName(), e.getType()); 45.269 + // Do these last so that they override 45.270 + for (Type t : this.typeDependencies) 45.271 + dependencies.put(t.getName(), t); 45.272 + return dependencies.values(); 45.273 + } 45.274 + } 45.275 + 45.276 + public static class Class extends Type { 45.277 + private Extends superClass; 45.278 + 45.279 + public Class(String name, List<AccessFlag> flags, 45.280 + List<TypeParameter> params, Extends sprClass, 45.281 + List<Extends> interfaces, List<Method> methods) { 45.282 + super(name, flags, params, interfaces, methods); 45.283 + this.superClass = sprClass; 45.284 + addAccessFlag(AccessFlag.PUBLIC); // should remove this 45.285 + } 45.286 + 45.287 + public Class(String name, Element ... components) { 45.288 + super(name, null, null, null, null); 45.289 + this.superClass = null; 45.290 + 45.291 + for (Element p : components) { 45.292 + addComponent(p); 45.293 + } 45.294 + addAccessFlag(AccessFlag.PUBLIC); // should remove this 45.295 + } 45.296 + 45.297 + public boolean isAbstract() { 45.298 + for (AccessFlag flag : getAccessFlags()) { 45.299 + if (flag == AccessFlag.ABSTRACT) { 45.300 + return true; 45.301 + } 45.302 + } 45.303 + return false; 45.304 + } 45.305 + 45.306 + @Override 45.307 + public void setSuperClass(Extends ext) { 45.308 + assert this.superClass == null : "Multiple superclasses defined"; 45.309 + assert ext.getType() instanceof Class : "Must be a class"; 45.310 + this.superClass = ext; 45.311 + } 45.312 + 45.313 + public void setSuperClass(Class c) { 45.314 + setSuperClass(new Extends(c)); 45.315 + } 45.316 + 45.317 + @Override 45.318 + public Class getSuperclass() { 45.319 + return superClass == null ? null : (Class)superClass.supertype; 45.320 + } 45.321 + 45.322 + public void generate(SourceProcessor processor) { 45.323 + StringWriter sw = new StringWriter(); 45.324 + PrintWriter pw = new PrintWriter(sw); 45.325 + generate(pw); 45.326 + processor.process(getName(), sw.toString()); 45.327 + } 45.328 + 45.329 + public void generate(PrintWriter pw) { 45.330 + generateAccessFlags(pw); 45.331 + pw.print("class "); 45.332 + generateName(pw); 45.333 + if (superClass != null) { 45.334 + pw.print("extends "); 45.335 + superClass.generate(pw); 45.336 + pw.print(" "); 45.337 + } 45.338 + generateBody(pw, "implements"); 45.339 + } 45.340 + 45.341 + public void generateAsDependency( 45.342 + SourceProcessor processor, Set<Method> neededMethods) { 45.343 + StringWriter sw = new StringWriter(); 45.344 + PrintWriter pw = new PrintWriter(sw); 45.345 + generateAccessFlags(pw); 45.346 + pw.print("class "); 45.347 + generateName(pw); 45.348 + pw.print(" "); 45.349 + generateBodyAsDependency(pw, neededMethods); 45.350 + 45.351 + processor.process(getName(), sw.toString()); 45.352 + } 45.353 + } 45.354 + 45.355 + public static class Interface extends Type { 45.356 + 45.357 + public Interface(String name, 45.358 + List<AccessFlag> flags, List<TypeParameter> params, 45.359 + List<Extends> interfaces, List<Method> methods) { 45.360 + super(name, flags, params, interfaces, methods); 45.361 + } 45.362 + 45.363 + public Interface(String name, Element ... components) { 45.364 + super(name, null, null, null, null); 45.365 + for (Element c : components) { 45.366 + addComponent(c); 45.367 + } 45.368 + } 45.369 + 45.370 + protected void setSuperClass(Extends ext) { 45.371 + assert false : "Interfaces cannot have Class supertypes"; 45.372 + } 45.373 + 45.374 + public void generate(SourceProcessor processor) { 45.375 + StringWriter sw = new StringWriter(); 45.376 + PrintWriter pw = new PrintWriter(sw); 45.377 + generate(pw); 45.378 + processor.process(getName(), sw.toString()); 45.379 + } 45.380 + 45.381 + public void generate(PrintWriter pw) { 45.382 + generateAccessFlags(pw); 45.383 + pw.print("interface "); 45.384 + generateName(pw); 45.385 + pw.print(" "); 45.386 + generateBody(pw, "extends"); 45.387 + } 45.388 + 45.389 + public void generateAsDependency( 45.390 + SourceProcessor processor, Set<Method> neededMethods) { 45.391 + StringWriter sw = new StringWriter(); 45.392 + PrintWriter pw = new PrintWriter(sw); 45.393 + 45.394 + generateAccessFlags(pw); 45.395 + pw.print("interface "); 45.396 + generateName(pw); 45.397 + pw.print(" "); 45.398 + generateBodyAsDependency(pw, neededMethods); 45.399 + 45.400 + processor.process(getName(), sw.toString()); 45.401 + } 45.402 + } 45.403 + 45.404 + /** 45.405 + * Represents a type extension that might contain type arguments 45.406 + */ 45.407 + public static class Extends extends Element { 45.408 + private final Type supertype; 45.409 + private final List<TypeArgument> arguments; 45.410 + 45.411 + public Type getType() { return supertype; } 45.412 + public List<TypeArgument> getArguments() { 45.413 + return arguments; 45.414 + } 45.415 + 45.416 + public Extends(Type supertype, String ... args) { 45.417 + assert supertype != null : "Null supertype"; 45.418 + this.supertype = supertype; 45.419 + this.arguments = new ArrayList<>(); 45.420 + for (String arg : args) { 45.421 + this.arguments.add(new TypeArgument(arg)); 45.422 + } 45.423 + } 45.424 + 45.425 + public void generate(PrintWriter pw) { 45.426 + pw.print(supertype.getName()); 45.427 + pw.print(toJoinedString(getArguments(), ",", "<", ">", "")); 45.428 + } 45.429 + } 45.430 + 45.431 + public static abstract class Method extends Element { 45.432 + private String name; 45.433 + private String returnType; 45.434 + private List<AccessFlag> accessFlags; 45.435 + private List<MethodParameter> parameters; 45.436 + private boolean emitSuppressWarnings; 45.437 + 45.438 + protected Method(String ret, String name, Element ... params) { 45.439 + this.name = name; 45.440 + this.returnType = ret; 45.441 + this.accessFlags = new ArrayList<>(); 45.442 + this.parameters = new ArrayList<>(); 45.443 + this.emitSuppressWarnings = false; 45.444 + 45.445 + for (Element e : params) { 45.446 + if (e instanceof MethodParameter) { 45.447 + this.parameters.add((MethodParameter) e); 45.448 + } else if (e instanceof AccessFlag) { 45.449 + this.accessFlags.add((AccessFlag) e); 45.450 + } 45.451 + } 45.452 + assert accessFlags.size() + parameters.size() == params.length : 45.453 + "Non method parameters or access flags in constructor"; 45.454 + } 45.455 + 45.456 + public String getName() { return this.name; } 45.457 + public String getReturnType() { return this.returnType; } 45.458 + public List<MethodParameter> getParameters() { 45.459 + return this.parameters; 45.460 + } 45.461 + public List<AccessFlag> getAccessFlags() { 45.462 + return this.accessFlags; 45.463 + } 45.464 + public Element[] getElements() { 45.465 + ArrayList<Element> elements = new ArrayList<>(); 45.466 + elements.addAll(getParameters()); 45.467 + elements.addAll(getAccessFlags()); 45.468 + return elements.toArray(new Element[0]); 45.469 + } 45.470 + 45.471 + public void suppressWarnings() { this.emitSuppressWarnings = true; } 45.472 + 45.473 + public void generateWarningSuppression(PrintWriter pw) { 45.474 + if (this.emitSuppressWarnings) { 45.475 + pw.printf("@SuppressWarnings(\"unchecked\")\n "); 45.476 + } 45.477 + } 45.478 + 45.479 + protected void generateDecl(PrintWriter pw) { 45.480 + generateWarningSuppression(pw); 45.481 + pw.print(toJoinedString(this.accessFlags, " ", "", " ")); 45.482 + pw.printf("%s %s(", returnType, name); 45.483 + pw.print(toJoinedString(parameters, ",")); 45.484 + pw.print(")"); 45.485 + } 45.486 + } 45.487 + 45.488 + public static class AbstractMethod extends Method { 45.489 + public AbstractMethod( 45.490 + String ret, String name, Element ... params) { 45.491 + super(ret, name, params); 45.492 + this.getAccessFlags().add(AccessFlag.ABSTRACT); 45.493 + } 45.494 + 45.495 + public void generate(PrintWriter pw) { 45.496 + generateDecl(pw); 45.497 + pw.print(";"); 45.498 + } 45.499 + 45.500 + public static AbstractMethod std() { 45.501 + return new AbstractMethod( 45.502 + "int", SourceModel.stdMethodName, AccessFlag.PUBLIC); 45.503 + } 45.504 + } 45.505 + 45.506 + public static class ConcreteMethod extends Method { 45.507 + protected String body; 45.508 + 45.509 + public ConcreteMethod(String ret, String name, 45.510 + String body, Element ... params) { 45.511 + super(ret, name, params); 45.512 + this.body = body; 45.513 + } 45.514 + 45.515 + public void generate(PrintWriter pw) { 45.516 + generateDecl(pw); 45.517 + pw.printf(" { %s }", this.body); 45.518 + } 45.519 + 45.520 + public static ConcreteMethod std(String value) { 45.521 + return new ConcreteMethod( 45.522 + "int", SourceModel.stdMethodName, "return " + value + ";", 45.523 + AccessFlag.PUBLIC); 45.524 + } 45.525 + } 45.526 + 45.527 + // When the default method flag gets moved into the traditional 45.528 + // access flags location, we can remove this class completely and 45.529 + // use a ConcreteMethod with an AccessFlag("default") in the constructor 45.530 + public static class DefaultMethod extends Method { 45.531 + protected String body; 45.532 + 45.533 + public DefaultMethod(String ret, String name, String body, 45.534 + Element ... params) { 45.535 + super(ret, name, params); 45.536 + this.body = body; 45.537 + this.getAccessFlags().add(AccessFlag.DEFAULT); 45.538 + } 45.539 + 45.540 + public void generate(PrintWriter pw) { 45.541 + generateDecl(pw); 45.542 + pw.printf(" { %s }", this.body); 45.543 + } 45.544 + 45.545 + public static DefaultMethod std(String value) { 45.546 + return new DefaultMethod( 45.547 + "int", SourceModel.stdMethodName, "return " + value + ";"); 45.548 + } 45.549 + } 45.550 + 45.551 + private static <T> String toJoinedString(List<T> list, String... p) { 45.552 + StringBuilder sb = new StringBuilder(); 45.553 + String sep = ""; 45.554 + String init = ""; 45.555 + String end = ""; 45.556 + String empty = null; 45.557 + switch (p.length) { 45.558 + case 4: 45.559 + empty = p[3]; 45.560 + /*fall-through*/ 45.561 + case 3: 45.562 + end = p[2]; 45.563 + /*fall-through*/ 45.564 + case 2: 45.565 + init = p[1]; 45.566 + /*fall-through*/ 45.567 + case 1: 45.568 + sep = p[0]; 45.569 + break; 45.570 + } 45.571 + if (empty != null && list.isEmpty()) { 45.572 + return empty; 45.573 + } else { 45.574 + sb.append(init); 45.575 + for (T x : list) { 45.576 + if (sb.length() != init.length()) { 45.577 + sb.append(sep); 45.578 + } 45.579 + sb.append(x.toString()); 45.580 + } 45.581 + sb.append(end); 45.582 + return sb.toString(); 45.583 + } 45.584 + } 45.585 +}
46.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 46.2 +++ b/test/tools/javac/lambdaShapes/org/openjdk/tests/separate/TestHarness.java Tue Nov 20 09:58:55 2012 -0800 46.3 @@ -0,0 +1,354 @@ 46.4 +/* 46.5 + * Copyright (c) 2012 Oracle and/or its affiliates. All rights reserved. 46.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 46.7 + * 46.8 + * This code is free software; you can redistribute it and/or modify it 46.9 + * under the terms of the GNU General Public License version 2 only, as 46.10 + * published by the Free Software Foundation. Oracle designates this 46.11 + * particular file as subject to the "Classpath" exception as provided 46.12 + * by Oracle in the LICENSE file that accompanied this code. 46.13 + * 46.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 46.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 46.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 46.17 + * version 2 for more details (a copy is included in the LICENSE file that 46.18 + * accompanied this code). 46.19 + * 46.20 + * You should have received a copy of the GNU General Public License version 46.21 + * 2 along with this work; if not, write to the Free Software Foundation, 46.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 46.23 + * 46.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 46.25 + * or visit www.oracle.com if you need additional information or have any 46.26 + * questions. 46.27 + */ 46.28 + 46.29 +package org.openjdk.tests.separate; 46.30 + 46.31 +import org.testng.ITestResult; 46.32 +import org.testng.annotations.AfterMethod; 46.33 + 46.34 +import java.lang.reflect.InvocationTargetException; 46.35 +import java.util.Arrays; 46.36 +import java.util.HashSet; 46.37 +import java.util.List; 46.38 + 46.39 +import static org.openjdk.tests.separate.SourceModel.Class; 46.40 +import static org.openjdk.tests.separate.SourceModel.*; 46.41 +import static org.testng.Assert.*; 46.42 + 46.43 +public class TestHarness { 46.44 + 46.45 + /** 46.46 + * Creates a per-thread persistent compiler object to allow as much 46.47 + * sharing as possible, but still allows for parallel execution of tests. 46.48 + */ 46.49 + protected ThreadLocal<Compiler> compilerLocal = new ThreadLocal<Compiler>(){ 46.50 + protected synchronized Compiler initialValue() { 46.51 + return new Compiler(); 46.52 + } 46.53 + }; 46.54 + 46.55 + protected ThreadLocal<Boolean> verboseLocal = new ThreadLocal<Boolean>() { 46.56 + protected synchronized Boolean initialValue() { 46.57 + return Boolean.FALSE; 46.58 + } 46.59 + }; 46.60 + 46.61 + protected boolean verbose; 46.62 + protected boolean canUseCompilerCache; 46.63 + public static final String stdMethodName = SourceModel.stdMethodName; 46.64 + 46.65 + private TestHarness() { 46.66 + } 46.67 + 46.68 + protected TestHarness(boolean verbose, boolean canUseCompilerCache) { 46.69 + this.verbose = verbose; 46.70 + this.canUseCompilerCache = canUseCompilerCache; 46.71 + } 46.72 + 46.73 + public void setTestVerbose() { 46.74 + verboseLocal.set(Boolean.TRUE); 46.75 + } 46.76 + 46.77 + @AfterMethod 46.78 + public void reset() { 46.79 + if (!this.verbose) { 46.80 + verboseLocal.set(Boolean.FALSE); 46.81 + } 46.82 + } 46.83 + 46.84 + public Compiler.Flags[] compilerFlags() { 46.85 + HashSet<Compiler.Flags> flags = new HashSet<>(); 46.86 + if (verboseLocal.get() == Boolean.TRUE) { 46.87 + flags.add(Compiler.Flags.VERBOSE); 46.88 + } 46.89 + if (this.canUseCompilerCache) { 46.90 + flags.add(Compiler.Flags.USECACHE); 46.91 + } 46.92 + return flags.toArray(new Compiler.Flags[0]); 46.93 + } 46.94 + 46.95 + @AfterMethod 46.96 + public void printError(ITestResult result) { 46.97 + if (result.getStatus() == ITestResult.FAILURE) { 46.98 + String clsName = result.getTestClass().getName(); 46.99 + clsName = clsName.substring(clsName.lastIndexOf(".") + 1); 46.100 + System.out.println("Test " + clsName + "." + 46.101 + result.getName() + " FAILED"); 46.102 + } 46.103 + } 46.104 + 46.105 + private static final ConcreteMethod stdCM = ConcreteMethod.std("-1"); 46.106 + private static final AbstractMethod stdAM = 46.107 + new AbstractMethod("int", stdMethodName); 46.108 + 46.109 + /** 46.110 + * Returns a class which has a static method with the same name as 46.111 + * 'method', whose body creates an new instance of 'specimen' and invokes 46.112 + * 'method' upon it via an invokevirtual instruction with 'args' as 46.113 + * function call parameters. 46.114 + * 46.115 + * 'returns' is a dummy return value that need only match 'methods' 46.116 + * return type (it is only used in the dummy class when compiling IV). 46.117 + */ 46.118 + private Class invokeVirtualHarness( 46.119 + Class specimen, ConcreteMethod method, 46.120 + String returns, String ... args) { 46.121 + Method cm = new ConcreteMethod( 46.122 + method.getReturnType(), method.getName(), 46.123 + "return " + returns + ";", method.getElements()); 46.124 + Class stub = new Class(specimen.getName(), cm); 46.125 + 46.126 + String params = toJoinedString(args, ", "); 46.127 + 46.128 + ConcreteMethod sm = new ConcreteMethod( 46.129 + method.getReturnType(), method.getName(), 46.130 + String.format("return (new %s()).%s(%s);", 46.131 + specimen.getName(), method.getName(), params), 46.132 + new AccessFlag("public"), new AccessFlag("static")); 46.133 + 46.134 + Class iv = new Class("IV_" + specimen.getName(), sm); 46.135 + 46.136 + iv.addCompilationDependency(stub); 46.137 + iv.addCompilationDependency(cm); 46.138 + 46.139 + return iv; 46.140 + } 46.141 + 46.142 + /** 46.143 + * Returns a class which has a static method with the same name as 46.144 + * 'method', whose body creates an new instance of 'specimen', casts it 46.145 + * to 'iface' (including the type parameters) and invokes 46.146 + * 'method' upon it via an invokeinterface instruction with 'args' as 46.147 + * function call parameters. 46.148 + */ 46.149 + private Class invokeInterfaceHarness(Class specimen, Extends iface, 46.150 + AbstractMethod method, String ... args) { 46.151 + Interface istub = new Interface( 46.152 + iface.getType().getName(), iface.getType().getAccessFlags(), 46.153 + iface.getType().getParameters(), 46.154 + null, Arrays.asList((Method)method)); 46.155 + Class cstub = new Class(specimen.getName()); 46.156 + 46.157 + String params = toJoinedString(args, ", "); 46.158 + 46.159 + ConcreteMethod sm = new ConcreteMethod( 46.160 + "int", SourceModel.stdMethodName, 46.161 + String.format("return ((%s)(new %s())).%s(%s);", iface.toString(), 46.162 + specimen.getName(), method.getName(), params), 46.163 + new AccessFlag("public"), new AccessFlag("static")); 46.164 + sm.suppressWarnings(); 46.165 + 46.166 + Class ii = new Class("II_" + specimen.getName() + "_" + 46.167 + iface.getType().getName(), sm); 46.168 + ii.addCompilationDependency(istub); 46.169 + ii.addCompilationDependency(cstub); 46.170 + ii.addCompilationDependency(method); 46.171 + return ii; 46.172 + } 46.173 + 46.174 + 46.175 + /** 46.176 + * Uses 'loader' to load class 'clzz', and calls the static method 46.177 + * 'method'. If the return value does not equal 'value' (or if an 46.178 + * exception is thrown), then a test failure is indicated. 46.179 + * 46.180 + * If 'value' is null, then no equality check is performed -- the assertion 46.181 + * fails only if an exception is thrown. 46.182 + */ 46.183 + protected void assertStaticCallEquals( 46.184 + ClassLoader loader, Class clzz, String method, Object value) { 46.185 + java.lang.Class<?> cls = null; 46.186 + try { 46.187 + cls = java.lang.Class.forName(clzz.getName(), true, loader); 46.188 + } catch (ClassNotFoundException e) {} 46.189 + assertNotNull(cls); 46.190 + 46.191 + java.lang.reflect.Method m = null; 46.192 + try { 46.193 + m = cls.getMethod(method); 46.194 + } catch (NoSuchMethodException e) {} 46.195 + assertNotNull(m); 46.196 + 46.197 + try { 46.198 + Object res = m.invoke(null); 46.199 + assertNotNull(res); 46.200 + if (value != null) { 46.201 + assertEquals(res, value); 46.202 + } 46.203 + } catch (InvocationTargetException | IllegalAccessException e) { 46.204 + fail("Unexpected exception thrown: " + e.getCause()); 46.205 + } 46.206 + } 46.207 + 46.208 + /** 46.209 + * Creates a class which calls target::method(args) via invokevirtual, 46.210 + * compiles and loads both the new class and 'target', and then invokes 46.211 + * the method. If the returned value does not match 'value' then a 46.212 + * test failure is indicated. 46.213 + */ 46.214 + public void assertInvokeVirtualEquals( 46.215 + Object value, Class target, ConcreteMethod method, 46.216 + String returns, String ... args) { 46.217 + 46.218 + Compiler compiler = compilerLocal.get(); 46.219 + compiler.setFlags(compilerFlags()); 46.220 + 46.221 + Class iv = invokeVirtualHarness(target, method, returns, args); 46.222 + ClassLoader loader = compiler.compile(iv, target); 46.223 + 46.224 + assertStaticCallEquals(loader, iv, method.getName(), value); 46.225 + compiler.cleanup(); 46.226 + } 46.227 + 46.228 + /** 46.229 + * Convenience method for above, which assumes stdMethodName, 46.230 + * a return type of 'int', and no arguments. 46.231 + */ 46.232 + public void assertInvokeVirtualEquals(int value, Class target) { 46.233 + assertInvokeVirtualEquals( 46.234 + new Integer(value), target, stdCM, "-1"); 46.235 + } 46.236 + 46.237 + /** 46.238 + * Creates a class which calls target::method(args) via invokeinterface 46.239 + * through 'iface', compiles and loads both it and 'target', and 46.240 + * then invokes the method. If the returned value does not match 46.241 + * 'value' then a test failure is indicated. 46.242 + */ 46.243 + public void assertInvokeInterfaceEquals(Object value, Class target, 46.244 + Extends iface, AbstractMethod method, String ... args) { 46.245 + 46.246 + Compiler compiler = compilerLocal.get(); 46.247 + compiler.setFlags(compilerFlags()); 46.248 + 46.249 + Class ii = invokeInterfaceHarness(target, iface, method, args); 46.250 + ClassLoader loader = compiler.compile(ii, target); 46.251 + 46.252 + assertStaticCallEquals(loader, ii, method.getName(), value); 46.253 + compiler.cleanup(); 46.254 + } 46.255 + 46.256 + /** 46.257 + * Convenience method for above, which assumes stdMethodName, 46.258 + * a return type of 'int', and no arguments. 46.259 + */ 46.260 + public void assertInvokeInterfaceEquals( 46.261 + int value, Class target, Interface iface) { 46.262 + 46.263 + Compiler compiler = compilerLocal.get(); 46.264 + compiler.setFlags(compilerFlags()); 46.265 + 46.266 + assertInvokeInterfaceEquals( 46.267 + new Integer(value), target, new Extends(iface), stdAM); 46.268 + 46.269 + compiler.cleanup(); 46.270 + } 46.271 + 46.272 + /** 46.273 + * Creates a class which calls target::method(args) via invokevirtual, 46.274 + * compiles and loads both the new class and 'target', and then invokes 46.275 + * the method. If an exception of type 'exceptionType' is not thrown, 46.276 + * then a test failure is indicated. 46.277 + */ 46.278 + public void assertThrows(java.lang.Class<?> exceptionType, Class target, 46.279 + ConcreteMethod method, String returns, String ... args) { 46.280 + 46.281 + Compiler compiler = compilerLocal.get(); 46.282 + compiler.setFlags(compilerFlags()); 46.283 + 46.284 + Class iv = invokeVirtualHarness(target, method, returns, args); 46.285 + ClassLoader loader = compiler.compile(iv, target); 46.286 + 46.287 + java.lang.Class<?> cls = null; 46.288 + try { 46.289 + cls = java.lang.Class.forName(iv.getName(), true, loader); 46.290 + } catch (ClassNotFoundException e) {} 46.291 + assertNotNull(cls); 46.292 + 46.293 + java.lang.reflect.Method m = null; 46.294 + try { 46.295 + m = cls.getMethod(method.getName()); 46.296 + } catch (NoSuchMethodException e) {} 46.297 + assertNotNull(m); 46.298 + 46.299 + try { 46.300 + m.invoke(null); 46.301 + fail("Exception should have been thrown"); 46.302 + } catch (InvocationTargetException | IllegalAccessException e) { 46.303 + if (verboseLocal.get() == Boolean.TRUE) { 46.304 + System.out.println(e.getCause()); 46.305 + } 46.306 + assertEquals(e.getCause().getClass(), exceptionType); 46.307 + } 46.308 + compiler.cleanup(); 46.309 + } 46.310 + 46.311 + /** 46.312 + * Convenience method for above, which assumes stdMethodName, 46.313 + * a return type of 'int', and no arguments. 46.314 + */ 46.315 + public void assertThrows(java.lang.Class<?> exceptionType, Class target) { 46.316 + assertThrows(exceptionType, target, stdCM, "-1"); 46.317 + } 46.318 + 46.319 + private static <T> String toJoinedString(T[] a, String... p) { 46.320 + return toJoinedString(Arrays.asList(a), p); 46.321 + } 46.322 + 46.323 + private static <T> String toJoinedString(List<T> list, String... p) { 46.324 + StringBuilder sb = new StringBuilder(); 46.325 + String sep = ""; 46.326 + String init = ""; 46.327 + String end = ""; 46.328 + String empty = null; 46.329 + switch (p.length) { 46.330 + case 4: 46.331 + empty = p[3]; 46.332 + /*fall-through*/ 46.333 + case 3: 46.334 + end = p[2]; 46.335 + /*fall-through*/ 46.336 + case 2: 46.337 + init = p[1]; 46.338 + /*fall-through*/ 46.339 + case 1: 46.340 + sep = p[0]; 46.341 + break; 46.342 + } 46.343 + if (empty != null && list.isEmpty()) { 46.344 + return empty; 46.345 + } else { 46.346 + sb.append(init); 46.347 + for (T x : list) { 46.348 + if (sb.length() != init.length()) { 46.349 + sb.append(sep); 46.350 + } 46.351 + sb.append(x.toString()); 46.352 + } 46.353 + sb.append(end); 46.354 + return sb.toString(); 46.355 + } 46.356 + } 46.357 +}
47.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 47.2 +++ b/test/tools/javac/lambdaShapes/org/openjdk/tests/shapegen/ClassCase.java Tue Nov 20 09:58:55 2012 -0800 47.3 @@ -0,0 +1,312 @@ 47.4 +/* 47.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 47.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 47.7 + * 47.8 + * This code is free software; you can redistribute it and/or modify it 47.9 + * under the terms of the GNU General Public License version 2 only, as 47.10 + * published by the Free Software Foundation. Oracle designates this 47.11 + * particular file as subject to the "Classpath" exception as provided 47.12 + * by Oracle in the LICENSE file that accompanied this code. 47.13 + * 47.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 47.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 47.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 47.17 + * version 2 for more details (a copy is included in the LICENSE file that 47.18 + * accompanied this code). 47.19 + * 47.20 + * You should have received a copy of the GNU General Public License version 47.21 + * 2 along with this work; if not, write to the Free Software Foundation, 47.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 47.23 + * 47.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 47.25 + * or visit www.oracle.com if you need additional information or have any 47.26 + * questions. 47.27 + */ 47.28 + 47.29 +package org.openjdk.tests.shapegen; 47.30 + 47.31 +import java.util.ArrayList; 47.32 +import java.util.HashSet; 47.33 +import java.util.List; 47.34 +import java.util.Map; 47.35 +import java.util.Set; 47.36 + 47.37 +/** 47.38 + * 47.39 + * @author Robert Field 47.40 + */ 47.41 +public class ClassCase { 47.42 + 47.43 + public enum Kind { 47.44 + IVAC (true, "v"), 47.45 + IPRESENT (true, "p"), 47.46 + IDEFAULT (true, "d"), 47.47 + CNONE (false, "n"), 47.48 + CABSTRACT (false, "a"), 47.49 + CCONCRETE (false, "c"); 47.50 + 47.51 + private final String prefix; 47.52 + public final boolean isInterface; 47.53 + 47.54 + Kind(boolean isInterface, String prefix) { 47.55 + this.isInterface = isInterface; 47.56 + this.prefix = prefix; 47.57 + } 47.58 + 47.59 + public String getPrefix() { return prefix; } 47.60 + } 47.61 + 47.62 + public final Kind kind; 47.63 + private final ClassCase superclass; 47.64 + private final List<ClassCase> supertypes; 47.65 + 47.66 + private String name; 47.67 + private boolean _OK; 47.68 + private boolean _HasClassMethod; 47.69 + private Set<ClassCase> _mprov; 47.70 + private boolean _IsConcrete; 47.71 + private boolean _HasDefault; 47.72 + private ClassCase _mres; 47.73 + private ClassCase _mdefend; 47.74 + 47.75 + private Set<RuleGroup> executed = new HashSet<RuleGroup>(); 47.76 + 47.77 + public ClassCase(Kind kind, ClassCase superclass, List<ClassCase> interfaces) { 47.78 + this.kind = kind; 47.79 + this.superclass = superclass; 47.80 + 47.81 + // Set supertypes from superclass (if any) and interfaces 47.82 + List<ClassCase> lc; 47.83 + if (superclass == null) { 47.84 + lc = interfaces; 47.85 + } else { 47.86 + lc = new ArrayList<>(); 47.87 + lc.add(superclass); 47.88 + lc.addAll(interfaces); 47.89 + } 47.90 + this.supertypes = lc; 47.91 + } 47.92 + 47.93 + public final boolean isInterface() { return kind.isInterface; } 47.94 + public final boolean isClass() { return !kind.isInterface; } 47.95 + 47.96 + public Set<ClassCase> get_mprov() { 47.97 + exec(RuleGroup.PROVENENCE); 47.98 + return _mprov; 47.99 + } 47.100 + 47.101 + public void set_mprov(ClassCase cc) { 47.102 + Set<ClassCase> s = new HashSet<>(); 47.103 + s.add(cc); 47.104 + _mprov = s; 47.105 + } 47.106 + 47.107 + public void set_mprov(Set<ClassCase> s) { 47.108 + _mprov = s; 47.109 + } 47.110 + 47.111 + public ClassCase get_mres() { 47.112 + exec(RuleGroup.RESOLUTION); 47.113 + return _mres; 47.114 + } 47.115 + 47.116 + public void set_mres(ClassCase cc) { 47.117 + _mres = cc; 47.118 + } 47.119 + 47.120 + public ClassCase get_mdefend() { 47.121 + exec(RuleGroup.DEFENDER); 47.122 + return _mdefend; 47.123 + } 47.124 + 47.125 + public void set_mdefend(ClassCase cc) { 47.126 + _mdefend = cc; 47.127 + } 47.128 + 47.129 + public boolean get_HasClassMethod() { 47.130 + exec(RuleGroup.PROVENENCE); 47.131 + return _HasClassMethod; 47.132 + } 47.133 + 47.134 + public void set_HasClassMethod(boolean bool) { 47.135 + _HasClassMethod = bool; 47.136 + } 47.137 + 47.138 + public boolean get_HasDefault() { 47.139 + exec(RuleGroup.MARKER); 47.140 + return _HasDefault; 47.141 + } 47.142 + 47.143 + public void set_HasDefault(boolean bool) { 47.144 + _HasDefault = bool; 47.145 + } 47.146 + 47.147 + public boolean get_IsConcrete() { 47.148 + exec(RuleGroup.MARKER); 47.149 + return _IsConcrete; 47.150 + } 47.151 + 47.152 + public void set_IsConcrete(boolean bool) { 47.153 + _IsConcrete = bool; 47.154 + } 47.155 + 47.156 + public boolean get_OK() { 47.157 + exec(RuleGroup.CHECKING); 47.158 + return _OK; 47.159 + } 47.160 + 47.161 + public void set_OK(boolean bool) { 47.162 + _OK = bool; 47.163 + } 47.164 + 47.165 + public boolean isMethodDefined() { 47.166 + for (ClassCase cc : supertypes) { 47.167 + if (cc.isMethodDefined()) { 47.168 + return true; 47.169 + } 47.170 + } 47.171 + switch (kind) { 47.172 + case CCONCRETE: 47.173 + case CABSTRACT: 47.174 + case IPRESENT: 47.175 + case IDEFAULT: 47.176 + return true; 47.177 + default: 47.178 + return false; 47.179 + } 47.180 + } 47.181 + 47.182 + public boolean isAbstract() { 47.183 + return isMethodDefined() && (get_mres()==null); 47.184 + } 47.185 + 47.186 + public boolean hasSuperclass() { 47.187 + return superclass != null; 47.188 + } 47.189 + 47.190 + public ClassCase getSuperclass() { 47.191 + return superclass; 47.192 + } 47.193 + 47.194 + public List<ClassCase> getSupertypes() { 47.195 + return supertypes; 47.196 + } 47.197 + 47.198 + public List<ClassCase> getInterfaces() { 47.199 + if (superclass != null) { 47.200 + if (supertypes.get(0) != superclass) { 47.201 + throw new AssertionError("superclass missing from supertypes"); 47.202 + } 47.203 + return supertypes.subList(1, supertypes.size()); 47.204 + } else { 47.205 + return supertypes; 47.206 + } 47.207 + } 47.208 + 47.209 + public boolean isSubtypeOf(ClassCase cc) { 47.210 + // S-Refl 47.211 + if (cc.equals(this)) { 47.212 + return true; 47.213 + } 47.214 + 47.215 + // S-Def 47.216 + for (ClassCase sp : getSupertypes()) { 47.217 + if (cc.equals(sp)) { 47.218 + return true; 47.219 + } 47.220 + } 47.221 + 47.222 + // _S-Trans 47.223 + for (ClassCase sp : getSupertypes()) { 47.224 + if (sp.isSubtypeOf(cc)) { 47.225 + return true; 47.226 + } 47.227 + } 47.228 + 47.229 + return false; 47.230 + } 47.231 + 47.232 + public void init(Map<String, Integer> namingContext) { 47.233 + if (name != null) { 47.234 + return; // Already inited 47.235 + } 47.236 + 47.237 + for (ClassCase sup : supertypes) { 47.238 + sup.init(namingContext); 47.239 + } 47.240 + 47.241 + // Build name 47.242 + StringBuilder sb = new StringBuilder(); 47.243 + if (!supertypes.isEmpty()) { 47.244 + sb.append(isInterface() ? "I" : "C"); 47.245 + for (ClassCase cc : supertypes) { 47.246 + sb.append(cc.getName()); 47.247 + } 47.248 + sb.append(kind.isInterface ? "i" : "c"); 47.249 + } 47.250 + sb.append(kind.prefix); 47.251 + String pname = sb.toString(); 47.252 + Integer icnt = namingContext.get(pname); 47.253 + int cnt = icnt == null ? 0 : icnt; 47.254 + ++cnt; 47.255 + namingContext.put(pname, cnt); 47.256 + if (cnt > 1) { 47.257 + sb.append(cnt); 47.258 + } 47.259 + this.name = sb.toString(); 47.260 + } 47.261 + 47.262 + public boolean isa(Kind... kinds) { 47.263 + for (Kind k : kinds) { 47.264 + if (kind == k) { 47.265 + return true; 47.266 + } 47.267 + } 47.268 + return false; 47.269 + } 47.270 + 47.271 + private void exec(RuleGroup rg ) { 47.272 + if (!executed.contains(rg)) { 47.273 + rg.exec(this); 47.274 + executed.add(rg); 47.275 + } 47.276 + } 47.277 + 47.278 + public void collectClasses(Set<ClassCase> seen) { 47.279 + seen.add(this); 47.280 + for (ClassCase cc : supertypes) { 47.281 + cc.collectClasses(seen); 47.282 + } 47.283 + } 47.284 + 47.285 + public String getID() { 47.286 + if (name == null) { 47.287 + throw new Error("Access to uninitialized ClassCase"); 47.288 + } else { 47.289 + return name; 47.290 + } 47.291 + } 47.292 + 47.293 + public final String getName() { 47.294 + if (name == null) { 47.295 + return "ClassCase uninited@" + hashCode(); 47.296 + } else { 47.297 + return name; 47.298 + } 47.299 + } 47.300 + 47.301 + @Override 47.302 + public boolean equals(Object obj) { 47.303 + return obj instanceof ClassCase && getID().equals(((ClassCase)obj).getID()); 47.304 + } 47.305 + 47.306 + @Override 47.307 + public int hashCode() { 47.308 + return getID().hashCode(); 47.309 + } 47.310 + 47.311 + @Override 47.312 + public String toString() { 47.313 + return getName(); 47.314 + } 47.315 +}
48.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 48.2 +++ b/test/tools/javac/lambdaShapes/org/openjdk/tests/shapegen/Hierarchy.java Tue Nov 20 09:58:55 2012 -0800 48.3 @@ -0,0 +1,209 @@ 48.4 +/* 48.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 48.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 48.7 + * 48.8 + * This code is free software; you can redistribute it and/or modify it 48.9 + * under the terms of the GNU General Public License version 2 only, as 48.10 + * published by the Free Software Foundation. Oracle designates this 48.11 + * particular file as subject to the "Classpath" exception as provided 48.12 + * by Oracle in the LICENSE file that accompanied this code. 48.13 + * 48.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 48.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 48.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 48.17 + * version 2 for more details (a copy is included in the LICENSE file that 48.18 + * accompanied this code). 48.19 + * 48.20 + * You should have received a copy of the GNU General Public License version 48.21 + * 2 along with this work; if not, write to the Free Software Foundation, 48.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 48.23 + * 48.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 48.25 + * or visit www.oracle.com if you need additional information or have any 48.26 + * questions. 48.27 + */ 48.28 + 48.29 +package org.openjdk.tests.shapegen; 48.30 + 48.31 +import java.util.ArrayList; 48.32 +import java.util.List; 48.33 +import java.util.HashMap; 48.34 +import java.util.HashSet; 48.35 +import java.util.Map; 48.36 +import java.util.Set; 48.37 + 48.38 +import static org.openjdk.tests.shapegen.ClassCase.Kind.*; 48.39 + 48.40 +/** 48.41 + * 48.42 + * @author Robert Field 48.43 + */ 48.44 +public class Hierarchy { 48.45 + 48.46 + public final ClassCase root; 48.47 + public final Set<ClassCase> all; 48.48 + 48.49 + public Hierarchy(ClassCase root) { 48.50 + this.root = root; 48.51 + root.init(new HashMap<String,Integer>()); 48.52 + Set<ClassCase> allClasses = new HashSet<>(); 48.53 + root.collectClasses(allClasses); 48.54 + this.all = allClasses; 48.55 + } 48.56 + 48.57 + public boolean anyDefaults() { 48.58 + for (ClassCase cc : all) { 48.59 + if (cc.kind == IDEFAULT) { 48.60 + return true; 48.61 + } 48.62 + } 48.63 + return false; 48.64 + } 48.65 + 48.66 + public boolean get_OK() { 48.67 + return root.get_OK(); 48.68 + } 48.69 + 48.70 + public String testName() { 48.71 + return root + "Test"; 48.72 + } 48.73 + 48.74 + private static void genInterfaceList(StringBuilder buf, String prefix, List<ClassCase> interfaces) { 48.75 + if (!interfaces.isEmpty()) { 48.76 + buf.append(" "); 48.77 + buf.append(prefix); 48.78 + buf.append(" "); 48.79 + buf.append(interfaces.get(0)); 48.80 + for (int i = 1; i < interfaces.size(); ++i) { 48.81 + buf.append(", " + interfaces.get(i)); 48.82 + } 48.83 + } 48.84 + } 48.85 + 48.86 + public static void genClassDef(StringBuilder buf, ClassCase cc, String implClass, List<ClassCase> defaultRef) { 48.87 + if (cc.isInterface()) { 48.88 + buf.append("interface "); 48.89 + buf.append(cc.getName() + " "); 48.90 + genInterfaceList(buf, "extends", cc.getInterfaces()); 48.91 + buf.append(" {\n"); 48.92 + 48.93 + switch (cc.kind) { 48.94 + case IDEFAULT: 48.95 + buf.append(" default String m() { return \"\"; }\n"); 48.96 + defaultRef.add(cc); 48.97 + break; 48.98 + case IPRESENT: 48.99 + buf.append(" String m();\n"); 48.100 + break; 48.101 + case IVAC: 48.102 + break; 48.103 + default: 48.104 + throw new AssertionError("Unexpected kind"); 48.105 + } 48.106 + buf.append("}\n\n"); 48.107 + } else { 48.108 + buf.append((cc.isAbstract()? "abstract " : "")); 48.109 + buf.append(" class " + cc.getName()); 48.110 + if (cc.getSuperclass() != null) { 48.111 + buf.append(" extends " + cc.getSuperclass()); 48.112 + } 48.113 + 48.114 + genInterfaceList(buf, "implements", cc.getInterfaces()); 48.115 + buf.append(" {\n"); 48.116 + 48.117 + switch (cc.kind) { 48.118 + case CCONCRETE: 48.119 + buf.append(" public String m() { return \"\"; }\n"); 48.120 + break; 48.121 + case CABSTRACT: 48.122 + buf.append(" public abstract String m();\n"); 48.123 + break; 48.124 + case CNONE: 48.125 + break; 48.126 + default: 48.127 + throw new AssertionError("Unexpected kind"); 48.128 + } 48.129 + buf.append("}\n\n"); 48.130 + } 48.131 + } 48.132 + 48.133 + @Override 48.134 + public boolean equals(Object obj) { 48.135 + return obj instanceof Hierarchy && root.getID().equals(((Hierarchy)obj).root.getID()); 48.136 + } 48.137 + 48.138 + @Override 48.139 + public int hashCode() { 48.140 + return root.getID().hashCode(); 48.141 + } 48.142 + 48.143 + @Override 48.144 + public String toString() { 48.145 + return root.getName(); 48.146 + } 48.147 + 48.148 + private static String classNames[] = { 48.149 + "C", "D", "E", "F", "G", "H", "S", "T", "U", "V" 48.150 + }; 48.151 + 48.152 + private static String interfaceNames[] = { 48.153 + "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R" 48.154 + }; 48.155 + 48.156 + private static int CLASS_INDEX = 0; 48.157 + private static int INTERFACE_INDEX = 1; 48.158 + private static int NUM_INDICIES = 2; 48.159 + 48.160 + public List<String> getDescription() { 48.161 + Map<ClassCase,String> nameMap = new HashMap<>(); 48.162 + assignNames(root, new int[NUM_INDICIES], nameMap); 48.163 + 48.164 + ArrayList<String> res = new ArrayList<>(); 48.165 + if (root.getSupertypes().size() == 0) { 48.166 + res.add(nameMap.get(root) + root.kind.getPrefix() + "()"); 48.167 + } else { 48.168 + genCaseDescription(root, res, new HashSet<ClassCase>(), nameMap); 48.169 + } 48.170 + return res; 48.171 + } 48.172 + 48.173 + private static void assignNames( 48.174 + ClassCase cc, int indices[], Map<ClassCase,String> names) { 48.175 + String name = names.get(cc); 48.176 + if (name == null) { 48.177 + if (cc.isInterface()) { 48.178 + names.put(cc, interfaceNames[indices[INTERFACE_INDEX]++]); 48.179 + } else { 48.180 + names.put(cc, classNames[indices[CLASS_INDEX]++]); 48.181 + } 48.182 + for (int i = 0; i < cc.getSupertypes().size(); ++i) { 48.183 + assignNames(cc.getSupertypes().get(i), indices, names); 48.184 + } 48.185 + } 48.186 + } 48.187 + 48.188 + private static void genCaseDescription( 48.189 + ClassCase cc, List<String> res, Set<ClassCase> alreadyDone, 48.190 + Map<ClassCase,String> nameMap) { 48.191 + if (!alreadyDone.contains(cc)) { 48.192 + if (cc.getSupertypes().size() > 0) { 48.193 + StringBuilder sb = new StringBuilder(); 48.194 + sb.append(nameMap.get(cc)); 48.195 + sb.append(cc.kind.getPrefix()); 48.196 + sb.append("("); 48.197 + for (int i = 0; i < cc.getSupertypes().size(); ++i) { 48.198 + ClassCase supertype = cc.getSupertypes().get(i); 48.199 + if (i != 0) { 48.200 + sb.append(","); 48.201 + } 48.202 + genCaseDescription(supertype, res, alreadyDone, nameMap); 48.203 + sb.append(nameMap.get(supertype)); 48.204 + sb.append(supertype.kind.getPrefix()); 48.205 + } 48.206 + sb.append(")"); 48.207 + res.add(sb.toString()); 48.208 + } 48.209 + } 48.210 + alreadyDone.add(cc); 48.211 + } 48.212 +}
49.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 49.2 +++ b/test/tools/javac/lambdaShapes/org/openjdk/tests/shapegen/HierarchyGenerator.java Tue Nov 20 09:58:55 2012 -0800 49.3 @@ -0,0 +1,192 @@ 49.4 +/* 49.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 49.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 49.7 + * 49.8 + * This code is free software; you can redistribute it and/or modify it 49.9 + * under the terms of the GNU General Public License version 2 only, as 49.10 + * published by the Free Software Foundation. Oracle designates this 49.11 + * particular file as subject to the "Classpath" exception as provided 49.12 + * by Oracle in the LICENSE file that accompanied this code. 49.13 + * 49.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 49.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 49.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 49.17 + * version 2 for more details (a copy is included in the LICENSE file that 49.18 + * accompanied this code). 49.19 + * 49.20 + * You should have received a copy of the GNU General Public License version 49.21 + * 2 along with this work; if not, write to the Free Software Foundation, 49.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 49.23 + * 49.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 49.25 + * or visit www.oracle.com if you need additional information or have any 49.26 + * questions. 49.27 + */ 49.28 + 49.29 +package org.openjdk.tests.shapegen; 49.30 + 49.31 +import org.openjdk.tests.shapegen.ClassCase.Kind; 49.32 + 49.33 +import java.util.Collection; 49.34 +import java.util.Set; 49.35 +import java.util.HashSet; 49.36 +import java.util.Collections; 49.37 +import java.util.ArrayList; 49.38 +import java.util.List; 49.39 + 49.40 +import static org.openjdk.tests.shapegen.ClassCase.Kind.*; 49.41 + 49.42 +import static java.lang.Math.pow; 49.43 + 49.44 +/** 49.45 + * 49.46 + * @author Robert Field 49.47 + */ 49.48 +public final class HierarchyGenerator { 49.49 + 49.50 + private int okcnt = 0; 49.51 + private int errcnt = 0; 49.52 + private Set<Hierarchy> uniqueOK = new HashSet<>(); 49.53 + private Set<Hierarchy> uniqueErr = new HashSet<>(); 49.54 + 49.55 + /** 49.56 + * @param args the command line arguments 49.57 + */ 49.58 + public HierarchyGenerator() { 49.59 + organize("exhaustive interface", iExhaustive(2)); 49.60 + organize("exhaustive class", cExhaustive()); 49.61 + organize("shapes interface", iShapes()); 49.62 + organize("shapes class/interface", ciShapes()); 49.63 + 49.64 + System.out.printf("\nExpect OK: %d -- unique %d", okcnt, uniqueOK.size()); 49.65 + System.out.printf("\nExpect Error: %d -- unique %d\n", errcnt, uniqueErr.size()); 49.66 + } 49.67 + 49.68 + public Collection<Hierarchy> getOK() { 49.69 + return uniqueOK; 49.70 + } 49.71 + 49.72 + public Collection<Hierarchy> getErr() { 49.73 + return uniqueErr; 49.74 + } 49.75 + 49.76 + private void organize(String tname, List<Hierarchy> totest) { 49.77 + System.out.printf("\nGenerating %s....\n", tname); 49.78 + int nodefault = 0; 49.79 + List<Hierarchy> ok = new ArrayList<>(); 49.80 + List<Hierarchy> err = new ArrayList<>(); 49.81 + for (Hierarchy cc : totest) { 49.82 + if (cc.anyDefaults()) { 49.83 + //System.out.printf(" %s\n", cc); 49.84 + if (cc.get_OK()) { 49.85 + ok.add(cc); 49.86 + } else { 49.87 + err.add(cc); 49.88 + } 49.89 + } else { 49.90 + ++nodefault; 49.91 + } 49.92 + } 49.93 + 49.94 + errcnt += err.size(); 49.95 + okcnt += ok.size(); 49.96 + uniqueErr.addAll(err); 49.97 + uniqueOK.addAll(ok); 49.98 + 49.99 + System.out.printf(" %5d No default\n %5d Error\n %5d OK\n %5d Total\n", 49.100 + nodefault, err.size(), ok.size(), totest.size()); 49.101 + } 49.102 + 49.103 + public List<Hierarchy> iExhaustive(int idepth) { 49.104 + List<ClassCase> current = new ArrayList<>(); 49.105 + for (int i = 0; i < idepth; ++i) { 49.106 + current = ilayer(current); 49.107 + } 49.108 + return wrapInClassAndHierarchy(current); 49.109 + } 49.110 + 49.111 + private List<ClassCase> ilayer(List<ClassCase> srcLayer) { 49.112 + List<ClassCase> lay = new ArrayList<>(); 49.113 + for (int i = (int) pow(2, srcLayer.size()) - 1; i >= 0; --i) { 49.114 + List<ClassCase> itfs = new ArrayList<>(); 49.115 + for (int b = srcLayer.size() - 1; b >= 0; --b) { 49.116 + if ((i & (1<<b)) != 0) { 49.117 + itfs.add(srcLayer.get(b)); 49.118 + } 49.119 + } 49.120 + lay.add(new ClassCase(IVAC, null, itfs)); 49.121 + lay.add(new ClassCase(IPRESENT, null, itfs)); 49.122 + lay.add(new ClassCase(IDEFAULT, null, itfs)); 49.123 + lay.add(new ClassCase(IDEFAULT, null, itfs)); 49.124 + } 49.125 + return lay; 49.126 + } 49.127 + 49.128 + public List<Hierarchy> cExhaustive() { 49.129 + final Kind[] iKinds = new Kind[]{IDEFAULT, IVAC, IPRESENT, null}; 49.130 + final Kind[] cKinds = new Kind[]{CNONE, CABSTRACT, CCONCRETE}; 49.131 + List<Hierarchy> totest = new ArrayList<>(); 49.132 + for (int i1 = 0; i1 < iKinds.length; ++i1) { 49.133 + for (int i2 = 0; i2 < iKinds.length; ++i2) { 49.134 + for (int i3 = 0; i3 < iKinds.length; ++i3) { 49.135 + for (int c1 = 0; c1 < cKinds.length; ++c1) { 49.136 + for (int c2 = 0; c2 < cKinds.length; ++c2) { 49.137 + for (int c3 = 0; c3 < cKinds.length; ++c3) { 49.138 + totest.add( new Hierarchy( 49.139 + new ClassCase(cKinds[c1], 49.140 + new ClassCase(cKinds[c2], 49.141 + new ClassCase(cKinds[c3], 49.142 + null, 49.143 + iList(iKinds[i1]) 49.144 + ), 49.145 + iList(iKinds[i2]) 49.146 + ), 49.147 + iList(iKinds[i3]) 49.148 + ))); 49.149 + } 49.150 + } 49.151 + } 49.152 + } 49.153 + } 49.154 + } 49.155 + return totest; 49.156 + } 49.157 + 49.158 + public static final List<ClassCase> EMPTY_LIST = new ArrayList<>(); 49.159 + 49.160 + private List<ClassCase> iList(Kind kind) { 49.161 + if (kind == null) { 49.162 + return EMPTY_LIST; 49.163 + } else { 49.164 + List<ClassCase> itfs = new ArrayList<>(); 49.165 + itfs.add(new ClassCase(kind, null, EMPTY_LIST)); 49.166 + return itfs; 49.167 + } 49.168 + } 49.169 + 49.170 + public List<Hierarchy> ciShapes() { 49.171 + return wrapInHierarchy(TTShape.allCases(true)); 49.172 + } 49.173 + 49.174 + public List<Hierarchy> iShapes() { 49.175 + return wrapInClassAndHierarchy(TTShape.allCases(false)); 49.176 + } 49.177 + 49.178 + public List<Hierarchy> wrapInClassAndHierarchy(List<ClassCase> ihs) { 49.179 + List<Hierarchy> totest = new ArrayList<>(); 49.180 + for (ClassCase cc : ihs) { 49.181 + List<ClassCase> interfaces = new ArrayList<>(); 49.182 + interfaces.add(cc); 49.183 + totest.add(new Hierarchy(new ClassCase(CNONE, null, interfaces))); 49.184 + } 49.185 + return totest; 49.186 + } 49.187 + 49.188 + public List<Hierarchy> wrapInHierarchy(List<ClassCase> ihs) { 49.189 + List<Hierarchy> totest = new ArrayList<>(); 49.190 + for (ClassCase cc : ihs) { 49.191 + totest.add(new Hierarchy(cc)); 49.192 + } 49.193 + return totest; 49.194 + } 49.195 +}
50.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 50.2 +++ b/test/tools/javac/lambdaShapes/org/openjdk/tests/shapegen/Rule.java Tue Nov 20 09:58:55 2012 -0800 50.3 @@ -0,0 +1,48 @@ 50.4 +/* 50.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 50.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 50.7 + * 50.8 + * This code is free software; you can redistribute it and/or modify it 50.9 + * under the terms of the GNU General Public License version 2 only, as 50.10 + * published by the Free Software Foundation. Oracle designates this 50.11 + * particular file as subject to the "Classpath" exception as provided 50.12 + * by Oracle in the LICENSE file that accompanied this code. 50.13 + * 50.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 50.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 50.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 50.17 + * version 2 for more details (a copy is included in the LICENSE file that 50.18 + * accompanied this code). 50.19 + * 50.20 + * You should have received a copy of the GNU General Public License version 50.21 + * 2 along with this work; if not, write to the Free Software Foundation, 50.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 50.23 + * 50.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 50.25 + * or visit www.oracle.com if you need additional information or have any 50.26 + * questions. 50.27 + */ 50.28 + 50.29 +package org.openjdk.tests.shapegen; 50.30 + 50.31 +/** 50.32 + * 50.33 + * @author Robert Field 50.34 + */ 50.35 +public abstract class Rule { 50.36 + 50.37 + public final String name; 50.38 + 50.39 + public Rule(String name) { 50.40 + this.name = name; 50.41 + } 50.42 + 50.43 + abstract boolean guard(ClassCase cc); 50.44 + 50.45 + abstract void eval(ClassCase cc); 50.46 + 50.47 + @Override 50.48 + public String toString() { 50.49 + return name; 50.50 + } 50.51 +}
51.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 51.2 +++ b/test/tools/javac/lambdaShapes/org/openjdk/tests/shapegen/RuleGroup.java Tue Nov 20 09:58:55 2012 -0800 51.3 @@ -0,0 +1,206 @@ 51.4 +/* 51.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 51.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 51.7 + * 51.8 + * This code is free software; you can redistribute it and/or modify it 51.9 + * under the terms of the GNU General Public License version 2 only, as 51.10 + * published by the Free Software Foundation. Oracle designates this 51.11 + * particular file as subject to the "Classpath" exception as provided 51.12 + * by Oracle in the LICENSE file that accompanied this code. 51.13 + * 51.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 51.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 51.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 51.17 + * version 2 for more details (a copy is included in the LICENSE file that 51.18 + * accompanied this code). 51.19 + * 51.20 + * You should have received a copy of the GNU General Public License version 51.21 + * 2 along with this work; if not, write to the Free Software Foundation, 51.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 51.23 + * 51.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 51.25 + * or visit www.oracle.com if you need additional information or have any 51.26 + * questions. 51.27 + */ 51.28 + 51.29 +package org.openjdk.tests.shapegen; 51.30 + 51.31 +import java.util.HashSet; 51.32 +import java.util.Set; 51.33 + 51.34 +import static org.openjdk.tests.shapegen.ClassCase.Kind.*; 51.35 + 51.36 +/** 51.37 + * 51.38 + * @author Robert Field 51.39 + */ 51.40 +public class RuleGroup { 51.41 + 51.42 + final String name; 51.43 + private final Rule[] rules; 51.44 + 51.45 + public RuleGroup(String name, Rule[] rules) { 51.46 + this.name = name; 51.47 + this.rules = rules; 51.48 + } 51.49 + 51.50 + public boolean exec(ClassCase cc) { 51.51 + boolean found = false; 51.52 + for (Rule rule : rules) { 51.53 + if (rule.guard(cc)) { 51.54 + if (found) { 51.55 + throw new RuntimeException("Bad rules -- multiple matches " + toString() + " for " + cc); 51.56 + } else { 51.57 + rule.eval(cc); 51.58 + found = true; 51.59 + } 51.60 + } 51.61 + } 51.62 + return found; 51.63 + } 51.64 + 51.65 + @Override 51.66 + public String toString() { 51.67 + return name; 51.68 + } 51.69 + 51.70 + public static RuleGroup PROVENENCE = new RuleGroup("Provenence", new Rule[] { 51.71 + new Rule("P-CDeclare") { 51.72 + boolean guard(ClassCase cc) { 51.73 + return cc.isa(CCONCRETE, CABSTRACT); 51.74 + } 51.75 + 51.76 + void eval(ClassCase cc) { 51.77 + cc.set_mprov(cc); 51.78 + cc.set_HasClassMethod(true); 51.79 + } 51.80 + }, 51.81 + 51.82 + new Rule("P-IDeclare") { 51.83 + boolean guard(ClassCase cc) { 51.84 + return cc.isa(IDEFAULT, IPRESENT); 51.85 + } 51.86 + 51.87 + void eval(ClassCase cc) { 51.88 + cc.set_mprov(cc); 51.89 + } 51.90 + }, 51.91 + 51.92 + new Rule("P-IntfInh") { 51.93 + boolean guard(ClassCase cc) { 51.94 + return cc.isa(IVAC, CNONE) && !(cc.hasSuperclass() && cc.getSuperclass().get_HasClassMethod()); 51.95 + } 51.96 + 51.97 + void eval(ClassCase cc) { 51.98 + Set<ClassCase> _S = new HashSet<>(); 51.99 + for (ClassCase t : cc.getSupertypes()) { 51.100 + _S.addAll(t.get_mprov()); 51.101 + } 51.102 + Set<ClassCase> tops = new HashSet<>(); 51.103 + for (ClassCase _W : _S) { 51.104 + for (ClassCase _V : _S) { 51.105 + if (_V.equals(_W) || !(_V.isSubtypeOf(_W))) { 51.106 + tops.add(_W); 51.107 + } 51.108 + } 51.109 + } 51.110 + cc.set_mprov(tops); 51.111 + } 51.112 + }, 51.113 + 51.114 + new Rule("P-ClassInh") { 51.115 + boolean guard(ClassCase cc) { 51.116 + return cc.isa(CNONE) && (cc.hasSuperclass() && cc.getSuperclass().get_HasClassMethod()); 51.117 + } 51.118 + 51.119 + void eval(ClassCase cc) { 51.120 + cc.set_mprov(cc.getSuperclass()); 51.121 + cc.set_HasClassMethod(true); 51.122 + } 51.123 + }, 51.124 + 51.125 + }); 51.126 + 51.127 + public static RuleGroup MARKER = new RuleGroup("Marker", new Rule[] { 51.128 + new Rule("M-Default") { 51.129 + boolean guard(ClassCase cc) { 51.130 + return cc.isa(IDEFAULT); 51.131 + } 51.132 + 51.133 + void eval(ClassCase cc) { 51.134 + cc.set_HasDefault(true); 51.135 + } 51.136 + }, 51.137 + 51.138 + new Rule("M-Conc") { 51.139 + boolean guard(ClassCase cc) { 51.140 + return cc.isa(CCONCRETE); 51.141 + } 51.142 + 51.143 + void eval(ClassCase cc) { 51.144 + cc.set_IsConcrete(true); 51.145 + } 51.146 + }, 51.147 + 51.148 + }); 51.149 + 51.150 + public static RuleGroup RESOLUTION = new RuleGroup("Resolution", new Rule[] { 51.151 + new Rule("R-Resolve") { 51.152 + boolean guard(ClassCase cc) { 51.153 + if (!(cc.isClass() && cc.get_mprov().size() == 1)) { 51.154 + return false; 51.155 + } 51.156 + ClassCase _V = cc.get_mprov().iterator().next(); 51.157 + return _V.get_IsConcrete() || _V.get_HasDefault(); 51.158 + } 51.159 + 51.160 + void eval(ClassCase cc) { 51.161 + ClassCase _V = cc.get_mprov().iterator().next(); 51.162 + cc.set_mres(_V); 51.163 + } 51.164 + }, 51.165 + 51.166 + }); 51.167 + 51.168 + public static RuleGroup DEFENDER = new RuleGroup("Defender", new Rule[] { 51.169 + new Rule("D-Defend") { 51.170 + boolean guard(ClassCase cc) { 51.171 + ClassCase mresSuper = cc.hasSuperclass() ? cc.getSuperclass().get_mres() : null; 51.172 + boolean eq = cc.get_mres() == null ? mresSuper == null : cc.get_mres().equals(mresSuper); 51.173 + return cc.isa(CNONE) && !eq; 51.174 + } 51.175 + 51.176 + void eval(ClassCase cc) { 51.177 + cc.set_mdefend(cc.get_mres()); 51.178 + } 51.179 + }, 51.180 + 51.181 + }); 51.182 + 51.183 + public static RuleGroup CHECKING = new RuleGroup("Checking", new Rule[] { 51.184 + new Rule("C-Check") { 51.185 + boolean guard(ClassCase cc) { 51.186 + for (ClassCase t : cc.getSupertypes()) { 51.187 + if (! t.get_OK()) { 51.188 + return false; 51.189 + } 51.190 + } 51.191 + int defenderCount = 0; 51.192 + int provCount = 0; 51.193 + for (ClassCase prov : cc.get_mprov()) { 51.194 + if (prov.get_HasDefault()) { 51.195 + defenderCount++; 51.196 + } 51.197 + provCount++; 51.198 + } 51.199 + return provCount <= 1 || defenderCount == 0; 51.200 + } 51.201 + 51.202 + void eval(ClassCase cc) { 51.203 + cc.set_OK(true); 51.204 + } 51.205 + }, 51.206 + 51.207 + }); 51.208 + 51.209 +}
52.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 52.2 +++ b/test/tools/javac/lambdaShapes/org/openjdk/tests/shapegen/TTNode.java Tue Nov 20 09:58:55 2012 -0800 52.3 @@ -0,0 +1,126 @@ 52.4 +/* 52.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 52.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 52.7 + * 52.8 + * This code is free software; you can redistribute it and/or modify it 52.9 + * under the terms of the GNU General Public License version 2 only, as 52.10 + * published by the Free Software Foundation. Oracle designates this 52.11 + * particular file as subject to the "Classpath" exception as provided 52.12 + * by Oracle in the LICENSE file that accompanied this code. 52.13 + * 52.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 52.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 52.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 52.17 + * version 2 for more details (a copy is included in the LICENSE file that 52.18 + * accompanied this code). 52.19 + * 52.20 + * You should have received a copy of the GNU General Public License version 52.21 + * 2 along with this work; if not, write to the Free Software Foundation, 52.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 52.23 + * 52.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 52.25 + * or visit www.oracle.com if you need additional information or have any 52.26 + * questions. 52.27 + */ 52.28 + 52.29 +package org.openjdk.tests.shapegen; 52.30 + 52.31 +import org.openjdk.tests.shapegen.ClassCase.Kind; 52.32 + 52.33 +import java.util.ArrayList; 52.34 +import java.util.List; 52.35 +import java.util.Set; 52.36 + 52.37 +import static org.openjdk.tests.shapegen.ClassCase.Kind.*; 52.38 + 52.39 +/** 52.40 + * Type Template Node 52.41 + * 52.42 + * @author Robert Field 52.43 + */ 52.44 +public class TTNode { 52.45 + 52.46 + final List<TTNode> supertypes; 52.47 + final boolean canBeClass; 52.48 + 52.49 + private int currentKindIndex; 52.50 + private Kind[] kinds; 52.51 + 52.52 + public TTNode(List<TTNode> subtypes, boolean canBeClass) { 52.53 + this.supertypes = subtypes; 52.54 + this.canBeClass = canBeClass; 52.55 + } 52.56 + 52.57 + public void start(boolean includeClasses) { 52.58 + kinds = 52.59 + supertypes.isEmpty()? 52.60 + (new Kind[]{IDEFAULT, IPRESENT}) 52.61 + : ((includeClasses && canBeClass)? 52.62 + new Kind[]{CNONE, IVAC, IDEFAULT, IPRESENT} 52.63 + : new Kind[]{IVAC, IDEFAULT, IPRESENT}); 52.64 + currentKindIndex = 0; 52.65 + 52.66 + for (TTNode sub : supertypes) { 52.67 + sub.start(includeClasses); 52.68 + } 52.69 + } 52.70 + 52.71 + public boolean next() { 52.72 + ++currentKindIndex; 52.73 + if (currentKindIndex >= kinds.length) { 52.74 + currentKindIndex = 0; 52.75 + return false; 52.76 + } else { 52.77 + return true; 52.78 + } 52.79 + } 52.80 + 52.81 + public void collectAllSubtypes(Set<TTNode> subs) { 52.82 + subs.add(this); 52.83 + for (TTNode n : supertypes) { 52.84 + n.collectAllSubtypes(subs); 52.85 + } 52.86 + } 52.87 + 52.88 + private Kind getKind() { 52.89 + return kinds[currentKindIndex]; 52.90 + } 52.91 + 52.92 + boolean isInterface() { 52.93 + return getKind().isInterface; 52.94 + } 52.95 + 52.96 + boolean isClass() { 52.97 + return !isInterface(); 52.98 + } 52.99 + 52.100 + boolean hasDefault() { 52.101 + return getKind() == IDEFAULT; 52.102 + } 52.103 + 52.104 + public boolean isValid() { 52.105 + for (TTNode n : supertypes) { 52.106 + if (!n.isValid() || (isInterface() && n.isClass())) { 52.107 + return false; 52.108 + } 52.109 + } 52.110 + return true; 52.111 + } 52.112 + 52.113 + public ClassCase genCase() { 52.114 + ClassCase subclass; 52.115 + List<TTNode> ttintfs; 52.116 + if (isClass() && !supertypes.isEmpty() && supertypes.get(0).isClass()) { 52.117 + subclass = supertypes.get(0).genCase(); 52.118 + ttintfs = supertypes.subList(1, supertypes.size()); 52.119 + } else { 52.120 + subclass = null; 52.121 + ttintfs = supertypes; 52.122 + } 52.123 + List<ClassCase> intfs = new ArrayList<>(); 52.124 + for (TTNode node : ttintfs) { 52.125 + intfs.add(node.genCase()); 52.126 + } 52.127 + return new ClassCase(getKind(), subclass, intfs); 52.128 + } 52.129 +}
53.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 53.2 +++ b/test/tools/javac/lambdaShapes/org/openjdk/tests/shapegen/TTParser.java Tue Nov 20 09:58:55 2012 -0800 53.3 @@ -0,0 +1,100 @@ 53.4 +/* 53.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 53.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 53.7 + * 53.8 + * This code is free software; you can redistribute it and/or modify it 53.9 + * under the terms of the GNU General Public License version 2 only, as 53.10 + * published by the Free Software Foundation. Oracle designates this 53.11 + * particular file as subject to the "Classpath" exception as provided 53.12 + * by Oracle in the LICENSE file that accompanied this code. 53.13 + * 53.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 53.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 53.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 53.17 + * version 2 for more details (a copy is included in the LICENSE file that 53.18 + * accompanied this code). 53.19 + * 53.20 + * You should have received a copy of the GNU General Public License version 53.21 + * 2 along with this work; if not, write to the Free Software Foundation, 53.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 53.23 + * 53.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 53.25 + * or visit www.oracle.com if you need additional information or have any 53.26 + * questions. 53.27 + */ 53.28 + 53.29 +package org.openjdk.tests.shapegen; 53.30 + 53.31 +import java.util.ArrayList; 53.32 +import java.util.HashMap; 53.33 +import java.util.List; 53.34 +import java.util.Map; 53.35 +import java.io.IOException; 53.36 +import java.io.StringReader; 53.37 + 53.38 +import static java.lang.Character.isLetter; 53.39 +import static java.lang.Character.isUpperCase; 53.40 +import static java.lang.Character.isWhitespace; 53.41 + 53.42 +/** 53.43 + * Parse a type template definition string 53.44 + * 53.45 + * input :: classDef 53.46 + * classDef :: letter [ ( classDef* ) ] 53.47 + * 53.48 + * @author Robert Field 53.49 + */ 53.50 +public class TTParser extends StringReader { 53.51 + 53.52 + private Map<Character, TTNode> letterMap = new HashMap<>(); 53.53 + private char ch; 53.54 + 53.55 + private final String def; 53.56 + 53.57 + public TTParser(String s) { 53.58 + super(s); 53.59 + this.def = s; 53.60 + } 53.61 + 53.62 + private void advance() throws IOException { 53.63 + do { 53.64 + ch = (char)read(); 53.65 + } while (isWhitespace(ch)); 53.66 + } 53.67 + 53.68 + public TTNode parse() { 53.69 + try { 53.70 + advance(); 53.71 + return classDef(); 53.72 + } catch (IOException t) { 53.73 + throw new RuntimeException(t); 53.74 + } 53.75 + } 53.76 + 53.77 + private TTNode classDef() throws IOException { 53.78 + if (!isLetter(ch)) { 53.79 + if (ch == (char)-1) { 53.80 + throw new IOException("Unexpected end of type template in " + def); 53.81 + } else { 53.82 + throw new IOException("Unexpected character in type template: " + (Character)ch + " in " + def); 53.83 + } 53.84 + } 53.85 + char nodeCh = ch; 53.86 + TTNode node = letterMap.get(nodeCh); 53.87 + boolean canBeClass = isUpperCase(nodeCh); 53.88 + advance(); 53.89 + if (node == null) { 53.90 + List<TTNode> subtypes = new ArrayList<>(); 53.91 + if (ch == '(') { 53.92 + advance(); 53.93 + while (ch != ')') { 53.94 + subtypes.add(classDef()); 53.95 + } 53.96 + advance(); 53.97 + } 53.98 + node = new TTNode(subtypes, canBeClass); 53.99 + letterMap.put(nodeCh, node); 53.100 + } 53.101 + return node; 53.102 + } 53.103 +}
54.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 54.2 +++ b/test/tools/javac/lambdaShapes/org/openjdk/tests/shapegen/TTShape.java Tue Nov 20 09:58:55 2012 -0800 54.3 @@ -0,0 +1,104 @@ 54.4 +/* 54.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 54.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 54.7 + * 54.8 + * This code is free software; you can redistribute it and/or modify it 54.9 + * under the terms of the GNU General Public License version 2 only, as 54.10 + * published by the Free Software Foundation. Oracle designates this 54.11 + * particular file as subject to the "Classpath" exception as provided 54.12 + * by Oracle in the LICENSE file that accompanied this code. 54.13 + * 54.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 54.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 54.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 54.17 + * version 2 for more details (a copy is included in the LICENSE file that 54.18 + * accompanied this code). 54.19 + * 54.20 + * You should have received a copy of the GNU General Public License version 54.21 + * 2 along with this work; if not, write to the Free Software Foundation, 54.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 54.23 + * 54.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 54.25 + * or visit www.oracle.com if you need additional information or have any 54.26 + * questions. 54.27 + */ 54.28 + 54.29 +package org.openjdk.tests.shapegen; 54.30 + 54.31 +import java.util.ArrayList; 54.32 +import java.util.HashSet; 54.33 +import java.util.List; 54.34 +import java.util.Set; 54.35 + 54.36 +/** 54.37 + * 54.38 + * @author Robert Field 54.39 + */ 54.40 +public class TTShape { 54.41 + 54.42 + private final TTNode root; 54.43 + private final TTNode[] nodes; 54.44 + 54.45 + TTShape(TTNode root) { 54.46 + this.root = root; 54.47 + Set<TTNode> subs = new HashSet<>(); 54.48 + root.collectAllSubtypes(subs); 54.49 + nodes = subs.toArray(new TTNode[subs.size()]); 54.50 + } 54.51 + 54.52 + private List<ClassCase> toCases(boolean includeClasses) { 54.53 + List<ClassCase> ccs = new ArrayList<>(); 54.54 + root.start(includeClasses); 54.55 + int i; 54.56 + outer: 54.57 + while (true) { 54.58 + if (root.isValid()) { 54.59 + ClassCase cc = root.genCase(); 54.60 + //System.out.println(cc); 54.61 + ccs.add(cc); 54.62 + } 54.63 + 54.64 + i = 0; 54.65 + do { 54.66 + if (i >= nodes.length) { 54.67 + break outer; 54.68 + } 54.69 + } while(!nodes[i++].next()); 54.70 + } 54.71 + return ccs; 54.72 + } 54.73 + 54.74 + public static List<ClassCase> allCases(boolean includeClasses) { 54.75 + List<ClassCase> ccs = new ArrayList<>(); 54.76 + for (TTShape shape : SHAPES) { 54.77 + ccs.addAll(shape.toCases(includeClasses)); 54.78 + } 54.79 + return ccs; 54.80 + } 54.81 + 54.82 + public static TTShape parse(String s) { 54.83 + return new TTShape(new TTParser(s).parse()); 54.84 + } 54.85 + 54.86 + public static final TTShape[] SHAPES = new TTShape[] { 54.87 + parse("a"), 54.88 + parse("a(b)"), 54.89 + parse("A(bb)"), 54.90 + parse("A(B(d)c(d))"), 54.91 + parse("A(b(c))"), 54.92 + parse("A(B(cd)d)"), 54.93 + parse("A(B(c)c)"), 54.94 + parse("A(B(Ce)d(e))"), 54.95 + parse("A(B(C)d(e))"), 54.96 + parse("A(Bc(d))"), 54.97 + parse("A(B(d)dc)"), 54.98 + parse("A(B(dc)dc)"), 54.99 + parse("A(B(c(d))d)"), 54.100 + parse("A(B(C(d))d)"), 54.101 + parse("A(B(C(e)d(e))e)"), 54.102 + parse("A(B(c(d))c)"), 54.103 + parse("A(B(dc(d))c)"), 54.104 + parse("A(B(C(d))d)"), 54.105 + }; 54.106 + 54.107 +}
55.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 55.2 +++ b/test/tools/javac/lambdaShapes/org/openjdk/tests/vm/DefaultMethodsTest.java Tue Nov 20 09:58:55 2012 -0800 55.3 @@ -0,0 +1,826 @@ 55.4 +/* 55.5 + * Copyright (c) 2012 Oracle and/or its affiliates. All rights reserved. 55.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 55.7 + * 55.8 + * This code is free software; you can redistribute it and/or modify it 55.9 + * under the terms of the GNU General Public License version 2 only, as 55.10 + * published by the Free Software Foundation. Oracle designates this 55.11 + * particular file as subject to the "Classpath" exception as provided 55.12 + * by Oracle in the LICENSE file that accompanied this code. 55.13 + * 55.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 55.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 55.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 55.17 + * version 2 for more details (a copy is included in the LICENSE file that 55.18 + * accompanied this code). 55.19 + * 55.20 + * You should have received a copy of the GNU General Public License version 55.21 + * 2 along with this work; if not, write to the Free Software Foundation, 55.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 55.23 + * 55.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 55.25 + * or visit www.oracle.com if you need additional information or have any 55.26 + * questions. 55.27 + */ 55.28 + 55.29 +package org.openjdk.tests.vm; 55.30 + 55.31 +import java.lang.reflect.*; 55.32 +import java.util.*; 55.33 +import java.io.File; 55.34 +import java.io.IOException; 55.35 + 55.36 +import org.testng.annotations.Test; 55.37 +import org.openjdk.tests.separate.*; 55.38 +import org.openjdk.tests.separate.Compiler; 55.39 + 55.40 +import static org.testng.Assert.*; 55.41 +import static org.openjdk.tests.separate.SourceModel.*; 55.42 +import static org.openjdk.tests.separate.SourceModel.Class; 55.43 + 55.44 +@Test(groups = "vm") 55.45 +public class DefaultMethodsTest extends TestHarness { 55.46 + public DefaultMethodsTest() { 55.47 + super(false, false); 55.48 + } 55.49 + 55.50 + /** 55.51 + * class C { public int m() { return 22; } } 55.52 + * 55.53 + * TEST: C c = new C(); c.m() == 22 55.54 + */ 55.55 + public void testHarnessInvokeVirtual() { 55.56 + Class C = new Class("C", ConcreteMethod.std("22")); 55.57 + assertInvokeVirtualEquals(22, C); 55.58 + } 55.59 + 55.60 + /** 55.61 + * interface I { int m(); } 55.62 + * class C implements I { public int m() { return 33; } } 55.63 + * 55.64 + * TEST: I i = new C(); i.m() == 33; 55.65 + */ 55.66 + public void testHarnessInvokeInterface() { 55.67 + Interface I = new Interface("I", AbstractMethod.std()); 55.68 + Class C = new Class("C", I, ConcreteMethod.std("33")); 55.69 + assertInvokeInterfaceEquals(33, C, I); 55.70 + } 55.71 + 55.72 + /** 55.73 + * class C {} 55.74 + * 55.75 + * TEST: C c = new C(); c.m() throws NoSuchMethod 55.76 + */ 55.77 + public void testHarnessThrows() { 55.78 + Class C = new Class("C"); 55.79 + assertThrows(NoSuchMethodError.class, C); 55.80 + } 55.81 + 55.82 + /** 55.83 + * interface I { int m() default { return 44; } } 55.84 + * class C implements I {} 55.85 + * 55.86 + * TEST: C c = new C(); c.m() == 44; 55.87 + * TEST: I i = new C(); i.m() == 44; 55.88 + */ 55.89 + public void testBasicDefault() { 55.90 + Interface I = new Interface("I", DefaultMethod.std("44")); 55.91 + Class C = new Class("C", I); 55.92 + 55.93 + assertInvokeVirtualEquals(44, C); 55.94 + assertInvokeInterfaceEquals(44, C, I); 55.95 + } 55.96 + 55.97 + /** 55.98 + * interface I { default int m() { return 44; } } 55.99 + * interface J extends I {} 55.100 + * interface K extends J {} 55.101 + * class C implements K {} 55.102 + * 55.103 + * TEST: C c = new C(); c.m() == 44; 55.104 + * TEST: I i = new C(); i.m() == 44; 55.105 + */ 55.106 + public void testFarDefault() { 55.107 + Interface I = new Interface("I", DefaultMethod.std("44")); 55.108 + Interface J = new Interface("J", I); 55.109 + Interface K = new Interface("K", J); 55.110 + Class C = new Class("C", K); 55.111 + 55.112 + assertInvokeVirtualEquals(44, C); 55.113 + assertInvokeInterfaceEquals(44, C, K); 55.114 + } 55.115 + 55.116 + /** 55.117 + * interface I { int m(); } 55.118 + * interface J extends I { default int m() { return 44; } } 55.119 + * interface K extends J {} 55.120 + * class C implements K {} 55.121 + * 55.122 + * TEST: C c = new C(); c.m() == 44; 55.123 + * TEST: K k = new C(); k.m() == 44; 55.124 + */ 55.125 + public void testOverrideAbstract() { 55.126 + Interface I = new Interface("I", AbstractMethod.std()); 55.127 + Interface J = new Interface("J", I, DefaultMethod.std("44")); 55.128 + Interface K = new Interface("K", J); 55.129 + Class C = new Class("C", K); 55.130 + 55.131 + assertInvokeVirtualEquals(44, C); 55.132 + assertInvokeInterfaceEquals(44, C, K); 55.133 + } 55.134 + 55.135 + /** 55.136 + * interface I { int m() default { return 44; } } 55.137 + * class C implements I { public int m() { return 55; } } 55.138 + * 55.139 + * TEST: C c = new C(); c.m() == 55; 55.140 + * TEST: I i = new C(); i.m() == 55; 55.141 + */ 55.142 + public void testExisting() { 55.143 + Interface I = new Interface("I", DefaultMethod.std("44")); 55.144 + Class C = new Class("C", I, ConcreteMethod.std("55")); 55.145 + 55.146 + assertInvokeVirtualEquals(55, C); 55.147 + assertInvokeInterfaceEquals(55, C, I); 55.148 + } 55.149 + 55.150 + /** 55.151 + * interface I { default int m() { return 99; } } 55.152 + * class B implements I {} 55.153 + * class C extends B {} 55.154 + * 55.155 + * TEST: C c = new C(); c.m() == 99; 55.156 + * TEST: I i = new C(); i.m() == 99; 55.157 + */ 55.158 + public void testInherited() { 55.159 + Interface I = new Interface("I", DefaultMethod.std("99")); 55.160 + Class B = new Class("B", I); 55.161 + Class C = new Class("C", B); 55.162 + 55.163 + assertInvokeVirtualEquals(99, C); 55.164 + assertInvokeInterfaceEquals(99, C, I); 55.165 + } 55.166 + 55.167 + /** 55.168 + * interface I { default int m() { return 99; } } 55.169 + * class C { public int m() { return 11; } } 55.170 + * class D extends C implements I {} 55.171 + * 55.172 + * TEST: D d = new D(); d.m() == 11; 55.173 + * TEST: I i = new D(); i.m() == 11; 55.174 + */ 55.175 + public void testExistingInherited() { 55.176 + Interface I = new Interface("I", DefaultMethod.std("99")); 55.177 + Class C = new Class("C", ConcreteMethod.std("11")); 55.178 + Class D = new Class("D", C, I); 55.179 + 55.180 + assertInvokeVirtualEquals(11, D); 55.181 + assertInvokeInterfaceEquals(11, D, I); 55.182 + } 55.183 + 55.184 + /** 55.185 + * interface I { default int m() { return 44; } } 55.186 + * class C implements I { public int m() { return 11; } } 55.187 + * class D extends C { public int m() { return 22; } } 55.188 + * 55.189 + * TEST: D d = new D(); d.m() == 22; 55.190 + * TEST: I i = new D(); i.m() == 22; 55.191 + */ 55.192 + void testExistingInheritedOverride() { 55.193 + Interface I = new Interface("I", DefaultMethod.std("99")); 55.194 + Class C = new Class("C", I, ConcreteMethod.std("11")); 55.195 + Class D = new Class("D", C, ConcreteMethod.std("22")); 55.196 + 55.197 + assertInvokeVirtualEquals(22, D); 55.198 + assertInvokeInterfaceEquals(22, D, I); 55.199 + } 55.200 + 55.201 + /** 55.202 + * interface I { default int m() { return 99; } } 55.203 + * interface J { defaultint m() { return 88; } } 55.204 + * class C implements I { public int m() { return 11; } } 55.205 + * class D extends C { public int m() { return 22; } } 55.206 + * class E extends D implements J {} 55.207 + * 55.208 + * TEST: E e = new E(); e.m() == 22; 55.209 + * TEST: J j = new E(); j.m() == 22; 55.210 + */ 55.211 + public void testExistingInheritedPlusDefault() { 55.212 + Interface I = new Interface("I", DefaultMethod.std("99")); 55.213 + Interface J = new Interface("J", DefaultMethod.std("88")); 55.214 + Class C = new Class("C", I, ConcreteMethod.std("11")); 55.215 + Class D = new Class("D", C, ConcreteMethod.std("22")); 55.216 + Class E = new Class("E", D, J); 55.217 + 55.218 + assertInvokeVirtualEquals(22, E); 55.219 + assertInvokeInterfaceEquals(22, E, J); 55.220 + } 55.221 + 55.222 + /** 55.223 + * interface I { default int m() { return 99; } } 55.224 + * class B implements I {} 55.225 + * class C extends B { public int m() { return 77; } } 55.226 + * 55.227 + * TEST: C c = new C(); c.m() == 77; 55.228 + * TEST: I i = new C(); i.m() == 77; 55.229 + */ 55.230 + public void testInheritedWithConcrete() { 55.231 + Interface I = new Interface("I", DefaultMethod.std("99")); 55.232 + Class B = new Class("B", I); 55.233 + Class C = new Class("C", B, ConcreteMethod.std("77")); 55.234 + 55.235 + assertInvokeVirtualEquals(77, C); 55.236 + assertInvokeInterfaceEquals(77, C, I); 55.237 + } 55.238 + 55.239 + /** 55.240 + * interface I { default int m() { return 99; } } 55.241 + * class B implements I {} 55.242 + * class C extends B implements I { public int m() { return 66; } } 55.243 + * 55.244 + * TEST: C c = new C(); c.m() == 66; 55.245 + * TEST: I i = new C(); i.m() == 66; 55.246 + */ 55.247 + public void testInheritedWithConcreteAndImpl() { 55.248 + Interface I = new Interface("I", DefaultMethod.std("99")); 55.249 + Class B = new Class("B", I); 55.250 + Class C = new Class("C", B, I, ConcreteMethod.std("66")); 55.251 + 55.252 + assertInvokeVirtualEquals(66, C); 55.253 + assertInvokeInterfaceEquals(66, C, I); 55.254 + } 55.255 + 55.256 + /** 55.257 + * interface I { default int m() { return 99; } } 55.258 + * interface J { default int m() { return 88; } } 55.259 + * class C implements I, J {} 55.260 + * 55.261 + * TEST: C c = new C(); c.m() throws AME 55.262 + */ 55.263 + public void testConflict() { 55.264 + // debugTest(); 55.265 + Interface I = new Interface("I", DefaultMethod.std("99")); 55.266 + Interface J = new Interface("J", DefaultMethod.std("88")); 55.267 + Class C = new Class("C", I, J); 55.268 + 55.269 + assertThrows(AbstractMethodError.class, C); 55.270 + } 55.271 + 55.272 + /** 55.273 + * interface I { int m(); } 55.274 + * interface J { default int m() { return 88; } } 55.275 + * class C implements I, J {} 55.276 + * 55.277 + * TEST: C c = new C(); c.m() throws AME 55.278 + */ 55.279 + public void testAmbiguousReabstract() { 55.280 + Interface I = new Interface("I", AbstractMethod.std()); 55.281 + Interface J = new Interface("J", DefaultMethod.std("88")); 55.282 + Class C = new Class("C", I, J); 55.283 + 55.284 + assertThrows(AbstractMethodError.class, C); 55.285 + } 55.286 + 55.287 + /** 55.288 + * interface I { default int m() { return 99; } } 55.289 + * interface J extends I { } 55.290 + * interface K extends I { } 55.291 + * class C implements J, K {} 55.292 + * 55.293 + * TEST: C c = new C(); c.m() == 99 55.294 + * TEST: J j = new C(); j.m() == 99 55.295 + * TEST: K k = new C(); k.m() == 99 55.296 + * TEST: I i = new C(); i.m() == 99 55.297 + */ 55.298 + public void testDiamond() { 55.299 + Interface I = new Interface("I", DefaultMethod.std("99")); 55.300 + Interface J = new Interface("J", I); 55.301 + Interface K = new Interface("K", I); 55.302 + Class C = new Class("C", J, K); 55.303 + 55.304 + assertInvokeVirtualEquals(99, C); 55.305 + assertInvokeInterfaceEquals(99, C, J); 55.306 + assertInvokeInterfaceEquals(99, C, K); 55.307 + assertInvokeInterfaceEquals(99, C, I); 55.308 + } 55.309 + 55.310 + /** 55.311 + * interface I { default int m() { return 99; } } 55.312 + * interface J extends I { } 55.313 + * interface K extends I { } 55.314 + * interface L extends I { } 55.315 + * interface M extends I { } 55.316 + * class C implements I, J, K, L, M {} 55.317 + * 55.318 + * TEST: C c = new C(); c.m() == 99 55.319 + * TEST: J j = new C(); j.m() == 99 55.320 + * TEST: K k = new C(); k.m() == 99 55.321 + * TEST: I i = new C(); i.m() == 99 55.322 + * TEST: L l = new C(); l.m() == 99 55.323 + * TEST: M m = new C(); m.m() == 99 55.324 + */ 55.325 + public void testExpandedDiamond() { 55.326 + Interface I = new Interface("I", DefaultMethod.std("99")); 55.327 + Interface J = new Interface("J", I); 55.328 + Interface K = new Interface("K", I); 55.329 + Interface L = new Interface("L", I); 55.330 + Interface M = new Interface("M", L); 55.331 + Class C = new Class("C", I, J, K, L, M); 55.332 + 55.333 + assertInvokeVirtualEquals(99, C); 55.334 + assertInvokeInterfaceEquals(99, C, J); 55.335 + assertInvokeInterfaceEquals(99, C, K); 55.336 + assertInvokeInterfaceEquals(99, C, I); 55.337 + assertInvokeInterfaceEquals(99, C, L); 55.338 + assertInvokeInterfaceEquals(99, C, M); 55.339 + } 55.340 + 55.341 + /** 55.342 + * interface I { int m() default { return 99; } } 55.343 + * interface J extends I { int m(); } 55.344 + * class C implements J {} 55.345 + * 55.346 + * TEST: C c = new C(); c.m() throws AME 55.347 + */ 55.348 + public void testReabstract() { 55.349 + Interface I = new Interface("I", DefaultMethod.std("99")); 55.350 + Interface J = new Interface("J", I, AbstractMethod.std()); 55.351 + Class C = new Class("C", J); 55.352 + 55.353 + assertThrows(AbstractMethodError.class, C); 55.354 + } 55.355 + 55.356 + /** 55.357 + * interface I { default int m() { return 88; } } 55.358 + * interface J extends I { default int m() { return 99; } } 55.359 + * class C implements J {} 55.360 + * 55.361 + * TEST: C c = new C(); c.m() == 99; 55.362 + * TEST: J j = new C(); j.m() == 99; 55.363 + * TEST: I i = new C(); i.m() == 99; 55.364 + */ 55.365 + public void testShadow() { 55.366 + Interface I = new Interface("I", DefaultMethod.std("88")); 55.367 + Interface J = new Interface("J", I, DefaultMethod.std("99")); 55.368 + Class C = new Class("C", J); 55.369 + 55.370 + assertInvokeVirtualEquals(99, C); 55.371 + assertInvokeInterfaceEquals(99, C, J); 55.372 + assertInvokeInterfaceEquals(99, C, I); 55.373 + } 55.374 + 55.375 + /** 55.376 + * interface I { default int m() { return 88; } } 55.377 + * interface J extends I { default int m() { return 99; } } 55.378 + * class C implements I, J {} 55.379 + * 55.380 + * TEST: C c = new C(); c.m() == 99; 55.381 + * TEST: J j = new C(); j.m() == 99; 55.382 + * TEST: I i = new C(); i.m() == 99; 55.383 + */ 55.384 + public void testDisqualified() { 55.385 + Interface I = new Interface("I", DefaultMethod.std("88")); 55.386 + Interface J = new Interface("J", I, DefaultMethod.std("99")); 55.387 + Class C = new Class("C", I, J); 55.388 + 55.389 + assertInvokeVirtualEquals(99, C); 55.390 + assertInvokeInterfaceEquals(99, C, J); 55.391 + assertInvokeInterfaceEquals(99, C, I); 55.392 + } 55.393 + 55.394 + /** 55.395 + * interface I<T> { default int m(T t) { return 99; } } 55.396 + * Class C implements I<String> { public int m() { return 88; } } 55.397 + * 55.398 + * TEST: C c = new C(); c.m() == 88; 55.399 + * TEST: I i = new C(); i.m() == 88; 55.400 + */ 55.401 + public void testSelfFill() { 55.402 + // This test ensures that a concrete method overrides a default method 55.403 + // that matches at the language-level, but has a different method 55.404 + // signature due to erasure. 55.405 + 55.406 + // debugTest(); 55.407 + 55.408 + DefaultMethod dm = new DefaultMethod( 55.409 + "int", "m", "return 99;", new MethodParameter("T", "t")); 55.410 + ConcreteMethod cm = new ConcreteMethod( 55.411 + "int", "m", "return 88;", AccessFlag.PUBLIC, 55.412 + new MethodParameter("String", "s")); 55.413 + 55.414 + Interface I = new Interface("I", new TypeParameter("T"), dm); 55.415 + Class C = new Class("C", I.with("String"), cm); 55.416 + 55.417 + AbstractMethod pm = new AbstractMethod( 55.418 + "int", "m", new MethodParameter("T", "t")); 55.419 + 55.420 + assertInvokeVirtualEquals(new Integer(88), C, cm, "-1", "\"string\""); 55.421 + assertInvokeInterfaceEquals( 55.422 + new Integer(88), C, I.with("String"), pm, "\"string\""); 55.423 + } 55.424 + 55.425 + /** 55.426 + * interface I { default int m() { return 99; } } 55.427 + * class C implements I {} 55.428 + * 55.429 + * TEST: C.class.getMethod("m").invoke(new C()) == 99 55.430 + */ 55.431 + public void testReflectCall() { 55.432 + Interface I = new Interface("I", DefaultMethod.std("99")); 55.433 + Class C = new Class("C", I); 55.434 + 55.435 + Compiler.Flags[] flags = this.verbose ? 55.436 + new Compiler.Flags[] { Compiler.Flags.VERBOSE } : 55.437 + new Compiler.Flags[] {}; 55.438 + Compiler compiler = new Compiler(flags); 55.439 + java.lang.Class<?> cls = null; 55.440 + try { 55.441 + cls = compiler.compileAndLoad(C); 55.442 + } catch (ClassNotFoundException e) { 55.443 + fail("Could not load class"); 55.444 + } 55.445 + 55.446 + java.lang.reflect.Method method = null; 55.447 + try { 55.448 + method = cls.getMethod(stdMethodName); 55.449 + } catch (NoSuchMethodException e) { 55.450 + fail("Could not find method in class"); 55.451 + } 55.452 + assertNotNull(method); 55.453 + 55.454 + Object c = null; 55.455 + try { 55.456 + c = cls.newInstance(); 55.457 + } catch (InstantiationException | IllegalAccessException e) { 55.458 + fail("Could not create instance of class"); 55.459 + } 55.460 + assertNotNull(c); 55.461 + 55.462 + Integer res = null; 55.463 + try { 55.464 + res = (Integer)method.invoke(c); 55.465 + } catch (IllegalAccessException | 55.466 + java.lang.reflect.InvocationTargetException e) { 55.467 + fail("Could not invoke default instance method"); 55.468 + } 55.469 + assertNotNull(res); 55.470 + 55.471 + assertEquals(res.intValue(), 99); 55.472 + 55.473 + compiler.cleanup(); 55.474 + } 55.475 + 55.476 + /** 55.477 + * interface I<T,V,W> { default int m(T t, V v, W w) { return 99; } } 55.478 + * interface J<T,V> extends I<String,T,V> { int m(T t, V v, String w); } } 55.479 + * interface K<T> extends J<String,T> { int m(T t, String v, String w); } } 55.480 + * class C implements K<String> { 55.481 + * public int m(String t, String v, String w) { return 88; } 55.482 + * } 55.483 + * 55.484 + * TEST: I<String,String,String> i = new C(); i.m("A","B","C") == 88; 55.485 + * TEST: J<String,String> j = new C(); j.m("A","B","C") == 88; 55.486 + * TEST: K<String> k = new C(); k.m("A","B","C") == 88; 55.487 + */ 55.488 + public void testBridges() { 55.489 + DefaultMethod dm = new DefaultMethod("int", stdMethodName, "return 99;", 55.490 + new MethodParameter("T", "t"), new MethodParameter("V", "v"), 55.491 + new MethodParameter("W", "w")); 55.492 + 55.493 + AbstractMethod pm0 = new AbstractMethod("int", stdMethodName, 55.494 + new MethodParameter("T", "t"), new MethodParameter("V", "v"), 55.495 + new MethodParameter("W", "w")); 55.496 + 55.497 + AbstractMethod pm1 = new AbstractMethod("int", stdMethodName, 55.498 + new MethodParameter("T", "t"), new MethodParameter("V", "v"), 55.499 + new MethodParameter("String", "w")); 55.500 + 55.501 + AbstractMethod pm2 = new AbstractMethod("int", stdMethodName, 55.502 + new MethodParameter("T", "t"), new MethodParameter("String", "v"), 55.503 + new MethodParameter("String", "w")); 55.504 + 55.505 + ConcreteMethod cm = new ConcreteMethod("int",stdMethodName,"return 88;", 55.506 + AccessFlag.PUBLIC, 55.507 + new MethodParameter("String", "t"), 55.508 + new MethodParameter("String", "v"), 55.509 + new MethodParameter("String", "w")); 55.510 + 55.511 + Interface I = new Interface("I", new TypeParameter("T"), 55.512 + new TypeParameter("V"), new TypeParameter("W"), dm); 55.513 + Interface J = new Interface("J", 55.514 + new TypeParameter("T"), new TypeParameter("V"), 55.515 + I.with("String", "T", "V"), pm1); 55.516 + Interface K = new Interface("K", new TypeParameter("T"), 55.517 + J.with("String", "T"), pm2); 55.518 + Class C = new Class("C", K.with("String"), cm); 55.519 + 55.520 + String[] args = new String[] { "\"A\"", "\"B\"", "\"C\"" }; 55.521 + assertInvokeInterfaceEquals(new Integer(88), C, 55.522 + I.with("String", "String", "String"), pm0, args); 55.523 + assertInvokeInterfaceEquals(new Integer(88), C, 55.524 + J.with("String", "String"), pm1, args); 55.525 + assertInvokeInterfaceEquals(new Integer(88), C, 55.526 + K.with("String"), pm2, args); 55.527 + } 55.528 + 55.529 + /** 55.530 + * interface J { default int m() { return 88; } } 55.531 + * interface I extends J { default int m() { return J.super.m(); } } 55.532 + * class C implements I {} 55.533 + * 55.534 + * TEST: C c = new C(); c.m() == 88; 55.535 + * TEST: I i = new C(); i.m() == 88; 55.536 + */ 55.537 + public void testSuperBasic() { 55.538 + // debugTest(); 55.539 + 55.540 + Interface J = new Interface("J", DefaultMethod.std("88")); 55.541 + Interface I = new Interface("I", J, new DefaultMethod( 55.542 + "int", stdMethodName, "return J.super.m();")); 55.543 + I.addCompilationDependency(J.findMethod(stdMethodName)); 55.544 + Class C = new Class("C", I); 55.545 + 55.546 + assertInvokeVirtualEquals(88, C); 55.547 + assertInvokeInterfaceEquals(88, C, I); 55.548 + } 55.549 + 55.550 + /** 55.551 + * interface K { int m() default { return 99; } } 55.552 + * interface L { int m() default { return 101; } } 55.553 + * interface J extends K, L {} 55.554 + * interface I extends J, K { int m() default { J.super.m(); } } 55.555 + * class C implements I {} 55.556 + * 55.557 + * TEST: C c = new C(); c.m() throws AME 55.558 + * TODO: add case for K k = new C(); k.m() throws AME 55.559 + */ 55.560 + public void testSuperConflict() { 55.561 + // debugTest(); 55.562 + 55.563 + Interface K = new Interface("K", DefaultMethod.std("99")); 55.564 + Interface L = new Interface("L", DefaultMethod.std("101")); 55.565 + Interface J = new Interface("J", K, L); 55.566 + Interface I = new Interface("I", J, K, new DefaultMethod( 55.567 + "int", stdMethodName, "return J.super.m();")); 55.568 + Interface Jstub = new Interface("J", DefaultMethod.std("-1")); 55.569 + I.addCompilationDependency(Jstub); 55.570 + I.addCompilationDependency(Jstub.findMethod(stdMethodName)); 55.571 + Class C = new Class("C", I); 55.572 + 55.573 + assertThrows(AbstractMethodError.class, C); 55.574 + } 55.575 + 55.576 + /** 55.577 + * interface I { default int m() { return 99; } } 55.578 + * interface J extends I { default int m() { return 55; } } 55.579 + * class C implements I, J { public int m() { return I.super.m(); } } 55.580 + * 55.581 + * TEST: C c = new C(); c.m() throws AME 55.582 + * TODO: add case for J j = new C(); j.m() throws AME 55.583 + */ 55.584 + public void testSuperDisqual() { 55.585 + Interface I = new Interface("I", DefaultMethod.std("99")); 55.586 + Interface J = new Interface("J", I, DefaultMethod.std("55")); 55.587 + Class C = new Class("C", I, J, 55.588 + new ConcreteMethod("int", stdMethodName, "return I.super.m();", 55.589 + AccessFlag.PUBLIC)); 55.590 + C.addCompilationDependency(I.findMethod(stdMethodName)); 55.591 + 55.592 + assertThrows(AbstractMethodError.class, C); 55.593 + } 55.594 + 55.595 + /** 55.596 + * interface J { int m(); } 55.597 + * interface I extends J { default int m() { return J.super.m(); } } 55.598 + * class C implements I {} 55.599 + * 55.600 + * TEST: C c = new C(); c.m() throws AME 55.601 + * TODO: add case for I i = new C(); i.m() throws AME 55.602 + */ 55.603 + public void testSuperNull() { 55.604 + Interface J = new Interface("J", AbstractMethod.std()); 55.605 + Interface I = new Interface("I", J, new DefaultMethod( 55.606 + "int", stdMethodName, "return J.super.m();")); 55.607 + Interface Jstub = new Interface("J", DefaultMethod.std("99")); 55.608 + I.addCompilationDependency(Jstub); 55.609 + I.addCompilationDependency(Jstub.findMethod(stdMethodName)); 55.610 + Class C = new Class("C", I); 55.611 + 55.612 + assertThrows(AbstractMethodError.class, C); 55.613 + } 55.614 + 55.615 + /** 55.616 + * interface J<T> { default int m(T t) { return 88; } } 55.617 + * interface I extends J<String> { 55.618 + * int m(String s) default { return J.super.m(); } 55.619 + * } 55.620 + * class C implements I {} 55.621 + * 55.622 + * TEST: I i = new C(); i.m("") == 88; 55.623 + */ 55.624 + public void testSuperGeneric() { 55.625 + Interface J = new Interface("J", new TypeParameter("T"), 55.626 + new DefaultMethod("int", stdMethodName, "return 88;", 55.627 + new MethodParameter("T", "t"))); 55.628 + Interface I = new Interface("I", J.with("String"), 55.629 + new DefaultMethod("int", stdMethodName, "return J.super.m(s);", 55.630 + new MethodParameter("String", "s"))); 55.631 + I.addCompilationDependency(J.findMethod(stdMethodName)); 55.632 + Class C = new Class("C", I); 55.633 + 55.634 + AbstractMethod pm = new AbstractMethod("int", stdMethodName, 55.635 + new MethodParameter("String", "s")); 55.636 + 55.637 + assertInvokeInterfaceEquals( 55.638 + new Integer(88), C, new Extends(I), pm, "\"\""); 55.639 + } 55.640 + 55.641 + /** 55.642 + * interface I<T> { int m(T t) default { return 44; } } 55.643 + * interface J extends I<String> { int m(String s) default { return 55; } } 55.644 + * class C implements I<String>, J { 55.645 + * public int m(String s) { return I.super.m(s); } 55.646 + * } 55.647 + * 55.648 + * TEST: C c = new C(); c.m("string") throws AME 55.649 + */ 55.650 + public void testSuperGenericDisqual() { 55.651 + MethodParameter t = new MethodParameter("T", "t"); 55.652 + MethodParameter s = new MethodParameter("String", "s"); 55.653 + 55.654 + Interface I = new Interface("I", new TypeParameter("T"), 55.655 + new DefaultMethod("int", stdMethodName, "return 44;", t)); 55.656 + Interface J = new Interface("J", I.with("String"), 55.657 + new DefaultMethod("int", stdMethodName, "return 55;", s)); 55.658 + Class C = new Class("C", I.with("String"), J, 55.659 + new ConcreteMethod("int", stdMethodName, 55.660 + "return I.super.m(s);", AccessFlag.PUBLIC, s)); 55.661 + C.addCompilationDependency(I.findMethod(stdMethodName)); 55.662 + 55.663 + assertThrows(AbstractMethodError.class, C, 55.664 + new ConcreteMethod( 55.665 + "int", stdMethodName, "return -1;", AccessFlag.PUBLIC, s), 55.666 + "-1", "\"string\""); 55.667 + } 55.668 + 55.669 + /** 55.670 + * interface I { default Integer m() { return new Integer(88); } } 55.671 + * class C { Number m() { return new Integer(99); } } 55.672 + * class D extends C implements I {} 55.673 + * class S { Object foo() { return (new D()).m(); } // link sig: ()LInteger; 55.674 + * TEST: S s = new S(); s.foo() == new Integer(99) 55.675 + */ 55.676 + public void testCovarBridge() { 55.677 + Interface I = new Interface("I", new DefaultMethod( 55.678 + "Integer", "m", "return new Integer(88);")); 55.679 + Class C = new Class("C", new ConcreteMethod( 55.680 + "Number", "m", "return new Integer(99);", AccessFlag.PUBLIC)); 55.681 + Class D = new Class("D", I, C); 55.682 + 55.683 + ConcreteMethod DstubMethod = new ConcreteMethod( 55.684 + "Integer", "m", "return null;", AccessFlag.PUBLIC); 55.685 + Class Dstub = new Class("D", DstubMethod); 55.686 + 55.687 + ConcreteMethod toCall = new ConcreteMethod( 55.688 + "Object", "foo", "return (new D()).m();", AccessFlag.PUBLIC); 55.689 + Class S = new Class("S", D, toCall); 55.690 + S.addCompilationDependency(Dstub); 55.691 + S.addCompilationDependency(DstubMethod); 55.692 + 55.693 + assertInvokeVirtualEquals(new Integer(99), S, toCall, "null"); 55.694 + } 55.695 + 55.696 + /** 55.697 + * interface I { default Integer m() { return new Integer(88); } } 55.698 + * class C { int m() { return 99; } } 55.699 + * class D extends C implements I {} 55.700 + * class S { Object foo() { return (new D()).m(); } // link sig: ()LInteger; 55.701 + * TEST: S s = new S(); s.foo() == new Integer(88) 55.702 + */ 55.703 + public void testNoCovarNoBridge() { 55.704 + Interface I = new Interface("I", new DefaultMethod( 55.705 + "Integer", "m", "return new Integer(88);")); 55.706 + Class C = new Class("C", new ConcreteMethod( 55.707 + "int", "m", "return 99;", AccessFlag.PUBLIC)); 55.708 + Class D = new Class("D", I, C); 55.709 + 55.710 + ConcreteMethod DstubMethod = new ConcreteMethod( 55.711 + "Integer", "m", "return null;", AccessFlag.PUBLIC); 55.712 + Class Dstub = new Class("D", DstubMethod); 55.713 + 55.714 + ConcreteMethod toCall = new ConcreteMethod( 55.715 + "Object", "foo", "return (new D()).m();", AccessFlag.PUBLIC); 55.716 + Class S = new Class("S", D, toCall); 55.717 + S.addCompilationDependency(Dstub); 55.718 + S.addCompilationDependency(DstubMethod); 55.719 + 55.720 + assertInvokeVirtualEquals(new Integer(88), S, toCall, "null"); 55.721 + } 55.722 + 55.723 + /** 55.724 + * interface J { int m(); } 55.725 + * interface I extends J { default int m() { return 99; } } 55.726 + * class B implements J {} 55.727 + * class C extends B implements I {} 55.728 + * TEST: C c = new C(); c.m() == 99 55.729 + * 55.730 + * The point of this test is that B does not get default method analysis, 55.731 + * and C does not generate any new miranda methods in the vtable. 55.732 + * It verifies that default method analysis occurs when mirandas have been 55.733 + * inherited and the supertypes don't have any overpass methods. 55.734 + */ 55.735 + public void testNoNewMiranda() { 55.736 + Interface J = new Interface("J", AbstractMethod.std()); 55.737 + Interface I = new Interface("I", J, DefaultMethod.std("99")); 55.738 + Class B = new Class("B", J); 55.739 + Class C = new Class("C", B, I); 55.740 + assertInvokeVirtualEquals(99, C); 55.741 + } 55.742 + 55.743 + /** 55.744 + * interface I<T,V,W> { int m(T t, V v, W w); } 55.745 + * interface J<T,V> implements I<T,V,String> { int m(T t, V v, String w); } 55.746 + * interface K<T> implements J<T,String> { 55.747 + * int m(T t, String v, String w); { return 99; } } 55.748 + * class C implements K<String> { 55.749 + * public int m(Object t, Object v, String w) { return 77; } 55.750 + * } 55.751 + * TEST C = new C(); ((I)c).m(Object,Object,Object) == 99 55.752 + * TEST C = new C(); ((J)c).m(Object,Object,String) == 77 55.753 + * TEST C = new C(); ((K)c).m(Object,String,String) == 99 55.754 + * 55.755 + * Test that a erased-signature-matching method does not implement 55.756 + * non-language-level matching methods 55.757 + */ 55.758 + public void testNonConcreteFill() { 55.759 + AbstractMethod ipm = new AbstractMethod("int", "m", 55.760 + new MethodParameter("T", "t"), 55.761 + new MethodParameter("V", "s"), 55.762 + new MethodParameter("W", "w")); 55.763 + Interface I = new Interface("I", 55.764 + new TypeParameter("T"), 55.765 + new TypeParameter("V"), 55.766 + new TypeParameter("W"), ipm); 55.767 + 55.768 + AbstractMethod jpm = new AbstractMethod("int", "m", 55.769 + new MethodParameter("T", "t"), 55.770 + new MethodParameter("V", "s"), 55.771 + new MethodParameter("String", "w")); 55.772 + Interface J = new Interface("J", 55.773 + new TypeParameter("T"), 55.774 + new TypeParameter("V"), 55.775 + I.with("T", "V", "String"), jpm); 55.776 + 55.777 + AbstractMethod kpm = new AbstractMethod("int", "m", 55.778 + new MethodParameter("T", "t"), 55.779 + new MethodParameter("String", "s"), 55.780 + new MethodParameter("String", "w")); 55.781 + Interface K = new Interface("K", 55.782 + new TypeParameter("T"), 55.783 + J.with("T", "String"), 55.784 + new DefaultMethod("int", "m", "return 99;", 55.785 + new MethodParameter("T", "t"), 55.786 + new MethodParameter("String", "v"), 55.787 + new MethodParameter("String", "w"))); 55.788 + 55.789 + Class C = new Class("C", 55.790 + K.with("String"), 55.791 + new ConcreteMethod("int", "m", "return 77;", 55.792 + AccessFlag.PUBLIC, 55.793 + new MethodParameter("Object", "t"), 55.794 + new MethodParameter("Object", "v"), 55.795 + new MethodParameter("String", "w"))); 55.796 + 55.797 + String a = "\"\""; 55.798 + assertInvokeInterfaceEquals(99, C, 55.799 + K.with("String"), kpm, a, a, a); 55.800 + assertInvokeInterfaceEquals(77, C, 55.801 + J.with("String", "String"), jpm, a, a, a); 55.802 + assertInvokeInterfaceEquals(99, C, 55.803 + I.with("String", "String", "String"), ipm, a, a, a); 55.804 + } 55.805 + 55.806 + public void testStrictfpDefault() { 55.807 + try { 55.808 + java.lang.Class.forName("org.openjdk.tests.vm.StrictfpDefault"); 55.809 + } catch (Exception e) { 55.810 + fail("Could not load class", e); 55.811 + } 55.812 + } 55.813 + 55.814 + public void testSynchronizedDefault() { 55.815 + try { 55.816 + java.lang.Class.forName("org.openjdk.tests.vm.SynchronizedDefault"); 55.817 + } catch (Exception e) { 55.818 + fail("Could not load class", e); 55.819 + } 55.820 + } 55.821 +} 55.822 + 55.823 +interface StrictfpDefault { 55.824 + default strictfp void m() {} 55.825 +} 55.826 + 55.827 +interface SynchronizedDefault { 55.828 + default synchronized void m() {} 55.829 +}
56.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 56.2 +++ b/test/tools/javac/lambdaShapes/org/openjdk/tests/vm/FDSeparateCompilationTest.java Tue Nov 20 09:58:55 2012 -0800 56.3 @@ -0,0 +1,197 @@ 56.4 +/* 56.5 + * Copyright (c) 2012 Oracle and/or its affiliates. All rights reserved. 56.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 56.7 + * 56.8 + * This code is free software; you can redistribute it and/or modify it 56.9 + * under the terms of the GNU General Public License version 2 only, as 56.10 + * published by the Free Software Foundation. Oracle designates this 56.11 + * particular file as subject to the "Classpath" exception as provided 56.12 + * by Oracle in the LICENSE file that accompanied this code. 56.13 + * 56.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 56.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 56.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 56.17 + * version 2 for more details (a copy is included in the LICENSE file that 56.18 + * accompanied this code). 56.19 + * 56.20 + * You should have received a copy of the GNU General Public License version 56.21 + * 2 along with this work; if not, write to the Free Software Foundation, 56.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 56.23 + * 56.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 56.25 + * or visit www.oracle.com if you need additional information or have any 56.26 + * questions. 56.27 + */ 56.28 + 56.29 +package org.openjdk.tests.vm; 56.30 + 56.31 +import java.util.*; 56.32 + 56.33 +import org.testng.ITestResult; 56.34 +import org.testng.annotations.Test; 56.35 +import org.testng.annotations.DataProvider; 56.36 +import org.testng.annotations.AfterMethod; 56.37 +import org.testng.annotations.AfterSuite; 56.38 + 56.39 +import org.openjdk.tests.separate.*; 56.40 +import org.openjdk.tests.separate.Compiler; 56.41 + 56.42 +import org.openjdk.tests.shapegen.Hierarchy; 56.43 +import org.openjdk.tests.shapegen.HierarchyGenerator; 56.44 +import org.openjdk.tests.shapegen.ClassCase; 56.45 + 56.46 +import static org.testng.Assert.*; 56.47 +import static org.openjdk.tests.separate.SourceModel.*; 56.48 +import static org.openjdk.tests.separate.SourceModel.Class; 56.49 +import static org.openjdk.tests.separate.SourceModel.Method; 56.50 +import static org.openjdk.tests.separate.SourceModel.Type; 56.51 + 56.52 +public class FDSeparateCompilationTest extends TestHarness { 56.53 + 56.54 + private static String EMPTY = "\"\""; 56.55 + 56.56 + public FDSeparateCompilationTest() { 56.57 + super(false, true); 56.58 + } 56.59 + 56.60 + @DataProvider(name = "allShapes", parallel = true) 56.61 + public Object[][] hierarchyGenerator() { 56.62 + ArrayList<Object[]> allCases = new ArrayList<>(); 56.63 + 56.64 + HierarchyGenerator hg = new HierarchyGenerator(); 56.65 + for (Object x : hg.getOK()) { 56.66 + allCases.add(new Object[]{x}); 56.67 + } 56.68 + for (Object x : hg.getErr()) { 56.69 + allCases.add(new Object[]{x}); 56.70 + } 56.71 + return allCases.toArray(new Object[0][]); 56.72 + } 56.73 + 56.74 + // The expected value obtained when invoking the method from the specified 56.75 + // class. If returns null, then an AbstractMethodError is expected. 56.76 + private static String getExpectedResult(ClassCase cc) { 56.77 + Set<ClassCase> provs = cc.get_mprov(); 56.78 + if (cc.get_mres() != null) { 56.79 + return cc.get_mres().getName(); 56.80 + } else if (provs != null && provs.size() == 1) { 56.81 + ClassCase cand = provs.iterator().next(); 56.82 + switch (cand.kind) { 56.83 + case CCONCRETE: 56.84 + case IDEFAULT: 56.85 + return cand.getName(); 56.86 + case CNONE: 56.87 + case IVAC: 56.88 + return getExpectedResult(cand); 56.89 + } 56.90 + } 56.91 + return null; 56.92 + } 56.93 + 56.94 + private static final ConcreteMethod canonicalMethod = new ConcreteMethod( 56.95 + "String", "m", "returns " + EMPTY + ";", AccessFlag.PUBLIC); 56.96 + 56.97 + @Test(groups = "vm", dataProvider = "allShapes") 56.98 + public void separateCompilationTest(Hierarchy hs) { 56.99 + ClassCase cc = hs.root; 56.100 + Type type = sourceTypeFrom(hs.root); 56.101 + 56.102 + Class specimen = null; 56.103 + if (type instanceof Class) { 56.104 + Class ctype = (Class)type; 56.105 + if (ctype.isAbstract()) { 56.106 + specimen = new Class("Test" + ctype.getName(), ctype); 56.107 + } else { 56.108 + specimen = ctype; 56.109 + } 56.110 + } else { 56.111 + specimen = new Class("Test" + type.getName(), (Interface)type); 56.112 + } 56.113 + 56.114 + String value = getExpectedResult(cc); 56.115 + if (value != null) { 56.116 + assertInvokeVirtualEquals(value, specimen, canonicalMethod, EMPTY); 56.117 + } else { 56.118 + assertThrows(AbstractMethodError.class, specimen, 56.119 + canonicalMethod, EMPTY); 56.120 + } 56.121 + } 56.122 + 56.123 + @AfterMethod 56.124 + public void printCaseError(ITestResult result) { 56.125 + if (result.getStatus() == ITestResult.FAILURE) { 56.126 + Hierarchy hs = (Hierarchy)result.getParameters()[0]; 56.127 + System.out.println("Separate compilation case " + hs); 56.128 + printCaseDetails(hs); 56.129 + } 56.130 + } 56.131 + 56.132 + @AfterSuite 56.133 + public void cleanupCompilerCache() { 56.134 + Compiler.purgeCache(); 56.135 + } 56.136 + 56.137 + private void printCaseDetails(Hierarchy hs) { 56.138 + String exp = getExpectedResult(hs.root); 56.139 + for (String s : hs.getDescription()) { 56.140 + System.out.println(" " + s); 56.141 + } 56.142 + if (exp != null) { 56.143 + System.out.println(" Expected \"" + exp + "\""); 56.144 + } else { 56.145 + System.out.println(" Expected AbstractMethodError"); 56.146 + } 56.147 + } 56.148 + 56.149 + private Type sourceTypeFrom(ClassCase cc) { 56.150 + Type type = null; 56.151 + 56.152 + if (cc.isInterface()) { 56.153 + Interface iface = new Interface(cc.getName()); 56.154 + for (ClassCase scc : cc.getInterfaces()) { 56.155 + Interface supertype = (Interface)sourceTypeFrom(scc); 56.156 + iface.addSuperType(supertype); 56.157 + } 56.158 + type = iface; 56.159 + } else { 56.160 + Class cls = new Class(cc.getName()); 56.161 + if (cc.hasSuperclass()) { 56.162 + Class superc = (Class)sourceTypeFrom(cc.getSuperclass()); 56.163 + cls.setSuperClass(superc); 56.164 + } 56.165 + for (ClassCase scc : cc.getInterfaces()) { 56.166 + Interface supertype = (Interface)sourceTypeFrom(scc); 56.167 + cls.addSuperType(supertype); 56.168 + } 56.169 + if (cc.isAbstract()) { 56.170 + cls.getAccessFlags().add(AccessFlag.ABSTRACT); 56.171 + } 56.172 + type = cls; 56.173 + } 56.174 + Method method = methodFrom(cc); 56.175 + if (method != null) { 56.176 + type.addMethod(method); 56.177 + } 56.178 + return type; 56.179 + } 56.180 + 56.181 + private Method methodFrom(ClassCase cc) { 56.182 + switch (cc.kind) { 56.183 + case IVAC: 56.184 + case CNONE: return null; 56.185 + case IPRESENT: 56.186 + case CABSTRACT: 56.187 + return new AbstractMethod("String", "m", AccessFlag.PUBLIC); 56.188 + case IDEFAULT: 56.189 + return new DefaultMethod( 56.190 + "String", "m", "return \"" + cc.getName() + "\";"); 56.191 + case CCONCRETE: 56.192 + return new ConcreteMethod( 56.193 + "String", "m", "return \"" + cc.getName() + "\";", 56.194 + AccessFlag.PUBLIC); 56.195 + default: 56.196 + fail("Unknown method type in class"); 56.197 + return null; 56.198 + } 56.199 + } 56.200 +}