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