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

The following examples show how to use org.eclipse.xtext.common.types.JvmParameterizedTypeReference. 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: SarlBehaviorUnitImpl.java    From sarl with Apache License 2.0 6 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public void eUnset(int featureID)
{
	switch (featureID)
	{
		case SarlPackage.SARL_BEHAVIOR_UNIT__NAME:
			setName((JvmParameterizedTypeReference)null);
			return;
		case SarlPackage.SARL_BEHAVIOR_UNIT__GUARD:
			setGuard((XExpression)null);
			return;
		case SarlPackage.SARL_BEHAVIOR_UNIT__EXPRESSION:
			setExpression((XExpression)null);
			return;
	}
	super.eUnset(featureID);
}
 
Example #3
Source File: AbstractConstantExpressionsInterpreter.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
protected JvmTypeReference toTypeReference(final JvmType type, final int arrayDimensions) {
  if ((type == null)) {
    return null;
  }
  JvmParameterizedTypeReference _createJvmParameterizedTypeReference = TypesFactory.eINSTANCE.createJvmParameterizedTypeReference();
  final Procedure1<JvmParameterizedTypeReference> _function = (JvmParameterizedTypeReference it) -> {
    it.setType(type);
  };
  JvmTypeReference resultTypeRef = ObjectExtensions.<JvmParameterizedTypeReference>operator_doubleArrow(_createJvmParameterizedTypeReference, _function);
  ExclusiveRange _doubleDotLessThan = new ExclusiveRange(0, arrayDimensions, true);
  for (final Integer i : _doubleDotLessThan) {
    {
      final JvmGenericArrayTypeReference arrayRef = TypesFactory.eINSTANCE.createJvmGenericArrayTypeReference();
      arrayRef.setComponentType(resultTypeRef);
      resultTypeRef = arrayRef;
    }
  }
  return resultTypeRef;
}
 
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_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 #5
Source File: SARLLabelProviderTest.java    From sarl with Apache License 2.0 6 votes vote down vote up
/**
 * @throws Exception
 */
@Test
public void getTextJvmParametizedTypeReference_1() throws Exception {
	SarlEvent event = helper().sarlTypeDeclaration(
			SarlEvent.class,
			PACKAGE_STATEMENT
			+ "event E1 {\n" //$NON-NLS-1$
			+ "var attr : org.eclipse.xtext.xbase.lib.Pair<java.lang.Integer,java.lang.Double>\n" //$NON-NLS-1$
			+ "}"); //$NON-NLS-1$
	validate(event.eResource()).assertNoErrors();
	EList<XtendMember> features = event.getMembers();
	assertNotNull(features);
	assertEquals(1, features.size());
	EObject eObject = features.get(0);
	assertTrue(eObject instanceof SarlField);
	SarlField attr = (SarlField)eObject;
	JvmTypeReference typeReference = attr.getType();
	assertTrue(typeReference instanceof JvmParameterizedTypeReference);
	JvmParameterizedTypeReference parametizedTypeReference = (JvmParameterizedTypeReference)typeReference;
	Object text = this.provider.getText(parametizedTypeReference);
	assertNotNull(text);
	assertEquals("Pair<Integer, Double>", text); //$NON-NLS-1$
}
 
Example #6
Source File: SARLJvmModelInferrer.java    From sarl with Apache License 2.0 6 votes vote down vote up
/** Generate the implemented types for the given SARL statement.
 *
 * @param context the context of the generation.
 * @param owner the JVM element to change.
 * @param defaultJvmType the default JVM type.
 * @param defaultSarlType the default SARL type.
 * @param implementedtypes the implemented types.
 */
