1 11 package org.eclipse.jdt.internal.compiler; 12 13 import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; 14 import org.eclipse.jdt.internal.compiler.env.*; 15 16 import org.eclipse.jdt.internal.compiler.impl.*; 17 import org.eclipse.jdt.core.compiler.*; 18 import org.eclipse.jdt.internal.compiler.ast.*; 19 import org.eclipse.jdt.internal.compiler.parser.*; 20 import org.eclipse.jdt.internal.compiler.problem.*; 21 22 public class DocumentElementParser extends Parser { 23 IDocumentElementRequestor requestor; 24 private int localIntPtr; 25 private int lastFieldEndPosition; 26 private int lastFieldBodyEndPosition; 27 private int typeStartPosition; 28 private long selectorSourcePositions; 29 private int typeDims; 30 private int extendsDim; 31 private int declarationSourceStart; 32 33 34 int[][] intArrayStack; 35 int intArrayPtr; 36 37 public DocumentElementParser( 38 final IDocumentElementRequestor requestor, 39 IProblemFactory problemFactory, 40 CompilerOptions options) { 41 super(new ProblemReporter( 42 DefaultErrorHandlingPolicies.exitAfterAllProblems(), 43 options, 44 problemFactory), 45 false); 46 this.requestor = requestor; 47 intArrayStack = new int[30][]; 48 this.options = options; 49 this.javadocParser.checkDocComment = false; 50 51 this.setMethodsFullRecovery(false); 52 this.setStatementsRecovery(false); 53 } 54 61 public void checkComment() { 62 63 64 pushOnIntArrayStack(this.getJavaDocPositions()); 65 boolean deprecated = false; 66 int lastCommentIndex = -1; 67 int commentPtr = scanner.commentPtr; 68 69 nextComment : for (lastCommentIndex = scanner.commentPtr; lastCommentIndex >= 0; lastCommentIndex--){ 71 int commentSourceStart = scanner.commentStarts[lastCommentIndex]; 73 if (modifiersSourceStart != -1 && modifiersSourceStart < commentSourceStart) { 75 continue nextComment; 76 } 77 if (scanner.commentStops[lastCommentIndex] < 0) { 78 continue nextComment; 79 } 80 deprecated = 81 this.javadocParser.checkDeprecation(lastCommentIndex); 82 break nextComment; 83 } 84 if (deprecated) { 85 checkAndSetModifiers(ClassFileConstants.AccDeprecated); 86 } 87 if (commentPtr >= 0) { 89 declarationSourceStart = scanner.commentStarts[0]; 90 } 91 } 92 96 protected void consumeClassBodyDeclaration() { 97 101 super.consumeClassBodyDeclaration(); 102 Initializer initializer = (Initializer) astStack[astPtr]; 103 requestor.acceptInitializer( 104 initializer.declarationSourceStart, 105 initializer.declarationSourceEnd, 106 intArrayStack[intArrayPtr--], 107 0, 108 modifiersSourceStart, 109 initializer.block.sourceStart, 110 initializer.block.sourceEnd); 111 } 112 116 protected void consumeClassDeclaration() { 117 super.consumeClassDeclaration(); 118 if (isLocalDeclaration()) { 120 return; 122 } 123 requestor.exitClass(endStatementPosition, ((TypeDeclaration) astStack[astPtr]).declarationSourceEnd); 125 } 126 130 protected void consumeClassHeader() { 131 super.consumeClassHeader(); 133 if (isLocalDeclaration()) { 134 intArrayPtr--; 136 return; 137 } 138 TypeDeclaration typeDecl = (TypeDeclaration) astStack[astPtr]; 139 TypeReference[] superInterfaces = typeDecl.superInterfaces; 140 char[][] interfaceNames = null; 141 int[] interfaceNameStarts = null; 142 int[] interfaceNameEnds = null; 143 if (superInterfaces != null) { 144 int superInterfacesLength = superInterfaces.length; 145 interfaceNames = new char[superInterfacesLength][]; 146 interfaceNameStarts = new int[superInterfacesLength]; 147 interfaceNameEnds = new int[superInterfacesLength]; 148 for (int i = 0; i < superInterfacesLength; i++) { 149 TypeReference superInterface = superInterfaces[i]; 150 interfaceNames[i] = CharOperation.concatWith(superInterface.getTypeName(), '.'); 151 interfaceNameStarts[i] = superInterface.sourceStart; 152 interfaceNameEnds[i] = superInterface.sourceEnd; 153 } 154 } 155 scanner.commentPtr = -1; 157 TypeReference superclass = typeDecl.superclass; 158 if (superclass == null) { 159 requestor.enterClass( 160 typeDecl.declarationSourceStart, 161 intArrayStack[intArrayPtr--], 162 typeDecl.modifiers, 163 typeDecl.modifiersSourceStart, 164 typeStartPosition, 165 typeDecl.name, 166 typeDecl.sourceStart, 167 typeDecl.sourceEnd, 168 null, 169 -1, 170 -1, 171 interfaceNames, 172 interfaceNameStarts, 173 interfaceNameEnds, 174 scanner.currentPosition - 1); 175 } else { 176 requestor.enterClass( 177 typeDecl.declarationSourceStart, 178 intArrayStack[intArrayPtr--], 179 typeDecl.modifiers, 180 typeDecl.modifiersSourceStart, 181 typeStartPosition, 182 typeDecl.name, 183 typeDecl.sourceStart, 184 typeDecl.sourceEnd, 185 CharOperation.concatWith(superclass.getTypeName(), '.'), 186 superclass.sourceStart, 187 superclass.sourceEnd, 188 interfaceNames, 189 interfaceNameStarts, 190 interfaceNameEnds, 191 scanner.currentPosition - 1); 192 193 } 194 } 195 protected void consumeClassHeaderName1() { 196 TypeDeclaration typeDecl = new TypeDeclaration(this.compilationUnit.compilationResult); 198 if (nestedMethod[nestedType] == 0) { 199 if (nestedType != 0) { 200 typeDecl.bits |= ASTNode.IsMemberType; 201 } 202 } else { 203 typeDecl.bits |= ASTNode.IsLocalType; 205 markEnclosingMemberWithLocalType(); 206 blockReal(); 207 } 208 209 long pos = identifierPositionStack[identifierPtr]; 211 typeDecl.sourceEnd = (int) pos; 212 typeDecl.sourceStart = (int) (pos >>> 32); 213 typeDecl.name = identifierStack[identifierPtr--]; 214 identifierLengthPtr--; 215 216 typeStartPosition = typeDecl.declarationSourceStart = intStack[intPtr--]; 219 intPtr--; 220 int declSourceStart = intStack[intPtr--]; 221 typeDecl.modifiersSourceStart = intStack[intPtr--]; 222 typeDecl.modifiers = intStack[intPtr--]; 223 if (typeDecl.declarationSourceStart > declSourceStart) { 224 typeDecl.declarationSourceStart = declSourceStart; 225 } 226 int length; 228 if ((length = this.expressionLengthStack[this.expressionLengthPtr--]) != 0) { 229 System.arraycopy( 230 this.expressionStack, 231 (this.expressionPtr -= length) + 1, 232 typeDecl.annotations = new Annotation[length], 233 0, 234 length); 235 } 236 typeDecl.bodyStart = typeDecl.sourceEnd + 1; 237 pushOnAstStack(typeDecl); 238 typeDecl.javadoc = this.javadoc; 240 this.javadoc = null; 241 } 242 246 protected void consumeCompilationUnit() { 247 requestor.exitCompilationUnit(scanner.source.length - 1); 249 } 250 254 protected void consumeConstructorDeclaration() { 255 super.consumeConstructorDeclaration(); 257 if (isLocalDeclaration()) { 258 return; 260 } 261 ConstructorDeclaration cd = (ConstructorDeclaration) astStack[astPtr]; 262 requestor.exitConstructor(endStatementPosition, cd.declarationSourceEnd); 263 } 264 268 protected void consumeConstructorHeader() { 269 super.consumeConstructorHeader(); 271 if (isLocalDeclaration()) { 272 intArrayPtr--; 274 return; 275 } 276 ConstructorDeclaration cd = (ConstructorDeclaration) astStack[astPtr]; 277 Argument[] arguments = cd.arguments; 278 char[][] argumentTypes = null; 279 char[][] argumentNames = null; 280 int[] argumentTypeStarts = null; 281 int[] argumentTypeEnds = null; 282 int[] argumentNameStarts = null; 283 int[] argumentNameEnds = null; 284 if (arguments != null) { 285 int argumentLength = arguments.length; 286 argumentTypes = new char[argumentLength][]; 287 argumentNames = new char[argumentLength][]; 288 argumentNameStarts = new int[argumentLength]; 289 argumentNameEnds = new int[argumentLength]; 290 argumentTypeStarts = new int[argumentLength]; 291 argumentTypeEnds = new int[argumentLength]; 292 for (int i = 0; i < argumentLength; i++) { 293 Argument argument = arguments[i]; 294 TypeReference argumentType = argument.type; 295 argumentTypes[i] = returnTypeName(argumentType); 296 argumentNames[i] = argument.name; 297 argumentNameStarts[i] = argument.sourceStart; 298 argumentNameEnds[i] = argument.sourceEnd; 299 argumentTypeStarts[i] = argumentType.sourceStart; 300 argumentTypeEnds[i] = argumentType.sourceEnd; 301 } 302 } 303 TypeReference[] thrownExceptions = cd.thrownExceptions; 304 char[][] exceptionTypes = null; 305 int[] exceptionTypeStarts = null; 306 int[] exceptionTypeEnds = null; 307 if (thrownExceptions != null) { 308 int thrownExceptionLength = thrownExceptions.length; 309 exceptionTypes = new char[thrownExceptionLength][]; 310 exceptionTypeStarts = new int[thrownExceptionLength]; 311 exceptionTypeEnds = new int[thrownExceptionLength]; 312 for (int i = 0; i < thrownExceptionLength; i++) { 313 TypeReference exception = thrownExceptions[i]; 314 exceptionTypes[i] = CharOperation.concatWith(exception.getTypeName(), '.'); 315 exceptionTypeStarts[i] = exception.sourceStart; 316 exceptionTypeEnds[i] = exception.sourceEnd; 317 } 318 } 319 requestor 320 .enterConstructor( 321 cd.declarationSourceStart, 322 intArrayStack[intArrayPtr--], 323 cd.modifiers, 324 cd.modifiersSourceStart, 325 cd.selector, 326 cd.sourceStart, 327 (int) (selectorSourcePositions & 0xFFFFFFFFL), 328 argumentTypes, 330 argumentTypeStarts, 331 argumentTypeEnds, 332 argumentNames, 333 argumentNameStarts, 334 argumentNameEnds, 335 rParenPos, 336 exceptionTypes, 338 exceptionTypeStarts, 339 exceptionTypeEnds, 340 scanner.currentPosition - 1); 341 } 342 protected void consumeConstructorHeaderName() { 343 ConstructorDeclaration cd = new ConstructorDeclaration(this.compilationUnit.compilationResult); 345 346 cd.selector = identifierStack[identifierPtr]; 348 selectorSourcePositions = identifierPositionStack[identifierPtr--]; 349 identifierLengthPtr--; 350 351 cd.declarationSourceStart = intStack[intPtr--]; 353 cd.modifiersSourceStart = intStack[intPtr--]; 354 cd.modifiers = intStack[intPtr--]; 355 int length; 357 if ((length = this.expressionLengthStack[this.expressionLengthPtr--]) != 0) { 358 System.arraycopy( 359 this.expressionStack, 360 (this.expressionPtr -= length) + 1, 361 cd.annotations = new Annotation[length], 362 0, 363 length); 364 } 365 cd.javadoc = this.javadoc; 367 this.javadoc = null; 368 369 cd.sourceStart = (int) (selectorSourcePositions >>> 32); 371 pushOnAstStack(cd); 372 373 cd.sourceEnd = lParenPos; 374 cd.bodyStart = lParenPos + 1; 375 } 376 protected void consumeDefaultModifiers() { 377 checkComment(); pushOnIntStack(modifiers); pushOnIntStack(-1); 380 pushOnIntStack( 381 declarationSourceStart >= 0 ? declarationSourceStart : scanner.startPosition); 382 resetModifiers(); 383 pushOnExpressionStackLengthStack(0); 384 } 385 protected void consumeDiet() { 386 super.consumeDiet(); 388 391 pushOnIntArrayStack(this.getJavaDocPositions()); 392 } 393 397 protected void consumeEnterCompilationUnit() { 398 requestor.enterCompilationUnit(); 400 } 401 405 protected void consumeEnterVariable() { 406 boolean isLocalDeclaration = isLocalDeclaration(); 408 if (!isLocalDeclaration && (variablesCounter[nestedType] != 0)) { 409 requestor.exitField(lastFieldBodyEndPosition, lastFieldEndPosition); 410 } 411 char[] varName = identifierStack[identifierPtr]; 412 long namePosition = identifierPositionStack[identifierPtr--]; 413 int extendedTypeDimension = intStack[intPtr--]; 414 415 AbstractVariableDeclaration declaration; 416 if (nestedMethod[nestedType] != 0) { 417 declaration = 419 new LocalDeclaration(varName, (int) (namePosition >>> 32), (int) namePosition); 420 } else { 421 declaration = 423 new FieldDeclaration(varName, (int) (namePosition >>> 32), (int) namePosition); 424 } 425 identifierLengthPtr--; 426 TypeReference type; 427 int variableIndex = variablesCounter[nestedType]; 428 int typeDim = 0; 429 if (variableIndex == 0) { 430 if (nestedMethod[nestedType] != 0) { 432 declaration.declarationSourceStart = intStack[intPtr--]; 434 declaration.modifiersSourceStart = intStack[intPtr--]; 435 declaration.modifiers = intStack[intPtr--]; 436 type = getTypeReference(typeDim = intStack[intPtr--]); pushOnAstStack(type); 438 } else { 439 type = getTypeReference(typeDim = intStack[intPtr--]); pushOnAstStack(type); 442 declaration.declarationSourceStart = intStack[intPtr--]; 443 declaration.modifiersSourceStart = intStack[intPtr--]; 444 declaration.modifiers = intStack[intPtr--]; 445 } 446 int length; 448 if ((length = this.expressionLengthStack[this.expressionLengthPtr--]) != 0) { 449 System.arraycopy( 450 this.expressionStack, 451 (this.expressionPtr -= length) + 1, 452 declaration.annotations = new Annotation[length], 453 0, 454 length); 455 } 456 } else { 457 type = (TypeReference) astStack[astPtr - variableIndex]; 458 typeDim = type.dimensions(); 459 AbstractVariableDeclaration previousVariable = 460 (AbstractVariableDeclaration) astStack[astPtr]; 461 declaration.declarationSourceStart = previousVariable.declarationSourceStart; 462 declaration.modifiers = previousVariable.modifiers; 463 declaration.modifiersSourceStart = previousVariable.modifiersSourceStart; 464 final Annotation[] annotations = previousVariable.annotations; 465 if (annotations != null) { 466 final int annotationsLength = annotations.length; 467 System.arraycopy(annotations, 0, declaration.annotations = new Annotation[annotationsLength], 0, annotationsLength); 468 } 469 } 470 471 localIntPtr = intPtr; 472 473 if (extendedTypeDimension == 0) { 474 declaration.type = type; 475 } else { 476 int dimension = typeDim + extendedTypeDimension; 477 declaration.type = this.copyDims(type, dimension); 478 } 479 variablesCounter[nestedType]++; 480 nestedMethod[nestedType]++; 481 pushOnAstStack(declaration); 482 483 int[] javadocPositions = intArrayStack[intArrayPtr]; 484 if (!isLocalDeclaration) { 485 requestor 486 .enterField( 487 declaration.declarationSourceStart, 488 javadocPositions, 489 declaration.modifiers, 490 declaration.modifiersSourceStart, 491 returnTypeName(declaration.type), 492 type.sourceStart, 493 type.sourceEnd, 494 typeDims, 495 varName, 496 (int) (namePosition >>> 32), 497 (int) namePosition, 498 extendedTypeDimension, 499 extendedTypeDimension == 0 ? -1 : endPosition); 500 } 501 } 502 506 protected void consumeExitVariableWithInitialization() { 507 super.consumeExitVariableWithInitialization(); 511 nestedMethod[nestedType]--; 512 lastFieldEndPosition = scanner.currentPosition - 1; 513 lastFieldBodyEndPosition = ((AbstractVariableDeclaration) astStack[astPtr]).initialization.sourceEnd; 514 } 515 protected void consumeExitVariableWithoutInitialization() { 516 super.consumeExitVariableWithoutInitialization(); 519 nestedMethod[nestedType]--; 520 lastFieldEndPosition = scanner.currentPosition - 1; 521 lastFieldBodyEndPosition = scanner.startPosition - 1; 522 } 523 527 protected void consumeFieldDeclaration() { 528 int variableIndex = variablesCounter[nestedType]; 532 super.consumeFieldDeclaration(); 533 intArrayPtr--; 534 if (isLocalDeclaration()) 535 return; 536 if (variableIndex != 0) { 537 requestor.exitField(lastFieldBodyEndPosition, lastFieldEndPosition); 538 } 539 } 540 protected void consumeFormalParameter(boolean isVarArgs) { 541 552 553 identifierLengthPtr--; 554 char[] parameterName = identifierStack[identifierPtr]; 555 long namePositions = identifierPositionStack[identifierPtr--]; 556 int extendedDimensions = this.intStack[this.intPtr--]; 557 int endOfEllipsis = 0; 558 if (isVarArgs) { 559 endOfEllipsis = this.intStack[this.intPtr--]; 560 } 561 int firstDimensions = this.intStack[this.intPtr--]; 562 final int typeDimensions = firstDimensions + extendedDimensions; 563 TypeReference type = getTypeReference(typeDimensions); 564 if (isVarArgs) { 565 type = copyDims(type, typeDimensions + 1); 566 if (extendedDimensions == 0) { 567 type.sourceEnd = endOfEllipsis; 568 } 569 type.bits |= ASTNode.IsVarArgs; } 571 intPtr -= 3; 572 Argument arg = 573 new Argument( 574 parameterName, 575 namePositions, 576 type, 577 intStack[intPtr + 1]); int length; 580 if ((length = this.expressionLengthStack[this.expressionLengthPtr--]) != 0) { 581 System.arraycopy( 582 this.expressionStack, 583 (this.expressionPtr -= length) + 1, 584 arg.annotations = new Annotation[length], 585 0, 586 length); 587 } 588 pushOnAstStack(arg); 589 intArrayPtr--; 590 } 591 595 protected void consumeInterfaceDeclaration() { 596 super.consumeInterfaceDeclaration(); 597 if (isLocalDeclaration()) { 599 return; 601 } 602 requestor.exitInterface(endStatementPosition, ((TypeDeclaration) astStack[astPtr]).declarationSourceEnd); 604 } 605 609 protected void consumeInterfaceHeader() { 610 super.consumeInterfaceHeader(); 612 if (isLocalDeclaration()) { 613 intArrayPtr--; 615 return; 616 } 617 TypeDeclaration typeDecl = (TypeDeclaration) astStack[astPtr]; 618 TypeReference[] superInterfaces = typeDecl.superInterfaces; 619 char[][] interfaceNames = null; 620 int[] interfaceNameStarts = null; 621 int[] interfacenameEnds = null; 622 int superInterfacesLength = 0; 623 if (superInterfaces != null) { 624 superInterfacesLength = superInterfaces.length; 625 interfaceNames = new char[superInterfacesLength][]; 626 interfaceNameStarts = new int[superInterfacesLength]; 627 interfacenameEnds = new int[superInterfacesLength]; 628 } 629 if (superInterfaces != null) { 630 for (int i = 0; i < superInterfacesLength; i++) { 631 TypeReference superInterface = superInterfaces[i]; 632 interfaceNames[i] = CharOperation.concatWith(superInterface.getTypeName(), '.'); 633 interfaceNameStarts[i] = superInterface.sourceStart; 634 interfacenameEnds[i] = superInterface.sourceEnd; 635 } 636 } 637 scanner.commentPtr = -1; 639 requestor.enterInterface( 640 typeDecl.declarationSourceStart, 641 intArrayStack[intArrayPtr--], 642 typeDecl.modifiers, 643 typeDecl.modifiersSourceStart, 644 typeStartPosition, 645 typeDecl.name, 646 typeDecl.sourceStart, 647 typeDecl.sourceEnd, 648 interfaceNames, 649 interfaceNameStarts, 650 interfacenameEnds, 651 scanner.currentPosition - 1); 652 } 653 protected void consumeInterfaceHeaderName1() { 654 TypeDeclaration typeDecl = new TypeDeclaration(this.compilationUnit.compilationResult); 656 if (nestedMethod[nestedType] == 0) { 657 if (nestedType != 0) { 658 typeDecl.bits |= ASTNode.IsMemberType; 659 } 660 } else { 661 typeDecl.bits |= ASTNode.IsLocalType; 663 markEnclosingMemberWithLocalType(); 664 blockReal(); 665 } 666 667 long pos = identifierPositionStack[identifierPtr]; 669 typeDecl.sourceEnd = (int) pos; 670 typeDecl.sourceStart = (int) (pos >>> 32); 671 typeDecl.name = identifierStack[identifierPtr--]; 672 identifierLengthPtr--; 673 674 typeStartPosition = typeDecl.declarationSourceStart = intStack[intPtr--]; 677 intPtr--; 678 int declSourceStart = intStack[intPtr--]; 679 typeDecl.modifiersSourceStart = intStack[intPtr--]; 680 typeDecl.modifiers = this.intStack[this.intPtr--] | ClassFileConstants.AccInterface; 681 if (typeDecl.declarationSourceStart > declSourceStart) { 682 typeDecl.declarationSourceStart = declSourceStart; 683 } 684 int length; 686 if ((length = this.expressionLengthStack[this.expressionLengthPtr--]) != 0) { 687 System.arraycopy( 688 this.expressionStack, 689 (this.expressionPtr -= length) + 1, 690 typeDecl.annotations = new Annotation[length], 691 0, 692 length); 693 } 694 typeDecl.bodyStart = typeDecl.sourceEnd + 1; 695 pushOnAstStack(typeDecl); 696 typeDecl.javadoc = this.javadoc; 698 this.javadoc = null; 699 } 700 protected void consumeInternalCompilationUnit() { 701 } 705 protected void consumeInternalCompilationUnitWithTypes() { 706 int length; 712 if ((length = this.astLengthStack[this.astLengthPtr--]) != 0) { 713 this.compilationUnit.types = new TypeDeclaration[length]; 714 this.astPtr -= length; 715 System.arraycopy(this.astStack, this.astPtr + 1, this.compilationUnit.types, 0, length); 716 } 717 } 718 722 protected void consumeLocalVariableDeclaration() { 723 726 super.consumeLocalVariableDeclaration(); 727 intArrayPtr--; 728 } 729 733 protected void consumeMethodDeclaration(boolean isNotAbstract) { 734 super.consumeMethodDeclaration(isNotAbstract); 737 if (isLocalDeclaration()) { 738 return; 740 } 741 MethodDeclaration md = (MethodDeclaration) astStack[astPtr]; 742 requestor.exitMethod(endStatementPosition, md.declarationSourceEnd); 743 } 744 748 protected void consumeMethodHeader() { 749 super.consumeMethodHeader(); 751 if (isLocalDeclaration()) { 752 intArrayPtr--; 754 return; 755 } 756 MethodDeclaration md = (MethodDeclaration) astStack[astPtr]; 757 758 TypeReference returnType = md.returnType; 759 char[] returnTypeName = returnTypeName(returnType); 760 Argument[] arguments = md.arguments; 761 char[][] argumentTypes = null; 762 char[][] argumentNames = null; 763 int[] argumentTypeStarts = null; 764 int[] argumentTypeEnds = null; 765 int[] argumentNameStarts = null; 766 int[] argumentNameEnds = null; 767 if (arguments != null) { 768 int argumentLength = arguments.length; 769 argumentTypes = new char[argumentLength][]; 770 argumentNames = new char[argumentLength][]; 771 argumentNameStarts = new int[argumentLength]; 772 argumentNameEnds = new int[argumentLength]; 773 argumentTypeStarts = new int[argumentLength]; 774 argumentTypeEnds = new int[argumentLength]; 775 for (int i = 0; i < argumentLength; i++) { 776 Argument argument = arguments[i]; 777 TypeReference argumentType = argument.type; 778 argumentTypes[i] = returnTypeName(argumentType); 779 argumentNames[i] = argument.name; 780 argumentNameStarts[i] = argument.sourceStart; 781 argumentNameEnds[i] = argument.sourceEnd; 782 argumentTypeStarts[i] = argumentType.sourceStart; 783 argumentTypeEnds[i] = argumentType.sourceEnd; 784 } 785 } 786 TypeReference[] thrownExceptions = md.thrownExceptions; 787 char[][] exceptionTypes = null; 788 int[] exceptionTypeStarts = null; 789 int[] exceptionTypeEnds = null; 790 if (thrownExceptions != null) { 791 int thrownExceptionLength = thrownExceptions.length; 792 exceptionTypeStarts = new int[thrownExceptionLength]; 793 exceptionTypeEnds = new int[thrownExceptionLength]; 794 exceptionTypes = new char[thrownExceptionLength][]; 795 for (int i = 0; i < thrownExceptionLength; i++) { 796 TypeReference exception = thrownExceptions[i]; 797 exceptionTypes[i] = CharOperation.concatWith(exception.getTypeName(), '.'); 798 exceptionTypeStarts[i] = exception.sourceStart; 799 exceptionTypeEnds[i] = exception.sourceEnd; 800 } 801 } 802 requestor 803 .enterMethod( 804 md.declarationSourceStart, 805 intArrayStack[intArrayPtr--], 806 md.modifiers, 807 md.modifiersSourceStart, 808 returnTypeName, 809 returnType.sourceStart, 810 returnType.sourceEnd, 811 typeDims, 812 md.selector, 813 md.sourceStart, 814 (int) (selectorSourcePositions & 0xFFFFFFFFL), 815 argumentTypes, 816 argumentTypeStarts, 817 argumentTypeEnds, 818 argumentNames, 819 argumentNameStarts, 820 argumentNameEnds, 821 rParenPos, 822 extendsDim, 823 extendsDim == 0 ? -1 : endPosition, 824 exceptionTypes, 825 exceptionTypeStarts, 826 exceptionTypeEnds, 827 scanner.currentPosition - 1); 828 } 829 protected void consumeMethodHeaderExtendedDims() { 830 MethodDeclaration md = (MethodDeclaration) astStack[astPtr]; 833 int extendedDims = intStack[intPtr--]; 834 extendsDim = extendedDims; 835 if (extendedDims != 0) { 836 TypeReference returnType = md.returnType; 837 md.sourceEnd = endPosition; 838 int dims = returnType.dimensions() + extendedDims; 839 md.returnType = this.copyDims(returnType, dims); 840 if (currentToken == TokenNameLBRACE) { 841 md.bodyStart = endPosition + 1; 842 } 843 } 844 } 845 protected void consumeMethodHeaderName(boolean isAnnotationMethod) { 846 MethodDeclaration md = null; 848 if(isAnnotationMethod) { 849 md = new AnnotationMethodDeclaration(this.compilationUnit.compilationResult); 850 } else { 851 md = new MethodDeclaration(this.compilationUnit.compilationResult); 852 } 853 md.selector = identifierStack[identifierPtr]; 855 selectorSourcePositions = identifierPositionStack[identifierPtr--]; 856 identifierLengthPtr--; 857 md.returnType = getTypeReference(typeDims = intStack[intPtr--]); 859 md.declarationSourceStart = intStack[intPtr--]; 861 md.modifiersSourceStart = intStack[intPtr--]; 862 md.modifiers = intStack[intPtr--]; 863 int length; 865 if ((length = this.expressionLengthStack[this.expressionLengthPtr--]) != 0) { 866 System.arraycopy( 867 this.expressionStack, 868 (this.expressionPtr -= length) + 1, 869 md.annotations = new Annotation[length], 870 0, 871 length); 872 } 873 md.javadoc = this.javadoc; 875 this.javadoc = null; 876 877 md.sourceStart = (int) (selectorSourcePositions >>> 32); 879 pushOnAstStack(md); 880 md.bodyStart = scanner.currentPosition-1; 881 } 882 protected void consumeModifiers() { 883 checkComment(); pushOnIntStack(modifiers); pushOnIntStack(modifiersSourceStart); 886 pushOnIntStack( 887 declarationSourceStart >= 0 ? declarationSourceStart : modifiersSourceStart); 888 resetModifiers(); 889 } 890 894 protected void consumePackageDeclarationName() { 895 896 pushOnIntArrayStack(this.getJavaDocPositions()); 897 898 super.consumePackageDeclarationName(); 899 ImportReference importReference = compilationUnit.currentPackage; 900 901 requestor.acceptPackage( 902 importReference.declarationSourceStart, 903 importReference.declarationSourceEnd, 904 intArrayStack[intArrayPtr--], 905 CharOperation.concatWith(importReference.getImportName(), '.'), 906 importReference.sourceStart); 907 } 908 912 protected void consumePackageDeclarationNameWithModifiers() { 913 914 pushOnIntArrayStack(this.getJavaDocPositions()); 915 916 super.consumePackageDeclarationNameWithModifiers(); 917 ImportReference importReference = compilationUnit.currentPackage; 918 919 requestor.acceptPackage( 920 importReference.declarationSourceStart, 921 importReference.declarationSourceEnd, 922 intArrayStack[intArrayPtr--], 923 CharOperation.concatWith(importReference.getImportName(), '.'), 924 importReference.sourceStart); 925 } 926 protected void consumePushModifiers() { 927 checkComment(); pushOnIntStack(modifiers); if (modifiersSourceStart < 0) { 930 pushOnIntStack(-1); 931 pushOnIntStack( 932 declarationSourceStart >= 0 ? declarationSourceStart : scanner.startPosition); 933 } else { 934 pushOnIntStack(modifiersSourceStart); 935 pushOnIntStack( 936 declarationSourceStart >= 0 ? declarationSourceStart : modifiersSourceStart); 937 } 938 resetModifiers(); 939 pushOnExpressionStackLengthStack(0); 940 } 941 protected void consumePushRealModifiers() { 942 checkComment(); pushOnIntStack(modifiers); if (modifiersSourceStart < 0) { 945 pushOnIntStack(-1); 946 pushOnIntStack( 947 declarationSourceStart >= 0 ? declarationSourceStart : scanner.startPosition); 948 } else { 949 pushOnIntStack(modifiersSourceStart); 950 pushOnIntStack( 951 declarationSourceStart >= 0 ? declarationSourceStart : modifiersSourceStart); 952 } 953 resetModifiers(); 954 } 955 protected void consumeSingleStaticImportDeclarationName() { 956 958 959 pushOnIntArrayStack(this.getJavaDocPositions()); 960 961 super.consumeSingleStaticImportDeclarationName(); 962 ImportReference importReference = (ImportReference) astStack[astPtr]; 963 requestor.acceptImport( 964 importReference.declarationSourceStart, 965 importReference.declarationSourceEnd, 966 intArrayStack[intArrayPtr--], 967 CharOperation.concatWith(importReference.getImportName(), '.'), 968 importReference.sourceStart, 969 false, 970 ClassFileConstants.AccStatic); 971 } 972 976 protected void consumeSingleTypeImportDeclarationName() { 977 979 980 pushOnIntArrayStack(this.getJavaDocPositions()); 981 982 super.consumeSingleTypeImportDeclarationName(); 983 ImportReference importReference = (ImportReference) astStack[astPtr]; 984 requestor.acceptImport( 985 importReference.declarationSourceStart, 986 importReference.declarationSourceEnd, 987 intArrayStack[intArrayPtr--], 988 CharOperation.concatWith(importReference.getImportName(), '.'), 989 importReference.sourceStart, 990 false, 991 ClassFileConstants.AccDefault); 992 } 993 protected void consumeStaticImportOnDemandDeclarationName() { 994 996 997 pushOnIntArrayStack(this.getJavaDocPositions()); 998 999 super.consumeStaticImportOnDemandDeclarationName(); 1000 ImportReference importReference = (ImportReference) astStack[astPtr]; 1001 requestor.acceptImport( 1002 importReference.declarationSourceStart, 1003 importReference.declarationSourceEnd, 1004 intArrayStack[intArrayPtr--], 1005 CharOperation.concatWith(importReference.getImportName(), '.'), 1006 importReference.sourceStart, 1007 true, 1008 ClassFileConstants.AccStatic); 1009} 1010 1014protected void consumeStaticInitializer() { 1015 super.consumeStaticInitializer(); 1019 Initializer initializer = (Initializer) astStack[astPtr]; 1020 requestor.acceptInitializer( 1021 initializer.declarationSourceStart, 1022 initializer.declarationSourceEnd, 1023 intArrayStack[intArrayPtr--], 1024 ClassFileConstants.AccStatic, 1025 intStack[intPtr--], 1026 initializer.block.sourceStart, 1027 initializer.declarationSourceEnd); 1028} 1029protected void consumeStaticOnly() { 1030 checkComment(); pushOnIntStack(modifiersSourceStart); 1033 pushOnIntStack(scanner.currentPosition); 1034 pushOnIntStack( 1035 declarationSourceStart >= 0 ? declarationSourceStart : modifiersSourceStart); 1036 jumpOverMethodBody(); 1037 nestedMethod[nestedType]++; 1038 resetModifiers(); 1039} 1040 1044protected void consumeTypeImportOnDemandDeclarationName() { 1045 1047 1048 pushOnIntArrayStack(this.getJavaDocPositions()); 1049 1050 super.consumeTypeImportOnDemandDeclarationName(); 1051 ImportReference importReference = (ImportReference) astStack[astPtr]; 1052 requestor.acceptImport( 1053 importReference.declarationSourceStart, 1054 importReference.declarationSourceEnd, 1055 intArrayStack[intArrayPtr--], 1056 CharOperation.concatWith(importReference.getImportName(), '.'), 1057 importReference.sourceStart, 1058 true, 1059 ClassFileConstants.AccDefault); 1060} 1061 1073 1074public int flushCommentsDefinedPriorTo(int position) { 1075 1076 return lastFieldEndPosition = super.flushCommentsDefinedPriorTo(position); 1077} 1078public CompilationUnitDeclaration endParse(int act) { 1079 if (scanner.recordLineSeparator) { 1080 requestor.acceptLineSeparatorPositions(scanner.getLineEnds()); 1081 } 1082 return super.endParse(act); 1083} 1084public void initialize(boolean initializeNLS) { 1085 super.initialize(initializeNLS); 1088 intArrayPtr = -1; 1089} 1090public void initialize() { 1091 super.initialize(); 1094 intArrayPtr = -1; 1095} 1096 1100private boolean isLocalDeclaration() { 1101 int nestedDepth = nestedType; 1102 while (nestedDepth >= 0) { 1103 if (nestedMethod[nestedDepth] != 0) { 1104 return true; 1105 } 1106 nestedDepth--; 1107 } 1108 return false; 1109} 1110protected void parse() { 1111 this.diet = true; 1112 super.parse(); 1113} 1114 1117public void parseCompilationUnit(ICompilationUnit unit) { 1118 char[] regionSource = unit.getContents(); 1119 try { 1120 initialize(true); 1121 goForCompilationUnit(); 1122 referenceContext = 1123 compilationUnit = 1124 new CompilationUnitDeclaration( 1125 problemReporter(), 1126 new CompilationResult(unit, 0, 0, this.options.maxProblemsPerUnit), 1127 regionSource.length); 1128 scanner.resetTo(0, regionSource.length); 1129 scanner.setSource(regionSource); 1130 parse(); 1131 } catch (AbortCompilation ex) { 1132 } 1134} 1135 1138public void parseConstructor(char[] regionSource) { 1139 try { 1140 initialize(); 1141 goForClassBodyDeclarations(); 1142 referenceContext = 1143 compilationUnit = 1144 new CompilationUnitDeclaration( 1145 problemReporter(), 1146 new CompilationResult(regionSource, 0, 0, this.options.maxProblemsPerUnit), 1147 regionSource.length); 1148 scanner.resetTo(0, regionSource.length); 1149 scanner.setSource(regionSource); 1150 parse(); 1151 } catch (AbortCompilation ex) { 1152 } 1154} 1155 1158public void parseField(char[] regionSource) { 1159 try { 1160 initialize(); 1161 goForFieldDeclaration(); 1162 referenceContext = 1163 compilationUnit = 1164 new CompilationUnitDeclaration( 1165 problemReporter(), 1166 new CompilationResult(regionSource, 0, 0, this.options.maxProblemsPerUnit), 1167 regionSource.length); 1168 scanner.resetTo(0, regionSource.length); 1169 scanner.setSource(regionSource); 1170 parse(); 1171 } catch (AbortCompilation ex) { 1172 } 1174 1175} 1176 1179public void parseImport(char[] regionSource) { 1180 try { 1181 initialize(); 1182 goForImportDeclaration(); 1183 referenceContext = 1184 compilationUnit = 1185 new CompilationUnitDeclaration( 1186 problemReporter(), 1187 new CompilationResult(regionSource, 0, 0, this.options.maxProblemsPerUnit), 1188 regionSource.length); 1189 scanner.resetTo(0, regionSource.length); 1190 scanner.setSource(regionSource); 1191 parse(); 1192 } catch (AbortCompilation ex) { 1193 } 1195 1196} 1197 1203public void parseInitializer(char[] regionSource) { 1204 try { 1205 initialize(); 1206 goForInitializer(); 1207 referenceContext = 1208 compilationUnit = 1209 new CompilationUnitDeclaration( 1210 problemReporter(), 1211 new CompilationResult(regionSource, 0, 0, this.options.maxProblemsPerUnit), 1212 regionSource.length); 1213 scanner.resetTo(0, regionSource.length); 1214 scanner.setSource(regionSource); 1215 parse(); 1216 } catch (AbortCompilation ex) { 1217 } 1219 1220} 1221 1224public void parseMethod(char[] regionSource) { 1225 try { 1226 initialize(); 1227 goForGenericMethodDeclaration(); 1228 referenceContext = 1229 compilationUnit = 1230 new CompilationUnitDeclaration( 1231 problemReporter(), 1232 new CompilationResult(regionSource, 0, 0, this.options.maxProblemsPerUnit), 1233 regionSource.length); 1234 scanner.resetTo(0, regionSource.length); 1235 scanner.setSource(regionSource); 1236 parse(); 1237 } catch (AbortCompilation ex) { 1238 } 1240} 1241 1244public void parsePackage(char[] regionSource) { 1245 try { 1246 initialize(); 1247 goForPackageDeclaration(); 1248 referenceContext = 1249 compilationUnit = 1250 new CompilationUnitDeclaration( 1251 problemReporter(), 1252 new CompilationResult(regionSource, 0, 0, this.options.maxProblemsPerUnit), 1253 regionSource.length); 1254 scanner.resetTo(0, regionSource.length); 1255 scanner.setSource(regionSource); 1256 parse(); 1257 } catch (AbortCompilation ex) { 1258 } 1260 1261} 1262 1265public void parseType(char[] regionSource) { 1266 try { 1267 initialize(); 1268 goForTypeDeclaration(); 1269 referenceContext = 1270 compilationUnit = 1271 new CompilationUnitDeclaration( 1272 problemReporter(), 1273 new CompilationResult(regionSource, 0, 0, this.options.maxProblemsPerUnit), 1274 regionSource.length); 1275 scanner.resetTo(0, regionSource.length); 1276 scanner.setSource(regionSource); 1277 parse(); 1278 } catch (AbortCompilation ex) { 1279 } 1281 1282} 1283 1290public ProblemReporter problemReporter() { 1291 problemReporter.referenceContext = referenceContext; 1292 return problemReporter; 1293} 1294protected void pushOnIntArrayStack(int[] positions) { 1295 1296 int stackLength = this.intArrayStack.length; 1297 if (++this.intArrayPtr >= stackLength) { 1298 System.arraycopy( 1299 this.intArrayStack, 0, 1300 this.intArrayStack = new int[stackLength + StackIncrement][], 0, 1301 stackLength); 1302 } 1303 intArrayStack[intArrayPtr] = positions; 1304} 1305protected void resetModifiers() { 1306 super.resetModifiers(); 1307 declarationSourceStart = -1; 1308} 1309 1313protected boolean resumeOnSyntaxError() { 1314 return false; 1315} 1316 1323private char[] returnTypeName(TypeReference type) { 1324 int dimension = type.dimensions(); 1325 if (dimension != 0) { 1326 char[] dimensionsArray = new char[dimension * 2]; 1327 for (int i = 0; i < dimension; i++) { 1328 dimensionsArray[i*2] = '['; 1329 dimensionsArray[(i*2) + 1] = ']'; 1330 } 1331 return CharOperation.concat( 1332 CharOperation.concatWith(type.getTypeName(), '.'), 1333 dimensionsArray); 1334 } 1335 return CharOperation.concatWith(type.getTypeName(), '.'); 1336} 1337public String toString() { 1338 StringBuffer buffer = new StringBuffer (); 1339 buffer.append("intArrayPtr = " + intArrayPtr + "\n"); buffer.append(super.toString()); 1341 return buffer.toString(); 1342} 1343 1346protected TypeReference typeReference( 1347 int dim, 1348 int localIdentifierPtr, 1349 int localIdentifierLengthPtr) { 1350 1354 1355 int length; 1356 TypeReference ref; 1357 if ((length = identifierLengthStack[localIdentifierLengthPtr]) == 1) { 1358 if (dim == 0) { 1360 ref = 1361 new SingleTypeReference( 1362 identifierStack[localIdentifierPtr], 1363 identifierPositionStack[localIdentifierPtr--]); 1364 } else { 1365 ref = 1366 new ArrayTypeReference( 1367 identifierStack[localIdentifierPtr], 1368 dim, 1369 identifierPositionStack[localIdentifierPtr--]); 1370 ref.sourceEnd = endPosition; 1371 } 1372 } else { 1373 if (length < 0) { ref = TypeReference.baseTypeReference(-length, dim); 1375 ref.sourceStart = intStack[localIntPtr--]; 1376 if (dim == 0) { 1377 ref.sourceEnd = intStack[localIntPtr--]; 1378 } else { 1379 localIntPtr--; 1380 ref.sourceEnd = endPosition; 1381 } 1382 } else { char[][] tokens = new char[length][]; 1384 localIdentifierPtr -= length; 1385 long[] positions = new long[length]; 1386 System.arraycopy(identifierStack, localIdentifierPtr + 1, tokens, 0, length); 1387 System.arraycopy( 1388 identifierPositionStack, 1389 localIdentifierPtr + 1, 1390 positions, 1391 0, 1392 length); 1393 if (dim == 0) 1394 ref = new QualifiedTypeReference(tokens, positions); 1395 else 1396 ref = new ArrayQualifiedTypeReference(tokens, dim, positions); 1397 } 1398 } 1399 return ref; 1400} 1401} 1402 | Popular Tags |