ClassMethod(String name, String returnType, String[] parameters, int accessFlags, ClassFile classFile) { ConstPool constPool = classFile.getConstPool(); this.classFile = classFile; this.returnType = DescriptorUtils.validateDescriptor(returnType); this.parameters = parameters; this.name = name; this.descriptor = DescriptorUtils.methodDescriptor(parameters, returnType); this.accessFlags = accessFlags; this.nameIndex = constPool.addUtf8Entry(name); this.descriptorIndex = constPool.addUtf8Entry(descriptor); this.constructor = name.equals("<init>"); this.exceptionsAttribute = new ExceptionsAttribute(constPool); this.attributes.add(exceptionsAttribute); if (Modifier.isAbstract(accessFlags)) { codeAttribute = null; } else { codeAttribute = new CodeAttribute(this, constPool); attributes.add(codeAttribute); } for (String param : this.parameters) { DescriptorUtils.validateDescriptor(param); } this.runtimeVisibleAnnotationsAttribute = new AnnotationsAttribute(AnnotationsAttribute.Type.RUNTIME_VISIBLE, constPool); this.attributes.add(runtimeVisibleAnnotationsAttribute); this.runtimeVisibleParameterAnnotationsAttribute = new ParameterAnnotationsAttribute( ParameterAnnotationsAttribute.Type.RUNTIME_VISIBLE, constPool, parameters.length); this.attributes.add(runtimeVisibleParameterAnnotationsAttribute); }
/** * Adds a method with the same signiture as the given method, including exception types * <p> * The new method will have the same modifier as the original method, except that the abstract and native flags will be * stripped. * <p> * TODO: annotations and signiture attribute */ public ClassMethod addMethod(Method method) { ClassMethod classMethod = addMethod(method.getModifiers() & (~AccessFlag.ABSTRACT) & (~AccessFlag.NATIVE), method .getName(), DescriptorUtils.makeDescriptor(method.getReturnType()), DescriptorUtils.parameterDescriptors(method .getParameterTypes())); for (Class<?> e : method.getExceptionTypes()) { classMethod.addCheckedExceptions((Class<? extends Exception>) e); } for (Annotation annotation : method.getDeclaredAnnotations()) { classMethod.getRuntimeVisibleAnnotationsAttribute().addAnnotation( AnnotationBuilder.createAnnotation(constPool, annotation)); } int count = 0; for (Annotation[] parameterAnnotations : method.getParameterAnnotations()) { for (Annotation annotation : parameterAnnotations) { classMethod.getRuntimeVisibleParameterAnnotationsAttribute().addAnnotation(count, AnnotationBuilder.createAnnotation(constPool, annotation)); } count++; } return classMethod; }
/** * Adds a method with the same signiture as the given method, including exception types * <p> * The new method will have the same modifier as the original method, except that the abstract and native flags will be * stripped. * <p> * TODO: annotations and signiture attribute */ public ClassMethod addMethod(Method method) { ClassMethod classMethod = addMethod(method.getModifiers() & (~AccessFlag.ABSTRACT) & (~AccessFlag.NATIVE), method .getName(), DescriptorUtils.makeDescriptor(method.getReturnType()), DescriptorUtils.parameterDescriptors(method .getParameterTypes())); for (Class<?> e : method.getExceptionTypes()) { classMethod.addCheckedExceptions((Class<? extends Exception>) e); } for (Annotation annotation : method.getDeclaredAnnotations()) { classMethod.getRuntimeVisibleAnnotationsAttribute().addAnnotation( AnnotationBuilder.createAnnotation(constPool, annotation)); } int count = 0; for (Annotation[] parameterAnnotations : method.getParameterAnnotations()) { for (Annotation annotation : parameterAnnotations) { classMethod.getRuntimeVisibleParameterAnnotationsAttribute().addAnnotation(count, AnnotationBuilder.createAnnotation(constPool, annotation)); } count++; } return classMethod; }
ClassMethod(String name, String returnType, String[] parameters, int accessFlags, ClassFile classFile) { ConstPool constPool = classFile.getConstPool(); this.classFile = classFile; this.returnType = DescriptorUtils.validateDescriptor(returnType); this.parameters = parameters; this.name = name; this.descriptor = DescriptorUtils.methodDescriptor(parameters, returnType); this.accessFlags = accessFlags; this.nameIndex = constPool.addUtf8Entry(name); this.descriptorIndex = constPool.addUtf8Entry(descriptor); this.constructor = name.equals("<init>"); this.exceptionsAttribute = new ExceptionsAttribute(constPool); this.attributes.add(exceptionsAttribute); if (Modifier.isAbstract(accessFlags)) { codeAttribute = null; } else { codeAttribute = new CodeAttribute(this, constPool); attributes.add(codeAttribute); } for (String param : this.parameters) { DescriptorUtils.validateDescriptor(param); } this.runtimeVisibleAnnotationsAttribute = new AnnotationsAttribute(AnnotationsAttribute.Type.RUNTIME_VISIBLE, constPool); this.attributes.add(runtimeVisibleAnnotationsAttribute); this.runtimeVisibleParameterAnnotationsAttribute = new ParameterAnnotationsAttribute( ParameterAnnotationsAttribute.Type.RUNTIME_VISIBLE, constPool, parameters.length); this.attributes.add(runtimeVisibleParameterAnnotationsAttribute); }
/** * Adds a method with the same signiture as the given method, including exception types * <p> * The new method will have the same modifier as the original method, except that the abstract and native flags will be * stripped. * <p> * TODO: annotations and signiture attribute */ public ClassMethod addMethod(Method method) { ClassMethod classMethod = addMethod(method.getModifiers() & (~AccessFlag.ABSTRACT) & (~AccessFlag.NATIVE), method .getName(), DescriptorUtils.makeDescriptor(method.getReturnType()), DescriptorUtils.parameterDescriptors(method .getParameterTypes())); for (Class<?> e : method.getExceptionTypes()) { classMethod.addCheckedExceptions((Class<? extends Exception>) e); } for (Annotation annotation : method.getDeclaredAnnotations()) { classMethod.getRuntimeVisibleAnnotationsAttribute().addAnnotation( AnnotationBuilder.createAnnotation(constPool, annotation)); } int count = 0; for (Annotation[] parameterAnnotations : method.getParameterAnnotations()) { for (Annotation annotation : parameterAnnotations) { classMethod.getRuntimeVisibleParameterAnnotationsAttribute().addAnnotation(count, AnnotationBuilder.createAnnotation(constPool, annotation)); } count++; } return classMethod; }
ClassMethod(String name, String returnType, String[] parameters, int accessFlags, ClassFile classFile) { ConstPool constPool = classFile.getConstPool(); this.classFile = classFile; this.returnType = DescriptorUtils.validateDescriptor(returnType); this.parameters = parameters; this.name = name; this.descriptor = DescriptorUtils.methodDescriptor(parameters, returnType); this.accessFlags = accessFlags; this.nameIndex = constPool.addUtf8Entry(name); this.descriptorIndex = constPool.addUtf8Entry(descriptor); this.constructor = name.equals("<init>"); this.exceptionsAttribute = new ExceptionsAttribute(constPool); this.attributes.add(exceptionsAttribute); if (Modifier.isAbstract(accessFlags)) { codeAttribute = null; } else { codeAttribute = new CodeAttribute(this, constPool); attributes.add(codeAttribute); } for (String param : this.parameters) { DescriptorUtils.validateDescriptor(param); } this.runtimeVisibleAnnotationsAttribute = new AnnotationsAttribute(AnnotationsAttribute.Type.RUNTIME_VISIBLE, constPool); this.attributes.add(runtimeVisibleAnnotationsAttribute); this.runtimeVisibleParameterAnnotationsAttribute = new ParameterAnnotationsAttribute( ParameterAnnotationsAttribute.Type.RUNTIME_VISIBLE, constPool, parameters.length); this.attributes.add(runtimeVisibleParameterAnnotationsAttribute); }
/** * Adds a method with the same signiture as the given method, including exception types * <p> * The new method will have the same modifier as the original method, except that the abstract and native flags will be * stripped. * <p> * TODO: annotations and signiture attribute */ public ClassMethod addMethod(Method method) { ClassMethod classMethod = addMethod(method.getModifiers() & (~AccessFlag.ABSTRACT) & (~AccessFlag.NATIVE), method .getName(), DescriptorUtils.makeDescriptor(method.getReturnType()), DescriptorUtils.parameterDescriptors(method .getParameterTypes())); for (Class<?> e : method.getExceptionTypes()) { classMethod.addCheckedExceptions((Class<? extends Exception>) e); } for (Annotation annotation : method.getDeclaredAnnotations()) { classMethod.getRuntimeVisibleAnnotationsAttribute().addAnnotation( AnnotationBuilder.createAnnotation(constPool, annotation)); } int count = 0; for (Annotation[] parameterAnnotations : method.getParameterAnnotations()) { for (Annotation annotation : parameterAnnotations) { classMethod.getRuntimeVisibleParameterAnnotationsAttribute().addAnnotation(count, AnnotationBuilder.createAnnotation(constPool, annotation)); } count++; } return classMethod; }
ClassMethod(String name, String returnType, String[] parameters, int accessFlags, ClassFile classFile) { ConstPool constPool = classFile.getConstPool(); this.classFile = classFile; this.returnType = DescriptorUtils.validateDescriptor(returnType); this.parameters = parameters; this.name = name; this.descriptor = DescriptorUtils.methodDescriptor(parameters, returnType); this.accessFlags = accessFlags; this.nameIndex = constPool.addUtf8Entry(name); this.descriptorIndex = constPool.addUtf8Entry(descriptor); this.constructor = name.equals("<init>"); this.exceptionsAttribute = new ExceptionsAttribute(constPool); this.attributes.add(exceptionsAttribute); if (Modifier.isAbstract(accessFlags)) { codeAttribute = null; } else { codeAttribute = new CodeAttribute(this, constPool); attributes.add(codeAttribute); } for (String param : this.parameters) { DescriptorUtils.validateDescriptor(param); } this.runtimeVisibleAnnotationsAttribute = new AnnotationsAttribute(AnnotationsAttribute.Type.RUNTIME_VISIBLE, constPool); this.attributes.add(runtimeVisibleAnnotationsAttribute); this.runtimeVisibleParameterAnnotationsAttribute = new ParameterAnnotationsAttribute( ParameterAnnotationsAttribute.Type.RUNTIME_VISIBLE, constPool, parameters.length); this.attributes.add(runtimeVisibleParameterAnnotationsAttribute); }
/** * Adds a method with the same signiture as the given method, including exception types * <p> * The new method will have the same modifier as the original method, except that the abstract and native flags will be * stripped. * <p> * TODO: annotations and signiture attribute */ public ClassMethod addMethod(Method method) { ClassMethod classMethod = addMethod(method.getModifiers() & (~AccessFlag.ABSTRACT) & (~AccessFlag.NATIVE), method .getName(), DescriptorUtils.makeDescriptor(method.getReturnType()), DescriptorUtils.parameterDescriptors(method .getParameterTypes())); for (Class<?> e : method.getExceptionTypes()) { classMethod.addCheckedExceptions((Class<? extends Exception>) e); } for (Annotation annotation : method.getDeclaredAnnotations()) { classMethod.getRuntimeVisibleAnnotationsAttribute().addAnnotation( AnnotationBuilder.createAnnotation(constPool, annotation)); } int count = 0; for (Annotation[] parameterAnnotations : method.getParameterAnnotations()) { for (Annotation annotation : parameterAnnotations) { classMethod.getRuntimeVisibleParameterAnnotationsAttribute().addAnnotation(count, AnnotationBuilder.createAnnotation(constPool, annotation)); } count++; } return classMethod; }
ClassMethod(String name, String returnType, String[] parameters, int accessFlags, ClassFile classFile) { ConstPool constPool = classFile.getConstPool(); this.classFile = classFile; this.returnType = DescriptorUtils.validateDescriptor(returnType); this.parameters = parameters; this.name = name; this.descriptor = DescriptorUtils.methodDescriptor(parameters, returnType); this.accessFlags = accessFlags; this.nameIndex = constPool.addUtf8Entry(name); this.descriptorIndex = constPool.addUtf8Entry(descriptor); this.constructor = name.equals("<init>"); this.exceptionsAttribute = new ExceptionsAttribute(constPool); this.attributes.add(exceptionsAttribute); if (Modifier.isAbstract(accessFlags)) { codeAttribute = null; } else { codeAttribute = new CodeAttribute(this, constPool); attributes.add(codeAttribute); } for (String param : this.parameters) { DescriptorUtils.validateDescriptor(param); } this.runtimeVisibleAnnotationsAttribute = new AnnotationsAttribute(AnnotationsAttribute.Type.RUNTIME_VISIBLE, constPool); this.attributes.add(runtimeVisibleAnnotationsAttribute); this.runtimeVisibleParameterAnnotationsAttribute = new ParameterAnnotationsAttribute( ParameterAnnotationsAttribute.Type.RUNTIME_VISIBLE, constPool, parameters.length); this.attributes.add(runtimeVisibleParameterAnnotationsAttribute); }
/** * Adds a constructor with the same signiture as the given constrcutor, including exception types * <p> * TODO: annotations and signiture attribute */ public ClassMethod addConstructor(Constructor<?> method) { ClassMethod classMethod = addMethod(method.getModifiers(), "<init>", "V", DescriptorUtils.parameterDescriptors(method .getParameterTypes())); for (Class<?> e : method.getExceptionTypes()) { classMethod.addCheckedExceptions((Class<? extends Exception>) e); } for (Annotation annotation : method.getDeclaredAnnotations()) { classMethod.getRuntimeVisibleAnnotationsAttribute().addAnnotation( AnnotationBuilder.createAnnotation(constPool, annotation)); } int count = 0; for (Annotation[] parameterAnnotations : method.getParameterAnnotations()) { for (Annotation annotation : parameterAnnotations) { classMethod.getRuntimeVisibleParameterAnnotationsAttribute().addAnnotation(count, AnnotationBuilder.createAnnotation(constPool, annotation)); } count++; } return classMethod; }
/** * Adds a constructor with the same signiture as the given constrcutor, including exception types * <p> * TODO: annotations and signiture attribute */ public ClassMethod addConstructor(Constructor<?> method) { ClassMethod classMethod = addMethod(method.getModifiers(), "<init>", "V", DescriptorUtils.parameterDescriptors(method .getParameterTypes())); for (Class<?> e : method.getExceptionTypes()) { classMethod.addCheckedExceptions((Class<? extends Exception>) e); } for (Annotation annotation : method.getDeclaredAnnotations()) { classMethod.getRuntimeVisibleAnnotationsAttribute().addAnnotation( AnnotationBuilder.createAnnotation(constPool, annotation)); } int count = 0; for (Annotation[] parameterAnnotations : method.getParameterAnnotations()) { for (Annotation annotation : parameterAnnotations) { classMethod.getRuntimeVisibleParameterAnnotationsAttribute().addAnnotation(count, AnnotationBuilder.createAnnotation(constPool, annotation)); } count++; } return classMethod; }
/** * Adds a constructor with the same signiture as the given constrcutor, including exception types * <p> * TODO: annotations and signiture attribute */ public ClassMethod addConstructor(Constructor<?> method) { ClassMethod classMethod = addMethod(method.getModifiers(), "<init>", "V", DescriptorUtils.parameterDescriptors(method .getParameterTypes())); for (Class<?> e : method.getExceptionTypes()) { classMethod.addCheckedExceptions((Class<? extends Exception>) e); } for (Annotation annotation : method.getDeclaredAnnotations()) { classMethod.getRuntimeVisibleAnnotationsAttribute().addAnnotation( AnnotationBuilder.createAnnotation(constPool, annotation)); } int count = 0; for (Annotation[] parameterAnnotations : method.getParameterAnnotations()) { for (Annotation annotation : parameterAnnotations) { classMethod.getRuntimeVisibleParameterAnnotationsAttribute().addAnnotation(count, AnnotationBuilder.createAnnotation(constPool, annotation)); } count++; } return classMethod; }
/** * Adds a constructor with the same signiture as the given constrcutor, including exception types * <p> * TODO: annotations and signiture attribute */ public ClassMethod addConstructor(Constructor<?> method) { ClassMethod classMethod = addMethod(method.getModifiers(), "<init>", "V", DescriptorUtils.parameterDescriptors(method .getParameterTypes())); for (Class<?> e : method.getExceptionTypes()) { classMethod.addCheckedExceptions((Class<? extends Exception>) e); } for (Annotation annotation : method.getDeclaredAnnotations()) { classMethod.getRuntimeVisibleAnnotationsAttribute().addAnnotation( AnnotationBuilder.createAnnotation(constPool, annotation)); } int count = 0; for (Annotation[] parameterAnnotations : method.getParameterAnnotations()) { for (Annotation annotation : parameterAnnotations) { classMethod.getRuntimeVisibleParameterAnnotationsAttribute().addAnnotation(count, AnnotationBuilder.createAnnotation(constPool, annotation)); } count++; } return classMethod; }
/** * Adds a constructor with the same signiture as the given constrcutor, including exception types * <p> * TODO: annotations and signiture attribute */ public ClassMethod addConstructor(Constructor<?> method) { ClassMethod classMethod = addMethod(method.getModifiers(), "<init>", "V", DescriptorUtils.parameterDescriptors(method .getParameterTypes())); for (Class<?> e : method.getExceptionTypes()) { classMethod.addCheckedExceptions((Class<? extends Exception>) e); } for (Annotation annotation : method.getDeclaredAnnotations()) { classMethod.getRuntimeVisibleAnnotationsAttribute().addAnnotation( AnnotationBuilder.createAnnotation(constPool, annotation)); } int count = 0; for (Annotation[] parameterAnnotations : method.getParameterAnnotations()) { for (Annotation annotation : parameterAnnotations) { classMethod.getRuntimeVisibleParameterAnnotationsAttribute().addAnnotation(count, AnnotationBuilder.createAnnotation(constPool, annotation)); } count++; } return classMethod; }