Search in sources :

Example 1 with NullAnnotationsFix

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

the class NullAnnotationsCorrectionProcessor method addRemoveRedundantAnnotationProposal.

public static void addRemoveRedundantAnnotationProposal(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) {
    NullAnnotationsFix fix = NullAnnotationsFix.createRemoveRedundantNullAnnotationsFix(context.getASTRoot(), problem);
    if (fix == null)
        return;
    Image image = JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
    Map<String, String> options = new Hashtable<String, String>();
    FixCorrectionProposal proposal = new FixCorrectionProposal(fix, new NullAnnotationsCleanUp(options, problem.getProblemId()), IProposalRelevance.REMOVE_REDUNDANT_NULLNESS_ANNOTATION, image, context);
    proposals.add(proposal);
}
Also used : FixCorrectionProposal(org.eclipse.jdt.internal.ui.text.correction.proposals.FixCorrectionProposal) Hashtable(java.util.Hashtable) NullAnnotationsFix(org.eclipse.jdt.internal.corext.fix.NullAnnotationsFix) Image(org.eclipse.swt.graphics.Image) NullAnnotationsCleanUp(org.eclipse.jdt.internal.ui.fix.NullAnnotationsCleanUp)

Example 2 with NullAnnotationsFix

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

Aggregations

Hashtable (java.util.Hashtable)2 NullAnnotationsFix (org.eclipse.jdt.internal.corext.fix.NullAnnotationsFix)2 NullAnnotationsCleanUp (org.eclipse.jdt.internal.ui.fix.NullAnnotationsCleanUp)2 FixCorrectionProposal (org.eclipse.jdt.internal.ui.text.correction.proposals.FixCorrectionProposal)2 Image (org.eclipse.swt.graphics.Image)2 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)1 ASTNode (org.eclipse.jdt.core.dom.ASTNode)1 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)1 IInvocationContext (org.eclipse.jdt.ui.text.java.IInvocationContext)1