private Set<String> findClassesRequiringName() { Set<String> classesRequiringName = new HashSet<>(); MethodDependencyInfo getNameMethod = context.getDependencyInfo().getMethod( new MethodReference(Class.class, "getName", String.class)); if (getNameMethod != null) { classesRequiringName.addAll(Arrays.asList(getNameMethod.getVariable(0).getClassValueNode().getTypes())); } MethodDependencyInfo getSimpleNameMethod = context.getDependencyInfo().getMethod( new MethodReference(Class.class, "getSimpleName", String.class)); if (getSimpleNameMethod != null) { classesRequiringName.addAll(Arrays.asList( getSimpleNameMethod.getVariable(0).getClassValueNode().getTypes())); } return classesRequiringName; }
private boolean checkMethod(TextLocation location, MethodReference method) { if (!checkClass(location, method.getClassName())) { return false; } if (!reachableMethods.contains(method)) { return true; } MethodDependencyInfo methodDep = dependencyInfo.getMethod(method); if (!methodDep.isMissing() || !methodDep.isUsed()) { return true; } diagnostics.error(new CallLocation(methodRef, location), "Method {{m0}} was not found", method); emitExceptionThrow(location, NoSuchMethodError.class.getName(), "Method not found: " + method); return true; }
public void apply(MethodHolder method) { MethodDependencyInfo methodDep = dependency.getMethod(method.getReference()); if (methodDep == null) { return; } Program program = method.getProgram(); for (int i = 0; i < program.basicBlockCount(); ++i) { BasicBlock block = program.basicBlockAt(i); for (Instruction insn : block) { if (!(insn instanceof InvokeInstruction)) { continue; } InvokeInstruction invoke = (InvokeInstruction) insn; if (invoke.getType() != InvocationType.VIRTUAL) { continue; } ValueDependencyInfo var = methodDep.getVariable(invoke.getInstance().getIndex()); Set<MethodReference> implementations = getImplementations(var.getTypes(), invoke.getMethod()); if (implementations.size() == 1) { invoke.setType(InvocationType.SPECIAL); invoke.setMethod(implementations.iterator().next()); } else { virtualMethods.addAll(implementations); } } } }
public void link(ClassHolder cls) { for (MethodHolder method : cls.getMethods().toArray(new MethodHolder[0])) { MethodReference methodRef = method.getReference(); MethodDependencyInfo methodDep = dependency.getMethod(methodRef); if (methodDep == null) { cls.removeMethod(method); } else if (!methodDep.isUsed()) { method.getModifiers().add(ElementModifier.ABSTRACT); method.setProgram(null); } else if (method.getProgram() != null) { link(method.getReference(), method.getProgram()); } } for (FieldHolder field : cls.getFields().toArray(new FieldHolder[0])) { FieldReference fieldRef = new FieldReference(cls.getName(), field.getName()); if (dependency.getField(fieldRef) == null) { cls.removeField(field); } } }
MethodDependencyInfo methodDep = dependencyInfo.getMethod(insn.getMethod()); if (methodDep != null) { if (insn.getReceiver() != null) {
MethodDependencyInfo methodDep = dependencyInfo.getMethod(resolvedMethodRef); if (methodDep == null) { continue;
MethodDependencyInfo thisMethodDep = dependencyInfo.getMethod(methodReference); buildPreliminaryGraphs(program, thisMethodDep);
private boolean checkMethod(TextLocation location, MethodReference method) { if (!checkClass(location, method.getClassName())) { return false; } if (!achievableMethods.contains(method) || !dependencyInfo.getMethod(method).isMissing()) { return true; } diagnostics.error(new CallLocation(methodHolder.getReference(), location), "Method {{m0}} was not found", method); emitExceptionThrow(location, NoSuchMethodError.class.getName(), "Method not found: " + method); return true; }
public void infer(Program program, MethodReference methodReference) { MethodDependencyInfo thisMethodDep = dependencyInfo.getMethod(methodReference); buildGraphs(program, thisMethodDep);
MethodDependencyInfo methodDep = dependencyInfo.getMethod(insn.getMethod()); if (methodDep != null) { if (insn.getReceiver() != null) {
public void apply(MethodHolder method) { MethodDependencyInfo methodDep = dependency.getMethod(method.getReference()); if (methodDep == null) { return; } Program program = method.getProgram(); for (int i = 0; i < program.basicBlockCount(); ++i) { BasicBlock block = program.basicBlockAt(i); for (Instruction insn : block) { if (!(insn instanceof InvokeInstruction)) { continue; } InvokeInstruction invoke = (InvokeInstruction) insn; if (invoke.getType() != InvocationType.VIRTUAL) { continue; } ValueDependencyInfo var = methodDep.getVariable(invoke.getInstance().getIndex()); Set<MethodReference> implementations = getImplementations(var.getTypes(), invoke.getMethod()); if (implementations.size() == 1) { invoke.setType(InvocationType.SPECIAL); invoke.setMethod(implementations.iterator().next()); } } } }
MethodDependencyInfo methodDep = dependencyInfo.getMethod(resolvedMethodRef); if (methodDep != null) { if (callSite.receiver >= 0) {
public void link(DependencyInfo dependency, ClassHolder cls) { for (MethodHolder method : cls.getMethods().toArray(new MethodHolder[0])) { MethodReference methodRef = new MethodReference(cls.getName(), method.getDescriptor()); MethodDependencyInfo methodDep = dependency.getMethod(methodRef); if (methodDep == null) { cls.removeMethod(method); } else if (!methodDep.isUsed()) { method.getModifiers().add(ElementModifier.ABSTRACT); method.setProgram(null); } else if (method.getProgram() != null) { link(dependency, method); } } for (FieldHolder field : cls.getFields().toArray(new FieldHolder[0])) { FieldReference fieldRef = new FieldReference(cls.getName(), field.getName()); if (dependency.getField(fieldRef) == null) { cls.removeField(field); } } }