KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > compiler > SourceJavadocParser


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;
12
13 import org.eclipse.jdt.core.compiler.CharOperation;
14 import org.eclipse.jdt.internal.compiler.parser.JavadocParser;
15 import org.eclipse.jdt.internal.compiler.parser.Parser;
16 import org.eclipse.jdt.internal.compiler.parser.ScannerHelper;
17 import org.eclipse.jdt.internal.compiler.parser.TerminalTokens;
18
19 public class SourceJavadocParser extends JavadocParser {
20
21     // Store categories identifiers parsed in javadoc
22
int categoriesPtr = -1;
23     char[][] categories = CharOperation.NO_CHAR_CHAR;
24
25 public SourceJavadocParser(Parser sourceParser) {
26     super(sourceParser);
27     this.kind = SOURCE_PARSER | TEXT_VERIF;
28 }
29
30 public boolean checkDeprecation(int commentPtr) {
31     this.categoriesPtr = -1;
32     boolean result = super.checkDeprecation(commentPtr);
33     if (this.categoriesPtr > -1) {
34         System.arraycopy(this.categories, 0, this.categories = new char[this.categoriesPtr+1][], 0, this.categoriesPtr+1);
35     } else {
36         this.categories = CharOperation.NO_CHAR_CHAR;
37     }
38     return result;
39 }
40
41 /* (non-Javadoc)
42  * @see org.eclipse.jdt.internal.compiler.parser.AbstractCommentParser#parseIdentifierTag()
43  */

44 protected boolean parseIdentifierTag(boolean report) {
45     int end = this.lineEnd+1;
46     if (super.parseIdentifierTag(report) && this.index <= end) {
47         if (this.tagValue == TAG_CATEGORY_VALUE) {
48             // Store first category id
49
int length = this.categories.length;
50             if (++this.categoriesPtr >= length) {
51                 System.arraycopy(this.categories, 0, this.categories = new char[length+5][], 0, length);
52                 length += 5;
53             }
54             this.categories[this.categoriesPtr] = this.identifierStack[this.identifierPtr--];
55             // Store optional additional category identifiers
56
consumeToken();
57             while (this.index < end) {
58                 if (readTokenSafely() == TerminalTokens.TokenNameIdentifier && (this.scanner.currentCharacter == ' ' || ScannerHelper.isWhitespace(this.scanner.currentCharacter))) {
59                     if (this.index > (this.lineEnd+1)) break;
60                     // valid additional identifier
61
if (++this.categoriesPtr >= length) {
62                         System.arraycopy(this.categories, 0, this.categories = new char[length+5][], 0, length);
63                         length += 5;
64                     }
65                     this.categories[this.categoriesPtr] = this.scanner.getCurrentIdentifierSource();
66                     consumeToken();
67                 } else {
68                     // TODO (frederic) raise warning for invalid syntax when javadoc spec will be finalized...
69
break;
70                 }
71             }
72             // Reset position to end of line
73
this.index = end;
74             this.scanner.currentPosition = end;
75             consumeToken();
76         }
77         return true;
78     }
79     return false;
80 }
81
82 /* (non-Javadoc)
83  * @see org.eclipse.jdt.internal.compiler.parser.JavadocParser#parseSimpleTag()
84  */

85 protected void parseSimpleTag() {
86     
87     // Read first char
88
// readChar() code is inlined to balance additional method call in checkDeprectation(int)
89
char first = this.source[this.index++];
90     if (first == '\\' && this.source[this.index] == 'u') {
91         int c1, c2, c3, c4;
92         int pos = this.index;
93         this.index++;
94         while (this.source[this.index] == 'u')
95             this.index++;
96         if (!(((c1 = ScannerHelper.getNumericValue(this.source[this.index++])) > 15 || c1 < 0)
97                 || ((c2 = ScannerHelper.getNumericValue(this.source[this.index++])) > 15 || c2 < 0)
98                 || ((c3 = ScannerHelper.getNumericValue(this.source[this.index++])) > 15 || c3 < 0)
99                 || ((c4 = ScannerHelper.getNumericValue(this.source[this.index++])) > 15 || c4 < 0))) {
100             first = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
101         } else {
102             this.index = pos;
103         }
104     }
105
106     // switch on first tag char
107
switch (first) {
108         case 'd': // perhaps @deprecated tag?
109
if ((readChar() == 'e') &&
110                     (readChar() == 'p') && (readChar() == 'r') &&
111                     (readChar() == 'e') && (readChar() == 'c') &&
112                     (readChar() == 'a') && (readChar() == 't') &&
113                     (readChar() == 'e') && (readChar() == 'd')) {
114                 // ensure the tag is properly ended: either followed by a space, a tab, line end or asterisk.
115
char c = readChar();
116                 if (ScannerHelper.isWhitespace(c) || c == '*') {
117                     this.tagValue = TAG_DEPRECATED_VALUE;
118                     this.deprecated = true;
119                 }
120             }
121             break;
122         case 'c': // perhaps @category tag?
123
if ((readChar() == 'a') &&
124                     (readChar() == 't') && (readChar() == 'e') &&
125                     (readChar() == 'g') && (readChar() == 'o') &&
126                     (readChar() == 'r') && (readChar() == 'y')) {
127                 // ensure the tag is properly ended: either followed by a space, a tab, line end or asterisk.
128
char c = readChar();
129                 if (ScannerHelper.isWhitespace(c) || c == '*') {
130                     this.tagValue = TAG_CATEGORY_VALUE;
131                     if (this.scanner.source == null) {
132                         this.scanner.setSource(this.source);
133                     }
134                     this.scanner.resetTo(this.index, this.scanner.eofPosition);
135                     parseIdentifierTag(false); // Do not report missing identifier
136
}
137             }
138             break;
139     }
140 }
141
142 }
143
Popular Tags