org.eclipse.xtext.ui.editor.contentassist.ConfigurableCompletionProposal Java Examples

The following examples show how to use org.eclipse.xtext.ui.editor.contentassist.ConfigurableCompletionProposal. 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: CodetemplatesProposalProvider.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
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 #2
Source File: JdtTypesProposalProvider.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@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 #3
Source File: TypeAwareReferenceProposalCreator.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected Function<IEObjectDescription, ICompletionProposal> getWrappedFactory(EObject model, EReference reference,
		final Function<IEObjectDescription, ICompletionProposal> proposalFactory) {
	if (TypesPackage.Literals.JVM_TYPE.isSuperTypeOf(getEReferenceType(model, reference))) {
		return new Function<IEObjectDescription, ICompletionProposal>() {

			@Override
			public ICompletionProposal apply(IEObjectDescription from) {
				ICompletionProposal result = proposalFactory.apply(from);
				if (result instanceof ConfigurableCompletionProposal) {
					String flags = from.getUserData("flags");
					if (flags != null) {
						boolean inner = "true".equals(from.getUserData("inner"));
						int modifiers = Integer.parseInt(flags);
						((ConfigurableCompletionProposal) result).setImage(computeImage(inner, modifiers));
					}
				}
				return result;
			}
		};
	}
	return super.getWrappedFactory(model, reference, proposalFactory);
}
 
Example #4
Source File: DotProposalProviderDelegator.java    From gef with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Computes the configurable completion proposals considering the given text
 * and the given cursorPosition.
 *
 * @param text
 *            The current text to parse.
 * @param cursorPosition
 *            The cursor position within the given text.
 * @return The configurable completion proposals valid on the given cursor
 *         position within the given text. Returns an empty list if the
 *         proposals cannot be determined.
 */
public List<ConfigurableCompletionProposal> computeConfigurableCompletionProposals(
		final String text, int cursorPosition) {

	List<ConfigurableCompletionProposal> configurableCompletionProposal = new ArrayList<>();
	ICompletionProposal[] completionProposals = {};
	try {
		completionProposals = computeCompletionProposals(text,
				cursorPosition);
	} catch (Exception e) {
		DotActivatorEx.logError(e);
	}

	// convert the completionProposals into configurableCompletionProposals
	for (ICompletionProposal completionProposal : completionProposals) {
		if (completionProposal instanceof ConfigurableCompletionProposal) {
			configurableCompletionProposal.add(
					(ConfigurableCompletionProposal) completionProposal);
		}
	}

	return configurableCompletionProposal;
}
 
Example #5
Source File: XbaseProposalProvider.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * @since 2.17
 */
protected void proposeFavoriteStaticFeatures(EObject context, ContentAssistContext contentAssistContext,
		ICompletionProposalAcceptor acceptor, IScope scopedFeatures) {
	Function<IEObjectDescription, ICompletionProposal> proposalFactory = getProposalFactory(getFeatureCallRuleName(), contentAssistContext);
	IReplacementTextApplier textApplier =  new FQNImporter(contentAssistContext.getResource(), contentAssistContext.getViewer(), scopedFeatures, qualifiedNameConverter,
			qualifiedNameValueConverter, importSectionFactory, replaceConverter);
	Function<IEObjectDescription, ICompletionProposal> importAddingProposalFactory = input->{
		ICompletionProposal proposal = proposalFactory.apply(input);
		if(proposal instanceof ConfigurableCompletionProposal) {
			ConfigurableCompletionProposal castedProposal = (ConfigurableCompletionProposal) proposal;
			// Add textApplier to introduce imports if necessary
			((ConfigurableCompletionProposal) proposal).setTextApplier(textApplier);
			return castedProposal;
		}
		return proposal;
	};
	getCrossReferenceProposalCreator().lookupCrossReference(scopedFeatures, context, XbasePackage.Literals.XABSTRACT_FEATURE_CALL__FEATURE, acceptor, getFeatureDescriptionPredicate(contentAssistContext), importAddingProposalFactory);
}
 
