KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ltk > core > refactoring > participants > ReorgExecutionLog


1 /*******************************************************************************
2  * Copyright (c) 2004, 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.ltk.core.refactoring.participants;
12
13 import java.util.ArrayList JavaDoc;
14 import java.util.HashMap JavaDoc;
15 import java.util.List JavaDoc;
16 import java.util.Map JavaDoc;
17
18 /**
19  * Objects of this class can be used as a log to trace the
20  * execution of refactorings like copy and paste
21  * <p>
22  * This class is not intended to be subclassed by clients.
23  * </p>
24  *
25  * @since 3.1
26  */

27 public class ReorgExecutionLog {
28     
29     private Map JavaDoc fNewNames;
30     private List JavaDoc fProcessedElements;
31     private boolean fCanceled;
32     
33     /**
34      * Creates new reorg execution log
35      */

36     public ReorgExecutionLog() {
37         fNewNames= new HashMap JavaDoc();
38         fProcessedElements= new ArrayList JavaDoc();
39     }
40
41     /**
42      * Logs that the reorg refactoring got canceled by the
43      * user.
44      */

45     public void markAsCanceled() {
46         fCanceled= true;
47     }
48     
49     /**
50      * Returns <code>true</code> if the reorg refactoring got
51      * canceled; otherwise <code>false</code>
52      *
53      * @return whether the refactoring got canceled or not
54      */

55     public boolean isCanceled() {
56         return fCanceled;
57     }
58
59     /**
60      * Returns <code>true</code> if the specified element has been processed;
61      * otherwise <code>false</code>
62      *
63      * @param element
64      * the element to test
65      * @return whether the specified element has been processed
66      * @since 3.3
67      */

68     public boolean isProcessed(Object JavaDoc element) {
69         return fProcessedElements.contains(element);
70     }
71
72     /**
73      * Returns <code>true</code> if the specified element has been renamed;
74      * otherwise <code>false</code>
75      *
76      * @param element
77      * the element to test
78      * @return whether the specified element has been renamed
79      * @since 3.3
80      */

81     public boolean isRenamed(Object JavaDoc element) {
82         return fNewNames.keySet().contains(element);
83     }
84
85     /**
86      * Logs that the given element got processed by the
87      * refactoring
88      *
89      * @param element the element that got processed
90      */

91     public void markAsProcessed(Object JavaDoc element) {
92         fProcessedElements.add(element);
93     }
94     
95     /**
96      * Returns all processed elements
97      *
98      * @return all processed elements
99      */

100     public Object JavaDoc[] getProcessedElements() {
101         return fProcessedElements.toArray();
102     }
103     
104     /**
105      * Logs that the element got renamed to <code>newName
106      * </code> by the reorg refactoring.
107      *
108      * @param element the element which got renamed
109      * @param newName the new name of the element
110      */

111     public void setNewName(Object JavaDoc element, String JavaDoc newName) {
112         fNewNames.put(element, newName);
113     }
114     
115     /**
116      * Returns all elements which got renamed during the
117      * reorg refactoring
118      *
119      * @return the renamed elements
120      */

121     public Object JavaDoc[] getRenamedElements() {
122         return fNewNames.keySet().toArray();
123     }
124     
125     /**
126      * Returns the new name of the element. Returns <code>
127      * null</code> if the element didn't get renamed.
128      *
129      * @param element the element for which the new name is
130      * requested
131      * @return the new name of <code>null</code>
132      */

133     public String JavaDoc getNewName(Object JavaDoc element) {
134         return (String JavaDoc)fNewNames.get(element);
135     }
136 }
137
Popular Tags