use of org.eclipse.che.jface.text.contentassist.ICompletionProposal in project che by eclipse.
the class ParameterGuessingProposal method apply.
/*
* @see ICompletionProposalExtension#apply(IDocument, char)
*/
@Override
public void apply(final IDocument document, char trigger, int offset) {
super.apply(document, trigger, offset);
int baseOffset = getReplacementOffset();
String replacement = getReplacementString();
if (fPositions != null && getTextViewer() != null) {
LinkedModeModelImpl model = new LinkedModeModelImpl();
for (int i = 0; i < fPositions.length; i++) {
LinkedPositionGroupImpl group = new LinkedPositionGroupImpl();
int positionOffset = fPositions[i].getOffset();
int positionLength = fPositions[i].getLength();
if (fChoices[i].length < 2) {
RegionImpl region = new RegionImpl();
region.setOffset(positionOffset);
region.setLength(positionLength);
// group.addPositions(new LinkedPosition(document, positionOffset, positionLength, LinkedPositionGroup.NO_STOP));
group.addPositions(region);
} else {
// ensurePositionCategoryInstalled(document, model);
// document.addPosition(getCategory(), fPositions[i]);
RegionImpl region = new RegionImpl();
region.setOffset(positionOffset);
region.setLength(positionLength);
// group.addPositions(
// new ProposalPosition(document, positionOffset, positionLength, LinkedPositionGroup.NO_STOP, fChoices[i]));
group.addPositions(region);
LinkedDataImpl data = new LinkedDataImpl();
for (ICompletionProposal proposal : fChoices[i]) {
data.addValues(proposal.getDisplayString());
}
group.setData(data);
}
model.addGroups(group);
}
model.setEscapePosition(baseOffset + replacement.length());
this.linkedModel = model;
// model.forceInstall();
// JavaEditor editor = getJavaEditor();
// if (editor != null) {
// model.addLinkingListener(new EditorHighlightingSynchronizer(editor));
// }
// LinkedModeUI ui = new EditorLinkedModeUI(model, getTextViewer());
// ui.setExitPosition(getTextViewer(), baseOffset + replacement.length(), 0, Integer.MAX_VALUE);
// // exit character can be either ')' or ';'
// final char exitChar = replacement.charAt(replacement.length() - 1);
// ui.setExitPolicy(new ExitPolicy(exitChar, document) {
// @Override
// public ExitFlags doExit(LinkedModeModel model2, VerifyEvent event, int offset2, int length) {
// if (event.character == ',') {
// for (int i = 0; i < fPositions.length - 1; i++) { // not for the last one
// Position position = fPositions[i];
// if (position.offset <= offset2 && offset2 + length <= position.offset + position.length) {
// try {
// ITypedRegion partition = TextUtilities
// .getPartition(document, IJavaPartitions.JAVA_PARTITIONING, offset2 + length, false);
// if (IDocument.DEFAULT_CONTENT_TYPE.equals(partition.getType())
// || offset2 + length == partition.getOffset() + partition.getLength()) {
// event.character = '\t';
// event.keyCode = SWT.TAB;
// return null;
// }
// } catch (BadLocationException e) {
// // continue; not serious enough to log
// }
// }
// }
// } else if (event.character == ')' && exitChar != ')') {
// // exit from link mode when user is in the last ')' position.
// Position position = fPositions[fPositions.length - 1];
// if (position.offset <= offset2 && offset2 + length <= position.offset + position.length) {
// return new ExitFlags(ILinkedModeListener.UPDATE_CARET, false);
// }
// }
// return super.doExit(model2, event, offset2, length);
// }
// });
// ui.setCyclingMode(LinkedModeUI.CYCLE_WHEN_NO_PARENT);
// ui.setDoContextInfo(true);
// ui.enter();
fSelectedRegion = new Region(baseOffset + replacement.length(), 0);
} else {
fSelectedRegion = new Region(baseOffset + replacement.length(), 0);
}
}
use of org.eclipse.che.jface.text.contentassist.ICompletionProposal in project che by eclipse.
the class CompletionJavadocTest method testJavadoc.
@Test
public void testJavadoc() 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(" foo(10);");
buf.append(" }\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);
List<ICompletionProposal> proposals = computeProposals(cu, buf.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.");
}
use of org.eclipse.che.jface.text.contentassist.ICompletionProposal in project che by eclipse.
the class TypeMismatchQuickFixTests method testTypeMismatchPrimitiveTypes.
@Test
public void testTypeMismatchPrimitiveTypes() throws Exception {
IPackageFragment pack1 = fSourceFolder.createPackageFragment("pack", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package pack;\n");
buf.append("\n");
buf.append("\n");
buf.append("public class E {\n");
buf.append(" public void foo(long o) {\n");
buf.append(" int i= o;\n");
buf.append(" }\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);
CompilationUnit astRoot = getASTRoot(cu);
ArrayList proposals = collectCorrections(cu, astRoot);
assertCorrectLabels(proposals);
assertNumberOfProposals(proposals, 3);
ICompletionProposal proposal = (ICompletionProposal) proposals.get(0);
assertTrue(proposal.getDisplayString().indexOf("Integer") == -1);
ICompletionProposal proposal2 = (ICompletionProposal) proposals.get(1);
assertTrue(proposal2.getDisplayString().indexOf("Integer") == -1);
ICompletionProposal proposal3 = (ICompletionProposal) proposals.get(2);
assertTrue(proposal3.getDisplayString().indexOf("Integer") == -1);
String[] expected = new String[3];
buf = new StringBuffer();
buf.append("package pack;\n");
buf.append("\n");
buf.append("\n");
buf.append("public class E {\n");
buf.append(" public void foo(long o) {\n");
buf.append(" int i= (int) o;\n");
buf.append(" }\n");
buf.append("}\n");
expected[0] = buf.toString();
buf = new StringBuffer();
buf.append("package pack;\n");
buf.append("\n");
buf.append("\n");
buf.append("public class E {\n");
buf.append(" public void foo(int o) {\n");
buf.append(" int i= o;\n");
buf.append(" }\n");
buf.append("}\n");
expected[1] = buf.toString();
buf = new StringBuffer();
buf.append("package pack;\n");
buf.append("\n");
buf.append("\n");
buf.append("public class E {\n");
buf.append(" public void foo(long o) {\n");
buf.append(" long i= o;\n");
buf.append(" }\n");
buf.append("}\n");
expected[2] = buf.toString();
assertExpectedExistInProposals(proposals, expected);
}
use of org.eclipse.che.jface.text.contentassist.ICompletionProposal in project che by eclipse.
the class TypeMismatchQuickFixTests method testTypeMismatchObjectAndPrimitiveType.
@Test
public void testTypeMismatchObjectAndPrimitiveType() throws Exception {
IPackageFragment pack1 = fSourceFolder.createPackageFragment("pack", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package pack;\n");
buf.append("\n");
buf.append("\n");
buf.append("public class E {\n");
buf.append(" public void foo() {\n");
buf.append(" Object o= new Object();\n");
buf.append(" int i= o;\n");
buf.append(" }\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);
CompilationUnit astRoot = getASTRoot(cu);
ArrayList proposals = collectCorrections(cu, astRoot);
assertCorrectLabels(proposals);
assertNumberOfProposals(proposals, 3);
ICompletionProposal proposal = (ICompletionProposal) proposals.get(0);
assertTrue(proposal.getDisplayString().indexOf("Integer") != -1);
String[] expected = new String[3];
buf = new StringBuffer();
buf.append("package pack;\n");
buf.append("\n");
buf.append("\n");
buf.append("public class E {\n");
buf.append(" public void foo() {\n");
buf.append(" Object o= new Object();\n");
buf.append(" int i= (Integer) o;\n");
buf.append(" }\n");
buf.append("}\n");
expected[0] = buf.toString();
buf = new StringBuffer();
buf.append("package pack;\n");
buf.append("\n");
buf.append("\n");
buf.append("public class E {\n");
buf.append(" public void foo() {\n");
buf.append(" int o= new Object();\n");
buf.append(" int i= o;\n");
buf.append(" }\n");
buf.append("}\n");
expected[1] = buf.toString();
buf = new StringBuffer();
buf.append("package pack;\n");
buf.append("\n");
buf.append("\n");
buf.append("public class E {\n");
buf.append(" public void foo() {\n");
buf.append(" Object o= new Object();\n");
buf.append(" Object i= o;\n");
buf.append(" }\n");
buf.append("}\n");
expected[2] = buf.toString();
assertExpectedExistInProposals(proposals, expected);
}
Aggregations