Java Code Examples for org.eclipse.jface.text.contentassist.ICompletionProposal#getDisplayString()

The following examples show how to use org.eclipse.jface.text.contentassist.ICompletionProposal#getDisplayString() . 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: CompositeQuickfixTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testMultiQuickAssist() throws Exception {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("c {\tbadname { foo {} } }");
  _builder.newLine();
  _builder.append("a {\tbadname { bar {} } }");
  _builder.newLine();
  final IFile resource = this.dslFile(_builder);
  final XtextEditor editor = this.openEditor(resource);
  final ICompletionProposal[] proposals = this.computeQuickAssistProposals(editor, 1);
  StringConcatenation _builder_1 = new StringConcatenation();
  _builder_1.append("Fix Bad Names");
  final Function1<ICompletionProposal, String> _function = (ICompletionProposal it) -> {
    return it.getDisplayString();
  };
  Assert.assertEquals(_builder_1.toString(), IterableExtensions.join(ListExtensions.<ICompletionProposal, String>map(((List<ICompletionProposal>)Conversions.doWrapArray(proposals)), _function), "\n"));
  IterableExtensions.<ICompletionProposal>head(((Iterable<ICompletionProposal>)Conversions.doWrapArray(proposals))).apply(editor.getDocument());
  StringConcatenation _builder_2 = new StringConcatenation();
  _builder_2.append("newElement { } c {\tgoodname { foo {} } }");
  _builder_2.newLine();
  _builder_2.append("a {\tbadname { bar {} } }");
  _builder_2.newLine();
  Assert.assertEquals(_builder_2.toString(), editor.getDocument().get());
}
 
Example 2
Source File: CompositeQuickfixTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testNoCrossRef() throws Exception {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("fixable_a {\tref fixable_b }");
  _builder.newLine();
  _builder.append("fixable_b {\tref fixable_a }");
  _builder.newLine();
  final IFile resource = this.dslFile(_builder);
  final XtextEditor editor = this.openEditor(resource);
  final ICompletionProposal[] proposals = this.computeQuickAssistProposals(editor, 1);
  StringConcatenation _builder_1 = new StringConcatenation();
  _builder_1.append("rename fixable");
  final Function1<ICompletionProposal, String> _function = (ICompletionProposal it) -> {
    return it.getDisplayString();
  };
  Assert.assertEquals(_builder_1.toString(), IterableExtensions.join(ListExtensions.<ICompletionProposal, String>map(((List<ICompletionProposal>)Conversions.doWrapArray(proposals)), _function), "\n"));
  IterableExtensions.<ICompletionProposal>head(((Iterable<ICompletionProposal>)Conversions.doWrapArray(proposals))).apply(editor.getDocument());
  StringConcatenation _builder_2 = new StringConcatenation();
  _builder_2.append("fixedName {\tref fixable_b }");
  _builder_2.newLine();
  _builder_2.append("fixable_b {\tref fixable_a }");
  _builder_2.newLine();
  Assert.assertEquals(_builder_2.toString(), editor.getDocument().get());
}
 
Example 3
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 4
Source File: HTMLContentAssistProcessor.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
/**
 * setSelectedProposal
 * 
 * @param prefix
 * @param proposals
 */
protected void setSelectedProposal(String prefix, ICompletionProposal[] proposals)
{
	if (prefix == null || prefix.equals(StringUtil.EMPTY) || proposals == null)
	{
		return;
	}

	for (ICompletionProposal proposal : proposals)
	{
		String displayString = proposal.getDisplayString();
		int comparison = displayString.compareToIgnoreCase(prefix);

		if (comparison >= 0)
		{
			if (displayString.toLowerCase().startsWith(prefix.toLowerCase()))
			{
				if (displayString.startsWith(prefix))
				{
					((ICommonCompletionProposal) proposal).setRelevance(ICommonCompletionProposal.RELEVANCE_HIGH);
				}
				else
				{
					((ICommonCompletionProposal) proposal).setRelevance(ICommonCompletionProposal.RELEVANCE_MEDIUM);
				}
			}
		}
	}
}
 
Example 5
Source File: SnippetsCompletionProcessor.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
/**
 * setSelectedProposal
 * 
 * @param prefix
 * @param proposals
 */
public void setSelectedProposal(String prefix, ICompletionProposal[] proposals)
{
	if (prefix == null || prefix.equals(StringUtil.EMPTY) || proposals == null)
	{
		return;
	}

	for (ICompletionProposal proposal : proposals)
	{
		String displayString = proposal.getDisplayString();
		if (proposal instanceof SnippetTemplateProposal)
		{
			displayString = ((SnippetTemplateProposal) proposal).getActivationString();
		}
		int comparison = displayString.compareToIgnoreCase(prefix);

		if (comparison >= 0)
		{
			if (displayString.toLowerCase().startsWith(prefix.toLowerCase()))
			{
				if (displayString.startsWith(prefix))
				{
					((ICommonCompletionProposal) proposal).setRelevance(ICommonCompletionProposal.RELEVANCE_HIGH);
				}
				else
				{
					((ICommonCompletionProposal) proposal).setRelevance(ICommonCompletionProposal.RELEVANCE_MEDIUM);
				}
			}
		}
	}
}
 
