|
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 |
} |