KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > impl > services > bytecode > Type


1 /*
2
3    Derby - Class org.apache.derby.impl.services.bytecode.Type
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to you under the Apache License, Version 2.0
9    (the "License"); you may not use this file except in compliance with
10    the License. You may obtain a copy of the License at
11
12       http://www.apache.org/licenses/LICENSE-2.0
13
14    Unless required by applicable law or agreed to in writing, software
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19
20  */

21
22 package org.apache.derby.impl.services.bytecode;
23
24 import org.apache.derby.iapi.services.classfile.VMDescriptor;
25 import org.apache.derby.iapi.services.classfile.ClassHolder;
26
27 final class Type {
28
29     static final Type LONG = new Type("long", VMDescriptor.LONG);
30     static final Type INT = new Type("int", VMDescriptor.INT);
31     static final Type SHORT = new Type("short", VMDescriptor.SHORT);
32     static final Type BYTE = new Type("byte", VMDescriptor.BYTE);
33     static final Type BOOLEAN = new Type("boolean", VMDescriptor.BOOLEAN);
34     static final Type FLOAT = new Type("float", VMDescriptor.FLOAT);
35     static final Type DOUBLE = new Type("double", VMDescriptor.DOUBLE);
36     static final Type STRING = new Type("java.lang.String", "Ljava/lang/String;");
37
38     private final String JavaDoc javaName; // e.g. java.lang.Object
39
private final short vmType; // e.g. BCExpr.vm_reference
40
private final String JavaDoc vmName; // e.g. Ljava/lang/Object;
41
final String JavaDoc vmNameSimple; // e.g. java/lang/Object
42

43     Type(String JavaDoc javaName, String JavaDoc vmName) {
44         this.vmName = vmName;
45         this.javaName = javaName;
46         vmType = BCJava.vmTypeId(vmName);
47         vmNameSimple = ClassHolder.convertToInternalClassName(javaName);
48     }
49
50     /*
51     ** Class specific methods.
52     */

53     
54     String JavaDoc javaName() {
55         return javaName;
56     }
57
58     /**
59      * Get the VM Type name (java/lang/Object)
60      */

61     String JavaDoc vmName() {
62         return vmName;
63     }
64     /**
65         Get the VM type (eg. VMDescriptor.INT)
66     */

67     short vmType() {
68         return vmType;
69     }
70
71     int width() {
72         return Type.width(vmType);
73     }
74
75     static int width(short type) {
76         switch (type) {
77         case BCExpr.vm_void:
78             return 0;
79         case BCExpr.vm_long:
80         case BCExpr.vm_double:
81             return 2;
82         default:
83             return 1;
84         }
85     }
86 }
87
Popular Tags