/** * Get simple unqualified type name. * * @param typ Type Reference. * @return String Unqualified type name. */ private static String getSimpleTypeName(TypeReference typ) { final Map<String, String> mapFullTypeName = ImmutableMap.<String, String>builder() .put("B", "byte") .put("C", "char") .put("D", "double") .put("F", "float") .put("I", "int") .put("J", "long") .put("S", "short") .put("Z", "boolean") .build(); if (typ.isArrayType()) return "Array"; String typName = typ.getName().toString(); if (typName.startsWith("L")) { typName = typName.split("<")[0].substring(1); // handle generics typName = typName.substring(typName.lastIndexOf('/') + 1); // get unqualified name typName = typName.substring(typName.lastIndexOf('$') + 1); // handle inner classes } else { typName = mapFullTypeName.get(typName); } return typName; } }
/** * Checks if all parameters and return value of a method have primitive types. * * @param mtd Method. * @return boolean True if all parameters and return value are of primitive type, otherwise false. */ private static boolean isAllPrimitiveTypes(IMethod mtd) { if (!mtd.getReturnType().isPrimitiveType()) return false; for (int i = (mtd.isStatic() ? 0 : 1); i < mtd.getNumberOfParameters(); i++) { if (!mtd.getParameterType(i).isPrimitiveType()) return false; } return true; }
/** * Get astubx style method signature. {FullyQualifiedEnclosingType}: {UnqualifiedMethodReturnType} * {methodName} ([{UnqualifiedArgumentType}*]) * * @param mtd Method reference. * @return String Method signature. */ // TODO: handle generics and inner classes private static String getSignature(IMethod mtd) { String classType = mtd.getDeclaringClass().getName().toString().replaceAll("/", "\\.").substring(1); classType = classType.replaceAll("\\$", "\\."); // handle inner class String returnType = mtd.isInit() ? null : getSimpleTypeName(mtd.getReturnType()); String strArgTypes = ""; int argi = mtd.isStatic() ? 0 : 1; // Skip 'this' parameter for (; argi < mtd.getNumberOfParameters(); argi++) { strArgTypes += getSimpleTypeName(mtd.getParameterType(argi)); if (argi < mtd.getNumberOfParameters() - 1) strArgTypes += ", "; } return classType + ":" + (returnType == null ? "void " : returnType + " ") + mtd.getName().toString() + "(" + strArgTypes + ")"; } /**
@Override public final String toString() { return "< " + getDeclaringClass().getClassLoader().getName() + ", " + getDeclaringClass().getName() + ", " + selector + " >"; }
@Override public final String toString() { return "< " + getDeclaringClass().getClassLoader().getName() + ", " + getDeclaringClass().getName() + ", " + getName() + ", " + fieldType + " >"; }
/** * Find or create the canonical {@link TypeReference} instance for the given pair. * * @param cl the classloader (defining/initiating depending on usage) * @param typeName something like "Ljava/util/Arrays" */ public static synchronized TypeReference findOrCreate(ClassLoaderReference cl, String typeName) { return findOrCreate(cl, TypeName.string2TypeName(typeName)); }
private static Atom getLanguage(MethodReference target) { return target .getDeclaringClass() .getClassLoader() .getLanguage(); }
if (!pkgName.isEmpty() && !cls.getName().toString().startsWith(pkgName)) continue; LOG(DEBUG, "DEBUG", "analyzing class: " + cls.getName().toString()); for (IMethod mtd : Iterator2Iterable.make(cls.getDeclaredMethods().iterator())) { if (!mtd.getReturnType().isPrimitiveType()) { if (analysisDriver == null) { analysisDriver = getAnalysisDriver(mtd, options, cache, cha);
@Override public Descriptor getDescriptor() { return method.getSelector().getDescriptor(); } /** BEGIN Custom change: : precise bytecode positions */
/** * Get array type corresponding to "this" array element type. */ public final TypeReference getArrayTypeForElementType() { return findOrCreate(classloader, name.getArrayTypeForElementType()); }
/** * Return the innermost element type reference for an array */ public final TypeReference getInnermostElementType() { return findOrCreate(classloader, name.getInnermostElementType()); }
} else if (instr instanceof SSAAbstractInvokeInstruction) { SSAAbstractInvokeInstruction callInst = (SSAAbstractInvokeInstruction) instr; String sign = callInst.getDeclaredTarget().getSignature(); if (((SSAAbstractInvokeInstruction) instr).isStatic()) {
@Override public final String toString() { return "< " + getDeclaringClass().getClassLoader().getName() + ", " + getDeclaringClass().getName() + ", " + selector + " >"; }
@Override public final String toString() { return "< " + getDeclaringClass().getClassLoader().getName() + ", " + getDeclaringClass().getName() + ", " + getName() + ", " + fieldType + " >"; }
/** * Find or create the canonical {@link TypeReference} instance for the given pair. * * @param cl the classloader (defining/initiating depending on usage) * @param typeName something like "Ljava/util/Arrays" */ public static synchronized TypeReference findOrCreate(ClassLoaderReference cl, String typeName) { return findOrCreate(cl, TypeName.string2TypeName(typeName)); }
private static Atom getLanguage(MethodReference target) { return target .getDeclaringClass() .getClassLoader() .getLanguage(); }
@Override public Descriptor getDescriptor() { return method.getSelector().getDescriptor(); } /** BEGIN Custom change: : precise bytecode positions */
if (method.getReturnType().isPrimitiveType()) { LOG(DEBUG, "DEBUG", "Skipping method with primitive return type: " + method.getSignature()); return NullnessHint.UNKNOWN;
/** * Method classLoaderName2Ref. * * @return ClassLoaderReference */ private TypeReference className2Ref(String clName) { return TypeReference.findOrCreate(governingLoader, TypeName.string2TypeName(clName)); } }