/** * Add a static field read (bytecode instruction GETSTATIC) to the graph * * @param owner * @param methodName * @param targetClass * @param targetField */ public void addStaticFieldRead(String owner, String methodName, String targetClass, String targetField) { StaticFieldReadEntry read = new StaticFieldReadEntry(owner, methodName, targetClass, targetField); logger.info("Adding new static field read: " + read.toString()); staticFieldReads.add(read); }
@Override public String toString() { return getSourceClass() + "." + getSourceMethod() + " -> " + getTargetClass() + "." + targetField; } }
/** * Returns a classname->set(fieldname) with those static fields reached by * static methods (included <clinit>) * * @return */ public Map<String, Set<String>> getStaticFields() { Map<String, Set<String>> staticFields = new LinkedHashMap<String, Set<String>>(); for (StaticFieldReadEntry read : this.staticFieldReads) { String className = read.getTargetClass().replace('/', '.'); if (!staticFields.containsKey(className)) { staticFields.put(className, new LinkedHashSet<String>()); } staticFields.get(className).add(read.getTargetField()); } return staticFields; } }
/** * Returns if there is a static field read egde (GETSTATIC bytecode * instruction)from <owner,methodName> to <targetClass,targetField>. * * @param owner * @param methodName * @param targetClass * @param targetField * @return */ public boolean hasStaticFieldRead(String owner, String methodName, String targetClass, String targetField) { StaticFieldReadEntry read = new StaticFieldReadEntry(owner, methodName, targetClass, targetField); return staticFieldReads.contains(read); }
/** * Returns the set of class names (with dots) of those classes * such that there is a at least one edge and the class is the target of * the edge. * * @return */ public Set<String> getTargetClasses() { Set<String> targetClasses = new LinkedHashSet<String>(); for (StaticFieldReadEntry entry : staticFieldReads) { targetClasses.add(entry.getTargetClass().replace('/', '.')); } for (StaticMethodCallEntry entry : staticMethodCalls) { targetClasses.add(entry.getTargetClass().replace('/', '.')); } return targetClasses; }
/** * Returns the set of class names (with dots) of those classes * such that there is a at least one edge and the class is the source of * the edge. * * @return */ public Set<String> getSourceClasses() { Set<String> sourceClasses = new LinkedHashSet<String>(); for (StaticFieldReadEntry entry : staticFieldReads) { sourceClasses.add(entry.getSourceClass().replace('/', '.')); } for (StaticMethodCallEntry entry : staticMethodCalls) { sourceClasses.add(entry.getSourceClass().replace('/', '.')); } return sourceClasses; }