Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(clone): clone preserves comments and implicitness #1028

Merged
merged 1 commit into from
Dec 7, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/java/spoon/generating/CloneVisitorGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ private CtInvocation<Object> createFactoryInvocation(CtVariableAccess<CtElement>
"spoon.support.reflect.declaration.CtCodeSnippetImpl", "spoon.support.reflect.declaration.CtFormalTypeDeclarerImpl", //
"spoon.support.reflect.declaration.CtGenericElementImpl", "spoon.support.reflect.reference.CtGenericElementReferenceImpl", //
"spoon.support.reflect.declaration.CtModifiableImpl", "spoon.support.reflect.declaration.CtMultiTypedElementImpl", //
"spoon.support.reflect.declaration.CtTypeMemberImpl", "spoon.support.reflect.declaration.CtElementImpl");
"spoon.support.reflect.declaration.CtTypeMemberImpl");
private final List<String> excludesFields = Arrays.asList("factory", "elementValues", "target", "metadata");
private final CtTypeReference<List> LIST_REFERENCE = factory.Type().createReference(List.class);
private final CtTypeReference<Collection> COLLECTION_REFERENCE = factory.Type().createReference(Collection.class);
Expand Down
42 changes: 26 additions & 16 deletions src/main/java/spoon/support/visitor/clone/CloneBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,22 @@
* This class is generated automatically by the processor {@link spoon.generating.CloneVisitorGenerator}.
*/
public class CloneBuilder extends spoon.reflect.visitor.CtInheritanceScanner {
public static <T extends spoon.reflect.declaration.CtElement> T build(spoon.reflect.declaration.CtElement element, spoon.reflect.declaration.CtElement other) {
return spoon.support.visitor.clone.CloneBuilder.build(new spoon.support.visitor.clone.CloneBuilder(), element, other);
}

public static <T extends spoon.reflect.declaration.CtElement> T build(spoon.support.visitor.clone.CloneBuilder builder, spoon.reflect.declaration.CtElement element, spoon.reflect.declaration.CtElement other) {
builder.setOther(other);
builder.scan(element);
return ((T) (builder.other));
}

private spoon.reflect.declaration.CtElement other;

public void setOther(spoon.reflect.declaration.CtElement other) {
spoon.support.visitor.clone.CloneBuilder.this.other = other;
}

// auto-generated, see spoon.generating.CloneVisitorGenerator
public <T> void visitCtCodeSnippetExpression(spoon.reflect.code.CtCodeSnippetExpression<T> e) {
((spoon.reflect.code.CtCodeSnippetExpression<T>) (other)).setValue(e.getValue());
Expand All @@ -37,6 +53,16 @@ public void visitCtCodeSnippetStatement(spoon.reflect.code.CtCodeSnippetStatemen
super.visitCtCodeSnippetStatement(e);
}

/**
* Scans an abstract element.
*/
// auto-generated, see spoon.generating.CloneVisitorGenerator
public void scanCtElement(spoon.reflect.declaration.CtElement e) {
((spoon.reflect.declaration.CtElement) (other)).setPosition(e.getPosition());
((spoon.reflect.declaration.CtElement) (other)).setImplicit(e.isImplicit());
super.scanCtElement(e);
}

/**
* Scans an abstract named element.
*/
Expand Down Expand Up @@ -231,21 +257,5 @@ public void visitCtComment(spoon.reflect.code.CtComment e) {
((spoon.reflect.code.CtComment) (other)).setCommentType(e.getCommentType());
super.visitCtComment(e);
}

public static <T extends spoon.reflect.declaration.CtElement> T build(spoon.reflect.declaration.CtElement element, spoon.reflect.declaration.CtElement other) {
return spoon.support.visitor.clone.CloneBuilder.build(new spoon.support.visitor.clone.CloneBuilder(), element, other);
}

public static <T extends spoon.reflect.declaration.CtElement> T build(spoon.support.visitor.clone.CloneBuilder builder, spoon.reflect.declaration.CtElement element, spoon.reflect.declaration.CtElement other) {
builder.setOther(other);
builder.scan(element);
return ((T) (builder.other));
}

private spoon.reflect.declaration.CtElement other;

public void setOther(spoon.reflect.declaration.CtElement other) {
spoon.support.visitor.clone.CloneBuilder.this.other = other;
}
}

Loading