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 160106 Details for
Bug 303776
Member types imports are removed too aggressively
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Proposed fix + regression test
patch_303776.txt (text/plain), 7.19 KB, created by
Olivier Thomann
on 2010-02-24 14:50:41 EST
(
hide
)
Description:
Proposed fix + regression test
Filename:
MIME Type:
Creator:
Olivier Thomann
Created:
2010-02-24 14:50:41 EST
Size:
7.19 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.23 >diff -u -r1.23 ImportRewriteAnalyzer.java >--- dom/org/eclipse/jdt/internal/core/dom/rewrite/ImportRewriteAnalyzer.java 17 Feb 2010 20:34:17 -0000 1.23 >+++ dom/org/eclipse/jdt/internal/core/dom/rewrite/ImportRewriteAnalyzer.java 24 Feb 2010 19:49:32 -0000 >@@ -266,7 +266,7 @@ > currEndLine++; > nextOffset= root.getPosition(currEndLine, 0); > } >- currPackage.add(new ImportDeclEntry(name, isStatic, new Region(currOffset, nextOffset - currOffset))); >+ currPackage.add(new ImportDeclEntry(packName.length(), name, isStatic, new Region(currOffset, nextOffset - currOffset))); > currOffset= nextOffset; > curr= next; > >@@ -276,7 +276,7 @@ > > currPackage= new PackageEntry(); // create a comment package entry for this > this.packageEntries.add(currPackage); >- currPackage.add(new ImportDeclEntry(null, false, new Region(currOffset, nextOffset - currOffset))); >+ currPackage.add(new ImportDeclEntry(packName.length(), null, false, new Region(currOffset, nextOffset - currOffset))); > > currOffset= nextOffset; > } >@@ -291,7 +291,7 @@ > this.packageEntries.add(currPackage); > } > int length= this.replaceRange.getOffset() + this.replaceRange.getLength() - curr.getStartPosition(); >- currPackage.add(new ImportDeclEntry(name, isStatic, new Region(curr.getStartPosition(), length))); >+ currPackage.add(new ImportDeclEntry(packName.length(), name, isStatic, new Region(curr.getStartPosition(), length))); > } > > /** >@@ -468,7 +468,7 @@ > > public void addImport(String fullTypeName, boolean isStatic) { > String typeContainerName= getQualifier(fullTypeName, isStatic); >- ImportDeclEntry decl= new ImportDeclEntry(fullTypeName, isStatic, null); >+ ImportDeclEntry decl= new ImportDeclEntry(typeContainerName.length(), fullTypeName, isStatic, null); > sortIn(typeContainerName, decl, isStatic); > } > >@@ -617,9 +617,10 @@ > > boolean doStarImport= pack.hasStarImport(threshold, onDemandConflicts); > if (doStarImport && (pack.find("*") == null)) { //$NON-NLS-1$ >- String starImportString= pack.getName() + ".*"; //$NON-NLS-1$ >- String str= getNewImportString(starImportString, isStatic, lineDelim); >- stringsToInsert.add(str); >+ String[] imports = getNewImportStrings(pack, isStatic, lineDelim); >+ for (int j = 0, max = imports.length; j < max; j++) { >+ stringsToInsert.add(imports[j]); >+ } > } > > for (int k= 0; k < nImports; k++) { >@@ -789,6 +790,25 @@ > } > return buf.toString(); > } >+ >+ private String[] getNewImportStrings(PackageEntry packageEntry, boolean isStatic, String lineDelim) { >+ boolean isStarImportAdded = false; >+ List allImports = new ArrayList(); >+ int nImports = packageEntry.getNumberOfImports(); >+ for (int i= 0; i < nImports; i++) { >+ ImportDeclEntry curr= packageEntry.getImportAt(i); >+ String simpleName = curr.getTypeQualifiedName(); >+ if (simpleName.indexOf('.') != -1) { >+ // member type imports - we preserve it >+ allImports.add(getNewImportString(curr.getElementName(), isStatic, lineDelim)); >+ } else if (!isStarImportAdded) { >+ String starImportString= packageEntry.getName() + ".*"; //$NON-NLS-1$ >+ allImports.add(getNewImportString(starImportString, isStatic, lineDelim)); >+ isStarImportAdded = true; >+ } >+ } >+ return (String[]) allImports.toArray(new String[allImports.size()]); >+ } > > private static int getFirstTypeBeginPos(CompilationUnit root) { > List types= root.types(); >@@ -844,11 +864,13 @@ > private String elementName; > private IRegion sourceRange; > private final boolean isStatic; >+ private int containerNameLength; > >- public ImportDeclEntry(String elementName, boolean isStatic, IRegion sourceRange) { >+ public ImportDeclEntry(int containerNameLength, String elementName, boolean isStatic, IRegion sourceRange) { > this.elementName= elementName; > this.sourceRange= sourceRange; > this.isStatic= isStatic; >+ this.containerNameLength = containerNameLength; > } > > public String getElementName() { >@@ -870,6 +892,10 @@ > return Signature.getSimpleName(this.elementName); > } > >+ public String getTypeQualifiedName() { >+ return this.elementName.substring(this.containerNameLength + 1); >+ } >+ > public boolean isOnDemand() { > return this.elementName != null && this.elementName.endsWith(".*"); //$NON-NLS-1$ > } >@@ -1078,11 +1104,11 @@ > int nImports= getNumberOfImports(); > for (int i= 0; i < nImports; i++) { > ImportDeclEntry curr= getImportAt(i); >- buf.append(" "); //$NON-NLS-1$ >+ buf.append(" "); //$NON-NLS-1$ > if (curr.isStatic()) { > buf.append("static "); //$NON-NLS-1$ > } >- buf.append(curr.getSimpleName()); >+ buf.append(curr.getTypeQualifiedName()); > if (curr.isNew()) { > buf.append(" (new)"); //$NON-NLS-1$ > } >#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.17 >diff -u -r1.17 ImportRewriteTest.java >--- src/org/eclipse/jdt/core/tests/rewrite/describing/ImportRewriteTest.java 17 Feb 2010 20:34:14 -0000 1.17 >+++ src/org/eclipse/jdt/core/tests/rewrite/describing/ImportRewriteTest.java 24 Feb 2010 19:49:33 -0000 >@@ -302,6 +302,39 @@ > assertEqualString(cu.getSource(), buf.toString()); > } > >+ public void testAddImports5() throws Exception { >+ getJavaProject("P").setOption(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_SEMICOLON, JavaCore.INSERT); >+ >+ IPackageFragment pack1= this.sourceFolder.createPackageFragment("pack1", false, null); >+ StringBuffer buf= new StringBuffer(); >+ buf.append("package pack1;\n"); >+ buf.append("\n"); >+ buf.append("public class C {\n"); >+ buf.append("}\n"); >+ ICompilationUnit cu= pack1.createCompilationUnit("C.java", buf.toString(), false, null); >+ >+ String[] order= new String[] { "java", "java.util", "com", "pack" }; >+ >+ ImportRewrite imports= newImportsRewrite(cu, order, 1, 1, true); >+ imports.setUseContextToFilterImplicitImports(true); >+ imports.addImport("java.util.Map"); >+ imports.addImport("java.util.Set"); >+ imports.addImport("java.util.Map.Entry"); >+ imports.addImport("java.util.Collections"); >+ >+ apply(imports); >+ >+ buf= new StringBuffer(); >+ buf.append("package pack1;\n"); >+ buf.append("\n"); >+ buf.append("import java.util.* ;\n"); >+ buf.append("import java.util.Map.Entry ;\n"); >+ buf.append("\n"); >+ buf.append("public class C {\n"); >+ buf.append("}\n"); >+ assertEqualString(cu.getSource(), buf.toString()); >+ } >+ > public void testAddImportsWithGroupsOfUnmatched1() 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 303776
:
160089
| 160106