Java Code Examples for org.eclipse.xtext.xbase.typesystem.references.ParameterizedTypeReference#getType()

The following examples show how to use org.eclipse.xtext.xbase.typesystem.references.ParameterizedTypeReference#getType() . 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: DeferredTypeParameterHintCollector.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected void doVisitArrayTypeReference(ArrayTypeReference reference, ParameterizedTypeReference declaration) {
	JvmType type = declaration.getType();
	if (type instanceof JvmTypeParameter) {
		if (shouldProcess((JvmTypeParameter) type)) {
			JvmTypeParameter typeParameter = (JvmTypeParameter) type;
			processTypeParameter(typeParameter, reference);
		}
	} else {
		if (!declaration.isRawType() && (declaration.isType(List.class) || declaration.isType(Collection.class) || declaration.isType(Iterable.class))) {
			LightweightTypeReference elementType = declaration.getTypeArguments().get(0);
			LightweightTypeReference componentType = reference.getComponentType();
			outerVisit(componentType.getInvariantBoundSubstitute(), elementType);
		}
	}
}
 
Example 2
Source File: RawTypeConformanceComputer.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
private int internalGetPrimitiveKindFromWrapper(ParameterizedTypeReference typeReference) {
	JvmType type = typeReference.getType();
	if (type == null || type.eIsProxy()) {
		return PRIMITIVE_NONE; 
	}
	EClass eClass = type.eClass();
	if (eClass != TypesPackage.Literals.JVM_GENERIC_TYPE) {
		if (eClass == TypesPackage.Literals.JVM_TYPE_PARAMETER) {
			return internalGetPrimitiveKindFromWrapper((JvmTypeParameter)type, null);
		}
		return PRIMITIVE_NONE;
	}
	return internalGetPrimitiveKindFromWrapper((JvmGenericType)type);
}
 
Example 3
Source File: UnboundTypeParameterAwareTypeArgumentCollector.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void doVisitUnboundTypeReference(UnboundTypeReference reference,
		ParameterizedTypeReference declaration) {
	JvmType type = declaration.getType();
	if (type instanceof JvmTypeParameter) {
		JvmTypeParameter unboundTypeParameter = (JvmTypeParameter) type;
		if (unboundTypeParameter != reference.getTypeParameter() && shouldProcess(unboundTypeParameter)) {
			processTypeParameter(unboundTypeParameter, reference);
		} else {
			// register synonym type param resolution et al for the actual type in the given UnboundTypeParameter
		}
	} else {
		acceptHint(reference, declaration);
	}
}
 
Example 4
Source File: UnboundTypeParameterAwareTypeArgumentCollector.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void doVisitCompoundTypeReference(CompoundTypeReference reference,
		ParameterizedTypeReference declaration) {
	JvmType type = declaration.getType();
	if (type instanceof JvmTypeParameter) {
		JvmTypeParameter unboundTypeParameter = (JvmTypeParameter) type;
		if (shouldProcess(unboundTypeParameter)) {
			processTypeParameter(unboundTypeParameter, reference);
		}
	} else {
		super.doVisitCompoundTypeReference(reference, declaration);
	}
}
 
Example 5
Source File: ConstraintAwareTypeArgumentCollector.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Boolean doVisitParameterizedTypeReference(ParameterizedTypeReference reference, LightweightTraversalData data) {
	JvmType type = reference.getType();
	if (!type.eIsProxy() && data.getVisited().add(type)) {
		if (type instanceof JvmTypeParameter) {
			JvmTypeParameter typeParameter = (JvmTypeParameter) type;
			if (!data.getTypeParameterMapping().containsKey(type)) {
				return addConstraintMapping(typeParameter, owner, data);
			}
		} else {
			return doVisitParameterizedTypeReference(reference, type, data);
		}
	}
	return Boolean.FALSE;
}
 
Example 6
Source File: DeclaratorTypeArgumentCollector.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Boolean doVisitParameterizedTypeReference(ParameterizedTypeReference reference, LightweightTraversalData data) {
	JvmType type = reference.getType();
	// TODO improve handling of redundant super types where a better path to the supertype exists
	/*
	 * e.g. MyList extends AbstractList implements List<String> {}
	 * the implements clause seems to be redundant but provides more reliable information
	 */
	if (!type.eIsProxy() && data.getVisited().add(type)) {
		return doVisitParameterizedTypeReference(reference, type, data);
	}
	return Boolean.FALSE;
}
 
