aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2016-02-28 11:42:34 +0000
committerMichael Williamson <mike@zwobble.org>2016-02-28 11:42:34 +0000
commit4330f93c6e694b546b7f3e7bfd2e18b93b15fbab (patch)
tree410b118f06476f609b07c76ee2e5df5b7203e8c0 /src/main
parent4e4f98062c07afdeef14d4031ca69668649e5873 (diff)
Support reading of empty interfaces
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/org/zwobble/couscous/frontends/java/JavaReader.java23
-rw-r--r--src/main/java/org/zwobble/couscous/util/ExtraSets.java17
2 files changed, 32 insertions, 8 deletions
diff --git a/src/main/java/org/zwobble/couscous/frontends/java/JavaReader.java b/src/main/java/org/zwobble/couscous/frontends/java/JavaReader.java
index 6e7f3fc..4eb7c7d 100644
--- a/src/main/java/org/zwobble/couscous/frontends/java/JavaReader.java
+++ b/src/main/java/org/zwobble/couscous/frontends/java/JavaReader.java
@@ -17,6 +17,7 @@ import java.nio.file.Path;
import java.util.List;
import java.util.Map;
import java.util.Optional;
+import java.util.Set;
import java.util.function.Function;
import static com.google.common.collect.Iterables.concat;
@@ -65,18 +66,24 @@ public class JavaReader {
classes = ImmutableList.builder();
}
- private ClassNode readCompilationUnit(CompilationUnit ast) {
+ private TypeNode readCompilationUnit(CompilationUnit ast) {
TypeName name = generateClassName(ast);
Scope scope = Scope.create().enterClass(name);
TypeDeclaration type = (TypeDeclaration)ast.types().get(0);
TypeDeclarationBody body = readTypeDeclarationBody(scope, name, type.bodyDeclarations());
- return ClassNode.declareClass(
- name,
- superTypes(type),
- body.getFields(),
- body.getStaticConstructor(),
- body.getConstructor(),
- body.getMethods());
+ Set<TypeName> superTypes = superTypes(type);
+ if (type.isInterface()) {
+ // TODO: throw exception if other parts of body are declared
+ return InterfaceNode.declareInterface(name, superTypes, body.getMethods());
+ } else {
+ return ClassNode.declareClass(
+ name,
+ superTypes,
+ body.getFields(),
+ body.getStaticConstructor(),
+ body.getConstructor(),
+ body.getMethods());
+ }
}
GeneratedClosure readExpressionMethodReference(Scope outerScope, ExpressionMethodReference expression) {
diff --git a/src/main/java/org/zwobble/couscous/util/ExtraSets.java b/src/main/java/org/zwobble/couscous/util/ExtraSets.java
new file mode 100644
index 0000000..ab3dd16
--- /dev/null
+++ b/src/main/java/org/zwobble/couscous/util/ExtraSets.java
@@ -0,0 +1,17 @@
+package org.zwobble.couscous.util;
+
+import com.google.common.collect.ImmutableSet;
+
+import java.util.Set;
+
+public class ExtraSets {
+ private ExtraSets() {}
+
+ public static <T> Set<T> set() {
+ return ImmutableSet.of();
+ }
+
+ public static <T> Set<T> set(T value1) {
+ return ImmutableSet.of(value1);
+ }
+}