Skip to content

Commit

Permalink
#476 class comments replication when implementation is primary
Browse files Browse the repository at this point in the history
  • Loading branch information
elucash committed Oct 26, 2016
1 parent f35a686 commit 882790e
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 17 deletions.
Expand Up @@ -116,20 +116,26 @@ import static [routine].immutableCopyOf;

[for setters = type.settableAttributes]
/**
[if type.docComment]
[for d in type.docComment]
*[d][-- no space before doc line!]
[/for]
[else]
* Immutable implementation of {@link [type.typeAbstract.relativeRaw]}.
* <p>
[if type.useBuilder]
[if type.useBuilder]
* Use the builder to create immutable instances:
* {@code [type.factoryBuilder.relative]()}.
[/if]
[if type.useConstructor]
[/if]
[if type.useConstructor]
* Use the static factory method to create immutable instances:
* {@code [type.factoryOf.relative]()}.
[/if]
[if type.useSingleton]
[/if]
[if type.useSingleton]
* Use the static factory method to get the default singleton instance:
* {@code [type.factoryInstance.relative]()}.
[/if]
[/if]
[/if]
*/
[annotationsWhenTopLevel type topLevel]
[if classpath.available 'javax.annotation.concurrent.Immutable']
Expand Down
Expand Up @@ -65,7 +65,6 @@ public final class ValueAttribute extends TypeIntrospectionBase {
private static final String GUAVA_IMMUTABLE_PREFIX = UnshadeGuava.typeString("collect.Immutable");
private static final String VALUE_ATTRIBUTE_NAME = "value";
private static final String ID_ATTRIBUTE_NAME = "_id";
private static final Splitter DOC_COMMENT_LINE_SPLITTER = Splitter.on('\n').omitEmptyStrings();
private static final String[] EMPTY_SERIALIZED_NAMES = {};

public AttributeNames names;
Expand Down Expand Up @@ -1287,18 +1286,11 @@ public boolean isDeferCollectionAllocation() {
}

private void initMiscellaneous() {
Elements elements = protoclass()
this.deprecated = protoclass()
.processing()
.getElementUtils();
.getElementUtils().isDeprecated(element);

this.deprecated = elements.isDeprecated(element);

if (containingType.constitution.implementationVisibility().isPublic()) {
@Nullable String docComment = elements.getDocComment(element);
if (docComment != null) {
this.docComment = ImmutableList.copyOf(DOC_COMMENT_LINE_SPLITTER.split(docComment));
}
}
this.docComment = containingType.extractDocComment(element);
}

private void initBuilderParamsIfApplicable() {
Expand Down
Expand Up @@ -15,6 +15,7 @@
*/
package org.immutables.value.processor.meta;

import com.google.common.base.Splitter;
import com.google.common.base.CaseFormat;
import com.google.common.base.Function;
import com.google.common.base.Optional;
Expand Down Expand Up @@ -1269,6 +1270,33 @@ public boolean isUseCompactBuilder() {
&& getThrowForInvalidImmutableState().equals(IllegalStateException.class.getName());
}

public ImmutableList<String> extractDocComment(Element element) {
// Only extract for generated type which is public
if (constitution.implementationVisibility().isPublic()) {
@Nullable String docComment = constitution
.protoclass()
.processing()
.getElementUtils()
.getDocComment(CachingElements.getDelegate(element));

if (docComment != null) {
return ImmutableList.copyOf(DOC_COMMENT_LINE_SPLITTER.split(docComment));
}
}
return ImmutableList.of();
}

private ImmutableList<String> docComment;

public ImmutableList<String> getDocComment() {
if (docComment == null) {
this.docComment = constitution.isImplementationPrimary()
? extractDocComment(element)
: ImmutableList.<String>of();
}
return docComment;
}

DeclaringType inferDeclaringType(Element element) {
return constitution.protoclass().environment().round().inferDeclaringTypeFor(element);
}
Expand Down Expand Up @@ -1476,4 +1504,6 @@ public int hashCode() {
public String toString() {
return "Type[" + name() + "]";
}

private static final Splitter DOC_COMMENT_LINE_SPLITTER = Splitter.on('\n').omitEmptyStrings();
}

0 comments on commit 882790e

Please sign in to comment.