1 package org.netbeans.modules.ruby.elements; 2 3 import java.util.Collections ; 4 import java.util.EnumSet ; 5 import java.util.Set ; 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 22 public String getName() { 23 if (name == null) { 24 if (node instanceof INameNode) { name = ((INameNode)node).getName(); 26 } else if (node instanceof ClassVarNode) { name = ((ClassVarNode)node).getName(); 28 } 29 30 if (name == null) { 31 name = node.toString(); 32 } 33 34 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 <Modifier> getModifiers() { 46 if (modifiers == null) { 47 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 59 public ElementKind getKind() { 60 return ElementKind.FIELD; 61 } 62 } 63 | Popular Tags |