Search in sources :

Example 16 with Type

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

the class DeclarationsTest method testIsAssignable.

@Test
public void testIsAssignable() {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("package foo");
    _builder.newLine();
    _builder.newLine();
    _builder.append("class BaseClass implements InterfaceA {");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    _builder.append("class SubType extends BaseClass implements InterfaceA {");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    _builder.append("interface InterfaceA {}");
    _builder.newLine();
    _builder.append("interface InterfaceB {}");
    _builder.newLine();
    final Procedure1<CompilationUnitImpl> _function = (CompilationUnitImpl it) -> {
        TypeDeclaration _get = ((TypeDeclaration[]) Conversions.unwrapArray(it.getSourceTypeDeclarations(), TypeDeclaration.class))[0];
        final ClassDeclaration baseClass = ((ClassDeclaration) _get);
        final MutableClassDeclaration subClass = it.getTypeLookup().findClass("foo.SubType");
        TypeDeclaration _get_1 = ((TypeDeclaration[]) Conversions.unwrapArray(it.getSourceTypeDeclarations(), TypeDeclaration.class))[2];
        final InterfaceDeclaration interfaceA = ((InterfaceDeclaration) _get_1);
        TypeDeclaration _get_2 = ((TypeDeclaration[]) Conversions.unwrapArray(it.getSourceTypeDeclarations(), TypeDeclaration.class))[3];
        final InterfaceDeclaration interfaceB = ((InterfaceDeclaration) _get_2);
        final Type object = it.getTypeReferenceProvider().getObject().getType();
        Assert.assertTrue(object.isAssignableFrom(baseClass));
        Assert.assertTrue(object.isAssignableFrom(subClass));
        Assert.assertTrue(object.isAssignableFrom(interfaceA));
        Assert.assertTrue(object.isAssignableFrom(interfaceB));
        Assert.assertTrue(baseClass.isAssignableFrom(baseClass));
        Assert.assertTrue(baseClass.isAssignableFrom(subClass));
        Assert.assertFalse(baseClass.isAssignableFrom(interfaceB));
        Assert.assertFalse(baseClass.isAssignableFrom(interfaceA));
        Assert.assertFalse(baseClass.isAssignableFrom(object));
        Assert.assertTrue(interfaceA.isAssignableFrom(baseClass));
        Assert.assertTrue(interfaceA.isAssignableFrom(subClass));
        Assert.assertTrue(interfaceA.isAssignableFrom(interfaceA));
        Assert.assertFalse(interfaceA.isAssignableFrom(interfaceB));
        Assert.assertFalse(interfaceA.isAssignableFrom(object));
    };
    this.asCompilationUnit(this.validFile(_builder), _function);
}
Also used : Type(org.eclipse.xtend.lib.macro.declaration.Type) ClassDeclaration(org.eclipse.xtend.lib.macro.declaration.ClassDeclaration) MutableClassDeclaration(org.eclipse.xtend.lib.macro.declaration.MutableClassDeclaration) CompilationUnitImpl(org.eclipse.xtend.core.macro.declaration.CompilationUnitImpl) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) InterfaceDeclaration(org.eclipse.xtend.lib.macro.declaration.InterfaceDeclaration) MutableInterfaceDeclaration(org.eclipse.xtend.lib.macro.declaration.MutableInterfaceDeclaration) AnnotationTypeDeclaration(org.eclipse.xtend.lib.macro.declaration.AnnotationTypeDeclaration) TypeDeclaration(org.eclipse.xtend.lib.macro.declaration.TypeDeclaration) MutableClassDeclaration(org.eclipse.xtend.lib.macro.declaration.MutableClassDeclaration) Test(org.junit.Test)

Example 17 with Type

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

the class CompilationUnitImpl method toType.

public Type toType(final JvmType delegate) {
    final Function1<JvmType, Type> _function = (JvmType it) -> {
        Type _switchResult = null;
        boolean _matched = false;
        if (delegate instanceof JvmDeclaredType) {
            _matched = true;
            _switchResult = this.toTypeDeclaration(((JvmDeclaredType) delegate));
        }
        if (!_matched) {
            if (delegate instanceof JvmTypeParameter) {
                _matched = true;
                _switchResult = this.toTypeParameterDeclaration(((JvmTypeParameter) delegate));
            }
        }
        if (!_matched) {
            if (delegate instanceof JvmVoid) {
                _matched = true;
                VoidTypeImpl _voidTypeImpl = new VoidTypeImpl();
                final Procedure1<VoidTypeImpl> _function_1 = (VoidTypeImpl it_1) -> {
                    it_1.setDelegate(((JvmVoid) delegate));
                    it_1.setCompilationUnit(this);
                };
                _switchResult = ObjectExtensions.<VoidTypeImpl>operator_doubleArrow(_voidTypeImpl, _function_1);
            }
        }
        if (!_matched) {
            if (delegate instanceof JvmPrimitiveType) {
                _matched = true;
                PrimitiveTypeImpl _primitiveTypeImpl = new PrimitiveTypeImpl();
                final Procedure1<PrimitiveTypeImpl> _function_1 = (PrimitiveTypeImpl it_1) -> {
                    it_1.setDelegate(((JvmPrimitiveType) delegate));
                    it_1.setCompilationUnit(this);
                };
                _switchResult = ObjectExtensions.<PrimitiveTypeImpl>operator_doubleArrow(_primitiveTypeImpl, _function_1);
            }
        }
        return _switchResult;
    };
    return this.<JvmType, Type>getOrCreate(delegate, _function);
}
Also used : PrimitiveTypeImpl(org.eclipse.xtend.core.macro.declaration.PrimitiveTypeImpl) JvmArrayType(org.eclipse.xtext.common.types.JvmArrayType) JvmEnumerationType(org.eclipse.xtext.common.types.JvmEnumerationType) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) XtendAnnotationType(org.eclipse.xtend.core.xtend.XtendAnnotationType) JvmType(org.eclipse.xtext.common.types.JvmType) JvmComponentType(org.eclipse.xtext.common.types.JvmComponentType) JvmPrimitiveType(org.eclipse.xtext.common.types.JvmPrimitiveType) AccessorType(org.eclipse.xtend.lib.annotations.AccessorType) Type(org.eclipse.xtend.lib.macro.declaration.Type) JvmAnnotationType(org.eclipse.xtext.common.types.JvmAnnotationType) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) JvmVoid(org.eclipse.xtext.common.types.JvmVoid) JvmTypeParameter(org.eclipse.xtext.common.types.JvmTypeParameter) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) JvmPrimitiveType(org.eclipse.xtext.common.types.JvmPrimitiveType) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) VoidTypeImpl(org.eclipse.xtend.core.macro.declaration.VoidTypeImpl) JvmType(org.eclipse.xtext.common.types.JvmType)

