Search in sources :

Example 1 with ExpressionsCleanUp

use of org.eclipse.jdt.internal.ui.fix.ExpressionsCleanUp in project che by eclipse.

the class AdvancedQuickAssistProcessor method getAddParanoidalParenthesesProposals.

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<String, String>();
    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;
}
Also used : FixCorrectionProposal(org.eclipse.jdt.internal.ui.text.correction.proposals.FixCorrectionProposal) Hashtable(java.util.Hashtable) IProposableFix(org.eclipse.jdt.internal.corext.fix.IProposableFix) ExpressionsCleanUp(org.eclipse.jdt.internal.ui.fix.ExpressionsCleanUp) Image(org.eclipse.swt.graphics.Image)

Example 2 with ExpressionsCleanUp

use of org.eclipse.jdt.internal.ui.fix.ExpressionsCleanUp in project che by eclipse.

the class AdvancedQuickAssistProcessor method getRemoveExtraParenthesesProposals.

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<ASTNode>();
        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<String, String>();
    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;
}
Also used : FixCorrectionProposal(org.eclipse.jdt.internal.ui.text.correction.proposals.FixCorrectionProposal) Hashtable(java.util.Hashtable) IProposableFix(org.eclipse.jdt.internal.corext.fix.IProposableFix) ExpressionsCleanUp(org.eclipse.jdt.internal.ui.fix.ExpressionsCleanUp) Image(org.eclipse.swt.graphics.Image)

Example 3 with ExpressionsCleanUp

use of org.eclipse.jdt.internal.ui.fix.ExpressionsCleanUp in project che by eclipse.

the class QuickAssistProcessor method getConvertAnonymousClassCreationsToLambdaProposals.

private static boolean getConvertAnonymousClassCreationsToLambdaProposals(IInvocationContext context, ASTNode covering, Collection<ICommandAccess> resultingCollections) {
    while (covering instanceof Name || covering instanceof Type || covering instanceof Dimension || covering.getParent() instanceof MethodDeclaration || covering.getLocationInParent() == AnonymousClassDeclaration.BODY_DECLARATIONS_PROPERTY) {
        covering = covering.getParent();
    }
    ClassInstanceCreation cic;
    if (covering instanceof ClassInstanceCreation) {
        cic = (ClassInstanceCreation) covering;
    } else if (covering.getLocationInParent() == ClassInstanceCreation.ANONYMOUS_CLASS_DECLARATION_PROPERTY) {
        cic = (ClassInstanceCreation) covering.getParent();
    } else if (covering instanceof Name) {
        ASTNode normalized = ASTNodes.getNormalizedNode(covering);
        if (normalized.getLocationInParent() != ClassInstanceCreation.TYPE_PROPERTY)
            return false;
        cic = (ClassInstanceCreation) normalized.getParent();
    } else {
        return false;
    }
    IProposableFix fix = LambdaExpressionsFix.createConvertToLambdaFix(cic);
    if (fix == null)
        return false;
    if (resultingCollections == null)
        return true;
    // add correction proposal
    Image image = JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
    Map<String, String> options = new Hashtable<String, String>();
    options.put(CleanUpConstants.CONVERT_FUNCTIONAL_INTERFACES, CleanUpOptions.TRUE);
    options.put(CleanUpConstants.USE_LAMBDA, CleanUpOptions.TRUE);
    FixCorrectionProposal proposal = new FixCorrectionProposal(fix, new ExpressionsCleanUp(options), IProposalRelevance.CONVERT_TO_LAMBDA_EXPRESSION, image, context);
    resultingCollections.add(proposal);
    return true;
}
Also used : Hashtable(java.util.Hashtable) IProposableFix(org.eclipse.jdt.internal.corext.fix.IProposableFix) LambdaExpressionsCleanUp(org.eclipse.jdt.internal.ui.fix.LambdaExpressionsCleanUp) ExpressionsCleanUp(org.eclipse.jdt.internal.ui.fix.ExpressionsCleanUp) Image(org.eclipse.swt.graphics.Image) IType(org.eclipse.jdt.core.IType) FixCorrectionProposal(org.eclipse.jdt.internal.ui.text.correction.proposals.FixCorrectionProposal)

Aggregations

Hashtable (java.util.Hashtable)3 IProposableFix (org.eclipse.jdt.internal.corext.fix.IProposableFix)3 ExpressionsCleanUp (org.eclipse.jdt.internal.ui.fix.ExpressionsCleanUp)3 FixCorrectionProposal (org.eclipse.jdt.internal.ui.text.correction.proposals.FixCorrectionProposal)3 Image (org.eclipse.swt.graphics.Image)3 IType (org.eclipse.jdt.core.IType)1 LambdaExpressionsCleanUp (org.eclipse.jdt.internal.ui.fix.LambdaExpressionsCleanUp)1