1 11 package org.eclipse.jdt.internal.compiler.problem; 12 13 import org.eclipse.jdt.core.compiler.CategorizedProblem; 14 import org.eclipse.jdt.core.compiler.CharOperation; 15 import org.eclipse.jdt.internal.compiler.CompilationResult; 16 import org.eclipse.jdt.internal.compiler.IErrorHandlingPolicy; 17 import org.eclipse.jdt.internal.compiler.IProblemFactory; 18 import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; 19 import org.eclipse.jdt.internal.compiler.impl.ReferenceContext; 20 import org.eclipse.jdt.internal.compiler.util.Util; 21 22 30 31 public class ProblemHandler { 32 33 public final static String [] NoArgument = CharOperation.NO_STRINGS; 34 35 final public IErrorHandlingPolicy policy; 36 public final IProblemFactory problemFactory; 37 public final CompilerOptions options; 38 44 public ProblemHandler(IErrorHandlingPolicy policy, CompilerOptions options, IProblemFactory problemFactory) { 45 this.policy = policy; 46 this.problemFactory = problemFactory; 47 this.options = options; 48 } 49 54 public int computeSeverity(int problemId){ 55 56 return ProblemSeverities.Error; } 58 public CategorizedProblem createProblem( 59 char[] fileName, 60 int problemId, 61 String [] problemArguments, 62 String [] messageArguments, 63 int severity, 64 int problemStartPosition, 65 int problemEndPosition, 66 int lineNumber, 67 int columnNumber) { 68 69 return this.problemFactory.createProblem( 70 fileName, 71 problemId, 72 problemArguments, 73 messageArguments, 74 severity, 75 problemStartPosition, 76 problemEndPosition, 77 lineNumber, 78 columnNumber); 79 } 80 public void handle( 81 int problemId, 82 String [] problemArguments, 83 String [] messageArguments, 84 int severity, 85 int problemStartPosition, 86 int problemEndPosition, 87 ReferenceContext referenceContext, 88 CompilationResult unitResult) { 89 90 if (severity == ProblemSeverities.Ignore) 91 return; 92 93 if (referenceContext == null) { 95 if ((severity & ProblemSeverities.Error) != 0) { CategorizedProblem problem = this.createProblem(null, problemId, problemArguments, messageArguments, severity, 0, 0, 0, 0); 97 throw new AbortCompilation(null, problem); 98 } else { 99 return; } 101 } 102 103 int[] lineEnds; 104 int lineNumber = problemStartPosition >= 0 105 ? Util.getLineNumber(problemStartPosition, lineEnds = unitResult.getLineSeparatorPositions(), 0, lineEnds.length-1) 106 : 0; 107 int columnNumber = problemStartPosition >= 0 108 ? Util.searchColumnNumber(unitResult.getLineSeparatorPositions(), lineNumber, problemStartPosition) 109 : 0; 110 CategorizedProblem problem = 111 this.createProblem( 112 unitResult.getFileName(), 113 problemId, 114 problemArguments, 115 messageArguments, 116 severity, 117 problemStartPosition, 118 problemEndPosition, 119 lineNumber, 120 columnNumber); 121 122 if (problem == null) return; 124 switch (severity & ProblemSeverities.Error) { 125 case ProblemSeverities.Error : 126 this.record(problem, unitResult, referenceContext); 127 if ((severity & ProblemSeverities.Fatal) != 0) { 128 referenceContext.tagAsHavingErrors(); 129 int abortLevel; 131 if ((abortLevel = this.policy.stopOnFirstError() ? ProblemSeverities.AbortCompilation : severity & ProblemSeverities.Abort) != 0) { 132 referenceContext.abort(abortLevel, problem); 133 } 134 } 135 break; 136 case ProblemSeverities.Warning : 137 this.record(problem, unitResult, referenceContext); 138 break; 139 } 140 } 141 145 public void handle( 146 int problemId, 147 String [] problemArguments, 148 String [] messageArguments, 149 int problemStartPosition, 150 int problemEndPosition, 151 ReferenceContext referenceContext, 152 CompilationResult unitResult) { 153 154 this.handle( 155 problemId, 156 problemArguments, 157 messageArguments, 158 this.computeSeverity(problemId), problemStartPosition, 160 problemEndPosition, 161 referenceContext, 162 unitResult); 163 } 164 public void record(CategorizedProblem problem, CompilationResult unitResult, ReferenceContext referenceContext) { 165 unitResult.record(problem, referenceContext); 166 } 167 } 168 | Popular Tags |