KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > debug > core > refactoring > WatchpointTypeChange


1 /*******************************************************************************
2  * Copyright (c) 2005, 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.debug.core.refactoring;
12
13 import java.util.HashMap JavaDoc;
14 import java.util.Map JavaDoc;
15
16 import org.eclipse.core.resources.IResource;
17 import org.eclipse.core.runtime.CoreException;
18 import org.eclipse.core.runtime.IProgressMonitor;
19 import org.eclipse.jdt.core.IField;
20 import org.eclipse.jdt.core.IType;
21 import org.eclipse.jdt.debug.core.IJavaWatchpoint;
22 import org.eclipse.jdt.debug.core.JDIDebugModel;
23 import org.eclipse.jdt.internal.debug.ui.BreakpointUtils;
24 import org.eclipse.ltk.core.refactoring.Change;
25
26 import com.ibm.icu.text.MessageFormat;
27
28 /**
29  * @since 3.2
30  *
31  */

32 public class WatchpointTypeChange extends WatchpointChange {
33     
34     private IType fDestType, fOriginalType;
35     
36     public WatchpointTypeChange(IJavaWatchpoint watchpoint, IType destType, IType originalType) throws CoreException {
37         super(watchpoint);
38         fDestType = destType;
39         fOriginalType = originalType;
40     }
41
42     /* (non-Javadoc)
43      * @see org.eclipse.ltk.core.refactoring.Change#getName()
44      */

45     public String JavaDoc getName() {
46         String JavaDoc msg = MessageFormat.format(RefactoringMessages.WatchpointTypeChange_1, new String JavaDoc[] {getBreakpointLabel(getOriginalBreakpoint())});
47         if(!"".equals(fDestType.getElementName())) { //$NON-NLS-1$
48
msg = MessageFormat.format(RefactoringMessages.WatchpointTypeChange_0,
49                 new String JavaDoc[] {getBreakpointLabel(getOriginalBreakpoint()), fDestType.getElementName()});
50         }
51         return msg;
52     }
53
54     /* (non-Javadoc)
55      * @see org.eclipse.ltk.core.refactoring.Change#perform(org.eclipse.core.runtime.IProgressMonitor)
56      */

57     public Change perform(IProgressMonitor pm) throws CoreException {
58         IField destField = fDestType.getField(getFieldName());
59         Map JavaDoc map = new HashMap JavaDoc();
60         BreakpointUtils.addJavaBreakpointAttributes(map, destField);
61         IResource resource = BreakpointUtils.getBreakpointResource(destField);
62         int[] range = getNewLineNumberAndRange(destField);
63         IJavaWatchpoint breakpoint = JDIDebugModel.createWatchpoint(
64                 resource,
65                 fDestType.getFullyQualifiedName(),
66                 getFieldName(),
67                 range[0],
68                 range[1],
69                 range[2],
70                 getHitCount(),
71                 true,
72                 map);
73         apply(breakpoint);
74         getOriginalBreakpoint().delete();
75         return new DeleteBreakpointChange(breakpoint);
76     }
77
78     public IType getDestinationType() {
79         return fDestType;
80     }
81
82     public IType getOriginalType() {
83         return fOriginalType;
84     }
85
86 }
87
Popular Tags