use of org.eclipse.xtext.ui.editor.model.IXtextDocument in project xtext-xtend by eclipse.
the class DirtyStateEditorValidationTest method testBug410575.
@Test
public void testBug410575() {
try {
final IJavaProject projectA = JavaCore.create(WorkbenchTestHelper.createPluginProject("projectA", "org.eclipse.xtext.xbase.lib", "org.eclipse.xtend.lib"));
WorkbenchTestHelper.addExportedPackages(projectA.getProject(), "mypack");
JavaCore.create(WorkbenchTestHelper.createPluginProject("projectB", "projectA", "org.eclipse.xtext.xbase.lib"));
StringConcatenation _builder = new StringConcatenation();
_builder.append("package mypack");
_builder.newLine();
_builder.newLine();
_builder.append("import org.eclipse.xtend.lib.annotations.Data");
_builder.newLine();
_builder.newLine();
_builder.append("@Data class MyClass {");
_builder.newLine();
_builder.append("\t");
_builder.append("String myProperty");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final IFile declaration = this.helper.createFileImpl("projectA/src/mypack/MyClass.xtend", _builder.toString());
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("package otherpack");
_builder_1.newLine();
_builder_1.newLine();
_builder_1.append("class OtherClass {");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("def void myMethod() {");
_builder_1.newLine();
_builder_1.append("\t\t");
_builder_1.append("val my = new mypack.MyClass(\"hello\")");
_builder_1.newLine();
_builder_1.append("\t\t");
_builder_1.append("println(my.getMyProperty())");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("}");
_builder_1.newLine();
_builder_1.append("}");
_builder_1.newLine();
final IFile file = this.helper.createFileImpl("projectB/src/otherpack/OtherClass.xtend", _builder_1.toString());
this._syncUtil.waitForBuild(null);
final IMarker[] markers = file.findMarkers(IMarker.PROBLEM, true, IResource.DEPTH_INFINITE);
int _length = markers.length;
boolean _greaterThan = (_length > 0);
if (_greaterThan) {
final Function1<IMarker, Object> _function = (IMarker it) -> {
try {
return it.getAttribute(IMarker.MESSAGE);
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
};
Assert.fail(IterableExtensions.join(ListExtensions.<IMarker, Object>map(((List<IMarker>) Conversions.doWrapArray(markers)), _function), "\n"));
}
final XtextEditor editor = this.helper.openEditor(declaration);
IXtextDocument _document = editor.getDocument();
StringConcatenation _builder_2 = new StringConcatenation();
_builder_2.append("package mypack");
_builder_2.newLine();
_builder_2.newLine();
_builder_2.append("import org.eclipse.xtend.lib.annotations.Data");
_builder_2.newLine();
_builder_2.newLine();
_builder_2.append("@Data class MyClass {");
_builder_2.newLine();
_builder_2.append("\t");
_builder_2.append("boolean foo");
_builder_2.newLine();
_builder_2.append("}");
_builder_2.newLine();
_document.set(_builder_2.toString());
this._syncUtil.waitForReconciler(editor);
this.assertNumberOfErrorAnnotations(editor, 0);
final XtextEditor editor2 = this.helper.openEditor(file);
this._syncUtil.waitForReconciler(editor2);
this.assertNumberOfErrorAnnotations(editor2, 2);
IXtextDocument _document_1 = editor2.getDocument();
StringConcatenation _builder_3 = new StringConcatenation();
_builder_3.append("package otherpack");
_builder_3.newLine();
_builder_3.newLine();
_builder_3.append("class OtherClass {");
_builder_3.newLine();
_builder_3.append("\t");
_builder_3.append("def void myMethod() {");
_builder_3.newLine();
_builder_3.append("\t\t");
_builder_3.append("val my = new mypack.MyClass(true)");
_builder_3.newLine();
_builder_3.append("\t\t");
_builder_3.append("println(my.isFoo())");
_builder_3.newLine();
_builder_3.append("\t");
_builder_3.append("}");
_builder_3.newLine();
_builder_3.append("}");
_builder_3.newLine();
_document_1.set(_builder_3.toString());
this._syncUtil.waitForReconciler(editor2);
this.assertNumberOfErrorAnnotations(editor2, 0);
IXtextDocument _document_2 = editor2.getDocument();
StringConcatenation _builder_4 = new StringConcatenation();
_builder_4.append("package otherpack");
_builder_4.newLine();
_builder_4.newLine();
_builder_4.append("@org.eclipse.xtend.lib.annotations.Data class OtherClass {");
_builder_4.newLine();
_builder_4.append("}");
_builder_4.newLine();
_document_2.set(_builder_4.toString());
this._syncUtil.waitForReconciler(editor2);
this.assertNumberOfErrorAnnotations(editor2, 1);
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtext.ui.editor.model.IXtextDocument in project xtext-xtend by eclipse.
the class DirtyEditorFilteringContentAssistTests method testFilteringExtends.
@Test
public void testFilteringExtends() {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("package foo");
_builder.newLine();
_builder.append("class MyDirtyType {}");
_builder.newLine();
final XtextEditor fooEditor = this._workbenchTestHelper.openEditor("foo/Foo.xtend", _builder.toString());
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("package foo");
_builder_1.newLine();
_builder_1.append("class Client extends MyDirtyType|{");
_builder_1.newLine();
_builder_1.append("}");
_builder_1.newLine();
final String clientModel = _builder_1.toString();
IResourcesSetupUtil.waitForBuild();
final XtextEditor clientEditor = this._workbenchTestHelper.openEditor("foo/Client.xtend", clientModel);
IXtextDocument _document = fooEditor.getDocument();
StringConcatenation _builder_2 = new StringConcatenation();
_builder_2.append("package foo");
_builder_2.newLine();
_builder_2.append("class MyDirtyType2 {}");
_builder_2.newLine();
_document.set(_builder_2.toString());
final ICompletionProposal[] proposals = this.computeCompletionProposals(clientEditor, fooEditor, clientModel.indexOf("|"));
Assert.assertEquals(1, ((List<ICompletionProposal>) Conversions.doWrapArray(proposals)).size());
final Function1<ICompletionProposal, Boolean> _function = (ICompletionProposal e) -> {
return Boolean.valueOf(e.toString().startsWith("Proposal: MyDirtyType - "));
};
boolean _exists = IterableExtensions.<ICompletionProposal>exists(((Iterable<ICompletionProposal>) Conversions.doWrapArray(proposals)), _function);
boolean _not = (!_exists);
Assert.assertTrue(_not);
final Function1<ICompletionProposal, Boolean> _function_1 = (ICompletionProposal e) -> {
return Boolean.valueOf(e.toString().startsWith("Proposal: MyDirtyType2 - "));
};
Assert.assertTrue(IterableExtensions.<ICompletionProposal>exists(((Iterable<ICompletionProposal>) Conversions.doWrapArray(proposals)), _function_1));
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtext.ui.editor.model.IXtextDocument in project xtext-xtend by eclipse.
the class DirtyEditorFilteringContentAssistTests method testFilteringConstructor.
@Test
public void testFilteringConstructor() {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("package foo");
_builder.newLine();
_builder.append("class MyDirtyType {}");
_builder.newLine();
final XtextEditor fooEditor = this._workbenchTestHelper.openEditor("foo/Foo.xtend", _builder.toString());
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("package foo");
_builder_1.newLine();
_builder_1.append("class Client {");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("def foo(){");
_builder_1.newLine();
_builder_1.append("\t\t");
_builder_1.append("new MyDirtyType|");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("}");
_builder_1.newLine();
_builder_1.append("}");
_builder_1.newLine();
final String clientModel = _builder_1.toString();
IResourcesSetupUtil.waitForBuild();
final XtextEditor clientEditor = this._workbenchTestHelper.openEditor("foo/Client.xtend", clientModel);
IXtextDocument _document = fooEditor.getDocument();
StringConcatenation _builder_2 = new StringConcatenation();
_builder_2.append("package foo");
_builder_2.newLine();
_builder_2.append("class MyDirtyType2 {}");
_builder_2.newLine();
_document.set(_builder_2.toString());
final ICompletionProposal[] proposals = this.computeCompletionProposals(clientEditor, fooEditor, clientModel.indexOf("|"));
final Function1<ICompletionProposal, Boolean> _function = (ICompletionProposal e) -> {
return Boolean.valueOf(e.toString().startsWith("Proposal: MyDirtyType - "));
};
boolean _exists = IterableExtensions.<ICompletionProposal>exists(((Iterable<ICompletionProposal>) Conversions.doWrapArray(proposals)), _function);
boolean _not = (!_exists);
Assert.assertTrue(_not);
final Function1<ICompletionProposal, Boolean> _function_1 = (ICompletionProposal e) -> {
return Boolean.valueOf(e.toString().startsWith("Proposal: MyDirtyType2 - "));
};
Assert.assertTrue(IterableExtensions.<ICompletionProposal>exists(((Iterable<ICompletionProposal>) Conversions.doWrapArray(proposals)), _function_1));
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtext.ui.editor.model.IXtextDocument in project xtext-eclipse by eclipse.
the class AbstractQuickfixTest method quickfixesAreOffered.
protected void quickfixesAreOffered(XtextEditor editor, String issueCode, Quickfix... expected) {
List<Quickfix> expectedSorted = Arrays.asList(expected);
expectedSorted.sort(Comparator.comparing(e -> e.getLabel()));
IXtextDocument document = editor.getDocument();
String originalText = document.get();
Issue issue = getValidationIssue(document, issueCode);
List<IssueResolution> actualIssueResolutions = issueResolutionProvider.getResolutions(issue);
actualIssueResolutions.sort(Comparator.comparing(i -> i.getLabel()));
assertEquals("The number of quickfixes does not match!", expectedSorted.size(), actualIssueResolutions.size());
for (int i = 0; i < actualIssueResolutions.size(); i++) {
IssueResolution actualIssueResolution = actualIssueResolutions.get(i);
Quickfix expectedIssueResolution = expectedSorted.get(i);
assertEquals(expectedIssueResolution.label, actualIssueResolution.getLabel());
assertEquals(expectedIssueResolution.description, actualIssueResolution.getDescription());
assertIssueResolutionResult(expectedIssueResolution.result, actualIssueResolution, originalText);
}
}
use of org.eclipse.xtext.ui.editor.model.IXtextDocument in project xtext-eclipse by eclipse.
the class ContentAssistProcessorTestBuilder method appendAndApplyProposal.
public ContentAssistProcessorTestBuilder appendAndApplyProposal(String model, int position, String proposalString) throws Exception {
IXtextDocument document = getDocument(getModel());
Shell shell = new Shell();
try {
XtextSourceViewerConfiguration configuration = get(XtextSourceViewerConfiguration.class);
ISourceViewer sourceViewer = getSourceViewer(shell, document, configuration);
ICompletionProposal[] proposals = computeCompletionProposals(document, position, shell);
ICompletionProposal proposal = findProposal(proposalString, proposals);
return appendAndApplyProposal(proposal, sourceViewer, model, position);
} finally {
shell.dispose();
}
}
Aggregations