Java Code Examples for org.eclipse.xtext.ui.editor.XtextEditor#doSave()
The following examples show how to use
org.eclipse.xtext.ui.editor.XtextEditor#doSave() .
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: LinkingErrorTest.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
@Test public void testSemanticIssueResolution() throws Exception { IFile dslFile = dslFile(MODEL_WITH_LINKING_ERROR); XtextEditor xtextEditor = openEditor(dslFile); URI uriToProblem = xtextEditor.getDocument().readOnly(new IUnitOfWork<URI, XtextResource>() { @Override public URI exec(XtextResource state) throws Exception { Main main = (Main) state.getContents().get(0); Element element = main.getElements().get(1); return EcoreUtil.getURI(element); } }); Issue.IssueImpl issue = new Issue.IssueImpl(); issue.setUriToProblem(uriToProblem); issue.setCode(QuickfixCrossrefTestLanguageQuickfixProvider.SEMANTIC_FIX_ID); List<IssueResolution> resolutions = issueResolutionProvider.getResolutions(issue); assertEquals(1, resolutions.size()); IssueResolution issueResolution = resolutions.get(0); issueResolution.apply(); xtextEditor.doSave(null); List<Issue> issues = getAllValidationIssues(xtextEditor.getDocument()); assertTrue(issues.isEmpty()); }
Example 2
Source File: XtextGrammarQuickfixProviderTest.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
private void assertAndApplySingleResolution(XtextEditor xtextEditor, String issueCode, int issueDataCount, String resolutionLabel, boolean isCleanAfterApply) { IXtextDocument document = xtextEditor.getDocument(); List<Issue> issues = getIssues(document); assertFalse(issues.toString(), issues.isEmpty()); Issue issue = issues.iterator().next(); assertEquals(issueCode, issue.getCode()); assertNotNull(issue.getData()); assertEquals(issueDataCount, issue.getData().length); List<IssueResolution> resolutions = issueResolutionProvider.getResolutions(issue); assertEquals(1, resolutions.size()); IssueResolution resolution = resolutions.iterator().next(); assertEquals(resolutionLabel, resolution.getLabel()); try { resolution.apply(); assertEquals(getIssues(document).toString(), isCleanAfterApply, getIssues(document).isEmpty()); } finally { // Save xtextEditor in any case. Otherwise test will stuck, // because the "save changed resource dialog" waits for user input. xtextEditor.doSave(new NullProgressMonitor()); } }
Example 3
Source File: ClearCacheOnCleanPluginUITest.java From n4js with Eclipse Public License 1.0 | 5 votes |
/** * Tests if the {@link MultiCleartriggerCache} is cleared when the user edits a 'package.json' file. Note that this * triggering is performed for the key {@link MultiCleartriggerCache#CACHE_KEY_API_IMPL_MAPPING} but not necessarily * for every other key in the cache. */ @Test public void testClearOnModifyPackageJson() throws CoreException { File prjDir = new File(PROBANDS); IProject project = ProjectTestsUtils.importProject(prjDir, PROJECT_NAME); IResource packagejson = project.findMember(N4JSGlobals.PACKAGE_JSON); IFile filePJ = ResourcesPlugin.getWorkspace().getRoot().getFile(packagejson.getFullPath()); IResourcesSetupUtil.fullBuild(); waitForAutoBuild(); syncExtAndBuild(); assertNoIssues(); // use key of API_IMPL_MAPPING SupplierWithPostAction testSupplier = new SupplierWithPostAction(); assertTrue(testSupplier.postActionTriggerCount == 0); cache.clear(MultiCleartriggerCache.CACHE_KEY_API_IMPL_MAPPING); // cache should be empty Object test = cache.get(testSupplier, MultiCleartriggerCache.CACHE_KEY_API_IMPL_MAPPING); assertTrue(testSupplier.postActionTriggerCount == 1); assertTrue("test".equals(test)); // cache should contain key cache.get(testSupplier, MultiCleartriggerCache.CACHE_KEY_API_IMPL_MAPPING); assertTrue(testSupplier.postActionTriggerCount == 1); assertTrue("test".equals(test)); // edit package.json should clear the cache and set a new instance of ApiImplMappings IWorkbenchPage page = EclipseUIUtils.getActivePage(); XtextEditor editor = openAndGetXtextEditor(filePJ, page); editor.doSave(new NullProgressMonitor()); waitForAutoBuild(); test = cache.get(testSupplier, MultiCleartriggerCache.CACHE_KEY_API_IMPL_MAPPING); assertTrue(test instanceof ApiImplMapping); }
Example 4
Source File: XtextGrammarQuickfixProviderTest.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
private void assertAndApplyAllResolutions(XtextEditor xtextEditor, String issueCode, int issueDataCount, int issueCount, String resolutionLabel) throws CoreException { InternalBuilderTest.setAutoBuild(true); if (xtextEditor.isDirty()) { xtextEditor.doSave(new NullProgressMonitor()); } InternalBuilderTest.fullBuild(); IXtextDocument document = xtextEditor.getDocument(); validateInEditor(document); List<Issue> issues = getIssues(document); assertFalse("Document has no issues, but should.", issues.isEmpty()); issues.iterator().forEachRemaining((issue) -> { assertEquals(issueCode, issue.getCode()); assertNotNull(issue.getData()); assertEquals(issueDataCount, issue.getData().length); }); IResource resource = xtextEditor.getResource(); IMarker[] problems = resource.findMarkers(MarkerTypes.FAST_VALIDATION, true, IResource.DEPTH_INFINITE); assertEquals("Resource should have " + issueCount + " error marker.", issueCount, problems.length); validateInEditor(document); MarkerResolutionGenerator instance = injector.getInstance(MarkerResolutionGenerator.class); List<IMarkerResolution> resolutions = Lists.newArrayList(instance.getResolutions(problems[0])); assertEquals(1, resolutions.size()); IMarkerResolution resolution = resolutions.iterator().next(); assertTrue(resolution instanceof WorkbenchMarkerResolution); WorkbenchMarkerResolution workbenchResolution = (WorkbenchMarkerResolution) resolution; IMarker primaryMarker = problems[0]; List<IMarker> others = Lists.newArrayList(workbenchResolution.findOtherMarkers(problems)); assertFalse(others.contains(primaryMarker)); assertEquals(problems.length - 1, others.size()); others.add(primaryMarker); workbenchResolution.run(others.toArray(new IMarker[others.size()]), new NullProgressMonitor()); if (xtextEditor.isDirty()) { xtextEditor.doSave(null); } InternalBuilderTest.cleanBuild(); problems = resource.findMarkers(MarkerTypes.FAST_VALIDATION, true, IResource.DEPTH_INFINITE); assertEquals("Resource should have no error marker.", 0, problems.length); }
Example 5
Source File: JavaRefactoringIntegrationTest.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@Test // @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=402916 public void testRenameRefToXtendDefinedConstructorSameFile() throws Exception { String xtendModel = "class XtendClass { new() {} def foo() { new XtendClass } }"; IFile xtendRef = createFile("XtendClass.xtend", xtendModel); final XtextEditor editor = openEditorSafely(xtendRef); renameXtendElement(editor, xtendModel.lastIndexOf("XtendClass"), "NewXtendClass"); assertDocumentContains(editor, xtendModel.replace("XtendClass", "NewXtendClass")); editor.doSave(new NullProgressMonitor()); IFile newXtendClass = fileAsserts.assertFileExists("src/NewXtendClass.xtend"); fileAsserts.assertFileContains(newXtendClass, "class NewXtendClass {"); }
Example 6
Source File: Bug493784Test.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@Test public void testNoMemoryLeakOnEditing() { try { StringConcatenation _builder = new StringConcatenation(); _builder.append("class A {"); _builder.newLine(); _builder.append("\t"); _builder.newLine(); _builder.append("}"); _builder.newLine(); _builder.newLine(); _builder.append("class A2 extends A {"); _builder.newLine(); _builder.append("\t"); _builder.append("def test() {"); _builder.newLine(); _builder.append("\t"); _builder.append("}"); _builder.newLine(); _builder.append("}"); _builder.newLine(); final String xtendModel = _builder.toString(); final IFile xtendClass = this.testHelper.createFile("XtendClass.xtend", xtendModel); final XtextEditor editor = this.testHelper.openEditor(xtendClass); Assert.assertEquals(1, (this.getListenerCount(editor)).intValue()); this.pressKey(editor, ' '); this._syncUtil.waitForReconciler(editor); Assert.assertEquals(1, (this.getListenerCount(editor)).intValue()); this.pressKey(editor, ' '); this._syncUtil.waitForReconciler(editor); Assert.assertEquals(1, (this.getListenerCount(editor)).intValue()); NullProgressMonitor _nullProgressMonitor = new NullProgressMonitor(); editor.doSave(_nullProgressMonitor); this._syncUtil.waitForReconciler(editor); Assert.assertEquals(1, (this.getListenerCount(editor)).intValue()); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example 7
Source File: ExternalEditorTest.java From xtext-eclipse with Eclipse Public License 2.0 | 4 votes |
private void setContentAndSave(XtextEditor editor, String newContent) { editor.getDocument().set(newContent); editor.doSave(new NullProgressMonitor()); }
Example 8
Source File: CompositeQuickfixTest.java From xtext-eclipse with Eclipse Public License 2.0 | 4 votes |
@Test public void testTextualMultiModification() { try { StringConcatenation _builder = new StringConcatenation(); _builder.append("lowercase_a {}"); _builder.newLine(); _builder.append("lowercase_b {}"); _builder.newLine(); _builder.append("lowercase_c {}"); _builder.newLine(); _builder.append("lowercase_d {}"); _builder.newLine(); _builder.append("lowercase_e {}"); _builder.newLine(); _builder.append("lowercase_f {}"); _builder.newLine(); final IFile resource = this.dslFile(_builder); IEditorPart _openEditor = IDE.openEditor(AbstractWorkbenchTest.getActivePage(), resource); final XtextEditor xtextEditor = ((XtextEditor) _openEditor); final IMarker[] markers = this.getMarkers(resource); StringConcatenation _builder_1 = new StringConcatenation(); _builder_1.append("<0<lowercase_a>0> {}"); _builder_1.newLine(); _builder_1.append("<1<lowercase_b>1> {}"); _builder_1.newLine(); _builder_1.append("<2<lowercase_c>2> {}"); _builder_1.newLine(); _builder_1.append("<3<lowercase_d>3> {}"); _builder_1.newLine(); _builder_1.append("<4<lowercase_e>4> {}"); _builder_1.newLine(); _builder_1.append("<5<lowercase_f>5> {}"); _builder_1.newLine(); _builder_1.append("--------------------"); _builder_1.newLine(); _builder_1.append("0: message=lowercase"); _builder_1.newLine(); _builder_1.append("1: message=lowercase"); _builder_1.newLine(); _builder_1.append("2: message=lowercase"); _builder_1.newLine(); _builder_1.append("3: message=lowercase"); _builder_1.newLine(); _builder_1.append("4: message=lowercase"); _builder_1.newLine(); _builder_1.append("5: message=lowercase"); _builder_1.newLine(); this.assertContentsAndMarkers(resource, markers, _builder_1); this.applyQuickfixOnMultipleMarkers(markers); xtextEditor.doSave(null); StringConcatenation _builder_2 = new StringConcatenation(); _builder_2.append("LOWERCASE_A_LOWERCASE_A {}"); _builder_2.newLine(); _builder_2.append("LOWERCASE_B_LOWERCASE_B {}"); _builder_2.newLine(); _builder_2.append("LOWERCASE_C_LOWERCASE_C {}"); _builder_2.newLine(); _builder_2.append("LOWERCASE_D_LOWERCASE_D {}"); _builder_2.newLine(); _builder_2.append("LOWERCASE_E_LOWERCASE_E {}"); _builder_2.newLine(); _builder_2.append("LOWERCASE_F_LOWERCASE_F {}"); _builder_2.newLine(); _builder_2.append("--------------------------"); _builder_2.newLine(); _builder_2.append("(no markers found)"); _builder_2.newLine(); this.assertContentsAndMarkers(resource, _builder_2); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }