Skip to content

Commit

Permalink
Value.* annotations got small changes incompatible and deleted
Browse files Browse the repository at this point in the history
deprecated stuff
Switched value-processor to use special generated annotation mirrors
(only for Value.*)
Annotations for other integrations moved into value.ext.* in processor
Implemented new damn simple Jackson integration, tests passed
Jdk collections got fixes for EnumMap and Map (fixed uncheked)
A lot of small refinement and fixes
  • Loading branch information
elucash committed Jan 30, 2015
1 parent 51ac8ff commit 4bb0bee
Show file tree
Hide file tree
Showing 72 changed files with 1,030 additions and 579 deletions.
Expand Up @@ -41,7 +41,6 @@
/** /**
* JSON marshaling JAX-RS provider for immutable classes with generated marshaler. * JSON marshaling JAX-RS provider for immutable classes with generated marshaler.
* @see org.immutables.value.Value.Immutable * @see org.immutables.value.Value.Immutable
* @see org.immutables.value.Json.Marshaled
*/ */
@Metainf.Service @Metainf.Service
@Provider @Provider
Expand Down
2 changes: 1 addition & 1 deletion common/src/org/immutables/common/marshal/Marshaling.java
Expand Up @@ -26,7 +26,7 @@


/** /**
* Contains convenient methods for marshaling and unmarshaling documents annotated with * Contains convenient methods for marshaling and unmarshaling documents annotated with
* {@link org.immutables.value.Json.Marshaled} to and from standard textual JSON. * {@link org.immutables.value.ext.Json.Marshaled} to and from standard textual JSON.
* <p> * <p>
* You can avoid using this class in favor of using Marshalers directly. But It's not always * You can avoid using this class in favor of using Marshalers directly. But It's not always
* possible if dynamic lookup is needed. * possible if dynamic lookup is needed.
Expand Down
6 changes: 3 additions & 3 deletions dependency/technology/pom.xml
Expand Up @@ -31,17 +31,17 @@
<dependency> <dependency>
<groupId>com.fasterxml.jackson.core</groupId> <groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId> <artifactId>jackson-core</artifactId>
<version>2.4.4</version> <version>2.5.0</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.fasterxml.jackson.core</groupId> <groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId> <artifactId>jackson-databind</artifactId>
<version>2.4.4</version> <version>2.5.0</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.fasterxml.jackson.core</groupId> <groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId> <artifactId>jackson-annotations</artifactId>
<version>2.4.4</version> <version>2.5.0</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.mongodb</groupId> <groupId>org.mongodb</groupId>
Expand Down
23 changes: 18 additions & 5 deletions mirror/src/org/immutables/mirror/processor/Mirrors.generator
Expand Up @@ -28,6 +28,10 @@ import [guava].collect.ImmutableList;
public class [m.name]Mirror implements [m.element.qualifiedName] { public class [m.name]Mirror implements [m.element.qualifiedName] {
public static final String ANNOTATION_NAME = "[m.annotationTypeCommas]".replace(',', '.'); public static final String ANNOTATION_NAME = "[m.annotationTypeCommas]".replace(',', '.');


public static String simpleName() {
return "[m.simpleName]";
}

public static boolean isPresent(Element annotatedElement) { public static boolean isPresent(Element annotatedElement) {
for (AnnotationMirror mirror : annotatedElement.getAnnotationMirrors()) { for (AnnotationMirror mirror : annotatedElement.getAnnotationMirrors()) {
TypeElement element = (TypeElement) mirror.getAnnotationType().asElement(); TypeElement element = (TypeElement) mirror.getAnnotationType().asElement();
Expand Down Expand Up @@ -78,6 +82,15 @@ public class [m.name]Mirror implements [m.element.qualifiedName] {
return builder.build(); return builder.build();
} }


/**
* Creates mirror with default values using annotation element (i.e. declaration, not usage).
* @param element annotation type element
* @return {@code [m.name]Mirror}
*/
public static [m.name]Mirror from(TypeElement element) {
return new [m.name]Mirror(element);
}

