private int indexOfMethod(ClassReader cls, MethodReader method) { int index = 0; for (MethodReader m : cls.getMethods()) { if (m.getDescriptor().equals(method.getDescriptor())) { return index; } ++index; } return -1; }
private MethodReader findOverriddenMethod(String className, MethodReader finalMethod) { if (finalMethod.getName().equals("<init>")) { return null; } return classSource.getAncestors(className) .skip(1) .map(cls -> cls.getMethod(finalMethod.getDescriptor())) .filter(Objects::nonNull) .findFirst() .orElse(null); }
@Override public ReflectMethod[] getDeclaredMethods() { resolve(); if (classReader == null) { return new ReflectMethod[0]; } return classReader.getMethods().stream() .filter(method -> !method.getName().equals("<clinit>")) .map(method -> getDeclaredMethod(method.getDescriptor())) .toArray(ReflectMethod[]::new); }
@Override public boolean optimize(MethodOptimizationContext context, Program program) { return optimize(context.getMethod().getDescriptor(), program); }
private void addPreservedMethods(String ifaceName, Set<MethodDescriptor> methods) { ClassReader iface = classSource.get(ifaceName); for (MethodReader method : iface.getMethods()) { methods.add(method.getDescriptor()); } for (String superIfaceName : iface.getInterfaces()) { addPreservedMethods(superIfaceName, methods); } }
@Override public ReflectMethod[] getMethods() { resolve(); if (classReader == null) { return new ReflectMethod[0]; } if (methodsCache == null) { Set<String> visited = new HashSet<>(); methodsCache = context.getClassSource().getAncestors(classReader.getName()) .flatMap(cls -> cls.getMethods().stream()) .filter(method -> !method.getName().equals("<clinit>")) .filter(method -> visited.add(method.getDescriptor().toString())) .map(method -> context.getClass(ValueType.object(method.getOwnerName())) .getDeclaredMethod(method.getDescriptor())) .filter(Objects::nonNull) .toArray(ReflectMethod[]::new); } return methodsCache.clone(); }
return ""; desc = reader.getDescriptor();
private void collectMethodsToCopyFromInterfacesImpl(ClassReader cls, List<MethodReference> targetList, Set<MethodDescriptor> visited, Set<String> visitedClasses) { if (!visitedClasses.add(cls.getName())) { return; } for (MethodReader method : cls.getMethods()) { if (!method.hasModifier(ElementModifier.STATIC) && !method.hasModifier(ElementModifier.ABSTRACT)) { if (visited.add(method.getDescriptor())) { targetList.add(method.getReference()); } } } for (String ifaceName : cls.getInterfaces()) { ClassReader iface = classSource.get(ifaceName); if (iface != null) { collectMethodsToCopyFromInterfacesImpl(iface, targetList, visited, visitedClasses); } } }
return candidate != null ? getDeclaredMethod(candidate.getDescriptor()) : null; });
continue; if (!exposedCls.inheritedMethods.containsKey(method.getDescriptor())) { String name = method.getName(); AnnotationReader methodAnnot = method.getAnnotations().get(JSMethod.class.getName()); exposedCls.methods.put(method.getDescriptor(), name);
@Override public void methodReached(DependencyAgent agent, MethodDependency methodDep) { MethodModel proxy = describer.getMethod(methodDep.getReference()); if (proxy != null && installedProxies.add(proxy)) { agent.getIncrementalCache().setNoCache(methodDep.getReference()); ClassReader cls = agent.getClassSource().get(methodDep.getMethod().getOwnerName()); int index = 0; for (MethodReader method : cls.getMethods()) { if (method.getDescriptor().equals(methodDep.getMethod().getDescriptor())) { break; } ++index; } new UsageGenerator(agent, proxy, methodDep, proxyClassLoader, index).installProxyEmitter(); } }
continue; VirtualTableEntry entry = table.entries.get(method.getDescriptor()); if (entry != null) { entry.implementor = method.getReference();
static MethodReader findMethod(ClassReaderSource classSource, String clsName, MethodDescriptor desc) { ClassReader cls = classSource.get(clsName); if (cls == null) { return null; } for (MethodReader method : cls.getMethods()) { if (method.getName().equals(desc.getName()) && sameParams(method.getDescriptor(), desc)) { return method; } } if (cls.getParent() != null) { MethodReader result = findMethod(classSource, cls.getParent(), desc); if (result != null) { return result; } } for (String iface : cls.getInterfaces()) { MethodReader result = findMethod(classSource, iface, desc); if (result != null) { return result; } } return null; }
private boolean processIndexer(MethodReader method, CallLocation callLocation, InvokeInstruction invoke) { if (isProperGetIndexer(method.getDescriptor())) { Variable result = invoke.getReceiver() != null ? program.createVariable() : null; addIndexerGet(invoke.getInstance(), marshaller.wrapArgument(callLocation, invoke.getArguments().get(0), method.parameterType(0), false), result, invoke.getLocation()); if (result != null) { result = marshaller.unwrapReturnValue(callLocation, result, method.getResultType()); copyVar(result, invoke.getReceiver(), invoke.getLocation()); } return true; } if (isProperSetIndexer(method.getDescriptor())) { Variable index = marshaller.wrapArgument(callLocation, invoke.getArguments().get(0), method.parameterType(0), false); Variable value = marshaller.wrapArgument(callLocation, invoke.getArguments().get(1), method.parameterType(1), false); addIndexerSet(invoke.getInstance(), index, value, invoke.getLocation()); return true; } diagnostics.error(callLocation, "Method {{m0}} is not a proper native JavaScript indexer " + "declaration", invoke.getMethod()); return false; }
private void findInheritedMethods(ClassReader cls, Set<MethodDescriptor> methods, Set<String> visited) { if (!visited.add(cls.getName())) { return; } if (typeHelper.isJavaScriptClass(cls.getName())) { for (MethodReader method : cls.getMethods()) { if (!method.hasModifier(ElementModifier.STATIC) && !method.hasModifier(ElementModifier.FINAL) && method.getLevel() != AccessLevel.PRIVATE) { methods.add(method.getDescriptor()); } } } else if (typeHelper.isJavaScriptImplementation(cls.getName())) { if (cls.getParent() != null) { ClassReader parentCls = classSource.get(cls.getParent()); if (parentCls != null) { findInheritedMethods(parentCls, methods, visited); } } for (String iface : cls.getInterfaces()) { ClassReader parentCls = classSource.get(iface); if (parentCls != null) { findInheritedMethods(parentCls, methods, visited); } } } }
String methodAlias = getPublicAlias(method); if (methodAlias != null) { methods.put(method.getDescriptor(), methodAlias);
public static MethodHolder copyMethod(MethodReader method, boolean withProgram) { MethodHolder copy = new MethodHolder(method.getDescriptor()); copy.setLevel(method.getLevel()); copy.getModifiers().addAll(method.readModifiers()); if (method.getProgram() != null && withProgram) { copy.setProgram(ProgramUtils.copy(method.getProgram())); } copyAnnotations(method.getAnnotations(), copy.getAnnotations()); if (method.getAnnotationDefault() != null) { copy.setAnnotationDefault(copyAnnotationValue(method.getAnnotationDefault())); } for (int i = 0; i < method.parameterCount(); ++i) { copyAnnotations(method.parameterAnnotation(i), copy.parameterAnnotation(i)); } return copy; }
implementor.addField(field); MethodHolder accessor = new MethodHolder(methodDecl.getDescriptor()); ProgramEmitter pe = ProgramEmitter.create(accessor, hierarchy); ValueEmitter thisVal = pe.var(0, implementor);
if (accessibleMethods != null && accessibleMethods.contains(method.getDescriptor())) { renderCallable(writer, method); } else {
@Override public boolean optimize(MethodOptimizationContext context, Program program) { NullnessInformation nullness = NullnessInformation.build(program, context.getMethod().getDescriptor());