KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > ruby > elements > IndexedMethod


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.ruby.elements;
20
21 import java.util.ArrayList JavaDoc;
22 import java.util.Collections JavaDoc;
23 import java.util.List JavaDoc;
24 import java.util.Set JavaDoc;
25
26 import org.netbeans.api.gsf.ElementKind;
27 import org.netbeans.api.gsf.Modifier;
28 import org.netbeans.modules.ruby.RubyIndex;
29 import org.netbeans.modules.ruby.elements.IndexedElement;
30
31
32 /**
33  * A class describing a Ruby method that is rin "textual form" (signature, filename, etc.)
34  * obtained from the code index.
35  *
36  * @todo Consider computing a lot of the extra info (requires, filenames, etc.)
37  * lazily - by just stashing the index map into the RubyMethod. Hopefully Lucene
38  * won't mind if we hang on to this information...
39  *
40  * @author Tor Norbye
41  */

42 public final class IndexedMethod extends IndexedElement implements MethodElement {
43     private String JavaDoc[] args;
44     private String JavaDoc name;
45     protected List JavaDoc<String JavaDoc> parameters;
46
47     private IndexedMethod(String JavaDoc signature, RubyIndex index, String JavaDoc fileUrl, String JavaDoc fqn,
48         String JavaDoc clz, String JavaDoc require, Set JavaDoc<Modifier> modifiers) {
49         super(signature, index, fileUrl, fqn, clz, require, modifiers);
50     }
51
52     public static IndexedMethod create(RubyIndex index, String JavaDoc signature, String JavaDoc fqn, String JavaDoc clz,
53         String JavaDoc fileUrl, String JavaDoc require, Set JavaDoc<Modifier> modifiers) {
54         IndexedMethod m =
55             new IndexedMethod(signature, index, fileUrl, fqn, clz, require, modifiers);
56
57         return m;
58     }
59
60     public boolean isPrivate() {
61         return modifiers.contains(Modifier.PRIVATE) || modifiers.contains(Modifier.PROTECTED);
62     }
63
64     public boolean isStatic() {
65         return modifiers.contains(Modifier.STATIC);
66     }
67     
68     @Override JavaDoc
69     public String JavaDoc toString() {
70         return getSignature();
71     }
72
73     public String JavaDoc getName() {
74         if (name == null) {
75             int index = signature.indexOf('(');
76
77             if (index == -1) {
78                 name = signature;
79             } else {
80                 name = signature.substring(0, index);
81             }
82         }
83
84         return name;
85     }
86
87     @Override JavaDoc
88     public String JavaDoc getSignature() {
89         return fqn + "#" + signature;
90     }
91
92     public String JavaDoc[] getArgs() {
93         if (args == null) {
94             // Parse signature
95
int index = signature.indexOf('(');
96
97             if (index == -1) {
98                 return new String JavaDoc[0];
99             }
100
101             String JavaDoc argsPortion = signature.substring(index + 1, signature.length() - 1);
102             args = argsPortion.split("\\), ");
103         }
104
105         return args;
106     }
107
108     public List JavaDoc<String JavaDoc> getParameters() {
109         if (parameters == null) {
110             String JavaDoc[] args = getArgs();
111
112             if ((args != null) && (args.length > 0)) {
113                 parameters = new ArrayList JavaDoc<String JavaDoc>(args.length);
114
115                 for (String JavaDoc arg : args) {
116                     parameters.add(arg);
117                 }
118             } else {
119                 parameters = Collections.emptyList();
120             }
121         }
122
123         return parameters;
124     }
125
126     public boolean isDeprecated() {
127         return false;
128     }
129
130     public ElementKind getKind() {
131         if (((name == null) && signature.startsWith("initialize(")) || // NOI18N
132
((name != null) && name.equals("initialize"))) { // NOI18N
133

134             return ElementKind.CONSTRUCTOR;
135         } else {
136             return ElementKind.METHOD;
137         }
138     }
139 }
140
Popular Tags