KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > org > apache > xalan > internal > xsltc > compiler > util > VoidType


1 /*
2  * Copyright 2001-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 /*
17  * $Id: VoidType.java,v 1.7 2004/02/16 22:26:44 minchau Exp $
18  */

19
20 package com.sun.org.apache.xalan.internal.xsltc.compiler.util;
21
22 import com.sun.org.apache.bcel.internal.generic.Instruction;
23 import com.sun.org.apache.bcel.internal.generic.InstructionList;
24 import com.sun.org.apache.bcel.internal.generic.PUSH;
25 import com.sun.org.apache.xalan.internal.xsltc.compiler.Constants;
26
27 /**
28  * @author Jacek Ambroziak
29  * @author Santiago Pericas-Geertsen
30  */

31 public final class VoidType extends Type {
32     protected VoidType() {}
33
34     public String JavaDoc toString() {
35     return "void";
36     }
37
38     public boolean identicalTo(Type other) {
39     return this == other;
40     }
41
42     public String JavaDoc toSignature() {
43     return "V";
44     }
45
46     public com.sun.org.apache.bcel.internal.generic.Type toJCType() {
47     return null; // should never be called
48
}
49
50     public Instruction POP() {
51         return NOP;
52     }
53
54     /**
55      * Translates a void into an object of internal type <code>type</code>.
56      * This translation is needed when calling external functions
57      * that return void.
58      *
59      * @see com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type#translateTo
60      */

61     public void translateTo(ClassGenerator classGen, MethodGenerator methodGen,
62                 Type type) {
63     if (type == Type.String) {
64         translateTo(classGen, methodGen, (StringType) type);
65     }
66     else {
67         ErrorMsg err = new ErrorMsg(ErrorMsg.DATA_CONVERSION_ERR,
68                     toString(), type.toString());
69         classGen.getParser().reportError(Constants.FATAL, err);
70     }
71     }
72
73     /**
74      * Translates a void into a string by pushing the empty string ''.
75      *
76      * @see com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type#translateTo
77      */

78     public void translateTo(ClassGenerator classGen, MethodGenerator methodGen,
79                 StringType type) {
80     final InstructionList il = methodGen.getInstructionList();
81     il.append(new PUSH(classGen.getConstantPool(), ""));
82     }
83
84     /**
85      * Translates an external (primitive) Java type into a void.
86      * Only an external "void" can be converted to this class.
87      */

88     public void translateFrom(ClassGenerator classGen, MethodGenerator methodGen,
89                   Class JavaDoc clazz) {
90     if (!clazz.getName().equals("void")) {
91         ErrorMsg err = new ErrorMsg(ErrorMsg.DATA_CONVERSION_ERR,
92                     toString(), clazz.getName());
93         classGen.getParser().reportError(Constants.FATAL, err);
94     }
95     }
96 }
97
Popular Tags