1 11 package org.eclipse.jdt.internal.debug.core.refactoring; 12 13 import java.util.List ; 14 15 import org.eclipse.core.resources.IMarker; 16 import org.eclipse.core.resources.IResource; 17 import org.eclipse.core.runtime.CoreException; 18 import org.eclipse.core.runtime.OperationCanceledException; 19 import org.eclipse.debug.core.model.IBreakpoint; 20 import org.eclipse.jdt.core.ICompilationUnit; 21 import org.eclipse.jdt.core.IJavaElement; 22 import org.eclipse.jdt.core.IType; 23 import org.eclipse.jdt.core.refactoring.RenameTypeArguments; 24 import org.eclipse.jdt.debug.core.IJavaBreakpoint; 25 import org.eclipse.jdt.debug.core.IJavaWatchpoint; 26 import org.eclipse.jdt.internal.debug.ui.BreakpointUtils; 27 import org.eclipse.ltk.core.refactoring.Change; 28 29 34 public class BreakpointRenameTypeParticipant extends BreakpointRenameParticipant { 35 36 41 protected boolean accepts(IJavaElement element) { 42 return element instanceof IType; 43 } 44 45 protected Change createTypeChange(IJavaBreakpoint breakpoint, IType destType, IType originalType) throws CoreException { 46 if (breakpoint instanceof IJavaWatchpoint) { 47 return new WatchpointTypeRenameChange((IJavaWatchpoint) breakpoint, destType, originalType, getProcessor(), (RenameTypeArguments) getArguments()); 48 } else { 49 return super.createTypeChange(breakpoint, destType, originalType); 50 } 51 } 52 53 59 protected void gatherChanges(IMarker[] markers, List changes, String simpleDestName) throws CoreException, OperationCanceledException { 60 IType originalType = (IType) getOriginalElement(); 61 ICompilationUnit originalCU = originalType.getCompilationUnit(); 62 ICompilationUnit destCU = null; 63 64 IType primaryType = originalCU.findPrimaryType(); 65 if (originalType.isMember() || primaryType == null || !primaryType.equals(originalType)) { 66 destCU = originalCU; 67 } else if (primaryType.equals(originalType)) { 68 String ext = ".java"; IResource res = originalCU.getResource(); 71 if (res != null) { 72 ext = '.' + res.getFileExtension(); 73 } 74 destCU = originalType.getPackageFragment().getCompilationUnit(simpleDestName + ext); 75 } 76 77 IType newType = BreakpointChange.getType(originalType.getParent(), simpleDestName); 79 newType = (IType) BreakpointChange.findElement(destCU, newType); 80 81 82 for (int i = 0; i < markers.length; i++) { 83 IMarker marker = markers[i]; 84 IBreakpoint breakpoint = getBreakpoint(marker); 85 if (breakpoint instanceof IJavaBreakpoint) { 86 IJavaBreakpoint javaBreakpoint = (IJavaBreakpoint) breakpoint; 87 IType breakpointType = BreakpointUtils.getType(javaBreakpoint); 88 IType destType = null; 89 if (breakpointType != null) { 90 IJavaElement element = null; 91 if (isContained(originalType, breakpointType)) { 92 element = BreakpointChange.findElement(newType, breakpointType); 93 } else if (isContained(originalCU, breakpointType)) { 94 element = BreakpointChange.findElement(destCU, breakpointType); 96 } 97 if (element instanceof IType) { 98 destType = (IType) element; 99 changes.add(createTypeChange(javaBreakpoint, destType, breakpointType)); 100 } 101 } 102 103 } 104 } 105 106 } 107 108 } 109 | Popular Tags |