b.dup(); int count = b.getParameterCount(); for (int i=0; i<count; i++) {
dup(); loadConstant(strlen); invokeConstructor(stringBufferDesc, new TypeDesc[] {intDesc});
} else { b.newObject(TypeDesc.forClass(NoSuchPropertyException.class)); b.dup(); b.loadLocal(propertyVar); b.loadConstant(methodType == READ_METHOD);
private static void throwIllegalArgException(CodeBuilder b, String message, LocalVariable concatStr) { TypeDesc exceptionType = TypeDesc.forClass(IllegalArgumentException.class); TypeDesc[] params = {TypeDesc.STRING}; b.newObject(exceptionType); b.dup(); b.loadConstant(message); b.loadLocal(concatStr); b.invokeVirtual(TypeDesc.STRING, "concat", TypeDesc.STRING, params); b.invokeConstructor(exceptionType, params); b.throwObject(); }
/** * Generate code to throw an exception with an optional message. * @param b {@link CodeBuilder} to which to add code * @param type type of the object to throw * @param message optional message to provide to the constructor */ public static void throwException(CodeBuilder b, Class type, String message) { TypeDesc desc = TypeDesc.forClass(type); b.newObject(desc); b.dup(); if (message == null) { b.invokeConstructor(desc, null); } else { b.loadConstant(message); b.invokeConstructor(desc, new TypeDesc[] {TypeDesc.STRING}); } b.throwObject(); }
/** * Generate code to throw an exception with an optional message. * @param b {@link CodeBuilder} to which to add code * @param type type of the object to throw * @param message optional message to provide to the constructor */ public static void throwException(CodeBuilder b, Class type, String message) { TypeDesc desc = TypeDesc.forClass(type); b.newObject(desc); b.dup(); if (message == null) { b.invokeConstructor(desc, null); } else { b.loadConstant(message); b.invokeConstructor(desc, new TypeDesc[] {TypeDesc.STRING}); } b.throwObject(); }
private static void throwIllegalArgException(CodeBuilder b, String message, LocalVariable concatStr) { TypeDesc exceptionType = TypeDesc.forClass(IllegalArgumentException.class); TypeDesc[] params = {TypeDesc.STRING}; b.newObject(exceptionType); b.dup(); b.loadConstant(message); b.loadLocal(concatStr); b.invokeVirtual(TypeDesc.STRING, "concat", TypeDesc.STRING, params); b.invokeConstructor(exceptionType, params); b.throwObject(); }
/** * Generate code to throw an exception with a message concatenated at runtime. * * @param b {@link CodeBuilder} to which to add code * @param type type of the object to throw * @param messages messages to concat at runtime */ public static void throwConcatException(CodeBuilder b, Class type, String... messages) { if (messages == null || messages.length == 0) { throwException(b, type, null); return; } if (messages.length == 1) { throwException(b, type, messages[0]); return; } TypeDesc desc = TypeDesc.forClass(type); b.newObject(desc); b.dup(); TypeDesc[] params = new TypeDesc[] {TypeDesc.STRING}; for (int i=0; i<messages.length; i++) { b.loadConstant(String.valueOf(messages[i])); if (i > 0) { b.invokeVirtual(TypeDesc.STRING, "concat", TypeDesc.STRING, params); } } b.invokeConstructor(desc, params); b.throwObject(); }
/** * Generate code to throw an exception with a message concatenated at runtime. * * @param b {@link CodeBuilder} to which to add code * @param type type of the object to throw * @param messages messages to concat at runtime */ public static void throwConcatException(CodeBuilder b, Class type, String... messages) { if (messages == null || messages.length == 0) { throwException(b, type, null); return; } if (messages.length == 1) { throwException(b, type, messages[0]); return; } TypeDesc desc = TypeDesc.forClass(type); b.newObject(desc); b.dup(); TypeDesc[] params = new TypeDesc[] {TypeDesc.STRING}; for (int i=0; i<messages.length; i++) { b.loadConstant(String.valueOf(messages[i])); if (i > 0) { b.invokeVirtual(TypeDesc.STRING, "concat", TypeDesc.STRING, params); } } b.invokeConstructor(desc, params); b.throwObject(); }
private void checkIfPartitionKeyPresent(CodeBuilder b) { b.loadThis(); b.invokeVirtual(StorableGenerator.IS_PARTITION_KEY_INITIALIZED_METHOD_NAME, TypeDesc.BOOLEAN, null); Label ptnkInitialized = b.createLabel(); b.ifZeroComparisonBranch(ptnkInitialized, "!="); TypeDesc exType = TypeDesc.forClass(IllegalStateException.class); b.newObject(exType); b.dup(); b.loadConstant("Partition key not fully specified"); b.invokeConstructor(exType, new TypeDesc[] {TypeDesc.STRING}); b.throwObject(); ptnkInitialized.setLocation(); }
private void checkIfPartitionKeyPresent(CodeBuilder b) { b.loadThis(); b.invokeVirtual(StorableGenerator.IS_PARTITION_KEY_INITIALIZED_METHOD_NAME, TypeDesc.BOOLEAN, null); Label ptnkInitialized = b.createLabel(); b.ifZeroComparisonBranch(ptnkInitialized, "!="); TypeDesc exType = TypeDesc.forClass(IllegalStateException.class); b.newObject(exType); b.dup(); b.loadConstant("Partition key not fully specified"); b.invokeConstructor(exType, new TypeDesc[] {TypeDesc.STRING}); b.throwObject(); ptnkInitialized.setLocation(); }
/** * Assumes a boolean is on the stack, as returned by doTryInsert or doTryUpdate. */ private void addNormalizationRollback(CodeBuilder b, Label doTryStart, List<PropertyCopy> unnormalized) { if (unnormalized == null) { return; } Label doTryEnd = b.createLabel().setLocation(); b.dup(); Label success = b.createLabel(); b.ifZeroComparisonBranch(success, "!="); for (int i=0; i<2; i++) { if (i == 0) { } else { b.exceptionHandler(doTryStart, doTryEnd, null); } // Rollback normalized properties. for (PropertyCopy copy : unnormalized) { copy.restore(b); } if (i == 0) { b.branch(success); } else { b.throwObject(); } } success.setLocation(); }
/** * Assumes a boolean is on the stack, as returned by doTryInsert or doTryUpdate. */ private void addNormalizationRollback(CodeBuilder b, Label doTryStart, List<PropertyCopy> unnormalized) { if (unnormalized == null) { return; } Label doTryEnd = b.createLabel().setLocation(); b.dup(); Label success = b.createLabel(); b.ifZeroComparisonBranch(success, "!="); for (int i=0; i<2; i++) { if (i == 0) { } else { b.exceptionHandler(doTryStart, doTryEnd, null); } // Rollback normalized properties. for (PropertyCopy copy : unnormalized) { copy.restore(b); } if (i == 0) { b.branch(success); } else { b.throwObject(); } } success.setLocation(); }
private void addAdjustVersionProperty(CodeBuilder b, LocalVariable storableVar, int value) throws SupportException { // Push storable to stack in preparation for calling set method below. if (storableVar == null) { b.loadThis(); } else { b.loadLocal(storableVar); } StorableProperty<?> versionProperty = mInfo.getVersionProperty(); TypeDesc versionType = TypeDesc.forClass(versionProperty.getType()); if (value >= 0) { CodeBuilderUtil.initialVersion(b, versionType, value); } else { // Load current property value. b.dup(); b.invoke(versionProperty.getReadMethod()); CodeBuilderUtil.incrementVersion(b, versionType); } b.invoke(versionProperty.getWriteMethod()); }
b.dup(); b.loadConstant(0); b.loadConstant(TypeDesc.forClass(property.getType()));
private void addAdjustVersionProperty(CodeBuilder b, LocalVariable storableVar, int value) throws SupportException { // Push storable to stack in preparation for calling set method below. if (storableVar == null) { b.loadThis(); } else { b.loadLocal(storableVar); } StorableProperty<?> versionProperty = mInfo.getVersionProperty(); TypeDesc versionType = TypeDesc.forClass(versionProperty.getType()); if (value >= 0) { CodeBuilderUtil.initialVersion(b, versionType, value); } else { // Load current property value. b.dup(); b.invoke(versionProperty.getReadMethod()); CodeBuilderUtil.incrementVersion(b, versionType); } b.invoke(versionProperty.getWriteMethod()); }
/** * Generated code checks if chained properties resolve to null, and if * so, branches to the current scope's fail or success location. */ private void loadChainedProperty(CodeBuilder b, ChainedProperty<?> chained) { b.loadLocal(mStorableVar); loadProperty(b, chained.getPrimeProperty()); for (int i=0; i<chained.getChainCount(); i++) { // Check if last loaded property was null. Fail for inner join, // success for outer join. b.dup(); Label notNull = b.createLabel(); b.ifNullBranch(notNull, false); b.pop(); if (chained.isOuterJoin(i)) { getScope().success(b); } else { getScope().fail(b); } notNull.setLocation(); // Now load next property in chain. loadProperty(b, chained.getChainedProperty(i)); } }
/** * Generated code checks if chained properties resolve to null, and if * so, branches to the current scope's fail or success location. */ private void loadChainedProperty(CodeBuilder b, ChainedProperty<?> chained) { b.loadLocal(mStorableVar); loadProperty(b, chained.getPrimeProperty()); for (int i=0; i<chained.getChainCount(); i++) { // Check if last loaded property was null. Fail for inner join, // success for outer join. b.dup(); Label notNull = b.createLabel(); b.ifNullBranch(notNull, false); b.pop(); if (chained.isOuterJoin(i)) { getScope().success(b); } else { getScope().fail(b); } notNull.setLocation(); // Now load next property in chain. loadProperty(b, chained.getChainedProperty(i)); } }
b.dup(); b.loadThis(); b.loadField(supportFieldName, supportFieldType);
b.dup(); b.loadThis(); b.loadField(supportFieldName, supportFieldType);