Reuse util method

This commit is contained in:
Alexander Zolotov
2015-10-15 02:44:18 +03:00
parent e95b0057b2
commit de80a43a26
6 changed files with 18 additions and 61 deletions
@@ -283,7 +283,7 @@ public class AnalysisScope {
if (file.isDirectory()) return true;
if (ProjectCoreUtil.isProjectOrWorkspaceFile(file)) return true;
if (fileIndex.isInContent(file) && (myIncludeTestSource || !fileIndex.isInTestSourceContent(file))
&& !isInGeneratedSources(file, myProject)) {
&& !GeneratedSourcesFilter.isGeneratedSourceByAnyFilter(file, myProject)) {
return processFile(file, visitor, psiManager, needReadAction, clearResolveCache);
}
return true;
@@ -310,7 +310,7 @@ public class AnalysisScope {
@Override
public Boolean compute() {
if (!myIncludeTestSource && projectFileIndex.isInTestSourceContent(fileOrDir)) return false;
if (isInGeneratedSources(fileOrDir, myProject)) return false;
if (GeneratedSourcesFilter.isGeneratedSourceByAnyFilter(fileOrDir, myProject)) return false;
return ((GlobalSearchScope)myScope).contains(fileOrDir);
}
}).booleanValue();
@@ -342,7 +342,7 @@ public class AnalysisScope {
}
return true;
}
List<Module> modules = myModule != null ? Collections.<Module>singletonList(myModule) : myModules;
List<Module> modules = myModule != null ? Collections.singletonList(myModule) : myModules;
if (modules != null) {
for (final Module module : modules) {
final FileIndex moduleFileIndex = ModuleRootManager.getInstance(module).getFileIndex();
@@ -377,15 +377,6 @@ public class AnalysisScope {
});
}
private static boolean isInGeneratedSources(@NotNull VirtualFile file, @NotNull Project project) {
for (GeneratedSourcesFilter filter : GeneratedSourcesFilter.EP_NAME.getExtensions()) {
if (filter.isGeneratedSource(file, project)) {
return true;
}
}
return false;
}
private static boolean processFile(@NotNull final VirtualFile vFile,
@NotNull final PsiElementVisitor visitor,
@NotNull final PsiManager psiManager,
@@ -460,13 +451,13 @@ public class AnalysisScope {
final Project project = dir.getProject();
final ProjectFileIndex index = ProjectRootManager.getInstance(project).getFileIndex();
//we should analyze generated source files only if the action is explicitly invoked for a directory located under generated roots
final boolean processGeneratedFiles = isInGeneratedSources(dir.getVirtualFile(), project);
final boolean processGeneratedFiles = GeneratedSourcesFilter.isGeneratedSourceByAnyFilter(dir.getVirtualFile(), project);
return VfsUtilCore.iterateChildrenRecursively(dir.getVirtualFile(), VirtualFileFilter.ALL, new ContentIterator() {
@Override
@SuppressWarnings({"SimplifiableIfStatement"})
public boolean processFile(@NotNull final VirtualFile fileOrDir) {
if (!myIncludeTestSource && index.isInTestSourceContent(fileOrDir)) return true;
if (!processGeneratedFiles && isInGeneratedSources(fileOrDir, project)) return true;
if (!processGeneratedFiles && GeneratedSourcesFilter.isGeneratedSourceByAnyFilter(fileOrDir, project)) return true;
if (!fileOrDir.isDirectory()) {
return processor.process(fileOrDir);
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -412,12 +412,7 @@ public abstract class AbstractLayoutCodeProcessor {
if (ProjectCoreUtil.isProjectOrWorkspaceFile(virtualFile)) return false;
for (GeneratedSourcesFilter filter : GeneratedSourcesFilter.EP_NAME.getExtensions()) {
if (filter.isGeneratedSource(virtualFile, file.getProject())) {
return false;
}
}
return true;
return !GeneratedSourcesFilter.isGeneratedSourceByAnyFilter(virtualFile, file.getProject());
}
private void runLayoutCodeProcess(final Runnable readAction, final Runnable writeAction, final boolean globalAction) {
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -28,11 +28,6 @@ public class GeneratedSourcesHighlightingSettingProvider extends DefaultHighligh
@Nullable
@Override
public FileHighlightingSetting getDefaultSetting(@NotNull Project project, @NotNull VirtualFile file) {
for (GeneratedSourcesFilter filter : GeneratedSourcesFilter.EP_NAME.getExtensions()) {
if (filter.isGeneratedSource(file, project)) {
return FileHighlightingSetting.SKIP_INSPECTION;
}
}
return null;
return GeneratedSourcesFilter.isGeneratedSourceByAnyFilter(file, project) ? FileHighlightingSetting.SKIP_INSPECTION : null;
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -32,7 +32,6 @@ import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.ui.EditorNotifications;
import com.intellij.util.Alarm;
import com.intellij.util.messages.MessageBusConnection;
import com.intellij.util.messages.Topic;
import com.intellij.util.ui.update.MergingUpdateQueue;
import com.intellij.util.ui.update.Update;
import org.jetbrains.annotations.NotNull;
@@ -122,7 +121,7 @@ public class GeneratedSourceFileChangeTrackerImpl extends GeneratedSourceFileCha
protected void run(final @NotNull Result result) {
if (myProject.isDisposed()) return;
for (VirtualFile file : files) {
if (isGenerated(file)) {
if (GeneratedSourcesFilter.isGeneratedSourceByAnyFilter(file, myProject)) {
newEditedGeneratedFiles.add(file);
}
}
@@ -134,13 +133,4 @@ public class GeneratedSourceFileChangeTrackerImpl extends GeneratedSourceFileCha
myEditorNotifications.updateAllNotifications();
}
}
private boolean isGenerated(VirtualFile file) {
for (GeneratedSourcesFilter filter : GeneratedSourcesFilter.EP_NAME.getExtensions()) {
if (filter.isGeneratedSource(file, myProject)) {
return true;
}
}
return false;
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -40,7 +40,6 @@ class UsageHolder {
Project project = element.getProject();
myElementPointer = SmartPointerManager.getInstance(project).createSmartPsiElementPointer(element);
GeneratedSourcesFilter[] filters = GeneratedSourcesFilter.EP_NAME.getExtensions();
for (UsageInfo usageInfo : usageInfos) {
if (!(usageInfo instanceof SafeDeleteReferenceUsageInfo)) continue;
final SafeDeleteReferenceUsageInfo usage = (SafeDeleteReferenceUsageInfo)usageInfo;
@@ -48,23 +47,16 @@ class UsageHolder {
if (!usage.isSafeDelete()) {
myUnsafeUsages++;
if (usage.isNonCodeUsage || isInGeneratedCode(usage, project, filters)) {
if (usage.isNonCodeUsage || isInGeneratedCode(usage, project)) {
myNonCodeUnsafeUsages++;
}
}
}
}
private static boolean isInGeneratedCode(SafeDeleteReferenceUsageInfo usage, Project project, GeneratedSourcesFilter[] filters) {
private static boolean isInGeneratedCode(SafeDeleteReferenceUsageInfo usage, Project project) {
VirtualFile file = usage.getVirtualFile();
if (file == null) return false;
for (GeneratedSourcesFilter filter : filters) {
if (filter.isGeneratedSource(file, project)) {
return true;
}
}
return false;
return file != null && GeneratedSourcesFilter.isGeneratedSourceByAnyFilter(file, project);
}
@NotNull
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -34,12 +34,10 @@ import org.jetbrains.annotations.NotNull;
* @author max
*/
public class NonCodeUsageGroupingRule implements UsageGroupingRule {
private final GeneratedSourcesFilter[] myGeneratedSourcesFilters;
private final Project myProject;
public NonCodeUsageGroupingRule(Project project) {
myProject = project;
myGeneratedSourcesFilters = GeneratedSourcesFilter.EP_NAME.getExtensions();
}
private static class CodeUsageGroup extends UsageGroupBase {
@@ -132,12 +130,8 @@ public class NonCodeUsageGroupingRule implements UsageGroupingRule {
public UsageGroup groupUsage(@NotNull Usage usage) {
if (usage instanceof UsageInFile) {
VirtualFile file = ((UsageInFile)usage).getFile();
if (file != null) {
for (GeneratedSourcesFilter filter : myGeneratedSourcesFilters) {
if (filter.isGeneratedSource(file, myProject)) {
return UsageInGeneratedCodeGroup.INSTANCE;
}
}
if (file != null && GeneratedSourcesFilter.isGeneratedSourceByAnyFilter(file, myProject)) {
return UsageInGeneratedCodeGroup.INSTANCE;
}
}
if (usage instanceof PsiElementUsage) {