PsiElementVisitor (@NotNull final ProblemsHolder holder, final boolean isOnTheFly) { return new JavaElementVisitor() { @Override public void visitMethod(@NotNull PsiMethod method) { PsiAnnotation annotation = JavaMethodContractUtil.findContractAnnotation(method); if (annotation == null || (!ApplicationManager.getApplication().isInternal() && AnnotationUtil.isInferredAnnotation(annotation))) { return; } boolean ownContract = annotation.getOwner() == method.getModifierList(); for (StandardMethodContract contract : JavaMethodContractUtil.getMethodContracts(method)) { Map<PsiElement, String> errors = ContractChecker.checkContractClause(method, contract, ownContract); errors.forEach(holder::registerProblem); } } @Override public void visitAnnotation(@NotNull PsiAnnotation annotation) { if (!JavaMethodContractUtil.ORG_JETBRAINS_ANNOTATIONS_CONTRACT.equals(annotation.getQualifiedName())) return; PsiMethod method = PsiTreeUtil.getParentOfType(annotation, PsiMethod.class); if (method == null) return; String text = AnnotationUtil.getStringAttributeValue(annotation, null); if (StringUtil.isNotEmpty(text)) { ParseException error = checkContract(method, text); if (error != null) { PsiAnnotationMemberValue value = annotation.findAttributeValue(null); assert value != null; TextRange actualRange = null; if (value instanceof PsiExpression && error.getRange() != null) { actualRange = ExpressionUtils .findStringLiteralRange((PsiExpression)value, error.getRange().getStartOffset(), error.getRange().getEndOffset()); } holder.registerProblem(value, actualRange, error.getMessage()); } } checkMutationContract(annotation, method); } private void checkMutationContract(PsiAnnotation annotation, PsiMethod method) { String mutationContract = AnnotationUtil.getStringAttributeValue(annotation, MutationSignature.ATTR_MUTATES); if (StringUtil.isNotEmpty(mutationContract)) { boolean pure = Boolean.TRUE.equals(AnnotationUtil.getBooleanAttributeValue(annotation, "pure")); String error; if (pure) { error = JavaAnalysisBundle.message("inspection.contract.checker.pure.method.mutation.contract"); } else { error = MutationSignature.checkSignature(mutationContract, method); } if (error != null) { PsiAnnotationMemberValue value = annotation.findAttributeValue(MutationSignature.ATTR_MUTATES); assert value != null; holder.registerProblem(value, error); } } } }; }