org.eclipse.jface.text.contentassist.ICompletionProposal Java Examples

The following examples show how to use org.eclipse.jface.text.contentassist.ICompletionProposal. 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: 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 #2
Source File: TexCompletionProcessor.java    From texlipse with Eclipse Public License 1.0 6 votes vote down vote up
private ICompletionProposal[] computeStyleProposals(String selectedText,
		Point selectedRange) {
	if (styleManager == null) {
		styleManager = TexStyleCompletionManager.getInstance();
	}
	return styleManager.getStyleCompletions(selectedText, selectedRange);
	/*
	 * ICompletionProposal[] result = new
	 * ICompletionProposal[STYLETAGS.length];
	 * 
	 * // Loop through all styles for (int i = 0; i < STYLETAGS.length; i++)
	 * { String tag = STYLETAGS[i];
	 * 
	 * // Compute replacement text String replacement = "{" + tag + " " +
	 * selectedText + "}";
	 * 
	 * // Derive cursor position int cursor = tag.length() + 2;
	 * 
	 * // Compute a suitable context information IContextInformation
	 * contextInfo = new ContextInformation(null, STYLELABELS[i]+" Style");
	 * 
	 * // Construct proposal result[i] = new CompletionProposal(replacement,
	 * selectedRange.x, selectedRange.y, cursor, null, STYLELABELS[i],
	 * contextInfo, replacement); } return result;
	 */
}
 
Example #3
Source File: ContenAssistProcessorExt.java    From goclipse with Eclipse Public License 1.0 6 votes vote down vote up
@Override
	public final ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) {
		resetComputeState();
		
		// The code below has been commented, it causes a bug with templates with "${word_selection} " usage,
		// and it's not clear this functionality made sense in the first place.
		
//		if(viewer instanceof LangSourceViewer) {
//			LangSourceViewer sourceViewer = (LangSourceViewer) viewer;
//			if(sourceViewer.getSelectedRange().y > 0) {
//				// Correct the invocation offset for content assist. 
//				// The issue is that if text is selected, the cursor can either be on the left, or the right
//				// but the offset used will always be the left side of the selection, unless we correct it.
//				
//				int caretOffset = sourceViewer.getTextWidget().getCaretOffset();
//				offset = sourceViewer.widgetOffset2ModelOffset(caretOffset);
//			}
//		}
		
		return doComputeCompletionProposals(viewer, offset);
	}
 
Example #4
Source File: RepeatedContentAssistProcessor.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) {
	ModeAware proposalProvider = getModeAwareProposalProvider();
	if (proposalProvider == null)
		return new ICompletionProposal[0];
	int i = 0;
	CompletionProposalComputer proposalComputer = createCompletionProposalComputer(viewer, offset);
	while(i++ < 1000) { // just to prevent endless loop in case #isLastMode has an error
		proposalProvider.nextMode();
		if (currentAssistant != null)
			currentAssistant.setStatusMessage(getStatusMessage());
		ICompletionProposal[] result = computeCompletionProposals(xtextDocumentUtil.getXtextDocument(viewer), proposalComputer);
		if (result != null && result.length > 0)
			return result;
		if (proposalProvider.isLastMode()) {
			return new ICompletionProposal[0];	
		}
	}
	throw new IllegalStateException("#isLastMode did not return true for 1000 times");
}
 
Example #5
Source File: VariableNamesProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public ICompletionProposal[] computeCompletionProposals(IContentAssistSubjectControl contentAssistSubject, int documentOffset) {
	if (fTempNameProposals.length == 0)
		return null;
	String input= contentAssistSubject.getDocument().get();

	ArrayList<JavaCompletionProposal> proposals= new ArrayList<JavaCompletionProposal>();
	String prefix= input.substring(0, documentOffset);
	Image image= fImageRegistry.get(fProposalImageDescriptor);
	for (int i= 0; i < fTempNameProposals.length; i++) {
		String tempName= fTempNameProposals[i];
		if (tempName.length() == 0 || ! tempName.startsWith(prefix))
			continue;
		JavaCompletionProposal proposal= new JavaCompletionProposal(tempName, 0, input.length(), image, tempName, 0);
		proposals.add(proposal);
	}
	fErrorMessage= proposals.size() > 0 ? null : JavaUIMessages.JavaEditor_codeassist_noCompletions;
	return proposals.toArray(new ICompletionProposal[proposals.size()]);
}
 
