private static boolean getConvertMethodReferenceToLambdaProposal(IInvocationContext context, ASTNode covering, Collection<ICommandAccess> resultingCollections) throws JavaModelException { MethodReference methodReference; if (covering instanceof MethodReference) { methodReference= (MethodReference) covering; } else if (covering.getParent() instanceof MethodReference) { methodReference= (MethodReference) covering.getParent(); } else { return false; } IMethodBinding functionalMethod= getFunctionalMethodForMethodReference(methodReference); if (functionalMethod == null || functionalMethod.isGenericMethod()) { // generic lambda expressions are not allowed return false; } if (resultingCollections == null) return true; ASTRewrite rewrite= ASTRewrite.create(methodReference.getAST()); LinkedProposalModel linkedProposalModel= new LinkedProposalModel(); LambdaExpression lambda= convertMethodRefernceToLambda(methodReference, functionalMethod, context.getASTRoot(), rewrite, linkedProposalModel, false); // add proposal String label= CorrectionMessages.QuickAssistProcessor_convert_to_lambda_expression; Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE); LinkedCorrectionProposal proposal= new LinkedCorrectionProposal(label, context.getCompilationUnit(), rewrite, IProposalRelevance.CONVERT_METHOD_REFERENCE_TO_LAMBDA, image); proposal.setLinkedProposalModel(linkedProposalModel); proposal.setEndPosition(rewrite.track(lambda)); resultingCollections.add(proposal); return true; }
private static boolean getConvertMethodReferenceToLambdaProposal(IInvocationContext context, ASTNode covering, Collection<ICommandAccess> resultingCollections) throws JavaModelException { MethodReference methodReference; if (covering instanceof MethodReference) { methodReference= (MethodReference) covering; } else if (covering.getParent() instanceof MethodReference) { methodReference= (MethodReference) covering.getParent(); } else { return false; } IMethodBinding functionalMethod= getFunctionalMethodForMethodReference(methodReference); if (functionalMethod == null || functionalMethod.isGenericMethod()) { // generic lambda expressions are not allowed return false; } if (resultingCollections == null) return true; ASTRewrite rewrite= ASTRewrite.create(methodReference.getAST()); LinkedProposalModel linkedProposalModel= new LinkedProposalModel(); LambdaExpression lambda= convertMethodRefernceToLambda(methodReference, functionalMethod, context.getASTRoot(), rewrite, linkedProposalModel, false); // add proposal String label= CorrectionMessages.QuickAssistProcessor_convert_to_lambda_expression; Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE); LinkedCorrectionProposal proposal= new LinkedCorrectionProposal(label, context.getCompilationUnit(), rewrite, IProposalRelevance.CONVERT_METHOD_REFERENCE_TO_LAMBDA, image); proposal.setLinkedProposalModel(linkedProposalModel); proposal.setEndPosition(rewrite.track(lambda)); resultingCollections.add(proposal); return true; }