Search in sources :

Example 21 with FixCorrectionProposal

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

the class LocalCorrectionsSubProcessor method addTypePrametersToRawTypeReference.

public static void addTypePrametersToRawTypeReference(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) {
    IProposableFix fix = Java50Fix.createRawTypeReferenceFix(context.getASTRoot(), problem);
    if (fix != null) {
        for (Iterator<ICommandAccess> iter = proposals.iterator(); iter.hasNext(); ) {
            Object element = iter.next();
            if (element instanceof FixCorrectionProposal) {
                FixCorrectionProposal fixProp = (FixCorrectionProposal) element;
                if (RAW_TYPE_REFERENCE_ID.equals(fixProp.getCommandId())) {
                    return;
                }
            }
        }
        Image image = JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
        Map<String, String> options = new Hashtable<String, String>();
        options.put(CleanUpConstants.VARIABLE_DECLARATION_USE_TYPE_ARGUMENTS_FOR_RAW_TYPE_REFERENCES, CleanUpOptions.TRUE);
        FixCorrectionProposal proposal = new FixCorrectionProposal(fix, new Java50CleanUp(options), IProposalRelevance.RAW_TYPE_REFERENCE, image, context);
        proposal.setCommandId(RAW_TYPE_REFERENCE_ID);
        proposals.add(proposal);
    }
    //Infer Generic Type Arguments... proposal
    boolean hasInferTypeArgumentsProposal = false;
    for (Iterator<ICommandAccess> iterator = proposals.iterator(); iterator.hasNext(); ) {
        Object completionProposal = iterator.next();
        if (completionProposal instanceof ChangeCorrectionProposal) {
            if (IJavaEditorActionDefinitionIds.INFER_TYPE_ARGUMENTS_ACTION.equals(((ChangeCorrectionProposal) completionProposal).getCommandId())) {
                hasInferTypeArgumentsProposal = true;
                break;
            }
        }
    }
    if (!hasInferTypeArgumentsProposal) {
        final ICompilationUnit cu = context.getCompilationUnit();
        ChangeCorrectionProposal proposal = new ChangeCorrectionProposal(CorrectionMessages.LocalCorrectionsSubProcessor_InferGenericTypeArguments, null, IProposalRelevance.INFER_GENERIC_TYPE_ARGUMENTS, JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE)) {

            @Override
            public void apply(IDocument document) {
                //							action.run(new StructuredSelection(cu));
                throw new UnsupportedOperationException();
            }

            @Override
            public String getActionId() {
                return "javaInferTypeArguments";
            }

            /**
						 * {@inheritDoc}
						 */
            @Override
            public Object getAdditionalProposalInfo(IProgressMonitor monitor) {
                return CorrectionMessages.LocalCorrectionsSubProcessor_InferGenericTypeArguments_description;
            }
        };
        proposal.setCommandId(IJavaEditorActionDefinitionIds.INFER_TYPE_ARGUMENTS_ACTION);
        proposals.add(proposal);
    }
    addTypeArgumentsFromContext(context, problem, proposals);
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) ICommandAccess(org.eclipse.jdt.ui.text.java.correction.ICommandAccess) 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) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) FixCorrectionProposal(org.eclipse.jdt.internal.ui.text.correction.proposals.FixCorrectionProposal) Java50CleanUp(org.eclipse.jdt.internal.ui.fix.Java50CleanUp) IDocument(org.eclipse.jface.text.IDocument)

Example 22 with FixCorrectionProposal

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

the class LocalCorrectionsSubProcessor method addCorrectAccessToStaticProposals.

/*
	 * Fix instance accesses and indirect (static) accesses to static fields/methods
	 */
public static void addCorrectAccessToStaticProposals(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) throws CoreException {
    IProposableFix fix = CodeStyleFix.createIndirectAccessToStaticFix(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_STATIC_QUALIFY_WITH_DECLARING_CLASS, CleanUpOptions.TRUE);
        options.put(CleanUpConstants.MEMBER_ACCESSES_STATIC_QUALIFY_WITH_DECLARING_CLASS_SUBTYPE_ACCESS, CleanUpOptions.TRUE);
        FixCorrectionProposal proposal = new FixCorrectionProposal(fix, new CodeStyleCleanUp(options), IProposalRelevance.CREATE_INDIRECT_ACCESS_TO_STATIC, image, context);
        proposal.setCommandId(ADD_STATIC_ACCESS_ID);
        proposals.add(proposal);
        return;
    }
    IProposableFix[] fixes = CodeStyleFix.createNonStaticAccessFixes(context.getASTRoot(), problem);
    if (fixes != null) {
        IProposableFix fix1 = fixes[0];
        Image image = JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
        Map<String, String> options = new HashMap<String, String>();
        options.put(CleanUpConstants.MEMBER_ACCESSES_STATIC_QUALIFY_WITH_DECLARING_CLASS, CleanUpOptions.TRUE);
        options.put(CleanUpConstants.MEMBER_ACCESSES_STATIC_QUALIFY_WITH_DECLARING_CLASS_INSTANCE_ACCESS, CleanUpOptions.TRUE);
        FixCorrectionProposal proposal = new FixCorrectionProposal(fix1, new CodeStyleCleanUp(options), IProposalRelevance.CREATE_NON_STATIC_ACCESS_USING_DECLARING_TYPE, image, context);
        proposal.setCommandId(ADD_STATIC_ACCESS_ID);
        proposals.add(proposal);
        if (fixes.length > 1) {
            Map<String, String> options1 = new HashMap<String, String>();
            options1.put(CleanUpConstants.MEMBER_ACCESSES_STATIC_QUALIFY_WITH_DECLARING_CLASS, CleanUpOptions.TRUE);
            options1.put(CleanUpConstants.MEMBER_ACCESSES_STATIC_QUALIFY_WITH_DECLARING_CLASS_SUBTYPE_ACCESS, CleanUpOptions.TRUE);
            options1.put(CleanUpConstants.MEMBER_ACCESSES_STATIC_QUALIFY_WITH_DECLARING_CLASS_INSTANCE_ACCESS, CleanUpOptions.TRUE);
            IProposableFix fix2 = fixes[1];
            proposal = new FixCorrectionProposal(fix2, new CodeStyleCleanUp(options), IProposalRelevance.CREATE_NON_STATIC_ACCESS_USING_INSTANCE_TYPE, image, context);
            proposals.add(proposal);
        }
    }
    ModifierCorrectionSubProcessor.addNonAccessibleReferenceProposal(context, problem, proposals, ModifierCorrectionSubProcessor.TO_NON_STATIC, IProposalRelevance.REMOVE_STATIC_MODIFIER);
}
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 23 with FixCorrectionProposal

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

the class LocalCorrectionsSubProcessor method addUnnecessaryCastProposal.

public static void addUnnecessaryCastProposal(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) {
    IProposableFix fix = UnusedCodeFix.createRemoveUnusedCastFix(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.REMOVE_UNNECESSARY_CASTS, CleanUpOptions.TRUE);
        FixCorrectionProposal proposal = new FixCorrectionProposal(fix, new UnnecessaryCodeCleanUp(options), IProposalRelevance.REMOVE_UNUSED_CAST, image, context);
        proposals.add(proposal);
    }
}
Also used : UnnecessaryCodeCleanUp(org.eclipse.jdt.internal.ui.fix.UnnecessaryCodeCleanUp) 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)

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