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.MoveParticipant; 36 37 42 public abstract class BreakpointMoveParticipant extends MoveParticipant { 43 44 47 private IJavaElement fElement; 48 49 52 private IJavaElement fDestination; 53 54 57 protected boolean initialize(Object element) { 58 if (element instanceof IJavaElement && accepts((IJavaElement)element)) { 59 fElement = (IJavaElement) element; 60 fDestination = (IJavaElement) getArguments().getDestination(); 61 } else { 62 return false; 63 } 64 return true; 65 } 66 67 72 protected IJavaElement getOriginalElement() { 73 return fElement; 74 } 75 76 81 protected IJavaElement getDestination() { 82 return fDestination; 83 } 84 85 91 protected abstract boolean accepts(IJavaElement element); 92 93 96 public String getName() { 97 return RefactoringMessages.BreakpointRenameParticipant_0; 98 } 99 100 103 public RefactoringStatus checkConditions(IProgressMonitor pm, CheckConditionsContext context) throws OperationCanceledException { 104 return new RefactoringStatus(); 105 } 106 107 110 public Change createChange(IProgressMonitor pm) throws CoreException, OperationCanceledException { 111 List changes = new ArrayList (); 112 IResource resource = getBreakpointContainer(); 113 IMarker[] markers= resource.findMarkers(IBreakpoint.BREAKPOINT_MARKER, true, IResource.DEPTH_INFINITE); 114 gatherChanges(markers, changes); 115 if (changes.size() > 1) { 116 return new CompositeChange(RefactoringMessages.BreakpointRenameParticipant_1, (Change[]) changes.toArray(new Change[changes.size()])); 117 } else if (changes.size() == 1) { 118 return (Change) changes.get(0); 119 } 120 return null; 121 } 122 123 132 protected abstract void gatherChanges(IMarker[] markers, List changes) throws CoreException, OperationCanceledException; 133 134 139 protected IResource getBreakpointContainer() { 140 return fElement.getResource(); 141 } 142 143 149 protected IBreakpoint getBreakpoint(IMarker marker) { 150 return DebugPlugin.getDefault().getBreakpointManager().getBreakpoint(marker); 151 } 152 153 158 protected Change createTypeChange(IJavaBreakpoint breakpoint, IType destType, IType originalType) throws CoreException { 159 if (breakpoint instanceof IJavaWatchpoint) { 160 return new WatchpointTypeChange((IJavaWatchpoint) breakpoint, destType, originalType); 161 } else if (breakpoint instanceof IJavaClassPrepareBreakpoint) { 162 return new ClassPrepareBreakpointTypeChange((IJavaClassPrepareBreakpoint) breakpoint, destType); 163 } else if (breakpoint instanceof IJavaMethodBreakpoint) { 164 return new MethodBreakpointTypeChange((IJavaMethodBreakpoint) breakpoint, destType); 165 } else if (breakpoint instanceof IJavaExceptionBreakpoint) { 166 return new ExceptionBreakpointTypeChange((IJavaExceptionBreakpoint) breakpoint, destType); 167 } else if (breakpoint instanceof IJavaLineBreakpoint) { 168 return new LineBreakpointTypeChange((IJavaLineBreakpoint) breakpoint, destType); 169 } 170 return null; 171 } 172 173 180 protected boolean isContained(IJavaElement container, IType type) { 181 IJavaElement parent = type; 182 while (parent != null) { 183 if (parent.equals(container)) { 184 return true; 185 } 186 parent = parent.getParent(); 187 } 188 return false; 189 } 190 } 191 | Popular Tags |