Example #6
Source File: ActiveCodeContentAssistProcessor.java    From xds-ide with Eclipse Public License 1.0 6 votes vote down vote up
private void addModulaSymbolToCompletionProposals(List<ICompletionProposal> completionProposals, Set<ICompletionProposal> proposalsSet,
        IModulaSymbol s, Predicate<IModulaSymbol> symbolFilter) 
{
    if (s == null || s.getName() == null) {
        return; // parser sometimes may produce it 
    }

    if (symbolFilter != null && !symbolFilter.test(s)) {
        return;
    }
    
    String proposalText =  s.getName();
    
    String filterPrefix = context.getBeforeCursorWordPart();
    if (filterPrefix != null && !StringUtils.startsWithIgnoreCase(proposalText, filterPrefix)) {
        return;
    }

    addProposal(completionProposals, proposalsSet, s);
}
 
Example #7
Source File: CompletionProposalPopup.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
private void setItem(TableItem[] items, int i)
{
	TableItem item = items[i];
	ICompletionProposal proposal = fFilteredProposals[i];
	item.setData("isAlt", "false");
		
	item.setImage(0, proposal.getImage());
	item.setText(1, proposal.getDisplayString());
	boolean isItalics = false;
	if (!(isItalics))
	{
		setDefaultStyle(item);
    }
	item.setData(proposal);

}
 
Example #8
Source File: JavaCompletionProposalComputer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private List<IContextInformation> addContextInformations(JavaContentAssistInvocationContext context, int offset) {
	List<ICompletionProposal> proposals= internalComputeCompletionProposals(offset, context);
	List<IContextInformation> result= new ArrayList<IContextInformation>(proposals.size());
	List<IContextInformation> anonymousResult= new ArrayList<IContextInformation>(proposals.size());

	for (Iterator<ICompletionProposal> it= proposals.iterator(); it.hasNext();) {
		ICompletionProposal proposal= it.next();
		IContextInformation contextInformation= proposal.getContextInformation();
		if (contextInformation != null) {
			ContextInformationWrapper wrapper= new ContextInformationWrapper(contextInformation);
			wrapper.setContextInformationPosition(offset);
			if (proposal instanceof AnonymousTypeCompletionProposal)
				anonymousResult.add(wrapper);
			else
				result.add(wrapper);
		}
	}

	if (result.size() == 0)
		return anonymousResult;
	return result;

}
 
Example #9
Source File: CorrectionCommandHandler.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Try to execute the correction command.
 * 
 * @return <code>true</code> iff the correction could be started
 * @since 3.6
 */
public boolean doExecute() {
	ISelection selection= fEditor.getSelectionProvider().getSelection();
	ICompilationUnit cu= JavaUI.getWorkingCopyManager().getWorkingCopy(fEditor.getEditorInput());
	IAnnotationModel model= JavaUI.getDocumentProvider().getAnnotationModel(fEditor.getEditorInput());
	if (selection instanceof ITextSelection && cu != null && model != null) {
		if (! ActionUtil.isEditable(fEditor)) {
			return false;
		}
		ICompletionProposal proposal= findCorrection(fId, fIsAssist, (ITextSelection) selection, cu, model);
		if (proposal != null) {
			invokeProposal(proposal, ((ITextSelection) selection).getOffset());
			return true;
		}
	}
	return false;
}
 
