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 156258 Details for
Bug 252379
Organize imports deletes needed static import.
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Proposed fix
patch_252379.txt (text/plain), 6.49 KB, created by
Olivier Thomann
on 2010-01-15 13:17:55 EST
(
hide
)
Description:
Proposed fix
Filename:
MIME Type:
Creator:
Olivier Thomann
Created:
2010-01-15 13:17:55 EST
Size:
6.49 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.core >Index: dom/org/eclipse/jdt/core/dom/rewrite/ImportRewrite.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/rewrite/ImportRewrite.java,v >retrieving revision 1.17 >diff -u -r1.17 ImportRewrite.java >--- dom/org/eclipse/jdt/core/dom/rewrite/ImportRewrite.java 7 Mar 2009 01:08:09 -0000 1.17 >+++ dom/org/eclipse/jdt/core/dom/rewrite/ImportRewrite.java 15 Jan 2010 18:16:14 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2009 IBM Corporation and others. >+ * Copyright (c) 2000, 2010 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -12,7 +12,9 @@ > package org.eclipse.jdt.core.dom.rewrite; > > import java.util.ArrayList; >+import java.util.HashMap; > import java.util.List; >+import java.util.Map; > > import org.eclipse.core.runtime.CoreException; > import org.eclipse.core.runtime.IProgressMonitor; >@@ -122,6 +124,7 @@ > > private final boolean restoreExistingImports; > private final List existingImports; >+ private final Map importsKindMap; > > private String[] importOrder; > private int importOnDemandThreshold; >@@ -232,6 +235,8 @@ > this.importOrder= CharOperation.NO_STRINGS; > this.importOnDemandThreshold= 99; > this.staticImportOnDemandThreshold= 99; >+ >+ this.importsKindMap = new HashMap(); > } > > >@@ -345,7 +350,13 @@ > int res= compareImport(prefix, qualifier, name, curr); > if (res != ImportRewriteContext.RES_NAME_UNKNOWN) { > if (!allowAmbiguity || res == ImportRewriteContext.RES_NAME_FOUND) { >- return res; >+ if (prefix != STATIC_PREFIX) { >+ return res; >+ } >+ Object currKind = this.importsKindMap.get(curr.substring(1)); >+ if (currKind != null && currKind.equals(this.importsKindMap.get(qualifier + '.' + name))) { >+ return res; >+ } > } > } > } >@@ -832,19 +843,21 @@ > * an import conflict prevented the import. > */ > public String addStaticImport(String declaringTypeName, String simpleName, boolean isField, ImportRewriteContext context) { >+ String key = declaringTypeName + '.' + simpleName; > if (declaringTypeName.indexOf('.') == -1) { >- return declaringTypeName + '.' + simpleName; >+ return key; > } > if (context == null) { > context= this.defaultContext; > } > int kind= isField ? ImportRewriteContext.KIND_STATIC_FIELD : ImportRewriteContext.KIND_STATIC_METHOD; >+ this.importsKindMap.put(key, new Integer(kind)); > int res= context.findInContext(declaringTypeName, simpleName, kind); > if (res == ImportRewriteContext.RES_NAME_CONFLICT) { >- return declaringTypeName + '.' + simpleName; >+ return key; > } > if (res == ImportRewriteContext.RES_NAME_UNKNOWN) { >- addEntry(STATIC_PREFIX + declaringTypeName + '.' + simpleName); >+ addEntry(STATIC_PREFIX + key); > } > return simpleName; > } >#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.14 >diff -u -r1.14 ImportRewriteTest.java >--- src/org/eclipse/jdt/core/tests/rewrite/describing/ImportRewriteTest.java 16 Nov 2009 15:07:36 -0000 1.14 >+++ src/org/eclipse/jdt/core/tests/rewrite/describing/ImportRewriteTest.java 15 Jan 2010 18:16:15 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2008 IBM Corporation and others. >+ * Copyright (c) 2000, 2010 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -922,6 +922,63 @@ > assertEqualString(cu.getSource(), buf.toString()); > } > >+ public void testBug252379() throws CoreException, BackingStoreException, >+ MalformedTreeException, BadLocationException { >+ >+ >+ ICompilationUnit[] units = new ICompilationUnit[3]; >+ >+ IPackageFragment pack1 = this.sourceFolder.createPackageFragment( >+ "bug", false, null); >+ >+ StringBuffer buf = new StringBuffer(); >+ buf.append("package bug;\n"); >+ buf.append("\n"); >+ buf.append("enum CaseType {\n"); >+ buf.append("\tone;\n"); >+ buf.append("\tstatic CaseType[] all(){return null;}\n"); >+ buf.append("}\n"); >+ >+ units[0] = pack1.createCompilationUnit("CaseType.java", buf.toString(), false, null); >+ >+ buf = new StringBuffer(); >+ buf.append("package bug;\n"); >+ buf.append("enum ShareLevel{all})\n"); >+ >+ units[1] = pack1.createCompilationUnit("ShareLevel.java", buf.toString(), false, null); >+ >+ buf = new StringBuffer(); >+ buf.append("package bug;\n"); >+ buf.append("class Bug {\n"); >+ buf.append("public ShareLevel createControl() {\n"); >+ buf.append("for (CaseType cat : all())\n"); >+ buf.append("cat.hashCode();\n"); >+ buf.append("ShareLevel temp = all;\n"); >+ buf.append("return temp;\n"); >+ buf.append("};\n"); >+ buf.append("}\n"); >+ units[2] = pack1.createCompilationUnit("Bug.java", buf.toString(), false, null); >+ >+ ImportRewrite imports = newImportsRewrite(units[2], new String[] {}, 99, 99, false); >+ imports.addStaticImport("bug.CaseType", "all", false); >+ imports.addStaticImport("bug.ShareLevel", "all", true); >+ >+ apply(imports); >+ >+ buf = new StringBuffer(); >+ buf.append("package bug;\n\n"); >+ buf.append("import static bug.CaseType.all;\n"); >+ buf.append("import static bug.ShareLevel.all;\n\n"); >+ buf.append("class Bug {\n"); >+ buf.append("public ShareLevel createControl() {\n"); >+ buf.append("for (CaseType cat : all())\n"); >+ buf.append("cat.hashCode();\n"); >+ buf.append("ShareLevel temp = all;\n"); >+ buf.append("return temp;\n"); >+ buf.append("};\n"); >+ buf.append("}\n"); >+ assertEqualString(units[2].getSource(), buf.toString()); >+ } > > private void assertAddedAndRemoved(ImportRewrite imports, String[] expectedAdded, String[] expectedRemoved, String[] expectedAddedStatic, String[] expectedRemovedStatic) { > assertEqualStringsIgnoreOrder(imports.getAddedImports(), expectedAdded);
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 252379
:
155406
|
155715
| 156258