/** /**
* Tries to convert annotation mirror to this annotation type. * Tries to convert annotation mirror to this annotation type.
* @param mirror annotation mirror * @param mirror annotation mirror
Expand Down Expand Up @@ -122,7 +135,7 @@ public class [m.name]Mirror implements [m.element.qualifiedName] {
[/for] [/for]


for (ExecutableElement attributeElement for (ExecutableElement attributeElement
: ElementFilter.methodsIn(annotationMirror.getAnnotationType().asElement().getEnclosedElements())) { : ElementFilter.methodsIn(defaultAnnotationElement.getEnclosedElements())) {
String name = attributeElement.getSimpleName().toString(); String name = attributeElement.getSimpleName().toString();
[for a in m.attributes] [for a in m.attributes]
if ("[a.name]".equals(name)) { if ("[a.name]".equals(name)) {
Expand Down Expand Up @@ -441,22 +454,22 @@ private static class [toUpper a.name]Extractor extends SimpleAnnotationValueVisi
array.get(0).accept(this, null); array.get(0).accept(this, null);
return null; return null;
} }

[targetType] get() {
return value;
}
[if a.kind.type] [if a.kind.type]


public String name() { public String name() {
return value.toString(); return value.toString();
} }
[/if] [/if]
[if a.mirrorModel] [if a.mirrorModel]
[let mirrorType][a.mirrorModel.package].[a.mirrorModel.name]Mirror[/let]


public [mirrorType a] mirror() { public [mirrorType a] mirror() {
return [mirrorType a].from(value).get(); return [mirrorType a].from(value).get();
} }
[/if] [/if]
[targetType] get() {
return value;
}
[/if] [/if]


@Override @Override
Expand Down
21 changes: 12 additions & 9 deletions mirror/src/org/immutables/mirror/processor/Mirrors.java
@@ -1,22 +1,20 @@
package org.immutables.mirror.processor; package org.immutables.mirror.processor;


import com.google.common.base.Splitter;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
import org.immutables.generator.AbstractTemplate;
import org.immutables.generator.Generator;
import org.immutables.mirror.Mirror;

import javax.annotation.Nullable; import javax.annotation.Nullable;
import javax.lang.model.element.Element; import javax.lang.model.element.*;
import javax.lang.model.element.ElementKind;
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.Modifier;
import javax.lang.model.element.PackageElement;
import javax.lang.model.element.TypeElement;
import javax.lang.model.type.ArrayType; import javax.lang.model.type.ArrayType;
import javax.lang.model.type.DeclaredType; import javax.lang.model.type.DeclaredType;
import javax.lang.model.type.TypeKind; import javax.lang.model.type.TypeKind;
import javax.lang.model.type.TypeMirror; import javax.lang.model.type.TypeMirror;
import javax.lang.model.util.ElementFilter; import javax.lang.model.util.ElementFilter;
import javax.tools.Diagnostic; import javax.tools.Diagnostic;
import org.immutables.generator.AbstractTemplate;
import org.immutables.generator.Generator;
import org.immutables.mirror.Mirror;


@Generator.Template @Generator.Template
@Generator.Import({Mirrors.MirrorModel.class, Mirrors.MirrorModel.AttributeModel.class}) @Generator.Import({Mirrors.MirrorModel.class, Mirrors.MirrorModel.AttributeModel.class})
Expand Down Expand Up @@ -67,6 +65,11 @@ String annotationTypeCommas() {
return element.getAnnotation(Mirror.Annotation.class).value().replace('.', ','); return element.getAnnotation(Mirror.Annotation.class).value().replace('.', ',');
} }


String simpleName() {
return Iterables.getLast(
Splitter.on('.').splitToList(element.getAnnotation(Mirror.Annotation.class).value()));
}

class AttributeModel { class AttributeModel {
final ExecutableElement element; final ExecutableElement element;
final String name; final String name;
Expand Down
8 changes: 5 additions & 3 deletions pom.xml
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>


<parent> <parent>
Expand Down Expand Up @@ -27,14 +28,15 @@
<module>generator</module> <module>generator</module>
<module>generator-processor</module> <module>generator-processor</module>
<module>generator-fixture</module> <module>generator-fixture</module>
<module>metainf</module>
<module>mirror</module>
<module>value</module> <module>value</module>
<module>value-processor</module> <module>value-processor</module>
<module>value-fixture</module>
<module>value-standalone</module> <module>value-standalone</module>
<module>value-fixture</module>
<module>quickstart</module> <module>quickstart</module>
<module>json-runtime</module> <module>json-runtime</module>
<module>gson</module> <module>gson</module>
<module>metainf</module>
</modules> </modules>


<organization> <organization>
Expand Down
14 changes: 13 additions & 1 deletion value-fixture/pom.xml
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>


<parent> <parent>
Expand Down Expand Up @@ -52,6 +53,17 @@
<artifactId>gson</artifactId> <artifactId>gson</artifactId>
<version>2.3.1</version> <version>2.3.1</version>
</dependency> </dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-guava</artifactId>
<version>2.5.0</version>
<exclusions>
<exclusion>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies> </dependencies>


<build> <build>
Expand Down
2 changes: 0 additions & 2 deletions value-fixture/src/org/immutables/fixture/GetterEncloser.java
Expand Up @@ -25,12 +25,10 @@


@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@Value.Immutable @Value.Immutable
@Value.Getters
public interface GetterEncloser { public interface GetterEncloser {
Optional<Integer> optional(); Optional<Integer> optional();


@Value.Immutable @Value.Immutable
@Value.Getters
public interface Getters { public interface Getters {
int ab(); int ab();


Expand Down
2 changes: 1 addition & 1 deletion value-fixture/src/org/immutables/fixture/HasNullable.java
Expand Up @@ -15,7 +15,7 @@
*/ */
package org.immutables.fixture; package org.immutables.fixture;