Example #6
Source File: N4JSContentProposalPriorities.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
@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 #7
Source File: TerminalsProposalProvider.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
private void createIntProposal(ContentAssistContext context, ICompletionProposalAcceptor acceptor,
		RuleCall ruleCall, String feature,	int i) {
	String proposalText = getValueConverter().toString(i, ruleCall.getRule().getName());
	String displayText = proposalText + " - " + ruleCall.getRule().getName();
	if (feature != null)
		displayText = proposalText + " - " + feature;
	ICompletionProposal proposal = createCompletionProposal(proposalText, displayText, null, context);
	if (proposal instanceof ConfigurableCompletionProposal) {
		ConfigurableCompletionProposal configurable = (ConfigurableCompletionProposal) proposal;
		configurable.setSelectionStart(configurable.getReplacementOffset());
		configurable.setSelectionLength(proposalText.length());
		configurable.setAutoInsertable(false);
		configurable.setSimpleLinkedMode(context.getViewer(), '\t', ' ');
	}
	acceptor.accept(proposal);
}
 
Example #8
Source File: TerminalsProposalProvider.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
private void createStringProposal(ContentAssistContext context, ICompletionProposalAcceptor acceptor,
		String feature, RuleCall ruleCall) {
	String proposalText = feature != null ? feature : Strings.toFirstUpper(ruleCall.getRule().getName().toLowerCase());
	proposalText = getValueConverter().toString(proposalText, ruleCall.getRule().getName());
	String displayText = proposalText;
	if (feature != null)
		displayText = displayText + " - " + ruleCall.getRule().getName();
	ICompletionProposal proposal = createCompletionProposal(proposalText, displayText, null, context);
	if (proposal instanceof ConfigurableCompletionProposal) {
		ConfigurableCompletionProposal configurable = (ConfigurableCompletionProposal) proposal;
		configurable.setSelectionStart(configurable.getReplacementOffset() + 1);
		configurable.setSelectionLength(proposalText.length() - 2);
		configurable.setAutoInsertable(false);
		configurable.setSimpleLinkedMode(context.getViewer(), proposalText.charAt(0), '\t');
		
	}
	acceptor.accept(proposal);
}
 
Example #9
Source File: DotHtmlLabelProposalProvider.java    From gef with Eclipse Public License 2.0 6 votes vote down vote up
private void proposeHtmlBgColorAttributeValues(ContentAssistContext context,
		ICompletionProposalAcceptor acceptor) {
	INode currentNode = context.getCurrentNode();
	String fullText = currentNode.getText();
	String text = fullText;
	int beginReplacementOffset = currentNode.getOffset();

	if (context.getPrefix().contains(":")) { //$NON-NLS-1$
		int colonOffset = fullText.indexOf(':') + 1;
		text = fullText.substring(colonOffset);
		beginReplacementOffset += colonOffset;
	} else {
		beginReplacementOffset += beginsWithQuote(text) ? 1 : 0;
	}
	proposeHtmlColorAttributeValues(context, acceptor,
			text.replaceAll("['\"]", ""), //$NON-NLS-1$ //$NON-NLS-2$
			beginReplacementOffset, context.getOffset());
	if (!fullText.contains(":")) { //$NON-NLS-1$
		acceptor.accept(new ConfigurableCompletionProposal(":", //$NON-NLS-1$
				context.getOffset(), 0, 1));
	}
}
 
Example #10
Source File: ArithmeticsProposalProvider.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * 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 #11
Source File: DotHtmlLabelProposalProvider.java    From gef with Eclipse Public License 2.0 6 votes vote down vote up
private void proposeHtmlColorAttributeValues(ContentAssistContext context,
		ICompletionProposalAcceptor acceptor, String text,
		int beginReplacementOffset, int contextOffset) {
	String subgrammarName = DotActivator.ORG_ECLIPSE_GEF_DOT_INTERNAL_LANGUAGE_DOTCOLOR;

	List<ConfigurableCompletionProposal> configurableCompletionProposals = new DotProposalProviderDelegator(
			subgrammarName).computeConfigurableCompletionProposals(text,
					contextOffset - beginReplacementOffset);

	for (ConfigurableCompletionProposal configurableCompletionProposal : configurableCompletionProposals) {
		// adapt the replacement offset determined within the
		// sub-grammar context to be valid within the context of the
		// original text
		configurableCompletionProposal.setReplacementOffset(
				beginReplacementOffset + configurableCompletionProposal
						.getReplacementOffset());
		acceptor.accept(configurableCompletionProposal);
	}
}
 
