Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 90082 Details for
Bug 117694
[api] Applying edits to a ICompilationUnit
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
patch for jdt-ui
patch-117694-jdtui.txt (text/plain), 8.47 KB, created by
Martin Aeschlimann
on 2008-02-19 12:00:18 EST
(
hide
)
Description:
patch for jdt-ui
Filename:
MIME Type:
Creator:
Martin Aeschlimann
Created:
2008-02-19 12:00:18 EST
Size:
8.47 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.ui >Index: ui/org/eclipse/jdt/internal/ui/javaeditor/DocumentAdapter.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/DocumentAdapter.java,v >retrieving revision 1.34 >diff -u -r1.34 DocumentAdapter.java >--- ui/org/eclipse/jdt/internal/ui/javaeditor/DocumentAdapter.java 29 May 2007 18:41:46 -0000 1.34 >+++ ui/org/eclipse/jdt/internal/ui/javaeditor/DocumentAdapter.java 19 Feb 2008 16:55:51 -0000 >@@ -18,6 +18,9 @@ > import java.util.List; > import java.util.Set; > >+import org.eclipse.text.edits.TextEdit; >+import org.eclipse.text.edits.UndoEdit; >+ > import org.eclipse.core.runtime.Assert; > import org.eclipse.core.runtime.CoreException; > import org.eclipse.core.runtime.IPath; >@@ -43,12 +46,14 @@ > import org.eclipse.jface.text.IDocument; > import org.eclipse.jface.text.IDocumentListener; > import org.eclipse.jface.text.ISynchronizable; >+import org.eclipse.jface.text.RewriteSessionEditProcessor; > > import org.eclipse.jdt.core.BufferChangedEvent; > import org.eclipse.jdt.core.IBuffer; > import org.eclipse.jdt.core.IBufferChangedListener; > import org.eclipse.jdt.core.IOpenable; > import org.eclipse.jdt.core.JavaModelException; >+import org.eclipse.jdt.core.IBuffer.ITextEditCapability; > > import org.eclipse.jdt.ui.JavaUI; > >@@ -61,7 +66,7 @@ > * All text inserted into the buffer is converted to this line delimiter. > * This class is <code>public</code> for test purposes only. > */ >-public class DocumentAdapter implements IBuffer, IDocumentListener { >+public class DocumentAdapter implements IBuffer, IDocumentListener, ITextEditCapability { > > /** > * Internal implementation of a NULL instanceof IBuffer. >@@ -153,6 +158,32 @@ > DocumentAdapter.run(this); > } > } >+ >+ /** >+ * Executes a document replace call in the UI thread. >+ */ >+ protected class ApplyTextEditCommand implements Runnable { >+ >+ private TextEdit fEdit; >+ private UndoEdit fUndoEdit; >+ >+ public void run() { >+ try { >+ if (!isClosed()) { >+ fUndoEdit= new RewriteSessionEditProcessor(fDocument, fEdit, TextEdit.UPDATE_REGIONS | TextEdit.CREATE_UNDO).performEdits(); >+ } >+ } catch (BadLocationException x) { >+ // ignore >+ } >+ } >+ >+ public UndoEdit applyTextEdit(TextEdit edit) { >+ fEdit= edit; >+ fUndoEdit= null; >+ DocumentAdapter.run(this); >+ return fUndoEdit; >+ } >+ } > > > private static final boolean DEBUG_LINE_DELIMITERS= true; >@@ -164,6 +195,7 @@ > > private DocumentSetCommand fSetCmd= new DocumentSetCommand(); > private DocumentReplaceCommand fReplaceCmd= new DocumentReplaceCommand(); >+ private ApplyTextEditCommand fTextEditCmd= new ApplyTextEditCommand(); > > private Set fLegalLineDelimiters; > >@@ -528,4 +560,9 @@ > ((IBufferChangedListener) e.next()).bufferChanged(event); > } > } >+ >+ public UndoEdit applyTextEdit(TextEdit edit, IProgressMonitor monitor) throws JavaModelException { >+ return fTextEditCmd.applyTextEdit(edit); >+ } >+ > } >Index: core extension/org/eclipse/jdt/internal/corext/util/JavaModelUtil.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/util/JavaModelUtil.java,v >retrieving revision 1.141 >diff -u -r1.141 JavaModelUtil.java >--- core extension/org/eclipse/jdt/internal/corext/util/JavaModelUtil.java 24 Jan 2008 16:15:03 -0000 1.141 >+++ core extension/org/eclipse/jdt/internal/corext/util/JavaModelUtil.java 19 Feb 2008 16:55:51 -0000 >@@ -15,7 +15,6 @@ > import java.util.HashSet; > import java.util.Map; > >-import org.eclipse.text.edits.MalformedTreeException; > import org.eclipse.text.edits.TextEdit; > > import org.eclipse.core.runtime.Assert; >@@ -27,19 +26,10 @@ > import org.eclipse.core.runtime.Path; > import org.eclipse.core.runtime.SubProgressMonitor; > >-import org.eclipse.core.filebuffers.FileBuffers; >-import org.eclipse.core.filebuffers.ITextFileBufferManager; >-import org.eclipse.core.filebuffers.LocationKind; >- > import org.eclipse.core.resources.IFile; > import org.eclipse.core.resources.IResource; > import org.eclipse.core.resources.IStorage; > >-import org.eclipse.jface.text.BadLocationException; >-import org.eclipse.jface.text.Document; >-import org.eclipse.jface.text.IDocument; >-import org.eclipse.jface.text.RewriteSessionEditProcessor; >- > import org.eclipse.jdt.core.ClasspathContainerInitializer; > import org.eclipse.jdt.core.Flags; > import org.eclipse.jdt.core.IClasspathContainer; >@@ -71,8 +61,6 @@ > import org.eclipse.jdt.launching.JavaRuntime; > import org.eclipse.jdt.launching.environments.IExecutionEnvironment; > >-import org.eclipse.jdt.internal.ui.JavaUIStatus; >- > /** > * Utility methods for the Java Model. > */ >@@ -945,79 +933,27 @@ > * @throws ValidateEditException if validate edit fails > */ > public static void applyEdit(ICompilationUnit cu, TextEdit edit, boolean save, IProgressMonitor monitor) throws CoreException, ValidateEditException { >- if (monitor == null) { >- monitor= new NullProgressMonitor(); >- } >- monitor.beginTask(CorextMessages.JavaModelUtil_applyedit_operation, 3); >- >- try { >- IDocument document= null; >- try { >- boolean[] needsSave= { save }; >- document= aquireDocument(cu, needsSave, new SubProgressMonitor(monitor, 1)); >- if (needsSave[0]) { >- commitDocument(cu, document, edit, new SubProgressMonitor(monitor, 1)); >- } else { >- new RewriteSessionEditProcessor(document, edit, TextEdit.UPDATE_REGIONS).performEdits(); >- } >- } catch (BadLocationException e) { >- throw new CoreException(JavaUIStatus.createError(IStatus.ERROR, e)); >- } finally { >- releaseDocument(cu, document, new SubProgressMonitor(monitor, 1)); >- } >- } finally { >- monitor.done(); >- } >- } >- >- private static IDocument aquireDocument(ICompilationUnit cu, boolean[] needsSave, IProgressMonitor monitor) throws CoreException { >- if (JavaModelUtil.isPrimary(cu)) { >- IFile file= (IFile) cu.getResource(); >- if (file.exists()) { >- ITextFileBufferManager bufferManager= FileBuffers.getTextFileBufferManager(); >- IPath path= cu.getPath(); >- if (!needsSave[0] && bufferManager.getTextFileBuffer(path, LocationKind.IFILE) == null) { >- needsSave[0]= true; >- } >- bufferManager.connect(path, LocationKind.IFILE, monitor); >- return bufferManager.getTextFileBuffer(path, LocationKind.IFILE).getDocument(); >+ IFile file= (IFile) cu.getResource(); >+ if (!save || !file.exists()) { >+ cu.applyTextEdit(edit, monitor); >+ } else { >+ if (monitor == null) { >+ monitor= new NullProgressMonitor(); > } >- } >- monitor.done(); >- return new Document(cu.getSource()); >- } >- >- private static void commitDocument(ICompilationUnit cu, IDocument document, TextEdit edit, IProgressMonitor monitor) throws CoreException, MalformedTreeException, BadLocationException { >- if (JavaModelUtil.isPrimary(cu)) { >- IFile file= (IFile) cu.getResource(); >- if (file.exists()) { >+ monitor.beginTask(CorextMessages.JavaModelUtil_applyedit_operation, 2); >+ try { > IStatus status= Resources.makeCommittable(file, null); > if (!status.isOK()) { > throw new ValidateEditException(status); > } >- new RewriteSessionEditProcessor(document, edit, TextEdit.UPDATE_REGIONS).performEdits(); // apply after file is commitable >- >- ITextFileBufferManager bufferManager= FileBuffers.getTextFileBufferManager(); >- bufferManager.getTextFileBuffer(file.getFullPath(), LocationKind.IFILE).commit(monitor, true); >- return; >- } >- } >- // no commit possible, make sure changes are in >- new RewriteSessionEditProcessor(document, edit, TextEdit.UPDATE_REGIONS).performEdits(); >- } >- >- >- private static void releaseDocument(ICompilationUnit cu, IDocument document, IProgressMonitor monitor) throws CoreException { >- if (JavaModelUtil.isPrimary(cu)) { >- IFile file= (IFile) cu.getResource(); >- if (file.exists()) { >- ITextFileBufferManager bufferManager= FileBuffers.getTextFileBufferManager(); >- bufferManager.disconnect(file.getFullPath(), LocationKind.IFILE, monitor); >- return; >+ >+ cu.applyTextEdit(edit, new SubProgressMonitor(monitor, 1)); >+ >+ cu.save(new SubProgressMonitor(monitor, 1), true); >+ } finally { >+ monitor.done(); > } > } >- cu.getBuffer().setContents(document.get()); >- monitor.done(); > } > > public static boolean isImplicitImport(String qualifier, ICompilationUnit cu) {
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 117694
:
90081
| 90082 |
90839