Search in sources :

Example 1 with LambdaExpressionsCleanUpCore

use of org.eclipse.jdt.internal.ui.fix.LambdaExpressionsCleanUpCore in project eclipse.jdt.ls by eclipse.

the class RefactorProcessor method getConvertLambdaToAnonymousClassCreationsProposals.

private static boolean getConvertLambdaToAnonymousClassCreationsProposals(IInvocationContext context, ASTNode covering, Collection<ChangeCorrectionProposal> resultingCollections) {
    if (resultingCollections == null) {
        return true;
    }
    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 = LambdaExpressionsFixCore.createConvertToAnonymousClassCreationsFix(lambda);
    if (fix == null) {
        return false;
    }
    // add correction proposal
    Map<String, String> options = new HashMap<>();
    options.put(CleanUpConstants.CONVERT_FUNCTIONAL_INTERFACES, CleanUpOptionsCore.TRUE);
    options.put(CleanUpConstants.USE_ANONYMOUS_CLASS_CREATION, CleanUpOptionsCore.TRUE);
    FixCorrectionProposal proposal = new FixCorrectionProposal(fix, new LambdaExpressionsCleanUpCore(options), IProposalRelevance.CONVERT_TO_ANONYMOUS_CLASS_CREATION, context, CodeActionKind.Refactor);
    resultingCollections.add(proposal);
    return true;
}
Also used : FixCorrectionProposal(org.eclipse.jdt.ls.core.internal.corrections.proposals.FixCorrectionProposal) HashMap(java.util.HashMap) IProposableFix(org.eclipse.jdt.internal.corext.fix.IProposableFix) LambdaExpression(org.eclipse.jdt.core.dom.LambdaExpression) LambdaExpressionsCleanUpCore(org.eclipse.jdt.internal.ui.fix.LambdaExpressionsCleanUpCore)

Example 2 with LambdaExpressionsCleanUpCore

use of org.eclipse.jdt.internal.ui.fix.LambdaExpressionsCleanUpCore in project eclipse.jdt.ls by eclipse.

the class RefactorProcessor method getConvertAnonymousClassCreationsToLambdaProposals.

private static boolean getConvertAnonymousClassCreationsToLambdaProposals(IInvocationContext context, ASTNode covering, Collection<ChangeCorrectionProposal> resultingCollections) {
    ClassInstanceCreation cic = getClassInstanceCreation(covering);
    if (cic == null) {
        return false;
    }
    IProposableFix fix = LambdaExpressionsFixCore.createConvertToLambdaFix(cic);
    if (fix == null) {
        return false;
    }
    if (resultingCollections == null) {
        return true;
    }
    Map<String, String> options = new HashMap<>();
    options.put(CleanUpConstants.CONVERT_FUNCTIONAL_INTERFACES, CleanUpOptionsCore.TRUE);
    options.put(CleanUpConstants.USE_LAMBDA, CleanUpOptionsCore.TRUE);
    FixCorrectionProposal proposal = new FixCorrectionProposal(fix, new LambdaExpressionsCleanUpCore(options), IProposalRelevance.CONVERT_TO_LAMBDA_EXPRESSION, context, CodeActionKind.Refactor);
    resultingCollections.add(proposal);
    return true;
}
Also used : ClassInstanceCreation(org.eclipse.jdt.core.dom.ClassInstanceCreation) FixCorrectionProposal(org.eclipse.jdt.ls.core.internal.corrections.proposals.FixCorrectionProposal) HashMap(java.util.HashMap) IProposableFix(org.eclipse.jdt.internal.corext.fix.IProposableFix) LambdaExpressionsCleanUpCore(org.eclipse.jdt.internal.ui.fix.LambdaExpressionsCleanUpCore)

Aggregations

HashMap (java.util.HashMap)2 IProposableFix (org.eclipse.jdt.internal.corext.fix.IProposableFix)2 LambdaExpressionsCleanUpCore (org.eclipse.jdt.internal.ui.fix.LambdaExpressionsCleanUpCore)2 FixCorrectionProposal (org.eclipse.jdt.ls.core.internal.corrections.proposals.FixCorrectionProposal)2 ClassInstanceCreation (org.eclipse.jdt.core.dom.ClassInstanceCreation)1 LambdaExpression (org.eclipse.jdt.core.dom.LambdaExpression)1