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

The following examples show how to use org.eclipse.xtext.common.types.JvmTypeParameterDeclarator. 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: JvmTypeParameterImpl.java    From xtext-extras with Eclipse Public 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 TypesPackage.JVM_TYPE_PARAMETER__CONSTRAINTS:
			getConstraints().clear();
			return;
		case TypesPackage.JVM_TYPE_PARAMETER__NAME:
			setName(NAME_EDEFAULT);
			return;
		case TypesPackage.JVM_TYPE_PARAMETER__DECLARATOR:
			setDeclarator((JvmTypeParameterDeclarator)null);
			return;
	}
	super.eUnset(featureID);
}
 
Example #2
Source File: RawTypeReferenceComputer.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public JvmTypeReference doVisitParameterizedTypeReference(JvmParameterizedTypeReference reference, Pair<Resource, Set<JvmType>> context) {
	JvmType type = reference.getType();
	if (type != null && !type.eIsProxy()) {
		if (type instanceof JvmTypeParameterDeclarator) {
			if (!((JvmTypeParameterDeclarator) type).getTypeParameters().isEmpty()) {
				JvmParameterizedTypeReference result = factory.createJvmParameterizedTypeReference();
				result.setType(type);
				return result;
			}
		} else if (type instanceof JvmTypeParameter) {
			Set<JvmType> recursionGuard = context.getSecond();
			if (recursionGuard.add(type)) {
				return getRawTypeFromConstraints(((JvmTypeParameter) type).getConstraints(), context);
			} else {
				return createObjectReference(context.getFirst());
			}
		}
	}
	return reference;
}
 
Example #3
Source File: JvmDeclaredTypeSignatureHashProvider.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
public SignatureHashBuilder appendSignature(JvmDeclaredType type) {
	if (type.getVisibility() != JvmVisibility.PRIVATE) {
		appendAnnotationReferences(type);
		appendVisibility(type.getVisibility()).append(" ");
		if (type.isAbstract())
			append("abstract ");
		if (type.isStatic())
			append("static ");
		if (type.isFinal())
			append("final ");
		append("class ").append(type.getIdentifier());
		if (type instanceof JvmTypeParameterDeclarator)
			appendTypeParameters((JvmTypeParameterDeclarator) type);
		append("\n").appendSuperTypeSignatures(type).appendMemberSignatures(type, false);
	}
	return this;
}
 
Example #4
Source File: ReflectionTypeFactory.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
protected JvmFormalParameter createFormalParameter(Type parameterType, String paramName,
		JvmMember container, GenericDeclaration member, Annotation[] annotations) {
	JvmFormalParameter result = TypesFactory.eINSTANCE.createJvmFormalParameter();
	result.setName(paramName);
	if (isLocal(parameterType, member)) {
		result.setParameterType(createLocalTypeReference(parameterType, (JvmTypeParameterDeclarator) container,
				member));
	} else {
		result.setParameterType(createTypeReference(parameterType));
	}
	if (annotations.length != 0) {
		InternalEList<JvmAnnotationReference> annotationsReferences = (InternalEList<JvmAnnotationReference>)result.getAnnotations();
		for (Annotation annotation : annotations) {
			annotationsReferences.addUnique(createAnnotationReference(annotation));
		}
	}
	return result;
}
 
Example #5
Source File: RawTypeHelper.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public JvmTypeReference doVisitParameterizedTypeReference(JvmParameterizedTypeReference reference,
		Resource resource) {
	JvmType type = reference.getType();
	if (type != null && !type.eIsProxy()) {
		if (type instanceof JvmTypeParameterDeclarator) {
			if (!((JvmTypeParameterDeclarator) type).getTypeParameters().isEmpty()) {
				JvmParameterizedTypeReference result = factory.createJvmParameterizedTypeReference();
				result.setType(type);
				return result;
			}
		} else if (type instanceof JvmTypeParameter) {
			return getRawTypeFromConstraints(((JvmTypeParameter) type).getConstraints(), resource);
		}
	}
	return reference;
}
 
