/** * {@inheritDoc} */ public boolean requireAST(ICompilationUnit unit) throws CoreException { return isEnabled(CleanUpConstants.CONTROL_STATMENTS_CONVERT_FOR_LOOP_TO_ENHANCED); }
protected ICleanUp[] createPreviewCleanUps(Map values) { return new ICleanUp[] { new ControlStatementsCleanUp(values), new ConvertLoopCleanUp(values), new ExpressionsCleanUp(values), new VariableDeclarationCleanUp(values) }; }
private static boolean getConvertIterableLoopProposal(IInvocationContext context, ASTNode node, Collection resultingCollections) throws CoreException { ForStatement forStatement= getEnclosingForStatementHeader(node); if (forStatement == null) return false; if (resultingCollections == null) return true; IFix fix= ConvertLoopFix.createConvertIterableLoopToEnhancedFix(context.getASTRoot(), forStatement); if (fix == null) return false; Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE); Map options= new HashMap(); options.put(CleanUpConstants.CONTROL_STATMENTS_CONVERT_FOR_LOOP_TO_ENHANCED, CleanUpConstants.TRUE); ICleanUp cleanUp= new ConvertLoopCleanUp(options); FixCorrectionProposal proposal= new FixCorrectionProposal(fix, cleanUp, 1, image, context); proposal.setCommandId(CONVERT_FOR_LOOP_ID); resultingCollections.add(proposal); return true; }
/** * {@inheritDoc} */ public IFix createFix(CompilationUnit compilationUnit) throws CoreException { if (compilationUnit == null) return null; boolean convertForLoops= isEnabled(CleanUpConstants.CONTROL_STATMENTS_CONVERT_FOR_LOOP_TO_ENHANCED); return ConvertLoopFix.createCleanUp(compilationUnit, convertForLoops, convertForLoops, isEnabled(CleanUpConstants.VARIABLE_DECLARATIONS_USE_FINAL) && isEnabled(CleanUpConstants.VARIABLE_DECLARATIONS_USE_FINAL_LOCAL_VARIABLES)); }
private static boolean getConvertIterableLoopProposal(IInvocationContext context, ASTNode node, Collection<ICommandAccess> resultingCollections) { ForStatement forStatement= getEnclosingForStatementHeader(node); if (forStatement == null) return false; if (resultingCollections == null) return true; IProposableFix fix= ConvertLoopFix.createConvertIterableLoopToEnhancedFix(context.getASTRoot(), forStatement); if (fix == null) return false; Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE); Map<String, String> options= new HashMap<>(); options.put(CleanUpConstants.CONTROL_STATMENTS_CONVERT_FOR_LOOP_TO_ENHANCED, CleanUpOptions.TRUE); ICleanUp cleanUp= new ConvertLoopCleanUp(options); FixCorrectionProposal proposal= new FixCorrectionProposal(fix, cleanUp, IProposalRelevance.CONVERT_ITERABLE_LOOP_TO_ENHANCED, image, context); proposal.setCommandId(CONVERT_FOR_LOOP_ID); resultingCollections.add(proposal); return true; }
@Override public String[] getStepDescriptions() { List<String> result= new ArrayList<>(); if (isEnabled(CleanUpConstants.CONTROL_STATMENTS_CONVERT_FOR_LOOP_TO_ENHANCED)) result.add(MultiFixMessages.Java50CleanUp_ConvertToEnhancedForLoop_description); return result.toArray(new String[result.size()]); }
private static boolean getConvertForLoopProposal(IInvocationContext context, ASTNode node, Collection resultingCollections) throws CoreException { ForStatement forStatement= getEnclosingForStatementHeader(node); if (forStatement == null) return false; if (resultingCollections == null) return true; IFix fix= ConvertLoopFix.createConvertForLoopToEnhancedFix(context.getASTRoot(), forStatement); if (fix == null) return false; Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE); Map options= new HashMap(); options.put(CleanUpConstants.CONTROL_STATMENTS_CONVERT_FOR_LOOP_TO_ENHANCED, CleanUpConstants.TRUE); ICleanUp cleanUp= new ConvertLoopCleanUp(options); FixCorrectionProposal proposal= new FixCorrectionProposal(fix, cleanUp, 1, image, context); proposal.setCommandId(CONVERT_FOR_LOOP_ID); resultingCollections.add(proposal); return true; }
@Override public String[] getStepDescriptions() { List<String> result= new ArrayList<>(); if (isEnabled(CleanUpConstants.CONTROL_STATMENTS_CONVERT_FOR_LOOP_TO_ENHANCED)) result.add(MultiFixMessages.Java50CleanUp_ConvertToEnhancedForLoop_description); return result.toArray(new String[result.size()]); }
private static boolean getConvertForLoopProposal(IInvocationContext context, ASTNode node, Collection<ICommandAccess> resultingCollections) { ForStatement forStatement= getEnclosingForStatementHeader(node); if (forStatement == null) return false; if (resultingCollections == null) return true; IProposableFix fix= ConvertLoopFix.createConvertForLoopToEnhancedFix(context.getASTRoot(), forStatement); if (fix == null) return false; Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE); Map<String, String> options= new HashMap<>(); options.put(CleanUpConstants.CONTROL_STATMENTS_CONVERT_FOR_LOOP_TO_ENHANCED, CleanUpOptions.TRUE); ICleanUp cleanUp= new ConvertLoopCleanUp(options); FixCorrectionProposal proposal= new FixCorrectionProposal(fix, cleanUp, IProposalRelevance.CONVERT_FOR_LOOP_TO_ENHANCED, image, context); proposal.setCommandId(CONVERT_FOR_LOOP_ID); resultingCollections.add(proposal); return true; }
/** * {@inheritDoc} */ public String[] getDescriptions() { List result= new ArrayList(); if (isEnabled(CleanUpConstants.CONTROL_STATMENTS_CONVERT_FOR_LOOP_TO_ENHANCED)) result.add(MultiFixMessages.Java50CleanUp_ConvertToEnhancedForLoop_description); return (String[])result.toArray(new String[result.size()]); }
@Override protected AbstractCleanUp[] createPreviewCleanUps(Map<String, String> values) { return new AbstractCleanUp[] { new ControlStatementsCleanUp(values), new ConvertLoopCleanUp(values), new ExpressionsCleanUp(values), new VariableDeclarationCleanUp(values), new LambdaExpressionsCleanUp(values) }; }
@Override public ICleanUpFix createFix(CleanUpContext context) throws CoreException { CompilationUnit compilationUnit= context.getAST(); if (compilationUnit == null) return null; boolean convertForLoops= isEnabled(CleanUpConstants.CONTROL_STATMENTS_CONVERT_FOR_LOOP_TO_ENHANCED); return ConvertLoopFix.createCleanUp(compilationUnit, convertForLoops, convertForLoops, isEnabled(CleanUpConstants.VARIABLE_DECLARATIONS_USE_FINAL) && isEnabled(CleanUpConstants.VARIABLE_DECLARATIONS_USE_FINAL_LOCAL_VARIABLES)); }
private static boolean getConvertForLoopProposal(IInvocationContext context, ASTNode node, Collection<ICommandAccess> resultingCollections) { ForStatement forStatement= getEnclosingForStatementHeader(node); if (forStatement == null) return false; if (resultingCollections == null) return true; IProposableFix fix= ConvertLoopFix.createConvertForLoopToEnhancedFix(context.getASTRoot(), forStatement); if (fix == null) return false; Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE); Map<String, String> options= new HashMap<>(); options.put(CleanUpConstants.CONTROL_STATMENTS_CONVERT_FOR_LOOP_TO_ENHANCED, CleanUpOptions.TRUE); ICleanUp cleanUp= new ConvertLoopCleanUp(options); FixCorrectionProposal proposal= new FixCorrectionProposal(fix, cleanUp, IProposalRelevance.CONVERT_FOR_LOOP_TO_ENHANCED, image, context); proposal.setCommandId(CONVERT_FOR_LOOP_ID); resultingCollections.add(proposal); return true; }
@Override public ICleanUpFix createFix(CleanUpContext context) throws CoreException { CompilationUnit compilationUnit= context.getAST(); if (compilationUnit == null) return null; boolean convertForLoops= isEnabled(CleanUpConstants.CONTROL_STATMENTS_CONVERT_FOR_LOOP_TO_ENHANCED); return ConvertLoopFix.createCleanUp(compilationUnit, convertForLoops, convertForLoops, isEnabled(CleanUpConstants.VARIABLE_DECLARATIONS_USE_FINAL) && isEnabled(CleanUpConstants.VARIABLE_DECLARATIONS_USE_FINAL_LOCAL_VARIABLES)); }
private static boolean getConvertIterableLoopProposal(IInvocationContext context, ASTNode node, Collection<ICommandAccess> resultingCollections) { ForStatement forStatement= getEnclosingForStatementHeader(node); if (forStatement == null) return false; if (resultingCollections == null) return true; IProposableFix fix= ConvertLoopFix.createConvertIterableLoopToEnhancedFix(context.getASTRoot(), forStatement); if (fix == null) return false; Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE); Map<String, String> options= new HashMap<>(); options.put(CleanUpConstants.CONTROL_STATMENTS_CONVERT_FOR_LOOP_TO_ENHANCED, CleanUpOptions.TRUE); ICleanUp cleanUp= new ConvertLoopCleanUp(options); FixCorrectionProposal proposal= new FixCorrectionProposal(fix, cleanUp, IProposalRelevance.CONVERT_ITERABLE_LOOP_TO_ENHANCED, image, context); proposal.setCommandId(CONVERT_FOR_LOOP_ID); resultingCollections.add(proposal); return true; }
@Override public CleanUpRequirements getRequirements() { return new CleanUpRequirements(isEnabled(CleanUpConstants.CONTROL_STATMENTS_CONVERT_FOR_LOOP_TO_ENHANCED), false, false, null); }
@Override protected AbstractCleanUp[] createPreviewCleanUps(Map<String, String> values) { return new AbstractCleanUp[] { new ControlStatementsCleanUp(values), new ConvertLoopCleanUp(values), new ExpressionsCleanUp(values), new VariableDeclarationCleanUp(values), new LambdaExpressionsCleanUp(values) }; }
@Override public String getPreview() { StringBuffer buf= new StringBuffer(); if (isEnabled(CleanUpConstants.CONTROL_STATMENTS_CONVERT_FOR_LOOP_TO_ENHANCED)) { buf.append("for (int element : ids) {\n"); //$NON-NLS-1$ buf.append(" double value= element / 2; \n"); //$NON-NLS-1$ buf.append(" System.out.println(value);\n"); //$NON-NLS-1$ buf.append("}\n"); //$NON-NLS-1$ } else { buf.append("for (int i = 0; i < ids.length; i++) {\n"); //$NON-NLS-1$ buf.append(" double value= ids[i] / 2; \n"); //$NON-NLS-1$ buf.append(" System.out.println(value);\n"); //$NON-NLS-1$ buf.append("}\n"); //$NON-NLS-1$ } return buf.toString(); } }
public static ICleanUp[] createCleanUps() { return new ICleanUp[] { new CodeStyleCleanUp(), new ControlStatementsCleanUp(), new ConvertLoopCleanUp(), new VariableDeclarationCleanUp(), new ExpressionsCleanUp(), new UnusedCodeCleanUp(), new Java50CleanUp(), new PotentialProgrammingProblemsCleanUp(), new UnnecessaryCodeCleanUp(), new StringCleanUp(), new SortMembersCleanUp(), new ImportsCleanUp(), new CodeFormatCleanUp(), new CommentFormatCleanUp()}; }
@Override public CleanUpRequirements getRequirements() { return new CleanUpRequirements(isEnabled(CleanUpConstants.CONTROL_STATMENTS_CONVERT_FOR_LOOP_TO_ENHANCED), false, false, null); }