Example 7
Source File: TypeParameterSubstitutor.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected LightweightTypeReference doVisitParameterizedTypeReference(ParameterizedTypeReference reference, Visiting visiting) {
	if (reference.isResolved() && reference.isOwnedBy(getOwner()))
		return reference;
	JvmType type = reference.getType();
	if (type instanceof JvmTypeParameter) {
		LightweightTypeReference boundTypeArgument = getBoundTypeArgument(reference, (JvmTypeParameter) type, visiting);
		if (boundTypeArgument != null)
			return boundTypeArgument;
	}
	return doVisitParameterizedTypeReference(reference, type, visiting);
}
 
Example 8
Source File: AbstractTypeReferencePairWalker.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void doVisitParameterizedTypeReference(ParameterizedTypeReference reference, ArrayTypeReference declaration) {
	JvmType type = reference.getType();
	if (type instanceof JvmTypeParameter) {
		if (shouldProcess((JvmTypeParameter) type)) {
			JvmTypeParameter typeParameter = (JvmTypeParameter) type;
			processTypeParameter(typeParameter, declaration);
		}
	} else {
		LightweightTypeReference declarationAsList = declaration.tryConvertToListType();
		outerVisit(declarationAsList, reference);
	}
}
 
Example 9
Source File: AbstractTypeReferencePairWalker.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void doVisitParameterizedTypeReference(ParameterizedTypeReference reference, ParameterizedTypeReference declaration) {
	JvmType type = declaration.getType();
	if (type instanceof JvmTypeParameter) {
		if (type != reference.getType() && shouldProcess((JvmTypeParameter) type)) {
			JvmTypeParameter typeParameter = (JvmTypeParameter) type;
			processTypeParameter(typeParameter, reference);
		}
	} else if (type instanceof JvmTypeParameterDeclarator
			&& !((JvmTypeParameterDeclarator) type).getTypeParameters().isEmpty()
			&& !declaration.getTypeArguments().isEmpty()) {
		doVisitMatchingTypeParameters(reference, declaration);
	}
}
 
Example 10
Source File: AbstractTypeReferencePairWalker.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected void doVisitMatchingTypeParameters(ParameterizedTypeReference reference,
		ParameterizedTypeReference declaration) {
	Map<JvmTypeParameter, LightweightMergedBoundTypeArgument> actualMapping = getTypeParameterMapping(reference);
	TypeParameterSubstitutor<?> actualSubstitutor = createTypeParameterSubstitutor(actualMapping);
	Map<JvmTypeParameter, LightweightMergedBoundTypeArgument> declaredMapping = getTypeParameterMapping(declaration);
	TypeParameterSubstitutor<?> declaredSubstitutor = createTypeParameterSubstitutor(declaredMapping);
	Set<JvmTypeParameter> actualBoundParameters = actualMapping.keySet();
	Set<JvmTypeParameter> visited = Sets.newHashSet();
	outer: for (JvmTypeParameter actualBoundParameter : actualBoundParameters) {
		if (visited.add(actualBoundParameter)) {
			LightweightMergedBoundTypeArgument declaredBoundArgument = declaredMapping.get(actualBoundParameter);
			while(declaredBoundArgument == null && actualBoundParameter != null) {
				actualBoundParameter = findMappedParameter(actualBoundParameter, actualMapping, visited);
				if (actualBoundParameter == null)
					continue outer;
				declaredBoundArgument = declaredMapping.get(actualBoundParameter);
			}
			if (declaredBoundArgument != null) {
				LightweightTypeReference declaredTypeReference = declaredBoundArgument.getTypeReference();
				JvmType declaredType = declaredTypeReference.getType();
				if (declaredType instanceof JvmTypeParameter) {
					JvmTypeParameter declaredTypeParameter = (JvmTypeParameter) declaredType;
					if (!shouldProcessInContextOf(declaredTypeParameter, actualBoundParameters, visited))
						continue;
					declaredTypeReference = declaredSubstitutor.substitute(declaredTypeReference);
				}
				LightweightTypeReference actual = actualSubstitutor.substitute(actualMapping.get(actualBoundParameter).getTypeReference());
				if (!actual.isResolved() || !declaredTypeReference.isResolved() || !Strings.equal(actual.getIdentifier(), declaredTypeReference.getIdentifier())) {
					if (reference.getType() != actual.getType() 
							|| declaredTypeReference.getType() != declaration.getType() 
							|| !reference.getIdentifier().equals(actual.getIdentifier())
							|| !declaredTypeReference.getIdentifier().equals(declaration.getIdentifier())) {
						outerVisit(declaredTypeReference, actual, declaration, VarianceInfo.INVARIANT, VarianceInfo.INVARIANT);
					}
				}
			}
		}
	}
}
 
