KickJava   Java API By Example, From Geeks To Geeks.

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


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.HashMap JavaDoc;
14 import java.util.Map JavaDoc;
15
16 import org.eclipse.core.resources.IResource;
17 import org.eclipse.core.runtime.CoreException;
18 import org.eclipse.core.runtime.IProgressMonitor;
19 import org.eclipse.jdt.core.IField;
20 import org.eclipse.jdt.core.IJavaElement;
21 import org.eclipse.jdt.core.IType;
22 import org.eclipse.jdt.core.refactoring.IJavaElementMapper;
23 import org.eclipse.jdt.core.refactoring.RenameTypeArguments;
24 import org.eclipse.jdt.debug.core.IJavaWatchpoint;
25 import org.eclipse.jdt.debug.core.JDIDebugModel;
26 import org.eclipse.jdt.internal.debug.ui.BreakpointUtils;
27 import org.eclipse.ltk.core.refactoring.Change;
28 import org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor;
29
30 public class WatchpointTypeRenameChange extends WatchpointTypeChange {
31
32     private RefactoringProcessor fProcessor;
33     private RenameTypeArguments fArguments;
34
35     public WatchpointTypeRenameChange(IJavaWatchpoint watchpoint, IType destType, IType originalType, RefactoringProcessor processor, RenameTypeArguments arguments) throws CoreException {
36         super(watchpoint, destType, originalType);
37         fProcessor = processor;
38         fArguments = arguments;
39     }
40     
41     public Change perform(IProgressMonitor pm) throws CoreException {
42         IField originalField = getOriginalType().getField(getFieldName());
43         IField destinationField = null;
44         
45         if (fArguments.getUpdateSimilarDeclarations()) {
46             IJavaElement[] similarDeclarations = fArguments.getSimilarDeclarations();
47             if (similarDeclarations != null) {
48                 for (int i = 0; i < similarDeclarations.length; i++) {
49                     IJavaElement element = similarDeclarations[i];
50                     if (element.equals(originalField)) {
51                         IJavaElementMapper elementMapper = (IJavaElementMapper) fProcessor.getAdapter(IJavaElementMapper.class);
52                         destinationField = (IField) elementMapper.getRefactoredJavaElement(originalField);
53                         break;
54                     }
55                 }
56             }
57         }
58         if (destinationField == null) {
59             destinationField = getDestinationType().getField(getFieldName());
60         }
61         
62         Map JavaDoc map = new HashMap JavaDoc();
63         BreakpointUtils.addJavaBreakpointAttributes(map, destinationField);
64         IResource resource = BreakpointUtils.getBreakpointResource(destinationField);
65         int[] range = getNewLineNumberAndRange(destinationField);
66         IJavaWatchpoint breakpoint = JDIDebugModel.createWatchpoint(
67                 resource,
68                 getDestinationType().getFullyQualifiedName(),
69                 destinationField.getElementName(),
70                 range[0],
71                 range[1],
72                 range[2],
73                 getHitCount(),
74                 true,
75                 map);
76         apply(breakpoint);
77         getOriginalBreakpoint().delete();
78         return new DeleteBreakpointChange(breakpoint);
79     }
80
81 }
82
Popular Tags