Java Code Examples for org.eclipse.xtext.xbase.testing.CompilationTestHelper#Result

The following examples show how to use org.eclipse.xtext.xbase.testing.CompilationTestHelper#Result . 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 vote down vote up
@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 2
Source File: OldDataCompilerTest.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@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 3
Source File: ActiveAnnotationsRuntimeTest.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@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 4
Source File: NewDataCompilerTest.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@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 5
Source File: NewDataCompilerTest.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@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 6
Source File: DelegateCompilerTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@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 7
Source File: NewDataCompilerTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@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 8
Source File: FinalFieldsConstructorCompilerTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@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);
  }
}
 
Example 9
Source File: OldDataCompilerTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@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 10
Source File: FinalFieldsConstructorCompilerTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@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 11
Source File: AbstractXtendCompilerTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
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 12
Source File: FinalFieldsConstructorCompilerTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@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 13
Source File: OldDataCompilerTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@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 14
Source File: NewDataCompilerTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@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 15
Source File: NewDataCompilerTest.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
@Test
public void testBug449185() {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("import org.eclipse.xtend.lib.annotations.Data");
    _builder.newLine();
    _builder.append("@Data class A {");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    _builder.newLine();
    _builder.append("@Data class C extends A {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("val int c");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    _builder.newLine();
    _builder.append("@Data class B {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("val int b");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    _builder.newLine();
    _builder.append("@Data class D extends B {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("val double d");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    final IAcceptor<CompilationTestHelper.Result> _function = (CompilationTestHelper.Result it) -> {
      final Class<?> d = it.getCompiledClass("D");
      final Class<?>[] parameterTypes = IterableExtensions.<Constructor<?>>head(((Iterable<Constructor<?>>)Conversions.doWrapArray(d.getDeclaredConstructors()))).getParameterTypes();
      Assert.assertArrayEquals(new Object[] { int.class, double.class }, parameterTypes);
    };
    this.compilationTestHelper.compile(_builder, _function);
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 16
Source File: DelegateCompilerTest.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
@Test
public void testDelegateMethod() {
  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 def B delegate() {null}");
    _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) -> {
        String _name = it_1.getName();
        return Boolean.valueOf(Objects.equal(_name, "m"));
      };
      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 17
Source File: DelegatingClassloader.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
public DelegatingClassloader(final ClassLoader parent, final CompilationTestHelper.Result classFinder) {
  super(parent);
  this.classFinder = classFinder;
}
 
Example 18
Source File: DelegateCompilerTest.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
@Test
public void testIgnoreInterfacesNotDeclaredOnTargetClass() {
  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("interface B {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("def void f()");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    _builder.append("class C implements A, B {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("override m() {}");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("override f() {}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    _builder.append("class D implements A {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("@Delegate C delegate");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    final IAcceptor<CompilationTestHelper.Result> _function = (CompilationTestHelper.Result it) -> {
      final Function1<Method, Boolean> _function_1 = (Method it_1) -> {
        String _name = it_1.getName();
        return Boolean.valueOf(Objects.equal(_name, "f"));
      };
      Assert.assertFalse(IterableExtensions.<Method>exists(((Iterable<Method>)Conversions.doWrapArray(it.getCompiledClass().getDeclaredMethods())), _function_1));
    };
    this.compilationTestHelper.compile(_builder, _function);
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 19
Source File: DelegateCompilerTest.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
@Test
public void testObjectMethodsAreIgnored2() {
  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("override Object clone() throws CloneNotSupportedException");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("override void finalize() throws Throwable");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    _builder.append("class B implements A {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("override clone() throws CloneNotSupportedException {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("super.clone");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("override finalize() throws Throwable {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("super.finalize");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _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 IAcceptor<CompilationTestHelper.Result> _function = (CompilationTestHelper.Result it) -> {
      StringConcatenation _builder_1 = new StringConcatenation();
      _builder_1.append("import org.eclipse.xtend.lib.annotations.Delegate;");
      _builder_1.newLine();
      _builder_1.newLine();
      _builder_1.append("@SuppressWarnings(\"all\")");
      _builder_1.newLine();
      _builder_1.append("public class C implements A {");
      _builder_1.newLine();
      _builder_1.append("  ");
      _builder_1.append("@Delegate");
      _builder_1.newLine();
      _builder_1.append("  ");
      _builder_1.append("private B delegate;");
      _builder_1.newLine();
      _builder_1.append("}");
      _builder_1.newLine();
      Assert.assertEquals(
        _builder_1.toString(), it.getGeneratedCode("C"));
    };
    this.compilationTestHelper.compile(_builder, _function);
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 20
Source File: DelegateCompilerTest.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
@Test
public void methodOrder() {
  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 c()");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("def void a()");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("def void b()");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    _builder.append("class C implements A {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("@Delegate A a");
    _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) -> {
      StringConcatenation _builder_1 = new StringConcatenation();
      _builder_1.append("import org.eclipse.xtend.lib.annotations.Delegate;");
      _builder_1.newLine();
      _builder_1.newLine();
      _builder_1.append("@SuppressWarnings(\"all\")");
      _builder_1.newLine();
      _builder_1.append("public class C implements A {");
      _builder_1.newLine();
      _builder_1.append("  ");
      _builder_1.append("@Delegate");
      _builder_1.newLine();
      _builder_1.append("  ");
      _builder_1.append("private A a;");
      _builder_1.newLine();
      _builder_1.append("  ");
      _builder_1.newLine();
      _builder_1.append("  ");
      _builder_1.append("public void a() {");
      _builder_1.newLine();
      _builder_1.append("    ");
      _builder_1.append("this.a.a();");
      _builder_1.newLine();
      _builder_1.append("  ");
      _builder_1.append("}");
      _builder_1.newLine();
      _builder_1.append("  ");
      _builder_1.newLine();
      _builder_1.append("  ");
      _builder_1.append("public void b() {");
      _builder_1.newLine();
      _builder_1.append("    ");
      _builder_1.append("this.a.b();");
      _builder_1.newLine();
      _builder_1.append("  ");
      _builder_1.append("}");
      _builder_1.newLine();
      _builder_1.append("  ");
      _builder_1.newLine();
      _builder_1.append("  ");
      _builder_1.append("public void c() {");
      _builder_1.newLine();
      _builder_1.append("    ");
      _builder_1.append("this.a.c();");
      _builder_1.newLine();
      _builder_1.append("  ");
      _builder_1.append("}");
      _builder_1.newLine();
      _builder_1.append("}");
      _builder_1.newLine();
      Assert.assertEquals(_builder_1.toString(), it.getGeneratedCode("C"));
    };
    this.compilationTestHelper.compile(text, _function);
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}