summaryrefslogtreecommitdiff
path: root/container-compiler-plugin/src/main/java/io/trygvis/container/compiler/model/TypeRef.java
diff options
context:
space:
mode:
Diffstat (limited to 'container-compiler-plugin/src/main/java/io/trygvis/container/compiler/model/TypeRef.java')
-rw-r--r--container-compiler-plugin/src/main/java/io/trygvis/container/compiler/model/TypeRef.java83
1 files changed, 83 insertions, 0 deletions
diff --git a/container-compiler-plugin/src/main/java/io/trygvis/container/compiler/model/TypeRef.java b/container-compiler-plugin/src/main/java/io/trygvis/container/compiler/model/TypeRef.java
new file mode 100644
index 0000000..aabfb45
--- /dev/null
+++ b/container-compiler-plugin/src/main/java/io/trygvis/container/compiler/model/TypeRef.java
@@ -0,0 +1,83 @@
+package io.trygvis.container.compiler.model;
+
+import javax.lang.model.type.TypeKind;
+
+public class TypeRef implements Comparable<TypeRef> {
+
+ public static final TypeRef VOID = new TypeRef("void", "void");
+ public static final TypeRef BOOLEAN = new TypeRef("boolean", null);
+ public static final TypeRef BYTE = new TypeRef("byte", null);
+ public static final TypeRef SHORT = new TypeRef("short", null);
+ public static final TypeRef CHAR = new TypeRef("char", null);
+ public static final TypeRef INT = new TypeRef("int", null);
+ public static final TypeRef LONG = new TypeRef("long", null);
+ public static final TypeRef FLOAT = new TypeRef("float", null);
+ public static final TypeRef DOUBLE = new TypeRef("double", null);
+
+ /**
+ * The name of a class used within a class file. Is either the simple name or the canonical name.
+ */
+ public final String name;
+
+ private final String canonicalName;
+
+ public String canonicalName() {
+ if (canonicalName == null) {
+ throw new RuntimeException("This type doesn't have a canonical name");
+ }
+
+ return canonicalName;
+ }
+
+ public boolean isPrimitive() {
+ return canonicalName == null;
+ }
+
+ public TypeRef(String name, String canonicalName) {
+ this.name = name;
+ this.canonicalName = canonicalName;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof TypeRef)) return false;
+
+ TypeRef classRef = (TypeRef) o;
+
+ return canonicalName.equals(classRef.canonicalName);
+ }
+
+ @Override
+ public int hashCode() {
+ return canonicalName.hashCode();
+ }
+
+ @Override
+ public int compareTo(TypeRef o) {
+ return canonicalName.compareTo(o.canonicalName);
+ }
+
+ public static TypeRef find(TypeKind kind) {
+ switch (kind) {
+ case BOOLEAN:
+ return BOOLEAN;
+ case BYTE:
+ return BYTE;
+ case SHORT:
+ return SHORT;
+ case CHAR:
+ return CHAR;
+ case INT:
+ return INT;
+ case LONG:
+ return LONG;
+ case FLOAT:
+ return FLOAT;
+ case DOUBLE:
+ return DOUBLE;
+ }
+
+ throw new RuntimeException("Unknown kind: " + kind);
+ }
+}