use of org.eclipse.xtext.xbase.scoping.batch.IIdentifiableElementDescription in project xtext-eclipse by eclipse.
the class JvmModelReferenceUpdater method getRefTextEvaluator.
/**
* 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();
}
};
}
use of org.eclipse.xtext.xbase.scoping.batch.IIdentifiableElementDescription in project xtext-eclipse by eclipse.
the class XbaseProposalProvider method getProposalBracketInfo.
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;
}
use of org.eclipse.xtext.xbase.scoping.batch.IIdentifiableElementDescription in project xtext-eclipse by eclipse.
the class ParameterContextInformationProvider method getContextInformation.
@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);
}
}
}
}
use of org.eclipse.xtext.xbase.scoping.batch.IIdentifiableElementDescription in project xtext-eclipse by eclipse.
the class XbaseContentProposalPriorities method adjustCrossReferencePriority.
@Override
public void adjustCrossReferencePriority(final ICompletionProposal proposal, final String prefix) {
if ((proposal instanceof ConfigurableCompletionProposal)) {
Object _additionalData = ((ConfigurableCompletionProposal) proposal).getAdditionalData(XbaseProposalProvider.DESCRIPTION_KEY);
final Object desc = _additionalData;
boolean _matched = false;
if (desc instanceof SimpleIdentifiableElementDescription) {
if (((!Objects.equal(((ConfigurableCompletionProposal) proposal).getReplacementString(), "this")) && (!Objects.equal(((ConfigurableCompletionProposal) proposal).getReplacementString(), "super")))) {
_matched = true;
this.adjustPriority(proposal, prefix, 570);
return;
}
}
if (!_matched) {
if (desc instanceof StaticFeatureDescriptionWithTypeLiteralReceiver) {
_matched = true;
this.adjustPriority(proposal, prefix, 560);
}
}
if (!_matched) {
if (desc instanceof IIdentifiableElementDescription) {
_matched = true;
JvmIdentifiableElement _elementOrProxy = ((IIdentifiableElementDescription) desc).getElementOrProxy();
boolean _matched_1 = false;
if (_elementOrProxy instanceof JvmField) {
_matched_1 = true;
this.adjustPriority(proposal, prefix, 550);
return;
}
if (!_matched_1) {
if (_elementOrProxy instanceof JvmExecutable) {
_matched_1 = true;
this.adjustPriority(proposal, prefix, 520);
return;
}
}
}
}
}
super.adjustCrossReferencePriority(proposal, prefix);
}
Aggregations