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
6 * Contributors: IBM Corporation - initial API and implementation
7 **********************************************************************************************************************************/
8 package net.sourceforge.phpdt.internal.compiler;
10 import net.sourceforge.phpdt.core.compiler.IProblem;
11 import net.sourceforge.phpdt.internal.compiler.env.ICompilationUnit;
12 import net.sourceforge.phpdt.internal.compiler.impl.CompilerOptions;
13 import net.sourceforge.phpdt.internal.compiler.parser.UnitParser;
14 import net.sourceforge.phpdt.internal.compiler.problem.AbortCompilation;
15 import net.sourceforge.phpdt.internal.compiler.problem.ProblemReporter;
16 import net.sourceforge.phpeclipse.internal.compiler.ast.CompilationUnitDeclaration;
18 import org.eclipse.core.resources.IResource;
21 * A document element parser extracts structural information from a piece of source, providing detailed source positions info.
23 * also see @IDocumentElementRequestor
25 * The structural investigation includes: - the package statement - import statements - top-level types: package member, member
26 * types (member types of member types...) - fields - methods
28 * Any (parsing) problem encountered is also provided.
30 public class DocumentElementParser extends UnitParser {
31 IDocumentElementRequestor requestor;
33 private int localIntPtr;
35 private int lastFieldEndPosition;
37 private int lastFieldBodyEndPosition;
39 private int typeStartPosition;
41 private long selectorSourcePositions;
45 private int extendsDim;
47 private int declarationSourceStart;
49 /* int[] stack for storing javadoc positions */
50 int[][] intArrayStack;
54 // CompilerOptions options;
56 public DocumentElementParser(final IDocumentElementRequestor requestor, IProblemFactory problemFactory,
57 CompilerOptions options) {
58 super(new ProblemReporter(DefaultErrorHandlingPolicies.exitAfterAllProblems(), options, problemFactory) {
59 public void record(IProblem problem, CompilationResult unitResult) {
60 requestor.acceptProblem(problem);
64 // options.sourceLevel >= CompilerOptions.JDK1_4);
65 this.requestor = requestor;
66 intArrayStack = new int[30][];
67 this.options = options;
74 //protected void adjustInterfaceModifiers() {
75 // intStack[intPtr - 2] |= AccInterface;
78 * Will clear the comment stack when looking for a potential JavaDoc which might contain @deprecated.
80 * Additionally, before investigating for @deprecated, retrieve the positions of the JavaDoc comments so as to notify requestor
83 //public void checkAnnotation() {
85 // /* persisting javadoc positions */
86 // pushOnIntArrayStack(this.getJavaDocPositions());
87 // boolean deprecated = false;
88 // int lastAnnotationIndex = -1;
89 // int commentPtr = scanner.commentPtr;
91 // //since jdk1.2 look only in the last java doc comment...
92 // nextComment : for (lastAnnotationIndex = scanner.commentPtr; lastAnnotationIndex >= 0; lastAnnotationIndex--){
93 // //look for @deprecated into the first javadoc comment preceeding the declaration
94 // int commentSourceStart = scanner.commentStarts[lastAnnotationIndex];
95 // // javadoc only (non javadoc comment have negative end positions.)
96 // if (modifiersSourceStart != -1 && modifiersSourceStart < commentSourceStart) {
97 // continue nextComment;
99 // if (scanner.commentStops[lastAnnotationIndex] < 0) {
100 // continue nextComment;
102 // int commentSourceEnd = scanner.commentStops[lastAnnotationIndex] - 1; //stop is one over
103 // char[] comment = scanner.source;
107 // commentSourceStart,
110 // break nextComment;
113 // checkAndSetModifiers(AccDeprecated);
115 // // modify the modifier source start to point at the first comment
116 // if (commentPtr >= 0) {
117 // declarationSourceStart = scanner.commentStarts[0];
124 //protected void consumeClassBodyDeclaration() {
125 // // ClassBodyDeclaration ::= Diet Block
126 // //push an Initializer
127 // //optimize the push/pop
129 // super.consumeClassBodyDeclaration();
130 // Initializer initializer = (Initializer) astStack[astPtr];
131 // requestor.acceptInitializer(
132 // initializer.declarationSourceStart,
133 // initializer.declarationSourceEnd,
134 // intArrayStack[intArrayPtr--],
136 // modifiersSourceStart,
137 // initializer.block.sourceStart,
138 // initializer.block.sourceEnd);
142 // * INTERNAL USE-ONLY
144 //protected void consumeClassDeclaration() {
145 // super.consumeClassDeclaration();
146 // // we know that we have a TypeDeclaration on the top of the astStack
147 // if (isLocalDeclaration()) {
148 // // we ignore the local variable declarations
151 // requestor.exitClass(endStatementPosition, // '}' is the end of the body
152 // ((TypeDeclaration) astStack[astPtr]).declarationSourceEnd);
156 // * INTERNAL USE-ONLY
158 //protected void consumeClassHeader() {
159 // //ClassHeader ::= $empty
160 // super.consumeClassHeader();
161 // if (isLocalDeclaration()) {
162 // // we ignore the local variable declarations
166 // TypeDeclaration typeDecl = (TypeDeclaration) astStack[astPtr];
167 // TypeReference[] superInterfaces = typeDecl.superInterfaces;
168 // char[][] interfaceNames = null;
169 // int[] interfaceNameStarts = null;
170 // int[] interfaceNameEnds = null;
171 // if (superInterfaces != null) {
172 // int superInterfacesLength = superInterfaces.length;
173 // interfaceNames = new char[superInterfacesLength][];
174 // interfaceNameStarts = new int[superInterfacesLength];
175 // interfaceNameEnds = new int[superInterfacesLength];
176 // for (int i = 0; i < superInterfacesLength; i++) {
177 // TypeReference superInterface = superInterfaces[i];
178 // interfaceNames[i] = CharOperation.concatWith(superInterface.getTypeName(), '.');
179 // interfaceNameStarts[i] = superInterface.sourceStart;
180 // interfaceNameEnds[i] = superInterface.sourceEnd;
183 // // flush the comments related to the class header
184 // scanner.commentPtr = -1;
185 // TypeReference superclass = typeDecl.superclass;
186 // if (superclass == null) {
187 // requestor.enterClass(
188 // typeDecl.declarationSourceStart,
189 // intArrayStack[intArrayPtr--],
190 // typeDecl.modifiers,
191 // typeDecl.modifiersSourceStart,
192 // typeStartPosition,
194 // typeDecl.sourceStart,
195 // typeDecl.sourceEnd,
200 // interfaceNameStarts,
201 // interfaceNameEnds,
202 // scanner.currentPosition - 1);
204 // requestor.enterClass(
205 // typeDecl.declarationSourceStart,
206 // intArrayStack[intArrayPtr--],
207 // typeDecl.modifiers,
208 // typeDecl.modifiersSourceStart,
209 // typeStartPosition,
211 // typeDecl.sourceStart,
212 // typeDecl.sourceEnd,
213 // CharOperation.concatWith(superclass.getTypeName(), '.'),
214 // superclass.sourceStart,
215 // superclass.sourceEnd,
217 // interfaceNameStarts,
218 // interfaceNameEnds,
219 // scanner.currentPosition - 1);
223 //protected void consumeClassHeaderName() {
224 // // ClassHeaderName ::= Modifiersopt 'class' 'Identifier'
225 // TypeDeclaration typeDecl;
226 // if (nestedMethod[nestedType] == 0) {
227 // if (nestedType != 0) {
228 // typeDecl = new MemberTypeDeclaration(this.compilationUnit.compilationResult);
230 // typeDecl = new TypeDeclaration(this.compilationUnit.compilationResult);
233 // // Record that the block has a declaration for local types
234 // typeDecl = new LocalTypeDeclaration(this.compilationUnit.compilationResult);
235 // markEnclosingMemberWithLocalType();
239 // //highlight the name of the type
240 // long pos = identifierPositionStack[identifierPtr];
241 // typeDecl.sourceEnd = (int) pos;
242 // typeDecl.sourceStart = (int) (pos >>> 32);
243 // typeDecl.name = identifierStack[identifierPtr--];
244 // identifierLengthPtr--;
246 // //compute the declaration source too
247 // // 'class' and 'interface' push an int position
248 // typeStartPosition = typeDecl.declarationSourceStart = intStack[intPtr--];
250 // int declarationSourceStart = intStack[intPtr--];
251 // typeDecl.modifiersSourceStart = intStack[intPtr--];
252 // typeDecl.modifiers = intStack[intPtr--];
253 // if (typeDecl.declarationSourceStart > declarationSourceStart) {
254 // typeDecl.declarationSourceStart = declarationSourceStart;
256 // typeDecl.bodyStart = typeDecl.sourceEnd + 1;
257 // pushOnAstStack(typeDecl);
261 // * INTERNAL USE-ONLY
263 //protected void consumeCompilationUnit() {
264 // // CompilationUnit ::= EnterCompilationUnit PackageDeclarationopt ImportDeclarationsopt
265 // requestor.exitCompilationUnit(scanner.source.length - 1);
271 //protected void consumeConstructorDeclaration() {
272 // // ConstructorDeclaration ::= ConstructorHeader ConstructorBody
273 // super.consumeConstructorDeclaration();
274 // if (isLocalDeclaration()) {
275 // // we ignore the local variable declarations
278 // ConstructorDeclaration cd = (ConstructorDeclaration) astStack[astPtr];
279 // requestor.exitConstructor(endStatementPosition, cd.declarationSourceEnd);
283 // * INTERNAL USE-ONLY
285 //protected void consumeConstructorHeader() {
286 // // ConstructorHeader ::= ConstructorHeaderName MethodHeaderParameters MethodHeaderThrowsClauseopt
287 // super.consumeConstructorHeader();
288 // if (isLocalDeclaration()) {
289 // // we ignore the local variable declarations
293 // ConstructorDeclaration cd = (ConstructorDeclaration) astStack[astPtr];
294 // Argument[] arguments = cd.arguments;
295 // char[][] argumentTypes = null;
296 // char[][] argumentNames = null;
297 // int[] argumentTypeStarts = null;
298 // int[] argumentTypeEnds = null;
299 // int[] argumentNameStarts = null;
300 // int[] argumentNameEnds = null;
301 // if (arguments != null) {
302 // int argumentLength = arguments.length;
303 // argumentTypes = new char[argumentLength][];
304 // argumentNames = new char[argumentLength][];
305 // argumentNameStarts = new int[argumentLength];
306 // argumentNameEnds = new int[argumentLength];
307 // argumentTypeStarts = new int[argumentLength];
308 // argumentTypeEnds = new int[argumentLength];
309 // for (int i = 0; i < argumentLength; i++) {
310 // Argument argument = arguments[i];
311 // TypeReference argumentType = argument.type;
312 // argumentTypes[i] = returnTypeName(argumentType);
313 // argumentNames[i] = argument.name;
314 // argumentNameStarts[i] = argument.sourceStart;
315 // argumentNameEnds[i] = argument.sourceEnd;
316 // argumentTypeStarts[i] = argumentType.sourceStart;
317 // argumentTypeEnds[i] = argumentType.sourceEnd;
320 // TypeReference[] thrownExceptions = cd.thrownExceptions;
321 // char[][] exceptionTypes = null;
322 // int[] exceptionTypeStarts = null;
323 // int[] exceptionTypeEnds = null;
324 // if (thrownExceptions != null) {
325 // int thrownExceptionLength = thrownExceptions.length;
326 // exceptionTypes = new char[thrownExceptionLength][];
327 // exceptionTypeStarts = new int[thrownExceptionLength];
328 // exceptionTypeEnds = new int[thrownExceptionLength];
329 // for (int i = 0; i < thrownExceptionLength; i++) {
330 // TypeReference exception = thrownExceptions[i];
331 // exceptionTypes[i] = CharOperation.concatWith(exception.getTypeName(), '.');
332 // exceptionTypeStarts[i] = exception.sourceStart;
333 // exceptionTypeEnds[i] = exception.sourceEnd;
337 // .enterConstructor(
338 // cd.declarationSourceStart,
339 // intArrayStack[intArrayPtr--],
341 // cd.modifiersSourceStart,
344 // (int) (selectorSourcePositions & 0xFFFFFFFFL),
345 // // retrieve the source end of the name
347 // argumentTypeStarts,
350 // argumentNameStarts,
353 // // right parenthesis
355 // exceptionTypeStarts,
356 // exceptionTypeEnds,
357 // scanner.currentPosition - 1);
359 //protected void consumeConstructorHeaderName() {
360 // // ConstructorHeaderName ::= Modifiersopt 'Identifier' '('
361 // ConstructorDeclaration cd = new ConstructorDeclaration(this.compilationUnit.compilationResult);
363 // //name -- this is not really revelant but we do .....
364 // cd.selector = identifierStack[identifierPtr];
365 // selectorSourcePositions = identifierPositionStack[identifierPtr--];
366 // identifierLengthPtr--;
369 // cd.declarationSourceStart = intStack[intPtr--];
370 // cd.modifiersSourceStart = intStack[intPtr--];
371 // cd.modifiers = intStack[intPtr--];
373 // //highlight starts at the selector starts
374 // cd.sourceStart = (int) (selectorSourcePositions >>> 32);
375 // pushOnAstStack(cd);
377 // cd.sourceEnd = lParenPos;
378 // cd.bodyStart = lParenPos + 1;
380 //protected void consumeDefaultModifiers() {
381 // checkAnnotation(); // might update modifiers with AccDeprecated
382 // pushOnIntStack(modifiers); // modifiers
383 // pushOnIntStack(-1);
385 // declarationSourceStart >= 0 ? declarationSourceStart : scanner.startPosition);
388 //protected void consumeDiet() {
389 // // Diet ::= $empty
390 // super.consumeDiet();
391 // /* persisting javadoc positions
392 // * Will be consume in consumeClassBodyDeclaration
394 // pushOnIntArrayStack(this.getJavaDocPositions());
398 // * INTERNAL USE-ONLY
400 //protected void consumeEnterCompilationUnit() {
401 // // EnterCompilationUnit ::= $empty
402 // requestor.enterCompilationUnit();
406 // * INTERNAL USE-ONLY
408 //protected void consumeEnterVariable() {
409 // // EnterVariable ::= $empty
410 // boolean isLocalDeclaration = isLocalDeclaration();
411 // if (!isLocalDeclaration && (variablesCounter[nestedType] != 0)) {
412 // requestor.exitField(lastFieldBodyEndPosition, lastFieldEndPosition);
414 // char[] name = identifierStack[identifierPtr];
415 // long namePosition = identifierPositionStack[identifierPtr--];
416 // int extendedTypeDimension = intStack[intPtr--];
418 // AbstractVariableDeclaration declaration;
419 // if (nestedMethod[nestedType] != 0) {
420 // // create the local variable declarations
422 // new LocalDeclaration(null, name, (int) (namePosition >>> 32), (int) namePosition);
424 // // create the field declaration
426 // new FieldDeclaration(null, name, (int) (namePosition >>> 32), (int) namePosition);
428 // identifierLengthPtr--;
429 // TypeReference type;
430 // int variableIndex = variablesCounter[nestedType];
432 // if (variableIndex == 0) {
433 // // first variable of the declaration (FieldDeclaration or LocalDeclaration)
434 // if (nestedMethod[nestedType] != 0) {
435 // // local declaration
436 // declaration.declarationSourceStart = intStack[intPtr--];
437 // declaration.modifiersSourceStart = intStack[intPtr--];
438 // declaration.modifiers = intStack[intPtr--];
439 // type = getTypeReference(typeDim = intStack[intPtr--]); // type dimension
440 // pushOnAstStack(type);
442 // // field declaration
443 // type = getTypeReference(typeDim = intStack[intPtr--]); // type dimension
444 // pushOnAstStack(type);
445 // declaration.declarationSourceStart = intStack[intPtr--];
446 // declaration.modifiersSourceStart = intStack[intPtr--];
447 // declaration.modifiers = intStack[intPtr--];
450 // type = (TypeReference) astStack[astPtr - variableIndex];
451 // typeDim = type.dimensions();
452 // AbstractVariableDeclaration previousVariable =
453 // (AbstractVariableDeclaration) astStack[astPtr];
454 // declaration.declarationSourceStart = previousVariable.declarationSourceStart;
455 // declaration.modifiers = previousVariable.modifiers;
456 // declaration.modifiersSourceStart = previousVariable.modifiersSourceStart;
459 // localIntPtr = intPtr;
461 // if (extendedTypeDimension == 0) {
462 // declaration.type = type;
464 // int dimension = typeDim + extendedTypeDimension;
465 // //on the identifierLengthStack there is the information about the type....
467 // if ((baseType = identifierLengthStack[identifierLengthPtr + 1]) < 0) {
468 // //it was a baseType
469 // declaration.type = TypeReference.baseTypeReference(-baseType, dimension);
470 // declaration.type.sourceStart = type.sourceStart;
471 // declaration.type.sourceEnd = type.sourceEnd;
473 // declaration.type = this.copyDims(type, dimension);
476 // variablesCounter[nestedType]++;
477 // nestedMethod[nestedType]++;
478 // pushOnAstStack(declaration);
480 // int[] javadocPositions = intArrayStack[intArrayPtr];
481 // if (!isLocalDeclaration) {
484 // declaration.declarationSourceStart,
486 // declaration.modifiers,
487 // declaration.modifiersSourceStart,
488 // returnTypeName(declaration.type),
493 // (int) (namePosition >>> 32),
494 // (int) namePosition,
495 // extendedTypeDimension,
496 // extendedTypeDimension == 0 ? -1 : endPosition);
501 // * INTERNAL USE-ONLY
503 //protected void consumeExitVariableWithInitialization() {
504 // // ExitVariableWithInitialization ::= $empty
505 // // the scanner is located after the comma or the semi-colon.
506 // // we want to include the comma or the semi-colon
507 // super.consumeExitVariableWithInitialization();
508 // nestedMethod[nestedType]--;
509 // lastFieldEndPosition = scanner.currentPosition - 1;
510 // lastFieldBodyEndPosition = ((AbstractVariableDeclaration) astStack[astPtr]).initialization.sourceEnd;
512 //protected void consumeExitVariableWithoutInitialization() {
513 // // ExitVariableWithoutInitialization ::= $empty
514 // // do nothing by default
515 // super.consumeExitVariableWithoutInitialization();
516 // nestedMethod[nestedType]--;
517 // lastFieldEndPosition = scanner.currentPosition - 1;
518 // lastFieldBodyEndPosition = scanner.startPosition - 1;
522 // * INTERNAL USE-ONLY
524 //protected void consumeFieldDeclaration() {
525 // // See consumeLocalVariableDeclarationDefaultModifier() in case of change: duplicated code
526 // // FieldDeclaration ::= Modifiersopt Type VariableDeclarators ';'
527 // // the super.consumeFieldDeclaration will reinitialize the variableCounter[nestedType]
528 // int variableIndex = variablesCounter[nestedType];
529 // super.consumeFieldDeclaration();
531 // if (isLocalDeclaration())
533 // if (variableIndex != 0) {
534 // requestor.exitField(lastFieldBodyEndPosition, lastFieldEndPosition);
537 //protected void consumeFormalParameter() {
538 // // FormalParameter ::= Type VariableDeclaratorId ==> false
539 // // FormalParameter ::= Modifiers Type VariableDeclaratorId ==> true
542 // identifierStack : type identifier
543 // intStack : dim dim
545 // astStack : Argument
550 // identifierLengthPtr--;
551 // char[] name = identifierStack[identifierPtr];
552 // long namePositions = identifierPositionStack[identifierPtr--];
553 // TypeReference type = getTypeReference(intStack[intPtr--] + intStack[intPtr--]);
560 // intStack[intPtr + 1]); // modifiers
561 // pushOnAstStack(arg);
566 // * INTERNAL USE-ONLY
568 //protected void consumeInterfaceDeclaration() {
569 // super.consumeInterfaceDeclaration();
570 // // we know that we have a TypeDeclaration on the top of the astStack
571 // if (isLocalDeclaration()) {
572 // // we ignore the local variable declarations
575 // requestor.exitInterface(endStatementPosition, // the '}' is the end of the body
576 // ((TypeDeclaration) astStack[astPtr]).declarationSourceEnd);
580 // * INTERNAL USE-ONLY
582 //protected void consumeInterfaceHeader() {
583 // //InterfaceHeader ::= $empty
584 // super.consumeInterfaceHeader();
585 // if (isLocalDeclaration()) {
586 // // we ignore the local variable declarations
590 // TypeDeclaration typeDecl = (TypeDeclaration) astStack[astPtr];
591 // TypeReference[] superInterfaces = typeDecl.superInterfaces;
592 // char[][] interfaceNames = null;
593 // int[] interfaceNameStarts = null;
594 // int[] interfacenameEnds = null;
595 // int superInterfacesLength = 0;
596 // if (superInterfaces != null) {
597 // superInterfacesLength = superInterfaces.length;
598 // interfaceNames = new char[superInterfacesLength][];
599 // interfaceNameStarts = new int[superInterfacesLength];
600 // interfacenameEnds = new int[superInterfacesLength];
602 // if (superInterfaces != null) {
603 // for (int i = 0; i < superInterfacesLength; i++) {
604 // TypeReference superInterface = superInterfaces[i];
605 // interfaceNames[i] = CharOperation.concatWith(superInterface.getTypeName(), '.');
606 // interfaceNameStarts[i] = superInterface.sourceStart;
607 // interfacenameEnds[i] = superInterface.sourceEnd;
610 // // flush the comments related to the interface header
611 // scanner.commentPtr = -1;
612 // requestor.enterInterface(
613 // typeDecl.declarationSourceStart,
614 // intArrayStack[intArrayPtr--],
615 // typeDecl.modifiers,
616 // typeDecl.modifiersSourceStart,
617 // typeStartPosition,
619 // typeDecl.sourceStart,
620 // typeDecl.sourceEnd,
622 // interfaceNameStarts,
623 // interfacenameEnds,
624 // scanner.currentPosition - 1);
626 //protected void consumeInterfaceHeaderName() {
627 // // InterfaceHeaderName ::= Modifiersopt 'interface' 'Identifier'
628 // TypeDeclaration typeDecl;
629 // if (nestedMethod[nestedType] == 0) {
630 // if (nestedType != 0) {
631 // typeDecl = new MemberTypeDeclaration(this.compilationUnit.compilationResult);
633 // typeDecl = new TypeDeclaration(this.compilationUnit.compilationResult);
636 // // Record that the block has a declaration for local types
637 // typeDecl = new LocalTypeDeclaration(this.compilationUnit.compilationResult);
638 // markEnclosingMemberWithLocalType();
642 // //highlight the name of the type
643 // long pos = identifierPositionStack[identifierPtr];
644 // typeDecl.sourceEnd = (int) pos;
645 // typeDecl.sourceStart = (int) (pos >>> 32);
646 // typeDecl.name = identifierStack[identifierPtr--];
647 // identifierLengthPtr--;
649 // //compute the declaration source too
650 // // 'class' and 'interface' push an int position
651 // typeStartPosition = typeDecl.declarationSourceStart = intStack[intPtr--];
653 // int declarationSourceStart = intStack[intPtr--];
654 // typeDecl.modifiersSourceStart = intStack[intPtr--];
655 // typeDecl.modifiers = intStack[intPtr--];
656 // if (typeDecl.declarationSourceStart > declarationSourceStart) {
657 // typeDecl.declarationSourceStart = declarationSourceStart;
659 // typeDecl.bodyStart = typeDecl.sourceEnd + 1;
660 // pushOnAstStack(typeDecl);
664 // * INTERNAL USE-ONLY
666 //protected void consumeLocalVariableDeclaration() {
667 // // See consumeLocalVariableDeclarationDefaultModifier() in case of change: duplicated code
668 // // FieldDeclaration ::= Modifiersopt Type VariableDeclarators ';'
670 // super.consumeLocalVariableDeclaration();
675 // * INTERNAL USE-ONLY
677 //protected void consumeMethodDeclaration(boolean isNotAbstract) {
678 // // MethodDeclaration ::= MethodHeader MethodBody
679 // // AbstractMethodDeclaration ::= MethodHeader ';'
680 // super.consumeMethodDeclaration(isNotAbstract);
681 // if (isLocalDeclaration()) {
682 // // we ignore the local variable declarations
685 // MethodDeclaration md = (MethodDeclaration) astStack[astPtr];
686 // requestor.exitMethod(endStatementPosition, md.declarationSourceEnd);
690 // * INTERNAL USE-ONLY
692 //protected void consumeMethodHeader() {
693 // // MethodHeader ::= MethodHeaderName MethodHeaderParameters MethodHeaderExtendedDims ThrowsClauseopt
694 // super.consumeMethodHeader();
695 // if (isLocalDeclaration()) {
696 // // we ignore the local variable declarations
700 // MethodDeclaration md = (MethodDeclaration) astStack[astPtr];
702 // TypeReference returnType = md.returnType;
703 // char[] returnTypeName = returnTypeName(returnType);
704 // Argument[] arguments = md.arguments;
705 // char[][] argumentTypes = null;
706 // char[][] argumentNames = null;
707 // int[] argumentTypeStarts = null;
708 // int[] argumentTypeEnds = null;
709 // int[] argumentNameStarts = null;
710 // int[] argumentNameEnds = null;
711 // if (arguments != null) {
712 // int argumentLength = arguments.length;
713 // argumentTypes = new char[argumentLength][];
714 // argumentNames = new char[argumentLength][];
715 // argumentNameStarts = new int[argumentLength];
716 // argumentNameEnds = new int[argumentLength];
717 // argumentTypeStarts = new int[argumentLength];
718 // argumentTypeEnds = new int[argumentLength];
719 // for (int i = 0; i < argumentLength; i++) {
720 // Argument argument = arguments[i];
721 // TypeReference argumentType = argument.type;
722 // argumentTypes[i] = returnTypeName(argumentType);
723 // argumentNames[i] = argument.name;
724 // argumentNameStarts[i] = argument.sourceStart;
725 // argumentNameEnds[i] = argument.sourceEnd;
726 // argumentTypeStarts[i] = argumentType.sourceStart;
727 // argumentTypeEnds[i] = argumentType.sourceEnd;
730 // TypeReference[] thrownExceptions = md.thrownExceptions;
731 // char[][] exceptionTypes = null;
732 // int[] exceptionTypeStarts = null;
733 // int[] exceptionTypeEnds = null;
734 // if (thrownExceptions != null) {
735 // int thrownExceptionLength = thrownExceptions.length;
736 // exceptionTypeStarts = new int[thrownExceptionLength];
737 // exceptionTypeEnds = new int[thrownExceptionLength];
738 // exceptionTypes = new char[thrownExceptionLength][];
739 // for (int i = 0; i < thrownExceptionLength; i++) {
740 // TypeReference exception = thrownExceptions[i];
741 // exceptionTypes[i] = CharOperation.concatWith(exception.getTypeName(), '.');
742 // exceptionTypeStarts[i] = exception.sourceStart;
743 // exceptionTypeEnds[i] = exception.sourceEnd;
748 // md.declarationSourceStart,
749 // intArrayStack[intArrayPtr--],
751 // md.modifiersSourceStart,
753 // returnType.sourceStart,
754 // returnType.sourceEnd,
758 // (int) (selectorSourcePositions & 0xFFFFFFFFL),
760 // argumentTypeStarts,
763 // argumentNameStarts,
767 // extendsDim == 0 ? -1 : endPosition,
769 // exceptionTypeStarts,
770 // exceptionTypeEnds,
771 // scanner.currentPosition - 1);
773 //protected void consumeMethodHeaderExtendedDims() {
774 // // MethodHeaderExtendedDims ::= Dimsopt
775 // // now we update the returnType of the method
776 // MethodDeclaration md = (MethodDeclaration) astStack[astPtr];
777 // int extendedDims = intStack[intPtr--];
778 // extendsDim = extendedDims;
779 // if (extendedDims != 0) {
780 // TypeReference returnType = md.returnType;
781 // md.sourceEnd = endPosition;
782 // int dims = returnType.dimensions() + extendedDims;
784 // if ((baseType = identifierLengthStack[identifierLengthPtr + 1]) < 0) {
785 // //it was a baseType
786 // int sourceStart = returnType.sourceStart;
787 // int sourceEnd = returnType.sourceEnd;
788 // returnType = TypeReference.baseTypeReference(-baseType, dims);
789 // returnType.sourceStart = sourceStart;
790 // returnType.sourceEnd = sourceEnd;
791 // md.returnType = returnType;
793 // md.returnType = this.copyDims(md.returnType, dims);
795 // if (currentToken == TokenNameLBRACE) {
796 // md.bodyStart = endPosition + 1;
800 //protected void consumeMethodHeaderName() {
801 // // MethodHeaderName ::= Modifiersopt Type 'Identifier' '('
802 // MethodDeclaration md = new MethodDeclaration(this.compilationUnit.compilationResult);
805 // md.selector = identifierStack[identifierPtr];
806 // selectorSourcePositions = identifierPositionStack[identifierPtr--];
807 // identifierLengthPtr--;
809 // md.returnType = getTypeReference(typeDims = intStack[intPtr--]);
811 // md.declarationSourceStart = intStack[intPtr--];
812 // md.modifiersSourceStart = intStack[intPtr--];
813 // md.modifiers = intStack[intPtr--];
815 // //highlight starts at selector start
816 // md.sourceStart = (int) (selectorSourcePositions >>> 32);
817 // pushOnAstStack(md);
818 // md.bodyStart = scanner.currentPosition-1;
820 //protected void consumeModifiers() {
821 // checkAnnotation(); // might update modifiers with AccDeprecated
822 // pushOnIntStack(modifiers); // modifiers
823 // pushOnIntStack(modifiersSourceStart);
825 // declarationSourceStart >= 0 ? declarationSourceStart : modifiersSourceStart);
832 //protected void consumePackageDeclarationName() {
833 // /* persisting javadoc positions */
834 // pushOnIntArrayStack(this.getJavaDocPositions());
836 // super.consumePackageDeclarationName();
837 // ImportReference importReference = compilationUnit.currentPackage;
839 // requestor.acceptPackage(
840 // importReference.declarationSourceStart,
841 // importReference.declarationSourceEnd,
842 // intArrayStack[intArrayPtr--],
843 // CharOperation.concatWith(importReference.getImportName(), '.'),
844 // importReference.sourceStart);
846 //protected void consumePushModifiers() {
847 // checkAnnotation(); // might update modifiers with AccDeprecated
848 // pushOnIntStack(modifiers); // modifiers
849 // if (modifiersSourceStart < 0) {
850 // pushOnIntStack(-1);
852 // declarationSourceStart >= 0 ? declarationSourceStart : scanner.startPosition);
854 // pushOnIntStack(modifiersSourceStart);
856 // declarationSourceStart >= 0 ? declarationSourceStart : modifiersSourceStart);
862 // * INTERNAL USE-ONLY
864 //protected void consumeSingleTypeImportDeclarationName() {
865 // // SingleTypeImportDeclarationName ::= 'import' Name
867 // /* persisting javadoc positions */
868 // pushOnIntArrayStack(this.getJavaDocPositions());
870 // super.consumeSingleTypeImportDeclarationName();
871 // ImportReference importReference = (ImportReference) astStack[astPtr];
872 // requestor.acceptImport(
873 // importReference.declarationSourceStart,
874 // importReference.declarationSourceEnd,
875 // intArrayStack[intArrayPtr--],
876 // CharOperation.concatWith(importReference.getImportName(), '.'),
877 // importReference.sourceStart,
882 // * INTERNAL USE-ONLY
884 //protected void consumeStaticInitializer() {
885 // // StaticInitializer ::= StaticOnly Block
886 // //push an Initializer
887 // //optimize the push/pop
888 // super.consumeStaticInitializer();
889 // Initializer initializer = (Initializer) astStack[astPtr];
890 // requestor.acceptInitializer(
891 // initializer.declarationSourceStart,
892 // initializer.declarationSourceEnd,
893 // intArrayStack[intArrayPtr--],
895 // intStack[intPtr--],
896 // initializer.block.sourceStart,
897 // initializer.declarationSourceEnd);
899 //protected void consumeStaticOnly() {
900 // // StaticOnly ::= 'static'
901 // checkAnnotation(); // might update declaration source start
902 // pushOnIntStack(modifiersSourceStart);
904 // declarationSourceStart >= 0 ? declarationSourceStart : modifiersSourceStart);
905 // jumpOverMethodBody();
906 // nestedMethod[nestedType]++;
911 // * INTERNAL USE-ONLY
913 //protected void consumeTypeImportOnDemandDeclarationName() {
914 // // TypeImportOnDemandDeclarationName ::= 'import' Name '.' '*'
916 // /* persisting javadoc positions */
917 // pushOnIntArrayStack(this.getJavaDocPositions());
919 // super.consumeTypeImportOnDemandDeclarationName();
920 // ImportReference importReference = (ImportReference) astStack[astPtr];
921 // requestor.acceptImport(
922 // importReference.declarationSourceStart,
923 // importReference.declarationSourceEnd,
924 // intArrayStack[intArrayPtr--],
925 // CharOperation.concatWith(importReference.getImportName(), '.'),
926 // importReference.sourceStart,
929 public CompilationUnitDeclaration endParse(int act) {
930 if (scanner.recordLineSeparator) {
931 requestor.acceptLineSeparatorPositions(scanner.getLineEnds());
933 return super.endParse(act);
937 * Flush annotations defined prior to a given positions.
939 * Note: annotations are stacked in syntactical order
941 * Either answer given <position>, or the end position of a comment line immediately following the <position> (same line)
943 * e.g. void foo(){ } // end of method foo
946 //public int flushAnnotationsDefinedPriorTo(int position) {
948 // return lastFieldEndPosition = super.flushAnnotationsDefinedPriorTo(position);
950 //protected TypeReference getTypeReference(int dim) { /* build a Reference on a variable that may be qualified or not
951 //This variable is a type reference and dim will be its dimensions*/
954 // TypeReference ref;
955 // if ((length = identifierLengthStack[identifierLengthPtr--]) == 1) {
956 // // single variable reference
959 // new SingleTypeReference(
960 // identifierStack[identifierPtr],
961 // identifierPositionStack[identifierPtr--]);
964 // new ArrayTypeReference(
965 // identifierStack[identifierPtr],
967 // identifierPositionStack[identifierPtr--]);
968 // ref.sourceEnd = endPosition;
971 // if (length < 0) { //flag for precompiled type reference on base types
972 // ref = TypeReference.baseTypeReference(-length, dim);
973 // ref.sourceStart = intStack[intPtr--];
975 // ref.sourceEnd = intStack[intPtr--];
978 // ref.sourceEnd = endPosition;
980 // } else { //Qualified variable reference
981 // char[][] tokens = new char[length][];
982 // identifierPtr -= length;
983 // long[] positions = new long[length];
984 // System.arraycopy(identifierStack, identifierPtr + 1, tokens, 0, length);
986 // identifierPositionStack,
987 // identifierPtr + 1,
992 // ref = new QualifiedTypeReference(tokens, positions);
994 // ref = new ArrayQualifiedTypeReference(tokens, dim, positions);
995 // ref.sourceEnd = endPosition;
1001 public void initialize() {
1002 //positionning the parser for a new compilation unit
1003 //avoiding stack reallocation and all that....
1004 super.initialize(false);
1012 //private boolean isLocalDeclaration() {
1013 // int nestedDepth = nestedType;
1014 // while (nestedDepth >= 0) {
1015 // if (nestedMethod[nestedDepth] != 0) {
1023 * Investigate one entire unit.
1025 public void parseCompilationUnit(ICompilationUnit unit) {
1026 char[] regionSource = unit.getContents();
1029 goForCompilationUnit();
1030 referenceContext = compilationUnit = new CompilationUnitDeclaration(problemReporter(),
1031 new CompilationResult(unit, 0, 0, 10), //this.options.maxProblemsPerUnit),
1032 regionSource.length);
1033 scanner.resetTo(0, regionSource.length);
1034 scanner.setSource(regionSource);
1036 } catch (AbortCompilation ex) {
1041 * Investigate one constructor declaration.
1043 //public void parseConstructor(char[] regionSource) {
1046 // goForClassBodyDeclarations();
1047 // referenceContext =
1048 // compilationUnit =
1049 // compilationUnit =
1050 // new CompilationUnitDeclaration(
1051 // problemReporter(),
1052 // new CompilationResult(regionSource, 0, 0, 10), //this.options.maxProblemsPerUnit),
1053 // regionSource.length);
1054 // scanner.resetTo(0, regionSource.length);
1055 // scanner.setSource(regionSource);
1057 // } catch (AbortCompilation ex) {
1061 * Investigate one field declaration statement (might have multiple declarations in it).
1063 //public void parseField(char[] regionSource) {
1066 // goForFieldDeclaration();
1067 // referenceContext =
1068 // compilationUnit =
1069 // compilationUnit =
1070 // new CompilationUnitDeclaration(
1071 // problemReporter(),
1072 // new CompilationResult(regionSource, 0, 0, this.options.maxProblemsPerUnit),
1073 // regionSource.length);
1074 // scanner.resetTo(0, regionSource.length);
1075 // scanner.setSource(regionSource);
1077 // } catch (AbortCompilation ex) {
1082 // * Investigate one import statement declaration.
1084 //public void parseImport(char[] regionSource) {
1087 // goForImportDeclaration();
1088 // referenceContext =
1089 // compilationUnit =
1090 // compilationUnit =
1091 // new CompilationUnitDeclaration(
1092 // problemReporter(),
1093 // new CompilationResult(regionSource, 0, 0, this.options.maxProblemsPerUnit),
1094 // regionSource.length);
1095 // scanner.resetTo(0, regionSource.length);
1096 // scanner.setSource(regionSource);
1098 // } catch (AbortCompilation ex) {
1103 // * Investigate one initializer declaration.
1104 // * regionSource need to content exactly an initializer declaration.
1105 // * e.g: static { i = 4; }
1106 // * { name = "test"; }
1108 //public void parseInitializer(char[] regionSource) {
1111 // goForInitializer();
1112 // referenceContext =
1113 // compilationUnit =
1114 // compilationUnit =
1115 // new CompilationUnitDeclaration(
1116 // problemReporter(),
1117 // new CompilationResult(regionSource, 0, 0, this.options.maxProblemsPerUnit),
1118 // regionSource.length);
1119 // scanner.resetTo(0, regionSource.length);
1120 // scanner.setSource(regionSource);
1122 // } catch (AbortCompilation ex) {
1127 // * Investigate one method declaration.
1129 //public void parseMethod(char[] regionSource) {
1132 // goForGenericMethodDeclaration();
1133 // referenceContext =
1134 // compilationUnit =
1135 // compilationUnit =
1136 // new CompilationUnitDeclaration(
1137 // problemReporter(),
1138 // new CompilationResult(regionSource, 0, 0, this.options.maxProblemsPerUnit),
1139 // regionSource.length);
1140 // scanner.resetTo(0, regionSource.length);
1141 // scanner.setSource(regionSource);
1143 // } catch (AbortCompilation ex) {
1148 // * Investigate one package statement declaration.
1150 //public void parsePackage(char[] regionSource) {
1153 // goForPackageDeclaration();
1154 // referenceContext =
1155 // compilationUnit =
1156 // compilationUnit =
1157 // new CompilationUnitDeclaration(
1158 // problemReporter(),
1159 // new CompilationResult(regionSource, 0, 0, this.options.maxProblemsPerUnit),
1160 // regionSource.length);
1161 // scanner.resetTo(0, regionSource.length);
1162 // scanner.setSource(regionSource);
1164 // } catch (AbortCompilation ex) {
1169 // * Investigate one type declaration, its fields, methods and member types.
1171 //public void parseType(char[] regionSource) {
1174 // goForTypeDeclaration();
1175 // referenceContext =
1176 // compilationUnit =
1177 // compilationUnit =
1178 // new CompilationUnitDeclaration(
1179 // problemReporter(),
1180 // new CompilationResult(regionSource, 0, 0, this.options.maxProblemsPerUnit),
1181 // regionSource.length);
1182 // scanner.resetTo(0, regionSource.length);
1183 // scanner.setSource(regionSource);
1185 // } catch (AbortCompilation ex) {
1190 * Returns this parser's problem reporter initialized with its reference context. Also it is assumed that a problem is going to be
1191 * reported, so initializes the compilation result's line positions.
1193 public ProblemReporter problemReporter() {
1194 problemReporter.referenceContext = referenceContext;
1195 return problemReporter;
1198 protected void pushOnIntArrayStack(int[] positions) {
1201 intArrayStack[++intArrayPtr] = positions;
1202 } catch (IndexOutOfBoundsException e) {
1204 int oldStackLength = intArrayStack.length;
1205 int oldStack[][] = intArrayStack;
1206 intArrayStack = new int[oldStackLength + StackIncrement][];
1207 System.arraycopy(oldStack, 0, intArrayStack, 0, oldStackLength);
1208 intArrayStack[intArrayPtr] = positions;
1212 //protected void resetModifiers() {
1213 // super.resetModifiers();
1214 // declarationSourceStart = -1;
1217 * Syntax error was detected. Will attempt to perform some recovery action in order to resume to the regular parse loop.
1219 protected boolean resumeOnSyntaxError() {
1223 * Answer a char array representation of the type name formatted like: - type name + dimensions Example: "A[][]".toCharArray()
1224 * "java.lang.String".toCharArray()
1226 //private char[] returnTypeName(TypeReference type) {
1227 // int dimension = type.dimensions();
1228 // if (dimension != 0) {
1229 // char[] dimensionsArray = new char[dimension * 2];
1230 // for (int i = 0; i < dimension; i++) {
1231 // dimensionsArray[i*2] = '[';
1232 // dimensionsArray[(i*2) + 1] = ']';
1234 // return CharOperation.concat(
1235 // CharOperation.concatWith(type.getTypeName(), '.'),
1236 // dimensionsArray);
1238 // return CharOperation.concatWith(type.getTypeName(), '.');
1240 //public String toString() {
1241 // StringBuffer buffer = new StringBuffer();
1242 // buffer.append("intArrayPtr = " + intArrayPtr + "\n"); //$NON-NLS-1$ //$NON-NLS-2$
1243 // buffer.append(super.toString());
1244 // return buffer.toString();
1247 // * INTERNAL USE ONLY
1249 //protected TypeReference typeReference(
1251 // int localIdentifierPtr,
1252 // int localIdentifierLengthPtr) {
1253 // /* build a Reference on a variable that may be qualified or not
1254 // * This variable is a type reference and dim will be its dimensions.
1255 // * We don't have any side effect on the stacks' pointers.
1259 // TypeReference ref;
1260 // if ((length = identifierLengthStack[localIdentifierLengthPtr]) == 1) {
1261 // // single variable reference
1264 // new SingleTypeReference(
1265 // identifierStack[localIdentifierPtr],
1266 // identifierPositionStack[localIdentifierPtr--]);
1269 // new ArrayTypeReference(
1270 // identifierStack[localIdentifierPtr],
1272 // identifierPositionStack[localIdentifierPtr--]);
1273 // ref.sourceEnd = endPosition;
1276 // if (length < 0) { //flag for precompiled type reference on base types
1277 // ref = TypeReference.baseTypeReference(-length, dim);
1278 // ref.sourceStart = intStack[localIntPtr--];
1280 // ref.sourceEnd = intStack[localIntPtr--];
1283 // ref.sourceEnd = endPosition;
1285 // } else { //Qualified variable reference
1286 // char[][] tokens = new char[length][];
1287 // localIdentifierPtr -= length;
1288 // long[] positions = new long[length];
1289 // System.arraycopy(identifierStack, localIdentifierPtr + 1, tokens, 0, length);
1290 // System.arraycopy(
1291 // identifierPositionStack,
1292 // localIdentifierPtr + 1,
1297 // ref = new QualifiedTypeReference(tokens, positions);
1299 // ref = new ArrayQualifiedTypeReference(tokens, dim, positions);