KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > compiler > lookup > SignatureWrapper


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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.compiler.lookup;
12
13 import org.eclipse.jdt.core.compiler.CharOperation;
14
15 public class SignatureWrapper {
16     public char[] signature;
17     public int start;
18     public int end;
19     public int bracket;
20
21     public SignatureWrapper(char[] signature) {
22         this.signature = signature;
23         this.start = 0;
24         this.end = this.bracket = -1;
25     }
26     public boolean atEnd() {
27         return this.start < 0 || this.start >= this.signature.length;
28     }
29     public int computeEnd() {
30         int index = this.start;
31         while (this.signature[index] == '[')
32             index++;
33         switch (this.signature[index]) {
34             case 'L' :
35             case 'T' :
36                 this.end = CharOperation.indexOf(';', this.signature, this.start);
37                 if (this.bracket <= this.start) // already know it if its > start
38
this.bracket = CharOperation.indexOf('<', this.signature, this.start);
39         
40                 if (this.bracket > this.start && this.bracket < this.end)
41                     this.end = this.bracket;
42                 else if (this.end == -1)
43                     this.end = this.signature.length + 1;
44                 break;
45             default :
46                 this.end = this.start;
47         }
48
49         this.start = this.end + 1; // skip ';'
50
return this.end;
51     }
52     public char[] nextWord() {
53         this.end = CharOperation.indexOf(';', this.signature, this.start);
54         if (this.bracket <= this.start) // already know it if its > start
55
this.bracket = CharOperation.indexOf('<', this.signature, this.start);
56         int dot = CharOperation.indexOf('.', this.signature, this.start);
57
58         if (this.bracket > this.start && this.bracket < this.end)
59             this.end = this.bracket;
60         if (dot > this.start && dot < this.end)
61             this.end = dot;
62
63         return CharOperation.subarray(this.signature, this.start, this.start = this.end); // skip word
64
}
65     public String JavaDoc toString() {
66         return new String JavaDoc(this.signature) + " @ " + this.start; //$NON-NLS-1$
67
}
68 }
69
Popular Tags