org.eclipse.xtext.xbase.scoping.batch.IIdentifiableElementDescription Java Examples
The following examples show how to use
org.eclipse.xtext.xbase.scoping.batch.IIdentifiableElementDescription.
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: ObjectAndPrimitiveBasedCastOperationCandidateSelector.java From sarl with Apache License 2.0 | 6 votes |
@Override public boolean isCastOperatorCandidate(IIdentifiableElementDescription description) { if (description instanceof ScopeProviderAccess.ErrorDescription || !description.isVisible()) { return false; } final JvmIdentifiableElement operatorFunction = description.getElementOrProxy(); if (!(operatorFunction instanceof JvmOperation)) { return false; } final JvmOperation executable = (JvmOperation) operatorFunction; final String objectTypeName = getValidClassSimpleName(executable.getSimpleName()); if (objectTypeName != null) { return validatePrototype(objectTypeName, executable); } final String primitiveTypeName = getValidPrimitiveSimpleName(executable.getSimpleName()); if (primitiveTypeName != null) { return validatePrototype(primitiveTypeName, executable); } return false; }
Example #2
Source File: AbstractTypeComputationState.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
protected IFeatureLinkingCandidate createCandidate(XAbstractFeatureCall featureCall, final StackedResolvedTypes demandComputedTypes, IIdentifiableElementDescription description) { if (description.getSyntacticReceiverType() != null) { return createCandidateWithReceiverType(featureCall, demandComputedTypes, description); } // pretty much the same constraints as in #createCandidateWithReceiverType ExpressionAwareStackedResolvedTypes resolvedTypes = this.resolvedTypes.pushTypes(featureCall); ExpressionTypeComputationState state = createExpressionComputationState(featureCall, resolvedTypes); if (description instanceof ScopeProviderAccess.ErrorDescription) { ScopeProviderAccess.ErrorDescription errorDescription = (ScopeProviderAccess.ErrorDescription) description; boolean followUpError = errorDescription.isFollowUpError(); if (followUpError) { return new FollowUpError(featureCall, state); } return new UnresolvableFeatureCall(featureCall, errorDescription.getNode(), description.getName().toString(), state); } else if (description.isTypeLiteral()) { return new TypeLiteralLinkingCandidate(featureCall, description, getSingleExpectation(state), state); } else { return new FeatureLinkingCandidate(featureCall, description, getSingleExpectation(state), state); } }
Example #3
Source File: XtendProposalProvider.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Override protected Predicate<IEObjectDescription> getFeatureDescriptionPredicate(ContentAssistContext contentAssistContext) { if (contentAssistContext.getPrefix().startsWith("_")) return super.getFeatureDescriptionPredicate(contentAssistContext); final Predicate<IEObjectDescription> delegate = super.getFeatureDescriptionPredicate(contentAssistContext); return new Predicate<IEObjectDescription>() { @Override public boolean apply(IEObjectDescription input) { boolean result = !input.getName().getFirstSegment().startsWith("_") && delegate.apply(input); if (result) { if (input instanceof IIdentifiableElementDescription) { IIdentifiableElementDescription casted = (IIdentifiableElementDescription) input; if (isDiscouragedExtension(casted)) { return false; } } } return result; } }; }
Example #4
Source File: XbaseIdeContentProposalPriorities.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@Override public int getCrossRefPriority(IEObjectDescription objectDesc, ContentAssistEntry entry) { if (entry != null) { if (objectDesc instanceof SimpleIdentifiableElementDescription) { if (!"this".equals(entry.getProposal()) && !"super".equals(entry.getProposal())) { return adjustPriority(entry, getCrossRefPriority() + 70); } } else if (objectDesc instanceof StaticFeatureDescriptionWithTypeLiteralReceiver) { return adjustPriority(entry, getCrossRefPriority() + 60); } else if (objectDesc instanceof IIdentifiableElementDescription) { JvmIdentifiableElement element = ((IIdentifiableElementDescription) objectDesc).getElementOrProxy(); if (element instanceof JvmField) { return adjustPriority(entry, getCrossRefPriority() + 50); } else if (element instanceof JvmExecutable) { return adjustPriority(entry, getCrossRefPriority() + 20); } } } return super.getCrossRefPriority(objectDesc, entry); }
Example #5
Source File: TypeLiteralLinkingCandidate.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
public TypeLiteralLinkingCandidate( XAbstractFeatureCall featureCall, IIdentifiableElementDescription description, ITypeExpectation expectation, final ExpressionTypeComputationState state) { super(featureCall, description, expectation, state, new TypeLiteralLinkingCandidateResolver(featureCall) { @Override protected IFeatureLinkingCandidate getLinkingCandidate(XExpression target) { return state.getResolvedTypes().getLinkingCandidate((XAbstractFeatureCall) target); } }); if (featureCall.isExplicitOperationCallOrBuilderSyntax()) { throw new IllegalArgumentException("Cannot be a type literal: " + String.valueOf(featureCall)); } this.helper = new TypeLiteralHelper(state); }
Example #6
Source File: XbaseReferenceProposalCreator.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
protected boolean isLongerThan(IIdentifiableElementDescription previous, IIdentifiableElementDescription next) { String previousName = nameConverter.toString(previous.getName()); String candidateName = nameConverter.toString(next.getName()); if (previousName.length() > candidateName.length()) { return true; } if (previousName.length() == candidateName.length()) { if (previous.getNumberOfParameters() >= 1) { return true; } } return false; }
Example #7
Source File: XbaseReferenceProposalCreator.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
protected void apply(IEObjectDescription description) { if (description instanceof IIdentifiableElementDescription) { IIdentifiableElementDescription featureDescription = (IIdentifiableElementDescription) description; kind.apply(featureDescription, this); } else { others.add(new SimpleIdentifiableElementDescription(description)); } }
Example #8
Source File: XbaseReferenceProposalCreator.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Override protected void apply(IIdentifiableElementDescription featureDescription, MultiNameDescriptions result) { JvmIdentifiableElement element = featureDescription.getElementOrProxy(); String firstSegment = featureDescription.getName().getFirstSegment(); if (element.getSimpleName().equals(firstSegment)) { result.others.add(featureDescription); } }
Example #9
Source File: XbaseReferenceProposalCreator.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Override protected void apply(IIdentifiableElementDescription featureDescription, MultiNameDescriptions result) { EObject feature = featureDescription.getEObjectOrProxy(); IIdentifiableElementDescription previous = (IIdentifiableElementDescription) result.descriptionsByEObject.get(feature); if (previous != null) { String previousName = result.nameConverter.toString(previous.getName()); String candidateName = result.nameConverter.toString(featureDescription.getName()); if (previousName.length() > candidateName.length() || (previousName.length() == candidateName.length() && previous.getNumberOfParameters() >= 1)) { result.descriptionsByEObject.put(feature, featureDescription); } } else { result.descriptionsByEObject.put(feature, featureDescription); } }
Example #10
Source File: XbaseProposalProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Override public boolean apply(IEObjectDescription input) { if (input instanceof IIdentifiableElementDescription) { final IIdentifiableElementDescription desc = (IIdentifiableElementDescription) input; if (!desc.isVisible() || !desc.isValidStaticState()) // || !desc.isValid()) return false; // filter operator method names from CA if (input.getName().getFirstSegment().startsWith("operator_")) { return operatorMapping.getOperator(input.getName()) == null; } return true; } return true; }
Example #11
Source File: XbaseIdeContentProposalProvider.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Override public boolean apply(final IEObjectDescription input) { if ((input instanceof IIdentifiableElementDescription)) { if (((!((IIdentifiableElementDescription)input).isVisible()) || (!((IIdentifiableElementDescription)input).isValidStaticState()))) { return false; } boolean _startsWith = ((IIdentifiableElementDescription)input).getName().getFirstSegment().startsWith("operator_"); if (_startsWith) { QualifiedName _operator = this.operatorMapping.getOperator(((IIdentifiableElementDescription)input).getName()); return (_operator == null); } } return true; }
Example #12
Source File: XbaseContentProposalPriorities.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Override public void adjustCrossReferencePriority(ICompletionProposal proposal, String prefix) { if (proposal instanceof ConfigurableCompletionProposal) { ConfigurableCompletionProposal configurableProposal = (ConfigurableCompletionProposal) proposal; Object desc = configurableProposal.getAdditionalData(XbaseProposalProvider.DESCRIPTION_KEY); if (desc instanceof SimpleIdentifiableElementDescription) { if (!"this".equals(configurableProposal.getReplacementString()) && !"super".equals(configurableProposal.getReplacementString())) { adjustPriority(proposal, prefix, 570); return; } } else if (desc instanceof StaticFeatureDescriptionWithTypeLiteralReceiver) { adjustPriority(proposal, prefix, 560); return; } else if (desc instanceof IIdentifiableElementDescription) { JvmIdentifiableElement identifiableElement = ((IIdentifiableElementDescription) desc).getElementOrProxy(); if (identifiableElement instanceof JvmField) { adjustPriority(proposal, prefix, 550); return; } else if (identifiableElement instanceof JvmExecutable) { adjustPriority(proposal, prefix, 520); return; } } } super.adjustCrossReferencePriority(proposal, prefix); }
Example #13
Source File: JvmModelReferenceUpdater.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
/** * Preserves the syntax of method calls if the target is refactored. * * @since 2.4 */ @Override protected RefTextEvaluator getRefTextEvaluator(final EObject referringElement, URI referringResourceURI, final EReference reference, int indexInList, EObject newTargetElement) { final ReferenceSyntax oldReferenceSyntax = getReferenceSyntax(referringElement, reference, indexInList); if (oldReferenceSyntax == null) return super.getRefTextEvaluator(referringElement, referringResourceURI, reference, indexInList, newTargetElement); return new RefTextEvaluator() { @Override public boolean isValid(IEObjectDescription newTarget) { IScope scope = linkingScopeProvider.getScope(referringElement, reference); IEObjectDescription element = scope.getSingleElement(newTarget.getName()); // TODO here we need to simulate linking with the new name instead of the old name if(element instanceof IIdentifiableElementDescription) { IIdentifiableElementDescription casted = (IIdentifiableElementDescription) element; if(!casted.isVisible() || !casted.isValidStaticState()) return false; } return element != null && element.getEObjectURI() != null && element.getEObjectURI().equals(newTarget.getEObjectURI()); } @Override public boolean isBetterThan(String newText, String currentText) { ReferenceSyntax newSyntax = getReferenceSyntax(newText); ReferenceSyntax currentSyntax = getReferenceSyntax(currentText); // prefer the one with the same syntax as before if (newSyntax == oldReferenceSyntax && currentSyntax != oldReferenceSyntax) return true; else if (newSyntax != oldReferenceSyntax && currentSyntax == oldReferenceSyntax) return false; else // in doubt shorter is better return newText.length() < currentText.length(); } }; }
Example #14
Source File: AbstractPendingLinkingCandidate.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected AbstractPendingLinkingCandidate( Expression expression, IIdentifiableElementDescription description, ITypeExpectation expectation, ExpressionTypeComputationState state, PendingLinkingCandidateResolver<Expression> pendingLinkingCandidateResolver) { super(expression, expectation, state); this.description = description; this.pendingLinkingCandidateResolver = pendingLinkingCandidateResolver; }
Example #15
Source File: AbstractPendingLinkingCandidate.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected AbstractPendingLinkingCandidate( Expression expression, IIdentifiableElementDescription description, ITypeExpectation expectation, ExpressionTypeComputationState state) { this(expression, description, expectation, state, new PendingLinkingCandidateResolver<Expression>(expression)); }
Example #16
Source File: FeatureLinkingCandidate.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected boolean isValidAssignmentName(IIdentifiableElementDescription description) { JvmIdentifiableElement candidate = description.getElementOrProxy(); if (candidate.eClass() == TypesPackage.Literals.JVM_OPERATION) { if (candidate.getSimpleName().equals(description.getName().getFirstSegment())) { return false; } else if (!candidate.getSimpleName().startsWith("set")) { return false; } } return true; }
Example #17
Source File: FeatureLinkingCandidate.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
public FeatureLinkingCandidate( XAbstractFeatureCall featureCall, IIdentifiableElementDescription description, ITypeExpectation expectation, ExpressionTypeComputationState state) { super(featureCall, description, expectation, state); }
Example #18
Source File: ConstructorLinkingCandidate.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
public ConstructorLinkingCandidate( XConstructorCall constructorCall, IIdentifiableElementDescription description, ITypeExpectation expectation, ExpressionTypeComputationState state) { super(constructorCall, description, expectation, state); }
Example #19
Source File: AbstractTypeComputationState.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected IConstructorLinkingCandidate createCandidate(XConstructorCall constructorCall, IIdentifiableElementDescription description) { StackedResolvedTypes stackedResolvedTypes = resolvedTypes.pushTypes(constructorCall); ExpressionTypeComputationState state = createExpressionComputationState(constructorCall, stackedResolvedTypes); if (description instanceof ScopeProviderAccess.ErrorDescription) { return new UnresolvableConstructorCall(constructorCall, ((ScopeProviderAccess.ErrorDescription) description).getNode(), description.getName().toString(), state); } else if (description.getElementOrProxy() instanceof JvmType) { return new TypeInsteadOfConstructorLinkingCandidate(constructorCall, description, state); } else { return new ConstructorLinkingCandidate(constructorCall, description, getSingleExpectation(state), state); } }
Example #20
Source File: AbstractTypeComputationState.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected IIdentifiableElementDescription toIdentifiableDescription(IEObjectDescription description) { if (description instanceof IIdentifiableElementDescription) return (IIdentifiableElementDescription) description; if (!(description.getEObjectOrProxy() instanceof JvmIdentifiableElement)) { throw new IllegalStateException("Given description does not describe an identifable element"); } return new SimpleIdentifiableElementDescription(description); }
Example #21
Source File: ExpressionScope.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected String getSignature(IIdentifiableElementDescription desc) { String descName = desc.getName().getFirstSegment(); StringBuilder builder = new StringBuilder(64).append(descName); JvmIdentifiableElement elementOrProxy = desc.getElementOrProxy(); if (elementOrProxy instanceof JvmExecutable) { JvmExecutable executable = (JvmExecutable) desc.getElementOrProxy(); String opName = executable.getSimpleName(); if (opName.length() - 3 == descName.length() && opName.startsWith("set")) { builder.append("="); } appendParameters(executable, builder, desc.isExtension()); } return builder.toString(); }
Example #22
Source File: ExpressionScope.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected String getExtensionSignature(IIdentifiableElementDescription desc) { JvmOperation operation = (JvmOperation) desc.getElementOrProxy(); StringBuilder builder = new StringBuilder(64).append(desc.getName()); String opName = operation.getSimpleName(); if (opName.length() - 3 == desc.getName().getFirstSegment().length() && opName.startsWith("set")) { builder.append("="); } appendParameters(operation, builder, desc.isExtension()); return builder.toString(); }
Example #23
Source File: ExpressionScope.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected LightweightTypeReference getFirstParameterType(IIdentifiableElementDescription candidate) { JvmOperation operation = (JvmOperation) candidate.getElementOrProxy(); if (operation.getParameters().isEmpty()) { return null; } return getParameterType(operation.getParameters().get(0)); }
Example #24
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 #25
Source File: XbaseProposalProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 4 votes |
public boolean isExplicitOperationCall(IIdentifiableElementDescription desc) { return desc.getNumberOfParameters() > 0; }
Example #26
Source File: XbaseProposalProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 4 votes |
protected ProposalBracketInfo getProposalBracketInfo(IEObjectDescription proposedDescription, ContentAssistContext contentAssistContext) { ProposalBracketInfo info = new ProposalBracketInfo(); if (proposedDescription instanceof IIdentifiableElementDescription) { IIdentifiableElementDescription jvmFeatureDescription = (IIdentifiableElementDescription)proposedDescription; JvmIdentifiableElement jvmFeature = jvmFeatureDescription.getElementOrProxy(); if(jvmFeature instanceof JvmExecutable) { List<JvmFormalParameter> parameters = ((JvmExecutable) jvmFeature).getParameters(); if (jvmFeatureDescription.getNumberOfParameters() == 1) { if (jvmFeature.getSimpleName().startsWith("set") && !proposedDescription.getName().getFirstSegment().startsWith("set")) { info.brackets = " = value"; info.selectionOffset = -"value".length(); info.selectionLength = "value".length(); return info; } JvmTypeReference parameterType = parameters.get(parameters.size()-1).getParameterType(); LightweightTypeReference light = getTypeConverter(contentAssistContext.getResource()).toLightweightReference(parameterType); if(light.isFunctionType()) { int numParameters = light.getAsFunctionTypeReference().getParameterTypes().size(); if(numParameters == 1) { info.brackets = "[]"; info.caretOffset = -1; return info; } else if(numParameters == 0) { info.brackets = "[|]"; info.caretOffset = -1; return info; } else { final StringBuilder b = new StringBuilder(); for(int i=0; i<numParameters; ++i) { if (i!=0) { b.append(", "); } b.append("p"+ (i+1)); } info.brackets = "[" + b.toString() + "|]"; info.caretOffset = -1; info.selectionOffset = -b.length() - 2; info.selectionLength = b.length(); return info; } } } } if (isExplicitOperationCall(jvmFeatureDescription)) { info.brackets = "()"; info.selectionOffset = -1; } } return info; }
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: XbaseIdeCrossrefProposalProvider.java From xtext-extras with Eclipse Public License 2.0 | 4 votes |
protected boolean isExplicitOperationCall(IIdentifiableElementDescription desc) { return desc.getNumberOfParameters() > 0; }
Example #29
Source File: XbaseReferenceProposalCreator.java From xtext-eclipse with Eclipse Public License 2.0 | 4 votes |
@Override protected void apply(IIdentifiableElementDescription featureDescription, MultiNameDescriptions result) { result.others.add(featureDescription); }
Example #30
Source File: ParameterContextInformationProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 4 votes |
@Override public void getContextInformation(ContentAssistContext context, IContextInformationAcceptor acceptor) { XExpression containerCall = getContainerCall(eObjectAtOffsetHelper.resolveContainedElementAt(context.getResource(), context.getOffset())); LightweightTypeReferenceFactory factory = proposalProvider.getTypeConverter(context.getResource()); if (containerCall != null) { ICompositeNode containerCallNode = NodeModelUtils.findActualNodeFor(containerCall); ITextRegion containerCallRegion = containerCallNode.getTextRegion(); if(containerCallRegion.getOffset() > context.getOffset() || containerCallRegion.getOffset() + containerCallRegion.getLength() < context.getOffset()) return; JvmIdentifiableElement calledFeature = getCalledFeature(containerCall); if (calledFeature instanceof JvmExecutable) { if(getParameterListOffset(containerCall) > context.getOffset()) return; ParameterData parameterData = new ParameterData(); IScope scope = getScope(containerCall); QualifiedName qualifiedName = QualifiedName.create(getCalledFeatureName(containerCall)); boolean candidatesFound = false; for (IEObjectDescription element : scope.getElements(qualifiedName)) { if (element instanceof IIdentifiableElementDescription) { IIdentifiableElementDescription featureDescription = (IIdentifiableElementDescription) element; JvmIdentifiableElement featureCandidate = featureDescription.getElementOrProxy(); if (featureCandidate instanceof JvmExecutable) { JvmExecutable executable = (JvmExecutable) featureCandidate; if(!executable.getParameters().isEmpty()) { StyledString styledString = new StyledString(); proposalProvider.appendParameters(styledString, executable, featureDescription.getNumberOfIrrelevantParameters(), factory); parameterData.addOverloaded(styledString.toString(), executable.isVarArgs()); candidatesFound = true; } } } } if (candidatesFound) { StyledString displayString = proposalProvider.getStyledDisplayString((JvmExecutable) calledFeature, true, 0, qualifiedNameConverter.toString(qualifiedNameProvider.getFullyQualifiedName(calledFeature)), calledFeature.getSimpleName(), factory); ParameterContextInformation parameterContextInformation = new ParameterContextInformation( parameterData, displayString.toString(), getParameterListOffset(containerCall), context.getOffset()); acceptor.accept(parameterContextInformation); } } } }