MethodHolder methodHolder = classHolder.getMethod(getDescriptor(child)); Set<Class<?>> expectedExceptions = new HashSet<>(); for (String exceptionName : getExpectedExceptions(methodHolder)) {
@Override public void transformClass(ClassHolder cls, ClassHolderTransformerContext context) { for (MethodHolder method : cls.getMethods()) { if (method.hasModifier(ElementModifier.NATIVE) && method.getAnnotations().get(Async.class.getName()) != null && method.getAnnotations().get(GeneratedBy.class.getName()) == null) { ValueType[] signature = new ValueType[method.parameterCount() + 2]; for (int i = 0; i < method.parameterCount(); ++i) { signature[i] = method.parameterType(i); } signature[method.parameterCount()] = ValueType.parse(AsyncCallback.class); signature[method.parameterCount() + 1] = ValueType.VOID; MethodDescriptor asyncDesc = new MethodDescriptor(method.getName(), signature); MethodHolder asyncMethod = cls.getMethod(asyncDesc); if (asyncMethod != null) { if (asyncMethod.hasModifier(ElementModifier.STATIC) != method.hasModifier(ElementModifier.STATIC)) { context.getDiagnostics().error(new CallLocation(method.getReference()), "Methods {{m0}} and {{m1}} must both be either static or non-static", method.getReference(), asyncMethod.getReference()); } } } } } }
MethodHolder methodHolder = classHolder.getMethod(getDescriptor(method));
signature[method.parameterCount() + 1] = ValueType.VOID; MethodDescriptor asyncDesc = new MethodDescriptor(method.getName(), signature); MethodHolder asyncMethod = cls.getMethod(asyncDesc); if (asyncMethod != null) { if (asyncMethod.hasModifier(ElementModifier.STATIC)
public WasmFunction generateDefinition(MethodReference methodReference) { ClassHolder cls = classSource.get(methodReference.getClassName()); MethodHolder method = cls.getMethod(methodReference.getDescriptor()); WasmFunction function = new WasmFunction(names.forMethod(method.getReference())); if (!method.hasModifier(ElementModifier.STATIC)) { function.getParameters().add(WasmType.INT32); } for (int i = 0; i < method.parameterCount(); ++i) { function.getParameters().add(WasmGeneratorUtil.mapType(method.parameterType(i))); } if (method.getResultType() != ValueType.VOID) { function.setResult(WasmGeneratorUtil.mapType(method.getResultType())); } return function; }
throw new IllegalArgumentException("Class not found: " + methodRef.getClassName()); if (cls.getMethod(methodRef.getDescriptor()) != null) { throw new IllegalArgumentException("Method already exists: " + methodRef.getClassName());
public WasmFunction generate(MethodReference methodReference, MethodHolder bodyMethod) { ClassHolder cls = classSource.get(methodReference.getClassName()); MethodHolder method = cls.getMethod(methodReference.getDescriptor()); RegularMethodNode methodAst = decompiler.decompileRegular(bodyMethod); WasmFunction function = context.getFunction(names.forMethod(methodReference)); int firstVariable = method.hasModifier(ElementModifier.STATIC) ? 1 : 0; for (int i = firstVariable; i < methodAst.getVariables().size(); ++i) { VariableNode variable = methodAst.getVariables().get(i); WasmType type = variable.getType() != null ? WasmGeneratorUtil.mapType(variable.getType()) : WasmType.INT32; function.add(new WasmLocal(type, variable.getName())); } WasmGenerationVisitor visitor = new WasmGenerationVisitor(context, classGenerator, binaryWriter, function, firstVariable); methodAst.getBody().acceptVisitor(visitor); if (visitor.result instanceof WasmBlock) { ((WasmBlock) visitor.result).setType(function.getResult()); } function.getBody().add(visitor.result); AnnotationReader exportAnnot = method.getAnnotations().get(Export.class.getName()); if (exportAnnot != null) { function.setExportName(exportAnnot.getValue("name").getString()); } return function; }
private void transformCompareMethod(ClassHolder cls, ValueType type, NumericOperandType insnType) { MethodHolder method = cls.getMethod(new MethodDescriptor("compare", type, type, ValueType.INTEGER)); Program program = new Program(); program.createVariable(); Variable firstArg = program.createVariable(); Variable secondArg = program.createVariable(); Variable result = program.createVariable(); BasicBlock block = program.createBasicBlock(); BinaryInstruction insn = new BinaryInstruction(BinaryOperation.COMPARE, insnType); insn.setFirstOperand(firstArg); insn.setSecondOperand(secondArg); insn.setReceiver(result); block.add(insn); ExitInstruction exit = new ExitInstruction(); exit.setValueToReturn(result); block.add(exit); method.setProgram(program); method.getModifiers().remove(ElementModifier.NATIVE); } }
MethodHolder methodToCall = classHolder.getMethod(method); JSClassProcessor.makeSync(methodToCall != null ? methodToCall : exportedMethod);
private List<Method> getChildren() { List<Method> children = new ArrayList<>(); for (Method method : testClass.getDeclaredMethods()) { MethodHolder methodHolder = classHolder.getMethod(getDescriptor(method)); if (testAdapter.acceptMethod(methodHolder)) { children.add(method); } } return children; }
private void transformControllers(final ClassHolder cls, ClassReaderSource classSource) { MethodDescriptor desc = new MethodDescriptor("initialize", void.class); cls.removeMethod(cls.getMethod(desc)); ClassReader patchClass = classSource.get(ControllersEmulator.class.getName()); MethodHolder patch = ModelUtils.copyMethod(patchClass.getMethod(desc)); ClassRefsRenamer renamer = new ClassRefsRenamer(preimage -> { if (preimage.equals(ControllersEmulator.class.getName())) { return Controllers.class.getName(); } return preimage; }); cls.addMethod(renamer.rename(patch)); } }
private void replaceMethods(ClassHolder cls, Class<?> emuType, ClassReaderSource innerSource, List<MethodDescriptor> descList) { ClassReader emuCls = innerSource.get(emuType.getName()); for (MethodDescriptor methodDesc : descList) { cls.removeMethod(cls.getMethod(methodDesc)); cls.addMethod(ModelUtils.copyMethod(emuCls.getMethod(methodDesc))); } }
boolean success = true; MethodHolder methodHolder = classHolder.getMethod(getDescriptor(child)); Set<Class<?>> expectedExceptions = new HashSet<>(); for (String exceptionName : testAdapter.getExpectedExceptions(methodHolder)) {
ClassHolderSource classSource = getClassSource(classLoader); MethodHolder methodHolder = classHolder.getMethod(getDescriptor(method)); Class<?> runnerType = testAdapter.getRunner(methodHolder);
throw new IllegalArgumentException("Class not found: " + methodRef.getClassName()); if (cls.getMethod(methodRef.getDescriptor()) != null) { throw new IllegalArgumentException("Method already exists: " + methodRef.getClassName());
public WasmFunction generateDefinition(MethodReference methodReference) { ClassHolder cls = classSource.get(methodReference.getClassName()); MethodHolder method = cls.getMethod(methodReference.getDescriptor()); WasmFunction function = new WasmFunction(WasmMangling.mangleMethod(method.getReference())); if (!method.hasModifier(ElementModifier.STATIC)) { function.getParameters().add(WasmType.INT32); } for (int i = 0; i < method.parameterCount(); ++i) { function.getParameters().add(WasmGeneratorUtil.mapType(method.parameterType(i))); } if (method.getResultType() != ValueType.VOID) { function.setResult(WasmGeneratorUtil.mapType(method.getResultType())); } return function; }
public WasmFunction generate(MethodReference methodReference, MethodHolder bodyMethod) { ClassHolder cls = classSource.get(methodReference.getClassName()); MethodHolder method = cls.getMethod(methodReference.getDescriptor()); RegularMethodNode methodAst = decompiler.decompileRegular(bodyMethod); WasmFunction function = context.getFunction(WasmMangling.mangleMethod(methodReference)); int firstVariable = method.hasModifier(ElementModifier.STATIC) ? 1 : 0; for (int i = firstVariable; i < methodAst.getVariables().size(); ++i) { VariableNode variable = methodAst.getVariables().get(i); WasmType type = variable.getType() != null ? WasmGeneratorUtil.mapType(variable.getType()) : WasmType.INT32; function.add(new WasmLocal(type, variable.getName())); } WasmGenerationVisitor visitor = new WasmGenerationVisitor(context, classGenerator, binaryWriter, function, firstVariable); methodAst.getBody().acceptVisitor(visitor); if (visitor.result instanceof WasmBlock) { ((WasmBlock) visitor.result).setType(function.getResult()); } function.getBody().add(visitor.result); AnnotationReader exportAnnot = method.getAnnotations().get(Export.class.getName()); if (exportAnnot != null) { function.setExportName(exportAnnot.getValue("name").getString()); } return function; }