RefinerMatchResult (@NotNull PsiElement element) { if (myMethodName.equals("requireNonNull") && myClassName.equals(CommonClassNames.JAVA_UTIL_OBJECTS)) { // Since Java 9 Objects.requireNonNull(x) is used by javac instead of x.getClass() for generated null-check (JDK-8074306) RefinerMatchResult result = NullPointerExceptionInfo.matchCompilerGeneratedNullCheck(element); if (result != null) { return result; } } if (!(element instanceof PsiIdentifier)) return null; if (myMethodName.equals("<init>")) { if (myHasDollarInName || element.textMatches(StringUtil.getShortName(myClassName))) { PsiElement parent = element.getParent(); while (parent instanceof PsiJavaCodeReferenceElement) { parent = parent.getParent(); } if (parent instanceof PsiAnonymousClass) { return isTargetClass(parent) || isTargetClass(((PsiAnonymousClass)parent).getSuperClass()) ? RefinerMatchResult.of(element) : null; } if (parent instanceof PsiNewExpression) { PsiJavaCodeReferenceElement ref = ((PsiNewExpression)parent).getClassOrAnonymousClassReference(); return ref != null && isTargetClass(ref.resolve()) ? RefinerMatchResult.of(element) : null; } } } else if (element.textMatches(myMethodName)) { PsiElement parent = element.getParent(); if (parent instanceof PsiReferenceExpression) { PsiElement target = ((PsiReferenceExpression)parent).resolve(); return target instanceof PsiMethod && isTargetClass(((PsiMethod)target).getContainingClass()) ? RefinerMatchResult.of(element) : null; } } return null; }