Skip to content

Commit

Permalink
Added support for the Fugue 2.x (under com.atlassion.fugue) and Fugue…
Browse files Browse the repository at this point in the history
… 3.x (under io.atlassion.fugue) Option class as an optional type.
  • Loading branch information
mzeijen committed Dec 2, 2015
1 parent 2fb9ba1 commit 81c1196
Show file tree
Hide file tree
Showing 14 changed files with 99 additions and 22 deletions.
12 changes: 12 additions & 0 deletions cases/pom.xml
Expand Up @@ -51,6 +51,18 @@
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.atlassian.fugue</groupId>
<artifactId>fugue</artifactId>
<version>2.2.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.atlassian.fugue</groupId>
<artifactId>fugue</artifactId>
<version>3.0.0</version>
<scope>test</scope>
</dependency>
<dependency>
<!-- Test only for moshi -->
<groupId>com.squareup.moshi</groupId>
Expand Down
7 changes: 7 additions & 0 deletions cases/test/org/immutables/moshi/Adapt.java
@@ -1,5 +1,6 @@
package org.immutables.moshi;

import com.atlassian.fugue.Option;
import com.google.common.collect.ListMultimap;
import com.google.common.collect.Multiset;
import com.google.common.collect.SetMultimap;
Expand All @@ -20,6 +21,12 @@ public interface Adapt {
@Value.Parameter
Multiset<Nst> bag();

@Value.Parameter
Option<String> optionFugue2();

@Value.Parameter
io.atlassian.fugue.Option<String> optionFugue3();

@Value.Immutable
public interface Inr {
String[] arr();
Expand Down
5 changes: 5 additions & 0 deletions cases/test/org/immutables/trees/ast/SampleTree.java
@@ -1,5 +1,6 @@
package org.immutables.trees.ast;

import com.atlassian.fugue.Option;
import com.google.common.base.Optional;
import java.util.List;
import org.immutables.trees.Trees;
Expand Down Expand Up @@ -31,6 +32,10 @@ interface Operator extends Expression {

Optional<String> position();

Option<String> fugue2Option();

io.atlassian.fugue.Option<String> fugue3Option();

enum Kind {
PLUS,
MINUS
Expand Down
10 changes: 10 additions & 0 deletions value-fixture/pom.xml
Expand Up @@ -76,6 +76,16 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.atlassian.fugue</groupId>
<artifactId>fugue</artifactId>
<version>2.2.1</version>
</dependency>
<dependency>
<groupId>io.atlassian.fugue</groupId>
<artifactId>fugue</artifactId>
<version>3.0.0</version>
</dependency>
</dependencies>

<build>
Expand Down
Expand Up @@ -15,6 +15,7 @@
*/
package org.immutables.fixture;

import com.atlassian.fugue.Option;
import com.google.common.base.Optional;
import java.util.List;
import org.immutables.fixture.subpack.SillySubstructure;
Expand All @@ -36,6 +37,10 @@ public interface SillyStructureWithId {

Optional<Integer> opt3();

Option<Integer> opt4();

io.atlassian.fugue.Option<Integer> opt5();

long very4();

double wet5();
Expand Down
Expand Up @@ -15,6 +15,7 @@
*/
package org.immutables.fixture.jdkonly;

import com.atlassian.fugue.Option;
import com.google.common.base.Optional;
import java.util.Objects;
import java.util.OptionalDouble;
Expand All @@ -36,6 +37,10 @@ public interface UsingAllOptionals {

OptionalDouble d1();

Option<String> fo2();

io.atlassian.fugue.Option<String> fo3();

class Use {
void use() {
UsingAllOptionals value =
Expand Down
@@ -1,5 +1,6 @@
package org.immutables.fixture.modifiable;

import com.atlassian.fugue.Option;
import com.google.common.base.Optional;
import com.google.common.collect.*;
import org.immutables.value.Value;
Expand Down Expand Up @@ -87,6 +88,10 @@ interface Standalone {

OptionalDouble d1();

Option<Integer> fugue2();

io.atlassian.fugue.Option<Integer> fugue3();

@Value.Default
default int def() {
return 1;
Expand Down
Expand Up @@ -201,7 +201,7 @@ if ([a.name]Value != null) {
}
[else if a.optionalType]
[a.type] [a.name]Optional = instance.[a.names.get]();
if ([a.name]Optional.isPresent()) {
if ([a.name]Optional.[optionalPresent a]) {
[a.unwrappedElementType] [a.name]Value = [a.name]Optional.[optionalGet a];
[generateWriteAttributeValue type a (a.name 'Value') false]
} else {
Expand Down Expand Up @@ -268,7 +268,7 @@ if ([a.name]Value != null) {
}
[else if a.optionalType]
[a.type] [a.name]Optional = instance.[a.names.get]();
if ([a.name]Optional.isPresent()) {
if ([a.name]Optional.[optionalPresent a]) {
out.name([serializedName a]);
[a.unwrappedElementType] [a.name]Value = [a.name]Optional.[optionalGet a];
[generateWriteAttributeValue type a (a.name 'Value') false]
Expand Down Expand Up @@ -692,4 +692,6 @@ out.value([variableName]);

[template optionalGet Attribute a][if a.jdkSpecializedOptional]getAs[toUpper a.elementType][else]get[/if]()[/template]

[template optionalEmpty Attribute a][a.rawType].[if a.jdkOptional]empty[else]absent[/if]()[/template]
[template optionalEmpty Attribute a][a.rawType].[if a.jdkOptional]empty[else if a.fugueOptional]none[else]absent[/if]()[/template]

[template optionalPresent Attribute a][if a.fugueOptional]isDefined[else]isPresent[/if]()[/template]
Expand Up @@ -210,7 +210,7 @@ private static class SerialForm implements java.io.Serializable {
values.add(toArray(instance.[v.names.get]().[if v.multimapType]entries[else]entrySet[/if]()));
}
[else if v.optionalType]
if (instance.[v.names.get]().isPresent()) {
if (instance.[v.names.get]().[optionalPresent v]) {
names.add("[v.name]");
values.add(instance.[v.names.get]().[optionalGet v]);
}
Expand Down Expand Up @@ -1219,7 +1219,7 @@ if ([for l in positions.longs][if not for.first]
[v.names.putAll](instance.[v.names.get]());
[else if v.optionalType]
[v.type] [v.name]Optional = instance.[v.names.get]();
if ([v.name]Optional.isPresent()) {
if ([v.name]Optional.[optionalPresent v]) {
[v.names.init]([v.name]Optional);
}
[else if v.nullable]
Expand Down Expand Up @@ -2458,9 +2458,11 @@ return [if type.innerBuilder.isExtending]([type.typeBuilder]) [/if]this;

[template optionalGet Attribute a][if a.jdkSpecializedOptional]getAs[toUpper a.elementType][else]get[/if]()[/template]

[template optionalEmpty Attribute a][a.rawType].[if a.jdkOptional]empty[else]absent[/if]()[/template]
[template optionalEmpty Attribute a][a.rawType].[if a.jdkOptional]empty[else if a.fugueOptional]none[else]absent[/if]()[/template]

[template optionalOf Attribute a][a.rawType].[if not a.optionalAcceptNullable]of[else if a.jdkOptional]ofNullable[else]fromNullable[/if][/template]
[template optionalOf Attribute a][a.rawType].[if not a.optionalAcceptNullable][if a.fugueOptional]some[else]of[/if][else if a.jdkOptional]ofNullable[else if a.fugueOptional]option[else]fromNullable[/if][/template]

[template optionalPresent Attribute a][if a.fugueOptional]isDefined[else]isPresent[/if]()[/template]

[template atNullableAccept Attribute a][if a.optionalType and a.optionalAcceptNullable][atNullable][/if][/template]

Expand Down
Expand Up @@ -635,7 +635,7 @@ private [v.atNullability][v.type] [v.name];
[v.names.putAll](instance.[v.names.get]());
[else if v.optionalType]
[v.type] [v.name]Optional = instance.[v.names.get]();
if ([v.name]Optional.isPresent()) {
if ([v.name]Optional.[optionalPresent v]) {
[v.names.set]([v.name]Optional);
}
[else if v.nullable]
Expand Down Expand Up @@ -845,9 +845,11 @@ import [starImport];

[template optionalGet Attribute a][if a.jdkSpecializedOptional]getAs[toUpper a.elementType][else]get[/if]()[/template]

[template optionalEmpty Attribute a][a.rawType].[if a.jdkOptional]empty[else]absent[/if]()[/template]
[template optionalEmpty Attribute a][a.rawType].[if a.jdkOptional]empty[else if a.fugueOptional]none[else]absent[/if]()[/template]

[template optionalOf Attribute a][a.rawType].[if not a.optionalAcceptNullable]of[else if a.jdkOptional]ofNullable[else]fromNullable[/if][/template]
[template optionalOf Attribute a][a.rawType].[if not a.optionalAcceptNullable][if a.fugueOptional]some[else]of[/if][else if a.jdkOptional]ofNullable[else if a.fugueOptional]option[else]fromNullable[/if][/template]

[template optionalPresent Attribute a][if a.fugueOptional]isDefined[else]isPresent[/if]()[/template]

[template atNullableAccept Attribute a][if a.optionalType and a.optionalAcceptNullable][atNullable][/if][/template]

Expand Down
Expand Up @@ -185,7 +185,7 @@ if ([a.name]Value != null) {
}
[else if a.optionalType]
[a.type] [a.name]Optional = instance.[a.names.get]();
if ([a.name]Optional.isPresent()) {
if ([a.name]Optional.[optionalPresent a]) {
[a.unwrappedElementType] [a.name]Value = [a.name]Optional.[optionalGet a];
[generateWriteAttributeValue type a (a.name 'Value') false]
} else {
Expand Down Expand Up @@ -252,7 +252,7 @@ if ([a.name]Value != null) {
}
[else if a.optionalType]
[a.type] [a.name]Optional = instance.[a.names.get]();
if ([a.name]Optional.isPresent()) {
if ([a.name]Optional.[optionalPresent a]) {
out.name([serializedName a]);
[a.unwrappedElementType] [a.name]Value = [a.name]Optional.[optionalGet a];
[generateWriteAttributeValue type a (a.name 'Value') false]
Expand Down Expand Up @@ -409,12 +409,12 @@ if (t == JsonReader.Token.NULL) {
return [optionalEmpty a];
}
[if a.jdkSpecializedOptional]
return [a.rawType].of([simpleTypeNext a.unwrappedElementType]);
return [a.rawType].of([simpleTypeNext a.unwrappedElementType]);kmo
[else if a.unwrappedElementPrimitiveType or (a.unwrappedElementType eq 'java.lang.String')]
return [a.rawType].<[a.elementType]>of([simpleTypeNext a.unwrappedElementType]);
return [optionalOf a]([simpleTypeNext a.unwrappedElementType]);
[else]
[generateReadAttributeValue type a a.wrappedElementType a.unwrapperOrRawElementType false]
return [a.rawType].of(value);
return [optionalOf a](value);
[/if]
[else if a.mapType]
[createBuilderForCollection type a 'mappings']
Expand Down Expand Up @@ -667,4 +667,8 @@ out.value([variableName]);

[template optionalGet Attribute a][if a.jdkSpecializedOptional]getAs[toUpper a.elementType][else]get[/if]()[/template]

[template optionalEmpty Attribute a][a.rawType].[if a.jdkOptional]empty[else]absent[/if]()[/template]
[template optionalEmpty Attribute a][a.rawType].[if a.jdkOptional]empty[else if a.fugueOptional]none[else]absent[/if]()[/template]

[template optionalOf Attribute a][a.rawType].[if a.fugueOptional]some[else]of[/if][/template]

[template optionalPresent Attribute a][if a.fugueOptional]isDefined[else]isPresent[/if]()[/template]
Expand Up @@ -55,10 +55,10 @@ package [transformerType.package];
[else if a.optionalType]

protected [a.rawType]<[a.wrappedElementType]> as[s][transformAttributeSuffix a]([t] value, [a.type] optional) {
if (optional.isPresent()) {
if (optional.[optionalPresent a]) {
[a.unwrappedElementType] original = optional.[optionalGet a];
[a.unwrappedElementType] changed = as[s][toUpper a.name](value, original);
return changed != original ? [a.rawType].of(changed) : optional;
return changed != original ? [optionalOf a](changed) : optional;
}
return [optionalEmpty a];
}
Expand Down Expand Up @@ -135,6 +135,7 @@ package [transformerType.package];

[template transformAttributeSuffix Attribute a][toUpper a.name][output.trim]
[if a.nullable]Nullable
[else if a.fugueOptional]Option
[else if a.optionalType]Optional
[else if a.mapType]Entries
[else if a.collectionType]Elements
Expand All @@ -143,4 +144,8 @@ package [transformerType.package];

[template optionalGet Attribute a][if a.jdkSpecializedOptional]getAs[toUpper a.elementType][else]get[/if]()[/template]

[template optionalEmpty Attribute a][a.rawType].[if a.jdkOptional]empty[else]absent[/if]()[/template]
[template optionalEmpty Attribute a][a.rawType].[if a.jdkOptional]empty[else if a.fugueOptional]none[else]absent[/if]()[/template]

[template optionalOf Attribute a][a.rawType].[if a.fugueOptional]some[else]of[/if][/template]

[template optionalPresent Attribute a][if a.fugueOptional]isDefined[else]isPresent[/if]()[/template]
Expand Up @@ -75,7 +75,12 @@ public enum AttributeTypeKind {
"java.util.OptionalDouble"),
OPTIONAL_GUAVA(
"Optional",
UnshadeGuava.typeString("base.Optional"));
UnshadeGuava.typeString("base.Optional")),
OPTION_FUGUE(
"Option",
"com.atlassian.fugue.Option",
"io.atlassian.fugue.Option"),
;

private final String[] rawTypes;
private final String rawSimpleName;
Expand Down Expand Up @@ -234,13 +239,18 @@ public boolean isOptionalGuava() {
return this == OPTIONAL_GUAVA;
}

public boolean isOptionFugue() {
return this == OPTION_FUGUE;
}

public boolean isOptionalKind() {
switch (this) {
case OPTIONAL_GUAVA:
case OPTIONAL_JDK:
case OPTIONAL_INT_JDK:
case OPTIONAL_LONG_JDK:
case OPTIONAL_DOUBLE_JDK:
case OPTION_FUGUE:
return true;
default:
return false;
Expand Down
Expand Up @@ -18,7 +18,6 @@
import com.google.common.base.MoreObjects;
import com.google.common.base.Optional;
import com.google.common.base.Splitter;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
Expand Down Expand Up @@ -248,7 +247,7 @@ private List<CharSequence> extractAnnotationsForElement(ElementType elementType,
Collections.singleton(JsonPropertyMirror.qualifiedName()),
false,
elementType).isEmpty();

if (dontHaveJsonPropetyAnnotationAlready) {
allAnnotations.add("@" + JsonPropertyMirror.qualifiedName());
}
Expand Down Expand Up @@ -366,6 +365,10 @@ public boolean isJdkOptional() {
return typeKind.isOptionalKind() && typeKind.isJdkOnlyContainerKind();
}

public boolean isFugueOptional() {
return typeKind.isOptionFugue();
}

public boolean isJdkSpecializedOptional() {
return typeKind.isOptionalSpecializedJdk();
}
Expand Down

0 comments on commit 81c1196

Please sign in to comment.