Пример #1
0
  @Nullable
  public static String getSourcePositionPackageDisplayName(
      DebugProcessImpl debugProcess, @Nullable SourcePosition position) {
    if (position == null) {
      return null;
    }
    final PsiFile positionFile = position.getFile();
    if (positionFile instanceof JspFile) {
      final PsiDirectory dir = positionFile.getContainingDirectory();
      return dir != null ? dir.getVirtualFile().getPresentableUrl() : null;
    }

    final PsiClass psiClass = getClassAt(position);

    if (psiClass != null) {
      PsiClass toplevel = PsiUtil.getTopLevelClass(psiClass);
      if (toplevel != null) {
        String qName = toplevel.getQualifiedName();
        if (qName != null) {
          int i = qName.lastIndexOf('.');
          return i > 0 ? qName.substring(0, i) : "";
        }
      }
    }

    if (positionFile instanceof PsiClassOwner) {
      String name = ((PsiClassOwner) positionFile).getPackageName();
      if (!StringUtil.isEmpty(name)) {
        return name;
      }
    }

    if (debugProcess != null && debugProcess.isAttached()) {
      List<ReferenceType> allClasses = debugProcess.getPositionManager().getAllClasses(position);
      if (!allClasses.isEmpty()) {
        final String className = allClasses.get(0).name();
        int dotIndex = className.lastIndexOf('.');
        if (dotIndex >= 0) {
          return className.substring(0, dotIndex);
        }
      }
    }
    return "";
  }
Пример #2
0
  @Nullable
  public static String getSourcePositionClassDisplayName(
      DebugProcessImpl debugProcess, @Nullable SourcePosition position) {
    if (position == null) {
      return null;
    }
    final PsiFile positionFile = position.getFile();
    if (positionFile instanceof JspFile) {
      return positionFile.getName();
    }

    final PsiClass psiClass = getClassAt(position);

    if (psiClass != null) {
      final String qName = psiClass.getQualifiedName();
      if (qName != null) {
        return qName;
      }
    }

    if (debugProcess != null && debugProcess.isAttached()) {
      List<ReferenceType> allClasses = debugProcess.getPositionManager().getAllClasses(position);
      if (!allClasses.isEmpty()) {
        return allClasses.get(0).name();
      }
    }
    if (psiClass == null) {
      if (positionFile instanceof PsiClassOwner) {
        return positionFile.getName();
      }

      return DebuggerBundle.message(
          "string.file.line.position", positionFile.getName(), position.getLine());
    }
    return calcClassDisplayName(psiClass);
  }