1 19 20 package org.netbeans.modules.ruby.elements; 21 22 import org.jruby.ast.Node; 23 import java.util.Set ; 24 import org.netbeans.api.gsf.Element; 25 import org.netbeans.api.gsf.ElementKind; 26 import org.netbeans.api.gsf.Modifier; 27 import java.awt.Image ; 28 import java.util.ArrayList ; 29 import java.util.Collections ; 30 import java.util.EnumSet ; 31 import java.util.List ; 32 import java.util.List ; 33 import java.util.List ; 34 import java.util.Set ; 35 import org.jruby.ast.ArgsNode; 36 import org.jruby.ast.ArgumentNode; 37 import org.jruby.ast.ArgumentNode; 38 import org.jruby.ast.ClassNode; 39 import org.jruby.ast.ClassVarDeclNode; 40 import org.jruby.ast.ClassVarNode; 41 import org.jruby.ast.Colon2Node; 42 import org.jruby.ast.ConstDeclNode; 43 import org.jruby.ast.ConstNode; 44 import org.jruby.ast.DefnNode; 45 import org.jruby.ast.DefsNode; 46 import org.jruby.ast.InstAsgnNode; 47 import org.jruby.ast.InstVarNode; 48 import org.jruby.ast.ListNode; 49 import org.jruby.ast.ModuleNode; 50 import org.jruby.ast.Node; 51 import org.jruby.ast.SymbolNode; 52 import org.jruby.ast.types.INameNode; 53 import org.jruby.parser.RubyParserResult; 54 import org.netbeans.api.gsf.Element; 55 import org.netbeans.api.gsf.ElementKind; 56 import org.netbeans.api.gsf.Modifier; 57 import org.openide.filesystems.FileObject; 58 59 64 public abstract class AstElement extends RubyElement { 65 protected Node node; 66 protected ArrayList <AstElement> children; 67 protected String name; 68 private String in; 69 protected Set <Modifier> modifiers; 70 71 public AstElement(Node node) { 72 super(); 73 this.node = node; 74 } 75 76 public Node getNode() { 77 return node; 78 } 79 80 public abstract String getName(); 81 82 public String getDisplayName() { 90 return getName(); 91 } 92 93 public String getDescription() { 94 return getName(); 96 } 97 98 @SuppressWarnings ("unchecked") 99 public List <AstElement> getChildren() { 100 if (children == null) { 109 return Collections.emptyList(); 110 } 111 112 return children; 113 } 114 115 public void addChild(AstElement child) { 116 if (children == null) { 117 children = new ArrayList <AstElement>(); 118 } 119 children.add(child); 120 } 121 122 public static AstElement create(Node node) { 123 if (node instanceof DefnNode || node instanceof DefsNode) { 124 return new AstMethodElement(node); 125 } else if (node instanceof ClassNode) { 126 return new AstClassElement(node); 127 } else if (node instanceof ModuleNode) { 128 return new AstModuleElement(node); 129 } else if (node instanceof ConstDeclNode || node instanceof ClassVarDeclNode) { 130 return new AstFieldElement(node); 131 } else if (node instanceof ConstNode) { 132 return new AstVariableElement(node, ((ConstNode)node).getName()); 133 } else if (node instanceof ClassVarNode || node instanceof ClassVarDeclNode || 134 node instanceof InstVarNode || node instanceof InstAsgnNode) { 135 return new AstFieldElement(node); 136 } else if (node instanceof ConstDeclNode) { 137 return new AstConstantElement((ConstDeclNode)node); 138 } else if (node instanceof SymbolNode) { 139 return new AstAttributeElement((SymbolNode)node); 140 } else { 141 return null; 142 } 143 } 144 145 public String toString() { 146 String clz = getClass().getName(); 147 148 return clz.substring(0, clz.lastIndexOf('.')) + ":" + node.toString(); 149 } 150 151 public Image getIcon() { 152 return null; 153 } 154 155 public String getIn() { 156 return in; 158 } 159 160 public void setIn(String in) { 161 this.in = in; 162 } 163 164 public ElementKind getKind() { 165 return ElementKind.OTHER; 166 } 167 168 public Set <Modifier> getModifiers() { 169 return Collections.emptySet(); 170 } 171 172 } 173 | Popular Tags |