public UnusedCodeCleanUp getCleanUp() { if (fCleanUpOptions == null) return null; return new UnusedCodeCleanUp(fCleanUpOptions); }
@Override public int computeNumberOfFixes(CompilationUnit compilationUnit) { int result= 0; IProblem[] problems= compilationUnit.getProblems(); if (isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_IMPORTS) && !isEnabled(CleanUpConstants.ORGANIZE_IMPORTS)) { for (int i=0;i<problems.length;i++) { int id= problems[i].getID(); if (id == IProblem.UnusedImport || id == IProblem.DuplicateImport || id == IProblem.ConflictingImport || id == IProblem.CannotImportPackage || id == IProblem.ImportNotFound) result++; } } if (isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_MEMBERS) && isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_METHODS)) result+= getNumberOfProblems(problems, IProblem.UnusedPrivateMethod); if (isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_MEMBERS) && isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_CONSTRUCTORS)) result+= getNumberOfProblems(problems, IProblem.UnusedPrivateConstructor); if (isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_MEMBERS) && isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_TYPES)) result+= getNumberOfProblems(problems, IProblem.UnusedPrivateType); if (isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_MEMBERS) && isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_FELDS)) result+= getNumberOfProblems(problems, IProblem.UnusedPrivateField); if (isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_LOCAL_VARIABLES)) result+= getNumberOfProblems(problems, IProblem.LocalVariableIsNeverUsed); return result; } }
@Override public CleanUpRequirements getRequirements() { boolean requireAST= requireAST(); Map<String, String> requiredOptions= requireAST ? getRequiredOptions() : null; return new CleanUpRequirements(requireAST, false, false, requiredOptions); }
private boolean requireAST() { boolean removeUnuseMembers= isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_MEMBERS); return removeUnuseMembers && isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_METHODS) || removeUnuseMembers && isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_CONSTRUCTORS) || removeUnuseMembers && isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_FELDS) || removeUnuseMembers && isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_TYPES) || isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_LOCAL_VARIABLES) || isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_IMPORTS) && !isEnabled(CleanUpConstants.ORGANIZE_IMPORTS); }
private boolean requireAST() { boolean removeUnuseMembers= isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_MEMBERS); return removeUnuseMembers && isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_METHODS) || removeUnuseMembers && isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_CONSTRUCTORS) || removeUnuseMembers && isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_FELDS) || removeUnuseMembers && isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_TYPES) || isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_LOCAL_VARIABLES) || isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_IMPORTS) && !isEnabled(CleanUpConstants.ORGANIZE_IMPORTS); }
/** * {@inheritDoc} */ public boolean requireAST(ICompilationUnit unit) throws CoreException { boolean removeUnuseMembers= isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_MEMBERS); return removeUnuseMembers && isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_METHODS) || removeUnuseMembers && isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_CONSTRUCTORS) || removeUnuseMembers && isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_FELDS) || removeUnuseMembers && isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_TYPES) || isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_LOCAL_VARIABLES) || isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_IMPORTS) && !isEnabled(CleanUpConstants.ORGANIZE_IMPORTS); }
/** * {@inheritDoc} */ public int maximalNumberOfFixes(CompilationUnit compilationUnit) { int result= 0; IProblem[] problems= compilationUnit.getProblems(); if (isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_IMPORTS) && !isEnabled(CleanUpConstants.ORGANIZE_IMPORTS)) { for (int i=0;i<problems.length;i++) { int id= problems[i].getID(); if (id == IProblem.UnusedImport || id == IProblem.DuplicateImport || id == IProblem.ConflictingImport || id == IProblem.CannotImportPackage || id == IProblem.ImportNotFound) result++; } } if (isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_MEMBERS) && isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_METHODS)) result+= getNumberOfProblems(problems, IProblem.UnusedPrivateMethod); if (isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_MEMBERS) && isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_CONSTRUCTORS)) result+= getNumberOfProblems(problems, IProblem.UnusedPrivateConstructor); if (isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_MEMBERS) && isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_TYPES)) result+= getNumberOfProblems(problems, IProblem.UnusedPrivateType); if (isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_MEMBERS) && isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_FELDS)) result+= getNumberOfProblems(problems, IProblem.UnusedPrivateField); if (isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_LOCAL_VARIABLES)) result+= getNumberOfProblems(problems, IProblem.LocalVariableIsNeverUsed); return result; } }
public UnusedCodeCleanUp getCleanUp() { if (fCleanUpOptions == null) return null; return new UnusedCodeCleanUp(fCleanUpOptions); }
@Override public CleanUpRequirements getRequirements() { boolean requireAST= requireAST(); Map<String, String> requiredOptions= requireAST ? getRequiredOptions() : null; return new CleanUpRequirements(requireAST, false, false, requiredOptions); }
@Override protected ICleanUpFix createFix(CompilationUnit compilationUnit) throws CoreException { boolean removeUnuseMembers= isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_MEMBERS); return UnusedCodeFix.createCleanUp(compilationUnit, removeUnuseMembers && isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_METHODS), removeUnuseMembers && isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_CONSTRUCTORS), removeUnuseMembers && isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_FELDS), removeUnuseMembers && isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_TYPES), isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_LOCAL_VARIABLES), isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_IMPORTS) && !isEnabled(CleanUpConstants.ORGANIZE_IMPORTS), false); }
@Override public int computeNumberOfFixes(CompilationUnit compilationUnit) { int result= 0; IProblem[] problems= compilationUnit.getProblems(); if (isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_IMPORTS) && !isEnabled(CleanUpConstants.ORGANIZE_IMPORTS)) { for (int i=0;i<problems.length;i++) { int id= problems[i].getID(); if (id == IProblem.UnusedImport || id == IProblem.DuplicateImport || id == IProblem.ConflictingImport || id == IProblem.CannotImportPackage || id == IProblem.ImportNotFound) result++; } } if (isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_MEMBERS) && isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_METHODS)) result+= getNumberOfProblems(problems, IProblem.UnusedPrivateMethod); if (isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_MEMBERS) && isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_CONSTRUCTORS)) result+= getNumberOfProblems(problems, IProblem.UnusedPrivateConstructor); if (isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_MEMBERS) && isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_TYPES)) result+= getNumberOfProblems(problems, IProblem.UnusedPrivateType); if (isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_MEMBERS) && isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_FELDS)) result+= getNumberOfProblems(problems, IProblem.UnusedPrivateField); if (isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_LOCAL_VARIABLES)) result+= getNumberOfProblems(problems, IProblem.LocalVariableIsNeverUsed); return result; } }
public UnusedCodeCleanUp getCleanUp() { return new UnusedCodeCleanUp(fCleanUpOptions); }
@Override protected ICleanUpFix createFix(CompilationUnit compilationUnit, IProblemLocation[] problems) throws CoreException { boolean removeMembers= isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_MEMBERS); return UnusedCodeFix.createCleanUp(compilationUnit, problems, removeMembers && isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_METHODS), removeMembers && isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_CONSTRUCTORS), removeMembers && isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_FELDS), removeMembers && isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_TYPES), isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_LOCAL_VARIABLES), isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_IMPORTS) && !isEnabled(CleanUpConstants.ORGANIZE_IMPORTS), false); }
protected ICleanUp[] createPreviewCleanUps(Map values) { return new ICleanUp[] { new UnusedCodeCleanUp(values), new UnnecessaryCodeCleanUp(values), new StringCleanUp(values) }; }
@Override public boolean canFix(ICompilationUnit compilationUnit, IProblemLocation problem) { if (UnusedCodeFix.isUnusedImport(problem)) return isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_IMPORTS); if (UnusedCodeFix.isUnusedMember(problem)) return isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_MEMBERS) && isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_METHODS) || isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_MEMBERS) && isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_CONSTRUCTORS) || isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_MEMBERS) && isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_TYPES) || isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_MEMBERS) && isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_FELDS) || isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_LOCAL_VARIABLES); return false; }
@Override protected AbstractCleanUp[] createPreviewCleanUps(Map<String, String> values) { return new AbstractCleanUp[] { new UnusedCodeCleanUp(values), new UnnecessaryCodeCleanUp(values), new StringCleanUp(values), new TypeParametersCleanUp(values) }; }
@Override protected ICleanUpFix createFix(CompilationUnit compilationUnit, IProblemLocation[] problems) throws CoreException { boolean removeMembers= isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_MEMBERS); return UnusedCodeFix.createCleanUp(compilationUnit, problems, removeMembers && isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_METHODS), removeMembers && isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_CONSTRUCTORS), removeMembers && isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_FELDS), removeMembers && isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_TYPES), isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_LOCAL_VARIABLES), isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_IMPORTS) && !isEnabled(CleanUpConstants.ORGANIZE_IMPORTS), false); }
public static void removeImportStatementProposals(IInvocationContext context, IProblemLocation problem, Collection proposals) throws CoreException { IFix fix= UnusedCodeFix.createRemoveUnusedImportFix(context.getASTRoot(), problem); if (fix != null) { Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_DELETE_IMPORT); Map options= new Hashtable(); options.put(CleanUpConstants.REMOVE_UNUSED_CODE_IMPORTS, CleanUpConstants.TRUE); FixCorrectionProposal proposal= new FixCorrectionProposal(fix, new UnusedCodeCleanUp(options), 6, image, context); proposals.add(proposal); } final ICompilationUnit cu= context.getCompilationUnit(); String name= CorrectionMessages.ReorgCorrectionsSubProcessor_organizeimports_description; ChangeCorrectionProposal proposal= new ChangeCorrectionProposal(name, null, 5, JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE)) { public void apply(IDocument document) { IEditorInput input= new FileEditorInput((IFile) cu.getResource()); IWorkbenchPage p= JavaPlugin.getActivePage(); if (p == null) { return; } IEditorPart part= p.findEditor(input); if (part instanceof JavaEditor) { OrganizeImportsAction action= new OrganizeImportsAction((JavaEditor) part); action.run(cu); } } }; proposals.add(proposal); }
@Override protected ICleanUpFix createFix(CompilationUnit compilationUnit) throws CoreException { boolean removeUnuseMembers= isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_MEMBERS); return UnusedCodeFix.createCleanUp(compilationUnit, removeUnuseMembers && isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_METHODS), removeUnuseMembers && isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_CONSTRUCTORS), removeUnuseMembers && isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_FELDS), removeUnuseMembers && isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_TYPES), isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_LOCAL_VARIABLES), isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_IMPORTS) && !isEnabled(CleanUpConstants.ORGANIZE_IMPORTS), false); }
public static void removeImportStatementProposals(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) { IProposableFix fix= UnusedCodeFix.createRemoveUnusedImportFix(context.getASTRoot(), problem); if (fix != null) { Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_DELETE_IMPORT); Map<String, String> options= new Hashtable<>(); options.put(CleanUpConstants.REMOVE_UNUSED_CODE_IMPORTS, CleanUpOptions.TRUE); FixCorrectionProposal proposal= new FixCorrectionProposal(fix, new UnusedCodeCleanUp(options), IProposalRelevance.REMOVE_UNUSED_IMPORT, image, context); proposals.add(proposal); } final ICompilationUnit cu= context.getCompilationUnit(); String name= CorrectionMessages.ReorgCorrectionsSubProcessor_organizeimports_description; ChangeCorrectionProposal proposal= new ChangeCorrectionProposal(name, null, IProposalRelevance.ORGANIZE_IMPORTS, JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE)) { @Override public void apply(IDocument document) { IEditorInput input= new FileEditorInput((IFile) cu.getResource()); IWorkbenchPage p= JavaPlugin.getActivePage(); if (p == null) { return; } IEditorPart part= p.findEditor(input); if (part instanceof JavaEditor) { OrganizeImportsAction action= new OrganizeImportsAction((JavaEditor) part); action.run(cu); } } }; proposals.add(proposal); }