public void newObject(TypeDesc type) { if (type.isArray()) { newObject(type, 1); } else { mInstructions.new NewObjectInstruction(mCp.addConstantClass(type)); } }
b.newObject(TypeDesc.forClass(objectType)); b.dup(); int count = b.getParameterCount();
TypeDesc[] stringParam = new TypeDesc[] {stringDesc}; newObject(stringBufferDesc); dup(); loadConstant(strlen);
mBuilder.newObject(mIntArrayType); mBuilder.storeLocal(mPositionsLocal);
b.returnValue(TypeDesc.OBJECT); } else { b.newObject(TypeDesc.forClass(NoSuchPropertyException.class)); b.dup(); b.loadLocal(propertyVar);
public void newObject(TypeDesc type) { if (type.isArray()) { newObject(type, 1); } else { mInstructions.new NewObjectInstruction(mCp.addConstantClass(type)); } }
/** * 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 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(); }
b.newObject(TypeDesc.forClass(Class[].class)); b.dup(); b.loadConstant(0);
b.newObject(cf.getType()); b.dup(); b.loadThis();
b.newObject(cf.getType()); b.dup(); b.loadThis();
private void addReadFromMethod() { TypeDesc streamType = TypeDesc.forClass(InputStream.class); MethodInfo mi = addMethodIfNotFinal(Modifiers.PUBLIC.toSynchronized(true), READ_FROM, null, new TypeDesc[] {streamType}); if (mi == null) { return; } CodeBuilder b = new CodeBuilder(mi); TypeDesc dataDecoderType = TypeDesc.forClass(DataDecoder.class); b.loadLocal(b.getParameter(0)); b.invokeStatic(dataDecoderType, "readLength", TypeDesc.INT, new TypeDesc[] {streamType}); LocalVariable encodedVar = b.createLocalVariable(null, TypeDesc.forClass(byte[].class)); b.newObject(encodedVar.getType()); b.storeLocal(encodedVar); b.loadLocal(b.getParameter(0)); b.loadLocal(encodedVar); b.invokeStatic(dataDecoderType, "readFully", null, new TypeDesc[] {streamType, encodedVar.getType()}); GenericEncodingStrategy<S> encoder = new GenericEncodingStrategy<S>(mStorableType, null); try { encoder.buildSerialDecoding(b, null, encodedVar); } catch (SupportException e) { // Wipe out any code generated so far. b = new CodeBuilder(mi); CodeBuilderUtil.throwException(b, SupportException.class, e.getMessage()); return; } b.returnVoid(); }
private void addReadFromMethod() { TypeDesc streamType = TypeDesc.forClass(InputStream.class); MethodInfo mi = addMethodIfNotFinal(Modifiers.PUBLIC.toSynchronized(true), READ_FROM, null, new TypeDesc[] {streamType}); if (mi == null) { return; } CodeBuilder b = new CodeBuilder(mi); TypeDesc dataDecoderType = TypeDesc.forClass(DataDecoder.class); b.loadLocal(b.getParameter(0)); b.invokeStatic(dataDecoderType, "readLength", TypeDesc.INT, new TypeDesc[] {streamType}); LocalVariable encodedVar = b.createLocalVariable(null, TypeDesc.forClass(byte[].class)); b.newObject(encodedVar.getType()); b.storeLocal(encodedVar); b.loadLocal(b.getParameter(0)); b.loadLocal(encodedVar); b.invokeStatic(dataDecoderType, "readFully", null, new TypeDesc[] {streamType, encodedVar.getType()}); GenericEncodingStrategy<S> encoder = new GenericEncodingStrategy<S>(mStorableType, null); try { encoder.buildSerialDecoding(b, null, encodedVar); } catch (SupportException e) { // Wipe out any code generated so far. b = new CodeBuilder(mi); CodeBuilderUtil.throwException(b, SupportException.class, e.getMessage()); return; } b.returnVoid(); }