KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > api > java > source > transform > ChangeList


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.api.java.source.transform;
21
22 import com.sun.source.tree.Tree;
23 import java.util.LinkedList JavaDoc;
24 import java.util.Map JavaDoc;
25
26 /**
27  * A Change which consists of a list of other Changes, so related changes
28  * are grouped together.
29  */

30 public class ChangeList extends LinkedList JavaDoc<Change> implements Change {
31     String JavaDoc name;
32     
33     public ChangeList(String JavaDoc refactoringName) {
34         super();
35         name = refactoringName;
36     }
37     
38     /**
39      * Returns the name of the refactoring that created this ChangeList.
40      */

41     public String JavaDoc getRefactoringName() {
42         return name;
43     }
44
45     /**
46      * Returns the changed tree, or null if no change exists for the
47      * specified tree.
48      */

49     public Tree getChange(Tree oldTree) {
50         for (Change item : this) {
51             Tree t = item.getChange(oldTree);
52             if (t != null)
53                 return t;
54         }
55         return null;
56     }
57
58     /**
59      * Returns the old tree for a specified new one, or null if no
60      * original exists for the specified tree.
61      */

62     public Tree getOriginal(Tree newTree) {
63         for (Change item : this) {
64             Tree t = item.getOriginal(newTree);
65             if (t != null)
66                 return t;
67         }
68         return null;
69     }
70
71     /**
72      * Returns true if this Change has a replacement for a specified tree.
73      */

74     public boolean hasChange(Tree old) {
75         for (Change item : this) {
76             if (item.hasChange(old))
77                 return true;
78         }
79         return false;
80     }
81
82     /**
83      * Returns true if this Change has an original for a specified tree.
84      */

85     public boolean hasOriginal(Tree newTree) {
86         for (Change item : this) {
87             if (item.hasOriginal(newTree))
88                 return true;
89         }
90         return false;
91     }
92     
93     /**
94      * Copies all changes into a specified Map.
95      */

96     public void addToMap(Map JavaDoc<Tree,Tree> map) {
97         for (Change ch : this)
98             ch.addToMap(map);
99     }
100 }
101
Popular Tags