org.eclipse.xtext.common.types.JvmUpperBound Java Examples

The following examples show how to use org.eclipse.xtext.common.types.JvmUpperBound. 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-extras with Eclipse Public License 2.0 6 votes vote down vote up
@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 #2
Source File: AbstractTypeProviderTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@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: AbstractTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@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());
}
 
Example #4
Source File: AbstractTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@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 #5
Source File: AbstractTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@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 #6
Source File: JvmExecutableDeclarationImpl.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
public MutableTypeParameterDeclaration addTypeParameter(final String name, final TypeReference... upperBounds) {
  this.checkMutable();
  ConditionUtils.checkJavaIdentifier(name, "name");
  ConditionUtils.checkIterable(((Iterable<?>)Conversions.doWrapArray(upperBounds)), "upperBounds");
  ConditionUtils.checkInferredTypeReferences("parameter type", upperBounds);
  final JvmTypeParameter param = TypesFactory.eINSTANCE.createJvmTypeParameter();
  param.setName(name);
  this.getDelegate().getTypeParameters().add(param);
  for (final TypeReference upper : upperBounds) {
    {
      final JvmTypeReference typeRef = this.getCompilationUnit().toJvmTypeReference(upper);
      final JvmUpperBound jvmUpperBound = TypesFactory.eINSTANCE.createJvmUpperBound();
      jvmUpperBound.setTypeReference(typeRef);
      param.getConstraints().add(jvmUpperBound);
    }
  }
  TypeParameterDeclaration _typeParameterDeclaration = this.getCompilationUnit().toTypeParameterDeclaration(param);
  return ((MutableTypeParameterDeclaration) _typeParameterDeclaration);
}
 
Example #7
Source File: AbstractTypeProviderTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void test_ParameterizedTypes_Inner_X_01() {
	String typeName = ParameterizedTypes.Inner.class.getName();
	JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName);
	JvmTypeParameter typeParameterX = type.getTypeParameters().get(0);
	assertEquals("X", typeParameterX.getIdentifier());
	assertSame(type, typeParameterX.getDeclarator());
	assertEquals(1, typeParameterX.getConstraints().size());
	JvmTypeConstraint typeConstraint = typeParameterX.getConstraints().get(0);
	assertTrue(typeConstraint instanceof JvmUpperBound);
	JvmUpperBound upperBound = (JvmUpperBound) typeConstraint;
	assertNotNull(upperBound.getTypeReference());
	assertEquals("W", upperBound.getTypeReference().getIdentifier());
	JvmType upperBoundType = upperBound.getTypeReference().getType();
	assertTrue(upperBoundType instanceof JvmTypeParameter);
	JvmTypeParameter typeParameterW = (JvmTypeParameter) upperBoundType;
	assertSame(type.getDeclaringType(), typeParameterW.getDeclarator());
}
 
Example #8
Source File: MutableJvmInterfaceDeclarationImpl.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public MutableTypeParameterDeclaration addTypeParameter(final String name, final TypeReference... upperBounds) {
  this.checkMutable();
  ConditionUtils.checkJavaIdentifier(name, "name");
  ConditionUtils.checkIterable(((Iterable<?>)Conversions.doWrapArray(upperBounds)), "upperBounds");
  ConditionUtils.checkInferredTypeReferences("parameter type", upperBounds);
  final JvmTypeParameter param = TypesFactory.eINSTANCE.createJvmTypeParameter();
  param.setName(name);
  this.getDelegate().getTypeParameters().add(param);
  for (final TypeReference upper : upperBounds) {
    {
      final JvmTypeReference typeRef = this.getCompilationUnit().toJvmTypeReference(upper);
      final JvmUpperBound jvmUpperBound = TypesFactory.eINSTANCE.createJvmUpperBound();
      jvmUpperBound.setTypeReference(typeRef);
      param.getConstraints().add(jvmUpperBound);
    }
  }
  TypeParameterDeclaration _typeParameterDeclaration = this.getCompilationUnit().toTypeParameterDeclaration(param);
  return ((MutableTypeParameterDeclaration) _typeParameterDeclaration);
}
 
Example #9
Source File: AbstractTypeProviderTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@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());
}
 
Example #10
Source File: AbstractPendingLinkingCandidate.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Returns the unresolved string representation of the given type parameter. The simple names of
 * the type bounds are used. The string representation includes the bounds, except for
 * the upper bound {@link Object}. 
 */
