Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 424172 | Differences between
and this patch

Collapse All | Expand All

(-)a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/ImportOrganizeTest18.java (-1 / +40 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2013 IBM Corporation and others.
2
 * Copyright (c) 2000, 2014 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 297-300 Link Here
297
		assertEqualString(cu.getSource(), buf.toString());
297
		assertEqualString(cu.getSource(), buf.toString());
298
	}
298
	}
299
299
300
	public void testStaticMethodReferenceImports_bug424172() throws Exception {
301
		IPackageFragmentRoot sourceFolder= JavaProjectHelper.addSourceContainer(fJProject1, "src");
302
303
		IPackageFragment pack0= sourceFolder.createPackageFragment("p", false, null);
304
		StringBuffer buf= new StringBuffer();
305
		buf.append("package p;\n");
306
		buf.append("\n");
307
		buf.append("import java.util.function.IntPredicate;\n");
308
		buf.append("\n");
309
		buf.append("class UnusedStaticImport {\n");
310
		buf.append("    boolean value = match(Character::isUpperCase, 'A');\n");
311
		buf.append("\n");
312
		buf.append("    public static boolean match(IntPredicate matcher, int codePoint) {\n");
313
		buf.append("        return matcher.test(codePoint);\n");
314
		buf.append("    }\n");
315
		buf.append("}\n");
316
		ICompilationUnit cu= pack0.createCompilationUnit("UnusedStaticImport.java", buf.toString(), false, null);
317
318
		String[] order= new String[] {};
319
		IChooseImportQuery query= createQuery("StaticMethodReferenceImports_bug424172", new String[] {}, new int[] {});
320
321
		OrganizeImportsOperation op= createOperation(cu, order, 99, false, true, true, query);
322
		op.run(null);
323
324
		buf= new StringBuffer();
325
		buf.append("package p;\n");
326
		buf.append("\n");
327
		buf.append("import java.util.function.IntPredicate;\n");
328
		buf.append("\n");
329
		buf.append("class UnusedStaticImport {\n");
330
		buf.append("    boolean value = match(Character::isUpperCase, 'A');\n");
331
		buf.append("\n");
332
		buf.append("    public static boolean match(IntPredicate matcher, int codePoint) {\n");
333
		buf.append("        return matcher.test(codePoint);\n");
334
		buf.append("    }\n");
335
		buf.append("}\n");
336
		assertEqualString(cu.getSource(), buf.toString());
337
	}
338
300
}
339
}
(-)a/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/codemanipulation/ImportReferencesCollector.java (+7 lines)
Lines 24-29 Link Here
24
import org.eclipse.jdt.core.dom.ClassInstanceCreation;
24
import org.eclipse.jdt.core.dom.ClassInstanceCreation;
25
import org.eclipse.jdt.core.dom.CompilationUnit;
25
import org.eclipse.jdt.core.dom.CompilationUnit;
26
import org.eclipse.jdt.core.dom.Expression;
26
import org.eclipse.jdt.core.dom.Expression;
27
import org.eclipse.jdt.core.dom.ExpressionMethodReference;
27
import org.eclipse.jdt.core.dom.FieldAccess;
28
import org.eclipse.jdt.core.dom.FieldAccess;
28
import org.eclipse.jdt.core.dom.IBinding;
29
import org.eclipse.jdt.core.dom.IBinding;
29
import org.eclipse.jdt.core.dom.IMethodBinding;
30
import org.eclipse.jdt.core.dom.IMethodBinding;
Lines 46-55 Link Here
46
import org.eclipse.jdt.core.dom.SimpleName;
47
import org.eclipse.jdt.core.dom.SimpleName;
47
import org.eclipse.jdt.core.dom.SimpleType;
48
import org.eclipse.jdt.core.dom.SimpleType;
48
import org.eclipse.jdt.core.dom.SingleMemberAnnotation;
49
import org.eclipse.jdt.core.dom.SingleMemberAnnotation;
50
import org.eclipse.jdt.core.dom.StructuralPropertyDescriptor;
49
import org.eclipse.jdt.core.dom.SuperConstructorInvocation;
51
import org.eclipse.jdt.core.dom.SuperConstructorInvocation;
50
import org.eclipse.jdt.core.dom.TagElement;
52
import org.eclipse.jdt.core.dom.TagElement;
51
import org.eclipse.jdt.core.dom.ThisExpression;
53
import org.eclipse.jdt.core.dom.ThisExpression;
52
import org.eclipse.jdt.core.dom.TypeDeclaration;
54
import org.eclipse.jdt.core.dom.TypeDeclaration;
55
import org.eclipse.jdt.core.dom.TypeMethodReference;
53
56
54
import org.eclipse.jdt.internal.corext.dom.GenericVisitor;
57
import org.eclipse.jdt.internal.corext.dom.GenericVisitor;
55
import org.eclipse.jdt.internal.corext.dom.ScopeAnalyzer;
58
import org.eclipse.jdt.internal.corext.dom.ScopeAnalyzer;
Lines 162-167 Link Here
162
				}
165
				}
163
			}
166
			}
164
		} else if (binding instanceof IMethodBinding) {
167
		} else if (binding instanceof IMethodBinding) {
168
			StructuralPropertyDescriptor locationInParent= simpleName.getLocationInParent();
169
			if (locationInParent == ExpressionMethodReference.NAME_PROPERTY || locationInParent == TypeMethodReference.NAME_PROPERTY) {
170
				return;
171
			}
165
			IMethodBinding methodBinding= ((IMethodBinding) binding).getMethodDeclaration();
172
			IMethodBinding methodBinding= ((IMethodBinding) binding).getMethodDeclaration();
166
			ITypeBinding declaringClass= methodBinding.getDeclaringClass();
173
			ITypeBinding declaringClass= methodBinding.getDeclaringClass();
167
			if (declaringClass != null && !declaringClass.isLocal()) {
174
			if (declaringClass != null && !declaringClass.isLocal()) {

Return to bug 424172