@Override public void methodReached(DependencyAgent agent, MethodDependency method) { method.getResult().propagate(agent.getType("java.lang.String")); } }
@Override public void methodReached(final DependencyAgent agent, MethodDependency method) { if (!method.getReference().getClassName().equals(Platform.class.getName())) { return; } switch (method.getReference().getName()) { case "objectFromResource": allClasses.connect(method.getResult()); break; } } }
@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))); } }
@Override public void methodReached(DependencyAgent agent, MethodDependency method) { if (!method.getReference().getClassName().equals(ResourceAccessor.class.getName())) { return; } switch (method.getReference().getName()) { case "castToString": method.getResult().propagate(agent.getType("java.lang.String")); break; } } }
@Override public void methodReached(DependencyAgent agent, MethodDependency method) { MethodDependency addMethod = agent.linkMethod(new MethodReference(PlatformQueue.class, "wrap", Object.class, PlatformObject.class)); addMethod.getVariable(1).connect(method.getResult()); }
@Override public void methodReached(DependencyAgent agent, MethodDependency method) { switch (method.getMethod().getName()) { case "clone": method.getVariable(0).connect(method.getResult()); break; } } }
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)); }); }
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])); } } } }); }
@Override public void methodReached(DependencyAgent agent, MethodDependency method) { if (method.getReference().getClassName().equals(JSExceptions.class.getName())) { if (method.getReference().getName().equals("getJavaException")) { allExceptions.connect(method.getResult()); } } else if (method.getReference().getClassName().equals(JS.class.getName())) { switch (method.getReference().getName()) { case "get": case "set": case "invoke": allExceptions.connect(method.getThrown()); break; } } else { method.getThrown().connect(allExceptions); } } }
@Override public void methodReached(DependencyAgent agent, MethodDependency method) { MethodReference ref = method.getReference(); if (ref.getClassName().equals("java.util.ServiceLoader") && ref.getName().equals("loadServices")) { List<ServiceLoaderFilter> filters = getFilters(agent); method.getResult().propagate(agent.getType("[Ljava/lang/Object;")); DependencyNode sourceNode = agent.linkMethod(LOAD_METHOD).getVariable(1).getClassValueNode(); sourceNode.connect(method.getResult().getArrayItem()); sourceNode.addConsumer(type -> { CallLocation location = new CallLocation(LOAD_METHOD); for (String implementationType : getImplementations(type.getName())) { if (filters.stream().anyMatch(filter -> !filter.apply(type.getName(), implementationType))) { continue; } serviceMap.computeIfAbsent(type.getName(), k -> new ArrayList<>()).add(implementationType); MethodReference ctor = new MethodReference(implementationType, new MethodDescriptor("<init>", ValueType.VOID)); agent.linkMethod(ctor).addLocation(location).use(); method.getResult().getArrayItem().propagate(agent.getType(implementationType)); } }); } }
private void reachGetInterfaces(DependencyAgent agent, MethodDependency method) { method.getVariable(0).getClassValueNode().addConsumer(type -> { String className = type.getName(); if (className.startsWith("[")) { return; } ClassReader cls = agent.getClassSource().get(className); if (cls != null) { for (String iface : cls.getInterfaces()) { method.getResult().getClassValueNode().propagate(agent.getType(iface)); } } }); }
private void reachGetSuperclass(DependencyAgent agent, MethodDependency method) { method.getVariable(0).getClassValueNode().addConsumer(type -> { String className = type.getName(); if (className.startsWith("[")) { return; } ClassReader cls = agent.getClassSource().get(className); if (cls != null && cls.getParent() != null) { method.getResult().getClassValueNode().propagate(agent.getType(cls.getParent())); } }); }
@Override public void methodReached(DependencyAgent agent, MethodDependency method) { switch (method.getReference().getName()) { case "newEmptyInstance": method.getVariable(0).getClassValueNode().connect(method.getResult()); break; case "getSuperclass": reachGetSuperclass(agent, method); break; case "getInterfaces": reachGetInterfaces(agent, method); break; case "getComponentType": reachGetComponentType(agent, method); break; } }
@Override public void methodReached(DependencyAgent agent, MethodDependency method) { if (method.getReference().getClassName().equals(Platform.class.getName()) && method.getReference().getName().equals("getEnumConstants")) { allEnums.connect(method.getResult().getArrayItem()); final MethodReference ref = method.getReference(); allEnums.addConsumer(type -> { ClassReader cls = agent.getClassSource().get(type.getName()); MethodReader valuesMethod = cls.getMethod(new MethodDescriptor("values", ValueType.arrayOf(ValueType.object(cls.getName())))); if (valuesMethod != null) { MethodDependency valuesDep = agent.linkMethod(valuesMethod.getReference()); valuesDep.addLocation(new CallLocation(ref)); valuesDep.use(); } }); method.getResult().propagate(agent.getType("[Ljava/lang/Enum;")); for (String cls : agent.getReachableClasses()) { classReached(agent, cls); } } } }
@Override public void methodReached(DependencyAgent agent, MethodDependency method) { switch (method.getReference().getName()) { case "invoke": case "instantiate": case "function": if (reachedFunctorMethods.add(method.getReference()) && !method.isMissing()) { for (int i = 0; i < method.getReference().parameterCount(); ++i) { DependencyNode node = method.getVariable(i); if (functorParamNodes.add(node)) { node.addConsumer(type -> { if (agent.getClassHierarchy().isSuperType(method.getMethod().getOwnerName(), type.getName(), false)) { reachFunctorMethods(agent, type.getName()); } }); } } } break; case "unwrapString": method.getResult().propagate(agent.getType("java.lang.String")); break; } }
@Override public void methodReached(DependencyAgent agent, MethodDependency method) { switch (method.getMethod().getName()) { case "initialize": method.getVariable(0).getClassValueNode().addConsumer(type -> { ClassDependency classDep = agent.linkClass(type.getName()); if (classDep != null) { classDep.initClass(new CallLocation(method.getReference())); } }); break; case "getSimpleNameCacheLowLevel": method.getResult().propagate(agent.getType("java.lang.String")); break; } } }
@Override public void methodReached(DependencyAgent agent, MethodDependency method) { MethodReference ref = method.getReference(); MethodReference asyncRef = getAsyncReference(ref); MethodDependency asyncMethod = agent.linkMethod(asyncRef); method.addLocationListener(asyncMethod::addLocation); int paramCount = ref.parameterCount(); for (int i = 0; i <= paramCount; ++i) { method.getVariable(i).connect(asyncMethod.getVariable(i)); } asyncMethod.getVariable(paramCount + 1).propagate(agent.getType(AsyncCallbackWrapper.class.getName())); MethodDependency completeMethod = agent.linkMethod( new MethodReference(AsyncCallbackWrapper.class, "complete", Object.class, void.class)); if (method.getResult() != null) { completeMethod.getVariable(1).connect(method.getResult(), type -> agent.getClassHierarchy() .isSuperType(ref.getReturnType(), ValueType.object(type.getName()), false)); } completeMethod.use(); MethodDependency errorMethod = agent.linkMethod(new MethodReference(AsyncCallbackWrapper.class, "error", Throwable.class, void.class)); errorMethod.getVariable(1).connect(method.getThrown()); errorMethod.use(); agent.linkMethod(new MethodReference(AsyncCallbackWrapper.class, "create", AsyncCallback.class, AsyncCallbackWrapper.class)).use(); asyncMethod.use(); }
private void handleFieldGet(DependencyAgent agent, MethodDependency method) { CallLocation location = new CallLocation(method.getReference()); DependencyNode classValueNode = agent.linkMethod(getFields) .addLocation(location) .getVariable(0).getClassValueNode(); classValueNode.addConsumer(reflectedType -> { if (reflectedType.getName().startsWith("[")) { return; } Set<String> accessibleFields = getAccessibleFields(agent, reflectedType.getName()); ClassReader cls = agent.getClassSource().get(reflectedType.getName()); for (String fieldName : accessibleFields) { FieldReader field = cls.getField(fieldName); FieldDependency fieldDep = agent.linkField(field.getReference()) .addLocation(location); propagateGet(agent, field.getType(), fieldDep.getValue(), method.getResult(), location); linkClassIfNecessary(agent, field, location); } }); }
private MethodDependency installAdditionalDependencies() { MethodDependency nameDep = agent.linkMethod(new MethodReference(Class.class, "getName", String.class)); nameDep.addLocation(location); nameDep.getVariable(0).propagate(agent.getType(Class.class.getName())); nameDep.getThrown().connect(methodDep.getThrown()); nameDep.use(); MethodDependency equalsDep = agent.linkMethod(new MethodReference(String.class, "equals", Object.class, boolean.class)); equalsDep.addLocation(location); nameDep.getResult().connect(equalsDep.getVariable(0)); equalsDep.getVariable(1).propagate(agent.getType("java.lang.String")); equalsDep.getThrown().connect(methodDep.getThrown()); equalsDep.use(); MethodDependency hashCodeDep = agent.linkMethod(new MethodReference(String.class, "hashCode", int.class)); hashCodeDep.addLocation(location); hashCodeDep.getVariable(0).propagate(agent.getType("java.lang.String")); nameDep.getResult().connect(hashCodeDep.getVariable(0)); hashCodeDep.getThrown().connect(methodDep.getThrown()); hashCodeDep.use(); agent.linkMethod(new MethodReference(Object.class, "hashCode", int.class)); agent.linkMethod(new MethodReference(Object.class, "equals", Object.class, boolean.class)); return nameDep; }
private void handleNewInstance(DependencyAgent agent, MethodDependency method) { CallLocation location = new CallLocation(method.getReference()); DependencyNode classValueNode = agent.linkMethod(getConstructors) .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(1).getArrayItem(), calledMethodDep.getVariable(i + 1), location); } calledMethodDep.getVariable(0).propagate(reflectedType); linkClassIfNecessary(agent, calledMethod, location); } }); classValueNode.connect(method.getResult()); }