KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > javacore > jmiimpl > javamodel > ArgumentListImpl


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 package org.netbeans.modules.javacore.jmiimpl.javamodel;
20
21 import java.util.ArrayList JavaDoc;
22 import java.util.Iterator JavaDoc;
23 import java.util.List JavaDoc;
24 import org.netbeans.jmi.javamodel.ArgumentList;
25 import org.netbeans.jmi.javamodel.ArgumentListClass;
26 import org.netbeans.jmi.javamodel.Element;
27 import org.netbeans.jmi.javamodel.JavaModelPackage;
28 import org.netbeans.lib.java.parser.ASTree;
29 import org.netbeans.mdr.storagemodel.StorableObject;
30 import org.netbeans.modules.javacore.parser.ASTProvider;
31
32 /**
33  *
34  * @author Martin Matula
35  */

36 public abstract class ArgumentListImpl extends TransientElement implements ArgumentList {
37     private LightAttrList arguments;
38     
39     /** Creates a new instance of ArgumentListImpl */
40     public ArgumentListImpl(StorableObject o) {
41         super(o);
42     }
43     
44     public List JavaDoc getArguments() {
45         if (!childrenInited) {
46             initChildren();
47         }
48         return arguments;
49     }
50     
51     void setData(List JavaDoc arguments) {
52         this.arguments = createChildrenList("arguments", arguments, CHANGED_ARGUMENTS); // NOI18N
53
}
54     
55     protected void _delete() {
56         // --- delete components -------------------------------------------
57
if (childrenInited) {
58             deleteChildren(arguments);
59         }
60         // --- delete links -----------------------------------------------
61
// no links to delete
62
// --- call super ---------------------------------------
63
super._delete();
64     }
65     
66     public void replaceChild(Element oldElement, Element newElement) {
67         if (childrenInited) {
68             replaceObject(getArguments(), oldElement, newElement);
69         }
70     }
71
72     public List JavaDoc getChildren() {
73         return new ArrayList JavaDoc(getArguments());
74     }
75     
76     protected void initChildren() {
77         childrenInited = false;
78         arguments = createChildrenList(arguments, "arguments", getASTree().getSubTrees(), CHANGED_ARGUMENTS, false); // NOI18N
79
childrenInited = true;
80     }
81     
82     public String JavaDoc getSourceText() {
83         String JavaDoc origElem;
84         if ((origElem = checkChange()) != null)
85             return origElem;
86         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
87         List JavaDoc arguments = getArguments();
88         for (Iterator JavaDoc iter = arguments.iterator(); iter.hasNext();) {
89             StatementImpl expr = (StatementImpl) iter.next();
90             buf.append(expr.getSourceText());
91             if (iter.hasNext()) {
92                 buf.append(", "); // NOI18N
93
}
94         }
95         return buf.toString();
96     }
97
98     public void getDiff(List JavaDoc diff) {
99         ASTProvider parser = getParser();
100         ASTree tree = getASTree();
101         ASTree[] children = tree.getSubTrees();
102         if (children == null)
103             children = new ASTree[0];
104         int pos = parser.getToken(tree.getLastToken()).getStartOffset();
105         getCollectionDiff(diff, parser, CHANGED_ARGUMENTS, children, getArguments(), pos, ", "); // NOI18N
106
}
107     
108     public Element duplicate(JavaModelPackage targetExtent) {
109         return targetExtent.getArgumentList().createArgumentList(duplicateList(getArguments(), targetExtent));
110     }
111 }
112
Popular Tags