Java 类com.intellij.psi.impl.file.PsiPackageImpl 实例源码

项目:intellij-ce-playground    文件:PackagePrefixElementFinder.java   
@NotNull
@Override
public PsiPackage[] getSubPackages(@NotNull PsiPackage psiPackage, @NotNull GlobalSearchScope scope) {
  final Map<String, PsiPackage> packagesMap = new HashMap<String, PsiPackage>();
  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));
      }
    }
  }

  packagesMap.remove(qualifiedName);    // avoid SOE caused by returning a package as a subpackage of itself
  return packagesMap.values().toArray(new PsiPackage[packagesMap.size()]);
}
项目:tools-idea    文件:PackagePrefixElementFinder.java   
@NotNull
@Override
public PsiPackage[] getSubPackages(@NotNull PsiPackage psiPackage, @NotNull GlobalSearchScope scope) {
  final Map<String, PsiPackage> packagesMap = new HashMap<String, PsiPackage>();
  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((PsiManagerEx)psiPackage.getManager(), childName));
      }
    }
  }

  packagesMap.remove(qualifiedName);    // avoid SOE caused by returning a package as a subpackage of itself
  return packagesMap.values().toArray(new PsiPackage[packagesMap.size()]);
}
项目:consulo-ikvm    文件:IkvmPsiElementFinder.java   
@Nullable
@Override
@RequiredReadAction
public PsiJavaPackage findPackage(@NotNull String qualifiedName)
{
    if(qualifiedName.equals("cli"))
    {
        return new PsiPackageImpl(myPsiManager, myPsiPackageManager, JavaModuleExtension.class, qualifiedName);
    }
    if(qualifiedName.startsWith("cli."))
    {
        PsiPackage aPackage = PsiPackageManager.getInstance(myProject).findPackage(qualifiedName.substring(4, qualifiedName.length()),
                JavaModuleExtension.class);
        if(aPackage != null)
        {
            return new PsiPackageImpl(myPsiManager, myPsiPackageManager, JavaModuleExtension.class, qualifiedName);
        }
    }

    return super.findPackage(qualifiedName);
}
项目:neovim-intellij-complete    文件:NeovimIntellijComplete.java   
@NeovimHandler("IntellijComplete")
public DeopleteItem[] intellijComplete(final String path, final String bufferContents,
                                       final int row, final int col) {

    LookupElement[] c = mEmbeditorRequestHandler.getCompletionVariants(path, bufferContents, row, col);
    if (c.length < 0) return null;
    DeopleteHelper dh = new DeopleteHelper();
        UIUtil.invokeAndWaitIfNeeded((Runnable) () -> {
                for (LookupElement i : c) {
                    if (i instanceof PsiPackage
                            || i instanceof LookupElementBuilder
                            || i.getPsiElement() instanceof PsiPackageImpl) {
                        dh.add(i.getLookupString(), "", "");
                        continue;
                    }
                    String word = i.getLookupString();
                    List<String> params = new ArrayList<String>();
                    String info;
                    String kind = "";
                    PsiElement psiElement = i.getPsiElement();
                    if (psiElement == null) {
                        dh.add(word, "", "");
                        continue;
                    }
                    for (PsiElement e : psiElement.getChildren()) {
                        if (e instanceof PsiParameterList) {
                            for (PsiParameter param : ((PsiParameterList)e).getParameters()) {
                                params.add(param.getTypeElement().getText() + " " + param.getName());
                            }
                        } else if (e instanceof PsiTypeElement) {
                            kind = e.getText();
                        }
                    }

                    info = "(" + String.join(", ", params) + ")";
                    dh.add(word, info, kind);
                }
        });
    return dh.getItems();
}
项目:intellij-ce-playground    文件:JavaFileManagerImpl.java   
@Override
@Nullable
public PsiPackage findPackage(@NotNull String packageName) {
  Query<VirtualFile> dirs = myPackageIndex.getDirsByPackageName(packageName, true);
  if (dirs.findFirst() == null) return null;
  return new PsiPackageImpl(myManager, packageName);
}
项目:intellij-ce-playground    文件:CoreJavaFileManager.java   
@Override
public PsiPackage findPackage(@NotNull String packageName) {
  final List<VirtualFile> files = findDirectoriesByPackageName(packageName);
  if (!files.isEmpty()) {
    return new PsiPackageImpl(myPsiManager, packageName);
  }
  return null;
}
项目:intellij-ce-playground    文件:CoreJavaFileManager.java   
@Nullable
public PsiPackage getPackage(PsiDirectory dir) {
  final VirtualFile file = dir.getVirtualFile();
  for (VirtualFile root : myClasspath) {
    if (VfsUtilCore.isAncestor(root, file, false)) {
      String relativePath = FileUtil.getRelativePath(root.getPath(), file.getPath(), '/');
      if (relativePath == null) continue;
      return new PsiPackageImpl(myPsiManager, relativePath.replace('/', '.'));
    }
  }
  return null;
}
项目:intellij-ce-playground    文件:PackagePrefixElementFinder.java   
@Override
public PsiPackage findPackage(@NotNull String qualifiedName) {
  if (packagePrefixExists(qualifiedName)) {
    return new PsiPackageImpl(PsiManager.getInstance(myProject), qualifiedName);
  }
  return null;
}
项目:intellij    文件:BlazeAndroidProjectPathsTest.java   
private void mockPsiPackage(Container applicationServices, Container projectServices) {
  projectServices.register(PsiManager.class, mock(PsiManager.class));
  applicationServices.register(JavaDirectoryService.class, mock(JavaDirectoryService.class));
  PsiManager manager = PsiManager.getInstance(project);
  PsiDirectory targetPsiDirectory = mock(PsiDirectory.class);
  PsiPackage targetPsiPackage = new PsiPackageImpl(manager, "com.google.target");
  when(PsiManager.getInstance(project).findDirectory(target)).thenReturn(targetPsiDirectory);
  when(JavaDirectoryService.getInstance().getPackage(targetPsiDirectory))
      .thenReturn(targetPsiPackage);
}
项目:tools-idea    文件:JavaFileManagerBase.java   
@Override
@Nullable
public PsiPackage findPackage(@NotNull String packageName) {
  Query<VirtualFile> dirs = myPackageIndex.getDirsByPackageName(packageName, true);
  if (dirs.findFirst() == null) return null;
  return new PsiPackageImpl(myManager, packageName);
}
项目:tools-idea    文件:CoreJavaFileManager.java   
@Override
public PsiPackage findPackage(@NotNull String packageName) {
  final List<VirtualFile> files = findDirectoriesByPackageName(packageName);
  if (files.size() > 0) {
    return new PsiPackageImpl(myPsiManager, packageName);
  }
  return null;
}
项目:tools-idea    文件:CoreJavaFileManager.java   
@Nullable
public PsiPackage getPackage(PsiDirectory dir) {
  final VirtualFile file = dir.getVirtualFile();
  for (VirtualFile root : myClasspath) {
    if (VfsUtilCore.isAncestor(root, file, false)) {
      String relativePath = FileUtil.getRelativePath(root.getPath(), file.getPath(), '/');
      if (relativePath == null) continue;
      return new PsiPackageImpl(myPsiManager, relativePath.replace('/', '.'));
    }
  }
  return null;
}
项目:tools-idea    文件:PackagePrefixElementFinder.java   
@Override
public PsiPackage findPackage(@NotNull String qualifiedName) {
  if (packagePrefixExists(qualifiedName)) {
    return new PsiPackageImpl((PsiManagerEx)PsiManager.getInstance(myProject), qualifiedName);
  }
  return null;
}
项目:consulo-ikvm    文件:IkvmPsiElementFinder.java   
@NotNull
@Override
@RequiredReadAction
public PsiJavaPackage[] getSubPackages(@NotNull PsiJavaPackage psiPackage, @NotNull GlobalSearchScope scope)
{
    String qualifiedName = psiPackage.getQualifiedName();
    if(qualifiedName.startsWith("cli"))
    {
        String substring = qualifiedName.substring(3, qualifiedName.length());
        PsiPackage aPackage = PsiPackageManager.getInstance(myProject).findPackage(substring, DotNetModuleExtension.class);
        if(aPackage == null)
        {
            aPackage = PsiPackageManager.getInstance(myProject).findPackage(substring, JavaModuleExtension.class);
        }
        if(aPackage != null)
        {
            PsiPackage[] subPackages = aPackage.getSubPackages(scope);
            if(subPackages.length == 0)
            {
                return PsiJavaPackage.EMPTY_ARRAY;
            }
            PsiJavaPackage[] packages = new PsiJavaPackage[subPackages.length];
            for(int i = 0; i < subPackages.length; i++)
            {
                PsiPackage subPackage = subPackages[i];
                packages[i] = new PsiPackageImpl(myPsiManager, myPsiPackageManager, JavaModuleExtension.class, subPackage.getQualifiedName());
            }
            return packages;
        }
    }
    return super.getSubPackages(psiPackage, scope);
}
项目:consulo-java    文件:JavaPsiPackageSupportProvider.java   
@NotNull
@Override
public PsiPackage createPackage(
        @NotNull PsiManager psiManager,
        @NotNull PsiPackageManager packageManager,
        @NotNull Class<? extends ModuleExtension> extensionClass,
        @NotNull String packageName)
{
    return new PsiPackageImpl(psiManager, packageManager, extensionClass, packageName);
}
项目:intellij-ce-playground    文件:NonClasspathClassFinder.java   
private PsiPackageImpl createPackage(String qualifiedName) {
  return new PsiPackageImpl(myManager, qualifiedName);
}
项目:eddy    文件:ItemGenerator.java   
private Items.Item[] generate(String s) {
  final EddyThread thread = EddyThread.getEddyThread();
  final HashSet<Items.Item> results = new HashSet<Items.Item>();

  // find and add packages
  for (String pkgQualifiedName: packageIndex.get(s)) {
    Items.Package pkg = (Items.Package) converter.addContainer(new PsiPackageImpl(psiManager, pkgQualifiedName));
    results.add(pkg);
  }

  final Processor<PsiClass> classProc = new Processor<PsiClass>() {
    @Override
    public boolean process(PsiClass cls) {
      // TODO: Ideally we'd check for interrupts here, but can't because our caller grabs fancy locks
      if (thread != null && thread.canceled()) return false;
      results.add(converter.addClass(cls));
      return true;
    }
  };

  final Processor<PsiMethod> methodProc = new Processor<PsiMethod>() {
    @Override
    public boolean process(PsiMethod method) {
      // TODO: Ideally we'd check for interrupts here, but can't because our caller grabs fancy locks
      if (thread != null && thread.canceled()) return false;
      if (!method.isConstructor())
        results.add(converter.addMethod(method));
      return true;
    }
  };

  final Processor<PsiField> fieldProc = new Processor<PsiField>() {
    @Override
    public boolean process(PsiField fld) {
      // TODO: Ideally we'd check for interrupts here, but can't because our caller grabs fancy locks
      if (thread != null && thread.canceled()) return false;
      results.add(converter.addField(fld));
      return true;
    }
  };

  if (thread != null) thread.pushSoftInterrupts();
  try {
    final IdFilter filter = null;
    psiCache.processClassesWithName(s, classProc, scope, filter);
    psiCache.processMethodsWithName(s, methodProc, scope, filter);
    psiCache.processFieldsWithName(s, fieldProc, scope, filter);
  } finally {
    if (thread != null) thread.popSoftInterrupts();
  }
  return results.toArray(new Items.Item[results.size()]);
}
项目:tools-idea    文件:NonClasspathClassFinder.java   
private PsiPackageImpl createPackage(String qualifiedName) {
  return new PsiPackageImpl((PsiManagerEx)myManager, qualifiedName);
}
项目:consulo-java    文件:NonClasspathClassFinder.java   
private PsiPackageImpl createPackage(String qualifiedName)
{
    return new PsiPackageImpl(myManager, myPackageManager, JavaModuleExtension.class, qualifiedName);
}