Ignore:
Timestamp:
07/02/13 16:20:07 (11 years ago)
Author:
psniegowski
Message:

HIGHLIGHTS:

CHANGELOG:
Make ProcedureParam? hold only ValueParams?.

Use id instead of names when naming gui components internally.

Basic procedure calling in GUI.

The actual procedure call is currently only backed
by the ObjectInstance?.

Add UnimplementedException?.

Improve naming of various gui elements.

Allow easy navigating in FEST Swing testing.

Add optional explicit order attribute to FramsClassAnnotation?.

That's because java reflection does return declared members
in any specific order. That ordering is needed only for
classes that have no representation in framsticks and need
a deterministic ordering of params.

Add ControlOwner? interface.

Add test for procedure calling in Browser.

First version of ParamAnnotation? for procedures.

Development of ProcedureParam?.

Add draft version of ProcedureParam? implementation in ReflectionAccess?.

Allow viewing FramsClasses? in gui Browser.

Extract ResourceBuilder? from ModelBuilder?.

Remove internalId from Param.

It was currently completely not utilised. Whether it is still needed
after introduction of ParamAnnotation? is arguable.

Add remaining param attributes to ParamAnnotation?.

Change AutoBuilder? semantics.

AutoBuilder? returns list of objects that are to be appended
with methods @AutoAppendAnnotation?.

This allows to omit explicit addition of ModelPackage? to instance
if the instance uses ModelBuilder? (registration of ModelPackage? comes
from schema).

Fix params ordering problem in auto created FramsClasses?.

Improve ObjectInstance?.

Several fixes to ModelBuilder?.

Improve test for ObjectInstance? in Browser.

Make initialization of robot static.

With robot recreated for second browser test, the test hanged
deep in AWT.

Add base convenience base test for Browser tests.

More tests to ObjectInstance?.

Rename Dispatcher.invokeLater() to dispatch().

Add assertDispatch.

It allows assertions in other threads, than TestNGInvoker.
Assertions are gathered after each method invocation and rethrown.

Use timeOut annotation attribute for tests involving some waiting.

Remove firstTask method (merge with joinableStart).

Clean up leftovers.

Remove unused FavouritesXMLFactory (the reading part is already
completely done with generic XmlLoader?, and writing part will be done
based on the same approach if needed).
Move UserFavourite? to the com.framsticks.gui.configuration package.

Remove GenotypeBrowser? as to specific.

This functionality will be available in ObjectInstance?.

Add interface ParamsPackage?.

Package containing registration of Java classes meant to use with
ReflectionAccess? may be in Instance using configuration.

Minor changes.

Make Group immutable.

Add AutoBuilder? interface extending Builder - only those would
be used to automatically build from XML.

Fix groups in FramsClass?.

Minor naming cleanup in Registry.

Add ModelComponent? interface.

All class creating the Model are implementing that interface.

Extract Model.build into ModelBuilder?.

ModelBuilder? will be compatible with other builders
and allow using it from configuration.

Fix NeuroConnection?.

Add synchronous get operation for dispatchers.

Rename JoinableMonitor? to Monitor.

Add ObjectInstance?.

This class is mainly for demonstration
and testing purposes.