Example #6
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 #7
Source File: JvmTypeParameterImpl.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public void setDeclarator(JvmTypeParameterDeclarator newDeclarator)
{
	if (newDeclarator != eInternalContainer() || (eContainerFeatureID() != TypesPackage.JVM_TYPE_PARAMETER__DECLARATOR && newDeclarator != null))
	{
		if (EcoreUtil.isAncestor(this, newDeclarator))
			throw new IllegalArgumentException("Recursive containment not allowed for " + toString());
		NotificationChain msgs = null;
		if (eInternalContainer() != null)
			msgs = eBasicRemoveFromContainer(msgs);
		if (newDeclarator != null)
			msgs = ((InternalEObject)newDeclarator).eInverseAdd(this, TypesPackage.JVM_TYPE_PARAMETER_DECLARATOR__TYPE_PARAMETERS, JvmTypeParameterDeclarator.class, msgs);
		msgs = basicSetDeclarator(newDeclarator, msgs);
		if (msgs != null) msgs.dispatch();
	}
	else if (eNotificationRequired())
		eNotify(new ENotificationImpl(this, Notification.SET, TypesPackage.JVM_TYPE_PARAMETER__DECLARATOR, newDeclarator, newDeclarator));
}
 
Example #8
Source File: JvmTypeParameterImpl.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@SuppressWarnings("unchecked")
@Override
public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, NotificationChain msgs)
{
	switch (featureID)
	{
		case TypesPackage.JVM_TYPE_PARAMETER__CONSTRAINTS:
			return ((InternalEList<InternalEObject>)(InternalEList<?>)getConstraints()).basicAdd(otherEnd, msgs);
		case TypesPackage.JVM_TYPE_PARAMETER__DECLARATOR:
			if (eInternalContainer() != null)
				msgs = eBasicRemoveFromContainer(msgs);
			return basicSetDeclarator((JvmTypeParameterDeclarator)otherEnd, msgs);
	}
	return super.eInverseAdd(otherEnd, featureID, msgs);
}
 
Example #9
Source File: NonOverridableTypesProvider.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
protected void process(JvmMember context, Map<String, JvmIdentifiableElement> result) {
	if (context instanceof JvmDeclaredType) {
		if (!result.containsKey(context.getSimpleName()))
			result.put(context.getSimpleName(), context);
		JvmDeclaredType contextType = (JvmDeclaredType) context;
		ContextualVisibilityHelper visibilityHelper = new ContextualVisibilityHelper(this.visibilityHelper, contextType);
		addInnerTypes(contextType, "", visibilityHelper, result);
		
		Set<JvmType> superTypes = rawSuperTypes.collect(contextType);
		for (JvmType superType : superTypes) {
			if (superType instanceof JvmDeclaredType)
				addInnerTypes((JvmDeclaredType) superType, "", visibilityHelper, result);
		}
	}
	if (context instanceof JvmTypeParameterDeclarator)
		addTypeParameters((JvmTypeParameterDeclarator) context, result);
	JvmDeclaredType declaringType = context.getDeclaringType();
	if (declaringType != null)
		process(declaringType, result);
}
 
Example #10
Source File: JvmTypeParameterImpl.java    From xtext-extras 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 TypesPackage.JVM_TYPE_PARAMETER__CONSTRAINTS:
			getConstraints().clear();
			getConstraints().addAll((Collection<? extends JvmTypeConstraint>)newValue);
			return;
		case TypesPackage.JVM_TYPE_PARAMETER__NAME:
			setName((String)newValue);
			return;
		case TypesPackage.JVM_TYPE_PARAMETER__DECLARATOR:
			setDeclarator((JvmTypeParameterDeclarator)newValue);
			return;
	}
	super.eSet(featureID, newValue);
}
 
Example #11
Source File: FunctionTypes.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
public List<JvmTypeParameter> collectAllTypeParameters(LightweightTypeReference closureType,
		JvmOperation operation) {
	// common case is worthy optimizing
	List<JvmType> rawTypes = closureType.getRawTypes();
	if (rawTypes.size() == 1 && operation.getTypeParameters().isEmpty()) {
		JvmType type = rawTypes.get(0);
		if (type instanceof JvmTypeParameterDeclarator) {
			return ((JvmTypeParameterDeclarator) type).getTypeParameters();
		}
		return Collections.emptyList();
	} else {
		List<JvmTypeParameter> allTypeParameters = Lists.newArrayList();
		for(JvmType rawType: rawTypes) {
			if (rawType instanceof JvmTypeParameterDeclarator) {
				allTypeParameters.addAll(((JvmTypeParameterDeclarator) rawType).getTypeParameters());
			}
		}
		allTypeParameters.addAll(operation.getTypeParameters());
		return allTypeParameters;
	}
}
 
Example #12
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_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 #13
Source File: XtendJvmModelInferrer.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
protected void fixTypeParameters(JvmTypeParameterDeclarator target) {
	for (JvmTypeParameter typeParameter : target.getTypeParameters()) {
		boolean upperBoundSeen = false;
		for (JvmTypeConstraint constraint : typeParameter.getConstraints()) {
			if (constraint instanceof JvmUpperBound) {
				upperBoundSeen = true;
				break;
			}
		}
		if (!upperBoundSeen) {
			JvmUpperBound upperBound = typesFactory.createJvmUpperBound();
			upperBound.setTypeReference(typeReferences.getTypeForName(Object.class, target));
			typeParameter.getConstraints().add(upperBound);
		}
	}
}
 
