Changeset 86


Ignore:
Timestamp:
06/26/13 13:27:31 (11 years ago)
Author:
psniegowski
Message:

HIGHLIGHTS:

  • use java annotations to mark classes and fields to be used when:
    • using java classes with ReflectionAccess? to represent remote objects with FramsClass? description found by "info ..." requests
    • to build up FramsClass? representation of objects not present at remote server
  • allow using primitive types (instead of wraping counterparts) in reflected classes
  • rework FramsClass? creation process (add FramsClassBuilder?)
  • add more tests

CHANGELOG:
Prepare model.World class.

Minor change.

Use primitive types for Genotype and Creature classes.

Use primitive types in model.Neuro* classes.

Use primitive types in model.Joint* classes.

Use primitive types in model.Part* classes.

Fix primitive values.

Extract FramsClassBuilder?.

Add tests of Model classes.

More fixes.

Refactorize out ParamCandidate?.

Several fixes.

Fix all regressions after introducing annotations.

Use annotations throughout the project.

Add exception classes.

Improve creation of FramsClass?.

More changes.

Many changes regarding annotations.

Annotate classes in com.framsticks.model package.

Remove manual FramsClass? constructor.

Construct FramsClass? for Creature. Add test.

Add default values to the ParamAnnotation?.

Add ParamBuilderTest? and ParamAnnotation?.

Add FramsClassAnnotation?.

Location:
java/main
Files:
22 added
1 deleted
45 edited

Legend:

