Skip to content

Commit

Permalink
cleanups, refinements and preparation of moshi generator
Browse files Browse the repository at this point in the history
+ making loading of generators more lazy as it might not needed
  • Loading branch information
elucash committed Feb 23, 2016
1 parent 87ec28b commit e44e106
Show file tree
Hide file tree
Showing 15 changed files with 988 additions and 494 deletions.
7 changes: 0 additions & 7 deletions cases/pom.xml
Expand Up @@ -78,13 +78,6 @@
<version>3.0.0</version>
<scope>test</scope>
</dependency>
<dependency>
<!-- Test only for moshi -->
<groupId>com.squareup.moshi</groupId>
<artifactId>moshi</artifactId>
<version>0.9.0</version>
<scope>test</scope>
</dependency>
</dependencies>
<repositories>
<repository>
Expand Down
66 changes: 0 additions & 66 deletions cases/src/org/immutables/moshi/Json.java

This file was deleted.

69 changes: 0 additions & 69 deletions cases/test/org/immutables/moshi/Adapt.java

This file was deleted.

Expand Up @@ -61,6 +61,7 @@ package [type.package];
[/if]

import java.lang.String;
import java.lang.Object;
[for starImport in type.requiredSourceStarImports]
import [starImport];
[/for]
Expand Down Expand Up @@ -778,7 +779,7 @@ private Object writeReplace() {
*/
public final [builderReturnType type] domain(Domain domain) {
this.domain = [requireNonNull type](domain, "domain");
[builderReturnThis type]
return [builderReturnThis type];
}
[/if]
[if type.kind.isValue]
Expand All @@ -795,7 +796,7 @@ private Object writeReplace() {
public final [builderReturnType type] [type.names.from]([type.typeImmutable.relative] instance) {
[requireNonNull type](instance, "instance");
from((Object) instance);
[builderReturnThis type]
return [builderReturnThis type];
}

/**
Expand All @@ -806,7 +807,7 @@ private Object writeReplace() {
[type.typeAbstract.access]final [builderReturnType type] [type.names.from]([type.typeAbstract.relative] instance) {
[requireNonNull type](instance, "instance");
from((Object) instance);
[builderReturnThis type]
return [builderReturnThis type];
}
[else]

Expand All @@ -818,7 +819,7 @@ private Object writeReplace() {
public final [builderReturnType type] [type.names.from]([s.type] instance) {
[requireNonNull type](instance, "instance");
from((Object) instance);
[builderReturnThis type]
return [builderReturnThis type];
}
[/if]
[/for]
Expand Down Expand Up @@ -872,15 +873,15 @@ private Object writeReplace() {
[for v in setters]
[buildFromAttribute v]
[/for]
[builderReturnThis type]
return [builderReturnThis type];
}
[else]
public final [builderReturnType type] [type.names.from]([type.typeAbstract.relative] instance) {
[requireNonNull type](instance, "instance");
[for v in setters]
[buildFromAttribute v]
[/for]
[builderReturnThis type]
return [builderReturnThis type];
}
[/if]
[/if]
Expand Down Expand Up @@ -933,7 +934,7 @@ checkNotIsSet([v.names.isSet](), "[v.name]");
[else]
[v.name]Builder.add(element);
[/if]
[builderReturnThis type]
return [builderReturnThis type];
}

/**
Expand All @@ -959,7 +960,7 @@ checkNotIsSet([v.names.isSet](), "[v.name]");
[v.name]Builder.add(elements);
[/if]
[/if]
[builderReturnThis type]
return [builderReturnThis type];
}
[if not type.useStrictBuilder]

Expand Down Expand Up @@ -990,7 +991,7 @@ checkNotIsSet([v.names.isSet](), "[v.name]");
[else]
[v.name]Builder.addAll(elements);
[/if]
[builderReturnThis type]
return [builderReturnThis type];
}
[else if v.optionalType]
[if not v.isBuilderParameter]
Expand All @@ -1011,7 +1012,7 @@ checkNotIsSet([v.names.isSet](), "[v.name]");
this.[v.name] = [optionalOf v]([v.name]);
[/if]
[nondefaultSetInBuilder v]
[builderReturnThis type]
return [builderReturnThis type];
}
[/if]

Expand All @@ -1031,7 +1032,7 @@ checkNotIsSet([v.names.isSet](), "[v.name]");
this.[v.name] = [requireNonNull type]([v.name], "[v.name]");
[/if]
[nondefaultSetInBuilder v]
[builderReturnThis type]
return [builderReturnThis type];
}
[else if v.mapType]
[for gE = v.consumedElementType, uK = v.unwrappedElementType, wK = v.wrappedElementType, uV = v.unwrappedSecondaryElementType, wV = v.wrappedSecondaryElementType]
Expand All @@ -1047,7 +1048,7 @@ checkNotIsSet([v.names.isSet](), "[v.name]");
[deprecation v]
public final [builderReturnType type] [v.names.put]([uK] key, [uV]... values) {
[v.name]Builder.putAll(key, [arrayAsListSecondary v 'values']);
[builderReturnThis type]
return [builderReturnThis type];
}

/**
Expand All @@ -1059,7 +1060,7 @@ checkNotIsSet([v.names.isSet](), "[v.name]");
[deprecation v]
public final [builderReturnType type] [v.names.putAll]([uK] key, Iterable<[wV]> values) {
[v.name]Builder.putAll(key, values);
[builderReturnThis type]
return [builderReturnThis type];
}
[/if]
[/if]
Expand All @@ -1080,7 +1081,7 @@ checkNotIsSet([v.names.isSet](), "[v.name]");
[else]
[v.name]Builder.put(key, value);
[/if]
[builderReturnThis type]
return [builderReturnThis type];
}

/**
Expand All @@ -1097,7 +1098,7 @@ checkNotIsSet([v.names.isSet](), "[v.name]");
[else]
[v.name]Builder.put(entry);
[/if]
[builderReturnThis type]
return [builderReturnThis type];
}
[if not type.useStrictBuilder]

Expand Down Expand Up @@ -1130,7 +1131,7 @@ checkNotIsSet([v.names.isSet](), "[v.name]");
[else]
[v.name]Builder.putAll(entries);
[/if]
[builderReturnThis type]
return [builderReturnThis type];
}
[/for]
[else if v.arrayType]
Expand All @@ -1149,12 +1150,12 @@ checkNotIsSet([v.names.isSet](), "[v.name]");
[checkNotIsSet v]
[if v.nullable][-- this is a special case --]
if (elements == null) {
[builderReturnThis type]
return [builderReturnThis type];
}
[/if]
this.[v.name] = elements.clone();
[mandatorySetInBuilder v]
[builderReturnThis type]
return [builderReturnThis type];
}
[else]
[if v.constructorParameters]
Expand All @@ -1175,7 +1176,7 @@ checkNotIsSet([v.names.isSet](), "[v.name]");
this.[v.name] = [v.attributeValueType.factoryOf]([for c in v.constructorParameters][if not for.first], [/if][c.name][/for]);
[nondefaultSetInBuilder v]
[mandatorySetInBuilder v]
[builderReturnThis type]
return [builderReturnThis type];
}
[/if]

Expand All @@ -1201,7 +1202,7 @@ checkNotIsSet([v.names.isSet](), "[v.name]");
[/if]
[nondefaultSetInBuilder v]
[mandatorySetInBuilder v]
[builderReturnThis type]
return [builderReturnThis type];
}
[/if]
[/for]
Expand All @@ -1221,7 +1222,7 @@ checkNotIsSet([v.names.isSet](), "[v.name]");
[for v in setters]
[defineOrResetBuildingField v false]
[/for]
[builderReturnThis type]
return [builderReturnThis type];
}
[/if]

Expand Down Expand Up @@ -2722,9 +2723,8 @@ java.util.List<[a.elementType]> [variableName] = new java.util.ArrayList<[a.elem
[/if]
[/output.trim][/template]

[template builderReturnThis Type type]
return [if type.innerBuilder.isExtending]([type.typeBuilder]) [/if]this;
[/template]
[-- templates below are one-liners so they auto-inlined --]
[template builderReturnThis Type type][if type.innerBuilder.isExtending]([type.typeBuilder]) [/if]this[/template]

[template requireNonNull Type type][if type.generateJdkOnly][objectsUtilRef type]requireNonNull[else][guava].base.Preconditions.checkNotNull[/if][/template]

Expand Down
Expand Up @@ -15,21 +15,22 @@
*/
package org.immutables.value.processor;

import org.immutables.generator.Templates;
import org.immutables.generator.Generator;

@Generator.Template
abstract class Immutables extends ValuesTemplate {
abstract org.immutables.generator.Templates.Invokable arrayAsList();

abstract org.immutables.generator.Templates.Invokable arrayAsListSecondary();
abstract Templates.Invokable arrayAsListSecondary();

abstract org.immutables.generator.Templates.Invokable objectsUtilRef();
abstract Templates.Invokable objectsUtilRef();

abstract org.immutables.generator.Templates.Invokable objectsUtility();
abstract Templates.Invokable objectsUtility();

abstract org.immutables.generator.Templates.Invokable collectionUtility();
abstract Templates.Invokable collectionUtility();

abstract org.immutables.generator.Templates.Invokable equalsAttribute();
abstract Templates.Invokable equalsAttribute();

abstract org.immutables.generator.Templates.Invokable primitiveHashCode();
abstract Templates.Invokable primitiveHashCode();
}

0 comments on commit e44e106

Please sign in to comment.