1 11 12 package org.eclipse.jdt.internal.debug.core.refactoring; 13 14 import java.text.MessageFormat ; 15 import java.util.Map ; 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 30 public class JavaWatchpointTypeChange extends JavaLineBreakpointTypeChange { 31 32 private String fFieldName; 33 private boolean fIsAccess; 34 private boolean fIsModification; 35 36 public JavaWatchpointTypeChange(IJavaWatchpoint watchpoint, Object changedElement, Object 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 46 public String getErrorMessageNoMoreExists() { 47 return MessageFormat.format(RefactoringMessages.JavaWatchpointTypeChange_0, new String [] {getDeclaringType().getElementName(), fFieldName}); } 49 50 53 public String getName() { 54 return MessageFormat.format(RefactoringMessages.JavaWatchpointTypeChange_1, new String [] {getDeclaringType().getElementName(), fFieldName}); } 56 57 60 public Change performChange(IType newType, Object undoChangedElement, Object 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 attributes= getAttributes(); 70 BreakpointUtils.addJavaBreakpointAttributes(attributes, newField); 71 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 getBreakpoint().delete(); 87 return new JavaWatchpointTypeChange(newWatchpoint, undoChangedElement, undoArgument, changeType); 88 } 89 90 } 91 | Popular Tags |