Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.google.common.collect.ImmutableList;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.stream.Collectors;
import javax.annotation.Nullable;
Expand Down Expand Up @@ -122,10 +123,7 @@ public abstract static class Builder {
public abstract Builder setHeaderCommentStatements(
List<CommentStatement> headeCommentStatements);

public Builder setAnnotations(List<AnnotationNode> annotations) {
annotationsBuilder().addAll(annotations);
return this;
}
public abstract Builder setAnnotations(List<AnnotationNode> annotations);

public abstract Builder setIsStatic(boolean isStatic);

Expand Down Expand Up @@ -162,10 +160,10 @@ public Builder setArguments(VariableExpr... arguments) {

// Private accessors.

abstract ImmutableList.Builder<AnnotationNode> annotationsBuilder();

abstract String name();

abstract ImmutableList<AnnotationNode> annotations();

abstract TypeNode returnType();

abstract boolean isOverride();
Expand Down Expand Up @@ -231,9 +229,19 @@ public MethodDefinition build() {
}

// If this method overrides another, ensure that the Override annotaiton is the last one.
ImmutableList<AnnotationNode> processedAnnotations = annotations();
if (isOverride()) {
annotationsBuilder().add(AnnotationNode.OVERRIDE);
processedAnnotations =
annotations()
.<AnnotationNode>builder()
.addAll(annotations())
.add(AnnotationNode.OVERRIDE)
.build();
}
// Remove duplicates while maintaining insertion order.
setAnnotations(
new LinkedHashSet<AnnotationNode>(processedAnnotations)
.stream().collect(Collectors.toList()));

MethodDefinition method = autoBuild();

Expand Down
Loading