1 18 19 package org.objectweb.jac.ide; 20 21 import org.objectweb.jac.util.Strings; 22 import java.util.Iterator ; 23 import java.util.List ; 24 import java.util.Vector ; 25 26 public class Method extends Member { 27 28 public String getPrototype() { 29 String prototype = 30 ((type==null)?"void":type.getGenerationFullName())+ 31 " "+getGenerationName()+"("+getParametersString()+")"; 32 if (!exceptions.isEmpty()) { 33 prototype += " throws "+Strings.join(exceptions,","); 34 } 35 return prototype; 36 } 37 38 public String getModifiers() { 39 if ((parent instanceof Interface)) { 40 return ""; 41 } else { 42 String modifiers = super.getModifiers(); 43 if (isAbstract) 44 modifiers += " abstract"; 45 if (isSynchronized) 46 modifiers += " synchronized"; 47 return modifiers; 48 } 49 } 50 51 54 public String getParametersString() { 55 String result=""; 56 if (parameters == null) 57 return result; 58 Iterator it = parameters.iterator(); 59 while (it.hasNext()) { 60 Parameter cur = (Parameter)it.next(); 61 result = result+cur.getPrototype(); 62 if (it.hasNext()) { 63 result = result+", "; 64 } 65 } 66 return result; 67 } 68 69 Vector parameters=new Vector (); 70 71 75 public List getParameters() { 76 return parameters; 77 } 78 79 public void addParameter(Parameter p) { 80 parameters.add(p); 81 } 82 83 public void removeParameter(Parameter p) { 84 parameters.remove(p); 85 } 86 87 public void clearParameters() { 88 parameters.clear(); 89 } 90 91 94 public Type[] getParameterTypes() { 95 Type[] types = new Type[parameters.size()]; 96 int i=0; 97 Iterator it = parameters.iterator(); 98 while (it.hasNext()) { 99 types[i] = ((Parameter)it.next()).getType(); 100 i++; 101 } 102 return types; 103 } 104 105 String body; 106 107 111 public String getBody() { 112 return body; 113 } 114 115 119 public void setBody(String v) { 120 this.body = v; 121 } 122 123 boolean isAbstract = false; 124 public boolean isAbstract() { 125 return isAbstract; 126 } 127 public void setAbstract(boolean value) { 128 isAbstract = value; 129 } 130 131 boolean isSynchronized = false; 132 public boolean isSynchronized() { 133 return isSynchronized; 134 } 135 public void setSynchronized(boolean value) { 136 isSynchronized = value; 137 } 138 139 143 public String getUniqueName() { 144 StringBuffer result = new StringBuffer (); 145 result.append(getGenerationName()); 146 result.append('('); 147 Iterator it = parameters.iterator(); 148 while (it.hasNext()) { 149 Parameter param = (Parameter)it.next(); 150 result.append(param.getTypeName()); 151 if (it.hasNext()) 152 result.append(','); 153 } 154 result.append(')'); 155 return result.toString(); 156 } 157 158 161 public String getParameterNames() { 162 StringBuffer text = new StringBuffer (); 163 Iterator it = getParameters().iterator(); 164 while (it.hasNext()) { 165 Parameter parameter = (Parameter)it.next(); 166 text.append(parameter.getName()); 167 if (it.hasNext()) 168 text.append(","); 169 } 170 return text.toString(); 171 } 172 173 Vector exceptions = new Vector (); 174 public List getExceptions() { 175 return exceptions; 176 } 177 public void addException(String exception) { 178 exceptions.add(exception); 179 } 180 public void removeException(String exception) { 181 exceptions.remove(exception); 182 } 183 184 188 public Method cloneMethod() { 189 Method method = new Method(); 190 method.setName(getName()); 191 method.setType(getType()); 192 method.setArray(isArray()); 193 Iterator params = getParameters().iterator(); 194 while (params.hasNext()) { 195 Parameter param = (Parameter)params.next(); 196 Parameter newParam = new Parameter(); 197 newParam.setName(param.getName()); 198 newParam.setType(param.getType()); 199 newParam.setArray(param.isArray()); 200 method.addParameter(newParam); 201 } 202 Iterator exceptions = getExceptions().iterator(); 203 while (exceptions.hasNext()) { 204 String exception = (String )exceptions.next(); 205 method.addException(exception); 206 } 207 return method; 208 } 209 } 210 | Popular Tags |