KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > corext > refactoring > ExceptionInfo


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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.corext.refactoring;
12
13 import org.eclipse.core.runtime.Assert;
14
15 import org.eclipse.jdt.core.IType;
16 import org.eclipse.jdt.core.dom.ITypeBinding;
17
18
19 public class ExceptionInfo {
20     private final IType fType;
21     private final ITypeBinding fTypeBinding;
22     private int fKind;
23
24     public static final int OLD= 0;
25     public static final int ADDED= 1;
26     public static final int DELETED= 2;
27     
28     public ExceptionInfo(IType type, int kind, ITypeBinding binding) {
29         Assert.isNotNull(type);
30         fType= type;
31         fKind= kind;
32         fTypeBinding= binding;
33     }
34
35     public static ExceptionInfo createInfoForOldException(IType type, ITypeBinding binding){
36         return new ExceptionInfo(type, OLD, binding);
37     }
38     public static ExceptionInfo createInfoForAddedException(IType type){
39         return new ExceptionInfo(type, ADDED, null);
40     }
41     
42     public void markAsDeleted(){
43         Assert.isTrue(! isAdded());//added exception infos should be simply removed from the list
44
fKind= DELETED;
45     }
46     
47     public void markAsOld(){
48         Assert.isTrue(isDeleted());
49         fKind= OLD;
50     }
51     
52     public boolean isAdded(){
53         return fKind == ADDED;
54     }
55     
56     public boolean isDeleted(){
57         return fKind == DELETED;
58     }
59     
60     public boolean isOld(){
61         return fKind == OLD;
62     }
63     
64     public IType getType() {
65         return fType;
66     }
67     
68     public int getKind() {
69         return fKind;
70     }
71     
72     /**
73      * @return ITypeBinding the typeBinding (for OLD and DELETED exceptions) or <code>null</code>
74      */

75     public ITypeBinding getTypeBinding() {
76         return fTypeBinding;
77     }
78     
79     public String JavaDoc toString() {
80         StringBuffer JavaDoc result= new StringBuffer JavaDoc();
81         switch (fKind) {
82             case OLD : result.append("OLD: "); break; //$NON-NLS-1$
83
case ADDED : result.append("ADDED: "); break; //$NON-NLS-1$
84
case DELETED : result.append("DELETED: "); break; //$NON-NLS-1$
85
}
86         if (fType == null)
87             result.append("null"); //$NON-NLS-1$
88
else
89             result.append(fType.toString());
90         return result.toString();
91     }
92 }
93
Popular Tags