Search in sources :

Example 66 with JvmGenericType

use of org.eclipse.xtext.common.types.JvmGenericType in project xtext-eclipse by eclipse.

the class AbstractTypeProviderTest method test_ParameterizedTypes_Inner_06.

@Test
public void test_ParameterizedTypes_Inner_06() {
    String typeName = ParameterizedTypes.class.getName();
    JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName);
    JvmOperation methodV = getMethodFromType(type, ParameterizedTypes.Inner.class, "methodVArray_02()");
    JvmTypeReference listV = methodV.getReturnType();
    assertEquals("java.util.List<? extends V[]>", listV.getIdentifier());
    JvmParameterizedTypeReference listType = (JvmParameterizedTypeReference) listV;
    assertEquals(1, listType.getArguments().size());
    JvmTypeReference typeArgument = listType.getArguments().get(0);
    assertTrue(typeArgument instanceof JvmWildcardTypeReference);
    JvmWildcardTypeReference wildcardTypeArgument = (JvmWildcardTypeReference) typeArgument;
    assertEquals("? extends V[]", wildcardTypeArgument.getIdentifier());
    assertEquals(1, wildcardTypeArgument.getConstraints().size());
    JvmUpperBound upperBound = (JvmUpperBound) wildcardTypeArgument.getConstraints().get(0);
    JvmType upperBoundType = upperBound.getTypeReference().getType();
    assertTrue(upperBoundType instanceof JvmArrayType);
    assertTrue(((JvmArrayType) upperBoundType).getComponentType() instanceof JvmTypeParameter);
    JvmTypeParameter v = type.getTypeParameters().get(3);
    assertSame(v, ((JvmArrayType) upperBoundType).getComponentType());
}
Also used : JvmOperation(org.eclipse.xtext.common.types.JvmOperation) JvmUpperBound(org.eclipse.xtext.common.types.JvmUpperBound) JvmWildcardTypeReference(org.eclipse.xtext.common.types.JvmWildcardTypeReference) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) JvmTypeParameter(org.eclipse.xtext.common.types.JvmTypeParameter) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) JvmType(org.eclipse.xtext.common.types.JvmType) JvmParameterizedTypeReference(org.eclipse.xtext.common.types.JvmParameterizedTypeReference) ParameterizedTypes(org.eclipse.xtext.common.types.testSetups.ParameterizedTypes) JvmArrayType(org.eclipse.xtext.common.types.JvmArrayType) Test(org.junit.Test)

Example 67 with JvmGenericType

use of org.eclipse.xtext.common.types.JvmGenericType in project xtext-eclipse by eclipse.

the class AbstractTypeProviderTest method testFindTypeByName_AbstractMultimap.

@Test
public void testFindTypeByName_AbstractMultimap() {
    String typeName = "com.google.common.collect.AbstractMultimap";
    JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName);
    assertNotNull(type);
    diagnose(type, "java:/Objects/javax.annotation.Nullable#javax.annotation.Nullable");
    Resource resource = type.eResource();
    getAndResolveAllFragments(resource);
    recomputeAndCheckIdentifiers(resource);
}
Also used : JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) Resource(org.eclipse.emf.ecore.resource.Resource) Test(org.junit.Test)

Example 68 with JvmGenericType

use of org.eclipse.xtext.common.types.JvmGenericType in project xtext-eclipse by eclipse.

the class JdtTypeProviderTest method testFindTypeByName_$StartsWithDollar_02.

// tests for the presence of the bug above
@Override
@Test
public void testFindTypeByName_$StartsWithDollar_02() {
    String typeName = "org.eclipse.xtext.common.types.testSetups.$StartsWithDollar";
    JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName);
    assertNull(type);
}
Also used : JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) Test(org.junit.Test)

Example 69 with JvmGenericType

use of org.eclipse.xtext.common.types.JvmGenericType in project xtext-eclipse by eclipse.

the class DomainmodelJvmModelInferrer method _infer.