Example #10
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 #11
Source File: ActiveCodeContentAssistProcessor.java    From xds-ide with Eclipse Public License 1.0 6 votes vote down vote up
private void dottedExpressionProposals(CompletionContext context,
		List<ICompletionProposal> proposals, Set<ICompletionProposal> proposalsSet) {
	Predicate<IModulaSymbol> symbolFilter = createSymbolFilter(context);
	IModulaSymbol symbol = context.getReferencedSymbol();
	if (symbol == null) {
		return;
	}
	if (symbol instanceof IModuleAliasSymbol) {
		symbol = ((IModuleAliasSymbol)symbol).getReference();
       }
	ITypeSymbol typeSymbol = JavaUtils.as(ITypeSymbol.class, symbol);
	if (typeSymbol != null) {
		addCompletionProposalsFromTypeSymbol(proposals, proposalsSet, typeSymbol, symbolFilter);
	}
	else {
		IModuleSymbol moduleSymbol = JavaUtils.as(IModuleSymbol.class, symbol);
		if (moduleSymbol != null) {
			addCompletionProposalsFromDefinitionModule(proposals, proposalsSet, moduleSymbol, symbolFilter);
		}
	}
}
 
Example #12
Source File: ModulaAssistProcessor2.java    From xds-ide with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer,
		int offset) {
	CompletionContext context = computeContext(viewer, offset);
	List<ICompletionProposal> completionProposals = new ArrayList<ICompletionProposal>();
	doComputeCompletionProposals(context, completionProposals);
	
	if (completionProposals.isEmpty() /*&& !isAstUpToDate()*/) {
		IModuleSymbol moduleSymbol = context.getModuleSymbol();
		if (moduleSymbol == null) {
			EmptyCompletionProposal emptyCompletionProposal = new EmptyCompletionProposal(Messages.XdsOutlinePage_Loading, 
					LOADING_IMAGE, viewer.getSelectedRange().x);
			return new ICompletionProposal[]{emptyCompletionProposal, emptyCompletionProposal};
		}
		else {
			return null;
		}
	}
	return completionProposals.toArray(new ICompletionProposal[0]);
}
 
Example #13
Source File: JsniMethodBodyCompletionProposalComputer.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Proposes a JSNI method of the form
 * <code>this.property = newPropertyValue</code> if the java method has a
 * single parameter.
 */
private void maybeProposePropertyWrite(IJavaProject project, IMethod method,
    String propertyName, int invocationOffset, int indentationUnits,
    boolean isStatic, List<ICompletionProposal> proposals, int numCharsFilled, 
    int numCharsToOverwrite) throws JavaModelException {
  String[] parameterNames = method.getParameterNames();
  if (parameterNames.length == 1 && propertyName.length() > 0) {
    String expression = createJsPropertyWriteExpression(propertyName,
        parameterNames[0], isStatic);

    String code = createJsniBlock(project, expression, indentationUnits);
    proposals.add(createProposal(method.getFlags(), code, invocationOffset,
        numCharsFilled, numCharsToOverwrite, expression));
  }
}
 
Example #14
Source File: CompletionProposalPopup.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Selects the entry with the given index in the proposal selector and feeds the selection to the additional info
 * controller.
 * 
 * @param index
 *            the index in the list
 * @param smartToggle
 *            <code>true</code> if the smart toggle key has been pressed
 * @param autoScroll
 *            Do we scroll the item into view at the middle of the list
 * @since 2.1
 */
private void selectProposal(int index, boolean smartToggle, boolean autoScroll)
{
	if (fFilteredProposals == null)
	{
		return;
	}

	ICompletionProposal oldProposal = getSelectedProposal();
	if (oldProposal instanceof ICompletionProposalExtension2 && fViewer != null)
	{
		((ICompletionProposalExtension2) oldProposal).unselected(fViewer);
	}

	ICompletionProposal proposal = fFilteredProposals[index];
	if (proposal instanceof ICompletionProposalExtension2 && fViewer != null)
	{
		((ICompletionProposalExtension2) proposal).selected(fViewer, smartToggle);
	}

	fLastProposal = proposal;
	fProposalTable.setSelection(index);

	if (autoScroll)
	{
		setScroll(index);
	}
	fProposalTable.showSelection();

	if (fAdditionalInfoController != null)
	{
	    fAdditionalInfoController.handleTableSelectionChanged();
    }
}
 
