Search in sources :

Example 1 with PsiShortNamesCache

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;
}
Also used : GrMethodCall(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall) ArrayList(java.util.ArrayList) GrReferenceExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression) PsiShortNamesCache(com.intellij.psi.search.PsiShortNamesCache) GrArgumentList(org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) PsiProximityComparator(com.intellij.psi.util.proximity.PsiProximityComparator) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with PsiShortNamesCache

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);
    }
}
Also used : Project(com.intellij.openapi.project.Project) PsiShortNamesCache(com.intellij.psi.search.PsiShortNamesCache) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) QualifiedName(com.intellij.psi.util.QualifiedName) PsiClass(com.intellij.psi.PsiClass) Module(com.intellij.openapi.module.Module) PsiElement(com.intellij.psi.PsiElement)

Example 3 with PsiShortNamesCache

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;
}
Also used : PsiShortNamesCache(com.intellij.psi.search.PsiShortNamesCache) Matcher(java.util.regex.Matcher)

Example 4 with PsiShortNamesCache

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;
}
Also used : Pattern(java.util.regex.Pattern) PsiShortNamesCache(com.intellij.psi.search.PsiShortNamesCache) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) PsiClass(com.intellij.psi.PsiClass) HashSet(com.intellij.util.containers.HashSet)

Example 5 with PsiShortNamesCache

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;
}
Also used : PsiShortNamesCache(com.intellij.psi.search.PsiShortNamesCache) PsiMethod(com.intellij.psi.PsiMethod) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

PsiShortNamesCache (com.intellij.psi.search.PsiShortNamesCache)30 NotNull (org.jetbrains.annotations.NotNull)20 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)11 Project (com.intellij.openapi.project.Project)6 PsiClass (com.intellij.psi.PsiClass)5 ArrayList (java.util.ArrayList)4 Nullable (org.jetbrains.annotations.Nullable)4 com.intellij.psi (com.intellij.psi)3 Processor (com.intellij.util.Processor)3 HashSet (com.intellij.util.containers.HashSet)3 Module (com.intellij.openapi.module.Module)2 PsiField (com.intellij.psi.PsiField)2 PsiMethod (com.intellij.psi.PsiMethod)2 THashSet (gnu.trove.THashSet)2 List (java.util.List)2 Matcher (java.util.regex.Matcher)2 Pattern (java.util.regex.Pattern)2 HighlightInfo (com.intellij.codeInsight.daemon.impl.HighlightInfo)1 NodeIterator (com.intellij.dupLocator.iterators.NodeIterator)1 DefaultPsiElementCellRenderer (com.intellij.ide.util.DefaultPsiElementCellRenderer)1