@Override public void visit(ConstantNameAndType obj) { String methodName = obj.getName(getConstantPool()); String methodSig = obj.getSignature(getConstantPool()); if (!"clone".equals(methodName)) { return; } if (!methodSig.startsWith("()")) { return; } referencesCloneMethod = true; }
@Override public void visit(ConstantNameAndType obj) { String signature = obj.getSignature(javaClass.getConstantPool()); ClassParser.extractReferencedClassesFromSignature(referencedClassSet, signature); } });
@Override public void visitClass(ClassDescriptor classDescriptor) throws CheckedAnalysisException { IAnalysisCache analysisCache = Global.getAnalysisCache(); ObligationFactory factory = database.getFactory(); JavaClass jclass = analysisCache.getClassAnalysis(JavaClass.class, classDescriptor); for (Constant c : jclass.getConstantPool().getConstantPool()) { if (c instanceof ConstantNameAndType) { ConstantNameAndType cnt = (ConstantNameAndType) c; String signature = cnt.getSignature(jclass.getConstantPool()); if (factory.signatureInvolvesObligations(signature)) { super.visitClass(classDescriptor); return; } } else if (c instanceof ConstantClass) { String className = ((ConstantClass) c).getBytes(jclass.getConstantPool()); if (factory.signatureInvolvesObligations(className)) { super.visitClass(classDescriptor); return; } } } if (DEBUG) { System.out.println(classDescriptor + " isn't interesting for obligation analysis"); } }
/** * Called to indicate that a field load or store was encountered. * * @param cpIndex * the constant pool index of the fieldref * @param isStatic * true if it is a static field access * @param isLoad * true if the access is a load */ private void setField(int cpIndex, boolean isStatic, boolean isLoad) { // We only allow one field access for an accessor method. accessCount++; if (accessCount != 1) { access = null; return; } ConstantPool cp = javaClass.getConstantPool(); ConstantFieldref fieldref = (ConstantFieldref) cp.getConstant(cpIndex); ConstantClass cls = (ConstantClass) cp.getConstant(fieldref.getClassIndex()); String className = cls.getBytes(cp).replace('/', '.'); ConstantNameAndType nameAndType = (ConstantNameAndType) cp.getConstant(fieldref.getNameAndTypeIndex()); String fieldName = nameAndType.getName(cp); String fieldSig = nameAndType.getSignature(cp); XField xfield = Hierarchy.findXField(className, fieldName, fieldSig, isStatic); if (xfield != null && xfield.isStatic() == isStatic && isValidAccessMethod(methodSig, xfield, isLoad)) { access = new InnerClassAccess(methodName, methodSig, xfield, isLoad); } }
@Override public void visit(ConstantNameAndType obj) { String signature = obj.getSignature(javaClass.getConstantPool()); ClassParser.extractReferencedClassesFromSignature(referencedClassSet, signature); } });
@Override public void visit(ConstantNameAndType obj) { String methodName = obj.getName(getConstantPool()); String methodSig = obj.getSignature(getConstantPool()); if (!"clone".equals(methodName)) { return; } if (!methodSig.startsWith("()")) { return; } referencesCloneMethod = true; }
private Type getFieldType(ConstantFieldref fieldRef) { ConstantNameAndType nameAndType= (ConstantNameAndType) constantPool.getConstant(fieldRef.getNameAndTypeIndex()); return Type.getType(nameAndType.getSignature(constantPool)); }
@Nullable private String getAnonymousName(ConstantMethodHandle cmh) { if (cmh == null || cmh.getReferenceKind() != Const.REF_invokeStatic) { return null; } ConstantPool cp = getConstantPool(); ConstantCP methodRef = (ConstantCP) cp.getConstant(cmh.getReferenceIndex()); String clsName = methodRef.getClass(cp); if (!clsName.equals(cls.getClassName())) { return null; } ConstantNameAndType nameAndType = (ConstantNameAndType) cp.getConstant(methodRef.getNameAndTypeIndex()); String signature = nameAndType.getSignature(cp); int numParms = SignatureUtils.getNumParameters(signature); if (((numParms == 1) && signature.endsWith("V")) || ((numParms == 2) && !signature.endsWith("V"))) { return null; } String methodName = nameAndType.getName(cp); if (!isSynthetic(methodName, nameAndType.getSignature(cp))) { return null; } return methodName; }
@Nullable private String getAnonymousName(ConstantMethodHandle cmh) { if ((cmh == null) || (cmh.getReferenceKind() != REF_invokeStatic)) { return null; } ConstantPool cp = getConstantPool(); ConstantCP methodRef = (ConstantCP) cp.getConstant(cmh.getReferenceIndex()); String clsName = methodRef.getClass(cp); if (!clsName.equals(cls.getClassName())) { return null; } ConstantNameAndType nameAndType = (ConstantNameAndType) cp.getConstant(methodRef.getNameAndTypeIndex()); String signature = nameAndType.getSignature(cp); if (signature.endsWith("V")) { return null; } String methodName = nameAndType.getName(cp); if (!isSynthetic(methodName, nameAndType.getSignature(cp))) { return null; } return methodName; }
public static MethodBinding lookup(int index, ConstantPool constantPool) { ConstantCP methodRef= (ConstantCP) constantPool.getConstant(index); ConstantNameAndType nameAndType= (ConstantNameAndType) constantPool.getConstant(methodRef.getNameAndTypeIndex(), Constants.CONSTANT_NameAndType); String name= nameAndType.getName(constantPool); String signature= nameAndType.getSignature(constantPool); return lookup(methodRef.getClass(constantPool), name, signature); }
@Override public void visitClass(ClassDescriptor classDescriptor) throws CheckedAnalysisException { IAnalysisCache analysisCache = Global.getAnalysisCache(); ObligationFactory factory = database.getFactory(); JavaClass jclass = analysisCache.getClassAnalysis(JavaClass.class, classDescriptor); for (Constant c : jclass.getConstantPool().getConstantPool()) { if (c instanceof ConstantNameAndType) { ConstantNameAndType cnt = (ConstantNameAndType) c; String signature = cnt.getSignature(jclass.getConstantPool()); if (factory.signatureInvolvesObligations(signature)) { super.visitClass(classDescriptor); return; } } else if (c instanceof ConstantClass) { String className = ((ConstantClass) c).getBytes(jclass.getConstantPool()); if (factory.signatureInvolvesObligations(className)) { super.visitClass(classDescriptor); return; } } } if (DEBUG) { System.out.println(classDescriptor + " isn't interesting for obligation analysis"); } }
/** * Called to indicate that a field load or store was encountered. * * @param cpIndex * the constant pool index of the fieldref * @param isStatic * true if it is a static field access * @param isLoad * true if the access is a load */ private void setField(int cpIndex, boolean isStatic, boolean isLoad) { // We only allow one field access for an accessor method. accessCount++; if (accessCount != 1) { access = null; return; } ConstantPool cp = javaClass.getConstantPool(); ConstantFieldref fieldref = (ConstantFieldref) cp.getConstant(cpIndex); ConstantClass cls = (ConstantClass) cp.getConstant(fieldref.getClassIndex()); String className = cls.getBytes(cp).replace('/', '.'); ConstantNameAndType nameAndType = (ConstantNameAndType) cp.getConstant(fieldref.getNameAndTypeIndex()); String fieldName = nameAndType.getName(cp); String fieldSig = nameAndType.getSignature(cp); XField xfield = Hierarchy.findXField(className, fieldName, fieldSig, isStatic); if (xfield != null && xfield.isStatic() == isStatic && isValidAccessMethod(methodSig, xfield, isLoad)) { access = new InnerClassAccess(methodName, methodSig, xfield, isLoad); } }