private void reachGet(DependencyAgent agent, MethodDependency method) { method.getVariable(1).getArrayItem().connect(method.getResult()); method.getVariable(1).addConsumer(type -> { if (type.getName().startsWith("[")) { String typeName = type.getName().substring(1); for (int i = 0; i < primitiveTypes.length; ++i) { if (primitiveTypes[i].toString().equals(typeName)) { String wrapper = "java.lang." + primitiveWrappers[i]; MethodReference methodRef = new MethodReference(wrapper, "valueOf", primitiveTypes[i], ValueType.object(wrapper)); agent.linkMethod(methodRef).use(); method.getResult().propagate(agent.getType("java.lang." + primitiveWrappers[i])); } } } }); }
private void reachGetComponentType(DependencyAgent agent, MethodDependency method) { method.getVariable(0).getClassValueNode().addConsumer(t -> { if (!t.getName().startsWith("[")) { return; } String typeName = t.getName().substring(1); if (typeName.charAt(0) == 'L') { typeName = ((ValueType.Object) ValueType.parse(typeName)).getClassName(); } method.getResult().getClassValueNode().propagate(agent.getType(typeName)); }); }
public String[] getClassesPassedToJavaScript() { return allClassesNode.getTypes(); }
public void connect(DependencyNode node, DependencyTypeFilter filter) { if (connectWithoutChildNodes(node, filter)) { connectArrayItemNodes(node); if (classValueNode != null && classValueNode != this) { classValueNode.connect(node.getClassValueNode()); } } }
private void connectArrayItemNodes(DependencyNode node) { if (degree > DEGREE_THRESHOLD || node.degree > DEGREE_THRESHOLD) { return; } if (!isArray(typeFilter) || !isArray(node.typeFilter)) { return; } if (Objects.equals(typeFilter, node.typeFilter)) { if (arrayItemNode != null && node.arrayItemNode == null) { node.arrayItemNode = arrayItemNode; return; } if (node.arrayItemNode != null && arrayItemNode == null) { arrayItemNode = node.arrayItemNode; return; } if (node.arrayItemNode == null && arrayItemNode == null) { node.arrayItemNode = getArrayItem(); return; } } getArrayItem().connect(node.getArrayItem()); node.getArrayItem().connect(getArrayItem()); }
private void connectClassValueNodes() { if (classNodeComplete) { return; } classNodeComplete = true; if (classNodeParent == null || classNodeParent.transitions == null) { return; } for (Transition transition : classNodeParent.transitionList.toArray(Transition.class)) { connect(transition.destination.getClassValueNode()); } }
@Override public void consume(DependencyType type) { target.propagate(type); } }
@Override public void cloneArray(VariableReader receiver, VariableReader array) { DependencyNode arrayNode = getNode(array); DependencyNode receiverNode = getNode(receiver); if (arrayNode != null && receiverNode != null) { arrayNode.addConsumer(receiverNode::propagate); arrayNode.getArrayItem().connect(receiverNode.getArrayItem()); } MethodDependency cloneDep = getAnalyzer().linkMethod(CLONE_METHOD); cloneDep.addLocation(getCallLocation()); arrayNode.connect(cloneDep.getVariable(0)); cloneDep.use(); }
private void reachArrayCopy(MethodDependency method) { DependencyNode src = method.getVariable(1); DependencyNode dest = method.getVariable(3); src.getArrayItem().connect(dest.getArrayItem()); } }
public void connect(DependencyNode node) { connect(node, null); }
public static void includeStackTraceMethods(DependencyAnalyzer dependencyAnalyzer) { MethodDependency dep; DependencyType stringType = dependencyAnalyzer.getType("java.lang.String"); dep = dependencyAnalyzer.linkMethod(new MethodReference( StackTraceElement.class, "<init>", String.class, String.class, String.class, int.class, void.class)); dep.getVariable(0).propagate(dependencyAnalyzer.getType(StackTraceElement.class.getName())); dep.getVariable(1).propagate(stringType); dep.getVariable(2).propagate(stringType); dep.getVariable(3).propagate(stringType); dep.use(); dep = dependencyAnalyzer.linkMethod(new MethodReference( Throwable.class, "setStackTrace", StackTraceElement[].class, void.class)); dep.getVariable(0).propagate(dependencyAnalyzer.getType(Throwable.class.getName())); dep.getVariable(1).propagate(dependencyAnalyzer.getType("[Ljava/lang/StackTraceElement;")); dep.getVariable(1).getArrayItem().propagate(dependencyAnalyzer.getType(StackTraceElement.class.getName())); dep.use(); }
nodeClasses[i].method = ref; if (DependencyAnalyzer.shouldTag) { nodeClasses[i].setTag(dep.getMethod().getReference() + ":" + i); DependencyNode incomingNode = nodes[incoming.getValue().getIndex()]; if (incomingNode != null && receiverNode != null) { incomingNode.connect(receiverNode); node.propagate(dependencyAnalyzer.getType("java.lang.Class")); nodes[0].connect(node);
private void reachGetAnnotations(DependencyAgent agent, DependencyNode node) { node.getClassValueNode().addConsumer(type -> { String className = type.getName(); ClassReader cls = agent.getClassSource().get(className); if (cls == null) { return; } for (AnnotationReader annotation : cls.getAnnotations().all()) { agent.linkClass(annotation.getType()); } createAnnotationClass(agent, className); }); }
@Override public void consume(DependencyType type) { if (filter != null && !filter.match(type)) { return; } if (type.getName().startsWith("[")) { source.getArrayItem().connect(destination.getArrayItem()); destination.getArrayItem().connect(source.getArrayItem()); } if (type.getName().equals("java.lang.Class")) { source.getClassValueNode().connect(destination.getClassValueNode()); } if (!destination.hasType(type)) { destination.propagate(type); } } }
@Override public void started(DependencyAgent agent) { allClasses = agent.createNode(); allClasses.addConsumer(c -> { if (agent.getClassSource().isSuperType("java.lang.Throwable", c.getName()).orElse(false)) { MethodDependency methodDep = agent.linkMethod(new MethodReference(c.getName(), GET_MESSAGE)); methodDep.getVariable(0).propagate(c); methodDep.use(); } }); agent.linkClass("java.lang.Throwable"); }
@Override public void methodReached(DependencyAgent agent, MethodDependency method) { MethodReader reader = method.getMethod(); if (reader.getOwnerName().equals(Platform.class.getName()) && reader.getName().equals("newInstanceImpl")) { allClassesNode.connect(method.getResult()); MethodReference methodRef = reader.getReference(); method.getResult().addConsumer(type -> attachConstructor(agent, type.getName(), new CallLocation(methodRef))); } }
public FastDependencyAnalyzer(ClassReaderSource classSource, ClassLoader classLoader, ServiceRepository services, Diagnostics diagnostics) { super(classSource, classLoader, services, diagnostics); instancesNode = new DependencyNode(this, null); classesNode = new DependencyNode(this, null); instancesNode.addConsumer(type -> { getSubtypeNode(type.getName()).propagate(type); }); }
@Override public void raise(VariableReader exception) { nodes[exception.getIndex()].addConsumer(currentExceptionConsumer); }
private void handleInvoke(DependencyAgent agent, MethodDependency method) { CallLocation location = new CallLocation(method.getReference()); DependencyNode classValueNode = agent.linkMethod(getMethods) .addLocation(location) .getVariable(0).getClassValueNode(); classValueNode.addConsumer(reflectedType -> { if (reflectedType.getName().startsWith("[")) { return; } Set<MethodDescriptor> accessibleMethods = getAccessibleMethods(agent, reflectedType.getName()); ClassReader cls = agent.getClassSource().get(reflectedType.getName()); for (MethodDescriptor methodDescriptor : accessibleMethods) { MethodReader calledMethod = cls.getMethod(methodDescriptor); MethodDependency calledMethodDep = agent.linkMethod(calledMethod.getReference()).addLocation(location); calledMethodDep.use(); for (int i = 0; i < calledMethod.parameterCount(); ++i) { propagateSet(agent, methodDescriptor.parameterType(i), method.getVariable(2).getArrayItem(), calledMethodDep.getVariable(i + 1), location); } propagateSet(agent, ValueType.object(reflectedType.getName()), method.getVariable(1), calledMethodDep.getVariable(0), location); propagateGet(agent, calledMethod.getResultType(), calledMethodDep.getResult(), method.getResult(), location); linkClassIfNecessary(agent, calledMethod, location); } }); }
@Override public void classConstant(VariableReader receiver, ValueType cst) { DependencyNode node = getNode(receiver); if (node != null) { node.propagate(getAnalyzer().getType("java.lang.Class")); if (!(cst instanceof ValueType.Primitive)) { StringBuilder sb = new StringBuilder(); if (cst instanceof ValueType.Object) { sb.append(((ValueType.Object) cst).getClassName()); } else { sb.append(cst.toString()); } node.getClassValueNode().propagate(getAnalyzer().getType(sb.toString())); } else { node.getClassValueNode().propagate(getAnalyzer().getType("~" + cst.toString())); } } while (cst instanceof ValueType.Array) { cst = ((ValueType.Array) cst).getItemType(); } if (cst instanceof ValueType.Object) { String className = ((ValueType.Object) cst).getClassName(); getAnalyzer().linkClass(className); } }