Java Code Examples for org.eclipse.xtext.ui.editor.XtextEditor#getEditorInput()
The following examples show how to use
org.eclipse.xtext.ui.editor.XtextEditor#getEditorInput() .
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: OccurrenceMarker.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
protected IAnnotationModel getAnnotationModel(XtextEditor editor) { if(editor != null) { IEditorInput editorInput = editor.getEditorInput(); if(editorInput != null) { IDocumentProvider documentProvider = editor.getDocumentProvider(); if(documentProvider != null) { return documentProvider.getAnnotationModel(editorInput); } } } return null; }
Example 2
Source File: OpenDocumentTracker.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
protected URI getResourceURI(XtextEditor editor) { IEditorInput editorInput = editor.getEditorInput(); if (editorInput instanceof IStorageEditorInput) { try { return storage2UriMapper.getUri(((IStorageEditorInput) editorInput).getStorage()); } catch (CoreException e) { LOG.error("Error getting URI for storage", e); } } return null; }
Example 3
Source File: CheckValidateActionHandler.java From dsl-devkit with Eclipse Public License 1.0 | 5 votes |
@Override public Object execute(final ExecutionEvent event) throws ExecutionException { XtextEditor xtextEditor = EditorUtils.getActiveXtextEditor(event); if (xtextEditor != null && xtextEditor.getEditorInput() instanceof XtextReadonlyEditorInput) { return null; } return super.execute(event); }
Example 4
Source File: PasteJavaCodeHandler.java From xtext-xtend with Eclipse Public License 2.0 | 4 votes |
private void doPasteJavaCode(final XtextEditor activeXtextEditor, final String javaCode, final JavaImportData javaImports) throws ExecutionException { ISourceViewer sourceViewer = activeXtextEditor.getInternalSourceViewer(); final IXtextDocument xtextDocument = activeXtextEditor.getDocument(); IJavaProject project = null; IProject iProject = null; IEditorInput editorInput = activeXtextEditor.getEditorInput(); if (editorInput instanceof IFileEditorInput) { iProject = ((IFileEditorInput) editorInput).getFile().getProject(); project = JavaCore.create(iProject); } final int selectionOffset = Math.max(0, sourceViewer.getSelectedRange().x - 1); EObject targetElement = xtextDocument.readOnly(new IUnitOfWork<EObject, XtextResource>() { @Override public EObject exec(XtextResource state) throws Exception { IParseResult parseResult = state.getParseResult(); if (parseResult == null) { return null; } ILeafNode leafNode = NodeModelUtils.findLeafNodeAtOffset(parseResult.getRootNode(), selectionOffset); if (leafNode == null) { return parseResult.getRootASTElement(); } return leafNode.getSemanticElement(); } }); JavaConverter javaConverter = javaConverterProvider.get(); final String xtendCode = javaConverter.toXtend(javaCode, javaImports != null ? javaImports.getImports() : null, targetElement, project, conditionalExpressionsAllowed(iProject)); if (!Strings.isEmpty(xtendCode)) { if (javaImports != null) { importsUtil.addImports(javaImports.getImports(), javaImports.getStaticImports(), new String[] {}, xtextDocument); } Point selection = sourceViewer.getSelectedRange(); try { xtextDocument.replace(selection.x, selection.y, xtendCode); } catch (BadLocationException e) { throw new ExecutionException("Failed to replace content.", e); } //TODO enable formatting, when performance became better // https://bugs.eclipse.org/bugs/show_bug.cgi?id=457814 // doFormat(sourceViewer, xtendCode, selection); } }