Example 6
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 7
Source File: WidgetProposalComputer.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected ICompletionProposal createProposal(CompletionProposal proposal) {
  if (proposal.getKind() != CompletionProposal.TYPE_REF) {
    return null;
  }

  // NOTE: Resulting qualified name is dot-separated, even for enclosing
  // types. Generic signatures are not produced. See
  // org.eclipse.jdt.internal.codeassist.CompletionEngine.createTypeProposal.
  String qualifiedTypeName = String.valueOf(Signature.toCharArray(proposal.getSignature()));
  String typePackage = JavaUtilities.getPackageName(qualifiedTypeName);
  String typeSimpleName = Signature.getSimpleName(qualifiedTypeName);

  if (packageName != null && !typePackage.equals(packageName)) {
    return null;
  }

  ICompletionProposal javaCompletionProposal = JavaContentAssistUtilities.getJavaCompletionProposal(
      proposal, getContext(), getJavaProject());
  if (javaCompletionProposal != null) {
    return new WidgetProposal(typeSimpleName, typePackage, null,
        javaCompletionProposal.getDisplayString(),
        javaCompletionProposal.getImage(), getReplaceOffset(),
        getReplaceLength(), packageManager);
  } else {
    return new WidgetProposal(typeSimpleName, typePackage, null,
        typeSimpleName, null, getReplaceOffset(), getReplaceLength(),
        packageManager);
  }
}
 
Example 8
Source File: AbstractAcfContentAssistTest.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Gets the completion proposal display strings.
 *
 * @param computedProposals
 *          the computed proposals
 * @return the completion proposal display strings
 */
private String getCompletionProposalDisplayStrings(final ICompletionProposal... computedProposals) {
  String result = "";
  for (ICompletionProposal p : computedProposals) {
    result += p.getDisplayString() + SEPARATOR; // NOPMD
  }
  if (result != null && result.length() > SEPARATOR.length()) {
    return result.substring(0, result.length() - SEPARATOR.length());
  }
  return null;
}
 
Example 9
Source File: AbstractContentAssistTest.java    From sarl with Apache 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 10
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 11
Source File: TwoContextsContentAssistTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void completeKeyword(Keyword keyword, final ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
	super.completeKeyword(keyword, context, new FilteringCompletionProposalAcceptor(acceptor, new Predicate<ICompletionProposal>() {
		@Override
		public boolean apply(ICompletionProposal input) {
			if (!input.getDisplayString().startsWith(context.getPrefix()))
				throw new IllegalStateException("proposed element '"+input.getDisplayString()+"' does not start with '"+ context.getPrefix()+"'");
			return true;
		}
	}));
}
 
Example 12
Source File: CommonContentAssistProcessor.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
/**
 * setSelectedProposal
 * 
 * @param prefix
 * @param proposals
 */
protected void setSelectedProposal(String prefix, ICompletionProposal[] proposals)
{
	if (StringUtil.isEmpty(prefix) || proposals == null)
	{
		return;
	}

	for (ICompletionProposal proposal : proposals)
	{
		String displayString = proposal.getDisplayString();
		int comparison = displayString.compareToIgnoreCase(prefix);

		if (comparison >= 0)
		{
			if (displayString.toLowerCase().startsWith(prefix.toLowerCase()))
			{
				if (displayString.startsWith(prefix))
				{
					((ICommonCompletionProposal) proposal).setRelevance(ICommonCompletionProposal.RELEVANCE_HIGH);
				}
				else
				{
					((ICommonCompletionProposal) proposal).setRelevance(ICommonCompletionProposal.RELEVANCE_MEDIUM);
				}
			}
		}
	}
}
 
Example 13
Source File: ContentAssistProcessorTestBuilder.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
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;
}
 
Example 14
Source File: ContentAssistProcessorTestBuilder.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public List<String> toDisplayString(ICompletionProposal[] proposals) {
	if (proposals == null)
		return Collections.emptyList();
	List<String> res = new ArrayList<String>(proposals.length);
	for (ICompletionProposal proposal : proposals) {
		String proposedText = proposal.getDisplayString();
		res.add(proposedText);
	}
	Collections.sort(res);
	return res;
}
 
Example 15
Source File: ContentAssistProcessorTestBuilder.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
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;
}
 
Example 16
Source File: ContentAssistTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * see https://bugs.eclipse.org/bugs/show_bug.cgi?id=438191
 */
@Test public void testSubtypeProposals() throws Exception {
	if (isJDT_3_6_orLater()) {
		ICompletionProposal[] proposals = newBuilder().append("import java.util.* subtype I").computeCompletionProposals();
		for (ICompletionProposal iCompletionProposal : proposals) {
			String displayString = iCompletionProposal.getDisplayString();
			assertFalse(displayString, displayString.contains(Iterable.class.getSimpleName()));
		}
	}
}
 
