KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2005, 2007 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.IProject;
17 import org.eclipse.core.resources.IResource;
18 import org.eclipse.core.resources.ResourcesPlugin;
19 import org.eclipse.core.runtime.CoreException;
20 import org.eclipse.core.runtime.OperationCanceledException;
21 import org.eclipse.debug.core.model.IBreakpoint;
22 import org.eclipse.jdt.core.IJavaElement;
23 import org.eclipse.jdt.core.IJavaProject;
24 import org.eclipse.jdt.core.IPackageFragment;
25 import org.eclipse.jdt.core.IPackageFragmentRoot;
26 import org.eclipse.jdt.core.IType;
27 import org.eclipse.jdt.core.JavaCore;
28 import org.eclipse.jdt.debug.core.IJavaBreakpoint;
29 import org.eclipse.jdt.internal.debug.ui.BreakpointUtils;
30
31 /**
32  * Breakpoint participant for project rename.
33  *
34  * @since 3.2
35  */

36 public class BreakpointRenameProjectParticipant extends BreakpointRenameParticipant {
37
38     /* (non-Javadoc)
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 IJavaProject;
43     }
44
45     /* (non-Javadoc)
46      * @see org.eclipse.jdt.internal.debug.core.refactoring.BreakpointRenameParticipant#gatherChanges(org.eclipse.core.resources.IMarker[], java.util.List, java.lang.String)
47      */

48     protected void gatherChanges(IMarker[] markers, List JavaDoc changes, String JavaDoc destProjectName) throws CoreException, OperationCanceledException {
49         IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(destProjectName);
50         IJavaProject destProject = JavaCore.create(project);
51         for (int i = 0; i < markers.length; i++) {
52             IMarker marker = markers[i];
53             IBreakpoint breakpoint = getBreakpoint(marker);
54             if (breakpoint instanceof IJavaBreakpoint) {
55                 IJavaBreakpoint javaBreakpoint = (IJavaBreakpoint) breakpoint;
56                 IType breakpointType = BreakpointUtils.getType(javaBreakpoint);
57                 if (breakpointType != null) {
58                     IPackageFragmentRoot root = (IPackageFragmentRoot) breakpointType.getPackageFragment().getParent();
59                     IResource rootResource = null;
60                     if (root.getCorrespondingResource().equals(getOriginalElement().getCorrespondingResource())) {
61                         rootResource = project;
62                     } else {
63                         if (root.isArchive()) {
64                             rootResource = project.getFile(root.getElementName());
65                         } else {
66                             rootResource = project.getFolder(root.getElementName());
67                         }
68                     }
69                     IPackageFragmentRoot destRoot = destProject.getPackageFragmentRoot(rootResource);
70                     IPackageFragment destPackage = destRoot.getPackageFragment(breakpointType.getPackageFragment().getElementName());
71                     IJavaElement parentElement = null;
72                     if (breakpointType.isBinary()) {
73                         parentElement = destPackage.getClassFile(breakpointType.getClassFile().getElementName());
74                     } else {
75                         parentElement = destPackage.getCompilationUnit(breakpointType.getCompilationUnit().getElementName());
76                     }
77                     IJavaElement element = BreakpointChange.findElement(parentElement, breakpointType);
78                     if (element != null) {
79                         if (element instanceof IType) {
80                             IType destType = (IType) element;
81                             changes.add(createTypeChange(javaBreakpoint, destType, breakpointType));
82                         }
83                     }
84                 }
85             }
86         }
87     }
88     
89 }
90
Popular Tags