
templates.default.stg Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of quality-immutable-object Show documentation
Show all versions of quality-immutable-object Show documentation
The goal of Quality-Immutable-Object is to provide a small Java library that
generates automatically an immutable object class and corresponding builder
based on an Java interface (only with accessor methods).
The newest version!
immutableCompilationUnit(settings) ::= <<
>>
immutableClass(settings) ::= <<
public final class implements {
private final int hash;
}
>>
accessorMethod(field) ::= <<
public () {
return ;
}
>>
accessToMemberField(field) ::= <<
>>
accessToArgument(field) ::= <<
>>
annotate(annotation) ::= <<
@
>>
annotateImmutable(settings) ::= <<
@Immutable
>>
annotateNonnull(settings) ::= <<
@Nonnull
>>
annotateNotThreadSafe(settings) ::= <<
@NotThreadSafe
>>
attribute(field) ::= <<
final
>>
constant(field) ::= <<
static final = ;
>>
immutableConstructor(name, fields, settings) ::= <<
public () {
hash = buildHashCode();
}
>>
copyOfMethods(settings) ::= <<
public static copyOf( final ) {
Check.notNull(, "");
return new ();
}
public static copyOnlyIfNecessary( final ) {
Check.notNull(, "");
return instanceof ? () : copyOf();
}
>>
copyOfAttribute(field, settings) ::= <<
.()
>>
copyOfAttributes(settings) ::= <<
}; separator = ",">
>>
equalsMethod(name, fields, settings) ::= <<
@Override
public boolean equals(final Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
other = () obj;
return ;
return true;
}
>>
equalsFieldBlock(field) ::= <<
if ( == null) {
if (other. != null)
return false;
} else
if ( != other.!.equals(other.))
return false;
>>
equalsMemberFieldWithOther(field) ::= <<
Objects.equal(this., other.)
>>
hashCodeMethod(fields, settings) ::= <<
@Override
public int hashCode() {
return hash;
}
>>
hashCodeMethodBody(fields, settings) ::= <<
return Objects.hashCode();
final int prime = 31;
int result = 1;
return result;
>>
hashCodeField(field) ::= <<
result = prime * result +
( ? 1231 : 1237)
( == null ? 0 : .hashCode())
.hashCode()
;
>>
hashCodePrecomputationMethod(fields, settings) ::= <<
private static int buildHashCode() {
}
>>
hashCodePrecomputationMethodBody(fields, settings) ::= <<
return Objects.hashCode();
final int prime = 31;
int result = 1;
return result;
>>
hashCodePrecomputationField(field) ::= <<
result = prime * result +
( ? 1231 : 1237)
( == null ? 0 : .hashCode())
.hashCode()
;
>>
asFinalField(field) ::= <<
private final ;
>>
asNonFinalField(field) ::= <<
private ;
>>
importStatement(i) ::= <<
import .;
>>
importGuavaClasses(settings) ::= <<
import com.google.common.base.Objects;
import com.google.common.collect.*;
>>
importJsr305Annotations(settings) ::= <<
import javax.annotation.Nonnegative;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;
import javax.annotation.concurrent.NotThreadSafe;
>>
importQualityCheck(settings) ::= <<
import net.sf.qualitycheck.Check;
>>
importedType(type) ::= <<
\<\>
>>
interface(interface) ::= <<
>>
package(package) ::= <<
package ;
>>
setupFieldMutable(field, settings) ::= <<
this. = ;
>>
setupFieldsImmutable(fields, settings) ::= <<
}>
>>
setupFieldImmutable(field, settings) ::= <<
this. = ;
>>
toStringMethod(fields, settings) ::= <<
@Override
public String toString() {
return " []";
}
>>
toStringField(field) ::= <<
=" + this. + "
>>
builderCompilationUnit(settings) ::= <<
import javax.annotation.concurrent.NotThreadSafe;
>>
builderClass(settings, innerClass) ::= <<
public static final class implements {
}
>>
defaultConstructor(settings) ::= <<
public () {
// default constructor
}
>>
buildMethod(settings) ::= <<
public build() {
return new ();
}
>>
buildMethodAttribute(field) ::= <<
>>
copyConstructor(settings) ::= <<
public ( final ) {