Search in sources :

Example 1 with TypeParametersCleanUp

use of org.eclipse.jdt.internal.ui.fix.TypeParametersCleanUp 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 2 with TypeParametersCleanUp

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

Aggregations

HashMap (java.util.HashMap)2 IProposableFix (org.eclipse.jdt.internal.corext.fix.IProposableFix)2 TypeParametersCleanUp (org.eclipse.jdt.internal.ui.fix.TypeParametersCleanUp)2 FixCorrectionProposal (org.eclipse.jdt.internal.ui.text.correction.proposals.FixCorrectionProposal)2 Image (org.eclipse.swt.graphics.Image)2 IType (org.eclipse.jdt.core.IType)1