Skip to content

Commit

Permalink
feat(role): add role annotation on implementation fields
Browse files Browse the repository at this point in the history
  • Loading branch information
tdurieux committed Jun 9, 2017
1 parent 841edfc commit 40c3ef8
Show file tree
Hide file tree
Showing 62 changed files with 294 additions and 7 deletions.
37 changes: 37 additions & 0 deletions src/main/java/spoon/support/MetamodelPropertyField.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* 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.support;

import spoon.reflect.declaration.CtClass;
import spoon.reflect.declaration.CtNamedElement;
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;

/**
* Tells that a field is a property of the metamodel
* For instance {@link CtClass#name} is the property name of {@link CtNamedElement}
*
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.FIELD })
public @interface MetamodelPropertyField {
CtRole role();
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@

import spoon.reflect.code.CtArrayAccess;
import spoon.reflect.code.CtExpression;
import spoon.reflect.path.CtRole;
import spoon.support.MetamodelPropertyField;

public abstract class CtArrayAccessImpl<T, V extends CtExpression<?>> extends CtTargetedExpressionImpl<T, V> implements CtArrayAccess<T, V> {
private static final long serialVersionUID = 1L;

@MetamodelPropertyField(role = CtRole.EXPRESSION)
private CtExpression<Integer> expression;

@Override
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/spoon/support/reflect/code/CtAssertImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,17 @@

import spoon.reflect.code.CtAssert;
import spoon.reflect.code.CtExpression;
import spoon.reflect.path.CtRole;
import spoon.reflect.visitor.CtVisitor;
import spoon.support.MetamodelPropertyField;

public class CtAssertImpl<T> extends CtStatementImpl implements CtAssert<T> {
private static final long serialVersionUID = 1L;

@MetamodelPropertyField(role = CtRole.CONDITION)
CtExpression<Boolean> asserted;

@MetamodelPropertyField(role = CtRole.VALUE)
CtExpression<T> value;

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@
import spoon.reflect.code.CtRHSReceiver;
import spoon.reflect.declaration.CtElement;
import spoon.reflect.declaration.CtTypedElement;
import spoon.reflect.path.CtRole;
import spoon.reflect.reference.CtTypeReference;
import spoon.reflect.visitor.CtVisitor;
import spoon.support.MetamodelPropertyField;
import spoon.support.reflect.declaration.CtElementImpl;

import java.util.ArrayList;
Expand All @@ -33,12 +35,16 @@
public class CtAssignmentImpl<T, A extends T> extends CtStatementImpl implements CtAssignment<T, A> {
private static final long serialVersionUID = 1L;

@MetamodelPropertyField(role = CtRole.ASSIGNED)
CtExpression<T> assigned;

@MetamodelPropertyField(role = CtRole.ASSIGNMENT)
CtExpression<A> assignment;

@MetamodelPropertyField(role = CtRole.TYPE)
CtTypeReference<T> type;

@MetamodelPropertyField(role = CtRole.CAST)
List<CtTypeReference<?>> typeCasts = emptyList();

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,20 @@
import spoon.reflect.code.BinaryOperatorKind;
import spoon.reflect.code.CtBinaryOperator;
import spoon.reflect.code.CtExpression;
import spoon.reflect.path.CtRole;
import spoon.reflect.visitor.CtVisitor;
import spoon.support.MetamodelPropertyField;

public class CtBinaryOperatorImpl<T> extends CtExpressionImpl<T> implements CtBinaryOperator<T> {
private static final long serialVersionUID = 1L;

@MetamodelPropertyField(role = CtRole.OPERATOR_KIND)
BinaryOperatorKind kind;

@MetamodelPropertyField(role = CtRole.LEFT_OPERAND)
CtExpression<?> leftHandOperand;

@MetamodelPropertyField(role = CtRole.RIGHT_OPERAND)
CtExpression<?> rightHandOperand;

@Override
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/spoon/support/reflect/code/CtBlockImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@
import spoon.reflect.declaration.CtConstructor;
import spoon.reflect.declaration.CtElement;
import spoon.reflect.declaration.ParentNotInitializedException;
import spoon.reflect.path.CtRole;
import spoon.reflect.visitor.CtVisitor;
import spoon.reflect.visitor.Filter;
import spoon.reflect.visitor.Query;
import spoon.support.MetamodelPropertyField;
import spoon.support.reflect.declaration.CtElementImpl;
import spoon.support.util.EmptyIterator;

Expand All @@ -39,6 +41,7 @@
public class CtBlockImpl<R> extends CtStatementImpl implements CtBlock<R> {
private static final long serialVersionUID = 1L;

@MetamodelPropertyField(role = CtRole.STATEMENT)
private List<CtStatement> statements = emptyList();

public void accept(CtVisitor visitor) {
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/spoon/support/reflect/code/CtBreakImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@
package spoon.support.reflect.code;

import spoon.reflect.code.CtBreak;
import spoon.reflect.path.CtRole;
import spoon.reflect.visitor.CtVisitor;
import spoon.support.MetamodelPropertyField;

public class CtBreakImpl extends CtStatementImpl implements CtBreak {
private static final long serialVersionUID = 1L;

@MetamodelPropertyField(role = CtRole.TARGET_LABEL)
String targetLabel;

@Override
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/spoon/support/reflect/code/CtCaseImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
import spoon.reflect.code.CtExpression;
import spoon.reflect.code.CtStatement;
import spoon.reflect.code.CtStatementList;
import spoon.reflect.path.CtRole;
import spoon.reflect.visitor.CtVisitor;
import spoon.support.MetamodelPropertyField;
import spoon.support.reflect.declaration.CtElementImpl;

import java.util.ArrayList;
Expand All @@ -32,8 +34,10 @@
public class CtCaseImpl<E> extends CtStatementImpl implements CtCase<E> {
private static final long serialVersionUID = 1L;

@MetamodelPropertyField(role = CtRole.CASE)
CtExpression<E> caseExpression;

@MetamodelPropertyField(role = CtRole.STATEMENT)
List<CtStatement> statements = emptyList();

@Override
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/spoon/support/reflect/code/CtCatchImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,17 @@
import spoon.reflect.code.CtCatch;
import spoon.reflect.code.CtCatchVariable;
import spoon.reflect.code.CtStatement;
import spoon.reflect.path.CtRole;
import spoon.reflect.visitor.CtVisitor;
import spoon.support.MetamodelPropertyField;

public class CtCatchImpl extends CtCodeElementImpl implements CtCatch {
private static final long serialVersionUID = 1L;

@MetamodelPropertyField(role = CtRole.BODY)
CtBlock<?> body;

@MetamodelPropertyField(role = CtRole.PARAMETER)
CtCatchVariable<? extends Throwable> parameter;

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@
import spoon.reflect.declaration.CtTypedElement;
import spoon.reflect.declaration.CtVariable;
import spoon.reflect.declaration.ModifierKind;
import spoon.reflect.path.CtRole;
import spoon.reflect.reference.CtCatchVariableReference;
import spoon.reflect.reference.CtTypeReference;
import spoon.reflect.visitor.CtVisitor;
import spoon.support.DerivedProperty;
import spoon.support.MetamodelPropertyField;
import spoon.support.UnsettableProperty;
import spoon.support.reflect.declaration.CtElementImpl;

Expand All @@ -41,12 +43,16 @@
public class CtCatchVariableImpl<T> extends CtCodeElementImpl implements CtCatchVariable<T> {
private static final long serialVersionUID = 1L;

@MetamodelPropertyField(role = CtRole.NAME)
String name = "";

@MetamodelPropertyField(role = CtRole.TYPE)
CtTypeReference<T> type;

@MetamodelPropertyField(role = CtRole.TYPE)
List<CtTypeReference<?>> types = emptyList();

@MetamodelPropertyField(role = CtRole.MODIFIER)
Set<ModifierKind> modifiers = CtElementImpl.emptySet();

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
import spoon.reflect.code.CtCodeSnippetExpression;
import spoon.reflect.code.CtExpression;
import spoon.reflect.declaration.CtCodeSnippet;
import spoon.reflect.path.CtRole;
import spoon.reflect.visitor.CtVisitor;
import spoon.support.MetamodelPropertyField;
import spoon.support.compiler.SnippetCompilationError;
import spoon.support.compiler.SnippetCompilationHelper;

Expand All @@ -31,6 +33,7 @@ public void accept(CtVisitor visitor) {
visitor.visitCtCodeSnippetExpression(this);
}

@MetamodelPropertyField(role = CtRole.VALUE)
String value;

public String getValue() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
import spoon.reflect.code.CtCodeSnippetStatement;
import spoon.reflect.code.CtStatement;
import spoon.reflect.declaration.CtCodeSnippet;
import spoon.reflect.path.CtRole;
import spoon.reflect.visitor.CtVisitor;
import spoon.support.MetamodelPropertyField;
import spoon.support.compiler.SnippetCompilationError;
import spoon.support.compiler.SnippetCompilationHelper;

Expand All @@ -31,6 +33,7 @@ public void accept(CtVisitor visitor) {
visitor.visitCtCodeSnippetStatement(this);
}

@MetamodelPropertyField(role = CtRole.VALUE)
String value;

public String getValue() {
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/spoon/support/reflect/code/CtCommentImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,17 @@
package spoon.support.reflect.code;

import spoon.reflect.code.CtComment;
import spoon.reflect.path.CtRole;
import spoon.reflect.visitor.CtVisitor;
import spoon.support.MetamodelPropertyField;

public class CtCommentImpl extends CtStatementImpl implements CtComment {
private static final long serialVersionUID = 1L;

@MetamodelPropertyField(role = CtRole.COMMENT_CONTENT)
private String content;

@MetamodelPropertyField(role = CtRole.TYPE)
private CommentType type;

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,20 @@

import spoon.reflect.code.CtConditional;
import spoon.reflect.code.CtExpression;
import spoon.reflect.path.CtRole;
import spoon.reflect.visitor.CtVisitor;
import spoon.support.MetamodelPropertyField;

public class CtConditionalImpl<T> extends CtExpressionImpl<T> implements CtConditional<T> {
private static final long serialVersionUID = 1L;

@MetamodelPropertyField(role = CtRole.ELSE)
CtExpression<T> elseExpression;

@MetamodelPropertyField(role = CtRole.CONDITION)
CtExpression<Boolean> condition;

@MetamodelPropertyField(role = CtRole.THEN)
CtExpression<T> thenExpression;

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@
import spoon.reflect.code.CtStatementList;
import spoon.reflect.declaration.CtElement;
import spoon.reflect.declaration.CtTypedElement;
import spoon.reflect.path.CtRole;
import spoon.reflect.reference.CtActualTypeContainer;
import spoon.reflect.reference.CtExecutableReference;
import spoon.reflect.reference.CtTypeReference;
import spoon.reflect.visitor.CtVisitor;
import spoon.support.MetamodelPropertyField;
import spoon.support.reflect.declaration.CtElementImpl;

import java.util.ArrayList;
Expand All @@ -37,8 +39,11 @@
public class CtConstructorCallImpl<T> extends CtTargetedExpressionImpl<T, CtExpression<?>> implements CtConstructorCall<T> {
private static final long serialVersionUID = 1L;

@MetamodelPropertyField(role = CtRole.ARGUMENT)
List<CtExpression<?>> arguments = emptyList();
@MetamodelPropertyField(role = CtRole.EXECUTABLE)
CtExecutableReference<T> executable;
@MetamodelPropertyField(role = CtRole.LABEL)
String label;

@Override
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/spoon/support/reflect/code/CtContinueImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,17 @@

import spoon.reflect.code.CtContinue;
import spoon.reflect.code.CtStatement;
import spoon.reflect.path.CtRole;
import spoon.reflect.visitor.CtVisitor;
import spoon.support.MetamodelPropertyField;

public class CtContinueImpl extends CtStatementImpl implements CtContinue {
private static final long serialVersionUID = 1L;

@MetamodelPropertyField(role = CtRole.LABEL)
CtStatement labelledStatement;

@MetamodelPropertyField(role = CtRole.TARGET_LABEL)
String targetLabel;

@Override
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/spoon/support/reflect/code/CtDoImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@

import spoon.reflect.code.CtDo;
import spoon.reflect.code.CtExpression;
import spoon.reflect.path.CtRole;
import spoon.reflect.visitor.CtVisitor;
import spoon.support.MetamodelPropertyField;

public class CtDoImpl extends CtLoopImpl implements CtDo {
private static final long serialVersionUID = 1L;

@MetamodelPropertyField(role = CtRole.EXPRESSION)
CtExpression<Boolean> expression;

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@

import spoon.reflect.code.CtExecutableReferenceExpression;
import spoon.reflect.code.CtExpression;
import spoon.reflect.path.CtRole;
import spoon.reflect.reference.CtExecutableReference;
import spoon.reflect.visitor.CtVisitor;
import spoon.support.MetamodelPropertyField;

public class CtExecutableReferenceExpressionImpl<T, E extends CtExpression<?>> extends CtTargetedExpressionImpl<T, E> implements CtExecutableReferenceExpression<T, E> {
@MetamodelPropertyField(role = CtRole.EXECUTABLE)
CtExecutableReference<T> executable;

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@

import spoon.reflect.code.CtExpression;
import spoon.reflect.declaration.CtTypedElement;
import spoon.reflect.path.CtRole;
import spoon.reflect.reference.CtTypeReference;
import spoon.support.MetamodelPropertyField;
import spoon.support.reflect.declaration.CtElementImpl;

import java.util.ArrayList;
Expand All @@ -29,8 +31,10 @@
public abstract class CtExpressionImpl<T> extends CtCodeElementImpl implements CtExpression<T> {
private static final long serialVersionUID = 1L;

@MetamodelPropertyField(role = CtRole.TYPE)
CtTypeReference<T> type;

@MetamodelPropertyField(role = CtRole.CAST)
List<CtTypeReference<?>> typeCasts = emptyList();

public CtTypeReference<T> getType() {
Expand Down
Loading

0 comments on commit 40c3ef8

Please sign in to comment.