KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > debug > eval > ast > engine > SignatureExt


1 /*******************************************************************************
2  * Copyright (c) 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.debug.eval.ast.engine;
12
13 import java.util.ArrayList JavaDoc;
14
15 import org.eclipse.jdt.core.Signature;
16 import org.eclipse.jdt.core.compiler.CharOperation;
17 import org.eclipse.jdt.internal.core.util.Util;
18
19 public class SignatureExt {
20
21     public static char[][] getTypeSuperClassInterfaces(char[] typeSignature) throws IllegalArgumentException JavaDoc {
22         try {
23             int length = typeSignature.length;
24             if (length == 0) return CharOperation.NO_CHAR_CHAR;
25             int i = 0;
26             if (typeSignature[0] == Signature.C_GENERIC_START) {
27                 i++; // leading '<'
28
while (i < length && typeSignature[i] != Signature.C_GENERIC_END) {
29                     i = CharOperation.indexOf(Signature.C_COLON, typeSignature, i);
30                     if (i < 0 || i >= length) throw new IllegalArgumentException JavaDoc();
31                     // iterate over bounds
32
nextBound: while (typeSignature[i] == ':') {
33                         i++; // skip colon
34
if (typeSignature[i] == ':') {
35                             continue nextBound; // empty bound
36
}
37                         i = Util.scanTypeSignature(typeSignature, i);
38                         i++; // position at start of next param if any
39
}
40                 }
41                 if (i < 0 || i >= length) throw new IllegalArgumentException JavaDoc();
42                 i++; // trailing '>'
43
}
44             ArrayList JavaDoc superList= new ArrayList JavaDoc();
45             while (i < length) {
46                 int superStart= i;
47                 i= Util.scanTypeSignature(typeSignature, i);
48                 i++;
49                 superList.add(CharOperation.subarray(typeSignature, superStart, i));
50             }
51             char[][] result;
52             superList.toArray(result = new char[superList.size()][]);
53             return result;
54         } catch (ArrayIndexOutOfBoundsException JavaDoc e) {
55             // invalid signature, fall through
56
}
57         throw new IllegalArgumentException JavaDoc();
58     }
59
60     public static String JavaDoc[] getTypeSuperClassInterfaces(String JavaDoc typeSignature) throws IllegalArgumentException JavaDoc {
61         char[][] params = getTypeSuperClassInterfaces(typeSignature.toCharArray());
62         return CharOperation.toStrings(params);
63     }
64 }
65
Popular Tags