Unmodified
Added
Removed
  • java/main/pom.xml

    r85 r86  
    1919        </properties>
    2020        <dependencies>
     21                <dependency>
     22                        <groupId>org.javatuples</groupId>
     23                        <artifactId>javatuples</artifactId>
     24                        <version>1.2</version>
     25                        <scope>compile</scope>
     26                </dependency>
    2127                <dependency>
    2228                        <groupId>com.google.code.findbugs</groupId>
     
    9096                        <plugin>
    9197                                <groupId>org.apache.maven.plugins</groupId>
     98                                <artifactId>maven-surefire-plugin</artifactId>
     99                                <version>2.9</version>
     100                                <configuration>
     101                                        <useFile>false</useFile>
     102                                </configuration>
     103                        </plugin>
     104
     105                        <plugin>
     106                                <groupId>org.apache.maven.plugins</groupId>
    92107                                <artifactId>maven-compiler-plugin</artifactId>
    93108                                <version>3.0</version>
  • java/main/src/main/java/com/framsticks/core/Entity.java

    r85 r86  
    33import javax.annotation.OverridingMethodsMustInvokeSuper;
    44
    5 import com.framsticks.params.FramsClass;
     5import com.framsticks.params.annotations.FramsClassAnnotation;
     6import com.framsticks.params.annotations.ParamAnnotation;
    67import com.framsticks.util.dispatching.Thread;
    78import com.framsticks.util.dispatching.Dispatcher;
     
    1415 * @author Piotr Sniegowski
    1516 */
     17@FramsClassAnnotation
    1618public abstract class Entity implements Dispatcher<Entity> {
    1719
    18         private final static Logger log = Logger.getLogger(Entity.class.getName());
     20        private final static Logger log = Logger.getLogger(Entity.class);
    1921
     22        @ParamAnnotation
    2023        protected String name = "entity";
    2124        protected EntityOwner owner;
     
    109112        }
    110113
    111         public static void constructFramsClass(FramsClass.Constructor constructor) {
    112                 constructor.method("getName");
    113         }
    114114}
  • java/main/src/main/java/com/framsticks/core/Instance.java

    r85 r86  
    2323        private static final Logger log = Logger.getLogger(Instance.class.getName());
    2424
    25 
    2625        protected Node root;
    2726
     
    3433        protected void run() {
    3534                super.run();
    36                 root = new Node((CompositeParam)Param.build().name("Instance").id(name).type("o").finish(), null);
     35                root = new Node((CompositeParam) Param.build().name("Instance").id(name).type("o").finish(), null);
    3736                com.framsticks.model.Package.register(registry);
    3837        }
     
    112111        }
    113112
    114 
    115113        protected void fireListChange(Path path, ListChange change) {
    116114                assert isActive();
     
    127125        }
    128126
    129 
    130127        public final FramsClass getInfoFromCache(Path path) {
    131128                return getInfoFromCache(path.getTop().getParam().getContainedTypeName());
    132129        }
    133130
    134 
    135131        public FramsClass getInfoFromCache(String id) {
    136132                assert isActive();
     
    140136        protected Registry registry = new Registry();
    141137
    142         public AccessInterface createAccess(String name) {
     138        public AccessInterface createAccess(String name) throws ConstructionException {
    143139                assert isActive();
    144140                return registry.createAccess(name);
    145141        }
    146 
    147142
    148143        // TODO: make ValueParam
     
    165160        public final AccessInterface bindAccess(Node node) {
    166161                assert node.getObject() != null;
    167                 AccessInterface access = registry.prepareAccess(node.getParam());
    168                 if (access == null) {
    169                         log.error("missing access for: " + node.getParam());
    170                         return null;
    171                 }
    172                 access.select(node.getObject());
    173                 return access;
     162
     163                try {
     164                        return registry.prepareAccess(node.getParam()).select(node.getObject());
     165                } catch (ConstructionException e) {
     166                        log.error("failed to bind access for " + node.getParam() + ": " + e);
     167                }
     168                return null;
    174169        }
    175170
  • java/main/src/main/java/com/framsticks/gui/controls/Control.java

    r84 r86  
    11package com.framsticks.gui.controls;
    22
     3import java.awt.BorderLayout;
     4
     5import javax.swing.JComponent;
     6import javax.swing.JPanel;
     7
     8import com.framsticks.gui.Frame;
    39import com.framsticks.params.Flags;
    410import com.framsticks.params.Param;
    5 import javax.swing.*;
    6 import java.awt.*;
    711
    812/**
  • java/main/src/main/java/com/framsticks/hosting/ServerInstance.java

    r85 r86  
    33import com.framsticks.core.*;
    44import com.framsticks.params.CompositeParam;
     5import com.framsticks.params.ConstructionException;
    56import com.framsticks.params.FramsClass;
     7import com.framsticks.params.FramsClassBuilder;
    68import com.framsticks.params.Param;
    79import com.framsticks.core.LocalInstance;
     
    4244                hosted.setName("hosted");
    4345                hosted.configure(hostedConfig);
    44                 root = new Node((CompositeParam)Param.build().name("root").id("root").type("o" + hosted.getClass().getCanonicalName()).finish(), hosted);
     46                root = new Node((CompositeParam) Param.build().name("root").id("root").type("o" + hosted.getClass().getCanonicalName()).finish(), hosted);
    4547        }
    4648
     
    5759                try {
    5860                        Class<?> nativeClass = Class.forName(id);
    59                         FramsClass framsClass = new FramsClass.Constructor(nativeClass, id).getResult();
     61                        FramsClass framsClass = FramsClassBuilder.buildForClass(nativeClass);
     62
     63                        if (!framsClass.getId().equals(id)) {
     64                                log.error("no matching id");
     65                                return null;
     66                        }
    6067
    6168                        registry.registerReflectedClass(null, id, nativeClass);
     
    6370                        return framsClass;
    6471                } catch (ClassNotFoundException ignored) {
     72                } catch (ConstructionException e) {
     73                        log.error("failed to use info from cache: " + e);
    6574                }
    6675
  • java/main/src/main/java/com/framsticks/model/BaseJoint.java

    r84 r86  
    11package com.framsticks.model;
    22
     3import com.framsticks.params.annotations.ParamAnnotation;
    34import com.framsticks.util.math.Point3d;
    45
     
    89public class BaseJoint {
    910
    10         /** stif */
    11         public Double stiffness;
    12         public Double getStif() { return stiffness; }
    13         public void setStif(Double stif) { stiffness = stif; }
     11        @ParamAnnotation(id = "stif")
     12        public double stiffness;
    1413
    15         /** rotstif */
    16         public Double rotationStiffness;
    17         public Double getRotstif() { return rotationStiffness; }
    18         public void setRotstif(Double rotstif) { rotationStiffness = rotstif; }
     14        @ParamAnnotation(id = "rotstif")
     15        public double rotationStiffness;
    1916
    20         /** rx, ry, rz*/
     17        @ParamAnnotation
    2118        public double rx, ry, rz;
    2219
     
    2421        public void setRotation(Point3d r) { rx = r.x; ry = r.y; rz = r.z; }
    2522
    26         /** dx, dy, dz*/
     23        @ParamAnnotation
    2724        public double dx, dy, dz;
    2825
  • java/main/src/main/java/com/framsticks/model/BaseNeuro.java

    r78 r86  
    11package com.framsticks.model;
     2
     3import com.framsticks.params.annotations.ParamAnnotation;
    24
    35/**
     
    57 */
    68public class BaseNeuro {
    7         /** inputCount */
    8         public Integer inputCount;
    9         public Integer getGetInputCount() { return inputCount; }
    10         public void setGetInputCount(Integer getInputCount) { inputCount = getInputCount; }
     9
     10        @ParamAnnotation(id = "getInputCount")
     11        public int inputCount;
    1112
    1213
  • java/main/src/main/java/com/framsticks/model/BasePart.java

    r84 r86  
    11package com.framsticks.model;
    22
     3import com.framsticks.params.annotations.ParamAnnotation;
    34import com.framsticks.util.math.Orientation;
    45import com.framsticks.util.math.Point3d;
     
    89 */
    910public class BasePart {
    10         /** x, y, z */
     11
     12        @ParamAnnotation
    1113        public double x, y, z;
    1214
     
    1416        public void setPosition(Point3d p) { x = p.x; y = p.y; z = p.z; }
    1517
    16         /** m */
    17         public Double mass = 0.0;
    18         public Double getM() { return mass; }
    19         public void setM(Double m) { mass = m; }
     18        @ParamAnnotation(id = "m")
     19        public double mass = 0.0;
    2020
    21         /** s */
    22         public Double size = 0.0;
    23         public Double getS() { return size; }
    24         public void setS(Double s) { size = s; }
     21        @ParamAnnotation(id = "s")
     22        public double size = 0.0;
    2523
    26         /** fr */
    27         public Double friction;
    28         public Double getFr() { return friction; }
    29         public void setFr(Double fr) { friction = fr; }
     24        @ParamAnnotation(id = "fr")
     25        public double friction;
    3026
    31 
     27        @ParamAnnotation
    3228        public double oxx, oxy, oxz, oyx, oyy, oyz, ozx, ozy, ozz;
    3329
  • java/main/src/main/java/com/framsticks/model/Creature.java

    r84 r86  
    11package com.framsticks.model;
    22
    3 import com.framsticks.params.FramsClass;
     3import com.framsticks.params.annotations.FramsClassAnnotation;
     4import com.framsticks.params.annotations.ParamAnnotation;
    45import com.framsticks.util.math.Point3d;
    56
     
    78import java.util.List;
    89
     10@FramsClassAnnotation
    911public class Creature {
     12
     13        @ParamAnnotation
    1014        public String name;
    1115
     16        @ParamAnnotation
    1217        public String genotype;
    1318
     19        @ParamAnnotation
    1420        public String info;
    1521
     22        @ParamAnnotation
    1623        public Object group;
    1724
    18         public Integer generation;
    19         public Integer getGnum() { return generation; }
    20         public void setGnum(Integer gnum) { generation = gnum; }
     25        @ParamAnnotation(id = "gnum")
     26        public int generation;
    2127
    22         public Integer buildProblems;
    23         public Integer getBuildproblems() { return buildProblems; }
    24         public void setBuildproblems(Integer buildproblems) { buildProblems = buildproblems; }
     28        @ParamAnnotation(id = "buildproblems")
     29        public int buildProblems;
    2530
    26         public Double startingEnergy;
    27         public Double getEnerg0() { return startingEnergy; }
    28         public void setEnerg0(Double energ0) { startingEnergy = energ0; }
     31        @ParamAnnotation(id = "energ0")
     32        public double startingEnergy;
    2933
    30         public Double idlePowerConsumption;
    31         public Double getIdleen() { return idlePowerConsumption; }
    32         public void setIdleen(Double idleen) { idlePowerConsumption = idleen; }
     34        @ParamAnnotation(id = "idleen")
     35        public double idlePowerConsumption;
    3336
    34         public Double energy;
     37        @ParamAnnotation
     38        public double energy;
    3539
    36         public Double energyIncome;
    37         public Double getEnergy_p() { return energyIncome; }
    38         public void setEnergy_p(Double energy_p) { energyIncome = energy_p; }
     40        @ParamAnnotation(id = "energy_p")
     41        public double energyIncome;
    3942
    40         public Double energyCosts;
    41         public Double getEnergy_m() { return energyCosts; }
    42         public void setEnergy_m(Double energy_m) { energyCosts = energy_m; }
     43        @ParamAnnotation(id = "energy_m")
     44        public double energyCosts;
    4345
    44         public Double energyBalance;
    45         public Double getEnergy_b() { return energyBalance; }
    46         public void setEnergy_b(Double energy_b) { energyBalance = energy_b; }
     46        @ParamAnnotation(id = "energy_b")
     47        public double energyBalance;
    4748
    48         public Integer performanceCalculation;
    49         public Integer getPerf() { return performanceCalculation; }
    50         public void setPerf(Integer perf) { performanceCalculation = perf; }
     49        @ParamAnnotation(id = "perf")
     50        public int performanceCalculation;
    5151
    52         public Boolean neuralNetworkEnabled;
     52        @ParamAnnotation(id = "nnenabled")
     53        public boolean neuralNetworkEnabled;
    5354
    54         public Boolean getNnenabled() { return neuralNetworkEnabled; }
    55         public void setNnenabled(Boolean nnenabled) { neuralNetworkEnabled = nnenabled; }
     55        @ParamAnnotation(id = "bodysim")
     56        public boolean bodySimulation;
    5657
    57         public Boolean bodySimulation;
    58         public Boolean getBodysim() { return bodySimulation; }
    59         public void setBodysim(Boolean bodysim) { bodySimulation = bodysim; }
     58        @ParamAnnotation(id = "selfcol")
     59        public boolean selfCollisions;
    6060
    61         public Boolean selfCollisions;
    62         public Boolean getSelfcol() { return selfCollisions; }
    63         public void setSelfcol(Boolean selfcol) { selfCollisions = selfcol; }
     61        @ParamAnnotation(id = "lifespan")
     62        public int lifeSpan;
    6463
    65         public Integer lifeSpan;
    66         public Integer getLifespan() { return lifeSpan; }
    67         public void setLifespan(Integer lifespan) { lifeSpan = lifespan; }
     64        @ParamAnnotation
     65        public double distance;
    6866
    69         public Double distance;
     67        @ParamAnnotation(id = "c_velocity")
     68        public double currentVelocity;
    7069
    71         public Double currentVelocity;
    72         public Double getC_velocity() { return currentVelocity; }
    73         public void setC_velocity(Double c_velocity) { currentVelocity = c_velocity; }
     70        @ParamAnnotation(id = "c_vertvelocity")
     71        public double currentVerticalVelocity;
    7472
    75         public Double currentVerticalVelocity;
    76         public Double getC_vertvelocity() { return currentVerticalVelocity; }
    77         public void setC_vertvelocity(Double c_vertvelocity) { currentVerticalVelocity = c_vertvelocity; }
     73        @ParamAnnotation(id = "c_vertpos")
     74        public double currentVerticalPosition;
    7875
    79         public Double currentVerticalPosition;
    80         public Double getC_vertpos() { return currentVerticalPosition; }
    81         public void setC_vertpos(Double c_vertpos) { currentVerticalPosition = c_vertpos; }
     76        @ParamAnnotation(id = "velocity")
     77        public double averageVelocity;
    8278
    83         public Double averageVelocity;
    84         public Double getVelocity() { return averageVelocity; }
    85         public void setVelocity(Double c_velocity) { averageVelocity = c_velocity; }
     79        @ParamAnnotation(id = "vertvel")
     80        public double averageVerticalVelocity;
    8681
    87         public Double averageVerticalVelocity;
    88         public Double getVertvel() { return averageVerticalVelocity; }
    89         public void setVertvel(Double c_vertvelocity) { averageVerticalVelocity = c_vertvelocity; }
     82        @ParamAnnotation(id = "vertpos")
     83        public double averageVerticalPosition;
    9084
    91         public Double averageVerticalPosition;
    92         public Double getVertpos() { return averageVerticalPosition; }
    93         public void setVertpos(Double c_vertpos) { averageVerticalPosition = c_vertpos; }
    94 
    95         /** pos_x, pos_y, pos_z*/
     85        @ParamAnnotation
    9686        public double pos_x, pos_y, pos_z;
    9787
     
    9989        public void setPosition(Point3d pos) { pos_x = pos.x; pos_y = pos.y; pos_z = pos.z; }
    10090
     91        @ParamAnnotation
    10192        public double size_x, size_y, size_z;
    10293
     
    10697
    10798        /** center_x, center_y, center_z*/
     99        @ParamAnnotation
    108100        public double center_x, center_y, center_z;
    109101
     
    111103        public void setCenter(Point3d center) { center_x = center.x; center_y = center.y; center_z = center.z; }
    112104
    113         public Integer getNumparts() { return parts.size(); }
    114         public void setNumparts(Integer numparts) { }
     105        @ParamAnnotation
     106        public int getNumparts() { return parts.size(); }
     107        @ParamAnnotation
     108        public void setNumparts(int numparts) { }
    115109
    116         public Integer getNumjoints() { return joints.size(); }
    117         public void setNumjoints(Integer numjoints) { }
     110        @ParamAnnotation
     111        public int getNumjoints() { return joints.size(); }
     112        @ParamAnnotation
     113        public void setNumjoints(int numjoints) { }
    118114
    119         public Integer getNumneurons() { return neurons.size(); }
    120         public void setNumneurons(Integer numneurons) { }
     115        @ParamAnnotation
     116        public int getNumneurons() { return neurons.size(); }
     117        @ParamAnnotation
     118        public void setNumneurons(int numneurons) { }
    121119
    122120        public Object[] userFields = new Object[3];
     121        @ParamAnnotation
    123122        public Object getUser1() { return userFields[0]; }
     123        @ParamAnnotation
    124124        public void setUser1(Object user1) { userFields[0] = user1; }
    125125
     126        @ParamAnnotation
    126127        public Object getUser2() { return userFields[1]; }
     128        @ParamAnnotation
    127129        public void setUser2(Object user2) { userFields[1] = user2; }
    128130
     131        @ParamAnnotation
    129132        public Object getUser3() { return userFields[2]; }
     133        @ParamAnnotation
    130134        public void setUser3(Object user3) { userFields[2] = user3; }
    131135
    132         public Integer selfCollisionMask;
    133         public Integer getSelfmask() { return selfCollisionMask; }
    134         public void setSelfmask(Integer selfmask) { selfCollisionMask = selfmask; }
     136        @ParamAnnotation(id = "selfmask")
     137        public int selfCollisionMask;
    135138
    136         public Integer otherCollisionMask;
    137         public Integer getOthermask() { return otherCollisionMask; }
    138         public void setOthermask(Integer othermask) { otherCollisionMask = othermask; }
     139        @ParamAnnotation(id = "othermask")
     140        public int otherCollisionMask;
    139141
     142        @ParamAnnotation(id = "selfcolstate")
     143        public boolean selfCollisionsState;
     144
     145        @ParamAnnotation
    140146        public String uid;
    141147
    142         public Integer index;
     148        @ParamAnnotation
     149        public int index;
    143150
     151        @ParamAnnotation
    144152        public final List<Part> parts = new ArrayList<Part>();
     153        @ParamAnnotation
    145154        public final List<Joint> joints = new ArrayList<Joint>();
     155        @ParamAnnotation
    146156        public final List<NeuroDef> neurodefs = new ArrayList<NeuroDef>();
    147157
     
    150160        public final List<NeuroDef> getNeuroDefs() { return neurodefs; }
    151161
     162        @ParamAnnotation
    152163        public final List<MechPart> mechparts = new ArrayList<MechPart>();
     164        @ParamAnnotation
    153165        public final List<MechJoint> mechjoints = new ArrayList<MechJoint>();
     166        @ParamAnnotation
    154167        public final List<Neuro> neurons = new ArrayList<Neuro>();
    155168
     
    158171        public final List<Neuro> getNeurons() { return neurons; }
    159172
    160 
    161 
    162         public static void constructFramsClass(FramsClass.Constructor constructor) {
    163                 constructor.field("name");
    164                 constructor.field("parts");
    165                 constructor.field("joints");
    166                 constructor.field("neurodefs");
    167                 constructor.field("mechparts");
    168                 constructor.field("mechjoints");
    169                 constructor.field("neurons");
    170         }
    171 
    172173}
  • java/main/src/main/java/com/framsticks/model/Genotype.java

    r84 r86  
    11package com.framsticks.model;
     2
     3import com.framsticks.params.annotations.FramsClassAnnotation;
     4import com.framsticks.params.annotations.ParamAnnotation;
    25
    36
    47// import org.apache.log4j.Logger;
    58
     9@FramsClassAnnotation
    610public class Genotype extends Model {
    711        // private final static Logger log = Logger.getLogger(Genotype.class);
    812
     13        @ParamAnnotation
    914        public String name;
     15
     16        @ParamAnnotation
    1017        public String genotype;
     18
     19        @ParamAnnotation
    1120        public String info;
    1221
    13         public Double similarity;
    14         public Double getSimi() { return similarity; }
    15         public void setSimi(Double simi) { similarity = simi; }
     22        @ParamAnnotation(id = "simi")
     23        public double similarity;
    1624
    17         public Double brainConnections;
    18         public Double getNumconnections() { return brainConnections; }
    19         public void setNumconnections(Double numconnections) { brainConnections = numconnections; }
     25        @ParamAnnotation(id = "numconnections")
     26        public double brainConnections;
    2027
    21     public Integer ordinalNumber;
    22         public Integer getNum() { return ordinalNumber; }
    23         public void setNum(Integer num) { ordinalNumber = num; }
     28        @ParamAnnotation(id = "num")
     29        public int ordinalNumber;
    2430
    25     public Integer generation;
    26         public Integer getGnum() { return generation; }
    27         public void setGnum(Integer gnum) { generation = gnum; }
     31        @ParamAnnotation(id = "gnum")
     32        public int generation;
    2833
    29         public Integer instances;
     34        @ParamAnnotation
     35        public int instances;
    3036
    31         public Integer lifeSpan;
    32         public Integer getLifespan() { return lifeSpan; }
    33         public void setLifespan(Integer lifespan) { lifeSpan = lifespan; }
     37        @ParamAnnotation(id = "lifespan")
     38        public double lifeSpan;
    3439
    35         public Double velocity;
    36         public Double distance;
     40        @ParamAnnotation
     41        public double velocity;
    3742
    38         public Double verticalVelocity;
    39         public Double getVertvel() { return verticalVelocity; }
    40         public void setVertvel(Double vertvel) { verticalVelocity = vertvel; }
     43        @ParamAnnotation
     44        public double distance;
    4145
    42         public Double verticalPosition;
    43         public Double getVertpos() { return verticalPosition; }
    44         public void setVertpos(Double vertpos) { verticalPosition = vertpos; }
     46        @ParamAnnotation(id = "vertvel")
     47        public double verticalVelocity;
    4548
    46         public Double fitness;
    47         public Double getFit() { return fitness; }
    48         public void setFit(Double fit) { fitness = fit; }
     49        @ParamAnnotation(id = "vertpos")
     50        public double verticalPosition;
    4951
    50         public Double finalFitness;
    51         public Double getFit2() { return finalFitness; }
    52         public void setFit2(Double fit2) { finalFitness = fit2; }
     52        @ParamAnnotation(id = "fit")
     53        public double fitness;
    5354
     55        @ParamAnnotation(id = "fit2")
     56        public double finalFitness;
     57
     58        @ParamAnnotation(id = "f0genotype")
    5459        public String genotypeInF0;
    55         public String getF0genotype() { return genotypeInF0; }
    56         public void setF0genotype(String f0genotype) { genotypeInF0 = f0genotype; }
    5760
     61        @ParamAnnotation(id = "convtrace1")
    5862        public String conversionBacktrace;
    59         public String getConvtrace1() { return conversionBacktrace; }
    60         public void setConvtrace1(String convtrace1) { conversionBacktrace = convtrace1; }
     63
     64        @ParamAnnotation
     65        public boolean isValid;
    6166
    6267        public Object[] userFields = new Object[3];
     68        @ParamAnnotation
    6369        public Object getUser1() { return userFields[0]; }
     70        @ParamAnnotation
    6471        public void setUser1(Object user1) { userFields[0] = user1; }
    6572
     73        @ParamAnnotation
    6674        public Object getUser2() { return userFields[1]; }
     75        @ParamAnnotation
    6776        public void setUser2(Object user2) { userFields[1] = user2; }
    6877
     78        @ParamAnnotation
    6979        public Object getUser3() { return userFields[2]; }
     80        @ParamAnnotation
    7081        public void setUser3(Object user3) { userFields[2] = user3; }
    7182
     83        @ParamAnnotation
    7284        public String uid;
     85
     86        @ParamAnnotation
     87        public double getStrsiz() { return getNumparts(); }
     88        @ParamAnnotation
     89        public void setStrsiz(double strsiz) { setNumparts(strsiz); }
     90
     91
     92        @ParamAnnotation
     93        public double getStrjoints() { return getNumjoints(); }
     94        @ParamAnnotation
     95        public void setStrjoints(double strjoints) { setNumjoints(strjoints); }
     96
     97
     98        @ParamAnnotation
     99        public double getNnsiz() { return getNumneurons(); }
     100        @ParamAnnotation
     101        public void setNnsiz(double nnsiz) { setNumneurons(nnsiz); }
     102
     103
     104        @ParamAnnotation
     105        public double getNncon() { return brainConnections; }
     106        @ParamAnnotation
     107        public void setNncon(double nncon) { this.brainConnections = nncon; }
     108
     109        @ParamAnnotation
     110        public int getPopsiz() { return instances; }
     111        @ParamAnnotation
     112        public void setPopsiz(int popsiz) { this.instances = popsiz; }
     113
    73114
    74115}
  • java/main/src/main/java/com/framsticks/model/Joint.java

    r84 r86  
    11package com.framsticks.model;
     2
     3import com.framsticks.params.annotations.FramsClassAnnotation;
     4import com.framsticks.params.annotations.ParamAnnotation;
    25
    36/**
     
    69 * All accessors are used by ReflectionAccess.
    710 */
     11@FramsClassAnnotation(id = "j")
    812public class Joint extends BaseJoint {
    913
    10         /** i */
     14        @ParamAnnotation(id = "i")
    1115        public String info;
    12         public String getI() { return info; }
    13         public void setI(String i) { info = i; }
    1416
    15         /** p1 */
    16         public Integer part1;
    17         public void setP1(Integer p1) { part1 = p1; }
    18         public Integer getP1() { return part1; }
     17        @ParamAnnotation(id = "p1")
     18        public int part1;
    1919
    20         /** p2 */
    21         public Integer part2;
    22         public void setP2(Integer p2) { part2 = p2; }
    23         public Integer getP2() { return part2; }
     20        @ParamAnnotation(id = "p2")
     21        public int part2;
    2422
     23        @ParamAnnotation(id = "stam")
     24        public double stamina;
    2525
    26         /** stam */
    27         public Double stamina;
    28         public Double getStam() { return stamina; }
    29         public void setStam(Double stam) { stamina = stam; }
     26        @ParamAnnotation(id = "Vstyle")
     27        public String visualizationStyle;
    3028
     29        @ParamAnnotation
     30        public double vr, vg, vb;
    3131
    32         /** Vstyle */
    33         public String visualizationStyle;
    34         public String getVstyle() { return visualizationStyle; }
    35         public void setVstyle(String Vstyle) { visualizationStyle = Vstyle; }
    3632}
  • java/main/src/main/java/com/framsticks/model/MechJoint.java

    r84 r86  
    11package com.framsticks.model;
     2
     3import com.framsticks.params.annotations.FramsClassAnnotation;
     4import com.framsticks.params.annotations.ParamAnnotation;
    25
    36/**
    47 * @author Piotr Sniegowski
    58 */
     9@FramsClassAnnotation
    610public class MechJoint extends BaseJoint {
    711
    8         /** stress */
    9         public Double stress;
    10         public Double getStress() { return stress; }
    11         public void setStress(Double stress) { this.stress = stress; }
     12        @ParamAnnotation
     13        public double stress;
    1214
    13         /** rotstress */
    14         public Double rotationStress;
    15         public Double getRotstress() { return rotationStress; }
    16         public void setRotstress(Double rotstress) { rotationStress = rotstress; }
     15        @ParamAnnotation(id = "rotstress")
     16        public double rotationStress;
    1717}
  • java/main/src/main/java/com/framsticks/model/MechPart.java

    r84 r86  
    11package com.framsticks.model;
    22
     3import com.framsticks.params.annotations.FramsClassAnnotation;
     4import com.framsticks.params.annotations.ParamAnnotation;
    35import com.framsticks.util.math.Point3d;
    46
    57/*
    68 */
     9@FramsClassAnnotation
    710public class MechPart extends BasePart {
    811
    9         /** vol */
    10         public Double volume = 0.0;
    11         public Double getVol() { return volume; }
    12         public void setVol(Double vol) { volume = vol; }
     12        @ParamAnnotation(id = "vol")
     13        public double volume = 0.0;
    1314
    14         /** vx, vy, vz*/
     15        @ParamAnnotation
    1516        public double vx, vy, vz;
    1617
  • java/main/src/main/java/com/framsticks/model/Model.java

    r84 r86  
    11package com.framsticks.model;
    22
     3import com.framsticks.params.annotations.FramsClassAnnotation;
     4import com.framsticks.params.annotations.ParamAnnotation;
    35import com.framsticks.util.lang.Casting;
    46import com.framsticks.util.lang.Containers;
     
    1416 * Author: Piotr Śniegowski
    1517 */
     18@FramsClassAnnotation(id = "m")
    1619public class Model {
    1720
    1821        private final static Logger log = Logger.getLogger(Model.class);
    1922
    20         public Double startingEnergy;
    21         public Double getEnerg0() { return startingEnergy; }
    22         public void setEnerg0(Double energ0) { startingEnergy = energ0; }
     23        @ParamAnnotation(id = "se")
     24        public double startingEnergy;
    2325
    24         public Double getSe() { return startingEnergy; }
    25         public void setSe(Double se) { startingEnergy = se; }
     26        @ParamAnnotation
     27        public double getEnerg0() { return startingEnergy; }
     28        @ParamAnnotation
     29        public void setEnerg0(double energ0) { startingEnergy = energ0; }
    2630
    27         /** Vstyle */
     31
     32        @ParamAnnotation(id = "Vstyle")
    2833        public String visualizationStyle;
    29         public String getVstyle() { return visualizationStyle; }
    30         public void setVstyle(String Vstyle) { visualizationStyle = Vstyle; }
    3134
     35        @ParamAnnotation
    3236        public final List<Part> parts = new ArrayList<Part>();
     37
     38        @ParamAnnotation
    3339        public final List<Joint> joints = new ArrayList<Joint>();
     40
     41        @ParamAnnotation
    3442        public final List<NeuroDef> neurodefs = new ArrayList<NeuroDef>();
    3543
    36         public Double getNumparts() { return (double)parts.size(); }
    37         public Double getNumjoints() { return (double)joints.size(); }
    38         public Double getNumneurons() { return (double)neurodefs.size(); }
     44        //TODO: why those methods returns and accepts doubles?
     45        @ParamAnnotation
     46        public double getNumparts() { return (double)parts.size(); }
     47        @ParamAnnotation
     48        public double getNumjoints() { return (double)joints.size(); }
     49        @ParamAnnotation
     50        public double getNumneurons() { return (double)neurodefs.size(); }
    3951
    4052        //this is impossible to use, because numparts field is marked as readonly
    41         public void setNumparts(Double numparts) { Containers.resizeList(parts, (int) (double) numparts); }
    42         public void setNumjoints(Double numjoints) { Containers.resizeList(joints, (int)(double)numjoints); }
    43         public void setNumneurons(Double numneurons) { Containers.resizeList(neurodefs, (int)(double)numneurons); }
     53        @ParamAnnotation
     54        public void setNumparts(double numparts) { Containers.resizeList(parts, (int) (double) numparts); }
     55        @ParamAnnotation
     56        public void setNumjoints(double numjoints) { Containers.resizeList(joints, (int)(double)numjoints); }
     57        @ParamAnnotation
     58        public void setNumneurons(double numneurons) { Containers.resizeList(neurodefs, (int)(double)numneurons); }
    4459
    4560        public List<Part> getParts() { return parts; }
     
    7893                for (Joint j : f0Genotype.getJoints()) {
    7994                        /** based on c++ Joint::attachToParts*/
    80                         Part p1 = f0Genotype.parts.get(j.getP1());
    81                         Part p2 = f0Genotype.parts.get(j.getP2());
     95                        Part p1 = f0Genotype.parts.get(j.part1);
     96                        Part p2 = f0Genotype.parts.get(j.part2);
    8297                        assert p1 != null && p2 != null;
    8398                        Orientation o = new Orientation().rotate(j.getRotation());
  • java/main/src/main/java/com/framsticks/model/Neuro.java

    r84 r86  
    11package com.framsticks.model;
    22
     3import com.framsticks.params.annotations.FramsClassAnnotation;
     4import com.framsticks.params.annotations.ParamAnnotation;
    35import com.framsticks.util.math.Point3d;
    46
     
    68 * @author Piotr Sniegowski
    79 */
     10@FramsClassAnnotation
    811public class Neuro extends BaseNeuro {
    912
    10         public Integer channelCount;
     13        @ParamAnnotation
     14        public int channelCount;
    1115
    12         public Double inputSum;
     16        @ParamAnnotation
     17        public double inputSum;
    1318
    14         public Double weightedInputSum;
     19        @ParamAnnotation
     20        public double weightedInputSum;
    1521
    16         public Double state;
     22        @ParamAnnotation
     23        public double state;
    1724
    18         public Double currentState;
    19         public Double getCurrState() { return currentState; }
    20         public void setCurrState(Double currState) { currentState = currState; }
     25        @ParamAnnotation(id = "currState")
     26        public double currentState;
    2127
    22         public Boolean hold;
     28        @ParamAnnotation
     29        public boolean hold;
    2330
     31        @ParamAnnotation
    2432        public double position_x, position_y, position_z;
    2533
  • java/main/src/main/java/com/framsticks/model/NeuroDef.java

    r78 r86  
    11package com.framsticks.model;
     2
     3import com.framsticks.params.annotations.FramsClassAnnotation;
     4import com.framsticks.params.annotations.ParamAnnotation;
    25
    36/**
    47 * @author Piotr Sniegowski
    58 */
     9@FramsClassAnnotation(id = "n")
    610public class NeuroDef extends BaseNeuro {
    711
    8         /** p */
    9         public Integer part;
     12        @ParamAnnotation(id = "p")
     13        public int part;
    1014
    11         /** j */
    12         public Integer joint;
     15        @ParamAnnotation(id = "j")
     16        public int joint;
    1317
    14         /** d */
     18        @ParamAnnotation(id = "d")
    1519        public String details;
    1620
    17         /** i */
     21        @ParamAnnotation(id = "i")
    1822        public String info;
    1923
    20         /** Vstyle */
     24        @ParamAnnotation(id = "Vstyle")
    2125        public String visualizationStyle;
    2226
    23         public Integer getP() { return part; }
    24         public void setP(Integer p) { part = p; }
    25 
    26         public Integer getJ() { return joint; }
    27         public void setJ(Integer j) { joint = j; }
    28 
    29         public String getD() { return details; }
    30         public void setD(String d) { details = d; }
    31 
    32         public String getI() { return info; }
    33         public void setI(String i) { info = i; }
    34 
    35         public String getVstyle() { return visualizationStyle; }
    36         public void setVstyle(String Vstyle) { visualizationStyle = Vstyle; }
    37 
    38 
    39 
    4027}
  • java/main/src/main/java/com/framsticks/model/Package.java

    r84 r86  
    88public class Package {
    99        public static void register(Registry registry) {
    10                 registry.registerReflectedClass("MechPart", null, "com.framsticks.model.MechPart");
    11                 registry.registerReflectedClass("Joint", "j", "com.framsticks.model.Joint");
    12                 registry.registerReflectedClass("MechJoint", null, "com.framsticks.model.MechJoint");
    13                 registry.registerReflectedClass("Neuro", null, "com.framsticks.model.Neuro");
    14                 registry.registerReflectedClass("NeuroDef", "n", "com.framsticks.model.NeuroDef");
    15                 registry.registerReflectedClass("Part", "p", "com.framsticks.model.Part");
    16                 registry.registerReflectedClass("Model", "m", "com.framsticks.model.Model");
    17                 registry.registerReflectedClass("Creature", null, "com.framsticks.model.Creature");
    18                 registry.registerReflectedClass("Genotype", null, "com.framsticks.model.Genotype");
    19 
     10                registry
     11                        .register(MechPart.class)
     12                        .register(Joint.class)
     13                        .register(MechJoint.class)
     14                        .register(Neuro.class)
     15                        .register(NeuroDef.class)
     16                        .register(Part.class)
     17                        .register(Model.class)
     18                        .register(Creature.class)
     19                        .register(Genotype.class)
     20                        .register(World.class);
    2021        }
    2122}
  • java/main/src/main/java/com/framsticks/model/Part.java

    r84 r86  
    22
    33
     4import com.framsticks.params.annotations.FramsClassAnnotation;
     5import com.framsticks.params.annotations.ParamAnnotation;
    46import com.framsticks.util.math.Point3d;
    57
     
    79 * The Class Part.
    810 */
     11@FramsClassAnnotation(id = "p")
    912public class Part extends BasePart {
    1013
    11         /** rx, ry, rz*/
     14        @ParamAnnotation
    1215        public double rx, ry, rz;
     16
    1317
    1418        public Point3d getRotation() { return new Point3d(rx, ry, rz); }
    1519        public void setRotation(Point3d r) { rx = r.x; ry = r.y; rz = r.z; }
    1620
    17         /** dn */
    18         public Double density;
     21        @ParamAnnotation(id = "dn")
     22        public double density;
    1923
    20         /** ing */
    21         public Double ingestion;
     24        @ParamAnnotation(id = "ing")
     25        public double ingestion;
    2226
    23         /** as */
    24         public Double assimilation;
     27        @ParamAnnotation(id = "as")
     28        public double assimilation;
    2529
    26         /** i */
     30        @ParamAnnotation(id = "i")
    2731        public String info;
    2832
    29         /** Vstyle */
     33        @ParamAnnotation(id = "Vstyle")
    3034        public String visualizationStyle;
    3135
    32         public Double getDn() { return density; }
    33         public void setDn(Double dn) { density = dn; }
     36        @ParamAnnotation(id = "vs")
     37        public double visualThickness;
    3438
    35         public Double getIng() { return ingestion; }
    36         public void setIng(Double ing) { ingestion = ing; }
    37 
    38         public Double getAs() { return assimilation; }
    39         public void setAs(Double as) { assimilation = as; }
    40 
    41         public String getI() { return info; }
    42         public void setI(String i) { info = i; }
    43 
    44         public String getVstyle() { return visualizationStyle; }
    45         public void setVstyle(String vstyle) { visualizationStyle = vstyle; }
     39        @ParamAnnotation
     40        public double vr, vg, vb;
    4641
    4742}
  • java/main/src/main/java/com/framsticks/model/World.java

    r77 r86  
    11package com.framsticks.model;
    22
     3import com.framsticks.params.annotations.FramsClassAnnotation;
     4import com.framsticks.params.annotations.ParamAnnotation;
     5
     6@FramsClassAnnotation
    37public class World {
    48
    5         public Integer wrldbnd;
    6         public Double wrldwat;
    7         public String faces;
     9        @ParamAnnotation(id = "wrldbnd")
     10        public int boundaries;
     11
     12        @ParamAnnotation(id = "wrldwat")
     13        public double waterLevel;
    814
    915
     16        @ParamAnnotation(id = "wrldtyp")
     17        public int type;
     18
     19        @ParamAnnotation(id = "wrldsiz")
     20        public double size;
     21
     22        @ParamAnnotation(id = "wrldmap")
     23        public String map;
     24
     25        @ParamAnnotation(id = "wrldg")
     26        public double gravity;
     27
     28        @ParamAnnotation(id = "simtype")
     29        public int simulationEngine;
     30
     31        @ParamAnnotation(id = "nnspeed")
     32        public double neuralNetworkSimulationSpeed;
     33
     34        @ParamAnnotation
     35        public String faces;
    1036        /*
    1137        public static ReflectionAccess createReflection()
  • java/main/src/main/java/com/framsticks/observers/Endpoint.java

    r85 r86  
    44import com.framsticks.core.InstanceListener;
    55import com.framsticks.core.Path;
    6 import com.framsticks.params.FramsClass;
     6import com.framsticks.params.annotations.FramsClassAnnotation;
     7import com.framsticks.params.annotations.ParamAnnotation;
    78import com.framsticks.core.ListChange;
    89import com.framsticks.util.dispatching.Dispatcher;
     
    1314 * @author Piotr Sniegowski
    1415 */
     16@FramsClassAnnotation
    1517public class Endpoint implements Dispatcher<Instance>, InstanceListener {
    1618        private final static Logger log = Logger.getLogger(Endpoint.class.getName());
    1719
     20        @ParamAnnotation
    1821        protected Instance instance;
    1922        protected Observer observer;
     23
     24        @ParamAnnotation
    2025        protected String name;
    2126
     
    8085        }
    8186
    82         public static void constructFramsClass(FramsClass.Constructor constructor) {
    83                 constructor.method("getName").method("getInstance");
    84         }
    8587
    8688}
  • java/main/src/main/java/com/framsticks/observers/Observer.java

    r84 r86  
    44import com.framsticks.core.Instance;
    55import com.framsticks.core.Program;
    6 import com.framsticks.params.FramsClass;
     6import com.framsticks.params.annotations.FramsClassAnnotation;
     7import com.framsticks.params.annotations.ParamAnnotation;
    78import com.framsticks.util.lang.Casting;
    89import org.apache.commons.configuration.Configuration;
     
    1415 * @author Piotr Sniegowski
    1516 */
     17@FramsClassAnnotation
    1618public abstract class Observer extends Entity {
    1719
     
    2123        }
    2224
     25        @ParamAnnotation
    2326        protected final Map<String, Endpoint> endpoints = new HashMap<String, Endpoint>();
    2427
     
    6871        }
    6972
    70         public static void constructFramsClass(FramsClass.Constructor constructor) {
    71                 constructor.method("getEndpoints");
    72         }
    7373
    7474
  • java/main/src/main/java/com/framsticks/params/AccessInterface.java

    r84 r86  
    6666        Object getSelected();
    6767
    68         AccessInterface cloneAccess();
     68        AccessInterface cloneAccess() throws ConstructionException;
    6969
    7070        Object createAccessee();
  • java/main/src/main/java/com/framsticks/params/ArrayListAccess.java

    r85 r86  
    2020
    2121        @Override
    22         public ArrayListAccess cloneAccess() {
     22        public ArrayListAccess cloneAccess() throws ConstructionException {
    2323                return new ArrayListAccess(elementAccess.cloneAccess());
    2424        }
  • java/main/src/main/java/com/framsticks/params/FramsClass.java

    r85 r86  
    11package com.framsticks.params;
    22
    3 import com.framsticks.params.types.StringParam;
    4 import com.framsticks.parsers.FileSource;
    5 import com.framsticks.parsers.Loaders;
    6 import com.framsticks.util.lang.Casting;
    7 
    8 import org.apache.log4j.Logger;
    9 
    10 import java.io.InputStream;
    11 import java.lang.reflect.*;
     3import com.framsticks.params.annotations.FramsClassAnnotation;
     4import com.framsticks.params.annotations.ParamAnnotation;
     5// import com.framsticks.util.FramsticksException;
     6
    127import java.util.*;
     8
     9import javax.annotation.Nonnull;
    1310
    1411/**
     
    2421 * @author Piotr Sniegowski
    2522 */
     23@FramsClassAnnotation(id = "class", name = "class")
    2624public final class FramsClass {
    27 
    28         private final static Logger log = Logger.getLogger(FramsClass.class
    29                         .getName());
    30 
    31         /**
    32          * The Class which represents group.
    33          */
    3425
    3526        /** The offset of the parameter (applied for newly added parameter). */
     
    6253
    6354        public FramsClass() {
     55
    6456        }
    6557
     
    7769         */
    7870        public FramsClass append(Param param) {
     71                // if (param.hasFlag(Flags.USERHIDDEN)) {
     72                //      return this;
     73                // }
    7974                paramEntryMap.put(param.getId(), param);
    8075                //paramEntryMap.put(param.getInternalId(), param);
     
    10499        }
    105100
     101        @ParamAnnotation(id = "desc")
    106102        public String getDescription() {
    107103                return description;
     
    130126
    131127        /**
    132          * Gets the group getName.
     128         * Gets the group name.
    133129         *
    134130         * @param gi
    135131         *            the offset of group
    136          * @return the group getName
     132         * @return the group name
    137133         */
    138134        public String getGroupName(int gi) {
     
    142138        }
    143139
     140        @ParamAnnotation
    144141        public String getId() {
    145142                return id;
    146143        }
    147144
     145        @ParamAnnotation
    148146        public String getName() {
    149147                return name;
     
    152150        public String getNiceName() {
    153151                return name != null ? name : id;
     152        }
     153
     154        public <T extends Param> T castedParam(@Nonnull final Param param, @Nonnull final Class<T> type, Object name) {
     155                if (param == null) {
     156                        return null;
     157                        // throw new FramsticksException().msg("param is missing").arg("name", name).arg("in", this);
     158                }
     159                if (!type.isInstance(param)) {
     160                        return null;
     161                        // throw new FramsticksException().msg("wrong type of param").arg("actual", param.getClass()).arg("requested", type).arg("in", this);
     162                }
     163                return type.cast(param);
    154164        }
    155165
     
    161171         * @return the param entry
    162172         */
    163         public <T extends Param> T getParamEntry(int i, Class<T> type) {
    164                 if (i < 0 || i >= paramList.size()) {
    165                         return null;
    166                 }
    167                 return Casting.tryCast(type, paramList.get(i));
     173        public <T extends Param> T getParamEntry(final int i, @Nonnull final Class<T> type) {
     174                return castedParam(getParam(i), type, i);
    168175        }
    169176
     
    175182         * @return the param entry
    176183         */
    177         public <T extends Param> T getParamEntry(String id, Class<T> type) {
    178                 return Casting.tryCast(type, paramEntryMap.get(id));
     184        public <T extends Param> T getParamEntry(@Nonnull final String id, @Nonnull final Class<T> type) {
     185                return castedParam(getParam(id), type, id);
     186        }
     187
     188        public Param getParam(int i) {
     189                if (i < 0 || i >= paramList.size()) {
     190                        return null;
     191                }
     192                return paramList.get(i);
     193        }
     194
     195        public Param getParam(String id) {
     196                if (!paramEntryMap.containsKey(id)) {
     197                        return null;
     198                }
     199                return paramEntryMap.get(id);
    179200        }
    180201
     
    188209        }
    189210
    190         public static FramsClass getFramsClass() {
    191                 return new FramsClass("class", "class", null)
    192                         .append(Param.build().id("name").name("Name").type(StringParam.class))
    193                         .append(Param.build().id("id").name("id").type(StringParam.class))
    194                         .append(Param.build().id("desc").name("Description").type(StringParam.class));
    195         }
    196 
     211        @ParamAnnotation
    197212        public void setId(String id) {
    198213                this.id = id;
    199214        }
    200215
     216        @ParamAnnotation
    201217        public void setName(String name) {
    202218                this.name = name;
    203219        }
    204220
     221        @ParamAnnotation(id = "desc")
    205222        public void setDescription(String description) {
    206223                this.description = description;
    207224        }
    208 
    209         public static String getParamTypeForNativeType(Type type) {
    210                 if (type instanceof ParameterizedType) {
    211                         ParameterizedType p = (ParameterizedType) type;
    212                         Type rawType = p.getRawType();
    213                         if (rawType.equals(Map.class)) {
    214                                 Type containedType = p.getActualTypeArguments()[1];
    215                                 //TODO uid should be passed along during construction
    216                                 if (containedType instanceof Class) {
    217                                         return "l " + ((Class<?>) containedType).getCanonicalName()
    218                                                         + " name";
    219                                 }
    220                         }
    221                         if (rawType.equals(List.class)) {
    222                                 Type containedType = p.getActualTypeArguments()[0];
    223                                 if (containedType instanceof Class) {
    224                                         return "l " + ((Class<?>) containedType).getCanonicalName();
    225                                 }
    226                         }
    227                         return null;
    228                 }
    229 
    230                 if (type.equals(Integer.class)) {
    231                         return "d";
    232                 }
    233                 if (type.equals(String.class)) {
    234                         return "s";
    235                 }
    236                 if (type.equals(Double.class)) {
    237                         return "f";
    238                 }
    239                 if (type instanceof Class) {
    240                         return "o " + ((Class<?>) type).getCanonicalName();
    241                 }
    242                 return null;
    243         }
    244 
    245         public static final String GENERATE_HELP_PREFIX = "automatically generated from: ";
    246 
    247         public static FramsClass readFromStream(InputStream stream) {
    248                 return Loaders.loadFramsClass(new FileSource(stream));
    249         }
    250 
    251         public static class Constructor {
    252                 protected final FramsClass result;
    253                 protected Class<?> currentClass;
    254 
    255                 public Constructor(Class<?> src, String name) {
    256                         result = new FramsClass(name, name, GENERATE_HELP_PREFIX
    257                                         + src.toString());
    258                         currentClass = src;
    259                         while (currentClass != null) {
    260                                 try {
    261                                         currentClass.getMethod("constructFramsClass", Constructor.class).invoke(null, this);
    262                                 } catch (IllegalAccessException | IllegalArgumentException
    263                                                 | InvocationTargetException | NoSuchMethodException
    264                                                 | SecurityException e) {
    265                                         log.debug("failed to use constructFramsClass static method (skipping): ", e);
    266                                 }
    267                                 currentClass = currentClass.getSuperclass();
    268                         }
    269                         currentClass = src;
    270                 }
    271 
    272                 public final FramsClass getResult() {
    273                         return result;
    274                 }
    275 
    276                 public Constructor allFields() {
    277                         for (Field f : currentClass.getFields()) {
    278                                 field(f.getName());
    279                         }
    280                         return this;
    281                 }
    282 
    283                 public Constructor method(String name, Class<?> ... arguments) {
    284                         try {
    285                                 Method method = currentClass.getMethod(name, arguments);
    286                                 if (!Modifier.isPublic(method.getModifiers())) {
    287                                         return this;
    288                                 }
    289                                 String returnParamClass = getParamTypeForNativeType(method.getGenericReturnType());
    290                                 if (returnParamClass == null) {
    291                                         return this;
    292                                 }
    293                                 Class<?>[] args = method.getParameterTypes();
    294                                 if (args.length == 0) {
    295                                         if (method.getName().startsWith("get")) {
    296                                                 String fieldName = method.getName().substring(3, 4).toLowerCase() + method.getName().substring(4);
    297                                                 Param param = Param.build().type(returnParamClass).name(fieldName).id(fieldName).help(GENERATE_HELP_PREFIX + method.toString()).finish();
    298                                                 assert param != null;
    299                                                 result.append(param);
    300                                                 return this;
    301                                         }
    302                                         return this;
    303                                 }
    304                                 return this;
    305                         } catch (NoSuchMethodException e) {
    306                                 log.fatal("method " + name + " was not found in " + currentClass.toString());
    307                         }
    308                         return this;
    309                 }
    310                 public Constructor field(String name) {
    311                         try {
    312                                 Field field = currentClass.getField(name);
    313                                 if (!Modifier.isPublic(field.getModifiers())) {
    314                                         return this;
    315                                 }
    316                                 String paramClass = getParamTypeForNativeType(field.getGenericType());
    317                                 if (paramClass == null) {
    318                                         return this;
    319                                 }
    320                                 Param param = Param.build().type(paramClass).name(field.getName()).id(field.getName()).help(GENERATE_HELP_PREFIX + field.toString()).finish();
    321                                 assert param != null;
    322                                 result.append(param);
    323                                 return this;
    324                         } catch (NoSuchFieldException e) {
    325                                 log.fatal("field " + name + " was not found in " + currentClass.toString());
    326                         }
    327                         return this;
    328                 }
    329         }
    330225}
  • java/main/src/main/java/com/framsticks/params/ListSource.java

    r84 r86  
    11package com.framsticks.params;
    22
     3import java.util.ArrayList;
    34import java.util.Iterator;
    45import java.util.List;
     
    78
    89        private Iterator<String> iterator = null;
    9     //private final List<String> source;
     10        //private final List<String> source;
    1011
    1112        public ListSource(List<String> source) {
    12         //this.source = source;
    13         iterator = source.iterator();
     13                //this.source = source;
     14                iterator = source.iterator();
    1415        }
    1516
    16     @Override
     17        @Override
    1718        public String getFilename() {
    1819                return "<net>";
    1920        }
    2021
    21     @Override
    22     public String readLine() {
    23         assert iterator != null;
     22        @Override
     23        public String readLine() {
     24                // if (iterator == null) {
     25                //      return null;
     26                // }
     27                assert iterator != null;
    2428                if (iterator.hasNext()) {
    2529                        return iterator.next();
     
    2832        }
    2933
    30     @Override
    31     public String demangleInclude(String include) {
     34        @Override
     35        public String demangleInclude(String include) {
    3236                return null;
    3337        }
    3438
    35     @Override
    36     public SourceInterface openInclude(String include) {
     39        @Override
     40        public SourceInterface openInclude(String include) {
    3741                return null;
    3842        }
    3943
    40     @Override
    41     public void close() {
    42         iterator = null;
     44        @Override
     45        public void close() {
     46                iterator = null;
     47        }
     48
     49        public static ListSource createFrom(String... lines) {
     50                List<String> list = new ArrayList<String>();
     51                for (String l : lines) {
     52                        list.add(l);
     53                }
     54                return new ListSource(list);
     55        }
     56
     57        @Override
     58        public boolean isClosed() {
     59                return iterator == null;
    4360        }
    4461}
  • java/main/src/main/java/com/framsticks/params/Param.java

    r85 r86  
    11package com.framsticks.params;
     2
    23
    34import com.framsticks.params.types.DecimalParam;
  • java/main/src/main/java/com/framsticks/params/ParamBuilder.java

    r85 r86  
    11package com.framsticks.params;
    22
     3import com.framsticks.params.annotations.FramsClassAnnotation;
     4import com.framsticks.params.annotations.ParamAnnotation;
    35import com.framsticks.params.types.*;
    46import com.framsticks.util.lang.Numbers;
     
    810import java.util.ArrayList;
    911import java.util.Arrays;
     12
    1013
    1114/**
     
    1821 */
    1922
     23@FramsClassAnnotation(name = "prop", id = "prop")
    2024public class ParamBuilder {
    2125        private final static Logger log = Logger.getLogger(ParamBuilder.class.getName());
     
    2832        private static final String FLAGS_FIELD = "flags";
    2933
    30         /** The parameter getId. */
     34        /** The parameter id. */
    3135        private String id;
    3236
    3337        /**
    34          * The parameter internal getId. It's set by a user to use user's own getId in
     38         * The parameter internal id. It's set by a user to use user's own id in
    3539         * code
    3640         */
     
    4044        private Integer group = 0;
    4145
    42         /** The getFlags stored as a bit sum. */
     46        /** The flags stored as a bit sum. */
    4347        private Integer flags = 0;
    4448
    45         /** The parameter getName. */
     49        /** The parameter name. */
    4650        private String name;
    4751
    48         /** The getHelp (description) concerning parameter. */
     52        /** The help (description) concerning parameter. */
    4953        private String help;
    5054
    51         /** The getType of parameter. */
     55        /** The type of parameter. */
    5256        private Class<? extends Param> paramType;
    5357
    5458        private Param param;
    5559        private PrimitiveParam primitiveParam;
    56 
    57         ParamBuilder() {
     60        private String typeString;
     61
     62        public ParamBuilder() {
    5863        }
    5964
     
    7681        }
    7782
     83        @ParamAnnotation
    7884        public ParamBuilder id(String id) {
    7985                this.id = id;
     
    8793                        primitiveParam = (PrimitiveParam) param;
    8894                }
     95                typeString = param.getFramsTypeName();
    8996                return this;
    9097        }
    9198
    9299        public <T extends Param> ParamBuilder type(Class<T> type) {
     100                assert type != null;
    93101                try {
    94102                        return internalSetType(type, type.newInstance());
     
    104112
    105113
     114        /**
     115         * @return the id
     116         */
     117        @ParamAnnotation
     118        public String getId() {
     119                return id;
     120        }
     121
    106122        public ParamBuilder setInternalId(String internalId) {
    107123                this.internalId = internalId;
     
    109125        }
    110126
     127        @ParamAnnotation
    111128        public ParamBuilder group(Integer group) {
    112129                this.group = group;
     
    114131        }
    115132
     133        @ParamAnnotation
    116134        public ParamBuilder flags(Integer flags) {
    117135                this.flags = flags;
     
    119137        }
    120138
     139        @ParamAnnotation
    121140        public ParamBuilder name(String name) {
    122141                this.name = name;
     
    143162        }
    144163
     164        @ParamAnnotation
    145165        public ParamBuilder type(String type) {
     166                typeString = type;
    146167
    147168                log.trace("parsing type: " + type);
     
    233254        }
    234255
     256        @ParamAnnotation
    235257        public ParamBuilder help(String help) {
    236258                this.help = help;
    237259                return this;
     260        }
     261
     262        /**
     263         * @return the group
     264         */
     265        @ParamAnnotation
     266        public Integer getGroup() {
     267                return group;
     268        }
     269
     270        /**
     271         * @return the flags
     272         */
     273        @ParamAnnotation
     274        public Integer getFlags() {
     275                return flags;
     276        }
     277
     278        /**
     279         * @return the name
     280         */
     281        @ParamAnnotation
     282        public String getName() {
     283                return name;
     284        }
     285
     286        /**
     287         * @return the help
     288         */
     289        @ParamAnnotation
     290        public String getHelp() {
     291                return help;
     292        }
     293
     294        @ParamAnnotation
     295        public String getType() {
     296                return typeString;
    238297        }
    239298
     
    328387
    329388
    330         public static FramsClass getFramsClass() {
    331                 return new FramsClass("prop", "prop", null)
    332                         .append(Param.build().id("name").name("Name").type(StringParam.class))
    333                         .append(Param.build().id("id").name("Id").type(StringParam.class))
    334                         .append(Param.build().id("type").name("Type").type(StringParam.class))
    335                         .append(Param.build().id("help").name("Help").type(StringParam.class))
    336                         .append(Param.build().id("group").name("Group").type(DecimalParam.class))
    337                         .append(Param.build().id("flags").name("Flags").type(DecimalParam.class));
    338         }
    339389
    340390}
  • java/main/src/main/java/com/framsticks/params/ReflectionAccess.java

    r85 r86  
    33import java.lang.reflect.Field;
    44import java.lang.reflect.InvocationTargetException;
    5 import java.lang.reflect.Modifier;
     5import java.lang.reflect.Method;
     6import java.util.HashMap;
     7import java.util.Map;
    68
    79import org.apache.log4j.Logger;
    810
    9 import com.framsticks.util.lang.Containers;
    10 
     11import com.framsticks.util.FramsticksException;
     12
     13import static com.framsticks.util.lang.Containers.*;
    1114
    1215/**
     
    1922 */
    2023public class ReflectionAccess extends SimpleAbstractAccess {
    21         private final static Logger log = Logger.getLogger(ReflectionAccess.class.getName());
     24        private final static Logger log = Logger.getLogger(ReflectionAccess.class
     25                        .getName());
    2226
    2327        protected final Class<?> reflectedClass;
    2428        private Object object;
    2529
    26         public ReflectionAccess(Class<?> reflectedClass, FramsClass framsClass) {
     30
     31        protected interface ReflectedSetter {
     32                public <T> void set(Object object, T value) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException;
     33        }
     34
     35        protected interface ReflectedGetter {
     36                public abstract <T> T get(Object object, Class<T> type) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException;
     37        }
     38
     39        protected static class ReflectedValueParam {
     40                public ReflectedSetter setter;
     41                public ReflectedGetter getter;
     42        }
     43
     44        protected final Map<ValueParam, ReflectedValueParam> reflectedValueParams = new HashMap<>();
     45
     46        public ReflectionAccess(Class<?> reflectedClass) throws ConstructionException {
     47                this(reflectedClass, FramsClassBuilder.buildForClass(reflectedClass));
     48        }
     49
     50        public static boolean typeMatch(Class<?> a, Class<?> b) {
     51                assert !b.isPrimitive();
     52                if (!a.isPrimitive()) {
     53                        return a.equals(b);
     54                }
     55
     56                if (a.equals(int.class)) {
     57                        return b.equals(Integer.class);
     58                }
     59                if (a.equals(double.class)) {
     60                        return b.equals(Double.class);
     61                }
     62                if (a.equals(boolean.class)) {
     63                        return b.equals(Boolean.class);
     64                }
     65                assert false;
     66                return false;
     67        }
     68
     69        public ReflectionAccess(Class<?> reflectedClass, FramsClass framsClass) throws ConstructionException {
    2770                this.reflectedClass = reflectedClass;
    2871                setFramsClass(framsClass);
    29         }
    30 
    31         private static String accessorName(boolean get, String id) {
    32                 return (get ? "get"  : "set") + id.substring(0, 1).toUpperCase() + id.substring(1);
    33         }
     72
     73                Map<String, ParamCandidate> candidates = ParamCandidate.getAllCandidates(reflectedClass);
     74
     75                try {
     76                        for (final ValueParam vp : filterInstanceof(framsClass.getParamEntries(), ValueParam.class)) {
     77                                if (!candidates.containsKey(vp.getId())) {
     78                                        throw new ConstructionException().msg("missing candidate for param").arg("param", vp);
     79                                }
     80                                ParamCandidate pc = candidates.get(vp.getId());
     81                                if (pc.isReadOnly() && !vp.hasFlag(Flags.READONLY)) {
     82                                        throw new ConstructionException().msg("readonly state conflict").arg("param", vp);
     83                                }
     84                                if (!typeMatch(pc.getRawType(), vp.getStorageType())) {
     85                                        throw new ConstructionException().msg("types mismatch for param").arg("param", vp).arg("candidate", pc.getType()).arg("storage", vp.getStorageType());
     86                                }
     87
     88                                ReflectedValueParam rvp = new ReflectedValueParam();
     89                                reflectedValueParams.put(vp, rvp);
     90                                final boolean primitive = pc.isPrimitive();
     91                                if (pc.getField() != null) {
     92                                        final Field f = pc.getField();
     93                                        rvp.getter = new ReflectedGetter() {
     94                                                @Override
     95                                                public <T> T get(Object object, Class<T> type) throws IllegalArgumentException, IllegalAccessException {
     96                                                        return type.cast(f.get(object));
     97                                                }
     98                                        };
     99                                        if (!pc.isFinal()) {
     100                                                rvp.setter = new ReflectedSetter() {
     101                                                        @Override
     102                                                        public <T> void set(Object object, T value) throws IllegalArgumentException, IllegalAccessException {
     103                                                                if (value == null && primitive) {
     104                                                                        throw new FramsticksException().msg("setting null to primitive value");
     105                                                                }
     106                                                                f.set(object, value);
     107                                                        }
     108                                                };
     109                                        }
     110                                } else {
     111                                        final Method g = pc.getGetter();
     112
     113                                        rvp.getter = new ReflectedGetter() {
     114                                                @Override
     115                                                public <T> T get(Object object, Class<T> type) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {
     116                                                        return type.cast(g.invoke(object));
     117                                                }
     118                                        };
     119
     120                                        if (!pc.isFinal()) {
     121                                                final Method s = pc.getSetter();
     122                                                rvp.setter = new ReflectedSetter() {
     123                                                        @Override
     124                                                        public <T> void set(Object object, T value) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {
     125                                                                if (value == null && primitive) {
     126                                                                        throw new FramsticksException().msg("setting null to primitive value");
     127                                                                }
     128                                                                s.invoke(object, value);
     129                                                        }
     130                                                };
     131                                        }
     132                                }
     133                        }
     134                } catch (ConstructionException e) {
     135                        throw e.arg("java class", reflectedClass).arg("framsClass", framsClass);
     136                }
     137        }
     138
     139        // private static String accessorName(boolean get, String id) {
     140        //      return (get ? "get" : "set") + id.substring(0, 1).toUpperCase() + id.substring(1);
     141        // }
    34142
    35143        @Override
    36144        public <T> T get(ValueParam param, Class<T> type) {
    37                 if (object == null) {
    38                         return null;
    39                 }
    40                 try {
    41                         //TODO: use internal id, if present
    42                         String id = param.getId();
     145                try {
    43146                        try {
    44                                 return type.cast(reflectedClass.getField(id).get(object));
    45                         } catch (NoSuchFieldException ignored) {
    46                         }
    47                         try {
    48                                 return type.cast(reflectedClass.getMethod(accessorName(true, id)).invoke(object));
    49                         } catch (NoSuchMethodException | InvocationTargetException ex) {
    50                                 //e.printStackTrace();
    51                         }
    52                         try {
    53                                 return type.cast(reflectedClass.getMethod(id).invoke(object));
    54                         } catch (NoSuchMethodException | InvocationTargetException ex) {
    55                                 //e.printStackTrace();
    56                         }
    57 
    58                 } catch (IllegalAccessException e) {
    59                         log.warn("illegal access error occurred while trying to access returnedObject");
    60                         e.printStackTrace();
    61                 } catch (ClassCastException ignored) {
    62 
    63                 }
    64                 return null;
     147                                if (object == null) {
     148                                        throw new FramsticksException().msg("no object set");
     149                                }
     150
     151                                return reflectedValueParams.get(param).getter.get(object, type);
     152                        } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
     153                                throw new FramsticksException().msg("failed to get").cause(e);
     154                        }
     155                } catch (FramsticksException e) {
     156                        throw e.arg("param", param).arg("type", type).arg("access", this);
     157                }
    65158        }
    66159
     
    71164
    72165        private <T> void setValue(ValueParam param, T value) {
    73                 if (object == null) {
    74                         return;
    75                 }
    76                 try {
    77                         String id = param.getId();
     166                try {
    78167                        try {
    79                                 Field f = reflectedClass.getField(id);
    80                                 Class<?> t = f.getType();
    81                                 if (Modifier.isFinal(f.getModifiers())) {
    82                                         return;
    83                                 }
    84                                 if (value != null || (!t.isPrimitive())) {
    85                                         f.set(object, value);
    86                                 }
    87                                 return;
    88                         } catch (NoSuchFieldException ignored) {
    89                         }
    90                         try {
    91                                 reflectedClass.getMethod(accessorName(false, id), new Class[]{param.getStorageType()}).invoke(object, value);
    92                         } catch (InvocationTargetException | NoSuchMethodException ignored) {
    93                         }
    94                         try {
    95                                 reflectedClass.getMethod(id, new Class[]{param.getStorageType()}).invoke(object, value);
    96                         } catch (InvocationTargetException | NoSuchMethodException ignored) {
    97                         }
    98                 } catch (Exception ex) {
    99                         ex.printStackTrace();
     168                                if (object == null) {
     169                                        throw new FramsticksException().msg("no object set");
     170                                }
     171                                ReflectedSetter s = reflectedValueParams.get(param).setter;
     172                                if (s == null) {
     173                                        throw new FramsticksException().msg("trying to set final");
     174                                }
     175                                s.set(object, value);
     176                        } catch (IllegalArgumentException | IllegalAccessException | InvocationTargetException e) {
     177                                throw new FramsticksException().msg("failed to set").cause(e);
     178                        }
     179                } catch (FramsticksException e) {
     180                        throw e.arg("param", param).arg("value", value).arg("access", this);
    100181                }
    101182        }
     
    114195
    115196                try {
    116                         for (ValueParam p : Containers.filterInstanceof(framsClass.getParamEntries(), ValueParam.class)) {
     197                        for (ValueParam p : filterInstanceof(framsClass.getParamEntries(), ValueParam.class)) {
    117198                                setValue(p, p.getDef(Object.class));
    118199                        }
     
    159240
    160241        @Override
    161         public ReflectionAccess cloneAccess() {
     242        public ReflectionAccess cloneAccess() throws ConstructionException {
    162243                return new ReflectionAccess(reflectedClass, framsClass);
    163244        }
     
    173254                return null;
    174255        }
     256
     257        @Override
     258        public String toString() {
     259                StringBuilder b = new StringBuilder();
     260                b.append(framsClass);
     261                if (object != null) {
     262                        b.append("(").append(object).append(")");
     263                }
     264                return b.toString();
     265        }
     266
    175267}
     268
  • java/main/src/main/java/com/framsticks/params/Registry.java

    r84 r86  
    22
    33import org.apache.log4j.Logger;
     4
     5import com.framsticks.params.annotations.FramsClassAnnotation;
    46
    57import java.util.HashMap;
     
    3537        }
    3638
    37         public AccessInterface createAccess(String name, FramsClass framsClass) {
     39        public Registry register(Class<?> reflectedClass) {
     40                FramsClassAnnotation a = reflectedClass.getAnnotation(FramsClassAnnotation.class);
     41                if (a == null) {
     42                        log.error("class is not annotated: " + reflectedClass);
     43                        return this;
     44                }
     45
     46                registerReflectedClass(FramsClassBuilder.getName(a, reflectedClass), FramsClassBuilder.getId(a, reflectedClass), reflectedClass);
     47
     48                return this;
     49        }
     50
     51        public AccessInterface createAccess(String name, FramsClass framsClass) throws ConstructionException {
    3852                if (reflectedClasses.containsKey(name)) {
    3953                        return new ReflectionAccess(reflectedClasses.get(name), framsClass);
     
    6680
    6781        public static AccessInterface wrapAccessWithListIfNeeded(CompositeParam param, AccessInterface access) {
    68         if (access == null) {
     82                if (access == null) {
    6983                        return null;
    7084                }
    71         return param.prepareAccessInterface(access);
     85                return param.prepareAccessInterface(access);
    7286        }
    7387
    74     public AccessInterface prepareAccess(CompositeParam param) {
    75         return wrapAccessWithListIfNeeded(param, createAccess(param.getContainedTypeName()));
    76     }
     88        public AccessInterface prepareAccess(CompositeParam param) throws ConstructionException {
     89                return wrapAccessWithListIfNeeded(param, createAccess(param.getContainedTypeName()));
     90        }
    7791
    78         public AccessInterface createAccess(String name) {
     92        public AccessInterface createAccess(String name) throws ConstructionException {
    7993                if (name == null) {
    8094                        return null;
  • java/main/src/main/java/com/framsticks/params/SimpleAbstractAccess.java

    r84 r86  
    6565        @Override
    6666        public Param getParam(int i) {
    67                 return framsClass.getParamEntry(i, Param.class);
     67                return framsClass.getParam(i);
    6868        }
    6969
    7070        @Override
    7171        public Param getParam(String id) {
    72                 return framsClass.getParamEntry(id, Param.class);
     72                return framsClass.getParam(id);
    7373        }
    7474
     
    8080        @Override
    8181        public <T> T get(int i, Class<T> type) {
    82                 Param p = getParam(i);
    83                 assert p instanceof ValueParam;
    84                 return get((ValueParam) p, type);
     82                return get(framsClass.getParamEntry(i, ValueParam.class), type);
    8583        }
    8684
    8785        @Override
    8886        public <T> T get(String id, Class<T> type) {
    89                 Param p = getParam(id);
    90                 assert p instanceof ValueParam;
    91                 return get((ValueParam) p, type);
     87                return get(framsClass.getParamEntry(id, ValueParam.class), type);
     88        }
     89
     90        @Override
     91        public <T> int set(int i, T value) {
     92                return set(framsClass.getParamEntry(i, ValueParam.class), value);
    9293        }
    9394
    9495        @Override
    9596        public <T> int set(String id, T value) {
    96                 Param p = getParam(id);
    97                 assert p instanceof ValueParam;
    98                 return set((ValueParam) p, value);
    99         }
    100 
    101         @Override
    102         public <T> int set(int i, T value) {
    103                 Param p = getParam(i);
    104                 assert p instanceof ValueParam;
    105                 return set((ValueParam) p, value);
     97                return set(framsClass.getParamEntry(id, ValueParam.class), value);
    10698        }
    10799
     
    115107                        ReassignResult<?> result = param.reassign(value, oldValue);
    116108                        Object casted = result.getValue();
    117                         if (casted != oldValue) {
     109                        if (!casted.equals(oldValue)) {
    118110                                internalSet(param, casted);
    119111                        }
  • java/main/src/main/java/com/framsticks/params/SimpleSource.java

    r77 r86  
    66public class SimpleSource implements SourceInterface {
    77
    8         final String content;
     8        String content;
    99        int cursor;
    1010
    1111        public SimpleSource(String content) {
    1212                this.content = content;
    13         cursor = 0;
     13                cursor = 0;
    1414        }
    1515
     
    2121        @Override
    2222        public String readLine() {
     23                assert !isClosed();
    2324                if (cursor >= content.length()) {
    2425                        return null;
     
    4546        @Override
    4647        public void close() {
     48                content = null;
     49        }
    4750
     51        //TODO no magic numbers
     52        @Override
     53        public boolean isClosed() {
     54                return content != null;
    4855        }
     56
    4957}
  • java/main/src/main/java/com/framsticks/params/SourceInterface.java

    r77 r86  
    77        SourceInterface openInclude(String include);
    88        void close();
     9        boolean isClosed();
    910}
  • java/main/src/main/java/com/framsticks/params/Util.java

    r84 r86  
    33import java.util.ArrayList;
    44import java.util.List;
     5
    56
    67import static com.framsticks.util.lang.Containers.filterInstanceof;
     
    4445                return copied;
    4546        }
     47
    4648}
  • java/main/src/main/java/com/framsticks/parsers/F0Parser.java

    r85 r86  
    1717import com.framsticks.params.PrimitiveParam;
    1818import com.framsticks.util.lang.Containers;
    19 import com.framsticks.util.lang.Exceptions;
    2019import com.framsticks.util.lang.Pair;
    2120import com.framsticks.util.lang.Strings;
     
    119118
    120119        private static void warn(int lineNumber, String message, Exception e) {
    121                 log.warn("in line " + lineNumber + " the following error occurred (" + message + "): " + e + "\n" + Exceptions.printStackTrace(e));
     120                log.warn("in line " + lineNumber + " the following error occurred (" + message + "): " + e);
    122121        }
    123122
  • java/main/src/main/java/com/framsticks/parsers/FileSource.java

    r85 r86  
    99public class FileSource implements SourceInterface {
    1010
    11         private final BufferedReader reader;
     11        private BufferedReader reader;
    1212        private final String filename;
    1313
    14         protected FileSource(InputStream stream, String filename) {
     14        public FileSource(InputStream stream, String filename) {
    1515                this.filename = filename;
    1616                this.reader = new BufferedReader(new InputStreamReader(stream, Encoding.getFramsticksCharset()));
     
    2828        public String readLine()
    2929        {
     30                assert !isClosed();
    3031                try
    3132                {
     
    8081
    8182                }
     83                reader = null;
     84        }
     85
     86        @Override
     87        public boolean isClosed() {
     88                return reader == null;
    8289        }
    8390
  • java/main/src/main/java/com/framsticks/parsers/Loaders.java

    r85 r86  
    22
    33import com.framsticks.params.*;
    4 import org.apache.log4j.Logger;
     4// import org.apache.log4j.Logger;
    55
    66/**
     
    99public class Loaders {
    1010
    11         private static final Logger log = Logger.getLogger(Loaders.class.getName());
     11        // private static final Logger log = Logger.getLogger(Loaders.class.getName());
    1212
    13         public static FramsClass loadFramsClass(SourceInterface source) {
     13        public static FramsClass loadFramsClass(SourceInterface source) throws ConstructionException {
    1414                MultiParamLoader loader = new MultiParamLoader();
    1515                loader.setNewSource(source);
     
    1717                FramsClass result = new FramsClass();
    1818
    19                 AccessInterface framsClassAccess = new ReflectionAccess(FramsClass.class, FramsClass.getFramsClass());
    20                 AccessInterface paramBuilderAccess = new ReflectionAccess(ParamBuilder.class, ParamBuilder.getFramsClass());
     19                AccessInterface framsClassAccess = new ReflectionAccess(FramsClass.class, FramsClassBuilder.buildForClass(FramsClass.class));
     20                AccessInterface paramBuilderAccess = new ReflectionAccess(ParamBuilder.class, FramsClassBuilder.buildForClass(ParamBuilder.class));
    2121                framsClassAccess.select(result);
    2222                loader.addAccessInterface(framsClassAccess);
     
    4141                        return result;
    4242                } catch (Exception e) {
    43                         log.error("an error occurred while loading class description: " + e + " before " + source.readLine());
    44                         e.printStackTrace();
     43                        throw new ConstructionException().msg("an error occurred while loading class description").arg("before", loader.getCurrentLine()).cause(e);
    4544                }
    46                 return null;
    47 
    48 
    4945        }
    5046}
  • java/main/src/main/java/com/framsticks/parsers/MultiParamLoader.java

    r77 r86  
    99
    1010public class MultiParamLoader {
    11         private final static Logger logger = Logger
    12                         .getLogger(MultiParamLoader.class.getName());
     11        private final static Logger log = Logger.getLogger(MultiParamLoader.class);
    1312
    1413        /**
     
    5655         * Status of current execution.
    5756         */
    58         private Status status;
     57        private Status status = Status.None;
     58
     59        private void setStatus(Status status) {
     60                log.trace("changing status: " + this.status.toString() + " -> " + status.toString());
     61                this.status = status;
     62        }
    5963
    6064        /**
     
    6266         */
    6367        private SourceInterface currentSource;
     68
     69        protected String currentLine;
    6470
    6571
     
    8692        private String lastUnknownObjectName;
    8793
     94        /**
     95         * @return the currentLine
     96         */
     97        public String getCurrentLine() {
     98                return currentLine;
     99        }
     100
    88101        public MultiParamLoader() {
    89102
     
    94107         */
    95108        public Status go() throws Exception {
    96                 logger.trace("go");
     109                log.trace("go");
    97110
    98111                while (!isFinished()) {
     
    106119
    107120                        // read data
    108                         String line = currentSource.readLine();
     121                        currentLine = currentSource.readLine();
    109122
    110123                        // end of file
    111                         if (line == null) {
     124                        if (currentLine == null) {
    112125                                if (!returnFromIncluded()) {
    113126                                        finish();
     
    117130                                }
    118131                        }
     132                        log.trace("read line: " + currentLine);
    119133
    120134                        // empty line
    121                         if (line.length() == 0) {
     135                        if (currentLine.length() == 0) {
    122136                                continue;
    123137                        }
    124138
    125139                        // check if some file should be included
    126                         if (isIncludeLine(line) == LoopAction.Continue) {
     140                        if (isIncludeLine(currentLine) == LoopAction.Continue) {
    127141                                continue;
    128142                        }
    129143
    130144                        // check if should break on comment
    131                         if (isCommentLine(line) == LoopAction.Break) {
     145                        if (isCommentLine(currentLine) == LoopAction.Break) {
    132146                                break;
    133147                        }
    134148
    135149                        // get class getName
    136                         if (changeCurrentParamInterface(line) == LoopAction.Break) {
     150                        LoopAction action = changeCurrentParamInterface(currentLine);
     151                        if (action == LoopAction.Break) {
    137152                                break;
    138153                        }
     154                        if (action == LoopAction.Continue) {
     155                                continue;
     156                        }
     157                        log.warn("unknown line: " + currentLine);
    139158                }
    140159
     
    145164         * Checks whether the reader found a known or unknown object and execution
    146165         * should be passed to it.
     166         * @throws Exception
    147167         */
    148168        private LoopAction tryReadObject() throws Exception {
     
    150170                                || (status == Status.BeforeUnknown && lastAccessInterface != null)) {
    151171                        // found object - let it load data
    152             if (lastAccessInterface.getSelected() == null) {
    153                 lastAccessInterface.select(lastAccessInterface.createAccessee());
    154             }
     172                        if (lastAccessInterface.getSelected() == null) {
     173                                lastAccessInterface.select(lastAccessInterface.createAccessee());
     174                        }
     175                        log.trace("loading into " + lastAccessInterface);
    155176                        lastAccessInterface.load(currentSource);
    156177
     
    162183                        return LoopAction.Continue;
    163184                } else if (status == Status.BeforeUnknown) {
    164                         logger.info("Omitting unknown object: " + lastUnknownObjectName);
     185                        log.warn("omitting unknown object: " + lastUnknownObjectName);
    165186
    166187                        // found unknown object
    167188                        emptyParam.load(currentSource);
    168                         status = Status.AfterObject;
     189                        setStatus(Status.AfterObject);
    169190
    170191                        return LoopAction.Continue;
     
    185206                                        int beg = line.indexOf('\"');
    186207                                        if (beg == -1) {
    187                                                 logger.info("Wanted to include some file, but the format is incorrect");
     208                                                log.info("Wanted to include some file, but the format is incorrect");
    188209                                                return LoopAction.Continue;
    189210                                        }
     
    192213                                        int end = includeFileName.indexOf('\"');
    193214                                        if (end == -1) {
    194                                                 logger.info("Wanted to include some file, but the format is incorrect");
     215                                                log.info("Wanted to include some file, but the format is incorrect");
    195216                                                return LoopAction.Continue;
    196217                                        }
     
    235256                        if (lastAccessInterface != null) {
    236257                                if (isBreakCondition(Status.BeforeObject)) {
    237                                         logger.info("Breaking before object");
     258                                        log.debug("breaking before object");
    238259                                        return LoopAction.Break;
     260                                } else {
     261                                        return LoopAction.Continue;
    239262                                }
    240263                        } else {
    241264                                lastUnknownObjectName = typeName;
    242265                                if (isBreakCondition(Status.BeforeUnknown)) {
    243                                         logger.info("Breaking before unknown");
     266                                        log.debug("breaking before unknown");
    244267                                        return LoopAction.Break;
     268                                } else {
     269                                        return LoopAction.Continue;
    245270                                }
    246271                        }
     
    279304
    280305        private void finish() {
     306                log.trace("finishing");
    281307                if (currentSource != null) {
    282308                        currentSource.close();
    283309                }
    284310
    285                 status = Status.Finished;
     311                setStatus(Status.Finished);
    286312        }
    287313
     
    291317
    292318        public boolean setNewSource(SourceInterface source) {
    293                 logger.debug("switching current source to " + source.getFilename() + "...");
     319                log.debug("switching current source to " + source.getFilename() + "...");
    294320
    295321                currentSource = source;
    296                 status = Status.Loading;
     322                setStatus(Status.Loading);
    297323
    298324                return true;
     
    311337                // check if it is already included and break if it is
    312338                if (isAlreadyIncluded(includeFilename)) {
    313                         logger.debug("circular reference ignored (" + includeFilename
     339                        log.debug("circular reference ignored (" + includeFilename
    314340                                        + ")");
    315341                        return;
    316342                }
    317343
    318                 logger.info("including file " + includeFilename + "...");
     344                log.info("including file " + includeFilename + "...");
    319345
    320346                SourceInterface newSource = currentSource.openInclude(includeFilename);
     
    335361                for (String file : fileStack) {
    336362                        if (filename.equals(file)) {
    337                                 logger.warn("file " + filename + " was already included");
     363                                log.warn("file " + filename + " was already included");
    338364                                return true;
    339365                        }
     
    366392         */
    367393        private boolean isBreakCondition(Status condition) {
    368                 status = condition;
     394                setStatus(condition);
    369395                return breakConditions.contains(condition);
    370396        }
    371397
    372398        public Object returnObject() {
     399                assert lastAccessInterface != null;
    373400                Object result = lastAccessInterface.getSelected();
    374401                if (result == null) {
    375402                        return null;
    376403                }
    377         lastAccessInterface.select(null);
     404                lastAccessInterface.select(null);
    378405                return result;
    379406        }
  • java/main/src/main/java/com/framsticks/parsers/Savers.java

    r84 r86  
    1010        public static void saveFramsClass(SinkInterface sink, FramsClass framsClass) {
    1111
    12                 AccessInterface framsClassAccess = new ReflectionAccess(FramsClass.class, FramsClass.getFramsClass());
    13                 AccessInterface paramAccess = new ReflectionAccess(Param.class, Param.getFramsClass());
     12                AccessInterface framsClassAccess = new ReflectionAccess(FramsClass.class);
     13                AccessInterface paramAccess = new ReflectionAccess(Param.class);
    1414                framsClassAccess.select(framsClass);
    1515                framsClassAccess.save(sink);
  • java/main/src/main/java/com/framsticks/portals/Portal.java

    r85 r86  
    22
    33import com.framsticks.observers.Observer;
    4 import com.framsticks.params.FramsClass;
     4import com.framsticks.params.annotations.FramsClassAnnotation;
     5import com.framsticks.params.annotations.ParamAnnotation;
    56import com.framsticks.util.PeriodicTask;
    67import org.apache.log4j.Logger;
     
    1011 * @author Piotr Sniegowski
    1112 */
     13@FramsClassAnnotation
    1214public class Portal extends Observer {
    1315
    1416        private final static Logger log = Logger.getLogger(Portal.class.getName());
    1517
     18        @ParamAnnotation
    1619        public Integer counter = 0;
    1720
     
    3841        }
    3942
     43        @ParamAnnotation(id = "counter_squared", name = "Counter Squared")
    4044        public Double getCounterSquared() {
    4145                return (double)(counter * counter);
    4246        }
    4347
    44         public static void constructFramsClass(FramsClass.Constructor constructor) {
    45                 constructor.method("getCounterSquared").field("counter");
    46         }
    4748}
  • java/main/src/main/java/com/framsticks/util/lang/Containers.java

    r84 r86  
    44import java.util.Iterator;
    55import java.util.List;
     6
    67import org.apache.commons.collections.functors.InstanceofPredicate;
     8import org.apache.commons.collections.functors.NotPredicate;
    79import org.apache.commons.collections.iterators.FilterIterator;
    810
     
    2022        }
    2123
    22         @SuppressWarnings("unchecked")
    2324        public static <T> Iterable<T> filterInstanceof(Iterator<? super T> i, Class<T> type) {
    2425                return new IterableIterator<T>(new FilterIterator(i, new InstanceofPredicate(type)));
    2526        }
    2627
    27         @SuppressWarnings("unchecked")
    2828        public static <T> Iterable<T> filterInstanceof(Iterable<? super T> i, Class<T> type) {
    2929                return new IterableIterator<T>(new FilterIterator(i.iterator(), new InstanceofPredicate(type)));
    3030        }
    3131
    32         @SuppressWarnings("unchecked")
    3332        public static <T> Iterable<T> filterInstanceof(Collection<? super T> c, Class<T> type) {
    3433                return new IterableIterator<T>(new FilterIterator(c.iterator(), new InstanceofPredicate(type)));
    3534        }
    3635
    37         // @SuppressWarnings("unchecked")
    38         // public static <T> Iterable<T> filterNotInstanceof(Collection<T> c, Class<? extends T> type) {
    39         //      return new IterableIterator<T>(new FilterIterator(c.iterator(), new NotPredicate(new InstanceofPredicate(type))));
    40         // }
     36        public static <T> Iterable<T> filterNotInstanceof(Collection<T> c, Class<? extends T> type) {
     37                return new IterableIterator<T>(new FilterIterator(c.iterator(), new NotPredicate(new InstanceofPredicate(type))));
     38        }
    4139}
  • java/main/src/main/java/com/framsticks/util/lang/Delimeted.java

    r84 r86  
    11package com.framsticks.util.lang;
     2
     3import java.util.Iterator;
    24
    35import org.apache.commons.collections.Closure;
     
    2729        }
    2830
     31        public final Delimeted append(Iterator<?> i) {
     32                while (i.hasNext()) {
     33                        append(i.next());
     34                }
     35                return this;
     36        }
     37
    2938        public final String build() {
    3039                return (builder != null ? builder.toString() : empty);
  • java/main/src/main/java/com/framsticks/util/lang/IterableIterator.java

    r84 r86  
    3030        // }
    3131
     32
    3233        @SuppressWarnings("unchecked")
    33         public IterableIterator(Iterator<? extends T> i) {
     34        public IterableIterator(Iterator<?> i) {
    3435                this.i = (Iterator<T>) i;
    3536        }
  • java/main/src/main/java/com/framsticks/util/lang/Pair.java

    r84 r86  
    1515        @Override
    1616        public String toString() {
    17                 return Strings.toStringNullProof(first) + " " + Strings.toStringNullProof(second);
     17                return Strings.toStringNullProof(first) + " : " + Strings.toStringNullProof(second);
    1818        }
    1919
  • java/main/src/main/java/com/framsticks/util/lang/Strings.java

    r84 r86  
    4242                }
    4343        }
     44
     45        public static String capitalize(String input) {
     46                return input.substring(0, 1).toUpperCase() + input.substring(1);
     47        }
     48
     49        public static String uncapitalize(String input) {
     50                return input.substring(0, 1).toLowerCase() + input.substring(1);
     51        }
    4452}
  • java/main/src/test/resources/log4j.properties

    r84 r86  
    2727
    2828log4j.logger.com.framsticks=INFO
     29# log4j.logger.com.framsticks.parsers.MultiParamLoader=TRACE
    2930# log4j.logger.com.framsticks.gui.controls.SliderControl=TRACE
    3031# log4j.logger.com.framsticks.communication.ClientConnection=DEBUG
Note: See TracChangeset for help on using the changeset viewer.