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 148758 Details for
Bug 194358
[import rewrite] Organize Imports produces wrong order of imports
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Patch with added performance test
patch_194358_1.txt (text/plain), 7.91 KB, created by
Jay Arthanareeswaran
on 2009-10-05 07:09:52 EDT
(
hide
)
Description:
Patch with added performance test
Filename:
MIME Type:
Creator:
Jay Arthanareeswaran
Created:
2009-10-05 07:09:52 EDT
Size:
7.91 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.core >Index: dom/org/eclipse/jdt/internal/core/dom/rewrite/ImportRewriteAnalyzer.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/rewrite/ImportRewriteAnalyzer.java,v >retrieving revision 1.15 >diff -u -r1.15 ImportRewriteAnalyzer.java >--- dom/org/eclipse/jdt/internal/core/dom/rewrite/ImportRewriteAnalyzer.java 7 Mar 2009 00:59:06 -0000 1.15 >+++ dom/org/eclipse/jdt/internal/core/dom/rewrite/ImportRewriteAnalyzer.java 5 Oct 2009 10:47:13 -0000 >@@ -21,6 +21,7 @@ > import org.eclipse.jdt.core.IBuffer; > import org.eclipse.jdt.core.ICompilationUnit; > import org.eclipse.jdt.core.IJavaElement; >+import org.eclipse.jdt.core.IType; > import org.eclipse.jdt.core.JavaCore; > import org.eclipse.jdt.core.JavaModelException; > import org.eclipse.jdt.core.Signature; >@@ -168,9 +169,30 @@ > } > } > >- private static String getQualifier(ImportDeclaration decl) { >+ private String getQualifier(ImportDeclaration decl) { > String name= decl.getName().getFullyQualifiedName(); >- return decl.isOnDemand() ? name : Signature.getQualifier(name); >+ if (decl.isOnDemand()) { >+ return name; >+ } >+ return getQualifier(name); >+ } >+ >+ private String getQualifier(String name) { >+ try { >+ // If our element is an inner class, we need to back up to the top-level >+ // enclosing type and use the package that it is in as a qualifier. >+ // This fixes bug 194358. >+ do { >+ IType element = this.compilationUnit.getJavaProject().findType(name); >+ name = Signature.getQualifier(name); >+ if (element == null || element.getDeclaringType() == null) { >+ break; >+ } >+ } while (true); >+ } catch (JavaModelException e) { >+ // Should never happen. >+ } >+ return name; > } > > private static String getFullName(ImportDeclaration decl) { >@@ -401,7 +423,7 @@ > } > > public void addImport(String fullTypeName, boolean isStatic) { >- String typeContainerName= Signature.getQualifier(fullTypeName); >+ String typeContainerName= getQualifier(fullTypeName); > ImportDeclEntry decl= new ImportDeclEntry(fullTypeName, isStatic, null); > sortIn(typeContainerName, decl, isStatic); > } >#P org.eclipse.jdt.core.tests.performance >Index: src/org/eclipse/jdt/core/tests/performance/FullSourceWorkspaceASTTests.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.performance/src/org/eclipse/jdt/core/tests/performance/FullSourceWorkspaceASTTests.java,v >retrieving revision 1.26 >diff -u -r1.26 FullSourceWorkspaceASTTests.java >--- src/org/eclipse/jdt/core/tests/performance/FullSourceWorkspaceASTTests.java 7 Mar 2009 02:04:23 -0000 1.26 >+++ src/org/eclipse/jdt/core/tests/performance/FullSourceWorkspaceASTTests.java 5 Oct 2009 10:47:21 -0000 >@@ -19,10 +19,15 @@ > > import junit.framework.*; > >+import org.eclipse.core.runtime.CoreException; > import org.eclipse.jdt.core.*; > import org.eclipse.jdt.core.compiler.IProblem; > import org.eclipse.jdt.core.dom.*; >+import org.eclipse.jdt.core.dom.rewrite.ImportRewrite; > import org.eclipse.jdt.core.tests.model.AbstractJavaModelTests; >+import org.eclipse.jface.text.BadLocationException; >+import org.eclipse.text.edits.MalformedTreeException; >+import org.osgi.service.prefs.BackingStoreException; > > /** > */ >@@ -723,6 +728,21 @@ > commitMeasurements(); > assertPerformance(); > } >+ private ImportRewrite rewriteImport(ICompilationUnit cu, String[] order, >+ int normalThreshold, int staticThreshold, >+ boolean restoreExistingImports) throws CoreException, >+ BackingStoreException, MalformedTreeException, BadLocationException { >+ >+ ImportRewrite rewrite = ImportRewrite >+ .create(cu, restoreExistingImports); >+ rewrite.setImportOrder(order); >+ rewrite.setOnDemandImportThreshold(normalThreshold); >+ rewrite.setStaticOnDemandImportThreshold(staticThreshold); >+ >+ rewrite.rewriteImports(null); >+ >+ return rewrite; >+ } > > /** > * Create AST nodes tree for all compilation units in JUnit project. >@@ -733,4 +753,31 @@ > tagAsSummary("DOM AST tree for project files (JLS3)", true); // put in fingerprint > runAstCreation(getProject("org.eclipse.search")); > } >+ >+ /** >+ * Rewrite imports for a CompilationUnit with many import statements - JavaProject.java has about 80 and >+ * used here. >+ * >+ */ >+ public void testPerfImportRewrite() throws MalformedTreeException, CoreException, BackingStoreException, BadLocationException { >+ tagAsSummary("Test Performance of Import Rewrite", false); // do NOT put in fingerprint >+ >+ String[] order= new String[] {"org", "javax", "java"}; >+ >+ int measures = MEASURES_COUNT * 2; >+ int internalLoop = 20; >+ for (int i = 0; i < measures; i++) { >+ runGc(); >+ startMeasuring(); >+ for (int index = 0; index < internalLoop; index++ ) { >+ ICompilationUnit unit = getCompilationUnit("org.eclipse.jdt.core", "org.eclipse.jdt.internal.core", "JavaProject.java"); >+ rewriteImport(unit, order, 99, 99, false); >+ } >+ stopMeasuring(); >+ } >+ commitMeasurements(); >+ assertPerformance(); >+ >+ } >+ > } >#P org.eclipse.jdt.core.tests.model >Index: src/org/eclipse/jdt/core/tests/rewrite/describing/ImportRewriteTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ImportRewriteTest.java,v >retrieving revision 1.12 >diff -u -r1.12 ImportRewriteTest.java >--- src/org/eclipse/jdt/core/tests/rewrite/describing/ImportRewriteTest.java 24 Oct 2008 10:40:41 -0000 1.12 >+++ src/org/eclipse/jdt/core/tests/rewrite/describing/ImportRewriteTest.java 5 Oct 2009 10:47:29 -0000 >@@ -572,6 +572,57 @@ > assertEqualString(cu.getSource(), buf.toString()); > } > >+ /** >+ * Test that import statements of inner classes are written right after the enclosing type >+ * and before other types. >+ * >+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=194358" >+ */ >+ public void testAddImports_bug194358() throws Exception { >+ >+ IPackageFragment pack1= this.sourceFolder.createPackageFragment("pack1", false, null); >+ StringBuffer buf= new StringBuffer(); >+ buf.append("package pack1;\n"); >+ buf.append("\n"); >+ buf.append("import pack2.A;\n"); >+ buf.append("import pack2.A.Inner;\n"); >+ buf.append("import pack2.B;\n"); >+ buf.append("\n"); >+ buf.append("public class C {\n"); >+ buf.append("}\n"); >+ >+ ICompilationUnit cu= pack1.createCompilationUnit("C.java", buf.toString(), false, null); >+ >+ // We need to actually make some state in the AST for the classes, to test that we can >+ // disambiguate between packages and inner classes (see the bug for details). >+ IPackageFragment pack2= this.sourceFolder.createPackageFragment("pack2", false, null); >+ ICompilationUnit aUnit= pack2.createCompilationUnit("A.java", "", false, null); >+ ICompilationUnit bUnit= pack2.createCompilationUnit("B.java", "", false, null); >+ bUnit.createType("class B {}", null, false, null); >+ >+ IType aType= aUnit.createType("class A {}", null, false, null); >+ aType.createType("class Inner {}", null, false, null); >+ String[] order= new String[] { "java" }; >+ >+ ImportRewrite imports= newImportsRewrite(cu, order, 99, 99, false); >+ imports.addImport("pack2.A"); >+ imports.addImport("pack2.A.Inner"); >+ imports.addImport("pack2.B"); >+ >+ apply(imports); >+ >+ buf= new StringBuffer(); >+ buf.append("package pack1;\n"); >+ buf.append("\n"); >+ buf.append("import pack2.A;\n"); >+ buf.append("import pack2.A.Inner;\n"); >+ buf.append("import pack2.B;\n"); >+ buf.append("\n"); >+ buf.append("public class C {\n"); >+ buf.append("}\n"); >+ assertEqualString(cu.getSource(), buf.toString()); >+ } >+ > public void testAddStaticImports1() throws Exception { > > IPackageFragment pack1= this.sourceFolder.createPackageFragment("pack1", false, null);
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 194358
:
122186
|
148389
|
148758
|
149099
|
149218
|
151351
|
151446
|
151922
|
152135
|
152716