use of org.eclipse.xtend.core.macro.declaration.CompilationUnitImpl 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.core.macro.declaration.CompilationUnitImpl in project xtext-xtend by eclipse.
the class TypeLookupImplTest method testFindClass_02.
@Test
public void testFindClass_02() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("package foo");
_builder.newLine();
_builder.append("import org.eclipse.xtend.core.tests.macro.declaration.AddNestedTypes");
_builder.newLine();
_builder.newLine();
_builder.append("@AddNestedTypes class MyClass {}");
_builder.newLine();
_builder.append("@AddNestedTypes enum MyEnum {}");
_builder.newLine();
_builder.append("@AddNestedTypes interface MyInterface {}");
_builder.newLine();
_builder.append("@AddNestedTypes annotation MyAnnotation {}");
_builder.newLine();
final Procedure1<CompilationUnitImpl> _function = (CompilationUnitImpl it) -> {
Assert.assertNotNull(it.getTypeLookup().findClass("foo.MyClass.NestedClass"));
Assert.assertNotNull(it.getTypeLookup().findInterface("foo.MyClass.NestedInterface"));
Assert.assertNotNull(it.getTypeLookup().findEnumerationType("foo.MyClass.NestedEnumerationType"));
Assert.assertNotNull(it.getTypeLookup().findAnnotationType("foo.MyClass.NestedAnnotationType"));
};
this.asCompilationUnit(this.validFile(_builder), _function);
}
use of org.eclipse.xtend.core.macro.declaration.CompilationUnitImpl in project xtext-xtend by eclipse.
the class TypeReferenceAssignabilityTest method asCompilationUnit.
public void asCompilationUnit(final XtendFile file, final Procedure1<? super CompilationUnitImpl> block) {
final CompilationUnitImpl compilationUnit = this.compilationUnitProvider.get();
compilationUnit.setXtendFile(file);
block.apply(compilationUnit);
}
use of org.eclipse.xtend.core.macro.declaration.CompilationUnitImpl 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);
}
use of org.eclipse.xtend.core.macro.declaration.CompilationUnitImpl in project xtext-xtend by eclipse.
the class ActiveAnnotationsProcessingInIDETest method assertProcessing.
@Override
public void assertProcessing(final Pair<String, String> macroContent, final Pair<String, String> clientContent, final Procedure1<? super CompilationUnitImpl> expectations) {
try {
this.macroFile = this.newSource(ActiveAnnotationsProcessingInIDETest.macroProject, macroContent.getKey(), macroContent.getValue().toString());
final int lidx = macroContent.getKey().lastIndexOf("/");
if ((lidx != (-1))) {
this.exportedPackage = macroContent.getKey().substring(0, lidx).replace("/", ".");
boolean _addExportedPackages = WorkbenchTestHelper.addExportedPackages(ActiveAnnotationsProcessingInIDETest.macroProject.getProject(), this.exportedPackage);
if (_addExportedPackages) {
IResourcesSetupUtil.reallyWaitForAutoBuild();
}
}
this.clientFile = this.newSource(ActiveAnnotationsProcessingInIDETest.userProject, clientContent.getKey(), clientContent.getValue().toString());
IResourcesSetupUtil.waitForBuild();
final ResourceSet resourceSet = this.resourceSetProvider.get(ActiveAnnotationsProcessingInIDETest.userProject.getProject());
final Resource resource = resourceSet.getResource(URI.createPlatformResourceURI(this.clientFile.getFullPath().toString(), true), true);
EcoreUtil2.resolveLazyCrossReferences(resource, CancelIndicator.NullImpl);
this.validator.validate(resource, CheckMode.FAST_ONLY, CancelIndicator.NullImpl);
final CompilationUnitImpl unit = this.compilationUnitProvider.get();
unit.setXtendFile(IterableExtensions.<XtendFile>head(Iterables.<XtendFile>filter(resource.getContents(), XtendFile.class)));
expectations.apply(unit);
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
Aggregations