Example #12
Source File: DotHtmlLabelProposalProvider.java    From gef with Eclipse Public License 2.0 6 votes vote down vote up
private void proposeHtmlAttributeValues(ContentAssistContext context,
		ICompletionProposalAcceptor acceptor, String... proposals) {
	for (String proposal : proposals) {
		ICompletionProposal completionProposal = createCompletionProposal(
				proposal, context);
		String text = context.getCurrentNode().getText();
		if ((text.startsWith("\"") || text.startsWith("'"))//$NON-NLS-1$ //$NON-NLS-2$
				&& completionProposal instanceof ConfigurableCompletionProposal) {
			// ensure that the single quote / double quote at the beginning
			// of an attribute
			// value is not overridden when applying the proposal
			ConfigurableCompletionProposal configurableCompletionProposal = (ConfigurableCompletionProposal) completionProposal;
			configurableCompletionProposal.setReplacementOffset(
					configurableCompletionProposal.getReplacementOffset()
							+ 1);
			configurableCompletionProposal.setReplacementLength(
					configurableCompletionProposal.getReplacementLength()
							- 1);
			configurableCompletionProposal.setReplaceContextLength(
					configurableCompletionProposal.getReplaceContextLength()
							- 1);
		}
		acceptor.accept(completionProposal);
	}
}
 
Example #13
Source File: CodetemplatesProposalProvider.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void completeCodetemplate_KeywordContext(EObject model, Assignment assignment, ContentAssistContext context,
		ICompletionProposalAcceptor acceptor) {
	Codetemplate template = EcoreUtil2.getContainerOfType(model, Codetemplate.class);
	if (template != null) {
		Codetemplates templates = EcoreUtil2.getContainerOfType(template, Codetemplates.class);
		if (templates != null) {
			Grammar language = templates.getLanguage();
			if (language != null && !language.eIsProxy()) {
				Set<String> keywords = GrammarUtil.getAllKeywords(language);
				for(String keyword: keywords) {
					String proposalText = keyword;
					proposalText = getValueConverter().toString(proposalText, ((RuleCall)assignment.getTerminal()).getRule().getName());
					StyledString displayText = new StyledString(proposalText).append(" - Keyword", StyledString.QUALIFIER_STYLER);
					ICompletionProposal proposal = createCompletionProposal(proposalText, displayText, null, context);
					getPriorityHelper().adjustCrossReferencePriority(proposal, context.getPrefix());
					if (proposal instanceof ConfigurableCompletionProposal) {
						((ConfigurableCompletionProposal) proposal).setPriority(((ConfigurableCompletionProposal) proposal).getPriority() - 1);
					}
					acceptor.accept(proposal);
				}
			}
		}
	}
}
 
Example #14
Source File: CodetemplatesProposalProvider.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void complete_Variable(EObject model, RuleCall ruleCall, ContentAssistContext context,
		ICompletionProposalAcceptor acceptor) {
	if ((mode & NORMAL) != 0) {
		String proposalText = "${}";
		StyledString displayText = new StyledString(proposalText, 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(0);
			configurable.setAutoInsertable(false);
			configurable.setSimpleLinkedMode(context.getViewer(), '\t', ' ');
		}
		acceptor.accept(proposal);
	}
}
 
Example #15
Source File: SolidityContentProposalPriorities.java    From solidity-ide with Eclipse Public License 1.0 6 votes vote down vote up
@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 #16
Source File: N4JSReplacementTextApplier.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 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 #17
Source File: StringProposalDelegate.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
@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);
}
 
Example #18
Source File: AcfContentAssistProcessorTestBuilder.java    From dsl-devkit with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Applies a content assist proposal using the expected display string.
 *
 * @param expectedDisplayString
 *          the content assist proposal to apply
 * @param appendSpace
 *          whether to append a space
 * @return a new {@link AcfContentAssistProcessorTestBuilder} with the text applied.
 * @throws Exception
 *           if there was a problem loading the xtext resource
 */
public AcfContentAssistProcessorTestBuilder applyText(final String expectedDisplayString, final boolean appendSpace) throws Exception {
  ICompletionProposal proposal = null;
  for (final ICompletionProposal p : computeCompletionProposals(getModel(), getCursorPosition())) {
    if (expectedDisplayString.equals(p.getDisplayString())) {
      proposal = p;
      break;
    }
  }
  assertNotNull(MessageFormat.format("\"{0}\" not a valid completion proposal", expectedDisplayString), proposal);
  String text = "";
  if (proposal instanceof ConfigurableCompletionProposal) {
    text = ((ConfigurableCompletionProposal) proposal).getReplacementString();
  } else if (proposal instanceof XtextTemplateProposal) {
    // These may occur in the context of custom content assist templates
    text = ((XtextTemplateProposal) proposal).getAdditionalProposalInfo();
  }
  AcfContentAssistProcessorTestBuilder ret = append(text);
  if (appendSpace) {
    return ret.append(" ");
  }
  return ret;
}
 
