Skip to content

Commit

Permalink
limiting retention of expensive objects #105
Browse files Browse the repository at this point in the history
+ fighting maven 3.3.1 which exposes both relocated and non-relocated
classes during reactor compilation. Had to change bunch of internal
dependency references for annotation + processor instead of value.
the problem is that there's no module to test fully shaded jar ((
  • Loading branch information
elucash committed Apr 19, 2015
1 parent 8a8da55 commit 978ab75
Show file tree
Hide file tree
Showing 16 changed files with 440 additions and 69 deletions.
14 changes: 12 additions & 2 deletions builder/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>
<artifactId>immutables</artifactId> <artifactId>immutables</artifactId>
Expand All @@ -22,11 +23,20 @@
<version>${project.version}</version> <version>${project.version}</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<!-- it's better have just 'value' dep, but due to some maven 3.3.1 bug,
it exposes both relocated and not relocated classess, having processor to run twice -->
<dependency> <dependency>
<groupId>org.immutables</groupId> <groupId>org.immutables</groupId>
<artifactId>value</artifactId> <artifactId>value-annotations</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
<scope>provided</scope>
<optional>true</optional> <optional>true</optional>
</dependency> </dependency>
<dependency>
<groupId>org.immutables</groupId>
<artifactId>value-processor</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
</dependencies> </dependencies>
</project> </project>
16 changes: 10 additions & 6 deletions generator/src/org/immutables/generator/Output.java
Expand Up @@ -297,12 +297,12 @@ void complete() {
writer.append(sourceCode); writer.append(sourceCode);
} }
} catch (FilerException ex) { } catch (FilerException ex) {
if (!identicalFileIsAlreadyGenerated(sourceCode)) { if (identicalFileIsAlreadyGenerated(sourceCode)) {
getMessager().printMessage(Kind.ERROR, getMessager().printMessage(Kind.MANDATORY_WARNING, "Regenerated file with the same content: " + key);
"Generated source file name collission. Attempt to overwrite already generated file: " + key);
} else { } else {
getMessager().printMessage(Kind.MANDATORY_WARNING, getMessager().printMessage(Kind.ERROR, String.format(
"Regenerated file with the same content: " + key); "Generated source file name collission. Attempt to overwrite already generated file: %s, %s",
key, ex));
} }
} catch (IOException ex) { } catch (IOException ex) {
throw Throwables.propagate(ex); throw Throwables.propagate(ex);
Expand All @@ -312,10 +312,14 @@ void complete() {
private boolean identicalFileIsAlreadyGenerated(CharSequence sourceCode) { private boolean identicalFileIsAlreadyGenerated(CharSequence sourceCode) {
try { try {
String existingContent = new CharSource() { String existingContent = new CharSource() {
final String packagePath = !key.packageName.isEmpty() ? (key.packageName.replace('.', '/') + '/') : "";
final String filename = key.relativeName + ".java";

@Override @Override
public Reader openStream() throws IOException { public Reader openStream() throws IOException {
return getFiler() return getFiler()
.getResource(StandardLocation.SOURCE_OUTPUT, key.packageName, key.relativeName) .getResource(StandardLocation.SOURCE_OUTPUT,
"", packagePath + filename)
.openReader(true); .openReader(true);
} }
}.read(); }.read();
Expand Down
14 changes: 12 additions & 2 deletions gson/pom.xml
Expand Up @@ -57,14 +57,24 @@
<version>2.0</version> <version>2.0</version>
<optional>true</optional> <optional>true</optional>
</dependency> </dependency>

<!-- it's better have just 'value' dep, but due to some maven 3.3.1 bug,
it exposes both relocated and not relocated classess, having processor to run twice -->
<dependency>
<groupId>org.immutables</groupId>
<artifactId>value-annotations</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
<optional>true</optional>
</dependency>
<dependency> <dependency>
<!-- Compile only immutablesp processor -->
<groupId>org.immutables</groupId> <groupId>org.immutables</groupId>
<artifactId>value</artifactId> <artifactId>value-processor</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
<scope>provided</scope> <scope>provided</scope>
<optional>true</optional> <optional>true</optional>
</dependency> </dependency>

<dependency> <dependency>
<!-- Test only utilities --> <!-- Test only utilities -->
<groupId>org.immutables</groupId> <groupId>org.immutables</groupId>
Expand Down
11 changes: 9 additions & 2 deletions mongo/pom.xml
Expand Up @@ -29,14 +29,21 @@
<type>pom</type> <type>pom</type>
</dependency> </dependency>


<!-- it's better have just 'value' dep, but due to some maven 3.3.1 bug,
it exposes both relocated and not relocated classess, having processor to run twice -->
<dependency> <dependency>
<!-- Compile only processor -->
<groupId>org.immutables</groupId> <groupId>org.immutables</groupId>
<artifactId>value</artifactId> <artifactId>value-annotations</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
<scope>test</scope> <scope>test</scope>
<optional>true</optional> <optional>true</optional>
</dependency> </dependency>
<dependency>
<groupId>org.immutables</groupId>
<artifactId>value-processor</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>


<dependency> <dependency>
<!-- compile only meta-inf/services generator --> <!-- compile only meta-inf/services generator -->
Expand Down
7 changes: 2 additions & 5 deletions mongo/test/org/immutables/mongo/fixture/sub/Item2.java
Expand Up @@ -16,13 +16,10 @@
package org.immutables.mongo.fixture.sub; package org.immutables.mongo.fixture.sub;


import java.util.List; import java.util.List;
import java.util.Set; import org.immutables.gson.Gson;
import org.immutables.mongo.Mongo; import org.immutables.mongo.Mongo;
import org.immutables.mongo.types.Binary;
import org.immutables.mongo.types.Id;
import org.immutables.value.Value;
import org.immutables.mongo.fixture.*; import org.immutables.mongo.fixture.*;
import org.immutables.gson.Gson; import org.immutables.value.Value;


@Mongo.Repository @Mongo.Repository
@Value.Immutable @Value.Immutable
Expand Down
13 changes: 11 additions & 2 deletions ordinal/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>
<artifactId>immutables</artifactId> <artifactId>immutables</artifactId>
Expand Down Expand Up @@ -28,9 +29,17 @@
<version>${project.version}</version> <version>${project.version}</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<!-- it's better have just 'value' dep, but due to some maven 3.3.1 bug,
it exposes both relocated and not relocated classess, having processor to run twice -->
<dependency> <dependency>
<groupId>org.immutables</groupId> <groupId>org.immutables</groupId>
<artifactId>value</artifactId> <artifactId>value-annotations</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.immutables</groupId>
<artifactId>value-processor</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
Expand Down
3 changes: 2 additions & 1 deletion pom.xml
Expand Up @@ -106,11 +106,12 @@
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version> <version>3.3</version>
<configuration> <configuration>
<compilerVersion>1.7</compilerVersion> <compilerVersion>1.7</compilerVersion>
<source>1.7</source> <source>1.7</source>
<target>1.7</target> <target>1.7</target>
<useIncrementalCompilation>false</useIncrementalCompilation>
<compilerArgs> <compilerArgs>
<!-- <arg>-Xlint:deprecation</arg> --> <!-- <arg>-Xlint:deprecation</arg> -->
<arg>-Xlint:unchecked</arg> <arg>-Xlint:unchecked</arg>
Expand Down
12 changes: 11 additions & 1 deletion value-fixture/pom.xml
Expand Up @@ -15,11 +15,21 @@
</description> </description>


<dependencies> <dependencies>
<!-- it's better have just 'value' dep, but due to some maven 3.3.1 bug,
it exposes both relocated and not relocated classess, having processor to run twice -->
<dependency> <dependency>
<groupId>org.immutables</groupId> <groupId>org.immutables</groupId>
<artifactId>value</artifactId> <artifactId>value-annotations</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
<optional>true</optional>
</dependency> </dependency>
<dependency>
<groupId>org.immutables</groupId>
<artifactId>value-processor</artifactId>
<version>${project.version}</version>
<optional>true</optional>
</dependency>

<dependency> <dependency>
<groupId>org.immutables</groupId> <groupId>org.immutables</groupId>
<artifactId>gson</artifactId> <artifactId>gson</artifactId>
Expand Down
Expand Up @@ -148,7 +148,7 @@ public NameForms typeAbstract() {
.build(); .build();
} }


public StyleMirror style() { public StyleInfo style() {
return protoclass().styles().style(); return protoclass().styles().style();
} }


Expand Down
84 changes: 64 additions & 20 deletions value-processor/src/org/immutables/value/processor/meta/Proto.java
Expand Up @@ -54,8 +54,8 @@ public static abstract class MetaAnnotated {


@Value.Derived @Value.Derived
@Value.Auxiliary @Value.Auxiliary
public Optional<StyleMirror> style() { public Optional<StyleInfo> style() {
return StyleMirror.find(element()); return StyleMirror.find(element()).transform(ToStyleInfo.FUNCTION);
} }


public static MetaAnnotated from(AnnotationMirror mirror) { public static MetaAnnotated from(AnnotationMirror mirror) {
Expand Down Expand Up @@ -99,12 +99,12 @@ abstract static class Environment {
abstract Round round(); abstract Round round();


@Value.Derived @Value.Derived
StyleMirror defaultStyles() { StyleInfo defaultStyles() {
TypeElement typeElement = processing() TypeElement typeElement = processing()
.getElementUtils() .getElementUtils()
.getTypeElement(StyleMirror.qualifiedName()); .getTypeElement(StyleMirror.qualifiedName());


return StyleMirror.from(typeElement); return ToStyleInfo.FUNCTION.apply(StyleMirror.from(typeElement));
} }


/** /**
Expand Down Expand Up @@ -185,16 +185,16 @@ public List<TypeElement> includedTypes() {
} }


@Value.Lazy @Value.Lazy
public Optional<StyleMirror> style() { public Optional<StyleInfo> style() {
Optional<StyleMirror> style = StyleMirror.find(element()); Optional<StyleInfo> style = StyleMirror.find(element()).transform(ToStyleInfo.FUNCTION);


if (style.isPresent()) { if (style.isPresent()) {
return style; return style;
} }


for (AnnotationMirror mirror : element().getAnnotationMirrors()) { for (AnnotationMirror mirror : element().getAnnotationMirrors()) {
MetaAnnotated metaAnnotated = MetaAnnotated.from(mirror); MetaAnnotated metaAnnotated = MetaAnnotated.from(mirror);
Optional<StyleMirror> metaStyle = metaAnnotated.style(); Optional<StyleInfo> metaStyle = metaAnnotated.style();
if (metaStyle.isPresent()) { if (metaStyle.isPresent()) {
return metaStyle; return metaStyle;
} }
Expand Down Expand Up @@ -285,8 +285,8 @@ Optional<DeclaringPackage> namedParentPackage() {


@Override @Override
@Value.Lazy @Value.Lazy
public Optional<StyleMirror> style() { public Optional<StyleInfo> style() {
Optional<StyleMirror> style = super.style(); Optional<StyleInfo> style = super.style();
if (style.isPresent()) { if (style.isPresent()) {
return style; return style;
} }
Expand Down Expand Up @@ -365,15 +365,15 @@ public DeclaringPackage packageOf() {
} }


@Value.Lazy @Value.Lazy
public Optional<ImmutableMirror> features() { public Optional<ValueImmutableInfo> features() {
return ImmutableMirror.find(element()); return ImmutableMirror.find(element()).transform(ToImmutableInfo.FUNCTION);
} }


@Value.Lazy @Value.Lazy
public boolean useImmutableDefaults() { public boolean useImmutableDefaults() {
Optional<ImmutableMirror> immutables = features(); Optional<ValueImmutableInfo> immutables = features();
if (immutables.isPresent()) { if (immutables.isPresent()) {
return immutables.get().getAnnotationMirror().getElementValues().isEmpty(); return immutables.get().isDefault();
} }
return true; return true;
} }
Expand Down Expand Up @@ -580,10 +580,10 @@ public Element element() {
} }


@Value.Lazy @Value.Lazy
public ImmutableMirror features() { public ValueImmutableInfo features() {
if (declaringType().isPresent() if (declaringType().isPresent()
&& !declaringType().get().useImmutableDefaults()) { && !declaringType().get().useImmutableDefaults()) {
Optional<ImmutableMirror> features = declaringType().get().features(); Optional<ValueImmutableInfo> features = declaringType().get().features();
if (features.isPresent()) { if (features.isPresent()) {
return features.get(); return features.get();
} }
Expand All @@ -593,27 +593,27 @@ public ImmutableMirror features() {


@Value.Lazy @Value.Lazy
public Styles styles() { public Styles styles() {
return Styles.using(determineStyle().or(environment().defaultStyles())); return determineStyle().or(environment().defaultStyles()).getStyles();
} }


private Optional<StyleMirror> determineStyle() { private Optional<StyleInfo> determineStyle() {
if (declaringType().isPresent()) { if (declaringType().isPresent()) {
DeclaringType type = declaringType().get(); DeclaringType type = declaringType().get();


Optional<DeclaringType> enclosing = type.enclosingOf(); Optional<DeclaringType> enclosing = type.enclosingOf();
if (enclosing.isPresent()) { if (enclosing.isPresent()) {
if (enclosing.get() != type) { if (enclosing.get() != type) {
Optional<StyleMirror> style = type.style(); Optional<StyleInfo> style = type.style();
if (style.isPresent()) { if (style.isPresent()) {
warnAboutIncompatibleStyles(); warnAboutIncompatibleStyles();
} }
} }
Optional<StyleMirror> enclosingStyle = enclosing.get().style(); Optional<StyleInfo> enclosingStyle = enclosing.get().style();
if (enclosingStyle.isPresent()) { if (enclosingStyle.isPresent()) {
return enclosingStyle; return enclosingStyle;
} }
} else { } else {
Optional<StyleMirror> style = type.style(); Optional<StyleInfo> style = type.style();
if (style.isPresent()) { if (style.isPresent()) {
return style; return style;
} }
Expand Down Expand Up @@ -767,4 +767,48 @@ public boolean apply(Element input) {
return input.getModifiers().contains(Modifier.PUBLIC); return input.getModifiers().contains(Modifier.PUBLIC);
} }
} }

enum ToImmutableInfo implements Function<ImmutableMirror, ValueImmutableInfo> {
FUNCTION;
@Override
public ValueImmutableInfo apply(ImmutableMirror input) {
return ImmutableValueImmutableInfo.theOf(
input.builder(),
input.copy(),
input.intern(),
input.prehash(),
input.singleton())
.withIsDefault(input.getAnnotationMirror().getElementValues().isEmpty());
}
}

enum ToStyleInfo implements Function<StyleMirror, StyleInfo> {
FUNCTION;
@Override
public StyleInfo apply(StyleMirror input) {
return ImmutableStyleInfo.of(input.get(),
input.init(),
input.with(),
input.add(),
input.addAll(),
input.put(),
input.putAll(),
input.copyOf(),
input.of(),
input.instance(),
input.builder(),
input.newBuilder(),
input.from(),
input.build(),
input.typeBuilder(),
input.typeAbstract(),
input.typeImmutable(),
input.typeImmutableEnclosing(),
input.typeImmutableNested(),
ToImmutableInfo.FUNCTION.apply(input.defaults()),
input.strictBuilder(),
input.visibility(),
input.jdkOnly());
}
}
} }

0 comments on commit 978ab75

Please sign in to comment.