Search in sources :

Example 1 with JvmUpperBound

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

the class JdtBasedTypeFactory method createTypeParameter.

protected JvmTypeParameter createTypeParameter(ITypeBinding parameter, JvmMember container) {
    resolveTypeParams.start();
    JvmTypeParameter result = TypesFactory.eINSTANCE.createJvmTypeParameter();
    result.setName(parameter.getName());
    InternalEList<JvmTypeConstraint> constraints = (InternalEList<JvmTypeConstraint>) result.getConstraints();
    ITypeBinding[] typeBounds = parameter.getTypeBounds();
    if (typeBounds.length != 0) {
        for (ITypeBinding bound : typeBounds) {
            JvmUpperBound upperBound = TypesFactory.eINSTANCE.createJvmUpperBound();
            upperBound.setTypeReference(createTypeReference(bound));
            constraints.addUnique(upperBound);
        }
    } else {
        JvmUpperBound upperBound = TypesFactory.eINSTANCE.createJvmUpperBound();
        upperBound.setTypeReference(createObjectClassReference());
        constraints.addUnique(upperBound);
    }
    resolveTypeParams.stop();
    return result;
}
Also used : JvmUpperBound(org.eclipse.xtext.common.types.JvmUpperBound) JvmTypeParameter(org.eclipse.xtext.common.types.JvmTypeParameter) ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding) InternalEList(org.eclipse.emf.ecore.util.InternalEList) JvmTypeConstraint(org.eclipse.xtext.common.types.JvmTypeConstraint)

Example 2 with JvmUpperBound

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

the class JdtBasedTypeFactory method createTypeArgument.

protected JvmTypeReference createTypeArgument(ITypeBinding argument) {
    if (argument.isWildcardType()) {
        JvmWildcardTypeReference result = TypesFactory.eINSTANCE.createJvmWildcardTypeReference();
        InternalEList<JvmTypeConstraint> constraints = (InternalEList<JvmTypeConstraint>) result.getConstraints();
        JvmUpperBound upperBound = TypesFactory.eINSTANCE.createJvmUpperBound();
        ITypeBinding bound = argument.getBound();
        if (argument.isUpperbound()) {
            JvmTypeReference reference = createTypeReference(bound);
            upperBound.setTypeReference(reference);
            constraints.addUnique(upperBound);
        } else {
            JvmTypeReference objectReference = createObjectClassReference();
            upperBound.setTypeReference(objectReference);
            constraints.addUnique(upperBound);
            if (bound != null) {
                JvmLowerBound lowerBound = TypesFactory.eINSTANCE.createJvmLowerBound();
                JvmTypeReference reference = createTypeReference(bound);
                lowerBound.setTypeReference(reference);
                constraints.addUnique(lowerBound);
            }
        }
        return result;
    } else {
        return createTypeReference(argument);
    }
}
Also used : JvmUpperBound(org.eclipse.xtext.common.types.JvmUpperBound) JvmWildcardTypeReference(org.eclipse.xtext.common.types.JvmWildcardTypeReference) JvmLowerBound(org.eclipse.xtext.common.types.JvmLowerBound) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding) InternalEList(org.eclipse.emf.ecore.util.InternalEList) JvmTypeConstraint(org.eclipse.xtext.common.types.JvmTypeConstraint)

Example 3 with JvmUpperBound

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

the class AbstractTypeProviderTest method testFindTypeByName_javaUtilList_01.

@Test
public void testFindTypeByName_javaUtilList_01() {
    String typeName = List.class.getName();
    JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName);
    assertNotNull(type);
    assertEquals(typeName, type.getIdentifier());
    assertEquals(1, type.getTypeParameters().size());
    JvmTypeParameter typeVariable = type.getTypeParameters().get(0);
    assertEquals("E", typeVariable.getName());
    assertEquals(1, typeVariable.getConstraints().size());
    JvmTypeConstraint typeConstraint = typeVariable.getConstraints().get(0);
    assertTrue(typeConstraint instanceof JvmUpperBound);
    JvmUpperBound upperBound = (JvmUpperBound) typeConstraint;
    assertSame(typeVariable, upperBound.getOwner());
    assertNotNull(upperBound.getTypeReference());
    assertFalse(upperBound.getTypeReference().getType().eIsProxy());
    assertEquals(Object.class.getName(), upperBound.getTypeReference().getIdentifier());
    diagnose(type);
    Resource resource = type.eResource();
    getAndResolveAllFragments(resource);
    recomputeAndCheckIdentifiers(resource);
}
Also used : JvmUpperBound(org.eclipse.xtext.common.types.JvmUpperBound) JvmTypeParameter(org.eclipse.xtext.common.types.JvmTypeParameter) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) Resource(org.eclipse.emf.ecore.resource.Resource) JvmTypeConstraint(org.eclipse.xtext.common.types.JvmTypeConstraint) EObject(org.eclipse.emf.ecore.EObject) Test(org.junit.Test)

