org.eclipse.xtext.xbase.typesystem.computation.ILinkingCandidate Java Examples
The following examples show how to use
org.eclipse.xtext.xbase.typesystem.computation.ILinkingCandidate.
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: SARLTypeComputer.java From sarl with Apache License 2.0 | 6 votes |
/** Replies if ambiguity could be removed for the given feature. * * @param candidate the candidate. * @return {@code true} if ambiguity could be removed. */ @SuppressWarnings({"checkstyle:npathcomplexity", "checkstyle:cyclomaticcomplexity"}) protected boolean isIgnorableCallToFeature(ILinkingCandidate candidate) { final JvmIdentifiableElement feature = candidate.getFeature(); // // @Deprecated // if (feature instanceof JvmOperation) { JvmAnnotationTarget target = (JvmOperation) feature; JvmAnnotationReference reference = this.annotationLookup.findAnnotation(target, Deprecated.class); if (reference == null) { do { target = EcoreUtil2.getContainerOfType(target.eContainer(), JvmAnnotationTarget.class); if (target != null) { reference = this.annotationLookup.findAnnotation(target, Deprecated.class); } } while (reference == null && target != null); } if (reference != null) { return true; } } return false; }
Example #2
Source File: ElementIssueProvider.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
protected void synthesizeIssuesForFollowUpErrors(Resource resource, List<Issue> result) { List<EObject> contents = resource.getContents(); if (!contents.isEmpty()) { IResolvedTypes resolvedTypes = typeResolver.resolveTypes(contents.get(0)); for(ILinkingCandidate linkingCandidate: resolvedTypes.getFollowUpErrors()) { XExpression expression = linkingCandidate.getExpression(); IssueImpl issue = new Issue.IssueImpl(); issue.setUriToProblem(EcoreUtil.getURI(linkingCandidate.getExpression())); if (expression instanceof XAbstractFeatureCall) issue.setMessage(((XAbstractFeatureCall) expression).getConcreteSyntaxFeatureName() + " cannot be resolved"); else { List<INode> nodes = NodeModelUtils.findNodesForFeature(expression, XbasePackage.Literals.XCONSTRUCTOR_CALL__CONSTRUCTOR); if (nodes.size() >= 1) { issue.setMessage(nodes.get(0).getText() + " cannot be resolved"); } } result.add(issue); } } }
Example #3
Source File: SuspiciouslyOverloadedCandidate.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@Override public ILinkingCandidate getPreferredCandidate(ILinkingCandidate other) { if (other instanceof FeatureLinkingCandidate) { FeatureLinkingCandidate right = (FeatureLinkingCandidate) other; CandidateCompareResult candidateCompareResult = compareTo(right); switch(candidateCompareResult) { case EQUALLY_INVALID: throw new IllegalStateException(); case AMBIGUOUS: return chosenCandidate.createAmbiguousLinkingCandidate(right); case THIS: return this; case SUSPICIOUS_OTHER: default: return new SuspiciouslyOverloadedCandidate(right, rejectedCandidate); } } throw new IllegalArgumentException("other was " + other); }
Example #4
Source File: ResolvedTypes.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@Override public Collection<ILinkingCandidate> getFollowUpErrors() { Collection<?> rawResult = Collections2.filter(basicGetLinkingMap().values(), new Predicate<IApplicableCandidate>() { @Override public boolean apply(/* @Nullable */ IApplicableCandidate input) { if (input == null) throw new IllegalArgumentException(); if (input instanceof FollowUpError) return true; return false; } }); @SuppressWarnings("unchecked") // cast is safe Collection<ILinkingCandidate> result = (Collection<ILinkingCandidate>) rawResult; return result; }
Example #5
Source File: AbstractAmbiguousLinkingCandidate.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@Override public ILinkingCandidate getPreferredCandidate(ILinkingCandidate other) { if (other instanceof AbstractPendingLinkingCandidate) { AbstractPendingLinkingCandidate<?> right = (AbstractPendingLinkingCandidate<?>) other; CandidateCompareResult candidateCompareResult = compareTo(right); switch(candidateCompareResult) { case AMBIGUOUS: addCandidate(right); case EQUALLY_INVALID: case THIS: return this; default: return other; } } throw new IllegalArgumentException("other was " + other); }
Example #6
Source File: CastOperatorLinkingCandidate.java From sarl with Apache License 2.0 | 6 votes |
@Override public ILinkingCandidate getPreferredCandidate(ILinkingCandidate other) { final CastOperatorLinkingCandidate right = (CastOperatorLinkingCandidate) other; final CandidateCompareResult candidateCompareResult = compareTo(right); switch (candidateCompareResult) { case AMBIGUOUS: return createAmbiguousLinkingCandidate(right); case SUSPICIOUS_OTHER: return createSuspiciousLinkingCandidate(right); case EQUALLY_INVALID: case THIS: return this; case OTHER: return other; default: throw new IllegalStateException(); } }
Example #7
Source File: AbstractPendingLinkingCandidate.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
/** * Returns the best candidate considering the this and the given other candidate. * * The result is not necessarily this or the other, but may also be a third instance, * e.g. in order to disambiguate certain error conditions. */ @Override public ILinkingCandidate getPreferredCandidate(ILinkingCandidate other) { if (other instanceof AbstractPendingLinkingCandidate) { AbstractPendingLinkingCandidate<?> right = (AbstractPendingLinkingCandidate<?>) other; CandidateCompareResult candidateCompareResult = compareTo(right); switch(candidateCompareResult) { case AMBIGUOUS: return createAmbiguousLinkingCandidate(right); case SUSPICIOUS_OTHER: return createSuspiciousLinkingCandidate(right); case EQUALLY_INVALID: case THIS: return this; case OTHER: return other; } } throw new IllegalArgumentException("other was " + other); }
Example #8
Source File: TypeUsageCollector.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected void collectStaticImportsFrom(ILinkingCandidate linkingCandidate) { if (linkingCandidate == null) { return; } XExpression expression = linkingCandidate.getExpression(); collectStaticImportsFrom(expression, linkingCandidate.getFeature()); }
Example #9
Source File: TypeUsageCollector.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
private void collectStaticImportsFrom(final XAbstractFeatureCall featureCall, IAmbiguousLinkingCandidate optionalAmbiguousCandidate) { if (optionalAmbiguousCandidate != null) { for (ILinkingCandidate linkingCandidate : optionalAmbiguousCandidate.getAlternatives()) { collectStaticImportsFrom(linkingCandidate); } } else { collectStaticImportsFrom(featureCall, featureCall.getFeature()); } }
Example #10
Source File: EagerArgumentTypeComputer.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Override protected ILinkingCandidate getBestCandidate(List<? extends ILinkingCandidate> candidates) { for (ILinkingCandidate candidate : candidates) { if (candidate instanceof AbstractPendingLinkingCandidate) { ((AbstractPendingLinkingCandidate<?>) candidate).computeArgumentTypes(); } } return super.getBestCandidate(candidates); }
Example #11
Source File: RecomputingReentrantTypeResolver.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected void _assertEqualLinkingData(final ITypeLiteralLinkingCandidate left, final ILinkingCandidate right) { StringConcatenation _builder = new StringConcatenation(); _builder.append(left); _builder.append(" vs "); _builder.append(right); Assert.fail(_builder.toString()); }
Example #12
Source File: ResolvedTypes.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected List<LightweightTypeReference> doGetActualTypeArguments(XExpression expression) { if (expression == null || expression.eClass() == XbasePackage.Literals.XCLOSURE) { return Collections.emptyList(); } ILinkingCandidate result = (ILinkingCandidate) basicGetLinkingMap().get(expression); if (result != null) { return result.getTypeArguments(); } return Collections.emptyList(); }
Example #13
Source File: ResolvedTypes.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected JvmIdentifiableElement doGetLinkedFeature(/* @Nullable */ XExpression featureOrConstructorCall) { if (linkingMap == null || featureOrConstructorCall == null || featureOrConstructorCall.eClass() == XbasePackage.Literals.XCLOSURE) return null; IApplicableCandidate candidate = linkingMap.get(featureOrConstructorCall); if (candidate == null) return null; return ((ILinkingCandidate) candidate).getFeature(); }
Example #14
Source File: RecomputingReentrantTypeResolver.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected void _assertEqualLinkingData(final ILinkingCandidate left, final ITypeLiteralLinkingCandidate right) { StringConcatenation _builder = new StringConcatenation(); _builder.append(left); _builder.append(" vs "); _builder.append(right); Assert.fail(_builder.toString()); }
Example #15
Source File: RecomputingReentrantTypeResolver.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
public void doAssertEqualLinkingData(final ILinkingCandidate left, final ILinkingCandidate right) { try { this.assertEqualReferences("typeArguments", left.getTypeArguments(), right.getTypeArguments()); this.assertEqualReferences("syntacticTypeArguments", this.<List<LightweightTypeReference>>invokeAndCast(left, "getSyntacticTypeArguments"), this.<List<LightweightTypeReference>>invokeAndCast(right, "getSyntacticTypeArguments")); Assert.assertEquals("arguments", this._reflectExtensions.invoke(left, "getArguments"), this._reflectExtensions.invoke(right, "getArguments")); Assert.assertEquals("declaredTypeParameters", this._reflectExtensions.invoke(left, "getDeclaredTypeParameters"), this._reflectExtensions.invoke(right, "getDeclaredTypeParameters")); this.assertEqualMapping("typeParameterMapping", this.<Map<JvmTypeParameter, LightweightMergedBoundTypeArgument>>invokeAndCast(left, "getTypeParameterMapping"), this.<Map<JvmTypeParameter, LightweightMergedBoundTypeArgument>>invokeAndCast(right, "getTypeParameterMapping")); this.assertEqualMapping("declaratorParameterMapping", this.<Map<JvmTypeParameter, LightweightMergedBoundTypeArgument>>invokeAndCast(left, "getDeclaratorParameterMapping"), this.<Map<JvmTypeParameter, LightweightMergedBoundTypeArgument>>invokeAndCast(right, "getDeclaratorParameterMapping")); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example #16
Source File: RecomputingReentrantTypeResolver.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
public <T extends Object> T invokeAndCast(final ILinkingCandidate receiver, final String getter) { try { Object _invoke = this._reflectExtensions.invoke(receiver, getter); return ((T) _invoke); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example #17
Source File: AmbiguousFeatureLinkingCandidate.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Override protected String[] getDiagnosticData() { FeatureLinkingCandidate primaryCandidate = getPrimaryCandidate(); XAbstractFeatureCall expression = primaryCandidate.getExpression(); if (expression.isExplicitOperationCallOrBuilderSyntax()) { return null; } Set<String> data = Sets.newLinkedHashSet(); for (ILinkingCandidate candidate : getAlternatives()) { JvmIdentifiableElement feature = candidate.getFeature(); String simpleName = feature.getSimpleName(); data.add(simpleName + "()"); } return data.toArray(new String[data.size()]); }
Example #18
Source File: AmbiguousCastOperatorLinkingCandidate.java From sarl with Apache License 2.0 | 5 votes |
@Override protected String[] getDiagnosticData() { final Set<String> data = Sets.newLinkedHashSet(); for (final ILinkingCandidate candidate : getAlternatives()) { final JvmIdentifiableElement feature = candidate.getFeature(); final String simpleName = feature.getSimpleName(); data.add(simpleName + "()"); //$NON-NLS-1$ } return data.toArray(new String[data.size()]); }
Example #19
Source File: CompoundReentrantTypeResolver.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Override public Collection<ILinkingCandidate> getFollowUpErrors() { List<ILinkingCandidate> result = Lists.newArrayList(); for(IResolvedTypes delegate: this) { result.addAll(delegate.getFollowUpErrors()); } return result; }
Example #20
Source File: CastedExpressionTypeComputationState.java From sarl with Apache License 2.0 | 5 votes |
/** Create a candidate from the given description. * * @param cast the cast operator. * @param state the state * @param description the description of the cast linked operation. * @return the linking candidate. */ protected ILinkingCandidate createCandidate(SarlCastedExpression cast, ExpressionTypeComputationState state, IIdentifiableElementDescription description) { return new CastOperatorLinkingCandidate(cast, description, getSingleExpectation(state), state); }
Example #21
Source File: SARLTypeComputer.java From sarl with Apache License 2.0 | 5 votes |
@Override protected ILinkingCandidate getBestCandidate(List<? extends ILinkingCandidate> candidates) { // Implementation of ignorable features: // For example, this function is ignoring the deprecated features when a not-deprecated feature is available. if (candidates.size() == 1) { return candidates.get(0); } ILinkingCandidate preferredCandidateWithoutConstraint = null; ILinkingCandidate preferredCandidateWithConstraint = null; for (final ILinkingCandidate candidate : candidates) { if (preferredCandidateWithoutConstraint == null) { preferredCandidateWithoutConstraint = candidate; } else { preferredCandidateWithoutConstraint = preferredCandidateWithoutConstraint.getPreferredCandidate(candidate); } if (preferredCandidateWithConstraint == null) { if (!isIgnorableCallToFeature(candidate)) { preferredCandidateWithConstraint = candidate; } } else { final ILinkingCandidate preferredCandidate = preferredCandidateWithConstraint.getPreferredCandidate(candidate); if (!(preferredCandidate instanceof AmbiguousFeatureLinkingCandidate) || !isIgnorableCallToFeature(candidate)) { preferredCandidateWithConstraint = preferredCandidate; } } } if (preferredCandidateWithConstraint != null) { return preferredCandidateWithConstraint; } return preferredCandidateWithoutConstraint; }
Example #22
Source File: XtendHyperlinkHelper.java From xtext-xtend with Eclipse Public License 2.0 | 4 votes |
private void createMultipleLinks(XtextResource resource, INode crossRefNode, List<? extends ILinkingCandidate> alternatives, IHyperlinkAcceptor acceptor) { for (ILinkingCandidate alternative : alternatives) { createHyperlinksTo(resource, crossRefNode, alternative.getFeature(), acceptor); } }
Example #23
Source File: RecomputingReentrantTypeResolver.java From xtext-extras with Eclipse Public License 2.0 | 4 votes |
public void assertEqualLinkingData(final IApplicableCandidate left, final IApplicableCandidate right) { if (left instanceof ImplicitFirstArgument && right instanceof ImplicitFirstArgument) { _assertEqualLinkingData((ImplicitFirstArgument)left, (ImplicitFirstArgument)right); return; } else if (left instanceof ImplicitReceiver && right instanceof ImplicitReceiver) { _assertEqualLinkingData((ImplicitReceiver)left, (ImplicitReceiver)right); return; } else if (left instanceof ImplicitReceiver && right instanceof IFeatureLinkingCandidate) { _assertEqualLinkingData((ImplicitReceiver)left, (IFeatureLinkingCandidate)right); return; } else if (left instanceof ITypeLiteralLinkingCandidate && right instanceof ITypeLiteralLinkingCandidate) { _assertEqualLinkingData((ITypeLiteralLinkingCandidate)left, (ITypeLiteralLinkingCandidate)right); return; } else if (left instanceof TypeInsteadOfConstructorLinkingCandidate && right instanceof TypeInsteadOfConstructorLinkingCandidate) { _assertEqualLinkingData((TypeInsteadOfConstructorLinkingCandidate)left, (TypeInsteadOfConstructorLinkingCandidate)right); return; } else if (left instanceof TypeInsteadOfConstructorLinkingCandidate && right instanceof IConstructorLinkingCandidate) { _assertEqualLinkingData((TypeInsteadOfConstructorLinkingCandidate)left, (IConstructorLinkingCandidate)right); return; } else if (left instanceof ITypeLiteralLinkingCandidate && right instanceof ILinkingCandidate) { _assertEqualLinkingData((ITypeLiteralLinkingCandidate)left, (ILinkingCandidate)right); return; } else if (left instanceof IFeatureLinkingCandidate && right instanceof ImplicitReceiver) { _assertEqualLinkingData((IFeatureLinkingCandidate)left, (ImplicitReceiver)right); return; } else if (left instanceof IConstructorLinkingCandidate && right instanceof TypeInsteadOfConstructorLinkingCandidate) { _assertEqualLinkingData((IConstructorLinkingCandidate)left, (TypeInsteadOfConstructorLinkingCandidate)right); return; } else if (left instanceof IConstructorLinkingCandidate && right instanceof IConstructorLinkingCandidate) { _assertEqualLinkingData((IConstructorLinkingCandidate)left, (IConstructorLinkingCandidate)right); return; } else if (left instanceof IFeatureLinkingCandidate && right instanceof IFeatureLinkingCandidate) { _assertEqualLinkingData((IFeatureLinkingCandidate)left, (IFeatureLinkingCandidate)right); return; } else if (left instanceof ILinkingCandidate && right instanceof ITypeLiteralLinkingCandidate) { _assertEqualLinkingData((ILinkingCandidate)left, (ITypeLiteralLinkingCandidate)right); return; } else if (left instanceof IClosureCandidate && right instanceof IClosureCandidate) { _assertEqualLinkingData((IClosureCandidate)left, (IClosureCandidate)right); return; } else if (left != null && right != null) { _assertEqualLinkingData(left, right); return; } else { throw new IllegalArgumentException("Unhandled parameter types: " + Arrays.<Object>asList(left, right).toString()); } }
Example #24
Source File: RuntimeInjectorProviderWithReversedCandidates.java From xtext-xtend with Eclipse Public License 2.0 | 4 votes |
@Override protected ILinkingCandidate getBestCandidate(List<? extends ILinkingCandidate> candidates) { return super.getBestCandidate(ListExtensions.reverseView(candidates)); }
Example #25
Source File: CastOperatorLinkingCandidate.java From sarl with Apache License 2.0 | 4 votes |
@Override protected ILinkingCandidate createAmbiguousLinkingCandidate(AbstractPendingLinkingCandidate<?> second) { return new AmbiguousCastOperatorLinkingCandidate(this, second); }
Example #26
Source File: CastOperatorLinkingCandidate.java From sarl with Apache License 2.0 | 4 votes |
@Override protected ILinkingCandidate createSuspiciousLinkingCandidate(AbstractPendingLinkingCandidate<?> chosenCandidate) { return new SuspiciousOverloadedCastOperatorLinkingCandidate((CastOperatorLinkingCandidate) chosenCandidate, this); }
Example #27
Source File: CastedExpressionTypeComputationState.java From sarl with Apache License 2.0 | 4 votes |
/** 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 #28
Source File: SuspiciousOverloadedCastOperatorLinkingCandidate.java From sarl with Apache License 2.0 | 4 votes |
@Override public ILinkingCandidate getPreferredCandidate(ILinkingCandidate other) { return getChosenCandidate().getPreferredCandidate(other); }
Example #29
Source File: SARLTypeComputer.java From sarl with Apache License 2.0 | 4 votes |
/** Compute the type of a casted expression. * * @param cast the expression. * @param state the state of the type resolver. */ @SuppressWarnings("checkstyle:nestedifdepth") protected void _computeTypes(SarlCastedExpression cast, ITypeComputationState state) { if (state instanceof AbstractTypeComputationState) { final JvmTypeReference type = cast.getType(); if (type != null) { state.withNonVoidExpectation().computeTypes(cast.getTarget()); // Set the linked feature try { final AbstractTypeComputationState computationState = (AbstractTypeComputationState) state; final CastedExpressionTypeComputationState astate = new CastedExpressionTypeComputationState( cast, computationState, this.castOperationValidator); astate.resetFeature(cast); if (astate.isCastOperatorLinkingEnabled(cast)) { final List<? extends ILinkingCandidate> candidates = astate.getLinkingCandidates(cast); if (!candidates.isEmpty()) { final ILinkingCandidate best = getBestCandidate(candidates); if (best != null) { best.applyToModel(computationState.getResolvedTypes()); } } } } catch (Throwable exception) { final Throwable cause = Throwables.getRootCause(exception); state.addDiagnostic(new EObjectDiagnosticImpl( Severity.ERROR, IssueCodes.INTERNAL_ERROR, cause.getLocalizedMessage(), cast, null, -1, null)); } state.acceptActualType(state.getReferenceOwner().toLightweightTypeReference(type)); } else { state.computeTypes(cast.getTarget()); } } else { super._computeTypes(cast, state); } }
Example #30
Source File: ResolvedFeature.java From xtext-extras with Eclipse Public License 2.0 | 4 votes |
@Override public ILinkingCandidate getPreferredCandidate(ILinkingCandidate other) { return this; }