KickJava   Java API By Example, From Geeks To Geeks.

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


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.internal.compiler.classfmt.ClassFileConstants;
14 import org.eclipse.jdt.internal.compiler.env.*;
15
16 import org.eclipse.jdt.internal.compiler.impl.*;
17 import org.eclipse.jdt.core.compiler.*;
18 import org.eclipse.jdt.internal.compiler.ast.*;
19 import org.eclipse.jdt.internal.compiler.parser.*;
20 import org.eclipse.jdt.internal.compiler.problem.*;
21
22 public class DocumentElementParser extends Parser {
23     IDocumentElementRequestor requestor;
24     private int localIntPtr;
25     private int lastFieldEndPosition;
26     private int lastFieldBodyEndPosition;
27     private int typeStartPosition;
28     private long selectorSourcePositions;
29     private int typeDims;
30     private int extendsDim;
31     private int declarationSourceStart;
32
33     /* int[] stack for storing javadoc positions */
34     int[][] intArrayStack;
35     int intArrayPtr;
36     
37 public DocumentElementParser(
38     final IDocumentElementRequestor requestor,
39     IProblemFactory problemFactory,
40     CompilerOptions options) {
41     super(new ProblemReporter(
42         DefaultErrorHandlingPolicies.exitAfterAllProblems(),
43         options,
44         problemFactory),
45     false);
46     this.requestor = requestor;
47     intArrayStack = new int[30][];
48     this.options = options;
49     this.javadocParser.checkDocComment = false;
50     
51     this.setMethodsFullRecovery(false);
52     this.setStatementsRecovery(false);
53 }
54 /*
55  * Will clear the comment stack when looking
56  * for a potential JavaDoc which might contain @deprecated.
57  *
58  * Additionally, before investigating for @deprecated, retrieve the positions
59  * of the JavaDoc comments so as to notify requestor with them.
60  */

61 public void checkComment() {
62
63     /* persisting javadoc positions */
64     pushOnIntArrayStack(this.getJavaDocPositions());
65     boolean deprecated = false;
66     int lastCommentIndex = -1;
67     int commentPtr = scanner.commentPtr;
68
69     //since jdk1.2 look only in the last java doc comment...
70
nextComment : for (lastCommentIndex = scanner.commentPtr; lastCommentIndex >= 0; lastCommentIndex--){
71         //look for @deprecated into the first javadoc comment preceeding the declaration
72
int commentSourceStart = scanner.commentStarts[lastCommentIndex];
73         // javadoc only (non javadoc comment have negative end positions.)
74
if (modifiersSourceStart != -1 && modifiersSourceStart < commentSourceStart) {
75             continue nextComment;
76         }
77         if (scanner.commentStops[lastCommentIndex] < 0) {
78             continue nextComment;
79         }
80         deprecated =
81             this.javadocParser.checkDeprecation(lastCommentIndex);
82         break nextComment;
83     }
84     if (deprecated) {
85         checkAndSetModifiers(ClassFileConstants.AccDeprecated);
86     }
87     // modify the modifier source start to point at the first comment
88
if (commentPtr >= 0) {
89         declarationSourceStart = scanner.commentStarts[0];
90     }
91 }
92 /*
93  *
94  * INTERNAL USE-ONLY
95  */

96 protected void consumeClassBodyDeclaration() {
97     // ClassBodyDeclaration ::= Diet Block
98
//push an Initializer
99
//optimize the push/pop
100

101     super.consumeClassBodyDeclaration();
102     Initializer initializer = (Initializer) astStack[astPtr];
103     requestor.acceptInitializer(
104         initializer.declarationSourceStart,
105         initializer.declarationSourceEnd,
106         intArrayStack[intArrayPtr--],
107         0,
108         modifiersSourceStart,
109         initializer.block.sourceStart,
110         initializer.block.sourceEnd);
111 }
112 /*
113  *
114  * INTERNAL USE-ONLY
115  */

116 protected void consumeClassDeclaration() {
117     super.consumeClassDeclaration();
118     // we know that we have a TypeDeclaration on the top of the astStack
119
if (isLocalDeclaration()) {
120         // we ignore the local variable declarations
121
return;
122     }
123     requestor.exitClass(endStatementPosition, // '}' is the end of the body
124
((TypeDeclaration) astStack[astPtr]).declarationSourceEnd);
125 }
126 /*
127  *
128  * INTERNAL USE-ONLY
129  */

130 protected void consumeClassHeader() {
131     //ClassHeader ::= $empty
132
super.consumeClassHeader();
133     if (isLocalDeclaration()) {
134         // we ignore the local variable declarations
135
intArrayPtr--;
136         return;
137     }
138     TypeDeclaration typeDecl = (TypeDeclaration) astStack[astPtr];
139     TypeReference[] superInterfaces = typeDecl.superInterfaces;
140     char[][] interfaceNames = null;
141     int[] interfaceNameStarts = null;
142     int[] interfaceNameEnds = null;
143     if (superInterfaces != null) {
144         int superInterfacesLength = superInterfaces.length;
145         interfaceNames = new char[superInterfacesLength][];
146         interfaceNameStarts = new int[superInterfacesLength];
147         interfaceNameEnds = new int[superInterfacesLength];
148         for (int i = 0; i < superInterfacesLength; i++) {
149             TypeReference superInterface = superInterfaces[i];
150             interfaceNames[i] = CharOperation.concatWith(superInterface.getTypeName(), '.');
151             interfaceNameStarts[i] = superInterface.sourceStart;
152             interfaceNameEnds[i] = superInterface.sourceEnd;
153         }
154     }
155     // flush the comments related to the class header
156
scanner.commentPtr = -1;
157     TypeReference superclass = typeDecl.superclass;
158     if (superclass == null) {
159         requestor.enterClass(
160             typeDecl.declarationSourceStart,
161             intArrayStack[intArrayPtr--],
162             typeDecl.modifiers,
163             typeDecl.modifiersSourceStart,
164             typeStartPosition,
165             typeDecl.name,
166             typeDecl.sourceStart,
167             typeDecl.sourceEnd,
168             null,
169             -1,
170             -1,
171             interfaceNames,
172             interfaceNameStarts,
173             interfaceNameEnds,
174             scanner.currentPosition - 1);
175     } else {
176         requestor.enterClass(
177             typeDecl.declarationSourceStart,
178             intArrayStack[intArrayPtr--],
179             typeDecl.modifiers,
180             typeDecl.modifiersSourceStart,
181             typeStartPosition,
182             typeDecl.name,
183             typeDecl.sourceStart,
184             typeDecl.sourceEnd,
185             CharOperation.concatWith(superclass.getTypeName(), '.'),
186             superclass.sourceStart,
187             superclass.sourceEnd,
188             interfaceNames,
189             interfaceNameStarts,
190             interfaceNameEnds,
191             scanner.currentPosition - 1);
192
193     }
194 }
195 protected void consumeClassHeaderName1() {
196     // ClassHeaderName ::= Modifiersopt 'class' 'Identifier'
197
TypeDeclaration typeDecl = new TypeDeclaration(this.compilationUnit.compilationResult);
198     if (nestedMethod[nestedType] == 0) {
199         if (nestedType != 0) {
200             typeDecl.bits |= ASTNode.IsMemberType;
201         }
202     } else {
203         // Record that the block has a declaration for local types
204
typeDecl.bits |= ASTNode.IsLocalType;
205         markEnclosingMemberWithLocalType();
206         blockReal();
207     }
208
209     //highlight the name of the type
210
long pos = identifierPositionStack[identifierPtr];
211     typeDecl.sourceEnd = (int) pos;
212     typeDecl.sourceStart = (int) (pos >>> 32);
213     typeDecl.name = identifierStack[identifierPtr--];
214     identifierLengthPtr--;
215
216     //compute the declaration source too
217
// 'class' and 'interface' push an int position
218
typeStartPosition = typeDecl.declarationSourceStart = intStack[intPtr--];
219     intPtr--;
220     int declSourceStart = intStack[intPtr--];
221     typeDecl.modifiersSourceStart = intStack[intPtr--];
222     typeDecl.modifiers = intStack[intPtr--];
223     if (typeDecl.declarationSourceStart > declSourceStart) {
224         typeDecl.declarationSourceStart = declSourceStart;
225     }
226     // consume annotations
227
int length;
228     if ((length = this.expressionLengthStack[this.expressionLengthPtr--]) != 0) {
229         System.arraycopy(
230             this.expressionStack,
231             (this.expressionPtr -= length) + 1,
232             typeDecl.annotations = new Annotation[length],
233             0,
234             length);
235     }
236     typeDecl.bodyStart = typeDecl.sourceEnd + 1;
237     pushOnAstStack(typeDecl);
238     // javadoc
239
typeDecl.javadoc = this.javadoc;
240     this.javadoc = null;
241 }
242 /*
243  *
244  * INTERNAL USE-ONLY
245  */

246 protected void consumeCompilationUnit() {
247     // CompilationUnit ::= EnterCompilationUnit PackageDeclarationopt ImportDeclarationsopt
248
requestor.exitCompilationUnit(scanner.source.length - 1);
249 }
250 /*
251  *
252  * INTERNAL USE-ONLY
253  */

254 protected void consumeConstructorDeclaration() {
255     // ConstructorDeclaration ::= ConstructorHeader ConstructorBody
256
super.consumeConstructorDeclaration();
257     if (isLocalDeclaration()) {
258         // we ignore the local variable declarations
259
return;
260     }
261     ConstructorDeclaration cd = (ConstructorDeclaration) astStack[astPtr];
262     requestor.exitConstructor(endStatementPosition, cd.declarationSourceEnd);
263 }
264 /*
265  *
266  * INTERNAL USE-ONLY
267  */

268 protected void consumeConstructorHeader() {
269     // ConstructorHeader ::= ConstructorHeaderName MethodHeaderParameters MethodHeaderThrowsClauseopt
270
super.consumeConstructorHeader();
271     if (isLocalDeclaration()) {
272         // we ignore the local variable declarations
273
intArrayPtr--;
274         return;
275     }
276     ConstructorDeclaration cd = (ConstructorDeclaration) astStack[astPtr];
277     Argument[] arguments = cd.arguments;
278     char[][] argumentTypes = null;
279     char[][] argumentNames = null;
280     int[] argumentTypeStarts = null;
281     int[] argumentTypeEnds = null;
282     int[] argumentNameStarts = null;
283     int[] argumentNameEnds = null;
284     if (arguments != null) {
285         int argumentLength = arguments.length;
286         argumentTypes = new char[argumentLength][];
287         argumentNames = new char[argumentLength][];
288         argumentNameStarts = new int[argumentLength];
289         argumentNameEnds = new int[argumentLength];
290         argumentTypeStarts = new int[argumentLength];
291         argumentTypeEnds = new int[argumentLength];
292         for (int i = 0; i < argumentLength; i++) {
293             Argument argument = arguments[i];
294             TypeReference argumentType = argument.type;
295             argumentTypes[i] = returnTypeName(argumentType);
296             argumentNames[i] = argument.name;
297             argumentNameStarts[i] = argument.sourceStart;
298             argumentNameEnds[i] = argument.sourceEnd;
299             argumentTypeStarts[i] = argumentType.sourceStart;
300             argumentTypeEnds[i] = argumentType.sourceEnd;
301         }
302     }
303     TypeReference[] thrownExceptions = cd.thrownExceptions;
304     char[][] exceptionTypes = null;
305     int[] exceptionTypeStarts = null;
306     int[] exceptionTypeEnds = null;
307     if (thrownExceptions != null) {
308         int thrownExceptionLength = thrownExceptions.length;
309         exceptionTypes = new char[thrownExceptionLength][];
310         exceptionTypeStarts = new int[thrownExceptionLength];
311         exceptionTypeEnds = new int[thrownExceptionLength];
312         for (int i = 0; i < thrownExceptionLength; i++) {
313             TypeReference exception = thrownExceptions[i];
314             exceptionTypes[i] = CharOperation.concatWith(exception.getTypeName(), '.');
315             exceptionTypeStarts[i] = exception.sourceStart;
316             exceptionTypeEnds[i] = exception.sourceEnd;
317         }
318     }
319     requestor
320         .enterConstructor(
321             cd.declarationSourceStart,
322             intArrayStack[intArrayPtr--],
323             cd.modifiers,
324             cd.modifiersSourceStart,
325             cd.selector,
326             cd.sourceStart,
327             (int) (selectorSourcePositions & 0xFFFFFFFFL),
328             // retrieve the source end of the name
329
argumentTypes,
330             argumentTypeStarts,
331             argumentTypeEnds,
332             argumentNames,
333             argumentNameStarts,
334             argumentNameEnds,
335             rParenPos,
336             // right parenthesis
337
exceptionTypes,
338             exceptionTypeStarts,
339             exceptionTypeEnds,
340             scanner.currentPosition - 1);
341 }
342 protected void consumeConstructorHeaderName() {
343     // ConstructorHeaderName ::= Modifiersopt 'Identifier' '('
344
ConstructorDeclaration cd = new ConstructorDeclaration(this.compilationUnit.compilationResult);
345
346     //name -- this is not really revelant but we do .....
347
cd.selector = identifierStack[identifierPtr];
348     selectorSourcePositions = identifierPositionStack[identifierPtr--];
349     identifierLengthPtr--;
350
351     //modifiers
352
cd.declarationSourceStart = intStack[intPtr--];
353     cd.modifiersSourceStart = intStack[intPtr--];
354     cd.modifiers = intStack[intPtr--];
355     // consume annotations
356
int length;
357     if ((length = this.expressionLengthStack[this.expressionLengthPtr--]) != 0) {
358         System.arraycopy(
359             this.expressionStack,
360             (this.expressionPtr -= length) + 1,
361             cd.annotations = new Annotation[length],
362             0,
363             length);
364     }
365     // javadoc
366
cd.javadoc = this.javadoc;
367     this.javadoc = null;
368
369     //highlight starts at the selector starts
370
cd.sourceStart = (int) (selectorSourcePositions >>> 32);
371     pushOnAstStack(cd);
372
373     cd.sourceEnd = lParenPos;
374     cd.bodyStart = lParenPos + 1;
375 }
376 protected void consumeDefaultModifiers() {
377     checkComment(); // might update modifiers with AccDeprecated
378
pushOnIntStack(modifiers); // modifiers
379
pushOnIntStack(-1);
380     pushOnIntStack(
381         declarationSourceStart >= 0 ? declarationSourceStart : scanner.startPosition);
382     resetModifiers();
383     pushOnExpressionStackLengthStack(0);
384 }
385 protected void consumeDiet() {
386     // Diet ::= $empty
387
super.consumeDiet();
388     /* persisting javadoc positions
389      * Will be consume in consumeClassBodyDeclaration
390      */

391     pushOnIntArrayStack(this.getJavaDocPositions());
392 }
393 /*
394  *
395  * INTERNAL USE-ONLY
396  */

397 protected void consumeEnterCompilationUnit() {
398     // EnterCompilationUnit ::= $empty
399
requestor.enterCompilationUnit();
400 }
401 /*
402  *
403  * INTERNAL USE-ONLY
404  */

405 protected void consumeEnterVariable() {
406     // EnterVariable ::= $empty
407
boolean isLocalDeclaration = isLocalDeclaration();
408     if (!isLocalDeclaration && (variablesCounter[nestedType] != 0)) {
409         requestor.exitField(lastFieldBodyEndPosition, lastFieldEndPosition);
410     }
411     char[] varName = identifierStack[identifierPtr];
412     long namePosition = identifierPositionStack[identifierPtr--];
413     int extendedTypeDimension = intStack[intPtr--];
414
415     AbstractVariableDeclaration declaration;
416     if (nestedMethod[nestedType] != 0) {
417         // create the local variable declarations
418
declaration =
419             new LocalDeclaration(varName, (int) (namePosition >>> 32), (int) namePosition);
420     } else {
421         // create the field declaration
422
declaration =
423             new FieldDeclaration(varName, (int) (namePosition >>> 32), (int) namePosition);
424     }
425     identifierLengthPtr--;
426     TypeReference type;
427     int variableIndex = variablesCounter[nestedType];
428     int typeDim = 0;
429     if (variableIndex == 0) {
430         // first variable of the declaration (FieldDeclaration or LocalDeclaration)
431
if (nestedMethod[nestedType] != 0) {
432             // local declaration
433
declaration.declarationSourceStart = intStack[intPtr--];
434             declaration.modifiersSourceStart = intStack[intPtr--];
435             declaration.modifiers = intStack[intPtr--];
436             type = getTypeReference(typeDim = intStack[intPtr--]); // type dimension
437
pushOnAstStack(type);
438         } else {
439             // field declaration
440
type = getTypeReference(typeDim = intStack[intPtr--]); // type dimension
441
pushOnAstStack(type);
442             declaration.declarationSourceStart = intStack[intPtr--];
443             declaration.modifiersSourceStart = intStack[intPtr--];
444             declaration.modifiers = intStack[intPtr--];
445         }
446         // consume annotations
447
int length;
448         if ((length = this.expressionLengthStack[this.expressionLengthPtr--]) != 0) {
449             System.arraycopy(
450                 this.expressionStack,
451                 (this.expressionPtr -= length) + 1,
452                 declaration.annotations = new Annotation[length],
453                 0,
454                 length);
455         }
456     } else {
457         type = (TypeReference) astStack[astPtr - variableIndex];
458         typeDim = type.dimensions();
459         AbstractVariableDeclaration previousVariable =
460             (AbstractVariableDeclaration) astStack[astPtr];
461         declaration.declarationSourceStart = previousVariable.declarationSourceStart;
462         declaration.modifiers = previousVariable.modifiers;
463         declaration.modifiersSourceStart = previousVariable.modifiersSourceStart;
464         final Annotation[] annotations = previousVariable.annotations;
465         if (annotations != null) {
466             final int annotationsLength = annotations.length;
467             System.arraycopy(annotations, 0, declaration.annotations = new Annotation[annotationsLength], 0, annotationsLength);
468         }
469     }
470
471     localIntPtr = intPtr;
472
473     if (extendedTypeDimension == 0) {
474         declaration.type = type;
475     } else {
476         int dimension = typeDim + extendedTypeDimension;
477         declaration.type = this.copyDims(type, dimension);
478     }
479     variablesCounter[nestedType]++;
480     nestedMethod[nestedType]++;
481     pushOnAstStack(declaration);
482
483     int[] javadocPositions = intArrayStack[intArrayPtr];
484     if (!isLocalDeclaration) {
485         requestor
486             .enterField(
487                 declaration.declarationSourceStart,
488                 javadocPositions,
489                 declaration.modifiers,
490                 declaration.modifiersSourceStart,
491                 returnTypeName(declaration.type),
492                 type.sourceStart,
493                 type.sourceEnd,
494                 typeDims,
495                 varName,
496                 (int) (namePosition >>> 32),
497                 (int) namePosition,
498                 extendedTypeDimension,
499                 extendedTypeDimension == 0 ? -1 : endPosition);
500     }
501 }
502 /*
503  *
504  * INTERNAL USE-ONLY
505  */

506 protected void consumeExitVariableWithInitialization() {
507     // ExitVariableWithInitialization ::= $empty
508
// the scanner is located after the comma or the semi-colon.
509
// we want to include the comma or the semi-colon
510
super.consumeExitVariableWithInitialization();
511     nestedMethod[nestedType]--;
512     lastFieldEndPosition = scanner.currentPosition - 1;
513     lastFieldBodyEndPosition = ((AbstractVariableDeclaration) astStack[astPtr]).initialization.sourceEnd;
514 }
515 protected void consumeExitVariableWithoutInitialization() {
516     // ExitVariableWithoutInitialization ::= $empty
517
// do nothing by default
518
super.consumeExitVariableWithoutInitialization();
519     nestedMethod[nestedType]--;
520     lastFieldEndPosition = scanner.currentPosition - 1;
521     lastFieldBodyEndPosition = scanner.startPosition - 1;
522 }
523 /*
524  *
525  * INTERNAL USE-ONLY
526  */

527 protected void consumeFieldDeclaration() {
528     // See consumeLocalVariableDeclarationDefaultModifier() in case of change: duplicated code
529
// FieldDeclaration ::= Modifiersopt Type VariableDeclarators ';'
530
// the super.consumeFieldDeclaration will reinitialize the variableCounter[nestedType]
531
int variableIndex = variablesCounter[nestedType];
532     super.consumeFieldDeclaration();
533     intArrayPtr--;
534     if (isLocalDeclaration())
535         return;
536     if (variableIndex != 0) {
537         requestor.exitField(lastFieldBodyEndPosition, lastFieldEndPosition);
538     }
539 }
540 protected void consumeFormalParameter(boolean isVarArgs) {
541     // FormalParameter ::= Type VariableDeclaratorId ==> false
542
// FormalParameter ::= Modifiers Type VariableDeclaratorId ==> true
543
/*
544     astStack :
545     identifierStack : type identifier
546     intStack : dim dim
547      ==>
548     astStack : Argument
549     identifierStack :
550     intStack :
551     */

552
553     identifierLengthPtr--;
554     char[] parameterName = identifierStack[identifierPtr];
555     long namePositions = identifierPositionStack[identifierPtr--];
556     int extendedDimensions = this.intStack[this.intPtr--];
557     int endOfEllipsis = 0;
558     if (isVarArgs) {
559         endOfEllipsis = this.intStack[this.intPtr--];
560     }
561     int firstDimensions = this.intStack[this.intPtr--];
562     final int typeDimensions = firstDimensions + extendedDimensions;
563     TypeReference type = getTypeReference(typeDimensions);
564     if (isVarArgs) {
565         type = copyDims(type, typeDimensions + 1);
566         if (extendedDimensions == 0) {
567             type.sourceEnd = endOfEllipsis;
568         }
569         type.bits |= ASTNode.IsVarArgs; // set isVarArgs
570
}
571     intPtr -= 3;
572     Argument arg =
573         new Argument(
574             parameterName,
575             namePositions,
576             type,
577             intStack[intPtr + 1]);// modifiers
578
// consume annotations
579
int length;
580     if ((length = this.expressionLengthStack[this.expressionLengthPtr--]) != 0) {
581         System.arraycopy(
582             this.expressionStack,
583             (this.expressionPtr -= length) + 1,
584             arg.annotations = new Annotation[length],
585             0,
586             length);
587     }
588     pushOnAstStack(arg);
589     intArrayPtr--;
590 }
591 /*
592  *
593  * INTERNAL USE-ONLY
594  */

595 protected void consumeInterfaceDeclaration() {
596     super.consumeInterfaceDeclaration();
597     // we know that we have a TypeDeclaration on the top of the astStack
598
if (isLocalDeclaration()) {
599         // we ignore the local variable declarations
600
return;
601     }
602     requestor.exitInterface(endStatementPosition, // the '}' is the end of the body
603
((TypeDeclaration) astStack[astPtr]).declarationSourceEnd);
604 }
605 /*
606  *
607  * INTERNAL USE-ONLY
608  */

609 protected void consumeInterfaceHeader() {
610     //InterfaceHeader ::= $empty
611
super.consumeInterfaceHeader();
612     if (isLocalDeclaration()) {
613         // we ignore the local variable declarations
614
intArrayPtr--;
615         return;
616     }
617     TypeDeclaration typeDecl = (TypeDeclaration) astStack[astPtr];
618     TypeReference[] superInterfaces = typeDecl.superInterfaces;
619     char[][] interfaceNames = null;
620     int[] interfaceNameStarts = null;
621     int[] interfacenameEnds = null;
622     int superInterfacesLength = 0;
623     if (superInterfaces != null) {
624         superInterfacesLength = superInterfaces.length;
625         interfaceNames = new char[superInterfacesLength][];
626         interfaceNameStarts = new int[superInterfacesLength];
627         interfacenameEnds = new int[superInterfacesLength];
628     }
629     if (superInterfaces != null) {
630         for (int i = 0; i < superInterfacesLength; i++) {
631             TypeReference superInterface = superInterfaces[i];
632             interfaceNames[i] = CharOperation.concatWith(superInterface.getTypeName(), '.');
633             interfaceNameStarts[i] = superInterface.sourceStart;
634             interfacenameEnds[i] = superInterface.sourceEnd;
635         }
636     }
637     // flush the comments related to the interface header
638
scanner.commentPtr = -1;
639     requestor.enterInterface(
640         typeDecl.declarationSourceStart,
641         intArrayStack[intArrayPtr--],
642         typeDecl.modifiers,
643         typeDecl.modifiersSourceStart,
644         typeStartPosition,
645         typeDecl.name,
646         typeDecl.sourceStart,
647         typeDecl.sourceEnd,
648         interfaceNames,
649         interfaceNameStarts,
650         interfacenameEnds,
651         scanner.currentPosition - 1);
652 }
653 protected void consumeInterfaceHeaderName1() {
654     // InterfaceHeaderName ::= Modifiersopt 'interface' 'Identifier'
655
TypeDeclaration typeDecl = new TypeDeclaration(this.compilationUnit.compilationResult);
656     if (nestedMethod[nestedType] == 0) {
657         if (nestedType != 0) {
658             typeDecl.bits |= ASTNode.IsMemberType;
659         }
660     } else {
661         // Record that the block has a declaration for local types
662
typeDecl.bits |= ASTNode.IsLocalType;
663         markEnclosingMemberWithLocalType();
664         blockReal();
665     }
666
667     //highlight the name of the type
668
long pos = identifierPositionStack[identifierPtr];
669     typeDecl.sourceEnd = (int) pos;
670     typeDecl.sourceStart = (int) (pos >>> 32);
671     typeDecl.name = identifierStack[identifierPtr--];
672     identifierLengthPtr--;
673
674     //compute the declaration source too
675
// 'class' and 'interface' push an int position
676
typeStartPosition = typeDecl.declarationSourceStart = intStack[intPtr--];
677     intPtr--;
678     int declSourceStart = intStack[intPtr--];
679     typeDecl.modifiersSourceStart = intStack[intPtr--];
680     typeDecl.modifiers = this.intStack[this.intPtr--] | ClassFileConstants.AccInterface;
681     if (typeDecl.declarationSourceStart > declSourceStart) {
682         typeDecl.declarationSourceStart = declSourceStart;
683     }
684     // consume annotations
685
int length;
686     if ((length = this.expressionLengthStack[this.expressionLengthPtr--]) != 0) {
687         System.arraycopy(
688             this.expressionStack,
689             (this.expressionPtr -= length) + 1,
690             typeDecl.annotations = new Annotation[length],
691             0,
692             length);
693     }
694     typeDecl.bodyStart = typeDecl.sourceEnd + 1;
695     pushOnAstStack(typeDecl);
696     // javadoc
697
typeDecl.javadoc = this.javadoc;
698     this.javadoc = null;
699 }
700 protected void consumeInternalCompilationUnit() {
701     // InternalCompilationUnit ::= PackageDeclaration
702
// InternalCompilationUnit ::= PackageDeclaration ImportDeclarations ReduceImports
703
// InternalCompilationUnit ::= ImportDeclarations ReduceImports
704
}
705 protected void consumeInternalCompilationUnitWithTypes() {
706     // InternalCompilationUnit ::= PackageDeclaration ImportDeclarations ReduceImports TypeDeclarations
707
// InternalCompilationUnit ::= PackageDeclaration TypeDeclarations
708
// InternalCompilationUnit ::= TypeDeclarations
709
// InternalCompilationUnit ::= ImportDeclarations ReduceImports TypeDeclarations
710
// consume type declarations
711
int length;
712     if ((length = this.astLengthStack[this.astLengthPtr--]) != 0) {
713         this.compilationUnit.types = new TypeDeclaration[length];
714         this.astPtr -= length;
715         System.arraycopy(this.astStack, this.astPtr + 1, this.compilationUnit.types, 0, length);
716     }
717 }
718 /*
719  *
720  * INTERNAL USE-ONLY
721  */

722 protected void consumeLocalVariableDeclaration() {
723     // See consumeLocalVariableDeclarationDefaultModifier() in case of change: duplicated code
724
// FieldDeclaration ::= Modifiersopt Type VariableDeclarators ';'
725

726     super.consumeLocalVariableDeclaration();
727     intArrayPtr--;
728 }
729 /*
730  *
731  * INTERNAL USE-ONLY
732  */

733 protected void consumeMethodDeclaration(boolean isNotAbstract) {
734     // MethodDeclaration ::= MethodHeader MethodBody
735
// AbstractMethodDeclaration ::= MethodHeader ';'
736
super.consumeMethodDeclaration(isNotAbstract);
737     if (isLocalDeclaration()) {
738         // we ignore the local variable declarations
739
return;
740     }
741     MethodDeclaration md = (MethodDeclaration) astStack[astPtr];
742     requestor.exitMethod(endStatementPosition, md.declarationSourceEnd);
743 }
744 /*
745  *
746  * INTERNAL USE-ONLY
747  */

748 protected void consumeMethodHeader() {
749     // MethodHeader ::= MethodHeaderName MethodHeaderParameters MethodHeaderExtendedDims ThrowsClauseopt
750
super.consumeMethodHeader();
751     if (isLocalDeclaration()) {
752         // we ignore the local variable declarations
753
intArrayPtr--;
754         return;
755     }
756     MethodDeclaration md = (MethodDeclaration) astStack[astPtr];
757
758     TypeReference returnType = md.returnType;
759     char[] returnTypeName = returnTypeName(returnType);
760     Argument[] arguments = md.arguments;
761     char[][] argumentTypes = null;
762     char[][] argumentNames = null;
763     int[] argumentTypeStarts = null;
764     int[] argumentTypeEnds = null;
765     int[] argumentNameStarts = null;
766     int[] argumentNameEnds = null;
767     if (arguments != null) {
768         int argumentLength = arguments.length;
769         argumentTypes = new char[argumentLength][];
770         argumentNames = new char[argumentLength][];
771         argumentNameStarts = new int[argumentLength];
772         argumentNameEnds = new int[argumentLength];
773         argumentTypeStarts = new int[argumentLength];
774         argumentTypeEnds = new int[argumentLength];
775         for (int i = 0; i < argumentLength; i++) {
776             Argument argument = arguments[i];
777             TypeReference argumentType = argument.type;
778             argumentTypes[i] = returnTypeName(argumentType);
779             argumentNames[i] = argument.name;
780             argumentNameStarts[i] = argument.sourceStart;
781             argumentNameEnds[i] = argument.sourceEnd;
782             argumentTypeStarts[i] = argumentType.sourceStart;
783             argumentTypeEnds[i] = argumentType.sourceEnd;
784         }
785     }
786     TypeReference[] thrownExceptions = md.thrownExceptions;
787     char[][] exceptionTypes = null;
788     int[] exceptionTypeStarts = null;
789     int[] exceptionTypeEnds = null;
790     if (thrownExceptions != null) {
791         int thrownExceptionLength = thrownExceptions.length;
792         exceptionTypeStarts = new int[thrownExceptionLength];
793         exceptionTypeEnds = new int[thrownExceptionLength];
794         exceptionTypes = new char[thrownExceptionLength][];
795         for (int i = 0; i < thrownExceptionLength; i++) {
796             TypeReference exception = thrownExceptions[i];
797             exceptionTypes[i] = CharOperation.concatWith(exception.getTypeName(), '.');
798             exceptionTypeStarts[i] = exception.sourceStart;
799             exceptionTypeEnds[i] = exception.sourceEnd;
800         }
801     }
802     requestor
803         .enterMethod(
804             md.declarationSourceStart,
805             intArrayStack[intArrayPtr--],
806             md.modifiers,
807             md.modifiersSourceStart,
808             returnTypeName,
809             returnType.sourceStart,
810             returnType.sourceEnd,
811             typeDims,
812             md.selector,
813             md.sourceStart,
814             (int) (selectorSourcePositions & 0xFFFFFFFFL),
815             argumentTypes,
816             argumentTypeStarts,
817             argumentTypeEnds,
818             argumentNames,
819             argumentNameStarts,
820             argumentNameEnds,
821             rParenPos,
822             extendsDim,
823             extendsDim == 0 ? -1 : endPosition,
824             exceptionTypes,
825             exceptionTypeStarts,
826             exceptionTypeEnds,
827             scanner.currentPosition - 1);
828 }
829 protected void consumeMethodHeaderExtendedDims() {
830     // MethodHeaderExtendedDims ::= Dimsopt
831
// now we update the returnType of the method
832
MethodDeclaration md = (MethodDeclaration) astStack[astPtr];
833     int extendedDims = intStack[intPtr--];
834     extendsDim = extendedDims;
835     if (extendedDims != 0) {
836         TypeReference returnType = md.returnType;
837         md.sourceEnd = endPosition;
838         int dims = returnType.dimensions() + extendedDims;
839         md.returnType = this.copyDims(returnType, dims);
840         if (currentToken == TokenNameLBRACE) {
841             md.bodyStart = endPosition + 1;
842         }
843     }
844 }
845 protected void consumeMethodHeaderName(boolean isAnnotationMethod) {
846     // MethodHeaderName ::= Modifiersopt Type 'Identifier' '('
847
MethodDeclaration md = null;
848     if(isAnnotationMethod) {
849         md = new AnnotationMethodDeclaration(this.compilationUnit.compilationResult);
850     } else {
851         md = new MethodDeclaration(this.compilationUnit.compilationResult);
852     }
853     //name
854
md.selector = identifierStack[identifierPtr];
855     selectorSourcePositions = identifierPositionStack[identifierPtr--];
856     identifierLengthPtr--;
857     //type
858
md.returnType = getTypeReference(typeDims = intStack[intPtr--]);
859     //modifiers
860
md.declarationSourceStart = intStack[intPtr--];
861     md.modifiersSourceStart = intStack[intPtr--];
862     md.modifiers = intStack[intPtr--];
863     // consume annotations
864
int length;
865     if ((length = this.expressionLengthStack[this.expressionLengthPtr--]) != 0) {
866         System.arraycopy(
867             this.expressionStack,
868             (this.expressionPtr -= length) + 1,
869             md.annotations = new Annotation[length],
870             0,
871             length);
872     }
873     // javadoc
874
md.javadoc = this.javadoc;
875     this.javadoc = null;
876
877     //highlight starts at selector start
878
md.sourceStart = (int) (selectorSourcePositions >>> 32);
879     pushOnAstStack(md);
880     md.bodyStart = scanner.currentPosition-1;
881 }
882 protected void consumeModifiers() {
883     checkComment(); // might update modifiers with AccDeprecated
884
pushOnIntStack(modifiers); // modifiers
885
pushOnIntStack(modifiersSourceStart);
886     pushOnIntStack(
887         declarationSourceStart >= 0 ? declarationSourceStart : modifiersSourceStart);
888     resetModifiers();
889 }
890 /*
891  *
892  * INTERNAL USE-ONLY
893  */

894 protected void consumePackageDeclarationName() {
895     /* persisting javadoc positions */
896     pushOnIntArrayStack(this.getJavaDocPositions());
897
898     super.consumePackageDeclarationName();
899     ImportReference importReference = compilationUnit.currentPackage;
900
901     requestor.acceptPackage(
902         importReference.declarationSourceStart,
903         importReference.declarationSourceEnd,
904         intArrayStack[intArrayPtr--],
905         CharOperation.concatWith(importReference.getImportName(), '.'),
906         importReference.sourceStart);
907 }
908 /*
909 *
910 * INTERNAL USE-ONLY
911 */

912 protected void consumePackageDeclarationNameWithModifiers() {
913     /* persisting javadoc positions */
914     pushOnIntArrayStack(this.getJavaDocPositions());
915
916     super.consumePackageDeclarationNameWithModifiers();
917     ImportReference importReference = compilationUnit.currentPackage;
918
919     requestor.acceptPackage(
920         importReference.declarationSourceStart,
921         importReference.declarationSourceEnd,
922         intArrayStack[intArrayPtr--],
923         CharOperation.concatWith(importReference.getImportName(), '.'),
924         importReference.sourceStart);
925 }
926 protected void consumePushModifiers() {
927     checkComment(); // might update modifiers with AccDeprecated
928
pushOnIntStack(modifiers); // modifiers
929
if (modifiersSourceStart < 0) {
930         pushOnIntStack(-1);
931         pushOnIntStack(
932             declarationSourceStart >= 0 ? declarationSourceStart : scanner.startPosition);
933     } else {
934         pushOnIntStack(modifiersSourceStart);
935         pushOnIntStack(
936             declarationSourceStart >= 0 ? declarationSourceStart : modifiersSourceStart);
937     }
938     resetModifiers();
939     pushOnExpressionStackLengthStack(0);
940 }
941 protected void consumePushRealModifiers() {
942     checkComment(); // might update modifiers with AccDeprecated
943
pushOnIntStack(modifiers); // modifiers
944
if (modifiersSourceStart < 0) {
945         pushOnIntStack(-1);
946         pushOnIntStack(
947             declarationSourceStart >= 0 ? declarationSourceStart : scanner.startPosition);
948     } else {
949         pushOnIntStack(modifiersSourceStart);
950         pushOnIntStack(
951             declarationSourceStart >= 0 ? declarationSourceStart : modifiersSourceStart);
952     }
953     resetModifiers();
954 }
955 protected void consumeSingleStaticImportDeclarationName() {
956     // SingleTypeImportDeclarationName ::= 'import' 'static' Name
957

958     /* persisting javadoc positions */
959     pushOnIntArrayStack(this.getJavaDocPositions());
960
961     super.consumeSingleStaticImportDeclarationName();
962     ImportReference importReference = (ImportReference) astStack[astPtr];
963     requestor.acceptImport(
964         importReference.declarationSourceStart,
965         importReference.declarationSourceEnd,
966         intArrayStack[intArrayPtr--],
967         CharOperation.concatWith(importReference.getImportName(), '.'),
968         importReference.sourceStart,
969         false,
970         ClassFileConstants.AccStatic);
971 }
972 /*
973  *
974  * INTERNAL USE-ONLY
975  */

976 protected void consumeSingleTypeImportDeclarationName() {
977     // SingleTypeImportDeclarationName ::= 'import' Name
978

979     /* persisting javadoc positions */
980     pushOnIntArrayStack(this.getJavaDocPositions());
981
982     super.consumeSingleTypeImportDeclarationName();
983     ImportReference importReference = (ImportReference) astStack[astPtr];
984     requestor.acceptImport(
985         importReference.declarationSourceStart,
986         importReference.declarationSourceEnd,
987         intArrayStack[intArrayPtr--],
988         CharOperation.concatWith(importReference.getImportName(), '.'),
989         importReference.sourceStart,
990         false,
991         ClassFileConstants.AccDefault);
992 }
993 protected void consumeStaticImportOnDemandDeclarationName() {
994     // SingleTypeImportDeclarationName ::= 'import' 'static' Name '.' '*'
995

996     /* persisting javadoc positions */
997     pushOnIntArrayStack(this.getJavaDocPositions());
998
999     super.consumeStaticImportOnDemandDeclarationName();
1000    ImportReference importReference = (ImportReference) astStack[astPtr];
1001    requestor.acceptImport(
1002        importReference.declarationSourceStart,
1003        importReference.declarationSourceEnd,
1004        intArrayStack[intArrayPtr--],
1005        CharOperation.concatWith(importReference.getImportName(), '.'),
1006        importReference.sourceStart,
1007        true,
1008        ClassFileConstants.AccStatic);
1009}
1010/*
1011 *
1012 * INTERNAL USE-ONLY
1013 */

1014protected void consumeStaticInitializer() {
1015    // StaticInitializer ::= StaticOnly Block
1016
//push an Initializer
1017
//optimize the push/pop
1018
super.consumeStaticInitializer();
1019    Initializer initializer = (Initializer) astStack[astPtr];
1020    requestor.acceptInitializer(
1021        initializer.declarationSourceStart,
1022        initializer.declarationSourceEnd,
1023        intArrayStack[intArrayPtr--],
1024        ClassFileConstants.AccStatic,
1025        intStack[intPtr--],
1026        initializer.block.sourceStart,
1027        initializer.declarationSourceEnd);
1028}
1029protected void consumeStaticOnly() {
1030    // StaticOnly ::= 'static'
1031
checkComment(); // might update declaration source start
1032
pushOnIntStack(modifiersSourceStart);
1033    pushOnIntStack(scanner.currentPosition);
1034    pushOnIntStack(
1035        declarationSourceStart >= 0 ? declarationSourceStart : modifiersSourceStart);
1036    jumpOverMethodBody();
1037    nestedMethod[nestedType]++;
1038    resetModifiers();
1039}
1040/*
1041 *
1042 * INTERNAL USE-ONLY
1043 */

1044protected void consumeTypeImportOnDemandDeclarationName() {
1045    // TypeImportOnDemandDeclarationName ::= 'import' Name '.' '*'
1046

1047    /* persisting javadoc positions */
1048    pushOnIntArrayStack(this.getJavaDocPositions());
1049
1050    super.consumeTypeImportOnDemandDeclarationName();
1051    ImportReference importReference = (ImportReference) astStack[astPtr];
1052    requestor.acceptImport(
1053        importReference.declarationSourceStart,
1054        importReference.declarationSourceEnd,
1055        intArrayStack[intArrayPtr--],
1056        CharOperation.concatWith(importReference.getImportName(), '.'),
1057        importReference.sourceStart,
1058        true,
1059        ClassFileConstants.AccDefault);
1060}
1061/*
1062 * Flush javadocs defined prior to a given positions.
1063 *
1064 * Note: javadocs are stacked in syntactical order
1065 *
1066 * Either answer given <position>, or the end position of a comment line
1067 * immediately following the <position> (same line)
1068 *
1069 * e.g.
1070 * void foo(){
1071 * } // end of method foo
1072 */

1073 
1074public int flushCommentsDefinedPriorTo(int position) {
1075
1076    return lastFieldEndPosition = super.flushCommentsDefinedPriorTo(position);
1077}
1078public CompilationUnitDeclaration endParse(int act) {
1079    if (scanner.recordLineSeparator) {
1080        requestor.acceptLineSeparatorPositions(scanner.getLineEnds());
1081    }
1082    return super.endParse(act);
1083}
1084public void initialize(boolean initializeNLS) {
1085    //positionning the parser for a new compilation unit
1086
//avoiding stack reallocation and all that....
1087
super.initialize(initializeNLS);
1088    intArrayPtr = -1;
1089}
1090public void initialize() {
1091    //positionning the parser for a new compilation unit
1092
//avoiding stack reallocation and all that....
1093
super.initialize();
1094    intArrayPtr = -1;
1095}
1096/*
1097 *
1098 * INTERNAL USE-ONLY
1099 */

1100private boolean isLocalDeclaration() {
1101    int nestedDepth = nestedType;
1102    while (nestedDepth >= 0) {
1103        if (nestedMethod[nestedDepth] != 0) {
1104            return true;
1105        }
1106        nestedDepth--;
1107    }
1108    return false;
1109}
1110protected void parse() {
1111    this.diet = true;
1112    super.parse();
1113}
1114/*
1115 * Investigate one entire unit.
1116 */

1117public void parseCompilationUnit(ICompilationUnit unit) {
1118    char[] regionSource = unit.getContents();
1119    try {
1120        initialize(true);
1121        goForCompilationUnit();
1122        referenceContext =
1123            compilationUnit =
1124                new CompilationUnitDeclaration(
1125                    problemReporter(),
1126                    new CompilationResult(unit, 0, 0, this.options.maxProblemsPerUnit),
1127                    regionSource.length);
1128        scanner.resetTo(0, regionSource.length);
1129        scanner.setSource(regionSource);
1130        parse();
1131    } catch (AbortCompilation ex) {
1132        // ignore this exception
1133
}
1134}
1135/*
1136 * Investigate one constructor declaration.
1137 */

1138public void parseConstructor(char[] regionSource) {
1139    try {
1140        initialize();
1141        goForClassBodyDeclarations();
1142        referenceContext =
1143            compilationUnit =
1144                new CompilationUnitDeclaration(
1145                    problemReporter(),
1146                    new CompilationResult(regionSource, 0, 0, this.options.maxProblemsPerUnit),
1147                    regionSource.length);
1148        scanner.resetTo(0, regionSource.length);
1149        scanner.setSource(regionSource);
1150        parse();
1151    } catch (AbortCompilation ex) {
1152        // ignore this exception
1153
}
1154}
1155/*
1156 * Investigate one field declaration statement (might have multiple declarations in it).
1157 */

1158public void parseField(char[] regionSource) {
1159    try {
1160        initialize();
1161        goForFieldDeclaration();
1162        referenceContext =
1163            compilationUnit =
1164                new CompilationUnitDeclaration(
1165                    problemReporter(),
1166                    new CompilationResult(regionSource, 0, 0, this.options.maxProblemsPerUnit),
1167                    regionSource.length);
1168        scanner.resetTo(0, regionSource.length);
1169        scanner.setSource(regionSource);
1170        parse();
1171    } catch (AbortCompilation ex) {
1172        // ignore this exception
1173
}
1174
1175}
1176/*
1177 * Investigate one import statement declaration.
1178 */

1179public void parseImport(char[] regionSource) {
1180    try {
1181        initialize();
1182        goForImportDeclaration();
1183        referenceContext =
1184            compilationUnit =
1185                new CompilationUnitDeclaration(
1186                    problemReporter(),
1187                    new CompilationResult(regionSource, 0, 0, this.options.maxProblemsPerUnit),
1188                    regionSource.length);
1189        scanner.resetTo(0, regionSource.length);
1190        scanner.setSource(regionSource);
1191        parse();
1192    } catch (AbortCompilation ex) {
1193        // ignore this exception
1194
}
1195
1196}
1197/*
1198 * Investigate one initializer declaration.
1199 * regionSource need to content exactly an initializer declaration.
1200 * e.g: static { i = 4; }
1201 * { name = "test"; }
1202 */

1203public void parseInitializer(char[] regionSource) {
1204    try {
1205        initialize();
1206        goForInitializer();
1207        referenceContext =
1208            compilationUnit =
1209                new CompilationUnitDeclaration(
1210                    problemReporter(),
1211                    new CompilationResult(regionSource, 0, 0, this.options.maxProblemsPerUnit),
1212                    regionSource.length);
1213        scanner.resetTo(0, regionSource.length);
1214        scanner.setSource(regionSource);
1215        parse();
1216    } catch (AbortCompilation ex) {
1217        // ignore this exception
1218
}
1219
1220}
1221/*
1222 * Investigate one method declaration.
1223 */

1224public void parseMethod(char[] regionSource) {
1225    try {
1226        initialize();
1227        goForGenericMethodDeclaration();
1228        referenceContext =
1229            compilationUnit =
1230                new CompilationUnitDeclaration(
1231                    problemReporter(),
1232                    new CompilationResult(regionSource, 0, 0, this.options.maxProblemsPerUnit),
1233                    regionSource.length);
1234        scanner.resetTo(0, regionSource.length);
1235        scanner.setSource(regionSource);
1236        parse();
1237    } catch (AbortCompilation ex) {
1238        // ignore this exception
1239
}
1240}
1241/*
1242 * Investigate one package statement declaration.
1243 */

1244public void parsePackage(char[] regionSource) {
1245    try {
1246        initialize();
1247        goForPackageDeclaration();
1248        referenceContext =
1249            compilationUnit =
1250                new CompilationUnitDeclaration(
1251                    problemReporter(),
1252                    new CompilationResult(regionSource, 0, 0, this.options.maxProblemsPerUnit),
1253                    regionSource.length);
1254        scanner.resetTo(0, regionSource.length);
1255        scanner.setSource(regionSource);
1256        parse();
1257    } catch (AbortCompilation ex) {
1258        // ignore this exception
1259
}
1260
1261}
1262/*
1263 * Investigate one type declaration, its fields, methods and member types.
1264 */

1265public void parseType(char[] regionSource) {
1266    try {
1267        initialize();
1268        goForTypeDeclaration();
1269        referenceContext =
1270            compilationUnit =
1271                new CompilationUnitDeclaration(
1272                    problemReporter(),
1273                    new CompilationResult(regionSource, 0, 0, this.options.maxProblemsPerUnit),
1274                    regionSource.length);
1275        scanner.resetTo(0, regionSource.length);
1276        scanner.setSource(regionSource);
1277        parse();
1278    } catch (AbortCompilation ex) {
1279        // ignore this exception
1280
}
1281
1282}
1283/**
1284 * Returns this parser's problem reporter initialized with its reference context.
1285 * Also it is assumed that a problem is going to be reported, so initializes
1286 * the compilation result's line positions.
1287 *
1288 * @return ProblemReporter
1289 */

1290public ProblemReporter problemReporter() {
1291    problemReporter.referenceContext = referenceContext;
1292    return problemReporter;
1293}
1294protected void pushOnIntArrayStack(int[] positions) {
1295
1296    int stackLength = this.intArrayStack.length;
1297    if (++this.intArrayPtr >= stackLength) {
1298        System.arraycopy(
1299            this.intArrayStack, 0,
1300            this.intArrayStack = new int[stackLength + StackIncrement][], 0,
1301            stackLength);
1302    }
1303    intArrayStack[intArrayPtr] = positions;
1304}
1305protected void resetModifiers() {
1306    super.resetModifiers();
1307    declarationSourceStart = -1;
1308}
1309/*
1310 * Syntax error was detected. Will attempt to perform some recovery action in order
1311 * to resume to the regular parse loop.
1312 */

1313protected boolean resumeOnSyntaxError() {
1314    return false;
1315}
1316/*
1317 * Answer a char array representation of the type name formatted like:
1318 * - type name + dimensions
1319 * Example:
1320 * "A[][]".toCharArray()
1321 * "java.lang.String".toCharArray()
1322 */

1323private char[] returnTypeName(TypeReference type) {
1324    int dimension = type.dimensions();
1325    if (dimension != 0) {
1326        char[] dimensionsArray = new char[dimension * 2];
1327        for (int i = 0; i < dimension; i++) {
1328            dimensionsArray[i*2] = '[';
1329            dimensionsArray[(i*2) + 1] = ']';
1330        }
1331        return CharOperation.concat(
1332            CharOperation.concatWith(type.getTypeName(), '.'),
1333            dimensionsArray);
1334    }
1335    return CharOperation.concatWith(type.getTypeName(), '.');
1336}
1337public String JavaDoc toString() {
1338    StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
1339    buffer.append("intArrayPtr = " + intArrayPtr + "\n"); //$NON-NLS-1$ //$NON-NLS-2$
1340
buffer.append(super.toString());
1341    return buffer.toString();
1342}
1343/**
1344 * INTERNAL USE ONLY
1345 */

1346protected TypeReference typeReference(
1347    int dim,
1348    int localIdentifierPtr,
1349    int localIdentifierLengthPtr) {
1350    /* build a Reference on a variable that may be qualified or not
1351     * This variable is a type reference and dim will be its dimensions.
1352     * We don't have any side effect on the stacks' pointers.
1353     */

1354
1355    int length;
1356    TypeReference ref;
1357    if ((length = identifierLengthStack[localIdentifierLengthPtr]) == 1) {
1358        // single variable reference
1359
if (dim == 0) {
1360            ref =
1361                new SingleTypeReference(
1362                    identifierStack[localIdentifierPtr],
1363                    identifierPositionStack[localIdentifierPtr--]);
1364        } else {
1365            ref =
1366                new ArrayTypeReference(
1367                    identifierStack[localIdentifierPtr],
1368                    dim,
1369                    identifierPositionStack[localIdentifierPtr--]);
1370            ref.sourceEnd = endPosition;
1371        }
1372    } else {
1373        if (length < 0) { //flag for precompiled type reference on base types
1374
ref = TypeReference.baseTypeReference(-length, dim);
1375            ref.sourceStart = intStack[localIntPtr--];
1376            if (dim == 0) {
1377                ref.sourceEnd = intStack[localIntPtr--];
1378            } else {
1379                localIntPtr--;
1380                ref.sourceEnd = endPosition;
1381            }
1382        } else { //Qualified variable reference
1383
char[][] tokens = new char[length][];
1384            localIdentifierPtr -= length;
1385            long[] positions = new long[length];
1386            System.arraycopy(identifierStack, localIdentifierPtr + 1, tokens, 0, length);
1387            System.arraycopy(
1388                identifierPositionStack,
1389                localIdentifierPtr + 1,
1390                positions,
1391                0,
1392                length);
1393            if (dim == 0)
1394                ref = new QualifiedTypeReference(tokens, positions);
1395            else
1396                ref = new ArrayQualifiedTypeReference(tokens, dim, positions);
1397        }
1398    }
1399    return ref;
1400}
1401}
1402
Popular Tags