Example 11
Source File: AbstractTypeReferencePairWalker.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void doVisitArrayTypeReference(ArrayTypeReference reference, ParameterizedTypeReference declaration) {
	JvmType type = declaration.getType();
	if (type instanceof JvmTypeParameter) {
		if (shouldProcess((JvmTypeParameter) type)) {
			JvmTypeParameter typeParameter = (JvmTypeParameter) type;
			processTypeParameter(typeParameter, reference);
		}
	}
}
 
Example 12
Source File: ExtensionScopeHelper.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected Boolean doVisitParameterizedTypeReference(ParameterizedTypeReference reference) {
	if (reference.isResolved()) {
		return true;
	}
	if (reference.getOwner().getDeclaredTypeParameters().contains(reference.getType())) {
		return true;
	}
	if (!visit(reference.getTypeArguments())) {
		return false;
	}
	return !(reference.getType() instanceof JvmTypeParameter);
}
 
Example 13
Source File: MockTypeParameterSubstitutor.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public LightweightTypeReference doVisitParameterizedTypeReference(final ParameterizedTypeReference reference, final Set<JvmTypeParameter> visiting) {
  final JvmType type = reference.getType();
  if ((type instanceof JvmTypeParameter)) {
    boolean _add = visiting.add(((JvmTypeParameter)type));
    boolean _not = (!_add);
    if (_not) {
      return null;
    }
    try {
      final LightweightMergedBoundTypeArgument mappedReference = this.getTypeParameterMapping().get(type);
      if ((mappedReference != null)) {
        return mappedReference.getTypeReference().<Set<JvmTypeParameter>, LightweightTypeReference>accept(this, visiting);
      } else {
        ITypeReferenceOwner _owner = this.getOwner();
        Object _object = new Object();
        final SimpleUnboundTypeReference result = new SimpleUnboundTypeReference(_owner, ((JvmTypeParameter)type), _object);
        Map<JvmTypeParameter, LightweightMergedBoundTypeArgument> _typeParameterMapping = this.getTypeParameterMapping();
        LightweightMergedBoundTypeArgument _lightweightMergedBoundTypeArgument = new LightweightMergedBoundTypeArgument(result, VarianceInfo.INVARIANT);
        _typeParameterMapping.put(((JvmTypeParameter)type), _lightweightMergedBoundTypeArgument);
        return result;
      }
    } finally {
      visiting.remove(type);
    }
  }
  return super.doVisitParameterizedTypeReference(reference, visiting);
}
 
Example 14
Source File: LocalClassAwareTypeNames.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void doVisitParameterizedTypeReference(ParameterizedTypeReference reference, StringBuilder param) {
	JvmType type = reference.getType();
	if (type instanceof JvmDeclaredType) {
		boolean local = ((JvmDeclaredType) type).isLocal();
		if (local) {
			param.append("new ");
			Iterables.getLast(reference.getSuperTypes()).accept(this, param);
			param.append("(){}");
			return;
		}
	}
	super.doVisitParameterizedTypeReference(reference, param);
}
 
