/** * Throw a ClassNotFoundException to indicate that class named by given * ClassDescriptor cannot be found. The exception message is formatted in a * way that can be decoded by ClassNotFoundExceptionParser. * * @param classDescriptor * ClassDescriptor naming a class that cannot be found * @throws ClassNotFoundException * @see edu.umd.cs.findbugs.ba.ClassNotFoundExceptionParser */ public static void throwClassNotFoundException(ClassDescriptor classDescriptor) throws ClassNotFoundException { throw new ClassNotFoundException("Class " + classDescriptor.toDottedClassName() + " cannot be resolved"); }
@Override public void reportMissingClass(ClassDescriptor classDescriptor) { if (DEBUG_MISSING_CLASSES) { System.out.println("Missing class: " + classDescriptor); new Throwable().printStackTrace(System.out); } if (verbosityLevel == SILENT) { return; } logMissingClass(classDescriptor.toDottedClassName()); }
/** * Factory method to create a ClassAnnotation from a ClassDescriptor. * * @param classDescriptor * the ClassDescriptor * @return the ClassAnnotation */ public static ClassAnnotation fromClassDescriptor(ClassDescriptor classDescriptor) { return new ClassAnnotation(classDescriptor.toDottedClassName()); }
/** * Constructor. * * @param classDescriptor * a ClassDescriptor naming a class: this TypeMatcher will test * whether or not candidate Types are subtypes of the class */ public SubtypeTypeMatcher(ClassDescriptor classDescriptor) { this(BCELUtil.getObjectTypeInstance(classDescriptor.toDottedClassName())); }
@Override public String getPackageName() { String dottedClassName = getClassDescriptor().toDottedClassName(); int lastDot = dottedClassName.lastIndexOf('.'); if (lastDot < 0) { return ""; } else { return dottedClassName.substring(0, lastDot); } }
@Override public void reportMissingClass(ClassDescriptor classDescriptor) { logError("Missing class: " + classDescriptor.toDottedClassName()); }
/** * Lookup a class. * <em>Use this method instead of Repository.lookupClass().</em> * * @param classDescriptor * descriptor specifying the class to look up * @return the class * @throws ClassNotFoundException * if the class can't be found */ public JavaClass lookupClass(@Nonnull ClassDescriptor classDescriptor) throws ClassNotFoundException { return lookupClass(classDescriptor.toDottedClassName()); }
/** * Convert this exception to a ClassNotFoundException. This method should * only be called if the ResourceNotFoundException occurs while looking for * a class. The message format is parseable by ClassNotFoundExceptionParser. */ public ClassNotFoundException toClassNotFoundException() { ClassDescriptor classDescriptor = DescriptorFactory.createClassDescriptorFromResourceName(resourceName); return new ClassNotFoundException("ResourceNotFoundException while looking for class " + classDescriptor.toDottedClassName() + ": " + getMessage()); } }
@Override protected void writeKey(Writer writer, MethodDescriptor method) throws IOException { writer.write(method.getClassDescriptor().toDottedClassName()); writer.write(","); writer.write(method.getName()); writer.write(","); writer.write(method.getSignature()); writer.write(","); XMethod xMethod = XFactory.createXMethod(method); writer.write(Integer.toString(xMethod.getAccessFlags() & 0xf)); } }
@Override public @DottedClassName String getClassName() { return getClassDescriptor().toDottedClassName(); }
@Override public @DottedClassName String getClassName() { return getClassDescriptor().toDottedClassName(); }
/** * Report an exception that occurred while analyzing a class with a * detector. * * @param classDescriptor * class being analyzed * @param detector * detector doing the analysis * @param e * the exception */ private void logRecoverableException(ClassDescriptor classDescriptor, Detector2 detector, Throwable e) { bugReporter.logError( "Exception analyzing " + classDescriptor.toDottedClassName() + " using detector " + detector.getDetectorClassName(), e); }
private List<String> findFullyQualifiedSourceFileNames(IClassPathBuilder builder, IClassPath classPath) { List<ClassDescriptor> appClassList = builder.getAppClassList(); progress.startScanningClasses(appClassList.size()); List<String> fullyQualifiedSourceFileNameList = new LinkedList<>(); for (ClassDescriptor classDesc : appClassList) { try { String fullyQualifiedSourceFileName = findFullyQualifiedSourceFileName(classPath, classDesc); fullyQualifiedSourceFileNameList.add(fullyQualifiedSourceFileName); } catch (IOException e) { errorLogger.logError("Couldn't scan class " + classDesc.toDottedClassName(), e); } catch (CheckedAnalysisException e) { errorLogger.logError("Couldn't scan class " + classDesc.toDottedClassName(), e); } } progress.doneScanningClasses(); return fullyQualifiedSourceFileNameList; }
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); } }
/** * Convenience method for generating a method signature in human readable * form. * * @param methodDescriptor * a MethodDescriptor * @return the formatted version of that signature */ public static String convertMethodSignature(MethodDescriptor methodDescriptor) { return convertMethodSignature(methodDescriptor.getClassDescriptor().toDottedClassName(), methodDescriptor.getName(), methodDescriptor.getSignature()); }
@Override public void observeClass(ClassDescriptor classDescriptor) { try { JavaClass javaClass = AnalysisContext.currentAnalysisContext().lookupClass(classDescriptor.toDottedClassName()); String sourceFileName = fileNameFor(javaClass.getPackageName(), javaClass.getSourceFileName()); sourceFileNameCache.put(javaClass.getClassName(), sourceFileName); } catch (ClassNotFoundException e) { // Ignore - should not happen } }
private void scanForResourceTypes() { Subtypes2 subtypes2 = Global.getAnalysisCache().getDatabase(Subtypes2.class); Collection<XClass> knownClasses = subtypes2.getXClassCollection(); for (XClass xclass : knownClasses) { // Is this class a resource type? if (xclass.getAnnotation(cleanupObligation) != null) { // Add it as an obligation type database.getFactory().addObligation(xclass.getClassDescriptor().toDottedClassName()); } } if (DEBUG_ANNOTATIONS) { System.out.println("After scanning for resource types:"); for (Iterator<Obligation> i = database.getFactory().obligationIterator(); i.hasNext();) { Obligation obligation = i.next(); System.out.println(" " + obligation); } } } }
/** * Constructor. * * @param methodDescriptor * the MethodDescriptor indicating the method it is unprofitable * to analyze */ public MethodUnprofitableException(MethodDescriptor methodDescriptor) { super("Appears unprofitable to analyze " + methodDescriptor.toString()); this.method = XFactory.createXMethod(methodDescriptor.getClassDescriptor().toDottedClassName(), methodDescriptor.getName(), methodDescriptor.getSignature(), methodDescriptor.isStatic()); }
/** * Determine whether class named by given ClassDescriptor is an Obligation * type. * * @param classDescriptor * a class * @return true if the class is an Obligation type, false otherwise */ public boolean isObligationType(ClassDescriptor classDescriptor) { try { return getObligationByType(BCELUtil.getObjectTypeInstance(classDescriptor.toDottedClassName())) != null; } catch (ClassNotFoundException e) { Global.getAnalysisCache().getErrorLogger().reportMissingClass(e); return false; } }
public static SourceLineAnnotation fromVisitedInstruction(MethodDescriptor methodDescriptor, int position) { try { IAnalysisCache analysisCache = Global.getAnalysisCache(); JavaClass jclass = analysisCache.getClassAnalysis(JavaClass.class, methodDescriptor.getClassDescriptor()); Method method = analysisCache.getMethodAnalysis(Method.class, methodDescriptor); return fromVisitedInstruction(jclass, method, position); } catch (CheckedAnalysisException e) { return createReallyUnknown(methodDescriptor.getClassDescriptor().toDottedClassName()); } }