1 19 20 package org.netbeans.modules.j2ee.common.method; 21 22 import java.util.Collections ; 23 import java.util.List ; 24 import java.util.Set ; 25 import javax.lang.model.element.Modifier; 26 import org.openide.util.Parameters; 27 28 34 public final class MethodModel { 35 36 private final String name; 37 private final String returnType; 38 private final String body; 39 private final List <Variable> parameters; private final List <String > exceptions; private final Set <Modifier> modifiers; 43 private MethodModel(String name, String returnType, String body, List <Variable> parameters, List <String > exceptions, Set <Modifier> modifiers) { 44 this.name = name; 45 this.returnType = returnType; 46 this.body = body; 47 this.parameters = Collections.unmodifiableList(parameters); 48 this.exceptions = Collections.unmodifiableList(exceptions); 49 this.modifiers = Collections.unmodifiableSet(modifiers); 50 } 51 52 68 public static MethodModel create(String name, String returnType, String body, List <Variable> parameters, List <String > exceptions, Set <Modifier> modifiers) { 69 Parameters.javaIdentifier("name", name); 70 Parameters.notWhitespace("returnType", returnType); 71 Parameters.notNull("parameters", parameters); 72 Parameters.notNull("exceptions", exceptions); 73 Parameters.notNull("modifiers", modifiers); 74 return new MethodModel(name, returnType, body, parameters, exceptions, modifiers); 75 } 76 77 80 public static final class Variable { 81 82 private final String type; 83 private final String name; 84 private final boolean finalModifier; 85 86 private Variable(String type, String name, boolean finalModifier) { 87 this.type = type; 88 this.name = name; 89 this.finalModifier = finalModifier; 90 } 91 92 106 public static Variable create(String type, String name) { 107 Parameters.notWhitespace("type", type); 108 Parameters.javaIdentifier("name", name); 109 return new MethodModel.Variable(type, name, false); 110 } 111 112 125 public static Variable create(String type, String name, boolean finalModifier) { 126 Parameters.notWhitespace("type", type); 127 Parameters.javaIdentifier("name", name); 128 return new MethodModel.Variable(type, name, finalModifier); 129 } 130 131 133 138 public String getType() { 139 return type; 140 } 141 142 147 public String getName() { 148 return name; 149 } 150 151 156 public boolean getFinalModifier() { 157 return finalModifier; 158 } 159 160 162 } 163 164 166 171 public String getName() { 172 return name; 173 } 174 175 180 public String getReturnType() { 181 return returnType; 182 } 183 184 189 public String getBody() { 190 return body; 191 } 192 193 199 public List <Variable> getParameters() { 200 return parameters; 201 } 202 203 209 public List <String > getExceptions() { 210 return exceptions; 211 } 212 213 219 public Set <Modifier> getModifiers() { 220 return modifiers; 221 } 222 223 225 @Override 226 public String toString() { 227 return "MethodModel<" + modifiers + "," + returnType + "," + name + "," + parameters + "," + exceptions + ",{" + body + "}>"; 228 } 229 230 } 231 | Popular Tags |