Skip to content

Commit

Permalink
feat(model): annotes getter and setter with a CtRole (#1377)
Browse files Browse the repository at this point in the history
* feat(model): annotes getter and setter with a CtRole

* add failing test

* update roles

* remove failing test

* add missing getter

* remove Type role on accessed type

* wip

* test without properties in references

* remove reference only role

* up

* moves PropertyGetter/Setter to reflect (will move DerivedProperty and UnsettableProperty after)
  • Loading branch information
tdurieux authored and surli committed Jun 9, 2017
1 parent 40326ca commit 841edfc
Show file tree
Hide file tree
Showing 78 changed files with 758 additions and 49 deletions.
34 changes: 34 additions & 0 deletions src/main/java/spoon/reflect/annotations/PropertyGetter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* Copyright (C) 2006-2017 INRIA and contributors
* Spoon - http://spoon.gforge.inria.fr/
*
* This software is governed by the CeCILL-C License under French law and
* abiding by the rules of distribution of free software. You can use, modify
* and/or redistribute the software under the terms of the CeCILL-C license as
* circulated by CEA, CNRS and INRIA at http://www.cecill.info.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the CeCILL-C License for more details.
*
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL-C license and that you accept its terms.
*/
package spoon.reflect.annotations;

import spoon.reflect.path.CtRole;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* Specifies that a method is an official metamodel getter in the Spoon metamodel.
* @see PropertySetter
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.METHOD })
public @interface PropertyGetter {
CtRole role();
}
34 changes: 34 additions & 0 deletions src/main/java/spoon/reflect/annotations/PropertySetter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* Copyright (C) 2006-2017 INRIA and contributors
* Spoon - http://spoon.gforge.inria.fr/
*
* This software is governed by the CeCILL-C License under French law and
* abiding by the rules of distribution of free software. You can use, modify
* and/or redistribute the software under the terms of the CeCILL-C license as
* circulated by CEA, CNRS and INRIA at http://www.cecill.info.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the CeCILL-C License for more details.
*
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL-C license and that you accept its terms.
*/
package spoon.reflect.annotations;

import spoon.reflect.path.CtRole;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* Specifies that a method is an official metamodel setter in the Spoon metamodel.
* @see PropertyGetter
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.METHOD })
public @interface PropertySetter {
CtRole role();
}
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.reflect.annotations.PropertyGetter;
import spoon.reflect.annotations.PropertySetter;

import java.util.List;

import static spoon.reflect.path.CtRole.ARGUMENT;
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 = ARGUMENT)
List<CtExpression<?>> getArguments();

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

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

/**
* Sets the invocation's arguments.
*/
@PropertySetter(role = ARGUMENT)
<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.reflect.annotations.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.reflect.annotations.PropertyGetter;
import spoon.reflect.annotations.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.reflect.annotations.PropertyGetter;
import spoon.reflect.annotations.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.reflect.annotations.PropertyGetter;
import spoon.reflect.annotations.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.reflect.annotations.PropertyGetter;
import spoon.reflect.annotations.PropertySetter;

import static spoon.reflect.path.CtRole.OPERATOR_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 = OPERATOR_KIND)
<C extends CtBinaryOperator<T>> C setKind(BinaryOperatorKind kind);

/**
* Gets the kind of this binary operator.
*/
@PropertyGetter(role = OPERATOR_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.reflect.annotations.PropertyGetter;
import spoon.reflect.annotations.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.reflect.annotations.PropertyGetter;
import spoon.reflect.annotations.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.reflect.annotations.PropertyGetter;
import spoon.reflect.annotations.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
Loading

0 comments on commit 841edfc

Please sign in to comment.