Пример #1
0
  void attach(TypeParameter[] parameters, int startPos) {
    if (methodDeclaration.modifiers != ClassFileConstants.AccDefault) return;

    int lastParameterEnd = parameters[parameters.length - 1].sourceEnd;

    Parser parser = this.parser();
    Scanner scanner = parser.scanner;
    if (Util.getLineNumber(
            methodDeclaration.declarationSourceStart, scanner.lineEnds, 0, scanner.linePtr)
        != Util.getLineNumber(lastParameterEnd, scanner.lineEnds, 0, scanner.linePtr)) return;

    if (parser.modifiersSourceStart > lastParameterEnd
        && parser.modifiersSourceStart < methodDeclaration.declarationSourceStart) return;

    if (this.methodDeclaration instanceof MethodDeclaration) {
      ((MethodDeclaration) this.methodDeclaration).typeParameters = parameters;
      this.methodDeclaration.declarationSourceStart = startPos;
    } else if (this.methodDeclaration instanceof ConstructorDeclaration) {
      ((ConstructorDeclaration) this.methodDeclaration).typeParameters = parameters;
      this.methodDeclaration.declarationSourceStart = startPos;
    }
  }
  public void handle(
      int problemId,
      String[] problemArguments,
      int elaborationId,
      String[] messageArguments,
      int severity,
      int problemStartPosition,
      int problemEndPosition,
      ReferenceContext referenceContext,
      CompilationResult unitResult) {

    if (severity == ProblemSeverities.Ignore) return;

    // if no reference context, we need to abort from the current compilation process
    if (referenceContext == null) {
      if ((severity & ProblemSeverities.Error) != 0) { // non reportable error is fatal
        CategorizedProblem problem =
            this.createProblem(
                null,
                problemId,
                problemArguments,
                elaborationId,
                messageArguments,
                severity,
                0,
                0,
                0,
                0);
        throw new AbortCompilation(null, problem);
      } else {
        return; // ignore non reportable warning
      }
    }

    int[] lineEnds;
    int lineNumber =
        problemStartPosition >= 0
            ? Util.getLineNumber(
                problemStartPosition,
                lineEnds = unitResult.getLineSeparatorPositions(),
                0,
                lineEnds.length - 1)
            : 0;
    int columnNumber =
        problemStartPosition >= 0
            ? Util.searchColumnNumber(
                unitResult.getLineSeparatorPositions(), lineNumber, problemStartPosition)
            : 0;
    CategorizedProblem problem =
        this.createProblem(
            unitResult.getFileName(),
            problemId,
            problemArguments,
            elaborationId,
            messageArguments,
            severity,
            problemStartPosition,
            problemEndPosition,
            lineNumber,
            columnNumber);

    if (problem == null) return; // problem couldn't be created, ignore

    switch (severity & ProblemSeverities.Error) {
      case ProblemSeverities.Error:
        record(problem, unitResult, referenceContext);
        if ((severity & ProblemSeverities.Fatal) != 0) {
          referenceContext.tagAsHavingErrors();
          // should abort ?
          int abortLevel;
          if ((abortLevel =
                  this.policy.stopOnFirstError()
                      ? ProblemSeverities.AbortCompilation
                      : severity & ProblemSeverities.Abort)
              != 0) {
            referenceContext.abort(abortLevel, problem);
          }
        }
        break;
      case ProblemSeverities.Warning:
        record(problem, unitResult, referenceContext);
        break;
    }
  }
  /* (non-Javadoc)
   * Save all source comments currently stored before flushing them.
   * @see org.eclipse.jdt.internal.compiler.parser.Parser#flushCommentsDefinedPriorTo(int)
   */
  public int flushCommentsDefinedPriorTo(int position) {

    int lastCommentIndex = this.scanner.commentPtr;
    if (lastCommentIndex < 0) return position; // no comment

    // compute the index of the first obsolete comment
    int index = lastCommentIndex;
    int validCount = 0;
    while (index >= 0) {
      int commentEnd = this.scanner.commentStops[index];
      if (commentEnd < 0)
        commentEnd = -commentEnd; // negative end position for non-javadoc comments
      if (commentEnd <= position) {
        break;
      }
      index--;
      validCount++;
    }
    // if the source at <position> is immediately followed by a line comment, then
    // flush this comment and shift <position> to the comment end.
    if (validCount > 0) {
      int immediateCommentEnd = 0;
      while (index < lastCommentIndex
          && (immediateCommentEnd = -this.scanner.commentStops[index + 1])
              > 0) { // only tolerating non-javadoc comments (non-javadoc comment end positions are
        // negative)
        // is there any line break until the end of the immediate comment ? (thus only tolerating
        // line comment)
        immediateCommentEnd--; // comment end in one char too far
        if (org.eclipse.jdt.internal.compiler.util.Util.getLineNumber(
                position, this.scanner.lineEnds, 0, this.scanner.linePtr)
            != org.eclipse.jdt.internal.compiler.util.Util.getLineNumber(
                immediateCommentEnd, this.scanner.lineEnds, 0, this.scanner.linePtr)) break;
        position = immediateCommentEnd;
        validCount--; // flush this comment
        index++;
      }
    }

    if (index < 0) return position; // no obsolete comment
    pushOnCommentsStack(0, index); // store comment before flushing them

    switch (validCount) {
      case 0:
        // do nothing
        break;
        // move valid comment infos, overriding obsolete comment infos
      case 2:
        this.scanner.commentStarts[0] = this.scanner.commentStarts[index + 1];
        this.scanner.commentStops[0] = this.scanner.commentStops[index + 1];
        this.scanner.commentTagStarts[0] = this.scanner.commentTagStarts[index + 1];
        this.scanner.commentStarts[1] = this.scanner.commentStarts[index + 2];
        this.scanner.commentStops[1] = this.scanner.commentStops[index + 2];
        this.scanner.commentTagStarts[1] = this.scanner.commentTagStarts[index + 2];
        break;
      case 1:
        this.scanner.commentStarts[0] = this.scanner.commentStarts[index + 1];
        this.scanner.commentStops[0] = this.scanner.commentStops[index + 1];
        this.scanner.commentTagStarts[0] = this.scanner.commentTagStarts[index + 1];
        break;
      default:
        System.arraycopy(
            this.scanner.commentStarts, index + 1, this.scanner.commentStarts, 0, validCount);
        System.arraycopy(
            this.scanner.commentStops, index + 1, this.scanner.commentStops, 0, validCount);
        System.arraycopy(
            this.scanner.commentTagStarts, index + 1, this.scanner.commentTagStarts, 0, validCount);
    }
    this.scanner.commentPtr = validCount - 1;
    return position;
  }