Search in sources :

Example 6 with JvmUpperBound

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

the class AbstractTypeProviderTest method test_ParameterizedTypes_W_02.

@Test
public void test_ParameterizedTypes_W_02() {
    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 secondTypeConstraint = typeParameterW.getConstraints().get(1);
    assertTrue(secondTypeConstraint instanceof JvmUpperBound);
    JvmUpperBound secondUpperBound = (JvmUpperBound) secondTypeConstraint;
    assertNotNull(secondUpperBound.getTypeReference());
    assertFalse(secondUpperBound.getTypeReference().toString(), secondUpperBound.getTypeReference().eIsProxy());
    assertEquals("java.io.Serializable", secondUpperBound.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)

Example 7 with JvmUpperBound

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

the class AbstractTypeProviderTest method test_ParameterizedTypes_U_01.

@Test
public void test_ParameterizedTypes_U_01() {
    String typeName = ParameterizedTypes.class.getName();
    JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName);
    JvmTypeParameter typeVariable = type.getTypeParameters().get(2);
    assertEquals("U", 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());
    assertFalse(upperBound.getTypeReference().toString(), upperBound.getTypeReference().eIsProxy());
    assertEquals("java.util.List<S>", upperBound.getTypeReference().getIdentifier());
    JvmParameterizedTypeReference listType = (JvmParameterizedTypeReference) upperBound.getTypeReference();
    assertEquals(1, listType.getArguments().size());
    JvmTypeReference typeArgument = listType.getArguments().get(0);
    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 8 with JvmUpperBound

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

the class AbstractTypeProviderTest method test_ParameterizedTypes_Inner_Z_01.

@Test
public void test_ParameterizedTypes_Inner_Z_01() {
    String typeName = ParameterizedTypes.Inner.class.getName();
    JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName);
    JvmTypeParameter typeParameterZ = type.getTypeParameters().get(2);
    assertEquals("Z", typeParameterZ.getIdentifier());
    assertSame(type, typeParameterZ.getDeclarator());
    assertEquals(1, typeParameterZ.getConstraints().size());
    JvmTypeConstraint typeConstraint = typeParameterZ.getConstraints().get(0);
    assertTrue(typeConstraint instanceof JvmUpperBound);
    JvmUpperBound upperBound = (JvmUpperBound) typeConstraint;
    assertNotNull(upperBound.getTypeReference());
    assertEquals("java.util.List<W>", upperBound.getTypeReference().getIdentifier());
    JvmParameterizedTypeReference listType = (JvmParameterizedTypeReference) upperBound.getTypeReference();
    assertEquals(1, listType.getArguments().size());
    JvmTypeReference typeArgument = listType.getArguments().get(0);
    assertEquals("W", typeArgument.getIdentifier());
    JvmTypeParameter w = ((JvmTypeParameterDeclarator) type.getDeclaringType()).getTypeParameters().get(4);
    assertSame(w, 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) ParameterizedTypes(org.eclipse.xtext.common.types.testSetups.ParameterizedTypes) Test(org.junit.Test)

Example 9 with JvmUpperBound

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

the class AbstractTypeProviderTest method test_ParameterizedTypes_V_01.

@Test
public void test_ParameterizedTypes_V_01() {
    String typeName = ParameterizedTypes.class.getName();
    JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName);
    JvmTypeParameter typeParameterV = type.getTypeParameters().get(3);
    assertEquals("V", typeParameterV.getIdentifier());
    assertSame(type, typeParameterV.getDeclarator());
    assertEquals(1, typeParameterV.getConstraints().size());
    JvmTypeConstraint typeConstraint = typeParameterV.getConstraints().get(0);
    assertTrue(typeConstraint instanceof JvmUpperBound);
    JvmUpperBound upperBound = (JvmUpperBound) typeConstraint;
    assertNotNull(upperBound.getTypeReference());
    assertFalse(upperBound.getTypeReference().toString(), upperBound.getTypeReference().eIsProxy());
    assertEquals("java.util.List<java.util.List<? extends V>>", upperBound.getTypeReference().getIdentifier());
    JvmParameterizedTypeReference listType = (JvmParameterizedTypeReference) upperBound.getTypeReference();
    assertEquals(1, listType.getArguments().size());
    JvmTypeReference typeArgument = listType.getArguments().get(0);
    assertEquals("java.util.List<? extends V>", typeArgument.getIdentifier());
    JvmParameterizedTypeReference nestedListType = (JvmParameterizedTypeReference) typeArgument;
    assertEquals(1, nestedListType.getArguments().size());
    JvmTypeReference nestedArgument = nestedListType.getArguments().get(0);
    assertTrue(nestedArgument instanceof JvmWildcardTypeReference);
    assertEquals(1, ((JvmWildcardTypeReference) nestedArgument).getConstraints().size());
    JvmUpperBound nestedUpperBound = (JvmUpperBound) ((JvmWildcardTypeReference) nestedArgument).getConstraints().get(0);
    assertSame(typeParameterV, nestedUpperBound.getTypeReference().getType());
}
Also used : 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) JvmTypeConstraint(org.eclipse.xtext.common.types.JvmTypeConstraint) JvmParameterizedTypeReference(org.eclipse.xtext.common.types.JvmParameterizedTypeReference) Test(org.junit.Test)

Example 10 with JvmUpperBound

use of org.eclipse.xtext.common.types.JvmUpperBound 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)

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