@Override
 public void visitLambdaExpression(PsiLambdaExpression lambdaExpression) {
   super.visitLambdaExpression(lambdaExpression);
   if (lambdaExpression.getBody() instanceof PsiExpression) {
     registerError(lambdaExpression);
   }
 }
 private void registerNestedClosures(
     @NotNull DfaInstructionState instructionState, @NotNull PsiLambdaExpression expr) {
   DfaMemoryState state = instructionState.getMemoryState();
   PsiElement body = expr.getBody();
   if (body != null) {
     myNestedClosures.putValue(body, createClosureState(state));
   }
 }
 public static boolean processDeclarationsInLambda(
     @NotNull final PsiLambdaExpression lambda,
     @NotNull final PsiScopeProcessor processor,
     @NotNull final ResolveState state,
     final PsiElement lastParent,
     @NotNull final PsiElement place) {
   final boolean fromBody = lastParent != null && lastParent == lambda.getBody();
   return processDeclarationsInMethodLike(lambda, processor, state, place, fromBody, null);
 }
Exemple #4
0
 @Override
 public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
   final PsiElement element = descriptor.getPsiElement();
   if (element != null) {
     if (!FileModificationService.getInstance().preparePsiElementForWrite(element)) return;
     final PsiLambdaExpression lambdaExpression =
         PsiTreeUtil.getParentOfType(element, PsiLambdaExpression.class);
     if (lambdaExpression != null) {
       final PsiElement body = lambdaExpression.getBody();
       if (body != null) {
         PsiExpression expression = LambdaUtil.extractSingleExpressionFromBody(body);
         if (expression != null) {
           body.replace(expression);
         }
       }
     }
   }
 }
Exemple #5
0
 @Nullable
 public static PsiElement getFirstElementOnTheLine(
     PsiLambdaExpression lambda, Document document, int line) {
   ApplicationManager.getApplication().assertReadAccessAllowed();
   TextRange lineRange = DocumentUtil.getLineTextRange(document, line);
   if (!intersects(lineRange, lambda)) return null;
   PsiElement body = lambda.getBody();
   if (body == null || !intersects(lineRange, body)) return null;
   if (body instanceof PsiCodeBlock) {
     for (PsiStatement statement : ((PsiCodeBlock) body).getStatements()) {
       if (intersects(lineRange, statement)) {
         return statement;
       }
     }
     return null;
   }
   return body;
 }