KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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
12 package org.eclipse.jdt.internal.debug.core.refactoring;
13
14 import java.text.MessageFormat JavaDoc;
15 import java.util.Map JavaDoc;
16
17 import org.eclipse.core.runtime.CoreException;
18 import org.eclipse.jdt.core.IField;
19 import org.eclipse.jdt.core.ISourceRange;
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
27 /**
28  * Change to update a watchpoint when a IType is moved or renamed.
29  */

30 public class JavaWatchpointTypeChange extends JavaLineBreakpointTypeChange {
31
32     private String JavaDoc fFieldName;
33     private boolean fIsAccess;
34     private boolean fIsModification;
35
36     public JavaWatchpointTypeChange(IJavaWatchpoint watchpoint, Object JavaDoc changedElement, Object JavaDoc argument, int changeType) throws CoreException {
37         super(watchpoint, changedElement, argument, changeType);
38         fFieldName= watchpoint.getFieldName();
39         fIsAccess= watchpoint.isAccess();
40         fIsModification= watchpoint.isModification();
41     }
42
43     /* (non-Javadoc)
44      * @see org.eclipse.jdt.internal.debug.core.refactoring.JavaBreakpointTypeNameChange#getErrorMessageNoMoreExists()
45      */

46     public String JavaDoc getErrorMessageNoMoreExists() {
47         return MessageFormat.format(RefactoringMessages.JavaWatchpointTypeChange_0, new String JavaDoc[] {getDeclaringType().getElementName(), fFieldName}); //$NON-NLS-1$
48
}
49
50     /* (non-Javadoc)
51      * @see org.eclipse.ltk.core.refactoring.Change#getName()
52      */

53     public String JavaDoc getName() {
54         return MessageFormat.format(RefactoringMessages.JavaWatchpointTypeChange_1, new String JavaDoc[] {getDeclaringType().getElementName(), fFieldName}); //$NON-NLS-1$
55
}
56
57     /* (non-Javadoc)
58      * @see org.eclipse.jdt.internal.debug.core.refactoring.JavaBreakpointTypeNameChange#performChange(org.eclipse.jdt.core.IType, java.lang.String)
59      */

60     public Change performChange(IType newType, Object JavaDoc undoChangedElement, Object JavaDoc undoArgument, int changeType) throws CoreException {
61         IField newField= newType.getField(fFieldName);
62         int start = -1;
63         int end = -1;
64         ISourceRange range = newField.getNameRange();
65         if (range != null) {
66             start = range.getOffset();
67             end = start + range.getLength();
68         }
69         Map JavaDoc attributes= getAttributes();
70         BreakpointUtils.addJavaBreakpointAttributes(attributes, newField);
71         // create the new breakpoint
72
IJavaWatchpoint newWatchpoint= JDIDebugModel.createWatchpoint(
73                 BreakpointUtils.getBreakpointResource(newType),
74                 newType.getFullyQualifiedName(),
75                 fFieldName,
76                 -1,
77                 start,
78                 end,
79                 getHitCount(),
80                 true,
81                 attributes);
82         newWatchpoint.setAccess(fIsAccess);
83         newWatchpoint.setModification(fIsModification);
84         newWatchpoint.setEnabled(getEnable());
85         // delete the old one
86
getBreakpoint().delete();
87         return new JavaWatchpointTypeChange(newWatchpoint, undoChangedElement, undoArgument, changeType);
88     }
89
90 }
91
Popular Tags