protected void appendConstrainedImplements(
		GenerationContext context,
		JvmGenericType owner, Class<?> defaultJvmType,
		Class<? extends XtendTypeDeclaration> defaultSarlType,
		List<? extends JvmParameterizedTypeReference> implementedtypes) {
	boolean explicitType = false;
	for (final JvmParameterizedTypeReference superType : implementedtypes) {
		if (!Objects.equal(owner.getIdentifier(), superType.getIdentifier())
				&& superType.getType() instanceof JvmGenericType
				/*&& this.inheritanceHelper.isProxyOrSubTypeOf(superType, defaultJvmType, defaultSarlType, true)*/) {
			owner.getSuperTypes().add(this.typeBuilder.cloneWithProxies(superType));
			context.incrementSerial(superType.getIdentifier().hashCode());
			explicitType = true;
		}
	}
	if (!explicitType) {
		final JvmTypeReference type = this._typeReferenceBuilder.typeRef(defaultJvmType);
		owner.getSuperTypes().add(type);
		context.incrementSerial(type.getIdentifier().hashCode());
	}
}
 
Example #7
Source File: AbstractTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@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 #8
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 #9
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 #10
Source File: ParameterizedTypeReference.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
private LightweightTypeReference getSuperTypeByName(String typeName, boolean interfaceType) {
	JvmTypeReference superType = getSuperTypeByName(typeName, interfaceType, type, new RecursionGuard<JvmType>());
	if (superType != null) {
		JvmType rawType = superType.getType();
		if (isRawType()) {
			return createRawTypeReference(rawType);
		}
		if (superType.eClass() == TypesPackage.Literals.JVM_PARAMETERIZED_TYPE_REFERENCE) {
			if (((JvmParameterizedTypeReference) superType).getArguments().isEmpty()) {
				return getOwner().newParameterizedTypeReference(rawType);
			}
		}
		LightweightTypeReference unresolved = getOwner().toLightweightTypeReference(rawType);
		TypeParameterSubstitutor<?> substitutor = createSubstitutor();
		LightweightTypeReference result = substitutor.substitute(unresolved);
		return result;
	}
	return null;
}
 
Example #11
Source File: SarlArtifactImpl.java    From sarl with Apache License 2.0 6 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public void setExtends(JvmParameterizedTypeReference newExtends)
{
	if (newExtends != extends_)
	{
		NotificationChain msgs = null;
		if (extends_ != null)
			msgs = ((InternalEObject)extends_).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - SarlPackage.SARL_ARTIFACT__EXTENDS, null, msgs);
		if (newExtends != null)
			msgs = ((InternalEObject)newExtends).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - SarlPackage.SARL_ARTIFACT__EXTENDS, null, msgs);
		msgs = basicSetExtends(newExtends, msgs);
		if (msgs != null) msgs.dispatch();
	}
	else if (eNotificationRequired())
		eNotify(new ENotificationImpl(this, Notification.SET, SarlPackage.SARL_ARTIFACT__EXTENDS, newExtends, newExtends));
}
 
Example #12
Source File: SarlAgentImpl.java    From sarl with Apache License 2.0 6 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public void setExtends(JvmParameterizedTypeReference newExtends)
{
	if (newExtends != extends_)
	{
		NotificationChain msgs = null;
		if (extends_ != null)
			msgs = ((InternalEObject)extends_).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - SarlPackage.SARL_AGENT__EXTENDS, null, msgs);
		if (newExtends != null)
			msgs = ((InternalEObject)newExtends).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - SarlPackage.SARL_AGENT__EXTENDS, null, msgs);
		msgs = basicSetExtends(newExtends, msgs);
		if (msgs != null) msgs.dispatch();
	}
	else if (eNotificationRequired())
		eNotify(new ENotificationImpl(this, Notification.SET, SarlPackage.SARL_AGENT__EXTENDS, newExtends, newExtends));
}
 
Example #13
Source File: AbstractTypeProviderTest.java    From xtext-eclipse 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 #14
Source File: ProxyAwareUIStrings.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Returns the type arguments including the surrounding angular brackets.
 * If the typeRef is invalid in the sense that it contains unresolved proxies,
 * null is returned.
 */
/* @Nullable */
public StringBuilder appendTypeArguments(JvmParameterizedTypeReference typeRef, StringBuilder result) {
	List<JvmTypeReference> typeArguments = typeRef.getArguments();
	if (typeArguments.isEmpty()) {
		throw new IllegalArgumentException("typeRef is not parameterized");
	}
	result.append("<");
	for(int i = 0, size = typeArguments.size(); i < size; i++) {
		if (i != 0) {
			result.append(", ");
		}
		result = visit(typeArguments.get(i), result);
		if (result == null)
			return null;
	}
	result.append(">");
	return result;
}
 
