KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > compiler > problem > AbortCompilation


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-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.CategorizedProblem;
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 import org.eclipse.jdt.internal.compiler.util.Util;
18
19 /*
20  * Special unchecked exception type used
21  * to abort from the compilation process
22  *
23  * should only be thrown from within problem handlers.
24  */

25 public class AbortCompilation extends RuntimeException JavaDoc {
26
27     public CompilationResult compilationResult;
28     public Throwable JavaDoc exception;
29     public CategorizedProblem problem;
30     
31     /* special fields used to abort silently (e.g. when cancelling build process) */
32     public boolean isSilent;
33     public RuntimeException JavaDoc silentException;
34
35     private static final long serialVersionUID = -2047226595083244852L; // backward compatible
36

37     public AbortCompilation() {
38         // empty
39
}
40
41     public AbortCompilation(CompilationResult compilationResult, CategorizedProblem problem) {
42         this();
43         this.compilationResult = compilationResult;
44         this.problem = problem;
45     }
46
47     public AbortCompilation(CompilationResult compilationResult, Throwable JavaDoc exception) {
48         this();
49         this.compilationResult = compilationResult;
50         this.exception = exception;
51     }
52
53     public AbortCompilation(boolean isSilent, RuntimeException JavaDoc silentException) {
54         this();
55         this.isSilent = isSilent;
56         this.silentException = silentException;
57     }
58     
59     public void updateContext(InvocationSite invocationSite, CompilationResult unitResult) {
60         if (this.problem == null) return;
61         if (this.problem.getSourceStart() != 0 || this.problem.getSourceEnd() != 0) return;
62         this.problem.setSourceStart(invocationSite.sourceStart());
63         this.problem.setSourceEnd(invocationSite.sourceEnd());
64         int[] lineEnds = unitResult.getLineSeparatorPositions();
65         this.problem.setSourceLineNumber(Util.getLineNumber(invocationSite.sourceStart(), lineEnds, 0, lineEnds.length-1));
66         this.compilationResult = unitResult;
67     }
68
69     public void updateContext(ASTNode astNode, CompilationResult unitResult) {
70         if (this.problem == null) return;
71         if (this.problem.getSourceStart() != 0 || this.problem.getSourceEnd() != 0) return;
72         this.problem.setSourceStart(astNode.sourceStart());
73         this.problem.setSourceEnd(astNode.sourceEnd());
74         int[] lineEnds = unitResult.getLineSeparatorPositions();
75         this.problem.setSourceLineNumber(Util.getLineNumber(astNode.sourceStart(), lineEnds, 0, lineEnds.length-1));
76         this.compilationResult = unitResult;
77     }
78 }
79
Popular Tags