Search in sources :

Example 41 with CompilationUnitImpl

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);
}
Also used : ClassDeclaration(org.eclipse.xtend.lib.macro.declaration.ClassDeclaration) MutableClassDeclaration(org.eclipse.xtend.lib.macro.declaration.MutableClassDeclaration) MutableFieldDeclaration(org.eclipse.xtend.lib.macro.declaration.MutableFieldDeclaration) CompilationUnitImpl(org.eclipse.xtend.core.macro.declaration.CompilationUnitImpl) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) AccessibleObject(java.lang.reflect.AccessibleObject) AnnotationTypeDeclaration(org.eclipse.xtend.lib.macro.declaration.AnnotationTypeDeclaration) TypeDeclaration(org.eclipse.xtend.lib.macro.declaration.TypeDeclaration) MutableClassDeclaration(org.eclipse.xtend.lib.macro.declaration.MutableClassDeclaration) MutableFieldDeclaration(org.eclipse.xtend.lib.macro.declaration.MutableFieldDeclaration) FieldDeclaration(org.eclipse.xtend.lib.macro.declaration.FieldDeclaration) Test(org.junit.Test)

Example 42 with CompilationUnitImpl

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);
}
Also used : CompilationUnitImpl(org.eclipse.xtend.core.macro.declaration.CompilationUnitImpl) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Test(org.junit.Test)

Example 43 with CompilationUnitImpl

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);
}
Also used : CompilationUnitImpl(org.eclipse.xtend.core.macro.declaration.CompilationUnitImpl)

Example 44 with CompilationUnitImpl

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);
}
Also used : EObjectDiagnosticImpl(org.eclipse.xtext.validation.EObjectDiagnosticImpl) CompilationUnitImpl(org.eclipse.xtend.core.macro.declaration.CompilationUnitImpl) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Resource(org.eclipse.emf.ecore.resource.Resource) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) MutableClassDeclaration(org.eclipse.xtend.lib.macro.declaration.MutableClassDeclaration) Test(org.junit.Test)

Example 45 with CompilationUnitImpl

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);
    }
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) CompilationUnitImpl(org.eclipse.xtend.core.macro.declaration.CompilationUnitImpl) Resource(org.eclipse.emf.ecore.resource.Resource) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet)

Aggregations

CompilationUnitImpl (org.eclipse.xtend.core.macro.declaration.CompilationUnitImpl)139 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)132 Test (org.junit.Test)130 MutableClassDeclaration (org.eclipse.xtend.lib.macro.declaration.MutableClassDeclaration)91 MutableMethodDeclaration (org.eclipse.xtend.lib.macro.declaration.MutableMethodDeclaration)22 AnnotationReference (org.eclipse.xtend.lib.macro.declaration.AnnotationReference)17 MutableFieldDeclaration (org.eclipse.xtend.lib.macro.declaration.MutableFieldDeclaration)15 EObject (org.eclipse.emf.ecore.EObject)12 MutableInterfaceDeclaration (org.eclipse.xtend.lib.macro.declaration.MutableInterfaceDeclaration)11 Resource (org.eclipse.emf.ecore.resource.Resource)10 AnnotationTypeDeclaration (org.eclipse.xtend.lib.macro.declaration.AnnotationTypeDeclaration)10 ClassDeclaration (org.eclipse.xtend.lib.macro.declaration.ClassDeclaration)10 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)10 List (java.util.List)9 Element (org.eclipse.xtend.lib.macro.declaration.Element)9 Type (org.eclipse.xtend.lib.macro.declaration.Type)9 TypeDeclaration (org.eclipse.xtend.lib.macro.declaration.TypeDeclaration)9 Function1 (org.eclipse.xtext.xbase.lib.Functions.Function1)9 Procedure1 (org.eclipse.xtext.xbase.lib.Procedures.Procedure1)9 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)8