KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > debug > core > refactoring > BreakpointRenameTypeParticipant


1 /*******************************************************************************
2  * Copyright (c) 2005, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.debug.core.refactoring;
12
13 import java.util.List JavaDoc;
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 /**
30  * Breakpoint participant for type rename.
31  *
32  * @since 3.2
33  */

34 public class BreakpointRenameTypeParticipant extends BreakpointRenameParticipant {
35
36     /*
37      * (non-Javadoc)
38      *
39      * @see org.eclipse.jdt.internal.debug.core.refactoring.BreakpointRenameParticipant#accepts(org.eclipse.jdt.core.IJavaElement)
40      */

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     /*
54      * (non-Javadoc)
55      *
56      * @see org.eclipse.jdt.internal.debug.core.refactoring.BreakpointRenameParticipant#gatherChanges(org.eclipse.core.resources.IMarker[],
57      * java.util.List, java.lang.String)
58      */

59     protected void gatherChanges(IMarker[] markers, List JavaDoc changes, String JavaDoc 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 JavaDoc ext = ".java"; //$NON-NLS-1$
69
// assume extension is same as original
70
IResource res = originalCU.getResource();
71             if (res != null) {
72                 ext = '.' + res.getFileExtension();
73             }
74             destCU = originalType.getPackageFragment().getCompilationUnit(simpleDestName + ext);
75         }
76         
77         // newType is the type that is changing - it may contain nested members with breakpoints
78
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                         // non public, or other type in the CU
95
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