added file extension php5
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / compiler / DocumentElementParser.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2003 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials 
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  * 
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11 package net.sourceforge.phpdt.internal.compiler;
12
13 import net.sourceforge.phpdt.core.compiler.IProblem;
14 import net.sourceforge.phpdt.internal.compiler.env.ICompilationUnit;
15 import net.sourceforge.phpdt.internal.compiler.impl.CompilerOptions;
16 import net.sourceforge.phpdt.internal.compiler.parser.UnitParser;
17 import net.sourceforge.phpdt.internal.compiler.problem.AbortCompilation;
18 import net.sourceforge.phpdt.internal.compiler.problem.ProblemReporter;
19 import net.sourceforge.phpeclipse.internal.compiler.ast.CompilationUnitDeclaration;
20
21
22 /*
23  * A document element parser extracts structural information
24  * from a piece of source, providing detailed source positions info.
25  *
26  * also see @IDocumentElementRequestor
27  *
28  * The structural investigation includes:
29  * - the package statement
30  * - import statements
31  * - top-level types: package member, member types (member types of member types...)
32  * - fields
33  * - methods
34  *
35  * Any (parsing) problem encountered is also provided.
36  */
37 public class DocumentElementParser extends UnitParser {
38         IDocumentElementRequestor requestor;
39         private int localIntPtr;
40         private int lastFieldEndPosition;
41         private int lastFieldBodyEndPosition;   
42         private int typeStartPosition;
43         private long selectorSourcePositions;
44         private int typeDims;
45         private int extendsDim;
46         private int declarationSourceStart;
47
48         /* int[] stack for storing javadoc positions */
49         int[][] intArrayStack;
50         int intArrayPtr;
51         
52 //      CompilerOptions options;
53         
54 public DocumentElementParser(
55         final IDocumentElementRequestor requestor, 
56         IProblemFactory problemFactory,
57         CompilerOptions options) {
58         super(new ProblemReporter(
59                 DefaultErrorHandlingPolicies.exitAfterAllProblems(), 
60                 options, 
61                 problemFactory) {
62                 public void record(IProblem problem, CompilationResult unitResult) {
63                         requestor.acceptProblem(problem);
64                 }
65         });
66 //      false,
67 //      options.sourceLevel >= CompilerOptions.JDK1_4);
68         this.requestor = requestor;
69         intArrayStack = new int[30][];
70         this.options = options;
71 }
72
73 /**
74  *
75  * INTERNAL USE-ONLY
76  */
77 //protected void adjustInterfaceModifiers() {
78 //      intStack[intPtr - 2] |= AccInterface;
79 //}
80 /*
81  * Will clear the comment stack when looking
82  * for a potential JavaDoc which might contain @deprecated.
83  *
84  * Additionally, before investigating for @deprecated, retrieve the positions
85  * of the JavaDoc comments so as to notify requestor with them.
86  */
87 //public void checkAnnotation() {
88 //
89 //      /* persisting javadoc positions */
90 //      pushOnIntArrayStack(this.getJavaDocPositions());
91 //      boolean deprecated = false;
92 //      int lastAnnotationIndex = -1;
93 //      int commentPtr = scanner.commentPtr;
94 //
95 //      //since jdk1.2 look only in the last java doc comment...
96 //      nextComment : for (lastAnnotationIndex = scanner.commentPtr; lastAnnotationIndex >= 0; lastAnnotationIndex--){
97 //              //look for @deprecated into the first javadoc comment preceeding the declaration
98 //              int commentSourceStart = scanner.commentStarts[lastAnnotationIndex];
99 //              // javadoc only (non javadoc comment have negative end positions.)
100 //              if (modifiersSourceStart != -1 && modifiersSourceStart < commentSourceStart) {
101 //                      continue nextComment;
102 //              }
103 //              if (scanner.commentStops[lastAnnotationIndex] < 0) {
104 //                      continue nextComment;
105 //              }
106 //              int commentSourceEnd = scanner.commentStops[lastAnnotationIndex] - 1; //stop is one over
107 //              char[] comment = scanner.source;
108 //
109 //              deprecated =
110 //                      checkDeprecation(
111 //                              commentSourceStart,
112 //                              commentSourceEnd,
113 //                              comment);
114 //              break nextComment;
115 //      }
116 //      if (deprecated) {
117 //              checkAndSetModifiers(AccDeprecated);
118 //      }
119 //      // modify the modifier source start to point at the first comment
120 //      if (commentPtr >= 0) {
121 //              declarationSourceStart = scanner.commentStarts[0];
122 //      }
123 //}
124 /**
125  *
126  * INTERNAL USE-ONLY
127  */
128 //protected void consumeClassBodyDeclaration() {
129 //      // ClassBodyDeclaration ::= Diet Block
130 //      //push an Initializer
131 //      //optimize the push/pop
132 //
133 //      super.consumeClassBodyDeclaration();
134 //      Initializer initializer = (Initializer) astStack[astPtr];
135 //      requestor.acceptInitializer(
136 //              initializer.declarationSourceStart,
137 //              initializer.declarationSourceEnd,
138 //              intArrayStack[intArrayPtr--], 
139 //              0,
140 //              modifiersSourceStart, 
141 //              initializer.block.sourceStart,
142 //              initializer.block.sourceEnd);
143 //}
144 ///**
145 // *
146 // * INTERNAL USE-ONLY
147 // */
148 //protected void consumeClassDeclaration() {
149 //      super.consumeClassDeclaration();
150 //      // we know that we have a TypeDeclaration on the top of the astStack
151 //      if (isLocalDeclaration()) {
152 //              // we ignore the local variable declarations
153 //              return;
154 //      }
155 //      requestor.exitClass(endStatementPosition, // '}' is the end of the body 
156 //       ((TypeDeclaration) astStack[astPtr]).declarationSourceEnd);
157 //}
158 ///**
159 // *
160 // * INTERNAL USE-ONLY
161 // */
162 //protected void consumeClassHeader() {
163 //      //ClassHeader ::= $empty
164 //      super.consumeClassHeader();
165 //      if (isLocalDeclaration()) {
166 //              // we ignore the local variable declarations
167 //              intArrayPtr--;
168 //              return;
169 //      }
170 //      TypeDeclaration typeDecl = (TypeDeclaration) astStack[astPtr];
171 //      TypeReference[] superInterfaces = typeDecl.superInterfaces;
172 //      char[][] interfaceNames = null;
173 //      int[] interfaceNameStarts = null;
174 //      int[] interfaceNameEnds = null;
175 //      if (superInterfaces != null) {
176 //              int superInterfacesLength = superInterfaces.length;
177 //              interfaceNames = new char[superInterfacesLength][];
178 //              interfaceNameStarts = new int[superInterfacesLength];
179 //              interfaceNameEnds = new int[superInterfacesLength];
180 //              for (int i = 0; i < superInterfacesLength; i++) {
181 //                      TypeReference superInterface = superInterfaces[i];
182 //                      interfaceNames[i] = CharOperation.concatWith(superInterface.getTypeName(), '.'); 
183 //                      interfaceNameStarts[i] = superInterface.sourceStart;
184 //                      interfaceNameEnds[i] = superInterface.sourceEnd;
185 //              }
186 //      }
187 //      // flush the comments related to the class header
188 //      scanner.commentPtr = -1;
189 //      TypeReference superclass = typeDecl.superclass;
190 //      if (superclass == null) {
191 //              requestor.enterClass(
192 //                      typeDecl.declarationSourceStart, 
193 //                      intArrayStack[intArrayPtr--], 
194 //                      typeDecl.modifiers, 
195 //                      typeDecl.modifiersSourceStart, 
196 //                      typeStartPosition, 
197 //                      typeDecl.name, 
198 //                      typeDecl.sourceStart, 
199 //                      typeDecl.sourceEnd, 
200 //                      null, 
201 //                      -1, 
202 //                      -1, 
203 //                      interfaceNames, 
204 //                      interfaceNameStarts, 
205 //                      interfaceNameEnds, 
206 //                      scanner.currentPosition - 1); 
207 //      } else {
208 //              requestor.enterClass(
209 //                      typeDecl.declarationSourceStart, 
210 //                      intArrayStack[intArrayPtr--], 
211 //                      typeDecl.modifiers, 
212 //                      typeDecl.modifiersSourceStart, 
213 //                      typeStartPosition, 
214 //                      typeDecl.name, 
215 //                      typeDecl.sourceStart, 
216 //                      typeDecl.sourceEnd, 
217 //                      CharOperation.concatWith(superclass.getTypeName(), '.'), 
218 //                      superclass.sourceStart, 
219 //                      superclass.sourceEnd, 
220 //                      interfaceNames, 
221 //                      interfaceNameStarts, 
222 //                      interfaceNameEnds, 
223 //                      scanner.currentPosition - 1); 
224 //
225 //      }
226 //}
227 //protected void consumeClassHeaderName() {
228 //      // ClassHeaderName ::= Modifiersopt 'class' 'Identifier'
229 //      TypeDeclaration typeDecl;
230 //      if (nestedMethod[nestedType] == 0) {
231 //              if (nestedType != 0) {
232 //                      typeDecl = new MemberTypeDeclaration(this.compilationUnit.compilationResult);
233 //              } else {
234 //                      typeDecl = new TypeDeclaration(this.compilationUnit.compilationResult);
235 //              }
236 //      } else {
237 //              // Record that the block has a declaration for local types
238 //              typeDecl = new LocalTypeDeclaration(this.compilationUnit.compilationResult);
239 //              markEnclosingMemberWithLocalType();
240 //              blockReal();
241 //      }
242 //
243 //      //highlight the name of the type
244 //      long pos = identifierPositionStack[identifierPtr];
245 //      typeDecl.sourceEnd = (int) pos;
246 //      typeDecl.sourceStart = (int) (pos >>> 32);
247 //      typeDecl.name = identifierStack[identifierPtr--];
248 //      identifierLengthPtr--;
249 //
250 //      //compute the declaration source too
251 //      // 'class' and 'interface' push an int position
252 //      typeStartPosition = typeDecl.declarationSourceStart = intStack[intPtr--];
253 //      intPtr--;
254 //      int declarationSourceStart = intStack[intPtr--];
255 //      typeDecl.modifiersSourceStart = intStack[intPtr--];
256 //      typeDecl.modifiers = intStack[intPtr--];
257 //      if (typeDecl.declarationSourceStart > declarationSourceStart) {
258 //              typeDecl.declarationSourceStart = declarationSourceStart;
259 //      }
260 //      typeDecl.bodyStart = typeDecl.sourceEnd + 1;
261 //      pushOnAstStack(typeDecl);
262 //}
263 ///**
264 // *
265 // * INTERNAL USE-ONLY
266 // */
267 //protected void consumeCompilationUnit() {
268 //      // CompilationUnit ::= EnterCompilationUnit PackageDeclarationopt ImportDeclarationsopt
269 //      requestor.exitCompilationUnit(scanner.source.length - 1);
270 //}
271 /**
272  *
273  * INTERNAL USE-ONLY
274  */
275 //protected void consumeConstructorDeclaration() {
276 //      // ConstructorDeclaration ::= ConstructorHeader ConstructorBody
277 //      super.consumeConstructorDeclaration();
278 //      if (isLocalDeclaration()) {
279 //              // we ignore the local variable declarations
280 //              return;
281 //      }
282 //      ConstructorDeclaration cd = (ConstructorDeclaration) astStack[astPtr];
283 //      requestor.exitConstructor(endStatementPosition, cd.declarationSourceEnd);
284 //}
285 ///**
286 // *
287 // * INTERNAL USE-ONLY
288 // */
289 //protected void consumeConstructorHeader() {
290 //      // ConstructorHeader ::= ConstructorHeaderName MethodHeaderParameters MethodHeaderThrowsClauseopt
291 //      super.consumeConstructorHeader();
292 //      if (isLocalDeclaration()) {
293 //              // we ignore the local variable declarations
294 //              intArrayPtr--;
295 //              return;
296 //      }
297 //      ConstructorDeclaration cd = (ConstructorDeclaration) astStack[astPtr];
298 //      Argument[] arguments = cd.arguments;
299 //      char[][] argumentTypes = null;
300 //      char[][] argumentNames = null;
301 //      int[] argumentTypeStarts = null;
302 //      int[] argumentTypeEnds = null;
303 //      int[] argumentNameStarts = null;
304 //      int[] argumentNameEnds = null;
305 //      if (arguments != null) {
306 //              int argumentLength = arguments.length;
307 //              argumentTypes = new char[argumentLength][];
308 //              argumentNames = new char[argumentLength][];
309 //              argumentNameStarts = new int[argumentLength];
310 //              argumentNameEnds = new int[argumentLength];
311 //              argumentTypeStarts = new int[argumentLength];
312 //              argumentTypeEnds = new int[argumentLength];
313 //              for (int i = 0; i < argumentLength; i++) {
314 //                      Argument argument = arguments[i];
315 //                      TypeReference argumentType = argument.type;
316 //                      argumentTypes[i] = returnTypeName(argumentType);
317 //                      argumentNames[i] = argument.name;
318 //                      argumentNameStarts[i] = argument.sourceStart;
319 //                      argumentNameEnds[i] = argument.sourceEnd;
320 //                      argumentTypeStarts[i] = argumentType.sourceStart;
321 //                      argumentTypeEnds[i] = argumentType.sourceEnd;
322 //              }
323 //      }
324 //      TypeReference[] thrownExceptions = cd.thrownExceptions;
325 //      char[][] exceptionTypes = null;
326 //      int[] exceptionTypeStarts = null;
327 //      int[] exceptionTypeEnds = null;
328 //      if (thrownExceptions != null) {
329 //              int thrownExceptionLength = thrownExceptions.length;
330 //              exceptionTypes = new char[thrownExceptionLength][];
331 //              exceptionTypeStarts = new int[thrownExceptionLength];
332 //              exceptionTypeEnds = new int[thrownExceptionLength];
333 //              for (int i = 0; i < thrownExceptionLength; i++) {
334 //                      TypeReference exception = thrownExceptions[i];
335 //                      exceptionTypes[i] = CharOperation.concatWith(exception.getTypeName(), '.');
336 //                      exceptionTypeStarts[i] = exception.sourceStart;
337 //                      exceptionTypeEnds[i] = exception.sourceEnd;
338 //              }
339 //      }
340 //      requestor
341 //              .enterConstructor(
342 //                      cd.declarationSourceStart, 
343 //                      intArrayStack[intArrayPtr--], 
344 //                      cd.modifiers,
345 //                      cd.modifiersSourceStart, 
346 //                      cd.selector, 
347 //                      cd.sourceStart, 
348 //                      (int) (selectorSourcePositions & 0xFFFFFFFFL), 
349 //                      // retrieve the source end of the name
350 //                      argumentTypes, 
351 //                      argumentTypeStarts, 
352 //                      argumentTypeEnds, 
353 //                      argumentNames, 
354 //                      argumentNameStarts, 
355 //                      argumentNameEnds, 
356 //                      rParenPos, 
357 //                      // right parenthesis
358 //                      exceptionTypes, 
359 //                      exceptionTypeStarts, 
360 //                      exceptionTypeEnds, 
361 //                      scanner.currentPosition - 1); 
362 //}
363 //protected void consumeConstructorHeaderName() {
364 //      // ConstructorHeaderName ::=  Modifiersopt 'Identifier' '('
365 //      ConstructorDeclaration cd = new ConstructorDeclaration(this.compilationUnit.compilationResult);
366 //
367 //      //name -- this is not really revelant but we do .....
368 //      cd.selector = identifierStack[identifierPtr];
369 //      selectorSourcePositions = identifierPositionStack[identifierPtr--];
370 //      identifierLengthPtr--;
371 //
372 //      //modifiers
373 //      cd.declarationSourceStart = intStack[intPtr--];
374 //      cd.modifiersSourceStart = intStack[intPtr--];
375 //      cd.modifiers = intStack[intPtr--];
376 //
377 //      //highlight starts at the selector starts
378 //      cd.sourceStart = (int) (selectorSourcePositions >>> 32);
379 //      pushOnAstStack(cd);
380 //
381 //      cd.sourceEnd = lParenPos;
382 //      cd.bodyStart = lParenPos + 1;
383 //}
384 //protected void consumeDefaultModifiers() {
385 //      checkAnnotation(); // might update modifiers with AccDeprecated
386 //      pushOnIntStack(modifiers); // modifiers
387 //      pushOnIntStack(-1);
388 //      pushOnIntStack(
389 //              declarationSourceStart >= 0 ? declarationSourceStart : scanner.startPosition); 
390 //      resetModifiers();
391 //}
392 //protected void consumeDiet() {
393 //      // Diet ::= $empty
394 //      super.consumeDiet();
395 //      /* persisting javadoc positions
396 //       * Will be consume in consumeClassBodyDeclaration
397 //       */
398 //      pushOnIntArrayStack(this.getJavaDocPositions());        
399 //}
400 ///**
401 // *
402 // * INTERNAL USE-ONLY
403 // */
404 //protected void consumeEnterCompilationUnit() {
405 //      // EnterCompilationUnit ::= $empty
406 //      requestor.enterCompilationUnit();
407 //}
408 ///**
409 // *
410 // * INTERNAL USE-ONLY
411 // */
412 //protected void consumeEnterVariable() {
413 //      // EnterVariable ::= $empty
414 //      boolean isLocalDeclaration = isLocalDeclaration();
415 //      if (!isLocalDeclaration && (variablesCounter[nestedType] != 0)) {
416 //              requestor.exitField(lastFieldBodyEndPosition, lastFieldEndPosition);
417 //      }
418 //      char[] name = identifierStack[identifierPtr];
419 //      long namePosition = identifierPositionStack[identifierPtr--];
420 //      int extendedTypeDimension = intStack[intPtr--];
421 //
422 //      AbstractVariableDeclaration declaration;
423 //      if (nestedMethod[nestedType] != 0) {
424 //              // create the local variable declarations
425 //              declaration = 
426 //                      new LocalDeclaration(null, name, (int) (namePosition >>> 32), (int) namePosition); 
427 //      } else {
428 //              // create the field declaration
429 //              declaration = 
430 //                      new FieldDeclaration(null, name, (int) (namePosition >>> 32), (int) namePosition); 
431 //      }
432 //      identifierLengthPtr--;
433 //      TypeReference type;
434 //      int variableIndex = variablesCounter[nestedType];
435 //      int typeDim = 0;
436 //      if (variableIndex == 0) {
437 //              // first variable of the declaration (FieldDeclaration or LocalDeclaration)
438 //              if (nestedMethod[nestedType] != 0) {
439 //                      // local declaration
440 //                      declaration.declarationSourceStart = intStack[intPtr--];
441 //                      declaration.modifiersSourceStart = intStack[intPtr--];
442 //                      declaration.modifiers = intStack[intPtr--];
443 //                      type = getTypeReference(typeDim = intStack[intPtr--]); // type dimension
444 //                      pushOnAstStack(type);
445 //              } else {
446 //                      // field declaration
447 //                      type = getTypeReference(typeDim = intStack[intPtr--]); // type dimension
448 //                      pushOnAstStack(type);
449 //                      declaration.declarationSourceStart = intStack[intPtr--];
450 //                      declaration.modifiersSourceStart = intStack[intPtr--];
451 //                      declaration.modifiers = intStack[intPtr--];
452 //              }
453 //      } else {
454 //              type = (TypeReference) astStack[astPtr - variableIndex];
455 //              typeDim = type.dimensions();
456 //              AbstractVariableDeclaration previousVariable = 
457 //                      (AbstractVariableDeclaration) astStack[astPtr]; 
458 //              declaration.declarationSourceStart = previousVariable.declarationSourceStart;
459 //              declaration.modifiers = previousVariable.modifiers;
460 //              declaration.modifiersSourceStart = previousVariable.modifiersSourceStart;
461 //      }
462 //
463 //      localIntPtr = intPtr;
464 //
465 //      if (extendedTypeDimension == 0) {
466 //              declaration.type = type;
467 //      } else {
468 //              int dimension = typeDim + extendedTypeDimension;
469 //              //on the identifierLengthStack there is the information about the type....
470 //              int baseType;
471 //              if ((baseType = identifierLengthStack[identifierLengthPtr + 1]) < 0) {
472 //                      //it was a baseType
473 //                      declaration.type = TypeReference.baseTypeReference(-baseType, dimension);
474 //                      declaration.type.sourceStart = type.sourceStart;
475 //                      declaration.type.sourceEnd = type.sourceEnd;
476 //              } else {
477 //                      declaration.type = this.copyDims(type, dimension);
478 //              }
479 //      }
480 //      variablesCounter[nestedType]++;
481 //      nestedMethod[nestedType]++;
482 //      pushOnAstStack(declaration);
483 //
484 //      int[] javadocPositions = intArrayStack[intArrayPtr];
485 //      if (!isLocalDeclaration) {
486 //              requestor
487 //                      .enterField(
488 //                              declaration.declarationSourceStart, 
489 //                              javadocPositions, 
490 //                              declaration.modifiers, 
491 //                              declaration.modifiersSourceStart, 
492 //                              returnTypeName(declaration.type), 
493 //                              type.sourceStart, 
494 //                              type.sourceEnd, 
495 //                              typeDims, 
496 //                              name, 
497 //                              (int) (namePosition >>> 32), 
498 //                              (int) namePosition, 
499 //                              extendedTypeDimension, 
500 //                              extendedTypeDimension == 0 ? -1 : endPosition); 
501 //      }
502 //}
503 ///**
504 // *
505 // * INTERNAL USE-ONLY
506 // */
507 //protected void consumeExitVariableWithInitialization() {
508 //      // ExitVariableWithInitialization ::= $empty
509 //      // the scanner is located after the comma or the semi-colon.
510 //      // we want to include the comma or the semi-colon
511 //      super.consumeExitVariableWithInitialization();
512 //      nestedMethod[nestedType]--;     
513 //      lastFieldEndPosition = scanner.currentPosition - 1;
514 //      lastFieldBodyEndPosition =      ((AbstractVariableDeclaration) astStack[astPtr]).initialization.sourceEnd;
515 //}
516 //protected void consumeExitVariableWithoutInitialization() {
517 //      // ExitVariableWithoutInitialization ::= $empty
518 //      // do nothing by default
519 //      super.consumeExitVariableWithoutInitialization();
520 //      nestedMethod[nestedType]--;     
521 //      lastFieldEndPosition = scanner.currentPosition - 1;
522 //      lastFieldBodyEndPosition = scanner.startPosition - 1;
523 //}
524 ///**
525 // *
526 // * INTERNAL USE-ONLY
527 // */
528 //protected void consumeFieldDeclaration() {
529 //      // See consumeLocalVariableDeclarationDefaultModifier() in case of change: duplicated code
530 //      // FieldDeclaration ::= Modifiersopt Type VariableDeclarators ';'
531 //      // the super.consumeFieldDeclaration will reinitialize the variableCounter[nestedType]  
532 //      int variableIndex = variablesCounter[nestedType];
533 //      super.consumeFieldDeclaration();
534 //      intArrayPtr--;
535 //      if (isLocalDeclaration())
536 //              return;
537 //      if (variableIndex != 0) {
538 //              requestor.exitField(lastFieldBodyEndPosition, lastFieldEndPosition);
539 //      }
540 //}
541 //protected void consumeFormalParameter() {
542 //      // FormalParameter ::= Type VariableDeclaratorId ==> false
543 //      // FormalParameter ::= Modifiers Type VariableDeclaratorId ==> true
544 //      /*
545 //      astStack : 
546 //      identifierStack : type identifier
547 //      intStack : dim dim
548 //       ==>
549 //      astStack : Argument
550 //      identifierStack :  
551 //      intStack :  
552 //      */
553 //
554 //      identifierLengthPtr--;
555 //      char[] name = identifierStack[identifierPtr];
556 //      long namePositions = identifierPositionStack[identifierPtr--];
557 //      TypeReference type = getTypeReference(intStack[intPtr--] + intStack[intPtr--]);
558 //      intPtr -= 3;
559 //      Argument arg = 
560 //              new Argument(
561 //                      name, 
562 //                      namePositions, 
563 //                      type, 
564 //                      intStack[intPtr + 1]); // modifiers
565 //      pushOnAstStack(arg);
566 //      intArrayPtr--;
567 //}
568 ///**
569 // *
570 // * INTERNAL USE-ONLY
571 // */
572 //protected void consumeInterfaceDeclaration() {
573 //      super.consumeInterfaceDeclaration();
574 //      // we know that we have a TypeDeclaration on the top of the astStack
575 //      if (isLocalDeclaration()) {
576 //              // we ignore the local variable declarations
577 //              return;
578 //      }
579 //      requestor.exitInterface(endStatementPosition, // the '}' is the end of the body
580 //       ((TypeDeclaration) astStack[astPtr]).declarationSourceEnd);
581 //}
582 ///**
583 // *
584 // * INTERNAL USE-ONLY
585 // */
586 //protected void consumeInterfaceHeader() {
587 //      //InterfaceHeader ::= $empty
588 //      super.consumeInterfaceHeader();
589 //      if (isLocalDeclaration()) {
590 //              // we ignore the local variable declarations
591 //              intArrayPtr--;
592 //              return;
593 //      }
594 //      TypeDeclaration typeDecl = (TypeDeclaration) astStack[astPtr];
595 //      TypeReference[] superInterfaces = typeDecl.superInterfaces;
596 //      char[][] interfaceNames = null;
597 //      int[] interfaceNameStarts = null;
598 //      int[] interfacenameEnds = null;
599 //      int superInterfacesLength = 0;
600 //      if (superInterfaces != null) {
601 //              superInterfacesLength = superInterfaces.length;
602 //              interfaceNames = new char[superInterfacesLength][];
603 //              interfaceNameStarts = new int[superInterfacesLength];
604 //              interfacenameEnds = new int[superInterfacesLength];
605 //      }
606 //      if (superInterfaces != null) {
607 //              for (int i = 0; i < superInterfacesLength; i++) {
608 //                      TypeReference superInterface = superInterfaces[i];
609 //                      interfaceNames[i] = CharOperation.concatWith(superInterface.getTypeName(), '.'); 
610 //                      interfaceNameStarts[i] = superInterface.sourceStart;
611 //                      interfacenameEnds[i] = superInterface.sourceEnd;
612 //              }
613 //      }
614 //      // flush the comments related to the interface header
615 //      scanner.commentPtr = -1;
616 //      requestor.enterInterface(
617 //              typeDecl.declarationSourceStart, 
618 //              intArrayStack[intArrayPtr--], 
619 //              typeDecl.modifiers, 
620 //              typeDecl.modifiersSourceStart, 
621 //              typeStartPosition, 
622 //              typeDecl.name, 
623 //              typeDecl.sourceStart, 
624 //              typeDecl.sourceEnd, 
625 //              interfaceNames, 
626 //              interfaceNameStarts, 
627 //              interfacenameEnds, 
628 //              scanner.currentPosition - 1); 
629 //}
630 //protected void consumeInterfaceHeaderName() {
631 //      // InterfaceHeaderName ::= Modifiersopt 'interface' 'Identifier'
632 //      TypeDeclaration typeDecl;
633 //      if (nestedMethod[nestedType] == 0) {
634 //              if (nestedType != 0) {
635 //                      typeDecl = new MemberTypeDeclaration(this.compilationUnit.compilationResult);
636 //              } else {
637 //                      typeDecl = new TypeDeclaration(this.compilationUnit.compilationResult);
638 //              }
639 //      } else {
640 //              // Record that the block has a declaration for local types
641 //              typeDecl = new LocalTypeDeclaration(this.compilationUnit.compilationResult);
642 //              markEnclosingMemberWithLocalType();
643 //              blockReal();
644 //      }
645 //
646 //      //highlight the name of the type
647 //      long pos = identifierPositionStack[identifierPtr];
648 //      typeDecl.sourceEnd = (int) pos;
649 //      typeDecl.sourceStart = (int) (pos >>> 32);
650 //      typeDecl.name = identifierStack[identifierPtr--];
651 //      identifierLengthPtr--;
652 //
653 //      //compute the declaration source too
654 //      // 'class' and 'interface' push an int position
655 //      typeStartPosition = typeDecl.declarationSourceStart = intStack[intPtr--];
656 //      intPtr--;
657 //      int declarationSourceStart = intStack[intPtr--];
658 //      typeDecl.modifiersSourceStart = intStack[intPtr--];
659 //      typeDecl.modifiers = intStack[intPtr--];
660 //      if (typeDecl.declarationSourceStart > declarationSourceStart) {
661 //              typeDecl.declarationSourceStart = declarationSourceStart;
662 //      }
663 //      typeDecl.bodyStart = typeDecl.sourceEnd + 1;
664 //      pushOnAstStack(typeDecl);
665 //}
666 ///**
667 // *
668 // * INTERNAL USE-ONLY
669 // */
670 //protected void consumeLocalVariableDeclaration() {
671 //      // See consumeLocalVariableDeclarationDefaultModifier() in case of change: duplicated code
672 //      // FieldDeclaration ::= Modifiersopt Type VariableDeclarators ';'
673 //
674 //      super.consumeLocalVariableDeclaration();
675 //      intArrayPtr--;
676 //}
677 ///**
678 // *
679 // * INTERNAL USE-ONLY
680 // */
681 //protected void consumeMethodDeclaration(boolean isNotAbstract) {
682 //      // MethodDeclaration ::= MethodHeader MethodBody
683 //      // AbstractMethodDeclaration ::= MethodHeader ';'
684 //      super.consumeMethodDeclaration(isNotAbstract);
685 //      if (isLocalDeclaration()) {
686 //              // we ignore the local variable declarations
687 //              return;
688 //      }
689 //      MethodDeclaration md = (MethodDeclaration) astStack[astPtr];
690 //      requestor.exitMethod(endStatementPosition, md.declarationSourceEnd);
691 //}
692 ///**
693 // *
694 // * INTERNAL USE-ONLY
695 // */
696 //protected void consumeMethodHeader() {
697 //      // MethodHeader ::= MethodHeaderName MethodHeaderParameters MethodHeaderExtendedDims ThrowsClauseopt
698 //      super.consumeMethodHeader();
699 //      if (isLocalDeclaration()) {
700 //              // we ignore the local variable declarations
701 //              intArrayPtr--;
702 //              return;
703 //      }
704 //      MethodDeclaration md = (MethodDeclaration) astStack[astPtr];
705 //
706 //      TypeReference returnType = md.returnType;
707 //      char[] returnTypeName = returnTypeName(returnType);
708 //      Argument[] arguments = md.arguments;
709 //      char[][] argumentTypes = null;
710 //      char[][] argumentNames = null;
711 //      int[] argumentTypeStarts = null;
712 //      int[] argumentTypeEnds = null;
713 //      int[] argumentNameStarts = null;
714 //      int[] argumentNameEnds = null;
715 //      if (arguments != null) {
716 //              int argumentLength = arguments.length;
717 //              argumentTypes = new char[argumentLength][];
718 //              argumentNames = new char[argumentLength][];
719 //              argumentNameStarts = new int[argumentLength];
720 //              argumentNameEnds = new int[argumentLength];
721 //              argumentTypeStarts = new int[argumentLength];
722 //              argumentTypeEnds = new int[argumentLength];
723 //              for (int i = 0; i < argumentLength; i++) {
724 //                      Argument argument = arguments[i];
725 //                      TypeReference argumentType = argument.type;
726 //                      argumentTypes[i] = returnTypeName(argumentType);
727 //                      argumentNames[i] = argument.name;
728 //                      argumentNameStarts[i] = argument.sourceStart;
729 //                      argumentNameEnds[i] = argument.sourceEnd;
730 //                      argumentTypeStarts[i] = argumentType.sourceStart;
731 //                      argumentTypeEnds[i] = argumentType.sourceEnd;
732 //              }
733 //      }
734 //      TypeReference[] thrownExceptions = md.thrownExceptions;
735 //      char[][] exceptionTypes = null;
736 //      int[] exceptionTypeStarts = null;
737 //      int[] exceptionTypeEnds = null;
738 //      if (thrownExceptions != null) {
739 //              int thrownExceptionLength = thrownExceptions.length;
740 //              exceptionTypeStarts = new int[thrownExceptionLength];
741 //              exceptionTypeEnds = new int[thrownExceptionLength];
742 //              exceptionTypes = new char[thrownExceptionLength][];
743 //              for (int i = 0; i < thrownExceptionLength; i++) {
744 //                      TypeReference exception = thrownExceptions[i];
745 //                      exceptionTypes[i] = CharOperation.concatWith(exception.getTypeName(), '.');
746 //                      exceptionTypeStarts[i] = exception.sourceStart;
747 //                      exceptionTypeEnds[i] = exception.sourceEnd;
748 //              }
749 //      }
750 //      requestor
751 //              .enterMethod(
752 //                      md.declarationSourceStart, 
753 //                      intArrayStack[intArrayPtr--], 
754 //                      md.modifiers, 
755 //                      md.modifiersSourceStart, 
756 //                      returnTypeName, 
757 //                      returnType.sourceStart, 
758 //                      returnType.sourceEnd, 
759 //                      typeDims, 
760 //                      md.selector, 
761 //                      md.sourceStart, 
762 //                      (int) (selectorSourcePositions & 0xFFFFFFFFL), 
763 //                      argumentTypes, 
764 //                      argumentTypeStarts, 
765 //                      argumentTypeEnds, 
766 //                      argumentNames, 
767 //                      argumentNameStarts, 
768 //                      argumentNameEnds, 
769 //                      rParenPos, 
770 //                      extendsDim, 
771 //                      extendsDim == 0 ? -1 : endPosition, 
772 //                      exceptionTypes, 
773 //                      exceptionTypeStarts, 
774 //                      exceptionTypeEnds, 
775 //                      scanner.currentPosition - 1); 
776 //}
777 //protected void consumeMethodHeaderExtendedDims() {
778 //      // MethodHeaderExtendedDims ::= Dimsopt
779 //      // now we update the returnType of the method
780 //      MethodDeclaration md = (MethodDeclaration) astStack[astPtr];
781 //      int extendedDims = intStack[intPtr--];
782 //      extendsDim = extendedDims;
783 //      if (extendedDims != 0) {
784 //              TypeReference returnType = md.returnType;
785 //              md.sourceEnd = endPosition;
786 //              int dims = returnType.dimensions() + extendedDims;
787 //              int baseType;
788 //              if ((baseType = identifierLengthStack[identifierLengthPtr + 1]) < 0) {
789 //                      //it was a baseType
790 //                      int sourceStart = returnType.sourceStart;
791 //                      int sourceEnd = returnType.sourceEnd;
792 //                      returnType = TypeReference.baseTypeReference(-baseType, dims);
793 //                      returnType.sourceStart = sourceStart;
794 //                      returnType.sourceEnd = sourceEnd;
795 //                      md.returnType = returnType;
796 //              } else {
797 //                      md.returnType = this.copyDims(md.returnType, dims);
798 //              }
799 //              if (currentToken == TokenNameLBRACE) {
800 //                      md.bodyStart = endPosition + 1;
801 //              }
802 //      }
803 //}
804 //protected void consumeMethodHeaderName() {
805 //      // MethodHeaderName ::= Modifiersopt Type 'Identifier' '('
806 //      MethodDeclaration md = new MethodDeclaration(this.compilationUnit.compilationResult);
807 //
808 //      //name
809 //      md.selector = identifierStack[identifierPtr];
810 //      selectorSourcePositions = identifierPositionStack[identifierPtr--];
811 //      identifierLengthPtr--;
812 //      //type
813 //      md.returnType = getTypeReference(typeDims = intStack[intPtr--]);
814 //      //modifiers
815 //      md.declarationSourceStart = intStack[intPtr--];
816 //      md.modifiersSourceStart = intStack[intPtr--];
817 //      md.modifiers = intStack[intPtr--];
818 //
819 //      //highlight starts at selector start
820 //      md.sourceStart = (int) (selectorSourcePositions >>> 32);
821 //      pushOnAstStack(md);
822 //      md.bodyStart = scanner.currentPosition-1;
823 //}
824 //protected void consumeModifiers() {
825 //      checkAnnotation(); // might update modifiers with AccDeprecated
826 //      pushOnIntStack(modifiers); // modifiers
827 //      pushOnIntStack(modifiersSourceStart);
828 //      pushOnIntStack(
829 //              declarationSourceStart >= 0 ? declarationSourceStart : modifiersSourceStart); 
830 //      resetModifiers();
831 //}
832 /**
833  *
834  * INTERNAL USE-ONLY
835  */
836 //protected void consumePackageDeclarationName() {
837 //      /* persisting javadoc positions */
838 //      pushOnIntArrayStack(this.getJavaDocPositions());
839 //
840 //      super.consumePackageDeclarationName();
841 //      ImportReference importReference = compilationUnit.currentPackage;
842 //
843 //      requestor.acceptPackage(
844 //              importReference.declarationSourceStart, 
845 //              importReference.declarationSourceEnd, 
846 //              intArrayStack[intArrayPtr--], 
847 //              CharOperation.concatWith(importReference.getImportName(), '.'),
848 //              importReference.sourceStart);
849 //}
850 //protected void consumePushModifiers() {
851 //      checkAnnotation(); // might update modifiers with AccDeprecated
852 //      pushOnIntStack(modifiers); // modifiers
853 //      if (modifiersSourceStart < 0) {
854 //              pushOnIntStack(-1);
855 //              pushOnIntStack(
856 //                      declarationSourceStart >= 0 ? declarationSourceStart : scanner.startPosition); 
857 //      } else {
858 //              pushOnIntStack(modifiersSourceStart);
859 //              pushOnIntStack(
860 //                      declarationSourceStart >= 0 ? declarationSourceStart : modifiersSourceStart); 
861 //      }
862 //      resetModifiers();
863 //}
864 ///**
865 // *
866 // * INTERNAL USE-ONLY
867 // */
868 //protected void consumeSingleTypeImportDeclarationName() {
869 //      // SingleTypeImportDeclarationName ::= 'import' Name
870 //
871 //      /* persisting javadoc positions */
872 //      pushOnIntArrayStack(this.getJavaDocPositions());
873 //
874 //      super.consumeSingleTypeImportDeclarationName();
875 //      ImportReference importReference = (ImportReference) astStack[astPtr];
876 //      requestor.acceptImport(
877 //              importReference.declarationSourceStart, 
878 //              importReference.declarationSourceEnd,
879 //              intArrayStack[intArrayPtr--],
880 //              CharOperation.concatWith(importReference.getImportName(), '.'),
881 //              importReference.sourceStart,
882 //              false);
883 //}
884 ///**
885 // *
886 // * INTERNAL USE-ONLY
887 // */
888 //protected void consumeStaticInitializer() {
889 //      // StaticInitializer ::=  StaticOnly Block
890 //      //push an Initializer
891 //      //optimize the push/pop
892 //      super.consumeStaticInitializer();
893 //      Initializer initializer = (Initializer) astStack[astPtr];
894 //      requestor.acceptInitializer(
895 //              initializer.declarationSourceStart,
896 //              initializer.declarationSourceEnd,
897 //              intArrayStack[intArrayPtr--],
898 //              AccStatic, 
899 //              intStack[intPtr--], 
900 //              initializer.block.sourceStart,
901 //              initializer.declarationSourceEnd);
902 //}
903 //protected void consumeStaticOnly() {
904 //      // StaticOnly ::= 'static'
905 //      checkAnnotation(); // might update declaration source start
906 //      pushOnIntStack(modifiersSourceStart);
907 //      pushOnIntStack(
908 //              declarationSourceStart >= 0 ? declarationSourceStart : modifiersSourceStart); 
909 //      jumpOverMethodBody();
910 //      nestedMethod[nestedType]++;
911 //      resetModifiers();
912 //}
913 ///**
914 // *
915 // * INTERNAL USE-ONLY
916 // */
917 //protected void consumeTypeImportOnDemandDeclarationName() {
918 //      // TypeImportOnDemandDeclarationName ::= 'import' Name '.' '*'
919 //
920 //      /* persisting javadoc positions */
921 //      pushOnIntArrayStack(this.getJavaDocPositions());
922 //
923 //      super.consumeTypeImportOnDemandDeclarationName();
924 //      ImportReference importReference = (ImportReference) astStack[astPtr];
925 //      requestor.acceptImport(
926 //              importReference.declarationSourceStart, 
927 //              importReference.declarationSourceEnd,
928 //              intArrayStack[intArrayPtr--],
929 //              CharOperation.concatWith(importReference.getImportName(), '.'), 
930 //              importReference.sourceStart,
931 //              true);
932 //}
933 public CompilationUnitDeclaration endParse(int act) {
934         if (scanner.recordLineSeparator) {
935                 requestor.acceptLineSeparatorPositions(scanner.getLineEnds());
936         }
937         return super.endParse(act);
938 }
939 /*
940  * Flush annotations defined prior to a given positions.
941  *
942  * Note: annotations are stacked in syntactical order
943  *
944  * Either answer given <position>, or the end position of a comment line 
945  * immediately following the <position> (same line)
946  *
947  * e.g.
948  * void foo(){
949  * } // end of method foo
950  */
951  
952 //public int flushAnnotationsDefinedPriorTo(int position) {
953 //
954 //      return lastFieldEndPosition = super.flushAnnotationsDefinedPriorTo(position);
955 //}
956 //protected TypeReference getTypeReference(int dim) { /* build a Reference on a variable that may be qualified or not
957 //This variable is a type reference and dim will be its dimensions*/
958 //
959 //      int length;
960 //      TypeReference ref;
961 //      if ((length = identifierLengthStack[identifierLengthPtr--]) == 1) {
962 //              // single variable reference
963 //              if (dim == 0) {
964 //                      ref = 
965 //                              new SingleTypeReference(
966 //                                      identifierStack[identifierPtr], 
967 //                                      identifierPositionStack[identifierPtr--]); 
968 //              } else {
969 //                      ref = 
970 //                              new ArrayTypeReference(
971 //                                      identifierStack[identifierPtr], 
972 //                                      dim, 
973 //                                      identifierPositionStack[identifierPtr--]); 
974 //                      ref.sourceEnd = endPosition;
975 //              }
976 //      } else {
977 //              if (length < 0) { //flag for precompiled type reference on base types
978 //                      ref = TypeReference.baseTypeReference(-length, dim);
979 //                      ref.sourceStart = intStack[intPtr--];
980 //                      if (dim == 0) {
981 //                              ref.sourceEnd = intStack[intPtr--];
982 //                      } else {
983 //                              intPtr--;
984 //                              ref.sourceEnd = endPosition;
985 //                      }
986 //              } else { //Qualified variable reference
987 //                      char[][] tokens = new char[length][];
988 //                      identifierPtr -= length;
989 //                      long[] positions = new long[length];
990 //                      System.arraycopy(identifierStack, identifierPtr + 1, tokens, 0, length);
991 //                      System.arraycopy(
992 //                              identifierPositionStack, 
993 //                              identifierPtr + 1, 
994 //                              positions, 
995 //                              0, 
996 //                              length); 
997 //                      if (dim == 0) {
998 //                              ref = new QualifiedTypeReference(tokens, positions);
999 //                      } else {
1000 //                              ref = new ArrayQualifiedTypeReference(tokens, dim, positions);
1001 //                              ref.sourceEnd = endPosition;
1002 //                      }
1003 //              }
1004 //      };
1005 //      return ref;
1006 //}
1007 public void initialize() {
1008         //positionning the parser for a new compilation unit
1009         //avoiding stack reallocation and all that....
1010         super.initialize(false);
1011         intArrayPtr = -1;
1012 }
1013 /**
1014  *
1015  * INTERNAL USE-ONLY
1016  */
1017 //private boolean isLocalDeclaration() {
1018 //      int nestedDepth = nestedType;
1019 //      while (nestedDepth >= 0) {
1020 //              if (nestedMethod[nestedDepth] != 0) {
1021 //                      return true;
1022 //              }
1023 //              nestedDepth--;
1024 //      }
1025 //      return false;
1026 //}
1027 /*
1028  * Investigate one entire unit.
1029  */
1030 public void parseCompilationUnit(ICompilationUnit unit) {
1031         char[] regionSource = unit.getContents();
1032         try {
1033                 initialize();
1034                 goForCompilationUnit();
1035                 referenceContext =
1036                         compilationUnit = 
1037                                 compilationUnit = 
1038                                         new CompilationUnitDeclaration(
1039                                                 problemReporter(), 
1040                                                 new CompilationResult(unit, 0, 0, 10), //this.options.maxProblemsPerUnit), 
1041                                                 regionSource.length); 
1042                 scanner.resetTo(0, regionSource.length);
1043                 scanner.setSource(regionSource);
1044                 parse();
1045         } catch (AbortCompilation ex) {
1046         }
1047 }
1048 /*
1049  * Investigate one constructor declaration.
1050  */
1051 //public void parseConstructor(char[] regionSource) {
1052 //      try {
1053 //              initialize();
1054 //              goForClassBodyDeclarations();
1055 //              referenceContext = 
1056 //                      compilationUnit = 
1057 //                              compilationUnit = 
1058 //                                      new CompilationUnitDeclaration(
1059 //                                              problemReporter(), 
1060 //                                              new CompilationResult(regionSource, 0, 0, 10), //this.options.maxProblemsPerUnit), 
1061 //                                              regionSource.length); 
1062 //              scanner.resetTo(0, regionSource.length);
1063 //              scanner.setSource(regionSource);
1064 //              parse();
1065 //      } catch (AbortCompilation ex) {
1066 //      }
1067 //}
1068 /*
1069  * Investigate one field declaration statement (might have multiple declarations in it).
1070  */
1071 //public void parseField(char[] regionSource) {
1072 //      try {
1073 //              initialize();
1074 //              goForFieldDeclaration();
1075 //              referenceContext = 
1076 //                      compilationUnit = 
1077 //                              compilationUnit = 
1078 //                                      new CompilationUnitDeclaration(
1079 //                                              problemReporter(), 
1080 //                                              new CompilationResult(regionSource, 0, 0, this.options.maxProblemsPerUnit), 
1081 //                                              regionSource.length); 
1082 //              scanner.resetTo(0, regionSource.length);
1083 //              scanner.setSource(regionSource);
1084 //              parse();
1085 //      } catch (AbortCompilation ex) {
1086 //      }
1087 //
1088 //}
1089 ///*
1090 // * Investigate one import statement declaration.
1091 // */
1092 //public void parseImport(char[] regionSource) {
1093 //      try {
1094 //              initialize();
1095 //              goForImportDeclaration();
1096 //              referenceContext = 
1097 //                      compilationUnit = 
1098 //                              compilationUnit = 
1099 //                                      new CompilationUnitDeclaration(
1100 //                                              problemReporter(), 
1101 //                                              new CompilationResult(regionSource, 0, 0, this.options.maxProblemsPerUnit), 
1102 //                                              regionSource.length); 
1103 //              scanner.resetTo(0, regionSource.length);
1104 //              scanner.setSource(regionSource);
1105 //              parse();
1106 //      } catch (AbortCompilation ex) {
1107 //      }
1108 //
1109 //}
1110 ///*
1111 // * Investigate one initializer declaration.
1112 // * regionSource need to content exactly an initializer declaration.
1113 // * e.g: static { i = 4; }
1114 // * { name = "test"; }
1115 // */
1116 //public void parseInitializer(char[] regionSource) {
1117 //      try {
1118 //              initialize();
1119 //              goForInitializer();
1120 //              referenceContext = 
1121 //                      compilationUnit = 
1122 //                              compilationUnit = 
1123 //                                      new CompilationUnitDeclaration(
1124 //                                              problemReporter(), 
1125 //                                              new CompilationResult(regionSource, 0, 0, this.options.maxProblemsPerUnit), 
1126 //                                              regionSource.length); 
1127 //              scanner.resetTo(0, regionSource.length);
1128 //              scanner.setSource(regionSource);
1129 //              parse();
1130 //      } catch (AbortCompilation ex) {
1131 //      }
1132 //
1133 //}
1134 ///*
1135 // * Investigate one method declaration.
1136 // */
1137 //public void parseMethod(char[] regionSource) {
1138 //      try {
1139 //              initialize();
1140 //              goForGenericMethodDeclaration();
1141 //              referenceContext = 
1142 //                      compilationUnit = 
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 //      }
1153 //
1154 //}
1155 ///*
1156 // * Investigate one package statement declaration.
1157 // */
1158 //public void parsePackage(char[] regionSource) {
1159 //      try {
1160 //              initialize();
1161 //              goForPackageDeclaration();
1162 //              referenceContext = 
1163 //                      compilationUnit = 
1164 //                              compilationUnit = 
1165 //                                      new CompilationUnitDeclaration(
1166 //                                              problemReporter(), 
1167 //                                              new CompilationResult(regionSource, 0, 0, this.options.maxProblemsPerUnit), 
1168 //                                              regionSource.length); 
1169 //              scanner.resetTo(0, regionSource.length);
1170 //              scanner.setSource(regionSource);
1171 //              parse();
1172 //      } catch (AbortCompilation ex) {
1173 //      }
1174 //
1175 //}
1176 ///*
1177 // * Investigate one type declaration, its fields, methods and member types.
1178 // */
1179 //public void parseType(char[] regionSource) {
1180 //      try {
1181 //              initialize();
1182 //              goForTypeDeclaration();
1183 //              referenceContext = 
1184 //                      compilationUnit = 
1185 //                              compilationUnit = 
1186 //                                      new CompilationUnitDeclaration(
1187 //                                              problemReporter(), 
1188 //                                              new CompilationResult(regionSource, 0, 0, this.options.maxProblemsPerUnit), 
1189 //                                              regionSource.length); 
1190 //              scanner.resetTo(0, regionSource.length);
1191 //              scanner.setSource(regionSource);
1192 //              parse();
1193 //      } catch (AbortCompilation ex) {
1194 //      }
1195 //
1196 //}
1197 /**
1198  * Returns this parser's problem reporter initialized with its reference context.
1199  * Also it is assumed that a problem is going to be reported, so initializes
1200  * the compilation result's line positions.
1201  */
1202 public ProblemReporter problemReporter() {
1203         problemReporter.referenceContext = referenceContext;
1204         return problemReporter;
1205 }
1206 protected void pushOnIntArrayStack(int[] positions) {
1207
1208         try {
1209                 intArrayStack[++intArrayPtr] = positions;
1210         } catch (IndexOutOfBoundsException e) {
1211                 //intPtr is correct 
1212                 int oldStackLength = intArrayStack.length;
1213                 int oldStack[][] = intArrayStack;
1214                 intArrayStack = new int[oldStackLength + StackIncrement][];
1215                 System.arraycopy(oldStack, 0, intArrayStack, 0, oldStackLength);
1216                 intArrayStack[intArrayPtr] = positions;
1217         }
1218 }
1219 //protected void resetModifiers() {
1220 //      super.resetModifiers();
1221 //      declarationSourceStart = -1;
1222 //}
1223 /*
1224  * Syntax error was detected. Will attempt to perform some recovery action in order
1225  * to resume to the regular parse loop.
1226  */
1227 protected boolean resumeOnSyntaxError() {
1228         return false;
1229 }
1230 /*
1231  * Answer a char array representation of the type name formatted like:
1232  * - type name + dimensions
1233  * Example:
1234  * "A[][]".toCharArray()
1235  * "java.lang.String".toCharArray()
1236  */
1237 //private char[] returnTypeName(TypeReference type) {
1238 //      int dimension = type.dimensions();
1239 //      if (dimension != 0) {
1240 //              char[] dimensionsArray = new char[dimension * 2];
1241 //              for (int i = 0; i < dimension; i++) {
1242 //                      dimensionsArray[i*2] = '[';
1243 //                      dimensionsArray[(i*2) + 1] = ']';
1244 //              }
1245 //              return CharOperation.concat(
1246 //                      CharOperation.concatWith(type.getTypeName(), '.'), 
1247 //                      dimensionsArray); 
1248 //      }
1249 //      return CharOperation.concatWith(type.getTypeName(), '.');
1250 //}
1251 //public String toString() {
1252 //      StringBuffer buffer = new StringBuffer();
1253 //      buffer.append("intArrayPtr = " + intArrayPtr + "\n"); //$NON-NLS-1$ //$NON-NLS-2$
1254 //      buffer.append(super.toString());
1255 //      return buffer.toString();
1256 //}
1257 ///**
1258 // * INTERNAL USE ONLY
1259 // */
1260 //protected TypeReference typeReference(
1261 //      int dim,
1262 //      int localIdentifierPtr, 
1263 //      int localIdentifierLengthPtr) {
1264 //      /* build a Reference on a variable that may be qualified or not
1265 //       * This variable is a type reference and dim will be its dimensions.
1266 //       * We don't have any side effect on the stacks' pointers.
1267 //       */
1268 //
1269 //      int length;
1270 //      TypeReference ref;
1271 //      if ((length = identifierLengthStack[localIdentifierLengthPtr]) == 1) {
1272 //              // single variable reference
1273 //              if (dim == 0) {
1274 //                      ref = 
1275 //                              new SingleTypeReference(
1276 //                                      identifierStack[localIdentifierPtr], 
1277 //                                      identifierPositionStack[localIdentifierPtr--]); 
1278 //              } else {
1279 //                      ref = 
1280 //                              new ArrayTypeReference(
1281 //                                      identifierStack[localIdentifierPtr], 
1282 //                                      dim, 
1283 //                                      identifierPositionStack[localIdentifierPtr--]); 
1284 //                      ref.sourceEnd = endPosition;                            
1285 //              }
1286 //      } else {
1287 //              if (length < 0) { //flag for precompiled type reference on base types
1288 //                      ref = TypeReference.baseTypeReference(-length, dim);
1289 //                      ref.sourceStart = intStack[localIntPtr--];
1290 //                      if (dim == 0) {
1291 //                              ref.sourceEnd = intStack[localIntPtr--];
1292 //                      } else {
1293 //                              localIntPtr--;
1294 //                              ref.sourceEnd = endPosition;
1295 //                      }
1296 //              } else { //Qualified variable reference
1297 //                      char[][] tokens = new char[length][];
1298 //                      localIdentifierPtr -= length;
1299 //                      long[] positions = new long[length];
1300 //                      System.arraycopy(identifierStack, localIdentifierPtr + 1, tokens, 0, length);
1301 //                      System.arraycopy(
1302 //                              identifierPositionStack, 
1303 //                              localIdentifierPtr + 1, 
1304 //                              positions, 
1305 //                              0, 
1306 //                              length); 
1307 //                      if (dim == 0)
1308 //                              ref = new QualifiedTypeReference(tokens, positions);
1309 //                      else
1310 //                              ref = new ArrayQualifiedTypeReference(tokens, dim, positions);
1311 //              }
1312 //      };
1313 //      return ref;
1314 //}
1315 }