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 250583 Details for
Bug 459320
[ImportRewrite] adds import for declared package when pasting to CU outside of classpath
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Fix in old ImportRewriteAnalyzer
eclipse.jdt.core.patch (text/plain), 2.30 KB, created by
Markus Keller
on 2015-02-06 09:40:34 EST
(
hide
)
Description:
Fix in old ImportRewriteAnalyzer
Filename:
MIME Type:
Creator:
Markus Keller
Created:
2015-02-06 09:40:34 EST
Size:
2.30 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.core >diff --git dom/org/eclipse/jdt/internal/core/dom/rewrite/ImportRewriteAnalyzer.java dom/org/eclipse/jdt/internal/core/dom/rewrite/ImportRewriteAnalyzer.java >index c83c7f2..49669bd 100644 >--- dom/org/eclipse/jdt/internal/core/dom/rewrite/ImportRewriteAnalyzer.java >+++ dom/org/eclipse/jdt/internal/core/dom/rewrite/ImportRewriteAnalyzer.java >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2013 IBM Corporation and others. >+ * Copyright (c) 2000, 2015 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 >@@ -25,6 +25,7 @@ > import org.eclipse.jdt.core.IBuffer; > import org.eclipse.jdt.core.ICompilationUnit; > import org.eclipse.jdt.core.IJavaElement; >+import org.eclipse.jdt.core.IPackageDeclaration; > import org.eclipse.jdt.core.JavaCore; > import org.eclipse.jdt.core.JavaModelException; > import org.eclipse.jdt.core.Signature; >@@ -617,10 +618,29 @@ > return true; > } > ICompilationUnit cu= this.compilationUnit; >- String packageName= cu.getParent().getElementName(); >+ IJavaElement packageFragment = cu.getParent(); >+ String packageName= packageFragment.getElementName(); > if (qualifier.equals(packageName)) { > return true; > } >+ if (packageName.isEmpty() && !packageFragment.exists() && cu.exists()) { >+ /* >+ * For a file outside of the build path, JavaCore#create(IFile) creates an >+ * ICompilationUnit with the file's parent folder as package fragment root, and a default package. >+ * That "wrong" package is problematic for the ImportRewrite, since it doesn't get filtered >+ * and eventually leads to unused import statements. >+ */ >+ try { >+ IPackageDeclaration[] packageDeclarations = this.compilationUnit.getPackageDeclarations(); >+ if (packageDeclarations.length > 0) { >+ if (qualifier.equals(packageDeclarations[0].getElementName())) { >+ return true; >+ } >+ } >+ } catch (JavaModelException e) { >+ // continue >+ } >+ } > String mainTypeName= JavaCore.removeJavaLikeExtension(cu.getElementName()); > if (packageName.length() == 0) { > return qualifier.equals(mainTypeName);
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 459320
: 250583