Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
106 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/target/ | ||
/nb-configuration.xml | ||
|
||
|
39 changes: 38 additions & 1 deletion
39
src/main/java/com/speedment/codegen/control/AccessorImplementer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,46 @@ | ||
package com.speedment.codegen.control; | ||
|
||
import com.speedment.codegen.model.Class_; | ||
import com.speedment.codegen.model.Field_; | ||
import com.speedment.codegen.model.Method_; | ||
import com.speedment.codegen.model.Statement_; | ||
|
||
/** | ||
* | ||
* @author pemi | ||
*/ | ||
public class AccessorImplementer { | ||
public class AccessorImplementer implements Controller { | ||
|
||
private final Class_ class_; | ||
|
||
public AccessorImplementer(final Class_ class_) { | ||
this.class_ = class_; | ||
} | ||
|
||
@Override | ||
public void apply() { | ||
class_.getFields().forEach((f) -> generateAccessors(f)); | ||
} | ||
|
||
protected void generateAccessors(final Field_ field_) { | ||
generateGetter(field_); | ||
generateSetter(field_); | ||
} | ||
|
||
protected void generateGetter(final Field_ field_) { | ||
final Method_ method_ = new Method_(field_.getType_(), "get" + firstCharCapital(field_.getName_())); | ||
method_.add(new Statement_("return " + field_.getName_())); | ||
class_.add(method_); | ||
} | ||
|
||
protected void generateSetter(final Field_ field_) { | ||
final Method_ method_ = new Method_(field_.getType_(), "set" + firstCharCapital(field_.getName_())).add(new Field_(field_.getType_(), field_.getName_())); | ||
method_.add(new Statement_("this." + field_.getName_() + " = ")); | ||
class_.add(method_); | ||
} | ||
|
||
private String firstCharCapital(CharSequence s) { | ||
return new StringBuilder().append(Character.toUpperCase(s.charAt(0))).append(s.subSequence(1, s.length())).toString(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.speedment.codegen.control; | ||
|
||
public interface Controller { | ||
|
||
void apply(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters