Skip to content

Commit

Permalink
refactor(role): CtCodeSnippet has CtRole.SNIPPET (#1623)
Browse files Browse the repository at this point in the history
  • Loading branch information
pvojtechovsky authored and monperrus committed Oct 19, 2017
1 parent 40e15b2 commit 6991e72
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 deletions.
6 changes: 3 additions & 3 deletions src/main/java/spoon/reflect/declaration/CtCodeSnippet.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import spoon.reflect.annotations.PropertyGetter;
import spoon.reflect.annotations.PropertySetter;

import static spoon.reflect.path.CtRole.EXPRESSION;
import static spoon.reflect.path.CtRole.SNIPPET;

/**
* This interface represents snippets of source code that can be used in the AST
Expand All @@ -36,13 +36,13 @@ public interface CtCodeSnippet {
/**
* Sets the textual value of the code.
*/
@PropertySetter(role = EXPRESSION)
@PropertySetter(role = SNIPPET)
<C extends CtCodeSnippet> C setValue(String value);

/**
* Gets the textual value of the code.
*/
@PropertyGetter(role = EXPRESSION)
@PropertyGetter(role = SNIPPET)
String getValue();

}
3 changes: 2 additions & 1 deletion src/main/java/spoon/reflect/path/CtRole.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ public enum CtRole {
COMMENT_TYPE,
DOCUMENTATION_TYPE,
JAVADOC_TAG_VALUE,
POSITION;
POSITION,
SNIPPET;

/**
* Get the {@link CtRole} associated to the field name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@
import spoon.reflect.code.CtCodeSnippetExpression;
import spoon.reflect.code.CtExpression;
import spoon.reflect.declaration.CtCodeSnippet;
import spoon.reflect.path.CtRole;
import spoon.reflect.visitor.CtVisitor;
import spoon.support.compiler.SnippetCompilationError;
import spoon.support.compiler.SnippetCompilationHelper;

import static spoon.reflect.path.CtRole.EXPRESSION;
import static spoon.reflect.path.CtRole.SNIPPET;

public class CtCodeSnippetExpressionImpl<T> extends CtExpressionImpl<T> implements CtCodeSnippetExpression<T> {

Expand All @@ -35,15 +34,17 @@ public void accept(CtVisitor visitor) {
visitor.visitCtCodeSnippetExpression(this);
}

@MetamodelPropertyField(role = CtRole.EXPRESSION)
@MetamodelPropertyField(role = SNIPPET)
String value;

@Override
public String getValue() {
return value;
}

@Override
public <C extends CtCodeSnippet> C setValue(String value) {
getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, EXPRESSION, value, this.value);
getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, SNIPPET, value, this.value);
this.value = value;
return (C) this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@
import spoon.reflect.code.CtCodeSnippetStatement;
import spoon.reflect.code.CtStatement;
import spoon.reflect.declaration.CtCodeSnippet;
import spoon.reflect.path.CtRole;
import spoon.reflect.visitor.CtVisitor;
import spoon.support.compiler.SnippetCompilationError;
import spoon.support.compiler.SnippetCompilationHelper;

import static spoon.reflect.path.CtRole.EXPRESSION;
import static spoon.reflect.path.CtRole.SNIPPET;

public class CtCodeSnippetStatementImpl extends CtStatementImpl implements CtCodeSnippetStatement {

Expand All @@ -35,15 +34,17 @@ public void accept(CtVisitor visitor) {
visitor.visitCtCodeSnippetStatement(this);
}

@MetamodelPropertyField(role = CtRole.EXPRESSION)
@MetamodelPropertyField(role = SNIPPET)
String value;

@Override
public String getValue() {
return value;
}

@Override
public <C extends CtCodeSnippet> C setValue(String value) {
getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, EXPRESSION, value, this.value);
getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, SNIPPET, value, this.value);
this.value = value;
return (C) this;
}
Expand Down

0 comments on commit 6991e72

Please sign in to comment.