Search in sources :

Example 16 with FixCorrectionProposal

use of org.eclipse.jdt.internal.ui.text.correction.proposals.FixCorrectionProposal in project che by eclipse.

the class NullAnnotationsCorrectionProcessor method addNullAnnotationInSignatureProposal.

public static void addNullAnnotationInSignatureProposal(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals, ChangeKind changeKind, boolean isArgumentProblem) {
    NullAnnotationsFix fix = NullAnnotationsFix.createNullAnnotationInSignatureFix(context.getASTRoot(), problem, changeKind, isArgumentProblem);
    if (fix != null) {
        Image image = JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
        Map<String, String> options = new Hashtable<String, String>();
        if (fix.getCu() != context.getASTRoot()) {
            // workaround: adjust the unit to operate on, depending on the findings of RewriteOperations.createAddAnnotationOperation(..)
            final CompilationUnit cu = fix.getCu();
            final IInvocationContext originalContext = context;
            context = new IInvocationContext() {

                public int getSelectionOffset() {
                    return originalContext.getSelectionOffset();
                }

                public int getSelectionLength() {
                    return originalContext.getSelectionLength();
                }

                public ASTNode getCoveringNode() {
                    return originalContext.getCoveringNode();
                }

                public ASTNode getCoveredNode() {
                    return originalContext.getCoveredNode();
                }

                public ICompilationUnit getCompilationUnit() {
                    return (ICompilationUnit) cu.getJavaElement();
                }

                public CompilationUnit getASTRoot() {
                    return cu;
                }
            };
        }
        //raise local change above change in overridden method
        int relevance = (changeKind == ChangeKind.OVERRIDDEN) ? IProposalRelevance.CHANGE_NULLNESS_ANNOTATION_IN_OVERRIDDEN_METHOD : IProposalRelevance.CHANGE_NULLNESS_ANNOTATION;
        FixCorrectionProposal proposal = new FixCorrectionProposal(fix, new NullAnnotationsCleanUp(options, problem.getProblemId()), relevance, image, context);
        proposals.add(proposal);
    }
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) CompilationUnit(org.eclipse.jdt.core.dom.CompilationUnit) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) FixCorrectionProposal(org.eclipse.jdt.internal.ui.text.correction.proposals.FixCorrectionProposal) Hashtable(java.util.Hashtable) ASTNode(org.eclipse.jdt.core.dom.ASTNode) IInvocationContext(org.eclipse.jdt.ui.text.java.IInvocationContext) NullAnnotationsFix(org.eclipse.jdt.internal.corext.fix.NullAnnotationsFix) Image(org.eclipse.swt.graphics.Image) NullAnnotationsCleanUp(org.eclipse.jdt.internal.ui.fix.NullAnnotationsCleanUp)

Example 17 with FixCorrectionProposal

use of org.eclipse.jdt.internal.ui.text.correction.proposals.FixCorrectionProposal 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 18 with FixCorrectionProposal

use of org.eclipse.jdt.internal.ui.text.correction.proposals.FixCorrectionProposal 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)

Example 19 with FixCorrectionProposal

use of org.eclipse.jdt.internal.ui.text.correction.proposals.FixCorrectionProposal in project che by eclipse.

the class LocalCorrectionsSubProcessor method getUnnecessaryNLSTagProposals.

public static void getUnnecessaryNLSTagProposals(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) throws CoreException {
    IProposableFix fix = StringFix.createFix(context.getASTRoot(), problem, true, false);
    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 Hashtable<String, String>();
        options.put(CleanUpConstants.REMOVE_UNNECESSARY_NLS_TAGS, CleanUpOptions.TRUE);
        FixCorrectionProposal proposal = new FixCorrectionProposal(fix, new StringCleanUp(options), IProposalRelevance.UNNECESSARY_NLS_TAG, image, context);
        proposal.setCommandId(REMOVE_UNNECESSARY_NLS_TAG_ID);
        proposals.add(proposal);
    }
}
Also used : FixCorrectionProposal(org.eclipse.jdt.internal.ui.text.correction.proposals.FixCorrectionProposal) Hashtable(java.util.Hashtable) StringCleanUp(org.eclipse.jdt.internal.ui.fix.StringCleanUp) IProposableFix(org.eclipse.jdt.internal.corext.fix.IProposableFix) Image(org.eclipse.swt.graphics.Image)

Example 20 with FixCorrectionProposal

use of org.eclipse.jdt.internal.ui.text.correction.proposals.FixCorrectionProposal in project che by eclipse.

the class LocalCorrectionsSubProcessor method addProposal.

private static void addProposal(IInvocationContext context, Collection<ICommandAccess> proposals, final UnusedCodeFix fix) {
    if (fix != null) {
        //JavaPlugin.getDefault().getWorkbench().getSharedImages().getImage(ISharedImages.IMG_TOOL_DELETE);
        Image image = JavaPluginImages.get(JavaPluginImages.IMG_TOOL_DELETE);
        FixCorrectionProposal proposal = new FixCorrectionProposal(fix, fix.getCleanUp(), IProposalRelevance.UNUSED_MEMBER, image, context);
        proposals.add(proposal);
    }
}
Also used : FixCorrectionProposal(org.eclipse.jdt.internal.ui.text.correction.proposals.FixCorrectionProposal) Image(org.eclipse.swt.graphics.Image)

Aggregations

FixCorrectionProposal (org.eclipse.jdt.internal.ui.text.correction.proposals.FixCorrectionProposal)23 Image (org.eclipse.swt.graphics.Image)23 IProposableFix (org.eclipse.jdt.internal.corext.fix.IProposableFix)19 Hashtable (java.util.Hashtable)15 HashMap (java.util.HashMap)6 ICleanUp (org.eclipse.jdt.ui.cleanup.ICleanUp)4 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)3 ExpressionsCleanUp (org.eclipse.jdt.internal.ui.fix.ExpressionsCleanUp)3 Java50CleanUp (org.eclipse.jdt.internal.ui.fix.Java50CleanUp)3 IType (org.eclipse.jdt.core.IType)2 NullAnnotationsFix (org.eclipse.jdt.internal.corext.fix.NullAnnotationsFix)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 NullAnnotationsCleanUp (org.eclipse.jdt.internal.ui.fix.NullAnnotationsCleanUp)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 ASTNode (org.eclipse.jdt.core.dom.ASTNode)1