public String getShortName(String fullName, boolean imported) {
    ClassNode node =
        DecompilerContext.getClassProcessor().getMapRootClasses().get(fullName.replace('.', '/'));

    String result = null;
    if (node != null && node.classStruct.isOwn()) {
      result = node.simpleName;

      while (node.parent != null && node.type == ClassNode.CLASS_MEMBER) {
        result = node.parent.simpleName + '.' + result;
        node = node.parent;
      }

      if (node.type == ClassNode.CLASS_ROOT) {
        fullName = node.classStruct.qualifiedName;
        fullName = fullName.replace('/', '.');
      } else {
        return result;
      }
    } else {
      fullName = fullName.replace('$', '.');
    }

    String shortName = fullName;
    String packageName = "";

    int lastDot = fullName.lastIndexOf('.');
    if (lastDot >= 0) {
      shortName = fullName.substring(lastDot + 1);
      packageName = fullName.substring(0, lastDot);
    }

    StructContext context = DecompilerContext.getStructContext();

    // check for another class which could 'shadow' this one. Two cases:
    // 1) class with the same short name in the current package
    // 2) class with the same short name in the default package
    boolean existsDefaultClass =
        (context.getClass(currentPackageSlash + shortName) != null
                && !packageName.equals(currentPackagePoint))
            || // current package
            (context.getClass(shortName) != null
                && !currentPackagePoint.isEmpty()); // default package

    if (existsDefaultClass
        || (mapSimpleNames.containsKey(shortName)
            && !packageName.equals(mapSimpleNames.get(shortName)))) {
      //  don't return full name because if the class is a inner class, full name refers to the
      // parent full name, not the child full name
      return result == null ? fullName : (packageName + "." + result);
    } else if (!mapSimpleNames.containsKey(shortName)) {
      mapSimpleNames.put(shortName, packageName);
      if (!imported) {
        setNotImportedNames.add(shortName);
      }
    }

    return result == null ? shortName : result;
  }
Exemplo n.º 2
0
  public void decompileContext() {
    if (DecompilerContext.getOption(IFernflowerPreferences.RENAME_ENTITIES)) {
      new IdentifierConverter().rename(structContext);
    }

    classesProcessor = new ClassesProcessor(structContext);

    DecompilerContext.setClassProcessor(classesProcessor);
    DecompilerContext.setStructContext(structContext);

    structContext.saveContext();
  }
Exemplo n.º 3
0
  private void addAllClasspath() {
    Set<String> found = new HashSet<String>();
    String[] props = {
      System.getProperty("java.class.path"), System.getProperty("sun.boot.class.path")
    };
    for (String prop : props) {
      if (prop == null) continue;

      for (final String path : prop.split(File.pathSeparator)) {
        File file = new File(path);
        if (found.contains(file.getAbsolutePath())) continue;

        // only add .class files from classpath
        if (file.exists()
            && (file.getName().endsWith(".class") || file.getName().endsWith(".jar"))) {
          DecompilerContext.getLogger()
              .writeMessage("Adding File to context from classpath: " + file, Severity.INFO);
          structContext.addSpace(file, false);
          found.add(file.getAbsolutePath());
        }
      }
    }
  }