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 if (problemId==IProblem.PHPParsingWarning ||
55 problemId==IProblem.PHPVarDeprecatedWarning) {
58 return Error; // by default all problems are errors
60 public IProblem createProblem(
63 String[] problemArguments,
64 String[] messageArguments,
66 int problemStartPosition,
67 int problemEndPosition,
69 ReferenceContext referenceContext,
70 CompilationResult unitResult) {
72 return problemFactory.createProblem(
84 String[] problemArguments,
85 String[] messageArguments,
87 int problemStartPosition,
88 int problemEndPosition,
89 ReferenceContext referenceContext,
90 CompilationResult unitResult) {
92 if (severity == Ignore)
95 // if no reference context, we need to abort from the current compilation process
96 if (referenceContext == null) {
97 if ((severity & Error) != 0) { // non reportable error is fatal
98 throw new AbortCompilation(problemId, problemArguments, messageArguments);
100 return; // ignore non reportable warning
106 unitResult.getFileName(),
111 problemStartPosition,
113 problemStartPosition >= 0
114 ? searchLineNumber(unitResult.lineSeparatorPositions, problemStartPosition)
118 if (problem == null) return; // problem couldn't be created, ignore
120 switch (severity & Error) {
122 this.record(problem, unitResult, referenceContext);
123 referenceContext.tagAsHavingErrors();
128 (policy.stopOnFirstError() ? AbortCompilation : severity & Abort)) != 0) {
130 referenceContext.abort(abortLevel);
134 this.record(problem, unitResult, referenceContext);
139 * Standard problem handling API, the actual severity (warning/error/ignore) is deducted
140 * from the problem ID and the current compiler options.
144 String[] problemArguments,
145 String[] messageArguments,
146 int problemStartPosition,
147 int problemEndPosition,
148 ReferenceContext referenceContext,
149 CompilationResult unitResult) {
155 this.computeSeverity(problemId), // severity inferred using the ID
156 problemStartPosition,
161 public void record(IProblem problem, CompilationResult unitResult, ReferenceContext referenceContext) {
162 unitResult.record(problem, referenceContext);
165 * Search the line number corresponding to a specific position
167 * @param methodBinding org.eclipse.jdt.internal.compiler.nameloopkup.SyntheticAccessMethodBinding
169 public static final int searchLineNumber(int[] startLineIndexes, int position) {
170 if (startLineIndexes == null)
172 int length = startLineIndexes.length;
175 int g = 0, d = length - 1;
179 if (position < startLineIndexes[m]) {
181 } else if (position > startLineIndexes[m]) {
187 if (position < startLineIndexes[m]) {