diff --git a/src/main/java/spoon/reflect/annotations/PropertyGetter.java b/src/main/java/spoon/reflect/annotations/PropertyGetter.java new file mode 100644 index 00000000000..7785b6f4384 --- /dev/null +++ b/src/main/java/spoon/reflect/annotations/PropertyGetter.java @@ -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(); +} diff --git a/src/main/java/spoon/reflect/annotations/PropertySetter.java b/src/main/java/spoon/reflect/annotations/PropertySetter.java new file mode 100644 index 00000000000..f293ef71862 --- /dev/null +++ b/src/main/java/spoon/reflect/annotations/PropertySetter.java @@ -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(); +} diff --git a/src/main/java/spoon/reflect/code/CtAbstractInvocation.java b/src/main/java/spoon/reflect/code/CtAbstractInvocation.java index b98ba429b1d..d2b24fc45b6 100644 --- a/src/main/java/spoon/reflect/code/CtAbstractInvocation.java +++ b/src/main/java/spoon/reflect/code/CtAbstractInvocation.java @@ -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 @@ -34,30 +39,36 @@ public interface CtAbstractInvocation extends CtElement { * * @return the expressions that define the values of the arguments */ + @PropertyGetter(role = ARGUMENT) List> getArguments(); /** * Adds an argument expression to the invocation. */ + @PropertySetter(role = ARGUMENT) > 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 setArguments(List> arguments); /** * Returns the invoked executable. */ + @PropertyGetter(role = EXECUTABLE) CtExecutableReference getExecutable(); /** * Sets the invoked executable. */ + @PropertySetter(role = EXECUTABLE) > C setExecutable(CtExecutableReference executable); } diff --git a/src/main/java/spoon/reflect/code/CtAnnotationFieldAccess.java b/src/main/java/spoon/reflect/code/CtAnnotationFieldAccess.java index adbc8e55912..d35045ef262 100644 --- a/src/main/java/spoon/reflect/code/CtAnnotationFieldAccess.java +++ b/src/main/java/spoon/reflect/code/CtAnnotationFieldAccess.java @@ -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. @@ -25,6 +28,7 @@ * Type of this field */ public interface CtAnnotationFieldAccess extends CtVariableRead, CtTargetedExpression> { + @PropertyGetter(role = VARIABLE) CtFieldReference getVariable(); @Override diff --git a/src/main/java/spoon/reflect/code/CtArrayAccess.java b/src/main/java/spoon/reflect/code/CtArrayAccess.java index 192ac5bfc1e..5782d389f21 100644 --- a/src/main/java/spoon/reflect/code/CtArrayAccess.java +++ b/src/main/java/spoon/reflect/code/CtArrayAccess.java @@ -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 @@ -31,11 +36,13 @@ public interface CtArrayAccess> extends CtTargetedE /** * Sets the expression that defines the index. */ + @PropertySetter(role = EXPRESSION) > C setIndexExpression(CtExpression expression); /** * Returns the expression that defines the index. */ + @PropertyGetter(role = EXPRESSION) CtExpression getIndexExpression(); @Override diff --git a/src/main/java/spoon/reflect/code/CtAssert.java b/src/main/java/spoon/reflect/code/CtAssert.java index 1820ae1014f..928d1d09d97 100644 --- a/src/main/java/spoon/reflect/code/CtAssert.java +++ b/src/main/java/spoon/reflect/code/CtAssert.java @@ -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:
assert 1+1==2
@@ -24,21 +31,25 @@ public interface CtAssert extends CtStatement { /** * Gets the assert expression. */ + @PropertyGetter(role = CONDITION) CtExpression getAssertExpression(); /** * Sets the assert expression. */ + @PropertySetter(role = CONDITION) > A setAssertExpression(CtExpression asserted); /** * Gets the expression of the assertion if defined. */ + @PropertyGetter(role = EXPRESSION) CtExpression getExpression(); /** * Sets the expression of the assertion. */ + @PropertySetter(role = EXPRESSION) > A setExpression(CtExpression expression); @Override diff --git a/src/main/java/spoon/reflect/code/CtAssignment.java b/src/main/java/spoon/reflect/code/CtAssignment.java index 9ca15794701..7f923570efa 100644 --- a/src/main/java/spoon/reflect/code/CtAssignment.java +++ b/src/main/java/spoon/reflect/code/CtAssignment.java @@ -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. * @@ -34,11 +40,13 @@ public interface CtAssignment 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 getAssigned(); /** * Sets the assigned expression (left hand side - LHS). */ + @PropertySetter(role = ASSIGNED) > C setAssigned(CtExpression assigned); @Override diff --git a/src/main/java/spoon/reflect/code/CtBinaryOperator.java b/src/main/java/spoon/reflect/code/CtBinaryOperator.java index c5eaead8c27..247b7bd255b 100644 --- a/src/main/java/spoon/reflect/code/CtBinaryOperator.java +++ b/src/main/java/spoon/reflect/code/CtBinaryOperator.java @@ -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. * @@ -32,31 +39,37 @@ public interface CtBinaryOperator extends CtExpression { /** * 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 setLeftHandOperand(CtExpression expression); /** * Sets the right-hand operand. */ + @PropertySetter(role = RIGHT_OPERAND) > C setRightHandOperand(CtExpression expression); /** * Sets the kind of this binary operator. */ + @PropertySetter(role = OPERATOR_KIND) > C setKind(BinaryOperatorKind kind); /** * Gets the kind of this binary operator. */ + @PropertyGetter(role = OPERATOR_KIND) BinaryOperatorKind getKind(); @Override diff --git a/src/main/java/spoon/reflect/code/CtBlock.java b/src/main/java/spoon/reflect/code/CtBlock.java index 492dec17eac..b2b92082a47 100644 --- a/src/main/java/spoon/reflect/code/CtBlock.java +++ b/src/main/java/spoon/reflect/code/CtBlock.java @@ -83,6 +83,7 @@ public interface CtBlock extends CtStatement, CtStatementList, TemplateParame /** * Gets the ith statement of this block. */ + @DerivedProperty T getStatement(int i); /** diff --git a/src/main/java/spoon/reflect/code/CtBodyHolder.java b/src/main/java/spoon/reflect/code/CtBodyHolder.java index 72f6a63aa05..a15e7c3a673 100644 --- a/src/main/java/spoon/reflect/code/CtBodyHolder.java +++ b/src/main/java/spoon/reflect/code/CtBodyHolder.java @@ -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 @@ -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 setBody(CtStatement body); } diff --git a/src/main/java/spoon/reflect/code/CtBreak.java b/src/main/java/spoon/reflect/code/CtBreak.java index 1941ab6c058..66e8d4698b2 100644 --- a/src/main/java/spoon/reflect/code/CtBreak.java +++ b/src/main/java/spoon/reflect/code/CtBreak.java @@ -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: @@ -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 setTargetLabel(String targetLabel); @Override diff --git a/src/main/java/spoon/reflect/code/CtCase.java b/src/main/java/spoon/reflect/code/CtCase.java index 6bf886bd1df..5a92571cf11 100644 --- a/src/main/java/spoon/reflect/code/CtCase.java +++ b/src/main/java/spoon/reflect/code/CtCase.java @@ -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. * @@ -34,11 +40,13 @@ public interface CtCase extends CtStatement, CtStatementList { /** * Gets the case expression. */ + @PropertyGetter(role = CASE) CtExpression getCaseExpression(); /** * Sets the case expression. */ + @PropertySetter(role = CASE) > T setCaseExpression(CtExpression caseExpression); @Override diff --git a/src/main/java/spoon/reflect/code/CtCatch.java b/src/main/java/spoon/reflect/code/CtCatch.java index 7508388727d..c7dd808be1c 100644 --- a/src/main/java/spoon/reflect/code/CtCatch.java +++ b/src/main/java/spoon/reflect/code/CtCatch.java @@ -16,6 +16,13 @@ */ package spoon.reflect.code; +import spoon.reflect.annotations.PropertyGetter; +import spoon.reflect.annotations.PropertySetter; + +import static spoon.reflect.path.CtRole.BODY; +import static spoon.reflect.path.CtRole.PARAMETER; + + /** * This code element defines a catch of a try. * @@ -26,17 +33,20 @@ public interface CtCatch extends CtCodeElement, CtBodyHolder { /** * Gets the catch's parameter (a throwable). */ + @PropertyGetter(role = PARAMETER) CtCatchVariable getParameter(); /** * Sets the catch's parameter (a throwable). */ + @PropertySetter(role = PARAMETER) T setParameter(CtCatchVariable parameter); /** * Gets the catch's body. */ @Override + @PropertySetter(role = BODY) CtBlock getBody(); @Override diff --git a/src/main/java/spoon/reflect/code/CtComment.java b/src/main/java/spoon/reflect/code/CtComment.java index 4659e228a12..7bf0ac7a816 100644 --- a/src/main/java/spoon/reflect/code/CtComment.java +++ b/src/main/java/spoon/reflect/code/CtComment.java @@ -16,6 +16,12 @@ */ package spoon.reflect.code; +import spoon.reflect.annotations.PropertyGetter; +import spoon.reflect.annotations.PropertySetter; + +import static spoon.reflect.path.CtRole.COMMENT_TYPE; +import static spoon.reflect.path.CtRole.COMMENT_CONTENT; + /** * This code element defines a comment * @@ -49,16 +55,20 @@ enum CommentType { * Get the content of the comment * @return the content of the comment */ + @PropertyGetter(role = COMMENT_CONTENT) String getContent(); + @PropertySetter(role = COMMENT_CONTENT) E setContent(String content); /** * Get the type of the comment * @return the comment type */ + @PropertyGetter(role = COMMENT_TYPE) CommentType getCommentType(); + @PropertySetter(role = COMMENT_TYPE) E setCommentType(CommentType commentType); @Override diff --git a/src/main/java/spoon/reflect/code/CtConditional.java b/src/main/java/spoon/reflect/code/CtConditional.java index 713d099f6bc..62978ce307f 100644 --- a/src/main/java/spoon/reflect/code/CtConditional.java +++ b/src/main/java/spoon/reflect/code/CtConditional.java @@ -16,6 +16,14 @@ */ 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.ELSE; +import static spoon.reflect.path.CtRole.THEN; + + /** * This code element defines conditional expressions using the ? (ternary expressions). * @@ -31,31 +39,37 @@ public interface CtConditional extends CtExpression { /** * Gets the "false" expression. */ + @PropertyGetter(role = ELSE) CtExpression getElseExpression(); /** * Gets the "true" expression. */ + @PropertyGetter(role = THEN) CtExpression getThenExpression(); /** * Gets the condition expression. */ + @PropertyGetter(role = CONDITION) CtExpression getCondition(); /** * Sets the "false" expression. */ + @PropertySetter(role = ELSE) > C setElseExpression(CtExpression elseExpression); /** * Sets the "true" expression. */ + @PropertySetter(role = THEN) > C setThenExpression(CtExpression thenExpression); /** * Sets the condition expression. */ + @PropertySetter(role = CONDITION) > C setCondition(CtExpression condition); @Override diff --git a/src/main/java/spoon/reflect/code/CtConstructorCall.java b/src/main/java/spoon/reflect/code/CtConstructorCall.java index 0c097f7b342..4771ef3d86c 100644 --- a/src/main/java/spoon/reflect/code/CtConstructorCall.java +++ b/src/main/java/spoon/reflect/code/CtConstructorCall.java @@ -21,9 +21,14 @@ import spoon.reflect.reference.CtTypeReference; import spoon.support.DefaultCoreFactory; import spoon.support.DerivedProperty; +import spoon.reflect.annotations.PropertyGetter; +import spoon.reflect.annotations.PropertySetter; import java.util.List; +import static spoon.reflect.path.CtRole.TYPE; +import static spoon.reflect.path.CtRole.TYPE_PARAMETER; + /** * This code element represents a constructor call. * @@ -44,6 +49,7 @@ public interface CtConstructorCall extends CtTargetedExpression> getActualTypeArguments(); /** @@ -52,6 +58,7 @@ public interface CtConstructorCall extends CtTargetedExpression T setActualTypeArguments(List> actualTypeArguments); /** @@ -60,6 +67,7 @@ public interface CtConstructorCall extends CtTargetedExpression T addActualTypeArgument(CtTypeReference actualTypeArgument); @Override @@ -67,5 +75,6 @@ public interface CtConstructorCall extends CtTargetedExpression getType(); } diff --git a/src/main/java/spoon/reflect/code/CtContinue.java b/src/main/java/spoon/reflect/code/CtContinue.java index 5c0d8e41263..c2b4c95f787 100644 --- a/src/main/java/spoon/reflect/code/CtContinue.java +++ b/src/main/java/spoon/reflect/code/CtContinue.java @@ -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 the continue statement. * Example: @@ -44,12 +50,14 @@ public interface CtContinue 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 setTargetLabel(String targetLabel); @Override diff --git a/src/main/java/spoon/reflect/code/CtDo.java b/src/main/java/spoon/reflect/code/CtDo.java index 3c1e03dfc84..6c503dee027 100644 --- a/src/main/java/spoon/reflect/code/CtDo.java +++ b/src/main/java/spoon/reflect/code/CtDo.java @@ -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 do loop. * @@ -32,11 +37,13 @@ public interface CtDo extends CtLoop { /** * Returns the looping test as a boolean expression. */ + @PropertyGetter(role = EXPRESSION) CtExpression getLoopingExpression(); /** * Sets the looping test as a boolean expression. */ + @PropertySetter(role = EXPRESSION) T setLoopingExpression(CtExpression expression); @Override diff --git a/src/main/java/spoon/reflect/code/CtExecutableReferenceExpression.java b/src/main/java/spoon/reflect/code/CtExecutableReferenceExpression.java index cab7454ffd3..a290e02cff7 100644 --- a/src/main/java/spoon/reflect/code/CtExecutableReferenceExpression.java +++ b/src/main/java/spoon/reflect/code/CtExecutableReferenceExpression.java @@ -17,6 +17,10 @@ package spoon.reflect.code; import spoon.reflect.reference.CtExecutableReference; +import spoon.reflect.annotations.PropertyGetter; +import spoon.reflect.annotations.PropertySetter; + +import static spoon.reflect.path.CtRole.EXECUTABLE; /** * This abstract code element defines an expression which represents an executable reference. @@ -37,11 +41,13 @@ public interface CtExecutableReferenceExpression> e /** * Gets the executable referenced by the expression. */ + @PropertyGetter(role = EXECUTABLE) CtExecutableReference getExecutable(); /** * Sets the executable will be referenced by the expression. */ + @PropertySetter(role = EXECUTABLE) > C setExecutable(CtExecutableReference executable); @Override diff --git a/src/main/java/spoon/reflect/code/CtExpression.java b/src/main/java/spoon/reflect/code/CtExpression.java index 19414f09723..d2ce9631542 100644 --- a/src/main/java/spoon/reflect/code/CtExpression.java +++ b/src/main/java/spoon/reflect/code/CtExpression.java @@ -18,10 +18,14 @@ import spoon.reflect.declaration.CtTypedElement; import spoon.reflect.reference.CtTypeReference; +import spoon.reflect.annotations.PropertyGetter; +import spoon.reflect.annotations.PropertySetter; import spoon.template.TemplateParameter; import java.util.List; +import static spoon.reflect.path.CtRole.CAST; + /** * This abstract code element defines a typed expression. * @@ -33,16 +37,19 @@ public interface CtExpression extends CtCodeElement, CtTypedElement, Templ /** * Returns the type casts if any. */ + @PropertyGetter(role = CAST) List> getTypeCasts(); /** * Sets the type casts. */ + @PropertySetter(role = CAST) > C setTypeCasts(List> types); /** * Adds a type cast. */ + @PropertySetter(role = CAST) > C addTypeCast(CtTypeReference type); /** diff --git a/src/main/java/spoon/reflect/code/CtFieldAccess.java b/src/main/java/spoon/reflect/code/CtFieldAccess.java index f0f4e54a4b4..c990fde14f3 100644 --- a/src/main/java/spoon/reflect/code/CtFieldAccess.java +++ b/src/main/java/spoon/reflect/code/CtFieldAccess.java @@ -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 field variable (read and write) @@ -25,6 +28,7 @@ * Type of this field */ public interface CtFieldAccess extends CtVariableAccess, CtTargetedExpression> { + @PropertyGetter(role = VARIABLE) CtFieldReference getVariable(); @Override diff --git a/src/main/java/spoon/reflect/code/CtFor.java b/src/main/java/spoon/reflect/code/CtFor.java index 3bf0e47c0fb..6c9ff1a2c90 100644 --- a/src/main/java/spoon/reflect/code/CtFor.java +++ b/src/main/java/spoon/reflect/code/CtFor.java @@ -16,8 +16,15 @@ */ package spoon.reflect.code; +import spoon.reflect.annotations.PropertyGetter; +import spoon.reflect.annotations.PropertySetter; + import java.util.List; +import static spoon.reflect.path.CtRole.EXPRESSION; +import static spoon.reflect.path.CtRole.FOR_INIT; +import static spoon.reflect.path.CtRole.FOR_UPDATE; + /** * This code element defines a for loop. * Example: @@ -33,51 +40,61 @@ public interface CtFor extends CtLoop { /** * Gets the end-loop test expression. */ + @PropertyGetter(role = EXPRESSION) CtExpression getExpression(); /** * Sets the end-loop test expression. */ + @PropertySetter(role = EXPRESSION) T setExpression(CtExpression expression); /** * Gets the init statements. */ + @PropertyGetter(role = FOR_INIT) List getForInit(); /** * Adds an init statement. */ + @PropertySetter(role = FOR_INIT) T addForInit(CtStatement statement); /** * Sets the init statements. */ + @PropertySetter(role = FOR_INIT) T setForInit(List forInit); /** * Removes an init statement. */ + @PropertySetter(role = FOR_INIT) boolean removeForInit(CtStatement statement); /** * Gets the update statements. */ + @PropertyGetter(role = FOR_UPDATE) List getForUpdate(); /** * Adds an update statement. */ + @PropertySetter(role = FOR_UPDATE) T addForUpdate(CtStatement statement); /** * Sets the update statements. */ + @PropertySetter(role = FOR_UPDATE) T setForUpdate(List forUpdate); /** * Removes an update statement. */ + @PropertySetter(role = FOR_UPDATE) boolean removeForUpdate(CtStatement statement); @Override diff --git a/src/main/java/spoon/reflect/code/CtForEach.java b/src/main/java/spoon/reflect/code/CtForEach.java index 3fad102e0d9..5ac5626c957 100644 --- a/src/main/java/spoon/reflect/code/CtForEach.java +++ b/src/main/java/spoon/reflect/code/CtForEach.java @@ -16,6 +16,13 @@ */ package spoon.reflect.code; +import spoon.reflect.annotations.PropertyGetter; +import spoon.reflect.annotations.PropertySetter; + +import static spoon.reflect.path.CtRole.EXPRESSION; +import static spoon.reflect.path.CtRole.VARIABLE; + + /** * This code element defines a foreach statement. * Example: @@ -30,21 +37,25 @@ public interface CtForEach extends CtLoop { /** * Gets the iterated expression (an iterable of an array). */ + @PropertyGetter(role = EXPRESSION) CtExpression getExpression(); /** * Gets the variable that references the currently iterated element. */ + @PropertyGetter(role = VARIABLE) CtLocalVariable getVariable(); /** * Sets the iterated expression (an iterable of an array). */ + @PropertySetter(role = EXPRESSION) T setExpression(CtExpression expression); /** * Sets the variable that references the currently iterated element. */ + @PropertySetter(role = VARIABLE) T setVariable(CtLocalVariable variable); @Override diff --git a/src/main/java/spoon/reflect/code/CtIf.java b/src/main/java/spoon/reflect/code/CtIf.java index ffbe9618347..5f5bd9ead50 100644 --- a/src/main/java/spoon/reflect/code/CtIf.java +++ b/src/main/java/spoon/reflect/code/CtIf.java @@ -16,8 +16,14 @@ */ package spoon.reflect.code; +import spoon.reflect.annotations.PropertyGetter; +import spoon.reflect.annotations.PropertySetter; import spoon.template.TemplateParameter; +import static spoon.reflect.path.CtRole.CONDITION; +import static spoon.reflect.path.CtRole.ELSE; +import static spoon.reflect.path.CtRole.THEN; + /** * This code element represents an if statement. * Example: @@ -35,32 +41,38 @@ public interface CtIf extends CtStatement, TemplateParameter { * Gets the boolean expression that represents the if's * condition. */ + @PropertyGetter(role = CONDITION) CtExpression getCondition(); /** * Gets the statement executed when the condition is false. */ + @PropertyGetter(role = ELSE) S getElseStatement(); /** * Gets the statement executed when the condition is true. */ + @PropertyGetter(role = THEN) S getThenStatement(); /** * Sets the boolean expression that represents the if's * condition. */ + @PropertySetter(role = CONDITION) T setCondition(CtExpression expression); /** * Sets the statement executed when the condition is false. */ + @PropertySetter(role = ELSE) T setElseStatement(CtStatement elseStatement); /** * Sets the statement executed when the condition is true. */ + @PropertySetter(role = THEN) T setThenStatement(CtStatement thenStatement); @Override diff --git a/src/main/java/spoon/reflect/code/CtInvocation.java b/src/main/java/spoon/reflect/code/CtInvocation.java index 195c7048839..9d43d1e8a3d 100644 --- a/src/main/java/spoon/reflect/code/CtInvocation.java +++ b/src/main/java/spoon/reflect/code/CtInvocation.java @@ -20,9 +20,14 @@ import spoon.reflect.reference.CtExecutableReference; import spoon.reflect.reference.CtTypeReference; import spoon.support.DerivedProperty; +import spoon.reflect.annotations.PropertyGetter; +import spoon.reflect.annotations.PropertySetter; import java.util.List; +import static spoon.reflect.path.CtRole.TYPE; +import static spoon.reflect.path.CtRole.TYPE_PARAMETER; + /** * This code element defines a concrete invocation. * @@ -44,6 +49,7 @@ public interface CtInvocation extends CtAbstractInvocation, CtStatement, C */ @Override @DerivedProperty + @PropertyGetter(role = TYPE_PARAMETER) List> getActualTypeArguments(); /** @@ -52,6 +58,7 @@ public interface CtInvocation extends CtAbstractInvocation, CtStatement, C * @see CtExecutableReference#getActualTypeArguments() */ @Override + @PropertySetter(role = TYPE_PARAMETER) T setActualTypeArguments(List> actualTypeArguments); /** @@ -60,6 +67,7 @@ public interface CtInvocation extends CtAbstractInvocation, CtStatement, C * @see CtExecutableReference#getActualTypeArguments() */ @Override + @PropertySetter(role = TYPE_PARAMETER) T addActualTypeArgument(CtTypeReference actualTypeArgument); /** @@ -69,6 +77,7 @@ public interface CtInvocation extends CtAbstractInvocation, CtStatement, C */ @Override @DerivedProperty + @PropertyGetter(role = TYPE) CtTypeReference getType(); @Override diff --git a/src/main/java/spoon/reflect/code/CtJavaDoc.java b/src/main/java/spoon/reflect/code/CtJavaDoc.java index de64cd4caa0..c1a04d51a6e 100644 --- a/src/main/java/spoon/reflect/code/CtJavaDoc.java +++ b/src/main/java/spoon/reflect/code/CtJavaDoc.java @@ -16,8 +16,14 @@ */ package spoon.reflect.code; +import spoon.support.DerivedProperty; +import spoon.reflect.annotations.PropertyGetter; +import spoon.reflect.annotations.PropertySetter; + import java.util.List; +import static spoon.reflect.path.CtRole.COMMENT_TAG; + /** * This code element defines a javadoc comment * @@ -34,18 +40,21 @@ public interface CtJavaDoc extends CtComment { * Get all the tag of the javadoc * @return the tag list */ + @PropertyGetter(role = COMMENT_TAG) List getTags(); /** * Define the list of tags * @param tags the new list of tags */ + @PropertySetter(role = COMMENT_TAG) E setTags(List tags); /** * Add a new tag at the end of the list * @param tag the new tag */ + @PropertySetter(role = COMMENT_TAG) E addTag(CtJavaDocTag tag); /** @@ -53,30 +62,35 @@ public interface CtJavaDoc extends CtComment { * @param index the index of the new tag * @param tag the new tag */ + @PropertySetter(role = COMMENT_TAG) E addTag(int index, CtJavaDocTag tag); /** * Remove a tag from the index * @param index the position of the tag to remove */ + @PropertySetter(role = COMMENT_TAG) E removeTag(int index); /** * Remove a specific tag * @param tag the tag to remove */ + @PropertySetter(role = COMMENT_TAG) E removeTag(CtJavaDocTag tag); /** * Get the short summary of the javadoc (first sentence of the javadoc) * @return the summary of the javadoc */ + @DerivedProperty String getShortDescription(); /** * Get the long description of the javadoc * @return the long description of the javadoc */ + @DerivedProperty String getLongDescription(); @Override diff --git a/src/main/java/spoon/reflect/code/CtJavaDocTag.java b/src/main/java/spoon/reflect/code/CtJavaDocTag.java index 832955e6b16..6d579708891 100644 --- a/src/main/java/spoon/reflect/code/CtJavaDocTag.java +++ b/src/main/java/spoon/reflect/code/CtJavaDocTag.java @@ -17,6 +17,12 @@ 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.COMMENT_CONTENT; +import static spoon.reflect.path.CtRole.PARAMETER; +import static spoon.reflect.path.CtRole.TYPE; /** * This code element defines a javadoc tag @@ -83,42 +89,49 @@ public String toString() { * The type of the tag * @return the type of the tag */ + @PropertyGetter(role = TYPE) TagType getType(); /** * Define the type of the tag * @param type the type name */ + @PropertySetter(role = TYPE) E setType(String type); /** * Define the type of the tag * @param type the new type */ + @PropertySetter(role = TYPE) E setType(TagType type); /** * Get the content of the atg * @return the content of the tag */ + @PropertyGetter(role = COMMENT_CONTENT) String getContent(); /** * Define the content of the tag * @param content the new content of the tag */ + @PropertySetter(role = COMMENT_CONTENT) E setContent(String content); /** * Get the parameter of the tag return null when none is specified (only for @param and @throws) * @return the parameter */ + @PropertyGetter(role = PARAMETER) String getParam(); /** * Define a parameter * @param param the parameter */ + @PropertySetter(role = PARAMETER) E setParam(String param); @Override diff --git a/src/main/java/spoon/reflect/code/CtLambda.java b/src/main/java/spoon/reflect/code/CtLambda.java index 5846595c67e..e1a1fdec86a 100644 --- a/src/main/java/spoon/reflect/code/CtLambda.java +++ b/src/main/java/spoon/reflect/code/CtLambda.java @@ -20,10 +20,14 @@ import spoon.reflect.declaration.CtMethod; import spoon.reflect.reference.CtTypeReference; import spoon.support.DerivedProperty; +import spoon.reflect.annotations.PropertyGetter; +import spoon.reflect.annotations.PropertySetter; import spoon.support.UnsettableProperty; import java.util.Set; +import static spoon.reflect.path.CtRole.EXPRESSION; + /** * This code element represents the creation of a lambda. A lambda * can have two sorts of body : an simple expression or a block of @@ -59,6 +63,7 @@ public interface CtLambda extends CtExpression, CtExecutable { * Gets the expression in the body. Null if the body is a list * of statements. */ + @PropertyGetter(role = EXPRESSION) CtExpression getExpression(); /** @@ -72,6 +77,7 @@ public interface CtLambda extends CtExpression, CtExecutable { * Sets the expression in the body of the lambda. Nothing will change * if the lambda already has a value in the body attribute. */ + @PropertySetter(role = EXPRESSION) > C setExpression(CtExpression expression); @Override diff --git a/src/main/java/spoon/reflect/code/CtLiteral.java b/src/main/java/spoon/reflect/code/CtLiteral.java index 51a54cc3e9d..f3e6fb726c0 100644 --- a/src/main/java/spoon/reflect/code/CtLiteral.java +++ b/src/main/java/spoon/reflect/code/CtLiteral.java @@ -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 literal value (an int, a string, etc). * @@ -32,11 +37,13 @@ public interface CtLiteral extends CtExpression { /** * Gets the actual value of the literal (statically known). */ + @PropertyGetter(role = EXPRESSION) T getValue(); /** * Sets the actual value of the literal. */ + @PropertySetter(role = EXPRESSION) > C setValue(T value); /** Overriding return type, a clone of a CtLiteral returns a CtLiteral */ diff --git a/src/main/java/spoon/reflect/code/CtLoop.java b/src/main/java/spoon/reflect/code/CtLoop.java index 2beee48cbc1..4eb2ac3d279 100644 --- a/src/main/java/spoon/reflect/code/CtLoop.java +++ b/src/main/java/spoon/reflect/code/CtLoop.java @@ -16,8 +16,11 @@ */ package spoon.reflect.code; +import spoon.reflect.annotations.PropertyGetter; import spoon.template.TemplateParameter; +import static spoon.reflect.path.CtRole.BODY; + /** * This abstract code element defines a loop. */ @@ -27,6 +30,7 @@ public interface CtLoop extends CtStatement, TemplateParameter, CtBodyHold * Gets the body of this loop. */ @Override + @PropertyGetter(role = BODY) CtStatement getBody(); @Override diff --git a/src/main/java/spoon/reflect/code/CtNewArray.java b/src/main/java/spoon/reflect/code/CtNewArray.java index e9258a7285d..1051d3cf667 100644 --- a/src/main/java/spoon/reflect/code/CtNewArray.java +++ b/src/main/java/spoon/reflect/code/CtNewArray.java @@ -16,8 +16,14 @@ */ package spoon.reflect.code; +import spoon.reflect.annotations.PropertyGetter; +import spoon.reflect.annotations.PropertySetter; + import java.util.List; +import static spoon.reflect.path.CtRole.DIMENSION; +import static spoon.reflect.path.CtRole.EXPRESSION; + /** * This code element defines the inline creation of a new array. * @@ -34,41 +40,49 @@ public interface CtNewArray extends CtExpression { /** * Gets the expressions that define the array's dimensions. */ + @PropertyGetter(role = DIMENSION) List> getDimensionExpressions(); /** * Sets the expressions that define the array's dimensions. */ + @PropertySetter(role = DIMENSION) > C setDimensionExpressions(List> dimensions); /** * Adds a dimension expression. */ + @PropertySetter(role = DIMENSION) > C addDimensionExpression(CtExpression dimension); /** * Removes a dimension expression. */ + @PropertySetter(role = DIMENSION) boolean removeDimensionExpression(CtExpression dimension); /** * Gets the initialization expressions. */ + @PropertyGetter(role = EXPRESSION) List> getElements(); /** * Sets the initialization expressions. */ + @PropertySetter(role = EXPRESSION) > C setElements(List> expression); /** * Adds an element. */ + @PropertySetter(role = EXPRESSION) > C addElement(CtExpression expression); /** * Removes an element. */ + @PropertySetter(role = EXPRESSION) boolean removeElement(CtExpression expression); @Override diff --git a/src/main/java/spoon/reflect/code/CtNewClass.java b/src/main/java/spoon/reflect/code/CtNewClass.java index 6cf15dcc86a..dfbfd984edd 100644 --- a/src/main/java/spoon/reflect/code/CtNewClass.java +++ b/src/main/java/spoon/reflect/code/CtNewClass.java @@ -21,9 +21,13 @@ import spoon.reflect.reference.CtExecutableReference; import spoon.reflect.reference.CtTypeReference; import spoon.support.DerivedProperty; +import spoon.reflect.annotations.PropertyGetter; +import spoon.reflect.annotations.PropertySetter; import java.util.List; +import static spoon.reflect.path.CtRole.TYPE_PARAMETER; + /** * This code element represents the creation of a anonymous class. * @@ -48,6 +52,7 @@ public interface CtNewClass extends CtConstructorCall { */ @Override @DerivedProperty + @PropertyGetter(role = TYPE_PARAMETER) List> getActualTypeArguments(); /** @@ -56,6 +61,7 @@ public interface CtNewClass extends CtConstructorCall { * @see CtExecutableReference#getActualTypeArguments() */ @Override + @PropertySetter(role = TYPE_PARAMETER) T setActualTypeArguments(List> actualTypeArguments); /** @@ -64,6 +70,7 @@ public interface CtNewClass extends CtConstructorCall { * @see CtExecutableReference#getActualTypeArguments() */ @Override + @PropertySetter(role = TYPE_PARAMETER) T addActualTypeArgument(CtTypeReference actualTypeArgument); /** diff --git a/src/main/java/spoon/reflect/code/CtOperatorAssignment.java b/src/main/java/spoon/reflect/code/CtOperatorAssignment.java index c47c2669e65..f8bb1740b39 100644 --- a/src/main/java/spoon/reflect/code/CtOperatorAssignment.java +++ b/src/main/java/spoon/reflect/code/CtOperatorAssignment.java @@ -16,6 +16,12 @@ */ package spoon.reflect.code; +import spoon.reflect.annotations.PropertyGetter; +import spoon.reflect.annotations.PropertySetter; + +import static spoon.reflect.path.CtRole.OPERATOR_KIND; + + /** * This code element defines an self-operated assignment such as += or *=. * @@ -30,11 +36,13 @@ public interface CtOperatorAssignment extends CtAssignment /** * Sets the operator kind. */ + @PropertySetter(role = OPERATOR_KIND) > C setKind(BinaryOperatorKind kind); /** * Gets the operator kind. */ + @PropertyGetter(role = OPERATOR_KIND) BinaryOperatorKind getKind(); @Override diff --git a/src/main/java/spoon/reflect/code/CtRHSReceiver.java b/src/main/java/spoon/reflect/code/CtRHSReceiver.java index 23474701b17..9834b96c9e6 100644 --- a/src/main/java/spoon/reflect/code/CtRHSReceiver.java +++ b/src/main/java/spoon/reflect/code/CtRHSReceiver.java @@ -17,6 +17,10 @@ package spoon.reflect.code; import spoon.reflect.declaration.CtField; +import spoon.reflect.annotations.PropertyGetter; +import spoon.reflect.annotations.PropertySetter; + +import static spoon.reflect.path.CtRole.ASSIGNMENT; /** * Represents the right hand side of an assignment @@ -27,10 +31,12 @@ public interface CtRHSReceiver { /** * Returns the right-hand side of the "=" operator. */ + @PropertyGetter(role = ASSIGNMENT) CtExpression getAssignment(); /** * Sets the right-hand side expression (RHS) of the "=" operator. */ + @PropertySetter(role = ASSIGNMENT) > T setAssignment(CtExpression assignment); } diff --git a/src/main/java/spoon/reflect/code/CtReturn.java b/src/main/java/spoon/reflect/code/CtReturn.java index 399ebd99344..b9b809da4b1 100644 --- a/src/main/java/spoon/reflect/code/CtReturn.java +++ b/src/main/java/spoon/reflect/code/CtReturn.java @@ -16,8 +16,12 @@ */ package spoon.reflect.code; +import spoon.reflect.annotations.PropertyGetter; +import spoon.reflect.annotations.PropertySetter; import spoon.template.TemplateParameter; +import static spoon.reflect.path.CtRole.EXPRESSION; + /** * This code element represents a return statement. * @@ -37,11 +41,13 @@ public interface CtReturn extends CtCFlowBreak, TemplateParameter { /** * Gets the returned expression. */ + @PropertyGetter(role = EXPRESSION) CtExpression getReturnedExpression(); /** * Sets the returned expression. */ + @PropertySetter(role = EXPRESSION) > T setReturnedExpression(CtExpression returnedExpression); @Override diff --git a/src/main/java/spoon/reflect/code/CtStatement.java b/src/main/java/spoon/reflect/code/CtStatement.java index 507e51de5ea..5e3c0d40e42 100644 --- a/src/main/java/spoon/reflect/code/CtStatement.java +++ b/src/main/java/spoon/reflect/code/CtStatement.java @@ -17,6 +17,10 @@ package spoon.reflect.code; import spoon.reflect.declaration.ParentNotInitializedException; +import spoon.reflect.annotations.PropertyGetter; +import spoon.reflect.annotations.PropertySetter; + +import static spoon.reflect.path.CtRole.LABEL; /** * This abstract code element represents all the statements, which can be part @@ -52,11 +56,13 @@ public interface CtStatement extends CtCodeElement { * * @return the label's name (null if undefined) */ + @PropertyGetter(role = LABEL) String getLabel(); /** * Sets the label of this statement. */ + @PropertySetter(role = LABEL) T setLabel(String label); /** diff --git a/src/main/java/spoon/reflect/code/CtStatementList.java b/src/main/java/spoon/reflect/code/CtStatementList.java index 49d8bb97631..e62e015804a 100644 --- a/src/main/java/spoon/reflect/code/CtStatementList.java +++ b/src/main/java/spoon/reflect/code/CtStatementList.java @@ -16,8 +16,13 @@ */ package spoon.reflect.code; +import spoon.reflect.annotations.PropertyGetter; +import spoon.reflect.annotations.PropertySetter; + import java.util.List; +import static spoon.reflect.path.CtRole.STATEMENT; + /** * This code element represents a list of statements. It is not a valid Java * program element and is never used directly, on contrary to @@ -27,21 +32,25 @@ public interface CtStatementList extends CtCodeElement, Iterable { /** * Returns the statement list. */ + @PropertyGetter(role = STATEMENT) List getStatements(); /** * Sets the statement list. */ + @PropertySetter(role = STATEMENT) T setStatements(List statements); /** * Adds a statement at the end of the list. */ + @PropertySetter(role = STATEMENT) T addStatement(CtStatement statement); /** * Removes a statement. */ + @PropertySetter(role = STATEMENT) void removeStatement(CtStatement statement); @Override diff --git a/src/main/java/spoon/reflect/code/CtSwitch.java b/src/main/java/spoon/reflect/code/CtSwitch.java index d2917a73d20..2379c5e7dcd 100644 --- a/src/main/java/spoon/reflect/code/CtSwitch.java +++ b/src/main/java/spoon/reflect/code/CtSwitch.java @@ -16,8 +16,14 @@ */ package spoon.reflect.code; +import spoon.reflect.annotations.PropertyGetter; +import spoon.reflect.annotations.PropertySetter; + import java.util.List; +import static spoon.reflect.path.CtRole.CASE; +import static spoon.reflect.path.CtRole.EXPRESSION; + /** * This code element defines a switch statement. * @@ -41,6 +47,7 @@ public interface CtSwitch extends CtStatement { * Character, Byte, Short, * Integer, or an enum type */ + @PropertyGetter(role = EXPRESSION) CtExpression getSelector(); /** @@ -49,26 +56,31 @@ public interface CtSwitch extends CtStatement { * Character, Byte, Short, * Integer, or an enum type */ + @PropertySetter(role = EXPRESSION) > T setSelector(CtExpression selector); /** * Gets the list of cases defined for this switch. */ + @PropertyGetter(role = CASE) List> getCases(); /** * Sets the list of cases defined for this switch. */ + @PropertySetter(role = CASE) > T setCases(List> cases); /** * Adds a case; */ + @PropertySetter(role = CASE) > T addCase(CtCase c); /** * Removes a case; */ + @PropertySetter(role = CASE) boolean removeCase(CtCase c); @Override diff --git a/src/main/java/spoon/reflect/code/CtSynchronized.java b/src/main/java/spoon/reflect/code/CtSynchronized.java index a504e452a19..b78c474d4bc 100644 --- a/src/main/java/spoon/reflect/code/CtSynchronized.java +++ b/src/main/java/spoon/reflect/code/CtSynchronized.java @@ -16,6 +16,13 @@ */ package spoon.reflect.code; +import spoon.reflect.annotations.PropertyGetter; +import spoon.reflect.annotations.PropertySetter; + +import static spoon.reflect.path.CtRole.BODY; +import static spoon.reflect.path.CtRole.EXPRESSION; + + /** * This code element defines a synchronized statement. * @@ -33,21 +40,25 @@ public interface CtSynchronized extends CtStatement { * * @return the monitored object if defined, null otherwise */ + @PropertyGetter(role = EXPRESSION) CtExpression getExpression(); /** * Sets the expression that defines the monitored. */ + @PropertySetter(role = EXPRESSION) T setExpression(CtExpression expression); /** * Gets the synchronized block. */ + @PropertyGetter(role = BODY) CtBlock getBlock(); /** * Sets the synchronized block. */ + @PropertyGetter(role = BODY) T setBlock(CtBlock block); @Override diff --git a/src/main/java/spoon/reflect/code/CtTargetedExpression.java b/src/main/java/spoon/reflect/code/CtTargetedExpression.java index 2b3693b0fd1..f862cef866d 100644 --- a/src/main/java/spoon/reflect/code/CtTargetedExpression.java +++ b/src/main/java/spoon/reflect/code/CtTargetedExpression.java @@ -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; + + /** * This abstract code element defines an expression which contains a target * expression. In Java, it is generally of the form: @@ -30,11 +36,13 @@ public interface CtTargetedExpression> extends CtEx /** * Gets the target expression. The target is a `CtTypeAccess` for static methods and a sub type of `CtExpression` for everything else. */ + @PropertyGetter(role = TARGET) E getTarget(); /** * Sets the target expression. */ + @PropertySetter(role = TARGET) > C setTarget(E target); @Override diff --git a/src/main/java/spoon/reflect/code/CtThrow.java b/src/main/java/spoon/reflect/code/CtThrow.java index 7f058de7370..d451e5bb511 100644 --- a/src/main/java/spoon/reflect/code/CtThrow.java +++ b/src/main/java/spoon/reflect/code/CtThrow.java @@ -16,8 +16,12 @@ */ package spoon.reflect.code; +import spoon.reflect.annotations.PropertyGetter; +import spoon.reflect.annotations.PropertySetter; import spoon.template.TemplateParameter; +import static spoon.reflect.path.CtRole.THROWN; + /** * This code element defines a throw statement. * @@ -31,11 +35,13 @@ public interface CtThrow extends CtCFlowBreak, TemplateParameter { /** * Returns the thrown expression (must be a throwable). */ + @PropertyGetter(role = THROWN) CtExpression getThrownExpression(); /** * Sets the thrown expression (must be a throwable). */ + @PropertySetter(role = THROWN) T setThrownExpression(CtExpression thrownExpression); @Override diff --git a/src/main/java/spoon/reflect/code/CtTry.java b/src/main/java/spoon/reflect/code/CtTry.java index 160777f60b3..c0fa99a570d 100644 --- a/src/main/java/spoon/reflect/code/CtTry.java +++ b/src/main/java/spoon/reflect/code/CtTry.java @@ -16,10 +16,16 @@ */ package spoon.reflect.code; +import spoon.reflect.annotations.PropertyGetter; +import spoon.reflect.annotations.PropertySetter; import spoon.template.TemplateParameter; import java.util.List; +import static spoon.reflect.path.CtRole.BODY; +import static spoon.reflect.path.CtRole.CATCH; +import static spoon.reflect.path.CtRole.FINALIZER; + /** * This code element defines a try statement. * @@ -35,39 +41,46 @@ public interface CtTry extends CtStatement, TemplateParameter, CtBodyHolde /** * Gets the catchers of this try. */ + @PropertyGetter(role = CATCH) List getCatchers(); /** * Sets the catchers of this try. */ + @PropertySetter(role = CATCH) T setCatchers(List catchers); /** * Adds a catch block. */ + @PropertySetter(role = CATCH) T addCatcher(CtCatch catcher); /** * Removes a catch block. */ + @PropertySetter(role = CATCH) boolean removeCatcher(CtCatch catcher); /** * Gets the try body. */ @Override + @PropertyGetter(role = BODY) CtBlock getBody(); /** * Gets the finalizer block of this try ( * finally part). */ + @PropertyGetter(role = FINALIZER) CtBlock getFinalizer(); /** * Sets the finalizer block of this try ( * finally part). */ + @PropertySetter(role = FINALIZER) T setFinalizer(CtBlock finalizer); @Override diff --git a/src/main/java/spoon/reflect/code/CtTryWithResource.java b/src/main/java/spoon/reflect/code/CtTryWithResource.java index 8d415fc154b..2eae7d5c521 100644 --- a/src/main/java/spoon/reflect/code/CtTryWithResource.java +++ b/src/main/java/spoon/reflect/code/CtTryWithResource.java @@ -16,8 +16,13 @@ */ package spoon.reflect.code; +import spoon.reflect.annotations.PropertyGetter; +import spoon.reflect.annotations.PropertySetter; + import java.util.List; +import static spoon.reflect.path.CtRole.TRY_RESOURCE; + /** * This code element defines a try with resource statement. * @@ -35,22 +40,26 @@ public interface CtTryWithResource extends CtTry { * Gets the auto-closeable resources of this try. Available * from Java 7 with the try-with-resource statement. */ + @PropertyGetter(role = TRY_RESOURCE) List> getResources(); /** * Sets the auto-closeable resources of this try. Available * from Java 7 with the try-with-resource statement. */ + @PropertySetter(role = TRY_RESOURCE) T setResources(List> resources); /** * Adds a resource. */ + @PropertySetter(role = TRY_RESOURCE) T addResource(CtLocalVariable resource); /** * Removes a resource. */ + @PropertySetter(role = TRY_RESOURCE) boolean removeResource(CtLocalVariable resource); @Override diff --git a/src/main/java/spoon/reflect/code/CtUnaryOperator.java b/src/main/java/spoon/reflect/code/CtUnaryOperator.java index 94ae730c2db..fdb6970f0ac 100644 --- a/src/main/java/spoon/reflect/code/CtUnaryOperator.java +++ b/src/main/java/spoon/reflect/code/CtUnaryOperator.java @@ -16,6 +16,13 @@ */ package spoon.reflect.code; +import spoon.reflect.annotations.PropertyGetter; +import spoon.reflect.annotations.PropertySetter; + +import static spoon.reflect.path.CtRole.EXPRESSION; +import static spoon.reflect.path.CtRole.OPERATOR_KIND; + + /** * This code element represents a unary operator. * For example : @@ -32,21 +39,25 @@ public interface CtUnaryOperator extends CtExpression, CtStatement { /** * Gets the expression to which the operator is applied. */ + @PropertyGetter(role = EXPRESSION) CtExpression getOperand(); /** * Sets the expression to which the operator is applied. */ + @PropertySetter(role = EXPRESSION) C setOperand(CtExpression expression); /** * Sets the kind of this operator. */ + @PropertySetter(role = OPERATOR_KIND) C setKind(UnaryOperatorKind kind); /** * Gets the kind of this operator. */ + @PropertyGetter(role = OPERATOR_KIND) UnaryOperatorKind getKind(); @Override diff --git a/src/main/java/spoon/reflect/code/CtVariableAccess.java b/src/main/java/spoon/reflect/code/CtVariableAccess.java index c1ea8560fa9..8aad39d3013 100644 --- a/src/main/java/spoon/reflect/code/CtVariableAccess.java +++ b/src/main/java/spoon/reflect/code/CtVariableAccess.java @@ -19,6 +19,10 @@ import spoon.reflect.reference.CtTypeReference; import spoon.reflect.reference.CtVariableReference; import spoon.support.DerivedProperty; +import spoon.reflect.annotations.PropertyGetter; +import spoon.reflect.annotations.PropertySetter; + +import static spoon.reflect.path.CtRole.VARIABLE; /** * This code element defines an access to a variable (read and write). @@ -32,11 +36,13 @@ public interface CtVariableAccess extends CtExpression { /** * Gets the reference to the accessed variable. */ + @PropertyGetter(role = VARIABLE) CtVariableReference getVariable(); /** * Sets the reference to the accessed variable. */ + @PropertySetter(role = VARIABLE) > C setVariable(CtVariableReference variable); @Override diff --git a/src/main/java/spoon/reflect/code/CtWhile.java b/src/main/java/spoon/reflect/code/CtWhile.java index 7538d7cdd2b..6c9a278534d 100644 --- a/src/main/java/spoon/reflect/code/CtWhile.java +++ b/src/main/java/spoon/reflect/code/CtWhile.java @@ -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 while loop. * @@ -32,11 +37,13 @@ public interface CtWhile extends CtLoop { /** * Gets the looping boolean test expression. */ + @PropertyGetter(role = EXPRESSION) CtExpression getLoopingExpression(); /** * Sets the looping boolean test expression. */ + @PropertySetter(role = EXPRESSION) T setLoopingExpression(CtExpression expression); @Override diff --git a/src/main/java/spoon/reflect/declaration/CtAnnotation.java b/src/main/java/spoon/reflect/declaration/CtAnnotation.java index 9e42981026b..7dd1e12e743 100644 --- a/src/main/java/spoon/reflect/declaration/CtAnnotation.java +++ b/src/main/java/spoon/reflect/declaration/CtAnnotation.java @@ -22,12 +22,17 @@ import spoon.reflect.code.CtNewArray; import spoon.reflect.reference.CtTypeReference; import spoon.support.DerivedProperty; +import spoon.reflect.annotations.PropertyGetter; +import spoon.reflect.annotations.PropertySetter; import spoon.support.UnsettableProperty; import java.lang.annotation.Annotation; import java.util.List; import java.util.Map; +import static spoon.reflect.path.CtRole.ANNOTATION_TYPE; +import static spoon.reflect.path.CtRole.VALUE; + /** * This element represents an annotation on an element. * @@ -49,6 +54,7 @@ public interface CtAnnotation extends CtExpression, CtS * the types referenced by the annotation have been compiled and are in the * classpath so that accessed values can be converted into the actual types. */ + @DerivedProperty A getActualAnnotation(); /** @@ -56,6 +62,7 @@ public interface CtAnnotation extends CtExpression, CtS * * @return a reference to the type of this annotation */ + @PropertyGetter(role = ANNOTATION_TYPE) CtTypeReference getAnnotationType(); /** @@ -65,6 +72,7 @@ public interface CtAnnotation extends CtExpression, CtS * Name of searched value. * @return the value expression or null if not found. */ + @PropertyGetter(role = VALUE) T getValue(String key); /** @@ -76,6 +84,7 @@ public interface CtAnnotation extends CtExpression, CtS * @return this annotation's element names and their values, or an empty map * if there are none */ + @PropertyGetter(role = VALUE) Map getValues(); /** @@ -84,6 +93,7 @@ public interface CtAnnotation extends CtExpression, CtS * @param type * reference to the type of this annotation */ + @PropertySetter(role = ANNOTATION_TYPE) > T setAnnotationType(CtTypeReference type); /** @@ -92,6 +102,7 @@ public interface CtAnnotation extends CtExpression, CtS * values. Note that type values are stored as * {@link spoon.reflect.reference.CtTypeReference}. */ + @PropertySetter(role = VALUE) > T setElementValues(Map values); /** @@ -99,6 +110,7 @@ public interface CtAnnotation extends CtExpression, CtS * form of a map that associates element names with their corresponding * values. */ + @PropertySetter(role = VALUE) > T setValues(Map values); /** @@ -114,31 +126,37 @@ public interface CtAnnotation extends CtExpression, CtS * * @return {@link spoon.reflect.declaration.CtAnnotatedElementType} */ + @DerivedProperty CtAnnotatedElementType getAnnotatedElementType(); /** * Adds a new key-value pair for this annotation */ + @PropertySetter(role = VALUE) > T addValue(String elementName, Object value); /** * Adds a new key-literal pair for this annotation. */ + @PropertySetter(role = VALUE) > T addValue(String elementName, CtLiteral value); /** * Adds a new key-array pair for this annotation. */ + @PropertySetter(role = VALUE) > T addValue(String elementName, CtNewArray value); /** * Adds a new key-field access pair for this annotation. */ + @PropertySetter(role = VALUE) > T addValue(String elementName, CtFieldAccess value); /** * Adds a new key-annotation pair for this annotation. */ + @PropertySetter(role = VALUE) > T addValue(String elementName, CtAnnotation value); @Override diff --git a/src/main/java/spoon/reflect/declaration/CtAnnotationMethod.java b/src/main/java/spoon/reflect/declaration/CtAnnotationMethod.java index ffc78999a24..ff9d2fc00d7 100644 --- a/src/main/java/spoon/reflect/declaration/CtAnnotationMethod.java +++ b/src/main/java/spoon/reflect/declaration/CtAnnotationMethod.java @@ -20,11 +20,15 @@ import spoon.reflect.code.CtExpression; import spoon.reflect.code.CtStatement; import spoon.reflect.reference.CtTypeReference; +import spoon.reflect.annotations.PropertyGetter; +import spoon.reflect.annotations.PropertySetter; import spoon.support.UnsettableProperty; import java.util.List; import java.util.Set; +import static spoon.reflect.path.CtRole.DEFAULT_EXPRESSION; + /** * This element defines an annotation method declared in an annotation type. */ @@ -32,11 +36,13 @@ public interface CtAnnotationMethod extends CtMethod { /** * Gets the default expression assigned to the annotation method. */ + @PropertyGetter(role = DEFAULT_EXPRESSION) CtExpression getDefaultExpression(); /** * Sets the default expression assigned to the annotation method. */ + @PropertySetter(role = DEFAULT_EXPRESSION) > C setDefaultExpression(CtExpression assignedExpression); @Override diff --git a/src/main/java/spoon/reflect/declaration/CtClass.java b/src/main/java/spoon/reflect/declaration/CtClass.java index 743e3b80a26..cb12e5230b4 100644 --- a/src/main/java/spoon/reflect/declaration/CtClass.java +++ b/src/main/java/spoon/reflect/declaration/CtClass.java @@ -19,10 +19,14 @@ import spoon.reflect.code.CtStatement; import spoon.reflect.reference.CtTypeReference; import spoon.support.DerivedProperty; +import spoon.reflect.annotations.PropertyGetter; +import spoon.reflect.annotations.PropertySetter; import java.util.List; import java.util.Set; +import static spoon.reflect.path.CtRole.CONSTRUCTOR; + /** * This element represents a class declaration. * @@ -44,7 +48,11 @@ public interface CtClass extends CtType, CtStatement { /** * Returns the constructor of the class that takes the given argument types. + * + * Derived from {@link #getTypeMembers()} */ + @DerivedProperty + @PropertyGetter(role = CONSTRUCTOR) CtConstructor getConstructor(CtTypeReference... parameterTypes); /** @@ -54,6 +62,7 @@ public interface CtClass extends CtType, CtStatement { * Derived from {@link #getTypeMembers()} */ @DerivedProperty + @PropertyGetter(role = CONSTRUCTOR) Set> getConstructors(); /** @@ -80,16 +89,19 @@ public interface CtClass extends CtType, CtStatement { /** * Sets the constructors for this class. */ + @PropertySetter(role = CONSTRUCTOR) > C setConstructors(Set> constructors); /** * Adds a constructor to this class. */ + @PropertySetter(role = CONSTRUCTOR) > C addConstructor(CtConstructor constructor); /** * Removes a constructor from this class. */ + @PropertySetter(role = CONSTRUCTOR) void removeConstructor(CtConstructor constructor); /** diff --git a/src/main/java/spoon/reflect/declaration/CtCodeSnippet.java b/src/main/java/spoon/reflect/declaration/CtCodeSnippet.java index 053e56c4853..023dda5129b 100644 --- a/src/main/java/spoon/reflect/declaration/CtCodeSnippet.java +++ b/src/main/java/spoon/reflect/declaration/CtCodeSnippet.java @@ -16,6 +16,10 @@ */ package spoon.reflect.declaration; +import spoon.reflect.annotations.PropertySetter; + +import static spoon.reflect.path.CtRole.EXPRESSION; + /** * This interface represents snippets of source code that can be used in the AST * to represent complex code without having to build the corresponding program @@ -31,11 +35,13 @@ public interface CtCodeSnippet { /** * Sets the textual value of the code. */ + @PropertySetter(role = EXPRESSION) C setValue(String value); /** * Gets the textual value of the code. */ + @PropertySetter(role = EXPRESSION) String getValue(); } diff --git a/src/main/java/spoon/reflect/declaration/CtConstructor.java b/src/main/java/spoon/reflect/declaration/CtConstructor.java index 638ccf00268..a51b1299cac 100644 --- a/src/main/java/spoon/reflect/declaration/CtConstructor.java +++ b/src/main/java/spoon/reflect/declaration/CtConstructor.java @@ -17,8 +17,11 @@ package spoon.reflect.declaration; import spoon.reflect.reference.CtTypeReference; +import spoon.reflect.annotations.PropertyGetter; import spoon.support.UnsettableProperty; +import static spoon.reflect.path.CtRole.NAME; + /** * This element defines a constructor declaration. */ @@ -27,6 +30,7 @@ public interface CtConstructor extends CtExecutable, CtTypeMember, CtForma /** * Always returns "<init>". */ + @PropertyGetter(role = NAME) String getSimpleName(); @Override diff --git a/src/main/java/spoon/reflect/declaration/CtElement.java b/src/main/java/spoon/reflect/declaration/CtElement.java index a845a16ef99..93a226bd4e8 100644 --- a/src/main/java/spoon/reflect/declaration/CtElement.java +++ b/src/main/java/spoon/reflect/declaration/CtElement.java @@ -25,11 +25,17 @@ import spoon.reflect.visitor.Root; import spoon.reflect.visitor.chain.CtQueryable; import spoon.support.DerivedProperty; +import spoon.reflect.annotations.PropertyGetter; +import spoon.reflect.annotations.PropertySetter; import java.lang.annotation.Annotation; import java.util.List; import java.util.Set; +import static spoon.reflect.path.CtRole.ANNOTATION; +import static spoon.reflect.path.CtRole.COMMENT; +import static spoon.reflect.path.CtRole.IS_IMPLICIT; + /** * This interface is the root interface for the metamodel elements (any program * element). @@ -53,6 +59,7 @@ public interface CtElement extends FactoryAccessor, CtVisitable, Cloneable, CtQu * the annotation's class * @return if found, returns a proxy for this annotation */ + @PropertyGetter(role = ANNOTATION) A getAnnotation(Class annotationType); /** @@ -63,6 +70,7 @@ public interface CtElement extends FactoryAccessor, CtVisitable, Cloneable, CtQu * @return the annotation if this element is annotated by one annotation of * the given type */ + @PropertyGetter(role = ANNOTATION) CtAnnotation getAnnotation( CtTypeReference annotationType); @@ -71,17 +79,20 @@ CtAnnotation getAnnotation( * * For sake of encapsulation, the returned list is unmodifiable. */ + @PropertyGetter(role = ANNOTATION) List> getAnnotations(); /** * Returns the text of the documentation ("javadoc") comment of this * element. The documentation is also accessible via {@link #getComments()}. */ + @DerivedProperty String getDocComment(); /** * Build a short representation of any element. */ + @DerivedProperty String getShortRepresentation(); /** @@ -149,11 +160,13 @@ List getAnnotatedChildren( * Java compiler or inferred when the model is built). * Consequently, implicit elements are not pretty-printed and have no position. */ + @PropertyGetter(role = IS_IMPLICIT) boolean isImplicit(); /** * Sets this element to be implicit. */ + @PropertySetter(role = IS_IMPLICIT) E setImplicit(boolean b); /** @@ -182,6 +195,7 @@ List getAnnotatedChildren( /** * Sets the annotations for this element. */ + @PropertySetter(role = ANNOTATION) E setAnnotations(List> annotation); /** @@ -251,12 +265,14 @@ List getAnnotatedChildren( /** * Set the comment list */ + @PropertySetter(role = COMMENT) E setComments(List comments); /** * The list of comments * @return the list of comment */ + @PropertyGetter(role = COMMENT) List getComments(); /** @@ -264,12 +280,14 @@ List getAnnotatedChildren( * element.addComment(element.getFactory().Code().createComment("comment", CtComment.CommentType.INLINE) * @param comment the comment */ + @PropertySetter(role = COMMENT) E addComment(CtComment comment); /** * Remove a comment * @param comment the comment to remove */ + @PropertySetter(role = COMMENT) E removeComment(CtComment comment); /** diff --git a/src/main/java/spoon/reflect/declaration/CtEnum.java b/src/main/java/spoon/reflect/declaration/CtEnum.java index beeabbd3946..d11513e016c 100644 --- a/src/main/java/spoon/reflect/declaration/CtEnum.java +++ b/src/main/java/spoon/reflect/declaration/CtEnum.java @@ -17,10 +17,14 @@ package spoon.reflect.declaration; import spoon.reflect.reference.CtTypeReference; +import spoon.reflect.annotations.PropertyGetter; +import spoon.reflect.annotations.PropertySetter; import spoon.support.UnsettableProperty; import java.util.List; +import static spoon.reflect.path.CtRole.VALUE; + /** * This element represents an enumeration declaration. * @@ -38,6 +42,7 @@ public interface CtEnum> extends CtClass { * An enum value. * @return true if this element changed as a result of the call */ + @PropertySetter(role = VALUE) > C addEnumValue(CtEnumValue enumValue); /** @@ -47,6 +52,7 @@ public interface CtEnum> extends CtClass { * An enum value. * @return true if this element changed as a result of the call */ + @PropertySetter(role = VALUE) boolean removeEnumValue(CtEnumValue enumValue); /** @@ -56,6 +62,7 @@ public interface CtEnum> extends CtClass { * Name of the enum value. * @return An enum value. */ + @PropertyGetter(role = VALUE) CtEnumValue getEnumValue(String name); /** @@ -63,11 +70,13 @@ public interface CtEnum> extends CtClass { * * @return All enum values. */ + @PropertyGetter(role = VALUE) List> getEnumValues(); /** *Sets all enum values of the enum. */ + @PropertySetter(role = VALUE) > C setEnumValues(List> enumValues); @Override diff --git a/src/main/java/spoon/reflect/declaration/CtExecutable.java b/src/main/java/spoon/reflect/declaration/CtExecutable.java index 6714ae87e81..0d7597d86b9 100644 --- a/src/main/java/spoon/reflect/declaration/CtExecutable.java +++ b/src/main/java/spoon/reflect/declaration/CtExecutable.java @@ -21,10 +21,15 @@ import spoon.reflect.reference.CtExecutableReference; import spoon.reflect.reference.CtTypeReference; import spoon.support.DerivedProperty; +import spoon.reflect.annotations.PropertyGetter; +import spoon.reflect.annotations.PropertySetter; import java.util.List; import java.util.Set; +import static spoon.reflect.path.CtRole.PARAMETER; +import static spoon.reflect.path.CtRole.THROWN; + /** * This element represents an executable element such as a method, a * constructor, or an anonymous block. @@ -53,11 +58,13 @@ public interface CtExecutable extends CtNamedElement, CtTypedElement, CtBo /** * Gets the parameters list. */ + @PropertyGetter(role = PARAMETER) List> getParameters(); /** * Sets the parameters. */ + @PropertySetter(role = PARAMETER) > T setParameters(List> parameters); /** @@ -66,6 +73,7 @@ public interface CtExecutable extends CtNamedElement, CtTypedElement, CtBo * @param parameter * @return true if this element changed as a result of the call */ + @PropertySetter(role = PARAMETER) > T addParameter(CtParameter parameter); /** @@ -80,11 +88,13 @@ public interface CtExecutable extends CtNamedElement, CtTypedElement, CtBo * Returns the exceptions and other throwables listed in this method or * constructor's throws clause. */ + @PropertyGetter(role = THROWN) Set> getThrownTypes(); /** * Sets the thrown types. */ + @PropertySetter(role = THROWN) > T setThrownTypes(Set> thrownTypes); /** @@ -93,6 +103,7 @@ public interface CtExecutable extends CtNamedElement, CtTypedElement, CtBo * @param throwType * @return true if this element changed as a result of the call */ + @PropertySetter(role = THROWN) > T addThrownType(CtTypeReference throwType); /** diff --git a/src/main/java/spoon/reflect/declaration/CtFormalTypeDeclarer.java b/src/main/java/spoon/reflect/declaration/CtFormalTypeDeclarer.java index 55cee002f13..3a6030c599d 100644 --- a/src/main/java/spoon/reflect/declaration/CtFormalTypeDeclarer.java +++ b/src/main/java/spoon/reflect/declaration/CtFormalTypeDeclarer.java @@ -16,8 +16,13 @@ */ package spoon.reflect.declaration; +import spoon.reflect.annotations.PropertyGetter; +import spoon.reflect.annotations.PropertySetter; + import java.util.List; +import static spoon.reflect.path.CtRole.TYPE_PARAMETER; + /** * This abstract element defines a declaration that accepts formal type * parameters (aka generics), such as a CtType (class A<E>), CtMethod or CtConstructor. @@ -27,20 +32,24 @@ public interface CtFormalTypeDeclarer extends CtTypeMember { /** * Returns the formal type parameters of this generic element. */ + @PropertyGetter(role = TYPE_PARAMETER) List getFormalCtTypeParameters(); /** * Sets the type parameters of this generic element. */ + @PropertySetter(role = TYPE_PARAMETER) T setFormalCtTypeParameters(List formalTypeParameters); /** * Add a type parameter to this generic element. */ + @PropertySetter(role = TYPE_PARAMETER) T addFormalCtTypeParameter(CtTypeParameter formalTypeParameter); /** * Removes a type parameters from this generic element. */ + @PropertySetter(role = TYPE_PARAMETER) boolean removeFormalCtTypeParameter(CtTypeParameter formalTypeParameter); } diff --git a/src/main/java/spoon/reflect/declaration/CtMethod.java b/src/main/java/spoon/reflect/declaration/CtMethod.java index 017311db147..2b2c6f08b1b 100644 --- a/src/main/java/spoon/reflect/declaration/CtMethod.java +++ b/src/main/java/spoon/reflect/declaration/CtMethod.java @@ -16,6 +16,12 @@ */ package spoon.reflect.declaration; +import spoon.reflect.annotations.PropertyGetter; +import spoon.reflect.annotations.PropertySetter; + +import static spoon.reflect.path.CtRole.IS_DEFAULT; + + /** * This element defines a method declaration. */ @@ -33,11 +39,13 @@ public interface CtMethod extends CtExecutable, CtTypeMember, CtFormalType * Checks if the method is a default method. Default method can be in interfaces from * Java 8: http://docs.oracle.com/javase/tutorial/java/IandI/defaultmethods.html. */ + @PropertyGetter(role = IS_DEFAULT) boolean isDefaultMethod(); /** * Sets the default value state of a method. */ + @PropertySetter(role = IS_DEFAULT) > C setDefaultMethod(boolean defaultMethod); /** diff --git a/src/main/java/spoon/reflect/declaration/CtModifiable.java b/src/main/java/spoon/reflect/declaration/CtModifiable.java index 0d4165b8076..9053509b7ab 100644 --- a/src/main/java/spoon/reflect/declaration/CtModifiable.java +++ b/src/main/java/spoon/reflect/declaration/CtModifiable.java @@ -16,8 +16,13 @@ */ package spoon.reflect.declaration; +import spoon.reflect.annotations.PropertyGetter; +import spoon.reflect.annotations.PropertySetter; + import java.util.Set; +import static spoon.reflect.path.CtRole.MODIFIER; + /** * This interface defines an element that accepts modifiers. */ @@ -30,6 +35,7 @@ public interface CtModifiable extends CtElement { * @return the modifiers of this declaration in undefined order; an empty * set if there are none */ + @PropertyGetter(role = MODIFIER) Set getModifiers(); /** @@ -44,6 +50,7 @@ public interface CtModifiable extends CtElement { /** * Sets the modifiers. */ + @PropertySetter(role = MODIFIER) T setModifiers(Set modifiers); /** @@ -52,6 +59,7 @@ public interface CtModifiable extends CtElement { * @param modifier * @return true if this element changed as a result of the call */ + @PropertySetter(role = MODIFIER) T addModifier(ModifierKind modifier); /** @@ -60,15 +68,18 @@ public interface CtModifiable extends CtElement { * @param modifier * @return true if this element changed as a result of the call */ + @PropertySetter(role = MODIFIER) boolean removeModifier(ModifierKind modifier); /** * Sets the visibility of this modifiable element (replaces old visibility). */ + @PropertySetter(role = MODIFIER) T setVisibility(ModifierKind visibility); /** * Gets the visibility of this modifiable element. */ + @PropertyGetter(role = MODIFIER) ModifierKind getVisibility(); } diff --git a/src/main/java/spoon/reflect/declaration/CtMultiTypedElement.java b/src/main/java/spoon/reflect/declaration/CtMultiTypedElement.java index e04a21601d9..a78ff54256a 100644 --- a/src/main/java/spoon/reflect/declaration/CtMultiTypedElement.java +++ b/src/main/java/spoon/reflect/declaration/CtMultiTypedElement.java @@ -17,9 +17,13 @@ package spoon.reflect.declaration; import spoon.reflect.reference.CtTypeReference; +import spoon.reflect.annotations.PropertyGetter; +import spoon.reflect.annotations.PropertySetter; import java.util.List; +import static spoon.reflect.path.CtRole.TYPE; + /** * Defined an element with several types. */ @@ -27,20 +31,24 @@ public interface CtMultiTypedElement extends CtElement { /** * Adds a type for the element. */ + @PropertySetter(role = TYPE) T addMultiType(CtTypeReference ref); /** * Removes a type for the element. */ + @PropertySetter(role = TYPE) boolean removeMultiType(CtTypeReference ref); /** * Gets all types of the element. */ + @PropertyGetter(role = TYPE) List> getMultiTypes(); /** * Adds a type for the element. */ + @PropertySetter(role = TYPE) T setMultiTypes(List> types); } diff --git a/src/main/java/spoon/reflect/declaration/CtNamedElement.java b/src/main/java/spoon/reflect/declaration/CtNamedElement.java index 045a00513f4..e59c5dcca94 100644 --- a/src/main/java/spoon/reflect/declaration/CtNamedElement.java +++ b/src/main/java/spoon/reflect/declaration/CtNamedElement.java @@ -18,6 +18,10 @@ import spoon.reflect.reference.CtReference; import spoon.support.DerivedProperty; +import spoon.reflect.annotations.PropertyGetter; +import spoon.reflect.annotations.PropertySetter; + +import static spoon.reflect.path.CtRole.NAME; /** * Declares an element that has a name (a class, a method, a variable, etc). @@ -29,11 +33,13 @@ public interface CtNamedElement extends CtElement { /** * Returns the simple (unqualified) name of this element. */ + @PropertyGetter(role = NAME) String getSimpleName(); /** * Sets the simple (unqualified) name of this element. */ + @PropertySetter(role = NAME) T setSimpleName(String simpleName); /** diff --git a/src/main/java/spoon/reflect/declaration/CtPackage.java b/src/main/java/spoon/reflect/declaration/CtPackage.java index b03ce6d3c76..f27216683a0 100644 --- a/src/main/java/spoon/reflect/declaration/CtPackage.java +++ b/src/main/java/spoon/reflect/declaration/CtPackage.java @@ -18,9 +18,14 @@ import spoon.reflect.reference.CtPackageReference; import spoon.support.DerivedProperty; +import spoon.reflect.annotations.PropertyGetter; +import spoon.reflect.annotations.PropertySetter; import java.util.Set; +import static spoon.reflect.path.CtRole.SUB_PACKAGE; +import static spoon.reflect.path.CtRole.TYPE; + /** * This element defines a package declaration. The packages are represented by a * tree. @@ -50,11 +55,13 @@ public interface CtPackage extends CtNamedElement, CtShadowable { * the simple name of searched package * @return the found package or null */ + @PropertyGetter(role = SUB_PACKAGE) CtPackage getPackage(String name); /** * Gets the set of included child packages. */ + @PropertyGetter(role = SUB_PACKAGE) Set getPackages(); /** @@ -84,6 +91,7 @@ public interface CtPackage extends CtNamedElement, CtShadowable { /** * Returns the set of the top-level types in this package. */ + @PropertyGetter(role = TYPE) Set> getTypes(); /** @@ -102,6 +110,7 @@ public interface CtPackage extends CtNamedElement, CtShadowable { * @param pack * new set of child packages */ + @PropertySetter(role = SUB_PACKAGE) T setPackages(Set pack); /** @@ -110,6 +119,7 @@ public interface CtPackage extends CtNamedElement, CtShadowable { * @param pack * @return true if this element changed as a result of the call */ + @PropertySetter(role = SUB_PACKAGE) T addPackage(CtPackage pack); /** @@ -126,6 +136,7 @@ public interface CtPackage extends CtNamedElement, CtShadowable { * @param types * new Set of types */ + @PropertyGetter(role = TYPE) T setTypes(Set> types); @Override diff --git a/src/main/java/spoon/reflect/declaration/CtParameter.java b/src/main/java/spoon/reflect/declaration/CtParameter.java index 672ec32548f..d4fbaf5fb36 100644 --- a/src/main/java/spoon/reflect/declaration/CtParameter.java +++ b/src/main/java/spoon/reflect/declaration/CtParameter.java @@ -19,8 +19,12 @@ import spoon.reflect.code.CtExpression; import spoon.reflect.reference.CtParameterReference; import spoon.support.DerivedProperty; +import spoon.reflect.annotations.PropertyGetter; +import spoon.reflect.annotations.PropertySetter; import spoon.support.UnsettableProperty; +import static spoon.reflect.path.CtRole.IS_VARARGS; + /** * This element defines an executable parameter declaration. * @@ -43,11 +47,13 @@ public interface CtParameter extends CtVariable, CtShadowable { * arguments (must be the last parameter of * {@link CtExecutable#getParameters()}). */ + @PropertyGetter(role = IS_VARARGS) boolean isVarArgs(); /** * Sets this parameter to have varargs. */ + @PropertySetter(role = IS_VARARGS) > C setVarArgs(boolean varArgs); /** overriding the return type */ diff --git a/src/main/java/spoon/reflect/declaration/CtShadowable.java b/src/main/java/spoon/reflect/declaration/CtShadowable.java index c06025bb597..c3a5ae97dfe 100644 --- a/src/main/java/spoon/reflect/declaration/CtShadowable.java +++ b/src/main/java/spoon/reflect/declaration/CtShadowable.java @@ -17,6 +17,10 @@ package spoon.reflect.declaration; import spoon.reflect.reference.CtTypeReference; +import spoon.reflect.annotations.PropertyGetter; +import spoon.reflect.annotations.PropertySetter; + +import static spoon.reflect.path.CtRole.IS_SHADOW; /** A shadow element is an element that is in the Spoon model, but does not exist in the actual source code. * The goal of shadow elements is to simplify transformations. @@ -30,11 +34,13 @@ public interface CtShadowable { * * @return true if the element is a shadow element, otherwise false. */ + @PropertyGetter(role = IS_SHADOW) boolean isShadow(); /** * Marks an element as shadow. To know what is a shadow element, see the javadoc of * {@link #isShadow()}. */ + @PropertySetter(role = IS_SHADOW) E setShadow(boolean isShadow); } diff --git a/src/main/java/spoon/reflect/declaration/CtType.java b/src/main/java/spoon/reflect/declaration/CtType.java index bc38412a483..dc418768528 100644 --- a/src/main/java/spoon/reflect/declaration/CtType.java +++ b/src/main/java/spoon/reflect/declaration/CtType.java @@ -18,10 +18,19 @@ import spoon.reflect.reference.CtTypeReference; import spoon.support.DerivedProperty; +import spoon.reflect.annotations.PropertyGetter; +import spoon.reflect.annotations.PropertySetter; import java.util.List; import java.util.Set; +import static spoon.reflect.path.CtRole.EXECUTABLE; +import static spoon.reflect.path.CtRole.FIELD; +import static spoon.reflect.path.CtRole.INTERFACE; +import static spoon.reflect.path.CtRole.NAME; +import static spoon.reflect.path.CtRole.NESTED_TYPE; +import static spoon.reflect.path.CtRole.SUPER_TYPE; + /** * This abstract element defines a super-type for classes and interfaces, which * can declare methods. @@ -44,6 +53,7 @@ public interface CtType extends CtNamedElement, CtTypeInformation, CtTypeMemb * the name starts with a numeric prefix (e.g. local class Foo has simple name 1Foo). */ @Override + @PropertyGetter(role = NAME) String getSimpleName(); /** @@ -60,6 +70,7 @@ public interface CtType extends CtNamedElement, CtTypeInformation, CtTypeMemb * * @return the runtime class, null if is not accessible or does not exist */ + @DerivedProperty Class getActualClass(); /** @@ -67,6 +78,7 @@ public interface CtType extends CtNamedElement, CtTypeInformation, CtTypeMemb * * @return null if does not exit */ + @PropertyGetter(role = FIELD) CtField getField(String name); /** @@ -76,11 +88,13 @@ public interface CtType extends CtNamedElement, CtTypeInformation, CtTypeMemb * Derived from {@link #getTypeMembers()} */ @DerivedProperty + @PropertyGetter(role = FIELD) List> getFields(); /** * Gets a nested type from its name. */ + @PropertyGetter(role = NESTED_TYPE) > N getNestedType(String name); /** @@ -88,6 +102,7 @@ public interface CtType extends CtNamedElement, CtTypeInformation, CtTypeMemb * directly declared by this class or interface. */ @DerivedProperty + @PropertyGetter(role = NESTED_TYPE) Set> getNestedTypes(); /** @@ -117,6 +132,7 @@ public interface CtType extends CtNamedElement, CtTypeInformation, CtTypeMemb * @param field * @return true if the field is added. */ + @PropertySetter(role = FIELD) > C addFieldAtTop(CtField field); /** @@ -125,6 +141,7 @@ public interface CtType extends CtNamedElement, CtTypeInformation, CtTypeMemb * @param field * @return true if this element changed as a result of the call */ + @PropertySetter(role = FIELD) > C addField(CtField field); /** @@ -133,11 +150,13 @@ public interface CtType extends CtNamedElement, CtTypeInformation, CtTypeMemb * @param field * @return true if this element changed as a result of the call */ + @PropertySetter(role = FIELD) > C addField(int index, CtField field); /** * Sets all fields in the type. */ + @PropertySetter(role = FIELD) > C setFields(List> fields); /** @@ -146,6 +165,7 @@ public interface CtType extends CtNamedElement, CtTypeInformation, CtTypeMemb * @param field * @return true if this element changed as a result of the call */ + @PropertySetter(role = FIELD) boolean removeField(CtField field); /** @@ -154,6 +174,7 @@ public interface CtType extends CtNamedElement, CtTypeInformation, CtTypeMemb * @param nestedType * @return true if this element changed as a result of the call */ + @PropertySetter(role = NESTED_TYPE) > C addNestedType(CtType nestedType); /** @@ -162,11 +183,13 @@ public interface CtType extends CtNamedElement, CtTypeInformation, CtTypeMemb * @param nestedType * @return true if this element changed as a result of the call */ + @PropertySetter(role = NESTED_TYPE) boolean removeNestedType(CtType nestedType); /** * Sets all nested types. */ + @PropertySetter(role = NESTED_TYPE) > C setNestedTypes(Set> nestedTypes); /** @@ -196,6 +219,7 @@ public interface CtType extends CtNamedElement, CtTypeInformation, CtTypeMemb * * @return null if does not exit */ + @PropertyGetter(role = EXECUTABLE) CtMethod getMethod(CtTypeReference returnType, String name, CtTypeReference... parameterTypes); /** @@ -203,6 +227,7 @@ public interface CtType extends CtNamedElement, CtTypeInformation, CtTypeMemb * * @return null if does not exit */ + @PropertyGetter(role = EXECUTABLE) CtMethod getMethod(String name, CtTypeReference... parameterTypes); /** @@ -213,18 +238,21 @@ public interface CtType extends CtNamedElement, CtTypeInformation, CtTypeMemb * */ @DerivedProperty + @PropertyGetter(role = EXECUTABLE) Set> getMethods(); /** * Returns the methods that are directly declared by this class or * interface and annotated with one of the given annotations. */ + @PropertyGetter(role = EXECUTABLE) Set> getMethodsAnnotatedWith(CtTypeReference... annotationTypes); /** * Returns the methods that are directly declared by this class or * interface and that have the given name. */ + @PropertyGetter(role = EXECUTABLE) List> getMethodsByName(String name); /** @@ -239,38 +267,45 @@ public interface CtType extends CtNamedElement, CtTypeInformation, CtTypeMemb /** * Sets the methods of this type. */ + @PropertySetter(role = EXECUTABLE) > C setMethods(Set> methods); /** * Adds a method to this type. */ + @PropertySetter(role = EXECUTABLE) > C addMethod(CtMethod method); /** * Removes a method from this type. */ + @PropertySetter(role = EXECUTABLE) boolean removeMethod(CtMethod method); /** * Sets the superclass type. */ + @PropertySetter(role = SUPER_TYPE) > C setSuperclass(CtTypeReference superClass); /** * Sets the super interfaces of this type. */ + @PropertySetter(role = INTERFACE) > C setSuperInterfaces(Set> interfaces); /** * @param interfac * @return true if this element changed as a result of the call */ + @PropertySetter(role = INTERFACE) > C addSuperInterface(CtTypeReference interfac); /** * @param interfac * @return true if this element changed as a result of the call */ + @PropertySetter(role = INTERFACE) boolean removeSuperInterface(CtTypeReference interfac); /** diff --git a/src/main/java/spoon/reflect/declaration/CtTypeInformation.java b/src/main/java/spoon/reflect/declaration/CtTypeInformation.java index dd7f1a3dbc9..b1ff0abfbd8 100644 --- a/src/main/java/spoon/reflect/declaration/CtTypeInformation.java +++ b/src/main/java/spoon/reflect/declaration/CtTypeInformation.java @@ -20,10 +20,15 @@ import spoon.reflect.reference.CtFieldReference; import spoon.reflect.reference.CtTypeReference; import spoon.support.DerivedProperty; +import spoon.reflect.annotations.PropertyGetter; import java.util.Collection; import java.util.Set; +import static spoon.reflect.path.CtRole.INTERFACE; +import static spoon.reflect.path.CtRole.MODIFIER; +import static spoon.reflect.path.CtRole.SUPER_TYPE; + /** * Returns information that can be obtained both at compile-time and run-time * @@ -37,16 +42,19 @@ public interface CtTypeInformation { * Returns the interface types directly implemented by this class or * extended by this interface. */ + @PropertyGetter(role = INTERFACE) Set> getSuperInterfaces(); /** * Returns the fully qualified name of this type declaration. */ + @DerivedProperty String getQualifiedName(); /** * Gets modifiers of this type. */ + @PropertyGetter(role = MODIFIER) Set getModifiers(); /** @@ -120,6 +128,7 @@ public interface CtTypeInformation { * @return the class type directly extended by this class, or null if there * is none */ + @PropertyGetter(role = SUPER_TYPE) CtTypeReference getSuperclass(); /** diff --git a/src/main/java/spoon/reflect/declaration/CtTypedElement.java b/src/main/java/spoon/reflect/declaration/CtTypedElement.java index 8537dc08d12..1d48b5e7f60 100644 --- a/src/main/java/spoon/reflect/declaration/CtTypedElement.java +++ b/src/main/java/spoon/reflect/declaration/CtTypedElement.java @@ -17,6 +17,10 @@ package spoon.reflect.declaration; import spoon.reflect.reference.CtTypeReference; +import spoon.reflect.annotations.PropertyGetter; +import spoon.reflect.annotations.PropertySetter; + +import static spoon.reflect.path.CtRole.TYPE; /** * This abstract element defines a typed element. @@ -25,10 +29,12 @@ public interface CtTypedElement extends CtElement { /** * Gets this element's type. */ + @PropertyGetter(role = TYPE) CtTypeReference getType(); /** * Sets this element's type. */ + @PropertySetter(role = TYPE) C setType(CtTypeReference type); } diff --git a/src/main/java/spoon/reflect/declaration/CtVariable.java b/src/main/java/spoon/reflect/declaration/CtVariable.java index 69e4291a942..58729c58d8c 100644 --- a/src/main/java/spoon/reflect/declaration/CtVariable.java +++ b/src/main/java/spoon/reflect/declaration/CtVariable.java @@ -19,6 +19,10 @@ import spoon.reflect.code.CtExpression; import spoon.reflect.reference.CtVariableReference; import spoon.support.DerivedProperty; +import spoon.reflect.annotations.PropertyGetter; +import spoon.reflect.annotations.PropertySetter; + +import static spoon.reflect.path.CtRole.DEFAULT_EXPRESSION; /** * This abstract element defines a variable declaration. @@ -28,6 +32,7 @@ public interface CtVariable extends CtNamedElement, CtTypedElement, CtModi * Gets the initialization expression assigned to the variable (also known * as the initializer), when declared. */ + @PropertyGetter(role = DEFAULT_EXPRESSION) CtExpression getDefaultExpression(); /* @@ -42,5 +47,6 @@ public interface CtVariable extends CtNamedElement, CtTypedElement, CtModi * Sets the initialization expression assigned to the variable, when * declared. */ + @PropertySetter(role = DEFAULT_EXPRESSION) > C setDefaultExpression(CtExpression assignedExpression); } diff --git a/src/main/java/spoon/reflect/path/CtRole.java b/src/main/java/spoon/reflect/path/CtRole.java index c1617fbeb29..1d0896ce2c0 100644 --- a/src/main/java/spoon/reflect/path/CtRole.java +++ b/src/main/java/spoon/reflect/path/CtRole.java @@ -20,61 +20,59 @@ * Created by nicolas on 27/08/2015. */ public enum CtRole { - PARENT, NAME, - DECLARING_TYPE, TYPE, BODY, - IS_FINAL, IS_SHADOW, - IS_STATIC, + //BOUND, // in reference only + //IS_FINAL, // in reference only + //IS_STATIC, // in reference only + //IS_UPPER, // in reference only IS_IMPLICIT, IS_DEFAULT, IS_VARARGS, - IS_UPPER, DEFAULT_EXPRESSION, THEN, ELSE, - PACKAGE, + SUB_PACKAGE, CONDITION, - SUPER_TYPE, - POSITION, RIGHT_OPERAND, LEFT_OPERAND, LABEL, CASE, - KIND, + OPERATOR_KIND, PARAMETER, EXPRESSION, TARGET, - OPERAND, VARIABLE, FINALIZER, - THROW, - EXECUTABLE, + THROWN, ASSIGNMENT, ASSIGNED, - MODIFIERS, - COMMENTS, - TYPES, - INTERFACES, - ANNOTATIONS, - STATEMENTS, - ARGUMENTS, - MEMBERS, - CASTS, - VALUES, + MODIFIER, + COMMENT, + ANNOTATION_TYPE, + INTERFACE, + ANNOTATION, + STATEMENT, + ARGUMENT, + SUPER_TYPE, + NESTED_TYPE, + CONSTRUCTOR, + EXECUTABLE, + FIELD, + CAST, + VALUE, FOR_UPDATE, FOR_INIT, - RESOURCES, - DIMENSIONS, - BOUNDS, - CATCHERS, - ANONYMOUS_CLASS, + TRY_RESOURCE, + DIMENSION, + CATCH, TARGET_LABEL, - TYPE_PARAMETERS, - CONTENT, - TAGS; + TYPE_PARAMETER, + COMMENT_TAG, + COMMENT_CONTENT, + COMMENT_TYPE; /** * Get the {@link CtRole} associated to the field name @@ -92,12 +90,6 @@ public static CtRole fromName(String name) { if ("implicit".equals(name)) { return IS_IMPLICIT; } - if ("fina".equals(name)) { - return IS_FINAL; - } - if ("stat".equals(name)) { - return IS_STATIC; - } if ("varargs".equals(name)) { return IS_VARARGS; } @@ -111,16 +103,16 @@ public static CtRole fromName(String name) { return PARAMETER; } if ("dimensionexpressions".equals(name)) { - return DIMENSIONS; + return DIMENSION; } if ("actualtypearguments".equals(name)) { - return TYPE_PARAMETERS; + return TYPE_PARAMETER; } if ("formalcttypeparameters".equals(name)) { - return TYPE_PARAMETERS; + return TYPE_PARAMETER; } if ("typecasts".equals(name)) { - return CASTS; + return CAST; } if ("cases".equals(name)) { return CASE; @@ -129,10 +121,10 @@ public static CtRole fromName(String name) { return LABEL; } if ("enumvalues".equals(name) || "elementvalues".equals(name)) { - return VALUES; + return VALUE; } if ("throwntypes".equals(name)) { - return THROW; + return THROWN; } if ("value".equals(name) || "returnedexpression".equals(name) || "expressions".equals(name)) { return EXPRESSION; @@ -144,14 +136,13 @@ public static CtRole fromName(String name) { return PARAMETER; } if ("typemembers".equals(name)) { - return MEMBERS; + return FIELD; } if ("throwexpression".equals(name)) { - return THROW; + return THROWN; } if ("returntype".equals(name) - || "componenttype".equals(name) - || "annotationtype".equals(name)) { + || "componenttype".equals(name)) { return TYPE; } if ("caseexpression".equals(name)) { @@ -170,7 +161,7 @@ public static CtRole fromName(String name) { return LEFT_OPERAND; } if ("pack".equals(name) || "packs".equals(name)) { - return PACKAGE; + return SUB_PACKAGE; } if ("superclass".equals(name)) { return SUPER_TYPE; diff --git a/src/main/java/spoon/reflect/reference/CtActualTypeContainer.java b/src/main/java/spoon/reflect/reference/CtActualTypeContainer.java index 057ae7d8e04..4af4c92193a 100644 --- a/src/main/java/spoon/reflect/reference/CtActualTypeContainer.java +++ b/src/main/java/spoon/reflect/reference/CtActualTypeContainer.java @@ -16,8 +16,10 @@ */ package spoon.reflect.reference; + import java.util.List; + /** * This interface defines the capability related to binding generics (aka type parameters). */ diff --git a/src/main/java/spoon/reflect/reference/CtArrayTypeReference.java b/src/main/java/spoon/reflect/reference/CtArrayTypeReference.java index 71c41178be2..4cd27901977 100644 --- a/src/main/java/spoon/reflect/reference/CtArrayTypeReference.java +++ b/src/main/java/spoon/reflect/reference/CtArrayTypeReference.java @@ -18,6 +18,7 @@ import spoon.support.DerivedProperty; + /** * This interface defines a reference to an array. */ @@ -48,6 +49,7 @@ public interface CtArrayTypeReference extends CtTypeReference { * the number of array types recursively embedded into the current one (see * {@link #getComponentType()}). */ + @DerivedProperty int getDimensionCount(); /** diff --git a/src/main/java/spoon/reflect/reference/CtExecutableReference.java b/src/main/java/spoon/reflect/reference/CtExecutableReference.java index d8c9b500d22..575a1d03f5d 100644 --- a/src/main/java/spoon/reflect/reference/CtExecutableReference.java +++ b/src/main/java/spoon/reflect/reference/CtExecutableReference.java @@ -23,6 +23,7 @@ import java.lang.reflect.Method; import java.util.List; + /** * This interface defines a reference to a * {@link spoon.reflect.declaration.CtExecutable}. It can be a diff --git a/src/main/java/spoon/reflect/reference/CtFieldReference.java b/src/main/java/spoon/reflect/reference/CtFieldReference.java index 417bc44ba57..44c179f1980 100644 --- a/src/main/java/spoon/reflect/reference/CtFieldReference.java +++ b/src/main/java/spoon/reflect/reference/CtFieldReference.java @@ -21,6 +21,7 @@ import java.lang.reflect.Member; + /** * This interface defines a reference to a * {@link spoon.reflect.declaration.CtField}. diff --git a/src/main/java/spoon/reflect/reference/CtIntersectionTypeReference.java b/src/main/java/spoon/reflect/reference/CtIntersectionTypeReference.java index d22f843bd02..096f68114c0 100644 --- a/src/main/java/spoon/reflect/reference/CtIntersectionTypeReference.java +++ b/src/main/java/spoon/reflect/reference/CtIntersectionTypeReference.java @@ -20,6 +20,7 @@ import java.util.List; + /** * This interface defines a reference to an intersection type in generics or in casts. */ diff --git a/src/main/java/spoon/reflect/reference/CtParameterReference.java b/src/main/java/spoon/reflect/reference/CtParameterReference.java index bb9f5197de2..2068355e223 100644 --- a/src/main/java/spoon/reflect/reference/CtParameterReference.java +++ b/src/main/java/spoon/reflect/reference/CtParameterReference.java @@ -19,6 +19,7 @@ import spoon.reflect.declaration.CtParameter; import spoon.support.DerivedProperty; + /** * This interface defines a reference to a * {@link spoon.reflect.declaration.CtParameter}. diff --git a/src/main/java/spoon/reflect/reference/CtReference.java b/src/main/java/spoon/reflect/reference/CtReference.java index f11da283755..8aaec7d6a99 100644 --- a/src/main/java/spoon/reflect/reference/CtReference.java +++ b/src/main/java/spoon/reflect/reference/CtReference.java @@ -23,6 +23,7 @@ import java.util.List; + /** * This is the root interface for named program element references. References * can point to program element built in the model or not. In the latter case, diff --git a/src/main/java/spoon/reflect/reference/CtTypeParameterReference.java b/src/main/java/spoon/reflect/reference/CtTypeParameterReference.java index 7f645b0396a..219d02437ca 100644 --- a/src/main/java/spoon/reflect/reference/CtTypeParameterReference.java +++ b/src/main/java/spoon/reflect/reference/CtTypeParameterReference.java @@ -22,6 +22,7 @@ import java.util.List; + /** * This interface defines a reference to a type parameter (aka generics). */ diff --git a/src/main/java/spoon/reflect/reference/CtTypeReference.java b/src/main/java/spoon/reflect/reference/CtTypeReference.java index 6fc9d3d33eb..306a6f50eed 100644 --- a/src/main/java/spoon/reflect/reference/CtTypeReference.java +++ b/src/main/java/spoon/reflect/reference/CtTypeReference.java @@ -26,6 +26,7 @@ import java.util.Set; + /** * This interface defines a reference to a * {@link spoon.reflect.declaration.CtType} or sub-type. diff --git a/src/main/java/spoon/reflect/reference/CtVariableReference.java b/src/main/java/spoon/reflect/reference/CtVariableReference.java index ea4e383a779..013a0f51e27 100644 --- a/src/main/java/spoon/reflect/reference/CtVariableReference.java +++ b/src/main/java/spoon/reflect/reference/CtVariableReference.java @@ -22,6 +22,7 @@ import java.util.Set; + /** * This interface defines a reference to a * {@link spoon.reflect.declaration.CtVariable} or sub-type. diff --git a/src/test/java/spoon/test/api/MetamodelTest.java b/src/test/java/spoon/test/api/MetamodelTest.java new file mode 100644 index 00000000000..13f106ef6a0 --- /dev/null +++ b/src/test/java/spoon/test/api/MetamodelTest.java @@ -0,0 +1,49 @@ +package spoon.test.api; + +import org.junit.Assert; +import org.junit.Test; +import spoon.Launcher; +import spoon.SpoonAPI; +import spoon.reflect.code.CtFieldRead; +import spoon.reflect.declaration.CtMethod; +import spoon.reflect.factory.Factory; +import spoon.reflect.path.CtRole; +import spoon.reflect.reference.CtTypeReference; +import spoon.reflect.visitor.filter.AnnotationFilter; +import spoon.reflect.annotations.PropertyGetter; +import spoon.reflect.annotations.PropertySetter; + +import java.util.Arrays; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; + +public class MetamodelTest { + + @Test + public void testGetterSetterFroRole() { + // contract: all roles in spoon metamodel must at least have a setter and a getter + + SpoonAPI interfaces = new Launcher(); + interfaces.addInputResource("src/main/java/spoon/reflect/declaration"); + interfaces.addInputResource("src/main/java/spoon/reflect/code"); + interfaces.addInputResource("src/main/java/spoon/reflect/reference"); + interfaces.buildModel(); + + Factory factory = interfaces.getFactory(); + CtTypeReference propertyGetter = factory.Type().get(PropertyGetter.class).getReference(); + CtTypeReference propertySetter = factory.Type().get(PropertySetter.class).getReference(); + + Set expectedRoles = Arrays.stream(CtRole.values()).map(r -> r.name()).collect(Collectors.toSet()); + + List getters = interfaces.getModel().getElements(new AnnotationFilter(PropertyGetter.class)); + Set getterRoles = getters.stream().map(g -> ((CtFieldRead)g.getAnnotation(propertyGetter).getValue("role")).getVariable().getSimpleName()).collect(Collectors.toSet()); + + List setters = interfaces.getModel().getElements(new AnnotationFilter(PropertySetter.class)); + Set setterRoles = setters.stream().map(g -> ((CtFieldRead)g.getAnnotation(propertySetter).getValue("role")).getVariable().getSimpleName()).collect(Collectors.toSet()); + + + Assert.assertEquals(expectedRoles, getterRoles); + Assert.assertEquals(expectedRoles, setterRoles); + } +}