- Timestamp:
- 07/02/13 16:20:07 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
java/main/src/main/java/com/framsticks/params/types/ProcedureParam.java
r87 r90 3 3 import com.framsticks.params.Param; 4 4 import com.framsticks.params.ParamBuilder; 5 import com.framsticks.util.FramsticksException; 6 import com.framsticks.util.lang.Strings; 5 import com.framsticks.params.ValueParam; 7 6 8 import java.util.ArrayList;9 7 import java.util.List; 10 import java.util.regex.Matcher;11 import java.util.regex.Pattern;12 8 13 9 import javax.annotation.concurrent.Immutable; … … 18 14 @Immutable 19 15 public class ProcedureParam extends Param { 20 private final Param resultType; 21 private final List<Param> argumentsType = new ArrayList<Param>(); 22 23 private static Pattern addressPattern = Pattern.compile("^([^\\(]+)?\\(([^\\)]*)\\)$"); 16 private final ValueParam resultType; 17 private final List<ValueParam> argumentsType; 24 18 25 19 /** … … 28 22 public ProcedureParam(ParamBuilder builder) { 29 23 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 } 59 60 protected static Param parseType(String type, String name) { 61 return Param.build().type(type).name(name).finish(); 24 resultType = builder.getResultType(); 25 argumentsType = builder.getArgumentsType(); 26 assert argumentsType != null; 62 27 } 63 28 … … 67 32 } 68 33 69 public Param getResultType() {34 public ValueParam getResultType() { 70 35 return resultType; 71 36 } 72 37 73 public List< Param> getArgumentsType() {38 public List<ValueParam> getArgumentsType() { 74 39 return argumentsType; 75 40 }
Note: See TracChangeset
for help on using the changeset viewer.