private static void checkMethodCall(RefElement refWhat, final PsiElement element) { if (!(refWhat instanceof RefMethod)) return; final RefMethod refMethod = (RefMethod) refWhat; final PsiElement psiElement = refMethod.getElement(); if (!(psiElement instanceof PsiMethod)) return; final PsiMethod psiMethod = (PsiMethod) psiElement; if (!PsiType.BOOLEAN.equals(psiMethod.getReturnType())) return; element.accept( new JavaRecursiveElementWalkingVisitor() { @Override public void visitMethodCallExpression(PsiMethodCallExpression call) { super.visitMethodCallExpression(call); final PsiReferenceExpression methodExpression = call.getMethodExpression(); if (methodExpression.isReferenceTo(psiMethod)) { if (isInvertedMethodCall(methodExpression)) return; refMethod.putUserData(ALWAYS_INVERTED, Boolean.FALSE); } } @Override public void visitMethodReferenceExpression(PsiMethodReferenceExpression expression) { super.visitMethodReferenceExpression(expression); if (expression.isReferenceTo(psiElement)) { refMethod.putUserData(ALWAYS_INVERTED, Boolean.FALSE); } } }); }
@Override public void onInitialize(RefElement refElement) { if (refElement instanceof RefMethod) { final PsiElement element = refElement.getElement(); if (!(element instanceof PsiMethod)) return; if (!PsiType.BOOLEAN.equals(((PsiMethod) element).getReturnType())) return; refElement.putUserData(ALWAYS_INVERTED, Boolean.TRUE); // initial mark boolean methods } }
private static boolean isCompileTimeFlagReference(PsiElement element) { PsiElement resolved = element instanceof PsiReferenceExpression ? ((PsiReferenceExpression) element).resolve() : null; if (!(resolved instanceof PsiField)) return false; PsiField field = (PsiField) resolved; return field.hasModifierProperty(PsiModifier.FINAL) && field.hasModifierProperty(PsiModifier.STATIC) && PsiType.BOOLEAN.equals(field.getType()); }