Search in sources :

Example 26 with JvmUpperBound

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

the class AbstractTypeProviderTest method test_ParameterizedTypes_04.

@Test
public void test_ParameterizedTypes_04() {
    String typeName = ParameterizedTypes.class.getName();
    JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName);
    JvmOperation methodY = getMethodFromType(type, ParameterizedTypes.class, "methodY(Y)");
    assertEquals(1, methodY.getParameters().size());
    JvmType parameterType = methodY.getParameters().get(0).getParameterType().getType();
    assertFalse(parameterType.eIsProxy());
    assertEquals("Y", parameterType.getIdentifier());
    assertTrue(parameterType instanceof JvmTypeParameter);
    assertSame(methodY, ((JvmTypeParameter) parameterType).getDeclarator());
    JvmTypeParameter y = (JvmTypeParameter) parameterType;
    assertEquals(1, y.getConstraints().size());
    JvmUpperBound upperBound = (JvmUpperBound) y.getConstraints().get(0);
    JvmTypeParameter t = type.getTypeParameters().get(1);
    assertSame(t, upperBound.getTypeReference().getType());
}
Also used : JvmOperation(org.eclipse.xtext.common.types.JvmOperation) JvmUpperBound(org.eclipse.xtext.common.types.JvmUpperBound) JvmTypeParameter(org.eclipse.xtext.common.types.JvmTypeParameter) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) JvmType(org.eclipse.xtext.common.types.JvmType) Test(org.junit.Test)

Example 27 with JvmUpperBound

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

the class AbstractTypeProviderTest method test_ParameterizedTypes_03.

@Test
public void test_ParameterizedTypes_03() {
    String typeName = ParameterizedTypes.class.getName();
    JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName);
    JvmOperation methodT = getMethodFromType(type, ParameterizedTypes.class, "methodT(T)");
    JvmTypeReference listS = methodT.getReturnType();
    assertFalse(listS.toString(), listS.eIsProxy());
    assertEquals("java.util.List<? extends java.lang.Object & super T>", listS.getIdentifier());
    JvmParameterizedTypeReference listType = (JvmParameterizedTypeReference) listS;
    assertEquals(1, listType.getArguments().size());
    JvmTypeReference typeArgument = listType.getArguments().get(0);
    assertTrue(typeArgument instanceof JvmWildcardTypeReference);
    JvmWildcardTypeReference wildcardTypeArgument = (JvmWildcardTypeReference) typeArgument;
    assertEquals("? extends java.lang.Object & super T", wildcardTypeArgument.getIdentifier());
    assertEquals(2, wildcardTypeArgument.getConstraints().size());
    JvmUpperBound uperBound = (JvmUpperBound) wildcardTypeArgument.getConstraints().get(0);
    assertEquals("java.lang.Object", uperBound.getTypeReference().getIdentifier());
    JvmLowerBound lowerBound = (JvmLowerBound) wildcardTypeArgument.getConstraints().get(1);
    JvmTypeParameter t = type.getTypeParameters().get(1);
    assertSame(t, lowerBound.getTypeReference().getType());
}
Also used : JvmOperation(org.eclipse.xtext.common.types.JvmOperation) 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) JvmTypeParameter(org.eclipse.xtext.common.types.JvmTypeParameter) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) JvmParameterizedTypeReference(org.eclipse.xtext.common.types.JvmParameterizedTypeReference) Test(org.junit.Test)

Example 28 with JvmUpperBound

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

the class AbstractTypeProviderTest method test_twoListWildcardsListResult_03.

@Test
public void test_twoListWildcardsListResult_03() {
    JvmOperation twoListWildcardsListResult = getMethodFromParameterizedMethods("twoListWildcardsListResult(java.util.List,java.util.List)");
    JvmTypeReference returnType = twoListWildcardsListResult.getReturnType();
    JvmParameterizedTypeReference parameterized = (JvmParameterizedTypeReference) returnType;
    assertEquals(1, parameterized.getArguments().size());
    JvmTypeReference typeParameter = parameterized.getArguments().get(0);
    assertTrue(typeParameter instanceof JvmWildcardTypeReference);
    JvmWildcardTypeReference wildcard = (JvmWildcardTypeReference) typeParameter;
    assertEquals(1, wildcard.getConstraints().size());
    assertTrue(wildcard.getConstraints().get(0) instanceof JvmUpperBound);
    JvmUpperBound upperBound = (JvmUpperBound) wildcard.getConstraints().get(0);
    assertNotNull(upperBound.getTypeReference());
    JvmType upperBoundType = upperBound.getTypeReference().getType();
    assertFalse(upperBoundType.eIsProxy());
    assertEquals("java.lang.Object", upperBoundType.getIdentifier());
}
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) JvmType(org.eclipse.xtext.common.types.JvmType) JvmParameterizedTypeReference(org.eclipse.xtext.common.types.JvmParameterizedTypeReference) Test(org.junit.Test)

Example 29 with JvmUpperBound

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

the class AbstractTypeProviderTest method test_ParameterizedTypes_Inner_05.

@Test
public void test_ParameterizedTypes_Inner_05() {
    String typeName = ParameterizedTypes.class.getName();
    JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName);
    JvmOperation methodV = getMethodFromType(type, ParameterizedTypes.Inner.class, "methodVArray_01()");
    JvmTypeReference listT = methodV.getReturnType();
    assertEquals("java.util.List<? extends V>[]", listT.getIdentifier());
    JvmParameterizedTypeReference listType = (JvmParameterizedTypeReference) ((JvmGenericArrayTypeReference) listT).getComponentType();
    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);
    JvmTypeParameter v = type.getTypeParameters().get(3);
    assertSame(v, upperBound.getTypeReference().getType());
}
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) JvmParameterizedTypeReference(org.eclipse.xtext.common.types.JvmParameterizedTypeReference) ParameterizedTypes(org.eclipse.xtext.common.types.testSetups.ParameterizedTypes) Test(org.junit.Test)

Example 30 with JvmUpperBound

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

the class AbstractTypeProviderTest method test_ParameterizedTypes_T_01.

@Test
public void test_ParameterizedTypes_T_01() {
    String typeName = ParameterizedTypes.class.getName();
    JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName);
    JvmTypeParameter typeVariable = type.getTypeParameters().get(1);
    assertEquals("T", 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("S", upperBound.getTypeReference().getIdentifier());
    JvmTypeParameter s = type.getTypeParameters().get(0);
    assertSame(s, upperBound.getTypeReference().getType());
}
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