Example #15
Source File: UiBinderXmlCompletionProcessor.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
private List<ICompletionProposal> getWstCompletionProposals(
    ITextViewer textViewer, int documentPosition) {
  ICompletionProposal[] proposals = super.computeCompletionProposals(
      textViewer, documentPosition);
  if (proposals == null || proposals.length == 0) {
    return null;
  }

  return new ArrayList<ICompletionProposal>(Arrays.asList(proposals));
}
 
Example #16
Source File: ContentAssistNoTerminalExtensionContentAssistTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void expectedAutocompletionAfterTwoCharacters() throws Exception {
	ICompletionProposal[] proposals = newBuilder().insert("pr<|>").getProposalsAtCursorIndicator();
	assertEquals(4, proposals.length);
	assertEquals("primersite", proposals[0].getDisplayString());
	assertEquals("promoter", proposals[1].getDisplayString());
	assertEquals("proteasesite", proposals[2].getDisplayString());
	assertEquals("proteinstab", proposals[3].getDisplayString());
}
 
Example #17
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 #18
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 #19
Source File: AbstractAnnotationHover.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void createCompletionProposalsControl(Composite parent, ICompletionProposal[] proposals) {
	Composite composite= new Composite(parent, SWT.NONE);
	composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
	GridLayout layout2= new GridLayout(1, false);
	layout2.marginHeight= 0;
	layout2.marginWidth= 0;
	layout2.verticalSpacing= 2;
	composite.setLayout(layout2);

	Label separator= new Label(composite, SWT.SEPARATOR | SWT.HORIZONTAL);
	GridData gridData= new GridData(SWT.FILL, SWT.CENTER, true, false);
	separator.setLayoutData(gridData);

	Label quickFixLabel= new Label(composite, SWT.NONE);
	GridData layoutData= new GridData(SWT.BEGINNING, SWT.CENTER, false, false);
	layoutData.horizontalIndent= 4;
	quickFixLabel.setLayoutData(layoutData);
	String text;
	if (proposals.length == 1) {
		text= JavaHoverMessages.AbstractAnnotationHover_message_singleQuickFix;
	} else {
		text= Messages.format(JavaHoverMessages.AbstractAnnotationHover_message_multipleQuickFix, new Object[] { String.valueOf(proposals.length) });
	}
	quickFixLabel.setText(text);

	setColorAndFont(composite, parent.getForeground(), parent.getBackground(), JFaceResources.getDialogFont());
	createCompletionProposalsList(composite, proposals);
}
 
Example #20
Source File: ContentAssistNoTerminalExtensionContentAssistTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void expectedAutocompletionAfterTwoCharacters4() throws Exception {
	ICompletionProposal[] proposals = newBuilder().insert("plain pr<|>").getProposalsAtCursorIndicator();
	assertEquals(4, proposals.length);
	assertEquals("primersite", proposals[0].getDisplayString());
	assertEquals("promoter", proposals[1].getDisplayString());
	assertEquals("proteasesite", proposals[2].getDisplayString());
	assertEquals("proteinstab", proposals[3].getDisplayString());
}
 
Example #21
Source File: XtextProposalProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected Set<String> completeStructuralFeatures(ContentAssistContext context, Function<IEObjectDescription, ICompletionProposal> factory,
		ICompletionProposalAcceptor acceptor,
		Iterable<? extends EStructuralFeature> features) {
	if (features != null) {
		Set<String> processedFeatures = newHashSet();
		for (EStructuralFeature feature : features) {
			acceptor.accept(createFeatureProposal(feature, 4, factory, context));
			processedFeatures.add(feature.getName());
		}
		return processedFeatures;
	}
	return null;
}
 
