public FieldOrMethodDescriptor(@SlashedClassName String slashedClassName, String name, String signature, boolean isStatic) { assert slashedClassName.indexOf('.') == -1 : "class name not in VM format: " + slashedClassName; this.slashedClassName = slashedClassName; this.name = name; this.signature = signature; this.isStatic = isStatic; this.nameSigHashCode = getNameSigHashCode(this.name, this.signature); }
@Override public XMethod findMethod(String methodName, String methodSig, boolean isStatic) { int hash = FieldOrMethodDescriptor.getNameSigHashCode(methodName, methodSig); for (MethodInfo mInfo : xMethods) { if (mInfo.getNameSigHashCode() == hash && mInfo.getName().equals(methodName) && mInfo.getSignature().equals(methodSig) && mInfo.isStatic() == isStatic) { return mInfo; } } return null; }
/** * Returns true if given constant pool probably has a reference to any of supplied methods * Useful to exclude from analysis uninteresting classes * @param cp constant pool * @param methods methods collection * @return true if method is found */ public static boolean hasInterestingMethod(ConstantPool cp, Collection<MethodDescriptor> methods) { for(Constant c : cp.getConstantPool()) { if(c instanceof ConstantMethodref || c instanceof ConstantInterfaceMethodref) { ConstantCP desc = (ConstantCP)c; ConstantNameAndType nameAndType = (ConstantNameAndType) cp.getConstant(desc.getNameAndTypeIndex()); String className = cp.getConstantString(desc.getClassIndex(), Const.CONSTANT_Class); String name = ((ConstantUtf8)cp.getConstant(nameAndType.getNameIndex())).getBytes(); String signature = ((ConstantUtf8)cp.getConstant(nameAndType.getSignatureIndex())).getBytes(); // We don't know whether method is static thus cannot use equals int hash = FieldOrMethodDescriptor.getNameSigHashCode(name, signature); for(MethodDescriptor method : methods) { if (method.getNameSigHashCode() == hash && (method.getSlashedClassName().isEmpty() || method.getSlashedClassName().equals(className)) && method.getName().equals(name) && method.getSignature().equals(signature)) { return true; } } } } return false; }
@Override public XField findField(String name, String signature, boolean isStatic) { int hash = FieldOrMethodDescriptor.getNameSigHashCode(name, signature); for (FieldInfo fInfo : xFields) { if (fInfo.getNameSigHashCode() == hash && fInfo.getName().equals(name) && fInfo.getSignature().equals(signature)
@Override public XMethod findMethod(String methodName, String methodSig, boolean isStatic) { int hash = FieldOrMethodDescriptor.getNameSigHashCode(methodName, methodSig); for (MethodInfo mInfo : xMethods) { if (mInfo.getNameSigHashCode() == hash && mInfo.getName().equals(methodName) && mInfo.getSignature().equals(methodSig) && mInfo.isStatic() == isStatic) { return mInfo; } } return null; }
public FieldOrMethodDescriptor(@SlashedClassName String slashedClassName, String name, String signature, boolean isStatic) { assert slashedClassName.indexOf('.') == -1 : "class name not in VM format: " + slashedClassName; this.slashedClassName = DescriptorFactory.canonicalizeString(slashedClassName); this.name = DescriptorFactory.canonicalizeString(name); this.signature = DescriptorFactory.canonicalizeString(signature); this.isStatic = isStatic; this.nameSigHashCode = getNameSigHashCode(this.name, this.signature); }
/** * Returns true if given constant pool probably has a reference to any of supplied methods * Useful to exclude from analysis uninteresting classes * @param cp constant pool * @param methods methods collection * @return true if method is found */ public static boolean hasInterestingMethod(ConstantPool cp, Collection<MethodDescriptor> methods) { for(Constant c : cp.getConstantPool()) { if(c instanceof ConstantMethodref || c instanceof ConstantInterfaceMethodref) { ConstantCP desc = (ConstantCP)c; ConstantNameAndType nameAndType = (ConstantNameAndType) cp.getConstant(desc.getNameAndTypeIndex()); String className = cp.getConstantString(desc.getClassIndex(), CONSTANT_Class); String name = ((ConstantUtf8)cp.getConstant(nameAndType.getNameIndex())).getBytes(); String signature = ((ConstantUtf8)cp.getConstant(nameAndType.getSignatureIndex())).getBytes(); // We don't know whether method is static thus cannot use equals int hash = FieldOrMethodDescriptor.getNameSigHashCode(name, signature); for(MethodDescriptor method : methods) { if (method.getNameSigHashCode() == hash && (method.getSlashedClassName().isEmpty() || method.getSlashedClassName().equals(className)) && method.getName().equals(name) && method.getSignature().equals(signature)) { return true; } } } } return false; }
@Override public XField findField(String name, String signature, boolean isStatic) { int hash = FieldOrMethodDescriptor.getNameSigHashCode(name, signature); for (FieldInfo fInfo : xFields) { if (fInfo.getNameSigHashCode() == hash && fInfo.getName().equals(name) && fInfo.getSignature().equals(signature)