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.ReferenceContext;
21 * Compiler error handler, responsible to determine whether
22 * a problem is actually a warning or an error; also will
23 * decide whether the compilation task can be processed further or not.
25 * Behavior : will request its current policy if need to stop on
26 * first error, and if should proceed (persist) with problems.
29 public class ProblemHandler implements ProblemSeverities {
31 public final static String[] NoArgument = new String[0];
33 final public IErrorHandlingPolicy policy;
34 public final IProblemFactory problemFactory;
35 // public final CompilerOptions options;
37 * Problem handler can be supplied with a policy to specify
38 * its behavior in error handling. Also see static methods for
42 public ProblemHandler(IErrorHandlingPolicy policy, IProblemFactory problemFactory) {
43 //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){
55 return Error; // by default all problems are errors
57 public IProblem createProblem(
60 String[] problemArguments,
61 String[] messageArguments,
63 int problemStartPosition,
64 int problemEndPosition,
66 ReferenceContext referenceContext,
67 CompilationResult unitResult) {
69 return problemFactory.createProblem(
81 String[] problemArguments,
82 String[] messageArguments,
84 int problemStartPosition,
85 int problemEndPosition,
86 ReferenceContext referenceContext,
87 CompilationResult unitResult) {
89 if (severity == Ignore)
92 // if no reference context, we need to abort from the current compilation process
93 if (referenceContext == null) {
94 if ((severity & Error) != 0) { // non reportable error is fatal
95 throw new AbortCompilation(problemId, problemArguments, messageArguments);
97 return; // ignore non reportable warning
103 unitResult.getFileName(),
108 problemStartPosition,
110 problemStartPosition >= 0
111 ? searchLineNumber(unitResult.lineSeparatorPositions, problemStartPosition)
115 if (problem == null) return; // problem couldn't be created, ignore
117 switch (severity & Error) {
119 this.record(problem, unitResult, referenceContext);
120 referenceContext.tagAsHavingErrors();
125 (policy.stopOnFirstError() ? AbortCompilation : severity & Abort)) != 0) {
127 referenceContext.abort(abortLevel);
131 this.record(problem, unitResult, referenceContext);
136 * Standard problem handling API, the actual severity (warning/error/ignore) is deducted
137 * from the problem ID and the current compiler options.
141 String[] problemArguments,
142 String[] messageArguments,
143 int problemStartPosition,
144 int problemEndPosition,
145 ReferenceContext referenceContext,
146 CompilationResult unitResult) {
152 this.computeSeverity(problemId), // severity inferred using the ID
153 problemStartPosition,
158 public void record(IProblem problem, CompilationResult unitResult, ReferenceContext referenceContext) {
159 unitResult.record(problem, referenceContext);
162 * Search the line number corresponding to a specific position
164 * @param methodBinding org.eclipse.jdt.internal.compiler.nameloopkup.SyntheticAccessMethodBinding
166 public static final int searchLineNumber(int[] startLineIndexes, int position) {
167 if (startLineIndexes == null)
169 int length = startLineIndexes.length;
172 int g = 0, d = length - 1;
176 if (position < startLineIndexes[m]) {
178 } else if (position > startLineIndexes[m]) {
184 if (position < startLineIndexes[m]) {