Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 424172

Summary: [1.8][organize imports] Unused static import for Character::isUpperCase added
Product: [Eclipse Project] JDT Reporter: Timo Kinnunen <timo.kinnunen>
Component: UIAssignee: Noopur Gupta <noopur_gupta>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: jarthana, markus.kell.r, noopur_gupta
Version: 4.4   
Target Milestone: BETA J8   
Hardware: All   
OS: All   
Whiteboard:
Attachments:
Description Flags
Patch
none
Patch + Test
none
Patch + Test none

Description Timo Kinnunen CLA 2013-12-16 14:30:07 EST
This program:

import java.util.function.IntPredicate;
class UnusedStaticImport {
  boolean value = match(Character::isUpperCase, 'A');
  public static boolean match(IntPredicate matcher, int codePoint) { return matcher.test(codePoint); }
}

Organize imports adds an unused line, leading to a warning:
import static java.lang.Character.isUpperCase;

This happens when organize imports is executed from save actions, clean up or organize imports menu item. Tested with Eclipse R4.3.1+BETA_JAVA8 binaries updated yesterday.
Comment 1 Noopur Gupta CLA 2013-12-17 03:59:17 EST
Created attachment 238392 [details]
Patch
Comment 2 Noopur Gupta CLA 2013-12-17 04:01:58 EST
Comment on attachment 238392 [details]
Patch

Attached a patch to prevent the addition of static import in case of method references. Markus, please review.
Comment 3 Noopur Gupta CLA 2013-12-17 05:38:01 EST
Created attachment 238395 [details]
Patch + Test

Updated patch with test
Comment 4 Noopur Gupta CLA 2014-01-10 04:10:24 EST
Created attachment 238849 [details]
Patch + Test

Updated patch based on mmathew/BETA_JAVA8 branch.
Comment 5 Markus Keller CLA 2014-02-26 05:16:41 EST
Released test with http://git.eclipse.org/c/jdt/eclipse.jdt.ui.git/commit/?id=5e66e8472e34be92037ee14a97b8af1a4339af50 and a better fix with http://git.eclipse.org/c/jdt/eclipse.jdt.ui.git/commit/?id=57f21feee55057978300e56a0cc1fea109c4b518

We already have that nice ASTVisitor, so we better add the missing visit(*) methods rather than adding this logic after the binding resolution already happened.
Comment 6 Jay Arthanareeswaran CLA 2014-03-07 02:20:56 EST
Verified as working for Eclipse + Java 8 RC2 using Kepler SR2 +   
Eclipse Java Development Tools Patch for Java 8 Support (BETA)
1.0.0.v20140306-1935