org.eclipse.xtext.xbase.testing.CompilationTestHelper Java Examples
The following examples show how to use
org.eclipse.xtext.xbase.testing.CompilationTestHelper.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OldDataCompilerTest.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Test public void testSuperClassWithTypeParameters() { try { StringConcatenation _builder = new StringConcatenation(); _builder.append("@Data class Foo<T> {"); _builder.newLine(); _builder.append("\t"); _builder.append("T foo"); _builder.newLine(); _builder.append("}"); _builder.newLine(); _builder.append("@Data class Bar extends Foo<String> {"); _builder.newLine(); _builder.append("}"); _builder.newLine(); final IAcceptor<CompilationTestHelper.Result> _function = (CompilationTestHelper.Result it) -> { Assert.assertTrue(it.getGeneratedCode("Bar").contains("public Bar(final String foo) {")); }; this.compilationTestHelper.compile(_builder, _function); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example #2
Source File: AbstractExtraLanguageGeneratorTest.java From sarl with Apache License 2.0 | 6 votes |
public void assertTypeDefinition(String typeName, String expectedContent) { final OutputConfiguration configuration = getOutputConfiguration(); if (configuration == null) { throw new AssertionFailedError("", expectedContent, ""); } final String filename = typeName.replaceAll("\\.", "/") + ".py"; final String key = "/" + CompilationTestHelper.PROJECT_NAME + "/" + configuration.getOutputDirectory() + "/" + filename; final Map<String, CharSequence> generatedResources = this.result.getAllGeneratedResources(); CharSequence ocontent = generatedResources.get(key); final String content; if (ocontent == null) { content = ""; } else { content = ocontent.toString(); } assertEquals(expectedContent, ocontent); }
Example #3
Source File: NewDataCompilerTest.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Test public void testSuperClassWithTypeParameters() { try { StringConcatenation _builder = new StringConcatenation(); _builder.append("import org.eclipse.xtend.lib.annotations.Data"); _builder.newLine(); _builder.append("@Data class Foo<T> {"); _builder.newLine(); _builder.append("\t"); _builder.append("T foo"); _builder.newLine(); _builder.append("}"); _builder.newLine(); _builder.append("@Data class Bar extends Foo<String> {"); _builder.newLine(); _builder.append("}"); _builder.newLine(); final IAcceptor<CompilationTestHelper.Result> _function = (CompilationTestHelper.Result it) -> { Assert.assertTrue(it.getGeneratedCode("Bar").contains("public Bar(final String foo) {")); }; this.compilationTestHelper.compile(_builder, _function); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example #4
Source File: NewDataCompilerTest.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Test public void testClassAndSuperClassWithTypeParameters() { try { StringConcatenation _builder = new StringConcatenation(); _builder.append("import org.eclipse.xtend.lib.annotations.Data"); _builder.newLine(); _builder.append("@Data class Foo<T> {"); _builder.newLine(); _builder.append("\t"); _builder.append("T foo"); _builder.newLine(); _builder.append("}"); _builder.newLine(); _builder.append("@Data class Bar<X> extends Foo<X> {"); _builder.newLine(); _builder.append("}"); _builder.newLine(); final IAcceptor<CompilationTestHelper.Result> _function = (CompilationTestHelper.Result it) -> { Assert.assertTrue(it.getGeneratedCode("Bar").contains("public Bar(final X foo) {")); }; this.compilationTestHelper.compile(_builder, _function); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example #5
Source File: NewDataCompilerTest.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Test public void testSuperClassWithoutEquals() { try { StringConcatenation _builder = new StringConcatenation(); _builder.append("import org.eclipse.xtend.lib.annotations.Data"); _builder.newLine(); _builder.append("class Foo {"); _builder.newLine(); _builder.append("}"); _builder.newLine(); _builder.append("@Data class Bar extends Foo {"); _builder.newLine(); _builder.append("\t"); _builder.append("String bar = \"Foo\""); _builder.newLine(); _builder.append("}"); _builder.newLine(); final IAcceptor<CompilationTestHelper.Result> _function = (CompilationTestHelper.Result it) -> { Assert.assertFalse(it.getGeneratedCode("Bar"), it.getGeneratedCode("Bar").contains("super.equals")); Assert.assertFalse(it.getGeneratedCode("Bar").contains("super.hashCode")); }; this.compilationTestHelper.compile(_builder, _function); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example #6
Source File: FinalFieldsConstructorCompilerTest.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Test public void testOnGenericClass() { try { StringConcatenation _builder = new StringConcatenation(); _builder.append("import org.eclipse.xtend.lib.annotations.FinalFieldsConstructor"); _builder.newLine(); _builder.append("@FinalFieldsConstructor class C<T> {"); _builder.newLine(); _builder.append("\t"); _builder.append("val T a"); _builder.newLine(); _builder.append("}"); _builder.newLine(); final String source = _builder.toString(); this._validationTestHelper.assertNoErrors(this.clazz(source)); final IAcceptor<CompilationTestHelper.Result> _function = (CompilationTestHelper.Result it) -> { Assert.assertTrue(it.getSingleGeneratedCode().contains("C(final T a)")); }; this.compilationTestHelper.compile(source, _function); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example #7
Source File: EqualsHashCodeCompilerTest.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Test public void testGenericClass() { try { StringConcatenation _builder = new StringConcatenation(); _builder.append("import org.eclipse.xtend.lib.annotations.EqualsHashCode"); _builder.newLine(); _builder.append("@EqualsHashCode class Foo<T> {"); _builder.newLine(); _builder.append("\t"); _builder.append("int a = 1"); _builder.newLine(); _builder.append("}"); _builder.newLine(); final String text = _builder.toString(); final IAcceptor<CompilationTestHelper.Result> _function = (CompilationTestHelper.Result it) -> { Assert.assertTrue(it.getSingleGeneratedCode().contains("Foo<?> other = (Foo<?>) obj")); }; this.compilationTestHelper.compile(text, _function); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example #8
Source File: OldDataCompilerTest.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Test public void testClassAndSuperClassWithTypeParameters() { try { StringConcatenation _builder = new StringConcatenation(); _builder.append("@Data class Foo<T> {"); _builder.newLine(); _builder.append("\t"); _builder.append("T foo"); _builder.newLine(); _builder.append("}"); _builder.newLine(); _builder.append("@Data class Bar<X> extends Foo<X> {"); _builder.newLine(); _builder.append("}"); _builder.newLine(); final IAcceptor<CompilationTestHelper.Result> _function = (CompilationTestHelper.Result it) -> { Assert.assertTrue(it.getGeneratedCode("Bar").contains("public Bar(final X foo) {")); }; this.compilationTestHelper.compile(_builder, _function); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example #9
Source File: EqualsHashCodeCompilerTest.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Test public void testSuperClassWithoutEquals() { try { StringConcatenation _builder = new StringConcatenation(); _builder.append("import org.eclipse.xtend.lib.annotations.EqualsHashCode"); _builder.newLine(); _builder.append("class Foo {"); _builder.newLine(); _builder.append("}"); _builder.newLine(); _builder.append("@EqualsHashCode class Bar extends Foo {"); _builder.newLine(); _builder.append("\t"); _builder.append("String bar = \"Foo\""); _builder.newLine(); _builder.append("}"); _builder.newLine(); final IAcceptor<CompilationTestHelper.Result> _function = (CompilationTestHelper.Result it) -> { Assert.assertFalse(it.getGeneratedCode("Bar"), it.getGeneratedCode("Bar").contains("super.equals")); Assert.assertFalse(it.getGeneratedCode("Bar").contains("super.hashCode")); }; this.compilationTestHelper.compile(_builder, _function); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example #10
Source File: ActiveAnnotationsRuntimeTest.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Override public void assertProcessing(final Pair<String, String> macroFile, final Pair<String, String> clientFile, final Procedure1<? super CompilationUnitImpl> expectations) { try { final XtextResourceSet resourceSet = this.compileMacroResourceSet(macroFile, clientFile); final Resource singleResource = IterableExtensions.<Resource>head(resourceSet.getResources()); singleResource.load(CollectionLiterals.<Object, Object>emptyMap()); final IAcceptor<CompilationTestHelper.Result> _function = (CompilationTestHelper.Result it) -> { it.getGeneratedCode(); final CompilationUnitImpl unit = this.compilationUnitProvider.get(); final XtendFile xtendFile = IterableExtensions.<XtendFile>head(Iterables.<XtendFile>filter(singleResource.getContents(), XtendFile.class)); unit.setXtendFile(xtendFile); expectations.apply(unit); }; this.compiler.compile(resourceSet, _function); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example #11
Source File: SkillCompilerTest.java From sarl with Apache License 2.0 | 5 votes |
@Test public void skillmodifier_package() throws Exception { String source = multilineString( "capacity C1 { }", "package skill S1 implements C1 { }" ); final String expectedS1 = multilineString( "import io.sarl.lang.annotation.SarlElementType;", "import io.sarl.lang.annotation.SarlSpecification;", "import io.sarl.lang.annotation.SyntheticMember;", "import io.sarl.lang.core.Agent;", "import io.sarl.lang.core.Skill;", "", "@SarlSpecification(\"" + SARLVersion.SPECIFICATION_RELEASE_VERSION_STRING + "\")", "@SarlElementType(" + SarlPackage.SARL_SKILL + ")", "@SuppressWarnings(\"all\")", "class S1 extends Skill implements C1 {", " @SyntheticMember", " public S1() {", " super();", " }", " ", " @SyntheticMember", " public S1(final Agent arg0) {", " super(arg0);", " }", "}", "" ); getCompileHelper().compile(source, new IAcceptor<CompilationTestHelper.Result>() { @Override public void accept(Result r) { assertEquals(expectedS1,r.getGeneratedCode("S1")); } }); }
Example #12
Source File: DelegateCompilerTest.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@Test public void testMethodWithParameters() { try { StringConcatenation _builder = new StringConcatenation(); _builder.append("import org.eclipse.xtend.lib.annotations.Delegate"); _builder.newLine(); _builder.append("interface A {"); _builder.newLine(); _builder.append("\t"); _builder.append("def void m(String foo, Object bar)"); _builder.newLine(); _builder.append("}"); _builder.newLine(); _builder.append("class B implements A {"); _builder.newLine(); _builder.append("\t"); _builder.append("override m(String foo, Object bar) {}"); _builder.newLine(); _builder.append("}"); _builder.newLine(); _builder.append("class C implements A{"); _builder.newLine(); _builder.append("\t"); _builder.append("@Delegate B delegate"); _builder.newLine(); _builder.append("}"); _builder.newLine(); final String text = _builder.toString(); this._validationTestHelper.assertNoIssues(this.file(text)); final IAcceptor<CompilationTestHelper.Result> _function = (CompilationTestHelper.Result it) -> { final Function1<Method, Boolean> _function_1 = (Method it_1) -> { return Boolean.valueOf(((Objects.equal(it_1.getName(), "m") && Objects.equal(IterableExtensions.<Class<?>>toList(((Iterable<Class<?>>)Conversions.doWrapArray(it_1.getParameterTypes()))), Collections.<Class<?>>unmodifiableList(CollectionLiterals.<Class<?>>newArrayList(String.class, Object.class)))) && Objects.equal(it_1.getReturnType(), void.class))); }; Assert.assertTrue(IterableExtensions.<Method>exists(((Iterable<Method>)Conversions.doWrapArray(it.getCompiledClass().getDeclaredMethods())), _function_1)); }; this.compilationTestHelper.compile(text, _function); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example #13
Source File: SkillCompilerTest.java From sarl with Apache License 2.0 | 5 votes |
@Test public void skillmodifier_abstract_member() throws Exception { String source = multilineString( "capacity C1 { }", "skill S1 implements C1 {", " def name()", "}" ); final String expectedS1 = multilineString( "import io.sarl.lang.annotation.SarlElementType;", "import io.sarl.lang.annotation.SarlSpecification;", "import io.sarl.lang.annotation.SyntheticMember;", "import io.sarl.lang.core.Agent;", "import io.sarl.lang.core.Skill;", "", "@SarlSpecification(\"" + SARLVersion.SPECIFICATION_RELEASE_VERSION_STRING + "\")", "@SarlElementType(" + SarlPackage.SARL_SKILL + ")", "@SuppressWarnings(\"all\")", "public abstract class S1 extends Skill implements C1 {", " public abstract void name();", " ", " @SyntheticMember", " public S1() {", " super();", " }", " ", " @SyntheticMember", " public S1(final Agent arg0) {", " super(arg0);", " }", "}", "" ); getCompileHelper().compile(source, new IAcceptor<CompilationTestHelper.Result>() { @Override public void accept(Result r) { assertEquals(expectedS1,r.getGeneratedCode("S1")); } }); }
Example #14
Source File: SkillCompilerTest.java From sarl with Apache License 2.0 | 5 votes |
@Test public void skillmodifier_abstract() throws Exception { String source = multilineString( "capacity C1 { }", "abstract skill S1 implements C1 { }" ); final String expectedS1 = multilineString( "import io.sarl.lang.annotation.SarlElementType;", "import io.sarl.lang.annotation.SarlSpecification;", "import io.sarl.lang.annotation.SyntheticMember;", "import io.sarl.lang.core.Agent;", "import io.sarl.lang.core.Skill;", "", "@SarlSpecification(\"" + SARLVersion.SPECIFICATION_RELEASE_VERSION_STRING + "\")", "@SarlElementType(" + SarlPackage.SARL_SKILL + ")", "@SuppressWarnings(\"all\")", "public abstract class S1 extends Skill implements C1 {", " @SyntheticMember", " public S1() {", " super();", " }", " ", " @SyntheticMember", " public S1(final Agent arg0) {", " super(arg0);", " }", "}", "" ); getCompileHelper().compile(source, new IAcceptor<CompilationTestHelper.Result>() { @Override public void accept(Result r) { assertEquals(expectedS1,r.getGeneratedCode("S1")); } }); }
Example #15
Source File: DelegateCompilerTest.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@Test public void testDelegateField() { try { StringConcatenation _builder = new StringConcatenation(); _builder.append("import org.eclipse.xtend.lib.annotations.Delegate"); _builder.newLine(); _builder.append("interface A {"); _builder.newLine(); _builder.append("\t"); _builder.append("def void m()"); _builder.newLine(); _builder.append("}"); _builder.newLine(); _builder.append("class B implements A {"); _builder.newLine(); _builder.append("\t"); _builder.append("override m() {}"); _builder.newLine(); _builder.append("}"); _builder.newLine(); _builder.append("class C implements A{"); _builder.newLine(); _builder.append("\t"); _builder.append("@Delegate B delegate"); _builder.newLine(); _builder.append("}"); _builder.newLine(); final String text = _builder.toString(); this._validationTestHelper.assertNoIssues(this.file(text)); final IAcceptor<CompilationTestHelper.Result> _function = (CompilationTestHelper.Result it) -> { final Function1<Method, Boolean> _function_1 = (Method it_1) -> { return Boolean.valueOf(((Objects.equal(it_1.getName(), "m") && ((List<Class<?>>)Conversions.doWrapArray(it_1.getParameterTypes())).isEmpty()) && Objects.equal(it_1.getReturnType(), void.class))); }; Assert.assertTrue(IterableExtensions.<Method>exists(((Iterable<Method>)Conversions.doWrapArray(it.getCompiledClass().getDeclaredMethods())), _function_1)); }; this.compilationTestHelper.compile(text, _function); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example #16
Source File: AbstractXtendCompilerTest.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
protected XtendFile doAssertCompilesTo(final CharSequence input, final CharSequence expected, final GeneratorConfig config, final boolean serializeAllTypes) { try { final XtendFile file = this.file(input.toString(), true); final ArrayList<CharSequence> results = CollectionLiterals.<CharSequence>newArrayList(); Iterable<JvmDeclaredType> _filter = Iterables.<JvmDeclaredType>filter(file.eResource().getContents(), JvmDeclaredType.class); for (final JvmDeclaredType inferredType : _filter) { { Assert.assertFalse(DisableCodeGenerationAdapter.isDisabled(inferredType)); CharSequence javaCode = this.generator.generateType(inferredType, config); javaCode = this.postProcessor.postProcess(null, javaCode); results.add(javaCode); if (this.useJavaCompiler) { final IAcceptor<CompilationTestHelper.Result> _function = (CompilationTestHelper.Result it) -> { it.getCompiledClass(); }; this.compilationTestHelper.compile(input, _function); } } } if (serializeAllTypes) { Assert.assertEquals(expected.toString(), IterableExtensions.join(results, "\n")); } else { Assert.assertEquals(expected.toString(), IterableExtensions.<CharSequence>head(results).toString()); } return file; } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example #17
Source File: AnnotationsCompilerTest.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
protected Class<?> compileToClass(final String text) throws Exception { final Class<?>[] result = new Class[1]; javaCompiler.compile(text, new IAcceptor<CompilationTestHelper.Result>() { @Override public void accept(Result t) { result[0] = t.getCompiledClass(); } }); return result[0]; }
Example #18
Source File: InlineFunctionTest.java From sarl with Apache License 2.0 | 5 votes |
private void compileWithInline(CharSequence source, IAcceptor<Result> acceptor) throws IOException { String fileName = "MyFile." + extensionProvider.getPrimaryFileExtension(); CompilationTestHelper compiler = getCompileHelper(); ResourceSet set = compiler.resourceSet(new Pair<String, CharSequence>(fileName, source)); if (this.config == null) { this.config = this.generatorConfigProvider2.get(null); ((GeneratorConfigProvider2) this.generatorConfigProvider2).install(set, config); } this.config.setGenerateInlineAnnotation(true); compiler.compile(set, acceptor); }
Example #19
Source File: SkillCompilerTest.java From sarl with Apache License 2.0 | 5 votes |
@Test public void fieldmodifier_static() throws Exception { String source = multilineString( "capacity C1 { }", "skill S1 implements C1 {", " static var field : int", "}" ); final String expectedS1 = multilineString( "import io.sarl.lang.annotation.SarlElementType;", "import io.sarl.lang.annotation.SarlSpecification;", "import io.sarl.lang.annotation.SyntheticMember;", "import io.sarl.lang.core.Agent;", "import io.sarl.lang.core.Skill;", "", "@SarlSpecification(\"" + SARLVersion.SPECIFICATION_RELEASE_VERSION_STRING + "\")", "@SarlElementType(" + SarlPackage.SARL_SKILL + ")", "@SuppressWarnings(\"all\")", "public class S1 extends Skill implements C1 {", " private static int field;", " ", " @SyntheticMember", " public S1() {", " super();", " }", " ", " @SyntheticMember", " public S1(final Agent arg0) {", " super(arg0);", " }", "}", "" ); getCompileHelper().compile(source, new IAcceptor<CompilationTestHelper.Result>() { @Override public void accept(Result r) { assertEquals(expectedS1,r.getGeneratedCode("S1")); } }); }
Example #20
Source File: VarArgsCompilerTest.java From sarl with Apache License 2.0 | 5 votes |
@Test public void inSkillConstructor() throws Exception { String source = multilineString( "capacity C1 {}", "skill S1 implements C1 {", " new(arg1 : char, arg2 : boolean, arg3 : int*) {", " System.out.println(arg3)", " }", "}" ); final String expected = multilineString( "import io.sarl.lang.annotation.SarlElementType;", "import io.sarl.lang.annotation.SarlSpecification;", "import io.sarl.lang.core.Skill;", "", "@SarlSpecification(\"" + SARLVersion.SPECIFICATION_RELEASE_VERSION_STRING + "\")", "@SarlElementType(" + SarlPackage.SARL_SKILL + ")", "@SuppressWarnings(\"all\")", "public class S1 extends Skill implements C1 {", " public S1(final char arg1, final boolean arg2, final int... arg3) {", " System.out.println(arg3);", " }", "}", "" ); getCompileHelper().compile(source, new IAcceptor<CompilationTestHelper.Result>() { @Override public void accept(Result r) { assertEquals(expected,r.getGeneratedCode("S1")); } }); }
Example #21
Source File: DelegateCompilerTest.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@Test public void testMethodWithReturnType() { try { StringConcatenation _builder = new StringConcatenation(); _builder.append("import org.eclipse.xtend.lib.annotations.Delegate"); _builder.newLine(); _builder.append("interface A {"); _builder.newLine(); _builder.append("\t"); _builder.append("def int m()"); _builder.newLine(); _builder.append("}"); _builder.newLine(); _builder.append("class B implements A {"); _builder.newLine(); _builder.append("\t"); _builder.append("override m() {1}"); _builder.newLine(); _builder.append("}"); _builder.newLine(); _builder.append("class C implements A{"); _builder.newLine(); _builder.append("\t"); _builder.append("@Delegate B delegate"); _builder.newLine(); _builder.append("}"); _builder.newLine(); final String text = _builder.toString(); this._validationTestHelper.assertNoIssues(this.file(text)); final IAcceptor<CompilationTestHelper.Result> _function = (CompilationTestHelper.Result it) -> { final Function1<Method, Boolean> _function_1 = (Method it_1) -> { return Boolean.valueOf(((Objects.equal(it_1.getName(), "m") && ((List<Class<?>>)Conversions.doWrapArray(it_1.getParameterTypes())).isEmpty()) && Objects.equal(it_1.getReturnType(), int.class))); }; Assert.assertTrue(IterableExtensions.<Method>exists(((Iterable<Method>)Conversions.doWrapArray(it.getCompiledClass().getDeclaredMethods())), _function_1)); }; this.compilationTestHelper.compile(text, _function); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example #22
Source File: SkillCompilerTest.java From sarl with Apache License 2.0 | 5 votes |
@Test public void skillmodifier_public() throws Exception { String source = multilineString( "capacity C1 { }", "public skill S1 implements C1 { }" ); final String expectedS1 = multilineString( "import io.sarl.lang.annotation.SarlElementType;", "import io.sarl.lang.annotation.SarlSpecification;", "import io.sarl.lang.annotation.SyntheticMember;", "import io.sarl.lang.core.Agent;", "import io.sarl.lang.core.Skill;", "", "@SarlSpecification(\"" + SARLVersion.SPECIFICATION_RELEASE_VERSION_STRING + "\")", "@SarlElementType(" + SarlPackage.SARL_SKILL + ")", "@SuppressWarnings(\"all\")", "public class S1 extends Skill implements C1 {", " @SyntheticMember", " public S1() {", " super();", " }", " ", " @SyntheticMember", " public S1(final Agent arg0) {", " super(arg0);", " }", "}", "" ); getCompileHelper().compile(source, new IAcceptor<CompilationTestHelper.Result>() { @Override public void accept(Result r) { assertEquals(expectedS1,r.getGeneratedCode("S1")); } }); }
Example #23
Source File: NewDataCompilerTest.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@Test public void testWithCreateExtension() { try { StringConcatenation _builder = new StringConcatenation(); _builder.append("import org.eclipse.xtend.lib.annotations.Data"); _builder.newLine(); _builder.append("@Data class Foo {"); _builder.newLine(); _builder.append("\t"); _builder.append("def create {} foo() {"); _builder.newLine(); _builder.append("\t"); _builder.append("}"); _builder.newLine(); _builder.append("}"); _builder.newLine(); final String text = _builder.toString(); this._validationTestHelper.assertNoIssues(this.clazz(text)); final IAcceptor<CompilationTestHelper.Result> _function = (CompilationTestHelper.Result it) -> { final Function1<Method, Boolean> _function_1 = (Method it_1) -> { return Boolean.valueOf(it_1.getName().startsWith("get")); }; Assert.assertFalse(IterableExtensions.<Method>exists(((Iterable<Method>)Conversions.doWrapArray(it.getCompiledClass().getDeclaredMethods())), _function_1)); }; this.compilationTestHelper.compile(text, _function); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example #24
Source File: NewDataCompilerTest.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@Test public void testParametrizedSuperConstructor() { try { StringConcatenation _builder = new StringConcatenation(); _builder.append("import org.eclipse.xtend.lib.annotations.Data"); _builder.newLine(); _builder.append("@Data class Foo {"); _builder.newLine(); _builder.append("\t"); _builder.append("int foo"); _builder.newLine(); _builder.append("}"); _builder.newLine(); _builder.append("@Data class Bar extends Foo {"); _builder.newLine(); _builder.append("\t"); _builder.append("String bar"); _builder.newLine(); _builder.append("}"); _builder.newLine(); final IAcceptor<CompilationTestHelper.Result> _function = (CompilationTestHelper.Result it) -> { Class<?> _compiledClass = it.getCompiledClass("Bar"); final Procedure1<Class<?>> _function_1 = (Class<?> it_1) -> { final Function1<Constructor<?>, Boolean> _function_2 = (Constructor<?> it_2) -> { List<Class<?>> _list = IterableExtensions.<Class<?>>toList(((Iterable<Class<?>>)Conversions.doWrapArray(it_2.getParameterTypes()))); return Boolean.valueOf(Objects.equal(_list, Collections.<Class<? extends Object>>unmodifiableList(CollectionLiterals.<Class<? extends Object>>newArrayList(int.class, String.class)))); }; Assert.assertTrue(IterableExtensions.<Constructor<?>>exists(((Iterable<Constructor<?>>)Conversions.doWrapArray(it_1.getDeclaredConstructors())), _function_2)); }; ObjectExtensions.<Class<?>>operator_doubleArrow(_compiledClass, _function_1); }; this.compilationTestHelper.compile(_builder, _function); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example #25
Source File: OldDataCompilerTest.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@Test public void testParametrizedSuperConstructor() { try { StringConcatenation _builder = new StringConcatenation(); _builder.append("@Data class Foo {"); _builder.newLine(); _builder.append("\t"); _builder.append("int foo"); _builder.newLine(); _builder.append("}"); _builder.newLine(); _builder.append("@Data class Bar extends Foo {"); _builder.newLine(); _builder.append("\t"); _builder.append("String bar"); _builder.newLine(); _builder.append("}"); _builder.newLine(); final IAcceptor<CompilationTestHelper.Result> _function = (CompilationTestHelper.Result it) -> { Class<?> _compiledClass = it.getCompiledClass("Bar"); final Procedure1<Class<?>> _function_1 = (Class<?> it_1) -> { final Function1<Constructor<?>, Boolean> _function_2 = (Constructor<?> it_2) -> { List<Class<?>> _list = IterableExtensions.<Class<?>>toList(((Iterable<Class<?>>)Conversions.doWrapArray(it_2.getParameterTypes()))); return Boolean.valueOf(Objects.equal(_list, Collections.<Class<? extends Object>>unmodifiableList(CollectionLiterals.<Class<? extends Object>>newArrayList(int.class, String.class)))); }; Assert.assertTrue(IterableExtensions.<Constructor<?>>exists(((Iterable<Constructor<?>>)Conversions.doWrapArray(it_1.getDeclaredConstructors())), _function_2)); }; ObjectExtensions.<Class<?>>operator_doubleArrow(_compiledClass, _function_1); }; this.compilationTestHelper.compile(_builder, _function); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example #26
Source File: OldDataCompilerTest.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@Test public void testWithCreateExtension() { try { StringConcatenation _builder = new StringConcatenation(); _builder.append("@Data class Foo {"); _builder.newLine(); _builder.append("\t"); _builder.append("def create {} foo() {"); _builder.newLine(); _builder.append("\t"); _builder.append("}"); _builder.newLine(); _builder.append("}"); _builder.newLine(); final String text = _builder.toString(); this._validationTestHelper.assertNoIssues(this.clazz(text)); final IAcceptor<CompilationTestHelper.Result> _function = (CompilationTestHelper.Result it) -> { final Function1<Method, Boolean> _function_1 = (Method it_1) -> { return Boolean.valueOf(it_1.getName().startsWith("get")); }; Assert.assertFalse(IterableExtensions.<Method>exists(((Iterable<Method>)Conversions.doWrapArray(it.getCompiledClass().getDeclaredMethods())), _function_1)); }; this.compilationTestHelper.compile(text, _function); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example #27
Source File: SkillCompilerTest.java From sarl with Apache License 2.0 | 5 votes |
@Test public void actionmodifier_abstract_implicit() throws Exception { String source = multilineString( "capacity C1 { }", "skill S1 implements C1 {", " def name", "}" ); final String expectedS1 = multilineString( "import io.sarl.lang.annotation.SarlElementType;", "import io.sarl.lang.annotation.SarlSpecification;", "import io.sarl.lang.annotation.SyntheticMember;", "import io.sarl.lang.core.Agent;", "import io.sarl.lang.core.Skill;", "", "@SarlSpecification(\"" + SARLVersion.SPECIFICATION_RELEASE_VERSION_STRING + "\")", "@SarlElementType(" + SarlPackage.SARL_SKILL + ")", "@SuppressWarnings(\"all\")", "public abstract class S1 extends Skill implements C1 {", " public abstract void name();", " ", " @SyntheticMember", " public S1() {", " super();", " }", " ", " @SyntheticMember", " public S1(final Agent arg0) {", " super(arg0);", " }", "}", "" ); getCompileHelper().compile(source, new IAcceptor<CompilationTestHelper.Result>() { @Override public void accept(Result r) { assertEquals(expectedS1,r.getGeneratedCode("S1")); } }); }
Example #28
Source File: FinalFieldsConstructorCompilerTest.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@Test public void testIntegrationWithAccessors() { try { StringConcatenation _builder = new StringConcatenation(); _builder.append("import org.eclipse.xtend.lib.annotations.FinalFieldsConstructor"); _builder.newLine(); _builder.append("import org.eclipse.xtend.lib.annotations.Accessors"); _builder.newLine(); _builder.append("@FinalFieldsConstructor @Accessors class C {"); _builder.newLine(); _builder.append("\t"); _builder.append("val int a"); _builder.newLine(); _builder.append("\t"); _builder.append("val String b"); _builder.newLine(); _builder.append("}"); _builder.newLine(); final String source = _builder.toString(); this._validationTestHelper.assertNoErrors(this.clazz(source)); final IAcceptor<CompilationTestHelper.Result> _function = (CompilationTestHelper.Result it) -> { final Function1<Constructor<?>, Boolean> _function_1 = (Constructor<?> it_1) -> { List<Class<?>> _list = IterableExtensions.<Class<?>>toList(((Iterable<Class<?>>)Conversions.doWrapArray(it_1.getParameterTypes()))); return Boolean.valueOf(Objects.equal(_list, Collections.<Class<? extends Object>>unmodifiableList(CollectionLiterals.<Class<? extends Object>>newArrayList(int.class, String.class)))); }; Assert.assertTrue( IterableExtensions.<Constructor<?>>exists(((Iterable<Constructor<?>>)Conversions.doWrapArray(it.getCompiledClass().getDeclaredConstructors())), _function_1)); }; this.compilationTestHelper.compile(source, _function); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example #29
Source File: FinalFieldsConstructorCompilerTest.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@Test public void testOnClass() { try { StringConcatenation _builder = new StringConcatenation(); _builder.append("import org.eclipse.xtend.lib.annotations.FinalFieldsConstructor"); _builder.newLine(); _builder.append("@FinalFieldsConstructor class C {"); _builder.newLine(); _builder.append("\t"); _builder.append("val int a"); _builder.newLine(); _builder.append("\t"); _builder.append("val String b"); _builder.newLine(); _builder.append("}"); _builder.newLine(); final String source = _builder.toString(); this._validationTestHelper.assertNoErrors(this.clazz(source)); final IAcceptor<CompilationTestHelper.Result> _function = (CompilationTestHelper.Result it) -> { final Function1<Constructor<?>, Boolean> _function_1 = (Constructor<?> it_1) -> { List<Class<?>> _list = IterableExtensions.<Class<?>>toList(((Iterable<Class<?>>)Conversions.doWrapArray(it_1.getParameterTypes()))); return Boolean.valueOf(Objects.equal(_list, Collections.<Class<? extends Object>>unmodifiableList(CollectionLiterals.<Class<? extends Object>>newArrayList(int.class, String.class)))); }; Assert.assertTrue( IterableExtensions.<Constructor<?>>exists(((Iterable<Constructor<?>>)Conversions.doWrapArray(it.getCompiledClass().getDeclaredConstructors())), _function_1)); }; this.compilationTestHelper.compile(source, _function); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example #30
Source File: FinalFieldsConstructorCompilerTest.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@Test public void testIntegrationWithData() { try { StringConcatenation _builder = new StringConcatenation(); _builder.append("import org.eclipse.xtend.lib.annotations.FinalFieldsConstructor"); _builder.newLine(); _builder.append("import org.eclipse.xtend.lib.annotations.Data"); _builder.newLine(); _builder.append("@FinalFieldsConstructor @Data class C {"); _builder.newLine(); _builder.append("\t"); _builder.append("val int a"); _builder.newLine(); _builder.append("\t"); _builder.append("val String b"); _builder.newLine(); _builder.append("}"); _builder.newLine(); final String source = _builder.toString(); this._validationTestHelper.assertNoErrors(this.clazz(source)); final IAcceptor<CompilationTestHelper.Result> _function = (CompilationTestHelper.Result it) -> { final Function1<Constructor<?>, Boolean> _function_1 = (Constructor<?> it_1) -> { List<Class<?>> _list = IterableExtensions.<Class<?>>toList(((Iterable<Class<?>>)Conversions.doWrapArray(it_1.getParameterTypes()))); return Boolean.valueOf(Objects.equal(_list, Collections.<Class<? extends Object>>unmodifiableList(CollectionLiterals.<Class<? extends Object>>newArrayList(int.class, String.class)))); }; Assert.assertTrue( IterableExtensions.<Constructor<?>>exists(((Iterable<Constructor<?>>)Conversions.doWrapArray(it.getCompiledClass().getDeclaredConstructors())), _function_1)); }; this.compilationTestHelper.compile(source, _function); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }