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 56470 Details for
Bug 168954
[clean up] Provide Sort Members
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
core fix
fix_core_168954.txt (text/plain), 6.74 KB, created by
Benno Baumgartner
on 2007-01-05 12:47:26 EST
(
hide
)
Description:
core fix
Filename:
MIME Type:
Creator:
Benno Baumgartner
Created:
2007-01-05 12:47:26 EST
Size:
6.74 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.core >Index: model/org/eclipse/jdt/core/util/CompilationUnitSorter.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/core/util/CompilationUnitSorter.java,v >retrieving revision 1.35 >diff -u -r1.35 CompilationUnitSorter.java >--- model/org/eclipse/jdt/core/util/CompilationUnitSorter.java 10 May 2006 18:03:49 -0000 1.35 >+++ model/org/eclipse/jdt/core/util/CompilationUnitSorter.java 5 Jan 2007 17:24:22 -0000 >@@ -15,9 +15,11 @@ > > import org.eclipse.core.runtime.IProgressMonitor; > import org.eclipse.jdt.core.ICompilationUnit; >+import org.eclipse.jdt.core.IJavaElement; > import org.eclipse.jdt.core.JavaModelException; > import org.eclipse.jdt.core.dom.AST; > import org.eclipse.jdt.internal.core.SortElementsOperation; >+import org.eclipse.text.edits.TextEdit; > > /** > * Operation for sorting members within a compilation unit. >@@ -329,4 +331,13 @@ > operation.runOperation(monitor); > } > >+ // TODO Write JavaDoc >+ public static TextEdit sort(org.eclipse.jdt.core.dom.CompilationUnit ast, int options, Comparator comparator, IProgressMonitor monitor) throws JavaModelException { >+ if (ast == null || comparator == null) { >+ throw new IllegalArgumentException(); >+ } >+ >+ SortElementsOperation operation = new SortElementsOperation(AST.JLS3, new IJavaElement[] {ast.getJavaElement()}, null, comparator); >+ return operation.calculateEdit(ast); >+ } > } >Index: model/org/eclipse/jdt/internal/core/SortElementsOperation.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/SortElementsOperation.java,v >retrieving revision 1.36 >diff -u -r1.36 SortElementsOperation.java >--- model/org/eclipse/jdt/internal/core/SortElementsOperation.java 10 May 2006 18:03:47 -0000 1.36 >+++ model/org/eclipse/jdt/internal/core/SortElementsOperation.java 5 Jan 2007 17:24:22 -0000 >@@ -23,7 +23,6 @@ > import org.eclipse.jdt.core.IJavaModelStatusConstants; > import org.eclipse.jdt.core.JavaModelException; > import org.eclipse.jdt.core.compiler.CharOperation; >-import org.eclipse.jdt.core.dom.AST; > import org.eclipse.jdt.core.dom.ASTNode; > import org.eclipse.jdt.core.dom.ASTParser; > import org.eclipse.jdt.core.dom.ASTVisitor; >@@ -112,6 +111,23 @@ > done(); > } > } >+ >+ public TextEdit calculateEdit(org.eclipse.jdt.core.dom.CompilationUnit ast) throws JavaModelException { >+ try { >+ beginTask(Messages.operation_sortelements, getMainAmountOfWork()); >+ >+ ASTRewrite rewrite= ASTRewrite.create(ast.getAST()); >+ sortCompilationUnit(ast, rewrite); >+ >+ ICompilationUnit cu= (ICompilationUnit)this.elementsToProcess[0]; >+ String content= cu.getBuffer().getContents(); >+ Document document= new Document(content); >+ >+ return rewrite.rewriteAST(document, null); >+ } finally { >+ done(); >+ } >+ } > > /** > * Method processElement. >@@ -119,14 +135,48 @@ > * @param source > */ > private String processElement(ICompilationUnit unit, char[] source) { >+ Document document = new Document(new String(source)); > CompilerOptions options = new CompilerOptions(unit.getJavaProject().getOptions(true)); >- ASTParser parser = ASTParser.newParser(this.apiLevel); >- parser.setCompilerOptions(options.getMap()); >- parser.setSource(source); >- parser.setKind(ASTParser.K_COMPILATION_UNIT); >- parser.setResolveBindings(false); >- org.eclipse.jdt.core.dom.CompilationUnit domUnit = (org.eclipse.jdt.core.dom.CompilationUnit) parser.createAST(null); >- domUnit.accept(new ASTVisitor() { >+ ASTParser parser = ASTParser.newParser(this.apiLevel); >+ parser.setCompilerOptions(options.getMap()); >+ parser.setSource(source); >+ parser.setKind(ASTParser.K_COMPILATION_UNIT); >+ parser.setResolveBindings(false); >+ org.eclipse.jdt.core.dom.CompilationUnit ast = (org.eclipse.jdt.core.dom.CompilationUnit) parser.createAST(null); >+ >+ ASTRewrite rewriter= ASTRewrite.create(ast.getAST()); >+ sortCompilationUnit(ast, rewriter); >+ >+ RangeMarker[] markers = null; >+ final boolean needPositionsMapping = this.positions != null; >+ if (needPositionsMapping) { >+ markers = new RangeMarker[this.positions.length]; >+ for (int i= 0; i < this.positions.length; i++) { >+ markers[i]= new RangeMarker(this.positions[i], 0); >+ } >+ } >+ TextEdit edits = rewriter.rewriteAST(document, null); >+ if (needPositionsMapping) { >+ for (int i = 0, max = markers.length; i < max; i++) { >+ insert(edits, markers[i]); >+ } >+ } >+ try { >+ edits.apply(document, TextEdit.UPDATE_REGIONS); >+ if (needPositionsMapping) { >+ for (int i= 0, max = markers.length; i < max; i++) { >+ this.positions[i]= markers[i].getOffset(); >+ } >+ } >+ } catch (BadLocationException e) { >+ // ignore >+ } >+ >+ return document.get(); >+ } >+ >+ private void sortCompilationUnit(org.eclipse.jdt.core.dom.CompilationUnit ast, final ASTRewrite rewriter) { >+ ast.accept(new ASTVisitor() { > public boolean visit(org.eclipse.jdt.core.dom.CompilationUnit compilationUnit) { > List types = compilationUnit.types(); > for (Iterator iter = types.iterator(); iter.hasNext();) { >@@ -182,20 +232,8 @@ > return true; > } > }); >- final AST localAst = domUnit.getAST(); >- final ASTRewrite rewriter = ASTRewrite.create(localAst); >- RangeMarker[] markers = null; > >- final boolean needPositionsMapping = this.positions != null; >- if (needPositionsMapping) { >- markers = new RangeMarker[this.positions.length]; >- for (int i= 0; i < this.positions.length; i++) { >- markers[i]= new RangeMarker(this.positions[i], 0); >- } >- } >- String generatedSource = new String(source); >- Document document = new Document(generatedSource); >- domUnit.accept(new ASTVisitor() { >+ ast.accept(new ASTVisitor() { > public boolean visit(org.eclipse.jdt.core.dom.CompilationUnit compilationUnit) { > if (checkMalformedNodes(compilationUnit)) { > return true; // abort sorting of current element >@@ -295,25 +333,7 @@ > } > return true; > } >- }); >- TextEdit edits = rewriter.rewriteAST(document, null); >- if (needPositionsMapping) { >- for (int i = 0, max = markers.length; i < max; i++) { >- insert(edits, markers[i]); >- } >- } >- try { >- edits.apply(document, TextEdit.UPDATE_REGIONS); >- generatedSource = document.get(); >- if (needPositionsMapping) { >- for (int i= 0, max = markers.length; i < max; i++) { >- this.positions[i]= markers[i].getOffset(); >- } >- } >- } catch (BadLocationException e) { >- // ignore >- } >- return generatedSource; >+ }); > } > > /**
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 168954
:
56111
|
56112
|
56314
|
56315
|
56440
|
56470
|
57040
|
57041
|
57408