protected void _infer(final Entity entity, @Extension final IJvmDeclaredTypeAcceptor acceptor, final boolean prelinkingPhase) {
    final Procedure1<JvmGenericType> _function = (JvmGenericType it) -> {
        this._jvmTypesBuilder.setDocumentation(it, this._jvmTypesBuilder.getDocumentation(entity));
        JvmParameterizedTypeReference _superType = entity.getSuperType();
        boolean _tripleNotEquals = (_superType != null);
        if (_tripleNotEquals) {
            EList<JvmTypeReference> _superTypes = it.getSuperTypes();
            JvmTypeReference _cloneWithProxies = this._jvmTypesBuilder.cloneWithProxies(entity.getSuperType());
            this._jvmTypesBuilder.<JvmTypeReference>operator_add(_superTypes, _cloneWithProxies);
        }
        EList<JvmMember> _members = it.getMembers();
        final Procedure1<JvmConstructor> _function_1 = (JvmConstructor it_1) -> {
        };
        JvmConstructor _constructor = this._jvmTypesBuilder.toConstructor(entity, _function_1);
        this._jvmTypesBuilder.<JvmConstructor>operator_add(_members, _constructor);
        final JvmTypeReference procedureType = this._typeReferenceBuilder.typeRef(Procedure1.class, this._typeReferenceBuilder.typeRef(it));
        EList<JvmMember> _members_1 = it.getMembers();
        final Procedure1<JvmConstructor> _function_2 = (JvmConstructor it_1) -> {
            EList<JvmFormalParameter> _parameters = it_1.getParameters();
            JvmFormalParameter _parameter = this._jvmTypesBuilder.toParameter(entity, "initializer", procedureType);
            this._jvmTypesBuilder.<JvmFormalParameter>operator_add(_parameters, _parameter);
            StringConcatenationClient _client = new StringConcatenationClient() {

                @Override
                protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
                    _builder.append("initializer.apply(this);");
                    _builder.newLine();
                }
            };
            this._jvmTypesBuilder.setBody(it_1, _client);
        };
        JvmConstructor _constructor_1 = this._jvmTypesBuilder.toConstructor(entity, _function_2);
        this._jvmTypesBuilder.<JvmConstructor>operator_add(_members_1, _constructor_1);
        EList<Feature> _features = entity.getFeatures();
        for (final Feature f : _features) {
            boolean _matched = false;
            if (f instanceof Property) {
                _matched = true;
                final JvmField field = this._jvmTypesBuilder.toField(f, ((Property) f).getName(), ((Property) f).getType());
                EList<JvmMember> _members_2 = it.getMembers();
                this._jvmTypesBuilder.<JvmField>operator_add(_members_2, field);
                EList<JvmMember> _members_3 = it.getMembers();
                JvmOperation _getter = this._jvmTypesBuilder.toGetter(f, ((Property) f).getName(), ((Property) f).getType());
                this._jvmTypesBuilder.<JvmOperation>operator_add(_members_3, _getter);
                EList<JvmMember> _members_4 = it.getMembers();
                JvmOperation _setter = this._jvmTypesBuilder.toSetter(f, ((Property) f).getName(), ((Property) f).getType());
                this._jvmTypesBuilder.<JvmOperation>operator_add(_members_4, _setter);
            }
            if (!_matched) {
                if (f instanceof Operation) {
                    _matched = true;
                    EList<JvmMember> _members_2 = it.getMembers();
                    String _name = ((Operation) f).getName();
                    JvmTypeReference _elvis = null;
                    JvmTypeReference _type = ((Operation) f).getType();
                    if (_type != null) {
                        _elvis = _type;
                    } else {
                        JvmTypeReference _inferredType = this._jvmTypesBuilder.inferredType();
                        _elvis = _inferredType;
                    }
                    final Procedure1<JvmOperation> _function_3 = (JvmOperation it_1) -> {
                        this._jvmTypesBuilder.setDocumentation(it_1, this._jvmTypesBuilder.getDocumentation(f));
                        EList<JvmFormalParameter> _params = ((Operation) f).getParams();
                        for (final JvmFormalParameter p : _params) {
                            EList<JvmFormalParameter> _parameters = it_1.getParameters();
                            JvmFormalParameter _parameter = this._jvmTypesBuilder.toParameter(p, p.getName(), p.getParameterType());
                            this._jvmTypesBuilder.<JvmFormalParameter>operator_add(_parameters, _parameter);
                        }
                        this._jvmTypesBuilder.setBody(it_1, ((Operation) f).getBody());
                    };
                    JvmOperation _method = this._jvmTypesBuilder.toMethod(f, _name, _elvis, _function_3);
                    this._jvmTypesBuilder.<JvmOperation>operator_add(_members_2, _method);
                }
            }
        }
        EList<JvmMember> _members_2 = it.getMembers();
        JvmOperation _toStringMethod = this._jvmTypesBuilder.toToStringMethod(entity, it);
        this._jvmTypesBuilder.<JvmOperation>operator_add(_members_2, _toStringMethod);
    };
    acceptor.<JvmGenericType>accept(this._jvmTypesBuilder.toClass(entity, this._iQualifiedNameProvider.getFullyQualifiedName(entity)), _function);
}
Also used : StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) Operation(org.eclipse.xtext.example.domainmodel.domainmodel.Operation) Feature(org.eclipse.xtext.example.domainmodel.domainmodel.Feature) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) EList(org.eclipse.emf.common.util.EList) JvmFormalParameter(org.eclipse.xtext.common.types.JvmFormalParameter) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) JvmConstructor(org.eclipse.xtext.common.types.JvmConstructor) JvmField(org.eclipse.xtext.common.types.JvmField) JvmParameterizedTypeReference(org.eclipse.xtext.common.types.JvmParameterizedTypeReference) Property(org.eclipse.xtext.example.domainmodel.domainmodel.Property)

