Bug 114369 Remove unused local and field too dangerous for multi quick fix
Version: 3.1.0 Build id: I20051025-0800 The two clean ups: Remove unused local variable and assignments without possible side effects and Remove unused private field and assignments without possible side effects are too dangerous to apply in a batch mode, at least without warning the user. Reason: private int i= methodWithSideEffect(); foo () { int j= methodWithSideEffect(); } in both cases i and j are removed as well as the two calls to methodWithSideEffect which will change the semantic of the program. Possible solutions: 1. Not having these two multi quick fixes 2. Warn the user 3. Only remove variables if this does not remove any method call 4. ?
org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/fix/UnusedCodeMultiFix.java
import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.compiler.IProblem;
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jdt.core.dom.IBinding;
import org.eclipse.jdt.core.dom.ImportDeclaration;
import org.eclipse.jdt.core.dom.SimpleName;
import org.eclipse.jdt.internal.corext.fix.IFix;
import org.eclipse.jdt.internal.corext.fix.UnusedCodeFix;
import org.eclipse.jdt.ui.text.java.IProblemLocation;
/**
 * Create fixes which can remove unused code
 * @see org.eclipse.jdt.internal.corext.fix.UnusedCodeFix
 *
 */
public class UnusedCodeMultiFix extends AbstractMultiFix {
	private static final String REMOVE_UNUSED_PRIVATE_CONSTRUCTORS_SETTINGS_ID= "RemoveUnusedPrivateConstructors"; 
	private static final String REMOVE_UNUSED_IMPORTS_SETTINGS_ID= "RemoveUnusedImports"; 
	private static final String REMOVE_UNUSED_PRIVATE_METHODES_SETTINGS_ID= "RemoveUnusedPrivateMethods"; 
	private static final String REMOVE_UNUSED_PRIVATE_FIELDS_SETTINGS_ID= "RemoveUnusedPrivateFields"; 
	private static final String REMOVE_UNUSED_PRIVATE_TYPE_SETTINGS_ID= "RemoveUnusedPrivateType"; 
	private static final String REMOVE_UNUSED_LOCAL_VARIABLES_SETTINGS_ID= "RemoveUnusedLocals"; 
	
	private boolean fRemoveUnusedImports;
	private boolean fRemoveUnusedPrivateMethods;
	private boolean fRemoveUnusedPrivateConstructors;
	private boolean fRemoveUnusedPrivateFields;
	private boolean fRemoveUnusedPrivateTypes;
	private boolean fRemoveUnusedLocalVariables;