Search in sources :

Example 1 with IProposableFix

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

the class QuickAssistProcessor method getConvertIterableLoopProposal.

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<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_ITERABLE_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 2 with IProposableFix

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

the class QuickAssistProcessor method getInferDiamondArgumentsProposal.

public static boolean getInferDiamondArgumentsProposal(IInvocationContext context, ASTNode node, IProblemLocation[] locations, Collection<ICommandAccess> resultingCollections) {
    // don't add if already added as quick fix
    if (containsMatchingProblem(locations, IProblem.DiamondNotBelow17))
        return false;
    ParameterizedType createdType = null;
    if (node instanceof Name) {
        Name name = ASTNodes.getTopMostName((Name) node);
        if (name.getLocationInParent() == SimpleType.NAME_PROPERTY || name.getLocationInParent() == NameQualifiedType.NAME_PROPERTY) {
            ASTNode type = name.getParent();
            if (type.getLocationInParent() == ParameterizedType.TYPE_PROPERTY) {
                createdType = (ParameterizedType) type.getParent();
                if (createdType.getLocationInParent() != ClassInstanceCreation.TYPE_PROPERTY) {
                    return false;
                }
            }
        }
    } else if (node instanceof ParameterizedType) {
        createdType = (ParameterizedType) node;
        if (createdType.getLocationInParent() != ClassInstanceCreation.TYPE_PROPERTY) {
            return false;
        }
    } else if (node instanceof ClassInstanceCreation) {
        ClassInstanceCreation creation = (ClassInstanceCreation) node;
        Type type = creation.getType();
        if (type instanceof ParameterizedType) {
            createdType = (ParameterizedType) type;
        }
    }
    IProposableFix fix = TypeParametersFix.createInsertInferredTypeArgumentsFix(context.getASTRoot(), createdType);
    if (fix != null && resultingCollections != null) {
        Image image = JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
        // if error -> higher than ReorgCorrectionsSubProcessor.getNeedHigherComplianceProposals()
        int relevance = locations == null ? IProposalRelevance.INSERT_INFERRED_TYPE_ARGUMENTS : IProposalRelevance.INSERT_INFERRED_TYPE_ARGUMENTS_ERROR;
        Map<String, String> options = new HashMap<String, String>();
        options.put(CleanUpConstants.USE_TYPE_ARGUMENTS, CleanUpOptions.TRUE);
        options.put(CleanUpConstants.INSERT_INFERRED_TYPE_ARGUMENTS, CleanUpOptions.TRUE);
        FixCorrectionProposal proposal = new FixCorrectionProposal(fix, new TypeParametersCleanUp(options), relevance, image, context);
        resultingCollections.add(proposal);
    }
    return true;
}
Also used : HashMap(java.util.HashMap) TypeParametersCleanUp(org.eclipse.jdt.internal.ui.fix.TypeParametersCleanUp) IProposableFix(org.eclipse.jdt.internal.corext.fix.IProposableFix) Image(org.eclipse.swt.graphics.Image) IType(org.eclipse.jdt.core.IType) FixCorrectionProposal(org.eclipse.jdt.internal.ui.text.correction.proposals.FixCorrectionProposal)

Example 3 with IProposableFix

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

the class ReorgCorrectionsSubProcessor method removeImportStatementProposals.

public static void removeImportStatementProposals(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) {
    IProposableFix fix = UnusedCodeFix.createRemoveUnusedImportFix(context.getASTRoot(), problem);
    if (fix != null) {
        Image image = JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_DELETE_IMPORT);
        Map<String, String> options = new Hashtable<String, String>();
        options.put(CleanUpConstants.REMOVE_UNUSED_CODE_IMPORTS, CleanUpOptions.TRUE);
        FixCorrectionProposal proposal = new FixCorrectionProposal(fix, new UnusedCodeCleanUp(options), IProposalRelevance.REMOVE_UNUSED_IMPORT, image, context);
        proposals.add(proposal);
    }
    final ICompilationUnit cu = context.getCompilationUnit();
    String name = CorrectionMessages.ReorgCorrectionsSubProcessor_organizeimports_description;
    ChangeCorrectionProposal proposal = new ChangeCorrectionProposal(name, null, IProposalRelevance.ORGANIZE_IMPORTS, JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE)) {

        @Override
        public void apply(IDocument document) {
            //				}
            throw new UnsupportedOperationException("apply doesn't supported for action proposal");
        }

        @Override
        public String getActionId() {
            return "javaOrganizeImports";
        }
    };
    proposals.add(proposal);
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) FixCorrectionProposal(org.eclipse.jdt.internal.ui.text.correction.proposals.FixCorrectionProposal) UnusedCodeCleanUp(org.eclipse.jdt.internal.ui.fix.UnusedCodeCleanUp) Hashtable(java.util.Hashtable) IProposableFix(org.eclipse.jdt.internal.corext.fix.IProposableFix) Image(org.eclipse.swt.graphics.Image) ChangeCorrectionProposal(org.eclipse.jdt.ui.text.java.correction.ChangeCorrectionProposal) IDocument(org.eclipse.jface.text.IDocument)

Example 4 with IProposableFix

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

the class LocalCorrectionsSubProcessor method addRemoveRedundantTypeArgumentsProposals.

public static void addRemoveRedundantTypeArgumentsProposals(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) {
    IProposableFix fix = TypeParametersFix.createRemoveRedundantTypeArgumentsFix(context.getASTRoot(), problem);
    if (fix != null) {
        //JavaPlugin.getDefault().getWorkbench().getSharedImages().getImage(ISharedImages.IMG_TOOL_DELETE);
        Image image = JavaPluginImages.get(JavaPluginImages.IMG_TOOL_DELETE);
        Map<String, String> options = new HashMap<String, String>();
        options.put(CleanUpConstants.USE_TYPE_ARGUMENTS, CleanUpOptions.TRUE);
        options.put(CleanUpConstants.REMOVE_REDUNDANT_TYPE_ARGUMENTS, CleanUpOptions.TRUE);
        FixCorrectionProposal proposal = new FixCorrectionProposal(fix, new TypeParametersCleanUp(options), IProposalRelevance.REMOVE_REDUNDANT_TYPE_ARGUMENTS, image, context);
        proposals.add(proposal);
    }
}
Also used : FixCorrectionProposal(org.eclipse.jdt.internal.ui.text.correction.proposals.FixCorrectionProposal) HashMap(java.util.HashMap) TypeParametersCleanUp(org.eclipse.jdt.internal.ui.fix.TypeParametersCleanUp) IProposableFix(org.eclipse.jdt.internal.corext.fix.IProposableFix) Image(org.eclipse.swt.graphics.Image)

Example 5 with IProposableFix

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

the class ModifierCorrectionSubProcessor method addOverrideAnnotationProposal.

public static void addOverrideAnnotationProposal(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) {
    IProposableFix fix = Java50Fix.createAddOverrideAnnotationFix(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_OVERRIDE, CleanUpOptions.TRUE);
        options.put(CleanUpConstants.ADD_MISSING_ANNOTATIONS_OVERRIDE_FOR_INTERFACE_METHOD_IMPLEMENTATION, CleanUpOptions.TRUE);
        FixCorrectionProposal proposal = new FixCorrectionProposal(fix, new Java50CleanUp(options), IProposalRelevance.ADD_OVERRIDE_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