Improve FramsServer? runner.

  • improve ExternalProcess? runner,
  • runner can kill the server but also react properly, when the server exists on it's own,
  • set default path to search for framsticks server installation,
  • add LoggingOutputListener?.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • java/main/src/main/java/com/framsticks/params/ParamCandidate.java

    r88 r90  
    1010import java.lang.reflect.ParameterizedType;
    1111import java.lang.reflect.Type;
     12import java.util.Arrays;
    1213import java.util.Collection;
     14import java.util.Collections;
     15import java.util.Comparator;
    1316import java.util.HashMap;
     17import java.util.LinkedList;
     18import java.util.List;
    1419import java.util.Map;
    1520
     21import com.framsticks.params.annotations.FramsClassAnnotation;
    1622import com.framsticks.params.annotations.ParamAnnotation;
     23import com.framsticks.params.types.ProcedureParam;
    1724
    1825public class ParamCandidate {
     
    6572        protected final OneTime<Method> setter = new OneTime<>("setter");
    6673        protected final OneTime<Method> getter = new OneTime<>("getter");
     74        protected final OneTime<Method> caller = new OneTime<>("caller");
     75
     76        protected final List<ParamAnnotation> annotations = new LinkedList<>();
    6777
    6878        /**
     
    124134        }
    125135
     136        /**
     137         * @return the getter
     138         */
     139        public Method getCaller() {
     140                return caller.get();
     141        }
     142
     143        /**
     144         * @return the annotations
     145         */
     146        public List<ParamAnnotation> getAnnotations() {
     147                return Collections.unmodifiableList(annotations);
     148        }
     149
    126150        void validate() throws ConstructionException {
    127151                try {
     152                        if (caller.has()) {
     153                                if (!isPublic(caller)) {
     154                                        throw new ConstructionException().msg("method is not public");
     155                                }
     156                                if (getter.has() || setter.has()) {
     157                                        throw new ConstructionException().msg("getter or setter coexist with caller");
     158                                }
     159                                return;
     160                        }
    128161                        if (isPublic(field)) {
    129162                                if (getter.has()) {
     
    147180
    148181        boolean isFinal() {
     182                if (caller.has()) {
     183                        return false;
     184                }
    149185                if (Collection.class.isAssignableFrom(getRawType())) {
    150186                        return false;
     
    160196
    161197        boolean isReadOnly() {
     198                if (caller.has()) {
     199                        return false;
     200                }
    162201                if (Collection.class.isAssignableFrom(getRawType())) {
    163202                        return false;
     
    172211        }
    173212
    174         void add(Member member, String name) {
     213        void add(ParamAnnotation paramAnnotation, Member member, String name) {
    175214                this.name.set(name);
     215                annotations.add(paramAnnotation);
    176216                if (member instanceof Field) {
    177                         this.field.set((Field) member);
     217                        field.set((Field) member);
    178218                        setType(field.get().getGenericType());
    179219                        return;
     
    181221                if (member instanceof Method) {
    182222                        Method m = (Method) member;
     223                        if (!paramAnnotation.paramType().equals(Param.class)) {
     224                                if (paramAnnotation.paramType().equals(ProcedureParam.class)) {
     225                                        caller.set(m);
     226                                        return;
     227                                }
     228                                throw new ConstructionException().msg("explicit set of paramType different than ProcedureParam is not yet supported").arg("name", name).arg("method", m).arg("in", this);
     229                        }
    183230                        Type[] ps = m.getGenericParameterTypes();
    184231                        if (ps.length == 0) {
     
    222269        }
    223270
    224         public static <M extends Member & AnnotatedElement> void filterParamsCandidates(Map<String, ParamCandidate> params, M[] members) {
     271        public static <M extends Member & AnnotatedElement> void filterParamsCandidates(Set set, M[] members) {
    225272                for (M m : members) {
    226273                        ParamAnnotation pa = m.getAnnotation(ParamAnnotation.class);
     
    228275                                continue;
    229276                        }
    230                         // if (!isPublic(m)) {
    231                         //      throw new ConstructionException().msg("field is not public").arg("field", m);
    232                         // }
    233277                        String id = FramsClassBuilder.getId(pa, m);
    234278                        ParamCandidate pc = null;
    235                         if (params.containsKey(id)) {
    236                                 pc = params.get(id);
     279                        if (set.getCandidates().containsKey(id)) {
     280                                pc = set.getCandidates().get(id);
    237281                        } else {
    238282                                pc = new ParamCandidate(id);
    239                                 params.put(id, pc);
    240                         }
    241                         pc.add(m, FramsClassBuilder.getName(pa, m));
    242 
    243                 }
    244         }
    245 
    246         public static Map<String, ParamCandidate> getAllCandidates(Class<?> javaClass) throws ConstructionException {
    247                 Map<String, ParamCandidate> candidates = new HashMap<>();
    248 
     283                                set.getCandidates().put(id, pc);
     284                                set.getOrder().add(pc);
     285                        }
     286                        pc.add(pa, m, FramsClassBuilder.getName(pa, m));
     287                }
     288        }
     289
     290        public static class Set {
     291                protected final Map<String, ParamCandidate> candidates;
     292                protected final List<ParamCandidate> order;
     293
     294                /**
     295                 * @param candidates
     296                 * @param order
     297                 */
     298                public Set(Map<String, ParamCandidate> candidates, List<ParamCandidate> order) {
     299                        this.candidates = candidates;
     300                        this.order = order;
     301                }
     302
     303                /**
     304                 * @return the candidates
     305                 */
     306                public Map<String, ParamCandidate> getCandidates() {
     307                        return candidates;
     308                }
     309
     310                /**
     311                 * @return the order
     312                 */
     313                public List<ParamCandidate> getOrder() {
     314                        return order;
     315                }
     316        }
     317
     318        public static Set getAllCandidates(Class<?> javaClass) throws ConstructionException {
     319
     320                List<Class<?>> javaClasses = new LinkedList<>();
    249321                while (javaClass != null) {
    250                         filterParamsCandidates(candidates, javaClass.getDeclaredFields());
    251                         filterParamsCandidates(candidates, javaClass.getDeclaredMethods());
    252 
     322                        javaClasses.add(0, javaClass);
    253323                        javaClass = javaClass.getSuperclass();
    254324                }
    255325
    256                 for (ParamCandidate pc : candidates.values()) {
     326                Set resultSet = new Set(new HashMap<String, ParamCandidate>(), new LinkedList<ParamCandidate>());
     327
     328                for (Class<?> j : javaClasses) {
     329                        Set set = new Set(resultSet.getCandidates(), new LinkedList<ParamCandidate>());
     330                        filterParamsCandidates(set, j.getDeclaredFields());
     331                        filterParamsCandidates(set, j.getDeclaredMethods());
     332
     333                        FramsClassAnnotation fa = j.getAnnotation(FramsClassAnnotation.class);
     334                        if (fa != null) {
     335                                final List<String> order = Arrays.asList(fa.order());
     336                                Collections.sort(set.getOrder(), new Comparator<ParamCandidate>() {
     337                                        @Override
     338                                        public int compare(ParamCandidate pc0, ParamCandidate pc1) {
     339                                                int u0 = order.indexOf(pc0.getId());
     340                                                int u1 = order.indexOf(pc1.getId());
     341                                                if (u0 == -1 || u1 == -1) {
     342                                                        return 0;
     343                                                }
     344                                                return u0 - u1;
     345                                        }
     346                                });
     347                        }
     348                        resultSet.getOrder().addAll(0, set.getOrder());
     349                }
     350
     351                for (ParamCandidate pc : resultSet.getOrder()) {
    257352                        pc.validate();
    258353                }
    259354
    260                 return candidates;
     355                return resultSet;
    261356        }
    262357
    263358        public static Class<?> getRawClass(final Type type) {
     359                if (type == null) {
     360                        throw new IllegalArgumentException();
     361                }
    264362                if (Class.class.isInstance(type)) {
    265363                        return Class.class.cast(type);
Note: See TracChangeset for help on using the changeset viewer.