Java Code Examples for org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference#copyInto()

The following examples show how to use org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference#copyInto() . 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: FeatureLinkingCandidate.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
protected void applyImplicitReceiver() {
	if (!isStatic()) {
		XExpression implicitReceiver = getImplicitReceiver();
		if (implicitReceiver != null) {
			ResolvedTypes resolvedTypes = getState().getResolvedTypes();
			LightweightTypeReference receiverType = getImplicitReceiverType();
			if (receiverType == null) {
				throw new IllegalStateException("Cannot determine the receiver's type");
			}
			LightweightTypeReference expectedReceiverType = new FeatureLinkHelper().getExpectedReceiverType(getFeature(), receiverType);
			if (expectedReceiverType != null)
				expectedReceiverType = expectedReceiverType.copyInto(resolvedTypes.getReferenceOwner());
			if (receiverType.isSynonym()) {
				receiverType = receiverType.getMultiTypeComponents().get(0);
			}
			TypeExpectation expectation = new TypeExpectation(expectedReceiverType, getState(), false);
			resolvedTypes.acceptType(implicitReceiver, expectation, receiverType.copyInto(resolvedTypes.getReferenceOwner()), false, ConformanceFlags.UNCHECKED);
			if (implicitReceiver instanceof XAbstractFeatureCall) {
				new ImplicitReceiver(getFeatureCall(), (XAbstractFeatureCall) implicitReceiver, getState()).applyToComputationState();
			} else {
				throw new IllegalStateException("unexpected implicit receiver, was: " + implicitReceiver);
			}
		}
	}
}
 
Example 2
Source File: UnboundTypeParameterPreservingSubstitutor.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Override
/* @Nullable */
protected LightweightTypeReference getBoundTypeArgument(ParameterizedTypeReference reference, JvmTypeParameter type, Set<JvmTypeParameter> visiting) {
	LightweightMergedBoundTypeArgument boundTypeArgument = getTypeParameterMapping().get(type);
	if (boundTypeArgument != null) {
		LightweightTypeReference boundReference = boundTypeArgument.getTypeReference();
		if (boundReference != null && reference != boundReference) {
			if (boundReference instanceof UnboundTypeReference)
				return boundReference.copyInto(getOwner());
			JvmType boundType = boundReference.getType();
			if (boundType != type) {
				if (visiting.add(type)) {
					try {
						LightweightTypeReference result = boundReference.accept(this, visiting);
						return result;
					} finally {
						visiting.remove(type);
					}
				} else {
					return reference;
				}
			} 
		}
	}
	return null;
}
 
Example 3
Source File: TypeComputationStateWithExpectation.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected AbstractTypeExpectation createTypeExpectation(/* @Nullable */ LightweightTypeReference expectedType, AbstractTypeComputationState actualState, boolean returnType) {
	AbstractTypeExpectation result = null;
	if (expectedType != null) {
		LightweightTypeReference copied = expectedType.copyInto(actualState.getReferenceOwner());
		result = new TypeExpectation(copied, actualState, returnType);
	} else {
		result = new NoExpectation(actualState, returnType);
	}
	return result;
}
 
Example 4
Source File: TypeComputationStateWithRootExpectation.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected AbstractTypeExpectation createTypeExpectation(/* @Nullable */ LightweightTypeReference expectedType, AbstractTypeComputationState actualState, boolean returnType) {
	LightweightTypeReference type = expectedType != null ? expectedType.copyInto(actualState.getReferenceOwner()) : null;
	AbstractTypeExpectation result;
	if (type != null) {
		result = returnType ? new TypeExpectation(type, actualState, returnType) : new RootTypeExpectation(type, actualState);
	} else {
		result = returnType ? new NoExpectation(actualState, returnType) : new RootNoExpectation(actualState, true);
	}
	return result;
}
 
Example 5
Source File: ResolvedImplicitReceiver.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void applyToComputationState() {
	ResolvedTypes resolvedTypes = getState().getResolvedTypes();
	
	LightweightTypeReference actualType = resolvedTypes.getActualType(getFeature());
	if (actualType == null)
		throw new IllegalStateException("Cannot determine actual type of already resolved implicit receiver");
	LightweightTypeReference expectedReceiverType = new FeatureLinkHelper().getExpectedReceiverType(getOwner().getFeature(), actualType);
	if (expectedReceiverType != null)
		expectedReceiverType = expectedReceiverType.copyInto(resolvedTypes.getReferenceOwner());
	TypeExpectation expectation = new TypeExpectation(expectedReceiverType, getState(), false);
	resolvedTypes.acceptType(getFeatureCall(), expectation, actualType.copyInto(resolvedTypes.getReferenceOwner()), false, ConformanceFlags.UNCHECKED);
	super.applyToComputationState();
}
 
Example 6
Source File: StackedResolvedTypes.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected TypeData prepareMerge(TypeData typeData, ITypeReferenceOwner owner) {
	LightweightTypeReference typeReference = typeData.getActualType();
	if (typeData.isOwnedBy(owner) && !(typeReference instanceof UnboundTypeReference))
		return typeData;
	if (typeReference instanceof UnboundTypeReference && super.isResolved(((UnboundTypeReference) typeReference).getHandle())) {
		typeReference = typeReference.getUpperBoundSubstitute();
	}
	return new TypeData(typeData.getExpression(), typeData.getExpectation().copyInto(owner), typeReference.copyInto(owner), typeData.getConformanceFlags(), typeData.isReturnType());
}
 