Example 17
Source File: CompositeQuickfixTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testSimpleQuickAssist() throws Exception {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("\"bad doc\"");
  _builder.newLine();
  _builder.append("Foo { ref Bor }");
  _builder.newLine();
  _builder.append("\"bad doc\"");
  _builder.newLine();
  _builder.append("Bor { }");
  _builder.newLine();
  final IFile resource = this.dslFile(_builder);
  final XtextEditor editor = this.openEditor(resource);
  final ICompletionProposal[] proposals = this.computeQuickAssistProposals(editor, 1);
  StringConcatenation _builder_1 = new StringConcatenation();
  _builder_1.append("Multi fix 2");
  final Function1<ICompletionProposal, String> _function = (ICompletionProposal it) -> {
    return it.getDisplayString();
  };
  Assert.assertEquals(_builder_1.toString(), IterableExtensions.join(ListExtensions.<ICompletionProposal, String>map(((List<ICompletionProposal>)Conversions.doWrapArray(proposals)), _function), "\n"));
  IterableExtensions.<ICompletionProposal>head(((Iterable<ICompletionProposal>)Conversions.doWrapArray(proposals))).apply(editor.getDocument());
  StringConcatenation _builder_2 = new StringConcatenation();
  _builder_2.append("\"not bad doc\"");
  _builder_2.newLine();
  _builder_2.append("Foo { ref Bor }");
  _builder_2.newLine();
  _builder_2.append("\"bad doc\"");
  _builder_2.newLine();
  _builder_2.append("Bor { }");
  _builder_2.newLine();
  Assert.assertEquals(_builder_2.toString(), editor.getDocument().get());
}
 
Example 18
Source File: MultiQuickFixTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testQuickAssist() throws Exception {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("\"no doc\"");
  _builder.newLine();
  _builder.append("Foo { ref Bor }");
  _builder.newLine();
  _builder.append("\"no doc\" Bor { }");
  _builder.newLine();
  final IFile dslFile = this.dslFile(_builder);
  final XtextEditor editor = this.openEditor(dslFile);
  final ICompletionProposal[] proposals = this.computeQuickAssistProposals(editor, 1);
  StringConcatenation _builder_1 = new StringConcatenation();
  _builder_1.append("Multi fix");
  final Function1<ICompletionProposal, String> _function = (ICompletionProposal it) -> {
    return it.getDisplayString();
  };
  Assert.assertEquals(_builder_1.toString(), IterableExtensions.join(ListExtensions.<ICompletionProposal, String>map(((List<ICompletionProposal>)Conversions.doWrapArray(proposals)), _function), "\n"));
  IterableExtensions.<ICompletionProposal>head(((Iterable<ICompletionProposal>)Conversions.doWrapArray(proposals))).apply(editor.getDocument());
  StringConcatenation _builder_2 = new StringConcatenation();
  _builder_2.append("\"Better documentation\"");
  _builder_2.newLine();
  _builder_2.append("Foo { ref Bor }");
  _builder_2.newLine();
  _builder_2.append("\"no doc\" Bor { }");
  _builder_2.newLine();
  Assert.assertEquals(_builder_2.toString(), editor.getDocument().get());
}
 
Example 19
Source File: ContentAssistPrioritiesTest.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
public void assertContains(final ICompletionProposal proposal, final String text) {
  String _displayString = proposal.getDisplayString();
  String _plus = ((text + " in ") + _displayString);
  Assert.assertTrue(_plus, proposal.getDisplayString().contains(text));
}
 
Example 20
Source File: UiBinderXmlCompletionProcessor.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 4 votes vote down vote up
private void removeSchemaWidgetProposals(List<ICompletionProposal> proposals,
    IDocument document) {

  PackageBasedNamespaceManager packageManager = new PackageBasedNamespaceManager();

  IDOMModel model = (IDOMModel) StructuredModelManager.getModelManager().getExistingModelForRead(
      document);
  try {
    packageManager.readFromElement(model.getDocument().getDocumentElement());
  } finally {
    if (model != null) {
      model.releaseFromRead();
    }
  }

  Iterator<ICompletionProposal> it = proposals.iterator();
  while (it.hasNext()) {
    ICompletionProposal proposal = it.next();
    if (!(proposal instanceof CustomCompletionProposal)) {
      // Schema-generated widget proposals are instances of this class
      continue;
    }

    String displayString = proposal.getDisplayString();
    String prefix = XmlUtilities.getPrefix(displayString);
    if (prefix == null) {
      // Must have a namespace
      continue;
    }

    String packageName = packageManager.getPackageName(prefix);
    if (packageName == null) {
      // This doesn't map to a widget
      continue;
    }

    String widgetName = XmlUtilities.getUnprefixed(displayString);
    if (widgetName.length() == 0
        || !Character.isUpperCase(widgetName.charAt(0))) {
      // Not a widget
      continue;
    }

    // Passes our test, it must be a widget!
    it.remove();
  }
}