Esempio n. 1
0
 /**
  * Lookup a class. <em>Use this method instead of Repository.lookupClass().</em>
  *
  * @param className the name of the class
  * @return the JavaClass representing the class
  * @throws ClassNotFoundException (but not really)
  */
 public JavaClass lookupClass(@Nonnull @DottedClassName String className)
     throws ClassNotFoundException {
   try {
     if (className.length() == 0) {
       throw new IllegalArgumentException("Class name is empty");
     }
     if (!ClassName.isValidClassName(className)) {
       throw new ClassNotFoundException("Invalid class name: " + className);
     }
     return Global.getAnalysisCache()
         .getClassAnalysis(
             JavaClass.class,
             DescriptorFactory.instance()
                 .getClassDescriptor(ClassName.toSlashedClassName(className)));
   } catch (CheckedAnalysisException e) {
     throw new ClassNotFoundException("Class not found: " + className, e);
   }
 }
Esempio n. 2
0
  /**
   * Get the ClassContext for a class.
   *
   * @param javaClass the class
   * @return the ClassContext for that class
   */
  public ClassContext getClassContext(JavaClass javaClass) {
    // This is a bit silly since we're doing an unnecessary
    // ClassDescriptor->JavaClass lookup.
    // However, we can be assured that it will succeed.

    ClassDescriptor classDescriptor =
        DescriptorFactory.instance()
            .getClassDescriptor(ClassName.toSlashedClassName(javaClass.getClassName()));

    try {
      return Global.getAnalysisCache().getClassAnalysis(ClassContext.class, classDescriptor);
    } catch (CheckedAnalysisException e) {
      IllegalStateException ise =
          new IllegalStateException("Could not get ClassContext for JavaClass");
      ise.initCause(e);
      throw ise;
    }
  }
Esempio n. 3
0
 /**
  * Construct a ClassDescriptor from a JavaClass.
  *
  * @param jclass a JavaClass
  * @return a ClassDescriptor identifying that JavaClass
  */
 public static ClassDescriptor getClassDescriptor(JavaClass jclass) {
   return DescriptorFactory.instance()
       .getClassDescriptor(ClassName.toSlashedClassName(jclass.getClassName()));
 }
Esempio n. 4
0
 private static String getFullMethodName(ConstantPoolGen cpg, InvokeInstruction invoke) {
   String dottedClassName = invoke.getReferenceType(cpg).toString();
   StringBuilder builder = new StringBuilder(ClassName.toSlashedClassName(dottedClassName));
   builder.append(".").append(invoke.getMethodName(cpg)).append(invoke.getSignature(cpg));
   return builder.toString();
 }
 private String getSlashedClassName(FieldOrMethod obj) {
   String className = obj.getReferenceType(cpg).toString();
   return ClassName.toSlashedClassName(className);
 }