Example 70 with JvmGenericType

use of org.eclipse.xtext.common.types.JvmGenericType in project xtext-xtend by eclipse.

the class CompilationUnitImpl method toTypeDeclaration.

public TypeDeclaration toTypeDeclaration(final JvmDeclaredType delegate) {
    final Function1<JvmDeclaredType, TypeDeclaration> _function = (JvmDeclaredType it) -> {
        JvmTypeDeclarationImpl<? extends JvmDeclaredType> _switchResult = null;
        boolean _matched = false;
        if (delegate instanceof JvmGenericType) {
            boolean _isInterface = ((JvmGenericType) delegate).isInterface();
            if (_isInterface) {
                _matched = true;
                JvmInterfaceDeclarationImpl _xifexpression = null;
                boolean _isBelongedToCompilationUnit = this.isBelongedToCompilationUnit(delegate);
                if (_isBelongedToCompilationUnit) {
                    MutableJvmInterfaceDeclarationImpl _mutableJvmInterfaceDeclarationImpl = new MutableJvmInterfaceDeclarationImpl();
                    final Procedure1<MutableJvmInterfaceDeclarationImpl> _function_1 = (MutableJvmInterfaceDeclarationImpl it_1) -> {
                        it_1.setDelegate(((JvmGenericType) delegate));
                        it_1.setCompilationUnit(this);
                    };
                    _xifexpression = ObjectExtensions.<MutableJvmInterfaceDeclarationImpl>operator_doubleArrow(_mutableJvmInterfaceDeclarationImpl, _function_1);
                } else {
                    JvmInterfaceDeclarationImpl _jvmInterfaceDeclarationImpl = new JvmInterfaceDeclarationImpl();
                    final Procedure1<JvmInterfaceDeclarationImpl> _function_2 = (JvmInterfaceDeclarationImpl it_1) -> {
                        it_1.setDelegate(((JvmGenericType) delegate));
                        it_1.setCompilationUnit(this);
                    };
                    _xifexpression = ObjectExtensions.<JvmInterfaceDeclarationImpl>operator_doubleArrow(_jvmInterfaceDeclarationImpl, _function_2);
                }
                _switchResult = _xifexpression;
            }
        }
        if (!_matched) {
            if (delegate instanceof JvmGenericType) {
                _matched = true;
                JvmClassDeclarationImpl _xifexpression = null;
                boolean _isBelongedToCompilationUnit = this.isBelongedToCompilationUnit(delegate);
                if (_isBelongedToCompilationUnit) {
                    MutableJvmClassDeclarationImpl _mutableJvmClassDeclarationImpl = new MutableJvmClassDeclarationImpl();
                    final Procedure1<MutableJvmClassDeclarationImpl> _function_1 = (MutableJvmClassDeclarationImpl it_1) -> {
                        it_1.setDelegate(((JvmGenericType) delegate));
                        it_1.setCompilationUnit(this);
                    };
                    _xifexpression = ObjectExtensions.<MutableJvmClassDeclarationImpl>operator_doubleArrow(_mutableJvmClassDeclarationImpl, _function_1);
                } else {
                    JvmClassDeclarationImpl _jvmClassDeclarationImpl = new JvmClassDeclarationImpl();
                    final Procedure1<JvmClassDeclarationImpl> _function_2 = (JvmClassDeclarationImpl it_1) -> {
                        it_1.setDelegate(((JvmGenericType) delegate));
                        it_1.setCompilationUnit(this);
                    };
                    _xifexpression = ObjectExtensions.<JvmClassDeclarationImpl>operator_doubleArrow(_jvmClassDeclarationImpl, _function_2);
                }
                _switchResult = _xifexpression;
            }
        }
        if (!_matched) {
            if (delegate instanceof JvmAnnotationType) {
                _matched = true;
                JvmAnnotationTypeDeclarationImpl _xifexpression = null;
                boolean _isBelongedToCompilationUnit = this.isBelongedToCompilationUnit(delegate);
                if (_isBelongedToCompilationUnit) {
                    MutableJvmAnnotationTypeDeclarationImpl _mutableJvmAnnotationTypeDeclarationImpl = new MutableJvmAnnotationTypeDeclarationImpl();
                    final Procedure1<MutableJvmAnnotationTypeDeclarationImpl> _function_1 = (MutableJvmAnnotationTypeDeclarationImpl it_1) -> {
                        it_1.setDelegate(((JvmAnnotationType) delegate));
                        it_1.setCompilationUnit(this);
                    };
                    _xifexpression = ObjectExtensions.<MutableJvmAnnotationTypeDeclarationImpl>operator_doubleArrow(_mutableJvmAnnotationTypeDeclarationImpl, _function_1);
                } else {
                    JvmAnnotationTypeDeclarationImpl _jvmAnnotationTypeDeclarationImpl = new JvmAnnotationTypeDeclarationImpl();
                    final Procedure1<JvmAnnotationTypeDeclarationImpl> _function_2 = (JvmAnnotationTypeDeclarationImpl it_1) -> {
                        it_1.setDelegate(((JvmAnnotationType) delegate));
                        it_1.setCompilationUnit(this);
                    };
                    _xifexpression = ObjectExtensions.<JvmAnnotationTypeDeclarationImpl>operator_doubleArrow(_jvmAnnotationTypeDeclarationImpl, _function_2);
                }
                _switchResult = _xifexpression;
            }
        }
        if (!_matched) {
            if (delegate instanceof JvmEnumerationType) {
                _matched = true;
                JvmEnumerationTypeDeclarationImpl _xifexpression = null;
                boolean _isBelongedToCompilationUnit = this.isBelongedToCompilationUnit(delegate);
                if (_isBelongedToCompilationUnit) {
                    MutableJvmEnumerationTypeDeclarationImpl _mutableJvmEnumerationTypeDeclarationImpl = new MutableJvmEnumerationTypeDeclarationImpl();
                    final Procedure1<MutableJvmEnumerationTypeDeclarationImpl> _function_1 = (MutableJvmEnumerationTypeDeclarationImpl it_1) -> {
                        it_1.setDelegate(((JvmEnumerationType) delegate));
                        it_1.setCompilationUnit(this);
                    };
                    _xifexpression = ObjectExtensions.<MutableJvmEnumerationTypeDeclarationImpl>operator_doubleArrow(_mutableJvmEnumerationTypeDeclarationImpl, _function_1);
                } else {
                    JvmEnumerationTypeDeclarationImpl _jvmEnumerationTypeDeclarationImpl = new JvmEnumerationTypeDeclarationImpl();
                    final Procedure1<JvmEnumerationTypeDeclarationImpl> _function_2 = (JvmEnumerationTypeDeclarationImpl it_1) -> {
                        it_1.setDelegate(((JvmEnumerationType) delegate));
                        it_1.setCompilationUnit(this);
                    };
                    _xifexpression = ObjectExtensions.<JvmEnumerationTypeDeclarationImpl>operator_doubleArrow(_jvmEnumerationTypeDeclarationImpl, _function_2);
                }
                _switchResult = _xifexpression;
            }
        }
        return ((TypeDeclaration) _switchResult);
    };
    return this.<JvmDeclaredType, TypeDeclaration>getOrCreate(delegate, _function);
}
Also used : JvmAnnotationType(org.eclipse.xtext.common.types.JvmAnnotationType) JvmAnnotationTypeDeclarationImpl(org.eclipse.xtend.core.macro.declaration.JvmAnnotationTypeDeclarationImpl) MutableJvmAnnotationTypeDeclarationImpl(org.eclipse.xtend.core.macro.declaration.MutableJvmAnnotationTypeDeclarationImpl) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) MutableJvmInterfaceDeclarationImpl(org.eclipse.xtend.core.macro.declaration.MutableJvmInterfaceDeclarationImpl) MutableJvmAnnotationTypeDeclarationImpl(org.eclipse.xtend.core.macro.declaration.MutableJvmAnnotationTypeDeclarationImpl) JvmTypeDeclarationImpl(org.eclipse.xtend.core.macro.declaration.JvmTypeDeclarationImpl) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) JvmClassDeclarationImpl(org.eclipse.xtend.core.macro.declaration.JvmClassDeclarationImpl) MutableJvmClassDeclarationImpl(org.eclipse.xtend.core.macro.declaration.MutableJvmClassDeclarationImpl) MutableJvmInterfaceDeclarationImpl(org.eclipse.xtend.core.macro.declaration.MutableJvmInterfaceDeclarationImpl) JvmInterfaceDeclarationImpl(org.eclipse.xtend.core.macro.declaration.JvmInterfaceDeclarationImpl) MutableJvmClassDeclarationImpl(org.eclipse.xtend.core.macro.declaration.MutableJvmClassDeclarationImpl) JvmEnumerationType(org.eclipse.xtext.common.types.JvmEnumerationType) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) TypeDeclaration(org.eclipse.xtend.lib.macro.declaration.TypeDeclaration) MutableJvmEnumerationTypeDeclarationImpl(org.eclipse.xtend.core.macro.declaration.MutableJvmEnumerationTypeDeclarationImpl) MutableJvmEnumerationTypeDeclarationImpl(org.eclipse.xtend.core.macro.declaration.MutableJvmEnumerationTypeDeclarationImpl) JvmEnumerationTypeDeclarationImpl(org.eclipse.xtend.core.macro.declaration.JvmEnumerationTypeDeclarationImpl)

Aggregations

JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)297 Test (org.junit.Test)237 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)117 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)64 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)56 JvmType (org.eclipse.xtext.common.types.JvmType)49 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)47 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)33 JvmConstructor (org.eclipse.xtext.common.types.JvmConstructor)33 JvmTypeParameter (org.eclipse.xtext.common.types.JvmTypeParameter)33 JvmField (org.eclipse.xtext.common.types.JvmField)31 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)30 EObject (org.eclipse.emf.ecore.EObject)28 Resource (org.eclipse.emf.ecore.resource.Resource)28 JvmMember (org.eclipse.xtext.common.types.JvmMember)25 JvmParameterizedTypeReference (org.eclipse.xtext.common.types.JvmParameterizedTypeReference)24 JvmTypeConstraint (org.eclipse.xtext.common.types.JvmTypeConstraint)21 JvmUpperBound (org.eclipse.xtext.common.types.JvmUpperBound)17 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)15 JvmFormalParameter (org.eclipse.xtext.common.types.JvmFormalParameter)15