void (@NotNull PsiReferenceExpression referenceExpression) { if (!expectedArgument.get().booleanValue()) { return; } super.visitReferenceExpression(referenceExpression); final PsiElement target = referenceExpression.resolve(); if (target instanceof PsiEnumConstant || target instanceof PsiClass) { return; } else if (target instanceof PsiField field) { if (field.hasModifierProperty(PsiModifier.STATIC) && field.hasModifierProperty(PsiModifier.FINAL)) { return; } } else if (target instanceof PsiParameter parameter) { if ("expected".equals(parameter.getName())) { return; } expectedArgument.set(Boolean.FALSE); return; } else if (target instanceof PsiLocalVariable) { final PsiVariable variable = (PsiLocalVariable)target; final PsiCodeBlock block = PsiTreeUtil.getParentOfType(variable, PsiCodeBlock.class); if (block == null) { return; // broken code } final PsiExpression definition = DeclarationSearchUtils.findDefinition(referenceExpression, variable); if (definition == null) { expectedArgument.set(Boolean.FALSE); return; } if (PsiUtil.isConstantExpression(definition) || PsiTypes.nullType().equals(definition.getType())) { return; } final PsiElement[] refs = DefUseUtil.getRefs(block, variable, definition); final int offset = referenceExpression.getTextOffset(); for (PsiElement ref : refs) { if (ref.getTextOffset() < offset) { expectedArgument.set(Boolean.FALSE); return; } } expressions.add(definition); } else if (target instanceof PsiMethod method && parameterPosition == ParameterPosition.ACTUAL) { if (!"expected".equals(method.getName())) { expectedArgument.set(Boolean.FALSE); } } if (!(target instanceof PsiCompiledElement)) { expectedArgument.set(Boolean.FALSE); } }