removed Makefile; lifted repo/org.ibex.tool/src/ to src/
[org.ibex.tool.git] / src / org / eclipse / jdt / internal / compiler / classfmt / ClassFormatException.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 IBM Corporation and others. All rights reserved.
3  * This program and the accompanying materials are made available under the
4  * terms of the Common Public License v1.0 which accompanies this distribution,
5  * and is available at http://www.eclipse.org/legal/cpl-v10.html
6  * 
7  * Contributors: IBM Corporation - initial API and implementation
8  ******************************************************************************/
9 package org.eclipse.jdt.internal.compiler.classfmt;
10 import java.io.PrintStream;
11 import java.io.PrintWriter;
12 public class ClassFormatException extends Exception {
13         public static final int ErrBadMagic = 1;
14         public static final int ErrBadMinorVersion = 2;
15         public static final int ErrBadMajorVersion = 3;
16         public static final int ErrBadConstantClass = 4;
17         public static final int ErrBadConstantString = 5;
18         public static final int ErrBadConstantNameAndType = 6;
19         public static final int ErrBadConstantFieldRef = 7;
20         public static final int ErrBadConstantMethodRef = 8;
21         public static final int ErrBadConstantInterfaceMethodRef = 9;
22         public static final int ErrBadConstantPoolIndex = 10;
23         public static final int ErrBadSuperclassName = 11;
24         public static final int ErrInterfaceCannotBeFinal = 12;
25         public static final int ErrInterfaceMustBeAbstract = 13;
26         public static final int ErrBadModifiers = 14;
27         public static final int ErrClassCannotBeAbstractFinal = 15;
28         public static final int ErrBadClassname = 16;
29         public static final int ErrBadFieldInfo = 17;
30         public static final int ErrBadMethodInfo = 17;
31         public static final int ErrEmptyConstantPool = 18;
32         public static final int ErrMalformedUtf8 = 19;
33         public static final int ErrUnknownConstantTag = 20;
34         public static final int ErrTruncatedInput = 21;
35         public static final int ErrMethodMustBeAbstract = 22;
36         public static final int ErrMalformedAttribute = 23;
37         public static final int ErrBadInterface = 24;
38         public static final int ErrInterfaceMustSubclassObject = 25;
39         public static final int ErrIncorrectInterfaceMethods = 26;
40         public static final int ErrInvalidMethodName = 27;
41         public static final int ErrInvalidMethodSignature = 28;
42
43         private static final long serialVersionUID = 6667458511042774540L; // backward compatible
44
45         private int errorCode;
46         private int bufferPosition;
47         private RuntimeException nestedException;
48         private char[] fileName;
49
50         public ClassFormatException(RuntimeException e, char[] fileName) {
51                 this.nestedException = e;
52         }
53         public ClassFormatException(int code) {
54                 errorCode = code;
55         }
56         public ClassFormatException(int code, int bufPos) {
57                 errorCode = code;
58                 bufferPosition = bufPos;
59         }
60         /**
61          * @return int
62          */
63         public int getErrorCode() {
64                 return errorCode;
65         }
66         /**
67          * @return int
68          */
69         public int getBufferPosition() {
70                 return bufferPosition;
71         }
72         /**
73          * Returns the underlying <code>Throwable</code> that caused the failure.
74          * 
75          * @return the wrappered <code>Throwable</code>, or <code>null</code>
76          *         if the direct case of the failure was at the Java model layer
77          */
78         public Throwable getException() {
79                 return this.nestedException;
80         }
81         public void printStackTrace() {
82                 printStackTrace(System.err);
83         }
84         /**
85          * Prints this exception's stack trace to the given print stream.
86          * 
87          * @param output
88          *            the print stream
89          * @since 3.0
90          */
91         public void printStackTrace(PrintStream output) {
92                 synchronized (output) {
93                         super.printStackTrace(output);
94                         Throwable throwable = getException();
95                         if (throwable != null) {
96                                 if (this.fileName != null) {
97                                         output.print("Caused in "); //$NON-NLS-1$
98                                         output.print(this.fileName);
99                                         output.print(" by: "); //$NON-NLS-1$
100                                 } else {
101                                         output.print("Caused by: "); //$NON-NLS-1$
102                                 }
103                                 throwable.printStackTrace(output);
104                         }
105                 }
106         }
107         /**
108          * Prints this exception's stack trace to the given print writer.
109          * 
110          * @param output
111          *            the print writer
112          * @since 3.0
113          */
114         public void printStackTrace(PrintWriter output) {
115                 synchronized (output) {
116                         super.printStackTrace(output);
117                         Throwable throwable = getException();
118                         if (throwable != null) {
119                                 if (this.fileName != null) {
120                                         output.print("Caused in "); //$NON-NLS-1$
121                                         output.print(this.fileName);
122                                         output.print(" by: "); //$NON-NLS-1$
123                                 } else {
124                                         output.print("Caused by: "); //$NON-NLS-1$
125                                 }
126                                 throwable.printStackTrace(output);
127                         }
128                 }
129         }
130 }