Example 15
Source File: RawTypeConformanceComputer.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
private int internalGetPrimitiveKind(ParameterizedTypeReference typeReference) {
	JvmType type = typeReference.getType();
	EClass eClass = type.eClass();
	if (eClass == TypesPackage.Literals.JVM_PRIMITIVE_TYPE) {
		if (type.eIsProxy())
			return PRIMITIVE_NONE;
		String name = type.getSimpleName();
		switch (name.length()) {
			case 3:
				if ("int".equals(name)) {
					return PRIMITIVE_INT;
				}
				break;
			case 4:
				if ("long".equals(name)) {
					return PRIMITIVE_LONG;
				} else if ("char".equals(name)) {
					return PRIMITIVE_CHAR;
				} else if ("byte".equals(name)) {
					return PRIMITIVE_BYTE;
				}
				break;
			case 5:
				if ("short".equals(name)) {
					return PRIMITIVE_SHORT;
				} else if ("float".equals(name)) {
					return PRIMITIVE_FLOAT;
				}
				break;
			case 6:
				if ("double".equals(name)) {
					return PRIMITIVE_DOUBLE;
				}
				break;
			case 7:
				if ("boolean".equals(name)) {
					return PRIMITIVE_BOOLEAN;
				}
				break;
		}
	} else if (eClass == TypesPackage.Literals.JVM_VOID) {
		if (type.eIsProxy())
			return PRIMITIVE_NONE;
		return PRIMITIVE_VOID;
	}
	return PRIMITIVE_NONE;
}
 
Example 16
Source File: ExpectationTypeParameterHintCollector.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void doVisitUnboundTypeReference(UnboundTypeReference reference,
		ParameterizedTypeReference declaration) {
	boolean constraintSeen = false;
	boolean constraintsMatch = true;
	boolean othersSeen = false;
	boolean declarationMatches = getExpectedVariance() != VarianceInfo.OUT;
	if (reference.getTypeParameter() != declaration.getType()) {
		List<LightweightBoundTypeArgument> hints = reference.getAllHints();
		for(int i = 0; i < hints.size(); i++) {
			LightweightBoundTypeArgument hint = hints.get(i);
			if (hint.getSource() == BoundTypeArgumentSource.CONSTRAINT) {
				constraintSeen = true;
				outerVisit(hint.getTypeReference(), declaration, hint.getSource(), hint.getDeclaredVariance(), hint.getActualVariance());
				if (constraintsMatch && !hint.getTypeReference().isAssignableFrom(declaration)) {
					constraintsMatch = false;
				}
			} else {
				othersSeen = true;
				// we don't break the list traversal here since we want to do the paired outerVisit for all constraints
				if (declarationMatches) {
					if (hint.getActualVariance() == VarianceInfo.OUT && hint.getDeclaredVariance() == VarianceInfo.OUT && 
							(hint.getSource() == BoundTypeArgumentSource.INFERRED || hint.getSource() == BoundTypeArgumentSource.INFERRED_EXPECTATION || hint.getSource() == BoundTypeArgumentSource.INFERRED_LATER)) {
						if (!declaration.isAssignableFrom(hint.getTypeReference())) {
							declarationMatches = false;
						}
					} else {
						declarationMatches = false;
					}
				}
			}
		}
	} else {
		if (getOwner().getDeclaredTypeParameters().contains(reference.getTypeParameter())) {
			reference.acceptHint(declaration, BoundTypeArgumentSource.RESOLVED, this, VarianceInfo.INVARIANT, VarianceInfo.INVARIANT);
			return;
		}
	}
	if (constraintSeen && constraintsMatch && !othersSeen) {
		reference.acceptHint(declaration, BoundTypeArgumentSource.RESOLVED, this, VarianceInfo.INVARIANT, VarianceInfo.INVARIANT);
	} else if (!constraintSeen && !reference.internalIsResolved() && declaration.isResolved() && !getOwner().isResolved(reference.getHandle()) && reference.canResolveTo(declaration)) {
		reference.acceptHint(declaration, BoundTypeArgumentSource.RESOLVED, this, VarianceInfo.INVARIANT, VarianceInfo.INVARIANT);
	} else if (othersSeen && declarationMatches) {
		reference.acceptHint(declaration, BoundTypeArgumentSource.INFERRED, this, VarianceInfo.INVARIANT, VarianceInfo.INVARIANT);
	} else {
		reference.tryResolve();
		if (reference.internalIsResolved()) {
			outerVisit(reference, declaration);
		} else {
			addHint(reference, declaration);
		}
	}
}