Example #15
Source File: AbstractTypeProviderTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@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 #16
Source File: AbstractTypeProviderTest.java    From xtext-eclipse 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 #17
Source File: EntityImpl.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@SuppressWarnings("unchecked")
@Override
public void eSet(int featureID, Object newValue)
{
  switch (featureID)
  {
    case DomainmodelPackage.ENTITY__SUPER_TYPE:
      setSuperType((JvmParameterizedTypeReference)newValue);
      return;
    case DomainmodelPackage.ENTITY__FEATURES:
      getFeatures().clear();
      getFeatures().addAll((Collection<? extends Feature>)newValue);
      return;
  }
  super.eSet(featureID, newValue);
}
 
Example #18
Source File: SarlSkillImpl.java    From sarl with Apache License 2.0 6 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@SuppressWarnings("unchecked")
@Override
public void eSet(int featureID, Object newValue)
{
	switch (featureID)
	{
		case SarlPackage.SARL_SKILL__EXTENDS:
			setExtends((JvmParameterizedTypeReference)newValue);
			return;
		case SarlPackage.SARL_SKILL__IMPLEMENTS:
			getImplements().clear();
			getImplements().addAll((Collection<? extends JvmParameterizedTypeReference>)newValue);
			return;
	}
	super.eSet(featureID, newValue);
}
 
Example #19
Source File: SarlEventImpl.java    From sarl with Apache License 2.0 5 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public void eSet(int featureID, Object newValue)
{
	switch (featureID)
	{
		case SarlPackage.SARL_EVENT__EXTENDS:
			setExtends((JvmParameterizedTypeReference)newValue);
			return;
	}
	super.eSet(featureID, newValue);
}
 
Example #20
Source File: TypeReferences.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
public JvmTypeReference getTypeForName(Class<?> clazz, Notifier context, JvmTypeReference... params) {
	if (clazz == null)
		throw new NullPointerException("clazz");
	JvmType declaredType = findDeclaredType(clazz, context);
	if (declaredType == null)
		return getUnknownTypeReference(clazz.getName());
	JvmParameterizedTypeReference result = createTypeRef(declaredType, params);
	return result;
}
 
Example #21
Source File: AbstractTypeProviderTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void test_ParameterizedTypes_Inner_04() {
	String typeName = ParameterizedTypes.Inner.class.getName();
	JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName);
	JvmOperation methodT = getMethodFromType(type, ParameterizedTypes.Inner.class, "methodT()");
	JvmTypeReference listT = methodT.getReturnType();
	assertEquals("java.util.List<T>", listT.getIdentifier());
	JvmParameterizedTypeReference listType = (JvmParameterizedTypeReference) listT;
	assertEquals(1, listType.getArguments().size());
	JvmTypeReference typeArgument = listType.getArguments().get(0);
	assertEquals("T", typeArgument.getIdentifier());
	JvmTypeParameter t = ((JvmTypeParameterDeclarator) type.getDeclaringType()).getTypeParameters().get(1);
	assertSame(t, typeArgument.getType());
}
 
Example #22
Source File: InnerTypeReference.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public JvmTypeReference toTypeReference() {
	JvmInnerTypeReference result = getTypesFactory().createJvmInnerTypeReference();
	result.setType(getType());
	result.setOuter((JvmParameterizedTypeReference) outer.toTypeReference());
	for(LightweightTypeReference typeArgument: getTypeArguments()) {
		result.getArguments().add(typeArgument.toTypeReference());
	}
	return result;
}
 
Example #23
Source File: SarlBehaviorBuilderImpl.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Create a SarlCapacityUses.
 * @param name the types referenced by the SarlCapacityUses.
 */
