PsiElementVisitor (@NotNull ProblemsHolder holder, boolean isOnTheFly) { return UastHintedVisitorAdapter.create(holder.getFile().getLanguage(), new AbstractUastNonRecursiveVisitor() { private final UnusedDeclarationInspectionBase myDeadCodeTool = UnusedDeclarationInspectionBase.findUnusedDeclarationInspection(holder.getFile()); @Override public boolean visitMethod(@NotNull UMethod method) { PsiMethod javaMethod = method.getJavaPsi(); if (method.isConstructor() || AccessModifier.fromModifierList(javaMethod.getModifierList()).compareTo( Objects.requireNonNullElse(myGlobal.highestModifier, DEFAULT_HIGHEST_MODIFIER)) < 0) { return true; } if (javaMethod.hasModifierProperty(PsiModifier.NATIVE)) return true; List<UParameter> parameters = method.getUastParameters(); if (parameters.isEmpty()) return true; if (myDeadCodeTool.isEntryPoint(javaMethod)) return true; if (!javaMethod.getHierarchicalMethodSignature().getSuperSignatures().isEmpty()) return true; Object[] paramValues = new Object[parameters.size()]; Arrays.fill(paramValues, VALUE_UNDEFINED); int[] usageCount = {0}; if (UnusedSymbolUtil.processUsages(holder.getProject(), holder.getFile(), javaMethod, new EmptyProgressIndicator(), null, info -> { PsiElement element = info.getElement(); usageCount[0]++; UElement uElement = UastContextKt.toUElement(element); if (!(uElement instanceof UReferenceExpression)) { return false; } if (uElement instanceof UCallableReferenceExpression) { return false; } UElement parent = uElement.getUastParent(); if (!(parent instanceof UCallExpression methodCall)) { return false; } if (methodCall.getValueArguments().size() < paramValues.length) return false; boolean needFurtherProcess = false; for (int i = 0; i < paramValues.length; i++) { UExpression arg = methodCall.getArgumentForParameter(i); Object argValue = RefParameterImpl.getAccessibleExpressionValue(arg, () -> method.getSourcePsi()); Object paramValue = paramValues[i]; if (paramValue == VALUE_UNDEFINED) { paramValues[i] = argValue; if (argValue != VALUE_IS_NOT_CONST) { needFurtherProcess = true; } } else if (paramValue != VALUE_IS_NOT_CONST) { if (!Comparing.equal(paramValue, argValue)) { paramValues[i] = VALUE_IS_NOT_CONST; } else { needFurtherProcess = true; } } } return needFurtherProcess; })) { if (myGlobal.minimalUsageCount != 0 && usageCount[0] < myGlobal.minimalUsageCount) return true; for (int i = 0, length = paramValues.length; i < length; i++) { Object value = paramValues[i]; List<Object> valueList = valueToList(value); if (valueList == null || ContainerUtil.all(valueList, v -> v != VALUE_UNDEFINED && v != VALUE_IS_NOT_CONST)) { final UParameter parameter = parameters.get(i); Boolean isFixAvailable = isFixAvailable(parameter, value, false); if (Boolean.FALSE.equals(isFixAvailable) && myGlobal.ignoreWhenRefactoringIsComplicated) return true; Object presentableValue = value; if (valueList != null && valueList.size() == 1 && valueList.get(0) == null) presentableValue = valueList.get(0); ProblemDescriptor descriptor = registerProblem(holder.getManager(), parameter, presentableValue, Boolean.TRUE.equals(isFixAvailable)); if (descriptor != null) { holder.registerProblem(descriptor); } } } } return true; } }, new Class[]{UMethod.class}); }