private static void addIdAndSuperClasses(PsiFile file, @NotNull TIntHashSet forward) {
   if (file instanceof PsiJavaFile
       && file.getName().equals("Object.class")
       && ((PsiJavaFile) file).getPackageName().equals("java.lang")) {
     return;
   }
   VirtualFile virtualFile = PsiUtilCore.getVirtualFile(file);
   if (virtualFile instanceof VirtualFileWithId
       && forward.add(getAbsId(virtualFile))
       && file instanceof PsiClassOwner) {
     for (PsiClass aClass : ((PsiClassOwner) file).getClasses()) {
       for (PsiClass superClass : aClass.getSupers()) {
         addIdAndSuperClasses(superClass.getContainingFile(), forward);
       }
     }
   }
 }
Exemplo n.º 2
0
  public static void addAvailableSystemScripts(
      final Collection<String> result, @NotNull Module module) {
    VirtualFile scriptRoot = null;

    GlobalSearchScope searchScope =
        GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module, false);

    for (PsiClass aClass :
        JavaPsiFacade.getInstance(module.getProject()).findClasses("CreateApp_", searchScope)) {
      PsiClass superClass = aClass.getSuperClass();
      if (superClass != null
          && GroovyCommonClassNames.GROOVY_LANG_SCRIPT.equals(superClass.getQualifiedName())) {
        PsiFile psiFile = aClass.getContainingFile();
        if (psiFile != null) {
          VirtualFile file = psiFile.getVirtualFile();
          if (file != null && file.getFileSystem() instanceof ArchiveFileSystem) {
            VirtualFile parent = file.getParent();
            if (parent != null && parent.findChild("Console.class") != null) {
              scriptRoot = parent;
              break;
            }
          }
        }
      }
    }

    if (scriptRoot == null) return;

    Pattern scriptPattern = Pattern.compile("([A-Za-z0-9]+)_?\\.class");

    for (VirtualFile file : scriptRoot.getChildren()) {
      Matcher matcher = scriptPattern.matcher(file.getName());
      if (matcher.matches()) {
        result.add(GroovyNamesUtil.camelToSnake(matcher.group(1)));
      }
    }
  }