Example #19
Source File: ImportsAwareReferenceProposalCreator.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Creates initial proposal adjusted for the N4JS imports. Then passes that proposal to the provided delegate
 * proposal factory. Obtained ICompletionProposal is configured with a FQNImporter as custom text. applier.
 *
 * @param candidate
 *            for which proposal is created
 * @param delegateProposalFactory
 *            delegate proposal factory
 * @return code completion proposal
 */
private ICompletionProposal getProposal(IEObjectDescription candidate, EObject model,
		IScope scope,
		EReference reference,
		ContentAssistContext context,
		Predicate<IEObjectDescription> filter,
		Function<IEObjectDescription, ICompletionProposal> delegateProposalFactory) {

	try (Measurement m = contentAssistDataCollectors.dcGetResolution().getMeasurement()) {
		final IEObjectDescription inputToUse = getAliasedDescription(candidate, reference, context);
		final ICompletionProposal result = delegateProposalFactory.apply(inputToUse);

		if (result instanceof ConfigurableCompletionProposal) {
			final N4JSReplacementTextApplier applier = applierFactory.create(
					model.eResource(),
					scope,
					valueConverter,
					filter,
					context.getViewer());

			((ConfigurableCompletionProposal) result).setTextApplier(applier);
		}
		return result;
	}
}
 
Example #20
Source File: JSONProposalProvider.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Propose an empty array literal to complete rule {@code JSONArray}.
 * 
 * The cursor is set between the two squared brackets.
 */
@Override
public void complete_JSONArray(EObject model, RuleCall ruleCall, ContentAssistContext context,
		ICompletionProposalAcceptor acceptor) {
	// only propose if context does not specify a prefix
	if (!context.getPrefix().isEmpty()) {
		return;
	}

	for (IJSONProposalProvider pe : registry.getProposalProviderExtensions()) {
		if (pe.isResponsible(model)) {
			pe.complete_JSONArray(model, ruleCall, context, acceptor);
		}
	}

	acceptor.accept(new ConfigurableCompletionProposal("[]", context.getOffset(), 0, 1, null,
			JSONProposalFactory.createStyledString("[...]", "Array"), null, ""));
}
 
Example #21
Source File: JSONProposalProvider.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Propose an empty string literal {@code ""} to complete rule {@code STRING}.
 * 
 * The cursor is set inside the two double quotes.
 */
@Override
public void complete_STRING(EObject model, RuleCall ruleCall, ContentAssistContext context,
		ICompletionProposalAcceptor acceptor) {

	// do not propose a string literal, if a name-value-pair is expected
	if (ruleCall.eContainer() instanceof Assignment
			&& ((Assignment) ruleCall.eContainer()).getFeature().equals("name")) {
		return;
	}

	// only propose if context does not specify a prefix
	if (!context.getPrefix().isEmpty()) {
		return;
	}

	for (IJSONProposalProvider pe : registry.getProposalProviderExtensions()) {
		if (pe.isResponsible(model)) {
			pe.complete_STRING(model, ruleCall, context, acceptor);
		}
	}

	acceptor.accept(new ConfigurableCompletionProposal("\"\"", context.getOffset(), 0, 1, null,
			JSONProposalFactory.createStyledString("\"...\"", "String"), null, ""));
}
 
Example #22
Source File: JSONProposalProvider.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Complete a the rule JSONObject using an empty object literal {@code {}}.
 */
@Override
public void complete_JSONObject(EObject model, RuleCall ruleCall, ContentAssistContext context,
		ICompletionProposalAcceptor acceptor) {

	// only propose if context does not specify a prefix
	if (!context.getPrefix().isEmpty()) {
		return;
	}

	for (IJSONProposalProvider pe : registry.getProposalProviderExtensions()) {
		if (pe.isResponsible(model)) {
			pe.complete_JSONObject(model, ruleCall, context, acceptor);
		}
	}

	acceptor.accept(new ConfigurableCompletionProposal("{}", context.getOffset(), 0, 1, null,
			JSONProposalFactory.createStyledString("{...}", "Object"), null, ""));
}
 
