Java Code Examples for org.eclipse.xtend.lib.macro.declaration.MutableClassDeclaration#setExtendedClass()

The following examples show how to use org.eclipse.xtend.lib.macro.declaration.MutableClassDeclaration#setExtendedClass() . 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: DeclarationsTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testSetImplementedInterfaces() {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("class BaseClass {}");
  _builder.newLine();
  _builder.append("interface Interface {}");
  _builder.newLine();
  final Procedure1<CompilationUnitImpl> _function = (CompilationUnitImpl it) -> {
    final MutableClassDeclaration baseClass = it.getTypeLookup().findClass("BaseClass");
    final MutableInterfaceDeclaration interf = it.getTypeLookup().findInterface("Interface");
    final TypeReference objectType = baseClass.getExtendedClass();
    Assert.assertEquals("Object", objectType.getSimpleName());
    Assert.assertTrue(IterableExtensions.isEmpty(baseClass.getImplementedInterfaces()));
    final TypeReference superType = it.getTypeReferenceProvider().newTypeReference(AccessibleObject.class);
    baseClass.setExtendedClass(superType);
    Assert.assertEquals("AccessibleObject", baseClass.getExtendedClass().getSimpleName());
    Assert.assertTrue(IterableExtensions.isEmpty(baseClass.getImplementedInterfaces()));
    baseClass.setExtendedClass(null);
    Assert.assertEquals("Object", baseClass.getExtendedClass().getSimpleName());
    Assert.assertTrue(IterableExtensions.isEmpty(baseClass.getImplementedInterfaces()));
    TypeReference _newTypeReference = it.getTypeReferenceProvider().newTypeReference(interf);
    baseClass.setImplementedInterfaces(Collections.<TypeReference>unmodifiableList(CollectionLiterals.<TypeReference>newArrayList(_newTypeReference)));
    Assert.assertEquals("Interface", IterableExtensions.head(baseClass.getImplementedInterfaces()).getSimpleName());
    baseClass.setImplementedInterfaces(Collections.<TypeReference>unmodifiableList(CollectionLiterals.<TypeReference>newArrayList()));
    Assert.assertTrue(IterableExtensions.isEmpty(baseClass.getImplementedInterfaces()));
  };
  this.asCompilationUnit(this.validFile(_builder), _function);
}
 
Example 2
Source File: ProjectTemplateProcessor.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void doTransform(final MutableClassDeclaration annotatedClass, @Extension final TransformationContext context) {
  annotatedClass.setExtendedClass(context.newTypeReference(AbstractProjectTemplate.class));
}
 
Example 3
Source File: FileTemplateProcessor.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void doTransform(final MutableClassDeclaration annotatedClass, @Extension final TransformationContext context) {
  annotatedClass.setExtendedClass(context.newTypeReference(AbstractFileTemplate.class));
}