Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNoopur Gupta2014-01-10 09:07:02 +0000
committerMarkus Keller2014-02-25 15:28:02 +0000
commit5e66e8472e34be92037ee14a97b8af1a4339af50 (patch)
treeab3e4b9f837022116671a966e114e5ef85aa0ca6
parent63859c4954c185343769e4ae41ac237a5fbd31f7 (diff)
downloadeclipse.jdt.ui-5e66e8472e34be92037ee14a97b8af1a4339af50.tar.gz
eclipse.jdt.ui-5e66e8472e34be92037ee14a97b8af1a4339af50.tar.xz
eclipse.jdt.ui-5e66e8472e34be92037ee14a97b8af1a4339af50.zip
Fixed bug 424172: [1.8][organize imports] Unused static import for
Character::isUpperCase added
-rw-r--r--org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/ImportOrganizeTest18.java41
-rw-r--r--org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/codemanipulation/ImportReferencesCollector.java7
2 files changed, 47 insertions, 1 deletions
diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/ImportOrganizeTest18.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/ImportOrganizeTest18.java
index db2d7989df..c374ceb352 100644
--- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/ImportOrganizeTest18.java
+++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/ImportOrganizeTest18.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2013 IBM Corporation and others.
+ * Copyright (c) 2000, 2014 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
@@ -297,4 +297,43 @@ public class ImportOrganizeTest18 extends ImportOrganizeTest {
assertEqualString(cu.getSource(), buf.toString());
}
+ public void testStaticMethodReferenceImports_bug424172() throws Exception {
+ IPackageFragmentRoot sourceFolder= JavaProjectHelper.addSourceContainer(fJProject1, "src");
+
+ IPackageFragment pack0= sourceFolder.createPackageFragment("p", false, null);
+ StringBuffer buf= new StringBuffer();
+ buf.append("package p;\n");
+ buf.append("\n");
+ buf.append("import java.util.function.IntPredicate;\n");
+ buf.append("\n");
+ buf.append("class UnusedStaticImport {\n");
+ buf.append(" boolean value = match(Character::isUpperCase, 'A');\n");
+ buf.append("\n");
+ buf.append(" public static boolean match(IntPredicate matcher, int codePoint) {\n");
+ buf.append(" return matcher.test(codePoint);\n");
+ buf.append(" }\n");
+ buf.append("}\n");
+ ICompilationUnit cu= pack0.createCompilationUnit("UnusedStaticImport.java", buf.toString(), false, null);
+
+ String[] order= new String[] {};
+ IChooseImportQuery query= createQuery("StaticMethodReferenceImports_bug424172", new String[] {}, new int[] {});
+
+ OrganizeImportsOperation op= createOperation(cu, order, 99, false, true, true, query);
+ op.run(null);
+
+ buf= new StringBuffer();
+ buf.append("package p;\n");
+ buf.append("\n");
+ buf.append("import java.util.function.IntPredicate;\n");
+ buf.append("\n");
+ buf.append("class UnusedStaticImport {\n");
+ buf.append(" boolean value = match(Character::isUpperCase, 'A');\n");
+ buf.append("\n");
+ buf.append(" public static boolean match(IntPredicate matcher, int codePoint) {\n");
+ buf.append(" return matcher.test(codePoint);\n");
+ buf.append(" }\n");
+ buf.append("}\n");
+ assertEqualString(cu.getSource(), buf.toString());
+ }
+
}
diff --git a/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/codemanipulation/ImportReferencesCollector.java b/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/codemanipulation/ImportReferencesCollector.java
index cc478714db..8077379283 100644
--- a/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/codemanipulation/ImportReferencesCollector.java
+++ b/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/codemanipulation/ImportReferencesCollector.java
@@ -24,6 +24,7 @@ import org.eclipse.jdt.core.dom.ASTNode;
import org.eclipse.jdt.core.dom.ClassInstanceCreation;
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jdt.core.dom.Expression;
+import org.eclipse.jdt.core.dom.ExpressionMethodReference;
import org.eclipse.jdt.core.dom.FieldAccess;
import org.eclipse.jdt.core.dom.IBinding;
import org.eclipse.jdt.core.dom.IMethodBinding;
@@ -46,10 +47,12 @@ import org.eclipse.jdt.core.dom.QualifiedType;
import org.eclipse.jdt.core.dom.SimpleName;
import org.eclipse.jdt.core.dom.SimpleType;
import org.eclipse.jdt.core.dom.SingleMemberAnnotation;
+import org.eclipse.jdt.core.dom.StructuralPropertyDescriptor;
import org.eclipse.jdt.core.dom.SuperConstructorInvocation;
import org.eclipse.jdt.core.dom.TagElement;
import org.eclipse.jdt.core.dom.ThisExpression;
import org.eclipse.jdt.core.dom.TypeDeclaration;
+import org.eclipse.jdt.core.dom.TypeMethodReference;
import org.eclipse.jdt.internal.corext.dom.GenericVisitor;
import org.eclipse.jdt.internal.corext.dom.ScopeAnalyzer;
@@ -162,6 +165,10 @@ public class ImportReferencesCollector extends GenericVisitor {
}
}
} else if (binding instanceof IMethodBinding) {
+ StructuralPropertyDescriptor locationInParent= simpleName.getLocationInParent();
+ if (locationInParent == ExpressionMethodReference.NAME_PROPERTY || locationInParent == TypeMethodReference.NAME_PROPERTY) {
+ return;
+ }
IMethodBinding methodBinding= ((IMethodBinding) binding).getMethodDeclaration();
ITypeBinding declaringClass= methodBinding.getDeclaringClass();
if (declaringClass != null && !declaringClass.isLocal()) {

Back to the top