- Timestamp:
- 06/28/13 11:56:03 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
java/main/src/main/java/com/framsticks/params/types/ProcedureParam.java
r85 r87 2 2 3 3 import com.framsticks.params.Param; 4 import com.framsticks.params.ParamBuilder; 5 import com.framsticks.util.FramsticksException; 4 6 import com.framsticks.util.lang.Strings; 5 7 … … 9 11 import java.util.regex.Pattern; 10 12 13 import javax.annotation.concurrent.Immutable; 14 11 15 /** 12 16 * @author Piotr Sniegowski 13 17 */ 18 @Immutable 14 19 public class ProcedureParam extends Param { 15 private Param resultType;16 private List<Param> argumentsType = new ArrayList<Param>();20 private final Param resultType; 21 private final List<Param> argumentsType = new ArrayList<Param>(); 17 22 18 23 private static Pattern addressPattern = Pattern.compile("^([^\\(]+)?\\(([^\\)]*)\\)$"); 24 25 /** 26 * @param builder 27 */ 28 public ProcedureParam(ParamBuilder builder) { 29 super(builder); 30 String signature = builder.getProcedureSignature(); 31 if (Strings.notEmpty(signature)) { 32 Matcher matcher = addressPattern.matcher(signature); 33 if (!matcher.matches()) { 34 throw new FramsticksException().msg("invalid signature"); 35 } 36 String result = Strings.collapse(matcher.group(1)); 37 resultType = (result != null) ? parseType(result, null) : null; 38 String arguments = matcher.group(2); 39 if (!Strings.notEmpty(arguments)) { 40 return; 41 } 42 for (String a : arguments.split(",")) { 43 int space = a.indexOf(' '); 44 String type; 45 String name; 46 if (space == -1) { 47 type = a; 48 name = null; 49 } else { 50 type = a.substring(0, space); 51 name = a.substring(space + 1); 52 } 53 argumentsType.add(parseType(type, name)); 54 } 55 } else { 56 resultType = null; 57 } 58 } 19 59 20 60 protected static Param parseType(String type, String name) { 21 61 return Param.build().type(type).name(name).finish(); 22 62 } 23 24 public void parseSignature(String signature) throws Exception {25 if (!Strings.notEmpty(signature)) {26 return;27 }28 Matcher matcher = addressPattern.matcher(signature);29 if (!matcher.matches()) {30 throw new Exception("invalid signature");31 }32 String result = Strings.collapse(matcher.group(1));33 if (result != null) {34 resultType = parseType(result, null);35 }36 String arguments = matcher.group(2);37 if (!Strings.notEmpty(arguments)) {38 return;39 }40 for (String a : arguments.split(",")) {41 int space = a.indexOf(' ');42 String type;43 String name;44 if (space == -1) {45 type = a;46 name = null;47 } else {48 type = a.substring(0, space);49 name = a.substring(space + 1);50 }51 argumentsType.add(parseType(type, name));52 }53 }54 55 63 56 64 @Override
Note: See TracChangeset
for help on using the changeset viewer.