From 63fc003231e92e8f5ea2af29a04ba5507c212325 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Mon, 4 Apr 2016 22:42:15 +0100 Subject: Partial support for reading type parameters for methods --- .../java/org/zwobble/couscous/ast/MethodNode.java | 47 ++++++++++++++-------- 1 file changed, 30 insertions(+), 17 deletions(-) (limited to 'src/main/java/org/zwobble/couscous/ast/MethodNode.java') diff --git a/src/main/java/org/zwobble/couscous/ast/MethodNode.java b/src/main/java/org/zwobble/couscous/ast/MethodNode.java index 8863619..1e682fb 100644 --- a/src/main/java/org/zwobble/couscous/ast/MethodNode.java +++ b/src/main/java/org/zwobble/couscous/ast/MethodNode.java @@ -11,6 +11,7 @@ import java.util.Optional; import java.util.function.Function; import static org.zwobble.couscous.util.ExtraLists.eagerMap; +import static org.zwobble.couscous.util.ExtraLists.list; public class MethodNode implements Node { public static Builder staticMethod(String name) { @@ -83,6 +84,7 @@ public class MethodNode implements Node { annotations.build(), isStatic, name, + list(), arguments.build(), returnType, isAbstract ? Optional.empty() : Optional.of(body.build()), @@ -94,17 +96,19 @@ public class MethodNode implements Node { List annotations, boolean isStatic, String name, + List typeParameters, List arguments, Type returnType, Optional> body, List overrides) { - return new MethodNode(annotations, isStatic, name, arguments, returnType, body, overrides); + return new MethodNode(annotations, isStatic, name, typeParameters, arguments, returnType, body, overrides); } private final List annotations; private final boolean isStatic; private final String name; + private final List typeParameters; private final List arguments; private final Type returnType; private final Optional> body; @@ -114,6 +118,7 @@ public class MethodNode implements Node { List annotations, boolean isStatic, String name, + List typeParameters, List arguments, Type returnType, Optional> body, @@ -122,6 +127,7 @@ public class MethodNode implements Node { this.annotations = annotations; this.isStatic = isStatic; this.name = name; + this.typeParameters = typeParameters; this.arguments = arguments; this.returnType = returnType; this.body = body; @@ -139,7 +145,11 @@ public class MethodNode implements Node { public String getName() { return name; } - + + public List getTypeParameters() { + return typeParameters; + } + public List getArguments() { return arguments; } @@ -168,7 +178,7 @@ public class MethodNode implements Node { } public MethodNode mapBody(Function, List> function) { - return new MethodNode(annotations, isStatic, name, arguments, returnType, body.map(function), overrides); + return new MethodNode(annotations, isStatic, name, typeParameters, arguments, returnType, body.map(function), overrides); } @Override @@ -181,12 +191,27 @@ public class MethodNode implements Node { transformer.transformAnnotations(annotations), isStatic, transformer.transformMethodName(signature()), + transformer.transformFormalTypeParameters(typeParameters), transformer.transformFormalArguments(arguments), transformer.transform(returnType), body.map(transformer::transformStatements), eagerMap(overrides, transformer::transform)); } + @Override + public String toString() { + return "MethodNode(" + + "annotations=" + annotations + + ", isStatic=" + isStatic + + ", name=" + name + + ", typeParameters=" + typeParameters + + ", arguments=" + arguments + + ", returnType=" + returnType + + ", body=" + body + + ", overrides=" + overrides + + ')'; + } + @Override public boolean equals(Object o) { if (this == o) return true; @@ -197,6 +222,7 @@ public class MethodNode implements Node { if (isStatic != that.isStatic) return false; if (!annotations.equals(that.annotations)) return false; if (!name.equals(that.name)) return false; + if (!typeParameters.equals(that.typeParameters)) return false; if (!arguments.equals(that.arguments)) return false; if (!returnType.equals(that.returnType)) return false; if (!body.equals(that.body)) return false; @@ -209,24 +235,11 @@ public class MethodNode implements Node { int result = annotations.hashCode(); result = 31 * result + (isStatic ? 1 : 0); result = 31 * result + name.hashCode(); + result = 31 * result + typeParameters.hashCode(); result = 31 * result + arguments.hashCode(); result = 31 * result + returnType.hashCode(); result = 31 * result + body.hashCode(); result = 31 * result + overrides.hashCode(); return result; } - - @Override - public String toString() { - return "MethodNode(" + - "annotations=" + annotations + - ", isStatic=" + isStatic + - ", name=" + name + - ", arguments=" + arguments + - ", returnType=" + returnType + - ", body=" + body + - ", overrides=" + overrides + - ')'; - } - } -- cgit v1.2.3