Ejemplo n.º 1
0
  @Nullable
  public static PsiJavaFileStub buildFileStub(@NotNull VirtualFile file, @NotNull byte[] bytes)
      throws ClsFormatException {
    if (ClassFileViewProvider.isInnerClass(file)) {
      return null;
    }

    try {
      PsiJavaFileStubImpl stub = new PsiJavaFileStubImpl("do.not.know.yet", true);
      String className = file.getNameWithoutExtension();
      StubBuildingVisitor<VirtualFile> visitor =
          new StubBuildingVisitor<VirtualFile>(file, STRATEGY, stub, 0, className);
      try {
        new ClassReader(bytes).accept(visitor, ClassReader.SKIP_FRAMES);
      } catch (OutOfOrderInnerClassException e) {
        return null;
      }

      PsiClassStub<?> result = visitor.getResult();
      if (result == null) return null;

      stub.setPackageName(getPackageName(result));
      return stub;
    } catch (Exception e) {
      throw new ClsFormatException(file.getPath() + ": " + e.getMessage(), e);
    }
  }