1 19 20 package org.openide.src; 21 22 import java.io.*; 23 import java.lang.reflect.Modifier ; 24 25 import org.openide.util.NbBundle; 26 27 33 public final class MethodElement extends ConstructorElement { 34 35 private static final ElementFormat HEADER_FORMAT = 36 new ElementFormat("{m,,\" \"}{r} {n}({a}){e,\" throws \",}"); 38 static final long serialVersionUID =2366156788906032138L; 39 40 41 public MethodElement() { 42 this(new Memory(), null); 43 } 44 45 49 public MethodElement(MethodElement.Impl impl, ClassElement clazz) { 50 super(impl, clazz); 51 } 52 53 57 public Object clone () { 58 return new MethodElement (new Memory (this), null); 59 } 60 61 final MethodElement.Impl getMethodImpl() { 62 return (MethodElement.Impl) impl; 63 } 64 65 68 public Type getReturn() { 69 return getMethodImpl().getReturn(); 70 } 71 72 76 public void setReturn (Type ret) throws SourceException { 77 getMethodImpl().setReturn(ret); 78 } 79 80 81 public int getModifiersMask() { 82 if (isDeclaredInInterface()) { 83 return Modifier.PUBLIC | Modifier.ABSTRACT; 84 } 85 else { 86 return Modifier.PUBLIC | Modifier.PROTECTED | Modifier.PRIVATE | 87 Modifier.ABSTRACT | Modifier.STATIC | Modifier.FINAL | 88 Modifier.NATIVE | Modifier.SYNCHRONIZED; 89 } 90 } 91 92 96 public final void setName(Identifier name) throws SourceException { 97 ClassElement c = getDeclaringClass(); 98 if (c != null) { 99 MethodParameter[] params = getParameters(); 100 Type[] types = new Type[params.length]; 101 for (int i = 0; i < types.length; i++) 102 types[i] = params[i].getType(); 103 MethodElement m = c.getMethod(name, types); 104 if ((m != null) && (m != this)) { 105 String msg = NbBundle.getMessage(ElementFormat.class, 106 "FMT_EXC_RenameMethod", c.getName().getName(), name ); throwSourceException(msg); 108 } 109 } 110 super.setName(name); 111 } 112 113 117 ElementFormat getFormat() { 118 return HEADER_FORMAT; 119 } 120 121 124 void printerMark(ElementPrinter printer, int what) throws ElementPrinterInterruptException { 125 printer.markMethod(this, what); 126 } 127 128 131 public interface Impl extends ConstructorElement.Impl { 132 133 long serialVersionUID = 7273573865765501815L; 134 137 public Type getReturn(); 138 139 142 public void setReturn (Type ret) throws SourceException; 143 } 144 145 147 public static final class Key extends ConstructorElement.Key { 148 149 private Identifier name; 150 private Type returnType; 151 152 156 public Key (final Identifier name, final Type[] params) { 157 super(params); 158 this.name = name; 159 } 160 161 169 public Key (final Identifier name, final Type[] params, final Type returnType) { 170 this(name, params); 171 this.returnType = returnType; 172 } 173 174 178 public Key (final MethodElement me) { 179 super(me); 180 name = me.getName(); 181 } 182 183 189 public Key(final MethodElement me, boolean checkReturn) { 190 this(me); 191 if (checkReturn) 192 returnType = me.getReturn(); 193 } 194 195 196 public boolean equals (Object obj) { 197 if (!(obj instanceof Key)) return false; 198 Key other = (Key)obj; 199 if (!name.equals(other.name) || !super.equals(obj)) return false; 200 if (returnType == null || other.returnType == null) 201 return true; 202 return returnType.equals(other.returnType); 203 } 204 205 208 public int hashCode () { 209 return super.hashCode() ^ name.getFullName().hashCode(); 213 } 214 215 } 217 static class Memory extends ConstructorElement.Memory implements Impl { 218 219 private Type type; 220 221 static final long serialVersionUID =2015834437815195149L; 222 Memory() { 223 type = Type.VOID; 224 } 225 226 227 Memory (MethodElement el) { 228 super (el); 229 type = el.getReturn (); 230 } 231 232 233 public Type getReturn() { 234 return type; 235 } 236 237 238 public void setReturn (Type ret) { 239 Type t = type; 240 type = ret; 241 firePropertyChange (PROP_RETURN, t, ret); 242 } 243 244 public Object readResolve() { 245 return new MethodElement(this, null); 246 } 247 248 } 249 250 } 251 | Popular Tags |