Example 7
Source File: AbstractLinkingCandidate.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected AbstractTypeExpectation createTypeExpectation(/* @Nullable */ LightweightTypeReference expectedType,
		AbstractTypeComputationState actualState, boolean returnType, int flags) {
	AbstractTypeExpectation result = null;
	if (expectedType != null) {
		LightweightTypeReference copied = expectedType.copyInto(actualState.getReferenceOwner());
		result = new ObservableTypeExpectation(copied, actualState, returnType, flags);
	} else {
		result = new NoExpectation(actualState, returnType);
	}
	return result;
}
 
Example 8
Source File: AbstractLinkingCandidate.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public ObservableTypeExpectation copyInto(ITypeReferenceOwner referenceOwner) {
	LightweightTypeReference expectedType = getExpectedType();
	if (expectedType == null || expectedType.isOwnedBy(referenceOwner))
		return this;
	return new ObservableTypeExpectation(expectedType.copyInto(referenceOwner), getState(), isReturnType(), flags);
}
 
Example 9
Source File: RootExpressionTypeComputationState.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected AbstractTypeExpectation createTypeExpectation(/* @Nullable */ LightweightTypeReference expectedType, AbstractTypeComputationState actualState, boolean voidAllowed, boolean returnType) {
	AbstractTypeExpectation result = null;
	if (expectedType != null) {
		LightweightTypeReference copied = expectedType.copyInto(actualState.getReferenceOwner());
		result = new RootTypeExpectation(copied, actualState);
	} else if (returnType) {
		result = new PendingRootExpectation(actualState, this, voidAllowed);
	} else {
		result = new RootNoExpectation(actualState, voidAllowed);
	}
	return result;
}
 
Example 10
Source File: FeatureLinkingCandidate.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected void resolveKnownArgumentType(XExpression argument, LightweightTypeReference knownType,
		/* @Nullable */ LightweightTypeReference declaredType, ITypeComputationState argumentState) {
	if (!(argumentState instanceof AbstractLinkingCandidate.ArgumentTypeComputationState))
		throw new IllegalArgumentException("argumentState was " + argumentState);
	AbstractLinkingCandidate<?>.ArgumentTypeComputationState castedArgumentState = (AbstractLinkingCandidate<?>.ArgumentTypeComputationState) argumentState;
	ResolvedTypes resolvedTypes = getState().getResolvedTypes();
	LightweightTypeReference copiedDeclaredType = declaredType != null ? declaredType.copyInto(resolvedTypes.getReferenceOwner()) : null;
	TypeExpectation expectation = new TypeExpectation(copiedDeclaredType, castedArgumentState, false);
	LightweightTypeReference copiedReceiverType = knownType.copyInto(resolvedTypes.getReferenceOwner());
	// TODO should we use the result of #acceptType?
	int defaultFlags = castedArgumentState.getDefaultFlags();
	resolvedTypes.acceptType(argument, expectation, copiedReceiverType, false, ConformanceFlags.UNCHECKED | defaultFlags);
	if (copiedDeclaredType != null)
		resolveAgainstActualType(copiedDeclaredType, copiedReceiverType, castedArgumentState);
}
 
Example 11
Source File: ResolvedFeature.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected void resolveKnownArgumentType(XExpression argument, LightweightTypeReference knownType,
		/* @Nullable */ LightweightTypeReference declaredType, ITypeComputationState argumentState) {
	if (!(argumentState instanceof AbstractTypeComputationState))
		throw new IllegalArgumentException("argumentState was " + argumentState);
	AbstractTypeComputationState castedArgumentState = (AbstractTypeComputationState) argumentState;
	ResolvedTypes resolvedTypes = getState().getResolvedTypes();
	LightweightTypeReference copiedDeclaredType = declaredType != null ? declaredType.copyInto(resolvedTypes.getReferenceOwner()) : null;
	TypeExpectation expectation = new TypeExpectation(copiedDeclaredType, castedArgumentState, false);
	LightweightTypeReference copiedReceiverType = knownType.copyInto(resolvedTypes.getReferenceOwner());
	// TODO should we use the result of #acceptType?
	resolvedTypes.acceptType(argument, expectation, copiedReceiverType, false, ConformanceFlags.UNCHECKED);
	if (copiedDeclaredType != null)
		resolveAgainstActualType(copiedDeclaredType, copiedReceiverType, castedArgumentState);
}
 
Example 12
Source File: ResolvedTypes.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
protected LightweightTypeReference toOwnedReference(/* @Nullable */ LightweightTypeReference result) {
	return result != null ? result.copyInto(getReferenceOwner()) : null;
}
 
Example 13
Source File: TypeParameterSubstitutor.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
protected LightweightTypeReference copy(LightweightTypeReference reference) {
	return reference.copyInto(getOwner());
}