/** * Get a ClassDescriptor for the class described by given ObjectType object. * * @param type * an ObjectType * @return a ClassDescriptor for the class described by the ObjectType * @deprecated Use {@link DescriptorFactory#getClassDescriptor(ObjectType)} * instead */ @Deprecated public static ClassDescriptor getClassDescriptor(ObjectType type) { return DescriptorFactory.getClassDescriptor(type); }
/** * Get a ClassDescriptor for a class name in dotted format. * * @param dottedClassName * a class name in dotted format * @return ClassDescriptor for that class */ public ClassDescriptor getClassDescriptorForDottedClassName(@DottedClassName String dottedClassName) { assert dottedClassName != null; ClassDescriptor classDescriptor = dottedClassDescriptorMap.get(dottedClassName); if (classDescriptor == null) { classDescriptor = getClassDescriptor(dottedClassName.replace('.', '/')); dottedClassDescriptorMap.put(dottedClassName, classDescriptor); } return classDescriptor; }
/** * Determine whether or not a given ObjectType is a subtype of another. * Throws ClassNotFoundException if the question cannot be answered * definitively due to a missing class. * * @param type * a ReferenceType * @param possibleSupertype * another Reference type * @return true if <code>type</code> is a subtype of * <code>possibleSupertype</code>, false if not * @throws ClassNotFoundException * if a missing class prevents a definitive answer */ public boolean isSubtype(ObjectType type, ObjectType possibleSupertype) throws ClassNotFoundException { if (DEBUG_QUERIES) { System.out.println("isSubtype: check " + type + " subtype of " + possibleSupertype); } if (type.equals(possibleSupertype)) { if (DEBUG_QUERIES) { System.out.println(" ==> yes, types are same"); } return true; } ClassDescriptor typeClassDescriptor = DescriptorFactory.getClassDescriptor(type); ClassDescriptor possibleSuperclassClassDescriptor = DescriptorFactory.getClassDescriptor(possibleSupertype); return isSubtype(typeClassDescriptor, possibleSuperclassClassDescriptor); }
public static ClassDescriptor createClassDescriptor(Class<?> aClass) { return instance().getClassDescriptor(ClassName.toSlashedClassName(aClass.getName())); }
public static @Nonnull ClassDescriptor createClassDescriptor(@SlashedClassName String className) { return instance().getClassDescriptor(className); }
public static void extractReferencedClassesFromSignature(Set<ClassDescriptor> referencedClassSet, String signature) { while (signature.length() > 0) { int start = signature.indexOf('L'); if (start < 0) { break; } int end = signature.indexOf(';', start); if (end < 0) { break; } @SlashedClassName String className = signature.substring(start + 1, end); if (ClassName.isValidClassName(className)) { referencedClassSet.add(DescriptorFactory.instance().getClassDescriptor(className)); } signature = signature.substring(end + 1); } }
@Override public JavaClass loadClass(String className) throws ClassNotFoundException { if (className.length() == 0) { throw new IllegalArgumentException("Request to load empty class"); } className = ClassName.toSlashedClassName(className); ClassDescriptor classDescriptor = DescriptorFactory.instance().getClassDescriptor(className); try { return Global.getAnalysisCache().getClassAnalysis(JavaClass.class, classDescriptor); } catch (CheckedAnalysisException e) { throw new ClassNotFoundException("Exception while looking for class " + className, e); } }
return; ClassDescriptor classDescriptor = DescriptorFactory.instance().getClassDescriptor(owner); calledClassSet.add(classDescriptor);
/** * 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())); }
/** * Get the ClassDescriptor of a class referenced in the constant pool. * * @param index * index of the referenced class in the constant pool * @return the ClassDescriptor of the referenced class * @throws InvalidClassFileFormatException */ private ClassDescriptor getClassDescriptor(int index) throws InvalidClassFileFormatException { @SlashedClassName String className = getClassName(index); return className != null ? DescriptorFactory.instance().getClassDescriptor(className) : null; }
@Override public void visit(ConstantClass obj) { @SlashedClassName String className = obj.getBytes(javaClass.getConstantPool()); if (className.indexOf('[') >= 0) { ClassParser.extractReferencedClassesFromSignature(referencedClassSet, className); } else if (ClassName.isValidClassName(className)) { referencedClassSet.add(DescriptorFactory.instance().getClassDescriptor(className)); } }
private void addVertexToGraph(ClassDescriptor classDescriptor, ClassVertex vertex) { assert classDescriptorToVertexMap.get(classDescriptor) == null; if (DEBUG) { System.out.println("Adding " + classDescriptor.toDottedClassName() + " to inheritance graph"); } graph.addVertex(vertex); classDescriptorToVertexMap.put(classDescriptor, vertex); if (vertex.isResolved()) { xclassSet.add(vertex.getXClass()); } if (vertex.isInterface()) { // There is no need to add additional worklist nodes because // java/lang/Object has no supertypes. addInheritanceEdge(vertex, DescriptorFactory.instance().getClassDescriptor("java/lang/Object"), false, null); } }
/** * 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); } }
/** * 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; } }
public BuildObligationPolicyDatabase(BugReporter bugReporter) { this.reporter = bugReporter; final DescriptorFactory instance = DescriptorFactory.instance(); this.willClose = instance.getClassDescriptor(WillClose.class); this.willNotClose = instance.getClassDescriptor(WillNotClose.class); this.willCloseWhenClosed = instance.getClassDescriptor(WillCloseWhenClosed.class); this.cleanupObligation = instance.getClassDescriptor(CleanupObligation.class); this.createsObligation = instance.getClassDescriptor(CreatesObligation.class); this.dischargesObligation = instance.getClassDescriptor(DischargesObligation.class);
@Override public JavaClass findClass(String className) { @SlashedClassName String slashedClassName = ClassName.toSlashedClassName(className); ClassDescriptor classDescriptor = DescriptorFactory.instance().getClassDescriptor(slashedClassName); return Global.getAnalysisCache().probeClassAnalysis(JavaClass.class, classDescriptor); }
private ObjectType computeFirstCommonSuperclassOfObjectTypes(ObjectType a, ObjectType b) throws ClassNotFoundException { ObjectType firstCommonSupertype; ClassDescriptor aDesc = DescriptorFactory.getClassDescriptor(a); ClassDescriptor bDesc = DescriptorFactory.getClassDescriptor(b); ClassDescriptor objDesc = DescriptorFactory.getClassDescriptor(Type.OBJECT); aSuperTypes.retainAll(bSuperTypes); aSuperTypes.remove(objDesc);
/** * Determine if the given ObjectType refers to an unchecked exception * (RuntimeException or Error). */ public static boolean isUncheckedException(ObjectType type) throws ClassNotFoundException { if (type.equals(Type.THROWABLE) || type.equals(RUNTIME_EXCEPTION_TYPE) || type.equals(ERROR_TYPE)) { return true; } ClassDescriptor c = DescriptorFactory.getClassDescriptor(type); Subtypes2 subtypes2 = Global.getAnalysisCache().getDatabase(Subtypes2.class); return subtypes2.isSubtype(c, RUNTIME_EXCEPTION, ERROR); }
UnreadFieldsData unreadFields = AnalysisContext.currentAnalysisContext().getUnreadFieldsData(); ClassDescriptor cd = DescriptorFactory.getClassDescriptor((ObjectType) type); @SlashedClassName String className = cd.getClassName();
extractReferencedClassesFromSignature(referencedClassSet, className); } else if (ClassName.isValidClassName(className)) { referencedClassSet.add(DescriptorFactory.instance().getClassDescriptor(className));