RefactoringElementListener (PsiElement element, RunConfigurationBase configuration, RefactoringElementListener listener) { if (!isApplicableFor(configuration)) { return listener; } final JavaCoverageEnabledConfiguration coverageEnabledConfiguration = JavaCoverageEnabledConfiguration.getFrom(configuration); if (coverageEnabledConfiguration != null) { final Project project = configuration.getProject(); final ClassFilter[] patterns = coverageEnabledConfiguration.getCoveragePatterns(); final String[] filters = getFilters(coverageEnabledConfiguration); if (patterns != null) { assert filters != null; if (element instanceof PsiClass) { final String qualifiedName = ((PsiClass)element).getQualifiedName(); final int idx = ArrayUtil.find(filters, qualifiedName); if (idx > -1) { final RefactoringListeners.Accessor<PsiClass> accessor = new MyClassAccessor(project, patterns, idx, filters); final RefactoringElementListener classListener = RefactoringListeners.getClassOrPackageListener(element, accessor); if (classListener != null) { listener = appendListener(listener, classListener); } } else if (qualifiedName != null){ final String packageName = StringUtil.getPackageName(qualifiedName); if (!StringUtil.isEmpty(packageName)) { int i = ArrayUtil.indexOf(filters, packageName + ".*"); if (i != -1) { listener = appendListener(listener, new RefactoringListeners.RefactorPackageByClass(new MyClassAccessor(project, patterns, i, filters))); } } } } else if (element instanceof PsiPackage) { final String qualifiedName = ((PsiPackage)element).getQualifiedName(); for (int i = 0, filtersLength = filters.length; i < filtersLength; i++) { if (filters[i].startsWith(qualifiedName + ".")) { final RefactoringElementListener packageListener; if (filters[i].endsWith("*")) { packageListener = RefactoringListeners.getListener((PsiPackage)element, new MyPackageAccessor(project, patterns, i, filters)); } else { packageListener = RefactoringListeners.getClassOrPackageListener(element, new MyClassAccessor(project, patterns, i, filters)); } if (packageListener != null) { listener = appendListener(listener, packageListener); } } } } } } return listener; }