KickJava   Java API By Example, From Geeks To Geeks.

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


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.runtime.CoreException;
17 import org.eclipse.core.runtime.OperationCanceledException;
18 import org.eclipse.debug.core.model.IBreakpoint;
19 import org.eclipse.jdt.core.ICompilationUnit;
20 import org.eclipse.jdt.core.IJavaElement;
21 import org.eclipse.jdt.core.IPackageFragment;
22 import org.eclipse.jdt.core.IPackageFragmentRoot;
23 import org.eclipse.jdt.core.IType;
24 import org.eclipse.jdt.debug.core.IJavaBreakpoint;
25 import org.eclipse.jdt.internal.debug.ui.BreakpointUtils;
26
27 /**
28  * Breakpoint participant for package rename.
29  *
30  * @since 3.2
31  */

32 public class BreakpointRenamePackageParticipant extends BreakpointRenameParticipant {
33
34     /* (non-Javadoc)
35      * @see org.eclipse.jdt.internal.debug.core.refactoring.BreakpointRenameParticipant#accepts(org.eclipse.jdt.core.IJavaElement)
36      */

37     protected boolean accepts(IJavaElement element) {
38         return element instanceof IPackageFragment;
39     }
40     
41     /* (non-Javadoc)
42      * @see org.eclipse.jdt.internal.debug.core.refactoring.BreakpointRenameParticipant#gatherChanges(org.eclipse.core.resources.IMarker[], java.util.List, java.lang.String)
43      */

44     protected void gatherChanges(IMarker[] markers, List JavaDoc changes, String JavaDoc destPackageName) throws CoreException, OperationCanceledException {
45         IPackageFragment originalPackage = (IPackageFragment) getOriginalElement();
46         String JavaDoc originalPackageName = originalPackage.getElementName();
47         IPackageFragmentRoot root = (IPackageFragmentRoot)originalPackage.getParent();
48         for (int i = 0; i < markers.length; i++) {
49             IMarker marker = markers[i];
50             IBreakpoint breakpoint = getBreakpoint(marker);
51             if (breakpoint instanceof IJavaBreakpoint) {
52                 IJavaBreakpoint javaBreakpoint = (IJavaBreakpoint) breakpoint;
53                 IType breakpointType = BreakpointUtils.getType(javaBreakpoint);
54                 if (breakpointType != null) {
55                     String JavaDoc breakpointPackageName = breakpointType.getPackageFragment().getElementName();
56                     String JavaDoc destBreakpointPackageName = destPackageName;
57                     if (breakpointPackageName.length() > originalPackageName.length()) {
58                         destBreakpointPackageName += breakpointPackageName.substring(originalPackageName.length());
59                     }
60                     IPackageFragment destBreakpointPackage = root.getPackageFragment(destBreakpointPackageName);
61                     ICompilationUnit cu = destBreakpointPackage.getCompilationUnit(breakpointType.getCompilationUnit().getElementName());
62                     IJavaElement element = BreakpointChange.findElement(cu, breakpointType);
63                     if (element != null) {
64                         if (element instanceof IType) {
65                             IType destType = (IType) element;
66                             changes.add(createTypeChange(javaBreakpoint, destType, breakpointType));
67                         }
68                     }
69                 }
70             }
71         }
72     }
73
74 }
75
Popular Tags