Search in sources :

Example 6 with MemberDeclaration

use of org.eclipse.xtend.lib.macro.declaration.MemberDeclaration in project xtext-xtend by eclipse.

the class XtendMethodDeclarationImpl method getOverriddenOrImplementedMethods.

@Override
public Iterable<? extends MethodDeclaration> getOverriddenOrImplementedMethods() {
    boolean _isOverride = this.getDelegate().isOverride();
    if (_isOverride) {
        final JvmOperation jvmOperation = this.getCompilationUnit().getJvmModelAssociations().getDirectlyInferredOperation(this.getDelegate());
        final ResolvedFeatures resolvedFeatures = this.getCompilationUnit().getOverrideHelper().getResolvedFeatures(jvmOperation.getDeclaringType());
        final IResolvedOperation resolvedOperation = resolvedFeatures.getResolvedOperation(jvmOperation);
        final List<IResolvedOperation> overriddenOrImplemented = resolvedOperation.getOverriddenAndImplementedMethods();
        final Function1<IResolvedOperation, MemberDeclaration> _function = (IResolvedOperation it) -> {
            return this.getCompilationUnit().toMemberDeclaration(it.getDeclaration());
        };
        return Iterables.<MethodDeclaration>filter(ListExtensions.<IResolvedOperation, MemberDeclaration>map(overriddenOrImplemented, _function), MethodDeclaration.class);
    }
    return CollectionLiterals.<MethodDeclaration>emptyList();
}
Also used : JvmOperation(org.eclipse.xtext.common.types.JvmOperation) ResolvedFeatures(org.eclipse.xtext.xbase.typesystem.override.ResolvedFeatures) MemberDeclaration(org.eclipse.xtend.lib.macro.declaration.MemberDeclaration) MethodDeclaration(org.eclipse.xtend.lib.macro.declaration.MethodDeclaration) IResolvedOperation(org.eclipse.xtext.xbase.typesystem.override.IResolvedOperation)

Example 7 with MemberDeclaration

use of org.eclipse.xtend.lib.macro.declaration.MemberDeclaration in project xtext-xtend by eclipse.

the class XtendParameterDeclarationImpl method getDeclaringExecutable.

@Override
public ExecutableDeclaration getDeclaringExecutable() {
    EObject _eContainer = this.getDelegate().eContainer();
    MemberDeclaration _xtendMemberDeclaration = this.getCompilationUnit().toXtendMemberDeclaration(((XtendMember) _eContainer));
    return ((ExecutableDeclaration) _xtendMemberDeclaration);
}
Also used : XtendMember(org.eclipse.xtend.core.xtend.XtendMember) MemberDeclaration(org.eclipse.xtend.lib.macro.declaration.MemberDeclaration) EObject(org.eclipse.emf.ecore.EObject)

Example 8 with MemberDeclaration

use of org.eclipse.xtend.lib.macro.declaration.MemberDeclaration in project xtext-xtend by eclipse.

the class DeclarationsTest method testSimpleClassWithField.

@Test
public void testSimpleClassWithField() {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("package foo");
    _builder.newLine();
    _builder.newLine();
    _builder.append("class MyClass extends Object implements java.io.Serializable {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("MyClass foo");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    final Procedure1<CompilationUnitImpl> _function = (CompilationUnitImpl it) -> {
        Assert.assertEquals("foo", it.getPackageName());
        TypeDeclaration _head = IterableExtensions.head(it.getSourceTypeDeclarations());
        final ClassDeclaration clazz = ((ClassDeclaration) _head);
        Assert.assertEquals("foo.MyClass", clazz.getQualifiedName());
        Assert.assertEquals("Object", clazz.getExtendedClass().toString());
        Assert.assertEquals("Serializable", IterableExtensions.head(clazz.getImplementedInterfaces()).toString());
        MemberDeclaration _head_1 = IterableExtensions.head(clazz.getDeclaredMembers());
        final FieldDeclaration field = ((FieldDeclaration) _head_1);
        Assert.assertEquals("foo", field.getSimpleName());
        Assert.assertSame(it.getTypeLookup().findClass("foo.MyClass"), field.getType().getType());
    };
    this.asCompilationUnit(this.validFile(_builder), _function);
}
Also used : ClassDeclaration(org.eclipse.xtend.lib.macro.declaration.ClassDeclaration) MutableClassDeclaration(org.eclipse.xtend.lib.macro.declaration.MutableClassDeclaration) CompilationUnitImpl(org.eclipse.xtend.core.macro.declaration.CompilationUnitImpl) MutableMemberDeclaration(org.eclipse.xtend.lib.macro.declaration.MutableMemberDeclaration) MemberDeclaration(org.eclipse.xtend.lib.macro.declaration.MemberDeclaration) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) AnnotationTypeDeclaration(org.eclipse.xtend.lib.macro.declaration.AnnotationTypeDeclaration) TypeDeclaration(org.eclipse.xtend.lib.macro.declaration.TypeDeclaration) MutableFieldDeclaration(org.eclipse.xtend.lib.macro.declaration.MutableFieldDeclaration) FieldDeclaration(org.eclipse.xtend.lib.macro.declaration.FieldDeclaration) Test(org.junit.Test)