Example 18 with Type

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

the class TypeLookupImpl method findType.

private Type findType(final String qualifiedName) {
    final Function1<JvmDeclaredType, String> _function = (JvmDeclaredType type) -> {
        return type.getQualifiedName('.');
    };
    final Function1<JvmDeclaredType, Iterable<? extends JvmDeclaredType>> _function_1 = (JvmDeclaredType type) -> {
        return Iterables.<JvmDeclaredType>filter(type.getMembers(), JvmDeclaredType.class);
    };
    final JvmDeclaredType result = this.<JvmDeclaredType>recursiveFindType(qualifiedName, Iterables.<JvmDeclaredType>filter(this.compilationUnit.getXtendFile().eResource().getContents(), JvmDeclaredType.class), _function, _function_1);
    Type _xifexpression = null;
    if ((result != null)) {
        _xifexpression = this.compilationUnit.toType(result);
    }
    return _xifexpression;
}
Also used : JvmType(org.eclipse.xtext.common.types.JvmType) Type(org.eclipse.xtend.lib.macro.declaration.Type) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType)

Example 19 with Type

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

the class TypeLookupImpl method findAnnotationType.

@Override
public MutableAnnotationTypeDeclaration findAnnotationType(final String qualifiedName) {
    final Type type = this.findType(qualifiedName);
    MutableAnnotationTypeDeclaration _switchResult = null;
    boolean _matched = false;
    if (type instanceof MutableAnnotationTypeDeclaration) {
        _matched = true;
        _switchResult = ((MutableAnnotationTypeDeclaration) type);
    }
    return _switchResult;
}
Also used : JvmType(org.eclipse.xtext.common.types.JvmType) Type(org.eclipse.xtend.lib.macro.declaration.Type) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) MutableAnnotationTypeDeclaration(org.eclipse.xtend.lib.macro.declaration.MutableAnnotationTypeDeclaration)

Example 20 with Type

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

the class TypeLookupImpl method findInterface.

@Override
public MutableInterfaceDeclaration findInterface(final String qualifiedName) {
    final Type type = this.findType(qualifiedName);
    MutableInterfaceDeclaration _switchResult = null;
    boolean _matched = false;
    if (type instanceof MutableInterfaceDeclaration) {
        _matched = true;
        _switchResult = ((MutableInterfaceDeclaration) type);
    }
    return _switchResult;
}
Also used : MutableInterfaceDeclaration(org.eclipse.xtend.lib.macro.declaration.MutableInterfaceDeclaration) JvmType(org.eclipse.xtext.common.types.JvmType) Type(org.eclipse.xtend.lib.macro.declaration.Type) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType)

Aggregations

Type (org.eclipse.xtend.lib.macro.declaration.Type)23 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)16 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)11 Test (org.junit.Test)11 CompilationUnitImpl (org.eclipse.xtend.core.macro.declaration.CompilationUnitImpl)10 MutableClassDeclaration (org.eclipse.xtend.lib.macro.declaration.MutableClassDeclaration)10 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)9 JvmType (org.eclipse.xtext.common.types.JvmType)7 AnnotationReference (org.eclipse.xtend.lib.macro.declaration.AnnotationReference)5 MutableEnumerationTypeDeclaration (org.eclipse.xtend.lib.macro.declaration.MutableEnumerationTypeDeclaration)5 List (java.util.List)4 TypeReference (org.eclipse.xtend.lib.macro.declaration.TypeReference)4 MutableInterfaceDeclaration (org.eclipse.xtend.lib.macro.declaration.MutableInterfaceDeclaration)3 StringConcatenationClient (org.eclipse.xtend2.lib.StringConcatenationClient)3 Serializable (java.io.Serializable)2 Consumer (java.util.function.Consumer)2 EObject (org.eclipse.emf.ecore.EObject)2 XtendCompilerTester (org.eclipse.xtend.core.compiler.batch.XtendCompilerTester)2 AbstractActiveAnnotationTest (org.eclipse.xtend.core.tests.macro.AbstractActiveAnnotationTest)2 TransformationContext (org.eclipse.xtend.lib.macro.TransformationContext)2