Skip to content

Commit

Permalink
Added first codegen skelaton
Browse files Browse the repository at this point in the history
  • Loading branch information
minborg committed Jan 20, 2015
1 parent 7f2b34b commit bc4f724
Show file tree
Hide file tree
Showing 15 changed files with 525 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,13 @@
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
<groupId>com.sun.codemodel</groupId>
<artifactId>codemodel-project</artifactId>
<version>2.6</version>
</dependency>
</dependencies>

</project>
26 changes: 26 additions & 0 deletions src/main/java/com/speedment/codegen/Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.speedment.codegen;

import com.speedment.codegen.model.Class_;
import com.speedment.codegen.model.Field_;
import static com.speedment.codegen.model.Type_.STRING;

/**
*
* @author pemi
*/
public class Test {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {

final Field_ field = new Field_(STRING, "foo").private_();

final Class_ class_ = new Class_();
class_.add(field);
class_.add(new Field_(STRING, "bar"));

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.speedment.codegen.control;

/**
*
* @author pemi
*/
public class AccessorImplementer {

}
27 changes: 27 additions & 0 deletions src/main/java/com/speedment/codegen/model/Block_.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.speedment.codegen.model;

import java.util.ArrayList;
import java.util.List;

/**
*
* @author pemi
*/
public class Block_ {

private final List<Statement_> statements;

public Block_() {
this.statements = new ArrayList<>();
}

Block_ add(Statement_ statement_) {
getStatements().add(statement_);
return this;
}

public List<Statement_> getStatements() {
return statements;
}

}
49 changes: 49 additions & 0 deletions src/main/java/com/speedment/codegen/model/Class_.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.speedment.codegen.model;

import java.util.ArrayList;
import java.util.List;

/**
*
* @author pemi
*/
public class Class_ {

private final List<Field_> fields;
private final List<Constructor_> constructors;
private final List<Method_> methods;

public Class_() {
this.fields = new ArrayList<>();
constructors = new ArrayList<>();
methods = new ArrayList<>();
}

public Class_ add(Field_ field) {
getFields().add(field);
return this;
}

public Class_ add(Constructor_ constructor) {
getConstructors().add(constructor);
return this;
}

public Class_ add(Method_ method_) {
getMethods().add(method_);
return this;
}

public List<Field_> getFields() {
return fields;
}

public List<Constructor_> getConstructors() {
return constructors;
}

public List<Method_> getMethods() {
return methods;
}

}
9 changes: 9 additions & 0 deletions src/main/java/com/speedment/codegen/model/Constructor_.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.speedment.codegen.model;

/**
*
* @author pemi
*/
public class Constructor_ {

}
24 changes: 24 additions & 0 deletions src/main/java/com/speedment/codegen/model/Expression_.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.speedment.codegen.model;

/**
*
* @author pemi
*/
public class Expression_ {

private String stringExpression;

public Expression_(String stringExpression) {
this.stringExpression = stringExpression;
}

public String getStringExpression() {
return stringExpression;
}

public Expression_ setStringExpression(String stringExpression) {
this.stringExpression = stringExpression;
return this;
}

}
98 changes: 98 additions & 0 deletions src/main/java/com/speedment/codegen/model/Field_.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package com.speedment.codegen.model;

/**
*
* @author pemi
*/
public class Field_ {

protected boolean private_;
protected boolean static_;
protected boolean final_;
protected Type_ type_;
private CharSequence name_;
private Expression_ expression_;

public Field_(Type_ type_, CharSequence name_) {
this.type_ = type_;
this.name_ = name_;
}

public Field_ private_() {
return private_(true);
}

public Field_ private_(boolean private_) {
this.private_ = private_;
return this;
}

public Field_ static_() {
return static_(true);
}

public Field_ static_(boolean static_) {
this.final_ = static_;
return this;
}

public Field_ final_(boolean final_) {
this.final_ = final_;
return this;
}

public Field_ final_() {
return final_(true);
}

// public static class Builder extends Field_ {
//
// public Builder(Type_ type_, CharSequence name_) {
// super(type_, name_);
// }
//
// public Builder private_() {
// return private_(true);
// }
//
// public Builder private_(boolean private_) {
// this.private_ = private_;
// return this;
// }
//
// public Builder static_(boolean static_) {
// this.final_ = static_;
// return this;
// }
//
// public Builder final_(boolean final_) {
// this.final_ = final_;
// return this;
// }
//
// public Field_ build() {
// return new Field_(private_, static_, final_, type_, name_);
// }
//
// }
//
// public static Builder builder(Type_ type_, CharSequence name_) {
// return new Builder(type_, name_);
// }

public CharSequence getName_() {
return name_;
}

public void setName_(CharSequence name_) {
this.name_ = name_;
}

public Expression_ getExpression_() {
return expression_;
}

public void setExpression_(Expression_ expression_) {
this.expression_ = expression_;
}
}
123 changes: 123 additions & 0 deletions src/main/java/com/speedment/codegen/model/Method_.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
package com.speedment.codegen.model;

import java.util.ArrayList;
import java.util.List;

/**
*
* @author pemi
*/
public class Method_ {

private boolean private_;
private boolean static_;
private boolean final_;
private Type_ type_;
private CharSequence name_;
private Expression_ expression_;
private Block_ block;
private List<Field_> parameters; // Todo: Introduce parameter

public Method_(Type_ type_, CharSequence name_) {
this.parameters = new ArrayList<>();
this.type_ = type_;
this.name_ = name_;
}

public Method_ private_() {
return private_(true);
}

public Method_ private_(boolean private_) {
this.setPrivate_(private_);
return this;
}

public Method_ static_() {
return static_(true);
}

public Method_ static_(boolean static_) {
this.setFinal_(static_);
return this;
}

public Method_ final_(boolean final_) {
this.setFinal_(final_);
return this;
}

public Method_ final_() {
return final_(true);
}

Method_ add(Field_ field_) {
getParameters().add(field_);
return this;
}

public boolean isPrivate_() {
return private_;
}

public void setPrivate_(boolean private_) {
this.private_ = private_;
}

public boolean isStatic_() {
return static_;
}

public void setStatic_(boolean static_) {
this.static_ = static_;
}

public boolean isFinal_() {
return final_;
}

public void setFinal_(boolean final_) {
this.final_ = final_;
}

public Type_ getType_() {
return type_;
}

public void setType_(Type_ type_) {
this.type_ = type_;
}

public CharSequence getName_() {
return name_;
}

public void setName_(CharSequence name_) {
this.name_ = name_;
}

public Expression_ getExpression_() {
return expression_;
}

public void setExpression_(Expression_ expression_) {
this.expression_ = expression_;
}

public Block_ getBlock() {
return block;
}

public void setBlock(Block_ block) {
this.block = block;
}

public List<Field_> getParameters() {
return parameters;
}

public void setParameters(List<Field_> parameters) {
this.parameters = parameters;
}

}

0 comments on commit bc4f724

Please sign in to comment.