Example 9 with MemberDeclaration

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

Example 10 with MemberDeclaration

use of org.eclipse.xtend.lib.macro.declaration.MemberDeclaration in project xtext-xtend by eclipse.

the class JvmMethodDeclarationImpl method getOverriddenOrImplementedMethods.

@Override
public Iterable<? extends MethodDeclaration> getOverriddenOrImplementedMethods() {
    final ResolvedFeatures resolvedFeatures = this.getCompilationUnit().getOverrideHelper().getResolvedFeatures(this.getDelegate().getDeclaringType());
    final IResolvedOperation resolvedOperation = resolvedFeatures.getResolvedOperation(this.getDelegate());
    final List<IResolvedOperation> overriddenOrImplemented = resolvedOperation.getOverriddenAndImplementedMethods();
    final Function1<IResolvedOperation, MemberDeclaration> _function = (IResolvedOperation it) -> {
        return this.getCompilationUnit().toMemberDeclaration(it.getDeclaration());
    };
    return Iterables.<MethodDeclaration>filter(ListExtensions.<IResolvedOperation, MemberDeclaration>map(overriddenOrImplemented, _function), MethodDeclaration.class);
}
Also used : ResolvedFeatures(org.eclipse.xtext.xbase.typesystem.override.ResolvedFeatures) MemberDeclaration(org.eclipse.xtend.lib.macro.declaration.MemberDeclaration) MethodDeclaration(org.eclipse.xtend.lib.macro.declaration.MethodDeclaration) IResolvedOperation(org.eclipse.xtext.xbase.typesystem.override.IResolvedOperation)

Aggregations

MemberDeclaration (org.eclipse.xtend.lib.macro.declaration.MemberDeclaration)16 EObject (org.eclipse.emf.ecore.EObject)5 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)5 MutableMemberDeclaration (org.eclipse.xtend.lib.macro.declaration.MutableMemberDeclaration)4 JvmMember (org.eclipse.xtext.common.types.JvmMember)4 MutableFieldDeclaration (org.eclipse.xtend.lib.macro.declaration.MutableFieldDeclaration)3 CompilationUnitImpl (org.eclipse.xtend.core.macro.declaration.CompilationUnitImpl)2 AnnotationTypeDeclaration (org.eclipse.xtend.lib.macro.declaration.AnnotationTypeDeclaration)2 ClassDeclaration (org.eclipse.xtend.lib.macro.declaration.ClassDeclaration)2 FieldDeclaration (org.eclipse.xtend.lib.macro.declaration.FieldDeclaration)2 MethodDeclaration (org.eclipse.xtend.lib.macro.declaration.MethodDeclaration)2 MutableClassDeclaration (org.eclipse.xtend.lib.macro.declaration.MutableClassDeclaration)2 MutableMethodDeclaration (org.eclipse.xtend.lib.macro.declaration.MutableMethodDeclaration)2 TypeDeclaration (org.eclipse.xtend.lib.macro.declaration.TypeDeclaration)2 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)2 JvmConstructor (org.eclipse.xtext.common.types.JvmConstructor)2 JvmEnumerationLiteral (org.eclipse.xtext.common.types.JvmEnumerationLiteral)2 JvmField (org.eclipse.xtext.common.types.JvmField)2 IResolvedOperation (org.eclipse.xtext.xbase.typesystem.override.IResolvedOperation)2 ResolvedFeatures (org.eclipse.xtext.xbase.typesystem.override.ResolvedFeatures)2