@Override protected Boolean doVisitTypeReference(LightweightTypeReference reference) { return reference.isResolved(); }
@Override public boolean isResolved() { return component.isResolved(); }
public boolean isOwnedBy(ITypeReferenceOwner owner) { if (isResolved()) { return true; } return owner == getOwner(); }
@Override public boolean isResolved() { if (internalGetResolvedTo() != null) { return resolvedTo.isResolved(); } return false; }
@Override public boolean isResolved() { return super.isResolved() && outer.isResolved(); }
@Override public boolean isResolved() { return super.isResolved() && outer.isResolved(); }
public void addComponent(LightweightTypeReference component) { if (component == null) { throw new NullPointerException("component may not be null"); } if (!component.isOwnedBy(getOwner())) { throw new NullPointerException("component is not valid in current context"); } if (components == null) components = Lists.newArrayListWithCapacity(2); components.add(component); resolved = resolved && component.isResolved(); }
/** Replies if the type candidate is a proxy (unresolved type) or a subtype of the given super type. * * @param candidate the type to test. * @param jvmSuperType the expected JVM super-type. * @param sarlSuperType the expected SARL super-type. * @return <code>true</code> if the candidate is a sub-type of the super-type. */ public boolean isProxyOrSubTypeOf(LightweightTypeReference candidate, Class<?> jvmSuperType, Class<? extends XtendTypeDeclaration> sarlSuperType) { if (!candidate.isResolved()) { return true; } return isSubTypeOf(candidate, jvmSuperType, sarlSuperType); }
public void addTypeArgument(LightweightTypeReference argument) { if (argument == null) { throw new NullPointerException("argument may not be null"); } if (!argument.isOwnedBy(getOwner())) { throw new IllegalArgumentException("argument is not valid in current context"); } if (typeArguments == null) typeArguments = Lists.newArrayListWithCapacity(2); typeArguments.add(argument); resolved = resolved && argument.isResolved(); }
public void addParameterType(LightweightTypeReference parameterType) { if (parameterType == null) { throw new NullPointerException("parameterType may not be null"); } if (!parameterType.isOwnedBy(getOwner())) { throw new NullPointerException("parameterType is not valid in current context"); } if (parameterTypes == null) parameterTypes = Lists.newArrayListWithCapacity(2); parameterTypes.add(parameterType); resolved = resolved && parameterType.isResolved(); }
protected void addIdentifier(LightweightTypeReference type, Set<String> allNames, Set<String> allBoundNames) { if (type instanceof UnboundTypeReference && !type.isResolved()) { allNames.add(((UnboundTypeReference) type).getHandle().toString()); } else { String identifier = type.getJavaIdentifier(); allNames.add(identifier); allBoundNames.add(identifier); } }
public void setReturnType(LightweightTypeReference returnType) { if (returnType == null) { throw new NullPointerException("returnType may not be null"); } if (!returnType.isOwnedBy(getOwner())) { throw new NullPointerException("returnType is not valid in current context"); } this.returnType = returnType; resolved = resolved && returnType.isResolved(); }
protected String getIdentifier(LightweightTypeReference type) { if (type instanceof UnboundTypeReference && !type.isResolved()) return ((UnboundTypeReference) type).getHandle().toString(); return type.getJavaIdentifier(); }
/** * If the expected type is a subtype of {@link Map}, the resolved super type is returned. * This allows to query for the type arguments that are available on the expectation. */ protected LightweightTypeReference getMapExpectation(LightweightTypeReference expectation) { if (expectation != null && expectation.isResolved()) { LightweightTypeReference result = expectation.getSuperType(Map.class); if (result != null && result.getTypeArguments().size() == 2) { return result; } } return null; }
/** * Implements fall-back strategy. If the expected type of a collection literal does not match the actual type, but the expected element * types would match the actual element type, the collection literal will be successfully typed according to the expectation. */ protected boolean matchesExpectation(LightweightTypeReference elementType, LightweightTypeReference expectation) { return expectation != null && expectation.isResolved() && !expectation.isWildcard() && expectation.isAssignableFrom(elementType); }
public void addUpperBound(LightweightTypeReference upperBound) { if (upperBound == null) { throw new NullPointerException("upperBound may not be null"); } if (!upperBound.isOwnedBy(getOwner())) { throw new IllegalArgumentException("upperBound is not valid in current context"); } if (upperBound instanceof WildcardTypeReference) { throw new IllegalArgumentException("Wildcards are not supported as upper bounds"); } if (upperBound.isPrimitive() || upperBound.isPrimitiveVoid()) { throw new IllegalArgumentException("Constraints may not be primitives"); } if (upperBounds == null) upperBounds = Lists.newArrayListWithCapacity(2); upperBounds.add(upperBound); resolved = resolved && upperBound.isResolved(); }
public void setLowerBound(LightweightTypeReference lowerBound) { if (lowerBound == null) { throw new NullPointerException("lowerBound may not be null"); } if (!lowerBound.isOwnedBy(getOwner())) { throw new IllegalArgumentException("lowerBound is not valid in current context"); } if (lowerBound instanceof WildcardTypeReference) { throw new IllegalArgumentException("Wildcards are not supported as lower bounds"); } if (lowerBound.isPrimitive() || lowerBound.isPrimitiveVoid()) { throw new IllegalArgumentException("Constraints may not be primitives"); } if (this.lowerBound != null && this.lowerBound != lowerBound) { throw new IllegalStateException("only one lower bound is supported"); } this.lowerBound = lowerBound; resolved = resolved && lowerBound.isResolved(); }
public JvmOperation findImplementingOperation(LightweightTypeReference functionType) { // avoid to trigger resolution of currently unbound type arguments // since the computation of this' lambdas type may enhance the information // about the given unbound type if (functionType.getKind() == LightweightTypeReference.KIND_UNBOUND_TYPE_REFERENCE && !functionType.isResolved()) { JvmOperation result = findImplementingOperation((UnboundTypeReference)functionType); if (result != null) { return result; } } List<JvmType> rawTypes = functionType.getRawTypes(); JvmOperation result = findImplementingOperation(rawTypes); return result; }
@Override protected List<JvmType> doVisitArrayTypeReference(ArrayTypeReference reference, ResourceSet resourceSet) { LightweightTypeReference componentType = reference.getComponentType(); List<JvmType> result; if (!componentType.isResolved()) { result = createObjectReference(resourceSet); } else { List<JvmType> rawComponentTypes = componentType.accept(this, resourceSet); result = Lists.newArrayListWithCapacity(rawComponentTypes.size()); for(JvmType rawComponentType: rawComponentTypes) { if (!rawComponentType.eIsProxy() && rawComponentType instanceof JvmComponentType) { JvmArrayType arrayType = ((JvmComponentType) rawComponentType).getArrayType(); if (arrayType == null) { arrayType = factory.createJvmArrayType(); arrayType.setComponentType((JvmComponentType) rawComponentType); } result.add(arrayType); } } } return result; }
protected boolean isExpectedType(LightweightTypeReference expectation, Class<?> clazz) { if (expectation != null) { if (expectation.isResolved() && isSubtypeButNotSynonym(expectation, clazz)) { return true; } if (expectation instanceof UnboundTypeReference) { if (expectation.getOwner().newParameterizedTypeReference(((UnboundTypeReference) expectation).getTypeParameter()).isSubtypeOf(clazz)) { return true; } List<LightweightBoundTypeArgument> hints = ((UnboundTypeReference) expectation).getAllHints(); for(LightweightBoundTypeArgument hint: hints) { LightweightTypeReference hintReference = hint.getTypeReference(); if (hintReference != null && isSubtypeButNotSynonym(hintReference, clazz)) { return true; } } } else if (expectation instanceof ParameterizedTypeReference) { return isSubtypeButNotSynonym(expectation, clazz); } } return false; }