org.eclipse.xtext.common.types.JvmWildcardTypeReference Java Examples
The following examples show how to use
org.eclipse.xtext.common.types.JvmWildcardTypeReference.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractTypeProviderTest.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
@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()); }
Example #2
Source File: AbstractTypeProviderTest.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@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()); }
Example #3
Source File: JvmTypeReferencesValidator.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@Check public void checkNotMultipleBounds(JvmWildcardTypeReference typeRef) { List<JvmTypeConstraint> constraints = typeRef.getConstraints(); if (constraints.size() >= 2) { int upperBounds = 0; int lowerBounds = 0; for(int i = 0; i < constraints.size(); i++) { JvmTypeConstraint constraint = constraints.get(i); if (constraint.eClass() == TypesPackage.Literals.JVM_UPPER_BOUND) { upperBounds++; if (upperBounds > 1) { error("Invalid type constraint. Cannot use multiple upper bounds in wildcards.", typeRef, TypesPackage.Literals.JVM_CONSTRAINT_OWNER__CONSTRAINTS, i, IssueCodes.INVALID_WILDCARD_CONSTRAINTS); return; } } else { lowerBounds++; if (lowerBounds > 1) { error("Invalid type constraint. Cannot use multiple lower bounds in wildcards.", typeRef, TypesPackage.Literals.JVM_CONSTRAINT_OWNER__CONSTRAINTS, i, IssueCodes.INVALID_WILDCARD_CONSTRAINTS); } } } } }
Example #4
Source File: AbstractTypeProviderTest.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
@Test public void test_twoListWildcardsNoResult_03() { JvmOperation twoListWildcardsNoResult = getMethodFromParameterizedMethods( "twoListWildcardsNoResult(java.util.List,java.util.List)"); JvmFormalParameter firstParam = twoListWildcardsNoResult.getParameters().get(0); JvmTypeReference paramType = firstParam.getParameterType(); JvmParameterizedTypeReference parameterized = (JvmParameterizedTypeReference) paramType; 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()); }
Example #5
Source File: NameConcatHelper.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
static String computeFor(JvmWildcardTypeReference typeReference, char innerClassDelimiter, NameType nameType) { if (typeReference.eIsSet(TypesPackage.Literals.JVM_CONSTRAINT_OWNER__CONSTRAINTS)) { if (typeReference.getConstraints().size() == 1) { JvmTypeConstraint onlyConstraint = typeReference.getConstraints().get(0); if (nameType != NameType.ID && nameType != NameType.TO_STRING) { JvmTypeReference reference = onlyConstraint.getTypeReference(); if (reference == null || (onlyConstraint instanceof JvmUpperBound && Object.class.getCanonicalName().equals(onlyConstraint.getTypeReference().getIdentifier()))) { return "?"; } } else if (nameType == NameType.ID && onlyConstraint.getTypeReference() == null) { return "?"; } } StringBuilder mutableResult = new StringBuilder(64); mutableResult.append("? "); appendConstraintsName(mutableResult, typeReference.getConstraints(), innerClassDelimiter, nameType); return mutableResult.toString(); } return "?"; }
Example #6
Source File: AbstractTypeProviderTest.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@Test public void test_ParameterizedTypes_06() { String typeName = ParameterizedTypes.class.getName(); JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName); JvmOperation methodMap = getMethodFromType(type, ParameterizedTypes.class, "methodMap(java.util.Map)"); assertEquals(1, methodMap.getParameters().size()); assertEquals(1, methodMap.getTypeParameters().size()); assertEquals("Z", methodMap.getTypeParameters().get(0).getIdentifier()); JvmType z = methodMap.getReturnType().getType(); assertSame(methodMap.getTypeParameters().get(0), z); JvmTypeReference mapType = methodMap.getParameters().get(0).getParameterType(); assertEquals("java.util.Map<? extends java.lang.Object & super Z, ? extends S>", mapType.getIdentifier()); JvmParameterizedTypeReference parameterizedMapType = (JvmParameterizedTypeReference) mapType; assertEquals(2, parameterizedMapType.getArguments().size()); JvmWildcardTypeReference extendsS = (JvmWildcardTypeReference) parameterizedMapType.getArguments().get(1); assertEquals(1, extendsS.getConstraints().size()); JvmType s = type.getTypeParameters().get(0); assertSame(s, extendsS.getConstraints().get(0).getTypeReference().getType()); }
Example #7
Source File: AbstractTypeProviderTest.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@Test public void test_ParameterizedTypes_05() { String typeName = ParameterizedTypes.class.getName(); JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName); JvmOperation methodZ = getMethodFromType(type, ParameterizedTypes.class, "methodZ(java.util.List)"); assertEquals(1, methodZ.getParameters().size()); assertEquals(1, methodZ.getTypeParameters().size()); assertEquals("Z", methodZ.getTypeParameters().get(0).getIdentifier()); JvmTypeReference listZ = methodZ.getReturnType(); assertFalse(listZ.toString(), listZ.getType().eIsProxy()); assertEquals("java.util.List<? extends java.lang.Object & super Z>", listZ.getIdentifier()); JvmParameterizedTypeReference listType = (JvmParameterizedTypeReference) listZ; 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 Z", wildcardTypeArgument.getIdentifier()); assertEquals(2, wildcardTypeArgument.getConstraints().size()); JvmUpperBound upperBound = (JvmUpperBound) wildcardTypeArgument.getConstraints().get(0); assertEquals("java.lang.Object", upperBound.getTypeReference().getIdentifier()); JvmLowerBound lowerBound = (JvmLowerBound) wildcardTypeArgument.getConstraints().get(1); assertEquals("Z", lowerBound.getTypeReference().getIdentifier()); JvmTypeParameter z = methodZ.getTypeParameters().get(0); assertSame(z, lowerBound.getTypeReference().getType()); }
Example #8
Source File: AbstractTypeProviderTest.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@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()); }
Example #9
Source File: AbstractTypeProviderTest.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@Test public void test_ParameterizedTypes_02() { String typeName = ParameterizedTypes.class.getName(); JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName); JvmOperation methodS = getMethodFromType(type, ParameterizedTypes.class, "methodS(S)"); JvmTypeReference listS = methodS.getReturnType(); assertFalse(listS.toString(), listS.eIsProxy()); assertEquals("java.util.List<? extends S>", 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 S", wildcardTypeArgument.getIdentifier()); assertEquals(1, wildcardTypeArgument.getConstraints().size()); JvmUpperBound upperBound = (JvmUpperBound) wildcardTypeArgument.getConstraints().get(0); JvmTypeParameter s = type.getTypeParameters().get(0); assertSame(s, upperBound.getTypeReference().getType()); }
Example #10
Source File: AbstractTypeProviderTest.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@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()); }
Example #11
Source File: AbstractTypeProviderTest.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@Test public void test_twoListWildcardsNoResult_03() { JvmOperation twoListWildcardsNoResult = getMethodFromParameterizedMethods( "twoListWildcardsNoResult(java.util.List,java.util.List)"); JvmFormalParameter firstParam = twoListWildcardsNoResult.getParameters().get(0); JvmTypeReference paramType = firstParam.getParameterType(); JvmParameterizedTypeReference parameterized = (JvmParameterizedTypeReference) paramType; 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()); }
Example #12
Source File: AbstractTypeProviderTest.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@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()); }
Example #13
Source File: AbstractTypeProviderTest.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
@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()); }
Example #14
Source File: AbstractTypeProviderTest.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
@Test public void test_ParameterizedTypes_02() { String typeName = ParameterizedTypes.class.getName(); JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName); JvmOperation methodS = getMethodFromType(type, ParameterizedTypes.class, "methodS(S)"); JvmTypeReference listS = methodS.getReturnType(); assertFalse(listS.toString(), listS.eIsProxy()); assertEquals("java.util.List<? extends S>", 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 S", wildcardTypeArgument.getIdentifier()); assertEquals(1, wildcardTypeArgument.getConstraints().size()); JvmUpperBound upperBound = (JvmUpperBound) wildcardTypeArgument.getConstraints().get(0); JvmTypeParameter s = type.getTypeParameters().get(0); assertSame(s, upperBound.getTypeReference().getType()); }
Example #15
Source File: AbstractTypeProviderTest.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
@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()); }
Example #16
Source File: AbstractTypeProviderTest.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
@Test public void test_ParameterizedTypes_05() { String typeName = ParameterizedTypes.class.getName(); JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName); JvmOperation methodZ = getMethodFromType(type, ParameterizedTypes.class, "methodZ(java.util.List)"); assertEquals(1, methodZ.getParameters().size()); assertEquals(1, methodZ.getTypeParameters().size()); assertEquals("Z", methodZ.getTypeParameters().get(0).getIdentifier()); JvmTypeReference listZ = methodZ.getReturnType(); assertFalse(listZ.toString(), listZ.getType().eIsProxy()); assertEquals("java.util.List<? extends java.lang.Object & super Z>", listZ.getIdentifier()); JvmParameterizedTypeReference listType = (JvmParameterizedTypeReference) listZ; 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 Z", wildcardTypeArgument.getIdentifier()); assertEquals(2, wildcardTypeArgument.getConstraints().size()); JvmUpperBound upperBound = (JvmUpperBound) wildcardTypeArgument.getConstraints().get(0); assertEquals("java.lang.Object", upperBound.getTypeReference().getIdentifier()); JvmLowerBound lowerBound = (JvmLowerBound) wildcardTypeArgument.getConstraints().get(1); assertEquals("Z", lowerBound.getTypeReference().getIdentifier()); JvmTypeParameter z = methodZ.getTypeParameters().get(0); assertSame(z, lowerBound.getTypeReference().getType()); }
Example #17
Source File: AbstractTypeProviderTest.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@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()); }
Example #18
Source File: AbstractTypeProviderTest.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@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()); }
Example #19
Source File: AbstractTypeProviderTest.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
@Test public void test_ParameterizedTypes_06() { String typeName = ParameterizedTypes.class.getName(); JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName); JvmOperation methodMap = getMethodFromType(type, ParameterizedTypes.class, "methodMap(java.util.Map)"); assertEquals(1, methodMap.getParameters().size()); assertEquals(1, methodMap.getTypeParameters().size()); assertEquals("Z", methodMap.getTypeParameters().get(0).getIdentifier()); JvmType z = methodMap.getReturnType().getType(); assertSame(methodMap.getTypeParameters().get(0), z); JvmTypeReference mapType = methodMap.getParameters().get(0).getParameterType(); assertEquals("java.util.Map<? extends java.lang.Object & super Z, ? extends S>", mapType.getIdentifier()); JvmParameterizedTypeReference parameterizedMapType = (JvmParameterizedTypeReference) mapType; assertEquals(2, parameterizedMapType.getArguments().size()); JvmWildcardTypeReference extendsS = (JvmWildcardTypeReference) parameterizedMapType.getArguments().get(1); assertEquals(1, extendsS.getConstraints().size()); JvmType s = type.getTypeParameters().get(0); assertSame(s, extendsS.getConstraints().get(0).getTypeReference().getType()); }
Example #20
Source File: AbstractTypeProviderTest.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@Test public void test_ParameterizedTypes_06() { String typeName = ParameterizedTypes.class.getName(); JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName); JvmOperation methodMap = getMethodFromType(type, ParameterizedTypes.class, "methodMap(java.util.Map)"); assertEquals(1, methodMap.getParameters().size()); assertEquals(1, methodMap.getTypeParameters().size()); assertEquals("Z", methodMap.getTypeParameters().get(0).getIdentifier()); JvmType z = methodMap.getReturnType().getType(); assertSame(methodMap.getTypeParameters().get(0), z); JvmTypeReference mapType = methodMap.getParameters().get(0).getParameterType(); assertEquals("java.util.Map<? extends java.lang.Object & super Z, ? extends S>", mapType.getIdentifier()); JvmParameterizedTypeReference parameterizedMapType = (JvmParameterizedTypeReference) mapType; assertEquals(2, parameterizedMapType.getArguments().size()); JvmWildcardTypeReference extendsS = (JvmWildcardTypeReference) parameterizedMapType.getArguments().get(1); assertEquals(1, extendsS.getConstraints().size()); JvmType s = type.getTypeParameters().get(0); assertSame(s, extendsS.getConstraints().get(0).getTypeReference().getType()); }
Example #21
Source File: AbstractTypeProviderTest.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@Test public void test_ParameterizedTypes_05() { String typeName = ParameterizedTypes.class.getName(); JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName); JvmOperation methodZ = getMethodFromType(type, ParameterizedTypes.class, "methodZ(java.util.List)"); assertEquals(1, methodZ.getParameters().size()); assertEquals(1, methodZ.getTypeParameters().size()); assertEquals("Z", methodZ.getTypeParameters().get(0).getIdentifier()); JvmTypeReference listZ = methodZ.getReturnType(); assertFalse(listZ.toString(), listZ.getType().eIsProxy()); assertEquals("java.util.List<? extends java.lang.Object & super Z>", listZ.getIdentifier()); JvmParameterizedTypeReference listType = (JvmParameterizedTypeReference) listZ; 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 Z", wildcardTypeArgument.getIdentifier()); assertEquals(2, wildcardTypeArgument.getConstraints().size()); JvmUpperBound upperBound = (JvmUpperBound) wildcardTypeArgument.getConstraints().get(0); assertEquals("java.lang.Object", upperBound.getTypeReference().getIdentifier()); JvmLowerBound lowerBound = (JvmLowerBound) wildcardTypeArgument.getConstraints().get(1); assertEquals("Z", lowerBound.getTypeReference().getIdentifier()); JvmTypeParameter z = methodZ.getTypeParameters().get(0); assertSame(z, lowerBound.getTypeReference().getType()); }
Example #22
Source File: AbstractTypeProviderTest.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@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()); }
Example #23
Source File: AbstractTypeProviderTest.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@Test public void test_ParameterizedTypes_02() { String typeName = ParameterizedTypes.class.getName(); JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName); JvmOperation methodS = getMethodFromType(type, ParameterizedTypes.class, "methodS(S)"); JvmTypeReference listS = methodS.getReturnType(); assertFalse(listS.toString(), listS.eIsProxy()); assertEquals("java.util.List<? extends S>", 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 S", wildcardTypeArgument.getIdentifier()); assertEquals(1, wildcardTypeArgument.getConstraints().size()); JvmUpperBound upperBound = (JvmUpperBound) wildcardTypeArgument.getConstraints().get(0); JvmTypeParameter s = type.getTypeParameters().get(0); assertSame(s, upperBound.getTypeReference().getType()); }
Example #24
Source File: AbstractTypeProviderTest.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@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()); }
Example #25
Source File: AbstractTypeProviderTest.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@Test public void test_twoListWildcardsNoResult_03() { JvmOperation twoListWildcardsNoResult = getMethodFromParameterizedMethods( "twoListWildcardsNoResult(java.util.List,java.util.List)"); JvmFormalParameter firstParam = twoListWildcardsNoResult.getParameters().get(0); JvmTypeReference paramType = firstParam.getParameterType(); JvmParameterizedTypeReference parameterized = (JvmParameterizedTypeReference) paramType; 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()); }
Example #26
Source File: AbstractTypeProviderTest.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
@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()); }
Example #27
Source File: JvmTypeConstraintImplCustom.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Override public void setTypeReference(JvmTypeReference newTypeReference) { if (newTypeReference instanceof JvmWildcardTypeReference) throw new IllegalArgumentException("wildcard type references are not supported as constraint bounds"); if (!isLikelyAValidConstraintBound(newTypeReference)) throw new IllegalArgumentException("primitive type references are not supported as constraint bounds"); super.setTypeReference(newTypeReference); }
Example #28
Source File: AbstractBuilder.java From sarl with Apache License 2.0 | 5 votes |
/** Replies the type reference for the given name in the given context. */ public JvmParameterizedTypeReference newTypeRef(Notifier context, String typeName) { JvmTypeReference typeReference; try { typeReference = findType(context, typeName); getImportManager().addImportFor(typeReference.getType()); return (JvmParameterizedTypeReference) typeReference; } catch (TypeNotPresentException exception) { } final JvmParameterizedTypeReference pref = ExpressionBuilderImpl.parseType(context, typeName, this); final JvmTypeReference baseType = findType(context, pref.getType().getIdentifier()); final int len = pref.getArguments().size(); final JvmTypeReference[] args = new JvmTypeReference[len]; for (int i = 0; i < len; ++i) { final JvmTypeReference original = pref.getArguments().get(i); if (original instanceof JvmAnyTypeReference) { args[i] = EcoreUtil.copy(original); } else if (original instanceof JvmWildcardTypeReference) { final JvmWildcardTypeReference wc = EcoreUtil.copy((JvmWildcardTypeReference) original); for (final JvmTypeConstraint c : wc.getConstraints()) { c.setTypeReference(newTypeRef(context, c.getTypeReference().getIdentifier())); } args[i] = wc; } else { args[i] = newTypeRef(context, original.getIdentifier()); } } final TypeReferences typeRefs = getTypeReferences(); return typeRefs.createTypeRef(baseType.getType(), args); }
Example #29
Source File: TypeReferences.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
public JvmWildcardTypeReference wildCardSuper(JvmTypeReference clone) { JvmWildcardTypeReference result = factory.createJvmWildcardTypeReference(); JvmLowerBound lowerBound = factory.createJvmLowerBound(); lowerBound.setTypeReference(clone); JvmUpperBound upperBound = factory.createJvmUpperBound(); upperBound.setTypeReference(getTypeForName(Object.class, clone.getType())); result.getConstraints().add(lowerBound); result.getConstraints().add(upperBound); return result; }
Example #30
Source File: TypeReferences.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
public JvmWildcardTypeReference wildCardExtends(JvmTypeReference clone) { JvmWildcardTypeReference result = factory.createJvmWildcardTypeReference(); JvmUpperBound upperBound = factory.createJvmUpperBound(); upperBound.setTypeReference(clone); result.getConstraints().add(upperBound); return result; }