diff --git a/full-build.sh b/full-build.sh index 067186e98bd..6cecb1cfbb6 100755 --- a/full-build.sh +++ b/full-build.sh @@ -42,6 +42,8 @@ while [ "$1" != "" ]; do shift done +MVN_ARGS+=(-fae) + MVN_ARGS+=(-PuseJenkinsSnapshots) MVN_ARGS+=("-Dmaven.home=$(./mvnw --version | grep "Maven home:" | cut -c 13-)") diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/Java6RuntimeInjectorProvider.java b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/Java6RuntimeInjectorProvider.java deleted file mode 100644 index 8a5d2ed873e..00000000000 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/Java6RuntimeInjectorProvider.java +++ /dev/null @@ -1,34 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2015, 2016 itemis AG (http://www.itemis.eu) and others. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * SPDX-License-Identifier: EPL-2.0 - *******************************************************************************/ -package org.eclipse.xtend.core.tests; - -import org.eclipse.xtext.util.JavaVersion; -import org.eclipse.xtext.xbase.testing.JavaVersionModule; - -import com.google.inject.Guice; -import com.google.inject.Injector; - -/** - * @author Miro Spoenemann - Initial contribution and API - */ -public class Java6RuntimeInjectorProvider extends RuntimeInjectorProvider { - - @Override - protected Injector internalCreateInjector() { - return new RuntimeTestSetup() { - - @Override - public Injector createInjector() { - return Guice.createInjector(new XtendRuntimeTestModule(), new JavaVersionModule(JavaVersion.JAVA6)); - } - - }.createInjectorAndDoEMFRegistration(); - } - -} diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/ModelExtensionsTest.java b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/ModelExtensionsTest.java index 48155c919ab..ce3e96070ca 100644 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/ModelExtensionsTest.java +++ b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/ModelExtensionsTest.java @@ -40,7 +40,7 @@ public class ModelExtensionsTest extends AbstractXtendTestCase { @Test public void testXtendFunction() throws Exception { XtendFile file = file("package foo class Bar { def int foo() {1}}"); - XtendFunction xtendFunction = (XtendFunction) ((XtendClass) file.getXtendTypes().get(0)).getMembers().get(0); + XtendFunction xtendFunction = (XtendFunction) file.getXtendTypes().get(0).getMembers().get(0); assertEquals("foo", xtendFunction.getName()); } diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/AbstractXbaseEvaluationTest.java b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/AbstractXbaseEvaluationTest.java deleted file mode 100644 index b95582fbd7d..00000000000 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/AbstractXbaseEvaluationTest.java +++ /dev/null @@ -1,5017 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010, 2019 itemis AG (http://www.itemis.eu) and others. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * SPDX-License-Identifier: EPL-2.0 - *******************************************************************************/ -package org.eclipse.xtend.core.tests.compiler; - -import static com.google.common.collect.Lists.*; -import static com.google.common.collect.Maps.*; -import static com.google.common.collect.Sets.*; -import static java.util.Collections.*; - -import java.io.IOException; -import java.lang.annotation.RetentionPolicy; -import java.lang.reflect.InvocationTargetException; -import java.math.BigDecimal; -import java.math.BigInteger; -import java.math.MathContext; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import java.util.Stack; - -import org.eclipse.xtend.core.tests.util.TemporaryFolder; -import org.eclipse.xtext.xbase.lib.Pair; -import org.junit.Assert; -import org.junit.Ignore; -import org.junit.Rule; -import org.junit.Test; - -import com.google.common.collect.ImmutableMap; -import com.google.inject.Inject; - -import testdata.ExceptionSubclass; -import testdata.OuterClass; - -/** - * @author Sebastian Zarnekow - Initial contribution and API - * @author Sven Efftinge - */ -public abstract class AbstractXbaseEvaluationTest extends Assert { - - @Rule - @Inject public TemporaryFolder temporaryFolder = new TemporaryFolder(); - - @Test public void testReservedWordEnum() throws Exception { - assertEvaluatesTo(Boolean.TRUE, "typeof(java.lang.annotation.RetentionPolicy).enum"); - } - - @Test public void testReservedWordEnum_02() throws Exception { - assertEvaluatesTo(Boolean.TRUE, "java.lang.annotation.RetentionPolicy.enum"); - } - - @Test public void testReservedWordEnum_03() throws Exception { - assertEvaluatesTo(RetentionPolicy.SOURCE, "java.lang.annotation.RetentionPolicy.SOURCE"); - } - - @Test public void testReservedWordInterface() throws Exception { - assertEvaluatesTo(Boolean.TRUE, "typeof(Iterable).interface"); - } - - @Test public void testReservedWordInterface_02() throws Exception { - assertEvaluatesTo(Boolean.TRUE, "Iterable.interface"); - } - - @Test public void testReservedWordAnnotation() throws Exception { - assertEvaluatesTo(Boolean.TRUE, "typeof(Override).annotation"); - } - - @Test public void testReservedWordClass() throws Exception { - assertEvaluatesTo(Class.class, "typeof(Override).class"); - } - - @Test public void testDoubleSwitch() throws Exception { - assertEvaluatesTo("foo","{ val x = 'foo' switch x.length { case 2 : 'bla'.toString } switch x.length { case 3 : 'foo'.toString } }"); - } - - @Test public void testIntLiteral_0() throws Exception { - assertEvaluatesTo(1, "1"); - } - - @Test public void testIntLiteral_2() throws Exception { - assertEvaluatesTo(0x17, "0x17"); - } - - @Test public void testIntLiteral_2a() throws Exception { - assertEvaluatesTo(0x17, "0X17"); - } - - @Test public void testIntLiteral_4() throws Exception { - assertEvaluatesTo(123456789, "123_456_789"); - } - - @Test public void testIntLiteral_5() throws Exception { - assertEvaluatesTo(0xffffeeee, "0xffff_eeee"); - } - - @Test public void testLongLiteral_0() throws Exception { - assertEvaluatesTo(1l, "1l"); - } - - @Test public void testLongLiteral_2() throws Exception { - assertEvaluatesTo(0x17l, "0x17#L"); - } - - @Test public void testLongLiteral_4() throws Exception { - assertEvaluatesTo(123456789123456789L, "123_456_789_123_456_789L"); - } - - @Test public void testLongLiteral_5() throws Exception { - assertEvaluatesTo(0xffffeeeeddddccccl, "0xffff_eeee_dddd_cccc#L"); - } - - @Test public void testFloatLiteral_0() throws Exception { - assertEvaluatesTo(1f, "1f"); - } - - @Test public void testFloatLiteral_1() throws Exception { - assertEvaluatesTo(17f, "017f"); - } - - @Test public void testFloatLiteral_2() throws Exception { - assertEvaluatesTo(1.0f, "1.0f"); - } - - @Test public void testFloatLiteral_3() throws Exception { - assertEvaluatesTo(1.0e-10f, "1.0e-10f"); - } - - @Test public void testFloatLiteral_4() throws Exception { - assertEvaluatesTo(1.0e+10f, "1.0e+10f"); - } - - @Test public void testFloatLiteral_5() throws Exception { - assertEvaluatesTo(1.0E10f, "1.0E10f"); - } - - @Test public void testFloatLiteral_6() throws Exception { - assertEvaluatesTo(1E10f, "1E10f"); - } - - @Test public void testDoubleLiteral_0() throws Exception { - assertEvaluatesTo(1d, "1d"); - } - - @Test public void testDoubleLiteral_2() throws Exception { - assertEvaluatesTo(1.0, "1.0"); - } - - @Test public void testDoubleLiteral_3() throws Exception { - assertEvaluatesTo(1.0e-10, "1.0e-10"); - } - - @Test public void testDoubleLiteral_4() throws Exception { - assertEvaluatesTo(1.0E+10, "1.0E+10"); - } - - @Test public void testDoubleLiteral_5() throws Exception { - assertEvaluatesTo(1.0E10, "1.0E10"); - } - - @Test public void testDoubleLiteral_6() throws Exception { - assertEvaluatesTo(1e10, "1e10"); - } - - @Test public void testDoubleLiteral_7() throws Exception { - assertEvaluatesTo(1.0d, "1.0d"); - } - - @Test public void testDoubleLiteral_8() throws Exception { - assertEvaluatesTo(1.0e-10d, "1.0e-10d"); - } - - @Test public void testDoubleLiteral_9() throws Exception { - assertEvaluatesTo(1.0E+10d, "1.0E+10d"); - } - - @Test public void testDoubleLiteral_10() throws Exception { - assertEvaluatesTo(1.0E10d, "1.0E10d"); - } - - @Test public void testDoubleLiteral_11() throws Exception { - assertEvaluatesTo(1e10d, "1e10d"); - } - - @Test public void testDoubleLiteral_12() throws Exception { - assertEvaluatesTo(1.123456789e10d, "1.123_456_789e1_0d"); - } - - @Test public void testDoubleLiteral_13() throws Exception { - assertEvaluatesTo(123456789d, "123_456_789d"); - } - - @Test public void testBigInteger_0() throws Exception { - assertEvaluatesTo(new BigInteger("1"), "1bi"); - } - - @Test public void testBigInteger_1() throws Exception { - assertEvaluatesTo(new BigInteger("12345678901234567890123456789012345678901234567890"), - "1234567890_12345678901234567890_1234567890_1234567890_Bi"); - } - - @Test public void testBigInteger_3() throws Exception { - assertEvaluatesTo(new BigInteger("77", 16), "0x77#bI"); - } - - @Test public void testBigInteger_4() throws Exception { - assertEvaluatesTo(new BigInteger("1000000"), "10e+5bI"); - } - - @Test public void testBigInteger_5() throws Exception { - assertEvaluatesTo(new BigDecimal("10e+12345").toBigInteger(), "10e+12345bI"); - } - - @Test public void testBigInteger_6() throws Exception { - assertEvaluatesTo(new BigInteger("beefbeefbeefbeefbeef", 16), "0xbeef_beef_beef_beef_beef#BI"); - } - - @Test public void testBigDecimal_0() throws Exception { - assertEvaluatesTo(new BigDecimal("1.0"), "1.0bd"); - } - - @Test public void testBigDecimal_1() throws Exception { - assertEvaluatesTo(new BigDecimal("1.0e500"), "1.0e500Bd"); - } - - @Test public void testBigDecimal_2() throws Exception { - assertEvaluatesTo(new BigDecimal("123456789012345678901234567890.123456789012345678901234567890"), - "1234567890_1234567890_1234567890.1234567890_1234567890_1234567890bD"); - } - - @Test public void testBigDecimal_3() throws Exception { - assertEvaluatesTo(new BigDecimal("1e500"), "1e500BD"); - } - - @Test public void testBug372408() throws Exception { - assertEvaluatesTo(new BigInteger("0"), "0BI"); - assertEvaluatesTo(0l, "0l"); - } - - @Test public void testImplicitOneArgClosure() throws Exception { - assertEvaluatesTo("foo","[it].apply('foo')"); - } - - @Ignore("To be implemented later") - @Test public void testImplicitOneArgClosure_01() throws Exception { - assertEvaluatesTo(3,"[length].apply('foo')"); - } - - @Test public void testImplicitOneArgClosure_02() throws Exception { - assertEvaluatesTo(newArrayList("a","bb","ccc"), "newArrayList('bb','a','ccc').sortBy([length])"); - } - - @Test public void testBug362725() throws Exception { - assertEvaluatesTo(Boolean.TRUE, "{ val =>int closure = null closure == null }"); - } - - @Test public void testBuilderSyntax_01() throws Exception { - assertEvaluatesTo(newArrayList("a","bb","ccc"), "newArrayList('a','bb','ccc').sortBy [length]"); - } - - @Test public void testBuilderSyntax_02() throws Exception { - assertEvaluatesTo(newArrayList("a","bb","ccc"), "newArrayList('a','bb','ccc').sortBy [it.length]"); - } - - @Test public void testBuilderSyntax_03() throws Exception { - assertEvaluatesTo(newArrayList("a","bb","ccc"), "newArrayList('a','bb','ccc').sortBy [x | x.length]"); - } - - @Test public void testBuilderSyntax_04() throws Exception { - assertEvaluatesTo(newArrayList(), "newArrayList.sortBy [length]"); - } - - @Test public void testNestedClosures_01() throws Exception { - String expr = - "{ " + - " val x = 'foo' " + - " [String s | x + [ String s1 | s1 + s + x].apply(s) ].apply(x)" + - "}"; - assertEvaluatesTo("foofoofoofoo", expr); - } - - @Test public void testNestedClosures_02() throws Exception { - String expr = - "{ " + - " val x = 'foo' " + - " [ s | x + [ s1 | s1 + s + x].apply(s) ].apply(x)" + - "}"; - assertEvaluatesTo("foofoofoofoo", expr); - } - - @Test public void testEscapeCharacter() throws Exception { - String expr = "'foo'.^class"; - assertEvaluatesTo(String.class, expr); - } - - @Test public void testShortCircuitBooleanExpression_00() throws Exception { - String expr = "true || {if (true) throw new NullPointerException() else false}"; - assertEvaluatesTo(true, expr); - } - - @Test public void testShortCircuitBooleanExpression_01() throws Exception { - String expr = "false && {if (true) throw new NullPointerException() else false}"; - assertEvaluatesTo(false, expr); - } - - @Test public void testShortCircuitBooleanExpression_02() throws Exception { - String expr = "true || {if (true) throw new NullPointerException else false}"; - assertEvaluatesTo(true, expr); - } - - @Test public void testShortCircuitBooleanExpression_03() throws Exception { - String expr = - "{ val i = newArrayList(false,true).iterator" + - " if (i.next && i.next)" + - " throw new NullPointerException()" + - " else" + - " i.next" + - "}"; - assertEvaluatesTo(true, expr); - } - - @Test public void testShortCircuitBooleanExpression_04() throws Exception { - String expr = - "{ val i = newArrayList(true,false).iterator" + - " if (i.next || i.next)" + - " i.next" + - "}"; - assertEvaluatesTo(false, expr); - } - - @Test public void testShortCircuitBooleanExpression_05() throws Exception { - String expr = - "{ " + - " val i = newArrayList(true, true, true).iterator" + - " if (i.next && i.next && i.next)" + - " i.hasNext" + - "}"; - assertEvaluatesTo(false, expr); - } - - @Test public void testShortCircuitBooleanExpression_06() throws Exception { - String expr = - "{ " + - " val i = newArrayList(false, true).iterator" + - " if (i.next && i.next || i.next)" + - " i.hasNext" + - "}"; - assertEvaluatesTo(false, expr); - } - - @Test public void testReferenceInnerClasses_01() throws Exception { - assertEvaluatesTo(OuterClass.InnerClass.SINGLETON, "testdata::OuterClass$InnerClass::SINGLETON"); - } - - @Test public void testReferenceInnerClasses_02() throws Exception { - assertEvaluatesTo("FOO", "[testdata.OuterClass$InnerClass param| param.toUpperCase('foo')].apply(new testdata.OuterClass$InnerClass())"); - } - - @Test public void testReferenceInnerClasses_03() throws Exception { - assertEvaluatesTo(null, "{for (x : newArrayList(new testdata.OuterClass$InnerClass())) { x.toString } null}"); - } - - @Test public void testReferenceInnerClasses_04() throws Exception { - assertEvaluatesTo("FOO", "[testdata.OuterClass$InnerClass param| param.toUpperCase('foo')].apply(new testdata.OuterClass$InnerClass)"); - } - - @Test public void testReferenceInnerClasses_05() throws Exception { - assertEvaluatesTo(OuterClass.InnerClass.SINGLETON, "testdata::OuterClass::InnerClass::SINGLETON"); - } - - @Test public void testReferenceInnerClasses_06() throws Exception { - assertEvaluatesTo("FOO", "[testdata.OuterClass.InnerClass param| param.toUpperCase('foo')].apply(new testdata.OuterClass.InnerClass())"); - } - - @Test public void testReferenceInnerClasses_07() throws Exception { - assertEvaluatesTo(null, "{for (x : newArrayList(new testdata.OuterClass.InnerClass())) { x.toString } null}"); - } - - @Test public void testReferenceInnerClasses_08() throws Exception { - assertEvaluatesTo("FOO", "[testdata.OuterClass.InnerClass param| param.toUpperCase('foo')].apply(new testdata.OuterClass.InnerClass)"); - } - - @Test public void testReferenceInnerClasses_09() throws Exception { - assertEvaluatesTo(OuterClass.InnerClass.SINGLETON, "testdata.OuterClass$InnerClass::SINGLETON"); - } - - @Test public void testReferenceInnerClasses_10() throws Exception { - assertEvaluatesTo(OuterClass.InnerClass.SINGLETON, "testdata.OuterClass.InnerClass::SINGLETON"); - } - - /* - * see https://bugs.eclipse.org/bugs/show_bug.cgi?id=341642 - */ - @Test public void testBug341642() throws Exception { - assertEvaluatesTo("a", "newArrayList('a', 'b', 'c').filter(a|a == 'a' || a == 'b').iterator.next"); - } - - @Test public void testBug341775() throws Exception { - assertEvaluatesTo(Boolean.FALSE, "'a'.charAt(0) == 'a'"); - assertEvaluatesTo(Boolean.TRUE, "'a'.charAt(0) == 'a'.charAt(0)"); - assertEvaluatesTo(Boolean.TRUE, "'a' == 'a'"); - } - - @Test public void testCurrying_01() throws Exception { - assertEvaluatesTo("123456", "[String p1, String p2, String p3, String p4, String p5, String p6| p1+p2+p3+p4+p5+p6].curry('1').curry('2').curry('3').curry('4').curry('5').curry('6').apply()"); - } - - @Test public void testCurrying_02() throws Exception { - assertEvaluatesTo("1", "[String p1| p1].curry('1').apply()"); - } - - @Test public void testCurrying_03() throws Exception { - assertEvaluatesTo("12", "[String p1, String p2| p1 + p2].curry('1').curry('2').apply()"); - } - - @Test public void testCurrying_04() throws Exception { - assertEvaluatesTo(newArrayList("1","2","3","4","5","6"), - "{\n" + - " val result = newArrayList\n" + - " var (String,String,String,String,String,String)=>void proc = [ p1, p2, p3, p4, p5, p6 |\n" + - " result.add(p1)\n" + - " result.add(p2)\n" + - " result.add(p3)\n" + - " result.add(p4)\n" + - " result.add(p5)\n" + - " result.add(p6)\n" + - " ]" + - " proc.curry('1').curry('2').curry('3').curry('4').curry('5').curry('6').apply()\n" + - " result\n" + - "}"); - } - - @Test public void testCurrying_05() throws Exception { - assertEvaluatesTo(newArrayList("1","2"), - "{\n" + - " val result = newArrayList\n" + - " var (String,String)=>void proc = [ p1, p2 |\n" + - " result.add(p1)\n" + - " result.add(p2)\n" + - " ]" + - " proc.curry('1').curry('2').apply()\n" + - " result\n" + - "}"); - } - - @Test public void testCurrying_06() throws Exception { - assertEvaluatesTo(newArrayList("1","2","3","4","5","6"), - "{\n" + - " val result = newArrayList\n" + - " val (String,String,String,String,String,String)=>void proc6 = [ p1, p2, p3, p4, p5, p6 |\n" + - " result.add(p1)\n" + - " result.add(p2)\n" + - " result.add(p3)\n" + - " result.add(p4)\n" + - " result.add(p5)\n" + - " result.add(p6)\n" + - " ]\n" + - " val (String,String,String,String,String)=>void proc5 = proc6.curry('1')\n" + - " val (String,String,String,String)=>void proc4 = proc5.curry('2')\n" + - " val (String,String,String)=>void proc3 = proc4.curry('3')\n" + - " val (String,String)=>void proc2 = proc3.curry('4')\n" + - " val (String)=>void proc1 = proc2.curry('5')\n" + - " val =>void proc0 = proc1.curry('6')\n" + - " proc0.apply()\n" + - " result\n" + - "}"); - } - - /* - * https://bugs.eclipse.org/bugs/show_bug.cgi?id=341550 - */ - @Test public void testBug341550() throws Exception { - assertEvaluatesTo(emptyList(),"switch emptyList() { case emptyList() : emptyList() }"); - } - - @Test public void testGenerics_00() throws Exception { - assertEvaluatesTo("", "try {typeof(String).newInstance} catch(Exception e) {}"); - } - - @Test public void testGenerics_00_b() throws Exception { - assertEvaluatesTo("", "try {String.newInstance} catch(Exception e) {}"); - } - - @Test public void testGenerics_01() throws Exception { - assertEvaluatesTo("y", - "{" + - " val x = newArrayList('y',23,true)" + - " return x.head" + - "}"); - } - - @Test public void testGenerics_02() throws Exception { - assertEvaluatesTo(Boolean.TRUE, - "new java.util.ArrayList().addAll(typeof(String).declaredFields)"); - } - - @Test public void testGenerics_02_b() throws Exception { - assertEvaluatesTo(Boolean.TRUE, - "new java.util.ArrayList().addAll(String.declaredFields)"); - } - - @Test public void testGenerics_03() throws Exception { - assertEvaluatesTo("y", - "{" + - " val x = newArrayList('y',23,true)" + - " return x.head" + - "}"); - } - - @Test public void testGenerics_04() throws Exception { - assertEvaluatesTo(Boolean.TRUE, - "new java.util.ArrayList.addAll(typeof(String).declaredFields)"); - } - - @Test public void testGenerics_04_b() throws Exception { - assertEvaluatesTo(Boolean.TRUE, - "new java.util.ArrayList.addAll(String.declaredFields)"); - } - - @Test public void testGenerics_05() throws Exception { - assertEvaluatesTo("y", - "{" + - " val x = newArrayList('y',23,true)" + - " x.head" + - "}"); - } - - @Test public void testGenerics_06() throws Exception { - assertEvaluatesTo("y", - "{" + - " val x = newArrayList('y',23,true)" + - " x.head" + - "}"); - } - - @Test public void testGenerics_07() throws Exception { - assertEvaluatesTo(Integer.valueOf(23), - "{" + - " val x = newArrayList(23, 23d)" + - " x.head" + - "}"); - } - - /** - * see https://bugs.eclipse.org/bugs/show_bug.cgi?id=341246 - */ - @Test public void testUnreferencedConstructorInBlock_01() throws Exception { - assertEvaluatesTo(false, "{ new String() false}"); - } - - @Test public void testUnreferencedConstructorInBlock_02() throws Exception { - assertEvaluatesTo(false, "{ new String false}"); - } - - @Test public void testStaticFeatureCall_01() throws Exception { - assertEvaluatesTo("false", "String::valueOf(false)"); - } - - @Test public void testStaticFeatureCall_02() throws Exception { - assertEvaluatesTo(Boolean.FALSE, "Boolean::FALSE"); - } - - @Test public void testStaticFeatureCall_03() throws Exception { - assertEvaluatesTo("false", "String.valueOf(false)"); - } - - @Test public void testStaticFeatureCall_04() throws Exception { - assertEvaluatesTo(Boolean.FALSE, "Boolean.FALSE"); - } - - @Test public void testStaticFeatureCall_05() throws Exception { - assertEvaluatesTo("false", "java.lang.String.valueOf(false)"); - } - - @Test public void testPrimitiveConversion_01() throws Exception { - assertEvaluatesTo("2","'ab'.length.toString"); - } - - @Test public void testPrimitiveConversion_02() throws Exception { - assertEvaluatesTo("123","123.toString"); - } - - @Test public void testPrimitiveConversion_03() throws Exception { - assertEvaluatesTo("123","return 123.toString"); - } - - @Test public void testPrimitiveConversion_04() throws Exception { - assertEvaluatesTo("123","123L.intValue.toString"); - } - - @Test public void testReturnExpression_01() throws Exception { - assertEvaluatesTo(Boolean.TRUE, "return true"); - } - - @Test public void testReturnExpression_02() throws Exception { - assertEvaluatesTo("xx", "return if ('x'=='x') 'xx'"); - } - - @Test public void testReturnExpression_03() throws Exception { - assertEvaluatesTo(null, "return if ('x'!='x') 'xx'"); - } - - @Test public void testReturnExpression_04() throws Exception { - assertEvaluatesTo(null, "return null"); - } - - @Test public void testReturnExpression_05() throws Exception { - assertEvaluatesTo("yy", "if ('x'!='x') return 'xx' else return 'yy'"); - assertEvaluatesTo("xx", "if ('x'=='x') return 'xx' else return 'yy'"); - } - - @Test public void testReturnExpression_06() throws Exception { - assertEvaluatesTo(null, - "{" + - " val closure = [Integer i| return i]" + - " for (x : 1..100) " + - " closure.apply(x)" + - " return null" + - "}"); - } - - @Ignore("Wrong type") - @Test public void testReturnExpression_07() throws Exception { - assertEvaluatesTo(null, "return if (true) while(false) ('foo'+'bar').length else null"); - assertEvaluatesTo(null, "return if (false) while(false) ('foo'+'bar').length else null"); - } - - @Ignore("Wrong type") - @Test public void testReturnExpression_08() throws Exception { - assertEvaluatesTo(null, "return if (true) while(false) ('foo'+'bar').length else 'zonk'"); - assertEvaluatesTo("zonk", "return if (false) while(false) ('foo'+'bar').length else 'zonk'"); - } - - @Test public void testReturnExpression_09() throws Exception { - assertEvaluatesTo(null, "{ return null }"); - } - - @Test public void testReturnExpression_10() throws Exception { - assertEvaluatesTo(null, "{ { println }; null }"); - } - - @Test public void testUnaryOperator_00() throws Exception { - assertEvaluatesTo(Integer.valueOf(-19),"-19"); - } - - @Test public void testUnaryOperator_01() throws Exception { - assertEvaluatesTo(false,"!true"); - } - - @Test public void testUnaryOperator_02() throws Exception { - assertEvaluatesTo("-1","(-1).toString()"); - } - - @Test public void testUnaryOperator_03() throws Exception { - assertEvaluatesTo(1,"- -1"); - } - - @Test public void testUnaryOperator_04() throws Exception { - assertEvaluatesTo(true,"!!true"); - } - - @Test public void testUpToOperator() throws Exception { - assertEvaluatesTo(Integer.valueOf(9),"(9..13).iterator().next()"); - } - - @Test public void testExclusiveRangeOperator_0() throws Exception { - assertEvaluatesTo("0,1,2,3", "(0..<4).join(',')"); - } - - @Test public void testExclusiveRangeOperator_1() throws Exception { - assertEvaluatesTo("3,2,1,0", "(4>..0).join(',')"); - } - - @Test public void testExclusiveRangeOperator_2() throws Exception { - assertEvaluatesTo("", "(0..<0).join(',')"); - } - - @Test public void testExclusiveRangeOperator_3() throws Exception { - assertEvaluatesTo("", "(0>..0).join(',')"); - } - - @Test public void testExclusiveRangeOperator_4() throws Exception { - assertEvaluatesTo("", "(0..<-1).join(',')"); - } - - @Test public void testExclusiveRangeOperator_5() throws Exception { - assertEvaluatesTo("", "(-1>..0).join(',')"); - } - - @Test public void testElvisOperator() throws Exception { - assertEvaluatesTo("foo","null as String?:'foo'"); - } - - @Test public void testElvisOperator_01() throws Exception { - assertEvaluatesTo("bar","'bar' ?: 'foo'"); - } - - @Test public void testElvisOperator_02() throws Exception { - assertEvaluatesTo(null,"null ?: null"); - } - - @Test public void testElvisOperator_03() throws Exception { - assertEvaluatesTo(null,"null as String ?: null as String"); - } - - @Test public void testElvisOperator_04() throws Exception { - assertEvaluatesTo("foo","{var foo='foo' val x=foo?:{foo='bar' foo} foo}"); - } - - @Test public void testElvisOperator_05() throws Exception { - assertEvaluatesTo("bar","{var String foo=null val x=foo?:{foo='bar' foo} foo}"); - } - - @Test public void testStringConcatenation_00() throws Exception { - assertEvaluatesTo("foobar", "'foo'+ ('bar' as Object)"); - } - @Test public void testStringConcatenation_01() throws Exception { - assertEvaluatesTo("foo3", "'foo'+3"); - } - @Test public void testStringConcatenation_2() throws Exception { - assertEvaluatesTo("footrue", "'foo'+true"); - } - - @Test public void testStringConcatenation_3() throws Exception { - assertEvaluatesTo("42footrue", "42 +'foo'+true"); - } - - @Test public void testStringConcatenation_4() throws Exception { - assertEvaluatesTo("truefootrue", "true + 'foo'+true"); - } - - @Test public void testAddOnIntegers() throws Exception { - assertEvaluatesTo(Integer.valueOf(3), "1+2"); - } - - @Test public void testSubtractionOnIntegers() throws Exception { - assertEvaluatesTo(Integer.valueOf(1), "2-1"); - } - - @Test public void testMultiplicationOnIntegers() throws Exception { - assertEvaluatesTo(Integer.valueOf(42), "6*7"); - } - - @Test public void testDivisionOnIntegers_01() throws Exception { - assertEvaluatesTo(Integer.valueOf(2), "6/3"); - } - - @Test public void testDivisionOnIntegers_02() throws Exception { - assertEvaluatesTo(Integer.valueOf(2), "7/3"); - } - - @Test public void testModuloOnIntegers() throws Exception { - assertEvaluatesTo(Integer.valueOf(1), "7%3"); - } - - @Test public void testPowerOnIntegers() throws Exception { - assertEvaluatesTo(Double.valueOf(8), "2**3"); - } - - @Test public void testLessThanOnIntegers_01() throws Exception { - assertEvaluatesTo(Boolean.TRUE, "3<4"); - } - - @Test public void testLessThanOnIntegers_02() throws Exception { - assertEvaluatesTo(Boolean.FALSE, "4<3"); - } - - @Test public void testGreaterThanOnIntegers_01() throws Exception { - assertEvaluatesTo(Boolean.TRUE, "4>3"); - } - - @Test public void testGreaterThanOnIntegers_02() throws Exception { - assertEvaluatesTo(Boolean.FALSE, "3>4"); - } - - @Test public void testLessEqualsThanOnIntegers_01() throws Exception { - assertEvaluatesTo(Boolean.TRUE, "3<=3"); - } - - @Test public void testLessEqualsThanOnIntegers_02() throws Exception { - assertEvaluatesTo(Boolean.TRUE, "3<=4"); - } - - @Test public void testLessEqualsThanOnIntegers_03() throws Exception { - assertEvaluatesTo(Boolean.FALSE, "4<=3"); - } - - @Test public void testGreaterEqualsThanOnIntegers_01() throws Exception { - assertEvaluatesTo(Boolean.TRUE, "3>=3"); - } - - @Test public void testGreaterEqualsThanOnIntegers_02() throws Exception { - assertEvaluatesTo(Boolean.TRUE, "4>=3"); - } - - @Test public void testGreaterEqualsThanOnIntegers_03() throws Exception { - assertEvaluatesTo(Boolean.FALSE, "3>=4"); - } - - @Test public void testOrOnBooleans_01() throws Exception { - assertEvaluatesTo(Boolean.TRUE, "true||false"); - } - - @Test public void testOrOnBooleans_02() throws Exception { - assertEvaluatesTo(Boolean.TRUE, "false||true"); - } - - @Test public void testOrOnBooleans_03() throws Exception { - assertEvaluatesTo(Boolean.TRUE, "true||true"); - } - - @Test public void testOrOnBooleans_04() throws Exception { - assertEvaluatesTo(Boolean.FALSE, "false||false"); - } - - @Test public void testAndOnBooleans_01() throws Exception { - assertEvaluatesTo(Boolean.TRUE, "true&&true"); - } - - @Test public void testAndOnBooleans_02() throws Exception { - assertEvaluatesTo(Boolean.FALSE, "false&&true"); - } - - @Test public void testAndOnBooleans_03() throws Exception { - assertEvaluatesTo(Boolean.FALSE, "true&&false"); - } - - @Test public void testAndOnBooleans_04() throws Exception { - assertEvaluatesTo(Boolean.FALSE, "false&&false"); - } - - @Test public void testNull() throws Exception { - assertEvaluatesTo(null, "null"); - } - - @Test public void testNullBlockResult_01() throws Exception { - assertEvaluatesTo(null, "{ null; }"); - } - - @Test public void testNullBlockResult_02() throws Exception { - assertEvaluatesTo(null, "{ 'literal'.length; null; }"); - } - - @Test public void testBlock_01() throws Exception { - assertEvaluatesTo(Boolean.TRUE, - "{\n" + - " val (Integer, Double, Boolean) => void fun1 = null\n" + - " val (byte[], Object) => double[] fun2 = null\n" + - " val test = newArrayList.map[1 -> org::eclipse::xtext::xbase::lib::Pair::of(fun1, fun2)]\n" + - " val test2 = newArrayList.map[2 -> org::eclipse::xtext::xbase::lib::Pair::of(fun1, fun2)]\n" + - " val test3 = com::google::common::collect::Iterables::concat(test, test2).toMap[key].entrySet.map[value].toList\n" + - " test3 != null" + - "}"); - } - - @Test public void testBlock_02() throws Exception { - assertEvaluatesTo("Length: 3", - "{\n" + - " val map = newHashMap\n" + - " map.put(1, 'abc')\n" + - " val x = map.get(1)\n" + - " 'Length: ' + x.length" + - "}"); - } - - @Test public void testSynchronizedBlock_01() throws Exception { - assertEvaluatesTo(Boolean.TRUE, - "synchronized(new Object) {\n" + - " val (Integer, Double, Boolean) => void fun1 = null\n" + - " val (byte[], Object) => double[] fun2 = null\n" + - " val test = newArrayList.map[1 -> org::eclipse::xtext::xbase::lib::Pair::of(fun1, fun2)]\n" + - " val test2 = newArrayList.map[2 -> org::eclipse::xtext::xbase::lib::Pair::of(fun1, fun2)]\n" + - " val test3 = com::google::common::collect::Iterables::concat(test, test2).toMap[key].entrySet.map[value].toList\n" + - " test3 != null" + - "}"); - } - - @Test public void testSynchronizedBlock_02() throws Exception { - assertEvaluatesTo("Length: 3", - "synchronized(new Object) {\n" + - " val map = newHashMap\n" + - " map.put(1, 'abc')\n" + - " val x = map.get(1)\n" + - " 'Length: ' + x.length" + - "}"); - } - - @Test public void testSynchronizedBlock_03() throws Exception { - assertEvaluatesTo("foo", - "{\n" + - " val list = newArrayList\n" + - " val ()=>int x = [|{ list += 'foo'; 1 }]\n" + - " synchronized(x.apply) {\n" + - " list.head\n" + - " }\n" + - "}\n"); - } - - @Test public void testStringLiteral_01() throws Exception { - assertEvaluatesTo("", "''"); - } - - @Test public void testStringLiteral_02() throws Exception { - assertEvaluatesTo("literal", "'literal'"); - } - - @Test public void testStringLiteral_03() throws Exception { - assertEvaluatesTo("lite\nr\\al", "'lite\r\nr\\\\al'"); - } - - @Test public void testStringLiteral_03_Issue_2293_01() throws Exception { - assertEvaluatesTo("lite\nr\\al", "'lite\\nr\\\\al'"); - } - - @Test public void testStringLiteral_03_Issue_2293_02() throws Exception { - assertEvaluatesTo("lite\r\nr\\al", "'lite\\r\\nr\\\\al'"); - } - - @Test public void testStringLiteral_04() throws Exception { - assertEvaluatesTo('\n', "{ val char x = '\n' x}"); - } - @Test public void testStringLiteral_05() throws Exception { - assertEvaluatesTo(' ', "{ val char x = ' ' x}"); - } - @Test public void testStringLiteral_06() throws Exception { - assertEvaluatesTo('«', "{ val char x = '«' x}"); - } - - @Test public void testStringLiteral_07() throws Exception { - assertEvaluatesTo('«', "{ val Character x = '«' x}"); - } - - @Test public void testBooleanLiteral_01() throws Exception { - assertEvaluatesTo(Boolean.TRUE, "true"); - } - - @Test public void testBooleanLiteral_02() throws Exception { - assertEvaluatesTo(Boolean.FALSE, "false"); - } - - @Test public void testIntLiteral_01() throws Exception { - assertEvaluatesTo(53, "53"); - } - - @Test public void testIntLiteral_02() throws Exception { - assertEvaluatesTo(0, "0"); - } - - @Test public void testTypeLiteral_01() throws Exception { - assertEvaluatesTo(Void.class, "typeof(Void)"); - } - - @Test public void testTypeLiteral_02() throws Exception { - assertEvaluatesTo(void.class, "typeof(void)"); - } - - @Test public void testTypeLiteral_03() throws Exception { - assertEvaluatesTo(String[].class, "typeof(String[])"); - } - - @Test public void testTypeLiteral_04() throws Exception { - assertEvaluatesTo(int[][].class, "typeof(int[][])"); - } - - @Test public void testTypeLiteral_05() throws Exception { - assertEvaluatesTo(Void.class, "Void"); - } - - @Test public void testTypeLiteral_06() throws Exception { - assertEvaluatesTo(void.class, "void"); - } - - @Test public void testTypeLiteral_07() throws Exception { - assertEvaluatesTo(void.class, "void"); - } - - @Test public void testTypeLiteral_08() throws Exception { - assertEvaluatesTo(Map.Entry.class, "typeof(java.util.Map$Entry)"); - } - - @Test public void testTypeLiteral_09() throws Exception { - assertEvaluatesTo(Map.Entry.class, "typeof(java.util.Map.Entry)"); - } - - @Test public void testTypeLiteral_10() throws Exception { - assertEvaluatesTo(Map.Entry.class, "java.util.Map$Entry"); - } - - @Test public void testTypeLiteral_11() throws Exception { - assertEvaluatesTo(Map.Entry.class, "java.util.Map.Entry"); - } - - - @Test public void testIdentityEquals_0() throws Exception { - assertEvaluatesTo(true, "1===1"); - } - - @Test public void testIdentityEquals_1() throws Exception { - assertEvaluatesTo(false, "new Object===new Object"); - } - - @Test public void testIdentityEquals_2() throws Exception { - assertEvaluatesTo(true, "130L===130L"); - } - - @Test public void testIdentityNotEquals_0() throws Exception { - assertEvaluatesTo(false, "130L!==130L"); - } - - @Test public void testSpaceship_0() throws Exception { - assertEvaluatesTo(1, "2<=>1"); - } - - @Test public void testSpaceship_1() throws Exception { - assertEvaluatesTo(-1, "1<=>2"); - } - - @Test public void testSpaceship_2() throws Exception { - assertEvaluatesTo(0, "'bar'<=>'bar'"); - } - - @Test public void testIfExpression_00() throws Exception { - assertEvaluatesTo(null, "if (0==1) 'literal'"); - } - - @Test public void testIfExpression_01() throws Exception { - assertEvaluatesTo(null, "if (false) 'literal'"); - } - - @Test public void testIfExpression_02() throws Exception { - assertEvaluatesTo("literal", "if (true) 'literal'"); - } - - @Test public void testIfExpression_03() throws Exception { - assertEvaluatesTo("then", "if (true) 'then' else 'else'"); - } - - @Test public void testIfExpression_04() throws Exception { - assertEvaluatesTo("else", "if (false) 'then' else 'else'"); - } - - @Test public void testIfExpression_05() throws Exception { - assertEvaluatesTo(null, "if (false) return 'fail'"); - } - - /** - * @since 2.5 - */ - @Test public void testIfExpression_06() throws Exception { - // this is compiled without expectation thus nothing is inserted during type compilation - // e.g. the if expression has type 'void' but the compiler / interpreter returns 'void' since - // the evaluation expects a hardcoded 'Object' - assertEvaluatesTo(null, - "if (false) return 1"); - } - - /** - * @since 2.5 - */ - @Test public void testIfExpression_07() throws Exception { - assertEvaluatesTo(null, - "if (false) return 1L"); - } - - /** - * @since 2.5 - */ - @Test public void testIfExpression_08() throws Exception { - assertEvaluatesTo(Integer.valueOf(0), - "if (false) 1"); - } - - /** - * @since 2.5 - */ - @Test public void testIfExpression_09() throws Exception { - assertEvaluatesTo(Long.valueOf(0), - "if (false) 1L"); - } - - @Test public void testBug342021_01() throws Exception { - assertEvaluatesTo(Boolean.FALSE, - "{\n" + - " val Iterable branch = \n" + - " if (true) \n" + - " [|newArrayList().iterator]\n" + - " else\n" + - " newArrayList('a').toArray\n" + - " branch.iterator.hasNext\n" + - "}"); - } - - @Test public void testBug342021_02() throws Exception { - assertEvaluatesTo(Boolean.FALSE, - "{\n" + - " val Iterable branch = \n" + - " if (true) \n" + - " { [|newArrayList().iterator] }\n" + - " else\n" + - " { ''.toString { newArrayList('a').toArray } }\n" + - " branch.iterator.hasNext\n" + - "}"); - } - - @Test public void testBug342021_03() throws Exception { - assertEvaluatesTo(Boolean.TRUE, - "{\n" + - " val Iterable branch = \n" + - " switch '' as Object {\n" + - " Boolean: [|newArrayList().iterator]\n" + - " String: newArrayList('a').toArray\n" + - " }\n" + - " branch.iterator.hasNext\n" + - "}"); - } - - @Test public void testIfExpression_withThrowExpression_00() throws Exception { - assertEvaluatesWithException(NullPointerException.class, "if (false) throw new NullPointerException() else throw new NullPointerException()"); - } - - @Test public void testIfExpression_withThrowExpression_01() throws Exception { - assertEvaluatesWithException(NullPointerException.class, "if (false) 'then' else throw new NullPointerException()"); - } - - @Test public void testIfExpression_withThrowExpression_02() throws Exception { - assertEvaluatesTo("then", "if (true) 'then' else throw new NullPointerException()"); - } - - @Test public void testIfExpression_withThrowExpression_03() throws Exception { - assertEvaluatesWithException(NullPointerException.class, "if (false) 'then' else throw new NullPointerException"); - } - - @Test public void testVariableDeclaration_01() throws Exception { - assertEvaluatesTo("literal", "{var x = 'literal' x = x}"); - } - - @Test public void testVariableDeclaration_03() throws Exception { - assertEvaluatesTo("literal", "{var String x x = 'literal' x}"); - } - - @Test public void testVariableDeclaration_04() throws Exception { - assertEvaluatesTo("literal", "{var String x; x = 'literal'}"); - } - - @Test public void testVariableDeclaration_06() throws Exception { - assertEvaluatesTo(Short.valueOf((short)0), "{var short s s}"); - } - - @Test public void testVariableDeclaration_07() throws Exception { - assertEvaluatesTo(Character.valueOf((char)0), "{var char c c}"); - } - - @Test public void testVariableDeclaration_08() throws Exception { - assertEvaluatesTo(Integer.valueOf(42), "{var int i i = 42 i}"); - } - - @Test public void testVariableDeclaration_09() throws Exception { - assertEvaluatesTo(Boolean.FALSE, "{var boolean b b}"); - } - - @Test public void testVariableDeclaration_10() throws Exception { - assertEvaluatesTo(Boolean.TRUE, "{var boolean b b = true b}"); - } - - @Test public void testVariableDeclaration_11() throws Exception { - assertEvaluatesTo("FOO", "{var b = 'foo'.toUpperCase b}"); - } - - @Test public void testFeatureCall_01() throws Exception { - assertEvaluatesTo("literal", "{var x = 'literal' x}"); - } - - @Test public void testFeatureCall_02() throws Exception { - assertEvaluatesTo(Character.valueOf('a'), "'a'.toCharArray.iterator.next"); - } - - @Test public void testFeatureCall_03() throws Exception { - assertEvaluatesTo(newArrayList( - Character.valueOf('a'), - Character.valueOf('b'), - Character.valueOf('c')), "{ var java.util.List x = ('abc'.toCharArray as Iterable).toList() x }"); - } - - @Test public void testFeatureCall_03_2() throws Exception { - assertEvaluatesTo(newArrayList( - Character.valueOf('a'), - Character.valueOf('b'), - Character.valueOf('c')), "{ var java.util.List x = 'abc'.toCharArray x }"); - } - - @Test public void testFeatureCall_04() throws Exception { - assertEvaluatesTo(Integer.valueOf("literal".length()), "{ var x = 'literal' x.length }"); - } - - @Test public void testConstructorCall_00() throws Exception { - assertEvaluatesTo("", "new String()"); - } - - @Test public void testConstructorCall_01() throws Exception { - assertEvaluatesTo("", "new String"); - } - - @Test public void testConstructorCall_02() throws Exception { - assertEvaluatesTo("foobar", "new String('foobar')"); - } - - @Test public void testConstructorCall_04() throws Exception { - assertEvaluatesTo("", "new java.lang.String"); - } - - @Test public void testConstructorCall_05() throws Exception { - assertEvaluatesTo("twoArgs:12", - "new testdata.ClosureClient2(|'1') [|'2'].value"); - } - - @Test public void testConstructorCall_06() throws Exception { - assertEvaluatesTo("varArgs:1", - "new testdata.ClosureClient2(|'1').value"); - } - - @Test public void testConstructorCall_07() throws Exception { - assertEvaluatesTo("varArgs:1", - "new testdata.ClosureClient2 [|'1'].value"); - } - - @Test public void testConstructorCall_08() throws Exception { - assertEvaluatesTo("varArgs:", - "(new testdata.ClosureClient2).value"); - } - - @Test public void testConstructorCall_09() throws Exception { - assertEvaluatesTo("varArgs:", - "{new testdata.ClosureClient2}.value"); - } - - @Test public void testConstructorCall_10() throws Exception { - assertEvaluatesTo("varArgs:123", - "new testdata.ClosureClient2([|'1'],[|'2']) [|'3'].value"); - } - - @Test public void testConstructorCall_11() throws Exception { - assertEvaluatesTo("varArgs:", - "(((((new testdata.ClosureClient2))).value))"); - } - - @Test public void testConstructorCall_12() throws Exception { - assertEvaluatesTo(Boolean.TRUE, - "{ new testdata.a.SameSimpleName new testdata.b.SameSimpleName } instanceof testdata.b.SameSimpleName"); - } - - @Test public void testConstructorCall_13() throws Exception { - assertEvaluatesTo(Boolean.TRUE, - "{ var res = new testdata.a.SameSimpleName new testdata.b.SameSimpleName res } instanceof testdata.a.SameSimpleName"); - } - - @Test public void testAssignment_01() throws Exception { - assertEvaluatesTo("newValue", "{var x = 'literal' x = 'newValue'}"); - } - - @Test public void testAssignment_02() throws Exception { - assertEvaluatesTo("literal", - "{" + - " var x = new testdata.Properties1()" + - " x.prop1 = 'literal'" + - " x.prop1" + - "}"); - } - - @Test public void testAssignment_03() throws Exception { - assertEvaluatesTo("literal", - "{" + - " var x = new testdata.Properties1()" + - " x.prop2 = 'literal'" + - " x.prop2" + - "}"); - } - - @Test public void testAssignment_04() throws Exception { - assertEvaluatesTo("Integer: 1", - "{" + - " var x = new testdata.Properties1()" + - " x.prop2 = 1" + - " x.prop2" + - "}"); - } - - @Test public void testAssignment_05() throws Exception { - assertEvaluatesTo("literal", - "{" + - " var x = new testdata.Properties1()" + - " x.prop2 = 'literal'" + - " x.prop2" + - "}"); - } - - @Test public void testAssignment_06() throws Exception { - assertEvaluatesTo("Integer: 1", - "{" + - " var x = new testdata.Properties1()" + - " x.prop2 = 1" + - " x.prop2" + - "}"); - } - - @Test public void testAssignment_07() throws Exception { - assertEvaluatesTo(null, - "{" + - " var x = new testdata.Properties1()" + - " x.prop2 = 'literal'" + - " null" + - "}"); - } - - @Test public void testAssignment_08() throws Exception { - assertEvaluatesTo(null, - "{" + - " var x = new testdata.Properties1()" + - " x.prop2 = 1" + - " null" + - "}"); - } - - @Test public void testAssignment_09() throws Exception { - assertEvaluatesTo("Integer: 1", - "{" + - " var x = new testdata.Properties1()" + - " x.prop3 = 1" + - "}"); - } - - @Test public void testAssignment_10() throws Exception { - assertEvaluatesTo("literal", - "{" + - " var x = new testdata.Properties1()" + - " x.prop1 = 'literal'" + - "}"); - } - - @Test public void testAssignment_11() throws Exception { - assertEvaluatesTo("literal", - "{" + - " var list = new testdata.GenericType1()" + - " list += 'literal'" + - " list.get()" + - "}"); - } - - @Test public void testAssignment_12() throws Exception { - assertEvaluatesTo(Boolean.TRUE, - "{" + - " var list = new testdata.GenericType1()" + - " list += 'literal'" + - "}"); - } - - @Test public void testAssignment_13() throws Exception { - assertEvaluatesTo("literal", - "{" + - " var x = new testdata.Properties2()" + - " x.prop2 = 'literal'" + - " x.prop2" + - "}"); - } - - @Test public void testAssignment_14() throws Exception { - assertEvaluatesTo("literal", - "{" + - " var x = new testdata.Properties1" + - " x.prop1 = 'literal'" + - " x.prop1" + - "}"); - } - - @Test public void testAssignment_15() throws Exception { - assertEvaluatesTo("literal", - "{" + - " var list = new testdata.GenericType1" + - " list += 'literal'" + - " list.get()" + - "}"); - } - - @Test public void testAssignment_16() throws Exception { - assertEvaluatesTo("literal", - "{" + - " var it = new testdata.Properties1()" + - " prop1 = 'literal'" + - " prop1" + - "}"); - } - - @Test public void testAssignment_17() throws Exception { - assertEvaluatesTo("literal", - "{" + - " var it = new testdata.Properties1()" + - " prop2 = 'literal'" + - " prop2" + - "}"); - } - - @Test public void testAssignment_18() throws Exception { - assertEvaluatesTo("Integer: 1", - "{" + - " var it = new testdata.Properties1()" + - " prop2 = 1" + - " prop2" + - "}"); - } - - @Test public void testAssignment_19() throws Exception { - assertEvaluatesTo("literal", - "{" + - " var it = new testdata.Properties1()" + - " prop2 = 'literal'" + - " prop2" + - "}"); - } - - @Test public void testAssignment_20() throws Exception { - assertEvaluatesTo("Integer: 1", - "{" + - " var it = new testdata.Properties1()" + - " prop2 = 1" + - " prop2" + - "}"); - } - - @Test public void testAssignment_21() throws Exception { - assertEvaluatesTo(null, - "{" + - " var it = new testdata.Properties1()" + - " prop2 = 'literal'" + - " null" + - "}"); - } - - @Test public void testAssignment_22() throws Exception { - assertEvaluatesTo(null, - "{" + - " var it = new testdata.Properties1()" + - " prop2 = 1" + - " null" + - "}"); - } - - @Test public void testAssignment_23() throws Exception { - assertEvaluatesTo("Integer: 1", - "{" + - " var it = new testdata.Properties1()" + - " prop3 = 1" + - "}"); - } - - @Test public void testAssignment_24() throws Exception { - assertEvaluatesTo("literal", - "{" + - " var it = new testdata.Properties1()" + - " prop1 = 'literal'" + - "}"); - } - - @Test public void testAssignment_25() throws Exception { - assertEvaluatesTo("literal", - "{" + - " var it = new testdata.GenericType1()" + - " it += 'literal'" + - " get()" + - "}"); - } - - @Test public void testAssignment_26() throws Exception { - assertEvaluatesTo(Boolean.TRUE, - "{" + - " var it = new testdata.GenericType1()" + - " it += 'literal'" + - "}"); - } - - @Test public void testAssignment_27() throws Exception { - assertEvaluatesTo("literal", - "{" + - " var it = new testdata.Properties2()" + - " prop2 = 'literal'" + - " prop2" + - "}"); - } - - @Test public void testAssignment_28() throws Exception { - assertEvaluatesTo("literal", - "{" + - " var it = new testdata.Properties1" + - " prop1 = 'literal'" + - " prop1" + - "}"); - } - - @Test public void testAssignment_29() throws Exception { - assertEvaluatesTo("literal", - "{" + - " var it = new testdata.GenericType1" + - " it += 'literal'" + - " get()" + - "}"); - } - - @Test public void testAssignment_30() throws Exception { - assertEvaluatesTo(Integer.valueOf(0), - "{" + - " var client = new testdata.CoercionClient" + - " client.comparator = [ s1, s2 | s1.compareTo(s2) ]" + - " client.compare('', '')" + - "}"); - } - - @Test public void testAssignment_31() throws Exception { - assertEvaluatesTo(Integer.valueOf(0), - "{" + - " var it = new testdata.CoercionClient" + - " comparator = [ s1, s2 | s1.compareTo(s2) ]" + - " compare('', '')" + - "}"); - } - - @Test public void testAssignment_32() throws Exception { - assertEvaluatesTo(Integer.valueOf(1), - "{" + - " var client = new testdata.CoercionClient" + - " client.array = newArrayList(1)" + - " client.array.head" + - "}"); - } - - @Test public void testAssignment_33() throws Exception { - assertEvaluatesTo(Integer.valueOf(1), - "{" + - " var it = new testdata.CoercionClient" + - " array = newArrayList(1)" + - " array.head" + - "}"); - } - - @Test public void testAssignment_34() throws Exception { - assertEvaluatesTo("a", - "{" + - " var client = new testdata.CoercionClient" + - " client.varArgArray = newArrayList('a')" + - " client.array.head" + - "}"); - } - - @Test public void testAssignment_35() throws Exception { - assertEvaluatesTo("a", - "{" + - " var it = new testdata.CoercionClient" + - " varArgArray = newArrayList('a')" + - " array.head" + - "}"); - } - - @Test public void testAssignment_36() throws Exception { - assertEvaluatesTo(Integer.valueOf(0), - "{" + - " var client = new testdata.CoercionClient" + - " client.comparatorField = [ s1, s2 | s1.compareTo(s2) ]" + - " client.compare('', '')" + - "}"); - } - - @Test public void testAssignment_37() throws Exception { - assertEvaluatesTo(Integer.valueOf(0), - "{" + - " var it = new testdata.CoercionClient" + - " comparatorField = [ s1, s2 | s1.compareTo(s2) ]" + - " compare('', '')" + - "}"); - } - - @Test public void testAssignment_38() throws Exception { - assertEvaluatesTo(Integer.valueOf(0), - "{" + - " var java.util.Comparator c = null" + - " c = [ s1, s2 | s1.compareTo(s2) ]" + - " c.compare('', '')" + - "}"); - } - - @Test public void testAssignment_39() throws Exception { - assertEvaluatesTo(newArrayList("bar"), - "{" - + " val list = newArrayList('foo','bar')" - + " list -= 'foo'" - + " list" - + "}"); - } - - @Test public void testAssignment_40() throws Exception { - assertEvaluatesTo(emptyList(), - "{" - + " val list = newArrayList('foo','bar')" - + " list -= #['foo', 'bar']" - + " list" - + "}"); - } - - @Test public void testAssignmentInBlock_01() throws Exception { - assertEvaluatesTo("newValue", "{var x = 'literal' { x = 'newValue' } x }"); - } - - @Test public void testThrowInBlock() throws Exception { - assertEvaluatesWithException(NullPointerException.class, "{ throw new NullPointerException() }"); - } - - @Test public void testThrowInBlock_01() throws Exception { - assertEvaluatesWithException(NullPointerException.class, "{ 42.toString() throw new NullPointerException() }"); - } - - @Test public void testThrowInBlock_02() throws Exception { - assertEvaluatesWithException(NullPointerException.class, "{ throw new NullPointerException }"); - } - - @Test public void testForLoop_01() throws Exception { - assertEvaluatesTo(Character.valueOf('c'), - "{\n" + - " var Character result = null\n" + - " for(x: 'abc'.toCharArray) result = x\n" + - " result" + - "}"); - } - - @Test public void testForLoop_02() throws Exception { - assertEvaluatesTo(Character.valueOf('a'), - "{\n" + - " var Character result = null\n" + - " for(x: 'aba'.toCharArray) if (result == null) result = x\n" + - " result" + - "}"); - } - - @Test public void testForLoop_03() throws Exception { - assertEvaluatesWithException(ClassCastException.class, "{for(x: 'abc' as Object as java.util.List) x.hashCode() null}"); - } - - @Test public void testForLoop_04() throws Exception { - assertEvaluatesTo("foobar", - "{ " + - " val list = new java.util.ArrayList()" + - " list += 'bar'" + - " var result = 'foo'" + - " for( e : list) result = result + e" + - " result" + - "}"); - } - - @Test public void testForLoop_05() throws Exception { - assertEvaluatesTo("foobar", - "{ " + - " val list = new java.util.ArrayList" + - " list += 'bar'" + - " var result = 'foo'" + - " for( e : list) result = result + e" + - " result" + - "}"); - } - - @Test public void testForLoop_06() throws Exception { - String expr = - "{\n" + - " val list = newArrayList('foo','bar','baz')\n" + - " for (x : list.reverse) {\n" + - " x.toUpperCase\n" + - " }\n" + - " null" + - "}"; - assertEvaluatesTo(null, expr); - } - - @Test public void testForLoop_07() throws Exception { - String expr = - "{\n" + - " val list = newArrayList('foo','bar','baz')\n" + - " for (String x : list.reverse) {\n" + - " x.toUpperCase\n" + - " }\n" + - " null" + - "}"; - assertEvaluatesTo(null, expr); - } - - @Test public void testForLoop_08() throws Exception { - assertEvaluatesTo(Character.valueOf('c'), - "{\n" + - " var Character result = null\n" + - " for(char x: 'abc'.toCharArray) result = x\n" + - " result" + - "}"); - } - - @Test public void testForLoop_09() throws Exception { - assertEvaluatesTo(Character.valueOf('a'), - "{\n" + - " var Character result = null\n" + - " for(char x: 'abc'.toCharArray) if (result == null) result = x\n" + - " result" + - "}"); - } - - @Test public void testForLoop_10() throws Exception { - assertEvaluatesTo(Character.valueOf('c'), - "{\n" + - " var char result\n" + - " for(Character x: 'abc'.toCharArray) result = x\n" + - " result" + - "}"); - } - - @Test public void testForLoop_11() throws Exception { - assertEvaluatesTo(Integer.valueOf(1+2+3+4+5+6+7+8+9+10), - "{\n" + - " var int result\n" + - " for(int i: 1..10) result = result + i\n" + - " result" + - "}"); - } - - @Test public void testForLoop_12() throws Exception { - assertEvaluatesTo("foobar", - "{\n" + - " val java.util.List list = new java.util.ArrayList" + - " list += 'bar'" + - " var result = 'foo'" + - " for( e : list) result = result + e" + - " result" + - "}"); - } - - @Test public void testForLoop_13() throws Exception { - assertEvaluatesTo("foobar", - "{\n" + - " val java.util.List list = new java.util.ArrayList" + - " list += 'bar'" + - " var result = 'foo'" + - " for(Object e : list) result = result + e" + - " result" + - "}"); - } - - @Test public void testForLoop_14() throws Exception { - assertEvaluatesTo(Character.valueOf('c'), - "{\n" + - " var Character result = null\n" + - " for(char x: 'abc'.toCharArray.toList) result = x\n" + - " result" + - "}"); - } - - @Test public void testForLoop_15() throws Exception { - assertEvaluatesTo(Character.valueOf('a'), - "{\n" + - " var Character result = null\n" + - " for(x: 'abc'.toCharArray.toList) if (result == null) result = x\n" + - " result" + - "}"); - } - - @Test public void testForLoop_16() throws Exception { - assertEvaluatesTo(Character.valueOf('a'), - "{\n" + - " var Character result = null\n" + - " for(int i: 'abc'.toCharArray) if (result == null) result = i as char\n" + - " result" + - "}"); - } - - @Test public void testFunctionConversion_00() throws Exception { - assertEvaluatesTo("foo", - "([|newArrayList('foo').iterator] as Iterable).iterator.next"); - } - - @Test public void testWhileLoop_01() throws Exception { - assertEvaluatesTo("newValue", - "{\n" + - " var value = 'oldValue'\n" + - " var condition = true\n" + - " while(condition) { value = 'newValue' condition=false }" + - " value" + - "}"); - } - - @Test public void testWhileLoop_02() throws Exception { - assertEvaluatesTo("oldValue", - "{\n" + - " var value = 'oldValue'\n" + - " var condition = false\n" + - " while(condition) { value = 'newValue' condition=false }" + - " value" + - "}"); - } - - @Test public void testWhileLoop_03() throws Exception { - assertEvaluatesTo("startfoo", - "{\n" + - " var value = 'start'\n" + - " while(value.length<6) " + - " value = value + 'foo'" + - " value" + - "}"); - } - - /** - * @since 2.5 - */ - @Test public void testWhileLoop_04() throws Exception { - assertEvaluatesTo("hello", "{ val CharSequence x = new StringBuilder; while (x instanceof Appendable) { x.append('hello') return x.toString } x.toString }"); - } - - @Test public void testDoWhileLoop_01() throws Exception { - assertEvaluatesTo("newValue", - "{\n" + - " var value = 'oldValue'\n" + - " var condition = true\n" + - " do {" + - " value ='newValue'" + - " condition = false" + - " } while(condition)" + - " value" + - "}"); - } - - @Test public void testDoWhileLoop_02() throws Exception { - assertEvaluatesTo("newValue", - "{\n" + - " var value = 'oldValue'\n" + - " var condition = false\n" + - " do {" + - " value = 'newValue'" + - " } while(condition)" + - " value" + - "}"); - } - - /** - * @since 2.6 - */ - @Test public void testXBasicForLoopExpression_01() throws Exception { - assertEvaluatesTo("newValue", - "{\n" + - " var result = 'oldValue'\n"+ - " for (var condition = true; condition; condition = false) {\n" + - " result = 'newValue'\n" + - " }\n" + - " result\n" + - "}"); - } - - /** - * @since 2.6 - */ - @Test public void testXBasicForLoopExpression_02() throws Exception { - assertEvaluatesTo("oldValue", - "{\n" + - " var result = 'oldValue'\n"+ - " for (var condition = false; condition; condition = false) {\n" + - " result = 'newValue'\n" + - " }\n" + - " result\n" + - "}"); - } - - /** - * @since 2.6 - */ - @Test public void testXBasicForLoopExpression_03() throws Exception { - assertEvaluatesTo("foo", - "{\n" + - " val value = 'foo'\n" + - " for (var i = 0; i < 10; i = i + 1) {\n" + - " if (i == 3) {\n" + - " return value\n" + - " }\n" + - " }\n" + - " 'bar'\n" + - "}"); - } - - /** - * @since 2.6 - */ - @Test public void testXBasicForLoopExpression_03_1() throws Exception { - assertEvaluatesTo("foo", - "{\n" + - " var String value\n" + - " var int i\n" + - " for (value = 'foo', i = 0; i < 10; i = i + 1) {\n" + - " if (i == 3) {\n" + - " return value\n" + - " }\n" + - " }\n" + - " 'bar'\n" + - "}"); - } - - /** - * @since 2.6 - */ - @Test public void testXBasicForLoopExpression_04() throws Exception { - assertEvaluatesTo("hello", - "{\n" + - " for (val CharSequence x = new StringBuilder; x instanceof Appendable; x.append('hello')) {\n" + - " if (x.length != 0) {\n" + - " return x.toString\n" + - " }\n" + - " }\n" + - " 'bar'\n" + - "}"); - } - - /** - * @since 2.6 - */ - @Test public void testXBasicForLoopExpression_05() throws Exception { - assertEvaluatesTo("hello", - "{\n" + - " for (val Appendable x = new StringBuilder; x instanceof CharSequence; x.append('hello')) {\n" + - " if (x.length != 0) {\n" + - " return x.toString\n" + - " }\n" + - " }\n" + - " 'bar'\n" + - "}"); - } - - /** - * @since 2.6 - */ - @Test public void testXBasicForLoopExpression_06() throws Exception { - assertEvaluatesTo(Integer.valueOf(1+2+3+4+5+6+7+8+9+10), - "{\n" + - " var int result\n"+ - " for (var i = 1; i <= 10; i = i + 1) {\n" + - " result = result + i\n" + - " }\n" + - " result\n" + - "}"); - } - - /** - * @since 2.6 - */ - @Test public void testXBasicForLoopExpression_07() throws Exception { - assertEvaluatesTo(Integer.valueOf(1+2+3+4+5+6+7+8+9+10), - "{\n" + - " var int result\n"+ - " for (var i = 1; i <= 10; result = result + i, i = i + 1) {}\n" + - " result\n" + - "}"); - } - - /** - * @since 2.6 - */ - @Test public void testXBasicForLoopExpression_08() throws Exception { - assertEvaluatesTo("foobar", - "{\n" + - " val list = new java.util.ArrayList\n" + - " list += 'bar'\n" + - " var result = 'foo'\n" + - " for (var i = 0; i < list.size; i = i + 1) {\n" + - " result = result + list.get(i)\n" + - " }\n" + - " result\n" + - "}"); - } - - /** - * @since 2.6 - */ - @Test public void testXBasicForLoopExpression_09() throws Exception { - assertEvaluatesTo("foobar", - "{\n" + - " val list = new java.util.ArrayList\n" + - " list += 'bar'\n" + - " var result = 'foo'\n" + - " for (var i = 0; i < list.size; result = result + list.get(i), i = i + 1) {}\n" + - " result\n" + - "}"); - } - - /** - * @since 2.6 - */ - @Test public void testXBasicForLoopExpression_10() throws Exception { - assertEvaluatesTo(Character.valueOf('c'), - "{\n" + - " var Character result = null\n" + - " val abc = 'abc'.toCharArray\n" + - " for (var i = 0; i < abc.size; i = i + 1) {\n" + - " result = abc.get(i)\n" + - " }\n" + - " result\n" + - "}"); - } - - /** - * @since 2.6 - */ - @Test public void testXBasicForLoopExpression_11() throws Exception { - assertEvaluatesTo(Character.valueOf('c'), - "{\n" + - " var Character result = null\n" + - " val abc = 'abc'.toCharArray\n" + - " for (var i = 0; i < abc.size; result = abc.get(i), i = i + 1) {}\n" + - " result\n" + - "}"); - } - - /** - * @since 2.6 - */ - @Test public void testXBasicForLoopExpression_12() throws Exception { - assertEvaluatesTo(Character.valueOf('a'), - "{\n" + - " var Character result = null\n" + - " val abc = 'abc'.toCharArray\n" + - " for (var i = 0; i < abc.size; i = i + 1) {\n" + - " if (result == null) {\n" + - " result = abc.get(i)\n" + - " }\n" + - " }\n" + - " result\n" + - "}"); - } - - /** - * @since 2.6 - */ - @Test public void testXBasicForLoopExpression_13() throws Exception { - assertEvaluatesTo(Character.valueOf('a'), - "{\n" + - " var Character result = null\n" + - " val abc = 'abc'.toCharArray\n" + - " for (var i = 0; i < abc.size; if (result == null) { result = abc.get(i) }, i = i + 1) {}\n" + - " result\n" + - "}"); - } - - /** - * @since 2.6 - */ - @Test public void testXBasicForLoopExpression_14() throws Exception { - assertEvaluatesTo(Boolean.TRUE, - "{\n" + - " var condition = true\n" + - " for (;condition;) { return true }\n" + - " false\n" + - "}"); - } - - /** - * @since 2.6 - */ - @Test public void testXBasicForLoopExpression_15() throws Exception { - assertEvaluatesTo(8, - "{\n" + - " for (var i = 0; i < 10; i = i + 1) { if (i == 8) { return i } };\n" + - " -1\n" + - "}"); - } - - /** - * @since 2.6 - */ - @Test public void testXBasicForLoopExpression_16() throws Exception { - assertEvaluatesTo(8, - "{\n" + - " for (var i = 0; i < 10; i += 1) { if (i == 8) { return i } };\n" + - " -1\n" + - "}"); - } - - @Test public void testMemberFeatureCall_01() throws Exception { - assertEvaluatesTo("LITERAL", "'literal'.toUpperCase()"); - } - - @Test public void testMemberFeatureCall_02() throws Exception { - assertEvaluatesTo("literal", "'literal'.toUpperCase().toLowerCase()"); - } - - @Test public void testMemberFeatureCall_03() throws Exception { - assertEvaluatesTo("source", "new java.util.EventObject('source').source"); - } - - @Test public void testMemberFeatureCall_04() throws Exception { - assertEvaluatesTo("literal", - "{" + - " var fieldAccess = new testdata.FieldAccess()" + - " fieldAccess.stringField = 'literal'" + - "}"); - } - - @Test public void testMemberFeatureCall_05() throws Exception { - assertEvaluatesTo("literal", - "{" + - " var fieldAccess = new testdata.FieldAccess()" + - " fieldAccess.stringField = 'literal'" + - " fieldAccess.stringField" + - "}"); - } - - @Test public void testMemberFeatureCall_06() throws Exception { - assertEvaluatesTo(null, - "{" + - " var fieldAccess = new testdata.FieldAccess()" + - " fieldAccess.stringField" + - "}"); - } - - @Test public void testMemberFeatureCall_07() throws Exception { - assertEvaluatesTo("finalField", - "new testdata.FieldAccess().finalField"); - } - - @Test public void testNullSafeOperator_01() throws Exception { - assertEvaluatesWithException(NullPointerException.class, "(null as Object).toString()"); - assertEvaluatesWithException(NullPointerException.class, "(null as Object)?.toString().toString()"); - } - - @Test public void testNullSafeOperator_02() throws Exception { - assertEvaluatesTo(null, "(null as Object)?.toString()"); - assertEvaluatesTo(null, "(null as Object)?.toString()?.toString()"); - } - - /** - * @since 2.3 - */ - @Test public void testNullSafeFieldAccess_0() throws Exception { - assertEvaluatesWithException(NullPointerException.class, "new testdata.FieldAccess().stringField.toUpperCase"); - } - - /** - * @since 2.3 - */ - @Test public void testNullSafeFieldAccess_1() throws Exception { - assertEvaluatesTo(null, "new testdata.FieldAccess()?.stringField?.toUpperCase"); - } - - @Test public void testNullSafeFieldAccess_2() throws Exception { - assertEvaluatesTo(null, "new testdata.FieldAccess?.stringField?.toUpperCase"); - } - - @Ignore("TODO see https://bugs.eclipse.org/bugs/show_bug.cgi?id=341048") - @Test public void testSpreadOperator_01() throws Exception { - assertEvaluatesWithException(NullPointerException.class, "(null as java.util.List)*.toString()"); - assertEvaluatesWithException(ClassCastException.class, "(new Object() as java.util.List)*.toString()"); - } - - @Ignore("TODO see https://bugs.eclipse.org/bugs/show_bug.cgi?id=341048") - @Test public void testSpreadOperator_02() throws Exception { - assertEvaluatesTo(newArrayList( - "A", "B", "C"), "('abc'.toCharArray as Iterable)*.toString*.toUpperCase"); - } - - @Test public void testSwitchExpression_01() throws Exception { - assertEvaluatesTo(null, "switch 'x' { case false: 'literal' }"); - } - - @Test public void testSwitchExpression_02() throws Exception { - assertEvaluatesTo("literal", "switch 'x' { case 'x': 'literal' }"); - } - - @Test public void testSwitchExpression_03() throws Exception { - assertEvaluatesTo("literal", "switch 'x' { case 'y': 'foo' default : 'literal' }"); - } - - @Test public void testSwitchExpression_04() throws Exception { - assertEvaluatesTo("x", "switch x:'x' { case x.length==3 : 'xxx' default : 'x' }"); - } - - @Test public void testSwitchExpression_05() throws Exception { - assertEvaluatesTo(null, "switch new Object() { String : 'literal' }"); - } - - @Test public void testSwitchExpression_06() throws Exception { - assertEvaluatesTo("literal", "switch new Object() { Object : 'literal' }"); - } - - @Test public void testSwitchExpression_07() throws Exception { - assertEvaluatesTo("literal", "switch new Object() { case false: null default: 'literal' }"); - } - - @Test public void testSwitchExpression_08() throws Exception { - assertEvaluatesTo("literal", "switch x : new Object() { case false: null case x!=null: 'literal' }"); - } - - @Test public void testSwitchExpression_09() throws Exception { - assertEvaluatesTo(4, "switch 'foo' { case 'foo': 4 String: 3 }"); - } - - @Test public void testSwitchExpression_10() throws Exception { - assertEvaluatesTo(3, "switch 'foo' as Object { Boolean case 'foo': 4 String: 3 }"); - } - - @Test public void testSwitchExpression_11() throws Exception { - assertEvaluatesTo(3, "switch new java.util.ArrayList() { java.util.Set : 5 java.util.List: 3 }"); - } - - @Test public void testSwitchExpression_12() throws Exception { - assertEvaluatesTo("bar", "switch 'foo' { case 'bar' : return 'foo' default : 'bar' }"); - } - - @Test public void testSwitchExpression_13() throws Exception { - assertEvaluatesTo("bar", "switch 'foo' { case 'bar' : 'foo' default : return 'bar' }"); - } - - @Test public void testSwitchExpression_14() throws Exception { - assertEvaluatesTo("bar", "{ val _string = 'foo' switch _string { String : 'bar' default : 'foo'} }"); - } - - @Test public void testSwitchExpression_15() throws Exception { - assertEvaluatesTo("bar", "switch x : 'foo' { String : switch x { String : 'bar' default : 'other' } default : 'foo'}"); - } - - /** - * @since 2.3 - */ - @Test public void testSwitchExpression_16() throws Exception { - assertEvaluatesTo("bar", "switch 'foo'.toCharArray { char[]: 'bar' default: 'foo' }"); - } - - @Test public void testSwitchExpression_17() throws Exception { - assertEvaluatesTo("literal", "switch new Object { Object : 'literal' }"); - } - - @Test public void testSwitchExpression_18() throws Exception { - assertEvaluatesTo("literal", "switch (x : new Object) { Object : 'literal' }"); - } - - @Test public void testSwitchExpression_19() throws Exception { - assertEvaluatesTo("foo", "switch (x : 'foo' as Object) { String : x }"); - } - - @Test public void testSwitchExpression_20() throws Exception { - assertEvaluatesTo("success", - "{ val Class it = typeof(String) switch x : newInstance { String case x.length==0 : 'success'}}"); - } - - @Test public void testSwitchExpression_21() throws Exception { - assertEvaluatesTo(42, "switch 'foo' { case 'bar': return 1 default: return 42 }"); - } - - @Test public void testSwitchExpression_22() throws Exception { - assertEvaluatesTo(42, "switch 'foo' { case 'bar': 1 default: return 42 }"); - } - - @Test public void testSwitchExpression_23() throws Exception { - assertEvaluatesTo(42, "switch 'foo' { case 'bar': return 1 default: 42 }"); - } - - @Test public void testSwitchExpression_24() throws Exception { - assertEvaluatesTo(Character.valueOf('b'), - "{\n" + - " val Comparable c = 'abc'\n" + - " switch c {\n" + - " CharSequence: switch(c) {\n" + - " java.io.Serializable: {\n" + - " c.charAt(1)\n" + - " }\n" + - " }\n" + - " }\n" + - "}"); - } - - @Test public void testSwitchExpression_25() throws Exception { - assertEvaluatesTo(0, - "{ val Object o = '' switch x : o { String : x.length }}"); - } - - /** - * @since 2.5 - */ - @Test public void testSwitchExpression_26() throws Exception { - assertEvaluatesTo(Boolean.TRUE, - "{ val policy = java.lang.annotation.RetentionPolicy.SOURCE switch policy { case SOURCE: true } }"); - } - - /** - * @since 2.5 - */ - @Test public void testSwitchExpression_27() throws Exception { - assertEvaluatesTo(Boolean.FALSE, - "{ val Object policy = java.lang.annotation.RetentionPolicy.SOURCE switch policy { java.lang.annotation.RetentionPolicy case CLASS: true } }"); - } - - /** - * @since 2.5 - */ - @Test public void testSwitchExpression_28() throws Exception { - assertEvaluatesTo(6, - "switch it : 'abcdef' as Object { String : length }"); - } - - /** - * @since 2.5 - */ - @Test public void testSwitchExpression_29() throws Exception { - assertEvaluatesTo("a", - "{ var Object o = ''\n" + - " switch o { String : o = 'a' }\n" + - " o\n" + - "}"); - } - - /** - * @since 2.5 - */ - @Test public void testSwitchExpression_30() throws Exception { - assertEvaluatesTo("Abcdef", - "switch it : 'abcdef' as Object { String : toFirstUpper }"); - } - - /** - * @since 2.5 - */ - @Test public void testSwitchExpression_31() throws Exception { - assertEvaluatesTo(1, - "{ val int[] myArray = #[1,2] switch it : myArray as Object { int[] : it.get(0) default : 42 }}"); - } - - /** - * @since 2.5 - */ - @Test public void testSwitchExpression_32() throws Exception { - assertEvaluatesTo(1, - "{ val int[][] myArray = #[#[1,2]] switch it : myArray as Object { int[][] : it.get(0).get(0) default : 42 }}"); - } - - @Test public void testSwitchExpression_33() throws Exception { - assertEvaluatesTo(1, - "{ switch x : 0 { case 0: 1 " + - "case 1, case 2: 2 " + - "case 3, default: 3 } }"); - } - - @Test public void testSwitchExpression_34() throws Exception { - assertEvaluatesTo(2, - "{ switch x : 1 { case 0: 1 " + - "case 1, case 2: 2 " + - "case 3, default: 3 } }"); - } - - @Test public void testSwitchExpression_35() throws Exception { - assertEvaluatesTo(2, - "{ switch x : 2 { case 0: 1 " + - "case 1, case 2: 2 " + - "case 3, default: 3 } }"); - } - - @Test public void testSwitchExpression_36() throws Exception { - assertEvaluatesTo(3, - "{ switch x : 3 { case 0: 1 " + - "case 1, case 2: 2 " + - "case 3, default: 3 } }"); - } - - @Test public void testSwitchExpression_37() throws Exception { - assertEvaluatesTo(3, - "{ switch x : 4 { case 0: 1 " + - "case 1, case 2: 2 " + - "case 3, default: 3 } }"); - } - - @Test public void testSwitchExpression_38() throws Exception { - assertEvaluatesTo(1, - "{ switch x : 'a' { case 'a': 1 " + - "case 'b', case 'c': 2 " + - "case 'd', default: 3 " + - "} }"); - } - - @Test public void testSwitchExpression_39() throws Exception { - assertEvaluatesTo(2, - "{ switch x : 'b' { case 'a': 1 " + - "case 'b', case 'c': 2 " + - "case 'd', default: 3 " + - "} }"); - } - - @Test public void testSwitchExpression_40() throws Exception { - assertEvaluatesTo(2, - "{ switch x : 'c' { case 'a': 1 " + - "case 'b', case 'c': 2 " + - "case 'd', default: 3 " + - "} }"); - } - - @Test public void testSwitchExpression_41() throws Exception { - assertEvaluatesTo(3, - "{ switch x : 'd' { case 'a': 1 " + - "case 'b', case 'c': 2 " + - "case 'd', default: 3 " + - "} }"); - } - - @Test public void testSwitchExpression_42() throws Exception { - assertEvaluatesTo(3, - "{ switch x : 'e' { case 'a': 1 " + - "case 'b', case 'c': 2 " + - "case 'd', default: 3 " + - "} }"); - } - - @Test public void testSwitchExpression_44() throws Exception { - assertEvaluatesTo(0, - "{ switch x : 'lalala' as Object { String, Integer case 1: 0 " + - "Integer, default: 1 } }"); - } - - @Test public void testSwitchExpression_45() throws Exception { - assertEvaluatesTo(1, - "{ switch x : Integer.valueOf(2) as Object { String, Integer case 1: 0 " + - "Integer, default: 1 } }"); - } - - @Test public void testSwitchExpression_46() throws Exception { - assertEvaluatesTo(null, "{ switch 1 { } }"); - } - - @Test public void testSwitchExpression_47() throws Exception { - assertEvaluatesTo(null, "{ switch 1 { default: { } } }"); - } - - @Test public void testSwitchExpression_48() throws Exception { - assertEvaluatesTo(null, "{ switch Object { } }"); - } - - @Test public void testSwitchExpression_49() throws Exception { - assertEvaluatesTo(null, "{ switch Object { default: { } } }"); - } - - @Test public void testSwitchExpression_50() throws Exception { - assertEvaluatesTo(null, "{ switch Thread.State.NEW { } }"); - } - - @Test public void testSwitchExpression_51() throws Exception { - assertEvaluatesTo(null, "{ switch Thread.State.NEW { default: { } } }"); - } - - @Test public void testSwitchExpression_52() throws Exception { - assertEvaluatesTo(null, "{ switch Object x : Thread.State.NEW { default: { } } }"); - } - - @Test public void testSwitchExpression_53() throws Exception { - assertEvaluatesTo(null, "{ switch Thread.State x\n : Thread.State.NEW { default: { } } }"); - } - - @Test public void testSwitchExpression_54() throws Exception { - assertEvaluatesTo(null, "{ switch (Object x : Thread.State.NEW) { default: { } } }"); - } - - @Test public void testSwitchExpression_55() throws Exception { - assertEvaluatesTo(null, "{ switch (Thread.State x : Thread.State.NEW) { default: { } } }"); - } - - @Test public void testSwitchExpressionOverEnum() throws Exception { - assertEvaluatesTo(1, - "{\n" + - "val java.lang.Thread.State x = null\n" + - "var result = 1\n" + - "switch x { case NEW: { result = 2 } }\n" + - "result\n" + - " }"); - } - - @Test public void testSwitchExpressionOverEnum_2() throws Exception { - assertEvaluatesTo(2, - "{\n" + - "val java.lang.Thread.State x = Thread.State.NEW\n" + - "var result = 1\n" + - "switch x { case NEW: { result = 2 } }\n" + - "result\n" + - " }"); - } - - @Test public void testSwitchExpressionOverEnum_3() throws Exception { - assertEvaluatesTo(2, - "{\n" + - "val java.lang.Thread.State x = null\n" + - "var result = 1\n" + - "switch x { case NEW: { result = 3 } default: { result = 2 } }\n" + - "result\n" + - " }"); - } - - @Test public void testSwitchExpressionOverEnum_4() throws Exception { - assertEvaluatesTo(3, - "{\n" + - "val java.lang.Thread.State x = Thread.State.NEW\n" + - "var result = 1\n" + - "switch x { case NEW: { result = 3 } default: { result = 2 } }\n" + - "result\n" + - " }"); - } - - @Test public void testSwitchExpressionOverEnum_5() throws Exception { - assertEvaluatesTo(2, - "{\n" + - "val java.lang.Thread.State x = Thread.State.RUNNABLE\n" + - "var result = 1\n" + - "switch x { case NEW: { result = 3 } default: { result = 2 } }\n" + - "result\n" + - " }"); - } - - @Test public void testSwitchExpressionOverEnum_6() throws Exception { - assertEvaluatesTo(null, - "{\n" + - " val Enum e = null\n" + - " switch(e) {\n" + - " java.lang.^annotation.RetentionPolicy: e.toString\n" + - " java.lang.^annotation.ElementType: e.toString\n" + - " }\n" + - "}"); - } - - @Test public void testSwitchExpressionOverInteger() throws Exception { - assertEvaluatesTo(1, - "{\n" + - "val Integer x = null\n" + - "var result = 1\n" + - "switch x { case 3: { result = 2 } }\n" + - "result\n" + - " }"); - } - - @Test public void testSwitchExpressionOveInteger_2() throws Exception { - assertEvaluatesTo(2, - "{\n" + - "val Integer x = Integer.valueOf('3')\n" + - "var result = 1\n" + - "switch x { case 3: { result = 2 } }\n" + - "result\n" + - " }"); - } - - @Test public void testSwitchExpressionOverInteger_3() throws Exception { - assertEvaluatesTo(2, - "{\n" + - "val Integer x = null\n" + - "var result = 1\n" + - "switch x { case 3: { result = 3 } default: { result = 2 } }\n" + - "result\n" + - " }"); - } - - @Test public void testSwitchExpressionOveInteger_4() throws Exception { - assertEvaluatesTo(3, - "{\n" + - "val Integer x = Integer.valueOf('3')\n" + - "var result = 1\n" + - "switch x { case 3: { result = 3 } default: { result = 2 } }\n" + - "result\n" + - " }"); - } - - @Test public void testSwitchExpressionOveInteger_5() throws Exception { - assertEvaluatesTo(2, - "{\n" + - "val Integer x = Integer.valueOf('4')\n" + - "var result = 1\n" + - "switch x { case 3: { result = 3 } default: { result = 2 } }\n" + - "result\n" + - " }"); - } - - @Test public void testSwitchExpressionOveInteger_6() throws Exception { - assertEvaluatesTo("bar", - "{\n" + - "val Integer x = Integer.valueOf('4')\n" + - "switch x { case 3: { 'foo' } default: if ('x'.length == 1) { 'bar' } }\n" + - " }"); - } - - @Test public void testCastedExpression_01() throws Exception { - assertEvaluatesTo("literal", "'literal' as String"); - } - - @Test public void testCastedExpression_02() throws Exception { - assertEvaluatesWithException(ClassCastException.class, "'literal' as Object as Integer"); - } - - @Test public void testCastedExpression_03() throws Exception { - assertEvaluatesTo(null, "null as Integer"); - } - - @Test public void testCastedExpression_05() throws Exception { - assertEvaluatesTo("MyString", "(if (true) { 'MyString' } else { throw new Exception() }) as String"); - } - - @Test public void testCastedExpression_06() throws Exception { - assertEvaluatesTo("MyString", "(try { 'MyString' } finally { 'bla'.length }) as String"); - } - - @Test public void testCastedExpression_07() throws Exception { - assertEvaluatesTo("MyString", "(try { 'MyString' } catch (Exception e) { throw e }) as String"); - } - - @Test public void testTryCatch_01() throws Exception { - assertEvaluatesTo("caught", "try { 'literal' as Object as Boolean } catch(ClassCastException e) {'caught'}"); - } - - @Test public void testTryCatch_02() throws Exception { - assertEvaluatesTo("literal", "try { 'literal' as String } catch(ClassCastException e) {'caught'}"); - } - - @Test public void testTryCatch_03() throws Exception { - assertEvaluatesTo("ClassCastException", "try { 'literal' as Object as Boolean } catch(ClassCastException e) {e.getClass().getSimpleName()}"); - } - - @Test public void testTryCatch_04() throws Exception { - assertEvaluatesWithException(NullPointerException.class, "try { 'literal' as Object as Boolean } catch(ClassCastException e) throw new NullPointerException()"); - } - - @Test public void testTryCatch_05() throws Exception { - assertEvaluatesWithException(NullPointerException.class, - "try 'literal' as Object as Boolean" + - " catch(ClassCastException e) throw new NullPointerException()" + - " catch(NullPointerException e) 'dont catch subsequent exceptions'"); - } - - @Test public void testTryCatch_06() throws Exception { - assertEvaluatesWithException(NullPointerException.class, - "try 'literal' as Object as Boolean" + - " catch(ClassCastException e) throw new NullPointerException" + - " catch(NullPointerException e) 'dont catch subsequent exceptions'"); - } - - @Test public void testTryCatch_WithThrows() throws Exception { - assertEvaluatesWithException(NullPointerException.class, - "try throw new NullPointerException()" + - " catch(ClassCastException e) throw new NullPointerException()" + - " catch(NullPointerException e) throw new NullPointerException()"); - } - - @Test public void testTryCatch_WithThrows_01() throws Exception { - assertEvaluatesTo("x", - "try throw new NullPointerException()" + - " catch(ClassCastException e) throw new NullPointerException()" + - " catch(NullPointerException e) 'x'"); - } - - @Test public void testTryCatch_WithThrows_02() throws Exception { - assertEvaluatesTo("foo", - "try 'foo'" + - " catch(ClassCastException e) throw new NullPointerException()" + - " catch(NullPointerException e) 'x'"); - } - - @Test public void testTryFinally_01() throws Exception { - assertEvaluatesTo("literal", "try 'literal' finally 'finally'.toString"); - } - - @Test public void testTryFinally_02() throws Exception { - assertEvaluatesTo("finally", "{ var x = 'foo' try x = 'literal' finally x = 'finally' x }"); - } - - @Test public void testConstructor_01() throws Exception { - assertEvaluatesTo(Boolean.TRUE, "new java.io.StringReader('literal').markSupported"); - } - - @Test public void testConstructor_02() throws Exception { - assertEvaluatesTo(Character.valueOf('a'), "new Character('abc'.charAt(0))"); - } - - @Test public void testConstructor_03() throws Exception { - assertEvaluatesTo("source", "new java.util.EventObject('source').getSource"); - } - - @Test public void testConstructor_04() throws Exception { - assertEvaluatesTo(new Stack(), "new java.util.Stack()"); - } - - @Test public void testConstructor_05() throws Exception { - assertEvaluatesTo(Collections.emptyList(), "new java.util.ArrayList(newArrayList)"); - } - - @Test public void testConstructor_06() throws Exception { - assertEvaluatesTo(Collections.singletonList("a"), "new java.util.ArrayList(newArrayList('a'))"); - } - - @Test public void testThrowExpression_01() throws Exception { - assertEvaluatesWithException(ExceptionSubclass.class, "throw new testdata.ExceptionSubclass()"); - } - - @Test public void testThrowExpression_02() throws Exception { - assertEvaluatesWithException(ClassCastException.class, "throw (new Object() as RuntimeException)"); - } - - @Test public void testThrowExpression_03() throws Exception { - assertEvaluatesWithException(NullPointerException.class, "throw null"); - } - - @Test public void testThrowExpression_04() throws Exception { - assertEvaluatesWithException(NullPointerException.class, "throw new NullPointerException()"); - } - - @Test public void testThrowExpression_05() throws Exception { - assertEvaluatesWithException(RuntimeException.class, "if ('foo'=='bar') 'foobar' else throw new RuntimeException()"); - } - - @Test public void testThrowExpression_06() throws Exception { - assertEvaluatesWithException(ClassCastException.class, "throw (new Object as RuntimeException)"); - } - - @Test public void testInstanceOf_01() throws Exception { - assertEvaluatesTo(Boolean.TRUE, "'literal' instanceof String"); - } - - @Test public void testInstanceOf_02() throws Exception { - assertEvaluatesTo(Boolean.TRUE, "'literal' instanceof CharSequence"); - } - - @Test public void testInstanceOf_03() throws Exception { - assertEvaluatesTo(Boolean.FALSE, "'literal' as Object instanceof Boolean"); - } - - @Test public void testInstanceOf_04() throws Exception { - assertEvaluatesTo(Boolean.FALSE, "null instanceof Boolean"); - } - - /** - * @since 2.3 - */ - @Test public void testInstanceOf_05() throws Exception { - assertEvaluatesTo(Boolean.FALSE, "[|'foo'] instanceof com.google.common.base.Supplier"); - assertEvaluatesTo(Boolean.TRUE, "[|'foo'] instanceof org.eclipse.xtext.xbase.lib.Functions$Function0"); - } - - /** - * @since 2.3 - */ - @Test public void testInstanceOf_06() throws Exception { - assertEvaluatesTo(Boolean.FALSE, "newArrayList('foo','bar') as Object instanceof Object[]"); - assertEvaluatesTo(Boolean.TRUE, "newArrayList('foo','bar') as String[] instanceof Object[]"); - } - - /** - * @since 2.4 - */ - @Test public void testInstanceOf_07() throws Exception { - assertEvaluatesTo(Boolean.FALSE, "[|'foo'] instanceof com.google.common.base.Supplier"); - assertEvaluatesTo(Boolean.TRUE, "[|'foo'] instanceof org.eclipse.xtext.xbase.lib.Functions$Function0"); - } - - /** - * @since 2.4 - */ - @Test public void testInstanceOf_08() throws Exception { - assertEvaluatesTo(Boolean.FALSE, "null instanceof java.util.List"); - } - - /** - * @since 2.4 - */ - @Test public void testInstanceOf_09() throws Exception { - assertEvaluatesTo(Boolean.TRUE, "[|'foo'] instanceof org.eclipse.xtext.xbase.lib.Functions.Function0"); - } - - /** - * @since 2.4 - */ - @Test public void testInstanceOf_10() throws Exception { - assertEvaluatesTo(Boolean.TRUE, "[|'foo'] instanceof org.eclipse.xtext.xbase.lib.Functions.Function0"); - } - - /** - * @since 2.5 - */ - @Test public void testInstanceOf_11() throws Exception { - assertEvaluatesTo("hello", "{ val CharSequence x = new StringBuilder; (if (x instanceof Appendable) x.append('hello')).toString }"); - } - - /** - * @since 2.5 - */ - @Test public void testInstanceOf_12() throws Exception { - assertEvaluatesTo("el", "{ val Object x = 'hello' if (x instanceof CharSequence) x.subSequence(1,3) }"); - } - - /** - * @since 2.5 - */ - @Test public void testInstanceOf_13() throws Exception { - assertEvaluatesTo("0", "{ val CharSequence x = new StringBuilder; (if (x instanceof Appendable) x.append(x.length().toString())).toString }"); - } - - /** - * @since 2.5 - */ - @Test public void testInstanceOf_14() throws Exception { - assertEvaluatesTo("0", "{ val Object x = new StringBuilder; if (x instanceof Appendable) if (x instanceof CharSequence) x.append(x.length().toString()) x.toString }"); - } - - @Test public void testClosure_01() throws Exception { - assertEvaluatesTo("literal", "new testdata.ClosureClient().invoke0(|'literal')"); - } - - @Test public void testClosure_02() throws Exception { - assertEvaluatesTo("literal", - "{" + - " val result = 'literal'" + - " new testdata.ClosureClient().invoke0(|result)" + - "}"); - } - - @Test public void testClosure_03() throws Exception { - assertEvaluatesTo("literal", - "{" + - " var closure = [|'literal']" + - " new testdata.ClosureClient().invoke0(closure)" + - "}"); - } - - @Test public void testClosure_05() throws Exception { - assertEvaluatesTo("LITERAL", - "new testdata.ClosureClient().invoke1([String s|s.toUpperCase], 'literal')"); - } - - @Test public void testClosure_06() throws Exception { - assertEvaluatesTo("LITERAL", - "new testdata.ClosureClient().invoke2(" + - "[Void p1, String s|s.toUpperCase], null, 'literal')"); - } - - @Test public void testClosure_06_1() throws Exception { - assertEvaluatesTo("LITERAL", - "new testdata.ClosureClient().invoke2(" + - "[p1, s|s.toUpperCase], null, 'literal')"); - } - - @Test public void testClosure_07() throws Exception { - assertEvaluatesTo("literal", - "{" + - " val func = [|'literal']" + - " new testdata.ClosureClient().useProvider(func)" + - "}"); - } - - @Test public void testClosure_07_01() throws Exception { - assertEvaluatesTo("literal", - "new testdata.ClosureClient().useProvider(|'literal')"); - } - - @Test public void testClosure_07_02() throws Exception { - assertEvaluatesWithException(NullPointerException.class, - "new testdata.ClosureClient().useProvider(null as =>String[])"); - } - - @Test public void testClosure_07_03() throws Exception { - assertEvaluatesWithException(NullPointerException.class, - "new testdata.ClosureClient().useSupplier(null as =>Iterable[])"); - } - - @Test public void testClosure_07_04() throws Exception { - assertEvaluatesWithException(NullPointerException.class, - "new testdata.ClosureClient().invoke0(null as =>String[])"); - } - - @Test public void testClosure_08() throws Exception { - assertEvaluatesTo("literal", - "new testdata.ClosureClient().useSupplier(|'literal')"); - } - - @Test public void testClosure_09() throws Exception { - assertEvaluatesTo("LITERAL", - "new testdata.ClosureClient().useGoogleCollectFunction([String s|s.toUpperCase], 'literal')"); - } - - @Test public void testClosure_09_2() throws Exception { - assertEvaluatesTo("LITERAL", - "new testdata.ClosureClient().useGoogleCollectFunction2([String s|s.toUpperCase], 'literal')"); - } - - @Test public void testClosure_10() throws Exception { - assertEvaluatesTo("LITERAL", - "new testdata.ClosureClient().useGoogleCollectFunction([s|s.toUpperCase], 'literal')"); - } - - @Test public void testClosure_10_2() throws Exception { - assertEvaluatesTo("LITERAL", - "new testdata.ClosureClient().useGoogleCollectFunction2([s|s.toUpperCase], 'literal')"); - } - - @Test public void testClosure_11() throws Exception { - assertEvaluatesTo(Boolean.TRUE, - "new testdata.ClosureClient().useGoogleCollectPredicate([String s|'literal'.equals(s)], 'literal')"); - } - - @Test public void testClosure_11_2() throws Exception { - assertEvaluatesTo(Boolean.TRUE, - "new testdata.ClosureClient().useGoogleCollectPredicate2([String s|'literal'.equals(s)], 'literal')"); - } - - @Test public void testClosure_12() throws Exception { - assertEvaluatesTo(Boolean.TRUE, - "new testdata.ClosureClient().useGoogleCollectPredicate([s|'literal'.equals(s)], 'literal')"); - } - - @Test public void testClosure_12_2() throws Exception { - assertEvaluatesTo(Boolean.TRUE, - "new testdata.ClosureClient().useGoogleCollectPredicate2([s|'literal'.equals(s)], 'literal')"); - } - - @Test public void testClosure_13() throws Exception { - assertEvaluatesTo(Boolean.FALSE, - "new testdata.ClosureClient().useGoogleCollectPredicate([s|'literal'.equals(s)], 'false')"); - } - - @Test public void testClosure_13_2() throws Exception { - assertEvaluatesTo(Boolean.FALSE, - "new testdata.ClosureClient().useGoogleCollectPredicate2([s|'literal'.equals(s)], 'false')"); - } - - @Test public void testClosure_14() throws Exception { - assertEvaluatesTo("literal", - "{" + - " var client = new testdata.ClosureClient()" + - " var fun = client.getIdentityFunction" + - " client.useGoogleCollectFunction(fun, 'literal')" + - "}"); - } - - @Test public void testClosure_14_2() throws Exception { - assertEvaluatesTo("literal", - "{" + - " var client = new testdata.ClosureClient()" + - " var fun = client.getIdentityFunction" + - " client.useGoogleCollectFunction2(fun, 'literal')" + - "}"); - } - - @Test public void testClosure_15() throws Exception { - assertEvaluatesTo(Collections.singletonList("literal"), - "{" + - " val result = newArrayList" + - " val =>void runMe = [|result.add('literal')]" + - " new testdata.ClosureClient().useRunnable(runMe)" + - " result" + - "}"); - } - - @Test public void testClosure_16() throws Exception { - assertEvaluatesTo(Collections.singletonList("literal"), - "{" + - " val result = newArrayList" + - " new testdata.ClosureClient().useRunnable(|result.add('literal'))" + - " result" + - "}"); - } - - @Test public void testClosure_17() throws Exception { - assertEvaluatesTo(Collections.singletonList("literal"), - "{" + - " val result = newArrayList" + - " val client = new testdata.ClosureClient()" + - " val runnable = client.asRunnable(|result.add('literal'))" + - " client.useRunnable(runnable)" + - " result" + - "}"); - } - - @Test public void testClosure_18() throws Exception { - assertEvaluatesTo(Collections.singletonList("literal"), - "{" + - " val result = newArrayList" + - " val client = new testdata.ClosureClient()" + - " val procedure = client.asProcedure(|result.add('literal'))" + - " client.useRunnable(procedure)" + - " result" + - "}"); - } - - @Test public void testClosure_19() throws Exception { - assertEvaluatesTo("twoArgs:12", - "{" + - " val client = new testdata.ClosureClient()" + - " client.concatStrings(|'1') [|'2']" + - "}"); - } - - @Test public void testClosure_20() throws Exception { - assertEvaluatesTo("varArgs:1", - "{" + - " val client = new testdata.ClosureClient()" + - " client.concatStrings(|'1')" + - "}"); - } - - @Test public void testClosure_21() throws Exception { - assertEvaluatesTo("varArgs:1", - "{" + - " val client = new testdata.ClosureClient()" + - " client.concatStrings [|'1']" + - "}"); - } - - @Test public void testClosure_22() throws Exception { - assertEvaluatesTo("varArgs:", - "{" + - " val client = new testdata.ClosureClient()" + - " client.concatStrings" + - "}"); - } - - @Test public void testClosure_23() throws Exception { - assertEvaluatesTo("varArgs:123", - "{" + - " val client = new testdata.ClosureClient()" + - " client.concatStrings([|'1'],[|'2']) [|'3']" + - "}"); - } - - @Test public void testClosure_24() throws Exception { - assertEvaluatesTo("twoArgs:12", - "{" + - " val it = new testdata.ClosureClient()" + - " concatStrings(|'1') [|'2']" + - "}"); - } - - @Test public void testClosure_25() throws Exception { - assertEvaluatesTo("varArgs:1", - "{" + - " val it = new testdata.ClosureClient()" + - " concatStrings(|'1')" + - "}"); - } - - @Test public void testClosure_26() throws Exception { - assertEvaluatesTo("varArgs:1", - "{" + - " val it = new testdata.ClosureClient()" + - " concatStrings [|'1']" + - "}"); - } - - @Test public void testClosure_27() throws Exception { - assertEvaluatesTo("varArgs:", - "{" + - " val it = new testdata.ClosureClient()" + - " concatStrings" + - "}"); - } - - @Test public void testClosure_28() throws Exception { - assertEvaluatesTo("varArgs:123", - "{" + - " val it = new testdata.ClosureClient()" + - " concatStrings([|'1'],[|'2']) [|'3']" + - "}"); - } - - @Test public void testClosure_29() throws Exception { - assertEvaluatesTo("done", - "{" + - " val (CharSequence)=>void proc = [s|]\n" + - " val client = new testdata.ClosureClient\n" + - " client.useProcedureForCharSequence(proc)" + - "}"); - } - - @Test public void testClosure_30() throws Exception { - assertEvaluatesTo("Foo", - "{" + - " new testdata.InterfaceASubClient().getClassName [| 'Foo' ]" + - "}"); - } - - @Test public void testClosure_31() throws Exception { - assertEvaluatesTo(Integer.valueOf(15), - "{ val (int)=>int fun = [ if (it == 0) 0 else self.apply(it - 1) + it ] fun.apply(5) }"); - } - - @Test public void testClosure_32() throws Exception { - assertEvaluatesTo("fooinner", - "{ val (String)=>String fun = [ val (String)=>String nestedFun = [if (it.endsWith('inner')) it else self.apply(it+'inner')] nestedFun.apply(it)] fun.apply('foo') }"); - } - - /* - * see https://bugs.eclipse.org/bugs/show_bug.cgi?id=391758 - */ - @Test public void testClosure_33() throws Exception { - assertEvaluatesTo(newArrayList("foo"), - "{ val (java.util.List,String)=>java.util.List functionReturningList = [a, b| a += b return a ] " - + "#['foo'].fold(newArrayList, functionReturningList) }"); - } - - /** - * @since 2.5 - */ - @Test public void testClosure_34() throws Exception { - assertEvaluatesTo("hello", "{ val (Object)=>String x = [ if (it instanceof String) return it ] x.apply('hello') }"); - } - - /** - * @since 2.7 - */ - @Test public void testClosure_35() throws Exception { - assertEvaluatesTo(newArrayList("foo"), - "{ val (java.util.List,String)=>java.util.List functionReturningList = [$0 += $1 return $0 ] " - + "#['foo'].fold(newArrayList, functionReturningList) }"); - } - - /** - * @since 2.7 - */ - @Test public void testClosure_36() throws Exception { - assertEvaluatesTo(Collections.singletonList("literal"), - "{" + - " val result = newArrayList" + - " val =>void runMe = [result.add('literal')]" + - " new testdata.ClosureClient().useRunnable(runMe)" + - " result" + - "}"); - } - - /** - * @since 2.7 - */ - @Test public void testClosure_37() throws Exception { - assertEvaluatesTo("LITERAL", - "new testdata.ClosureClient().invoke2(" + - "[$1.toUpperCase], null, 'literal')"); - } - - @Test public void testExceptionOnClosure() throws Exception { - assertEvaluatesWithException(java.beans.PropertyVetoException.class, - "{ val java.beans.VetoableChangeListener x = [ throw new java.beans.PropertyVetoException('', it) ] x.vetoableChange(null) true }"); - } - - /** - * @since 2.3 - */ - @Test public void testClosureConversion_01() throws Exception { - assertEvaluatesTo(newArrayList("bar","foo"), - "{" + - " val client = new testdata.ClosureClient()" + - " val com.google.inject.Provider provider = [|'foo']" + - " val com.google.common.base.Supplier supplier = [|'bar']" + - " newArrayList(client.useProvider(supplier as =>String), client.useSupplier(provider as =>String))" + - "}"); - } - - @Test public void testArrayConversion_01() throws Exception { - assertEvaluatesTo("LITERAL", - "{" + - " var client = new testdata.ArrayClient()" + - " var stringArray = client.toStringArray('literal', 'other')" + - " client.inplaceToUpperCase(stringArray)" + - " stringArray.iterator.next()" + - "}"); - } - - @Test public void testArrayConversion_02() throws Exception { - assertEvaluatesTo("OTHER", - "{" + - " var client = new testdata.ArrayClient()" + - " var stringArray = client.toStringArray('literal', 'other')" + - " client.inplaceToUpperCase(stringArray)" + - " var iter = (stringArray as Iterable).iterator" + - " iter.next" + - " iter.next" + - "}"); - } - - @Test public void testArrayConversion_03() throws Exception { - assertEvaluatesTo(Integer.valueOf(42), - "{" + - " var client = new testdata.ArrayClient()" + - " var intArray = client.toIntArray(32, 7)" + - " client.inplaceAdd10(intArray)" + - " var iter = (intArray as java.util.List).iterator" + - " iter.next" + - "}"); - } - - @Test public void testArrayConversion_04() throws Exception { - assertEvaluatesTo(Integer.valueOf(17), - "{" + - " var client = new testdata.ArrayClient()" + - " var intArray = client.toIntArray(32, 7)" + - " client.inplaceAdd10(intArray)" + - " var iter = (intArray as Iterable).iterator" + - " iter.next" + - " iter.next" + - "}"); - } - - @Test public void testArrayConversion_05() throws Exception { - assertEvaluatesTo("literal", - "{" + - " var client = new testdata.ArrayClient()" + - " var stringArray = client.toStringArray('literal', 'other')" + - " client.inplaceSwap(stringArray)" + - " var iter = (stringArray as java.util.List).iterator" + - " iter.next" + - " iter.next" + - "}"); - } - - @Test public void testArrayConversion_06() throws Exception { - assertEvaluatesTo(newArrayList("b", "c"), - "{" + - " var a = 'a,b,c'.split(',')\n" + - " a = a.tail" + - " a.toList" + - "}"); - } - - @Test public void testArrayConversion_07() throws Exception { - assertEvaluatesTo(newArrayList(2, 3), - "{" + - " var int[] result = newArrayList(1, 2, 3)\n" + - " result = result.tail" + - " result.toList" + - "}"); - } - - @Test public void testArrayConversion_08() throws Exception { - assertEvaluatesTo(newArrayList("c", "b"), - "{" + - " var a = 'b,c'.split(',')\n" + - " new testdata.ArrayClient().swap(a).toList" + - "}"); - } - - @Test public void testArrayConversion_09() throws Exception { - assertEvaluatesTo(newArrayList("c", "b"), - "new testdata.ArrayClient().swap('b,c'.split(',')).toList"); - } - - @Test public void testArrayConversion_10() throws Exception { - assertEvaluatesTo(newArrayList("c", "b"), - "{" + - " var a = 'a,b,c'.split(',')\n" + - " a = a.tail" + - " a = new testdata.ArrayClient().swap(a)" + - " a.toList" + - "}"); - } - - @Test public void testArrays_01() throws Exception { - assertEvaluatesTo(42, - "{" + - " var Integer[] a = newArrayOfSize(42)" + - " a.length" + - "}"); - } - - @Test public void testArrays_02() throws Exception { - assertEvaluatesTo(38, - "{" + - " var a = newArrayOfSize(42)" + - " a.set(40, 4)" + - " a.length - a.get(40)" + - "}"); - } - - - @Test public void testArrays_03() throws Exception { - assertEvaluatesTo('x', - "{" + - " var a = newCharArrayOfSize(42)" + - " a.set(40, 'x')" + - " a.get(40)" + - "}"); - } - - @Test public void testArrays_04() throws Exception { - assertEvaluatesTo("foo", - "{" + - " var java.util.List[] a = newArrayOfSize(42)" + - " a.set(40, #['foo'])" + - " a.get(40).head" + - "}"); - } - - @Test public void testConstructorVarArgs_01() throws Exception { - assertEvaluatesTo(Boolean.TRUE, "new testdata.ClassWithVarArgs().defaultConstructor"); - } - - @Test public void testConstructorVarArgs_02() throws Exception { - assertEvaluatesTo(Boolean.TRUE, "new testdata.ClassWithVarArgs(1).varArgConstructor"); - } - - @Test public void testConstructorVarArgs_03() throws Exception { - assertEvaluatesTo(Boolean.TRUE, "new testdata.ClassWithVarArgs(1, '').varArgConstructor"); - } - - @Test public void testConstructorVarArgs_04() throws Exception { - assertEvaluatesTo(Boolean.FALSE, "new testdata.ClassWithVarArgs(1, '', '').varArgConstructor"); - } - - @Test public void testConstructorVarArgs_05() throws Exception { - assertEvaluatesTo(Boolean.TRUE, "new testdata.ClassWithVarArgs(1, '', '', '').varArgConstructor"); - } - - @Test public void testMethodVarArgs_01() throws Exception { - assertEvaluatesTo(Collections.emptyList(), "new testdata.ClassWithVarArgs().stringsToList()"); - } - - @Test public void testMethodVarArgs_02() throws Exception { - assertEvaluatesTo(Collections.singletonList("s1"), "new testdata.ClassWithVarArgs().stringsToList('s1')"); - } - - @Test public void testMethodVarArgs_03() throws Exception { - assertEvaluatesTo(newArrayList("foo", "s1", "s2"), "new testdata.ClassWithVarArgs().stringsToList('s1', 's2')"); - } - - @Test public void testMethodVarArgs_04() throws Exception { - assertEvaluatesTo(newArrayList("s1", "s2", "s3"), "new testdata.ClassWithVarArgs().stringsToList('s1', 's2', 's3')"); - } - - @Test public void testMethodVarArgs_05() throws Exception { - assertEvaluatesTo(Collections.emptyList(), "{ var x = new testdata.ClassWithVarArgs() x.stringsToList() }"); - } - - @Test public void testMethodVarArgs_06() throws Exception { - assertEvaluatesTo(Collections.singletonList("s1"), "{ var x = new testdata.ClassWithVarArgs() x.stringsToList('s1') }"); - } - - @Test public void testMethodVarArgs_07() throws Exception { - assertEvaluatesTo(newArrayList("foo", "s1", "s2"), "{ var x = new testdata.ClassWithVarArgs() x.stringsToList('s1', 's2') }"); - } - - @Test public void testMethodVarArgs_08() throws Exception { - assertEvaluatesTo(newArrayList("s1", "s2", "s3"), "{ var x = new testdata.ClassWithVarArgs() x.stringsToList('s1', 's2', 's3') }"); - } - - @Test public void testMethodVarArgs_09() throws Exception { - assertEvaluatesTo(newArrayList("s1"), "{ var x = new testdata.ClassWithVarArgs() x.stringsToList2('s1') }"); - } - @Test public void testMethodVarArgs_10() throws Exception { - assertEvaluatesTo(newArrayList("s1", "s2"), "{ var x = new testdata.ClassWithVarArgs() x.stringsToList2('s1', 's2') }"); - } - @Test public void testMethodVarArgs_11() throws Exception { - assertEvaluatesTo(newArrayList("s1", "s2", "s3"), "{ var x = new testdata.ClassWithVarArgs() x.stringsToList2('s1', 's2', 's3') }"); - } - - @Test public void testMethodVarArgs_12() throws Exception { - assertEvaluatesTo("logInfo(a)", "new testdata.ClassWithVarArgs().logInfo('a')"); - } - - @Test public void testMethodVarArgs_13() throws Exception { - assertEvaluatesTo("logInfo(a, args...)", "new testdata.ClassWithVarArgs().logInfo('a', 'b')"); - } - - @Test public void testMethodVarArgs_14() throws Exception { - assertEvaluatesTo("logInfo2(a)", "new testdata.ClassWithVarArgs().logInfo2('a')"); - } - - @Test public void testMethodVarArgs_15() throws Exception { - assertEvaluatesTo("logInfo2(a, b)", "new testdata.ClassWithVarArgs().logInfo2('a', 'b')"); - } - - @Test public void testMethodVarArgs_16() throws Exception { - assertEvaluatesTo("logInfo2(a, b, c)", "new testdata.ClassWithVarArgs().logInfo2('a', 'b', 'c')"); - } - - @Test public void testMethodVarArgs_17() throws Exception { - assertEvaluatesTo("logInfo2(a, args...)", "new testdata.ClassWithVarArgs().logInfo2('a', 'b', 'c', 'd')"); - } - - @Test public void testMethodVarArgs_18() throws Exception { - assertEvaluatesTo(newArrayList("s1", "s2", "s3"), "new testdata.ClassWithVarArgs().stringsToList(#['s1', 's2', 's3'])"); - } - - @Test public void testMethodVarArgs_19() throws Exception { - assertEvaluatesTo(newArrayList("s1", "s2", "s3"), "new testdata.ClassWithVarArgs().stringsToList2('s1', #['s2', 's3'])"); - } - - @Test public void testMethodVarArgs_20() throws Exception { - assertEvaluatesTo("logInfo2(foo, args...)", "new testdata.ClassWithVarArgs().logInfo2('foo',#['s1', 's2', 's3'])"); - } - - @Test public void testMethodVarArgs_21() throws Exception { - assertEvaluatesTo("logInfo2(foo, args...)", "new testdata.ClassWithVarArgs().logInfo2('foo', 's1', 's2', 's3')"); - } - - @Test public void testAssignmentVarArgs_01() throws Exception { - assertEvaluatesTo(Collections.emptyList(), "{ var x = new testdata.ClassWithVarArgs x.values = #[] x.values }"); - } - - @Test public void testAssignmentVarArgs_02() throws Exception { - assertEvaluatesTo(null, "{ var x = new testdata.ClassWithVarArgs x.values = null x.values }"); - } - - @Test public void testAssignmentVarArgs_03() throws Exception { - assertEvaluatesTo(newArrayList("s1"), "{ var x = new testdata.ClassWithVarArgs x.values = 's1' x.values }"); - } - - @Test public void testAssignmentVarArgs_04() throws Exception { - assertEvaluatesTo(newArrayList("s1", "s2"), "{ var x = new testdata.ClassWithVarArgs x.values = #['s1', 's2'] x.values }"); - } - - @Test public void testAssignmentVarArgs_05() throws Exception { - assertEvaluatesTo(newArrayList("s1", "s2", "s3"), "{ var x = new testdata.ClassWithVarArgs x.values = #['s1', 's2', 's3'] x.values }"); - } - - @Test public void testIterableExtension_01() throws Exception { - assertEvaluatesTo(null, "new java.util.ArrayList().findFirst(String e|e.length==0)"); - } - - @Test public void testIterableExtension_02() throws Exception { - assertEvaluatesTo(null, "new java.util.ArrayList().findFirst(e|e.length==0)"); - } - - @Test public void testIterableExtension_03() throws Exception { - assertEvaluatesTo(Integer.valueOf(12), "newArrayList(1, 2, 3, 4, 5, 6).filter(i|i%2==0).reduce(a,b|a+b)"); - } - - @Test public void testIterableExtension_04() throws Exception { - assertEvaluatesTo(newArrayList(2, 3, 2, 3, 4), "newArrayList('a','aa','b','aa','abc').map(s|s.length+1).toList()"); - } - - @Test public void testIterableExtension_05() throws Exception { - assertEvaluatesTo(Integer.valueOf(2 + 3 + 2 + 3 + 4), "newArrayList('a','aa','b','aa','abc').map(s|s.length + 1).reduce(a,b|a+b)"); - } - - @Test public void testIterableExtension_06() throws Exception { - assertEvaluatesTo(Integer.valueOf(5), "newArrayList('a','aa','b','aa','abc').map(s|s.length + 1).take(4).toSet().reduce(a,b|a+b)"); - } - - @Test public void testIterableExtension_07() throws Exception { - assertEvaluatesTo(newArrayList("a", "b", "c"), "newArrayList('a','b', 'c', 'd', 'e').take(3).toList()"); - } - - @Test public void testIterableExtension_08() throws Exception { - assertEvaluatesTo(newArrayList("d", "e"), "newArrayList('a', 'b', 'c', 'd', 'e').drop(3).toList()"); - } - - @Test public void testIterableExtension_09() throws Exception { - assertEvaluatesTo(Boolean.TRUE, "(null as Iterable).isNullOrEmpty()"); - assertEvaluatesTo(Boolean.TRUE, "newArrayList().isNullOrEmpty()"); - assertEvaluatesTo(Boolean.FALSE, "newHashSet('a').isNullOrEmpty()"); - } - - @Test public void testIterableExtension_10() throws Exception { - assertEvaluatesTo("seed 12345", "newArrayList(1, 2, 3, 4, 5).fold('seed ', [s, i|s+i.toString])"); - } - - @Test public void testIterableExtension_11() throws Exception { - assertEvaluatesTo("seed", "newArrayList().fold('seed', [s, i|s+i.toString])"); - } - - @Test public void testIterableExtension_12() throws Exception { - assertEvaluatesTo(newArrayList("a","b"), - "{\n" + - " val result = newArrayList\n" + - " newArrayList('a','b').forEach [ result += it ]\n" + - " result\n" + - "}"); - } - - @Test public void testIterableExtension_13() throws Exception { - assertEvaluatesTo(null, "new java.util.ArrayList.findFirst(String e|e.length==0)"); - } - - @Test public void testIterableExtension_14() throws Exception { - assertEvaluatesTo("seed", "newArrayList.fold('seed', [s, i|s+i.toString])"); - } - - @Test public void testMapExtension_01() throws Exception { - assertEvaluatesTo(newArrayList("a->b","c->d","a->b","c->d","a->b","c->d"), - "{\n" + - " val result = newArrayList\n" + - " newLinkedHashMap('a'->'b', 'c'->'d').forEach(k, v| result.add(k + '->' + v))\n" + - " newLinkedHashMap('a'->'b', 'c'->'d').forEach[k, v| result.add(k + '->' + v)]\n" + - " newLinkedHashMap('a'->'b', 'c'->'d').forEach() [k, v| result.add(k + '->' + v)]\n" + - " result\n" + - "}"); - } - - @Test public void testMapExtension_02() throws Exception { - assertEvaluatesTo(Boolean.FALSE, - "newLinkedHashMap('a'->'b', 'c'->'d').filter(k, v| k != 'a').containsKey('a')"); - } - - @Test public void testMapExtension_03() throws Exception { - assertEvaluatesTo("B", - "newLinkedHashMap('a'->'b', 'c'->'d').mapValues[ toUpperCase ].get('a')"); - } - - @Test public void testMapExtension_04() throws Exception { - assertEvaluatesTo("B", - "newLinkedHashMap('a'->'b', 'c'->'d').mapValues() [ toUpperCase ].get('a')"); - } - - @Test public void testMapExtension_05() throws Exception { - assertEvaluatesTo(newArrayList("a->b","c->d","a->b","c->d","a->b","c->d"), - "{\n" + - " val result = newArrayList\n" + - " val it = newLinkedHashMap('a'->'b', 'c'->'d')" + - " forEach(k, v| result.add(k + '->' + v))\n" + - " forEach() [k, v| result.add(k + '->' + v)]\n" + - " forEach [k, v| result.add(k + '->' + v)]\n" + - " result\n" + - "}"); - } - - @Test public void testMapExtension_06() throws Exception { - assertEvaluatesTo(Boolean.FALSE, - "{ val it = newLinkedHashMap('a'->'b', 'c'->'d') filter(k, v| k != 'a').containsKey('a') }"); - } - - @Test public void testMapExtension_07() throws Exception { - assertEvaluatesTo("B", - "{ val it = newLinkedHashMap('a'->'b', 'c'->'d') mapValues[ toUpperCase ].get('a') }"); - } - - @Test public void testMapExtension_08() throws Exception { - assertEvaluatesTo("B", - "{ val it = newLinkedHashMap('a'->'b', 'c'->'d') mapValues() [ toUpperCase ].get('a') }"); - } - - @Test public void testTypeInference() throws Exception { - assertEvaluatesTo(9, - "newArrayList('foo','bar','baz','booze').sortBy[length].take(3).fold(0)[a, b| a + b.length]"); - } - - @Test public void testMapValuesExtension() throws Exception { - assertEvaluatesTo("B", - "{ val it = newLinkedHashMap(1->'b', 2->'d') " + - "if ('D' != it.mapValues[ toUpperCase ].get(2)) {\n" + - " throw new RuntimeException" + - "} " + - "return it.mapValues[ toUpperCase ].get(1)}"); - } - - @Test public void testReduceWithPlusOperator() throws Exception { - assertEvaluatesTo( 55 , - "(1..10).map[it].reduce[ a, b | a + b]"); - } - - @Test public void testMapConstruction_00() throws Exception { - assertEvaluatesTo("vier", "newHashMap(3->'drei',4->'vier').get(4)"); - } - - @Test public void testMapConstruction_01() throws Exception { - assertEvaluatesTo("vier", "newHashMap(3->'drei',4->'vier').entrySet.findFirst(e|e.key==4).value"); - } - - @Test public void testStaticMethod_01() throws Exception { - assertEvaluatesTo(newTreeSet(), "newTreeSet(String left, String right|left.compareTo(right))"); - } - - @Test public void testStaticMethod_02() throws Exception { - assertEvaluatesTo(newHashSet("a"), "newTreeSet([left, right|left.compareTo(right)], 'a')"); - } - - @Test public void testCollectionExtensions_01() throws Exception { - assertEvaluatesTo(Boolean.TRUE, "{ var x = newArrayList('') var result = x.unmodifiableView() x.clear() result.empty }"); -// assertEvaluatesWithException(UnsupportedOperationException.class, "newArrayList('').unmodifiableView().clear()"); - assertEvaluatesWithException(UnsupportedOperationException.class, "{ newArrayList('').unmodifiableView().clear() null }"); - } - - @Test public void testCollectionExtensions_02() throws Exception { - assertEvaluatesTo(Boolean.TRUE, "{ var x = newHashSet('') var result = x.unmodifiableView() x.clear() result.empty }"); -// assertEvaluatesWithException(UnsupportedOperationException.class, "newHashSet('').unmodifiableView().clear()"); - assertEvaluatesWithException(UnsupportedOperationException.class, "{ newHashSet('').unmodifiableView().clear null }"); - } - - @Test public void testCollectionExtensions_03() throws Exception { - assertEvaluatesTo(Boolean.TRUE, "newArrayList().unmodifiableView() instanceof java.util.List"); - assertEvaluatesTo(Boolean.TRUE, "newHashSet().unmodifiableView() instanceof java.util.Set"); - assertEvaluatesTo(Boolean.TRUE, "newLinkedHashSet().unmodifiableView() instanceof java.util.Set"); - assertEvaluatesTo(Boolean.TRUE, "newTreeSet(String a, String b|a.compareTo(b)).unmodifiableView() instanceof java.util.SortedSet"); - assertEvaluatesTo(Boolean.TRUE, "newHashMap().unmodifiableView() instanceof java.util.Map"); - assertEvaluatesTo(Boolean.TRUE, "newLinkedHashMap().unmodifiableView() instanceof java.util.Map"); - assertEvaluatesTo(Boolean.TRUE, "newTreeMap(String a, String b|a.compareTo(b)).unmodifiableView() instanceof java.util.SortedMap"); - } - - @Test public void testCollectionExtensions_04() throws Exception { - assertEvaluatesTo(Boolean.FALSE, "(newArrayList() as java.util.Collection).unmodifiableView() instanceof java.util.List"); - assertEvaluatesTo(Boolean.TRUE, "(newArrayList() as java.util.Collection).unmodifiableView() instanceof java.util.Collection"); - assertEvaluatesTo(Boolean.FALSE, "(newHashSet() as java.util.Collection).unmodifiableView() instanceof java.util.Set"); - assertEvaluatesTo(Boolean.TRUE, "(newHashSet() as java.util.Collection).unmodifiableView() instanceof java.util.Collection"); - } - - @Test public void testCollectionExtensions_05() throws Exception { - assertEvaluatesTo(Collections.singletonList("foo"), "{ var x = newArrayList('foo') var result = x.immutableCopy() x.clear() result }"); - assertEvaluatesWithException(UnsupportedOperationException.class, "{ newArrayList('').immutableCopy().clear() null }"); - } - - @Test public void testCollectionExtensions_06() throws Exception { - assertEvaluatesTo(Collections.singleton("foo"), "{ var x = newHashSet('foo') var result = x.immutableCopy() x.clear() result }"); - assertEvaluatesWithException(UnsupportedOperationException.class, "{ newHashSet('').immutableCopy().clear null }"); - } - - @Test public void testCollectionExtensions_07() throws Exception { - assertEvaluatesTo(newArrayList("a", "b", "c"), "{ var x = newArrayList() x.addAll('a', 'b', 'c') x }"); - assertEvaluatesTo(Boolean.FALSE, "newHashSet('a', 'b', 'c').addAll('a', 'b', 'c')"); - } - - @Test public void testCollectionExtensions_08() throws Exception { - assertEvaluatesTo("a", "{ var x = newArrayList('a,b'.split(',')) x.head.head }"); - } - - @Test public void testCollectionExtensions_09() throws Exception { - assertEvaluatesTo("a", "{ var x = >newArrayList('a,b'.split(',')) x.head.head }"); - } - - @Test public void testCollectionExtensions_10() throws Exception { - assertEvaluatesTo("a", "{ var x = >newArrayList('a,b'.split(',')).flatten x.head }"); - } - - @Test public void testListExtensions_01() throws Exception { - assertEvaluatesTo(newArrayList("a", "b", "c"), "newArrayList('c', 'a', 'b').sortInplace()"); - assertEvaluatesTo(newArrayList("a", "b", "c"), "newArrayList('c', 'a', 'b').sort()"); - assertEvaluatesTo("b", "{ var l = newArrayList('c', 'a', 'b', 'd') l.sortInplace() l.get(1) }"); - assertEvaluatesTo("a", "{ var l = newArrayList('c', 'a', 'b', 'd') l.sort() l.get(1) }"); - } - - @Test public void testListExtensions_02() throws Exception { - assertEvaluatesTo(newArrayList("a", "b", "c"), "(newArrayList('c', 'a', 'b') as Iterable).sort(a,b|a.compareTo(b))"); - assertEvaluatesTo(newArrayList("a", "b", "c"), "newArrayList('c', 'a', 'b').sortInplace(a,b|a.compareTo(b))"); - assertEvaluatesTo(newArrayList("c", "b", "a"), "(newArrayList('c', 'a', 'b') as Iterable).sort(a,b|b.compareTo(a))"); - assertEvaluatesTo(newArrayList("c", "b", "a"), "newArrayList('c', 'a', 'b').sortInplace(a,b|b.compareTo(a))"); - assertEvaluatesTo("a", "{ var l = newArrayList('c', 'a', 'b', 'd') (l as Iterable).sort(a,b|a.compareTo(b)) l.get(1) }"); - assertEvaluatesTo("b", "{ var l = newArrayList('c', 'a', 'b', 'd') l.sortInplace(a,b|a.compareTo(b)) l.get(1) }"); - } - - @Test public void testListExtensions_03() throws Exception { - assertEvaluatesTo(newArrayList("aaa", "bb", "c"), "newArrayList('c', 'aaa', 'bb').sortBy(s|-s.length)"); - assertEvaluatesTo(newArrayList("aaa", "bb", "c"), "newArrayList('c', 'aaa', 'bb').sortInplaceBy(s|-s.length)"); - assertEvaluatesTo(newArrayList("c", "bb", "aaa"), "newArrayList('c', 'aaa', 'bb').sortBy(s|s.length)"); - assertEvaluatesTo(newArrayList("c", "bb", "aaa"), "newArrayList('c', 'aaa', 'bb').sortInplaceBy(s|s.length)"); - assertEvaluatesTo("a", "{ var l = newArrayList('c', 'a', 'b', 'd') l.sortBy(a|a) l.get(1) }"); - assertEvaluatesTo("b", "{ var l = newArrayList('c', 'a', 'b', 'd') l.sortInplaceBy(a|a) l.get(1) }"); - } - - @Test public void testMemberCallOnMultiType_01() throws Exception { - assertEvaluatesTo("ClassB", "(if (false) new testdata.ClassA() else new testdata.ClassB()).getClassName()"); - assertEvaluatesTo("CLASSB", "(if (false) new testdata.ClassA() else new testdata.ClassB()).getUpperCaseClassName()"); - assertEvaluatesTo("ClassA", "(if (true) new testdata.ClassA() else new testdata.ClassB()).getClassName()"); - assertEvaluatesTo("CLASSA", "(if (true) new testdata.ClassA() else new testdata.ClassB()).getUpperCaseClassName()"); - } - - @Test public void testMemberCallOnMultiType_02() throws Exception { - assertEvaluatesTo(Integer.valueOf(20), "(if (false) new Double('-20') else new Integer('20')).intValue"); - assertEvaluatesTo(Integer.valueOf(-20), "(if (true) new Double('-20') else new Integer('20')).intValue"); - } - - @Test public void testMemberCallOnMultiType_03() throws Exception { - assertEvaluatesTo( - Integer.valueOf(20), - "newArrayList('20').map(s|if (false) new Double(s) else new Integer(s)).head.intValue"); - } - - @Test public void testMemberCallOnMultiType_04() throws Exception { - assertEvaluatesTo( - Integer.valueOf(20), - "newArrayList(if (false) new Double('-20') else new Integer('20')).map(v|v.intValue).head"); - } - - @Test public void testMemberCallOnMultiType_05() throws Exception { - assertEvaluatesTo(Integer.valueOf(20), "{ var number = if (false) new Double('-10') else new Integer('20') number.intValue}"); - } - - @Test public void testMemberCallOnMultiType_06() throws Exception { - assertEvaluatesTo(Integer.valueOf(20), "{ var x = if (false) new Double('-10') else new Integer('20') x.intValue }"); - } - - @Ignore("This is actually not conformant except if generics are ignored") - @Test public void testMemberCallOnMultiType_07() throws Exception { - assertEvaluatesTo(Boolean.TRUE, "(if (false) new Double('-20') else new Integer('10')) >= 0"); - } - - @Ignore("This is actually not conformant except if generics are ignored") - @Test public void testMemberCallOnMultiType_08() throws Exception { - assertEvaluatesTo(Boolean.FALSE, "(if (false) new Double('-20') else new Integer('10')) < 0"); - } - - @Test public void testMemberCallOnMultiType_09() throws Exception { - assertEvaluatesTo( - Integer.valueOf(20), - "{ val Object o = newArrayList(if (false) new Double('-20') else new Integer('20')).map(v|v.intValue).head o }"); - } - - @Test public void testBug343144_01() throws Exception { - for (int i = 0; i < 1; i++) { - assertEvaluatesTo(Integer.valueOf(3), - "{" + - "newArrayList('ab', 'abc').fold(0 as Integer, [max, s | Math::max(s.length, max)]);" + - "newArrayList('ab', 'abc').fold(0 as Integer, [max, s | Math::max(s.length, max)]);" + - "newArrayList('ab', 'abc').fold(0 as Integer, [max, s | Math::max(s.length, max)]);" + - "newArrayList('ab', 'abc').fold(0 as Integer, [max, s | Math::max(s.length, max)]);" + - "newArrayList('ab', 'abc').fold(0 as Integer, [max, s | Math::max(s.length, max)]);" + - "newArrayList('ab', 'abc').fold(0 as Integer, [max, s | Math::max(s.length, max)]);" + - "newArrayList('ab', 'abc').fold(0 as Integer, [max, s | Math::max(s.length, max)]);" + - "newArrayList('ab', 'abc').fold(0 as Integer, [max, s | Math::max(s.length, max)]);" + - "newArrayList('ab', 'abc').fold(0 as Integer, [max, s | Math::max(s.length, max)]);" + - "newArrayList('ab', 'abc').fold(0 as Integer, [max, s | Math::max(s.length, max)]);" + - "newArrayList('ab', 'abc').fold(0 as Integer, [max, s | Math::max(s.length, max)]);" + - "newArrayList('ab', 'abc').fold(0 as Integer, [max, s | Math::max(s.length, max)]);" + - "newArrayList('ab', 'abc').fold(0 as Integer, [max, s | Math::max(s.length, max)]);" + - "newArrayList('ab', 'abc').fold(0 as Integer, [max, s | Math::max(s.length, max)]);" + - "newArrayList('ab', 'abc').fold(0 as Integer, [max, s | Math::max(s.length, max)]);" + - "newArrayList('ab', 'abc').fold(0 as Integer, [max, s | Math::max(s.length, max)]);" + - "newArrayList('ab', 'abc').fold(0 as Integer, [max, s | Math::max(s.length, max)]);" + - "newArrayList('ab', 'abc').fold(0 as Integer, [max, s | Math::max(s.length, max)]);" + - "newArrayList('ab', 'abc').fold(0 as Integer, [max, s | Math::max(s.length, max)]);" + - "newArrayList('ab', 'abc').fold(0 as Integer, [max, s | Math::max(s.length, max)]);" + - "}" - ); - } - } - - @Test public void testBug343144_02() throws Exception { - assertEvaluatesTo(Integer.valueOf(3), - "newArrayList('ab', 'abc').fold(0, [Integer max, s | Math::max(s.length, max)])"); - } - - @Test public void testBug343144_03() throws Exception { - assertEvaluatesTo(Integer.valueOf(3), - "newArrayList('ab', 'abc').fold(0, [max, s | Math::max(s.length, max)])"); - } - - @Test public void testBug343144_04() throws Exception { - assertEvaluatesTo(Integer.valueOf(3), - "{ val Integer i = 0 newArrayList('ab', 'abc').fold(i, [max, s | Math::max(s.length, max)]) }"); - } - - @Test public void testBug343144_05() throws Exception { - assertEvaluatesTo(Integer.valueOf(3), - "{ val int i = 0 newArrayList('ab', 'abc').fold(i, [max, s | Math::max(s.length, max)]) }"); - } - - @Test public void testBug343144_06() throws Exception { - assertEvaluatesTo(Integer.valueOf(3), - "{ val i = 0 newArrayList('ab', 'abc').fold(i, [max, s | Math::max(s.length, max)]) }"); - } - - @Test public void testBug343144_long_01() throws Exception { - assertEvaluatesTo(Long.valueOf(3), - "newArrayList('ab', 'abc').fold(0.longValue, [max, s | Math::max(s.length, max)])"); - } - - @Test public void testBug343144_long_02() throws Exception { - assertEvaluatesTo(Long.valueOf(3), - "newArrayList('ab', 'abc').fold(0.longValue, [Long max, s | Math::max(s.length, max)])"); - } - - @Test public void testBug343144_long_03() throws Exception { - assertEvaluatesTo(Long.valueOf(3), - "newArrayList('ab', 'abc').fold(0.longValue, [max, s | Math::max(s.length, max as Long)])"); - } - - @Test public void testBug343144_long_04() throws Exception { - assertEvaluatesTo(Long.valueOf(3), - "{ val Long i = 0.longValue newArrayList('ab', 'abc').fold(i, [max, s | Math::max(s.length, max)]) }"); - } - - @Test public void testBug343144_long_05() throws Exception { - assertEvaluatesTo(Long.valueOf(3), - "{ val long i = 0.longValue newArrayList('ab', 'abc').fold(i, [max, s | Math::max(s.length, max)]) }"); - } - - @Test public void testBug343144_long_06() throws Exception { - assertEvaluatesTo(Long.valueOf(3), - "{ val i = 0.longValue as Long newArrayList('ab', 'abc').fold(i, [max, s | Math::max(s.length, max)]) }"); - } - - @Test public void testBug343144_float_01() throws Exception { - assertEvaluatesTo(Float.valueOf(3), - "newArrayList('ab', 'abc').fold(0.floatValue, [max, s | Math::max(s.length, max)])"); - } - - @Test public void testBug343144_float_02() throws Exception { - assertEvaluatesTo(Float.valueOf(3), - "newArrayList('ab', 'abc').fold(0.floatValue, [Float max, s | Math::max(s.length, max)])"); - } - - @Test public void testBug343144_float_03() throws Exception { - assertEvaluatesTo(Float.valueOf(3), - "newArrayList('ab', 'abc').fold(0.floatValue, [max, s | Math::max(s.length, max as Float)])"); - } - - @Test public void testBug343144_float_04() throws Exception { - assertEvaluatesTo(Float.valueOf(3), - "{ val Float i = 0.floatValue newArrayList('ab', 'abc').fold(i, [max, s | Math::max(s.length, max)]) }"); - } - - @Test public void testBug343144_float_05() throws Exception { - assertEvaluatesTo(Float.valueOf(3), - "{ val float i = 0.floatValue newArrayList('ab', 'abc').fold(i, [max, s | Math::max(s.length, max)]) }"); - } - - @Test public void testBug343144_float_06() throws Exception { - assertEvaluatesTo(Float.valueOf(3), - "{ val i = 0.floatValue as Float newArrayList('ab', 'abc').fold(i, [max, s | Math::max(s.length, max)]) }"); - } - - @Test public void testBug342434_01() throws Exception { - assertEvaluatesTo("baz", - "{\n" + - " val x = newArrayList('foo','bar','baz').toArray\n" + - " val arrayAccess = new testdata.ArrayClient2(x)\n" + - " arrayAccess.set(1,arrayAccess.get(0))\n" + - " return arrayAccess.get(2)\n" + - "}"); - } - - @Test public void testBug342434_02() throws Exception { - assertEvaluatesTo("baz", - "{\n" + - " val x = newArrayList('foo','bar','baz').toArray\n" + - " val arrayAccess = new testdata.ArrayClient2(x)\n" + - " arrayAccess.set(1,arrayAccess.get(0))\n" + - " return arrayAccess.get(2)\n" + - "}"); - } - - @Test public void testBug342434_03() throws Exception { - assertEvaluatesTo("foo", - "{\n" + - " val x = new testdata.GenericType1('foo')\n" + - " val testdata.GenericType1 y = x\n" + - " y.get\n" + - "}"); - } - - @Test public void testBug342434_04() throws Exception { - assertEvaluatesTo("foo", - "{\n" + - " val testdata.GenericType1 x = new testdata.GenericType1()\n" + - " x.set('foo')\n" + - " x.get\n" + - "}"); - } - - @Test public void testBug342434_05() throws Exception { - assertEvaluatesTo("baz", - "{\n" + - " val x = newArrayList('foo','bar','baz').toArray\n" + - " val arrayAccess = testdata::ArrayClient2::access(x)\n" + - " arrayAccess.set(1,arrayAccess.get(0))\n" + - " return arrayAccess.get(2)\n" + - "}"); - } - - @Test public void testBug342434_06() throws Exception { - assertEvaluatesTo("baz", - "{\n" + - " val x = newArrayList('foo','bar','baz').toArray\n" + - " val arrayAccess = new testdata.ArrayClient2(x)\n" + - " arrayAccess.set(1,arrayAccess.get(0))\n" + - " arrayAccess.get(2)\n" + - "}"); - } - - @Test public void testBug342434_07() throws Exception { - assertEvaluatesTo("baz", - "{\n" + - " val x = newArrayList('foo','bar','baz').toArray\n" + - " val arrayAccess = new testdata.ArrayClient2(x)\n" + - " arrayAccess.set(1,arrayAccess.get(0))\n" + - " arrayAccess.get(2)\n" + - "}"); - } - - @Test public void testBug342434_08() throws Exception { - assertEvaluatesTo("baz", - "{\n" + - " val x = newArrayList('foo','bar','baz').toArray\n" + - " val arrayAccess = testdata::ArrayClient2::access(x)\n" + - " arrayAccess.set(1,arrayAccess.get(0))\n" + - " arrayAccess.get(2)\n" + - "}"); - } - - @Test public void testBug349762_01() throws Exception { - assertEvaluatesTo(Boolean.TRUE, - "try {\n" + - " throw new NullPointerException()\n" + - "} catch(Exception e) {\n" + - " [Exception e2 | e==e2].apply(e)\n" + - "}"); - } - - @Test public void testBug349762_02() throws Exception { - assertEvaluatesTo("a", - "switch s: 'abc' as CharSequence {\n" + - " String: [Integer a, Integer b| s.substring(a, b)].apply(0, 1)\n" + - "}"); - } - - @Test public void testBug347175() throws Exception { - assertEvaluatesTo(Boolean.FALSE, "(null as Boolean)?.booleanValue()"); - assertEvaluatesTo(Byte.valueOf((byte)0), "(null as Byte)?.byteValue()"); - assertEvaluatesTo(Character.valueOf((char)0), "(null as Character)?.charValue()"); - assertEvaluatesTo(Short.valueOf((short)0), "(null as Short)?.shortValue()"); - assertEvaluatesTo(Integer.valueOf(0), "(null as Integer)?.intValue()"); - assertEvaluatesTo(Long.valueOf(0l), "(null as Long)?.longValue()"); - assertEvaluatesTo(Float.valueOf(0f), "(null as Float)?.floatValue()"); - assertEvaluatesTo(Double.valueOf(0.), "(null as Double)?.doubleValue()"); - } - - @Test public void test351809() throws Exception { - assertEvaluatesTo(Boolean.FALSE, - "{\n" + - " val l = new java.util.ArrayList()\n" + - " new java.util.ArrayList() += l\n" + - "}"); - } - - @Test public void test351809_02() throws Exception { - assertEvaluatesTo(Boolean.FALSE, - "{\n" + - " val l = new java.util.ArrayList\n" + - " new java.util.ArrayList += l\n" + - "}"); - } - - @Test public void testFilterArrays_01() throws Exception { - assertEvaluatesTo(newArrayList("a"), - "{\n" + - " val filtered = new testdata.ArrayClient().toStringArray('a', 'c').filter(e|e < 'c')" + - " filtered.toList\n" + - "}"); - } - - @Test public void testFilterArrays_02() throws Exception { - assertEvaluatesTo("result", - "{\n" + - " for(s: new testdata.ArrayClient().toStringArray('a', 'b').filter(e|e!=null))" + - " s.toUpperCase\n" + - " 'result'" + - "}"); - } - - @Test public void testBug370302() throws Exception { - assertEvaluatesTo(3, - "{\n" + - " val strings = newHashSet('foobar', 'bar', 'longer')\n" + - " val (String)=>int length = [s | s.length]\n" + - " val (int,int)=>int min = [i,j | if (i < j) i else j]\n" + - " strings.map(length).reduce(min)\n" + - "}"); - } - - @Test public void testBooleanArithmetics() throws Exception { - assertEvaluatesTo(false ^ (false || true) && true, "false.xor(false || true) && true"); - } - - @Test public void testIntegerArithmetics() throws Exception { - assertEvaluatesTo(-1+2*3/4%5, "-1+2*3/4%5"); - } - - @Test public void testIntegerBitOperations() throws Exception { - assertEvaluatesTo(~(1 | 2 & 3), "1.bitwiseOr(2).bitwiseAnd(3).bitwiseNot()"); - } - - @Test public void testIntegerShiftOperations_01() throws Exception { - assertEvaluatesTo(2 >> 1, "2 >> 1"); - } - @Test public void testIntegerShiftOperations_02() throws Exception { - assertEvaluatesTo(-2 >>> 1, " -2 >>> 1"); - } - @Test public void testIntegerShiftOperations_03() throws Exception { - assertEvaluatesTo(2 << 1, "2 << 1"); - } - - @Test public void testLongShiftOperations_01() throws Exception { - assertEvaluatesTo(2l >> 1, "2l >> 1"); - } - @Test public void testLongShiftOperations_02() throws Exception { - assertEvaluatesTo(-2l >>> 1, " -2l >>> 1"); - } - @Test public void testLongShiftOperations_03() throws Exception { - assertEvaluatesTo(2l << 1, "2l << 1"); - } - - protected void assertIntegerAssignOperations(Integer expectedResult, String xbaseCode) throws Exception { - assertEvaluatesTo(expectedResult, xbaseCode); - } - - @Test public void testIntegerAssignOperations_01() throws Exception { - int i = 2; - assertIntegerAssignOperations(i += 3, - "{\n" + - " var i = 2\n" + - " i += 3\n" + - " i" + - "}"); - } - - @Test public void testIntegerAssignOperations_02() throws Exception { - int i = 2; - assertIntegerAssignOperations(i *= 3, - "{\n" + - " var i = 2\n" + - " i *= 3\n" + - " i" + - "}"); - } - - @Test public void testIntegerAssignOperations_03() throws Exception { - int i = 2; - assertIntegerAssignOperations(i += i *= 2, - "{\n" + - " var i = 2\n" + - " i += i *= 2\n" + - " i" + - "}"); - } - - @Test public void testIntegerAssignOperations_04() throws Exception { - int i = 2; - assertIntegerAssignOperations(i *= i += 2, - "{\n" + - " var i = 2\n" + - " i *= i += 2\n" + - " i" + - "}"); - } - - @Test public void testIntegerAssignOperations_05() throws Exception { - int i = 2; - assertIntegerAssignOperations(i += (3 + (i *= 2)), - "{\n" + - " var i = 2\n" + - " i += (3 + (i *= 2))\n" + - " i" + - "}"); - } - - @Test public void testIntegerAssignOperations_06() throws Exception { - int i = 2; - assertIntegerAssignOperations(i *= (3 + (i += 2)), - "{\n" + - " var i = 2\n" + - " i *= (3 + (i += 2))\n" + - " i" + - "}"); - } - - @Test public void testIntegerAssignOperations_07() throws Exception { - int i = 10; - assertIntegerAssignOperations(i *= i %= i -= 2, - "{\n" + - " var i = 10\n" + - " i *= i %= i -= 2\n" + - " i" + - "}"); - } - - @Test public void testIntegerAssignOperations_08() throws Exception { - int i = 10; - assertIntegerAssignOperations(i *= i /= i -= 2, - "{\n" + - " var i = 10\n" + - " i *= i /= i -= 2\n" + - " i" + - "}"); - } - - @Test public void testBigIntegerBitOperations() throws Exception { - assertEvaluatesTo(new BigInteger("1").or(new BigInteger("2")).and(new BigInteger("3")).not(), - "1BI.or(2BI).and(3BI).not()"); - } - - @Test public void testBigIntegerArithmetics() throws Exception { - BigInteger x = new BigInteger("2"); - assertEvaluatesTo(x.negate().add(x.multiply(x).divide(x).mod(x)), - "{ val x=2BI; -x+x*x/x%x }"); - } - - @Test public void testDoubleArithmetics() throws Exception { - assertEvaluatesTo(-(2.+2.*2./2.), "-(2d+2d*2d/2d)"); - } - - @Test public void testBigDecimalArithmetics() throws Exception { - BigDecimal x = new BigDecimal("2"); - assertEvaluatesTo(x.negate().add(x.multiply(x).divide(x)), - "-2bd+2bd*2bd/2bd"); - } - - @Test public void testBigDecimalDivide() throws Exception { - BigDecimal x = new BigDecimal("1"); - BigDecimal y = new BigDecimal("3"); - assertEvaluatesTo(x.divide(y, MathContext.DECIMAL128), - "1BD/3BD"); - } - - @Test - public void testWithOperator() throws Exception { - assertEvaluatesTo("foobar", "(new StringBuilder => [ append('foo') it => [foo | foo.append('bar')] ]).toString"); - } - - @Test - public void testItAssignment() throws Exception { - assertEvaluatesTo(42l, "(new java.util.Date() => [ time = 42l ]).time"); - } - - @Test - public void testItAssignment_1() throws Exception { - assertEvaluatesTo(42l, "{val it = new java.util.Date(); time = 42l; time }"); - } - - @Test public void testIteratorExtensions() throws Exception { - assertEvaluatesTo("Foo", "newArrayList('Foo').iterator.toIterable.iterator.next"); - } - - @Test public void testExceptionInClosure_01() throws Exception { - assertEvaluatesWithException(IOException.class, - "{val ()=>void proc = [| throw new java.io.IOException()] proc.apply return null}"); - } - - @Test public void testExceptionInClosure_02() throws Exception { - assertEvaluatesWithException(IOException.class, - "{ newArrayList('foo').forEach( s | throw new java.io.IOException() ) return null }"); - } - - @Test public void testExceptionInClosure_03() throws Exception { - assertEvaluatesWithException(IOException.class, - "{val ()=>void proc = [| throw new java.io.IOException] proc.apply return null}"); - } - - @Test public void testExceptionInClosure_04() throws Exception { - assertEvaluatesWithException(IOException.class, - "{ newArrayList('foo').forEach( s | throw new java.io.IOException ) return null }"); - } - - @Test public void testTryCatch_07() throws Exception { - assertEvaluatesTo("", - "try new String() " + - " catch(java.io.IOException e) 'foo'" + - " catch(Exception e) 'bar'"); - } - - @Test public void testTryCatch_08() throws Exception { - assertEvaluatesTo("", - "try new String " + - " catch(java.io.IOException e) 'foo'" + - " catch(Exception e) 'bar'"); - } - - @Test public void testTryCatch_09() throws Exception { - assertEvaluatesTo("foo", - "try { 'foo' }" + - " catch(RuntimeException e) { e.printStackTrace() null }"); - } - - @Test - public void testListLiteral_0() throws Exception { - assertEvaluatesTo(newArrayList(), "#[]"); - } - - @Test - public void testListLiteral_1() throws Exception { - assertEvaluatesTo(newArrayList("Foo", "Bar"), "#['Foo', 'Bar']"); - } - - @Test - public void testListLiteral_2() throws Exception { - assertEvaluatesTo(newArrayList(1, "Foo", true), "#[1, 'Foo', true]"); - } - - @Test - public void testListLiteral_3() throws Exception { - assertEvaluatesToArray(new String[] {"Foo"}, "{ val String[] x = #['Foo'] x }"); - } - - @Test - // @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=403357 - public void testListLiteral_4() throws Exception { - assertEvaluatesTo(newArrayList((Object)null), "#[null]"); - } - - @Test - // @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=403357 - public void testListLiteral_5() throws Exception { - assertEvaluatesTo(newArrayList(null, ""), "#[null, '']"); - } - - @Test - public void testListLiteral_6() throws Exception { - assertEvaluatesTo("", "{ val char[] c = #[] String.valueOf(c) }"); - } - - @Test - public void testSetLiteral_0() throws Exception { - assertEvaluatesTo(newHashSet(), "#{}"); - } - - @Test - public void testSetLiteral_1() throws Exception { - assertEvaluatesTo(newHashSet("Foo", "Bar"), "#{'Foo', 'Bar'}"); - } - - @Test - public void testSetLiteral_2() throws Exception { - assertEvaluatesTo(newHashSet(1, "Foo", true), "#{1, 'Foo', true}"); - } - - @Test - public void testSetLiteral_3() throws Exception { - assertEvaluatesToArray(new String[] {"Foo"}, "{ val String[] x = #{'Foo'} x}"); - } - - @Test - // @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=403357 - public void testSetLiteral_4() throws Exception { - assertEvaluatesTo(newHashSet((Object) null), "#{null}"); - } - - @Test - // @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=403357 - public void testSetLiteral_5() throws Exception { - assertEvaluatesTo(newHashSet(null, ""), "#{null, ''}"); - } - - @SuppressWarnings("unchecked") - @Test - public void testSetLiteral_6() throws Exception { - assertEvaluatesTo(newHashSet(Pair.of("foo", "bar")), "{ val java.util.Set x = #{'foo' -> 'bar'} x }"); - } - - @Test - public void testMapLiteral_0() throws Exception { - assertEvaluatesTo(ImmutableMap.builder().put("foo", "bar").build(), "#{'foo' -> 'bar'}"); - } - - @Test - public void testMapLiteral_1() throws Exception { - assertEvaluatesTo(Collections.emptyMap(), "{val java.util.Map x = #{} x}"); - } - - @Test - public void testMapLiteral_2() throws Exception { - assertEvaluatesTo(ImmutableMap.builder().put("foo", 1).put("bar", true).build(), "#{'foo'->1, 'bar'->true}"); - } - - @Test - // @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=403357 - public void testMapLiteral_3() throws Exception { - HashMap map = newHashMap(); - map.put("foo", null); - assertEvaluatesTo(map, "#{'foo'->null}"); - } - - @Test - // @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=403357 - public void testMapLiteral_4() throws Exception { - HashMap map = newHashMap(); - map.put(null, "foo"); - assertEvaluatesTo(map, "#{null->'foo'}"); - } - - @Test - // @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=403357 - public void testMapLiteral_5() throws Exception { - HashMap map = newHashMap(); - map.put(null, null); - assertEvaluatesTo(map, "#{null->null}"); - } - - @Test - // @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=412642 - public void testMapLiteral_6() throws Exception { - HashMap map = newHashMap(); - map.put("Apple", Integer.valueOf(1)); - assertEvaluatesTo(map, "{\n" + - "val pair = 'Apple' -> 1\n" + - "#{pair}\n" + - "} "); - } - - @Test - // @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=412642 - public void testMapLiteral_7() throws Exception { - HashMap map = newHashMap(); - map.put("Apple", Integer.valueOf(1)); - assertEvaluatesTo(map, "{\n" + - "#{ if (true) 'Apple' -> 1 else 'Banana' -> 2 }" + - "} "); - } - - @Test - public void testIncrementOnByte() throws Exception { - byte i = 2; - i++; - assertEvaluatesTo(i, - "{\n" + - "var i = 2 as byte\n" + - "i++\n" + - "i" + - "}"); - } - - @Test - public void testIncrementOnByte_2() throws Exception { - byte i = 2; - assertEvaluatesTo(i++, - "{\n" + - "var i = 2 as byte\n" + - "i++\n" + - "}"); - } - - @Test - public void testIncrementOnByte_3() throws Exception { - byte i = 2; - assertEvaluatesTo(i++ + i, - "{\n" + - "var i = 2 as byte\n" + - "i++ + i\n" + - "}"); - } - - @Test - public void testIncrementOnByte_4() throws Exception { - byte i = 2; - assertEvaluatesTo(i++, - "{\n" + - "var Byte i = 2 as byte\n" + - "i++\n" + - "}"); - } - - @Test - public void testDecrementOnByte() throws Exception { - byte i = 2; - i--; - assertEvaluatesTo(i, - "{\n" + - "var i = 2 as byte\n" + - "i--\n" + - "i" + - "}"); - } - - @Test - public void testDecrementOnByte_2() throws Exception { - byte i = 2; - assertEvaluatesTo(i--, - "{\n" + - "var i = 2 as byte\n" + - "i--\n" + - "}"); - } - - @Test - public void testDecrementOnByte_3() throws Exception { - byte i = 2; - assertEvaluatesTo(i-- - i, - "{\n" + - "var i = 2 as byte\n" + - "i-- - i\n" + - "}"); - } - - @Test - public void testDecrementOnByte_4() throws Exception { - byte i = 2; - i--; - assertEvaluatesTo(i, - "{\n" + - "var Byte i = 2 as byte\n" + - "i--\n" + - "i" + - "}"); - } - - @Test - public void testIncrementOnCharacter() throws Exception { - char i = 2; - i++; - assertEvaluatesTo(i, - "{\n" + - "var i = 2 as char\n" + - "i++\n" + - "i" + - "}"); - } - - @Test - public void testIncrementOnCharacter_2() throws Exception { - char i = 2; - assertEvaluatesTo(i++, - "{\n" + - "var i = 2 as char\n" + - "i++\n" + - "}"); - } - - @Test - public void testIncrementOnCharacter_3() throws Exception { - char i = 2; - assertEvaluatesTo(i++ + i, - "{\n" + - "var i = 2 as char\n" + - "i++ + i\n" + - "}"); - } - - @Test - public void testIncrementOnCharacter_4() throws Exception { - char i = 2; - i++; - assertEvaluatesTo(i, - "{\n" + - "var Character i = 2 as char\n" + - "i++\n" + - "i" + - "}"); - } - - @Test - public void testDecrementOnCharacter() throws Exception { - char i = 2; - i--; - assertEvaluatesTo(i, - "{\n" + - "var i = 2 as char\n" + - "i--\n" + - "i" + - "}"); - } - - @Test - public void testDecrementOnCharacter_2() throws Exception { - char i = 2; - assertEvaluatesTo(i--, - "{\n" + - "var i = 2 as char\n" + - "i--\n" + - "}"); - } - - @Test - public void testDecrementOnCharacter_3() throws Exception { - char i = 2; - assertEvaluatesTo(i-- - i, - "{\n" + - "var i = 2 as char\n" + - "i-- - i\n" + - "}"); - } - - @Test - public void testDecrementOnCharacter_4() throws Exception { - char i = 2; - i--; - assertEvaluatesTo(i, - "{\n" + - "var Character i = 2 as char\n" + - "i--\n" + - "i" + - "}"); - } - - @Test - public void testIncrementOnShort() throws Exception { - short i = 2; - i++; - assertEvaluatesTo(i, - "{\n" + - "var i = 2 as short\n" + - "i++\n" + - "i" + - "}"); - } - - @Test - public void testIncrementOnShort_2() throws Exception { - short i = 2; - assertEvaluatesTo(i++, - "{\n" + - "var i = 2 as short\n" + - "i++\n" + - "}"); - } - - @Test - public void testIncrementOnShort_3() throws Exception { - short i = 2; - assertEvaluatesTo(i++ + i, - "{\n" + - "var i = 2 as short\n" + - "i++ + i\n" + - "}"); - } - - @Test - public void testIncrementOnShort_4() throws Exception { - short i = 2; - i++; - assertEvaluatesTo(i, - "{\n" + - "var Short i = 2 as short\n" + - "i++\n" + - "i" + - "}"); - } - - @Test - public void testDecrementOnShort() throws Exception { - short i = 2; - i--; - assertEvaluatesTo(i, - "{\n" + - "var i = 2 as short\n" + - "i--\n" + - "i" + - "}"); - } - - @Test - public void testDecrementOnShort_2() throws Exception { - short i = 2; - assertEvaluatesTo(i--, - "{\n" + - "var i = 2 as short\n" + - "i--\n" + - "}"); - } - - @Test - public void testDecrementOnShort_3() throws Exception { - short i = 2; - assertEvaluatesTo(i-- - i, - "{\n" + - "var i = 2 as short\n" + - "i-- - i\n" + - "}"); - } - - @Test - public void testDecrementOnShort_4() throws Exception { - short i = 2; - i--; - assertEvaluatesTo(i, - "{\n" + - "var Short i = 2 as short\n" + - "i--\n" + - "i" + - "}"); - } - - @Test - public void testIncrementOnInteger() throws Exception { - int i = 2; - i++; - assertEvaluatesTo(i, - "{\n" + - "var i = 2\n" + - "i++\n" + - "i" + - "}"); - } - - @Test - public void testIncrementOnInteger_2() throws Exception { - int i = 2; - assertEvaluatesTo(i++, - "{\n" + - "var i = 2\n" + - "i++\n" + - "}"); - } - - @Test - public void testIncrementOnInteger_3() throws Exception { - int i = 2; - assertEvaluatesTo(i++ + i, - "{\n" + - "var i = 2\n" + - "i++ + i\n" + - "}"); - } - - @Test - public void testIncrementOnInteger_4() throws Exception { - int i = 2; - i++; - assertEvaluatesTo(i, - "{\n" + - "var Integer i = 2\n" + - "i++\n" + - "i" + - "}"); - } - - @Test - public void testDecrementOnInteger() throws Exception { - int i = 2; - i--; - assertEvaluatesTo(i, - "{\n" + - "var i = 2\n" + - "i--\n" + - "i" + - "}"); - } - - @Test - public void testDecrementOnInteger_2() throws Exception { - int i = 2; - assertEvaluatesTo(i--, - "{\n" + - "var i = 2\n" + - "i--\n" + - "}"); - } - - @Test - public void testDecrementOnInteger_3() throws Exception { - int i = 2; - assertEvaluatesTo(i-- - i, - "{\n" + - "var i = 2\n" + - "i-- - i\n" + - "}"); - } - - @Test - public void testDecrementOnInteger_4() throws Exception { - int i = 2; - i--; - assertEvaluatesTo(i, - "{\n" + - "var Integer i = 2\n" + - "i--\n" + - "i" + - "}"); - } - - @Test - public void testIncrementOnLong() throws Exception { - long i = 2; - i++; - assertEvaluatesTo(i, - "{\n" + - "var i = 2 as long\n" + - "i++\n" + - "i" + - "}"); - } - - @Test - public void testIncrementOnLong_2() throws Exception { - long i = 2; - assertEvaluatesTo(i++, - "{\n" + - "var i = 2 as long\n" + - "i++\n" + - "}"); - } - - @Test - public void testIncrementOnLong_3() throws Exception { - long i = 2; - assertEvaluatesTo(i++ + i, - "{\n" + - "var i = 2 as long\n" + - "i++ + i\n" + - "}"); - } - - @Test - public void testIncrementOnLong_4() throws Exception { - long i = 2; - i++; - assertEvaluatesTo(i, - "{\n" + - "var Long i = 2 as long\n" + - "i++\n" + - "i" + - "}"); - } - - @Test - public void testDecrementOnLong() throws Exception { - long i = 2; - i--; - assertEvaluatesTo(i, - "{\n" + - "var i = 2 as long\n" + - "i--\n" + - "i" + - "}"); - } - - @Test - public void testDecrementOnLong_2() throws Exception { - long i = 2; - assertEvaluatesTo(i--, - "{\n" + - "var i = 2 as long\n" + - "i--\n" + - "}"); - } - - @Test - public void testDecrementOnLong_3() throws Exception { - long i = 2; - assertEvaluatesTo(i-- - i, - "{\n" + - "var i = 2 as long\n" + - "i-- - i\n" + - "}"); - } - - @Test - public void testDecrementOnLong_4() throws Exception { - long i = 2; - i--; - assertEvaluatesTo(i, - "{\n" + - "var Long i = 2 as long\n" + - "i--\n" + - "i" + - "}"); - } - - @Test - public void testIncrementOnFloat() throws Exception { - float i = 2; - i++; - assertEvaluatesTo(i, - "{\n" + - "var i = 2 as float\n" + - "i++\n" + - "i" + - "}"); - } - - @Test - public void testIncrementOnFloat_2() throws Exception { - float i = 2; - assertEvaluatesTo(i++, - "{\n" + - "var i = 2 as float\n" + - "i++\n" + - "}"); - } - - @Test - public void testIncrementOnFloat_3() throws Exception { - float i = 2; - assertEvaluatesTo(i++ + i, - "{\n" + - "var i = 2 as float\n" + - "i++ + i\n" + - "}"); - } - - @Test - public void testIncrementOnFloat_4() throws Exception { - float i = 2; - i++; - assertEvaluatesTo(i, - "{\n" + - "var Float i = 2 as float\n" + - "i++\n" + - "i" + - "}"); - } - - @Test - public void testDecrementOnFloat() throws Exception { - float i = 2; - i--; - assertEvaluatesTo(i, - "{\n" + - "var i = 2 as float\n" + - "i--\n" + - "i" + - "}"); - } - - @Test - public void testDecrementOnFloat_2() throws Exception { - float i = 2; - assertEvaluatesTo(i--, - "{\n" + - "var i = 2 as float\n" + - "i--\n" + - "}"); - } - - @Test - public void testDecrementOnFloat_3() throws Exception { - float i = 2; - assertEvaluatesTo(i-- - i, - "{\n" + - "var i = 2 as float\n" + - "i-- - i\n" + - "}"); - } - - @Test - public void testDecrementOnFloat_4() throws Exception { - float i = 2; - i--; - assertEvaluatesTo(i, - "{\n" + - "var Float i = 2 as float\n" + - "i--\n" + - "i" + - "}"); - } - - @Test - public void testIncrementOnDouble() throws Exception { - double i = 2; - i++; - assertEvaluatesTo(i, - "{\n" + - "var i = 2 as double\n" + - "i++\n" + - "i" + - "}"); - } - - @Test - public void testIncrementOnDouble_2() throws Exception { - double i = 2; - assertEvaluatesTo(i++, - "{\n" + - "var i = 2 as double\n" + - "i++\n" + - "}"); - } - - @Test - public void testIncrementOnDouble_3() throws Exception { - double i = 2; - assertEvaluatesTo(i++ + i, - "{\n" + - "var i = 2 as double\n" + - "i++ + i\n" + - "}"); - } - - @Test - public void testIncrementOnDouble_4() throws Exception { - double i = 2; - i++; - assertEvaluatesTo(i, - "{\n" + - "var Double i = 2 as double\n" + - "i++\n" + - "i" + - "}"); - } - - @Test - public void testDecrementOnDouble() throws Exception { - double i = 2; - i--; - assertEvaluatesTo(i, - "{\n" + - "var i = 2 as double\n" + - "i--\n" + - "i" + - "}"); - } - - @Test - public void testDecrementOnDouble_2() throws Exception { - double i = 2; - assertEvaluatesTo(i--, - "{\n" + - "var i = 2 as double\n" + - "i--\n" + - "}"); - } - - @Test - public void testDecrementOnDouble_3() throws Exception { - double i = 2; - assertEvaluatesTo(i-- - i, - "{\n" + - "var i = 2 as double\n" + - "i-- - i\n" + - "}"); - } - - @Test - public void testDecrementOnDouble_4() throws Exception { - double i = 2; - i--; - assertEvaluatesTo(i, - "{\n" + - "var Double i = 2 as double\n" + - "i--\n" + - "i" + - "}"); - } - - @Test - public void testBug466974_01() throws Exception { - int i = 0; - int a = i = i + 1; - int b = i == 1 ? 1 : 2; - int result = Math.max(a, b); - assertEvaluatesTo(result, - "{\n" + - "var i = 0\n" + - "val result = Math.max(i = i + 1, if (i == 1) { 1 } else { 2 })\n" + - "result" + - "}"); - } - - @Test - public void testBug466974_02() throws Exception { - int i = 0; - Integer a = i = i + 1; - Integer b = i == 1 ? 1 : 2; - int result = a.compareTo(b); - assertEvaluatesTo(result, - "{\n" + - "var i = 0\n" + - "val result = {i = i + 1}.compareTo(if (i == 1) { 1 } else { 2 })\n" + - "result" + - "}"); - } - - @Test - public void testBug466974_03() throws Exception { - int i = 0; - Integer a = i = i + 1; - Integer b = i == 1 ? i = i + 1 : -1; - int result = Math.max(a, b); - assertEvaluatesTo(result, - "{\n" + - "var i = 0\n" + - "val result = Math.max({i = i + 1}, if (i == 1) { i = i + 1 } else { -1 })\n" + - "result" + - "}"); - } - - @Test - public void testBug466974_04() throws Exception { - int i = 0; - boolean a = (i = i + 1) == 1; - boolean b = false; - if (i == 1) { - b = true; - } - boolean result = a && b; - assertEvaluatesTo(result, - "{\n" + - "var i = 0\n" + - "val result = (i = i + 1) == 1 && if(i == 1) true else false\n" + - "result" + - "}"); - } - - @Test - public void testBug466974_05() throws Exception { - int i = 0; - boolean a = (i = i + 1) != 1; - boolean b = false; - if (i == 1) { - b = true; - } - boolean result = a || b; - assertEvaluatesTo(result, - "{\n" + - "var i = 0\n" + - "val result = (i = i + 1) != 1 || if(i == 1) true else false\n" + - "result" + - "}"); - } - - protected void assertEvaluatesTo(Object object, String string) throws Exception { - Object result = invokeXbaseExpression(string); - assertEquals(object, result); - } - - protected void assertEvaluatesToArray(Object[] object, String string) throws Exception { - Object result = invokeXbaseExpression(string); - assertTrue(result.getClass().isArray()); - assertArrayEquals(object, (Object[])result); - } - - protected void assertEvaluatesWithException(Class class1, String string) throws Exception { - try { - invokeXbaseExpression(string); - } catch (InvocationTargetException e) { - assertTrue(e.getClass().toString(), class1.isInstance(e.getCause())); - } - } - - @Test - public void testNullSaveLazyEvaluation1() throws Exception { - assertEvaluatesTo(0, "{ var x = 0; (null as String)?.substring(x = 1); return x; }"); - } - - @Test - public void testNullSaveLazyEvaluation2() throws Exception { - assertEvaluatesTo(0, "{ val x = newArrayList; var c = [|x += 'x';1]; (null as String)?.substring(c.apply); return x.size; }"); - } - - /** - * @param expression the input that should be executed - */ - protected Object invokeXbaseExpression(String expression) throws Exception { - throw new UnsupportedOperationException("Override and implement me!"); - } -} diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/AnnotationCompilerTest.xtend b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/AnnotationCompilerTest.xtend index ff9f3b761ba..320cc913f08 100644 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/AnnotationCompilerTest.xtend +++ b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/AnnotationCompilerTest.xtend @@ -239,7 +239,7 @@ class AnnotationCompilerTest extends AbstractXtendCompilerTest { */ package foo - annotation bar { + annotation MyAnnotation { String name = 'foobar' } ''', @@ -255,7 +255,7 @@ class AnnotationCompilerTest extends AbstractXtendCompilerTest { package foo; @SuppressWarnings("all") - public @interface bar { + public @interface MyAnnotation { public String name() default "foobar"; } ''') @@ -414,11 +414,13 @@ class AnnotationCompilerTest extends AbstractXtendCompilerTest { public interface MyIf extends MyAnno { } public static class MyClass implements MyAnno.MyIf { + @Override public Class annotationType() { return null; } } public static class MyClass2 implements MyAnno { + @Override public Class annotationType() { return null; } diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/AnonymousClassCompilerTest.xtend b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/AnonymousClassCompilerTest.xtend index a08967fcf23..5da86289cb7 100644 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/AnonymousClassCompilerTest.xtend +++ b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/AnonymousClassCompilerTest.xtend @@ -30,6 +30,7 @@ class AnonymousClassCompilerTest extends AbstractXtendCompilerTest { public class C { public Runnable m() { return new Runnable() { + @Override public void run() { } }; @@ -72,6 +73,7 @@ class AnonymousClassCompilerTest extends AbstractXtendCompilerTest { public Runnable getRunnable() { return new Runnable() { + @Override public void run() { Test.this._util.sayHello(); } @@ -116,6 +118,7 @@ class AnonymousClassCompilerTest extends AbstractXtendCompilerTest { @Extension final Test.Util u = null; _xblockexpression = new Runnable() { + @Override public void run() { u.sayHello(); } @@ -157,6 +160,7 @@ class AnonymousClassCompilerTest extends AbstractXtendCompilerTest { { final Test.Util it = null; _xblockexpression = new __Test_1() { + @Override public void run() { this.sayHello(it); } @@ -206,6 +210,7 @@ class AnonymousClassCompilerTest extends AbstractXtendCompilerTest { { final String it = null; _xblockexpression = new Runnable() { + @Override public void run() { Test.this._util.sayHello(it); } @@ -242,6 +247,7 @@ class AnonymousClassCompilerTest extends AbstractXtendCompilerTest { { final String it = null; _xblockexpression = new Runnable() { + @Override public void run() { Util.sayHello(it); } @@ -278,6 +284,7 @@ class AnonymousClassCompilerTest extends AbstractXtendCompilerTest { { final String it = null; _xblockexpression = new Runnable() { + @Override public void run() { Util.sayHello(this); } @@ -314,6 +321,7 @@ class AnonymousClassCompilerTest extends AbstractXtendCompilerTest { { final String it = null; _xblockexpression = new Runnable() { + @Override public void run() { Util.sayHello(Test.this); } @@ -356,6 +364,7 @@ class AnonymousClassCompilerTest extends AbstractXtendCompilerTest { public Runnable getRunnable() { return new Runnable() { + @Override public void run() { Test.this.u.sayHello(this); } @@ -400,6 +409,7 @@ class AnonymousClassCompilerTest extends AbstractXtendCompilerTest { public Runnable getRunnable() { return new Runnable() { + @Override public void run() { Test.this.u.sayHello(Test.this); } @@ -440,6 +450,7 @@ class AnonymousClassCompilerTest extends AbstractXtendCompilerTest { public Runnable getRunnable() { return new Runnable() { + @Override public void run() { Test.this.u.sayHello(Test.this); } @@ -466,6 +477,7 @@ class AnonymousClassCompilerTest extends AbstractXtendCompilerTest { @SuppressWarnings("all") public class Bar { private final Runnable r = new Runnable() { + @Override public void run() { InputOutput.println(Integer.valueOf(Bar.this.x)); } @@ -535,6 +547,7 @@ class AnonymousClassCompilerTest extends AbstractXtendCompilerTest { return null; } + @Override public String toString() { return ""; } @@ -662,10 +675,12 @@ class AnonymousClassCompilerTest extends AbstractXtendCompilerTest { public class C { public void m() { new Runnable() { + @Override public void run() { } }; new Runnable() { + @Override public void run() { } }; @@ -702,6 +717,7 @@ class AnonymousClassCompilerTest extends AbstractXtendCompilerTest { } new __C_1() { + @Override public void run() { } @@ -709,6 +725,7 @@ class AnonymousClassCompilerTest extends AbstractXtendCompilerTest { } }; new __C_2() { + @Override public void run() { } @@ -811,6 +828,7 @@ class AnonymousClassCompilerTest extends AbstractXtendCompilerTest { public class C { public ArrayList m() { return CollectionLiterals.newArrayList(new Runnable() { + @Override public void run() { } }); @@ -834,6 +852,7 @@ class AnonymousClassCompilerTest extends AbstractXtendCompilerTest { public class C { public Iterable m() { return CollectionLiterals.newArrayList(new Runnable() { + @Override public void run() { } }); @@ -864,6 +883,7 @@ class AnonymousClassCompilerTest extends AbstractXtendCompilerTest { } __C_1 ___C_1 = new __C_1() { + @Override public void run() { } @@ -903,6 +923,7 @@ class AnonymousClassCompilerTest extends AbstractXtendCompilerTest { } __C_1 ___C_1 = new __C_1() { + @Override public void run() { } @@ -910,6 +931,7 @@ class AnonymousClassCompilerTest extends AbstractXtendCompilerTest { } }; __C_2 ___C_2 = new __C_2() { + @Override public void run() { } @@ -942,6 +964,7 @@ class AnonymousClassCompilerTest extends AbstractXtendCompilerTest { } __C_1 ___C_1 = new __C_1() { + @Override public void run() { } @@ -971,6 +994,7 @@ class AnonymousClassCompilerTest extends AbstractXtendCompilerTest { public void foo() { final String x = ""; final Runnable bar = new Runnable() { + @Override public void run() { x.toString(); } @@ -1002,6 +1026,7 @@ class AnonymousClassCompilerTest extends AbstractXtendCompilerTest { String x = ""; final __Foo_1 bar = new __Foo_1() { + @Override public void run() { this.x.toString(); } @@ -1033,6 +1058,7 @@ class AnonymousClassCompilerTest extends AbstractXtendCompilerTest { final String x = ""; final __Foo_1 bar = new __Foo_1() { + @Override public void run() { this.x.toString(); } @@ -1075,8 +1101,10 @@ class AnonymousClassCompilerTest extends AbstractXtendCompilerTest { final String x = ""; final __Foo_1 bar = new __Foo_1() { + @Override public void run() { new Object() { + @Override public String toString() { return _this__Foo_1.x; } @@ -1118,9 +1146,11 @@ class AnonymousClassCompilerTest extends AbstractXtendCompilerTest { } final __Foo_1 bar = new __Foo_1() { + @Override public void run() { final String x = ""; new Object() { + @Override public String toString() { return x; } @@ -1154,6 +1184,7 @@ class AnonymousClassCompilerTest extends AbstractXtendCompilerTest { } final __Foo_1 bar = new __Foo_1() { + @Override public void run() { this.x.toString(); } @@ -1189,6 +1220,7 @@ class AnonymousClassCompilerTest extends AbstractXtendCompilerTest { } final __Foo_1 bar = new __Foo_1() { + @Override public void run() { } @@ -1221,6 +1253,7 @@ class AnonymousClassCompilerTest extends AbstractXtendCompilerTest { public Object m(final String x) { return new Object() { + @Override public String toString() { return x.substring(1); } @@ -1264,6 +1297,7 @@ class AnonymousClassCompilerTest extends AbstractXtendCompilerTest { { String name = null; __Foo_1 ___Foo_1 = new __Foo_1() { + @Override public String apply() { return this.name; } @@ -1304,6 +1338,7 @@ class AnonymousClassCompilerTest extends AbstractXtendCompilerTest { Runnable _xifexpression = null; if ((x instanceof Appendable)) { _xifexpression = new Runnable() { + @Override public void run() { try { ((Appendable)x).append("hello"); @@ -1341,6 +1376,7 @@ class AnonymousClassCompilerTest extends AbstractXtendCompilerTest { Runnable _xifexpression = null; if ((x instanceof Appendable)) { _xifexpression = new Runnable() { + @Override public void run() { try { ((Appendable)x).append("hello"); @@ -1371,6 +1407,7 @@ class AnonymousClassCompilerTest extends AbstractXtendCompilerTest { public class Foo { public void foo() { final Runnable bar = new Runnable() { + @Override public void run() { } }; @@ -1401,6 +1438,7 @@ class AnonymousClassCompilerTest extends AbstractXtendCompilerTest { public class C { public AbstractMap newMap() { return new AbstractMap() { + @Override public Set> entrySet() { return CollectionLiterals.>newHashSet(); } @@ -1432,6 +1470,7 @@ class AnonymousClassCompilerTest extends AbstractXtendCompilerTest { public class C { public AbstractMap newMap() { return new AbstractMap() { + @Override public Set> entrySet() { return CollectionLiterals.>newHashSet(); } @@ -1465,6 +1504,7 @@ class AnonymousClassCompilerTest extends AbstractXtendCompilerTest { public class C { public AbstractMap newMap() { return new AbstractMap() { + @Override public Set> entrySet() { Set> _xblockexpression = null; { @@ -1632,12 +1672,14 @@ class AnonymousClassCompilerTest extends AbstractXtendCompilerTest { public class C extends B { public D myMethod() { return new D() { + @Override public void m() { super.m(); } }; } + @Override public void m() { } } @@ -1665,12 +1707,14 @@ class AnonymousClassCompilerTest extends AbstractXtendCompilerTest { public class C extends B { public D myMethod() { return new D() { + @Override public void m() { C.super.m(); } }; } + @Override public void m() { } } @@ -1697,6 +1741,7 @@ class AnonymousClassCompilerTest extends AbstractXtendCompilerTest { } final __Foo_1 bar = new __Foo_1() { + @Override public void run() { } }; @@ -1725,6 +1770,7 @@ class AnonymousClassCompilerTest extends AbstractXtendCompilerTest { } return new __Foo_1() { + @Override public void run() { } }; @@ -1750,6 +1796,7 @@ class AnonymousClassCompilerTest extends AbstractXtendCompilerTest { public class Foo { public void foo() { final Object[] bar = new Object[] { new Runnable() { + @Override public void run() { } } }; @@ -1779,6 +1826,7 @@ class AnonymousClassCompilerTest extends AbstractXtendCompilerTest { public class Foo { public void foo() { final List bar = Collections.unmodifiableList(CollectionLiterals.newArrayList(new Runnable() { + @Override public void run() { } })); @@ -1799,6 +1847,7 @@ class AnonymousClassCompilerTest extends AbstractXtendCompilerTest { @SuppressWarnings("all") public class Foo { private final Runnable bar = new Runnable() { + @Override public void run() { } }; @@ -1821,12 +1870,14 @@ class AnonymousClassCompilerTest extends AbstractXtendCompilerTest { @SuppressWarnings("all") public class Foo { private final Runnable bar = new Function0() { + @Override public Runnable apply() { abstract class __Foo_1 implements Runnable { int baz; } __Foo_1 ___Foo_1 = new __Foo_1() { + @Override public void run() { } }; @@ -1856,6 +1907,7 @@ class AnonymousClassCompilerTest extends AbstractXtendCompilerTest { private final int secondOuterField = 1; private final Object outerField = new Function0() { + @Override public Object apply() { abstract class __C_1 { int localField; @@ -1863,10 +1915,8 @@ class AnonymousClassCompilerTest extends AbstractXtendCompilerTest { __C_1 ___C_1 = new __C_1() { }; - final Procedure1<__C_1> _function = new Procedure1<__C_1>() { - public void apply(final __C_1 it) { - it.localField = C.this.secondOuterField; - } + final Procedure1<__C_1> _function = (__C_1 it) -> { + it.localField = C.this.secondOuterField; }; __C_1 _doubleArrow = ObjectExtensions.<__C_1>operator_doubleArrow(___C_1, _function); return _doubleArrow; @@ -1906,6 +1956,7 @@ class AnonymousClassCompilerTest extends AbstractXtendCompilerTest { { s2 = s1; } + @Override public void run() { this.s2.toString(); } @@ -1954,6 +2005,7 @@ class AnonymousClassCompilerTest extends AbstractXtendCompilerTest { final __C_1 r = new __C_1() { { idx = new Function0() { + @Override public Integer apply() { int _xtrycatchfinallyexpression = (int) 0; try { @@ -1969,6 +2021,7 @@ class AnonymousClassCompilerTest extends AbstractXtendCompilerTest { } }.apply().intValue(); } + @Override public void run() { Integer.valueOf(this.idx).toString(); } @@ -2004,10 +2057,8 @@ class AnonymousClassCompilerTest extends AbstractXtendCompilerTest { __C_1 ___C_1 = new __C_1() { }; - final Procedure1<__C_1> _function = new Procedure1<__C_1>() { - public void apply(final __C_1 it) { - it.f = 1; - } + final Procedure1<__C_1> _function = (__C_1 it) -> { + it.f = 1; }; return ObjectExtensions.<__C_1>operator_doubleArrow(___C_1, _function); } @@ -2034,6 +2085,7 @@ class AnonymousClassCompilerTest extends AbstractXtendCompilerTest { public class Foo { public void foo() { final Iterable bar = new Iterable() { + @Override public Iterator iterator() { return null; } @@ -2062,6 +2114,7 @@ class AnonymousClassCompilerTest extends AbstractXtendCompilerTest { public class Foo { public void foo() { final Iterable bar = new Iterable() { + @Override public Iterator iterator() { return null; } @@ -2092,6 +2145,7 @@ class AnonymousClassCompilerTest extends AbstractXtendCompilerTest { public class Foo { public void foo() { final Iterable bar = new Iterable() { + @Override public Iterator iterator() { return null; } @@ -2122,6 +2176,7 @@ class AnonymousClassCompilerTest extends AbstractXtendCompilerTest { public class Foo { public void foo() { final Bar bar = new Bar() { + @Override public T bar(final U it) { return null; } @@ -2152,6 +2207,7 @@ class AnonymousClassCompilerTest extends AbstractXtendCompilerTest { public class Foo { public void foo() { final Bar bar = new Bar() { + @Override public U bar(final T it) { return null; } @@ -2227,6 +2283,7 @@ class AnonymousClassCompilerTest extends AbstractXtendCompilerTest { return null; } + @Override public Set> entrySet() { return null; } @@ -2262,6 +2319,7 @@ class AnonymousClassCompilerTest extends AbstractXtendCompilerTest { public > void foo() { final Foo.Bar bar = new Foo.Bar() { + @Override public W bar() { return null; } @@ -2373,8 +2431,10 @@ class AnonymousClassCompilerTest extends AbstractXtendCompilerTest { public class MyXtendClass { public void bar() { new Visibilities() { + @Override public void publicMethod() { new Thread() { + @Override public void run() { protectedMethod(); } @@ -2416,10 +2476,12 @@ class AnonymousClassCompilerTest extends AbstractXtendCompilerTest { public class InstanceTest { public void doSomething() { MyConfiguration config = new MyConfiguration() { + @Override public Class annotationType() { return null; } + @Override public String name() { return null; } @@ -2459,11 +2521,9 @@ class AnonymousClassCompilerTest extends AbstractXtendCompilerTest { _elvis = _head; } else { AdapterImpl _adapterImpl = new AdapterImpl(); - final Procedure1 _function = new Procedure1() { - public void apply(final AdapterImpl it_1) { - EList _eAdapters = it.eAdapters(); - _eAdapters.add(it_1); - } + final Procedure1 _function = (AdapterImpl it_1) -> { + EList _eAdapters = it.eAdapters(); + _eAdapters.add(it_1); }; AdapterImpl _doubleArrow = ObjectExtensions.operator_doubleArrow(_adapterImpl, _function); _elvis = _doubleArrow; diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug1005Test.xtend b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug1005Test.xtend index b70facd7b1e..7e78ed05405 100644 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug1005Test.xtend +++ b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug1005Test.xtend @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2023 Sebastian Zarnekow and others. + * Copyright (c) 2023, 2024 Sebastian Zarnekow and others. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. @@ -59,10 +59,8 @@ class CompilerBug1005Test extends AbstractXtendCompilerTest { public class Outer { public static class C { public Outer.B m(final Outer.B it) { - final Consumer> _function = new Consumer>() { - public void accept(final Outer.B it_1) { - it_1.c(7); - } + final Consumer> _function = (Outer.B it_1) -> { + it_1.c(7); }; return it.child(Outer.E1.F, _function); } diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug342021Test.xtend b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug342021Test.xtend index 1f2565fc572..29b3628acc2 100644 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug342021Test.xtend +++ b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug342021Test.xtend @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2013, 2018 itemis AG (http://www.itemis.eu) and others. + * Copyright (c) 2013, 2024 itemis AG (http://www.itemis.eu) and others. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. @@ -27,7 +27,6 @@ class CompilerBug342021Test extends AbstractXtendCompilerTest { } } ''', ''' - import java.util.Iterator; import org.eclipse.xtext.xbase.lib.CollectionLiterals; import org.eclipse.xtext.xbase.lib.Conversions; @@ -36,10 +35,8 @@ class CompilerBug342021Test extends AbstractXtendCompilerTest { public Iterable m(final String s) { Iterable _xifexpression = null; if (true) { - final Iterable _function = new Iterable() { - public Iterator iterator() { - return CollectionLiterals.newArrayList().iterator(); - } + final Iterable _function = () -> { + return CollectionLiterals.newArrayList().iterator(); }; _xifexpression = _function; } else { @@ -63,7 +60,6 @@ class CompilerBug342021Test extends AbstractXtendCompilerTest { } } ''', ''' - import java.util.Iterator; import org.eclipse.xtext.xbase.lib.CollectionLiterals; import org.eclipse.xtext.xbase.lib.Conversions; @@ -72,10 +68,8 @@ class CompilerBug342021Test extends AbstractXtendCompilerTest { public Iterable m() { Iterable _xifexpression = null; if (true) { - final Iterable _function = new Iterable() { - public Iterator iterator() { - return CollectionLiterals.newArrayList().iterator(); - } + final Iterable _function = () -> { + return CollectionLiterals.newArrayList().iterator(); }; _xifexpression = _function; } else { @@ -98,7 +92,6 @@ class CompilerBug342021Test extends AbstractXtendCompilerTest { } } ''', ''' - import java.util.Iterator; import org.eclipse.xtext.xbase.lib.CollectionLiterals; import org.eclipse.xtext.xbase.lib.Conversions; @@ -106,10 +99,8 @@ class CompilerBug342021Test extends AbstractXtendCompilerTest { public class C { public Iterable m() { if (true) { - final Iterable _function = new Iterable() { - public Iterator iterator() { - return CollectionLiterals.newArrayList().iterator(); - } + final Iterable _function = () -> { + return CollectionLiterals.newArrayList().iterator(); }; return _function; } else { @@ -131,7 +122,6 @@ class CompilerBug342021Test extends AbstractXtendCompilerTest { } } ''', ''' - import java.util.Iterator; import org.eclipse.xtext.xbase.lib.CollectionLiterals; import org.eclipse.xtext.xbase.lib.Conversions; @@ -140,10 +130,8 @@ class CompilerBug342021Test extends AbstractXtendCompilerTest { public Iterable m() { Object[] _xifexpression = null; if (true) { - final Iterable _function = new Iterable() { - public Iterator iterator() { - return CollectionLiterals.newArrayList().iterator(); - } + final Iterable _function = () -> { + return CollectionLiterals.newArrayList().iterator(); }; return _function; } else { @@ -166,7 +154,6 @@ class CompilerBug342021Test extends AbstractXtendCompilerTest { } } ''', ''' - import java.util.Iterator; import org.eclipse.xtext.xbase.lib.CollectionLiterals; import org.eclipse.xtext.xbase.lib.Conversions; @@ -175,10 +162,8 @@ class CompilerBug342021Test extends AbstractXtendCompilerTest { public Iterable m() { Iterable _xifexpression = null; if (true) { - final Iterable _function = new Iterable() { - public Iterator iterator() { - return CollectionLiterals.newArrayList().iterator(); - } + final Iterable _function = () -> { + return CollectionLiterals.newArrayList().iterator(); }; _xifexpression = _function; } else { @@ -202,7 +187,6 @@ class CompilerBug342021Test extends AbstractXtendCompilerTest { } } ''', ''' - import java.util.Iterator; import org.eclipse.xtext.xbase.lib.CollectionLiterals; import org.eclipse.xtext.xbase.lib.Conversions; @@ -211,10 +195,8 @@ class CompilerBug342021Test extends AbstractXtendCompilerTest { public Iterable m(final String s) { Iterable _xifexpression = null; if (true) { - final Iterable _function = new Iterable() { - public Iterator iterator() { - return CollectionLiterals.newArrayList().iterator(); - } + final Iterable _function = () -> { + return CollectionLiterals.newArrayList().iterator(); }; _xifexpression = _function; } else { @@ -239,7 +221,6 @@ class CompilerBug342021Test extends AbstractXtendCompilerTest { } } ''', ''' - import java.util.Iterator; import org.eclipse.xtext.xbase.lib.CollectionLiterals; import org.eclipse.xtext.xbase.lib.Conversions; @@ -248,10 +229,8 @@ class CompilerBug342021Test extends AbstractXtendCompilerTest { public Iterable m() { Iterable _xifexpression = null; if (true) { - final Iterable _function = new Iterable() { - public Iterator iterator() { - return CollectionLiterals.newArrayList().iterator(); - } + final Iterable _function = () -> { + return CollectionLiterals.newArrayList().iterator(); }; _xifexpression = _function; } else { @@ -276,7 +255,6 @@ class CompilerBug342021Test extends AbstractXtendCompilerTest { } } ''', ''' - import java.util.Iterator; import org.eclipse.xtext.xbase.lib.CollectionLiterals; import org.eclipse.xtext.xbase.lib.Conversions; @@ -284,10 +262,8 @@ class CompilerBug342021Test extends AbstractXtendCompilerTest { public class C { public Iterable m() { if (true) { - final Iterable _function = new Iterable() { - public Iterator iterator() { - return CollectionLiterals.newArrayList().iterator(); - } + final Iterable _function = () -> { + return CollectionLiterals.newArrayList().iterator(); }; return _function; } else { @@ -309,7 +285,6 @@ class CompilerBug342021Test extends AbstractXtendCompilerTest { } } ''', ''' - import java.util.Iterator; import org.eclipse.xtext.xbase.lib.CollectionLiterals; import org.eclipse.xtext.xbase.lib.Conversions; @@ -318,10 +293,8 @@ class CompilerBug342021Test extends AbstractXtendCompilerTest { public Iterable m() { Object[] _xifexpression = null; if (true) { - final Iterable _function = new Iterable() { - public Iterator iterator() { - return CollectionLiterals.newArrayList().iterator(); - } + final Iterable _function = () -> { + return CollectionLiterals.newArrayList().iterator(); }; return _function; } else { @@ -344,7 +317,6 @@ class CompilerBug342021Test extends AbstractXtendCompilerTest { } } ''', ''' - import java.util.Iterator; import org.eclipse.xtext.xbase.lib.CollectionLiterals; import org.eclipse.xtext.xbase.lib.Conversions; @@ -353,10 +325,8 @@ class CompilerBug342021Test extends AbstractXtendCompilerTest { public Iterable m() { Iterable _xifexpression = null; if (true) { - final Iterable _function = new Iterable() { - public Iterator iterator() { - return CollectionLiterals.newArrayList().iterator(); - } + final Iterable _function = () -> { + return CollectionLiterals.newArrayList().iterator(); }; _xifexpression = _function; } else { @@ -384,7 +354,6 @@ class CompilerBug342021Test extends AbstractXtendCompilerTest { } } ''', ''' - import java.util.Iterator; import org.eclipse.xtext.xbase.lib.CollectionLiterals; import org.eclipse.xtext.xbase.lib.Conversions; @@ -399,10 +368,8 @@ class CompilerBug342021Test extends AbstractXtendCompilerTest { Iterable _xblockexpression_1 = null; { this.toString(); - final Iterable _function = new Iterable() { - public Iterator iterator() { - return CollectionLiterals.newArrayList().iterator(); - } + final Iterable _function = () -> { + return CollectionLiterals.newArrayList().iterator(); }; _xblockexpression_1 = _function; } @@ -441,7 +408,6 @@ class CompilerBug342021Test extends AbstractXtendCompilerTest { } } ''', ''' - import java.util.Iterator; import org.eclipse.xtext.xbase.lib.CollectionLiterals; import org.eclipse.xtext.xbase.lib.Conversions; @@ -457,10 +423,8 @@ class CompilerBug342021Test extends AbstractXtendCompilerTest { Iterable _xblockexpression_1 = null; { this.toString(); - final Iterable _function = new Iterable() { - public Iterator iterator() { - return CollectionLiterals.newArrayList().iterator(); - } + final Iterable _function = () -> { + return CollectionLiterals.newArrayList().iterator(); }; _xblockexpression_1 = _function; } @@ -496,7 +460,6 @@ class CompilerBug342021Test extends AbstractXtendCompilerTest { } } ''', ''' - import java.util.Iterator; import org.eclipse.xtext.xbase.lib.CollectionLiterals; import org.eclipse.xtext.xbase.lib.Conversions; @@ -506,10 +469,8 @@ class CompilerBug342021Test extends AbstractXtendCompilerTest { this.toString(); if (true) { this.toString(); - final Iterable _function = new Iterable() { - public Iterator iterator() { - return CollectionLiterals.newArrayList().iterator(); - } + final Iterable _function = () -> { + return CollectionLiterals.newArrayList().iterator(); }; return _function; } else { @@ -536,7 +497,6 @@ class CompilerBug342021Test extends AbstractXtendCompilerTest { } } ''', ''' - import java.util.Iterator; import org.eclipse.xtext.xbase.lib.CollectionLiterals; import org.eclipse.xtext.xbase.lib.Conversions; @@ -549,10 +509,8 @@ class CompilerBug342021Test extends AbstractXtendCompilerTest { Object[] _xifexpression = null; if (true) { this.toString(); - final Iterable _function = new Iterable() { - public Iterator iterator() { - return CollectionLiterals.newArrayList().iterator(); - } + final Iterable _function = () -> { + return CollectionLiterals.newArrayList().iterator(); }; return _function; } else { @@ -592,7 +550,6 @@ class CompilerBug342021Test extends AbstractXtendCompilerTest { } } ''', ''' - import java.util.Iterator; import org.eclipse.xtext.xbase.lib.CollectionLiterals; import org.eclipse.xtext.xbase.lib.Conversions; @@ -607,10 +564,8 @@ class CompilerBug342021Test extends AbstractXtendCompilerTest { Iterable _xblockexpression_1 = null; { this.toString(); - final Iterable _function = new Iterable() { - public Iterator iterator() { - return CollectionLiterals.newArrayList().iterator(); - } + final Iterable _function = () -> { + return CollectionLiterals.newArrayList().iterator(); }; _xblockexpression_1 = _function; } @@ -639,7 +594,6 @@ class CompilerBug342021Test extends AbstractXtendCompilerTest { } } ''', ''' - import java.util.Iterator; import org.eclipse.xtext.xbase.lib.CollectionLiterals; import org.eclipse.xtext.xbase.lib.Conversions; @@ -650,10 +604,8 @@ class CompilerBug342021Test extends AbstractXtendCompilerTest { boolean _matched = false; if (o instanceof Boolean) { _matched=true; - final Iterable _function = new Iterable() { - public Iterator iterator() { - return CollectionLiterals.newArrayList().iterator(); - } + final Iterable _function = () -> { + return CollectionLiterals.newArrayList().iterator(); }; _switchResult = _function; } @@ -678,7 +630,6 @@ class CompilerBug342021Test extends AbstractXtendCompilerTest { } } ''', ''' - import java.util.Iterator; import org.eclipse.xtext.xbase.lib.CollectionLiterals; import org.eclipse.xtext.xbase.lib.Conversions; @@ -689,10 +640,8 @@ class CompilerBug342021Test extends AbstractXtendCompilerTest { boolean _matched = false; if (o instanceof Boolean) { _matched=true; - final Iterable _function = new Iterable() { - public Iterator iterator() { - return CollectionLiterals.newArrayList().iterator(); - } + final Iterable _function = () -> { + return CollectionLiterals.newArrayList().iterator(); }; _switchResult = _function; } @@ -721,7 +670,6 @@ class CompilerBug342021Test extends AbstractXtendCompilerTest { } } ''', ''' - import java.util.Iterator; import org.eclipse.xtext.xbase.lib.CollectionLiterals; import org.eclipse.xtext.xbase.lib.Conversions; @@ -732,10 +680,8 @@ class CompilerBug342021Test extends AbstractXtendCompilerTest { boolean _matched = false; if (o instanceof Boolean) { _matched=true; - final Iterable _function = new Iterable() { - public Iterator iterator() { - return CollectionLiterals.newArrayList().iterator(); - } + final Iterable _function = () -> { + return CollectionLiterals.newArrayList().iterator(); }; _switchResult = _function; } @@ -767,7 +713,6 @@ class CompilerBug342021Test extends AbstractXtendCompilerTest { } } ''', ''' - import java.util.Iterator; import org.eclipse.xtext.xbase.lib.CollectionLiterals; import org.eclipse.xtext.xbase.lib.Conversions; @@ -778,10 +723,8 @@ class CompilerBug342021Test extends AbstractXtendCompilerTest { boolean _matched = false; if (o instanceof Boolean) { _matched=true; - final Iterable _function = new Iterable() { - public Iterator iterator() { - return CollectionLiterals.newArrayList().iterator(); - } + final Iterable _function = () -> { + return CollectionLiterals.newArrayList().iterator(); }; return _function; } @@ -813,7 +756,6 @@ class CompilerBug342021Test extends AbstractXtendCompilerTest { } } ''', ''' - import java.util.Iterator; import org.eclipse.xtext.xbase.lib.CollectionLiterals; import org.eclipse.xtext.xbase.lib.Conversions; import org.eclipse.xtext.xbase.lib.Exceptions; @@ -823,10 +765,8 @@ class CompilerBug342021Test extends AbstractXtendCompilerTest { public Iterable m(final Object o) { Iterable _xtrycatchfinallyexpression = null; try { - final Iterable _function = new Iterable() { - public Iterator iterator() { - return CollectionLiterals.newArrayList().iterator(); - } + final Iterable _function = () -> { + return CollectionLiterals.newArrayList().iterator(); }; _xtrycatchfinallyexpression = _function; } catch (final Throwable _t) { @@ -860,7 +800,6 @@ class CompilerBug342021Test extends AbstractXtendCompilerTest { } ''', ''' import java.util.Collections; - import java.util.Iterator; import org.eclipse.xtext.xbase.lib.CollectionLiterals; import org.eclipse.xtext.xbase.lib.Conversions; @@ -871,10 +810,8 @@ class CompilerBug342021Test extends AbstractXtendCompilerTest { boolean _matched = false; if (o instanceof Boolean) { _matched=true; - final Iterable _function = new Iterable() { - public Iterator iterator() { - return CollectionLiterals.newArrayList().iterator(); - } + final Iterable _function = () -> { + return CollectionLiterals.newArrayList().iterator(); }; _switchResult = _function; } diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug383534Test.xtend b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug383534Test.xtend index ff0bb807e52..e07f0ad22f4 100644 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug383534Test.xtend +++ b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug383534Test.xtend @@ -45,25 +45,19 @@ class CompilerBug383534Test extends AbstractXtendCompilerTest { @SuppressWarnings("all") public class C { public void m() { - final Function2 _function = new Function2() { - public String apply(final String s1, final String s2) { - return (s1 + s2); - } + final Function2 _function = (String s1, String s2) -> { + return (s1 + s2); }; final Function2 strAdd = _function; final Function1 curriedStrAdd = FunctionExtensions.curry(strAdd, "x"); InputOutput.println(strAdd.apply("x", "y")); InputOutput.println(curriedStrAdd.apply("y")); - final Function2 _function_1 = new Function2() { - public String apply(final String s1, final String[] s2) { - final Function2 _function = new Function2() { - public String apply(final String x1, final String x2) { - return (x1 + x2); - } - }; - String _reduce = IterableExtensions.reduce(((Iterable)Conversions.doWrapArray(s2)), _function); - return (s1 + _reduce); - } + final Function2 _function_1 = (String s1, String[] s2) -> { + final Function2 _function_2 = (String x1, String x2) -> { + return (x1 + x2); + }; + String _reduce = IterableExtensions.reduce(((Iterable)Conversions.doWrapArray(s2)), _function_2); + return (s1 + _reduce); }; final Function2 strAdd2 = _function_1; final Function1 curriedStrAdd2 = FunctionExtensions.curry(strAdd2, "x"); @@ -94,10 +88,8 @@ class CompilerBug383534Test extends AbstractXtendCompilerTest { @SuppressWarnings("all") public class C { public void m() { - final Function2 _function = new Function2() { - public String apply(final String s1, final String s2) { - return (s1 + s2); - } + final Function2 _function = (String s1, String s2) -> { + return (s1 + s2); }; final Function2 strAdd = _function; final Function1 curriedStrAdd = FunctionExtensions.curry(strAdd, "x"); @@ -131,11 +123,9 @@ class CompilerBug383534Test extends AbstractXtendCompilerTest { @SuppressWarnings("all") public class C { public void m() { - final Function2 _function = new Function2() { - public String apply(final String s1, final String[] s2) { - String _head = IterableExtensions.head(((Iterable)Conversions.doWrapArray(s2))); - return (s1 + _head); - } + final Function2 _function = (String s1, String[] s2) -> { + String _head = IterableExtensions.head(((Iterable)Conversions.doWrapArray(s2))); + return (s1 + _head); }; final Function2 strAdd = _function; final Function1 curriedStrAdd = FunctionExtensions.curry(strAdd, "x"); @@ -168,16 +158,12 @@ class CompilerBug383534Test extends AbstractXtendCompilerTest { @SuppressWarnings("all") public class C { public void m() { - final Function2 _function = new Function2() { - public String apply(final String s1, final String[] s2) { - final Function2 _function = new Function2() { - public String apply(final String x1, final String x2) { - return (x1 + x2); - } - }; - String _reduce = IterableExtensions.reduce(((Iterable)Conversions.doWrapArray(s2)), _function); - return (s1 + _reduce); - } + final Function2 _function = (String s1, String[] s2) -> { + final Function2 _function_1 = (String x1, String x2) -> { + return (x1 + x2); + }; + String _reduce = IterableExtensions.reduce(((Iterable)Conversions.doWrapArray(s2)), _function_1); + return (s1 + _reduce); }; final Function2 strAdd = _function; final Function1 curriedStrAdd = FunctionExtensions.curry(strAdd, "x"); diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug404051Test.xtend b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug404051Test.xtend index 079cd596cfb..a61c7327824 100644 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug404051Test.xtend +++ b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug404051Test.xtend @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2013, 2016 itemis AG (http://www.itemis.eu) and others. + * Copyright (c) 2013, 2024 itemis AG (http://www.itemis.eu) and others. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. @@ -35,15 +35,11 @@ class CompilerBug404051Test extends AbstractXtendCompilerTest { @SuppressWarnings("all") public class C { public List m(final Iterable iterable) { - final Function1 _function = new Function1() { - public Object apply(final String it) { - return null; - } + final Function1 _function = (String it) -> { + return null; }; - final Function1 _function_1 = new Function1() { - public Integer apply(final Object it) { - return Integer.valueOf(it.hashCode()); - } + final Function1 _function_1 = (Object it) -> { + return Integer.valueOf(it.hashCode()); }; return IterableExtensions.sortBy(this.flatMap(iterable, _function), _function_1); } @@ -74,15 +70,11 @@ class CompilerBug404051Test extends AbstractXtendCompilerTest { @SuppressWarnings("all") public class C { public List m(final Iterable iterable) { - final Function1 _function = new Function1() { - public Number apply(final String it) { - return null; - } + final Function1 _function = (String it) -> { + return null; }; - final Function1 _function_1 = new Function1() { - public Integer apply(final Object it) { - return Integer.valueOf(it.hashCode()); - } + final Function1 _function_1 = (Object it) -> { + return Integer.valueOf(it.hashCode()); }; return IterableExtensions.sortBy(this.flatMap(iterable, _function), _function_1); } @@ -113,15 +105,11 @@ class CompilerBug404051Test extends AbstractXtendCompilerTest { @SuppressWarnings("all") public class C { public List m(final Iterable iterable) { - final Function1 _function = new Function1() { - public Number apply(final String it) { - return null; - } + final Function1 _function = (String it) -> { + return null; }; - final Function1 _function_1 = new Function1() { - public Integer apply(final Number it) { - return Integer.valueOf(it.intValue()); - } + final Function1 _function_1 = (Number it) -> { + return Integer.valueOf(it.intValue()); }; return IterableExtensions.sortBy(this.flatMap(iterable, _function), _function_1); } @@ -154,15 +142,11 @@ class CompilerBug404051Test extends AbstractXtendCompilerTest { @SuppressWarnings("all") public class C { public List m() { - final Function1 _function = new Function1() { - public Integer apply(final String it) { - return Integer.valueOf(it.length()); - } + final Function1 _function = (String it) -> { + return Integer.valueOf(it.length()); }; - final Function1 _function_1 = new Function1() { - public Integer apply(final Integer it) { - return Integer.valueOf(it.intValue()); - } + final Function1 _function_1 = (Integer it) -> { + return Integer.valueOf(it.intValue()); }; return IterableExtensions.sortBy(this.flatMap(Collections.unmodifiableList(CollectionLiterals.newArrayList()), _function), _function_1); } @@ -195,15 +179,11 @@ class CompilerBug404051Test extends AbstractXtendCompilerTest { @SuppressWarnings("all") public class C { public List m() { - final Function1 _function = new Function1() { - public Number apply(final String it) { - return null; - } + final Function1 _function = (String it) -> { + return null; }; - final Function1 _function_1 = new Function1() { - public Integer apply(final Number it) { - return Integer.valueOf(it.intValue()); - } + final Function1 _function_1 = (Number it) -> { + return Integer.valueOf(it.intValue()); }; return IterableExtensions.sortBy(this.flatMap(Collections.unmodifiableList(CollectionLiterals.newArrayList()), _function), _function_1); } @@ -234,15 +214,11 @@ class CompilerBug404051Test extends AbstractXtendCompilerTest { @SuppressWarnings("all") public class C { public List m(final Iterable iterable) { - final Function1 _function = new Function1() { - public String apply(final String it) { - return null; - } + final Function1 _function = (String it) -> { + return null; }; - final Function1 _function_1 = new Function1() { - public Integer apply(final String it) { - return Integer.valueOf(it.length()); - } + final Function1 _function_1 = (String it) -> { + return Integer.valueOf(it.length()); }; return IterableExtensions.sortBy(this.flatMap(iterable, _function), _function_1); } diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug405825Test.xtend b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug405825Test.xtend index 5c93281a5ea..a25c6b1cd4f 100644 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug405825Test.xtend +++ b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug405825Test.xtend @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2013 itemis AG (http://www.itemis.eu) and others. + * Copyright (c) 2013, 2024 itemis AG (http://www.itemis.eu) and others. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. @@ -36,9 +36,7 @@ class CompilerBug405825Test extends AbstractXtendCompilerTest { } public static void main() { - final Bound _function = new Bound() { - public void method(final Number it) { - } + final Bound _function = (Number it) -> { }; Test.test(_function); } @@ -67,9 +65,7 @@ class CompilerBug405825Test extends AbstractXtendCompilerTest { } public static void main() { - final Bound _function = new Bound() { - public void method(final Integer it) { - } + final Bound _function = (Integer it) -> { }; Test.test(_function); } @@ -99,9 +95,7 @@ class CompilerBug405825Test extends AbstractXtendCompilerTest { } public static void main() { - final Sub _function = new Sub() { - public void method(final Number it) { - } + final Sub _function = (Number it) -> { }; Test.test(_function); } diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug406425Test.xtend b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug406425Test.xtend index 6e7fbc36be1..0822b4b9acd 100644 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug406425Test.xtend +++ b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug406425Test.xtend @@ -15,9 +15,8 @@ import org.junit.Test */ class CompilerBug406425Test extends AbstractXtendCompilerTest { - @Test - def testBug406425_01() { - assertCompilesTo(''' + @Test def void testBug406425_01() { + ''' import static org.hamcrest.core.Is.* import static org.junit.Assert.* import org.hamcrest.Matcher @@ -33,7 +32,7 @@ class CompilerBug406425Test extends AbstractXtendCompilerTest { class MyEntity { @Property String name } - ''', ''' + '''.assertCompilesTo(''' import org.eclipse.xtext.xbase.lib.ObjectExtensions; import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; import org.hamcrest.Matcher; @@ -44,11 +43,9 @@ class CompilerBug406425Test extends AbstractXtendCompilerTest { public class Test { public MyEntity test() { MyEntity _myEntity = new MyEntity(); - final Procedure1 _function = new Procedure1() { - public void apply(final MyEntity it) { - Assert.assertThat(it, Test.nullValue()); - Assert.assertThat(it.getName(), Is.is("")); - } + final Procedure1 _function = (MyEntity it) -> { + Assert.assertThat(it, Test.nullValue()); + Assert.assertThat(it.getName(), Is.is("")); }; return ObjectExtensions.operator_doubleArrow(_myEntity, _function); } @@ -60,10 +57,9 @@ class CompilerBug406425Test extends AbstractXtendCompilerTest { ''') } - @Test - def testBug406425_02() { - assertCompilesTo(''' - import org.eclipse.xtend.core.tests.compiler.StringBuilderLike + @Test def void testBug406425_02() { + ''' + import org.eclipse.xtend.core.tests.java8.compiler.StringBuilderLike class Test { def m(T a, T b){} @@ -74,9 +70,9 @@ class CompilerBug406425Test extends AbstractXtendCompilerTest { ] } } - ''', ''' + '''.assertCompilesTo(''' import java.io.Serializable; - import org.eclipse.xtend.core.tests.compiler.StringBuilderLike; + import org.eclipse.xtend.core.tests.java8.compiler.StringBuilderLike; import org.eclipse.xtext.xbase.lib.InputOutput; import org.eclipse.xtext.xbase.lib.ObjectExtensions; import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; @@ -89,13 +85,11 @@ class CompilerBug406425Test extends AbstractXtendCompilerTest { public static StringBuilderLike m() { StringBuilderLike _stringBuilderLike = new StringBuilderLike(); - final Procedure1 _function = new Procedure1() { - public void apply(final StringBuilderLike it) { - Test _test = new Test(); - Long _long = new Long(0); - _test.m(it, _long); - InputOutput.println(Integer.valueOf(it.length())); - } + final Procedure1 _function = (StringBuilderLike it) -> { + Test _test = new Test(); + Long _long = new Long(0); + _test.m(it, _long); + InputOutput.println(Integer.valueOf(it.length())); }; return ObjectExtensions.operator_doubleArrow(_stringBuilderLike, _function); } @@ -103,10 +97,9 @@ class CompilerBug406425Test extends AbstractXtendCompilerTest { ''') } - @Test - def testBug406425_03() { - assertCompilesTo(''' - import org.eclipse.xtend.core.tests.compiler.StringBuilderLike + @Test def void testBug406425_03() { + ''' + import org.eclipse.xtend.core.tests.java8.compiler.StringBuilderLike class Test { def m(T a, T b){} @@ -117,9 +110,9 @@ class CompilerBug406425Test extends AbstractXtendCompilerTest { ] } } - ''', ''' + '''.assertCompilesTo(''' import java.io.Serializable; - import org.eclipse.xtend.core.tests.compiler.StringBuilderLike; + import org.eclipse.xtend.core.tests.java8.compiler.StringBuilderLike; import org.eclipse.xtext.xbase.lib.InputOutput; import org.eclipse.xtext.xbase.lib.ObjectExtensions; import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; @@ -132,12 +125,10 @@ class CompilerBug406425Test extends AbstractXtendCompilerTest { public StringBuilderLike m() { StringBuilderLike _stringBuilderLike = new StringBuilderLike(); - final Procedure1 _function = new Procedure1() { - public void apply(final StringBuilderLike it) { - Long _long = new Long(0); - Test.this.m(it, _long); - InputOutput.println(Integer.valueOf(it.length())); - } + final Procedure1 _function = (StringBuilderLike it) -> { + Long _long = new Long(0); + this.m(it, _long); + InputOutput.println(Integer.valueOf(it.length())); }; return ObjectExtensions.operator_doubleArrow(_stringBuilderLike, _function); } @@ -145,10 +136,9 @@ class CompilerBug406425Test extends AbstractXtendCompilerTest { ''') } - @Test - def testBug406425_04() { - assertCompilesTo(''' - import org.eclipse.xtend.core.tests.compiler.StringBuilderLike + @Test def void testBug406425_04() { + ''' + import org.eclipse.xtend.core.tests.java8.compiler.StringBuilderLike class Test { def m(T a, T b){} @@ -159,9 +149,9 @@ class CompilerBug406425Test extends AbstractXtendCompilerTest { ] } } - ''', ''' + '''.assertCompilesTo(''' import java.io.Serializable; - import org.eclipse.xtend.core.tests.compiler.StringBuilderLike; + import org.eclipse.xtend.core.tests.java8.compiler.StringBuilderLike; import org.eclipse.xtext.xbase.lib.InputOutput; import org.eclipse.xtext.xbase.lib.ObjectExtensions; import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; @@ -174,12 +164,10 @@ class CompilerBug406425Test extends AbstractXtendCompilerTest { public StringBuilderLike m() { StringBuilderLike _stringBuilderLike = new StringBuilderLike(); - final Procedure1 _function = new Procedure1() { - public void apply(final StringBuilderLike it) { - Long _long = new Long(0); - Test.this.m(it, _long); - InputOutput.println(Integer.valueOf(it.length())); - } + final Procedure1 _function = (StringBuilderLike it) -> { + Long _long = new Long(0); + this.m(it, _long); + InputOutput.println(Integer.valueOf(it.length())); }; return ObjectExtensions.operator_doubleArrow(_stringBuilderLike, _function); } @@ -187,10 +175,9 @@ class CompilerBug406425Test extends AbstractXtendCompilerTest { ''') } - @Test - def testBug406425_05() { - assertCompilesTo(''' - import org.eclipse.xtend.core.tests.compiler.StringBuilderLike + @Test def void testBug406425_05() { + ''' + import org.eclipse.xtend.core.tests.java8.compiler.StringBuilderLike class Test { def m(T a, T b){} @@ -201,9 +188,9 @@ class CompilerBug406425Test extends AbstractXtendCompilerTest { ] } } - ''', ''' + '''.assertCompilesTo(''' import java.io.Serializable; - import org.eclipse.xtend.core.tests.compiler.StringBuilderLike; + import org.eclipse.xtend.core.tests.java8.compiler.StringBuilderLike; import org.eclipse.xtext.xbase.lib.InputOutput; import org.eclipse.xtext.xbase.lib.ObjectExtensions; import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; @@ -216,12 +203,10 @@ class CompilerBug406425Test extends AbstractXtendCompilerTest { public StringBuilderLike m() { StringBuilderLike _stringBuilderLike = new StringBuilderLike(); - final Procedure1 _function = new Procedure1() { - public void apply(final StringBuilderLike it) { - Long _long = new Long(0); - Test.this.m(it, _long); - InputOutput.println(Integer.valueOf(it.length())); - } + final Procedure1 _function = (StringBuilderLike it) -> { + Long _long = new Long(0); + this.m(it, _long); + InputOutput.println(Integer.valueOf(it.length())); }; return ObjectExtensions.operator_doubleArrow(_stringBuilderLike, _function); } @@ -229,10 +214,9 @@ class CompilerBug406425Test extends AbstractXtendCompilerTest { ''') } - @Test - def testBug406425_06() { - assertCompilesTo(''' - import org.eclipse.xtend.core.tests.compiler.StringBuilderLike + @Test def void testBug406425_06() { + ''' + import org.eclipse.xtend.core.tests.java8.compiler.StringBuilderLike class Test { def m(T a, T b){} @@ -243,10 +227,10 @@ class CompilerBug406425Test extends AbstractXtendCompilerTest { ] } } - ''', ''' + '''.assertCompilesTo(''' import java.io.Serializable; import java.util.function.Consumer; - import org.eclipse.xtend.core.tests.compiler.StringBuilderLike; + import org.eclipse.xtend.core.tests.java8.compiler.StringBuilderLike; import org.eclipse.xtext.xbase.lib.CollectionLiterals; import org.eclipse.xtext.xbase.lib.InputOutput; @@ -258,12 +242,10 @@ class CompilerBug406425Test extends AbstractXtendCompilerTest { public void m() { StringBuilderLike _stringBuilderLike = new StringBuilderLike(); - final Consumer _function = new Consumer() { - public void accept(final StringBuilderLike it) { - Long _long = new Long(0); - Test.this.m(it, _long); - InputOutput.println(Integer.valueOf(it.length())); - } + final Consumer _function = (StringBuilderLike it) -> { + Long _long = new Long(0); + this.m(it, _long); + InputOutput.println(Integer.valueOf(it.length())); }; CollectionLiterals.newArrayList(_stringBuilderLike).forEach(_function); } @@ -271,10 +253,9 @@ class CompilerBug406425Test extends AbstractXtendCompilerTest { ''') } - @Test - def testBug406425_07() { - assertCompilesTo(''' - import org.eclipse.xtend.core.tests.compiler.StringBuilderLike + @Test def void testBug406425_07() { + ''' + import org.eclipse.xtend.core.tests.java8.compiler.StringBuilderLike class Test { def static m(T a, T b){} @@ -285,9 +266,9 @@ class CompilerBug406425Test extends AbstractXtendCompilerTest { ] } } - ''', ''' + '''.assertCompilesTo(''' import java.io.Serializable; - import org.eclipse.xtend.core.tests.compiler.StringBuilderLike; + import org.eclipse.xtend.core.tests.java8.compiler.StringBuilderLike; import org.eclipse.xtext.xbase.lib.InputOutput; import org.eclipse.xtext.xbase.lib.ObjectExtensions; import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; @@ -300,12 +281,10 @@ class CompilerBug406425Test extends AbstractXtendCompilerTest { public StringBuilderLike m() { StringBuilderLike _stringBuilderLike = new StringBuilderLike(); - final Procedure1 _function = new Procedure1() { - public void apply(final StringBuilderLike it) { - Long _long = new Long(0); - Test.m(it, _long); - InputOutput.println(Integer.valueOf(it.length())); - } + final Procedure1 _function = (StringBuilderLike it) -> { + Long _long = new Long(0); + Test.m(it, _long); + InputOutput.println(Integer.valueOf(it.length())); }; return ObjectExtensions.operator_doubleArrow(_stringBuilderLike, _function); } @@ -313,10 +292,9 @@ class CompilerBug406425Test extends AbstractXtendCompilerTest { ''') } - @Test - def testBug406425_08() { - assertCompilesTo(''' - import org.eclipse.xtend.core.tests.compiler.StringBuilderLike + @Test def void testBug406425_08() { + ''' + import org.eclipse.xtend.core.tests.java8.compiler.StringBuilderLike class Test { def static m(T a, T b){} @@ -327,9 +305,9 @@ class CompilerBug406425Test extends AbstractXtendCompilerTest { ] } } - ''', ''' + '''.assertCompilesTo(''' import java.io.Serializable; - import org.eclipse.xtend.core.tests.compiler.StringBuilderLike; + import org.eclipse.xtend.core.tests.java8.compiler.StringBuilderLike; import org.eclipse.xtext.xbase.lib.InputOutput; import org.eclipse.xtext.xbase.lib.ObjectExtensions; import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; @@ -342,12 +320,10 @@ class CompilerBug406425Test extends AbstractXtendCompilerTest { public static StringBuilderLike m() { StringBuilderLike _stringBuilderLike = new StringBuilderLike(); - final Procedure1 _function = new Procedure1() { - public void apply(final StringBuilderLike it) { - Long _long = new Long(0); - Test.m(it, _long); - InputOutput.println(Integer.valueOf(it.length())); - } + final Procedure1 _function = (StringBuilderLike it) -> { + Long _long = new Long(0); + Test.m(it, _long); + InputOutput.println(Integer.valueOf(it.length())); }; return ObjectExtensions.operator_doubleArrow(_stringBuilderLike, _function); } @@ -355,10 +331,9 @@ class CompilerBug406425Test extends AbstractXtendCompilerTest { ''') } - @Test - def testBug406425_09() { - assertCompilesTo(''' - import org.eclipse.xtend.core.tests.compiler.StringBuilderLike + @Test def void testBug406425_09() { + ''' + import org.eclipse.xtend.core.tests.java8.compiler.StringBuilderLike class Test { def m(T a, T b){} @@ -369,10 +344,10 @@ class CompilerBug406425Test extends AbstractXtendCompilerTest { ] } } - ''', ''' + '''.assertCompilesTo(''' import java.io.Serializable; import java.util.function.Consumer; - import org.eclipse.xtend.core.tests.compiler.StringBuilderLike; + import org.eclipse.xtend.core.tests.java8.compiler.StringBuilderLike; import org.eclipse.xtext.xbase.lib.CollectionLiterals; import org.eclipse.xtext.xbase.lib.InputOutput; @@ -384,13 +359,11 @@ class CompilerBug406425Test extends AbstractXtendCompilerTest { public static void m() { StringBuilderLike _stringBuilderLike = new StringBuilderLike(); - final Consumer _function = new Consumer() { - public void accept(final StringBuilderLike it) { - Test _test = new Test(); - Long _long = new Long(0); - _test.m(it, _long); - InputOutput.println(Integer.valueOf(it.length())); - } + final Consumer _function = (StringBuilderLike it) -> { + Test _test = new Test(); + Long _long = new Long(0); + _test.m(it, _long); + InputOutput.println(Integer.valueOf(it.length())); }; CollectionLiterals.newArrayList(_stringBuilderLike).forEach(_function); } @@ -398,10 +371,9 @@ class CompilerBug406425Test extends AbstractXtendCompilerTest { ''') } - @Test - def testBug406425_10() { - assertCompilesTo(''' - import org.eclipse.xtend.core.tests.compiler.StringBuilderLike + @Test def void testBug406425_10() { + ''' + import org.eclipse.xtend.core.tests.java8.compiler.StringBuilderLike class Test { def m(T a, T b){} @@ -412,10 +384,10 @@ class CompilerBug406425Test extends AbstractXtendCompilerTest { ] } } - ''', ''' + '''.assertCompilesTo(''' import java.io.Serializable; import java.util.function.Consumer; - import org.eclipse.xtend.core.tests.compiler.StringBuilderLike; + import org.eclipse.xtend.core.tests.java8.compiler.StringBuilderLike; import org.eclipse.xtext.xbase.lib.CollectionLiterals; import org.eclipse.xtext.xbase.lib.InputOutput; @@ -427,13 +399,11 @@ class CompilerBug406425Test extends AbstractXtendCompilerTest { public static void m() { StringBuilderLike _stringBuilderLike = new StringBuilderLike(); - final Consumer _function = new Consumer() { - public void accept(final StringBuilderLike it) { - Test _test = new Test(); - Long _long = new Long(0); - _test.m(it, _long); - InputOutput.println(Integer.valueOf(it.length())); - } + final Consumer _function = (StringBuilderLike it) -> { + Test _test = new Test(); + Long _long = new Long(0); + _test.m(it, _long); + InputOutput.println(Integer.valueOf(it.length())); }; CollectionLiterals.newArrayList(_stringBuilderLike).forEach(_function); } @@ -441,10 +411,9 @@ class CompilerBug406425Test extends AbstractXtendCompilerTest { ''') } - @Test - def testBug406425_11() { - assertCompilesTo(''' - import org.eclipse.xtend.core.tests.compiler.StringBuilderLike + @Test def void testBug406425_11() { + ''' + import org.eclipse.xtend.core.tests.java8.compiler.StringBuilderLike class Test { static def m(T a, T b){} @@ -455,10 +424,10 @@ class CompilerBug406425Test extends AbstractXtendCompilerTest { ] } } - ''', ''' + '''.assertCompilesTo(''' import java.io.Serializable; import java.util.function.Consumer; - import org.eclipse.xtend.core.tests.compiler.StringBuilderLike; + import org.eclipse.xtend.core.tests.java8.compiler.StringBuilderLike; import org.eclipse.xtext.xbase.lib.CollectionLiterals; import org.eclipse.xtext.xbase.lib.InputOutput; @@ -470,12 +439,10 @@ class CompilerBug406425Test extends AbstractXtendCompilerTest { public static void m() { StringBuilderLike _stringBuilderLike = new StringBuilderLike(); - final Consumer _function = new Consumer() { - public void accept(final StringBuilderLike it) { - Long _long = new Long(0); - Test.m(it, _long); - InputOutput.println(Integer.valueOf(it.length())); - } + final Consumer _function = (StringBuilderLike it) -> { + Long _long = new Long(0); + Test.m(it, _long); + InputOutput.println(Integer.valueOf(it.length())); }; CollectionLiterals.newArrayList(_stringBuilderLike).forEach(_function); } diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug406549Test.xtend b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug406549Test.xtend index 4d886d381ab..2c0cbc2cb0f 100644 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug406549Test.xtend +++ b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug406549Test.xtend @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2013, 2016 itemis AG (http://www.itemis.eu) and others. + * Copyright (c) 2013, 2024 itemis AG (http://www.itemis.eu) and others. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. @@ -60,10 +60,8 @@ class CompilerBug406549Test extends AbstractXtendCompilerTest { } public void m(final T a, final T b) { - final Procedure1> _function = new Procedure1>() { - public void apply(final Test it) { - new Test().m(a, b); - } + final Procedure1> _function = (Test it) -> { + new Test().m(a, b); }; ObjectExtensions.>operator_doubleArrow(this, _function); } @@ -94,12 +92,10 @@ class CompilerBug406549Test extends AbstractXtendCompilerTest { public StringBuilder m() { StringBuilder _stringBuilder = new StringBuilder(); - final Procedure1 _function = new Procedure1() { - public void apply(final StringBuilder it) { - Test _test = new Test(); - Long _long = new Long(0); - _test.m(it, _long); - } + final Procedure1 _function = (StringBuilder it) -> { + Test _test = new Test(); + Long _long = new Long(0); + _test.m(it, _long); }; return ObjectExtensions.operator_doubleArrow(_stringBuilder, _function); } diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug406762Test.xtend b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug406762Test.xtend index e3870152653..bc0617e961d 100644 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug406762Test.xtend +++ b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug406762Test.xtend @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2016 TypeFox.io (http://www.typefox.io) and others. + * Copyright (c) 2016, 2024 TypeFox.io (http://www.typefox.io) and others. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. @@ -28,6 +28,7 @@ class CompilerBug406762Test extends AbstractXtendCompilerTest { @SuppressWarnings("all") public class Bug { private static final class MyException extends Exception { + @Override public synchronized Throwable fillInStackTrace() { return this; } @@ -49,6 +50,7 @@ class CompilerBug406762Test extends AbstractXtendCompilerTest { @SuppressWarnings("all") public class Bug { private static final class MyException extends Exception { + @Override public synchronized Throwable fillInStackTrace() { return this; } diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug410555Test.xtend b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug410555Test.xtend index 8bc993d4bfd..8adaf717bf0 100644 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug410555Test.xtend +++ b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug410555Test.xtend @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2013 itemis AG (http://www.itemis.eu) and others. + * Copyright (c) 2013, 2024 itemis AG (http://www.itemis.eu) and others. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. @@ -65,10 +65,8 @@ class CompilerBug410555Test extends AbstractXtendCompilerTest { @SuppressWarnings("all") public class BugSAM2 extends BugSAM { public BugSAM2() { - super(new SAMInterface() { - public void test() { - } - }); + super(((SAMInterface) () -> { + })); } } ''') @@ -102,16 +100,12 @@ class CompilerBug410555Test extends AbstractXtendCompilerTest { } public BugSAM() { - this(new SAMInterface() { - public void test() { - } - }); + this(((SAMInterface) () -> { + })); } public static void main(final String[] args) { - final SAMInterface _function = new SAMInterface() { - public void test() { - } + final SAMInterface _function = () -> { }; new BugSAM(_function); } diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug410797Test.xtend b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug410797Test.xtend index 9644581d50c..430033a4cad 100644 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug410797Test.xtend +++ b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug410797Test.xtend @@ -56,15 +56,11 @@ class CompilerBug410797Test extends AbstractXtendCompilerTest { { final ArrayList list = CollectionLiterals.newArrayList(); final G g = new G(); - final Function1> _function = new Function1>() { - public ArrayList apply(final E e) { - return e.m(); - } + final Function1> _function = (E e) -> { + return e.m(); }; - final Function1 _function_1 = new Function1() { - public D apply(final F it) { - return C.this.d(it, g); - } + final Function1 _function_1 = (F it) -> { + return this.d(it, g); }; _xblockexpression = IterableExtensions.map(Iterables.concat(ListExtensions.>map(list, _function)), _function_1); } @@ -116,15 +112,11 @@ class CompilerBug410797Test extends AbstractXtendCompilerTest { Iterable _xblockexpression = null; { final G g = new G(); - final Function1> _function = new Function1>() { - public ArrayList apply(final E e) { - return e.m(); - } + final Function1> _function = (E e) -> { + return e.m(); }; - final Function1 _function_1 = new Function1() { - public D apply(final F it) { - return C.this.d(it, g); - } + final Function1 _function_1 = (F it) -> { + return this.d(it, g); }; _xblockexpression = IterableExtensions.map(Iterables.concat(ListExtensions.>map(CollectionLiterals.newArrayList(), _function)), _function_1); } @@ -172,16 +164,12 @@ class CompilerBug410797Test extends AbstractXtendCompilerTest { @SuppressWarnings("all") public class C { public Iterable m() { - final Function1> _function = new Function1>() { - public ArrayList apply(final E e) { - return e.m(); - } + final Function1> _function = (E e) -> { + return e.m(); }; - final Function1 _function_1 = new Function1() { - public D apply(final F it) { - G _g = new G(); - return C.this.d(it, _g); - } + final Function1 _function_1 = (F it) -> { + G _g = new G(); + return this.d(it, _g); }; return IterableExtensions.map(Iterables.concat(ListExtensions.>map(CollectionLiterals.newArrayList(), _function)), _function_1); } @@ -253,35 +241,29 @@ class CompilerBug410797Test extends AbstractXtendCompilerTest { } public int getLenght() { - final Function2 _function = new Function2() { - public Integer apply(final Integer x, final LeafInfo i) { - ILeafNode _node = i.getNode(); - int _length = 0; - if (_node!=null) { - _length=_node.getLength(); - } - return Integer.valueOf(((x).intValue() + _length)); + final Function2 _function = (Integer x, LeafInfo i) -> { + ILeafNode _node = i.getNode(); + int _length = 0; + if (_node!=null) { + _length=_node.getLength(); } + return Integer.valueOf(((x).intValue() + _length)); }; return (int) IterableExtensions.fold(this.getLeafs(), Integer.valueOf(0), _function); } public int getNewLines() { - final Function2 _function = new Function2() { - public Integer apply(final Integer x, final LeafInfo i) { - int _newLines = i.getNewLines(); - return Integer.valueOf(((x).intValue() + _newLines)); - } + final Function2 _function = (Integer x, LeafInfo i) -> { + int _newLines = i.getNewLines(); + return Integer.valueOf(((x).intValue() + _newLines)); }; return (int) IterableExtensions.fold(this.getLeafs(), Integer.valueOf(0), _function); } public int getNewLinesInComments() { - final Function2 _function = new Function2() { - public Integer apply(final Integer x, final CommentInfo i) { - int _newLines = i.getNewLines(); - return Integer.valueOf(((x).intValue() + _newLines)); - } + final Function2 _function = (Integer x, CommentInfo i) -> { + int _newLines = i.getNewLines(); + return Integer.valueOf(((x).intValue() + _newLines)); }; return (int) IterableExtensions.fold(Iterables.filter(this.getLeafs(), CommentInfo.class), Integer.valueOf(0), _function); } diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug412894Test.xtend b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug412894Test.xtend index fc704a559b7..a55a5f7812b 100644 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug412894Test.xtend +++ b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug412894Test.xtend @@ -15,9 +15,8 @@ import org.junit.Test */ class CompilerBug412894Test extends AbstractXtendCompilerTest { - @Test - def test_01() { - assertCompilesTo(''' + @Test def void test_01() { + ''' class C { def m() { val list = newArrayList @@ -28,22 +27,20 @@ class CompilerBug412894Test extends AbstractXtendCompilerTest { ] } } - ''', ''' + '''.assertCompilesTo(''' import java.util.ArrayList; import java.util.function.Consumer; import org.eclipse.xtext.xbase.lib.CollectionLiterals; - + @SuppressWarnings("all") public class C { public void m() { final ArrayList list = CollectionLiterals.newArrayList(); - final Consumer _function = new Consumer() { - public void accept(final String it) { - boolean _matched = false; - if (it instanceof String) { - _matched=true; - list.add(it); - } + final Consumer _function = (String it) -> { + boolean _matched = false; + if (it instanceof String) { + _matched=true; + list.add(it); } }; list.forEach(_function); @@ -52,9 +49,8 @@ class CompilerBug412894Test extends AbstractXtendCompilerTest { ''') } - @Test - def test_02() { - assertCompilesTo(''' + @Test def void test_02() { + ''' class C { def m() { val list = newArrayList @@ -66,7 +62,7 @@ class CompilerBug412894Test extends AbstractXtendCompilerTest { ] } } - ''', ''' + '''.assertCompilesTo(''' import java.io.Serializable; import java.util.ArrayList; import java.util.function.Consumer; @@ -76,19 +72,17 @@ class CompilerBug412894Test extends AbstractXtendCompilerTest { public class C { public void m() { final ArrayList list = CollectionLiterals.newArrayList(); - final Consumer _function = new Consumer() { - public void accept(final Serializable it) { - boolean _matched = false; - if (it instanceof String) { + final Consumer _function = (Serializable it) -> { + boolean _matched = false; + if (it instanceof String) { + _matched=true; + list.add(it); + } + if (!_matched) { + if (it instanceof Number) { _matched=true; list.add(it); } - if (!_matched) { - if (it instanceof Number) { - _matched=true; - list.add(it); - } - } } }; list.forEach(_function); @@ -97,9 +91,8 @@ class CompilerBug412894Test extends AbstractXtendCompilerTest { ''') } - @Test - def test_03() { - assertCompilesTo(''' + @Test def void test_03() { + ''' class C { def m() { val list = newArrayList @@ -110,23 +103,21 @@ class CompilerBug412894Test extends AbstractXtendCompilerTest { ] } } - ''', ''' + '''.assertCompilesTo(''' import java.io.Serializable; import java.util.ArrayList; import java.util.function.Consumer; import org.eclipse.xtext.xbase.lib.CollectionLiterals; - + @SuppressWarnings("all") public class C { public void m() { final ArrayList list = CollectionLiterals.newArrayList(); - final Consumer _function = new Consumer() { - public void accept(final Serializable it) { - boolean _matched = false; - if (it instanceof Number) { - _matched=true; - list.add(((Number)it).toString()); - } + final Consumer _function = (Serializable it) -> { + boolean _matched = false; + if (it instanceof Number) { + _matched=true; + list.add(((Number)it).toString()); } }; list.forEach(_function); @@ -135,9 +126,8 @@ class CompilerBug412894Test extends AbstractXtendCompilerTest { ''') } - @Test - def test_04() { - assertCompilesTo(''' + @Test def void test_04() { + ''' class C { def m() { val list = newArrayList @@ -146,20 +136,18 @@ class CompilerBug412894Test extends AbstractXtendCompilerTest { ] } } - ''', ''' + '''.assertCompilesTo(''' import java.util.ArrayList; import java.util.function.Consumer; import org.eclipse.xtext.xbase.lib.CollectionLiterals; - + @SuppressWarnings("all") public class C { public void m() { final ArrayList list = CollectionLiterals.newArrayList(); - final Consumer _function = new Consumer() { - public void accept(final Object it) { - if ((it instanceof String)) { - list.add(it); - } + final Consumer _function = (Object it) -> { + if ((it instanceof String)) { + list.add(it); } }; list.forEach(_function); diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug419050Test.xtend b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug419050Test.xtend index 245986fa4f6..2cea590de81 100644 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug419050Test.xtend +++ b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug419050Test.xtend @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2013 itemis AG (http://www.itemis.eu) and others. + * Copyright (c) 2013, 2024 itemis AG (http://www.itemis.eu) and others. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. @@ -246,11 +246,9 @@ class CompilerBug419050Test extends AbstractXtendCompilerTest { @SuppressWarnings("all") public class C { public boolean m(final boolean b) { - final Function1 _function = new Function1() { - public Boolean apply(final String s) { - while (true) { - return Boolean.valueOf(false); - } + final Function1 _function = (String s) -> { + while (true) { + return Boolean.valueOf(false); } }; final Function1 func = _function; @@ -278,11 +276,9 @@ class CompilerBug419050Test extends AbstractXtendCompilerTest { @SuppressWarnings("all") public class C { public boolean m(final boolean b) { - final Predicate _function = new Predicate() { - public boolean apply(final String it) { - while (true) { - return false; - } + final Predicate _function = (String it) -> { + while (true) { + return false; } }; final Predicate func = _function; @@ -315,21 +311,19 @@ class CompilerBug419050Test extends AbstractXtendCompilerTest { @SuppressWarnings("all") public class C { public Iterable m(final Iterable iter) { - final Function1 _function = new Function1() { - public Boolean apply(final String it) { - int _length = it.length(); - boolean _lessThan = (_length < 2); - if (_lessThan) { - return Boolean.valueOf(true); - } else { - int _length_1 = it.length(); - boolean _greaterThan = (_length_1 > 2); - if (_greaterThan) { - return Boolean.valueOf(false); - } + final Function1 _function = (String it) -> { + int _length = it.length(); + boolean _lessThan = (_length < 2); + if (_lessThan) { + return Boolean.valueOf(true); + } else { + int _length_1 = it.length(); + boolean _greaterThan = (_length_1 > 2); + if (_greaterThan) { + return Boolean.valueOf(false); } - return null; } + return null; }; return IterableExtensions.filter(iter, _function); } diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug419688Test.xtend b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug419688Test.xtend index 5886754b52d..ee4db6c4970 100644 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug419688Test.xtend +++ b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug419688Test.xtend @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2013 itemis AG (http://www.itemis.eu) and others. + * Copyright (c) 2013, 2024 itemis AG (http://www.itemis.eu) and others. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. @@ -34,6 +34,7 @@ class CompilerBug419688Test extends AbstractXtendCompilerTest { super(); } + @Override public D m() { return super.m(); } @@ -60,6 +61,7 @@ class CompilerBug419688Test extends AbstractXtendCompilerTest { super(); } + @Override public Iterable m() { return super.m(); } diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug421999Test.xtend b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug421999Test.xtend index 816f2aa6540..6e113dd9a4b 100644 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug421999Test.xtend +++ b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug421999Test.xtend @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2013 itemis AG (http://www.itemis.eu) and others. + * Copyright (c) 2013, 2024 itemis AG (http://www.itemis.eu) and others. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. @@ -31,10 +31,8 @@ class CompilerBug421999Test extends AbstractXtendCompilerTest { @SuppressWarnings("all") public class C { public List m(final List list) { - final Function1 _function = new Function1() { - public String apply(final String e) { - return e; - } + final Function1 _function = (String e) -> { + return e; }; return IterableExtensions.sortBy(list, _function); } @@ -58,10 +56,8 @@ class CompilerBug421999Test extends AbstractXtendCompilerTest { @SuppressWarnings("all") public class C { public List m(final List list) { - final Function1 _function = new Function1() { - public String apply(final String e) { - return e; - } + final Function1 _function = (String e) -> { + return e; }; return IterableExtensions.sortBy(list, _function); } @@ -85,10 +81,8 @@ class CompilerBug421999Test extends AbstractXtendCompilerTest { @SuppressWarnings("all") public class C { public List m(final List list) { - final Function1 _function = new Function1() { - public String apply(final String e) { - return e; - } + final Function1 _function = (String e) -> { + return e; }; return IterableExtensions.sortBy(list, _function); } @@ -112,10 +106,8 @@ class CompilerBug421999Test extends AbstractXtendCompilerTest { @SuppressWarnings("all") public class C { public List m(final List list) { - final Function1 _function = new Function1() { - public String apply(final String e) { - return e; - } + final Function1 _function = (String e) -> { + return e; }; return IterableExtensions.sortBy(list, _function); } @@ -172,12 +164,10 @@ class CompilerBug421999Test extends AbstractXtendCompilerTest { List> _xblockexpression = null; { final ArrayList c = CollectionLiterals.newArrayList(); - final Function1> _function = new Function1>() { - public Pair apply(final IEObjectDescription eod) { - QualifiedName _qualifiedName = eod.getQualifiedName(); - T _resolve = Dummy.this.resolve(eod, resourceSet); - return Pair.of(_qualifiedName, _resolve); - } + final Function1> _function = (IEObjectDescription eod) -> { + QualifiedName _qualifiedName = eod.getQualifiedName(); + T _resolve = this.resolve(eod, resourceSet); + return Pair.of(_qualifiedName, _resolve); }; _xblockexpression = ListExtensions.>map(c, _function); } diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug422864Test.xtend b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug422864Test.xtend index b1025469164..199ed8abf27 100644 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug422864Test.xtend +++ b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug422864Test.xtend @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2014, 2016 itemis AG (http://www.itemis.eu) and others. + * Copyright (c) 2014, 2024 itemis AG (http://www.itemis.eu) and others. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. @@ -39,10 +39,8 @@ class CompilerBug422864Test extends AbstractXtendCompilerTest { @SuppressWarnings("all") public class C { public Pair, String> test(final L, String>> l) { - final Function1, String>, Double> _function = new Function1, String>, Double>() { - public Double apply(final Pair, String> it) { - return it.getKey().getValue(); - } + final Function1, String>, Double> _function = (Pair, String> it) -> { + return it.getKey().getValue(); }; return l.maximum(O.doubleO()., String>>c(_function)); } diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug424763Test.xtend b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug424763Test.xtend index 376d62899ad..3d80da8218a 100644 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug424763Test.xtend +++ b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug424763Test.xtend @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2014, 2016 itemis AG (http://www.itemis.eu) and others. + * Copyright (c) 2014, 2024 itemis AG (http://www.itemis.eu) and others. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. @@ -63,6 +63,7 @@ class CompilerBug424763Test extends AbstractXtendCompilerTest { this.type = Preconditions.>checkNotNull(theType, "theType").getName(); } + @Override public JAVA_TYPE apply() { throw new UnsupportedOperationException( (("Instances of type " + this.type) + " cannot be created (without parameters?)")); @@ -289,6 +290,7 @@ class CompilerBug424763Test extends AbstractXtendCompilerTest { public C(final C theConstructor) { this(new Function0>() { + @Override public Function0 apply() { Function0 _constructor = null; if (theConstructor!=null) { @@ -369,6 +371,7 @@ class CompilerBug424763Test extends AbstractXtendCompilerTest { public C(final C theConstructor) { this(theConstructor.doGetConstructor(new Function0() { + @Override public String apply() { String _xtrycatchfinallyexpression = null; try { diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug427637Test.xtend b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug427637Test.xtend index 6958394df34..cb48bd467cd 100644 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug427637Test.xtend +++ b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug427637Test.xtend @@ -16,7 +16,7 @@ import org.junit.Test class CompilerBug427637Test extends AbstractXtendCompilerTest { @Test def void testBug_427637_01() { - assertCompilesTo(''' + ''' import java.util.List class C { @@ -26,16 +26,14 @@ class CompilerBug427637Test extends AbstractXtendCompilerTest { } def void forEach2(Iterable iterable, (T)=>void procedure) {} } - ''', ''' + '''.assertCompilesTo(''' import java.util.List; import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; @SuppressWarnings("all") public class C { public void m(final List list) { - final Procedure1 _function = new Procedure1() { - public void apply(final V it) { - } + final Procedure1 _function = (V it) -> { }; this.forEach2(list, _function); } @@ -47,7 +45,7 @@ class CompilerBug427637Test extends AbstractXtendCompilerTest { } @Test def void testBug_427637_01_b() { - assertCompilesTo(''' + ''' import java.util.List class C { @@ -56,16 +54,14 @@ class CompilerBug427637Test extends AbstractXtendCompilerTest { ] } } - ''', ''' + '''.assertCompilesTo(''' import java.util.List; import java.util.function.Consumer; @SuppressWarnings("all") public class C { public void m(final List list) { - final Consumer _function = new Consumer() { - public void accept(final V it) { - } + final Consumer _function = (V it) -> { }; list.forEach(_function); } @@ -74,7 +70,7 @@ class CompilerBug427637Test extends AbstractXtendCompilerTest { } @Test def void testBug_427637_02() { - assertCompilesTo(''' + ''' import java.util.List class C { @@ -84,16 +80,14 @@ class CompilerBug427637Test extends AbstractXtendCompilerTest { } def void forEach2(Iterable iterable, (T)=>void procedure) {} } - ''', ''' + '''.assertCompilesTo(''' import java.util.List; import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; @SuppressWarnings("all") public class C { public void m(final List list) { - final Procedure1 _function = new Procedure1() { - public void apply(final V it) { - } + final Procedure1 _function = (V it) -> { }; this.forEach2(list, _function); } @@ -105,7 +99,7 @@ class CompilerBug427637Test extends AbstractXtendCompilerTest { } @Test def void testBug_427637_02_b() { - assertCompilesTo(''' + ''' import java.util.List class C { @@ -114,16 +108,14 @@ class CompilerBug427637Test extends AbstractXtendCompilerTest { ] } } - ''', ''' + '''.assertCompilesTo(''' import java.util.List; import java.util.function.Consumer; @SuppressWarnings("all") public class C { public void m(final List list) { - final Consumer _function = new Consumer() { - public void accept(final V it) { - } + final Consumer _function = (V it) -> { }; list.forEach(_function); } @@ -132,7 +124,7 @@ class CompilerBug427637Test extends AbstractXtendCompilerTest { } @Test def void testBug_427637_03() { - assertCompilesTo(''' + ''' import java.util.List class C { @@ -142,16 +134,14 @@ class CompilerBug427637Test extends AbstractXtendCompilerTest { } def void forEach2(Iterable iterable, (T)=>void procedure) {} } - ''', ''' + '''.assertCompilesTo(''' import java.util.List; import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; @SuppressWarnings("all") public class C { public void m(final List list) { - final Procedure1 _function = new Procedure1() { - public void apply(final Object it) { - } + final Procedure1 _function = (Object it) -> { }; this.forEach2(list, _function); } @@ -163,7 +153,7 @@ class CompilerBug427637Test extends AbstractXtendCompilerTest { } @Test def void testBug_427637_03_b() { - assertCompilesTo(''' + ''' import java.util.List class C { @@ -172,16 +162,14 @@ class CompilerBug427637Test extends AbstractXtendCompilerTest { ] } } - ''', ''' + '''.assertCompilesTo(''' import java.util.List; import java.util.function.Consumer; @SuppressWarnings("all") public class C { public void m(final List list) { - final Consumer _function = new Consumer() { - public void accept(final Object it) { - } + final Consumer _function = (Object it) -> { }; list.forEach(_function); } @@ -190,7 +178,7 @@ class CompilerBug427637Test extends AbstractXtendCompilerTest { } @Test def void testBug_427637_04() { - assertCompilesTo(''' + ''' import java.util.List class C { @@ -200,16 +188,14 @@ class CompilerBug427637Test extends AbstractXtendCompilerTest { } def void forEach2(Iterable iterable, (T)=>void procedure) {} } - ''', ''' + '''.assertCompilesTo(''' import java.util.List; import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; @SuppressWarnings("all") public class C { public void m(final List list) { - final Procedure1 _function = new Procedure1() { - public void apply(final V it) { - } + final Procedure1 _function = (V it) -> { }; this.forEach2(list.subList(1, 1), _function); } @@ -221,7 +207,7 @@ class CompilerBug427637Test extends AbstractXtendCompilerTest { } @Test def void testBug_427637_04_b() { - assertCompilesTo(''' + ''' import java.util.List class C { @@ -230,16 +216,14 @@ class CompilerBug427637Test extends AbstractXtendCompilerTest { ] } } - ''', ''' + '''.assertCompilesTo(''' import java.util.List; import java.util.function.Consumer; @SuppressWarnings("all") public class C { public void m(final List list) { - final Consumer _function = new Consumer() { - public void accept(final V it) { - } + final Consumer _function = (V it) -> { }; list.subList(1, 1).forEach(_function); } @@ -248,7 +232,7 @@ class CompilerBug427637Test extends AbstractXtendCompilerTest { } @Test def void testBug_427637_05() { - assertCompilesTo(''' + ''' import java.util.List class C { @@ -258,16 +242,14 @@ class CompilerBug427637Test extends AbstractXtendCompilerTest { } def void forEach2(Iterable iterable, (T)=>void procedure) {} } - ''', ''' + '''.assertCompilesTo(''' import java.util.List; import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; @SuppressWarnings("all") public class C { public void m(final List list) { - final Procedure1 _function = new Procedure1() { - public void apply(final V it) { - } + final Procedure1 _function = (V it) -> { }; this.forEach2(list.subList(1, 1), _function); } @@ -279,7 +261,7 @@ class CompilerBug427637Test extends AbstractXtendCompilerTest { } @Test def void testBug_427637_05_b() { - assertCompilesTo(''' + ''' import java.util.List class C { @@ -288,16 +270,14 @@ class CompilerBug427637Test extends AbstractXtendCompilerTest { ] } } - ''', ''' + '''.assertCompilesTo(''' import java.util.List; import java.util.function.Consumer; @SuppressWarnings("all") public class C { public void m(final List list) { - final Consumer _function = new Consumer() { - public void accept(final V it) { - } + final Consumer _function = (V it) -> { }; list.subList(1, 1).forEach(_function); } @@ -306,7 +286,7 @@ class CompilerBug427637Test extends AbstractXtendCompilerTest { } @Test def void testBug_427637_06() { - assertCompilesTo(''' + ''' import java.util.List class C { @@ -316,16 +296,14 @@ class CompilerBug427637Test extends AbstractXtendCompilerTest { } def void forEach2(Iterable iterable, (T)=>void procedure) {} } - ''', ''' + '''.assertCompilesTo(''' import java.util.List; import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; @SuppressWarnings("all") public class C { public void m(final List list) { - final Procedure1 _function = new Procedure1() { - public void apply(final Object it) { - } + final Procedure1 _function = (Object it) -> { }; this.forEach2(list.subList(1, 1), _function); } @@ -337,7 +315,7 @@ class CompilerBug427637Test extends AbstractXtendCompilerTest { } @Test def void testBug_427637_06_b() { - assertCompilesTo(''' + ''' import java.util.List class C { @@ -346,16 +324,14 @@ class CompilerBug427637Test extends AbstractXtendCompilerTest { ] } } - ''', ''' + '''.assertCompilesTo(''' import java.util.List; import java.util.function.Consumer; @SuppressWarnings("all") public class C { public void m(final List list) { - final Consumer _function = new Consumer() { - public void accept(final Object it) { - } + final Consumer _function = (Object it) -> { }; list.subList(1, 1).forEach(_function); } @@ -364,7 +340,7 @@ class CompilerBug427637Test extends AbstractXtendCompilerTest { } @Test def void testBug_427637_07() { - assertCompilesTo(''' + ''' import java.util.List class C { @@ -375,17 +351,15 @@ class CompilerBug427637Test extends AbstractXtendCompilerTest { } def void forEach2(Iterable iterable, (T)=>void procedure) {} } - ''', ''' + '''.assertCompilesTo(''' import java.util.List; import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; @SuppressWarnings("all") public class C { public void m(final List list) { - final Procedure1 _function = new Procedure1() { - public void apply(final V it) { - it.toString(); - } + final Procedure1 _function = (V it) -> { + it.toString(); }; this.forEach2(list.subList(1, 1), _function); } @@ -397,7 +371,7 @@ class CompilerBug427637Test extends AbstractXtendCompilerTest { } @Test def void testBug_427637_07_b() { - assertCompilesTo(''' + ''' import java.util.List class C { @@ -407,17 +381,15 @@ class CompilerBug427637Test extends AbstractXtendCompilerTest { ] } } - ''', ''' + '''.assertCompilesTo(''' import java.util.List; import java.util.function.Consumer; @SuppressWarnings("all") public class C { public void m(final List list) { - final Consumer _function = new Consumer() { - public void accept(final V it) { - it.toString(); - } + final Consumer _function = (V it) -> { + it.toString(); }; list.subList(1, 1).forEach(_function); } @@ -426,7 +398,7 @@ class CompilerBug427637Test extends AbstractXtendCompilerTest { } @Test def void testBug_427637_08() { - assertCompilesTo(''' + ''' import java.util.List class C { @@ -437,17 +409,15 @@ class CompilerBug427637Test extends AbstractXtendCompilerTest { } def void forEach2(Iterable iterable, (T)=>void procedure) {} } - ''', ''' + '''.assertCompilesTo(''' import java.util.List; import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; @SuppressWarnings("all") public class C { public void m(final List list) { - final Procedure1 _function = new Procedure1() { - public void apply(final V it) { - it.toString(); - } + final Procedure1 _function = (V it) -> { + it.toString(); }; this.forEach2(list.subList(1, 1), _function); } @@ -459,7 +429,7 @@ class CompilerBug427637Test extends AbstractXtendCompilerTest { } @Test def void testBug_427637_08_b() { - assertCompilesTo(''' + ''' import java.util.List class C { @@ -469,17 +439,15 @@ class CompilerBug427637Test extends AbstractXtendCompilerTest { ] } } - ''', ''' + '''.assertCompilesTo(''' import java.util.List; import java.util.function.Consumer; @SuppressWarnings("all") public class C { public void m(final List list) { - final Consumer _function = new Consumer() { - public void accept(final V it) { - it.toString(); - } + final Consumer _function = (V it) -> { + it.toString(); }; list.subList(1, 1).forEach(_function); } @@ -488,7 +456,7 @@ class CompilerBug427637Test extends AbstractXtendCompilerTest { } @Test def void testBug_427637_09() { - assertCompilesTo(''' + ''' import java.util.List class C { @@ -499,17 +467,15 @@ class CompilerBug427637Test extends AbstractXtendCompilerTest { } def void forEach2(Iterable iterable, (T)=>void procedure) {} } - ''', ''' + '''.assertCompilesTo(''' import java.util.List; import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; @SuppressWarnings("all") public class C { public void m(final List list) { - final Procedure1 _function = new Procedure1() { - public void apply(final Object it) { - it.toString(); - } + final Procedure1 _function = (Object it) -> { + it.toString(); }; this.forEach2(list.subList(1, 1), _function); } @@ -521,7 +487,7 @@ class CompilerBug427637Test extends AbstractXtendCompilerTest { } @Test def void testBug_427637_09_b() { - assertCompilesTo(''' + ''' import java.util.List class C { @@ -531,17 +497,15 @@ class CompilerBug427637Test extends AbstractXtendCompilerTest { ] } } - ''', ''' + '''.assertCompilesTo(''' import java.util.List; import java.util.function.Consumer; @SuppressWarnings("all") public class C { public void m(final List list) { - final Consumer _function = new Consumer() { - public void accept(final Object it) { - it.toString(); - } + final Consumer _function = (Object it) -> { + it.toString(); }; list.subList(1, 1).forEach(_function); } @@ -550,7 +514,7 @@ class CompilerBug427637Test extends AbstractXtendCompilerTest { } @Test def void testBug_427637_10() { - assertCompilesTo(''' + ''' import java.util.List class C { @@ -562,7 +526,7 @@ class CompilerBug427637Test extends AbstractXtendCompilerTest { } def void forEach2(Iterable iterable, (T)=>void procedure) {} } - ''', ''' + '''.assertCompilesTo(''' import java.util.List; import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; @@ -570,10 +534,8 @@ class CompilerBug427637Test extends AbstractXtendCompilerTest { public class C { public void m(final List list) { final List target = null; - final Procedure1 _function = new Procedure1() { - public void apply(final V it) { - target.add(it); - } + final Procedure1 _function = (V it) -> { + target.add(it); }; this.forEach2(list, _function); } @@ -585,7 +547,7 @@ class CompilerBug427637Test extends AbstractXtendCompilerTest { } @Test def void testBug_427637_10_b() { - assertCompilesTo(''' + ''' import java.util.List class C { @@ -596,7 +558,7 @@ class CompilerBug427637Test extends AbstractXtendCompilerTest { ] } } - ''', ''' + '''.assertCompilesTo(''' import java.util.List; import java.util.function.Consumer; @@ -604,10 +566,8 @@ class CompilerBug427637Test extends AbstractXtendCompilerTest { public class C { public void m(final List list) { final List target = null; - final Consumer _function = new Consumer() { - public void accept(final V it) { - target.add(it); - } + final Consumer _function = (V it) -> { + target.add(it); }; list.forEach(_function); } @@ -616,7 +576,7 @@ class CompilerBug427637Test extends AbstractXtendCompilerTest { } @Test def void testBug_427637_11() { - assertCompilesTo(''' + ''' import java.util.List class C { @@ -630,7 +590,7 @@ class CompilerBug427637Test extends AbstractXtendCompilerTest { ] } } - ''', ''' + '''.assertCompilesTo(''' import com.google.common.collect.Iterables; import java.util.ArrayList; import java.util.List; @@ -641,19 +601,17 @@ class CompilerBug427637Test extends AbstractXtendCompilerTest { public class C { public void m(final List list) { final List target = null; - final Consumer _function = new Consumer() { - public void accept(final T it) { - List _subList = target.subList(0, 1); - _subList.add(it); - List _subList_1 = target.subList(0, 1); - _subList_1.remove(it); - List _subList_2 = target.subList(0, 1); - ArrayList _newArrayList = CollectionLiterals.newArrayList(it); - Iterables.addAll(_subList_2, _newArrayList); - List _subList_3 = target.subList(0, 1); - ArrayList _newArrayList_1 = CollectionLiterals.newArrayList(it); - Iterables.removeAll(_subList_3, _newArrayList_1); - } + final Consumer _function = (T it) -> { + List _subList = target.subList(0, 1); + _subList.add(it); + List _subList_1 = target.subList(0, 1); + _subList_1.remove(it); + List _subList_2 = target.subList(0, 1); + ArrayList _newArrayList = CollectionLiterals.newArrayList(it); + Iterables.addAll(_subList_2, _newArrayList); + List _subList_3 = target.subList(0, 1); + ArrayList _newArrayList_1 = CollectionLiterals.newArrayList(it); + Iterables.removeAll(_subList_3, _newArrayList_1); }; list.subList(0, 1).forEach(_function); } @@ -662,7 +620,7 @@ class CompilerBug427637Test extends AbstractXtendCompilerTest { } @Test def void testBug_427637_12() { - assertCompilesTo(''' + ''' import java.util.List class Listener implements ListChangeListener { @@ -672,12 +630,12 @@ class CompilerBug427637Test extends AbstractXtendCompilerTest { override onChanged(Change change) { while(change.next) { if(change.wasAdded) - change.addedSubList.forEach [ T it | // Xtend bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=427637 + change.addedSubList.forEach [ T it | layer.children += it it.activate() ] if(change.wasRemoved) - change.removed.forEach [ T it | // Xtend bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=427637 + change.removed.forEach [ T it | layer.children -= it ] } @@ -702,34 +660,31 @@ class CompilerBug427637Test extends AbstractXtendCompilerTest { def boolean wasAdded() def boolean wasRemoved() } - ''', ''' + '''.assertCompilesTo(''' import java.util.function.Consumer; @SuppressWarnings("all") public class Listener implements ListChangeListener { private Group layer; + @Override public void onChanged(final Change change) { while (change.next()) { { boolean _wasAdded = change.wasAdded(); if (_wasAdded) { - final Consumer _function = new Consumer() { - public void accept(final T it) { - ObservableList _children = Listener.this.layer.getChildren(); - _children.add(it); - it.activate(); - } + final Consumer _function = (T it) -> { + ObservableList _children = this.layer.getChildren(); + _children.add(it); + it.activate(); }; change.getAddedSubList().forEach(_function); } boolean _wasRemoved = change.wasRemoved(); if (_wasRemoved) { - final Consumer _function_1 = new Consumer() { - public void accept(final T it) { - ObservableList _children = Listener.this.layer.getChildren(); - _children.remove(it); - } + final Consumer _function_1 = (T it) -> { + ObservableList _children = this.layer.getChildren(); + _children.remove(it); }; change.getRemoved().forEach(_function_1); } @@ -741,7 +696,7 @@ class CompilerBug427637Test extends AbstractXtendCompilerTest { } @Test def void testBug_427637_13() { - assertCompilesTo(''' + ''' import java.util.List class Listener implements ListChangeListener { @@ -781,34 +736,31 @@ class CompilerBug427637Test extends AbstractXtendCompilerTest { def boolean wasAdded() def boolean wasRemoved() } - ''', ''' + '''.assertCompilesTo(''' import java.util.function.Consumer; @SuppressWarnings("all") public class Listener implements ListChangeListener { private Group layer; + @Override public void onChanged(final Change change) { while (change.next()) { { boolean _wasAdded = change.wasAdded(); if (_wasAdded) { - final Consumer _function = new Consumer() { - public void accept(final T it) { - ObservableList _children = Listener.this.layer.getChildren(); - _children.add(it); - it.activate(); - } + final Consumer _function = (T it) -> { + ObservableList _children = this.layer.getChildren(); + _children.add(it); + it.activate(); }; change.getAddedSubList().forEach(_function); } boolean _wasRemoved = change.wasRemoved(); if (_wasRemoved) { - final Consumer _function_1 = new Consumer() { - public void accept(final T it) { - ObservableList _children = Listener.this.layer.getChildren(); - _children.remove(it); - } + final Consumer _function_1 = (T it) -> { + ObservableList _children = this.layer.getChildren(); + _children.remove(it); }; change.getRemoved().forEach(_function_1); } @@ -820,7 +772,7 @@ class CompilerBug427637Test extends AbstractXtendCompilerTest { } @Test def void testBug_427637_14() { - assertCompilesTo(''' + ''' import java.util.List class Listener { // implements ListChangeListener { @@ -851,7 +803,7 @@ class CompilerBug427637Test extends AbstractXtendCompilerTest { def boolean wasAdded() def boolean wasRemoved() } - ''', ''' + '''.assertCompilesTo(''' import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; @SuppressWarnings("all") @@ -859,11 +811,9 @@ class CompilerBug427637Test extends AbstractXtendCompilerTest { private Group layer; public void onChanged(final Change change) { - final Procedure1 _function = new Procedure1() { - public void apply(final T it) { - ObservableList _children = Listener.this.layer.getChildren(); - _children.add(it); - } + final Procedure1 _function = (T it) -> { + ObservableList _children = this.layer.getChildren(); + _children.add(it); }; this.forEach2(change.getAddedSubList(), _function); } @@ -1118,7 +1068,7 @@ class CompilerBug427637Test extends AbstractXtendCompilerTest { } } } - ''', ''' + ''',''' package org.eclipse.xtext.xbase.formatting; import com.google.common.collect.Iterables; @@ -1173,6 +1123,7 @@ class CompilerBug427637Test extends AbstractXtendCompilerTest { this.decreaseIndentationChange = (this.decreaseIndentationChange - 1); } + @Override public String toString() { return new ToStringHelper().toString(this); } @@ -1193,87 +1144,79 @@ class CompilerBug427637Test extends AbstractXtendCompilerTest { } protected Function1> _newFormattingData(final HiddenLeafs leafs, final Void key, final FormattingDataFactory.FormattingDataInit it) { - final Function1> _function = new Function1>() { - public Iterable apply(final FormattableDocument doc) { - Integer _elvis = null; - if (it.newLines != null) { - _elvis = it.newLines; - } else { - _elvis = Integer.valueOf(0); - } - final int newLines2 = (int) _elvis; - if (((Objects.equals(it.space, null) && Objects.equals(it.newLines, null)) || ((leafs.getNewLinesInComments() == 0) && ((newLines2 == 0) || Objects.equals(it.space, ""))))) { - return FormattingDataFactory.this.newWhitespaceData(leafs, it.space, it.increaseIndentationChange, it.decreaseIndentationChange, doc.isDebugConflicts()); - } else { - return FormattingDataFactory.this.newNewLineData(leafs, newLines2, newLines2, it.increaseIndentationChange, it.decreaseIndentationChange, doc.isDebugConflicts()); - } + final Function1> _function = (FormattableDocument doc) -> { + Integer _elvis = null; + if (it.newLines != null) { + _elvis = it.newLines; + } else { + _elvis = Integer.valueOf(0); + } + final int newLines2 = (int) _elvis; + if (((Objects.equals(it.space, null) && Objects.equals(it.newLines, null)) || ((leafs.getNewLinesInComments() == 0) && ((newLines2 == 0) || Objects.equals(it.space, ""))))) { + return this.newWhitespaceData(leafs, it.space, it.increaseIndentationChange, it.decreaseIndentationChange, doc.isDebugConflicts()); + } else { + return this.newNewLineData(leafs, newLines2, newLines2, it.increaseIndentationChange, it.decreaseIndentationChange, doc.isDebugConflicts()); } }; return _function; } protected Function1> _newFormattingData(final HiddenLeafs leafs, final BlankLineKey key, final FormattingDataFactory.FormattingDataInit it) { - final Function1> _function = new Function1>() { - public Iterable apply(final FormattableDocument doc) { - Iterable _xblockexpression = null; - { - final int blankline = doc.getCfg().get(key); - final int preserve = doc.getCfg().get(XbaseFormatterPreferenceKeys.preserveBlankLines); - final int min = (blankline + 1); - final int max = Math.max((preserve + 1), min); - _xblockexpression = FormattingDataFactory.this.newNewLineData(leafs, min, max, it.increaseIndentationChange, it.decreaseIndentationChange, doc.isDebugConflicts()); - } - return _xblockexpression; + final Function1> _function = (FormattableDocument doc) -> { + Iterable _xblockexpression = null; + { + final int blankline = doc.getCfg().get(key); + final int preserve = doc.getCfg().get(XbaseFormatterPreferenceKeys.preserveBlankLines); + final int min = (blankline + 1); + final int max = Math.max((preserve + 1), min); + _xblockexpression = this.newNewLineData(leafs, min, max, it.increaseIndentationChange, it.decreaseIndentationChange, doc.isDebugConflicts()); } + return _xblockexpression; }; return _function; } protected Function1> _newFormattingData(final HiddenLeafs leafs, final NewLineOrPreserveKey key, final FormattingDataFactory.FormattingDataInit it) { - final Function1> _function = new Function1>() { - public Iterable apply(final FormattableDocument doc) { - Iterable _xblockexpression = null; - { - final boolean newLine = doc.getCfg().get(key); - final boolean preserve = doc.getCfg().get(XbaseFormatterPreferenceKeys.preserveNewLines); - int _xifexpression = (int) 0; - if (newLine) { - _xifexpression = 1; - } else { - _xifexpression = 0; - } - int _xifexpression_1 = (int) 0; - if ((preserve || newLine)) { - _xifexpression_1 = 1; - } else { - _xifexpression_1 = 0; - } - _xblockexpression = FormattingDataFactory.this.newNewLineData(leafs, _xifexpression, _xifexpression_1, it.increaseIndentationChange, it.decreaseIndentationChange, - doc.isDebugConflicts()); + final Function1> _function = (FormattableDocument doc) -> { + Iterable _xblockexpression = null; + { + final boolean newLine = doc.getCfg().get(key); + final boolean preserve = doc.getCfg().get(XbaseFormatterPreferenceKeys.preserveNewLines); + int _xifexpression = (int) 0; + if (newLine) { + _xifexpression = 1; + } else { + _xifexpression = 0; + } + int _xifexpression_1 = (int) 0; + if ((preserve || newLine)) { + _xifexpression_1 = 1; + } else { + _xifexpression_1 = 0; } - return _xblockexpression; + _xblockexpression = this.newNewLineData(leafs, _xifexpression, _xifexpression_1, it.increaseIndentationChange, it.decreaseIndentationChange, + doc.isDebugConflicts()); } + return _xblockexpression; }; return _function; } protected Function1> _newFormattingData(final HiddenLeafs leafs, final NewLineKey key, final FormattingDataFactory.FormattingDataInit it) { - final Function1> _function = new Function1>() { - public Iterable apply(final FormattableDocument doc) { - Iterable _xblockexpression = null; - { - final boolean newLine = doc.getCfg().get(key); - int _xifexpression = (int) 0; - if (newLine) { - _xifexpression = 1; - } else { - _xifexpression = 0; - } - final int minmax = _xifexpression; - _xblockexpression = FormattingDataFactory.this.newNewLineData(leafs, minmax, minmax, it.increaseIndentationChange, it.decreaseIndentationChange, doc.isDebugConflicts()); + final Function1> _function = (FormattableDocument doc) -> { + Iterable _xblockexpression = null; + { + final boolean newLine = doc.getCfg().get(key); + int _xifexpression = (int) 0; + if (newLine) { + _xifexpression = 1; + } else { + _xifexpression = 0; } - return _xblockexpression; + final int minmax = _xifexpression; + _xblockexpression = this.newNewLineData(leafs, minmax, minmax, it.increaseIndentationChange, it.decreaseIndentationChange, doc.isDebugConflicts()); } + return _xblockexpression; }; return _function; } @@ -1285,21 +1228,19 @@ class CompilerBug427637Test extends AbstractXtendCompilerTest { } protected Function1> _newFormattingData(final HiddenLeafs leafs, final WhitespaceKey key, final FormattingDataFactory.FormattingDataInit it) { - final Function1> _function = new Function1>() { - public Iterable apply(final FormattableDocument doc) { - Iterable _xblockexpression = null; - { - final boolean space = doc.getCfg().get(key); - String _xifexpression = null; - if (space) { - _xifexpression = " "; - } else { - _xifexpression = ""; - } - _xblockexpression = FormattingDataFactory.this.newWhitespaceData(leafs, _xifexpression, it.increaseIndentationChange, it.decreaseIndentationChange, doc.isDebugConflicts()); + final Function1> _function = (FormattableDocument doc) -> { + Iterable _xblockexpression = null; + { + final boolean space = doc.getCfg().get(key); + String _xifexpression = null; + if (space) { + _xifexpression = " "; + } else { + _xifexpression = ""; } - return _xblockexpression; + _xblockexpression = this.newWhitespaceData(leafs, _xifexpression, it.increaseIndentationChange, it.decreaseIndentationChange, doc.isDebugConflicts()); } + return _xblockexpression; }; return _function; } @@ -1567,87 +1508,83 @@ class CompilerBug427637Test extends AbstractXtendCompilerTest { } public Function1> surround(final INode node, final Procedure1 init) { - final Function1> _function = new Function1>() { - public Iterable apply(final FormattableDocument doc) { - ArrayList _xblockexpression = null; - { - final ArrayList result = CollectionLiterals.newArrayList(); - boolean _notEquals = (!Objects.equals(node, null)); - if (_notEquals) { - Iterable _elvis = null; - Function1> _newFormattingData = FormattingDataFactory.this.newFormattingData(FormattingDataFactory.this._hiddenLeafAccess.getHiddenLeafsBefore(node), init); - Iterable _apply = null; - if (_newFormattingData!=null) { - _apply=_newFormattingData.apply(doc); - } - if (_apply != null) { - _elvis = _apply; - } else { - List _emptyList = CollectionLiterals.emptyList(); - _elvis = _emptyList; - } - Iterables.addAll(result, _elvis); - Iterable _elvis_1 = null; - Function1> _newFormattingData_1 = FormattingDataFactory.this.newFormattingData(FormattingDataFactory.this._hiddenLeafAccess.getHiddenLeafsAfter(node), init); - Iterable _apply_1 = null; - if (_newFormattingData_1!=null) { - _apply_1=_newFormattingData_1.apply(doc); - } - if (_apply_1 != null) { - _elvis_1 = _apply_1; - } else { - List _emptyList_1 = CollectionLiterals.emptyList(); - _elvis_1 = _emptyList_1; - } - Iterables.addAll(result, _elvis_1); + final Function1> _function = (FormattableDocument doc) -> { + ArrayList _xblockexpression = null; + { + final ArrayList result = CollectionLiterals.newArrayList(); + boolean _notEquals = (!Objects.equals(node, null)); + if (_notEquals) { + Iterable _elvis = null; + Function1> _newFormattingData = this.newFormattingData(this._hiddenLeafAccess.getHiddenLeafsBefore(node), init); + Iterable _apply = null; + if (_newFormattingData!=null) { + _apply=_newFormattingData.apply(doc); + } + if (_apply != null) { + _elvis = _apply; + } else { + List _emptyList = CollectionLiterals.emptyList(); + _elvis = _emptyList; + } + Iterables.addAll(result, _elvis); + Iterable _elvis_1 = null; + Function1> _newFormattingData_1 = this.newFormattingData(this._hiddenLeafAccess.getHiddenLeafsAfter(node), init); + Iterable _apply_1 = null; + if (_newFormattingData_1!=null) { + _apply_1=_newFormattingData_1.apply(doc); + } + if (_apply_1 != null) { + _elvis_1 = _apply_1; + } else { + List _emptyList_1 = CollectionLiterals.emptyList(); + _elvis_1 = _emptyList_1; } - _xblockexpression = result; + Iterables.addAll(result, _elvis_1); } - return _xblockexpression; + _xblockexpression = result; } + return _xblockexpression; }; return _function; } public Function1> surround(final INode node, final Procedure1 before, final Procedure1 after) { - final Function1> _function = new Function1>() { - public Iterable apply(final FormattableDocument doc) { - ArrayList _xblockexpression = null; - { - final ArrayList result = CollectionLiterals.newArrayList(); - boolean _notEquals = (!Objects.equals(node, null)); - if (_notEquals) { - Iterable _elvis = null; - Function1> _newFormattingData = FormattingDataFactory.this.newFormattingData(FormattingDataFactory.this._hiddenLeafAccess.getHiddenLeafsBefore(node), before); - Iterable _apply = null; - if (_newFormattingData!=null) { - _apply=_newFormattingData.apply(doc); - } - if (_apply != null) { - _elvis = _apply; - } else { - List _emptyList = CollectionLiterals.emptyList(); - _elvis = _emptyList; - } - Iterables.addAll(result, _elvis); - Iterable _elvis_1 = null; - Function1> _newFormattingData_1 = FormattingDataFactory.this.newFormattingData(FormattingDataFactory.this._hiddenLeafAccess.getHiddenLeafsAfter(node), after); - Iterable _apply_1 = null; - if (_newFormattingData_1!=null) { - _apply_1=_newFormattingData_1.apply(doc); - } - if (_apply_1 != null) { - _elvis_1 = _apply_1; - } else { - List _emptyList_1 = CollectionLiterals.emptyList(); - _elvis_1 = _emptyList_1; - } - Iterables.addAll(result, _elvis_1); + final Function1> _function = (FormattableDocument doc) -> { + ArrayList _xblockexpression = null; + { + final ArrayList result = CollectionLiterals.newArrayList(); + boolean _notEquals = (!Objects.equals(node, null)); + if (_notEquals) { + Iterable _elvis = null; + Function1> _newFormattingData = this.newFormattingData(this._hiddenLeafAccess.getHiddenLeafsBefore(node), before); + Iterable _apply = null; + if (_newFormattingData!=null) { + _apply=_newFormattingData.apply(doc); } - _xblockexpression = result; + if (_apply != null) { + _elvis = _apply; + } else { + List _emptyList = CollectionLiterals.emptyList(); + _elvis = _emptyList; + } + Iterables.addAll(result, _elvis); + Iterable _elvis_1 = null; + Function1> _newFormattingData_1 = this.newFormattingData(this._hiddenLeafAccess.getHiddenLeafsAfter(node), after); + Iterable _apply_1 = null; + if (_newFormattingData_1!=null) { + _apply_1=_newFormattingData_1.apply(doc); + } + if (_apply_1 != null) { + _elvis_1 = _apply_1; + } else { + List _emptyList_1 = CollectionLiterals.emptyList(); + _elvis_1 = _emptyList_1; + } + Iterables.addAll(result, _elvis_1); } - return _xblockexpression; + _xblockexpression = result; } + return _xblockexpression; }; return _function; } @@ -1673,4 +1610,5 @@ class CompilerBug427637Test extends AbstractXtendCompilerTest { } ''') } + } \ No newline at end of file diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug428063Test.xtend b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug428063Test.xtend index c84cf26d39f..87f73009efd 100644 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug428063Test.xtend +++ b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug428063Test.xtend @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2014 itemis AG (http://www.itemis.eu) and others. + * Copyright (c) 2014, 2024 itemis AG (http://www.itemis.eu) and others. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. @@ -30,9 +30,7 @@ class CompilerBug428063Test extends AbstractXtendCompilerTest { @SuppressWarnings("all") public class C { public static void main() { - final Procedure1 _function = new Procedure1() { - public void apply(final Integer it) { - } + final Procedure1 _function = (Integer it) -> { }; C.m(_function); } @@ -59,9 +57,7 @@ class CompilerBug428063Test extends AbstractXtendCompilerTest { @SuppressWarnings("all") public class C { public static void main() { - final Procedure1 _function = new Procedure1() { - public void apply(final Integer it) { - } + final Procedure1 _function = (Integer it) -> { }; C.m(_function); } diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug432193Test.xtend b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug432193Test.xtend index a00c2408c77..4bd6755c1d7 100644 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug432193Test.xtend +++ b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug432193Test.xtend @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2014 itemis AG (http://www.itemis.eu) and others. + * Copyright (c) 2014, 2024 itemis AG (http://www.itemis.eu) and others. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. @@ -28,11 +28,9 @@ class CompilerBug432193Test extends AbstractXtendCompilerTest { ''', ''' @SuppressWarnings("all") public class C { - private D d = new D() { - public void m(final String o) { - o.subSequence(1, 2); - } - }; + private D d = ((D) (String o) -> { + o.subSequence(1, 2); + }); } ''') } diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug434424Test.xtend b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug434424Test.xtend index cf871e671f7..cee609c39c3 100644 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug434424Test.xtend +++ b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug434424Test.xtend @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2014 itemis AG (http://www.itemis.eu) and others. + * Copyright (c) 2014, 2024 itemis AG (http://www.itemis.eu) and others. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. @@ -266,10 +266,8 @@ class CompilerBug434424Test extends AbstractXtendCompilerTest { } public void setField(final String field) { - final Function1 _function = new Function1() { - public Number apply(final Number it) { - return it; - } + final Function1 _function = (Number it) -> { + return it; }; this.field = _function; } diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug435473Test.xtend b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug435473Test.xtend index 421913c506d..c5c5b8a3873 100644 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug435473Test.xtend +++ b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug435473Test.xtend @@ -16,14 +16,13 @@ import org.junit.Test */ class CompilerBug435473Test extends AbstractXtendCompilerTest { - @Test - def test_01() { - assertCompilesTo(''' + @Test def test_01() { + ''' import java.util.List class Outer { val List> x = #[[|1], [|1.0]] } - ''', ''' + '''.assertCompilesTo(''' import java.util.Collections; import java.util.List; import org.eclipse.xtext.xbase.lib.CollectionLiterals; @@ -31,27 +30,22 @@ class CompilerBug435473Test extends AbstractXtendCompilerTest { @SuppressWarnings("all") public class Outer { - private final List> x = Collections.>unmodifiableList(CollectionLiterals.>newArrayList(new Function0() { - public Object apply() { - return Integer.valueOf(1); - } - }, new Function0() { - public Object apply() { - return Double.valueOf(1.0); - } - })); + private final List> x = Collections.>unmodifiableList(CollectionLiterals.>newArrayList(((Function0) () -> { + return Integer.valueOf(1); + }), ((Function0) () -> { + return Double.valueOf(1.0); + }))); } ''') } - @Test - def test_02() { - assertCompilesTo(''' + @Test def test_02() { + ''' import java.util.List class Outer { val List> x = #[[|1], [|1.0]] } - ''', ''' + '''.assertCompilesTo(''' import java.util.Collections; import java.util.List; import org.eclipse.xtext.xbase.lib.CollectionLiterals; @@ -59,27 +53,22 @@ class CompilerBug435473Test extends AbstractXtendCompilerTest { @SuppressWarnings("all") public class Outer { - private final List> x = Collections.>unmodifiableList(CollectionLiterals.>newArrayList(new Function0() { - public Number apply() { - return Integer.valueOf(1); - } - }, new Function0() { - public Number apply() { - return Double.valueOf(1.0); - } - })); + private final List> x = Collections.>unmodifiableList(CollectionLiterals.>newArrayList(((Function0) () -> { + return Integer.valueOf(1); + }), ((Function0) () -> { + return Double.valueOf(1.0); + }))); } ''') } - @Test - def test_03() { - assertCompilesTo(''' + @Test def test_03() { + ''' import java.util.List class Outer { val List> x = #[[|1], [|1.0]] } - ''', ''' + '''.assertCompilesTo(''' import java.util.Collections; import java.util.List; import org.eclipse.xtext.xbase.lib.CollectionLiterals; @@ -87,27 +76,22 @@ class CompilerBug435473Test extends AbstractXtendCompilerTest { @SuppressWarnings("all") public class Outer { - private final List> x = Collections.>unmodifiableList(CollectionLiterals.>newArrayList(new Function0() { - public Number apply() { - return Integer.valueOf(1); - } - }, new Function0() { - public Number apply() { - return Double.valueOf(1.0); - } - })); + private final List> x = Collections.>unmodifiableList(CollectionLiterals.>newArrayList(((Function0) () -> { + return Integer.valueOf(1); + }), ((Function0) () -> { + return Double.valueOf(1.0); + }))); } ''') } - @Test - def test_04() { - assertCompilesTo(''' + @Test def test_04() { + ''' import java.util.List class Outer { val List> x = #[[|1], [|1.0]] } - ''', ''' + '''.assertCompilesTo(''' import java.util.Collections; import java.util.List; import org.eclipse.xtext.xbase.lib.CollectionLiterals; @@ -115,27 +99,22 @@ class CompilerBug435473Test extends AbstractXtendCompilerTest { @SuppressWarnings("all") public class Outer { - private final List> x = Collections.>unmodifiableList(CollectionLiterals.>newArrayList(new Function0() { - public Number apply() { - return Integer.valueOf(1); - } - }, new Function0() { - public Number apply() { - return Double.valueOf(1.0); - } - })); + private final List> x = Collections.>unmodifiableList(CollectionLiterals.>newArrayList(((Function0) () -> { + return Integer.valueOf(1); + }), ((Function0) () -> { + return Double.valueOf(1.0); + }))); } ''') } - @Test - def test_05() { - assertCompilesTo(''' + @Test def test_05() { + ''' import java.util.Set class Outer { val Set> x = #{ [|1], [|1.0] } } - ''', ''' + '''.assertCompilesTo(''' import java.util.Collections; import java.util.Set; import org.eclipse.xtext.xbase.lib.CollectionLiterals; @@ -143,27 +122,22 @@ class CompilerBug435473Test extends AbstractXtendCompilerTest { @SuppressWarnings("all") public class Outer { - private final Set> x = Collections.>unmodifiableSet(CollectionLiterals.>newHashSet(new Function0() { - public Number apply() { - return Integer.valueOf(1); - } - }, new Function0() { - public Number apply() { - return Double.valueOf(1.0); - } - })); + private final Set> x = Collections.>unmodifiableSet(CollectionLiterals.>newHashSet(((Function0) () -> { + return Integer.valueOf(1); + }), ((Function0) () -> { + return Double.valueOf(1.0); + }))); } ''') } - @Test - def test_06() { - assertCompilesTo(''' + @Test def test_06() { + ''' import java.util.Set class Outer { val Set> x = #{ [|1], [|1.0] } } - ''', ''' + '''.assertCompilesTo(''' import java.util.Collections; import java.util.Set; import org.eclipse.xtext.xbase.lib.CollectionLiterals; @@ -171,27 +145,22 @@ class CompilerBug435473Test extends AbstractXtendCompilerTest { @SuppressWarnings("all") public class Outer { - private final Set> x = Collections.>unmodifiableSet(CollectionLiterals.>newHashSet(new Function0() { - public Number apply() { - return Integer.valueOf(1); - } - }, new Function0() { - public Number apply() { - return Double.valueOf(1.0); - } - })); + private final Set> x = Collections.>unmodifiableSet(CollectionLiterals.>newHashSet(((Function0) () -> { + return Integer.valueOf(1); + }), ((Function0) () -> { + return Double.valueOf(1.0); + }))); } ''') } - @Test - def test_07() { - assertCompilesTo(''' + @Test def test_07() { + ''' import java.util.Set class Outer { val Set> x = #{ [|1], [|1.0] } } - ''', ''' + '''.assertCompilesTo(''' import java.util.Collections; import java.util.Set; import org.eclipse.xtext.xbase.lib.CollectionLiterals; @@ -199,27 +168,22 @@ class CompilerBug435473Test extends AbstractXtendCompilerTest { @SuppressWarnings("all") public class Outer { - private final Set> x = Collections.>unmodifiableSet(CollectionLiterals.>newHashSet(new Function0() { - public Number apply() { - return Integer.valueOf(1); - } - }, new Function0() { - public Number apply() { - return Double.valueOf(1.0); - } - })); + private final Set> x = Collections.>unmodifiableSet(CollectionLiterals.>newHashSet(((Function0) () -> { + return Integer.valueOf(1); + }), ((Function0) () -> { + return Double.valueOf(1.0); + }))); } ''') } - @Test - def test_08() { - assertCompilesTo(''' + @Test def test_08() { + ''' import java.util.Set class Outer { val Set> x = #{ [|1], [|1.0] } } - ''', ''' + '''.assertCompilesTo(''' import java.util.Collections; import java.util.Set; import org.eclipse.xtext.xbase.lib.CollectionLiterals; @@ -227,96 +191,77 @@ class CompilerBug435473Test extends AbstractXtendCompilerTest { @SuppressWarnings("all") public class Outer { - private final Set> x = Collections.>unmodifiableSet(CollectionLiterals.>newHashSet(new Function0() { - public Number apply() { - return Integer.valueOf(1); - } - }, new Function0() { - public Number apply() { - return Double.valueOf(1.0); - } - })); + private final Set> x = Collections.>unmodifiableSet(CollectionLiterals.>newHashSet(((Function0) () -> { + return Integer.valueOf(1); + }), ((Function0) () -> { + return Double.valueOf(1.0); + }))); } ''') } - @Test - def test_09() { - assertCompilesTo(''' + @Test def test_09() { + ''' import java.util.List class Outer { val List> x = newArrayList([|1], [|1.0]) } - ''', ''' + '''.assertCompilesTo(''' import java.util.List; import org.eclipse.xtext.xbase.lib.CollectionLiterals; import org.eclipse.xtext.xbase.lib.Functions.Function0; @SuppressWarnings("all") public class Outer { - private final List> x = CollectionLiterals.>newArrayList(new Function0() { - public Integer apply() { - return Integer.valueOf(1); - } - }, new Function0() { - public Double apply() { - return Double.valueOf(1.0); - } - }); + private final List> x = CollectionLiterals.>newArrayList(((Function0) () -> { + return Integer.valueOf(1); + }), ((Function0) () -> { + return Double.valueOf(1.0); + })); } ''') } - @Test - def test_10() { - assertCompilesTo(''' + @Test def test_10() { + ''' import java.util.List class Outer { val List> x = newArrayList([|1], [|1.0]) } - ''', ''' + '''.assertCompilesTo(''' import java.util.List; import org.eclipse.xtext.xbase.lib.CollectionLiterals; import org.eclipse.xtext.xbase.lib.Functions.Function0; @SuppressWarnings("all") public class Outer { - private final List> x = CollectionLiterals.>newArrayList(new Function0() { - public Integer apply() { - return Integer.valueOf(1); - } - }, new Function0() { - public Double apply() { - return Double.valueOf(1.0); - } - }); + private final List> x = CollectionLiterals.>newArrayList(((Function0) () -> { + return Integer.valueOf(1); + }), ((Function0) () -> { + return Double.valueOf(1.0); + })); } ''') } - @Test - def test_11() { - assertCompilesTo(''' + @Test def test_11() { + ''' import java.util.List class Outer { val List> x = newArrayList([|1], [|1.0]) } - ''', ''' + '''.assertCompilesTo(''' import java.util.List; import org.eclipse.xtext.xbase.lib.CollectionLiterals; import org.eclipse.xtext.xbase.lib.Functions.Function0; @SuppressWarnings("all") public class Outer { - private final List> x = CollectionLiterals.>newArrayList(new Function0() { - public Integer apply() { - return Integer.valueOf(1); - } - }, new Function0() { - public Double apply() { - return Double.valueOf(1.0); - } - }); + private final List> x = CollectionLiterals.>newArrayList(((Function0) () -> { + return Integer.valueOf(1); + }), ((Function0) () -> { + return Double.valueOf(1.0); + })); } ''') } @@ -334,14 +279,13 @@ class CompilerBug435473Test extends AbstractXtendCompilerTest { ''') } - @Test - def test_13() { - assertCompilesTo(''' + @Test def test_13() { + ''' import java.util.List class Outer { val x = #[[|1], [|1.0]] } - ''', ''' + '''.assertCompilesTo(''' import java.util.Collections; import java.util.List; import org.eclipse.xtext.xbase.lib.CollectionLiterals; @@ -349,81 +293,68 @@ class CompilerBug435473Test extends AbstractXtendCompilerTest { @SuppressWarnings("all") public class Outer { - private final List> x = Collections.>unmodifiableList(CollectionLiterals.>newArrayList(new Function0() { - public Integer apply() { - return Integer.valueOf(1); - } - }, new Function0() { - public Double apply() { - return Double.valueOf(1.0); - } - })); + private final List> x = Collections.>unmodifiableList(CollectionLiterals.>newArrayList(((Function0) () -> { + return Integer.valueOf(1); + }), ((Function0) () -> { + return Double.valueOf(1.0); + }))); } ''') } - @Test - def test_14() { - assertCompilesTo(''' + @Test def test_14() { + ''' import java.util.List class Outer { val x = newArrayList([|1], [|1.0]) } - ''', ''' + '''.assertCompilesTo(''' import java.util.ArrayList; import org.eclipse.xtext.xbase.lib.CollectionLiterals; import org.eclipse.xtext.xbase.lib.Functions.Function0; @SuppressWarnings("all") public class Outer { - private final ArrayList> x = CollectionLiterals.>newArrayList(new Function0() { - public Integer apply() { - return Integer.valueOf(1); - } - }, new Function0() { - public Double apply() { - return Double.valueOf(1.0); - } - }); + private final ArrayList> x = CollectionLiterals.>newArrayList(((Function0) () -> { + return Integer.valueOf(1); + }), ((Function0) () -> { + return Double.valueOf(1.0); + })); } ''') } @Test def test_15() { - assertCompilesTo(''' + ''' import java.util.List class Outer { val List> x = >newArrayList([|1], [|1.0]) } - ''', ''' + '''.assertCompilesTo(''' import java.util.List; import org.eclipse.xtext.xbase.lib.CollectionLiterals; import org.eclipse.xtext.xbase.lib.Functions.Function0; @SuppressWarnings("all") public class Outer { - private final List> x = CollectionLiterals.>newArrayList(new Function0() { - public Number apply() { - return Integer.valueOf(1); - } - }, new Function0() { - public Number apply() { - return Double.valueOf(1.0); - } - }); + private final List> x = CollectionLiterals.>newArrayList(((Function0) () -> { + return Integer.valueOf(1); + }), ((Function0) () -> { + return Double.valueOf(1.0); + })); } ''') } @Test def test_16() { - assertCompilesTo(''' + ''' import java.util.Map class Outer { val Map> y = #{'' -> [|1], '' -> [|1.0]} } - ''', ''' + '''.assertCompilesTo(''' import java.util.Collections; import java.util.Map; import org.eclipse.xtext.xbase.lib.CollectionLiterals; @@ -432,27 +363,23 @@ class CompilerBug435473Test extends AbstractXtendCompilerTest { @SuppressWarnings("all") public class Outer { - private final Map> y = Collections.>unmodifiableMap(CollectionLiterals.>newHashMap(Pair.>of("", new Function0() { - public Integer apply() { - return Integer.valueOf(1); - } - }), Pair.>of("", new Function0() { - public Double apply() { - return Double.valueOf(1.0); - } - }))); + private final Map> y = Collections.>unmodifiableMap(CollectionLiterals.>newHashMap(Pair.>of("", ((Function0) () -> { + return Integer.valueOf(1); + })), Pair.>of("", ((Function0) () -> { + return Double.valueOf(1.0); + })))); } ''') } @Test def test_17() { - assertCompilesTo(''' + ''' import java.util.Map class Outer { val Map> y = #{null as StringBuilder -> [|1], null as StringBuffer -> [|1.0]} } - ''', ''' + '''.assertCompilesTo(''' import java.util.Collections; import java.util.Map; import org.eclipse.xtext.xbase.lib.CollectionLiterals; @@ -461,15 +388,11 @@ class CompilerBug435473Test extends AbstractXtendCompilerTest { @SuppressWarnings("all") public class Outer { - private final Map> y = Collections.>unmodifiableMap(CollectionLiterals.>newHashMap(Pair.>of(((StringBuilder) null), new Function0() { - public Integer apply() { - return Integer.valueOf(1); - } - }), Pair.>of(((StringBuffer) null), new Function0() { - public Double apply() { - return Double.valueOf(1.0); - } - }))); + private final Map> y = Collections.>unmodifiableMap(CollectionLiterals.>newHashMap(Pair.>of(((StringBuilder) null), ((Function0) () -> { + return Integer.valueOf(1); + })), Pair.>of(((StringBuffer) null), ((Function0) () -> { + return Double.valueOf(1.0); + })))); } ''') } @@ -477,44 +400,40 @@ class CompilerBug435473Test extends AbstractXtendCompilerTest { // TODO this should be a list of Comparator - Would be nice but too much effort ATM @Test def test_18() { - assertCompilesTo(''' + ''' class Outer { val x = newArrayList( String.CASE_INSENSITIVE_ORDER, [ $0 <=> $1 ] ) } - ''', ''' + '''.assertCompilesTo(''' import java.util.ArrayList; import java.util.Comparator; import org.eclipse.xtext.xbase.lib.CollectionLiterals; @SuppressWarnings("all") public class Outer { - private final ArrayList> x = CollectionLiterals.>newArrayList(String.CASE_INSENSITIVE_ORDER, new Comparator>>() { - public int compare(final Comparable> $0, final Comparable> $1) { - return ($0.compareTo($1)); - } - }); + private final ArrayList> x = CollectionLiterals.>newArrayList(String.CASE_INSENSITIVE_ORDER, ((Comparator>>) (Comparable> $0, Comparable> $1) -> { + return ($0.compareTo($1)); + })); } ''') } @Test def test_19() { - assertCompilesTo(''' + ''' class Outer { val x = newArrayList( String.CASE_INSENSITIVE_ORDER, [ String s1, s2| s1 <=> s2 ] ) } - ''', ''' + '''.assertCompilesTo(''' import java.util.ArrayList; import java.util.Comparator; import org.eclipse.xtext.xbase.lib.CollectionLiterals; @SuppressWarnings("all") public class Outer { - private final ArrayList> x = CollectionLiterals.>newArrayList(String.CASE_INSENSITIVE_ORDER, new Comparator() { - public int compare(final String s1, final String s2) { - return (s1.compareTo(s2)); - } - }); + private final ArrayList> x = CollectionLiterals.>newArrayList(String.CASE_INSENSITIVE_ORDER, ((Comparator) (String s1, String s2) -> { + return (s1.compareTo(s2)); + })); } ''') } @@ -573,7 +492,7 @@ class CompilerBug435473Test extends AbstractXtendCompilerTest { @Test def test_31() { - assertCompilesTo(''' + ''' import java.util.List class Outer { interface A {} @@ -581,7 +500,7 @@ class CompilerBug435473Test extends AbstractXtendCompilerTest { interface C extends A{} val List> x = #[[| null as B], [| null as C]] } - ''', ''' + '''.assertCompilesTo(''' import java.util.Collections; import java.util.List; import org.eclipse.xtext.xbase.lib.CollectionLiterals; @@ -598,22 +517,18 @@ class CompilerBug435473Test extends AbstractXtendCompilerTest { public interface C extends Outer.A { } - private final List> x = Collections.>unmodifiableList(CollectionLiterals.>newArrayList(new Function0() { - public Object apply() { - return ((Outer.B) null); - } - }, new Function0() { - public Object apply() { - return ((Outer.C) null); - } - })); + private final List> x = Collections.>unmodifiableList(CollectionLiterals.>newArrayList(((Function0) () -> { + return ((Outer.B) null); + }), ((Function0) () -> { + return ((Outer.C) null); + }))); } ''') } @Test def test_32() { - assertCompilesTo(''' + ''' import java.util.List class Outer { interface A {} @@ -621,7 +536,7 @@ class CompilerBug435473Test extends AbstractXtendCompilerTest { interface C extends A{} val List> x = #[[| null as B], [| null as C]] } - ''', ''' + '''.assertCompilesTo(''' import java.util.Collections; import java.util.List; import org.eclipse.xtext.xbase.lib.CollectionLiterals; @@ -638,22 +553,18 @@ class CompilerBug435473Test extends AbstractXtendCompilerTest { public interface C extends Outer.A { } - private final List> x = Collections.>unmodifiableList(CollectionLiterals.>newArrayList(new Function0() { - public Outer.A apply() { - return ((Outer.B) null); - } - }, new Function0() { - public Outer.A apply() { - return ((Outer.C) null); - } - })); + private final List> x = Collections.>unmodifiableList(CollectionLiterals.>newArrayList(((Function0) () -> { + return ((Outer.B) null); + }), ((Function0) () -> { + return ((Outer.C) null); + }))); } ''') } @Test def test_33() { - assertCompilesTo(''' + ''' import java.util.List class Outer { interface A {} @@ -661,7 +572,7 @@ class CompilerBug435473Test extends AbstractXtendCompilerTest { interface C extends A{} val List> x = #[[| null as B], [| null as C]] } - ''', ''' + '''.assertCompilesTo(''' import java.util.Collections; import java.util.List; import org.eclipse.xtext.xbase.lib.CollectionLiterals; @@ -678,22 +589,18 @@ class CompilerBug435473Test extends AbstractXtendCompilerTest { public interface C extends Outer.A { } - private final List> x = Collections.>unmodifiableList(CollectionLiterals.>newArrayList(new Function0() { - public Outer.A apply() { - return ((Outer.B) null); - } - }, new Function0() { - public Outer.A apply() { - return ((Outer.C) null); - } - })); + private final List> x = Collections.>unmodifiableList(CollectionLiterals.>newArrayList(((Function0) () -> { + return ((Outer.B) null); + }), ((Function0) () -> { + return ((Outer.C) null); + }))); } ''') } @Test def test_34() { - assertCompilesTo(''' + ''' import java.util.List class Outer { interface A {} @@ -701,7 +608,7 @@ class CompilerBug435473Test extends AbstractXtendCompilerTest { interface C extends A{} val List> x = #[[| null as B], [| null as C]] } - ''', ''' + '''.assertCompilesTo(''' import java.util.Collections; import java.util.List; import org.eclipse.xtext.xbase.lib.CollectionLiterals; @@ -718,22 +625,18 @@ class CompilerBug435473Test extends AbstractXtendCompilerTest { public interface C extends Outer.A { } - private final List> x = Collections.>unmodifiableList(CollectionLiterals.>newArrayList(new Function0() { - public Outer.A apply() { - return ((Outer.B) null); - } - }, new Function0() { - public Outer.A apply() { - return ((Outer.C) null); - } - })); + private final List> x = Collections.>unmodifiableList(CollectionLiterals.>newArrayList(((Function0) () -> { + return ((Outer.B) null); + }), ((Function0) () -> { + return ((Outer.C) null); + }))); } ''') } @Test def test_35() { - assertCompilesTo(''' + ''' import java.util.Set class Outer { interface A {} @@ -741,7 +644,7 @@ class CompilerBug435473Test extends AbstractXtendCompilerTest { interface C extends A{} val Set> x = #{ [| null as B], [| null as C] } } - ''', ''' + '''.assertCompilesTo(''' import java.util.Collections; import java.util.Set; import org.eclipse.xtext.xbase.lib.CollectionLiterals; @@ -758,22 +661,18 @@ class CompilerBug435473Test extends AbstractXtendCompilerTest { public interface C extends Outer.A { } - private final Set> x = Collections.>unmodifiableSet(CollectionLiterals.>newHashSet(new Function0() { - public Outer.A apply() { - return ((Outer.B) null); - } - }, new Function0() { - public Outer.A apply() { - return ((Outer.C) null); - } - })); + private final Set> x = Collections.>unmodifiableSet(CollectionLiterals.>newHashSet(((Function0) () -> { + return ((Outer.B) null); + }), ((Function0) () -> { + return ((Outer.C) null); + }))); } ''') } @Test def test_36() { - assertCompilesTo(''' + ''' import java.util.Set class Outer { interface A {} @@ -781,7 +680,7 @@ class CompilerBug435473Test extends AbstractXtendCompilerTest { interface C extends A{} val Set> x = #{ [| null as B], [| null as C] } } - ''', ''' + '''.assertCompilesTo(''' import java.util.Collections; import java.util.Set; import org.eclipse.xtext.xbase.lib.CollectionLiterals; @@ -798,22 +697,18 @@ class CompilerBug435473Test extends AbstractXtendCompilerTest { public interface C extends Outer.A { } - private final Set> x = Collections.>unmodifiableSet(CollectionLiterals.>newHashSet(new Function0() { - public Outer.A apply() { - return ((Outer.B) null); - } - }, new Function0() { - public Outer.A apply() { - return ((Outer.C) null); - } - })); + private final Set> x = Collections.>unmodifiableSet(CollectionLiterals.>newHashSet(((Function0) () -> { + return ((Outer.B) null); + }), ((Function0) () -> { + return ((Outer.C) null); + }))); } ''') } @Test def test_37() { - assertCompilesTo(''' + ''' import java.util.Set class Outer { interface A {} @@ -821,7 +716,7 @@ class CompilerBug435473Test extends AbstractXtendCompilerTest { interface C extends A{} val Set> x = #{ [| null as B], [| null as C] } } - ''', ''' + '''.assertCompilesTo(''' import java.util.Collections; import java.util.Set; import org.eclipse.xtext.xbase.lib.CollectionLiterals; @@ -838,22 +733,18 @@ class CompilerBug435473Test extends AbstractXtendCompilerTest { public interface C extends Outer.A { } - private final Set> x = Collections.>unmodifiableSet(CollectionLiterals.>newHashSet(new Function0() { - public Outer.A apply() { - return ((Outer.B) null); - } - }, new Function0() { - public Outer.A apply() { - return ((Outer.C) null); - } - })); + private final Set> x = Collections.>unmodifiableSet(CollectionLiterals.>newHashSet(((Function0) () -> { + return ((Outer.B) null); + }), ((Function0) () -> { + return ((Outer.C) null); + }))); } ''') } @Test def test_38() { - assertCompilesTo(''' + ''' import java.util.Set class Outer { interface A {} @@ -861,7 +752,7 @@ class CompilerBug435473Test extends AbstractXtendCompilerTest { interface C extends A{} val Set> x = #{ [| null as B], [| null as C] } } - ''', ''' + '''.assertCompilesTo(''' import java.util.Collections; import java.util.Set; import org.eclipse.xtext.xbase.lib.CollectionLiterals; @@ -878,22 +769,18 @@ class CompilerBug435473Test extends AbstractXtendCompilerTest { public interface C extends Outer.A { } - private final Set> x = Collections.>unmodifiableSet(CollectionLiterals.>newHashSet(new Function0() { - public Outer.A apply() { - return ((Outer.B) null); - } - }, new Function0() { - public Outer.A apply() { - return ((Outer.C) null); - } - })); + private final Set> x = Collections.>unmodifiableSet(CollectionLiterals.>newHashSet(((Function0) () -> { + return ((Outer.B) null); + }), ((Function0) () -> { + return ((Outer.C) null); + }))); } ''') } @Test def test_39() { - assertCompilesTo(''' + ''' import java.util.List class Outer { interface A {} @@ -901,7 +788,7 @@ class CompilerBug435473Test extends AbstractXtendCompilerTest { interface C extends A{} val List> x = newArrayList([| null as B], [| null as C]) } - ''', ''' + '''.assertCompilesTo(''' import java.util.List; import org.eclipse.xtext.xbase.lib.CollectionLiterals; import org.eclipse.xtext.xbase.lib.Functions.Function0; @@ -917,22 +804,18 @@ class CompilerBug435473Test extends AbstractXtendCompilerTest { public interface C extends Outer.A { } - private final List> x = CollectionLiterals.>newArrayList(new Function0() { - public Outer.B apply() { - return ((Outer.B) null); - } - }, new Function0() { - public Outer.C apply() { - return ((Outer.C) null); - } - }); + private final List> x = CollectionLiterals.>newArrayList(((Function0) () -> { + return ((Outer.B) null); + }), ((Function0) () -> { + return ((Outer.C) null); + })); } ''') } @Test def test_40() { - assertCompilesTo(''' + ''' import java.util.List class Outer { interface A {} @@ -940,7 +823,7 @@ class CompilerBug435473Test extends AbstractXtendCompilerTest { interface C extends A{} val List> x = newArrayList([| null as B], [| null as C]) } - ''', ''' + '''.assertCompilesTo(''' import java.util.List; import org.eclipse.xtext.xbase.lib.CollectionLiterals; import org.eclipse.xtext.xbase.lib.Functions.Function0; @@ -956,22 +839,18 @@ class CompilerBug435473Test extends AbstractXtendCompilerTest { public interface C extends Outer.A { } - private final List> x = CollectionLiterals.>newArrayList(new Function0() { - public Outer.B apply() { - return ((Outer.B) null); - } - }, new Function0() { - public Outer.C apply() { - return ((Outer.C) null); - } - }); + private final List> x = CollectionLiterals.>newArrayList(((Function0) () -> { + return ((Outer.B) null); + }), ((Function0) () -> { + return ((Outer.C) null); + })); } ''') } @Test def test_41() { - assertCompilesTo(''' + ''' import java.util.List class Outer { interface A {} @@ -979,7 +858,7 @@ class CompilerBug435473Test extends AbstractXtendCompilerTest { interface C extends A{} val List> x = newArrayList([| null as B], [| null as C]) } - ''', ''' + '''.assertCompilesTo(''' import java.util.List; import org.eclipse.xtext.xbase.lib.CollectionLiterals; import org.eclipse.xtext.xbase.lib.Functions.Function0; @@ -995,15 +874,11 @@ class CompilerBug435473Test extends AbstractXtendCompilerTest { public interface C extends Outer.A { } - private final List> x = CollectionLiterals.>newArrayList(new Function0() { - public Outer.B apply() { - return ((Outer.B) null); - } - }, new Function0() { - public Outer.C apply() { - return ((Outer.C) null); - } - }); + private final List> x = CollectionLiterals.>newArrayList(((Function0) () -> { + return ((Outer.B) null); + }), ((Function0) () -> { + return ((Outer.C) null); + })); } ''') } @@ -1026,7 +901,7 @@ class CompilerBug435473Test extends AbstractXtendCompilerTest { @Test def test_43() { - assertCompilesTo(''' + ''' import java.util.List class Outer { interface A {} @@ -1034,7 +909,7 @@ class CompilerBug435473Test extends AbstractXtendCompilerTest { interface C extends A{} val x = #[[| null as B], [| null as C]] } - ''', ''' + '''.assertCompilesTo(''' import java.util.Collections; import java.util.List; import org.eclipse.xtext.xbase.lib.CollectionLiterals; @@ -1051,22 +926,18 @@ class CompilerBug435473Test extends AbstractXtendCompilerTest { public interface C extends Outer.A { } - private final List> x = Collections.>unmodifiableList(CollectionLiterals.>newArrayList(new Function0() { - public Outer.B apply() { - return ((Outer.B) null); - } - }, new Function0() { - public Outer.C apply() { - return ((Outer.C) null); - } - })); + private final List> x = Collections.>unmodifiableList(CollectionLiterals.>newArrayList(((Function0) () -> { + return ((Outer.B) null); + }), ((Function0) () -> { + return ((Outer.C) null); + }))); } ''') } @Test def test_44() { - assertCompilesTo(''' + ''' import java.util.List class Outer { interface A {} @@ -1074,7 +945,7 @@ class CompilerBug435473Test extends AbstractXtendCompilerTest { interface C extends A{} val x = newArrayList([| null as B], [| null as C]) } - ''', ''' + '''.assertCompilesTo(''' import java.util.ArrayList; import org.eclipse.xtext.xbase.lib.CollectionLiterals; import org.eclipse.xtext.xbase.lib.Functions.Function0; @@ -1090,15 +961,11 @@ class CompilerBug435473Test extends AbstractXtendCompilerTest { public interface C extends Outer.A { } - private final ArrayList> x = CollectionLiterals.>newArrayList(new Function0() { - public Outer.B apply() { - return ((Outer.B) null); - } - }, new Function0() { - public Outer.C apply() { - return ((Outer.C) null); - } - }); + private final ArrayList> x = CollectionLiterals.>newArrayList(((Function0) () -> { + return ((Outer.B) null); + }), ((Function0) () -> { + return ((Outer.C) null); + })); } ''') } diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug436230Test.xtend b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug436230Test.xtend index 1fc74694c18..372c9fe91e6 100644 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug436230Test.xtend +++ b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug436230Test.xtend @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2014, 2016 itemis AG (http://www.itemis.eu) and others. + * Copyright (c) 2014, 2024 itemis AG (http://www.itemis.eu) and others. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. @@ -37,10 +37,8 @@ class CompilerBug436230Test extends AbstractXtendCompilerTest { private final List list = CollectionLiterals.newArrayList(); public boolean foo(final List source) { - final Function1 _function = new Function1() { - public String apply(final Object it) { - return ""; - } + final Function1 _function = (Object it) -> { + return ""; }; List _map = ListExtensions.map(source, _function); return Iterables.addAll(this.list, _map); @@ -73,10 +71,8 @@ class CompilerBug436230Test extends AbstractXtendCompilerTest { { final List res = null; final Iterable obj = null; - final Function1 _function = new Function1() { - public String apply(final Object it) { - return ""; - } + final Function1 _function = (Object it) -> { + return ""; }; Iterable _map = IterableExtensions.map(obj, _function); _xblockexpression = Iterables.addAll(res, _map); @@ -111,10 +107,8 @@ class CompilerBug436230Test extends AbstractXtendCompilerTest { { final List res = null; final Iterable obj = null; - final Function1 _function = new Function1() { - public String apply(final Object it) { - return ""; - } + final Function1 _function = (Object it) -> { + return ""; }; Iterable _map = IterableExtensions.map(obj, _function); _xblockexpression = Iterables.addAll(res, _map); @@ -145,10 +139,8 @@ class CompilerBug436230Test extends AbstractXtendCompilerTest { Iterable _xblockexpression = null; { final Iterable obj = null; - final Function1 _function = new Function1() { - public String apply(final Object it) { - return ""; - } + final Function1 _function = (Object it) -> { + return ""; }; _xblockexpression = IterableExtensions.map(obj, _function); } diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug436886Test.xtend b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug436886Test.xtend index 913d10c9b13..821ed7402a2 100644 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug436886Test.xtend +++ b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug436886Test.xtend @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2014 itemis AG (http://www.itemis.eu) and others. + * Copyright (c) 2014, 2024 itemis AG (http://www.itemis.eu) and others. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. @@ -44,25 +44,23 @@ class CompilerBug436886Test extends AbstractXtendCompilerTest { } public Test method() { - final Function1 _function = new Function1() { - public Boolean apply(final Super it) { - boolean _switchResult = false; - boolean _matched = false; - if (it instanceof Foo) { + final Function1 _function = (Super it) -> { + boolean _switchResult = false; + boolean _matched = false; + if (it instanceof Foo) { + _matched=true; + _switchResult = true; + } + if (!_matched) { + if (it instanceof Bar) { _matched=true; _switchResult = true; } - if (!_matched) { - if (it instanceof Bar) { - _matched=true; - _switchResult = true; - } - } - if (!_matched) { - _switchResult = false; - } - return Boolean.valueOf(_switchResult); } + if (!_matched) { + _switchResult = false; + } + return Boolean.valueOf(_switchResult); }; return new Test(_function); } diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug440196Test.xtend b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug440196Test.xtend index 714fe063636..53cadcf065e 100644 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug440196Test.xtend +++ b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug440196Test.xtend @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2014 itemis AG (http://www.itemis.eu) and others. + * Copyright (c) 2014, 2024 itemis AG (http://www.itemis.eu) and others. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. @@ -60,13 +60,11 @@ class CompilerBug440196Test extends AbstractXtendCompilerTest { @SuppressWarnings("all") public class C { public Boolean m() { - final Function0 _function = new Function0() { - public Boolean apply() { - if ((Boolean.TRUE).booleanValue()) { - return true; - } - return null; + final Function0 _function = () -> { + if ((Boolean.TRUE).booleanValue()) { + return true; } + return null; }; return _function.apply(); } diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug440902Test.xtend b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug440902Test.xtend index b14e69911ca..30f1a872844 100644 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug440902Test.xtend +++ b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug440902Test.xtend @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2014, 2016 itemis AG (http://www.itemis.eu) and others. + * Copyright (c) 2014, 2024 itemis AG (http://www.itemis.eu) and others. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. @@ -36,6 +36,7 @@ class CompilerBug440902Test extends AbstractXtendCompilerTest { return this.m().toString(); } + @Override public String m() { throw new RuntimeException(); } @@ -57,6 +58,7 @@ class CompilerBug440902Test extends AbstractXtendCompilerTest { ''', ''' @SuppressWarnings("all") public class C implements I { + @Override public String m() { throw new RuntimeException(); } diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug440906Test.xtend b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug440906Test.xtend index 8e6ccffdcdb..fc2e76f7a17 100644 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug440906Test.xtend +++ b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug440906Test.xtend @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2014, 2016 itemis AG (http://www.itemis.eu) and others. + * Copyright (c) 2014, 2024 itemis AG (http://www.itemis.eu) and others. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. @@ -38,10 +38,8 @@ class CompilerBug440906Test extends AbstractXtendCompilerTest { @SuppressWarnings("all") public class C { public Function2 m() { - final Function2 _function = new Function2() { - public Integer apply(final Object a, final Object b) { - return Integer.valueOf(1); - } + final Function2 _function = (Object a, Object b) -> { + return Integer.valueOf(1); }; return _function; } @@ -80,10 +78,8 @@ class CompilerBug440906Test extends AbstractXtendCompilerTest { @SuppressWarnings("all") public class C { public Function2 m() { - final Function2 _function = new Function2() { - public Integer apply(final Object a, final Object b) { - return Integer.valueOf(1); - } + final Function2 _function = (Object a, Object b) -> { + return Integer.valueOf(1); }; return _function; } diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug441096Test.xtend b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug441096Test.xtend index c4bf3607f4b..c501bdd3325 100644 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug441096Test.xtend +++ b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug441096Test.xtend @@ -60,6 +60,7 @@ class CompilerBug441096Test extends AbstractXtendCompilerTest { } private final C.I x = new C.I() { + @Override public void m() { } }; diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug445487Test.xtend b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug445487Test.xtend index c224e2dccd0..41284a11e2b 100644 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug445487Test.xtend +++ b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug445487Test.xtend @@ -15,91 +15,81 @@ import org.junit.Test */ class CompilerBug445487Test extends AbstractXtendCompilerTest { - @Test - def test_01() { - assertCompilesTo(''' + @Test def test_01() { + ''' import com.google.inject.Provider import org.antlr.runtime.Lexer import org.eclipse.xtend.core.parser.antlr.internal.InternalXtendLexer class C { Provider lexerProvider= [return new InternalXtendLexer(null)] } - ''', ''' + '''.assertCompilesTo(''' import com.google.inject.Provider; import org.antlr.runtime.Lexer; import org.eclipse.xtend.core.parser.antlr.internal.InternalXtendLexer; @SuppressWarnings("all") public class C { - private Provider lexerProvider = new Provider() { - public Lexer get() { - return new InternalXtendLexer(null); - } - }; + private Provider lexerProvider = ((Provider) () -> { + return new InternalXtendLexer(null); + }); } ''') } - @Test - def test_02() { - assertCompilesTo(''' + @Test def test_02() { + ''' import com.google.inject.Provider import org.antlr.runtime.Lexer import org.eclipse.xtend.core.parser.antlr.internal.InternalXtendLexer class C { Provider lexerProvider= [return new InternalXtendLexer(null)] } - ''', ''' + '''.assertCompilesTo(''' import com.google.inject.Provider; import org.antlr.runtime.Lexer; import org.eclipse.xtend.core.parser.antlr.internal.InternalXtendLexer; @SuppressWarnings("all") public class C { - private Provider lexerProvider = new Provider() { - public Lexer get() { - return new InternalXtendLexer(null); - } - }; + private Provider lexerProvider = ((Provider) () -> { + return new InternalXtendLexer(null); + }); } ''') } - @Test - def test_03() { - assertCompilesTo(''' + @Test def test_03() { + ''' import com.google.inject.Provider import org.antlr.runtime.Lexer import org.eclipse.xtend.core.parser.antlr.internal.InternalXtendLexer class C { Provider lexerProvider= [return new InternalXtendLexer(null)] } - ''', ''' + '''.assertCompilesTo(''' import com.google.inject.Provider; import org.antlr.runtime.Lexer; import org.eclipse.xtend.core.parser.antlr.internal.InternalXtendLexer; @SuppressWarnings("all") public class C { - private Provider lexerProvider = new Provider() { - public Lexer get() { - return new InternalXtendLexer(null); - } - }; + private Provider lexerProvider = ((Provider) () -> { + return new InternalXtendLexer(null); + }); } ''') } - @Test - def test_04() { - assertCompilesTo(''' + @Test def test_04() { + ''' import com.google.inject.Provider import org.antlr.runtime.Lexer import org.eclipse.xtend.core.parser.antlr.internal.InternalXtendLexer class C { Provider lexerProvider= [|return new InternalXtendLexer(null)] as Provider } - ''', ''' + '''.assertCompilesTo(''' import com.google.inject.Provider; import org.antlr.runtime.Lexer; import org.eclipse.xtend.core.parser.antlr.internal.InternalXtendLexer; @@ -109,27 +99,24 @@ class CompilerBug445487Test extends AbstractXtendCompilerTest { public class C { private Provider lexerProvider = ((Provider) new Provider() { public Lexer get() { - return new Function0() { - public InternalXtendLexer apply() { - return new InternalXtendLexer(null); - } - }.apply(); + return ((Function0) () -> { + return new InternalXtendLexer(null); + }).apply(); } }); } ''') } - @Test - def test_05() { - assertCompilesTo(''' + @Test def test_05() { + ''' import com.google.inject.Provider import org.antlr.runtime.Lexer import org.eclipse.xtend.core.parser.antlr.internal.InternalXtendLexer class C { Provider lexerProvider= [|return new InternalXtendLexer(null)] as ()=>Lexer } - ''', ''' + '''.assertCompilesTo(''' import com.google.inject.Provider; import org.antlr.runtime.Lexer; import org.eclipse.xtend.core.parser.antlr.internal.InternalXtendLexer; @@ -139,19 +126,16 @@ class CompilerBug445487Test extends AbstractXtendCompilerTest { public class C { private Provider lexerProvider = new Provider() { public Lexer get() { - return ((Function0) new Function0() { - public InternalXtendLexer apply() { - return new InternalXtendLexer(null); - } - }).apply(); + return ((Function0) ((Function0) () -> { + return new InternalXtendLexer(null); + })).apply(); } }; } ''') } - - @Test - def test_06() { + + @Test def test_06() { assertCompilesTo(''' import com.google.inject.Provider import org.antlr.runtime.Lexer @@ -169,19 +153,16 @@ class CompilerBug445487Test extends AbstractXtendCompilerTest { public class C { private Provider lexerProvider = ((Provider) new Provider() { public Lexer get() { - return new Function1() { - public InternalXtendLexer apply(final Object it) { - return new InternalXtendLexer(null); - } - }.apply(null); + return ((Function1) (Object it) -> { + return new InternalXtendLexer(null); + }).apply(null); } }); } ''') } - @Test - def test_07() { + @Test def test_07() { assertCompilesTo(''' import com.google.inject.Provider import org.antlr.runtime.Lexer @@ -202,11 +183,9 @@ class CompilerBug445487Test extends AbstractXtendCompilerTest { public Lexer get() { return ((Function0) new Function0() { public Lexer apply() { - return new Function1() { - public InternalXtendLexer apply(final Object it) { - return new InternalXtendLexer(null); - } - }.apply(null); + return ((Function1) (Object it) -> { + return new InternalXtendLexer(null); + }).apply(null); } }).apply(); } diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug447516Test.xtend b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug447516Test.xtend index fdffe8add6e..baf144660ba 100644 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug447516Test.xtend +++ b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug447516Test.xtend @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2014 itemis AG (http://www.itemis.eu) and others. + * Copyright (c) 2014, 20204 itemis AG (http://www.itemis.eu) and others. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. @@ -32,6 +32,7 @@ class CompilerBug447516Test extends AbstractXtendCompilerTest { @SuppressWarnings("all") public class C { private final IReadAccess readAccess = new IReadAccess() { + @Override public Result readOnly(final IUnitOfWork it) { try { return it.exec(""); @@ -67,6 +68,7 @@ class CompilerBug447516Test extends AbstractXtendCompilerTest { } private final C.I readAccess = new C.I() { + @Override public T exec(final Function1 it) { return it.apply(""); } @@ -98,6 +100,7 @@ class CompilerBug447516Test extends AbstractXtendCompilerTest { } private final C.I i = new C.I() { + @Override public T exec(final String $0, final Function1 $1) { return $1.apply(""); } diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug447551Test.xtend b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug447551Test.xtend index ceb6637821f..6b653aa56e3 100644 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug447551Test.xtend +++ b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug447551Test.xtend @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2014, 2016 itemis AG (http://www.itemis.eu) and others. + * Copyright (c) 2014, 2024 itemis AG (http://www.itemis.eu) and others. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. @@ -132,6 +132,7 @@ class CompilerBug447551Test extends AbstractXtendCompilerTest { } public final C.E e = new Function0>() { + @Override public C.E apply() { try { C.E _copy = C.E.copy(CollectionLiterals.newArrayList()); diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug456883Test.xtend b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug456883Test.xtend index d4218066680..1072f277e5d 100644 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug456883Test.xtend +++ b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug456883Test.xtend @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2015 itemis AG (http://www.itemis.eu) and others. + * Copyright (c) 2015, 2024 itemis AG (http://www.itemis.eu) and others. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. @@ -41,16 +41,15 @@ class CompilerBug456883Test extends AbstractXtendCompilerTest { public class XtendCompilationError { public XtendCompilationError() { ArrayList _arrayList = new ArrayList(); - final Procedure1> _function = new Procedure1>() { - public void apply(final ArrayList it) { - final int finalValue = 1; - it.add( - new Object() { - public String toString() { - return ("" + Integer.valueOf(finalValue)); - } - }); - } + final Procedure1> _function = (ArrayList it) -> { + final int finalValue = 1; + it.add( + new Object() { + @Override + public String toString() { + return ("" + Integer.valueOf(finalValue)); + } + }); }; ObjectExtensions.>operator_doubleArrow(_arrayList, _function); } diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug457333Test.xtend b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug457333Test.xtend index cb8cffd71a9..07ee464291b 100644 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug457333Test.xtend +++ b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug457333Test.xtend @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2015 itemis AG (http://www.itemis.eu) and others. + * Copyright (c) 2015, 2024 itemis AG (http://www.itemis.eu) and others. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. @@ -54,36 +54,29 @@ class CompilerBug457333Test extends AbstractXtendCompilerTest { import org.eclipse.xtext.xbase.lib.Functions.Function0; import org.eclipse.xtext.xbase.lib.Pair; import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; - + @SuppressWarnings("all") public class XtendPlugin implements Procedure1 { public interface Action { void exec(final T t); } + @Override public void apply(final String project) { - final Consumer _function = new Consumer() { - public void accept(final String sourceSet) { - final XtendPlugin.Action _function = new XtendPlugin.Action() { - public void exec(final Object it) { - final Function0 _function = new Function0() { - public Character apply() { - return Character.valueOf(sourceSet.charAt(0)); - } - }; - Pair> _mappedTo = Pair.>of("classpath", _function); - final Function0 _function_1 = new Function0() { - public Character apply() { - return Character.valueOf(sourceSet.charAt(0)); - } - }; - Pair> _mappedTo_1 = Pair.>of("bootClasspath", _function_1); - XtendPlugin.conventionMapping(it, - Collections.>unmodifiableMap(CollectionLiterals.>newHashMap(_mappedTo, _mappedTo_1))); - } + final Consumer _function = (String sourceSet) -> { + final XtendPlugin.Action _function_1 = (Object it) -> { + final Function0 _function_2 = () -> { + return Character.valueOf(sourceSet.charAt(0)); + }; + Pair> _mappedTo = Pair.>of("classpath", _function_2); + final Function0 _function_3 = () -> { + return Character.valueOf(sourceSet.charAt(0)); }; - XtendPlugin.this.create("", Object.class, _function); - } + Pair> _mappedTo_1 = Pair.>of("bootClasspath", _function_3); + XtendPlugin.conventionMapping(it, + Collections.>unmodifiableMap(CollectionLiterals.>newHashMap(_mappedTo, _mappedTo_1))); + }; + this.create("", Object.class, _function_1); }; Collections.unmodifiableList(CollectionLiterals.newArrayList("")).forEach(_function); } diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug457346Test.xtend b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug457346Test.xtend index 7c3df2eba8f..eec1c8381ee 100644 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug457346Test.xtend +++ b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug457346Test.xtend @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2015, 2016 itemis AG (http://www.itemis.eu) and others. + * Copyright (c) 2015, 2024 itemis AG (http://www.itemis.eu) and others. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. @@ -35,15 +35,11 @@ class CompilerBug457346Test extends AbstractXtendCompilerTest { @SuppressWarnings("all") public class C { public List m() { - final Function _function = new Function() { - public Integer apply(final String s) { - return Integer.valueOf(s.length()); - } + final Function _function = (String s) -> { + return Integer.valueOf(s.length()); }; - final Function _function_1 = new Function() { - public String apply(final String it) { - return null; - } + final Function _function_1 = (String it) -> { + return null; }; return IterableExtensions.sortWith(Collections.unmodifiableList(CollectionLiterals.newArrayList("a", "aa", "aaa")), Ordering.natural().onResultOf(_function).onResultOf(_function_1)); } @@ -76,15 +72,11 @@ class CompilerBug457346Test extends AbstractXtendCompilerTest { } public void m(final C.Sortable sortMe) { - final Function _function = new Function() { - public Integer apply(final String s) { - return Integer.valueOf(s.length()); - } + final Function _function = (String s) -> { + return Integer.valueOf(s.length()); }; - final Function _function_1 = new Function() { - public String apply(final String it) { - return null; - } + final Function _function_1 = (String it) -> { + return null; }; sortMe.sort(Ordering.natural().onResultOf(_function).onResultOf(_function_1)); } @@ -137,15 +129,11 @@ class CompilerBug457346Test extends AbstractXtendCompilerTest { } public void m(final C.Sortable sortMe) { - final C.ToIntFunction _function = new C.ToIntFunction() { - public int apply(final String s) { - return s.length(); - } + final C.ToIntFunction _function = (String s) -> { + return s.length(); }; - final Function1 _function_1 = new Function1() { - public String apply(final String s) { - return s; - } + final Function1 _function_1 = (String s) -> { + return s; }; sortMe.sort(C.MyComparator.comparingInt2(_function).thenComparing2(_function_1)); } @@ -198,15 +186,11 @@ class CompilerBug457346Test extends AbstractXtendCompilerTest { } public void m(final C.Sortable sortMe) { - final C.ToIntFunction _function = new C.ToIntFunction() { - public int apply(final String s) { - return s.length(); - } + final C.ToIntFunction _function = (String s) -> { + return s.length(); }; - final Function1 _function_1 = new Function1() { - public String apply(final String it) { - return it.toUpperCase(); - } + final Function1 _function_1 = (String it) -> { + return it.toUpperCase(); }; sortMe.sort(C.MyComparator.comparingInt2(_function).thenComparing2(_function_1)); } @@ -259,15 +243,11 @@ class CompilerBug457346Test extends AbstractXtendCompilerTest { } public void m(final C.Sortable sortMe) { - final C.ToIntFunction _function = new C.ToIntFunction() { - public int apply(final String s) { - return s.length(); - } + final C.ToIntFunction _function = (String s) -> { + return s.length(); }; - final Function1 _function_1 = new Function1() { - public String apply(final String it) { - return it; - } + final Function1 _function_1 = (String it) -> { + return it; }; sortMe.sort(C.MyComparator.comparingInt2(_function).thenComparing2(_function_1)); } @@ -323,15 +303,11 @@ class CompilerBug457346Test extends AbstractXtendCompilerTest { } public C.MyComparator m() { - final C.ToIntFunction _function = new C.ToIntFunction() { - public int apply(final String s) { - return s.length(); - } + final C.ToIntFunction _function = (String s) -> { + return s.length(); }; - final C.Function _function_1 = new C.Function() { - public String apply(final String it) { - return it; - } + final C.Function _function_1 = (String it) -> { + return it; }; return C.MyComparator.comparingInt(_function).thenComparing(_function_1); } diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug457350Test.xtend b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug457350Test.xtend index 73efa9a588d..fff1ebe96d9 100644 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug457350Test.xtend +++ b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug457350Test.xtend @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2015 itemis AG (http://www.itemis.eu) and others. + * Copyright (c) 2015, 2024 itemis AG (http://www.itemis.eu) and others. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. @@ -35,10 +35,12 @@ class CompilerBug457350Test extends AbstractXtendCompilerTest { public void test() { final Runnable _function = new Runnable() { final Runnable _self = this; + @Override public void run() { new Runnable() { + @Override public void run() { - _self.run(); + Runnable.super.run(); this.run(); } }; @@ -70,21 +72,21 @@ class CompilerBug457350Test extends AbstractXtendCompilerTest { @SuppressWarnings("all") public class Test { public void test() { - final Procedure1 _function = new Procedure1() { - public void apply(final Object it) { - final Runnable _function = new Runnable() { - final Runnable _self = this; - public void run() { - new Runnable() { - public void run() { - _self.run(); - this.run(); - } - }; - } - }; - final Runnable r1 = _function; - } + final Procedure1 _function = (Object it) -> { + final Runnable _function_1 = new Runnable() { + final Runnable _self = this; + @Override + public void run() { + new Runnable() { + @Override + public void run() { + Runnable.super.run(); + this.run(); + } + }; + } + }; + final Runnable r1 = _function_1; }; _function.apply(null); } @@ -112,8 +114,10 @@ class CompilerBug457350Test extends AbstractXtendCompilerTest { public void test() { new Runnable() { final Runnable _this = this; + @Override public void run() { final Runnable _function = new Runnable() { + @Override public void run() { this.run(); _this.run(); @@ -153,8 +157,10 @@ class CompilerBug457350Test extends AbstractXtendCompilerTest { } new __Test_1() { + @Override public void run() { final Runnable _function = new Runnable() { + @Override public void run() { this.run(); _this__Test_1.run(); @@ -192,21 +198,21 @@ class CompilerBug457350Test extends AbstractXtendCompilerTest { @SuppressWarnings("all") public class Test { public void test() { - final Function1 _function = new Function1() { - public Runnable apply(final Object it) { - return new Runnable() { - final Runnable _this = this; - public void run() { - final Runnable _function = new Runnable() { - public void run() { - this.run(); - _this.run(); - } - }; - final Runnable r1 = _function; - } - }; - } + final Function1 _function = (Object it) -> { + return new Runnable() { + final Runnable _this = this; + @Override + public void run() { + final Runnable _function = new Runnable() { + @Override + public void run() { + this.run(); + _this.run(); + } + }; + final Runnable r1 = _function; + } + }; }; _function.apply(null); } @@ -234,14 +240,13 @@ class CompilerBug457350Test extends AbstractXtendCompilerTest { @SuppressWarnings("all") public class Test extends SuperFoo { public void test() { - final Runnable _function = new Runnable() { - public void run() { - new Runnable() { - public void run() { - Test.super.bar(); - } - }; - } + final Runnable _function = () -> { + new Runnable() { + @Override + public void run() { + Test.super.bar(); + } + }; }; final Runnable r1 = _function; } diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug457539Test.xtend b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug457539Test.xtend index 1e12b8707a2..67f7fd7962d 100644 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug457539Test.xtend +++ b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug457539Test.xtend @@ -21,31 +21,25 @@ class CompilerBug457539Test extends AbstractXtendCompilerTest { class C { def m() { val list = new ArrayList - list.forEach2 [ + list.forEach [ if (it instanceof String) list.add(it) ] } - def void forEach2(Iterable it, (T)=>void f) {} } '''.assertCompilesTo(''' import java.util.ArrayList; - import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; + import java.util.function.Consumer; @SuppressWarnings("all") public class C { public void m() { final ArrayList list = new ArrayList(); - final Procedure1 _function = new Procedure1() { - public void apply(final Object it) { - if ((it instanceof String)) { - list.add(it); - } + final Consumer _function = (Object it) -> { + if ((it instanceof String)) { + list.add(it); } }; - this.forEach2(list, _function); - } - - public void forEach2(final Iterable it, final Procedure1 f) { + list.forEach(_function); } } ''') @@ -55,45 +49,27 @@ class CompilerBug457539Test extends AbstractXtendCompilerTest { ''' class C { def m() { - val list = newIterable - list.forEach2 [ + val list = newArrayList + list.forEach [ if (it instanceof String) list.add(it) ] } - def static MyIterable newIterable(T... initial) {} - interface MyIterable extends Iterable { - def void forEach2((T)=>void f) - def void add(T t) - def T get() - } } '''.assertCompilesTo(''' - import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; + import java.util.ArrayList; + import java.util.function.Consumer; + import org.eclipse.xtext.xbase.lib.CollectionLiterals; @SuppressWarnings("all") public class C { - public interface MyIterable extends Iterable { - void forEach2(final Procedure1 f); - - void add(final T t); - - T get(); - } - public void m() { - final C.MyIterable list = C.newIterable(); - final Procedure1 _function = new Procedure1() { - public void apply(final Object it) { - if ((it instanceof String)) { - list.add(it); - } + final ArrayList list = CollectionLiterals.newArrayList(); + final Consumer _function = (Object it) -> { + if ((it instanceof String)) { + list.add(it); } }; - list.forEach2(_function); - } - - public static C.MyIterable newIterable(final T... initial) { - return null; + list.forEach(_function); } } ''') @@ -104,37 +80,26 @@ class CompilerBug457539Test extends AbstractXtendCompilerTest { class C { def m() { val list = newIterable - - list.forEach2 [ + list.forEach [ ] } def static MyIterable newIterable(T... initial) {} interface MyIterable extends Iterable { - def void forEach2((T)=>void f) - def void add(T t) - def T get() } } '''.assertCompilesTo(''' - import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; + import java.util.function.Consumer; @SuppressWarnings("all") public class C { public interface MyIterable extends Iterable { - void forEach2(final Procedure1 f); - - void add(final T t); - - T get(); } public void m() { final C.MyIterable list = C.newIterable(); - final Procedure1 _function = new Procedure1() { - public void apply(final CharSequence it) { - } + final Consumer _function = (CharSequence it) -> { }; - list.forEach2(_function); + list.forEach(_function); } public static C.MyIterable newIterable(final T... initial) { @@ -150,24 +115,21 @@ class CompilerBug457539Test extends AbstractXtendCompilerTest { def m() { val list = newIterable list.add('') - list.forEach2 [ + list.forEach [ ] } def static MyIterable newIterable(T... initial) {} interface MyIterable extends Iterable { - def void forEach2((T)=>void f) def void add(T t) def T get() } } '''.assertCompilesTo(''' - import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; + import java.util.function.Consumer; @SuppressWarnings("all") public class C { public interface MyIterable extends Iterable { - void forEach2(final Procedure1 f); - void add(final T t); T get(); @@ -176,11 +138,9 @@ class CompilerBug457539Test extends AbstractXtendCompilerTest { public void m() { final C.MyIterable list = C.newIterable(); list.add(""); - final Procedure1 _function = new Procedure1() { - public void apply(final String it) { - } + final Consumer _function = (String it) -> { }; - list.forEach2(_function); + list.forEach(_function); } public static C.MyIterable newIterable(final T... initial) { @@ -197,24 +157,21 @@ class CompilerBug457539Test extends AbstractXtendCompilerTest { val list = newIterable list.get.toString list.add('') - list.forEach2 [ + list.forEach [ ] } def static MyIterable newIterable(T... initial) {} interface MyIterable extends Iterable { - def void forEach2((T)=>void f) def void add(T t) def T get() } } '''.assertCompilesTo(''' - import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; + import java.util.function.Consumer; @SuppressWarnings("all") public class C { public interface MyIterable extends Iterable { - void forEach2(final Procedure1 f); - void add(final T t); T get(); @@ -224,11 +181,9 @@ class CompilerBug457539Test extends AbstractXtendCompilerTest { final C.MyIterable list = C.newIterable(); list.get().toString(); list.add(""); - final Procedure1 _function = new Procedure1() { - public void apply(final CharSequence it) { - } + final Consumer _function = (CharSequence it) -> { }; - list.forEach2(_function); + list.forEach(_function); } public static C.MyIterable newIterable(final T... initial) { @@ -244,25 +199,22 @@ class CompilerBug457539Test extends AbstractXtendCompilerTest { def m() { val list = newIterable list.get.toString - list.forEach2 [ + list.forEach [ if (it instanceof String) list.add(it) ] } def static MyIterable newIterable(T... initial) {} interface MyIterable extends Iterable { - def void forEach2((T)=>void f) def void add(T t) def T get() } } '''.assertCompilesTo(''' - import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; + import java.util.function.Consumer; @SuppressWarnings("all") public class C { public interface MyIterable extends Iterable { - void forEach2(final Procedure1 f); - void add(final T t); T get(); @@ -271,14 +223,12 @@ class CompilerBug457539Test extends AbstractXtendCompilerTest { public void m() { final C.MyIterable list = C.newIterable(); list.get().toString(); - final Procedure1 _function = new Procedure1() { - public void apply(final CharSequence it) { - if ((it instanceof String)) { - list.add(it); - } + final Consumer _function = (CharSequence it) -> { + if ((it instanceof String)) { + list.add(it); } }; - list.forEach2(_function); + list.forEach(_function); } public static C.MyIterable newIterable(final T... initial) { @@ -293,25 +243,22 @@ class CompilerBug457539Test extends AbstractXtendCompilerTest { class C { def m() { val list = newIterable - list.forEach2 [ + list.forEach [ if (it instanceof String) list.add(it) ] } def static MyIterable newIterable(T... initial) {} interface MyIterable extends Iterable { - def void forEach2((T)=>void f) def void add(T t) def T get() } } '''.assertCompilesTo(''' - import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; + import java.util.function.Consumer; @SuppressWarnings("all") public class C { public interface MyIterable extends Iterable { - void forEach2(final Procedure1 f); - void add(final T t); T get(); @@ -319,14 +266,12 @@ class CompilerBug457539Test extends AbstractXtendCompilerTest { public void m() { final C.MyIterable list = C.newIterable(); - final Procedure1 _function = new Procedure1() { - public void apply(final CharSequence it) { - if ((it instanceof String)) { - list.add(it); - } + final Consumer _function = (CharSequence it) -> { + if ((it instanceof String)) { + list.add(it); } }; - list.forEach2(_function); + list.forEach(_function); } public static C.MyIterable newIterable(final T... initial) { @@ -341,25 +286,22 @@ class CompilerBug457539Test extends AbstractXtendCompilerTest { class C { def m() { val list = newIterable - list.forEach2 [ CharSequence it | + list.forEach [ CharSequence it | if (it instanceof String) list.add(it) ] } def static MyIterable newIterable(T... initial) {} interface MyIterable extends Iterable { - def void forEach2((T)=>void f) def void add(T t) def T get() } } '''.assertCompilesTo(''' - import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; - + import java.util.function.Consumer; + @SuppressWarnings("all") public class C { public interface MyIterable extends Iterable { - void forEach2(final Procedure1 f); - void add(final T t); T get(); @@ -367,14 +309,12 @@ class CompilerBug457539Test extends AbstractXtendCompilerTest { public void m() { final C.MyIterable list = C.newIterable(); - final Procedure1 _function = new Procedure1() { - public void apply(final CharSequence it) { - if ((it instanceof String)) { - list.add(it); - } + final Consumer _function = (CharSequence it) -> { + if ((it instanceof String)) { + list.add(it); } }; - list.forEach2(_function); + list.forEach(_function); } public static C.MyIterable newIterable(final T... initial) { @@ -386,7 +326,7 @@ class CompilerBug457539Test extends AbstractXtendCompilerTest { @Test def test_09() { ''' - import org.eclipse.xtend.core.tests.compiler.StringBuilderLike + import org.eclipse.xtend.core.tests.java8.compiler.StringBuilderLike class C { def m() { newIterable(new StringBuilderLike).forEach2 [ @@ -402,7 +342,7 @@ class CompilerBug457539Test extends AbstractXtendCompilerTest { } '''.assertCompilesTo(''' import java.io.Serializable; - import org.eclipse.xtend.core.tests.compiler.StringBuilderLike; + import org.eclipse.xtend.core.tests.java8.compiler.StringBuilderLike; import org.eclipse.xtext.xbase.lib.InputOutput; import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; @@ -414,12 +354,10 @@ class CompilerBug457539Test extends AbstractXtendCompilerTest { public void m() { StringBuilderLike _stringBuilderLike = new StringBuilderLike(); - final Procedure1 _function = new Procedure1() { - public void apply(final StringBuilderLike it) { - Long _long = new Long(0); - C.this.m(it, _long); - InputOutput.println(Integer.valueOf(it.length())); - } + final Procedure1 _function = (StringBuilderLike it) -> { + Long _long = new Long(0); + this.m(it, _long); + InputOutput.println(Integer.valueOf(it.length())); }; C.newIterable(_stringBuilderLike).forEach2(_function); } @@ -434,7 +372,7 @@ class CompilerBug457539Test extends AbstractXtendCompilerTest { } ''') } - + @Test def test_10() { ''' class C { @@ -455,9 +393,7 @@ class CompilerBug457539Test extends AbstractXtendCompilerTest { } public void m(final C.MyIterable list) { - final Procedure1 _function = new Procedure1() { - public void apply(final Object it) { - } + final Procedure1 _function = (Object it) -> { }; list.forEach2(_function); } diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug459920Test.xtend b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug459920Test.xtend index 6f3c0032589..66bb16967e7 100644 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug459920Test.xtend +++ b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug459920Test.xtend @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2015, 2016 itemis AG (http://www.itemis.eu) and others. + * Copyright (c) 2015, 2024 itemis AG (http://www.itemis.eu) and others. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. @@ -52,10 +52,8 @@ class CompilerBug459920Test extends AbstractXtendCompilerTest { if ((work instanceof CancelableUnitOfWork)) { CancelIndicator _xifexpression = null; if ((param == null)) { - final CancelIndicator _function = new CancelIndicator() { - public boolean isCanceled() { - return true; - } + final CancelIndicator _function = () -> { + return true; }; _xifexpression = _function; } else { diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug460691Test.xtend b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug460691Test.xtend index 83dd05b3251..35dd8699ae7 100644 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug460691Test.xtend +++ b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug460691Test.xtend @@ -27,6 +27,7 @@ class CompilerBug460691Test extends AbstractXtendCompilerTest { @SuppressWarnings("all") public class C implements Comparator { + @Override public int compare(final String s1, final String s2) { return s1.compareTo(s2); } diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug461568Test.xtend b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug461568Test.xtend index 438b9ad4f6f..b5cb27aa419 100644 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug461568Test.xtend +++ b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug461568Test.xtend @@ -38,10 +38,8 @@ class CompilerBug461568Test extends AbstractXtendCompilerTest { } public Object m2() { - final Procedure1 _function = new Procedure1() { - public void apply(final String s) { - s.getBytes(); - } + final Procedure1 _function = (String s) -> { + s.getBytes(); }; return this.m(_function); } @@ -72,10 +70,8 @@ class CompilerBug461568Test extends AbstractXtendCompilerTest { } public Object m2() { - final Function1 _function = new Function1() { - public Object apply(final String s) { - return s.getBytes(); - } + final Function1 _function = (String s) -> { + return s.getBytes(); }; return this.m(_function); } @@ -106,10 +102,8 @@ class CompilerBug461568Test extends AbstractXtendCompilerTest { } public Object m2() { - final Procedure1 _function = new Procedure1() { - public void apply(final String it) { - it.getBytes(); - } + final Procedure1 _function = (String it) -> { + it.getBytes(); }; return this.m(_function); } diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug461923Test.xtend b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug461923Test.xtend index 41781b3b85a..fb7bd996bda 100644 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug461923Test.xtend +++ b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug461923Test.xtend @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2015, 2016 itemis AG (http://www.itemis.eu) and others. + * Copyright (c) 2015, 2024 itemis AG (http://www.itemis.eu) and others. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. @@ -35,10 +35,8 @@ class CompilerBug461923Test extends AbstractXtendCompilerTest { @SuppressWarnings("all") public class C { public static ImmutableList m(final List list, final T value) { - final Function1 _function = new Function1() { - public Boolean apply(final T it) { - return Boolean.valueOf((!Objects.equals(it, value))); - } + final Function1 _function = (T it) -> { + return Boolean.valueOf((!Objects.equals(it, value))); }; return ImmutableList.builder().addAll(IterableExtensions.filter(list, _function)).build(); } @@ -66,10 +64,8 @@ class CompilerBug461923Test extends AbstractXtendCompilerTest { @SuppressWarnings("all") public class C { public static ImmutableList m(final List list, final T value) { - final Function1 _function = new Function1() { - public Boolean apply(final T it) { - return Boolean.valueOf((!Objects.equals(it, value))); - } + final Function1 _function = (T it) -> { + return Boolean.valueOf((!Objects.equals(it, value))); }; return ImmutableList.builder().addAll(IterableExtensions.filter(list, _function)).build(); } @@ -97,10 +93,8 @@ class CompilerBug461923Test extends AbstractXtendCompilerTest { @SuppressWarnings("all") public class C { public static ImmutableList m(final List list, final T value) { - final Function1 _function = new Function1() { - public Boolean apply(final Object it) { - return Boolean.valueOf((!Objects.equals(it, value))); - } + final Function1 _function = (Object it) -> { + return Boolean.valueOf((!Objects.equals(it, value))); }; return ImmutableList.builder().addAll(IterableExtensions.filter(list, _function)).build(); } @@ -150,10 +144,8 @@ class CompilerBug461923Test extends AbstractXtendCompilerTest { @SuppressWarnings("all") public class C { public static ImmutableList m(final List list) { - final Function1 _function = new Function1() { - public Boolean apply(final T it) { - return Boolean.valueOf(true); - } + final Function1 _function = (T it) -> { + return Boolean.valueOf(true); }; return ImmutableList.builder().addAll(IterableExtensions.filter(list, _function)).addAll(list).build(); } @@ -180,10 +172,8 @@ class CompilerBug461923Test extends AbstractXtendCompilerTest { @SuppressWarnings("all") public class C { public static ImmutableList m(final List list) { - final Function1 _function = new Function1() { - public Boolean apply(final T it) { - return Boolean.valueOf(false); - } + final Function1 _function = (T it) -> { + return Boolean.valueOf(false); }; return ImmutableList.builder().addAll(list).addAll(IterableExtensions.filter(list, _function)).build(); } @@ -210,15 +200,11 @@ class CompilerBug461923Test extends AbstractXtendCompilerTest { @SuppressWarnings("all") public class C { public static ImmutableList m(final List list) { - final Function1 _function = new Function1() { - public Boolean apply(final T it) { - return Boolean.valueOf(true); - } + final Function1 _function = (T it) -> { + return Boolean.valueOf(true); }; - final Function1 _function_1 = new Function1() { - public Boolean apply(final T it) { - return Boolean.valueOf(false); - } + final Function1 _function_1 = (T it) -> { + return Boolean.valueOf(false); }; return ImmutableList.builder().addAll(IterableExtensions.filter(list, _function)).addAll(IterableExtensions.filter(list, _function_1)).build(); } @@ -246,10 +232,8 @@ class CompilerBug461923Test extends AbstractXtendCompilerTest { @SuppressWarnings("all") public class C { public static ImmutableList m(final T[] arr, final T value) { - final Function1 _function = new Function1() { - public Boolean apply(final T it) { - return Boolean.valueOf((!Objects.equals(it, value))); - } + final Function1 _function = (T it) -> { + return Boolean.valueOf((!Objects.equals(it, value))); }; return ImmutableList.builder().addAll(IterableExtensions.filter(((Iterable)Conversions.doWrapArray(arr)), _function)).build(); } diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug462845Test.xtend b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug462845Test.xtend index 4a0cda8152b..7b7ae5c7a1e 100644 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug462845Test.xtend +++ b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug462845Test.xtend @@ -29,13 +29,12 @@ class CompilerBug462845Test extends AbstractXtendCompilerTest { override next() { delegate.next } - override remove() {} } } } '''.assertCompilesTo(''' import java.util.Iterator; - + @SuppressWarnings("all") public class C { public C() { @@ -43,26 +42,23 @@ class CompilerBug462845Test extends AbstractXtendCompilerTest { Iterator delegate; } - final Iterable _function = new Iterable() { - public Iterator iterator() { - return null; - } + final Iterable _function = () -> { + return null; }; final Iterable iter = _function; new __C_1() { { delegate = iter.iterator(); } + @Override public boolean hasNext() { return this.delegate.hasNext(); } + @Override public String next() { return this.delegate.next(); } - - public void remove() { - } }; } } @@ -83,7 +79,6 @@ class CompilerBug462845Test extends AbstractXtendCompilerTest { override next() { delegate.next } - override remove() {} } } } @@ -99,26 +94,23 @@ class CompilerBug462845Test extends AbstractXtendCompilerTest { __C_1 _xblockexpression = null; { - final Iterable _function = new Iterable() { - public Iterator iterator() { - return null; - } + final Iterable _function = () -> { + return null; }; final Iterable iter = _function; _xblockexpression = new __C_1() { { delegate = iter.iterator(); } + @Override public boolean hasNext() { return this.delegate.hasNext(); } + @Override public String next() { return this.delegate.next(); } - - public void remove() { - } }; } return _xblockexpression; @@ -157,24 +149,25 @@ class CompilerBug462845Test extends AbstractXtendCompilerTest { __C_1 _xblockexpression = null; { - final Iterable _function = new Iterable() { - public Iterator iterator() { - return null; - } + final Iterable _function = () -> { + return null; }; final Iterable iter = _function; _xblockexpression = new __C_1() { { delegate = iter.iterator(); } + @Override public boolean hasNext() { return this.delegate.hasNext(); } + @Override public String next() { return this.delegate.next(); } + @Override public void remove() { } }; @@ -213,24 +206,25 @@ class CompilerBug462845Test extends AbstractXtendCompilerTest { Iterator delegate; } - final Iterable _function = new Iterable() { - public Iterator iterator() { - return null; - } + final Iterable _function = () -> { + return null; }; final Iterable iter = _function; new __C_1() { { delegate = iter.iterator(); } + @Override public boolean hasNext() { return this.delegate.hasNext(); } + @Override public String next() { return this.delegate.next(); } + @Override public void remove() { } }; @@ -264,6 +258,7 @@ class CompilerBug462845Test extends AbstractXtendCompilerTest { @SuppressWarnings("all") public class C { private final Iterator iterator = new Function0>() { + @Override public Iterator apply() { abstract class __C_1 implements Iterator { Iterator delegate; @@ -271,24 +266,25 @@ class CompilerBug462845Test extends AbstractXtendCompilerTest { __C_1 _xblockexpression = null; { - final Iterable _function = new Iterable() { - public Iterator iterator() { - return null; - } + final Iterable _function = () -> { + return null; }; final Iterable iter = _function; _xblockexpression = new __C_1() { { delegate = iter.iterator(); } + @Override public boolean hasNext() { return this.delegate.hasNext(); } + @Override public String next() { return this.delegate.next(); } + @Override public void remove() { } }; diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug464264Test.xtend b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug464264Test.xtend index 7b31cb4da36..7297ac8c85f 100644 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug464264Test.xtend +++ b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug464264Test.xtend @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2015, 2016 itemis AG (http://www.itemis.eu) and others. + * Copyright (c) 2015, 2024 itemis AG (http://www.itemis.eu) and others. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. @@ -43,17 +43,13 @@ class CompilerBug464264Test extends AbstractXtendCompilerTest { List _xblockexpression = null; { List _strings = i.getStrings(); - final Function1 _function = new Function1() { - public String apply(final CharSequence it) { - return ((String) it); - } + final Function1 _function = (CharSequence it) -> { + return ((String) it); }; List _map = ListExtensions.map(list, _function); Iterables.addAll(_strings, _map); - final Function1 _function_1 = new Function1() { - public CharSequence apply(final CharSequence it) { - return it; - } + final Function1 _function_1 = (CharSequence it) -> { + return it; }; _xblockexpression = ListExtensions.map(list, _function_1); } @@ -80,10 +76,8 @@ class CompilerBug464264Test extends AbstractXtendCompilerTest { @SuppressWarnings("all") public class C { public boolean m(final List res, final Iterable obj) { - final Function1 _function = new Function1() { - public String apply(final Object it) { - return ""; - } + final Function1 _function = (Object it) -> { + return ""; }; Iterable _map = IterableExtensions.map(obj, _function); return Iterables.addAll(res, _map); diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug465058Test.xtend b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug465058Test.xtend index 682425f1a7b..56326d7b0dc 100644 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug465058Test.xtend +++ b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug465058Test.xtend @@ -15,7 +15,7 @@ import org.junit.Test */ class CompilerBug465058Test extends AbstractXtendCompilerTest { - @Test def test_01() { + @Test def void test_01() { ''' abstract class Bug { val list = #["one", "two", "three"] @@ -38,10 +38,8 @@ class CompilerBug465058Test extends AbstractXtendCompilerTest { public abstract void foo(final Function0 f); public void bar() { - final Function0 _function = new Function0() { - public Object apply() { - return IterableExtensions.head(Bug.this.list); - } + final Function0 _function = () -> { + return IterableExtensions.head(this.list); }; this.foo(_function); } @@ -49,7 +47,7 @@ class CompilerBug465058Test extends AbstractXtendCompilerTest { ''') } - @Test def test_02() { + @Test def void test_02() { ''' abstract class Bug { val list = newArrayList('a', 'b') @@ -71,10 +69,8 @@ class CompilerBug465058Test extends AbstractXtendCompilerTest { public abstract void foo(final Function0 f); public void bar() { - final Function0 _function = new Function0() { - public Object apply() { - return IterableExtensions.head(Bug.this.list); - } + final Function0 _function = () -> { + return IterableExtensions.head(this.list); }; this.foo(_function); } @@ -82,7 +78,7 @@ class CompilerBug465058Test extends AbstractXtendCompilerTest { ''') } - @Test def test_03() { + @Test def void test_03() { ''' abstract class Bug { val list = #["one", "two", "three"] @@ -105,10 +101,8 @@ class CompilerBug465058Test extends AbstractXtendCompilerTest { public abstract void foo(final Function0 f); public void bar() { - final Function0 _function = new Function0() { - public Object apply() { - return IterableExtensions.head(Bug.this.list); - } + final Function0 _function = () -> { + return IterableExtensions.head(this.list); }; this.foo(_function); } @@ -116,7 +110,7 @@ class CompilerBug465058Test extends AbstractXtendCompilerTest { ''') } - @Test def test_04() { + @Test def void test_04() { ''' abstract class Bug { val list = newArrayList('a', 'b') @@ -138,10 +132,8 @@ class CompilerBug465058Test extends AbstractXtendCompilerTest { public abstract void foo(final Function0 f); public void bar() { - final Function0 _function = new Function0() { - public Object apply() { - return IterableExtensions.head(Bug.this.list); - } + final Function0 _function = () -> { + return IterableExtensions.head(this.list); }; this.foo(_function); } @@ -149,7 +141,7 @@ class CompilerBug465058Test extends AbstractXtendCompilerTest { ''') } - @Test def test_05() { + @Test def void test_05() { ''' abstract class Bug { val list = #["one", "two", "three"] @@ -172,10 +164,8 @@ class CompilerBug465058Test extends AbstractXtendCompilerTest { public abstract void foo(final Function0 f); public void bar() { - final Function0 _function = new Function0() { - public Object apply() { - return Bug.this.head2(Bug.this.list); - } + final Function0 _function = () -> { + return this.head2(this.list); }; this.foo(_function); } @@ -187,7 +177,7 @@ class CompilerBug465058Test extends AbstractXtendCompilerTest { ''') } - @Test def test_06() { + @Test def void test_06() { ''' abstract class Bug { val list = #["one", "two", "three"] @@ -210,10 +200,8 @@ class CompilerBug465058Test extends AbstractXtendCompilerTest { public abstract void foo(final Function0 f); public void bar() { - final Function0 _function = new Function0() { - public Object apply() { - return Bug.this.head2(Bug.this.list); - } + final Function0 _function = () -> { + return this.head2(this.list); }; this.foo(_function); } @@ -225,7 +213,7 @@ class CompilerBug465058Test extends AbstractXtendCompilerTest { ''') } - @Test def test_07() { + @Test def void test_07() { ''' abstract class Bug { val list = #["one", "two", "three"] @@ -249,10 +237,8 @@ class CompilerBug465058Test extends AbstractXtendCompilerTest { public abstract void foo(final Function0 f); public void bar() { - final Function0 _function = new Function0() { - public Object apply() { - return Bug.this.head2(((String[])Conversions.unwrapArray(Bug.this.list, String.class))); - } + final Function0 _function = () -> { + return this.head2(((String[])Conversions.unwrapArray(this.list, String.class))); }; this.foo(_function); } @@ -264,7 +250,7 @@ class CompilerBug465058Test extends AbstractXtendCompilerTest { ''') } - @Test def test_08() { + @Test def void test_08() { ''' abstract class Bug { def void foo(=>Object f) @@ -281,10 +267,8 @@ class CompilerBug465058Test extends AbstractXtendCompilerTest { public abstract void foo(final Function0 f); public void bar() { - final Function0 _function = new Function0() { - public Object apply() { - return Bug.this.head2(new String[] { "one", "two", "three" }); - } + final Function0 _function = () -> { + return this.head2(new String[] { "one", "two", "three" }); }; this.foo(_function); } @@ -296,7 +280,7 @@ class CompilerBug465058Test extends AbstractXtendCompilerTest { ''') } - @Test def test_09() { + @Test def void test_09() { ''' abstract class Bug { val list = #["one", "two", "three"] @@ -319,10 +303,8 @@ class CompilerBug465058Test extends AbstractXtendCompilerTest { public abstract void foo(final Function0 f); public void bar() { - final Function0 _function = new Function0() { - public Object apply() { - return Bug.this.head2(Bug.this.list); - } + final Function0 _function = () -> { + return this.head2(this.list); }; this.foo(_function); } @@ -334,7 +316,7 @@ class CompilerBug465058Test extends AbstractXtendCompilerTest { ''') } - @Test def test_10() { + @Test def void test_10() { ''' abstract class Bug { val list = #["one", "two", "three"] @@ -357,10 +339,8 @@ class CompilerBug465058Test extends AbstractXtendCompilerTest { public abstract void foo(final Function0 f); public void bar() { - final Function0 _function = new Function0() { - public Object apply() { - return Bug.this.head2(Bug.this.list); - } + final Function0 _function = () -> { + return this.head2(this.list); }; this.foo(_function); } @@ -372,7 +352,7 @@ class CompilerBug465058Test extends AbstractXtendCompilerTest { ''') } - @Test def test_11() { + @Test def void test_11() { ''' abstract class Bug { val list = #["one", "two", "three"] @@ -395,10 +375,8 @@ class CompilerBug465058Test extends AbstractXtendCompilerTest { public abstract void foo(final Function0 f); public void bar() { - final Function0 _function = new Function0() { - public Object apply() { - return Bug.this.head2(Bug.this.list); - } + final Function0 _function = () -> { + return this.head2(this.list); }; this.foo(_function); } @@ -410,7 +388,7 @@ class CompilerBug465058Test extends AbstractXtendCompilerTest { ''') } - @Test def test_12() { + @Test def void test_12() { ''' abstract class Bug { val list = #["one", "two", "three"] @@ -434,10 +412,8 @@ class CompilerBug465058Test extends AbstractXtendCompilerTest { public abstract void foo(final Function0 f); public void bar() { - final Function0 _function = new Function0() { - public Object apply() { - return Bug.this.head2(((String[])Conversions.unwrapArray(Bug.this.list, String.class))); - } + final Function0 _function = () -> { + return this.head2(((String[])Conversions.unwrapArray(this.list, String.class))); }; this.foo(_function); } @@ -449,7 +425,7 @@ class CompilerBug465058Test extends AbstractXtendCompilerTest { ''') } - @Test def test_13() { + @Test def void test_13() { ''' abstract class Bug { def void foo(=>Object f) @@ -466,10 +442,8 @@ class CompilerBug465058Test extends AbstractXtendCompilerTest { public abstract void foo(final Function0 f); public void bar() { - final Function0 _function = new Function0() { - public Object apply() { - return Bug.this.head2(new String[] { "one", "two", "three" }); - } + final Function0 _function = () -> { + return this.head2(new String[] { "one", "two", "three" }); }; this.foo(_function); } @@ -481,7 +455,7 @@ class CompilerBug465058Test extends AbstractXtendCompilerTest { ''') } - @Test def test_14() { + @Test def void test_14() { ''' abstract class Bug { val list = #["one", "two", "three"] @@ -504,10 +478,8 @@ class CompilerBug465058Test extends AbstractXtendCompilerTest { public abstract void foo(final Function0 f); public void bar() { - final Function0 _function = new Function0() { - public Object apply() { - return Bug.this.head2(Bug.this.list); - } + final Function0 _function = () -> { + return this.head2(this.list); }; this.foo(_function); } @@ -519,7 +491,7 @@ class CompilerBug465058Test extends AbstractXtendCompilerTest { ''') } - @Test def test_15() { + @Test def void test_15() { ''' abstract class Bug { val list = #["one", "two", "three"] @@ -540,10 +512,8 @@ class CompilerBug465058Test extends AbstractXtendCompilerTest { private final List list = Collections.unmodifiableList(CollectionLiterals.newArrayList("one", "two", "three")); public void bar() { - final Function0 _function = new Function0() { - public Object apply() { - return Bug.this.head2(Bug.this.list); - } + final Function0 _function = () -> { + return this.head2(this.list); }; Function0 x = _function; x.apply(); @@ -556,7 +526,7 @@ class CompilerBug465058Test extends AbstractXtendCompilerTest { ''') } - @Test def test_16() { + @Test def void test_16() { ''' abstract class Bug { def bar() { @@ -575,10 +545,8 @@ class CompilerBug465058Test extends AbstractXtendCompilerTest { public Object bar() { Object _xblockexpression = null; { - final Function0 _function = new Function0() { - public Object apply() { - return Bug.this.head2(Collections.unmodifiableList(CollectionLiterals.newArrayList("one", "two", "three"))); - } + final Function0 _function = () -> { + return this.head2(Collections.unmodifiableList(CollectionLiterals.newArrayList("one", "two", "three"))); }; Function0 x = _function; _xblockexpression = x.apply(); @@ -593,7 +561,7 @@ class CompilerBug465058Test extends AbstractXtendCompilerTest { ''') } - @Test def test_17() { + @Test def void test_17() { ''' abstract class Bug { def bar() { @@ -610,10 +578,8 @@ class CompilerBug465058Test extends AbstractXtendCompilerTest { public Object bar() { Object _xblockexpression = null; { - final Function0 _function = new Function0() { - public Object apply() { - return Bug.this.head2(new String[] { "one", "two", "three" }); - } + final Function0 _function = () -> { + return this.head2(new String[] { "one", "two", "three" }); }; Function0 x = _function; _xblockexpression = x.apply(); @@ -628,7 +594,7 @@ class CompilerBug465058Test extends AbstractXtendCompilerTest { ''') } - @Test def test_18() { + @Test def void test_18() { ''' abstract class Bug { def void foo(=>Object f) @@ -645,10 +611,8 @@ class CompilerBug465058Test extends AbstractXtendCompilerTest { public abstract void foo(final Function0 f); public void bar() { - final Function0 _function = new Function0() { - public Object apply() { - return ((Number)Bug.this.head2(new Number[] { Integer.valueOf(1), Double.valueOf(1.0) })); - } + final Function0 _function = () -> { + return ((Number)this.head2(new Number[] { Integer.valueOf(1), Double.valueOf(1.0) })); }; this.foo(_function); } @@ -660,7 +624,7 @@ class CompilerBug465058Test extends AbstractXtendCompilerTest { ''') } - @Test def test_19() { + @Test def void test_19() { ''' abstract class Bug { def void foo(=>Object f) @@ -677,10 +641,8 @@ class CompilerBug465058Test extends AbstractXtendCompilerTest { public abstract void foo(final Function0 f); public void bar() { - final Function0 _function = new Function0() { - public Object apply() { - return Bug.this.head2(new Comparable[] { "", "" }); - } + final Function0 _function = () -> { + return this.head2(new Comparable[] { "", "" }); }; this.foo(_function); } @@ -692,7 +654,7 @@ class CompilerBug465058Test extends AbstractXtendCompilerTest { ''') } - @Test def test_20() { + @Test def void test_20() { ''' abstract class Bug { def void foo(=>Object f) @@ -709,10 +671,8 @@ class CompilerBug465058Test extends AbstractXtendCompilerTest { public abstract void foo(final Function0 f); public void bar() { - final Function0 _function = new Function0() { - public Object apply() { - return ((Number)Bug.this.head2(new Comparable[] { ((Integer) null), ((Double) null) })); - } + final Function0 _function = () -> { + return ((Number)this.head2(new Comparable[] { ((Integer) null), ((Double) null) })); }; this.foo(_function); } @@ -724,7 +684,7 @@ class CompilerBug465058Test extends AbstractXtendCompilerTest { ''') } - @Test def test_21() { + @Test def void test_21() { ''' abstract class Bug { def void foo(=>Object f) @@ -741,10 +701,8 @@ class CompilerBug465058Test extends AbstractXtendCompilerTest { public abstract void foo(final Function0 f); public void bar() { - final Function0 _function = new Function0() { - public Object apply() { - return ((Number)Bug.this.head2(new Comparable[] { Integer.valueOf(1), Double.valueOf(1.0) })); - } + final Function0 _function = () -> { + return ((Number)this.head2(new Comparable[] { Integer.valueOf(1), Double.valueOf(1.0) })); }; this.foo(_function); } diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug470768Test.xtend b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug470768Test.xtend index fe43067f29a..94c65fc8939 100644 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug470768Test.xtend +++ b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug470768Test.xtend @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2015, 2016 itemis AG (http://www.itemis.eu) and others. + * Copyright (c) 2015, 2024 itemis AG (http://www.itemis.eu) and others. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. @@ -44,6 +44,7 @@ class CompilerBug470768Test extends AbstractXtendCompilerTest { } public static class CustomItr implements Iterable { + @Override public Iterator iterator() { throw new UnsupportedOperationException(); } @@ -96,6 +97,7 @@ class CompilerBug470768Test extends AbstractXtendCompilerTest { @SuppressWarnings("all") public class C { public static class CustomItr implements Iterable { + @Override public Iterator iterator() { return null; } @@ -153,6 +155,7 @@ class CompilerBug470768Test extends AbstractXtendCompilerTest { } public static class CustomItr implements Iterable { + @Override public Iterator iterator() { return null; } @@ -209,6 +212,7 @@ class CompilerBug470768Test extends AbstractXtendCompilerTest { } public static class CustomItr implements Iterable { + @Override public Iterator iterator() { return null; } diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug472602Test.xtend b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug472602Test.xtend index 5f87bd6c6b2..4fb5696c058 100644 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug472602Test.xtend +++ b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBug472602Test.xtend @@ -243,6 +243,7 @@ class CompilerBug472602Test extends AbstractXtendCompilerTest { this.f = f; } + @Override public B get() { final A a = this.in.get(); final B b = this.f.apply(a); @@ -289,6 +290,7 @@ class CompilerBug472602Test extends AbstractXtendCompilerTest { { final C thiz = this; _xblockexpression = new C() { + @Override public B get() { final A a = thiz.get(); final B b = f.apply(a); diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBugDispatchWithOverrideTest.xtend b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBugDispatchWithOverrideTest.xtend index 1d0488366be..4476f50db5d 100644 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBugDispatchWithOverrideTest.xtend +++ b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBugDispatchWithOverrideTest.xtend @@ -8,10 +8,9 @@ *******************************************************************************/ package org.eclipse.xtend.core.tests.compiler -import org.junit.Test -import org.eclipse.xtext.util.JavaVersion -import org.eclipse.xtext.testing.InjectWith import org.eclipse.xtend.core.tests.SingletonGeneratorConfigRuntimeInjectorProvider +import org.eclipse.xtext.testing.InjectWith +import org.junit.Test /** * Tests for https://github.com/eclipse/xtext-xtend/issues/484 @@ -22,9 +21,6 @@ import org.eclipse.xtend.core.tests.SingletonGeneratorConfigRuntimeInjectorProvi class CompilerBugDispatchWithOverrideTest extends AbstractXtendCompilerTest { @Test def void testDispatchWithOverrideJava6HasAnnotation() { - val generatorConfig = generatorConfigProvider.get(null) - generatorConfig.javaSourceVersion = JavaVersion.JAVA6 - assertCompilesTo( ''' class Something extends AbstractSomething { @@ -64,9 +60,6 @@ class CompilerBugDispatchWithOverrideTest extends AbstractXtendCompilerTest { } @Test def void testDispatchWithOverrideJava5HasNoAnnotation() { - val generatorConfig = generatorConfigProvider.get(null) - generatorConfig.javaSourceVersion = JavaVersion.JAVA5 - assertCompilesTo( ''' class Something extends AbstractSomething { @@ -83,9 +76,11 @@ class CompilerBugDispatchWithOverrideTest extends AbstractXtendCompilerTest { @SuppressWarnings("all") public class Something extends AbstractSomething { + @Override protected void _m(final String x) { } + @Override public void m(final Object x) { if (x instanceof Integer) { _m((Integer)x); diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBugProtectedVisibilityTest.xtend b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBugProtectedVisibilityTest.xtend index 52740416dbb..7a7a5906172 100644 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBugProtectedVisibilityTest.xtend +++ b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBugProtectedVisibilityTest.xtend @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2014, 2020 itemis AG (http://www.itemis.eu) and others. + * Copyright (c) 2014, 2024 itemis AG (http://www.itemis.eu) and others. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. @@ -175,10 +175,8 @@ class CompilerBugProtectedVisibilityTest extends AbstractXtendCompilerTest { private C c = new C(); protected Object doX(final Runnable r) { - final Runnable _function = new Runnable() { - public void run() { - B.this.c.protectedMethod(); - } + final Runnable _function = () -> { + this.c.protectedMethod(); }; return this.doX(_function); } @@ -209,6 +207,7 @@ class CompilerBugProtectedVisibilityTest extends AbstractXtendCompilerTest { protected Object doX(final Runnable r) { return this.doX(new Runnable() { + @Override public void run() { B.this.c.protectedMethod(); } diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBugTest.xtend b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBugTest.xtend index b47fe245988..0c8897cdd41 100644 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBugTest.xtend +++ b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerBugTest.xtend @@ -499,10 +499,8 @@ class CompilerBugTest extends AbstractXtendCompilerTest { } }; } else { - final Function1 _function = new Function1() { - public Boolean apply(final String s) { - return Boolean.valueOf(true); - } + final Function1 _function = (String s) -> { + return Boolean.valueOf(true); }; return _function; } @@ -1061,10 +1059,8 @@ class CompilerBugTest extends AbstractXtendCompilerTest { } public void build(final Factory f) { - final Procedure1 _function = new Procedure1() { - public void apply(final T it) { - Factory.this.>buildChild(f); - } + final Procedure1 _function = (T it) -> { + this.>buildChild(f); }; this.fill(_function); } @@ -1089,10 +1085,8 @@ class CompilerBugTest extends AbstractXtendCompilerTest { @SuppressWarnings("all") public class C { public C() { - final Function1 _function = new Function1() { - public String apply(final Integer it) { - return it.toString(); - } + final Function1 _function = (Integer it) -> { + return it.toString(); }; ListExtensions.map(Collections.unmodifiableList(CollectionLiterals.newArrayList(Integer.valueOf(1), Integer.valueOf(2), Integer.valueOf(3))), _function).toString(); } @@ -1130,14 +1124,10 @@ class CompilerBugTest extends AbstractXtendCompilerTest { private ErrorSafeExtensions _errorSafeExtensions; public void m(final Iterable refs, final ITreeAppendable it) { - final Procedure1 _function = new Procedure1() { - public void apply(final LoopParams it_1) { - } + final Procedure1 _function = (LoopParams it_1) -> { }; - final Procedure2 _function_1 = new Procedure2() { - public void apply(final JvmTypeReference it_1, final ITreeAppendable app) { - app.trace(it_1).append(it_1.getType()); - } + final Procedure2 _function_1 = (JvmTypeReference it_1, ITreeAppendable app) -> { + app.trace(it_1).append(it_1.getType()); }; this._errorSafeExtensions.forEachSafely(it, refs, _function, _function_1); } @@ -1279,12 +1269,10 @@ class CompilerBugTest extends AbstractXtendCompilerTest { public StringBuilder m() { StringBuilder _xblockexpression = null; { - final Procedure1 _function = new Procedure1() { - public void apply(final StringBuilder it) { - List _children = C.this.getChildren(); - _children.add(it); - it.append(""); - } + final Procedure1 _function = (StringBuilder it) -> { + List _children = this.getChildren(); + _children.add(it); + it.append(""); }; final StringBuilder result = ObjectExtensions.operator_doubleArrow(((StringBuilder) null), _function); _xblockexpression = result; @@ -1799,15 +1787,11 @@ class CompilerBugTest extends AbstractXtendCompilerTest { @SuppressWarnings("all") public class C { public List m(final Iterable iterable) { - final Function1 _function = new Function1() { - public Object apply(final String it) { - return null; - } + final Function1 _function = (String it) -> { + return null; }; - final Function1 _function_1 = new Function1() { - public Integer apply(final Object it) { - return Integer.valueOf(it.hashCode()); - } + final Function1 _function_1 = (Object it) -> { + return Integer.valueOf(it.hashCode()); }; return IterableExtensions.sortBy(this.flatMap(iterable, _function), _function_1); } @@ -1837,15 +1821,11 @@ class CompilerBugTest extends AbstractXtendCompilerTest { @SuppressWarnings("all") public class C { public void m(final Iterable iterable) { - final Function1 _function = new Function1() { - public String apply(final String it) { - return it; - } + final Function1 _function = (String it) -> { + return it; }; - final Function1 _function_1 = new Function1() { - public Integer apply(final String it) { - return Integer.valueOf(it.hashCode()); - } + final Function1 _function_1 = (String it) -> { + return Integer.valueOf(it.hashCode()); }; IterableExtensions.sortBy(this.flatMap(iterable, _function), _function_1); } @@ -1875,15 +1855,11 @@ class CompilerBugTest extends AbstractXtendCompilerTest { @SuppressWarnings("all") public class C { public void m(final Iterable iterable) { - final Function1 _function = new Function1() { - public String apply(final String it) { - return it.toUpperCase(); - } + final Function1 _function = (String it) -> { + return it.toUpperCase(); }; - final Function1 _function_1 = new Function1() { - public Integer apply(final String it) { - return Integer.valueOf(it.length()); - } + final Function1 _function_1 = (String it) -> { + return Integer.valueOf(it.length()); }; IterableExtensions.sortBy(this.flatMap(iterable, _function), _function_1); } @@ -1912,11 +1888,10 @@ class CompilerBugTest extends AbstractXtendCompilerTest { @SuppressWarnings("all") public class MyMap extends HashMap { + @Override public void putAll(final Map t) { - final Consumer> _function = new Consumer>() { - public void accept(final Map.Entry it) { - MyMap.this.put(it.getKey(), it.getValue()); - } + final Consumer> _function = (Map.Entry it) -> { + this.put(it.getKey(), it.getValue()); }; t.entrySet().forEach(_function); } @@ -1962,6 +1937,7 @@ class CompilerBugTest extends AbstractXtendCompilerTest { public class Weight implements Comparable> { private final T _weight; + @Override public int compareTo(final Weight w) { return this.getWeight().compareTo(w.getWeight()); } @@ -2030,6 +2006,7 @@ class CompilerBugTest extends AbstractXtendCompilerTest { public class Weight> implements Comparable> { private final T _weight; + @Override public int compareTo(final Weight w) { return this.getWeight().compareTo(w.getWeight()); } @@ -2098,6 +2075,7 @@ class CompilerBugTest extends AbstractXtendCompilerTest { public class Weight implements Comparable> { private final T _weight; + @Override public int compareTo(final Weight w) { return this.getWeight().compareTo(w.getWeight()); } @@ -2166,6 +2144,7 @@ class CompilerBugTest extends AbstractXtendCompilerTest { public class Weight implements Comparable { private final T _weight; + @Override public int compareTo(final Weight w) { return this.getWeight().compareTo(w.getWeight()); } @@ -2281,26 +2260,22 @@ class CompilerBugTest extends AbstractXtendCompilerTest { } } ''', ''' - import java.util.Objects; - @SuppressWarnings("all") public class C { public String m() { String _switchResult = null; final String _switchValue = "a"; - boolean _matched = false; - if (Objects.equals(_switchValue, "b")) { - _matched=true; - _switchResult = "a"; - } - if (!_matched) { - if (Objects.equals(_switchValue, "c")) { - _matched=true; - if ((1 == 2)) { - return "b"; - } else { - return "c"; - } + if (_switchValue != null) { + switch (_switchValue) { + case "b": + _switchResult = "a"; + break; + case "c": + if ((1 == 2)) { + return "b"; + } else { + return "c"; + } } } return _switchResult; @@ -2326,26 +2301,22 @@ class CompilerBugTest extends AbstractXtendCompilerTest { } } ''', ''' - import java.util.Objects; - @SuppressWarnings("all") public class C { public String m(final boolean b) { String _switchResult = null; final String _switchValue = "a"; - boolean _matched = false; - if (Objects.equals(_switchValue, "b")) { - _matched=true; - _switchResult = "a"; - } - if (!_matched) { - if (Objects.equals(_switchValue, "c")) { - _matched=true; - if (b) { - return "b"; - } else { - return "c"; - } + if (_switchValue != null) { + switch (_switchValue) { + case "b": + _switchResult = "a"; + break; + case "c": + if (b) { + return "b"; + } else { + return "c"; + } } } return _switchResult; @@ -2590,14 +2561,12 @@ class CompilerBugTest extends AbstractXtendCompilerTest { } '''.assertCompilesTo(''' import org.eclipse.xtext.xbase.lib.Functions.Function1; - + @SuppressWarnings("all") public class C { public T m() { - final Function1 _function = new Function1() { - public T apply(final T x) { - return x; - } + final Function1 _function = (T x) -> { + return x; }; return _function.apply(null); } @@ -2618,10 +2587,8 @@ class CompilerBugTest extends AbstractXtendCompilerTest { @SuppressWarnings("all") public class C { public T m() { - final Function1 _function = new Function1() { - public T apply(final T x) { - return x; - } + final Function1 _function = (T x) -> { + return x; }; return _function.apply(null); } @@ -2645,16 +2612,14 @@ class CompilerBugTest extends AbstractXtendCompilerTest { public abstract class L extends AbstractList { protected L() { Object _object = new Object(); - final Procedure1 _function = new Procedure1() { - public void apply(final Object it) { - boolean _and = false; - boolean _add = L.this.add(((E) it)); - if (!_add) { - _and = false; - } else { - boolean _remove = L.this.remove(it); - _and = _remove; - } + final Procedure1 _function = (Object it) -> { + boolean _and = false; + boolean _add = this.add(((E) it)); + if (!_add) { + _and = false; + } else { + boolean _remove = this.remove(it); + _and = _remove; } }; ObjectExtensions.operator_doubleArrow(_object, _function); @@ -2678,16 +2643,14 @@ class CompilerBugTest extends AbstractXtendCompilerTest { @SuppressWarnings("all") public abstract class L extends AbstractList { protected L(final E e) { - final Procedure1 _function = new Procedure1() { - public void apply(final E it) { - boolean _and = false; - boolean _add = L.this.add(it); - if (!_add) { - _and = false; - } else { - boolean _remove = L.this.remove(it); - _and = _remove; - } + final Procedure1 _function = (E it) -> { + boolean _and = false; + boolean _add = this.add(it); + if (!_add) { + _and = false; + } else { + boolean _remove = this.remove(it); + _and = _remove; } }; ObjectExtensions.operator_doubleArrow(e, _function); @@ -3183,6 +3146,7 @@ class CompilerBugTest extends AbstractXtendCompilerTest { '''.assertCompilesTo(''' @SuppressWarnings("all") public class B extends A { + @Override public void m(final Class[] c) { } } @@ -3217,6 +3181,7 @@ class CompilerBugTest extends AbstractXtendCompilerTest { '''.assertCompilesTo(''' @SuppressWarnings("all") public class B extends A { + @Override public void m(final Class... c) { } } @@ -3716,16 +3681,12 @@ class CompilerBugTest extends AbstractXtendCompilerTest { public Object test() { Object _xblockexpression = null; { - final Foo _function = new Foo() { - public void foo(final Foo foo) { - foo.foo(foo); - } + final Foo _function = (Foo foo) -> { + foo.foo(foo); }; this.bug(_function); - final Bar _function_1 = new Bar() { - public void bar(final Bar bar) { - bar.bar(bar); - } + final Bar _function_1 = (Bar bar) -> { + bar.bar(bar); }; _xblockexpression = this.bug(_function_1); } diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerTest.java b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerTest.java index 137dc2a4446..7e8fcadf24c 100644 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerTest.java +++ b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerTest.java @@ -27,20 +27,7 @@ import org.eclipse.emf.ecore.EReference; import org.eclipse.emf.ecore.ETypedElement; import org.eclipse.emf.ecore.EcoreFactory; -import org.eclipse.xtend.core.compiler.XtendCompiler; -import org.eclipse.xtend.core.jvmmodel.IXtendJvmAssociations; -import org.eclipse.xtend.core.tests.AbstractXtendTestCase; -import org.eclipse.xtend.core.xtend.XtendClass; -import org.eclipse.xtend.core.xtend.XtendFile; import org.eclipse.xtend.core.xtend.XtendPackage; -import org.eclipse.xtext.common.types.JvmGenericType; -import org.eclipse.xtext.testing.util.ParseHelper; -import org.eclipse.xtext.testing.validation.ValidationTestHelper; -import org.eclipse.xtext.xbase.compiler.IGeneratorConfigProvider; -import org.eclipse.xtext.xbase.testing.InMemoryJavaCompiler; -import org.eclipse.xtext.xbase.testing.InMemoryJavaCompiler.Result; -import org.eclipse.xtext.xbase.testing.JavaSource; -import org.eclipse.xtext.xbase.compiler.JvmModelGenerator; import org.eclipse.xtext.xbase.lib.Conversions; import org.eclipse.xtext.xbase.lib.Functions; import org.eclipse.xtext.xbase.lib.Functions.Function1; @@ -50,9 +37,6 @@ import com.google.common.collect.Lists; import com.google.common.collect.Sets; -import com.google.inject.Guice; -import com.google.inject.Inject; -import com.google.inject.Injector; import test.ExtensionMethods; import test.SampleBuilder; @@ -62,7 +46,7 @@ * @author Sven Efftinge - Initial contribution and API * @author Sebastian Zarnekow */ -public class CompilerTest extends AbstractXtendTestCase { +public class CompilerTest extends CompilerTestBase { @Test public void testBug472142() throws Exception { String code = @@ -419,15 +403,6 @@ public class CompilerTest extends AbstractXtendTestCase { assertEquals("123", castedClosure.apply(123)); } - private Class compileToClass(String className, String javaCode) { - Result result = javaCompiler.compile(new JavaSource(className.replace(".", "/")+".java", javaCode)); - try { - return result.getClassLoader().loadClass(className); - } catch (ClassNotFoundException e) { - throw new RuntimeException(e); - } - } - @Test public void testBug362236_02() throws Exception { String code = "import java.util.List\n" + @@ -3268,120 +3243,7 @@ public void testBug346763_07() throws Exception { assertEquals(Deprecated.class, fooMethod.getParameterAnnotations()[0][0].annotationType()); } - protected InMemoryJavaCompiler javaCompiler; - - @Inject - protected ParseHelper parseHelper; - - @Inject - protected ValidationTestHelper validationHelper; - @Inject - protected XtendCompiler compiler; - - @Inject - protected JvmModelGenerator generator; - - @Inject - private IXtendJvmAssociations associations; - - @Inject - protected IGeneratorConfigProvider generatorConfigProvider; - - @Inject - protected void createInMemoryJavaCompiler(ClassLoader classLoader) { - javaCompiler = new InMemoryJavaCompiler(classLoader, generatorConfigProvider.get(null).getJavaSourceVersion()); - } - - protected void invokeAndExpect2(Object expectation, String xtendclassBody, String methodToInvoke, Object... args) - throws Exception { - Class class1 = compileJavaCode("x.Y", "package x class Y {" + xtendclassBody + "}"); - assertEquals(expectation, apply(class1, methodToInvoke, args)); - } - - protected void invokeAndExpectStatic(Object expectation, String xtendclassBody, String methodToInvoke, Object... args) throws Exception { - Class class1 = compileJavaCode("x.Y", "package x class Y {" + xtendclassBody + "}"); - assertEquals(expectation, applyStatic(class1, methodToInvoke, argTypes(args), args)); - } - - protected void invokeAndExpect3(Object expectation, String xtendclassBody, String methodToInvoke, - Class[] parameterTypes, Object... args) throws Exception { - Class class1 = compileJavaCode("x.Y", "package x class Y {" + xtendclassBody + "}"); - assertEquals(expectation, applyImpl(class1, methodToInvoke, parameterTypes, args)); - } - protected void invokeAndExpect(Object expectation, String functionDef, Object...args) throws Exception { - String fullClass = "package x class Y { def Object testEntry("; - for (int i = 0; i < args.length; i++) { - Object object = args[i]; - if (object == null) { - fullClass+= Object.class.getCanonicalName()+" p"+(i+1); - } else { - fullClass+= object.getClass().getCanonicalName()+" p"+(i+1); - } - if (i+1 compiledClass = compileJavaCode("x.Y",fullClass); - assertEquals(expectation, apply(compiledClass,"testEntry",args)); - } - - protected Object apply(Class type, String methodName, Object... args) throws Exception { - return applyImpl(type, methodName, argTypes(args), args); - } - - protected Class[] argTypes(Object...args) throws Exception { - Class[] argTypes = new Class[args.length]; - for (int i = 0; i < argTypes.length; i++) { - if (args[i] == null) { - argTypes[i] = Object.class; - } else { - argTypes[i] = args[i].getClass(); - } - } - return argTypes; - } - - protected Object applyImpl(Class type,String methodName,Class[] parameterTypes,Object...args) throws Exception { - final Injector inj = Guice.createInjector(); - Object instance = inj.getInstance(type); - if (args==null) { - return type.getDeclaredMethod(methodName).invoke(instance); - } - Method method = type.getDeclaredMethod(methodName, parameterTypes); - return method.invoke(instance,args); - } - - protected Object applyStatic(Class type,String methodName,Class[] parameterTypes,Object...args) throws Exception { - if (args==null) { - return type.getDeclaredMethod(methodName).invoke(null); - } - Method method = type.getDeclaredMethod(methodName, parameterTypes); - return method.invoke(null, args); - } - - protected Class compileJavaCode(String clazzName, String code) { - String javaCode = compileToJavaCode(code); - try { - Class clazz = compileToClass(clazzName, javaCode); - return clazz; - } catch (Exception e) { - System.err.println(javaCode); - throw new RuntimeException("Java compilation failed. Java code was : \n" + javaCode, e); - } - } - - protected String compileToJavaCode(String xtendCode) { - try { - XtendFile file = parseHelper.parse(xtendCode); - validationHelper.assertNoErrors(file); - JvmGenericType inferredType = associations.getInferredType((XtendClass) file.getXtendTypes().get(0)); - CharSequence javaCode = generator.generateType(inferredType, generatorConfigProvider.get(inferredType)); - return javaCode.toString(); - } catch (Exception exc) { - throw new RuntimeException("Xtend compilation failed:\n" + xtendCode, exc); - } - } @Test public void testStaticMethod() throws Exception { invokeAndExpectStatic(42, "def static foo() { 42 }", "foo"); diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerTestBase.java b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerTestBase.java new file mode 100644 index 00000000000..2c79bab1e02 --- /dev/null +++ b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/CompilerTestBase.java @@ -0,0 +1,155 @@ +/******************************************************************************* + * Copyright (c) 2024 itemis AG (http://www.itemis.eu) and others. + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + *******************************************************************************/ +package org.eclipse.xtend.core.tests.compiler; + +import java.lang.reflect.Method; + +import org.eclipse.xtend.core.compiler.XtendCompiler; +import org.eclipse.xtend.core.jvmmodel.IXtendJvmAssociations; +import org.eclipse.xtend.core.tests.AbstractXtendTestCase; +import org.eclipse.xtend.core.xtend.XtendClass; +import org.eclipse.xtend.core.xtend.XtendFile; +import org.eclipse.xtext.common.types.JvmGenericType; +import org.eclipse.xtext.testing.util.ParseHelper; +import org.eclipse.xtext.testing.validation.ValidationTestHelper; +import org.eclipse.xtext.xbase.compiler.IGeneratorConfigProvider; +import org.eclipse.xtext.xbase.compiler.JvmModelGenerator; +import org.eclipse.xtext.xbase.testing.InMemoryJavaCompiler; +import org.eclipse.xtext.xbase.testing.JavaSource; +import org.eclipse.xtext.xbase.testing.InMemoryJavaCompiler.Result; + +import com.google.inject.Guice; +import com.google.inject.Inject; +import com.google.inject.Injector; + +public abstract class CompilerTestBase extends AbstractXtendTestCase { + protected InMemoryJavaCompiler javaCompiler; + + @Inject + protected ParseHelper parseHelper; + + @Inject + protected ValidationTestHelper validationHelper; + + @Inject + protected XtendCompiler compiler; + + @Inject + protected JvmModelGenerator generator; + + @Inject + private IXtendJvmAssociations associations; + + @Inject + protected IGeneratorConfigProvider generatorConfigProvider; + + @Inject + protected void createInMemoryJavaCompiler(ClassLoader classLoader) { + javaCompiler = new InMemoryJavaCompiler(classLoader, generatorConfigProvider.get(null).getJavaSourceVersion()); + } + + protected void invokeAndExpect2(Object expectation, String xtendclassBody, String methodToInvoke, Object... args) + throws Exception { + Class class1 = compileJavaCode("x.Y", "package x class Y {" + xtendclassBody + "}"); + assertEquals(expectation, apply(class1, methodToInvoke, args)); + } + + protected void invokeAndExpectStatic(Object expectation, String xtendclassBody, String methodToInvoke, Object... args) throws Exception { + Class class1 = compileJavaCode("x.Y", "package x class Y {" + xtendclassBody + "}"); + assertEquals(expectation, applyStatic(class1, methodToInvoke, argTypes(args), args)); + } + + protected void invokeAndExpect3(Object expectation, String xtendclassBody, String methodToInvoke, + Class[] parameterTypes, Object... args) throws Exception { + Class class1 = compileJavaCode("x.Y", "package x class Y {" + xtendclassBody + "}"); + assertEquals(expectation, applyImpl(class1, methodToInvoke, parameterTypes, args)); + } + protected void invokeAndExpect(Object expectation, String functionDef, Object...args) throws Exception { + String fullClass = "package x class Y { def Object testEntry("; + for (int i = 0; i < args.length; i++) { + Object object = args[i]; + if (object == null) { + fullClass+= Object.class.getCanonicalName()+" p"+(i+1); + } else { + fullClass+= object.getClass().getCanonicalName()+" p"+(i+1); + } + if (i+1 compiledClass = compileJavaCode("x.Y",fullClass); + assertEquals(expectation, apply(compiledClass,"testEntry",args)); + } + + protected Object apply(Class type, String methodName, Object... args) throws Exception { + return applyImpl(type, methodName, argTypes(args), args); + } + + protected Class[] argTypes(Object...args) throws Exception { + Class[] argTypes = new Class[args.length]; + for (int i = 0; i < argTypes.length; i++) { + if (args[i] == null) { + argTypes[i] = Object.class; + } else { + argTypes[i] = args[i].getClass(); + } + } + return argTypes; + } + + protected Object applyImpl(Class type,String methodName,Class[] parameterTypes,Object...args) throws Exception { + final Injector inj = Guice.createInjector(); + Object instance = inj.getInstance(type); + if (args==null) { + return type.getDeclaredMethod(methodName).invoke(instance); + } + Method method = type.getDeclaredMethod(methodName, parameterTypes); + return method.invoke(instance,args); + } + + protected Object applyStatic(Class type,String methodName,Class[] parameterTypes,Object...args) throws Exception { + if (args==null) { + return type.getDeclaredMethod(methodName).invoke(null); + } + Method method = type.getDeclaredMethod(methodName, parameterTypes); + return method.invoke(null, args); + } + + protected Class compileJavaCode(String clazzName, String code) { + String javaCode = compileToJavaCode(code); + try { + Class clazz = compileToClass(clazzName, javaCode); + return clazz; + } catch (Exception e) { + System.err.println(javaCode); + throw new RuntimeException("Java compilation failed. Java code was : \n" + javaCode, e); + } + } + + Class compileToClass(String className, String javaCode) { + Result result = javaCompiler.compile(new JavaSource(className.replace(".", "/")+".java", javaCode)); + try { + return result.getClassLoader().loadClass(className); + } catch (ClassNotFoundException e) { + throw new RuntimeException(e); + } + } + + protected String compileToJavaCode(String xtendCode) { + try { + XtendFile file = parseHelper.parse(xtendCode); + validationHelper.assertNoErrors(file); + JvmGenericType inferredType = associations.getInferredType((XtendClass) file.getXtendTypes().get(0)); + CharSequence javaCode = generator.generateType(inferredType, generatorConfigProvider.get(inferredType)); + return javaCode.toString(); + } catch (Exception exc) { + throw new RuntimeException("Xtend compilation failed:\n" + xtendCode, exc); + } + } +} diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/ExtensionsCompilerTest.xtend b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/ExtensionsCompilerTest.xtend index ecc6298cada..c8e91476100 100644 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/ExtensionsCompilerTest.xtend +++ b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/ExtensionsCompilerTest.xtend @@ -31,10 +31,8 @@ class ExtensionsCompilerTest extends AbstractXtendCompilerTest { @SuppressWarnings("all") public class C { public List m(final Iterable it) { - final Comparator _function = new Comparator() { - public int compare(final String $0, final String $1) { - return $0.compareTo($1); - } + final Comparator _function = (String $0, String $1) -> { + return $0.compareTo($1); }; return IterableExtensions.sortWith(it, _function); } @@ -64,10 +62,8 @@ class ExtensionsCompilerTest extends AbstractXtendCompilerTest { @SuppressWarnings("all") public class C { public List m(final List list) { - final Function1 _function = new Function1() { - public String apply(final String it) { - return it; - } + final Function1 _function = (String it) -> { + return it; }; return ListExtensions.map(list, _function); } @@ -95,10 +91,8 @@ class ExtensionsCompilerTest extends AbstractXtendCompilerTest { @SuppressWarnings("all") public class C { public List m(final List list) { - final Function1 _function = new Function1() { - public String apply(final String it) { - return it; - } + final Function1 _function = (String it) -> { + return it; }; return D.map(list, _function); } @@ -125,10 +119,8 @@ class ExtensionsCompilerTest extends AbstractXtendCompilerTest { @SuppressWarnings("all") public class C { public Collection m(final List list) { - final Function1 _function = new Function1() { - public String apply(final String it) { - return it; - } + final Function1 _function = (String it) -> { + return it; }; return this.map(list, _function); } @@ -157,10 +149,8 @@ class ExtensionsCompilerTest extends AbstractXtendCompilerTest { @SuppressWarnings("all") public class C { public List m(final List list) { - final Function1 _function = new Function1() { - public String apply(final String it) { - return it; - } + final Function1 _function = (String it) -> { + return it; }; return this.map(list, _function); } @@ -192,10 +182,8 @@ class ExtensionsCompilerTest extends AbstractXtendCompilerTest { @SuppressWarnings("all") public class C { public List m(final List list) { - final Function1 _function = new Function1() { - public String apply(final String it) { - return it; - } + final Function1 _function = (String it) -> { + return it; }; return ListExtensions.map(list, _function); } @@ -224,10 +212,8 @@ class ExtensionsCompilerTest extends AbstractXtendCompilerTest { @SuppressWarnings("all") public class C { public List m(final List list) { - final Function1 _function = new Function1() { - public String apply(final String it) { - return it; - } + final Function1 _function = (String it) -> { + return it; }; return C.map(list, _function); } @@ -265,10 +251,8 @@ class ExtensionsCompilerTest extends AbstractXtendCompilerTest { private D _d; public Collection m(final List list) { - final Function1 _function = new Function1() { - public String apply(final String it) { - return it; - } + final Function1 _function = (String it) -> { + return it; }; return this._d.map(list, _function); } @@ -300,10 +284,8 @@ class ExtensionsCompilerTest extends AbstractXtendCompilerTest { private D _d; public List m(final List list) { - final Function1 _function = new Function1() { - public String apply(final String it) { - return it; - } + final Function1 _function = (String it) -> { + return it; }; return this._d.map(list, _function); } @@ -341,21 +323,19 @@ class ExtensionsCompilerTest extends AbstractXtendCompilerTest { final Double d = Double.valueOf(1.0); IntegerRange _upTo = new IntegerRange(1, 1); for (@Extension final Integer j : _upTo) { - final Function1 _function = new Function1() { - public Throwable apply(@Extension final Object o) { - Throwable _xtrycatchfinallyexpression = null; - try { - _xtrycatchfinallyexpression = null; - } catch (final Throwable _t) { - if (_t instanceof Throwable) { - @Extension final Throwable t = (Throwable)_t; - _xtrycatchfinallyexpression = InputOutput.println(t); - } else { - throw Exceptions.sneakyThrow(_t); - } + final Function1 _function = (Object o) -> { + Throwable _xtrycatchfinallyexpression = null; + try { + _xtrycatchfinallyexpression = null; + } catch (final Throwable _t) { + if (_t instanceof Throwable) { + @Extension final Throwable t = (Throwable)_t; + _xtrycatchfinallyexpression = InputOutput.println(t); + } else { + throw Exceptions.sneakyThrow(_t); } - return _xtrycatchfinallyexpression; } + return _xtrycatchfinallyexpression; }; _function.apply(null); } @@ -794,15 +774,12 @@ class ExtensionsCompilerTest extends AbstractXtendCompilerTest { ''', ''' import java.util.function.Consumer; import org.eclipse.xtext.xbase.lib.CollectionLiterals; - import org.eclipse.xtext.xbase.lib.Extension; @SuppressWarnings("all") public class C { public void m(final int it) { - final Consumer _function = new Consumer() { - public void accept(@Extension final String s) { - s.substring(it); - } + final Consumer _function = (String s) -> { + s.substring(it); }; CollectionLiterals.newArrayList().forEach(_function); } @@ -914,10 +891,8 @@ class ExtensionsCompilerTest extends AbstractXtendCompilerTest { public ArrayList m3() { ArrayList _newArrayList = CollectionLiterals.newArrayList("foo", "bar"); - final Procedure1> _function = new Procedure1>() { - public void apply(final ArrayList it) { - C.this.at(((String[])Conversions.unwrapArray(it, String.class)), 2); - } + final Procedure1> _function = (ArrayList it) -> { + this.at(((String[])Conversions.unwrapArray(it, String.class)), 2); }; return ObjectExtensions.>operator_doubleArrow(_newArrayList, _function); } diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/Java6CompilerTest.xtend b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/Java6CompilerTest.xtend index 4a98f217a51..d148bf64fc4 100644 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/Java6CompilerTest.xtend +++ b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/Java6CompilerTest.xtend @@ -8,14 +8,11 @@ *******************************************************************************/ package org.eclipse.xtend.core.tests.compiler -import org.eclipse.xtend.core.tests.Java6RuntimeInjectorProvider -import org.eclipse.xtext.testing.InjectWith import org.junit.Test /** * @author Miro Spoenemann - Initial contribution and API */ -@InjectWith(Java6RuntimeInjectorProvider) class Java6CompilerTest extends AbstractXtendCompilerTest { @Test def void testOverrideAbstractClass() { diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/Java8OverloadCompilerTest.xtend b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/Java8OverloadCompilerTest.xtend index f9c35693185..ba68a6b1a91 100644 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/Java8OverloadCompilerTest.xtend +++ b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/Java8OverloadCompilerTest.xtend @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2013, 2016 itemis AG (http://www.itemis.eu) and others. + * Copyright (c) 2013, 2024 itemis AG (http://www.itemis.eu) and others. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. @@ -32,10 +32,8 @@ class Java8OverloadCompilerTest extends AbstractXtendCompilerTest { @SuppressWarnings("all") public class Bug { public void m(final ExecutorService service) { - final Callable _function = new Callable() { - public Object call() throws Exception { - return null; - } + final Callable _function = () -> { + return null; }; service.submit(_function); } @@ -58,10 +56,8 @@ class Java8OverloadCompilerTest extends AbstractXtendCompilerTest { @SuppressWarnings("all") public class Bug { public void m(final ExecutorService service) { - final Runnable _function = new Runnable() { - public void run() { - return; - } + final Runnable _function = () -> { + return; }; service.submit(_function); } @@ -85,10 +81,8 @@ class Java8OverloadCompilerTest extends AbstractXtendCompilerTest { @SuppressWarnings("all") public class Bug { public void m(final ExecutorService service) { - final Callable _function = new Callable() { - public String call() throws Exception { - return ""; - } + final Callable _function = () -> { + return ""; }; service.submit(_function); } @@ -112,10 +106,8 @@ class Java8OverloadCompilerTest extends AbstractXtendCompilerTest { @SuppressWarnings("all") public class Bug { public void m(final ExecutorService service) { - final Callable _function = new Callable() { - public String call() throws Exception { - return ""; - } + final Callable _function = () -> { + return ""; }; service.submit(_function); } @@ -142,10 +134,8 @@ class Java8OverloadCompilerTest extends AbstractXtendCompilerTest { } public void m(final ExecutorService service) { - final Runnable _function = new Runnable() { - public void run() { - Bug.this.m(); - } + final Runnable _function = () -> { + this.m(); }; service.submit(_function); } @@ -176,10 +166,8 @@ class Java8OverloadCompilerTest extends AbstractXtendCompilerTest { } public void m(final Iterable i) { - final Bug.I _function = new Bug.I() { - public void bind(final Runnable it) { - it.run(); - } + final Bug.I _function = (Runnable it) -> { + it.run(); }; this.m(_function); } @@ -210,10 +198,8 @@ class Java8OverloadCompilerTest extends AbstractXtendCompilerTest { } public void m(final Iterable i) { - final Bug.I _function = new Bug.I() { - public void bind(final Runnable it) { - it.run(); - } + final Bug.I _function = (Runnable it) -> { + it.run(); }; this.m(_function); } @@ -244,10 +230,8 @@ class Java8OverloadCompilerTest extends AbstractXtendCompilerTest { } public void m(final Iterable... i) { - final Bug.I _function = new Bug.I() { - public void bind(final Runnable it) { - it.run(); - } + final Bug.I _function = (Runnable it) -> { + it.run(); }; this.m(_function); } @@ -274,10 +258,8 @@ class Java8OverloadCompilerTest extends AbstractXtendCompilerTest { } public void m(final Function0 f) { - final Function0 _function = new Function0() { - public String apply() { - return ""; - } + final Function0 _function = () -> { + return ""; }; this.m(_function); } @@ -304,10 +286,8 @@ class Java8OverloadCompilerTest extends AbstractXtendCompilerTest { } public void m(final Procedure0 f) { - final Function2 _function = new Function2() { - public String apply(final String $0, final String $1) { - return ($0 + $1); - } + final Function2 _function = (String $0, String $1) -> { + return ($0 + $1); }; this.m(_function); } @@ -334,10 +314,8 @@ class Java8OverloadCompilerTest extends AbstractXtendCompilerTest { } public void m(final Function0... f) { - final Function0 _function = new Function0() { - public String apply() { - return ""; - } + final Function0 _function = () -> { + return ""; }; this.m(_function); } @@ -364,10 +342,8 @@ class Java8OverloadCompilerTest extends AbstractXtendCompilerTest { } public void m(final Procedure0 f) { - final Function2 _function = new Function2() { - public String apply(final String $0, final String $1) { - return ($0 + $1); - } + final Function2 _function = (String $0, String $1) -> { + return ($0 + $1); }; this.m(_function); } diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/NestedClassCompilerTest.xtend b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/NestedClassCompilerTest.xtend index 8123ff271be..7e2acb3cdbb 100644 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/NestedClassCompilerTest.xtend +++ b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/NestedClassCompilerTest.xtend @@ -413,18 +413,18 @@ class NestedClassCompilerTest extends AbstractXtendCompilerTest { dis = this; depositExceptionHandler = new AbstractIterator() { + @Override public Boolean computeNext() { return Boolean.valueOf(false); } }; } + @Override public Iterator iterator() { Object _xblockexpression = null; { - final Procedure1 _function = new Procedure1() { - public void apply(final Object it) { - _this__Account_1.dis.processAsyncResponse(true); - } + final Procedure1 _function = (Object it) -> { + this.dis.processAsyncResponse(true); }; this.send(_function); _xblockexpression = null; @@ -491,11 +491,9 @@ class NestedClassCompilerTest extends AbstractXtendCompilerTest { } public void m2() { - final C.I _function = new C.I() { - public void m1(final int it) { - _this__C_1.m1(1); - C.this.m1(""); - } + final C.I _function = (int it) -> { + this.m1(1); + C.this.m1(""); }; final C.I i = _function; } @@ -553,6 +551,7 @@ class NestedClassCompilerTest extends AbstractXtendCompilerTest { public void m2() { final C.I i = new C.I() { + @Override public void m1() { _this__C_1.m1(1); C.this.m1(""); @@ -621,6 +620,7 @@ class NestedClassCompilerTest extends AbstractXtendCompilerTest { new __C_1() { public void m2() { final C.I _function = new C.I() { + @Override public void m1(final int it) { this.m1(1); _this__C_1.m1(1); diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/OverloadedExtensionCompilerTest.xtend b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/OverloadedExtensionCompilerTest.xtend index 97be824d875..3e1ddd6ff79 100644 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/OverloadedExtensionCompilerTest.xtend +++ b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/OverloadedExtensionCompilerTest.xtend @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2013, 2016 itemis AG (http://www.itemis.eu) and others. + * Copyright (c) 2013, 2024 itemis AG (http://www.itemis.eu) and others. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. @@ -34,10 +34,8 @@ class OverloadedExtensionCompilerTest extends AbstractXtendCompilerTest { @SuppressWarnings("all") public class C { public void method(final MyIterable list) { - final Consumer _function = new Consumer() { - public void consume(final Number it) { - C.this.process(it); - } + final Consumer _function = (Number it) -> { + this.process(it); }; list.m(_function); } @@ -67,10 +65,8 @@ class OverloadedExtensionCompilerTest extends AbstractXtendCompilerTest { @SuppressWarnings("all") public class C { public void method(final MyIterable list) { - final Consumer _function = new Consumer() { - public void consume(final Number it) { - C.this.process(it); - } + final Consumer _function = (Number it) -> { + this.process(it); }; list.forEach2(_function); } diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/ParameterizedInnerTypesCompilerTest.xtend b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/ParameterizedInnerTypesCompilerTest.xtend index b53dd06cac3..67f2fc33280 100644 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/ParameterizedInnerTypesCompilerTest.xtend +++ b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/ParameterizedInnerTypesCompilerTest.xtend @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2014, 2022 itemis AG (http://www.itemis.eu) and others. + * Copyright (c) 2014, 2024 itemis AG (http://www.itemis.eu) and others. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. @@ -81,11 +81,9 @@ class ParameterizedInnerTypesCompilerTest extends AbstractXtendCompilerTest { @SuppressWarnings("all") public class EitherTest { public Boolean m(final Either it) { - final Function _function = new Function() { - public Boolean apply(final Integer it_1) { - int _intValue = it_1.intValue(); - return Boolean.valueOf((_intValue == 0)); - } + final Function _function = (Integer it_1) -> { + int _intValue = it_1.intValue(); + return Boolean.valueOf((_intValue == 0)); }; return it.right().on(_function); } @@ -151,10 +149,8 @@ class ParameterizedInnerTypesCompilerTest extends AbstractXtendCompilerTest { @SuppressWarnings("all") public class EitherTest { public Either m(final Either it) { - final Function _function = new Function() { - public String apply(final Boolean it_1) { - return it_1.toString(); - } + final Function _function = (Boolean it_1) -> { + return it_1.toString(); }; return it.map(_function).swap(); } diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/ParameterizedTypeCompilerTest.xtend b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/ParameterizedTypeCompilerTest.xtend index 981a298e24f..d25c1b4c0ae 100644 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/ParameterizedTypeCompilerTest.xtend +++ b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/ParameterizedTypeCompilerTest.xtend @@ -335,6 +335,7 @@ class ParameterizedTypeCompilerTest extends AbstractXtendCompilerTest { super(list); } + @Override public Object woot(final List list) { return super.woot(list); } diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/TryWithResourcesTest.xtend b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/TryWithResourcesTest.xtend index a343cc09e2b..bd1b784d7cc 100644 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/TryWithResourcesTest.xtend +++ b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/TryWithResourcesTest.xtend @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2019 itemis AG (http://www.itemis.eu) and others. + * Copyright (c) 2019, 2024 itemis AG (http://www.itemis.eu) and others. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. @@ -101,8 +101,6 @@ class TryWithResourcesTest extends AbstractXtendCompilerTest { import java.io.IOException; import java.io.StringReader; - import java.util.ArrayList; - import java.util.List; import org.eclipse.xtext.xbase.lib.Exceptions; @SuppressWarnings("all") @@ -110,28 +108,15 @@ class TryWithResourcesTest extends AbstractXtendCompilerTest { private final String s = "line1\nline2\nline3"; public void fooMethod() { - List _ts = new ArrayList(); - StringReader a = null; - try { - a = new StringReader(this.s); + try (final StringReader a = new StringReader(this.s)) { a.read(); } catch (final Throwable _t) { if (_t instanceof IOException) { final IOException e = (IOException)_t; e.fillInStackTrace(); } else { - _ts.add(_t); throw Exceptions.sneakyThrow(_t); } - } finally { - if (a != null) { - try { - a.close(); - } catch (Throwable _t_1) { - _ts.add(_t_1); - } - } - if(!_ts.isEmpty()) throw Exceptions.sneakyThrow(_ts.get(0)); } } } @@ -147,22 +132,10 @@ class TryWithResourcesTest extends AbstractXtendCompilerTest { } '''.buildXtendInput(false, false, false).assertCompilesTo(''' final AutoCloseable[] array = new AutoCloseable[2]; - List _ts = new ArrayList(); - AutoCloseable someCloseable = null; - try { - someCloseable = array[0]; + try (final AutoCloseable someCloseable = array[0]) { someCloseable.close(); - } finally { - if (someCloseable != null) { - try { - someCloseable.close(); - } catch (Throwable _t) { - _ts.add(_t); - } - } - if(!_ts.isEmpty()) throw Exceptions.sneakyThrow(_ts.get(0)); } - '''.buildJavaOutput(false, false, false, true)) + '''.buildJavaOutput(false, false, false, false)) } @Test @@ -177,7 +150,6 @@ class TryWithResourcesTest extends AbstractXtendCompilerTest { package sample; import java.io.StringReader; - import java.util.ArrayList; import java.util.Collections; import java.util.List; import org.eclipse.xtext.xbase.lib.CollectionLiterals; @@ -192,19 +164,7 @@ class TryWithResourcesTest extends AbstractXtendCompilerTest { final StringReader reader1 = new StringReader(this.s); final StringReader reader2 = new StringReader(this.s); final List array = Collections.unmodifiableList(CollectionLiterals.newArrayList(reader1, reader2)); - List _ts = new ArrayList(); - AutoCloseable closable = null; - try { - closable = array.get(0); - } finally { - if (closable != null) { - try { - closable.close(); - } catch (Throwable _t) { - _ts.add(_t); - } - } - if(!_ts.isEmpty()) throw Exceptions.sneakyThrow(_ts.get(0)); + try (final AutoCloseable closable = array.get(0)) { } } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); @@ -229,8 +189,6 @@ class TryWithResourcesTest extends AbstractXtendCompilerTest { package sample; import java.io.StringReader; - import java.util.ArrayList; - import java.util.List; import org.eclipse.xtext.xbase.lib.Exceptions; @SuppressWarnings("all") @@ -239,36 +197,12 @@ class TryWithResourcesTest extends AbstractXtendCompilerTest { public void fooMethod() { try { - List _ts = new ArrayList(); - StringReader a = null; - try { - a = new StringReader(this.s); + try (final StringReader a = new StringReader(this.s)) { final int x = (1 + 1); a.read(); - } finally { - if (a != null) { - try { - a.close(); - } catch (Throwable _t) { - _ts.add(_t); - } - } - if(!_ts.isEmpty()) throw Exceptions.sneakyThrow(_ts.get(0)); } - List _ts_1 = new ArrayList(); - StringReader x = null; - try { - x = new StringReader(this.s); + try (final StringReader x = new StringReader(this.s)) { x.close(); - } finally { - if (x != null) { - try { - x.close(); - } catch (Throwable _t) { - _ts_1.add(_t); - } - } - if(!_ts_1.isEmpty()) throw Exceptions.sneakyThrow(_ts_1.get(0)); } } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); @@ -289,8 +223,6 @@ class TryWithResourcesTest extends AbstractXtendCompilerTest { import java.io.BufferedReader; import java.io.StringReader; - import java.util.ArrayList; - import java.util.List; import org.eclipse.xtext.xbase.lib.Exceptions; @SuppressWarnings("all") @@ -299,29 +231,8 @@ class TryWithResourcesTest extends AbstractXtendCompilerTest { public void fooMethod() { try { - List _ts = new ArrayList(); - StringReader sr = null; - BufferedReader buffy = null; - try { - sr = new StringReader(this.s); - buffy = new BufferedReader(sr); + try (final StringReader sr = new StringReader(this.s); final BufferedReader buffy = new BufferedReader(sr)) { buffy.read(); - } finally { - if (buffy != null) { - try { - buffy.close(); - } catch (Throwable _t) { - _ts.add(_t); - } - } - if (sr != null) { - try { - sr.close(); - } catch (Throwable _t) { - _ts.add(_t); - } - } - if(!_ts.isEmpty()) throw Exceptions.sneakyThrow(_ts.get(0)); } } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); @@ -341,8 +252,6 @@ class TryWithResourcesTest extends AbstractXtendCompilerTest { import java.io.BufferedReader; import java.io.StringReader; - import java.util.ArrayList; - import java.util.List; import org.eclipse.xtext.xbase.lib.Exceptions; @SuppressWarnings("all") @@ -351,20 +260,8 @@ class TryWithResourcesTest extends AbstractXtendCompilerTest { public void fooMethod() { try { - List _ts = new ArrayList(); - BufferedReader br = null; - try { - br = new BufferedReader(new StringReader(this.s)); + try (final BufferedReader br = new BufferedReader(new StringReader(this.s))) { br.readLine(); - } finally { - if (br != null) { - try { - br.close(); - } catch (Throwable _t) { - _ts.add(_t); - } - } - if(!_ts.isEmpty()) throw Exceptions.sneakyThrow(_ts.get(0)); } } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); @@ -385,8 +282,6 @@ class TryWithResourcesTest extends AbstractXtendCompilerTest { import java.io.BufferedReader; import java.io.StringReader; - import java.util.ArrayList; - import java.util.List; import org.eclipse.xtext.xbase.lib.Exceptions; @SuppressWarnings("all") @@ -396,20 +291,8 @@ class TryWithResourcesTest extends AbstractXtendCompilerTest { public void fooMethod() { try { final StringReader sr = new StringReader(this.s); - List _ts = new ArrayList(); - BufferedReader br = null; - try { - br = new BufferedReader(sr); + try (final BufferedReader br = new BufferedReader(sr)) { br.readLine(); - } finally { - if (br != null) { - try { - br.close(); - } catch (Throwable _t) { - _ts.add(_t); - } - } - if(!_ts.isEmpty()) throw Exceptions.sneakyThrow(_ts.get(0)); } } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); @@ -430,8 +313,6 @@ class TryWithResourcesTest extends AbstractXtendCompilerTest { import java.io.BufferedReader; import java.io.StringReader; - import java.util.ArrayList; - import java.util.List; import org.eclipse.xtext.xbase.lib.Exceptions; import org.eclipse.xtext.xbase.lib.Functions.Function0; @@ -441,39 +322,19 @@ class TryWithResourcesTest extends AbstractXtendCompilerTest { public void fooMethod() { try { - List _ts = new ArrayList(); - StringReader fr = null; - BufferedReader br = null; - try { - fr = new Function0() { - public StringReader apply() { - String _xifexpression = null; - if (true) { - _xifexpression = (FooClass.this.s + "1"); - } else { - _xifexpression = (FooClass.this.s + "2"); - } - return new StringReader(_xifexpression); - } - }.apply(); - br = new BufferedReader(fr); - br.read(); - } finally { - if (br != null) { - try { - br.close(); - } catch (Throwable _t) { - _ts.add(_t); + try (final StringReader fr = new Function0() { + @Override + public StringReader apply() { + String _xifexpression = null; + if (true) { + _xifexpression = (FooClass.this.s + "1"); + } else { + _xifexpression = (FooClass.this.s + "2"); } + return new StringReader(_xifexpression); } - if (fr != null) { - try { - fr.close(); - } catch (Throwable _t) { - _ts.add(_t); - } - } - if(!_ts.isEmpty()) throw Exceptions.sneakyThrow(_ts.get(0)); + }.apply(); final BufferedReader br = new BufferedReader(fr)) { + br.read(); } } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); @@ -508,45 +369,31 @@ class TryWithResourcesTest extends AbstractXtendCompilerTest { import java.io.File; import java.io.FileReader; import java.io.IOException; - import java.util.ArrayList; - import java.util.List; import org.eclipse.xtext.xbase.lib.Exceptions; import org.eclipse.xtext.xbase.lib.Functions.Function0; @SuppressWarnings("all") public class FooClass { public void fooMethod() { - List _ts = new ArrayList(); - FileReader a = null; - try { - a = new Function0() { - public FileReader apply() { - try { - File _file = new File("\\home/docs/text.txt"); - return new FileReader(_file); - } catch (Throwable _e) { - throw Exceptions.sneakyThrow(_e); - } + try (final FileReader a = new Function0() { + @Override + public FileReader apply() { + try { + File _file = new File("\\home/docs/text.txt"); + return new FileReader(_file); + } catch (Throwable _e) { + throw Exceptions.sneakyThrow(_e); } - }.apply(); + } + }.apply()) { a.read(); } catch (final Throwable _t) { if (_t instanceof IOException) { final IOException e = (IOException)_t; e.fillInStackTrace(); } else { - _ts.add(_t); throw Exceptions.sneakyThrow(_t); } - } finally { - if (a != null) { - try { - a.close(); - } catch (Throwable _t_1) { - _ts.add(_t_1); - } - } - if(!_ts.isEmpty()) throw Exceptions.sneakyThrow(_ts.get(0)); } } } @@ -559,25 +406,11 @@ class TryWithResourcesTest extends AbstractXtendCompilerTest { try (var r = [System.out.println("Closing")]) { } '''.buildXtendInput(false, false, false).assertCompilesTo(''' - List _ts = new ArrayList(); - AutoCloseable r = null; - try { - r = new AutoCloseable() { - public void close() throws Exception { - System.out.println("Closing"); - } - }; - } finally { - if (r != null) { - try { - r.close(); - } catch (Throwable _t) { - _ts.add(_t); - } - } - if(!_ts.isEmpty()) throw Exceptions.sneakyThrow(_ts.get(0)); + try (AutoCloseable r = ((AutoCloseable) () -> { + System.out.println("Closing"); + })) { } - '''.buildJavaOutput(false, false, false, true)) + '''.buildJavaOutput(false, false, false, false)) } @Test @@ -592,7 +425,6 @@ class TryWithResourcesTest extends AbstractXtendCompilerTest { package sample; import java.util.ArrayList; - import java.util.List; import org.eclipse.xtext.xbase.lib.CollectionLiterals; import org.eclipse.xtext.xbase.lib.Exceptions; @@ -603,24 +435,10 @@ class TryWithResourcesTest extends AbstractXtendCompilerTest { public void fooMethod() { try { final ArrayList myList = CollectionLiterals.newArrayList(); - List _ts = new ArrayList(); - AutoCloseable someCloseable = null; - try { - someCloseable = new AutoCloseable() { - public void close() throws Exception { - myList.add("close"); - } - }; + try (final AutoCloseable someCloseable = ((AutoCloseable) () -> { + myList.add("close"); + })) { myList.add("body"); - } finally { - if (someCloseable != null) { - try { - someCloseable.close(); - } catch (Throwable _t) { - _ts.add(_t); - } - } - if(!_ts.isEmpty()) throw Exceptions.sneakyThrow(_ts.get(0)); } } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/XbaseIntegrationTest.java b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/XbaseIntegrationTest.java index d217187be3d..b6d83da0364 100644 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/XbaseIntegrationTest.java +++ b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/XbaseIntegrationTest.java @@ -11,18 +11,21 @@ import org.eclipse.xtend.core.tests.RuntimeInjectorProvider; import org.eclipse.xtext.testing.InjectWith; import org.eclipse.xtext.testing.XtextRunner; +import org.eclipse.xtext.xbase.testing.evaluation.AbstractXbaseEvaluationTestEx; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import com.google.inject.Inject; +import testdata.TryBodyException; + /** * @author Sven Efftinge - Initial contribution and API */ @RunWith(XtextRunner.class) @InjectWith(RuntimeInjectorProvider.class) -public class XbaseIntegrationTest extends AbstractXbaseEvaluationTest { +public class XbaseIntegrationTest extends AbstractXbaseEvaluationTestEx { @Inject private CompilerTestHelper testHelper; @@ -80,4 +83,25 @@ protected void assertIntegerAssignOperations(Integer expectedResult, String xbas assertEvaluatesTo(Boolean.TRUE, "(new testdata.ClassWithVarArgs(1, '', '', '') {}).varArgConstructor"); } + @Test @Override + public void testTryWithResources_ExceptionInBody() throws Exception { + assertEvaluatesWithException(TryBodyException.class, + "try (var a = new testdata.ClosableWithListExceptionOnAdd()) {\n" + + " a.add(\"body\")\n" + + " a.addExc\n" + + "}\n" + + "null"); + } + + @Test @Override + public void testTryWithResources_2ResourcesCatch_02() throws Exception { + assertEvaluatesWithException(InstantiationException.class, //b.add would invoke NullPointerExcpt, but InstExc came first and is caught + "var java.util.List result\n" + + "try (var a = new testdata.ClosableWithList;\n" + + " var b = new testdata.ClosableWithListExceptionOnConstr) {\n" + + " a.add(\"body\")\n" + + " b.add(\"body\")\n" + + "}\n" + + "null"); + } } diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/XtendCompilerTest.xtend b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/XtendCompilerTest.xtend index 01f58970837..2acf47242ff 100644 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/XtendCompilerTest.xtend +++ b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/XtendCompilerTest.xtend @@ -11,7 +11,6 @@ package org.eclipse.xtend.core.tests.compiler import com.google.inject.Inject import org.eclipse.xtext.common.types.JvmDeclaredType import org.eclipse.xtext.generator.IFilePostProcessor -import org.eclipse.xtext.util.JavaVersion import org.junit.Test class XtendCompilerTest extends AbstractXtendCompilerTest { @@ -94,11 +93,13 @@ class XtendCompilerTest extends AbstractXtendCompilerTest { } public static class E1 extends Exception implements Foo.E { + @Override public void m() { } } public static class E2 extends Exception implements Foo.E { + @Override public void m() { } } @@ -127,32 +128,28 @@ class XtendCompilerTest extends AbstractXtendCompilerTest { ''') } - @Test - def testClosureNoArgs() { - assertCompilesTo(''' + @Test def void testClosureNoArgs() { + ''' class Foo { val thread = new Thread [] } - ''',''' + '''.assertCompilesTo(''' @SuppressWarnings("all") public class Foo { - private final Thread thread = new Thread(new Runnable() { - public void run() { - } - }); + private final Thread thread = new Thread(((Runnable) () -> { + })); } ''') } - @Test - def testClosureTwoArgs() { - assertCompilesTo(''' + @Test def void testClosureTwoArgs() { + ''' class Foo { def void m(java.util.List list) { java.util.Collections.sort(list) [ return 0 ] } } - ''',''' + '''.assertCompilesTo(''' import java.util.Collections; import java.util.Comparator; import java.util.List; @@ -160,10 +157,8 @@ class XtendCompilerTest extends AbstractXtendCompilerTest { @SuppressWarnings("all") public class Foo { public void m(final List list) { - final Comparator _function = new Comparator() { - public int compare(final String $0, final String $1) { - return 0; - } + final Comparator _function = (String $0, String $1) -> { + return 0; }; Collections.sort(list, _function); } @@ -171,7 +166,7 @@ class XtendCompilerTest extends AbstractXtendCompilerTest { ''') } - @Test def testInnerTypeImports() { + @Test def void testInnerTypeImports_1() { assertCompilesTo(''' class Foo extends types.SomeClassWithNestedInterface implements types.SomeClassWithNestedInterface.NestedInterface {} ''', ''' @@ -183,18 +178,19 @@ class XtendCompilerTest extends AbstractXtendCompilerTest { ''') } - @Test def testInnerTypeImports_1() { - assertCompilesTo(''' + @Test def void testInnerTypeImports_2() { + ''' class Foo extends types.SomeClassWithNestedInterface { override types.SomeClassWithNestedInterface.String convert(java.lang.String s) { return null; } } - ''', ''' + '''.assertCompilesTo(''' import types.SomeClassWithNestedInterface; @SuppressWarnings("all") public class Foo extends SomeClassWithNestedInterface { + @Override public SomeClassWithNestedInterface.String convert(final java.lang.String s) { return null; } @@ -328,9 +324,8 @@ class XtendCompilerTest extends AbstractXtendCompilerTest { } ''') } - @Test - def testExpectationFromTypeParameter() { - assertCompilesTo(''' + @Test def void testExpectationFromTypeParameter() { + ''' import java.util.Set import org.eclipse.xtext.common.types.JvmTypeParameter import org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference @@ -351,7 +346,7 @@ class XtendCompilerTest extends AbstractXtendCompilerTest { return newHashSet } } - ''', ''' + '''.assertCompilesTo(''' import java.util.Set; import org.eclipse.xtext.common.types.JvmTypeParameter; import org.eclipse.xtext.xbase.lib.CollectionLiterals; @@ -365,10 +360,12 @@ class XtendCompilerTest extends AbstractXtendCompilerTest { super(null, owner); } + @Override public LightweightTypeReference substitute(final LightweightTypeReference original) { return original., LightweightTypeReference>accept(this, CollectionLiterals.newHashSet()); } + @Override protected Set createVisiting() { return CollectionLiterals.newHashSet(); } @@ -924,19 +921,20 @@ class XtendCompilerTest extends AbstractXtendCompilerTest { } @Test def void testRecursiveLambda_01() { - assertCompilesTo(''' + ''' public class Foo { def void foo((String)=>String func) { foo[self.apply(it)] } } - ''', ''' + '''.assertCompilesTo(''' import org.eclipse.xtext.xbase.lib.Functions.Function1; @SuppressWarnings("all") public class Foo { public void foo(final Function1 func) { final Function1 _function = new Function1() { + @Override public String apply(final String it) { return this.apply(it); } @@ -948,19 +946,20 @@ class XtendCompilerTest extends AbstractXtendCompilerTest { } @Test def void testRecursiveLambda_02() { - assertCompilesTo(''' + ''' public class Foo { def void foo(()=>void func) { foo[|self.apply()] } } - ''', ''' + '''.assertCompilesTo(''' import org.eclipse.xtext.xbase.lib.Procedures.Procedure0; @SuppressWarnings("all") public class Foo { public void foo(final Procedure0 func) { final Procedure0 _function = new Procedure0() { + @Override public void apply() { this.apply(); } @@ -1057,7 +1056,7 @@ class XtendCompilerTest extends AbstractXtendCompilerTest { } @Test def void testAbstractIterator_03() { - assertCompilesTo(''' + ''' import java.util.Iterator import com.google.common.collect.AbstractIterator public class Foo { @@ -1068,7 +1067,7 @@ class XtendCompilerTest extends AbstractXtendCompilerTest { return result } } - ''', ''' + '''.assertCompilesTo(''' import com.google.common.collect.AbstractIterator; import java.util.Iterator; import org.eclipse.xtext.xbase.lib.Functions.Function1; @@ -1081,10 +1080,8 @@ class XtendCompilerTest extends AbstractXtendCompilerTest { @Override protected T computeNext() { T _elvis = null; - final Function1 _function = new Function1() { - public Boolean apply(final T it) { - return Boolean.valueOf((it != null)); - } + final Function1 _function = (T it) -> { + return Boolean.valueOf((it != null)); }; T _findFirst = IteratorExtensions.findFirst(iter, _function); if (_findFirst != null) { @@ -1103,128 +1100,82 @@ class XtendCompilerTest extends AbstractXtendCompilerTest { ''') } - @Test - def testAbstractIterator_04() { - assertCompilesTo( - ''' - import java.util.Iterator - import com.google.common.collect.AbstractIterator - class FindFirstOnIt { - - def Iterator skipNulls(Iterator it) { - val AbstractIterator result = [| - findFirst [ it != null ] ?: self.endOfData - ] - return result - } - } - ''', ''' - import com.google.common.collect.AbstractIterator; - import java.util.Iterator; - import java.util.Objects; - import org.eclipse.xtext.xbase.lib.Functions.Function1; - import org.eclipse.xtext.xbase.lib.IteratorExtensions; - - @SuppressWarnings("all") - public class FindFirstOnIt { - public Iterator skipNulls(final Iterator it) { - final AbstractIterator _function = new AbstractIterator() { - @Override - protected T computeNext() { - T _elvis = null; - final Function1 _function = new Function1() { - public Boolean apply(final T it_1) { - return Boolean.valueOf((!Objects.equals(it_1, null))); - } - }; - T _findFirst = IteratorExtensions.findFirst(it, _function); - if (_findFirst != null) { - _elvis = _findFirst; - } else { - T _endOfData = this.endOfData(); - _elvis = _endOfData; - } - return _elvis; - } - }; - final AbstractIterator result = _function; - return result; - } - } - ''') - } - - @Test def testVoidMethod_01() throws Exception { - ''' - class A { - def m() { - System::out.println('') - } - } - '''.assertCompilesTo(''' - @SuppressWarnings("all") - public class A { - public void m() { - System.out.println(""); - } - } - ''') - } - - @Test def testVoidMethod_02() throws Exception { + @Test def void testAbstractIterator_04() { ''' - class A { - def m() { - [ | System::out.println('') ] + import java.util.Iterator + import com.google.common.collect.AbstractIterator + class FindFirstOnIt { + + def Iterator skipNulls(Iterator it) { + val AbstractIterator result = [| + findFirst [ it != null ] ?: self.endOfData + ] + return result } } '''.assertCompilesTo(''' - import org.eclipse.xtext.xbase.lib.Procedures.Procedure0; - + import com.google.common.collect.AbstractIterator; + import java.util.Iterator; + import java.util.Objects; + import org.eclipse.xtext.xbase.lib.Functions.Function1; + import org.eclipse.xtext.xbase.lib.IteratorExtensions; + @SuppressWarnings("all") - public class A { - public Procedure0 m() { - final Procedure0 _function = new Procedure0() { - public void apply() { - System.out.println(""); + public class FindFirstOnIt { + public Iterator skipNulls(final Iterator it) { + final AbstractIterator _function = new AbstractIterator() { + @Override + protected T computeNext() { + T _elvis = null; + final Function1 _function = (T it_1) -> { + return Boolean.valueOf((!Objects.equals(it_1, null))); + }; + T _findFirst = IteratorExtensions.findFirst(it, _function); + if (_findFirst != null) { + _elvis = _findFirst; + } else { + T _endOfData = this.endOfData(); + _elvis = _endOfData; + } + return _elvis; } }; - return _function; + final AbstractIterator result = _function; + return result; } } ''') } - @Test def testVoidMethod_03() throws Exception { + @Test def testVoidMethod_01() throws Exception { ''' class A { def m() { - [ | println('') ] + System::out.println('') } } '''.assertCompilesTo(''' - import org.eclipse.xtext.xbase.lib.Functions.Function0; - import org.eclipse.xtext.xbase.lib.InputOutput; - @SuppressWarnings("all") public class A { - public Function0 m() { - final Function0 _function = new Function0() { - public String apply() { - return InputOutput.println(""); - } - }; - return _function; + public void m() { + System.out.println(""); } } ''') } - @Test def testThrowablesPropagate_01() throws Exception { + @Test def void testThrowablesPropagate_01() throws Exception { ''' import static extension Throwables.* import java.net.URI + class Client { + val uri = [| new URI('')].propagate [ new IllegalArgumentException(it) ] + + def foo (){ + uri.toString + } + } class Throwables { def static T propagate(()=>T proc, (Exception)=>Exception handler) { try { @@ -1234,43 +1185,32 @@ class XtendCompilerTest extends AbstractXtendCompilerTest { } } } - class Client { - val uri = [| new URI('')].propagate [ new IllegalArgumentException(it) ] - - def foo (){ - uri.toString - } - } '''.assertCompilesTo(''' + import java.net.URI; import org.eclipse.xtext.xbase.lib.Exceptions; import org.eclipse.xtext.xbase.lib.Functions.Function0; import org.eclipse.xtext.xbase.lib.Functions.Function1; @SuppressWarnings("all") - public class Throwables { - public static T propagate(final Function0 proc, final Function1 handler) { + public class Client { + private final URI uri = Throwables.propagate(((Function0) () -> { try { - T _xtrycatchfinallyexpression = null; - try { - _xtrycatchfinallyexpression = proc.apply(); - } catch (final Throwable _t) { - if (_t instanceof Exception) { - final Exception e = (Exception)_t; - throw handler.apply(e); - } else { - throw Exceptions.sneakyThrow(_t); - } - } - return _xtrycatchfinallyexpression; + return new URI(""); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } + }), ((Function1) (Exception it) -> { + return new IllegalArgumentException(it); + })); + + public String foo() { + return this.uri.toString(); } } ''') } - @Test def testThrowablesPropagate_02() throws Exception { + @Test def void testThrowablesPropagate_02() throws Exception { ''' import static extension Throwables.* import java.net.URI @@ -1295,19 +1235,15 @@ class XtendCompilerTest extends AbstractXtendCompilerTest { @SuppressWarnings("all") public class Client { - private final URI uri = Throwables.propagate(new Function0() { - public URI apply() { - try { - return new URI(""); - } catch (Throwable _e) { - throw Exceptions.sneakyThrow(_e); - } - } - }, new Function1() { - public Exception apply(final Exception it) { - return new IllegalArgumentException(it); + private final URI uri = Throwables.propagate(((Function0) () -> { + try { + return new URI(""); + } catch (Throwable _e) { + throw Exceptions.sneakyThrow(_e); } - }); + }), ((Function1) (Exception it) -> { + return new IllegalArgumentException(it); + })); } ''') } @@ -1447,7 +1383,7 @@ class XtendCompilerTest extends AbstractXtendCompilerTest { /** * see https://bugs.eclipse.org/bugs/show_bug.cgi?id=395043 */ - @Test def testOverriddenVarArgs() { + @Test def void testOverriddenVarArgs() { ''' class B extends A { override foo(String x, String...args) { @@ -1461,6 +1397,7 @@ class XtendCompilerTest extends AbstractXtendCompilerTest { '''.assertCompilesTo(''' @SuppressWarnings("all") public class B extends A { + @Override public String foo(final String x, final String... args) { return x; } @@ -1642,11 +1579,13 @@ class XtendCompilerTest extends AbstractXtendCompilerTest { } public static class E1 extends Exception implements C.E { + @Override public void m() { } } public static class E2 extends Exception implements C.E { + @Override public void m() { } } @@ -1692,11 +1631,13 @@ class XtendCompilerTest extends AbstractXtendCompilerTest { } public static class E1 extends Exception implements C.E { + @Override public void m() { } } public static class E2 extends Exception implements C.E { + @Override public void m() { } } @@ -1879,55 +1820,50 @@ class XtendCompilerTest extends AbstractXtendCompilerTest { ''') } - @Test - def testSwitchWithBooleanExpression_3() { + @Test def void testSwitchWithBooleanExpression_3() { ''' - class Foo { - def foo(int x) { - switch x { - case [|1 == x].apply || x == 2: true - default: false + class Foo { + def foo(int x) { + switch x { + case [|1 == x].apply || x == 2: true + default: false + } } } - } - '''.assertCompilesTo( - ''' - import org.eclipse.xtext.xbase.lib.Functions.Function0; - - @SuppressWarnings("all") - public class Foo { - public boolean foo(final int x) { - boolean _switchResult = false; - boolean _matched = false; - if (((new Function0() { - public Boolean apply() { - return Boolean.valueOf((1 == x)); - } - }.apply()).booleanValue() || (x == 2))) { - _matched=true; - _switchResult = true; - } - if (!_matched) { - _switchResult = false; - } - return _switchResult; - } - } + '''.assertCompilesTo(''' + import org.eclipse.xtext.xbase.lib.Functions.Function0; + + @SuppressWarnings("all") + public class Foo { + public boolean foo(final int x) { + boolean _switchResult = false; + boolean _matched = false; + if (((((Function0) () -> { + return Boolean.valueOf((1 == x)); + }).apply()).booleanValue() || (x == 2))) { + _matched=true; + _switchResult = true; + } + if (!_matched) { + _switchResult = false; + } + return _switchResult; + } + } ''') } - @Test - def testSwitchOverNull() { - assertCompilesTo(''' + @Test def void testSwitchOverNull() { + ''' public class Foo { def foo() { switch null { case null : [Object it|it] case null : [Integer it|it] } - } + } } - ''', ''' + '''.assertCompilesTo(''' import java.util.Objects; import org.eclipse.xtext.xbase.lib.Functions.Function1; @@ -1939,20 +1875,16 @@ class XtendCompilerTest extends AbstractXtendCompilerTest { boolean _matched = false; if (Objects.equals(_switchValue, null)) { _matched=true; - final Function1 _function = new Function1() { - public Object apply(final Object it) { - return it; - } + final Function1 _function = (Object it) -> { + return it; }; _switchResult = _function; } if (!_matched) { if (Objects.equals(_switchValue, null)) { _matched=true; - final Function1 _function_1 = new Function1() { - public Integer apply(final Integer it) { - return it; - } + final Function1 _function_1 = (Integer it) -> { + return it; }; _switchResult = _function_1; } @@ -2138,103 +2070,95 @@ class XtendCompilerTest extends AbstractXtendCompilerTest { ''') } + @Test def void testSwitchWithConstantExpressions_6() { + ''' + class Foo { + def foo() { + switch x : [|1].apply { + case 1: true + } + } + } + '''.assertCompilesTo(''' + import org.eclipse.xtext.xbase.lib.Functions.Function0; + + @SuppressWarnings("all") + public class Foo { + public boolean foo() { + boolean _switchResult = false; + final Function0 _function = () -> { + return Integer.valueOf(1); + }; + Integer _apply = _function.apply(); + final Integer x = _apply; + if (x != null) { + switch (x) { + case 1: + _switchResult = true; + break; + } + } + return _switchResult; + } + } + ''') + } + + @Test def void testSwitchWithConstantExpressions_7() { + ''' + class Foo { + def foo() { + switch x : 1 { + case [|1].apply: true + } + } + } + '''.assertCompilesTo(''' + import java.util.Objects; + import org.eclipse.xtext.xbase.lib.Functions.Function0; + + @SuppressWarnings("all") + public class Foo { + public boolean foo() { + boolean _switchResult = false; + final int x = 1; + boolean _matched = false; + final Function0 _function = () -> { + return Integer.valueOf(1); + }; + Integer _apply = _function.apply(); + if (Objects.equals(x, _apply)) { + _matched=true; + _switchResult = true; + } + return _switchResult; + } + } + ''') + } + @Test - def testSwitchWithConstantExpressions_6() { + def testSwitchWithConstantExpressions_8() { ''' class Foo { def foo() { - switch x : [|1].apply { - case 1: true + switch x : Thread.State.NEW { + case Thread.State.NEW: true + case Thread.State.RUNNABLE: false + case BLOCKED: true } } } '''.assertCompilesTo( ''' - import org.eclipse.xtext.xbase.lib.Functions.Function0; - @SuppressWarnings("all") public class Foo { public boolean foo() { boolean _switchResult = false; - final Function0 _function = new Function0() { - public Integer apply() { - return Integer.valueOf(1); - } - }; - Integer _apply = _function.apply(); - final Integer x = _apply; + final Thread.State x = Thread.State.NEW; if (x != null) { switch (x) { - case 1: - _switchResult = true; - break; - } - } - return _switchResult; - } - } - ''') - } - - @Test - def testSwitchWithConstantExpressions_7() { - ''' - class Foo { - def foo() { - switch x : 1 { - case [|1].apply: true - } - } - } - '''.assertCompilesTo( - ''' - import java.util.Objects; - import org.eclipse.xtext.xbase.lib.Functions.Function0; - - @SuppressWarnings("all") - public class Foo { - public boolean foo() { - boolean _switchResult = false; - final int x = 1; - boolean _matched = false; - final Function0 _function = new Function0() { - public Integer apply() { - return Integer.valueOf(1); - } - }; - Integer _apply = _function.apply(); - if (Objects.equals(x, _apply)) { - _matched=true; - _switchResult = true; - } - return _switchResult; - } - } - ''') - } - - @Test - def testSwitchWithConstantExpressions_8() { - ''' - class Foo { - def foo() { - switch x : Thread.State.NEW { - case Thread.State.NEW: true - case Thread.State.RUNNABLE: false - case BLOCKED: true - } - } - } - '''.assertCompilesTo( - ''' - @SuppressWarnings("all") - public class Foo { - public boolean foo() { - boolean _switchResult = false; - final Thread.State x = Thread.State.NEW; - if (x != null) { - switch (x) { - case NEW: + case NEW: _switchResult = true; break; case RUNNABLE: @@ -2687,9 +2611,8 @@ class XtendCompilerTest extends AbstractXtendCompilerTest { ''') } - @Test - def testClosureSneakyThrow() { - assertCompilesTo(''' + @Test def void testClosureSneakyThrow() { + ''' import java.io.File import java.io.IOException import java.util.Collections @@ -2703,7 +2626,7 @@ class XtendCompilerTest extends AbstractXtendCompilerTest { } } } - ''',''' + '''.assertCompilesTo(''' import java.io.File; import java.io.IOException; import java.util.Collections; @@ -2718,13 +2641,11 @@ class XtendCompilerTest extends AbstractXtendCompilerTest { public List bar() { List _xtrycatchfinallyexpression = null; try { - final Function1 _function = new Function1() { - public File apply(final String f) { - try { - return new File(f).getCanonicalFile(); - } catch (Throwable _e) { - throw Exceptions.sneakyThrow(_e); - } + final Function1 _function = (String f) -> { + try { + return new File(f).getCanonicalFile(); + } catch (Throwable _e) { + throw Exceptions.sneakyThrow(_e); } }; _xtrycatchfinallyexpression = ListExtensions.map(CollectionLiterals.newArrayList("file1.ext"), _function); @@ -2741,8 +2662,7 @@ class XtendCompilerTest extends AbstractXtendCompilerTest { ''') } - @Test - def testClosureSneakyThrow_02() throws Exception { + @Test def void testClosureSneakyThrow_02() throws Exception { ''' abstract class Foo { def Object getFoo(String x) throws Exception @@ -2762,13 +2682,11 @@ class XtendCompilerTest extends AbstractXtendCompilerTest { public abstract Object getFoo(final String x) throws Exception; public Map bar() { - final Function1 _function = new Function1() { - public Object apply(final String it) { - try { - return Foo.this.getFoo(it); - } catch (Throwable _e) { - throw Exceptions.sneakyThrow(_e); - } + final Function1 _function = (String it) -> { + try { + return this.getFoo(it); + } catch (Throwable _e) { + throw Exceptions.sneakyThrow(_e); } }; return IterableExtensions.toMap(CollectionLiterals.newArrayList(), _function); @@ -3513,24 +3431,24 @@ class XtendCompilerTest extends AbstractXtendCompilerTest { ) } - @Test - def testSuperCall_01() { - assertCompilesTo(''' + @Test def void testSuperCall_01() { + ''' package x class Y extends Object { override boolean equals(Object p){ if ('foo' == p) return true else - super.equals(p) - } + super.equals(p) + } } - ''', ''' + '''.assertCompilesTo(''' package x; import java.util.Objects; @SuppressWarnings("all") public class Y { + @Override public boolean equals(final Object p) { boolean _xifexpression = false; boolean _equals = Objects.equals("foo", p); @@ -3594,9 +3512,8 @@ class XtendCompilerTest extends AbstractXtendCompilerTest { ''') } - @Test - def testSuperCall_03() { - assertCompilesTo(''' + @Test def void testSuperCall_03() { + ''' package x class B extends A { override getThing() { @@ -3620,11 +3537,12 @@ class XtendCompilerTest extends AbstractXtendCompilerTest { return s } } - ''', ''' + '''.assertCompilesTo(''' package x; @SuppressWarnings("all") public class B extends A { + @Override public String getThing() { String _xblockexpression = null; { @@ -3937,16 +3855,15 @@ class XtendCompilerTest extends AbstractXtendCompilerTest { '''); } - @Test - def testNestedClosureWithIt() { - assertCompilesTo(''' + @Test def void testNestedClosureWithIt() { + ''' class X { def foo() { val (String)=>String function = [ [String it | it].apply(it) ] function.apply('foo') } } - ''',''' + '''.assertCompilesTo(''' import org.eclipse.xtext.xbase.lib.Functions.Function1; @SuppressWarnings("all") @@ -3954,15 +3871,11 @@ class XtendCompilerTest extends AbstractXtendCompilerTest { public String foo() { String _xblockexpression = null; { - final Function1 _function = new Function1() { - public String apply(final String it) { - final Function1 _function = new Function1() { - public String apply(final String it_1) { - return it_1; - } - }; - return _function.apply(it); - } + final Function1 _function = (String it) -> { + final Function1 _function_1 = (String it_1) -> { + return it_1; + }; + return _function_1.apply(it); }; final Function1 function = _function; _xblockexpression = function.apply("foo"); @@ -3973,29 +3886,24 @@ class XtendCompilerTest extends AbstractXtendCompilerTest { ''') } - @Test - def testNestedClosureSuperCall() { - assertCompilesTo(''' + @Test def void testNestedClosureSuperCall() { + ''' class X { def foo() { [| [| super.toString ].apply ].apply } } - ''',''' + '''.assertCompilesTo(''' import org.eclipse.xtext.xbase.lib.Functions.Function0; @SuppressWarnings("all") public class X { public String foo() { - final Function0 _function = new Function0() { - public String apply() { - final Function0 _function = new Function0() { - public String apply() { - return X.super.toString(); - } - }; - return _function.apply(); - } + final Function0 _function = () -> { + final Function0 _function_1 = () -> { + return super.toString(); + }; + return _function_1.apply(); }; return _function.apply(); } @@ -4202,7 +4110,7 @@ class XtendCompilerTest extends AbstractXtendCompilerTest { } @Test - def testNoVarForRightHandSideOfVarDecl() { + def void testNoVarForRightHandSideOfVarDecl() { assertCompilesTo(''' package foo; @@ -4224,9 +4132,9 @@ class XtendCompilerTest extends AbstractXtendCompilerTest { } ''') } - @Test - def testJavaKeywordsUsed() { - assertCompilesTo(''' + + @Test def void testJavaKeywordsUsed() { + ''' package foo; public class Foo { @@ -4239,13 +4147,13 @@ class XtendCompilerTest extends AbstractXtendCompilerTest { } } } - ''', ''' + '''.assertCompilesTo(''' package foo; import java.util.ArrayList; import java.util.function.Consumer; import org.eclipse.xtext.xbase.lib.CollectionLiterals; - + @SuppressWarnings("all") public class Foo { public void someMethod(final String assert_) { @@ -4257,10 +4165,8 @@ class XtendCompilerTest extends AbstractXtendCompilerTest { boolean _greaterThan = (_length > 2); if (_greaterThan) { _matched=true; - final Consumer _function = new Consumer() { - public void accept(final String break_) { - (break_ + continue_).toString(); - } + final Consumer _function = (String break_) -> { + (break_ + continue_).toString(); }; synchronized_.forEach(_function); } @@ -4270,92 +4176,82 @@ class XtendCompilerTest extends AbstractXtendCompilerTest { ''') } - @Test - def testFindFirstOnIt_01() { - assertCompilesTo( - ''' - class FindFirstOnIt { - def useExtension(Iterable it) { - findFirst [ it !== null ] - } - } - ''', ''' - import org.eclipse.xtext.xbase.lib.Functions.Function1; - import org.eclipse.xtext.xbase.lib.IterableExtensions; - - @SuppressWarnings("all") - public class FindFirstOnIt { - public T useExtension(final Iterable it) { - final Function1 _function = new Function1() { - public Boolean apply(final T it_1) { - return Boolean.valueOf((it_1 != null)); - } - }; - return IterableExtensions.findFirst(it, _function); - } + @Test def void testFindFirstOnIt_01() { + ''' + class FindFirstOnIt { + def useExtension(Iterable it) { + findFirst [ it !== null ] } - ''') + } + '''.assertCompilesTo(''' + import org.eclipse.xtext.xbase.lib.Functions.Function1; + import org.eclipse.xtext.xbase.lib.IterableExtensions; + + @SuppressWarnings("all") + public class FindFirstOnIt { + public T useExtension(final Iterable it) { + final Function1 _function = (T it_1) -> { + return Boolean.valueOf((it_1 != null)); + }; + return IterableExtensions.findFirst(it, _function); + } + } + ''') } - @Test - def testReturnType() { - assertCompilesTo( - ''' - import test.ReturnTypeUsesTypeParameter - class MyClass implements ReturnTypeUsesTypeParameter { - - override accept(LocalName param) { - null - } - } - ''', ''' - import test.ReturnTypeUsesTypeParameter; - - @SuppressWarnings("all") - public class MyClass implements ReturnTypeUsesTypeParameter { - public ReturnTypeUsesTypeParameter.Inner accept(final LocalName param) { - return null; - } + @Test def void testReturnType() { + ''' + import test.ReturnTypeUsesTypeParameter + class MyClass implements ReturnTypeUsesTypeParameter { + + override accept(LocalName param) { + null } - ''') - + } + '''.assertCompilesTo(''' + import test.ReturnTypeUsesTypeParameter; + + @SuppressWarnings("all") + public class MyClass implements ReturnTypeUsesTypeParameter { + @Override + public ReturnTypeUsesTypeParameter.Inner accept(final LocalName param) { + return null; + } + } + ''') } - @Test - def testReturnType_02() { - assertCompilesTo( - ''' - import test.ReturnTypeUsesTypeParameter - class MyClass implements ReturnTypeUsesTypeParameter { - - override accept(LocalName param) { - [ if (true) it?.apply(param) ] - } - } - ''', ''' - import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; - import test.ReturnTypeUsesTypeParameter; - - @SuppressWarnings("all") - public class MyClass implements ReturnTypeUsesTypeParameter { - public ReturnTypeUsesTypeParameter.Inner accept(final LocalName param) { - final ReturnTypeUsesTypeParameter.Inner _function = new ReturnTypeUsesTypeParameter.Inner() { - public void useProcedure(final Procedure1 it) { - if (true) { - if (it!=null) { - it.apply(param); - } - } - } - }; - return _function; - } + @Test def void testReturnType_02() { + ''' + import test.ReturnTypeUsesTypeParameter + class MyClass implements ReturnTypeUsesTypeParameter { + + override accept(LocalName param) { + [ if (true) it?.apply(param) ] } - ''') + } + '''.assertCompilesTo(''' + import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; + import test.ReturnTypeUsesTypeParameter; + + @SuppressWarnings("all") + public class MyClass implements ReturnTypeUsesTypeParameter { + @Override + public ReturnTypeUsesTypeParameter.Inner accept(final LocalName param) { + final ReturnTypeUsesTypeParameter.Inner _function = (Procedure1 it) -> { + if (true) { + if (it!=null) { + it.apply(param); + } + } + }; + return _function; + } + } + ''') } - @Test - def void testReturnType_03() { + @Test def void testReturnType_03() { ''' import java.util.LinkedList @@ -4369,7 +4265,7 @@ class XtendCompilerTest extends AbstractXtendCompilerTest { } abstract class A { - def CharSequence m() + def CharSequence m() } '''.assertCompilesTo(''' @SuppressWarnings("all") @@ -4378,6 +4274,7 @@ class XtendCompilerTest extends AbstractXtendCompilerTest { return this.client(this.m()); } + @Override public CharSequence m() { return ""; } @@ -4670,7 +4567,7 @@ class XtendCompilerTest extends AbstractXtendCompilerTest { */ package foo - class bar { + class MyClass { String name = 'foobar' } ''', @@ -4686,7 +4583,7 @@ class XtendCompilerTest extends AbstractXtendCompilerTest { package foo; @SuppressWarnings("all") - public class bar { + public class MyClass { private String name = "foobar"; } ''') @@ -5653,17 +5550,15 @@ class XtendCompilerTest extends AbstractXtendCompilerTest { @Test def void testXFunctionTypeRefAsSuperType_01() { ''' class Foo implements ()=>void { - override apply() { - } - } '''.assertCompilesTo(''' import org.eclipse.xtext.xbase.lib.Procedures.Procedure0; @SuppressWarnings("all") public class Foo implements Procedure0 { + @Override public void apply() { } } @@ -5673,34 +5568,31 @@ class XtendCompilerTest extends AbstractXtendCompilerTest { @Test def void testXFunctionTypeRefAsSuperType_02() { ''' interface Foo extends ()=>void { - - override void apply(); - + override void apply() } '''.assertCompilesTo(''' import org.eclipse.xtext.xbase.lib.Procedures.Procedure0; @SuppressWarnings("all") public interface Foo extends Procedure0 { + @Override void apply(); } ''') - } + } @Test def void testXFunctionTypeRefAsSuperType_03() { ''' class Foo implements (String)=>void { - override apply(String value) { - } - } '''.assertCompilesTo(''' import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; @SuppressWarnings("all") public class Foo implements Procedure1 { + @Override public void apply(final String value) { } } @@ -5710,34 +5602,31 @@ class XtendCompilerTest extends AbstractXtendCompilerTest { @Test def void testXFunctionTypeRefAsSuperType_04() { ''' interface Foo extends (String)=>void { - - override void apply(String value); - + override void apply(String value) } '''.assertCompilesTo(''' import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; @SuppressWarnings("all") public interface Foo extends Procedure1 { + @Override void apply(final String value); } ''') - } + } @Test def void testXFunctionTypeRefAsSuperType_05() { ''' class Foo implements ((String)=>void)=>void { - override apply((String)=>void procedure) { - } - } '''.assertCompilesTo(''' import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; @SuppressWarnings("all") public class Foo implements Procedure1> { + @Override public void apply(final Procedure1 procedure) { } } @@ -5747,34 +5636,31 @@ class XtendCompilerTest extends AbstractXtendCompilerTest { @Test def void testXFunctionTypeRefAsSuperType_06() { ''' interface Foo extends ((String)=>void)=>void { - - override void apply((String)=>void procedure); - + override void apply((String)=>void procedure) } '''.assertCompilesTo(''' import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; @SuppressWarnings("all") public interface Foo extends Procedure1> { + @Override void apply(final Procedure1 procedure); } ''') - } + } @Test def void testXFunctionTypeRefAsSuperType_07() { ''' class Foo implements ()=>String { - override apply() { - } - } '''.assertCompilesTo(''' import org.eclipse.xtext.xbase.lib.Functions.Function0; @SuppressWarnings("all") public class Foo implements Function0 { + @Override public String apply() { return null; } @@ -5785,28 +5671,24 @@ class XtendCompilerTest extends AbstractXtendCompilerTest { @Test def void testXFunctionTypeRefAsSuperType_08() { ''' interface Foo extends ()=>String { - - override String apply(); - + override String apply() } '''.assertCompilesTo(''' import org.eclipse.xtext.xbase.lib.Functions.Function0; @SuppressWarnings("all") public interface Foo extends Function0 { + @Override String apply(); } ''') - } + } @Test def void testXFunctionTypeRefAsSuperType_09() { ''' class Foo implements ()=>(String)=>void { - override apply() { - } - } '''.assertCompilesTo(''' import org.eclipse.xtext.xbase.lib.Functions.Function0; @@ -5814,6 +5696,7 @@ class XtendCompilerTest extends AbstractXtendCompilerTest { @SuppressWarnings("all") public class Foo implements Function0> { + @Override public Procedure1 apply() { return null; } @@ -5824,9 +5707,7 @@ class XtendCompilerTest extends AbstractXtendCompilerTest { @Test def void testXFunctionTypeRefAsSuperType_10() { ''' interface Foo extends ()=>(String)=>void { - override (String)=>void apply(); - } '''.assertCompilesTo(''' import org.eclipse.xtext.xbase.lib.Functions.Function0; @@ -5834,6 +5715,7 @@ class XtendCompilerTest extends AbstractXtendCompilerTest { @SuppressWarnings("all") public interface Foo extends Function0> { + @Override Procedure1 apply(); } ''') @@ -5976,7 +5858,6 @@ class XtendCompilerTest extends AbstractXtendCompilerTest { @Test // see https://github.com/eclipse/xtext-xtend/issues/942 def testSuppressUnnecessaryModifiersInInterfaces() { - val generatorConfig = generatorConfigProvider.get(null) assertCompilesTo(''' interface FooItf { def void bar () @@ -5988,9 +5869,7 @@ class XtendCompilerTest extends AbstractXtendCompilerTest { @SuppressWarnings("all") public interface FooItf { class FooItfImpl implements FooItf { - «IF generatorConfig.javaSourceVersion.isAtLeast(JavaVersion.JAVA6)» @Override - «ENDIF» public void bar() { } } @@ -5999,52 +5878,346 @@ class XtendCompilerTest extends AbstractXtendCompilerTest { } ''') } + + @Test def void testStaticMethodInInterface() { + ''' + interface Foo { + static def bar() { + "bar!" + } + } + '''.assertCompilesTo(''' + @SuppressWarnings("all") + public interface Foo { + static String bar() { + return "bar!"; + } + } + ''') + } + + @Test def void testJava8UnaryOperator() throws Exception { + ''' + import java.util.List + class Test { + def test(List list) { + list.replaceAll[it + 1] + } + } + '''.assertCompilesTo(''' + import java.util.List; + import java.util.function.UnaryOperator; + + @SuppressWarnings("all") + public class Test { + public void test(final List list) { + final UnaryOperator _function = (Integer it) -> { + return Integer.valueOf(((it).intValue() + 1)); + }; + list.replaceAll(_function); + } + } + ''') + } + + @Test def void testJava8Comparator() throws Exception { + ''' + import java.util.List + class Test { + def test(List list) { + list.sort(java.util.Comparator.comparingInt[String s | s.length] + .thenComparing[String s | s.length]) + } + } + '''.assertCompilesTo(''' + import java.util.Comparator; + import java.util.List; + import java.util.function.Function; + import java.util.function.ToIntFunction; + + @SuppressWarnings("all") + public class Test { + public void test(final List list) { + final ToIntFunction _function = (String s) -> { + return s.length(); + }; + final Function _function_1 = (String s) -> { + return Integer.valueOf(s.length()); + }; + list.sort(Comparator.comparingInt(_function).thenComparing(_function_1)); + } + } + ''') + } + + @Test def void testJava8Predicate() throws Exception { + ''' + import java.util.List + class Test { + def test(List list) { + list.removeIf[it < 2] + } + } + '''.assertCompilesTo(''' + import java.util.List; + import java.util.function.Predicate; + + @SuppressWarnings("all") + public class Test { + public boolean test(final List list) { + final Predicate _function = (Integer it) -> { + return ((it).intValue() < 2); + }; + return list.removeIf(_function); + } + } + ''') + } + + @Test def void testJava8BinaryOperation() throws Exception { + ''' + import java.util.List + class Test { + def test(List list) { + list.stream.reduce[a, b | a && b] + } + } + '''.assertCompilesTo(''' + import java.util.List; + import java.util.Optional; + import java.util.function.BinaryOperator; + + @SuppressWarnings("all") + public class Test { + public Optional test(final List list) { + final BinaryOperator _function = (Boolean a, Boolean b) -> { + return Boolean.valueOf(((a).booleanValue() && (b).booleanValue())); + }; + return list.stream().reduce(_function); + } + } + ''') + } + + @Test def void testJava8Consumer() throws Exception { + ''' + import java.util.List + class Test { + def test(List list) { + list.stream.forEach[println(it)] + } + } + '''.assertCompilesTo(''' + import java.util.List; + import java.util.function.Consumer; + import org.eclipse.xtext.xbase.lib.InputOutput; + + @SuppressWarnings("all") + public class Test { + public void test(final List list) { + final Consumer _function = (String it) -> { + InputOutput.println(it); + }; + list.stream().forEach(_function); + } + } + ''') + } + + @Test def void testJava8BiFunction() throws Exception { + ''' + import java.util.Map + class Test { + def test(Map map) { + map.replaceAll[k, v | v + k.length] + } + } + '''.assertCompilesTo(''' + import java.util.Map; + import java.util.function.BiFunction; + + @SuppressWarnings("all") + public class Test { + public void test(final Map map) { + final BiFunction _function = (String k, Integer v) -> { + int _length = k.length(); + return Integer.valueOf(((v).intValue() + _length)); + }; + map.replaceAll(_function); + } + } + ''') + } + + @Test def void testDefaultMethodSuperCall01() throws Exception { + ''' + class Test implements A { + override void foo() { + A.super.foo + } + } + interface A { + def void foo() {} + } + '''.assertCompilesTo(''' + @SuppressWarnings("all") + public class Test implements A { + @Override + public void foo() { + A.super.foo(); + } + } + ''') + } + + @Test def void testDefaultMethodSuperCall02() throws Exception { + ''' + class Test implements A, B { + override void foo() { + B.super.foo + } + } + interface A { + def void foo() {} + } + interface B { + def void foo() {} + } + '''.assertCompilesTo(''' + @SuppressWarnings("all") + public class Test implements A, B { + @Override + public void foo() { + B.super.foo(); + } + } + ''') + } + + @Test def void testDefaultMethodSuperCall03() throws Exception { + ''' + import test.Consumer + class Test implements Consumer, java.util.function.Consumer { + override void accept(String element) { + java.util.function.Consumer.super.andThen(this).accept('foo') + } + } + '''.assertCompilesTo(''' + import test.Consumer; + + @SuppressWarnings("all") + public class Test implements Consumer, java.util.function.Consumer { + @Override + public void accept(final String element) { + java.util.function.Consumer.super.andThen(this).accept("foo"); + } + } + ''') + } + + @Test def void testDefaultMethodSuperCall04() throws Exception { + ''' + interface Test extends A { + override void foo() { + A.super.foo + } + } + interface A { + def void foo() {} + } + '''.assertCompilesTo(''' + @SuppressWarnings("all") + public interface Test extends A { + @Override + default void foo() { + A.super.foo(); + } + } + ''') + } + + @Test def void testSelfReference() throws Exception { + ''' + class LambdaTest { + def b(A a) { + a.a + } + def test() { + b['hello' + b['world' + self.a]] + } + } + interface A { + def String a() + } + '''.assertCompilesTo(''' + @SuppressWarnings("all") + public class LambdaTest { + public String b(final A a) { + return a.a(); + } + + public String test() { + final A _function = () -> { + final A _function_1 = new A() { + @Override + public String a() { + String _a = this.a(); + return ("world" + _a); + } + }; + String _b = this.b(_function_1); + return ("hello" + _b); + }; + return this.b(_function); + } + } + ''') + } + + @Test def void testVoidMethod_02() throws Exception { + ''' + class A { + def m() { + [ | System::out.println('') ] + } + } + '''.assertCompilesTo(''' + import org.eclipse.xtext.xbase.lib.Procedures.Procedure0; + + @SuppressWarnings("all") + public class A { + public Procedure0 m() { + final Procedure0 _function = () -> { + System.out.println(""); + }; + return _function; + } + } + ''') + } + + @Test def void testVoidMethod_03() throws Exception { + ''' + class A { + def m() { + [ | println('') ] + } + } + '''.assertCompilesTo(''' + import org.eclipse.xtext.xbase.lib.Functions.Function0; + import org.eclipse.xtext.xbase.lib.InputOutput; + + @SuppressWarnings("all") + public class A { + public Function0 m() { + final Function0 _function = () -> { + return InputOutput.println(""); + }; + return _function; + } + } + ''') + } + } -//class XtendCompilerTest extends AbstractXtendCompilerTest { -// -// /* -// * Refined questionable expectation. -// */ -// @Test -// override testRichStringNoAutoConversionToString_03(){ -// assertCompilesTo( -// "class Foo { def test(){ System::out.println('''SomeString''') } }", -// ''' -// import org.eclipse.xtend2.lib.StringConcatenation; -// -// @SuppressWarnings("all") -// public class Foo { -// public void test() { -// StringConcatenation _builder = new StringConcatenation(); -// _builder.append("SomeString"); -// System.out.println(_builder.toString()); -// } -// } -// ''') -// } -// -// /* -// * Refined questionable expectation. -// */ -// @Test -// override testRichStringNoAutoConversionToString_04(){ -// assertCompilesTo( -// "class Foo { def test(){ System::out.println(println('''SomeString''')) } }", -// ''' -// import org.eclipse.xtend2.lib.StringConcatenation; -// import org.eclipse.xtext.xbase.lib.InputOutput; -// -// @SuppressWarnings("all") -// public class Foo { -// public void test() { -// StringConcatenation _builder = new StringConcatenation(); -// _builder.append("SomeString"); -// String _println = InputOutput.println(_builder.toString()); -// System.out.println(_println); -// } -// } -// ''') -// } -// -//} diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/batch/BatchCompilerTest.xtend b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/batch/BatchCompilerTest.xtend index 8933e30d3a7..65c67f0e4de 100644 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/batch/BatchCompilerTest.xtend +++ b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/compiler/batch/BatchCompilerTest.xtend @@ -24,7 +24,6 @@ import org.eclipse.xtext.testing.smoketest.IgnoredBySmokeTest import org.junit.After import org.junit.AfterClass import org.junit.Before -import org.junit.Ignore import org.junit.Test import org.junit.runner.RunWith @@ -327,7 +326,6 @@ class BatchCompilerTest { } @Test - @Ignore def void bug416262() { batchCompiler.sourcePath = BUG416262_SRC_DIRECTORY assertTrue("Compiling funny file pass", batchCompiler.compile) @@ -349,8 +347,11 @@ class BatchCompilerTest { @Test def void testActiveAnnotatons1() { batchCompiler.sourcePath = "./batch-compiler-data/activeAnnotations1" - val logs = LoggingTester.captureLogging(Level.ERROR, XtendBatchCompiler)[ - assertFalse(batchCompiler.compile) + val logs = LoggingTester.captureLogging(Level.ERROR, XtendBatchCompiler) [ + val providerLogs = LoggingTester.captureLogging(Level.ERROR, "org.eclipse.xtend.core.macro.ActiveAnnotationContextProvider")[ + assertFalse(batchCompiler.compile) + ] + providerLogs.assertNumberOfLogEntries(1) ] logs.assertNumberOfLogEntries(1) } @@ -495,34 +496,19 @@ class BatchCompilerTest { } - @Test + @Test(expected = IllegalArgumentException) def void testJavaVersion5() { batchCompiler.javaSourceVersion = "1.5" - batchCompiler.sourcePath = "./batch-compiler-data/javaVersion" - assertTrue(batchCompiler.compile) - val generated = (OUTPUT_DIRECTORY + "/XtendA.java").contents - assertFalse(generated.contains("@Override")) - assertTrue(generated.contains("new Function1")) } - @Test + @Test(expected = IllegalArgumentException) def void testJavaVersion6() { batchCompiler.javaSourceVersion = "1.6" - batchCompiler.sourcePath = "./batch-compiler-data/javaVersion" - assertTrue(batchCompiler.compile) - val generated = (OUTPUT_DIRECTORY + "/XtendA.java").contents - assertTrue(generated.contains("@Override")) - assertTrue(generated.contains("new Function1")) } - @Test + @Test(expected = IllegalArgumentException) def void testJavaVersion7() { batchCompiler.javaSourceVersion = "1.7" - batchCompiler.sourcePath = "./batch-compiler-data/javaVersion" - assertTrue(batchCompiler.compile) - val generated = (OUTPUT_DIRECTORY + "/XtendA.java").contents - assertTrue(generated.contains("@Override")) - assertTrue(generated.contains("new Function1")) } @Test diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/Java8RuntimeInjectorProvider.java b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/Java8RuntimeInjectorProvider.java deleted file mode 100644 index cef2ec57df6..00000000000 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/Java8RuntimeInjectorProvider.java +++ /dev/null @@ -1,41 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2015, 2016 itemis AG (http://www.itemis.eu) and others. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * SPDX-License-Identifier: EPL-2.0 - *******************************************************************************/ -package org.eclipse.xtend.core.tests.java8; - -import org.eclipse.xtend.core.tests.RuntimeInjectorProvider; -import org.eclipse.xtend.core.tests.RuntimeTestSetup; -import org.eclipse.xtext.util.JavaVersion; -import org.eclipse.xtext.xbase.testing.JavaVersionModule; - -import com.google.inject.Guice; -import com.google.inject.Injector; - -/** - * @author Miro Spoenemann - Initial contribution and API - */ -public class Java8RuntimeInjectorProvider extends RuntimeInjectorProvider { - - @Override - protected Injector internalCreateInjector() { - return new RuntimeTestSetup() { - - @Override - public Injector createInjector() { - return Guice.createInjector(new XtendRuntimeTestModule() { - @Override - public ClassLoader bindClassLoaderToInstance() { - return Java8RuntimeInjectorProvider.class.getClassLoader(); - } - }, new JavaVersionModule(JavaVersion.JAVA8)); - } - - }.createInjectorAndDoEMFRegistration(); - } - -} diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/Java8TypeProviderTest.xtend b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/Java8TypeProviderTest.xtend index 1bc8b7dae31..29f6e741bbd 100644 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/Java8TypeProviderTest.xtend +++ b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/Java8TypeProviderTest.xtend @@ -9,24 +9,18 @@ package org.eclipse.xtend.core.tests.java8 import com.google.inject.Inject +import org.eclipse.xtend.core.tests.AbstractXtendTestCase import org.eclipse.xtend.core.xtend.XtendFile import org.eclipse.xtext.common.types.JvmGenericType import org.eclipse.xtext.common.types.JvmOperation import org.eclipse.xtext.common.types.access.IJvmTypeProvider -import org.eclipse.xtext.testing.InjectWith -import org.eclipse.xtext.testing.XtextRunner import org.eclipse.xtext.testing.util.ParseHelper import org.junit.Test -import org.junit.runner.RunWith - -import static org.junit.Assert.* /** * @author koehnlein - Initial contribution and API */ -@RunWith(XtextRunner) -@InjectWith(Java8RuntimeInjectorProvider) -class Java8TypeProviderTest { +class Java8TypeProviderTest extends AbstractXtendTestCase { @Inject IJvmTypeProvider.Factory typeProviderFactory; diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug342021Test.xtend b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug342021Test.xtend deleted file mode 100644 index a98f2f084ef..00000000000 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug342021Test.xtend +++ /dev/null @@ -1,826 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2013, 2018 itemis AG (http://www.itemis.eu) and others. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * SPDX-License-Identifier: EPL-2.0 - *******************************************************************************/ -package org.eclipse.xtend.core.tests.java8.compiler - -import org.eclipse.xtend.core.tests.compiler.AbstractXtendCompilerTest -import org.eclipse.xtend.core.tests.java8.Java8RuntimeInjectorProvider -import org.eclipse.xtext.testing.InjectWith -import org.junit.Test - -/** - * @author Sebastian Zarnekow - Initial contribution and API - * @author Miro Spoenemann - Copied and adapted to Java 8 output - */ -@InjectWith(Java8RuntimeInjectorProvider) -class CompilerBug342021Test extends AbstractXtendCompilerTest { - - @Test def testIfExpression_01() { - ''' - class C { - def Iterable m(String s) { - if (true) - [|newArrayList().iterator] - else - newArrayList(s).toArray - } - } - '''.assertCompilesTo(''' - import org.eclipse.xtext.xbase.lib.CollectionLiterals; - import org.eclipse.xtext.xbase.lib.Conversions; - - @SuppressWarnings("all") - public class C { - public Iterable m(final String s) { - Iterable _xifexpression = null; - if (true) { - final Iterable _function = () -> { - return CollectionLiterals.newArrayList().iterator(); - }; - _xifexpression = _function; - } else { - _xifexpression = (Iterable)Conversions.doWrapArray(CollectionLiterals.newArrayList(s).toArray()); - } - return _xifexpression; - } - } - ''') - } - - @Test def testIfExpression_02() { - ''' - class C { - def Iterable m() { - return if (true) - [|newArrayList().iterator] - else - newArrayList('').toArray - } - } - '''.assertCompilesTo(''' - import org.eclipse.xtext.xbase.lib.CollectionLiterals; - import org.eclipse.xtext.xbase.lib.Conversions; - - @SuppressWarnings("all") - public class C { - public Iterable m() { - Iterable _xifexpression = null; - if (true) { - final Iterable _function = () -> { - return CollectionLiterals.newArrayList().iterator(); - }; - _xifexpression = _function; - } else { - _xifexpression = (Iterable)Conversions.doWrapArray(CollectionLiterals.newArrayList("").toArray()); - } - return _xifexpression; - } - } - ''') - } - - @Test def testIfExpression_03() { - ''' - class C { - def Iterable m() { - if (true) - return [|newArrayList().iterator] - else - return newArrayList('').toArray - } - } - '''.assertCompilesTo(''' - import org.eclipse.xtext.xbase.lib.CollectionLiterals; - import org.eclipse.xtext.xbase.lib.Conversions; - - @SuppressWarnings("all") - public class C { - public Iterable m() { - if (true) { - final Iterable _function = () -> { - return CollectionLiterals.newArrayList().iterator(); - }; - return _function; - } else { - return (Iterable)Conversions.doWrapArray(CollectionLiterals.newArrayList("").toArray()); - } - } - } - ''') - } - - @Test def testIfExpression_04() { - ''' - class C { - def Iterable m() { - if (true) - return [|newArrayList().iterator] - else - newArrayList('').toArray - } - } - '''.assertCompilesTo(''' - import org.eclipse.xtext.xbase.lib.CollectionLiterals; - import org.eclipse.xtext.xbase.lib.Conversions; - - @SuppressWarnings("all") - public class C { - public Iterable m() { - Object[] _xifexpression = null; - if (true) { - final Iterable _function = () -> { - return CollectionLiterals.newArrayList().iterator(); - }; - return _function; - } else { - _xifexpression = CollectionLiterals.newArrayList("").toArray(); - } - return (Iterable)Conversions.doWrapArray(_xifexpression); - } - } - ''') - } - - @Test def testIfExpression_05() { - ''' - class C { - def Iterable m() { - if (true) - [|newArrayList().iterator] - else - return newArrayList('').toArray - } - } - '''.assertCompilesTo(''' - import org.eclipse.xtext.xbase.lib.CollectionLiterals; - import org.eclipse.xtext.xbase.lib.Conversions; - - @SuppressWarnings("all") - public class C { - public Iterable m() { - Iterable _xifexpression = null; - if (true) { - final Iterable _function = () -> { - return CollectionLiterals.newArrayList().iterator(); - }; - _xifexpression = _function; - } else { - return (Iterable)Conversions.doWrapArray(CollectionLiterals.newArrayList("").toArray()); - } - return _xifexpression; - } - } - ''') - } - - @Test def testIfExpression_06() { - ''' - class C { - def Iterable m(String s) { - if (true) - { [| { newArrayList().iterator } ] } - else - { { newArrayList(s).toArray } } - } - } - '''.assertCompilesTo(''' - import org.eclipse.xtext.xbase.lib.CollectionLiterals; - import org.eclipse.xtext.xbase.lib.Conversions; - - @SuppressWarnings("all") - public class C { - public Iterable m(final String s) { - Iterable _xifexpression = null; - if (true) { - final Iterable _function = () -> { - return CollectionLiterals.newArrayList().iterator(); - }; - _xifexpression = _function; - } else { - _xifexpression = (Iterable)Conversions.doWrapArray(CollectionLiterals.newArrayList(s).toArray()); - } - return _xifexpression; - } - } - ''') - } - - @Test def testIfExpression_07() { - ''' - class C { - def Iterable m() { - return { - if (true) - { [|newArrayList().iterator] } - else - { newArrayList('').toArray } - } - } - } - '''.assertCompilesTo(''' - import org.eclipse.xtext.xbase.lib.CollectionLiterals; - import org.eclipse.xtext.xbase.lib.Conversions; - - @SuppressWarnings("all") - public class C { - public Iterable m() { - Iterable _xifexpression = null; - if (true) { - final Iterable _function = () -> { - return CollectionLiterals.newArrayList().iterator(); - }; - _xifexpression = _function; - } else { - _xifexpression = (Iterable)Conversions.doWrapArray(CollectionLiterals.newArrayList("").toArray()); - } - return _xifexpression; - } - } - ''') - } - - @Test def testIfExpression_08() { - ''' - class C { - def Iterable m() { - { - if (true) - { return { [|newArrayList().iterator] } } - else - { return { { newArrayList('') } .toArray } } - } - } - } - '''.assertCompilesTo(''' - import org.eclipse.xtext.xbase.lib.CollectionLiterals; - import org.eclipse.xtext.xbase.lib.Conversions; - - @SuppressWarnings("all") - public class C { - public Iterable m() { - if (true) { - final Iterable _function = () -> { - return CollectionLiterals.newArrayList().iterator(); - }; - return _function; - } else { - return (Iterable)Conversions.doWrapArray(CollectionLiterals.newArrayList("").toArray()); - } - } - } - ''') - } - - @Test def testIfExpression_09() { - ''' - class C { - def Iterable m() { - if (true) - { return { [|newArrayList().iterator] } } - else - { newArrayList('').toArray } - } - } - '''.assertCompilesTo(''' - import org.eclipse.xtext.xbase.lib.CollectionLiterals; - import org.eclipse.xtext.xbase.lib.Conversions; - - @SuppressWarnings("all") - public class C { - public Iterable m() { - Object[] _xifexpression = null; - if (true) { - final Iterable _function = () -> { - return CollectionLiterals.newArrayList().iterator(); - }; - return _function; - } else { - _xifexpression = CollectionLiterals.newArrayList("").toArray(); - } - return (Iterable)Conversions.doWrapArray(_xifexpression); - } - } - ''') - } - - @Test def testIfExpression_10() { - ''' - class C { - def Iterable m() { - if (true) - { [|newArrayList().iterator] } - else - { return newArrayList('').toArray } - } - } - '''.assertCompilesTo(''' - import org.eclipse.xtext.xbase.lib.CollectionLiterals; - import org.eclipse.xtext.xbase.lib.Conversions; - - @SuppressWarnings("all") - public class C { - public Iterable m() { - Iterable _xifexpression = null; - if (true) { - final Iterable _function = () -> { - return CollectionLiterals.newArrayList().iterator(); - }; - _xifexpression = _function; - } else { - return (Iterable)Conversions.doWrapArray(CollectionLiterals.newArrayList("").toArray()); - } - return _xifexpression; - } - } - ''') - } - - @Test def testIfExpression_11() { - ''' - class C { - def Iterable m(String s) { - toString - if (true) { - toString; - [|newArrayList().iterator] - } else { - toString - newArrayList(s).toArray - } - } - } - '''.assertCompilesTo(''' - import org.eclipse.xtext.xbase.lib.CollectionLiterals; - import org.eclipse.xtext.xbase.lib.Conversions; - - @SuppressWarnings("all") - public class C { - public Iterable m(final String s) { - Iterable _xblockexpression = null; - { - this.toString(); - Iterable _xifexpression = null; - if (true) { - Iterable _xblockexpression_1 = null; - { - this.toString(); - final Iterable _function = () -> { - return CollectionLiterals.newArrayList().iterator(); - }; - _xblockexpression_1 = _function; - } - _xifexpression = _xblockexpression_1; - } else { - Object[] _xblockexpression_2 = null; - { - this.toString(); - _xblockexpression_2 = CollectionLiterals.newArrayList(s).toArray(); - } - _xifexpression = (Iterable)Conversions.doWrapArray(_xblockexpression_2); - } - _xblockexpression = _xifexpression; - } - return _xblockexpression; - } - } - ''') - } - - @Test def testIfExpression_12() { - ''' - class C { - def Iterable m() { - toString - return { - toString - if (true) { - toString; - [|newArrayList().iterator] - } else { - toString - newArrayList('').toArray - } - } - } - } - '''.assertCompilesTo(''' - import org.eclipse.xtext.xbase.lib.CollectionLiterals; - import org.eclipse.xtext.xbase.lib.Conversions; - - @SuppressWarnings("all") - public class C { - public Iterable m() { - this.toString(); - Iterable _xblockexpression = null; - { - this.toString(); - Iterable _xifexpression = null; - if (true) { - Iterable _xblockexpression_1 = null; - { - this.toString(); - final Iterable _function = () -> { - return CollectionLiterals.newArrayList().iterator(); - }; - _xblockexpression_1 = _function; - } - _xifexpression = _xblockexpression_1; - } else { - Object[] _xblockexpression_2 = null; - { - this.toString(); - _xblockexpression_2 = CollectionLiterals.newArrayList("").toArray(); - } - _xifexpression = (Iterable)Conversions.doWrapArray(_xblockexpression_2); - } - _xblockexpression = _xifexpression; - } - return _xblockexpression; - } - } - ''') - } - - @Test def testIfExpression_13() { - ''' - class C { - def Iterable m() { - toString - if (true) { - toString - return [|newArrayList().iterator] - } else { - toString - return newArrayList('').toArray - } - } - } - '''.assertCompilesTo(''' - import org.eclipse.xtext.xbase.lib.CollectionLiterals; - import org.eclipse.xtext.xbase.lib.Conversions; - - @SuppressWarnings("all") - public class C { - public Iterable m() { - this.toString(); - if (true) { - this.toString(); - final Iterable _function = () -> { - return CollectionLiterals.newArrayList().iterator(); - }; - return _function; - } else { - this.toString(); - return (Iterable)Conversions.doWrapArray(CollectionLiterals.newArrayList("").toArray()); - } - } - } - ''') - } - - @Test def testIfExpression_14() { - ''' - class C { - def Iterable m() { - toString - if (true) { - toString - return [|newArrayList().iterator] - } else { - toString - newArrayList('').toArray - } - } - } - '''.assertCompilesTo(''' - import org.eclipse.xtext.xbase.lib.CollectionLiterals; - import org.eclipse.xtext.xbase.lib.Conversions; - - @SuppressWarnings("all") - public class C { - public Iterable m() { - Object[] _xblockexpression = null; - { - this.toString(); - Object[] _xifexpression = null; - if (true) { - this.toString(); - final Iterable _function = () -> { - return CollectionLiterals.newArrayList().iterator(); - }; - return _function; - } else { - Object[] _xblockexpression_1 = null; - { - this.toString(); - _xblockexpression_1 = CollectionLiterals.newArrayList("").toArray(); - } - _xifexpression = _xblockexpression_1; - } - _xblockexpression = _xifexpression; - } - return (Iterable)Conversions.doWrapArray(_xblockexpression); - } - } - ''') - } - - @Test def testIfExpression_15() { - ''' - class C { - def Iterable m() { - { - toString - } - if (true) { - { - toString - } - [|newArrayList().iterator] - } else { - { - toString - } - return newArrayList('').toArray - } - } - } - '''.assertCompilesTo(''' - import org.eclipse.xtext.xbase.lib.CollectionLiterals; - import org.eclipse.xtext.xbase.lib.Conversions; - - @SuppressWarnings("all") - public class C { - public Iterable m() { - Iterable _xblockexpression = null; - { - this.toString(); - Iterable _xifexpression = null; - if (true) { - Iterable _xblockexpression_1 = null; - { - this.toString(); - final Iterable _function = () -> { - return CollectionLiterals.newArrayList().iterator(); - }; - _xblockexpression_1 = _function; - } - _xifexpression = _xblockexpression_1; - } else { - this.toString(); - return (Iterable)Conversions.doWrapArray(CollectionLiterals.newArrayList("").toArray()); - } - _xblockexpression = _xifexpression; - } - return _xblockexpression; - } - } - ''') - } - - @Test def testSwitchExpression_01() { - ''' - class C { - def Iterable m(Object o) { - switch o { - Boolean: [|newArrayList().iterator] - default: newArrayList('').toArray - } - } - } - '''.assertCompilesTo(''' - import org.eclipse.xtext.xbase.lib.CollectionLiterals; - import org.eclipse.xtext.xbase.lib.Conversions; - - @SuppressWarnings("all") - public class C { - public Iterable m(final Object o) { - Iterable _switchResult = null; - boolean _matched = false; - if (o instanceof Boolean) { - _matched=true; - final Iterable _function = () -> { - return CollectionLiterals.newArrayList().iterator(); - }; - _switchResult = _function; - } - if (!_matched) { - _switchResult = (Iterable)Conversions.doWrapArray(CollectionLiterals.newArrayList("").toArray()); - } - return _switchResult; - } - } - ''') - } - - @Test def testSwitchExpression_02() { - ''' - class C { - def Iterable m(Object o) { - switch o { - Boolean: [|newArrayList().iterator] - String: return newArrayList('').toArray - } - } - } - '''.assertCompilesTo(''' - import org.eclipse.xtext.xbase.lib.CollectionLiterals; - import org.eclipse.xtext.xbase.lib.Conversions; - - @SuppressWarnings("all") - public class C { - public Iterable m(final Object o) { - Iterable _switchResult = null; - boolean _matched = false; - if (o instanceof Boolean) { - _matched=true; - final Iterable _function = () -> { - return CollectionLiterals.newArrayList().iterator(); - }; - _switchResult = _function; - } - if (!_matched) { - if (o instanceof String) { - _matched=true; - return (Iterable)Conversions.doWrapArray(CollectionLiterals.newArrayList("").toArray()); - } - } - return _switchResult; - } - } - ''') - } - - @Test def testSwitchExpression_03() { - ''' - class C { - def Iterable m(Object o) { - return switch o { - Boolean: [|newArrayList().iterator] - String: newArrayList('').toArray - default: null - } - } - } - '''.assertCompilesTo(''' - import org.eclipse.xtext.xbase.lib.CollectionLiterals; - import org.eclipse.xtext.xbase.lib.Conversions; - - @SuppressWarnings("all") - public class C { - public Iterable m(final Object o) { - Iterable _switchResult = null; - boolean _matched = false; - if (o instanceof Boolean) { - _matched=true; - final Iterable _function = () -> { - return CollectionLiterals.newArrayList().iterator(); - }; - _switchResult = _function; - } - if (!_matched) { - if (o instanceof String) { - _matched=true; - _switchResult = (Iterable)Conversions.doWrapArray(CollectionLiterals.newArrayList("").toArray()); - } - } - if (!_matched) { - _switchResult = null; - } - return _switchResult; - } - } - ''') - } - - @Test def testSwitchExpression_04() { - ''' - class C { - def Iterable m(Object o) { - return switch o { - Boolean: return [|newArrayList().iterator] - String: newArrayList('').toArray - default: emptyList - } - } - } - '''.assertCompilesTo(''' - import org.eclipse.xtext.xbase.lib.CollectionLiterals; - import org.eclipse.xtext.xbase.lib.Conversions; - - @SuppressWarnings("all") - public class C { - public Iterable m(final Object o) { - Iterable _switchResult = null; - boolean _matched = false; - if (o instanceof Boolean) { - _matched=true; - final Iterable _function = () -> { - return CollectionLiterals.newArrayList().iterator(); - }; - return _function; - } - if (!_matched) { - if (o instanceof String) { - _matched=true; - _switchResult = (Iterable)Conversions.doWrapArray(CollectionLiterals.newArrayList("").toArray()); - } - } - if (!_matched) { - _switchResult = CollectionLiterals.emptyList(); - } - return _switchResult; - } - } - ''') - } - - @Test def testTryCatchExpression_01() { - ''' - class C { - def Iterable m(Object o) { - try { - [|newArrayList().iterator] - } catch(Exception e) { - newArrayList('').toArray - } - } - } - '''.assertCompilesTo(''' - import org.eclipse.xtext.xbase.lib.CollectionLiterals; - import org.eclipse.xtext.xbase.lib.Conversions; - import org.eclipse.xtext.xbase.lib.Exceptions; - - @SuppressWarnings("all") - public class C { - public Iterable m(final Object o) { - Iterable _xtrycatchfinallyexpression = null; - try { - final Iterable _function = () -> { - return CollectionLiterals.newArrayList().iterator(); - }; - _xtrycatchfinallyexpression = _function; - } catch (final Throwable _t) { - if (_t instanceof Exception) { - _xtrycatchfinallyexpression = (Iterable)Conversions.doWrapArray(CollectionLiterals.newArrayList("").toArray()); - } else { - throw Exceptions.sneakyThrow(_t); - } - } - return _xtrycatchfinallyexpression; - } - } - ''') - } - - @Test def testNestedIfInSwitchExpression_01() { - ''' - class C { - def Iterable m(Object o, boolean b) { - switch o { - Boolean: [|newArrayList().iterator] - default: { - if (b) - return newArrayList('').toArray - else - return #{} - } - } - } - } - '''.assertCompilesTo(''' - import java.util.Collections; - import org.eclipse.xtext.xbase.lib.CollectionLiterals; - import org.eclipse.xtext.xbase.lib.Conversions; - - @SuppressWarnings("all") - public class C { - public Iterable m(final Object o, final boolean b) { - Iterable _switchResult = null; - boolean _matched = false; - if (o instanceof Boolean) { - _matched=true; - final Iterable _function = () -> { - return CollectionLiterals.newArrayList().iterator(); - }; - _switchResult = _function; - } - if (!_matched) { - if (b) { - return (Iterable)Conversions.doWrapArray(CollectionLiterals.newArrayList("").toArray()); - } else { - return Collections.unmodifiableSet(CollectionLiterals.newHashSet()); - } - } - return _switchResult; - } - } - ''') - } - -} \ No newline at end of file diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug383534Test.xtend b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug383534Test.xtend deleted file mode 100644 index 33e0a5d6a35..00000000000 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug383534Test.xtend +++ /dev/null @@ -1,178 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2014, 2016 itemis AG (http://www.itemis.eu) and others. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * SPDX-License-Identifier: EPL-2.0 - *******************************************************************************/ -package org.eclipse.xtend.core.tests.java8.compiler - -import org.eclipse.xtend.core.tests.compiler.AbstractXtendCompilerTest -import org.eclipse.xtend.core.tests.java8.Java8RuntimeInjectorProvider -import org.eclipse.xtext.testing.InjectWith -import org.junit.Test - -/** - * @author Sebastian Zarnekow - Initial contribution and API - * @author Miro Spoenemann - Copied and adapted to Java 8 output - */ -@InjectWith(Java8RuntimeInjectorProvider) -class CompilerBug383534Test extends AbstractXtendCompilerTest { - - @Test def test_01() { - ''' - class C { - def void m() { - val (String,String)=>String strAdd = [s1,s2 | s1+s2] - val /*(String)=>String*/ curriedStrAdd = strAdd.curry('x') // ok - - println(strAdd.apply('x', 'y')) // result: 'xy' - println(curriedStrAdd.apply('y')) // result: 'xy' - - val (String,String[])=>String strAdd2 = [s1,s2 | s1 + s2.reduce[x1,x2 | x1+x2]] - val /*(String)=>String*/ curriedStrAdd2 = strAdd2.curry('x') // fail - - println(strAdd2.apply('x', newArrayList('y', 'z'))) // result: 'xyz' - println(curriedStrAdd2.apply(newArrayList('y', 'z'))) // should result in 'xyz' - } - } - '''.assertCompilesTo(''' - import org.eclipse.xtext.xbase.lib.CollectionLiterals; - import org.eclipse.xtext.xbase.lib.Conversions; - import org.eclipse.xtext.xbase.lib.FunctionExtensions; - import org.eclipse.xtext.xbase.lib.Functions.Function1; - import org.eclipse.xtext.xbase.lib.Functions.Function2; - import org.eclipse.xtext.xbase.lib.InputOutput; - import org.eclipse.xtext.xbase.lib.IterableExtensions; - - @SuppressWarnings("all") - public class C { - public void m() { - final Function2 _function = (String s1, String s2) -> { - return (s1 + s2); - }; - final Function2 strAdd = _function; - final Function1 curriedStrAdd = FunctionExtensions.curry(strAdd, "x"); - InputOutput.println(strAdd.apply("x", "y")); - InputOutput.println(curriedStrAdd.apply("y")); - final Function2 _function_1 = (String s1, String[] s2) -> { - final Function2 _function_2 = (String x1, String x2) -> { - return (x1 + x2); - }; - String _reduce = IterableExtensions.reduce(((Iterable)Conversions.doWrapArray(s2)), _function_2); - return (s1 + _reduce); - }; - final Function2 strAdd2 = _function_1; - final Function1 curriedStrAdd2 = FunctionExtensions.curry(strAdd2, "x"); - InputOutput.println(strAdd2.apply("x", ((String[])Conversions.unwrapArray(CollectionLiterals.newArrayList("y", "z"), String.class)))); - InputOutput.println(curriedStrAdd2.apply(((String[])Conversions.unwrapArray(CollectionLiterals.newArrayList("y", "z"), String.class)))); - } - } - ''') - } - - @Test def test_02() { - ''' - class C { - def void m() { - val (String,String)=>String strAdd = [s1,s2 | s1+s2] - val curriedStrAdd = strAdd.curry('x') - println(strAdd.apply('x', 'y')) // result: 'xy' - println(curriedStrAdd.apply('y')) // result: 'xy' - } - } - '''.assertCompilesTo(''' - import org.eclipse.xtext.xbase.lib.FunctionExtensions; - import org.eclipse.xtext.xbase.lib.Functions.Function1; - import org.eclipse.xtext.xbase.lib.Functions.Function2; - import org.eclipse.xtext.xbase.lib.InputOutput; - - @SuppressWarnings("all") - public class C { - public void m() { - final Function2 _function = (String s1, String s2) -> { - return (s1 + s2); - }; - final Function2 strAdd = _function; - final Function1 curriedStrAdd = FunctionExtensions.curry(strAdd, "x"); - InputOutput.println(strAdd.apply("x", "y")); - InputOutput.println(curriedStrAdd.apply("y")); - } - } - ''') - } - - @Test def test_03() { - ''' - class C { - def void m() { - val (String,String[])=>String strAdd = [s1,s2 | s1+s2.head] - val curriedStrAdd = strAdd.curry('x') - println(strAdd.apply('x', newArrayList('y', 'z'))) - println(curriedStrAdd.apply(newArrayList('y', 'z'))) - } - } - '''.assertCompilesTo(''' - import org.eclipse.xtext.xbase.lib.CollectionLiterals; - import org.eclipse.xtext.xbase.lib.Conversions; - import org.eclipse.xtext.xbase.lib.FunctionExtensions; - import org.eclipse.xtext.xbase.lib.Functions.Function1; - import org.eclipse.xtext.xbase.lib.Functions.Function2; - import org.eclipse.xtext.xbase.lib.InputOutput; - import org.eclipse.xtext.xbase.lib.IterableExtensions; - - @SuppressWarnings("all") - public class C { - public void m() { - final Function2 _function = (String s1, String[] s2) -> { - String _head = IterableExtensions.head(((Iterable)Conversions.doWrapArray(s2))); - return (s1 + _head); - }; - final Function2 strAdd = _function; - final Function1 curriedStrAdd = FunctionExtensions.curry(strAdd, "x"); - InputOutput.println(strAdd.apply("x", ((String[])Conversions.unwrapArray(CollectionLiterals.newArrayList("y", "z"), String.class)))); - InputOutput.println(curriedStrAdd.apply(((String[])Conversions.unwrapArray(CollectionLiterals.newArrayList("y", "z"), String.class)))); - } - } - ''') - } - - @Test def test_04() { - ''' - class C { - def void m() { - val (String,String[])=>String strAdd = [s1,s2 | s1+s2.reduce[x1,x2 | x1+x2]] - val curriedStrAdd = strAdd.curry('x') - println(strAdd.apply('x', #['y'])) // result: 'xy' - println(curriedStrAdd.apply(#['y'])) // result: 'xy' - } - } - '''.assertCompilesTo(''' - import org.eclipse.xtext.xbase.lib.Conversions; - import org.eclipse.xtext.xbase.lib.FunctionExtensions; - import org.eclipse.xtext.xbase.lib.Functions.Function1; - import org.eclipse.xtext.xbase.lib.Functions.Function2; - import org.eclipse.xtext.xbase.lib.InputOutput; - import org.eclipse.xtext.xbase.lib.IterableExtensions; - - @SuppressWarnings("all") - public class C { - public void m() { - final Function2 _function = (String s1, String[] s2) -> { - final Function2 _function_1 = (String x1, String x2) -> { - return (x1 + x2); - }; - String _reduce = IterableExtensions.reduce(((Iterable)Conversions.doWrapArray(s2)), _function_1); - return (s1 + _reduce); - }; - final Function2 strAdd = _function; - final Function1 curriedStrAdd = FunctionExtensions.curry(strAdd, "x"); - InputOutput.println(strAdd.apply("x", new String[] { "y" })); - InputOutput.println(curriedStrAdd.apply(new String[] { "y" })); - } - } - ''') - } - -} \ No newline at end of file diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug404051Test.xtend b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug404051Test.xtend deleted file mode 100644 index 67632e02677..00000000000 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug404051Test.xtend +++ /dev/null @@ -1,234 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2013, 2016 itemis AG (http://www.itemis.eu) and others. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * SPDX-License-Identifier: EPL-2.0 - *******************************************************************************/ -package org.eclipse.xtend.core.tests.java8.compiler - -import org.eclipse.xtend.core.tests.compiler.AbstractXtendCompilerTest -import org.eclipse.xtend.core.tests.compiler.CompilerBugTest -import org.eclipse.xtend.core.tests.java8.Java8RuntimeInjectorProvider -import org.eclipse.xtext.testing.InjectWith -import org.junit.Test - -/** - * @author Sebastian Zarnekow - Initial contribution and API - * @author Miro Spoenemann - Copied and adapted to Java 8 output - * @see CompilerBugTest#testBug404051_01 and friends - */ -@InjectWith(Java8RuntimeInjectorProvider) -class CompilerBug404051Test extends AbstractXtendCompilerTest { - - @Test def test_01() { - ''' - class C { - def m(Iterable iterable) { - iterable.flatMap[].sortBy [ hashCode ] - } - def Iterable flatMap(Iterable iterable, (A)=>B map) { - return null - } - } - '''.assertCompilesTo(''' - import java.util.List; - import org.eclipse.xtext.xbase.lib.Functions.Function1; - import org.eclipse.xtext.xbase.lib.IterableExtensions; - - @SuppressWarnings("all") - public class C { - public List m(final Iterable iterable) { - final Function1 _function = (String it) -> { - return null; - }; - final Function1 _function_1 = (Object it) -> { - return Integer.valueOf(it.hashCode()); - }; - return IterableExtensions.sortBy(this.flatMap(iterable, _function), _function_1); - } - - public Iterable flatMap(final Iterable iterable, final Function1 map) { - return null; - } - } - ''') - } - - @Test def test_02() { - ''' - class C { - def m(Iterable iterable) { - iterable.flatMap[].sortBy [ hashCode ] - } - def Iterable flatMap(Iterable iterable, (A)=>B map) { - return null - } - } - '''.assertCompilesTo(''' - import java.util.List; - import org.eclipse.xtext.xbase.lib.Functions.Function1; - import org.eclipse.xtext.xbase.lib.IterableExtensions; - - @SuppressWarnings("all") - public class C { - public List m(final Iterable iterable) { - final Function1 _function = (String it) -> { - return null; - }; - final Function1 _function_1 = (Object it) -> { - return Integer.valueOf(it.hashCode()); - }; - return IterableExtensions.sortBy(this.flatMap(iterable, _function), _function_1); - } - - public Iterable flatMap(final Iterable iterable, final Function1 map) { - return null; - } - } - ''') - } - - @Test def test_03() { - ''' - class C { - def m(Iterable iterable) { - iterable.flatMap[].sortBy [ intValue ] - } - def Iterable flatMap(Iterable iterable, (A)=>B map) { - return null - } - } - '''.assertCompilesTo(''' - import java.util.List; - import org.eclipse.xtext.xbase.lib.Functions.Function1; - import org.eclipse.xtext.xbase.lib.IterableExtensions; - - @SuppressWarnings("all") - public class C { - public List m(final Iterable iterable) { - final Function1 _function = (String it) -> { - return null; - }; - final Function1 _function_1 = (Number it) -> { - return Integer.valueOf(it.intValue()); - }; - return IterableExtensions.sortBy(this.flatMap(iterable, _function), _function_1); - } - - public Iterable flatMap(final Iterable iterable, final Function1 map) { - return null; - } - } - ''') - } - - @Test def test_04() { - ''' - class C { - def m() { - #[].flatMap[ length ].sortBy [ intValue ] - } - def Iterable flatMap(Iterable iterable, (A)=>B map) { - return null - } - } - '''.assertCompilesTo(''' - import java.util.Collections; - import java.util.List; - import org.eclipse.xtext.xbase.lib.CollectionLiterals; - import org.eclipse.xtext.xbase.lib.Functions.Function1; - import org.eclipse.xtext.xbase.lib.IterableExtensions; - - @SuppressWarnings("all") - public class C { - public List m() { - final Function1 _function = (String it) -> { - return Integer.valueOf(it.length()); - }; - final Function1 _function_1 = (Integer it) -> { - return Integer.valueOf(it.intValue()); - }; - return IterableExtensions.sortBy(this.flatMap(Collections.unmodifiableList(CollectionLiterals.newArrayList()), _function), _function_1); - } - - public Iterable flatMap(final Iterable iterable, final Function1 map) { - return null; - } - } - ''') - } - - @Test def test_05() { - ''' - class C { - def m() { - #[].flatMap[].sortBy [ intValue ] - } - def Iterable flatMap(Iterable iterable, (A)=>B map) { - return null - } - } - '''.assertCompilesTo(''' - import java.util.Collections; - import java.util.List; - import org.eclipse.xtext.xbase.lib.CollectionLiterals; - import org.eclipse.xtext.xbase.lib.Functions.Function1; - import org.eclipse.xtext.xbase.lib.IterableExtensions; - - @SuppressWarnings("all") - public class C { - public List m() { - final Function1 _function = (String it) -> { - return null; - }; - final Function1 _function_1 = (Number it) -> { - return Integer.valueOf(it.intValue()); - }; - return IterableExtensions.sortBy(this.flatMap(Collections.unmodifiableList(CollectionLiterals.newArrayList()), _function), _function_1); - } - - public Iterable flatMap(final Iterable iterable, final Function1 map) { - return null; - } - } - ''') - } - - @Test def test_06() { - ''' - class C { - def m(Iterable iterable) { - iterable.flatMap[].sortBy [ length ] - } - def Iterable flatMap(Iterable iterable, (A)=>B map) { - return null - } - } - '''.assertCompilesTo(''' - import java.util.List; - import org.eclipse.xtext.xbase.lib.Functions.Function1; - import org.eclipse.xtext.xbase.lib.IterableExtensions; - - @SuppressWarnings("all") - public class C { - public List m(final Iterable iterable) { - final Function1 _function = (String it) -> { - return null; - }; - final Function1 _function_1 = (String it) -> { - return Integer.valueOf(it.length()); - }; - return IterableExtensions.sortBy(this.flatMap(iterable, _function), _function_1); - } - - public Iterable flatMap(final Iterable iterable, final Function1 map) { - return null; - } - } - ''') - } - - -} \ No newline at end of file diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug405825Test.xtend b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug405825Test.xtend deleted file mode 100644 index 371093f777d..00000000000 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug405825Test.xtend +++ /dev/null @@ -1,108 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2013, 2016 itemis AG (http://www.itemis.eu) and others. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * SPDX-License-Identifier: EPL-2.0 - *******************************************************************************/ -package org.eclipse.xtend.core.tests.java8.compiler - -import org.eclipse.xtend.core.tests.compiler.AbstractXtendCompilerTest -import org.eclipse.xtend.core.tests.java8.Java8RuntimeInjectorProvider -import org.eclipse.xtext.testing.InjectWith -import org.junit.Test - -/** - * @author Sebastian Zarnekow - Initial contribution and API - * @author Miro Spoenemann - Copied and adapted to Java 8 output - */ -@InjectWith(Java8RuntimeInjectorProvider) -class CompilerBug405825Test extends AbstractXtendCompilerTest { - - @Test def testBug405825_01() { - ''' - class Test { - def static void test(Bound b) { - } - def static void main() { - test [ - ] - } - } - interface Bound { - def void method(T t); - } - '''.assertCompilesTo(''' - @SuppressWarnings("all") - public class Test { - public static void test(final Bound b) { - } - - public static void main() { - final Bound _function = (Number it) -> { - }; - Test.test(_function); - } - } - ''') - } - - @Test def testBug405825_02() { - ''' - class Test { - def static void test(Bound b) { - } - def static void main() { - test [ - ] - } - } - interface Bound { - def void method(T t); - } - '''.assertCompilesTo(''' - @SuppressWarnings("all") - public class Test { - public static void test(final Bound b) { - } - - public static void main() { - final Bound _function = (Integer it) -> { - }; - Test.test(_function); - } - } - ''') - } - - @Test def testBug405825_03() { - ''' - class Test { - def static void test(Sub b) { - } - def static void main() { - test [ - ] - } - } - interface Bound { - def void method(T t); - } - interface Sub extends Bound {} - '''.assertCompilesTo(''' - @SuppressWarnings("all") - public class Test { - public static void test(final Sub b) { - } - - public static void main() { - final Sub _function = (Number it) -> { - }; - Test.test(_function); - } - } - ''') - } - -} diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug406425Test.xtend b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug406425Test.xtend deleted file mode 100644 index 2f978540627..00000000000 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug406425Test.xtend +++ /dev/null @@ -1,458 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2013, 2016 itemis AG (http://www.itemis.eu) and others. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * SPDX-License-Identifier: EPL-2.0 - *******************************************************************************/ -package org.eclipse.xtend.core.tests.java8.compiler - -import org.eclipse.xtend.core.tests.java8.Java8RuntimeInjectorProvider -import org.eclipse.xtext.testing.InjectWith -import org.junit.Test - -/** - * @author Sebastian Zarnekow - Initial contribution and API - * @author Miro Spoenemann - Copied and adapted to Java 8 output - */ -@InjectWith(Java8RuntimeInjectorProvider) -class CompilerBug406425Test extends org.eclipse.xtend.core.tests.compiler.CompilerBug406425Test { - - @Test override testBug406425_01() { - ''' - import static org.hamcrest.core.Is.* - import static org.junit.Assert.* - import org.hamcrest.Matcher - class Test { - def test() { - new MyEntity => [ - assertThat(it, nullValue) - assertThat(it.name, is("")) - ] - } - def static Matcher nullValue() {} - } - class MyEntity { - @Property String name - } - '''.assertCompilesTo(''' - import org.eclipse.xtext.xbase.lib.ObjectExtensions; - import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; - import org.hamcrest.Matcher; - import org.hamcrest.core.Is; - import org.junit.Assert; - - @SuppressWarnings("all") - public class Test { - public MyEntity test() { - MyEntity _myEntity = new MyEntity(); - final Procedure1 _function = (MyEntity it) -> { - Assert.assertThat(it, Test.nullValue()); - Assert.assertThat(it.getName(), Is.is("")); - }; - return ObjectExtensions.operator_doubleArrow(_myEntity, _function); - } - - public static Matcher nullValue() { - return null; - } - } - ''') - } - - @Test override testBug406425_02() { - ''' - import org.eclipse.xtend.core.tests.java8.compiler.StringBuilderLike - class Test { - def m(T a, T b){} - - static def m() { - new StringBuilderLike => [ - new Test().m(it, new Long(0)) - println(length) - ] - } - } - '''.assertCompilesTo(''' - import java.io.Serializable; - import org.eclipse.xtend.core.tests.java8.compiler.StringBuilderLike; - import org.eclipse.xtext.xbase.lib.InputOutput; - import org.eclipse.xtext.xbase.lib.ObjectExtensions; - import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; - - @SuppressWarnings("all") - public class Test { - public Object m(final T a, final T b) { - return null; - } - - public static StringBuilderLike m() { - StringBuilderLike _stringBuilderLike = new StringBuilderLike(); - final Procedure1 _function = (StringBuilderLike it) -> { - Test _test = new Test(); - Long _long = new Long(0); - _test.m(it, _long); - InputOutput.println(Integer.valueOf(it.length())); - }; - return ObjectExtensions.operator_doubleArrow(_stringBuilderLike, _function); - } - } - ''') - } - - @Test override testBug406425_03() { - ''' - import org.eclipse.xtend.core.tests.java8.compiler.StringBuilderLike - class Test { - def m(T a, T b){} - - def m() { - new StringBuilderLike => [ - m(it, new Long(0)) - println(length) - ] - } - } - '''.assertCompilesTo(''' - import java.io.Serializable; - import org.eclipse.xtend.core.tests.java8.compiler.StringBuilderLike; - import org.eclipse.xtext.xbase.lib.InputOutput; - import org.eclipse.xtext.xbase.lib.ObjectExtensions; - import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; - - @SuppressWarnings("all") - public class Test { - public Object m(final T a, final T b) { - return null; - } - - public StringBuilderLike m() { - StringBuilderLike _stringBuilderLike = new StringBuilderLike(); - final Procedure1 _function = (StringBuilderLike it) -> { - Long _long = new Long(0); - this.m(it, _long); - InputOutput.println(Integer.valueOf(it.length())); - }; - return ObjectExtensions.operator_doubleArrow(_stringBuilderLike, _function); - } - } - ''') - } - - @Test override testBug406425_04() { - ''' - import org.eclipse.xtend.core.tests.java8.compiler.StringBuilderLike - class Test { - def m(T a, T b){} - - def m() { - new StringBuilderLike => [ - it.m(new Long(0)) - println(length) - ] - } - } - '''.assertCompilesTo(''' - import java.io.Serializable; - import org.eclipse.xtend.core.tests.java8.compiler.StringBuilderLike; - import org.eclipse.xtext.xbase.lib.InputOutput; - import org.eclipse.xtext.xbase.lib.ObjectExtensions; - import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; - - @SuppressWarnings("all") - public class Test { - public Object m(final T a, final T b) { - return null; - } - - public StringBuilderLike m() { - StringBuilderLike _stringBuilderLike = new StringBuilderLike(); - final Procedure1 _function = (StringBuilderLike it) -> { - Long _long = new Long(0); - this.m(it, _long); - InputOutput.println(Integer.valueOf(it.length())); - }; - return ObjectExtensions.operator_doubleArrow(_stringBuilderLike, _function); - } - } - ''') - } - - @Test override testBug406425_05() { - ''' - import org.eclipse.xtend.core.tests.java8.compiler.StringBuilderLike - class Test { - def m(T a, T b){} - - def m() { - new StringBuilderLike => [ - m(new Long(0)) - println(length) - ] - } - } - '''.assertCompilesTo(''' - import java.io.Serializable; - import org.eclipse.xtend.core.tests.java8.compiler.StringBuilderLike; - import org.eclipse.xtext.xbase.lib.InputOutput; - import org.eclipse.xtext.xbase.lib.ObjectExtensions; - import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; - - @SuppressWarnings("all") - public class Test { - public Object m(final T a, final T b) { - return null; - } - - public StringBuilderLike m() { - StringBuilderLike _stringBuilderLike = new StringBuilderLike(); - final Procedure1 _function = (StringBuilderLike it) -> { - Long _long = new Long(0); - this.m(it, _long); - InputOutput.println(Integer.valueOf(it.length())); - }; - return ObjectExtensions.operator_doubleArrow(_stringBuilderLike, _function); - } - } - ''') - } - - @Test override testBug406425_06() { - ''' - import org.eclipse.xtend.core.tests.java8.compiler.StringBuilderLike - class Test { - def m(T a, T b){} - - def m() { - newArrayList(new StringBuilderLike).forEach [ - m(it, new Long(0)) - println(length) - ] - } - } - '''.assertCompilesTo(''' - import java.io.Serializable; - import java.util.function.Consumer; - import org.eclipse.xtend.core.tests.java8.compiler.StringBuilderLike; - import org.eclipse.xtext.xbase.lib.CollectionLiterals; - import org.eclipse.xtext.xbase.lib.InputOutput; - - @SuppressWarnings("all") - public class Test { - public Object m(final T a, final T b) { - return null; - } - - public void m() { - StringBuilderLike _stringBuilderLike = new StringBuilderLike(); - final Consumer _function = (StringBuilderLike it) -> { - Long _long = new Long(0); - this.m(it, _long); - InputOutput.println(Integer.valueOf(it.length())); - }; - CollectionLiterals.newArrayList(_stringBuilderLike).forEach(_function); - } - } - ''') - } - - @Test override testBug406425_07() { - ''' - import org.eclipse.xtend.core.tests.java8.compiler.StringBuilderLike - class Test { - def static m(T a, T b){} - - def m() { - new StringBuilderLike => [ - m(it, new Long(0)) - println(length) - ] - } - } - '''.assertCompilesTo(''' - import java.io.Serializable; - import org.eclipse.xtend.core.tests.java8.compiler.StringBuilderLike; - import org.eclipse.xtext.xbase.lib.InputOutput; - import org.eclipse.xtext.xbase.lib.ObjectExtensions; - import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; - - @SuppressWarnings("all") - public class Test { - public static Object m(final T a, final T b) { - return null; - } - - public StringBuilderLike m() { - StringBuilderLike _stringBuilderLike = new StringBuilderLike(); - final Procedure1 _function = (StringBuilderLike it) -> { - Long _long = new Long(0); - Test.m(it, _long); - InputOutput.println(Integer.valueOf(it.length())); - }; - return ObjectExtensions.operator_doubleArrow(_stringBuilderLike, _function); - } - } - ''') - } - - @Test override testBug406425_08() { - ''' - import org.eclipse.xtend.core.tests.java8.compiler.StringBuilderLike - class Test { - def static m(T a, T b){} - - def static m() { - new StringBuilderLike => [ - m(it, new Long(0)) - println(length) - ] - } - } - '''.assertCompilesTo(''' - import java.io.Serializable; - import org.eclipse.xtend.core.tests.java8.compiler.StringBuilderLike; - import org.eclipse.xtext.xbase.lib.InputOutput; - import org.eclipse.xtext.xbase.lib.ObjectExtensions; - import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; - - @SuppressWarnings("all") - public class Test { - public static Object m(final T a, final T b) { - return null; - } - - public static StringBuilderLike m() { - StringBuilderLike _stringBuilderLike = new StringBuilderLike(); - final Procedure1 _function = (StringBuilderLike it) -> { - Long _long = new Long(0); - Test.m(it, _long); - InputOutput.println(Integer.valueOf(it.length())); - }; - return ObjectExtensions.operator_doubleArrow(_stringBuilderLike, _function); - } - } - ''') - } - - @Test override testBug406425_09() { - ''' - import org.eclipse.xtend.core.tests.java8.compiler.StringBuilderLike - class Test { - def m(T a, T b){} - - static def m() { - newArrayList(new StringBuilderLike).forEach [ - new Test().m(it, new Long(0)) - println(length) - ] - } - } - '''.assertCompilesTo(''' - import java.io.Serializable; - import java.util.function.Consumer; - import org.eclipse.xtend.core.tests.java8.compiler.StringBuilderLike; - import org.eclipse.xtext.xbase.lib.CollectionLiterals; - import org.eclipse.xtext.xbase.lib.InputOutput; - - @SuppressWarnings("all") - public class Test { - public Object m(final T a, final T b) { - return null; - } - - public static void m() { - StringBuilderLike _stringBuilderLike = new StringBuilderLike(); - final Consumer _function = (StringBuilderLike it) -> { - Test _test = new Test(); - Long _long = new Long(0); - _test.m(it, _long); - InputOutput.println(Integer.valueOf(it.length())); - }; - CollectionLiterals.newArrayList(_stringBuilderLike).forEach(_function); - } - } - ''') - } - - @Test override testBug406425_10() { - ''' - import org.eclipse.xtend.core.tests.java8.compiler.StringBuilderLike - class Test { - def m(T a, T b){} - - static def m() { - newArrayList(new StringBuilderLike).forEach [ - new Test().m(it, new Long(0)) - println(length) - ] - } - } - '''.assertCompilesTo(''' - import java.io.Serializable; - import java.util.function.Consumer; - import org.eclipse.xtend.core.tests.java8.compiler.StringBuilderLike; - import org.eclipse.xtext.xbase.lib.CollectionLiterals; - import org.eclipse.xtext.xbase.lib.InputOutput; - - @SuppressWarnings("all") - public class Test { - public Object m(final T a, final T b) { - return null; - } - - public static void m() { - StringBuilderLike _stringBuilderLike = new StringBuilderLike(); - final Consumer _function = (StringBuilderLike it) -> { - Test _test = new Test(); - Long _long = new Long(0); - _test.m(it, _long); - InputOutput.println(Integer.valueOf(it.length())); - }; - CollectionLiterals.newArrayList(_stringBuilderLike).forEach(_function); - } - } - ''') - } - - @Test override testBug406425_11() { - ''' - import org.eclipse.xtend.core.tests.java8.compiler.StringBuilderLike - class Test { - static def m(T a, T b){} - - static def m() { - newArrayList(new StringBuilderLike).forEach [ - m(it, new Long(0)) - println(length) - ] - } - } - '''.assertCompilesTo(''' - import java.io.Serializable; - import java.util.function.Consumer; - import org.eclipse.xtend.core.tests.java8.compiler.StringBuilderLike; - import org.eclipse.xtext.xbase.lib.CollectionLiterals; - import org.eclipse.xtext.xbase.lib.InputOutput; - - @SuppressWarnings("all") - public class Test { - public static Object m(final T a, final T b) { - return null; - } - - public static void m() { - StringBuilderLike _stringBuilderLike = new StringBuilderLike(); - final Consumer _function = (StringBuilderLike it) -> { - Long _long = new Long(0); - Test.m(it, _long); - InputOutput.println(Integer.valueOf(it.length())); - }; - CollectionLiterals.newArrayList(_stringBuilderLike).forEach(_function); - } - } - ''') - } - -} - diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug410797Test.xtend b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug410797Test.xtend deleted file mode 100644 index 88467ec22b6..00000000000 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug410797Test.xtend +++ /dev/null @@ -1,335 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2014, 2020 itemis AG (http://www.itemis.eu) and others. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * SPDX-License-Identifier: EPL-2.0 - *******************************************************************************/ -package org.eclipse.xtend.core.tests.java8.compiler - -import org.eclipse.xtend.core.tests.compiler.AbstractXtendCompilerTest -import org.eclipse.xtend.core.tests.java8.Java8RuntimeInjectorProvider -import org.eclipse.xtext.testing.InjectWith -import org.junit.Test - -/** - * @author Sebastian Zarnekow - Initial contribution and API - * @author Miro Spoenemann - Copied and adapted to Java 8 output - */ -@InjectWith(Java8RuntimeInjectorProvider) -class CompilerBug410797Test extends AbstractXtendCompilerTest { - - @Test def void testBug_410797_01() { - ''' - class C { - def Iterable m() { - val list = newArrayList - val g = new G - - list.map[e|e.m].flatten.map[d(g)] - } - def d(F f, G g) { - new D - } - } - class D { - } - class E { - def m() { - newArrayList - } - } - - class G { - } - class F { - - } - '''.assertCompilesTo(''' - import com.google.common.collect.Iterables; - import java.util.ArrayList; - import org.eclipse.xtext.xbase.lib.CollectionLiterals; - import org.eclipse.xtext.xbase.lib.Functions.Function1; - import org.eclipse.xtext.xbase.lib.IterableExtensions; - import org.eclipse.xtext.xbase.lib.ListExtensions; - - @SuppressWarnings("all") - public class C { - public Iterable m() { - Iterable _xblockexpression = null; - { - final ArrayList list = CollectionLiterals.newArrayList(); - final G g = new G(); - final Function1> _function = (E e) -> { - return e.m(); - }; - final Function1 _function_1 = (F it) -> { - return this.d(it, g); - }; - _xblockexpression = IterableExtensions.map(Iterables.concat(ListExtensions.>map(list, _function)), _function_1); - } - return _xblockexpression; - } - - public D d(final F f, final G g) { - return new D(); - } - } - ''') - } - - @Test def void testBug_410797_02() { - ''' - class C { - def Iterable m() { - val g = new G(); - newArrayList.map[e|e.m].flatten.map[d(g)] - } - def d(F f, G g) { - new D - } - } - class D { - } - class E { - def m() { - newArrayList - } - } - - class G { - } - class F { - - } - '''.assertCompilesTo(''' - import com.google.common.collect.Iterables; - import java.util.ArrayList; - import org.eclipse.xtext.xbase.lib.CollectionLiterals; - import org.eclipse.xtext.xbase.lib.Functions.Function1; - import org.eclipse.xtext.xbase.lib.IterableExtensions; - import org.eclipse.xtext.xbase.lib.ListExtensions; - - @SuppressWarnings("all") - public class C { - public Iterable m() { - Iterable _xblockexpression = null; - { - final G g = new G(); - final Function1> _function = (E e) -> { - return e.m(); - }; - final Function1 _function_1 = (F it) -> { - return this.d(it, g); - }; - _xblockexpression = IterableExtensions.map(Iterables.concat(ListExtensions.>map(CollectionLiterals.newArrayList(), _function)), _function_1); - } - return _xblockexpression; - } - - public D d(final F f, final G g) { - return new D(); - } - } - ''') - } - - @Test def void testBug_410797_03() { - ''' - class C { - def Iterable m() { - newArrayList.map[e|e.m].flatten.map[d(new G)] - } - def d(F f, G g) { - new D - } - } - class D { - } - class E { - def m() { - newArrayList - } - } - - class G { - } - class F { - - } - '''.assertCompilesTo(''' - import com.google.common.collect.Iterables; - import java.util.ArrayList; - import org.eclipse.xtext.xbase.lib.CollectionLiterals; - import org.eclipse.xtext.xbase.lib.Functions.Function1; - import org.eclipse.xtext.xbase.lib.IterableExtensions; - import org.eclipse.xtext.xbase.lib.ListExtensions; - - @SuppressWarnings("all") - public class C { - public Iterable m() { - final Function1> _function = (E e) -> { - return e.m(); - }; - final Function1 _function_1 = (F it) -> { - G _g = new G(); - return this.d(it, _g); - }; - return IterableExtensions.map(Iterables.concat(ListExtensions.>map(CollectionLiterals.newArrayList(), _function)), _function_1); - } - - public D d(final F f, final G g) { - return new D(); - } - } - ''') - } - - @Test def void testBug_410797_04() { - ''' - package org.eclipse.xtext.xbase.formatting - - import com.google.inject.Inject - import org.eclipse.xtext.nodemodel.INode - import java.util.List - import org.eclipse.xtext.nodemodel.ILeafNode - import org.eclipse.xtext.parsetree.reconstr.impl.NodeIterator - import org.eclipse.xtext.nodemodel.ICompositeNode - - @Data class HiddenLeafs { - int offset - List leafs = newArrayList - - def boolean isSingleWhitespace() { - leafs.empty || (leafs.size == 1 && leafs.head instanceof WhitespaceInfo) - } - - def int getLenght() { - leafs.fold(0, [x, i | x + i.node?.length]) - } - - def int getNewLines() { - leafs.fold(0, [x, i | x + i.newLines]) - } - - def int getNewLinesInComments() { - leafs.filter(CommentInfo).fold(0, [x, i | x + i.newLines]) - } - - def containsComment(){ - leafs.filter(CommentInfo).size > 0 - } - } - '''.assertCompilesTo(''' - package org.eclipse.xtext.xbase.formatting; - - import com.google.common.collect.Iterables; - import java.util.List; - import org.eclipse.xtend.lib.Data; - import org.eclipse.xtext.nodemodel.ILeafNode; - import org.eclipse.xtext.xbase.lib.CollectionLiterals; - import org.eclipse.xtext.xbase.lib.Functions.Function2; - import org.eclipse.xtext.xbase.lib.IterableExtensions; - import org.eclipse.xtext.xbase.lib.Pure; - import org.eclipse.xtext.xbase.lib.util.ToStringHelper; - - @Data - @SuppressWarnings("all") - public class HiddenLeafs { - private final int _offset; - - private final List _leafs = CollectionLiterals.newArrayList(); - - public boolean isSingleWhitespace() { - return (this.getLeafs().isEmpty() || ((this.getLeafs().size() == 1) && (IterableExtensions.head(this.getLeafs()) instanceof WhitespaceInfo))); - } - - public int getLenght() { - final Function2 _function = (Integer x, LeafInfo i) -> { - ILeafNode _node = i.getNode(); - int _length = 0; - if (_node!=null) { - _length=_node.getLength(); - } - return Integer.valueOf(((x).intValue() + _length)); - }; - return (int) IterableExtensions.fold(this.getLeafs(), Integer.valueOf(0), _function); - } - - public int getNewLines() { - final Function2 _function = (Integer x, LeafInfo i) -> { - int _newLines = i.getNewLines(); - return Integer.valueOf(((x).intValue() + _newLines)); - }; - return (int) IterableExtensions.fold(this.getLeafs(), Integer.valueOf(0), _function); - } - - public int getNewLinesInComments() { - final Function2 _function = (Integer x, CommentInfo i) -> { - int _newLines = i.getNewLines(); - return Integer.valueOf(((x).intValue() + _newLines)); - }; - return (int) IterableExtensions.fold(Iterables.filter(this.getLeafs(), CommentInfo.class), Integer.valueOf(0), _function); - } - - public boolean containsComment() { - int _size = IterableExtensions.size(Iterables.filter(this.getLeafs(), CommentInfo.class)); - return (_size > 0); - } - - public HiddenLeafs(final int offset) { - super(); - this._offset = offset; - } - - @Override - @Pure - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + this._offset; - return prime * result + ((this._leafs== null) ? 0 : this._leafs.hashCode()); - } - - @Override - @Pure - public boolean equals(final Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - HiddenLeafs other = (HiddenLeafs) obj; - if (other._offset != this._offset) - return false; - if (this._leafs == null) { - if (other._leafs != null) - return false; - } else if (!this._leafs.equals(other._leafs)) - return false; - return true; - } - - @Override - @Pure - public String toString() { - String result = new ToStringHelper().toString(this); - return result; - } - - @Pure - public int getOffset() { - return this._offset; - } - - @Pure - public List getLeafs() { - return this._leafs; - } - } - ''') - } - -} \ No newline at end of file diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug412894Test.xtend b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug412894Test.xtend deleted file mode 100644 index f0b6c8790a6..00000000000 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug412894Test.xtend +++ /dev/null @@ -1,163 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2014, 2016 itemis AG (http://www.itemis.eu) and others. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * SPDX-License-Identifier: EPL-2.0 - *******************************************************************************/ -package org.eclipse.xtend.core.tests.java8.compiler - -import org.eclipse.xtend.core.tests.java8.Java8RuntimeInjectorProvider -import org.eclipse.xtext.testing.InjectWith -import org.junit.Test - -/** - * @author Sebastian Zarnekow - Initial contribution and API - * @author Miro Spoenemann - Copied and adapted to Java 8 output - */ -@InjectWith(Java8RuntimeInjectorProvider) -class CompilerBug412894Test extends org.eclipse.xtend.core.tests.compiler.CompilerBug412894Test { - - @Test override test_01() { - ''' - class C { - def m() { - val list = newArrayList - list.forEach [ - switch it { - String: list.add(it) - } - ] - } - } - '''.assertCompilesTo(''' - import java.util.ArrayList; - import java.util.function.Consumer; - import org.eclipse.xtext.xbase.lib.CollectionLiterals; - - @SuppressWarnings("all") - public class C { - public void m() { - final ArrayList list = CollectionLiterals.newArrayList(); - final Consumer _function = (String it) -> { - boolean _matched = false; - if (it instanceof String) { - _matched=true; - list.add(it); - } - }; - list.forEach(_function); - } - } - ''') - } - - @Test override test_02() { - ''' - class C { - def m() { - val list = newArrayList - list.forEach [ - switch it { - String: list.add(it) - Number: list.add(it) - } - ] - } - } - '''.assertCompilesTo(''' - import java.io.Serializable; - import java.util.ArrayList; - import java.util.function.Consumer; - import org.eclipse.xtext.xbase.lib.CollectionLiterals; - - @SuppressWarnings("all") - public class C { - public void m() { - final ArrayList list = CollectionLiterals.newArrayList(); - final Consumer _function = (Serializable it) -> { - boolean _matched = false; - if (it instanceof String) { - _matched=true; - list.add(it); - } - if (!_matched) { - if (it instanceof Number) { - _matched=true; - list.add(it); - } - } - }; - list.forEach(_function); - } - } - ''') - } - - @Test override test_03() { - ''' - class C { - def m() { - val list = newArrayList - list.forEach [ - switch it { - Number: list.add(it.toString) - } - ] - } - } - '''.assertCompilesTo(''' - import java.io.Serializable; - import java.util.ArrayList; - import java.util.function.Consumer; - import org.eclipse.xtext.xbase.lib.CollectionLiterals; - - @SuppressWarnings("all") - public class C { - public void m() { - final ArrayList list = CollectionLiterals.newArrayList(); - final Consumer _function = (Serializable it) -> { - boolean _matched = false; - if (it instanceof Number) { - _matched=true; - list.add(((Number)it).toString()); - } - }; - list.forEach(_function); - } - } - ''') - } - - @Test override test_04() { - ''' - class C { - def m() { - val list = newArrayList - list.forEach [ - if (it instanceof String) list.add(it) - ] - } - } - '''.assertCompilesTo(''' - import java.util.ArrayList; - import java.util.function.Consumer; - import org.eclipse.xtext.xbase.lib.CollectionLiterals; - - @SuppressWarnings("all") - public class C { - public void m() { - final ArrayList list = CollectionLiterals.newArrayList(); - final Consumer _function = (Object it) -> { - if ((it instanceof String)) { - list.add(it); - } - }; - list.forEach(_function); - } - } - ''') - } - -} \ No newline at end of file diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug421999Test.xtend b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug421999Test.xtend deleted file mode 100644 index 5a9b3d453b6..00000000000 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug421999Test.xtend +++ /dev/null @@ -1,179 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2013, 2016 itemis AG (http://www.itemis.eu) and others. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * SPDX-License-Identifier: EPL-2.0 - *******************************************************************************/ -package org.eclipse.xtend.core.tests.java8.compiler - -import org.eclipse.xtend.core.tests.compiler.AbstractXtendCompilerTest -import org.eclipse.xtend.core.tests.java8.Java8RuntimeInjectorProvider -import org.eclipse.xtext.testing.InjectWith -import org.junit.Test - -/** - * @author Sebastian Zarnekow - Initial contribution and API - * @author Miro Spoenemann - Copied and adapted to Java 8 output - */ -@InjectWith(Java8RuntimeInjectorProvider) -class CompilerBug421999Test extends AbstractXtendCompilerTest { - - @Test def test_01() { - ''' - class C { - def m(java.util.List list) { - return list.sortBy(e|e) - } - } - '''.assertCompilesTo(''' - import java.util.List; - import org.eclipse.xtext.xbase.lib.Functions.Function1; - import org.eclipse.xtext.xbase.lib.IterableExtensions; - - @SuppressWarnings("all") - public class C { - public List m(final List list) { - final Function1 _function = (String e) -> { - return e; - }; - return IterableExtensions.sortBy(list, _function); - } - } - ''') - } - - @Test def test_02() { - ''' - class C { - def java.util.List m(java.util.List list) { - return list.sortBy(e|e) - } - } - '''.assertCompilesTo(''' - import java.util.List; - import org.eclipse.xtext.xbase.lib.Functions.Function1; - import org.eclipse.xtext.xbase.lib.IterableExtensions; - - @SuppressWarnings("all") - public class C { - public List m(final List list) { - final Function1 _function = (String e) -> { - return e; - }; - return IterableExtensions.sortBy(list, _function); - } - } - ''') - } - - @Test def test_03() { - ''' - class C { - def m(java.util.List list) { - list.sortBy(e|e) - } - } - '''.assertCompilesTo(''' - import java.util.List; - import org.eclipse.xtext.xbase.lib.Functions.Function1; - import org.eclipse.xtext.xbase.lib.IterableExtensions; - - @SuppressWarnings("all") - public class C { - public List m(final List list) { - final Function1 _function = (String e) -> { - return e; - }; - return IterableExtensions.sortBy(list, _function); - } - } - ''') - } - - @Test def test_04() { - ''' - class C { - def java.util.List m(java.util.List list) { - list.sortBy(e|e) - } - } - '''.assertCompilesTo(''' - import java.util.List; - import org.eclipse.xtext.xbase.lib.Functions.Function1; - import org.eclipse.xtext.xbase.lib.IterableExtensions; - - @SuppressWarnings("all") - public class C { - public List m(final List list) { - final Function1 _function = (String e) -> { - return e; - }; - return IterableExtensions.sortBy(list, _function); - } - } - ''') - } - - @Test def test_05() { - ''' - import org.eclipse.emf.ecore.EClass - import org.eclipse.emf.ecore.EObject - import org.eclipse.emf.ecore.resource.ResourceSet - import org.eclipse.xtext.EcoreUtil2 - import org.eclipse.xtext.naming.QualifiedName - import org.eclipse.xtext.resource.IEObjectDescription - import org.eclipse.xtext.xbase.lib.Pair - - class Dummy { - - def private T resolve(IEObjectDescription it, ResourceSet resourceSet) { - } - - def Iterable> getVisibleIEObjectDescriptionByTypeAndCondition( - ResourceSet resourceSet, - EClass type, - (IEObjectDescription)=>boolean p) { - val c = newArrayList - c.map[eod| - eod.qualifiedName -> resolve(eod, resourceSet)] - } - - } - '''.assertCompilesTo(''' - import java.util.ArrayList; - import java.util.List; - import org.eclipse.emf.ecore.EClass; - import org.eclipse.emf.ecore.EObject; - import org.eclipse.emf.ecore.resource.ResourceSet; - import org.eclipse.xtext.naming.QualifiedName; - import org.eclipse.xtext.resource.IEObjectDescription; - import org.eclipse.xtext.xbase.lib.CollectionLiterals; - import org.eclipse.xtext.xbase.lib.Functions.Function1; - import org.eclipse.xtext.xbase.lib.ListExtensions; - import org.eclipse.xtext.xbase.lib.Pair; - - @SuppressWarnings("all") - public class Dummy { - private T resolve(final IEObjectDescription it, final ResourceSet resourceSet) { - return null; - } - - public Iterable> getVisibleIEObjectDescriptionByTypeAndCondition(final ResourceSet resourceSet, final EClass type, final Function1 p) { - List> _xblockexpression = null; - { - final ArrayList c = CollectionLiterals.newArrayList(); - final Function1> _function = (IEObjectDescription eod) -> { - QualifiedName _qualifiedName = eod.getQualifiedName(); - T _resolve = this.resolve(eod, resourceSet); - return Pair.of(_qualifiedName, _resolve); - }; - _xblockexpression = ListExtensions.>map(c, _function); - } - return _xblockexpression; - } - } - ''') - } -} diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug427637Test.xtend b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug427637Test.xtend deleted file mode 100644 index 7892da9a2df..00000000000 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug427637Test.xtend +++ /dev/null @@ -1,1617 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2014, 2020 itemis AG (http://www.itemis.eu) and others. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * SPDX-License-Identifier: EPL-2.0 - *******************************************************************************/ -package org.eclipse.xtend.core.tests.java8.compiler - -import org.eclipse.xtend.core.tests.java8.Java8RuntimeInjectorProvider -import org.eclipse.xtext.testing.InjectWith -import org.junit.Test - -/** - * @author Sebastian Zarnekow - Initial contribution and API - * @author Miro Spoenemann - Copied and adapted to Java 8 output - */ -@InjectWith(Java8RuntimeInjectorProvider) -class CompilerBug427637Test extends org.eclipse.xtend.core.tests.compiler.CompilerBug427637Test { - - @Test override void testBug_427637_01() { - ''' - import java.util.List - - class C { - def m(List list) { - list.forEach2 [ - ] - } - def void forEach2(Iterable iterable, (T)=>void procedure) {} - } - '''.assertCompilesTo(''' - import java.util.List; - import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; - - @SuppressWarnings("all") - public class C { - public void m(final List list) { - final Procedure1 _function = (V it) -> { - }; - this.forEach2(list, _function); - } - - public void forEach2(final Iterable iterable, final Procedure1 procedure) { - } - } - ''') - } - - @Test override void testBug_427637_01_b() { - ''' - import java.util.List - - class C { - def m(List list) { - list.forEach [ - ] - } - } - '''.assertCompilesTo(''' - import java.util.List; - import java.util.function.Consumer; - - @SuppressWarnings("all") - public class C { - public void m(final List list) { - final Consumer _function = (V it) -> { - }; - list.forEach(_function); - } - } - ''') - } - - @Test override void testBug_427637_02() { - ''' - import java.util.List - - class C { - def m(List list) { - list.forEach2 [ - ] - } - def void forEach2(Iterable iterable, (T)=>void procedure) {} - } - '''.assertCompilesTo(''' - import java.util.List; - import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; - - @SuppressWarnings("all") - public class C { - public void m(final List list) { - final Procedure1 _function = (V it) -> { - }; - this.forEach2(list, _function); - } - - public void forEach2(final Iterable iterable, final Procedure1 procedure) { - } - } - ''') - } - - @Test override void testBug_427637_02_b() { - ''' - import java.util.List - - class C { - def m(List list) { - list.forEach [ - ] - } - } - '''.assertCompilesTo(''' - import java.util.List; - import java.util.function.Consumer; - - @SuppressWarnings("all") - public class C { - public void m(final List list) { - final Consumer _function = (V it) -> { - }; - list.forEach(_function); - } - } - ''') - } - - @Test override void testBug_427637_03() { - ''' - import java.util.List - - class C { - def m(List list) { - list.forEach2 [ - ] - } - def void forEach2(Iterable iterable, (T)=>void procedure) {} - } - '''.assertCompilesTo(''' - import java.util.List; - import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; - - @SuppressWarnings("all") - public class C { - public void m(final List list) { - final Procedure1 _function = (Object it) -> { - }; - this.forEach2(list, _function); - } - - public void forEach2(final Iterable iterable, final Procedure1 procedure) { - } - } - ''') - } - - @Test override void testBug_427637_03_b() { - ''' - import java.util.List - - class C { - def m(List list) { - list.forEach [ - ] - } - } - '''.assertCompilesTo(''' - import java.util.List; - import java.util.function.Consumer; - - @SuppressWarnings("all") - public class C { - public void m(final List list) { - final Consumer _function = (Object it) -> { - }; - list.forEach(_function); - } - } - ''') - } - - @Test override void testBug_427637_04() { - ''' - import java.util.List - - class C { - def m(List list) { - list.subList(1,1).forEach2 [ - ] - } - def void forEach2(Iterable iterable, (T)=>void procedure) {} - } - '''.assertCompilesTo(''' - import java.util.List; - import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; - - @SuppressWarnings("all") - public class C { - public void m(final List list) { - final Procedure1 _function = (V it) -> { - }; - this.forEach2(list.subList(1, 1), _function); - } - - public void forEach2(final Iterable iterable, final Procedure1 procedure) { - } - } - ''') - } - - @Test override void testBug_427637_04_b() { - ''' - import java.util.List - - class C { - def m(List list) { - list.subList(1,1).forEach [ - ] - } - } - '''.assertCompilesTo(''' - import java.util.List; - import java.util.function.Consumer; - - @SuppressWarnings("all") - public class C { - public void m(final List list) { - final Consumer _function = (V it) -> { - }; - list.subList(1, 1).forEach(_function); - } - } - ''') - } - - @Test override void testBug_427637_05() { - ''' - import java.util.List - - class C { - def m(List list) { - list.subList(1,1).forEach2 [ - ] - } - def void forEach2(Iterable iterable, (T)=>void procedure) {} - } - '''.assertCompilesTo(''' - import java.util.List; - import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; - - @SuppressWarnings("all") - public class C { - public void m(final List list) { - final Procedure1 _function = (V it) -> { - }; - this.forEach2(list.subList(1, 1), _function); - } - - public void forEach2(final Iterable iterable, final Procedure1 procedure) { - } - } - ''') - } - - @Test override void testBug_427637_05_b() { - ''' - import java.util.List - - class C { - def m(List list) { - list.subList(1,1).forEach [ - ] - } - } - '''.assertCompilesTo(''' - import java.util.List; - import java.util.function.Consumer; - - @SuppressWarnings("all") - public class C { - public void m(final List list) { - final Consumer _function = (V it) -> { - }; - list.subList(1, 1).forEach(_function); - } - } - ''') - } - - @Test override void testBug_427637_06() { - ''' - import java.util.List - - class C { - def m(List list) { - list.subList(1,1).forEach2 [ - ] - } - def void forEach2(Iterable iterable, (T)=>void procedure) {} - } - '''.assertCompilesTo(''' - import java.util.List; - import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; - - @SuppressWarnings("all") - public class C { - public void m(final List list) { - final Procedure1 _function = (Object it) -> { - }; - this.forEach2(list.subList(1, 1), _function); - } - - public void forEach2(final Iterable iterable, final Procedure1 procedure) { - } - } - ''') - } - - @Test override void testBug_427637_06_b() { - ''' - import java.util.List - - class C { - def m(List list) { - list.subList(1,1).forEach [ - ] - } - } - '''.assertCompilesTo(''' - import java.util.List; - import java.util.function.Consumer; - - @SuppressWarnings("all") - public class C { - public void m(final List list) { - final Consumer _function = (Object it) -> { - }; - list.subList(1, 1).forEach(_function); - } - } - ''') - } - - @Test override void testBug_427637_07() { - ''' - import java.util.List - - class C { - def m(List list) { - list.subList(1,1).forEach2 [ - it.toString - ] - } - def void forEach2(Iterable iterable, (T)=>void procedure) {} - } - '''.assertCompilesTo(''' - import java.util.List; - import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; - - @SuppressWarnings("all") - public class C { - public void m(final List list) { - final Procedure1 _function = (V it) -> { - it.toString(); - }; - this.forEach2(list.subList(1, 1), _function); - } - - public void forEach2(final Iterable iterable, final Procedure1 procedure) { - } - } - ''') - } - - @Test override void testBug_427637_07_b() { - ''' - import java.util.List - - class C { - def m(List list) { - list.subList(1,1).forEach [ - it.toString - ] - } - } - '''.assertCompilesTo(''' - import java.util.List; - import java.util.function.Consumer; - - @SuppressWarnings("all") - public class C { - public void m(final List list) { - final Consumer _function = (V it) -> { - it.toString(); - }; - list.subList(1, 1).forEach(_function); - } - } - ''') - } - - @Test override void testBug_427637_08() { - ''' - import java.util.List - - class C { - def m(List list) { - list.subList(1,1).forEach2 [ - it.toString - ] - } - def void forEach2(Iterable iterable, (T)=>void procedure) {} - } - '''.assertCompilesTo(''' - import java.util.List; - import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; - - @SuppressWarnings("all") - public class C { - public void m(final List list) { - final Procedure1 _function = (V it) -> { - it.toString(); - }; - this.forEach2(list.subList(1, 1), _function); - } - - public void forEach2(final Iterable iterable, final Procedure1 procedure) { - } - } - ''') - } - - @Test override void testBug_427637_08_b() { - ''' - import java.util.List - - class C { - def m(List list) { - list.subList(1,1).forEach [ - it.toString - ] - } - } - '''.assertCompilesTo(''' - import java.util.List; - import java.util.function.Consumer; - - @SuppressWarnings("all") - public class C { - public void m(final List list) { - final Consumer _function = (V it) -> { - it.toString(); - }; - list.subList(1, 1).forEach(_function); - } - } - ''') - } - - @Test override void testBug_427637_09() { - ''' - import java.util.List - - class C { - def m(List list) { - list.subList(1,1).forEach2 [ - it.toString - ] - } - def void forEach2(Iterable iterable, (T)=>void procedure) {} - } - '''.assertCompilesTo(''' - import java.util.List; - import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; - - @SuppressWarnings("all") - public class C { - public void m(final List list) { - final Procedure1 _function = (Object it) -> { - it.toString(); - }; - this.forEach2(list.subList(1, 1), _function); - } - - public void forEach2(final Iterable iterable, final Procedure1 procedure) { - } - } - ''') - } - - @Test override void testBug_427637_09_b() { - ''' - import java.util.List - - class C { - def m(List list) { - list.subList(1,1).forEach [ - it.toString - ] - } - } - '''.assertCompilesTo(''' - import java.util.List; - import java.util.function.Consumer; - - @SuppressWarnings("all") - public class C { - public void m(final List list) { - final Consumer _function = (Object it) -> { - it.toString(); - }; - list.subList(1, 1).forEach(_function); - } - } - ''') - } - - @Test override void testBug_427637_10() { - ''' - import java.util.List - - class C { - def m(List list) { - val List target = null - list.forEach2 [ - target += it - ] - } - def void forEach2(Iterable iterable, (T)=>void procedure) {} - } - '''.assertCompilesTo(''' - import java.util.List; - import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; - - @SuppressWarnings("all") - public class C { - public void m(final List list) { - final List target = null; - final Procedure1 _function = (V it) -> { - target.add(it); - }; - this.forEach2(list, _function); - } - - public void forEach2(final Iterable iterable, final Procedure1 procedure) { - } - } - ''') - } - - @Test override void testBug_427637_10_b() { - ''' - import java.util.List - - class C { - def m(List list) { - val List target = null - list.forEach [ - target += it - ] - } - } - '''.assertCompilesTo(''' - import java.util.List; - import java.util.function.Consumer; - - @SuppressWarnings("all") - public class C { - public void m(final List list) { - final List target = null; - final Consumer _function = (V it) -> { - target.add(it); - }; - list.forEach(_function); - } - } - ''') - } - - @Test override void testBug_427637_11() { - ''' - import java.util.List - - class C { - def m(List list) { - val List target = null - list.subList(0,1).forEach [ - target.subList(0, 1) += it - target.subList(0, 1) -= it - target.subList(0, 1) += newArrayList(it) - target.subList(0, 1) -= newArrayList(it) - ] - } - } - '''.assertCompilesTo(''' - import com.google.common.collect.Iterables; - import java.util.ArrayList; - import java.util.List; - import java.util.function.Consumer; - import org.eclipse.xtext.xbase.lib.CollectionLiterals; - - @SuppressWarnings("all") - public class C { - public void m(final List list) { - final List target = null; - final Consumer _function = (T it) -> { - List _subList = target.subList(0, 1); - _subList.add(it); - List _subList_1 = target.subList(0, 1); - _subList_1.remove(it); - List _subList_2 = target.subList(0, 1); - ArrayList _newArrayList = CollectionLiterals.newArrayList(it); - Iterables.addAll(_subList_2, _newArrayList); - List _subList_3 = target.subList(0, 1); - ArrayList _newArrayList_1 = CollectionLiterals.newArrayList(it); - Iterables.removeAll(_subList_3, _newArrayList_1); - }; - list.subList(0, 1).forEach(_function); - } - } - ''') - } - - @Test override void testBug_427637_12() { - ''' - import java.util.List - - class Listener implements ListChangeListener { - - Group layer - - override onChanged(Change change) { - while(change.next) { - if(change.wasAdded) - change.addedSubList.forEach [ T it | - layer.children += it - it.activate() - ] - if(change.wasRemoved) - change.removed.forEach [ T it | - layer.children -= it - ] - } - } - } - interface ObservableList extends Observable, List {} - interface Observable {} - interface Node {} - interface Group extends Node { - def ObservableList getChildren() - } - interface XActivatable { - def void activate() - } - interface ListChangeListener { - def void onChanged(Change c) - } - interface Change { - def List getAddedSubList() - def List getRemoved() - def boolean next() - def boolean wasAdded() - def boolean wasRemoved() - } - '''.assertCompilesTo(''' - import java.util.function.Consumer; - - @SuppressWarnings("all") - public class Listener implements ListChangeListener { - private Group layer; - - @Override - public void onChanged(final Change change) { - while (change.next()) { - { - boolean _wasAdded = change.wasAdded(); - if (_wasAdded) { - final Consumer _function = (T it) -> { - ObservableList _children = this.layer.getChildren(); - _children.add(it); - it.activate(); - }; - change.getAddedSubList().forEach(_function); - } - boolean _wasRemoved = change.wasRemoved(); - if (_wasRemoved) { - final Consumer _function_1 = (T it) -> { - ObservableList _children = this.layer.getChildren(); - _children.remove(it); - }; - change.getRemoved().forEach(_function_1); - } - } - } - } - } - ''') - } - - @Test override void testBug_427637_13() { - ''' - import java.util.List - - class Listener implements ListChangeListener { - - Group layer - - override onChanged(Change change) { - while(change.next) { - if(change.wasAdded) - change.addedSubList.forEach [ - layer.children += it - it.activate() - ] - if(change.wasRemoved) - change.removed.forEach [ - layer.children -= it - ] - } - } - } - interface ObservableList extends Observable, List {} - interface Observable {} - interface Node {} - interface Group extends Node { - def ObservableList getChildren() - } - interface XActivatable { - def void activate() - } - interface ListChangeListener { - def void onChanged(Change c) - } - interface Change { - def List getAddedSubList() - def List getRemoved() - def boolean next() - def boolean wasAdded() - def boolean wasRemoved() - } - '''.assertCompilesTo(''' - import java.util.function.Consumer; - - @SuppressWarnings("all") - public class Listener implements ListChangeListener { - private Group layer; - - @Override - public void onChanged(final Change change) { - while (change.next()) { - { - boolean _wasAdded = change.wasAdded(); - if (_wasAdded) { - final Consumer _function = (T it) -> { - ObservableList _children = this.layer.getChildren(); - _children.add(it); - it.activate(); - }; - change.getAddedSubList().forEach(_function); - } - boolean _wasRemoved = change.wasRemoved(); - if (_wasRemoved) { - final Consumer _function_1 = (T it) -> { - ObservableList _children = this.layer.getChildren(); - _children.remove(it); - }; - change.getRemoved().forEach(_function_1); - } - } - } - } - } - ''') - } - - @Test override void testBug_427637_14() { - ''' - import java.util.List - - class Listener { // implements ListChangeListener { - Group layer - def onChanged(Change change) { - change.addedSubList.forEach2 [ - layer.children += it - ] - } - def void forEach2(Iterable iterable, (T)=>void procedure) {} - } - interface ObservableList extends Observable, List {} - interface Observable {} - interface Node {} - interface Group extends Node { - def ObservableList getChildren() - } - interface XActivatable { - def void activate() - } - interface ListChangeListener { - def void onChanged(Change c) - } - interface Change { - def List getAddedSubList() - def List getRemoved() - def boolean next() - def boolean wasAdded() - def boolean wasRemoved() - } - '''.assertCompilesTo(''' - import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; - - @SuppressWarnings("all") - public class Listener { - private Group layer; - - public void onChanged(final Change change) { - final Procedure1 _function = (T it) -> { - ObservableList _children = this.layer.getChildren(); - _children.add(it); - }; - this.forEach2(change.getAddedSubList(), _function); - } - - public void forEach2(final Iterable iterable, final Procedure1 procedure) { - } - } - ''') - } - - @Test override void testBug_427637_15() { - assertCompilesTo(''' - package org.eclipse.xtext.xbase.formatting - - import com.google.inject.Inject - import org.eclipse.xtext.nodemodel.INode - import org.eclipse.xtext.xbase.lib.util.ToStringHelper - - import static org.eclipse.xtext.xbase.formatting.XbaseFormatterPreferenceKeys.* - import org.eclipse.xtext.preferences.PreferenceKey - - class FormattingDataFactory { - - @Inject extension HiddenLeafAccess - - def protected (FormattableDocument)=>Iterable newFormattingData( - HiddenLeafs leafs, - (FormattingDataInit)=>void init - ) { - val data = new FormattingDataInit() - init.apply(data) - newFormattingData(leafs, data.key, data) - } - - def protected dispatch (FormattableDocument)=>Iterable newFormattingData(HiddenLeafs leafs, - Void key, FormattingDataInit it) { - [ FormattableDocument doc | - val int newLines2 = newLines ?: 0 - if ((space == null && newLines == null) || (leafs.newLinesInComments == 0 && (newLines2 == 0 || space == ""))) - return newWhitespaceData(leafs, space, increaseIndentationChange, decreaseIndentationChange, doc.debugConflicts) - else - return newNewLineData(leafs, newLines2, newLines2, increaseIndentationChange, decreaseIndentationChange, doc.debugConflicts) - ] - } - - def protected dispatch (FormattableDocument)=>Iterable newFormattingData( - HiddenLeafs leafs, - BlankLineKey key, - FormattingDataInit it - ) { - [ FormattableDocument doc | - val blankline = doc.cfg.get(key) - val preserve = doc.cfg.get(preserveBlankLines) - val min = blankline + 1 - val max = Math.max(preserve + 1, min) - newNewLineData(leafs, min, max, increaseIndentationChange, decreaseIndentationChange, doc.debugConflicts) - ] - } - - def protected dispatch (FormattableDocument)=>Iterable newFormattingData( - HiddenLeafs leafs, - NewLineOrPreserveKey key, - FormattingDataInit it - ) { - [ FormattableDocument doc | - val newLine = doc.cfg.get(key) - val preserve = doc.cfg.get(preserveNewLines) - newNewLineData(leafs, if (newLine) 1 else 0, if (preserve || newLine) 1 else 0, increaseIndentationChange, decreaseIndentationChange, - doc.debugConflicts) - ] - } - - def protected dispatch (FormattableDocument)=>Iterable newFormattingData( - HiddenLeafs leafs, - NewLineKey key, - FormattingDataInit it - ) { - [ FormattableDocument doc | - val newLine = doc.cfg.get(key) - val minmax = if (newLine) 1 else 0 - newNewLineData(leafs, minmax, minmax, increaseIndentationChange, decreaseIndentationChange, doc.debugConflicts) - ] - } - - def protected dispatch (FormattableDocument)=>Iterable newFormattingData( - HiddenLeafs leafs, - PreferenceKey key, - FormattingDataInit it - ) { - throw new RuntimeException("Unknown configuration key kind: " + key.^class) - } - - def protected dispatch (FormattableDocument)=>Iterable newFormattingData(HiddenLeafs leafs, - WhitespaceKey key, FormattingDataInit it) { - [ FormattableDocument doc | - val space = doc.cfg.get(key) - newWhitespaceData(leafs, if (space) " " else "", increaseIndentationChange, decreaseIndentationChange, doc.debugConflicts) - ] - } - - def protected Iterable newWhitespaceData( - HiddenLeafs leafs, - String space, - int increaseIndentationChange, - int decreaseIndentationChange, - boolean trace - ) { - val result = newArrayList - var isFirst = true - for (leaf : leafs.leafs) - switch leaf { - WhitespaceInfo: { - result += new WhitespaceData(leaf.offset, leaf.length, if(isFirst) increaseIndentationChange else 0, if(isFirst) decreaseIndentationChange else 0, - if (trace) new RuntimeException, space) - isFirst = false - } - CommentInfo: { - } - } - result - } - - def protected Iterable newNewLineData( - HiddenLeafs leafs, - int minNewLines, - int maxNewLines, - int increaseIndentationChange, - int decreaseIndentationChange, - boolean trace - ) { - val result = newArrayList - var applied = false - for (leaf : leafs.leafs) - switch leaf { - WhitespaceInfo: { - val equalIndentationChange = increaseIndentationChange == decreaseIndentationChange * -1 - if (leaf.trailingComment?.trailing && !leaf.trailingComment?.multiline) { - val space = if (leaf.offset == 0) "" else if(maxNewLines == 0) null else " " - result += new WhitespaceData(leaf.offset, leaf.length, 0 , 0, if (trace) new RuntimeException(), space) - } else if (!applied) { - var newLines = Math.min(Math.max(leafs.newLines, minNewLines), maxNewLines) - if (newLines < 1 && leaf.offset > 0 && - (leaf.leadingComment?.multiline || leaf.trailingComment?.multiline)) - newLines = 1 - if (leaf.leadingComment?.endsWithNewLine) - newLines = newLines - 1 - if (!leaf.leadingComment?.endsWithNewLine && newLines == 0) - result += new WhitespaceData(leaf.offset, leaf.length, increaseIndentationChange, decreaseIndentationChange, - if (trace) new RuntimeException(), if (leaf.offset == 0) "" else if(leafs.containsComment) null else " ") - else - if(equalIndentationChange && leafs.leafs.lastOrNull != leaf) - result += new NewLineData(leaf.offset, leaf.length, increaseIndentationChange, decreaseIndentationChange, if (trace) new RuntimeException(), newLines) - else - result += new NewLineData(leaf.offset, leaf.length, if(equalIndentationChange) 0 else increaseIndentationChange, if(equalIndentationChange) 0 else decreaseIndentationChange, if (trace) new RuntimeException(), newLines) - applied = true - } else { - var newLines = 1 - if (leaf.leadingComment?.endsWithNewLine) - newLines = newLines - 1 - if(equalIndentationChange && leafs.leafs.lastOrNull != leaf) - result += new NewLineData(leaf.offset, leaf.length, increaseIndentationChange, decreaseIndentationChange, if (trace) new RuntimeException(), newLines) - else - result += new NewLineData(leaf.offset, leaf.length, 0, 0, if (trace) new RuntimeException(), newLines) - } - } - CommentInfo: { - } - } - result - } - - def (FormattableDocument)=>Iterable append( - INode node, - (FormattingDataInit)=>void init - ) { - if (node != null) { - node.hiddenLeafsAfter.newFormattingData(init) - } - } - - def (FormattableDocument)=>Iterable prepend( - INode node, - (FormattingDataInit)=>void init - ) { - if (node != null) { - node.hiddenLeafsBefore.newFormattingData(init) - } - } - - def (FormattableDocument)=>Iterable surround( - INode node, - (FormattingDataInit)=>void init - ) { - [ FormattableDocument doc | - val result = newArrayList() - if (node != null) { - result += node.hiddenLeafsBefore.newFormattingData(init)?.apply(doc) ?: emptyList - result += node.hiddenLeafsAfter.newFormattingData(init)?.apply(doc) ?: emptyList - } - result - ] - } - - def (FormattableDocument)=>Iterable surround( - INode node, - (FormattingDataInit)=>void before, - (FormattingDataInit)=>void after - ) { - [ FormattableDocument doc | - val result = newArrayList() - if (node != null) { - result += node.hiddenLeafsBefore.newFormattingData(before)?.apply(doc) ?: emptyList - result += node.hiddenLeafsAfter.newFormattingData(after)?.apply(doc) ?: emptyList - } - result - ] - } - - static class FormattingDataInit { - public String space = null - public Integer newLines = null - public int increaseIndentationChange = 0 - public int decreaseIndentationChange = 0 - public PreferenceKey key = null - - def void cfg(PreferenceKey key) { - this.key = key - } - - def void newLine() { - newLines = 1 - } - - def void noSpace() { - space = "" - } - - def void oneSpace() { - space = " " - } - - def void increaseIndentation() { - increaseIndentationChange = increaseIndentationChange + 1 - } - - def void decreaseIndentation() { - decreaseIndentationChange = decreaseIndentationChange - 1 - } - - override String toString() { - new ToStringHelper().toString(this) - } - } - } - ''',''' - package org.eclipse.xtext.xbase.formatting; - - import com.google.common.collect.Iterables; - import com.google.inject.Inject; - import java.util.ArrayList; - import java.util.Arrays; - import java.util.List; - import java.util.Objects; - import org.eclipse.xtext.nodemodel.INode; - import org.eclipse.xtext.preferences.PreferenceKey; - import org.eclipse.xtext.xbase.lib.CollectionLiterals; - import org.eclipse.xtext.xbase.lib.Extension; - import org.eclipse.xtext.xbase.lib.Functions.Function1; - import org.eclipse.xtext.xbase.lib.IterableExtensions; - import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; - import org.eclipse.xtext.xbase.lib.util.ToStringHelper; - - @SuppressWarnings("all") - public class FormattingDataFactory { - public static class FormattingDataInit { - public String space = null; - - public Integer newLines = null; - - public int increaseIndentationChange = 0; - - public int decreaseIndentationChange = 0; - - public PreferenceKey key = null; - - public void cfg(final PreferenceKey key) { - this.key = key; - } - - public void newLine() { - this.newLines = Integer.valueOf(1); - } - - public void noSpace() { - this.space = ""; - } - - public void oneSpace() { - this.space = " "; - } - - public void increaseIndentation() { - this.increaseIndentationChange = (this.increaseIndentationChange + 1); - } - - public void decreaseIndentation() { - this.decreaseIndentationChange = (this.decreaseIndentationChange - 1); - } - - @Override - public String toString() { - return new ToStringHelper().toString(this); - } - } - - @Inject - @Extension - private HiddenLeafAccess _hiddenLeafAccess; - - protected Function1> newFormattingData(final HiddenLeafs leafs, final Procedure1 init) { - Function1> _xblockexpression = null; - { - final FormattingDataFactory.FormattingDataInit data = new FormattingDataFactory.FormattingDataInit(); - init.apply(data); - _xblockexpression = this.newFormattingData(leafs, data.key, data); - } - return _xblockexpression; - } - - protected Function1> _newFormattingData(final HiddenLeafs leafs, final Void key, final FormattingDataFactory.FormattingDataInit it) { - final Function1> _function = (FormattableDocument doc) -> { - Integer _elvis = null; - if (it.newLines != null) { - _elvis = it.newLines; - } else { - _elvis = Integer.valueOf(0); - } - final int newLines2 = (int) _elvis; - if (((Objects.equals(it.space, null) && Objects.equals(it.newLines, null)) || ((leafs.getNewLinesInComments() == 0) && ((newLines2 == 0) || Objects.equals(it.space, ""))))) { - return this.newWhitespaceData(leafs, it.space, it.increaseIndentationChange, it.decreaseIndentationChange, doc.isDebugConflicts()); - } else { - return this.newNewLineData(leafs, newLines2, newLines2, it.increaseIndentationChange, it.decreaseIndentationChange, doc.isDebugConflicts()); - } - }; - return _function; - } - - protected Function1> _newFormattingData(final HiddenLeafs leafs, final BlankLineKey key, final FormattingDataFactory.FormattingDataInit it) { - final Function1> _function = (FormattableDocument doc) -> { - Iterable _xblockexpression = null; - { - final int blankline = doc.getCfg().get(key); - final int preserve = doc.getCfg().get(XbaseFormatterPreferenceKeys.preserveBlankLines); - final int min = (blankline + 1); - final int max = Math.max((preserve + 1), min); - _xblockexpression = this.newNewLineData(leafs, min, max, it.increaseIndentationChange, it.decreaseIndentationChange, doc.isDebugConflicts()); - } - return _xblockexpression; - }; - return _function; - } - - protected Function1> _newFormattingData(final HiddenLeafs leafs, final NewLineOrPreserveKey key, final FormattingDataFactory.FormattingDataInit it) { - final Function1> _function = (FormattableDocument doc) -> { - Iterable _xblockexpression = null; - { - final boolean newLine = doc.getCfg().get(key); - final boolean preserve = doc.getCfg().get(XbaseFormatterPreferenceKeys.preserveNewLines); - int _xifexpression = (int) 0; - if (newLine) { - _xifexpression = 1; - } else { - _xifexpression = 0; - } - int _xifexpression_1 = (int) 0; - if ((preserve || newLine)) { - _xifexpression_1 = 1; - } else { - _xifexpression_1 = 0; - } - _xblockexpression = this.newNewLineData(leafs, _xifexpression, _xifexpression_1, it.increaseIndentationChange, it.decreaseIndentationChange, - doc.isDebugConflicts()); - } - return _xblockexpression; - }; - return _function; - } - - protected Function1> _newFormattingData(final HiddenLeafs leafs, final NewLineKey key, final FormattingDataFactory.FormattingDataInit it) { - final Function1> _function = (FormattableDocument doc) -> { - Iterable _xblockexpression = null; - { - final boolean newLine = doc.getCfg().get(key); - int _xifexpression = (int) 0; - if (newLine) { - _xifexpression = 1; - } else { - _xifexpression = 0; - } - final int minmax = _xifexpression; - _xblockexpression = this.newNewLineData(leafs, minmax, minmax, it.increaseIndentationChange, it.decreaseIndentationChange, doc.isDebugConflicts()); - } - return _xblockexpression; - }; - return _function; - } - - protected Function1> _newFormattingData(final HiddenLeafs leafs, final PreferenceKey key, final FormattingDataFactory.FormattingDataInit it) { - Class _class = key.getClass(); - String _plus = ("Unknown configuration key kind: " + _class); - throw new RuntimeException(_plus); - } - - protected Function1> _newFormattingData(final HiddenLeafs leafs, final WhitespaceKey key, final FormattingDataFactory.FormattingDataInit it) { - final Function1> _function = (FormattableDocument doc) -> { - Iterable _xblockexpression = null; - { - final boolean space = doc.getCfg().get(key); - String _xifexpression = null; - if (space) { - _xifexpression = " "; - } else { - _xifexpression = ""; - } - _xblockexpression = this.newWhitespaceData(leafs, _xifexpression, it.increaseIndentationChange, it.decreaseIndentationChange, doc.isDebugConflicts()); - } - return _xblockexpression; - }; - return _function; - } - - protected Iterable newWhitespaceData(final HiddenLeafs leafs, final String space, final int increaseIndentationChange, final int decreaseIndentationChange, final boolean trace) { - ArrayList _xblockexpression = null; - { - final ArrayList result = CollectionLiterals.newArrayList(); - boolean isFirst = true; - List _leafs = leafs.getLeafs(); - for (final LeafInfo leaf : _leafs) { - boolean _matched = false; - if (leaf instanceof WhitespaceInfo) { - _matched=true; - int _offset = ((WhitespaceInfo)leaf).getOffset(); - int _length = ((WhitespaceInfo)leaf).getLength(); - int _xifexpression = (int) 0; - if (isFirst) { - _xifexpression = increaseIndentationChange; - } else { - _xifexpression = 0; - } - int _xifexpression_1 = (int) 0; - if (isFirst) { - _xifexpression_1 = decreaseIndentationChange; - } else { - _xifexpression_1 = 0; - } - RuntimeException _xifexpression_2 = null; - if (trace) { - _xifexpression_2 = new RuntimeException(); - } - WhitespaceData _whitespaceData = new WhitespaceData(_offset, _length, _xifexpression, _xifexpression_1, _xifexpression_2, space); - result.add(_whitespaceData); - isFirst = false; - } - if (!_matched) { - if (leaf instanceof CommentInfo) { - _matched=true; - } - } - } - _xblockexpression = result; - } - return _xblockexpression; - } - - protected Iterable newNewLineData(final HiddenLeafs leafs, final int minNewLines, final int maxNewLines, final int increaseIndentationChange, final int decreaseIndentationChange, final boolean trace) { - ArrayList _xblockexpression = null; - { - final ArrayList result = CollectionLiterals.newArrayList(); - boolean applied = false; - List _leafs = leafs.getLeafs(); - for (final LeafInfo leaf : _leafs) { - boolean _matched = false; - if (leaf instanceof WhitespaceInfo) { - _matched=true; - final boolean equalIndentationChange = (increaseIndentationChange == (decreaseIndentationChange * (-1))); - boolean _and = false; - CommentInfo _trailingComment = ((WhitespaceInfo)leaf).trailingComment(); - boolean _isTrailing = false; - if (_trailingComment!=null) { - _isTrailing=_trailingComment.isTrailing(); - } - if (!_isTrailing) { - _and = false; - } else { - CommentInfo _trailingComment_1 = ((WhitespaceInfo)leaf).trailingComment(); - boolean _isMultiline = false; - if (_trailingComment_1!=null) { - _isMultiline=_trailingComment_1.isMultiline(); - } - boolean _not = (!_isMultiline); - _and = _not; - } - if (_and) { - String _xifexpression = null; - int _offset = ((WhitespaceInfo)leaf).getOffset(); - boolean _equals = (_offset == 0); - if (_equals) { - _xifexpression = ""; - } else { - String _xifexpression_1 = null; - if ((maxNewLines == 0)) { - _xifexpression_1 = null; - } else { - _xifexpression_1 = " "; - } - _xifexpression = _xifexpression_1; - } - final String space = _xifexpression; - int _offset_1 = ((WhitespaceInfo)leaf).getOffset(); - int _length = ((WhitespaceInfo)leaf).getLength(); - RuntimeException _xifexpression_2 = null; - if (trace) { - _xifexpression_2 = new RuntimeException(); - } - WhitespaceData _whitespaceData = new WhitespaceData(_offset_1, _length, 0, 0, _xifexpression_2, space); - result.add(_whitespaceData); - } else { - if ((!applied)) { - int newLines = Math.min(Math.max(leafs.getNewLines(), minNewLines), maxNewLines); - boolean _and_1 = false; - if (!((newLines < 1) && (((WhitespaceInfo)leaf).getOffset() > 0))) { - _and_1 = false; - } else { - boolean _or = false; - CommentInfo _leadingComment = ((WhitespaceInfo)leaf).leadingComment(); - boolean _isMultiline_1 = false; - if (_leadingComment!=null) { - _isMultiline_1=_leadingComment.isMultiline(); - } - if (_isMultiline_1) { - _or = true; - } else { - CommentInfo _trailingComment_2 = ((WhitespaceInfo)leaf).trailingComment(); - boolean _isMultiline_2 = false; - if (_trailingComment_2!=null) { - _isMultiline_2=_trailingComment_2.isMultiline(); - } - _or = _isMultiline_2; - } - _and_1 = _or; - } - if (_and_1) { - newLines = 1; - } - CommentInfo _leadingComment_1 = ((WhitespaceInfo)leaf).leadingComment(); - boolean _endsWithNewLine = false; - if (_leadingComment_1!=null) { - _endsWithNewLine=_leadingComment_1.endsWithNewLine(); - } - if (_endsWithNewLine) { - newLines = (newLines - 1); - } - boolean _and_2 = false; - CommentInfo _leadingComment_2 = ((WhitespaceInfo)leaf).leadingComment(); - boolean _endsWithNewLine_1 = false; - if (_leadingComment_2!=null) { - _endsWithNewLine_1=_leadingComment_2.endsWithNewLine(); - } - boolean _not_1 = (!_endsWithNewLine_1); - if (!_not_1) { - _and_2 = false; - } else { - _and_2 = (newLines == 0); - } - if (_and_2) { - int _offset_2 = ((WhitespaceInfo)leaf).getOffset(); - int _length_1 = ((WhitespaceInfo)leaf).getLength(); - RuntimeException _xifexpression_3 = null; - if (trace) { - _xifexpression_3 = new RuntimeException(); - } - String _xifexpression_4 = null; - int _offset_3 = ((WhitespaceInfo)leaf).getOffset(); - boolean _equals_1 = (_offset_3 == 0); - if (_equals_1) { - _xifexpression_4 = ""; - } else { - String _xifexpression_5 = null; - boolean _containsComment = leafs.containsComment(); - if (_containsComment) { - _xifexpression_5 = null; - } else { - _xifexpression_5 = " "; - } - _xifexpression_4 = _xifexpression_5; - } - WhitespaceData _whitespaceData_1 = new WhitespaceData(_offset_2, _length_1, increaseIndentationChange, decreaseIndentationChange, _xifexpression_3, _xifexpression_4); - result.add(_whitespaceData_1); - } else { - if ((equalIndentationChange && (!Objects.equals(IterableExtensions.lastOrNull(leafs.getLeafs()), leaf)))) { - int _offset_4 = ((WhitespaceInfo)leaf).getOffset(); - int _length_2 = ((WhitespaceInfo)leaf).getLength(); - RuntimeException _xifexpression_6 = null; - if (trace) { - _xifexpression_6 = new RuntimeException(); - } - NewLineData _newLineData = new NewLineData(_offset_4, _length_2, increaseIndentationChange, decreaseIndentationChange, _xifexpression_6, Integer.valueOf(newLines)); - result.add(_newLineData); - } else { - int _offset_5 = ((WhitespaceInfo)leaf).getOffset(); - int _length_3 = ((WhitespaceInfo)leaf).getLength(); - int _xifexpression_7 = (int) 0; - if (equalIndentationChange) { - _xifexpression_7 = 0; - } else { - _xifexpression_7 = increaseIndentationChange; - } - int _xifexpression_8 = (int) 0; - if (equalIndentationChange) { - _xifexpression_8 = 0; - } else { - _xifexpression_8 = decreaseIndentationChange; - } - RuntimeException _xifexpression_9 = null; - if (trace) { - _xifexpression_9 = new RuntimeException(); - } - NewLineData _newLineData_1 = new NewLineData(_offset_5, _length_3, _xifexpression_7, _xifexpression_8, _xifexpression_9, Integer.valueOf(newLines)); - result.add(_newLineData_1); - } - } - applied = true; - } else { - int newLines_1 = 1; - CommentInfo _leadingComment_3 = ((WhitespaceInfo)leaf).leadingComment(); - boolean _endsWithNewLine_2 = false; - if (_leadingComment_3!=null) { - _endsWithNewLine_2=_leadingComment_3.endsWithNewLine(); - } - if (_endsWithNewLine_2) { - newLines_1 = (newLines_1 - 1); - } - if ((equalIndentationChange && (!Objects.equals(IterableExtensions.lastOrNull(leafs.getLeafs()), leaf)))) { - int _offset_6 = ((WhitespaceInfo)leaf).getOffset(); - int _length_4 = ((WhitespaceInfo)leaf).getLength(); - RuntimeException _xifexpression_10 = null; - if (trace) { - _xifexpression_10 = new RuntimeException(); - } - NewLineData _newLineData_2 = new NewLineData(_offset_6, _length_4, increaseIndentationChange, decreaseIndentationChange, _xifexpression_10, Integer.valueOf(newLines_1)); - result.add(_newLineData_2); - } else { - int _offset_7 = ((WhitespaceInfo)leaf).getOffset(); - int _length_5 = ((WhitespaceInfo)leaf).getLength(); - RuntimeException _xifexpression_11 = null; - if (trace) { - _xifexpression_11 = new RuntimeException(); - } - NewLineData _newLineData_3 = new NewLineData(_offset_7, _length_5, 0, 0, _xifexpression_11, Integer.valueOf(newLines_1)); - result.add(_newLineData_3); - } - } - } - } - if (!_matched) { - if (leaf instanceof CommentInfo) { - _matched=true; - } - } - } - _xblockexpression = result; - } - return _xblockexpression; - } - - public Function1> append(final INode node, final Procedure1 init) { - Function1> _xifexpression = null; - boolean _notEquals = (!Objects.equals(node, null)); - if (_notEquals) { - _xifexpression = this.newFormattingData(this._hiddenLeafAccess.getHiddenLeafsAfter(node), init); - } - return _xifexpression; - } - - public Function1> prepend(final INode node, final Procedure1 init) { - Function1> _xifexpression = null; - boolean _notEquals = (!Objects.equals(node, null)); - if (_notEquals) { - _xifexpression = this.newFormattingData(this._hiddenLeafAccess.getHiddenLeafsBefore(node), init); - } - return _xifexpression; - } - - public Function1> surround(final INode node, final Procedure1 init) { - final Function1> _function = (FormattableDocument doc) -> { - ArrayList _xblockexpression = null; - { - final ArrayList result = CollectionLiterals.newArrayList(); - boolean _notEquals = (!Objects.equals(node, null)); - if (_notEquals) { - Iterable _elvis = null; - Function1> _newFormattingData = this.newFormattingData(this._hiddenLeafAccess.getHiddenLeafsBefore(node), init); - Iterable _apply = null; - if (_newFormattingData!=null) { - _apply=_newFormattingData.apply(doc); - } - if (_apply != null) { - _elvis = _apply; - } else { - List _emptyList = CollectionLiterals.emptyList(); - _elvis = _emptyList; - } - Iterables.addAll(result, _elvis); - Iterable _elvis_1 = null; - Function1> _newFormattingData_1 = this.newFormattingData(this._hiddenLeafAccess.getHiddenLeafsAfter(node), init); - Iterable _apply_1 = null; - if (_newFormattingData_1!=null) { - _apply_1=_newFormattingData_1.apply(doc); - } - if (_apply_1 != null) { - _elvis_1 = _apply_1; - } else { - List _emptyList_1 = CollectionLiterals.emptyList(); - _elvis_1 = _emptyList_1; - } - Iterables.addAll(result, _elvis_1); - } - _xblockexpression = result; - } - return _xblockexpression; - }; - return _function; - } - - public Function1> surround(final INode node, final Procedure1 before, final Procedure1 after) { - final Function1> _function = (FormattableDocument doc) -> { - ArrayList _xblockexpression = null; - { - final ArrayList result = CollectionLiterals.newArrayList(); - boolean _notEquals = (!Objects.equals(node, null)); - if (_notEquals) { - Iterable _elvis = null; - Function1> _newFormattingData = this.newFormattingData(this._hiddenLeafAccess.getHiddenLeafsBefore(node), before); - Iterable _apply = null; - if (_newFormattingData!=null) { - _apply=_newFormattingData.apply(doc); - } - if (_apply != null) { - _elvis = _apply; - } else { - List _emptyList = CollectionLiterals.emptyList(); - _elvis = _emptyList; - } - Iterables.addAll(result, _elvis); - Iterable _elvis_1 = null; - Function1> _newFormattingData_1 = this.newFormattingData(this._hiddenLeafAccess.getHiddenLeafsAfter(node), after); - Iterable _apply_1 = null; - if (_newFormattingData_1!=null) { - _apply_1=_newFormattingData_1.apply(doc); - } - if (_apply_1 != null) { - _elvis_1 = _apply_1; - } else { - List _emptyList_1 = CollectionLiterals.emptyList(); - _elvis_1 = _emptyList_1; - } - Iterables.addAll(result, _elvis_1); - } - _xblockexpression = result; - } - return _xblockexpression; - }; - return _function; - } - - protected Function1> newFormattingData(final HiddenLeafs leafs, final PreferenceKey key, final FormattingDataFactory.FormattingDataInit it) { - if (key instanceof BlankLineKey) { - return _newFormattingData(leafs, (BlankLineKey)key, it); - } else if (key instanceof NewLineKey) { - return _newFormattingData(leafs, (NewLineKey)key, it); - } else if (key instanceof NewLineOrPreserveKey) { - return _newFormattingData(leafs, (NewLineOrPreserveKey)key, it); - } else if (key instanceof WhitespaceKey) { - return _newFormattingData(leafs, (WhitespaceKey)key, it); - } else if (key == null) { - return _newFormattingData(leafs, (Void)null, it); - } else if (key != null) { - return _newFormattingData(leafs, key, it); - } else { - throw new IllegalArgumentException("Unhandled parameter types: " + - Arrays.asList(leafs, key, it).toString()); - } - } - } - ''') - } -} \ No newline at end of file diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug428063Test.xtend b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug428063Test.xtend deleted file mode 100644 index 11d2012fea2..00000000000 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug428063Test.xtend +++ /dev/null @@ -1,77 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2014, 2016 itemis AG (http://www.itemis.eu) and others. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * SPDX-License-Identifier: EPL-2.0 - *******************************************************************************/ -package org.eclipse.xtend.core.tests.java8.compiler - -import org.eclipse.xtend.core.tests.compiler.AbstractXtendCompilerTest -import org.eclipse.xtend.core.tests.java8.Java8RuntimeInjectorProvider -import org.eclipse.xtext.testing.InjectWith -import org.junit.Test - -/** - * @author Sebastian Zarnekow - Initial contribution and API - * @author Miro Spoenemann - Copied and adapted to Java 8 output - */ -@InjectWith(Java8RuntimeInjectorProvider) -class CompilerBug428063Test extends AbstractXtendCompilerTest { - - @Test def void testBug_428063_01() { - ''' - class C { - def static void main() { - m[Integer it| ] - } - def static m((T)=>void block) { - } - } - '''.assertCompilesTo(''' - import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; - - @SuppressWarnings("all") - public class C { - public static void main() { - final Procedure1 _function = (Integer it) -> { - }; - C.m(_function); - } - - public static Object m(final Procedure1 block) { - return null; - } - } - ''') - } - - @Test def void testBug_428063_02() { - ''' - class C { - def static void main() { - m[int it| ] - } - def static m((T)=>void block) { - } - } - '''.assertCompilesTo(''' - import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; - - @SuppressWarnings("all") - public class C { - public static void main() { - final Procedure1 _function = (Integer it) -> { - }; - C.m(_function); - } - - public static Object m(final Procedure1 block) { - return null; - } - } - ''') - } - -} \ No newline at end of file diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug432193Test.xtend b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug432193Test.xtend deleted file mode 100644 index d5ea5740355..00000000000 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug432193Test.xtend +++ /dev/null @@ -1,43 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2014, 2016 itemis AG (http://www.itemis.eu) and others. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * SPDX-License-Identifier: EPL-2.0 - *******************************************************************************/ -package org.eclipse.xtend.core.tests.java8.compiler - -import org.eclipse.xtend.core.tests.compiler.AbstractXtendCompilerTest -import org.eclipse.xtend.core.tests.java8.Java8RuntimeInjectorProvider -import org.eclipse.xtext.testing.InjectWith -import org.junit.Test - -/** - * @author Sebastian Zarnekow - Initial contribution and API - * @author Miro Spoenemann - Copied and adapted to Java 8 output - */ -@InjectWith(Java8RuntimeInjectorProvider) -class CompilerBug432193Test extends AbstractXtendCompilerTest { - - @Test def void testBug_432193_01() { - ''' - class C { - D d = [ CharSequence o | - o.subSequence(1, 2) - ] - } - interface D { - def void m(String o) - } - '''.assertCompilesTo(''' - @SuppressWarnings("all") - public class C { - private D d = ((D) (String o) -> { - o.subSequence(1, 2); - }); - } - ''') - } - -} \ No newline at end of file diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug435473Test.xtend b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug435473Test.xtend deleted file mode 100644 index 1fe5643b3b0..00000000000 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug435473Test.xtend +++ /dev/null @@ -1,895 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2014, 2016 itemis AG (http://www.itemis.eu) and others. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * SPDX-License-Identifier: EPL-2.0 - *******************************************************************************/ -package org.eclipse.xtend.core.tests.java8.compiler - -import org.eclipse.xtend.core.tests.java8.Java8RuntimeInjectorProvider -import org.eclipse.xtext.testing.InjectWith -import org.junit.Test - -/** - * @author Sebastian Zarnekow - Initial contribution and API - * @author Miro Spoenemann - Copied and adapted to Java 8 output - */ -@InjectWith(Java8RuntimeInjectorProvider) -class CompilerBug435473Test extends org.eclipse.xtend.core.tests.compiler.CompilerBug435473Test { - - @Test override test_01() { - ''' - import java.util.List - class Outer { - val List> x = #[[|1], [|1.0]] - } - '''.assertCompilesTo(''' - import java.util.Collections; - import java.util.List; - import org.eclipse.xtext.xbase.lib.CollectionLiterals; - import org.eclipse.xtext.xbase.lib.Functions.Function0; - - @SuppressWarnings("all") - public class Outer { - private final List> x = Collections.>unmodifiableList(CollectionLiterals.>newArrayList(((Function0) () -> { - return Integer.valueOf(1); - }), ((Function0) () -> { - return Double.valueOf(1.0); - }))); - } - ''') - } - - @Test override test_02() { - ''' - import java.util.List - class Outer { - val List> x = #[[|1], [|1.0]] - } - '''.assertCompilesTo(''' - import java.util.Collections; - import java.util.List; - import org.eclipse.xtext.xbase.lib.CollectionLiterals; - import org.eclipse.xtext.xbase.lib.Functions.Function0; - - @SuppressWarnings("all") - public class Outer { - private final List> x = Collections.>unmodifiableList(CollectionLiterals.>newArrayList(((Function0) () -> { - return Integer.valueOf(1); - }), ((Function0) () -> { - return Double.valueOf(1.0); - }))); - } - ''') - } - - @Test override test_03() { - ''' - import java.util.List - class Outer { - val List> x = #[[|1], [|1.0]] - } - '''.assertCompilesTo(''' - import java.util.Collections; - import java.util.List; - import org.eclipse.xtext.xbase.lib.CollectionLiterals; - import org.eclipse.xtext.xbase.lib.Functions.Function0; - - @SuppressWarnings("all") - public class Outer { - private final List> x = Collections.>unmodifiableList(CollectionLiterals.>newArrayList(((Function0) () -> { - return Integer.valueOf(1); - }), ((Function0) () -> { - return Double.valueOf(1.0); - }))); - } - ''') - } - - @Test override test_04() { - ''' - import java.util.List - class Outer { - val List> x = #[[|1], [|1.0]] - } - '''.assertCompilesTo(''' - import java.util.Collections; - import java.util.List; - import org.eclipse.xtext.xbase.lib.CollectionLiterals; - import org.eclipse.xtext.xbase.lib.Functions.Function0; - - @SuppressWarnings("all") - public class Outer { - private final List> x = Collections.>unmodifiableList(CollectionLiterals.>newArrayList(((Function0) () -> { - return Integer.valueOf(1); - }), ((Function0) () -> { - return Double.valueOf(1.0); - }))); - } - ''') - } - - @Test override test_05() { - ''' - import java.util.Set - class Outer { - val Set> x = #{ [|1], [|1.0] } - } - '''.assertCompilesTo(''' - import java.util.Collections; - import java.util.Set; - import org.eclipse.xtext.xbase.lib.CollectionLiterals; - import org.eclipse.xtext.xbase.lib.Functions.Function0; - - @SuppressWarnings("all") - public class Outer { - private final Set> x = Collections.>unmodifiableSet(CollectionLiterals.>newHashSet(((Function0) () -> { - return Integer.valueOf(1); - }), ((Function0) () -> { - return Double.valueOf(1.0); - }))); - } - ''') - } - - @Test override test_06() { - ''' - import java.util.Set - class Outer { - val Set> x = #{ [|1], [|1.0] } - } - '''.assertCompilesTo(''' - import java.util.Collections; - import java.util.Set; - import org.eclipse.xtext.xbase.lib.CollectionLiterals; - import org.eclipse.xtext.xbase.lib.Functions.Function0; - - @SuppressWarnings("all") - public class Outer { - private final Set> x = Collections.>unmodifiableSet(CollectionLiterals.>newHashSet(((Function0) () -> { - return Integer.valueOf(1); - }), ((Function0) () -> { - return Double.valueOf(1.0); - }))); - } - ''') - } - - @Test override test_07() { - ''' - import java.util.Set - class Outer { - val Set> x = #{ [|1], [|1.0] } - } - '''.assertCompilesTo(''' - import java.util.Collections; - import java.util.Set; - import org.eclipse.xtext.xbase.lib.CollectionLiterals; - import org.eclipse.xtext.xbase.lib.Functions.Function0; - - @SuppressWarnings("all") - public class Outer { - private final Set> x = Collections.>unmodifiableSet(CollectionLiterals.>newHashSet(((Function0) () -> { - return Integer.valueOf(1); - }), ((Function0) () -> { - return Double.valueOf(1.0); - }))); - } - ''') - } - - @Test override test_08() { - ''' - import java.util.Set - class Outer { - val Set> x = #{ [|1], [|1.0] } - } - '''.assertCompilesTo(''' - import java.util.Collections; - import java.util.Set; - import org.eclipse.xtext.xbase.lib.CollectionLiterals; - import org.eclipse.xtext.xbase.lib.Functions.Function0; - - @SuppressWarnings("all") - public class Outer { - private final Set> x = Collections.>unmodifiableSet(CollectionLiterals.>newHashSet(((Function0) () -> { - return Integer.valueOf(1); - }), ((Function0) () -> { - return Double.valueOf(1.0); - }))); - } - ''') - } - - @Test override test_09() { - ''' - import java.util.List - class Outer { - val List> x = newArrayList([|1], [|1.0]) - } - '''.assertCompilesTo(''' - import java.util.List; - import org.eclipse.xtext.xbase.lib.CollectionLiterals; - import org.eclipse.xtext.xbase.lib.Functions.Function0; - - @SuppressWarnings("all") - public class Outer { - private final List> x = CollectionLiterals.>newArrayList(((Function0) () -> { - return Integer.valueOf(1); - }), ((Function0) () -> { - return Double.valueOf(1.0); - })); - } - ''') - } - - @Test override test_10() { - ''' - import java.util.List - class Outer { - val List> x = newArrayList([|1], [|1.0]) - } - '''.assertCompilesTo(''' - import java.util.List; - import org.eclipse.xtext.xbase.lib.CollectionLiterals; - import org.eclipse.xtext.xbase.lib.Functions.Function0; - - @SuppressWarnings("all") - public class Outer { - private final List> x = CollectionLiterals.>newArrayList(((Function0) () -> { - return Integer.valueOf(1); - }), ((Function0) () -> { - return Double.valueOf(1.0); - })); - } - ''') - } - - @Test override test_11() { - ''' - import java.util.List - class Outer { - val List> x = newArrayList([|1], [|1.0]) - } - '''.assertCompilesTo(''' - import java.util.List; - import org.eclipse.xtext.xbase.lib.CollectionLiterals; - import org.eclipse.xtext.xbase.lib.Functions.Function0; - - @SuppressWarnings("all") - public class Outer { - private final List> x = CollectionLiterals.>newArrayList(((Function0) () -> { - return Integer.valueOf(1); - }), ((Function0) () -> { - return Double.valueOf(1.0); - })); - } - ''') - } - - @Test override test_13() { - ''' - import java.util.List - class Outer { - val x = #[[|1], [|1.0]] - } - '''.assertCompilesTo(''' - import java.util.Collections; - import java.util.List; - import org.eclipse.xtext.xbase.lib.CollectionLiterals; - import org.eclipse.xtext.xbase.lib.Functions.Function0; - - @SuppressWarnings("all") - public class Outer { - private final List> x = Collections.>unmodifiableList(CollectionLiterals.>newArrayList(((Function0) () -> { - return Integer.valueOf(1); - }), ((Function0) () -> { - return Double.valueOf(1.0); - }))); - } - ''') - } - - @Test override test_14() { - ''' - import java.util.List - class Outer { - val x = newArrayList([|1], [|1.0]) - } - '''.assertCompilesTo(''' - import java.util.ArrayList; - import org.eclipse.xtext.xbase.lib.CollectionLiterals; - import org.eclipse.xtext.xbase.lib.Functions.Function0; - - @SuppressWarnings("all") - public class Outer { - private final ArrayList> x = CollectionLiterals.>newArrayList(((Function0) () -> { - return Integer.valueOf(1); - }), ((Function0) () -> { - return Double.valueOf(1.0); - })); - } - ''') - } - - @Test - override test_15() { - ''' - import java.util.List - class Outer { - val List> x = >newArrayList([|1], [|1.0]) - } - '''.assertCompilesTo(''' - import java.util.List; - import org.eclipse.xtext.xbase.lib.CollectionLiterals; - import org.eclipse.xtext.xbase.lib.Functions.Function0; - - @SuppressWarnings("all") - public class Outer { - private final List> x = CollectionLiterals.>newArrayList(((Function0) () -> { - return Integer.valueOf(1); - }), ((Function0) () -> { - return Double.valueOf(1.0); - })); - } - ''') - } - - @Test - override test_16() { - ''' - import java.util.Map - class Outer { - val Map> y = #{'' -> [|1], '' -> [|1.0]} - } - '''.assertCompilesTo(''' - import java.util.Collections; - import java.util.Map; - import org.eclipse.xtext.xbase.lib.CollectionLiterals; - import org.eclipse.xtext.xbase.lib.Functions.Function0; - import org.eclipse.xtext.xbase.lib.Pair; - - @SuppressWarnings("all") - public class Outer { - private final Map> y = Collections.>unmodifiableMap(CollectionLiterals.>newHashMap(Pair.>of("", ((Function0) () -> { - return Integer.valueOf(1); - })), Pair.>of("", ((Function0) () -> { - return Double.valueOf(1.0); - })))); - } - ''') - } - - @Test - override test_17() { - ''' - import java.util.Map - class Outer { - val Map> y = #{null as StringBuilder -> [|1], null as StringBuffer -> [|1.0]} - } - '''.assertCompilesTo(''' - import java.util.Collections; - import java.util.Map; - import org.eclipse.xtext.xbase.lib.CollectionLiterals; - import org.eclipse.xtext.xbase.lib.Functions.Function0; - import org.eclipse.xtext.xbase.lib.Pair; - - @SuppressWarnings("all") - public class Outer { - private final Map> y = Collections.>unmodifiableMap(CollectionLiterals.>newHashMap(Pair.>of(((StringBuilder) null), ((Function0) () -> { - return Integer.valueOf(1); - })), Pair.>of(((StringBuffer) null), ((Function0) () -> { - return Double.valueOf(1.0); - })))); - } - ''') - } - - // TODO this should be a list of Comparator - Would be nice but too much effort ATM - @Test - override test_18() { - ''' - class Outer { - val x = newArrayList( String.CASE_INSENSITIVE_ORDER, [ $0 <=> $1 ] ) - } - '''.assertCompilesTo(''' - import java.util.ArrayList; - import java.util.Comparator; - import org.eclipse.xtext.xbase.lib.CollectionLiterals; - - @SuppressWarnings("all") - public class Outer { - private final ArrayList> x = CollectionLiterals.>newArrayList(String.CASE_INSENSITIVE_ORDER, ((Comparator>>) (Comparable> $0, Comparable> $1) -> { - return ($0.compareTo($1)); - })); - } - ''') - } - - @Test - override test_19() { - ''' - class Outer { - val x = newArrayList( String.CASE_INSENSITIVE_ORDER, [ String s1, s2| s1 <=> s2 ] ) - } - '''.assertCompilesTo(''' - import java.util.ArrayList; - import java.util.Comparator; - import org.eclipse.xtext.xbase.lib.CollectionLiterals; - - @SuppressWarnings("all") - public class Outer { - private final ArrayList> x = CollectionLiterals.>newArrayList(String.CASE_INSENSITIVE_ORDER, ((Comparator) (String s1, String s2) -> { - return (s1.compareTo(s2)); - })); - } - ''') - } - - @Test - override test_31() { - ''' - import java.util.List - class Outer { - interface A {} - interface B extends A{} - interface C extends A{} - val List> x = #[[| null as B], [| null as C]] - } - '''.assertCompilesTo(''' - import java.util.Collections; - import java.util.List; - import org.eclipse.xtext.xbase.lib.CollectionLiterals; - import org.eclipse.xtext.xbase.lib.Functions.Function0; - - @SuppressWarnings("all") - public class Outer { - public interface A { - } - - public interface B extends Outer.A { - } - - public interface C extends Outer.A { - } - - private final List> x = Collections.>unmodifiableList(CollectionLiterals.>newArrayList(((Function0) () -> { - return ((Outer.B) null); - }), ((Function0) () -> { - return ((Outer.C) null); - }))); - } - ''') - } - - @Test - override test_32() { - ''' - import java.util.List - class Outer { - interface A {} - interface B extends A{} - interface C extends A{} - val List> x = #[[| null as B], [| null as C]] - } - '''.assertCompilesTo(''' - import java.util.Collections; - import java.util.List; - import org.eclipse.xtext.xbase.lib.CollectionLiterals; - import org.eclipse.xtext.xbase.lib.Functions.Function0; - - @SuppressWarnings("all") - public class Outer { - public interface A { - } - - public interface B extends Outer.A { - } - - public interface C extends Outer.A { - } - - private final List> x = Collections.>unmodifiableList(CollectionLiterals.>newArrayList(((Function0) () -> { - return ((Outer.B) null); - }), ((Function0) () -> { - return ((Outer.C) null); - }))); - } - ''') - } - - @Test - override test_33() { - ''' - import java.util.List - class Outer { - interface A {} - interface B extends A{} - interface C extends A{} - val List> x = #[[| null as B], [| null as C]] - } - '''.assertCompilesTo(''' - import java.util.Collections; - import java.util.List; - import org.eclipse.xtext.xbase.lib.CollectionLiterals; - import org.eclipse.xtext.xbase.lib.Functions.Function0; - - @SuppressWarnings("all") - public class Outer { - public interface A { - } - - public interface B extends Outer.A { - } - - public interface C extends Outer.A { - } - - private final List> x = Collections.>unmodifiableList(CollectionLiterals.>newArrayList(((Function0) () -> { - return ((Outer.B) null); - }), ((Function0) () -> { - return ((Outer.C) null); - }))); - } - ''') - } - - @Test - override test_34() { - ''' - import java.util.List - class Outer { - interface A {} - interface B extends A{} - interface C extends A{} - val List> x = #[[| null as B], [| null as C]] - } - '''.assertCompilesTo(''' - import java.util.Collections; - import java.util.List; - import org.eclipse.xtext.xbase.lib.CollectionLiterals; - import org.eclipse.xtext.xbase.lib.Functions.Function0; - - @SuppressWarnings("all") - public class Outer { - public interface A { - } - - public interface B extends Outer.A { - } - - public interface C extends Outer.A { - } - - private final List> x = Collections.>unmodifiableList(CollectionLiterals.>newArrayList(((Function0) () -> { - return ((Outer.B) null); - }), ((Function0) () -> { - return ((Outer.C) null); - }))); - } - ''') - } - - @Test - override test_35() { - ''' - import java.util.Set - class Outer { - interface A {} - interface B extends A{} - interface C extends A{} - val Set> x = #{ [| null as B], [| null as C] } - } - '''.assertCompilesTo(''' - import java.util.Collections; - import java.util.Set; - import org.eclipse.xtext.xbase.lib.CollectionLiterals; - import org.eclipse.xtext.xbase.lib.Functions.Function0; - - @SuppressWarnings("all") - public class Outer { - public interface A { - } - - public interface B extends Outer.A { - } - - public interface C extends Outer.A { - } - - private final Set> x = Collections.>unmodifiableSet(CollectionLiterals.>newHashSet(((Function0) () -> { - return ((Outer.B) null); - }), ((Function0) () -> { - return ((Outer.C) null); - }))); - } - ''') - } - - @Test - override test_36() { - ''' - import java.util.Set - class Outer { - interface A {} - interface B extends A{} - interface C extends A{} - val Set> x = #{ [| null as B], [| null as C] } - } - '''.assertCompilesTo(''' - import java.util.Collections; - import java.util.Set; - import org.eclipse.xtext.xbase.lib.CollectionLiterals; - import org.eclipse.xtext.xbase.lib.Functions.Function0; - - @SuppressWarnings("all") - public class Outer { - public interface A { - } - - public interface B extends Outer.A { - } - - public interface C extends Outer.A { - } - - private final Set> x = Collections.>unmodifiableSet(CollectionLiterals.>newHashSet(((Function0) () -> { - return ((Outer.B) null); - }), ((Function0) () -> { - return ((Outer.C) null); - }))); - } - ''') - } - - @Test - override test_37() { - ''' - import java.util.Set - class Outer { - interface A {} - interface B extends A{} - interface C extends A{} - val Set> x = #{ [| null as B], [| null as C] } - } - '''.assertCompilesTo(''' - import java.util.Collections; - import java.util.Set; - import org.eclipse.xtext.xbase.lib.CollectionLiterals; - import org.eclipse.xtext.xbase.lib.Functions.Function0; - - @SuppressWarnings("all") - public class Outer { - public interface A { - } - - public interface B extends Outer.A { - } - - public interface C extends Outer.A { - } - - private final Set> x = Collections.>unmodifiableSet(CollectionLiterals.>newHashSet(((Function0) () -> { - return ((Outer.B) null); - }), ((Function0) () -> { - return ((Outer.C) null); - }))); - } - ''') - } - - @Test - override test_38() { - ''' - import java.util.Set - class Outer { - interface A {} - interface B extends A{} - interface C extends A{} - val Set> x = #{ [| null as B], [| null as C] } - } - '''.assertCompilesTo(''' - import java.util.Collections; - import java.util.Set; - import org.eclipse.xtext.xbase.lib.CollectionLiterals; - import org.eclipse.xtext.xbase.lib.Functions.Function0; - - @SuppressWarnings("all") - public class Outer { - public interface A { - } - - public interface B extends Outer.A { - } - - public interface C extends Outer.A { - } - - private final Set> x = Collections.>unmodifiableSet(CollectionLiterals.>newHashSet(((Function0) () -> { - return ((Outer.B) null); - }), ((Function0) () -> { - return ((Outer.C) null); - }))); - } - ''') - } - - @Test - override test_39() { - ''' - import java.util.List - class Outer { - interface A {} - interface B extends A{} - interface C extends A{} - val List> x = newArrayList([| null as B], [| null as C]) - } - '''.assertCompilesTo(''' - import java.util.List; - import org.eclipse.xtext.xbase.lib.CollectionLiterals; - import org.eclipse.xtext.xbase.lib.Functions.Function0; - - @SuppressWarnings("all") - public class Outer { - public interface A { - } - - public interface B extends Outer.A { - } - - public interface C extends Outer.A { - } - - private final List> x = CollectionLiterals.>newArrayList(((Function0) () -> { - return ((Outer.B) null); - }), ((Function0) () -> { - return ((Outer.C) null); - })); - } - ''') - } - - @Test - override test_40() { - ''' - import java.util.List - class Outer { - interface A {} - interface B extends A{} - interface C extends A{} - val List> x = newArrayList([| null as B], [| null as C]) - } - '''.assertCompilesTo(''' - import java.util.List; - import org.eclipse.xtext.xbase.lib.CollectionLiterals; - import org.eclipse.xtext.xbase.lib.Functions.Function0; - - @SuppressWarnings("all") - public class Outer { - public interface A { - } - - public interface B extends Outer.A { - } - - public interface C extends Outer.A { - } - - private final List> x = CollectionLiterals.>newArrayList(((Function0) () -> { - return ((Outer.B) null); - }), ((Function0) () -> { - return ((Outer.C) null); - })); - } - ''') - } - - @Test - override test_41() { - ''' - import java.util.List - class Outer { - interface A {} - interface B extends A{} - interface C extends A{} - val List> x = newArrayList([| null as B], [| null as C]) - } - '''.assertCompilesTo(''' - import java.util.List; - import org.eclipse.xtext.xbase.lib.CollectionLiterals; - import org.eclipse.xtext.xbase.lib.Functions.Function0; - - @SuppressWarnings("all") - public class Outer { - public interface A { - } - - public interface B extends Outer.A { - } - - public interface C extends Outer.A { - } - - private final List> x = CollectionLiterals.>newArrayList(((Function0) () -> { - return ((Outer.B) null); - }), ((Function0) () -> { - return ((Outer.C) null); - })); - } - ''') - } - - @Test - override test_43() { - ''' - import java.util.List - class Outer { - interface A {} - interface B extends A{} - interface C extends A{} - val x = #[[| null as B], [| null as C]] - } - '''.assertCompilesTo(''' - import java.util.Collections; - import java.util.List; - import org.eclipse.xtext.xbase.lib.CollectionLiterals; - import org.eclipse.xtext.xbase.lib.Functions.Function0; - - @SuppressWarnings("all") - public class Outer { - public interface A { - } - - public interface B extends Outer.A { - } - - public interface C extends Outer.A { - } - - private final List> x = Collections.>unmodifiableList(CollectionLiterals.>newArrayList(((Function0) () -> { - return ((Outer.B) null); - }), ((Function0) () -> { - return ((Outer.C) null); - }))); - } - ''') - } - - @Test - override test_44() { - ''' - import java.util.List - class Outer { - interface A {} - interface B extends A{} - interface C extends A{} - val x = newArrayList([| null as B], [| null as C]) - } - '''.assertCompilesTo(''' - import java.util.ArrayList; - import org.eclipse.xtext.xbase.lib.CollectionLiterals; - import org.eclipse.xtext.xbase.lib.Functions.Function0; - - @SuppressWarnings("all") - public class Outer { - public interface A { - } - - public interface B extends Outer.A { - } - - public interface C extends Outer.A { - } - - private final ArrayList> x = CollectionLiterals.>newArrayList(((Function0) () -> { - return ((Outer.B) null); - }), ((Function0) () -> { - return ((Outer.C) null); - })); - } - ''') - } - -} \ No newline at end of file diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug436230Test.xtend b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug436230Test.xtend deleted file mode 100644 index 95c47df4736..00000000000 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug436230Test.xtend +++ /dev/null @@ -1,154 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2014, 2016 itemis AG (http://www.itemis.eu) and others. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * SPDX-License-Identifier: EPL-2.0 - *******************************************************************************/ -package org.eclipse.xtend.core.tests.java8.compiler - -import org.eclipse.xtend.core.tests.compiler.AbstractXtendCompilerTest -import org.eclipse.xtend.core.tests.java8.Java8RuntimeInjectorProvider -import org.eclipse.xtext.testing.InjectWith -import org.junit.Test - -/** - * @author Sebastian Zarnekow - Initial contribution and API - * @author Miro Spoenemann - Copied and adapted to Java 8 output - */ -@InjectWith(Java8RuntimeInjectorProvider) -class CompilerBug436230Test extends AbstractXtendCompilerTest { - - @Test def test_01() { - ''' - import java.util.List - class Foo { - val List list = newArrayList - def foo(List source) { - list += source.map[''] - } - } - '''.assertCompilesTo(''' - import com.google.common.collect.Iterables; - import java.util.List; - import org.eclipse.xtext.xbase.lib.CollectionLiterals; - import org.eclipse.xtext.xbase.lib.Functions.Function1; - import org.eclipse.xtext.xbase.lib.ListExtensions; - - @SuppressWarnings("all") - public class Foo { - private final List list = CollectionLiterals.newArrayList(); - - public boolean foo(final List source) { - final Function1 _function = (Object it) -> { - return ""; - }; - List _map = ListExtensions.map(source, _function); - return Iterables.addAll(this.list, _map); - } - } - ''') - } - - @Test def test_02() { - ''' - import java.util.List - class C { - def m() { - val List res = null - val Iterable obj = null - res += obj.map[""] - } - } - '''.assertCompilesTo(''' - import com.google.common.collect.Iterables; - import java.util.List; - import org.eclipse.xtext.xbase.lib.Functions.Function1; - import org.eclipse.xtext.xbase.lib.IterableExtensions; - - @SuppressWarnings("all") - public class C { - public boolean m() { - boolean _xblockexpression = false; - { - final List res = null; - final Iterable obj = null; - final Function1 _function = (Object it) -> { - return ""; - }; - Iterable _map = IterableExtensions.map(obj, _function); - _xblockexpression = Iterables.addAll(res, _map); - } - return _xblockexpression; - } - } - ''') - } - - @Test def test_03() { - ''' - import java.util.List - class C { - def m() { - val List res = null - val Iterable obj = null - res += obj.map[""] - } - } - '''.assertCompilesTo(''' - import com.google.common.collect.Iterables; - import java.util.List; - import org.eclipse.xtext.xbase.lib.Functions.Function1; - import org.eclipse.xtext.xbase.lib.IterableExtensions; - - @SuppressWarnings("all") - public class C { - public boolean m() { - boolean _xblockexpression = false; - { - final List res = null; - final Iterable obj = null; - final Function1 _function = (Object it) -> { - return ""; - }; - Iterable _map = IterableExtensions.map(obj, _function); - _xblockexpression = Iterables.addAll(res, _map); - } - return _xblockexpression; - } - } - ''') - } - - @Test def test_04() { - ''' - import java.util.List - class C { - def Iterable m() { - val Iterable obj = null - obj.map[""] - } - } - '''.assertCompilesTo(''' - import org.eclipse.xtext.xbase.lib.Functions.Function1; - import org.eclipse.xtext.xbase.lib.IterableExtensions; - - @SuppressWarnings("all") - public class C { - public Iterable m() { - Iterable _xblockexpression = null; - { - final Iterable obj = null; - final Function1 _function = (Object it) -> { - return ""; - }; - _xblockexpression = IterableExtensions.map(obj, _function); - } - return _xblockexpression; - } - } - ''') - } - -} \ No newline at end of file diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug440906Test.xtend b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug440906Test.xtend deleted file mode 100644 index 642dcf98ce4..00000000000 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug440906Test.xtend +++ /dev/null @@ -1,108 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2014, 2016 itemis AG (http://www.itemis.eu) and others. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * SPDX-License-Identifier: EPL-2.0 - *******************************************************************************/ -package org.eclipse.xtend.core.tests.java8.compiler - -import org.eclipse.xtend.core.tests.compiler.AbstractXtendCompilerTest -import org.eclipse.xtend.core.tests.java8.Java8RuntimeInjectorProvider -import org.eclipse.xtext.testing.InjectWith -import org.junit.Test - -/** - * @author Sebastian Zarnekow - Initial contribution and API - * @author Miro Spoenemann - Copied and adapted to Java 8 output - */ -@InjectWith(Java8RuntimeInjectorProvider) -class CompilerBug440906Test extends AbstractXtendCompilerTest { - - @Test def test_01() { - ''' - class C { - def m() { - [ Object a, Object b | 1 ] - } - - def m2() { - #[].sortWith(m) - } - } - '''.assertCompilesTo(''' - import java.util.Collections; - import java.util.Comparator; - import java.util.List; - import org.eclipse.xtext.xbase.lib.CollectionLiterals; - import org.eclipse.xtext.xbase.lib.Functions.Function2; - import org.eclipse.xtext.xbase.lib.IterableExtensions; - - @SuppressWarnings("all") - public class C { - public Function2 m() { - final Function2 _function = (Object a, Object b) -> { - return Integer.valueOf(1); - }; - return _function; - } - - public List m2() { - return IterableExtensions.sortWith(Collections.unmodifiableList(CollectionLiterals.newArrayList()), new Comparator() { - public int compare(Object arg0, Object arg1) { - return C.this.m().apply(arg0, arg1); - } - }); - } - } - ''') - } - - @Test - def test_02() { - ''' - class C { - def m() { - [ Object a, Object b | 1 ] - } - - def m2() { - #[].sortWith({toString m}) - } - } - '''.assertCompilesTo(''' - import java.util.Collections; - import java.util.Comparator; - import java.util.List; - import org.eclipse.xtext.xbase.lib.CollectionLiterals; - import org.eclipse.xtext.xbase.lib.Functions.Function2; - import org.eclipse.xtext.xbase.lib.IterableExtensions; - - @SuppressWarnings("all") - public class C { - public Function2 m() { - final Function2 _function = (Object a, Object b) -> { - return Integer.valueOf(1); - }; - return _function; - } - - public List m2() { - Function2 _xblockexpression = null; - { - this.toString(); - _xblockexpression = this.m(); - } - final Function2 _final_xblockexpression = _xblockexpression; - return IterableExtensions.sortWith(Collections.unmodifiableList(CollectionLiterals.newArrayList()), new Comparator() { - public int compare(Object arg0, Object arg1) { - return _final_xblockexpression.apply(arg0, arg1); - } - }); - } - } - ''') - } - -} \ No newline at end of file diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug445487Test.xtend b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug445487Test.xtend deleted file mode 100644 index 599a15e2b99..00000000000 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug445487Test.xtend +++ /dev/null @@ -1,201 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2014, 2016 itemis AG (http://www.itemis.eu) and others. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * SPDX-License-Identifier: EPL-2.0 - *******************************************************************************/ -package org.eclipse.xtend.core.tests.java8.compiler - -import org.eclipse.xtend.core.tests.java8.Java8RuntimeInjectorProvider -import org.eclipse.xtext.testing.InjectWith -import org.junit.Test - -/** - * @author Sebastian Zarnekow - Initial contribution and API - * @author Miro Spoenemann - Copied and adapted to Java 8 output - */ -@InjectWith(Java8RuntimeInjectorProvider) -class CompilerBug445487Test extends org.eclipse.xtend.core.tests.compiler.CompilerBug445487Test { - - @Test override test_01() { - ''' - import com.google.inject.Provider - import org.antlr.runtime.Lexer - import org.eclipse.xtend.core.parser.antlr.internal.InternalXtendLexer - class C { - Provider lexerProvider= [return new InternalXtendLexer(null)] - } - '''.assertCompilesTo(''' - import com.google.inject.Provider; - import org.antlr.runtime.Lexer; - import org.eclipse.xtend.core.parser.antlr.internal.InternalXtendLexer; - - @SuppressWarnings("all") - public class C { - private Provider lexerProvider = ((Provider) () -> { - return new InternalXtendLexer(null); - }); - } - ''') - } - - @Test override test_02() { - ''' - import com.google.inject.Provider - import org.antlr.runtime.Lexer - import org.eclipse.xtend.core.parser.antlr.internal.InternalXtendLexer - class C { - Provider lexerProvider= [return new InternalXtendLexer(null)] - } - '''.assertCompilesTo(''' - import com.google.inject.Provider; - import org.antlr.runtime.Lexer; - import org.eclipse.xtend.core.parser.antlr.internal.InternalXtendLexer; - - @SuppressWarnings("all") - public class C { - private Provider lexerProvider = ((Provider) () -> { - return new InternalXtendLexer(null); - }); - } - ''') - } - - @Test override test_03() { - ''' - import com.google.inject.Provider - import org.antlr.runtime.Lexer - import org.eclipse.xtend.core.parser.antlr.internal.InternalXtendLexer - class C { - Provider lexerProvider= [return new InternalXtendLexer(null)] - } - '''.assertCompilesTo(''' - import com.google.inject.Provider; - import org.antlr.runtime.Lexer; - import org.eclipse.xtend.core.parser.antlr.internal.InternalXtendLexer; - - @SuppressWarnings("all") - public class C { - private Provider lexerProvider = ((Provider) () -> { - return new InternalXtendLexer(null); - }); - } - ''') - } - - @Test override test_04() { - ''' - import com.google.inject.Provider - import org.antlr.runtime.Lexer - import org.eclipse.xtend.core.parser.antlr.internal.InternalXtendLexer - class C { - Provider lexerProvider= [|return new InternalXtendLexer(null)] as Provider - } - '''.assertCompilesTo(''' - import com.google.inject.Provider; - import org.antlr.runtime.Lexer; - import org.eclipse.xtend.core.parser.antlr.internal.InternalXtendLexer; - import org.eclipse.xtext.xbase.lib.Functions.Function0; - - @SuppressWarnings("all") - public class C { - private Provider lexerProvider = ((Provider) new Provider() { - public Lexer get() { - return ((Function0) () -> { - return new InternalXtendLexer(null); - }).apply(); - } - }); - } - ''') - } - - @Test override test_05() { - ''' - import com.google.inject.Provider - import org.antlr.runtime.Lexer - import org.eclipse.xtend.core.parser.antlr.internal.InternalXtendLexer - class C { - Provider lexerProvider= [|return new InternalXtendLexer(null)] as ()=>Lexer - } - '''.assertCompilesTo(''' - import com.google.inject.Provider; - import org.antlr.runtime.Lexer; - import org.eclipse.xtend.core.parser.antlr.internal.InternalXtendLexer; - import org.eclipse.xtext.xbase.lib.Functions.Function0; - - @SuppressWarnings("all") - public class C { - private Provider lexerProvider = new Provider() { - public Lexer get() { - return ((Function0) ((Function0) () -> { - return new InternalXtendLexer(null); - })).apply(); - } - }; - } - ''') - } - - @Test override test_06() { - assertCompilesTo(''' - import com.google.inject.Provider - import org.antlr.runtime.Lexer - import org.eclipse.xtend.core.parser.antlr.internal.InternalXtendLexer - class C { - Provider lexerProvider= [return new InternalXtendLexer(null)] as Provider - } - ''', ''' - import com.google.inject.Provider; - import org.antlr.runtime.Lexer; - import org.eclipse.xtend.core.parser.antlr.internal.InternalXtendLexer; - import org.eclipse.xtext.xbase.lib.Functions.Function1; - - @SuppressWarnings("all") - public class C { - private Provider lexerProvider = ((Provider) new Provider() { - public Lexer get() { - return ((Function1) (Object it) -> { - return new InternalXtendLexer(null); - }).apply(null); - } - }); - } - ''') - } - - @Test override test_07() { - assertCompilesTo(''' - import com.google.inject.Provider - import org.antlr.runtime.Lexer - import org.eclipse.xtend.core.parser.antlr.internal.InternalXtendLexer - class C { - Provider lexerProvider= [return new InternalXtendLexer(null)] as ()=>Lexer - } - ''', ''' - import com.google.inject.Provider; - import org.antlr.runtime.Lexer; - import org.eclipse.xtend.core.parser.antlr.internal.InternalXtendLexer; - import org.eclipse.xtext.xbase.lib.Functions.Function0; - import org.eclipse.xtext.xbase.lib.Functions.Function1; - - @SuppressWarnings("all") - public class C { - private Provider lexerProvider = new Provider() { - public Lexer get() { - return ((Function0) new Function0() { - public Lexer apply() { - return ((Function1) (Object it) -> { - return new InternalXtendLexer(null); - }).apply(null); - } - }).apply(); - } - }; - } - ''') - } - -} \ No newline at end of file diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug447516Test.xtend b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug447516Test.xtend deleted file mode 100644 index 02a8329f266..00000000000 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug447516Test.xtend +++ /dev/null @@ -1,114 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2014, 2016 itemis AG (http://www.itemis.eu) and others. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * SPDX-License-Identifier: EPL-2.0 - *******************************************************************************/ -package org.eclipse.xtend.core.tests.java8.compiler - -import org.eclipse.xtend.core.tests.compiler.AbstractXtendCompilerTest -import org.eclipse.xtend.core.tests.java8.Java8RuntimeInjectorProvider -import org.eclipse.xtext.testing.InjectWith -import org.junit.Test - -/** - * @author Sebastian Zarnekow - Initial contribution and API - * @author Miro Spoenemann - Copied and adapted to Java 8 output - */ -@InjectWith(Java8RuntimeInjectorProvider) -class CompilerBug447516Test extends AbstractXtendCompilerTest { - - @Test def test_01() { - ''' - import org.eclipse.xtext.util.concurrent.IReadAccess - class C { - val IReadAccess readAccess = [ - return it.exec('') - ] - } - '''.assertCompilesTo(''' - import org.eclipse.xtext.util.concurrent.IReadAccess; - import org.eclipse.xtext.util.concurrent.IUnitOfWork; - import org.eclipse.xtext.xbase.lib.Exceptions; - - @SuppressWarnings("all") - public class C { - private final IReadAccess readAccess = new IReadAccess() { - @Override - public Result readOnly(final IUnitOfWork it) { - try { - return it.exec(""); - } catch (Throwable _e) { - throw Exceptions.sneakyThrow(_e); - } - } - }; - } - ''') - } - - @Test def test_02() { - ''' - import org.eclipse.xtext.util.concurrent.IReadAccess - class C { - val I readAccess = [ - return it.apply('') - ] - - interface I

{ - def T exec((P)=>T arg) - } - } - '''.assertCompilesTo(''' - import org.eclipse.xtext.xbase.lib.Functions.Function1; - - @SuppressWarnings("all") - public class C { - public interface I

{ - T exec(final Function1 arg); - } - - private final C.I readAccess = new C.I() { - @Override - public T exec(final Function1 it) { - return it.apply(""); - } - }; - } - ''') - } - - @Test def test_03() { - ''' - import org.eclipse.xtext.util.concurrent.IReadAccess - class C { - val I i = [ - return $1.apply('') - ] - - interface I { - def T exec(W w, (P)=>T arg) - } - } - '''.assertCompilesTo(''' - import org.eclipse.xtext.xbase.lib.Functions.Function1; - - @SuppressWarnings("all") - public class C { - public interface I

{ - T exec(final W w, final Function1 arg); - } - - private final C.I i = new C.I() { - @Override - public T exec(final String $0, final Function1 $1) { - return $1.apply(""); - } - }; - } - ''') - } - -} \ No newline at end of file diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug457333Test.xtend b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug457333Test.xtend deleted file mode 100644 index 4b630d44c46..00000000000 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug457333Test.xtend +++ /dev/null @@ -1,100 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2015, 2016 itemis AG (http://www.itemis.eu) and others. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * SPDX-License-Identifier: EPL-2.0 - *******************************************************************************/ -package org.eclipse.xtend.core.tests.java8.compiler - -import org.eclipse.xtend.core.tests.compiler.AbstractXtendCompilerTest -import org.eclipse.xtend.core.tests.java8.Java8RuntimeInjectorProvider -import org.eclipse.xtext.testing.InjectWith -import org.junit.Test - -/** - * @author Sebastian Zarnekow - Initial contribution and API - * @author Miro Spoenemann - Copied and adapted to Java 8 output - */ -@InjectWith(Java8RuntimeInjectorProvider) -class CompilerBug457333Test extends AbstractXtendCompilerTest { - - @Test def test_01() { - ''' - import java.util.Map - import org.eclipse.xtext.xbase.lib.Functions.Function0 - - class XtendPlugin implements (String)=>void { - - override apply(String project) { - #[''].forEach [ sourceSet | - create('', Object) [ - conventionMapping( - #{ - "classpath" -> [|sourceSet.charAt(0)], - "bootClasspath" -> [|sourceSet.charAt(0)] - }) - ] - ] - } - - static def void conventionMapping(Object task, Map> mappings) { - } - - def void create(String s, Class c, Action a) {} - - def void all(Action action) {} - - interface Action { - def void exec(T t) - } - } - '''.assertCompilesTo(''' - import java.util.Collections; - import java.util.Map; - import java.util.function.Consumer; - import org.eclipse.xtext.xbase.lib.CollectionLiterals; - import org.eclipse.xtext.xbase.lib.Functions.Function0; - import org.eclipse.xtext.xbase.lib.Pair; - import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; - - @SuppressWarnings("all") - public class XtendPlugin implements Procedure1 { - public interface Action { - void exec(final T t); - } - - @Override - public void apply(final String project) { - final Consumer _function = (String sourceSet) -> { - final XtendPlugin.Action _function_1 = (Object it) -> { - final Function0 _function_2 = () -> { - return Character.valueOf(sourceSet.charAt(0)); - }; - Pair> _mappedTo = Pair.>of("classpath", _function_2); - final Function0 _function_3 = () -> { - return Character.valueOf(sourceSet.charAt(0)); - }; - Pair> _mappedTo_1 = Pair.>of("bootClasspath", _function_3); - XtendPlugin.conventionMapping(it, - Collections.>unmodifiableMap(CollectionLiterals.>newHashMap(_mappedTo, _mappedTo_1))); - }; - this.create("", Object.class, _function_1); - }; - Collections.unmodifiableList(CollectionLiterals.newArrayList("")).forEach(_function); - } - - public static void conventionMapping(final Object task, final Map> mappings) { - } - - public void create(final String s, final Class c, final XtendPlugin.Action a) { - } - - public void all(final XtendPlugin.Action action) { - } - } - ''') - } - -} \ No newline at end of file diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug457346Test.xtend b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug457346Test.xtend deleted file mode 100644 index 94cdb794de7..00000000000 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug457346Test.xtend +++ /dev/null @@ -1,311 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2015, 2016 itemis AG (http://www.itemis.eu) and others. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * SPDX-License-Identifier: EPL-2.0 - *******************************************************************************/ -package org.eclipse.xtend.core.tests.java8.compiler - -import org.eclipse.xtend.core.tests.compiler.AbstractXtendCompilerTest -import org.eclipse.xtend.core.tests.java8.Java8RuntimeInjectorProvider -import org.eclipse.xtext.testing.InjectWith -import org.junit.Test - -/** - * @author Sebastian Zarnekow - Initial contribution and API - * @author Miro Spoenemann - Copied and adapted to Java 8 output - */ -@InjectWith(Java8RuntimeInjectorProvider) -class CompilerBug457346Test extends AbstractXtendCompilerTest { - - @Test def test_01() { - ''' - import com.google.common.collect.Ordering - class C { - def m() { - #['a', 'aa', 'aaa'].sortWith(Ordering.natural.onResultOf [ String s| s.length ].onResultOf[]) - } - } - '''.assertCompilesTo(''' - import com.google.common.base.Function; - import com.google.common.collect.Ordering; - import java.util.Collections; - import java.util.List; - import org.eclipse.xtext.xbase.lib.CollectionLiterals; - import org.eclipse.xtext.xbase.lib.IterableExtensions; - - @SuppressWarnings("all") - public class C { - public List m() { - final Function _function = (String s) -> { - return Integer.valueOf(s.length()); - }; - final Function _function_1 = (String it) -> { - return null; - }; - return IterableExtensions.sortWith(Collections.unmodifiableList(CollectionLiterals.newArrayList("a", "aa", "aaa")), Ordering.natural().onResultOf(_function).onResultOf(_function_1)); - } - } - ''') - } - - @Test def test_02() { - ''' - import com.google.common.collect.Ordering - class C { - def m(Sortable sortMe) { - sortMe.sort(Ordering.natural.onResultOf [ String s| s.length ].onResultOf[]) - } - - interface Sortable extends Iterable { - def void sort(java.util.Comparator c) - } - } - '''.assertCompilesTo(''' - import com.google.common.base.Function; - import com.google.common.collect.Ordering; - import java.util.Comparator; - - @SuppressWarnings("all") - public class C { - public interface Sortable extends Iterable { - void sort(final Comparator c); - } - - public void m(final C.Sortable sortMe) { - final Function _function = (String s) -> { - return Integer.valueOf(s.length()); - }; - final Function _function_1 = (String it) -> { - return null; - }; - sortMe.sort(Ordering.natural().onResultOf(_function).onResultOf(_function_1)); - } - } - ''') - } - - @Test def test_03() { - ''' - class C { - def m(Sortable sortMe) { - sortMe.sort(MyComparator.comparingInt[String s| s.length].thenComparing[String s | s]) - } - - interface Sortable extends Iterable { - def void sort(MyComparator c) - } - static abstract class MyComparator { - def static MyComparator comparingInt(ToIntFunction fun) {} - def > MyComparator thenComparing((T)=>U f) {} - } - interface ToIntFunction { - def int apply(T t) - } - } - '''.assertCompilesTo(''' - import org.eclipse.xtext.xbase.lib.Functions.Function1; - - @SuppressWarnings("all") - public class C { - public interface Sortable extends Iterable { - void sort(final C.MyComparator c); - } - - public static abstract class MyComparator { - public static C.MyComparator comparingInt(final C.ToIntFunction fun) { - return null; - } - - public > C.MyComparator thenComparing(final Function1 f) { - return null; - } - } - - public interface ToIntFunction { - int apply(final T t); - } - - public void m(final C.Sortable sortMe) { - final C.ToIntFunction _function = (String s) -> { - return s.length(); - }; - final Function1 _function_1 = (String s) -> { - return s; - }; - sortMe.sort(C.MyComparator.comparingInt(_function).thenComparing(_function_1)); - } - } - ''') - } - - @Test def test_04() { - ''' - class C { - def m(Sortable sortMe) { - sortMe.sort(MyComparator.comparingInt[String s| s.length].thenComparing[toUpperCase]) - } - - interface Sortable extends Iterable { - def void sort(MyComparator c) - } - static abstract class MyComparator { - def static MyComparator comparingInt(ToIntFunction fun) {} - def > MyComparator thenComparing((T)=>U f) {} - } - interface ToIntFunction { - def int apply(T t) - } - } - '''.assertCompilesTo(''' - import org.eclipse.xtext.xbase.lib.Functions.Function1; - - @SuppressWarnings("all") - public class C { - public interface Sortable extends Iterable { - void sort(final C.MyComparator c); - } - - public static abstract class MyComparator { - public static C.MyComparator comparingInt(final C.ToIntFunction fun) { - return null; - } - - public > C.MyComparator thenComparing(final Function1 f) { - return null; - } - } - - public interface ToIntFunction { - int apply(final T t); - } - - public void m(final C.Sortable sortMe) { - final C.ToIntFunction _function = (String s) -> { - return s.length(); - }; - final Function1 _function_1 = (String it) -> { - return it.toUpperCase(); - }; - sortMe.sort(C.MyComparator.comparingInt(_function).thenComparing(_function_1)); - } - } - ''') - } - - @Test def test_05() { - ''' - class C { - def m(Sortable sortMe) { - sortMe.sort(MyComparator.comparingInt[String s| s.length].thenComparing[it]) - } - - interface Sortable extends Iterable { - def void sort(MyComparator c) - } - static abstract class MyComparator { - def static MyComparator comparingInt(ToIntFunction fun) {} - def > MyComparator thenComparing((T)=>U f) {} - } - interface ToIntFunction { - def int apply(T t) - } - } - '''.assertCompilesTo(''' - import org.eclipse.xtext.xbase.lib.Functions.Function1; - - @SuppressWarnings("all") - public class C { - public interface Sortable extends Iterable { - void sort(final C.MyComparator c); - } - - public static abstract class MyComparator { - public static C.MyComparator comparingInt(final C.ToIntFunction fun) { - return null; - } - - public > C.MyComparator thenComparing(final Function1 f) { - return null; - } - } - - public interface ToIntFunction { - int apply(final T t); - } - - public void m(final C.Sortable sortMe) { - final C.ToIntFunction _function = (String s) -> { - return s.length(); - }; - final Function1 _function_1 = (String it) -> { - return it; - }; - sortMe.sort(C.MyComparator.comparingInt(_function).thenComparing(_function_1)); - } - } - ''') - } - - @Test def test_06() { - ''' - class C { - def m() { - MyComparator.comparingInt [String s| s.length].thenComparing[it] - } - - static abstract class MyComparator { - def static MyComparator comparingInt(ToIntFunction fun) {} - def > MyComparator thenComparing( - Function keyExtractor, - MyComparator keyComparator) - def MyComparator thenComparing(MyComparator other) - def > MyComparator thenComparing( - Function keyExtractor) - } - interface ToIntFunction { - def int apply(T t) - } - interface Function { - def R apply(T t) - } - } - '''.assertCompilesTo(''' - @SuppressWarnings("all") - public class C { - public static abstract class MyComparator { - public static C.MyComparator comparingInt(final C.ToIntFunction fun) { - return null; - } - - public abstract > C.MyComparator thenComparing(final C.Function keyExtractor, final C.MyComparator keyComparator); - - public abstract C.MyComparator thenComparing(final C.MyComparator other); - - public abstract > C.MyComparator thenComparing(final C.Function keyExtractor); - } - - public interface ToIntFunction { - int apply(final T t); - } - - public interface Function { - R apply(final T t); - } - - public C.MyComparator m() { - final C.ToIntFunction _function = (String s) -> { - return s.length(); - }; - final C.Function _function_1 = (String it) -> { - return it; - }; - return C.MyComparator.comparingInt(_function).thenComparing(_function_1); - } - } - ''') - } - -} \ No newline at end of file diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug457539Test.xtend b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug457539Test.xtend deleted file mode 100644 index 3a2c2c3b85d..00000000000 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug457539Test.xtend +++ /dev/null @@ -1,406 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2015, 2016 itemis AG (http://www.itemis.eu) and others. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * SPDX-License-Identifier: EPL-2.0 - *******************************************************************************/ -package org.eclipse.xtend.core.tests.java8.compiler - -import org.eclipse.xtend.core.tests.java8.Java8RuntimeInjectorProvider -import org.eclipse.xtext.testing.InjectWith -import org.junit.Test - -/** - * @author Sebastian Zarnekow - Initial contribution and API - */ -@InjectWith(Java8RuntimeInjectorProvider) -class CompilerBug457539Test extends org.eclipse.xtend.core.tests.compiler.CompilerBug457539Test { - - @Test override test_01() { - ''' - import java.util.ArrayList - class C { - def m() { - val list = new ArrayList - list.forEach [ - if (it instanceof String) list.add(it) - ] - } - } - '''.assertCompilesTo(''' - import java.util.ArrayList; - import java.util.function.Consumer; - - @SuppressWarnings("all") - public class C { - public void m() { - final ArrayList list = new ArrayList(); - final Consumer _function = (Object it) -> { - if ((it instanceof String)) { - list.add(it); - } - }; - list.forEach(_function); - } - } - ''') - } - - @Test override test_02() { - ''' - class C { - def m() { - val list = newArrayList - list.forEach [ - if (it instanceof String) list.add(it) - ] - } - } - '''.assertCompilesTo(''' - import java.util.ArrayList; - import java.util.function.Consumer; - import org.eclipse.xtext.xbase.lib.CollectionLiterals; - - @SuppressWarnings("all") - public class C { - public void m() { - final ArrayList list = CollectionLiterals.newArrayList(); - final Consumer _function = (Object it) -> { - if ((it instanceof String)) { - list.add(it); - } - }; - list.forEach(_function); - } - } - ''') - } - - @Test override test_03() { - ''' - class C { - def m() { - val list = newIterable - list.forEach [ - ] - } - def static MyIterable newIterable(T... initial) {} - interface MyIterable extends Iterable { - } - } - '''.assertCompilesTo(''' - import java.util.function.Consumer; - - @SuppressWarnings("all") - public class C { - public interface MyIterable extends Iterable { - } - - public void m() { - final C.MyIterable list = C.newIterable(); - final Consumer _function = (CharSequence it) -> { - }; - list.forEach(_function); - } - - public static C.MyIterable newIterable(final T... initial) { - return null; - } - } - ''') - } - - @Test override test_04() { - ''' - class C { - def m() { - val list = newIterable - list.add('') - list.forEach [ - ] - } - def static MyIterable newIterable(T... initial) {} - interface MyIterable extends Iterable { - def void add(T t) - def T get() - } - } - '''.assertCompilesTo(''' - import java.util.function.Consumer; - - @SuppressWarnings("all") - public class C { - public interface MyIterable extends Iterable { - void add(final T t); - - T get(); - } - - public void m() { - final C.MyIterable list = C.newIterable(); - list.add(""); - final Consumer _function = (String it) -> { - }; - list.forEach(_function); - } - - public static C.MyIterable newIterable(final T... initial) { - return null; - } - } - ''') - } - - @Test override test_05() { - ''' - class C { - def m() { - val list = newIterable - list.get.toString - list.add('') - list.forEach [ - ] - } - def static MyIterable newIterable(T... initial) {} - interface MyIterable extends Iterable { - def void add(T t) - def T get() - } - } - '''.assertCompilesTo(''' - import java.util.function.Consumer; - - @SuppressWarnings("all") - public class C { - public interface MyIterable extends Iterable { - void add(final T t); - - T get(); - } - - public void m() { - final C.MyIterable list = C.newIterable(); - list.get().toString(); - list.add(""); - final Consumer _function = (CharSequence it) -> { - }; - list.forEach(_function); - } - - public static C.MyIterable newIterable(final T... initial) { - return null; - } - } - ''') - } - - @Test override test_06() { - ''' - class C { - def m() { - val list = newIterable - list.get.toString - list.forEach [ - if (it instanceof String) list.add(it) - ] - } - def static MyIterable newIterable(T... initial) {} - interface MyIterable extends Iterable { - def void add(T t) - def T get() - } - } - '''.assertCompilesTo(''' - import java.util.function.Consumer; - - @SuppressWarnings("all") - public class C { - public interface MyIterable extends Iterable { - void add(final T t); - - T get(); - } - - public void m() { - final C.MyIterable list = C.newIterable(); - list.get().toString(); - final Consumer _function = (CharSequence it) -> { - if ((it instanceof String)) { - list.add(it); - } - }; - list.forEach(_function); - } - - public static C.MyIterable newIterable(final T... initial) { - return null; - } - } - ''') - } - - @Test override test_07() { - ''' - class C { - def m() { - val list = newIterable - list.forEach [ - if (it instanceof String) list.add(it) - ] - } - def static MyIterable newIterable(T... initial) {} - interface MyIterable extends Iterable { - def void add(T t) - def T get() - } - } - '''.assertCompilesTo(''' - import java.util.function.Consumer; - - @SuppressWarnings("all") - public class C { - public interface MyIterable extends Iterable { - void add(final T t); - - T get(); - } - - public void m() { - final C.MyIterable list = C.newIterable(); - final Consumer _function = (CharSequence it) -> { - if ((it instanceof String)) { - list.add(it); - } - }; - list.forEach(_function); - } - - public static C.MyIterable newIterable(final T... initial) { - return null; - } - } - ''') - } - - @Test override test_08() { - ''' - class C { - def m() { - val list = newIterable - list.forEach [ CharSequence it | - if (it instanceof String) list.add(it) - ] - } - def static MyIterable newIterable(T... initial) {} - interface MyIterable extends Iterable { - def void add(T t) - def T get() - } - } - '''.assertCompilesTo(''' - import java.util.function.Consumer; - - @SuppressWarnings("all") - public class C { - public interface MyIterable extends Iterable { - void add(final T t); - - T get(); - } - - public void m() { - final C.MyIterable list = C.newIterable(); - final Consumer _function = (CharSequence it) -> { - if ((it instanceof String)) { - list.add(it); - } - }; - list.forEach(_function); - } - - public static C.MyIterable newIterable(final T... initial) { - return null; - } - } - ''') - } - - @Test override test_09() { - ''' - import org.eclipse.xtend.core.tests.java8.compiler.StringBuilderLike - class C { - def m() { - newIterable(new StringBuilderLike).forEach2 [ - m(it, new Long(0)) - println(length) - ] - } - def m(T a, T b){} - def static MyIterable newIterable(T... initial) {} - interface MyIterable extends Iterable { - def void forEach2((T)=>void f) - } - } - '''.assertCompilesTo(''' - import java.io.Serializable; - import org.eclipse.xtend.core.tests.java8.compiler.StringBuilderLike; - import org.eclipse.xtext.xbase.lib.InputOutput; - import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; - - @SuppressWarnings("all") - public class C { - public interface MyIterable extends Iterable { - void forEach2(final Procedure1 f); - } - - public void m() { - StringBuilderLike _stringBuilderLike = new StringBuilderLike(); - final Procedure1 _function = (StringBuilderLike it) -> { - Long _long = new Long(0); - this.m(it, _long); - InputOutput.println(Integer.valueOf(it.length())); - }; - C.newIterable(_stringBuilderLike).forEach2(_function); - } - - public Object m(final T a, final T b) { - return null; - } - - public static C.MyIterable newIterable(final T... initial) { - return null; - } - } - ''') - } - - @Test override test_10() { - ''' - class C { - def m(MyIterable list) { - list.forEach2 [] - } - interface MyIterable extends Iterable { - def void forEach2((T)=>void f) - } - } - '''.assertCompilesTo(''' - import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; - - @SuppressWarnings("all") - public class C { - public interface MyIterable extends Iterable { - void forEach2(final Procedure1 f); - } - - public void m(final C.MyIterable list) { - final Procedure1 _function = (Object it) -> { - }; - list.forEach2(_function); - } - } - ''') - } -} \ No newline at end of file diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug458010Test.xtend b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug458010Test.xtend index 37b20045fb9..cd1d03f9bec 100644 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug458010Test.xtend +++ b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug458010Test.xtend @@ -9,14 +9,11 @@ package org.eclipse.xtend.core.tests.java8.compiler import org.eclipse.xtend.core.tests.compiler.AbstractXtendCompilerTest -import org.eclipse.xtend.core.tests.java8.Java8RuntimeInjectorProvider -import org.eclipse.xtext.testing.InjectWith import org.junit.Test /** * @author Sebastian Zarnekow - Initial contribution and API */ -@InjectWith(Java8RuntimeInjectorProvider) class CompilerBug458010Test extends AbstractXtendCompilerTest { @Test diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug460691Test.xtend b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug460691Test.xtend deleted file mode 100644 index f1b7bc6b6d2..00000000000 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug460691Test.xtend +++ /dev/null @@ -1,41 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2015, 2016 itemis AG (http://www.itemis.eu) and others. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * SPDX-License-Identifier: EPL-2.0 - *******************************************************************************/ -package org.eclipse.xtend.core.tests.java8.compiler - -import org.eclipse.xtend.core.tests.java8.Java8RuntimeInjectorProvider -import org.eclipse.xtext.testing.InjectWith -import org.junit.Test - -/** - * @author Sebastian Zarnekow - Initial contribution and API - */ -@InjectWith(Java8RuntimeInjectorProvider) -class CompilerBug460691Test extends org.eclipse.xtend.core.tests.compiler.CompilerBug460691Test { - - @Test override test_01() { - ''' - class C implements java.util.Comparator { - override compare(String s1, String s2) { - return s1.compareTo(s2) - } - } - '''.assertCompilesTo(''' - import java.util.Comparator; - - @SuppressWarnings("all") - public class C implements Comparator { - @Override - public int compare(final String s1, final String s2) { - return s1.compareTo(s2); - } - } - ''') - } - -} \ No newline at end of file diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug462845Test.xtend b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug462845Test.xtend deleted file mode 100644 index 2f6c7160b39..00000000000 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug462845Test.xtend +++ /dev/null @@ -1,302 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2015, 2016 itemis AG (http://www.itemis.eu) and others. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * SPDX-License-Identifier: EPL-2.0 - *******************************************************************************/ -package org.eclipse.xtend.core.tests.java8.compiler - -import org.eclipse.xtend.core.tests.java8.Java8RuntimeInjectorProvider -import org.eclipse.xtext.testing.InjectWith -import org.junit.Test - -/** - * @author Sebastian Zarnekow - Initial contribution and API - */ -@InjectWith(Java8RuntimeInjectorProvider) -class CompilerBug462845Test extends org.eclipse.xtend.core.tests.compiler.CompilerBug462845Test { - - @Test override test_01() { - ''' - import java.util.Iterator - class C { - new() { - val Iterable iter = [ null ] - new Iterator() { - Iterator delegate = iter.iterator - override hasNext() { - delegate.hasNext - } - override next() { - delegate.next - } - } - } - } - '''.assertCompilesTo(''' - import java.util.Iterator; - - @SuppressWarnings("all") - public class C { - public C() { - abstract class __C_1 implements Iterator { - Iterator delegate; - } - - final Iterable _function = () -> { - return null; - }; - final Iterable iter = _function; - new __C_1() { - { - delegate = iter.iterator(); - } - @Override - public boolean hasNext() { - return this.delegate.hasNext(); - } - - @Override - public String next() { - return this.delegate.next(); - } - }; - } - } - ''') - } - - @Test override test_02() { - ''' - import java.util.Iterator - class C { - def m() { - val Iterable iter = [ null ] - new Iterator() { - Iterator delegate = iter.iterator - override hasNext() { - delegate.hasNext - } - override next() { - delegate.next - } - } - } - } - '''.assertCompilesTo(''' - import java.util.Iterator; - - @SuppressWarnings("all") - public class C { - public Iterator m() { - abstract class __C_1 implements Iterator { - Iterator delegate; - } - - __C_1 _xblockexpression = null; - { - final Iterable _function = () -> { - return null; - }; - final Iterable iter = _function; - _xblockexpression = new __C_1() { - { - delegate = iter.iterator(); - } - @Override - public boolean hasNext() { - return this.delegate.hasNext(); - } - - @Override - public String next() { - return this.delegate.next(); - } - }; - } - return _xblockexpression; - } - } - ''') - } - - @Test override test_03() { - ''' - import java.util.Iterator - class C { - def static m() { - val Iterable iter = [ null ] - new Iterator() { - Iterator delegate = iter.iterator - override hasNext() { - delegate.hasNext - } - override next() { - delegate.next - } - override remove() {} - } - } - } - '''.assertCompilesTo(''' - import java.util.Iterator; - - @SuppressWarnings("all") - public class C { - public static Iterator m() { - abstract class __C_1 implements Iterator { - Iterator delegate; - } - - __C_1 _xblockexpression = null; - { - final Iterable _function = () -> { - return null; - }; - final Iterable iter = _function; - _xblockexpression = new __C_1() { - { - delegate = iter.iterator(); - } - @Override - public boolean hasNext() { - return this.delegate.hasNext(); - } - - @Override - public String next() { - return this.delegate.next(); - } - - @Override - public void remove() { - } - }; - } - return _xblockexpression; - } - } - ''') - } - - @Test override test_04() { - ''' - import java.util.Iterator - class C { - def void m() { - val Iterable iter = [ null ] - new Iterator() { - Iterator delegate = iter.iterator - override hasNext() { - delegate.hasNext - } - override next() { - delegate.next - } - override remove() {} - } - } - } - '''.assertCompilesTo(''' - import java.util.Iterator; - - @SuppressWarnings("all") - public class C { - public void m() { - abstract class __C_1 implements Iterator { - Iterator delegate; - } - - final Iterable _function = () -> { - return null; - }; - final Iterable iter = _function; - new __C_1() { - { - delegate = iter.iterator(); - } - @Override - public boolean hasNext() { - return this.delegate.hasNext(); - } - - @Override - public String next() { - return this.delegate.next(); - } - - @Override - public void remove() { - } - }; - } - } - ''') - } - - @Test override test_05() { - ''' - import java.util.Iterator - class C { - val iterator = { - val Iterable iter = [ null ] - new Iterator() { - Iterator delegate = iter.iterator - override hasNext() { - delegate.hasNext - } - override next() { - delegate.next - } - override remove() {} - } - } - } - '''.assertCompilesTo(''' - import java.util.Iterator; - import org.eclipse.xtext.xbase.lib.Functions.Function0; - - @SuppressWarnings("all") - public class C { - private final Iterator iterator = new Function0>() { - @Override - public Iterator apply() { - abstract class __C_1 implements Iterator { - Iterator delegate; - } - - __C_1 _xblockexpression = null; - { - final Iterable _function = () -> { - return null; - }; - final Iterable iter = _function; - _xblockexpression = new __C_1() { - { - delegate = iter.iterator(); - } - @Override - public boolean hasNext() { - return this.delegate.hasNext(); - } - - @Override - public String next() { - return this.delegate.next(); - } - - @Override - public void remove() { - } - }; - } - return _xblockexpression; - } - }.apply(); - } - ''') - } - -} \ No newline at end of file diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug465058Test.xtend b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug465058Test.xtend deleted file mode 100644 index 83a47d71d98..00000000000 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug465058Test.xtend +++ /dev/null @@ -1,720 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2015, 2016 itemis AG (http://www.itemis.eu) and others. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * SPDX-License-Identifier: EPL-2.0 - *******************************************************************************/ -package org.eclipse.xtend.core.tests.java8.compiler - -import org.eclipse.xtend.core.tests.java8.Java8RuntimeInjectorProvider -import org.eclipse.xtext.testing.InjectWith -import org.junit.Test - -/** - * @author Sebastian Zarnekow - Initial contribution and API - */ -@InjectWith(Java8RuntimeInjectorProvider) -class CompilerBug465058Test extends org.eclipse.xtend.core.tests.compiler.CompilerBug465058Test { - - @Test override test_01() { - ''' - abstract class Bug { - val list = #["one", "two", "three"] - def void foo(=>Object f) - def bar() { - foo[list.head] - } - } - '''.assertCompilesTo(''' - import java.util.Collections; - import java.util.List; - import org.eclipse.xtext.xbase.lib.CollectionLiterals; - import org.eclipse.xtext.xbase.lib.Functions.Function0; - import org.eclipse.xtext.xbase.lib.IterableExtensions; - - @SuppressWarnings("all") - public abstract class Bug { - private final List list = Collections.unmodifiableList(CollectionLiterals.newArrayList("one", "two", "three")); - - public abstract void foo(final Function0 f); - - public void bar() { - final Function0 _function = () -> { - return IterableExtensions.head(this.list); - }; - this.foo(_function); - } - } - ''') - } - - @Test override test_02() { - ''' - abstract class Bug { - val list = newArrayList('a', 'b') - def void foo(=>Object f) - def bar() { - foo[ list.head ] - } - } - '''.assertCompilesTo(''' - import java.util.ArrayList; - import org.eclipse.xtext.xbase.lib.CollectionLiterals; - import org.eclipse.xtext.xbase.lib.Functions.Function0; - import org.eclipse.xtext.xbase.lib.IterableExtensions; - - @SuppressWarnings("all") - public abstract class Bug { - private final ArrayList list = CollectionLiterals.newArrayList("a", "b"); - - public abstract void foo(final Function0 f); - - public void bar() { - final Function0 _function = () -> { - return IterableExtensions.head(this.list); - }; - this.foo(_function); - } - } - ''') - } - - @Test override test_03() { - ''' - abstract class Bug { - val list = #["one", "two", "three"] - def void foo(=>Object f) - def bar() { - foo[list.head] - } - } - '''.assertCompilesTo(''' - import java.util.Collections; - import java.util.List; - import org.eclipse.xtext.xbase.lib.CollectionLiterals; - import org.eclipse.xtext.xbase.lib.Functions.Function0; - import org.eclipse.xtext.xbase.lib.IterableExtensions; - - @SuppressWarnings("all") - public abstract class Bug { - private final List list = Collections.unmodifiableList(CollectionLiterals.newArrayList("one", "two", "three")); - - public abstract void foo(final Function0 f); - - public void bar() { - final Function0 _function = () -> { - return IterableExtensions.head(this.list); - }; - this.foo(_function); - } - } - ''') - } - - @Test override test_04() { - ''' - abstract class Bug { - val list = newArrayList('a', 'b') - def void foo(=>Object f) - def bar() { - foo[ list.head ] - } - } - '''.assertCompilesTo(''' - import java.util.ArrayList; - import org.eclipse.xtext.xbase.lib.CollectionLiterals; - import org.eclipse.xtext.xbase.lib.Functions.Function0; - import org.eclipse.xtext.xbase.lib.IterableExtensions; - - @SuppressWarnings("all") - public abstract class Bug { - private final ArrayList list = CollectionLiterals.newArrayList("a", "b"); - - public abstract void foo(final Function0 f); - - public void bar() { - final Function0 _function = () -> { - return IterableExtensions.head(this.list); - }; - this.foo(_function); - } - } - ''') - } - - @Test override test_05() { - ''' - abstract class Bug { - val list = #["one", "two", "three"] - def void foo(=>Object f) - def bar() { - foo[list.head2] - } - def T head2(Iterable iterable) {} - } - '''.assertCompilesTo(''' - import java.util.Collections; - import java.util.List; - import org.eclipse.xtext.xbase.lib.CollectionLiterals; - import org.eclipse.xtext.xbase.lib.Functions.Function0; - - @SuppressWarnings("all") - public abstract class Bug { - private final List list = Collections.unmodifiableList(CollectionLiterals.newArrayList("one", "two", "three")); - - public abstract void foo(final Function0 f); - - public void bar() { - final Function0 _function = () -> { - return this.head2(this.list); - }; - this.foo(_function); - } - - public T head2(final Iterable iterable) { - return null; - } - } - ''') - } - - @Test override test_06() { - ''' - abstract class Bug { - val list = #["one", "two", "three"] - def void foo(=>Object f) - def bar() { - foo[list.head2] - } - def T head2(Iterable iterable) {} - } - '''.assertCompilesTo(''' - import java.util.Collections; - import java.util.List; - import org.eclipse.xtext.xbase.lib.CollectionLiterals; - import org.eclipse.xtext.xbase.lib.Functions.Function0; - - @SuppressWarnings("all") - public abstract class Bug { - private final List list = Collections.unmodifiableList(CollectionLiterals.newArrayList("one", "two", "three")); - - public abstract void foo(final Function0 f); - - public void bar() { - final Function0 _function = () -> { - return this.head2(this.list); - }; - this.foo(_function); - } - - public T head2(final Iterable iterable) { - return null; - } - } - ''') - } - - @Test override test_07() { - ''' - abstract class Bug { - val list = #["one", "two", "three"] - def void foo(=>Object f) - def bar() { - foo[list.head2] - } - def T head2(T[] iterable) {} - } - '''.assertCompilesTo(''' - import java.util.Collections; - import java.util.List; - import org.eclipse.xtext.xbase.lib.CollectionLiterals; - import org.eclipse.xtext.xbase.lib.Conversions; - import org.eclipse.xtext.xbase.lib.Functions.Function0; - - @SuppressWarnings("all") - public abstract class Bug { - private final List list = Collections.unmodifiableList(CollectionLiterals.newArrayList("one", "two", "three")); - - public abstract void foo(final Function0 f); - - public void bar() { - final Function0 _function = () -> { - return this.head2(((String[])Conversions.unwrapArray(this.list, String.class))); - }; - this.foo(_function); - } - - public T head2(final T[] iterable) { - return null; - } - } - ''') - } - - @Test override test_08() { - ''' - abstract class Bug { - def void foo(=>Object f) - def bar() { - foo[head2(#["one", "two", "three"])] - } - def T head2(T[] iterable) {} - } - '''.assertCompilesTo(''' - import org.eclipse.xtext.xbase.lib.Functions.Function0; - - @SuppressWarnings("all") - public abstract class Bug { - public abstract void foo(final Function0 f); - - public void bar() { - final Function0 _function = () -> { - return this.head2(new String[] { "one", "two", "three" }); - }; - this.foo(_function); - } - - public T head2(final T[] iterable) { - return null; - } - } - ''') - } - - @Test override test_09() { - ''' - abstract class Bug { - val list = #["one", "two", "three"] - def void foo(=>Object f) - def bar() { - foo[head2(list)] - } - def T head2(Iterable iterable) {} - } - '''.assertCompilesTo(''' - import java.util.Collections; - import java.util.List; - import org.eclipse.xtext.xbase.lib.CollectionLiterals; - import org.eclipse.xtext.xbase.lib.Functions.Function0; - - @SuppressWarnings("all") - public abstract class Bug { - private final List list = Collections.unmodifiableList(CollectionLiterals.newArrayList("one", "two", "three")); - - public abstract void foo(final Function0 f); - - public void bar() { - final Function0 _function = () -> { - return this.head2(this.list); - }; - this.foo(_function); - } - - public T head2(final Iterable iterable) { - return null; - } - } - ''') - } - - @Test override test_10() { - ''' - abstract class Bug { - val list = #["one", "two", "three"] - def void foo(=>Object f) - def bar() { - foo[list.head2] - } - def T head2(Iterable iterable) {} - } - '''.assertCompilesTo(''' - import java.util.Collections; - import java.util.List; - import org.eclipse.xtext.xbase.lib.CollectionLiterals; - import org.eclipse.xtext.xbase.lib.Functions.Function0; - - @SuppressWarnings("all") - public abstract class Bug { - private final List list = Collections.unmodifiableList(CollectionLiterals.newArrayList("one", "two", "three")); - - public abstract void foo(final Function0 f); - - public void bar() { - final Function0 _function = () -> { - return this.head2(this.list); - }; - this.foo(_function); - } - - public T head2(final Iterable iterable) { - return null; - } - } - ''') - } - - @Test override test_11() { - ''' - abstract class Bug { - val list = #["one", "two", "three"] - def void foo(=>Object f) - def bar() { - foo[list.head2] - } - def T head2(Iterable iterable) {} - } - '''.assertCompilesTo(''' - import java.util.Collections; - import java.util.List; - import org.eclipse.xtext.xbase.lib.CollectionLiterals; - import org.eclipse.xtext.xbase.lib.Functions.Function0; - - @SuppressWarnings("all") - public abstract class Bug { - private final List list = Collections.unmodifiableList(CollectionLiterals.newArrayList("one", "two", "three")); - - public abstract void foo(final Function0 f); - - public void bar() { - final Function0 _function = () -> { - return this.head2(this.list); - }; - this.foo(_function); - } - - public T head2(final Iterable iterable) { - return null; - } - } - ''') - } - - @Test override test_12() { - ''' - abstract class Bug { - val list = #["one", "two", "three"] - def void foo(=>Object f) - def bar() { - foo[list.head2] - } - def T head2(T[] iterable) {} - } - '''.assertCompilesTo(''' - import java.util.Collections; - import java.util.List; - import org.eclipse.xtext.xbase.lib.CollectionLiterals; - import org.eclipse.xtext.xbase.lib.Conversions; - import org.eclipse.xtext.xbase.lib.Functions.Function0; - - @SuppressWarnings("all") - public abstract class Bug { - private final List list = Collections.unmodifiableList(CollectionLiterals.newArrayList("one", "two", "three")); - - public abstract void foo(final Function0 f); - - public void bar() { - final Function0 _function = () -> { - return this.head2(((String[])Conversions.unwrapArray(this.list, String.class))); - }; - this.foo(_function); - } - - public T head2(final T[] iterable) { - return null; - } - } - ''') - } - - @Test override test_13() { - ''' - abstract class Bug { - def void foo(=>Object f) - def bar() { - foo[head2(#["one", "two", "three"])] - } - def T head2(T[] iterable) {} - } - '''.assertCompilesTo(''' - import org.eclipse.xtext.xbase.lib.Functions.Function0; - - @SuppressWarnings("all") - public abstract class Bug { - public abstract void foo(final Function0 f); - - public void bar() { - final Function0 _function = () -> { - return this.head2(new String[] { "one", "two", "three" }); - }; - this.foo(_function); - } - - public T head2(final T[] iterable) { - return null; - } - } - ''') - } - - @Test override test_14() { - ''' - abstract class Bug { - val list = #["one", "two", "three"] - def void foo(=>Object f) - def bar() { - foo[head2(list)] - } - def T head2(Iterable iterable) {} - } - '''.assertCompilesTo(''' - import java.util.Collections; - import java.util.List; - import org.eclipse.xtext.xbase.lib.CollectionLiterals; - import org.eclipse.xtext.xbase.lib.Functions.Function0; - - @SuppressWarnings("all") - public abstract class Bug { - private final List list = Collections.unmodifiableList(CollectionLiterals.newArrayList("one", "two", "three")); - - public abstract void foo(final Function0 f); - - public void bar() { - final Function0 _function = () -> { - return this.head2(this.list); - }; - this.foo(_function); - } - - public T head2(final Iterable iterable) { - return null; - } - } - ''') - } - - @Test override test_15() { - ''' - abstract class Bug { - val list = #["one", "two", "three"] - def void bar() { - var =>Object x = [head2(list)] - x.apply - } - def T head2(Iterable iterable) {} - } - '''.assertCompilesTo(''' - import java.util.Collections; - import java.util.List; - import org.eclipse.xtext.xbase.lib.CollectionLiterals; - import org.eclipse.xtext.xbase.lib.Functions.Function0; - - @SuppressWarnings("all") - public abstract class Bug { - private final List list = Collections.unmodifiableList(CollectionLiterals.newArrayList("one", "two", "three")); - - public void bar() { - final Function0 _function = () -> { - return this.head2(this.list); - }; - Function0 x = _function; - x.apply(); - } - - public T head2(final Iterable iterable) { - return null; - } - } - ''') - } - - @Test override test_16() { - ''' - abstract class Bug { - def bar() { - var =>Object x = [head2(#["one", "two", "three"])] - x.apply - } - def T head2(Iterable iterable) {} - } - '''.assertCompilesTo(''' - import java.util.Collections; - import org.eclipse.xtext.xbase.lib.CollectionLiterals; - import org.eclipse.xtext.xbase.lib.Functions.Function0; - - @SuppressWarnings("all") - public abstract class Bug { - public Object bar() { - Object _xblockexpression = null; - { - final Function0 _function = () -> { - return this.head2(Collections.unmodifiableList(CollectionLiterals.newArrayList("one", "two", "three"))); - }; - Function0 x = _function; - _xblockexpression = x.apply(); - } - return _xblockexpression; - } - - public T head2(final Iterable iterable) { - return null; - } - } - ''') - } - - @Test override test_17() { - ''' - abstract class Bug { - def bar() { - var =>Object x = [head2(#["one", "two", "three"])] - x.apply() - } - def T head2(T[] iterable) {} - } - '''.assertCompilesTo(''' - import org.eclipse.xtext.xbase.lib.Functions.Function0; - - @SuppressWarnings("all") - public abstract class Bug { - public Object bar() { - Object _xblockexpression = null; - { - final Function0 _function = () -> { - return this.head2(new String[] { "one", "two", "three" }); - }; - Function0 x = _function; - _xblockexpression = x.apply(); - } - return _xblockexpression; - } - - public T head2(final T[] iterable) { - return null; - } - } - ''') - } - - @Test override test_18() { - ''' - abstract class Bug { - def void foo(=>Object f) - def bar() { - foo[head2(#[1, 1.0])] - } - def T head2(T[] iterable) {} - } - '''.assertCompilesTo(''' - import org.eclipse.xtext.xbase.lib.Functions.Function0; - - @SuppressWarnings("all") - public abstract class Bug { - public abstract void foo(final Function0 f); - - public void bar() { - final Function0 _function = () -> { - return ((Number)this.head2(new Number[] { Integer.valueOf(1), Double.valueOf(1.0) })); - }; - this.foo(_function); - } - - public T head2(final T[] iterable) { - return null; - } - } - ''') - } - - @Test override test_19() { - ''' - abstract class Bug { - def void foo(=>Object f) - def bar() { - foo[head2(#['', ''])] - } - def T head2(Comparable[] iterable) {} - } - '''.assertCompilesTo(''' - import org.eclipse.xtext.xbase.lib.Functions.Function0; - - @SuppressWarnings("all") - public abstract class Bug { - public abstract void foo(final Function0 f); - - public void bar() { - final Function0 _function = () -> { - return this.head2(new Comparable[] { "", "" }); - }; - this.foo(_function); - } - - public T head2(final Comparable[] iterable) { - return null; - } - } - ''') - } - - @Test override test_20() { - ''' - abstract class Bug { - def void foo(=>Object f) - def bar() { - foo[head2(#[null as Integer, null as Double])] - } - def T head2(Comparable[] iterable) {} - } - '''.assertCompilesTo(''' - import org.eclipse.xtext.xbase.lib.Functions.Function0; - - @SuppressWarnings("all") - public abstract class Bug { - public abstract void foo(final Function0 f); - - public void bar() { - final Function0 _function = () -> { - return ((Number)this.head2(new Comparable[] { ((Integer) null), ((Double) null) })); - }; - this.foo(_function); - } - - public T head2(final Comparable[] iterable) { - return null; - } - } - ''') - } - - @Test override test_21() { - ''' - abstract class Bug { - def void foo(=>Object f) - def bar() { - foo[head2(#[1, 1.0])] - } - def T head2(Comparable[] iterable) {} - } - '''.assertCompilesTo(''' - import org.eclipse.xtext.xbase.lib.Functions.Function0; - - @SuppressWarnings("all") - public abstract class Bug { - public abstract void foo(final Function0 f); - - public void bar() { - final Function0 _function = () -> { - return ((Number)this.head2(new Comparable[] { Integer.valueOf(1), Double.valueOf(1.0) })); - }; - this.foo(_function); - } - - public T head2(final Comparable[] iterable) { - return null; - } - } - ''') - } - -} \ No newline at end of file diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug472602Test.xtend b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug472602Test.xtend deleted file mode 100644 index 1e57c70d355..00000000000 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug472602Test.xtend +++ /dev/null @@ -1,121 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2015, 2016 itemis AG (http://www.itemis.eu) and others. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * SPDX-License-Identifier: EPL-2.0 - *******************************************************************************/ -package org.eclipse.xtend.core.tests.java8.compiler - -import org.eclipse.xtend.core.tests.java8.Java8RuntimeInjectorProvider -import org.eclipse.xtext.testing.InjectWith -import org.junit.Test - -/** - * @author Sebastian Zarnekow - Initial contribution and API - */ -@InjectWith(Java8RuntimeInjectorProvider) -class CompilerBug472602Test extends org.eclipse.xtend.core.tests.compiler.CompilerBug472602Test { - - @Test override test_06() { - ''' - import com.google.common.base.Function - - abstract class C { - def A get(); - - def C map(Function f) { - new MapResult(this, f) - } - static class MapResult extends C { - C in - Function f - new (C in, Function f) { - this.in = in - this.f = f - } - override get() { - val A a = in.get - val B b = f.apply(a) - return b - } - } - } - '''.assertCompilesTo(''' - import com.google.common.base.Function; - - @SuppressWarnings("all") - public abstract class C { - public static class MapResult extends C { - private C in; - - private Function f; - - public MapResult(final C in, final Function f) { - this.in = in; - this.f = f; - } - - @Override - public B get() { - final A a = this.in.get(); - final B b = this.f.apply(a); - return b; - } - } - - public abstract A get(); - - public C map(final Function f) { - return new C.MapResult(this, f); - } - } - ''') - } - - @Test override test_07() { - ''' - import com.google.common.base.Function - - abstract class C { - def A get(); - - def C map(Function f) { - val thiz = this - new C() { - override get() { - val A a = thiz.get - val B b = f.apply(a) - return b - } - } - } - } - '''.assertCompilesTo(''' - import com.google.common.base.Function; - - @SuppressWarnings("all") - public abstract class C { - public abstract A get(); - - public C map(final Function f) { - C _xblockexpression = null; - { - final C thiz = this; - _xblockexpression = new C() { - @Override - public B get() { - final A a = thiz.get(); - final B b = f.apply(a); - return b; - } - }; - } - return _xblockexpression; - } - } - ''') - } - -} \ No newline at end of file diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/compiler/Java8Compiler1Test.xtend b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/compiler/Java8Compiler1Test.xtend index 16cc470b2de..bb23c787a8a 100644 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/compiler/Java8Compiler1Test.xtend +++ b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/compiler/Java8Compiler1Test.xtend @@ -8,16 +8,13 @@ *******************************************************************************/ package org.eclipse.xtend.core.tests.java8.compiler -import org.eclipse.xtend.core.tests.compiler.CompilerTest -import org.eclipse.xtend.core.tests.java8.Java8RuntimeInjectorProvider -import org.eclipse.xtext.testing.InjectWith +import org.eclipse.xtend.core.tests.compiler.CompilerTestBase import org.junit.Test /** * @author Miro Spoenemann - Initial contribution and API */ -@InjectWith(Java8RuntimeInjectorProvider) -class Java8Compiler1Test extends CompilerTest { +class Java8Compiler1Test extends CompilerTestBase { @Test def testJava8Reduce() { invokeAndExpect2(36, ''' diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/compiler/Java8Compiler2Test.xtend b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/compiler/Java8Compiler2Test.xtend deleted file mode 100644 index db27a64d0cc..00000000000 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/compiler/Java8Compiler2Test.xtend +++ /dev/null @@ -1,1579 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2015, 2020 itemis AG (http://www.itemis.eu) and others. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * SPDX-License-Identifier: EPL-2.0 - *******************************************************************************/ -package org.eclipse.xtend.core.tests.java8.compiler - -import org.eclipse.xtend.core.tests.compiler.XtendCompilerTest -import org.eclipse.xtend.core.tests.java8.Java8RuntimeInjectorProvider -import org.eclipse.xtext.testing.InjectWith -import org.junit.Test - -/** - * @author Miro Spoenemann - Initial contribution and API - */ -@InjectWith(Java8RuntimeInjectorProvider) -class Java8Compiler2Test extends XtendCompilerTest { - - @Test def void testStaticMethodInInterface() { - ''' - interface Foo { - static def bar() { - "bar!" - } - } - '''.assertCompilesTo(''' - @SuppressWarnings("all") - public interface Foo { - static String bar() { - return "bar!"; - } - } - ''') - } - - @Test - override testMultiCatch_02() { - assertCompilesTo(''' - abstract class Foo { - abstract def void throwsSomething() throws E; - def void m() { - try { - throwsSomething; - throwsSomething - } catch(E1 | E2 e) { - e.m - e.message - } - } - interface E { - def void m() - } - static class E1 extends Exception implements E { - override m() {} - } - static class E2 extends Exception implements E { - override m() {} - } - } - ''',''' - import org.eclipse.xtext.xbase.lib.Exceptions; - - @SuppressWarnings("all") - public abstract class Foo { - public interface E { - void m(); - } - - public static class E1 extends Exception implements Foo.E { - @Override - public void m() { - } - } - - public static class E2 extends Exception implements Foo.E { - @Override - public void m() { - } - } - - public abstract void throwsSomething() throws E; - - public void m() { - try { - try { - this.throwsSomething(); - this.throwsSomething(); - } catch (final Throwable _t) { - if (_t instanceof Foo.E1 || _t instanceof Foo.E2) { - final Exception e = (Exception)_t; - ((Foo.E)e).m(); - e.getMessage(); - } else { - throw Exceptions.sneakyThrow(_t); - } - } - } catch (Throwable _e) { - throw Exceptions.sneakyThrow(_e); - } - } - } - ''') - } - - @Test override void testSwitchWithMultiType_02() { - assertCompilesTo(''' - public class C { - def m(Object a) { - switch a { - E1 | E2 case a.message !== null: a.m - } - } - interface E { - def void m() - } - static class E1 extends Exception implements E { - override m() {} - } - static class E2 extends Exception implements E { - override m() {} - } - } - ''', ''' - @SuppressWarnings("all") - public class C { - public interface E { - void m(); - } - - public static class E1 extends Exception implements C.E { - @Override - public void m() { - } - } - - public static class E2 extends Exception implements C.E { - @Override - public void m() { - } - } - - public void m(final Object a) { - boolean _matched = false; - if (a instanceof C.E1 || a instanceof C.E2) { - String _message = ((Exception)a).getMessage(); - boolean _tripleNotEquals = (_message != null); - if (_tripleNotEquals) { - _matched=true; - ((C.E)a).m(); - } - } - } - } - ''') - } - - @Test override void testSwitchWithMultiType_03() { - assertCompilesTo(''' - public class C { - def m(Object a) { - switch a { - E1 | E2 : { val b = a b.message b.m } - } - } - interface E { - def void m() - } - static class E1 extends Exception implements E { - override m() {} - } - static class E2 extends Exception implements E { - override m() {} - } - } - ''', ''' - @SuppressWarnings("all") - public class C { - public interface E { - void m(); - } - - public static class E1 extends Exception implements C.E { - @Override - public void m() { - } - } - - public static class E2 extends Exception implements C.E { - @Override - public void m() { - } - } - - public void m(final Object a) { - boolean _matched = false; - if (a instanceof C.E1 || a instanceof C.E2) { - _matched=true; - final Exception b = ((Exception)a); - b.getMessage(); - ((C.E)b).m(); - } - } - } - ''') - } - - @Test def void testJava8UnaryOperator() throws Exception { - ''' - import java.util.List - class Test { - def test(List list) { - list.replaceAll[it + 1] - } - } - '''.assertCompilesTo(''' - import java.util.List; - import java.util.function.UnaryOperator; - - @SuppressWarnings("all") - public class Test { - public void test(final List list) { - final UnaryOperator _function = (Integer it) -> { - return Integer.valueOf(((it).intValue() + 1)); - }; - list.replaceAll(_function); - } - } - ''') - } - - @Test def void testJava8Comparator() throws Exception { - ''' - import java.util.List - class Test { - def test(List list) { - list.sort(java.util.Comparator.comparingInt[String s | s.length] - .thenComparing[String s | s.length]) - } - } - '''.assertCompilesTo(''' - import java.util.Comparator; - import java.util.List; - import java.util.function.Function; - import java.util.function.ToIntFunction; - - @SuppressWarnings("all") - public class Test { - public void test(final List list) { - final ToIntFunction _function = (String s) -> { - return s.length(); - }; - final Function _function_1 = (String s) -> { - return Integer.valueOf(s.length()); - }; - list.sort(Comparator.comparingInt(_function).thenComparing(_function_1)); - } - } - ''') - } - - @Test def void testJava8Predicate() throws Exception { - ''' - import java.util.List - class Test { - def test(List list) { - list.removeIf[it < 2] - } - } - '''.assertCompilesTo(''' - import java.util.List; - import java.util.function.Predicate; - - @SuppressWarnings("all") - public class Test { - public boolean test(final List list) { - final Predicate _function = (Integer it) -> { - return ((it).intValue() < 2); - }; - return list.removeIf(_function); - } - } - ''') - } - - @Test def void testJava8BinaryOperation() throws Exception { - ''' - import java.util.List - class Test { - def test(List list) { - list.stream.reduce[a, b | a && b] - } - } - '''.assertCompilesTo(''' - import java.util.List; - import java.util.Optional; - import java.util.function.BinaryOperator; - - @SuppressWarnings("all") - public class Test { - public Optional test(final List list) { - final BinaryOperator _function = (Boolean a, Boolean b) -> { - return Boolean.valueOf(((a).booleanValue() && (b).booleanValue())); - }; - return list.stream().reduce(_function); - } - } - ''') - } - - @Test def void testJava8Consumer() throws Exception { - ''' - import java.util.List - class Test { - def test(List list) { - list.stream.forEach[println(it)] - } - } - '''.assertCompilesTo(''' - import java.util.List; - import java.util.function.Consumer; - import org.eclipse.xtext.xbase.lib.InputOutput; - - @SuppressWarnings("all") - public class Test { - public void test(final List list) { - final Consumer _function = (String it) -> { - InputOutput.println(it); - }; - list.stream().forEach(_function); - } - } - ''') - } - - @Test def void testJava8BiFunction() throws Exception { - ''' - import java.util.Map - class Test { - def test(Map map) { - map.replaceAll[k, v | v + k.length] - } - } - '''.assertCompilesTo(''' - import java.util.Map; - import java.util.function.BiFunction; - - @SuppressWarnings("all") - public class Test { - public void test(final Map map) { - final BiFunction _function = (String k, Integer v) -> { - int _length = k.length(); - return Integer.valueOf(((v).intValue() + _length)); - }; - map.replaceAll(_function); - } - } - ''') - } - - @Test def void testDefaultMethodSuperCall01() throws Exception { - ''' - class Test implements A { - override void foo() { - A.super.foo - } - } - interface A { - def void foo() {} - } - '''.assertCompilesTo(''' - @SuppressWarnings("all") - public class Test implements A { - @Override - public void foo() { - A.super.foo(); - } - } - ''') - } - - @Test def void testDefaultMethodSuperCall02() throws Exception { - ''' - class Test implements A, B { - override void foo() { - B.super.foo - } - } - interface A { - def void foo() {} - } - interface B { - def void foo() {} - } - '''.assertCompilesTo(''' - @SuppressWarnings("all") - public class Test implements A, B { - @Override - public void foo() { - B.super.foo(); - } - } - ''') - } - - @Test def void testDefaultMethodSuperCall03() throws Exception { - ''' - import test.Consumer - class Test implements Consumer, java.util.function.Consumer { - override void accept(String element) { - java.util.function.Consumer.super.andThen(this).accept('foo') - } - } - '''.assertCompilesTo(''' - import test.Consumer; - - @SuppressWarnings("all") - public class Test implements Consumer, java.util.function.Consumer { - @Override - public void accept(final String element) { - java.util.function.Consumer.super.andThen(this).accept("foo"); - } - } - ''') - } - - @Test def void testDefaultMethodSuperCall04() throws Exception { - ''' - interface Test extends A { - override void foo() { - A.super.foo - } - } - interface A { - def void foo() {} - } - '''.assertCompilesTo(''' - @SuppressWarnings("all") - public interface Test extends A { - @Override - default void foo() { - A.super.foo(); - } - } - ''') - } - - @Test def void testSelfReference() throws Exception { - ''' - class LambdaTest { - def b(A a) { - a.a - } - def test() { - b['hello' + b['world' + self.a]] - } - } - interface A { - def String a() - } - '''.assertCompilesTo(''' - @SuppressWarnings("all") - public class LambdaTest { - public String b(final A a) { - return a.a(); - } - - public String test() { - final A _function = () -> { - final A _function_1 = new A() { - @Override - public String a() { - String _a = this.a(); - return ("world" + _a); - } - }; - String _b = this.b(_function_1); - return ("hello" + _b); - }; - return this.b(_function); - } - } - ''') - } - - @Test override testClosureNoArgs() { - ''' - class Foo { - val thread = new Thread [] - } - '''.assertCompilesTo(''' - @SuppressWarnings("all") - public class Foo { - private final Thread thread = new Thread(((Runnable) () -> { - })); - } - ''') - } - - @Test override testClosureTwoArgs() { - ''' - class Foo { - def void m(java.util.List list) { - java.util.Collections.sort(list) [ return 0 ] - } - } - '''.assertCompilesTo(''' - import java.util.Collections; - import java.util.Comparator; - import java.util.List; - - @SuppressWarnings("all") - public class Foo { - public void m(final List list) { - final Comparator _function = (String $0, String $1) -> { - return 0; - }; - Collections.sort(list, _function); - } - } - ''') - } - - @Test override testVoidMethod_02() throws Exception { - ''' - class A { - def m() { - [ | System::out.println('') ] - } - } - '''.assertCompilesTo(''' - import org.eclipse.xtext.xbase.lib.Procedures.Procedure0; - - @SuppressWarnings("all") - public class A { - public Procedure0 m() { - final Procedure0 _function = () -> { - System.out.println(""); - }; - return _function; - } - } - ''') - } - - @Test override testVoidMethod_03() throws Exception { - ''' - class A { - def m() { - [ | println('') ] - } - } - '''.assertCompilesTo(''' - import org.eclipse.xtext.xbase.lib.Functions.Function0; - import org.eclipse.xtext.xbase.lib.InputOutput; - - @SuppressWarnings("all") - public class A { - public Function0 m() { - final Function0 _function = () -> { - return InputOutput.println(""); - }; - return _function; - } - } - ''') - } - - @Test override testThrowablesPropagate_01() throws Exception { - ''' - import static extension Throwables.* - import java.net.URI - - class Client { - val uri = [| new URI('')].propagate [ new IllegalArgumentException(it) ] - - def foo (){ - uri.toString - } - } - class Throwables { - def static T propagate(()=>T proc, (Exception)=>Exception handler) { - try { - proc.apply - } catch(Exception e) { - throw handler.apply(e) - } - } - } - '''.assertCompilesTo(''' - import java.net.URI; - import org.eclipse.xtext.xbase.lib.Exceptions; - import org.eclipse.xtext.xbase.lib.Functions.Function0; - import org.eclipse.xtext.xbase.lib.Functions.Function1; - - @SuppressWarnings("all") - public class Client { - private final URI uri = Throwables.propagate(((Function0) () -> { - try { - return new URI(""); - } catch (Throwable _e) { - throw Exceptions.sneakyThrow(_e); - } - }), ((Function1) (Exception it) -> { - return new IllegalArgumentException(it); - })); - - public String foo() { - return this.uri.toString(); - } - } - ''') - } - - @Test override testThrowablesPropagate_02() throws Exception { - ''' - import static extension Throwables.* - import java.net.URI - - class Client { - val uri = [| new URI('')].propagate [ new IllegalArgumentException(it) ] - } - class Throwables { - def static T propagate(()=>T proc, (Exception)=>Exception handler) { - try { - proc.apply - } catch(Exception e) { - throw handler.apply(e) - } - } - } - '''.assertCompilesTo(''' - import java.net.URI; - import org.eclipse.xtext.xbase.lib.Exceptions; - import org.eclipse.xtext.xbase.lib.Functions.Function0; - import org.eclipse.xtext.xbase.lib.Functions.Function1; - - @SuppressWarnings("all") - public class Client { - private final URI uri = Throwables.propagate(((Function0) () -> { - try { - return new URI(""); - } catch (Throwable _e) { - throw Exceptions.sneakyThrow(_e); - } - }), ((Function1) (Exception it) -> { - return new IllegalArgumentException(it); - })); - } - ''') - } - - @Test override testSwitchWithBooleanExpression_3() { - ''' - class Foo { - def foo(int x) { - switch x { - case [|1 == x].apply || x == 2: true - default: false - } - } - } - '''.assertCompilesTo(''' - import org.eclipse.xtext.xbase.lib.Functions.Function0; - - @SuppressWarnings("all") - public class Foo { - public boolean foo(final int x) { - boolean _switchResult = false; - boolean _matched = false; - if (((((Function0) () -> { - return Boolean.valueOf((1 == x)); - }).apply()).booleanValue() || (x == 2))) { - _matched=true; - _switchResult = true; - } - if (!_matched) { - _switchResult = false; - } - return _switchResult; - } - } - ''') - } - - @Test override testSwitchOverNull() { - ''' - public class Foo { - def foo() { - switch null { - case null : [Object it|it] - case null : [Integer it|it] - } - } - } - '''.assertCompilesTo(''' - import java.util.Objects; - import org.eclipse.xtext.xbase.lib.Functions.Function1; - - @SuppressWarnings("all") - public class Foo { - public Function1 foo() { - Function1 _switchResult = null; - final Object _switchValue = null; - boolean _matched = false; - if (Objects.equals(_switchValue, null)) { - _matched=true; - final Function1 _function = (Object it) -> { - return it; - }; - _switchResult = _function; - } - if (!_matched) { - if (Objects.equals(_switchValue, null)) { - _matched=true; - final Function1 _function_1 = (Integer it) -> { - return it; - }; - _switchResult = _function_1; - } - } - return _switchResult; - } - } - ''') - } - - @Test override testSwitchWithConstantExpressions_6() { - ''' - class Foo { - def foo() { - switch x : [|1].apply { - case 1: true - } - } - } - '''.assertCompilesTo(''' - import org.eclipse.xtext.xbase.lib.Functions.Function0; - - @SuppressWarnings("all") - public class Foo { - public boolean foo() { - boolean _switchResult = false; - final Function0 _function = () -> { - return Integer.valueOf(1); - }; - Integer _apply = _function.apply(); - final Integer x = _apply; - if (x != null) { - switch (x) { - case 1: - _switchResult = true; - break; - } - } - return _switchResult; - } - } - ''') - } - - @Test override testSwitchWithConstantExpressions_7() { - ''' - class Foo { - def foo() { - switch x : 1 { - case [|1].apply: true - } - } - } - '''.assertCompilesTo(''' - import java.util.Objects; - import org.eclipse.xtext.xbase.lib.Functions.Function0; - - @SuppressWarnings("all") - public class Foo { - public boolean foo() { - boolean _switchResult = false; - final int x = 1; - boolean _matched = false; - final Function0 _function = () -> { - return Integer.valueOf(1); - }; - Integer _apply = _function.apply(); - if (Objects.equals(x, _apply)) { - _matched=true; - _switchResult = true; - } - return _switchResult; - } - } - ''') - } - - @Test override testClosureSneakyThrow() { - ''' - import java.io.File - import java.io.IOException - import java.util.Collections - - class Foo { - def bar() { - try { - newArrayList("file1.ext").map(f| new File(f).canonicalFile) - } catch(IOException o) { - Collections::emptyList - } - } - } - '''.assertCompilesTo(''' - import java.io.File; - import java.io.IOException; - import java.util.Collections; - import java.util.List; - import org.eclipse.xtext.xbase.lib.CollectionLiterals; - import org.eclipse.xtext.xbase.lib.Exceptions; - import org.eclipse.xtext.xbase.lib.Functions.Function1; - import org.eclipse.xtext.xbase.lib.ListExtensions; - - @SuppressWarnings("all") - public class Foo { - public List bar() { - List _xtrycatchfinallyexpression = null; - try { - final Function1 _function = (String f) -> { - try { - return new File(f).getCanonicalFile(); - } catch (Throwable _e) { - throw Exceptions.sneakyThrow(_e); - } - }; - _xtrycatchfinallyexpression = ListExtensions.map(CollectionLiterals.newArrayList("file1.ext"), _function); - } catch (final Throwable _t) { - if (_t instanceof IOException) { - _xtrycatchfinallyexpression = Collections.emptyList(); - } else { - throw Exceptions.sneakyThrow(_t); - } - } - return _xtrycatchfinallyexpression; - } - } - ''') - } - - @Test override testClosureSneakyThrow_02() throws Exception { - ''' - abstract class Foo { - def Object getFoo(String x) throws Exception - def bar() { - newArrayList.toMap[foo] - } - } - '''.assertCompilesTo(''' - import java.util.Map; - import org.eclipse.xtext.xbase.lib.CollectionLiterals; - import org.eclipse.xtext.xbase.lib.Exceptions; - import org.eclipse.xtext.xbase.lib.Functions.Function1; - import org.eclipse.xtext.xbase.lib.IterableExtensions; - - @SuppressWarnings("all") - public abstract class Foo { - public abstract Object getFoo(final String x) throws Exception; - - public Map bar() { - final Function1 _function = (String it) -> { - try { - return this.getFoo(it); - } catch (Throwable _e) { - throw Exceptions.sneakyThrow(_e); - } - }; - return IterableExtensions.toMap(CollectionLiterals.newArrayList(), _function); - } - } - ''') - } - - @Test override testNestedClosureWithIt() { - ''' - class X { - def foo() { - val (String)=>String function = [ [String it | it].apply(it) ] - function.apply('foo') - } - } - '''.assertCompilesTo(''' - import org.eclipse.xtext.xbase.lib.Functions.Function1; - - @SuppressWarnings("all") - public class X { - public String foo() { - String _xblockexpression = null; - { - final Function1 _function = (String it) -> { - final Function1 _function_1 = (String it_1) -> { - return it_1; - }; - return _function_1.apply(it); - }; - final Function1 function = _function; - _xblockexpression = function.apply("foo"); - } - return _xblockexpression; - } - } - ''') - } - - @Test override testNestedClosureSuperCall() { - ''' - class X { - def foo() { - [| [| super.toString ].apply ].apply - } - } - '''.assertCompilesTo(''' - import org.eclipse.xtext.xbase.lib.Functions.Function0; - - @SuppressWarnings("all") - public class X { - public String foo() { - final Function0 _function = () -> { - final Function0 _function_1 = () -> { - return super.toString(); - }; - return _function_1.apply(); - }; - return _function.apply(); - } - } - ''') - } - - @Test override testFindFirstOnIt_01() { - ''' - class FindFirstOnIt { - def useExtension(Iterable it) { - findFirst [ it !== null ] - } - } - '''.assertCompilesTo(''' - import org.eclipse.xtext.xbase.lib.Functions.Function1; - import org.eclipse.xtext.xbase.lib.IterableExtensions; - - @SuppressWarnings("all") - public class FindFirstOnIt { - public T useExtension(final Iterable it) { - final Function1 _function = (T it_1) -> { - return Boolean.valueOf((it_1 != null)); - }; - return IterableExtensions.findFirst(it, _function); - } - } - ''') - } - - @Test override testAbstractIterator_03() { - ''' - import java.util.Iterator - import com.google.common.collect.AbstractIterator - public class Foo { - def Iterator skipNulls(Iterator iter) { - val AbstractIterator result = [| - iter.findFirst [ it !== null ] ?: self.endOfData - ] - return result - } - } - '''.assertCompilesTo(''' - import com.google.common.collect.AbstractIterator; - import java.util.Iterator; - import org.eclipse.xtext.xbase.lib.Functions.Function1; - import org.eclipse.xtext.xbase.lib.IteratorExtensions; - - @SuppressWarnings("all") - public class Foo { - public Iterator skipNulls(final Iterator iter) { - final AbstractIterator _function = new AbstractIterator() { - @Override - protected T computeNext() { - T _elvis = null; - final Function1 _function = (T it) -> { - return Boolean.valueOf((it != null)); - }; - T _findFirst = IteratorExtensions.findFirst(iter, _function); - if (_findFirst != null) { - _elvis = _findFirst; - } else { - T _endOfData = this.endOfData(); - _elvis = _endOfData; - } - return _elvis; - } - }; - final AbstractIterator result = _function; - return result; - } - } - ''') - } - - @Test override testAbstractIterator_04() { - ''' - import java.util.Iterator - import com.google.common.collect.AbstractIterator - class FindFirstOnIt { - - def Iterator skipNulls(Iterator it) { - val AbstractIterator result = [| - findFirst [ it != null ] ?: self.endOfData - ] - return result - } - } - '''.assertCompilesTo(''' - import com.google.common.collect.AbstractIterator; - import java.util.Iterator; - import java.util.Objects; - import org.eclipse.xtext.xbase.lib.Functions.Function1; - import org.eclipse.xtext.xbase.lib.IteratorExtensions; - - @SuppressWarnings("all") - public class FindFirstOnIt { - public Iterator skipNulls(final Iterator it) { - final AbstractIterator _function = new AbstractIterator() { - @Override - protected T computeNext() { - T _elvis = null; - final Function1 _function = (T it_1) -> { - return Boolean.valueOf((!Objects.equals(it_1, null))); - }; - T _findFirst = IteratorExtensions.findFirst(it, _function); - if (_findFirst != null) { - _elvis = _findFirst; - } else { - T _endOfData = this.endOfData(); - _elvis = _endOfData; - } - return _elvis; - } - }; - final AbstractIterator result = _function; - return result; - } - } - ''') - } - - @Test override testReturnType() { - ''' - import test.ReturnTypeUsesTypeParameter - class MyClass implements ReturnTypeUsesTypeParameter { - - override accept(LocalName param) { - null - } - } - '''.assertCompilesTo(''' - import test.ReturnTypeUsesTypeParameter; - - @SuppressWarnings("all") - public class MyClass implements ReturnTypeUsesTypeParameter { - @Override - public ReturnTypeUsesTypeParameter.Inner accept(final LocalName param) { - return null; - } - } - ''') - } - - @Test override testReturnType_02() { - ''' - import test.ReturnTypeUsesTypeParameter - class MyClass implements ReturnTypeUsesTypeParameter { - - override accept(LocalName param) { - [ if (true) it?.apply(param) ] - } - } - '''.assertCompilesTo(''' - import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; - import test.ReturnTypeUsesTypeParameter; - - @SuppressWarnings("all") - public class MyClass implements ReturnTypeUsesTypeParameter { - @Override - public ReturnTypeUsesTypeParameter.Inner accept(final LocalName param) { - final ReturnTypeUsesTypeParameter.Inner _function = (Procedure1 it) -> { - if (true) { - if (it!=null) { - it.apply(param); - } - } - }; - return _function; - } - } - ''') - } - - @Test override testReturnType_03() { - ''' - import java.util.LinkedList - - class B extends A { - def String client(CharSequence c) { - client(m) - } - override m() { - '' - } - } - - abstract class A { - def CharSequence m() - } - '''.assertCompilesTo(''' - @SuppressWarnings("all") - public class B extends A { - public String client(final CharSequence c) { - return this.client(this.m()); - } - - @Override - public CharSequence m() { - return ""; - } - } - ''') - } - - @Test override testInnerTypeImports_1() { - ''' - class Foo extends types.SomeClassWithNestedInterface { - override types.SomeClassWithNestedInterface.String convert(java.lang.String s) { - return null; - } - } - '''.assertCompilesTo(''' - import types.SomeClassWithNestedInterface; - - @SuppressWarnings("all") - public class Foo extends SomeClassWithNestedInterface { - @Override - public SomeClassWithNestedInterface.String convert(final java.lang.String s) { - return null; - } - } - ''') - } - - @Test override testRecursiveLambda_01() { - ''' - public class Foo { - def void foo((String)=>String func) { - foo[self.apply(it)] - } - } - '''.assertCompilesTo(''' - import org.eclipse.xtext.xbase.lib.Functions.Function1; - - @SuppressWarnings("all") - public class Foo { - public void foo(final Function1 func) { - final Function1 _function = new Function1() { - @Override - public String apply(final String it) { - return this.apply(it); - } - }; - this.foo(_function); - } - } - ''') - } - - @Test override testRecursiveLambda_02() { - ''' - public class Foo { - def void foo(()=>void func) { - foo[|self.apply()] - } - } - '''.assertCompilesTo(''' - import org.eclipse.xtext.xbase.lib.Procedures.Procedure0; - - @SuppressWarnings("all") - public class Foo { - public void foo(final Procedure0 func) { - final Procedure0 _function = new Procedure0() { - @Override - public void apply() { - this.apply(); - } - }; - this.foo(_function); - } - } - ''') - } - - @Test override testXFunctionTypeRefAsSuperType_01() { - ''' - class Foo implements ()=>void { - override apply() { - } - } - '''.assertCompilesTo(''' - import org.eclipse.xtext.xbase.lib.Procedures.Procedure0; - - @SuppressWarnings("all") - public class Foo implements Procedure0 { - @Override - public void apply() { - } - } - ''') - } - - @Test override testXFunctionTypeRefAsSuperType_02() { - ''' - interface Foo extends ()=>void { - override void apply() - } - '''.assertCompilesTo(''' - import org.eclipse.xtext.xbase.lib.Procedures.Procedure0; - - @SuppressWarnings("all") - public interface Foo extends Procedure0 { - @Override - void apply(); - } - ''') - } - - @Test override testXFunctionTypeRefAsSuperType_03() { - ''' - class Foo implements (String)=>void { - override apply(String value) { - } - } - '''.assertCompilesTo(''' - import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; - - @SuppressWarnings("all") - public class Foo implements Procedure1 { - @Override - public void apply(final String value) { - } - } - ''') - } - - @Test override testXFunctionTypeRefAsSuperType_04() { - ''' - interface Foo extends (String)=>void { - override void apply(String value) - } - '''.assertCompilesTo(''' - import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; - - @SuppressWarnings("all") - public interface Foo extends Procedure1 { - @Override - void apply(final String value); - } - ''') - } - - @Test override testXFunctionTypeRefAsSuperType_05() { - ''' - class Foo implements ((String)=>void)=>void { - override apply((String)=>void procedure) { - } - } - '''.assertCompilesTo(''' - import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; - - @SuppressWarnings("all") - public class Foo implements Procedure1> { - @Override - public void apply(final Procedure1 procedure) { - } - } - ''') - } - - @Test override testXFunctionTypeRefAsSuperType_06() { - ''' - interface Foo extends ((String)=>void)=>void { - override void apply((String)=>void procedure) - } - '''.assertCompilesTo(''' - import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; - - @SuppressWarnings("all") - public interface Foo extends Procedure1> { - @Override - void apply(final Procedure1 procedure); - } - ''') - } - - @Test override testXFunctionTypeRefAsSuperType_07() { - ''' - class Foo implements ()=>String { - override apply() { - } - } - '''.assertCompilesTo(''' - import org.eclipse.xtext.xbase.lib.Functions.Function0; - - @SuppressWarnings("all") - public class Foo implements Function0 { - @Override - public String apply() { - return null; - } - } - ''') - } - - @Test override testXFunctionTypeRefAsSuperType_08() { - ''' - interface Foo extends ()=>String { - override String apply() - } - '''.assertCompilesTo(''' - import org.eclipse.xtext.xbase.lib.Functions.Function0; - - @SuppressWarnings("all") - public interface Foo extends Function0 { - @Override - String apply(); - } - ''') - } - - @Test override testXFunctionTypeRefAsSuperType_09() { - ''' - class Foo implements ()=>(String)=>void { - override apply() { - } - } - '''.assertCompilesTo(''' - import org.eclipse.xtext.xbase.lib.Functions.Function0; - import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; - - @SuppressWarnings("all") - public class Foo implements Function0> { - @Override - public Procedure1 apply() { - return null; - } - } - ''') - } - - @Test override testXFunctionTypeRefAsSuperType_10() { - ''' - interface Foo extends ()=>(String)=>void { - override (String)=>void apply(); - } - '''.assertCompilesTo(''' - import org.eclipse.xtext.xbase.lib.Functions.Function0; - import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; - - @SuppressWarnings("all") - public interface Foo extends Function0> { - @Override - Procedure1 apply(); - } - ''') - } - - @Test override testSuperCall_01() { - ''' - package x class Y extends Object { - override boolean equals(Object p){ - if ('foo' == p) - return true - else - super.equals(p) - } - } - '''.assertCompilesTo(''' - package x; - - import java.util.Objects; - - @SuppressWarnings("all") - public class Y { - @Override - public boolean equals(final Object p) { - boolean _xifexpression = false; - boolean _equals = Objects.equals("foo", p); - if (_equals) { - return true; - } else { - _xifexpression = super.equals(p); - } - return _xifexpression; - } - } - ''') - } - - @Test override testSuperCall_03() { - ''' - package x - class B extends A { - override getThing() { - this.getThing('') - ''.getThing - this.thing - ''.thing - thing - getThing('') - super.getThing('') - super.thing - super.getThing - super.getThing() - } - } - class A { - def String getThing() { - getThing('') - } - def protected String getThing(String s) { - return s - } - } - '''.assertCompilesTo(''' - package x; - - @SuppressWarnings("all") - public class B extends A { - @Override - public String getThing() { - String _xblockexpression = null; - { - this.getThing(""); - this.getThing(""); - this.getThing(); - this.getThing(""); - this.getThing(); - this.getThing(""); - super.getThing(""); - super.getThing(); - super.getThing(); - _xblockexpression = super.getThing(); - } - return _xblockexpression; - } - } - ''') - } - - /** - * see https://bugs.eclipse.org/bugs/show_bug.cgi?id=395043 - */ - @Test override testOverriddenVarArgs() { - ''' - class B extends A { - override foo(String x, String...args) { - return x - } - } - abstract class A { - def String foo(String x, String...args) - } - - '''.assertCompilesTo(''' - @SuppressWarnings("all") - public class B extends A { - @Override - public String foo(final String x, final String... args) { - return x; - } - } - ''') - } - - @Test override testExpectationFromTypeParameter() { - ''' - import java.util.Set - import org.eclipse.xtext.common.types.JvmTypeParameter - import org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference - import org.eclipse.xtext.xbase.typesystem.util.TypeParameterSubstitutor - import org.eclipse.xtext.xbase.typesystem.references.ITypeReferenceOwner - - class C extends TypeParameterSubstitutor> { - - new(ITypeReferenceOwner owner) { - super(null, owner) - } - - override substitute(LightweightTypeReference original) { - original.accept(this, newHashSet) - } - - override protected createVisiting() { - return newHashSet - } - } - '''.assertCompilesTo(''' - import java.util.Set; - import org.eclipse.xtext.common.types.JvmTypeParameter; - import org.eclipse.xtext.xbase.lib.CollectionLiterals; - import org.eclipse.xtext.xbase.typesystem.references.ITypeReferenceOwner; - import org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference; - import org.eclipse.xtext.xbase.typesystem.util.TypeParameterSubstitutor; - - @SuppressWarnings("all") - public class C extends TypeParameterSubstitutor> { - public C(final ITypeReferenceOwner owner) { - super(null, owner); - } - - @Override - public LightweightTypeReference substitute(final LightweightTypeReference original) { - return original., LightweightTypeReference>accept(this, CollectionLiterals.newHashSet()); - } - - @Override - protected Set createVisiting() { - return CollectionLiterals.newHashSet(); - } - } - ''') - } - - @Test override testJavaKeywordsUsed() { - ''' - package foo; - - public class Foo { - def void someMethod(String assert) { - val synchronized = newArrayList('foo') - for (volatile : synchronized) { - switch continue : volatile { - case continue.length > 2 : synchronized.forEach(break | (break + continue).toString) - } - } - } - } - '''.assertCompilesTo(''' - package foo; - - import java.util.ArrayList; - import java.util.function.Consumer; - import org.eclipse.xtext.xbase.lib.CollectionLiterals; - - @SuppressWarnings("all") - public class Foo { - public void someMethod(final String assert_) { - final ArrayList synchronized_ = CollectionLiterals.newArrayList("foo"); - for (final String volatile_ : synchronized_) { - final String continue_ = volatile_; - boolean _matched = false; - int _length = continue_.length(); - boolean _greaterThan = (_length > 2); - if (_greaterThan) { - _matched=true; - final Consumer _function = (String break_) -> { - (break_ + continue_).toString(); - }; - synchronized_.forEach(_function); - } - } - } - } - ''') - } - -} \ No newline at end of file diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/compiler/TryWithResourcesJava8Test.xtend b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/compiler/TryWithResourcesJava8Test.xtend index 3ef01fc8ad7..030a3c31fca 100644 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/compiler/TryWithResourcesJava8Test.xtend +++ b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/compiler/TryWithResourcesJava8Test.xtend @@ -10,9 +10,7 @@ package org.eclipse.xtend.core.tests.java8.compiler import com.google.inject.Inject import org.eclipse.xtend.core.tests.compiler.AbstractXtendCompilerTest -import org.eclipse.xtend.core.tests.java8.Java8RuntimeInjectorProvider import org.eclipse.xtend.core.xtend.XtendFile -import org.eclipse.xtext.testing.InjectWith import org.eclipse.xtext.testing.util.ParseHelper import org.eclipse.xtext.testing.validation.ValidationTestHelper import org.eclipse.xtext.xbase.XbasePackage @@ -22,7 +20,6 @@ import org.junit.Test /** * @author Eva Poell - Initial contribution and API */ -@InjectWith(Java8RuntimeInjectorProvider) class TryWithResourcesJava8Test extends AbstractXtendCompilerTest { @Inject extension ValidationTestHelper diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/macro/DeclarationsTest.xtend b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/macro/DeclarationsTest.xtend index 66bb451265d..7bf616473a5 100644 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/macro/DeclarationsTest.xtend +++ b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/macro/DeclarationsTest.xtend @@ -8,12 +8,9 @@ *******************************************************************************/ package org.eclipse.xtend.core.tests.java8.macro -import org.eclipse.xtend.core.tests.java8.Java8RuntimeInjectorProvider import org.eclipse.xtend.lib.macro.declaration.InterfaceDeclaration -import org.eclipse.xtext.testing.InjectWith import org.junit.Test -@InjectWith(Java8RuntimeInjectorProvider) class DeclarationsTest extends org.eclipse.xtend.core.tests.macro.declaration.DeclarationsTest { @Test def testXtendInterfaceWithDefaultMethod() { diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/validation/Java8ValidationTest.xtend b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/validation/Java8ValidationTest.xtend index e797a5ff201..5de2038ac67 100644 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/validation/Java8ValidationTest.xtend +++ b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/java8/validation/Java8ValidationTest.xtend @@ -10,9 +10,7 @@ package org.eclipse.xtend.core.tests.java8.validation import com.google.inject.Inject import org.eclipse.xtend.core.tests.AbstractXtendTestCase -import org.eclipse.xtend.core.tests.java8.Java8RuntimeInjectorProvider import org.eclipse.xtext.diagnostics.Severity -import org.eclipse.xtext.testing.InjectWith import org.eclipse.xtext.testing.validation.ValidationTestHelper import org.junit.Test @@ -23,7 +21,6 @@ import static org.eclipse.xtext.xbase.validation.IssueCodes.* /** * @author Miro Spoenemann - Initial contribution and API */ -@InjectWith(Java8RuntimeInjectorProvider) class Java8ValidationTest extends AbstractXtendTestCase { @Inject extension ValidationTestHelper diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/linking/InferredJvmModelTest.java b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/linking/InferredJvmModelTest.java index 702ec3c3849..8fc2dc39255 100644 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/linking/InferredJvmModelTest.java +++ b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/linking/InferredJvmModelTest.java @@ -601,7 +601,7 @@ public boolean apply(JvmOperation input) { assertEquals(1, typeParameter.getConstraints().size()); JvmTypeConstraint typeConstraint = typeParameter.getConstraints().get(0); assertTrue(typeConstraint instanceof JvmUpperBound); - assertEquals(inferredType, ((JvmUpperBound) typeConstraint).getTypeReference().getType()); + assertEquals(inferredType, typeConstraint.getTypeReference().getType()); } @Test public void testInferredFunction_01() throws Exception { @@ -733,7 +733,7 @@ public boolean apply(JvmOperation input) { JvmGenericType inferredType = getInferredType(xtendFile); assertTrue(inferredType.getMembers().get(0) instanceof JvmConstructor); JvmOperation jvmOperation = (JvmOperation) inferredType.getMembers().get(1); - XtendFunction xtendFunction = (XtendFunction) ((XtendClass)xtendFile.getXtendTypes().get(0)).getMembers().get(0); + XtendFunction xtendFunction = (XtendFunction) xtendFile.getXtendTypes().get(0).getMembers().get(0); assertFalse(xtendFunction.getReturnType() == jvmOperation.getReturnType()); assertEquals(xtendFunction.getReturnType().getType(), jvmOperation.getReturnType().getType()); } @@ -743,7 +743,7 @@ public boolean apply(JvmOperation input) { JvmGenericType inferredType = getInferredType(xtendFile); assertTrue(inferredType.getMembers().get(0) instanceof JvmConstructor); JvmOperation jvmOperation = (JvmOperation) inferredType.getMembers().get(1); - XtendFunction xtendFunction = (XtendFunction) ((XtendClass)xtendFile.getXtendTypes().get(0)).getMembers().get(0); + XtendFunction xtendFunction = (XtendFunction) xtendFile.getXtendTypes().get(0).getMembers().get(0); assertFalse(xtendFunction.getReturnType() == jvmOperation.getReturnType()); assertEquals(xtendFunction.getReturnType().getType(), jvmOperation.getReturnType().getType()); } @@ -801,7 +801,7 @@ public boolean apply(JvmOperation input) { XtendFile xtendFile = file("class Foo { def bar(Boolean baz) { true } }"); JvmGenericType inferredType = getInferredType(xtendFile); JvmOperation jvmOperation = (JvmOperation) inferredType.getMembers().get(1); - XtendFunction xtendFunction = (XtendFunction) ((XtendClass)xtendFile.getXtendTypes().get(0)).getMembers().get(0); + XtendFunction xtendFunction = (XtendFunction) xtendFile.getXtendTypes().get(0).getMembers().get(0); assertEquals(1, jvmOperation.getParameters().size()); JvmFormalParameter jvmParameter = jvmOperation.getParameters().get(0); XtendParameter xtendParameter = xtendFunction.getParameters().get(0); @@ -814,7 +814,7 @@ public boolean apply(JvmOperation input) { JvmGenericType inferredType = getInferredType(xtendFile); JvmOperation jvmOperation = (JvmOperation) inferredType.getMembers().get(1); assertEquals(inferredType, jvmOperation.getReturnType().getType()); - XtendFunction xtendFunction = (XtendFunction) ((XtendClass)xtendFile.getXtendTypes().get(0)).getMembers().get(0); + XtendFunction xtendFunction = (XtendFunction) xtendFile.getXtendTypes().get(0).getMembers().get(0); assertEquals(inferredType, xtendFunction.getReturnType().getType()); } @@ -913,7 +913,7 @@ public void testInferredFunctionWithTypeParameter() throws Exception { assertEquals("java.util.List", jvmOperation.getReturnType().getIdentifier()); JvmTypeReference argument = ((JvmParameterizedTypeReference)jvmOperation.getReturnType()).getArguments().get(0); assertSame(inferredType, ((JvmTypeParameter)argument.getType()).getDeclarator()); - XtendFunction xtendFunction = (XtendFunction) ((XtendClass)xtendFile.getXtendTypes().get(0)).getMembers().get(0); + XtendFunction xtendFunction = (XtendFunction) xtendFile.getXtendTypes().get(0).getMembers().get(0); assertEquals("java.util.List", xtendFunction.getReturnType().getIdentifier()); } diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/linking/LinkingTest.java b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/linking/LinkingTest.java index c028a798b0f..8eb4b4de085 100644 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/linking/LinkingTest.java +++ b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/linking/LinkingTest.java @@ -1542,7 +1542,7 @@ public boolean apply(JvmOperation input) { } @Test public void testTypeParameterReference_0() throws Exception { - XtendFunction func = (XtendFunction) ((XtendClass)file("import java.lang.* class X { def String foo(String x) {x}}").getXtendTypes().get(0)).getMembers().get(0); + XtendFunction func = (XtendFunction) file("import java.lang.* class X { def String foo(String x) {x}}").getXtendTypes().get(0).getMembers().get(0); JvmTypeReference returnType = func.getReturnType(); JvmTypeParameter typeParamDecl = (JvmTypeParameter) returnType.getType(); assertEquals("String", typeParamDecl.getIdentifier()); @@ -1553,8 +1553,8 @@ public boolean apply(JvmOperation input) { } @Test public void testTypeParameterReference_1() throws Exception { - XtendFunction func = (XtendFunction) ((XtendClass)file("import java.lang.* class X { def String foo(java.lang.String x) {x}}") - .getXtendTypes().get(0)).getMembers().get(0); + XtendFunction func = (XtendFunction) file("import java.lang.* class X { def String foo(java.lang.String x) {x}}") + .getXtendTypes().get(0).getMembers().get(0); JvmTypeReference returnType = func.getReturnType(); JvmTypeParameter typeParamDecl = (JvmTypeParameter) returnType.getType(); assertEquals("String", typeParamDecl.getIdentifier()); @@ -1565,8 +1565,8 @@ public boolean apply(JvmOperation input) { } @Test public void testTypeParameterReference_2() throws Exception { - XtendFunction func = (XtendFunction) ((XtendClass)file("class X { def foo(Y y) { return y }}") - .getXtendTypes().get(0)).getMembers().get(0); + XtendFunction func = (XtendFunction) file("class X { def foo(Y y) { return y }}") + .getXtendTypes().get(0).getMembers().get(0); JvmOperation operation = associator.getDirectlyInferredOperation(func); JvmTypeReference returnType = operation.getReturnType(); assertEquals("Y", returnType.getIdentifier()); @@ -1576,8 +1576,8 @@ public boolean apply(JvmOperation input) { } @Test public void testTypeParameterReference_3() throws Exception { - XtendFunction func = (XtendFunction) ((XtendClass)file("class X { def foo(Iterable ys) { return newArrayList(ys.head) }}") - .getXtendTypes().get(0)).getMembers().get(0); + XtendFunction func = (XtendFunction) file("class X { def foo(Iterable ys) { return newArrayList(ys.head) }}") + .getXtendTypes().get(0).getMembers().get(0); JvmOperation operation = associator.getDirectlyInferredOperation(func); JvmTypeReference returnType = operation.getReturnType(); assertEquals("java.util.ArrayList", returnType.getIdentifier()); @@ -1587,8 +1587,8 @@ public boolean apply(JvmOperation input) { } @Test public void testTypeParameterReference_4() throws Exception { - XtendFunction func = (XtendFunction) ((XtendClass)file("class X { def foo(Y y) { return y }}") - .getXtendTypes().get(0)).getMembers().get(0); + XtendFunction func = (XtendFunction) file("class X { def foo(Y y) { return y }}") + .getXtendTypes().get(0).getMembers().get(0); JvmOperation operation = associator.getDirectlyInferredOperation(func); JvmTypeReference returnType = operation.getReturnType(); assertEquals("Y", returnType.getIdentifier()); @@ -1598,8 +1598,8 @@ public boolean apply(JvmOperation input) { } @Test public void testTypeParameterReference_5() throws Exception { - XtendFunction func = (XtendFunction) ((XtendClass)file("class X { def foo(Iterable ys) { return newArrayList(ys.head) }}") - .getXtendTypes().get(0)).getMembers().get(0); + XtendFunction func = (XtendFunction) file("class X { def foo(Iterable ys) { return newArrayList(ys.head) }}") + .getXtendTypes().get(0).getMembers().get(0); JvmOperation operation = associator.getDirectlyInferredOperation(func); JvmTypeReference returnType = operation.getReturnType(); assertEquals("java.util.ArrayList", returnType.getIdentifier()); @@ -1609,32 +1609,32 @@ public boolean apply(JvmOperation input) { } @Test public void testTypeParameterReference_6() throws Exception { - XtendFunction func = (XtendFunction) ((XtendClass)file("class X { def foo() { val result = new X return result }}") - .getXtendTypes().get(0)).getMembers().get(0); + XtendFunction func = (XtendFunction) file("class X { def foo() { val result = new X return result }}") + .getXtendTypes().get(0).getMembers().get(0); JvmOperation operation = associator.getDirectlyInferredOperation(func); JvmTypeReference returnType = operation.getReturnType(); assertEquals("X", returnType.getIdentifier()); } @Test public void testTypeParameterReference_7() throws Exception { - XtendFunction func = (XtendFunction) ((XtendClass)file("class X { def foo() { return new X }}") - .getXtendTypes().get(0)).getMembers().get(0); + XtendFunction func = (XtendFunction) file("class X { def foo() { return new X }}") + .getXtendTypes().get(0).getMembers().get(0); JvmOperation operation = associator.getDirectlyInferredOperation(func); JvmTypeReference returnType = operation.getReturnType(); assertEquals("X", returnType.getIdentifier()); } @Test public void testTypeParameterReference_8() throws Exception { - XtendFunction func = (XtendFunction) ((XtendClass)file("class X { def foo() { return new X }}") - .getXtendTypes().get(0)).getMembers().get(0); + XtendFunction func = (XtendFunction) file("class X { def foo() { return new X }}") + .getXtendTypes().get(0).getMembers().get(0); JvmOperation operation = associator.getDirectlyInferredOperation(func); JvmTypeReference returnType = operation.getReturnType(); assertEquals("X", returnType.getIdentifier()); } @Test public void testTypeParameterReference_9() throws Exception { - XtendFunction func = (XtendFunction) ((XtendClass)file("class X { def foo(Iterable iter) { for(y: iter) { return y } }}") - .getXtendTypes().get(0)).getMembers().get(0); + XtendFunction func = (XtendFunction) file("class X { def foo(Iterable iter) { for(y: iter) { return y } }}") + .getXtendTypes().get(0).getMembers().get(0); JvmOperation operation = associator.getDirectlyInferredOperation(func); JvmTypeReference returnType = operation.getReturnType(); assertEquals("Y", returnType.getIdentifier()); @@ -1644,8 +1644,8 @@ public boolean apply(JvmOperation input) { } @Test public void testTypeParameterReference_10() throws Exception { - XtendFunction func = (XtendFunction) ((XtendClass)file("class X { def foo(Iterable iter) { for(y: iter) { return y } null }}") - .getXtendTypes().get(0)).getMembers().get(0); + XtendFunction func = (XtendFunction) file("class X { def foo(Iterable iter) { for(y: iter) { return y } null }}") + .getXtendTypes().get(0).getMembers().get(0); JvmOperation operation = associator.getDirectlyInferredOperation(func); JvmTypeReference returnType = operation.getReturnType(); assertEquals("Y", returnType.getIdentifier()); @@ -1655,8 +1655,8 @@ public boolean apply(JvmOperation input) { } @Test public void testTypeParameterReference_11() throws Exception { - XtendFunction func = (XtendFunction) ((XtendClass)file("class X implements Iterable { def Iterable foo() { val result = new X result }}") - .getXtendTypes().get(0)).getMembers().get(0); + XtendFunction func = (XtendFunction) file("class X implements Iterable { def Iterable foo() { val result = new X result }}") + .getXtendTypes().get(0).getMembers().get(0); JvmOperation operation = associator.getDirectlyInferredOperation(func); JvmTypeReference returnType = operation.getReturnType(); assertEquals("java.lang.Iterable", returnType.getIdentifier()); @@ -1679,8 +1679,8 @@ protected LightweightTypeReference getType(JvmIdentifiableElement identifiable) } @Test public void testTypeParameterReference_12() throws Exception { - XtendFunction func = (XtendFunction) ((XtendClass)file("class X implements Iterable { def Iterable foo() { val result = new X return result }}") - .getXtendTypes().get(0)).getMembers().get(0); + XtendFunction func = (XtendFunction) file("class X implements Iterable { def Iterable foo() { val result = new X return result }}") + .getXtendTypes().get(0).getMembers().get(0); JvmOperation operation = associator.getDirectlyInferredOperation(func); JvmTypeReference returnType = operation.getReturnType(); assertEquals("java.lang.Iterable", returnType.getIdentifier()); @@ -1691,8 +1691,8 @@ protected LightweightTypeReference getType(JvmIdentifiableElement identifiable) } @Test public void testTypeParameterReference_13() throws Exception { - XtendFunction func = (XtendFunction) ((XtendClass)file("class X implements Iterable { def Iterable foo() { val r = new X return r }}") - .getXtendTypes().get(0)).getMembers().get(0); + XtendFunction func = (XtendFunction) file("class X implements Iterable { def Iterable foo() { val r = new X return r }}") + .getXtendTypes().get(0).getMembers().get(0); JvmOperation operation = associator.getDirectlyInferredOperation(func); JvmTypeReference returnType = operation.getReturnType(); assertEquals("java.lang.Iterable", returnType.getIdentifier()); @@ -1703,16 +1703,16 @@ protected LightweightTypeReference getType(JvmIdentifiableElement identifiable) } @Test public void testTypeParameterReference_14() throws Exception { - XtendFunction func = (XtendFunction) ((XtendClass)file("class X { def foo() { new X }}") - .getXtendTypes().get(0)).getMembers().get(0); + XtendFunction func = (XtendFunction) file("class X { def foo() { new X }}") + .getXtendTypes().get(0).getMembers().get(0); JvmOperation operation = associator.getDirectlyInferredOperation(func); JvmTypeReference returnType = operation.getReturnType(); assertEquals("X", returnType.getIdentifier()); } @Test public void testTypeParameterReference_15() throws Exception { - XtendFunction func = (XtendFunction) ((XtendClass)file("class X implements Iterable { def Iterable foo() { val result = new X result }}") - .getXtendTypes().get(0)).getMembers().get(0); + XtendFunction func = (XtendFunction) file("class X implements Iterable { def Iterable foo() { val result = new X result }}") + .getXtendTypes().get(0).getMembers().get(0); JvmOperation operation = associator.getDirectlyInferredOperation(func); JvmTypeReference returnType = operation.getReturnType(); assertEquals("java.lang.Iterable", returnType.getIdentifier()); @@ -1723,8 +1723,8 @@ protected LightweightTypeReference getType(JvmIdentifiableElement identifiable) } @Test public void testTypeParameterReference_16() throws Exception { - XtendFunction func = (XtendFunction) ((XtendClass)file("class X implements Iterable { def Iterable foo() { val r = new X r }}") - .getXtendTypes().get(0)).getMembers().get(0); + XtendFunction func = (XtendFunction) file("class X implements Iterable { def Iterable foo() { val r = new X r }}") + .getXtendTypes().get(0).getMembers().get(0); JvmOperation operation = associator.getDirectlyInferredOperation(func); JvmTypeReference returnType = operation.getReturnType(); assertEquals("java.lang.Iterable", returnType.getIdentifier()); @@ -1735,24 +1735,24 @@ protected LightweightTypeReference getType(JvmIdentifiableElement identifiable) } @Test public void testTypeParameterReference_17() throws Exception { - XtendFunction func = (XtendFunction) ((XtendClass)file("class X { def foo() { val result = new X result }}") - .getXtendTypes().get(0)).getMembers().get(0); + XtendFunction func = (XtendFunction) file("class X { def foo() { val result = new X result }}") + .getXtendTypes().get(0).getMembers().get(0); JvmOperation operation = associator.getDirectlyInferredOperation(func); JvmTypeReference returnType = operation.getReturnType(); assertEquals("X", returnType.getIdentifier()); } @Test public void testTypeParameterReference_18() throws Exception { - XtendFunction func = (XtendFunction) ((XtendClass)file("class X { def foo() { new X }}") - .getXtendTypes().get(0)).getMembers().get(0); + XtendFunction func = (XtendFunction) file("class X { def foo() { new X }}") + .getXtendTypes().get(0).getMembers().get(0); JvmOperation operation = associator.getDirectlyInferredOperation(func); JvmTypeReference returnType = operation.getReturnType(); assertEquals("X", returnType.getIdentifier()); } @Test public void testTypeParameterReference_19() throws Exception { - XtendFunction func = (XtendFunction) ((XtendClass)file("class X { def foo() { return new X }}") - .getXtendTypes().get(0)).getMembers().get(0); + XtendFunction func = (XtendFunction) file("class X { def foo() { return new X }}") + .getXtendTypes().get(0).getMembers().get(0); JvmOperation operation = associator.getDirectlyInferredOperation(func); JvmTypeReference returnType = operation.getReturnType(); assertEquals("X", returnType.getIdentifier()); @@ -1760,16 +1760,16 @@ protected LightweightTypeReference getType(JvmIdentifiableElement identifiable) @Test public void testTypeParameterReference_20() throws Exception { - XtendFunction func = (XtendFunction) ((XtendClass)file("class X { def foo() { return new X }}") - .getXtendTypes().get(0)).getMembers().get(0); + XtendFunction func = (XtendFunction) file("class X { def foo() { return new X }}") + .getXtendTypes().get(0).getMembers().get(0); JvmOperation operation = associator.getDirectlyInferredOperation(func); JvmTypeReference returnType = operation.getReturnType(); assertEquals("X", returnType.getIdentifier()); } @Test public void testTypeParameterShadowsType_1() throws Exception { - XtendFunction func = (XtendFunction) ((XtendClass) file("class A {} class B { def A foo(A x) {x}}") - .getXtendTypes().get(1)).getMembers().get(0); + XtendFunction func = (XtendFunction) file("class A {} class B { def A foo(A x) {x}}") + .getXtendTypes().get(1).getMembers().get(0); JvmTypeReference returnType = func.getReturnType(); JvmTypeParameter typeParamDecl = (JvmTypeParameter) returnType.getType(); @@ -1780,8 +1780,8 @@ protected LightweightTypeReference getType(JvmIdentifiableElement identifiable) } @Test public void testTypeParameterShadowsType_2() throws Exception { - XtendFunction func = (XtendFunction) ((XtendClass) file("class A {} class B { def A foo(A x) {x}}") - .getXtendTypes().get(1)).getMembers().get(0); + XtendFunction func = (XtendFunction) file("class A {} class B { def A foo(A x) {x}}") + .getXtendTypes().get(1).getMembers().get(0); JvmTypeReference returnType = func.getReturnType(); JvmTypeParameter typeParamDecl = (JvmTypeParameter) returnType.getType(); @@ -2304,7 +2304,7 @@ protected LightweightTypeReference getType(JvmIdentifiableElement identifiable) @Test public void testStaticImports_03() throws Exception { String fileAsText= "import static extension java.util.Collections.* class Clazz { def void method() {''.singletonList()} }"; XtendFile file = file(fileAsText, true); - XtendFunction function = (XtendFunction) ((XtendClass) file.getXtendTypes().get(0)).getMembers().get(0); + XtendFunction function = (XtendFunction) file.getXtendTypes().get(0).getMembers().get(0); XMemberFeatureCall featureCall = (XMemberFeatureCall) ((XBlockExpression)function.getExpression()).getExpressions().get(0); String identifier = featureCall.getFeature().getIdentifier(); assertEquals("java.util.Collections.singletonList(T)", identifier); @@ -2313,7 +2313,7 @@ protected LightweightTypeReference getType(JvmIdentifiableElement identifiable) @Test public void testStaticImports_04() throws Exception { String fileAsText= "import static extension java.util.Collections.* class Clazz { def void method() {''.singletonList} }"; XtendFile file = file(fileAsText, true); - XtendFunction function = (XtendFunction) ((XtendClass) file.getXtendTypes().get(0)).getMembers().get(0); + XtendFunction function = (XtendFunction) file.getXtendTypes().get(0).getMembers().get(0); XMemberFeatureCall featureCall = (XMemberFeatureCall) ((XBlockExpression)function.getExpression()).getExpressions().get(0); String identifier = featureCall.getFeature().getIdentifier(); assertEquals("java.util.Collections.singletonList(T)", identifier); @@ -2322,7 +2322,7 @@ protected LightweightTypeReference getType(JvmIdentifiableElement identifiable) @Test public void testStaticImports_05() throws Exception { String fileAsText= "import static java.util.Collections.* class Clazz { def void method() {singletonList('')} }"; XtendFile file = file(fileAsText, true); - XtendFunction function = (XtendFunction) ((XtendClass) file.getXtendTypes().get(0)).getMembers().get(0); + XtendFunction function = (XtendFunction) file.getXtendTypes().get(0).getMembers().get(0); XFeatureCall featureCall = (XFeatureCall) ((XBlockExpression)function.getExpression()).getExpressions().get(0); String identifier = featureCall.getFeature().getIdentifier(); assertEquals("java.util.Collections.singletonList(T)", identifier); @@ -2334,7 +2334,7 @@ protected LightweightTypeReference getType(JvmIdentifiableElement identifiable) "import static java.util.Collections.*\n" + "class Clazz { def void method() {find(singletonList(''), [e|e!=null])} }"; XtendFile file = file(fileAsText, true); - XtendFunction function = (XtendFunction) ((XtendClass) file.getXtendTypes().get(0)).getMembers().get(0); + XtendFunction function = (XtendFunction) file.getXtendTypes().get(0).getMembers().get(0); XFeatureCall featureCall = (XFeatureCall) ((XBlockExpression)function.getExpression()).getExpressions().get(0); String identifier = featureCall.getFeature().getIdentifier(); assertEquals("com.google.common.collect.Iterables.find(java.lang.Iterable,com.google.common.base.Predicate)", identifier); @@ -2346,7 +2346,7 @@ protected LightweightTypeReference getType(JvmIdentifiableElement identifiable) "import static java.util.Collections.*\n" + "class Clazz { def void method() {find(singletonList(''), [e|e!=null])} }"; XtendFile file = file(fileAsText, true); - XtendFunction function = (XtendFunction) ((XtendClass) file.getXtendTypes().get(0)).getMembers().get(0); + XtendFunction function = (XtendFunction) file.getXtendTypes().get(0).getMembers().get(0); XFeatureCall featureCall = (XFeatureCall) ((XBlockExpression)function.getExpression()).getExpressions().get(0); String identifier = featureCall.getFeature().getIdentifier(); assertEquals("com.google.common.collect.Iterables.find(java.lang.Iterable,com.google.common.base.Predicate)", identifier); @@ -2358,7 +2358,7 @@ protected LightweightTypeReference getType(JvmIdentifiableElement identifiable) "import static java.util.Collections.*\n" + "class Clazz { def void method() {singletonList('').findFirst(e|e!=null)} }"; XtendFile file = file(fileAsText, true); - XtendFunction function = (XtendFunction) ((XtendClass) file.getXtendTypes().get(0)).getMembers().get(0); + XtendFunction function = (XtendFunction) file.getXtendTypes().get(0).getMembers().get(0); XMemberFeatureCall featureCall = (XMemberFeatureCall) ((XBlockExpression)function.getExpression()).getExpressions().get(0); String identifier = featureCall.getFeature().getIdentifier(); assertEquals("org.eclipse.xtext.xbase.lib.IterableExtensions.findFirst(java.lang.Iterable,org.eclipse.xtext.xbase.lib.Functions$Function1)", identifier); @@ -2367,7 +2367,7 @@ protected LightweightTypeReference getType(JvmIdentifiableElement identifiable) @Test public void testStaticImports_09() throws Exception { String fileAsText= "import static java.util.Collections.* class Clazz { def void method() {singletonList('').findFirst(String e|e!=null)} }"; XtendFile file = file(fileAsText, true); - XtendFunction function = (XtendFunction) ((XtendClass) file.getXtendTypes().get(0)).getMembers().get(0); + XtendFunction function = (XtendFunction) file.getXtendTypes().get(0).getMembers().get(0); XMemberFeatureCall featureCall = (XMemberFeatureCall) ((XBlockExpression)function.getExpression()).getExpressions().get(0); String identifier = featureCall.getFeature().getIdentifier(); assertEquals("org.eclipse.xtext.xbase.lib.IterableExtensions.findFirst(java.lang.Iterable,org.eclipse.xtext.xbase.lib.Functions$Function1)", identifier); @@ -2376,7 +2376,7 @@ protected LightweightTypeReference getType(JvmIdentifiableElement identifiable) @Test public void testStaticImports_10() throws Exception { String fileAsText= "import static extension java.util.Collections.* class Clazz { def void method() { singletonList('')} }"; XtendFile file = file(fileAsText, true); - XtendFunction function = (XtendFunction) ((XtendClass) file.getXtendTypes().get(0)).getMembers().get(0); + XtendFunction function = (XtendFunction) file.getXtendTypes().get(0).getMembers().get(0); XFeatureCall featureCall = (XFeatureCall) ((XBlockExpression)function.getExpression()).getExpressions().get(0); String identifier = featureCall.getFeature().getIdentifier(); assertEquals("java.util.Collections.singletonList(T)", identifier); @@ -2388,7 +2388,7 @@ protected LightweightTypeReference getType(JvmIdentifiableElement identifiable) "import static java.util.Collections.*\n" + "class Clazz { def void method() {find(singletonList(''), [e|e.length!=0])} }"; XtendFile file = file(fileAsText, true); - XtendFunction function = (XtendFunction) ((XtendClass) file.getXtendTypes().get(0)).getMembers().get(0); + XtendFunction function = (XtendFunction) file.getXtendTypes().get(0).getMembers().get(0); XFeatureCall featureCall = (XFeatureCall) ((XBlockExpression)function.getExpression()).getExpressions().get(0); String identifier = featureCall.getFeature().getIdentifier(); assertEquals("com.google.common.collect.Iterables.find(java.lang.Iterable,com.google.common.base.Predicate)", identifier); @@ -2400,7 +2400,7 @@ protected LightweightTypeReference getType(JvmIdentifiableElement identifiable) "import static java.util.Collections.*\n" + "class Clazz { def void method() { find(singletonList(''), [e|e.length!=0])} }"; XtendFile file = file(fileAsText, true); - XtendFunction function = (XtendFunction) ((XtendClass) file.getXtendTypes().get(0)).getMembers().get(0); + XtendFunction function = (XtendFunction) file.getXtendTypes().get(0).getMembers().get(0); XFeatureCall featureCall = (XFeatureCall) ((XBlockExpression)function.getExpression()).getExpressions().get(0); String identifier = featureCall.getFeature().getIdentifier(); assertEquals("com.google.common.collect.Iterables.find(java.lang.Iterable,com.google.common.base.Predicate)", identifier); @@ -2550,7 +2550,7 @@ protected LightweightTypeReference getType(JvmIdentifiableElement identifiable) "import org.eclipse.xtext.xbase.lib.Functions\n" + "class Clazz { def void method(Functions$Function0 f) { f.apply } }"; XtendFile file = file(fileAsText, true); - XtendFunction function = (XtendFunction) ((XtendClass) file.getXtendTypes().get(0)).getMembers().get(0); + XtendFunction function = (XtendFunction) file.getXtendTypes().get(0).getMembers().get(0); XtendParameter parameter = function.getParameters().get(0); String identifier = parameter.getParameterType().getIdentifier(); assertEquals(Functions.Function0.class.getName()+ "", identifier); @@ -2561,7 +2561,7 @@ protected LightweightTypeReference getType(JvmIdentifiableElement identifiable) "import org.eclipse.xtext.xbase.lib.Functions\n" + "class Clazz { def void method(Functions.Function0 f) { f.apply } }"; XtendFile file = file(fileAsText, true); - XtendFunction function = (XtendFunction) ((XtendClass) file.getXtendTypes().get(0)).getMembers().get(0); + XtendFunction function = (XtendFunction) file.getXtendTypes().get(0).getMembers().get(0); XtendParameter parameter = function.getParameters().get(0); String identifier = parameter.getParameterType().getIdentifier(); assertEquals(Functions.Function0.class.getName()+ "", identifier); diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/validation/ModifierValidationTest.xtend b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/validation/ModifierValidationTest.xtend index f58d17e02e6..762c9f27c99 100644 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/validation/ModifierValidationTest.xtend +++ b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/validation/ModifierValidationTest.xtend @@ -140,7 +140,7 @@ class ModifierValidationTest extends AbstractXtendTestCase { memberInInterface('''protected def foo() {}''').assertError(XTEND_FUNCTION, INVALID_MODIFIER) memberInInterface('''public def foo() {}''').assertNoError(INVALID_MODIFIER) memberInInterface('''override def foo() {}''').assertNoError(INVALID_MODIFIER) - memberInInterface('''static def foo() {}''').assertError(XTEND_FUNCTION, INVALID_MODIFIER) + memberInInterface('''static def foo() {}''').assertNoError(INVALID_MODIFIER) memberInInterface('''abstract def int foo()''').assertNoErrors memberInInterface('''dispatch def foo (int i){}''').assertError(XTEND_FUNCTION, INVALID_MODIFIER) memberInInterface('''final def foo() {}''').assertError(XTEND_FUNCTION, INVALID_MODIFIER) diff --git a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/validation/XtendValidationTest.java b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/validation/XtendValidationTest.java index e2cafde56aa..f3a12689858 100644 --- a/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/validation/XtendValidationTest.java +++ b/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/validation/XtendValidationTest.java @@ -1869,7 +1869,7 @@ protected void assertNoConformanceError(String body) throws Exception { @Test public void testNonAbstractMethodInInterface() throws Exception { XtendInterface clazz = interfaze("interface Foo { def test() {} }"); - helper.assertError(clazz.getMembers().get(0), XTEND_FUNCTION, ABSTRACT_METHOD_WITH_BODY); + helper.assertNoErrors(clazz.getMembers().get(0)); } @Test public void testAbstractMethodWithReturnType() throws Exception { diff --git a/org.eclipse.xtend.core.tests/suites/org/eclipse/xtend/core/tests/java8/compiler/Java8CompilerSuite.java b/org.eclipse.xtend.core.tests/suites/org/eclipse/xtend/core/tests/java8/compiler/Java8CompilerSuite.java deleted file mode 100644 index 93e1311154a..00000000000 --- a/org.eclipse.xtend.core.tests/suites/org/eclipse/xtend/core/tests/java8/compiler/Java8CompilerSuite.java +++ /dev/null @@ -1,49 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2013 itemis AG (http://www.itemis.eu) and others. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * SPDX-License-Identifier: EPL-2.0 - *******************************************************************************/ -package org.eclipse.xtend.core.tests.java8.compiler; - -import org.junit.runner.RunWith; -import org.junit.runners.Suite; -import org.junit.runners.Suite.SuiteClasses; - -/** - * @author Sebastian Zarnekow - Initial contribution and API - */ -@RunWith(Suite.class) -@SuiteClasses({ - CompilerBug342021Test.class, - CompilerBug383534Test.class, - CompilerBug404051Test.class, - CompilerBug405825Test.class, - CompilerBug406425Test.class, - CompilerBug410797Test.class, - CompilerBug412894Test.class, - CompilerBug421999Test.class, - CompilerBug427637Test.class, - CompilerBug428063Test.class, - CompilerBug432193Test.class, - CompilerBug435473Test.class, - CompilerBug436230Test.class, - CompilerBug440906Test.class, - CompilerBug445487Test.class, - CompilerBug447516Test.class, - CompilerBug457333Test.class, - CompilerBug457346Test.class, - CompilerBug457539Test.class, - CompilerBug458010Test.class, - CompilerBug460691Test.class, - CompilerBug462845Test.class, - CompilerBug465058Test.class, - CompilerBug472602Test.class, - Java8Compiler1Test.class, - Java8Compiler2Test.class, - TryWithResourcesJava8Test.class -}) -public class Java8CompilerSuite { -} diff --git a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/AnnotationCompilerTest.java b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/AnnotationCompilerTest.java index 8bda8b00820..47431f4603a 100644 --- a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/AnnotationCompilerTest.java +++ b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/AnnotationCompilerTest.java @@ -431,7 +431,7 @@ public void compileAnnotationWithFileHeader() { _builder.append("package foo"); _builder.newLine(); _builder.newLine(); - _builder.append("annotation bar { "); + _builder.append("annotation MyAnnotation { "); _builder.newLine(); _builder.append(" "); _builder.append("String name = \'foobar\'"); @@ -467,7 +467,7 @@ public void compileAnnotationWithFileHeader() { _builder_1.newLine(); _builder_1.append("@SuppressWarnings(\"all\")"); _builder_1.newLine(); - _builder_1.append("public @interface bar {"); + _builder_1.append("public @interface MyAnnotation {"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("public String name() default \"foobar\";"); @@ -790,6 +790,9 @@ public void testInterfaceExtendsAnnotation() { _builder_1.append("public static class MyClass implements MyAnno.MyIf {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public Class annotationType() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -805,6 +808,9 @@ public void testInterfaceExtendsAnnotation() { _builder_1.append("public static class MyClass2 implements MyAnno {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public Class annotationType() {"); _builder_1.newLine(); _builder_1.append(" "); diff --git a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/AnonymousClassCompilerTest.java b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/AnonymousClassCompilerTest.java index 5eff9060d66..73436b5b794 100644 --- a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/AnonymousClassCompilerTest.java +++ b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/AnonymousClassCompilerTest.java @@ -50,6 +50,9 @@ public void testPlain() { _builder_1.append("return new Runnable() {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public void run() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -150,6 +153,9 @@ public void testExtensions_01() { _builder_1.append("return new Runnable() {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public void run() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -258,6 +264,9 @@ public void testExtensions_02() { _builder_1.append("_xblockexpression = new Runnable() {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public void run() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -358,6 +367,9 @@ public void testExtensions_03() { _builder_1.append("_xblockexpression = new __Test_1() {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public void run() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -477,6 +489,9 @@ public void testExtensions_04() { _builder_1.append("_xblockexpression = new Runnable() {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public void run() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -563,6 +578,9 @@ public void testExtensions_05() { _builder_1.append("_xblockexpression = new Runnable() {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public void run() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -649,6 +667,9 @@ public void testExtensions_06() { _builder_1.append("_xblockexpression = new Runnable() {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public void run() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -735,6 +756,9 @@ public void testExtensions_07() { _builder_1.append("_xblockexpression = new Runnable() {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public void run() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -835,6 +859,9 @@ public void testExtensions_08() { _builder_1.append("return new Runnable() {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public void run() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -939,6 +966,9 @@ public void testExtensions_09() { _builder_1.append("return new Runnable() {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public void run() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -1033,6 +1063,9 @@ public void testExtensions_10() { _builder_1.append("return new Runnable() {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public void run() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -1089,6 +1122,9 @@ public void testForwardFieldReference() { _builder_1.append("private final Runnable r = new Runnable() {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public void run() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -1261,6 +1297,9 @@ public void testTypeUsed() { _builder_1.newLine(); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public String toString() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -1575,6 +1614,9 @@ public void testTwoClasses() { _builder_1.append("new Runnable() {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public void run() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -1587,6 +1629,9 @@ public void testTwoClasses() { _builder_1.append("new Runnable() {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public void run() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -1672,6 +1717,9 @@ public void testTwoClassesWithMembers() { _builder_1.append("new __C_1() {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public void run() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -1691,6 +1739,9 @@ public void testTwoClassesWithMembers() { _builder_1.append("new __C_2() {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public void run() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -1922,6 +1973,9 @@ public void testNestedLocalClass_01() { _builder_1.append("return CollectionLiterals.newArrayList(new Runnable() {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public void run() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -1969,6 +2023,9 @@ public void testNestedLocalClass_02() { _builder_1.append("return CollectionLiterals.newArrayList(new Runnable() {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public void run() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -2034,6 +2091,9 @@ public void testNestedLocalClass_03() { _builder_1.append("__C_1 ___C_1 = new __C_1() {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public void run() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -2122,6 +2182,9 @@ public void testNestedLocalClass_04() { _builder_1.append("__C_1 ___C_1 = new __C_1() {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public void run() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -2141,6 +2204,9 @@ public void testNestedLocalClass_04() { _builder_1.append("__C_2 ___C_2 = new __C_2() {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public void run() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -2210,6 +2276,9 @@ public void testNestedLocalClass_05() { _builder_1.append("__C_1 ___C_1 = new __C_1() {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public void run() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -2276,6 +2345,9 @@ public void testCapturedLocalVar_01() { _builder_1.append("final Runnable bar = new Runnable() {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public void run() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -2348,6 +2420,9 @@ public void testCapturedLocalVar_02() { _builder_1.append("final __Foo_1 bar = new __Foo_1() {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public void run() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -2420,6 +2495,9 @@ public void testCapturedLocalVar_03() { _builder_1.append("final __Foo_1 bar = new __Foo_1() {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public void run() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -2521,12 +2599,18 @@ public void testCapturedLocalVar_04() { _builder_1.append("final __Foo_1 bar = new __Foo_1() {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public void run() {"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("new Object() {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public String toString() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -2627,6 +2711,9 @@ public void testCapturedLocalVar_05() { _builder_1.append("final __Foo_1 bar = new __Foo_1() {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public void run() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -2636,6 +2723,9 @@ public void testCapturedLocalVar_05() { _builder_1.append("new Object() {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public String toString() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -2714,6 +2804,9 @@ public void testCapturedLocalVar_06() { _builder_1.append("final __Foo_1 bar = new __Foo_1() {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public void run() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -2796,6 +2889,9 @@ public void testCapturedLocalVar_07() { _builder_1.append("final __Foo_1 bar = new __Foo_1() {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public void run() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -2869,6 +2965,9 @@ public void testCapturedLocalVar_08() { _builder_1.append("return new Object() {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public String toString() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -2969,6 +3068,9 @@ public void testCapturedLocalVar_09() { _builder_1.append("__Foo_1 ___Foo_1 = new __Foo_1() {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public String apply() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -3065,6 +3167,9 @@ public void testCapturedLocalVar_10() { _builder_1.append("_xifexpression = new Runnable() {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public void run() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -3154,6 +3259,9 @@ public void testCapturedLocalVar_11() { _builder_1.append("_xifexpression = new Runnable() {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public void run() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -3225,6 +3333,9 @@ public void testLocalVar() { _builder_1.append("final Runnable bar = new Runnable() {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public void run() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -3290,6 +3401,9 @@ public void testNestedTypeScoping_01() { _builder_1.append("return new AbstractMap() {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public Set> entrySet() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -3358,6 +3472,9 @@ public void testNestedTypeScoping_02() { _builder_1.append("return new AbstractMap() {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public Set> entrySet() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -3431,6 +3548,9 @@ public void testNestedTypeScoping_03() { _builder_1.append("return new AbstractMap() {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public Set> entrySet() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -3818,6 +3938,9 @@ public void testSuperScoping_01() { _builder_1.append("return new D() {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public void m() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -3834,6 +3957,9 @@ public void testSuperScoping_01() { _builder_1.newLine(); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public void m() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -3893,6 +4019,9 @@ public void testSuperScoping_02() { _builder_1.append("return new D() {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public void m() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -3909,6 +4038,9 @@ public void testSuperScoping_02() { _builder_1.newLine(); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public void m() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -3966,6 +4098,9 @@ public void testLocalVar_AdditionalMember() { _builder_1.append("final __Foo_1 bar = new __Foo_1() {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public void run() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -4029,6 +4164,9 @@ public void testLocalVar_AdditionalMember_Return() { _builder_1.append("return new __Foo_1() {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public void run() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -4085,6 +4223,9 @@ public void testLocalVarInArray_01() { _builder_1.append("final Object[] bar = new Object[] { new Runnable() {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public void run() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -4148,6 +4289,9 @@ public void testLocalVarInArray_02() { _builder_1.append("final List bar = Collections.unmodifiableList(CollectionLiterals.newArrayList(new Runnable() {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public void run() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -4189,6 +4333,9 @@ public void testField() { _builder_1.append("private final Runnable bar = new Runnable() {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public void run() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -4233,6 +4380,9 @@ public void testField_AdditionalMember_01() { _builder_1.append("private final Runnable bar = new Function0() {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public Runnable apply() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -4249,6 +4399,9 @@ public void testField_AdditionalMember_01() { _builder_1.append("__Foo_1 ___Foo_1 = new __Foo_1() {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public void run() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -4310,6 +4463,9 @@ public void testField_AdditionalMember_02() { _builder_1.append("private final Object outerField = new Function0() {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public Object apply() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -4329,17 +4485,11 @@ public void testField_AdditionalMember_02() { _builder_1.append("};"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Procedure1<__C_1> _function = new Procedure1<__C_1>() {"); + _builder_1.append("final Procedure1<__C_1> _function = (__C_1 it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public void apply(final __C_1 it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("it.localField = C.this.secondOuterField;"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -4437,6 +4587,9 @@ public void testFieldInitializerUsesCapturedLocal_01() { _builder_1.append("}"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public void run() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -4556,6 +4709,9 @@ public void testFieldInitializerUsesCapturedLocal_02() { _builder_1.append("idx = new Function0() {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public Integer apply() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -4601,6 +4757,9 @@ public void testFieldInitializerUsesCapturedLocal_02() { _builder_1.append("}"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public void run() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -4681,17 +4840,11 @@ public void testAdditionalMemberAccess_01() { _builder_1.append("};"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Procedure1<__C_1> _function = new Procedure1<__C_1>() {"); + _builder_1.append("final Procedure1<__C_1> _function = (__C_1 it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public void apply(final __C_1 it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("it.f = 1;"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -4749,6 +4902,9 @@ public void testGeneric() { _builder_1.append("final Iterable bar = new Iterable() {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public Iterator iterator() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -4811,6 +4967,9 @@ public void testGeneric1() { _builder_1.append("final Iterable bar = new Iterable() {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public Iterator iterator() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -4876,6 +5035,9 @@ public void testGeneric2() { _builder_1.append("final Iterable bar = new Iterable() {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public Iterator iterator() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -4943,6 +5105,9 @@ public void testGeneric3() { _builder_1.append("final Bar bar = new Bar() {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public T bar(final U it) {"); _builder_1.newLine(); _builder_1.append(" "); @@ -5010,6 +5175,9 @@ public void testGeneric4() { _builder_1.append("final Bar bar = new Bar() {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public U bar(final T it) {"); _builder_1.newLine(); _builder_1.append(" "); @@ -5184,6 +5352,9 @@ public void testGeneric6() { _builder_1.newLine(); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public Set> entrySet() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -5268,6 +5439,9 @@ public void testGeneric7() { _builder_1.append("final Foo.Bar bar = new Foo.Bar() {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public W bar() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -5526,12 +5700,18 @@ public void testBug462313() { _builder_1.append("new Visibilities() {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public void publicMethod() {"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("new Thread() {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public void run() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -5623,6 +5803,9 @@ public void testAnnotation() { _builder_1.append("MyConfiguration config = new MyConfiguration() {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public Class annotationType() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -5633,6 +5816,9 @@ public void testAnnotation() { _builder_1.newLine(); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public String name() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -5718,19 +5904,13 @@ public void testXtendIssue1301() { _builder_1.append("AdapterImpl _adapterImpl = new AdapterImpl();"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Procedure1 _function = new Procedure1() {"); + _builder_1.append("final Procedure1 _function = (AdapterImpl it_1) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public void apply(final AdapterImpl it_1) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("EList _eAdapters = it.eAdapters();"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_eAdapters.add(it_1);"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("_eAdapters.add(it_1);"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); diff --git a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug1005Test.java b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug1005Test.java index ca7a321cc4e..0d8ee126407 100644 --- a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug1005Test.java +++ b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug1005Test.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Sebastian Zarnekow and others. + * Copyright (c) 2023, 2024 Sebastian Zarnekow and others. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. @@ -131,17 +131,11 @@ public void testBug516321() { _builder_1.append("public Outer.B m(final Outer.B it) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Consumer> _function = new Consumer>() {"); + _builder_1.append("final Consumer> _function = (Outer.B it_1) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public void accept(final Outer.B it_1) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("it_1.c(7);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); diff --git a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug342021Test.java b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug342021Test.java index bedb2a4fd64..92325bcdfa5 100644 --- a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug342021Test.java +++ b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug342021Test.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2013, 2018 itemis AG (http://www.itemis.eu) and others. + * Copyright (c) 2013, 2024 itemis AG (http://www.itemis.eu) and others. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. @@ -42,8 +42,6 @@ public void testIfExpression_01() { _builder.append("}"); _builder.newLine(); StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.Iterator;"); - _builder_1.newLine(); _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); _builder_1.newLine(); _builder_1.append("import org.eclipse.xtext.xbase.lib.Conversions;"); @@ -63,17 +61,11 @@ public void testIfExpression_01() { _builder_1.append("if (true) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Iterable _function = new Iterable() {"); + _builder_1.append("final Iterable _function = () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Iterator iterator() {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return CollectionLiterals.newArrayList().iterator();"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -126,8 +118,6 @@ public void testIfExpression_02() { _builder.append("}"); _builder.newLine(); StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.Iterator;"); - _builder_1.newLine(); _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); _builder_1.newLine(); _builder_1.append("import org.eclipse.xtext.xbase.lib.Conversions;"); @@ -147,17 +137,11 @@ public void testIfExpression_02() { _builder_1.append("if (true) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Iterable _function = new Iterable() {"); + _builder_1.append("final Iterable _function = () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Iterator iterator() {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return CollectionLiterals.newArrayList().iterator();"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -210,8 +194,6 @@ public void testIfExpression_03() { _builder.append("}"); _builder.newLine(); StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.Iterator;"); - _builder_1.newLine(); _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); _builder_1.newLine(); _builder_1.append("import org.eclipse.xtext.xbase.lib.Conversions;"); @@ -228,17 +210,11 @@ public void testIfExpression_03() { _builder_1.append("if (true) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Iterable _function = new Iterable() {"); + _builder_1.append("final Iterable _function = () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Iterator iterator() {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return CollectionLiterals.newArrayList().iterator();"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -288,8 +264,6 @@ public void testIfExpression_04() { _builder.append("}"); _builder.newLine(); StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.Iterator;"); - _builder_1.newLine(); _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); _builder_1.newLine(); _builder_1.append("import org.eclipse.xtext.xbase.lib.Conversions;"); @@ -309,17 +283,11 @@ public void testIfExpression_04() { _builder_1.append("if (true) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Iterable _function = new Iterable() {"); + _builder_1.append("final Iterable _function = () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Iterator iterator() {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return CollectionLiterals.newArrayList().iterator();"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -372,8 +340,6 @@ public void testIfExpression_05() { _builder.append("}"); _builder.newLine(); StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.Iterator;"); - _builder_1.newLine(); _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); _builder_1.newLine(); _builder_1.append("import org.eclipse.xtext.xbase.lib.Conversions;"); @@ -393,17 +359,11 @@ public void testIfExpression_05() { _builder_1.append("if (true) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Iterable _function = new Iterable() {"); + _builder_1.append("final Iterable _function = () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Iterator iterator() {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return CollectionLiterals.newArrayList().iterator();"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -456,8 +416,6 @@ public void testIfExpression_06() { _builder.append("}"); _builder.newLine(); StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.Iterator;"); - _builder_1.newLine(); _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); _builder_1.newLine(); _builder_1.append("import org.eclipse.xtext.xbase.lib.Conversions;"); @@ -477,17 +435,11 @@ public void testIfExpression_06() { _builder_1.append("if (true) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Iterable _function = new Iterable() {"); + _builder_1.append("final Iterable _function = () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Iterator iterator() {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return CollectionLiterals.newArrayList().iterator();"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -546,8 +498,6 @@ public void testIfExpression_07() { _builder.append("}"); _builder.newLine(); StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.Iterator;"); - _builder_1.newLine(); _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); _builder_1.newLine(); _builder_1.append("import org.eclipse.xtext.xbase.lib.Conversions;"); @@ -567,17 +517,11 @@ public void testIfExpression_07() { _builder_1.append("if (true) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Iterable _function = new Iterable() {"); + _builder_1.append("final Iterable _function = () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Iterator iterator() {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return CollectionLiterals.newArrayList().iterator();"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -636,8 +580,6 @@ public void testIfExpression_08() { _builder.append("}"); _builder.newLine(); StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.Iterator;"); - _builder_1.newLine(); _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); _builder_1.newLine(); _builder_1.append("import org.eclipse.xtext.xbase.lib.Conversions;"); @@ -654,17 +596,11 @@ public void testIfExpression_08() { _builder_1.append("if (true) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Iterable _function = new Iterable() {"); + _builder_1.append("final Iterable _function = () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Iterator iterator() {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return CollectionLiterals.newArrayList().iterator();"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -714,8 +650,6 @@ public void testIfExpression_09() { _builder.append("}"); _builder.newLine(); StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.Iterator;"); - _builder_1.newLine(); _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); _builder_1.newLine(); _builder_1.append("import org.eclipse.xtext.xbase.lib.Conversions;"); @@ -735,17 +669,11 @@ public void testIfExpression_09() { _builder_1.append("if (true) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Iterable _function = new Iterable() {"); + _builder_1.append("final Iterable _function = () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Iterator iterator() {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return CollectionLiterals.newArrayList().iterator();"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -798,8 +726,6 @@ public void testIfExpression_10() { _builder.append("}"); _builder.newLine(); StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.Iterator;"); - _builder_1.newLine(); _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); _builder_1.newLine(); _builder_1.append("import org.eclipse.xtext.xbase.lib.Conversions;"); @@ -819,17 +745,11 @@ public void testIfExpression_10() { _builder_1.append("if (true) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Iterable _function = new Iterable() {"); + _builder_1.append("final Iterable _function = () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Iterator iterator() {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return CollectionLiterals.newArrayList().iterator();"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -894,8 +814,6 @@ public void testIfExpression_11() { _builder.append("}"); _builder.newLine(); StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.Iterator;"); - _builder_1.newLine(); _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); _builder_1.newLine(); _builder_1.append("import org.eclipse.xtext.xbase.lib.Conversions;"); @@ -933,17 +851,11 @@ public void testIfExpression_11() { _builder_1.append("this.toString();"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Iterable _function = new Iterable() {"); + _builder_1.append("final Iterable _function = () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Iterator iterator() {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return CollectionLiterals.newArrayList().iterator();"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -1044,8 +956,6 @@ public void testIfExpression_12() { _builder.append("}"); _builder.newLine(); StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.Iterator;"); - _builder_1.newLine(); _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); _builder_1.newLine(); _builder_1.append("import org.eclipse.xtext.xbase.lib.Conversions;"); @@ -1086,17 +996,11 @@ public void testIfExpression_12() { _builder_1.append("this.toString();"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Iterable _function = new Iterable() {"); + _builder_1.append("final Iterable _function = () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Iterator iterator() {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return CollectionLiterals.newArrayList().iterator();"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -1188,8 +1092,6 @@ public void testIfExpression_13() { _builder.append("}"); _builder.newLine(); StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.Iterator;"); - _builder_1.newLine(); _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); _builder_1.newLine(); _builder_1.append("import org.eclipse.xtext.xbase.lib.Conversions;"); @@ -1212,17 +1114,11 @@ public void testIfExpression_13() { _builder_1.append("this.toString();"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Iterable _function = new Iterable() {"); + _builder_1.append("final Iterable _function = () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Iterator iterator() {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return CollectionLiterals.newArrayList().iterator();"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -1287,8 +1183,6 @@ public void testIfExpression_14() { _builder.append("}"); _builder.newLine(); StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.Iterator;"); - _builder_1.newLine(); _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); _builder_1.newLine(); _builder_1.append("import org.eclipse.xtext.xbase.lib.Conversions;"); @@ -1320,17 +1214,11 @@ public void testIfExpression_14() { _builder_1.append("this.toString();"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Iterable _function = new Iterable() {"); + _builder_1.append("final Iterable _function = () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Iterator iterator() {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return CollectionLiterals.newArrayList().iterator();"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -1434,8 +1322,6 @@ public void testIfExpression_15() { _builder.append("}"); _builder.newLine(); StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.Iterator;"); - _builder_1.newLine(); _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); _builder_1.newLine(); _builder_1.append("import org.eclipse.xtext.xbase.lib.Conversions;"); @@ -1473,17 +1359,11 @@ public void testIfExpression_15() { _builder_1.append("this.toString();"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Iterable _function = new Iterable() {"); + _builder_1.append("final Iterable _function = () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Iterator iterator() {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return CollectionLiterals.newArrayList().iterator();"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -1551,8 +1431,6 @@ public void testSwitchExpression_01() { _builder.append("}"); _builder.newLine(); StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.Iterator;"); - _builder_1.newLine(); _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); _builder_1.newLine(); _builder_1.append("import org.eclipse.xtext.xbase.lib.Conversions;"); @@ -1578,17 +1456,11 @@ public void testSwitchExpression_01() { _builder_1.append("_matched=true;"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Iterable _function = new Iterable() {"); + _builder_1.append("final Iterable _function = () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Iterator iterator() {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return CollectionLiterals.newArrayList().iterator();"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -1644,8 +1516,6 @@ public void testSwitchExpression_02() { _builder.append("}"); _builder.newLine(); StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.Iterator;"); - _builder_1.newLine(); _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); _builder_1.newLine(); _builder_1.append("import org.eclipse.xtext.xbase.lib.Conversions;"); @@ -1671,17 +1541,11 @@ public void testSwitchExpression_02() { _builder_1.append("_matched=true;"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Iterable _function = new Iterable() {"); + _builder_1.append("final Iterable _function = () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Iterator iterator() {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return CollectionLiterals.newArrayList().iterator();"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -1749,8 +1613,6 @@ public void testSwitchExpression_03() { _builder.append("}"); _builder.newLine(); StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.Iterator;"); - _builder_1.newLine(); _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); _builder_1.newLine(); _builder_1.append("import org.eclipse.xtext.xbase.lib.Conversions;"); @@ -1776,17 +1638,11 @@ public void testSwitchExpression_03() { _builder_1.append("_matched=true;"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Iterable _function = new Iterable() {"); + _builder_1.append("final Iterable _function = () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Iterator iterator() {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return CollectionLiterals.newArrayList().iterator();"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -1863,8 +1719,6 @@ public void testSwitchExpression_04() { _builder.append("}"); _builder.newLine(); StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.Iterator;"); - _builder_1.newLine(); _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); _builder_1.newLine(); _builder_1.append("import org.eclipse.xtext.xbase.lib.Conversions;"); @@ -1890,17 +1744,11 @@ public void testSwitchExpression_04() { _builder_1.append("_matched=true;"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Iterable _function = new Iterable() {"); + _builder_1.append("final Iterable _function = () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Iterator iterator() {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return CollectionLiterals.newArrayList().iterator();"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -1977,8 +1825,6 @@ public void testTryCatchExpression_01() { _builder.append("}"); _builder.newLine(); StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.Iterator;"); - _builder_1.newLine(); _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); _builder_1.newLine(); _builder_1.append("import org.eclipse.xtext.xbase.lib.Conversions;"); @@ -2000,17 +1846,11 @@ public void testTryCatchExpression_01() { _builder_1.append("try {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Iterable _function = new Iterable() {"); + _builder_1.append("final Iterable _function = () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Iterator iterator() {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return CollectionLiterals.newArrayList().iterator();"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -2092,8 +1932,6 @@ public void testNestedIfInSwitchExpression_01() { StringConcatenation _builder_1 = new StringConcatenation(); _builder_1.append("import java.util.Collections;"); _builder_1.newLine(); - _builder_1.append("import java.util.Iterator;"); - _builder_1.newLine(); _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); _builder_1.newLine(); _builder_1.append("import org.eclipse.xtext.xbase.lib.Conversions;"); @@ -2119,17 +1957,11 @@ public void testNestedIfInSwitchExpression_01() { _builder_1.append("_matched=true;"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Iterable _function = new Iterable() {"); + _builder_1.append("final Iterable _function = () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Iterator iterator() {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return CollectionLiterals.newArrayList().iterator();"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); diff --git a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug383534Test.java b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug383534Test.java index 48fa63ebbbc..0e8c9735465 100644 --- a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug383534Test.java +++ b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug383534Test.java @@ -83,17 +83,11 @@ public void test_01() { _builder_1.append("public void m() {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function2 _function = new Function2() {"); + _builder_1.append("final Function2 _function = (String s1, String s2) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public String apply(final String s1, final String s2) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return (s1 + s2);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -110,34 +104,22 @@ public void test_01() { _builder_1.append("InputOutput.println(curriedStrAdd.apply(\"y\"));"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function2 _function_1 = new Function2() {"); + _builder_1.append("final Function2 _function_1 = (String s1, String[] s2) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public String apply(final String s1, final String[] s2) {"); + _builder_1.append("final Function2 _function_2 = (String x1, String x2) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function2 _function = new Function2() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public String apply(final String x1, final String x2) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return (x1 + x2);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("String _reduce = IterableExtensions.reduce(((Iterable)Conversions.doWrapArray(s2)), _function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return (s1 + _reduce);"); + _builder_1.append(" "); + _builder_1.append("String _reduce = IterableExtensions.reduce(((Iterable)Conversions.doWrapArray(s2)), _function_2);"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("return (s1 + _reduce);"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); @@ -205,17 +187,11 @@ public void test_02() { _builder_1.append("public void m() {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function2 _function = new Function2() {"); + _builder_1.append("final Function2 _function = (String s1, String s2) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public String apply(final String s1, final String s2) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return (s1 + s2);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -288,19 +264,13 @@ public void test_03() { _builder_1.append("public void m() {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function2 _function = new Function2() {"); + _builder_1.append("final Function2 _function = (String s1, String[] s2) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public String apply(final String s1, final String[] s2) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("String _head = IterableExtensions.head(((Iterable)Conversions.doWrapArray(s2)));"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return (s1 + _head);"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("return (s1 + _head);"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); @@ -372,34 +342,22 @@ public void test_04() { _builder_1.append("public void m() {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function2 _function = new Function2() {"); + _builder_1.append("final Function2 _function = (String s1, String[] s2) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public String apply(final String s1, final String[] s2) {"); + _builder_1.append("final Function2 _function_1 = (String x1, String x2) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function2 _function = new Function2() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public String apply(final String x1, final String x2) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return (x1 + x2);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("String _reduce = IterableExtensions.reduce(((Iterable)Conversions.doWrapArray(s2)), _function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return (s1 + _reduce);"); + _builder_1.append(" "); + _builder_1.append("String _reduce = IterableExtensions.reduce(((Iterable)Conversions.doWrapArray(s2)), _function_1);"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("return (s1 + _reduce);"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); diff --git a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug404051Test.java b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug404051Test.java index 8c59a91ed9a..43e767824d0 100644 --- a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug404051Test.java +++ b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug404051Test.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2013, 2016 itemis AG (http://www.itemis.eu) and others. + * Copyright (c) 2013, 2024 itemis AG (http://www.itemis.eu) and others. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. @@ -58,32 +58,20 @@ public void test_01() { _builder_1.append("public List m(final Iterable iterable) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function1 _function = new Function1() {"); + _builder_1.append("final Function1 _function = (String it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Object apply(final String it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return null;"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function1 _function_1 = new Function1() {"); + _builder_1.append("final Function1 _function_1 = (Object it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Integer apply(final Object it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return Integer.valueOf(it.hashCode());"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -149,32 +137,20 @@ public void test_02() { _builder_1.append("public List m(final Iterable iterable) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function1 _function = new Function1() {"); + _builder_1.append("final Function1 _function = (String it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Number apply(final String it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return null;"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function1 _function_1 = new Function1() {"); + _builder_1.append("final Function1 _function_1 = (Object it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Integer apply(final Object it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return Integer.valueOf(it.hashCode());"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -240,32 +216,20 @@ public void test_03() { _builder_1.append("public List m(final Iterable iterable) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function1 _function = new Function1() {"); + _builder_1.append("final Function1 _function = (String it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Number apply(final String it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return null;"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function1 _function_1 = new Function1() {"); + _builder_1.append("final Function1 _function_1 = (Number it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Integer apply(final Number it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return Integer.valueOf(it.intValue());"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -335,32 +299,20 @@ public void test_04() { _builder_1.append("public List m() {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function1 _function = new Function1() {"); + _builder_1.append("final Function1 _function = (String it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Integer apply(final String it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return Integer.valueOf(it.length());"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function1 _function_1 = new Function1() {"); + _builder_1.append("final Function1 _function_1 = (Integer it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Integer apply(final Integer it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return Integer.valueOf(it.intValue());"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -430,32 +382,20 @@ public void test_05() { _builder_1.append("public List m() {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function1 _function = new Function1() {"); + _builder_1.append("final Function1 _function = (String it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Number apply(final String it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return null;"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function1 _function_1 = new Function1() {"); + _builder_1.append("final Function1 _function_1 = (Number it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Integer apply(final Number it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return Integer.valueOf(it.intValue());"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -521,32 +461,20 @@ public void test_06() { _builder_1.append("public List m(final Iterable iterable) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function1 _function = new Function1() {"); + _builder_1.append("final Function1 _function = (String it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public String apply(final String it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return null;"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function1 _function_1 = new Function1() {"); + _builder_1.append("final Function1 _function_1 = (String it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Integer apply(final String it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return Integer.valueOf(it.length());"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); diff --git a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug405825Test.java b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug405825Test.java index fe6f6b17699..8be9cb1bc61 100644 --- a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug405825Test.java +++ b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug405825Test.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2013 itemis AG (http://www.itemis.eu) and others. + * Copyright (c) 2013, 2024 itemis AG (http://www.itemis.eu) and others. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. @@ -64,13 +64,7 @@ public void testBug405825_01() { _builder_1.append("public static void main() {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Bound _function = new Bound() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void method(final Number it) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("final Bound _function = (Number it) -> {"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); @@ -134,13 +128,7 @@ public void testBug405825_02() { _builder_1.append("public static void main() {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Bound _function = new Bound() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void method(final Integer it) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("final Bound _function = (Integer it) -> {"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); @@ -206,13 +194,7 @@ public void testBug405825_03() { _builder_1.append("public static void main() {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Sub _function = new Sub() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void method(final Number it) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("final Sub _function = (Number it) -> {"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); diff --git a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug406425Test.java b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug406425Test.java index dbfb490ef30..98cfa158066 100644 --- a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug406425Test.java +++ b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug406425Test.java @@ -80,19 +80,13 @@ public void testBug406425_01() { _builder_1.append("MyEntity _myEntity = new MyEntity();"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Procedure1 _function = new Procedure1() {"); + _builder_1.append("final Procedure1 _function = (MyEntity it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public void apply(final MyEntity it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("Assert.assertThat(it, Test.nullValue());"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Assert.assertThat(it.getName(), Is.is(\"\"));"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("Assert.assertThat(it.getName(), Is.is(\"\"));"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); @@ -121,7 +115,7 @@ public void testBug406425_01() { @Test public void testBug406425_02() { StringConcatenation _builder = new StringConcatenation(); - _builder.append("import org.eclipse.xtend.core.tests.compiler.StringBuilderLike"); + _builder.append("import org.eclipse.xtend.core.tests.java8.compiler.StringBuilderLike"); _builder.newLine(); _builder.append("class Test {"); _builder.newLine(); @@ -152,7 +146,7 @@ public void testBug406425_02() { StringConcatenation _builder_1 = new StringConcatenation(); _builder_1.append("import java.io.Serializable;"); _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtend.core.tests.compiler.StringBuilderLike;"); + _builder_1.append("import org.eclipse.xtend.core.tests.java8.compiler.StringBuilderLike;"); _builder_1.newLine(); _builder_1.append("import org.eclipse.xtext.xbase.lib.InputOutput;"); _builder_1.newLine(); @@ -182,25 +176,19 @@ public void testBug406425_02() { _builder_1.append("StringBuilderLike _stringBuilderLike = new StringBuilderLike();"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Procedure1 _function = new Procedure1() {"); + _builder_1.append("final Procedure1 _function = (StringBuilderLike it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public void apply(final StringBuilderLike it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("Test _test = new Test();"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("Long _long = new Long(0);"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("_test.m(it, _long);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("InputOutput.println(Integer.valueOf(it.length()));"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("InputOutput.println(Integer.valueOf(it.length()));"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); @@ -219,7 +207,7 @@ public void testBug406425_02() { @Test public void testBug406425_03() { StringConcatenation _builder = new StringConcatenation(); - _builder.append("import org.eclipse.xtend.core.tests.compiler.StringBuilderLike"); + _builder.append("import org.eclipse.xtend.core.tests.java8.compiler.StringBuilderLike"); _builder.newLine(); _builder.append("class Test {"); _builder.newLine(); @@ -250,7 +238,7 @@ public void testBug406425_03() { StringConcatenation _builder_1 = new StringConcatenation(); _builder_1.append("import java.io.Serializable;"); _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtend.core.tests.compiler.StringBuilderLike;"); + _builder_1.append("import org.eclipse.xtend.core.tests.java8.compiler.StringBuilderLike;"); _builder_1.newLine(); _builder_1.append("import org.eclipse.xtext.xbase.lib.InputOutput;"); _builder_1.newLine(); @@ -280,22 +268,16 @@ public void testBug406425_03() { _builder_1.append("StringBuilderLike _stringBuilderLike = new StringBuilderLike();"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Procedure1 _function = new Procedure1() {"); + _builder_1.append("final Procedure1 _function = (StringBuilderLike it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public void apply(final StringBuilderLike it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("Long _long = new Long(0);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Test.this.m(it, _long);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("InputOutput.println(Integer.valueOf(it.length()));"); + _builder_1.append(" "); + _builder_1.append("this.m(it, _long);"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("InputOutput.println(Integer.valueOf(it.length()));"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); @@ -314,7 +296,7 @@ public void testBug406425_03() { @Test public void testBug406425_04() { StringConcatenation _builder = new StringConcatenation(); - _builder.append("import org.eclipse.xtend.core.tests.compiler.StringBuilderLike"); + _builder.append("import org.eclipse.xtend.core.tests.java8.compiler.StringBuilderLike"); _builder.newLine(); _builder.append("class Test {"); _builder.newLine(); @@ -345,7 +327,7 @@ public void testBug406425_04() { StringConcatenation _builder_1 = new StringConcatenation(); _builder_1.append("import java.io.Serializable;"); _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtend.core.tests.compiler.StringBuilderLike;"); + _builder_1.append("import org.eclipse.xtend.core.tests.java8.compiler.StringBuilderLike;"); _builder_1.newLine(); _builder_1.append("import org.eclipse.xtext.xbase.lib.InputOutput;"); _builder_1.newLine(); @@ -375,22 +357,16 @@ public void testBug406425_04() { _builder_1.append("StringBuilderLike _stringBuilderLike = new StringBuilderLike();"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Procedure1 _function = new Procedure1() {"); + _builder_1.append("final Procedure1 _function = (StringBuilderLike it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public void apply(final StringBuilderLike it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("Long _long = new Long(0);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Test.this.m(it, _long);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("InputOutput.println(Integer.valueOf(it.length()));"); + _builder_1.append(" "); + _builder_1.append("this.m(it, _long);"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("InputOutput.println(Integer.valueOf(it.length()));"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); @@ -409,7 +385,7 @@ public void testBug406425_04() { @Test public void testBug406425_05() { StringConcatenation _builder = new StringConcatenation(); - _builder.append("import org.eclipse.xtend.core.tests.compiler.StringBuilderLike"); + _builder.append("import org.eclipse.xtend.core.tests.java8.compiler.StringBuilderLike"); _builder.newLine(); _builder.append("class Test {"); _builder.newLine(); @@ -440,7 +416,7 @@ public void testBug406425_05() { StringConcatenation _builder_1 = new StringConcatenation(); _builder_1.append("import java.io.Serializable;"); _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtend.core.tests.compiler.StringBuilderLike;"); + _builder_1.append("import org.eclipse.xtend.core.tests.java8.compiler.StringBuilderLike;"); _builder_1.newLine(); _builder_1.append("import org.eclipse.xtext.xbase.lib.InputOutput;"); _builder_1.newLine(); @@ -470,22 +446,16 @@ public void testBug406425_05() { _builder_1.append("StringBuilderLike _stringBuilderLike = new StringBuilderLike();"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Procedure1 _function = new Procedure1() {"); + _builder_1.append("final Procedure1 _function = (StringBuilderLike it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public void apply(final StringBuilderLike it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("Long _long = new Long(0);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Test.this.m(it, _long);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("InputOutput.println(Integer.valueOf(it.length()));"); + _builder_1.append(" "); + _builder_1.append("this.m(it, _long);"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("InputOutput.println(Integer.valueOf(it.length()));"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); @@ -504,7 +474,7 @@ public void testBug406425_05() { @Test public void testBug406425_06() { StringConcatenation _builder = new StringConcatenation(); - _builder.append("import org.eclipse.xtend.core.tests.compiler.StringBuilderLike"); + _builder.append("import org.eclipse.xtend.core.tests.java8.compiler.StringBuilderLike"); _builder.newLine(); _builder.append("class Test {"); _builder.newLine(); @@ -537,7 +507,7 @@ public void testBug406425_06() { _builder_1.newLine(); _builder_1.append("import java.util.function.Consumer;"); _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtend.core.tests.compiler.StringBuilderLike;"); + _builder_1.append("import org.eclipse.xtend.core.tests.java8.compiler.StringBuilderLike;"); _builder_1.newLine(); _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); _builder_1.newLine(); @@ -565,22 +535,16 @@ public void testBug406425_06() { _builder_1.append("StringBuilderLike _stringBuilderLike = new StringBuilderLike();"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Consumer _function = new Consumer() {"); + _builder_1.append("final Consumer _function = (StringBuilderLike it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public void accept(final StringBuilderLike it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("Long _long = new Long(0);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Test.this.m(it, _long);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("InputOutput.println(Integer.valueOf(it.length()));"); + _builder_1.append(" "); + _builder_1.append("this.m(it, _long);"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("InputOutput.println(Integer.valueOf(it.length()));"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); @@ -599,7 +563,7 @@ public void testBug406425_06() { @Test public void testBug406425_07() { StringConcatenation _builder = new StringConcatenation(); - _builder.append("import org.eclipse.xtend.core.tests.compiler.StringBuilderLike"); + _builder.append("import org.eclipse.xtend.core.tests.java8.compiler.StringBuilderLike"); _builder.newLine(); _builder.append("class Test {"); _builder.newLine(); @@ -630,7 +594,7 @@ public void testBug406425_07() { StringConcatenation _builder_1 = new StringConcatenation(); _builder_1.append("import java.io.Serializable;"); _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtend.core.tests.compiler.StringBuilderLike;"); + _builder_1.append("import org.eclipse.xtend.core.tests.java8.compiler.StringBuilderLike;"); _builder_1.newLine(); _builder_1.append("import org.eclipse.xtext.xbase.lib.InputOutput;"); _builder_1.newLine(); @@ -660,22 +624,16 @@ public void testBug406425_07() { _builder_1.append("StringBuilderLike _stringBuilderLike = new StringBuilderLike();"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Procedure1 _function = new Procedure1() {"); + _builder_1.append("final Procedure1 _function = (StringBuilderLike it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public void apply(final StringBuilderLike it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("Long _long = new Long(0);"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("Test.m(it, _long);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("InputOutput.println(Integer.valueOf(it.length()));"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("InputOutput.println(Integer.valueOf(it.length()));"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); @@ -694,7 +652,7 @@ public void testBug406425_07() { @Test public void testBug406425_08() { StringConcatenation _builder = new StringConcatenation(); - _builder.append("import org.eclipse.xtend.core.tests.compiler.StringBuilderLike"); + _builder.append("import org.eclipse.xtend.core.tests.java8.compiler.StringBuilderLike"); _builder.newLine(); _builder.append("class Test {"); _builder.newLine(); @@ -725,7 +683,7 @@ public void testBug406425_08() { StringConcatenation _builder_1 = new StringConcatenation(); _builder_1.append("import java.io.Serializable;"); _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtend.core.tests.compiler.StringBuilderLike;"); + _builder_1.append("import org.eclipse.xtend.core.tests.java8.compiler.StringBuilderLike;"); _builder_1.newLine(); _builder_1.append("import org.eclipse.xtext.xbase.lib.InputOutput;"); _builder_1.newLine(); @@ -755,22 +713,16 @@ public void testBug406425_08() { _builder_1.append("StringBuilderLike _stringBuilderLike = new StringBuilderLike();"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Procedure1 _function = new Procedure1() {"); + _builder_1.append("final Procedure1 _function = (StringBuilderLike it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public void apply(final StringBuilderLike it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("Long _long = new Long(0);"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("Test.m(it, _long);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("InputOutput.println(Integer.valueOf(it.length()));"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("InputOutput.println(Integer.valueOf(it.length()));"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); @@ -789,7 +741,7 @@ public void testBug406425_08() { @Test public void testBug406425_09() { StringConcatenation _builder = new StringConcatenation(); - _builder.append("import org.eclipse.xtend.core.tests.compiler.StringBuilderLike"); + _builder.append("import org.eclipse.xtend.core.tests.java8.compiler.StringBuilderLike"); _builder.newLine(); _builder.append("class Test {"); _builder.newLine(); @@ -822,7 +774,7 @@ public void testBug406425_09() { _builder_1.newLine(); _builder_1.append("import java.util.function.Consumer;"); _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtend.core.tests.compiler.StringBuilderLike;"); + _builder_1.append("import org.eclipse.xtend.core.tests.java8.compiler.StringBuilderLike;"); _builder_1.newLine(); _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); _builder_1.newLine(); @@ -850,25 +802,19 @@ public void testBug406425_09() { _builder_1.append("StringBuilderLike _stringBuilderLike = new StringBuilderLike();"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Consumer _function = new Consumer() {"); + _builder_1.append("final Consumer _function = (StringBuilderLike it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public void accept(final StringBuilderLike it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("Test _test = new Test();"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("Long _long = new Long(0);"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("_test.m(it, _long);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("InputOutput.println(Integer.valueOf(it.length()));"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("InputOutput.println(Integer.valueOf(it.length()));"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); @@ -887,7 +833,7 @@ public void testBug406425_09() { @Test public void testBug406425_10() { StringConcatenation _builder = new StringConcatenation(); - _builder.append("import org.eclipse.xtend.core.tests.compiler.StringBuilderLike"); + _builder.append("import org.eclipse.xtend.core.tests.java8.compiler.StringBuilderLike"); _builder.newLine(); _builder.append("class Test {"); _builder.newLine(); @@ -920,7 +866,7 @@ public void testBug406425_10() { _builder_1.newLine(); _builder_1.append("import java.util.function.Consumer;"); _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtend.core.tests.compiler.StringBuilderLike;"); + _builder_1.append("import org.eclipse.xtend.core.tests.java8.compiler.StringBuilderLike;"); _builder_1.newLine(); _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); _builder_1.newLine(); @@ -948,25 +894,19 @@ public void testBug406425_10() { _builder_1.append("StringBuilderLike _stringBuilderLike = new StringBuilderLike();"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Consumer _function = new Consumer() {"); + _builder_1.append("final Consumer _function = (StringBuilderLike it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public void accept(final StringBuilderLike it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("Test _test = new Test();"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("Long _long = new Long(0);"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("_test.m(it, _long);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("InputOutput.println(Integer.valueOf(it.length()));"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("InputOutput.println(Integer.valueOf(it.length()));"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); @@ -985,7 +925,7 @@ public void testBug406425_10() { @Test public void testBug406425_11() { StringConcatenation _builder = new StringConcatenation(); - _builder.append("import org.eclipse.xtend.core.tests.compiler.StringBuilderLike"); + _builder.append("import org.eclipse.xtend.core.tests.java8.compiler.StringBuilderLike"); _builder.newLine(); _builder.append("class Test {"); _builder.newLine(); @@ -1018,7 +958,7 @@ public void testBug406425_11() { _builder_1.newLine(); _builder_1.append("import java.util.function.Consumer;"); _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtend.core.tests.compiler.StringBuilderLike;"); + _builder_1.append("import org.eclipse.xtend.core.tests.java8.compiler.StringBuilderLike;"); _builder_1.newLine(); _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); _builder_1.newLine(); @@ -1046,22 +986,16 @@ public void testBug406425_11() { _builder_1.append("StringBuilderLike _stringBuilderLike = new StringBuilderLike();"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Consumer _function = new Consumer() {"); + _builder_1.append("final Consumer _function = (StringBuilderLike it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public void accept(final StringBuilderLike it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("Long _long = new Long(0);"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("Test.m(it, _long);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("InputOutput.println(Integer.valueOf(it.length()));"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("InputOutput.println(Integer.valueOf(it.length()));"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); diff --git a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug406549Test.java b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug406549Test.java index 8476f00b675..38faa80c57d 100644 --- a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug406549Test.java +++ b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug406549Test.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2013, 2016 itemis AG (http://www.itemis.eu) and others. + * Copyright (c) 2013, 2024 itemis AG (http://www.itemis.eu) and others. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. @@ -113,17 +113,11 @@ public void testBug406549_02() { _builder_1.append("public void m(final T a, final T b) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Procedure1> _function = new Procedure1>() {"); + _builder_1.append("final Procedure1> _function = (Test it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public void apply(final Test it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("new Test().m(a, b);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -190,22 +184,16 @@ public void testBug406549_03() { _builder_1.append("StringBuilder _stringBuilder = new StringBuilder();"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Procedure1 _function = new Procedure1() {"); + _builder_1.append("final Procedure1 _function = (StringBuilder it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public void apply(final StringBuilder it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("Test _test = new Test();"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("Long _long = new Long(0);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_test.m(it, _long);"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("_test.m(it, _long);"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); diff --git a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug406762Test.java b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug406762Test.java index 7ffa7b4fc6e..c1a19aeabdf 100644 --- a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug406762Test.java +++ b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug406762Test.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2016 TypeFox.io (http://www.typefox.io) and others. + * Copyright (c) 2016, 2024 TypeFox.io (http://www.typefox.io) and others. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. @@ -47,6 +47,9 @@ public void testMyExceptionReturnsThisAsThrowable() { _builder_1.append("private static final class MyException extends Exception {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public synchronized Throwable fillInStackTrace() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -94,6 +97,9 @@ public void testMyExceptionImpicitlyReturnsThisAsThrowable() { _builder_1.append("private static final class MyException extends Exception {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public synchronized Throwable fillInStackTrace() {"); _builder_1.newLine(); _builder_1.append(" "); diff --git a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug410555Test.java b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug410555Test.java index 3b7cde0c764..5c123e16c37 100644 --- a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug410555Test.java +++ b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug410555Test.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2013 itemis AG (http://www.itemis.eu) and others. + * Copyright (c) 2013, 2024 itemis AG (http://www.itemis.eu) and others. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. @@ -128,16 +128,10 @@ public void test_02() { _builder_1.append("public BugSAM2() {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("super(new SAMInterface() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void test() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("super(((SAMInterface) () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("});"); + _builder_1.append("}));"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("}"); @@ -214,16 +208,10 @@ public void test_03() { _builder_1.append("public BugSAM() {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("this(new SAMInterface() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void test() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("this(((SAMInterface) () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("});"); + _builder_1.append("}));"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("}"); @@ -233,13 +221,7 @@ public void test_03() { _builder_1.append("public static void main(final String[] args) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final SAMInterface _function = new SAMInterface() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void test() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("final SAMInterface _function = () -> {"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); diff --git a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug410797Test.java b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug410797Test.java index 84c8548152a..dd9a666f6ef 100644 --- a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug410797Test.java +++ b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug410797Test.java @@ -110,31 +110,19 @@ public void testBug_410797_01() { _builder_1.append("final G g = new G();"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function1> _function = new Function1>() {"); + _builder_1.append("final Function1> _function = (E e) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public ArrayList apply(final E e) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return e.m();"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function1 _function_1 = new Function1() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public D apply(final F it) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return C.this.d(it, g);"); + _builder_1.append("final Function1 _function_1 = (F it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("return this.d(it, g);"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); @@ -253,31 +241,19 @@ public void testBug_410797_02() { _builder_1.append("final G g = new G();"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function1> _function = new Function1>() {"); + _builder_1.append("final Function1> _function = (E e) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public ArrayList apply(final E e) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return e.m();"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function1 _function_1 = new Function1() {"); + _builder_1.append("final Function1 _function_1 = (F it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public D apply(final F it) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return C.this.d(it, g);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("return this.d(it, g);"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); @@ -384,34 +360,22 @@ public void testBug_410797_03() { _builder_1.append("public Iterable m() {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function1> _function = new Function1>() {"); + _builder_1.append("final Function1> _function = (E e) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public ArrayList apply(final E e) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return e.m();"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function1 _function_1 = new Function1() {"); + _builder_1.append("final Function1 _function_1 = (F it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public D apply(final F it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("G _g = new G();"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return C.this.d(it, _g);"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("return this.d(it, _g);"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); @@ -571,31 +535,25 @@ public void testBug_410797_04() { _builder_1.append("public int getLenght() {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function2 _function = new Function2() {"); + _builder_1.append("final Function2 _function = (Integer x, LeafInfo i) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Integer apply(final Integer x, final LeafInfo i) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("ILeafNode _node = i.getNode();"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("int _length = 0;"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("if (_node!=null) {"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("_length=_node.getLength();"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("}"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return Integer.valueOf(((x).intValue() + _length));"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("return Integer.valueOf(((x).intValue() + _length));"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); @@ -611,19 +569,13 @@ public void testBug_410797_04() { _builder_1.append("public int getNewLines() {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function2 _function = new Function2() {"); + _builder_1.append("final Function2 _function = (Integer x, LeafInfo i) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Integer apply(final Integer x, final LeafInfo i) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("int _newLines = i.getNewLines();"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return Integer.valueOf(((x).intValue() + _newLines));"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("return Integer.valueOf(((x).intValue() + _newLines));"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); @@ -639,19 +591,13 @@ public void testBug_410797_04() { _builder_1.append("public int getNewLinesInComments() {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function2 _function = new Function2() {"); + _builder_1.append("final Function2 _function = (Integer x, CommentInfo i) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Integer apply(final Integer x, final CommentInfo i) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("int _newLines = i.getNewLines();"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return Integer.valueOf(((x).intValue() + _newLines));"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("return Integer.valueOf(((x).intValue() + _newLines));"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); diff --git a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug412894Test.java b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug412894Test.java index 41ec8d89f20..b6f5c5a8a79 100644 --- a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug412894Test.java +++ b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug412894Test.java @@ -66,25 +66,19 @@ public void test_01() { _builder_1.append("final ArrayList list = CollectionLiterals.newArrayList();"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Consumer _function = new Consumer() {"); + _builder_1.append("final Consumer _function = (String it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public void accept(final String it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("boolean _matched = false;"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("if (it instanceof String) {"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("_matched=true;"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("list.add(it);"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("list.add(it);"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("}"); @@ -158,40 +152,34 @@ public void test_02() { _builder_1.append("final ArrayList list = CollectionLiterals.newArrayList();"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Consumer _function = new Consumer() {"); + _builder_1.append("final Consumer _function = (Serializable it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public void accept(final Serializable it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("boolean _matched = false;"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("if (it instanceof String) {"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("_matched=true;"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("list.add(it);"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("}"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("if (!_matched) {"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("if (it instanceof Number) {"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("_matched=true;"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("list.add(it);"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("list.add(it);"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("}"); @@ -265,25 +253,19 @@ public void test_03() { _builder_1.append("final ArrayList list = CollectionLiterals.newArrayList();"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Consumer _function = new Consumer() {"); + _builder_1.append("final Consumer _function = (Serializable it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public void accept(final Serializable it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("boolean _matched = false;"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("if (it instanceof Number) {"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("_matched=true;"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("list.add(((Number)it).toString());"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("list.add(((Number)it).toString());"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("}"); @@ -346,19 +328,13 @@ public void test_04() { _builder_1.append("final ArrayList list = CollectionLiterals.newArrayList();"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Consumer _function = new Consumer() {"); + _builder_1.append("final Consumer _function = (Object it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public void accept(final Object it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("if ((it instanceof String)) {"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("list.add(it);"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("list.add(it);"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("}"); diff --git a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug419050Test.java b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug419050Test.java index bbf0893b440..6de87deb28e 100644 --- a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug419050Test.java +++ b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug419050Test.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2013 itemis AG (http://www.itemis.eu) and others. + * Copyright (c) 2013, 2024 itemis AG (http://www.itemis.eu) and others. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. @@ -522,19 +522,13 @@ public void test_10() { _builder_1.append("public boolean m(final boolean b) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function1 _function = new Function1() {"); + _builder_1.append("final Function1 _function = (String s) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Boolean apply(final String s) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("while (true) {"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return Boolean.valueOf(false);"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("return Boolean.valueOf(false);"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("}"); @@ -596,19 +590,13 @@ public void test_11() { _builder_1.append("public boolean m(final boolean b) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Predicate _function = new Predicate() {"); + _builder_1.append("final Predicate _function = (String it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public boolean apply(final String it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("while (true) {"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return false;"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("return false;"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("}"); @@ -684,50 +672,44 @@ public void testBug417371_01() { _builder_1.append("public Iterable m(final Iterable iter) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function1 _function = new Function1() {"); + _builder_1.append("final Function1 _function = (String it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Boolean apply(final String it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("int _length = it.length();"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("boolean _lessThan = (_length < 2);"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("if (_lessThan) {"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("return Boolean.valueOf(true);"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("} else {"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("int _length_1 = it.length();"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("boolean _greaterThan = (_length_1 > 2);"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("if (_greaterThan) {"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return Boolean.valueOf(false);"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("return Boolean.valueOf(false);"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("}"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return null;"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("}"); _builder_1.newLine(); + _builder_1.append(" "); + _builder_1.append("return null;"); + _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); diff --git a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug419688Test.java b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug419688Test.java index 60f147a60bb..bac2289dca1 100644 --- a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug419688Test.java +++ b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug419688Test.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2013 itemis AG (http://www.itemis.eu) and others. + * Copyright (c) 2013, 2024 itemis AG (http://www.itemis.eu) and others. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. @@ -58,6 +58,9 @@ public void test_01() { _builder_1.newLine(); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public D m() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -113,6 +116,9 @@ public void test_02() { _builder_1.newLine(); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public Iterable m() {"); _builder_1.newLine(); _builder_1.append(" "); diff --git a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug421999Test.java b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug421999Test.java index ee1ff959191..7a8fe1ccf5d 100644 --- a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug421999Test.java +++ b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug421999Test.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2013 itemis AG (http://www.itemis.eu) and others. + * Copyright (c) 2013, 2024 itemis AG (http://www.itemis.eu) and others. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. @@ -48,17 +48,11 @@ public void test_01() { _builder_1.append("public List m(final List list) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function1 _function = new Function1() {"); + _builder_1.append("final Function1 _function = (String e) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public String apply(final String e) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return e;"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -105,17 +99,11 @@ public void test_02() { _builder_1.append("public List m(final List list) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function1 _function = new Function1() {"); + _builder_1.append("final Function1 _function = (String e) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public String apply(final String e) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return e;"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -162,17 +150,11 @@ public void test_03() { _builder_1.append("public List m(final List list) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function1 _function = new Function1() {"); + _builder_1.append("final Function1 _function = (String e) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public String apply(final String e) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return e;"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -219,17 +201,11 @@ public void test_04() { _builder_1.append("public List m(final List list) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function1 _function = new Function1() {"); + _builder_1.append("final Function1 _function = (String e) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public String apply(final String e) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return e;"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -353,22 +329,16 @@ public void test_05() { _builder_1.append("final ArrayList c = CollectionLiterals.newArrayList();"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function1> _function = new Function1>() {"); + _builder_1.append("final Function1> _function = (IEObjectDescription eod) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Pair apply(final IEObjectDescription eod) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("QualifiedName _qualifiedName = eod.getQualifiedName();"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("T _resolve = Dummy.this.resolve(eod, resourceSet);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return Pair.of(_qualifiedName, _resolve);"); + _builder_1.append(" "); + _builder_1.append("T _resolve = this.resolve(eod, resourceSet);"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("return Pair.of(_qualifiedName, _resolve);"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); diff --git a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug422864Test.java b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug422864Test.java index 2c1e5e975d5..d76d254c78c 100644 --- a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug422864Test.java +++ b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug422864Test.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2014, 2016 itemis AG (http://www.itemis.eu) and others. + * Copyright (c) 2014, 2024 itemis AG (http://www.itemis.eu) and others. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. @@ -67,17 +67,11 @@ public void testBug422864_00() { _builder_1.append("public Pair, String> test(final L, String>> l) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function1, String>, Double> _function = new Function1, String>, Double>() {"); + _builder_1.append("final Function1, String>, Double> _function = (Pair, String> it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Double apply(final Pair, String> it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return it.getKey().getValue();"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); diff --git a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug424763Test.java b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug424763Test.java index 07b54709953..e55b5c37b7f 100644 --- a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug424763Test.java +++ b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug424763Test.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2014, 2016 itemis AG (http://www.itemis.eu) and others. + * Copyright (c) 2014, 2024 itemis AG (http://www.itemis.eu) and others. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. @@ -129,6 +129,9 @@ public void testBug_424763_01() { _builder_1.newLine(); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public JAVA_TYPE apply() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -652,6 +655,9 @@ public void testBug_424763_06() { _builder_1.append("this(new Function0>() {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public Function0 apply() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -836,6 +842,9 @@ public void testBug_424763_08() { _builder_1.append("this(theConstructor.doGetConstructor(new Function0() {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public String apply() {"); _builder_1.newLine(); _builder_1.append(" "); diff --git a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug427637Test.java b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug427637Test.java index a006d18ecf2..c793facb8c8 100644 --- a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug427637Test.java +++ b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug427637Test.java @@ -55,13 +55,7 @@ public void testBug_427637_01() { _builder_1.append("public void m(final List list) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Procedure1 _function = new Procedure1() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void apply(final V it) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("final Procedure1 _function = (V it) -> {"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); @@ -120,13 +114,7 @@ public void testBug_427637_01_b() { _builder_1.append("public void m(final List list) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Consumer _function = new Consumer() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void accept(final V it) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("final Consumer _function = (V it) -> {"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); @@ -181,13 +169,7 @@ public void testBug_427637_02() { _builder_1.append("public void m(final List list) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Procedure1 _function = new Procedure1() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void apply(final V it) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("final Procedure1 _function = (V it) -> {"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); @@ -246,13 +228,7 @@ public void testBug_427637_02_b() { _builder_1.append("public void m(final List list) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Consumer _function = new Consumer() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void accept(final V it) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("final Consumer _function = (V it) -> {"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); @@ -307,13 +283,7 @@ public void testBug_427637_03() { _builder_1.append("public void m(final List list) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Procedure1 _function = new Procedure1() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void apply(final Object it) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("final Procedure1 _function = (Object it) -> {"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); @@ -372,13 +342,7 @@ public void testBug_427637_03_b() { _builder_1.append("public void m(final List list) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Consumer _function = new Consumer() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void accept(final Object it) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("final Consumer _function = (Object it) -> {"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); @@ -433,13 +397,7 @@ public void testBug_427637_04() { _builder_1.append("public void m(final List list) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Procedure1 _function = new Procedure1() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void apply(final V it) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("final Procedure1 _function = (V it) -> {"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); @@ -498,13 +456,7 @@ public void testBug_427637_04_b() { _builder_1.append("public void m(final List list) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Consumer _function = new Consumer() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void accept(final V it) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("final Consumer _function = (V it) -> {"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); @@ -559,13 +511,7 @@ public void testBug_427637_05() { _builder_1.append("public void m(final List list) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Procedure1 _function = new Procedure1() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void apply(final V it) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("final Procedure1 _function = (V it) -> {"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); @@ -624,13 +570,7 @@ public void testBug_427637_05_b() { _builder_1.append("public void m(final List list) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Consumer _function = new Consumer() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void accept(final V it) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("final Consumer _function = (V it) -> {"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); @@ -685,13 +625,7 @@ public void testBug_427637_06() { _builder_1.append("public void m(final List list) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Procedure1 _function = new Procedure1() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void apply(final Object it) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("final Procedure1 _function = (Object it) -> {"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); @@ -750,13 +684,7 @@ public void testBug_427637_06_b() { _builder_1.append("public void m(final List list) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Consumer _function = new Consumer() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void accept(final Object it) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("final Consumer _function = (Object it) -> {"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); @@ -814,17 +742,11 @@ public void testBug_427637_07() { _builder_1.append("public void m(final List list) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Procedure1 _function = new Procedure1() {"); + _builder_1.append("final Procedure1 _function = (V it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public void apply(final V it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("it.toString();"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -885,17 +807,11 @@ public void testBug_427637_07_b() { _builder_1.append("public void m(final List list) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Consumer _function = new Consumer() {"); + _builder_1.append("final Consumer _function = (V it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public void accept(final V it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("it.toString();"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -952,17 +868,11 @@ public void testBug_427637_08() { _builder_1.append("public void m(final List list) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Procedure1 _function = new Procedure1() {"); + _builder_1.append("final Procedure1 _function = (V it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public void apply(final V it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("it.toString();"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -1023,17 +933,11 @@ public void testBug_427637_08_b() { _builder_1.append("public void m(final List list) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Consumer _function = new Consumer() {"); + _builder_1.append("final Consumer _function = (V it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public void accept(final V it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("it.toString();"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -1090,17 +994,11 @@ public void testBug_427637_09() { _builder_1.append("public void m(final List list) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Procedure1 _function = new Procedure1() {"); + _builder_1.append("final Procedure1 _function = (Object it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public void apply(final Object it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("it.toString();"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -1161,17 +1059,11 @@ public void testBug_427637_09_b() { _builder_1.append("public void m(final List list) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Consumer _function = new Consumer() {"); + _builder_1.append("final Consumer _function = (Object it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public void accept(final Object it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("it.toString();"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -1234,17 +1126,11 @@ public void testBug_427637_10() { _builder_1.append("final List target = null;"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Procedure1 _function = new Procedure1() {"); + _builder_1.append("final Procedure1 _function = (V it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public void apply(final V it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("target.add(it);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -1311,17 +1197,11 @@ public void testBug_427637_10_b() { _builder_1.append("final List target = null;"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Consumer _function = new Consumer() {"); + _builder_1.append("final Consumer _function = (V it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public void accept(final V it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("target.add(it);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -1396,43 +1276,37 @@ public void testBug_427637_11() { _builder_1.append("final List target = null;"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Consumer _function = new Consumer() {"); + _builder_1.append("final Consumer _function = (T it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public void accept(final T it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("List _subList = target.subList(0, 1);"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("_subList.add(it);"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("List _subList_1 = target.subList(0, 1);"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("_subList_1.remove(it);"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("List _subList_2 = target.subList(0, 1);"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("ArrayList _newArrayList = CollectionLiterals.newArrayList(it);"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("Iterables.addAll(_subList_2, _newArrayList);"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("List _subList_3 = target.subList(0, 1);"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("ArrayList _newArrayList_1 = CollectionLiterals.newArrayList(it);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Iterables.removeAll(_subList_3, _newArrayList_1);"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("Iterables.removeAll(_subList_3, _newArrayList_1);"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); @@ -1473,7 +1347,7 @@ public void testBug_427637_12() { _builder.append("if(change.wasAdded)"); _builder.newLine(); _builder.append("\t\t\t\t"); - _builder.append("change.addedSubList.forEach [ T it | // Xtend bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=427637"); + _builder.append("change.addedSubList.forEach [ T it |"); _builder.newLine(); _builder.append("\t\t\t\t\t"); _builder.append("layer.children += it"); @@ -1488,7 +1362,7 @@ public void testBug_427637_12() { _builder.append("if(change.wasRemoved) "); _builder.newLine(); _builder.append("\t\t\t\t"); - _builder.append("change.removed.forEach [ T it | // Xtend bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=427637"); + _builder.append("change.removed.forEach [ T it |"); _builder.newLine(); _builder.append("\t\t\t\t\t"); _builder.append("layer.children -= it"); @@ -1563,6 +1437,9 @@ public void testBug_427637_12() { _builder_1.newLine(); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public void onChanged(final Change change) {"); _builder_1.newLine(); _builder_1.append(" "); @@ -1578,22 +1455,16 @@ public void testBug_427637_12() { _builder_1.append("if (_wasAdded) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Consumer _function = new Consumer() {"); + _builder_1.append("final Consumer _function = (T it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public void accept(final T it) {"); + _builder_1.append("ObservableList _children = this.layer.getChildren();"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("ObservableList _children = Listener.this.layer.getChildren();"); - _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("_children.add(it);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("it.activate();"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("it.activate();"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); @@ -1611,19 +1482,13 @@ public void testBug_427637_12() { _builder_1.append("if (_wasRemoved) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Consumer _function_1 = new Consumer() {"); + _builder_1.append("final Consumer _function_1 = (T it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public void accept(final T it) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("ObservableList _children = Listener.this.layer.getChildren();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_children.remove(it);"); + _builder_1.append("ObservableList _children = this.layer.getChildren();"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("_children.remove(it);"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); @@ -1763,6 +1628,9 @@ public void testBug_427637_13() { _builder_1.newLine(); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public void onChanged(final Change change) {"); _builder_1.newLine(); _builder_1.append(" "); @@ -1778,22 +1646,16 @@ public void testBug_427637_13() { _builder_1.append("if (_wasAdded) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Consumer _function = new Consumer() {"); + _builder_1.append("final Consumer _function = (T it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public void accept(final T it) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("ObservableList _children = Listener.this.layer.getChildren();"); + _builder_1.append("ObservableList _children = this.layer.getChildren();"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("_children.add(it);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("it.activate();"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("it.activate();"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); @@ -1811,19 +1673,13 @@ public void testBug_427637_13() { _builder_1.append("if (_wasRemoved) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Consumer _function_1 = new Consumer() {"); + _builder_1.append("final Consumer _function_1 = (T it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public void accept(final T it) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("ObservableList _children = Listener.this.layer.getChildren();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_children.remove(it);"); + _builder_1.append("ObservableList _children = this.layer.getChildren();"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("_children.remove(it);"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); @@ -1941,19 +1797,13 @@ public void testBug_427637_14() { _builder_1.append("public void onChanged(final Change change) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Procedure1 _function = new Procedure1() {"); + _builder_1.append("final Procedure1 _function = (T it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public void apply(final T it) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("ObservableList _children = Listener.this.layer.getChildren();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_children.add(it);"); + _builder_1.append("ObservableList _children = this.layer.getChildren();"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("_children.add(it);"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); @@ -2776,6 +2626,9 @@ public void testBug_427637_15() { _builder_1.newLine(); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public String toString() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -2830,46 +2683,40 @@ public void testBug_427637_15() { _builder_1.append("protected Function1> _newFormattingData(final HiddenLeafs leafs, final Void key, final FormattingDataFactory.FormattingDataInit it) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function1> _function = new Function1>() {"); + _builder_1.append("final Function1> _function = (FormattableDocument doc) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Iterable apply(final FormattableDocument doc) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("Integer _elvis = null;"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("if (it.newLines != null) {"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("_elvis = it.newLines;"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("} else {"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("_elvis = Integer.valueOf(0);"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("}"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("final int newLines2 = (int) _elvis;"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("if (((Objects.equals(it.space, null) && Objects.equals(it.newLines, null)) || ((leafs.getNewLinesInComments() == 0) && ((newLines2 == 0) || Objects.equals(it.space, \"\"))))) {"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return FormattingDataFactory.this.newWhitespaceData(leafs, it.space, it.increaseIndentationChange, it.decreaseIndentationChange, doc.isDebugConflicts());"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("} else {"); + _builder_1.append("return this.newWhitespaceData(leafs, it.space, it.increaseIndentationChange, it.decreaseIndentationChange, doc.isDebugConflicts());"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return FormattingDataFactory.this.newNewLineData(leafs, newLines2, newLines2, it.increaseIndentationChange, it.decreaseIndentationChange, doc.isDebugConflicts());"); + _builder_1.append(" "); + _builder_1.append("} else {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("return this.newNewLineData(leafs, newLines2, newLines2, it.increaseIndentationChange, it.decreaseIndentationChange, doc.isDebugConflicts());"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("}"); @@ -2888,41 +2735,35 @@ public void testBug_427637_15() { _builder_1.append("protected Function1> _newFormattingData(final HiddenLeafs leafs, final BlankLineKey key, final FormattingDataFactory.FormattingDataInit it) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function1> _function = new Function1>() {"); + _builder_1.append("final Function1> _function = (FormattableDocument doc) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Iterable apply(final FormattableDocument doc) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("Iterable _xblockexpression = null;"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("{"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("final int blankline = doc.getCfg().get(key);"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("final int preserve = doc.getCfg().get(XbaseFormatterPreferenceKeys.preserveBlankLines);"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("final int min = (blankline + 1);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final int max = Math.max((preserve + 1), min);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_xblockexpression = FormattingDataFactory.this.newNewLineData(leafs, min, max, it.increaseIndentationChange, it.decreaseIndentationChange, doc.isDebugConflicts());"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("final int max = Math.max((preserve + 1), min);"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("return _xblockexpression;"); + _builder_1.append("_xblockexpression = this.newNewLineData(leafs, min, max, it.increaseIndentationChange, it.decreaseIndentationChange, doc.isDebugConflicts());"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("}"); _builder_1.newLine(); + _builder_1.append(" "); + _builder_1.append("return _xblockexpression;"); + _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -2937,73 +2778,67 @@ public void testBug_427637_15() { _builder_1.append("protected Function1> _newFormattingData(final HiddenLeafs leafs, final NewLineOrPreserveKey key, final FormattingDataFactory.FormattingDataInit it) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function1> _function = new Function1>() {"); + _builder_1.append("final Function1> _function = (FormattableDocument doc) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Iterable apply(final FormattableDocument doc) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("Iterable _xblockexpression = null;"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("{"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("final boolean newLine = doc.getCfg().get(key);"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("final boolean preserve = doc.getCfg().get(XbaseFormatterPreferenceKeys.preserveNewLines);"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("int _xifexpression = (int) 0;"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("if (newLine) {"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("_xifexpression = 1;"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("} else {"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("_xifexpression = 0;"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("}"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("int _xifexpression_1 = (int) 0;"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("if ((preserve || newLine)) {"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("_xifexpression_1 = 1;"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("} else {"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("_xifexpression_1 = 0;"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("}"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_xblockexpression = FormattingDataFactory.this.newNewLineData(leafs, _xifexpression, _xifexpression_1, it.increaseIndentationChange, it.decreaseIndentationChange, "); + _builder_1.append(" "); + _builder_1.append("_xblockexpression = this.newNewLineData(leafs, _xifexpression, _xifexpression_1, it.increaseIndentationChange, it.decreaseIndentationChange, "); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("doc.isDebugConflicts());"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("}"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return _xblockexpression;"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("return _xblockexpression;"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); @@ -3019,53 +2854,47 @@ public void testBug_427637_15() { _builder_1.append("protected Function1> _newFormattingData(final HiddenLeafs leafs, final NewLineKey key, final FormattingDataFactory.FormattingDataInit it) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function1> _function = new Function1>() {"); + _builder_1.append("final Function1> _function = (FormattableDocument doc) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Iterable apply(final FormattableDocument doc) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("Iterable _xblockexpression = null;"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("{"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("final boolean newLine = doc.getCfg().get(key);"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("int _xifexpression = (int) 0;"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("if (newLine) {"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("_xifexpression = 1;"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("} else {"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("_xifexpression = 0;"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("}"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final int minmax = _xifexpression;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_xblockexpression = FormattingDataFactory.this.newNewLineData(leafs, minmax, minmax, it.increaseIndentationChange, it.decreaseIndentationChange, doc.isDebugConflicts());"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("final int minmax = _xifexpression;"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("return _xblockexpression;"); + _builder_1.append("_xblockexpression = this.newNewLineData(leafs, minmax, minmax, it.increaseIndentationChange, it.decreaseIndentationChange, doc.isDebugConflicts());"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("}"); _builder_1.newLine(); + _builder_1.append(" "); + _builder_1.append("return _xblockexpression;"); + _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -3096,50 +2925,44 @@ public void testBug_427637_15() { _builder_1.append("protected Function1> _newFormattingData(final HiddenLeafs leafs, final WhitespaceKey key, final FormattingDataFactory.FormattingDataInit it) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function1> _function = new Function1>() {"); + _builder_1.append("final Function1> _function = (FormattableDocument doc) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Iterable apply(final FormattableDocument doc) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("Iterable _xblockexpression = null;"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("{"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("final boolean space = doc.getCfg().get(key);"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("String _xifexpression = null;"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("if (space) {"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("_xifexpression = \" \";"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("} else {"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_xifexpression = \"\";"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("_xblockexpression = FormattingDataFactory.this.newWhitespaceData(leafs, _xifexpression, it.increaseIndentationChange, it.decreaseIndentationChange, doc.isDebugConflicts());"); + _builder_1.append("_xifexpression = \"\";"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("}"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("return _xblockexpression;"); + _builder_1.append("_xblockexpression = this.newWhitespaceData(leafs, _xifexpression, it.increaseIndentationChange, it.decreaseIndentationChange, doc.isDebugConflicts());"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("}"); _builder_1.newLine(); + _builder_1.append(" "); + _builder_1.append("return _xblockexpression;"); + _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -3932,119 +3755,113 @@ public void testBug_427637_15() { _builder_1.append("public Function1> surround(final INode node, final Procedure1 init) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function1> _function = new Function1>() {"); + _builder_1.append("final Function1> _function = (FormattableDocument doc) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Iterable apply(final FormattableDocument doc) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("ArrayList _xblockexpression = null;"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("{"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("final ArrayList result = CollectionLiterals.newArrayList();"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("boolean _notEquals = (!Objects.equals(node, null));"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("if (_notEquals) {"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("Iterable _elvis = null;"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Function1> _newFormattingData = FormattingDataFactory.this.newFormattingData(FormattingDataFactory.this._hiddenLeafAccess.getHiddenLeafsBefore(node), init);"); + _builder_1.append(" "); + _builder_1.append("Function1> _newFormattingData = this.newFormattingData(this._hiddenLeafAccess.getHiddenLeafsBefore(node), init);"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("Iterable _apply = null;"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("if (_newFormattingData!=null) {"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("_apply=_newFormattingData.apply(doc);"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("}"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("if (_apply != null) {"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("_elvis = _apply;"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("} else {"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("List _emptyList = CollectionLiterals.emptyList();"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("_elvis = _emptyList;"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("}"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("Iterables.addAll(result, _elvis);"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("Iterable _elvis_1 = null;"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Function1> _newFormattingData_1 = FormattingDataFactory.this.newFormattingData(FormattingDataFactory.this._hiddenLeafAccess.getHiddenLeafsAfter(node), init);"); + _builder_1.append(" "); + _builder_1.append("Function1> _newFormattingData_1 = this.newFormattingData(this._hiddenLeafAccess.getHiddenLeafsAfter(node), init);"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("Iterable _apply_1 = null;"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("if (_newFormattingData_1!=null) {"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("_apply_1=_newFormattingData_1.apply(doc);"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("}"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("if (_apply_1 != null) {"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("_elvis_1 = _apply_1;"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("} else {"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("List _emptyList_1 = CollectionLiterals.emptyList();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_elvis_1 = _emptyList_1;"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("List _emptyList_1 = CollectionLiterals.emptyList();"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("Iterables.addAll(result, _elvis_1);"); + _builder_1.append("_elvis_1 = _emptyList_1;"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("}"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("_xblockexpression = result;"); + _builder_1.append("Iterables.addAll(result, _elvis_1);"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("}"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("return _xblockexpression;"); + _builder_1.append("_xblockexpression = result;"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("}"); _builder_1.newLine(); + _builder_1.append(" "); + _builder_1.append("return _xblockexpression;"); + _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -4059,119 +3876,113 @@ public void testBug_427637_15() { _builder_1.append("public Function1> surround(final INode node, final Procedure1 before, final Procedure1 after) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function1> _function = new Function1>() {"); + _builder_1.append("final Function1> _function = (FormattableDocument doc) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Iterable apply(final FormattableDocument doc) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("ArrayList _xblockexpression = null;"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("{"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("final ArrayList result = CollectionLiterals.newArrayList();"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("boolean _notEquals = (!Objects.equals(node, null));"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("if (_notEquals) {"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("Iterable _elvis = null;"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Function1> _newFormattingData = FormattingDataFactory.this.newFormattingData(FormattingDataFactory.this._hiddenLeafAccess.getHiddenLeafsBefore(node), before);"); + _builder_1.append(" "); + _builder_1.append("Function1> _newFormattingData = this.newFormattingData(this._hiddenLeafAccess.getHiddenLeafsBefore(node), before);"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("Iterable _apply = null;"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("if (_newFormattingData!=null) {"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("_apply=_newFormattingData.apply(doc);"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("}"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("if (_apply != null) {"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("_elvis = _apply;"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("} else {"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("List _emptyList = CollectionLiterals.emptyList();"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("_elvis = _emptyList;"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("}"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("Iterables.addAll(result, _elvis);"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("Iterable _elvis_1 = null;"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Function1> _newFormattingData_1 = FormattingDataFactory.this.newFormattingData(FormattingDataFactory.this._hiddenLeafAccess.getHiddenLeafsAfter(node), after);"); + _builder_1.append(" "); + _builder_1.append("Function1> _newFormattingData_1 = this.newFormattingData(this._hiddenLeafAccess.getHiddenLeafsAfter(node), after);"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("Iterable _apply_1 = null;"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("if (_newFormattingData_1!=null) {"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("_apply_1=_newFormattingData_1.apply(doc);"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("}"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("if (_apply_1 != null) {"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("_elvis_1 = _apply_1;"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("} else {"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("List _emptyList_1 = CollectionLiterals.emptyList();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_elvis_1 = _emptyList_1;"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("List _emptyList_1 = CollectionLiterals.emptyList();"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("Iterables.addAll(result, _elvis_1);"); + _builder_1.append("_elvis_1 = _emptyList_1;"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("}"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("_xblockexpression = result;"); + _builder_1.append("Iterables.addAll(result, _elvis_1);"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("}"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("return _xblockexpression;"); + _builder_1.append("_xblockexpression = result;"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("}"); _builder_1.newLine(); + _builder_1.append(" "); + _builder_1.append("return _xblockexpression;"); + _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); diff --git a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug428063Test.java b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug428063Test.java index c7226503390..753f26e7ed2 100644 --- a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug428063Test.java +++ b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug428063Test.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2014 itemis AG (http://www.itemis.eu) and others. + * Copyright (c) 2014, 2024 itemis AG (http://www.itemis.eu) and others. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. @@ -50,13 +50,7 @@ public void testBug_428063_01() { _builder_1.append("public static void main() {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Procedure1 _function = new Procedure1() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void apply(final Integer it) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("final Procedure1 _function = (Integer it) -> {"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); @@ -116,13 +110,7 @@ public void testBug_428063_02() { _builder_1.append("public static void main() {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Procedure1 _function = new Procedure1() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void apply(final Integer it) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("final Procedure1 _function = (Integer it) -> {"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); diff --git a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug432193Test.java b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug432193Test.java index 880b6d6db74..e5a6b9260e4 100644 --- a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug432193Test.java +++ b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug432193Test.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2014 itemis AG (http://www.itemis.eu) and others. + * Copyright (c) 2014, 2024 itemis AG (http://www.itemis.eu) and others. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. @@ -45,19 +45,13 @@ public void testBug_432193_01() { _builder_1.append("public class C {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("private D d = new D() {"); + _builder_1.append("private D d = ((D) (String o) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public void m(final String o) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("o.subSequence(1, 2);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("};"); + _builder_1.append("});"); _builder_1.newLine(); _builder_1.append("}"); _builder_1.newLine(); diff --git a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug434424Test.java b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug434424Test.java index f9e31588dc2..d05c3a3d824 100644 --- a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug434424Test.java +++ b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug434424Test.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2014 itemis AG (http://www.itemis.eu) and others. + * Copyright (c) 2014, 2024 itemis AG (http://www.itemis.eu) and others. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. @@ -545,17 +545,11 @@ public void test_10() { _builder_1.append("public void setField(final String field) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function1 _function = new Function1() {"); + _builder_1.append("final Function1 _function = (Number it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Number apply(final Number it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return it;"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); diff --git a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug435473Test.java b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug435473Test.java index 0836c3b876f..38353468d3f 100644 --- a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug435473Test.java +++ b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug435473Test.java @@ -44,31 +44,19 @@ public void test_01() { _builder_1.append("public class Outer {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("private final List> x = Collections.>unmodifiableList(CollectionLiterals.>newArrayList(new Function0() {"); + _builder_1.append("private final List> x = Collections.>unmodifiableList(CollectionLiterals.>newArrayList(((Function0) () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Object apply() {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return Integer.valueOf(1);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}, new Function0() {"); + _builder_1.append("}), ((Function0) () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Object apply() {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return Double.valueOf(1.0);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}));"); + _builder_1.append("})));"); _builder_1.newLine(); _builder_1.append("}"); _builder_1.newLine(); @@ -102,31 +90,19 @@ public void test_02() { _builder_1.append("public class Outer {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("private final List> x = Collections.>unmodifiableList(CollectionLiterals.>newArrayList(new Function0() {"); + _builder_1.append("private final List> x = Collections.>unmodifiableList(CollectionLiterals.>newArrayList(((Function0) () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Number apply() {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return Integer.valueOf(1);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}, new Function0() {"); + _builder_1.append("}), ((Function0) () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Number apply() {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return Double.valueOf(1.0);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}));"); + _builder_1.append("})));"); _builder_1.newLine(); _builder_1.append("}"); _builder_1.newLine(); @@ -160,31 +136,19 @@ public void test_03() { _builder_1.append("public class Outer {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("private final List> x = Collections.>unmodifiableList(CollectionLiterals.>newArrayList(new Function0() {"); + _builder_1.append("private final List> x = Collections.>unmodifiableList(CollectionLiterals.>newArrayList(((Function0) () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Number apply() {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return Integer.valueOf(1);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}, new Function0() {"); + _builder_1.append("}), ((Function0) () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Number apply() {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return Double.valueOf(1.0);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}));"); + _builder_1.append("})));"); _builder_1.newLine(); _builder_1.append("}"); _builder_1.newLine(); @@ -218,31 +182,19 @@ public void test_04() { _builder_1.append("public class Outer {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("private final List> x = Collections.>unmodifiableList(CollectionLiterals.>newArrayList(new Function0() {"); + _builder_1.append("private final List> x = Collections.>unmodifiableList(CollectionLiterals.>newArrayList(((Function0) () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Number apply() {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return Integer.valueOf(1);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}, new Function0() {"); + _builder_1.append("}), ((Function0) () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Number apply() {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return Double.valueOf(1.0);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}));"); + _builder_1.append("})));"); _builder_1.newLine(); _builder_1.append("}"); _builder_1.newLine(); @@ -276,31 +228,19 @@ public void test_05() { _builder_1.append("public class Outer {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("private final Set> x = Collections.>unmodifiableSet(CollectionLiterals.>newHashSet(new Function0() {"); + _builder_1.append("private final Set> x = Collections.>unmodifiableSet(CollectionLiterals.>newHashSet(((Function0) () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Number apply() {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return Integer.valueOf(1);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}, new Function0() {"); + _builder_1.append("}), ((Function0) () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Number apply() {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return Double.valueOf(1.0);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}));"); + _builder_1.append("})));"); _builder_1.newLine(); _builder_1.append("}"); _builder_1.newLine(); @@ -334,31 +274,19 @@ public void test_06() { _builder_1.append("public class Outer {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("private final Set> x = Collections.>unmodifiableSet(CollectionLiterals.>newHashSet(new Function0() {"); + _builder_1.append("private final Set> x = Collections.>unmodifiableSet(CollectionLiterals.>newHashSet(((Function0) () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Number apply() {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return Integer.valueOf(1);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}, new Function0() {"); + _builder_1.append("}), ((Function0) () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Number apply() {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return Double.valueOf(1.0);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}));"); + _builder_1.append("})));"); _builder_1.newLine(); _builder_1.append("}"); _builder_1.newLine(); @@ -392,31 +320,19 @@ public void test_07() { _builder_1.append("public class Outer {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("private final Set> x = Collections.>unmodifiableSet(CollectionLiterals.>newHashSet(new Function0() {"); + _builder_1.append("private final Set> x = Collections.>unmodifiableSet(CollectionLiterals.>newHashSet(((Function0) () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Number apply() {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return Integer.valueOf(1);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}, new Function0() {"); + _builder_1.append("}), ((Function0) () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Number apply() {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return Double.valueOf(1.0);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}));"); + _builder_1.append("})));"); _builder_1.newLine(); _builder_1.append("}"); _builder_1.newLine(); @@ -450,31 +366,19 @@ public void test_08() { _builder_1.append("public class Outer {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("private final Set> x = Collections.>unmodifiableSet(CollectionLiterals.>newHashSet(new Function0() {"); + _builder_1.append("private final Set> x = Collections.>unmodifiableSet(CollectionLiterals.>newHashSet(((Function0) () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Number apply() {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return Integer.valueOf(1);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}, new Function0() {"); + _builder_1.append("}), ((Function0) () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Number apply() {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return Double.valueOf(1.0);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}));"); + _builder_1.append("})));"); _builder_1.newLine(); _builder_1.append("}"); _builder_1.newLine(); @@ -506,31 +410,19 @@ public void test_09() { _builder_1.append("public class Outer {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("private final List> x = CollectionLiterals.>newArrayList(new Function0() {"); + _builder_1.append("private final List> x = CollectionLiterals.>newArrayList(((Function0) () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Integer apply() {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return Integer.valueOf(1);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}, new Function0() {"); + _builder_1.append("}), ((Function0) () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Double apply() {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return Double.valueOf(1.0);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("});"); + _builder_1.append("}));"); _builder_1.newLine(); _builder_1.append("}"); _builder_1.newLine(); @@ -562,31 +454,19 @@ public void test_10() { _builder_1.append("public class Outer {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("private final List> x = CollectionLiterals.>newArrayList(new Function0() {"); + _builder_1.append("private final List> x = CollectionLiterals.>newArrayList(((Function0) () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Integer apply() {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return Integer.valueOf(1);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}, new Function0() {"); + _builder_1.append("}), ((Function0) () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Double apply() {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return Double.valueOf(1.0);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("});"); + _builder_1.append("}));"); _builder_1.newLine(); _builder_1.append("}"); _builder_1.newLine(); @@ -618,31 +498,19 @@ public void test_11() { _builder_1.append("public class Outer {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("private final List> x = CollectionLiterals.>newArrayList(new Function0() {"); + _builder_1.append("private final List> x = CollectionLiterals.>newArrayList(((Function0) () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Integer apply() {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return Integer.valueOf(1);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}, new Function0() {"); + _builder_1.append("}), ((Function0) () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Double apply() {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return Double.valueOf(1.0);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("});"); + _builder_1.append("}));"); _builder_1.newLine(); _builder_1.append("}"); _builder_1.newLine(); @@ -695,31 +563,19 @@ public void test_13() { _builder_1.append("public class Outer {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("private final List> x = Collections.>unmodifiableList(CollectionLiterals.>newArrayList(new Function0() {"); + _builder_1.append("private final List> x = Collections.>unmodifiableList(CollectionLiterals.>newArrayList(((Function0) () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Integer apply() {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return Integer.valueOf(1);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}, new Function0() {"); + _builder_1.append("}), ((Function0) () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Double apply() {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return Double.valueOf(1.0);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}));"); + _builder_1.append("})));"); _builder_1.newLine(); _builder_1.append("}"); _builder_1.newLine(); @@ -751,31 +607,19 @@ public void test_14() { _builder_1.append("public class Outer {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("private final ArrayList> x = CollectionLiterals.>newArrayList(new Function0() {"); + _builder_1.append("private final ArrayList> x = CollectionLiterals.>newArrayList(((Function0) () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Integer apply() {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return Integer.valueOf(1);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}, new Function0() {"); + _builder_1.append("}), ((Function0) () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Double apply() {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return Double.valueOf(1.0);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("});"); + _builder_1.append("}));"); _builder_1.newLine(); _builder_1.append("}"); _builder_1.newLine(); @@ -807,31 +651,19 @@ public void test_15() { _builder_1.append("public class Outer {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("private final List> x = CollectionLiterals.>newArrayList(new Function0() {"); + _builder_1.append("private final List> x = CollectionLiterals.>newArrayList(((Function0) () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Number apply() {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return Integer.valueOf(1);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}, new Function0() {"); + _builder_1.append("}), ((Function0) () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Number apply() {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return Double.valueOf(1.0);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("});"); + _builder_1.append("}));"); _builder_1.newLine(); _builder_1.append("}"); _builder_1.newLine(); @@ -867,31 +699,19 @@ public void test_16() { _builder_1.append("public class Outer {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("private final Map> y = Collections.>unmodifiableMap(CollectionLiterals.>newHashMap(Pair.>of(\"\", new Function0() {"); + _builder_1.append("private final Map> y = Collections.>unmodifiableMap(CollectionLiterals.>newHashMap(Pair.>of(\"\", ((Function0) () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Integer apply() {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return Integer.valueOf(1);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}), Pair.>of(\"\", new Function0() {"); + _builder_1.append("})), Pair.>of(\"\", ((Function0) () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Double apply() {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return Double.valueOf(1.0);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("})));"); + _builder_1.append("}))));"); _builder_1.newLine(); _builder_1.append("}"); _builder_1.newLine(); @@ -927,31 +747,19 @@ public void test_17() { _builder_1.append("public class Outer {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("private final Map> y = Collections.>unmodifiableMap(CollectionLiterals.>newHashMap(Pair.>of(((StringBuilder) null), new Function0() {"); + _builder_1.append("private final Map> y = Collections.>unmodifiableMap(CollectionLiterals.>newHashMap(Pair.>of(((StringBuilder) null), ((Function0) () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Integer apply() {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return Integer.valueOf(1);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}), Pair.>of(((StringBuffer) null), new Function0() {"); + _builder_1.append("})), Pair.>of(((StringBuffer) null), ((Function0) () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Double apply() {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return Double.valueOf(1.0);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("})));"); + _builder_1.append("}))));"); _builder_1.newLine(); _builder_1.append("}"); _builder_1.newLine(); @@ -981,19 +789,13 @@ public void test_18() { _builder_1.append("public class Outer {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("private final ArrayList> x = CollectionLiterals.>newArrayList(String.CASE_INSENSITIVE_ORDER, new Comparator>>() {"); + _builder_1.append("private final ArrayList> x = CollectionLiterals.>newArrayList(String.CASE_INSENSITIVE_ORDER, ((Comparator>>) (Comparable> $0, Comparable> $1) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public int compare(final Comparable> $0, final Comparable> $1) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return ($0.compareTo($1));"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("});"); + _builder_1.append("}));"); _builder_1.newLine(); _builder_1.append("}"); _builder_1.newLine(); @@ -1023,19 +825,13 @@ public void test_19() { _builder_1.append("public class Outer {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("private final ArrayList> x = CollectionLiterals.>newArrayList(String.CASE_INSENSITIVE_ORDER, new Comparator() {"); + _builder_1.append("private final ArrayList> x = CollectionLiterals.>newArrayList(String.CASE_INSENSITIVE_ORDER, ((Comparator) (String s1, String s2) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public int compare(final String s1, final String s2) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return (s1.compareTo(s2));"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("});"); + _builder_1.append("}));"); _builder_1.newLine(); _builder_1.append("}"); _builder_1.newLine(); @@ -1199,31 +995,19 @@ public void test_31() { _builder_1.newLine(); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("private final List> x = Collections.>unmodifiableList(CollectionLiterals.>newArrayList(new Function0() {"); + _builder_1.append("private final List> x = Collections.>unmodifiableList(CollectionLiterals.>newArrayList(((Function0) () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Object apply() {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return ((Outer.B) null);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}, new Function0() {"); + _builder_1.append("}), ((Function0) () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Object apply() {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return ((Outer.C) null);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}));"); + _builder_1.append("})));"); _builder_1.newLine(); _builder_1.append("}"); _builder_1.newLine(); @@ -1287,31 +1071,19 @@ public void test_32() { _builder_1.newLine(); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("private final List> x = Collections.>unmodifiableList(CollectionLiterals.>newArrayList(new Function0() {"); + _builder_1.append("private final List> x = Collections.>unmodifiableList(CollectionLiterals.>newArrayList(((Function0) () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Outer.A apply() {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return ((Outer.B) null);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}, new Function0() {"); + _builder_1.append("}), ((Function0) () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Outer.A apply() {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return ((Outer.C) null);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}));"); + _builder_1.append("})));"); _builder_1.newLine(); _builder_1.append("}"); _builder_1.newLine(); @@ -1375,31 +1147,19 @@ public void test_33() { _builder_1.newLine(); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("private final List> x = Collections.>unmodifiableList(CollectionLiterals.>newArrayList(new Function0() {"); + _builder_1.append("private final List> x = Collections.>unmodifiableList(CollectionLiterals.>newArrayList(((Function0) () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Outer.A apply() {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return ((Outer.B) null);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}, new Function0() {"); + _builder_1.append("}), ((Function0) () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Outer.A apply() {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return ((Outer.C) null);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}));"); + _builder_1.append("})));"); _builder_1.newLine(); _builder_1.append("}"); _builder_1.newLine(); @@ -1463,31 +1223,19 @@ public void test_34() { _builder_1.newLine(); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("private final List> x = Collections.>unmodifiableList(CollectionLiterals.>newArrayList(new Function0() {"); + _builder_1.append("private final List> x = Collections.>unmodifiableList(CollectionLiterals.>newArrayList(((Function0) () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Outer.A apply() {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return ((Outer.B) null);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}, new Function0() {"); + _builder_1.append("}), ((Function0) () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Outer.A apply() {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return ((Outer.C) null);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}));"); + _builder_1.append("})));"); _builder_1.newLine(); _builder_1.append("}"); _builder_1.newLine(); @@ -1551,31 +1299,19 @@ public void test_35() { _builder_1.newLine(); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("private final Set> x = Collections.>unmodifiableSet(CollectionLiterals.>newHashSet(new Function0() {"); + _builder_1.append("private final Set> x = Collections.>unmodifiableSet(CollectionLiterals.>newHashSet(((Function0) () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Outer.A apply() {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return ((Outer.B) null);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}, new Function0() {"); + _builder_1.append("}), ((Function0) () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Outer.A apply() {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return ((Outer.C) null);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}));"); + _builder_1.append("})));"); _builder_1.newLine(); _builder_1.append("}"); _builder_1.newLine(); @@ -1639,31 +1375,19 @@ public void test_36() { _builder_1.newLine(); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("private final Set> x = Collections.>unmodifiableSet(CollectionLiterals.>newHashSet(new Function0() {"); + _builder_1.append("private final Set> x = Collections.>unmodifiableSet(CollectionLiterals.>newHashSet(((Function0) () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Outer.A apply() {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return ((Outer.B) null);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}, new Function0() {"); + _builder_1.append("}), ((Function0) () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Outer.A apply() {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return ((Outer.C) null);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}));"); + _builder_1.append("})));"); _builder_1.newLine(); _builder_1.append("}"); _builder_1.newLine(); @@ -1727,31 +1451,19 @@ public void test_37() { _builder_1.newLine(); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("private final Set> x = Collections.>unmodifiableSet(CollectionLiterals.>newHashSet(new Function0() {"); + _builder_1.append("private final Set> x = Collections.>unmodifiableSet(CollectionLiterals.>newHashSet(((Function0) () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Outer.A apply() {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return ((Outer.B) null);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}, new Function0() {"); + _builder_1.append("}), ((Function0) () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Outer.A apply() {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return ((Outer.C) null);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}));"); + _builder_1.append("})));"); _builder_1.newLine(); _builder_1.append("}"); _builder_1.newLine(); @@ -1815,31 +1527,19 @@ public void test_38() { _builder_1.newLine(); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("private final Set> x = Collections.>unmodifiableSet(CollectionLiterals.>newHashSet(new Function0() {"); + _builder_1.append("private final Set> x = Collections.>unmodifiableSet(CollectionLiterals.>newHashSet(((Function0) () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Outer.A apply() {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return ((Outer.B) null);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}, new Function0() {"); + _builder_1.append("}), ((Function0) () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Outer.A apply() {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return ((Outer.C) null);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}));"); + _builder_1.append("})));"); _builder_1.newLine(); _builder_1.append("}"); _builder_1.newLine(); @@ -1901,31 +1601,19 @@ public void test_39() { _builder_1.newLine(); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("private final List> x = CollectionLiterals.>newArrayList(new Function0() {"); + _builder_1.append("private final List> x = CollectionLiterals.>newArrayList(((Function0) () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Outer.B apply() {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return ((Outer.B) null);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}, new Function0() {"); + _builder_1.append("}), ((Function0) () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Outer.C apply() {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return ((Outer.C) null);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("});"); + _builder_1.append("}));"); _builder_1.newLine(); _builder_1.append("}"); _builder_1.newLine(); @@ -1987,31 +1675,19 @@ public void test_40() { _builder_1.newLine(); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("private final List> x = CollectionLiterals.>newArrayList(new Function0() {"); + _builder_1.append("private final List> x = CollectionLiterals.>newArrayList(((Function0) () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Outer.B apply() {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return ((Outer.B) null);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}, new Function0() {"); + _builder_1.append("}), ((Function0) () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Outer.C apply() {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return ((Outer.C) null);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("});"); + _builder_1.append("}));"); _builder_1.newLine(); _builder_1.append("}"); _builder_1.newLine(); @@ -2073,31 +1749,19 @@ public void test_41() { _builder_1.newLine(); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("private final List> x = CollectionLiterals.>newArrayList(new Function0() {"); + _builder_1.append("private final List> x = CollectionLiterals.>newArrayList(((Function0) () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Outer.B apply() {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return ((Outer.B) null);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}, new Function0() {"); + _builder_1.append("}), ((Function0) () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Outer.C apply() {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return ((Outer.C) null);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("});"); + _builder_1.append("}));"); _builder_1.newLine(); _builder_1.append("}"); _builder_1.newLine(); @@ -2189,31 +1853,19 @@ public void test_43() { _builder_1.newLine(); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("private final List> x = Collections.>unmodifiableList(CollectionLiterals.>newArrayList(new Function0() {"); + _builder_1.append("private final List> x = Collections.>unmodifiableList(CollectionLiterals.>newArrayList(((Function0) () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Outer.B apply() {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return ((Outer.B) null);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}, new Function0() {"); + _builder_1.append("}), ((Function0) () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Outer.C apply() {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return ((Outer.C) null);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}));"); + _builder_1.append("})));"); _builder_1.newLine(); _builder_1.append("}"); _builder_1.newLine(); @@ -2275,31 +1927,19 @@ public void test_44() { _builder_1.newLine(); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("private final ArrayList> x = CollectionLiterals.>newArrayList(new Function0() {"); + _builder_1.append("private final ArrayList> x = CollectionLiterals.>newArrayList(((Function0) () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Outer.B apply() {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return ((Outer.B) null);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}, new Function0() {"); + _builder_1.append("}), ((Function0) () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Outer.C apply() {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return ((Outer.C) null);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("});"); + _builder_1.append("}));"); _builder_1.newLine(); _builder_1.append("}"); _builder_1.newLine(); diff --git a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug436230Test.java b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug436230Test.java index a65e5282d19..482de251962 100644 --- a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug436230Test.java +++ b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug436230Test.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2014, 2016 itemis AG (http://www.itemis.eu) and others. + * Copyright (c) 2014, 2024 itemis AG (http://www.itemis.eu) and others. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. @@ -61,17 +61,11 @@ public void test_01() { _builder_1.append("public boolean foo(final List source) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function1 _function = new Function1() {"); + _builder_1.append("final Function1 _function = (Object it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public String apply(final Object it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return \"\";"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -143,17 +137,11 @@ public void test_02() { _builder_1.append("final Iterable obj = null;"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function1 _function = new Function1() {"); + _builder_1.append("final Function1 _function = (Object it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public String apply(final Object it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return \"\";"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -231,17 +219,11 @@ public void test_03() { _builder_1.append("final Iterable obj = null;"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function1 _function = new Function1() {"); + _builder_1.append("final Function1 _function = (Object it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public String apply(final Object it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return \"\";"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -309,17 +291,11 @@ public void test_04() { _builder_1.append("final Iterable obj = null;"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function1 _function = new Function1() {"); + _builder_1.append("final Function1 _function = (Object it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public String apply(final Object it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return \"\";"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); diff --git a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug436886Test.java b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug436886Test.java index 6f29f614afe..082e8c71d15 100644 --- a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug436886Test.java +++ b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug436886Test.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2014 itemis AG (http://www.itemis.eu) and others. + * Copyright (c) 2014, 2024 itemis AG (http://www.itemis.eu) and others. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. @@ -83,61 +83,55 @@ public void test_01() { _builder_1.append("public Test method() {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function1 _function = new Function1() {"); + _builder_1.append("final Function1 _function = (Super it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Boolean apply(final Super it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("boolean _switchResult = false;"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("boolean _matched = false;"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("if (it instanceof Foo) {"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("_matched=true;"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("_switchResult = true;"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("}"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("if (!_matched) {"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("if (it instanceof Bar) {"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("_matched=true;"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("_switchResult = true;"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("}"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("}"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("if (!_matched) {"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("_switchResult = false;"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("}"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return Boolean.valueOf(_switchResult);"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("return Boolean.valueOf(_switchResult);"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); diff --git a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug440196Test.java b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug440196Test.java index b014657ef39..1e0a5cf09bd 100644 --- a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug440196Test.java +++ b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug440196Test.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2014 itemis AG (http://www.itemis.eu) and others. + * Copyright (c) 2014, 2024 itemis AG (http://www.itemis.eu) and others. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. @@ -116,25 +116,19 @@ public void test_02() { _builder_1.append("public Boolean m() {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function0 _function = new Function0() {"); + _builder_1.append("final Function0 _function = () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Boolean apply() {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("if ((Boolean.TRUE).booleanValue()) {"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("return true;"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("}"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return null;"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("return null;"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); diff --git a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug440902Test.java b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug440902Test.java index 01d787fe2dd..e71d99955cb 100644 --- a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug440902Test.java +++ b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug440902Test.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2014, 2016 itemis AG (http://www.itemis.eu) and others. + * Copyright (c) 2014, 2024 itemis AG (http://www.itemis.eu) and others. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. @@ -64,6 +64,9 @@ public void test_01() { _builder_1.newLine(); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public String m() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -106,6 +109,9 @@ public void test_02() { _builder_1.append("public class C implements I {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public String m() {"); _builder_1.newLine(); _builder_1.append(" "); diff --git a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug440906Test.java b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug440906Test.java index f27f6a54c1a..0a326499e20 100644 --- a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug440906Test.java +++ b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug440906Test.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2014, 2016 itemis AG (http://www.itemis.eu) and others. + * Copyright (c) 2014, 2024 itemis AG (http://www.itemis.eu) and others. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. @@ -65,17 +65,11 @@ public void test_01() { _builder_1.append("public Function2 m() {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function2 _function = new Function2() {"); + _builder_1.append("final Function2 _function = (Object a, Object b) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Integer apply(final Object a, final Object b) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return Integer.valueOf(1);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -161,17 +155,11 @@ public void test_02() { _builder_1.append("public Function2 m() {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function2 _function = new Function2() {"); + _builder_1.append("final Function2 _function = (Object a, Object b) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Integer apply(final Object a, final Object b) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return Integer.valueOf(1);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); diff --git a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug441096Test.java b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug441096Test.java index 7926218fa6b..185d101fa19 100644 --- a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug441096Test.java +++ b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug441096Test.java @@ -123,6 +123,9 @@ public void test_01() { _builder_1.append("private final C.I x = new C.I() {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public void m() {"); _builder_1.newLine(); _builder_1.append(" "); diff --git a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug445487Test.java b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug445487Test.java index faf0e95b940..d093af410e7 100644 --- a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug445487Test.java +++ b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug445487Test.java @@ -45,19 +45,13 @@ public void test_01() { _builder_1.append("public class C {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("private Provider lexerProvider = new Provider() {"); + _builder_1.append("private Provider lexerProvider = ((Provider) () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Lexer get() {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return new InternalXtendLexer(null);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("};"); + _builder_1.append("});"); _builder_1.newLine(); _builder_1.append("}"); _builder_1.newLine(); @@ -93,19 +87,13 @@ public void test_02() { _builder_1.append("public class C {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("private Provider lexerProvider = new Provider() {"); + _builder_1.append("private Provider lexerProvider = ((Provider) () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Lexer get() {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return new InternalXtendLexer(null);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("};"); + _builder_1.append("});"); _builder_1.newLine(); _builder_1.append("}"); _builder_1.newLine(); @@ -141,19 +129,13 @@ public void test_03() { _builder_1.append("public class C {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("private Provider lexerProvider = new Provider() {"); + _builder_1.append("private Provider lexerProvider = ((Provider) () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Lexer get() {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return new InternalXtendLexer(null);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("};"); + _builder_1.append("});"); _builder_1.newLine(); _builder_1.append("}"); _builder_1.newLine(); @@ -197,19 +179,13 @@ public void test_04() { _builder_1.append("public Lexer get() {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("return new Function0() {"); + _builder_1.append("return ((Function0) () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public InternalXtendLexer apply() {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return new InternalXtendLexer(null);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}.apply();"); + _builder_1.append("}).apply();"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("}"); @@ -259,19 +235,13 @@ public void test_05() { _builder_1.append("public Lexer get() {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("return ((Function0) new Function0() {"); + _builder_1.append("return ((Function0) ((Function0) () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public InternalXtendLexer apply() {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return new InternalXtendLexer(null);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}).apply();"); + _builder_1.append("})).apply();"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("}"); @@ -321,19 +291,13 @@ public void test_06() { _builder_1.append("public Lexer get() {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("return new Function1() {"); + _builder_1.append("return ((Function1) (Object it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public InternalXtendLexer apply(final Object it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return new InternalXtendLexer(null);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}.apply(null);"); + _builder_1.append("}).apply(null);"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("}"); @@ -391,19 +355,13 @@ public void test_07() { _builder_1.append("public Lexer apply() {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("return new Function1() {"); + _builder_1.append("return ((Function1) (Object it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public InternalXtendLexer apply(final Object it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return new InternalXtendLexer(null);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}.apply(null);"); + _builder_1.append("}).apply(null);"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("}"); diff --git a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug447516Test.java b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug447516Test.java index 8d9d8e1e8cb..b5c76827f91 100644 --- a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug447516Test.java +++ b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug447516Test.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2014 itemis AG (http://www.itemis.eu) and others. + * Copyright (c) 2014, 20204 itemis AG (http://www.itemis.eu) and others. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. @@ -50,6 +50,9 @@ public void test_01() { _builder_1.append("private final IReadAccess readAccess = new IReadAccess() {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public Result readOnly(final IUnitOfWork it) {"); _builder_1.newLine(); _builder_1.append(" "); @@ -129,6 +132,9 @@ public void test_02() { _builder_1.append("private final C.I readAccess = new C.I() {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public T exec(final Function1 it) {"); _builder_1.newLine(); _builder_1.append(" "); @@ -196,6 +202,9 @@ public void test_03() { _builder_1.append("private final C.I i = new C.I() {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public T exec(final String $0, final Function1 $1) {"); _builder_1.newLine(); _builder_1.append(" "); diff --git a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug447551Test.java b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug447551Test.java index 6b465f05623..648e77b01e5 100644 --- a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug447551Test.java +++ b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug447551Test.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2014, 2016 itemis AG (http://www.itemis.eu) and others. + * Copyright (c) 2014, 2024 itemis AG (http://www.itemis.eu) and others. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. @@ -248,6 +248,9 @@ public void test_05() { _builder_1.append("public final C.E e = new Function0>() {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public C.E apply() {"); _builder_1.newLine(); _builder_1.append(" "); diff --git a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug456883Test.java b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug456883Test.java index 7dde3c3348c..39620ca24a2 100644 --- a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug456883Test.java +++ b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug456883Test.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2015 itemis AG (http://www.itemis.eu) and others. + * Copyright (c) 2015, 2024 itemis AG (http://www.itemis.eu) and others. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. @@ -78,35 +78,32 @@ public void test_01() { _builder_1.append("ArrayList _arrayList = new ArrayList();"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Procedure1> _function = new Procedure1>() {"); + _builder_1.append("final Procedure1> _function = (ArrayList it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public void apply(final ArrayList it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("final int finalValue = 1;"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("it.add("); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("new Object() {"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public String toString() {"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("return (\"\" + Integer.valueOf(finalValue));"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("}"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("});"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); diff --git a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug457333Test.java b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug457333Test.java index 3e381c13031..01718371b58 100644 --- a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug457333Test.java +++ b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug457333Test.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2015 itemis AG (http://www.itemis.eu) and others. + * Copyright (c) 2015, 2024 itemis AG (http://www.itemis.eu) and others. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. @@ -122,73 +122,52 @@ public void test_01() { _builder_1.newLine(); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public void apply(final String project) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Consumer _function = new Consumer() {"); + _builder_1.append("final Consumer _function = (String sourceSet) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public void accept(final String sourceSet) {"); + _builder_1.append("final XtendPlugin.Action _function_1 = (Object it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final XtendPlugin.Action _function = new XtendPlugin.Action() {"); + _builder_1.append("final Function0 _function_2 = () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public void exec(final Object it) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function0 _function = new Function0() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public Character apply() {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return Character.valueOf(sourceSet.charAt(0));"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Pair> _mappedTo = Pair.>of(\"classpath\", _function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function0 _function_1 = new Function0() {"); + _builder_1.append(" "); + _builder_1.append("Pair> _mappedTo = Pair.>of(\"classpath\", _function_2);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public Character apply() {"); + _builder_1.append(" "); + _builder_1.append("final Function0 _function_3 = () -> {"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("return Character.valueOf(sourceSet.charAt(0));"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Pair> _mappedTo_1 = Pair.>of(\"bootClasspath\", _function_1);"); + _builder_1.append(" "); + _builder_1.append("Pair> _mappedTo_1 = Pair.>of(\"bootClasspath\", _function_3);"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("XtendPlugin.conventionMapping(it, "); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Collections.>unmodifiableMap(CollectionLiterals.>newHashMap(_mappedTo, _mappedTo_1)));"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("Collections.>unmodifiableMap(CollectionLiterals.>newHashMap(_mappedTo, _mappedTo_1)));"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("XtendPlugin.this.create(\"\", Object.class, _function);"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("this.create(\"\", Object.class, _function_1);"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); diff --git a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug457346Test.java b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug457346Test.java index 2f7fab44951..0885f2d0118 100644 --- a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug457346Test.java +++ b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug457346Test.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2015, 2016 itemis AG (http://www.itemis.eu) and others. + * Copyright (c) 2015, 2024 itemis AG (http://www.itemis.eu) and others. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. @@ -56,32 +56,20 @@ public void test_01() { _builder_1.append("public List m() {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function _function = new Function() {"); + _builder_1.append("final Function _function = (String s) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Integer apply(final String s) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return Integer.valueOf(s.length());"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function _function_1 = new Function() {"); + _builder_1.append("final Function _function_1 = (String it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public String apply(final String it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return null;"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -151,32 +139,20 @@ public void test_02() { _builder_1.append("public void m(final C.Sortable sortMe) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function _function = new Function() {"); + _builder_1.append("final Function _function = (String s) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Integer apply(final String s) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return Integer.valueOf(s.length());"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function _function_1 = new Function() {"); + _builder_1.append("final Function _function_1 = (String it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public String apply(final String it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return null;"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -301,32 +277,20 @@ public void test_03() { _builder_1.append("public void m(final C.Sortable sortMe) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final C.ToIntFunction _function = new C.ToIntFunction() {"); + _builder_1.append("final C.ToIntFunction _function = (String s) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public int apply(final String s) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return s.length();"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function1 _function_1 = new Function1() {"); + _builder_1.append("final Function1 _function_1 = (String s) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public String apply(final String s) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return s;"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -451,32 +415,20 @@ public void test_04() { _builder_1.append("public void m(final C.Sortable sortMe) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final C.ToIntFunction _function = new C.ToIntFunction() {"); + _builder_1.append("final C.ToIntFunction _function = (String s) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public int apply(final String s) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return s.length();"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function1 _function_1 = new Function1() {"); + _builder_1.append("final Function1 _function_1 = (String it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public String apply(final String it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return it.toUpperCase();"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -601,32 +553,20 @@ public void test_05() { _builder_1.append("public void m(final C.Sortable sortMe) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final C.ToIntFunction _function = new C.ToIntFunction() {"); + _builder_1.append("final C.ToIntFunction _function = (String s) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public int apply(final String s) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return s.length();"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function1 _function_1 = new Function1() {"); + _builder_1.append("final Function1 _function_1 = (String it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public String apply(final String it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return it;"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -761,32 +701,20 @@ public void test_06() { _builder_1.append("public C.MyComparator m() {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final C.ToIntFunction _function = new C.ToIntFunction() {"); + _builder_1.append("final C.ToIntFunction _function = (String s) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public int apply(final String s) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return s.length();"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final C.Function _function_1 = new C.Function() {"); + _builder_1.append("final C.Function _function_1 = (String it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public String apply(final String it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return it;"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); diff --git a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug457350Test.java b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug457350Test.java index 642d1c1a5fc..f629546d3df 100644 --- a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug457350Test.java +++ b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug457350Test.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2015 itemis AG (http://www.itemis.eu) and others. + * Copyright (c) 2015, 2024 itemis AG (http://www.itemis.eu) and others. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. @@ -68,16 +68,22 @@ public void testBug457350_01() { _builder_1.append("final Runnable _self = this;"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public void run() {"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("new Runnable() {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public void run() {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("_self.run();"); + _builder_1.append("Runnable.super.run();"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("this.run();"); @@ -154,49 +160,49 @@ public void testBug457350_02() { _builder_1.append("public void test() {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Procedure1 _function = new Procedure1() {"); + _builder_1.append("final Procedure1 _function = (Object it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public void apply(final Object it) {"); + _builder_1.append("final Runnable _function_1 = new Runnable() {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Runnable _function = new Runnable() {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("final Runnable _self = this;"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public void run() {"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("new Runnable() {"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public void run() {"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_self.run();"); + _builder_1.append(" "); + _builder_1.append("Runnable.super.run();"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("this.run();"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("}"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("}"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Runnable r1 = _function;"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("final Runnable r1 = _function_1;"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); @@ -264,12 +270,18 @@ public void testBug457350_03() { _builder_1.append("final Runnable _this = this;"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public void run() {"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("final Runnable _function = new Runnable() {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public void run() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -367,12 +379,18 @@ public void testBug457350_04() { _builder_1.append("new __Test_1() {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public void run() {"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("final Runnable _function = new Runnable() {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public void run() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -463,49 +481,49 @@ public void testBug457350_05() { _builder_1.append("public void test() {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function1 _function = new Function1() {"); + _builder_1.append("final Function1 _function = (Object it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Runnable apply(final Object it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return new Runnable() {"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("final Runnable _this = this;"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public void run() {"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("final Runnable _function = new Runnable() {"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public void run() {"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("this.run();"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("_this.run();"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("}"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Runnable r1 = _function;"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("final Runnable r1 = _function;"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("};"); + _builder_1.append("}"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("};"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); @@ -571,28 +589,25 @@ public void testBug457350_06() { _builder_1.append("public void test() {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Runnable _function = new Runnable() {"); + _builder_1.append("final Runnable _function = () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public void run() {"); + _builder_1.append("new Runnable() {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("new Runnable() {"); + _builder_1.append("@Override"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("public void run() {"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Test.super.bar();"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("Test.super.bar();"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("};"); + _builder_1.append("}"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("};"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); diff --git a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug457539Test.java b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug457539Test.java index e5b05e62d5b..ecee3cf12c9 100644 --- a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug457539Test.java +++ b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug457539Test.java @@ -30,7 +30,7 @@ public void test_01() { _builder.append("val list = new ArrayList"); _builder.newLine(); _builder.append("\t\t"); - _builder.append("list.forEach2 ["); + _builder.append("list.forEach ["); _builder.newLine(); _builder.append("\t\t\t"); _builder.append("if (it instanceof String) list.add(it)"); @@ -41,15 +41,12 @@ public void test_01() { _builder.append("\t"); _builder.append("}"); _builder.newLine(); - _builder.append("\t"); - _builder.append("def void forEach2(Iterable it, (T)=>void f) {}"); - _builder.newLine(); _builder.append("}"); _builder.newLine(); StringConcatenation _builder_1 = new StringConcatenation(); _builder_1.append("import java.util.ArrayList;"); _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;"); + _builder_1.append("import java.util.function.Consumer;"); _builder_1.newLine(); _builder_1.newLine(); _builder_1.append("@SuppressWarnings(\"all\")"); @@ -63,19 +60,13 @@ public void test_01() { _builder_1.append("final ArrayList list = new ArrayList();"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Procedure1 _function = new Procedure1() {"); + _builder_1.append("final Consumer _function = (Object it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public void apply(final Object it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("if ((it instanceof String)) {"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("list.add(it);"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("list.add(it);"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("}"); @@ -84,14 +75,7 @@ public void test_01() { _builder_1.append("};"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("this.forEach2(list, _function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void forEach2(final Iterable it, final Procedure1 f) {"); + _builder_1.append("list.forEach(_function);"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("}"); @@ -110,10 +94,10 @@ public void test_02() { _builder.append("def m()\t{"); _builder.newLine(); _builder.append("\t\t"); - _builder.append("val list = newIterable"); + _builder.append("val list = newArrayList"); _builder.newLine(); _builder.append("\t\t"); - _builder.append("list.forEach2 ["); + _builder.append("list.forEach ["); _builder.newLine(); _builder.append("\t\t\t"); _builder.append("if (it instanceof String) list.add(it)"); @@ -124,72 +108,34 @@ public void test_02() { _builder.append("\t"); _builder.append("}"); _builder.newLine(); - _builder.append("\t"); - _builder.append("def static MyIterable newIterable(T... initial) {}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("interface MyIterable extends Iterable {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("def void forEach2((T)=>void f)"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("def void add(T t)"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("def T get()"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); _builder.append("}"); _builder.newLine(); StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public interface MyIterable extends Iterable {"); + _builder_1.append("import java.util.ArrayList;"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("void forEach2(final Procedure1 f);"); + _builder_1.append("import java.util.function.Consumer;"); _builder_1.newLine(); + _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("void add(final T t);"); _builder_1.newLine(); + _builder_1.append("@SuppressWarnings(\"all\")"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("T get();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); + _builder_1.append("public class C {"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("public void m() {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final C.MyIterable list = C.newIterable();"); + _builder_1.append("final ArrayList list = CollectionLiterals.newArrayList();"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Procedure1 _function = new Procedure1() {"); + _builder_1.append("final Consumer _function = (Object it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public void apply(final Object it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("if ((it instanceof String)) {"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("list.add(it);"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("list.add(it);"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("}"); @@ -198,17 +144,7 @@ public void test_02() { _builder_1.append("};"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("list.forEach2(_function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public static C.MyIterable newIterable(final T... initial) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return null;"); + _builder_1.append("list.forEach(_function);"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("}"); @@ -230,9 +166,7 @@ public void test_03() { _builder.append("val list = newIterable"); _builder.newLine(); _builder.append("\t\t"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("list.forEach2 ["); + _builder.append("list.forEach ["); _builder.newLine(); _builder.append("\t\t"); _builder.append("]"); @@ -246,22 +180,13 @@ public void test_03() { _builder.append("\t"); _builder.append("interface MyIterable extends Iterable {"); _builder.newLine(); - _builder.append("\t\t"); - _builder.append("def void forEach2((T)=>void f)"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("def void add(T t)"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("def T get()"); - _builder.newLine(); _builder.append("\t"); _builder.append("}"); _builder.newLine(); _builder.append("}"); _builder.newLine(); StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;"); + _builder_1.append("import java.util.function.Consumer;"); _builder_1.newLine(); _builder_1.newLine(); _builder_1.append("@SuppressWarnings(\"all\")"); @@ -271,17 +196,6 @@ public void test_03() { _builder_1.append(" "); _builder_1.append("public interface MyIterable extends Iterable {"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("void forEach2(final Procedure1 f);"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("void add(final T t);"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("T get();"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("}"); _builder_1.newLine(); @@ -293,19 +207,13 @@ public void test_03() { _builder_1.append("final C.MyIterable list = C.newIterable();"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Procedure1 _function = new Procedure1() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void apply(final CharSequence it) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("final Consumer _function = (CharSequence it) -> {"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("list.forEach2(_function);"); + _builder_1.append("list.forEach(_function);"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("}"); @@ -340,7 +248,7 @@ public void test_04() { _builder.append("list.add(\'\')"); _builder.newLine(); _builder.append("\t\t"); - _builder.append("list.forEach2 ["); + _builder.append("list.forEach ["); _builder.newLine(); _builder.append("\t\t"); _builder.append("]"); @@ -355,9 +263,6 @@ public void test_04() { _builder.append("interface MyIterable extends Iterable {"); _builder.newLine(); _builder.append("\t\t"); - _builder.append("def void forEach2((T)=>void f)"); - _builder.newLine(); - _builder.append("\t\t"); _builder.append("def void add(T t)"); _builder.newLine(); _builder.append("\t\t"); @@ -369,7 +274,7 @@ public void test_04() { _builder.append("}"); _builder.newLine(); StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;"); + _builder_1.append("import java.util.function.Consumer;"); _builder_1.newLine(); _builder_1.newLine(); _builder_1.append("@SuppressWarnings(\"all\")"); @@ -380,10 +285,6 @@ public void test_04() { _builder_1.append("public interface MyIterable extends Iterable {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("void forEach2(final Procedure1 f);"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("void add(final T t);"); _builder_1.newLine(); _builder_1.newLine(); @@ -404,19 +305,13 @@ public void test_04() { _builder_1.append("list.add(\"\");"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Procedure1 _function = new Procedure1() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void apply(final String it) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("final Consumer _function = (String it) -> {"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("list.forEach2(_function);"); + _builder_1.append("list.forEach(_function);"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("}"); @@ -454,7 +349,7 @@ public void test_05() { _builder.append("list.add(\'\')"); _builder.newLine(); _builder.append("\t\t"); - _builder.append("list.forEach2 ["); + _builder.append("list.forEach ["); _builder.newLine(); _builder.append("\t\t"); _builder.append("]"); @@ -469,9 +364,6 @@ public void test_05() { _builder.append("interface MyIterable extends Iterable {"); _builder.newLine(); _builder.append("\t\t"); - _builder.append("def void forEach2((T)=>void f)"); - _builder.newLine(); - _builder.append("\t\t"); _builder.append("def void add(T t)"); _builder.newLine(); _builder.append("\t\t"); @@ -483,7 +375,7 @@ public void test_05() { _builder.append("}"); _builder.newLine(); StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;"); + _builder_1.append("import java.util.function.Consumer;"); _builder_1.newLine(); _builder_1.newLine(); _builder_1.append("@SuppressWarnings(\"all\")"); @@ -494,10 +386,6 @@ public void test_05() { _builder_1.append("public interface MyIterable extends Iterable {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("void forEach2(final Procedure1 f);"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("void add(final T t);"); _builder_1.newLine(); _builder_1.newLine(); @@ -521,19 +409,13 @@ public void test_05() { _builder_1.append("list.add(\"\");"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Procedure1 _function = new Procedure1() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void apply(final CharSequence it) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("final Consumer _function = (CharSequence it) -> {"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("list.forEach2(_function);"); + _builder_1.append("list.forEach(_function);"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("}"); @@ -568,7 +450,7 @@ public void test_06() { _builder.append("list.get.toString"); _builder.newLine(); _builder.append("\t\t"); - _builder.append("list.forEach2 ["); + _builder.append("list.forEach ["); _builder.newLine(); _builder.append("\t\t\t"); _builder.append("if (it instanceof String) list.add(it)"); @@ -586,9 +468,6 @@ public void test_06() { _builder.append("interface MyIterable extends Iterable {"); _builder.newLine(); _builder.append("\t\t"); - _builder.append("def void forEach2((T)=>void f)"); - _builder.newLine(); - _builder.append("\t\t"); _builder.append("def void add(T t)"); _builder.newLine(); _builder.append("\t\t"); @@ -600,7 +479,7 @@ public void test_06() { _builder.append("}"); _builder.newLine(); StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;"); + _builder_1.append("import java.util.function.Consumer;"); _builder_1.newLine(); _builder_1.newLine(); _builder_1.append("@SuppressWarnings(\"all\")"); @@ -611,10 +490,6 @@ public void test_06() { _builder_1.append("public interface MyIterable extends Iterable {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("void forEach2(final Procedure1 f);"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("void add(final T t);"); _builder_1.newLine(); _builder_1.newLine(); @@ -635,19 +510,13 @@ public void test_06() { _builder_1.append("list.get().toString();"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Procedure1 _function = new Procedure1() {"); + _builder_1.append("final Consumer _function = (CharSequence it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public void apply(final CharSequence it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("if ((it instanceof String)) {"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("list.add(it);"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("list.add(it);"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("}"); @@ -656,7 +525,7 @@ public void test_06() { _builder_1.append("};"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("list.forEach2(_function);"); + _builder_1.append("list.forEach(_function);"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("}"); @@ -688,7 +557,7 @@ public void test_07() { _builder.append("val list = newIterable"); _builder.newLine(); _builder.append("\t\t"); - _builder.append("list.forEach2 ["); + _builder.append("list.forEach ["); _builder.newLine(); _builder.append("\t\t\t"); _builder.append("if (it instanceof String) list.add(it)"); @@ -706,9 +575,6 @@ public void test_07() { _builder.append("interface MyIterable extends Iterable {"); _builder.newLine(); _builder.append("\t\t"); - _builder.append("def void forEach2((T)=>void f)"); - _builder.newLine(); - _builder.append("\t\t"); _builder.append("def void add(T t)"); _builder.newLine(); _builder.append("\t\t"); @@ -720,7 +586,7 @@ public void test_07() { _builder.append("}"); _builder.newLine(); StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;"); + _builder_1.append("import java.util.function.Consumer;"); _builder_1.newLine(); _builder_1.newLine(); _builder_1.append("@SuppressWarnings(\"all\")"); @@ -731,10 +597,6 @@ public void test_07() { _builder_1.append("public interface MyIterable extends Iterable {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("void forEach2(final Procedure1 f);"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("void add(final T t);"); _builder_1.newLine(); _builder_1.newLine(); @@ -752,19 +614,13 @@ public void test_07() { _builder_1.append("final C.MyIterable list = C.newIterable();"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Procedure1 _function = new Procedure1() {"); + _builder_1.append("final Consumer _function = (CharSequence it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public void apply(final CharSequence it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("if ((it instanceof String)) {"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("list.add(it);"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("list.add(it);"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("}"); @@ -773,7 +629,7 @@ public void test_07() { _builder_1.append("};"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("list.forEach2(_function);"); + _builder_1.append("list.forEach(_function);"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("}"); @@ -805,7 +661,7 @@ public void test_08() { _builder.append("val list = newIterable"); _builder.newLine(); _builder.append("\t\t"); - _builder.append("list.forEach2 [ CharSequence it |"); + _builder.append("list.forEach [ CharSequence it |"); _builder.newLine(); _builder.append("\t\t\t"); _builder.append("if (it instanceof String) list.add(it)"); @@ -823,9 +679,6 @@ public void test_08() { _builder.append("interface MyIterable extends Iterable {"); _builder.newLine(); _builder.append("\t\t"); - _builder.append("def void forEach2((T)=>void f)"); - _builder.newLine(); - _builder.append("\t\t"); _builder.append("def void add(T t)"); _builder.newLine(); _builder.append("\t\t"); @@ -837,7 +690,7 @@ public void test_08() { _builder.append("}"); _builder.newLine(); StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;"); + _builder_1.append("import java.util.function.Consumer;"); _builder_1.newLine(); _builder_1.newLine(); _builder_1.append("@SuppressWarnings(\"all\")"); @@ -848,10 +701,6 @@ public void test_08() { _builder_1.append("public interface MyIterable extends Iterable {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("void forEach2(final Procedure1 f);"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("void add(final T t);"); _builder_1.newLine(); _builder_1.newLine(); @@ -869,19 +718,13 @@ public void test_08() { _builder_1.append("final C.MyIterable list = C.newIterable();"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Procedure1 _function = new Procedure1() {"); + _builder_1.append("final Consumer _function = (CharSequence it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public void apply(final CharSequence it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("if ((it instanceof String)) {"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("list.add(it);"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("list.add(it);"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("}"); @@ -890,7 +733,7 @@ public void test_08() { _builder_1.append("};"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("list.forEach2(_function);"); + _builder_1.append("list.forEach(_function);"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("}"); @@ -913,7 +756,7 @@ public void test_08() { @Test public void test_09() { StringConcatenation _builder = new StringConcatenation(); - _builder.append("import org.eclipse.xtend.core.tests.compiler.StringBuilderLike"); + _builder.append("import org.eclipse.xtend.core.tests.java8.compiler.StringBuilderLike"); _builder.newLine(); _builder.append("class C {"); _builder.newLine(); @@ -955,7 +798,7 @@ public void test_09() { StringConcatenation _builder_1 = new StringConcatenation(); _builder_1.append("import java.io.Serializable;"); _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtend.core.tests.compiler.StringBuilderLike;"); + _builder_1.append("import org.eclipse.xtend.core.tests.java8.compiler.StringBuilderLike;"); _builder_1.newLine(); _builder_1.append("import org.eclipse.xtext.xbase.lib.InputOutput;"); _builder_1.newLine(); @@ -983,22 +826,16 @@ public void test_09() { _builder_1.append("StringBuilderLike _stringBuilderLike = new StringBuilderLike();"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Procedure1 _function = new Procedure1() {"); + _builder_1.append("final Procedure1 _function = (StringBuilderLike it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public void apply(final StringBuilderLike it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("Long _long = new Long(0);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("C.this.m(it, _long);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("InputOutput.println(Integer.valueOf(it.length()));"); + _builder_1.append(" "); + _builder_1.append("this.m(it, _long);"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("InputOutput.println(Integer.valueOf(it.length()));"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); @@ -1081,13 +918,7 @@ public void test_10() { _builder_1.append("public void m(final C.MyIterable list) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Procedure1 _function = new Procedure1() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void apply(final Object it) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("final Procedure1 _function = (Object it) -> {"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); diff --git a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug459920Test.java b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug459920Test.java index 04c7490273b..2529be9de68 100644 --- a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug459920Test.java +++ b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug459920Test.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2015, 2016 itemis AG (http://www.itemis.eu) and others. + * Copyright (c) 2015, 2024 itemis AG (http://www.itemis.eu) and others. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. @@ -104,17 +104,11 @@ public void regression_01() { _builder_1.append("if ((param == null)) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final CancelIndicator _function = new CancelIndicator() {"); + _builder_1.append("final CancelIndicator _function = () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public boolean isCanceled() {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return true;"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); diff --git a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug460691Test.java b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug460691Test.java index fa708132a81..1d38bcb9bff 100644 --- a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug460691Test.java +++ b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug460691Test.java @@ -41,6 +41,9 @@ public void test_01() { _builder_1.append("public class C implements Comparator {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public int compare(final String s1, final String s2) {"); _builder_1.newLine(); _builder_1.append(" "); diff --git a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug461568Test.java b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug461568Test.java index 7aa868308c3..77e8adbe325 100644 --- a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug461568Test.java +++ b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug461568Test.java @@ -70,17 +70,11 @@ public void test_01() { _builder_1.append("public Object m2() {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Procedure1 _function = new Procedure1() {"); + _builder_1.append("final Procedure1 _function = (String s) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public void apply(final String s) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("s.getBytes();"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -149,17 +143,11 @@ public void test_02() { _builder_1.append("public Object m2() {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function1 _function = new Function1() {"); + _builder_1.append("final Function1 _function = (String s) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Object apply(final String s) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return s.getBytes();"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -228,17 +216,11 @@ public void test_03() { _builder_1.append("public Object m2() {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Procedure1 _function = new Procedure1() {"); + _builder_1.append("final Procedure1 _function = (String it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public void apply(final String it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("it.getBytes();"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); diff --git a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug461923Test.java b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug461923Test.java index cfb3101e545..04ff65440e2 100644 --- a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug461923Test.java +++ b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug461923Test.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2015, 2016 itemis AG (http://www.itemis.eu) and others. + * Copyright (c) 2015, 2024 itemis AG (http://www.itemis.eu) and others. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. @@ -57,17 +57,11 @@ public void test_01() { _builder_1.append("public static ImmutableList m(final List list, final T value) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function1 _function = new Function1() {"); + _builder_1.append("final Function1 _function = (T it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Boolean apply(final T it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return Boolean.valueOf((!Objects.equals(it, value)));"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -123,17 +117,11 @@ public void test_02() { _builder_1.append("public static ImmutableList m(final List list, final T value) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function1 _function = new Function1() {"); + _builder_1.append("final Function1 _function = (T it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Boolean apply(final T it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return Boolean.valueOf((!Objects.equals(it, value)));"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -189,17 +177,11 @@ public void test_03() { _builder_1.append("public static ImmutableList m(final List list, final T value) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function1 _function = new Function1() {"); + _builder_1.append("final Function1 _function = (Object it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Boolean apply(final Object it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return Boolean.valueOf((!Objects.equals(it, value)));"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -298,17 +280,11 @@ public void test_05() { _builder_1.append("public static ImmutableList m(final List list) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function1 _function = new Function1() {"); + _builder_1.append("final Function1 _function = (T it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Boolean apply(final T it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return Boolean.valueOf(true);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -362,17 +338,11 @@ public void test_06() { _builder_1.append("public static ImmutableList m(final List list) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function1 _function = new Function1() {"); + _builder_1.append("final Function1 _function = (T it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Boolean apply(final T it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return Boolean.valueOf(false);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -426,32 +396,20 @@ public void test_07() { _builder_1.append("public static ImmutableList m(final List list) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function1 _function = new Function1() {"); + _builder_1.append("final Function1 _function = (T it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Boolean apply(final T it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return Boolean.valueOf(true);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function1 _function_1 = new Function1() {"); + _builder_1.append("final Function1 _function_1 = (T it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Boolean apply(final T it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return Boolean.valueOf(false);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -507,17 +465,11 @@ public void test_08() { _builder_1.append("public static ImmutableList m(final T[] arr, final T value) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function1 _function = new Function1() {"); + _builder_1.append("final Function1 _function = (T it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Boolean apply(final T it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return Boolean.valueOf((!Objects.equals(it, value)));"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); diff --git a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug462845Test.java b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug462845Test.java index 79c14d18af0..e1336c1a56a 100644 --- a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug462845Test.java +++ b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug462845Test.java @@ -53,9 +53,6 @@ public void test_01() { _builder.append("\t\t\t"); _builder.append("}"); _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("override remove() {}"); - _builder.newLine(); _builder.append("\t\t"); _builder.append("}"); _builder.newLine(); @@ -86,17 +83,11 @@ public void test_01() { _builder_1.newLine(); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Iterable _function = new Iterable() {"); + _builder_1.append("final Iterable _function = () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Iterator iterator() {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return null;"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -116,6 +107,9 @@ public void test_01() { _builder_1.append("}"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public boolean hasNext() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -126,6 +120,9 @@ public void test_01() { _builder_1.newLine(); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public String next() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -134,13 +131,6 @@ public void test_01() { _builder_1.append(" "); _builder_1.append("}"); _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void remove() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -189,9 +179,6 @@ public void test_02() { _builder.append("\t\t\t"); _builder.append("}"); _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("override remove() {}"); - _builder.newLine(); _builder.append("\t\t"); _builder.append("}"); _builder.newLine(); @@ -228,17 +215,11 @@ public void test_02() { _builder_1.append("{"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Iterable _function = new Iterable() {"); + _builder_1.append("final Iterable _function = () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Iterator iterator() {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return null;"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -258,6 +239,9 @@ public void test_02() { _builder_1.append("}"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public boolean hasNext() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -268,6 +252,9 @@ public void test_02() { _builder_1.newLine(); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public String next() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -276,13 +263,6 @@ public void test_02() { _builder_1.append(" "); _builder_1.append("}"); _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void remove() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -376,17 +356,11 @@ public void test_03() { _builder_1.append("{"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Iterable _function = new Iterable() {"); + _builder_1.append("final Iterable _function = () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Iterator iterator() {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return null;"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -406,6 +380,9 @@ public void test_03() { _builder_1.append("}"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public boolean hasNext() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -416,6 +393,9 @@ public void test_03() { _builder_1.newLine(); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public String next() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -426,6 +406,9 @@ public void test_03() { _builder_1.newLine(); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public void remove() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -518,17 +501,11 @@ public void test_04() { _builder_1.newLine(); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Iterable _function = new Iterable() {"); + _builder_1.append("final Iterable _function = () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Iterator iterator() {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return null;"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -548,6 +525,9 @@ public void test_04() { _builder_1.append("}"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public boolean hasNext() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -558,6 +538,9 @@ public void test_04() { _builder_1.newLine(); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public String next() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -568,6 +551,9 @@ public void test_04() { _builder_1.newLine(); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public void remove() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -646,6 +632,9 @@ public void test_05() { _builder_1.append("private final Iterator iterator = new Function0>() {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public Iterator apply() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -665,17 +654,11 @@ public void test_05() { _builder_1.append("{"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Iterable _function = new Iterable() {"); + _builder_1.append("final Iterable _function = () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Iterator iterator() {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return null;"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -695,6 +678,9 @@ public void test_05() { _builder_1.append("}"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public boolean hasNext() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -705,6 +691,9 @@ public void test_05() { _builder_1.newLine(); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public String next() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -715,6 +704,9 @@ public void test_05() { _builder_1.newLine(); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public void remove() {"); _builder_1.newLine(); _builder_1.append(" "); diff --git a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug464264Test.java b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug464264Test.java index 29bcdac92b0..0f668e50583 100644 --- a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug464264Test.java +++ b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug464264Test.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2015, 2016 itemis AG (http://www.itemis.eu) and others. + * Copyright (c) 2015, 2024 itemis AG (http://www.itemis.eu) and others. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. @@ -83,17 +83,11 @@ public void test_01() { _builder_1.append("List _strings = i.getStrings();"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function1 _function = new Function1() {"); + _builder_1.append("final Function1 _function = (CharSequence it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public String apply(final CharSequence it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return ((String) it);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -104,17 +98,11 @@ public void test_01() { _builder_1.append("Iterables.addAll(_strings, _map);"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function1 _function_1 = new Function1() {"); + _builder_1.append("final Function1 _function_1 = (CharSequence it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public CharSequence apply(final CharSequence it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return it;"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -171,17 +159,11 @@ public void test_02() { _builder_1.append("public boolean m(final List res, final Iterable obj) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function1 _function = new Function1() {"); + _builder_1.append("final Function1 _function = (Object it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public String apply(final Object it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return \"\";"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); diff --git a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug465058Test.java b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug465058Test.java index 1538af92eb7..41968fb1f90 100644 --- a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug465058Test.java +++ b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug465058Test.java @@ -66,16 +66,10 @@ public void test_01() { _builder_1.append("public void bar() {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function0 _function = new Function0() {"); + _builder_1.append("final Function0 _function = () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Object apply() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return IterableExtensions.head(Bug.this.list);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("return IterableExtensions.head(this.list);"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); @@ -139,16 +133,10 @@ public void test_02() { _builder_1.append("public void bar() {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function0 _function = new Function0() {"); + _builder_1.append("final Function0 _function = () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Object apply() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return IterableExtensions.head(Bug.this.list);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("return IterableExtensions.head(this.list);"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); @@ -214,16 +202,10 @@ public void test_03() { _builder_1.append("public void bar() {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function0 _function = new Function0() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public Object apply() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return IterableExtensions.head(Bug.this.list);"); + _builder_1.append("final Function0 _function = () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("return IterableExtensions.head(this.list);"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); @@ -287,16 +269,10 @@ public void test_04() { _builder_1.append("public void bar() {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function0 _function = new Function0() {"); + _builder_1.append("final Function0 _function = () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Object apply() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return IterableExtensions.head(Bug.this.list);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("return IterableExtensions.head(this.list);"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); @@ -363,16 +339,10 @@ public void test_05() { _builder_1.append("public void bar() {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function0 _function = new Function0() {"); + _builder_1.append("final Function0 _function = () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Object apply() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return Bug.this.head2(Bug.this.list);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("return this.head2(this.list);"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); @@ -449,16 +419,10 @@ public void test_06() { _builder_1.append("public void bar() {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function0 _function = new Function0() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public Object apply() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return Bug.this.head2(Bug.this.list);"); + _builder_1.append("final Function0 _function = () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("return this.head2(this.list);"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); @@ -537,16 +501,10 @@ public void test_07() { _builder_1.append("public void bar() {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function0 _function = new Function0() {"); + _builder_1.append("final Function0 _function = () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Object apply() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return Bug.this.head2(((String[])Conversions.unwrapArray(Bug.this.list, String.class)));"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("return this.head2(((String[])Conversions.unwrapArray(this.list, String.class)));"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); @@ -610,16 +568,10 @@ public void test_08() { _builder_1.append("public void bar() {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function0 _function = new Function0() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public Object apply() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return Bug.this.head2(new String[] { \"one\", \"two\", \"three\" });"); + _builder_1.append("final Function0 _function = () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("return this.head2(new String[] { \"one\", \"two\", \"three\" });"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); @@ -696,16 +648,10 @@ public void test_09() { _builder_1.append("public void bar() {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function0 _function = new Function0() {"); + _builder_1.append("final Function0 _function = () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Object apply() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return Bug.this.head2(Bug.this.list);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("return this.head2(this.list);"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); @@ -782,16 +728,10 @@ public void test_10() { _builder_1.append("public void bar() {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function0 _function = new Function0() {"); + _builder_1.append("final Function0 _function = () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Object apply() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return Bug.this.head2(Bug.this.list);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("return this.head2(this.list);"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); @@ -868,16 +808,10 @@ public void test_11() { _builder_1.append("public void bar() {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function0 _function = new Function0() {"); + _builder_1.append("final Function0 _function = () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Object apply() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return Bug.this.head2(Bug.this.list);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("return this.head2(this.list);"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); @@ -956,16 +890,10 @@ public void test_12() { _builder_1.append("public void bar() {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function0 _function = new Function0() {"); + _builder_1.append("final Function0 _function = () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Object apply() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return Bug.this.head2(((String[])Conversions.unwrapArray(Bug.this.list, String.class)));"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("return this.head2(((String[])Conversions.unwrapArray(this.list, String.class)));"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); @@ -1029,16 +957,10 @@ public void test_13() { _builder_1.append("public void bar() {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function0 _function = new Function0() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public Object apply() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return Bug.this.head2(new String[] { \"one\", \"two\", \"three\" });"); + _builder_1.append("final Function0 _function = () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("return this.head2(new String[] { \"one\", \"two\", \"three\" });"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); @@ -1115,16 +1037,10 @@ public void test_14() { _builder_1.append("public void bar() {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function0 _function = new Function0() {"); + _builder_1.append("final Function0 _function = () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Object apply() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return Bug.this.head2(Bug.this.list);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("return this.head2(this.list);"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); @@ -1197,16 +1113,10 @@ public void test_15() { _builder_1.append("public void bar() {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function0 _function = new Function0() {"); + _builder_1.append("final Function0 _function = () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Object apply() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return Bug.this.head2(Bug.this.list);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("return this.head2(this.list);"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); @@ -1279,16 +1189,10 @@ public void test_16() { _builder_1.append("{"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function0 _function = new Function0() {"); + _builder_1.append("final Function0 _function = () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Object apply() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return Bug.this.head2(Collections.unmodifiableList(CollectionLiterals.newArrayList(\"one\", \"two\", \"three\")));"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("return this.head2(Collections.unmodifiableList(CollectionLiterals.newArrayList(\"one\", \"two\", \"three\")));"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); @@ -1363,16 +1267,10 @@ public void test_17() { _builder_1.append("{"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function0 _function = new Function0() {"); + _builder_1.append("final Function0 _function = () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Object apply() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return Bug.this.head2(new String[] { \"one\", \"two\", \"three\" });"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("return this.head2(new String[] { \"one\", \"two\", \"three\" });"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); @@ -1445,16 +1343,10 @@ public void test_18() { _builder_1.append("public void bar() {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function0 _function = new Function0() {"); + _builder_1.append("final Function0 _function = () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Object apply() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return ((Number)Bug.this.head2(new Number[] { Integer.valueOf(1), Double.valueOf(1.0) }));"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("return ((Number)this.head2(new Number[] { Integer.valueOf(1), Double.valueOf(1.0) }));"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); @@ -1518,16 +1410,10 @@ public void test_19() { _builder_1.append("public void bar() {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function0 _function = new Function0() {"); + _builder_1.append("final Function0 _function = () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Object apply() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return Bug.this.head2(new Comparable[] { \"\", \"\" });"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("return this.head2(new Comparable[] { \"\", \"\" });"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); @@ -1591,16 +1477,10 @@ public void test_20() { _builder_1.append("public void bar() {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function0 _function = new Function0() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public Object apply() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return ((Number)Bug.this.head2(new Comparable[] { ((Integer) null), ((Double) null) }));"); + _builder_1.append("final Function0 _function = () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("return ((Number)this.head2(new Comparable[] { ((Integer) null), ((Double) null) }));"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); @@ -1664,16 +1544,10 @@ public void test_21() { _builder_1.append("public void bar() {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function0 _function = new Function0() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public Object apply() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return ((Number)Bug.this.head2(new Comparable[] { Integer.valueOf(1), Double.valueOf(1.0) }));"); + _builder_1.append("final Function0 _function = () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("return ((Number)this.head2(new Comparable[] { Integer.valueOf(1), Double.valueOf(1.0) }));"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); diff --git a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug470768Test.java b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug470768Test.java index dbc1d11b32f..53e23a1dca6 100644 --- a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug470768Test.java +++ b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug470768Test.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2015, 2016 itemis AG (http://www.itemis.eu) and others. + * Copyright (c) 2015, 2024 itemis AG (http://www.itemis.eu) and others. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. @@ -86,6 +86,9 @@ public void test_01() { _builder_1.append("public static class CustomItr implements Iterable {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public Iterator iterator() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -213,6 +216,9 @@ public void test_02() { _builder_1.append("public static class CustomItr implements Iterable {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public Iterator iterator() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -352,6 +358,9 @@ public void test_03() { _builder_1.append("public static class CustomItr implements Iterable {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public Iterator iterator() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -489,6 +498,9 @@ public void test_04() { _builder_1.append("public static class CustomItr implements Iterable {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public Iterator iterator() {"); _builder_1.newLine(); _builder_1.append(" "); diff --git a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug472602Test.java b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug472602Test.java index e39f36daa76..d419924e95b 100644 --- a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug472602Test.java +++ b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBug472602Test.java @@ -550,6 +550,9 @@ public void test_06() { _builder_1.newLine(); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public B get() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -659,6 +662,9 @@ public void test_07() { _builder_1.append("_xblockexpression = new C() {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public B get() {"); _builder_1.newLine(); _builder_1.append(" "); diff --git a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBugDispatchWithOverrideTest.java b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBugDispatchWithOverrideTest.java index 4942ade4cdf..0146d6e5264 100644 --- a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBugDispatchWithOverrideTest.java +++ b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBugDispatchWithOverrideTest.java @@ -11,8 +11,6 @@ import org.eclipse.xtend.core.tests.SingletonGeneratorConfigRuntimeInjectorProvider; import org.eclipse.xtend2.lib.StringConcatenation; import org.eclipse.xtext.testing.InjectWith; -import org.eclipse.xtext.util.JavaVersion; -import org.eclipse.xtext.xbase.compiler.GeneratorConfig; import org.junit.Test; /** @@ -25,8 +23,6 @@ public class CompilerBugDispatchWithOverrideTest extends AbstractXtendCompilerTest { @Test public void testDispatchWithOverrideJava6HasAnnotation() { - final GeneratorConfig generatorConfig = this.generatorConfigProvider.get(null); - generatorConfig.setJavaSourceVersion(JavaVersion.JAVA6); StringConcatenation _builder = new StringConcatenation(); _builder.append("class Something extends AbstractSomething {"); _builder.newLine(); @@ -110,8 +106,6 @@ public void testDispatchWithOverrideJava6HasAnnotation() { @Test public void testDispatchWithOverrideJava5HasNoAnnotation() { - final GeneratorConfig generatorConfig = this.generatorConfigProvider.get(null); - generatorConfig.setJavaSourceVersion(JavaVersion.JAVA5); StringConcatenation _builder = new StringConcatenation(); _builder.append("class Something extends AbstractSomething {"); _builder.newLine(); @@ -140,6 +134,9 @@ public void testDispatchWithOverrideJava5HasNoAnnotation() { _builder_1.append("public class Something extends AbstractSomething {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("protected void _m(final String x) {"); _builder_1.newLine(); _builder_1.append(" "); @@ -147,6 +144,9 @@ public void testDispatchWithOverrideJava5HasNoAnnotation() { _builder_1.newLine(); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public void m(final Object x) {"); _builder_1.newLine(); _builder_1.append(" "); diff --git a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBugProtectedVisibilityTest.java b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBugProtectedVisibilityTest.java index 83b31bb0081..ab0a8a89c12 100644 --- a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBugProtectedVisibilityTest.java +++ b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBugProtectedVisibilityTest.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2014, 2020 itemis AG (http://www.itemis.eu) and others. + * Copyright (c) 2014, 2024 itemis AG (http://www.itemis.eu) and others. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. @@ -341,16 +341,10 @@ public void test472662_01() { _builder_1.append("protected Object doX(final Runnable r) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Runnable _function = new Runnable() {"); + _builder_1.append("final Runnable _function = () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public void run() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("B.this.c.protectedMethod();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("this.c.protectedMethod();"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); @@ -423,6 +417,9 @@ public void test472662_02() { _builder_1.append("return this.doX(new Runnable() {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public void run() {"); _builder_1.newLine(); _builder_1.append(" "); diff --git a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBugTest.java b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBugTest.java index 5a89a66a807..2914e289142 100644 --- a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBugTest.java +++ b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/CompilerBugTest.java @@ -1132,17 +1132,11 @@ public void testReturnExpressionConverted_04() { _builder_1.append("} else {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function1 _function = new Function1() {"); + _builder_1.append("final Function1 _function = (String s) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Boolean apply(final String s) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return Boolean.valueOf(true);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -2359,16 +2353,10 @@ public void testBug406416_02() { _builder_1.append("public void build(final Factory f) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Procedure1 _function = new Procedure1() {"); + _builder_1.append("final Procedure1 _function = (T it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public void apply(final T it) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Factory.this.>buildChild(f);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("this.>buildChild(f);"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); @@ -2418,17 +2406,11 @@ public void testBug406370() { _builder_1.append("public C() {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function1 _function = new Function1() {"); + _builder_1.append("final Function1 _function = (Integer it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public String apply(final Integer it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return it.toString();"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -2506,29 +2488,17 @@ public void testBug406360() { _builder_1.append("public void m(final Iterable refs, final ITreeAppendable it) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Procedure1 _function = new Procedure1() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void apply(final LoopParams it_1) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("final Procedure1 _function = (LoopParams it_1) -> {"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Procedure2 _function_1 = new Procedure2() {"); + _builder_1.append("final Procedure2 _function_1 = (JvmTypeReference it_1, ITreeAppendable app) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public void apply(final JvmTypeReference it_1, final ITreeAppendable app) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("app.trace(it_1).append(it_1.getType());"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -2825,22 +2795,16 @@ public void testBug405900_01() { _builder_1.append("{"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Procedure1 _function = new Procedure1() {"); + _builder_1.append("final Procedure1 _function = (StringBuilder it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public void apply(final StringBuilder it) {"); + _builder_1.append("List _children = this.getChildren();"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("List _children = C.this.getChildren();"); - _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("_children.add(it);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("it.append(\"\");"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("it.append(\"\");"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); @@ -3958,32 +3922,20 @@ public void testBug404051_01() { _builder_1.append("public List m(final Iterable iterable) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function1 _function = new Function1() {"); + _builder_1.append("final Function1 _function = (String it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Object apply(final String it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return null;"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function1 _function_1 = new Function1() {"); + _builder_1.append("final Function1 _function_1 = (Object it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Integer apply(final Object it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return Integer.valueOf(it.hashCode());"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -4047,32 +3999,20 @@ public void testBug404051_02() { _builder_1.append("public void m(final Iterable iterable) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function1 _function = new Function1() {"); + _builder_1.append("final Function1 _function = (String it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public String apply(final String it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return it;"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function1 _function_1 = new Function1() {"); + _builder_1.append("final Function1 _function_1 = (String it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Integer apply(final String it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return Integer.valueOf(it.hashCode());"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -4136,32 +4076,20 @@ public void testBug404051_03() { _builder_1.append("public void m(final Iterable iterable) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function1 _function = new Function1() {"); + _builder_1.append("final Function1 _function = (String it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public String apply(final String it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return it.toUpperCase();"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function1 _function_1 = new Function1() {"); + _builder_1.append("final Function1 _function_1 = (String it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Integer apply(final String it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return Integer.valueOf(it.length());"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -4221,19 +4149,16 @@ public void testBug384313() { _builder_1.append("public class MyMap extends HashMap {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public void putAll(final Map t) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Consumer> _function = new Consumer>() {"); + _builder_1.append("final Consumer> _function = (Map.Entry it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public void accept(final Map.Entry it) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("MyMap.this.put(it.getKey(), it.getValue());"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("this.put(it.getKey(), it.getValue());"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); @@ -4324,6 +4249,9 @@ public void testWeightComparable_01() { _builder_1.newLine(); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public int compareTo(final Weight w) {"); _builder_1.newLine(); _builder_1.append(" "); @@ -4490,6 +4418,9 @@ public void testWeightComparable_02() { _builder_1.newLine(); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public int compareTo(final Weight w) {"); _builder_1.newLine(); _builder_1.append(" "); @@ -4656,6 +4587,9 @@ public void testWeightComparable_03() { _builder_1.newLine(); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public int compareTo(final Weight w) {"); _builder_1.newLine(); _builder_1.append(" "); @@ -4822,6 +4756,9 @@ public void testWeightComparable_04() { _builder_1.newLine(); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public int compareTo(final Weight w) {"); _builder_1.newLine(); _builder_1.append(" "); @@ -5072,9 +5009,6 @@ public void testEarlyExitInBranch_01() { _builder.append("}"); _builder.newLine(); StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.Objects;"); - _builder_1.newLine(); - _builder_1.newLine(); _builder_1.append("@SuppressWarnings(\"all\")"); _builder_1.newLine(); _builder_1.append("public class C {"); @@ -5089,42 +5023,36 @@ public void testEarlyExitInBranch_01() { _builder_1.append("final String _switchValue = \"a\";"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("boolean _matched = false;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (Objects.equals(_switchValue, \"b\")) {"); + _builder_1.append("if (_switchValue != null) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("_matched=true;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_switchResult = \"a\";"); + _builder_1.append("switch (_switchValue) {"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append(" "); + _builder_1.append("case \"b\":"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (!_matched) {"); + _builder_1.append(" "); + _builder_1.append("_switchResult = \"a\";"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (Objects.equals(_switchValue, \"c\")) {"); + _builder_1.append(" "); + _builder_1.append("break;"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("_matched=true;"); + _builder_1.append("case \"c\":"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("if ((1 == 2)) {"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("return \"b\";"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("} else {"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("return \"c\";"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("}"); _builder_1.newLine(); _builder_1.append(" "); @@ -5185,9 +5113,6 @@ public void testEarlyExitInBranch_02() { _builder.append("}"); _builder.newLine(); StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.Objects;"); - _builder_1.newLine(); - _builder_1.newLine(); _builder_1.append("@SuppressWarnings(\"all\")"); _builder_1.newLine(); _builder_1.append("public class C {"); @@ -5202,42 +5127,36 @@ public void testEarlyExitInBranch_02() { _builder_1.append("final String _switchValue = \"a\";"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("boolean _matched = false;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (Objects.equals(_switchValue, \"b\")) {"); + _builder_1.append("if (_switchValue != null) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("_matched=true;"); + _builder_1.append("switch (_switchValue) {"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_switchResult = \"a\";"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append(" "); + _builder_1.append("case \"b\":"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (!_matched) {"); + _builder_1.append(" "); + _builder_1.append("_switchResult = \"a\";"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (Objects.equals(_switchValue, \"c\")) {"); + _builder_1.append(" "); + _builder_1.append("break;"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("_matched=true;"); + _builder_1.append("case \"c\":"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("if (b) {"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("return \"b\";"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("} else {"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("return \"c\";"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("}"); _builder_1.newLine(); _builder_1.append(" "); @@ -5802,17 +5721,11 @@ public void testBug362285_01() { _builder_1.append("public T m() {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function1 _function = new Function1() {"); + _builder_1.append("final Function1 _function = (T x) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public T apply(final T x) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return x;"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -5855,17 +5768,11 @@ public void testBug362285_02() { _builder_1.append("public T m() {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function1 _function = new Function1() {"); + _builder_1.append("final Function1 _function = (T x) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public T apply(final T x) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return x;"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -5915,34 +5822,28 @@ public void testBug380525_01() { _builder_1.append("Object _object = new Object();"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Procedure1 _function = new Procedure1() {"); + _builder_1.append("final Procedure1 _function = (Object it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public void apply(final Object it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("boolean _and = false;"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("boolean _add = L.this.add(((E) it));"); + _builder_1.append(" "); + _builder_1.append("boolean _add = this.add(((E) it));"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("if (!_add) {"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("_and = false;"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("} else {"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("boolean _remove = L.this.remove(it);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_and = _remove;"); + _builder_1.append(" "); + _builder_1.append("boolean _remove = this.remove(it);"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("_and = _remove;"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("}"); @@ -5993,34 +5894,28 @@ public void testBug380525_02() { _builder_1.append("protected L(final E e) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Procedure1 _function = new Procedure1() {"); + _builder_1.append("final Procedure1 _function = (E it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public void apply(final E it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("boolean _and = false;"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("boolean _add = L.this.add(it);"); + _builder_1.append(" "); + _builder_1.append("boolean _add = this.add(it);"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("if (!_add) {"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("_and = false;"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("} else {"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("boolean _remove = L.this.remove(it);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_and = _remove;"); + _builder_1.append(" "); + _builder_1.append("boolean _remove = this.remove(it);"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("_and = _remove;"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("}"); @@ -7129,6 +7024,9 @@ public void testBug399975_02() throws Exception { _builder_1.append("public class B extends A {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public void m(final Class[] c) {"); _builder_1.newLine(); _builder_1.append(" "); @@ -7195,6 +7093,9 @@ public void testBug399975_04() throws Exception { _builder_1.append("public class B extends A {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public void m(final Class... c) {"); _builder_1.newLine(); _builder_1.append(" "); @@ -8332,17 +8233,11 @@ public void testBug410990() { _builder_1.append("{"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Foo _function = new Foo() {"); + _builder_1.append("final Foo _function = (Foo foo) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public void foo(final Foo foo) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("foo.foo(foo);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -8350,17 +8245,11 @@ public void testBug410990() { _builder_1.append("this.bug(_function);"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Bar _function_1 = new Bar() {"); + _builder_1.append("final Bar _function_1 = (Bar bar) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public void bar(final Bar bar) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("bar.bar(bar);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); diff --git a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/ExtensionsCompilerTest.java b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/ExtensionsCompilerTest.java index efa1fa84d44..c6e4ebcc5bd 100644 --- a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/ExtensionsCompilerTest.java +++ b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/ExtensionsCompilerTest.java @@ -48,17 +48,11 @@ public void testDeprecatedSort() { _builder_1.append("public List m(final Iterable it) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Comparator _function = new Comparator() {"); + _builder_1.append("final Comparator _function = (String $0, String $1) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public int compare(final String $0, final String $1) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return $0.compareTo($1);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -118,17 +112,11 @@ public void testExtensionImportVsDefaultExtensions_01() { _builder_1.append("public List m(final List list) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function1 _function = new Function1() {"); + _builder_1.append("final Function1 _function = (String it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public String apply(final String it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return it;"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -184,17 +172,11 @@ public void testExtensionImportVsDefaultExtensions_02() { _builder_1.append("public List m(final List list) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function1 _function = new Function1() {"); + _builder_1.append("final Function1 _function = (String it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public String apply(final String it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return it;"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -248,17 +230,11 @@ public void testLocalVsDefaultExtensions_01() { _builder_1.append("public Collection m(final List list) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function1 _function = new Function1() {"); + _builder_1.append("final Function1 _function = (String it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public String apply(final String it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return it;"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -318,17 +294,11 @@ public void testLocalVsDefaultExtensions_02() { _builder_1.append("public List m(final List list) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function1 _function = new Function1() {"); + _builder_1.append("final Function1 _function = (String it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public String apply(final String it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return it;"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -394,17 +364,11 @@ public void testLocalVsDefaultExtensions_03() { _builder_1.append("public List m(final List list) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function1 _function = new Function1() {"); + _builder_1.append("final Function1 _function = (String it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public String apply(final String it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return it;"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -464,17 +428,11 @@ public void testLocalVsDefaultExtensions_04() { _builder_1.append("public List m(final List list) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function1 _function = new Function1() {"); + _builder_1.append("final Function1 _function = (String it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public String apply(final String it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return it;"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -554,17 +512,11 @@ public void testExtensionFieldVsDefaultExtensions_01() { _builder_1.append("public Collection m(final List list) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function1 _function = new Function1() {"); + _builder_1.append("final Function1 _function = (String it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public String apply(final String it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return it;"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -630,17 +582,11 @@ public void testExtensionFieldVsDefaultExtensions_02() { _builder_1.append("public List m(final List list) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function1 _function = new Function1() {"); + _builder_1.append("final Function1 _function = (String it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public String apply(final String it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return it;"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -727,50 +673,44 @@ public void testExtensionAnnotations() { _builder_1.append("for (@Extension final Integer j : _upTo) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function1 _function = new Function1() {"); + _builder_1.append("final Function1 _function = (Object o) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Throwable apply(@Extension final Object o) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("Throwable _xtrycatchfinallyexpression = null;"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("try {"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("_xtrycatchfinallyexpression = null;"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("} catch (final Throwable _t) {"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("if (_t instanceof Throwable) {"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("@Extension final Throwable t = (Throwable)_t;"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("_xtrycatchfinallyexpression = InputOutput.println(t);"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("} else {"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("throw Exceptions.sneakyThrow(_t);"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("throw Exceptions.sneakyThrow(_t);"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("}"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return _xtrycatchfinallyexpression;"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("}"); _builder_1.newLine(); + _builder_1.append(" "); + _builder_1.append("return _xtrycatchfinallyexpression;"); + _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -1665,8 +1605,6 @@ public void testExtensionParamOnLamdba() { _builder_1.newLine(); _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Extension;"); - _builder_1.newLine(); _builder_1.newLine(); _builder_1.append("@SuppressWarnings(\"all\")"); _builder_1.newLine(); @@ -1676,17 +1614,11 @@ public void testExtensionParamOnLamdba() { _builder_1.append("public void m(final int it) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Consumer _function = new Consumer() {"); + _builder_1.append("final Consumer _function = (String s) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public void accept(@Extension final String s) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("s.substring(it);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -1941,16 +1873,10 @@ public void testExtensionForArrayOfT_01() { _builder_1.append("ArrayList _newArrayList = CollectionLiterals.newArrayList(\"foo\", \"bar\");"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Procedure1> _function = new Procedure1>() {"); + _builder_1.append("final Procedure1> _function = (ArrayList it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public void apply(final ArrayList it) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("C.this.at(((String[])Conversions.unwrapArray(it, String.class)), 2);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("this.at(((String[])Conversions.unwrapArray(it, String.class)), 2);"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); diff --git a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/Java6CompilerTest.java b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/Java6CompilerTest.java index 8e0d0e06ba8..b170c3c9826 100644 --- a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/Java6CompilerTest.java +++ b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/Java6CompilerTest.java @@ -8,15 +8,12 @@ */ package org.eclipse.xtend.core.tests.compiler; -import org.eclipse.xtend.core.tests.Java6RuntimeInjectorProvider; import org.eclipse.xtend2.lib.StringConcatenation; -import org.eclipse.xtext.testing.InjectWith; import org.junit.Test; /** * @author Miro Spoenemann - Initial contribution and API */ -@InjectWith(Java6RuntimeInjectorProvider.class) @SuppressWarnings("all") public class Java6CompilerTest extends AbstractXtendCompilerTest { @Test diff --git a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/Java8OverloadCompilerTest.java b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/Java8OverloadCompilerTest.java index ccde182609b..3cbded8f448 100644 --- a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/Java8OverloadCompilerTest.java +++ b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/Java8OverloadCompilerTest.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2013, 2016 itemis AG (http://www.itemis.eu) and others. + * Copyright (c) 2013, 2024 itemis AG (http://www.itemis.eu) and others. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. @@ -49,17 +49,11 @@ public void testBug438461_01() { _builder_1.append("public void m(final ExecutorService service) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Callable _function = new Callable() {"); + _builder_1.append("final Callable _function = () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Object call() throws Exception {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return null;"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -104,17 +98,11 @@ public void testBug438461_02() { _builder_1.append("public void m(final ExecutorService service) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Runnable _function = new Runnable() {"); + _builder_1.append("final Runnable _function = () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public void run() {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return;"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -161,17 +149,11 @@ public void testBug438461_03() { _builder_1.append("public void m(final ExecutorService service) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Callable _function = new Callable() {"); + _builder_1.append("final Callable _function = () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public String call() throws Exception {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return \"\";"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -218,17 +200,11 @@ public void testBug438461_04() { _builder_1.append("public void m(final ExecutorService service) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Callable _function = new Callable() {"); + _builder_1.append("final Callable _function = () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public String call() throws Exception {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return \"\";"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -283,16 +259,10 @@ public void testBug438461_05() { _builder_1.append("public void m(final ExecutorService service) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Runnable _function = new Runnable() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void run() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Bug.this.m();"); + _builder_1.append("final Runnable _function = () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("this.m();"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); @@ -362,17 +332,11 @@ public void testBug438461_06() { _builder_1.append("public void m(final Iterable i) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Bug.I _function = new Bug.I() {"); + _builder_1.append("final Bug.I _function = (Runnable it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public void bind(final Runnable it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("it.run();"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -441,17 +405,11 @@ public void testBug438461_07() { _builder_1.append("public void m(final Iterable i) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Bug.I _function = new Bug.I() {"); + _builder_1.append("final Bug.I _function = (Runnable it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public void bind(final Runnable it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("it.run();"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -520,17 +478,11 @@ public void testBug438461_08() { _builder_1.append("public void m(final Iterable... i) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Bug.I _function = new Bug.I() {"); + _builder_1.append("final Bug.I _function = (Runnable it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public void bind(final Runnable it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("it.run();"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -585,17 +537,11 @@ public void testBug438461_09() { _builder_1.append("public void m(final Function0 f) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function0 _function = new Function0() {"); + _builder_1.append("final Function0 _function = () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public String apply() {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return \"\";"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -650,17 +596,11 @@ public void testBug438461_10() { _builder_1.append("public void m(final Procedure0 f) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function2 _function = new Function2() {"); + _builder_1.append("final Function2 _function = (String $0, String $1) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public String apply(final String $0, final String $1) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return ($0 + $1);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -715,17 +655,11 @@ public void testBug438461_11() { _builder_1.append("public void m(final Function0... f) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function0 _function = new Function0() {"); + _builder_1.append("final Function0 _function = () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public String apply() {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return \"\";"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -780,17 +714,11 @@ public void testBug438461_12() { _builder_1.append("public void m(final Procedure0 f) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function2 _function = new Function2() {"); + _builder_1.append("final Function2 _function = (String $0, String $1) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public String apply(final String $0, final String $1) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return ($0 + $1);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); diff --git a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/NestedClassCompilerTest.java b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/NestedClassCompilerTest.java index 0553c584257..2b8c4bbaf8c 100644 --- a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/NestedClassCompilerTest.java +++ b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/NestedClassCompilerTest.java @@ -914,6 +914,9 @@ public void testBugNotAnEnclosingInstance_01() { _builder_1.append("depositExceptionHandler = new AbstractIterator() {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public Boolean computeNext() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -929,6 +932,9 @@ public void testBugNotAnEnclosingInstance_01() { _builder_1.append("}"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public Iterator iterator() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -938,16 +944,10 @@ public void testBugNotAnEnclosingInstance_01() { _builder_1.append("{"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Procedure1 _function = new Procedure1() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void apply(final Object it) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_this__Account_1.dis.processAsyncResponse(true);"); + _builder_1.append("final Procedure1 _function = (Object it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("this.dis.processAsyncResponse(true);"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); @@ -1111,19 +1111,13 @@ public void testBugNotAnEnclosingInstance_02() { _builder_1.append("public void m2() {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final C.I _function = new C.I() {"); + _builder_1.append("final C.I _function = (int it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public void m1(final int it) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_this__C_1.m1(1);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("C.this.m1(\"\");"); + _builder_1.append("this.m1(1);"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("C.this.m1(\"\");"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); @@ -1266,6 +1260,9 @@ public void testBugNotAnEnclosingInstance_03() { _builder_1.append("final C.I i = new C.I() {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public void m1() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -1439,6 +1436,9 @@ public void testBugNotAnEnclosingInstance_04() { _builder_1.append("final C.I _function = new C.I() {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public void m1(final int it) {"); _builder_1.newLine(); _builder_1.append(" "); diff --git a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/OverloadedExtensionCompilerTest.java b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/OverloadedExtensionCompilerTest.java index 6cfc4d5958a..3b2070708e6 100644 --- a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/OverloadedExtensionCompilerTest.java +++ b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/OverloadedExtensionCompilerTest.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2013, 2016 itemis AG (http://www.itemis.eu) and others. + * Copyright (c) 2013, 2024 itemis AG (http://www.itemis.eu) and others. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. @@ -58,16 +58,10 @@ public void test_01() { _builder_1.append("public void method(final MyIterable list) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Consumer _function = new Consumer() {"); + _builder_1.append("final Consumer _function = (Number it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public void consume(final Number it) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("C.this.process(it);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("this.process(it);"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); @@ -132,16 +126,10 @@ public void test_02() { _builder_1.append("public void method(final MyIterable list) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Consumer _function = new Consumer() {"); + _builder_1.append("final Consumer _function = (Number it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public void consume(final Number it) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("C.this.process(it);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("this.process(it);"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); diff --git a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/ParameterizedInnerTypesCompilerTest.java b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/ParameterizedInnerTypesCompilerTest.java index 295945d195b..bc8225b4220 100644 --- a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/ParameterizedInnerTypesCompilerTest.java +++ b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/ParameterizedInnerTypesCompilerTest.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2014, 2022 itemis AG (http://www.itemis.eu) and others. + * Copyright (c) 2014, 2024 itemis AG (http://www.itemis.eu) and others. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. @@ -144,19 +144,13 @@ public void test_03() { _builder_1.append("public Boolean m(final Either it) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function _function = new Function() {"); + _builder_1.append("final Function _function = (Integer it_1) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Boolean apply(final Integer it_1) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("int _intValue = it_1.intValue();"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return Boolean.valueOf((_intValue == 0));"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("return Boolean.valueOf((_intValue == 0));"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); @@ -284,17 +278,11 @@ public void test_06() { _builder_1.append("public Either m(final Either it) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function _function = new Function() {"); + _builder_1.append("final Function _function = (Boolean it_1) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public String apply(final Boolean it_1) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return it_1.toString();"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); diff --git a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/ParameterizedTypeCompilerTest.java b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/ParameterizedTypeCompilerTest.java index 69981aa8f3c..89a4c5e9a97 100644 --- a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/ParameterizedTypeCompilerTest.java +++ b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/ParameterizedTypeCompilerTest.java @@ -632,6 +632,9 @@ public void testBug403706_02() { _builder_1.newLine(); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public Object woot(final List list) {"); _builder_1.newLine(); _builder_1.append(" "); diff --git a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/TryWithResourcesTest.java b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/TryWithResourcesTest.java index bdbd6a2a0a2..46708c00db9 100644 --- a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/TryWithResourcesTest.java +++ b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/TryWithResourcesTest.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2019 itemis AG (http://www.itemis.eu) and others. + * Copyright (c) 2019, 2024 itemis AG (http://www.itemis.eu) and others. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. @@ -171,10 +171,6 @@ public void test_easyResource() { _builder_1.newLine(); _builder_1.append("import java.io.StringReader;"); _builder_1.newLine(); - _builder_1.append("import java.util.ArrayList;"); - _builder_1.newLine(); - _builder_1.append("import java.util.List;"); - _builder_1.newLine(); _builder_1.append("import org.eclipse.xtext.xbase.lib.Exceptions;"); _builder_1.newLine(); _builder_1.newLine(); @@ -190,16 +186,7 @@ public void test_easyResource() { _builder_1.append("public void fooMethod() {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("List _ts = new ArrayList();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("StringReader a = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("try {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("a = new StringReader(this.s);"); + _builder_1.append("try (final StringReader a = new StringReader(this.s)) {"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("a.read();"); @@ -220,42 +207,12 @@ public void test_easyResource() { _builder_1.append("} else {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("_ts.add(_t);"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("throw Exceptions.sneakyThrow(_t);"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("}"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("} finally {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (a != null) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("try {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("a.close();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("} catch (Throwable _t_1) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_ts.add(_t_1);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if(!_ts.isEmpty()) throw Exceptions.sneakyThrow(_ts.get(0));"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("}"); _builder_1.newLine(); _builder_1.append(" "); @@ -281,47 +238,14 @@ public void test_assumeTypeAutoClosable() { StringConcatenation _builder_1 = new StringConcatenation(); _builder_1.append("final AutoCloseable[] array = new AutoCloseable[2];"); _builder_1.newLine(); - _builder_1.append("List _ts = new ArrayList();"); - _builder_1.newLine(); - _builder_1.append("AutoCloseable someCloseable = null;"); - _builder_1.newLine(); - _builder_1.append("try {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("someCloseable = array[0];"); + _builder_1.append("try (final AutoCloseable someCloseable = array[0]) {"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("someCloseable.close();"); _builder_1.newLine(); - _builder_1.append("} finally {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (someCloseable != null) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("try {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("someCloseable.close();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("} catch (Throwable _t) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_ts.add(_t);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if(!_ts.isEmpty()) throw Exceptions.sneakyThrow(_ts.get(0));"); - _builder_1.newLine(); _builder_1.append("}"); _builder_1.newLine(); - this.assertCompilesTo(this.buildXtendInput(_builder, false, false, false), this.buildJavaOutput(_builder_1, false, false, false, true)); + this.assertCompilesTo(this.buildXtendInput(_builder, false, false, false), this.buildJavaOutput(_builder_1, false, false, false, false)); } @Test @@ -343,8 +267,6 @@ public void test_automaticCloseButStillExceptionCatched() { _builder_1.newLine(); _builder_1.append("import java.io.StringReader;"); _builder_1.newLine(); - _builder_1.append("import java.util.ArrayList;"); - _builder_1.newLine(); _builder_1.append("import java.util.Collections;"); _builder_1.newLine(); _builder_1.append("import java.util.List;"); @@ -378,43 +300,7 @@ public void test_automaticCloseButStillExceptionCatched() { _builder_1.append("final List array = Collections.unmodifiableList(CollectionLiterals.newArrayList(reader1, reader2));"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("List _ts = new ArrayList();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("AutoCloseable closable = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("try {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("closable = array.get(0);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("} finally {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (closable != null) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("try {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("closable.close();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("} catch (Throwable _t) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_ts.add(_t);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if(!_ts.isEmpty()) throw Exceptions.sneakyThrow(_ts.get(0));"); + _builder_1.append("try (final AutoCloseable closable = array.get(0)) {"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("}"); @@ -464,10 +350,6 @@ public void test_noteSecretVariableNames() { _builder_1.newLine(); _builder_1.append("import java.io.StringReader;"); _builder_1.newLine(); - _builder_1.append("import java.util.ArrayList;"); - _builder_1.newLine(); - _builder_1.append("import java.util.List;"); - _builder_1.newLine(); _builder_1.append("import org.eclipse.xtext.xbase.lib.Exceptions;"); _builder_1.newLine(); _builder_1.newLine(); @@ -486,16 +368,7 @@ public void test_noteSecretVariableNames() { _builder_1.append("try {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("List _ts = new ArrayList();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("StringReader a = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("try {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("a = new StringReader(this.s);"); + _builder_1.append("try (final StringReader a = new StringReader(this.s)) {"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("final int x = (1 + 1);"); @@ -504,78 +377,15 @@ public void test_noteSecretVariableNames() { _builder_1.append("a.read();"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("} finally {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (a != null) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("try {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("a.close();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("} catch (Throwable _t) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_ts.add(_t);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if(!_ts.isEmpty()) throw Exceptions.sneakyThrow(_ts.get(0));"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("}"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("List _ts_1 = new ArrayList();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("StringReader x = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("try {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("x = new StringReader(this.s);"); + _builder_1.append("try (final StringReader x = new StringReader(this.s)) {"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("x.close();"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("} finally {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (x != null) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("try {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("x.close();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("} catch (Throwable _t) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_ts_1.add(_t);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if(!_ts_1.isEmpty()) throw Exceptions.sneakyThrow(_ts_1.get(0));"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("}"); _builder_1.newLine(); _builder_1.append(" "); @@ -614,10 +424,6 @@ public void test_twoResources() { _builder_1.newLine(); _builder_1.append("import java.io.StringReader;"); _builder_1.newLine(); - _builder_1.append("import java.util.ArrayList;"); - _builder_1.newLine(); - _builder_1.append("import java.util.List;"); - _builder_1.newLine(); _builder_1.append("import org.eclipse.xtext.xbase.lib.Exceptions;"); _builder_1.newLine(); _builder_1.newLine(); @@ -636,75 +442,12 @@ public void test_twoResources() { _builder_1.append("try {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("List _ts = new ArrayList();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("StringReader sr = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("BufferedReader buffy = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("try {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("sr = new StringReader(this.s);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("buffy = new BufferedReader(sr);"); + _builder_1.append("try (final StringReader sr = new StringReader(this.s); final BufferedReader buffy = new BufferedReader(sr)) {"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("buffy.read();"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("} finally {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (buffy != null) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("try {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("buffy.close();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("} catch (Throwable _t) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_ts.add(_t);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (sr != null) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("try {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("sr.close();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("} catch (Throwable _t) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_ts.add(_t);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if(!_ts.isEmpty()) throw Exceptions.sneakyThrow(_ts.get(0));"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("}"); _builder_1.newLine(); _builder_1.append(" "); @@ -741,10 +484,6 @@ public void test_twoNestedResources() { _builder_1.newLine(); _builder_1.append("import java.io.StringReader;"); _builder_1.newLine(); - _builder_1.append("import java.util.ArrayList;"); - _builder_1.newLine(); - _builder_1.append("import java.util.List;"); - _builder_1.newLine(); _builder_1.append("import org.eclipse.xtext.xbase.lib.Exceptions;"); _builder_1.newLine(); _builder_1.newLine(); @@ -763,48 +502,12 @@ public void test_twoNestedResources() { _builder_1.append("try {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("List _ts = new ArrayList();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("BufferedReader br = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("try {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("br = new BufferedReader(new StringReader(this.s));"); + _builder_1.append("try (final BufferedReader br = new BufferedReader(new StringReader(this.s))) {"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("br.readLine();"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("} finally {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (br != null) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("try {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("br.close();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("} catch (Throwable _t) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_ts.add(_t);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if(!_ts.isEmpty()) throw Exceptions.sneakyThrow(_ts.get(0));"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("}"); _builder_1.newLine(); _builder_1.append(" "); @@ -843,10 +546,6 @@ public void test_twoResourcesOneDefinedOutside() { _builder_1.newLine(); _builder_1.append("import java.io.StringReader;"); _builder_1.newLine(); - _builder_1.append("import java.util.ArrayList;"); - _builder_1.newLine(); - _builder_1.append("import java.util.List;"); - _builder_1.newLine(); _builder_1.append("import org.eclipse.xtext.xbase.lib.Exceptions;"); _builder_1.newLine(); _builder_1.newLine(); @@ -868,48 +567,12 @@ public void test_twoResourcesOneDefinedOutside() { _builder_1.append("final StringReader sr = new StringReader(this.s);"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("List _ts = new ArrayList();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("BufferedReader br = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("try {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("br = new BufferedReader(sr);"); + _builder_1.append("try (final BufferedReader br = new BufferedReader(sr)) {"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("br.readLine();"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("} finally {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (br != null) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("try {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("br.close();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("} catch (Throwable _t) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_ts.add(_t);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if(!_ts.isEmpty()) throw Exceptions.sneakyThrow(_ts.get(0));"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("}"); _builder_1.newLine(); _builder_1.append(" "); @@ -948,10 +611,6 @@ public void test_nestedIf1() { _builder_1.newLine(); _builder_1.append("import java.io.StringReader;"); _builder_1.newLine(); - _builder_1.append("import java.util.ArrayList;"); - _builder_1.newLine(); - _builder_1.append("import java.util.List;"); - _builder_1.newLine(); _builder_1.append("import org.eclipse.xtext.xbase.lib.Exceptions;"); _builder_1.newLine(); _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function0;"); @@ -972,103 +631,43 @@ public void test_nestedIf1() { _builder_1.append("try {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("List _ts = new ArrayList();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("StringReader fr = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("BufferedReader br = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("try {"); + _builder_1.append("try (final StringReader fr = new Function0() {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("fr = new Function0() {"); + _builder_1.append("@Override"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("public StringReader apply() {"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("String _xifexpression = null;"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("if (true) {"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("_xifexpression = (FooClass.this.s + \"1\");"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("} else {"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_xifexpression = (FooClass.this.s + \"2\");"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return new StringReader(_xifexpression);"); + _builder_1.append("_xifexpression = (FooClass.this.s + \"2\");"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("}"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}.apply();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("br = new BufferedReader(fr);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("br.read();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("} finally {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (br != null) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("try {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("br.close();"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("} catch (Throwable _t) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_ts.add(_t);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("return new StringReader(_xifexpression);"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("}"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (fr != null) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("try {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("fr.close();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("} catch (Throwable _t) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_ts.add(_t);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append(" "); + _builder_1.append("}.apply(); final BufferedReader br = new BufferedReader(fr)) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("if(!_ts.isEmpty()) throw Exceptions.sneakyThrow(_ts.get(0));"); + _builder_1.append("br.read();"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("}"); @@ -1136,10 +735,6 @@ public void test_ResourceIOException() { _builder_1.newLine(); _builder_1.append("import java.io.IOException;"); _builder_1.newLine(); - _builder_1.append("import java.util.ArrayList;"); - _builder_1.newLine(); - _builder_1.append("import java.util.List;"); - _builder_1.newLine(); _builder_1.append("import org.eclipse.xtext.xbase.lib.Exceptions;"); _builder_1.newLine(); _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function0;"); @@ -1153,43 +748,37 @@ public void test_ResourceIOException() { _builder_1.append("public void fooMethod() {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("List _ts = new ArrayList();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("FileReader a = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("try {"); + _builder_1.append("try (final FileReader a = new Function0() {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("a = new Function0() {"); + _builder_1.append("@Override"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("public FileReader apply() {"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("try {"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("File _file = new File(\"\\\\home/docs/text.txt\");"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("return new FileReader(_file);"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("} catch (Throwable _e) {"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("throw Exceptions.sneakyThrow(_e);"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("throw Exceptions.sneakyThrow(_e);"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("}"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}.apply();"); + _builder_1.append("}"); + _builder_1.newLine(); + _builder_1.append(" "); + _builder_1.append("}.apply()) {"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("a.read();"); @@ -1210,42 +799,12 @@ public void test_ResourceIOException() { _builder_1.append("} else {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("_ts.add(_t);"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("throw Exceptions.sneakyThrow(_t);"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("}"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("} finally {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (a != null) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("try {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("a.close();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("} catch (Throwable _t_1) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_ts.add(_t_1);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if(!_ts.isEmpty()) throw Exceptions.sneakyThrow(_ts.get(0));"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("}"); _builder_1.newLine(); _builder_1.append(" "); @@ -1264,56 +823,16 @@ public void test_tryWithLambda01() { _builder.append("}"); _builder.newLine(); StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("List _ts = new ArrayList();"); - _builder_1.newLine(); - _builder_1.append("AutoCloseable r = null;"); - _builder_1.newLine(); - _builder_1.append("try {"); + _builder_1.append("try (AutoCloseable r = ((AutoCloseable) () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("r = new AutoCloseable() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void close() throws Exception {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("System.out.println(\"Closing\");"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append("} finally {"); + _builder_1.append("})) {"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (r != null) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("try {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("r.close();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("} catch (Throwable _t) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_ts.add(_t);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("}"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if(!_ts.isEmpty()) throw Exceptions.sneakyThrow(_ts.get(0));"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(this.buildXtendInput(_builder, false, false, false), this.buildJavaOutput(_builder_1, false, false, false, true)); + this.assertCompilesTo(this.buildXtendInput(_builder, false, false, false), this.buildJavaOutput(_builder_1, false, false, false, false)); } @Test @@ -1335,8 +854,6 @@ public void test_tryWithLambda02() { _builder_1.newLine(); _builder_1.append("import java.util.ArrayList;"); _builder_1.newLine(); - _builder_1.append("import java.util.List;"); - _builder_1.newLine(); _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); _builder_1.newLine(); _builder_1.append("import org.eclipse.xtext.xbase.lib.Exceptions;"); @@ -1360,58 +877,16 @@ public void test_tryWithLambda02() { _builder_1.append("final ArrayList myList = CollectionLiterals.newArrayList();"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("List _ts = new ArrayList();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("AutoCloseable someCloseable = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("try {"); + _builder_1.append("try (final AutoCloseable someCloseable = ((AutoCloseable) () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("someCloseable = new AutoCloseable() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void close() throws Exception {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("myList.add(\"close\");"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("myList.add(\"body\");"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("} finally {"); + _builder_1.append("})) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("if (someCloseable != null) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("try {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("someCloseable.close();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("} catch (Throwable _t) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_ts.add(_t);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if(!_ts.isEmpty()) throw Exceptions.sneakyThrow(_ts.get(0));"); + _builder_1.append("myList.add(\"body\");"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("}"); diff --git a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/XtendCompilerTest.java b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/XtendCompilerTest.java index 18e2f725623..43a45c64ae0 100644 --- a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/XtendCompilerTest.java +++ b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/XtendCompilerTest.java @@ -14,7 +14,6 @@ import org.eclipse.xtend2.lib.StringConcatenation; import org.eclipse.xtext.common.types.JvmDeclaredType; import org.eclipse.xtext.generator.IFilePostProcessor; -import org.eclipse.xtext.util.JavaVersion; import org.eclipse.xtext.xbase.compiler.GeneratorConfig; import org.eclipse.xtext.xbase.lib.Exceptions; import org.eclipse.xtext.xbase.lib.IterableExtensions; @@ -215,6 +214,9 @@ public void testMultiCatch_02() { _builder_1.append("public static class E1 extends Exception implements Foo.E {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public void m() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -228,6 +230,9 @@ public void testMultiCatch_02() { _builder_1.append("public static class E2 extends Exception implements Foo.E {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public void m() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -316,16 +321,10 @@ public void testClosureNoArgs() { _builder_1.append("public class Foo {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("private final Thread thread = new Thread(new Runnable() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void run() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("private final Thread thread = new Thread(((Runnable) () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("});"); + _builder_1.append("}));"); _builder_1.newLine(); _builder_1.append("}"); _builder_1.newLine(); @@ -364,17 +363,11 @@ public void testClosureTwoArgs() { _builder_1.append("public void m(final List list) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Comparator _function = new Comparator() {"); + _builder_1.append("final Comparator _function = (String $0, String $1) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public int compare(final String $0, final String $1) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return 0;"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -390,7 +383,7 @@ public void testClosureTwoArgs() { } @Test - public void testInnerTypeImports() { + public void testInnerTypeImports_1() { StringConcatenation _builder = new StringConcatenation(); _builder.append("class Foo extends types.SomeClassWithNestedInterface implements types.SomeClassWithNestedInterface.NestedInterface {}"); _builder.newLine(); @@ -408,7 +401,7 @@ public void testInnerTypeImports() { } @Test - public void testInnerTypeImports_1() { + public void testInnerTypeImports_2() { StringConcatenation _builder = new StringConcatenation(); _builder.append("class Foo extends types.SomeClassWithNestedInterface {"); _builder.newLine(); @@ -432,6 +425,9 @@ public void testInnerTypeImports_1() { _builder_1.append("public class Foo extends SomeClassWithNestedInterface {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public SomeClassWithNestedInterface.String convert(final java.lang.String s) {"); _builder_1.newLine(); _builder_1.append(" "); @@ -794,6 +790,9 @@ public void testExpectationFromTypeParameter() { _builder_1.newLine(); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public LightweightTypeReference substitute(final LightweightTypeReference original) {"); _builder_1.newLine(); _builder_1.append(" "); @@ -804,6 +803,9 @@ public void testExpectationFromTypeParameter() { _builder_1.newLine(); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("protected Set createVisiting() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -2129,6 +2131,9 @@ public void testRecursiveLambda_01() { _builder_1.append("final Function1 _function = new Function1() {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public String apply(final String it) {"); _builder_1.newLine(); _builder_1.append(" "); @@ -2182,6 +2187,9 @@ public void testRecursiveLambda_02() { _builder_1.append("final Procedure0 _function = new Procedure0() {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public void apply() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -2475,17 +2483,11 @@ public void testAbstractIterator_03() { _builder_1.append("T _elvis = null;"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function1 _function = new Function1() {"); + _builder_1.append("final Function1 _function = (T it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Boolean apply(final T it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return Boolean.valueOf((it != null));"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -2595,17 +2597,11 @@ public void testAbstractIterator_04() { _builder_1.append("T _elvis = null;"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function1 _function = new Function1() {"); + _builder_1.append("final Function1 _function = (T it_1) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Boolean apply(final T it_1) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return Boolean.valueOf((!Objects.equals(it_1, null)));"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -2689,121 +2685,31 @@ public void testVoidMethod_01() throws Exception { } @Test - public void testVoidMethod_02() throws Exception { + public void testThrowablesPropagate_01() throws Exception { StringConcatenation _builder = new StringConcatenation(); - _builder.append("class A {"); + _builder.append("import static extension Throwables.*"); _builder.newLine(); - _builder.append("\t"); - _builder.append("def m() {"); + _builder.append("import java.net.URI"); _builder.newLine(); - _builder.append("\t\t"); - _builder.append("[ | System::out.println(\'\') ]"); _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); + _builder.append("class Client {"); _builder.newLine(); - _builder.append("}"); + _builder.append("\t"); + _builder.append("val uri = [| new URI(\'\')].propagate [ new IllegalArgumentException(it) ]"); _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Procedures.Procedure0;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class A {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public Procedure0 m() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Procedure0 _function = new Procedure0() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void apply() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("System.out.println(\"\");"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return _function;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - public void testVoidMethod_03() throws Exception { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("class A {"); + _builder.append("\t"); _builder.newLine(); _builder.append("\t"); - _builder.append("def m() {"); + _builder.append("def foo (){"); _builder.newLine(); _builder.append("\t\t"); - _builder.append("[ | println(\'\') ]"); + _builder.append("uri.toString"); _builder.newLine(); _builder.append("\t"); _builder.append("}"); _builder.newLine(); _builder.append("}"); _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function0;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.InputOutput;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class A {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public Function0 m() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function0 _function = new Function0() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public String apply() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return InputOutput.println(\"\");"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return _function;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - public void testThrowablesPropagate_01() throws Exception { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import static extension Throwables.*"); - _builder.newLine(); - _builder.append("import java.net.URI"); - _builder.newLine(); - _builder.newLine(); _builder.append("class Throwables {"); _builder.newLine(); _builder.append("\t"); @@ -2829,25 +2735,9 @@ public void testThrowablesPropagate_01() throws Exception { _builder.newLine(); _builder.append("}"); _builder.newLine(); - _builder.append("class Client {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("val uri = [| new URI(\'\')].propagate [ new IllegalArgumentException(it) ]"); - _builder.newLine(); - _builder.append("\t"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def foo (){"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("uri.toString"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); StringConcatenation _builder_1 = new StringConcatenation(); + _builder_1.append("import java.net.URI;"); + _builder_1.newLine(); _builder_1.append("import org.eclipse.xtext.xbase.lib.Exceptions;"); _builder_1.newLine(); _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function0;"); @@ -2857,58 +2747,41 @@ public void testThrowablesPropagate_01() throws Exception { _builder_1.newLine(); _builder_1.append("@SuppressWarnings(\"all\")"); _builder_1.newLine(); - _builder_1.append("public class Throwables {"); + _builder_1.append("public class Client {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public static T propagate(final Function0 proc, final Function1 handler) {"); + _builder_1.append("private final URI uri = Throwables.propagate(((Function0) () -> {"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("try {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("T _xtrycatchfinallyexpression = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("try {"); + _builder_1.append("return new URI(\"\");"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_xtrycatchfinallyexpression = proc.apply();"); + _builder_1.append(" "); + _builder_1.append("} catch (Throwable _e) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("} catch (final Throwable _t) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (_t instanceof Exception) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Exception e = (Exception)_t;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("throw handler.apply(e);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("} else {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("throw Exceptions.sneakyThrow(_t);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("throw Exceptions.sneakyThrow(_e);"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("}"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return _xtrycatchfinallyexpression;"); + _builder_1.append(" "); + _builder_1.append("}), ((Function1) (Exception it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("} catch (Throwable _e) {"); + _builder_1.append("return new IllegalArgumentException(it);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("throw Exceptions.sneakyThrow(_e);"); + _builder_1.append(" "); + _builder_1.append("}));"); + _builder_1.newLine(); + _builder_1.newLine(); + _builder_1.append(" "); + _builder_1.append("public String foo() {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("return this.uri.toString();"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("}"); @@ -2973,43 +2846,31 @@ public void testThrowablesPropagate_02() throws Exception { _builder_1.append("public class Client {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("private final URI uri = Throwables.propagate(new Function0() {"); + _builder_1.append("private final URI uri = Throwables.propagate(((Function0) () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public URI apply() {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("try {"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("return new URI(\"\");"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("} catch (Throwable _e) {"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("throw Exceptions.sneakyThrow(_e);"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("throw Exceptions.sneakyThrow(_e);"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("}"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}, new Function1() {"); + _builder_1.append("}), ((Function1) (Exception it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Exception apply(final Exception it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return new IllegalArgumentException(it);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("});"); + _builder_1.append("}));"); _builder_1.newLine(); _builder_1.append("}"); _builder_1.newLine(); @@ -3320,6 +3181,9 @@ public void testOverriddenVarArgs() { _builder_1.append("public class B extends A {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public String foo(final String x, final String... args) {"); _builder_1.newLine(); _builder_1.append(" "); @@ -3746,6 +3610,9 @@ public void testSwitchWithMultiType_02() { _builder_1.append("public static class E1 extends Exception implements C.E {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public void m() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -3759,6 +3626,9 @@ public void testSwitchWithMultiType_02() { _builder_1.append("public static class E2 extends Exception implements C.E {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public void m() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -3874,6 +3744,9 @@ public void testSwitchWithMultiType_03() { _builder_1.append("public static class E1 extends Exception implements C.E {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public void m() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -3887,6 +3760,9 @@ public void testSwitchWithMultiType_03() { _builder_1.append("public static class E2 extends Exception implements C.E {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public void m() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -4346,7 +4222,7 @@ public void testSwitchWithBooleanExpression_3() { _builder.append("class Foo {"); _builder.newLine(); _builder.append("\t"); - _builder.append("def foo(int x) {"); + _builder.append("def foo(int x) { "); _builder.newLine(); _builder.append("\t\t"); _builder.append("switch x {"); @@ -4383,19 +4259,13 @@ public void testSwitchWithBooleanExpression_3() { _builder_1.append("boolean _matched = false;"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("if (((new Function0() {"); + _builder_1.append("if (((((Function0) () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Boolean apply() {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return Boolean.valueOf((1 == x));"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}.apply()).booleanValue() || (x == 2))) {"); + _builder_1.append("}).apply()).booleanValue() || (x == 2))) {"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("_matched=true;"); @@ -4447,7 +4317,7 @@ public void testSwitchOverNull() { _builder.append("}"); _builder.newLine(); _builder.append(" "); - _builder.append("}"); + _builder.append("} "); _builder.newLine(); _builder.append("}"); _builder.newLine(); @@ -4480,17 +4350,11 @@ public void testSwitchOverNull() { _builder_1.append("_matched=true;"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function1 _function = new Function1() {"); + _builder_1.append("final Function1 _function = (Object it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Object apply(final Object it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return it;"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -4510,17 +4374,11 @@ public void testSwitchOverNull() { _builder_1.append("_matched=true;"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function1 _function_1 = new Function1() {"); + _builder_1.append("final Function1 _function_1 = (Integer it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Integer apply(final Integer it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return it;"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -4990,17 +4848,11 @@ public void testSwitchWithConstantExpressions_6() { _builder_1.append("boolean _switchResult = false;"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function0 _function = new Function0() {"); + _builder_1.append("final Function0 _function = () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Integer apply() {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return Integer.valueOf(1);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -5087,17 +4939,11 @@ public void testSwitchWithConstantExpressions_7() { _builder_1.append("boolean _matched = false;"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function0 _function = new Function0() {"); + _builder_1.append("final Function0 _function = () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Integer apply() {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return Integer.valueOf(1);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -6351,25 +6197,19 @@ public void testClosureSneakyThrow() { _builder_1.append("try {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function1 _function = new Function1() {"); + _builder_1.append("final Function1 _function = (String f) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public File apply(final String f) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("try {"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("return new File(f).getCanonicalFile();"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("} catch (Throwable _e) {"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("throw Exceptions.sneakyThrow(_e);"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("throw Exceptions.sneakyThrow(_e);"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("}"); @@ -6455,25 +6295,19 @@ public void testClosureSneakyThrow_02() throws Exception { _builder_1.append("public Map bar() {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function1 _function = new Function1() {"); + _builder_1.append("final Function1 _function = (String it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Object apply(final String it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("try {"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return Foo.this.getFoo(it);"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("} catch (Throwable _e) {"); + _builder_1.append("return this.getFoo(it);"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("throw Exceptions.sneakyThrow(_e);"); + _builder_1.append(" "); + _builder_1.append("} catch (Throwable _e) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("throw Exceptions.sneakyThrow(_e);"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("}"); @@ -7954,10 +7788,10 @@ public void testSuperCall_01() { _builder.append("else"); _builder.newLine(); _builder.append("\t\t\t"); - _builder.append("super.equals(p)"); + _builder.append("super.equals(p) "); _builder.newLine(); _builder.append("\t"); - _builder.append("}"); + _builder.append("} "); _builder.newLine(); _builder.append("}"); _builder.newLine(); @@ -7973,6 +7807,9 @@ public void testSuperCall_01() { _builder_1.append("public class Y {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public boolean equals(final Object p) {"); _builder_1.newLine(); _builder_1.append(" "); @@ -8203,6 +8040,9 @@ public void testSuperCall_03() { _builder_1.append("public class B extends A {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public String getThing() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -8898,31 +8738,19 @@ public void testNestedClosureWithIt() { _builder_1.append("{"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function1 _function = new Function1() {"); + _builder_1.append("final Function1 _function = (String it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public String apply(final String it) {"); + _builder_1.append("final Function1 _function_1 = (String it_1) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function1 _function = new Function1() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public String apply(final String it_1) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return it_1;"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return _function.apply(it);"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("return _function_1.apply(it);"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); @@ -8975,31 +8803,19 @@ public void testNestedClosureSuperCall() { _builder_1.append("public String foo() {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function0 _function = new Function0() {"); + _builder_1.append("final Function0 _function = () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public String apply() {"); + _builder_1.append("final Function0 _function_1 = () -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function0 _function = new Function0() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public String apply() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return X.super.toString();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("return super.toString();"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return _function.apply();"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("return _function_1.apply();"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); @@ -9541,17 +9357,11 @@ public void testJavaKeywordsUsed() { _builder_1.append("_matched=true;"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Consumer _function = new Consumer() {"); + _builder_1.append("final Consumer _function = (String break_) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public void accept(final String break_) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("(break_ + continue_).toString();"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -9602,17 +9412,11 @@ public void testFindFirstOnIt_01() { _builder_1.append("public T useExtension(final Iterable it) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final Function1 _function = new Function1() {"); + _builder_1.append("final Function1 _function = (T it_1) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public Boolean apply(final T it_1) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("return Boolean.valueOf((it_1 != null));"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("};"); _builder_1.newLine(); @@ -9655,6 +9459,9 @@ public void testReturnType() { _builder_1.append("public class MyClass implements ReturnTypeUsesTypeParameter {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public ReturnTypeUsesTypeParameter.Inner accept(final LocalName param) {"); _builder_1.newLine(); _builder_1.append(" "); @@ -9680,7 +9487,7 @@ public void testReturnType_02() { _builder.append("override accept(LocalName param) {"); _builder.newLine(); _builder.append("\t\t"); - _builder.append("[ if (true) it?.apply(param) ]"); + _builder.append("[ if (true) it?.apply(param) ] "); _builder.newLine(); _builder.append("\t"); _builder.append("}"); @@ -9698,25 +9505,22 @@ public void testReturnType_02() { _builder_1.append("public class MyClass implements ReturnTypeUsesTypeParameter {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public ReturnTypeUsesTypeParameter.Inner accept(final LocalName param) {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("final ReturnTypeUsesTypeParameter.Inner _function = new ReturnTypeUsesTypeParameter.Inner() {"); + _builder_1.append("final ReturnTypeUsesTypeParameter.Inner _function = (Procedure1 it) -> {"); _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("public void useProcedure(final Procedure1 it) {"); - _builder_1.newLine(); - _builder_1.append(" "); _builder_1.append("if (true) {"); _builder_1.newLine(); - _builder_1.append(" "); + _builder_1.append(" "); _builder_1.append("if (it!=null) {"); _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("it.apply(param);"); - _builder_1.newLine(); _builder_1.append(" "); - _builder_1.append("}"); + _builder_1.append("it.apply(param);"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("}"); @@ -9770,7 +9574,7 @@ public void testReturnType_03() { _builder.append("abstract class A {"); _builder.newLine(); _builder.append("\t"); - _builder.append("def CharSequence m()"); + _builder.append("def CharSequence m() "); _builder.newLine(); _builder.append("}"); _builder.newLine(); @@ -9790,6 +9594,9 @@ public void testReturnType_03() { _builder_1.newLine(); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public CharSequence m() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -10347,7 +10154,7 @@ public void compileClassWithFileHeader() { _builder.append("package foo"); _builder.newLine(); _builder.newLine(); - _builder.append("class bar {"); + _builder.append("class MyClass {"); _builder.newLine(); _builder.append(" "); _builder.append("String name = \'foobar\'"); @@ -10383,7 +10190,7 @@ public void compileClassWithFileHeader() { _builder_1.newLine(); _builder_1.append("@SuppressWarnings(\"all\")"); _builder_1.newLine(); - _builder_1.append("public class bar {"); + _builder_1.append("public class MyClass {"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("private String name = \"foobar\";"); @@ -12439,16 +12246,12 @@ public void testXFunctionTypeRefAsSuperType_01() { StringConcatenation _builder = new StringConcatenation(); _builder.append("class Foo implements ()=>void {"); _builder.newLine(); - _builder.newLine(); _builder.append("\t"); _builder.append("override apply() {"); _builder.newLine(); - _builder.append("\t\t"); - _builder.newLine(); _builder.append("\t"); _builder.append("}"); _builder.newLine(); - _builder.newLine(); _builder.append("}"); _builder.newLine(); StringConcatenation _builder_1 = new StringConcatenation(); @@ -12460,6 +12263,9 @@ public void testXFunctionTypeRefAsSuperType_01() { _builder_1.append("public class Foo implements Procedure0 {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public void apply() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -12475,10 +12281,8 @@ public void testXFunctionTypeRefAsSuperType_02() { StringConcatenation _builder = new StringConcatenation(); _builder.append("interface Foo extends ()=>void {"); _builder.newLine(); - _builder.newLine(); _builder.append("\t"); - _builder.append("override void apply();"); - _builder.newLine(); + _builder.append("override void apply()"); _builder.newLine(); _builder.append("}"); _builder.newLine(); @@ -12491,6 +12295,9 @@ public void testXFunctionTypeRefAsSuperType_02() { _builder_1.append("public interface Foo extends Procedure0 {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("void apply();"); _builder_1.newLine(); _builder_1.append("}"); @@ -12503,16 +12310,12 @@ public void testXFunctionTypeRefAsSuperType_03() { StringConcatenation _builder = new StringConcatenation(); _builder.append("class Foo implements (String)=>void {"); _builder.newLine(); - _builder.newLine(); _builder.append("\t"); _builder.append("override apply(String value) {"); _builder.newLine(); - _builder.append("\t\t"); - _builder.newLine(); _builder.append("\t"); _builder.append("}"); _builder.newLine(); - _builder.newLine(); _builder.append("}"); _builder.newLine(); StringConcatenation _builder_1 = new StringConcatenation(); @@ -12524,6 +12327,9 @@ public void testXFunctionTypeRefAsSuperType_03() { _builder_1.append("public class Foo implements Procedure1 {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public void apply(final String value) {"); _builder_1.newLine(); _builder_1.append(" "); @@ -12539,10 +12345,8 @@ public void testXFunctionTypeRefAsSuperType_04() { StringConcatenation _builder = new StringConcatenation(); _builder.append("interface Foo extends (String)=>void {"); _builder.newLine(); - _builder.newLine(); _builder.append("\t"); - _builder.append("override void apply(String value);"); - _builder.newLine(); + _builder.append("override void apply(String value)"); _builder.newLine(); _builder.append("}"); _builder.newLine(); @@ -12555,6 +12359,9 @@ public void testXFunctionTypeRefAsSuperType_04() { _builder_1.append("public interface Foo extends Procedure1 {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("void apply(final String value);"); _builder_1.newLine(); _builder_1.append("}"); @@ -12567,16 +12374,12 @@ public void testXFunctionTypeRefAsSuperType_05() { StringConcatenation _builder = new StringConcatenation(); _builder.append("class Foo implements ((String)=>void)=>void {"); _builder.newLine(); - _builder.newLine(); _builder.append("\t"); _builder.append("override apply((String)=>void procedure) {"); _builder.newLine(); - _builder.append("\t\t"); - _builder.newLine(); _builder.append("\t"); _builder.append("}"); _builder.newLine(); - _builder.newLine(); _builder.append("}"); _builder.newLine(); StringConcatenation _builder_1 = new StringConcatenation(); @@ -12588,6 +12391,9 @@ public void testXFunctionTypeRefAsSuperType_05() { _builder_1.append("public class Foo implements Procedure1> {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public void apply(final Procedure1 procedure) {"); _builder_1.newLine(); _builder_1.append(" "); @@ -12603,10 +12409,8 @@ public void testXFunctionTypeRefAsSuperType_06() { StringConcatenation _builder = new StringConcatenation(); _builder.append("interface Foo extends ((String)=>void)=>void {"); _builder.newLine(); - _builder.newLine(); _builder.append("\t"); - _builder.append("override void apply((String)=>void procedure);"); - _builder.newLine(); + _builder.append("override void apply((String)=>void procedure)"); _builder.newLine(); _builder.append("}"); _builder.newLine(); @@ -12619,6 +12423,9 @@ public void testXFunctionTypeRefAsSuperType_06() { _builder_1.append("public interface Foo extends Procedure1> {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("void apply(final Procedure1 procedure);"); _builder_1.newLine(); _builder_1.append("}"); @@ -12631,16 +12438,12 @@ public void testXFunctionTypeRefAsSuperType_07() { StringConcatenation _builder = new StringConcatenation(); _builder.append("class Foo implements ()=>String {"); _builder.newLine(); - _builder.newLine(); _builder.append("\t"); _builder.append("override apply() {"); _builder.newLine(); - _builder.append("\t\t"); - _builder.newLine(); _builder.append("\t"); _builder.append("}"); _builder.newLine(); - _builder.newLine(); _builder.append("}"); _builder.newLine(); StringConcatenation _builder_1 = new StringConcatenation(); @@ -12652,6 +12455,9 @@ public void testXFunctionTypeRefAsSuperType_07() { _builder_1.append("public class Foo implements Function0 {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public String apply() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -12670,10 +12476,8 @@ public void testXFunctionTypeRefAsSuperType_08() { StringConcatenation _builder = new StringConcatenation(); _builder.append("interface Foo extends ()=>String {"); _builder.newLine(); - _builder.newLine(); _builder.append("\t"); - _builder.append("override String apply();"); - _builder.newLine(); + _builder.append("override String apply()"); _builder.newLine(); _builder.append("}"); _builder.newLine(); @@ -12686,6 +12490,9 @@ public void testXFunctionTypeRefAsSuperType_08() { _builder_1.append("public interface Foo extends Function0 {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("String apply();"); _builder_1.newLine(); _builder_1.append("}"); @@ -12698,16 +12505,12 @@ public void testXFunctionTypeRefAsSuperType_09() { StringConcatenation _builder = new StringConcatenation(); _builder.append("class Foo implements ()=>(String)=>void {"); _builder.newLine(); - _builder.newLine(); _builder.append("\t"); _builder.append("override apply() {"); _builder.newLine(); - _builder.append("\t\t"); - _builder.newLine(); _builder.append("\t"); _builder.append("}"); _builder.newLine(); - _builder.newLine(); _builder.append("}"); _builder.newLine(); StringConcatenation _builder_1 = new StringConcatenation(); @@ -12721,6 +12524,9 @@ public void testXFunctionTypeRefAsSuperType_09() { _builder_1.append("public class Foo implements Function0> {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("public Procedure1 apply() {"); _builder_1.newLine(); _builder_1.append(" "); @@ -12739,11 +12545,9 @@ public void testXFunctionTypeRefAsSuperType_10() { StringConcatenation _builder = new StringConcatenation(); _builder.append("interface Foo extends ()=>(String)=>void {"); _builder.newLine(); - _builder.newLine(); _builder.append("\t"); _builder.append("override (String)=>void apply();"); _builder.newLine(); - _builder.newLine(); _builder.append("}"); _builder.newLine(); StringConcatenation _builder_1 = new StringConcatenation(); @@ -12757,6 +12561,9 @@ public void testXFunctionTypeRefAsSuperType_10() { _builder_1.append("public interface Foo extends Function0> {"); _builder_1.newLine(); _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); _builder_1.append("Procedure1 apply();"); _builder_1.newLine(); _builder_1.append("}"); @@ -13103,7 +12910,6 @@ public void testBug485556() { @Test public void testSuppressUnnecessaryModifiersInInterfaces() { - final GeneratorConfig generatorConfig = this.generatorConfigProvider.get(null); StringConcatenation _builder = new StringConcatenation(); _builder.append("interface FooItf {"); _builder.newLine(); @@ -13129,14 +12935,9 @@ public void testSuppressUnnecessaryModifiersInInterfaces() { _builder_1.append(" "); _builder_1.append("class FooItfImpl implements FooItf {"); _builder_1.newLine(); - { - boolean _isAtLeast = generatorConfig.getJavaSourceVersion().isAtLeast(JavaVersion.JAVA6); - if (_isAtLeast) { - _builder_1.append(" "); - _builder_1.append("@Override"); - _builder_1.newLine(); - } - } + _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("public void bar() {"); _builder_1.newLine(); @@ -13154,4 +12955,743 @@ public void testSuppressUnnecessaryModifiersInInterfaces() { _builder_1.newLine(); this.assertCompilesTo(_builder, _builder_1); } + + @Test + public void testStaticMethodInInterface() { + StringConcatenation _builder = new StringConcatenation(); + _builder.append("interface Foo {"); + _builder.newLine(); + _builder.append("\t"); + _builder.append("static def bar() {"); + _builder.newLine(); + _builder.append("\t\t"); + _builder.append("\"bar!\""); + _builder.newLine(); + _builder.append("\t"); + _builder.append("}"); + _builder.newLine(); + _builder.append("}"); + _builder.newLine(); + StringConcatenation _builder_1 = new StringConcatenation(); + _builder_1.append("@SuppressWarnings(\"all\")"); + _builder_1.newLine(); + _builder_1.append("public interface Foo {"); + _builder_1.newLine(); + _builder_1.append(" "); + _builder_1.append("static String bar() {"); + _builder_1.newLine(); + _builder_1.append(" "); + _builder_1.append("return \"bar!\";"); + _builder_1.newLine(); + _builder_1.append(" "); + _builder_1.append("}"); + _builder_1.newLine(); + _builder_1.append("}"); + _builder_1.newLine(); + this.assertCompilesTo(_builder, _builder_1); + } + + @Test + public void testJava8UnaryOperator() throws Exception { + StringConcatenation _builder = new StringConcatenation(); + _builder.append("import java.util.List"); + _builder.newLine(); + _builder.append("class Test {"); + _builder.newLine(); + _builder.append("\t"); + _builder.append("def test(List list) {"); + _builder.newLine(); + _builder.append("\t\t"); + _builder.append("list.replaceAll[it + 1]"); + _builder.newLine(); + _builder.append("\t"); + _builder.append("}"); + _builder.newLine(); + _builder.append("}"); + _builder.newLine(); + StringConcatenation _builder_1 = new StringConcatenation(); + _builder_1.append("import java.util.List;"); + _builder_1.newLine(); + _builder_1.append("import java.util.function.UnaryOperator;"); + _builder_1.newLine(); + _builder_1.newLine(); + _builder_1.append("@SuppressWarnings(\"all\")"); + _builder_1.newLine(); + _builder_1.append("public class Test {"); + _builder_1.newLine(); + _builder_1.append(" "); + _builder_1.append("public void test(final List list) {"); + _builder_1.newLine(); + _builder_1.append(" "); + _builder_1.append("final UnaryOperator _function = (Integer it) -> {"); + _builder_1.newLine(); + _builder_1.append(" "); + _builder_1.append("return Integer.valueOf(((it).intValue() + 1));"); + _builder_1.newLine(); + _builder_1.append(" "); + _builder_1.append("};"); + _builder_1.newLine(); + _builder_1.append(" "); + _builder_1.append("list.replaceAll(_function);"); + _builder_1.newLine(); + _builder_1.append(" "); + _builder_1.append("}"); + _builder_1.newLine(); + _builder_1.append("}"); + _builder_1.newLine(); + this.assertCompilesTo(_builder, _builder_1); + } + + @Test + public void testJava8Comparator() throws Exception { + StringConcatenation _builder = new StringConcatenation(); + _builder.append("import java.util.List"); + _builder.newLine(); + _builder.append("class Test {"); + _builder.newLine(); + _builder.append("\t"); + _builder.append("def test(List list) {"); + _builder.newLine(); + _builder.append("\t\t"); + _builder.append("list.sort(java.util.Comparator.comparingInt[String s | s.length]"); + _builder.newLine(); + _builder.append("\t\t\t"); + _builder.append(".thenComparing[String s | s.length])"); + _builder.newLine(); + _builder.append("\t"); + _builder.append("}"); + _builder.newLine(); + _builder.append("}"); + _builder.newLine(); + StringConcatenation _builder_1 = new StringConcatenation(); + _builder_1.append("import java.util.Comparator;"); + _builder_1.newLine(); + _builder_1.append("import java.util.List;"); + _builder_1.newLine(); + _builder_1.append("import java.util.function.Function;"); + _builder_1.newLine(); + _builder_1.append("import java.util.function.ToIntFunction;"); + _builder_1.newLine(); + _builder_1.newLine(); + _builder_1.append("@SuppressWarnings(\"all\")"); + _builder_1.newLine(); + _builder_1.append("public class Test {"); + _builder_1.newLine(); + _builder_1.append(" "); + _builder_1.append("public void test(final List list) {"); + _builder_1.newLine(); + _builder_1.append(" "); + _builder_1.append("final ToIntFunction _function = (String s) -> {"); + _builder_1.newLine(); + _builder_1.append(" "); + _builder_1.append("return s.length();"); + _builder_1.newLine(); + _builder_1.append(" "); + _builder_1.append("};"); + _builder_1.newLine(); + _builder_1.append(" "); + _builder_1.append("final Function _function_1 = (String s) -> {"); + _builder_1.newLine(); + _builder_1.append(" "); + _builder_1.append("return Integer.valueOf(s.length());"); + _builder_1.newLine(); + _builder_1.append(" "); + _builder_1.append("};"); + _builder_1.newLine(); + _builder_1.append(" "); + _builder_1.append("list.sort(Comparator.comparingInt(_function).thenComparing(_function_1));"); + _builder_1.newLine(); + _builder_1.append(" "); + _builder_1.append("}"); + _builder_1.newLine(); + _builder_1.append("}"); + _builder_1.newLine(); + this.assertCompilesTo(_builder, _builder_1); + } + + @Test + public void testJava8Predicate() throws Exception { + StringConcatenation _builder = new StringConcatenation(); + _builder.append("import java.util.List"); + _builder.newLine(); + _builder.append("class Test {"); + _builder.newLine(); + _builder.append("\t"); + _builder.append("def test(List list) {"); + _builder.newLine(); + _builder.append("\t\t"); + _builder.append("list.removeIf[it < 2]"); + _builder.newLine(); + _builder.append("\t"); + _builder.append("}"); + _builder.newLine(); + _builder.append("}"); + _builder.newLine(); + StringConcatenation _builder_1 = new StringConcatenation(); + _builder_1.append("import java.util.List;"); + _builder_1.newLine(); + _builder_1.append("import java.util.function.Predicate;"); + _builder_1.newLine(); + _builder_1.newLine(); + _builder_1.append("@SuppressWarnings(\"all\")"); + _builder_1.newLine(); + _builder_1.append("public class Test {"); + _builder_1.newLine(); + _builder_1.append(" "); + _builder_1.append("public boolean test(final List list) {"); + _builder_1.newLine(); + _builder_1.append(" "); + _builder_1.append("final Predicate _function = (Integer it) -> {"); + _builder_1.newLine(); + _builder_1.append(" "); + _builder_1.append("return ((it).intValue() < 2);"); + _builder_1.newLine(); + _builder_1.append(" "); + _builder_1.append("};"); + _builder_1.newLine(); + _builder_1.append(" "); + _builder_1.append("return list.removeIf(_function);"); + _builder_1.newLine(); + _builder_1.append(" "); + _builder_1.append("}"); + _builder_1.newLine(); + _builder_1.append("}"); + _builder_1.newLine(); + this.assertCompilesTo(_builder, _builder_1); + } + + @Test + public void testJava8BinaryOperation() throws Exception { + StringConcatenation _builder = new StringConcatenation(); + _builder.append("import java.util.List"); + _builder.newLine(); + _builder.append("class Test {"); + _builder.newLine(); + _builder.append("\t"); + _builder.append("def test(List list) {"); + _builder.newLine(); + _builder.append("\t\t"); + _builder.append("list.stream.reduce[a, b | a && b]"); + _builder.newLine(); + _builder.append("\t"); + _builder.append("}"); + _builder.newLine(); + _builder.append("}"); + _builder.newLine(); + StringConcatenation _builder_1 = new StringConcatenation(); + _builder_1.append("import java.util.List;"); + _builder_1.newLine(); + _builder_1.append("import java.util.Optional;"); + _builder_1.newLine(); + _builder_1.append("import java.util.function.BinaryOperator;"); + _builder_1.newLine(); + _builder_1.newLine(); + _builder_1.append("@SuppressWarnings(\"all\")"); + _builder_1.newLine(); + _builder_1.append("public class Test {"); + _builder_1.newLine(); + _builder_1.append(" "); + _builder_1.append("public Optional test(final List list) {"); + _builder_1.newLine(); + _builder_1.append(" "); + _builder_1.append("final BinaryOperator _function = (Boolean a, Boolean b) -> {"); + _builder_1.newLine(); + _builder_1.append(" "); + _builder_1.append("return Boolean.valueOf(((a).booleanValue() && (b).booleanValue()));"); + _builder_1.newLine(); + _builder_1.append(" "); + _builder_1.append("};"); + _builder_1.newLine(); + _builder_1.append(" "); + _builder_1.append("return list.stream().reduce(_function);"); + _builder_1.newLine(); + _builder_1.append(" "); + _builder_1.append("}"); + _builder_1.newLine(); + _builder_1.append("}"); + _builder_1.newLine(); + this.assertCompilesTo(_builder, _builder_1); + } + + @Test + public void testJava8Consumer() throws Exception { + StringConcatenation _builder = new StringConcatenation(); + _builder.append("import java.util.List"); + _builder.newLine(); + _builder.append("class Test {"); + _builder.newLine(); + _builder.append("\t"); + _builder.append("def test(List list) {"); + _builder.newLine(); + _builder.append("\t\t"); + _builder.append("list.stream.forEach[println(it)]"); + _builder.newLine(); + _builder.append("\t"); + _builder.append("}"); + _builder.newLine(); + _builder.append("}"); + _builder.newLine(); + StringConcatenation _builder_1 = new StringConcatenation(); + _builder_1.append("import java.util.List;"); + _builder_1.newLine(); + _builder_1.append("import java.util.function.Consumer;"); + _builder_1.newLine(); + _builder_1.append("import org.eclipse.xtext.xbase.lib.InputOutput;"); + _builder_1.newLine(); + _builder_1.newLine(); + _builder_1.append("@SuppressWarnings(\"all\")"); + _builder_1.newLine(); + _builder_1.append("public class Test {"); + _builder_1.newLine(); + _builder_1.append(" "); + _builder_1.append("public void test(final List list) {"); + _builder_1.newLine(); + _builder_1.append(" "); + _builder_1.append("final Consumer _function = (String it) -> {"); + _builder_1.newLine(); + _builder_1.append(" "); + _builder_1.append("InputOutput.println(it);"); + _builder_1.newLine(); + _builder_1.append(" "); + _builder_1.append("};"); + _builder_1.newLine(); + _builder_1.append(" "); + _builder_1.append("list.stream().forEach(_function);"); + _builder_1.newLine(); + _builder_1.append(" "); + _builder_1.append("}"); + _builder_1.newLine(); + _builder_1.append("}"); + _builder_1.newLine(); + this.assertCompilesTo(_builder, _builder_1); + } + + @Test + public void testJava8BiFunction() throws Exception { + StringConcatenation _builder = new StringConcatenation(); + _builder.append("import java.util.Map"); + _builder.newLine(); + _builder.append("class Test {"); + _builder.newLine(); + _builder.append("\t"); + _builder.append("def test(Map map) {"); + _builder.newLine(); + _builder.append("\t\t"); + _builder.append("map.replaceAll[k, v | v + k.length]"); + _builder.newLine(); + _builder.append("\t"); + _builder.append("}"); + _builder.newLine(); + _builder.append("}"); + _builder.newLine(); + StringConcatenation _builder_1 = new StringConcatenation(); + _builder_1.append("import java.util.Map;"); + _builder_1.newLine(); + _builder_1.append("import java.util.function.BiFunction;"); + _builder_1.newLine(); + _builder_1.newLine(); + _builder_1.append("@SuppressWarnings(\"all\")"); + _builder_1.newLine(); + _builder_1.append("public class Test {"); + _builder_1.newLine(); + _builder_1.append(" "); + _builder_1.append("public void test(final Map map) {"); + _builder_1.newLine(); + _builder_1.append(" "); + _builder_1.append("final BiFunction _function = (String k, Integer v) -> {"); + _builder_1.newLine(); + _builder_1.append(" "); + _builder_1.append("int _length = k.length();"); + _builder_1.newLine(); + _builder_1.append(" "); + _builder_1.append("return Integer.valueOf(((v).intValue() + _length));"); + _builder_1.newLine(); + _builder_1.append(" "); + _builder_1.append("};"); + _builder_1.newLine(); + _builder_1.append(" "); + _builder_1.append("map.replaceAll(_function);"); + _builder_1.newLine(); + _builder_1.append(" "); + _builder_1.append("}"); + _builder_1.newLine(); + _builder_1.append("}"); + _builder_1.newLine(); + this.assertCompilesTo(_builder, _builder_1); + } + + @Test + public void testDefaultMethodSuperCall01() throws Exception { + StringConcatenation _builder = new StringConcatenation(); + _builder.append("class Test implements A {"); + _builder.newLine(); + _builder.append("\t"); + _builder.append("override void foo() {"); + _builder.newLine(); + _builder.append("\t\t"); + _builder.append("A.super.foo"); + _builder.newLine(); + _builder.append("\t"); + _builder.append("}"); + _builder.newLine(); + _builder.append("}"); + _builder.newLine(); + _builder.append("interface A {"); + _builder.newLine(); + _builder.append("\t"); + _builder.append("def void foo() {}"); + _builder.newLine(); + _builder.append("}"); + _builder.newLine(); + StringConcatenation _builder_1 = new StringConcatenation(); + _builder_1.append("@SuppressWarnings(\"all\")"); + _builder_1.newLine(); + _builder_1.append("public class Test implements A {"); + _builder_1.newLine(); + _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); + _builder_1.append("public void foo() {"); + _builder_1.newLine(); + _builder_1.append(" "); + _builder_1.append("A.super.foo();"); + _builder_1.newLine(); + _builder_1.append(" "); + _builder_1.append("}"); + _builder_1.newLine(); + _builder_1.append("}"); + _builder_1.newLine(); + this.assertCompilesTo(_builder, _builder_1); + } + + @Test + public void testDefaultMethodSuperCall02() throws Exception { + StringConcatenation _builder = new StringConcatenation(); + _builder.append("class Test implements A, B {"); + _builder.newLine(); + _builder.append("\t"); + _builder.append("override void foo() {"); + _builder.newLine(); + _builder.append("\t\t"); + _builder.append("B.super.foo"); + _builder.newLine(); + _builder.append("\t"); + _builder.append("}"); + _builder.newLine(); + _builder.append("}"); + _builder.newLine(); + _builder.append("interface A {"); + _builder.newLine(); + _builder.append("\t"); + _builder.append("def void foo() {}"); + _builder.newLine(); + _builder.append("}"); + _builder.newLine(); + _builder.append("interface B {"); + _builder.newLine(); + _builder.append("\t"); + _builder.append("def void foo() {}"); + _builder.newLine(); + _builder.append("}"); + _builder.newLine(); + StringConcatenation _builder_1 = new StringConcatenation(); + _builder_1.append("@SuppressWarnings(\"all\")"); + _builder_1.newLine(); + _builder_1.append("public class Test implements A, B {"); + _builder_1.newLine(); + _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); + _builder_1.append("public void foo() {"); + _builder_1.newLine(); + _builder_1.append(" "); + _builder_1.append("B.super.foo();"); + _builder_1.newLine(); + _builder_1.append(" "); + _builder_1.append("}"); + _builder_1.newLine(); + _builder_1.append("}"); + _builder_1.newLine(); + this.assertCompilesTo(_builder, _builder_1); + } + + @Test + public void testDefaultMethodSuperCall03() throws Exception { + StringConcatenation _builder = new StringConcatenation(); + _builder.append("import test.Consumer"); + _builder.newLine(); + _builder.append("class Test implements Consumer, java.util.function.Consumer {"); + _builder.newLine(); + _builder.append("\t"); + _builder.append("override void accept(String element) {"); + _builder.newLine(); + _builder.append("\t\t"); + _builder.append("java.util.function.Consumer.super.andThen(this).accept(\'foo\')"); + _builder.newLine(); + _builder.append("\t"); + _builder.append("}"); + _builder.newLine(); + _builder.append("}"); + _builder.newLine(); + StringConcatenation _builder_1 = new StringConcatenation(); + _builder_1.append("import test.Consumer;"); + _builder_1.newLine(); + _builder_1.newLine(); + _builder_1.append("@SuppressWarnings(\"all\")"); + _builder_1.newLine(); + _builder_1.append("public class Test implements Consumer, java.util.function.Consumer {"); + _builder_1.newLine(); + _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); + _builder_1.append("public void accept(final String element) {"); + _builder_1.newLine(); + _builder_1.append(" "); + _builder_1.append("java.util.function.Consumer.super.andThen(this).accept(\"foo\");"); + _builder_1.newLine(); + _builder_1.append(" "); + _builder_1.append("}"); + _builder_1.newLine(); + _builder_1.append("}"); + _builder_1.newLine(); + this.assertCompilesTo(_builder, _builder_1); + } + + @Test + public void testDefaultMethodSuperCall04() throws Exception { + StringConcatenation _builder = new StringConcatenation(); + _builder.append("interface Test extends A {"); + _builder.newLine(); + _builder.append("\t"); + _builder.append("override void foo() {"); + _builder.newLine(); + _builder.append("\t\t"); + _builder.append("A.super.foo"); + _builder.newLine(); + _builder.append("\t"); + _builder.append("}"); + _builder.newLine(); + _builder.append("}"); + _builder.newLine(); + _builder.append("interface A {"); + _builder.newLine(); + _builder.append("\t"); + _builder.append("def void foo() {}"); + _builder.newLine(); + _builder.append("}"); + _builder.newLine(); + StringConcatenation _builder_1 = new StringConcatenation(); + _builder_1.append("@SuppressWarnings(\"all\")"); + _builder_1.newLine(); + _builder_1.append("public interface Test extends A {"); + _builder_1.newLine(); + _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); + _builder_1.append("default void foo() {"); + _builder_1.newLine(); + _builder_1.append(" "); + _builder_1.append("A.super.foo();"); + _builder_1.newLine(); + _builder_1.append(" "); + _builder_1.append("}"); + _builder_1.newLine(); + _builder_1.append("}"); + _builder_1.newLine(); + this.assertCompilesTo(_builder, _builder_1); + } + + @Test + public void testSelfReference() throws Exception { + StringConcatenation _builder = new StringConcatenation(); + _builder.append("class LambdaTest {"); + _builder.newLine(); + _builder.append("\t"); + _builder.append("def b(A a) {"); + _builder.newLine(); + _builder.append("\t\t"); + _builder.append("a.a"); + _builder.newLine(); + _builder.append("\t"); + _builder.append("}"); + _builder.newLine(); + _builder.append("\t"); + _builder.append("def test() {"); + _builder.newLine(); + _builder.append("\t\t"); + _builder.append("b[\'hello\' + b[\'world\' + self.a]]"); + _builder.newLine(); + _builder.append("\t"); + _builder.append("}"); + _builder.newLine(); + _builder.append("}"); + _builder.newLine(); + _builder.append("interface A {"); + _builder.newLine(); + _builder.append("\t"); + _builder.append("def String a()"); + _builder.newLine(); + _builder.append("}"); + _builder.newLine(); + StringConcatenation _builder_1 = new StringConcatenation(); + _builder_1.append("@SuppressWarnings(\"all\")"); + _builder_1.newLine(); + _builder_1.append("public class LambdaTest {"); + _builder_1.newLine(); + _builder_1.append(" "); + _builder_1.append("public String b(final A a) {"); + _builder_1.newLine(); + _builder_1.append(" "); + _builder_1.append("return a.a();"); + _builder_1.newLine(); + _builder_1.append(" "); + _builder_1.append("}"); + _builder_1.newLine(); + _builder_1.newLine(); + _builder_1.append(" "); + _builder_1.append("public String test() {"); + _builder_1.newLine(); + _builder_1.append(" "); + _builder_1.append("final A _function = () -> {"); + _builder_1.newLine(); + _builder_1.append(" "); + _builder_1.append("final A _function_1 = new A() {"); + _builder_1.newLine(); + _builder_1.append(" "); + _builder_1.append("@Override"); + _builder_1.newLine(); + _builder_1.append(" "); + _builder_1.append("public String a() {"); + _builder_1.newLine(); + _builder_1.append(" "); + _builder_1.append("String _a = this.a();"); + _builder_1.newLine(); + _builder_1.append(" "); + _builder_1.append("return (\"world\" + _a);"); + _builder_1.newLine(); + _builder_1.append(" "); + _builder_1.append("}"); + _builder_1.newLine(); + _builder_1.append(" "); + _builder_1.append("};"); + _builder_1.newLine(); + _builder_1.append(" "); + _builder_1.append("String _b = this.b(_function_1);"); + _builder_1.newLine(); + _builder_1.append(" "); + _builder_1.append("return (\"hello\" + _b);"); + _builder_1.newLine(); + _builder_1.append(" "); + _builder_1.append("};"); + _builder_1.newLine(); + _builder_1.append(" "); + _builder_1.append("return this.b(_function);"); + _builder_1.newLine(); + _builder_1.append(" "); + _builder_1.append("}"); + _builder_1.newLine(); + _builder_1.append("}"); + _builder_1.newLine(); + this.assertCompilesTo(_builder, _builder_1); + } + + @Test + public void testVoidMethod_02() throws Exception { + StringConcatenation _builder = new StringConcatenation(); + _builder.append("class A {"); + _builder.newLine(); + _builder.append("\t"); + _builder.append("def m() {"); + _builder.newLine(); + _builder.append("\t\t"); + _builder.append("[ | System::out.println(\'\') ]"); + _builder.newLine(); + _builder.append("\t"); + _builder.append("}"); + _builder.newLine(); + _builder.append("}"); + _builder.newLine(); + StringConcatenation _builder_1 = new StringConcatenation(); + _builder_1.append("import org.eclipse.xtext.xbase.lib.Procedures.Procedure0;"); + _builder_1.newLine(); + _builder_1.newLine(); + _builder_1.append("@SuppressWarnings(\"all\")"); + _builder_1.newLine(); + _builder_1.append("public class A {"); + _builder_1.newLine(); + _builder_1.append(" "); + _builder_1.append("public Procedure0 m() {"); + _builder_1.newLine(); + _builder_1.append(" "); + _builder_1.append("final Procedure0 _function = () -> {"); + _builder_1.newLine(); + _builder_1.append(" "); + _builder_1.append("System.out.println(\"\");"); + _builder_1.newLine(); + _builder_1.append(" "); + _builder_1.append("};"); + _builder_1.newLine(); + _builder_1.append(" "); + _builder_1.append("return _function;"); + _builder_1.newLine(); + _builder_1.append(" "); + _builder_1.append("}"); + _builder_1.newLine(); + _builder_1.append("}"); + _builder_1.newLine(); + this.assertCompilesTo(_builder, _builder_1); + } + + @Test + public void testVoidMethod_03() throws Exception { + StringConcatenation _builder = new StringConcatenation(); + _builder.append("class A {"); + _builder.newLine(); + _builder.append("\t"); + _builder.append("def m() {"); + _builder.newLine(); + _builder.append("\t\t"); + _builder.append("[ | println(\'\') ]"); + _builder.newLine(); + _builder.append("\t"); + _builder.append("}"); + _builder.newLine(); + _builder.append("}"); + _builder.newLine(); + StringConcatenation _builder_1 = new StringConcatenation(); + _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function0;"); + _builder_1.newLine(); + _builder_1.append("import org.eclipse.xtext.xbase.lib.InputOutput;"); + _builder_1.newLine(); + _builder_1.newLine(); + _builder_1.append("@SuppressWarnings(\"all\")"); + _builder_1.newLine(); + _builder_1.append("public class A {"); + _builder_1.newLine(); + _builder_1.append(" "); + _builder_1.append("public Function0 m() {"); + _builder_1.newLine(); + _builder_1.append(" "); + _builder_1.append("final Function0 _function = () -> {"); + _builder_1.newLine(); + _builder_1.append(" "); + _builder_1.append("return InputOutput.println(\"\");"); + _builder_1.newLine(); + _builder_1.append(" "); + _builder_1.append("};"); + _builder_1.newLine(); + _builder_1.append(" "); + _builder_1.append("return _function;"); + _builder_1.newLine(); + _builder_1.append(" "); + _builder_1.append("}"); + _builder_1.newLine(); + _builder_1.append("}"); + _builder_1.newLine(); + this.assertCompilesTo(_builder, _builder_1); + } } diff --git a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/batch/BatchCompilerTest.java b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/batch/BatchCompilerTest.java index 7f6d22e3ff6..12c6fc83805 100644 --- a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/batch/BatchCompilerTest.java +++ b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/compiler/batch/BatchCompilerTest.java @@ -40,7 +40,6 @@ import org.junit.AfterClass; import org.junit.Assert; import org.junit.Before; -import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; @@ -487,7 +486,6 @@ public void bug410594() { } @Test - @Ignore public void bug416262() { this.batchCompiler.setSourcePath(BatchCompilerTest.BUG416262_SRC_DIRECTORY); Assert.assertTrue("Compiling funny file pass", this.batchCompiler.compile()); @@ -514,7 +512,11 @@ public void bug417177() { public void testActiveAnnotatons1() { this.batchCompiler.setSourcePath("./batch-compiler-data/activeAnnotations1"); final Runnable _function = () -> { - Assert.assertFalse(this.batchCompiler.compile()); + final Runnable _function_1 = () -> { + Assert.assertFalse(this.batchCompiler.compile()); + }; + final LoggingTester.LogCapture providerLogs = LoggingTester.captureLogging(Level.ERROR, "org.eclipse.xtend.core.macro.ActiveAnnotationContextProvider", _function_1); + providerLogs.assertNumberOfLogEntries(1); }; final LoggingTester.LogCapture logs = LoggingTester.captureLogging(Level.ERROR, XtendBatchCompiler.class, _function); logs.assertNumberOfLogEntries(1); @@ -728,34 +730,19 @@ public void testNoSuppressWarningsAnnotations() { Assert.assertFalse(this.getContents((BatchCompilerTest.OUTPUT_DIRECTORY + "/XtendA.java")).contains("@SuppressWarnings")); } - @Test + @Test(expected = IllegalArgumentException.class) public void testJavaVersion5() { this.batchCompiler.setJavaSourceVersion("1.5"); - this.batchCompiler.setSourcePath("./batch-compiler-data/javaVersion"); - Assert.assertTrue(this.batchCompiler.compile()); - final String generated = this.getContents((BatchCompilerTest.OUTPUT_DIRECTORY + "/XtendA.java")); - Assert.assertFalse(generated.contains("@Override")); - Assert.assertTrue(generated.contains("new Function1")); } - @Test + @Test(expected = IllegalArgumentException.class) public void testJavaVersion6() { this.batchCompiler.setJavaSourceVersion("1.6"); - this.batchCompiler.setSourcePath("./batch-compiler-data/javaVersion"); - Assert.assertTrue(this.batchCompiler.compile()); - final String generated = this.getContents((BatchCompilerTest.OUTPUT_DIRECTORY + "/XtendA.java")); - Assert.assertTrue(generated.contains("@Override")); - Assert.assertTrue(generated.contains("new Function1")); } - @Test + @Test(expected = IllegalArgumentException.class) public void testJavaVersion7() { this.batchCompiler.setJavaSourceVersion("1.7"); - this.batchCompiler.setSourcePath("./batch-compiler-data/javaVersion"); - Assert.assertTrue(this.batchCompiler.compile()); - final String generated = this.getContents((BatchCompilerTest.OUTPUT_DIRECTORY + "/XtendA.java")); - Assert.assertTrue(generated.contains("@Override")); - Assert.assertTrue(generated.contains("new Function1")); } @Test diff --git a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/java8/Java8TypeProviderTest.java b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/java8/Java8TypeProviderTest.java index ebbd3ed90ee..e56bd46ec0d 100644 --- a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/java8/Java8TypeProviderTest.java +++ b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/java8/Java8TypeProviderTest.java @@ -12,29 +12,25 @@ import com.google.inject.Inject; import java.util.Objects; import org.eclipse.emf.ecore.EObject; +import org.eclipse.xtend.core.tests.AbstractXtendTestCase; import org.eclipse.xtend.core.xtend.XtendFile; import org.eclipse.xtend2.lib.StringConcatenation; import org.eclipse.xtext.common.types.JvmGenericType; import org.eclipse.xtext.common.types.JvmOperation; import org.eclipse.xtext.common.types.JvmType; import org.eclipse.xtext.common.types.access.IJvmTypeProvider; -import org.eclipse.xtext.testing.InjectWith; -import org.eclipse.xtext.testing.XtextRunner; import org.eclipse.xtext.testing.util.ParseHelper; import org.eclipse.xtext.xbase.lib.Exceptions; import org.eclipse.xtext.xbase.lib.Functions.Function1; import org.eclipse.xtext.xbase.lib.IterableExtensions; import org.junit.Assert; import org.junit.Test; -import org.junit.runner.RunWith; /** * @author koehnlein - Initial contribution and API */ -@RunWith(XtextRunner.class) -@InjectWith(Java8RuntimeInjectorProvider.class) @SuppressWarnings("all") -public class Java8TypeProviderTest { +public class Java8TypeProviderTest extends AbstractXtendTestCase { @Inject private IJvmTypeProvider.Factory typeProviderFactory; diff --git a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug342021Test.java b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug342021Test.java deleted file mode 100644 index 75f4a2b540c..00000000000 --- a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug342021Test.java +++ /dev/null @@ -1,2010 +0,0 @@ -/** - * Copyright (c) 2013, 2018 itemis AG (http://www.itemis.eu) and others. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.eclipse.xtend.core.tests.java8.compiler; - -import org.eclipse.xtend.core.tests.compiler.AbstractXtendCompilerTest; -import org.eclipse.xtend.core.tests.java8.Java8RuntimeInjectorProvider; -import org.eclipse.xtend2.lib.StringConcatenation; -import org.eclipse.xtext.testing.InjectWith; -import org.junit.Test; - -/** - * @author Sebastian Zarnekow - Initial contribution and API - * @author Miro Spoenemann - Copied and adapted to Java 8 output - */ -@InjectWith(Java8RuntimeInjectorProvider.class) -@SuppressWarnings("all") -public class CompilerBug342021Test extends AbstractXtendCompilerTest { - @Test - public void testIfExpression_01() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def Iterable m(String s) {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("if (true) "); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("[|newArrayList().iterator]"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("else"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("newArrayList(s).toArray"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Conversions;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public Iterable m(final String s) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Iterable _xifexpression = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (true) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Iterable _function = () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return CollectionLiterals.newArrayList().iterator();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_xifexpression = _function;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("} else {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_xifexpression = (Iterable)Conversions.doWrapArray(CollectionLiterals.newArrayList(s).toArray());"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return _xifexpression;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - public void testIfExpression_02() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def Iterable m() {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("return if (true) "); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("[|newArrayList().iterator]"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("else"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("newArrayList(\'\').toArray"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Conversions;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public Iterable m() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Iterable _xifexpression = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (true) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Iterable _function = () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return CollectionLiterals.newArrayList().iterator();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_xifexpression = _function;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("} else {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_xifexpression = (Iterable)Conversions.doWrapArray(CollectionLiterals.newArrayList(\"\").toArray());"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return _xifexpression;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - public void testIfExpression_03() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def Iterable m() {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("if (true) "); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("return [|newArrayList().iterator]"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("else"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("return newArrayList(\'\').toArray"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Conversions;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public Iterable m() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (true) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Iterable _function = () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return CollectionLiterals.newArrayList().iterator();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return _function;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("} else {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return (Iterable)Conversions.doWrapArray(CollectionLiterals.newArrayList(\"\").toArray());"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - public void testIfExpression_04() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def Iterable m() {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("if (true) "); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("return [|newArrayList().iterator]"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("else"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("newArrayList(\'\').toArray"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Conversions;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public Iterable m() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Object[] _xifexpression = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (true) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Iterable _function = () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return CollectionLiterals.newArrayList().iterator();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return _function;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("} else {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_xifexpression = CollectionLiterals.newArrayList(\"\").toArray();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return (Iterable)Conversions.doWrapArray(_xifexpression);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - public void testIfExpression_05() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def Iterable m() {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("if (true) "); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("[|newArrayList().iterator]"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("else"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("return newArrayList(\'\').toArray"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Conversions;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public Iterable m() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Iterable _xifexpression = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (true) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Iterable _function = () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return CollectionLiterals.newArrayList().iterator();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_xifexpression = _function;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("} else {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return (Iterable)Conversions.doWrapArray(CollectionLiterals.newArrayList(\"\").toArray());"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return _xifexpression;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - public void testIfExpression_06() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def Iterable m(String s) {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("if (true) "); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("{ [| { newArrayList().iterator } ] }"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("else"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("{ { newArrayList(s).toArray } }"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Conversions;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public Iterable m(final String s) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Iterable _xifexpression = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (true) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Iterable _function = () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return CollectionLiterals.newArrayList().iterator();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_xifexpression = _function;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("} else {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_xifexpression = (Iterable)Conversions.doWrapArray(CollectionLiterals.newArrayList(s).toArray());"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return _xifexpression;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - public void testIfExpression_07() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def Iterable m() {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("return { "); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("if (true) "); - _builder.newLine(); - _builder.append("\t\t\t\t"); - _builder.append("{ [|newArrayList().iterator] }"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("else"); - _builder.newLine(); - _builder.append("\t\t\t\t"); - _builder.append("{ newArrayList(\'\').toArray }"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Conversions;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public Iterable m() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Iterable _xifexpression = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (true) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Iterable _function = () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return CollectionLiterals.newArrayList().iterator();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_xifexpression = _function;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("} else {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_xifexpression = (Iterable)Conversions.doWrapArray(CollectionLiterals.newArrayList(\"\").toArray());"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return _xifexpression;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - public void testIfExpression_08() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def Iterable m() {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("{"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("if (true) "); - _builder.newLine(); - _builder.append("\t\t\t\t"); - _builder.append("{ return { [|newArrayList().iterator] } }"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("else"); - _builder.newLine(); - _builder.append("\t\t\t\t"); - _builder.append("{ return { { newArrayList(\'\') } .toArray } }"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Conversions;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public Iterable m() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (true) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Iterable _function = () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return CollectionLiterals.newArrayList().iterator();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return _function;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("} else {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return (Iterable)Conversions.doWrapArray(CollectionLiterals.newArrayList(\"\").toArray());"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - public void testIfExpression_09() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def Iterable m() {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("if (true) "); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("{ return { [|newArrayList().iterator] } }"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("else"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("{ newArrayList(\'\').toArray }"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Conversions;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public Iterable m() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Object[] _xifexpression = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (true) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Iterable _function = () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return CollectionLiterals.newArrayList().iterator();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return _function;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("} else {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_xifexpression = CollectionLiterals.newArrayList(\"\").toArray();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return (Iterable)Conversions.doWrapArray(_xifexpression);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - public void testIfExpression_10() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def Iterable m() {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("if (true) "); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("{ [|newArrayList().iterator] }"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("else"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("{ return newArrayList(\'\').toArray }"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Conversions;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public Iterable m() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Iterable _xifexpression = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (true) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Iterable _function = () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return CollectionLiterals.newArrayList().iterator();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_xifexpression = _function;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("} else {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return (Iterable)Conversions.doWrapArray(CollectionLiterals.newArrayList(\"\").toArray());"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return _xifexpression;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - public void testIfExpression_11() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def Iterable m(String s) {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("toString"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("if (true) {"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("toString;"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("[|newArrayList().iterator]"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("} else {"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("toString"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("newArrayList(s).toArray"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Conversions;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public Iterable m(final String s) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Iterable _xblockexpression = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("{"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("this.toString();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Iterable _xifexpression = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (true) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Iterable _xblockexpression_1 = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("{"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("this.toString();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Iterable _function = () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return CollectionLiterals.newArrayList().iterator();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_xblockexpression_1 = _function;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_xifexpression = _xblockexpression_1;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("} else {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Object[] _xblockexpression_2 = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("{"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("this.toString();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_xblockexpression_2 = CollectionLiterals.newArrayList(s).toArray();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_xifexpression = (Iterable)Conversions.doWrapArray(_xblockexpression_2);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_xblockexpression = _xifexpression;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return _xblockexpression;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - public void testIfExpression_12() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def Iterable m() {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("toString"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("return {"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("toString"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("if (true) {"); - _builder.newLine(); - _builder.append("\t\t\t\t"); - _builder.append("toString;"); - _builder.newLine(); - _builder.append("\t\t\t\t"); - _builder.append("[|newArrayList().iterator]"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("} else {"); - _builder.newLine(); - _builder.append("\t\t\t\t"); - _builder.append("toString"); - _builder.newLine(); - _builder.append("\t\t\t\t"); - _builder.append("newArrayList(\'\').toArray"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Conversions;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public Iterable m() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("this.toString();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Iterable _xblockexpression = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("{"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("this.toString();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Iterable _xifexpression = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (true) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Iterable _xblockexpression_1 = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("{"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("this.toString();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Iterable _function = () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return CollectionLiterals.newArrayList().iterator();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_xblockexpression_1 = _function;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_xifexpression = _xblockexpression_1;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("} else {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Object[] _xblockexpression_2 = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("{"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("this.toString();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_xblockexpression_2 = CollectionLiterals.newArrayList(\"\").toArray();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_xifexpression = (Iterable)Conversions.doWrapArray(_xblockexpression_2);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_xblockexpression = _xifexpression;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return _xblockexpression;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - public void testIfExpression_13() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def Iterable m() {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("toString"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("if (true) {"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("toString "); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("return [|newArrayList().iterator]"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("} else {"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("toString"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("return newArrayList(\'\').toArray"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Conversions;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public Iterable m() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("this.toString();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (true) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("this.toString();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Iterable _function = () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return CollectionLiterals.newArrayList().iterator();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return _function;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("} else {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("this.toString();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return (Iterable)Conversions.doWrapArray(CollectionLiterals.newArrayList(\"\").toArray());"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - public void testIfExpression_14() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def Iterable m() {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("toString"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("if (true) {"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("toString"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("return [|newArrayList().iterator]"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("} else {"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("toString"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("newArrayList(\'\').toArray"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Conversions;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public Iterable m() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Object[] _xblockexpression = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("{"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("this.toString();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Object[] _xifexpression = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (true) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("this.toString();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Iterable _function = () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return CollectionLiterals.newArrayList().iterator();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return _function;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("} else {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Object[] _xblockexpression_1 = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("{"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("this.toString();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_xblockexpression_1 = CollectionLiterals.newArrayList(\"\").toArray();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_xifexpression = _xblockexpression_1;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_xblockexpression = _xifexpression;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return (Iterable)Conversions.doWrapArray(_xblockexpression);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - public void testIfExpression_15() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def Iterable m() {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("{"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("toString"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("if (true) {"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("{"); - _builder.newLine(); - _builder.append("\t\t\t\t"); - _builder.append("toString"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("[|newArrayList().iterator]"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("} else {"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("{"); - _builder.newLine(); - _builder.append("\t\t\t\t"); - _builder.append("toString"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("return newArrayList(\'\').toArray"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Conversions;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public Iterable m() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Iterable _xblockexpression = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("{"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("this.toString();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Iterable _xifexpression = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (true) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Iterable _xblockexpression_1 = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("{"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("this.toString();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Iterable _function = () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return CollectionLiterals.newArrayList().iterator();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_xblockexpression_1 = _function;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_xifexpression = _xblockexpression_1;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("} else {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("this.toString();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return (Iterable)Conversions.doWrapArray(CollectionLiterals.newArrayList(\"\").toArray());"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_xblockexpression = _xifexpression;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return _xblockexpression;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - public void testSwitchExpression_01() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append(" "); - _builder.append("def Iterable m(Object o) {"); - _builder.newLine(); - _builder.append("\t "); - _builder.append("switch o {"); - _builder.newLine(); - _builder.append("\t "); - _builder.append("Boolean: [|newArrayList().iterator]"); - _builder.newLine(); - _builder.append("\t \t"); - _builder.append("default: newArrayList(\'\').toArray"); - _builder.newLine(); - _builder.append("\t "); - _builder.append("}"); - _builder.newLine(); - _builder.append(" "); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Conversions;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public Iterable m(final Object o) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Iterable _switchResult = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("boolean _matched = false;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (o instanceof Boolean) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_matched=true;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Iterable _function = () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return CollectionLiterals.newArrayList().iterator();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_switchResult = _function;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (!_matched) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_switchResult = (Iterable)Conversions.doWrapArray(CollectionLiterals.newArrayList(\"\").toArray());"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return _switchResult;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - public void testSwitchExpression_02() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append(" "); - _builder.append("def Iterable m(Object o) {"); - _builder.newLine(); - _builder.append("\t "); - _builder.append("switch o {"); - _builder.newLine(); - _builder.append("\t "); - _builder.append("Boolean: [|newArrayList().iterator]"); - _builder.newLine(); - _builder.append("\t \t"); - _builder.append("String: return newArrayList(\'\').toArray"); - _builder.newLine(); - _builder.append("\t "); - _builder.append("}"); - _builder.newLine(); - _builder.append(" "); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Conversions;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public Iterable m(final Object o) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Iterable _switchResult = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("boolean _matched = false;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (o instanceof Boolean) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_matched=true;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Iterable _function = () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return CollectionLiterals.newArrayList().iterator();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_switchResult = _function;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (!_matched) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (o instanceof String) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_matched=true;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return (Iterable)Conversions.doWrapArray(CollectionLiterals.newArrayList(\"\").toArray());"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return _switchResult;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - public void testSwitchExpression_03() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append(" "); - _builder.append("def Iterable m(Object o) {"); - _builder.newLine(); - _builder.append("\t "); - _builder.append("return switch o {"); - _builder.newLine(); - _builder.append("\t "); - _builder.append("Boolean: [|newArrayList().iterator]"); - _builder.newLine(); - _builder.append("\t \t"); - _builder.append("String: newArrayList(\'\').toArray"); - _builder.newLine(); - _builder.append("\t \t"); - _builder.append("default: null"); - _builder.newLine(); - _builder.append("\t "); - _builder.append("}"); - _builder.newLine(); - _builder.append(" "); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Conversions;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public Iterable m(final Object o) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Iterable _switchResult = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("boolean _matched = false;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (o instanceof Boolean) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_matched=true;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Iterable _function = () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return CollectionLiterals.newArrayList().iterator();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_switchResult = _function;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (!_matched) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (o instanceof String) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_matched=true;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_switchResult = (Iterable)Conversions.doWrapArray(CollectionLiterals.newArrayList(\"\").toArray());"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (!_matched) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_switchResult = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return _switchResult;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - public void testSwitchExpression_04() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append(" "); - _builder.append("def Iterable m(Object o) {"); - _builder.newLine(); - _builder.append("\t "); - _builder.append("return switch o {"); - _builder.newLine(); - _builder.append("\t "); - _builder.append("Boolean: return [|newArrayList().iterator]"); - _builder.newLine(); - _builder.append("\t \t"); - _builder.append("String: newArrayList(\'\').toArray"); - _builder.newLine(); - _builder.append("\t \t"); - _builder.append("default: emptyList"); - _builder.newLine(); - _builder.append("\t "); - _builder.append("}"); - _builder.newLine(); - _builder.append(" "); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Conversions;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public Iterable m(final Object o) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Iterable _switchResult = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("boolean _matched = false;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (o instanceof Boolean) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_matched=true;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Iterable _function = () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return CollectionLiterals.newArrayList().iterator();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return _function;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (!_matched) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (o instanceof String) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_matched=true;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_switchResult = (Iterable)Conversions.doWrapArray(CollectionLiterals.newArrayList(\"\").toArray());"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (!_matched) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_switchResult = CollectionLiterals.emptyList();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return _switchResult;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - public void testTryCatchExpression_01() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append(" "); - _builder.append("def Iterable m(Object o) {"); - _builder.newLine(); - _builder.append("\t "); - _builder.append("try {"); - _builder.newLine(); - _builder.append("\t \t"); - _builder.append("[|newArrayList().iterator]"); - _builder.newLine(); - _builder.append("\t "); - _builder.append("} catch(Exception e) {"); - _builder.newLine(); - _builder.append("\t \t"); - _builder.append("newArrayList(\'\').toArray"); - _builder.newLine(); - _builder.append("\t "); - _builder.append("}"); - _builder.newLine(); - _builder.append(" "); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Conversions;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Exceptions;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public Iterable m(final Object o) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Iterable _xtrycatchfinallyexpression = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("try {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Iterable _function = () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return CollectionLiterals.newArrayList().iterator();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_xtrycatchfinallyexpression = _function;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("} catch (final Throwable _t) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (_t instanceof Exception) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_xtrycatchfinallyexpression = (Iterable)Conversions.doWrapArray(CollectionLiterals.newArrayList(\"\").toArray());"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("} else {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("throw Exceptions.sneakyThrow(_t);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return _xtrycatchfinallyexpression;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - public void testNestedIfInSwitchExpression_01() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append(" "); - _builder.append("def Iterable m(Object o, boolean b) {"); - _builder.newLine(); - _builder.append("\t "); - _builder.append("switch o {"); - _builder.newLine(); - _builder.append("\t "); - _builder.append("Boolean: [|newArrayList().iterator]"); - _builder.newLine(); - _builder.append("\t \t"); - _builder.append("default: {"); - _builder.newLine(); - _builder.append("\t \t\t"); - _builder.append("if (b)"); - _builder.newLine(); - _builder.append("\t \t\t\t"); - _builder.append("return newArrayList(\'\').toArray"); - _builder.newLine(); - _builder.append("\t \t\t"); - _builder.append("else"); - _builder.newLine(); - _builder.append("\t \t\t\t"); - _builder.append("return #{}"); - _builder.newLine(); - _builder.append("\t \t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t "); - _builder.append("}"); - _builder.newLine(); - _builder.append(" "); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.Collections;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Conversions;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public Iterable m(final Object o, final boolean b) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Iterable _switchResult = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("boolean _matched = false;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (o instanceof Boolean) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_matched=true;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Iterable _function = () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return CollectionLiterals.newArrayList().iterator();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_switchResult = _function;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (!_matched) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (b) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return (Iterable)Conversions.doWrapArray(CollectionLiterals.newArrayList(\"\").toArray());"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("} else {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return Collections.unmodifiableSet(CollectionLiterals.newHashSet());"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return _switchResult;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } -} diff --git a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug383534Test.java b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug383534Test.java deleted file mode 100644 index 888ba688446..00000000000 --- a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug383534Test.java +++ /dev/null @@ -1,389 +0,0 @@ -/** - * Copyright (c) 2014, 2016 itemis AG (http://www.itemis.eu) and others. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.eclipse.xtend.core.tests.java8.compiler; - -import org.eclipse.xtend.core.tests.compiler.AbstractXtendCompilerTest; -import org.eclipse.xtend.core.tests.java8.Java8RuntimeInjectorProvider; -import org.eclipse.xtend2.lib.StringConcatenation; -import org.eclipse.xtext.testing.InjectWith; -import org.junit.Test; - -/** - * @author Sebastian Zarnekow - Initial contribution and API - * @author Miro Spoenemann - Copied and adapted to Java 8 output - */ -@InjectWith(Java8RuntimeInjectorProvider.class) -@SuppressWarnings("all") -public class CompilerBug383534Test extends AbstractXtendCompilerTest { - @Test - public void test_01() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def void m() {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("val (String,String)=>String strAdd = [s1,s2 | s1+s2]"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("val /*(String)=>String*/ curriedStrAdd = strAdd.curry(\'x\') // ok"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("println(strAdd.apply(\'x\', \'y\')) // result: \'xy\'"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("println(curriedStrAdd.apply(\'y\')) // result: \'xy\'"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("val (String,String[])=>String strAdd2 = [s1,s2 | s1 + s2.reduce[x1,x2 | x1+x2]]"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("val /*(String)=>String*/ curriedStrAdd2 = strAdd2.curry(\'x\') // fail"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("println(strAdd2.apply(\'x\', newArrayList(\'y\', \'z\'))) // result: \'xyz\'"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("println(curriedStrAdd2.apply(newArrayList(\'y\', \'z\'))) // should result in \'xyz\'"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Conversions;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.FunctionExtensions;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function1;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function2;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.InputOutput;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.IterableExtensions;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void m() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function2 _function = (String s1, String s2) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return (s1 + s2);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function2 strAdd = _function;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function1 curriedStrAdd = FunctionExtensions.curry(strAdd, \"x\");"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("InputOutput.println(strAdd.apply(\"x\", \"y\"));"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("InputOutput.println(curriedStrAdd.apply(\"y\"));"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function2 _function_1 = (String s1, String[] s2) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function2 _function_2 = (String x1, String x2) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return (x1 + x2);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("String _reduce = IterableExtensions.reduce(((Iterable)Conversions.doWrapArray(s2)), _function_2);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return (s1 + _reduce);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function2 strAdd2 = _function_1;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function1 curriedStrAdd2 = FunctionExtensions.curry(strAdd2, \"x\");"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("InputOutput.println(strAdd2.apply(\"x\", ((String[])Conversions.unwrapArray(CollectionLiterals.newArrayList(\"y\", \"z\"), String.class))));"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("InputOutput.println(curriedStrAdd2.apply(((String[])Conversions.unwrapArray(CollectionLiterals.newArrayList(\"y\", \"z\"), String.class))));"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - public void test_02() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def void m() {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("val (String,String)=>String strAdd = [s1,s2 | s1+s2]"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("val curriedStrAdd = strAdd.curry(\'x\')"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("println(strAdd.apply(\'x\', \'y\')) // result: \'xy\'"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("println(curriedStrAdd.apply(\'y\')) // result: \'xy\'"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.FunctionExtensions;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function1;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function2;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.InputOutput;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void m() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function2 _function = (String s1, String s2) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return (s1 + s2);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function2 strAdd = _function;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function1 curriedStrAdd = FunctionExtensions.curry(strAdd, \"x\");"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("InputOutput.println(strAdd.apply(\"x\", \"y\"));"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("InputOutput.println(curriedStrAdd.apply(\"y\"));"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - public void test_03() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def void m() {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("val (String,String[])=>String strAdd = [s1,s2 | s1+s2.head]"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("val curriedStrAdd = strAdd.curry(\'x\')"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("println(strAdd.apply(\'x\', newArrayList(\'y\', \'z\')))"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("println(curriedStrAdd.apply(newArrayList(\'y\', \'z\')))"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Conversions;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.FunctionExtensions;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function1;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function2;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.InputOutput;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.IterableExtensions;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void m() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function2 _function = (String s1, String[] s2) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("String _head = IterableExtensions.head(((Iterable)Conversions.doWrapArray(s2)));"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return (s1 + _head);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function2 strAdd = _function;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function1 curriedStrAdd = FunctionExtensions.curry(strAdd, \"x\");"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("InputOutput.println(strAdd.apply(\"x\", ((String[])Conversions.unwrapArray(CollectionLiterals.newArrayList(\"y\", \"z\"), String.class))));"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("InputOutput.println(curriedStrAdd.apply(((String[])Conversions.unwrapArray(CollectionLiterals.newArrayList(\"y\", \"z\"), String.class))));"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - public void test_04() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def void m() {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("val (String,String[])=>String strAdd = [s1,s2 | s1+s2.reduce[x1,x2 | x1+x2]]"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("val curriedStrAdd = strAdd.curry(\'x\')"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("println(strAdd.apply(\'x\', #[\'y\'])) // result: \'xy\'"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("println(curriedStrAdd.apply(#[\'y\'])) // result: \'xy\'"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Conversions;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.FunctionExtensions;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function1;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function2;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.InputOutput;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.IterableExtensions;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void m() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function2 _function = (String s1, String[] s2) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function2 _function_1 = (String x1, String x2) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return (x1 + x2);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("String _reduce = IterableExtensions.reduce(((Iterable)Conversions.doWrapArray(s2)), _function_1);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return (s1 + _reduce);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function2 strAdd = _function;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function1 curriedStrAdd = FunctionExtensions.curry(strAdd, \"x\");"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("InputOutput.println(strAdd.apply(\"x\", new String[] { \"y\" }));"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("InputOutput.println(curriedStrAdd.apply(new String[] { \"y\" }));"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } -} diff --git a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug404051Test.java b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug404051Test.java deleted file mode 100644 index c65f89836cf..00000000000 --- a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug404051Test.java +++ /dev/null @@ -1,507 +0,0 @@ -/** - * Copyright (c) 2013, 2016 itemis AG (http://www.itemis.eu) and others. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.eclipse.xtend.core.tests.java8.compiler; - -import org.eclipse.xtend.core.tests.compiler.AbstractXtendCompilerTest; -import org.eclipse.xtend.core.tests.compiler.CompilerBugTest; -import org.eclipse.xtend.core.tests.java8.Java8RuntimeInjectorProvider; -import org.eclipse.xtend2.lib.StringConcatenation; -import org.eclipse.xtext.testing.InjectWith; -import org.junit.Test; - -/** - * @author Sebastian Zarnekow - Initial contribution and API - * @author Miro Spoenemann - Copied and adapted to Java 8 output - * @see CompilerBugTest#testBug404051_01 and friends - */ -@InjectWith(Java8RuntimeInjectorProvider.class) -@SuppressWarnings("all") -public class CompilerBug404051Test extends AbstractXtendCompilerTest { - @Test - public void test_01() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def m(Iterable iterable) {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("iterable.flatMap[].sortBy [ hashCode ]"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def Iterable flatMap(Iterable iterable, (A)=>B map) {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("return null"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.List;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function1;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.IterableExtensions;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public List m(final Iterable iterable) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function1 _function = (String it) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function1 _function_1 = (Object it) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return Integer.valueOf(it.hashCode());"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return IterableExtensions.sortBy(this.flatMap(iterable, _function), _function_1);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public Iterable flatMap(final Iterable iterable, final Function1 map) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - public void test_02() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def m(Iterable iterable) {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("iterable.flatMap[].sortBy [ hashCode ]"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def Iterable flatMap(Iterable iterable, (A)=>B map) {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("return null"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.List;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function1;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.IterableExtensions;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public List m(final Iterable iterable) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function1 _function = (String it) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function1 _function_1 = (Object it) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return Integer.valueOf(it.hashCode());"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return IterableExtensions.sortBy(this.flatMap(iterable, _function), _function_1);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public Iterable flatMap(final Iterable iterable, final Function1 map) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - public void test_03() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def m(Iterable iterable) {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("iterable.flatMap[].sortBy [ intValue ]"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def Iterable flatMap(Iterable iterable, (A)=>B map) {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("return null"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.List;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function1;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.IterableExtensions;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public List m(final Iterable iterable) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function1 _function = (String it) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function1 _function_1 = (Number it) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return Integer.valueOf(it.intValue());"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return IterableExtensions.sortBy(this.flatMap(iterable, _function), _function_1);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public Iterable flatMap(final Iterable iterable, final Function1 map) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - public void test_04() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def m() {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("#[].flatMap[ length ].sortBy [ intValue ]"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def Iterable flatMap(Iterable iterable, (A)=>B map) {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("return null"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.Collections;"); - _builder_1.newLine(); - _builder_1.append("import java.util.List;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function1;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.IterableExtensions;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public List m() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function1 _function = (String it) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return Integer.valueOf(it.length());"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function1 _function_1 = (Integer it) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return Integer.valueOf(it.intValue());"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return IterableExtensions.sortBy(this.flatMap(Collections.unmodifiableList(CollectionLiterals.newArrayList()), _function), _function_1);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public Iterable flatMap(final Iterable iterable, final Function1 map) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - public void test_05() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def m() {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("#[].flatMap[].sortBy [ intValue ]"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def Iterable flatMap(Iterable iterable, (A)=>B map) {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("return null"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.Collections;"); - _builder_1.newLine(); - _builder_1.append("import java.util.List;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function1;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.IterableExtensions;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public List m() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function1 _function = (String it) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function1 _function_1 = (Number it) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return Integer.valueOf(it.intValue());"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return IterableExtensions.sortBy(this.flatMap(Collections.unmodifiableList(CollectionLiterals.newArrayList()), _function), _function_1);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public Iterable flatMap(final Iterable iterable, final Function1 map) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - public void test_06() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def m(Iterable iterable) {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("iterable.flatMap[].sortBy [ length ]"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def Iterable flatMap(Iterable iterable, (A)=>B map) {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("return null"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.List;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function1;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.IterableExtensions;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public List m(final Iterable iterable) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function1 _function = (String it) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function1 _function_1 = (String it) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return Integer.valueOf(it.length());"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return IterableExtensions.sortBy(this.flatMap(iterable, _function), _function_1);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public Iterable flatMap(final Iterable iterable, final Function1 map) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } -} diff --git a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug405825Test.java b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug405825Test.java deleted file mode 100644 index 22e96256bfa..00000000000 --- a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug405825Test.java +++ /dev/null @@ -1,217 +0,0 @@ -/** - * Copyright (c) 2013, 2016 itemis AG (http://www.itemis.eu) and others. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.eclipse.xtend.core.tests.java8.compiler; - -import org.eclipse.xtend.core.tests.compiler.AbstractXtendCompilerTest; -import org.eclipse.xtend.core.tests.java8.Java8RuntimeInjectorProvider; -import org.eclipse.xtend2.lib.StringConcatenation; -import org.eclipse.xtext.testing.InjectWith; -import org.junit.Test; - -/** - * @author Sebastian Zarnekow - Initial contribution and API - * @author Miro Spoenemann - Copied and adapted to Java 8 output - */ -@InjectWith(Java8RuntimeInjectorProvider.class) -@SuppressWarnings("all") -public class CompilerBug405825Test extends AbstractXtendCompilerTest { - @Test - public void testBug405825_01() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("class Test {"); - _builder.newLine(); - _builder.append(" "); - _builder.append("def static void test(Bound b) {"); - _builder.newLine(); - _builder.append(" "); - _builder.append("}"); - _builder.newLine(); - _builder.append(" "); - _builder.append("def static void main() {"); - _builder.newLine(); - _builder.append(" "); - _builder.append("test ["); - _builder.newLine(); - _builder.append(" "); - _builder.append("]"); - _builder.newLine(); - _builder.append(" "); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - _builder.append("interface Bound {"); - _builder.newLine(); - _builder.append(" "); - _builder.append("def void method(T t);"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class Test {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public static void test(final Bound b) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public static void main() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Bound _function = (Number it) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Test.test(_function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - public void testBug405825_02() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("class Test {"); - _builder.newLine(); - _builder.append(" "); - _builder.append("def static void test(Bound b) {"); - _builder.newLine(); - _builder.append(" "); - _builder.append("}"); - _builder.newLine(); - _builder.append(" "); - _builder.append("def static void main() {"); - _builder.newLine(); - _builder.append(" "); - _builder.append("test ["); - _builder.newLine(); - _builder.append(" "); - _builder.append("]"); - _builder.newLine(); - _builder.append(" "); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - _builder.append("interface Bound {"); - _builder.newLine(); - _builder.append(" "); - _builder.append("def void method(T t);"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class Test {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public static void test(final Bound b) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public static void main() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Bound _function = (Integer it) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Test.test(_function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - public void testBug405825_03() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("class Test {"); - _builder.newLine(); - _builder.append(" "); - _builder.append("def static void test(Sub b) {"); - _builder.newLine(); - _builder.append(" "); - _builder.append("}"); - _builder.newLine(); - _builder.append(" "); - _builder.append("def static void main() {"); - _builder.newLine(); - _builder.append(" "); - _builder.append("test ["); - _builder.newLine(); - _builder.append(" "); - _builder.append("]"); - _builder.newLine(); - _builder.append(" "); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - _builder.append("interface Bound {"); - _builder.newLine(); - _builder.append(" "); - _builder.append("def void method(T t);"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - _builder.append("interface Sub extends Bound {}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class Test {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public static void test(final Sub b) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public static void main() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Sub _function = (Number it) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Test.test(_function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } -} diff --git a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug406425Test.java b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug406425Test.java deleted file mode 100644 index 203b97c70ba..00000000000 --- a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug406425Test.java +++ /dev/null @@ -1,1028 +0,0 @@ -/** - * Copyright (c) 2013, 2016 itemis AG (http://www.itemis.eu) and others. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.eclipse.xtend.core.tests.java8.compiler; - -import org.eclipse.xtend.core.tests.java8.Java8RuntimeInjectorProvider; -import org.eclipse.xtend2.lib.StringConcatenation; -import org.eclipse.xtext.testing.InjectWith; -import org.junit.Test; - -/** - * @author Sebastian Zarnekow - Initial contribution and API - * @author Miro Spoenemann - Copied and adapted to Java 8 output - */ -@InjectWith(Java8RuntimeInjectorProvider.class) -@SuppressWarnings("all") -public class CompilerBug406425Test extends org.eclipse.xtend.core.tests.compiler.CompilerBug406425Test { - @Test - @Override - public void testBug406425_01() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import static org.hamcrest.core.Is.*"); - _builder.newLine(); - _builder.append("import static org.junit.Assert.*"); - _builder.newLine(); - _builder.append("import org.hamcrest.Matcher"); - _builder.newLine(); - _builder.append("class Test {"); - _builder.newLine(); - _builder.append(" "); - _builder.append("def test() {"); - _builder.newLine(); - _builder.append(" "); - _builder.append("new MyEntity => ["); - _builder.newLine(); - _builder.append(" "); - _builder.append("assertThat(it, nullValue)"); - _builder.newLine(); - _builder.append(" "); - _builder.append("assertThat(it.name, is(\"\"))"); - _builder.newLine(); - _builder.append(" "); - _builder.append("]"); - _builder.newLine(); - _builder.append(" "); - _builder.append("}"); - _builder.newLine(); - _builder.append(" "); - _builder.append("def static Matcher nullValue() {}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - _builder.append("class MyEntity {"); - _builder.newLine(); - _builder.append(" "); - _builder.append("@Property String name"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.ObjectExtensions;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;"); - _builder_1.newLine(); - _builder_1.append("import org.hamcrest.Matcher;"); - _builder_1.newLine(); - _builder_1.append("import org.hamcrest.core.Is;"); - _builder_1.newLine(); - _builder_1.append("import org.junit.Assert;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class Test {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public MyEntity test() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("MyEntity _myEntity = new MyEntity();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Procedure1 _function = (MyEntity it) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Assert.assertThat(it, Test.nullValue());"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Assert.assertThat(it.getName(), Is.is(\"\"));"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return ObjectExtensions.operator_doubleArrow(_myEntity, _function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public static Matcher nullValue() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void testBug406425_02() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import org.eclipse.xtend.core.tests.java8.compiler.StringBuilderLike"); - _builder.newLine(); - _builder.append("class Test {"); - _builder.newLine(); - _builder.append(" "); - _builder.append("def m(T a, T b){}"); - _builder.newLine(); - _builder.newLine(); - _builder.append(" "); - _builder.append("static def m() {"); - _builder.newLine(); - _builder.append(" "); - _builder.append("new StringBuilderLike => ["); - _builder.newLine(); - _builder.append(" "); - _builder.append("new Test().m(it, new Long(0))"); - _builder.newLine(); - _builder.append(" "); - _builder.append("println(length)"); - _builder.newLine(); - _builder.append(" "); - _builder.append("]"); - _builder.newLine(); - _builder.append(" "); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.io.Serializable;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtend.core.tests.java8.compiler.StringBuilderLike;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.InputOutput;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.ObjectExtensions;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class Test {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public Object m(final T a, final T b) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public static StringBuilderLike m() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("StringBuilderLike _stringBuilderLike = new StringBuilderLike();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Procedure1 _function = (StringBuilderLike it) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Test _test = new Test();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Long _long = new Long(0);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_test.m(it, _long);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("InputOutput.println(Integer.valueOf(it.length()));"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return ObjectExtensions.operator_doubleArrow(_stringBuilderLike, _function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void testBug406425_03() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import org.eclipse.xtend.core.tests.java8.compiler.StringBuilderLike"); - _builder.newLine(); - _builder.append("class Test {"); - _builder.newLine(); - _builder.append(" "); - _builder.append("def m(T a, T b){}"); - _builder.newLine(); - _builder.newLine(); - _builder.append(" "); - _builder.append("def m() {"); - _builder.newLine(); - _builder.append(" "); - _builder.append("new StringBuilderLike => ["); - _builder.newLine(); - _builder.append(" "); - _builder.append("m(it, new Long(0))"); - _builder.newLine(); - _builder.append(" "); - _builder.append("println(length)"); - _builder.newLine(); - _builder.append(" "); - _builder.append("]"); - _builder.newLine(); - _builder.append(" "); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.io.Serializable;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtend.core.tests.java8.compiler.StringBuilderLike;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.InputOutput;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.ObjectExtensions;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class Test {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public Object m(final T a, final T b) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public StringBuilderLike m() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("StringBuilderLike _stringBuilderLike = new StringBuilderLike();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Procedure1 _function = (StringBuilderLike it) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Long _long = new Long(0);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("this.m(it, _long);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("InputOutput.println(Integer.valueOf(it.length()));"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return ObjectExtensions.operator_doubleArrow(_stringBuilderLike, _function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void testBug406425_04() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import org.eclipse.xtend.core.tests.java8.compiler.StringBuilderLike"); - _builder.newLine(); - _builder.append("class Test {"); - _builder.newLine(); - _builder.append(" "); - _builder.append("def m(T a, T b){}"); - _builder.newLine(); - _builder.newLine(); - _builder.append(" "); - _builder.append("def m() {"); - _builder.newLine(); - _builder.append(" "); - _builder.append("new StringBuilderLike => ["); - _builder.newLine(); - _builder.append(" "); - _builder.append("it.m(new Long(0))"); - _builder.newLine(); - _builder.append(" "); - _builder.append("println(length)"); - _builder.newLine(); - _builder.append(" "); - _builder.append("]"); - _builder.newLine(); - _builder.append(" "); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.io.Serializable;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtend.core.tests.java8.compiler.StringBuilderLike;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.InputOutput;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.ObjectExtensions;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class Test {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public Object m(final T a, final T b) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public StringBuilderLike m() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("StringBuilderLike _stringBuilderLike = new StringBuilderLike();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Procedure1 _function = (StringBuilderLike it) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Long _long = new Long(0);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("this.m(it, _long);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("InputOutput.println(Integer.valueOf(it.length()));"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return ObjectExtensions.operator_doubleArrow(_stringBuilderLike, _function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void testBug406425_05() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import org.eclipse.xtend.core.tests.java8.compiler.StringBuilderLike"); - _builder.newLine(); - _builder.append("class Test {"); - _builder.newLine(); - _builder.append(" "); - _builder.append("def m(T a, T b){}"); - _builder.newLine(); - _builder.newLine(); - _builder.append(" "); - _builder.append("def m() {"); - _builder.newLine(); - _builder.append(" "); - _builder.append("new StringBuilderLike => ["); - _builder.newLine(); - _builder.append(" "); - _builder.append("m(new Long(0))"); - _builder.newLine(); - _builder.append(" "); - _builder.append("println(length)"); - _builder.newLine(); - _builder.append(" "); - _builder.append("]"); - _builder.newLine(); - _builder.append(" "); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.io.Serializable;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtend.core.tests.java8.compiler.StringBuilderLike;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.InputOutput;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.ObjectExtensions;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class Test {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public Object m(final T a, final T b) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public StringBuilderLike m() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("StringBuilderLike _stringBuilderLike = new StringBuilderLike();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Procedure1 _function = (StringBuilderLike it) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Long _long = new Long(0);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("this.m(it, _long);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("InputOutput.println(Integer.valueOf(it.length()));"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return ObjectExtensions.operator_doubleArrow(_stringBuilderLike, _function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void testBug406425_06() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import org.eclipse.xtend.core.tests.java8.compiler.StringBuilderLike"); - _builder.newLine(); - _builder.append("class Test {"); - _builder.newLine(); - _builder.append(" "); - _builder.append("def m(T a, T b){}"); - _builder.newLine(); - _builder.newLine(); - _builder.append(" "); - _builder.append("def m() {"); - _builder.newLine(); - _builder.append(" "); - _builder.append("newArrayList(new StringBuilderLike).forEach ["); - _builder.newLine(); - _builder.append(" "); - _builder.append("m(it, new Long(0))"); - _builder.newLine(); - _builder.append(" "); - _builder.append("println(length)"); - _builder.newLine(); - _builder.append(" "); - _builder.append("]"); - _builder.newLine(); - _builder.append(" "); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.io.Serializable;"); - _builder_1.newLine(); - _builder_1.append("import java.util.function.Consumer;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtend.core.tests.java8.compiler.StringBuilderLike;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.InputOutput;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class Test {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public Object m(final T a, final T b) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void m() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("StringBuilderLike _stringBuilderLike = new StringBuilderLike();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Consumer _function = (StringBuilderLike it) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Long _long = new Long(0);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("this.m(it, _long);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("InputOutput.println(Integer.valueOf(it.length()));"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("CollectionLiterals.newArrayList(_stringBuilderLike).forEach(_function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void testBug406425_07() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import org.eclipse.xtend.core.tests.java8.compiler.StringBuilderLike"); - _builder.newLine(); - _builder.append("class Test {"); - _builder.newLine(); - _builder.append(" "); - _builder.append("def static m(T a, T b){}"); - _builder.newLine(); - _builder.newLine(); - _builder.append(" "); - _builder.append("def m() {"); - _builder.newLine(); - _builder.append(" "); - _builder.append("new StringBuilderLike => ["); - _builder.newLine(); - _builder.append(" "); - _builder.append("m(it, new Long(0))"); - _builder.newLine(); - _builder.append(" "); - _builder.append("println(length)"); - _builder.newLine(); - _builder.append(" "); - _builder.append("]"); - _builder.newLine(); - _builder.append(" "); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.io.Serializable;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtend.core.tests.java8.compiler.StringBuilderLike;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.InputOutput;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.ObjectExtensions;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class Test {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public static Object m(final T a, final T b) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public StringBuilderLike m() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("StringBuilderLike _stringBuilderLike = new StringBuilderLike();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Procedure1 _function = (StringBuilderLike it) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Long _long = new Long(0);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Test.m(it, _long);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("InputOutput.println(Integer.valueOf(it.length()));"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return ObjectExtensions.operator_doubleArrow(_stringBuilderLike, _function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void testBug406425_08() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import org.eclipse.xtend.core.tests.java8.compiler.StringBuilderLike"); - _builder.newLine(); - _builder.append("class Test {"); - _builder.newLine(); - _builder.append(" "); - _builder.append("def static m(T a, T b){}"); - _builder.newLine(); - _builder.newLine(); - _builder.append(" "); - _builder.append("def static m() {"); - _builder.newLine(); - _builder.append(" "); - _builder.append("new StringBuilderLike => ["); - _builder.newLine(); - _builder.append(" "); - _builder.append("m(it, new Long(0))"); - _builder.newLine(); - _builder.append(" "); - _builder.append("println(length)"); - _builder.newLine(); - _builder.append(" "); - _builder.append("]"); - _builder.newLine(); - _builder.append(" "); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.io.Serializable;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtend.core.tests.java8.compiler.StringBuilderLike;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.InputOutput;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.ObjectExtensions;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class Test {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public static Object m(final T a, final T b) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public static StringBuilderLike m() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("StringBuilderLike _stringBuilderLike = new StringBuilderLike();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Procedure1 _function = (StringBuilderLike it) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Long _long = new Long(0);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Test.m(it, _long);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("InputOutput.println(Integer.valueOf(it.length()));"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return ObjectExtensions.operator_doubleArrow(_stringBuilderLike, _function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void testBug406425_09() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import org.eclipse.xtend.core.tests.java8.compiler.StringBuilderLike"); - _builder.newLine(); - _builder.append("class Test {"); - _builder.newLine(); - _builder.append(" "); - _builder.append("def m(T a, T b){}"); - _builder.newLine(); - _builder.newLine(); - _builder.append(" "); - _builder.append("static def m() {"); - _builder.newLine(); - _builder.append(" "); - _builder.append("newArrayList(new StringBuilderLike).forEach ["); - _builder.newLine(); - _builder.append(" "); - _builder.append("new Test().m(it, new Long(0))"); - _builder.newLine(); - _builder.append(" "); - _builder.append("println(length)"); - _builder.newLine(); - _builder.append(" "); - _builder.append("]"); - _builder.newLine(); - _builder.append(" "); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.io.Serializable;"); - _builder_1.newLine(); - _builder_1.append("import java.util.function.Consumer;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtend.core.tests.java8.compiler.StringBuilderLike;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.InputOutput;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class Test {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public Object m(final T a, final T b) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public static void m() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("StringBuilderLike _stringBuilderLike = new StringBuilderLike();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Consumer _function = (StringBuilderLike it) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Test _test = new Test();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Long _long = new Long(0);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_test.m(it, _long);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("InputOutput.println(Integer.valueOf(it.length()));"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("CollectionLiterals.newArrayList(_stringBuilderLike).forEach(_function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void testBug406425_10() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import org.eclipse.xtend.core.tests.java8.compiler.StringBuilderLike"); - _builder.newLine(); - _builder.append("class Test {"); - _builder.newLine(); - _builder.append(" "); - _builder.append("def m(T a, T b){}"); - _builder.newLine(); - _builder.newLine(); - _builder.append(" "); - _builder.append("static def m() {"); - _builder.newLine(); - _builder.append(" "); - _builder.append("newArrayList(new StringBuilderLike).forEach ["); - _builder.newLine(); - _builder.append(" "); - _builder.append("new Test().m(it, new Long(0))"); - _builder.newLine(); - _builder.append(" "); - _builder.append("println(length)"); - _builder.newLine(); - _builder.append(" "); - _builder.append("]"); - _builder.newLine(); - _builder.append(" "); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.io.Serializable;"); - _builder_1.newLine(); - _builder_1.append("import java.util.function.Consumer;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtend.core.tests.java8.compiler.StringBuilderLike;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.InputOutput;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class Test {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public Object m(final T a, final T b) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public static void m() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("StringBuilderLike _stringBuilderLike = new StringBuilderLike();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Consumer _function = (StringBuilderLike it) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Test _test = new Test();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Long _long = new Long(0);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_test.m(it, _long);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("InputOutput.println(Integer.valueOf(it.length()));"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("CollectionLiterals.newArrayList(_stringBuilderLike).forEach(_function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void testBug406425_11() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import org.eclipse.xtend.core.tests.java8.compiler.StringBuilderLike"); - _builder.newLine(); - _builder.append("class Test {"); - _builder.newLine(); - _builder.append(" "); - _builder.append("static def m(T a, T b){}"); - _builder.newLine(); - _builder.newLine(); - _builder.append(" "); - _builder.append("static def m() {"); - _builder.newLine(); - _builder.append(" "); - _builder.append("newArrayList(new StringBuilderLike).forEach ["); - _builder.newLine(); - _builder.append(" "); - _builder.append("m(it, new Long(0))"); - _builder.newLine(); - _builder.append(" "); - _builder.append("println(length)"); - _builder.newLine(); - _builder.append(" "); - _builder.append("]"); - _builder.newLine(); - _builder.append(" "); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.io.Serializable;"); - _builder_1.newLine(); - _builder_1.append("import java.util.function.Consumer;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtend.core.tests.java8.compiler.StringBuilderLike;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.InputOutput;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class Test {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public static Object m(final T a, final T b) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public static void m() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("StringBuilderLike _stringBuilderLike = new StringBuilderLike();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Consumer _function = (StringBuilderLike it) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Long _long = new Long(0);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Test.m(it, _long);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("InputOutput.println(Integer.valueOf(it.length()));"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("CollectionLiterals.newArrayList(_stringBuilderLike).forEach(_function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } -} diff --git a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug410797Test.java b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug410797Test.java deleted file mode 100644 index 3f612174ad0..00000000000 --- a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug410797Test.java +++ /dev/null @@ -1,774 +0,0 @@ -/** - * Copyright (c) 2014, 2020 itemis AG (http://www.itemis.eu) and others. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.eclipse.xtend.core.tests.java8.compiler; - -import org.eclipse.xtend.core.tests.compiler.AbstractXtendCompilerTest; -import org.eclipse.xtend.core.tests.java8.Java8RuntimeInjectorProvider; -import org.eclipse.xtend2.lib.StringConcatenation; -import org.eclipse.xtext.testing.InjectWith; -import org.junit.Test; - -/** - * @author Sebastian Zarnekow - Initial contribution and API - * @author Miro Spoenemann - Copied and adapted to Java 8 output - */ -@InjectWith(Java8RuntimeInjectorProvider.class) -@SuppressWarnings("all") -public class CompilerBug410797Test extends AbstractXtendCompilerTest { - @Test - public void testBug_410797_01() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def Iterable m() {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("val list = newArrayList"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("val g = new G"); - _builder.newLine(); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("list.map[e|e.m].flatten.map[d(g)]"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def d(F f, G g) {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("new D"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - _builder.append("class D {"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - _builder.append("class E {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def m() {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("newArrayList"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - _builder.newLine(); - _builder.append("class G {\t"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - _builder.append("class F {"); - _builder.newLine(); - _builder.append("\t"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import com.google.common.collect.Iterables;"); - _builder_1.newLine(); - _builder_1.append("import java.util.ArrayList;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function1;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.IterableExtensions;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.ListExtensions;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public Iterable m() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Iterable _xblockexpression = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("{"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final ArrayList list = CollectionLiterals.newArrayList();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final G g = new G();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function1> _function = (E e) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return e.m();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function1 _function_1 = (F it) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return this.d(it, g);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_xblockexpression = IterableExtensions.map(Iterables.concat(ListExtensions.>map(list, _function)), _function_1);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return _xblockexpression;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public D d(final F f, final G g) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return new D();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - public void testBug_410797_02() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def Iterable m() {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("val g = new G();"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("newArrayList.map[e|e.m].flatten.map[d(g)]"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def d(F f, G g) {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("new D"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - _builder.append("class D {"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - _builder.append("class E {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def m() {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("newArrayList"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - _builder.newLine(); - _builder.append("class G {\t"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - _builder.append("class F {"); - _builder.newLine(); - _builder.append("\t"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import com.google.common.collect.Iterables;"); - _builder_1.newLine(); - _builder_1.append("import java.util.ArrayList;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function1;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.IterableExtensions;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.ListExtensions;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public Iterable m() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Iterable _xblockexpression = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("{"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final G g = new G();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function1> _function = (E e) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return e.m();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function1 _function_1 = (F it) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return this.d(it, g);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_xblockexpression = IterableExtensions.map(Iterables.concat(ListExtensions.>map(CollectionLiterals.newArrayList(), _function)), _function_1);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return _xblockexpression;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public D d(final F f, final G g) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return new D();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - public void testBug_410797_03() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def Iterable m() {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("newArrayList.map[e|e.m].flatten.map[d(new G)]"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def d(F f, G g) {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("new D"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - _builder.append("class D {"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - _builder.append("class E {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def m() {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("newArrayList"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - _builder.newLine(); - _builder.append("class G {\t"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - _builder.append("class F {"); - _builder.newLine(); - _builder.append("\t"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import com.google.common.collect.Iterables;"); - _builder_1.newLine(); - _builder_1.append("import java.util.ArrayList;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function1;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.IterableExtensions;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.ListExtensions;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public Iterable m() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function1> _function = (E e) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return e.m();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function1 _function_1 = (F it) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("G _g = new G();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return this.d(it, _g);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return IterableExtensions.map(Iterables.concat(ListExtensions.>map(CollectionLiterals.newArrayList(), _function)), _function_1);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public D d(final F f, final G g) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return new D();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - public void testBug_410797_04() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("package org.eclipse.xtext.xbase.formatting"); - _builder.newLine(); - _builder.newLine(); - _builder.append("import com.google.inject.Inject"); - _builder.newLine(); - _builder.append("import org.eclipse.xtext.nodemodel.INode"); - _builder.newLine(); - _builder.append("import java.util.List"); - _builder.newLine(); - _builder.append("import org.eclipse.xtext.nodemodel.ILeafNode"); - _builder.newLine(); - _builder.append("import org.eclipse.xtext.parsetree.reconstr.impl.NodeIterator"); - _builder.newLine(); - _builder.append("import org.eclipse.xtext.nodemodel.ICompositeNode"); - _builder.newLine(); - _builder.newLine(); - _builder.append("@Data class HiddenLeafs {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("int offset"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("List leafs = newArrayList"); - _builder.newLine(); - _builder.append("\t"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def boolean isSingleWhitespace() {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("leafs.empty || (leafs.size == 1 && leafs.head instanceof WhitespaceInfo)"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def int getLenght() {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("leafs.fold(0, [x, i | x + i.node?.length])"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def int getNewLines() {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("leafs.fold(0, [x, i | x + i.newLines])"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def int getNewLinesInComments() {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("leafs.filter(CommentInfo).fold(0, [x, i | x + i.newLines])"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def containsComment(){"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("leafs.filter(CommentInfo).size > 0"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("package org.eclipse.xtext.xbase.formatting;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("import com.google.common.collect.Iterables;"); - _builder_1.newLine(); - _builder_1.append("import java.util.List;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtend.lib.Data;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.nodemodel.ILeafNode;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function2;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.IterableExtensions;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Pure;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.util.ToStringHelper;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@Data"); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class HiddenLeafs {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("private final int _offset;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("private final List _leafs = CollectionLiterals.newArrayList();"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public boolean isSingleWhitespace() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return (this.getLeafs().isEmpty() || ((this.getLeafs().size() == 1) && (IterableExtensions.head(this.getLeafs()) instanceof WhitespaceInfo)));"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public int getLenght() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function2 _function = (Integer x, LeafInfo i) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("ILeafNode _node = i.getNode();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("int _length = 0;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (_node!=null) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_length=_node.getLength();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return Integer.valueOf(((x).intValue() + _length));"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return (int) IterableExtensions.fold(this.getLeafs(), Integer.valueOf(0), _function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public int getNewLines() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function2 _function = (Integer x, LeafInfo i) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("int _newLines = i.getNewLines();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return Integer.valueOf(((x).intValue() + _newLines));"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return (int) IterableExtensions.fold(this.getLeafs(), Integer.valueOf(0), _function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public int getNewLinesInComments() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function2 _function = (Integer x, CommentInfo i) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("int _newLines = i.getNewLines();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return Integer.valueOf(((x).intValue() + _newLines));"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return (int) IterableExtensions.fold(Iterables.filter(this.getLeafs(), CommentInfo.class), Integer.valueOf(0), _function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public boolean containsComment() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("int _size = IterableExtensions.size(Iterables.filter(this.getLeafs(), CommentInfo.class));"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return (_size > 0);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public HiddenLeafs(final int offset) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("super();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("this._offset = offset;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("@Override"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("@Pure"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public int hashCode() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final int prime = 31;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("int result = 1;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("result = prime * result + this._offset;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return prime * result + ((this._leafs== null) ? 0 : this._leafs.hashCode());"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("@Override"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("@Pure"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public boolean equals(final Object obj) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (this == obj)"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return true;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (obj == null)"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return false;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (getClass() != obj.getClass())"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return false;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("HiddenLeafs other = (HiddenLeafs) obj;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (other._offset != this._offset)"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return false;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (this._leafs == null) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (other._leafs != null)"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return false;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("} else if (!this._leafs.equals(other._leafs))"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return false;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return true;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("@Override"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("@Pure"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public String toString() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("String result = new ToStringHelper().toString(this);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return result;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("@Pure"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public int getOffset() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return this._offset;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("@Pure"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public List getLeafs() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return this._leafs;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } -} diff --git a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug412894Test.java b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug412894Test.java deleted file mode 100644 index dfe4e64b3da..00000000000 --- a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug412894Test.java +++ /dev/null @@ -1,363 +0,0 @@ -/** - * Copyright (c) 2014, 2016 itemis AG (http://www.itemis.eu) and others. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.eclipse.xtend.core.tests.java8.compiler; - -import org.eclipse.xtend.core.tests.java8.Java8RuntimeInjectorProvider; -import org.eclipse.xtend2.lib.StringConcatenation; -import org.eclipse.xtext.testing.InjectWith; -import org.junit.Test; - -/** - * @author Sebastian Zarnekow - Initial contribution and API - * @author Miro Spoenemann - Copied and adapted to Java 8 output - */ -@InjectWith(Java8RuntimeInjectorProvider.class) -@SuppressWarnings("all") -public class CompilerBug412894Test extends org.eclipse.xtend.core.tests.compiler.CompilerBug412894Test { - @Test - @Override - public void test_01() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def m()\t{"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("val list = newArrayList"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("list.forEach ["); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("switch it {"); - _builder.newLine(); - _builder.append("\t\t\t\t"); - _builder.append("String: list.add(it)"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("]"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.ArrayList;"); - _builder_1.newLine(); - _builder_1.append("import java.util.function.Consumer;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void m() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final ArrayList list = CollectionLiterals.newArrayList();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Consumer _function = (String it) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("boolean _matched = false;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (it instanceof String) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_matched=true;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("list.add(it);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("list.forEach(_function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void test_02() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def m()\t{"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("val list = newArrayList"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("list.forEach ["); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("switch it {"); - _builder.newLine(); - _builder.append("\t\t\t\t"); - _builder.append("String: list.add(it)"); - _builder.newLine(); - _builder.append("\t\t\t\t"); - _builder.append("Number: list.add(it)"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("]"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.io.Serializable;"); - _builder_1.newLine(); - _builder_1.append("import java.util.ArrayList;"); - _builder_1.newLine(); - _builder_1.append("import java.util.function.Consumer;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void m() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final ArrayList list = CollectionLiterals.newArrayList();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Consumer _function = (Serializable it) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("boolean _matched = false;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (it instanceof String) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_matched=true;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("list.add(it);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (!_matched) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (it instanceof Number) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_matched=true;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("list.add(it);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("list.forEach(_function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void test_03() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def m()\t{"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("val list = newArrayList"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("list.forEach ["); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("switch it {"); - _builder.newLine(); - _builder.append("\t\t\t\t"); - _builder.append("Number: list.add(it.toString)"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("]"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.io.Serializable;"); - _builder_1.newLine(); - _builder_1.append("import java.util.ArrayList;"); - _builder_1.newLine(); - _builder_1.append("import java.util.function.Consumer;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void m() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final ArrayList list = CollectionLiterals.newArrayList();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Consumer _function = (Serializable it) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("boolean _matched = false;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (it instanceof Number) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_matched=true;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("list.add(((Number)it).toString());"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("list.forEach(_function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void test_04() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def m()\t{"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("val list = newArrayList"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("list.forEach ["); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("if (it instanceof String) list.add(it)"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("]"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.ArrayList;"); - _builder_1.newLine(); - _builder_1.append("import java.util.function.Consumer;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void m() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final ArrayList list = CollectionLiterals.newArrayList();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Consumer _function = (Object it) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if ((it instanceof String)) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("list.add(it);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("list.forEach(_function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } -} diff --git a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug421999Test.java b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug421999Test.java deleted file mode 100644 index 3a7553d8666..00000000000 --- a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug421999Test.java +++ /dev/null @@ -1,367 +0,0 @@ -/** - * Copyright (c) 2013, 2016 itemis AG (http://www.itemis.eu) and others. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.eclipse.xtend.core.tests.java8.compiler; - -import org.eclipse.xtend.core.tests.compiler.AbstractXtendCompilerTest; -import org.eclipse.xtend.core.tests.java8.Java8RuntimeInjectorProvider; -import org.eclipse.xtend2.lib.StringConcatenation; -import org.eclipse.xtext.testing.InjectWith; -import org.junit.Test; - -/** - * @author Sebastian Zarnekow - Initial contribution and API - * @author Miro Spoenemann - Copied and adapted to Java 8 output - */ -@InjectWith(Java8RuntimeInjectorProvider.class) -@SuppressWarnings("all") -public class CompilerBug421999Test extends AbstractXtendCompilerTest { - @Test - public void test_01() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def m(java.util.List list) {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("return list.sortBy(e|e)"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.List;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function1;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.IterableExtensions;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public List m(final List list) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function1 _function = (String e) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return e;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return IterableExtensions.sortBy(list, _function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - public void test_02() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def java.util.List m(java.util.List list) {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("return list.sortBy(e|e)"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.List;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function1;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.IterableExtensions;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public List m(final List list) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function1 _function = (String e) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return e;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return IterableExtensions.sortBy(list, _function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - public void test_03() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def m(java.util.List list) {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("list.sortBy(e|e)"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.List;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function1;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.IterableExtensions;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public List m(final List list) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function1 _function = (String e) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return e;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return IterableExtensions.sortBy(list, _function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - public void test_04() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def java.util.List m(java.util.List list) {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("list.sortBy(e|e)"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.List;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function1;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.IterableExtensions;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public List m(final List list) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function1 _function = (String e) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return e;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return IterableExtensions.sortBy(list, _function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - public void test_05() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import org.eclipse.emf.ecore.EClass"); - _builder.newLine(); - _builder.append("import org.eclipse.emf.ecore.EObject"); - _builder.newLine(); - _builder.append("import org.eclipse.emf.ecore.resource.ResourceSet"); - _builder.newLine(); - _builder.append("import org.eclipse.xtext.EcoreUtil2"); - _builder.newLine(); - _builder.append("import org.eclipse.xtext.naming.QualifiedName"); - _builder.newLine(); - _builder.append("import org.eclipse.xtext.resource.IEObjectDescription"); - _builder.newLine(); - _builder.append("import org.eclipse.xtext.xbase.lib.Pair"); - _builder.newLine(); - _builder.newLine(); - _builder.append("class Dummy {"); - _builder.newLine(); - _builder.append("\t"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def private T resolve(IEObjectDescription it, ResourceSet resourceSet) {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def Iterable> getVisibleIEObjectDescriptionByTypeAndCondition("); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("ResourceSet resourceSet,"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("EClass type,"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("(IEObjectDescription)=>boolean p) {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("val c = newArrayList"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("c.map[eod|"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("eod.qualifiedName -> resolve(eod, resourceSet)]"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.ArrayList;"); - _builder_1.newLine(); - _builder_1.append("import java.util.List;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.emf.ecore.EClass;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.emf.ecore.EObject;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.emf.ecore.resource.ResourceSet;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.naming.QualifiedName;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.resource.IEObjectDescription;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function1;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.ListExtensions;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Pair;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class Dummy {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("private T resolve(final IEObjectDescription it, final ResourceSet resourceSet) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public Iterable> getVisibleIEObjectDescriptionByTypeAndCondition(final ResourceSet resourceSet, final EClass type, final Function1 p) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("List> _xblockexpression = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("{"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final ArrayList c = CollectionLiterals.newArrayList();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function1> _function = (IEObjectDescription eod) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("QualifiedName _qualifiedName = eod.getQualifiedName();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("T _resolve = this.resolve(eod, resourceSet);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return Pair.of(_qualifiedName, _resolve);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_xblockexpression = ListExtensions.>map(c, _function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return _xblockexpression;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } -} diff --git a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug427637Test.java b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug427637Test.java deleted file mode 100644 index 09de561505b..00000000000 --- a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug427637Test.java +++ /dev/null @@ -1,4083 +0,0 @@ -/** - * Copyright (c) 2014, 2020 itemis AG (http://www.itemis.eu) and others. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.eclipse.xtend.core.tests.java8.compiler; - -import org.eclipse.xtend.core.tests.java8.Java8RuntimeInjectorProvider; -import org.eclipse.xtend2.lib.StringConcatenation; -import org.eclipse.xtext.testing.InjectWith; -import org.junit.Test; - -/** - * @author Sebastian Zarnekow - Initial contribution and API - * @author Miro Spoenemann - Copied and adapted to Java 8 output - */ -@InjectWith(Java8RuntimeInjectorProvider.class) -@SuppressWarnings("all") -public class CompilerBug427637Test extends org.eclipse.xtend.core.tests.compiler.CompilerBug427637Test { - @Test - @Override - public void testBug_427637_01() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import java.util.List"); - _builder.newLine(); - _builder.newLine(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def m(List list) {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("list.forEach2 ["); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("]"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def void forEach2(Iterable iterable, (T)=>void procedure) {}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.List;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void m(final List list) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Procedure1 _function = (V it) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("this.forEach2(list, _function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void forEach2(final Iterable iterable, final Procedure1 procedure) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void testBug_427637_01_b() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import java.util.List"); - _builder.newLine(); - _builder.newLine(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def m(List list) {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("list.forEach ["); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("]"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.List;"); - _builder_1.newLine(); - _builder_1.append("import java.util.function.Consumer;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void m(final List list) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Consumer _function = (V it) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("list.forEach(_function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void testBug_427637_02() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import java.util.List"); - _builder.newLine(); - _builder.newLine(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def m(List list) {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("list.forEach2 ["); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("]"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def void forEach2(Iterable iterable, (T)=>void procedure) {}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.List;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void m(final List list) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Procedure1 _function = (V it) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("this.forEach2(list, _function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void forEach2(final Iterable iterable, final Procedure1 procedure) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void testBug_427637_02_b() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import java.util.List"); - _builder.newLine(); - _builder.newLine(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def m(List list) {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("list.forEach ["); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("]"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.List;"); - _builder_1.newLine(); - _builder_1.append("import java.util.function.Consumer;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void m(final List list) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Consumer _function = (V it) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("list.forEach(_function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void testBug_427637_03() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import java.util.List"); - _builder.newLine(); - _builder.newLine(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def m(List list) {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("list.forEach2 ["); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("]"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def void forEach2(Iterable iterable, (T)=>void procedure) {}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.List;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void m(final List list) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Procedure1 _function = (Object it) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("this.forEach2(list, _function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void forEach2(final Iterable iterable, final Procedure1 procedure) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void testBug_427637_03_b() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import java.util.List"); - _builder.newLine(); - _builder.newLine(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def m(List list) {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("list.forEach ["); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("]"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.List;"); - _builder_1.newLine(); - _builder_1.append("import java.util.function.Consumer;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void m(final List list) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Consumer _function = (Object it) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("list.forEach(_function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void testBug_427637_04() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import java.util.List"); - _builder.newLine(); - _builder.newLine(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def m(List list) {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("list.subList(1,1).forEach2 ["); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("]"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def void forEach2(Iterable iterable, (T)=>void procedure) {}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.List;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void m(final List list) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Procedure1 _function = (V it) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("this.forEach2(list.subList(1, 1), _function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void forEach2(final Iterable iterable, final Procedure1 procedure) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void testBug_427637_04_b() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import java.util.List"); - _builder.newLine(); - _builder.newLine(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def m(List list) {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("list.subList(1,1).forEach ["); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("]"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.List;"); - _builder_1.newLine(); - _builder_1.append("import java.util.function.Consumer;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void m(final List list) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Consumer _function = (V it) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("list.subList(1, 1).forEach(_function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void testBug_427637_05() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import java.util.List"); - _builder.newLine(); - _builder.newLine(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def m(List list) {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("list.subList(1,1).forEach2 ["); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("]"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def void forEach2(Iterable iterable, (T)=>void procedure) {}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.List;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void m(final List list) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Procedure1 _function = (V it) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("this.forEach2(list.subList(1, 1), _function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void forEach2(final Iterable iterable, final Procedure1 procedure) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void testBug_427637_05_b() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import java.util.List"); - _builder.newLine(); - _builder.newLine(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def m(List list) {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("list.subList(1,1).forEach ["); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("]"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.List;"); - _builder_1.newLine(); - _builder_1.append("import java.util.function.Consumer;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void m(final List list) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Consumer _function = (V it) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("list.subList(1, 1).forEach(_function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void testBug_427637_06() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import java.util.List"); - _builder.newLine(); - _builder.newLine(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def m(List list) {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("list.subList(1,1).forEach2 ["); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("]"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def void forEach2(Iterable iterable, (T)=>void procedure) {}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.List;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void m(final List list) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Procedure1 _function = (Object it) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("this.forEach2(list.subList(1, 1), _function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void forEach2(final Iterable iterable, final Procedure1 procedure) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void testBug_427637_06_b() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import java.util.List"); - _builder.newLine(); - _builder.newLine(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def m(List list) {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("list.subList(1,1).forEach ["); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("]"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.List;"); - _builder_1.newLine(); - _builder_1.append("import java.util.function.Consumer;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void m(final List list) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Consumer _function = (Object it) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("list.subList(1, 1).forEach(_function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void testBug_427637_07() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import java.util.List"); - _builder.newLine(); - _builder.newLine(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def m(List list) {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("list.subList(1,1).forEach2 ["); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("it.toString"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("]"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def void forEach2(Iterable iterable, (T)=>void procedure) {}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.List;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void m(final List list) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Procedure1 _function = (V it) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("it.toString();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("this.forEach2(list.subList(1, 1), _function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void forEach2(final Iterable iterable, final Procedure1 procedure) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void testBug_427637_07_b() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import java.util.List"); - _builder.newLine(); - _builder.newLine(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def m(List list) {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("list.subList(1,1).forEach ["); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("it.toString"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("]"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.List;"); - _builder_1.newLine(); - _builder_1.append("import java.util.function.Consumer;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void m(final List list) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Consumer _function = (V it) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("it.toString();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("list.subList(1, 1).forEach(_function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void testBug_427637_08() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import java.util.List"); - _builder.newLine(); - _builder.newLine(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def m(List list) {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("list.subList(1,1).forEach2 ["); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("it.toString"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("]"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def void forEach2(Iterable iterable, (T)=>void procedure) {}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.List;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void m(final List list) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Procedure1 _function = (V it) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("it.toString();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("this.forEach2(list.subList(1, 1), _function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void forEach2(final Iterable iterable, final Procedure1 procedure) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void testBug_427637_08_b() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import java.util.List"); - _builder.newLine(); - _builder.newLine(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def m(List list) {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("list.subList(1,1).forEach ["); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("it.toString"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("]"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.List;"); - _builder_1.newLine(); - _builder_1.append("import java.util.function.Consumer;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void m(final List list) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Consumer _function = (V it) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("it.toString();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("list.subList(1, 1).forEach(_function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void testBug_427637_09() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import java.util.List"); - _builder.newLine(); - _builder.newLine(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def m(List list) {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("list.subList(1,1).forEach2 ["); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("it.toString"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("]"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def void forEach2(Iterable iterable, (T)=>void procedure) {}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.List;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void m(final List list) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Procedure1 _function = (Object it) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("it.toString();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("this.forEach2(list.subList(1, 1), _function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void forEach2(final Iterable iterable, final Procedure1 procedure) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void testBug_427637_09_b() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import java.util.List"); - _builder.newLine(); - _builder.newLine(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def m(List list) {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("list.subList(1,1).forEach ["); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("it.toString"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("]"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.List;"); - _builder_1.newLine(); - _builder_1.append("import java.util.function.Consumer;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void m(final List list) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Consumer _function = (Object it) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("it.toString();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("list.subList(1, 1).forEach(_function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void testBug_427637_10() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import java.util.List"); - _builder.newLine(); - _builder.newLine(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def m(List list) {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("val List target = null"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("list.forEach2 ["); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("target += it"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("]"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def void forEach2(Iterable iterable, (T)=>void procedure) {}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.List;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void m(final List list) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final List target = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Procedure1 _function = (V it) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("target.add(it);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("this.forEach2(list, _function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void forEach2(final Iterable iterable, final Procedure1 procedure) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void testBug_427637_10_b() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import java.util.List"); - _builder.newLine(); - _builder.newLine(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def m(List list) {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("val List target = null"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("list.forEach ["); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("target += it"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("]"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.List;"); - _builder_1.newLine(); - _builder_1.append("import java.util.function.Consumer;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void m(final List list) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final List target = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Consumer _function = (V it) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("target.add(it);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("list.forEach(_function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void testBug_427637_11() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import java.util.List"); - _builder.newLine(); - _builder.newLine(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def m(List list) {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("val List target = null"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("list.subList(0,1).forEach ["); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("target.subList(0, 1) += it"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("target.subList(0, 1) -= it"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("target.subList(0, 1) += newArrayList(it)"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("target.subList(0, 1) -= newArrayList(it)"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("]"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import com.google.common.collect.Iterables;"); - _builder_1.newLine(); - _builder_1.append("import java.util.ArrayList;"); - _builder_1.newLine(); - _builder_1.append("import java.util.List;"); - _builder_1.newLine(); - _builder_1.append("import java.util.function.Consumer;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void m(final List list) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final List target = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Consumer _function = (T it) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("List _subList = target.subList(0, 1);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_subList.add(it);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("List _subList_1 = target.subList(0, 1);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_subList_1.remove(it);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("List _subList_2 = target.subList(0, 1);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("ArrayList _newArrayList = CollectionLiterals.newArrayList(it);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Iterables.addAll(_subList_2, _newArrayList);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("List _subList_3 = target.subList(0, 1);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("ArrayList _newArrayList_1 = CollectionLiterals.newArrayList(it);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Iterables.removeAll(_subList_3, _newArrayList_1);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("list.subList(0, 1).forEach(_function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void testBug_427637_12() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import java.util.List"); - _builder.newLine(); - _builder.newLine(); - _builder.append("class Listener implements ListChangeListener {"); - _builder.newLine(); - _builder.append("\t"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("Group layer"); - _builder.newLine(); - _builder.append("\t"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("override onChanged(Change change) {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("while(change.next) {"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("if(change.wasAdded)"); - _builder.newLine(); - _builder.append("\t\t\t\t"); - _builder.append("change.addedSubList.forEach [ T it |"); - _builder.newLine(); - _builder.append("\t\t\t\t\t"); - _builder.append("layer.children += it"); - _builder.newLine(); - _builder.append("\t\t\t\t\t"); - _builder.append("it.activate()"); - _builder.newLine(); - _builder.append("\t\t\t\t"); - _builder.append("]"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("if(change.wasRemoved) "); - _builder.newLine(); - _builder.append("\t\t\t\t"); - _builder.append("change.removed.forEach [ T it |"); - _builder.newLine(); - _builder.append("\t\t\t\t\t"); - _builder.append("layer.children -= it"); - _builder.newLine(); - _builder.append("\t\t\t\t"); - _builder.append("]"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - _builder.append("interface ObservableList extends Observable, List {}"); - _builder.newLine(); - _builder.append("interface Observable {} "); - _builder.newLine(); - _builder.append("interface Node {}"); - _builder.newLine(); - _builder.append("interface Group extends Node {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def ObservableList getChildren()"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - _builder.append("interface XActivatable {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def void activate()"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - _builder.append("interface ListChangeListener {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def void onChanged(Change c)"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - _builder.append("interface Change {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def List getAddedSubList()"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def List getRemoved()"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def boolean next()"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def boolean wasAdded()"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def boolean wasRemoved()"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.function.Consumer;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class Listener implements ListChangeListener {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("private Group layer;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("@Override"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void onChanged(final Change change) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("while (change.next()) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("{"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("boolean _wasAdded = change.wasAdded();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (_wasAdded) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Consumer _function = (T it) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("ObservableList _children = this.layer.getChildren();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_children.add(it);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("it.activate();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("change.getAddedSubList().forEach(_function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("boolean _wasRemoved = change.wasRemoved();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (_wasRemoved) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Consumer _function_1 = (T it) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("ObservableList _children = this.layer.getChildren();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_children.remove(it);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("change.getRemoved().forEach(_function_1);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void testBug_427637_13() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import java.util.List"); - _builder.newLine(); - _builder.newLine(); - _builder.append("class Listener implements ListChangeListener {"); - _builder.newLine(); - _builder.append("\t"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("Group layer"); - _builder.newLine(); - _builder.append("\t"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("override onChanged(Change change) {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("while(change.next) {"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("if(change.wasAdded)"); - _builder.newLine(); - _builder.append("\t\t\t\t"); - _builder.append("change.addedSubList.forEach ["); - _builder.newLine(); - _builder.append("\t\t\t\t\t"); - _builder.append("layer.children += it"); - _builder.newLine(); - _builder.append("\t\t\t\t\t"); - _builder.append("it.activate()"); - _builder.newLine(); - _builder.append("\t\t\t\t"); - _builder.append("]"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("if(change.wasRemoved) "); - _builder.newLine(); - _builder.append("\t\t\t\t"); - _builder.append("change.removed.forEach ["); - _builder.newLine(); - _builder.append("\t\t\t\t\t"); - _builder.append("layer.children -= it"); - _builder.newLine(); - _builder.append("\t\t\t\t"); - _builder.append("]"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - _builder.append("interface ObservableList extends Observable, List {}"); - _builder.newLine(); - _builder.append("interface Observable {} "); - _builder.newLine(); - _builder.append("interface Node {}"); - _builder.newLine(); - _builder.append("interface Group extends Node {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def ObservableList getChildren()"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - _builder.append("interface XActivatable {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def void activate()"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - _builder.append("interface ListChangeListener {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def void onChanged(Change c)"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - _builder.append("interface Change {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def List getAddedSubList()"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def List getRemoved()"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def boolean next()"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def boolean wasAdded()"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def boolean wasRemoved()"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.function.Consumer;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class Listener implements ListChangeListener {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("private Group layer;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("@Override"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void onChanged(final Change change) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("while (change.next()) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("{"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("boolean _wasAdded = change.wasAdded();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (_wasAdded) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Consumer _function = (T it) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("ObservableList _children = this.layer.getChildren();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_children.add(it);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("it.activate();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("change.getAddedSubList().forEach(_function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("boolean _wasRemoved = change.wasRemoved();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (_wasRemoved) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Consumer _function_1 = (T it) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("ObservableList _children = this.layer.getChildren();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_children.remove(it);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("change.getRemoved().forEach(_function_1);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void testBug_427637_14() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import java.util.List"); - _builder.newLine(); - _builder.newLine(); - _builder.append("class Listener { // implements ListChangeListener {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("Group layer"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def onChanged(Change change) {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("change.addedSubList.forEach2 ["); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("layer.children += it"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("]"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def void forEach2(Iterable iterable, (T)=>void procedure) {}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - _builder.append("interface ObservableList extends Observable, List {}"); - _builder.newLine(); - _builder.append("interface Observable {} "); - _builder.newLine(); - _builder.append("interface Node {}"); - _builder.newLine(); - _builder.append("interface Group extends Node {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def ObservableList getChildren()"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - _builder.append("interface XActivatable {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def void activate()"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - _builder.append("interface ListChangeListener {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def void onChanged(Change c)"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - _builder.append("interface Change {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def List getAddedSubList()"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def List getRemoved()"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def boolean next()"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def boolean wasAdded()"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def boolean wasRemoved()"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class Listener {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("private Group layer;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void onChanged(final Change change) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Procedure1 _function = (T it) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("ObservableList _children = this.layer.getChildren();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_children.add(it);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("this.forEach2(change.getAddedSubList(), _function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void forEach2(final Iterable iterable, final Procedure1 procedure) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void testBug_427637_15() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("package org.eclipse.xtext.xbase.formatting"); - _builder.newLine(); - _builder.newLine(); - _builder.append("import com.google.inject.Inject"); - _builder.newLine(); - _builder.append("import org.eclipse.xtext.nodemodel.INode"); - _builder.newLine(); - _builder.append("import org.eclipse.xtext.xbase.lib.util.ToStringHelper"); - _builder.newLine(); - _builder.newLine(); - _builder.append("import static org.eclipse.xtext.xbase.formatting.XbaseFormatterPreferenceKeys.*"); - _builder.newLine(); - _builder.append("import org.eclipse.xtext.preferences.PreferenceKey"); - _builder.newLine(); - _builder.newLine(); - _builder.append("class FormattingDataFactory {"); - _builder.newLine(); - _builder.newLine(); - _builder.append("\t"); - _builder.append("@Inject extension HiddenLeafAccess"); - _builder.newLine(); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def protected (FormattableDocument)=>Iterable newFormattingData("); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("HiddenLeafs leafs,"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("(FormattingDataInit)=>void init"); - _builder.newLine(); - _builder.append("\t"); - _builder.append(") {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("val data = new FormattingDataInit()"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("init.apply(data)"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("newFormattingData(leafs, data.key, data)"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def protected dispatch (FormattableDocument)=>Iterable newFormattingData(HiddenLeafs leafs,"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("Void key, FormattingDataInit it) {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("[ FormattableDocument doc |"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("val int newLines2 = newLines ?: 0"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("if ((space == null && newLines == null) || (leafs.newLinesInComments == 0 && (newLines2 == 0 || space == \"\")))"); - _builder.newLine(); - _builder.append("\t\t\t\t"); - _builder.append("return newWhitespaceData(leafs, space, increaseIndentationChange, decreaseIndentationChange, doc.debugConflicts)"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("else"); - _builder.newLine(); - _builder.append("\t\t\t\t"); - _builder.append("return newNewLineData(leafs, newLines2, newLines2, increaseIndentationChange, decreaseIndentationChange, doc.debugConflicts)"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("]"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def protected dispatch (FormattableDocument)=>Iterable newFormattingData("); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("HiddenLeafs leafs,"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("BlankLineKey key,"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("FormattingDataInit it"); - _builder.newLine(); - _builder.append("\t"); - _builder.append(") {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("[ FormattableDocument doc |"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("val blankline = doc.cfg.get(key)"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("val preserve = doc.cfg.get(preserveBlankLines)"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("val min = blankline + 1"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("val max = Math.max(preserve + 1, min)"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("newNewLineData(leafs, min, max, increaseIndentationChange, decreaseIndentationChange, doc.debugConflicts)"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("]"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def protected dispatch (FormattableDocument)=>Iterable newFormattingData("); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("HiddenLeafs leafs,"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("NewLineOrPreserveKey key,"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("FormattingDataInit it"); - _builder.newLine(); - _builder.append("\t"); - _builder.append(") {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("[ FormattableDocument doc |"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("val newLine = doc.cfg.get(key)"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("val preserve = doc.cfg.get(preserveNewLines)"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("newNewLineData(leafs, if (newLine) 1 else 0, if (preserve || newLine) 1 else 0, increaseIndentationChange, decreaseIndentationChange,"); - _builder.newLine(); - _builder.append("\t\t\t\t"); - _builder.append("doc.debugConflicts)"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("]"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def protected dispatch (FormattableDocument)=>Iterable newFormattingData("); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("HiddenLeafs leafs,"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("NewLineKey key,"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("FormattingDataInit it"); - _builder.newLine(); - _builder.append("\t"); - _builder.append(") {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("[ FormattableDocument doc |"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("val newLine = doc.cfg.get(key)"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("val minmax = if (newLine) 1 else 0"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("newNewLineData(leafs, minmax, minmax, increaseIndentationChange, decreaseIndentationChange, doc.debugConflicts)"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("]"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def protected dispatch (FormattableDocument)=>Iterable newFormattingData("); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("HiddenLeafs leafs,"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("PreferenceKey key,"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("FormattingDataInit it"); - _builder.newLine(); - _builder.append("\t"); - _builder.append(") {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("throw new RuntimeException(\"Unknown configuration key kind: \" + key.^class)"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def protected dispatch (FormattableDocument)=>Iterable newFormattingData(HiddenLeafs leafs,"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("WhitespaceKey key, FormattingDataInit it) {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("[ FormattableDocument doc |"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("val space = doc.cfg.get(key)"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("newWhitespaceData(leafs, if (space) \" \" else \"\", increaseIndentationChange, decreaseIndentationChange, doc.debugConflicts)"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("]"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def protected Iterable newWhitespaceData("); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("HiddenLeafs leafs,"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("String space,"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("int increaseIndentationChange,"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("int decreaseIndentationChange,"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("boolean trace"); - _builder.newLine(); - _builder.append("\t"); - _builder.append(") {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("val result = newArrayList"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("var isFirst = true"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("for (leaf : leafs.leafs)"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("switch leaf {"); - _builder.newLine(); - _builder.append("\t\t\t\t"); - _builder.append("WhitespaceInfo: {"); - _builder.newLine(); - _builder.append("\t\t\t\t\t"); - _builder.append("result += new WhitespaceData(leaf.offset, leaf.length, if(isFirst) increaseIndentationChange else 0, if(isFirst) decreaseIndentationChange else 0,"); - _builder.newLine(); - _builder.append("\t\t\t\t\t\t"); - _builder.append("if (trace) new RuntimeException, space)"); - _builder.newLine(); - _builder.append("\t\t\t\t\t"); - _builder.append("isFirst = false"); - _builder.newLine(); - _builder.append("\t\t\t\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t\t\t\t"); - _builder.append("CommentInfo: {"); - _builder.newLine(); - _builder.append("\t\t\t\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("result"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def protected Iterable newNewLineData("); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("HiddenLeafs leafs,"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("int minNewLines,"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("int maxNewLines,"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("int increaseIndentationChange,"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("int decreaseIndentationChange,"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("boolean trace"); - _builder.newLine(); - _builder.append("\t"); - _builder.append(") {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("val result = newArrayList"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("var applied = false"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("for (leaf : leafs.leafs)"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("switch leaf {"); - _builder.newLine(); - _builder.append("\t\t\t\t"); - _builder.append("WhitespaceInfo: {"); - _builder.newLine(); - _builder.append("\t\t\t\t\t"); - _builder.append("val equalIndentationChange = increaseIndentationChange == decreaseIndentationChange * -1"); - _builder.newLine(); - _builder.append("\t\t\t\t\t"); - _builder.append("if (leaf.trailingComment?.trailing && !leaf.trailingComment?.multiline) {"); - _builder.newLine(); - _builder.append("\t\t\t\t\t\t"); - _builder.append("val space = if (leaf.offset == 0) \"\" else if(maxNewLines == 0) null else \" \""); - _builder.newLine(); - _builder.append("\t\t\t\t\t\t"); - _builder.append("result += new WhitespaceData(leaf.offset, leaf.length, 0 , 0, if (trace) new RuntimeException(), space)"); - _builder.newLine(); - _builder.append("\t\t\t\t\t"); - _builder.append("} else if (!applied) {"); - _builder.newLine(); - _builder.append("\t\t\t\t\t\t"); - _builder.append("var newLines = Math.min(Math.max(leafs.newLines, minNewLines), maxNewLines)"); - _builder.newLine(); - _builder.append("\t\t\t\t\t\t"); - _builder.append("if (newLines < 1 && leaf.offset > 0 &&"); - _builder.newLine(); - _builder.append("\t\t\t\t\t\t\t"); - _builder.append("(leaf.leadingComment?.multiline || leaf.trailingComment?.multiline))"); - _builder.newLine(); - _builder.append("\t\t\t\t\t\t\t"); - _builder.append("newLines = 1"); - _builder.newLine(); - _builder.append("\t\t\t\t\t\t"); - _builder.append("if (leaf.leadingComment?.endsWithNewLine)"); - _builder.newLine(); - _builder.append("\t\t\t\t\t\t\t"); - _builder.append("newLines = newLines - 1"); - _builder.newLine(); - _builder.append("\t\t\t\t\t\t"); - _builder.append("if (!leaf.leadingComment?.endsWithNewLine && newLines == 0)"); - _builder.newLine(); - _builder.append("\t\t\t\t\t\t\t"); - _builder.append("result += new WhitespaceData(leaf.offset, leaf.length, increaseIndentationChange, decreaseIndentationChange,"); - _builder.newLine(); - _builder.append("\t\t\t\t\t\t\t\t"); - _builder.append("if (trace) new RuntimeException(), if (leaf.offset == 0) \"\" else if(leafs.containsComment) null else \" \")"); - _builder.newLine(); - _builder.append("\t\t\t\t\t\t"); - _builder.append("else"); - _builder.newLine(); - _builder.append("\t\t\t\t\t\t\t"); - _builder.append("if(equalIndentationChange && leafs.leafs.lastOrNull != leaf)"); - _builder.newLine(); - _builder.append("\t\t\t\t\t\t\t\t"); - _builder.append("result += new NewLineData(leaf.offset, leaf.length, increaseIndentationChange, decreaseIndentationChange, if (trace) new RuntimeException(), newLines)"); - _builder.newLine(); - _builder.append("\t\t\t\t\t\t\t"); - _builder.append("else"); - _builder.newLine(); - _builder.append("\t\t\t\t\t\t\t\t"); - _builder.append("result += new NewLineData(leaf.offset, leaf.length, if(equalIndentationChange) 0 else increaseIndentationChange, if(equalIndentationChange) 0 else decreaseIndentationChange, if (trace) new RuntimeException(), newLines)"); - _builder.newLine(); - _builder.append("\t\t\t\t\t\t"); - _builder.append("applied = true"); - _builder.newLine(); - _builder.append("\t\t\t\t\t"); - _builder.append("} else {"); - _builder.newLine(); - _builder.append("\t\t\t\t\t\t"); - _builder.append("var newLines = 1"); - _builder.newLine(); - _builder.append("\t\t\t\t\t\t"); - _builder.append("if (leaf.leadingComment?.endsWithNewLine)"); - _builder.newLine(); - _builder.append("\t\t\t\t\t\t\t"); - _builder.append("newLines = newLines - 1"); - _builder.newLine(); - _builder.append("\t\t\t\t\t\t"); - _builder.append("if(equalIndentationChange && leafs.leafs.lastOrNull != leaf)"); - _builder.newLine(); - _builder.append("\t\t\t\t\t\t\t"); - _builder.append("result += new NewLineData(leaf.offset, leaf.length, increaseIndentationChange, decreaseIndentationChange, if (trace) new RuntimeException(), newLines)"); - _builder.newLine(); - _builder.append("\t\t\t\t\t\t"); - _builder.append("else"); - _builder.newLine(); - _builder.append("\t\t\t\t\t\t\t"); - _builder.append("result += new NewLineData(leaf.offset, leaf.length, 0, 0, if (trace) new RuntimeException(), newLines)"); - _builder.newLine(); - _builder.append("\t\t\t\t\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t\t\t\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t\t\t\t"); - _builder.append("CommentInfo: {"); - _builder.newLine(); - _builder.append("\t\t\t\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("result"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def (FormattableDocument)=>Iterable append("); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("INode node,"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("(FormattingDataInit)=>void init"); - _builder.newLine(); - _builder.append("\t"); - _builder.append(") {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("if (node != null) {"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("node.hiddenLeafsAfter.newFormattingData(init)"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def (FormattableDocument)=>Iterable prepend("); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("INode node,"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("(FormattingDataInit)=>void init"); - _builder.newLine(); - _builder.append("\t"); - _builder.append(") {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("if (node != null) {"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("node.hiddenLeafsBefore.newFormattingData(init)"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def (FormattableDocument)=>Iterable surround("); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("INode node,"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("(FormattingDataInit)=>void init"); - _builder.newLine(); - _builder.append("\t"); - _builder.append(") {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("[ FormattableDocument doc |"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("val result = newArrayList()"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("if (node != null) {"); - _builder.newLine(); - _builder.append("\t\t\t\t"); - _builder.append("result += node.hiddenLeafsBefore.newFormattingData(init)?.apply(doc) ?: emptyList"); - _builder.newLine(); - _builder.append("\t\t\t\t"); - _builder.append("result += node.hiddenLeafsAfter.newFormattingData(init)?.apply(doc) ?: emptyList"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("result"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("]"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def (FormattableDocument)=>Iterable surround("); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("INode node,"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("(FormattingDataInit)=>void before,"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("(FormattingDataInit)=>void after"); - _builder.newLine(); - _builder.append("\t"); - _builder.append(") {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("[ FormattableDocument doc |"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("val result = newArrayList()"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("if (node != null) {"); - _builder.newLine(); - _builder.append("\t\t\t\t"); - _builder.append("result += node.hiddenLeafsBefore.newFormattingData(before)?.apply(doc) ?: emptyList"); - _builder.newLine(); - _builder.append("\t\t\t\t"); - _builder.append("result += node.hiddenLeafsAfter.newFormattingData(after)?.apply(doc) ?: emptyList"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("result"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("]"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("static class FormattingDataInit {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("public String space = null"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("public Integer newLines = null"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("public int increaseIndentationChange = 0"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("public int decreaseIndentationChange = 0"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("public PreferenceKey key = null"); - _builder.newLine(); - _builder.append("\t"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("def void cfg(PreferenceKey key) {"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("this.key = key"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("def void newLine() {"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("newLines = 1"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("def void noSpace() {"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("space = \"\""); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("def void oneSpace() {"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("space = \" \""); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("def void increaseIndentation() {"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("increaseIndentationChange = increaseIndentationChange + 1"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("def void decreaseIndentation() {"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("decreaseIndentationChange = decreaseIndentationChange - 1"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("override String toString() {"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("new ToStringHelper().toString(this)"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("package org.eclipse.xtext.xbase.formatting;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("import com.google.common.collect.Iterables;"); - _builder_1.newLine(); - _builder_1.append("import com.google.inject.Inject;"); - _builder_1.newLine(); - _builder_1.append("import java.util.ArrayList;"); - _builder_1.newLine(); - _builder_1.append("import java.util.Arrays;"); - _builder_1.newLine(); - _builder_1.append("import java.util.List;"); - _builder_1.newLine(); - _builder_1.append("import java.util.Objects;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.nodemodel.INode;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.preferences.PreferenceKey;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Extension;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function1;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.IterableExtensions;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.util.ToStringHelper;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class FormattingDataFactory {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public static class FormattingDataInit {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public String space = null;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public Integer newLines = null;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public int increaseIndentationChange = 0;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public int decreaseIndentationChange = 0;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public PreferenceKey key = null;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void cfg(final PreferenceKey key) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("this.key = key;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void newLine() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("this.newLines = Integer.valueOf(1);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void noSpace() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("this.space = \"\";"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void oneSpace() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("this.space = \" \";"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void increaseIndentation() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("this.increaseIndentationChange = (this.increaseIndentationChange + 1);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void decreaseIndentation() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("this.decreaseIndentationChange = (this.decreaseIndentationChange - 1);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("@Override"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public String toString() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return new ToStringHelper().toString(this);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("@Inject"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("@Extension"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("private HiddenLeafAccess _hiddenLeafAccess;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("protected Function1> newFormattingData(final HiddenLeafs leafs, final Procedure1 init) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Function1> _xblockexpression = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("{"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final FormattingDataFactory.FormattingDataInit data = new FormattingDataFactory.FormattingDataInit();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("init.apply(data);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_xblockexpression = this.newFormattingData(leafs, data.key, data);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return _xblockexpression;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("protected Function1> _newFormattingData(final HiddenLeafs leafs, final Void key, final FormattingDataFactory.FormattingDataInit it) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function1> _function = (FormattableDocument doc) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Integer _elvis = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (it.newLines != null) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_elvis = it.newLines;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("} else {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_elvis = Integer.valueOf(0);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final int newLines2 = (int) _elvis;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (((Objects.equals(it.space, null) && Objects.equals(it.newLines, null)) || ((leafs.getNewLinesInComments() == 0) && ((newLines2 == 0) || Objects.equals(it.space, \"\"))))) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return this.newWhitespaceData(leafs, it.space, it.increaseIndentationChange, it.decreaseIndentationChange, doc.isDebugConflicts());"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("} else {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return this.newNewLineData(leafs, newLines2, newLines2, it.increaseIndentationChange, it.decreaseIndentationChange, doc.isDebugConflicts());"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return _function;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("protected Function1> _newFormattingData(final HiddenLeafs leafs, final BlankLineKey key, final FormattingDataFactory.FormattingDataInit it) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function1> _function = (FormattableDocument doc) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Iterable _xblockexpression = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("{"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final int blankline = doc.getCfg().get(key);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final int preserve = doc.getCfg().get(XbaseFormatterPreferenceKeys.preserveBlankLines);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final int min = (blankline + 1);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final int max = Math.max((preserve + 1), min);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_xblockexpression = this.newNewLineData(leafs, min, max, it.increaseIndentationChange, it.decreaseIndentationChange, doc.isDebugConflicts());"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return _xblockexpression;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return _function;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("protected Function1> _newFormattingData(final HiddenLeafs leafs, final NewLineOrPreserveKey key, final FormattingDataFactory.FormattingDataInit it) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function1> _function = (FormattableDocument doc) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Iterable _xblockexpression = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("{"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final boolean newLine = doc.getCfg().get(key);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final boolean preserve = doc.getCfg().get(XbaseFormatterPreferenceKeys.preserveNewLines);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("int _xifexpression = (int) 0;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (newLine) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_xifexpression = 1;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("} else {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_xifexpression = 0;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("int _xifexpression_1 = (int) 0;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if ((preserve || newLine)) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_xifexpression_1 = 1;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("} else {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_xifexpression_1 = 0;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_xblockexpression = this.newNewLineData(leafs, _xifexpression, _xifexpression_1, it.increaseIndentationChange, it.decreaseIndentationChange, "); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("doc.isDebugConflicts());"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return _xblockexpression;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return _function;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("protected Function1> _newFormattingData(final HiddenLeafs leafs, final NewLineKey key, final FormattingDataFactory.FormattingDataInit it) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function1> _function = (FormattableDocument doc) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Iterable _xblockexpression = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("{"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final boolean newLine = doc.getCfg().get(key);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("int _xifexpression = (int) 0;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (newLine) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_xifexpression = 1;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("} else {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_xifexpression = 0;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final int minmax = _xifexpression;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_xblockexpression = this.newNewLineData(leafs, minmax, minmax, it.increaseIndentationChange, it.decreaseIndentationChange, doc.isDebugConflicts());"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return _xblockexpression;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return _function;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("protected Function1> _newFormattingData(final HiddenLeafs leafs, final PreferenceKey key, final FormattingDataFactory.FormattingDataInit it) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Class _class = key.getClass();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("String _plus = (\"Unknown configuration key kind: \" + _class);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("throw new RuntimeException(_plus);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("protected Function1> _newFormattingData(final HiddenLeafs leafs, final WhitespaceKey key, final FormattingDataFactory.FormattingDataInit it) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function1> _function = (FormattableDocument doc) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Iterable _xblockexpression = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("{"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final boolean space = doc.getCfg().get(key);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("String _xifexpression = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (space) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_xifexpression = \" \";"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("} else {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_xifexpression = \"\";"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_xblockexpression = this.newWhitespaceData(leafs, _xifexpression, it.increaseIndentationChange, it.decreaseIndentationChange, doc.isDebugConflicts());"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return _xblockexpression;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return _function;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("protected Iterable newWhitespaceData(final HiddenLeafs leafs, final String space, final int increaseIndentationChange, final int decreaseIndentationChange, final boolean trace) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("ArrayList _xblockexpression = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("{"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final ArrayList result = CollectionLiterals.newArrayList();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("boolean isFirst = true;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("List _leafs = leafs.getLeafs();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("for (final LeafInfo leaf : _leafs) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("boolean _matched = false;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (leaf instanceof WhitespaceInfo) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_matched=true;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("int _offset = ((WhitespaceInfo)leaf).getOffset();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("int _length = ((WhitespaceInfo)leaf).getLength();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("int _xifexpression = (int) 0;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (isFirst) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_xifexpression = increaseIndentationChange;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("} else {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_xifexpression = 0;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("int _xifexpression_1 = (int) 0;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (isFirst) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_xifexpression_1 = decreaseIndentationChange;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("} else {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_xifexpression_1 = 0;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("RuntimeException _xifexpression_2 = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (trace) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_xifexpression_2 = new RuntimeException();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("WhitespaceData _whitespaceData = new WhitespaceData(_offset, _length, _xifexpression, _xifexpression_1, _xifexpression_2, space);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("result.add(_whitespaceData);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("isFirst = false;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (!_matched) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (leaf instanceof CommentInfo) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_matched=true;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_xblockexpression = result;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return _xblockexpression;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("protected Iterable newNewLineData(final HiddenLeafs leafs, final int minNewLines, final int maxNewLines, final int increaseIndentationChange, final int decreaseIndentationChange, final boolean trace) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("ArrayList _xblockexpression = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("{"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final ArrayList result = CollectionLiterals.newArrayList();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("boolean applied = false;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("List _leafs = leafs.getLeafs();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("for (final LeafInfo leaf : _leafs) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("boolean _matched = false;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (leaf instanceof WhitespaceInfo) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_matched=true;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final boolean equalIndentationChange = (increaseIndentationChange == (decreaseIndentationChange * (-1)));"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("boolean _and = false;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("CommentInfo _trailingComment = ((WhitespaceInfo)leaf).trailingComment();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("boolean _isTrailing = false;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (_trailingComment!=null) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_isTrailing=_trailingComment.isTrailing();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (!_isTrailing) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_and = false;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("} else {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("CommentInfo _trailingComment_1 = ((WhitespaceInfo)leaf).trailingComment();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("boolean _isMultiline = false;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (_trailingComment_1!=null) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_isMultiline=_trailingComment_1.isMultiline();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("boolean _not = (!_isMultiline);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_and = _not;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (_and) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("String _xifexpression = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("int _offset = ((WhitespaceInfo)leaf).getOffset();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("boolean _equals = (_offset == 0);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (_equals) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_xifexpression = \"\";"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("} else {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("String _xifexpression_1 = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if ((maxNewLines == 0)) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_xifexpression_1 = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("} else {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_xifexpression_1 = \" \";"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_xifexpression = _xifexpression_1;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final String space = _xifexpression;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("int _offset_1 = ((WhitespaceInfo)leaf).getOffset();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("int _length = ((WhitespaceInfo)leaf).getLength();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("RuntimeException _xifexpression_2 = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (trace) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_xifexpression_2 = new RuntimeException();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("WhitespaceData _whitespaceData = new WhitespaceData(_offset_1, _length, 0, 0, _xifexpression_2, space);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("result.add(_whitespaceData);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("} else {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if ((!applied)) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("int newLines = Math.min(Math.max(leafs.getNewLines(), minNewLines), maxNewLines);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("boolean _and_1 = false;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (!((newLines < 1) && (((WhitespaceInfo)leaf).getOffset() > 0))) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_and_1 = false;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("} else {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("boolean _or = false;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("CommentInfo _leadingComment = ((WhitespaceInfo)leaf).leadingComment();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("boolean _isMultiline_1 = false;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (_leadingComment!=null) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_isMultiline_1=_leadingComment.isMultiline();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (_isMultiline_1) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_or = true;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("} else {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("CommentInfo _trailingComment_2 = ((WhitespaceInfo)leaf).trailingComment();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("boolean _isMultiline_2 = false;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (_trailingComment_2!=null) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_isMultiline_2=_trailingComment_2.isMultiline();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_or = _isMultiline_2;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_and_1 = _or;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (_and_1) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("newLines = 1;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("CommentInfo _leadingComment_1 = ((WhitespaceInfo)leaf).leadingComment();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("boolean _endsWithNewLine = false;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (_leadingComment_1!=null) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_endsWithNewLine=_leadingComment_1.endsWithNewLine();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (_endsWithNewLine) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("newLines = (newLines - 1);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("boolean _and_2 = false;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("CommentInfo _leadingComment_2 = ((WhitespaceInfo)leaf).leadingComment();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("boolean _endsWithNewLine_1 = false;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (_leadingComment_2!=null) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_endsWithNewLine_1=_leadingComment_2.endsWithNewLine();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("boolean _not_1 = (!_endsWithNewLine_1);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (!_not_1) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_and_2 = false;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("} else {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_and_2 = (newLines == 0);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (_and_2) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("int _offset_2 = ((WhitespaceInfo)leaf).getOffset();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("int _length_1 = ((WhitespaceInfo)leaf).getLength();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("RuntimeException _xifexpression_3 = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (trace) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_xifexpression_3 = new RuntimeException();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("String _xifexpression_4 = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("int _offset_3 = ((WhitespaceInfo)leaf).getOffset();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("boolean _equals_1 = (_offset_3 == 0);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (_equals_1) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_xifexpression_4 = \"\";"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("} else {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("String _xifexpression_5 = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("boolean _containsComment = leafs.containsComment();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (_containsComment) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_xifexpression_5 = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("} else {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_xifexpression_5 = \" \";"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_xifexpression_4 = _xifexpression_5;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("WhitespaceData _whitespaceData_1 = new WhitespaceData(_offset_2, _length_1, increaseIndentationChange, decreaseIndentationChange, _xifexpression_3, _xifexpression_4);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("result.add(_whitespaceData_1);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("} else {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if ((equalIndentationChange && (!Objects.equals(IterableExtensions.lastOrNull(leafs.getLeafs()), leaf)))) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("int _offset_4 = ((WhitespaceInfo)leaf).getOffset();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("int _length_2 = ((WhitespaceInfo)leaf).getLength();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("RuntimeException _xifexpression_6 = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (trace) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_xifexpression_6 = new RuntimeException();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("NewLineData _newLineData = new NewLineData(_offset_4, _length_2, increaseIndentationChange, decreaseIndentationChange, _xifexpression_6, Integer.valueOf(newLines));"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("result.add(_newLineData);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("} else {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("int _offset_5 = ((WhitespaceInfo)leaf).getOffset();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("int _length_3 = ((WhitespaceInfo)leaf).getLength();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("int _xifexpression_7 = (int) 0;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (equalIndentationChange) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_xifexpression_7 = 0;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("} else {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_xifexpression_7 = increaseIndentationChange;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("int _xifexpression_8 = (int) 0;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (equalIndentationChange) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_xifexpression_8 = 0;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("} else {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_xifexpression_8 = decreaseIndentationChange;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("RuntimeException _xifexpression_9 = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (trace) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_xifexpression_9 = new RuntimeException();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("NewLineData _newLineData_1 = new NewLineData(_offset_5, _length_3, _xifexpression_7, _xifexpression_8, _xifexpression_9, Integer.valueOf(newLines));"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("result.add(_newLineData_1);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("applied = true;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("} else {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("int newLines_1 = 1;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("CommentInfo _leadingComment_3 = ((WhitespaceInfo)leaf).leadingComment();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("boolean _endsWithNewLine_2 = false;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (_leadingComment_3!=null) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_endsWithNewLine_2=_leadingComment_3.endsWithNewLine();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (_endsWithNewLine_2) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("newLines_1 = (newLines_1 - 1);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if ((equalIndentationChange && (!Objects.equals(IterableExtensions.lastOrNull(leafs.getLeafs()), leaf)))) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("int _offset_6 = ((WhitespaceInfo)leaf).getOffset();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("int _length_4 = ((WhitespaceInfo)leaf).getLength();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("RuntimeException _xifexpression_10 = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (trace) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_xifexpression_10 = new RuntimeException();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("NewLineData _newLineData_2 = new NewLineData(_offset_6, _length_4, increaseIndentationChange, decreaseIndentationChange, _xifexpression_10, Integer.valueOf(newLines_1));"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("result.add(_newLineData_2);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("} else {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("int _offset_7 = ((WhitespaceInfo)leaf).getOffset();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("int _length_5 = ((WhitespaceInfo)leaf).getLength();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("RuntimeException _xifexpression_11 = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (trace) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_xifexpression_11 = new RuntimeException();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("NewLineData _newLineData_3 = new NewLineData(_offset_7, _length_5, 0, 0, _xifexpression_11, Integer.valueOf(newLines_1));"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("result.add(_newLineData_3);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (!_matched) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (leaf instanceof CommentInfo) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_matched=true;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_xblockexpression = result;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return _xblockexpression;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public Function1> append(final INode node, final Procedure1 init) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Function1> _xifexpression = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("boolean _notEquals = (!Objects.equals(node, null));"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (_notEquals) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_xifexpression = this.newFormattingData(this._hiddenLeafAccess.getHiddenLeafsAfter(node), init);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return _xifexpression;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public Function1> prepend(final INode node, final Procedure1 init) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Function1> _xifexpression = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("boolean _notEquals = (!Objects.equals(node, null));"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (_notEquals) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_xifexpression = this.newFormattingData(this._hiddenLeafAccess.getHiddenLeafsBefore(node), init);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return _xifexpression;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public Function1> surround(final INode node, final Procedure1 init) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function1> _function = (FormattableDocument doc) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("ArrayList _xblockexpression = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("{"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final ArrayList result = CollectionLiterals.newArrayList();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("boolean _notEquals = (!Objects.equals(node, null));"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (_notEquals) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Iterable _elvis = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Function1> _newFormattingData = this.newFormattingData(this._hiddenLeafAccess.getHiddenLeafsBefore(node), init);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Iterable _apply = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (_newFormattingData!=null) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_apply=_newFormattingData.apply(doc);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (_apply != null) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_elvis = _apply;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("} else {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("List _emptyList = CollectionLiterals.emptyList();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_elvis = _emptyList;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Iterables.addAll(result, _elvis);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Iterable _elvis_1 = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Function1> _newFormattingData_1 = this.newFormattingData(this._hiddenLeafAccess.getHiddenLeafsAfter(node), init);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Iterable _apply_1 = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (_newFormattingData_1!=null) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_apply_1=_newFormattingData_1.apply(doc);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (_apply_1 != null) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_elvis_1 = _apply_1;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("} else {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("List _emptyList_1 = CollectionLiterals.emptyList();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_elvis_1 = _emptyList_1;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Iterables.addAll(result, _elvis_1);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_xblockexpression = result;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return _xblockexpression;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return _function;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public Function1> surround(final INode node, final Procedure1 before, final Procedure1 after) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function1> _function = (FormattableDocument doc) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("ArrayList _xblockexpression = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("{"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final ArrayList result = CollectionLiterals.newArrayList();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("boolean _notEquals = (!Objects.equals(node, null));"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (_notEquals) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Iterable _elvis = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Function1> _newFormattingData = this.newFormattingData(this._hiddenLeafAccess.getHiddenLeafsBefore(node), before);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Iterable _apply = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (_newFormattingData!=null) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_apply=_newFormattingData.apply(doc);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (_apply != null) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_elvis = _apply;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("} else {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("List _emptyList = CollectionLiterals.emptyList();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_elvis = _emptyList;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Iterables.addAll(result, _elvis);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Iterable _elvis_1 = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Function1> _newFormattingData_1 = this.newFormattingData(this._hiddenLeafAccess.getHiddenLeafsAfter(node), after);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Iterable _apply_1 = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (_newFormattingData_1!=null) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_apply_1=_newFormattingData_1.apply(doc);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (_apply_1 != null) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_elvis_1 = _apply_1;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("} else {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("List _emptyList_1 = CollectionLiterals.emptyList();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_elvis_1 = _emptyList_1;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Iterables.addAll(result, _elvis_1);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_xblockexpression = result;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return _xblockexpression;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return _function;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("protected Function1> newFormattingData(final HiddenLeafs leafs, final PreferenceKey key, final FormattingDataFactory.FormattingDataInit it) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (key instanceof BlankLineKey) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return _newFormattingData(leafs, (BlankLineKey)key, it);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("} else if (key instanceof NewLineKey) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return _newFormattingData(leafs, (NewLineKey)key, it);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("} else if (key instanceof NewLineOrPreserveKey) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return _newFormattingData(leafs, (NewLineOrPreserveKey)key, it);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("} else if (key instanceof WhitespaceKey) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return _newFormattingData(leafs, (WhitespaceKey)key, it);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("} else if (key == null) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return _newFormattingData(leafs, (Void)null, it);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("} else if (key != null) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return _newFormattingData(leafs, key, it);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("} else {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("throw new IllegalArgumentException(\"Unhandled parameter types: \" +"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Arrays.asList(leafs, key, it).toString());"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } -} diff --git a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug428063Test.java b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug428063Test.java deleted file mode 100644 index 4c7c27a40e9..00000000000 --- a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug428063Test.java +++ /dev/null @@ -1,143 +0,0 @@ -/** - * Copyright (c) 2014, 2016 itemis AG (http://www.itemis.eu) and others. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.eclipse.xtend.core.tests.java8.compiler; - -import org.eclipse.xtend.core.tests.compiler.AbstractXtendCompilerTest; -import org.eclipse.xtend.core.tests.java8.Java8RuntimeInjectorProvider; -import org.eclipse.xtend2.lib.StringConcatenation; -import org.eclipse.xtext.testing.InjectWith; -import org.junit.Test; - -/** - * @author Sebastian Zarnekow - Initial contribution and API - * @author Miro Spoenemann - Copied and adapted to Java 8 output - */ -@InjectWith(Java8RuntimeInjectorProvider.class) -@SuppressWarnings("all") -public class CompilerBug428063Test extends AbstractXtendCompilerTest { - @Test - public void testBug_428063_01() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def static void main() {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("m[Integer it| ]"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def static m((T)=>void block) {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public static void main() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Procedure1 _function = (Integer it) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("C.m(_function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public static Object m(final Procedure1 block) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - public void testBug_428063_02() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def static void main() {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("m[int it| ]"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def static m((T)=>void block) {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public static void main() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Procedure1 _function = (Integer it) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("C.m(_function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public static Object m(final Procedure1 block) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } -} diff --git a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug432193Test.java b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug432193Test.java deleted file mode 100644 index fe3db5fec6b..00000000000 --- a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug432193Test.java +++ /dev/null @@ -1,65 +0,0 @@ -/** - * Copyright (c) 2014, 2016 itemis AG (http://www.itemis.eu) and others. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.eclipse.xtend.core.tests.java8.compiler; - -import org.eclipse.xtend.core.tests.compiler.AbstractXtendCompilerTest; -import org.eclipse.xtend.core.tests.java8.Java8RuntimeInjectorProvider; -import org.eclipse.xtend2.lib.StringConcatenation; -import org.eclipse.xtext.testing.InjectWith; -import org.junit.Test; - -/** - * @author Sebastian Zarnekow - Initial contribution and API - * @author Miro Spoenemann - Copied and adapted to Java 8 output - */ -@InjectWith(Java8RuntimeInjectorProvider.class) -@SuppressWarnings("all") -public class CompilerBug432193Test extends AbstractXtendCompilerTest { - @Test - public void testBug_432193_01() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("D d = [ CharSequence o | "); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("o.subSequence(1, 2)"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("]"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - _builder.append("interface D {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def void m(String o) "); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("private D d = ((D) (String o) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("o.subSequence(1, 2);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("});"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } -} diff --git a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug435473Test.java b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug435473Test.java deleted file mode 100644 index db5af856883..00000000000 --- a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug435473Test.java +++ /dev/null @@ -1,1835 +0,0 @@ -/** - * Copyright (c) 2014, 2016 itemis AG (http://www.itemis.eu) and others. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.eclipse.xtend.core.tests.java8.compiler; - -import org.eclipse.xtend.core.tests.java8.Java8RuntimeInjectorProvider; -import org.eclipse.xtend2.lib.StringConcatenation; -import org.eclipse.xtext.testing.InjectWith; -import org.junit.Test; - -/** - * @author Sebastian Zarnekow - Initial contribution and API - * @author Miro Spoenemann - Copied and adapted to Java 8 output - */ -@InjectWith(Java8RuntimeInjectorProvider.class) -@SuppressWarnings("all") -public class CompilerBug435473Test extends org.eclipse.xtend.core.tests.compiler.CompilerBug435473Test { - @Test - @Override - public void test_01() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import java.util.List"); - _builder.newLine(); - _builder.append("class Outer {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("val List> x = #[[|1], [|1.0]]"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.Collections;"); - _builder_1.newLine(); - _builder_1.append("import java.util.List;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function0;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class Outer {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("private final List> x = Collections.>unmodifiableList(CollectionLiterals.>newArrayList(((Function0) () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return Integer.valueOf(1);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}), ((Function0) () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return Double.valueOf(1.0);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("})));"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void test_02() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import java.util.List"); - _builder.newLine(); - _builder.append("class Outer {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("val List> x = #[[|1], [|1.0]]"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.Collections;"); - _builder_1.newLine(); - _builder_1.append("import java.util.List;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function0;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class Outer {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("private final List> x = Collections.>unmodifiableList(CollectionLiterals.>newArrayList(((Function0) () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return Integer.valueOf(1);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}), ((Function0) () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return Double.valueOf(1.0);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("})));"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void test_03() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import java.util.List"); - _builder.newLine(); - _builder.append("class Outer {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("val List> x = #[[|1], [|1.0]]"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.Collections;"); - _builder_1.newLine(); - _builder_1.append("import java.util.List;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function0;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class Outer {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("private final List> x = Collections.>unmodifiableList(CollectionLiterals.>newArrayList(((Function0) () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return Integer.valueOf(1);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}), ((Function0) () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return Double.valueOf(1.0);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("})));"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void test_04() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import java.util.List"); - _builder.newLine(); - _builder.append("class Outer {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("val List> x = #[[|1], [|1.0]]"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.Collections;"); - _builder_1.newLine(); - _builder_1.append("import java.util.List;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function0;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class Outer {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("private final List> x = Collections.>unmodifiableList(CollectionLiterals.>newArrayList(((Function0) () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return Integer.valueOf(1);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}), ((Function0) () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return Double.valueOf(1.0);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("})));"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void test_05() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import java.util.Set"); - _builder.newLine(); - _builder.append("class Outer {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("val Set> x = #{ [|1], [|1.0] }"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.Collections;"); - _builder_1.newLine(); - _builder_1.append("import java.util.Set;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function0;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class Outer {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("private final Set> x = Collections.>unmodifiableSet(CollectionLiterals.>newHashSet(((Function0) () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return Integer.valueOf(1);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}), ((Function0) () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return Double.valueOf(1.0);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("})));"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void test_06() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import java.util.Set"); - _builder.newLine(); - _builder.append("class Outer {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("val Set> x = #{ [|1], [|1.0] }"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.Collections;"); - _builder_1.newLine(); - _builder_1.append("import java.util.Set;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function0;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class Outer {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("private final Set> x = Collections.>unmodifiableSet(CollectionLiterals.>newHashSet(((Function0) () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return Integer.valueOf(1);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}), ((Function0) () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return Double.valueOf(1.0);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("})));"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void test_07() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import java.util.Set"); - _builder.newLine(); - _builder.append("class Outer {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("val Set> x = #{ [|1], [|1.0] }"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.Collections;"); - _builder_1.newLine(); - _builder_1.append("import java.util.Set;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function0;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class Outer {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("private final Set> x = Collections.>unmodifiableSet(CollectionLiterals.>newHashSet(((Function0) () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return Integer.valueOf(1);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}), ((Function0) () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return Double.valueOf(1.0);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("})));"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void test_08() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import java.util.Set"); - _builder.newLine(); - _builder.append("class Outer {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("val Set> x = #{ [|1], [|1.0] }"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.Collections;"); - _builder_1.newLine(); - _builder_1.append("import java.util.Set;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function0;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class Outer {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("private final Set> x = Collections.>unmodifiableSet(CollectionLiterals.>newHashSet(((Function0) () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return Integer.valueOf(1);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}), ((Function0) () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return Double.valueOf(1.0);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("})));"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void test_09() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import java.util.List"); - _builder.newLine(); - _builder.append("class Outer {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("val List> x = newArrayList([|1], [|1.0])"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.List;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function0;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class Outer {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("private final List> x = CollectionLiterals.>newArrayList(((Function0) () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return Integer.valueOf(1);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}), ((Function0) () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return Double.valueOf(1.0);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}));"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void test_10() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import java.util.List"); - _builder.newLine(); - _builder.append("class Outer {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("val List> x = newArrayList([|1], [|1.0])"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.List;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function0;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class Outer {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("private final List> x = CollectionLiterals.>newArrayList(((Function0) () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return Integer.valueOf(1);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}), ((Function0) () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return Double.valueOf(1.0);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}));"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void test_11() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import java.util.List"); - _builder.newLine(); - _builder.append("class Outer {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("val List> x = newArrayList([|1], [|1.0])"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.List;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function0;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class Outer {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("private final List> x = CollectionLiterals.>newArrayList(((Function0) () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return Integer.valueOf(1);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}), ((Function0) () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return Double.valueOf(1.0);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}));"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void test_13() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import java.util.List"); - _builder.newLine(); - _builder.append("class Outer {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("val x = #[[|1], [|1.0]]"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.Collections;"); - _builder_1.newLine(); - _builder_1.append("import java.util.List;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function0;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class Outer {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("private final List> x = Collections.>unmodifiableList(CollectionLiterals.>newArrayList(((Function0) () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return Integer.valueOf(1);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}), ((Function0) () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return Double.valueOf(1.0);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("})));"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void test_14() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import java.util.List"); - _builder.newLine(); - _builder.append("class Outer {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("val x = newArrayList([|1], [|1.0])"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.ArrayList;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function0;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class Outer {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("private final ArrayList> x = CollectionLiterals.>newArrayList(((Function0) () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return Integer.valueOf(1);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}), ((Function0) () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return Double.valueOf(1.0);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}));"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void test_15() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import java.util.List"); - _builder.newLine(); - _builder.append("class Outer {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("val List> x = >newArrayList([|1], [|1.0])"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.List;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function0;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class Outer {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("private final List> x = CollectionLiterals.>newArrayList(((Function0) () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return Integer.valueOf(1);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}), ((Function0) () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return Double.valueOf(1.0);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}));"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void test_16() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import java.util.Map"); - _builder.newLine(); - _builder.append("class Outer {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("val Map> y = #{\'\' -> [|1], \'\' -> [|1.0]}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.Collections;"); - _builder_1.newLine(); - _builder_1.append("import java.util.Map;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function0;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Pair;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class Outer {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("private final Map> y = Collections.>unmodifiableMap(CollectionLiterals.>newHashMap(Pair.>of(\"\", ((Function0) () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return Integer.valueOf(1);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("})), Pair.>of(\"\", ((Function0) () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return Double.valueOf(1.0);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}))));"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void test_17() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import java.util.Map"); - _builder.newLine(); - _builder.append("class Outer {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("val Map> y = #{null as StringBuilder -> [|1], null as StringBuffer -> [|1.0]}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.Collections;"); - _builder_1.newLine(); - _builder_1.append("import java.util.Map;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function0;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Pair;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class Outer {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("private final Map> y = Collections.>unmodifiableMap(CollectionLiterals.>newHashMap(Pair.>of(((StringBuilder) null), ((Function0) () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return Integer.valueOf(1);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("})), Pair.>of(((StringBuffer) null), ((Function0) () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return Double.valueOf(1.0);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}))));"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void test_18() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("class Outer {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("val x = newArrayList( String.CASE_INSENSITIVE_ORDER, [ $0 <=> $1 ] )"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.ArrayList;"); - _builder_1.newLine(); - _builder_1.append("import java.util.Comparator;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class Outer {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("private final ArrayList> x = CollectionLiterals.>newArrayList(String.CASE_INSENSITIVE_ORDER, ((Comparator>>) (Comparable> $0, Comparable> $1) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return ($0.compareTo($1));"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}));"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void test_19() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("class Outer {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("val x = newArrayList( String.CASE_INSENSITIVE_ORDER, [ String s1, s2| s1 <=> s2 ] )"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.ArrayList;"); - _builder_1.newLine(); - _builder_1.append("import java.util.Comparator;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class Outer {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("private final ArrayList> x = CollectionLiterals.>newArrayList(String.CASE_INSENSITIVE_ORDER, ((Comparator) (String s1, String s2) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return (s1.compareTo(s2));"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}));"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void test_31() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import java.util.List"); - _builder.newLine(); - _builder.append("class Outer {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("interface A {}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("interface B extends A{}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("interface C extends A{}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("val List> x = #[[| null as B], [| null as C]]"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.Collections;"); - _builder_1.newLine(); - _builder_1.append("import java.util.List;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function0;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class Outer {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public interface A {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public interface B extends Outer.A {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public interface C extends Outer.A {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("private final List> x = Collections.>unmodifiableList(CollectionLiterals.>newArrayList(((Function0) () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return ((Outer.B) null);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}), ((Function0) () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return ((Outer.C) null);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("})));"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void test_32() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import java.util.List"); - _builder.newLine(); - _builder.append("class Outer {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("interface A {}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("interface B extends A{}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("interface C extends A{}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("val List> x = #[[| null as B], [| null as C]]"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.Collections;"); - _builder_1.newLine(); - _builder_1.append("import java.util.List;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function0;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class Outer {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public interface A {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public interface B extends Outer.A {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public interface C extends Outer.A {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("private final List> x = Collections.>unmodifiableList(CollectionLiterals.>newArrayList(((Function0) () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return ((Outer.B) null);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}), ((Function0) () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return ((Outer.C) null);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("})));"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void test_33() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import java.util.List"); - _builder.newLine(); - _builder.append("class Outer {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("interface A {}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("interface B extends A{}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("interface C extends A{}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("val List> x = #[[| null as B], [| null as C]]"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.Collections;"); - _builder_1.newLine(); - _builder_1.append("import java.util.List;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function0;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class Outer {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public interface A {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public interface B extends Outer.A {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public interface C extends Outer.A {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("private final List> x = Collections.>unmodifiableList(CollectionLiterals.>newArrayList(((Function0) () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return ((Outer.B) null);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}), ((Function0) () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return ((Outer.C) null);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("})));"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void test_34() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import java.util.List"); - _builder.newLine(); - _builder.append("class Outer {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("interface A {}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("interface B extends A{}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("interface C extends A{}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("val List> x = #[[| null as B], [| null as C]]"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.Collections;"); - _builder_1.newLine(); - _builder_1.append("import java.util.List;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function0;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class Outer {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public interface A {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public interface B extends Outer.A {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public interface C extends Outer.A {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("private final List> x = Collections.>unmodifiableList(CollectionLiterals.>newArrayList(((Function0) () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return ((Outer.B) null);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}), ((Function0) () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return ((Outer.C) null);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("})));"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void test_35() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import java.util.Set"); - _builder.newLine(); - _builder.append("class Outer {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("interface A {}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("interface B extends A{}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("interface C extends A{}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("val Set> x = #{ [| null as B], [| null as C] }"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.Collections;"); - _builder_1.newLine(); - _builder_1.append("import java.util.Set;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function0;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class Outer {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public interface A {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public interface B extends Outer.A {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public interface C extends Outer.A {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("private final Set> x = Collections.>unmodifiableSet(CollectionLiterals.>newHashSet(((Function0) () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return ((Outer.B) null);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}), ((Function0) () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return ((Outer.C) null);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("})));"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void test_36() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import java.util.Set"); - _builder.newLine(); - _builder.append("class Outer {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("interface A {}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("interface B extends A{}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("interface C extends A{}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("val Set> x = #{ [| null as B], [| null as C] }"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.Collections;"); - _builder_1.newLine(); - _builder_1.append("import java.util.Set;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function0;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class Outer {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public interface A {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public interface B extends Outer.A {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public interface C extends Outer.A {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("private final Set> x = Collections.>unmodifiableSet(CollectionLiterals.>newHashSet(((Function0) () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return ((Outer.B) null);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}), ((Function0) () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return ((Outer.C) null);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("})));"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void test_37() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import java.util.Set"); - _builder.newLine(); - _builder.append("class Outer {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("interface A {}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("interface B extends A{}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("interface C extends A{}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("val Set> x = #{ [| null as B], [| null as C] }"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.Collections;"); - _builder_1.newLine(); - _builder_1.append("import java.util.Set;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function0;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class Outer {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public interface A {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public interface B extends Outer.A {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public interface C extends Outer.A {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("private final Set> x = Collections.>unmodifiableSet(CollectionLiterals.>newHashSet(((Function0) () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return ((Outer.B) null);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}), ((Function0) () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return ((Outer.C) null);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("})));"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void test_38() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import java.util.Set"); - _builder.newLine(); - _builder.append("class Outer {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("interface A {}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("interface B extends A{}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("interface C extends A{}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("val Set> x = #{ [| null as B], [| null as C] }"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.Collections;"); - _builder_1.newLine(); - _builder_1.append("import java.util.Set;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function0;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class Outer {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public interface A {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public interface B extends Outer.A {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public interface C extends Outer.A {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("private final Set> x = Collections.>unmodifiableSet(CollectionLiterals.>newHashSet(((Function0) () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return ((Outer.B) null);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}), ((Function0) () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return ((Outer.C) null);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("})));"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void test_39() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import java.util.List"); - _builder.newLine(); - _builder.append("class Outer {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("interface A {}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("interface B extends A{}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("interface C extends A{}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("val List> x = newArrayList([| null as B], [| null as C])"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.List;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function0;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class Outer {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public interface A {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public interface B extends Outer.A {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public interface C extends Outer.A {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("private final List> x = CollectionLiterals.>newArrayList(((Function0) () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return ((Outer.B) null);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}), ((Function0) () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return ((Outer.C) null);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}));"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void test_40() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import java.util.List"); - _builder.newLine(); - _builder.append("class Outer {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("interface A {}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("interface B extends A{}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("interface C extends A{}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("val List> x = newArrayList([| null as B], [| null as C])"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.List;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function0;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class Outer {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public interface A {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public interface B extends Outer.A {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public interface C extends Outer.A {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("private final List> x = CollectionLiterals.>newArrayList(((Function0) () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return ((Outer.B) null);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}), ((Function0) () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return ((Outer.C) null);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}));"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void test_41() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import java.util.List"); - _builder.newLine(); - _builder.append("class Outer {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("interface A {}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("interface B extends A{}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("interface C extends A{}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("val List> x = newArrayList([| null as B], [| null as C])"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.List;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function0;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class Outer {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public interface A {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public interface B extends Outer.A {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public interface C extends Outer.A {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("private final List> x = CollectionLiterals.>newArrayList(((Function0) () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return ((Outer.B) null);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}), ((Function0) () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return ((Outer.C) null);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}));"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void test_43() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import java.util.List"); - _builder.newLine(); - _builder.append("class Outer {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("interface A {}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("interface B extends A{}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("interface C extends A{}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("val x = #[[| null as B], [| null as C]]"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.Collections;"); - _builder_1.newLine(); - _builder_1.append("import java.util.List;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function0;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class Outer {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public interface A {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public interface B extends Outer.A {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public interface C extends Outer.A {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("private final List> x = Collections.>unmodifiableList(CollectionLiterals.>newArrayList(((Function0) () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return ((Outer.B) null);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}), ((Function0) () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return ((Outer.C) null);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("})));"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void test_44() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import java.util.List"); - _builder.newLine(); - _builder.append("class Outer {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("interface A {}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("interface B extends A{}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("interface C extends A{}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("val x = newArrayList([| null as B], [| null as C])"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.ArrayList;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function0;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class Outer {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public interface A {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public interface B extends Outer.A {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public interface C extends Outer.A {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("private final ArrayList> x = CollectionLiterals.>newArrayList(((Function0) () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return ((Outer.B) null);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}), ((Function0) () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return ((Outer.C) null);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}));"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } -} diff --git a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug436230Test.java b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug436230Test.java deleted file mode 100644 index 78d0b6f6d72..00000000000 --- a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug436230Test.java +++ /dev/null @@ -1,323 +0,0 @@ -/** - * Copyright (c) 2014, 2016 itemis AG (http://www.itemis.eu) and others. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.eclipse.xtend.core.tests.java8.compiler; - -import org.eclipse.xtend.core.tests.compiler.AbstractXtendCompilerTest; -import org.eclipse.xtend.core.tests.java8.Java8RuntimeInjectorProvider; -import org.eclipse.xtend2.lib.StringConcatenation; -import org.eclipse.xtext.testing.InjectWith; -import org.junit.Test; - -/** - * @author Sebastian Zarnekow - Initial contribution and API - * @author Miro Spoenemann - Copied and adapted to Java 8 output - */ -@InjectWith(Java8RuntimeInjectorProvider.class) -@SuppressWarnings("all") -public class CompilerBug436230Test extends AbstractXtendCompilerTest { - @Test - public void test_01() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import java.util.List"); - _builder.newLine(); - _builder.append("class Foo {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("val List list = newArrayList"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def foo(List source) {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("list += source.map[\'\']"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import com.google.common.collect.Iterables;"); - _builder_1.newLine(); - _builder_1.append("import java.util.List;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function1;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.ListExtensions;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class Foo {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("private final List list = CollectionLiterals.newArrayList();"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public boolean foo(final List source) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function1 _function = (Object it) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return \"\";"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("List _map = ListExtensions.map(source, _function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return Iterables.addAll(this.list, _map);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - public void test_02() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import java.util.List"); - _builder.newLine(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def m() { "); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("val List res = null"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("val Iterable obj = null"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("res += obj.map[\"\"]"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import com.google.common.collect.Iterables;"); - _builder_1.newLine(); - _builder_1.append("import java.util.List;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function1;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.IterableExtensions;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public boolean m() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("boolean _xblockexpression = false;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("{"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final List res = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Iterable obj = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function1 _function = (Object it) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return \"\";"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Iterable _map = IterableExtensions.map(obj, _function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_xblockexpression = Iterables.addAll(res, _map);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return _xblockexpression;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - public void test_03() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import java.util.List"); - _builder.newLine(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def m() { "); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("val List res = null"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("val Iterable obj = null"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("res += obj.map[\"\"]"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import com.google.common.collect.Iterables;"); - _builder_1.newLine(); - _builder_1.append("import java.util.List;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function1;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.IterableExtensions;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public boolean m() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("boolean _xblockexpression = false;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("{"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final List res = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Iterable obj = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function1 _function = (Object it) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return \"\";"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Iterable _map = IterableExtensions.map(obj, _function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_xblockexpression = Iterables.addAll(res, _map);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return _xblockexpression;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - public void test_04() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import java.util.List"); - _builder.newLine(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def Iterable m() { "); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("val Iterable obj = null"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("obj.map[\"\"]"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function1;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.IterableExtensions;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public Iterable m() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Iterable _xblockexpression = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("{"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Iterable obj = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function1 _function = (Object it) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return \"\";"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_xblockexpression = IterableExtensions.map(obj, _function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return _xblockexpression;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } -} diff --git a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug440906Test.java b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug440906Test.java deleted file mode 100644 index bf7c4a05868..00000000000 --- a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug440906Test.java +++ /dev/null @@ -1,221 +0,0 @@ -/** - * Copyright (c) 2014, 2016 itemis AG (http://www.itemis.eu) and others. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.eclipse.xtend.core.tests.java8.compiler; - -import org.eclipse.xtend.core.tests.compiler.AbstractXtendCompilerTest; -import org.eclipse.xtend.core.tests.java8.Java8RuntimeInjectorProvider; -import org.eclipse.xtend2.lib.StringConcatenation; -import org.eclipse.xtext.testing.InjectWith; -import org.junit.Test; - -/** - * @author Sebastian Zarnekow - Initial contribution and API - * @author Miro Spoenemann - Copied and adapted to Java 8 output - */ -@InjectWith(Java8RuntimeInjectorProvider.class) -@SuppressWarnings("all") -public class CompilerBug440906Test extends AbstractXtendCompilerTest { - @Test - public void test_01() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def m() {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("[ Object a, Object b | 1 ]"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def m2() {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("#[].sortWith(m)"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.Collections;"); - _builder_1.newLine(); - _builder_1.append("import java.util.Comparator;"); - _builder_1.newLine(); - _builder_1.append("import java.util.List;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function2;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.IterableExtensions;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public Function2 m() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function2 _function = (Object a, Object b) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return Integer.valueOf(1);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return _function;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public List m2() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return IterableExtensions.sortWith(Collections.unmodifiableList(CollectionLiterals.newArrayList()), new Comparator() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public int compare(Object arg0, Object arg1) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return C.this.m().apply(arg0, arg1);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("});"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - public void test_02() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def m() {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("[ Object a, Object b | 1 ]"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def m2() {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("#[].sortWith({toString m})"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.Collections;"); - _builder_1.newLine(); - _builder_1.append("import java.util.Comparator;"); - _builder_1.newLine(); - _builder_1.append("import java.util.List;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function2;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.IterableExtensions;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public Function2 m() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function2 _function = (Object a, Object b) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return Integer.valueOf(1);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return _function;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public List m2() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Function2 _xblockexpression = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("{"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("this.toString();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_xblockexpression = this.m();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function2 _final_xblockexpression = _xblockexpression;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return IterableExtensions.sortWith(Collections.unmodifiableList(CollectionLiterals.newArrayList()), new Comparator() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public int compare(Object arg0, Object arg1) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return _final_xblockexpression.apply(arg0, arg1);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("});"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } -} diff --git a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug445487Test.java b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug445487Test.java deleted file mode 100644 index 15823b73e86..00000000000 --- a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug445487Test.java +++ /dev/null @@ -1,393 +0,0 @@ -/** - * Copyright (c) 2014, 2016 itemis AG (http://www.itemis.eu) and others. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.eclipse.xtend.core.tests.java8.compiler; - -import org.eclipse.xtend.core.tests.java8.Java8RuntimeInjectorProvider; -import org.eclipse.xtend2.lib.StringConcatenation; -import org.eclipse.xtext.testing.InjectWith; -import org.junit.Test; - -/** - * @author Sebastian Zarnekow - Initial contribution and API - * @author Miro Spoenemann - Copied and adapted to Java 8 output - */ -@InjectWith(Java8RuntimeInjectorProvider.class) -@SuppressWarnings("all") -public class CompilerBug445487Test extends org.eclipse.xtend.core.tests.compiler.CompilerBug445487Test { - @Test - @Override - public void test_01() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import com.google.inject.Provider"); - _builder.newLine(); - _builder.append("import org.antlr.runtime.Lexer"); - _builder.newLine(); - _builder.append("import org.eclipse.xtend.core.parser.antlr.internal.InternalXtendLexer"); - _builder.newLine(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("Provider lexerProvider= [return new InternalXtendLexer(null)]"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import com.google.inject.Provider;"); - _builder_1.newLine(); - _builder_1.append("import org.antlr.runtime.Lexer;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtend.core.parser.antlr.internal.InternalXtendLexer;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("private Provider lexerProvider = ((Provider) () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return new InternalXtendLexer(null);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("});"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void test_02() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import com.google.inject.Provider"); - _builder.newLine(); - _builder.append("import org.antlr.runtime.Lexer"); - _builder.newLine(); - _builder.append("import org.eclipse.xtend.core.parser.antlr.internal.InternalXtendLexer"); - _builder.newLine(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("Provider lexerProvider= [return new InternalXtendLexer(null)]"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import com.google.inject.Provider;"); - _builder_1.newLine(); - _builder_1.append("import org.antlr.runtime.Lexer;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtend.core.parser.antlr.internal.InternalXtendLexer;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("private Provider lexerProvider = ((Provider) () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return new InternalXtendLexer(null);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("});"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void test_03() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import com.google.inject.Provider"); - _builder.newLine(); - _builder.append("import org.antlr.runtime.Lexer"); - _builder.newLine(); - _builder.append("import org.eclipse.xtend.core.parser.antlr.internal.InternalXtendLexer"); - _builder.newLine(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("Provider lexerProvider= [return new InternalXtendLexer(null)]"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import com.google.inject.Provider;"); - _builder_1.newLine(); - _builder_1.append("import org.antlr.runtime.Lexer;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtend.core.parser.antlr.internal.InternalXtendLexer;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("private Provider lexerProvider = ((Provider) () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return new InternalXtendLexer(null);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("});"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void test_04() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import com.google.inject.Provider"); - _builder.newLine(); - _builder.append("import org.antlr.runtime.Lexer"); - _builder.newLine(); - _builder.append("import org.eclipse.xtend.core.parser.antlr.internal.InternalXtendLexer"); - _builder.newLine(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("Provider lexerProvider= [|return new InternalXtendLexer(null)] as Provider "); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import com.google.inject.Provider;"); - _builder_1.newLine(); - _builder_1.append("import org.antlr.runtime.Lexer;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtend.core.parser.antlr.internal.InternalXtendLexer;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function0;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("private Provider lexerProvider = ((Provider) new Provider() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public Lexer get() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return ((Function0) () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return new InternalXtendLexer(null);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}).apply();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("});"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void test_05() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import com.google.inject.Provider"); - _builder.newLine(); - _builder.append("import org.antlr.runtime.Lexer"); - _builder.newLine(); - _builder.append("import org.eclipse.xtend.core.parser.antlr.internal.InternalXtendLexer"); - _builder.newLine(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("Provider lexerProvider= [|return new InternalXtendLexer(null)] as ()=>Lexer"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import com.google.inject.Provider;"); - _builder_1.newLine(); - _builder_1.append("import org.antlr.runtime.Lexer;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtend.core.parser.antlr.internal.InternalXtendLexer;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function0;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("private Provider lexerProvider = new Provider() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public Lexer get() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return ((Function0) ((Function0) () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return new InternalXtendLexer(null);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("})).apply();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void test_06() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import com.google.inject.Provider"); - _builder.newLine(); - _builder.append("import org.antlr.runtime.Lexer"); - _builder.newLine(); - _builder.append("import org.eclipse.xtend.core.parser.antlr.internal.InternalXtendLexer"); - _builder.newLine(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("Provider lexerProvider= [return new InternalXtendLexer(null)] as Provider "); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import com.google.inject.Provider;"); - _builder_1.newLine(); - _builder_1.append("import org.antlr.runtime.Lexer;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtend.core.parser.antlr.internal.InternalXtendLexer;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function1;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("private Provider lexerProvider = ((Provider) new Provider() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public Lexer get() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return ((Function1) (Object it) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return new InternalXtendLexer(null);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}).apply(null);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("});"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void test_07() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import com.google.inject.Provider"); - _builder.newLine(); - _builder.append("import org.antlr.runtime.Lexer"); - _builder.newLine(); - _builder.append("import org.eclipse.xtend.core.parser.antlr.internal.InternalXtendLexer"); - _builder.newLine(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("Provider lexerProvider= [return new InternalXtendLexer(null)] as ()=>Lexer"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import com.google.inject.Provider;"); - _builder_1.newLine(); - _builder_1.append("import org.antlr.runtime.Lexer;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtend.core.parser.antlr.internal.InternalXtendLexer;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function0;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function1;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("private Provider lexerProvider = new Provider() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public Lexer get() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return ((Function0) new Function0() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public Lexer apply() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return ((Function1) (Object it) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return new InternalXtendLexer(null);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}).apply(null);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}).apply();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } -} diff --git a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug447516Test.java b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug447516Test.java deleted file mode 100644 index 109f74f86bc..00000000000 --- a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug447516Test.java +++ /dev/null @@ -1,228 +0,0 @@ -/** - * Copyright (c) 2014, 2016 itemis AG (http://www.itemis.eu) and others. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.eclipse.xtend.core.tests.java8.compiler; - -import org.eclipse.xtend.core.tests.compiler.AbstractXtendCompilerTest; -import org.eclipse.xtend.core.tests.java8.Java8RuntimeInjectorProvider; -import org.eclipse.xtend2.lib.StringConcatenation; -import org.eclipse.xtext.testing.InjectWith; -import org.junit.Test; - -/** - * @author Sebastian Zarnekow - Initial contribution and API - * @author Miro Spoenemann - Copied and adapted to Java 8 output - */ -@InjectWith(Java8RuntimeInjectorProvider.class) -@SuppressWarnings("all") -public class CompilerBug447516Test extends AbstractXtendCompilerTest { - @Test - public void test_01() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import org.eclipse.xtext.util.concurrent.IReadAccess"); - _builder.newLine(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("val IReadAccess readAccess = ["); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("return it.exec(\'\')"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("]"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import org.eclipse.xtext.util.concurrent.IReadAccess;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.util.concurrent.IUnitOfWork;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Exceptions;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("private final IReadAccess readAccess = new IReadAccess() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("@Override"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public Result readOnly(final IUnitOfWork it) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("try {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return it.exec(\"\");"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("} catch (Throwable _e) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("throw Exceptions.sneakyThrow(_e);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - public void test_02() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import org.eclipse.xtext.util.concurrent.IReadAccess"); - _builder.newLine(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("val I readAccess = ["); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("return it.apply(\'\')"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("]"); - _builder.newLine(); - _builder.append("\t"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("interface I

{"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("def T exec((P)=>T arg)"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function1;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public interface I

{"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append(" T exec(final Function1 arg);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("private final C.I readAccess = new C.I() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("@Override"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public T exec(final Function1 it) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return it.apply(\"\");"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - public void test_03() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import org.eclipse.xtext.util.concurrent.IReadAccess"); - _builder.newLine(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("val I i = ["); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("return $1.apply(\'\')"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("]"); - _builder.newLine(); - _builder.append("\t"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("interface I {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("def T exec(W w, (P)=>T arg)"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function1;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public interface I

{"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append(" T exec(final W w, final Function1 arg);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("private final C.I i = new C.I() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("@Override"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public T exec(final String $0, final Function1 $1) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return $1.apply(\"\");"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } -} diff --git a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug457333Test.java b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug457333Test.java deleted file mode 100644 index 487c708da71..00000000000 --- a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug457333Test.java +++ /dev/null @@ -1,211 +0,0 @@ -/** - * Copyright (c) 2015, 2016 itemis AG (http://www.itemis.eu) and others. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.eclipse.xtend.core.tests.java8.compiler; - -import org.eclipse.xtend.core.tests.compiler.AbstractXtendCompilerTest; -import org.eclipse.xtend.core.tests.java8.Java8RuntimeInjectorProvider; -import org.eclipse.xtend2.lib.StringConcatenation; -import org.eclipse.xtext.testing.InjectWith; -import org.junit.Test; - -/** - * @author Sebastian Zarnekow - Initial contribution and API - * @author Miro Spoenemann - Copied and adapted to Java 8 output - */ -@InjectWith(Java8RuntimeInjectorProvider.class) -@SuppressWarnings("all") -public class CompilerBug457333Test extends AbstractXtendCompilerTest { - @Test - public void test_01() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import java.util.Map"); - _builder.newLine(); - _builder.append("import org.eclipse.xtext.xbase.lib.Functions.Function0"); - _builder.newLine(); - _builder.newLine(); - _builder.append("class XtendPlugin implements (String)=>void {"); - _builder.newLine(); - _builder.newLine(); - _builder.append("\t"); - _builder.append("override apply(String project) {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("#[\'\'].forEach [ sourceSet |"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("create(\'\', Object) ["); - _builder.newLine(); - _builder.append("\t\t\t\t"); - _builder.append("conventionMapping("); - _builder.newLine(); - _builder.append("\t\t\t\t\t"); - _builder.append("#{"); - _builder.newLine(); - _builder.append("\t\t\t\t\t\t"); - _builder.append("\"classpath\" -> [|sourceSet.charAt(0)],"); - _builder.newLine(); - _builder.append("\t\t\t\t\t\t"); - _builder.append("\"bootClasspath\" -> [|sourceSet.charAt(0)]"); - _builder.newLine(); - _builder.append("\t\t\t\t\t"); - _builder.append("})"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("]"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("]"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("static def void conventionMapping(Object task, Map> mappings) {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def void create(String s, Class c, Action a) {}"); - _builder.newLine(); - _builder.append("\t"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def void all(Action action) {}"); - _builder.newLine(); - _builder.append("\t"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("interface Action {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("def void exec(T t)"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.Collections;"); - _builder_1.newLine(); - _builder_1.append("import java.util.Map;"); - _builder_1.newLine(); - _builder_1.append("import java.util.function.Consumer;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function0;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Pair;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class XtendPlugin implements Procedure1 {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public interface Action {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("void exec(final T t);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("@Override"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void apply(final String project) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Consumer _function = (String sourceSet) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final XtendPlugin.Action _function_1 = (Object it) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function0 _function_2 = () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return Character.valueOf(sourceSet.charAt(0));"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Pair> _mappedTo = Pair.>of(\"classpath\", _function_2);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function0 _function_3 = () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return Character.valueOf(sourceSet.charAt(0));"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Pair> _mappedTo_1 = Pair.>of(\"bootClasspath\", _function_3);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("XtendPlugin.conventionMapping(it, "); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Collections.>unmodifiableMap(CollectionLiterals.>newHashMap(_mappedTo, _mappedTo_1)));"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("this.create(\"\", Object.class, _function_1);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Collections.unmodifiableList(CollectionLiterals.newArrayList(\"\")).forEach(_function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public static void conventionMapping(final Object task, final Map> mappings) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void create(final String s, final Class c, final XtendPlugin.Action a) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void all(final XtendPlugin.Action action) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } -} diff --git a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug457346Test.java b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug457346Test.java deleted file mode 100644 index 57c391f0c9e..00000000000 --- a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug457346Test.java +++ /dev/null @@ -1,724 +0,0 @@ -/** - * Copyright (c) 2015, 2016 itemis AG (http://www.itemis.eu) and others. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.eclipse.xtend.core.tests.java8.compiler; - -import org.eclipse.xtend.core.tests.compiler.AbstractXtendCompilerTest; -import org.eclipse.xtend.core.tests.java8.Java8RuntimeInjectorProvider; -import org.eclipse.xtend2.lib.StringConcatenation; -import org.eclipse.xtext.testing.InjectWith; -import org.junit.Test; - -/** - * @author Sebastian Zarnekow - Initial contribution and API - * @author Miro Spoenemann - Copied and adapted to Java 8 output - */ -@InjectWith(Java8RuntimeInjectorProvider.class) -@SuppressWarnings("all") -public class CompilerBug457346Test extends AbstractXtendCompilerTest { - @Test - public void test_01() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import com.google.common.collect.Ordering"); - _builder.newLine(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def m() {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("#[\'a\', \'aa\', \'aaa\'].sortWith(Ordering.natural.onResultOf [ String s| s.length ].onResultOf[])"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import com.google.common.base.Function;"); - _builder_1.newLine(); - _builder_1.append("import com.google.common.collect.Ordering;"); - _builder_1.newLine(); - _builder_1.append("import java.util.Collections;"); - _builder_1.newLine(); - _builder_1.append("import java.util.List;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.IterableExtensions;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public List m() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function _function = (String s) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return Integer.valueOf(s.length());"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function _function_1 = (String it) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return IterableExtensions.sortWith(Collections.unmodifiableList(CollectionLiterals.newArrayList(\"a\", \"aa\", \"aaa\")), Ordering.natural().onResultOf(_function).onResultOf(_function_1));"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - public void test_02() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import com.google.common.collect.Ordering"); - _builder.newLine(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def m(Sortable sortMe) {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("sortMe.sort(Ordering.natural.onResultOf [ String s| s.length ].onResultOf[])"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("interface Sortable extends Iterable {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("def void sort(java.util.Comparator c)"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import com.google.common.base.Function;"); - _builder_1.newLine(); - _builder_1.append("import com.google.common.collect.Ordering;"); - _builder_1.newLine(); - _builder_1.append("import java.util.Comparator;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public interface Sortable extends Iterable {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("void sort(final Comparator c);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void m(final C.Sortable sortMe) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function _function = (String s) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return Integer.valueOf(s.length());"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function _function_1 = (String it) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("sortMe.sort(Ordering.natural().onResultOf(_function).onResultOf(_function_1));"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - public void test_03() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def m(Sortable sortMe) {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("sortMe.sort(MyComparator.comparingInt[String s| s.length].thenComparing[String s | s])"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("interface Sortable extends Iterable {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("def void sort(MyComparator c)"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("static abstract class MyComparator {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("def static MyComparator comparingInt(ToIntFunction fun) {}"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("def > MyComparator thenComparing((T)=>U f) {}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("interface ToIntFunction {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("def int apply(T t)"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function1;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public interface Sortable extends Iterable {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("void sort(final C.MyComparator c);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public static abstract class MyComparator {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public static C.MyComparator comparingInt(final C.ToIntFunction fun) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public > C.MyComparator thenComparing(final Function1 f) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public interface ToIntFunction {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("int apply(final T t);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void m(final C.Sortable sortMe) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final C.ToIntFunction _function = (String s) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return s.length();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function1 _function_1 = (String s) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return s;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("sortMe.sort(C.MyComparator.comparingInt(_function).thenComparing(_function_1));"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - public void test_04() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def m(Sortable sortMe) {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("sortMe.sort(MyComparator.comparingInt[String s| s.length].thenComparing[toUpperCase])"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("interface Sortable extends Iterable {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("def void sort(MyComparator c)"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("static abstract class MyComparator {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("def static MyComparator comparingInt(ToIntFunction fun) {}"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("def > MyComparator thenComparing((T)=>U f) {}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("interface ToIntFunction {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("def int apply(T t)"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function1;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public interface Sortable extends Iterable {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("void sort(final C.MyComparator c);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public static abstract class MyComparator {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public static C.MyComparator comparingInt(final C.ToIntFunction fun) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public > C.MyComparator thenComparing(final Function1 f) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public interface ToIntFunction {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("int apply(final T t);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void m(final C.Sortable sortMe) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final C.ToIntFunction _function = (String s) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return s.length();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function1 _function_1 = (String it) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return it.toUpperCase();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("sortMe.sort(C.MyComparator.comparingInt(_function).thenComparing(_function_1));"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - public void test_05() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def m(Sortable sortMe) {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("sortMe.sort(MyComparator.comparingInt[String s| s.length].thenComparing[it])"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("interface Sortable extends Iterable {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("def void sort(MyComparator c)"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("static abstract class MyComparator {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("def static MyComparator comparingInt(ToIntFunction fun) {}"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("def > MyComparator thenComparing((T)=>U f) {}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("interface ToIntFunction {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("def int apply(T t)"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function1;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public interface Sortable extends Iterable {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("void sort(final C.MyComparator c);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public static abstract class MyComparator {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public static C.MyComparator comparingInt(final C.ToIntFunction fun) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public > C.MyComparator thenComparing(final Function1 f) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public interface ToIntFunction {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("int apply(final T t);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void m(final C.Sortable sortMe) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final C.ToIntFunction _function = (String s) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return s.length();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function1 _function_1 = (String it) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return it;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("sortMe.sort(C.MyComparator.comparingInt(_function).thenComparing(_function_1));"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - public void test_06() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def m() {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("MyComparator.comparingInt [String s| s.length].thenComparing[it]"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("static abstract class MyComparator {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("def static MyComparator comparingInt(ToIntFunction fun) {}"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("def > MyComparator thenComparing("); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("Function keyExtractor,"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("MyComparator keyComparator)"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("def MyComparator thenComparing(MyComparator other)"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("def > MyComparator thenComparing("); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("Function keyExtractor)"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("interface ToIntFunction {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("def int apply(T t)"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("interface Function {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("def R apply(T t)"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public static abstract class MyComparator {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public static C.MyComparator comparingInt(final C.ToIntFunction fun) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public abstract > C.MyComparator thenComparing(final C.Function keyExtractor, final C.MyComparator keyComparator);"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public abstract C.MyComparator thenComparing(final C.MyComparator other);"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public abstract > C.MyComparator thenComparing(final C.Function keyExtractor);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public interface ToIntFunction {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("int apply(final T t);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public interface Function {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("R apply(final T t);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public C.MyComparator m() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final C.ToIntFunction _function = (String s) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return s.length();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final C.Function _function_1 = (String it) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return it;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return C.MyComparator.comparingInt(_function).thenComparing(_function_1);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } -} diff --git a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug457539Test.java b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug457539Test.java deleted file mode 100644 index 27371a5a340..00000000000 --- a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug457539Test.java +++ /dev/null @@ -1,949 +0,0 @@ -/** - * Copyright (c) 2015, 2016 itemis AG (http://www.itemis.eu) and others. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.eclipse.xtend.core.tests.java8.compiler; - -import org.eclipse.xtend.core.tests.java8.Java8RuntimeInjectorProvider; -import org.eclipse.xtend2.lib.StringConcatenation; -import org.eclipse.xtext.testing.InjectWith; -import org.junit.Test; - -/** - * @author Sebastian Zarnekow - Initial contribution and API - */ -@InjectWith(Java8RuntimeInjectorProvider.class) -@SuppressWarnings("all") -public class CompilerBug457539Test extends org.eclipse.xtend.core.tests.compiler.CompilerBug457539Test { - @Test - @Override - public void test_01() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import java.util.ArrayList"); - _builder.newLine(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def m()\t{"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("val list = new ArrayList"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("list.forEach ["); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("if (it instanceof String) list.add(it)"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("]"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.ArrayList;"); - _builder_1.newLine(); - _builder_1.append("import java.util.function.Consumer;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void m() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final ArrayList list = new ArrayList();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Consumer _function = (Object it) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if ((it instanceof String)) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("list.add(it);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("list.forEach(_function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void test_02() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def m()\t{"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("val list = newArrayList"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("list.forEach ["); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("if (it instanceof String) list.add(it)"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("]"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.ArrayList;"); - _builder_1.newLine(); - _builder_1.append("import java.util.function.Consumer;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void m() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final ArrayList list = CollectionLiterals.newArrayList();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Consumer _function = (Object it) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if ((it instanceof String)) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("list.add(it);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("list.forEach(_function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void test_03() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def m()\t{"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("val list = newIterable"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("list.forEach ["); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("]"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def static MyIterable newIterable(T... initial) {}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("interface MyIterable extends Iterable {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.function.Consumer;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public interface MyIterable extends Iterable {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void m() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final C.MyIterable list = C.newIterable();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Consumer _function = (CharSequence it) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("list.forEach(_function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public static C.MyIterable newIterable(final T... initial) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void test_04() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def m()\t{"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("val list = newIterable"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("list.add(\'\')"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("list.forEach ["); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("]"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def static MyIterable newIterable(T... initial) {}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("interface MyIterable extends Iterable {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("def void add(T t)"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("def T get()"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.function.Consumer;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public interface MyIterable extends Iterable {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("void add(final T t);"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("T get();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void m() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final C.MyIterable list = C.newIterable();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("list.add(\"\");"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Consumer _function = (String it) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("list.forEach(_function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public static C.MyIterable newIterable(final T... initial) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void test_05() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def m()\t{"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("val list = newIterable"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("list.get.toString"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("list.add(\'\')"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("list.forEach ["); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("]"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def static MyIterable newIterable(T... initial) {}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("interface MyIterable extends Iterable {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("def void add(T t)"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("def T get()"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.function.Consumer;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public interface MyIterable extends Iterable {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("void add(final T t);"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("T get();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void m() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final C.MyIterable list = C.newIterable();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("list.get().toString();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("list.add(\"\");"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Consumer _function = (CharSequence it) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("list.forEach(_function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public static C.MyIterable newIterable(final T... initial) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void test_06() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def m()\t{"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("val list = newIterable"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("list.get.toString"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("list.forEach ["); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("if (it instanceof String) list.add(it)"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("]"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def static MyIterable newIterable(T... initial) {}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("interface MyIterable extends Iterable {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("def void add(T t)"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("def T get()"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.function.Consumer;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public interface MyIterable extends Iterable {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("void add(final T t);"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("T get();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void m() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final C.MyIterable list = C.newIterable();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("list.get().toString();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Consumer _function = (CharSequence it) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if ((it instanceof String)) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("list.add(it);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("list.forEach(_function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public static C.MyIterable newIterable(final T... initial) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void test_07() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def m()\t{"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("val list = newIterable"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("list.forEach ["); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("if (it instanceof String) list.add(it)"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("]"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def static MyIterable newIterable(T... initial) {}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("interface MyIterable extends Iterable {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("def void add(T t)"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("def T get()"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.function.Consumer;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public interface MyIterable extends Iterable {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("void add(final T t);"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("T get();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void m() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final C.MyIterable list = C.newIterable();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Consumer _function = (CharSequence it) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if ((it instanceof String)) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("list.add(it);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("list.forEach(_function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public static C.MyIterable newIterable(final T... initial) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void test_08() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def m()\t{"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("val list = newIterable"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("list.forEach [ CharSequence it |"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("if (it instanceof String) list.add(it)"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("]"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def static MyIterable newIterable(T... initial) {}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("interface MyIterable extends Iterable {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("def void add(T t)"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("def T get()"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.function.Consumer;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public interface MyIterable extends Iterable {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("void add(final T t);"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("T get();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void m() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final C.MyIterable list = C.newIterable();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Consumer _function = (CharSequence it) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if ((it instanceof String)) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("list.add(it);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("list.forEach(_function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public static C.MyIterable newIterable(final T... initial) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void test_09() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import org.eclipse.xtend.core.tests.java8.compiler.StringBuilderLike"); - _builder.newLine(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def m()\t{"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("newIterable(new StringBuilderLike).forEach2 ["); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("m(it, new Long(0))"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("println(length)"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("]"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def m(T a, T b){}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def static MyIterable newIterable(T... initial) {}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("interface MyIterable extends Iterable {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("def void forEach2((T)=>void f)"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.io.Serializable;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtend.core.tests.java8.compiler.StringBuilderLike;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.InputOutput;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public interface MyIterable extends Iterable {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("void forEach2(final Procedure1 f);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void m() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("StringBuilderLike _stringBuilderLike = new StringBuilderLike();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Procedure1 _function = (StringBuilderLike it) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Long _long = new Long(0);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("this.m(it, _long);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("InputOutput.println(Integer.valueOf(it.length()));"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("C.newIterable(_stringBuilderLike).forEach2(_function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public Object m(final T a, final T b) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public static C.MyIterable newIterable(final T... initial) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void test_10() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def m(MyIterable list) {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("list.forEach2 []"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("interface MyIterable extends Iterable {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("def void forEach2((T)=>void f)"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public interface MyIterable extends Iterable {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("void forEach2(final Procedure1 f);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void m(final C.MyIterable list) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Procedure1 _function = (Object it) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("list.forEach2(_function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } -} diff --git a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug458010Test.java b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug458010Test.java index 77ebc72dbc0..ab2397716b8 100644 --- a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug458010Test.java +++ b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug458010Test.java @@ -9,15 +9,12 @@ package org.eclipse.xtend.core.tests.java8.compiler; import org.eclipse.xtend.core.tests.compiler.AbstractXtendCompilerTest; -import org.eclipse.xtend.core.tests.java8.Java8RuntimeInjectorProvider; import org.eclipse.xtend2.lib.StringConcatenation; -import org.eclipse.xtext.testing.InjectWith; import org.junit.Test; /** * @author Sebastian Zarnekow - Initial contribution and API */ -@InjectWith(Java8RuntimeInjectorProvider.class) @SuppressWarnings("all") public class CompilerBug458010Test extends AbstractXtendCompilerTest { @Test diff --git a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug460691Test.java b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug460691Test.java deleted file mode 100644 index 07ba9218aaf..00000000000 --- a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug460691Test.java +++ /dev/null @@ -1,63 +0,0 @@ -/** - * Copyright (c) 2015, 2016 itemis AG (http://www.itemis.eu) and others. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.eclipse.xtend.core.tests.java8.compiler; - -import org.eclipse.xtend.core.tests.java8.Java8RuntimeInjectorProvider; -import org.eclipse.xtend2.lib.StringConcatenation; -import org.eclipse.xtext.testing.InjectWith; -import org.junit.Test; - -/** - * @author Sebastian Zarnekow - Initial contribution and API - */ -@InjectWith(Java8RuntimeInjectorProvider.class) -@SuppressWarnings("all") -public class CompilerBug460691Test extends org.eclipse.xtend.core.tests.compiler.CompilerBug460691Test { - @Test - @Override - public void test_01() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("class C implements java.util.Comparator {"); - _builder.newLine(); - _builder.append(" "); - _builder.append("override compare(String s1, String s2) {"); - _builder.newLine(); - _builder.append(" \t"); - _builder.append("return s1.compareTo(s2)"); - _builder.newLine(); - _builder.append(" "); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.Comparator;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C implements Comparator {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("@Override"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public int compare(final String s1, final String s2) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return s1.compareTo(s2);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } -} diff --git a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug462845Test.java b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug462845Test.java deleted file mode 100644 index 6e455e07598..00000000000 --- a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug462845Test.java +++ /dev/null @@ -1,742 +0,0 @@ -/** - * Copyright (c) 2015, 2016 itemis AG (http://www.itemis.eu) and others. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.eclipse.xtend.core.tests.java8.compiler; - -import org.eclipse.xtend.core.tests.java8.Java8RuntimeInjectorProvider; -import org.eclipse.xtend2.lib.StringConcatenation; -import org.eclipse.xtext.testing.InjectWith; -import org.junit.Test; - -/** - * @author Sebastian Zarnekow - Initial contribution and API - */ -@InjectWith(Java8RuntimeInjectorProvider.class) -@SuppressWarnings("all") -public class CompilerBug462845Test extends org.eclipse.xtend.core.tests.compiler.CompilerBug462845Test { - @Test - @Override - public void test_01() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import java.util.Iterator"); - _builder.newLine(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("new() {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("val Iterable iter = [ null ]"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("new Iterator() {"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("Iterator delegate = iter.iterator"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("override hasNext() {"); - _builder.newLine(); - _builder.append("\t\t\t\t"); - _builder.append("delegate.hasNext"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("override next() {"); - _builder.newLine(); - _builder.append("\t\t\t\t"); - _builder.append("delegate.next"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.Iterator;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public C() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("abstract class __C_1 implements Iterator {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Iterator delegate;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Iterable _function = () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Iterable iter = _function;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("new __C_1() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("{"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("delegate = iter.iterator();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("@Override"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public boolean hasNext() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return this.delegate.hasNext();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("@Override"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public String next() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return this.delegate.next();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void test_02() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import java.util.Iterator"); - _builder.newLine(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def m() {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("val Iterable iter = [ null ]"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("new Iterator() {"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("Iterator delegate = iter.iterator"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("override hasNext() {"); - _builder.newLine(); - _builder.append("\t\t\t\t"); - _builder.append("delegate.hasNext"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("override next() {"); - _builder.newLine(); - _builder.append("\t\t\t\t"); - _builder.append("delegate.next"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.Iterator;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public Iterator m() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("abstract class __C_1 implements Iterator {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Iterator delegate;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("__C_1 _xblockexpression = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("{"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Iterable _function = () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Iterable iter = _function;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_xblockexpression = new __C_1() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("{"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("delegate = iter.iterator();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("@Override"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public boolean hasNext() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return this.delegate.hasNext();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("@Override"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public String next() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return this.delegate.next();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return _xblockexpression;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void test_03() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import java.util.Iterator"); - _builder.newLine(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def static m() {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("val Iterable iter = [ null ]"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("new Iterator() {"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("Iterator delegate = iter.iterator"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("override hasNext() {"); - _builder.newLine(); - _builder.append("\t\t\t\t"); - _builder.append("delegate.hasNext"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("override next() {"); - _builder.newLine(); - _builder.append("\t\t\t\t"); - _builder.append("delegate.next"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("override remove() {}"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.Iterator;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public static Iterator m() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("abstract class __C_1 implements Iterator {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Iterator delegate;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("__C_1 _xblockexpression = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("{"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Iterable _function = () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Iterable iter = _function;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_xblockexpression = new __C_1() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("{"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("delegate = iter.iterator();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("@Override"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public boolean hasNext() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return this.delegate.hasNext();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("@Override"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public String next() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return this.delegate.next();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("@Override"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void remove() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return _xblockexpression;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void test_04() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import java.util.Iterator"); - _builder.newLine(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def void m() {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("val Iterable iter = [ null ]"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("new Iterator() {"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("Iterator delegate = iter.iterator"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("override hasNext() {"); - _builder.newLine(); - _builder.append("\t\t\t\t"); - _builder.append("delegate.hasNext"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("override next() {"); - _builder.newLine(); - _builder.append("\t\t\t\t"); - _builder.append("delegate.next"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("override remove() {}"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.Iterator;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void m() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("abstract class __C_1 implements Iterator {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Iterator delegate;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Iterable _function = () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Iterable iter = _function;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("new __C_1() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("{"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("delegate = iter.iterator();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("@Override"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public boolean hasNext() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return this.delegate.hasNext();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("@Override"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public String next() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return this.delegate.next();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("@Override"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void remove() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void test_05() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import java.util.Iterator"); - _builder.newLine(); - _builder.append("class C {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("val iterator = {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("val Iterable iter = [ null ]"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("new Iterator() {"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("Iterator delegate = iter.iterator"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("override hasNext() {"); - _builder.newLine(); - _builder.append("\t\t\t\t"); - _builder.append("delegate.hasNext"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("override next() {"); - _builder.newLine(); - _builder.append("\t\t\t\t"); - _builder.append("delegate.next"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("override remove() {}"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.Iterator;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function0;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("private final Iterator iterator = new Function0>() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("@Override"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public Iterator apply() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("abstract class __C_1 implements Iterator {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Iterator delegate;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("__C_1 _xblockexpression = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("{"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Iterable _function = () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Iterable iter = _function;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_xblockexpression = new __C_1() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("{"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("delegate = iter.iterator();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("@Override"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public boolean hasNext() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return this.delegate.hasNext();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("@Override"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public String next() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return this.delegate.next();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("@Override"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void remove() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return _xblockexpression;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}.apply();"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } -} diff --git a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug465058Test.java b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug465058Test.java deleted file mode 100644 index b78a5101526..00000000000 --- a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug465058Test.java +++ /dev/null @@ -1,1599 +0,0 @@ -/** - * Copyright (c) 2015, 2016 itemis AG (http://www.itemis.eu) and others. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.eclipse.xtend.core.tests.java8.compiler; - -import org.eclipse.xtend.core.tests.java8.Java8RuntimeInjectorProvider; -import org.eclipse.xtend2.lib.StringConcatenation; -import org.eclipse.xtext.testing.InjectWith; -import org.junit.Test; - -/** - * @author Sebastian Zarnekow - Initial contribution and API - */ -@InjectWith(Java8RuntimeInjectorProvider.class) -@SuppressWarnings("all") -public class CompilerBug465058Test extends org.eclipse.xtend.core.tests.compiler.CompilerBug465058Test { - @Test - @Override - public void test_01() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("abstract class Bug {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("val list = #[\"one\", \"two\", \"three\"]"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def void foo(=>Object f)"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def bar() {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("foo[list.head]"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.Collections;"); - _builder_1.newLine(); - _builder_1.append("import java.util.List;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function0;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.IterableExtensions;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public abstract class Bug {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("private final List list = Collections.unmodifiableList(CollectionLiterals.newArrayList(\"one\", \"two\", \"three\"));"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public abstract void foo(final Function0 f);"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void bar() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function0 _function = () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return IterableExtensions.head(this.list);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("this.foo(_function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void test_02() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("abstract class Bug {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("val list = newArrayList(\'a\', \'b\')"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def void foo(=>Object f)"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def bar() {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("foo[ list.head ]"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.ArrayList;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function0;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.IterableExtensions;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public abstract class Bug {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("private final ArrayList list = CollectionLiterals.newArrayList(\"a\", \"b\");"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public abstract void foo(final Function0 f);"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void bar() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function0 _function = () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return IterableExtensions.head(this.list);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("this.foo(_function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void test_03() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("abstract class Bug {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("val list = #[\"one\", \"two\", \"three\"]"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def void foo(=>Object f)"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def bar() {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("foo[list.head]"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.Collections;"); - _builder_1.newLine(); - _builder_1.append("import java.util.List;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function0;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.IterableExtensions;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public abstract class Bug {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("private final List list = Collections.unmodifiableList(CollectionLiterals.newArrayList(\"one\", \"two\", \"three\"));"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public abstract void foo(final Function0 f);"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void bar() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function0 _function = () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return IterableExtensions.head(this.list);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("this.foo(_function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void test_04() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("abstract class Bug {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("val list = newArrayList(\'a\', \'b\')"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def void foo(=>Object f)"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def bar() {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("foo[ list.head ]"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.ArrayList;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function0;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.IterableExtensions;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public abstract class Bug {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("private final ArrayList list = CollectionLiterals.newArrayList(\"a\", \"b\");"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public abstract void foo(final Function0 f);"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void bar() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function0 _function = () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return IterableExtensions.head(this.list);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("this.foo(_function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void test_05() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("abstract class Bug {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("val list = #[\"one\", \"two\", \"three\"]"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def void foo(=>Object f)"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def bar() {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("foo[list.head2]"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def T head2(Iterable iterable) {}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.Collections;"); - _builder_1.newLine(); - _builder_1.append("import java.util.List;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function0;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public abstract class Bug {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("private final List list = Collections.unmodifiableList(CollectionLiterals.newArrayList(\"one\", \"two\", \"three\"));"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public abstract void foo(final Function0 f);"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void bar() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function0 _function = () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return this.head2(this.list);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("this.foo(_function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public T head2(final Iterable iterable) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void test_06() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("abstract class Bug {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("val list = #[\"one\", \"two\", \"three\"]"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def void foo(=>Object f)"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def bar() {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("foo[list.head2]"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def T head2(Iterable iterable) {}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.Collections;"); - _builder_1.newLine(); - _builder_1.append("import java.util.List;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function0;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public abstract class Bug {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("private final List list = Collections.unmodifiableList(CollectionLiterals.newArrayList(\"one\", \"two\", \"three\"));"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public abstract void foo(final Function0 f);"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void bar() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function0 _function = () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return this.head2(this.list);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("this.foo(_function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public T head2(final Iterable iterable) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void test_07() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("abstract class Bug {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("val list = #[\"one\", \"two\", \"three\"]"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def void foo(=>Object f)"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def bar() {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("foo[list.head2]"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def T head2(T[] iterable) {}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.Collections;"); - _builder_1.newLine(); - _builder_1.append("import java.util.List;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Conversions;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function0;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public abstract class Bug {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("private final List list = Collections.unmodifiableList(CollectionLiterals.newArrayList(\"one\", \"two\", \"three\"));"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public abstract void foo(final Function0 f);"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void bar() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function0 _function = () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return this.head2(((String[])Conversions.unwrapArray(this.list, String.class)));"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("this.foo(_function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public T head2(final T[] iterable) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void test_08() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("abstract class Bug {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def void foo(=>Object f)"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def bar() {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("foo[head2(#[\"one\", \"two\", \"three\"])]"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def T head2(T[] iterable) {}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function0;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public abstract class Bug {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public abstract void foo(final Function0 f);"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void bar() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function0 _function = () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return this.head2(new String[] { \"one\", \"two\", \"three\" });"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("this.foo(_function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public T head2(final T[] iterable) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void test_09() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("abstract class Bug {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("val list = #[\"one\", \"two\", \"three\"]"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def void foo(=>Object f)"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def bar() {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("foo[head2(list)]"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def T head2(Iterable iterable) {}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.Collections;"); - _builder_1.newLine(); - _builder_1.append("import java.util.List;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function0;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public abstract class Bug {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("private final List list = Collections.unmodifiableList(CollectionLiterals.newArrayList(\"one\", \"two\", \"three\"));"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public abstract void foo(final Function0 f);"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void bar() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function0 _function = () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return this.head2(this.list);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("this.foo(_function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public T head2(final Iterable iterable) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void test_10() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("abstract class Bug {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("val list = #[\"one\", \"two\", \"three\"]"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def void foo(=>Object f)"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def bar() {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("foo[list.head2]"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def T head2(Iterable iterable) {}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.Collections;"); - _builder_1.newLine(); - _builder_1.append("import java.util.List;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function0;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public abstract class Bug {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("private final List list = Collections.unmodifiableList(CollectionLiterals.newArrayList(\"one\", \"two\", \"three\"));"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public abstract void foo(final Function0 f);"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void bar() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function0 _function = () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return this.head2(this.list);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("this.foo(_function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public T head2(final Iterable iterable) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void test_11() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("abstract class Bug {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("val list = #[\"one\", \"two\", \"three\"]"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def void foo(=>Object f)"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def bar() {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("foo[list.head2]"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def T head2(Iterable iterable) {}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.Collections;"); - _builder_1.newLine(); - _builder_1.append("import java.util.List;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function0;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public abstract class Bug {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("private final List list = Collections.unmodifiableList(CollectionLiterals.newArrayList(\"one\", \"two\", \"three\"));"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public abstract void foo(final Function0 f);"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void bar() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function0 _function = () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return this.head2(this.list);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("this.foo(_function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public T head2(final Iterable iterable) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void test_12() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("abstract class Bug {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("val list = #[\"one\", \"two\", \"three\"]"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def void foo(=>Object f)"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def bar() {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("foo[list.head2]"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def T head2(T[] iterable) {}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.Collections;"); - _builder_1.newLine(); - _builder_1.append("import java.util.List;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Conversions;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function0;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public abstract class Bug {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("private final List list = Collections.unmodifiableList(CollectionLiterals.newArrayList(\"one\", \"two\", \"three\"));"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public abstract void foo(final Function0 f);"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void bar() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function0 _function = () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return this.head2(((String[])Conversions.unwrapArray(this.list, String.class)));"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("this.foo(_function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public T head2(final T[] iterable) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void test_13() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("abstract class Bug {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def void foo(=>Object f)"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def bar() {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("foo[head2(#[\"one\", \"two\", \"three\"])]"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def T head2(T[] iterable) {}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function0;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public abstract class Bug {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public abstract void foo(final Function0 f);"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void bar() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function0 _function = () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return this.head2(new String[] { \"one\", \"two\", \"three\" });"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("this.foo(_function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public T head2(final T[] iterable) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void test_14() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("abstract class Bug {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("val list = #[\"one\", \"two\", \"three\"]"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def void foo(=>Object f)"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def bar() {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("foo[head2(list)]"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def T head2(Iterable iterable) {}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.Collections;"); - _builder_1.newLine(); - _builder_1.append("import java.util.List;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function0;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public abstract class Bug {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("private final List list = Collections.unmodifiableList(CollectionLiterals.newArrayList(\"one\", \"two\", \"three\"));"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public abstract void foo(final Function0 f);"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void bar() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function0 _function = () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return this.head2(this.list);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("this.foo(_function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public T head2(final Iterable iterable) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void test_15() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("abstract class Bug {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("val list = #[\"one\", \"two\", \"three\"]"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def void bar() {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("var =>Object x = [head2(list)]"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("x.apply"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def T head2(Iterable iterable) {}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.Collections;"); - _builder_1.newLine(); - _builder_1.append("import java.util.List;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function0;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public abstract class Bug {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("private final List list = Collections.unmodifiableList(CollectionLiterals.newArrayList(\"one\", \"two\", \"three\"));"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void bar() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function0 _function = () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return this.head2(this.list);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Function0 x = _function;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("x.apply();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public T head2(final Iterable iterable) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void test_16() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("abstract class Bug {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def bar() {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("var =>Object x = [head2(#[\"one\", \"two\", \"three\"])]"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("x.apply"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def T head2(Iterable iterable) {}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.Collections;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function0;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public abstract class Bug {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public Object bar() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Object _xblockexpression = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("{"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function0 _function = () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return this.head2(Collections.unmodifiableList(CollectionLiterals.newArrayList(\"one\", \"two\", \"three\")));"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Function0 x = _function;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_xblockexpression = x.apply();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return _xblockexpression;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public T head2(final Iterable iterable) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void test_17() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("abstract class Bug {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def bar() {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("var =>Object x = [head2(#[\"one\", \"two\", \"three\"])]"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("x.apply()"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def T head2(T[] iterable) {}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function0;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public abstract class Bug {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public Object bar() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Object _xblockexpression = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("{"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function0 _function = () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return this.head2(new String[] { \"one\", \"two\", \"three\" });"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Function0 x = _function;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_xblockexpression = x.apply();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return _xblockexpression;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public T head2(final T[] iterable) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void test_18() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("abstract class Bug {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def void foo(=>Object f)"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def bar() {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("foo[head2(#[1, 1.0])]"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def T head2(T[] iterable) {}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function0;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public abstract class Bug {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public abstract void foo(final Function0 f);"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void bar() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function0 _function = () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return ((Number)this.head2(new Number[] { Integer.valueOf(1), Double.valueOf(1.0) }));"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("this.foo(_function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public T head2(final T[] iterable) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void test_19() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("abstract class Bug {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def void foo(=>Object f)"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def bar() {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("foo[head2(#[\'\', \'\'])]"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def T head2(Comparable[] iterable) {}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function0;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public abstract class Bug {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public abstract void foo(final Function0 f);"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void bar() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function0 _function = () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return this.head2(new Comparable[] { \"\", \"\" });"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("this.foo(_function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public T head2(final Comparable[] iterable) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void test_20() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("abstract class Bug {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def void foo(=>Object f)"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def bar() {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("foo[head2(#[null as Integer, null as Double])]"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def T head2(Comparable[] iterable) {}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function0;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public abstract class Bug {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public abstract void foo(final Function0 f);"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void bar() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function0 _function = () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return ((Number)this.head2(new Comparable[] { ((Integer) null), ((Double) null) }));"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("this.foo(_function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public T head2(final Comparable[] iterable) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void test_21() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("abstract class Bug {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def void foo(=>Object f)"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def bar() {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("foo[head2(#[1, 1.0])]"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def T head2(Comparable[] iterable) {}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function0;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public abstract class Bug {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public abstract void foo(final Function0 f);"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void bar() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function0 _function = () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return ((Number)this.head2(new Comparable[] { Integer.valueOf(1), Double.valueOf(1.0) }));"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("this.foo(_function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public T head2(final Comparable[] iterable) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } -} diff --git a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug472602Test.java b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug472602Test.java deleted file mode 100644 index ae737a1714d..00000000000 --- a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/java8/compiler/CompilerBug472602Test.java +++ /dev/null @@ -1,265 +0,0 @@ -/** - * Copyright (c) 2015, 2016 itemis AG (http://www.itemis.eu) and others. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.eclipse.xtend.core.tests.java8.compiler; - -import org.eclipse.xtend.core.tests.java8.Java8RuntimeInjectorProvider; -import org.eclipse.xtend2.lib.StringConcatenation; -import org.eclipse.xtext.testing.InjectWith; -import org.junit.Test; - -/** - * @author Sebastian Zarnekow - Initial contribution and API - */ -@InjectWith(Java8RuntimeInjectorProvider.class) -@SuppressWarnings("all") -public class CompilerBug472602Test extends org.eclipse.xtend.core.tests.compiler.CompilerBug472602Test { - @Test - @Override - public void test_06() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import com.google.common.base.Function"); - _builder.newLine(); - _builder.newLine(); - _builder.append("abstract class C {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def A get();"); - _builder.newLine(); - _builder.append("\t"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def C map(Function f) {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("new MapResult(this, f)"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("static class MapResult extends C {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("C in"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("Function f"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("new (C in, Function f) {"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("this.in = in"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("this.f = f"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("override get() {"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("val A a = in.get"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("val B b = f.apply(a)"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("return b"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import com.google.common.base.Function;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public abstract class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public static class MapResult extends C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("private C in;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("private Function f;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public MapResult(final C in, final Function f) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("this.in = in;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("this.f = f;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("@Override"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public B get() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final A a = this.in.get();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final B b = this.f.apply(a);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return b;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public abstract A get();"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public C map(final Function f) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return new C.MapResult(this, f);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void test_07() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import com.google.common.base.Function"); - _builder.newLine(); - _builder.newLine(); - _builder.append("abstract class C {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def A get();"); - _builder.newLine(); - _builder.append("\t"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def C map(Function f) {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("val thiz = this"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("new C() {"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("override get() {"); - _builder.newLine(); - _builder.append("\t\t\t\t"); - _builder.append("val A a = thiz.get"); - _builder.newLine(); - _builder.append("\t\t\t\t"); - _builder.append("val B b = f.apply(a)"); - _builder.newLine(); - _builder.append("\t\t\t\t"); - _builder.append("return b"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import com.google.common.base.Function;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public abstract class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public abstract A get();"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public C map(final Function f) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("C _xblockexpression = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("{"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final C thiz = this;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_xblockexpression = new C() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("@Override"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public B get() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final A a = thiz.get();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final B b = f.apply(a);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return b;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return _xblockexpression;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } -} diff --git a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/java8/compiler/Java8Compiler1Test.java b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/java8/compiler/Java8Compiler1Test.java index 9d9ef529242..b7b74efacf3 100644 --- a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/java8/compiler/Java8Compiler1Test.java +++ b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/java8/compiler/Java8Compiler1Test.java @@ -9,10 +9,8 @@ package org.eclipse.xtend.core.tests.java8.compiler; import java.util.Collections; -import org.eclipse.xtend.core.tests.compiler.CompilerTest; -import org.eclipse.xtend.core.tests.java8.Java8RuntimeInjectorProvider; +import org.eclipse.xtend.core.tests.compiler.CompilerTestBase; import org.eclipse.xtend2.lib.StringConcatenation; -import org.eclipse.xtext.testing.InjectWith; import org.eclipse.xtext.xbase.lib.CollectionLiterals; import org.eclipse.xtext.xbase.lib.Exceptions; import org.junit.Test; @@ -20,9 +18,8 @@ /** * @author Miro Spoenemann - Initial contribution and API */ -@InjectWith(Java8RuntimeInjectorProvider.class) @SuppressWarnings("all") -public class Java8Compiler1Test extends CompilerTest { +public class Java8Compiler1Test extends CompilerTestBase { @Test public void testJava8Reduce() { try { diff --git a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/java8/compiler/Java8Compiler2Test.java b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/java8/compiler/Java8Compiler2Test.java deleted file mode 100644 index 5474245f56a..00000000000 --- a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/java8/compiler/Java8Compiler2Test.java +++ /dev/null @@ -1,3585 +0,0 @@ -/** - * Copyright (c) 2015, 2020 itemis AG (http://www.itemis.eu) and others. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.eclipse.xtend.core.tests.java8.compiler; - -import org.eclipse.xtend.core.tests.compiler.XtendCompilerTest; -import org.eclipse.xtend.core.tests.java8.Java8RuntimeInjectorProvider; -import org.eclipse.xtend2.lib.StringConcatenation; -import org.eclipse.xtext.testing.InjectWith; -import org.junit.Test; - -/** - * @author Miro Spoenemann - Initial contribution and API - */ -@InjectWith(Java8RuntimeInjectorProvider.class) -@SuppressWarnings("all") -public class Java8Compiler2Test extends XtendCompilerTest { - @Test - public void testStaticMethodInInterface() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("interface Foo {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("static def bar() {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("\"bar!\""); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public interface Foo {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("static String bar() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return \"bar!\";"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void testMultiCatch_02() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("abstract class Foo {"); - _builder.newLine(); - _builder.append(" "); - _builder.append("abstract def void throwsSomething() throws E;"); - _builder.newLine(); - _builder.append(" "); - _builder.append("def void m() {"); - _builder.newLine(); - _builder.append(" "); - _builder.append("try {"); - _builder.newLine(); - _builder.append(" "); - _builder.append("throwsSomething;"); - _builder.newLine(); - _builder.append(" "); - _builder.append("throwsSomething"); - _builder.newLine(); - _builder.append(" "); - _builder.append("} catch(E1 | E2 e) {"); - _builder.newLine(); - _builder.append(" "); - _builder.append("e.m"); - _builder.newLine(); - _builder.append(" "); - _builder.append("e.message"); - _builder.newLine(); - _builder.append(" "); - _builder.append("}"); - _builder.newLine(); - _builder.append(" "); - _builder.append("}"); - _builder.newLine(); - _builder.append(" "); - _builder.append("interface E {"); - _builder.newLine(); - _builder.append(" \t "); - _builder.append("def void m()"); - _builder.newLine(); - _builder.append(" "); - _builder.append("}"); - _builder.newLine(); - _builder.append(" "); - _builder.append("static class E1 extends Exception implements E {"); - _builder.newLine(); - _builder.append(" \t "); - _builder.append("override m() {}"); - _builder.newLine(); - _builder.append(" "); - _builder.append("}"); - _builder.newLine(); - _builder.append(" "); - _builder.append("static class E2 extends Exception implements E {"); - _builder.newLine(); - _builder.append(" \t "); - _builder.append("override m() {}"); - _builder.newLine(); - _builder.append(" "); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Exceptions;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public abstract class Foo {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public interface E {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("void m();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public static class E1 extends Exception implements Foo.E {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("@Override"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void m() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public static class E2 extends Exception implements Foo.E {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("@Override"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void m() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public abstract void throwsSomething() throws E;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void m() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("try {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("try {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("this.throwsSomething();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("this.throwsSomething();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("} catch (final Throwable _t) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (_t instanceof Foo.E1 || _t instanceof Foo.E2) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Exception e = (Exception)_t;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("((Foo.E)e).m();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("e.getMessage();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("} else {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("throw Exceptions.sneakyThrow(_t);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("} catch (Throwable _e) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("throw Exceptions.sneakyThrow(_e);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void testSwitchWithMultiType_02() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("public class C {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def m(Object a) {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("switch a {"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("E1 | E2 case a.message !== null: a.m"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("interface E {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("def void m()"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("static class E1 extends Exception implements E {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("override m() {}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("static class E2 extends Exception implements E {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("override m() {}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public interface E {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("void m();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public static class E1 extends Exception implements C.E {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("@Override"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void m() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public static class E2 extends Exception implements C.E {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("@Override"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void m() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void m(final Object a) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("boolean _matched = false;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (a instanceof C.E1 || a instanceof C.E2) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("String _message = ((Exception)a).getMessage();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("boolean _tripleNotEquals = (_message != null);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (_tripleNotEquals) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_matched=true;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("((C.E)a).m();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void testSwitchWithMultiType_03() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("public class C {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def m(Object a) {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("switch a {"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("E1 | E2 : { val b = a b.message b.m }"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("interface E {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("def void m()"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("static class E1 extends Exception implements E {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("override m() {}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("static class E2 extends Exception implements E {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("override m() {}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public interface E {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("void m();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public static class E1 extends Exception implements C.E {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("@Override"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void m() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public static class E2 extends Exception implements C.E {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("@Override"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void m() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void m(final Object a) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("boolean _matched = false;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (a instanceof C.E1 || a instanceof C.E2) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_matched=true;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Exception b = ((Exception)a);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("b.getMessage();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("((C.E)b).m();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - public void testJava8UnaryOperator() throws Exception { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import java.util.List"); - _builder.newLine(); - _builder.append("class Test {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def test(List list) {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("list.replaceAll[it + 1]"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.List;"); - _builder_1.newLine(); - _builder_1.append("import java.util.function.UnaryOperator;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class Test {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void test(final List list) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final UnaryOperator _function = (Integer it) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return Integer.valueOf(((it).intValue() + 1));"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("list.replaceAll(_function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - public void testJava8Comparator() throws Exception { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import java.util.List"); - _builder.newLine(); - _builder.append("class Test {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def test(List list) {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("list.sort(java.util.Comparator.comparingInt[String s | s.length]"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append(".thenComparing[String s | s.length])"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.Comparator;"); - _builder_1.newLine(); - _builder_1.append("import java.util.List;"); - _builder_1.newLine(); - _builder_1.append("import java.util.function.Function;"); - _builder_1.newLine(); - _builder_1.append("import java.util.function.ToIntFunction;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class Test {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void test(final List list) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final ToIntFunction _function = (String s) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return s.length();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function _function_1 = (String s) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return Integer.valueOf(s.length());"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("list.sort(Comparator.comparingInt(_function).thenComparing(_function_1));"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - public void testJava8Predicate() throws Exception { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import java.util.List"); - _builder.newLine(); - _builder.append("class Test {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def test(List list) {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("list.removeIf[it < 2]"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.List;"); - _builder_1.newLine(); - _builder_1.append("import java.util.function.Predicate;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class Test {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public boolean test(final List list) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Predicate _function = (Integer it) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return ((it).intValue() < 2);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return list.removeIf(_function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - public void testJava8BinaryOperation() throws Exception { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import java.util.List"); - _builder.newLine(); - _builder.append("class Test {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def test(List list) {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("list.stream.reduce[a, b | a && b]"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.List;"); - _builder_1.newLine(); - _builder_1.append("import java.util.Optional;"); - _builder_1.newLine(); - _builder_1.append("import java.util.function.BinaryOperator;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class Test {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public Optional test(final List list) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final BinaryOperator _function = (Boolean a, Boolean b) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return Boolean.valueOf(((a).booleanValue() && (b).booleanValue()));"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return list.stream().reduce(_function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - public void testJava8Consumer() throws Exception { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import java.util.List"); - _builder.newLine(); - _builder.append("class Test {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def test(List list) {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("list.stream.forEach[println(it)]"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.List;"); - _builder_1.newLine(); - _builder_1.append("import java.util.function.Consumer;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.InputOutput;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class Test {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void test(final List list) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Consumer _function = (String it) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("InputOutput.println(it);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("list.stream().forEach(_function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - public void testJava8BiFunction() throws Exception { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import java.util.Map"); - _builder.newLine(); - _builder.append("class Test {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def test(Map map) {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("map.replaceAll[k, v | v + k.length]"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.Map;"); - _builder_1.newLine(); - _builder_1.append("import java.util.function.BiFunction;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class Test {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void test(final Map map) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final BiFunction _function = (String k, Integer v) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("int _length = k.length();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return Integer.valueOf(((v).intValue() + _length));"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("map.replaceAll(_function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - public void testDefaultMethodSuperCall01() throws Exception { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("class Test implements A {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("override void foo() {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("A.super.foo"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - _builder.append("interface A {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def void foo() {}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class Test implements A {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("@Override"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void foo() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("A.super.foo();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - public void testDefaultMethodSuperCall02() throws Exception { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("class Test implements A, B {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("override void foo() {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("B.super.foo"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - _builder.append("interface A {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def void foo() {}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - _builder.append("interface B {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def void foo() {}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class Test implements A, B {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("@Override"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void foo() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("B.super.foo();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - public void testDefaultMethodSuperCall03() throws Exception { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import test.Consumer"); - _builder.newLine(); - _builder.append("class Test implements Consumer, java.util.function.Consumer {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("override void accept(String element) {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("java.util.function.Consumer.super.andThen(this).accept(\'foo\')"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import test.Consumer;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class Test implements Consumer, java.util.function.Consumer {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("@Override"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void accept(final String element) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("java.util.function.Consumer.super.andThen(this).accept(\"foo\");"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - public void testDefaultMethodSuperCall04() throws Exception { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("interface Test extends A {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("override void foo() {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("A.super.foo"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - _builder.append("interface A {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def void foo() {}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public interface Test extends A {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("@Override"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("default void foo() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("A.super.foo();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - public void testSelfReference() throws Exception { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("class LambdaTest {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def b(A a) {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("a.a"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def test() {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("b[\'hello\' + b[\'world\' + self.a]]"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - _builder.append("interface A {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def String a()"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class LambdaTest {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public String b(final A a) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return a.a();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public String test() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final A _function = () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final A _function_1 = new A() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("@Override"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public String a() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("String _a = this.a();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return (\"world\" + _a);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("String _b = this.b(_function_1);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return (\"hello\" + _b);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return this.b(_function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void testClosureNoArgs() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("class Foo {"); - _builder.newLine(); - _builder.append(" "); - _builder.append("val thread = new Thread []"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class Foo {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("private final Thread thread = new Thread(((Runnable) () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}));"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void testClosureTwoArgs() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("class Foo {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def void m(java.util.List list) {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("java.util.Collections.sort(list) [ return 0 ]"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.Collections;"); - _builder_1.newLine(); - _builder_1.append("import java.util.Comparator;"); - _builder_1.newLine(); - _builder_1.append("import java.util.List;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class Foo {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void m(final List list) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Comparator _function = (String $0, String $1) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return 0;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Collections.sort(list, _function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void testVoidMethod_02() throws Exception { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("class A {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def m() {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("[ | System::out.println(\'\') ]"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Procedures.Procedure0;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class A {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public Procedure0 m() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Procedure0 _function = () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("System.out.println(\"\");"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return _function;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void testVoidMethod_03() throws Exception { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("class A {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def m() {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("[ | println(\'\') ]"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function0;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.InputOutput;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class A {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public Function0 m() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function0 _function = () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return InputOutput.println(\"\");"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return _function;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void testThrowablesPropagate_01() throws Exception { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import static extension Throwables.*"); - _builder.newLine(); - _builder.append("import java.net.URI"); - _builder.newLine(); - _builder.newLine(); - _builder.append("class Client {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("val uri = [| new URI(\'\')].propagate [ new IllegalArgumentException(it) ]"); - _builder.newLine(); - _builder.append("\t"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def foo (){"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("uri.toString"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - _builder.append("class Throwables {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def static T propagate(()=>T proc, (Exception)=>Exception handler) {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("try {"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("proc.apply"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("} catch(Exception e) {"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("throw handler.apply(e)"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.net.URI;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Exceptions;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function0;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function1;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class Client {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("private final URI uri = Throwables.propagate(((Function0) () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("try {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return new URI(\"\");"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("} catch (Throwable _e) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("throw Exceptions.sneakyThrow(_e);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}), ((Function1) (Exception it) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return new IllegalArgumentException(it);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}));"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public String foo() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return this.uri.toString();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void testThrowablesPropagate_02() throws Exception { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import static extension Throwables.*"); - _builder.newLine(); - _builder.append("import java.net.URI"); - _builder.newLine(); - _builder.newLine(); - _builder.append("class Client {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("val uri = [| new URI(\'\')].propagate [ new IllegalArgumentException(it) ]"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - _builder.append("class Throwables {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def static T propagate(()=>T proc, (Exception)=>Exception handler) {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("try {"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("proc.apply"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("} catch(Exception e) {"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("throw handler.apply(e)"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.net.URI;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Exceptions;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function0;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function1;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class Client {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("private final URI uri = Throwables.propagate(((Function0) () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("try {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return new URI(\"\");"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("} catch (Throwable _e) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("throw Exceptions.sneakyThrow(_e);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}), ((Function1) (Exception it) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return new IllegalArgumentException(it);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}));"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void testSwitchWithBooleanExpression_3() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("class Foo {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def foo(int x) { "); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("switch x {"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("case [|1 == x].apply || x == 2: true"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("default: false"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function0;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class Foo {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public boolean foo(final int x) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("boolean _switchResult = false;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("boolean _matched = false;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (((((Function0) () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return Boolean.valueOf((1 == x));"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}).apply()).booleanValue() || (x == 2))) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_matched=true;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_switchResult = true;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (!_matched) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_switchResult = false;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return _switchResult;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void testSwitchOverNull() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("public class Foo {"); - _builder.newLine(); - _builder.append(" "); - _builder.append("def foo() {"); - _builder.newLine(); - _builder.append(" "); - _builder.append("switch null {"); - _builder.newLine(); - _builder.append(" "); - _builder.append("case null : [Object it|it]"); - _builder.newLine(); - _builder.append(" "); - _builder.append("case null : [Integer it|it]"); - _builder.newLine(); - _builder.append(" "); - _builder.append("}"); - _builder.newLine(); - _builder.append(" "); - _builder.append("} "); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.Objects;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function1;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class Foo {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public Function1 foo() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Function1 _switchResult = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Object _switchValue = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("boolean _matched = false;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (Objects.equals(_switchValue, null)) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_matched=true;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function1 _function = (Object it) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return it;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_switchResult = _function;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (!_matched) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (Objects.equals(_switchValue, null)) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_matched=true;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function1 _function_1 = (Integer it) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return it;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_switchResult = _function_1;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return _switchResult;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void testSwitchWithConstantExpressions_6() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("class Foo {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def foo() {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("switch x : [|1].apply {"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("case 1: true"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function0;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class Foo {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public boolean foo() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("boolean _switchResult = false;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function0 _function = () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return Integer.valueOf(1);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Integer _apply = _function.apply();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Integer x = _apply;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (x != null) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("switch (x) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("case 1:"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_switchResult = true;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("break;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return _switchResult;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void testSwitchWithConstantExpressions_7() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("class Foo {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def foo() {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("switch x : 1 {"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("case [|1].apply: true"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.Objects;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function0;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class Foo {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public boolean foo() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("boolean _switchResult = false;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final int x = 1;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("boolean _matched = false;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function0 _function = () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return Integer.valueOf(1);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Integer _apply = _function.apply();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (Objects.equals(x, _apply)) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_matched=true;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_switchResult = true;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return _switchResult;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void testClosureSneakyThrow() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import java.io.File"); - _builder.newLine(); - _builder.append("import java.io.IOException"); - _builder.newLine(); - _builder.append("import java.util.Collections"); - _builder.newLine(); - _builder.newLine(); - _builder.append("class Foo {"); - _builder.newLine(); - _builder.append(" "); - _builder.append("def bar() {"); - _builder.newLine(); - _builder.append(" "); - _builder.append("try {"); - _builder.newLine(); - _builder.append(" "); - _builder.append("newArrayList(\"file1.ext\").map(f| new File(f).canonicalFile)"); - _builder.newLine(); - _builder.append(" "); - _builder.append("} catch(IOException o) {"); - _builder.newLine(); - _builder.append(" "); - _builder.append("Collections::emptyList"); - _builder.newLine(); - _builder.append(" "); - _builder.append("}"); - _builder.newLine(); - _builder.append(" "); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.io.File;"); - _builder_1.newLine(); - _builder_1.append("import java.io.IOException;"); - _builder_1.newLine(); - _builder_1.append("import java.util.Collections;"); - _builder_1.newLine(); - _builder_1.append("import java.util.List;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Exceptions;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function1;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.ListExtensions;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class Foo {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public List bar() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("List _xtrycatchfinallyexpression = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("try {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function1 _function = (String f) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("try {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return new File(f).getCanonicalFile();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("} catch (Throwable _e) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("throw Exceptions.sneakyThrow(_e);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_xtrycatchfinallyexpression = ListExtensions.map(CollectionLiterals.newArrayList(\"file1.ext\"), _function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("} catch (final Throwable _t) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (_t instanceof IOException) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_xtrycatchfinallyexpression = Collections.emptyList();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("} else {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("throw Exceptions.sneakyThrow(_t);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return _xtrycatchfinallyexpression;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void testClosureSneakyThrow_02() throws Exception { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("abstract class Foo {"); - _builder.newLine(); - _builder.append(" "); - _builder.append("def Object getFoo(String x) throws Exception"); - _builder.newLine(); - _builder.append(" "); - _builder.append("def bar() {"); - _builder.newLine(); - _builder.append(" "); - _builder.append("newArrayList.toMap[foo]"); - _builder.newLine(); - _builder.append(" "); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.Map;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Exceptions;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function1;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.IterableExtensions;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public abstract class Foo {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public abstract Object getFoo(final String x) throws Exception;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public Map bar() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function1 _function = (String it) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("try {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return this.getFoo(it);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("} catch (Throwable _e) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("throw Exceptions.sneakyThrow(_e);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return IterableExtensions.toMap(CollectionLiterals.newArrayList(), _function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void testNestedClosureWithIt() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("class X {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def foo() {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("val (String)=>String function = [ [String it | it].apply(it) ]"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("function.apply(\'foo\')"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function1;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class X {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public String foo() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("String _xblockexpression = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("{"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function1 _function = (String it) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function1 _function_1 = (String it_1) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return it_1;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return _function_1.apply(it);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function1 function = _function;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_xblockexpression = function.apply(\"foo\");"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return _xblockexpression;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void testNestedClosureSuperCall() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("class X {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def foo() {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("[| [| super.toString ].apply ].apply"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function0;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class X {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public String foo() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function0 _function = () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function0 _function_1 = () -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return super.toString();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return _function_1.apply();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return _function.apply();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void testFindFirstOnIt_01() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("class FindFirstOnIt {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def useExtension(Iterable it) {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("findFirst [ it !== null ]"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function1;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.IterableExtensions;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class FindFirstOnIt {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public T useExtension(final Iterable it) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function1 _function = (T it_1) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return Boolean.valueOf((it_1 != null));"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return IterableExtensions.findFirst(it, _function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void testAbstractIterator_03() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import java.util.Iterator"); - _builder.newLine(); - _builder.append("import com.google.common.collect.AbstractIterator"); - _builder.newLine(); - _builder.append("public class Foo {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def Iterator skipNulls(Iterator iter) {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("val AbstractIterator result = [|"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("iter.findFirst [ it !== null ] ?: self.endOfData"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("]"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("return result"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import com.google.common.collect.AbstractIterator;"); - _builder_1.newLine(); - _builder_1.append("import java.util.Iterator;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function1;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.IteratorExtensions;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class Foo {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public Iterator skipNulls(final Iterator iter) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final AbstractIterator _function = new AbstractIterator() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("@Override"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("protected T computeNext() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("T _elvis = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function1 _function = (T it) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return Boolean.valueOf((it != null));"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("T _findFirst = IteratorExtensions.findFirst(iter, _function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (_findFirst != null) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_elvis = _findFirst;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("} else {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("T _endOfData = this.endOfData();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_elvis = _endOfData;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return _elvis;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final AbstractIterator result = _function;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return result;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void testAbstractIterator_04() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import java.util.Iterator"); - _builder.newLine(); - _builder.append("import com.google.common.collect.AbstractIterator"); - _builder.newLine(); - _builder.append("class FindFirstOnIt {"); - _builder.newLine(); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def Iterator skipNulls(Iterator it) {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("val AbstractIterator result = [|"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("findFirst [ it != null ] ?: self.endOfData"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("]"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("return result"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import com.google.common.collect.AbstractIterator;"); - _builder_1.newLine(); - _builder_1.append("import java.util.Iterator;"); - _builder_1.newLine(); - _builder_1.append("import java.util.Objects;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function1;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.IteratorExtensions;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class FindFirstOnIt {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public Iterator skipNulls(final Iterator it) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final AbstractIterator _function = new AbstractIterator() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("@Override"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("protected T computeNext() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("T _elvis = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function1 _function = (T it_1) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return Boolean.valueOf((!Objects.equals(it_1, null)));"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("T _findFirst = IteratorExtensions.findFirst(it, _function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (_findFirst != null) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_elvis = _findFirst;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("} else {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("T _endOfData = this.endOfData();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_elvis = _endOfData;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return _elvis;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final AbstractIterator result = _function;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return result;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void testReturnType() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import test.ReturnTypeUsesTypeParameter"); - _builder.newLine(); - _builder.append("class MyClass implements ReturnTypeUsesTypeParameter {"); - _builder.newLine(); - _builder.newLine(); - _builder.append("\t"); - _builder.append("override accept(LocalName param) {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("null"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import test.ReturnTypeUsesTypeParameter;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class MyClass implements ReturnTypeUsesTypeParameter {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("@Override"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public ReturnTypeUsesTypeParameter.Inner accept(final LocalName param) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void testReturnType_02() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import test.ReturnTypeUsesTypeParameter"); - _builder.newLine(); - _builder.append("class MyClass implements ReturnTypeUsesTypeParameter {"); - _builder.newLine(); - _builder.newLine(); - _builder.append("\t"); - _builder.append("override accept(LocalName param) {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("[ if (true) it?.apply(param) ] "); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;"); - _builder_1.newLine(); - _builder_1.append("import test.ReturnTypeUsesTypeParameter;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class MyClass implements ReturnTypeUsesTypeParameter {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("@Override"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public ReturnTypeUsesTypeParameter.Inner accept(final LocalName param) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final ReturnTypeUsesTypeParameter.Inner _function = (Procedure1 it) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (true) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (it!=null) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("it.apply(param);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return _function;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void testReturnType_03() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import java.util.LinkedList"); - _builder.newLine(); - _builder.newLine(); - _builder.append("class B extends A {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def String client(CharSequence c) {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("client(m)"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("override m() {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("\'\'"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - _builder.newLine(); - _builder.append("abstract class A {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def CharSequence m() "); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class B extends A {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public String client(final CharSequence c) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return this.client(this.m());"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("@Override"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public CharSequence m() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return \"\";"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void testInnerTypeImports_1() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("class Foo extends types.SomeClassWithNestedInterface {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("override types.SomeClassWithNestedInterface.String convert(java.lang.String s) {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("return null;"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import types.SomeClassWithNestedInterface;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class Foo extends SomeClassWithNestedInterface {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("@Override"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public SomeClassWithNestedInterface.String convert(final java.lang.String s) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void testRecursiveLambda_01() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("public class Foo {"); - _builder.newLine(); - _builder.append(" "); - _builder.append("def void foo((String)=>String func) {"); - _builder.newLine(); - _builder.append(" \t"); - _builder.append("foo[self.apply(it)]"); - _builder.newLine(); - _builder.append(" "); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function1;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class Foo {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void foo(final Function1 func) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Function1 _function = new Function1() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("@Override"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public String apply(final String it) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return this.apply(it);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("this.foo(_function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void testRecursiveLambda_02() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("public class Foo {"); - _builder.newLine(); - _builder.append(" "); - _builder.append("def void foo(()=>void func) {"); - _builder.newLine(); - _builder.append(" \t"); - _builder.append("foo[|self.apply()]"); - _builder.newLine(); - _builder.append(" "); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Procedures.Procedure0;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class Foo {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void foo(final Procedure0 func) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Procedure0 _function = new Procedure0() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("@Override"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void apply() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("this.apply();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("this.foo(_function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void testXFunctionTypeRefAsSuperType_01() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("class Foo implements ()=>void {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("override apply() {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Procedures.Procedure0;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class Foo implements Procedure0 {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("@Override"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void apply() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void testXFunctionTypeRefAsSuperType_02() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("interface Foo extends ()=>void {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("override void apply()"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Procedures.Procedure0;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public interface Foo extends Procedure0 {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("@Override"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("void apply();"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void testXFunctionTypeRefAsSuperType_03() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("class Foo implements (String)=>void {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("override apply(String value) {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class Foo implements Procedure1 {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("@Override"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void apply(final String value) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void testXFunctionTypeRefAsSuperType_04() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("interface Foo extends (String)=>void {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("override void apply(String value)"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public interface Foo extends Procedure1 {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("@Override"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("void apply(final String value);"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void testXFunctionTypeRefAsSuperType_05() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("class Foo implements ((String)=>void)=>void {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("override apply((String)=>void procedure) {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class Foo implements Procedure1> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("@Override"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void apply(final Procedure1 procedure) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void testXFunctionTypeRefAsSuperType_06() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("interface Foo extends ((String)=>void)=>void {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("override void apply((String)=>void procedure)"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public interface Foo extends Procedure1> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("@Override"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("void apply(final Procedure1 procedure);"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void testXFunctionTypeRefAsSuperType_07() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("class Foo implements ()=>String {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("override apply() {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function0;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class Foo implements Function0 {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("@Override"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public String apply() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void testXFunctionTypeRefAsSuperType_08() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("interface Foo extends ()=>String {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("override String apply()"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function0;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public interface Foo extends Function0 {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("@Override"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("String apply();"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void testXFunctionTypeRefAsSuperType_09() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("class Foo implements ()=>(String)=>void {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("override apply() {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function0;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class Foo implements Function0> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("@Override"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public Procedure1 apply() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void testXFunctionTypeRefAsSuperType_10() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("interface Foo extends ()=>(String)=>void {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("override (String)=>void apply();"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function0;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public interface Foo extends Function0> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("@Override"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("Procedure1 apply();"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void testSuperCall_01() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("package x class Y extends Object {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("override boolean equals(Object p){"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("if (\'foo\' == p)"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("return true"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("else"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("super.equals(p) "); - _builder.newLine(); - _builder.append("\t"); - _builder.append("} "); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("package x;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("import java.util.Objects;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class Y {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("@Override"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public boolean equals(final Object p) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("boolean _xifexpression = false;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("boolean _equals = Objects.equals(\"foo\", p);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (_equals) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return true;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("} else {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_xifexpression = super.equals(p);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return _xifexpression;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void testSuperCall_03() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("package x"); - _builder.newLine(); - _builder.append("class B extends A {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("override getThing() {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("this.getThing(\'\')"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("\'\'.getThing"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("this.thing"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("\'\'.thing"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("thing"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("getThing(\'\')"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("super.getThing(\'\')"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("super.thing"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("super.getThing"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("super.getThing()"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - _builder.append("class A {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def String getThing() {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("getThing(\'\')"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def protected String getThing(String s) {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("return s"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("package x;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class B extends A {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("@Override"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public String getThing() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("String _xblockexpression = null;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("{"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("this.getThing(\"\");"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("this.getThing(\"\");"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("this.getThing();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("this.getThing(\"\");"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("this.getThing();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("this.getThing(\"\");"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("super.getThing(\"\");"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("super.getThing();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("super.getThing();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_xblockexpression = super.getThing();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return _xblockexpression;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - /** - * see https://bugs.eclipse.org/bugs/show_bug.cgi?id=395043 - */ - @Test - @Override - public void testOverriddenVarArgs() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("class B extends A {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("override foo(String x, String...args) {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("return x"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - _builder.append("abstract class A {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def String foo(String x, String...args)"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class B extends A {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("@Override"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public String foo(final String x, final String... args) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return x;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void testExpectationFromTypeParameter() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("import java.util.Set"); - _builder.newLine(); - _builder.append("import org.eclipse.xtext.common.types.JvmTypeParameter"); - _builder.newLine(); - _builder.append("import org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference"); - _builder.newLine(); - _builder.append("import org.eclipse.xtext.xbase.typesystem.util.TypeParameterSubstitutor"); - _builder.newLine(); - _builder.append("import org.eclipse.xtext.xbase.typesystem.references.ITypeReferenceOwner"); - _builder.newLine(); - _builder.newLine(); - _builder.append("class C extends TypeParameterSubstitutor> {"); - _builder.newLine(); - _builder.append("\t"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("new(ITypeReferenceOwner owner) {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("super(null, owner)"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("override substitute(LightweightTypeReference original) {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("original.accept(this, newHashSet)"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.newLine(); - _builder.append("\t"); - _builder.append("override protected createVisiting() {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("return newHashSet"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("import java.util.Set;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.common.types.JvmTypeParameter;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.typesystem.references.ITypeReferenceOwner;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.typesystem.util.TypeParameterSubstitutor;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class C extends TypeParameterSubstitutor> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public C(final ITypeReferenceOwner owner) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("super(null, owner);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("@Override"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public LightweightTypeReference substitute(final LightweightTypeReference original) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return original., LightweightTypeReference>accept(this, CollectionLiterals.newHashSet());"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("@Override"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("protected Set createVisiting() {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("return CollectionLiterals.newHashSet();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } - - @Test - @Override - public void testJavaKeywordsUsed() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("package foo;"); - _builder.newLine(); - _builder.newLine(); - _builder.append("public class Foo {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def void someMethod(String assert) {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("val synchronized = newArrayList(\'foo\')"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("for (volatile : synchronized) {"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("switch continue : volatile {"); - _builder.newLine(); - _builder.append("\t\t\t\t"); - _builder.append("case continue.length > 2 : synchronized.forEach(break | (break + continue).toString)"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("package foo;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("import java.util.ArrayList;"); - _builder_1.newLine(); - _builder_1.append("import java.util.function.Consumer;"); - _builder_1.newLine(); - _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("@SuppressWarnings(\"all\")"); - _builder_1.newLine(); - _builder_1.append("public class Foo {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("public void someMethod(final String assert_) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final ArrayList synchronized_ = CollectionLiterals.newArrayList(\"foo\");"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("for (final String volatile_ : synchronized_) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final String continue_ = volatile_;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("boolean _matched = false;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("int _length = continue_.length();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("boolean _greaterThan = (_length > 2);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("if (_greaterThan) {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("_matched=true;"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("final Consumer _function = (String break_) -> {"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("(break_ + continue_).toString();"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("};"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("synchronized_.forEach(_function);"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - this.assertCompilesTo(_builder, _builder_1); - } -} diff --git a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/java8/compiler/TryWithResourcesJava8Test.java b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/java8/compiler/TryWithResourcesJava8Test.java index 669745c9606..00efa634d46 100644 --- a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/java8/compiler/TryWithResourcesJava8Test.java +++ b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/java8/compiler/TryWithResourcesJava8Test.java @@ -10,10 +10,8 @@ import com.google.inject.Inject; import org.eclipse.xtend.core.tests.compiler.AbstractXtendCompilerTest; -import org.eclipse.xtend.core.tests.java8.Java8RuntimeInjectorProvider; import org.eclipse.xtend.core.xtend.XtendFile; import org.eclipse.xtend2.lib.StringConcatenation; -import org.eclipse.xtext.testing.InjectWith; import org.eclipse.xtext.testing.util.ParseHelper; import org.eclipse.xtext.testing.validation.ValidationTestHelper; import org.eclipse.xtext.xbase.XbasePackage; @@ -25,7 +23,6 @@ /** * @author Eva Poell - Initial contribution and API */ -@InjectWith(Java8RuntimeInjectorProvider.class) @SuppressWarnings("all") public class TryWithResourcesJava8Test extends AbstractXtendCompilerTest { @Inject diff --git a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/java8/macro/DeclarationsTest.java b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/java8/macro/DeclarationsTest.java index 58c647cb7ec..25bbda2c68f 100644 --- a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/java8/macro/DeclarationsTest.java +++ b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/java8/macro/DeclarationsTest.java @@ -9,19 +9,16 @@ package org.eclipse.xtend.core.tests.java8.macro; import org.eclipse.xtend.core.macro.declaration.CompilationUnitImpl; -import org.eclipse.xtend.core.tests.java8.Java8RuntimeInjectorProvider; import org.eclipse.xtend.lib.macro.declaration.InterfaceDeclaration; import org.eclipse.xtend.lib.macro.declaration.MethodDeclaration; import org.eclipse.xtend.lib.macro.declaration.TypeDeclaration; import org.eclipse.xtend2.lib.StringConcatenation; -import org.eclipse.xtext.testing.InjectWith; import org.eclipse.xtext.xbase.lib.Conversions; import org.eclipse.xtext.xbase.lib.IterableExtensions; import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; import org.junit.Assert; import org.junit.Test; -@InjectWith(Java8RuntimeInjectorProvider.class) @SuppressWarnings("all") public class DeclarationsTest extends org.eclipse.xtend.core.tests.macro.declaration.DeclarationsTest { @Test diff --git a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/java8/validation/Java8ValidationTest.java b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/java8/validation/Java8ValidationTest.java index fc7d419529f..f8c3dd886d6 100644 --- a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/java8/validation/Java8ValidationTest.java +++ b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/java8/validation/Java8ValidationTest.java @@ -10,12 +10,10 @@ import com.google.inject.Inject; import org.eclipse.xtend.core.tests.AbstractXtendTestCase; -import org.eclipse.xtend.core.tests.java8.Java8RuntimeInjectorProvider; import org.eclipse.xtend.core.xtend.XtendFile; import org.eclipse.xtend.core.xtend.XtendPackage; import org.eclipse.xtend2.lib.StringConcatenation; import org.eclipse.xtext.diagnostics.Severity; -import org.eclipse.xtext.testing.InjectWith; import org.eclipse.xtext.testing.validation.ValidationTestHelper; import org.eclipse.xtext.xbase.XbasePackage; import org.eclipse.xtext.xbase.lib.Exceptions; @@ -26,7 +24,6 @@ /** * @author Miro Spoenemann - Initial contribution and API */ -@InjectWith(Java8RuntimeInjectorProvider.class) @SuppressWarnings("all") public class Java8ValidationTest extends AbstractXtendTestCase { @Inject diff --git a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/validation/ModifierValidationTest.java b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/validation/ModifierValidationTest.java index 3063d8f72ee..84ebe82500a 100644 --- a/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/validation/ModifierValidationTest.java +++ b/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/validation/ModifierValidationTest.java @@ -370,7 +370,7 @@ public void testMethodInInterfaceAllowedModifiers() { this._validationTestHelper.assertNoError(this.memberInInterface(_builder_4.toString()), IssueCodes.INVALID_MODIFIER); StringConcatenation _builder_5 = new StringConcatenation(); _builder_5.append("static def foo() {}"); - this._validationTestHelper.assertError(this.memberInInterface(_builder_5.toString()), XtendPackage.Literals.XTEND_FUNCTION, IssueCodes.INVALID_MODIFIER); + this._validationTestHelper.assertNoError(this.memberInInterface(_builder_5.toString()), IssueCodes.INVALID_MODIFIER); StringConcatenation _builder_6 = new StringConcatenation(); _builder_6.append("abstract def int foo()"); this._validationTestHelper.assertNoErrors(this.memberInInterface(_builder_6.toString())); diff --git a/org.eclipse.xtend.core/src/org/eclipse/xtend/core/compiler/batch/XtendBatchCompiler.java b/org.eclipse.xtend.core/src/org/eclipse/xtend/core/compiler/batch/XtendBatchCompiler.java index c31cda2b436..8620d54152b 100644 --- a/org.eclipse.xtend.core/src/org/eclipse/xtend/core/compiler/batch/XtendBatchCompiler.java +++ b/org.eclipse.xtend.core/src/org/eclipse/xtend/core/compiler/batch/XtendBatchCompiler.java @@ -370,15 +370,22 @@ public String getJavaSourceVersion() { public void setJavaSourceVersion(final String javaSourceVersion) { JavaVersion javaVersion = JavaVersion.fromQualifier(javaSourceVersion); if(javaVersion == null) { - List qualifiers = Lists.newArrayList(); - for (JavaVersion version : JavaVersion.values()) - qualifiers.addAll(version.getAllQualifiers()); - + List qualifiers = supportedJavaVersions(); throw new IllegalArgumentException("Unknown Java Version Qualifier: '" + javaSourceVersion + "'. Valid values are: '" + Joiner.on(", ").join(qualifiers) + "'"); } generatorConfig.setJavaSourceVersion(javaVersion); } + private List supportedJavaVersions() { + List qualifiers = Lists.newArrayList(); + for (JavaVersion version : JavaVersion.values()) { + if (version.isAtLeast(JavaVersion.JAVA8)) { + qualifiers.addAll(version.getAllQualifiers()); + } + } + return qualifiers; + } + public void setVerbose(boolean verbose) { this.verbose = verbose; } diff --git a/org.eclipse.xtend.ide.tests/src/org/eclipse/xtend/ide/tests/compiler/JavaVersionSettingTest.xtend b/org.eclipse.xtend.ide.tests/src/org/eclipse/xtend/ide/tests/compiler/JavaVersionSettingTest.xtend index c45a9bd886d..0601d68a183 100644 --- a/org.eclipse.xtend.ide.tests/src/org/eclipse/xtend/ide/tests/compiler/JavaVersionSettingTest.xtend +++ b/org.eclipse.xtend.ide.tests/src/org/eclipse/xtend/ide/tests/compiler/JavaVersionSettingTest.xtend @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2015, 2017 itemis AG (http://www.itemis.eu) and others. + * Copyright (c) 2015, 2024 itemis AG (http://www.itemis.eu) and others. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. @@ -60,9 +60,9 @@ class JavaVersionSettingTest extends Assert { workbenchTestHelper.tearDown } - @Test def void testCompileWithJava5() { + @Test def void testCompileWithJava8() { workbenchTestHelper.tearDown - WorkbenchTestHelper.createPluginProject(WorkbenchTestHelper.TESTPROJECT_NAME, JavaVersion.JAVA5) + WorkbenchTestHelper.createPluginProject(WorkbenchTestHelper.TESTPROJECT_NAME, JavaVersion.JAVA8) val xtendFile = workbenchTestHelper.createFile('mypackage/OverrideTest.xtend', ''' package mypackage class B implements A { @@ -76,26 +76,7 @@ class JavaVersionSettingTest extends Assert { waitForBuild() assertNoErrors(xtendFile) val content = getJavaFileContent('xtend-gen/mypackage/B.java', xtendFile.project) - assertFalse("@Override annotation was generated, but it shouldn't.", content.contains('@Override')) - } - - @Test def void testCompileWithJava6() { - workbenchTestHelper.tearDown - WorkbenchTestHelper.createPluginProject(WorkbenchTestHelper.TESTPROJECT_NAME, JavaVersion.JAVA6) - val xtendFile = workbenchTestHelper.createFile('mypackage/OverrideTest.xtend', ''' - package mypackage - class B implements A { - override a() { - } - } - interface A { - def void a() - } - ''') - waitForBuild() - assertNoErrors(xtendFile) - val content = getJavaFileContent('xtend-gen/mypackage/B.java', xtendFile.project) - assertTrue("@Override annotation was not generated.", content.contains('@Override')) + assertTrue("@Override annotation not was generated.", content.contains('@Override')) } private def getJavaFileContent(String fileName, IProject project) { diff --git a/org.eclipse.xtend.ide.tests/xtend-gen/org/eclipse/xtend/ide/tests/compiler/JavaVersionSettingTest.java b/org.eclipse.xtend.ide.tests/xtend-gen/org/eclipse/xtend/ide/tests/compiler/JavaVersionSettingTest.java index aea6c763a45..fbc3d915d24 100644 --- a/org.eclipse.xtend.ide.tests/xtend-gen/org/eclipse/xtend/ide/tests/compiler/JavaVersionSettingTest.java +++ b/org.eclipse.xtend.ide.tests/xtend-gen/org/eclipse/xtend/ide/tests/compiler/JavaVersionSettingTest.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2015, 2017 itemis AG (http://www.itemis.eu) and others. + * Copyright (c) 2015, 2024 itemis AG (http://www.itemis.eu) and others. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. @@ -66,10 +66,10 @@ public void tearDown() { } @Test - public void testCompileWithJava5() { + public void testCompileWithJava8() { try { this.workbenchTestHelper.tearDown(); - WorkbenchTestHelper.createPluginProject(WorkbenchTestHelper.TESTPROJECT_NAME, JavaVersion.JAVA5); + WorkbenchTestHelper.createPluginProject(WorkbenchTestHelper.TESTPROJECT_NAME, JavaVersion.JAVA8); StringConcatenation _builder = new StringConcatenation(); _builder.append("package mypackage"); _builder.newLine(); @@ -94,42 +94,7 @@ public void testCompileWithJava5() { IResourcesSetupUtil.waitForBuild(); this.assertNoErrors(xtendFile); final String content = this.getJavaFileContent("xtend-gen/mypackage/B.java", xtendFile.getProject()); - Assert.assertFalse("@Override annotation was generated, but it shouldn\'t.", content.contains("@Override")); - } catch (Throwable _e) { - throw Exceptions.sneakyThrow(_e); - } - } - - @Test - public void testCompileWithJava6() { - try { - this.workbenchTestHelper.tearDown(); - WorkbenchTestHelper.createPluginProject(WorkbenchTestHelper.TESTPROJECT_NAME, JavaVersion.JAVA6); - StringConcatenation _builder = new StringConcatenation(); - _builder.append("package mypackage"); - _builder.newLine(); - _builder.append("class B implements A {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("override a() {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - _builder.append("interface A {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("def void a()"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - final IFile xtendFile = this.workbenchTestHelper.createFile("mypackage/OverrideTest.xtend", _builder.toString()); - IResourcesSetupUtil.waitForBuild(); - this.assertNoErrors(xtendFile); - final String content = this.getJavaFileContent("xtend-gen/mypackage/B.java", xtendFile.getProject()); - Assert.assertTrue("@Override annotation was not generated.", content.contains("@Override")); + Assert.assertTrue("@Override annotation not was generated.", content.contains("@Override")); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } diff --git a/org.eclipse.xtext.builder.standalone/src/org/eclipse/xtext/builder/standalone/compiler/CompilerConfiguration.java b/org.eclipse.xtext.builder.standalone/src/org/eclipse/xtext/builder/standalone/compiler/CompilerConfiguration.java index 281be42f51c..bb842f720f1 100644 --- a/org.eclipse.xtext.builder.standalone/src/org/eclipse/xtext/builder/standalone/compiler/CompilerConfiguration.java +++ b/org.eclipse.xtext.builder.standalone/src/org/eclipse/xtext/builder/standalone/compiler/CompilerConfiguration.java @@ -16,9 +16,9 @@ * @author Dennis Huebner - Initial contribution and API */ public class CompilerConfiguration { - private String sourceLevel = "1.5"; + private String sourceLevel = "8"; - private String targetLevel = "1.5"; + private String targetLevel = "8"; private boolean verbose; diff --git a/org.eclipse.xtext.purexbase.tests/src/org/eclipse/xtext/purexbase/tests/CompilerTest.java b/org.eclipse.xtext.purexbase.tests/src/org/eclipse/xtext/purexbase/tests/CompilerTest.java index 89a20ef5eb9..fd17696d772 100644 --- a/org.eclipse.xtext.purexbase.tests/src/org/eclipse/xtext/purexbase/tests/CompilerTest.java +++ b/org.eclipse.xtext.purexbase.tests/src/org/eclipse/xtext/purexbase/tests/CompilerTest.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2012, 2021 itemis AG (http://www.itemis.eu) and others. + * Copyright (c) 2012, 2024 itemis AG (http://www.itemis.eu) and others. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. @@ -278,45 +278,36 @@ public void closures() throws Exception { "f2.apply('simsalabim')\n" + "// SIMSALABIM (String)\n"; String expectation = - "import java.util.ArrayList;\n" + - "import org.eclipse.xtext.xbase.lib.CollectionLiterals;\n" + - "import org.eclipse.xtext.xbase.lib.Functions.Function1;\n" + - "import org.eclipse.xtext.xbase.lib.ListExtensions;\n" + - "\n" + - "@SuppressWarnings(\"all\")\n" + - "public class MyFile {\n" + - " public String myMethod() throws Throwable {\n" + - " String _xblockexpression = null;\n" + - " {\n" + - " final String x = \"Hello \";\n" + - " final Function1 _function = new Function1() {\n" + - " @Override\n" + - " public String apply(final String e) {\n" + - " return (x + e);\n" + - " }\n" + - " };\n" + - " final Function1 f = _function;\n" + - " f.apply(\"World!\");\n" + - " final ArrayList list = CollectionLiterals.newArrayList(\"a\", \"b\", \"c\");\n" + - " final Function1 _function_1 = new Function1() {\n" + - " @Override\n" + - " public String apply(final String e) {\n" + - " return e.toUpperCase();\n" + - " }\n" + - " };\n" + - " /* ListExtensions.map(list, _function_1); */\n" + - " final Function1 _function_2 = new Function1() {\n" + - " @Override\n" + - " public String apply(final String e) {\n" + - " return e.toUpperCase();\n" + - " }\n" + - " };\n" + - " final Function1 f2 = _function_2;\n" + - " _xblockexpression = f2.apply(\"simsalabim\");\n" + - " }\n" + - " return _xblockexpression;\n" + - " }\n" + - "}\n"; + "import java.util.ArrayList;\n" + + "import org.eclipse.xtext.xbase.lib.CollectionLiterals;\n" + + "import org.eclipse.xtext.xbase.lib.Functions.Function1;\n" + + "import org.eclipse.xtext.xbase.lib.ListExtensions;\n" + + "\n" + + "@SuppressWarnings(\"all\")\n" + + "public class MyFile {\n" + + " public String myMethod() throws Throwable {\n" + + " String _xblockexpression = null;\n" + + " {\n" + + " final String x = \"Hello \";\n" + + " final Function1 _function = (String e) -> {\n" + + " return (x + e);\n" + + " };\n" + + " final Function1 f = _function;\n" + + " f.apply(\"World!\");\n" + + " final ArrayList list = CollectionLiterals.newArrayList(\"a\", \"b\", \"c\");\n" + + " final Function1 _function_1 = (String e) -> {\n" + + " return e.toUpperCase();\n" + + " };\n" + + " /* ListExtensions.map(list, _function_1); */\n" + + " final Function1 _function_2 = (String e) -> {\n" + + " return e.toUpperCase();\n" + + " };\n" + + " final Function1 f2 = _function_2;\n" + + " _xblockexpression = f2.apply(\"simsalabim\");\n" + + " }\n" + + " return _xblockexpression;\n" + + " }\n" + + "}\n"; assertCompilesTo(source, expectation); } @@ -578,73 +569,70 @@ public void switchExpression() throws Exception { " })\n" + "// [a square : size=5, a circle : diameter=4, a rectangle : width=8 height=6] (List)\n"; String expectation = - "import java.util.ArrayList;\n" + - "import java.util.List;\n" + - "import java.util.Objects;\n" + - "import org.eclipse.xtext.purexbase.tests.data.Circle;\n" + - "import org.eclipse.xtext.purexbase.tests.data.Rectangle;\n" + - "import org.eclipse.xtext.purexbase.tests.data.Shape;\n" + - "import org.eclipse.xtext.xbase.lib.CollectionLiterals;\n" + - "import org.eclipse.xtext.xbase.lib.Functions.Function1;\n" + - "import org.eclipse.xtext.xbase.lib.IterableExtensions;\n" + - "import org.eclipse.xtext.xbase.lib.ListExtensions;\n" + - "\n" + - "@SuppressWarnings(\"all\")\n" + - "public class MyFile {\n" + - " public List myMethod() throws Throwable {\n" + - " List _xblockexpression = null;\n" + - " {\n" + - " final ArrayList list = CollectionLiterals.newArrayList(\"foo\", \"bar\", \"baz\");\n" + - " String _head = IterableExtensions.head(list);\n" + - " boolean _matched = false;\n" + - " if (Objects.equals(_head, \"foo\")) {\n" + - " _matched=true;\n" + - " /* \"it\\'s foo\" */\n" + - " }\n" + - " if (!_matched) {\n" + - " if (Objects.equals(_head, \"bar\")) {\n" + - " _matched=true;\n" + - " /* \"a bar\" */\n" + - " }\n" + - " }\n" + - " if (!_matched) {\n" + - " /* \"don\\'t know\" */\n" + - " }\n" + - " Rectangle _rectangle = new Rectangle(5, 5);\n" + - " Circle _circle = new Circle(4);\n" + - " Rectangle _rectangle_1 = new Rectangle(6, 8);\n" + - " final ArrayList list2 = CollectionLiterals.newArrayList(_rectangle, _circle, _rectangle_1);\n" + - " final Function1 _function = new Function1() {\n" + - " @Override\n" + - " public String apply(final Shape shape) {\n" + - " String _switchResult = null;\n" + - " boolean _matched = false;\n" + - " if (shape instanceof Circle) {\n" + - " _matched=true;\n" + - " _switchResult = (\"a circle : diameter=\" + Integer.valueOf(((Circle)shape).diameter));\n" + - " }\n" + - " if (!_matched) {\n" + - " if (shape instanceof Rectangle) {\n" + - " if ((((Rectangle)shape).height == ((Rectangle)shape).width)) {\n" + - " _matched=true;\n" + - " _switchResult = (\"a square : size=\" + Integer.valueOf(((Rectangle)shape).width));\n" + - " }\n" + - " }\n" + - " }\n" + - " if (!_matched) {\n" + - " if (shape instanceof Rectangle) {\n" + - " _matched=true;\n" + - " _switchResult = (((\"a rectangle : width=\" + Integer.valueOf(((Rectangle)shape).width)) + \", height=\") + Integer.valueOf(((Rectangle)shape).height));\n" + - " }\n" + - " }\n" + - " return _switchResult;\n" + - " }\n" + - " };\n" + - " _xblockexpression = ListExtensions.map(list2, _function);\n" + - " }\n" + - " return _xblockexpression;\n" + - " }\n" + - "}\n"; + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "import org.eclipse.xtext.purexbase.tests.data.Circle;\n" + + "import org.eclipse.xtext.purexbase.tests.data.Rectangle;\n" + + "import org.eclipse.xtext.purexbase.tests.data.Shape;\n" + + "import org.eclipse.xtext.xbase.lib.CollectionLiterals;\n" + + "import org.eclipse.xtext.xbase.lib.Functions.Function1;\n" + + "import org.eclipse.xtext.xbase.lib.IterableExtensions;\n" + + "import org.eclipse.xtext.xbase.lib.ListExtensions;\n" + + "\n" + + "@SuppressWarnings(\"all\")\n" + + "public class MyFile {\n" + + " public List myMethod() throws Throwable {\n" + + " List _xblockexpression = null;\n" + + " {\n" + + " final ArrayList list = CollectionLiterals.newArrayList(\"foo\", \"bar\", \"baz\");\n" + + " String _head = IterableExtensions.head(list);\n" + + " if (_head != null) {\n" + + " switch (_head) {\n" + + " case \"foo\":\n" + + " /* \"it\\'s foo\" */\n" + + " break;\n" + + " case \"bar\":\n" + + " /* \"a bar\" */\n" + + " break;\n" + + " default:\n" + + " /* \"don\\'t know\" */\n" + + " break;\n" + + " }\n" + + " } else {\n" + + " /* \"don\\'t know\" */\n" + + " }\n" + + " Rectangle _rectangle = new Rectangle(5, 5);\n" + + " Circle _circle = new Circle(4);\n" + + " Rectangle _rectangle_1 = new Rectangle(6, 8);\n" + + " final ArrayList list2 = CollectionLiterals.newArrayList(_rectangle, _circle, _rectangle_1);\n" + + " final Function1 _function = (Shape shape) -> {\n" + + " String _switchResult_1 = null;\n" + + " boolean _matched = false;\n" + + " if (shape instanceof Circle) {\n" + + " _matched=true;\n" + + " _switchResult_1 = (\"a circle : diameter=\" + Integer.valueOf(((Circle)shape).diameter));\n" + + " }\n" + + " if (!_matched) {\n" + + " if (shape instanceof Rectangle) {\n" + + " if ((((Rectangle)shape).height == ((Rectangle)shape).width)) {\n" + + " _matched=true;\n" + + " _switchResult_1 = (\"a square : size=\" + Integer.valueOf(((Rectangle)shape).width));\n" + + " }\n" + + " }\n" + + " }\n" + + " if (!_matched) {\n" + + " if (shape instanceof Rectangle) {\n" + + " _matched=true;\n" + + " _switchResult_1 = (((\"a rectangle : width=\" + Integer.valueOf(((Rectangle)shape).width)) + \", height=\") + Integer.valueOf(((Rectangle)shape).height));\n" + + " }\n" + + " }\n" + + " return _switchResult_1;\n" + + " };\n" + + " _xblockexpression = ListExtensions.map(list2, _function);\n" + + " }\n" + + " return _xblockexpression;\n" + + " }\n" + + "}\n"; assertCompilesTo(source, expectation); } @@ -695,29 +683,26 @@ public void typeCoercion() throws Exception { " */\n" + "val java.util.Comparator comparator = [a,b| a.length.compareTo(b.length)]\n"; String expectation = - "import java.util.Comparator;\n" + - "import java.util.List;\n" + - "import org.eclipse.xtext.xbase.lib.Conversions;\n" + - "\n" + - "@SuppressWarnings(\"all\")\n" + - "public class MyFile {\n" + - " public void myMethod() throws Throwable {\n" + - " \"string\".length();\n" + - " final Integer i = Integer.valueOf(\"string\".length());\n" + - " /* i; */\n" + - " Integer.valueOf(\"string\".length()).toString();\n" + - " \"string\".toCharArray();\n" + - " final List l = (List)Conversions.doWrapArray(\"string\".toCharArray());\n" + - " /* \"string\".toCharArray()[3]; */\n" + - " final Comparator _function = new Comparator() {\n" + - " @Override\n" + - " public int compare(final String a, final String b) {\n" + - " return Integer.valueOf(a.length()).compareTo(Integer.valueOf(b.length()));\n" + - " }\n" + - " };\n" + - " final Comparator comparator = _function;\n" + - " }\n" + - "}\n"; + "import java.util.Comparator;\n" + + "import java.util.List;\n" + + "import org.eclipse.xtext.xbase.lib.Conversions;\n" + + "\n" + + "@SuppressWarnings(\"all\")\n" + + "public class MyFile {\n" + + " public void myMethod() throws Throwable {\n" + + " \"string\".length();\n" + + " final Integer i = Integer.valueOf(\"string\".length());\n" + + " /* i; */\n" + + " Integer.valueOf(\"string\".length()).toString();\n" + + " \"string\".toCharArray();\n" + + " final List l = (List)Conversions.doWrapArray(\"string\".toCharArray());\n" + + " /* \"string\".toCharArray()[3]; */\n" + + " final Comparator _function = (String a, String b) -> {\n" + + " return Integer.valueOf(a.length()).compareTo(Integer.valueOf(b.length()));\n" + + " };\n" + + " final Comparator comparator = _function;\n" + + " }\n" + + "}\n"; assertCompilesTo(source, expectation); } diff --git a/org.eclipse.xtext.purexbase.tests/src/org/eclipse/xtext/purexbase/tests/PureXbaseInterpreterTest.java b/org.eclipse.xtext.purexbase.tests/src/org/eclipse/xtext/purexbase/tests/PureXbaseInterpreterTest.java index a4fe6320919..8f8d31607cf 100644 --- a/org.eclipse.xtext.purexbase.tests/src/org/eclipse/xtext/purexbase/tests/PureXbaseInterpreterTest.java +++ b/org.eclipse.xtext.purexbase.tests/src/org/eclipse/xtext/purexbase/tests/PureXbaseInterpreterTest.java @@ -17,7 +17,7 @@ import org.eclipse.xtext.xbase.XExpression; import org.eclipse.xtext.xbase.interpreter.IEvaluationResult; import org.eclipse.xtext.xbase.interpreter.IExpressionInterpreter; -import org.eclipse.xtext.xbase.testing.evaluation.AbstractXbaseEvaluationTest; +import org.eclipse.xtext.xbase.testing.evaluation.AbstractXbaseEvaluationTestEx; import org.junit.After; import org.junit.Assert; import org.junit.Ignore; @@ -31,7 +31,7 @@ */ @RunWith(XtextRunner.class) @InjectWith(PureXbaseInjectorProvider.class) -public class PureXbaseInterpreterTest extends AbstractXbaseEvaluationTest { +public class PureXbaseInterpreterTest extends AbstractXbaseEvaluationTestEx { @Inject private ParseHelper parseHelper; @@ -109,192 +109,6 @@ public XExpression expression(String string, boolean resolve) throws Exception { return model.getBlock(); } - @Test - @Override - public void testTryWithoutResources() throws Exception { - super.testTryWithoutResources(); - } - - @Test - @Override - public void testTryWithResources_easy() throws Exception { - super.testTryWithResources_easy(); - } - - @Test - @Override - public void testTryWithResources_lambda() throws Exception { - super.testTryWithResources_lambda(); - } - - @Test - @Override - public void testTryWithResources_2Resources() throws Exception { - super.testTryWithResources_2Resources(); - } - - @Test - @Override - public void testTryWithResources_2NestedResources() throws Exception { - super.testTryWithResources_2NestedResources(); - } - - @Test - @Override - public void testTryWithResources_2DiffResources() throws Exception { - super.testTryWithResources_2DiffResources(); - } - - @Test - @Override - public void testTryWithResources_if1() throws Exception { - super.testTryWithResources_if1(); - } - - @Test - @Override - public void testTryWithResources_if2() throws Exception { - super.testTryWithResources_if2(); - } - - @Test - @Override - public void testTryWithResources_userClass() throws Exception { - super.testTryWithResources_userClass(); - } - - @Test - @Override - public void testTryWithResources_isClosed1() throws Exception { - super.testTryWithResources_isClosed1(); - } - - @Test - @Override - public void testTryWithResources_isClosed2() throws Exception { - super.testTryWithResources_isClosed2(); - } - - @Test - @Override - public void testTryWithResources_userClassExceptionOnConstructor() throws Exception { - super.testTryWithResources_userClassExceptionOnConstructor(); - } - - @Test - @Override - public void testTryWithResources_userClassExceptionOnClose() throws Exception { - super.testTryWithResources_userClassExceptionOnClose(); - } - - @Test - @Override - public void testTryWithResources_userClassExceptionOnCloseStillCallEveryClose1() throws Exception { - super.testTryWithResources_userClassExceptionOnCloseStillCallEveryClose1(); - } - - @Test - @Override - public void testTryWithResources_userClassExceptionOnCloseStillCallEveryClose2() throws Exception { - super.testTryWithResources_userClassExceptionOnCloseStillCallEveryClose2(); - } - - @Test - @Override - public void testTryWithResources_userClassExceptionOnCloseStillCallEveryClose3() throws Exception { - super.testTryWithResources_userClassExceptionOnCloseStillCallEveryClose3(); - } - - @Test - @Override - public void testTryWithResources_finally() throws Exception { - super.testTryWithResources_finally(); - } - - @Test - @Override - public void testTryWithResources_catch() throws Exception { - super.testTryWithResources_catch(); - } - - @Test - @Override - public void testTryWithResources_catchFinally() throws Exception { - super.testTryWithResources_catchFinally(); - } - - @Test - @Override - public void testTryWithResources_ExceptionInBody() throws Exception { - super.testTryWithResources_ExceptionInBody(); - } - - @Test - @Override - public void testTryWithResources_2Resources_ExceptionInBody() throws Exception { - super.testTryWithResources_2Resources_ExceptionInBody(); - } - - @Test - @Override - public void testTryWithResources_2Resources_ExceptionOnClose() throws Exception { - super.testTryWithResources_2Resources_ExceptionOnClose(); - } - - @Test - @Override - public void testTryWithResources_2ResourcesCatch_01() throws Exception { - super.testTryWithResources_2ResourcesCatch_01(); - } - - @Test - @Override - public void testTryWithResources_2ResourcesCatch_02() throws Exception { - super.testTryWithResources_2ResourcesCatch_02(); - } - - @Test - @Override - public void testTernaryIf_1() throws Exception { - super.testTernaryIf_1(); - } - - @Test - @Override - public void testTernaryIf_2() throws Exception { - super.testTernaryIf_2(); - } - - @Test - @Override - public void testTernaryIf_3() throws Exception { - super.testTernaryIf_3(); - } - - @Test - @Override - public void testTernaryIf_4() throws Exception { - super.testTernaryIf_4(); - } - - @Test - @Override - public void testTernaryIf_5() throws Exception { - super.testTernaryIf_5(); - } - - @Test - @Override - public void testTernaryIf_6() throws Exception { - super.testTernaryIf_6(); - } - - @Test - @Override - public void testTernaryIf_7() throws Exception { - super.testTernaryIf_7(); - } - @Ignore @Test @Override diff --git a/org.eclipse.xtext.purexbase.tests/src/org/eclipse/xtext/purexbase/tests/XbaseIntegrationTest.java b/org.eclipse.xtext.purexbase.tests/src/org/eclipse/xtext/purexbase/tests/XbaseIntegrationTest.java index 41d921ea72f..c92192776e3 100644 --- a/org.eclipse.xtext.purexbase.tests/src/org/eclipse/xtext/purexbase/tests/XbaseIntegrationTest.java +++ b/org.eclipse.xtext.purexbase.tests/src/org/eclipse/xtext/purexbase/tests/XbaseIntegrationTest.java @@ -16,7 +16,7 @@ import org.eclipse.xtext.util.IAcceptor; import org.eclipse.xtext.xbase.testing.CompilationTestHelper; import org.eclipse.xtext.xbase.testing.CompilationTestHelper.Result; -import org.eclipse.xtext.xbase.testing.evaluation.AbstractXbaseEvaluationTest; +import org.eclipse.xtext.xbase.testing.evaluation.AbstractXbaseEvaluationTestEx; import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; @@ -26,7 +26,7 @@ @RunWith(XtextRunner.class) @InjectWith(PureXbaseInjectorProvider.class) -public class XbaseIntegrationTest extends AbstractXbaseEvaluationTest { +public class XbaseIntegrationTest extends AbstractXbaseEvaluationTestEx { @Inject private CompilationTestHelper helper; @@ -62,22 +62,6 @@ public void testImplicitOneArgClosure_01() throws Exception { super.testImplicitOneArgClosure_01(); } - @Override - @Test - @Ignore("Wrong type") - public void testReturnExpression_07() throws Exception { - assertEvaluatesTo(null, "return if (true) while(false) ('foo'+'bar').length else null"); - assertEvaluatesTo(null, "return if (false) while(false) ('foo'+'bar').length else null"); - } - - @Override - @Test - @Ignore("Wrong type") - public void testReturnExpression_08() throws Exception { - assertEvaluatesTo(null, "return if (true) while(false) ('foo'+'bar').length else 'zonk'"); - assertEvaluatesTo("zonk", "return if (false) while(false) ('foo'+'bar').length else 'zonk'"); - } - /** * @since 2.5 */ @@ -96,147 +80,4 @@ public void testReturnExpression_08() throws Exception { "if (Boolean.FALSE) return 1L"); } - @Test - @Override - public void testTryWithoutResources() throws Exception { - super.testTryWithoutResources(); - } - - @Test - @Override - public void testTryWithResources_easy() throws Exception { - super.testTryWithResources_easy(); - } - - @Test - @Override - public void testTryWithResources_lambda() throws Exception { - super.testTryWithResources_lambda(); - } - - @Test - @Override - public void testTryWithResources_2Resources() throws Exception { - super.testTryWithResources_2Resources(); - } - - @Test - @Override - public void testTryWithResources_2NestedResources() throws Exception { - super.testTryWithResources_2NestedResources(); - } - - @Test - @Override - public void testTryWithResources_2DiffResources() throws Exception { - super.testTryWithResources_2DiffResources(); - } - - @Test - @Override - public void testTryWithResources_if1() throws Exception { - super.testTryWithResources_if1(); - } - - @Test - @Override - public void testTryWithResources_if2() throws Exception { - super.testTryWithResources_if2(); - } - - @Test - @Override - public void testTryWithResources_userClass() throws Exception { - super.testTryWithResources_userClass(); - } - - @Test - @Override - public void testTryWithResources_isClosed1() throws Exception { - super.testTryWithResources_isClosed1(); - } - - @Test - @Override - public void testTryWithResources_isClosed2() throws Exception { - super.testTryWithResources_isClosed2(); - } - - @Test - @Override - public void testTryWithResources_userClassExceptionOnConstructor() throws Exception { - super.testTryWithResources_userClassExceptionOnConstructor(); - } - - @Test - @Override - public void testTryWithResources_userClassExceptionOnClose() throws Exception { - super.testTryWithResources_userClassExceptionOnClose(); - } - - @Test - @Override - public void testTryWithResources_userClassExceptionOnCloseStillCallEveryClose1() throws Exception { - super.testTryWithResources_userClassExceptionOnCloseStillCallEveryClose1(); - } - - @Test - @Override - public void testTryWithResources_userClassExceptionOnCloseStillCallEveryClose2() throws Exception { - super.testTryWithResources_userClassExceptionOnCloseStillCallEveryClose2(); - } - - @Test - @Override - public void testTryWithResources_userClassExceptionOnCloseStillCallEveryClose3() throws Exception { - super.testTryWithResources_userClassExceptionOnCloseStillCallEveryClose3(); - } - - @Test - @Override - public void testTryWithResources_finally() throws Exception { - super.testTryWithResources_finally(); - } - - @Test - @Override - public void testTryWithResources_catch() throws Exception { - super.testTryWithResources_catch(); - } - - @Test - @Override - public void testTryWithResources_catchFinally() throws Exception { - super.testTryWithResources_catchFinally(); - } - - @Test - @Override - public void testTryWithResources_ExceptionInBody() throws Exception { - super.testTryWithResources_ExceptionInBody(); - } - - @Test - @Override - public void testTryWithResources_2Resources_ExceptionInBody() throws Exception { - super.testTryWithResources_2Resources_ExceptionInBody(); - } - - @Test - @Override - public void testTryWithResources_2Resources_ExceptionOnClose() throws Exception { - super.testTryWithResources_2Resources_ExceptionOnClose(); - } - - @Test - @Override - public void testTryWithResources_2ResourcesCatch_01() throws Exception { - super.testTryWithResources_2ResourcesCatch_01(); - } - - @Test - @Override - public void testTryWithResources_2ResourcesCatch_02() throws Exception { - super.testTryWithResources_2ResourcesCatch_02(); - } } diff --git a/org.eclipse.xtext.tests/src/org/eclipse/xtext/util/JavaVersionTest.java b/org.eclipse.xtext.tests/src/org/eclipse/xtext/util/JavaVersionTest.java index 4799939da1d..2f0d6fd0aeb 100644 --- a/org.eclipse.xtext.tests/src/org/eclipse/xtext/util/JavaVersionTest.java +++ b/org.eclipse.xtext.tests/src/org/eclipse/xtext/util/JavaVersionTest.java @@ -43,11 +43,11 @@ public void testFromQualifier() { assertEquals(JavaVersion.JAVA9, JavaVersion.fromQualifier("1.9")); assertEquals(JavaVersion.JAVA8, JavaVersion.fromQualifier("8")); assertEquals(JavaVersion.JAVA8, JavaVersion.fromQualifier("1.8")); - assertEquals(JavaVersion.JAVA7, JavaVersion.fromQualifier("7")); - assertEquals(JavaVersion.JAVA7, JavaVersion.fromQualifier("1.7")); - assertEquals(JavaVersion.JAVA6, JavaVersion.fromQualifier("6")); - assertEquals(JavaVersion.JAVA6, JavaVersion.fromQualifier("1.6")); - assertEquals(JavaVersion.JAVA5, JavaVersion.fromQualifier("1.5")); + assertNull(JavaVersion.fromQualifier("7")); + assertNull(JavaVersion.fromQualifier("1.7")); + assertNull(JavaVersion.fromQualifier("6")); + assertNull(JavaVersion.fromQualifier("1.6")); + assertNull(JavaVersion.fromQualifier("1.5")); assertNull(JavaVersion.fromQualifier("1.4")); assertNull(JavaVersion.fromQualifier("5")); assertNull(JavaVersion.fromQualifier(null)); diff --git a/org.eclipse.xtext.ui.testing/src/org/eclipse/xtext/ui/testing/util/JavaProjectSetupUtil.java b/org.eclipse.xtext.ui.testing/src/org/eclipse/xtext/ui/testing/util/JavaProjectSetupUtil.java index 518a637f71c..498cea35f2b 100644 --- a/org.eclipse.xtext.ui.testing/src/org/eclipse/xtext/ui/testing/util/JavaProjectSetupUtil.java +++ b/org.eclipse.xtext.ui.testing/src/org/eclipse/xtext/ui/testing/util/JavaProjectSetupUtil.java @@ -380,6 +380,7 @@ public static void addJreClasspathEntry(IJavaProject javaProject, String bree, b private static boolean isJava7Default = false; + @Deprecated public static void makeJava7Default() { if (!isJava7Default) { IExecutionEnvironmentsManager manager = JavaRuntime.getExecutionEnvironmentsManager(); diff --git a/org.eclipse.xtext.ui.tests/src-longrunning/org/eclipse/xtext/ui/tests/refactoring/ProgressReportingTest.java b/org.eclipse.xtext.ui.tests/src-longrunning/org/eclipse/xtext/ui/tests/refactoring/ProgressReportingTest.java index 3b18902f3bb..99a9e06e27b 100644 --- a/org.eclipse.xtext.ui.tests/src-longrunning/org/eclipse/xtext/ui/tests/refactoring/ProgressReportingTest.java +++ b/org.eclipse.xtext.ui.tests/src-longrunning/org/eclipse/xtext/ui/tests/refactoring/ProgressReportingTest.java @@ -123,15 +123,13 @@ public void testProgressReportOfRenameCommonDir() throws Exception { + "BeginTask Performing changes... (1000)\n" + "Worked 41 (2041.0)\n" + "Worked 42 (2083.0)\n" - + "Worked 20 (2103.0)\n" - + "Worked 21 (2124.0)\n" - + "Worked 42 (2166.0)\n" + + "Worked 79 (2162.0)\n" + + "Worked 4 (2166.0)\n" + "Worked 84 (2250.0)\n" + "Worked 41 (2291.0)\n" + "Worked 42 (2333.0)\n" - + "Worked 20 (2353.0)\n" - + "Worked 21 (2374.0)\n" - + "Worked 42 (2416.0)\n" + + "Worked 79 (2412.0)\n" + + "Worked 4 (2416.0)\n" + "Worked 84 (2500.0)\n" + "Worked 5 (2505.0)\n" + "Worked 125 (2630.0)\n" diff --git a/org.eclipse.xtext.util/src/org/eclipse/xtext/util/JavaVersion.java b/org.eclipse.xtext.util/src/org/eclipse/xtext/util/JavaVersion.java index f38f2a21d27..741837fe8e4 100644 --- a/org.eclipse.xtext.util/src/org/eclipse/xtext/util/JavaVersion.java +++ b/org.eclipse.xtext.util/src/org/eclipse/xtext/util/JavaVersion.java @@ -19,22 +19,36 @@ */ public enum JavaVersion { + /* + * Implemenatation note: The deprecated enum constants cannot be removed since the ordinals of all + * subsequent enum constants would change. + */ + /** * Java 5 language enhancements: generics, simplified for-loop, autoboxing and unboxing, enums, varargs, static * import, annotations. + * + * @deprecated Not supported anymore. Defaults to Java8. */ - JAVA5("Java 5", new String[] {"1.5"}, "J2SE-1.5", "-1.5", Constants.JAVA5), + @Deprecated + JAVA5("Java 8", new String[] {"1.8", "8"}, "JavaSE-1.8", "-1.8", Constants.JAVA8), /** * Java 6 language enhancements: Override annotations for implemented methods. + * + * @deprecated Not supported anymore. Defaults to Java8. */ - JAVA6("Java 6", new String[] {"1.6", "6"}, "JavaSE-1.6", "-1.6", Constants.JAVA6), + @Deprecated + JAVA6("Java 8", new String[] {"1.8", "8"}, "JavaSE-1.8", "-1.8", Constants.JAVA8), /** * Java 7 language enhancements: extended numeric literals, switch over strings, type inference, try-with-resources, * catch multiple exceptions. + * + * @deprecated Not supported anymore. Defaults to Java8. */ - JAVA7("Java 7", new String[] {"1.7", "7"}, "JavaSE-1.7", "-1.7", Constants.JAVA7), + @Deprecated + JAVA7("Java 8", new String[] {"1.8", "8"}, "JavaSE-1.8", "-1.8", Constants.JAVA8), /** * Java 8 language enhancements: lambda expressions, better type inference, more flexible annotations. @@ -67,9 +81,7 @@ public enum JavaVersion { private static final class Constants { private static final int MAJOR_VERSION_1_5 = 49; private static final int MINOR_VERSION_0 = 0; - private static final long JAVA5 = ((long)MAJOR_VERSION_1_5 << 16) + MINOR_VERSION_0; - private static final long JAVA6 = ((long)(MAJOR_VERSION_1_5 + 1) << 16) + MINOR_VERSION_0; - private static final long JAVA7 = ((long)(MAJOR_VERSION_1_5 + 2) << 16) + MINOR_VERSION_0; + private static final long JAVA8 = ((long)(MAJOR_VERSION_1_5 + 3) << 16) + MINOR_VERSION_0; private static final long JAVA9 = ((long)(MAJOR_VERSION_1_5 + 4) << 16) + MINOR_VERSION_0; private static final long JAVA10 = ((long)(MAJOR_VERSION_1_5 + 5) << 16) + MINOR_VERSION_0; @@ -108,9 +120,12 @@ public static JavaVersion fromQualifier(String qualifier) { } public static JavaVersion fromBree(String bree) { - for (JavaVersion version : JavaVersion.values()) { - if (version.bree.equals(bree)) - return version; + JavaVersion[] values = JavaVersion.values(); + // iterate backwards since it's a fair assumption that we'll use a more recent java version + for(int i = values.length - 1; i >= 0; i--) { + JavaVersion candidate = values[i]; + if (candidate.bree.equals(bree)) + return candidate; } return null; } @@ -152,4 +167,5 @@ public boolean isAtLeast(JavaVersion other) { public long toJdtClassFileConstant() { return jdtClassFileConstant; } + } diff --git a/org.eclipse.xtext.xbase.testing/META-INF/MANIFEST.MF b/org.eclipse.xtext.xbase.testing/META-INF/MANIFEST.MF index dfed2f58cc4..7748b505862 100644 --- a/org.eclipse.xtext.xbase.testing/META-INF/MANIFEST.MF +++ b/org.eclipse.xtext.xbase.testing/META-INF/MANIFEST.MF @@ -14,7 +14,7 @@ Require-Bundle: org.eclipse.xtext;bundle-version="2.36.0", org.eclipse.core.runtime;bundle-version="3.24.100" Bundle-ActivationPolicy: lazy Export-Package: org.eclipse.xtext.xbase.testing;version="2.36.0", - org.eclipse.xtext.xbase.testing.evaluation;version="2.36.0";x-friends:="org.eclipse.xtext.xbase.tests,org.eclipse.xtext.purexbase.tests", + org.eclipse.xtext.xbase.testing.evaluation;version="2.36.0";x-friends:="org.eclipse.xtext.xbase.tests,org.eclipse.xtext.purexbase.tests,org.eclipse.xtend.core.tests", org.eclipse.xtext.xbase.testing.typesystem;version="2.36.0";x-internal:=true, testdata;version="2.36.0";x-friends:="org.eclipse.xtext.xbase.tests,org.eclipse.xtend.core.tests", testdata.a;version="2.36.0";x-internal:=true, diff --git a/org.eclipse.xtext.xbase.testing/deprecated/org/eclipse/xtext/xbase/testing/OnTheFlyJavaCompiler.java b/org.eclipse.xtext.xbase.testing/deprecated/org/eclipse/xtext/xbase/testing/OnTheFlyJavaCompiler.java index e92b1dcb608..0f47f9679cc 100644 --- a/org.eclipse.xtext.xbase.testing/deprecated/org/eclipse/xtext/xbase/testing/OnTheFlyJavaCompiler.java +++ b/org.eclipse.xtext.xbase.testing/deprecated/org/eclipse/xtext/xbase/testing/OnTheFlyJavaCompiler.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2017 itemis AG (http://www.itemis.eu) and others. + * Copyright (c) 2011, 2024 itemis AG (http://www.itemis.eu) and others. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. @@ -371,7 +371,7 @@ public void initializeClassPath() { } protected String getComplianceLevelArg() { - JavaVersion javaVersion = JavaVersion.JAVA5; + JavaVersion javaVersion = JavaVersion.JAVA8; if (generatorConfigProvider != null) { GeneratorConfig generatorConfig = generatorConfigProvider.get(null); javaVersion = generatorConfig.getJavaSourceVersion(); diff --git a/org.eclipse.xtext.xbase.testing/src/org/eclipse/xtext/xbase/testing/InMemoryJavaCompiler.java b/org.eclipse.xtext.xbase.testing/src/org/eclipse/xtext/xbase/testing/InMemoryJavaCompiler.java index c0d6f3de980..e0a6abac066 100644 --- a/org.eclipse.xtext.xbase.testing/src/org/eclipse/xtext/xbase/testing/InMemoryJavaCompiler.java +++ b/org.eclipse.xtext.xbase.testing/src/org/eclipse/xtext/xbase/testing/InMemoryJavaCompiler.java @@ -22,6 +22,7 @@ import java.util.Map; import java.util.Set; +import org.apache.log4j.Logger; import org.eclipse.jdt.core.compiler.CategorizedProblem; import org.eclipse.jdt.core.compiler.CharOperation; import org.eclipse.jdt.internal.compiler.ClassFile; @@ -45,6 +46,9 @@ * @since 2.9 */ public class InMemoryJavaCompiler { + + private static final Logger logger = Logger.getLogger(InMemoryJavaCompiler.class); + private static class ClassLoaderBasedNameEnvironment implements INameEnvironment { private final ClassLoader classLoader; @@ -211,6 +215,8 @@ public InMemoryJavaCompiler(ClassLoader parent, CompilerOptions compilerOptions) } /** + * Sets the Java version that this compiler works with. Defaults to Java8 and attempts to set older versions are ignored. + * * @since 2.11 */ public long setJavaVersion(JavaVersion javaVersion) { @@ -221,6 +227,10 @@ public long setJavaVersion(JavaVersion javaVersion) { } private long toClassFmt(JavaVersion version) { + if (JavaVersion.JAVA8.compareTo(version) > 0) { + logger.error("Ignored attempt to set JavaVersion lower than 8", new IllegalArgumentException(version.toString())); + version = JavaVersion.JAVA8; + } return version.toJdtClassFileConstant(); } diff --git a/org.eclipse.xtext.xbase.testing/src/org/eclipse/xtext/xbase/testing/OnTheFlyJavaCompiler2.java b/org.eclipse.xtext.xbase.testing/src/org/eclipse/xtext/xbase/testing/OnTheFlyJavaCompiler2.java index 510d0ac6a15..5f1b036ba14 100644 --- a/org.eclipse.xtext.xbase.testing/src/org/eclipse/xtext/xbase/testing/OnTheFlyJavaCompiler2.java +++ b/org.eclipse.xtext.xbase.testing/src/org/eclipse/xtext/xbase/testing/OnTheFlyJavaCompiler2.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2015, 2020 itemis AG (http://www.itemis.eu) and others. + * Copyright (c) 2015, 2024 itemis AG (http://www.itemis.eu) and others. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. @@ -11,6 +11,7 @@ import java.lang.reflect.InvocationTargetException; import java.util.Map; +import org.apache.log4j.Logger; import org.eclipse.jdt.core.compiler.CategorizedProblem; import org.eclipse.xtend2.lib.StringConcatenation; import org.eclipse.xtext.util.JavaVersion; @@ -33,16 +34,18 @@ */ @Singleton public class OnTheFlyJavaCompiler2 { + private static final Logger logger = Logger.getLogger(OnTheFlyJavaCompiler2.class); + private InMemoryJavaCompiler inMemoryCompiler; private JavaVersion javaVersion; /** - * Creates a new OnTheFlyCompiler that accepts Java6 compliant code. + * Creates a new OnTheFlyCompiler that accepts Java8 compliant code. */ @Inject public OnTheFlyJavaCompiler2(ClassLoader scope) { - this(scope, JavaVersion.JAVA6); + this(scope, JavaVersion.JAVA8); } public OnTheFlyJavaCompiler2(ClassLoader scope, JavaVersion version) { @@ -51,9 +54,15 @@ public OnTheFlyJavaCompiler2(ClassLoader scope, JavaVersion version) { } /** + * Sets the Java version that this compiler works with. Defaults to Java8 and attempts to set older versions are ignored. + * * @since 2.11 */ public void setJavaVersion(JavaVersion version) { + if (JavaVersion.JAVA8.compareTo(version) > 0) { + logger.error("Ignored attempt to set JavaVersion lower than 8", new IllegalArgumentException(version.toString())); + version = JavaVersion.JAVA8; + } inMemoryCompiler.setJavaVersion(version); javaVersion = version; } diff --git a/org.eclipse.xtext.xbase.testing/src/org/eclipse/xtext/xbase/testing/evaluation/AbstractXbaseEvaluationTest.java b/org.eclipse.xtext.xbase.testing/src/org/eclipse/xtext/xbase/testing/evaluation/AbstractXbaseEvaluationTest.java index 09a3920de39..8564e799142 100644 --- a/org.eclipse.xtext.xbase.testing/src/org/eclipse/xtext/xbase/testing/evaluation/AbstractXbaseEvaluationTest.java +++ b/org.eclipse.xtext.xbase.testing/src/org/eclipse/xtext/xbase/testing/evaluation/AbstractXbaseEvaluationTest.java @@ -628,14 +628,14 @@ public abstract class AbstractXbaseEvaluationTest extends Assert { @Ignore("Wrong type") @Test public void testReturnExpression_07() throws Exception { - assertEvaluatesTo(null, "return if (true) while(false) ('foo'+'bar').length else null"); - assertEvaluatesTo(null, "return if (false) while(false) ('foo'+'bar').length else null"); + assertEvaluatesTo(null, "return if (Boolean.TRUE) while(Boolean.FALSE) ('foo'+'bar').length else null"); + assertEvaluatesTo(null, "return if (Boolean.FALSE) while(Boolean.FALSE) ('foo'+'bar').length else null"); } @Ignore("Wrong type") @Test public void testReturnExpression_08() throws Exception { - assertEvaluatesTo(null, "return if (true) while(false) ('foo'+'bar').length else 'zonk'"); - assertEvaluatesTo("zonk", "return if (false) while(false) ('foo'+'bar').length else 'zonk'"); + assertEvaluatesTo(null, "return if (Boolean.TRUE) while(Boolean.FALSE) ('foo'+'bar').length else 'zonk'"); + assertEvaluatesTo("zonk", "return if (Boolean.FALSE) while(Boolean.FALSE) ('foo'+'bar').length else 'zonk'"); } @Test public void testReturnExpression_09() throws Exception { @@ -765,75 +765,75 @@ public abstract class AbstractXbaseEvaluationTest extends Assert { } @Test public void testLessThanOnIntegers_01() throws Exception { - assertEvaluatesTo(Boolean.valueOf(true), "3<4"); + assertEvaluatesTo(Boolean.TRUE, "3<4"); } @Test public void testLessThanOnIntegers_02() throws Exception { - assertEvaluatesTo(Boolean.valueOf(false), "4<3"); + assertEvaluatesTo(Boolean.FALSE, "4<3"); } @Test public void testGreaterThanOnIntegers_01() throws Exception { - assertEvaluatesTo(Boolean.valueOf(true), "4>3"); + assertEvaluatesTo(Boolean.TRUE, "4>3"); } @Test public void testGreaterThanOnIntegers_02() throws Exception { - assertEvaluatesTo(Boolean.valueOf(false), "3>4"); + assertEvaluatesTo(Boolean.FALSE, "3>4"); } @Test public void testLessEqualsThanOnIntegers_01() throws Exception { - assertEvaluatesTo(Boolean.valueOf(true), "3<=3"); + assertEvaluatesTo(Boolean.TRUE, "3<=3"); } @Test public void testLessEqualsThanOnIntegers_02() throws Exception { - assertEvaluatesTo(Boolean.valueOf(true), "3<=4"); + assertEvaluatesTo(Boolean.TRUE, "3<=4"); } @Test public void testLessEqualsThanOnIntegers_03() throws Exception { - assertEvaluatesTo(Boolean.valueOf(false), "4<=3"); + assertEvaluatesTo(Boolean.FALSE, "4<=3"); } @Test public void testGreaterEqualsThanOnIntegers_01() throws Exception { - assertEvaluatesTo(Boolean.valueOf(true), "3>=3"); + assertEvaluatesTo(Boolean.TRUE, "3>=3"); } @Test public void testGreaterEqualsThanOnIntegers_02() throws Exception { - assertEvaluatesTo(Boolean.valueOf(true), "4>=3"); + assertEvaluatesTo(Boolean.TRUE, "4>=3"); } @Test public void testGreaterEqualsThanOnIntegers_03() throws Exception { - assertEvaluatesTo(Boolean.valueOf(false), "3>=4"); + assertEvaluatesTo(Boolean.FALSE, "3>=4"); } @Test public void testOrOnBooleans_01() throws Exception { - assertEvaluatesTo(Boolean.valueOf(true), "true||false"); + assertEvaluatesTo(Boolean.TRUE, "true||false"); } @Test public void testOrOnBooleans_02() throws Exception { - assertEvaluatesTo(Boolean.valueOf(true), "false||true"); + assertEvaluatesTo(Boolean.TRUE, "false||true"); } @Test public void testOrOnBooleans_03() throws Exception { - assertEvaluatesTo(Boolean.valueOf(true), "true||true"); + assertEvaluatesTo(Boolean.TRUE, "true||true"); } @Test public void testOrOnBooleans_04() throws Exception { - assertEvaluatesTo(Boolean.valueOf(false), "false||false"); + assertEvaluatesTo(Boolean.FALSE, "false||false"); } @Test public void testAndOnBooleans_01() throws Exception { - assertEvaluatesTo(Boolean.valueOf(true), "true&&true"); + assertEvaluatesTo(Boolean.TRUE, "true&&true"); } @Test public void testAndOnBooleans_02() throws Exception { - assertEvaluatesTo(Boolean.valueOf(false), "false&&true"); + assertEvaluatesTo(Boolean.FALSE, "false&&true"); } @Test public void testAndOnBooleans_03() throws Exception { - assertEvaluatesTo(Boolean.valueOf(false), "true&&false"); + assertEvaluatesTo(Boolean.FALSE, "true&&false"); } @Test public void testAndOnBooleans_04() throws Exception { - assertEvaluatesTo(Boolean.valueOf(false), "false&&false"); + assertEvaluatesTo(Boolean.FALSE, "false&&false"); } @Test public void testNull() throws Exception { @@ -1447,7 +1447,7 @@ public abstract class AbstractXbaseEvaluationTest extends Assert { * @since 2.29 */ @Test @Ignore public void testTryWithResources_finally() throws Exception { - assertEvaluatesTo("[new, body, finally, close]", + assertEvaluatesTo("[new, body, close, finally]", "var testdata.ClosableWithList result\n" + "try (var a = new testdata.ClosableWithList()){\n" + " a.add(\"body\")\n" + @@ -1462,7 +1462,7 @@ public abstract class AbstractXbaseEvaluationTest extends Assert { * @since 2.29 */ @Test @Ignore public void testTryWithResources_catch() throws Exception { - assertEvaluatesTo("[new, catch, close]", + assertEvaluatesTo("[new, close, catch]", "val java.util.List result = newArrayList\n" + "try (val a = new testdata.ClosableWithList(result);\n" + " var b = new testdata.ClosableWithListExceptionOnConstr) {\n" + @@ -1477,7 +1477,7 @@ public abstract class AbstractXbaseEvaluationTest extends Assert { * @since 2.29 */ @Test @Ignore public void testTryWithResources_catchFinally() throws Exception { - assertEvaluatesTo("[new, body, catch b, finally, close]", + assertEvaluatesTo("[new, body, close, catch b, finally]", "var testdata.ClosableWithList result\n" + "try (var a = new testdata.ClosableWithList();\n" + " var b = new testdata.ClosableWithListExceptionOnAdd()) {\n" + @@ -1534,7 +1534,7 @@ public abstract class AbstractXbaseEvaluationTest extends Assert { * @since 2.29 */ @Test @Ignore public void testTryWithResources_2ResourcesCatch_01() throws Exception { - assertEvaluatesTo("[new, catch, close]", //b.add would invoke NullPointerExcpt, but InstExc came first and is caught + assertEvaluatesTo("[new, close, catch]", //b.add would invoke NullPointerExcpt, but InstExc came first and is caught "var java.util.List result = newArrayList\n" + "try (var a = new testdata.ClosableWithList(result);\n" + " var b = new testdata.ClosableWithListExceptionOnConstr) {\n" + diff --git a/org.eclipse.xtext.xbase.testing/src/org/eclipse/xtext/xbase/testing/evaluation/AbstractXbaseEvaluationTestEx.java b/org.eclipse.xtext.xbase.testing/src/org/eclipse/xtext/xbase/testing/evaluation/AbstractXbaseEvaluationTestEx.java new file mode 100644 index 00000000000..7ecc9fac57a --- /dev/null +++ b/org.eclipse.xtext.xbase.testing/src/org/eclipse/xtext/xbase/testing/evaluation/AbstractXbaseEvaluationTestEx.java @@ -0,0 +1,203 @@ +/******************************************************************************* + * Copyright (c) 2024 Sebastian Zarnekow and others. + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + *******************************************************************************/ +package org.eclipse.xtext.xbase.testing.evaluation; + +import org.junit.Test; + +/** + * @since 2.36 + */ +public abstract class AbstractXbaseEvaluationTestEx extends AbstractXbaseEvaluationTest { + + @Test + @Override + public void testTryWithoutResources() throws Exception { + super.testTryWithoutResources(); + } + + @Test + @Override + public void testTryWithResources_easy() throws Exception { + super.testTryWithResources_easy(); + } + + @Test + @Override + public void testTryWithResources_lambda() throws Exception { + super.testTryWithResources_lambda(); + } + + @Test + @Override + public void testTryWithResources_2Resources() throws Exception { + super.testTryWithResources_2Resources(); + } + + @Test + @Override + public void testTryWithResources_2NestedResources() throws Exception { + super.testTryWithResources_2NestedResources(); + } + + @Test + @Override + public void testTryWithResources_2DiffResources() throws Exception { + super.testTryWithResources_2DiffResources(); + } + + @Test + @Override + public void testTryWithResources_if1() throws Exception { + super.testTryWithResources_if1(); + } + + @Test + @Override + public void testTryWithResources_if2() throws Exception { + super.testTryWithResources_if2(); + } + + @Test + @Override + public void testTryWithResources_userClass() throws Exception { + super.testTryWithResources_userClass(); + } + + @Test + @Override + public void testTryWithResources_isClosed1() throws Exception { + super.testTryWithResources_isClosed1(); + } + + @Test + @Override + public void testTryWithResources_isClosed2() throws Exception { + super.testTryWithResources_isClosed2(); + } + + @Test + @Override + public void testTryWithResources_userClassExceptionOnConstructor() throws Exception { + super.testTryWithResources_userClassExceptionOnConstructor(); + } + + @Test + @Override + public void testTryWithResources_userClassExceptionOnClose() throws Exception { + super.testTryWithResources_userClassExceptionOnClose(); + } + + @Test + @Override + public void testTryWithResources_userClassExceptionOnCloseStillCallEveryClose1() throws Exception { + super.testTryWithResources_userClassExceptionOnCloseStillCallEveryClose1(); + } + + @Test + @Override + public void testTryWithResources_userClassExceptionOnCloseStillCallEveryClose2() throws Exception { + super.testTryWithResources_userClassExceptionOnCloseStillCallEveryClose2(); + } + + @Test + @Override + public void testTryWithResources_userClassExceptionOnCloseStillCallEveryClose3() throws Exception { + super.testTryWithResources_userClassExceptionOnCloseStillCallEveryClose3(); + } + + @Test + @Override + public void testTryWithResources_finally() throws Exception { + super.testTryWithResources_finally(); + } + + @Test + @Override + public void testTryWithResources_catch() throws Exception { + super.testTryWithResources_catch(); + } + + @Test + @Override + public void testTryWithResources_catchFinally() throws Exception { + super.testTryWithResources_catchFinally(); + } + + @Test + @Override + public void testTryWithResources_ExceptionInBody() throws Exception { + super.testTryWithResources_ExceptionInBody(); + } + + @Test + @Override + public void testTryWithResources_2Resources_ExceptionInBody() throws Exception { + super.testTryWithResources_2Resources_ExceptionInBody(); + } + + @Test + @Override + public void testTryWithResources_2Resources_ExceptionOnClose() throws Exception { + super.testTryWithResources_2Resources_ExceptionOnClose(); + } + + @Test + @Override + public void testTryWithResources_2ResourcesCatch_01() throws Exception { + super.testTryWithResources_2ResourcesCatch_01(); + } + + @Test + @Override + public void testTryWithResources_2ResourcesCatch_02() throws Exception { + super.testTryWithResources_2ResourcesCatch_02(); + } + + @Test + @Override + public void testTernaryIf_1() throws Exception { + super.testTernaryIf_1(); + } + + @Test + @Override + public void testTernaryIf_2() throws Exception { + super.testTernaryIf_2(); + } + + @Test + @Override + public void testTernaryIf_3() throws Exception { + super.testTernaryIf_3(); + } + + @Test + @Override + public void testTernaryIf_4() throws Exception { + super.testTernaryIf_4(); + } + + @Test + @Override + public void testTernaryIf_5() throws Exception { + super.testTernaryIf_5(); + } + + @Test + @Override + public void testTernaryIf_6() throws Exception { + super.testTernaryIf_6(); + } + + @Test + @Override + public void testTernaryIf_7() throws Exception { + super.testTernaryIf_7(); + } +} diff --git a/org.eclipse.xtext.xbase.tests/META-INF/MANIFEST.MF b/org.eclipse.xtext.xbase.tests/META-INF/MANIFEST.MF index bf60b4135bf..c620ddf2e18 100644 --- a/org.eclipse.xtext.xbase.tests/META-INF/MANIFEST.MF +++ b/org.eclipse.xtext.xbase.tests/META-INF/MANIFEST.MF @@ -22,6 +22,8 @@ Bundle-Vendor: Eclipse Xtext Export-Package: org.eclipse.xtext.xbase.tests;version="2.36.0", org.eclipse.xtext.xbase.tests.interpreter;version="2.36.0" Import-Package: jakarta.inject;version="2.0.0", + org.aopalliance.aop;version="[1.0.0,2.0.0)", + org.aopalliance.intercept;version="[1.0.0,2.0.0)", org.apache.log4j;version="1.2.24", org.junit;version="4.13.2", org.junit.rules;version="4.13.2", diff --git a/org.eclipse.xtext.xbase.tests/build.properties b/org.eclipse.xtext.xbase.tests/build.properties index 4fd57d3ddb2..a1552c47c7f 100644 --- a/org.eclipse.xtext.xbase.tests/build.properties +++ b/org.eclipse.xtext.xbase.tests/build.properties @@ -4,7 +4,6 @@ bin.includes = META-INF/,\ somelib/sample.jar src.includes = about.html source.. = src,\ - testdata,\ suites,\ testdata,\ smoke-suites,\ diff --git a/org.eclipse.xtext.xbase.tests/longrunning/src/org/eclipse/xtext/xbase/tests/typesystem/AbstractBatchTypeResolverTest.java b/org.eclipse.xtext.xbase.tests/longrunning/src/org/eclipse/xtext/xbase/tests/typesystem/AbstractBatchTypeResolverTest.java index 4ddb98bda04..4f8a3894f65 100644 --- a/org.eclipse.xtext.xbase.tests/longrunning/src/org/eclipse/xtext/xbase/tests/typesystem/AbstractBatchTypeResolverTest.java +++ b/org.eclipse.xtext.xbase.tests/longrunning/src/org/eclipse/xtext/xbase/tests/typesystem/AbstractBatchTypeResolverTest.java @@ -62,15 +62,15 @@ public LightweightTypeReference resolvesTo(String expression, String type) { while (allContents.hasNext()) { EObject content = allContents.next(); if (content instanceof XConstructorCall) { - InternalEObject constructor = (InternalEObject) ((XConstructorCall) content) + InternalEObject constructor = (InternalEObject) content .eGet(XbasePackage.Literals.XCONSTRUCTOR_CALL__CONSTRUCTOR, false); - Assert.assertNotNull(((XConstructorCall) content).toString(), constructor); - Assert.assertFalse(((XConstructorCall) content).toString(), constructor.eIsProxy()); + Assert.assertNotNull(content.toString(), constructor); + Assert.assertFalse(content.toString(), constructor.eIsProxy()); } else if (content instanceof XAbstractFeatureCall) { - InternalEObject feature = (InternalEObject) ((XAbstractFeatureCall) content) + InternalEObject feature = (InternalEObject) content .eGet(XbasePackage.Literals.XABSTRACT_FEATURE_CALL__FEATURE, false); - Assert.assertNotNull(((XAbstractFeatureCall) content).toString(), feature); - Assert.assertFalse(((XAbstractFeatureCall) content).toString(), feature.eIsProxy()); + Assert.assertNotNull(content.toString(), feature); + Assert.assertFalse(content.toString(), feature.eIsProxy()); if (((XAbstractFeatureCall) content).getImplicitReceiver() != null) { InternalEObject implicitFeature = (InternalEObject) ((XAbstractFeatureCall) content).getImplicitReceiver() .eGet(XbasePackage.Literals.XABSTRACT_FEATURE_CALL__FEATURE, false); diff --git a/org.eclipse.xtext.xbase.tests/pom.xml b/org.eclipse.xtext.xbase.tests/pom.xml index 00fefa36ab0..15f77775ed4 100644 --- a/org.eclipse.xtext.xbase.tests/pom.xml +++ b/org.eclipse.xtext.xbase.tests/pom.xml @@ -10,5 +10,158 @@ eclipse-test-plugin Xtext Xbase Tests + + + + + xtext-202203 + + + target-platform-classifier + xtext-r202203 + + + + + + org.eclipse.tycho + target-platform-configuration + + + + + + eclipse-plugin + org.eclipse.jdt.compiler.apt + 0.0.0 + + + eclipse-plugin + org.eclipse.jdt.compiler.tool + 0.0.0 + + + + + + + + + + xtext-202206 + + + target-platform-classifier + xtext-r202206 + + + + + + org.eclipse.tycho + target-platform-configuration + + + + + + eclipse-plugin + org.eclipse.jdt.compiler.apt + 0.0.0 + + + eclipse-plugin + org.eclipse.jdt.compiler.tool + 0.0.0 + + + + + + + + + + xtext-202209 + + + target-platform-classifier + xtext-r202209 + + + + + + org.eclipse.tycho + target-platform-configuration + + + + + + eclipse-plugin + org.eclipse.jdt.compiler.apt + 0.0.0 + + + eclipse-plugin + org.eclipse.jdt.compiler.tool + 0.0.0 + + + + + + + + + + xtext-202212 + + + target-platform-classifier + xtext-r202212 + + + + + + org.eclipse.tycho + target-platform-configuration + + + + + + eclipse-plugin + org.eclipse.jdt.compiler.apt + 0.0.0 + + + eclipse-plugin + org.eclipse.jdt.compiler.tool + 0.0.0 + + + + + + + + + diff --git a/org.eclipse.xtext.xbase.tests/src/org/eclipse/xtext/xbase/tests/compiler/AbstractOutputComparingCompilerTests.java b/org.eclipse.xtext.xbase.tests/src/org/eclipse/xtext/xbase/tests/compiler/AbstractOutputComparingCompilerTests.java index 8db3e1900c7..e9c6820d304 100644 --- a/org.eclipse.xtext.xbase.tests/src/org/eclipse/xtext/xbase/tests/compiler/AbstractOutputComparingCompilerTests.java +++ b/org.eclipse.xtext.xbase.tests/src/org/eclipse/xtext/xbase/tests/compiler/AbstractOutputComparingCompilerTests.java @@ -16,7 +16,6 @@ import org.eclipse.xtext.xbase.compiler.XbaseCompiler; import org.eclipse.xtext.xbase.compiler.output.FakeTreeAppendable; import org.eclipse.xtext.xbase.compiler.output.ITreeAppendable; -import org.eclipse.xtext.xbase.lib.Pair; import org.eclipse.xtext.xbase.tests.AbstractXbaseTestCase; import org.eclipse.xtext.xbase.typesystem.IBatchTypeResolver; import org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference; @@ -100,18 +99,6 @@ protected void compilesTo(final CharSequence xbaseCode, final CharSequence resul assertCompilesTo(result, xbaseCode, javaVersion); } - protected void compilesTo(final CharSequence xbaseCode, final CharSequence result, - Pair minAndMaxVersion) throws Exception { - int min = minAndMaxVersion.getKey().ordinal(); - int max = minAndMaxVersion.getValue().ordinal(); - if (min > max) - throw new IllegalArgumentException(); - for (int i = min; i <= max; i++) { - JavaVersion version = JavaVersion.values()[i]; - assertCompilesTo(result, xbaseCode, version); - } - } - protected void compilesTo(final CharSequence xbaseCode, final CharSequence result, GeneratorConfig generatorConfig) throws Exception { assertCompilesTo(result, xbaseCode, generatorConfig); diff --git a/org.eclipse.xtext.xbase.tests/src/org/eclipse/xtext/xbase/tests/compiler/CompilationTestHelperTest.java b/org.eclipse.xtext.xbase.tests/src/org/eclipse/xtext/xbase/tests/compiler/CompilationTestHelperTest.java index 274c09c4c53..d4b228b0ca3 100644 --- a/org.eclipse.xtext.xbase.tests/src/org/eclipse/xtext/xbase/tests/compiler/CompilationTestHelperTest.java +++ b/org.eclipse.xtext.xbase.tests/src/org/eclipse/xtext/xbase/tests/compiler/CompilationTestHelperTest.java @@ -42,8 +42,7 @@ public class CompilationTestHelperTest extends AbstractJvmModelTest { private FileExtensionProvider extensionProvider; @Test - public void testSwitchJavaVersion6() throws Exception { - compilationTestHelper.setJavaVersion(JavaVersion.JAVA6); + public void testSwitchJavaVersion8() throws Exception { String source = "{\n" + " val s = \"\"\n" + @@ -54,99 +53,31 @@ public void testSwitchJavaVersion6() throws Exception { "}\n"; compilationTestHelper.compile(source, it -> { String expectation = - "import java.util.Objects;\n" + - "\n" + - "@SuppressWarnings(\"all\")\n" + - "public class Test {\n" + - " public String doStuff(final String s) {\n" + - " String _xblockexpression = null;\n" + - " {\n" + - " final String s_1 = \"\";\n" + - " String _switchResult = null;\n" + - " boolean _matched = false;\n" + - " if (Objects.equals(s_1, \"foo\")) {\n" + - " _matched=true;\n" + - " _switchResult = \"foo\";\n" + - " }\n" + - " if (!_matched) {\n" + - " _switchResult = \"bar\";\n" + - " }\n" + - " _xblockexpression = _switchResult;\n" + - " }\n" + - " return _xblockexpression;\n" + - " }\n" + - "}\n"; - Assert.assertEquals(expectation, Strings.toUnixLineSeparator(it.getSingleGeneratedCode())); - it.getCompiledClass(); - }); - } - - @Test - public void testSwitchJavaVersion7() throws Exception { - compilationTestHelper.setJavaVersion(JavaVersion.JAVA7); - String source = - "{\n" + - " val s = \"\"\n" + - " switch (s) {\n" + - " case \"foo\": \"foo\"\n" + - " default: \"bar\"\n" + - " }\n" + - "}\n"; - compilationTestHelper.compile(source, it -> { - String expectation = - "@SuppressWarnings(\"all\")\n" + - "public class Test {\n" + - " public String doStuff(final String s) {\n" + - " String _xblockexpression = null;\n" + - " {\n" + - " final String s_1 = \"\";\n" + - " String _switchResult = null;\n" + - " if (s_1 != null) {\n" + - " switch (s_1) {\n" + - " case \"foo\":\n" + - " _switchResult = \"foo\";\n" + - " break;\n" + - " default:\n" + - " _switchResult = \"bar\";\n" + - " break;\n" + - " }\n" + - " } else {\n" + - " _switchResult = \"bar\";\n" + - " }\n" + - " _xblockexpression = _switchResult;\n" + - " }\n" + - " return _xblockexpression;\n" + - " }\n" + - "}\n"; - Assert.assertEquals(expectation, Strings.toUnixLineSeparator(it.getSingleGeneratedCode())); - it.getCompiledClass(); - }); - } - - @Test - public void testLambdaJavaVersion6() throws Exception { - compilationTestHelper.setJavaVersion(JavaVersion.JAVA6); - String source = - "{\n" + - " val f = [ int i | i + 1 ]\n" + - "}\n"; - compilationTestHelper.compile(source, it -> { - String expectation = - "import org.eclipse.xtext.xbase.lib.Functions.Function1;\n" + - "\n" + - "@SuppressWarnings(\"all\")\n" + - "public class Test {\n" + - " public String doStuff(final String s) {\n" + - " final Function1 _function = new Function1() {\n" + - " @Override\n" + - " public Integer apply(final Integer i) {\n" + - " return Integer.valueOf((i + 1));\n" + - " }\n" + - " };\n" + - " final Function1 f = _function;\n" + - " return null;\n" + - " }\n" + - "}\n"; + "@SuppressWarnings(\"all\")\n" + + "public class Test {\n" + + " public String doStuff(final String s) {\n" + + " String _xblockexpression = null;\n" + + " {\n" + + " final String s_1 = \"\";\n" + + " String _switchResult = null;\n" + + " if (s_1 != null) {\n" + + " switch (s_1) {\n" + + " case \"foo\":\n" + + " _switchResult = \"foo\";\n" + + " break;\n" + + " default:\n" + + " _switchResult = \"bar\";\n" + + " break;\n" + + " }\n" + + " } else {\n" + + " _switchResult = \"bar\";\n" + + " }\n" + + " _xblockexpression = _switchResult;\n" + + " }\n" + + " return _xblockexpression;\n" + + " }\n" + + "}\n" + + ""; Assert.assertEquals(expectation, Strings.toUnixLineSeparator(it.getSingleGeneratedCode())); it.getCompiledClass(); }); diff --git a/org.eclipse.xtext.xbase.tests/src/org/eclipse/xtext/xbase/tests/compiler/Compiler2Tests.java b/org.eclipse.xtext.xbase.tests/src/org/eclipse/xtext/xbase/tests/compiler/Compiler2Tests.java index d63c335fd6f..c39e36641df 100644 --- a/org.eclipse.xtext.xbase.tests/src/org/eclipse/xtext/xbase/tests/compiler/Compiler2Tests.java +++ b/org.eclipse.xtext.xbase.tests/src/org/eclipse/xtext/xbase/tests/compiler/Compiler2Tests.java @@ -8,11 +8,7 @@ */ package org.eclipse.xtext.xbase.tests.compiler; -import org.eclipse.xtext.util.JavaVersion; -import org.eclipse.xtext.xbase.compiler.GeneratorConfig; import org.eclipse.xtext.xbase.compiler.output.FakeTreeAppendable; -import org.eclipse.xtext.xbase.lib.ObjectExtensions; -import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; import org.junit.Test; public class Compiler2Tests extends AbstractOutputComparingCompilerTests { @@ -241,13 +237,10 @@ public void testBug371321_2() throws Exception { public void testNewThread() throws Exception { compilesTo( "new Thread [| ]\n", - "\n" + - "final Runnable _function = new Runnable() {\n" + - " public void run() {\n" + - " }\n" + - "};\n" + - "Thread _thread = new Thread(_function);\n" + - "return _thread;\n"); + "final Runnable _function = () -> {\n" + + "};\n" + + "Thread _thread = new Thread(_function);\n" + + "return _thread;"); } @Test @@ -450,26 +443,21 @@ public void testSwitchScopes_Bug470586_01() throws Exception { " println(it)\n" + " ]\n" + "}\n", - "\n" + - "final java.util.List list = java.util.Collections.unmodifiableList(org.eclipse.xtext.xbase.lib.CollectionLiterals.newArrayList(\"1\", \"2\"));\n" + - "final java.util.function.Consumer _function = new java.util.function.Consumer() {\n" + - " public void accept(final String it) {\n" + - " String _switchResult = null;\n" + - " boolean _matched = false;\n" + - " if (it instanceof CharSequence) {\n" + - " _matched=true;\n" + - " _switchResult = it;\n" + - " }\n" + - " final String res = _switchResult;\n" + - " }\n" + - "};\n" + - "list.forEach(_function);\n" + - "final java.util.function.Consumer _function_1 = new java.util.function.Consumer() {\n" + - " public void accept(final String it) {\n" + - " org.eclipse.xtext.xbase.lib.InputOutput.println(it);\n" + - " }\n" + - "};\n" + - "list.forEach(_function_1);\n"); + "final java.util.List list = java.util.Collections.unmodifiableList(org.eclipse.xtext.xbase.lib.CollectionLiterals.newArrayList(\"1\", \"2\"));\n" + + "final java.util.function.Consumer _function = (String it) -> {\n" + + " String _switchResult = null;\n" + + " boolean _matched = false;\n" + + " if (it instanceof CharSequence) {\n" + + " _matched=true;\n" + + " _switchResult = it;\n" + + " }\n" + + " final String res = _switchResult;\n" + + "};\n" + + "list.forEach(_function);\n" + + "final java.util.function.Consumer _function_1 = (String it) -> {\n" + + " org.eclipse.xtext.xbase.lib.InputOutput.println(it);\n" + + "};\n" + + "list.forEach(_function_1);"); } @Test @@ -487,29 +475,24 @@ public void testSwitchScopes_Bug470586_02() throws Exception { " println(it)\n" + " ]\n" + "}\n", - "\n" + - "final java.util.List list = java.util.Collections.unmodifiableList(org.eclipse.xtext.xbase.lib.CollectionLiterals.newArrayList(\"1\", \"2\"));\n" + - "final java.util.function.Consumer _function = new java.util.function.Consumer() {\n" + - " public void accept(final String it) {\n" + - " String _switchResult = null;\n" + - " boolean _matched = false;\n" + - " if (it instanceof CharSequence) {\n" + - " _matched=true;\n" + - " _switchResult = it;\n" + - " }\n" + - " if (!_matched) {\n" + - " _switchResult = \"\";\n" + - " }\n" + - " final String res = _switchResult;\n" + - " }\n" + - "};\n" + - "list.forEach(_function);\n" + - "final java.util.function.Consumer _function_1 = new java.util.function.Consumer() {\n" + - " public void accept(final String it) {\n" + - " org.eclipse.xtext.xbase.lib.InputOutput.println(it);\n" + - " }\n" + - "};\n" + - "list.forEach(_function_1);\n"); + "final java.util.List list = java.util.Collections.unmodifiableList(org.eclipse.xtext.xbase.lib.CollectionLiterals.newArrayList(\"1\", \"2\"));\n" + + "final java.util.function.Consumer _function = (String it) -> {\n" + + " String _switchResult = null;\n" + + " boolean _matched = false;\n" + + " if (it instanceof CharSequence) {\n" + + " _matched=true;\n" + + " _switchResult = it;\n" + + " }\n" + + " if (!_matched) {\n" + + " _switchResult = \"\";\n" + + " }\n" + + " final String res = _switchResult;\n" + + "};\n" + + "list.forEach(_function);\n" + + "final java.util.function.Consumer _function_1 = (String it) -> {\n" + + " org.eclipse.xtext.xbase.lib.InputOutput.println(it);\n" + + "};\n" + + "list.forEach(_function_1);"); } @Test @@ -527,36 +510,31 @@ public void testSwitchScopes_Bug470586_03() throws Exception { " println(it)\n" + " ]\n" + "}\n", - "\n" + - "final java.util.List list = java.util.Collections.unmodifiableList(org.eclipse.xtext.xbase.lib.CollectionLiterals.newArrayList(\"1\", \"2\"));\n" + - "final java.util.function.Consumer _function = new java.util.function.Consumer() {\n" + - " public void accept(final String it) {\n" + - " String _switchResult = null;\n" + - " boolean _matched = false;\n" + - " if (it instanceof String) {\n" + - " _matched=true;\n" + - " }\n" + - " if (!_matched) {\n" + - " if (it instanceof CharSequence) {\n" + - " _matched=true;\n" + - " }\n" + - " }\n" + - " if (_matched) {\n" + - " _switchResult = it;\n" + - " }\n" + - " if (!_matched) {\n" + - " _switchResult = \"\";\n" + - " }\n" + - " final String res = _switchResult;\n" + - " }\n" + - "};\n" + - "list.forEach(_function);\n" + - "final java.util.function.Consumer _function_1 = new java.util.function.Consumer() {\n" + - " public void accept(final String it) {\n" + - " org.eclipse.xtext.xbase.lib.InputOutput.println(it);\n" + - " }\n" + - "};\n" + - "list.forEach(_function_1);\n"); + "final java.util.List list = java.util.Collections.unmodifiableList(org.eclipse.xtext.xbase.lib.CollectionLiterals.newArrayList(\"1\", \"2\"));\n" + + "final java.util.function.Consumer _function = (String it) -> {\n" + + " String _switchResult = null;\n" + + " boolean _matched = false;\n" + + " if (it instanceof String) {\n" + + " _matched=true;\n" + + " }\n" + + " if (!_matched) {\n" + + " if (it instanceof CharSequence) {\n" + + " _matched=true;\n" + + " }\n" + + " }\n" + + " if (_matched) {\n" + + " _switchResult = it;\n" + + " }\n" + + " if (!_matched) {\n" + + " _switchResult = \"\";\n" + + " }\n" + + " final String res = _switchResult;\n" + + "};\n" + + "list.forEach(_function);\n" + + "final java.util.function.Consumer _function_1 = (String it) -> {\n" + + " org.eclipse.xtext.xbase.lib.InputOutput.println(it);\n" + + "};\n" + + "list.forEach(_function_1);"); } @Test @@ -592,27 +570,18 @@ public void testFallThroughSwitch_2() throws Exception { " 'lalala'\n" + " }\n" + "}\n", - "\n" + - "String _switchResult = null;\n" + - "final String x = \"lalala\";\n" + - "boolean _matched = false;\n" + - "if (java.util.Objects.equals(x, \"a\")) {\n" + - " _matched=true;\n" + - "}\n" + - "if (!_matched) {\n" + - " if (java.util.Objects.equals(x, \"b\")) {\n" + - " _matched=true;\n" + - " }\n" + - "}\n" + - "if (!_matched) {\n" + - " if (java.util.Objects.equals(x, \"c\")) {\n" + - " _matched=true;\n" + - " }\n" + - "}\n" + - "if (_matched) {\n" + - " _switchResult = \"lalala\";\n" + - "}\n" + - "return _switchResult;\n"); + "String _switchResult = null;\n" + + "final String x = \"lalala\";\n" + + "if (x != null) {\n" + + " switch (x) {\n" + + " case \"a\":\n" + + " case \"b\":\n" + + " case \"c\":\n" + + " _switchResult = \"lalala\";\n" + + " break;\n" + + " }\n" + + "}\n" + + "return _switchResult;"); } @Test @@ -650,25 +619,20 @@ public void testFallThroughSwitch_4() throws Exception { " 'lalala'\n" + " }\n" + "}\n", - "\n" + - "String _switchResult = null;\n" + - "final String x = \"lalala\";\n" + - "boolean _matched = false;\n" + - "if (java.util.Objects.equals(x, \"a\")) {\n" + - " _matched=true;\n" + - "}\n" + - "if (!_matched) {\n" + - " if (java.util.Objects.equals(x, \"b\")) {\n" + - " _matched=true;\n" + - " }\n" + - "}\n" + - "if (_matched) {\n" + - " _switchResult = \"lalala\";\n" + - "}\n" + - "if (!_matched) {\n" + - " _switchResult = \"lalala\";\n" + - "}\n" + - "return _switchResult;\n"); + "String _switchResult = null;\n" + + "final String x = \"lalala\";\n" + + "if (x != null) {\n" + + " switch (x) {\n" + + " case \"a\":\n" + + " case \"b\":\n" + + " default:\n" + + " _switchResult = \"lalala\";\n" + + " break;\n" + + " }\n" + + "} else {\n" + + " _switchResult = \"lalala\";\n" + + "}\n" + + "return _switchResult;"); } @Test @@ -1007,11 +971,6 @@ public void testEmptySwitch_10() throws Exception { @Test public void testEmptySwitch_11() throws Exception { - GeneratorConfig _generatorConfig = new GeneratorConfig(); - final Procedure1 _function = (GeneratorConfig it) -> { - it.setJavaSourceVersion(JavaVersion.JAVA8); - }; - GeneratorConfig _doubleArrow = ObjectExtensions. operator_doubleArrow(_generatorConfig, _function); compilesTo( "{\n" + " val String x = null\n" + @@ -1029,8 +988,7 @@ public void testEmptySwitch_11() throws Exception { " }\n" + " _xblockexpression = _switchResult;\n" + "}\n" + - "return _xblockexpression;\n", - _doubleArrow); + "return _xblockexpression;\n"); } @Test @@ -1225,14 +1183,11 @@ public void testBasicForLoop_8() throws Exception { "{\n" + " [| for (;;) {} ]\n" + "}\n", - "\n" + - "final org.eclipse.xtext.xbase.lib.Procedures.Procedure0 _function = new org.eclipse.xtext.xbase.lib.Procedures.Procedure0() {\n" + - " public void apply() {\n" + - " for (;;) {\n" + - " }\n" + - " }\n" + - "};\n" + - "return _function;\n"); + "final org.eclipse.xtext.xbase.lib.Procedures.Procedure0 _function = () -> {\n" + + " for (;;) {\n" + + " }\n" + + "};\n" + + "return _function;"); } @Test @@ -1260,18 +1215,13 @@ public void testBasicForLoop_10() throws Exception { " \n" + " }\n" + "}\n", - "\n" + - "final int i = 0;\n" + - "for (new org.eclipse.xtext.xbase.lib.Functions.Function0() {\n" + - " public Integer apply() {\n" + - " return Integer.valueOf(i);\n" + - " }\n" + - "}.apply(), new org.eclipse.xtext.xbase.lib.Functions.Function0() {\n" + - " public Integer apply() {\n" + - " return Integer.valueOf(i);\n" + - " }\n" + - "}.apply(); (i < 10);) {\n" + - "}\n"); + "final int i = 0;\n" + + "for (((org.eclipse.xtext.xbase.lib.Functions.Function0) () -> {\n" + + " return Integer.valueOf(i);\n" + + "}).apply(), ((org.eclipse.xtext.xbase.lib.Functions.Function0) () -> {\n" + + " return Integer.valueOf(i);\n" + + "}).apply(); (i < 10);) {\n" + + "}"); } @Test @@ -1403,13 +1353,10 @@ public void testSynchronizedBlock_3() throws Exception { public void testBug410797_01() throws Exception { compilesTo( "{ val boolean bug = #[true, false, true].reduce[a,b|a && b] }\n", - "\n" + - "final org.eclipse.xtext.xbase.lib.Functions.Function2 _function = new org.eclipse.xtext.xbase.lib.Functions.Function2() {\n" + - " public Boolean apply(final Boolean a, final Boolean b) {\n" + - " return Boolean.valueOf(((a).booleanValue() && (b).booleanValue()));\n" + - " }\n" + - "};\n" + - "final boolean bug = (boolean) org.eclipse.xtext.xbase.lib.IterableExtensions.reduce(java.util.Collections.unmodifiableList(org.eclipse.xtext.xbase.lib.CollectionLiterals.newArrayList(Boolean.valueOf(true), Boolean.valueOf(false), Boolean.valueOf(true))), _function);\n"); + "final org.eclipse.xtext.xbase.lib.Functions.Function2 _function = (Boolean a, Boolean b) -> {\n" + + " return Boolean.valueOf(((a).booleanValue() && (b).booleanValue()));\n" + + "};\n" + + "final boolean bug = (boolean) org.eclipse.xtext.xbase.lib.IterableExtensions.reduce(java.util.Collections.unmodifiableList(org.eclipse.xtext.xbase.lib.CollectionLiterals.newArrayList(Boolean.valueOf(true), Boolean.valueOf(false), Boolean.valueOf(true))), _function);"); } @Test @@ -2052,23 +1999,20 @@ public void test406762_ValidReturnInLambdaContainedInThrow() throws Exception { " val foo = [|return \"foo\"]\n" + " new Exception(foo.apply)\n" + "}\n", - "\n" + - "try {\n" + - " Exception _xblockexpression = null;\n" + - " {\n" + - " final org.eclipse.xtext.xbase.lib.Functions.Function0 _function = new org.eclipse.xtext.xbase.lib.Functions.Function0() {\n" + - " public String apply() {\n" + - " return \"foo\";\n" + - " }\n" + - " };\n" + - " final org.eclipse.xtext.xbase.lib.Functions.Function0 foo = _function;\n" + - " String _apply = foo.apply();\n" + - " _xblockexpression = new Exception(_apply);\n" + - " }\n" + - " throw _xblockexpression;\n" + - "} catch (Throwable _e) {\n" + - " throw org.eclipse.xtext.xbase.lib.Exceptions.sneakyThrow(_e);\n" + - "}\n"); + "try {\n" + + " Exception _xblockexpression = null;\n" + + " {\n" + + " final org.eclipse.xtext.xbase.lib.Functions.Function0 _function = () -> {\n" + + " return \"foo\";\n" + + " };\n" + + " final org.eclipse.xtext.xbase.lib.Functions.Function0 foo = _function;\n" + + " String _apply = foo.apply();\n" + + " _xblockexpression = new Exception(_apply);\n" + + " }\n" + + " throw _xblockexpression;\n" + + "} catch (Throwable _e) {\n" + + " throw org.eclipse.xtext.xbase.lib.Exceptions.sneakyThrow(_e);\n" + + "}"); } @Test @@ -2079,21 +2023,19 @@ public void test406762_ValidReturnInLambdaContainedInThrow_1() throws Exception " foo.apply\n" + "}\n", "\n" + - "try {\n" + - " Exception _xblockexpression = null;\n" + - " {\n" + - " final org.eclipse.xtext.xbase.lib.Functions.Function0 _function = new org.eclipse.xtext.xbase.lib.Functions.Function0() {\n" + - " public Exception apply() {\n" + - " return new Exception();\n" + - " }\n" + - " };\n" + - " final org.eclipse.xtext.xbase.lib.Functions.Function0 foo = _function;\n" + - " _xblockexpression = foo.apply();\n" + - " }\n" + - " throw _xblockexpression;\n" + - "} catch (Throwable _e) {\n" + - " throw org.eclipse.xtext.xbase.lib.Exceptions.sneakyThrow(_e);\n" + - "}\n"); + "try {\n" + + " Exception _xblockexpression = null;\n" + + " {\n" + + " final org.eclipse.xtext.xbase.lib.Functions.Function0 _function = () -> {\n" + + " return new Exception();\n" + + " };\n" + + " final org.eclipse.xtext.xbase.lib.Functions.Function0 foo = _function;\n" + + " _xblockexpression = foo.apply();\n" + + " }\n" + + " throw _xblockexpression;\n" + + "} catch (Throwable _e) {\n" + + " throw org.eclipse.xtext.xbase.lib.Exceptions.sneakyThrow(_e);\n" + + "}"); } @Test diff --git a/org.eclipse.xtext.xbase.tests/src/org/eclipse/xtext/xbase/tests/compiler/CompilerTest.java b/org.eclipse.xtext.xbase.tests/src/org/eclipse/xtext/xbase/tests/compiler/CompilerTest.java index 35dc388465b..ab73cdef507 100644 --- a/org.eclipse.xtext.xbase.tests/src/org/eclipse/xtext/xbase/tests/compiler/CompilerTest.java +++ b/org.eclipse.xtext.xbase.tests/src/org/eclipse/xtext/xbase/tests/compiler/CompilerTest.java @@ -8,15 +8,10 @@ *******************************************************************************/ package org.eclipse.xtext.xbase.tests.compiler; -import org.eclipse.xtext.util.JavaVersion; -import org.eclipse.xtext.xbase.compiler.GeneratorConfig; -import org.eclipse.xtext.xbase.compiler.IGeneratorConfigProvider; import org.eclipse.xtext.xbase.compiler.output.FakeTreeAppendable; import org.junit.Ignore; import org.junit.Test; -import com.google.inject.Inject; - /** * @author Sven Efftinge - Initial contribution and API */ @@ -27,9 +22,6 @@ protected FakeTreeAppendable createAppendable() { return new FakeTreeAppendable(); } - @Inject - private IGeneratorConfigProvider generatorConfigProvider; - @Test public void testSimple() throws Exception { assertCompilesTo("\nint _length = \"foo\".length();\n" + "return _length;", "'foo'.length"); @@ -139,10 +131,8 @@ protected FakeTreeAppendable createAppendable() { assertCompilesTo( // TODO AbstractStringBuilder is package private and should not be part of the resolved type "Iterable _plus = com.google.common.collect.Iterables.concat(((Iterable) null), ((Iterable) null));\n" + - "final java.util.function.Consumer _function = new java.util.function.Consumer() {\n" + - " public void accept(final Object it) {\n" + - " ((CharSequence)it).length();\n" + - " }\n" + + "final java.util.function.Consumer _function = (Object it) -> {\n" + + " ((CharSequence)it).length();\n" + "};\n" + "com.google.common.collect.Iterables.concat(_plus, ((Iterable) null)).forEach(_function);", "((null as Iterable) + (null as Iterable) + (null as Iterable)).forEach[ length ]"); @@ -157,10 +147,8 @@ protected FakeTreeAppendable createAppendable() { @Test public void testImplicitReferenceToSynonym_01() throws Exception { assertCompilesTo( - "final java.util.function.Consumer _function = new java.util.function.Consumer() {\n" + - " public void accept(final String[] it) {\n" + - " ((java.util.List)org.eclipse.xtext.xbase.lib.Conversions.doWrapArray(it)).subList(1, 1);\n" + - " }\n" + + "final java.util.function.Consumer _function = (String[] it) -> {\n" + + " ((java.util.List)org.eclipse.xtext.xbase.lib.Conversions.doWrapArray(it)).subList(1, 1);\n" + "};\n" + "((Iterable) null).forEach(_function);", "(null as Iterable).forEach[ subList(1,1) ]"); @@ -168,10 +156,8 @@ protected FakeTreeAppendable createAppendable() { @Test public void testImplicitReferenceToSynonym_02() throws Exception { assertCompilesTo( - "final java.util.function.Consumer _function = new java.util.function.Consumer() {\n" + - " public void accept(final String[] it) {\n" + - " ((java.util.List)org.eclipse.xtext.xbase.lib.Conversions.doWrapArray(it)).size();\n" + - " }\n" + + "final java.util.function.Consumer _function = (String[] it) -> {\n" + + " ((java.util.List)org.eclipse.xtext.xbase.lib.Conversions.doWrapArray(it)).size();\n" + "};\n" + "((Iterable) null).forEach(_function);", "(null as Iterable).forEach[ size() ]"); @@ -179,10 +165,8 @@ protected FakeTreeAppendable createAppendable() { @Test public void testImplicitReferenceToSynonymWithPrimitives() throws Exception { assertCompilesTo( - "final java.util.function.Consumer _function = new java.util.function.Consumer() {\n" + - " public void accept(final int[] it) {\n" + - " ((java.util.List)org.eclipse.xtext.xbase.lib.Conversions.doWrapArray(it)).subList(1, 1);\n" + - " }\n" + + "final java.util.function.Consumer _function = (int[] it) -> {\n" + + " ((java.util.List)org.eclipse.xtext.xbase.lib.Conversions.doWrapArray(it)).subList(1, 1);\n" + "};\n" + "((Iterable) null).forEach(_function);", "(null as Iterable).forEach[ subList(1,1) ]"); @@ -190,10 +174,8 @@ protected FakeTreeAppendable createAppendable() { @Test public void testImplicitReferenceToArray() throws Exception { assertCompilesTo( - "final java.util.function.Consumer _function = new java.util.function.Consumer() {\n" + - " public void accept(final String[] it) {\n" + - " org.eclipse.xtext.xbase.lib.InputOutput.println(Integer.valueOf(it.length));\n" + - " }\n" + + "final java.util.function.Consumer _function = (String[] it) -> {\n" + + " org.eclipse.xtext.xbase.lib.InputOutput.println(Integer.valueOf(it.length));\n" + "};\n" + "((Iterable) null).forEach(_function);", "(null as Iterable).forEach[ println(length) ]"); @@ -201,10 +183,8 @@ protected FakeTreeAppendable createAppendable() { @Test public void testExplicitReferenceToSynonym_01() throws Exception { assertCompilesTo( - "final java.util.function.Consumer _function = new java.util.function.Consumer() {\n" + - " public void accept(final String[] it) {\n" + - " ((java.util.List)org.eclipse.xtext.xbase.lib.Conversions.doWrapArray(it)).subList(1, 1);\n" + - " }\n" + + "final java.util.function.Consumer _function = (String[] it) -> {\n" + + " ((java.util.List)org.eclipse.xtext.xbase.lib.Conversions.doWrapArray(it)).subList(1, 1);\n" + "};\n" + "((Iterable) null).forEach(_function);", "(null as Iterable).forEach[ it.subList(1,1) ]"); @@ -212,10 +192,8 @@ protected FakeTreeAppendable createAppendable() { @Test public void testExplicitReferenceToSynonym_02() throws Exception { assertCompilesTo( - "final java.util.function.Consumer _function = new java.util.function.Consumer() {\n" + - " public void accept(final String[] it) {\n" + - " ((java.util.List)org.eclipse.xtext.xbase.lib.Conversions.doWrapArray(it)).size();\n" + - " }\n" + + "final java.util.function.Consumer _function = (String[] it) -> {\n" + + " ((java.util.List)org.eclipse.xtext.xbase.lib.Conversions.doWrapArray(it)).size();\n" + "};\n" + "((Iterable) null).forEach(_function);", "(null as Iterable).forEach[ it.size ]"); @@ -223,10 +201,8 @@ protected FakeTreeAppendable createAppendable() { @Test public void testExplicitReferenceToSynonymWithPrimitives() throws Exception { assertCompilesTo( - "final java.util.function.Consumer _function = new java.util.function.Consumer() {\n" + - " public void accept(final int[] it) {\n" + - " ((java.util.List)org.eclipse.xtext.xbase.lib.Conversions.doWrapArray(it)).subList(1, 1);\n" + - " }\n" + + "final java.util.function.Consumer _function = (int[] it) -> {\n" + + " ((java.util.List)org.eclipse.xtext.xbase.lib.Conversions.doWrapArray(it)).subList(1, 1);\n" + "};\n" + "((Iterable) null).forEach(_function);", "(null as Iterable).forEach[ it.subList(1,1) ]"); @@ -234,10 +210,8 @@ protected FakeTreeAppendable createAppendable() { @Test public void testExplicitReferenceToArray() throws Exception { assertCompilesTo( - "final java.util.function.Consumer _function = new java.util.function.Consumer() {\n" + - " public void accept(final String[] it) {\n" + - " org.eclipse.xtext.xbase.lib.InputOutput.println(Integer.valueOf(it.length));\n" + - " }\n" + + "final java.util.function.Consumer _function = (String[] it) -> {\n" + + " org.eclipse.xtext.xbase.lib.InputOutput.println(Integer.valueOf(it.length));\n" + "};\n" + "((Iterable) null).forEach(_function);", "(null as Iterable).forEach[ println(it.length) ]"); @@ -289,12 +263,9 @@ protected FakeTreeAppendable createAppendable() { @Test public void testBlockHasNoSuperfluousBraces_03() throws Exception { assertCompilesTo( - "\n" + - "final org.eclipse.xtext.xbase.lib.Procedures.Procedure1 _function = new org.eclipse.xtext.xbase.lib.Procedures.Procedure1() {\n" + - " public void apply(final Integer i) {\n" + - " new Object();\n" + - " new Object();\n" + - " }\n" + + "final org.eclipse.xtext.xbase.lib.Procedures.Procedure1 _function = (Integer i) -> {\n" + + " new Object();\n" + + " new Object();\n" + "};\n" + "org.eclipse.xtext.xbase.lib.Procedures.Procedure1 fun = _function;", "{ var (int)=>void fun = [ int i | new Object() new Object() ] }"); @@ -733,9 +704,7 @@ public void testSwitchTypeGuards_01() throws Exception { @Test public void testExceptionOnClosure() throws Exception { assertCompilesTo( - "final java.beans.VetoableChangeListener _function = new java.beans.VetoableChangeListener() {\n" + - " public void vetoableChange(final java.beans.PropertyChangeEvent it) throws java.beans.PropertyVetoException {\n" + - " }\n" + + "final java.beans.VetoableChangeListener _function = (java.beans.PropertyChangeEvent it) -> {\n" + "};\n" + "final java.beans.VetoableChangeListener x = _function;", "{val java.beans.VetoableChangeListener x = []}"); @@ -801,148 +770,65 @@ public void testSetLiteralInForLoop3() throws Exception { @Test public void testBug472265_01() throws Exception { - assertCompilesTo("final closures.IAcceptors.IAcceptor _function = new closures.IAcceptors.IAcceptor() {\n" - + " public void doSth(final String x) {\n" - + " }\n" - + "};\n" - + "closures.IAcceptors.IAcceptor a = _function;", + assertCompilesTo( + "final closures.IAcceptors.IAcceptor _function = (String x) -> {\n" + + "};\n" + + "closures.IAcceptors.IAcceptor a = _function;", "{var closures.IAcceptors.IAcceptor a = [x|]}"); } @Test public void testBug472265_02() throws Exception { - assertCompilesTo("final closures.IAcceptors.IAcceptor2 _function = new closures.IAcceptors.IAcceptor2() {\n" - + " public void doSth(final String[] x) {\n" - + " }\n" - + "};\n" - + "closures.IAcceptors.IAcceptor2 a = _function;", + assertCompilesTo( + "final closures.IAcceptors.IAcceptor2 _function = (String[] x) -> {\n" + + "};\n" + + "closures.IAcceptors.IAcceptor2 a = _function;", "{var closures.IAcceptors.IAcceptor2 a = [x|]}"); } @Test public void testBug472265_03() throws Exception { - assertCompilesTo("final closures.IAcceptors.IAcceptor3 _function = new closures.IAcceptors.IAcceptor3() {\n" - + " public void doSth(final String... x) {\n" - + " }\n" - + "};\n" - + "closures.IAcceptors.IAcceptor3 a = _function;", + assertCompilesTo( + "final closures.IAcceptors.IAcceptor3 _function = (String... x) -> {\n" + + "};\n" + + "closures.IAcceptors.IAcceptor3 a = _function;", "{var closures.IAcceptors.IAcceptor3 a = [x|]}"); } @Test public void testBug472265_04() throws Exception { - assertCompilesTo("final closures.IAcceptors.IAcceptor4 _function = new closures.IAcceptors.IAcceptor4() {\n" - + " public void doSth(final String x, final String[] y) {\n" - + " }\n" - + "};\n" - + "closures.IAcceptors.IAcceptor4 a = _function;", + assertCompilesTo( + "final closures.IAcceptors.IAcceptor4 _function = (String x, String[] y) -> {\n" + + "};\n" + + "closures.IAcceptors.IAcceptor4 a = _function;", "{var closures.IAcceptors.IAcceptor4 a = [x,y|]}"); } @Test public void testBug472265_05() throws Exception { - assertCompilesTo("final closures.IAcceptors.IAcceptor5 _function = new closures.IAcceptors.IAcceptor5() {\n" - + " public void doSth(final String x, final String... y) {\n" - + " }\n" - + "};\n" - + "closures.IAcceptors.IAcceptor5 a = _function;", + assertCompilesTo( + "final closures.IAcceptors.IAcceptor5 _function = (String x, String... y) -> {\n" + + "};\n" + + "closures.IAcceptors.IAcceptor5 a = _function;", "{var closures.IAcceptors.IAcceptor5 a = [x,y|]}"); } @Test public void testBug472265_06() throws Exception { - assertCompilesTo("final closures.IAcceptors.IAcceptor6 _function = new closures.IAcceptors.IAcceptor6() {\n" - + " public void doSth(final String[] x, final String[] y) {\n" - + " }\n" - + "};\n" - + "closures.IAcceptors.IAcceptor6 a = _function;", + assertCompilesTo( + "final closures.IAcceptors.IAcceptor6 _function = (String[] x, String[] y) -> {\n" + + "};\n" + + "closures.IAcceptors.IAcceptor6 a = _function;", "{var closures.IAcceptors.IAcceptor6 a = [x,y|]}"); } @Test public void testBug472265_07() throws Exception { - assertCompilesTo("final closures.IAcceptors.IAcceptor7 _function = new closures.IAcceptors.IAcceptor7() {\n" - + " public void doSth(final String[] x, final String... y) {\n" - + " }\n" - + "};\n" - + "closures.IAcceptors.IAcceptor7 a = _function;", + assertCompilesTo( + "final closures.IAcceptors.IAcceptor7 _function = (String[] x, String... y) -> {\n" + + "};\n" + + "closures.IAcceptors.IAcceptor7 a = _function;", "{var closures.IAcceptors.IAcceptor7 a = [x,y|]}"); } - @Test - public void testBug472265_01_lamda() throws Exception { - GeneratorConfig generatorConfig = generatorConfigProvider.get(null); - generatorConfig.setJavaSourceVersion(JavaVersion.JAVA8); - assertCompilesTo("final closures.IAcceptors.IAcceptor _function = (String x) -> {\n" - + "};\n" - + "closures.IAcceptors.IAcceptor a = _function;", - "{var closures.IAcceptors.IAcceptor a = [x|]}", - generatorConfig); - } - - @Test - public void testBug472265_02_lamda() throws Exception { - GeneratorConfig generatorConfig = generatorConfigProvider.get(null); - generatorConfig.setJavaSourceVersion(JavaVersion.JAVA8); - assertCompilesTo("final closures.IAcceptors.IAcceptor2 _function = (String[] x) -> {\n" - + "};\n" - + "closures.IAcceptors.IAcceptor2 a = _function;", - "{var closures.IAcceptors.IAcceptor2 a = [x|]}", - generatorConfig); - } - - @Test - public void testBug472265_03_lamda() throws Exception { - GeneratorConfig generatorConfig = generatorConfigProvider.get(null); - generatorConfig.setJavaSourceVersion(JavaVersion.JAVA8); - assertCompilesTo("final closures.IAcceptors.IAcceptor3 _function = (String... x) -> {\n" - + "};\n" - + "closures.IAcceptors.IAcceptor3 a = _function;", - "{var closures.IAcceptors.IAcceptor3 a = [x|]}", - generatorConfig); - } - - @Test - public void testBug472265_04_lamda() throws Exception { - GeneratorConfig generatorConfig = generatorConfigProvider.get(null); - generatorConfig.setJavaSourceVersion(JavaVersion.JAVA8); - assertCompilesTo("final closures.IAcceptors.IAcceptor4 _function = (String x, String[] y) -> {\n" - + "};\n" - + "closures.IAcceptors.IAcceptor4 a = _function;", - "{var closures.IAcceptors.IAcceptor4 a = [x,y|]}", - generatorConfig); - } - - @Test - public void testBug472265_05_lamda() throws Exception { - GeneratorConfig generatorConfig = generatorConfigProvider.get(null); - generatorConfig.setJavaSourceVersion(JavaVersion.JAVA8); - assertCompilesTo("final closures.IAcceptors.IAcceptor5 _function = (String x, String... y) -> {\n" - + "};\n" - + "closures.IAcceptors.IAcceptor5 a = _function;", - "{var closures.IAcceptors.IAcceptor5 a = [x,y|]}", - generatorConfig); - } - - @Test - public void testBug472265_06_lamda() throws Exception { - GeneratorConfig generatorConfig = generatorConfigProvider.get(null); - generatorConfig.setJavaSourceVersion(JavaVersion.JAVA8); - assertCompilesTo("final closures.IAcceptors.IAcceptor6 _function = (String[] x, String[] y) -> {\n" - + "};\n" - + "closures.IAcceptors.IAcceptor6 a = _function;", - "{var closures.IAcceptors.IAcceptor6 a = [x,y|]}", - generatorConfig); - } - - @Test - public void testBug472265_07_lamda() throws Exception { - GeneratorConfig generatorConfig = generatorConfigProvider.get(null); - generatorConfig.setJavaSourceVersion(JavaVersion.JAVA8); - assertCompilesTo("final closures.IAcceptors.IAcceptor7 _function = (String[] x, String... y) -> {\n" - + "};\n" - + "closures.IAcceptors.IAcceptor7 a = _function;", - "{var closures.IAcceptors.IAcceptor7 a = [x,y|]}", - generatorConfig); - } } diff --git a/org.eclipse.xtext.xbase.tests/src/org/eclipse/xtext/xbase/tests/compiler/NewLanguageFeaturesCompilerTest.java b/org.eclipse.xtext.xbase.tests/src/org/eclipse/xtext/xbase/tests/compiler/NewLanguageFeaturesCompilerTest.java index 1c06332c035..b8a3a754a2b 100644 --- a/org.eclipse.xtext.xbase.tests/src/org/eclipse/xtext/xbase/tests/compiler/NewLanguageFeaturesCompilerTest.java +++ b/org.eclipse.xtext.xbase.tests/src/org/eclipse/xtext/xbase/tests/compiler/NewLanguageFeaturesCompilerTest.java @@ -10,7 +10,6 @@ import org.eclipse.xtext.util.JavaVersion; import org.eclipse.xtext.xbase.compiler.output.FakeTreeAppendable; -import org.eclipse.xtext.xbase.lib.Pair; import org.junit.Test; /** @@ -22,20 +21,31 @@ public class NewLanguageFeaturesCompilerTest extends AbstractOutputComparingComp protected FakeTreeAppendable createAppendable() { return new FakeTreeAppendable(); } - + @Test public void testOverride() throws Exception { + String xbaseCode = "{ val com.google.common.base.AbstractIterator x = [ self.endOfData ] }"; + String result = + "final com.google.common.base.AbstractIterator _function = new com.google.common.base.AbstractIterator() {\n" + + " @Override\n" + + " protected String computeNext() {\n" + + " return this.endOfData();\n" + + " }\n" + + "};\n" + + "final com.google.common.base.AbstractIterator x = _function;"; + compilesTo(xbaseCode, result, JavaVersion.JAVA8); + } + + @Test + public void testLamdba() throws Exception { String xbaseCode = "{ val x = #['a', '', 'c'].filter[!empty] }"; String result = - "final org.eclipse.xtext.xbase.lib.Functions.Function1 _function = new org.eclipse.xtext.xbase.lib.Functions.Function1() {\n" + - " @Override\n" + - " public Boolean apply(final String it) {\n" + - " boolean _isEmpty = it.isEmpty();\n" + - " return Boolean.valueOf((!_isEmpty));\n" + - " }\n" + - "};\n" + - "final Iterable x = org.eclipse.xtext.xbase.lib.IterableExtensions.filter(java.util.Collections.unmodifiableList(org.eclipse.xtext.xbase.lib.CollectionLiterals.newArrayList(\"a\", \"\", \"c\")), _function);\n"; - compilesTo(xbaseCode, result, Pair.of(JavaVersion.JAVA6, JavaVersion.JAVA7)); + "final org.eclipse.xtext.xbase.lib.Functions.Function1 _function = (String it) -> {\n" + + " boolean _isEmpty = it.isEmpty();\n" + + " return Boolean.valueOf((!_isEmpty));\n" + + "};\n" + + "final Iterable x = org.eclipse.xtext.xbase.lib.IterableExtensions.filter(java.util.Collections.unmodifiableList(org.eclipse.xtext.xbase.lib.CollectionLiterals.newArrayList(\"a\", \"\", \"c\")), _function);"; + compilesTo(xbaseCode, result, JavaVersion.JAVA8); } @Test @@ -67,7 +77,7 @@ public void testSwitchOverString() throws Exception { " _switchResult = 3;\n" + "}\n" + "final int x = _switchResult;\n"; - compilesTo(xbaseCode, result, Pair.of(JavaVersion.JAVA7, JavaVersion.JAVA8)); + compilesTo(xbaseCode, result, JavaVersion.JAVA8); } @Test @@ -77,7 +87,7 @@ public void testUnderscoreInNumericLiteral() throws Exception { " val x = 123_456_789\n" + "}\n"; String result = "final int x = 123_456_789;\n"; - compilesTo(xbaseCode, result, Pair.of(JavaVersion.JAVA7, JavaVersion.JAVA8)); + compilesTo(xbaseCode, result, JavaVersion.JAVA8); } @Test diff --git a/org.eclipse.xtext.xbase.tests/src/org/eclipse/xtext/xbase/tests/compiler/OnTheFlyJavaCompiler2Test.java b/org.eclipse.xtext.xbase.tests/src/org/eclipse/xtext/xbase/tests/compiler/OnTheFlyJavaCompiler2Test.java index ba6e4955d14..c2e72ec761a 100644 --- a/org.eclipse.xtext.xbase.tests/src/org/eclipse/xtext/xbase/tests/compiler/OnTheFlyJavaCompiler2Test.java +++ b/org.eclipse.xtext.xbase.tests/src/org/eclipse/xtext/xbase/tests/compiler/OnTheFlyJavaCompiler2Test.java @@ -10,11 +10,13 @@ import org.eclipse.xtext.testing.InjectWith; import org.eclipse.xtext.testing.XtextRunner; +import org.eclipse.xtext.util.JavaRuntimeVersion; import org.eclipse.xtext.util.JavaVersion; import org.eclipse.xtext.xbase.testing.OnTheFlyJavaCompiler2; import org.eclipse.xtext.xbase.testing.TemporaryFolder; import org.eclipse.xtext.xbase.tests.XbaseInjectorProvider; import org.eclipse.xtext.xbase.tests.jvmmodel.AbstractJvmModelTest; +import org.junit.Assume; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; @@ -32,19 +34,26 @@ public class OnTheFlyJavaCompiler2Test extends AbstractJvmModelTest { private OnTheFlyJavaCompiler2 javaCompiler; @Test(expected = IllegalArgumentException.class) - public void testDefaultJavaVersionWithJava7Feature() { - assertJavaCompilation("java.util.List list = new java.util.LinkedList<>();", null); + public void testDefaultJavaVersionWithJava17Feature() { + Assume.assumeTrue("Active only on Java 17 and later", JavaRuntimeVersion.isJava17OrLater()); + assertJavaCompilation("record Hello(String s) {}", null); } @Test - public void testJavaVersion7() { - assertJavaCompilation("java.util.List list = new java.util.LinkedList<>();", JavaVersion.JAVA7); + public void testJavaVersion8_01() { + assertJavaCompilation("java.util.List list = new java.util.LinkedList<>();", JavaVersion.JAVA8); } @Test - public void testJavaVersion8() { + public void testJavaVersion8_02() { assertJavaCompilation("Runnable r = () -> {};", JavaVersion.JAVA8); } + + @Test + public void testJavaVersion17() { + Assume.assumeTrue("Active only on Java 17 and later", JavaRuntimeVersion.isJava17OrLater()); + assertJavaCompilation("record Hello(String s) {}", JavaVersion.JAVA17); + } private Class assertJavaCompilation(CharSequence input, JavaVersion javaVersion) { if (javaVersion != null) { diff --git a/org.eclipse.xtext.xbase.tests/src/org/eclipse/xtext/xbase/tests/typesystem/TypeComputationStateTest.java b/org.eclipse.xtext.xbase.tests/src/org/eclipse/xtext/xbase/tests/typesystem/TypeComputationStateTest.java index 74522c15573..fd9364019d6 100644 --- a/org.eclipse.xtext.xbase.tests/src/org/eclipse/xtext/xbase/tests/typesystem/TypeComputationStateTest.java +++ b/org.eclipse.xtext.xbase.tests/src/org/eclipse/xtext/xbase/tests/typesystem/TypeComputationStateTest.java @@ -149,11 +149,11 @@ public void computeTypes(XExpression expression, ITypeComputationState state) { ResolvedTypes resolution = reflectExtensions.get(casted, "resolvedTypes"); ResolvedTypes parentResolution = reflectExtensions .get(reflectExtensions. get(casted, "parent"), "resolvedTypes"); - assertNull(parentResolution.getActualType(((XExpression) ((XNullLiteral) expression).eContainer()))); + assertNull(parentResolution.getActualType(((XExpression) expression.eContainer()))); state.acceptActualType(expectedType); assertNull(parentResolution.getActualType(expression)); assertEquals(expectedType.getIdentifier(), resolution.getActualType(expression).getIdentifier()); - assertNull(parentResolution.getActualType(((XExpression) ((XNullLiteral) expression).eContainer()))); + assertNull(parentResolution.getActualType(((XExpression) expression.eContainer()))); } else { assertTrue((expression instanceof XBlockExpression)); XNullLiteral nullLiteral = ((XNullLiteral) getFirst(expression.eContents(), null)); diff --git a/org.eclipse.xtext.xbase.ui.tests/src/org/eclipse/xtext/xbase/ui/tests/JavaVersionExtendedTest.java b/org.eclipse.xtext.xbase.ui.tests/src/org/eclipse/xtext/xbase/ui/tests/JavaVersionExtendedTest.java index 69ca18f34ea..63b564fab1c 100644 --- a/org.eclipse.xtext.xbase.ui.tests/src/org/eclipse/xtext/xbase/ui/tests/JavaVersionExtendedTest.java +++ b/org.eclipse.xtext.xbase.ui.tests/src/org/eclipse/xtext/xbase/ui/tests/JavaVersionExtendedTest.java @@ -21,9 +21,6 @@ public class JavaVersionExtendedTest { @Test public void testToJdtClassFileConstant() { - assertEquals(ClassFileConstants.JDK1_5, JavaVersion.JAVA5.toJdtClassFileConstant()); - assertEquals(ClassFileConstants.JDK1_6, JavaVersion.JAVA6.toJdtClassFileConstant()); - assertEquals(ClassFileConstants.JDK1_7, JavaVersion.JAVA7.toJdtClassFileConstant()); assertEquals(ClassFileConstants.JDK1_8, JavaVersion.JAVA8.toJdtClassFileConstant()); assertEquals(ClassFileConstants.JDK9, JavaVersion.JAVA9.toJdtClassFileConstant()); assertEquals(ClassFileConstants.JDK10, JavaVersion.JAVA10.toJdtClassFileConstant()); @@ -41,5 +38,13 @@ public void testToJdtClassFileConstant() { // // ok // } } + + @SuppressWarnings("deprecation") + @Test + public void testSpoofedClassFileConstant() { + assertEquals(ClassFileConstants.JDK1_8, JavaVersion.JAVA5.toJdtClassFileConstant()); + assertEquals(ClassFileConstants.JDK1_8, JavaVersion.JAVA6.toJdtClassFileConstant()); + assertEquals(ClassFileConstants.JDK1_8, JavaVersion.JAVA7.toJdtClassFileConstant()); + } } diff --git a/org.eclipse.xtext.xbase.ui/src/org/eclipse/xtext/xbase/ui/builder/XbaseBuilderPreferenceAccess.java b/org.eclipse.xtext.xbase.ui/src/org/eclipse/xtext/xbase/ui/builder/XbaseBuilderPreferenceAccess.java index 93ad2cf0f09..fed0d3c782b 100644 --- a/org.eclipse.xtext.xbase.ui/src/org/eclipse/xtext/xbase/ui/builder/XbaseBuilderPreferenceAccess.java +++ b/org.eclipse.xtext.xbase.ui/src/org/eclipse/xtext/xbase/ui/builder/XbaseBuilderPreferenceAccess.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2015, 2017 itemis AG (http://www.itemis.eu) and others. + * Copyright (c) 2015, 2024 itemis AG (http://www.itemis.eu) and others. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. @@ -61,7 +61,7 @@ protected void initializeBuilderPreferences(IPreferenceStore store) { store.setDefault(PREF_GENERATE_SUPPRESS_WARNINGS, true); store.setDefault(PREF_GENERATE_GENERATED, false); store.setDefault(PREF_DATE_IN_GENERATED, false); - store.setDefault(PREF_JAVA_VERSION, JavaVersion.JAVA5.toString()); + store.setDefault(PREF_JAVA_VERSION, JavaVersion.JAVA8.toString()); store.setDefault(PREF_USE_COMPILER_SOURCE, true); } @@ -100,7 +100,7 @@ public JavaVersion getJavaVersion(Object context, IPreferenceStore preferenceSto // Fall back to default value } } - return JavaVersion.JAVA5; + return JavaVersion.JAVA8; } public void setJavaVersion(Object context, JavaVersion version) { @@ -112,7 +112,7 @@ public void setJavaVersion(Object context, JavaVersion version) { public JavaVersion fromCompilerSourceLevel(String compilerSource) { JavaVersion javaVersion = JavaVersion.fromQualifier(compilerSource); if (javaVersion == null) - javaVersion = JavaVersion.JAVA5; + javaVersion = JavaVersion.JAVA8; return javaVersion; } diff --git a/org.eclipse.xtext.xbase/src/org/eclipse/xtext/xbase/compiler/GeneratorConfig.java b/org.eclipse.xtext.xbase/src/org/eclipse/xtext/xbase/compiler/GeneratorConfig.java index 2da721d8cc1..a264a9d119d 100644 --- a/org.eclipse.xtext.xbase/src/org/eclipse/xtext/xbase/compiler/GeneratorConfig.java +++ b/org.eclipse.xtext.xbase/src/org/eclipse/xtext/xbase/compiler/GeneratorConfig.java @@ -49,7 +49,7 @@ public class GeneratorConfig { /** * Version of the Java Source code that's being generated by the compiler. */ - private JavaVersion javaSourceVersion = JavaVersion.JAVA5; + private JavaVersion javaSourceVersion = JavaVersion.JAVA8; /** * Copy the values of the given generator configuration. diff --git a/org.eclipse.xtext.xbase/src/org/eclipse/xtext/xbase/interpreter/impl/XbaseInterpreter.java b/org.eclipse.xtext.xbase/src/org/eclipse/xtext/xbase/interpreter/impl/XbaseInterpreter.java index f8d1e8ac0da..bbbb984d77f 100644 --- a/org.eclipse.xtext.xbase/src/org/eclipse/xtext/xbase/interpreter/impl/XbaseInterpreter.java +++ b/org.eclipse.xtext.xbase/src/org/eclipse/xtext/xbase/interpreter/impl/XbaseInterpreter.java @@ -657,18 +657,46 @@ protected Object _doEvaluate(XTryCatchFinallyExpression tryCatchFinally, List caughtExceptions = newArrayList(); // Resources try { - for (XVariableDeclaration res : resources) { - resIsInit.put(res.getName(), false); - result = internalEvaluate(res, context, indicator); - // Remember for automatic close which resources are initialized - resIsInit.put(res.getName(), true); + try { + for (XVariableDeclaration res : resources) { + resIsInit.put(res.getName(), false); + result = internalEvaluate(res, context, indicator); + // Remember for automatic close which resources are initialized + resIsInit.put(res.getName(), true); + } + // Expression Body + result = internalEvaluate(tryCatchFinally.getExpression(), context, indicator); + + } catch (ReturnValue value) { + // Keep thrown return value in mind until resources are closed + returnValue = value; + } finally { + // ... prompted by try with resources (automatic close) + if (!resources.isEmpty()) { + for (int i = resources.size() - 1; i >= 0; i--) { + XVariableDeclaration resource = resources.get(i); + // Only close resources that are instantiated (= avoid + // NullPointerException) + if (resIsInit.get(resource.getName())) { + // Find close method for resource + JvmOperation close = findCloseMethod(resource); + // Invoke close on resource + if (close != null) { + // Invoking the close method might throw + // a EvaluationException. Hence, we collect those thrown + // EvaluationExceptions and propagate them later on. + try { + invokeOperation(close, + context.getValue(QualifiedName.create(resource.getSimpleName())), + Collections.emptyList()); + } catch (EvaluationException t) { + caughtExceptions.add(t); + } + } + } + } + } } - // Expression Body - result = internalEvaluate(tryCatchFinally.getExpression(), context, indicator); - - } catch (ReturnValue value) { - // Keep thrown return value in mind until resources are closed - returnValue = value; } catch (EvaluationException evaluationException) { Throwable cause = evaluationException.getCause(); boolean caught = false; @@ -698,31 +726,6 @@ protected Object _doEvaluate(XTryCatchFinallyExpression tryCatchFinally, throw new EvaluationException(new FinallyDidNotCompleteException(e)); } } - // ... prompted by try with resources (automatic close) - if (!resources.isEmpty()) { - for (int i = resources.size() - 1; i >= 0; i--) { - XVariableDeclaration resource = resources.get(i); - // Only close resources that are instantiated (= avoid - // NullPointerException) - if (resIsInit.get(resource.getName())) { - // Find close method for resource - JvmOperation close = findCloseMethod(resource); - // Invoke close on resource - if (close != null) { - // Invoking the close method might throw - // a EvaluationException. Hence, we collect those thrown - // EvaluationExceptions and propagate them later on. - try { - invokeOperation(close, - context.getValue(QualifiedName.create(resource.getSimpleName())), - Collections.emptyList()); - } catch (EvaluationException t) { - caughtExceptions.add(t); - } - } - } - } - } // Throw caught exceptions if there are any if (!caughtExceptions.isEmpty()) throw caughtExceptions.get(0); diff --git a/org.eclipse.xtext.xbase/src/org/eclipse/xtext/xbase/typesystem/override/ResolvedFeatures.java b/org.eclipse.xtext.xbase/src/org/eclipse/xtext/xbase/typesystem/override/ResolvedFeatures.java index 71152753995..a87d0bde1e1 100644 --- a/org.eclipse.xtext.xbase/src/org/eclipse/xtext/xbase/typesystem/override/ResolvedFeatures.java +++ b/org.eclipse.xtext.xbase/src/org/eclipse/xtext/xbase/typesystem/override/ResolvedFeatures.java @@ -49,7 +49,7 @@ public class ResolvedFeatures extends AbstractResolvedFeatures { private List declaredOperations; private ListMultimap allOperationsPerErasure; private ListMultimap declaredOperationsPerErasure; - private JavaVersion targetVersion = JavaVersion.JAVA5; + private JavaVersion targetVersion = JavaVersion.JAVA8; public ResolvedFeatures(LightweightTypeReference type, OverrideTester overrideTester, JavaVersion targetVersion) { super(type, overrideTester);