org.eclipse.jface.text.IDocumentExtension4 Java Examples
The following examples show how to use
org.eclipse.jface.text.IDocumentExtension4.
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: ImportRewriter.java From n4js with Eclipse Public License 1.0 | 6 votes |
private ImportRewriter(IDocument document, Resource resource) { if (document instanceof IDocumentExtension4) { lineDelimiter = ((IDocumentExtension4) document).getDefaultLineDelimiter(); } else { lineDelimiter = Strings.newLine(); } this.script = (Script) resource.getContents().get(0); this.existingImports = Lists.newArrayList(); for (ScriptElement element : script.getScriptElements()) { if (element instanceof ImportDeclaration) existingImports.add((ImportDeclaration) element); } this.requestedImports = Sets.newLinkedHashSet(); this.lazySpacer = new Lazy<>(() -> spacerPreference.getSpacingPreference(resource)); }
Example #2
Source File: OrganizeImportsFixesUnused.java From Pydev with Eclipse Public License 1.0 | 6 votes |
private void findAndDeleteUnusedImports(PySelection ps, PyEdit edit, IDocumentExtension4 doc, IFile f) throws Exception { Iterator<MarkerAnnotationAndPosition> it; if (edit != null) { it = edit.getPySourceViewer().getMarkerIterator(); } else { IMarker markers[] = f.findMarkers(IMiscConstants.PYDEV_ANALYSIS_PROBLEM_MARKER, true, IResource.DEPTH_ZERO); MarkerAnnotationAndPosition maap[] = new MarkerAnnotationAndPosition[markers.length]; int ix = 0; for (IMarker m : markers) { int start = (Integer) m.getAttribute(IMarker.CHAR_START); int end = (Integer) m.getAttribute(IMarker.CHAR_END); maap[ix++] = new MarkerAnnotationAndPosition(new MarkerAnnotation(m), new Position(start, end - start)); } it = Arrays.asList(maap).iterator(); } ArrayList<MarkerAnnotationAndPosition> unusedImportsMarkers = getUnusedImports(it); sortInReverseDocumentOrder(unusedImportsMarkers); deleteImports(doc, ps, unusedImportsMarkers); }
Example #3
Source File: DocCopy.java From Pydev with Eclipse Public License 1.0 | 6 votes |
public DocCopy(IDocument document) { this.contents = document.get(); this.document = document; categoryToPos = new HashMap<>(); String[] positionCategories = document.getPositionCategories(); for (String string : positionCategories) { try { categoryToPos.put(string, document.getPositions(string)); } catch (BadPositionCategoryException e) { Log.log(e); } } IDocumentExtension4 doc4 = (IDocumentExtension4) document; modificationStamp = doc4.getModificationStamp(); }
Example #4
Source File: PyChange.java From Pydev with Eclipse Public License 1.0 | 6 votes |
public long getModificationStamp(IResource resource) { if (!(resource instanceof IFile)) { return resource.getModificationStamp(); } IFile file = (IFile) resource; ITextFileBuffer buffer = getBuffer(file); if (buffer == null) { return file.getModificationStamp(); } else { IDocument document = buffer.getDocument(); if (document instanceof IDocumentExtension4) { return ((IDocumentExtension4) document).getModificationStamp(); } else { return file.getModificationStamp(); } } }
Example #5
Source File: PyChange.java From Pydev with Eclipse Public License 1.0 | 6 votes |
private void initializeFile(IFile file) { fTextFileBuffer = getBuffer(file); if (fTextFileBuffer == null) { initializeResource(file); } else { IDocument document = fTextFileBuffer.getDocument(); fDirty = fTextFileBuffer.isDirty(); fReadOnly = isReadOnly(file); if (document instanceof IDocumentExtension4) { fKind = DOCUMENT; fModificationStamp = ((IDocumentExtension4) document).getModificationStamp(); } else { fKind = RESOURCE; fModificationStamp = file.getModificationStamp(); } } }
Example #6
Source File: JavaEditor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
void removeOccurrenceAnnotations() { fMarkOccurrenceModificationStamp= IDocumentExtension4.UNKNOWN_MODIFICATION_STAMP; fMarkOccurrenceTargetRegion= null; IDocumentProvider documentProvider= getDocumentProvider(); if (documentProvider == null) return; IAnnotationModel annotationModel= documentProvider.getAnnotationModel(getEditorInput()); if (annotationModel == null || fOccurrenceAnnotations == null) return; synchronized (getLockObject(annotationModel)) { if (annotationModel instanceof IAnnotationModelExtension) { ((IAnnotationModelExtension)annotationModel).replaceAnnotations(fOccurrenceAnnotations, null); } else { for (int i= 0, length= fOccurrenceAnnotations.length; i < length; i++) annotationModel.removeAnnotation(fOccurrenceAnnotations[i]); } fOccurrenceAnnotations= null; } }
Example #7
Source File: CleanUpPostSaveListener.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private long getDocumentStamp(IFile file, IProgressMonitor monitor) throws CoreException { final ITextFileBufferManager manager= FileBuffers.getTextFileBufferManager(); final IPath path= file.getFullPath(); monitor.beginTask("", 2); //$NON-NLS-1$ ITextFileBuffer buffer= null; try { manager.connect(path, LocationKind.IFILE, new SubProgressMonitor(monitor, 1)); buffer= manager.getTextFileBuffer(path, LocationKind.IFILE); IDocument document= buffer.getDocument(); if (document instanceof IDocumentExtension4) { return ((IDocumentExtension4)document).getModificationStamp(); } else { return file.getModificationStamp(); } } finally { if (buffer != null) manager.disconnect(path, LocationKind.IFILE, new SubProgressMonitor(monitor, 1)); monitor.done(); } }
Example #8
Source File: CleanUpPostSaveListener.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private void performEdit(IDocument document, long oldFileValue, LinkedList<UndoEdit> editCollector, long[] oldDocValue, boolean[] setContentStampSuccess) throws MalformedTreeException, BadLocationException, CoreException { if (document instanceof IDocumentExtension4) { oldDocValue[0]= ((IDocumentExtension4)document).getModificationStamp(); } else { oldDocValue[0]= oldFileValue; } // perform the changes for (int index= 0; index < fUndos.length; index++) { UndoEdit edit= fUndos[index]; UndoEdit redo= edit.apply(document, TextEdit.CREATE_UNDO); editCollector.addFirst(redo); } if (document instanceof IDocumentExtension4 && fDocumentStamp != IDocumentExtension4.UNKNOWN_MODIFICATION_STAMP) { try { ((IDocumentExtension4)document).replace(0, 0, "", fDocumentStamp); //$NON-NLS-1$ setContentStampSuccess[0]= true; } catch (BadLocationException e) { throw wrapBadLocationException(e); } } }
Example #9
Source File: OrganizeImportsHandler.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
public void doOrganizeImports(final IXtextDocument document) { List<ReplaceRegion> result = document.priorityReadOnly(new IUnitOfWork<List<ReplaceRegion>, XtextResource>() { @Override public List<ReplaceRegion> exec(XtextResource state) throws Exception { return importOrganizer.getOrganizedImportChanges(state); } }); if (result == null || result.isEmpty()) return; try { DocumentRewriteSession session = null; if(document instanceof IDocumentExtension4) { session = ((IDocumentExtension4)document).startRewriteSession(DocumentRewriteSessionType.UNRESTRICTED); } replaceConverter.convertToTextEdit(result).apply(document); if(session != null) { ((IDocumentExtension4)document).stopRewriteSession(session); } } catch (BadLocationException e) { LOG.error(Messages.OrganizeImportsHandler_organizeImportsErrorMessage, e); } }
Example #10
Source File: ChangeManager.java From n4js with Eclipse Public License 1.0 | 6 votes |
/** * Applies all given changes to the given document. This method assumes that 'changes' contains only changes * intended for the given document; the actual URI stored in the changes is ignored. */ public void applyAllInSameDocument(Collection<? extends IAtomicChange> changes, IDocument document) throws BadLocationException { DocumentRewriteSession rewriteSession = null; try { // prepare if (document instanceof IDocumentExtension4) { rewriteSession = ((IDocumentExtension4) document).startRewriteSession( DocumentRewriteSessionType.UNRESTRICTED); } // perform replacements for (IAtomicChange currRepl : changes) { currRepl.apply(document); } } finally { // cleanup if (rewriteSession != null) ((IDocumentExtension4) document).stopRewriteSession(rewriteSession); } }
Example #11
Source File: XtextTemplateProposal.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
@Override public void apply(ITextViewer viewer, char trigger, int stateMask, int offset) { IDocument document = viewer.getDocument(); // ImportsVariableResolver may add imports, so start a rewrite session if possible. // This will compound all document changes in one Undo entry. if (document instanceof IDocumentExtension4) { IDocumentExtension4 docExt4 = (IDocumentExtension4) document; DocumentRewriteSession session = docExt4.startRewriteSession(DocumentRewriteSessionType.UNRESTRICTED); super.apply(viewer, trigger, stateMask, offset); if (session != null) { docExt4.stopRewriteSession(session); } } else { super.apply(viewer, trigger, stateMask, offset); } }
Example #12
Source File: XtextTemplateContext.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
protected TemplateTranslator createTemplateTranslator() { try { int offset = getStart(); IRegion lineRegion = getDocument().getLineInformationOfOffset(offset); String line = getDocument().get(lineRegion.getOffset(), lineRegion.getLength()); String lineDelimiter = getDocument() instanceof IDocumentExtension4 ? ((IDocumentExtension4) getDocument()).getDefaultLineDelimiter() : null; int i = 0; while (i < line.length() && Character.isWhitespace(line.charAt(i))) { i++; } if (i != 0) return new IndentationAwareTemplateTranslator(line.substring(0, i), lineDelimiter); return new IndentationAwareTemplateTranslator("", lineDelimiter); } catch (BadLocationException ex) { return new TemplateTranslator(); } }
Example #13
Source File: EmbeddedEditorModelAccess.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
public void updateModel(String prefix, String editablePart, String suffix) { IDocument document = this.viewer.getDocument(); if (this.insertLineBreaks) { String delimiter = document.getLegalLineDelimiters()[0]; if (document instanceof IDocumentExtension4) { delimiter = ((IDocumentExtension4) document).getDefaultLineDelimiter(); } prefix = prefix + delimiter; suffix = delimiter + suffix; } String model = prefix + editablePart + suffix; this.viewer.setRedraw(false); this.viewer.getUndoManager().disconnect(); document.set(model); this.viewer.setVisibleRegion(prefix.length(), editablePart.length()); this.viewer.getUndoManager().connect(this.viewer); this.viewer.setRedraw(true); }
Example #14
Source File: EmbeddedEditorModelAccess.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
public void updatePrefix(String prefix) { try { IDocument document = this.viewer.getDocument(); IRegion visibleRegion = this.viewer.getVisibleRegion(); String editablePart = document.get(visibleRegion.getOffset(), visibleRegion.getLength()); int suffixOffset = visibleRegion.getOffset() + visibleRegion.getLength(); String suffix = ""; if (document.getLength() - suffixOffset > 0) { suffix = document.get(suffixOffset, document.getLength() - suffixOffset); if (this.insertLineBreaks) { String delimiter = document.getLegalLineDelimiters()[0]; if (document instanceof IDocumentExtension4) { delimiter = ((IDocumentExtension4) document).getDefaultLineDelimiter(); } suffix = suffix.substring(delimiter.length()); } } updateModel(prefix, editablePart, suffix); } catch (BadLocationException e) { throw new RuntimeException(e); } }
Example #15
Source File: PyChange.java From Pydev with Eclipse Public License 1.0 | 5 votes |
public void checkModificationStamp(RefactoringStatus status, long stampToMatch) { if (fKind == DOCUMENT) { if (stampToMatch != IDocumentExtension4.UNKNOWN_MODIFICATION_STAMP && fModificationStamp != stampToMatch) { status.addFatalError(StringUtils.format("Resource %s has modifications", fResource.getFullPath())); } } else { if (stampToMatch != IResource.NULL_STAMP && fModificationStamp != stampToMatch) { status.addFatalError(StringUtils.format("Resource %s has modifications", fResource.getFullPath())); } } }
Example #16
Source File: RefactoringRequest.java From Pydev with Eclipse Public License 1.0 | 5 votes |
/** * @return the module for the document (may return the ast from the pyedit if it is available). */ public IModule getModule() { if (module == null) { if (pyEdit != null) { SimpleNode ast = (SimpleNode) pyEdit.getAST(); if (ast != null) { IDocument doc = ps.getDoc(); long astModificationTimeStamp = pyEdit.getAstModificationTimeStamp(); if (astModificationTimeStamp != -1 && astModificationTimeStamp == (((IDocumentExtension4) doc).getModificationStamp())) { //Matched time stamp -- so, we can use the ast without fear of being unsynched. module = AbstractModule.createModule(ast, file, resolveModule(), nature); } else { //Did not match time stamp!! We'll reparse the document later on to get a synched version. } } } if (module == null) { try { module = AbstractModule.createModuleFromDoc(resolveModule(), file, ps.getDoc(), nature, false); } catch (MisconfigurationException e) { throw new RuntimeException(e); } } } return module; }
Example #17
Source File: OrganizeImportsFixesUnused.java From Pydev with Eclipse Public License 1.0 | 5 votes |
public boolean beforePerformArrangeImports(PySelection ps, PyEdit edit, IFile f) { int oldSelection = ps.getRegion().getOffset(); IDocumentExtension4 doc = (IDocumentExtension4) ps.getDoc(); if (edit != null) { if (!ensureParsed(edit)) { return true; } //Check that the editor time is actually the same as the document time. long docTime = doc.getModificationStamp(); if (docTime != edit.getAstModificationTimeStamp()) { return true; } ErrorDescription errorDescription = edit.getErrorDescription(); if (errorDescription != null) { return true; //Don't remove unused imports if we have syntax errors. } } try { findAndDeleteUnusedImports(ps, edit, doc, f); } catch (Exception e) { Log.log(e); } ps.setSelection(oldSelection, oldSelection); return true; }
Example #18
Source File: XtextReconcilerDebugger.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
public void assertModelInSyncWithDocument(IDocument document, XtextResource resource, final ReconcilerReplaceRegion region) { if (document instanceof IDocumentExtension4 && resource != null) { long beforeGet = ((IDocumentExtension4) document).getModificationStamp(); final String documentContent = document.get(); long afterGet = ((IDocumentExtension4) document).getModificationStamp(); if (beforeGet == afterGet && beforeGet == resource.getModificationStamp()) { IParseResult parseResult = resource.getParseResult(); if (parseResult != null) { ICompositeNode rootNode = parseResult.getRootNode(); final String resourceContent = rootNode.getText(); if (!resourceContent.equals(documentContent)) { new DisplayRunnable() { @Override protected void run() throws Exception { LOG.error("XtextDocument and XtextResource have run out of sync:\n" + DiffUtil.diff(documentContent, resourceContent)); LOG.error("Events: \n\t" + Joiner.on("\n\t").join(region.getDocumentEvents())); LOG.error("ReplaceRegion: \n\t'" + region + "'" ); MessageDialog.openError( Display.getCurrent().getActiveShell(), "XtextReconcilerDebugger", "XtextDocument and XtextResource have run out of sync." + "\n\nSee log for details."); } }.syncExec(); } else { if (LOG.isDebugEnabled()) LOG.debug("Model and document are in sync"); } } } } }
Example #19
Source File: DocumentChanged.java From Pydev with Eclipse Public License 1.0 | 5 votes |
public static boolean hasDocumentChanged(IResource resource, IDocument document) { Tuple3<Long, Long, WeakReference<IDocument>> tuple = fileToSavedTime.get(resource); if (tuple == null) { return false; } IDocument cachedDoc = tuple.o3.get(); if (cachedDoc == document) { if (((IDocumentExtension4) document).getModificationStamp() == tuple.o1) { return false; } return true; } return false; }
Example #20
Source File: TextSelectionUtils.java From Pydev with Eclipse Public License 1.0 | 5 votes |
/** * Starts a rewrite session (keep things in a single undo/redo) */ public static DocumentRewriteSession startWrite(IDocument doc) { if (doc instanceof IDocumentExtension4) { IDocumentExtension4 d = (IDocumentExtension4) doc; return d.startRewriteSession(DocumentRewriteSessionType.UNRESTRICTED); } return null; }
Example #21
Source File: TextSelectionUtils.java From Pydev with Eclipse Public License 1.0 | 5 votes |
/** * Stop a rewrite session */ public static void endWrite(IDocument doc, DocumentRewriteSession session) { if (doc instanceof IDocumentExtension4 && session != null) { IDocumentExtension4 d = (IDocumentExtension4) doc; d.stopRewriteSession(session); } }
Example #22
Source File: ScopeSelectionAction.java From Pydev with Eclipse Public License 1.0 | 5 votes |
private static String getCurrentSelectionCacheKey(BaseEditor pyEdit) { IDocument doc = pyEdit.getDocument(); int length = doc.getLength(); String key = Integer.toString(length); if (doc instanceof IDocumentExtension4) { IDocumentExtension4 document = (IDocumentExtension4) doc; long modificationStamp = document.getModificationStamp(); key += " - " + modificationStamp; } return key; }
Example #23
Source File: EditorDocumentUndoChange.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
protected UndoEdit performEdits(IDocument document) throws BadLocationException, MalformedTreeException { DocumentRewriteSession session = null; try { if (document instanceof IDocumentExtension4) { session = ((IDocumentExtension4) document).startRewriteSession(DocumentRewriteSessionType.UNRESTRICTED); } return undoEdit.apply(document); } finally { if (session != null) { ((IDocumentExtension4) document).stopRewriteSession(session); } } }
Example #24
Source File: EmacsPlusUtils.java From e4macs with Eclipse Public License 1.0 | 5 votes |
public static final String getEol(IDocument document) { String eol = "\n"; //$NON-NLS-1$ try { if (document instanceof IDocumentExtension4) { eol = ((IDocumentExtension4)document).getDefaultLineDelimiter(); } else { eol = document.getLineDelimiter(0); } } catch (BadLocationException e) { } return eol; }
Example #25
Source File: MinibufferImpl.java From e4macs with Eclipse Public License 1.0 | 5 votes |
private void setEolChars(IDocument document) { try { if (document instanceof IDocumentExtension4) { eol = ((IDocumentExtension4)document).getDefaultLineDelimiter(); } else { eol = document.getLineDelimiter(0); } int eolLen = eol.length(); eolcp = new int[eolLen]; for (int i=0; i<eolLen; i++) { eolcp[i] = eol.codePointAt(i); } } catch (BadLocationException e) { } }
Example #26
Source File: WithMinibuffer.java From e4macs with Eclipse Public License 1.0 | 5 votes |
protected final String getEol() { IDocument document = getDocument(); if (eol == null) { try { if (document instanceof IDocumentExtension4) { eol = ((IDocumentExtension4)document).getDefaultLineDelimiter(); } else { eol = document.getLineDelimiter(0); } } catch (BadLocationException e) { } } return eol; }
Example #27
Source File: XtextDocumentProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
public UnchangedElementListener(ElementInfo element) { this.element = element; if (element.fDocument instanceof IDocumentExtension4) { modificationStamp = ((IDocumentExtension4) element.fDocument).getModificationStamp(); } else { modificationStamp = IDocumentExtension4.UNKNOWN_MODIFICATION_STAMP; } }
Example #28
Source File: AbstractThemeableEditor.java From APICloud-Studio with GNU General Public License v3.0 | 5 votes |
public ParseResult getParseResult() { try { IDocument document = getDocument(); if (document == null) { return null; } long modificationStamp = IDocumentExtension4.UNKNOWN_MODIFICATION_STAMP; if (document instanceof IDocumentExtension4) { synchronized (modificationStampLock) { IDocumentExtension4 iDocumentExtension = (IDocumentExtension4) document; modificationStamp = iDocumentExtension.getModificationStamp(); if (modificationStamp != IDocumentExtension4.UNKNOWN_MODIFICATION_STAMP && modificationStamp == lastModificationStamp) { return lastAstForModificationStamp; } } } // Don't synchronize the actual parse! ParseResult ast = doGetAST(document); synchronized (modificationStampLock) { lastAstForModificationStamp = ast; lastModificationStamp = modificationStamp; return lastAstForModificationStamp; } } catch (Throwable e) { IdeLog.logTrace(CommonEditorPlugin.getDefault(), e.getMessage(), e, IDebugScopes.AST); } return null; }
Example #29
Source File: AbstractThemeableEditor.java From APICloud-Studio with GNU General Public License v3.0 | 5 votes |
@Override protected void doSetInput(IEditorInput input) throws CoreException { synchronized (modificationStampLock) { // Reset our cache when a new input is set. lastModificationStamp = IDocumentExtension4.UNKNOWN_MODIFICATION_STAMP; lastAstForModificationStamp = null; } super.doSetInput(input); }
Example #30
Source File: XtextDocumentProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Override public long getModificationStamp(Object element) { if (isWorkspaceExternalEditorInput(element)) { IFileStore fileStore = Adapters.adapt(element, IFileStore.class); if (fileStore != null) { IFileInfo info = fileStore.fetchInfo(); if (info.exists()) { return info.getLastModified(); } } return IDocumentExtension4.UNKNOWN_MODIFICATION_STAMP; } else { return super.getModificationStamp(element); } }