Search in sources :

Example 6 with IProposableFix

use of org.eclipse.jdt.internal.corext.fix.IProposableFix 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 7 with IProposableFix

use of org.eclipse.jdt.internal.corext.fix.IProposableFix 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 8 with IProposableFix

use of org.eclipse.jdt.internal.corext.fix.IProposableFix 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)

Example 9 with IProposableFix

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

the class LocalCorrectionsSubProcessor method addUnimplementedMethodsProposals.

public static void addUnimplementedMethodsProposals(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) {
    IProposableFix addMethodFix = UnimplementedCodeFix.createAddUnimplementedMethodsFix(context.getASTRoot(), problem);
    if (addMethodFix != null) {
        Image image = JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
        Map<String, String> settings = new Hashtable<String, String>();
        settings.put(CleanUpConstants.ADD_MISSING_METHODES, CleanUpOptions.TRUE);
        ICleanUp cleanUp = new UnimplementedCodeCleanUp(settings);
        proposals.add(new FixCorrectionProposal(addMethodFix, cleanUp, IProposalRelevance.ADD_UNIMPLEMENTED_METHODS, image, context));
    }
    IProposableFix makeAbstractFix = UnimplementedCodeFix.createMakeTypeAbstractFix(context.getASTRoot(), problem);
    if (makeAbstractFix != null) {
        Image image = JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
        Map<String, String> settings = new Hashtable<String, String>();
        settings.put(UnimplementedCodeCleanUp.MAKE_TYPE_ABSTRACT, CleanUpOptions.TRUE);
        ICleanUp cleanUp = new UnimplementedCodeCleanUp(settings);
        proposals.add(new FixCorrectionProposal(makeAbstractFix, cleanUp, IProposalRelevance.MAKE_TYPE_ABSTRACT, image, context));
    }
}
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) UnimplementedCodeCleanUp(org.eclipse.jdt.internal.ui.fix.UnimplementedCodeCleanUp) Image(org.eclipse.swt.graphics.Image)

Example 10 with IProposableFix

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

the class ModifierCorrectionSubProcessor method addDeprecatedAnnotationProposal.

public static void addDeprecatedAnnotationProposal(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) {
    IProposableFix fix = Java50Fix.createAddDeprectatedAnnotation(context.getASTRoot(), problem);
    if (fix != null) {
        Image image = JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
        Map<String, String> options = new Hashtable<String, String>();
        options.put(CleanUpConstants.ADD_MISSING_ANNOTATIONS, CleanUpOptions.TRUE);
        options.put(CleanUpConstants.ADD_MISSING_ANNOTATIONS_DEPRECATED, CleanUpOptions.TRUE);
        FixCorrectionProposal proposal = new FixCorrectionProposal(fix, new Java50CleanUp(options), IProposalRelevance.ADD_DEPRECATED_ANNOTATION, image, context);
        proposals.add(proposal);
    }
}
Also used : 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) Java50CleanUp(org.eclipse.jdt.internal.ui.fix.Java50CleanUp)

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