use of org.eclipse.che.jface.text.contentassist.ICompletionProposal in project che by eclipse.
the class CodeAssist method convertProposals.
private Proposals convertProposals(int offset, ICompilationUnit compilationUnit, TextViewer viewer, List<ICompletionProposal> proposals) {
Proposals result = DtoFactory.getInstance().createDto(Proposals.class);
String sessionId = UUID.randomUUID().toString();
result.setSessionId(sessionId);
ArrayList<ProposalPresentation> presentations = new ArrayList<>();
for (int i = 0; i < proposals.size(); i++) {
ProposalPresentation presentation = DtoFactory.getInstance().createDto(ProposalPresentation.class);
ICompletionProposal proposal = proposals.get(i);
presentation.setIndex(i);
presentation.setDisplayString(proposal.getDisplayString());
String image = proposal.getImage() == null ? null : proposal.getImage().getImg();
presentation.setImage(image);
if (proposal instanceof ICompletionProposalExtension4) {
presentation.setAutoInsertable(((ICompletionProposalExtension4) proposal).isAutoInsertable());
}
if (proposal instanceof CheActionAcces) {
String actionId = ((CheActionAcces) proposal).getActionId();
if (actionId != null) {
presentation.setActionId(actionId);
}
}
presentations.add(presentation);
}
result.setProposals(presentations);
cache.put(sessionId, new CodeAssistContext(viewer, offset, proposals, compilationUnit));
return result;
}
use of org.eclipse.che.jface.text.contentassist.ICompletionProposal in project che by eclipse.
the class QuickFixTest method assertNumberOfProposals.
protected static void assertNumberOfProposals(List proposals, int expectedProposals) {
if (proposals.size() != expectedProposals) {
StringBuffer buf = new StringBuffer();
buf.append("Wrong number of proposals, is: ").append(proposals.size()).append(", expected: ").append(expectedProposals).append('\n');
for (int i = 0; i < proposals.size(); i++) {
ICompletionProposal curr = (ICompletionProposal) proposals.get(i);
buf.append(" - ").append(curr.getDisplayString()).append('\n');
if (curr instanceof CUCorrectionProposal) {
appendSource(((CUCorrectionProposal) curr), buf);
}
}
assertTrue(buf.toString(), false);
}
}
use of org.eclipse.che.jface.text.contentassist.ICompletionProposal in project che by eclipse.
the class QuickFixTest method assertCorrectLabels.
public static void assertCorrectLabels(List proposals) {
for (int i = 0; i < proposals.size(); i++) {
ICompletionProposal proposal = (ICompletionProposal) proposals.get(i);
String name = proposal.getDisplayString();
if (name == null || name.length() == 0 || name.charAt(0) == '!' || name.indexOf("{0}") != -1 || name.indexOf("{1}") != -1) {
assertTrue("wrong proposal label: " + name, false);
}
if (proposal.getImage() == null) {
assertTrue("wrong proposal image", false);
}
}
}
use of org.eclipse.che.jface.text.contentassist.ICompletionProposal in project che by eclipse.
the class CompletionJavadocTest method computeProposals.
private static List<ICompletionProposal> computeProposals(ICompilationUnit compilationUnit, int offset) throws JavaModelException {
IBuffer buffer = compilationUnit.getBuffer();
IDocument document;
if (buffer instanceof org.eclipse.jdt.internal.ui.javaeditor.DocumentAdapter) {
document = ((org.eclipse.jdt.internal.ui.javaeditor.DocumentAdapter) buffer).getDocument();
} else {
document = new DocumentAdapter(buffer);
}
TextViewer viewer = new TextViewer(document, new Point(offset, 0));
JavaContentAssistInvocationContext context = new JavaContentAssistInvocationContext(viewer, offset, compilationUnit);
List<ICompletionProposal> proposals = new ArrayList<>();
proposals.addAll(new JavaAllCompletionProposalComputer().computeCompletionProposals(context, null));
// proposals.addAll(new TemplateCompletionProposalComputer().computeCompletionProposals(context, null));
Collections.sort(proposals, new RelevanceSorter());
return proposals;
}
use of org.eclipse.che.jface.text.contentassist.ICompletionProposal in project che by eclipse.
the class CompletionJavadocTest method testInheredJavadoc.
@Test
public void testInheredJavadoc() throws Exception {
IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("public class E {\n");
buf.append(" /**\n");
buf.append(" * Test JavaDoc.\n");
buf.append(" */\n");
buf.append(" public void foo(int i) {\n");
buf.append(" }\n");
buf.append("}\n");
pack1.createCompilationUnit("E.java", buf.toString(), false, null);
StringBuffer buf2 = new StringBuffer();
buf2.append("package test1;\n");
buf2.append("public class B extends E {\n");
buf2.append(" @Override\n");
buf2.append(" public void foo(int i) {\n");
buf2.append(" foo(10);\n");
buf2.append(" }\n");
buf2.append("}\n");
ICompilationUnit cu2 = pack1.createCompilationUnit("B.java", buf2.toString(), false, null);
List<ICompletionProposal> proposals = computeProposals(cu2, buf2.indexOf(" foo") + " foo".length());
Assertions.assertThat(proposals).hasSize(1);
ICompletionProposal proposal = proposals.get(0);
String result;
if (proposal instanceof ICompletionProposalExtension5) {
result = ((ICompletionProposalExtension5) proposal).getAdditionalProposalInfo(null).toString();
} else {
result = proposal.getAdditionalProposalInfo();
}
Assertions.assertThat(result).contains("Test JavaDoc.");
}
Aggregations