use of org.eclipse.xtext.ui.editor.contentassist.ConfigurableCompletionProposal in project statecharts by Yakindu.
the class STextProposalProvider method getProposalFactory.
protected Function<IEObjectDescription, ICompletionProposal> getProposalFactory(String ruleName, ContentAssistContext contentAssistContext) {
return new DefaultProposalCreator(contentAssistContext, ruleName, getQualifiedNameConverter()) {
@Override
public ICompletionProposal apply(IEObjectDescription candidate) {
ICompletionProposal proposal = super.apply(candidate);
EObject eObjectOrProxy = candidate.getEObjectOrProxy();
if (eObjectOrProxy.eIsProxy()) {
return proposal;
}
if (eObjectOrProxy instanceof Operation) {
Operation operation = (Operation) eObjectOrProxy;
if (operation.getParameters().size() > 0 && (proposal instanceof ConfigurableCompletionProposal)) {
ConfigurableCompletionProposal configurableProposal = (ConfigurableCompletionProposal) proposal;
configurableProposal.setReplacementString(configurableProposal.getReplacementString() + "()");
configurableProposal.setCursorPosition(configurableProposal.getCursorPosition() + 1);
}
}
return proposal;
}
};
}
use of org.eclipse.xtext.ui.editor.contentassist.ConfigurableCompletionProposal in project statecharts by Yakindu.
the class STextProposalProvider method complete_HEX.
@Override
public void complete_HEX(EObject model, RuleCall ruleCall, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
ICompletionProposalAcceptor priorityOptimizer = getCustomAcceptor(model, "integer", acceptor);
String proposalText = "0x1";
ICompletionProposal proposal = createCompletionProposal(proposalText, proposalText + " - " + ruleCall.getRule().getName(), null, context);
if (proposal instanceof ConfigurableCompletionProposal) {
ConfigurableCompletionProposal configurable = (ConfigurableCompletionProposal) proposal;
configurable.setSelectionStart(configurable.getReplacementOffset() + 2);
configurable.setSelectionLength(proposalText.length() - 2);
configurable.setAutoInsertable(false);
configurable.setSimpleLinkedMode(context.getViewer(), '\t', ' ');
}
priorityOptimizer.accept(proposal);
}
use of org.eclipse.xtext.ui.editor.contentassist.ConfigurableCompletionProposal in project statecharts by Yakindu.
the class STextProposalProvider method completeImportScope_Imports.
@Override
public void completeImportScope_Imports(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
StringProposalDelegate stringProposalDelegate = new StringProposalDelegate(acceptor, context);
Set<PackageImport> allImports = mapper.getAllImports(model.eResource());
for (PackageImport pkgImport : allImports) {
ConfigurableCompletionProposal doCreateProposal = doCreateProposal("\"" + pkgImport.getName() + "\"", computePackageStyledString(pkgImport), getIncludeImage(), pkgImport.getUri().isFile() ? -1 : 1, context);
stringProposalDelegate.accept(doCreateProposal);
}
}
use of org.eclipse.xtext.ui.editor.contentassist.ConfigurableCompletionProposal in project statecharts by Yakindu.
the class StringProposalDelegate method accept.
@Override
public void accept(ICompletionProposal proposal) {
if (proposal instanceof ConfigurableCompletionProposal) {
ConfigurableCompletionProposal configurableCompletionProposal = (ConfigurableCompletionProposal) proposal;
int endPos = configurableCompletionProposal.getReplacementOffset() + configurableCompletionProposal.getReplacementLength();
if (ctx.getDocument() != null && ctx.getDocument().getLength() > endPos) {
// We are not at the end of the file
try {
if ("\"".equals(ctx.getDocument().get(endPos, 1))) {
configurableCompletionProposal.setReplacementLength(configurableCompletionProposal.getReplacementLength() - 1);
configurableCompletionProposal.setReplacementString(configurableCompletionProposal.getReplacementString().substring(0, configurableCompletionProposal.getReplacementString().length() - 1));
}
} catch (BadLocationException e) {
LOG.debug("Skipped propsal adjustment.", e);
}
}
}
super.accept(proposal);
}
use of org.eclipse.xtext.ui.editor.contentassist.ConfigurableCompletionProposal in project xtext-eclipse by eclipse.
the class ContentAssistProcessorTestBuilder method getProposedText.
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;
}
Aggregations