Example #23
Source File: CodetemplatesProposalProvider.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
private void createStringProposal(ContentAssistContext context, ICompletionProposalAcceptor acceptor,
		String feature, RuleCall ruleCall) {
	String proposalText = feature != null ? feature : Strings.toFirstUpper(ruleCall.getRule().getName().toLowerCase());
	proposalText = getValueConverter().toString(proposalText, ruleCall.getRule().getName());
	String displayText = proposalText;
	if (feature != null)
		displayText = displayText + " - " + ruleCall.getRule().getName();
	ICompletionProposal proposal = createCompletionProposal(proposalText, displayText, null, context);
	if (proposal instanceof ConfigurableCompletionProposal) {
		ConfigurableCompletionProposal configurable = (ConfigurableCompletionProposal) proposal;
		configurable.setSelectionStart(configurable.getReplacementOffset() + 1);
		configurable.setSelectionLength(proposalText.length() - 2);
		configurable.setAutoInsertable(false);
		configurable.setSimpleLinkedMode(context.getViewer(), proposalText.charAt(0), '\t');
		
	}
	acceptor.accept(proposal);
}
 
Example #24
Source File: DotColorProposalProvider.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * This customization is needed to render the additional proposal
 * information in html form properly.
 */
@Override
protected ConfigurableCompletionProposal doCreateProposal(String proposal,
		StyledString displayString, Image image, int replacementOffset,
		int replacementLength) {
	return new ConfigurableCompletionProposal(proposal, replacementOffset,
			replacementLength, proposal.length(), image, displayString,
			null, null) {
		@Override
		public IInformationControlCreator getInformationControlCreator() {
			return new IInformationControlCreator() {

				@Override
				public IInformationControl createInformationControl(
						Shell parent) {
					/**
					 * These information has been taken from the
					 * org.eclipse.xtext.ui.editor.hover.html.DefaultEObjectHoverProvider.HoverControlCreator
					 * class
					 */
					String font = "org.eclipse.jdt.ui.javadocfont"; //$NON-NLS-1$
					String tooltipAffordanceString = EditorsUI
							.getTooltipAffordanceString();
					return new XtextBrowserInformationControl(parent, font,
							tooltipAffordanceString);
				}
			};
		}
	};
}
 
Example #25
Source File: DotColorProposalProvider.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void completeStringColor_Name(EObject model, Assignment assignment,
		ContentAssistContext context,
		ICompletionProposalAcceptor acceptor) {
	super.completeStringColor_Name(model, assignment, context, acceptor);
	// start with the default color scheme
	String colorScheme = defaultColorScheme;

	if (model instanceof StringColor
			&& ((StringColor) model).getScheme() != null) {
		colorScheme = ((StringColor) model).getScheme();
	} else if (globalColorScheme != null) {
		colorScheme = globalColorScheme;
	}

	for (String colorName : DotColors
			.getColorNames(colorScheme.toLowerCase())) {
		ICompletionProposal completionProposal = createCompletionProposal(
				colorName, context);
		if (completionProposal instanceof ConfigurableCompletionProposal) {
			ConfigurableCompletionProposal configurableCompletionProposal = (ConfigurableCompletionProposal) completionProposal;
			String colorCode = DotColors.get(colorScheme, colorName);
			// add color image to the proposal
			Image image = DotActivator.getInstance().getImageRegistry()
					.get(colorCode);
			configurableCompletionProposal.setImage(image);
			// add color description to the proposal
			String colorDescription = DotColors.getColorDescription(
					colorScheme.toLowerCase(), colorName, colorCode);
			configurableCompletionProposal
					.setAdditionalProposalInfo(colorDescription);
			acceptor.accept(configurableCompletionProposal);
		}
	}
}
 
Example #26
Source File: DotProposalProvider.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
private void proposeAttributeNames(Context attributeContext,
		ContentAssistContext contentAssistContext,
		ICompletionProposalAcceptor acceptor) {

	Image attributeImage = imageHelper.getImage("attribute.png"); //$NON-NLS-1$
	String format = "%s: Attribute"; //$NON-NLS-1$

	for (String attributeName : dotAttributeNames.get(attributeContext)) {
		StyledString displayString = DotEditorUtils.style(format,
				attributeName);
		ICompletionProposal completionProposal = createCompletionProposal(
				attributeName, displayString, attributeImage,
				contentAssistContext);
		if (completionProposal instanceof ConfigurableCompletionProposal) {
			ConfigurableCompletionProposal configurableCompletionProposal = (ConfigurableCompletionProposal) completionProposal;

			// ensure that the '=' symbol is inserted after the attribute
			// name when applying the proposal
			configurableCompletionProposal.setReplacementString(
					configurableCompletionProposal.getReplacementString()
							+ "="); //$NON-NLS-1$
			configurableCompletionProposal.setCursorPosition(
					configurableCompletionProposal.getCursorPosition() + 1);
		}
		acceptor.accept(completionProposal);
	}
}
 
