public AbstractParserGenerator(final String parseStateClass, final String resultClass, final String constructorDescriptor, String existingClassName) { this.parseStateClass = parseStateClass; this.resultClass = resultClass; this.existingClassName = existingClassName; parseStateDescriptor = DescriptorUtils.makeDescriptor(parseStateClass); httpExchangeDescriptor = DescriptorUtils.makeDescriptor(resultClass); this.constructorDescriptor = constructorDescriptor; }
private void setupLocalVariables(final CodeAttribute c) { c.setupFrame(DescriptorUtils.makeDescriptor(existingClassName + CLASS_NAME_SUFFIX), DescriptorUtils.makeDescriptor(ByteBuffer.class), parseStateDescriptor, httpExchangeDescriptor, "I", "I", HTTP_STRING_DESCRIPTOR, DescriptorUtils.makeDescriptor(StringBuilder.class), "[B"); }
protected void createStateMachine(final String[] originalItems, final String className, final ClassFile file, final ClassMethod sctor, final AtomicInteger fieldCounter, final String methodName, final CustomStateMachine stateMachine, boolean expectNewline) { //list of all states except the initial final List<State> allStates = new ArrayList<State>(); final State initial = new State((byte) 0, ""); for (String value : originalItems) { addStates(initial, value, allStates); } //we want initial to be number 0 final AtomicInteger stateCounter = new AtomicInteger(-1); setupStateNo(initial, stateCounter, fieldCounter); for (State state : allStates) { setupStateNo(state, stateCounter, fieldCounter); createStateField(state, file, sctor.getCodeAttribute()); } final int noStates = stateCounter.get(); final ClassMethod handle = file.addMethod(Modifier.PROTECTED | Modifier.FINAL, methodName, "V", DescriptorUtils.makeDescriptor(ByteBuffer.class), parseStateDescriptor, httpExchangeDescriptor); handle.addCheckedExceptions(BAD_REQUEST_EXCEPTION); writeStateMachine(className, file, handle.getCodeAttribute(), initial, allStates, noStates, stateMachine, expectNewline); }
} else { ca.iload(index); Boxing.boxIfNessesary(ca, DescriptorUtils.makeDescriptor(type)); invoke += (Character.toUpperCase(typeName.charAt(0)) + typeName.substring(1)); ret = DescriptorUtils.makeDescriptor(returnType);
public byte[] createTokenizer(final String[] httpVerbs, String[] httpVersions, String[] standardHeaders) { final String className = existingClassName + CLASS_NAME_SUFFIX; final ClassFile file = new ClassFile(className, existingClassName); final ClassMethod ctor = file.addMethod(AccessFlag.PUBLIC, "<init>", "V", DescriptorUtils.parameterDescriptors(constructorDescriptor)); ctor.getCodeAttribute().aload(0); ctor.getCodeAttribute().loadMethodParameters(); ctor.getCodeAttribute().invokespecial(existingClassName, "<init>", constructorDescriptor); ctor.getCodeAttribute().returnInstruction(); final ClassMethod sctor = file.addMethod(AccessFlag.PUBLIC | AccessFlag.STATIC, "<clinit>", "V"); final AtomicInteger fieldCounter = new AtomicInteger(1); sctor.getCodeAttribute().invokestatic(existingClassName, "httpStrings", "()" + DescriptorUtils.makeDescriptor(Map.class)); sctor.getCodeAttribute().astore(CONSTRUCTOR_HTTP_STRING_MAP_VAR); createStateMachines(httpVerbs, httpVersions, standardHeaders, className, file, sctor, fieldCounter); sctor.getCodeAttribute().returnInstruction(); return file.toBytecode(); }
c.getfield(parseStateClass, "stringBuilder", DescriptorUtils.makeDescriptor(StringBuilder.class)); c.astore(STATE_STRING_BUILDER_VAR); c.dup();
public static String[] parameterDescriptors(Class<?>[] parameters) { String[] ret = new String[parameters.length]; for (int i = 0; i < ret.length; ++i) { ret[i] = DescriptorUtils.makeDescriptor(parameters[i]); } return ret; }
/** * returns the type descriptor for the class * * @return */ public String getDescriptor() { return DescriptorUtils.makeDescriptor(name); }
public static String methodDescriptor(Method m) { StringBuilder desc = new StringBuilder("("); for (Class<?> p : m.getParameterTypes()) { desc.append(DescriptorUtils.makeDescriptor(p)); } desc.append(")"); desc.append(DescriptorUtils.makeDescriptor(m.getReturnType())); return desc.toString(); }
public static String methodDescriptor(Method m) { StringBuilder desc = new StringBuilder("("); for (Class<?> p : m.getParameterTypes()) { desc.append(DescriptorUtils.makeDescriptor(p)); } desc.append(")"); desc.append(DescriptorUtils.makeDescriptor(m.getReturnType())); return desc.toString(); }
/** * Generates the apprpriate load instruction for the given type * * @param type The type of variable * @param no local variable number */ public void load(Class<?> type, int no) { load(DescriptorUtils.makeDescriptor(type), no); }
public void invokeinterface(Method method) { if (Modifier.isStatic(method.getModifiers())) { throw new InvalidBytecodeException("Cannot use invokeinterface to invoke a static method"); } else if (Modifier.isPrivate(method.getModifiers())) { throw new InvalidBytecodeException("Cannot use invokeinterface to invoke a private method"); } else if (!method.getDeclaringClass().isInterface()) { throw new InvalidBytecodeException("Cannot use invokeinterface to invoke a non interface method"); } invokeinterface(method.getDeclaringClass().getName(), method.getName(), DescriptorUtils.methodDescriptor(method), DescriptorUtils.makeDescriptor(method.getReturnType()), DescriptorUtils.parameterDescriptors(method .getParameterTypes())); }
public void invokevirtual(Method method) { if (Modifier.isStatic(method.getModifiers())) { throw new InvalidBytecodeException("Cannot use invokevirtual to invoke a static method"); } else if (Modifier.isPrivate(method.getModifiers())) { throw new InvalidBytecodeException("Cannot use invokevirtual to invoke a private method"); } else if (method.getDeclaringClass().isInterface()) { throw new InvalidBytecodeException("Cannot use invokevirtual to invoke an interface method"); } invokevirtual(method.getDeclaringClass().getName(), method.getName(), DescriptorUtils.methodDescriptor(method), DescriptorUtils.makeDescriptor(method.getReturnType()), DescriptorUtils.parameterDescriptors(method .getParameterTypes())); }
public void invokeinterface(Method method) { if (Modifier.isStatic(method.getModifiers())) { throw new InvalidBytecodeException("Cannot use invokeinterface to invoke a static method"); } else if (Modifier.isPrivate(method.getModifiers())) { throw new InvalidBytecodeException("Cannot use invokeinterface to invoke a private method"); } else if (!method.getDeclaringClass().isInterface()) { throw new InvalidBytecodeException("Cannot use invokeinterface to invoke a non interface method"); } invokeinterface(method.getDeclaringClass().getName(), method.getName(), DescriptorUtils.methodDescriptor(method), DescriptorUtils.makeDescriptor(method.getReturnType()), DescriptorUtils.parameterDescriptors(method .getParameterTypes())); }
public void invokevirtual(Method method) { if (Modifier.isStatic(method.getModifiers())) { throw new InvalidBytecodeException("Cannot use invokevirtual to invoke a static method"); } else if (Modifier.isPrivate(method.getModifiers())) { throw new InvalidBytecodeException("Cannot use invokevirtual to invoke a private method"); } else if (method.getDeclaringClass().isInterface()) { throw new InvalidBytecodeException("Cannot use invokevirtual to invoke an interface method"); } invokevirtual(method.getDeclaringClass().getName(), method.getName(), DescriptorUtils.methodDescriptor(method), DescriptorUtils.makeDescriptor(method.getReturnType()), DescriptorUtils.parameterDescriptors(method .getParameterTypes())); }
@SuppressWarnings("unchecked") private void createDelegateMethod(ClassFile proxyClassType, Method method, MethodInformation methodInformation) { int modifiers = (method.getModifiers() | AccessFlag.SYNTHETIC | AccessFlag.PRIVATE) & ~AccessFlag.PUBLIC & ~AccessFlag.PROTECTED; ClassMethod delegatingMethod = proxyClassType.addMethod(modifiers, method.getName() + SUPER_DELEGATE_SUFFIX, DescriptorUtils.makeDescriptor(method.getReturnType()), DescriptorUtils.parameterDescriptors(method.getParameterTypes())); delegatingMethod.addCheckedExceptions((Class<? extends Exception>[]) method.getExceptionTypes()); createDelegateToSuper(delegatingMethod, methodInformation); }
@SuppressWarnings("unchecked") private void createDelegateMethod(ClassFile proxyClassType, Method method, MethodInformation methodInformation) { int modifiers = (method.getModifiers() | AccessFlag.SYNTHETIC | AccessFlag.PRIVATE) & ~AccessFlag.PUBLIC & ~AccessFlag.PROTECTED; ClassMethod delegatingMethod = proxyClassType.addMethod(modifiers, method.getName() + SUPER_DELEGATE_SUFFIX, DescriptorUtils.makeDescriptor(method.getReturnType()), DescriptorUtils.parameterDescriptors(method.getParameterTypes())); delegatingMethod.addCheckedExceptions((Class<? extends Exception>[]) method.getExceptionTypes()); createDelegateToSuper(delegatingMethod, methodInformation); }
@SuppressWarnings("unchecked") private void createDelegateMethod(ClassFile proxyClassType, Method method, MethodInformation methodInformation) { int modifiers = (method.getModifiers() | AccessFlag.SYNTHETIC | AccessFlag.PRIVATE) & ~AccessFlag.PUBLIC & ~AccessFlag.PROTECTED; ClassMethod delegatingMethod = proxyClassType.addMethod(modifiers, method.getName() + SUPER_DELEGATE_SUFFIX, DescriptorUtils.makeDescriptor(method.getReturnType()), DescriptorUtils.parameterDescriptors(method.getParameterTypes())); delegatingMethod.addCheckedExceptions((Class<? extends Exception>[]) method.getExceptionTypes()); createDelegateToSuper(delegatingMethod, methodInformation); }
protected void generateSetMethodHandlerBody(ClassMethod method) { final CodeAttribute b = method.getCodeAttribute(); b.aload(0); b.aload(1); b.checkcast(getMethodHandlerType()); b.putfield(method.getClassFile().getName(), METHOD_HANDLER_FIELD_NAME, DescriptorUtils.makeDescriptor(getMethodHandlerType())); b.returnInstruction(); }
protected void generateSetMethodHandlerBody(ClassMethod method) { final CodeAttribute b = method.getCodeAttribute(); b.aload(0); b.aload(1); b.checkcast(getMethodHandlerType()); b.putfield(method.getClassFile().getName(), METHOD_HANDLER_FIELD_NAME, DescriptorUtils.makeDescriptor(getMethodHandlerType())); b.returnInstruction(); }