Skip to content

Commit

Permalink
feat(model): annotes getter and setter with a CtRole
Browse files Browse the repository at this point in the history
  • Loading branch information
tdurieux committed Jun 8, 2017
1 parent bd67096 commit 37ffe1c
Show file tree
Hide file tree
Showing 79 changed files with 819 additions and 4 deletions.
15 changes: 13 additions & 2 deletions src/main/java/spoon/reflect/code/CtAbstractInvocation.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,15 @@
*/
package spoon.reflect.code;

import java.util.List;

import spoon.reflect.declaration.CtElement;
import spoon.reflect.reference.CtExecutableReference;
import spoon.support.PropertyGetter;
import spoon.support.PropertySetter;

import java.util.List;

import static spoon.reflect.path.CtRole.ARGUMENTS;
import static spoon.reflect.path.CtRole.EXECUTABLE;

/**
* This code element defines an abstract invocation on a
Expand All @@ -34,30 +39,36 @@ public interface CtAbstractInvocation<T> extends CtElement {
*
* @return the expressions that define the values of the arguments
*/
@PropertyGetter(role = ARGUMENTS)
List<CtExpression<?>> getArguments();

/**
* Adds an argument expression to the invocation.
*/
@PropertySetter(role = ARGUMENTS)
<C extends CtAbstractInvocation<T>> C addArgument(CtExpression<?> argument);

/**
* Removes an argument expression from the invocation.
*/
@PropertySetter(role = ARGUMENTS)
void removeArgument(CtExpression<?> argument);

/**
* Sets the invocation's arguments.
*/
@PropertySetter(role = ARGUMENTS)
<C extends CtAbstractInvocation<T>> C setArguments(List<CtExpression<?>> arguments);

/**
* Returns the invoked executable.
*/
@PropertyGetter(role = EXECUTABLE)
CtExecutableReference<T> getExecutable();

/**
* Sets the invoked executable.
*/
@PropertySetter(role = EXECUTABLE)
<C extends CtAbstractInvocation<T>> C setExecutable(CtExecutableReference<T> executable);
}
4 changes: 4 additions & 0 deletions src/main/java/spoon/reflect/code/CtAnnotationFieldAccess.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
package spoon.reflect.code;

import spoon.reflect.reference.CtFieldReference;
import spoon.support.PropertyGetter;

import static spoon.reflect.path.CtRole.VARIABLE;

/**
* This code element defines an access to a annotation parameter variable.
Expand All @@ -25,6 +28,7 @@
* Type of this field
*/
public interface CtAnnotationFieldAccess<T> extends CtVariableRead<T>, CtTargetedExpression<T, CtExpression<?>> {
@PropertyGetter(role = VARIABLE)
CtFieldReference<T> getVariable();

@Override
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/spoon/reflect/code/CtArrayAccess.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
*/
package spoon.reflect.code;

import spoon.support.PropertyGetter;
import spoon.support.PropertySetter;

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

/**
* This code element defines a one-dimensional array access. When
* multi-dimensional, array accesses are applied to other one-dimensional array
Expand All @@ -31,11 +36,13 @@ public interface CtArrayAccess<T, E extends CtExpression<?>> extends CtTargetedE
/**
* Sets the expression that defines the index.
*/
@PropertySetter(role = EXPRESSION)
<C extends CtArrayAccess<T, E>> C setIndexExpression(CtExpression<Integer> expression);

/**
* Returns the expression that defines the index.
*/
@PropertyGetter(role = EXPRESSION)
CtExpression<Integer> getIndexExpression();

@Override
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/spoon/reflect/code/CtAssert.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@
*/
package spoon.reflect.code;

import spoon.support.PropertyGetter;
import spoon.support.PropertySetter;

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


/**
* This code element defines an assert clause.
* Example: <pre>assert 1+1==2</pre>
Expand All @@ -24,21 +31,25 @@ public interface CtAssert<T> extends CtStatement {
/**
* Gets the assert expression.
*/
@PropertyGetter(role = CONDITION)
CtExpression<Boolean> getAssertExpression();

/**
* Sets the assert expression.
*/
@PropertySetter(role = CONDITION)
<A extends CtAssert<T>> A setAssertExpression(CtExpression<Boolean> asserted);

/**
* Gets the expression of the assertion if defined.
*/
@PropertyGetter(role = EXPRESSION)
CtExpression<T> getExpression();

/**
* Sets the expression of the assertion.
*/
@PropertySetter(role = EXPRESSION)
<A extends CtAssert<T>> A setExpression(CtExpression<T> expression);

@Override
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/spoon/reflect/code/CtAssignment.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
*/
package spoon.reflect.code;

import spoon.support.PropertyGetter;
import spoon.support.PropertySetter;

import static spoon.reflect.path.CtRole.ASSIGNED;


/**
* This code element defines an assignment.
*
Expand All @@ -34,11 +40,13 @@ public interface CtAssignment<T, A extends T> extends CtStatement, CtExpression<
* Returns the assigned expression on the left-hand side (where the value is stored,
* e.g. in a variable, in an array, in a field ...).
*/
@PropertyGetter(role = ASSIGNED)
CtExpression<T> getAssigned();

/**
* Sets the assigned expression (left hand side - LHS).
*/
@PropertySetter(role = ASSIGNED)
<C extends CtAssignment<T, A>> C setAssigned(CtExpression<T> assigned);

@Override
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/spoon/reflect/code/CtBinaryOperator.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@
*/
package spoon.reflect.code;

import spoon.support.PropertyGetter;
import spoon.support.PropertySetter;

import static spoon.reflect.path.CtRole.KIND;
import static spoon.reflect.path.CtRole.LEFT_OPERAND;
import static spoon.reflect.path.CtRole.RIGHT_OPERAND;

/**
* This interface defines a binary operator.
*
Expand All @@ -32,31 +39,37 @@ public interface CtBinaryOperator<T> extends CtExpression<T> {
/**
* Returns the left-hand operand.
*/
@PropertyGetter(role = LEFT_OPERAND)
CtExpression<?> getLeftHandOperand();

/**
* Returns the right-hand operand.
*/
@PropertyGetter(role = RIGHT_OPERAND)
CtExpression<?> getRightHandOperand();

/**
* Sets the left-hand operand.
*/
@PropertySetter(role = LEFT_OPERAND)
<C extends CtBinaryOperator<T>> C setLeftHandOperand(CtExpression<?> expression);

/**
* Sets the right-hand operand.
*/
@PropertySetter(role = RIGHT_OPERAND)
<C extends CtBinaryOperator<T>> C setRightHandOperand(CtExpression<?> expression);

/**
* Sets the kind of this binary operator.
*/
@PropertySetter(role = KIND)
<C extends CtBinaryOperator<T>> C setKind(BinaryOperatorKind kind);

/**
* Gets the kind of this binary operator.
*/
@PropertyGetter(role = KIND)
BinaryOperatorKind getKind();

@Override
Expand Down
1 change: 1 addition & 0 deletions src/main/java/spoon/reflect/code/CtBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public interface CtBlock<R> extends CtStatement, CtStatementList, TemplateParame
/**
* Gets the ith statement of this block.
*/
@DerivedProperty
<T extends CtStatement> T getStatement(int i);

/**
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/spoon/reflect/code/CtBodyHolder.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
package spoon.reflect.code;

import spoon.reflect.declaration.CtElement;
import spoon.support.PropertyGetter;
import spoon.support.PropertySetter;

import static spoon.reflect.path.CtRole.BODY;

/**
* This abstract code element defines an element, which contains a body
Expand All @@ -26,11 +30,13 @@ public interface CtBodyHolder extends CtElement {
/**
* Gets the body of this element
*/
@PropertyGetter(role = BODY)
CtStatement getBody();

/**
* Sets the body of this element.
* If body is not a block, it is wrapped in a CtBlock which is semantically equivalent and eases transformation afterwards if required.
*/
@PropertySetter(role = BODY)
<T extends CtBodyHolder> T setBody(CtStatement body);
}
8 changes: 8 additions & 0 deletions src/main/java/spoon/reflect/code/CtBreak.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
*/
package spoon.reflect.code;

