use of org.eclipse.xtend.lib.macro.declaration.MutableClassDeclaration in project xtext-xtend by eclipse.
the class TypeLookupImpl method findClass.
@Override
public MutableClassDeclaration findClass(final String qualifiedName) {
final Type type = this.findType(qualifiedName);
MutableClassDeclaration _switchResult = null;
boolean _matched = false;
if (type instanceof MutableClassDeclaration) {
_matched = true;
_switchResult = ((MutableClassDeclaration) type);
}
return _switchResult;
}
use of org.eclipse.xtend.lib.macro.declaration.MutableClassDeclaration 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.MutableClassDeclaration in project xtext-xtend by eclipse.
the class DeclarationsTest method testAnnotationReferenceValues_2.
@Test
public void testAnnotationReferenceValues_2() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("package foo");
_builder.newLine();
_builder.append("@test.Annotation(");
_builder.newLine();
_builder.append("\t");
_builder.append("intValue = 2 / 2 + 2 * 3 - 4 % 1,");
_builder.newLine();
_builder.append("\t");
_builder.append("longValue = 42 + 4 + 6 * 42 - 4 / 45,");
_builder.newLine();
_builder.append("\t");
_builder.append("stringValue = \'foo\' + \'baz\',");
_builder.newLine();
_builder.append("\t");
_builder.append("booleanArrayValue = #[true, false],");
_builder.newLine();
_builder.append("\t");
_builder.append("intArrayValue = #[ -1, 34 + 45, 2 - 6 ],");
_builder.newLine();
_builder.append("\t");
_builder.append("longArrayValue = #[42, 5 * -3],");
_builder.newLine();
_builder.append("\t");
_builder.append("stringArrayValue = #[\'foo\', \'bla\' + \'buzz\'],");
_builder.newLine();
_builder.append("\t");
_builder.append("typeValue = String,");
_builder.newLine();
_builder.append("\t");
_builder.append("typeArrayValue = #[String, Integer],");
_builder.newLine();
_builder.append("\t");
_builder.append("annotation2Value = @test.Annotation2(\'foo\' + \'wuppa\'),");
_builder.newLine();
_builder.append("\t");
_builder.append("annotation2ArrayValue = #[@test.Annotation2, @test.Annotation2(\'foo\'+\'wuppa\')]");
_builder.newLine();
_builder.append("\t");
_builder.append(") class Bar {");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final Procedure1<CompilationUnitImpl> _function = (CompilationUnitImpl it) -> {
final MutableClassDeclaration baseClass = it.getTypeLookup().findClass("foo.Bar");
final AnnotationReference annoRef = IterableExtensions.head(baseClass.getAnnotations());
Assert.assertEquals((((2 / 2) + (2 * 3)) - (4 % 1)), annoRef.getIntValue("intValue"));
Assert.assertEquals((((42 + 4) + (6 * 42)) - (4 / 45)), annoRef.getLongValue("longValue"));
Assert.assertEquals("foobaz", annoRef.getStringValue("stringValue"));
final boolean[] bools = annoRef.getBooleanArrayValue("booleanArrayValue");
Assert.assertTrue(bools[0]);
Assert.assertFalse(bools[1]);
Assert.assertArrayEquals(new int[] { (-1), (34 + 45), (2 - 6) }, annoRef.getIntArrayValue("intArrayValue"));
final TypeReference[] type = annoRef.getClassArrayValue("typeArrayValue");
Assert.assertEquals(it.getTypeReferenceProvider().newTypeReference(Integer.class), type[1]);
final AnnotationReference anno = annoRef.getAnnotationValue("annotation2Value");
Assert.assertEquals("foowuppa", anno.getStringValue("value"));
final AnnotationReference[] annoArray = annoRef.getAnnotationArrayValue("annotation2ArrayValue");
Assert.assertEquals("HUBBA BUBBA!", annoArray[0].getValue("value"));
};
this.asCompilationUnit(this.validFile(_builder), _function);
}
use of org.eclipse.xtend.lib.macro.declaration.MutableClassDeclaration 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.MutableClassDeclaration in project xtext-xtend by eclipse.
the class ProblemSupportTests method testErrorOnDerivedElement.
@Test
public void testErrorOnDerivedElement() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("class MyClass {");
_builder.newLine();
_builder.append("\t");
_builder.append("String foo = \'foo\'");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final Procedure1<CompilationUnitImpl> _function = (CompilationUnitImpl it) -> {
final MutableClassDeclaration derived = it.getTypeLookup().findClass("MyClass");
it.getProblemSupport().addError(derived, "error on derived element");
Assert.assertEquals("error on derived element", IterableExtensions.<Resource.Diagnostic>head(it.getXtendFile().eResource().getErrors()).getMessage());
Resource.Diagnostic _head = IterableExtensions.<Resource.Diagnostic>head(it.getXtendFile().eResource().getErrors());
Assert.assertEquals(IterableExtensions.<XtendTypeDeclaration>head(it.getXtendFile().getXtendTypes()), ((EObjectDiagnosticImpl) _head).getProblematicObject());
};
this.asCompilationUnit(this.validFile(_builder), _function);
}
Aggregations