Search in sources :

Example 1 with PsiPackageImpl

use of com.intellij.psi.impl.file.PsiPackageImpl in project intellij-community by JetBrains.

the class PackagePrefixElementFinder method getSubPackages.

@NotNull
@Override
public PsiPackage[] getSubPackages(@NotNull PsiPackage psiPackage, @NotNull GlobalSearchScope scope) {
    final Map<String, PsiPackage> packagesMap = new HashMap<>();
    final String qualifiedName = psiPackage.getQualifiedName();
    for (final String prefix : myPackagePrefixIndex.getAllPackagePrefixes(scope)) {
        if (StringUtil.isEmpty(qualifiedName) || StringUtil.startsWithConcatenation(prefix, qualifiedName, ".")) {
            final int i = prefix.indexOf('.', qualifiedName.length() + 1);
            String childName = i >= 0 ? prefix.substring(0, i) : prefix;
            if (!packagesMap.containsKey(childName)) {
                packagesMap.put(childName, new PsiPackageImpl(psiPackage.getManager(), childName));
            }
        }
    }
    // avoid SOE caused by returning a package as a subpackage of itself
    packagesMap.remove(qualifiedName);
    return packagesMap.values().toArray(new PsiPackage[packagesMap.size()]);
}
Also used : HashMap(com.intellij.util.containers.HashMap) PsiPackageImpl(com.intellij.psi.impl.file.PsiPackageImpl) PsiPackage(com.intellij.psi.PsiPackage) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with PsiPackageImpl

use of com.intellij.psi.impl.file.PsiPackageImpl in project android by JetBrains.

the class DataBindingProjectComponent method getOrCreateDataBindingPsiPackage.

/**
   * Returns a {@linkplain PsiPackage} instance for the given package name.
   * <p>
   * If it does not exist in the cache, a new one is created.
   *
   * @param packageName The qualified package name
   * @return A {@linkplain PsiPackage} that represents the given qualified name
   */
public synchronized PsiPackage getOrCreateDataBindingPsiPackage(String packageName) {
    PsiPackage pkg = myDataBindingPsiPackages.get(packageName);
    if (pkg == null) {
        pkg = new PsiPackageImpl(PsiManager.getInstance(myProject), packageName) {

            @Override
            public boolean isValid() {
                return true;
            }
        };
        myDataBindingPsiPackages.put(packageName, pkg);
    }
    return pkg;
}
Also used : PsiPackageImpl(com.intellij.psi.impl.file.PsiPackageImpl) PsiPackage(com.intellij.psi.PsiPackage)

Aggregations

PsiPackage (com.intellij.psi.PsiPackage)2 PsiPackageImpl (com.intellij.psi.impl.file.PsiPackageImpl)2 HashMap (com.intellij.util.containers.HashMap)1 NotNull (org.jetbrains.annotations.NotNull)1