Skip to content

Commit

Permalink
Made Method_ annotatable
Browse files Browse the repository at this point in the history
  • Loading branch information
emilforslund committed Jan 24, 2015
1 parent a69fdbc commit 027fd22
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 18 deletions.
2 changes: 2 additions & 0 deletions src/main/java/com/speedment/codegen/CodeUtil.java
Expand Up @@ -166,6 +166,8 @@ public static void tab(String tab) {
AE = "]",
SPACE = " ",
EMPTY = "",
COMMA = ",",
COMMA_SPACE = " ",
SC = ";",
DOT = ".",
AT = "@";
Expand Down
23 changes: 22 additions & 1 deletion src/main/java/com/speedment/codegen/model/method/Method_.java
Expand Up @@ -22,10 +22,13 @@
import com.speedment.codegen.model.field.Field_;
import com.speedment.codegen.model.Statement_;
import com.speedment.codegen.model.Type_;
import com.speedment.codegen.model.annotation.Annotatable;
import com.speedment.codegen.model.annotation.Annotation_;
import com.speedment.codegen.model.modifier.MethodModifier_;
import com.speedment.codegen.model.modifier.Modifiable;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Stream;
Expand All @@ -34,9 +37,10 @@
*
* @author pemi
*/
public class Method_ implements CodeModel, Modifiable<MethodModifier_> {
public class Method_ implements CodeModel, Modifiable<MethodModifier_>, Annotatable {

private final Set<MethodModifier_> modifiers;
private final List<Annotation_> annotations;
private Type_ type_;
private CharSequence name_;
private Expression_ expression_;
Expand All @@ -46,9 +50,11 @@ public class Method_ implements CodeModel, Modifiable<MethodModifier_> {
public Method_(Type_ type_, CharSequence name_) {
this.parameters = new ArrayList<>();
this.statements = new ArrayList<>();
this.annotations = new ArrayList<>();
this.type_ = type_;
this.name_ = name_;
this.modifiers = EnumSet.noneOf(MethodModifier_.class);

}

@SuppressWarnings("unchecked")
Expand Down Expand Up @@ -134,4 +140,19 @@ public Method_ set(final Set<MethodModifier_> newSet) {
return this;
}

@Override
public List<Annotation_> getAnnotations() {
return annotations;
}

@Override
public boolean has(Annotation_ annotation_) {
return annotations.contains(annotation_);
}

@Override
public Method_ add(Annotation_ annotation) {
annotations.add(annotation);
return this;
}
}
Expand Up @@ -47,7 +47,7 @@ public CharSequence render(CodeGenerator renderer, Class_ model) {
renderParent(model),
renderList(model.getInterfaces(), renderer, COMMA_STRING, IMPLEMENTS_STRING, SPACE),
looseBracketsIndent(new $(
renderList(model.getFields(), renderer, nl()), dnl(),
renderList(model.getFields(), renderer, scnl(), EMPTY, SC), dnl(),
renderList(model.getConstructors(), renderer, nl()), dnl(),
renderList(model.getMethods(), renderer, dnl())
))
Expand Down
21 changes: 5 additions & 16 deletions src/main/java/com/speedment/codegen/view/java/MethodView.java
Expand Up @@ -20,7 +20,6 @@
import com.speedment.codegen.model.method.Method_;
import com.speedment.codegen.view.CodeView;
import static com.speedment.codegen.CodeUtil.*;
import com.speedment.codegen.model.modifier.Modifier_;
import java.util.stream.Collectors;
import com.speedment.util.$;

Expand All @@ -29,27 +28,17 @@
* @author Duncan
*/
public class MethodView extends CodeView<Method_> {
private final static CharSequence
PUBLIC = "public ",
PROTECTED = "protected ",
PRIVATE = "private ",
FINAL = "final ",
STATIC = "static ",
COMMA = ", ";

@Override
public CharSequence render(CodeGenerator renderer, Method_ method) {
return new $(
// method. ? PUBLIC :
// method.isProtected_() ? PROTECTED :
// method.isPrivate_() ? PRIVATE : EMPTY,
// method.isFinal_() ? FINAL : EMPTY,
// method.isStatic_() ? STATIC : EMPTY,
method.getAnnotations().stream()
.map((anno) -> renderer.on(anno))
.collect(Collectors.joining(nl(), EMPTY, nl())),
method.getName_(), PS,
method.getParameters().stream()
.map((param) -> renderer.on(param))
.collect(Collectors.joining(COMMA)),
PE, renderer.on(method.getBlock_())
.collect(Collectors.joining(COMMA_SPACE)),
PE, SPACE, renderer.on(method.getBlock_())
);
}
}

0 comments on commit 027fd22

Please sign in to comment.