001: package de.uka.ilkd.key.casetool.eclipse;
002:
003: /*
004: * This file is part of KeY - Integrated Deductive Software Design
005: * Copyright (C) 2001-2005 Universitaet Karlsruhe, Germany
006: * Universitaet Koblenz-Landau, Germany
007: * Chalmers University of Technology, Sweden
008: *
009: * The KeY system is protected by the GNU General Public License.
010: */
011:
012: import org.eclipse.jdt.core.IType;
013: import org.eclipse.jdt.core.JavaModelException;
014: import org.eclipse.jdt.core.Signature;
015:
016: /**
017: * @author Marius Hillenbrand
018: *
019: */
020: public class EclipseSignaturesHelper {
021:
022: /**
023: * @param string
024: * @return
025: */
026: public static String determineJavaType(String eclipseSignature,
027: IType surroundingType) {
028: // TODO when upgrading to jdk1.5: add support for the various generic
029: // type expressions
030:
031: switch (eclipseSignature.charAt(0)) {
032:
033: case Signature.C_ARRAY: // this parameter is an array
034:
035: int depth = Signature.getArrayCount(eclipseSignature);
036:
037: StringBuffer type = new StringBuffer(determineJavaType(
038: Signature.getElementType(eclipseSignature),
039: surroundingType));
040: // array type is <element type> ([])+, now create the []s
041:
042: for (int i = 0; i < depth; i++)
043: type.append('[');
044: type.append(']');
045: // this is probably much faster, than handling String-objects ?!
046: return type.toString();
047:
048: // primitive types:
049: case Signature.C_BOOLEAN:
050: return "boolean";
051:
052: case Signature.C_BYTE:
053: return "byte";
054:
055: case Signature.C_CHAR:
056: return "char";
057:
058: case Signature.C_DOUBLE:
059: return "double";
060:
061: case Signature.C_FLOAT:
062: return "float";
063:
064: case Signature.C_INT:
065: return "int";
066:
067: case Signature.C_LONG:
068: return "long";
069:
070: case Signature.C_SHORT:
071: return "short";
072:
073: // arbitrary types with fully-qualified name
074: case Signature.C_RESOLVED:
075: return eclipseSignature.substring(1, eclipseSignature
076: .length() - 1);
077: // eclipse input is "Lpackage.Type;", so
078: // cut off the first and last character
079:
080: // arbitrary types with unresolved names
081: case Signature.C_UNRESOLVED:
082: String unqualifiedTypeName = eclipseSignature.substring(1,
083: eclipseSignature.length() - 1);
084: try {
085: String[][] resolvedTypes = surroundingType
086: .resolveType(unqualifiedTypeName);
087: if (resolvedTypes != null && resolvedTypes.length > 0) {
088: return (resolvedTypes[0][0].equals("") ? ""
089: : resolvedTypes[0][0] + ".")
090: + resolvedTypes[0][1];
091: } else {
092: return null;
093: }
094:
095: } catch (JavaModelException e) {
096: // TODO Auto-generated catch block
097: e.printStackTrace();
098: }
099:
100: }
101: throw new RuntimeException("Eclipse Signature type "
102: + eclipseSignature + "not checked, add support !!");
103: }
104:
105: }
|