1 11 package org.eclipse.jdt.internal.debug.core.refactoring; 12 13 import java.text.MessageFormat ; 14 import java.util.Map ; 15 16 import org.eclipse.core.runtime.CoreException; 17 import org.eclipse.core.runtime.IProgressMonitor; 18 import org.eclipse.debug.core.DebugPlugin; 19 import org.eclipse.debug.core.IBreakpointManager; 20 import org.eclipse.debug.core.model.IBreakpoint; 21 import org.eclipse.jdt.core.IMethod; 22 import org.eclipse.jdt.core.IType; 23 import org.eclipse.jdt.core.Signature; 24 import org.eclipse.jdt.debug.core.IJavaMethodBreakpoint; 25 import org.eclipse.jdt.debug.core.JDIDebugModel; 26 import org.eclipse.jdt.internal.debug.ui.BreakpointUtils; 27 import org.eclipse.jdt.internal.debug.ui.actions.ToggleBreakpointAdapter; 28 import org.eclipse.ltk.core.refactoring.Change; 29 import org.eclipse.ltk.core.refactoring.RefactoringStatus; 30 31 34 public class JavaMethodBreakpointMethodNameChange extends Change { 35 36 private IJavaMethodBreakpoint fMethodBreakpoint; 37 private String fNewMethodName; 38 private String fOldMethodName; 39 private IType fDeclaringType; 40 41 45 public static Change createChange(IMethod method, String newName) throws CoreException { 46 IType declaringType= method.getDeclaringType(); 47 String typeName= declaringType.getFullyQualifiedName(); 48 String methodName= method.getElementName(); 49 String methodSignature= ToggleBreakpointAdapter.resolveMethodSignature(declaringType, method.getSignature()); 50 IBreakpointManager breakpointManager= DebugPlugin.getDefault().getBreakpointManager(); 51 IBreakpoint[] breakpoints= breakpointManager.getBreakpoints(JDIDebugModel.getPluginIdentifier()); 52 for (int i= 0; i < breakpoints.length; i++) { 53 IBreakpoint breakpoint= breakpoints[i]; 54 if (breakpoint instanceof IJavaMethodBreakpoint) { 55 IJavaMethodBreakpoint methodBreakpoint= (IJavaMethodBreakpoint)breakpoint; 56 if (typeName.equals(methodBreakpoint.getTypeName()) && methodName.equals(methodBreakpoint.getMethodName()) && methodSignature.equals(methodBreakpoint.getMethodSignature())) { 57 return new JavaMethodBreakpointMethodNameChange(methodBreakpoint, newName); 58 } 59 } 60 } 61 return null; 62 } 63 64 protected JavaMethodBreakpointMethodNameChange(IJavaMethodBreakpoint methodBreakpoint, String newName) throws CoreException { 65 fMethodBreakpoint= methodBreakpoint; 66 fNewMethodName= newName; 67 fOldMethodName= fMethodBreakpoint.getMethodName(); 68 fDeclaringType= BreakpointUtils.getType(methodBreakpoint); 69 } 70 71 74 public String getName() { 75 return MessageFormat.format(RefactoringMessages.JavaMethodBreakpointMethodNameChange_0, new String [] {fDeclaringType.getElementName(), fOldMethodName}); } 77 78 81 public void initializeValidationData(IProgressMonitor pm) { 82 } 83 84 87 public RefactoringStatus isValid(IProgressMonitor pm) throws CoreException { 88 RefactoringStatus status= new RefactoringStatus(); 89 if (!fMethodBreakpoint.isRegistered()) { 90 status.addFatalError(MessageFormat.format(RefactoringMessages.JavaMethodBreakpointMethodNameChange_1, new String [] {fDeclaringType.getElementName(), fOldMethodName})); } 92 return status; 93 } 94 95 98 public Change perform(IProgressMonitor pm) throws CoreException { 99 String methodSignature= fMethodBreakpoint.getMethodSignature(); 100 String [] parameterTypes= Signature.getParameterTypes(methodSignature); 101 for (int i= 0; i < parameterTypes.length; i++) { 102 parameterTypes[i]= parameterTypes[i].replace('/', '.'); 103 } 104 IMethod method= fDeclaringType.getMethod(fNewMethodName, parameterTypes); 105 Map attributes= fMethodBreakpoint.getMarker().getAttributes(); 106 BreakpointUtils.addJavaBreakpointAttributes(attributes, method); 107 boolean isEnable= fMethodBreakpoint.isEnabled(); 108 IJavaMethodBreakpoint newMethodBreakpoint= JDIDebugModel.createMethodBreakpoint( 109 fMethodBreakpoint.getMarker().getResource(), 110 fMethodBreakpoint.getTypeName(), 111 fNewMethodName, 112 methodSignature, 113 fMethodBreakpoint.isEntry(), 114 fMethodBreakpoint.isExit(), 115 fMethodBreakpoint.isNativeOnly(), 116 fMethodBreakpoint.getLineNumber(), 117 fMethodBreakpoint.getCharStart(), 118 fMethodBreakpoint.getCharEnd(), 119 fMethodBreakpoint.getHitCount(), 120 true, 121 attributes); 122 newMethodBreakpoint.setEnabled(isEnable); 123 fMethodBreakpoint.delete(); 124 return new JavaMethodBreakpointMethodNameChange(newMethodBreakpoint, fOldMethodName); 125 } 126 127 130 public Object getModifiedElement() { 131 return fMethodBreakpoint; 132 } 133 134 } 135 | Popular Tags |