From dc3d82e5a814cb4076ba02eed9bd1bc226cde83d Mon Sep 17 00:00:00 2001 From: Pavel Vojtechovsky Date: Tue, 24 Oct 2017 21:58:57 +0200 Subject: [PATCH 01/14] feature: role based access to model values --- .../spoon/reflect/declaration/CtElement.java | 36 + .../spoon/reflect/meta/ContainerKind.java | 43 + .../java/spoon/reflect/meta/RoleHandler.java | 62 + .../meta/impl/AbstractRoleHandler.java | 376 ++++ .../reflect/meta/impl/ModelRoleHandlers.java | 1889 +++++++++++++++++ .../meta/impl/RoleHandlerProvider.java | 74 + .../reflect/declaration/CtElementImpl.java | 39 + .../generating/RoleHandlersGenerator.java | 205 ++ .../meta/ModelRoleHandlerTemplate.java | 31 + .../generating/meta/RoleHandlerTemplate.java | 119 ++ 10 files changed, 2874 insertions(+) create mode 100644 src/main/java/spoon/reflect/meta/ContainerKind.java create mode 100644 src/main/java/spoon/reflect/meta/RoleHandler.java create mode 100644 src/main/java/spoon/reflect/meta/impl/AbstractRoleHandler.java create mode 100644 src/main/java/spoon/reflect/meta/impl/ModelRoleHandlers.java create mode 100644 src/main/java/spoon/reflect/meta/impl/RoleHandlerProvider.java create mode 100644 src/test/java/spoon/generating/RoleHandlersGenerator.java create mode 100644 src/test/java/spoon/generating/meta/ModelRoleHandlerTemplate.java create mode 100644 src/test/java/spoon/generating/meta/RoleHandlerTemplate.java diff --git a/src/main/java/spoon/reflect/declaration/CtElement.java b/src/main/java/spoon/reflect/declaration/CtElement.java index 97199180a88..76a81d4e350 100644 --- a/src/main/java/spoon/reflect/declaration/CtElement.java +++ b/src/main/java/spoon/reflect/declaration/CtElement.java @@ -32,6 +32,7 @@ import java.lang.annotation.Annotation; import java.util.Collection; import java.util.List; +import java.util.Map; import java.util.Set; import static spoon.reflect.path.CtRole.ANNOTATION; @@ -314,4 +315,39 @@ List getAnnotatedChildren( * Clone the element which calls this method in a new object. */ CtElement clone(); + + /** + * @param role defines, which attribute has to be returned + * @return a value of the `role` attribute of this model node. + * It can return a single value, List, Set or Map depending on this `element` and `role`. + * In all cases the returned value is READ ONLY + */ + T getValueByRole(CtRole role); + + /** + * @param role defines, which attribute has to be returned + * @return a value of the `role` attribute of this model node adapted to modifiable Collection + */ + Collection getValueByRoleAsCollection(CtRole role); + /** + * @param role defines, which attribute has to be returned + * @return a value of the `role` attribute of this model node adapted to modifiable List + */ + List getValueByRoleAsList(CtRole role); + /** + * @param role defines, which attribute has to be returned + * @return a value of the `role` attribute of this model node adapted to modifiable Set + */ + Set getValueByRoleAsSet(CtRole role); + /** + * @param role defines, which attribute has to be returned + * @return a value of the `role` attribute of this model node adapted to modifiable Map + */ + Map getValueByRoleAsMap(CtRole role); + + /** + * @param role defines, which attribute has to be returned + * @param value to be assigned value + */ + E setValueByRole(CtRole role, T value); } diff --git a/src/main/java/spoon/reflect/meta/ContainerKind.java b/src/main/java/spoon/reflect/meta/ContainerKind.java new file mode 100644 index 00000000000..15ea37cbca8 --- /dev/null +++ b/src/main/java/spoon/reflect/meta/ContainerKind.java @@ -0,0 +1,43 @@ +/** + * 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.meta; + +/** + * Defines kind of container, which is used in an attribute of Spoon model + */ +public enum ContainerKind { + /** + * it is a single value field + * Example: CtClassImpl.simpleName + */ + SINGLE, + /** + * It is a list of values + * Example: CtClassImpl.typeMembers + */ + LIST, + /** + * It is a set of values + * Example: CtPackageImpl.types + */ + SET, + /** + * It is a map<String, T> of values + * Example: CtAnnotationImpl.elementValues + */ + MAP; +} diff --git a/src/main/java/spoon/reflect/meta/RoleHandler.java b/src/main/java/spoon/reflect/meta/RoleHandler.java new file mode 100644 index 00000000000..86ad2bf5a93 --- /dev/null +++ b/src/main/java/spoon/reflect/meta/RoleHandler.java @@ -0,0 +1,62 @@ +/** + * 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.meta; + +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import spoon.reflect.path.CtRole; + +/** + * Has all knowledge about a role of an target type + */ +public interface RoleHandler { + /** + * @return a role of this handler + */ + CtRole getRole(); + /** + * @return a type of the class, which this handler can be applied to + */ + Class getTargetType(); + /** + * @param element a element whose value will be get + * @return a value of the element on the role defined by {@link #getRole()} + */ + U getValue(T element); + /** + * @param element a element whose value will be set + * @param value new value, which will be assigned to the element's attribute defined by role defined by {@link #getRole()} + */ + void setValue(T element, U value); + /** + * @return a Class of value of the attribute of {@link #getTargetType()} defined by {@link #getRole()} + */ + Class getValueClass(); + + /** + * @return true if value can contain only one element. It is not a collection or map + */ + ContainerKind getContainerKind(); + + Collection asCollection(T element); + Set asSet(T element); + List asList(T element); + Map asMap(T element); +} diff --git a/src/main/java/spoon/reflect/meta/impl/AbstractRoleHandler.java b/src/main/java/spoon/reflect/meta/impl/AbstractRoleHandler.java new file mode 100644 index 00000000000..d382b92ce0c --- /dev/null +++ b/src/main/java/spoon/reflect/meta/impl/AbstractRoleHandler.java @@ -0,0 +1,376 @@ +/** + * 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.meta.impl; + +import java.util.AbstractList; +import java.util.AbstractMap; +import java.util.AbstractSet; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import spoon.SpoonException; +import spoon.reflect.meta.ContainerKind; +import spoon.reflect.meta.RoleHandler; +import spoon.reflect.path.CtRole; + +/** + * common implementation of {@link RoleHandler} + * @param the type of node whose attribute has to be manipulated + * @param the type of container value of the attribute + * @param the type of item value of the attribute + */ +abstract class AbstractRoleHandler implements RoleHandler { + + private final CtRole role; + private final Class targetClass; + private final Class valueClass; + + @SuppressWarnings({ "unchecked", "rawtypes" }) + protected AbstractRoleHandler(CtRole role, Class targetType, Class valueType) { + this.role = role; + this.targetClass = targetType; + this.valueClass = (Class) valueType; + } + + @Override + public CtRole getRole() { + return role; + } + + @Override + public Class getTargetType() { + return targetClass; + } + + + @SuppressWarnings("unchecked") + protected T castTarget(Object element) { + return (T) element; + } + @SuppressWarnings("unchecked") + protected U castValue(Object value) { + return (U) value; + } + + protected void checkItemsClass(Iterable iterable) { + //check that each item has expected class + for (Object value : iterable) { + castItemValue(value); + } + } + @SuppressWarnings("unchecked") + protected V castItemValue(Object value) { + //check that item has expected class + if (value != null && valueClass.isInstance(value) == false) { + throw new ClassCastException(value.getClass().getName() + " cannot be cast to " + valueClass.getName()); + } + return (V) value; + } + + public void setValue(W element, X value) { + throw new SpoonException("Setting of CtRole." + role.name() + " is not supported for " + element.getClass().getSimpleName()); + }; + + @Override + public Class getValueClass() { + return valueClass; + } + + public List asList(W element) { + throw new SpoonException("The value of CtRole." + getRole().name() + " cannot be adapted to List for " + element.getClass().getSimpleName()); + }; + + public Set asSet(W element) { + throw new SpoonException("The value of CtRole." + getRole().name() + " cannot be adapted to Set for " + element.getClass().getSimpleName()); + }; + + public Map asMap(W element) { + throw new SpoonException("The value of CtRole." + getRole().name() + " cannot be adapted to Map for " + element.getClass().getSimpleName()); + }; + +// protected abstract Iterator iterator(T element); +// protected abstract int size(T element); +// protected abstract V get(T element, int index); +// protected abstract boolean contains(T element, Object o); +// protected abstract boolean add(T element, V o); +// protected abstract boolean remove(T element, Object o); + + + abstract static class SingleHandler extends AbstractRoleHandler { + + protected SingleHandler(CtRole role, Class targetType, Class valueClass) { + super(role, targetType, valueClass); + } + + @Override + public ContainerKind getContainerKind() { + return ContainerKind.SINGLE; + } + + public java.util.Collection asCollection(W element) { + return asList(element); + }; + + public java.util.List asList(W element) { + return Collections.singletonList(getValue(element)); + }; + + public java.util.Set asSet(W element) { + return Collections.singleton(getValue(element)); + }; + } + + abstract static class ListHandler extends AbstractRoleHandler, V> { + + protected ListHandler(CtRole role, Class targetType, Class valueClass) { + super(role, targetType, valueClass); + } + + @Override + public ContainerKind getContainerKind() { + return ContainerKind.LIST; + } + + @Override + protected List castValue(Object value) { + List list = super.castValue(value); + //check that each item has expected class + checkItemsClass(list); + return list; + } + + public java.util.Collection asCollection(W element) { + return asList(element); + }; + + public java.util.List asList(W e) { + return new AbstractList() { + T element = castTarget(e); + + @SuppressWarnings({ "unchecked", "rawtypes" }) + @Override + public Iterator iterator() { + return (Iterator) ListHandler.this.iterator(element); + } + + @Override + public int size() { + return ListHandler.this.size(element); + } + + @SuppressWarnings("unchecked") + @Override + public X get(int index) { + return (X) ListHandler.this.get(element, index); + } + @Override + public boolean add(X value) { + return ListHandler.this.add(element, castItemValue(value)); + } + + @Override + public boolean remove(Object value) { + return ListHandler.this.remove(element, value); + } + }; + } + + protected boolean remove(T element, Object value) { + List values = new ArrayList<>(this.>getValue(element)); + boolean ret = values.remove(value); + if (ret) { + setValue(element, values); + } + return ret; + } + + protected boolean add(T element, V value) { + List values = new ArrayList<>(this.>getValue(element)); + boolean ret = values.add(value); + setValue(element, values); + return ret; + } + + protected V get(T element, int index) { + return this.>getValue(element).get(index); + } + + protected int size(T element) { + return this.>getValue(element).size(); + } + + protected Iterator iterator(T element) { + return this.>getValue(element).iterator(); + }; + } + + abstract static class SetHandler extends AbstractRoleHandler, V> { + + protected SetHandler(CtRole role, Class targetType, Class valueClass) { + super(role, targetType, valueClass); + } + + @Override + public ContainerKind getContainerKind() { + return ContainerKind.SET; + } + + @Override + protected Set castValue(Object value) { + Set set = super.castValue(value); + //check that each item has expected class + checkItemsClass(set); + return set; + } + + public Collection asCollection(W element) { + return asSet(element); + }; + + @Override + public Set asSet(W e) { + return new AbstractSet() { + T element = castTarget(e); + + @SuppressWarnings({ "unchecked", "rawtypes" }) + @Override + public Iterator iterator() { + return (Iterator) SetHandler.this.iterator(element); + } + + @Override + public int size() { + return SetHandler.this.size(element); + } + + @Override + public boolean contains(Object o) { + return SetHandler.this.contains(element, o); + } + + @Override + public boolean add(X value) { + return SetHandler.this.add(element, castItemValue(value)); + } + + @Override + public boolean remove(Object value) { + return SetHandler.this.remove(element, value); + } + }; + } + + protected boolean remove(T element, Object value) { + Set values = new HashSet<>(this.>getValue(element)); + boolean ret = values.remove(value); + if (ret) { + setValue(element, values); + } + return false; + } + + protected boolean add(T element, V value) { + Set values = new HashSet<>(this.>getValue(element)); + boolean ret = values.add(value); + if (ret) { + setValue(element, values); + } + return ret; + } + + protected boolean contains(T element, Object o) { + return this.>getValue(element).contains(o); + } + + protected int size(T element) { + return this.>getValue(element).size(); + } + + protected Iterator iterator(T element) { + return this.>getValue(element).iterator(); + } + } + + abstract static class MapHandler extends AbstractRoleHandler, V> { + + protected MapHandler(CtRole role, Class targetType, Class valueClass) { + super(role, targetType, valueClass); + } + + @Override + public ContainerKind getContainerKind() { + return ContainerKind.MAP; + } + + @Override + protected Map castValue(Object value) { + Map map = super.castValue(value); + //check that each item has expected class + checkItemsClass(map.values()); + return map; + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) + public java.util.Collection asCollection(W element) { + return (Collection) asMap(element).values(); + }; + + @Override + public Map asMap(W e) { + // TODO Auto-generated method stub + return new AbstractMap() { + T element = castTarget(e); + + @SuppressWarnings({ "unchecked", "rawtypes" }) + @Override + public Set> entrySet() { + return (Set) MapHandler.this.entrySet(element); + } + + @SuppressWarnings("unchecked") + @Override + public X get(Object key) { + return (X) MapHandler.this.get(element, key); + } + + @SuppressWarnings("unchecked") + @Override + public X put(String key, X value) { + return (X) MapHandler.this.put(element, key, castItemValue(value)); + } + }; + } + + protected V get(T element, Object key) { + return this.>getValue(element).get(key); + } + + protected V put(T element, String key, V value) { + return this.>getValue(element).put(key, value); + } + + protected Set> entrySet(T element) { + return this.>getValue(element).entrySet(); + } + } +} diff --git a/src/main/java/spoon/reflect/meta/impl/ModelRoleHandlers.java b/src/main/java/spoon/reflect/meta/impl/ModelRoleHandlers.java new file mode 100644 index 00000000000..e6a35bd6100 --- /dev/null +++ b/src/main/java/spoon/reflect/meta/impl/ModelRoleHandlers.java @@ -0,0 +1,1889 @@ +/** + * 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.meta.impl; + + +import java.lang.annotation.Annotation; +import spoon.reflect.code.BinaryOperatorKind; +import spoon.reflect.code.CtAbstractInvocation; +import spoon.reflect.code.CtArrayAccess; +import spoon.reflect.code.CtAssert; +import spoon.reflect.code.CtAssignment; +import spoon.reflect.code.CtBinaryOperator; +import spoon.reflect.code.CtBlock; +import spoon.reflect.code.CtBodyHolder; +import spoon.reflect.code.CtCase; +import spoon.reflect.code.CtCatch; +import spoon.reflect.code.CtCatchVariable; +import spoon.reflect.code.CtComment; +import spoon.reflect.code.CtConditional; +import spoon.reflect.code.CtDo; +import spoon.reflect.code.CtExecutableReferenceExpression; +import spoon.reflect.code.CtExpression; +import spoon.reflect.code.CtFor; +import spoon.reflect.code.CtForEach; +import spoon.reflect.code.CtIf; +import spoon.reflect.code.CtJavaDoc; +import spoon.reflect.code.CtJavaDocTag; +import spoon.reflect.code.CtLabelledFlowBreak; +import spoon.reflect.code.CtLambda; +import spoon.reflect.code.CtLiteral; +import spoon.reflect.code.CtLocalVariable; +import spoon.reflect.code.CtNewArray; +import spoon.reflect.code.CtNewClass; +import spoon.reflect.code.CtOperatorAssignment; +import spoon.reflect.code.CtRHSReceiver; +import spoon.reflect.code.CtReturn; +import spoon.reflect.code.CtStatement; +import spoon.reflect.code.CtStatementList; +import spoon.reflect.code.CtSwitch; +import spoon.reflect.code.CtSynchronized; +import spoon.reflect.code.CtTargetedExpression; +import spoon.reflect.code.CtThrow; +import spoon.reflect.code.CtTry; +import spoon.reflect.code.CtTryWithResource; +import spoon.reflect.code.CtTypeAccess; +import spoon.reflect.code.CtUnaryOperator; +import spoon.reflect.code.CtVariableAccess; +import spoon.reflect.code.CtWhile; +import spoon.reflect.code.UnaryOperatorKind; +import spoon.reflect.cu.SourcePosition; +import spoon.reflect.declaration.CtAnnotation; +import spoon.reflect.declaration.CtAnnotationMethod; +import spoon.reflect.declaration.CtAnonymousExecutable; +import spoon.reflect.declaration.CtClass; +import spoon.reflect.declaration.CtCodeSnippet; +import spoon.reflect.declaration.CtConstructor; +import spoon.reflect.declaration.CtElement; +import spoon.reflect.declaration.CtEnum; +import spoon.reflect.declaration.CtEnumValue; +import spoon.reflect.declaration.CtExecutable; +import spoon.reflect.declaration.CtField; +import spoon.reflect.declaration.CtFormalTypeDeclarer; +import spoon.reflect.declaration.CtMethod; +import spoon.reflect.declaration.CtModifiable; +import spoon.reflect.declaration.CtMultiTypedElement; +import spoon.reflect.declaration.CtNamedElement; +import spoon.reflect.declaration.CtPackage; +import spoon.reflect.declaration.CtParameter; +import spoon.reflect.declaration.CtShadowable; +import spoon.reflect.declaration.CtType; +import spoon.reflect.declaration.CtTypeInformation; +import spoon.reflect.declaration.CtTypeMember; +import spoon.reflect.declaration.CtTypeParameter; +import spoon.reflect.declaration.CtTypedElement; +import spoon.reflect.declaration.CtVariable; +import spoon.reflect.declaration.ModifierKind; +import spoon.reflect.meta.RoleHandler; +import spoon.reflect.meta.impl.AbstractRoleHandler.ListHandler; +import spoon.reflect.meta.impl.AbstractRoleHandler.MapHandler; +import spoon.reflect.meta.impl.AbstractRoleHandler.SetHandler; +import spoon.reflect.meta.impl.AbstractRoleHandler.SingleHandler; +import spoon.reflect.path.CtRole; +import spoon.reflect.reference.CtActualTypeContainer; +import spoon.reflect.reference.CtArrayTypeReference; +import spoon.reflect.reference.CtExecutableReference; +import spoon.reflect.reference.CtFieldReference; +import spoon.reflect.reference.CtIntersectionTypeReference; +import spoon.reflect.reference.CtPackageReference; +import spoon.reflect.reference.CtParameterReference; +import spoon.reflect.reference.CtReference; +import spoon.reflect.reference.CtTypeParameterReference; +import spoon.reflect.reference.CtTypeReference; +import spoon.reflect.reference.CtVariableReference; + + +/** + * Contains implementations of {@link RoleHandler}s for all {@link CtRole}s of all model elements + */ +class ModelRoleHandlers { + static final RoleHandler[] roleHandlers = new RoleHandler[]{ new CtNamedElement_NAME_RoleHandler(), new CtReference_NAME_RoleHandler(), new CtArrayTypeReference_TYPE_RoleHandler(), new CtExecutableReference_TYPE_RoleHandler(), new CtMultiTypedElement_TYPE_RoleHandler(), new CtTypedElement_TYPE_RoleHandler(), new CtVariableReference_TYPE_RoleHandler(), new CtExecutableReference_DECLARING_TYPE_RoleHandler(), new CtFieldReference_DECLARING_TYPE_RoleHandler(), new CtTypeReference_DECLARING_TYPE_RoleHandler(), new CtPackage_CONTAINED_TYPE_RoleHandler(), new CtBodyHolder_BODY_RoleHandler(), new CtSynchronized_BODY_RoleHandler(), new CtShadowable_IS_SHADOW_RoleHandler(), new CtIntersectionTypeReference_BOUND_RoleHandler(), new CtTypeParameterReference_BOUNDING_TYPE_RoleHandler(), new CtFieldReference_IS_FINAL_RoleHandler(), new CtExecutableReference_IS_STATIC_RoleHandler(), new CtFieldReference_IS_STATIC_RoleHandler(), new CtTypeParameterReference_IS_UPPER_RoleHandler(), new CtElement_IS_IMPLICIT_RoleHandler(), new CtMethod_IS_DEFAULT_RoleHandler(), new CtParameter_IS_VARARGS_RoleHandler(), new CtAnnotationMethod_DEFAULT_EXPRESSION_RoleHandler(), new CtVariable_DEFAULT_EXPRESSION_RoleHandler(), new CtConditional_THEN_RoleHandler(), new CtIf_THEN_RoleHandler(), new CtConditional_ELSE_RoleHandler(), new CtIf_ELSE_RoleHandler(), new CtTypeReference_PACKAGE_REF_RoleHandler(), new CtPackage_SUB_PACKAGE_RoleHandler(), new CtAssert_CONDITION_RoleHandler(), new CtConditional_CONDITION_RoleHandler(), new CtIf_CONDITION_RoleHandler(), new CtBinaryOperator_RIGHT_OPERAND_RoleHandler(), new CtBinaryOperator_LEFT_OPERAND_RoleHandler(), new CtStatement_LABEL_RoleHandler(), new CtSwitch_CASE_RoleHandler(), new CtBinaryOperator_OPERATOR_KIND_RoleHandler(), new CtOperatorAssignment_OPERATOR_KIND_RoleHandler(), new CtUnaryOperator_OPERATOR_KIND_RoleHandler(), new CtCatch_PARAMETER_RoleHandler(), new CtExecutable_PARAMETER_RoleHandler(), new CtExecutableReference_ARGUMENT_TYPE_RoleHandler(), new CtArrayAccess_EXPRESSION_RoleHandler(), new CtAssert_EXPRESSION_RoleHandler(), new CtCase_EXPRESSION_RoleHandler(), new CtDo_EXPRESSION_RoleHandler(), new CtFor_EXPRESSION_RoleHandler(), new CtForEach_EXPRESSION_RoleHandler(), new CtLambda_EXPRESSION_RoleHandler(), new CtNewArray_EXPRESSION_RoleHandler(), new CtReturn_EXPRESSION_RoleHandler(), new CtSwitch_EXPRESSION_RoleHandler(), new CtSynchronized_EXPRESSION_RoleHandler(), new CtThrow_EXPRESSION_RoleHandler(), new CtUnaryOperator_EXPRESSION_RoleHandler(), new CtWhile_EXPRESSION_RoleHandler(), new CtTargetedExpression_TARGET_RoleHandler(), new CtVariableAccess_VARIABLE_RoleHandler(), new CtTry_FINALIZER_RoleHandler(), new CtExecutable_THROWN_RoleHandler(), new CtRHSReceiver_ASSIGNMENT_RoleHandler(), new CtAssignment_ASSIGNED_RoleHandler(), new CtModifiable_MODIFIER_RoleHandler(), new CtTypeInformation_MODIFIER_RoleHandler(), new CtElement_COMMENT_RoleHandler(), new CtAnnotation_ANNOTATION_TYPE_RoleHandler(), new CtTypeInformation_INTERFACE_RoleHandler(), new CtElement_ANNOTATION_RoleHandler(), new CtStatementList_STATEMENT_RoleHandler(), new CtAbstractInvocation_ARGUMENT_RoleHandler(), new CtTypeInformation_SUPER_TYPE_RoleHandler(), new CtNewClass_NESTED_TYPE_RoleHandler(), new CtType_NESTED_TYPE_RoleHandler(), new CtClass_CONSTRUCTOR_RoleHandler(), new CtAbstractInvocation_EXECUTABLE_REF_RoleHandler(), new CtExecutableReferenceExpression_EXECUTABLE_REF_RoleHandler(), new CtParameterReference_EXECUTABLE_REF_RoleHandler(), new CtType_METHOD_RoleHandler(), new CtClass_ANNONYMOUS_EXECUTABLE_RoleHandler(), new CtType_FIELD_RoleHandler(), new CtType_TYPE_MEMBER_RoleHandler(), new CtExpression_CAST_RoleHandler(), new CtAnnotation_VALUE_RoleHandler(), new CtEnum_VALUE_RoleHandler(), new CtLiteral_VALUE_RoleHandler(), new CtFor_FOR_UPDATE_RoleHandler(), new CtFor_FOR_INIT_RoleHandler(), new CtForEach_FOREACH_VARIABLE_RoleHandler(), new CtTryWithResource_TRY_RESOURCE_RoleHandler(), new CtNewArray_DIMENSION_RoleHandler(), new CtTry_CATCH_RoleHandler(), new CtLabelledFlowBreak_TARGET_LABEL_RoleHandler(), new CtFormalTypeDeclarer_TYPE_PARAMETER_RoleHandler(), new CtActualTypeContainer_TYPE_ARGUMENT_RoleHandler(), new CtJavaDoc_COMMENT_TAG_RoleHandler(), new CtComment_COMMENT_CONTENT_RoleHandler(), new CtJavaDocTag_COMMENT_CONTENT_RoleHandler(), new CtComment_COMMENT_TYPE_RoleHandler(), new CtJavaDocTag_DOCUMENTATION_TYPE_RoleHandler(), new CtJavaDocTag_JAVADOC_TAG_VALUE_RoleHandler(), new CtElement_POSITION_RoleHandler(), new CtCodeSnippet_SNIPPET_RoleHandler(), new CtTypeAccess_ACCESSED_TYPE_RoleHandler() }; + + private ModelRoleHandlers() { + } + + static class CtNamedElement_NAME_RoleHandler extends SingleHandler { + private CtNamedElement_NAME_RoleHandler() { + super(CtRole.NAME, CtNamedElement.class, String.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).getSimpleName()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setSimpleName(castValue(value)); + } + } + + static class CtReference_NAME_RoleHandler extends SingleHandler { + private CtReference_NAME_RoleHandler() { + super(CtRole.NAME, CtReference.class, String.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).getSimpleName()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setSimpleName(castValue(value)); + } + } + + static class CtArrayTypeReference_TYPE_RoleHandler extends SingleHandler> { + private CtArrayTypeReference_TYPE_RoleHandler() { + super(CtRole.TYPE, CtArrayTypeReference.class, CtTypeReference.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).getComponentType()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setComponentType(castValue(value)); + } + } + + static class CtExecutableReference_TYPE_RoleHandler extends SingleHandler> { + private CtExecutableReference_TYPE_RoleHandler() { + super(CtRole.TYPE, CtExecutableReference.class, CtTypeReference.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).getType()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setType(castValue(value)); + } + } + + static class CtMultiTypedElement_TYPE_RoleHandler extends ListHandler> { + private CtMultiTypedElement_TYPE_RoleHandler() { + super(CtRole.TYPE, CtMultiTypedElement.class, CtTypeReference.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).getMultiTypes()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setMultiTypes(castValue(value)); + } + } + + static class CtTypedElement_TYPE_RoleHandler extends SingleHandler> { + private CtTypedElement_TYPE_RoleHandler() { + super(CtRole.TYPE, CtTypedElement.class, CtTypeReference.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).getType()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setType(castValue(value)); + } + } + + static class CtVariableReference_TYPE_RoleHandler extends SingleHandler> { + private CtVariableReference_TYPE_RoleHandler() { + super(CtRole.TYPE, CtVariableReference.class, CtTypeReference.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).getType()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setType(castValue(value)); + } + } + + static class CtExecutableReference_DECLARING_TYPE_RoleHandler extends SingleHandler> { + private CtExecutableReference_DECLARING_TYPE_RoleHandler() { + super(CtRole.DECLARING_TYPE, CtExecutableReference.class, CtTypeReference.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).getDeclaringType()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setDeclaringType(castValue(value)); + } + } + + static class CtFieldReference_DECLARING_TYPE_RoleHandler extends SingleHandler> { + private CtFieldReference_DECLARING_TYPE_RoleHandler() { + super(CtRole.DECLARING_TYPE, CtFieldReference.class, CtTypeReference.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).getDeclaringType()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setDeclaringType(castValue(value)); + } + } + + static class CtTypeReference_DECLARING_TYPE_RoleHandler extends SingleHandler> { + private CtTypeReference_DECLARING_TYPE_RoleHandler() { + super(CtRole.DECLARING_TYPE, CtTypeReference.class, CtTypeReference.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).getDeclaringType()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setDeclaringType(castValue(value)); + } + } + + static class CtPackage_CONTAINED_TYPE_RoleHandler extends SetHandler> { + private CtPackage_CONTAINED_TYPE_RoleHandler() { + super(CtRole.CONTAINED_TYPE, CtPackage.class, CtType.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).getTypes()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setTypes(castValue(value)); + } + } + + static class CtBodyHolder_BODY_RoleHandler extends SingleHandler { + private CtBodyHolder_BODY_RoleHandler() { + super(CtRole.BODY, CtBodyHolder.class, CtStatement.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).getBody()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setBody(castValue(value)); + } + } + + static class CtSynchronized_BODY_RoleHandler extends SingleHandler> { + private CtSynchronized_BODY_RoleHandler() { + super(CtRole.BODY, CtSynchronized.class, CtBlock.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).getBlock()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setBlock(castValue(value)); + } + } + + static class CtShadowable_IS_SHADOW_RoleHandler extends SingleHandler { + private CtShadowable_IS_SHADOW_RoleHandler() { + super(CtRole.IS_SHADOW, CtShadowable.class, Boolean.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).isShadow()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setShadow(castValue(value)); + } + } + + static class CtIntersectionTypeReference_BOUND_RoleHandler extends ListHandler> { + private CtIntersectionTypeReference_BOUND_RoleHandler() { + super(CtRole.BOUND, CtIntersectionTypeReference.class, CtTypeReference.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).getBounds()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setBounds(castValue(value)); + } + } + + static class CtTypeParameterReference_BOUNDING_TYPE_RoleHandler extends SingleHandler> { + private CtTypeParameterReference_BOUNDING_TYPE_RoleHandler() { + super(CtRole.BOUNDING_TYPE, CtTypeParameterReference.class, CtTypeReference.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).getBoundingType()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setBoundingType(castValue(value)); + } + } + + static class CtFieldReference_IS_FINAL_RoleHandler extends SingleHandler { + private CtFieldReference_IS_FINAL_RoleHandler() { + super(CtRole.IS_FINAL, CtFieldReference.class, Boolean.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).isFinal()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setFinal(castValue(value)); + } + } + + static class CtExecutableReference_IS_STATIC_RoleHandler extends SingleHandler { + private CtExecutableReference_IS_STATIC_RoleHandler() { + super(CtRole.IS_STATIC, CtExecutableReference.class, Boolean.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).isStatic()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setStatic(castValue(value)); + } + } + + static class CtFieldReference_IS_STATIC_RoleHandler extends SingleHandler { + private CtFieldReference_IS_STATIC_RoleHandler() { + super(CtRole.IS_STATIC, CtFieldReference.class, Boolean.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).isStatic()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setStatic(castValue(value)); + } + } + + static class CtTypeParameterReference_IS_UPPER_RoleHandler extends SingleHandler { + private CtTypeParameterReference_IS_UPPER_RoleHandler() { + super(CtRole.IS_UPPER, CtTypeParameterReference.class, Boolean.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).isUpper()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setUpper(castValue(value)); + } + } + + static class CtElement_IS_IMPLICIT_RoleHandler extends SingleHandler { + private CtElement_IS_IMPLICIT_RoleHandler() { + super(CtRole.IS_IMPLICIT, CtElement.class, Boolean.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).isImplicit()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setImplicit(castValue(value)); + } + } + + static class CtMethod_IS_DEFAULT_RoleHandler extends SingleHandler { + private CtMethod_IS_DEFAULT_RoleHandler() { + super(CtRole.IS_DEFAULT, CtMethod.class, Boolean.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).isDefaultMethod()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setDefaultMethod(castValue(value)); + } + } + + static class CtParameter_IS_VARARGS_RoleHandler extends SingleHandler { + private CtParameter_IS_VARARGS_RoleHandler() { + super(CtRole.IS_VARARGS, CtParameter.class, Boolean.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).isVarArgs()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setVarArgs(castValue(value)); + } + } + + static class CtAnnotationMethod_DEFAULT_EXPRESSION_RoleHandler extends SingleHandler> { + private CtAnnotationMethod_DEFAULT_EXPRESSION_RoleHandler() { + super(CtRole.DEFAULT_EXPRESSION, CtAnnotationMethod.class, CtExpression.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).getDefaultExpression()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setDefaultExpression(castValue(value)); + } + } + + static class CtVariable_DEFAULT_EXPRESSION_RoleHandler extends SingleHandler> { + private CtVariable_DEFAULT_EXPRESSION_RoleHandler() { + super(CtRole.DEFAULT_EXPRESSION, CtVariable.class, CtExpression.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).getDefaultExpression()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setDefaultExpression(castValue(value)); + } + } + + static class CtConditional_THEN_RoleHandler extends SingleHandler> { + private CtConditional_THEN_RoleHandler() { + super(CtRole.THEN, CtConditional.class, CtExpression.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).getThenExpression()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setThenExpression(castValue(value)); + } + } + + static class CtIf_THEN_RoleHandler extends SingleHandler { + private CtIf_THEN_RoleHandler() { + super(CtRole.THEN, CtIf.class, CtStatement.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).getThenStatement()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setThenStatement(castValue(value)); + } + } + + static class CtConditional_ELSE_RoleHandler extends SingleHandler> { + private CtConditional_ELSE_RoleHandler() { + super(CtRole.ELSE, CtConditional.class, CtExpression.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).getElseExpression()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setElseExpression(castValue(value)); + } + } + + static class CtIf_ELSE_RoleHandler extends SingleHandler { + private CtIf_ELSE_RoleHandler() { + super(CtRole.ELSE, CtIf.class, CtStatement.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).getElseStatement()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setElseStatement(castValue(value)); + } + } + + static class CtTypeReference_PACKAGE_REF_RoleHandler extends SingleHandler { + private CtTypeReference_PACKAGE_REF_RoleHandler() { + super(CtRole.PACKAGE_REF, CtTypeReference.class, CtPackageReference.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).getPackage()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setPackage(castValue(value)); + } + } + + static class CtPackage_SUB_PACKAGE_RoleHandler extends SetHandler { + private CtPackage_SUB_PACKAGE_RoleHandler() { + super(CtRole.SUB_PACKAGE, CtPackage.class, CtPackage.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).getPackages()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setPackages(castValue(value)); + } + } + + static class CtAssert_CONDITION_RoleHandler extends SingleHandler> { + private CtAssert_CONDITION_RoleHandler() { + super(CtRole.CONDITION, CtAssert.class, CtExpression.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).getAssertExpression()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setAssertExpression(castValue(value)); + } + } + + static class CtConditional_CONDITION_RoleHandler extends SingleHandler> { + private CtConditional_CONDITION_RoleHandler() { + super(CtRole.CONDITION, CtConditional.class, CtExpression.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).getCondition()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setCondition(castValue(value)); + } + } + + static class CtIf_CONDITION_RoleHandler extends SingleHandler> { + private CtIf_CONDITION_RoleHandler() { + super(CtRole.CONDITION, CtIf.class, CtExpression.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).getCondition()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setCondition(castValue(value)); + } + } + + static class CtBinaryOperator_RIGHT_OPERAND_RoleHandler extends SingleHandler> { + private CtBinaryOperator_RIGHT_OPERAND_RoleHandler() { + super(CtRole.RIGHT_OPERAND, CtBinaryOperator.class, CtExpression.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).getRightHandOperand()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setRightHandOperand(castValue(value)); + } + } + + static class CtBinaryOperator_LEFT_OPERAND_RoleHandler extends SingleHandler> { + private CtBinaryOperator_LEFT_OPERAND_RoleHandler() { + super(CtRole.LEFT_OPERAND, CtBinaryOperator.class, CtExpression.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).getLeftHandOperand()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setLeftHandOperand(castValue(value)); + } + } + + static class CtStatement_LABEL_RoleHandler extends SingleHandler { + private CtStatement_LABEL_RoleHandler() { + super(CtRole.LABEL, CtStatement.class, String.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).getLabel()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setLabel(castValue(value)); + } + } + + static class CtSwitch_CASE_RoleHandler extends ListHandler> { + private CtSwitch_CASE_RoleHandler() { + super(CtRole.CASE, CtSwitch.class, CtCase.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).getCases()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setCases(castValue(value)); + } + } + + static class CtBinaryOperator_OPERATOR_KIND_RoleHandler extends SingleHandler { + private CtBinaryOperator_OPERATOR_KIND_RoleHandler() { + super(CtRole.OPERATOR_KIND, CtBinaryOperator.class, BinaryOperatorKind.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).getKind()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setKind(castValue(value)); + } + } + + static class CtOperatorAssignment_OPERATOR_KIND_RoleHandler extends SingleHandler { + private CtOperatorAssignment_OPERATOR_KIND_RoleHandler() { + super(CtRole.OPERATOR_KIND, CtOperatorAssignment.class, BinaryOperatorKind.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).getKind()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setKind(castValue(value)); + } + } + + static class CtUnaryOperator_OPERATOR_KIND_RoleHandler extends SingleHandler { + private CtUnaryOperator_OPERATOR_KIND_RoleHandler() { + super(CtRole.OPERATOR_KIND, CtUnaryOperator.class, UnaryOperatorKind.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).getKind()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setKind(castValue(value)); + } + } + + static class CtCatch_PARAMETER_RoleHandler extends SingleHandler> { + private CtCatch_PARAMETER_RoleHandler() { + super(CtRole.PARAMETER, CtCatch.class, CtCatchVariable.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).getParameter()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setParameter(castValue(value)); + } + } + + static class CtExecutable_PARAMETER_RoleHandler extends ListHandler> { + private CtExecutable_PARAMETER_RoleHandler() { + super(CtRole.PARAMETER, CtExecutable.class, CtParameter.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).getParameters()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setParameters(castValue(value)); + } + } + + static class CtExecutableReference_ARGUMENT_TYPE_RoleHandler extends ListHandler> { + private CtExecutableReference_ARGUMENT_TYPE_RoleHandler() { + super(CtRole.ARGUMENT_TYPE, CtExecutableReference.class, CtTypeReference.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).getParameters()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setParameters(castValue(value)); + } + } + + static class CtArrayAccess_EXPRESSION_RoleHandler extends SingleHandler> { + private CtArrayAccess_EXPRESSION_RoleHandler() { + super(CtRole.EXPRESSION, CtArrayAccess.class, CtExpression.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).getIndexExpression()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setIndexExpression(castValue(value)); + } + } + + static class CtAssert_EXPRESSION_RoleHandler extends SingleHandler> { + private CtAssert_EXPRESSION_RoleHandler() { + super(CtRole.EXPRESSION, CtAssert.class, CtExpression.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).getExpression()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setExpression(castValue(value)); + } + } + + static class CtCase_EXPRESSION_RoleHandler extends SingleHandler> { + private CtCase_EXPRESSION_RoleHandler() { + super(CtRole.EXPRESSION, CtCase.class, CtExpression.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).getCaseExpression()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setCaseExpression(castValue(value)); + } + } + + static class CtDo_EXPRESSION_RoleHandler extends SingleHandler> { + private CtDo_EXPRESSION_RoleHandler() { + super(CtRole.EXPRESSION, CtDo.class, CtExpression.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).getLoopingExpression()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setLoopingExpression(castValue(value)); + } + } + + static class CtFor_EXPRESSION_RoleHandler extends SingleHandler> { + private CtFor_EXPRESSION_RoleHandler() { + super(CtRole.EXPRESSION, CtFor.class, CtExpression.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).getExpression()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setExpression(castValue(value)); + } + } + + static class CtForEach_EXPRESSION_RoleHandler extends SingleHandler> { + private CtForEach_EXPRESSION_RoleHandler() { + super(CtRole.EXPRESSION, CtForEach.class, CtExpression.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).getExpression()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setExpression(castValue(value)); + } + } + + static class CtLambda_EXPRESSION_RoleHandler extends SingleHandler> { + private CtLambda_EXPRESSION_RoleHandler() { + super(CtRole.EXPRESSION, CtLambda.class, CtExpression.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).getExpression()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setExpression(castValue(value)); + } + } + + static class CtNewArray_EXPRESSION_RoleHandler extends ListHandler> { + private CtNewArray_EXPRESSION_RoleHandler() { + super(CtRole.EXPRESSION, CtNewArray.class, CtExpression.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).getElements()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setElements(castValue(value)); + } + } + + static class CtReturn_EXPRESSION_RoleHandler extends SingleHandler> { + private CtReturn_EXPRESSION_RoleHandler() { + super(CtRole.EXPRESSION, CtReturn.class, CtExpression.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).getReturnedExpression()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setReturnedExpression(castValue(value)); + } + } + + static class CtSwitch_EXPRESSION_RoleHandler extends SingleHandler> { + private CtSwitch_EXPRESSION_RoleHandler() { + super(CtRole.EXPRESSION, CtSwitch.class, CtExpression.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).getSelector()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setSelector(castValue(value)); + } + } + + static class CtSynchronized_EXPRESSION_RoleHandler extends SingleHandler> { + private CtSynchronized_EXPRESSION_RoleHandler() { + super(CtRole.EXPRESSION, CtSynchronized.class, CtExpression.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).getExpression()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setExpression(castValue(value)); + } + } + + static class CtThrow_EXPRESSION_RoleHandler extends SingleHandler> { + private CtThrow_EXPRESSION_RoleHandler() { + super(CtRole.EXPRESSION, CtThrow.class, CtExpression.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).getThrownExpression()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setThrownExpression(castValue(value)); + } + } + + static class CtUnaryOperator_EXPRESSION_RoleHandler extends SingleHandler> { + private CtUnaryOperator_EXPRESSION_RoleHandler() { + super(CtRole.EXPRESSION, CtUnaryOperator.class, CtExpression.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).getOperand()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setOperand(castValue(value)); + } + } + + static class CtWhile_EXPRESSION_RoleHandler extends SingleHandler> { + private CtWhile_EXPRESSION_RoleHandler() { + super(CtRole.EXPRESSION, CtWhile.class, CtExpression.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).getLoopingExpression()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setLoopingExpression(castValue(value)); + } + } + + static class CtTargetedExpression_TARGET_RoleHandler extends SingleHandler> { + private CtTargetedExpression_TARGET_RoleHandler() { + super(CtRole.TARGET, CtTargetedExpression.class, CtExpression.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).getTarget()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setTarget(castValue(value)); + } + } + + static class CtVariableAccess_VARIABLE_RoleHandler extends SingleHandler> { + private CtVariableAccess_VARIABLE_RoleHandler() { + super(CtRole.VARIABLE, CtVariableAccess.class, CtVariableReference.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).getVariable()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setVariable(castValue(value)); + } + } + + static class CtTry_FINALIZER_RoleHandler extends SingleHandler> { + private CtTry_FINALIZER_RoleHandler() { + super(CtRole.FINALIZER, CtTry.class, CtBlock.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).getFinalizer()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setFinalizer(castValue(value)); + } + } + + static class CtExecutable_THROWN_RoleHandler extends SetHandler> { + private CtExecutable_THROWN_RoleHandler() { + super(CtRole.THROWN, CtExecutable.class, CtTypeReference.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).getThrownTypes()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setThrownTypes(castValue(value)); + } + } + + static class CtRHSReceiver_ASSIGNMENT_RoleHandler extends SingleHandler> { + private CtRHSReceiver_ASSIGNMENT_RoleHandler() { + super(CtRole.ASSIGNMENT, CtRHSReceiver.class, CtExpression.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).getAssignment()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setAssignment(castValue(value)); + } + } + + static class CtAssignment_ASSIGNED_RoleHandler extends SingleHandler> { + private CtAssignment_ASSIGNED_RoleHandler() { + super(CtRole.ASSIGNED, CtAssignment.class, CtExpression.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).getAssigned()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setAssigned(castValue(value)); + } + } + + static class CtModifiable_MODIFIER_RoleHandler extends SetHandler { + private CtModifiable_MODIFIER_RoleHandler() { + super(CtRole.MODIFIER, CtModifiable.class, ModifierKind.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).getModifiers()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setModifiers(castValue(value)); + } + } + + static class CtTypeInformation_MODIFIER_RoleHandler extends SetHandler { + private CtTypeInformation_MODIFIER_RoleHandler() { + super(CtRole.MODIFIER, CtTypeInformation.class, ModifierKind.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).getModifiers()))); + } + } + + static class CtElement_COMMENT_RoleHandler extends ListHandler { + private CtElement_COMMENT_RoleHandler() { + super(CtRole.COMMENT, CtElement.class, CtComment.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).getComments()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setComments(castValue(value)); + } + } + + static class CtAnnotation_ANNOTATION_TYPE_RoleHandler extends SingleHandler> { + private CtAnnotation_ANNOTATION_TYPE_RoleHandler() { + super(CtRole.ANNOTATION_TYPE, CtAnnotation.class, CtTypeReference.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).getAnnotationType()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setAnnotationType(castValue(value)); + } + } + + static class CtTypeInformation_INTERFACE_RoleHandler extends SetHandler> { + private CtTypeInformation_INTERFACE_RoleHandler() { + super(CtRole.INTERFACE, CtTypeInformation.class, CtTypeReference.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).getSuperInterfaces()))); + } + } + + static class CtElement_ANNOTATION_RoleHandler extends ListHandler> { + private CtElement_ANNOTATION_RoleHandler() { + super(CtRole.ANNOTATION, CtElement.class, CtAnnotation.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).getAnnotations()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setAnnotations(castValue(value)); + } + } + + static class CtStatementList_STATEMENT_RoleHandler extends ListHandler { + private CtStatementList_STATEMENT_RoleHandler() { + super(CtRole.STATEMENT, CtStatementList.class, CtStatement.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).getStatements()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setStatements(castValue(value)); + } + } + + static class CtAbstractInvocation_ARGUMENT_RoleHandler extends ListHandler> { + private CtAbstractInvocation_ARGUMENT_RoleHandler() { + super(CtRole.ARGUMENT, CtAbstractInvocation.class, CtExpression.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).getArguments()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setArguments(castValue(value)); + } + } + + static class CtTypeInformation_SUPER_TYPE_RoleHandler extends SingleHandler> { + private CtTypeInformation_SUPER_TYPE_RoleHandler() { + super(CtRole.SUPER_TYPE, CtTypeInformation.class, CtTypeReference.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).getSuperclass()))); + } + } + + static class CtNewClass_NESTED_TYPE_RoleHandler extends SingleHandler> { + private CtNewClass_NESTED_TYPE_RoleHandler() { + super(CtRole.NESTED_TYPE, CtNewClass.class, CtClass.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).getAnonymousClass()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setAnonymousClass(castValue(value)); + } + } + + static class CtType_NESTED_TYPE_RoleHandler extends SetHandler> { + private CtType_NESTED_TYPE_RoleHandler() { + super(CtRole.NESTED_TYPE, CtType.class, CtType.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).getNestedTypes()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setNestedTypes(castValue(value)); + } + } + + static class CtClass_CONSTRUCTOR_RoleHandler extends SetHandler> { + private CtClass_CONSTRUCTOR_RoleHandler() { + super(CtRole.CONSTRUCTOR, CtClass.class, CtConstructor.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).getConstructors()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setConstructors(castValue(value)); + } + } + + static class CtAbstractInvocation_EXECUTABLE_REF_RoleHandler extends SingleHandler> { + private CtAbstractInvocation_EXECUTABLE_REF_RoleHandler() { + super(CtRole.EXECUTABLE_REF, CtAbstractInvocation.class, CtExecutableReference.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).getExecutable()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setExecutable(castValue(value)); + } + } + + static class CtExecutableReferenceExpression_EXECUTABLE_REF_RoleHandler extends SingleHandler> { + private CtExecutableReferenceExpression_EXECUTABLE_REF_RoleHandler() { + super(CtRole.EXECUTABLE_REF, CtExecutableReferenceExpression.class, CtExecutableReference.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).getExecutable()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setExecutable(castValue(value)); + } + } + + static class CtParameterReference_EXECUTABLE_REF_RoleHandler extends SingleHandler> { + private CtParameterReference_EXECUTABLE_REF_RoleHandler() { + super(CtRole.EXECUTABLE_REF, CtParameterReference.class, CtExecutableReference.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).getDeclaringExecutable()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setDeclaringExecutable(castValue(value)); + } + } + + static class CtType_METHOD_RoleHandler extends SetHandler> { + private CtType_METHOD_RoleHandler() { + super(CtRole.METHOD, CtType.class, CtMethod.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).getMethods()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setMethods(castValue(value)); + } + } + + static class CtClass_ANNONYMOUS_EXECUTABLE_RoleHandler extends ListHandler { + private CtClass_ANNONYMOUS_EXECUTABLE_RoleHandler() { + super(CtRole.ANNONYMOUS_EXECUTABLE, CtClass.class, CtAnonymousExecutable.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).getAnonymousExecutables()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setAnonymousExecutables(castValue(value)); + } + } + + static class CtType_FIELD_RoleHandler extends ListHandler> { + private CtType_FIELD_RoleHandler() { + super(CtRole.FIELD, CtType.class, CtField.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).getFields()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setFields(castValue(value)); + } + } + + static class CtType_TYPE_MEMBER_RoleHandler extends ListHandler { + private CtType_TYPE_MEMBER_RoleHandler() { + super(CtRole.TYPE_MEMBER, CtType.class, CtTypeMember.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).getTypeMembers()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setTypeMembers(castValue(value)); + } + } + + static class CtExpression_CAST_RoleHandler extends ListHandler> { + private CtExpression_CAST_RoleHandler() { + super(CtRole.CAST, CtExpression.class, CtTypeReference.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).getTypeCasts()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setTypeCasts(castValue(value)); + } + } + + static class CtAnnotation_VALUE_RoleHandler extends MapHandler { + private CtAnnotation_VALUE_RoleHandler() { + super(CtRole.VALUE, CtAnnotation.class, CtExpression.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).getValues()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setValues(castValue(value)); + } + } + + static class CtEnum_VALUE_RoleHandler extends ListHandler> { + private CtEnum_VALUE_RoleHandler() { + super(CtRole.VALUE, CtEnum.class, CtEnumValue.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).getEnumValues()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setEnumValues(castValue(value)); + } + } + + static class CtLiteral_VALUE_RoleHandler extends SingleHandler { + private CtLiteral_VALUE_RoleHandler() { + super(CtRole.VALUE, CtLiteral.class, Object.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).getValue()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setValue(castValue(value)); + } + } + + static class CtFor_FOR_UPDATE_RoleHandler extends ListHandler { + private CtFor_FOR_UPDATE_RoleHandler() { + super(CtRole.FOR_UPDATE, CtFor.class, CtStatement.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).getForUpdate()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setForUpdate(castValue(value)); + } + } + + static class CtFor_FOR_INIT_RoleHandler extends ListHandler { + private CtFor_FOR_INIT_RoleHandler() { + super(CtRole.FOR_INIT, CtFor.class, CtStatement.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).getForInit()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setForInit(castValue(value)); + } + } + + static class CtForEach_FOREACH_VARIABLE_RoleHandler extends SingleHandler> { + private CtForEach_FOREACH_VARIABLE_RoleHandler() { + super(CtRole.FOREACH_VARIABLE, CtForEach.class, CtLocalVariable.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).getVariable()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setVariable(castValue(value)); + } + } + + static class CtTryWithResource_TRY_RESOURCE_RoleHandler extends ListHandler> { + private CtTryWithResource_TRY_RESOURCE_RoleHandler() { + super(CtRole.TRY_RESOURCE, CtTryWithResource.class, CtLocalVariable.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).getResources()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setResources(castValue(value)); + } + } + + static class CtNewArray_DIMENSION_RoleHandler extends ListHandler> { + private CtNewArray_DIMENSION_RoleHandler() { + super(CtRole.DIMENSION, CtNewArray.class, CtExpression.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).getDimensionExpressions()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setDimensionExpressions(castValue(value)); + } + } + + static class CtTry_CATCH_RoleHandler extends ListHandler { + private CtTry_CATCH_RoleHandler() { + super(CtRole.CATCH, CtTry.class, CtCatch.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).getCatchers()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setCatchers(castValue(value)); + } + } + + static class CtLabelledFlowBreak_TARGET_LABEL_RoleHandler extends SingleHandler { + private CtLabelledFlowBreak_TARGET_LABEL_RoleHandler() { + super(CtRole.TARGET_LABEL, CtLabelledFlowBreak.class, String.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).getTargetLabel()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setTargetLabel(castValue(value)); + } + } + + static class CtFormalTypeDeclarer_TYPE_PARAMETER_RoleHandler extends ListHandler { + private CtFormalTypeDeclarer_TYPE_PARAMETER_RoleHandler() { + super(CtRole.TYPE_PARAMETER, CtFormalTypeDeclarer.class, CtTypeParameter.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).getFormalCtTypeParameters()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setFormalCtTypeParameters(castValue(value)); + } + } + + static class CtActualTypeContainer_TYPE_ARGUMENT_RoleHandler extends ListHandler> { + private CtActualTypeContainer_TYPE_ARGUMENT_RoleHandler() { + super(CtRole.TYPE_ARGUMENT, CtActualTypeContainer.class, CtTypeReference.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).getActualTypeArguments()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setActualTypeArguments(castValue(value)); + } + } + + static class CtJavaDoc_COMMENT_TAG_RoleHandler extends ListHandler { + private CtJavaDoc_COMMENT_TAG_RoleHandler() { + super(CtRole.COMMENT_TAG, CtJavaDoc.class, CtJavaDocTag.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).getTags()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setTags(castValue(value)); + } + } + + static class CtComment_COMMENT_CONTENT_RoleHandler extends SingleHandler { + private CtComment_COMMENT_CONTENT_RoleHandler() { + super(CtRole.COMMENT_CONTENT, CtComment.class, String.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).getContent()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setContent(castValue(value)); + } + } + + static class CtJavaDocTag_COMMENT_CONTENT_RoleHandler extends SingleHandler { + private CtJavaDocTag_COMMENT_CONTENT_RoleHandler() { + super(CtRole.COMMENT_CONTENT, CtJavaDocTag.class, String.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).getContent()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setContent(castValue(value)); + } + } + + static class CtComment_COMMENT_TYPE_RoleHandler extends SingleHandler { + private CtComment_COMMENT_TYPE_RoleHandler() { + super(CtRole.COMMENT_TYPE, CtComment.class, CtComment.CommentType.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).getCommentType()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setCommentType(castValue(value)); + } + } + + static class CtJavaDocTag_DOCUMENTATION_TYPE_RoleHandler extends SingleHandler { + private CtJavaDocTag_DOCUMENTATION_TYPE_RoleHandler() { + super(CtRole.DOCUMENTATION_TYPE, CtJavaDocTag.class, CtJavaDocTag.TagType.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).getType()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setType(castValue(value)); + } + } + + static class CtJavaDocTag_JAVADOC_TAG_VALUE_RoleHandler extends SingleHandler { + private CtJavaDocTag_JAVADOC_TAG_VALUE_RoleHandler() { + super(CtRole.JAVADOC_TAG_VALUE, CtJavaDocTag.class, String.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).getParam()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setParam(castValue(value)); + } + } + + static class CtElement_POSITION_RoleHandler extends SingleHandler { + private CtElement_POSITION_RoleHandler() { + super(CtRole.POSITION, CtElement.class, SourcePosition.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).getPosition()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setPosition(castValue(value)); + } + } + + static class CtCodeSnippet_SNIPPET_RoleHandler extends SingleHandler { + private CtCodeSnippet_SNIPPET_RoleHandler() { + super(CtRole.SNIPPET, CtCodeSnippet.class, String.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).getValue()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setValue(castValue(value)); + } + } + + static class CtTypeAccess_ACCESSED_TYPE_RoleHandler extends SingleHandler> { + private CtTypeAccess_ACCESSED_TYPE_RoleHandler() { + super(CtRole.ACCESSED_TYPE, CtTypeAccess.class, CtTypeReference.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return ((U) ((Object) (castTarget(element).getAccessedType()))); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).setAccessedType(castValue(value)); + } + } +} + diff --git a/src/main/java/spoon/reflect/meta/impl/RoleHandlerProvider.java b/src/main/java/spoon/reflect/meta/impl/RoleHandlerProvider.java new file mode 100644 index 00000000000..18f67efeee7 --- /dev/null +++ b/src/main/java/spoon/reflect/meta/impl/RoleHandlerProvider.java @@ -0,0 +1,74 @@ +/** + * 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.meta.impl; + +import java.util.ArrayList; +import java.util.List; + +import spoon.SpoonException; +import spoon.reflect.declaration.CtElement; +import spoon.reflect.meta.RoleHandler; +import spoon.reflect.path.CtRole; + +/** + * Provides a {@link RoleHandler} implementation for the pair of {@link CtElement} implementation and {@link CtRole} + * The returned {@link RoleHandler} can be then used to manipulate value of attribute represented by {@link CtRole} on the {@link CtElement} instance + */ +public class RoleHandlerProvider { + private RoleHandlerProvider() { + } + + @SuppressWarnings("unchecked") + private static final List[] roleHandlers = new List[CtRole.values().length]; + static { + for (int i = 0; i < roleHandlers.length; i++) { + roleHandlers[i] = new ArrayList<>(); + } + for (RoleHandler rh : ModelRoleHandlers.roleHandlers) { + roleHandlers[rh.getRole().ordinal()].add(0, rh); + } + } + + /** + * @param targetClass the class of the to be manipulated node + * @param role defines the to be manipulated attribute + * @return {@link RoleHandler} implementation which knows how to manipulate the attribute of {@link CtRole} on `targetClass` + * or throws exception if such role does not exists on the `targetClass` + */ + public static RoleHandler getRoleHandler(Class targetClass, CtRole role) { + RoleHandler rh = getOptionalRoleHandler(targetClass, role); + if (rh == null) { + throw new SpoonException("The element of class " + targetClass + " does not have CtRole." + role.name()); + } + return rh; + } + /** + * @param targetClass the class of the to be manipulated node + * @param role defines the to be manipulated attribute + * @return {@link RoleHandler} implementation which knows how to manipulate the attribute of {@link CtRole} on `targetClass` + * or returns null if such role does not exists on the `targetClass` + */ + public static RoleHandler getOptionalRoleHandler(Class targetClass, CtRole role) { + List handlers = roleHandlers[role.ordinal()]; + for (RoleHandler ctRoleHandler : handlers) { + if (ctRoleHandler.getTargetType().isAssignableFrom(targetClass)) { + return ctRoleHandler; + } + } + return null; + } +} diff --git a/src/main/java/spoon/support/reflect/declaration/CtElementImpl.java b/src/main/java/spoon/support/reflect/declaration/CtElementImpl.java index ce3cadc5270..cb4a6d4f11d 100644 --- a/src/main/java/spoon/support/reflect/declaration/CtElementImpl.java +++ b/src/main/java/spoon/support/reflect/declaration/CtElementImpl.java @@ -26,6 +26,8 @@ import spoon.reflect.declaration.ParentNotInitializedException; import spoon.reflect.factory.Factory; import spoon.reflect.factory.FactoryImpl; +import spoon.reflect.meta.RoleHandler; +import spoon.reflect.meta.impl.RoleHandlerProvider; import spoon.reflect.path.CtRole; import spoon.reflect.reference.CtReference; import spoon.reflect.reference.CtTypeReference; @@ -496,4 +498,41 @@ public E setComments(List comments) { public CtElement clone() { return CloneHelper.INSTANCE.clone(this); } + + @Override + public T getValueByRole(CtRole role) { + RoleHandler rh = RoleHandlerProvider.getRoleHandler(this.getClass(), role); + return rh.getValue(this); + } + + @Override + public Collection getValueByRoleAsCollection(CtRole role) { + RoleHandler rh = RoleHandlerProvider.getRoleHandler(this.getClass(), role); + return rh.asCollection(this); + } + + @Override + public List getValueByRoleAsList(CtRole role) { + RoleHandler rh = RoleHandlerProvider.getRoleHandler(this.getClass(), role); + return rh.asList(this); + } + + @Override + public Set getValueByRoleAsSet(CtRole role) { + RoleHandler rh = RoleHandlerProvider.getRoleHandler(this.getClass(), role); + return rh.asSet(this); + } + + @Override + public Map getValueByRoleAsMap(CtRole role) { + RoleHandler rh = RoleHandlerProvider.getRoleHandler(this.getClass(), role); + return rh.asMap(this); + } + + @Override + public E setValueByRole(CtRole role, T value) { + RoleHandler rh = RoleHandlerProvider.getRoleHandler(this.getClass(), role); + rh.setValue(this, value); + return (E) this; + } } diff --git a/src/test/java/spoon/generating/RoleHandlersGenerator.java b/src/test/java/spoon/generating/RoleHandlersGenerator.java new file mode 100644 index 00000000000..62e8366ee6f --- /dev/null +++ b/src/test/java/spoon/generating/RoleHandlersGenerator.java @@ -0,0 +1,205 @@ +/** + * 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.generating; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStreamWriter; +import java.io.Writer; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import spoon.SpoonException; +import spoon.processing.AbstractManualProcessor; +import spoon.reflect.code.CtNewArray; +import spoon.reflect.declaration.CtClass; +import spoon.reflect.declaration.CtType; +import spoon.reflect.declaration.ModifierKind; +import spoon.reflect.path.CtRole; +import spoon.reflect.reference.CtTypeParameterReference; +import spoon.reflect.reference.CtTypeReference; +import spoon.reflect.reference.CtWildcardReference; +import spoon.reflect.visitor.PrinterHelper; +import spoon.template.Substitution; +import spoon.test.metamodel.MMField; +import spoon.test.metamodel.MMMethod; +import spoon.test.metamodel.MMMethodKind; +import spoon.test.metamodel.SpoonMetaModel; + +public class RoleHandlersGenerator extends AbstractManualProcessor { + public static final String TARGET_PACKAGE = "spoon.reflect.meta.impl"; + + // Class[] helperIfaces = new Class[]{CtBodyHolder.class, + // CtTypeInformation.class, CtNamedElement.class}; + Map methodsByTypeRoleHandler = new HashMap<>(); + + @Override + public void process() { + SpoonMetaModel metaModel = new SpoonMetaModel(getFactory()); + + //all root super MMFields + List superFields = new ArrayList<>(); + + metaModel.getMMTypes().forEach(mmType -> { + mmType.getRole2field().forEach((role, rim) -> { + addUniqueObject(superFields, rim.getRootSuperField()); + }); + }); + + superFields.sort((a, b) -> { + int d = a.getRole().ordinal() - b.getRole().ordinal(); + if (d != 0) { + return d; + } + return a.getOwnerType().getName().compareTo(b.getOwnerType().getName()); + }); + PrinterHelper concept = new PrinterHelper(getFactory().getEnvironment()); + superFields.forEach(mmField -> { + concept.write(mmField.getOwnerType().getName() + " CtRole." + mmField.getRole().name()).writeln().incTab() + .write("ItemType: ").write(mmField.getValueType().toString()).writeln(); + for (MMMethodKind mk : MMMethodKind.values()) { + MMMethod mmMethod = mmField.getMethod(mk); + if (mmMethod != null) { + concept.write(mk.name()).write(": ").write(mmMethod.getSignature()).write(" : ").write(mmMethod.getReturnType().toString()).writeln(); + } + } + concept.decTab(); + concept.write("----------------------------------------------------------").writeln(); + }); + try (Writer w = new OutputStreamWriter(new FileOutputStream(file("target/report/concept.txt")))) { + w.write(concept.toString()); + } catch (IOException e) { + throw new RuntimeException(e); + } + + CtType template = getTemplate("spoon.generating.meta.ModelRoleHandlerTemplate"); + + CtClass modelRoleHandlersClass = Substitution.createTypeFromTemplate( + TARGET_PACKAGE + ".ModelRoleHandlers", + template, + new HashMap<>()); + CtNewArray roleHandlersFieldExpr = (CtNewArray) modelRoleHandlersClass.getField("roleHandlers").getDefaultExpression(); + superFields.forEach(rim -> { + Map params = new HashMap<>(); + params.put("$getterName$", rim.getMethod(MMMethodKind.GET).getName()); + if (rim.getMethod(MMMethodKind.SET) != null) { + params.put("$setterName$", rim.getMethod(MMMethodKind.SET).getName()); + } + params.put("$Role$", getFactory().Type().createReference(CtRole.class)); + params.put("ROLE", rim.getRole().name()); + params.put("$TargetType$", rim.getOwnerType().getModelInteface().getReference()); +// params.put("AbstractHandler", getFactory().Type().createReference("spoon.reflect.meta.impl.AbstractRoleHandler")); + params.put("AbstractHandler", getRoleHandlerSuperTypeQName(rim)); + params.put("Node", rim.getOwnerType().getModelInteface().getReference()); + params.put("ValueType", fixMainValueType(getRoleHandlerSuperTypeQName(rim).endsWith("SingleHandler") ? rim.getValueType() : rim.getItemValueType())); + CtClass modelRoleHandlerClass = Substitution.createTypeFromTemplate( + getHandlerName(rim), + getTemplate("spoon.generating.meta.RoleHandlerTemplate"), + params); + if (rim.getMethod(MMMethodKind.SET) == null) { + modelRoleHandlerClass.getMethodsByName("setValue").forEach(m -> m.delete()); + } + modelRoleHandlerClass.addModifier(ModifierKind.STATIC); + modelRoleHandlersClass.addNestedType(modelRoleHandlerClass); + roleHandlersFieldExpr.addElement(getFactory().createCodeSnippetExpression("new " + modelRoleHandlerClass.getSimpleName() + "()")); + }); + } + + private CtTypeReference fixMainValueType(CtTypeReference valueType) { + valueType = fixValueType(valueType); + if (valueType instanceof CtWildcardReference) { + return getFactory().Type().OBJECT; + } + return valueType; + } + private CtTypeReference fixValueType(CtTypeReference valueType) { + valueType = valueType.clone(); + if (valueType instanceof CtTypeParameterReference) { + if (valueType instanceof CtWildcardReference) { + CtTypeReference boundingType = ((CtTypeParameterReference) valueType).getBoundingType(); + if (boundingType instanceof CtTypeParameterReference) { + ((CtTypeParameterReference) valueType).setBoundingType(null); + } + return valueType; + } + CtTypeParameterReference tpr = (CtTypeParameterReference) valueType; + return getFactory().createWildcardReference(); + } + for (int i = 0; i < valueType.getActualTypeArguments().size(); i++) { + valueType.getActualTypeArguments().set(i, fixValueType(valueType.getActualTypeArguments().get(i))); + } + valueType = valueType.box(); + return valueType; + } + + private CtType getTemplate(String templateQName) { + CtType template = getFactory().Class().get(templateQName); + return template; + } + + private File file(String name) { + File f = new File(name); + f.getParentFile().mkdirs(); + return f; + } + + private static boolean containsObject(Iterable iter, Object o) { + for (Object object : iter) { + if (object == o) { + return true; + } + } + return false; + } + + /** + * + * @param col + * @param o + * @return true if added + */ + private boolean addUniqueObject(Collection col, T o) { + if (containsObject(col, o)) { + return false; + } + col.add(o); + return true; + } + + String getHandlerName(MMField field) { + String typeName = field.getOwnerType().getName(); + return typeName + "_" + field.getRole().name() + "_RoleHandler"; + } + + public String getRoleHandlerSuperTypeQName(MMField field) { + switch (field.getValueContainerType()) { + case LIST: + return "spoon.reflect.meta.impl.AbstractRoleHandler.ListHandler"; + case SET: + return "spoon.reflect.meta.impl.AbstractRoleHandler.SetHandler"; + case MAP: + return "spoon.reflect.meta.impl.AbstractRoleHandler.MapHandler"; + case SINGLE: + return "spoon.reflect.meta.impl.AbstractRoleHandler.SingleHandler"; + } + throw new SpoonException("Unexpected value container type: " + field.getValueContainerType().name()); + } +} diff --git a/src/test/java/spoon/generating/meta/ModelRoleHandlerTemplate.java b/src/test/java/spoon/generating/meta/ModelRoleHandlerTemplate.java new file mode 100644 index 00000000000..14459785839 --- /dev/null +++ b/src/test/java/spoon/generating/meta/ModelRoleHandlerTemplate.java @@ -0,0 +1,31 @@ +/** + * 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.generating.meta; + +import spoon.reflect.meta.RoleHandler; +import spoon.reflect.path.CtRole; + +/** + * Contains implementations of {@link RoleHandler}s for all {@link CtRole}s of all model elements + */ +class ModelRoleHandlerTemplate { + + private ModelRoleHandlerTemplate() { + } + + static final RoleHandler[] roleHandlers = new RoleHandler[] { }; +} diff --git a/src/test/java/spoon/generating/meta/RoleHandlerTemplate.java b/src/test/java/spoon/generating/meta/RoleHandlerTemplate.java new file mode 100644 index 00000000000..077befa7460 --- /dev/null +++ b/src/test/java/spoon/generating/meta/RoleHandlerTemplate.java @@ -0,0 +1,119 @@ +/** + * 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.generating.meta; + +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import spoon.reflect.meta.ContainerKind; +import spoon.reflect.meta.RoleHandler; +import spoon.reflect.path.CtRole; + +class RoleHandlerTemplate extends AbstractHandler { + + private RoleHandlerTemplate() { + super($Role$.ROLE, $TargetType$.class, ValueType.class); + } + + @SuppressWarnings("unchecked") + @Override + public U getValue(T element) { + return (U) (Object) castTarget(element).$getterName$(); + } + + @Override + public void setValue(T element, U value) { + castTarget(element).$setterName$(castValue(value)); + } +} + +enum $Role$ { + ROLE +} + +class $TargetType$ { +} + +class Node { + ValueType $getterName$() { + return null; + } + void $setterName$(ValueType value) { + } +} + +class ValueType { +} + +class AbstractHandler implements RoleHandler { + + AbstractHandler($Role$ role, Class targetClass, Class valueClass) { + } + T castTarget(Object e) { + return null; + } + U castValue(Object value) { + return null; + } + @Override + public CtRole getRole() { + return null; + } + @Override + public Class getTargetType() { + return null; + } + @Override + public U getValue(T element) { + return null; + } + @Override + public void setValue(T element, U value) { + } + @Override + public Class getValueClass() { + // TODO Auto-generated method stub + return null; + } + @Override + public ContainerKind getContainerKind() { + // TODO Auto-generated method stub + return null; + } + @Override + public Collection asCollection(T element) { + // TODO Auto-generated method stub + return null; + } + @Override + public Set asSet(T element) { + // TODO Auto-generated method stub + return null; + } + @Override + public List asList(T element) { + // TODO Auto-generated method stub + return null; + } + @Override + public Map asMap(T element) { + // TODO Auto-generated method stub + return null; + } +} From 7912506f971d49e959ee514e0974cc8c1d1ab533 Mon Sep 17 00:00:00 2001 From: Pavel Vojtechovsky Date: Tue, 24 Oct 2017 21:59:23 +0200 Subject: [PATCH 02/14] tests --- src/test/java/spoon/MavenLauncherTest.java | 2 +- .../spoon/processing/CtGenerationTest.java | 36 +++ .../spoon/reflect/ast/AstCheckerTest.java | 2 + .../test/reflect/meta/MetaModelTest.java | 235 ++++++++++++++++++ 4 files changed, 274 insertions(+), 1 deletion(-) create mode 100644 src/test/java/spoon/test/reflect/meta/MetaModelTest.java diff --git a/src/test/java/spoon/MavenLauncherTest.java b/src/test/java/spoon/MavenLauncherTest.java index 40c9169fc10..e4a3e227fa4 100644 --- a/src/test/java/spoon/MavenLauncherTest.java +++ b/src/test/java/spoon/MavenLauncherTest.java @@ -13,7 +13,7 @@ public void spoonMavenLauncherTest() { assertEquals(5, launcher.getEnvironment().getSourceClasspath().length); // 54 because of the sub folders of src/main/java - assertEquals(50, launcher.getModelBuilder().getInputSources().size()); + assertTrue(54 < launcher.getModelBuilder().getInputSources().size()); // with the tests launcher = new MavenLauncher("./", MavenLauncher.SOURCE_TYPE.ALL_SOURCE); diff --git a/src/test/java/spoon/processing/CtGenerationTest.java b/src/test/java/spoon/processing/CtGenerationTest.java index ee35488bd29..beef47174be 100644 --- a/src/test/java/spoon/processing/CtGenerationTest.java +++ b/src/test/java/spoon/processing/CtGenerationTest.java @@ -6,6 +6,7 @@ import spoon.generating.CloneVisitorGenerator; import spoon.generating.CtBiScannerGenerator; import spoon.generating.ReplacementVisitorGenerator; +import spoon.generating.RoleHandlersGenerator; import spoon.reflect.declaration.CtClass; import spoon.reflect.declaration.CtType; import spoon.reflect.visitor.CtBiScannerDefault; @@ -133,6 +134,41 @@ public void testGenerateCloneVisitor() throws Exception { throw new ComparisonFailure("CloneVisitor different", expected.toString(), actual.toString()); } } + + @Test + public void testGenerateRoleHandler() throws Exception { + //use always LINUX line separator, because generated files are committed to Spoon repository which expects that. + System.setProperty("line.separator", "\n"); + final Launcher launcher = new Launcher(); + launcher.getEnvironment().setAutoImports(true); + launcher.getEnvironment().setNoClasspath(true); + launcher.getEnvironment().setCommentEnabled(true); + launcher.getEnvironment().setCopyResources(false); + launcher.getEnvironment().useTabulations(true); + //launcher.getEnvironment().setAutoImports(true); + launcher.setSourceOutputDirectory("./target/generated/"); + // Spoon model interfaces + launcher.addInputResource("./src/main/java/spoon/reflect/code"); + launcher.addInputResource("./src/main/java/spoon/reflect/declaration"); + launcher.addInputResource("./src/main/java/spoon/reflect/reference"); + launcher.addInputResource("./src/main/java/spoon/reflect/internal"); + // Templates + launcher.addInputResource("./src/test/java/spoon/generating/meta"); + // Linked classes + launcher.addInputResource("./src/main/java/spoon/reflect/meta/impl/AbstractRoleHandler.java"); + launcher.addProcessor(new RoleHandlersGenerator()); + launcher.setOutputFilter(new RegexFilter("\\Q" + RoleHandlersGenerator.TARGET_PACKAGE + ".ModelRoleHandlers\\E.*")); + launcher.run(); + + CtClass actual = build(new File(launcher.getModelBuilder().getSourceOutputDirectory()+"/spoon/reflect/meta/impl/ModelRoleHandlers.java")).Class().get("spoon.reflect.meta.impl.ModelRoleHandlers"); + CtClass expected = build(new File("./src/main/java/spoon/reflect/meta/impl/ModelRoleHandlers.java")).Class().get("spoon.reflect.meta.impl.ModelRoleHandlers"); + try { + assertThat(actual).isEqualTo(expected); + } catch (AssertionError e) { + throw new ComparisonFailure("ModelRoleHandlers different", expected.toString(), actual.toString()); + } + } + private class RegexFilter implements Filter> { private final Pattern regex; diff --git a/src/test/java/spoon/reflect/ast/AstCheckerTest.java b/src/test/java/spoon/reflect/ast/AstCheckerTest.java index 6e206e5574f..bbae34916c3 100644 --- a/src/test/java/spoon/reflect/ast/AstCheckerTest.java +++ b/src/test/java/spoon/reflect/ast/AstCheckerTest.java @@ -116,9 +116,11 @@ private class PushStackInIntercessionChecker extends CtScanner { "CtElementImpl#setPositions", // "CtElementImpl#setDocComment", // "CtElementImpl#setParent", // + "CtElementImpl#setValueByRole", // "CtTypeParameterReferenceImpl#addBound", // "CtTypeParameterReferenceImpl#removeBound", // "CtTypeParameterReferenceImpl#setBounds" // + ); } diff --git a/src/test/java/spoon/test/reflect/meta/MetaModelTest.java b/src/test/java/spoon/test/reflect/meta/MetaModelTest.java new file mode 100644 index 00000000000..756c2984db7 --- /dev/null +++ b/src/test/java/spoon/test/reflect/meta/MetaModelTest.java @@ -0,0 +1,235 @@ +package spoon.test.reflect.meta; + +import org.junit.Test; + +import spoon.Launcher; +import spoon.reflect.declaration.CtAnnotation; +import spoon.reflect.declaration.CtClass; +import spoon.reflect.declaration.CtElement; +import spoon.reflect.factory.Factory; +import spoon.reflect.meta.ContainerKind; +import spoon.reflect.meta.RoleHandler; +import spoon.reflect.meta.impl.RoleHandlerProvider; +import spoon.reflect.path.CtRole; +import spoon.reflect.reference.CtReference; +import spoon.template.Parameter; +import spoon.test.metamodel.MMMethodKind; +import spoon.test.metamodel.SpoonMetaModel; + +import static org.junit.Assert.*; + +import java.io.File; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +public class MetaModelTest { + + @Test + public void spoonMetaModelTest() { + /* + * this test reports all spoon model elements which are not yet handled by meta model + * actually this is the result +Unhandled method signature: CtParameter#setVisibility(spoon.reflect.declaration.ModifierKind) +Unhandled method signature: CtElement#getAnnotation(java.lang.Class) +Unhandled method signature: CtElement#getAnnotation(java.lang.Class) +Unhandled method signature: CtElement#getAnnotation(spoon.reflect.reference.CtTypeReference) +Unhandled method signature: CtElement#getAnnotation(spoon.reflect.reference.CtTypeReference) +Unhandled method signature: CtConstructor#setVisibility(spoon.reflect.declaration.ModifierKind) +Unhandled method signature: CtModifiable#setVisibility(spoon.reflect.declaration.ModifierKind) +Unhandled method signature: CtAnonymousExecutable#setVisibility(spoon.reflect.declaration.ModifierKind) +Unhandled method signature: CtJavaDoc#removeTag(int) +Unhandled method signature: CtJavaDoc#removeTag(int) +Unhandled method signature: CtStatementList#insertEnd(spoon.reflect.code.CtStatement) +Unhandled method signature: CtStatementList#insertEnd(spoon.reflect.code.CtStatement) +Unhandled method signature: CtStatementList#insertEnd(spoon.reflect.code.CtStatementList) +Unhandled method signature: CtStatementList#insertEnd(spoon.reflect.code.CtStatementList) +Unhandled method signature: CtStatementList#insertBegin(spoon.reflect.code.CtStatementList) +Unhandled method signature: CtStatementList#insertBegin(spoon.reflect.code.CtStatementList) +Unhandled method signature: CtClass#getConstructor(spoon.reflect.reference.CtTypeReference[]) +Unhandled method signature: CtClass#getConstructor(spoon.reflect.reference.CtTypeReference[]) +Unhandled method signature: CtBlock#insertEnd(spoon.reflect.code.CtStatementList) +Unhandled method signature: CtBlock#addStatement(spoon.reflect.code.CtStatement) +Unhandled method signature: CtBlock#insertBegin(spoon.reflect.code.CtStatementList) +Unhandled method signature: CtTypeParameterReference#setBounds(java.util.List) +Unhandled method signature: CtTypeParameterReference#setBounds(java.util.List) +Unhandled method signature: CtTypeParameter#setVisibility(spoon.reflect.declaration.ModifierKind) +Unhandled method signature: CtTypeParameter#getMethod(spoon.reflect.reference.CtTypeReference,java.lang.String,spoon.reflect.reference.CtTypeReference[]) +Unhandled method signature: CtTypeParameter#getMethod(java.lang.String,spoon.reflect.reference.CtTypeReference[]) +Unhandled method signature: CtTypeParameter#getMethodsAnnotatedWith(spoon.reflect.reference.CtTypeReference[]) +Unhandled method signature: CtLocalVariable#setVisibility(spoon.reflect.declaration.ModifierKind) +Unhandled method signature: CtType#setVisibility(spoon.reflect.declaration.ModifierKind) +Unhandled method signature: CtType#getMethod(spoon.reflect.reference.CtTypeReference,java.lang.String,spoon.reflect.reference.CtTypeReference[]) +Unhandled method signature: CtType#getMethod(spoon.reflect.reference.CtTypeReference,java.lang.String,spoon.reflect.reference.CtTypeReference[]) +Unhandled method signature: CtType#getMethod(java.lang.String,spoon.reflect.reference.CtTypeReference[]) +Unhandled method signature: CtType#getMethod(java.lang.String,spoon.reflect.reference.CtTypeReference[]) +Unhandled method signature: CtType#getMethodsAnnotatedWith(spoon.reflect.reference.CtTypeReference[]) +Unhandled method signature: CtType#getMethodsAnnotatedWith(spoon.reflect.reference.CtTypeReference[]) +Unhandled method signature: CtCase#insertEnd(spoon.reflect.code.CtStatement) +Unhandled method signature: CtCase#insertEnd(spoon.reflect.code.CtStatementList) +Unhandled method signature: CtCase#insertBegin(spoon.reflect.code.CtStatementList) +Unhandled method signature: CtMethod#setVisibility(spoon.reflect.declaration.ModifierKind) +Unhandled method signature: CtJavaDocTag#setType(java.lang.String) +Unhandled method signature: CtJavaDocTag#setType(java.lang.String) +Unhandled method signature: CtField#setVisibility(spoon.reflect.declaration.ModifierKind) +Unhandled method signature: CtAnnotation#setElementValues(java.util.Map) +Unhandled method signature: CtAnnotation#setElementValues(java.util.Map) +Unhandled method signature: CtAnnotation#addValue(java.lang.String,java.lang.Object) +Unhandled method signature: CtAnnotation#addValue(java.lang.String,java.lang.Object) +Unhandled method signature: CtAnnotation#addValue(java.lang.String,spoon.reflect.code.CtLiteral) +Unhandled method signature: CtAnnotation#addValue(java.lang.String,spoon.reflect.code.CtLiteral) +Unhandled method signature: CtAnnotation#addValue(java.lang.String,spoon.reflect.code.CtNewArray) +Unhandled method signature: CtAnnotation#addValue(java.lang.String,spoon.reflect.code.CtNewArray) +Unhandled method signature: CtAnnotation#addValue(java.lang.String,spoon.reflect.code.CtFieldAccess) +Unhandled method signature: CtAnnotation#addValue(java.lang.String,spoon.reflect.code.CtFieldAccess) +Unhandled method signature: CtAnnotation#addValue(java.lang.String,spoon.reflect.declaration.CtAnnotation) +Unhandled method signature: CtAnnotation#addValue(java.lang.String,spoon.reflect.declaration.CtAnnotation) +Unhandled method signature: CtEnum#getMethod(java.lang.String,spoon.reflect.reference.CtTypeReference[]) +Unhandled method signature: CtEnum#getMethod(spoon.reflect.reference.CtTypeReference,java.lang.String,spoon.reflect.reference.CtTypeReference[]) +Unhandled method signature: CtCatchVariable#setType(spoon.reflect.reference.CtTypeReference) +Unhandled method signature: CtCatchVariable#getType() +Unhandled method signature: CtCatchVariable#setVisibility(spoon.reflect.declaration.ModifierKind) + */ + if(false) { + //enable this test after everything is covered. + SpoonMetaModel mm = new SpoonMetaModel(new File("./src/main/java")); + List problems = new ArrayList<>(); + + //detect unused CtRoles + Set unhandledRoles = new HashSet<>(Arrays.asList(CtRole.values())); + + mm.getMMTypes().forEach(mmType -> { + mmType.getRole2field().forEach((role, mmField) -> { + unhandledRoles.remove(role); + if (mmField.getMethod(MMMethodKind.GET) == null) { + problems.add("Missing getter for " + mmField.getOwnerType().getName() + " and CtRole." + mmField.getRole()); + } + if (mmField.getMethod(MMMethodKind.SET) == null) { + if (mmType.getTypeContext().isSubtypeOf(mm.getFactory().Type().createReference(CtReference.class)) == false + && mmType.getName().equals("CtTypeInformation") == false) { + //only NON references needs a setter + problems.add("Missing setter for " + mmField.getOwnerType().getName() + " and CtRole." + mmField.getRole()); + } + } + + mmField.forEachUnhandledMethod(ctMethod -> problems.add("Unhandled method signature: " + mmType.getName() + "#" + ctMethod.getSignature())); + }); + }); + + unhandledRoles.forEach(it -> problems.add("Unused CtRole." + it.name())); + + assertTrue(String.join("\n", problems), problems.isEmpty()); + } + } + @Test + public void elementAnnotationRoleHandlerTest() { + Launcher launcher = new Launcher(); + Factory factory = launcher.getFactory(); + CtClass type = (CtClass) factory.Core().create(CtClass.class); + CtAnnotation annotation = factory.Annotation().annotate(type, Parameter.class, "value", "abc"); + + //check contract of low level RoleHandler + RoleHandler roleHandler = RoleHandlerProvider.getRoleHandler(type.getClass(), CtRole.ANNOTATION); + assertNotNull(roleHandler); + assertEquals(CtElement.class, roleHandler.getTargetType()); + assertSame(CtRole.ANNOTATION, roleHandler.getRole()); + assertSame(ContainerKind.LIST, roleHandler.getContainerKind()); + assertEquals(CtAnnotation.class, roleHandler.getValueClass()); + + //check getting value using role handler + List> value = roleHandler.getValue(type); + assertEquals(1, value.size()); + assertSame(annotation, value.get(0)); + + //check we have got direct readonly List + try { + value.remove(annotation); + fail(); + } catch (Exception e) { + this.getClass(); + } + + //check setValueByRole + roleHandler.setValue(type, Collections.emptyList()); + value = roleHandler.getValue(type); + assertEquals(0, value.size()); + + roleHandler.setValue(type, Collections.singletonList(annotation)); + value = roleHandler.getValue(type); + assertEquals(1, value.size()); + assertSame(annotation, value.get(0)); + + try { + //contract value must be a list of annotation. One annotation is not actually OK. This contract might be changed in future + roleHandler.setValue(type, annotation); + fail(); + } catch (ClassCastException e) { + //OK + } + } + + @Test + public void elementAnnotationRoleTest() { + Launcher launcher = new Launcher(); + Factory factory = launcher.getFactory(); + CtClass type = (CtClass) factory.Core().create(CtClass.class); + CtAnnotation annotation = factory.Annotation().annotate(type, Parameter.class, "value", "abc"); + + //check direct getValueByRole + List> value = type.getValueByRole(CtRole.ANNOTATION); + assertEquals(1, value.size()); + assertSame(annotation, value.get(0)); + + try { + value.remove(annotation); + fail(); + } catch (Exception e) { + this.getClass(); + } + + //check setValueByRole + type.setValueByRole(CtRole.ANNOTATION, Collections.emptyList()); + value = type.getValueByRole(CtRole.ANNOTATION); + assertEquals(0, value.size()); + + type.setValueByRole(CtRole.ANNOTATION, Collections.singletonList(annotation)); + value = type.getValueByRole(CtRole.ANNOTATION); + assertEquals(1, value.size()); + assertSame(annotation, value.get(0)); + + try { + //contract value must be a list of annotation. One annotation is not actually OK. This contract might be changed in future + type.setValueByRole(CtRole.ANNOTATION, annotation); + fail(); + } catch (ClassCastException e) { + //OK + } + } + @Test + public void elementAnnotationAdaptedRoleTest() { + Launcher launcher = new Launcher(); + Factory factory = launcher.getFactory(); + CtClass type = (CtClass) factory.Core().create(CtClass.class); + CtAnnotation annotation = factory.Annotation().annotate(type, Parameter.class, "value", "abc"); + + //check adaptation of attribute to modifiable List + List> value = type.getValueByRoleAsList(CtRole.ANNOTATION); + assertEquals(1, value.size()); + assertSame(annotation, value.get(0)); + + //check we can remove from this collection + value.remove(annotation); + assertEquals(0, value.size()); + assertEquals(0, ((List) type.getValueByRole(CtRole.ANNOTATION)).size()); + + //check we can add to this collection + value.add(annotation); + assertEquals(1, value.size()); + assertSame(annotation, value.get(0)); + assertEquals(1, ((List) type.getValueByRole(CtRole.ANNOTATION)).size()); + assertEquals(annotation, ((List) type.getValueByRole(CtRole.ANNOTATION)).get(0)); + } +} From 504be242f747375b54f3a8f52c166052a4b48d25 Mon Sep 17 00:00:00 2001 From: Pavel Vojtechovsky Date: Mon, 6 Nov 2017 20:26:21 +0100 Subject: [PATCH 03/14] ignore the test and move the report of problems into #1691 --- .../test/reflect/meta/MetaModelTest.java | 123 +++++------------- 1 file changed, 32 insertions(+), 91 deletions(-) diff --git a/src/test/java/spoon/test/reflect/meta/MetaModelTest.java b/src/test/java/spoon/test/reflect/meta/MetaModelTest.java index 756c2984db7..791b59088ec 100644 --- a/src/test/java/spoon/test/reflect/meta/MetaModelTest.java +++ b/src/test/java/spoon/test/reflect/meta/MetaModelTest.java @@ -1,5 +1,6 @@ package spoon.test.reflect.meta; +import org.junit.Ignore; import org.junit.Test; import spoon.Launcher; @@ -28,101 +29,41 @@ public class MetaModelTest { + /* + * this test reports all spoon model elements which are not yet handled by meta model + * actually this is the result + */ + //enable this test after everything is covered. @Test + @Ignore public void spoonMetaModelTest() { - /* - * this test reports all spoon model elements which are not yet handled by meta model - * actually this is the result -Unhandled method signature: CtParameter#setVisibility(spoon.reflect.declaration.ModifierKind) -Unhandled method signature: CtElement#getAnnotation(java.lang.Class) -Unhandled method signature: CtElement#getAnnotation(java.lang.Class) -Unhandled method signature: CtElement#getAnnotation(spoon.reflect.reference.CtTypeReference) -Unhandled method signature: CtElement#getAnnotation(spoon.reflect.reference.CtTypeReference) -Unhandled method signature: CtConstructor#setVisibility(spoon.reflect.declaration.ModifierKind) -Unhandled method signature: CtModifiable#setVisibility(spoon.reflect.declaration.ModifierKind) -Unhandled method signature: CtAnonymousExecutable#setVisibility(spoon.reflect.declaration.ModifierKind) -Unhandled method signature: CtJavaDoc#removeTag(int) -Unhandled method signature: CtJavaDoc#removeTag(int) -Unhandled method signature: CtStatementList#insertEnd(spoon.reflect.code.CtStatement) -Unhandled method signature: CtStatementList#insertEnd(spoon.reflect.code.CtStatement) -Unhandled method signature: CtStatementList#insertEnd(spoon.reflect.code.CtStatementList) -Unhandled method signature: CtStatementList#insertEnd(spoon.reflect.code.CtStatementList) -Unhandled method signature: CtStatementList#insertBegin(spoon.reflect.code.CtStatementList) -Unhandled method signature: CtStatementList#insertBegin(spoon.reflect.code.CtStatementList) -Unhandled method signature: CtClass#getConstructor(spoon.reflect.reference.CtTypeReference[]) -Unhandled method signature: CtClass#getConstructor(spoon.reflect.reference.CtTypeReference[]) -Unhandled method signature: CtBlock#insertEnd(spoon.reflect.code.CtStatementList) -Unhandled method signature: CtBlock#addStatement(spoon.reflect.code.CtStatement) -Unhandled method signature: CtBlock#insertBegin(spoon.reflect.code.CtStatementList) -Unhandled method signature: CtTypeParameterReference#setBounds(java.util.List) -Unhandled method signature: CtTypeParameterReference#setBounds(java.util.List) -Unhandled method signature: CtTypeParameter#setVisibility(spoon.reflect.declaration.ModifierKind) -Unhandled method signature: CtTypeParameter#getMethod(spoon.reflect.reference.CtTypeReference,java.lang.String,spoon.reflect.reference.CtTypeReference[]) -Unhandled method signature: CtTypeParameter#getMethod(java.lang.String,spoon.reflect.reference.CtTypeReference[]) -Unhandled method signature: CtTypeParameter#getMethodsAnnotatedWith(spoon.reflect.reference.CtTypeReference[]) -Unhandled method signature: CtLocalVariable#setVisibility(spoon.reflect.declaration.ModifierKind) -Unhandled method signature: CtType#setVisibility(spoon.reflect.declaration.ModifierKind) -Unhandled method signature: CtType#getMethod(spoon.reflect.reference.CtTypeReference,java.lang.String,spoon.reflect.reference.CtTypeReference[]) -Unhandled method signature: CtType#getMethod(spoon.reflect.reference.CtTypeReference,java.lang.String,spoon.reflect.reference.CtTypeReference[]) -Unhandled method signature: CtType#getMethod(java.lang.String,spoon.reflect.reference.CtTypeReference[]) -Unhandled method signature: CtType#getMethod(java.lang.String,spoon.reflect.reference.CtTypeReference[]) -Unhandled method signature: CtType#getMethodsAnnotatedWith(spoon.reflect.reference.CtTypeReference[]) -Unhandled method signature: CtType#getMethodsAnnotatedWith(spoon.reflect.reference.CtTypeReference[]) -Unhandled method signature: CtCase#insertEnd(spoon.reflect.code.CtStatement) -Unhandled method signature: CtCase#insertEnd(spoon.reflect.code.CtStatementList) -Unhandled method signature: CtCase#insertBegin(spoon.reflect.code.CtStatementList) -Unhandled method signature: CtMethod#setVisibility(spoon.reflect.declaration.ModifierKind) -Unhandled method signature: CtJavaDocTag#setType(java.lang.String) -Unhandled method signature: CtJavaDocTag#setType(java.lang.String) -Unhandled method signature: CtField#setVisibility(spoon.reflect.declaration.ModifierKind) -Unhandled method signature: CtAnnotation#setElementValues(java.util.Map) -Unhandled method signature: CtAnnotation#setElementValues(java.util.Map) -Unhandled method signature: CtAnnotation#addValue(java.lang.String,java.lang.Object) -Unhandled method signature: CtAnnotation#addValue(java.lang.String,java.lang.Object) -Unhandled method signature: CtAnnotation#addValue(java.lang.String,spoon.reflect.code.CtLiteral) -Unhandled method signature: CtAnnotation#addValue(java.lang.String,spoon.reflect.code.CtLiteral) -Unhandled method signature: CtAnnotation#addValue(java.lang.String,spoon.reflect.code.CtNewArray) -Unhandled method signature: CtAnnotation#addValue(java.lang.String,spoon.reflect.code.CtNewArray) -Unhandled method signature: CtAnnotation#addValue(java.lang.String,spoon.reflect.code.CtFieldAccess) -Unhandled method signature: CtAnnotation#addValue(java.lang.String,spoon.reflect.code.CtFieldAccess) -Unhandled method signature: CtAnnotation#addValue(java.lang.String,spoon.reflect.declaration.CtAnnotation) -Unhandled method signature: CtAnnotation#addValue(java.lang.String,spoon.reflect.declaration.CtAnnotation) -Unhandled method signature: CtEnum#getMethod(java.lang.String,spoon.reflect.reference.CtTypeReference[]) -Unhandled method signature: CtEnum#getMethod(spoon.reflect.reference.CtTypeReference,java.lang.String,spoon.reflect.reference.CtTypeReference[]) -Unhandled method signature: CtCatchVariable#setType(spoon.reflect.reference.CtTypeReference) -Unhandled method signature: CtCatchVariable#getType() -Unhandled method signature: CtCatchVariable#setVisibility(spoon.reflect.declaration.ModifierKind) - */ - if(false) { - //enable this test after everything is covered. - SpoonMetaModel mm = new SpoonMetaModel(new File("./src/main/java")); - List problems = new ArrayList<>(); - - //detect unused CtRoles - Set unhandledRoles = new HashSet<>(Arrays.asList(CtRole.values())); + SpoonMetaModel mm = new SpoonMetaModel(new File("./src/main/java")); + List problems = new ArrayList<>(); + + //detect unused CtRoles + Set unhandledRoles = new HashSet<>(Arrays.asList(CtRole.values())); - mm.getMMTypes().forEach(mmType -> { - mmType.getRole2field().forEach((role, mmField) -> { - unhandledRoles.remove(role); - if (mmField.getMethod(MMMethodKind.GET) == null) { - problems.add("Missing getter for " + mmField.getOwnerType().getName() + " and CtRole." + mmField.getRole()); - } - if (mmField.getMethod(MMMethodKind.SET) == null) { - if (mmType.getTypeContext().isSubtypeOf(mm.getFactory().Type().createReference(CtReference.class)) == false - && mmType.getName().equals("CtTypeInformation") == false) { - //only NON references needs a setter - problems.add("Missing setter for " + mmField.getOwnerType().getName() + " and CtRole." + mmField.getRole()); - } - } - - mmField.forEachUnhandledMethod(ctMethod -> problems.add("Unhandled method signature: " + mmType.getName() + "#" + ctMethod.getSignature())); - }); + mm.getMMTypes().forEach(mmType -> { + mmType.getRole2field().forEach((role, mmField) -> { + unhandledRoles.remove(role); + if (mmField.getMethod(MMMethodKind.GET) == null) { + problems.add("Missing getter for " + mmField.getOwnerType().getName() + " and CtRole." + mmField.getRole()); + } + if (mmField.getMethod(MMMethodKind.SET) == null) { + if (mmType.getTypeContext().isSubtypeOf(mm.getFactory().Type().createReference(CtReference.class)) == false + && mmType.getName().equals("CtTypeInformation") == false) { + //only NON references needs a setter + problems.add("Missing setter for " + mmField.getOwnerType().getName() + " and CtRole." + mmField.getRole()); + } + } + + mmField.forEachUnhandledMethod(ctMethod -> problems.add("Unhandled method signature: " + ctMethod.getDeclaringType().getSimpleName() + "#" + ctMethod.getSignature())); }); - - unhandledRoles.forEach(it -> problems.add("Unused CtRole." + it.name())); - - assertTrue(String.join("\n", problems), problems.isEmpty()); - } + }); + + unhandledRoles.forEach(it -> problems.add("Unused CtRole." + it.name())); + + assertTrue(String.join("\n", problems), problems.isEmpty()); } @Test public void elementAnnotationRoleHandlerTest() { From ac8ded6994483c3386f39f2cd2ab531135e8f359 Mon Sep 17 00:00:00 2001 From: Pavel Vojtechovsky Date: Mon, 6 Nov 2017 21:11:57 +0100 Subject: [PATCH 04/14] fix number of folders in test --- src/test/java/spoon/MavenLauncherTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/spoon/MavenLauncherTest.java b/src/test/java/spoon/MavenLauncherTest.java index e4a3e227fa4..45f9510392c 100644 --- a/src/test/java/spoon/MavenLauncherTest.java +++ b/src/test/java/spoon/MavenLauncherTest.java @@ -12,8 +12,8 @@ public void spoonMavenLauncherTest() { MavenLauncher launcher = new MavenLauncher("./", MavenLauncher.SOURCE_TYPE.APP_SOURCE); assertEquals(5, launcher.getEnvironment().getSourceClasspath().length); - // 54 because of the sub folders of src/main/java - assertTrue(54 < launcher.getModelBuilder().getInputSources().size()); + // 52 because of the sub folders of src/main/java + assertEquals(52, launcher.getModelBuilder().getInputSources().size()); // with the tests launcher = new MavenLauncher("./", MavenLauncher.SOURCE_TYPE.ALL_SOURCE); From 47db6a769206ddac21c158d1522ddaf0fe8e38b3 Mon Sep 17 00:00:00 2001 From: Martin Monperrus Date: Wed, 8 Nov 2017 21:33:52 +0100 Subject: [PATCH 05/14] Update RoleHandler.java --- src/main/java/spoon/reflect/meta/RoleHandler.java | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/main/java/spoon/reflect/meta/RoleHandler.java b/src/main/java/spoon/reflect/meta/RoleHandler.java index 86ad2bf5a93..3a2a8f77db1 100644 --- a/src/main/java/spoon/reflect/meta/RoleHandler.java +++ b/src/main/java/spoon/reflect/meta/RoleHandler.java @@ -24,17 +24,10 @@ import spoon.reflect.path.CtRole; /** - * Has all knowledge about a role of an target type + * Enables the user to get and set a field based on a rol for a CtElement */ public interface RoleHandler { - /** - * @return a role of this handler - */ - CtRole getRole(); - /** - * @return a type of the class, which this handler can be applied to - */ - Class getTargetType(); + // the main methods, responsible to get and set the field corresponding to this role /** * @param element a element whose value will be get * @return a value of the element on the role defined by {@link #getRole()} @@ -45,6 +38,8 @@ public interface RoleHandler { * @param value new value, which will be assigned to the element's attribute defined by role defined by {@link #getRole()} */ void setValue(T element, U value); + + // introspection methods /** * @return a Class of value of the attribute of {@link #getTargetType()} defined by {@link #getRole()} */ @@ -55,6 +50,7 @@ public interface RoleHandler { */ ContainerKind getContainerKind(); + // utility methods Collection asCollection(T element); Set asSet(T element); List asList(T element); From f28040f4032d9cd5321d5bec6575593f757b1399 Mon Sep 17 00:00:00 2001 From: Martin Monperrus Date: Wed, 8 Nov 2017 21:42:06 +0100 Subject: [PATCH 06/14] Update RoleHandler.java --- src/main/java/spoon/reflect/meta/RoleHandler.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main/java/spoon/reflect/meta/RoleHandler.java b/src/main/java/spoon/reflect/meta/RoleHandler.java index 3a2a8f77db1..9d885e70eb6 100644 --- a/src/main/java/spoon/reflect/meta/RoleHandler.java +++ b/src/main/java/spoon/reflect/meta/RoleHandler.java @@ -40,6 +40,16 @@ public interface RoleHandler { void setValue(T element, U value); // introspection methods + /** + * @return a role of this handler + */ + CtRole getRole(); + + /** + * @return a type of the class, which this handler can be applied to + */ + Class getTargetType(); + /** * @return a Class of value of the attribute of {@link #getTargetType()} defined by {@link #getRole()} */ From 7eed056d1f38b358d71b6d5d7c07ac4f7afc8f26 Mon Sep 17 00:00:00 2001 From: Martin Monperrus Date: Wed, 8 Nov 2017 21:50:30 +0100 Subject: [PATCH 07/14] Update RoleHandler.java --- src/main/java/spoon/reflect/meta/RoleHandler.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/spoon/reflect/meta/RoleHandler.java b/src/main/java/spoon/reflect/meta/RoleHandler.java index 9d885e70eb6..ab6205d1a93 100644 --- a/src/main/java/spoon/reflect/meta/RoleHandler.java +++ b/src/main/java/spoon/reflect/meta/RoleHandler.java @@ -38,18 +38,18 @@ public interface RoleHandler { * @param value new value, which will be assigned to the element's attribute defined by role defined by {@link #getRole()} */ void setValue(T element, U value); - + // introspection methods /** * @return a role of this handler */ CtRole getRole(); - + /** * @return a type of the class, which this handler can be applied to */ Class getTargetType(); - + /** * @return a Class of value of the attribute of {@link #getTargetType()} defined by {@link #getRole()} */ From 6c64be7ce98d5b7a936674d2ca02c8a57d867358 Mon Sep 17 00:00:00 2001 From: Pavel Vojtechovsky Date: Wed, 8 Nov 2017 21:59:09 +0100 Subject: [PATCH 08/14] add missing Override annotations --- .../java/spoon/reflect/meta/impl/AbstractRoleHandler.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/java/spoon/reflect/meta/impl/AbstractRoleHandler.java b/src/main/java/spoon/reflect/meta/impl/AbstractRoleHandler.java index d382b92ce0c..29bc597c9d1 100644 --- a/src/main/java/spoon/reflect/meta/impl/AbstractRoleHandler.java +++ b/src/main/java/spoon/reflect/meta/impl/AbstractRoleHandler.java @@ -96,14 +96,17 @@ public Class getValueClass() { return valueClass; } + @Override public List asList(W element) { throw new SpoonException("The value of CtRole." + getRole().name() + " cannot be adapted to List for " + element.getClass().getSimpleName()); }; + @Override public Set asSet(W element) { throw new SpoonException("The value of CtRole." + getRole().name() + " cannot be adapted to Set for " + element.getClass().getSimpleName()); }; + @Override public Map asMap(W element) { throw new SpoonException("The value of CtRole." + getRole().name() + " cannot be adapted to Map for " + element.getClass().getSimpleName()); }; @@ -159,10 +162,12 @@ protected List castValue(Object value) { return list; } + @Override public java.util.Collection asCollection(W element) { return asList(element); }; + @Override public java.util.List asList(W e) { return new AbstractList() { T element = castTarget(e); @@ -243,6 +248,7 @@ protected Set castValue(Object value) { return set; } + @Override public Collection asCollection(W element) { return asSet(element); }; @@ -330,6 +336,7 @@ protected Map castValue(Object value) { return map; } + @Override @SuppressWarnings({ "unchecked", "rawtypes" }) public java.util.Collection asCollection(W element) { return (Collection) asMap(element).values(); From e4134f4d61ce15fbd8c2dd1fd682c2a08dde1dff Mon Sep 17 00:00:00 2001 From: Pavel Vojtechovsky Date: Wed, 8 Nov 2017 22:08:04 +0100 Subject: [PATCH 09/14] rename RoleHandlerProvider to RoleHandlerHelper --- ...HandlerProvider.java => RoleHandlerHelper.java} | 4 ++-- .../support/reflect/declaration/CtElementImpl.java | 14 +++++++------- .../spoon/test/reflect/meta/MetaModelTest.java | 4 ++-- 3 files changed, 11 insertions(+), 11 deletions(-) rename src/main/java/spoon/reflect/meta/impl/{RoleHandlerProvider.java => RoleHandlerHelper.java} (97%) diff --git a/src/main/java/spoon/reflect/meta/impl/RoleHandlerProvider.java b/src/main/java/spoon/reflect/meta/impl/RoleHandlerHelper.java similarity index 97% rename from src/main/java/spoon/reflect/meta/impl/RoleHandlerProvider.java rename to src/main/java/spoon/reflect/meta/impl/RoleHandlerHelper.java index 18f67efeee7..d34e164b317 100644 --- a/src/main/java/spoon/reflect/meta/impl/RoleHandlerProvider.java +++ b/src/main/java/spoon/reflect/meta/impl/RoleHandlerHelper.java @@ -28,8 +28,8 @@ * Provides a {@link RoleHandler} implementation for the pair of {@link CtElement} implementation and {@link CtRole} * The returned {@link RoleHandler} can be then used to manipulate value of attribute represented by {@link CtRole} on the {@link CtElement} instance */ -public class RoleHandlerProvider { - private RoleHandlerProvider() { +public class RoleHandlerHelper { + private RoleHandlerHelper() { } @SuppressWarnings("unchecked") diff --git a/src/main/java/spoon/support/reflect/declaration/CtElementImpl.java b/src/main/java/spoon/support/reflect/declaration/CtElementImpl.java index cb4a6d4f11d..359b28cc6ee 100644 --- a/src/main/java/spoon/support/reflect/declaration/CtElementImpl.java +++ b/src/main/java/spoon/support/reflect/declaration/CtElementImpl.java @@ -27,7 +27,7 @@ import spoon.reflect.factory.Factory; import spoon.reflect.factory.FactoryImpl; import spoon.reflect.meta.RoleHandler; -import spoon.reflect.meta.impl.RoleHandlerProvider; +import spoon.reflect.meta.impl.RoleHandlerHelper; import spoon.reflect.path.CtRole; import spoon.reflect.reference.CtReference; import spoon.reflect.reference.CtTypeReference; @@ -501,37 +501,37 @@ public CtElement clone() { @Override public T getValueByRole(CtRole role) { - RoleHandler rh = RoleHandlerProvider.getRoleHandler(this.getClass(), role); + RoleHandler rh = RoleHandlerHelper.getRoleHandler(this.getClass(), role); return rh.getValue(this); } @Override public Collection getValueByRoleAsCollection(CtRole role) { - RoleHandler rh = RoleHandlerProvider.getRoleHandler(this.getClass(), role); + RoleHandler rh = RoleHandlerHelper.getRoleHandler(this.getClass(), role); return rh.asCollection(this); } @Override public List getValueByRoleAsList(CtRole role) { - RoleHandler rh = RoleHandlerProvider.getRoleHandler(this.getClass(), role); + RoleHandler rh = RoleHandlerHelper.getRoleHandler(this.getClass(), role); return rh.asList(this); } @Override public Set getValueByRoleAsSet(CtRole role) { - RoleHandler rh = RoleHandlerProvider.getRoleHandler(this.getClass(), role); + RoleHandler rh = RoleHandlerHelper.getRoleHandler(this.getClass(), role); return rh.asSet(this); } @Override public Map getValueByRoleAsMap(CtRole role) { - RoleHandler rh = RoleHandlerProvider.getRoleHandler(this.getClass(), role); + RoleHandler rh = RoleHandlerHelper.getRoleHandler(this.getClass(), role); return rh.asMap(this); } @Override public E setValueByRole(CtRole role, T value) { - RoleHandler rh = RoleHandlerProvider.getRoleHandler(this.getClass(), role); + RoleHandler rh = RoleHandlerHelper.getRoleHandler(this.getClass(), role); rh.setValue(this, value); return (E) this; } diff --git a/src/test/java/spoon/test/reflect/meta/MetaModelTest.java b/src/test/java/spoon/test/reflect/meta/MetaModelTest.java index 791b59088ec..ede19272d2a 100644 --- a/src/test/java/spoon/test/reflect/meta/MetaModelTest.java +++ b/src/test/java/spoon/test/reflect/meta/MetaModelTest.java @@ -10,7 +10,7 @@ import spoon.reflect.factory.Factory; import spoon.reflect.meta.ContainerKind; import spoon.reflect.meta.RoleHandler; -import spoon.reflect.meta.impl.RoleHandlerProvider; +import spoon.reflect.meta.impl.RoleHandlerHelper; import spoon.reflect.path.CtRole; import spoon.reflect.reference.CtReference; import spoon.template.Parameter; @@ -73,7 +73,7 @@ public void elementAnnotationRoleHandlerTest() { CtAnnotation annotation = factory.Annotation().annotate(type, Parameter.class, "value", "abc"); //check contract of low level RoleHandler - RoleHandler roleHandler = RoleHandlerProvider.getRoleHandler(type.getClass(), CtRole.ANNOTATION); + RoleHandler roleHandler = RoleHandlerHelper.getRoleHandler(type.getClass(), CtRole.ANNOTATION); assertNotNull(roleHandler); assertEquals(CtElement.class, roleHandler.getTargetType()); assertSame(CtRole.ANNOTATION, roleHandler.getRole()); From f7f577fd92812ee30564544c9f565b6adb517cda Mon Sep 17 00:00:00 2001 From: Martin Monperrus Date: Wed, 8 Nov 2017 23:42:30 +0100 Subject: [PATCH 10/14] up --- .../spoon/reflect/declaration/CtElement.java | 36 +++++-------------- .../java/spoon/reflect/meta/RoleHandler.java | 33 +++++++++++++---- .../reflect/declaration/CtElementImpl.java | 24 ------------- 3 files changed, 35 insertions(+), 58 deletions(-) diff --git a/src/main/java/spoon/reflect/declaration/CtElement.java b/src/main/java/spoon/reflect/declaration/CtElement.java index 76a81d4e350..e192fb426e6 100644 --- a/src/main/java/spoon/reflect/declaration/CtElement.java +++ b/src/main/java/spoon/reflect/declaration/CtElement.java @@ -317,37 +317,19 @@ List getAnnotatedChildren( CtElement clone(); /** - * @param role defines, which attribute has to be returned - * @return a value of the `role` attribute of this model node. - * It can return a single value, List, Set or Map depending on this `element` and `role`. - * In all cases the returned value is READ ONLY + * @return a a single value (eg a CtElement), List, Set or Map depending on this `element` and `role`. Returned collections are read-only. + * @param the role of the returned attribute with respect to this element. + * + * For instance, "klass.getValueByRole(CtRole.METHOD)" returns a list of methods. + * + * See {@link spoon.reflect.meta.impl.RoleHandlerHelper} for more advanced methods. */ T getValueByRole(CtRole role); /** - * @param role defines, which attribute has to be returned - * @return a value of the `role` attribute of this model node adapted to modifiable Collection - */ - Collection getValueByRoleAsCollection(CtRole role); - /** - * @param role defines, which attribute has to be returned - * @return a value of the `role` attribute of this model node adapted to modifiable List - */ - List getValueByRoleAsList(CtRole role); - /** - * @param role defines, which attribute has to be returned - * @return a value of the `role` attribute of this model node adapted to modifiable Set - */ - Set getValueByRoleAsSet(CtRole role); - /** - * @param role defines, which attribute has to be returned - * @return a value of the `role` attribute of this model node adapted to modifiable Map - */ - Map getValueByRoleAsMap(CtRole role); - - /** - * @param role defines, which attribute has to be returned - * @param value to be assigned value + * Sets a field according to a role. + * @param the role of the field to be set + * @param value to be assigned to this field. */ E setValueByRole(CtRole role, T value); } diff --git a/src/main/java/spoon/reflect/meta/RoleHandler.java b/src/main/java/spoon/reflect/meta/RoleHandler.java index ab6205d1a93..990a32d18c3 100644 --- a/src/main/java/spoon/reflect/meta/RoleHandler.java +++ b/src/main/java/spoon/reflect/meta/RoleHandler.java @@ -24,45 +24,64 @@ import spoon.reflect.path.CtRole; /** - * Enables the user to get and set a field based on a rol for a CtElement + * Enables client code to get and set a field based on a role for a CtElement. + * + * One obtains instances of {@link RoleHandler} using the methods of {@link spoon.reflect.meta.impl.RoleHandlerHelper}. + * + * There is one role handler per role of {@link CtRole}, they are set by {@link spoon.reflect.meta.impl.RoleHandlerHelper}. */ public interface RoleHandler { // the main methods, responsible to get and set the field corresponding to this role /** - * @param element a element whose value will be get + * @param element a element from which the value will be get for this role * @return a value of the element on the role defined by {@link #getRole()} */ U getValue(T element); /** - * @param element a element whose value will be set + * @param element a element whose value will be set for this role * @param value new value, which will be assigned to the element's attribute defined by role defined by {@link #getRole()} */ void setValue(T element, U value); // introspection methods /** - * @return a role of this handler + * @return the role handled by this handler */ CtRole getRole(); /** - * @return a type of the class, which this handler can be applied to + * @return the type of the class, which this handler can be applied to (eg CtMethod) */ Class getTargetType(); /** - * @return a Class of value of the attribute of {@link #getTargetType()} defined by {@link #getRole()} + * @return the type of returned value defined by {@link #getRole()} */ Class getValueClass(); /** - * @return true if value can contain only one element. It is not a collection or map + * @return the container kind, to know whether an element, a list, a map, etc is returned. */ ContainerKind getContainerKind(); // utility methods + /** + * @return a value for this role adapted as a modifiable Collection + */ Collection asCollection(T element); + + /** + * @return a value for this role adapted as a modifiable Set + */ Set asSet(T element); + + /** + * @return a value for this role adapted as a modifiable List + */ List asList(T element); + + /** + * @return a value for this role adapted as a modifiable Map + */ Map asMap(T element); } diff --git a/src/main/java/spoon/support/reflect/declaration/CtElementImpl.java b/src/main/java/spoon/support/reflect/declaration/CtElementImpl.java index 359b28cc6ee..20059abf9c5 100644 --- a/src/main/java/spoon/support/reflect/declaration/CtElementImpl.java +++ b/src/main/java/spoon/support/reflect/declaration/CtElementImpl.java @@ -505,30 +505,6 @@ public T getValueByRole(CtRole role) { return rh.getValue(this); } - @Override - public Collection getValueByRoleAsCollection(CtRole role) { - RoleHandler rh = RoleHandlerHelper.getRoleHandler(this.getClass(), role); - return rh.asCollection(this); - } - - @Override - public List getValueByRoleAsList(CtRole role) { - RoleHandler rh = RoleHandlerHelper.getRoleHandler(this.getClass(), role); - return rh.asList(this); - } - - @Override - public Set getValueByRoleAsSet(CtRole role) { - RoleHandler rh = RoleHandlerHelper.getRoleHandler(this.getClass(), role); - return rh.asSet(this); - } - - @Override - public Map getValueByRoleAsMap(CtRole role) { - RoleHandler rh = RoleHandlerHelper.getRoleHandler(this.getClass(), role); - return rh.asMap(this); - } - @Override public E setValueByRole(CtRole role, T value) { RoleHandler rh = RoleHandlerHelper.getRoleHandler(this.getClass(), role); From f1ede5d48905fc7ab16aa2cc16ba90d3ef660542 Mon Sep 17 00:00:00 2001 From: Martin Monperrus Date: Wed, 8 Nov 2017 23:58:29 +0100 Subject: [PATCH 11/14] up --- src/test/java/spoon/test/reflect/meta/MetaModelTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/test/java/spoon/test/reflect/meta/MetaModelTest.java b/src/test/java/spoon/test/reflect/meta/MetaModelTest.java index ede19272d2a..f5b76c529ff 100644 --- a/src/test/java/spoon/test/reflect/meta/MetaModelTest.java +++ b/src/test/java/spoon/test/reflect/meta/MetaModelTest.java @@ -7,6 +7,7 @@ import spoon.reflect.declaration.CtAnnotation; import spoon.reflect.declaration.CtClass; import spoon.reflect.declaration.CtElement; +import spoon.reflect.declaration.CtType; import spoon.reflect.factory.Factory; import spoon.reflect.meta.ContainerKind; import spoon.reflect.meta.RoleHandler; @@ -157,7 +158,7 @@ public void elementAnnotationAdaptedRoleTest() { CtAnnotation annotation = factory.Annotation().annotate(type, Parameter.class, "value", "abc"); //check adaptation of attribute to modifiable List - List> value = type.getValueByRoleAsList(CtRole.ANNOTATION); + List> value = RoleHandlerHelper.getRoleHandler(CtType.class, CtRole.ANNOTATION).asList(type); assertEquals(1, value.size()); assertSame(annotation, value.get(0)); From f2635634d27eef1b0c4f150ab4cbb9dd13a13455 Mon Sep 17 00:00:00 2001 From: Martin Monperrus Date: Wed, 8 Nov 2017 23:59:03 +0100 Subject: [PATCH 12/14] up --- src/test/java/spoon/test/reflect/meta/MetaModelTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/spoon/test/reflect/meta/MetaModelTest.java b/src/test/java/spoon/test/reflect/meta/MetaModelTest.java index f5b76c529ff..7da1cbf38e7 100644 --- a/src/test/java/spoon/test/reflect/meta/MetaModelTest.java +++ b/src/test/java/spoon/test/reflect/meta/MetaModelTest.java @@ -158,7 +158,7 @@ public void elementAnnotationAdaptedRoleTest() { CtAnnotation annotation = factory.Annotation().annotate(type, Parameter.class, "value", "abc"); //check adaptation of attribute to modifiable List - List> value = RoleHandlerHelper.getRoleHandler(CtType.class, CtRole.ANNOTATION).asList(type); + List> value = RoleHandlerHelper.getRoleHandler(type.getClass(), CtRole.ANNOTATION).asList(type); assertEquals(1, value.size()); assertSame(annotation, value.get(0)); From 1498392240366251316d1a5f0d7a77a076c0e3b0 Mon Sep 17 00:00:00 2001 From: Pavel Vojtechovsky Date: Thu, 9 Nov 2017 19:25:36 +0100 Subject: [PATCH 13/14] remove unused import --- src/main/java/spoon/reflect/declaration/CtElement.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/spoon/reflect/declaration/CtElement.java b/src/main/java/spoon/reflect/declaration/CtElement.java index e192fb426e6..09d363a3885 100644 --- a/src/main/java/spoon/reflect/declaration/CtElement.java +++ b/src/main/java/spoon/reflect/declaration/CtElement.java @@ -32,7 +32,6 @@ import java.lang.annotation.Annotation; import java.util.Collection; import java.util.List; -import java.util.Map; import java.util.Set; import static spoon.reflect.path.CtRole.ANNOTATION; From 8f2e84f0815743c7eaaaf169117eff08a8f20a60 Mon Sep 17 00:00:00 2001 From: Martin Monperrus Date: Thu, 9 Nov 2017 20:29:09 +0100 Subject: [PATCH 14/14] up --- doc/filter.md | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/doc/filter.md b/doc/filter.md index 238c9e216d7..b0b753074e5 100644 --- a/doc/filter.md +++ b/doc/filter.md @@ -1,10 +1,26 @@ --- -title: Filter +title: Navigation and Query tags: [quering] keywords: quering, query, filter, ast, elements --- -Spoon gives developers a way to query code elements. + +Getters +------- + +All elements provide a set of appropriate getters to get the children of an element. + + +```java +methods = ctClass.getMethods(); +``` + +In addition, there exists a generic getter based on the role played by an element with respect to its parent. See CtRole for a complete list of roles. + +```java +methods = ctClass.getValueByRole(CtRole.METHOD); +``` + Filters ------- @@ -120,4 +136,4 @@ It is faster then `query.list().get(0)`, because query engine does not collect o ```java // returns first deprecated element CtElement firstDeprecated = rootPackage.filterChildren(new AnnotationFilter(Deprecated.class)).first(); -``` \ No newline at end of file +```