@Override public boolean match(DependencyType type) { if (cache >= 0) { return type.index == cache; } boolean result = typeName.equals(type.getName()); if (result) { cache = type.index; } return result; } }
@Override public boolean match(DependencyType type) { if (!superType.subtypeExists) { return superType.index == type.index; } if (knownTypes.get(type.index)) { return cache.get(type.index); } boolean result = predicate.test(type.getName(), false); knownTypes.set(type.index); cache.set(type.index, result); return result; }
private boolean matchCacheMiss(DependencyType type) { if (!type.getName().startsWith("[")) { return false; } String typeName = type.getName().substring(1); ValueType valueType = ValueType.parseIfPossible(typeName); if (valueType == null || valueType instanceof ValueType.Primitive) { return false; } if (valueType instanceof ValueType.Object) { typeName = ((ValueType.Object) valueType).getClassName(); } return itemTypeFilter.match(analyzer.getType(typeName)); }
@Override public String[] getTypes() { if (typeSet == null) { return new String[0]; } DependencyType[] types = typeSet.getTypes(); String[] result = new String[types.length]; int i = 0; for (DependencyType type : types) { if (filter(type)) { result[i++] = type.getName(); } } return i == result.length ? result : Arrays.copyOf(result, i); }
SuperClassFilter(DependencyAnalyzer dependencyAnalyzer, DependencyType superType) { this.superType = superType; predicate = dependencyAnalyzer.getClassHierarchy().getSuperclassPredicate(superType.getName()); }
@Override public int[] tryExtract(BitSet types) { int[] result = itemTypeFilter.tryExtract(types); if (result == null) { return null; } for (int i = 0; i < result.length; ++i) { String name = analyzer.types.get(i).getName(); int mapped; if (name.startsWith("[")) { mapped = analyzer.getType("[" + name).index; } else if (name.startsWith("~")) { mapped = analyzer.getType("[" + name.substring(1)).index; } else { mapped = analyzer.getType(ValueType.arrayOf(ValueType.object(name)).toString()).index; } result[i] = mapped; } return result; } }
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 reachSet(DependencyAgent agent, MethodDependency method) { method.getVariable(3).connect(method.getVariable(1).getArrayItem()); 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, primitives[i].toLowerCase() + "Value", primitiveTypes[i]); agent.linkMethod(methodRef).use(); } } } }); } }
private void reachGetLength(DependencyAgent agent, MethodDependency method) { method.getVariable(1).addConsumer(type -> { if (!type.getName().startsWith("[")) { MethodReference cons = new MethodReference(IllegalArgumentException.class, "<init>", void.class); agent.linkMethod(cons).use(); } }); }
@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"); }
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) { 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 consume(DependencyType type) { ClassHierarchy hierarchy = analyzer.getClassHierarchy(); for (int i = 0; i < exceptions.length; ++i) { if (exceptions[i] == null || hierarchy.isSuperType(exceptions[i].getName(), type.getName(), false)) { if (vars[i] != null) { vars[i].propagate(type); } return; } } method.getThrown().propagate(type); } }
@Override public void methodReached(DependencyAgent agent, MethodDependency method) { MethodReference ref = method.getReference(); if (ref.getClassName().equals(Platform.class.getName()) && ref.getName().equals("lookupClass")) { allClasses.addConsumer(type -> { ClassReader cls = agent.getClassSource().get(type.getName()); if (cls == null) { return; } MethodReader initMethod = cls.getMethod(new MethodDescriptor("<clinit>", void.class)); if (initMethod != null) { MethodDependency initDep = agent.linkMethod(initMethod.getReference()); method.addLocationListener(initDep::addLocation); initDep.use(); } }); } } }
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)); } } }); }
@Override public void consume(DependencyType type) { if (!agent.getClassHierarchy().isSuperType(superMethod.getClassName(), type.getName(), false)) { return; } MethodReader method = agent.getClassSource().resolveImplementation(new MethodReference( type.getName(), superMethod.getDescriptor())); if (method == null) { return; } virtualMethods.add(method.getReference()); MethodDependency methodDep = agent.linkMethod(method.getReference()); methodDep.use(); for (int i = 0; i < methodDep.getParameterCount(); ++i) { allClassesNode.connect(methodDep.getVariable(i)); allClassesNode.connect(methodDep.getVariable(i).getArrayItem()); } } }
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())); } }); }
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 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; } } }