Example #14
Source File: ProxyAwareUIStrings.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Returns the signature of the given type. If the type declares type parameters, the type
 * parameters are included but their bounds are omitted. That is, the type {@code X<T extends CharSequence>}
 * will be returned as {@code X<T>}
 *
 */
public StringBuilder appendTypeSignature(JvmType type, StringBuilder result) {
	result.append(type.getSimpleName());
	if(type instanceof JvmTypeParameterDeclarator) {
		List<JvmTypeParameter> typeParameters = ((JvmTypeParameterDeclarator) type).getTypeParameters();
		if (!typeParameters.isEmpty()) {
			result.append("<");
			for(int i = 0, size = typeParameters.size(); i < size; i++) {
				if (i != 0) {
					result.append(", ");
				}
				result.append(typeParameters.get(i).getName());
			}
			result.append(">");
		}
	}
	return result;
}
 
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_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 #16
Source File: JvmExecutableImpl.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public int eBaseStructuralFeatureID(int derivedFeatureID, Class<?> baseClass)
{
	if (baseClass == JvmTypeParameterDeclarator.class)
	{
		switch (derivedFeatureID)
		{
			case TypesPackage.JVM_EXECUTABLE__TYPE_PARAMETERS: return TypesPackage.JVM_TYPE_PARAMETER_DECLARATOR__TYPE_PARAMETERS;
			default: return -1;
		}
	}
	return super.eBaseStructuralFeatureID(derivedFeatureID, baseClass);
}
 
Example #17
Source File: JvmGenericTypeImpl.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public int eDerivedStructuralFeatureID(int baseFeatureID, Class<?> baseClass)
{
	if (baseClass == JvmTypeParameterDeclarator.class)
	{
		switch (baseFeatureID)
		{
			case TypesPackage.JVM_TYPE_PARAMETER_DECLARATOR__TYPE_PARAMETERS: return TypesPackage.JVM_GENERIC_TYPE__TYPE_PARAMETERS;
			default: return -1;
		}
	}
	return super.eDerivedStructuralFeatureID(baseFeatureID, baseClass);
}
 
Example #18
Source File: JvmGenericTypeImpl.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public int eBaseStructuralFeatureID(int derivedFeatureID, Class<?> baseClass)
{
	if (baseClass == JvmTypeParameterDeclarator.class)
	{
		switch (derivedFeatureID)
		{
			case TypesPackage.JVM_GENERIC_TYPE__TYPE_PARAMETERS: return TypesPackage.JVM_TYPE_PARAMETER_DECLARATOR__TYPE_PARAMETERS;
			default: return -1;
		}
	}
	return super.eBaseStructuralFeatureID(derivedFeatureID, baseClass);
}
 
Example #19
Source File: ReflectionTypeFactory.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected JvmTypeReference createLocalArrayTypeReference(Type componentType, JvmTypeParameterDeclarator container,
		GenericDeclaration member) {
	JvmTypeReference componentTypeReference = createLocalTypeReference(componentType, container, member);
	JvmGenericArrayTypeReference result = TypesFactory.eINSTANCE.createJvmGenericArrayTypeReference();
	result.setComponentType(componentTypeReference);
	return result;
}
 
Example #20
Source File: JvmExecutableImpl.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public int eDerivedStructuralFeatureID(int baseFeatureID, Class<?> baseClass)
{
	if (baseClass == JvmTypeParameterDeclarator.class)
	{
		switch (baseFeatureID)
		{
			case TypesPackage.JVM_TYPE_PARAMETER_DECLARATOR__TYPE_PARAMETERS: return TypesPackage.JVM_EXECUTABLE__TYPE_PARAMETERS;
			default: return -1;
		}
	}
	return super.eDerivedStructuralFeatureID(baseFeatureID, baseClass);
}
 
Example #21
Source File: JvmTypeParameterImpl.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public NotificationChain eBasicRemoveFromContainerFeature(NotificationChain msgs)
{
	switch (eContainerFeatureID())
	{
		case TypesPackage.JVM_TYPE_PARAMETER__DECLARATOR:
			return eInternalContainer().eInverseRemove(this, TypesPackage.JVM_TYPE_PARAMETER_DECLARATOR__TYPE_PARAMETERS, JvmTypeParameterDeclarator.class, msgs);
	}
	return super.eBasicRemoveFromContainerFeature(msgs);
}
 