import spoon.support.PropertyGetter;
import spoon.support.PropertySetter;

import static spoon.reflect.path.CtRole.TARGET_LABEL;


/**
* This code element defines a break statement.
* Example:
Expand All @@ -32,12 +38,14 @@ public interface CtBreak extends CtCFlowBreak {
* Gets the label from which the control flow breaks (null if no label
* defined).
*/
@PropertyGetter(role = TARGET_LABEL)
String getTargetLabel();

/**
* Sets the label from which the control flow breaks (null if no label
* defined).
*/
@PropertySetter(role = TARGET_LABEL)
<T extends CtBreak> T setTargetLabel(String targetLabel);

@Override
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/spoon/reflect/code/CtCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
*/
package spoon.reflect.code;

import spoon.support.PropertyGetter;
import spoon.support.PropertySetter;

import static spoon.reflect.path.CtRole.CASE;


/**
* This code element defines a case within a switch-case.
*
Expand All @@ -34,11 +40,13 @@ public interface CtCase<S> extends CtStatement, CtStatementList {
/**
* Gets the case expression.
*/
@PropertyGetter(role = CASE)
CtExpression<S> getCaseExpression();

/**
* Sets the case expression.
*/
@PropertySetter(role = CASE)
<T extends CtCase<S>> T setCaseExpression(CtExpression<S> caseExpression);

@Override
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/spoon/reflect/code/CtCatch.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@
*/
package spoon.reflect.code;

import spoon.support.PropertyGetter;
import spoon.support.PropertySetter;

import static spoon.reflect.path.CtRole.BODY;
import static spoon.reflect.path.CtRole.PARAMETER;


/**
* This code element defines a <code>catch</code> of a <code>try</code>.
*
Expand All @@ -26,17 +33,20 @@ public interface CtCatch extends CtCodeElement, CtBodyHolder {
/**
* Gets the catch's parameter (a throwable).
*/
@PropertyGetter(role = PARAMETER)
CtCatchVariable<? extends Throwable> getParameter();

/**
* Sets the catch's parameter (a throwable).
*/
@PropertySetter(role = PARAMETER)
<T extends CtCatch> T setParameter(CtCatchVariable<? extends Throwable> parameter);

/**
* Gets the catch's body.
*/
@Override
@PropertySetter(role = BODY)
CtBlock<?> getBody();

@Override
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/spoon/reflect/code/CtComment.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
*/
package spoon.reflect.code;

import spoon.support.PropertyGetter;
import spoon.support.PropertySetter;

import static spoon.reflect.path.CtRole.CONTENT;
import static spoon.reflect.path.CtRole.TYPE;

/**
* This code element defines a comment
*
Expand Down Expand Up @@ -49,16 +55,20 @@ enum CommentType {
* Get the content of the comment
* @return the content of the comment
*/
@PropertyGetter(role = CONTENT)
String getContent();

@PropertySetter(role = CONTENT)
<E extends CtComment> E setContent(String content);

/**
* Get the type of the comment
* @return the comment type
*/
@PropertyGetter(role = TYPE)
CommentType getCommentType();

@PropertySetter(role = TYPE)
<E extends CtComment> E setCommentType(CommentType commentType);

@Override
Expand Down
Loading

0 comments on commit 37ffe1c

Please sign in to comment.