Example #27
Source File: EclipseBug28DirtyStateModifierContentAssistTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
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 #28
Source File: Bug427440Test.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
public String getProposedText(final ICompletionProposal completionProposal) {
  String proposedText = completionProposal.getDisplayString();
  if ((completionProposal instanceof ConfigurableCompletionProposal)) {
    proposedText = ((ConfigurableCompletionProposal)completionProposal).getReplacementString();
    ConfigurableCompletionProposal.IReplacementTextApplier _textApplier = ((ConfigurableCompletionProposal)completionProposal).getTextApplier();
    if ((_textApplier instanceof ReplacementTextApplier)) {
      ConfigurableCompletionProposal.IReplacementTextApplier _textApplier_1 = ((ConfigurableCompletionProposal)completionProposal).getTextApplier();
      proposedText = ((ReplacementTextApplier) _textApplier_1).getActualReplacementString(((ConfigurableCompletionProposal)completionProposal));
    }
  }
  return proposedText;
}
 
Example #29
Source File: XtendImportingTypesProposalProvider.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected ConfigurableCompletionProposal.IReplacementTextApplier createTextApplier(final ContentAssistContext context, final IScope typeScope, final IQualifiedNameConverter qualifiedNameConverter, final IValueConverter<String> valueConverter) {
  final Predicate<IEObjectDescription> _function = (IEObjectDescription it) -> {
    QualifiedName _name = it.getName();
    return (!Objects.equal(_name, XtendImportedNamespaceScopeProvider.OLD_DATA_ANNOTATION));
  };
  final FilteringScope scope = new FilteringScope(typeScope, _function);
  return super.createTextApplier(context, scope, qualifiedNameConverter, valueConverter);
}
 
Example #30
Source File: XbaseReferenceProposalCreator.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected Function<IEObjectDescription, ICompletionProposal> getWrappedFactory(EObject model, EReference reference,
		final Function<IEObjectDescription, ICompletionProposal> proposalFactory) {
	if (!TypesPackage.Literals.JVM_TYPE.isSuperTypeOf(getEReferenceType(model, reference))) {
		return new Function<IEObjectDescription, ICompletionProposal>() {

			@Override
			public ICompletionProposal apply(IEObjectDescription from) {
				ICompletionProposal result = proposalFactory.apply(from);
				if (EcoreUtil2.isAssignableFrom(TypesPackage.Literals.JVM_FEATURE, from.getEClass())) {
					if (result instanceof ConfigurableCompletionProposal) {
						EObject eObjectOrProxy = from.getEObjectOrProxy();
						if (eObjectOrProxy.eIsProxy()) {
							Image img = null;
							if (EcoreUtil2.isAssignableFrom(TypesPackage.Literals.JVM_CONSTRUCTOR, from.getEClass())) {
								img = computeConstructorImage(false, false, Flags.AccPublic, JavaElementImageDescriptor.CONSTRUCTOR);
							} else if (EcoreUtil2.isAssignableFrom(TypesPackage.Literals.JVM_OPERATION, from.getEClass())) {
								img = computeMethodImage(false, Flags.AccPublic, 0);
							} else if (EcoreUtil2.isAssignableFrom(TypesPackage.Literals.JVM_FIELD, from.getEClass())) {
								img = computeFieldImage(false, Flags.AccPublic, 0);
							}
							if (img != null) {
								((ConfigurableCompletionProposal) result).setImage(img);
							}
						} else {
							((ConfigurableCompletionProposal) result).setImage(computeImage((JvmFeature)eObjectOrProxy));
						}
					}
				} 
				else if (from instanceof SimpleIdentifiableElementDescription && isLocalVarOrFormalParameter(from)){
					if (result instanceof ConfigurableCompletionProposal) {
						((ConfigurableCompletionProposal) result).setImage(JavaPlugin.getImageDescriptorRegistry().get(JavaPluginImages.DESC_OBJS_LOCAL_VARIABLE));
					}
				}
				return result;
			}
		};
	}
	return super.getWrappedFactory(model, reference, proposalFactory);
}