Example #22
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 #23
Source File: JvmTypeParameterDeclaratorItemProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * This handles model notifications by calling {@link #updateChildren} to update any cached
 * children and by creating a viewer notification, which it passes to {@link #fireNotifyChanged}.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public void notifyChanged(Notification notification)
{
	updateChildren(notification);

	switch (notification.getFeatureID(JvmTypeParameterDeclarator.class))
	{
		case TypesPackage.JVM_TYPE_PARAMETER_DECLARATOR__TYPE_PARAMETERS:
			fireNotifyChanged(new ViewerNotification(notification, notification.getNotifier(), true, false));
			return;
	}
	super.notifyChanged(notification);
}
 
Example #24
Source File: XtendJvmModelInferrer.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
protected void copyTypeParameters(List<JvmTypeParameter> typeParameters, JvmTypeParameterDeclarator target) {
	for (JvmTypeParameter typeParameter : typeParameters) {
		if (!Strings.isEmpty(typeParameter.getName())) {
			final JvmTypeParameter clonedTypeParameter = jvmTypesBuilder.cloneWithProxies(typeParameter);
			if (clonedTypeParameter != null) {
				target.getTypeParameters().add(clonedTypeParameter);
				associator.associate(typeParameter, clonedTypeParameter);
			}
		}
	}
}
 
Example #25
Source File: JvmTypeParameterImpl.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public JvmTypeParameterDeclarator getDeclarator()
{
	if (eContainerFeatureID() != TypesPackage.JVM_TYPE_PARAMETER__DECLARATOR) return null;
	return (JvmTypeParameterDeclarator)eInternalContainer();
}
 
Example #26
Source File: JvmDeclaredTypeSignatureHashProvider.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected SignatureHashBuilder appendTypeParameters(JvmTypeParameterDeclarator decl) {
	append("<");
	for (JvmTypeParameter tp : decl.getTypeParameters()) {
		appendTypeParameter(tp).append(",");
	}
	append(">");
	return this;
}
 
Example #27
Source File: AbstractTypeProviderTest.java    From xtext-extras 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 #28
Source File: ReflectionTypeFactory.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected JvmTypeReference createLocalTypeReference(Type type, JvmTypeParameterDeclarator container,
		GenericDeclaration member) {
	if (type instanceof GenericArrayType) {
		GenericArrayType arrayType = (GenericArrayType) type;
		Type componentType = arrayType.getGenericComponentType();
		return createLocalArrayTypeReference(componentType, container, member);
	} else if (type instanceof TypeVariable<?>) {
		TypeVariable<?> typeVariable = (TypeVariable<?>) type;
		JvmParameterizedTypeReference result = TypesFactory.eINSTANCE.createJvmParameterizedTypeReference();
		int idx = Arrays.asList(member.getTypeParameters()).indexOf(typeVariable);
		result.setType(container.getTypeParameters().get(idx));
		return result;
	}
	throw new IllegalArgumentException(type.toString());
}
 
Example #29
Source File: ConstructorLinkingCandidate.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected List<JvmTypeParameter> getDeclaredTypeParameters() {
	if (isAnonymousClassConstructorCall()) {
		JvmDeclaredType anonymousType = getConstructor().getDeclaringType();
		JvmTypeReference superType = Iterables.getLast(anonymousType.getSuperTypes());
		JvmType rawSuperType = superType.getType();
		if (rawSuperType instanceof JvmTypeParameterDeclarator) {
			return ((JvmTypeParameterDeclarator) rawSuperType).getTypeParameters();
		}
		return Collections.emptyList();
	}
	return new FeatureLinkHelper().getDeclaredTypeParameters(getConstructor());
}
 
Example #30
Source File: LogicalContainerAwareReentrantTypeResolver.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected StackedResolvedTypes declareTypeParameters(ResolvedTypes resolvedTypes, JvmIdentifiableElement declarator,
		Map<JvmIdentifiableElement, ResolvedTypes> resolvedTypesByContext) {
	StackedResolvedTypes childResolvedTypes = resolvedTypes.pushTypes();
	if (declarator instanceof JvmTypeParameterDeclarator) {
		JvmTypeParameterDeclarator casted = (JvmTypeParameterDeclarator) declarator;
		if (isStatic(declarator) && !(declarator instanceof JvmConstructor)) {
			childResolvedTypes.replaceDeclaredTypeParameters(casted.getTypeParameters());
		} else {
			childResolvedTypes.addDeclaredTypeParameters(casted.getTypeParameters());
		}
	}
	resolvedTypesByContext.put(declarator, childResolvedTypes);
	return childResolvedTypes;
}