01: /*******************************************************************************
02: * Copyright (c) 2000, 2007 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.jdt.internal.compiler.problem;
11:
12: import org.eclipse.jdt.core.compiler.CategorizedProblem;
13: import org.eclipse.jdt.internal.compiler.CompilationResult;
14: import org.eclipse.jdt.internal.compiler.ast.ASTNode;
15: import org.eclipse.jdt.internal.compiler.lookup.InvocationSite;
16: import org.eclipse.jdt.internal.compiler.util.Util;
17:
18: /*
19: * Special unchecked exception type used
20: * to abort from the compilation process
21: *
22: * should only be thrown from within problem handlers.
23: */
24: public class AbortCompilation extends RuntimeException {
25:
26: public CompilationResult compilationResult;
27: public Throwable exception;
28: public CategorizedProblem problem;
29:
30: /* special fields used to abort silently (e.g. when cancelling build process) */
31: public boolean isSilent;
32: public RuntimeException silentException;
33:
34: private static final long serialVersionUID = -2047226595083244852L; // backward compatible
35:
36: public AbortCompilation() {
37: // empty
38: }
39:
40: public AbortCompilation(CompilationResult compilationResult,
41: CategorizedProblem problem) {
42: this ();
43: this .compilationResult = compilationResult;
44: this .problem = problem;
45: }
46:
47: public AbortCompilation(CompilationResult compilationResult,
48: Throwable exception) {
49: this ();
50: this .compilationResult = compilationResult;
51: this .exception = exception;
52: }
53:
54: public AbortCompilation(boolean isSilent,
55: RuntimeException silentException) {
56: this ();
57: this .isSilent = isSilent;
58: this .silentException = silentException;
59: }
60:
61: public void updateContext(InvocationSite invocationSite,
62: CompilationResult unitResult) {
63: if (this .problem == null)
64: return;
65: if (this .problem.getSourceStart() != 0
66: || this .problem.getSourceEnd() != 0)
67: return;
68: this .problem.setSourceStart(invocationSite.sourceStart());
69: this .problem.setSourceEnd(invocationSite.sourceEnd());
70: int[] lineEnds = unitResult.getLineSeparatorPositions();
71: this .problem.setSourceLineNumber(Util.getLineNumber(
72: invocationSite.sourceStart(), lineEnds, 0,
73: lineEnds.length - 1));
74: this .compilationResult = unitResult;
75: }
76:
77: public void updateContext(ASTNode astNode,
78: CompilationResult unitResult) {
79: if (this .problem == null)
80: return;
81: if (this .problem.getSourceStart() != 0
82: || this .problem.getSourceEnd() != 0)
83: return;
84: this .problem.setSourceStart(astNode.sourceStart());
85: this .problem.setSourceEnd(astNode.sourceEnd());
86: int[] lineEnds = unitResult.getLineSeparatorPositions();
87: this .problem.setSourceLineNumber(Util.getLineNumber(astNode
88: .sourceStart(), lineEnds, 0, lineEnds.length - 1));
89: this.compilationResult = unitResult;
90: }
91: }
|