public void doBuild(InstructionBuilder builder) { simpleTerm.callback.doBuild(builder); builder.dupe().when(Condition.NULL, new InstructionBuilderCallback() { public void doBuild(InstructionBuilder builder) { switch (nullHandling) { // It is necessary to load a null onto the stack (even if there's already one // there) because of the verifier. It sees the return when the stack contains an // intermediate value (along the navigation chain) and thinks the method is // returning a value of the wrong type. case ALLOW: builder.loadNull().returnResult(); case FORBID: builder.loadConstant(simpleTerm.description); builder.loadConstant(expression); builder.loadArgument(0); builder.invokeStatic(PropertyConduitSourceImpl.class, NullPointerException.class, "nullTerm", String.class, String.class, Object.class); builder.throwException(); break; } } }); } });
public void doBuild(InstructionBuilder builder) { builder.loadArgument(0).dupe().when(Condition.NULL, new InstructionBuilderCallback() { public void doBuild(InstructionBuilder builder) { builder.throwException(NullPointerException.class, String.format("Root object of property expression '%s' is null.", expression)); } }); builder.checkcast(rootType).returnResult(); } });
/** * The first part of any implementation of get() or set(): invoke the navigation method * and if the result is null, return immediately. */ private void invokeNavigateMethod(InstructionBuilder builder) { builder.loadThis().loadArgument(0).invokeVirtual(navMethod); builder.dupe().when(Condition.NULL, RETURN_NULL); }
@Override public InstructionBuilder throwException(String className, String message) { check(); newInstance(className).dupe().loadConstant(message); invokeConstructor(className, "java.lang.String"); v.visitInsn(ATHROW); return this; }
@Override public InstructionBuilder throwException(String className, String message) { check(); newInstance(className).dupe().loadConstant(message); invokeConstructor(className, "java.lang.String"); v.visitInsn(ATHROW); return this; }
private Type implementListConstructor(InstructionBuilder builder, Tree listNode) { // First, create an empty instance of ArrayList int count = listNode.getChildCount(); builder.newInstance(ArrayList.class); builder.dupe().loadConstant(count).invokeConstructor(ArrayList.class, int.class); for (int i = 0; i < count; i++) { builder.dupe(); // the ArrayList Type expressionType = implementSubexpression(builder, null, listNode.getChild(i)); boxIfPrimitive(builder, GenericsUtils.asClass(expressionType)); // Add the value to the array, then pop off the returned boolean builder.invoke(ArrayListMethods.ADD).pop(); } return ArrayList.class; }
private Type implementMapConstructor(InstructionBuilder builder, Tree mapNode) { int count = mapNode.getChildCount(); builder.newInstance(HashMap.class); builder.dupe().loadConstant(count).invokeConstructor(HashMap.class, int.class); for (int i = 0; i < count; i += 2) { builder.dupe(); //build the key: Type keyType = implementSubexpression(builder, null, mapNode.getChild(i)); boxIfPrimitive(builder, GenericsUtils.asClass(keyType)); //and the value: Type valueType = implementSubexpression(builder, null, mapNode.getChild(i + 1)); boxIfPrimitive(builder, GenericsUtils.asClass(valueType)); //put the value into the array, then pop off the returned object. builder.invoke(HashMapMethods.PUT).pop(); } return HashMap.class; }
@Override public void doBuild(final LocalVariable invocation, InstructionBuilder builder) { builder.dupe().storeVariable(invocation); builder.invoke(AbstractMethodInvocation.class, MethodInvocation.class, "proceed"); if (description.checkedExceptionTypes.length > 0) { builder.invoke(MethodInvocation.class, boolean.class, "didThrowCheckedException"); builder.when(Condition.NON_ZERO, new InstructionBuilderCallback() { @Override public void doBuild(InstructionBuilder builder) { builder.loadVariable(invocation).loadTypeConstant(Exception.class); builder.invokeVirtual(invocationClassName, Throwable.class.getName(), "getCheckedException", Class.class.getName()); builder.throwException(); } }); } if (!isVoid) { builder.loadVariable(invocation).getField(invocationClassName, RETURN_VALUE, description.returnType); } builder.returnResult(); } });
@Override public void doBuild(final LocalVariable invocation, InstructionBuilder builder) { builder.dupe().storeVariable(invocation); builder.invoke(AbstractMethodInvocation.class, MethodInvocation.class, "proceed"); if (description.checkedExceptionTypes.length > 0) { builder.invoke(MethodInvocation.class, boolean.class, "didThrowCheckedException"); builder.when(Condition.NON_ZERO, new InstructionBuilderCallback() { @Override public void doBuild(InstructionBuilder builder) { builder.loadVariable(invocation).loadTypeConstant(Exception.class); builder.invokeVirtual(invocationClassName, Throwable.class.getName(), "getCheckedException", Class.class.getName()); builder.throwException(); } }); } if (!isVoid) { builder.loadVariable(invocation).getField(invocationClassName, RETURN_VALUE, description.returnType); } builder.returnResult(); } });
builder.newInstance(invocationClassName).dupe();
builder.newInstance(invocationClassName).dupe();