use of com.intellij.psi.search.GlobalSearchScope in project intellij-community by JetBrains.
the class CouplingVisitor method addDependency.
private void addDependency(PsiType type) {
if (type == null) {
return;
}
final PsiType baseType = type.getDeepComponentType();
if (ClassUtils.isPrimitive(type)) {
return;
}
final String qualifiedName = m_class.getQualifiedName();
if (qualifiedName == null) {
return;
}
if (baseType.equalsToText(qualifiedName)) {
return;
}
final String baseTypeName = baseType.getCanonicalText();
@NonNls final String javaPrefix = "java.";
@NonNls final String javaxPrefix = "javax.";
if (!m_includeJavaClasses && (baseTypeName.startsWith(javaPrefix) || baseTypeName.startsWith(javaxPrefix))) {
return;
}
if (!m_includeLibraryClasses) {
final Project project = m_class.getProject();
final GlobalSearchScope searchScope = GlobalSearchScope.allScope(project);
final PsiClass aClass = JavaPsiFacade.getInstance(project).findClass(baseTypeName, searchScope);
if (aClass == null) {
return;
}
if (LibraryUtil.classIsInLibrary(aClass)) {
return;
}
}
if (StringUtil.startsWithConcatenation(baseTypeName, qualifiedName, ".")) {
return;
}
m_dependencies.add(baseTypeName);
}
use of com.intellij.psi.search.GlobalSearchScope in project intellij-community by JetBrains.
the class JavaCoverageViewExtension method createTopLevelNodes.
@Override
public List<AbstractTreeNode> createTopLevelNodes() {
final List<AbstractTreeNode> topLevelNodes = new ArrayList<>();
final LinkedHashSet<PsiPackage> packages = new LinkedHashSet<>();
final LinkedHashSet<PsiClass> classes = new LinkedHashSet<>();
for (CoverageSuite suite : mySuitesBundle.getSuites()) {
packages.addAll(((JavaCoverageSuite) suite).getCurrentSuitePackages(myProject));
classes.addAll(((JavaCoverageSuite) suite).getCurrentSuiteClasses(myProject));
}
final Set<PsiPackage> packs = new HashSet<>();
for (PsiPackage aPackage : packages) {
final String qualifiedName = aPackage.getQualifiedName();
for (PsiPackage psiPackage : packages) {
if (psiPackage.getQualifiedName().startsWith(qualifiedName + ".")) {
packs.add(psiPackage);
break;
}
}
}
packages.removeAll(packs);
for (PsiPackage aPackage : packages) {
final GlobalSearchScope searchScope = mySuitesBundle.getSearchScope(myProject);
if (aPackage.getClasses(searchScope).length != 0) {
final CoverageListNode node = new CoverageListNode(myProject, aPackage, mySuitesBundle, myStateBean);
topLevelNodes.add(node);
}
collectSubPackages(topLevelNodes, aPackage);
}
for (PsiClass aClass : classes) {
topLevelNodes.add(new CoverageListNode(myProject, aClass, mySuitesBundle, myStateBean));
}
return topLevelNodes;
}
use of com.intellij.psi.search.GlobalSearchScope in project intellij-community by JetBrains.
the class CoverageProjectViewClassNodeDecorator method decorate.
public void decorate(ProjectViewNode node, PresentationData data) {
final CoverageDataManager coverageDataManager = getCoverageDataManager();
final CoverageSuitesBundle currentSuite = coverageDataManager.getCurrentSuitesBundle();
final Project project = node.getProject();
final JavaCoverageAnnotator javaCovAnnotator = getCovAnnotator(currentSuite, project);
// This decorator is applicable only to JavaCoverageAnnotator
if (javaCovAnnotator == null) {
return;
}
final Object value = node.getValue();
PsiElement element = null;
if (value instanceof PsiElement) {
element = (PsiElement) value;
} else if (value instanceof SmartPsiElementPointer) {
element = ((SmartPsiElementPointer) value).getElement();
} else if (value instanceof PackageElement) {
PackageElement packageElement = (PackageElement) value;
final String coverageString = javaCovAnnotator.getPackageCoverageInformationString(packageElement.getPackage(), packageElement.getModule(), coverageDataManager);
data.setLocationString(coverageString);
}
if (element instanceof PsiClass) {
final GlobalSearchScope searchScope = currentSuite.getSearchScope(project);
final VirtualFile vFile = PsiUtilCore.getVirtualFile(element);
if (vFile != null && searchScope.contains(vFile)) {
final String qName = ((PsiClass) element).getQualifiedName();
if (qName != null) {
data.setLocationString(javaCovAnnotator.getClassCoverageInformationString(qName, coverageDataManager));
}
}
}
}
use of com.intellij.psi.search.GlobalSearchScope in project intellij-community by JetBrains.
the class JavaCoverageEngine method findTestsByNames.
@NotNull
public List<PsiElement> findTestsByNames(@NotNull String[] testNames, @NotNull Project project) {
final List<PsiElement> elements = new ArrayList<>();
final JavaPsiFacade facade = JavaPsiFacade.getInstance(project);
final GlobalSearchScope projectScope = GlobalSearchScope.projectScope(project);
for (String testName : testNames) {
PsiClass psiClass = facade.findClass(StringUtil.getPackageName(testName, '_').replaceAll("\\_", "\\."), projectScope);
int lastIdx = testName.lastIndexOf("_");
if (psiClass != null) {
collectTestsByName(elements, testName, psiClass, lastIdx);
} else {
String className = testName;
while (lastIdx > 0) {
className = className.substring(0, lastIdx - 1);
psiClass = facade.findClass(StringUtil.getPackageName(className, '_').replaceAll("\\_", "\\."), projectScope);
lastIdx = className.lastIndexOf("_");
if (psiClass != null) {
collectTestsByName(elements, testName, psiClass, lastIdx);
break;
}
}
}
}
return elements;
}
use of com.intellij.psi.search.GlobalSearchScope in project intellij-community by JetBrains.
the class LanguageResolvingUtil method collectLanguageDefinitions.
private static List<LanguageDefinition> collectLanguageDefinitions(final ConvertContext context) {
final Project project = context.getProject();
final Collection<PsiClass> allLanguages = CachedValuesManager.getManager(project).getCachedValue(project, () -> {
final PsiClass languageClass = JavaPsiFacade.getInstance(project).findClass(Language.class.getName(), GlobalSearchScope.allScope(project));
if (languageClass == null) {
return Result.create(Collections.emptyList(), PsiModificationTracker.JAVA_STRUCTURE_MODIFICATION_COUNT);
}
final GlobalSearchScope projectProductionScope = GlobalSearchScopesCore.projectProductionScope(project);
GlobalSearchScope allScope = projectProductionScope.union(ProjectScope.getLibrariesScope(project));
final Collection<PsiClass> allInheritors = ClassInheritorsSearch.search(languageClass, allScope, true).findAll();
return Result.create(allInheritors, PsiModificationTracker.JAVA_STRUCTURE_MODIFICATION_COUNT);
});
if (allLanguages.isEmpty()) {
return Collections.emptyList();
}
final List<LanguageDefinition> libraryDefinitions = collectLibraryLanguages(context, allLanguages);
final GlobalSearchScope projectProductionScope = GlobalSearchScopesCore.projectProductionScope(project);
final Collection<PsiClass> projectLanguages = ContainerUtil.filter(allLanguages, aClass -> PsiSearchScopeUtil.isInScope(projectProductionScope, aClass));
final List<LanguageDefinition> projectDefinitions = collectProjectLanguages(projectLanguages, libraryDefinitions);
final List<LanguageDefinition> all = ContainerUtil.newArrayList(libraryDefinitions);
all.addAll(projectDefinitions);
return all;
}
Aggregations