use of com.intellij.psi.search.PsiShortNamesCache in project intellij-community by JetBrains.
the class GroovyStaticImportMethodFix method getMethodsToImport.
@NotNull
private List<PsiMethod> getMethodsToImport() {
PsiShortNamesCache cache = PsiShortNamesCache.getInstance(myMethodCall.getProject());
GrMethodCall element = myMethodCall.getElement();
LOG.assertTrue(element != null);
GrReferenceExpression reference = getMethodExpression(element);
LOG.assertTrue(reference != null);
GrArgumentList argumentList = element.getArgumentList();
String name = reference.getReferenceName();
ArrayList<PsiMethod> list = new ArrayList<>();
if (name == null)
return list;
GlobalSearchScope scope = element.getResolveScope();
PsiMethod[] methods = cache.getMethodsByNameIfNotMoreThan(name, scope, 20);
List<PsiMethod> applicableList = new ArrayList<>();
for (PsiMethod method : methods) {
ProgressManager.checkCanceled();
if (JavaCompletionUtil.isInExcludedPackage(method, false))
continue;
if (!method.hasModifierProperty(PsiModifier.STATIC))
continue;
PsiFile file = method.getContainingFile();
if (file instanceof PsiClassOwner && //do not show methods from default package
!((PsiClassOwner) file).getPackageName().isEmpty() && PsiUtil.isAccessible(element, method)) {
list.add(method);
if (PsiUtil.isApplicable(PsiUtil.getArgumentTypes(element, true), method, PsiSubstitutor.EMPTY, element, false)) {
applicableList.add(method);
}
}
}
List<PsiMethod> result = applicableList.isEmpty() ? list : applicableList;
Collections.sort(result, new PsiProximityComparator(argumentList));
return result;
}
use of com.intellij.psi.search.PsiShortNamesCache in project intellij-community by JetBrains.
the class PyJavaImportCandidateProvider method addImportCandidates.
@Override
public void addImportCandidates(PsiReference reference, String name, AutoImportQuickFix quickFix) {
final PsiElement element = reference.getElement();
final Project project = element.getProject();
Module module = ModuleUtil.findModuleForPsiElement(element);
GlobalSearchScope scope = module == null ? ProjectScope.getAllScope(project) : module.getModuleWithDependenciesAndLibrariesScope(false);
PsiShortNamesCache cache = PsiShortNamesCache.getInstance(project);
final PsiClass[] classesByName = cache.getClassesByName(name, scope);
for (PsiClass psiClass : classesByName) {
final String qualifiedName = psiClass.getQualifiedName();
if (qualifiedName == null) {
continue;
}
final QualifiedName packageQName = QualifiedName.fromDottedString(qualifiedName).removeLastComponent();
quickFix.addImport(psiClass, psiClass.getContainingFile(), packageQName);
}
}
use of com.intellij.psi.search.PsiShortNamesCache in project intellij-community by JetBrains.
the class YourkitFilter method applyFilter.
public Result applyFilter(final String line, final int entireLength) {
if (!line.endsWith(".java\n")) {
return null;
}
try {
final Matcher matcher = PATTERN.matcher(line);
if (matcher.matches()) {
final String method = matcher.group(1);
final int lineNumber = Integer.parseInt(matcher.group(2));
final String fileName = matcher.group(3);
final int textStartOffset = entireLength - line.length();
final PsiShortNamesCache cache = PsiShortNamesCache.getInstance(myProject);
final PsiFile[] psiFiles = cache.getFilesByName(fileName);
if (psiFiles.length == 0)
return null;
final HyperlinkInfo info = psiFiles.length == 1 ? new OpenFileHyperlinkInfo(myProject, psiFiles[0].getVirtualFile(), lineNumber - 1) : new MyHyperlinkInfo(psiFiles);
return new Result(textStartOffset + matcher.start(2), textStartOffset + matcher.end(3), info);
}
} catch (NumberFormatException e) {
LOG.debug(e);
}
return null;
}
use of com.intellij.psi.search.PsiShortNamesCache in project intellij-community by JetBrains.
the class JavaTestFinder method collectTests.
private boolean collectTests(PsiClass klass, Processor<Pair<? extends PsiNamedElement, Integer>> processor) {
GlobalSearchScope scope = getSearchScope(klass, false);
PsiShortNamesCache cache = PsiShortNamesCache.getInstance(klass.getProject());
String klassName = klass.getName();
Pattern pattern = Pattern.compile(".*" + StringUtil.escapeToRegexp(klassName) + ".*", Pattern.CASE_INSENSITIVE);
HashSet<String> names = new HashSet<>();
cache.getAllClassNames(names);
for (String eachName : names) {
if (pattern.matcher(eachName).matches()) {
for (PsiClass eachClass : cache.getClassesByName(eachName, scope)) {
if (isTestClass(eachClass, klass)) {
if (!processor.process(Pair.create(eachClass, TestFinderHelper.calcTestNameProximity(klassName, eachName)))) {
return true;
}
}
}
}
}
return false;
}
use of com.intellij.psi.search.PsiShortNamesCache in project intellij-community by JetBrains.
the class CompositeShortNamesCache method getMethodsByName.
@Override
@NotNull
public PsiMethod[] getMethodsByName(@NotNull String name, @NotNull GlobalSearchScope scope) {
Merger<PsiMethod> merger = null;
for (PsiShortNamesCache cache : myCaches) {
PsiMethod[] methods = cache.getMethodsByName(name, scope);
if (methods.length != 0) {
if (merger == null)
merger = new Merger<>();
merger.add(methods);
}
}
PsiMethod[] result = merger == null ? null : merger.getResult();
return result == null ? PsiMethod.EMPTY_ARRAY : result;
}
Aggregations