/** * {@inheritDoc} */ public IFix createFix(CompilationUnit compilationUnit, IProblemLocation[] problems) throws CoreException { return createFix(compilationUnit); }
private static boolean getAddParanoidalParenthesesProposals(IInvocationContext context, ArrayList<ASTNode> coveredNodes, Collection<ICommandAccess> resultingCollections) { IProposableFix fix= ExpressionsFix.createAddParanoidalParenthesisFix(context.getASTRoot(), coveredNodes.toArray(new ASTNode[coveredNodes.size()])); if (fix == null) return false; if (resultingCollections == null) return true; // add correction proposal Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CAST); Map<String, String> options= new Hashtable<>(); options.put(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES, CleanUpOptions.TRUE); options.put(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES_ALWAYS, CleanUpOptions.TRUE); FixCorrectionProposal proposal= new FixCorrectionProposal(fix, new ExpressionsCleanUp(options), IProposalRelevance.ADD_PARANOIDAL_PARENTHESES, image, context); resultingCollections.add(proposal); return true; }
@Override public CleanUpRequirements getRequirements() { return new CleanUpRequirements(requireAST(), false, false, null); }
private static boolean getAddParanoidalParenthesesProposals(IInvocationContext context, ArrayList<ASTNode> coveredNodes, Collection<ICommandAccess> resultingCollections) { IProposableFix fix= ExpressionsFix.createAddParanoidalParenthesisFix(context.getASTRoot(), coveredNodes.toArray(new ASTNode[coveredNodes.size()])); if (fix == null) return false; if (resultingCollections == null) return true; // add correction proposal Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CAST); Map<String, String> options= new Hashtable<>(); options.put(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES, CleanUpOptions.TRUE); options.put(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES_ALWAYS, CleanUpOptions.TRUE); FixCorrectionProposal proposal= new FixCorrectionProposal(fix, new ExpressionsCleanUp(options), IProposalRelevance.ADD_PARANOIDAL_PARENTHESES, image, context); resultingCollections.add(proposal); return true; }
@Override public CleanUpRequirements getRequirements() { return new CleanUpRequirements(requireAST(), false, false, null); }
/** * {@inheritDoc} */ public boolean requireAST(ICompilationUnit unit) throws CoreException { boolean usePrentheses= isEnabled(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES); if (!usePrentheses) return false; return isEnabled(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES_ALWAYS) || isEnabled(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES_NEVER); }
private static boolean getAddParanoidalParenthesisProposals(IInvocationContext context, ASTNode covering, ArrayList coveredNodes, Collection resultingCollections) throws CoreException { IFix fix= ExpressionsFix.createAddParanoidalParenthesisFix(context.getASTRoot(), (ASTNode[])coveredNodes.toArray(new ASTNode[coveredNodes.size()])); if (fix == null) return false; if (resultingCollections == null) return true; // add correction proposal Image image = JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE); Map options= new Hashtable(); options.put(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES, CleanUpConstants.TRUE); options.put(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES_ALWAYS, CleanUpConstants.TRUE); FixCorrectionProposal proposal= new FixCorrectionProposal(fix, new ExpressionsCleanUp(options), 1, image, context); resultingCollections.add(proposal); return true; }
private static boolean getRemoveExtraParenthesesProposals(IInvocationContext context, ASTNode covering, ArrayList<ASTNode> coveredNodes, Collection<ICommandAccess> resultingCollections) { ArrayList<ASTNode> nodes; if (context.getSelectionLength() == 0 && covering instanceof ParenthesizedExpression) { nodes= new ArrayList<>(); nodes.add(covering); } else { nodes= coveredNodes; } if (nodes.isEmpty()) return false; IProposableFix fix= ExpressionsFix.createRemoveUnnecessaryParenthesisFix(context.getASTRoot(), nodes.toArray(new ASTNode[nodes.size()])); if (fix == null) return false; if (resultingCollections == null) return true; Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_REMOVE); Map<String, String> options= new Hashtable<>(); options.put(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES, CleanUpOptions.TRUE); options.put(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES_NEVER, CleanUpOptions.TRUE); FixCorrectionProposal proposal= new FixCorrectionProposal(fix, new ExpressionsCleanUp(options), IProposalRelevance.REMOVE_EXTRA_PARENTHESES, image, context); resultingCollections.add(proposal); return true; }
public IFix createFix(CompilationUnit compilationUnit) throws CoreException { if (compilationUnit == null) return null; boolean usePrentheses= isEnabled(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES); if (!usePrentheses) return null; return ExpressionsFix.createCleanUp(compilationUnit, isEnabled(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES_ALWAYS), isEnabled(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES_NEVER)); }
private static boolean getRemoveExtraParenthesesProposals(IInvocationContext context, ASTNode covering, ArrayList<ASTNode> coveredNodes, Collection<ICommandAccess> resultingCollections) { ArrayList<ASTNode> nodes; if (context.getSelectionLength() == 0 && covering instanceof ParenthesizedExpression) { nodes= new ArrayList<>(); nodes.add(covering); } else { nodes= coveredNodes; } if (nodes.isEmpty()) return false; IProposableFix fix= ExpressionsFix.createRemoveUnnecessaryParenthesisFix(context.getASTRoot(), nodes.toArray(new ASTNode[nodes.size()])); if (fix == null) return false; if (resultingCollections == null) return true; Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_REMOVE); Map<String, String> options= new Hashtable<>(); options.put(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES, CleanUpOptions.TRUE); options.put(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES_NEVER, CleanUpOptions.TRUE); FixCorrectionProposal proposal= new FixCorrectionProposal(fix, new ExpressionsCleanUp(options), IProposalRelevance.REMOVE_EXTRA_PARENTHESES, image, context); resultingCollections.add(proposal); return true; }
@Override public String getPreview() { StringBuffer buf= new StringBuffer(); if (isEnabled(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES) && isEnabled(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES_ALWAYS)) { buf.append("boolean b= (((i > 0) && (i < 10)) || (i == 50));\n"); //$NON-NLS-1$ } else if (isEnabled(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES) && isEnabled(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES_NEVER)) { buf.append("boolean b= i > 0 && i < 10 || i == 50;\n"); //$NON-NLS-1$ } else { buf.append("boolean b= (i > 0 && i < 10 || i == 50);\n"); //$NON-NLS-1$ } return buf.toString(); }
private static boolean getRemoveExtraParenthesisProposals(IInvocationContext context, ASTNode covering, ArrayList coveredNodes, Collection resultingCollections) { ArrayList nodes; if ((context.getSelectionLength() == 0) && (covering instanceof ParenthesizedExpression)) { nodes = new ArrayList(); nodes.add(covering); } else { nodes= coveredNodes; } if (nodes.isEmpty()) return false; IFix fix= ExpressionsFix.createRemoveUnnecessaryParenthesisFix(context.getASTRoot(), (ASTNode[])nodes.toArray(new ASTNode[nodes.size()])); if (fix == null) return false; if (resultingCollections == null) return true; Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_REMOVE); Map options= new Hashtable(); options.put(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES, CleanUpConstants.TRUE); options.put(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES_NEVER, CleanUpConstants.TRUE); FixCorrectionProposal proposal= new FixCorrectionProposal(fix, new ExpressionsCleanUp(options), 1, image, context); resultingCollections.add(proposal); return true; } private static int getExpressionPrecedence(Expression expression) {
/** * {@inheritDoc} */ public String[] getDescriptions() { List result= new ArrayList(); if (isEnabled(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES) && isEnabled(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES_ALWAYS)) result.add(MultiFixMessages.ExpressionsCleanUp_addParanoiac_description); if (isEnabled(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES) && isEnabled(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES_NEVER)) result.add(MultiFixMessages.ExpressionsCleanUp_removeUnnecessary_description); return (String[])result.toArray(new String[result.size()]); }
protected ICleanUp[] createPreviewCleanUps(Map values) { return new ICleanUp[] { new ControlStatementsCleanUp(values), new ConvertLoopCleanUp(values), new ExpressionsCleanUp(values), new VariableDeclarationCleanUp(values) }; }
@Override public String[] getStepDescriptions() { List<String> result= new ArrayList<>(); if (isEnabled(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES) && isEnabled(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES_ALWAYS)) result.add(MultiFixMessages.ExpressionsCleanUp_addParanoiac_description); if (isEnabled(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES) && isEnabled(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES_NEVER)) result.add(MultiFixMessages.ExpressionsCleanUp_removeUnnecessary_description); return 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 String[] getStepDescriptions() { List<String> result= new ArrayList<>(); if (isEnabled(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES) && isEnabled(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES_ALWAYS)) result.add(MultiFixMessages.ExpressionsCleanUp_addParanoiac_description); if (isEnabled(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES) && isEnabled(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES_NEVER)) result.add(MultiFixMessages.ExpressionsCleanUp_removeUnnecessary_description); return 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) }; }