01: /*******************************************************************************
02: * Copyright (c) 2000, 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.jdt.internal.corext.refactoring;
11:
12: import org.eclipse.core.runtime.Assert;
13:
14: import org.eclipse.jdt.core.IType;
15: import org.eclipse.jdt.core.dom.ITypeBinding;
16:
17: public class ExceptionInfo {
18: private final IType fType;
19: private final ITypeBinding fTypeBinding;
20: private int fKind;
21:
22: public static final int OLD = 0;
23: public static final int ADDED = 1;
24: public static final int DELETED = 2;
25:
26: public ExceptionInfo(IType type, int kind, ITypeBinding binding) {
27: Assert.isNotNull(type);
28: fType = type;
29: fKind = kind;
30: fTypeBinding = binding;
31: }
32:
33: public static ExceptionInfo createInfoForOldException(IType type,
34: ITypeBinding binding) {
35: return new ExceptionInfo(type, OLD, binding);
36: }
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 toString() {
80: StringBuffer result = new StringBuffer();
81: switch (fKind) {
82: case OLD:
83: result.append("OLD: ");break; //$NON-NLS-1$
84: case ADDED:
85: result.append("ADDED: ");break; //$NON-NLS-1$
86: case DELETED:
87: result.append("DELETED: ");break; //$NON-NLS-1$
88: }
89: if (fType == null)
90: result.append("null"); //$NON-NLS-1$
91: else
92: result.append(fType.toString());
93: return result.toString();
94: }
95: }
|