source: java/main/src/main/java/com/framsticks/params/types/ProcedureParam.java @ 87

Last change on this file since 87 was 87, checked in by psniegowski, 11 years ago

HIGHLIGHTS:

  • FramsClass? and contained Param are now immutable classes (like String),

which allows to refer to them concurrently without synchronization
(which for example in turn simplifies GUI management)

  • also make Path immutable (which was earlier only assumed)
  • add global cache for FramsClasses? created solely and automatically

on base of Java classes.

representations basing on given FramsClass?

  • above changes greatly improved GUI responsivness during browsing
  • furtherly improve Param class hierarchy
  • allow to inject actions on state changes into MultiParamLoader?
  • add more tests

CHANGELOG:

Add StatusListener? to MultiParamLoader?.

Minor refactorization in MultiParamLoader?.

First step with auto append.

Add SchemaTest?.

Improve Registry.

Clean up in Registry.

Work out Registry.

Use annotations for Param.

Fix ListChange?.

Improve fluent interface of the FramsClassBuilder?.

Done caching of ReflectionAccess?.Backend

Fix hashCode of Pair.

A step on a way to cache ReflectionAccess?.Backend

Make SimpleAbstractAccess?.framsClass a final field.

Add static cache for FramsClasses? based on java.

Only classes created strictly and automatically
based on java classes are using this cache.

Make all Params immutable.

Many improvement to make Param immutable.

Make PrimitiveParam? generic type.

Several changes to make Param immutable.

Make FramsClass? immutable.

Another improvement to Path immutability.

Several improvements to Path.

Improve PathTest?.

Configurarable MutabilityDetector?.

File size: 1.9 KB
Line 
1package com.framsticks.params.types;
2
3import com.framsticks.params.Param;
4import com.framsticks.params.ParamBuilder;
5import com.framsticks.util.FramsticksException;
6import com.framsticks.util.lang.Strings;
7
8import java.util.ArrayList;
9import java.util.List;
10import java.util.regex.Matcher;
11import java.util.regex.Pattern;
12
13import javax.annotation.concurrent.Immutable;
14
15/**
16 * @author Piotr Sniegowski
17 */
18@Immutable
19public 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("^([^\\(]+)?\\(([^\\)]*)\\)$");
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        }
59
60        protected static Param parseType(String type, String name) {
61                return Param.build().type(type).name(name).finish();
62        }
63
64        @Override
65        public Class<?> getStorageType() {
66                return Void.class;
67        }
68
69        public Param getResultType() {
70                return resultType;
71        }
72
73        public List<Param> getArgumentsType() {
74                return argumentsType;
75        }
76
77        @Override
78        public String getFramsTypeName() {
79                return "p";
80        }
81
82}
Note: See TracBrowser for help on using the repository browser.