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
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package net.sourceforge.phpdt.internal.compiler;
13 import net.sourceforge.phpdt.core.compiler.CharOperation;
14 import net.sourceforge.phpdt.core.compiler.IProblem;
15 import net.sourceforge.phpdt.internal.compiler.env.ICompilationUnit;
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;
21 import org.eclipse.core.runtime.CoreException;
25 * A document element parser extracts structural information
26 * from a piece of source, providing detailed source positions info.
28 * also see @IDocumentElementRequestor
30 * The structural investigation includes:
31 * - the package statement
33 * - top-level types: package member, member types (member types of member types...)
37 * Any (parsing) problem encountered is also provided.
39 public class DocumentElementParser extends UnitParser {
40 IDocumentElementRequestor requestor;
41 private int localIntPtr;
42 private int lastFieldEndPosition;
43 private int lastFieldBodyEndPosition;
44 private int typeStartPosition;
45 private long selectorSourcePositions;
47 private int extendsDim;
48 private int declarationSourceStart;
50 /* int[] stack for storing javadoc positions */
51 int[][] intArrayStack;
54 // CompilerOptions options;
56 public DocumentElementParser(
57 final IDocumentElementRequestor requestor,
58 IProblemFactory problemFactory) {
59 // CompilerOptions options) {
60 super(new ProblemReporter(
61 DefaultErrorHandlingPolicies.exitAfterAllProblems(),
64 public void record(IProblem problem, CompilationResult unitResult) {
65 requestor.acceptProblem(problem);
69 // options.sourceLevel >= CompilerOptions.JDK1_4);
70 this.requestor = requestor;
71 intArrayStack = new int[30][];
72 // this.options = options;
79 //protected void adjustInterfaceModifiers() {
80 // intStack[intPtr - 2] |= AccInterface;
83 * Will clear the comment stack when looking
84 * for a potential JavaDoc which might contain @deprecated.
86 * Additionally, before investigating for @deprecated, retrieve the positions
87 * of the JavaDoc comments so as to notify requestor with them.
89 //public void checkAnnotation() {
91 // /* persisting javadoc positions */
92 // pushOnIntArrayStack(this.getJavaDocPositions());
93 // boolean deprecated = false;
94 // int lastAnnotationIndex = -1;
95 // int commentPtr = scanner.commentPtr;
97 // //since jdk1.2 look only in the last java doc comment...
98 // nextComment : for (lastAnnotationIndex = scanner.commentPtr; lastAnnotationIndex >= 0; lastAnnotationIndex--){
99 // //look for @deprecated into the first javadoc comment preceeding the declaration
100 // int commentSourceStart = scanner.commentStarts[lastAnnotationIndex];
101 // // javadoc only (non javadoc comment have negative end positions.)
102 // if (modifiersSourceStart != -1 && modifiersSourceStart < commentSourceStart) {
103 // continue nextComment;
105 // if (scanner.commentStops[lastAnnotationIndex] < 0) {
106 // continue nextComment;
108 // int commentSourceEnd = scanner.commentStops[lastAnnotationIndex] - 1; //stop is one over
109 // char[] comment = scanner.source;
113 // commentSourceStart,
116 // break nextComment;
119 // checkAndSetModifiers(AccDeprecated);
121 // // modify the modifier source start to point at the first comment
122 // if (commentPtr >= 0) {
123 // declarationSourceStart = scanner.commentStarts[0];
130 //protected void consumeClassBodyDeclaration() {
131 // // ClassBodyDeclaration ::= Diet Block
132 // //push an Initializer
133 // //optimize the push/pop
135 // super.consumeClassBodyDeclaration();
136 // Initializer initializer = (Initializer) astStack[astPtr];
137 // requestor.acceptInitializer(
138 // initializer.declarationSourceStart,
139 // initializer.declarationSourceEnd,
140 // intArrayStack[intArrayPtr--],
142 // modifiersSourceStart,
143 // initializer.block.sourceStart,
144 // initializer.block.sourceEnd);
148 // * INTERNAL USE-ONLY
150 //protected void consumeClassDeclaration() {
151 // super.consumeClassDeclaration();
152 // // we know that we have a TypeDeclaration on the top of the astStack
153 // if (isLocalDeclaration()) {
154 // // we ignore the local variable declarations
157 // requestor.exitClass(endStatementPosition, // '}' is the end of the body
158 // ((TypeDeclaration) astStack[astPtr]).declarationSourceEnd);
162 // * INTERNAL USE-ONLY
164 //protected void consumeClassHeader() {
165 // //ClassHeader ::= $empty
166 // super.consumeClassHeader();
167 // if (isLocalDeclaration()) {
168 // // we ignore the local variable declarations
172 // TypeDeclaration typeDecl = (TypeDeclaration) astStack[astPtr];
173 // TypeReference[] superInterfaces = typeDecl.superInterfaces;
174 // char[][] interfaceNames = null;
175 // int[] interfaceNameStarts = null;
176 // int[] interfaceNameEnds = null;
177 // if (superInterfaces != null) {
178 // int superInterfacesLength = superInterfaces.length;
179 // interfaceNames = new char[superInterfacesLength][];
180 // interfaceNameStarts = new int[superInterfacesLength];
181 // interfaceNameEnds = new int[superInterfacesLength];
182 // for (int i = 0; i < superInterfacesLength; i++) {
183 // TypeReference superInterface = superInterfaces[i];
184 // interfaceNames[i] = CharOperation.concatWith(superInterface.getTypeName(), '.');
185 // interfaceNameStarts[i] = superInterface.sourceStart;
186 // interfaceNameEnds[i] = superInterface.sourceEnd;
189 // // flush the comments related to the class header
190 // scanner.commentPtr = -1;
191 // TypeReference superclass = typeDecl.superclass;
192 // if (superclass == null) {
193 // requestor.enterClass(
194 // typeDecl.declarationSourceStart,
195 // intArrayStack[intArrayPtr--],
196 // typeDecl.modifiers,
197 // typeDecl.modifiersSourceStart,
198 // typeStartPosition,
200 // typeDecl.sourceStart,
201 // typeDecl.sourceEnd,
206 // interfaceNameStarts,
207 // interfaceNameEnds,
208 // scanner.currentPosition - 1);
210 // requestor.enterClass(
211 // typeDecl.declarationSourceStart,
212 // intArrayStack[intArrayPtr--],
213 // typeDecl.modifiers,
214 // typeDecl.modifiersSourceStart,
215 // typeStartPosition,
217 // typeDecl.sourceStart,
218 // typeDecl.sourceEnd,
219 // CharOperation.concatWith(superclass.getTypeName(), '.'),
220 // superclass.sourceStart,
221 // superclass.sourceEnd,
223 // interfaceNameStarts,
224 // interfaceNameEnds,
225 // scanner.currentPosition - 1);
229 //protected void consumeClassHeaderName() {
230 // // ClassHeaderName ::= Modifiersopt 'class' 'Identifier'
231 // TypeDeclaration typeDecl;
232 // if (nestedMethod[nestedType] == 0) {
233 // if (nestedType != 0) {
234 // typeDecl = new MemberTypeDeclaration(this.compilationUnit.compilationResult);
236 // typeDecl = new TypeDeclaration(this.compilationUnit.compilationResult);
239 // // Record that the block has a declaration for local types
240 // typeDecl = new LocalTypeDeclaration(this.compilationUnit.compilationResult);
241 // markEnclosingMemberWithLocalType();
245 // //highlight the name of the type
246 // long pos = identifierPositionStack[identifierPtr];
247 // typeDecl.sourceEnd = (int) pos;
248 // typeDecl.sourceStart = (int) (pos >>> 32);
249 // typeDecl.name = identifierStack[identifierPtr--];
250 // identifierLengthPtr--;
252 // //compute the declaration source too
253 // // 'class' and 'interface' push an int position
254 // typeStartPosition = typeDecl.declarationSourceStart = intStack[intPtr--];
256 // int declarationSourceStart = intStack[intPtr--];
257 // typeDecl.modifiersSourceStart = intStack[intPtr--];
258 // typeDecl.modifiers = intStack[intPtr--];
259 // if (typeDecl.declarationSourceStart > declarationSourceStart) {
260 // typeDecl.declarationSourceStart = declarationSourceStart;
262 // typeDecl.bodyStart = typeDecl.sourceEnd + 1;
263 // pushOnAstStack(typeDecl);
267 // * INTERNAL USE-ONLY
269 //protected void consumeCompilationUnit() {
270 // // CompilationUnit ::= EnterCompilationUnit PackageDeclarationopt ImportDeclarationsopt
271 // requestor.exitCompilationUnit(scanner.source.length - 1);
277 //protected void consumeConstructorDeclaration() {
278 // // ConstructorDeclaration ::= ConstructorHeader ConstructorBody
279 // super.consumeConstructorDeclaration();
280 // if (isLocalDeclaration()) {
281 // // we ignore the local variable declarations
284 // ConstructorDeclaration cd = (ConstructorDeclaration) astStack[astPtr];
285 // requestor.exitConstructor(endStatementPosition, cd.declarationSourceEnd);
289 // * INTERNAL USE-ONLY
291 //protected void consumeConstructorHeader() {
292 // // ConstructorHeader ::= ConstructorHeaderName MethodHeaderParameters MethodHeaderThrowsClauseopt
293 // super.consumeConstructorHeader();
294 // if (isLocalDeclaration()) {
295 // // we ignore the local variable declarations
299 // ConstructorDeclaration cd = (ConstructorDeclaration) astStack[astPtr];
300 // Argument[] arguments = cd.arguments;
301 // char[][] argumentTypes = null;
302 // char[][] argumentNames = null;
303 // int[] argumentTypeStarts = null;
304 // int[] argumentTypeEnds = null;
305 // int[] argumentNameStarts = null;
306 // int[] argumentNameEnds = null;
307 // if (arguments != null) {
308 // int argumentLength = arguments.length;
309 // argumentTypes = new char[argumentLength][];
310 // argumentNames = new char[argumentLength][];
311 // argumentNameStarts = new int[argumentLength];
312 // argumentNameEnds = new int[argumentLength];
313 // argumentTypeStarts = new int[argumentLength];
314 // argumentTypeEnds = new int[argumentLength];
315 // for (int i = 0; i < argumentLength; i++) {
316 // Argument argument = arguments[i];
317 // TypeReference argumentType = argument.type;
318 // argumentTypes[i] = returnTypeName(argumentType);
319 // argumentNames[i] = argument.name;
320 // argumentNameStarts[i] = argument.sourceStart;
321 // argumentNameEnds[i] = argument.sourceEnd;
322 // argumentTypeStarts[i] = argumentType.sourceStart;
323 // argumentTypeEnds[i] = argumentType.sourceEnd;
326 // TypeReference[] thrownExceptions = cd.thrownExceptions;
327 // char[][] exceptionTypes = null;
328 // int[] exceptionTypeStarts = null;
329 // int[] exceptionTypeEnds = null;
330 // if (thrownExceptions != null) {
331 // int thrownExceptionLength = thrownExceptions.length;
332 // exceptionTypes = new char[thrownExceptionLength][];
333 // exceptionTypeStarts = new int[thrownExceptionLength];
334 // exceptionTypeEnds = new int[thrownExceptionLength];
335 // for (int i = 0; i < thrownExceptionLength; i++) {
336 // TypeReference exception = thrownExceptions[i];
337 // exceptionTypes[i] = CharOperation.concatWith(exception.getTypeName(), '.');
338 // exceptionTypeStarts[i] = exception.sourceStart;
339 // exceptionTypeEnds[i] = exception.sourceEnd;
343 // .enterConstructor(
344 // cd.declarationSourceStart,
345 // intArrayStack[intArrayPtr--],
347 // cd.modifiersSourceStart,
350 // (int) (selectorSourcePositions & 0xFFFFFFFFL),
351 // // retrieve the source end of the name
353 // argumentTypeStarts,
356 // argumentNameStarts,
359 // // right parenthesis
361 // exceptionTypeStarts,
362 // exceptionTypeEnds,
363 // scanner.currentPosition - 1);
365 //protected void consumeConstructorHeaderName() {
366 // // ConstructorHeaderName ::= Modifiersopt 'Identifier' '('
367 // ConstructorDeclaration cd = new ConstructorDeclaration(this.compilationUnit.compilationResult);
369 // //name -- this is not really revelant but we do .....
370 // cd.selector = identifierStack[identifierPtr];
371 // selectorSourcePositions = identifierPositionStack[identifierPtr--];
372 // identifierLengthPtr--;
375 // cd.declarationSourceStart = intStack[intPtr--];
376 // cd.modifiersSourceStart = intStack[intPtr--];
377 // cd.modifiers = intStack[intPtr--];
379 // //highlight starts at the selector starts
380 // cd.sourceStart = (int) (selectorSourcePositions >>> 32);
381 // pushOnAstStack(cd);
383 // cd.sourceEnd = lParenPos;
384 // cd.bodyStart = lParenPos + 1;
386 //protected void consumeDefaultModifiers() {
387 // checkAnnotation(); // might update modifiers with AccDeprecated
388 // pushOnIntStack(modifiers); // modifiers
389 // pushOnIntStack(-1);
391 // declarationSourceStart >= 0 ? declarationSourceStart : scanner.startPosition);
394 //protected void consumeDiet() {
395 // // Diet ::= $empty
396 // super.consumeDiet();
397 // /* persisting javadoc positions
398 // * Will be consume in consumeClassBodyDeclaration
400 // pushOnIntArrayStack(this.getJavaDocPositions());
404 // * INTERNAL USE-ONLY
406 //protected void consumeEnterCompilationUnit() {
407 // // EnterCompilationUnit ::= $empty
408 // requestor.enterCompilationUnit();
412 // * INTERNAL USE-ONLY
414 //protected void consumeEnterVariable() {
415 // // EnterVariable ::= $empty
416 // boolean isLocalDeclaration = isLocalDeclaration();
417 // if (!isLocalDeclaration && (variablesCounter[nestedType] != 0)) {
418 // requestor.exitField(lastFieldBodyEndPosition, lastFieldEndPosition);
420 // char[] name = identifierStack[identifierPtr];
421 // long namePosition = identifierPositionStack[identifierPtr--];
422 // int extendedTypeDimension = intStack[intPtr--];
424 // AbstractVariableDeclaration declaration;
425 // if (nestedMethod[nestedType] != 0) {
426 // // create the local variable declarations
428 // new LocalDeclaration(null, name, (int) (namePosition >>> 32), (int) namePosition);
430 // // create the field declaration
432 // new FieldDeclaration(null, name, (int) (namePosition >>> 32), (int) namePosition);
434 // identifierLengthPtr--;
435 // TypeReference type;
436 // int variableIndex = variablesCounter[nestedType];
438 // if (variableIndex == 0) {
439 // // first variable of the declaration (FieldDeclaration or LocalDeclaration)
440 // if (nestedMethod[nestedType] != 0) {
441 // // local declaration
442 // declaration.declarationSourceStart = intStack[intPtr--];
443 // declaration.modifiersSourceStart = intStack[intPtr--];
444 // declaration.modifiers = intStack[intPtr--];
445 // type = getTypeReference(typeDim = intStack[intPtr--]); // type dimension
446 // pushOnAstStack(type);
448 // // field declaration
449 // type = getTypeReference(typeDim = intStack[intPtr--]); // type dimension
450 // pushOnAstStack(type);
451 // declaration.declarationSourceStart = intStack[intPtr--];
452 // declaration.modifiersSourceStart = intStack[intPtr--];
453 // declaration.modifiers = intStack[intPtr--];
456 // type = (TypeReference) astStack[astPtr - variableIndex];
457 // typeDim = type.dimensions();
458 // AbstractVariableDeclaration previousVariable =
459 // (AbstractVariableDeclaration) astStack[astPtr];
460 // declaration.declarationSourceStart = previousVariable.declarationSourceStart;
461 // declaration.modifiers = previousVariable.modifiers;
462 // declaration.modifiersSourceStart = previousVariable.modifiersSourceStart;
465 // localIntPtr = intPtr;
467 // if (extendedTypeDimension == 0) {
468 // declaration.type = type;
470 // int dimension = typeDim + extendedTypeDimension;
471 // //on the identifierLengthStack there is the information about the type....
473 // if ((baseType = identifierLengthStack[identifierLengthPtr + 1]) < 0) {
474 // //it was a baseType
475 // declaration.type = TypeReference.baseTypeReference(-baseType, dimension);
476 // declaration.type.sourceStart = type.sourceStart;
477 // declaration.type.sourceEnd = type.sourceEnd;
479 // declaration.type = this.copyDims(type, dimension);
482 // variablesCounter[nestedType]++;
483 // nestedMethod[nestedType]++;
484 // pushOnAstStack(declaration);
486 // int[] javadocPositions = intArrayStack[intArrayPtr];
487 // if (!isLocalDeclaration) {
490 // declaration.declarationSourceStart,
492 // declaration.modifiers,
493 // declaration.modifiersSourceStart,
494 // returnTypeName(declaration.type),
499 // (int) (namePosition >>> 32),
500 // (int) namePosition,
501 // extendedTypeDimension,
502 // extendedTypeDimension == 0 ? -1 : endPosition);
507 // * INTERNAL USE-ONLY
509 //protected void consumeExitVariableWithInitialization() {
510 // // ExitVariableWithInitialization ::= $empty
511 // // the scanner is located after the comma or the semi-colon.
512 // // we want to include the comma or the semi-colon
513 // super.consumeExitVariableWithInitialization();
514 // nestedMethod[nestedType]--;
515 // lastFieldEndPosition = scanner.currentPosition - 1;
516 // lastFieldBodyEndPosition = ((AbstractVariableDeclaration) astStack[astPtr]).initialization.sourceEnd;
518 //protected void consumeExitVariableWithoutInitialization() {
519 // // ExitVariableWithoutInitialization ::= $empty
520 // // do nothing by default
521 // super.consumeExitVariableWithoutInitialization();
522 // nestedMethod[nestedType]--;
523 // lastFieldEndPosition = scanner.currentPosition - 1;
524 // lastFieldBodyEndPosition = scanner.startPosition - 1;
528 // * INTERNAL USE-ONLY
530 //protected void consumeFieldDeclaration() {
531 // // See consumeLocalVariableDeclarationDefaultModifier() in case of change: duplicated code
532 // // FieldDeclaration ::= Modifiersopt Type VariableDeclarators ';'
533 // // the super.consumeFieldDeclaration will reinitialize the variableCounter[nestedType]
534 // int variableIndex = variablesCounter[nestedType];
535 // super.consumeFieldDeclaration();
537 // if (isLocalDeclaration())
539 // if (variableIndex != 0) {
540 // requestor.exitField(lastFieldBodyEndPosition, lastFieldEndPosition);
543 //protected void consumeFormalParameter() {
544 // // FormalParameter ::= Type VariableDeclaratorId ==> false
545 // // FormalParameter ::= Modifiers Type VariableDeclaratorId ==> true
548 // identifierStack : type identifier
549 // intStack : dim dim
551 // astStack : Argument
556 // identifierLengthPtr--;
557 // char[] name = identifierStack[identifierPtr];
558 // long namePositions = identifierPositionStack[identifierPtr--];
559 // TypeReference type = getTypeReference(intStack[intPtr--] + intStack[intPtr--]);
566 // intStack[intPtr + 1]); // modifiers
567 // pushOnAstStack(arg);
572 // * INTERNAL USE-ONLY
574 //protected void consumeInterfaceDeclaration() {
575 // super.consumeInterfaceDeclaration();
576 // // we know that we have a TypeDeclaration on the top of the astStack
577 // if (isLocalDeclaration()) {
578 // // we ignore the local variable declarations
581 // requestor.exitInterface(endStatementPosition, // the '}' is the end of the body
582 // ((TypeDeclaration) astStack[astPtr]).declarationSourceEnd);
586 // * INTERNAL USE-ONLY
588 //protected void consumeInterfaceHeader() {
589 // //InterfaceHeader ::= $empty
590 // super.consumeInterfaceHeader();
591 // if (isLocalDeclaration()) {
592 // // we ignore the local variable declarations
596 // TypeDeclaration typeDecl = (TypeDeclaration) astStack[astPtr];
597 // TypeReference[] superInterfaces = typeDecl.superInterfaces;
598 // char[][] interfaceNames = null;
599 // int[] interfaceNameStarts = null;
600 // int[] interfacenameEnds = null;
601 // int superInterfacesLength = 0;
602 // if (superInterfaces != null) {
603 // superInterfacesLength = superInterfaces.length;
604 // interfaceNames = new char[superInterfacesLength][];
605 // interfaceNameStarts = new int[superInterfacesLength];
606 // interfacenameEnds = new int[superInterfacesLength];
608 // if (superInterfaces != null) {
609 // for (int i = 0; i < superInterfacesLength; i++) {
610 // TypeReference superInterface = superInterfaces[i];
611 // interfaceNames[i] = CharOperation.concatWith(superInterface.getTypeName(), '.');
612 // interfaceNameStarts[i] = superInterface.sourceStart;
613 // interfacenameEnds[i] = superInterface.sourceEnd;
616 // // flush the comments related to the interface header
617 // scanner.commentPtr = -1;
618 // requestor.enterInterface(
619 // typeDecl.declarationSourceStart,
620 // intArrayStack[intArrayPtr--],
621 // typeDecl.modifiers,
622 // typeDecl.modifiersSourceStart,
623 // typeStartPosition,
625 // typeDecl.sourceStart,
626 // typeDecl.sourceEnd,
628 // interfaceNameStarts,
629 // interfacenameEnds,
630 // scanner.currentPosition - 1);
632 //protected void consumeInterfaceHeaderName() {
633 // // InterfaceHeaderName ::= Modifiersopt 'interface' 'Identifier'
634 // TypeDeclaration typeDecl;
635 // if (nestedMethod[nestedType] == 0) {
636 // if (nestedType != 0) {
637 // typeDecl = new MemberTypeDeclaration(this.compilationUnit.compilationResult);
639 // typeDecl = new TypeDeclaration(this.compilationUnit.compilationResult);
642 // // Record that the block has a declaration for local types
643 // typeDecl = new LocalTypeDeclaration(this.compilationUnit.compilationResult);
644 // markEnclosingMemberWithLocalType();
648 // //highlight the name of the type
649 // long pos = identifierPositionStack[identifierPtr];
650 // typeDecl.sourceEnd = (int) pos;
651 // typeDecl.sourceStart = (int) (pos >>> 32);
652 // typeDecl.name = identifierStack[identifierPtr--];
653 // identifierLengthPtr--;
655 // //compute the declaration source too
656 // // 'class' and 'interface' push an int position
657 // typeStartPosition = typeDecl.declarationSourceStart = intStack[intPtr--];
659 // int declarationSourceStart = intStack[intPtr--];
660 // typeDecl.modifiersSourceStart = intStack[intPtr--];
661 // typeDecl.modifiers = intStack[intPtr--];
662 // if (typeDecl.declarationSourceStart > declarationSourceStart) {
663 // typeDecl.declarationSourceStart = declarationSourceStart;
665 // typeDecl.bodyStart = typeDecl.sourceEnd + 1;
666 // pushOnAstStack(typeDecl);
670 // * INTERNAL USE-ONLY
672 //protected void consumeLocalVariableDeclaration() {
673 // // See consumeLocalVariableDeclarationDefaultModifier() in case of change: duplicated code
674 // // FieldDeclaration ::= Modifiersopt Type VariableDeclarators ';'
676 // super.consumeLocalVariableDeclaration();
681 // * INTERNAL USE-ONLY
683 //protected void consumeMethodDeclaration(boolean isNotAbstract) {
684 // // MethodDeclaration ::= MethodHeader MethodBody
685 // // AbstractMethodDeclaration ::= MethodHeader ';'
686 // super.consumeMethodDeclaration(isNotAbstract);
687 // if (isLocalDeclaration()) {
688 // // we ignore the local variable declarations
691 // MethodDeclaration md = (MethodDeclaration) astStack[astPtr];
692 // requestor.exitMethod(endStatementPosition, md.declarationSourceEnd);
696 // * INTERNAL USE-ONLY
698 //protected void consumeMethodHeader() {
699 // // MethodHeader ::= MethodHeaderName MethodHeaderParameters MethodHeaderExtendedDims ThrowsClauseopt
700 // super.consumeMethodHeader();
701 // if (isLocalDeclaration()) {
702 // // we ignore the local variable declarations
706 // MethodDeclaration md = (MethodDeclaration) astStack[astPtr];
708 // TypeReference returnType = md.returnType;
709 // char[] returnTypeName = returnTypeName(returnType);
710 // Argument[] arguments = md.arguments;
711 // char[][] argumentTypes = null;
712 // char[][] argumentNames = null;
713 // int[] argumentTypeStarts = null;
714 // int[] argumentTypeEnds = null;
715 // int[] argumentNameStarts = null;
716 // int[] argumentNameEnds = null;
717 // if (arguments != null) {
718 // int argumentLength = arguments.length;
719 // argumentTypes = new char[argumentLength][];
720 // argumentNames = new char[argumentLength][];
721 // argumentNameStarts = new int[argumentLength];
722 // argumentNameEnds = new int[argumentLength];
723 // argumentTypeStarts = new int[argumentLength];
724 // argumentTypeEnds = new int[argumentLength];
725 // for (int i = 0; i < argumentLength; i++) {
726 // Argument argument = arguments[i];
727 // TypeReference argumentType = argument.type;
728 // argumentTypes[i] = returnTypeName(argumentType);
729 // argumentNames[i] = argument.name;
730 // argumentNameStarts[i] = argument.sourceStart;
731 // argumentNameEnds[i] = argument.sourceEnd;
732 // argumentTypeStarts[i] = argumentType.sourceStart;
733 // argumentTypeEnds[i] = argumentType.sourceEnd;
736 // TypeReference[] thrownExceptions = md.thrownExceptions;
737 // char[][] exceptionTypes = null;
738 // int[] exceptionTypeStarts = null;
739 // int[] exceptionTypeEnds = null;
740 // if (thrownExceptions != null) {
741 // int thrownExceptionLength = thrownExceptions.length;
742 // exceptionTypeStarts = new int[thrownExceptionLength];
743 // exceptionTypeEnds = new int[thrownExceptionLength];
744 // exceptionTypes = new char[thrownExceptionLength][];
745 // for (int i = 0; i < thrownExceptionLength; i++) {
746 // TypeReference exception = thrownExceptions[i];
747 // exceptionTypes[i] = CharOperation.concatWith(exception.getTypeName(), '.');
748 // exceptionTypeStarts[i] = exception.sourceStart;
749 // exceptionTypeEnds[i] = exception.sourceEnd;
754 // md.declarationSourceStart,
755 // intArrayStack[intArrayPtr--],
757 // md.modifiersSourceStart,
759 // returnType.sourceStart,
760 // returnType.sourceEnd,
764 // (int) (selectorSourcePositions & 0xFFFFFFFFL),
766 // argumentTypeStarts,
769 // argumentNameStarts,
773 // extendsDim == 0 ? -1 : endPosition,
775 // exceptionTypeStarts,
776 // exceptionTypeEnds,
777 // scanner.currentPosition - 1);
779 //protected void consumeMethodHeaderExtendedDims() {
780 // // MethodHeaderExtendedDims ::= Dimsopt
781 // // now we update the returnType of the method
782 // MethodDeclaration md = (MethodDeclaration) astStack[astPtr];
783 // int extendedDims = intStack[intPtr--];
784 // extendsDim = extendedDims;
785 // if (extendedDims != 0) {
786 // TypeReference returnType = md.returnType;
787 // md.sourceEnd = endPosition;
788 // int dims = returnType.dimensions() + extendedDims;
790 // if ((baseType = identifierLengthStack[identifierLengthPtr + 1]) < 0) {
791 // //it was a baseType
792 // int sourceStart = returnType.sourceStart;
793 // int sourceEnd = returnType.sourceEnd;
794 // returnType = TypeReference.baseTypeReference(-baseType, dims);
795 // returnType.sourceStart = sourceStart;
796 // returnType.sourceEnd = sourceEnd;
797 // md.returnType = returnType;
799 // md.returnType = this.copyDims(md.returnType, dims);
801 // if (currentToken == TokenNameLBRACE) {
802 // md.bodyStart = endPosition + 1;
806 //protected void consumeMethodHeaderName() {
807 // // MethodHeaderName ::= Modifiersopt Type 'Identifier' '('
808 // MethodDeclaration md = new MethodDeclaration(this.compilationUnit.compilationResult);
811 // md.selector = identifierStack[identifierPtr];
812 // selectorSourcePositions = identifierPositionStack[identifierPtr--];
813 // identifierLengthPtr--;
815 // md.returnType = getTypeReference(typeDims = intStack[intPtr--]);
817 // md.declarationSourceStart = intStack[intPtr--];
818 // md.modifiersSourceStart = intStack[intPtr--];
819 // md.modifiers = intStack[intPtr--];
821 // //highlight starts at selector start
822 // md.sourceStart = (int) (selectorSourcePositions >>> 32);
823 // pushOnAstStack(md);
824 // md.bodyStart = scanner.currentPosition-1;
826 //protected void consumeModifiers() {
827 // checkAnnotation(); // might update modifiers with AccDeprecated
828 // pushOnIntStack(modifiers); // modifiers
829 // pushOnIntStack(modifiersSourceStart);
831 // declarationSourceStart >= 0 ? declarationSourceStart : modifiersSourceStart);
838 //protected void consumePackageDeclarationName() {
839 // /* persisting javadoc positions */
840 // pushOnIntArrayStack(this.getJavaDocPositions());
842 // super.consumePackageDeclarationName();
843 // ImportReference importReference = compilationUnit.currentPackage;
845 // requestor.acceptPackage(
846 // importReference.declarationSourceStart,
847 // importReference.declarationSourceEnd,
848 // intArrayStack[intArrayPtr--],
849 // CharOperation.concatWith(importReference.getImportName(), '.'),
850 // importReference.sourceStart);
852 //protected void consumePushModifiers() {
853 // checkAnnotation(); // might update modifiers with AccDeprecated
854 // pushOnIntStack(modifiers); // modifiers
855 // if (modifiersSourceStart < 0) {
856 // pushOnIntStack(-1);
858 // declarationSourceStart >= 0 ? declarationSourceStart : scanner.startPosition);
860 // pushOnIntStack(modifiersSourceStart);
862 // declarationSourceStart >= 0 ? declarationSourceStart : modifiersSourceStart);
868 // * INTERNAL USE-ONLY
870 //protected void consumeSingleTypeImportDeclarationName() {
871 // // SingleTypeImportDeclarationName ::= 'import' Name
873 // /* persisting javadoc positions */
874 // pushOnIntArrayStack(this.getJavaDocPositions());
876 // super.consumeSingleTypeImportDeclarationName();
877 // ImportReference importReference = (ImportReference) astStack[astPtr];
878 // requestor.acceptImport(
879 // importReference.declarationSourceStart,
880 // importReference.declarationSourceEnd,
881 // intArrayStack[intArrayPtr--],
882 // CharOperation.concatWith(importReference.getImportName(), '.'),
883 // importReference.sourceStart,
888 // * INTERNAL USE-ONLY
890 //protected void consumeStaticInitializer() {
891 // // StaticInitializer ::= StaticOnly Block
892 // //push an Initializer
893 // //optimize the push/pop
894 // super.consumeStaticInitializer();
895 // Initializer initializer = (Initializer) astStack[astPtr];
896 // requestor.acceptInitializer(
897 // initializer.declarationSourceStart,
898 // initializer.declarationSourceEnd,
899 // intArrayStack[intArrayPtr--],
901 // intStack[intPtr--],
902 // initializer.block.sourceStart,
903 // initializer.declarationSourceEnd);
905 //protected void consumeStaticOnly() {
906 // // StaticOnly ::= 'static'
907 // checkAnnotation(); // might update declaration source start
908 // pushOnIntStack(modifiersSourceStart);
910 // declarationSourceStart >= 0 ? declarationSourceStart : modifiersSourceStart);
911 // jumpOverMethodBody();
912 // nestedMethod[nestedType]++;
917 // * INTERNAL USE-ONLY
919 //protected void consumeTypeImportOnDemandDeclarationName() {
920 // // TypeImportOnDemandDeclarationName ::= 'import' Name '.' '*'
922 // /* persisting javadoc positions */
923 // pushOnIntArrayStack(this.getJavaDocPositions());
925 // super.consumeTypeImportOnDemandDeclarationName();
926 // ImportReference importReference = (ImportReference) astStack[astPtr];
927 // requestor.acceptImport(
928 // importReference.declarationSourceStart,
929 // importReference.declarationSourceEnd,
930 // intArrayStack[intArrayPtr--],
931 // CharOperation.concatWith(importReference.getImportName(), '.'),
932 // importReference.sourceStart,
935 public CompilationUnitDeclaration endParse(int act) {
936 if (scanner.recordLineSeparator) {
937 requestor.acceptLineSeparatorPositions(scanner.getLineEnds());
939 return super.endParse(act);
942 * Flush annotations defined prior to a given positions.
944 * Note: annotations are stacked in syntactical order
946 * Either answer given <position>, or the end position of a comment line
947 * immediately following the <position> (same line)
951 * } // end of method foo
954 //public int flushAnnotationsDefinedPriorTo(int position) {
956 // return lastFieldEndPosition = super.flushAnnotationsDefinedPriorTo(position);
958 //protected TypeReference getTypeReference(int dim) { /* build a Reference on a variable that may be qualified or not
959 //This variable is a type reference and dim will be its dimensions*/
962 // TypeReference ref;
963 // if ((length = identifierLengthStack[identifierLengthPtr--]) == 1) {
964 // // single variable reference
967 // new SingleTypeReference(
968 // identifierStack[identifierPtr],
969 // identifierPositionStack[identifierPtr--]);
972 // new ArrayTypeReference(
973 // identifierStack[identifierPtr],
975 // identifierPositionStack[identifierPtr--]);
976 // ref.sourceEnd = endPosition;
979 // if (length < 0) { //flag for precompiled type reference on base types
980 // ref = TypeReference.baseTypeReference(-length, dim);
981 // ref.sourceStart = intStack[intPtr--];
983 // ref.sourceEnd = intStack[intPtr--];
986 // ref.sourceEnd = endPosition;
988 // } else { //Qualified variable reference
989 // char[][] tokens = new char[length][];
990 // identifierPtr -= length;
991 // long[] positions = new long[length];
992 // System.arraycopy(identifierStack, identifierPtr + 1, tokens, 0, length);
994 // identifierPositionStack,
995 // identifierPtr + 1,
1000 // ref = new QualifiedTypeReference(tokens, positions);
1002 // ref = new ArrayQualifiedTypeReference(tokens, dim, positions);
1003 // ref.sourceEnd = endPosition;
1009 public void initialize() {
1010 //positionning the parser for a new compilation unit
1011 //avoiding stack reallocation and all that....
1012 super.initialize(false);
1019 //private boolean isLocalDeclaration() {
1020 // int nestedDepth = nestedType;
1021 // while (nestedDepth >= 0) {
1022 // if (nestedMethod[nestedDepth] != 0) {
1030 * Investigate one entire unit.
1032 public void parseCompilationUnit(ICompilationUnit unit) {
1033 char[] regionSource = unit.getContents();
1036 goForCompilationUnit();
1040 new CompilationUnitDeclaration(
1042 new CompilationResult(unit, 0, 0, 10), //this.options.maxProblemsPerUnit),
1043 regionSource.length);
1044 scanner.resetTo(0, regionSource.length);
1045 scanner.setSource(regionSource);
1047 } catch (CoreException e) {
1048 e.printStackTrace();
1049 } catch (AbortCompilation ex) {
1053 * Investigate one constructor declaration.
1055 //public void parseConstructor(char[] regionSource) {
1058 // goForClassBodyDeclarations();
1059 // referenceContext =
1060 // compilationUnit =
1061 // compilationUnit =
1062 // new CompilationUnitDeclaration(
1063 // problemReporter(),
1064 // new CompilationResult(regionSource, 0, 0, 10), //this.options.maxProblemsPerUnit),
1065 // regionSource.length);
1066 // scanner.resetTo(0, regionSource.length);
1067 // scanner.setSource(regionSource);
1069 // } catch (AbortCompilation ex) {
1073 * Investigate one field declaration statement (might have multiple declarations in it).
1075 //public void parseField(char[] regionSource) {
1078 // goForFieldDeclaration();
1079 // referenceContext =
1080 // compilationUnit =
1081 // compilationUnit =
1082 // new CompilationUnitDeclaration(
1083 // problemReporter(),
1084 // new CompilationResult(regionSource, 0, 0, this.options.maxProblemsPerUnit),
1085 // regionSource.length);
1086 // scanner.resetTo(0, regionSource.length);
1087 // scanner.setSource(regionSource);
1089 // } catch (AbortCompilation ex) {
1094 // * Investigate one import statement declaration.
1096 //public void parseImport(char[] regionSource) {
1099 // goForImportDeclaration();
1100 // referenceContext =
1101 // compilationUnit =
1102 // compilationUnit =
1103 // new CompilationUnitDeclaration(
1104 // problemReporter(),
1105 // new CompilationResult(regionSource, 0, 0, this.options.maxProblemsPerUnit),
1106 // regionSource.length);
1107 // scanner.resetTo(0, regionSource.length);
1108 // scanner.setSource(regionSource);
1110 // } catch (AbortCompilation ex) {
1115 // * Investigate one initializer declaration.
1116 // * regionSource need to content exactly an initializer declaration.
1117 // * e.g: static { i = 4; }
1118 // * { name = "test"; }
1120 //public void parseInitializer(char[] regionSource) {
1123 // goForInitializer();
1124 // referenceContext =
1125 // compilationUnit =
1126 // compilationUnit =
1127 // new CompilationUnitDeclaration(
1128 // problemReporter(),
1129 // new CompilationResult(regionSource, 0, 0, this.options.maxProblemsPerUnit),
1130 // regionSource.length);
1131 // scanner.resetTo(0, regionSource.length);
1132 // scanner.setSource(regionSource);
1134 // } catch (AbortCompilation ex) {
1139 // * Investigate one method declaration.
1141 //public void parseMethod(char[] regionSource) {
1144 // goForGenericMethodDeclaration();
1145 // referenceContext =
1146 // compilationUnit =
1147 // compilationUnit =
1148 // new CompilationUnitDeclaration(
1149 // problemReporter(),
1150 // new CompilationResult(regionSource, 0, 0, this.options.maxProblemsPerUnit),
1151 // regionSource.length);
1152 // scanner.resetTo(0, regionSource.length);
1153 // scanner.setSource(regionSource);
1155 // } catch (AbortCompilation ex) {
1160 // * Investigate one package statement declaration.
1162 //public void parsePackage(char[] regionSource) {
1165 // goForPackageDeclaration();
1166 // referenceContext =
1167 // compilationUnit =
1168 // compilationUnit =
1169 // new CompilationUnitDeclaration(
1170 // problemReporter(),
1171 // new CompilationResult(regionSource, 0, 0, this.options.maxProblemsPerUnit),
1172 // regionSource.length);
1173 // scanner.resetTo(0, regionSource.length);
1174 // scanner.setSource(regionSource);
1176 // } catch (AbortCompilation ex) {
1181 // * Investigate one type declaration, its fields, methods and member types.
1183 //public void parseType(char[] regionSource) {
1186 // goForTypeDeclaration();
1187 // referenceContext =
1188 // compilationUnit =
1189 // compilationUnit =
1190 // new CompilationUnitDeclaration(
1191 // problemReporter(),
1192 // new CompilationResult(regionSource, 0, 0, this.options.maxProblemsPerUnit),
1193 // regionSource.length);
1194 // scanner.resetTo(0, regionSource.length);
1195 // scanner.setSource(regionSource);
1197 // } catch (AbortCompilation ex) {
1202 * Returns this parser's problem reporter initialized with its reference context.
1203 * Also it is assumed that a problem is going to be reported, so initializes
1204 * the compilation result's line positions.
1206 public ProblemReporter problemReporter() {
1207 problemReporter.referenceContext = referenceContext;
1208 return problemReporter;
1210 protected void pushOnIntArrayStack(int[] positions) {
1213 intArrayStack[++intArrayPtr] = positions;
1214 } catch (IndexOutOfBoundsException e) {
1216 int oldStackLength = intArrayStack.length;
1217 int oldStack[][] = intArrayStack;
1218 intArrayStack = new int[oldStackLength + StackIncrement][];
1219 System.arraycopy(oldStack, 0, intArrayStack, 0, oldStackLength);
1220 intArrayStack[intArrayPtr] = positions;
1223 //protected void resetModifiers() {
1224 // super.resetModifiers();
1225 // declarationSourceStart = -1;
1228 * Syntax error was detected. Will attempt to perform some recovery action in order
1229 * to resume to the regular parse loop.
1231 protected boolean resumeOnSyntaxError() {
1235 * Answer a char array representation of the type name formatted like:
1236 * - type name + dimensions
1238 * "A[][]".toCharArray()
1239 * "java.lang.String".toCharArray()
1241 //private char[] returnTypeName(TypeReference type) {
1242 // int dimension = type.dimensions();
1243 // if (dimension != 0) {
1244 // char[] dimensionsArray = new char[dimension * 2];
1245 // for (int i = 0; i < dimension; i++) {
1246 // dimensionsArray[i*2] = '[';
1247 // dimensionsArray[(i*2) + 1] = ']';
1249 // return CharOperation.concat(
1250 // CharOperation.concatWith(type.getTypeName(), '.'),
1251 // dimensionsArray);
1253 // return CharOperation.concatWith(type.getTypeName(), '.');
1255 //public String toString() {
1256 // StringBuffer buffer = new StringBuffer();
1257 // buffer.append("intArrayPtr = " + intArrayPtr + "\n"); //$NON-NLS-1$ //$NON-NLS-2$
1258 // buffer.append(super.toString());
1259 // return buffer.toString();
1262 // * INTERNAL USE ONLY
1264 //protected TypeReference typeReference(
1266 // int localIdentifierPtr,
1267 // int localIdentifierLengthPtr) {
1268 // /* build a Reference on a variable that may be qualified or not
1269 // * This variable is a type reference and dim will be its dimensions.
1270 // * We don't have any side effect on the stacks' pointers.
1274 // TypeReference ref;
1275 // if ((length = identifierLengthStack[localIdentifierLengthPtr]) == 1) {
1276 // // single variable reference
1279 // new SingleTypeReference(
1280 // identifierStack[localIdentifierPtr],
1281 // identifierPositionStack[localIdentifierPtr--]);
1284 // new ArrayTypeReference(
1285 // identifierStack[localIdentifierPtr],
1287 // identifierPositionStack[localIdentifierPtr--]);
1288 // ref.sourceEnd = endPosition;
1291 // if (length < 0) { //flag for precompiled type reference on base types
1292 // ref = TypeReference.baseTypeReference(-length, dim);
1293 // ref.sourceStart = intStack[localIntPtr--];
1295 // ref.sourceEnd = intStack[localIntPtr--];
1298 // ref.sourceEnd = endPosition;
1300 // } else { //Qualified variable reference
1301 // char[][] tokens = new char[length][];
1302 // localIdentifierPtr -= length;
1303 // long[] positions = new long[length];
1304 // System.arraycopy(identifierStack, localIdentifierPtr + 1, tokens, 0, length);
1305 // System.arraycopy(
1306 // identifierPositionStack,
1307 // localIdentifierPtr + 1,
1312 // ref = new QualifiedTypeReference(tokens, positions);
1314 // ref = new ArrayQualifiedTypeReference(tokens, dim, positions);