Java Code Examples for org.eclipse.xtext.ui.editor.contentassist.ConfigurableCompletionProposal#getReplacementString()
The following examples show how to use
org.eclipse.xtext.ui.editor.contentassist.ConfigurableCompletionProposal#getReplacementString() .
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: N4JSContentProposalPriorities.java From n4js with Eclipse Public License 1.0 | 6 votes |
@Override protected void adjustPriority(ICompletionProposal proposal, String prefix, int priority) { // default adjustments super.adjustPriority(proposal, prefix, priority); // custom adjustments if (proposal instanceof ConfigurableCompletionProposal) { ConfigurableCompletionProposal proposalCasted = (ConfigurableCompletionProposal) proposal; String replacement = proposalCasted.getReplacementString(); if (!prefix.isEmpty() && isPrefixWithMatchingCase(prefix, replacement)) { adjustPriorityByFactor(proposalCasted, sameCaseMultiplier); } if (isSecondaryMember(proposalCasted)) { adjustPriorityByFactor(proposalCasted, secondaryMemberMultiplier); } } }
Example 2
Source File: N4JSReplacementTextApplier.java From n4js with Eclipse Public License 1.0 | 6 votes |
/** * Return the to-be-inserted string if an existing import is present. */ @Override public String getActualReplacementString(ConfigurableCompletionProposal proposal) { String syntacticReplacementString = proposal.getReplacementString(); if (scope != null) { final QualifiedName qualifiedName = applyValueConverter(syntacticReplacementString); if (qualifiedName.getSegmentCount() == 1) { return syntacticReplacementString; } final IEObjectDescription element = scope.getSingleElement(qualifiedName); if (element != null) { EObject resolved = EcoreUtil.resolve(element.getEObjectOrProxy(), context); if (!resolved.eIsProxy()) { IEObjectDescription description = findApplicableDescription(resolved, qualifiedName, true); if (description != null) { String multisegmentProposal = applyValueConverter(description.getName()); return multisegmentProposal; } } } } return syntacticReplacementString; }
Example 3
Source File: ArithmeticsProposalProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
/** * sets the selection on the arguments for proposed functions. */ @Override public void completePrimaryExpression_Func(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) { super.completePrimaryExpression_Func(model, assignment, context, new ICompletionProposalAcceptor.Delegate(acceptor) { @Override public void accept(ICompletionProposal proposal) { if (proposal instanceof ConfigurableCompletionProposal) { ConfigurableCompletionProposal configurableCompletionProposal = (ConfigurableCompletionProposal) proposal; String string = configurableCompletionProposal.getReplacementString(); int indexOfOpenPar = string.indexOf(Character.valueOf('(').charValue()); if (indexOfOpenPar != -1) { int oldSelectionStart = configurableCompletionProposal.getSelectionStart(); int selectionStart = oldSelectionStart - string.length() + indexOfOpenPar + 1; int selectionLenth = oldSelectionStart - selectionStart - 1; configurableCompletionProposal.setSelectionStart(selectionStart); configurableCompletionProposal.setSelectionLength(selectionLenth); } } super.accept(proposal); } }); }
Example 4
Source File: JdtTypesProposalProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
@Override public String getActualReplacementString(ConfigurableCompletionProposal proposal) { String replacementString = proposal.getReplacementString(); if (scope != null) { String qualifiedNameAsString = replacementString; if (valueConverter != null) { qualifiedNameAsString = valueConverter.toValue(qualifiedNameAsString, null); } IEObjectDescription element = scope.getSingleElement(qualifiedNameConverter.toQualifiedName(qualifiedNameAsString)); if (element != null) { EObject resolved = EcoreUtil.resolve(element.getEObjectOrProxy(), context); if (!resolved.eIsProxy()) { IEObjectDescription shortendElement = scope.getSingleElement(resolved); if (shortendElement != null) replacementString = applyValueConverter(shortendElement.getName()); } } } return replacementString; }
Example 5
Source File: ContentAssistProcessorTestBuilder.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
protected String getProposedText(ICompletionProposal completionProposal) { String proposedText = completionProposal.getDisplayString(); if (completionProposal instanceof ConfigurableCompletionProposal) { ConfigurableCompletionProposal configurableProposal = (ConfigurableCompletionProposal) completionProposal; proposedText = configurableProposal.getReplacementString(); if (configurableProposal.getTextApplier() instanceof ReplacementTextApplier) { proposedText = ((ReplacementTextApplier) configurableProposal.getTextApplier()).getActualReplacementString(configurableProposal); } } return proposedText; }
Example 6
Source File: ContentAssistProcessorTestBuilder.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
protected String getProposedText(ICompletionProposal completionProposal) { String proposedText = completionProposal.getDisplayString(); if (completionProposal instanceof ConfigurableCompletionProposal) { ConfigurableCompletionProposal configurableProposal = (ConfigurableCompletionProposal) completionProposal; proposedText = configurableProposal.getReplacementString(); if (configurableProposal.getTextApplier() instanceof ReplacementTextApplier) { proposedText = ((ReplacementTextApplier) configurableProposal.getTextApplier()).getActualReplacementString(configurableProposal); } } return proposedText; }
Example 7
Source File: EclipseBug28DirtyStateModifierContentAssistTest.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
private static String getProposedText(ICompletionProposal completionProposal) { String proposedText = completionProposal.getDisplayString(); if (completionProposal instanceof ConfigurableCompletionProposal) { ConfigurableCompletionProposal configurableProposal = (ConfigurableCompletionProposal) completionProposal; proposedText = configurableProposal.getReplacementString(); if (configurableProposal.getTextApplier() instanceof ReplacementTextApplier) { proposedText = ((ReplacementTextApplier) configurableProposal.getTextApplier()) .getActualReplacementString(configurableProposal); } } return proposedText; }
Example 8
Source File: AbstractContentAssistTest.java From sarl with Apache License 2.0 | 5 votes |
private static String getProposedText(ICompletionProposal completionProposal) { String proposedText = completionProposal.getDisplayString(); if (completionProposal instanceof ConfigurableCompletionProposal) { ConfigurableCompletionProposal configurableProposal = (ConfigurableCompletionProposal) completionProposal; proposedText = configurableProposal.getReplacementString(); if (configurableProposal.getTextApplier() instanceof ReplacementTextApplier) { proposedText = ((ReplacementTextApplier) configurableProposal.getTextApplier()) .getActualReplacementString(configurableProposal); } } return proposedText; }
Example 9
Source File: N4JSReplacementTextApplier.java From n4js with Eclipse Public License 1.0 | 4 votes |
/** * Modify the document and start linked editing if necessary. * * Imports will be added if necessary. * * @see #applyWithImport(QualifiedName, String, IDocument, ConfigurableCompletionProposal) */ @Override public void apply(IDocument document, ConfigurableCompletionProposal proposal) throws BadLocationException { final String syntacticReplacementString = proposal.getReplacementString(); // does it even happen? check logs if first and/or second check passes { String actualSyntacticReplacementString = getActualReplacementString(proposal); // there is an import statement - apply computed replacementString if (!syntacticReplacementString.equals(actualSyntacticReplacementString)) { QualifiedName shortQualifiedName = applyValueConverter(actualSyntacticReplacementString); if (shortQualifiedName.getSegmentCount() == 1) { simpleApply(document, actualSyntacticReplacementString, proposal); return; } } } final QualifiedName qualifiedName = (QualifiedName) proposal.getAdditionalData(KEY_QUALIFIED_NAME); final QualifiedName originalQualifiedName = (QualifiedName) proposal .getAdditionalData(KEY_ORIGINAL_QUALIFIED_NAME); if (qualifiedName == null) { simpleApply(document, syntacticReplacementString, proposal); return; } // we could create an import statement if there is no conflict if (qualifiedName.getSegmentCount() == 1) { // type name is a simple name - no need to hassle with imports simpleApply(document, syntacticReplacementString, proposal); return; } // Globally available elements should not generate imports if (qualifiedName.getSegmentCount() == 2 && N4TSQualifiedNameProvider.GLOBAL_NAMESPACE_SEGMENT.equals(qualifiedName.getFirstSegment())) { // type name is a simple name from global Namespace - no need to hassle with imports simpleApply(document, syntacticReplacementString, proposal); return; } String alias = null; String shortQName = lastSegmentOrDefaultHost(originalQualifiedName); IEObjectDescription descriptionFullQN = scope .getSingleElement(QualifiedName.create(shortQName)); // element is already imported via namespace if (descriptionFullQN instanceof PlainAccessOfNamespacedImportDescription) { QualifiedName namespaceQN = ((PlainAccessOfNamespacedImportDescription) descriptionFullQN) .getNamespacedName(); simpleApply(document, namespaceQN.toString(), proposal); return; } // element is already imported via an alias if (descriptionFullQN instanceof PlainAccessOfAliasedImportDescription) { simpleApply(document, ((PlainAccessOfAliasedImportDescription) descriptionFullQN).getAlias(), proposal); return; } if (descriptionFullQN != null) { if (descriptionFullQN.getEObjectOrProxy() instanceof ModuleNamespaceVirtualType) { // accessing default export via already imported namespace simpleApply(document, qualifiedName.toString(), proposal); return; } // the simple name is already reachable, i.e. already in use - another import is present // try to use an alias alias = "Alias" + UtilN4.toUpperCaseFirst(shortQName); } applyWithImport(qualifiedName, alias, document, proposal); }