@Override public final int hashCode() { return Objects.hashCode(packageInfo(), simpleName()); }
@Override public final boolean equals(final Object obj) { if (obj == this) { return true; } if (obj instanceof SimpleTypeInfo) { final SimpleTypeInfo that = (SimpleTypeInfo) obj; return Objects.equal(packageInfo(), that.packageInfo()) && Objects.equal(simpleName(), that.simpleName()); } else { return false; } }
public Object newInstance() throws ClassNotFoundException { try { String qualifiedName = toString(); Class<?> type = Class.forName(qualifiedName); Constructor<?> constructor = type.getDeclaredConstructor(); Invokable<?, ?> invokable = Invokable.from(constructor); if (!invokable.isAccessible()) { invokable.setAccessible(true); } return invokable.invoke(null); } catch (SecurityException e) { throw new RuntimeException(simpleName() + " could not be instantiated", e); } catch (NoSuchMethodException e) { throw new RuntimeException(simpleName() + " has no nullary Constructor", e); } catch (InvocationTargetException e) { throw new RuntimeException(simpleName() + " could not be instantiated", e); } catch (IllegalAccessException e) { throw new AssertionError(e); } }
@Override public String toString() { return enumType().simpleName() + "." + value(); }
void recordBuilderCode(Body body) { SimpleTypeInfo returnTypeInfo = property.returnTypeInfo(); if (returnTypeInfo.isPrimitive()) { body.add(".$L(record.$LValue())", property.name(), returnTypeInfo.simpleName()); } else { body.add(".$L(record.<$T> get())", property.name(), returnTypeInfo.typeName()); } }
@Override public MustacheObject toMustache() { return Mustaches.toMustacheHelper() .add("package", packageInfo().orNull()) .add("name", getDeclaredName()) .add("simpleName", simpleName()) .add("qualifiedName", toString()) .add("rawName", getRawName()) .add("varName", varName()) .add("primitive", isPrimitive()) .toMustache(); }