void (@NotNull final ProgressIndicator progress) { ProjectFileIndex fileIndex = ProjectRootManager.getInstance(myProject).getFileIndex(); VirtualFile virtualFile = myFile.getViewProvider().getVirtualFile(); if (!fileIndex.isInContent(virtualFile)) { return; } final InspectionProfile profile = InspectionProjectProfileManager.getInstance(myProject).getCurrentProfile(); final HighlightDisplayKey unusedDefKey = HighlightDisplayKey.find(GroovyUnusedDeclarationInspection.SHORT_NAME); final boolean deadCodeEnabled = profile.isToolEnabled(unusedDefKey, myFile); final UnusedDeclarationInspectionBase deadCodeInspection = (UnusedDeclarationInspectionBase)profile.getUnwrappedTool(UnusedDeclarationInspectionBase.SHORT_NAME, myFile); final GroovyUsageHelper usageHelper = new GroovyUsageHelper(deadCodeInspection); final List<HighlightInfo> unusedDeclarations = new ArrayList<>(); final Map<GrParameter, Boolean> usedParams = new HashMap<>(); myFile.accept(new PsiRecursiveElementWalkingVisitor() { @Override public void visitElement(@NotNull PsiElement element) { if (element instanceof GrReferenceExpression && !((GrReferenceElement<?>)element).isQualified()) { GroovyResolveResult[] results = ((GrReferenceExpression)element).multiResolve(false); if (results.length == 0) { results = ((GrReferenceExpression)element).multiResolve(true); } for (GroovyResolveResult result : results) { PsiElement resolved = result.getElement(); if (resolved instanceof GrParameter && resolved.getContainingFile() == myFile) { usedParams.put((GrParameter)resolved, Boolean.TRUE); } } } if (deadCodeEnabled && element instanceof GrNamedElement && element instanceof PsiModifierListOwner && !UnusedSymbolUtil.isImplicitUsage(element.getProject(), (PsiModifierListOwner)element) && !GroovySuppressableInspectionTool.isElementToolSuppressedIn(element, GroovyUnusedDeclarationInspection.SHORT_NAME)) { PsiElement nameId = ((GrNamedElement)element).getNameIdentifierGroovy(); if (nameId.getNode().getElementType() == GroovyTokenTypes.mIDENT) { String name = ((GrNamedElement)element).getName(); if (element instanceof GrTypeDefinition && !UnusedSymbolUtil.isClassUsed(myProject, element.getContainingFile(), (GrTypeDefinition)element, progress, usageHelper )) { HighlightInfo.Builder builder = UnusedSymbolUtil .createUnusedSymbolInfoBuilder(nameId, GroovyBundle.message("text.class.0.is.unused", name), HighlightInfoType.UNUSED_SYMBOL, GroovyUnusedDeclarationInspection.SHORT_NAME); IntentionAction action = QuickFixFactory.getInstance().createSafeDeleteFix(element); builder.registerFix(action, null, HighlightDisplayKey.getDisplayNameByKey(unusedDefKey), null, unusedDefKey); ContainerUtil.addIfNotNull(unusedDeclarations, builder.create()); } else if (element instanceof GrMethod method) { if (SpockUtils.isUnusedInSpock(method, usageHelper)) { usageHelper.shouldCheckContributors = false; } try { if (!UnusedSymbolUtil.isMethodUsed(method.getProject(), method.getContainingFile(), method, progress, usageHelper)) { String message; if (method.isConstructor()) { message = GroovyBundle.message("text.constructor.0.is.unused", name); } else { message = GroovyBundle.message("text.method.0.is.unused", name); } HighlightInfo.Builder builder = UnusedSymbolUtil.createUnusedSymbolInfoBuilder(nameId, message, HighlightInfoType.UNUSED_SYMBOL, GroovyUnusedDeclarationInspection.SHORT_NAME); IntentionAction action = QuickFixFactory.getInstance().createSafeDeleteFix(method); builder.registerFix(action, null, HighlightDisplayKey.getDisplayNameByKey(unusedDefKey), null, unusedDefKey); ContainerUtil.addIfNotNull(unusedDeclarations, builder.create()); } } finally { usageHelper.shouldCheckContributors = true; } } else if (element instanceof GrField && isFieldUnused((GrField)element, progress, usageHelper)) { HighlightInfo.Builder builder = UnusedSymbolUtil.createUnusedSymbolInfoBuilder(nameId, GroovyBundle.message("text.property.0.is.unused", name), HighlightInfoType.UNUSED_SYMBOL, GroovyUnusedDeclarationInspection.SHORT_NAME); IntentionAction action = QuickFixFactory.getInstance().createSafeDeleteFix(element); builder.registerFix(action, null, HighlightDisplayKey.getDisplayNameByKey(unusedDefKey), null, unusedDefKey); ContainerUtil.addIfNotNull(unusedDeclarations, builder.create()); } else if (element instanceof GrParameter) { if (!usedParams.containsKey(element)) { usedParams.put((GrParameter)element, Boolean.FALSE); } } } } super.visitElement(element); } }); Set<GrImportStatement> unusedImports; myUnusedImports = unusedImports = unusedImports(myFile); if (deadCodeEnabled) { for (GrParameter parameter : usedParams.keySet()) { if (usedParams.get(parameter)) continue; PsiElement scope = parameter.getDeclarationScope(); if (scope instanceof GrMethod method) { if (methodMayHaveUnusedParameters(method)) { PsiElement identifier = parameter.getNameIdentifierGroovy(); HighlightInfo.Builder builder = UnusedSymbolUtil .createUnusedSymbolInfoBuilder(identifier, GroovyBundle.message("text.parameter.0.is.unused", parameter.getName()), HighlightInfoType.UNUSED_SYMBOL, GroovyUnusedDeclarationInspection.SHORT_NAME); IntentionAction action = GroovyQuickFixFactory.getInstance().createRemoveUnusedGrParameterFix(parameter); builder.registerFix(action, null, HighlightDisplayKey.getDisplayNameByKey(unusedDefKey), null, unusedDefKey); ContainerUtil.addIfNotNull(unusedDeclarations, builder.create()); } } else if (scope instanceof GrClosableBlock) { //todo Max Medvedev } } } myUnusedDeclarations = unusedDeclarations; List<HighlightInfo> infos = convertUnusedImportsToInfos(unusedDeclarations, unusedImports); BackgroundUpdateHighlightersUtil.setHighlightersToEditor(myProject, myFile, myDocument, 0, myFile.getTextLength(), infos, getId()); }