OpenJDK / jdk / hs
changeset 29745:119626a43008
8076632: Remove duplicate tests: FDTest, MethodReferenceTest and more -- follow-on (completion)
Summary: Remove certain lambda tests from the JDK repo which also exist in the langtools repo
Reviewed-by: rfield
Contributed-by: amy.lu@oracle.com
author | rfield |
---|---|
date | Fri, 03 Apr 2015 00:00:16 -0700 |
parents | 03803e001170 |
children | f0730dd3de62 |
files | jdk/test/jdk/lambda/FDTest.java jdk/test/jdk/lambda/LambdaTranslationInInterface.java jdk/test/jdk/lambda/LambdaTranslationInnerConstructor.java jdk/test/jdk/lambda/MethodReferenceTestFDCCE.java jdk/test/jdk/lambda/MethodReferenceTestInnerDefault.java jdk/test/jdk/lambda/MethodReferenceTestInnerInstance.java jdk/test/jdk/lambda/MethodReferenceTestInnerVarArgsThis.java jdk/test/jdk/lambda/MethodReferenceTestInstance.java jdk/test/jdk/lambda/MethodReferenceTestKinds.java jdk/test/jdk/lambda/MethodReferenceTestNew.java jdk/test/jdk/lambda/MethodReferenceTestNewInner.java jdk/test/jdk/lambda/MethodReferenceTestSueCase1.java jdk/test/jdk/lambda/MethodReferenceTestSueCase2.java jdk/test/jdk/lambda/MethodReferenceTestSueCase4.java jdk/test/jdk/lambda/MethodReferenceTestSuper.java jdk/test/jdk/lambda/MethodReferenceTestSuperDefault.java jdk/test/jdk/lambda/MethodReferenceTestTypeConversion.java jdk/test/jdk/lambda/MethodReferenceTestVarArgs.java jdk/test/jdk/lambda/MethodReferenceTestVarArgsExt.java jdk/test/jdk/lambda/MethodReferenceTestVarArgsSuper.java jdk/test/jdk/lambda/MethodReferenceTestVarArgsSuperDefault.java jdk/test/jdk/lambda/MethodReferenceTestVarArgsThis.java jdk/test/jdk/lambda/shapegen/ClassCase.java jdk/test/jdk/lambda/shapegen/Hierarchy.java jdk/test/jdk/lambda/shapegen/HierarchyGenerator.java jdk/test/jdk/lambda/shapegen/Rule.java jdk/test/jdk/lambda/shapegen/RuleGroup.java jdk/test/jdk/lambda/shapegen/TTNode.java jdk/test/jdk/lambda/shapegen/TTParser.java jdk/test/jdk/lambda/shapegen/TTShape.java |
diffstat | 30 files changed, 0 insertions(+), 3988 deletions(-) [+] |
line wrap: on
line diff
--- a/jdk/test/jdk/lambda/FDTest.java Thu Apr 02 17:32:05 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,192 +0,0 @@ -/* - * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - - -import shapegen.*; - -import com.sun.source.util.JavacTask; -import com.sun.tools.javac.util.Pair; - -import java.net.URI; -import java.util.Arrays; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -import javax.tools.Diagnostic; -import javax.tools.JavaCompiler; -import javax.tools.JavaFileObject; -import javax.tools.SimpleJavaFileObject; -import javax.tools.StandardJavaFileManager; -import javax.tools.ToolProvider; - -import org.testng.annotations.Test; -import org.testng.annotations.BeforeSuite; -import org.testng.annotations.DataProvider; -import static org.testng.Assert.*; - -public class FDTest { - - public enum TestKind { - POSITIVE, - NEGATIVE; - - Collection<Hierarchy> getHierarchy(HierarchyGenerator hg) { - return this == POSITIVE ? - hg.getOK() : hg.getErr(); - } - } - - public static JavaCompiler comp; - public static StandardJavaFileManager fm; - - @BeforeSuite - static void init() { - // create default shared JavaCompiler - reused across multiple - // compilations - - comp = ToolProvider.getSystemJavaCompiler(); - fm = comp.getStandardFileManager(null, null, null); - } - - public static void main(String[] args) throws Exception { - init(); - - for (Pair<TestKind,Hierarchy> fdtest : generateCases()) { - runTest(fdtest.fst, fdtest.snd, comp, fm); - } - } - - @Test(dataProvider = "fdCases") - public void testOneCase(TestKind tk, Hierarchy hs) - throws Exception { - FDTest.runTest(tk, hs, comp, fm); - } - - @DataProvider(name = "fdCases") - public Object[][] caseGenerator() { - List<Pair<TestKind, Hierarchy>> cases = generateCases(); - Object[][] fdCases = new Object[cases.size()][]; - for (int i = 0; i < cases.size(); ++i) { - fdCases[i] = new Object[2]; - fdCases[i][0] = cases.get(i).fst; - fdCases[i][1] = cases.get(i).snd; - } - return fdCases; - } - - public static List<Pair<TestKind, Hierarchy>> generateCases() { - ArrayList<Pair<TestKind,Hierarchy>> list = new ArrayList<>(); - HierarchyGenerator hg = new HierarchyGenerator(); - for (TestKind tk : TestKind.values()) { - for (Hierarchy hs : tk.getHierarchy(hg)) { - list.add(new Pair<>(tk, hs)); - } - } - return list; - } - - public static void runTest(TestKind tk, Hierarchy hs, - JavaCompiler comp, StandardJavaFileManager fm) throws Exception { - new FDTest(tk, hs).run(comp, fm); - } - - TestKind tk; - Hierarchy hs; - DefenderTestSource source; - DiagnosticChecker diagChecker; - - public FDTest() {} - - FDTest(TestKind tk, Hierarchy hs) { - this.tk = tk; - this.hs = hs; - this.source = new DefenderTestSource(); - this.diagChecker = new DiagnosticChecker(); - } - - void run(JavaCompiler tool, StandardJavaFileManager fm) throws Exception { - JavacTask ct = (JavacTask)tool.getTask(null, fm, diagChecker, - null, null, Arrays.asList(source)); - try { - ct.analyze(); - } catch (Throwable ex) { - fail("Error thrown when analyzing the following source:\n" + source.getCharContent(true)); - } - check(); - } - - void check() { - boolean errorExpected = tk == TestKind.NEGATIVE; - if (errorExpected != diagChecker.errorFound) { - fail("problem in source: \n" + - "\nerror found = " + diagChecker.errorFound + - "\nerror expected = " + errorExpected + - "\n" + dumpHierarchy() + - "\n" + source.getCharContent(true)); - } - } - - String dumpHierarchy() { - StringBuilder buf = new StringBuilder(); - buf.append("root = " + hs.root + "\n"); - for (ClassCase cc : hs.all) { - buf.append(" class name = " + cc.getName() + "\n"); - buf.append(" class OK = " + cc.get_OK() + "\n"); - buf.append(" prov = " + cc.get_mprov() + "\n"); - - } - return buf.toString(); - } - - class DefenderTestSource extends SimpleJavaFileObject { - - String source; - - public DefenderTestSource() { - super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE); - StringBuilder buf = new StringBuilder(); - List<ClassCase> defaultRef = new ArrayList<>(); - for (ClassCase cc : hs.all) { - Hierarchy.genClassDef(buf, cc, null, defaultRef); - } - source = buf.toString(); - } - - @Override - public CharSequence getCharContent(boolean ignoreEncodingErrors) { - return source; - } - } - - static class DiagnosticChecker implements javax.tools.DiagnosticListener<JavaFileObject> { - - boolean errorFound; - - public void report(Diagnostic<? extends JavaFileObject> diagnostic) { - if (diagnostic.getKind() == Diagnostic.Kind.ERROR) { - errorFound = true; - } - } - } -}
--- a/jdk/test/jdk/lambda/LambdaTranslationInInterface.java Thu Apr 02 17:32:05 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,59 +0,0 @@ -/* - * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -import static org.testng.Assert.assertEquals; -import org.testng.annotations.Test; - -/** - * @author Robert Field - */ - -interface LTII { - - interface ILsp1 { - String m(); - } - - interface ILsp2 { - String m(String x); - } - - default ILsp1 t1() { - return () -> { return "yo"; }; - } - - default ILsp2 t2() { - return (x) -> { return "snur" + x; }; - } - -} - -@Test -public class LambdaTranslationInInterface implements LTII { - - public void testLambdaInDefaultMethod() { - assertEquals(t1().m(), "yo"); - assertEquals(t2().m("p"), "snurp"); - } - -}
--- a/jdk/test/jdk/lambda/LambdaTranslationInnerConstructor.java Thu Apr 02 17:32:05 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,70 +0,0 @@ -/* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -import static org.testng.Assert.assertEquals; -import org.testng.annotations.Test; - -/** - * @author Robert Field - */ - -@Test -public class LambdaTranslationInnerConstructor { - - public void testLambdaWithInnerConstructor() { - assertEquals(seq1().m().toString(), "Cbl:nada"); - assertEquals(seq2().m("rats").toString(), "Cbl:rats"); - } - - Ib1 seq1() { - return () -> { return new Cbl(); }; - } - - Ib2 seq2() { - return (x) -> { return new Cbl(x); }; - } - - class Cbl { - String val; - - Cbl() { - this.val = "nada"; - } - - Cbl(String z) { - this.val = z; - } - - public String toString() { - return "Cbl:" + val; - } - } - - interface Ib1 { - Object m(); - } - - interface Ib2 { - Object m(String x); - } -} \ No newline at end of file
--- a/jdk/test/jdk/lambda/MethodReferenceTestFDCCE.java Thu Apr 02 17:32:05 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,146 +0,0 @@ -/* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -import org.testng.annotations.Test; -import java.lang.reflect.Array; - -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertTrue; -import static org.testng.Assert.fail; - -/** - * Method references and raw types. - * @author Robert Field - */ - -@Test -@SuppressWarnings({"rawtypes", "unchecked"}) -public class MethodReferenceTestFDCCE { - - static void assertCCE(Throwable t) { - assertEquals(t.getClass().getName(), "java.lang.ClassCastException"); - } - - interface Pred<T> { boolean accept(T x); } - - interface Ps { boolean accept(short x); } - - interface Oo { Object too(int x); } - - interface Reto<T> { T m(); } - - class A {} - class B extends A {} - - static boolean isMinor(int x) { - return x < 18; - } - - static boolean tst(A x) { - return true; - } - - static Object otst(Object x) { - return x; - } - - static boolean stst(Short x) { - return x < 18; - } - - static short ritst() { - return 123; - } - - public void testMethodReferenceFDPrim1() { - Pred<Byte> p = MethodReferenceTestFDCCE::isMinor; - Pred p2 = p; - assertTrue(p2.accept((Byte)(byte)15)); - } - - public void testMethodReferenceFDPrim2() { - Pred<Byte> p = MethodReferenceTestFDCCE::isMinor; - Pred p2 = p; - assertTrue(p2.accept((byte)15)); - } - - public void testMethodReferenceFDPrimICCE() { - Pred<Byte> p = MethodReferenceTestFDCCE::isMinor; - Pred p2 = p; - try { - p2.accept(15); // should throw CCE - fail("Exception should have been thrown"); - } catch (Throwable t) { - assertCCE(t); - } - } - - public void testMethodReferenceFDPrimOCCE() { - Pred<Byte> p = MethodReferenceTestFDCCE::isMinor; - Pred p2 = p; - try { - p2.accept(new Object()); // should throw CCE - fail("Exception should have been thrown"); - } catch (Throwable t) { - assertCCE(t); - } - } - - public void testMethodReferenceFDRef() { - Pred<B> p = MethodReferenceTestFDCCE::tst; - Pred p2 = p; - assertTrue(p2.accept(new B())); - } - - public void testMethodReferenceFDRefCCE() { - Pred<B> p = MethodReferenceTestFDCCE::tst; - Pred p2 = p; - try { - p2.accept(new A()); // should throw CCE - fail("Exception should have been thrown"); - } catch (Throwable t) { - assertCCE(t); - } - } - - public void testMethodReferenceFDPrimPrim() { - Ps p = MethodReferenceTestFDCCE::isMinor; - assertTrue(p.accept((byte)15)); - } - - public void testMethodReferenceFDPrimBoxed() { - Ps p = MethodReferenceTestFDCCE::stst; - assertTrue(p.accept((byte)15)); - } - - public void testMethodReferenceFDPrimRef() { - Oo p = MethodReferenceTestFDCCE::otst; - assertEquals(p.too(15).getClass().getName(), "java.lang.Integer"); - } - - public void testMethodReferenceFDRet1() { - Reto<Short> p = MethodReferenceTestFDCCE::ritst; - assertEquals(p.m(), (Short)(short)123); - } - -} \ No newline at end of file
--- a/jdk/test/jdk/lambda/MethodReferenceTestInnerDefault.java Thu Apr 02 17:32:05 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,79 +0,0 @@ -/* - * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -import org.testng.annotations.Test; - -import static org.testng.Assert.assertEquals; - -/** - * @author Robert Field - */ - -interface IDSs { String m(String a); } - -interface InDefA { - default String xsA__(String s) { - return "A__xsA:" + s; - } - - default String xsAB_(String s) { - return "AB_xsA:" + s; - } - -} - -interface InDefB extends InDefA { - - default String xsAB_(String s) { - return "AB_xsB:" + s; - } - - default String xs_B_(String s) { - return "_B_xsB:" + s; - } -} - -@Test -public class MethodReferenceTestInnerDefault implements InDefB { - - public void testMethodReferenceInnerDefault() { - (new In()).testMethodReferenceInnerDefault(); - } - - class In { - - public void testMethodReferenceInnerDefault() { - IDSs q; - - q = MethodReferenceTestInnerDefault.this::xsA__; - assertEquals(q.m("*"), "A__xsA:*"); - - q = MethodReferenceTestInnerDefault.this::xsAB_; - assertEquals(q.m("*"), "AB_xsB:*"); - - q = MethodReferenceTestInnerDefault.this::xs_B_; - assertEquals(q.m("*"), "_B_xsB:*"); - } - } - -}
--- a/jdk/test/jdk/lambda/MethodReferenceTestInnerInstance.java Thu Apr 02 17:32:05 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,86 +0,0 @@ -/* - * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -import org.testng.annotations.Test; - -import static org.testng.Assert.assertEquals; - -/** - * @author Robert Field - */ - -@Test -public class MethodReferenceTestInnerInstance { - - public void testMethodReferenceInnerInstance() { - cia().cib().testMethodReferenceInstance(); - } - - public void testMethodReferenceInnerExternal() { - cia().cib().testMethodReferenceExternal(); - } - - interface SI { - String m(Integer a); - } - - class CIA { - - String xI(Integer i) { - return "xI:" + i; - } - - public class CIB { - - public void testMethodReferenceInstance() { - SI q; - - q = CIA.this::xI; - assertEquals(q.m(55), "xI:55"); - } - - public void testMethodReferenceExternal() { - SI q; - - q = (new E())::xI; - assertEquals(q.m(77), "ExI:77"); - } - } - - CIB cib() { - return new CIB(); - } - - class E { - - String xI(Integer i) { - return "ExI:" + i; - } - } - - } - - CIA cia() { - return new CIA(); - } -}
--- a/jdk/test/jdk/lambda/MethodReferenceTestInnerVarArgsThis.java Thu Apr 02 17:32:05 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,241 +0,0 @@ -/* - * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -import org.testng.annotations.Test; -import java.lang.reflect.Array; - -import static org.testng.Assert.assertEquals; - -/** - * @author Robert Field - */ - -@Test -public class MethodReferenceTestInnerVarArgsThis { - - interface NsII { - - String m(Integer a, Integer b); - } - - interface Nsiii { - - String m(int a, int b, int c); - } - - interface Nsi { - - String m(int a); - } - - interface NsaO { - - String m(Object[] a); - } - - interface Nsai { - - String m(int[] a); - } - - interface Nsvi { - - String m(int... va); - } - - class CIA { - - String xvI(Integer... vi) { - StringBuilder sb = new StringBuilder("xvI:"); - for (Integer i : vi) { - sb.append(i); - sb.append("-"); - } - return sb.toString(); - } - - String xIvI(Integer f, Integer... vi) { - StringBuilder sb = new StringBuilder("xIvI:"); - sb.append(f); - for (Integer i : vi) { - sb.append(i); - sb.append("-"); - } - return sb.toString(); - } - - String xvi(int... vi) { - int sum = 0; - for (int i : vi) { - sum += i; - } - return "xvi:" + sum; - } - - String xIvi(Integer f, int... vi) { - int sum = 0; - for (int i : vi) { - sum += i; - } - return "xIvi:(" + f + ")" + sum; - } - - String xvO(Object... vi) { - StringBuilder sb = new StringBuilder("xvO:"); - for (Object i : vi) { - if (i.getClass().isArray()) { - sb.append("["); - int len = Array.getLength(i); - for (int x = 0; x < len; ++x) { - sb.append(Array.get(i, x)); - sb.append(","); - } - sb.append("]"); - - } else { - sb.append(i); - } - sb.append("*"); - } - return sb.toString(); - } - - public class CIB { - - // These should be processed as var args - public void testVarArgsNsSuperclass() { - NsII q; - - q = CIA.this::xvO; - assertEquals(q.m(55, 66), "xvO:55*66*"); - } - - public void testVarArgsNsArray() { - Nsai q; - - q = CIA.this::xvO; - assertEquals(q.m(new int[]{55, 66}), "xvO:[55,66,]*"); - } - - public void testVarArgsNsII() { - NsII q; - - q = CIA.this::xvI; - assertEquals(q.m(33, 7), "xvI:33-7-"); - - q = CIA.this::xIvI; - assertEquals(q.m(50, 40), "xIvI:5040-"); - - q = CIA.this::xvi; - assertEquals(q.m(100, 23), "xvi:123"); - - q = CIA.this::xIvi; - assertEquals(q.m(9, 21), "xIvi:(9)21"); - } - - public void testVarArgsNsiii() { - Nsiii q; - - q = CIA.this::xvI; - assertEquals(q.m(3, 2, 1), "xvI:3-2-1-"); - - q = CIA.this::xIvI; - assertEquals(q.m(888, 99, 2), "xIvI:88899-2-"); - - q = CIA.this::xvi; - assertEquals(q.m(900, 80, 7), "xvi:987"); - - q = CIA.this::xIvi; - assertEquals(q.m(333, 27, 72), "xIvi:(333)99"); - } - - public void testVarArgsNsi() { - Nsi q; - - q = CIA.this::xvI; - assertEquals(q.m(3), "xvI:3-"); - - q = CIA.this::xIvI; - assertEquals(q.m(888), "xIvI:888"); - - q = CIA.this::xvi; - assertEquals(q.m(900), "xvi:900"); - - q = CIA.this::xIvi; - assertEquals(q.m(333), "xIvi:(333)0"); - } - - // These should NOT be processed as var args - public void testVarArgsNsaO() { - NsaO q; - - q = CIA.this::xvO; - assertEquals(q.m(new String[]{"yo", "there", "dude"}), "xvO:yo*there*dude*"); - } - } - - CIB cib() { - return new CIB(); - } - - class E { - - String xI(Integer i) { - return "ExI:" + i; - } - } - } - - CIA cia() { - return new CIA(); - } - - // These should be processed as var args - public void testVarArgsNsSuperclass() { - cia().cib().testVarArgsNsSuperclass(); - } - - public void testVarArgsNsArray() { - cia().cib().testVarArgsNsArray(); - } - - public void testVarArgsNsII() { - cia().cib().testVarArgsNsII(); - } - - public void testVarArgsNsiii() { - cia().cib().testVarArgsNsiii(); - } - - public void testVarArgsNsi() { - cia().cib().testVarArgsNsi(); - } - - // These should NOT be processed as var args - - public void testVarArgsNsaO() { - cia().cib().testVarArgsNsaO(); - } - - -}
--- a/jdk/test/jdk/lambda/MethodReferenceTestInstance.java Thu Apr 02 17:32:05 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,61 +0,0 @@ -/* - * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -import org.testng.annotations.Test; - -import static org.testng.Assert.assertEquals; - -/** - * @author Robert Field - */ - -class MethodReferenceTestInstance_E { - String xI(Integer i) { - return "ExI:" + i; - } -} - -@Test -public class MethodReferenceTestInstance { - - interface SI { String m(Integer a); } - - String xI(Integer i) { - return "xI:" + i; - } - - public void testMethodReferenceInstance() { - SI q; - - q = this::xI; - assertEquals(q.m(55), "xI:55"); - } - - public void testMethodReferenceExternal() { - SI q; - - q = (new MethodReferenceTestInstance_E())::xI; - assertEquals(q.m(77), "ExI:77"); - } - -}
--- a/jdk/test/jdk/lambda/MethodReferenceTestKinds.java Thu Apr 02 17:32:05 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,173 +0,0 @@ -/* - * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - - -import org.testng.annotations.Test; - -import static org.testng.Assert.assertEquals; - -/** - * @author Robert Field - */ - -@Test -public class MethodReferenceTestKinds extends MethodReferenceTestKindsSup { - - interface S0 { String get(); } - interface S1 { String get(MethodReferenceTestKinds x); } - interface S2 { String get(MethodReferenceTestKinds x, MethodReferenceTestKinds y); } - - interface SXN0 { MethodReferenceTestKindsBase make(MethodReferenceTestKinds x); } - interface SXN1 { MethodReferenceTestKindsBase make(MethodReferenceTestKinds x, String str); } - - interface SN0 { MethodReferenceTestKindsBase make(); } - interface SN1 { MethodReferenceTestKindsBase make(String x); } - - class In extends MethodReferenceTestKindsBase { - In(String val) { - this.val = val; - } - - In() { - this("blank"); - } - } - - String instanceMethod0() { return "IM:0-" + this; } - String instanceMethod1(MethodReferenceTestKinds x) { return "IM:1-" + this + x; } - - static String staticMethod0() { return "SM:0"; } - static String staticMethod1(MethodReferenceTestKinds x) { return "SM:1-" + x; } - - MethodReferenceTestKinds(String val) { - super(val); - } - - MethodReferenceTestKinds() { - super("blank"); - } - - MethodReferenceTestKinds inst(String val) { - return new MethodReferenceTestKinds(val); - } - - public void testMRBound() { - S0 var = this::instanceMethod0; - assertEquals(var.get(), "IM:0-MethodReferenceTestKinds(blank)"); - } - - public void testMRBoundArg() { - S1 var = this::instanceMethod1; - assertEquals(var.get(inst("arg")), "IM:1-MethodReferenceTestKinds(blank)MethodReferenceTestKinds(arg)"); - } - - public void testMRUnbound() { - S1 var = MethodReferenceTestKinds::instanceMethod0; - assertEquals(var.get(inst("rcvr")), "IM:0-MethodReferenceTestKinds(rcvr)"); - } - - public void testMRUnboundArg() { - S2 var = MethodReferenceTestKinds::instanceMethod1; - assertEquals(var.get(inst("rcvr"), inst("arg")), "IM:1-MethodReferenceTestKinds(rcvr)MethodReferenceTestKinds(arg)"); - } - - public void testMRSuper() { - S0 var = super::instanceMethod0; - assertEquals(var.get(), "SIM:0-MethodReferenceTestKinds(blank)"); - } - - public void testMRSuperArg() { - S1 var = super::instanceMethod1; - assertEquals(var.get(inst("arg")), "SIM:1-MethodReferenceTestKinds(blank)MethodReferenceTestKinds(arg)"); - } - - public void testMRStatic() { - S0 var = MethodReferenceTestKinds::staticMethod0; - assertEquals(var.get(), "SM:0"); - } - - public void testMRStaticArg() { - S1 var = MethodReferenceTestKinds::staticMethod1; - assertEquals(var.get(inst("arg")), "SM:1-MethodReferenceTestKinds(arg)"); - } - - public void testMRTopLevel() { - SN0 var = MethodReferenceTestKindsBase::new; - assertEquals(var.make().toString(), "MethodReferenceTestKindsBase(blank)"); - } - - public void testMRTopLevelArg() { - SN1 var = MethodReferenceTestKindsBase::new; - assertEquals(var.make("name").toString(), "MethodReferenceTestKindsBase(name)"); - } -/* unbound inner case not supported anymore (dropped by EG) - public void testMRUnboundInner() { - SXN0 var = MethodReferenceTestKinds.In::new; - assertEquals(var.make(inst("out")).toString(), "In(blank)"); - } - - public void testMRUnboundInnerArg() { - SXN1 var = MethodReferenceTestKinds.In::new; - assertEquals(var.make(inst("out"), "name").toString(), "In(name)"); - } -*/ - public void testMRImplicitInner() { - SN0 var = MethodReferenceTestKinds.In::new; - assertEquals(var.make().toString(), "In(blank)"); - } - - public void testMRImplicitInnerArg() { - SN1 var = MethodReferenceTestKinds.In::new; - assertEquals(var.make("name").toString(), "In(name)"); - } - -} - - -class MethodReferenceTestKindsBase { - String val = "unset"; - - public String toString() { - return getClass().getSimpleName() + "(" + val + ")"; - } - - MethodReferenceTestKindsBase(String val) { - this.val = val; - } - - MethodReferenceTestKindsBase() { - this("blank"); - } - -} - -class MethodReferenceTestKindsSup extends MethodReferenceTestKindsBase { - String instanceMethod0() { return "SIM:0-" + this; } - String instanceMethod1(MethodReferenceTestKinds x) { return "SIM:1-" + this + x; } - - MethodReferenceTestKindsSup(String val) { - super(val); - } - -} -
--- a/jdk/test/jdk/lambda/MethodReferenceTestNew.java Thu Apr 02 17:32:05 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,130 +0,0 @@ -/* - * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -import org.testng.annotations.Test; - -import static org.testng.Assert.assertEquals; - -/** - * @author Robert Field - */ - -@Test -public class MethodReferenceTestNew { - - interface M0<T> { - - T m(); - } - - static class N0 { - - N0() { - } - } - - interface M1<T> { - - T m(Integer a); - } - - static class N1 { - - int i; - - N1(int i) { - this.i = i; - } - } - - interface M2<T> { - - T m(Integer n, String o); - } - - static class N2 { - - Number n; - Object o; - - N2(Number n, Object o) { - this.n = n; - this.o = o; - } - - public String toString() { - return "N2(" + n + "," + o + ")"; - } - } - - interface MV { - - NV m(Integer ai, int i); - } - - static class NV { - - int i; - - NV(int... v) { - i = 0; - for (int x : v) { - i += x; - } - } - - public String toString() { - return "NV(" + i + ")"; - } - } - - public void testConstructorReference0() { - M0<N0> q; - - q = N0::new; - assertEquals(q.m().getClass().getSimpleName(), "N0"); - } - - public void testConstructorReference1() { - M1<N1> q; - - q = N1::new; - assertEquals(q.m(14).getClass().getSimpleName(), "N1"); - } - - public void testConstructorReference2() { - M2<N2> q; - - q = N2::new; - assertEquals(q.m(7, "hi").toString(), "N2(7,hi)"); - } - - public void testConstructorReferenceVarArgs() { - MV q; - - q = NV::new; - assertEquals(q.m(5, 45).toString(), "NV(50)"); - } - -} -
--- a/jdk/test/jdk/lambda/MethodReferenceTestNewInner.java Thu Apr 02 17:32:05 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,150 +0,0 @@ -/* - * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -import org.testng.annotations.Test; - -import static org.testng.Assert.assertEquals; - -/** - * @author Robert Field - */ - -@Test -public class MethodReferenceTestNewInner { - - String note = "NO NOTE"; - - interface M0<T> { - - T m(); - } - - interface MP<T> { - - T m(MethodReferenceTestNewInner m); - } - - class N0 { - - N0() { - } - } - - interface M1<T> { - - T m(Integer a); - } - - class N1 { - - int i; - - N1(int i) { - this.i = i; - } - } - - interface M2<T> { - - T m(Integer n, String o); - } - - class N2 { - - Number n; - Object o; - - N2(Number n, Object o) { - this.n = n; - this.o = o; - } - - public String toString() { - return note + ":N2(" + n + "," + o + ")"; - } - } - - interface MV { - - NV m(Integer ai, int i); - } - - class NV { - - int i; - - NV(int... v) { - i = 0; - for (int x : v) { - i += x; - } - } - - public String toString() { - return note + ":NV(" + i + ")"; - } - } - -/* unbound constructor case not supported anymore (dropped by EG) - public static void testConstructorReferenceP() { - MP<N0> q; - - q = N0::new; - assertEquals(q.m(new MethodReferenceTestNewInner()).getClass().getSimpleName(), "N0"); - } -*/ - public void testConstructorReference0() { - M0<N0> q; - - q = N0::new; - assertEquals(q.m().getClass().getSimpleName(), "N0"); - } - - public void testConstructorReference1() { - M1<N1> q; - - q = N1::new; - assertEquals(q.m(14).getClass().getSimpleName(), "N1"); - } - - public void testConstructorReference2() { - M2<N2> q; - - note = "T2"; - q = N2::new; - assertEquals(q.m(7, "hi").toString(), "T2:N2(7,hi)"); - } - - /*** - public void testConstructorReferenceVarArgs() { - MV q; - - note = "TVA"; - q = NV::new; - assertEquals(q.m(5, 45).toString(), "TNV:NV(50)"); - } - ***/ - -} - -
--- a/jdk/test/jdk/lambda/MethodReferenceTestSueCase1.java Thu Apr 02 17:32:05 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - - -import org.testng.annotations.Test; - -import static org.testng.Assert.assertEquals; - -/** - * @author Robert Field - */ - -@Test -public class MethodReferenceTestSueCase1 { - - public interface Sam2<T> { public String get(T target, String s); } - - String instanceMethod(String s) { return "2"; } - Sam2<MethodReferenceTestSueCase1> var = MethodReferenceTestSueCase1::instanceMethod; - - String m() { return var.get(new MethodReferenceTestSueCase1(), ""); } - - public void testSueCase1() { - assertEquals(m(), "2"); - } -} \ No newline at end of file
--- a/jdk/test/jdk/lambda/MethodReferenceTestSueCase2.java Thu Apr 02 17:32:05 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - - -import org.testng.annotations.Test; - -import static org.testng.Assert.assertEquals; - -/** - * @author Robert Field - */ - -@Test -public class MethodReferenceTestSueCase2 { - - public interface Sam2<T> { public String get(T target, String s); } - - String instanceMethod(String s) { return "2"; } - static Sam2<MethodReferenceTestSueCase2> var = MethodReferenceTestSueCase2::instanceMethod; - - String m() { return var.get(new MethodReferenceTestSueCase2(), ""); } - - public void testSueCase2() { - assertEquals(m(), "2"); - } - -} \ No newline at end of file
--- a/jdk/test/jdk/lambda/MethodReferenceTestSueCase4.java Thu Apr 02 17:32:05 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - - -import org.testng.annotations.Test; - -import static org.testng.Assert.assertEquals; - -/** - * @author Robert Field - */ - -@Test -public class MethodReferenceTestSueCase4 { - - public interface Sam2<T> { public String get(T target, String s); } - - Sam2<Target> var = new Object().equals(new Object()) ? Target::instanceMethod : Target::instanceMethod; - - String m() { - return var.get(new Target(), ""); - } - - static class Target { - String instanceMethod(String s) { return "2"; } - } - - public void testSueCase4() { - assertEquals(m(), "2"); - } - -} \ No newline at end of file
--- a/jdk/test/jdk/lambda/MethodReferenceTestSuper.java Thu Apr 02 17:32:05 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,113 +0,0 @@ -/* - * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -import org.testng.annotations.Test; - -import static org.testng.Assert.assertEquals; - - - -/** - * @author Robert Field - */ - -interface SPRI { String m(String a); } - -class SPRA { - String xsA__(String s) { - return "A__xsA:" + s; - } - - String xsA_M(String s) { - return "A_MxsA:" + s; - } - - String xsAB_(String s) { - return "AB_xsA:" + s; - } - - String xsABM(String s) { - return "ABMxsA:" + s; - } - -} - -class SPRB extends SPRA { - - String xsAB_(String s) { - return "AB_xsB:" + s; - } - - String xsABM(String s) { - return "ABMxsB:" + s; - } - - String xs_B_(String s) { - return "_B_xsB:" + s; - } - - String xs_BM(String s) { - return "_BMxsB:" + s; - } - -} - -@Test -public class MethodReferenceTestSuper extends SPRB { - - String xsA_M(String s) { - return "A_MxsM:" + s; - } - - - String xsABM(String s) { - return "ABMxsM:" + s; - } - - String xs_BM(String s) { - return "_BMxsM:" + s; - } - - public void testMethodReferenceSuper() { - SPRI q; - - q = super::xsA__; - assertEquals(q.m("*"), "A__xsA:*"); - - q = super::xsA_M; - assertEquals(q.m("*"), "A_MxsA:*"); - - q = super::xsAB_; - assertEquals(q.m("*"), "AB_xsB:*"); - - q = super::xsABM; - assertEquals(q.m("*"), "ABMxsB:*"); - - q = super::xs_B_; - assertEquals(q.m("*"), "_B_xsB:*"); - - q = super::xs_BM; - assertEquals(q.m("*"), "_BMxsB:*"); - } - -}
--- a/jdk/test/jdk/lambda/MethodReferenceTestSuperDefault.java Thu Apr 02 17:32:05 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,74 +0,0 @@ -/* - * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -import org.testng.annotations.Test; - -import static org.testng.Assert.assertEquals; - - -/** - * @author Robert Field - */ - -interface DSPRI { String m(String a); } - -interface DSPRA { - default String xsA__(String s) { - return "A__xsA:" + s; - } - - default String xsAB_(String s) { - return "AB_xsA:" + s; - } - -} - -interface DSPRB extends DSPRA { - - default String xsAB_(String s) { - return "AB_xsB:" + s; - } - - default String xs_B_(String s) { - return "_B_xsB:" + s; - } - -} - -@Test -public class MethodReferenceTestSuperDefault implements DSPRB { - - public void testMethodReferenceSuper() { - DSPRI q; - - q = DSPRB.super::xsA__; - assertEquals(q.m("*"), "A__xsA:*"); - - q = DSPRB.super::xsAB_; - assertEquals(q.m("*"), "AB_xsB:*"); - - q = DSPRB.super::xs_B_; - assertEquals(q.m("*"), "_B_xsB:*"); - } - -}
--- a/jdk/test/jdk/lambda/MethodReferenceTestTypeConversion.java Thu Apr 02 17:32:05 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -import org.testng.annotations.Test; - -import static org.testng.Assert.assertEquals; - -/** - * @author Robert Field - */ - -class MethodReferenceTestTypeConversion_E<T> { - T xI(T t) { return t; } -} - -@Test -public class MethodReferenceTestTypeConversion { - - interface ISi { int m(Short a); } - - interface ICc { char m(Character a); } - - public void testUnboxObjectToNumberWiden() { - ISi q = (new MethodReferenceTestTypeConversion_E<Short>())::xI; - assertEquals(q.m((short)77), (short)77); - } - - public void testUnboxObjectToChar() { - ICc q = (new MethodReferenceTestTypeConversion_E<Character>())::xI; - assertEquals(q.m('@'), '@'); - } - -}
--- a/jdk/test/jdk/lambda/MethodReferenceTestVarArgs.java Thu Apr 02 17:32:05 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,195 +0,0 @@ -/* - * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -import org.testng.annotations.Test; -import java.lang.reflect.Array; - -import static org.testng.Assert.assertEquals; - -/** - * @author Robert Field - */ - -@Test -public class MethodReferenceTestVarArgs { - - interface SII { - - String m(Integer a, Integer b); - } - - interface Siii { - - String m(int a, int b, int c); - } - - interface Si { - - String m(int a); - } - - interface SaO { - - String m(Object[] a); - } - - interface Sai { - - String m(int[] a); - } - - interface Svi { - - String m(int... va); - } - - // These should be processed as var args - - static String xvI(Integer... vi) { - StringBuilder sb = new StringBuilder("xvI:"); - for (Integer i : vi) { - sb.append(i); - sb.append("-"); - } - return sb.toString(); - } - - static String xIvI(Integer f, Integer... vi) { - StringBuilder sb = new StringBuilder("xIvI:"); - sb.append(f); - for (Integer i : vi) { - sb.append(i); - sb.append("-"); - } - return sb.toString(); - } - - static String xvi(int... vi) { - int sum = 0; - for (int i : vi) { - sum += i; - } - return "xvi:" + sum; - } - - static String xIvi(Integer f, int... vi) { - int sum = 0; - for (int i : vi) { - sum += i; - } - return "xIvi:(" + f + ")" + sum; - } - - static String xvO(Object... vi) { - StringBuilder sb = new StringBuilder("xvO:"); - for (Object i : vi) { - if (i.getClass().isArray()) { - sb.append("["); - int len = Array.getLength(i); - for (int x = 0; x < len; ++x) { - sb.append(Array.get(i, x)); - sb.append(","); - } - sb.append("]"); - - } else { - sb.append(i); - } - sb.append("*"); - } - return sb.toString(); - } - - public void testVarArgsSuperclass() { - SII q; - - q = MethodReferenceTestVarArgs::xvO; - assertEquals(q.m(55,66), "xvO:55*66*"); - } - - public void testVarArgsArray() { - Sai q; - - q = MethodReferenceTestVarArgs::xvO; - assertEquals(q.m(new int[] { 55,66 } ), "xvO:[55,66,]*"); - } - - public void testVarArgsII() { - SII q; - - q = MethodReferenceTestVarArgs::xvI; - assertEquals(q.m(33,7), "xvI:33-7-"); - - q = MethodReferenceTestVarArgs::xIvI; - assertEquals(q.m(50,40), "xIvI:5040-"); - - q = MethodReferenceTestVarArgs::xvi; - assertEquals(q.m(100,23), "xvi:123"); - - q = MethodReferenceTestVarArgs::xIvi; - assertEquals(q.m(9,21), "xIvi:(9)21"); - } - - public void testVarArgsiii() { - Siii q; - - q = MethodReferenceTestVarArgs::xvI; - assertEquals(q.m(3, 2, 1), "xvI:3-2-1-"); - - q = MethodReferenceTestVarArgs::xIvI; - assertEquals(q.m(888, 99, 2), "xIvI:88899-2-"); - - q = MethodReferenceTestVarArgs::xvi; - assertEquals(q.m(900,80,7), "xvi:987"); - - q = MethodReferenceTestVarArgs::xIvi; - assertEquals(q.m(333,27, 72), "xIvi:(333)99"); - } - - public void testVarArgsi() { - Si q; - - q = MethodReferenceTestVarArgs::xvI; - assertEquals(q.m(3), "xvI:3-"); - - q = MethodReferenceTestVarArgs::xIvI; - assertEquals(q.m(888), "xIvI:888"); - - q = MethodReferenceTestVarArgs::xvi; - assertEquals(q.m(900), "xvi:900"); - - q = MethodReferenceTestVarArgs::xIvi; - assertEquals(q.m(333), "xIvi:(333)0"); - } - - // These should NOT be processed as var args - - public void testVarArgsaO() { - SaO q; - - q = MethodReferenceTestVarArgs::xvO; - assertEquals(q.m(new String[] { "yo", "there", "dude" }), "xvO:yo*there*dude*"); - } - - -}
--- a/jdk/test/jdk/lambda/MethodReferenceTestVarArgsExt.java Thu Apr 02 17:32:05 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,182 +0,0 @@ -/* - * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -import org.testng.annotations.Test; -import java.lang.reflect.Array; - -import static org.testng.Assert.assertEquals; - -/** - * @author Robert Field - */ - -interface NXII { String m(Integer a, Integer b); } - -interface NXiii { String m(int a, int b, int c); } - -interface NXi { String m(int a); } - -interface NXaO { String m(Object[] a); } - -interface NXai { String m(int[] a); } - -interface NXvi { String m(int... va); } - -@Test -public class MethodReferenceTestVarArgsExt { - - // These should be processed as var args - - public void testVarArgsNXSuperclass() { - NXII q; - - q = (new Ext())::xvO; - assertEquals(q.m(55,66), "xvO:55*66*"); - } - - public void testVarArgsNXArray() { - NXai q; - - q = (new Ext())::xvO; - assertEquals(q.m(new int[] { 55,66 } ), "xvO:[55,66,]*"); - } - - public void testVarArgsNXII() { - NXII q; - - q = (new Ext())::xvI; - assertEquals(q.m(33,7), "xvI:33-7-"); - - q = (new Ext())::xIvI; - assertEquals(q.m(50,40), "xIvI:5040-"); - - q = (new Ext())::xvi; - assertEquals(q.m(100,23), "xvi:123"); - - q = (new Ext())::xIvi; - assertEquals(q.m(9,21), "xIvi:(9)21"); - } - - public void testVarArgsNXiii() { - NXiii q; - - q = (new Ext())::xvI; - assertEquals(q.m(3, 2, 1), "xvI:3-2-1-"); - - q = (new Ext())::xIvI; - assertEquals(q.m(888, 99, 2), "xIvI:88899-2-"); - - q = (new Ext())::xvi; - assertEquals(q.m(900,80,7), "xvi:987"); - - q = (new Ext())::xIvi; - assertEquals(q.m(333,27, 72), "xIvi:(333)99"); - } - - public void testVarArgsNXi() { - NXi q; - - q = (new Ext())::xvI; - assertEquals(q.m(3), "xvI:3-"); - - q = (new Ext())::xIvI; - assertEquals(q.m(888), "xIvI:888"); - - q = (new Ext())::xvi; - assertEquals(q.m(900), "xvi:900"); - - q = (new Ext())::xIvi; - assertEquals(q.m(333), "xIvi:(333)0"); - } - - // These should NOT be processed as var args - - public void testVarArgsNXaO() { - NXaO q; - - q = (new Ext())::xvO; - assertEquals(q.m(new String[] { "yo", "there", "dude" }), "xvO:yo*there*dude*"); - } - - -} - -class Ext { - - String xvI(Integer... vi) { - StringBuilder sb = new StringBuilder("xvI:"); - for (Integer i : vi) { - sb.append(i); - sb.append("-"); - } - return sb.toString(); - } - - String xIvI(Integer f, Integer... vi) { - StringBuilder sb = new StringBuilder("xIvI:"); - sb.append(f); - for (Integer i : vi) { - sb.append(i); - sb.append("-"); - } - return sb.toString(); - } - - String xvi(int... vi) { - int sum = 0; - for (int i : vi) { - sum += i; - } - return "xvi:" + sum; - } - - String xIvi(Integer f, int... vi) { - int sum = 0; - for (int i : vi) { - sum += i; - } - return "xIvi:(" + f + ")" + sum; - } - - String xvO(Object... vi) { - StringBuilder sb = new StringBuilder("xvO:"); - for (Object i : vi) { - if (i.getClass().isArray()) { - sb.append("["); - int len = Array.getLength(i); - for (int x = 0; x < len; ++x) { - sb.append(Array.get(i, x)); - sb.append(","); - } - sb.append("]"); - - } else { - sb.append(i); - } - sb.append("*"); - } - return sb.toString(); - } - - -}
--- a/jdk/test/jdk/lambda/MethodReferenceTestVarArgsSuper.java Thu Apr 02 17:32:05 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,200 +0,0 @@ -/* - * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -import org.testng.annotations.Test; -import java.lang.reflect.Array; - -import static org.testng.Assert.assertEquals; - - -/** - * @author Robert Field - */ - -class MethodReferenceTestVarArgsSuper_Sub { - - String xvI(Integer... vi) { - StringBuilder sb = new StringBuilder("xvI:"); - for (Integer i : vi) { - sb.append(i); - sb.append("-"); - } - return sb.toString(); - } - - String xIvI(Integer f, Integer... vi) { - StringBuilder sb = new StringBuilder("xIvI:"); - sb.append(f); - for (Integer i : vi) { - sb.append(i); - sb.append("-"); - } - return sb.toString(); - } - - String xvi(int... vi) { - int sum = 0; - for (int i : vi) { - sum += i; - } - return "xvi:" + sum; - } - - String xIvi(Integer f, int... vi) { - int sum = 0; - for (int i : vi) { - sum += i; - } - return "xIvi:(" + f + ")" + sum; - } - - String xvO(Object... vi) { - StringBuilder sb = new StringBuilder("xvO:"); - for (Object i : vi) { - if (i.getClass().isArray()) { - sb.append("["); - int len = Array.getLength(i); - for (int x = 0; x < len; ++x) { - sb.append(Array.get(i, x)); - sb.append(","); - } - sb.append("]"); - - } else { - sb.append(i); - } - sb.append("*"); - } - return sb.toString(); - } -} - -@Test -public class MethodReferenceTestVarArgsSuper extends MethodReferenceTestVarArgsSuper_Sub { - - interface SPRII { String m(Integer a, Integer b); } - - interface SPRiii { String m(int a, int b, int c); } - - interface SPRi { String m(int a); } - - interface SPRaO { String m(Object[] a); } - - interface SPRai { String m(int[] a); } - - interface SPRvi { String m(int... va); } - - String xvI(Integer... vi) { - return "ERROR"; - } - - String xIvI(Integer f, Integer... vi) { - return "ERROR"; - } - - String xvi(int... vi) { - return "ERROR"; - } - - String xIvi(Integer f, int... vi) { - return "ERROR"; - } - - String xvO(Object... vi) { - return "ERROR"; - } - - // These should be processed as var args - - public void testVarArgsSPRSuperclass() { - SPRII q; - - q = super::xvO; - assertEquals(q.m(55,66), "xvO:55*66*"); - } - - public void testVarArgsSPRArray() { - SPRai q; - - q = super::xvO; - assertEquals(q.m(new int[] { 55,66 } ), "xvO:[55,66,]*"); - } - - public void testVarArgsSPRII() { - SPRII q; - - q = super::xvI; - assertEquals(q.m(33,7), "xvI:33-7-"); - - q = super::xIvI; - assertEquals(q.m(50,40), "xIvI:5040-"); - - q = super::xvi; - assertEquals(q.m(100,23), "xvi:123"); - - q = super::xIvi; - assertEquals(q.m(9,21), "xIvi:(9)21"); - } - - public void testVarArgsSPRiii() { - SPRiii q; - - q = super::xvI; - assertEquals(q.m(3, 2, 1), "xvI:3-2-1-"); - - q = super::xIvI; - assertEquals(q.m(888, 99, 2), "xIvI:88899-2-"); - - q = super::xvi; - assertEquals(q.m(900,80,7), "xvi:987"); - - q = super::xIvi; - assertEquals(q.m(333,27, 72), "xIvi:(333)99"); - } - - public void testVarArgsSPRi() { - SPRi q; - - q = super::xvI; - assertEquals(q.m(3), "xvI:3-"); - - q = super::xIvI; - assertEquals(q.m(888), "xIvI:888"); - - q = super::xvi; - assertEquals(q.m(900), "xvi:900"); - - q = super::xIvi; - assertEquals(q.m(333), "xIvi:(333)0"); - } - - // These should NOT be processed as var args - - public void testVarArgsSPRaO() { - SPRaO q; - - q = super::xvO; - assertEquals(q.m(new String[] { "yo", "there", "dude" }), "xvO:yo*there*dude*"); - } -} -
--- a/jdk/test/jdk/lambda/MethodReferenceTestVarArgsSuperDefault.java Thu Apr 02 17:32:05 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,181 +0,0 @@ -/* - * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -import org.testng.annotations.Test; -import java.lang.reflect.Array; - -import static org.testng.Assert.assertEquals; - -/** - * @author Robert Field - */ - -interface MethodReferenceTestVarArgsSuperDefault_I { - - default String xvI(Integer... vi) { - StringBuilder sb = new StringBuilder("xvI:"); - for (Integer i : vi) { - sb.append(i); - sb.append("-"); - } - return sb.toString(); - } - - default String xIvI(Integer f, Integer... vi) { - StringBuilder sb = new StringBuilder("xIvI:"); - sb.append(f); - for (Integer i : vi) { - sb.append(i); - sb.append("-"); - } - return sb.toString(); - } - - default String xvi(int... vi) { - int sum = 0; - for (int i : vi) { - sum += i; - } - return "xvi:" + sum; - } - - default String xIvi(Integer f, int... vi) { - int sum = 0; - for (int i : vi) { - sum += i; - } - return "xIvi:(" + f + ")" + sum; - } - - default String xvO(Object... vi) { - StringBuilder sb = new StringBuilder("xvO:"); - for (Object i : vi) { - if (i.getClass().isArray()) { - sb.append("["); - int len = Array.getLength(i); - for (int x = 0; x < len; ++x) { - sb.append(Array.get(i, x)); - sb.append(","); - } - sb.append("]"); - - } else { - sb.append(i); - } - sb.append("*"); - } - return sb.toString(); - } -} - -@Test -public class MethodReferenceTestVarArgsSuperDefault implements MethodReferenceTestVarArgsSuperDefault_I { - - interface DSPRII { String m(Integer a, Integer b); } - - interface DSPRiii { String m(int a, int b, int c); } - - interface DSPRi { String m(int a); } - - interface DSPRaO { String m(Object[] a); } - - interface DSPRai { String m(int[] a); } - - interface DSPRvi { String m(int... va); } - - // These should be processed as var args - - public void testVarArgsSPRSuperclass() { - DSPRII q; - - q = MethodReferenceTestVarArgsSuperDefault_I.super::xvO; - assertEquals(q.m(55,66), "xvO:55*66*"); - } - - public void testVarArgsSPRArray() { - DSPRai q; - - q = MethodReferenceTestVarArgsSuperDefault_I.super::xvO; - assertEquals(q.m(new int[] { 55,66 } ), "xvO:[55,66,]*"); - } - - public void testVarArgsSPRII() { - DSPRII q; - - q = MethodReferenceTestVarArgsSuperDefault_I.super::xvI; - assertEquals(q.m(33,7), "xvI:33-7-"); - - q = MethodReferenceTestVarArgsSuperDefault_I.super::xIvI; - assertEquals(q.m(50,40), "xIvI:5040-"); - - q = MethodReferenceTestVarArgsSuperDefault_I.super::xvi; - assertEquals(q.m(100,23), "xvi:123"); - - q = MethodReferenceTestVarArgsSuperDefault_I.super::xIvi; - assertEquals(q.m(9,21), "xIvi:(9)21"); - } - - public void testVarArgsSPRiii() { - DSPRiii q; - - q = MethodReferenceTestVarArgsSuperDefault_I.super::xvI; - assertEquals(q.m(3, 2, 1), "xvI:3-2-1-"); - - q = MethodReferenceTestVarArgsSuperDefault_I.super::xIvI; - assertEquals(q.m(888, 99, 2), "xIvI:88899-2-"); - - q = MethodReferenceTestVarArgsSuperDefault_I.super::xvi; - assertEquals(q.m(900,80,7), "xvi:987"); - - q = MethodReferenceTestVarArgsSuperDefault_I.super::xIvi; - assertEquals(q.m(333,27, 72), "xIvi:(333)99"); - } - - public void testVarArgsSPRi() { - DSPRi q; - - q = MethodReferenceTestVarArgsSuperDefault_I.super::xvI; - assertEquals(q.m(3), "xvI:3-"); - - q = MethodReferenceTestVarArgsSuperDefault_I.super::xIvI; - assertEquals(q.m(888), "xIvI:888"); - - q = MethodReferenceTestVarArgsSuperDefault_I.super::xvi; - assertEquals(q.m(900), "xvi:900"); - - q = MethodReferenceTestVarArgsSuperDefault_I.super::xIvi; - assertEquals(q.m(333), "xIvi:(333)0"); - } - - // These should NOT be processed as var args - - public void testVarArgsSPRaO() { - DSPRaO q; - - q = MethodReferenceTestVarArgsSuperDefault_I.super::xvO; - assertEquals(q.m(new String[] { "yo", "there", "dude" }), "xvO:yo*there*dude*"); - } - - -} -
--- a/jdk/test/jdk/lambda/MethodReferenceTestVarArgsThis.java Thu Apr 02 17:32:05 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,177 +0,0 @@ -/* - * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -import org.testng.annotations.Test; -import java.lang.reflect.Array; - -import static org.testng.Assert.assertEquals; - -/** - * @author Robert Field - */ - -interface NsII { String m(Integer a, Integer b); } - -interface Nsiii { String m(int a, int b, int c); } - -interface Nsi { String m(int a); } - -interface NsaO { String m(Object[] a); } - -interface Nsai { String m(int[] a); } - -interface Nsvi { String m(int... va); } - -@Test -public class MethodReferenceTestVarArgsThis { - - // These should be processed as var args - - String xvI(Integer... vi) { - StringBuilder sb = new StringBuilder("xvI:"); - for (Integer i : vi) { - sb.append(i); - sb.append("-"); - } - return sb.toString(); - } - - String xIvI(Integer f, Integer... vi) { - StringBuilder sb = new StringBuilder("xIvI:"); - sb.append(f); - for (Integer i : vi) { - sb.append(i); - sb.append("-"); - } - return sb.toString(); - } - - String xvi(int... vi) { - int sum = 0; - for (int i : vi) { - sum += i; - } - return "xvi:" + sum; - } - - String xIvi(Integer f, int... vi) { - int sum = 0; - for (int i : vi) { - sum += i; - } - return "xIvi:(" + f + ")" + sum; - } - - String xvO(Object... vi) { - StringBuilder sb = new StringBuilder("xvO:"); - for (Object i : vi) { - if (i.getClass().isArray()) { - sb.append("["); - int len = Array.getLength(i); - for (int x = 0; x < len; ++x) { - sb.append(Array.get(i, x)); - sb.append(","); - } - sb.append("]"); - - } else { - sb.append(i); - } - sb.append("*"); - } - return sb.toString(); - } - - public void testVarArgsNsSuperclass() { - NsII q; - - q = this::xvO; - assertEquals(q.m(55,66), "xvO:55*66*"); - } - - public void testVarArgsNsArray() { - Nsai q; - - q = this::xvO; - assertEquals(q.m(new int[] { 55,66 } ), "xvO:[55,66,]*"); - } - - public void testVarArgsNsII() { - NsII q; - - q = this::xvI; - assertEquals(q.m(33,7), "xvI:33-7-"); - - q = this::xIvI; - assertEquals(q.m(50,40), "xIvI:5040-"); - - q = this::xvi; - assertEquals(q.m(100,23), "xvi:123"); - - q = this::xIvi; - assertEquals(q.m(9,21), "xIvi:(9)21"); - } - - public void testVarArgsNsiii() { - Nsiii q; - - q = this::xvI; - assertEquals(q.m(3, 2, 1), "xvI:3-2-1-"); - - q = this::xIvI; - assertEquals(q.m(888, 99, 2), "xIvI:88899-2-"); - - q = this::xvi; - assertEquals(q.m(900,80,7), "xvi:987"); - - q = this::xIvi; - assertEquals(q.m(333,27, 72), "xIvi:(333)99"); - } - - public void testVarArgsNsi() { - Nsi q; - - q = this::xvI; - assertEquals(q.m(3), "xvI:3-"); - - q = this::xIvI; - assertEquals(q.m(888), "xIvI:888"); - - q = this::xvi; - assertEquals(q.m(900), "xvi:900"); - - q = this::xIvi; - assertEquals(q.m(333), "xIvi:(333)0"); - } - - // These should NOT be processed as var args - - public void testVarArgsNsaO() { - NsaO q; - - q = this::xvO; - assertEquals(q.m(new String[] { "yo", "there", "dude" }), "xvO:yo*there*dude*"); - } - - -}
--- a/jdk/test/jdk/lambda/shapegen/ClassCase.java Thu Apr 02 17:32:05 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,310 +0,0 @@ -/* - * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package shapegen; - -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -/** - * - * @author Robert Field - */ -public class ClassCase { - - public enum Kind { - IVAC (true, "v"), - IPRESENT (true, "p"), - IDEFAULT (true, "d"), - CNONE (false, "n"), - CABSTRACT (false, "a"), - CCONCRETE (false, "c"); - - private final String prefix; - public final boolean isInterface; - - Kind(boolean isInterface, String prefix) { - this.isInterface = isInterface; - this.prefix = prefix; - } - - public String getPrefix() { return prefix; } - } - - public final Kind kind; - private final ClassCase superclass; - private final List<ClassCase> supertypes; - - private String name; - private boolean _OK; - private boolean _HasClassMethod; - private Set<ClassCase> _mprov; - private boolean _IsConcrete; - private boolean _HasDefault; - private ClassCase _mres; - private ClassCase _mdefend; - - private Set<RuleGroup> executed = new HashSet<RuleGroup>(); - - public ClassCase(Kind kind, ClassCase superclass, List<ClassCase> interfaces) { - this.kind = kind; - this.superclass = superclass; - - // Set supertypes from superclass (if any) and interfaces - List<ClassCase> lc; - if (superclass == null) { - lc = interfaces; - } else { - lc = new ArrayList<>(); - lc.add(superclass); - lc.addAll(interfaces); - } - this.supertypes = lc; - } - - public final boolean isInterface() { return kind.isInterface; } - public final boolean isClass() { return !kind.isInterface; } - - public Set<ClassCase> get_mprov() { - exec(RuleGroup.PROVENENCE); - return _mprov; - } - - public void set_mprov(ClassCase cc) { - Set<ClassCase> s = new HashSet<>(); - s.add(cc); - _mprov = s; - } - - public void set_mprov(Set<ClassCase> s) { - _mprov = s; - } - - public ClassCase get_mres() { - exec(RuleGroup.RESOLUTION); - return _mres; - } - - public void set_mres(ClassCase cc) { - _mres = cc; - } - - public ClassCase get_mdefend() { - exec(RuleGroup.DEFENDER); - return _mdefend; - } - - public void set_mdefend(ClassCase cc) { - _mdefend = cc; - } - - public boolean get_HasClassMethod() { - exec(RuleGroup.PROVENENCE); - return _HasClassMethod; - } - - public void set_HasClassMethod(boolean bool) { - _HasClassMethod = bool; - } - - public boolean get_HasDefault() { - exec(RuleGroup.MARKER); - return _HasDefault; - } - - public void set_HasDefault(boolean bool) { - _HasDefault = bool; - } - - public boolean get_IsConcrete() { - exec(RuleGroup.MARKER); - return _IsConcrete; - } - - public void set_IsConcrete(boolean bool) { - _IsConcrete = bool; - } - - public boolean get_OK() { - exec(RuleGroup.CHECKING); - return _OK; - } - - public void set_OK(boolean bool) { - _OK = bool; - } - - public boolean isMethodDefined() { - for (ClassCase cc : supertypes) { - if (cc.isMethodDefined()) { - return true; - } - } - switch (kind) { - case CCONCRETE: - case CABSTRACT: - case IPRESENT: - case IDEFAULT: - return true; - default: - return false; - } - } - - public boolean isAbstract() { - return isMethodDefined() && (get_mres()==null); - } - - public boolean hasSuperclass() { - return superclass != null; - } - - public ClassCase getSuperclass() { - return superclass; - } - - public List<ClassCase> getSupertypes() { - return supertypes; - } - - public List<ClassCase> getInterfaces() { - if (superclass != null) { - if (supertypes.get(0) != superclass) { - throw new AssertionError("superclass missing from supertypes"); - } - return supertypes.subList(1, supertypes.size()); - } else { - return supertypes; - } - } - - public boolean isSubtypeOf(ClassCase cc) { - // S-Refl - if (cc.equals(this)) { - return true; - } - - // S-Def - for (ClassCase sp : getSupertypes()) { - if (cc.equals(sp)) { - return true; - } - } - - // _S-Trans - for (ClassCase sp : getSupertypes()) { - if (sp.isSubtypeOf(cc)) { - return true; - } - } - - return false; - } - - public void init(Map<String, Integer> namingContext) { - if (name != null) { - return; // Already inited - } - - for (ClassCase sup : supertypes) { - sup.init(namingContext); - } - - // Build name - StringBuilder sb = new StringBuilder(); - if (!supertypes.isEmpty()) { - sb.append(isInterface() ? "I" : "C"); - for (ClassCase cc : supertypes) { - sb.append(cc.getName()); - } - sb.append(kind.isInterface ? "i" : "c"); - } - sb.append(kind.prefix); - String pname = sb.toString(); - Integer icnt = namingContext.get(pname); - int cnt = icnt == null ? 0 : icnt; - ++cnt; - namingContext.put(pname, cnt); - if (cnt > 1) { - sb.append(cnt); - } - this.name = sb.toString(); - } - - public boolean isa(Kind... kinds) { - for (Kind k : kinds) { - if (kind == k) { - return true; - } - } - return false; - } - - private void exec(RuleGroup rg ) { - if (!executed.contains(rg)) { - rg.exec(this); - executed.add(rg); - } - } - - public void collectClasses(Set<ClassCase> seen) { - seen.add(this); - for (ClassCase cc : supertypes) { - cc.collectClasses(seen); - } - } - - public String getID() { - if (name == null) { - throw new Error("Access to uninitialized ClassCase"); - } else { - return name; - } - } - - public final String getName() { - if (name == null) { - return "ClassCase uninited@" + hashCode(); - } else { - return name; - } - } - - @Override - public boolean equals(Object obj) { - return obj instanceof ClassCase && getID().equals(((ClassCase)obj).getID()); - } - - @Override - public int hashCode() { - return getID().hashCode(); - } - - @Override - public String toString() { - return getName(); - } -}
--- a/jdk/test/jdk/lambda/shapegen/Hierarchy.java Thu Apr 02 17:32:05 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,207 +0,0 @@ -/* - * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package shapegen; - -import java.util.ArrayList; -import java.util.List; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -import static shapegen.ClassCase.Kind.*; - -/** - * - * @author Robert Field - */ -public class Hierarchy { - - public final ClassCase root; - public final Set<ClassCase> all; - - public Hierarchy(ClassCase root) { - this.root = root; - root.init(new HashMap<String,Integer>()); - Set<ClassCase> allClasses = new HashSet<>(); - root.collectClasses(allClasses); - this.all = allClasses; - } - - public boolean anyDefaults() { - for (ClassCase cc : all) { - if (cc.kind == IDEFAULT) { - return true; - } - } - return false; - } - - public boolean get_OK() { - return root.get_OK(); - } - - public String testName() { - return root + "Test"; - } - - private static void genInterfaceList(StringBuilder buf, String prefix, List<ClassCase> interfaces) { - if (!interfaces.isEmpty()) { - buf.append(" "); - buf.append(prefix); - buf.append(" "); - buf.append(interfaces.get(0)); - for (int i = 1; i < interfaces.size(); ++i) { - buf.append(", " + interfaces.get(i)); - } - } - } - - public static void genClassDef(StringBuilder buf, ClassCase cc, String implClass, List<ClassCase> defaultRef) { - if (cc.isInterface()) { - buf.append("interface "); - buf.append(cc.getName() + " "); - genInterfaceList(buf, "extends", cc.getInterfaces()); - buf.append(" {\n"); - - switch (cc.kind) { - case IDEFAULT: - buf.append(" default String m() { return \"\"; }\n"); - defaultRef.add(cc); - break; - case IPRESENT: - buf.append(" String m();\n"); - break; - case IVAC: - break; - default: - throw new AssertionError("Unexpected kind"); - } - buf.append("}\n\n"); - } else { - buf.append((cc.isAbstract()? "abstract " : "")); - buf.append(" class " + cc.getName()); - if (cc.getSuperclass() != null) { - buf.append(" extends " + cc.getSuperclass()); - } - - genInterfaceList(buf, "implements", cc.getInterfaces()); - buf.append(" {\n"); - - switch (cc.kind) { - case CCONCRETE: - buf.append(" public String m() { return \"\"; }\n"); - break; - case CABSTRACT: - buf.append(" public abstract String m();\n"); - break; - case CNONE: - break; - default: - throw new AssertionError("Unexpected kind"); - } - buf.append("}\n\n"); - } - } - - @Override - public boolean equals(Object obj) { - return obj instanceof Hierarchy && root.getID().equals(((Hierarchy)obj).root.getID()); - } - - @Override - public int hashCode() { - return root.getID().hashCode(); - } - - @Override - public String toString() { - return root.getName(); - } - - private static String classNames[] = { - "C", "D", "E", "F", "G", "H", "S", "T", "U", "V" - }; - - private static String interfaceNames[] = { - "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R" - }; - - private static int CLASS_INDEX = 0; - private static int INTERFACE_INDEX = 1; - private static int NUM_INDICIES = 2; - - public List<String> getDescription() { - Map<ClassCase,String> nameMap = new HashMap<>(); - assignNames(root, new int[NUM_INDICIES], nameMap); - - ArrayList<String> res = new ArrayList<>(); - if (root.getSupertypes().size() == 0) { - res.add(nameMap.get(root) + root.kind.getPrefix() + "()"); - } else { - genCaseDescription(root, res, new HashSet<ClassCase>(), nameMap); - } - return res; - } - - private static void assignNames( - ClassCase cc, int indices[], Map<ClassCase,String> names) { - String name = names.get(cc); - if (name == null) { - if (cc.isInterface()) { - names.put(cc, interfaceNames[indices[INTERFACE_INDEX]++]); - } else { - names.put(cc, classNames[indices[CLASS_INDEX]++]); - } - for (int i = 0; i < cc.getSupertypes().size(); ++i) { - assignNames(cc.getSupertypes().get(i), indices, names); - } - } - } - - private static void genCaseDescription( - ClassCase cc, List<String> res, Set<ClassCase> alreadyDone, - Map<ClassCase,String> nameMap) { - if (!alreadyDone.contains(cc)) { - if (cc.getSupertypes().size() > 0) { - StringBuilder sb = new StringBuilder(); - sb.append(nameMap.get(cc)); - sb.append(cc.kind.getPrefix()); - sb.append("("); - for (int i = 0; i < cc.getSupertypes().size(); ++i) { - ClassCase supertype = cc.getSupertypes().get(i); - if (i != 0) { - sb.append(","); - } - genCaseDescription(supertype, res, alreadyDone, nameMap); - sb.append(nameMap.get(supertype)); - sb.append(supertype.kind.getPrefix()); - } - sb.append(")"); - res.add(sb.toString()); - } - } - alreadyDone.add(cc); - } -}
--- a/jdk/test/jdk/lambda/shapegen/HierarchyGenerator.java Thu Apr 02 17:32:05 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,190 +0,0 @@ -/* - * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package shapegen; - -import shapegen.ClassCase.Kind; - -import java.util.Collection; -import java.util.Set; -import java.util.HashSet; -import java.util.Collections; -import java.util.ArrayList; -import java.util.List; - -import static shapegen.ClassCase.Kind.*; - -import static java.lang.Math.pow; - -/** - * - * @author Robert Field - */ -public final class HierarchyGenerator { - - private int okcnt = 0; - private int errcnt = 0; - private Set<Hierarchy> uniqueOK = new HashSet<>(); - private Set<Hierarchy> uniqueErr = new HashSet<>(); - - /** - * @param args the command line arguments - */ - public HierarchyGenerator() { - organize("exhaustive interface", iExhaustive(2)); - organize("exhaustive class", cExhaustive()); - organize("shapes interface", iShapes()); - organize("shapes class/interface", ciShapes()); - - System.out.printf("\nExpect OK: %d -- unique %d", okcnt, uniqueOK.size()); - System.out.printf("\nExpect Error: %d -- unique %d\n", errcnt, uniqueErr.size()); - } - - public Collection<Hierarchy> getOK() { - return uniqueOK; - } - - public Collection<Hierarchy> getErr() { - return uniqueErr; - } - - private void organize(String tname, List<Hierarchy> totest) { - System.out.printf("\nGenerating %s....\n", tname); - int nodefault = 0; - List<Hierarchy> ok = new ArrayList<>(); - List<Hierarchy> err = new ArrayList<>(); - for (Hierarchy cc : totest) { - if (cc.anyDefaults()) { - //System.out.printf(" %s\n", cc); - if (cc.get_OK()) { - ok.add(cc); - } else { - err.add(cc); - } - } else { - ++nodefault; - } - } - - errcnt += err.size(); - okcnt += ok.size(); - uniqueErr.addAll(err); - uniqueOK.addAll(ok); - - System.out.printf(" %5d No default\n %5d Error\n %5d OK\n %5d Total\n", - nodefault, err.size(), ok.size(), totest.size()); - } - - public List<Hierarchy> iExhaustive(int idepth) { - List<ClassCase> current = new ArrayList<>(); - for (int i = 0; i < idepth; ++i) { - current = ilayer(current); - } - return wrapInClassAndHierarchy(current); - } - - private List<ClassCase> ilayer(List<ClassCase> srcLayer) { - List<ClassCase> lay = new ArrayList<>(); - for (int i = (int) pow(2, srcLayer.size()) - 1; i >= 0; --i) { - List<ClassCase> itfs = new ArrayList<>(); - for (int b = srcLayer.size() - 1; b >= 0; --b) { - if ((i & (1<<b)) != 0) { - itfs.add(srcLayer.get(b)); - } - } - lay.add(new ClassCase(IVAC, null, itfs)); - lay.add(new ClassCase(IPRESENT, null, itfs)); - lay.add(new ClassCase(IDEFAULT, null, itfs)); - lay.add(new ClassCase(IDEFAULT, null, itfs)); - } - return lay; - } - - public List<Hierarchy> cExhaustive() { - final Kind[] iKinds = new Kind[]{IDEFAULT, IVAC, IPRESENT, null}; - final Kind[] cKinds = new Kind[]{CNONE, CABSTRACT, CCONCRETE}; - List<Hierarchy> totest = new ArrayList<>(); - for (int i1 = 0; i1 < iKinds.length; ++i1) { - for (int i2 = 0; i2 < iKinds.length; ++i2) { - for (int i3 = 0; i3 < iKinds.length; ++i3) { - for (int c1 = 0; c1 < cKinds.length; ++c1) { - for (int c2 = 0; c2 < cKinds.length; ++c2) { - for (int c3 = 0; c3 < cKinds.length; ++c3) { - totest.add( new Hierarchy( - new ClassCase(cKinds[c1], - new ClassCase(cKinds[c2], - new ClassCase(cKinds[c3], - null, - iList(iKinds[i1]) - ), - iList(iKinds[i2]) - ), - iList(iKinds[i3]) - ))); - } - } - } - } - } - } - return totest; - } - - public static final List<ClassCase> EMPTY_LIST = new ArrayList<>(); - - private List<ClassCase> iList(Kind kind) { - if (kind == null) { - return EMPTY_LIST; - } else { - List<ClassCase> itfs = new ArrayList<>(); - itfs.add(new ClassCase(kind, null, EMPTY_LIST)); - return itfs; - } - } - - public List<Hierarchy> ciShapes() { - return wrapInHierarchy(TTShape.allCases(true)); - } - - public List<Hierarchy> iShapes() { - return wrapInClassAndHierarchy(TTShape.allCases(false)); - } - - public List<Hierarchy> wrapInClassAndHierarchy(List<ClassCase> ihs) { - List<Hierarchy> totest = new ArrayList<>(); - for (ClassCase cc : ihs) { - List<ClassCase> interfaces = new ArrayList<>(); - interfaces.add(cc); - totest.add(new Hierarchy(new ClassCase(CNONE, null, interfaces))); - } - return totest; - } - - public List<Hierarchy> wrapInHierarchy(List<ClassCase> ihs) { - List<Hierarchy> totest = new ArrayList<>(); - for (ClassCase cc : ihs) { - totest.add(new Hierarchy(cc)); - } - return totest; - } -}
--- a/jdk/test/jdk/lambda/shapegen/Rule.java Thu Apr 02 17:32:05 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package shapegen; - -/** - * - * @author Robert Field - */ -public abstract class Rule { - - public final String name; - - public Rule(String name) { - this.name = name; - } - - abstract boolean guard(ClassCase cc); - - abstract void eval(ClassCase cc); - - @Override - public String toString() { - return name; - } -}
--- a/jdk/test/jdk/lambda/shapegen/RuleGroup.java Thu Apr 02 17:32:05 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,204 +0,0 @@ -/* - * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package shapegen; - -import java.util.HashSet; -import java.util.Set; - -import static shapegen.ClassCase.Kind.*; - -/** - * - * @author Robert Field - */ -public class RuleGroup { - - final String name; - private final Rule[] rules; - - public RuleGroup(String name, Rule[] rules) { - this.name = name; - this.rules = rules; - } - - public boolean exec(ClassCase cc) { - boolean found = false; - for (Rule rule : rules) { - if (rule.guard(cc)) { - if (found) { - throw new RuntimeException("Bad rules -- multiple matches " + toString() + " for " + cc); - } else { - rule.eval(cc); - found = true; - } - } - } - return found; - } - - @Override - public String toString() { - return name; - } - - public static RuleGroup PROVENENCE = new RuleGroup("Provenence", new Rule[] { - new Rule("P-CDeclare") { - boolean guard(ClassCase cc) { - return cc.isa(CCONCRETE, CABSTRACT); - } - - void eval(ClassCase cc) { - cc.set_mprov(cc); - cc.set_HasClassMethod(true); - } - }, - - new Rule("P-IDeclare") { - boolean guard(ClassCase cc) { - return cc.isa(IDEFAULT, IPRESENT); - } - - void eval(ClassCase cc) { - cc.set_mprov(cc); - } - }, - - new Rule("P-IntfInh") { - boolean guard(ClassCase cc) { - return cc.isa(IVAC, CNONE) && !(cc.hasSuperclass() && cc.getSuperclass().get_HasClassMethod()); - } - - void eval(ClassCase cc) { - Set<ClassCase> _S = new HashSet<>(); - for (ClassCase t : cc.getSupertypes()) { - _S.addAll(t.get_mprov()); - } - Set<ClassCase> tops = new HashSet<>(); - for (ClassCase _W : _S) { - for (ClassCase _V : _S) { - if (_V.equals(_W) || !(_V.isSubtypeOf(_W))) { - tops.add(_W); - } - } - } - cc.set_mprov(tops); - } - }, - - new Rule("P-ClassInh") { - boolean guard(ClassCase cc) { - return cc.isa(CNONE) && (cc.hasSuperclass() && cc.getSuperclass().get_HasClassMethod()); - } - - void eval(ClassCase cc) { - cc.set_mprov(cc.getSuperclass()); - cc.set_HasClassMethod(true); - } - }, - - }); - - public static RuleGroup MARKER = new RuleGroup("Marker", new Rule[] { - new Rule("M-Default") { - boolean guard(ClassCase cc) { - return cc.isa(IDEFAULT); - } - - void eval(ClassCase cc) { - cc.set_HasDefault(true); - } - }, - - new Rule("M-Conc") { - boolean guard(ClassCase cc) { - return cc.isa(CCONCRETE); - } - - void eval(ClassCase cc) { - cc.set_IsConcrete(true); - } - }, - - }); - - public static RuleGroup RESOLUTION = new RuleGroup("Resolution", new Rule[] { - new Rule("R-Resolve") { - boolean guard(ClassCase cc) { - if (!(cc.isClass() && cc.get_mprov().size() == 1)) { - return false; - } - ClassCase _V = cc.get_mprov().iterator().next(); - return _V.get_IsConcrete() || _V.get_HasDefault(); - } - - void eval(ClassCase cc) { - ClassCase _V = cc.get_mprov().iterator().next(); - cc.set_mres(_V); - } - }, - - }); - - public static RuleGroup DEFENDER = new RuleGroup("Defender", new Rule[] { - new Rule("D-Defend") { - boolean guard(ClassCase cc) { - ClassCase mresSuper = cc.hasSuperclass() ? cc.getSuperclass().get_mres() : null; - boolean eq = cc.get_mres() == null ? mresSuper == null : cc.get_mres().equals(mresSuper); - return cc.isa(CNONE) && !eq; - } - - void eval(ClassCase cc) { - cc.set_mdefend(cc.get_mres()); - } - }, - - }); - - public static RuleGroup CHECKING = new RuleGroup("Checking", new Rule[] { - new Rule("C-Check") { - boolean guard(ClassCase cc) { - for (ClassCase t : cc.getSupertypes()) { - if (! t.get_OK()) { - return false; - } - } - int defenderCount = 0; - int provCount = 0; - for (ClassCase prov : cc.get_mprov()) { - if (prov.get_HasDefault()) { - defenderCount++; - } - provCount++; - } - return provCount <= 1 || defenderCount == 0; - } - - void eval(ClassCase cc) { - cc.set_OK(true); - } - }, - - }); - -}
--- a/jdk/test/jdk/lambda/shapegen/TTNode.java Thu Apr 02 17:32:05 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,124 +0,0 @@ -/* - * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package shapegen; - -import shapegen.ClassCase.Kind; - -import java.util.ArrayList; -import java.util.List; -import java.util.Set; - -import static shapegen.ClassCase.Kind.*; - -/** - * Type Template Node - * - * @author Robert Field - */ -public class TTNode { - - final List<TTNode> supertypes; - final boolean canBeClass; - - private int currentKindIndex; - private Kind[] kinds; - - public TTNode(List<TTNode> subtypes, boolean canBeClass) { - this.supertypes = subtypes; - this.canBeClass = canBeClass; - } - - public void start(boolean includeClasses) { - kinds = - supertypes.isEmpty()? - (new Kind[]{IDEFAULT, IPRESENT}) - : ((includeClasses && canBeClass)? - new Kind[]{CNONE, IVAC, IDEFAULT, IPRESENT} - : new Kind[]{IVAC, IDEFAULT, IPRESENT}); - currentKindIndex = 0; - - for (TTNode sub : supertypes) { - sub.start(includeClasses); - } - } - - public boolean next() { - ++currentKindIndex; - if (currentKindIndex >= kinds.length) { - currentKindIndex = 0; - return false; - } else { - return true; - } - } - - public void collectAllSubtypes(Set<TTNode> subs) { - subs.add(this); - for (TTNode n : supertypes) { - n.collectAllSubtypes(subs); - } - } - - private Kind getKind() { - return kinds[currentKindIndex]; - } - - boolean isInterface() { - return getKind().isInterface; - } - - boolean isClass() { - return !isInterface(); - } - - boolean hasDefault() { - return getKind() == IDEFAULT; - } - - public boolean isValid() { - for (TTNode n : supertypes) { - if (!n.isValid() || (isInterface() && n.isClass())) { - return false; - } - } - return true; - } - - public ClassCase genCase() { - ClassCase subclass; - List<TTNode> ttintfs; - if (isClass() && !supertypes.isEmpty() && supertypes.get(0).isClass()) { - subclass = supertypes.get(0).genCase(); - ttintfs = supertypes.subList(1, supertypes.size()); - } else { - subclass = null; - ttintfs = supertypes; - } - List<ClassCase> intfs = new ArrayList<>(); - for (TTNode node : ttintfs) { - intfs.add(node.genCase()); - } - return new ClassCase(getKind(), subclass, intfs); - } -}
--- a/jdk/test/jdk/lambda/shapegen/TTParser.java Thu Apr 02 17:32:05 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,98 +0,0 @@ -/* - * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package shapegen; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.io.IOException; -import java.io.StringReader; - -import static java.lang.Character.isLetter; -import static java.lang.Character.isUpperCase; -import static java.lang.Character.isWhitespace; - -/** - * Parse a type template definition string - * - * input :: classDef - * classDef :: letter [ ( classDef* ) ] - * - * @author Robert Field - */ -public class TTParser extends StringReader { - - private Map<Character, TTNode> letterMap = new HashMap<>(); - private char ch; - - private final String def; - - public TTParser(String s) { - super(s); - this.def = s; - } - - private void advance() throws IOException { - do { - ch = (char)read(); - } while (isWhitespace(ch)); - } - - public TTNode parse() { - try { - advance(); - return classDef(); - } catch (IOException t) { - throw new RuntimeException(t); - } - } - - private TTNode classDef() throws IOException { - if (!isLetter(ch)) { - if (ch == (char)-1) { - throw new IOException("Unexpected end of type template in " + def); - } else { - throw new IOException("Unexpected character in type template: " + (Character)ch + " in " + def); - } - } - char nodeCh = ch; - TTNode node = letterMap.get(nodeCh); - boolean canBeClass = isUpperCase(nodeCh); - advance(); - if (node == null) { - List<TTNode> subtypes = new ArrayList<>(); - if (ch == '(') { - advance(); - while (ch != ')') { - subtypes.add(classDef()); - } - advance(); - } - node = new TTNode(subtypes, canBeClass); - letterMap.put(nodeCh, node); - } - return node; - } -}
--- a/jdk/test/jdk/lambda/shapegen/TTShape.java Thu Apr 02 17:32:05 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,102 +0,0 @@ -/* - * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package shapegen; - -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -/** - * - * @author Robert Field - */ -public class TTShape { - - private final TTNode root; - private final TTNode[] nodes; - - TTShape(TTNode root) { - this.root = root; - Set<TTNode> subs = new HashSet<>(); - root.collectAllSubtypes(subs); - nodes = subs.toArray(new TTNode[subs.size()]); - } - - private List<ClassCase> toCases(boolean includeClasses) { - List<ClassCase> ccs = new ArrayList<>(); - root.start(includeClasses); - int i; - outer: - while (true) { - if (root.isValid()) { - ClassCase cc = root.genCase(); - //System.out.println(cc); - ccs.add(cc); - } - - i = 0; - do { - if (i >= nodes.length) { - break outer; - } - } while(!nodes[i++].next()); - } - return ccs; - } - - public static List<ClassCase> allCases(boolean includeClasses) { - List<ClassCase> ccs = new ArrayList<>(); - for (TTShape shape : SHAPES) { - ccs.addAll(shape.toCases(includeClasses)); - } - return ccs; - } - - public static TTShape parse(String s) { - return new TTShape(new TTParser(s).parse()); - } - - public static final TTShape[] SHAPES = new TTShape[] { - parse("a"), - parse("a(b)"), - parse("A(bb)"), - parse("A(B(d)c(d))"), - parse("A(b(c))"), - parse("A(B(cd)d)"), - parse("A(B(c)c)"), - parse("A(B(Ce)d(e))"), - parse("A(B(C)d(e))"), - parse("A(Bc(d))"), - parse("A(B(d)dc)"), - parse("A(B(dc)dc)"), - parse("A(B(c(d))d)"), - parse("A(B(C(d))d)"), - parse("A(B(C(e)d(e))e)"), - parse("A(B(c(d))c)"), - parse("A(B(dc(d))c)"), - parse("A(B(C(d))d)"), - }; - -}