Bug 113770 [organize import] generates syntactically incorrect static import
In very few cases, "organize import" generates an invalid static import. Note that the following compiable example must be placed in *two* separate files. When organizing imports for the first file, it generates the invalid import "import static EclipseBugOrganizeStaticImport.logger;". ----------------------------------------------- public class EclipseBugOrganizeStaticImport { private static String logger; public void startGenerator() { new MyRunnableImpl() { @Override public void run() { try { // } catch (Exception e) { logger.toString(); } } }; } } ---------------------------------------------- package de.ingo_homann.test; public class MyRunnableImpl implements Runnable { private static String logger; public void run() { // } }
org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/ImportOrganizeTest.java
buf.append("@MyAnnot1()\n");
		buf.append("@MyAnnot2(File.separatorChar)\n");
		buf.append("public @interface Test2 {\n");
		buf.append("}\n");
		assertEqualString(cu.getSource(), buf.toString());
	}
	
	private OrganizeImportsOperation createOperation(ICompilationUnit cu, String[] order, int threshold, boolean ignoreLowerCaseNames, boolean save, boolean doResolve, IChooseImportQuery chooseImportQuery) throws CoreException, BackingStoreException {
		setOrganizeImportSettings(order, threshold, threshold, cu.getJavaProject());
		return new OrganizeImportsOperation(cu, null, ignoreLowerCaseNames, save, doResolve, chooseImportQuery);
	}
	
	private  void setOrganizeImportSettings(String[] order, int threshold, int staticThreshold, IJavaProject project) throws BackingStoreException {
		IEclipsePreferences scope= new ProjectScope(project.getProject()).getNode(JavaUI.ID_PLUGIN);
		if (order == null) {
			scope.remove(PreferenceConstants.ORGIMPORTS_IMPORTORDER);
			scope.remove(PreferenceConstants.ORGIMPORTS_ONDEMANDTHRESHOLD);
		} else {
			StringBuffer buf= new StringBuffer();
			for (int i= 0; i < order.length; i++) {
				buf.append(order[i]);
				buf.append(';');
			}
			scope.put(PreferenceConstants.ORGIMPORTS_IMPORTORDER, buf.toString());
			scope.put(PreferenceConstants.ORGIMPORTS_ONDEMANDTHRESHOLD, String.valueOf(threshold));
		}
	}
	
}