use of com.intellij.analysis.AnalysisScope in project intellij-community by JetBrains.
the class GlobalJavaInspectionContextImpl method processSearchRequests.
private void processSearchRequests(final GlobalInspectionContext context) {
final RefManager refManager = context.getRefManager();
final AnalysisScope scope = refManager.getScope();
final SearchScope searchScope = new GlobalSearchScope(refManager.getProject()) {
@Override
public boolean contains(@NotNull VirtualFile file) {
return scope != null && !scope.contains(file) || file.getFileType() != StdFileTypes.JAVA;
}
@Override
public int compare(@NotNull VirtualFile file1, @NotNull VirtualFile file2) {
return 0;
}
@Override
public boolean isSearchInModuleContent(@NotNull Module aModule) {
return true;
}
@Override
public boolean isSearchInLibraries() {
return false;
}
};
if (myDerivedClassesRequests != null) {
final List<SmartPsiElementPointer> sortedIDs = getSortedIDs(myDerivedClassesRequests);
for (SmartPsiElementPointer sortedID : sortedIDs) {
final PsiClass psiClass = (PsiClass) dereferenceInReadAction(sortedID);
if (psiClass == null)
continue;
context.incrementJobDoneAmount(context.getStdJobDescriptors().FIND_EXTERNAL_USAGES, getClassPresentableName(psiClass));
final List<DerivedClassesProcessor> processors = myDerivedClassesRequests.get(sortedID);
LOG.assertTrue(processors != null, psiClass.getClass().getName());
ClassInheritorsSearch.search(psiClass, searchScope, false).forEach(createMembersProcessor(processors, scope));
}
myDerivedClassesRequests = null;
}
if (myDerivedMethodsRequests != null) {
final List<SmartPsiElementPointer> sortedIDs = getSortedIDs(myDerivedMethodsRequests);
for (SmartPsiElementPointer sortedID : sortedIDs) {
final PsiMethod psiMethod = (PsiMethod) dereferenceInReadAction(sortedID);
if (psiMethod == null)
continue;
final RefMethod refMethod = (RefMethod) refManager.getReference(psiMethod);
context.incrementJobDoneAmount(context.getStdJobDescriptors().FIND_EXTERNAL_USAGES, refManager.getQualifiedName(refMethod));
final List<DerivedMethodsProcessor> processors = myDerivedMethodsRequests.get(sortedID);
LOG.assertTrue(processors != null, psiMethod.getClass().getName());
OverridingMethodsSearch.search(psiMethod, searchScope, true).forEach(createMembersProcessor(processors, scope));
}
myDerivedMethodsRequests = null;
}
if (myFieldUsagesRequests != null) {
final List<SmartPsiElementPointer> sortedIDs = getSortedIDs(myFieldUsagesRequests);
for (SmartPsiElementPointer sortedID : sortedIDs) {
final PsiField psiField = (PsiField) dereferenceInReadAction(sortedID);
if (psiField == null)
continue;
final List<UsagesProcessor> processors = myFieldUsagesRequests.get(sortedID);
LOG.assertTrue(processors != null, psiField.getClass().getName());
context.incrementJobDoneAmount(context.getStdJobDescriptors().FIND_EXTERNAL_USAGES, refManager.getQualifiedName(refManager.getReference(psiField)));
ReferencesSearch.search(psiField, searchScope, false).forEach(new PsiReferenceProcessorAdapter(createReferenceProcessor(processors, context)));
}
myFieldUsagesRequests = null;
}
if (myClassUsagesRequests != null) {
final List<SmartPsiElementPointer> sortedIDs = getSortedIDs(myClassUsagesRequests);
for (SmartPsiElementPointer sortedID : sortedIDs) {
final PsiClass psiClass = (PsiClass) dereferenceInReadAction(sortedID);
if (psiClass == null)
continue;
final List<UsagesProcessor> processors = myClassUsagesRequests.get(sortedID);
LOG.assertTrue(processors != null, psiClass.getClass().getName());
context.incrementJobDoneAmount(context.getStdJobDescriptors().FIND_EXTERNAL_USAGES, getClassPresentableName(psiClass));
ReferencesSearch.search(psiClass, searchScope, false).forEach(new PsiReferenceProcessorAdapter(createReferenceProcessor(processors, context)));
}
myClassUsagesRequests = null;
}
if (myMethodUsagesRequests != null) {
List<SmartPsiElementPointer> sortedIDs = getSortedIDs(myMethodUsagesRequests);
for (SmartPsiElementPointer sortedID : sortedIDs) {
final PsiMethod psiMethod = (PsiMethod) dereferenceInReadAction(sortedID);
if (psiMethod == null)
continue;
final List<UsagesProcessor> processors = myMethodUsagesRequests.get(sortedID);
LOG.assertTrue(processors != null, psiMethod.getClass().getName());
context.incrementJobDoneAmount(context.getStdJobDescriptors().FIND_EXTERNAL_USAGES, refManager.getQualifiedName(refManager.getReference(psiMethod)));
MethodReferencesSearch.search(psiMethod, searchScope, true).forEach(new PsiReferenceProcessorAdapter(createReferenceProcessor(processors, context)));
}
myMethodUsagesRequests = null;
}
}
use of com.intellij.analysis.AnalysisScope in project intellij-community by JetBrains.
the class CyclicDependenciesAction method getInspectionScope.
@Nullable
private static AnalysisScope getInspectionScope(final DataContext dataContext) {
final Project project = CommonDataKeys.PROJECT.getData(dataContext);
if (project == null)
return null;
AnalysisScope scope = getInspectionScopeImpl(dataContext);
return scope != null && scope.getScopeType() != AnalysisScope.INVALID ? scope : null;
}
use of com.intellij.analysis.AnalysisScope in project intellij-community by JetBrains.
the class CyclicDependenciesAction method actionPerformed.
public void actionPerformed(AnActionEvent e) {
DataContext dataContext = e.getDataContext();
final Project project = CommonDataKeys.PROJECT.getData(dataContext);
final Module module = LangDataKeys.MODULE.getData(dataContext);
if (project != null) {
AnalysisScope scope = getInspectionScope(dataContext);
if (scope == null || scope.getScopeType() != AnalysisScope.MODULES) {
ProjectModuleOrPackageDialog dlg = null;
if (module != null) {
dlg = new ProjectModuleOrPackageDialog(ModuleManager.getInstance(project).getModules().length == 1 ? null : ModuleUtilCore.getModuleNameInReadAction(module), scope);
if (!dlg.showAndGet()) {
return;
}
}
if (dlg == null || dlg.isProjectScopeSelected()) {
scope = getProjectScope(dataContext);
} else {
if (dlg.isModuleScopeSelected()) {
scope = getModuleScope(dataContext);
}
}
if (scope != null) {
scope.setIncludeTestSource(dlg != null && dlg.isIncludeTestSources());
}
}
FileDocumentManager.getInstance().saveAllDocuments();
new CyclicDependenciesHandler(project, scope).analyze();
}
}
use of com.intellij.analysis.AnalysisScope in project intellij-community by JetBrains.
the class CyclicDependenciesAction method getInspectionScopeImpl.
@Nullable
private static AnalysisScope getInspectionScopeImpl(DataContext dataContext) {
//Possible scopes: package, project, module.
Project projectContext = PlatformDataKeys.PROJECT_CONTEXT.getData(dataContext);
if (projectContext != null) {
return null;
}
Module moduleContext = LangDataKeys.MODULE_CONTEXT.getData(dataContext);
if (moduleContext != null) {
return null;
}
final Module[] modulesArray = LangDataKeys.MODULE_CONTEXT_ARRAY.getData(dataContext);
if (modulesArray != null && modulesArray.length > 0) {
return new AnalysisScope(modulesArray);
}
PsiElement psiTarget = CommonDataKeys.PSI_ELEMENT.getData(dataContext);
if (psiTarget instanceof PsiDirectory) {
PsiDirectory psiDirectory = (PsiDirectory) psiTarget;
if (!psiDirectory.getManager().isInProject(psiDirectory))
return null;
return new AnalysisScope(psiDirectory);
} else if (psiTarget instanceof PsiPackage) {
PsiPackage pack = (PsiPackage) psiTarget;
PsiDirectory[] dirs = pack.getDirectories(GlobalSearchScope.projectScope(pack.getProject()));
if (dirs.length == 0)
return null;
return new JavaAnalysisScope(pack, LangDataKeys.MODULE.getData(dataContext));
}
return null;
}
use of com.intellij.analysis.AnalysisScope in project intellij-community by JetBrains.
the class UsageContextDataflowToPanel method createParams.
@NotNull
private static SliceAnalysisParams createParams(PsiElement element, boolean dataFlowToThis) {
SliceAnalysisParams params = new SliceAnalysisParams();
params.scope = new AnalysisScope(element.getProject());
params.dataFlowToThis = dataFlowToThis;
params.showInstanceDereferences = true;
return params;
}
Aggregations