Makefile fixup
[org.ibex.tool.git] / src / org / eclipse / jdt / internal / compiler / problem / AbortCompilation.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 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
7  * 
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11 package org.eclipse.jdt.internal.compiler.problem;
12
13 import org.eclipse.jdt.core.compiler.IProblem;
14 import org.eclipse.jdt.internal.compiler.CompilationResult;
15 import org.eclipse.jdt.internal.compiler.ast.ASTNode;
16 import org.eclipse.jdt.internal.compiler.lookup.InvocationSite;
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 IProblem 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, IProblem problem) {
41                 this();
42                 this.compilationResult = compilationResult;
43                 this.problem = problem;
44         }
45
46         public AbortCompilation(CompilationResult compilationResult, Throwable exception) {
47                 this();
48                 this.compilationResult = compilationResult;
49                 this.exception = exception;
50         }
51
52         public AbortCompilation(boolean isSilent, RuntimeException silentException) {
53                 this();
54                 this.isSilent = isSilent;
55                 this.silentException = silentException;
56         }
57         
58         public void updateContext(InvocationSite invocationSite, CompilationResult unitResult) {
59                 if (this.problem == null) return;
60                 if (this.problem.getSourceStart() != 0 || this.problem.getSourceEnd() != 0) return;
61                 this.problem.setSourceStart(invocationSite.sourceStart());
62                 this.problem.setSourceEnd(invocationSite.sourceEnd());
63                 this.problem.setSourceLineNumber(ProblemHandler.searchLineNumber(unitResult.lineSeparatorPositions, invocationSite.sourceStart()));
64                 this.compilationResult = unitResult;
65         }
66
67         public void updateContext(ASTNode astNode, CompilationResult unitResult) {
68                 if (this.problem == null) return;
69                 if (this.problem.getSourceStart() != 0 || this.problem.getSourceEnd() != 0) return;
70                 this.problem.setSourceStart(astNode.sourceStart());
71                 this.problem.setSourceEnd(astNode.sourceEnd());
72                 this.problem.setSourceLineNumber(ProblemHandler.searchLineNumber(unitResult.lineSeparatorPositions, astNode.sourceStart()));
73                 this.compilationResult = unitResult;
74         }
75 }