Java Code Examples for org.eclipse.xtext.ui.editor.contentassist.ConfigurableCompletionProposal#setPriority()
The following examples show how to use
org.eclipse.xtext.ui.editor.contentassist.ConfigurableCompletionProposal#setPriority() .
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: SolidityContentProposalPriorities.java From solidity-ide with Eclipse Public License 1.0 | 6 votes |
@Override protected void adjustPriority(ICompletionProposal proposal, String prefix, int priority) { if (proposal == null || !(proposal instanceof ConfigurableCompletionProposal)) return; ConfigurableCompletionProposal castedProposal = (ConfigurableCompletionProposal) proposal; if (castedProposal.getPriority() != getDefaultPriority()) return; int adjustedPriority = priority; if (!Strings.isEmpty(prefix)) { if (castedProposal.getReplacementString().equals(prefix)) adjustedPriority = (int) (adjustedPriority * sameTextMultiplier); else if (castedProposal.getReplacementString().startsWith(prefix)) adjustedPriority = adjustedPriority * proposalWithPrefixMultiplier; } castedProposal.setPriority(adjustedPriority); }
Example 2
Source File: CodetemplatesProposalProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
public void completeNestedKeyword(Keyword keyword, ContentAssistContext contentAssistContext, ICompletionProposalAcceptor acceptor, TemplateData data) { String keywordValue = keyword.getValue(); String escapedKeywordValue = keywordValue.replace("$", "$$"); StyledString displayString = new StyledString(keywordValue); if (!keywordValue.equals(escapedKeywordValue)) { displayString = new StyledString(escapedKeywordValue) .append(" - ", StyledString.QUALIFIER_STYLER) .append(keywordValue, StyledString.COUNTER_STYLER) .append(" - Keyword", StyledString.QUALIFIER_STYLER); } else { displayString = displayString.append(" - Keyword", StyledString.QUALIFIER_STYLER); } ConfigurableCompletionProposal proposal = (ConfigurableCompletionProposal) createCompletionProposal(escapedKeywordValue, displayString, getImage(keyword), contentAssistContext); getPriorityHelper().adjustKeywordPriority(proposal, contentAssistContext.getPrefix()); if (proposal != null) proposal.setPriority(proposal.getPriority() * 2); acceptor.accept(proposal); }
Example 3
Source File: N4JSContentProposalPriorities.java From n4js with Eclipse Public License 1.0 | 5 votes |
private void adjustPriorityByFactor(ConfigurableCompletionProposal proposal, float factor) { if (factor == 1.0f) { return; } int newPrio = (int) (proposal.getPriority() * factor); proposal.setPriority(newPrio); }
Example 4
Source File: CodetemplatesProposalProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
public void completeNestedAssignment(Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor, TemplateData data) { String proposalText = "${" + assignment.getFeature() + "}"; StyledString displayText; if (assignment.getTerminal() instanceof RuleCall) { RuleCall ruleCall = (RuleCall) assignment.getTerminal(); AbstractRule calledRule = ruleCall.getRule(); displayText = new StyledString("${", StyledString.DECORATIONS_STYLER) .append(assignment.getFeature(), null) .append("}", StyledString.DECORATIONS_STYLER) .append(" - ", StyledString.QUALIFIER_STYLER) .append(calledRule.getName(), StyledString.COUNTER_STYLER) .append(" - Create a new template variable", StyledString.QUALIFIER_STYLER); } else { displayText = new StyledString("${", StyledString.DECORATIONS_STYLER) .append(assignment.getFeature(), null) .append("}", StyledString.DECORATIONS_STYLER) .append(" - Create a new template variable", StyledString.QUALIFIER_STYLER); } ICompletionProposal proposal = createCompletionProposal(proposalText, displayText, null, context); if (proposal instanceof ConfigurableCompletionProposal) { ConfigurableCompletionProposal configurable = (ConfigurableCompletionProposal) proposal; configurable.setSelectionStart(configurable.getReplacementOffset() + 2); configurable.setSelectionLength(proposalText.length() - 3); configurable.setAutoInsertable(false); configurable.setSimpleLinkedMode(context.getViewer(), '\t'); configurable.setPriority(configurable.getPriority() * 2); } acceptor.accept(proposal); }
Example 5
Source File: CodetemplatesProposalProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
public void completeNestedCrossReference(CrossReference crossReference, ContentAssistContext context, ICompletionProposalAcceptor acceptor, TemplateData data) { if (data.doCreateProposals()) { ContextTypeIdHelper helper = languageRegistry.getContextTypeIdHelper(data.language); if (helper != null) { String contextTypeId = helper.getId(data.rule); ContextTypeRegistry contextTypeRegistry = languageRegistry.getContextTypeRegistry(data.language); TemplateContextType contextType = contextTypeRegistry.getContextType(contextTypeId); TemplateVariableResolver crossRefResolver = getResolver(contextType, "CrossReference"); if (crossRefResolver != null) { Assignment assignment = (Assignment) crossReference.eContainer(); EReference reference = GrammarUtil.getReference(crossReference); if (reference != null) { String proposalText = "${" + assignment.getFeature() + ":CrossReference(" + reference.getEContainingClass().getName() + "." + reference.getName() + ")}"; StyledString displayText = new StyledString("${", StyledString.DECORATIONS_STYLER) .append(assignment.getFeature()) .append(":CrossReference(", StyledString.DECORATIONS_STYLER) .append(reference.getEContainingClass().getName() + "." + reference.getName(), StyledString.COUNTER_STYLER) .append(")}", StyledString.DECORATIONS_STYLER) .append(" - Create a new template variable", StyledString.QUALIFIER_STYLER); ICompletionProposal proposal = createCompletionProposal(proposalText, displayText, null, context); if (proposal instanceof ConfigurableCompletionProposal) { ConfigurableCompletionProposal configurable = (ConfigurableCompletionProposal) proposal; configurable.setSelectionStart(configurable.getReplacementOffset() + 2); configurable.setSelectionLength(assignment.getFeature().length()); configurable.setAutoInsertable(false); configurable.setSimpleLinkedMode(context.getViewer(), '\t'); configurable.setPriority(configurable.getPriority() * 2); } acceptor.accept(proposal); } } } } }
Example 6
Source File: XtextProposalProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
private void createAliasProposal(ContentAssistContext context, ICompletionProposalAcceptor acceptor, EPackage ePackage, String proposal) { if (!Strings.isEmpty(proposal)) { ConfigurableCompletionProposal completionProposal = (ConfigurableCompletionProposal) createCompletionProposal( proposal, proposal + " - alias", ePackage != null ? getImage(ePackage) : null, context); if (completionProposal != null) { completionProposal.setPriority(completionProposal.getPriority() * 2); acceptor.accept(completionProposal); } } }
Example 7
Source File: XtextProposalProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
protected ICompletionProposal createFeatureProposal(EStructuralFeature feature, int priorityFactor, Function<IEObjectDescription, ICompletionProposal> factory, ContentAssistContext context) { IEObjectDescription description = EObjectDescription.create(QualifiedName.create(feature.getName()), feature); ConfigurableCompletionProposal proposal = (ConfigurableCompletionProposal) factory.apply(description); if (proposal != null) { proposal.setPriority(proposal.getPriority() * priorityFactor); if(SemanticHighlightingCalculator.SPECIAL_ATTRIBUTES.contains(feature.getName())) { StyledString displayString = stylerFactory.createFromXtextStyle(feature.getName(), semanticHighlightingConfiguration.specialAttribute()) .append(" - Assignment of special attribute ") .append(stylerFactory.createFromXtextStyle(feature.getName(), semanticHighlightingConfiguration.specialAttribute())); proposal.setDisplayString(displayString); } else { proposal.setDisplayString(new StyledString(feature.getName() + " - Assignment of feature " + feature.getName())); } if(feature.isMany()) { proposal.setReplacementString(feature.getName() + "+="); proposal.setCursorPosition(proposal.getCursorPosition() + 2); } else if(feature.getEType() == EcorePackage.Literals.EBOOLEAN) { proposal.setReplacementString(feature.getName() + "?="); proposal.setCursorPosition(proposal.getCursorPosition() + 2); } else { proposal.setReplacementString(feature.getName() + "="); proposal.setCursorPosition(proposal.getCursorPosition() + 1); } } return proposal; }
Example 8
Source File: XtextProposalProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
private void createClassifierProposals(AbstractMetamodelDeclaration declaration, EObject model, ContentAssistContext context, ICompletionProposalAcceptor acceptor) { String alias = declaration.getAlias(); QualifiedName prefix = (!Strings.isEmpty(alias)) ? QualifiedName.create(getValueConverter().toString(alias, grammarAccess.getValidIDRule().getName())) : null; boolean createDatatypeProposals = !(model instanceof AbstractElement) && modelOrContainerIs(model, AbstractRule.class); boolean createEnumProposals = !(model instanceof AbstractElement) && modelOrContainerIs(model, EnumRule.class); boolean createClassProposals = modelOrContainerIs(model, ParserRule.class, CrossReference.class, Action.class); Function<IEObjectDescription, ICompletionProposal> factory = new DefaultProposalCreator(context, null, classifierQualifiedNameConverter); for (EClassifier classifier : declaration.getEPackage().getEClassifiers()) { if (classifier instanceof EDataType && createDatatypeProposals || classifier instanceof EEnum && createEnumProposals || classifier instanceof EClass && createClassProposals) { String classifierName = getValueConverter().toString(classifier.getName(), grammarAccess.getValidIDRule().getName()); QualifiedName proposalQualifiedName = (prefix != null) ? prefix.append(classifierName) : QualifiedName .create(classifierName); IEObjectDescription description = EObjectDescription.create(proposalQualifiedName, classifier); ConfigurableCompletionProposal proposal = (ConfigurableCompletionProposal) factory.apply(description); if (proposal != null) { if (prefix != null) proposal.setDisplayString(classifier.getName() + " - " + alias); proposal.setPriority(proposal.getPriority() * 2); } acceptor.accept(proposal); } } }
Example 9
Source File: GamlProposalProvider.java From gama with GNU General Public License v3.0 | 4 votes |
@Override public ICompletionProposal apply(final IEObjectDescription candidate) { final ConfigurableCompletionProposal cp = (ConfigurableCompletionProposal) super.apply(candidate); boolean isOperator = false; String doc = candidate.getUserData("doc"); final String title = candidate.getUserData("title"); if (doc == null) { doc = "Not documented yet"; } if (cp != null) { cp.setAdditionalProposalInfo("<b>" + title + "</b><p/><p>" + doc + "</p>"); final String type = candidate.getUserData("type"); if (type != null) { if (type.equals("operator")) { isOperator = true; cp.setDisplayString(cp.getDisplayString().concat(" (Built-in operator) ")); cp.setImage(actionImage); } else if (type.equals("variable")) { cp.setDisplayString(cp.getDisplayString().concat(" (Built-in variable) ")); cp.setImage(varImage); } else if (type.equals("field")) { cp.setDisplayString(cp.getDisplayString().concat(" (Built-in field) ")); cp.setImage(varImage); } else if (type.equals("action")) { cp.setDisplayString(cp.getDisplayString().concat(" (Built-in action) ")); cp.setImage(actionImage); } else if (type.equals("unit")) { isOperator = true; cp.setDisplayString(cp.getDisplayString().concat(" (Built-in unit) ")); cp.setImage(null); } else if (type.equals("type")) { isOperator = true; cp.setDisplayString(cp.getDisplayString().concat(" (Built-in type) ")); cp.setImage(typeImage); } cp.setPriority(1000); } } if (context.getPrefix().equals(".")) { if (isOperator) { return null; } if (cp != null && cp.getPriority() > 500) { cp.setPriority(200); } } return cp; }