void (@NotNull GroovyFile file) { Set<GrTypeDefinition> classesWithUnresolvedRef = new HashSet<>(); Set<GrMethod> methodsWithUnresolvedRef = new HashSet<>(); VisitorCallback callback = (element, info) -> { GrMethod containingMethod = PsiTreeUtil.getParentOfType(element, GrMethod.class); if (containingMethod != null) { methodsWithUnresolvedRef.add(containingMethod); return; } GrTypeDefinition containingClass = PsiTreeUtil.getParentOfType(element, GrTypeDefinition.class); if (containingClass != null) classesWithUnresolvedRef.add(containingClass); }; file.accept(new DynamicFeaturesVisitor(file, myProject, callback)); file.accept(new GroovyRecursiveElementVisitor() { @Override public void visitTypeDefinition(@NotNull GrTypeDefinition typeDef) { processDefinitions(typeDef, classesWithUnresolvedRef); super.visitTypeDefinition(typeDef); } @Override public void visitMethod(@NotNull GrMethod method) { processMethods(method, methodsWithUnresolvedRef); super.visitMethod(method); } }); }