import org.immutables.value.Json; import org.immutables.value.ext.Json;
import org.immutables.value.Value; import org.immutables.value.Value;
import javax.annotation.Nullable; import javax.annotation.Nullable;


Expand Down
Expand Up @@ -19,7 +19,7 @@
import java.lang.annotation.Target; import java.lang.annotation.Target;
import java.util.Map; import java.util.Map;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import org.immutables.value.Json; import org.immutables.value.ext.Json;
import org.immutables.value.Value; import org.immutables.value.Value;


@Target(ElementType.TYPE_USE) @Target(ElementType.TYPE_USE)
Expand Down
2 changes: 1 addition & 1 deletion value-fixture/src/org/immutables/fixture/JsonIgnore.java
Expand Up @@ -17,7 +17,7 @@


import java.util.List; import java.util.List;
import org.immutables.value.Value; import org.immutables.value.Value;
import org.immutables.value.Json; import org.immutables.value.ext.Json;


@Value.Immutable @Value.Immutable
@Json.Marshaled @Json.Marshaled
Expand Down
Expand Up @@ -15,10 +15,11 @@
*/ */
package org.immutables.fixture; package org.immutables.fixture;


import org.immutables.value.Value.Immutable.ImplementationVisibility; import org.immutables.value.Value.Style.ImplementationVisibility;
import org.immutables.value.Value; import org.immutables.value.Value;


