Java Code Examples for org.eclipse.xtext.ui.editor.contentassist.ConfigurableCompletionProposal#setSelectionStart()

The following examples show how to use org.eclipse.xtext.ui.editor.contentassist.ConfigurableCompletionProposal#setSelectionStart() . 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
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 2
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 3
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 4
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 5
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 6
Source File: N4JSReplacementTextApplier.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
private void adjustCursorPositionIfRequested(ConfigurableCompletionProposal proposal) {
	final int offset = ConfigurableCompletionProposalExtensions.getCursorOffset(proposal);
	if (offset != 0) {
		proposal.setCursorPosition(proposal.getCursorPosition() + offset);

		// do not attempt to set up linked mode in a disposed UI
		if (viewer.getTextWidget() != null && !viewer.getTextWidget().isDisposed()) {
			final int pos = proposal.getReplacementOffset() + proposal.getCursorPosition();
			proposal.setSelectionStart(pos);
			proposal.setSelectionLength(0);
			proposal.setSimpleLinkedMode(viewer, '\t', '\n', '\r');
		}
	}
}
 
Example 7
Source File: CodetemplatesProposalProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
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 8
Source File: CodetemplatesProposalProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
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 9
Source File: ProjectionAwareProposalAcceptor.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void accept(ICompletionProposal proposal) {
	if (proposal != null) {
		ConfigurableCompletionProposal configurableProposal = 
			(ConfigurableCompletionProposal) proposal;
		configurableProposal.setSelectionStart(evaluatedTemplate.getOriginalOffset(configurableProposal.getSelectionStart()));
		configurableProposal.setReplacementOffset(evaluatedTemplate.getOriginalOffset(configurableProposal.getReplacementOffset()));
		acceptor.accept(proposal);
	}
}
 
Example 10
Source File: TerminalsProposalProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public void complete_ID(EObject model, RuleCall ruleCall, final ContentAssistContext context,
		ICompletionProposalAcceptor acceptor) {
	if (doCreateIdProposals()) {
		PrefixMatcher newMatcher = new PrefixMatcher() {
			@Override
			public boolean isCandidateMatchingPrefix(String name, String prefix) {
				String strippedName = name;
				if (name.startsWith("^") && !prefix.startsWith("^")) {
					strippedName = name.substring(1);
				}
				return context.getMatcher().isCandidateMatchingPrefix(strippedName, prefix);
			}
		};
		ContentAssistContext myContext = context.copy().setMatcher(newMatcher).toContext();
		String feature = getAssignedFeature(ruleCall);
		String proposalText = feature != null ? feature : Strings.toFirstUpper(ruleCall.getRule().getName().toLowerCase());
		String displayText = proposalText;
		if (feature != null)
			displayText = proposalText + " - " + ruleCall.getRule().getName();
		proposalText = getValueConverter().toString(proposalText, ruleCall.getRule().getName());
		ICompletionProposal proposal = createCompletionProposal(proposalText, displayText, null, myContext);
		if (proposal instanceof ConfigurableCompletionProposal) {
			ConfigurableCompletionProposal configurable = (ConfigurableCompletionProposal) proposal;
			configurable.setSelectionStart(configurable.getReplacementOffset());
			configurable.setSelectionLength(proposalText.length());
			configurable.setAutoInsertable(false);
			configurable.setSimpleLinkedMode(myContext.getViewer(), '\t', ' ');
		}
		acceptor.accept(proposal);
	}
}