Example #22
Source File: XtextQuickAssistProcessor.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @since 2.3
 */
protected List<ICompletionProposal> createQuickfixes(IQuickAssistInvocationContext invocationContext, Set<Annotation> applicableAnnotations) {
   	List<ICompletionProposal> result = Lists.newArrayList();
   	ISourceViewer sourceViewer = invocationContext.getSourceViewer();
	IAnnotationModel annotationModel = sourceViewer.getAnnotationModel();
	IXtextDocument xtextDocument = xtextDocumentUtil.getXtextDocument(sourceViewer);
   	for(Annotation annotation : applicableAnnotations) {
		if (annotation instanceof SpellingAnnotation) {
			SpellingProblem spellingProblem = ((SpellingAnnotation) annotation).getSpellingProblem();
			ICompletionProposal[] proposals = spellingProblem.getProposals();
			if (proposals != null) {
				result.addAll(asList(proposals));
			}
		} else {
			final Issue issue = issueUtil.getIssueFromAnnotation(annotation);
			Position pos = annotationModel.getPosition(annotation);
			if (issue != null && pos != null) {
				@SuppressWarnings("deprecation")
				Iterable<IssueResolution> resolutions = getResolutions(issue, xtextDocument);
				if (resolutions.iterator().hasNext()) {
					for (IssueResolution resolution : resolutions) {
						result.add(create(pos, resolution));
					}
				}
			}
		}
	}
   	return result;
   }
 
Example #23
Source File: ContentAssistProcessorTestBuilder.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public ICompletionProposal[] computeCompletionProposals(final String currentModelToParse, int cursorPosition)
		throws Exception {
	try {
		final IXtextDocument xtextDocument = getDocument(currentModelToParse);
		return computeCompletionProposals(xtextDocument, cursorPosition);
	} finally {
		if (announceDirtyState) {
			dirtyStateManager.discardDirtyState(dirtyResource);
		}
	}
}
 