Example 4 with JvmUpperBound

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

the class AbstractTypeProviderTest method test_ParameterizedTypes_W_01.

@Test
public void test_ParameterizedTypes_W_01() {
    String typeName = ParameterizedTypes.class.getName();
    JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName);
    JvmTypeParameter typeParameterW = type.getTypeParameters().get(4);
    assertEquals("W", typeParameterW.getIdentifier());
    assertSame(type, typeParameterW.getDeclarator());
    assertEquals(2, typeParameterW.getConstraints().size());
    JvmTypeConstraint firstTypeConstraint = typeParameterW.getConstraints().get(0);
    assertTrue(firstTypeConstraint instanceof JvmUpperBound);
    JvmUpperBound firstUpperBound = (JvmUpperBound) firstTypeConstraint;
    assertNotNull(firstUpperBound.getTypeReference());
    assertFalse(firstUpperBound.getTypeReference().toString(), firstUpperBound.getTypeReference().eIsProxy());
    assertEquals("java.lang.Comparable<S>", firstUpperBound.getTypeReference().getIdentifier());
    JvmParameterizedTypeReference comparableType = (JvmParameterizedTypeReference) firstUpperBound.getTypeReference();
    assertEquals(1, comparableType.getArguments().size());
    JvmTypeReference typeArgument = comparableType.getArguments().get(0);
    assertEquals("S", typeArgument.getIdentifier());
    JvmTypeParameter s = type.getTypeParameters().get(0);
    assertSame(s, typeArgument.getType());
}
Also used : JvmUpperBound(org.eclipse.xtext.common.types.JvmUpperBound) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) JvmTypeParameter(org.eclipse.xtext.common.types.JvmTypeParameter) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) JvmTypeConstraint(org.eclipse.xtext.common.types.JvmTypeConstraint) JvmParameterizedTypeReference(org.eclipse.xtext.common.types.JvmParameterizedTypeReference) Test(org.junit.Test)

Example 5 with JvmUpperBound

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

the class AbstractTypeProviderTest method test_ParameterizedTypes_S_01.

@Test
public void test_ParameterizedTypes_S_01() {
    String typeName = ParameterizedTypes.class.getName();
    JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName);
    JvmTypeParameter typeVariable = type.getTypeParameters().get(0);
    assertEquals("S", typeVariable.getIdentifier());
    assertSame(type, typeVariable.getDeclarator());
    assertEquals(1, typeVariable.getConstraints().size());
    JvmTypeConstraint typeConstraint = typeVariable.getConstraints().get(0);
    assertTrue(typeConstraint instanceof JvmUpperBound);
    JvmUpperBound upperBound = (JvmUpperBound) typeConstraint;
    assertNotNull(upperBound.getTypeReference());
    assertEquals("java.lang.Object", upperBound.getTypeReference().getIdentifier());
}
Also used : JvmUpperBound(org.eclipse.xtext.common.types.JvmUpperBound) JvmTypeParameter(org.eclipse.xtext.common.types.JvmTypeParameter) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) JvmTypeConstraint(org.eclipse.xtext.common.types.JvmTypeConstraint) Test(org.junit.Test)

Aggregations

JvmUpperBound (org.eclipse.xtext.common.types.JvmUpperBound)34 JvmTypeParameter (org.eclipse.xtext.common.types.JvmTypeParameter)29 Test (org.junit.Test)21 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)18 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)17 JvmTypeConstraint (org.eclipse.xtext.common.types.JvmTypeConstraint)17 JvmParameterizedTypeReference (org.eclipse.xtext.common.types.JvmParameterizedTypeReference)16 JvmWildcardTypeReference (org.eclipse.xtext.common.types.JvmWildcardTypeReference)11 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)7 JvmLowerBound (org.eclipse.xtext.common.types.JvmLowerBound)6 JvmType (org.eclipse.xtext.common.types.JvmType)6 ParameterizedTypes (org.eclipse.xtext.common.types.testSetups.ParameterizedTypes)5 EPackage (org.eclipse.emf.ecore.EPackage)3 MutableTypeParameterDeclaration (org.eclipse.xtend.lib.macro.declaration.MutableTypeParameterDeclaration)3 TypeParameterDeclaration (org.eclipse.xtend.lib.macro.declaration.TypeParameterDeclaration)3 TypeReference (org.eclipse.xtend.lib.macro.declaration.TypeReference)3 Action (org.eclipse.xtext.Action)3 Parameter (org.eclipse.xtext.Parameter)3 JvmFormalParameter (org.eclipse.xtext.common.types.JvmFormalParameter)3 InternalEList (org.eclipse.emf.ecore.util.InternalEList)2