Class Descriptors

java.lang.Object
aQute.bnd.osgi.Descriptors

public class Descriptors extends Object
  • Field Details

  • Constructor Details

    • Descriptors

      public Descriptors()
  • Method Details

    • getTypeRef

      public Descriptors.TypeRef getTypeRef(String binaryClassName)
    • createTypeRef

      private Descriptors.TypeRef createTypeRef(String binaryClassName)
    • getPackageInfo

      public Descriptors.TypeRef getPackageInfo(Descriptors.PackageRef packageRef)
    • getPackageRef

      public Descriptors.PackageRef getPackageRef(String binaryPackName)
    • getDescriptor

      public Descriptors.Descriptor getDescriptor(String descriptor)
    • getClassSignature

      public ClassSignature getClassSignature(String signature)
    • getMethodSignature

      public MethodSignature getMethodSignature(String signature)
    • getFieldSignature

      public FieldSignature getFieldSignature(String signature)
    • getShortName

      public static String getShortName(String fqn)
      Return the short name of a FQN
    • binaryToFQN

      public static String binaryToFQN(String binary)
    • binaryClassToFQN

      public static String binaryClassToFQN(String path)
    • fqnToBinary

      public static String fqnToBinary(String fqn)
    • fqnClassToBinary

      public static String fqnClassToBinary(String fqn)
      Converts the given fully-qualified top-level class name into the binary class path. For example:

      my.pkg.And.Clazz becomes:

      my/pkg/And$Clazz.class

      This method uses determine(String) to split the class and package names, which is imperfect.

      Parameters:
      fqn - the fully-qualified name to be converted.
      Returns:
      The binary name corresponding to the fully-qualified name.
    • classToPath

      public static String classToPath(String className)
      Converts the class name (without the package qualifier) into the corresponding binary name. For example:

      my.pkg.and.Clazz becomes:

      my$pkg$and$Clazz.class As you can see, this method is not smart about distinguishing between package and class nesting - it always converts the . into a $.

      Parameters:
      className - the name of the class to be converted.
      Returns:
      The binary name corresponding to the class name.
    • getPackage

      public static String getPackage(String binaryNameOrFqn)
    • fqnToPath

      public static String fqnToPath(String s)
    • getTypeRefFromFQN

      public Descriptors.TypeRef getTypeRefFromFQN(String fqn)
    • getTypeRefFromPath

      public Descriptors.TypeRef getTypeRefFromPath(String path)
    • pathToFqn

      public static String pathToFqn(String path)
    • isBinaryClass

      public static boolean isBinaryClass(String resource)
    • binaryToSimple

      public static String binaryToSimple(String resource)
      Java really screwed up in using different names for the binary path and the fqns. This calculates the simple name of a potentially nested class.
      Parameters:
      resource - ( segment '/')+ (name '$')* name '.class'
      Returns:
      the last name
    • isClassName

      public static boolean isClassName(String fqn)
      Heuristic for a class name. We assume a segment with
      Parameters:
      fqn - can be a class name, nested class, or simple name
      Returns:
      true if the last segment starts with an upper case
    • determine

      public static Result<String[],String> determine(String fqn)
      Return a 2 element array based on the fqn. The first element is the package name, the second is the class name. Each can be absent, but not both. The class name can be a nested class (will contain a '.' then)

      Because there is an inherent ambiguity between packages and nested classes, this method uses a heuristic that works most of the time: the start of the class name is considered to be the first element that begins with a capital letter. Hence "simple.Sample.Sumple" => ["simple", "Sample.Sumple" ] and not [ "simple.Sample", "Sumple" ].

      Parameters:
      fqn - a Java identifier name, either a simple class name, a qualified class name, or a package name
      Returns:
      a Result with 2 element array with [package, class]