KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.netbeans.modules.ruby.elements;
2
3 import java.util.Collections JavaDoc;
4 import java.util.EnumSet JavaDoc;
5 import java.util.Set JavaDoc;
6
7 import org.jruby.ast.ClassVarDeclNode;
8 import org.jruby.ast.ClassVarNode;
9 import org.jruby.ast.Node;
10 import org.jruby.ast.types.INameNode;
11 import org.netbeans.api.gsf.Element;
12 import org.netbeans.api.gsf.ElementKind;
13 import org.netbeans.api.gsf.Modifier;
14
15
16 public class AstFieldElement extends AstElement implements Element {
17     public AstFieldElement(Node node) {
18         super(node);
19     }
20
21     @Override JavaDoc
22     public String JavaDoc getName() {
23         if (name == null) {
24             if (node instanceof INameNode) { // InstVarNode, ClassDeclVarNode, ConstNode, etc.
25
name = ((INameNode)node).getName();
26             } else if (node instanceof ClassVarNode) { // should be INameNode)
27
name = ((ClassVarNode)node).getName();
28             }
29
30             if (name == null) {
31                 name = node.toString();
32             }
33
34             // Chop off "@" and "@@"
35
if (name.startsWith("@@")) {
36                 name = name.substring(2);
37             } else if (name.startsWith("@")) {
38                 name = name.substring(1);
39             }
40         }
41
42         return name;
43     }
44
45     public Set JavaDoc<Modifier> getModifiers() {
46         if (modifiers == null) {
47             // TODO - find access level!
48
if (node instanceof ClassVarNode || node instanceof ClassVarDeclNode) {
49                 modifiers = EnumSet.of(Modifier.STATIC);
50             } else {
51                 modifiers = Collections.emptySet();
52             }
53         }
54
55         return modifiers;
56     }
57
58     @Override JavaDoc
59     public ElementKind getKind() {
60         return ElementKind.FIELD;
61     }
62 }
63
Popular Tags