Example #24
Source File: ContentAssistProcessorTestBuilder.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Asserts the presence of at least single the proposal with the given replacement string
 * at the cursor position {@code <|>} in the currently configured {@link #model}.
 */
public ProposalTester assertProposalAtCursor(String expectedText) throws Exception {
	ICompletionProposal[] proposals = getProposalsAtCursorIndicator();
	for(ICompletionProposal proposal: proposals) {
		if (expectedText.equals(toString(proposal))) {
			return new ProposalTester(proposal);
		}
	}
	Assert.fail("No such proposal: " + expectedText + " Found: " + toString(proposals));
	return null;
}
 
Example #25
Source File: ReplacementCompletionProposal.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Creates a {@link ReplacementCompletionProposal} with the given text and
 * position, but attempts to copy additional information from an existing
 * {@link ICompletionProposal}.
 * 
 * @param text the replacement text
 * @param offset the offset to the text to replace
 * @param length the length of the text to replace
 * @param existingCompletionProposal the existing {@link ICompletionProposal}
 *          to copy info from
 * @return an {@link ReplacementCompletionProposal}
 */
public static ReplacementCompletionProposal fromExistingCompletionProposal(
    String text, int offset, int length,
    ICompletionProposal existingCompletionProposal) {
  if (existingCompletionProposal != null) {
    return new ReplacementCompletionProposal(text, offset, length,
        ReplacementCompletionProposal.DEFAULT_CURSOR_POSITION,
        existingCompletionProposal.getAdditionalProposalInfo(),
        existingCompletionProposal.getDisplayString(),
        existingCompletionProposal.getImage());
  } else {
    return new ReplacementCompletionProposal(text, offset, length);
  }
}
 
Example #26
Source File: SpellingQuickfixTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testSpellingQuickfixInMlComment() throws Exception {
	xtextEditor.getDocument().set(MODEL_WITH_SPELLING_QUICKFIX_IN_ML_COLMMENT);
	ICompletionProposal[] quickAssistProposals = computeQuickAssistProposals(getDocument().getLength());
	List<ICompletionProposal> proposals = Arrays.asList(quickAssistProposals);
	assertSpellingQuickfixProposals(proposals);
}
 
Example #27
Source File: ContractInputCompletionProposalComputerTest.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void should_computeCompletionProposals_returns_no_proposals_for_unsupported_expression() throws Exception {
    when(contentAssistContext.getPerceivedCompletionNode()).thenReturn(null);
    doReturn(Collections.emptyList()).when(proposalComputer).getContractInputs(context);
    final List<ICompletionProposal> proposals = proposalComputer.computeCompletionProposals(context, null);
    assertThat(proposals).isEmpty();
}
 
Example #28
Source File: CompletionProposalPopup.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Create the "no proposals" proposal
 * 
 * @return
 */
private ICompletionProposal[] createNoProposal()
{
	fEmptyProposal.fOffset = fFilterOffset;
	fEmptyProposal.fDisplayString = JFaceTextMessages.
			getString("CompletionProposalPopup.no_proposals");  //$NON-NLS-1$
	modifySelection(-1, -1); // deselect everything
	return new ICompletionProposal[] { fEmptyProposal };
}
 
Example #29
Source File: ContentAssistantExt.java    From goclipse with Eclipse Public License 1.0 5 votes vote down vote up
protected String getSortString(ICompletionProposal proposal) {
	String sortString;
	if(proposal instanceof LangCompletionProposal) {
		LangCompletionProposal langProposal = (LangCompletionProposal) proposal;
		sortString = langProposal.getSortString();
	} else {
		sortString = proposal.getDisplayString();
	}
	return sortString == null ? "\uFFFF" : sortString;
}
 
Example #30
Source File: JsniMethodBodyCompletionProposalComputerTest.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
/**
 *  If length of line at 'lineNum' is 'len', then validate all proposals for invocation
 *  index varying from '(len - numCharsCompleted)' to 'len'.
 */
private static void validateExpectedProposals(IJavaProject javaProject,
    String fullyQualifiedClassName, String source, int lineNum, int numCharsCompleted,
    String... expectedProposals) throws CoreException, BadLocationException {
  IProgressMonitor monitor = new NullProgressMonitor();

  ICompilationUnit iCompilationUnit = JavaProjectUtilities.createCompilationUnit(
      javaProject, fullyQualifiedClassName, source);
  CompilationUnitEditor cuEditor = (CompilationUnitEditor) JavaUI.openInEditor(iCompilationUnit);

  ISourceViewer viewer = cuEditor.getViewer();
  IDocument document = viewer.getDocument();

  IRegion lineInformation = document.getLineInformation(lineNum);
  JsniMethodBodyCompletionProposalComputer jcpc = new JsniMethodBodyCompletionProposalComputer();

  for (int numCharsToOverwrite = 0; numCharsToOverwrite <= numCharsCompleted;
      numCharsToOverwrite++){
    int invocationOffset = lineInformation.getOffset()
        + lineInformation.getLength() - numCharsToOverwrite;
    JavaContentAssistInvocationContext context = new JavaContentAssistInvocationContext(
        viewer, invocationOffset, cuEditor);
    List<ICompletionProposal> completions = jcpc.computeCompletionProposals(
        context, monitor);

    int indentationUnits = JsniMethodBodyCompletionProposalComputer.measureIndentationUnits(
        document, lineNum, lineInformation.getOffset(), javaProject);
    List<String> expected = createJsniBlocks(javaProject, indentationUnits,
        expectedProposals);
    for (int i = 0; i < expected.size(); i++){
      String expectedBlock = expected.get(i).substring(numCharsCompleted - numCharsToOverwrite);
      expected.set(i, expectedBlock);
    }
    assertExpectedProposals(expected, completions, numCharsToOverwrite);
  }
}