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.problem;
 
  13 import net.sourceforge.phpdt.core.compiler.IProblem;
 
  14 import net.sourceforge.phpdt.internal.compiler.CompilationResult;
 
  15 import net.sourceforge.phpdt.internal.compiler.IErrorHandlingPolicy;
 
  16 import net.sourceforge.phpdt.internal.compiler.IProblemFactory;
 
  17 import net.sourceforge.phpdt.internal.compiler.impl.CompilerOptions;
 
  18 import net.sourceforge.phpdt.internal.compiler.impl.ReferenceContext;
 
  22  * Compiler error handler, responsible to determine whether
 
  23  * a problem is actually a warning or an error; also will
 
  24  * decide whether the compilation task can be processed further or not.
 
  26  * Behavior : will request its current policy if need to stop on
 
  27  *      first error, and if should proceed (persist) with problems.
 
  30 public class ProblemHandler implements ProblemSeverities {
 
  32         public final static String[] NoArgument = new String[0];
 
  34         final public IErrorHandlingPolicy policy;
 
  35         public final IProblemFactory problemFactory;
 
  36         public final CompilerOptions options;
 
  38  * Problem handler can be supplied with a policy to specify
 
  39  * its behavior in error handling. Also see static methods for
 
  43 public ProblemHandler(IErrorHandlingPolicy policy, CompilerOptions options, IProblemFactory problemFactory) {
 
  45         this.problemFactory = problemFactory;
 
  46         this.options = options;
 
  49  * Given the current configuration, answers which category the problem
 
  51  *              Error | Warning | Ignore
 
  53 public int computeSeverity(int problemId){
 
  54         return Error; // by default all problems are errors
 
  56 public IProblem createProblem(
 
  59         String[] problemArguments, 
 
  60         String[] messageArguments,
 
  62         int problemStartPosition, 
 
  63         int problemEndPosition, 
 
  65         ReferenceContext referenceContext,
 
  66         CompilationResult unitResult) {
 
  68         return problemFactory.createProblem(
 
  80         String[] problemArguments, 
 
  81         String[] messageArguments,
 
  83         int problemStartPosition, 
 
  84         int problemEndPosition, 
 
  85         ReferenceContext referenceContext, 
 
  86         CompilationResult unitResult) {
 
  88         if (severity == Ignore)
 
  91         // if no reference context, we need to abort from the current compilation process
 
  92         if (referenceContext == null) {
 
  93                 if ((severity & Error) != 0) { // non reportable error is fatal
 
  94                         throw new AbortCompilation(problemId, problemArguments, messageArguments);
 
  96                         return; // ignore non reportable warning
 
 102                         unitResult.getFileName(), 
 
 107                         problemStartPosition, 
 
 109                         problemStartPosition >= 0
 
 110                                 ? searchLineNumber(unitResult.lineSeparatorPositions, problemStartPosition)
 
 114         if (problem == null) return; // problem couldn't be created, ignore
 
 116         switch (severity & Error) {
 
 118                         this.record(problem, unitResult, referenceContext);
 
 119                         referenceContext.tagAsHavingErrors();
 
 124                                 (policy.stopOnFirstError() ? AbortCompilation : severity & Abort)) != 0) {
 
 126                                 referenceContext.abort(abortLevel);
 
 130                         this.record(problem, unitResult, referenceContext);
 
 135  * Standard problem handling API, the actual severity (warning/error/ignore) is deducted
 
 136  * from the problem ID and the current compiler options.
 
 140         String[] problemArguments, 
 
 141         String[] messageArguments,
 
 142         int problemStartPosition, 
 
 143         int problemEndPosition, 
 
 144         ReferenceContext referenceContext, 
 
 145         CompilationResult unitResult) {
 
 151                 this.computeSeverity(problemId), // severity inferred using the ID
 
 152                 problemStartPosition,
 
 157 public void record(IProblem problem, CompilationResult unitResult, ReferenceContext referenceContext) {
 
 158         unitResult.record(problem, referenceContext);
 
 161  * Search the line number corresponding to a specific position
 
 163  * @param methodBinding net.sourceforge.phpdt.internal.compiler.nameloopkup.SyntheticAccessMethodBinding
 
 165 public static final int searchLineNumber(int[] startLineIndexes, int position) {
 
 166         if (startLineIndexes == null)
 
 168         int length = startLineIndexes.length;
 
 171         int g = 0, d = length - 1;
 
 175                 if (position < startLineIndexes[m]) {
 
 177                 } else if (position > startLineIndexes[m]) {
 
 183         if (position < startLineIndexes[m]) {