Search in sources :

Example 11 with IProposableFix

use of org.eclipse.jdt.internal.corext.fix.IProposableFix in project che by eclipse.

the class QuickAssistProcessor method getConvertForLoopProposal.

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

Example 12 with IProposableFix

use of org.eclipse.jdt.internal.corext.fix.IProposableFix in project che by eclipse.

the class LocalCorrectionsSubProcessor method addUnqualifiedFieldAccessProposal.

public static void addUnqualifiedFieldAccessProposal(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) {
    IProposableFix fix = CodeStyleFix.createAddFieldQualifierFix(context.getASTRoot(), problem);
    if (fix != null) {
        Image image = JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
        Map<String, String> options = new HashMap<String, String>();
        options.put(CleanUpConstants.MEMBER_ACCESSES_NON_STATIC_FIELD_USE_THIS, CleanUpOptions.TRUE);
        options.put(CleanUpConstants.MEMBER_ACCESSES_NON_STATIC_FIELD_USE_THIS_ALWAYS, CleanUpOptions.TRUE);
        FixCorrectionProposal proposal = new FixCorrectionProposal(fix, new CodeStyleCleanUp(options), IProposalRelevance.ADD_FIELD_QUALIFIER, image, context);
        proposal.setCommandId(ADD_FIELD_QUALIFICATION_ID);
        proposals.add(proposal);
    }
}
Also used : FixCorrectionProposal(org.eclipse.jdt.internal.ui.text.correction.proposals.FixCorrectionProposal) CodeStyleCleanUp(org.eclipse.jdt.internal.ui.fix.CodeStyleCleanUp) HashMap(java.util.HashMap) IProposableFix(org.eclipse.jdt.internal.corext.fix.IProposableFix) Image(org.eclipse.swt.graphics.Image)

Example 13 with IProposableFix

use of org.eclipse.jdt.internal.corext.fix.IProposableFix in project che by eclipse.

the class QuickAssistProcessor method getRemoveBlockProposals.

private static boolean getRemoveBlockProposals(IInvocationContext context, ASTNode coveringNode, Collection<ICommandAccess> resultingCollections) {
    IProposableFix[] fixes = ControlStatementsFix.createRemoveBlockFix(context.getASTRoot(), coveringNode);
    if (fixes != null) {
        if (resultingCollections == null) {
            return true;
        }
        Map<String, String> options = new Hashtable<String, String>();
        options.put(CleanUpConstants.CONTROL_STATEMENTS_USE_BLOCKS, CleanUpOptions.TRUE);
        options.put(CleanUpConstants.CONTROL_STATMENTS_USE_BLOCKS_NEVER, CleanUpOptions.TRUE);
        ICleanUp cleanUp = new ControlStatementsCleanUp(options);
        for (int i = 0; i < fixes.length; i++) {
            IProposableFix fix = fixes[i];
            Image image = JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
            FixCorrectionProposal proposal = new FixCorrectionProposal(fix, cleanUp, IProposalRelevance.REMOVE_BLOCK_FIX, image, context);
            resultingCollections.add(proposal);
        }
        return true;
    }
    return false;
}
Also used : FixCorrectionProposal(org.eclipse.jdt.internal.ui.text.correction.proposals.FixCorrectionProposal) ICleanUp(org.eclipse.jdt.ui.cleanup.ICleanUp) Hashtable(java.util.Hashtable) IProposableFix(org.eclipse.jdt.internal.corext.fix.IProposableFix) Image(org.eclipse.swt.graphics.Image) ControlStatementsCleanUp(org.eclipse.jdt.internal.ui.fix.ControlStatementsCleanUp)

Example 14 with IProposableFix

use of org.eclipse.jdt.internal.corext.fix.IProposableFix in project che by eclipse.

the class QuickAssistProcessor method getConvertLambdaToAnonymousClassCreationsProposals.

private static boolean getConvertLambdaToAnonymousClassCreationsProposals(IInvocationContext context, ASTNode covering, Collection<ICommandAccess> resultingCollections) {
    LambdaExpression lambda;
    if (covering instanceof LambdaExpression) {
        lambda = (LambdaExpression) covering;
    } else if (covering.getLocationInParent() == LambdaExpression.BODY_PROPERTY) {
        lambda = (LambdaExpression) covering.getParent();
    } else {
        return false;
    }
    IProposableFix fix = LambdaExpressionsFix.createConvertToAnonymousClassCreationsFix(lambda);
    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_ANONYMOUS_CLASS_CREATION, CleanUpOptions.TRUE);
    FixCorrectionProposal proposal = new FixCorrectionProposal(fix, new LambdaExpressionsCleanUp(options), IProposalRelevance.CONVERT_TO_ANONYMOUS_CLASS_CREATION, image, context);
    resultingCollections.add(proposal);
    return true;
}
Also used : FixCorrectionProposal(org.eclipse.jdt.internal.ui.text.correction.proposals.FixCorrectionProposal) Hashtable(java.util.Hashtable) LambdaExpressionsCleanUp(org.eclipse.jdt.internal.ui.fix.LambdaExpressionsCleanUp) IProposableFix(org.eclipse.jdt.internal.corext.fix.IProposableFix) Image(org.eclipse.swt.graphics.Image)

