1 19 package org.netbeans.modules.ruby.elements; 20 21 import java.util.ArrayList ; 22 import java.util.Collections ; 23 import java.util.List ; 24 import java.util.Set ; 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 42 public final class IndexedMethod extends IndexedElement implements MethodElement { 43 private String [] args; 44 private String name; 45 protected List <String > parameters; 46 47 private IndexedMethod(String signature, RubyIndex index, String fileUrl, String fqn, 48 String clz, String require, Set <Modifier> modifiers) { 49 super(signature, index, fileUrl, fqn, clz, require, modifiers); 50 } 51 52 public static IndexedMethod create(RubyIndex index, String signature, String fqn, String clz, 53 String fileUrl, String require, Set <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 69 public String toString() { 70 return getSignature(); 71 } 72 73 public String 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 88 public String getSignature() { 89 return fqn + "#" + signature; 90 } 91 92 public String [] getArgs() { 93 if (args == null) { 94 int index = signature.indexOf('('); 96 97 if (index == -1) { 98 return new String [0]; 99 } 100 101 String argsPortion = signature.substring(index + 1, signature.length() - 1); 102 args = argsPortion.split("\\), "); 103 } 104 105 return args; 106 } 107 108 public List <String > getParameters() { 109 if (parameters == null) { 110 String [] args = getArgs(); 111 112 if ((args != null) && (args.length > 0)) { 113 parameters = new ArrayList <String >(args.length); 114 115 for (String 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(")) || ((name != null) && name.equals("initialize"))) { 134 return ElementKind.CONSTRUCTOR; 135 } else { 136 return ElementKind.METHOD; 137 } 138 } 139 } 140 | Popular Tags |