public void addSarlCapacityUses(String... name) {
	if (name != null && name.length > 0) {
		SarlCapacityUses member = SarlFactory.eINSTANCE.createSarlCapacityUses();
		this.sarlBehavior.getMembers().add(member);
		member.setAnnotationInfo(XtendFactory.eINSTANCE.createXtendMember());
		Collection<JvmParameterizedTypeReference> thecollection = member.getCapacities();
		for (final String aname : name) {
			if (!Strings.isEmpty(aname)) {
				thecollection.add(newTypeRef(this.sarlBehavior, aname));
			}
		}
	}

}
 
Example #24
Source File: TypeReferences.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
public JvmTypeReference getTypeForName(String typeName, Notifier context, JvmTypeReference... params) {
	if (typeName == null)
		throw new NullPointerException("typeName");
	JvmType declaredType = findDeclaredType(typeName, context);
	if (declaredType == null)
		return getUnknownTypeReference(typeName);
	JvmParameterizedTypeReference result = createTypeRef(declaredType, params);
	return result;
}
 
Example #25
Source File: AbstractTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void test_twoListParamsListResult_02() {
	JvmOperation twoListParamsListResult = getMethodFromParameterizedMethods(
			"twoListParamsListResult(java.util.List,java.util.List)");
	JvmTypeReference returnType = twoListParamsListResult.getReturnType();
	assertNotNull(returnType);
	assertEquals("java.util.List<T>", returnType.getIdentifier());
	assertTrue(returnType instanceof JvmParameterizedTypeReference);
	JvmParameterizedTypeReference parameterized = (JvmParameterizedTypeReference) returnType;
	JvmType rawType = parameterized.getType();
	assertFalse(rawType.eIsProxy());
	assertEquals("java.util.List", rawType.getIdentifier());
}
 
Example #26
Source File: JvmTypeReferencesValidator.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected void warnRawType(JvmType type, JvmParameterizedTypeReference typeRef) {
	if (typeRef.eContainer() instanceof XInstanceOfExpression) {
		return;
	}
	StringBuilder message = new StringBuilder(64);
	message.append(type.getSimpleName());
	message.append(" is a raw type. References to generic type ");
	message = proxyAwareUIStrings.appendTypeSignature(type, message);
	message.append(" should be parameterized");
	warning(message.toString(), IssueCodes.RAW_TYPE, typeRef);
}
 
Example #27
Source File: SarlSkillImpl.java    From sarl with Apache License 2.0 5 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public NotificationChain basicSetExtends(JvmParameterizedTypeReference newExtends, NotificationChain msgs)
{
	JvmParameterizedTypeReference oldExtends = extends_;
	extends_ = newExtends;
	if (eNotificationRequired())
	{
		ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, SarlPackage.SARL_SKILL__EXTENDS, oldExtends, newExtends);
		if (msgs == null) msgs = notification; else msgs.add(notification);
	}
	return msgs;
}
 
Example #28
Source File: JvmTypeReferencesValidator.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Check
public void checkTypeArgumentsNotPrimitive(JvmParameterizedTypeReference typeRef) {
	EList<JvmTypeReference> arguments = typeRef.getArguments();
	for (int i=0;i<arguments.size();i++) {
		JvmTypeReference jvmTypeReference = arguments.get(i);
		checkNotPrimitive(jvmTypeReference);
	}
}
 
Example #29
Source File: XbaseValidator.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Check
public void checkDeprecated(JvmParameterizedTypeReference type) {
	if (!isIgnored(DEPRECATED_MEMBER_REFERENCE)) {
		JvmType jvmType = type.getType();
		checkDeprecated(
				jvmType,
				type,
				TypesPackage.Literals.JVM_PARAMETERIZED_TYPE_REFERENCE__TYPE);
	}
}
 
Example #30
Source File: AbstractTypeProviderTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testVarArgs_03() {
	String typeName = ClassWithVarArgs.class.getName();
	JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName);
	JvmConstructor constructor = getConstructorFromType(type, ClassWithVarArgs.class,
			"ClassWithVarArgs(int,java.lang.String[])");
	assertTrue(constructor.isVarArgs());
	assertEquals(2, constructor.getParameters().size());
	assertTrue(constructor.getParameters().get(0).getParameterType() instanceof JvmParameterizedTypeReference);
	assertTrue(constructor.getParameters().get(1).getParameterType() instanceof JvmGenericArrayTypeReference);
}