01: // This file is part of KeY - Integrated Deductive Software Design
02: // Copyright (C) 2001-2007 Universitaet Karlsruhe, Germany
03: // Universitaet Koblenz-Landau, Germany
04: // Chalmers University of Technology, Sweden
05: //
06: // The KeY system is protected by the GNU General Public License.
07: // See LICENSE.TXT for details.
08: //
09: //
10:
11: package de.uka.ilkd.key.casetool;
12:
13: import tudresden.ocl.check.OclTypeException;
14: import tudresden.ocl.check.types.Any;
15: import tudresden.ocl.check.types.Basic;
16: import tudresden.ocl.check.types.Type;
17:
18: /**
19: * @deprecated
20: */
21: public class JavaOCLTypeMap {
22:
23: protected HashMapOfClassifier classes;
24:
25: private static final Type[] basicTypes = new Type[] {
26: Basic.INTEGER, Basic.REAL, Basic.BOOLEAN };
27:
28: public static final Type[] getBasicTypes() {
29: return basicTypes;
30: }
31:
32: private JavaOCLTypeMap() {
33: }
34:
35: public JavaOCLTypeMap(HashMapOfClassifier cls) {
36: this .classes = cls;
37: }
38:
39: public static Type getBasicTypeFor(String t) {
40: if (t.equals("byte") || t.equals("short") || t.equals("char")
41: || t.equals("int") || t.equals("long")) {
42: return Basic.INTEGER;
43: } else if (t.equals("float") || t.equals("double")) {
44: return Basic.REAL;
45: } else if (t.equals("boolean")) {
46: return Basic.BOOLEAN;
47: } else if (t.equals("void")) {
48: return Any.VOID;
49: } else
50: throw new OclTypeException("Cannot find OCL type"
51: + "for Java type \"" + t + "\"");
52: }
53:
54: private boolean isBasicType(recoder.abstraction.Type type) {
55: if ((type instanceof recoder.abstraction.PrimitiveType)
56: || (type instanceof recoder.abstraction.NullType)) {
57: //??? || (type == null)) {
58: return true;
59: } else {
60: return false;
61: }
62: }
63:
64: public Type getTypeFor(recoder.abstraction.Type type,
65: HashMapOfClassifier classes) {
66: if (type == null) {
67: return getBasicTypeFor("void");
68: } else if (isBasicType(type)) {
69: // basic type
70: return getBasicTypeFor(type.getName());
71: } else if ("java.lang.String".equals(type.getFullName())) {
72: return Basic.STRING;
73: } else {
74: String refClass = type.getName();
75: if (classes.getClassifier(refClass) != null
76: && refClass != null) {
77: return classes.getClassifier(refClass);
78: } else {
79: return null;
80: // return new UMLOCLClassifier(type.getFullName());
81: }
82: }
83: }
84:
85: public String toString() {
86: return classes.toString();
87: }
88:
89: }
|