protected String getTypeParameterAsString(JvmTypeParameter typeParameter) {
	StringBuilder b = new StringBuilder();
	b.append(typeParameter.getName());
	ITypeReferenceOwner referenceOwner = getState().getReferenceOwner();
	if(!typeParameter.getConstraints().isEmpty()) {
		boolean firstUpperBound = true;
		for(int j=0; j<typeParameter.getConstraints().size(); ++j) {
			JvmTypeConstraint constraint = typeParameter.getConstraints().get(j);
			LightweightTypeReference typeRef = referenceOwner.toLightweightTypeReference(constraint.getTypeReference());
			if(constraint instanceof JvmUpperBound) {
				if(typeRef.isType(Object.class))
					continue;
				if (firstUpperBound) {
					b.append(" extends ");
					firstUpperBound = false;
				} else {
					b.append(" & ");
				}
			} else 
				b.append(" super ");
			b.append(typeRef.getHumanReadableName());
		}
	}
	return b.toString();
}
 
Example #11
Source File: AbstractTypeProviderTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@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 #12
Source File: TypeParameterByConstraintSubstitutor.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Override
/* @Nullable */
protected LightweightTypeReference getDeclaredUpperBound(JvmTypeParameter typeParameter, ConstraintVisitingInfo visiting) {
	if (!typeParameter.getConstraints().isEmpty() &&
				((DeclaredConstraintVisitingInfo)visiting).tryVisitDeclaredUpperBoundsOf(typeParameter)) {
		try {
			JvmTypeConstraint constraint = typeParameter.getConstraints().get(0);
			if (constraint instanceof JvmUpperBound) {
				LightweightTypeReference reference = getOwner().toLightweightTypeReference(constraint.getTypeReference());
				if (visiting.getCurrentDeclarator() != reference.getType()) {
					return reference.accept(this, visiting);
				}
				WildcardTypeReference result = getOwner().newWildcardTypeReference();
				result.addUpperBound(getObjectReference());
				return result;
			}
		} finally {
			((DeclaredConstraintVisitingInfo)visiting).didVisitDeclaredUpperBoundsOf(typeParameter);
		}
	}
	return null;
}
 
Example #13
Source File: AbstractTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@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);
}
 
Example #14
Source File: AbstractTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@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 #15
Source File: AbstractTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@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: RawTypeHelper.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
protected List<JvmType> getRawTypesFromConstraints(ITypeReferenceOwner owner, JvmTypeParameter typeParameter, ResourceSet resourceSet) {
	if (visited.add(typeParameter)) {
		List<JvmTypeConstraint> constraints = typeParameter.getConstraints();
		if (!constraints.isEmpty()) {
			List<JvmType> result = Lists.newArrayList();
			for(JvmTypeConstraint constraint: constraints) {
				if (constraint instanceof JvmUpperBound && constraint.getTypeReference() != null) {
					result.addAll(owner.toLightweightTypeReference(constraint.getTypeReference()).accept(this, resourceSet));
				}
			}
			if (!result.isEmpty())
				return result;
		}
	}
	return createObjectReference(resourceSet);
}
 
Example #17
Source File: AbstractTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@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 #18
Source File: AbstractTypeProviderTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@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());
}
 
Example #19
Source File: AbstractTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@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 #20
Source File: AbstractTypeProviderTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@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 #21
Source File: AbstractTypeProviderTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@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 #22
Source File: AbstractTypeProviderTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@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 #23
Source File: AbstractTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@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());
}
 
Example #24
Source File: AbstractTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@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());
}
 
Example #25
Source File: AbstractTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@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 #26
Source File: AbstractTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@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 #27
Source File: AbstractTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void test_ParameterizedTypes_Inner_X_01() {
	String typeName = ParameterizedTypes.Inner.class.getName();
	JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName);
	JvmTypeParameter typeParameterX = type.getTypeParameters().get(0);
	assertEquals("X", typeParameterX.getIdentifier());
	assertSame(type, typeParameterX.getDeclarator());
	assertEquals(1, typeParameterX.getConstraints().size());
	JvmTypeConstraint typeConstraint = typeParameterX.getConstraints().get(0);
	assertTrue(typeConstraint instanceof JvmUpperBound);
	JvmUpperBound upperBound = (JvmUpperBound) typeConstraint;
	assertNotNull(upperBound.getTypeReference());
	assertEquals("W", upperBound.getTypeReference().getIdentifier());
	JvmType upperBoundType = upperBound.getTypeReference().getType();
	assertTrue(upperBoundType instanceof JvmTypeParameter);
	JvmTypeParameter typeParameterW = (JvmTypeParameter) upperBoundType;
	assertSame(type.getDeclaringType(), typeParameterW.getDeclarator());
}
 
Example #28
Source File: AbstractTypeProviderTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@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);
}
 
Example #29
Source File: AbstractTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@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());
}
 
Example #30
Source File: NameConcatHelper.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
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 "?";
}