/** * 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 + ")"; } /**
/** * Get the {@link TypeReference} that describes the ith parameter to this method. By convention, for a non-static method, the 0th * parameter is "this". */ public TypeReference getParameterType(int i) { return method.getParameterType(i); }
/** END Custom change */ @Override protected TypeReference[] makeParameterTypes(IMethod method, int i) { TypeReference[] trA = new TypeReference[] {method.getParameterType(i)}; return trA; }
/** * Get the {@link TypeReference} that describes the ith parameter to this method. By convention, for a non-static method, the 0th * parameter is "this". */ public TypeReference getParameterType(int i) { return method.getParameterType(i); }
/** END Custom change */ @Override protected TypeReference[] makeParameterTypes(IMethod method, int i) { TypeReference[] trA = new TypeReference[] {method.getParameterType(i)}; return trA; }
@Override public TypeReference getParameterType(int i) { return method.getParameterType(i); }
@Override public TypeReference getParameterType(int i) { return method.getParameterType(i); }
protected TypeReference[] makeParameterTypes(IMethod method, int i) { return new TypeReference[] { method.getParameterType(i) }; }
protected TypeReference[] makeParameterTypes(IMethod method, int i) { return new TypeReference[] { method.getParameterType(i) }; }
/** * Get the first paramNo of a given type. * * @see com.ibm.wala.util.ssa.ParameterAccessor */ private static int firstOf(TypeName type, IMethod inCallTo) { for (int i = 0; i < inCallTo.getNumberOfParameters(); ++i) { if (inCallTo.getParameterType(i).getName().equals(type)) { return i; } } throw new IllegalArgumentException(type.toString() + " is not a parameter to " + inCallTo); }
/** * Get the first paramNo of a given type. * * @see com.ibm.wala.util.ssa.ParameterAccessor */ private static int firstOf(TypeName type, IMethod inCallTo) { for (int i = 0; i < inCallTo.getNumberOfParameters(); ++i) { if (inCallTo.getParameterType(i).getName().equals(type)) { return i; } } throw new IllegalArgumentException(type.toString() + " is not a parameter to " + inCallTo); }
private void processCallBackParams() { for (MethodParams mp:callBacks) { int params[] = new int[mp.getIMethod().getNumberOfParameters()]; int startPos; if (mp.getIMethod().isStatic()) { startPos = 0; } else { params[0] = typeToID.get(mp.getIMethod().getDeclaringClass().getReference()); startPos = 1; } for (int i = startPos; i < params.length; i++) { params[i] = makeArgument(mp.getIMethod().getParameterType(i)); } mp.setParams(params); } }
/** * @return the receiver class for this method. */ private IClass getReceiverClass(IMethod method) { TypeReference formalType = method.getParameterType(0); IClass C = cha.lookupClass(formalType); if (method.isStatic()) { Assertions.UNREACHABLE("asked for receiver of static method " + method); } if (C == null) { Assertions.UNREACHABLE("no class found for " + formalType + " recv of " + method); } return C; }
/** * @return the receiver class for this method. */ private IClass getReceiverClass(IMethod method) { TypeReference formalType = method.getParameterType(0); IClass C = cha.lookupClass(formalType); if (method.isStatic()) { Assertions.UNREACHABLE("asked for receiver of static method " + method); } if (C == null) { Assertions.UNREACHABLE("no class found for " + formalType + " recv of " + method); } return C; }
/** * @return the receiver class for this method. */ private IClass getReceiverClass(IMethod method) { TypeReference formalType = method.getParameterType(0); IClass C = getClassHierarchy().lookupClass(formalType); if (method.isStatic()) { Assertions.UNREACHABLE("asked for receiver of static method " + method); } if (C == null) { Assertions.UNREACHABLE("no class found for " + formalType + " recv of " + method); } return C; }
/** * @return the receiver class for this method. */ private IClass getReceiverClass(IMethod method) { TypeReference formalType = method.getParameterType(0); IClass C = getClassHierarchy().lookupClass(formalType); if (method.isStatic()) { Assertions.UNREACHABLE("asked for receiver of static method " + method); } if (C == null) { Assertions.UNREACHABLE("no class found for " + formalType + " recv of " + method); } return C; }
@Override protected TypeReference[] makeParameterTypes(IMethod method, int i) { TypeReference nominal = method.getParameterType(i); if (nominal.isPrimitiveType() || nominal.isArrayType()) return new TypeReference[] { nominal }; else { IClass nc = getCha().lookupClass(nominal); if (nc == null) { throw new IllegalStateException("Could not resolve in cha: " + nominal); } Collection<IClass> subcs = nc.isInterface() ? getCha().getImplementors(nominal) : getCha().computeSubClasses(nominal); Set<TypeReference> subs = HashSetFactory.make(); for (IClass cs : subcs) { if (!cs.isAbstract() && !cs.isInterface()) { subs.add(cs.getReference()); } } return subs.toArray(new TypeReference[0]); } } }
@Override protected TypeReference[] makeParameterTypes(IMethod method, int i) { TypeReference nominal = method.getParameterType(i); if (nominal.isPrimitiveType() || nominal.isArrayType()) return new TypeReference[] { nominal }; else { IClass nc = getCha().lookupClass(nominal); if (nc == null) { throw new IllegalStateException("Could not resolve in cha: " + nominal); } Collection<IClass> subcs = nc.isInterface() ? getCha().getImplementors(nominal) : getCha().computeSubClasses(nominal); Set<TypeReference> subs = HashSetFactory.make(); for (IClass cs : subcs) { if (!cs.isAbstract() && !cs.isInterface()) { subs.add(cs.getReference()); } } return subs.toArray(new TypeReference[0]); } } }
protected void dump(ClassHierarchy cha) { for (Object name : cha) { IClass cls = (IClass) name; System.err.println(("class " + cls)); for (Object name2 : cls.getDeclaredInstanceFields()) { IField fld = (IField) name2; System.err.println(("instance field " + fld)); } for (Object name2 : cls.getDeclaredStaticFields()) { IField fld = (IField) name2; System.err.println(("static field " + fld)); } for (Object name2 : cls.getDeclaredMethods()) { IMethod mth = (IMethod) name2; if (mth.isStatic()) System.err.print("static "); System.err.println(("method " + mth + " with " + mth.getNumberOfParameters() + " parameters")); for (int i = 0; i < mth.getNumberOfParameters(); i++) { System.err.println(("param " + i + ": " + mth.getParameterType(i))); } System.err.println(factory.makeIR(mth, Everywhere.EVERYWHERE, options)); } } }