@Override public int hashCode() { int result = super.hashCode(); result = 31 * result + (context != null ? context.hashCode() : 0); result = 31 * result + (className != null ? className.hashCode() : 0); result = 31 * result + (superClass != null ? superClass.hashCode() : 0); result = 31 * result + (interfaces != null ? interfaces.hashCode() : 0); result = 31 * result + (scope != null ? scope.hashCode() : 0); result = 31 * result + (isArray ? 1 : 0); result = 31 * result + dimensions; result = 31 * result + (isInterface ? 1 : 0); result = 31 * result + (isAbstract ? 1 : 0); result = 31 * result + (isFinal ? 1 : 0); result = 31 * result + (isStatic ? 1 : 0); result = 31 * result + (isInner ? 1 : 0); result = 31 * result + (methods != null ? methods.hashCode() : 0); result = 31 * result + (fields != null ? fields.hashCode() : 0); result = 31 * result + (constructors != null ? constructors.hashCode() : 0); result = 31 * result + (typeVariables != null ? typeVariables.hashCode() : 0); result = 31 * result + (reifiedFormOf != null ? reifiedFormOf.hashCode() : 0); result = 31 * result + (_nameCache != null ? _nameCache.hashCode() : 0); result = 31 * result + (_methodsCache != null ? Arrays.hashCode(_methodsCache) : 0); result = 31 * result + (_fieldsCache != null ? Arrays.hashCode(_fieldsCache) : 0); result = 31 * result + (_constructorsCache != null ? Arrays.hashCode(_constructorsCache) : 0); result = 31 * result + (generatedCache != null ? generatedCache.hashCode() : 0); return result; }
@Override public String toJavaString() { if (generatedCache != null) return generatedCache; StringBuilder buf = new StringBuilder(512); if (classComment != null) { buf.append(new Comment(classComment).generate(null)).append("\n"); } context.addVariable(Variable.create("this", this)); for (Annotation a : annotations) { buf.append(new AnnotationLiteral(a).getCanonicalString(context)); buf.append(" "); } if (!annotations.isEmpty()) buf.append("\n"); buf.append("\n"); buf.append(scope.getCanonicalName()); if (isAbstract) { buf.append(" abstract"); } if (isStatic) { buf.append(" static"); } if (isInterface()) { buf.append(" interface ").append(getName()); } else { buf.append(" class ").append(getName()); } if (getSuperClass() != null) { buf.append(" extends ") .append(LoadClassReference.getClassReference(getSuperClass(), context)); } if (interfaces.size() != 0) { buf.append(" implements "); Iterator<MetaClass> iter = interfaces.iterator(); while (iter.hasNext()) { buf.append(LoadClassReference.getClassReference(iter.next(), context)); if (iter.hasNext()) buf.append(", "); } } superClass = (superClass != null) ? superClass : MetaClassFactory.get(Object.class); context.addVariable(Variable.create("super", superClass)); buf.append(" {\n"); buf.append(membersToString()); StringBuilder headerBuffer = new StringBuilder(128); if (!getPackageName().isEmpty() && !isInner) headerBuffer.append("package ").append(getPackageName()).append(";\n"); if (!context.getRequiredImports().isEmpty()) headerBuffer.append("\n"); if (!isInner) { for (String cls : context.getRequiredImports()) { if (getFullyQualifiedName().equals(cls)) { continue; } else { String pkg = getPackageName(); if (cls.startsWith(pkg)) { if (cls.substring(pkg.length() + 1).indexOf('.') == -1) { continue; } } } headerBuffer.append("import ").append(cls).append(";\n"); } } return generatedCache = PrettyPrinter.prettyPrintJava(headerBuffer.toString() + buf.append("}\n").toString()); }