Example 15 with IProposableFix

use of org.eclipse.jdt.internal.corext.fix.IProposableFix in project che by eclipse.

the class QuickAssistProcessor method getMakeVariableDeclarationFinalProposals.

private static boolean getMakeVariableDeclarationFinalProposals(IInvocationContext context, Collection<ICommandAccess> resultingCollections) {
    SelectionAnalyzer analyzer = new SelectionAnalyzer(Selection.createFromStartLength(context.getSelectionOffset(), context.getSelectionLength()), false);
    context.getASTRoot().accept(analyzer);
    ASTNode[] selectedNodes = analyzer.getSelectedNodes();
    if (selectedNodes.length == 0)
        return false;
    IProposableFix fix = VariableDeclarationFix.createChangeModifierToFinalFix(context.getASTRoot(), selectedNodes);
    if (fix == null)
        return false;
    if (resultingCollections == null)
        return true;
    Image image = JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
    Map<String, String> options = new Hashtable<String, String>();
    options.put(CleanUpConstants.VARIABLE_DECLARATIONS_USE_FINAL, CleanUpOptions.TRUE);
    options.put(CleanUpConstants.VARIABLE_DECLARATIONS_USE_FINAL_LOCAL_VARIABLES, CleanUpOptions.TRUE);
    options.put(CleanUpConstants.VARIABLE_DECLARATIONS_USE_FINAL_PARAMETERS, CleanUpOptions.TRUE);
    options.put(CleanUpConstants.VARIABLE_DECLARATIONS_USE_FINAL_PRIVATE_FIELDS, CleanUpOptions.TRUE);
    VariableDeclarationCleanUp cleanUp = new VariableDeclarationCleanUp(options);
    FixCorrectionProposal proposal = new FixCorrectionProposal(fix, cleanUp, IProposalRelevance.MAKE_VARIABLE_DECLARATION_FINAL, image, context);
    resultingCollections.add(proposal);
    return true;
}
Also used : SelectionAnalyzer(org.eclipse.jdt.internal.corext.dom.SelectionAnalyzer) FixCorrectionProposal(org.eclipse.jdt.internal.ui.text.correction.proposals.FixCorrectionProposal) Hashtable(java.util.Hashtable) IProposableFix(org.eclipse.jdt.internal.corext.fix.IProposableFix) Image(org.eclipse.swt.graphics.Image) VariableDeclarationCleanUp(org.eclipse.jdt.internal.ui.fix.VariableDeclarationCleanUp)

Aggregations

IProposableFix (org.eclipse.jdt.internal.corext.fix.IProposableFix)19 FixCorrectionProposal (org.eclipse.jdt.internal.ui.text.correction.proposals.FixCorrectionProposal)19 Image (org.eclipse.swt.graphics.Image)19 Hashtable (java.util.Hashtable)13 HashMap (java.util.HashMap)6 ICleanUp (org.eclipse.jdt.ui.cleanup.ICleanUp)4 ExpressionsCleanUp (org.eclipse.jdt.internal.ui.fix.ExpressionsCleanUp)3 Java50CleanUp (org.eclipse.jdt.internal.ui.fix.Java50CleanUp)3 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)2 IType (org.eclipse.jdt.core.IType)2 CodeStyleCleanUp (org.eclipse.jdt.internal.ui.fix.CodeStyleCleanUp)2 ConvertLoopCleanUp (org.eclipse.jdt.internal.ui.fix.ConvertLoopCleanUp)2 LambdaExpressionsCleanUp (org.eclipse.jdt.internal.ui.fix.LambdaExpressionsCleanUp)2 TypeParametersCleanUp (org.eclipse.jdt.internal.ui.fix.TypeParametersCleanUp)2 ChangeCorrectionProposal (org.eclipse.jdt.ui.text.java.correction.ChangeCorrectionProposal)2 IDocument (org.eclipse.jface.text.IDocument)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 SelectionAnalyzer (org.eclipse.jdt.internal.corext.dom.SelectionAnalyzer)1 ControlStatementsCleanUp (org.eclipse.jdt.internal.ui.fix.ControlStatementsCleanUp)1 StringCleanUp (org.eclipse.jdt.internal.ui.fix.StringCleanUp)1