Disable conversion when anonymous class is annotated (IDEA-197979)

GitOrigin-RevId: 07e199e8ccf2ff58132f642f6bdf178a34802c37
This commit is contained in:
Tagir Valeev
2020-04-01 11:35:50 +07:00
committed by intellij-monorepo-bot
parent 37158871a3
commit c53dea2917
2 changed files with 16 additions and 0 deletions

View File

@@ -190,6 +190,7 @@ public class AnonymousCanBeLambdaInspection extends AbstractBaseJavaLocalInspect
boolean acceptParameterizedFunctionTypes,
boolean reportNotAnnotatedInterfaces,
@NotNull Set<String> ignoredRuntimeAnnotations) {
if (aClass.getBaseClassType().getAnnotations().length > 0) return false;
PsiElement parent = aClass.getParent();
final PsiElement lambdaContext = parent != null ? PsiUtil.skipParenthesizedExprUp(parent.getParent()) : null;
if (lambdaContext == null || !LambdaUtil.isValidLambdaContext(lambdaContext) && !(lambdaContext instanceof PsiReferenceExpression)) return false;

View File

@@ -0,0 +1,15 @@
// "Replace with lambda" "false"
import java.lang.annotation.*;
class MyTest {
final Runnable anonymRunnable = new @A Run<caret>nable() {
@Override
public void run() {
System.out.println();
}
};
}
@Target({ElementType.TYPE_USE})
@Retention(RetentionPolicy.RUNTIME)
@interface A {}