public void doBuild(InstructionBuilder builder) { builder.loadConstant(conduitPropertyName).returnResult(); } });
public void doBuild(InstructionBuilder builder) { builder.loadConstant(true).returnResult(); } };
@Override public void doBuild(InstructionBuilder builder) { builder.loadConstant(toStringValue).returnResult(); } });
@Override public void doBuild(InstructionBuilder builder) { builder.loadConstant(toStringValue).returnResult(); } });
@Override public void doBuild(final LocalVariable indexVariable, InstructionBuilder builder) { builder.loadConstant(0).storeVariable(indexVariable); builder.doWhile(Condition.LESS_THAN, new WhileCallback() { @Override public void buildTest(InstructionBuilder builder) { builder.dupe().arrayLength(); builder.loadVariable(indexVariable).swap(); } @Override public void buildBody(InstructionBuilder builder) { builder.dupe().loadVariable(indexVariable).loadArrayElement(); callback.doBuild(builder); builder.increment(indexVariable); } }); } });
@Override public void doBuild(final LocalVariable indexVariable, InstructionBuilder builder) { builder.loadConstant(0).storeVariable(indexVariable); builder.doWhile(Condition.LESS_THAN, new WhileCallback() { @Override public void buildTest(InstructionBuilder builder) { builder.dupe().arrayLength(); builder.loadVariable(indexVariable).swap(); } @Override public void buildBody(InstructionBuilder builder) { builder.dupe().loadVariable(indexVariable).loadArrayElement(); callback.doBuild(builder); builder.increment(indexVariable); } }); } });
private void invokeCallback(ConstructorCallback callback) { int index = staticContext.store(callback); // First, load the callback constructorBuilder.loadArgument(0).loadConstant(index).invoke(STATIC_CONTEXT_GET_METHOD).castOrUnbox(ConstructorCallback.class.getName()); // Load this and the InstanceContext constructorBuilder.loadThis().loadArgument(1); constructorBuilder.invoke(CONSTRUCTOR_CALLBACK_METHOD); }
@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 void invokeCallback(ConstructorCallback callback) { int index = staticContext.store(callback); // First, load the callback constructorBuilder.loadArgument(0).loadConstant(index).invoke(STATIC_CONTEXT_GET_METHOD).castOrUnbox(ConstructorCallback.class.getName()); // Load this and the InstanceContext constructorBuilder.loadThis().loadArgument(1); constructorBuilder.invoke(CONSTRUCTOR_CALLBACK_METHOD); }
@Override public InstructionBuilder throwException(String className, String message) { check(); newInstance(className).dupe().loadConstant(message); invokeConstructor(className, "java.lang.String"); v.visitInsn(ATHROW); return this; }
/** * Initializes a field from the static context. The injected value is added to the static * context and the class constructor updated to assign the value from the context (which includes casting and * possibly unboxing). */ void initializeFieldFromStaticContext(String fieldName, String fieldType, Object injectedFieldValue) { int index = staticContext.store(injectedFieldValue); // Although it feels nicer to do the loadThis() later and then swap(), that breaks // on primitive longs and doubles, so its just easier to do the loadThis() first // so its at the right place on the stack for the putField(). constructorBuilder.loadThis(); constructorBuilder.loadArgument(0).loadConstant(index); constructorBuilder.invoke(STATIC_CONTEXT_GET_METHOD); constructorBuilder.castOrUnbox(fieldType); constructorBuilder.putField(className, fieldName, fieldType); }
/** * Initializes a field from the static context. The injected value is added to the static * context and the class constructor updated to assign the value from the context (which includes casting and * possibly unboxing). */ void initializeFieldFromStaticContext(String fieldName, String fieldType, Object injectedFieldValue) { int index = staticContext.store(injectedFieldValue); // Although it feels nicer to do the loadThis() later and then swap(), that breaks // on primitive longs and doubles, so its just easier to do the loadThis() first // so its at the right place on the stack for the putField(). constructorBuilder.loadThis(); constructorBuilder.loadArgument(0).loadConstant(index); constructorBuilder.invoke(STATIC_CONTEXT_GET_METHOD); constructorBuilder.castOrUnbox(fieldType); constructorBuilder.putField(className, fieldName, fieldType); }
public void doBuild(InstructionBuilder builder) { builder.loadArgument(0).loadConstant(method.getMethodIdentifier()).invoke(Event.class, void.class, "setMethodDescription", String.class); builder.loadThis(); int count = description.argumentTypes.length; for (int i = 0; i < count; i++) { builder.loadThis().getField(sourceField).loadArgument(0).loadConstant(i); builder.invoke(EventHandlerMethodParameterSource.class, Object.class, "get", ComponentEvent.class, int.class); builder.castOrUnbox(description.argumentTypes[i]); } builder.invokeVirtual(method); if (!method.isVoid()) { builder.boxPrimitive(description.returnType); builder.loadArgument(0).swap(); builder.invoke(Event.class, boolean.class, "storeResult", Object.class); // storeResult() returns true if the method is aborted. Return true since, certainly, // a method was invoked. builder.when(Condition.NON_ZERO, RETURN_TRUE); } // Set the result to true, to indicate that some method was invoked. builder.loadConstant(true).storeVariable(resultVariable); } });
private void initializeComputedField(ComputedValue<?> computedValue) { int index = plasticClass.staticContext.store(computedValue); plasticClass.constructorBuilder.loadThis(); // for the putField() // Get the ComputedValue out of the StaticContext and onto the stack plasticClass.constructorBuilder.loadArgument(0).loadConstant(index); plasticClass.constructorBuilder.invoke(PlasticClassImpl.STATIC_CONTEXT_GET_METHOD).checkcast(ComputedValue.class); // Add the InstanceContext to the stack plasticClass.constructorBuilder.loadArgument(1); plasticClass.constructorBuilder.invoke(PlasticClassImpl.COMPUTED_VALUE_GET_METHOD).castOrUnbox(typeName); plasticClass.constructorBuilder.putField(plasticClass.className, node.name, typeName); }
private void initializeComputedField(ComputedValue<?> computedValue) { int index = plasticClass.staticContext.store(computedValue); plasticClass.constructorBuilder.loadThis(); // for the putField() // Get the ComputedValue out of the StaticContext and onto the stack plasticClass.constructorBuilder.loadArgument(0).loadConstant(index); plasticClass.constructorBuilder.invoke(PlasticClassImpl.STATIC_CONTEXT_GET_METHOD).checkcast(ComputedValue.class); // Add the InstanceContext to the stack plasticClass.constructorBuilder.loadArgument(1); plasticClass.constructorBuilder.invoke(PlasticClassImpl.COMPUTED_VALUE_GET_METHOD).castOrUnbox(typeName); plasticClass.constructorBuilder.putField(plasticClass.className, node.name, typeName); }
@Override public PlasticField injectFromInstanceContext() { plasticClass.check(); verifyInitialState("inject instance context value into"); // Easiest to load this, for the putField(), early, in case the field is // wide (long or double primitive) plasticClass.constructorBuilder.loadThis(); // Add the InstanceContext to the stack plasticClass.constructorBuilder.loadArgument(1); plasticClass.constructorBuilder.loadConstant(typeName); plasticClass.constructorBuilder.invokeStatic(PlasticInternalUtils.class, Object.class, "getFromInstanceContext", InstanceContext.class, String.class).castOrUnbox(typeName); plasticClass.constructorBuilder.putField(plasticClass.className, node.name, typeName); makeReadOnly(); state = FieldState.INJECTED; return this; }
@Override public PlasticField injectFromInstanceContext() { plasticClass.check(); verifyInitialState("inject instance context value into"); // Easiest to load this, for the putField(), early, in case the field is // wide (long or double primitive) plasticClass.constructorBuilder.loadThis(); // Add the InstanceContext to the stack plasticClass.constructorBuilder.loadArgument(1); plasticClass.constructorBuilder.loadConstant(typeName); plasticClass.constructorBuilder.invokeStatic(PlasticInternalUtils.class, Object.class, "getFromInstanceContext", InstanceContext.class, String.class).castOrUnbox(typeName); plasticClass.constructorBuilder.putField(plasticClass.className, node.name, typeName); makeReadOnly(); state = FieldState.INJECTED; 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 void invokeMethod(InstructionBuilder builder, PlasticMethod method) { // First, tell the Event object what method is being invoked. builder.loadArgument(1); builder.loadConstant( method.getMethodIdentifier()); builder.invoke(Event.class, void.class, "setMethodDescription", String.class); builder.loadThis(); // Methods either take no parameters, or take a MarkupWriter parameter. if (method.getParameters().size() > 0) { builder.loadArgument(0); } builder.invokeVirtual(method); // Non-void methods will pass a value to the event. if (!method.isVoid()) { builder.boxPrimitive(method.getDescription().returnType); builder.loadArgument(1).swap(); builder.invoke(Event.class, boolean.class, "storeResult", Object.class); builder.when(Condition.NON_ZERO, JUST_RETURN); } }
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; }