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/ImportOrganizeTest.java (-3 / +7 lines)
Lines 5-10 Link Here
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
7
 *
8
 * This is an implementation of an early-draft specification developed under the Java
9
 * Community Process (JCP) and is made available for testing and evaluation purposes
10
 * only. The code is not compatible with any specification of the JCP.
11
 *
8
 * Contributors:
12
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
13
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
14
 *******************************************************************************/
Lines 76-82 Link Here
76
		JavaProjectHelper.clear(fJProject1, ProjectTestSetup.getDefaultClasspath());
80
		JavaProjectHelper.clear(fJProject1, ProjectTestSetup.getDefaultClasspath());
77
	}
81
	}
78
82
79
	private IChooseImportQuery createQuery(final String name, final String[] choices, final int[] nEntries) {
83
	static IChooseImportQuery createQuery(final String name, final String[] choices, final int[] nEntries) {
80
		return new IChooseImportQuery() {
84
		return new IChooseImportQuery() {
81
			public TypeNameMatch[] chooseImports(TypeNameMatch[][] openChoices, ISourceRange[] ranges) {
85
			public TypeNameMatch[] chooseImports(TypeNameMatch[][] openChoices, ISourceRange[] ranges) {
82
				assertTrue(name + "-query-nchoices1", choices.length == openChoices.length);
86
				assertTrue(name + "-query-nchoices1", choices.length == openChoices.length);
Lines 3209-3220 Link Here
3209
	}
3213
	}
3210
3214
3211
3215
3212
	private OrganizeImportsOperation createOperation(ICompilationUnit cu, String[] order, int threshold, boolean ignoreLowerCaseNames, boolean save, boolean allowSyntaxErrors, IChooseImportQuery chooseImportQuery) {
3216
	static OrganizeImportsOperation createOperation(ICompilationUnit cu, String[] order, int threshold, boolean ignoreLowerCaseNames, boolean save, boolean allowSyntaxErrors, IChooseImportQuery chooseImportQuery) {
3213
		setOrganizeImportSettings(order, threshold, threshold, cu.getJavaProject());
3217
		setOrganizeImportSettings(order, threshold, threshold, cu.getJavaProject());
3214
		return new OrganizeImportsOperation(cu, null, ignoreLowerCaseNames, save, allowSyntaxErrors, chooseImportQuery);
3218
		return new OrganizeImportsOperation(cu, null, ignoreLowerCaseNames, save, allowSyntaxErrors, chooseImportQuery);
3215
	}
3219
	}
3216
3220
3217
	private void setOrganizeImportSettings(String[] order, int threshold, int staticThreshold, IJavaProject project) {
3221
	static void setOrganizeImportSettings(String[] order, int threshold, int staticThreshold, IJavaProject project) {
3218
		IEclipsePreferences scope= new ProjectScope(project.getProject()).getNode(JavaUI.ID_PLUGIN);
3222
		IEclipsePreferences scope= new ProjectScope(project.getProject()).getNode(JavaUI.ID_PLUGIN);
3219
		if (order == null) {
3223
		if (order == null) {
3220
			scope.remove(PreferenceConstants.ORGIMPORTS_IMPORTORDER);
3224
			scope.remove(PreferenceConstants.ORGIMPORTS_IMPORTORDER);
(-)a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/ImportOrganizeTest18.java (+108 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2013 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * This is an implementation of an early-draft specification developed under the Java
9
 * Community Process (JCP) and is made available for testing and evaluation purposes
10
 * only. The code is not compatible with any specification of the JCP.
11
 *
12
 * Contributors:
13
 *     IBM Corporation - initial API and implementation
14
 *******************************************************************************/
15
package org.eclipse.jdt.ui.tests.core;
16
17
import java.util.Hashtable;
18
19
import junit.framework.Test;
20
import junit.framework.TestSuite;
21
22
import org.eclipse.jdt.testplugin.JavaProjectHelper;
23
import org.eclipse.jdt.testplugin.TestOptions;
24
25
import org.eclipse.jdt.core.ICompilationUnit;
26
import org.eclipse.jdt.core.IJavaProject;
27
import org.eclipse.jdt.core.IPackageFragment;
28
import org.eclipse.jdt.core.IPackageFragmentRoot;
29
import org.eclipse.jdt.core.JavaCore;
30
import org.eclipse.jdt.core.formatter.DefaultCodeFormatterConstants;
31
32
import org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation;
33
import org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation.IChooseImportQuery;
34
35
36
public class ImportOrganizeTest18 extends CoreTests {
37
38
	private static final Class THIS= ImportOrganizeTest18.class;
39
40
	private IJavaProject fJProject1;
41
42
	public ImportOrganizeTest18(String name) {
43
		super(name);
44
	}
45
46
	public static Test setUpTest(Test test) {
47
		return new Java18ProjectTestSetup(test);
48
	}
49
50
	public static Test suite() {
51
		return setUpTest(new TestSuite(THIS));
52
	}
53
54
55
	protected void setUp() throws Exception {
56
		fJProject1= Java18ProjectTestSetup.getProject();
57
58
		Hashtable options= TestOptions.getDefaultOptions();
59
		options.put(DefaultCodeFormatterConstants.FORMATTER_NUMBER_OF_EMPTY_LINES_TO_PRESERVE, String.valueOf(99));
60
		JavaCore.setOptions(options);
61
	}
62
63
64
	protected void tearDown() throws Exception {
65
		ImportOrganizeTest.setOrganizeImportSettings(null, 99, 99, fJProject1);
66
		JavaProjectHelper.clear(fJProject1, Java18ProjectTestSetup.getDefaultClasspath());
67
	}
68
69
	public void testStaticMethodReferenceImports_bug424172() throws Exception {
70
		IPackageFragmentRoot sourceFolder= JavaProjectHelper.addSourceContainer(fJProject1, "src");
71
72
		IPackageFragment pack0= sourceFolder.createPackageFragment("p", false, null);
73
		StringBuffer buf= new StringBuffer();
74
		buf.append("package p;\n");
75
		buf.append("\n");
76
		buf.append("import java.util.function.IntPredicate;\n");
77
		buf.append("\n");
78
		buf.append("class UnusedStaticImport {\n");
79
		buf.append("    boolean value = match(Character::isUpperCase, 'A');\n");
80
		buf.append("\n");
81
		buf.append("    public static boolean match(IntPredicate matcher, int codePoint) {\n");
82
		buf.append("        return matcher.test(codePoint);\n");
83
		buf.append("    }\n");
84
		buf.append("}\n");
85
		ICompilationUnit cu= pack0.createCompilationUnit("UnusedStaticImport.java", buf.toString(), false, null);
86
87
		String[] order= new String[] {};
88
		IChooseImportQuery query= ImportOrganizeTest.createQuery("StaticMethodReferenceImports_bug424172", new String[] {}, new int[] {});
89
90
		OrganizeImportsOperation op= ImportOrganizeTest.createOperation(cu, order, 99, false, true, true, query);
91
		op.run(null);
92
93
		buf= new StringBuffer();
94
		buf.append("package p;\n");
95
		buf.append("\n");
96
		buf.append("import java.util.function.IntPredicate;\n");
97
		buf.append("\n");
98
		buf.append("class UnusedStaticImport {\n");
99
		buf.append("    boolean value = match(Character::isUpperCase, 'A');\n");
100
		buf.append("\n");
101
		buf.append("    public static boolean match(IntPredicate matcher, int codePoint) {\n");
102
		buf.append("        return matcher.test(codePoint);\n");
103
		buf.append("    }\n");
104
		buf.append("}\n");
105
		assertEqualString(cu.getSource(), buf.toString());
106
	}
107
108
}
(-)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