use of org.eclipse.xtend.lib.macro.declaration.TypeDeclaration in project xtext-xtend by eclipse.
the class CompilationUnitImpl method toTypeDeclaration.
public TypeDeclaration toTypeDeclaration(final JvmDeclaredType delegate) {
final Function1<JvmDeclaredType, TypeDeclaration> _function = (JvmDeclaredType it) -> {
JvmTypeDeclarationImpl<? extends JvmDeclaredType> _switchResult = null;
boolean _matched = false;
if (delegate instanceof JvmGenericType) {
boolean _isInterface = ((JvmGenericType) delegate).isInterface();
if (_isInterface) {
_matched = true;
JvmInterfaceDeclarationImpl _xifexpression = null;
boolean _isBelongedToCompilationUnit = this.isBelongedToCompilationUnit(delegate);
if (_isBelongedToCompilationUnit) {
MutableJvmInterfaceDeclarationImpl _mutableJvmInterfaceDeclarationImpl = new MutableJvmInterfaceDeclarationImpl();
final Procedure1<MutableJvmInterfaceDeclarationImpl> _function_1 = (MutableJvmInterfaceDeclarationImpl it_1) -> {
it_1.setDelegate(((JvmGenericType) delegate));
it_1.setCompilationUnit(this);
};
_xifexpression = ObjectExtensions.<MutableJvmInterfaceDeclarationImpl>operator_doubleArrow(_mutableJvmInterfaceDeclarationImpl, _function_1);
} else {
JvmInterfaceDeclarationImpl _jvmInterfaceDeclarationImpl = new JvmInterfaceDeclarationImpl();
final Procedure1<JvmInterfaceDeclarationImpl> _function_2 = (JvmInterfaceDeclarationImpl it_1) -> {
it_1.setDelegate(((JvmGenericType) delegate));
it_1.setCompilationUnit(this);
};
_xifexpression = ObjectExtensions.<JvmInterfaceDeclarationImpl>operator_doubleArrow(_jvmInterfaceDeclarationImpl, _function_2);
}
_switchResult = _xifexpression;
}
}
if (!_matched) {
if (delegate instanceof JvmGenericType) {
_matched = true;
JvmClassDeclarationImpl _xifexpression = null;
boolean _isBelongedToCompilationUnit = this.isBelongedToCompilationUnit(delegate);
if (_isBelongedToCompilationUnit) {
MutableJvmClassDeclarationImpl _mutableJvmClassDeclarationImpl = new MutableJvmClassDeclarationImpl();
final Procedure1<MutableJvmClassDeclarationImpl> _function_1 = (MutableJvmClassDeclarationImpl it_1) -> {
it_1.setDelegate(((JvmGenericType) delegate));
it_1.setCompilationUnit(this);
};
_xifexpression = ObjectExtensions.<MutableJvmClassDeclarationImpl>operator_doubleArrow(_mutableJvmClassDeclarationImpl, _function_1);
} else {
JvmClassDeclarationImpl _jvmClassDeclarationImpl = new JvmClassDeclarationImpl();
final Procedure1<JvmClassDeclarationImpl> _function_2 = (JvmClassDeclarationImpl it_1) -> {
it_1.setDelegate(((JvmGenericType) delegate));
it_1.setCompilationUnit(this);
};
_xifexpression = ObjectExtensions.<JvmClassDeclarationImpl>operator_doubleArrow(_jvmClassDeclarationImpl, _function_2);
}
_switchResult = _xifexpression;
}
}
if (!_matched) {
if (delegate instanceof JvmAnnotationType) {
_matched = true;
JvmAnnotationTypeDeclarationImpl _xifexpression = null;
boolean _isBelongedToCompilationUnit = this.isBelongedToCompilationUnit(delegate);
if (_isBelongedToCompilationUnit) {
MutableJvmAnnotationTypeDeclarationImpl _mutableJvmAnnotationTypeDeclarationImpl = new MutableJvmAnnotationTypeDeclarationImpl();
final Procedure1<MutableJvmAnnotationTypeDeclarationImpl> _function_1 = (MutableJvmAnnotationTypeDeclarationImpl it_1) -> {
it_1.setDelegate(((JvmAnnotationType) delegate));
it_1.setCompilationUnit(this);
};
_xifexpression = ObjectExtensions.<MutableJvmAnnotationTypeDeclarationImpl>operator_doubleArrow(_mutableJvmAnnotationTypeDeclarationImpl, _function_1);
} else {
JvmAnnotationTypeDeclarationImpl _jvmAnnotationTypeDeclarationImpl = new JvmAnnotationTypeDeclarationImpl();
final Procedure1<JvmAnnotationTypeDeclarationImpl> _function_2 = (JvmAnnotationTypeDeclarationImpl it_1) -> {
it_1.setDelegate(((JvmAnnotationType) delegate));
it_1.setCompilationUnit(this);
};
_xifexpression = ObjectExtensions.<JvmAnnotationTypeDeclarationImpl>operator_doubleArrow(_jvmAnnotationTypeDeclarationImpl, _function_2);
}
_switchResult = _xifexpression;
}
}
if (!_matched) {
if (delegate instanceof JvmEnumerationType) {
_matched = true;
JvmEnumerationTypeDeclarationImpl _xifexpression = null;
boolean _isBelongedToCompilationUnit = this.isBelongedToCompilationUnit(delegate);
if (_isBelongedToCompilationUnit) {
MutableJvmEnumerationTypeDeclarationImpl _mutableJvmEnumerationTypeDeclarationImpl = new MutableJvmEnumerationTypeDeclarationImpl();
final Procedure1<MutableJvmEnumerationTypeDeclarationImpl> _function_1 = (MutableJvmEnumerationTypeDeclarationImpl it_1) -> {
it_1.setDelegate(((JvmEnumerationType) delegate));
it_1.setCompilationUnit(this);
};
_xifexpression = ObjectExtensions.<MutableJvmEnumerationTypeDeclarationImpl>operator_doubleArrow(_mutableJvmEnumerationTypeDeclarationImpl, _function_1);
} else {
JvmEnumerationTypeDeclarationImpl _jvmEnumerationTypeDeclarationImpl = new JvmEnumerationTypeDeclarationImpl();
final Procedure1<JvmEnumerationTypeDeclarationImpl> _function_2 = (JvmEnumerationTypeDeclarationImpl it_1) -> {
it_1.setDelegate(((JvmEnumerationType) delegate));
it_1.setCompilationUnit(this);
};
_xifexpression = ObjectExtensions.<JvmEnumerationTypeDeclarationImpl>operator_doubleArrow(_jvmEnumerationTypeDeclarationImpl, _function_2);
}
_switchResult = _xifexpression;
}
}
return ((TypeDeclaration) _switchResult);
};
return this.<JvmDeclaredType, TypeDeclaration>getOrCreate(delegate, _function);
}
use of org.eclipse.xtend.lib.macro.declaration.TypeDeclaration in project xtext-xtend by eclipse.
the class XtendAnnotationReferenceImpl method getAnnotationTypeDeclaration.
@Override
public AnnotationTypeDeclaration getAnnotationTypeDeclaration() {
AnnotationTypeDeclaration _switchResult = null;
JvmType _annotationType = this.getAnnotationType();
final JvmType type = _annotationType;
boolean _matched = false;
if (type instanceof JvmAnnotationType) {
_matched = true;
TypeDeclaration _typeDeclaration = this.getCompilationUnit().toTypeDeclaration(((JvmDeclaredType) type));
_switchResult = ((AnnotationTypeDeclaration) _typeDeclaration);
}
if (!_matched) {
_switchResult = null;
}
return _switchResult;
}
use of org.eclipse.xtend.lib.macro.declaration.TypeDeclaration in project xtext-xtend by eclipse.
the class DeclarationsTest method testAnnotation2.
@Test
public void testAnnotation2() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("class MyClass {");
_builder.newLine();
_builder.append("\t");
_builder.append("@com.google.inject.Inject() MyClass foo");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final Procedure1<CompilationUnitImpl> _function = (CompilationUnitImpl it) -> {
TypeDeclaration _head = IterableExtensions.head(it.getSourceTypeDeclarations());
final ClassDeclaration sourceClazz = ((ClassDeclaration) _head);
final MutableClassDeclaration javaClass = it.getTypeLookup().findClass("MyClass");
Assert.assertEquals(javaClass.getQualifiedName(), sourceClazz.getQualifiedName());
final FieldDeclaration field = IterableExtensions.head(sourceClazz.getDeclaredFields());
Assert.assertEquals(Boolean.FALSE, IterableExtensions.head(field.getAnnotations()).getValue("optional"));
final MutableFieldDeclaration javaField = IterableExtensions.head(javaClass.getDeclaredFields());
Object _value = IterableExtensions.head(javaField.getAnnotations()).getValue("optional");
Assert.assertFalse((((Boolean) _value)).booleanValue());
};
this.asCompilationUnit(this.validFile(_builder), _function);
}
use of org.eclipse.xtend.lib.macro.declaration.TypeDeclaration in project xtext-xtend by eclipse.
the class DeclarationsTest method testRemove.
@Test
public void testRemove() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("class C {");
_builder.newLine();
_builder.append("\t");
_builder.append("def void m() {}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final Procedure1<CompilationUnitImpl> _function = (CompilationUnitImpl it) -> {
TypeDeclaration _head = IterableExtensions.head(it.getSourceTypeDeclarations());
final ClassDeclaration c = ((ClassDeclaration) _head);
final MutableClassDeclaration mutable = it.getTypeLookup().findClass(c.getQualifiedName());
final Consumer<MutableMemberDeclaration> _function_1 = (MutableMemberDeclaration it_1) -> {
it_1.remove();
};
mutable.getDeclaredMembers().forEach(_function_1);
Assert.assertTrue(IterableExtensions.isEmpty(mutable.getDeclaredMembers()));
};
this.asCompilationUnit(this.validFile(_builder), _function);
}
use of org.eclipse.xtend.lib.macro.declaration.TypeDeclaration in project xtext-xtend by eclipse.
the class DeclarationsTest method testAnnotation.
@Test
public void testAnnotation() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("@SuppressWarnings(\"unused\")");
_builder.newLine();
_builder.append("class MyClass {");
_builder.newLine();
_builder.append("\t");
_builder.append("@com.google.inject.Inject(optional=true) MyClass foo");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final Procedure1<CompilationUnitImpl> _function = (CompilationUnitImpl it) -> {
Assert.assertNull(it.getPackageName());
TypeDeclaration _head = IterableExtensions.head(it.getSourceTypeDeclarations());
final ClassDeclaration clazz = ((ClassDeclaration) _head);
Assert.assertEquals("MyClass", clazz.getQualifiedName());
final AnnotationReference suppressWarning = IterableExtensions.head(clazz.getAnnotations());
final AnnotationTypeDeclaration supressWarningsDeclaration = suppressWarning.getAnnotationTypeDeclaration();
Assert.assertEquals("java.lang.SuppressWarnings", supressWarningsDeclaration.getQualifiedName());
Assert.assertEquals("unused", suppressWarning.getStringArrayValue("value")[0]);
Assert.assertEquals(2, IterableExtensions.size(supressWarningsDeclaration.getAnnotations()));
final AnnotationTypeElementDeclaration valueProperty = IterableExtensions.<AnnotationTypeElementDeclaration>head(Iterables.<AnnotationTypeElementDeclaration>filter(supressWarningsDeclaration.getDeclaredMembers(), AnnotationTypeElementDeclaration.class));
Assert.assertEquals("String[]", valueProperty.getType().toString());
Assert.assertEquals("value", valueProperty.getSimpleName());
MemberDeclaration _head_1 = IterableExtensions.head(clazz.getDeclaredMembers());
final FieldDeclaration field = ((FieldDeclaration) _head_1);
final AnnotationReference inject = IterableExtensions.head(field.getAnnotations());
Object _value = inject.getValue("optional");
Assert.assertTrue((((Boolean) _value)).booleanValue());
};
this.asCompilationUnit(this.validFile(_builder), _function);
}
Aggregations