01: /*
02: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
03: * Distributed under the terms of either:
04: * - the common development and distribution license (CDDL), v1.0; or
05: * - the GNU Lesser General Public License, v2.1 or later
06: * $Id: ParsedBlockText.java 3634 2007-01-08 21:42:24Z gbevin $
07: */
08: package com.uwyn.rife.template;
09:
10: import com.uwyn.rife.asm.ClassVisitor;
11: import com.uwyn.rife.asm.MethodVisitor;
12:
13: class ParsedBlockText extends ParsedBlockPart {
14: private String mText = null;
15:
16: ParsedBlockText(String text) {
17: assert text != null;
18: assert text.length() > 0;
19:
20: mText = text;
21: }
22:
23: String getData() {
24: return mText;
25: }
26:
27: int getType() {
28: return TEXT;
29: }
30:
31: void visitByteCodeExternalForm(MethodVisitor visitor,
32: String className, String staticIdentifier) {
33: visitor.visitVarInsn(ALOAD, 2);
34: visitor.visitFieldInsn(GETSTATIC, className, staticIdentifier,
35: "Lcom/uwyn/rife/template/InternalString;");
36: visitor.visitMethodInsn(INVOKEVIRTUAL,
37: "com/uwyn/rife/template/ExternalValue", "append",
38: "(Ljava/lang/CharSequence;)V");
39: }
40:
41: void visitByteCodeInternalForm(MethodVisitor visitor,
42: String className, String staticIdentifier) {
43: visitor.visitVarInsn(ALOAD, 0);
44: visitor.visitVarInsn(ALOAD, 2);
45: visitor.visitFieldInsn(GETSTATIC, className, staticIdentifier,
46: "Lcom/uwyn/rife/template/InternalString;");
47: visitor
48: .visitMethodInsn(INVOKEVIRTUAL, className,
49: "appendTextInternal",
50: "(Lcom/uwyn/rife/template/InternalValue;Ljava/lang/CharSequence;)V");
51: }
52:
53: void visitByteCodeStaticDeclaration(ClassVisitor visitor,
54: String staticIdentifier) {
55: visitor.visitField(ACC_PRIVATE | ACC_STATIC, staticIdentifier,
56: "Lcom/uwyn/rife/template/InternalString;", null, null);
57: }
58:
59: void visitByteCodeStaticDefinition(MethodVisitor visitor,
60: String className, String staticIdentifier) {
61: visitor.visitTypeInsn(NEW,
62: "com/uwyn/rife/template/InternalString");
63: visitor.visitInsn(DUP);
64: visitor.visitLdcInsn(mText);
65: visitor.visitMethodInsn(INVOKESPECIAL,
66: "com/uwyn/rife/template/InternalString", "<init>",
67: "(Ljava/lang/String;)V");
68: visitor.visitFieldInsn(PUTSTATIC, className, staticIdentifier,
69: "Lcom/uwyn/rife/template/InternalString;");
70: }
71: }
|