Skip to content

Commit

Permalink
Add support to comment out CtStatement
Browse files Browse the repository at this point in the history
  • Loading branch information
LakshyAAAgrawal committed Jul 13, 2020
1 parent d62c3eb commit fbeaa96
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/main/java/spoon/reflect/code/CtStatement.java
Expand Up @@ -56,6 +56,11 @@ public interface CtStatement extends CtCodeElement {
@PropertySetter(role = LABEL)
<T extends CtStatement> T setLabel(String label);

/**
* Replace the statement with a CtComment having the statement as text
*/
void comment();

@Override
CtStatement clone();
}
11 changes: 11 additions & 0 deletions src/main/java/spoon/support/reflect/code/CtStatementImpl.java
Expand Up @@ -25,6 +25,7 @@
import spoon.reflect.visitor.CtInheritanceScanner;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import static spoon.reflect.path.CtRole.LABEL;
Expand Down Expand Up @@ -282,6 +283,16 @@ public <T extends CtStatement> T setLabel(String label) {
this.label = label;
return (T) this;
}

@Override
public void comment() {
if (!isParentInitialized()) {
// already not in a tree, commenting wouldn't make a difference
return;
}
// comment is implemented as replace by a comment
replace(getFactory().Code().createInlineComment(toString()));
}

@Override
public CtStatement clone() {
Expand Down

0 comments on commit fbeaa96

Please sign in to comment.