82adfab495e76ef1433948c14c3ff5925058008c
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / formatter / align / AlignmentException.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 International Business Machines Corp. 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 net.sourceforge.phpdt.internal.formatter.align;
12
13 /**
14  * Exception used to backtrack and break available alignments When the exception
15  * is thrown, it is assumed that some alignment will be changed.
16  * 
17  * @since 2.1
18  */
19 public class AlignmentException extends RuntimeException {
20
21         public static final int LINE_TOO_LONG = 1;
22
23         public static final int ALIGN_TOO_SMALL = 2;
24
25         int reason;
26
27         int value;
28
29         public int relativeDepth;
30
31         public AlignmentException(int reason, int relativeDepth) {
32                 this(reason, 0, relativeDepth);
33         }
34
35         public AlignmentException(int reason, int value, int relativeDepth) {
36                 this.reason = reason;
37                 this.value = value;
38                 this.relativeDepth = relativeDepth;
39         }
40
41         public String toString() {
42                 StringBuffer buffer = new StringBuffer(10);
43                 switch (this.reason) {
44                 case LINE_TOO_LONG:
45                         buffer.append("LINE_TOO_LONG"); //$NON-NLS-1$
46                         break;
47                 case ALIGN_TOO_SMALL:
48                         buffer.append("ALIGN_TOO_SMALL"); //$NON-NLS-1$
49                         break;
50                 }
51                 buffer.append("<relativeDepth: ") //$NON-NLS-1$
52                                 .append(this.relativeDepth).append(">\n"); //$NON-NLS-1$
53                 return buffer.toString();
54         }
55 }