1 11 package org.eclipse.jdt.internal.debug.core.refactoring; 12 13 import java.util.ArrayList ; 14 import java.util.List ; 15 16 import org.eclipse.core.resources.IMarker; 17 import org.eclipse.core.resources.IResource; 18 import org.eclipse.core.runtime.CoreException; 19 import org.eclipse.core.runtime.IProgressMonitor; 20 import org.eclipse.core.runtime.OperationCanceledException; 21 import org.eclipse.debug.core.DebugPlugin; 22 import org.eclipse.debug.core.model.IBreakpoint; 23 import org.eclipse.jdt.core.IJavaElement; 24 import org.eclipse.jdt.core.IType; 25 import org.eclipse.jdt.debug.core.IJavaBreakpoint; 26 import org.eclipse.jdt.debug.core.IJavaClassPrepareBreakpoint; 27 import org.eclipse.jdt.debug.core.IJavaExceptionBreakpoint; 28 import org.eclipse.jdt.debug.core.IJavaLineBreakpoint; 29 import org.eclipse.jdt.debug.core.IJavaMethodBreakpoint; 30 import org.eclipse.jdt.debug.core.IJavaWatchpoint; 31 import org.eclipse.ltk.core.refactoring.Change; 32 import org.eclipse.ltk.core.refactoring.CompositeChange; 33 import org.eclipse.ltk.core.refactoring.RefactoringStatus; 34 import org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext; 35 import org.eclipse.ltk.core.refactoring.participants.RenameParticipant; 36 37 42 public abstract class BreakpointRenameParticipant extends RenameParticipant { 43 44 47 private IJavaElement fElement; 48 49 52 protected boolean initialize(Object element) { 53 if (element instanceof IJavaElement && accepts((IJavaElement)element)) { 54 fElement = (IJavaElement) element; 55 } else { 56 return false; 57 } 58 return true; 59 } 60 61 66 protected IJavaElement getOriginalElement() { 67 return fElement; 68 } 69 70 76 protected abstract boolean accepts(IJavaElement element); 77 78 81 public String getName() { 82 return RefactoringMessages.BreakpointRenameParticipant_0; 83 } 84 85 88 public RefactoringStatus checkConditions(IProgressMonitor pm, CheckConditionsContext context) throws OperationCanceledException { 89 return new RefactoringStatus(); 90 } 91 92 95 public Change createChange(IProgressMonitor pm) throws CoreException, OperationCanceledException { 96 List changes = new ArrayList (); 97 IResource resource = getBreakpointContainer(); 98 IMarker[] markers= resource.findMarkers(IBreakpoint.BREAKPOINT_MARKER, true, IResource.DEPTH_INFINITE); 99 gatherChanges(markers, changes, getArguments().getNewName()); 100 if (changes.size() > 1) { 101 return new CompositeChange(RefactoringMessages.BreakpointRenameParticipant_1, (Change[]) changes.toArray(new Change[changes.size()])); 102 } else if (changes.size() == 1) { 103 return (Change) changes.get(0); 104 } 105 return null; 106 } 107 108 118 protected abstract void gatherChanges(IMarker[] markers, List changes, String destName) throws CoreException, OperationCanceledException; 119 120 125 protected IResource getBreakpointContainer() { 126 return fElement.getResource(); 127 } 128 129 135 protected IBreakpoint getBreakpoint(IMarker marker) { 136 return DebugPlugin.getDefault().getBreakpointManager().getBreakpoint(marker); 137 } 138 139 144 protected Change createTypeChange(IJavaBreakpoint breakpoint, IType destType, IType originalType) throws CoreException { 145 if (breakpoint instanceof IJavaWatchpoint) { 146 return new WatchpointTypeChange((IJavaWatchpoint) breakpoint, destType, originalType); 147 } else if (breakpoint instanceof IJavaClassPrepareBreakpoint) { 148 return new ClassPrepareBreakpointTypeChange((IJavaClassPrepareBreakpoint) breakpoint, destType); 149 } else if (breakpoint instanceof IJavaMethodBreakpoint) { 150 return new MethodBreakpointTypeChange((IJavaMethodBreakpoint) breakpoint, destType); 151 } else if (breakpoint instanceof IJavaExceptionBreakpoint) { 152 return new ExceptionBreakpointTypeChange((IJavaExceptionBreakpoint) breakpoint, destType); 153 } else if (breakpoint instanceof IJavaLineBreakpoint) { 154 return new LineBreakpointTypeChange((IJavaLineBreakpoint) breakpoint, destType); 155 } 156 return null; 157 } 158 159 166 protected boolean isContained(IJavaElement container, IType type) { 167 IJavaElement parent = type; 168 while (parent != null) { 169 if (parent.equals(container)) { 170 return true; 171 } 172 parent = parent.getParent(); 173 } 174 return false; 175 } 176 } 177 | Popular Tags |