@Value.Immutable(visibility = ImplementationVisibility.PACKAGE) @Value.Immutable
@Value.Style(visibility = ImplementationVisibility.PACKAGE)
public abstract class PrimitiveDefault { public abstract class PrimitiveDefault {
@Value.Default @Value.Default
public boolean def() { public boolean def() {
Expand Down
Expand Up @@ -15,7 +15,7 @@
*/ */
package org.immutables.fixture; package org.immutables.fixture;


import org.immutables.value.Json; import org.immutables.value.ext.Json;


@Json.Subclasses({ @Json.Subclasses({
SillySub1.class, SillySub1.class,
Expand Down
2 changes: 1 addition & 1 deletion value-fixture/src/org/immutables/fixture/SillyDumb.java
Expand Up @@ -17,7 +17,7 @@


import com.google.common.base.Optional; import com.google.common.base.Optional;
import java.util.List; import java.util.List;
import org.immutables.value.Json; import org.immutables.value.ext.Json;
import org.immutables.value.Value; import org.immutables.value.Value;


@Value.Immutable @Value.Immutable
Expand Down
4 changes: 2 additions & 2 deletions value-fixture/src/org/immutables/fixture/SillyEntity.java
Expand Up @@ -22,8 +22,8 @@
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import org.immutables.value.Json; import org.immutables.value.ext.Json;
import org.immutables.value.Mongo; import org.immutables.value.ext.Mongo;
import org.immutables.value.Value; import org.immutables.value.Value;


@Value.Immutable @Value.Immutable
Expand Down
Expand Up @@ -15,9 +15,9 @@
*/ */
package org.immutables.fixture; package org.immutables.fixture;


import org.immutables.value.Mongo; import org.immutables.value.ext.Mongo;
import org.immutables.common.repository.Id; import org.immutables.common.repository.Id;
import org.immutables.value.Json; import org.immutables.value.ext.Json;
import org.immutables.value.Value; import org.immutables.value.Value;


@Value.Immutable @Value.Immutable
Expand Down
2 changes: 1 addition & 1 deletion value-fixture/src/org/immutables/fixture/SillyIntWrap.java
Expand Up @@ -15,7 +15,7 @@
*/ */
package org.immutables.fixture; package org.immutables.fixture;


import org.immutables.value.Json; import org.immutables.value.ext.Json;
import org.immutables.value.Value; import org.immutables.value.Value;


@Value.Immutable(builder = false) @Value.Immutable(builder = false)
Expand Down
Expand Up @@ -18,7 +18,7 @@
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import org.immutables.value.Json; import org.immutables.value.ext.Json;
import org.immutables.value.Value; import org.immutables.value.Value;


@Value.Immutable @Value.Immutable
Expand Down
2 changes: 1 addition & 1 deletion value-fixture/src/org/immutables/fixture/SillyMapTup.java
Expand Up @@ -17,7 +17,7 @@


import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
import java.util.Map; import java.util.Map;
import org.immutables.value.Json; import org.immutables.value.ext.Json;
import org.immutables.value.Value; import org.immutables.value.Value;


@Value.Immutable(builder = false) @Value.Immutable(builder = false)
Expand Down
Expand Up @@ -16,7 +16,7 @@
package org.immutables.fixture; package org.immutables.fixture;


import java.util.List; import java.util.List;
import org.immutables.value.Json; import org.immutables.value.ext.Json;
import org.immutables.value.Value; import org.immutables.value.Value;


@Value.Immutable @Value.Immutable
Expand Down
Expand Up @@ -16,7 +16,7 @@
package org.immutables.fixture; package org.immutables.fixture;


import com.google.common.base.Optional; import com.google.common.base.Optional;
import org.immutables.value.Json; import org.immutables.value.ext.Json;
import org.immutables.value.Value; import org.immutables.value.Value;


@Value.Immutable @Value.Immutable
Expand Down
Expand Up @@ -17,7 +17,7 @@


import com.google.common.base.Optional; import com.google.common.base.Optional;
import java.util.List; import java.util.List;
import org.immutables.value.Json; import org.immutables.value.ext.Json;
import org.immutables.value.Value; import org.immutables.value.Value;


@Value.Immutable @Value.Immutable
Expand Down
Expand Up @@ -15,10 +15,10 @@
*/ */
package org.immutables.fixture; package org.immutables.fixture;


import org.immutables.value.Mongo; import org.immutables.value.ext.Mongo;
import com.google.common.base.Optional; import com.google.common.base.Optional;
import java.util.List; import java.util.List;
import org.immutables.value.Json; import org.immutables.value.ext.Json;
import org.immutables.value.Value; import org.immutables.value.Value;


@Value.Immutable @Value.Immutable
Expand Down
2 changes: 1 addition & 1 deletion value-fixture/src/org/immutables/fixture/SillySub1.java
Expand Up @@ -15,7 +15,7 @@
*/ */
package org.immutables.fixture; package org.immutables.fixture;


import org.immutables.value.Json; import org.immutables.value.ext.Json;
import org.immutables.value.Value; import org.immutables.value.Value;


@Value.Immutable @Value.Immutable
Expand Down
2 changes: 1 addition & 1 deletion value-fixture/src/org/immutables/fixture/SillySub2.java
Expand Up @@ -15,7 +15,7 @@
*/ */
package org.immutables.fixture; package org.immutables.fixture;


import org.immutables.value.Json; import org.immutables.value.ext.Json;
import org.immutables.value.Value; import org.immutables.value.Value;


@Value.Immutable @Value.Immutable
Expand Down
2 changes: 1 addition & 1 deletion value-fixture/src/org/immutables/fixture/SillySub3.java
Expand Up @@ -16,7 +16,7 @@
package org.immutables.fixture; package org.immutables.fixture;


import java.util.List; import java.util.List;
import org.immutables.value.Json; import org.immutables.value.ext.Json;
import org.immutables.value.Value; import org.immutables.value.Value;


@Value.Immutable @Value.Immutable
Expand Down
Expand Up @@ -15,12 +15,12 @@
*/ */
package org.immutables.fixture; package org.immutables.fixture;


import org.immutables.value.Mongo; import org.immutables.value.ext.Mongo;
import java.lang.annotation.ElementType; import java.lang.annotation.ElementType;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import org.immutables.value.Json; import org.immutables.value.ext.Json;
import org.immutables.value.Value; import org.immutables.value.Value;


@Value.Immutable @Value.Immutable
Expand Down

0 comments on commit 4bb0bee

Please sign in to comment.