org.eclipse.xtext.xbase.typesystem.computation.ITypeComputationResult Java Examples

The following examples show how to use org.eclipse.xtext.xbase.typesystem.computation.ITypeComputationResult. 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: CompoundTypeComputationState.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public ITypeComputationResult computeTypes(/* @Nullable */ XExpression expression) {
	if (expression == null) {
		throw new IllegalArgumentException("XExpression may not be null");
	}
	StackedResolvedTypes resolvedTypes = components[0].doComputeTypes(expression);
	int flags = resolvedTypes.getConformanceFlags(expression, false);
	for(int i = 1; i < components.length; i++) {
		StackedResolvedTypes candidate = components[i].doComputeTypes(expression);
		int candidateFlags = candidate.getConformanceFlags(expression, false);
		int compareResult = compareFlags(flags, candidateFlags);
		if (compareResult == 1) {
			resolvedTypes = candidate;
			flags = candidateFlags;
		}
	}
	resolvedTypes.performMergeIntoParent();
	ResolutionBasedComputationResult result = new ResolutionBasedComputationResult(expression, resolvedTypes.getParent());
	return result;
}
 
Example #2
Source File: AbstractTypeComputationState.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public final ITypeComputationResult computeTypes(/* @Nullable */ XExpression expression) {
	resolvedTypes.checkCanceled();
	if (expression != null) {
		if (expression.eContainer() == null && expression.eResource() == null)
			throw new IllegalStateException("Dangling expression: " + expression);
		assert getResolvedTypes().doGetTypeData(expression) == null : "Expression was already resolved: " + expression;  
		ExpressionAwareStackedResolvedTypes stackedResolvedTypes = doComputeTypes(expression);
		stackedResolvedTypes.performMergeIntoParent();
		return new ResolutionBasedComputationResult(expression, resolvedTypes);
	} else {
		return new NoTypeResult(null, getReferenceOwner());
	}
}
 
Example #3
Source File: OperationBodyComputationState.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected ITypeComputationResult createNoTypeResult() {
	JvmOperation operation = (JvmOperation) getMember();
	LightweightTypeReference expectedType = ((LogicalContainerAwareReentrantTypeResolver)getResolver()).getReturnTypeOfOverriddenOperation(operation, resolvedTypes, getFeatureScopeSession());
	if (expectedType != null) {
		InferredTypeIndicator.resolveTo(operation.getReturnType(), expectedType.toJavaCompliantTypeReference());
	}
	return new NoTypeResult(getMember(), resolvedTypes.getReferenceOwner());
}
 
Example #4
Source File: ExpressionBasedRootTypeComputationState.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
@Override
protected ITypeComputationResult createNoTypeResult() {
	return new NoTypeResult(null, resolvedTypes.getReferenceOwner());
}
 
Example #5
Source File: ForwardingTypeComputationState.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public ITypeComputationResult computeTypes(/* @Nullable */ XExpression expression) {
	return delegate.computeTypes(expression);
}
 
Example #6
Source File: AbstractRootTypeComputationState.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
public ITypeComputationResult computeTypes() {
	XExpression rootExpression = getRootExpression();
	if (rootExpression == null)
		return createNoTypeResult();
	return computeTypes(rootExpression);
}
 
Example #7
Source File: ConstructorBodyComputationState.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
@Override
protected ITypeComputationResult createNoTypeResult() {
	return new NoTypeResult(getMember(), resolvedTypes.getReferenceOwner());
}
 
Example #8
Source File: AnnotationValueTypeComputationState.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
@Override
protected ITypeComputationResult createNoTypeResult() {
	return new NoTypeResult(annotationValue, resolvedTypes.getReferenceOwner());
}
 
Example #9
Source File: FieldTypeComputationState.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
@Override
protected ITypeComputationResult createNoTypeResult() {
	return new NoTypeResult(getMember(), resolvedTypes.getReferenceOwner());
}
 
Example #10
Source File: CastedExpressionTypeComputationState.java    From sarl with Apache License 2.0 4 votes vote down vote up
/** Compute the best candidates for the feature behind the cast operator.
 *
 * @param cast the cast operator.
 * @return the candidates.
 */
public List<? extends ILinkingCandidate> getLinkingCandidates(SarlCastedExpression cast) {
	// Prepare the type resolver.
	final StackedResolvedTypes demandComputedTypes = pushTypes();
	final AbstractTypeComputationState forked = withNonVoidExpectation(demandComputedTypes);
	final ForwardingResolvedTypes demandResolvedTypes = new ForwardingResolvedTypes() {
		@Override
		protected IResolvedTypes delegate() {
			return forked.getResolvedTypes();
		}

		@Override
		public LightweightTypeReference getActualType(XExpression expression) {
			final LightweightTypeReference type = super.getActualType(expression);
			if (type == null) {
				final ITypeComputationResult result = forked.computeTypes(expression);
				return result.getActualExpressionType();
			}
			return type;
		}
	};

	// Create the scope
	final IScope scope = getCastScopeSession().getScope(cast,
			// Must be the feature of the AbstractFeatureCall in order to enable the scoping for a function call.
			//XbasePackage.Literals.XABSTRACT_FEATURE_CALL__FEATURE,
			SarlPackage.Literals.SARL_CASTED_EXPRESSION__FEATURE,
			demandResolvedTypes);

	// Search for the features into the scope
	final LightweightTypeReference targetType = getReferenceOwner().toLightweightTypeReference(cast.getType());
	final List<ILinkingCandidate> resultList = Lists.newArrayList();
	final LightweightTypeReference expressionType = getStackedResolvedTypes().getActualType(cast.getTarget());
	final ISelector validator = this.candidateValidator.prepare(
			getParent(), targetType, expressionType);
	// FIXME: The call to getAllElements() is not efficient; find another way in order to be faster.
	for (final IEObjectDescription description : scope.getAllElements()) {
		final IIdentifiableElementDescription idesc = toIdentifiableDescription(description);
		if (validator.isCastOperatorCandidate(idesc)) {
			final ExpressionAwareStackedResolvedTypes descriptionResolvedTypes = pushTypes(cast);
			final ExpressionTypeComputationState descriptionState = createExpressionComputationState(cast, descriptionResolvedTypes);
			final ILinkingCandidate candidate = createCandidate(cast, descriptionState, idesc);
			if (candidate != null) {
				resultList.add(candidate);
			}
		}
	}

	return resultList;
}
 
Example #11
Source File: AbstractRootTypeComputationState.java    From xtext-extras with Eclipse Public License 2.0 votes vote down vote up
protected abstract ITypeComputationResult createNoTypeResult();