From bc798c1e362fd6cbf286257a915064a99e659a68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9rard=20Paligot?= Date: Thu, 26 May 2016 10:19:06 +0200 Subject: [PATCH] refactor(clone): Adds the handy CtElement#clone (and deprecates CoreFactory#clone) --- .../generating/replace/ReplaceScanner.java | 6 +- .../reflect/code/CtAnnotationFieldAccess.java | 6 +- .../spoon/reflect/code/CtArrayAccess.java | 3 + .../java/spoon/reflect/code/CtArrayRead.java | 2 + .../java/spoon/reflect/code/CtArrayWrite.java | 2 + .../java/spoon/reflect/code/CtAssert.java | 3 + .../java/spoon/reflect/code/CtAssignment.java | 6 +- .../spoon/reflect/code/CtBinaryOperator.java | 3 + src/main/java/spoon/reflect/code/CtBlock.java | 3 + src/main/java/spoon/reflect/code/CtBreak.java | 3 + src/main/java/spoon/reflect/code/CtCase.java | 3 + src/main/java/spoon/reflect/code/CtCatch.java | 3 + .../spoon/reflect/code/CtCatchVariable.java | 3 + .../spoon/reflect/code/CtCodeElement.java | 2 + .../reflect/code/CtCodeSnippetExpression.java | 4 +- .../reflect/code/CtCodeSnippetStatement.java | 4 +- .../java/spoon/reflect/code/CtComment.java | 3 + .../spoon/reflect/code/CtConditional.java | 3 + .../spoon/reflect/code/CtConstructorCall.java | 2 + .../java/spoon/reflect/code/CtContinue.java | 3 + src/main/java/spoon/reflect/code/CtDo.java | 3 + .../code/CtExecutableReferenceExpression.java | 3 + .../java/spoon/reflect/code/CtExpression.java | 6 +- .../spoon/reflect/code/CtFieldAccess.java | 3 + .../java/spoon/reflect/code/CtFieldRead.java | 2 + .../java/spoon/reflect/code/CtFieldWrite.java | 2 + src/main/java/spoon/reflect/code/CtFor.java | 2 + .../java/spoon/reflect/code/CtForEach.java | 3 + src/main/java/spoon/reflect/code/CtIf.java | 3 + .../java/spoon/reflect/code/CtInvocation.java | 3 + .../java/spoon/reflect/code/CtLambda.java | 3 + .../java/spoon/reflect/code/CtLiteral.java | 2 + .../spoon/reflect/code/CtLocalVariable.java | 3 + src/main/java/spoon/reflect/code/CtLoop.java | 3 + .../java/spoon/reflect/code/CtNewArray.java | 2 + .../java/spoon/reflect/code/CtNewClass.java | 2 + .../reflect/code/CtOperatorAssignment.java | 3 + .../java/spoon/reflect/code/CtReturn.java | 3 + .../java/spoon/reflect/code/CtStatement.java | 3 + .../spoon/reflect/code/CtStatementList.java | 3 + .../spoon/reflect/code/CtSuperAccess.java | 2 + .../java/spoon/reflect/code/CtSwitch.java | 3 + .../spoon/reflect/code/CtSynchronized.java | 3 + .../reflect/code/CtTargetedExpression.java | 7 +- .../java/spoon/reflect/code/CtThisAccess.java | 2 + src/main/java/spoon/reflect/code/CtThrow.java | 3 + src/main/java/spoon/reflect/code/CtTry.java | 7 +- .../spoon/reflect/code/CtTryWithResource.java | 3 + .../java/spoon/reflect/code/CtTypeAccess.java | 3 + .../spoon/reflect/code/CtUnaryOperator.java | 3 + .../spoon/reflect/code/CtVariableAccess.java | 3 + .../spoon/reflect/code/CtVariableRead.java | 2 + .../spoon/reflect/code/CtVariableWrite.java | 2 + src/main/java/spoon/reflect/code/CtWhile.java | 3 + .../reflect/declaration/CtAnnotation.java | 3 + .../reflect/declaration/CtAnnotationType.java | 2 + .../declaration/CtAnonymousExecutable.java | 2 + .../spoon/reflect/declaration/CtClass.java | 9 ++- .../reflect/declaration/CtConstructor.java | 3 + .../spoon/reflect/declaration/CtElement.java | 7 +- .../spoon/reflect/declaration/CtEnum.java | 3 + .../reflect/declaration/CtEnumValue.java | 2 + .../reflect/declaration/CtExecutable.java | 3 + .../spoon/reflect/declaration/CtField.java | 3 + .../reflect/declaration/CtInterface.java | 2 + .../spoon/reflect/declaration/CtMethod.java | 3 + .../reflect/declaration/CtNamedElement.java | 3 + .../spoon/reflect/declaration/CtPackage.java | 3 + .../reflect/declaration/CtParameter.java | 3 + .../spoon/reflect/declaration/CtType.java | 2 + .../spoon/reflect/factory/CodeFactory.java | 13 ++-- .../reflect/factory/ConstructorFactory.java | 10 +-- .../spoon/reflect/factory/CoreFactory.java | 2 + .../reflect/factory/ExecutableFactory.java | 6 +- .../spoon/reflect/factory/FieldFactory.java | 2 +- .../spoon/reflect/factory/MethodFactory.java | 16 ++-- .../spoon/reflect/factory/TypeFactory.java | 4 +- .../internal/CtCircularTypeReference.java | 2 + .../reference/CtArrayTypeReference.java | 3 + .../reference/CtCatchVariableReference.java | 3 + .../reference/CtExecutableReference.java | 3 + .../reflect/reference/CtFieldReference.java | 3 + .../CtIntersectionTypeReference.java | 3 + .../reference/CtLocalVariableReference.java | 3 + .../reflect/reference/CtPackageReference.java | 3 + .../reference/CtParameterReference.java | 3 + .../spoon/reflect/reference/CtReference.java | 3 + .../reference/CtTypeParameterReference.java | 3 + .../reflect/reference/CtTypeReference.java | 3 + .../reference/CtUnboundVariableReference.java | 3 +- .../reference/CtVariableReference.java | 3 + .../spoon/support/DefaultCoreFactory.java | 2 +- .../support/compiler/jdt/JDTTreeBuilder.java | 7 +- .../support/compiler/jdt/ParentExiter.java | 4 +- .../code/CtAnnotationFieldAccessImpl.java | 8 +- .../reflect/code/CtArrayAccessImpl.java | 9 ++- .../support/reflect/code/CtArrayReadImpl.java | 8 +- .../reflect/code/CtArrayWriteImpl.java | 8 +- .../support/reflect/code/CtAssertImpl.java | 5 ++ .../reflect/code/CtAssignmentImpl.java | 7 +- .../reflect/code/CtBinaryOperatorImpl.java | 5 ++ .../support/reflect/code/CtBlockImpl.java | 7 +- .../support/reflect/code/CtBreakImpl.java | 5 ++ .../support/reflect/code/CtCaseImpl.java | 13 +++- .../support/reflect/code/CtCatchImpl.java | 4 + .../reflect/code/CtCatchVariableImpl.java | 8 +- .../reflect/code/CtCodeElementImpl.java | 7 +- .../code/CtCodeSnippetExpressionImpl.java | 7 +- .../code/CtCodeSnippetStatementImpl.java | 7 +- .../support/reflect/code/CtCommentImpl.java | 5 ++ .../reflect/code/CtConditionalImpl.java | 5 ++ .../reflect/code/CtConstructorCallImpl.java | 8 +- .../support/reflect/code/CtContinueImpl.java | 4 + .../spoon/support/reflect/code/CtDoImpl.java | 5 ++ .../CtExecutableReferenceExpressionImpl.java | 8 +- .../reflect/code/CtExpressionImpl.java | 8 +- .../reflect/code/CtFieldAccessImpl.java | 5 ++ .../support/reflect/code/CtFieldReadImpl.java | 5 ++ .../reflect/code/CtFieldWriteImpl.java | 5 ++ .../support/reflect/code/CtForEachImpl.java | 5 ++ .../spoon/support/reflect/code/CtForImpl.java | 16 ++-- .../spoon/support/reflect/code/CtIfImpl.java | 7 +- .../reflect/code/CtInvocationImpl.java | 5 ++ .../support/reflect/code/CtLambdaImpl.java | 5 ++ .../support/reflect/code/CtLiteralImpl.java | 7 +- .../reflect/code/CtLocalVariableImpl.java | 5 ++ .../support/reflect/code/CtLoopImpl.java | 7 +- .../support/reflect/code/CtNewArrayImpl.java | 14 ++-- .../support/reflect/code/CtNewClassImpl.java | 5 ++ .../code/CtOperatorAssignmentImpl.java | 8 +- .../support/reflect/code/CtReturnImpl.java | 7 +- .../support/reflect/code/CtStatementImpl.java | 5 ++ .../reflect/code/CtStatementListImpl.java | 15 ++-- .../reflect/code/CtSuperAccessImpl.java | 5 ++ .../support/reflect/code/CtSwitchImpl.java | 10 ++- .../reflect/code/CtSynchronizedImpl.java | 5 ++ .../code/CtTargetedExpressionImpl.java | 8 +- .../reflect/code/CtThisAccessImpl.java | 4 + .../support/reflect/code/CtThrowImpl.java | 7 +- .../spoon/support/reflect/code/CtTryImpl.java | 13 +++- .../reflect/code/CtTryWithResourceImpl.java | 8 +- .../reflect/code/CtTypeAccessImpl.java | 7 +- .../reflect/code/CtUnaryOperatorImpl.java | 5 ++ .../reflect/code/CtVariableAccessImpl.java | 5 ++ .../reflect/code/CtVariableReadImpl.java | 5 ++ .../reflect/code/CtVariableWriteImpl.java | 5 ++ .../support/reflect/code/CtWhileImpl.java | 5 ++ .../reflect/declaration/CtAnnotationImpl.java | 7 +- .../declaration/CtAnnotationTypeImpl.java | 11 ++- .../CtAnonymousExecutableImpl.java | 5 ++ .../reflect/declaration/CtClassImpl.java | 5 ++ .../declaration/CtConstructorImpl.java | 5 ++ .../reflect/declaration/CtElementImpl.java | 5 ++ .../reflect/declaration/CtEnumImpl.java | 5 ++ .../reflect/declaration/CtEnumValueImpl.java | 5 ++ .../reflect/declaration/CtExecutableImpl.java | 5 ++ .../reflect/declaration/CtFieldImpl.java | 5 ++ .../reflect/declaration/CtInterfaceImpl.java | 14 ++-- .../reflect/declaration/CtMethodImpl.java | 5 ++ .../declaration/CtNamedElementImpl.java | 5 ++ .../reflect/declaration/CtPackageImpl.java | 11 ++- .../reflect/declaration/CtParameterImpl.java | 5 ++ .../reflect/declaration/CtTypeImpl.java | 5 ++ .../declaration/CtUncomparableException.java | 37 ---------- .../reflect/eval/VisitorPartialEvaluator.java | 56 +++++++------- .../internal/CtCircularTypeReferenceImpl.java | 5 ++ .../reference/CtArrayTypeReferenceImpl.java | 7 +- .../CtCatchVariableReferenceImpl.java | 8 +- .../reference/CtExecutableReferenceImpl.java | 8 +- .../reference/CtFieldReferenceImpl.java | 7 +- .../CtIntersectionTypeReferenceImpl.java | 5 ++ .../CtLocalVariableReferenceImpl.java | 7 +- .../reference/CtPackageReferenceImpl.java | 7 +- .../reference/CtParameterReferenceImpl.java | 8 +- .../reflect/reference/CtReferenceImpl.java | 5 ++ .../CtTypeParameterReferenceImpl.java | 5 ++ .../reference/CtTypeReferenceImpl.java | 5 ++ .../CtUnboundVariableReferenceImpl.java | 9 ++- .../reference/CtVariableReferenceImpl.java | 8 +- .../support/template/SubstitutionVisitor.java | 12 +-- .../spoon/template/StatementTemplate.java | 5 +- .../java/spoon/template/Substitution.java | 8 +- .../template/TypedBlockTemplateParameter.java | 2 +- .../TypedStatementListTemplateParameter.java | 2 +- .../java/spoon/reflect/ast/CloneTest.java | 73 +++++++++++++++++++ .../java/spoon/test/api/AwesomeProcessor.java | 2 +- .../java/spoon/test/factory/FactoryTest.java | 43 ++++++----- .../test/intercession/IntercessionTest.java | 25 +++---- .../insertBefore/InsertMethodsTest.java | 4 +- .../spoon/test/parent/ParentContractTest.java | 2 +- .../spoon/test/signature/SignatureTest.java | 8 +- 191 files changed, 895 insertions(+), 280 deletions(-) delete mode 100644 src/main/java/spoon/support/reflect/declaration/CtUncomparableException.java create mode 100644 src/test/java/spoon/reflect/ast/CloneTest.java diff --git a/src/main/java/spoon/generating/replace/ReplaceScanner.java b/src/main/java/spoon/generating/replace/ReplaceScanner.java index 385ba9f93db..1140b5a004e 100644 --- a/src/main/java/spoon/generating/replace/ReplaceScanner.java +++ b/src/main/java/spoon/generating/replace/ReplaceScanner.java @@ -71,7 +71,7 @@ public void visitCtMethod(CtMethod element) { } Factory factory = element.getFactory(); - CtMethod clone = factory.Core().clone(element); + CtMethod clone = element.clone(); clone.getBody().getStatements().clear(); for (int i = 1; i < element.getBody().getStatements().size() - 1; i++) { CtInvocation inv = element.getBody().getStatement(i); @@ -129,7 +129,7 @@ private CtTypeReference getGetterType(Factory factory, CtInvocation getter) { if (type instanceof CtTypeParameterReference) { getterType = getTypeFromTypeParameterReference((CtTypeParameterReference) getter.getExecutable().getDeclaration().getType()); } else { - getterType = factory.Core().clone(type); + getterType = type.clone(); } getterType.getActualTypeArguments().clear(); return getterType; @@ -153,7 +153,7 @@ private CtTypeReference getTypeFromTypeParameterReference(CtTypeParameterReferen private CtClass createListenerClass(Factory factory, String listenerName, CtTypeReference getterType, Type type) { CtClass listener; - listener = factory.Core().clone(factory.Class().get(GENERATING_REPLACE_PACKAGE + ".CtListener")); + listener = factory.Class().get(GENERATING_REPLACE_PACKAGE + ".CtListener").clone(); listener.setSimpleName(listenerName); target.addNestedType(listener); final List references = listener.getReferences(new ReferenceFilter() { diff --git a/src/main/java/spoon/reflect/code/CtAnnotationFieldAccess.java b/src/main/java/spoon/reflect/code/CtAnnotationFieldAccess.java index e7302869e2a..2be47764eea 100644 --- a/src/main/java/spoon/reflect/code/CtAnnotationFieldAccess.java +++ b/src/main/java/spoon/reflect/code/CtAnnotationFieldAccess.java @@ -24,7 +24,9 @@ * @param * Type of this field */ -public interface CtAnnotationFieldAccess - extends CtVariableRead, CtTargetedExpression> { +public interface CtAnnotationFieldAccess extends CtVariableRead, CtTargetedExpression> { CtFieldReference getVariable(); + + @Override + CtAnnotationFieldAccess clone(); } diff --git a/src/main/java/spoon/reflect/code/CtArrayAccess.java b/src/main/java/spoon/reflect/code/CtArrayAccess.java index e66e1b3f2d1..95861ff5448 100644 --- a/src/main/java/spoon/reflect/code/CtArrayAccess.java +++ b/src/main/java/spoon/reflect/code/CtArrayAccess.java @@ -37,4 +37,7 @@ public interface CtArrayAccess> extends CtTargetedE * Returns the expression that defines the index. */ CtExpression getIndexExpression(); + + @Override + CtArrayAccess clone(); } diff --git a/src/main/java/spoon/reflect/code/CtArrayRead.java b/src/main/java/spoon/reflect/code/CtArrayRead.java index 6d5d68df78e..95d20802e6f 100644 --- a/src/main/java/spoon/reflect/code/CtArrayRead.java +++ b/src/main/java/spoon/reflect/code/CtArrayRead.java @@ -28,4 +28,6 @@ * type of the array */ public interface CtArrayRead extends CtArrayAccess> { + @Override + CtArrayRead clone(); } diff --git a/src/main/java/spoon/reflect/code/CtArrayWrite.java b/src/main/java/spoon/reflect/code/CtArrayWrite.java index 53208b87f8e..66b1903634b 100644 --- a/src/main/java/spoon/reflect/code/CtArrayWrite.java +++ b/src/main/java/spoon/reflect/code/CtArrayWrite.java @@ -33,4 +33,6 @@ * type of the array */ public interface CtArrayWrite extends CtArrayAccess> { + @Override + CtArrayWrite clone(); } diff --git a/src/main/java/spoon/reflect/code/CtAssert.java b/src/main/java/spoon/reflect/code/CtAssert.java index 8bcec47e430..99ad9c403ba 100644 --- a/src/main/java/spoon/reflect/code/CtAssert.java +++ b/src/main/java/spoon/reflect/code/CtAssert.java @@ -39,4 +39,7 @@ public interface CtAssert extends CtStatement { * Sets the expression of the assertion. */ > A setExpression(CtExpression expression); + + @Override + CtAssert clone(); } diff --git a/src/main/java/spoon/reflect/code/CtAssignment.java b/src/main/java/spoon/reflect/code/CtAssignment.java index 9fe16616526..7bbd47168ba 100644 --- a/src/main/java/spoon/reflect/code/CtAssignment.java +++ b/src/main/java/spoon/reflect/code/CtAssignment.java @@ -24,8 +24,7 @@ * @param * type of expression to assign, it should extends <T> */ -public interface CtAssignment - extends CtStatement, CtExpression, CtRHSReceiver { +public interface CtAssignment extends CtStatement, CtExpression, CtRHSReceiver { /** * Returns the assigned expression on the left-hand side (where the value is stored, * e.g. in a variable, in an array, in a field ...). @@ -36,4 +35,7 @@ public interface CtAssignment * Sets the assigned expression (left hand side - LHS). */ > C setAssigned(CtExpression assigned); + + @Override + CtAssignment clone(); } diff --git a/src/main/java/spoon/reflect/code/CtBinaryOperator.java b/src/main/java/spoon/reflect/code/CtBinaryOperator.java index 17df5a3772d..00ecd478399 100644 --- a/src/main/java/spoon/reflect/code/CtBinaryOperator.java +++ b/src/main/java/spoon/reflect/code/CtBinaryOperator.java @@ -53,4 +53,7 @@ public interface CtBinaryOperator extends CtExpression { * Gets the kind of this binary operator. */ BinaryOperatorKind getKind(); + + @Override + CtBinaryOperator clone(); } diff --git a/src/main/java/spoon/reflect/code/CtBlock.java b/src/main/java/spoon/reflect/code/CtBlock.java index e1b1b6188b5..0e6fd245879 100644 --- a/src/main/java/spoon/reflect/code/CtBlock.java +++ b/src/main/java/spoon/reflect/code/CtBlock.java @@ -85,4 +85,7 @@ public interface CtBlock extends CtStatement, CtStatementList, TemplateParame * Replaces this element by another one. */ void replace(CtBlock element); + + @Override + CtBlock clone(); } diff --git a/src/main/java/spoon/reflect/code/CtBreak.java b/src/main/java/spoon/reflect/code/CtBreak.java index 986ea7ca017..b4673d9437b 100644 --- a/src/main/java/spoon/reflect/code/CtBreak.java +++ b/src/main/java/spoon/reflect/code/CtBreak.java @@ -31,4 +31,7 @@ public interface CtBreak extends CtCFlowBreak { * defined). */ T setTargetLabel(String targetLabel); + + @Override + CtBreak clone(); } diff --git a/src/main/java/spoon/reflect/code/CtCase.java b/src/main/java/spoon/reflect/code/CtCase.java index 7a6ba18b6f7..6ca3621141a 100644 --- a/src/main/java/spoon/reflect/code/CtCase.java +++ b/src/main/java/spoon/reflect/code/CtCase.java @@ -33,4 +33,7 @@ public interface CtCase extends CtStatement, CtStatementList { * Sets the case expression. */ > T setCaseExpression(CtExpression caseExpression); + + @Override + CtCase clone(); } diff --git a/src/main/java/spoon/reflect/code/CtCatch.java b/src/main/java/spoon/reflect/code/CtCatch.java index 1e352fb3bba..a682bc37c69 100644 --- a/src/main/java/spoon/reflect/code/CtCatch.java +++ b/src/main/java/spoon/reflect/code/CtCatch.java @@ -42,4 +42,7 @@ public interface CtCatch extends CtCodeElement { * Sets the catch's body. */ T setBody(CtBlock body); + + @Override + CtCatch clone(); } diff --git a/src/main/java/spoon/reflect/code/CtCatchVariable.java b/src/main/java/spoon/reflect/code/CtCatchVariable.java index 05e73883084..18d0ba0e792 100644 --- a/src/main/java/spoon/reflect/code/CtCatchVariable.java +++ b/src/main/java/spoon/reflect/code/CtCatchVariable.java @@ -34,4 +34,7 @@ public interface CtCatchVariable extends CtVariable, CtMultiTypedElement, * @see spoon.reflect.declaration.CtNamedElement#getReference() */ CtCatchVariableReference getReference(); + + @Override + CtCatchVariable clone(); } diff --git a/src/main/java/spoon/reflect/code/CtCodeElement.java b/src/main/java/spoon/reflect/code/CtCodeElement.java index 2e941087426..ca31fd3dc4d 100644 --- a/src/main/java/spoon/reflect/code/CtCodeElement.java +++ b/src/main/java/spoon/reflect/code/CtCodeElement.java @@ -32,4 +32,6 @@ public interface CtCodeElement extends CtElement { */ R partiallyEvaluate(); + @Override + CtCodeElement clone(); } diff --git a/src/main/java/spoon/reflect/code/CtCodeSnippetExpression.java b/src/main/java/spoon/reflect/code/CtCodeSnippetExpression.java index c542e87f631..cbf3010ea2e 100644 --- a/src/main/java/spoon/reflect/code/CtCodeSnippetExpression.java +++ b/src/main/java/spoon/reflect/code/CtCodeSnippetExpression.java @@ -24,7 +24,7 @@ * be inserted in the program's model as is. Code snippets should be avoided * since no controls can be performed on them. */ -public interface CtCodeSnippetExpression extends CtCodeSnippet, CtExpression { +public interface CtCodeSnippetExpression extends CtExpression, CtCodeSnippet { /** * Compiles this expression snippet to produce the corresponding AST expression. @@ -34,4 +34,6 @@ public interface CtCodeSnippetExpression extends CtCodeSnippet, CtExpression< */ > E compile() throws SnippetCompilationError; + @Override + CtCodeSnippetExpression clone(); } diff --git a/src/main/java/spoon/reflect/code/CtCodeSnippetStatement.java b/src/main/java/spoon/reflect/code/CtCodeSnippetStatement.java index ebecf62d976..4653fd23c7a 100644 --- a/src/main/java/spoon/reflect/code/CtCodeSnippetStatement.java +++ b/src/main/java/spoon/reflect/code/CtCodeSnippetStatement.java @@ -25,7 +25,7 @@ * since no controls can be performed on them. */ -public interface CtCodeSnippetStatement extends CtCodeSnippet, CtStatement { +public interface CtCodeSnippetStatement extends CtStatement, CtCodeSnippet { /** * Compiles this statement code snippet to produce the corresponding AST @@ -37,4 +37,6 @@ public interface CtCodeSnippetStatement extends CtCodeSnippet, CtStatement { */ S compile() throws SnippetCompilationError; + @Override + CtCodeSnippetStatement clone(); } diff --git a/src/main/java/spoon/reflect/code/CtComment.java b/src/main/java/spoon/reflect/code/CtComment.java index 9e5e862cc1d..3ead80569b3 100644 --- a/src/main/java/spoon/reflect/code/CtComment.java +++ b/src/main/java/spoon/reflect/code/CtComment.java @@ -55,4 +55,7 @@ enum CommentType { CommentType getCommentType(); E setCommentType(CommentType commentType); + + @Override + CtComment clone(); } diff --git a/src/main/java/spoon/reflect/code/CtConditional.java b/src/main/java/spoon/reflect/code/CtConditional.java index d7cfe966627..1d1f4a5d931 100644 --- a/src/main/java/spoon/reflect/code/CtConditional.java +++ b/src/main/java/spoon/reflect/code/CtConditional.java @@ -50,4 +50,7 @@ public interface CtConditional extends CtExpression { * Sets the condition expression. */ > C setCondition(CtExpression condition); + + @Override + CtConditional clone(); } diff --git a/src/main/java/spoon/reflect/code/CtConstructorCall.java b/src/main/java/spoon/reflect/code/CtConstructorCall.java index 4ca5aadbd93..1f23638f46d 100644 --- a/src/main/java/spoon/reflect/code/CtConstructorCall.java +++ b/src/main/java/spoon/reflect/code/CtConstructorCall.java @@ -25,4 +25,6 @@ * created type */ public interface CtConstructorCall extends CtTargetedExpression>, CtAbstractInvocation, CtStatement, CtGenericElementReference { + @Override + CtConstructorCall clone(); } diff --git a/src/main/java/spoon/reflect/code/CtContinue.java b/src/main/java/spoon/reflect/code/CtContinue.java index c9898dc217b..7a39ebc109c 100644 --- a/src/main/java/spoon/reflect/code/CtContinue.java +++ b/src/main/java/spoon/reflect/code/CtContinue.java @@ -43,4 +43,7 @@ public interface CtContinue extends CtCFlowBreak { * defined). */ T setTargetLabel(String targetLabel); + + @Override + CtContinue clone(); } diff --git a/src/main/java/spoon/reflect/code/CtDo.java b/src/main/java/spoon/reflect/code/CtDo.java index b6a4e95df1f..68805b9ed9f 100644 --- a/src/main/java/spoon/reflect/code/CtDo.java +++ b/src/main/java/spoon/reflect/code/CtDo.java @@ -29,4 +29,7 @@ public interface CtDo extends CtLoop { * Sets the looping test as a boolean expression. */ T setLoopingExpression(CtExpression expression); + + @Override + CtDo clone(); } diff --git a/src/main/java/spoon/reflect/code/CtExecutableReferenceExpression.java b/src/main/java/spoon/reflect/code/CtExecutableReferenceExpression.java index b960c9cd720..afef1a8d069 100644 --- a/src/main/java/spoon/reflect/code/CtExecutableReferenceExpression.java +++ b/src/main/java/spoon/reflect/code/CtExecutableReferenceExpression.java @@ -39,4 +39,7 @@ public interface CtExecutableReferenceExpression> e * Sets the executable will be referenced by the expression. */ > C setExecutable(CtExecutableReference executable); + + @Override + CtExecutableReferenceExpression clone(); } diff --git a/src/main/java/spoon/reflect/code/CtExpression.java b/src/main/java/spoon/reflect/code/CtExpression.java index 176e4ea5cf4..0317a27de9a 100644 --- a/src/main/java/spoon/reflect/code/CtExpression.java +++ b/src/main/java/spoon/reflect/code/CtExpression.java @@ -16,12 +16,12 @@ */ package spoon.reflect.code; -import java.util.List; - import spoon.reflect.declaration.CtTypedElement; import spoon.reflect.reference.CtTypeReference; import spoon.template.TemplateParameter; +import java.util.List; + /** * This abstract code element defines a typed expression. * @@ -50,4 +50,6 @@ public interface CtExpression extends CtCodeElement, CtTypedElement, Templ */ void replace(CtExpression element); + @Override + CtExpression clone(); } diff --git a/src/main/java/spoon/reflect/code/CtFieldAccess.java b/src/main/java/spoon/reflect/code/CtFieldAccess.java index eb30209dabe..7f5237960f4 100644 --- a/src/main/java/spoon/reflect/code/CtFieldAccess.java +++ b/src/main/java/spoon/reflect/code/CtFieldAccess.java @@ -26,4 +26,7 @@ */ public interface CtFieldAccess extends CtVariableRead, CtTargetedExpression> { CtFieldReference getVariable(); + + @Override + CtFieldAccess clone(); } diff --git a/src/main/java/spoon/reflect/code/CtFieldRead.java b/src/main/java/spoon/reflect/code/CtFieldRead.java index e055eab52d8..4ca1638973d 100644 --- a/src/main/java/spoon/reflect/code/CtFieldRead.java +++ b/src/main/java/spoon/reflect/code/CtFieldRead.java @@ -28,4 +28,6 @@ * type of the field */ public interface CtFieldRead extends CtFieldAccess { + @Override + CtFieldRead clone(); } diff --git a/src/main/java/spoon/reflect/code/CtFieldWrite.java b/src/main/java/spoon/reflect/code/CtFieldWrite.java index 1a304358ea3..7d0c0b912fc 100644 --- a/src/main/java/spoon/reflect/code/CtFieldWrite.java +++ b/src/main/java/spoon/reflect/code/CtFieldWrite.java @@ -33,4 +33,6 @@ * type of the field */ public interface CtFieldWrite extends CtFieldAccess { + @Override + CtFieldWrite clone(); } diff --git a/src/main/java/spoon/reflect/code/CtFor.java b/src/main/java/spoon/reflect/code/CtFor.java index 64772b7b2b7..cded50651ec 100644 --- a/src/main/java/spoon/reflect/code/CtFor.java +++ b/src/main/java/spoon/reflect/code/CtFor.java @@ -73,4 +73,6 @@ public interface CtFor extends CtLoop { */ boolean removeForUpdate(CtStatement statement); + @Override + CtFor clone(); } diff --git a/src/main/java/spoon/reflect/code/CtForEach.java b/src/main/java/spoon/reflect/code/CtForEach.java index 91eac3a9303..9887e943da0 100644 --- a/src/main/java/spoon/reflect/code/CtForEach.java +++ b/src/main/java/spoon/reflect/code/CtForEach.java @@ -40,4 +40,7 @@ public interface CtForEach extends CtLoop { * Sets the variable that references the currently iterated element. */ T setVariable(CtLocalVariable variable); + + @Override + CtForEach clone(); } diff --git a/src/main/java/spoon/reflect/code/CtIf.java b/src/main/java/spoon/reflect/code/CtIf.java index cceb2eedc81..82ac3ccfff1 100644 --- a/src/main/java/spoon/reflect/code/CtIf.java +++ b/src/main/java/spoon/reflect/code/CtIf.java @@ -54,4 +54,7 @@ public interface CtIf extends CtStatement, TemplateParameter { * Sets the statement executed when the condition is true. */ T setThenStatement(CtStatement thenStatement); + + @Override + CtIf clone(); } diff --git a/src/main/java/spoon/reflect/code/CtInvocation.java b/src/main/java/spoon/reflect/code/CtInvocation.java index c4f9618d16a..c777c2e135c 100644 --- a/src/main/java/spoon/reflect/code/CtInvocation.java +++ b/src/main/java/spoon/reflect/code/CtInvocation.java @@ -33,4 +33,7 @@ public interface CtInvocation extends CtAbstractInvocation, CtStatement, C */ @Override CtTypeReference getType(); + + @Override + CtInvocation clone(); } diff --git a/src/main/java/spoon/reflect/code/CtLambda.java b/src/main/java/spoon/reflect/code/CtLambda.java index 2591ccea249..aba68da9474 100644 --- a/src/main/java/spoon/reflect/code/CtLambda.java +++ b/src/main/java/spoon/reflect/code/CtLambda.java @@ -53,4 +53,7 @@ public interface CtLambda extends CtExpression, CtExecutable { * if the lambda already has a value in the body attribute. */ > C setExpression(CtExpression expression); + + @Override + CtLambda clone(); } diff --git a/src/main/java/spoon/reflect/code/CtLiteral.java b/src/main/java/spoon/reflect/code/CtLiteral.java index 1c9b4206c5c..dbaceabcdb7 100644 --- a/src/main/java/spoon/reflect/code/CtLiteral.java +++ b/src/main/java/spoon/reflect/code/CtLiteral.java @@ -34,4 +34,6 @@ public interface CtLiteral extends CtExpression { */ > C setValue(T value); + @Override + CtLiteral clone(); } diff --git a/src/main/java/spoon/reflect/code/CtLocalVariable.java b/src/main/java/spoon/reflect/code/CtLocalVariable.java index 9a375b09a84..ee0ae396ab2 100644 --- a/src/main/java/spoon/reflect/code/CtLocalVariable.java +++ b/src/main/java/spoon/reflect/code/CtLocalVariable.java @@ -34,4 +34,7 @@ public interface CtLocalVariable extends CtStatement, CtVariable, CtRHSRec * @see spoon.reflect.declaration.CtNamedElement#getReference() */ CtLocalVariableReference getReference(); + + @Override + CtLocalVariable clone(); } diff --git a/src/main/java/spoon/reflect/code/CtLoop.java b/src/main/java/spoon/reflect/code/CtLoop.java index 7607aa8e2aa..45b4ca5147b 100644 --- a/src/main/java/spoon/reflect/code/CtLoop.java +++ b/src/main/java/spoon/reflect/code/CtLoop.java @@ -32,4 +32,7 @@ public interface CtLoop extends CtStatement, TemplateParameter { * Sets the body of this loop. */ T setBody(CtStatement body); + + @Override + CtLoop clone(); } diff --git a/src/main/java/spoon/reflect/code/CtNewArray.java b/src/main/java/spoon/reflect/code/CtNewArray.java index 20743a1c056..a303fb58a7d 100644 --- a/src/main/java/spoon/reflect/code/CtNewArray.java +++ b/src/main/java/spoon/reflect/code/CtNewArray.java @@ -66,4 +66,6 @@ public interface CtNewArray extends CtExpression { */ boolean removeElement(CtExpression expression); + @Override + CtNewArray clone(); } diff --git a/src/main/java/spoon/reflect/code/CtNewClass.java b/src/main/java/spoon/reflect/code/CtNewClass.java index b825f09a20e..a4a7876a484 100644 --- a/src/main/java/spoon/reflect/code/CtNewClass.java +++ b/src/main/java/spoon/reflect/code/CtNewClass.java @@ -36,4 +36,6 @@ public interface CtNewClass extends CtConstructorCall { */ N setAnonymousClass(CtClass anonymousClass); + @Override + CtNewClass clone(); } diff --git a/src/main/java/spoon/reflect/code/CtOperatorAssignment.java b/src/main/java/spoon/reflect/code/CtOperatorAssignment.java index 7509ee05113..53a00ec041f 100644 --- a/src/main/java/spoon/reflect/code/CtOperatorAssignment.java +++ b/src/main/java/spoon/reflect/code/CtOperatorAssignment.java @@ -29,4 +29,7 @@ public interface CtOperatorAssignment extends CtAssignment * Gets the operator kind. */ BinaryOperatorKind getKind(); + + @Override + CtOperatorAssignment clone(); } diff --git a/src/main/java/spoon/reflect/code/CtReturn.java b/src/main/java/spoon/reflect/code/CtReturn.java index 03ef76472ed..16b6e8000a7 100644 --- a/src/main/java/spoon/reflect/code/CtReturn.java +++ b/src/main/java/spoon/reflect/code/CtReturn.java @@ -32,4 +32,7 @@ public interface CtReturn extends CtCFlowBreak, TemplateParameter { * Sets the returned expression. */ > T setReturnedExpression(CtExpression returnedExpression); + + @Override + CtReturn clone(); } diff --git a/src/main/java/spoon/reflect/code/CtStatement.java b/src/main/java/spoon/reflect/code/CtStatement.java index aaed3ddcdd9..3ea3e29972e 100644 --- a/src/main/java/spoon/reflect/code/CtStatement.java +++ b/src/main/java/spoon/reflect/code/CtStatement.java @@ -63,4 +63,7 @@ public interface CtStatement extends CtCodeElement { * Replaces this element by another one. */ void replace(CtStatement element); + + @Override + CtStatement clone(); } diff --git a/src/main/java/spoon/reflect/code/CtStatementList.java b/src/main/java/spoon/reflect/code/CtStatementList.java index 304f4571bc0..54b75a088b1 100644 --- a/src/main/java/spoon/reflect/code/CtStatementList.java +++ b/src/main/java/spoon/reflect/code/CtStatementList.java @@ -43,4 +43,7 @@ public interface CtStatementList extends CtCodeElement, Iterable { * Removes a statement. */ void removeStatement(CtStatement statement); + + @Override + CtStatementList clone(); } diff --git a/src/main/java/spoon/reflect/code/CtSuperAccess.java b/src/main/java/spoon/reflect/code/CtSuperAccess.java index 787a8f3859e..3023e80fb11 100644 --- a/src/main/java/spoon/reflect/code/CtSuperAccess.java +++ b/src/main/java/spoon/reflect/code/CtSuperAccess.java @@ -23,4 +23,6 @@ * Type of super */ public interface CtSuperAccess extends CtVariableRead, CtTargetedExpression> { + @Override + CtSuperAccess clone(); } diff --git a/src/main/java/spoon/reflect/code/CtSwitch.java b/src/main/java/spoon/reflect/code/CtSwitch.java index 3543ed27bbd..efa861bfa8f 100644 --- a/src/main/java/spoon/reflect/code/CtSwitch.java +++ b/src/main/java/spoon/reflect/code/CtSwitch.java @@ -63,4 +63,7 @@ public interface CtSwitch extends CtStatement { * Removes a case; */ boolean removeCase(CtCase c); + + @Override + CtSwitch clone(); } diff --git a/src/main/java/spoon/reflect/code/CtSynchronized.java b/src/main/java/spoon/reflect/code/CtSynchronized.java index b4ecaeb9f94..af0d6825ff2 100644 --- a/src/main/java/spoon/reflect/code/CtSynchronized.java +++ b/src/main/java/spoon/reflect/code/CtSynchronized.java @@ -41,4 +41,7 @@ public interface CtSynchronized extends CtStatement { * Sets the synchronized block. */ T setBlock(CtBlock block); + + @Override + CtSynchronized clone(); } diff --git a/src/main/java/spoon/reflect/code/CtTargetedExpression.java b/src/main/java/spoon/reflect/code/CtTargetedExpression.java index 50d43b27a9d..6fb61797d57 100644 --- a/src/main/java/spoon/reflect/code/CtTargetedExpression.java +++ b/src/main/java/spoon/reflect/code/CtTargetedExpression.java @@ -26,9 +26,7 @@ * @param * Type of the target */ -public interface CtTargetedExpression> - extends CtExpression { - +public interface CtTargetedExpression> extends CtExpression { /** * Gets the target expression. The target is a `CtTypeAccess` for static methods and a sub type of `CtExpression` for everything else. */ @@ -38,4 +36,7 @@ public interface CtTargetedExpression> * Sets the target expression. */ > C setTarget(E target); + + @Override + CtTargetedExpression clone(); } diff --git a/src/main/java/spoon/reflect/code/CtThisAccess.java b/src/main/java/spoon/reflect/code/CtThisAccess.java index 2ed22c5c7b9..2f3b117e6b4 100644 --- a/src/main/java/spoon/reflect/code/CtThisAccess.java +++ b/src/main/java/spoon/reflect/code/CtThisAccess.java @@ -23,4 +23,6 @@ * Type of this */ public interface CtThisAccess extends CtTargetedExpression> { + @Override + CtThisAccess clone(); } diff --git a/src/main/java/spoon/reflect/code/CtThrow.java b/src/main/java/spoon/reflect/code/CtThrow.java index 5a58b846ceb..0dd2fc7ccef 100644 --- a/src/main/java/spoon/reflect/code/CtThrow.java +++ b/src/main/java/spoon/reflect/code/CtThrow.java @@ -32,4 +32,7 @@ public interface CtThrow extends CtCFlowBreak, TemplateParameter { * Sets the thrown expression (must be a throwable). */ T setThrownExpression(CtExpression thrownExpression); + + @Override + CtThrow clone(); } diff --git a/src/main/java/spoon/reflect/code/CtTry.java b/src/main/java/spoon/reflect/code/CtTry.java index 0725fb7a418..7a78c511f0d 100644 --- a/src/main/java/spoon/reflect/code/CtTry.java +++ b/src/main/java/spoon/reflect/code/CtTry.java @@ -16,10 +16,10 @@ */ package spoon.reflect.code; -import java.util.List; - import spoon.template.TemplateParameter; +import java.util.List; + /** * This code element defines a try statement. */ @@ -66,4 +66,7 @@ public interface CtTry extends CtStatement, TemplateParameter { * finally part). */ T setFinalizer(CtBlock finalizer); + + @Override + CtTry clone(); } diff --git a/src/main/java/spoon/reflect/code/CtTryWithResource.java b/src/main/java/spoon/reflect/code/CtTryWithResource.java index 79bfd4f084b..11681b881d4 100644 --- a/src/main/java/spoon/reflect/code/CtTryWithResource.java +++ b/src/main/java/spoon/reflect/code/CtTryWithResource.java @@ -44,4 +44,7 @@ public interface CtTryWithResource extends CtTry { * Removes a resource. */ boolean removeResource(CtLocalVariable resource); + + @Override + CtTryWithResource clone(); } diff --git a/src/main/java/spoon/reflect/code/CtTypeAccess.java b/src/main/java/spoon/reflect/code/CtTypeAccess.java index b9f3dcd5542..5135709c6a3 100644 --- a/src/main/java/spoon/reflect/code/CtTypeAccess.java +++ b/src/main/java/spoon/reflect/code/CtTypeAccess.java @@ -59,4 +59,7 @@ public interface CtTypeAccess extends CtExpression { */ @Override CtTypeReference getType(); + + @Override + CtTypeAccess clone(); } diff --git a/src/main/java/spoon/reflect/code/CtUnaryOperator.java b/src/main/java/spoon/reflect/code/CtUnaryOperator.java index 97385ff0f7b..dad29417cf3 100644 --- a/src/main/java/spoon/reflect/code/CtUnaryOperator.java +++ b/src/main/java/spoon/reflect/code/CtUnaryOperator.java @@ -44,4 +44,7 @@ public interface CtUnaryOperator extends CtExpression, CtStatement { * Gets the kind of this operator. */ UnaryOperatorKind getKind(); + + @Override + CtUnaryOperator clone(); } diff --git a/src/main/java/spoon/reflect/code/CtVariableAccess.java b/src/main/java/spoon/reflect/code/CtVariableAccess.java index 92cafbf4e40..d8acacfeaca 100644 --- a/src/main/java/spoon/reflect/code/CtVariableAccess.java +++ b/src/main/java/spoon/reflect/code/CtVariableAccess.java @@ -36,4 +36,7 @@ public interface CtVariableAccess extends CtExpression { * Sets the reference to the accessed variable. */ > C setVariable(CtVariableReference variable); + + @Override + CtVariableAccess clone(); } diff --git a/src/main/java/spoon/reflect/code/CtVariableRead.java b/src/main/java/spoon/reflect/code/CtVariableRead.java index b6fc4685f9a..66e85ad7fa1 100644 --- a/src/main/java/spoon/reflect/code/CtVariableRead.java +++ b/src/main/java/spoon/reflect/code/CtVariableRead.java @@ -26,4 +26,6 @@ * type of the variable */ public interface CtVariableRead extends CtVariableAccess { + @Override + CtVariableRead clone(); } diff --git a/src/main/java/spoon/reflect/code/CtVariableWrite.java b/src/main/java/spoon/reflect/code/CtVariableWrite.java index 991680f4958..a9c663c61fd 100644 --- a/src/main/java/spoon/reflect/code/CtVariableWrite.java +++ b/src/main/java/spoon/reflect/code/CtVariableWrite.java @@ -33,4 +33,6 @@ * type of the variable */ public interface CtVariableWrite extends CtVariableAccess { + @Override + CtVariableWrite clone(); } diff --git a/src/main/java/spoon/reflect/code/CtWhile.java b/src/main/java/spoon/reflect/code/CtWhile.java index fa7d913f59c..b5f2136fc55 100644 --- a/src/main/java/spoon/reflect/code/CtWhile.java +++ b/src/main/java/spoon/reflect/code/CtWhile.java @@ -29,4 +29,7 @@ public interface CtWhile extends CtLoop { * Sets the looping boolean test expression. */ T setLoopingExpression(CtExpression expression); + + @Override + CtWhile clone(); } diff --git a/src/main/java/spoon/reflect/declaration/CtAnnotation.java b/src/main/java/spoon/reflect/declaration/CtAnnotation.java index 23ddf181635..ebba3bf9213 100644 --- a/src/main/java/spoon/reflect/declaration/CtAnnotation.java +++ b/src/main/java/spoon/reflect/declaration/CtAnnotation.java @@ -168,4 +168,7 @@ public interface CtAnnotation extends CtExpression, CtS * Adds a new key-annotation pair for this annotation. */ > T addValue(String elementName, CtAnnotation value); + + @Override + CtAnnotation clone(); } diff --git a/src/main/java/spoon/reflect/declaration/CtAnnotationType.java b/src/main/java/spoon/reflect/declaration/CtAnnotationType.java index c3bd36e7653..7c1f9b1b599 100644 --- a/src/main/java/spoon/reflect/declaration/CtAnnotationType.java +++ b/src/main/java/spoon/reflect/declaration/CtAnnotationType.java @@ -22,4 +22,6 @@ * This element defines an annotation type. */ public interface CtAnnotationType extends CtType { + @Override + CtAnnotationType clone(); } diff --git a/src/main/java/spoon/reflect/declaration/CtAnonymousExecutable.java b/src/main/java/spoon/reflect/declaration/CtAnonymousExecutable.java index 9b1ec42b045..b0a1ca41396 100644 --- a/src/main/java/spoon/reflect/declaration/CtAnonymousExecutable.java +++ b/src/main/java/spoon/reflect/declaration/CtAnonymousExecutable.java @@ -22,4 +22,6 @@ * @see spoon.reflect.declaration.CtClass */ public interface CtAnonymousExecutable extends CtExecutable, CtTypeMember { + @Override + CtAnonymousExecutable clone(); } diff --git a/src/main/java/spoon/reflect/declaration/CtClass.java b/src/main/java/spoon/reflect/declaration/CtClass.java index 17e6a0fc4ff..254e2b4b573 100644 --- a/src/main/java/spoon/reflect/declaration/CtClass.java +++ b/src/main/java/spoon/reflect/declaration/CtClass.java @@ -16,12 +16,12 @@ */ package spoon.reflect.declaration; -import java.util.List; -import java.util.Set; - import spoon.reflect.code.CtStatement; import spoon.reflect.reference.CtTypeReference; +import java.util.List; +import java.util.Set; + /** * This element represents a class declaration. * @@ -95,4 +95,7 @@ public interface CtClass extends CtType, CtStatement { * Return {@code true} if the referenced type is a anonymous type */ boolean isAnonymous(); + + @Override + CtClass clone(); } diff --git a/src/main/java/spoon/reflect/declaration/CtConstructor.java b/src/main/java/spoon/reflect/declaration/CtConstructor.java index 3246b51b128..7b2a9e0b0c7 100644 --- a/src/main/java/spoon/reflect/declaration/CtConstructor.java +++ b/src/main/java/spoon/reflect/declaration/CtConstructor.java @@ -31,4 +31,7 @@ public interface CtConstructor extends CtExecutable, CtTypeMember, CtGener * constructor's type). */ CtType getDeclaringType(); + + @Override + CtConstructor clone(); } diff --git a/src/main/java/spoon/reflect/declaration/CtElement.java b/src/main/java/spoon/reflect/declaration/CtElement.java index 12124ce7c69..5a63859dce4 100644 --- a/src/main/java/spoon/reflect/declaration/CtElement.java +++ b/src/main/java/spoon/reflect/declaration/CtElement.java @@ -35,7 +35,7 @@ * element). */ @Root -public interface CtElement extends FactoryAccessor, CtVisitable { +public interface CtElement extends FactoryAccessor, CtVisitable, Cloneable { /** * Searches for an annotation (proxy) of the given class that annotates the @@ -280,4 +280,9 @@ List getAnnotatedChildren( * @param comment the comment to remove */ E removeComment(CtComment comment); + + /** + * Clone the element which calls this method in a new object. + */ + CtElement clone(); } diff --git a/src/main/java/spoon/reflect/declaration/CtEnum.java b/src/main/java/spoon/reflect/declaration/CtEnum.java index 49915a88568..86442b723be 100644 --- a/src/main/java/spoon/reflect/declaration/CtEnum.java +++ b/src/main/java/spoon/reflect/declaration/CtEnum.java @@ -62,4 +62,7 @@ public interface CtEnum> extends CtClass { */ @Deprecated List> getValues(); + + @Override + CtEnum clone(); } diff --git a/src/main/java/spoon/reflect/declaration/CtEnumValue.java b/src/main/java/spoon/reflect/declaration/CtEnumValue.java index ed47eedc220..2b31ee31616 100644 --- a/src/main/java/spoon/reflect/declaration/CtEnumValue.java +++ b/src/main/java/spoon/reflect/declaration/CtEnumValue.java @@ -31,4 +31,6 @@ * the type of the enum, hence equal to the type of getParent(). */ public interface CtEnumValue extends CtField { + @Override + CtEnumValue clone(); } diff --git a/src/main/java/spoon/reflect/declaration/CtExecutable.java b/src/main/java/spoon/reflect/declaration/CtExecutable.java index cc6684e619c..65630754e36 100644 --- a/src/main/java/spoon/reflect/declaration/CtExecutable.java +++ b/src/main/java/spoon/reflect/declaration/CtExecutable.java @@ -108,4 +108,7 @@ public interface CtExecutable extends CtNamedElement, CtTypedElement { * Gets the signature of this method or constructor as specified by chapter "8.4.2 Method Signature" of the Java specification */ String getSignature(); + + @Override + CtExecutable clone(); } diff --git a/src/main/java/spoon/reflect/declaration/CtField.java b/src/main/java/spoon/reflect/declaration/CtField.java index f1b5f6b7362..16770be25ca 100644 --- a/src/main/java/spoon/reflect/declaration/CtField.java +++ b/src/main/java/spoon/reflect/declaration/CtField.java @@ -40,4 +40,7 @@ public interface CtField extends CtVariable, CtTypeMember, CtRHSReceiver void replace(CtField element); + + @Override + CtField clone(); } diff --git a/src/main/java/spoon/reflect/declaration/CtInterface.java b/src/main/java/spoon/reflect/declaration/CtInterface.java index 26ff0099ee0..3820c71a21d 100644 --- a/src/main/java/spoon/reflect/declaration/CtInterface.java +++ b/src/main/java/spoon/reflect/declaration/CtInterface.java @@ -20,4 +20,6 @@ * This element defines an interface declaration. */ public interface CtInterface extends CtType { + @Override + CtInterface clone(); } diff --git a/src/main/java/spoon/reflect/declaration/CtMethod.java b/src/main/java/spoon/reflect/declaration/CtMethod.java index 13461d482d8..ee404fbcbd7 100644 --- a/src/main/java/spoon/reflect/declaration/CtMethod.java +++ b/src/main/java/spoon/reflect/declaration/CtMethod.java @@ -35,4 +35,7 @@ public interface CtMethod extends CtExecutable, CtTypeMember, CtGenericEle * Replaces this element by another one. */ void replace(CtMethod element); + + @Override + CtMethod clone(); } diff --git a/src/main/java/spoon/reflect/declaration/CtNamedElement.java b/src/main/java/spoon/reflect/declaration/CtNamedElement.java index 08320734b00..f56fd0355d2 100644 --- a/src/main/java/spoon/reflect/declaration/CtNamedElement.java +++ b/src/main/java/spoon/reflect/declaration/CtNamedElement.java @@ -36,4 +36,7 @@ public interface CtNamedElement extends CtElement { * Returns the corresponding reference. */ CtReference getReference(); + + @Override + CtNamedElement clone(); } diff --git a/src/main/java/spoon/reflect/declaration/CtPackage.java b/src/main/java/spoon/reflect/declaration/CtPackage.java index 233267f63b4..eb43cda100d 100644 --- a/src/main/java/spoon/reflect/declaration/CtPackage.java +++ b/src/main/java/spoon/reflect/declaration/CtPackage.java @@ -124,4 +124,7 @@ public interface CtPackage extends CtNamedElement, CtShadowable { * new Set of types */ T setTypes(Set> types); + + @Override + CtPackage clone(); } diff --git a/src/main/java/spoon/reflect/declaration/CtParameter.java b/src/main/java/spoon/reflect/declaration/CtParameter.java index a51ba040b3a..2c646b19615 100644 --- a/src/main/java/spoon/reflect/declaration/CtParameter.java +++ b/src/main/java/spoon/reflect/declaration/CtParameter.java @@ -44,4 +44,7 @@ public interface CtParameter extends CtVariable, CtShadowable { > C setVarArgs(boolean varArgs); CtParameterReference getReference(); + + @Override + CtParameter clone(); } diff --git a/src/main/java/spoon/reflect/declaration/CtType.java b/src/main/java/spoon/reflect/declaration/CtType.java index 69190d3e7fb..19d95bc2101 100644 --- a/src/main/java/spoon/reflect/declaration/CtType.java +++ b/src/main/java/spoon/reflect/declaration/CtType.java @@ -242,4 +242,6 @@ public interface CtType extends CtNamedElement, CtTypeInformation, CtTypeMemb */ boolean removeSuperInterface(CtTypeReference interfac); + @Override + CtType clone(); } diff --git a/src/main/java/spoon/reflect/factory/CodeFactory.java b/src/main/java/spoon/reflect/factory/CodeFactory.java index 639266146e7..75c2212d4b7 100644 --- a/src/main/java/spoon/reflect/factory/CodeFactory.java +++ b/src/main/java/spoon/reflect/factory/CodeFactory.java @@ -104,8 +104,7 @@ public CtBinaryOperator createBinaryOperator(CtExpression left, CtExpr * @return a accessed type expression. */ public CtTypeAccess createTypeAccess(CtTypeReference accessedType) { - CtTypeReference accessedTypeClone = factory.Core().clone(accessedType); - return createTypeAccessWithoutCloningReference(accessedTypeClone); + return createTypeAccessWithoutCloningReference(accessedType == null ? null : accessedType.clone()); } /** @@ -139,7 +138,7 @@ public CtFieldAccess> createClassAccess(CtTypeReference type) { fieldReference.setDeclaringType(type); CtFieldRead> fieldRead = factory.Core().createFieldRead(); - fieldRead.setType(factory.Core().clone(classType)); + fieldRead.setType(classType.clone()); fieldRead.setVariable(fieldReference); fieldRead.setTarget(typeAccess); return fieldRead; @@ -159,7 +158,7 @@ public CtConstructorCall createConstructorCall(CtTypeReference type, C CtExecutableReference executableReference = factory.Core() .createExecutableReference(); executableReference.setType(type); - executableReference.setDeclaringType(factory.Core().clone(type)); + executableReference.setDeclaringType(type == null ? type : type.clone()); executableReference.setSimpleName(CtExecutableReference.CONSTRUCTOR_NAME); List> typeReferences = new ArrayList>(); for (int i = 0; i < parameters.length; i++) { @@ -285,7 +284,7 @@ public CtLocalVariable createLocalVariable(CtTypeReference type, Strin */ public CtLocalVariableReference createLocalVariableReference(CtLocalVariable localVariable) { CtLocalVariableReference ref = factory.Core().createLocalVariableReference(); - ref.setType(factory.Core().clone(localVariable.getType())); + ref.setType(localVariable.getType() == null ? null : localVariable.getType().clone()); ref.setSimpleName(localVariable.getSimpleName()); ref.setDeclaration(localVariable); return ref; @@ -329,7 +328,7 @@ public CtCatchVariableReference createCatchVariableReference(CtCatchVaria public CtStatementList createStatementList(CtBlock block) { CtStatementList l = factory.Core().createStatementList(); for (CtStatement s : block.getStatements()) { - l.addStatement(factory.Core().clone(s)); + l.addStatement(s.clone()); } return l; } @@ -368,7 +367,7 @@ public CtVariableAccess createVariableRead(CtVariableReference variabl } else { va = factory.Core().createVariableRead(); } - return va.setVariable(variable).setType(factory.Core().clone(variable.getType())); + return va.setVariable(variable).setType(variable.getType() == null ? null : variable.getType().clone()); } /** diff --git a/src/main/java/spoon/reflect/factory/ConstructorFactory.java b/src/main/java/spoon/reflect/factory/ConstructorFactory.java index 6135938e678..72849d2fd10 100644 --- a/src/main/java/spoon/reflect/factory/ConstructorFactory.java +++ b/src/main/java/spoon/reflect/factory/ConstructorFactory.java @@ -58,7 +58,7 @@ public ConstructorFactory(Factory factory) { */ @SuppressWarnings("unchecked") public CtConstructor create(CtClass target, CtConstructor source) { - CtConstructor newConstructor = factory.Core().clone((CtConstructor) source); + CtConstructor newConstructor = (CtConstructor) source.clone(); target.addConstructor(newConstructor); return newConstructor; } @@ -75,7 +75,7 @@ public CtConstructor create(CtClass target, CtConstructor source) { */ @SuppressWarnings("unchecked") public CtConstructor create(CtClass target, CtMethod source) { - CtMethod method = factory.Core().clone((CtMethod) source); + CtMethod method = (CtMethod) source.clone(); CtConstructor newConstructor = factory.Core().createConstructor(); newConstructor.setAnnotations(method.getAnnotations()); newConstructor.setBody(method.getBody()); @@ -152,7 +152,7 @@ public CtExecutableReference createReference(CtConstructor c) { */ public CtExecutableReference createReference(Constructor constructor) { CtTypeReference type = factory.Type().createReference(constructor.getDeclaringClass()); - return createReference(type, factory.Core().clone(type), CtExecutableReference.CONSTRUCTOR_NAME, + return createReference(type, type.clone(), CtExecutableReference.CONSTRUCTOR_NAME, factory.Type().createReferences(Arrays.asList(constructor.getParameterTypes()))); } @@ -166,11 +166,11 @@ public CtExecutableReference createReference(Constructor constructor) public CtExecutableReference createReference(CtTypeReference type, CtExpression...parameters) { final CtExecutableReference executableReference = factory.Core().createExecutableReference(); executableReference.setType(type); - executableReference.setDeclaringType(factory.Core().clone(type)); + executableReference.setDeclaringType(type == null ? null : type.clone()); executableReference.setSimpleName(CtExecutableReference.CONSTRUCTOR_NAME); List> typeReferences = new ArrayList>(); for (CtExpression parameter : parameters) { - typeReferences.add(factory.Core().clone(parameter.getType())); + typeReferences.add(parameter.getType() == null ? null : parameter.getType().clone()); } executableReference.setParameters(typeReferences); return executableReference; diff --git a/src/main/java/spoon/reflect/factory/CoreFactory.java b/src/main/java/spoon/reflect/factory/CoreFactory.java index 16c32597696..a884f3d6bec 100644 --- a/src/main/java/spoon/reflect/factory/CoreFactory.java +++ b/src/main/java/spoon/reflect/factory/CoreFactory.java @@ -109,7 +109,9 @@ public interface CoreFactory { * @param element * the element * @return a clone of element + * @see spoon.reflect.declaration.CtElement#clone() */ + @Deprecated T clone(T element); /** diff --git a/src/main/java/spoon/reflect/factory/ExecutableFactory.java b/src/main/java/spoon/reflect/factory/ExecutableFactory.java index 2edc3a8738a..830ccebab2a 100644 --- a/src/main/java/spoon/reflect/factory/ExecutableFactory.java +++ b/src/main/java/spoon/reflect/factory/ExecutableFactory.java @@ -98,15 +98,15 @@ public CtExecutableReference createReference(CtExecutable e) { CtTypeReference refs[] = new CtTypeReference[e.getParameters().size()]; int i = 0; for (CtParameter param : e.getParameters()) { - refs[i++] = factory.Core().clone(param.getType()); + refs[i++] = param.getType().clone(); } if (e instanceof CtMethod) { - return createReference(((CtMethod) e).getDeclaringType().getReference(), factory.Core().clone(((CtMethod) e).getType()), e.getSimpleName(), refs); + return createReference(((CtMethod) e).getDeclaringType().getReference(), ((CtMethod) e).getType().clone(), e.getSimpleName(), refs); } else if (e instanceof CtLambda) { // A lambda isn't a structural element and doesn't have a declaring type like a method or a constructor. return createReference(null, e.getType(), e.getSimpleName(), refs); } - return createReference(((CtConstructor) e).getDeclaringType().getReference(), factory.Core().clone(((CtConstructor) e).getType()), CtExecutableReference.CONSTRUCTOR_NAME, refs); + return createReference(((CtConstructor) e).getDeclaringType().getReference(), ((CtConstructor) e).getType().clone(), CtExecutableReference.CONSTRUCTOR_NAME, refs); } /** diff --git a/src/main/java/spoon/reflect/factory/FieldFactory.java b/src/main/java/spoon/reflect/factory/FieldFactory.java index ff03af12303..31d12fce8f2 100644 --- a/src/main/java/spoon/reflect/factory/FieldFactory.java +++ b/src/main/java/spoon/reflect/factory/FieldFactory.java @@ -96,7 +96,7 @@ public CtField create(CtType target, Set modifiers, CtTy * @return the newly created field */ public CtField create(CtType target, CtField source) { - CtField newField = factory.Core().clone(source); + CtField newField = source.clone(); if (target != null) { target.addField(newField); } diff --git a/src/main/java/spoon/reflect/factory/MethodFactory.java b/src/main/java/spoon/reflect/factory/MethodFactory.java index 993ce2b23f5..90560712b2f 100644 --- a/src/main/java/spoon/reflect/factory/MethodFactory.java +++ b/src/main/java/spoon/reflect/factory/MethodFactory.java @@ -16,13 +16,6 @@ */ package spoon.reflect.factory; -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.List; -import java.util.Set; - import spoon.reflect.code.CtBlock; import spoon.reflect.declaration.CtClass; import spoon.reflect.declaration.CtMethod; @@ -33,6 +26,13 @@ import spoon.reflect.reference.CtTypeReference; import spoon.template.Substitution; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.List; +import java.util.Set; + /** * The {@link CtMethod} sub-factory. */ @@ -89,7 +89,7 @@ public CtMethod create(CtClass target, Set * @return the newly created method */ public CtMethod create(CtType target, CtMethod source, boolean redirectReferences) { - CtMethod newMethod = factory.Core().clone(source); + CtMethod newMethod = source.clone(); if (redirectReferences && (source.getDeclaringType() != null)) { Substitution.redirectTypeReferences(newMethod, source.getDeclaringType().getReference(), target.getReference()); } diff --git a/src/main/java/spoon/reflect/factory/TypeFactory.java b/src/main/java/spoon/reflect/factory/TypeFactory.java index 83f6f189c22..06a77bc4eed 100644 --- a/src/main/java/spoon/reflect/factory/TypeFactory.java +++ b/src/main/java/spoon/reflect/factory/TypeFactory.java @@ -395,7 +395,7 @@ public CtTypeParameterReference createTypeParameterReference(String name, List CtIntersectionTypeReference createIntersectionTypeReference(List> bounds) { final CtIntersectionTypeReference intersectionRef = factory.Core().createIntersectionTypeReference(); - CtTypeReference firstBound = factory.Core().clone(bounds.get(0)); + CtTypeReference firstBound = bounds.get(0).clone(); intersectionRef.setSimpleName(firstBound.getSimpleName()); intersectionRef.setDeclaringType(firstBound.getDeclaringType()); intersectionRef.setPackage(firstBound.getPackage()); @@ -414,7 +414,7 @@ public CtIntersectionTypeReference createIntersectionTypeReference(List CtIntersectionTypeReference createIntersectionTypeReferenceWithBounds(Set> bounds) { final CtIntersectionTypeReference intersectionRef = factory.Core().createIntersectionTypeReference(); - CtTypeReference firstBound = factory.Core().clone(bounds.toArray(new CtTypeReference[0])[0]); + CtTypeReference firstBound = bounds.toArray(new CtTypeReference[0])[0].clone(); intersectionRef.setSimpleName(firstBound.getSimpleName()); intersectionRef.setDeclaringType(firstBound.getDeclaringType()); intersectionRef.setPackage(firstBound.getPackage()); diff --git a/src/main/java/spoon/reflect/internal/CtCircularTypeReference.java b/src/main/java/spoon/reflect/internal/CtCircularTypeReference.java index e097b3ca721..01a347b3bc4 100644 --- a/src/main/java/spoon/reflect/internal/CtCircularTypeReference.java +++ b/src/main/java/spoon/reflect/internal/CtCircularTypeReference.java @@ -29,4 +29,6 @@ * when we build the generic or when we scan an AST given. */ public interface CtCircularTypeReference extends CtTypeParameterReference { + @Override + CtCircularTypeReference clone(); } diff --git a/src/main/java/spoon/reflect/reference/CtArrayTypeReference.java b/src/main/java/spoon/reflect/reference/CtArrayTypeReference.java index ae0f8cb4118..00fa1900b7a 100644 --- a/src/main/java/spoon/reflect/reference/CtArrayTypeReference.java +++ b/src/main/java/spoon/reflect/reference/CtArrayTypeReference.java @@ -52,4 +52,7 @@ public interface CtArrayTypeReference extends CtTypeReference { * []s). Use toString() to get the full array type including []s. */ String getSimpleName(); + + @Override + CtArrayTypeReference clone(); } diff --git a/src/main/java/spoon/reflect/reference/CtCatchVariableReference.java b/src/main/java/spoon/reflect/reference/CtCatchVariableReference.java index 81016a0f772..b753fb90b6e 100644 --- a/src/main/java/spoon/reflect/reference/CtCatchVariableReference.java +++ b/src/main/java/spoon/reflect/reference/CtCatchVariableReference.java @@ -29,4 +29,7 @@ public interface CtCatchVariableReference extends CtVariableReference { * variable reference. */ > C setDeclaration(CtCatchVariable declaration); + + @Override + CtCatchVariableReference clone(); } diff --git a/src/main/java/spoon/reflect/reference/CtExecutableReference.java b/src/main/java/spoon/reflect/reference/CtExecutableReference.java index 9dd3bda0cf4..7dddb4b6594 100644 --- a/src/main/java/spoon/reflect/reference/CtExecutableReference.java +++ b/src/main/java/spoon/reflect/reference/CtExecutableReference.java @@ -141,4 +141,7 @@ public interface CtExecutableReference extends CtReference, CtGenericElementR * Replaces an executable reference by another one. */ void replace(CtExecutableReference reference); + + @Override + CtExecutableReference clone(); } diff --git a/src/main/java/spoon/reflect/reference/CtFieldReference.java b/src/main/java/spoon/reflect/reference/CtFieldReference.java index bd18a9963e3..3846e035809 100644 --- a/src/main/java/spoon/reflect/reference/CtFieldReference.java +++ b/src/main/java/spoon/reflect/reference/CtFieldReference.java @@ -78,4 +78,7 @@ public interface CtFieldReference extends CtVariableReference { * Forces a reference to a static element. */ > C setStatic(boolean b); + + @Override + CtFieldReference clone(); } diff --git a/src/main/java/spoon/reflect/reference/CtIntersectionTypeReference.java b/src/main/java/spoon/reflect/reference/CtIntersectionTypeReference.java index 6c5601d469a..853671469f7 100644 --- a/src/main/java/spoon/reflect/reference/CtIntersectionTypeReference.java +++ b/src/main/java/spoon/reflect/reference/CtIntersectionTypeReference.java @@ -44,4 +44,7 @@ public interface CtIntersectionTypeReference extends CtTypeReference { * Removes a bound. */ boolean removeBound(CtTypeReference bound); + + @Override + CtIntersectionTypeReference clone(); } diff --git a/src/main/java/spoon/reflect/reference/CtLocalVariableReference.java b/src/main/java/spoon/reflect/reference/CtLocalVariableReference.java index 460d69deec0..bd84f86cab9 100644 --- a/src/main/java/spoon/reflect/reference/CtLocalVariableReference.java +++ b/src/main/java/spoon/reflect/reference/CtLocalVariableReference.java @@ -30,4 +30,7 @@ public interface CtLocalVariableReference extends CtVariableReference { * variable reference. */ > C setDeclaration(CtLocalVariable declaration); + + @Override + CtLocalVariableReference clone(); } diff --git a/src/main/java/spoon/reflect/reference/CtPackageReference.java b/src/main/java/spoon/reflect/reference/CtPackageReference.java index 9916633fd3b..d81ed51b3bd 100644 --- a/src/main/java/spoon/reflect/reference/CtPackageReference.java +++ b/src/main/java/spoon/reflect/reference/CtPackageReference.java @@ -37,4 +37,7 @@ public interface CtPackageReference extends CtReference { * Replace a package reference by another one. */ void replace(CtPackageReference packageReference); + + @Override + CtPackageReference clone(); } diff --git a/src/main/java/spoon/reflect/reference/CtParameterReference.java b/src/main/java/spoon/reflect/reference/CtParameterReference.java index 4d582e1ea2a..8a1fe992b84 100644 --- a/src/main/java/spoon/reflect/reference/CtParameterReference.java +++ b/src/main/java/spoon/reflect/reference/CtParameterReference.java @@ -35,4 +35,7 @@ public interface CtParameterReference extends CtVariableReference { > C setDeclaringExecutable(CtExecutableReference executable); CtParameter getDeclaration(); + + @Override + CtParameterReference clone(); } diff --git a/src/main/java/spoon/reflect/reference/CtReference.java b/src/main/java/spoon/reflect/reference/CtReference.java index 460afd94b5f..e7816289ea9 100644 --- a/src/main/java/spoon/reflect/reference/CtReference.java +++ b/src/main/java/spoon/reflect/reference/CtReference.java @@ -45,4 +45,7 @@ public interface CtReference extends CtElement { * @return referenced element or null if element does not exist */ CtElement getDeclaration(); + + @Override + CtReference clone(); } diff --git a/src/main/java/spoon/reflect/reference/CtTypeParameterReference.java b/src/main/java/spoon/reflect/reference/CtTypeParameterReference.java index a6cbb92d857..18e314a11c8 100644 --- a/src/main/java/spoon/reflect/reference/CtTypeParameterReference.java +++ b/src/main/java/spoon/reflect/reference/CtTypeParameterReference.java @@ -76,4 +76,7 @@ public interface CtTypeParameterReference extends CtTypeReference { * Sets the extends clause of the type parameter. */ T setBoundingType(CtTypeReference superType); + + @Override + CtTypeParameterReference clone(); } diff --git a/src/main/java/spoon/reflect/reference/CtTypeReference.java b/src/main/java/spoon/reflect/reference/CtTypeReference.java index 56e0bcdfbf4..f3fbe65467e 100644 --- a/src/main/java/spoon/reflect/reference/CtTypeReference.java +++ b/src/main/java/spoon/reflect/reference/CtTypeReference.java @@ -121,4 +121,7 @@ public interface CtTypeReference extends CtReference, CtGenericElementReferen * Casts the type reference in {@link CtIntersectionTypeReference}. */ CtIntersectionTypeReference asCtIntersectionTypeReference(); + + @Override + CtTypeReference clone(); } diff --git a/src/main/java/spoon/reflect/reference/CtUnboundVariableReference.java b/src/main/java/spoon/reflect/reference/CtUnboundVariableReference.java index bb649ae5eb4..3c6c47fa458 100644 --- a/src/main/java/spoon/reflect/reference/CtUnboundVariableReference.java +++ b/src/main/java/spoon/reflect/reference/CtUnboundVariableReference.java @@ -21,5 +21,6 @@ * {@link spoon.reflect.declaration.CtVariable}. */ public interface CtUnboundVariableReference extends CtVariableReference { - + @Override + CtUnboundVariableReference clone(); } diff --git a/src/main/java/spoon/reflect/reference/CtVariableReference.java b/src/main/java/spoon/reflect/reference/CtVariableReference.java index f0e06158850..9ec097d8c4c 100644 --- a/src/main/java/spoon/reflect/reference/CtVariableReference.java +++ b/src/main/java/spoon/reflect/reference/CtVariableReference.java @@ -51,4 +51,7 @@ public interface CtVariableReference extends CtReference { * Replace a variable reference by another one. */ void replace(CtVariableReference reference); + + @Override + CtVariableReference clone(); } diff --git a/src/main/java/spoon/support/DefaultCoreFactory.java b/src/main/java/spoon/support/DefaultCoreFactory.java index 0baa7b7c1bf..dc4a9f74507 100644 --- a/src/main/java/spoon/support/DefaultCoreFactory.java +++ b/src/main/java/spoon/support/DefaultCoreFactory.java @@ -204,7 +204,7 @@ private T clone(T object, Stack cloningContext) { return object; } // RP: this should be done first or removed? - if (object instanceof Cloneable) { + if (object instanceof Cloneable && !(object instanceof CtElement)) { return (T) object.getClass().getMethod("clone").invoke(object); } // RP: never called? diff --git a/src/main/java/spoon/support/compiler/jdt/JDTTreeBuilder.java b/src/main/java/spoon/support/compiler/jdt/JDTTreeBuilder.java index bc890d720a2..8b7cfe9ef1f 100644 --- a/src/main/java/spoon/support/compiler/jdt/JDTTreeBuilder.java +++ b/src/main/java/spoon/support/compiler/jdt/JDTTreeBuilder.java @@ -950,7 +950,7 @@ public CtTypeReference getTypeReference(TypeBinding binding) { ref.setSimpleName(name); basestypes.put(name, ref); } else { - ref = factory.Core().clone(ref); + ref = ref == null ? ref : ref.clone(); } } } else if (binding instanceof WildcardBinding) { @@ -2074,7 +2074,8 @@ private > CtExecutableReferenceExpression cre executableReference.setSimpleName(new String(referenceExpression.selector)); executableReference.setDeclaringType(references.getTypeReference(referenceExpression.lhs.resolvedType)); } - executableReference.setType(factory.Core().clone((CtTypeReference) executableReference.getDeclaringType())); + final CtTypeReference declaringType = (CtTypeReference) executableReference.getDeclaringType(); + executableReference.setType(declaringType == null ? null : declaringType.clone()); executableRef.setExecutable(executableReference); return executableRef; } @@ -3251,7 +3252,7 @@ public boolean onAccess(char[][] tokens, int index) { va = factory.Core().createVariableRead(); } va.setVariable(references.getVariableReference((VariableBinding) qualifiedNameReference.binding)); - va.setType(factory.Core().clone(va.getVariable().getType())); + va.setType(va.getVariable().getType() == null ? null : va.getVariable().getType().clone()); if (qualifiedNameReference.otherBindings != null) { int i = 0; //positions index; int sourceStart = (int) (positions[0] >>> 32); diff --git a/src/main/java/spoon/support/compiler/jdt/ParentExiter.java b/src/main/java/spoon/support/compiler/jdt/ParentExiter.java index 1e34b58ed90..6d91dea0a1b 100644 --- a/src/main/java/spoon/support/compiler/jdt/ParentExiter.java +++ b/src/main/java/spoon/support/compiler/jdt/ParentExiter.java @@ -424,9 +424,9 @@ public void visitCtNewClass(CtNewClass newClass) { final QualifiedAllocationExpression node = (QualifiedAllocationExpression) jdtTreeBuilder.context.stack.peek().node; final ReferenceBinding[] referenceBindings = node.resolvedType == null ? null : node.resolvedType.superInterfaces(); if (referenceBindings != null && referenceBindings.length > 0) { - ((CtClass) child).addSuperInterface(child.getFactory().Core().clone(newClass.getType())); + ((CtClass) child).addSuperInterface(newClass.getType().clone()); } else if (newClass.getType() != null) { - ((CtClass) child).setSuperclass(child.getFactory().Core().clone(newClass.getType())); + ((CtClass) child).setSuperclass(newClass.getType().clone()); } return; } diff --git a/src/main/java/spoon/support/reflect/code/CtAnnotationFieldAccessImpl.java b/src/main/java/spoon/support/reflect/code/CtAnnotationFieldAccessImpl.java index d7d10336c8e..3b45df7fe21 100644 --- a/src/main/java/spoon/support/reflect/code/CtAnnotationFieldAccessImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtAnnotationFieldAccessImpl.java @@ -19,12 +19,16 @@ import spoon.reflect.code.CtAnnotationFieldAccess; import spoon.reflect.visitor.CtVisitor; -public class CtAnnotationFieldAccessImpl extends CtFieldAccessImpl - implements CtAnnotationFieldAccess { +public class CtAnnotationFieldAccessImpl extends CtFieldAccessImpl implements CtAnnotationFieldAccess { private static final long serialVersionUID = 1L; @Override public void accept(CtVisitor visitor) { visitor.visitCtAnnotationFieldAccess(this); } + + @Override + public CtAnnotationFieldAccessImpl clone() { + return (CtAnnotationFieldAccessImpl) super.clone(); + } } diff --git a/src/main/java/spoon/support/reflect/code/CtArrayAccessImpl.java b/src/main/java/spoon/support/reflect/code/CtArrayAccessImpl.java index ad519a1134a..5660afdafcc 100644 --- a/src/main/java/spoon/support/reflect/code/CtArrayAccessImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtArrayAccessImpl.java @@ -19,9 +19,7 @@ import spoon.reflect.code.CtArrayAccess; import spoon.reflect.code.CtExpression; -public abstract class CtArrayAccessImpl> - extends CtTargetedExpressionImpl - implements CtArrayAccess { +public abstract class CtArrayAccessImpl> extends CtTargetedExpressionImpl implements CtArrayAccess { private static final long serialVersionUID = 1L; private CtExpression expression; @@ -39,4 +37,9 @@ public > C setIndexExpression(CtExpression clone() { + return (CtArrayAccess) super.clone(); + } } diff --git a/src/main/java/spoon/support/reflect/code/CtArrayReadImpl.java b/src/main/java/spoon/support/reflect/code/CtArrayReadImpl.java index 1b991cd1e49..edfca1a720d 100644 --- a/src/main/java/spoon/support/reflect/code/CtArrayReadImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtArrayReadImpl.java @@ -20,11 +20,15 @@ import spoon.reflect.code.CtExpression; import spoon.reflect.visitor.CtVisitor; -public class CtArrayReadImpl extends CtArrayAccessImpl> - implements CtArrayRead { +public class CtArrayReadImpl extends CtArrayAccessImpl> implements CtArrayRead { private static final long serialVersionUID = 1L; public void accept(CtVisitor visitor) { visitor.visitCtArrayRead(this); } + + @Override + public CtArrayRead clone() { + return (CtArrayRead) super.clone(); + } } diff --git a/src/main/java/spoon/support/reflect/code/CtArrayWriteImpl.java b/src/main/java/spoon/support/reflect/code/CtArrayWriteImpl.java index 4439ab1ec02..4f317bdb96d 100644 --- a/src/main/java/spoon/support/reflect/code/CtArrayWriteImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtArrayWriteImpl.java @@ -20,11 +20,15 @@ import spoon.reflect.code.CtExpression; import spoon.reflect.visitor.CtVisitor; -public class CtArrayWriteImpl extends CtArrayAccessImpl> - implements CtArrayWrite { +public class CtArrayWriteImpl extends CtArrayAccessImpl> implements CtArrayWrite { private static final long serialVersionUID = 1L; public void accept(CtVisitor visitor) { visitor.visitCtArrayWrite(this); } + + @Override + public CtArrayWrite clone() { + return (CtArrayWrite) super.clone(); + } } diff --git a/src/main/java/spoon/support/reflect/code/CtAssertImpl.java b/src/main/java/spoon/support/reflect/code/CtAssertImpl.java index a02345ce319..4e391060ba5 100644 --- a/src/main/java/spoon/support/reflect/code/CtAssertImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtAssertImpl.java @@ -59,4 +59,9 @@ public > A setExpression(CtExpression value) { this.value = value; return (A) this; } + + @Override + public CtAssert clone() { + return (CtAssert) super.clone(); + } } diff --git a/src/main/java/spoon/support/reflect/code/CtAssignmentImpl.java b/src/main/java/spoon/support/reflect/code/CtAssignmentImpl.java index b20ff9cb46b..2784a08e2cc 100644 --- a/src/main/java/spoon/support/reflect/code/CtAssignmentImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtAssignmentImpl.java @@ -17,11 +17,9 @@ package spoon.support.reflect.code; import spoon.reflect.code.CtAssignment; -import spoon.reflect.code.CtCodeElement; import spoon.reflect.code.CtExpression; import spoon.reflect.code.CtRHSReceiver; import spoon.reflect.declaration.CtElement; -import spoon.reflect.declaration.CtType; import spoon.reflect.declaration.CtTypedElement; import spoon.reflect.reference.CtTypeReference; import spoon.reflect.visitor.CtVisitor; @@ -127,7 +125,8 @@ public T S() { return null; } - public CtCodeElement getSubstitution(CtType targetType) { - return getFactory().Core().clone(this); + @Override + public CtAssignment clone() { + return (CtAssignment) super.clone(); } } diff --git a/src/main/java/spoon/support/reflect/code/CtBinaryOperatorImpl.java b/src/main/java/spoon/support/reflect/code/CtBinaryOperatorImpl.java index e3892b87069..c70fc949dfc 100644 --- a/src/main/java/spoon/support/reflect/code/CtBinaryOperatorImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtBinaryOperatorImpl.java @@ -73,4 +73,9 @@ public > C setKind(BinaryOperatorKind kind) { public BinaryOperatorKind getKind() { return kind; } + + @Override + public CtBinaryOperator clone() { + return (CtBinaryOperator) super.clone(); + } } diff --git a/src/main/java/spoon/support/reflect/code/CtBlockImpl.java b/src/main/java/spoon/support/reflect/code/CtBlockImpl.java index 922ce28f63b..009bbb399a4 100644 --- a/src/main/java/spoon/support/reflect/code/CtBlockImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtBlockImpl.java @@ -17,13 +17,11 @@ package spoon.support.reflect.code; import spoon.reflect.code.CtBlock; -import spoon.reflect.code.CtCodeElement; import spoon.reflect.code.CtInvocation; import spoon.reflect.code.CtStatement; import spoon.reflect.code.CtStatementList; import spoon.reflect.declaration.CtConstructor; import spoon.reflect.declaration.CtElement; -import spoon.reflect.declaration.CtType; import spoon.reflect.declaration.ParentNotInitializedException; import spoon.reflect.visitor.CtVisitor; import spoon.reflect.visitor.Filter; @@ -221,7 +219,8 @@ public R S() { return null; } - public CtCodeElement getSubstitution(CtType targetType) { - return getFactory().Core().clone(this); + @Override + public CtBlock clone() { + return (CtBlock) super.clone(); } } diff --git a/src/main/java/spoon/support/reflect/code/CtBreakImpl.java b/src/main/java/spoon/support/reflect/code/CtBreakImpl.java index 0338be3c380..1ee063eafea 100644 --- a/src/main/java/spoon/support/reflect/code/CtBreakImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtBreakImpl.java @@ -39,4 +39,9 @@ public T setTargetLabel(String targetLabel) { this.targetLabel = targetLabel; return (T) this; } + + @Override + public CtBreak clone() { + return (CtBreak) super.clone(); + } } diff --git a/src/main/java/spoon/support/reflect/code/CtCaseImpl.java b/src/main/java/spoon/support/reflect/code/CtCaseImpl.java index fb50dbdff72..1606e759f81 100644 --- a/src/main/java/spoon/support/reflect/code/CtCaseImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtCaseImpl.java @@ -16,10 +16,6 @@ */ package spoon.support.reflect.code; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - import spoon.reflect.code.CtCase; import spoon.reflect.code.CtExpression; import spoon.reflect.code.CtStatement; @@ -27,6 +23,10 @@ import spoon.reflect.visitor.CtVisitor; import spoon.support.reflect.declaration.CtElementImpl; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + import static spoon.reflect.ModelElementContainerDefaultCapacities.CASE_STATEMENTS_CONTAINER_DEFAULT_CAPACITY; public class CtCaseImpl extends CtStatementImpl implements CtCase { @@ -89,4 +89,9 @@ public void removeStatement(CtStatement statement) { public Iterator iterator() { return getStatements().iterator(); } + + @Override + public CtCase clone() { + return (CtCase) super.clone(); + } } diff --git a/src/main/java/spoon/support/reflect/code/CtCatchImpl.java b/src/main/java/spoon/support/reflect/code/CtCatchImpl.java index a7a16303f01..ab6358490d5 100644 --- a/src/main/java/spoon/support/reflect/code/CtCatchImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtCatchImpl.java @@ -57,4 +57,8 @@ public T setParameter(CtCatchVariable p return (T) this; } + @Override + public CtCatch clone() { + return (CtCatch) super.clone(); + } } diff --git a/src/main/java/spoon/support/reflect/code/CtCatchVariableImpl.java b/src/main/java/spoon/support/reflect/code/CtCatchVariableImpl.java index 5c68e63d508..91401864949 100644 --- a/src/main/java/spoon/support/reflect/code/CtCatchVariableImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtCatchVariableImpl.java @@ -34,8 +34,7 @@ import java.util.List; import java.util.Set; -import static spoon.reflect.ModelElementContainerDefaultCapacities - .CATCH_VARIABLE_MULTI_TYPES_CONTAINER_DEFAULT_CAPACITY; +import static spoon.reflect.ModelElementContainerDefaultCapacities.CATCH_VARIABLE_MULTI_TYPES_CONTAINER_DEFAULT_CAPACITY; public class CtCatchVariableImpl extends CtCodeElementImpl implements CtCatchVariable { private static final long serialVersionUID = 1L; @@ -169,4 +168,9 @@ public ModifierKind getVisibility() { } return null; } + + @Override + public CtCatchVariable clone() { + return (CtCatchVariable) super.clone(); + } } diff --git a/src/main/java/spoon/support/reflect/code/CtCodeElementImpl.java b/src/main/java/spoon/support/reflect/code/CtCodeElementImpl.java index 1437df4d746..97d6032d871 100644 --- a/src/main/java/spoon/support/reflect/code/CtCodeElementImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtCodeElementImpl.java @@ -20,8 +20,7 @@ import spoon.support.reflect.declaration.CtElementImpl; import spoon.support.reflect.eval.VisitorPartialEvaluator; -public abstract class CtCodeElementImpl extends CtElementImpl - implements CtCodeElement { +public abstract class CtCodeElementImpl extends CtElementImpl implements CtCodeElement { private static final long serialVersionUID = 1L; public CtCodeElementImpl() { @@ -35,4 +34,8 @@ public R partiallyEvaluate() { return eval.evaluate(getParent(), (R) this); } + @Override + public CtCodeElement clone() { + return (CtCodeElement) super.clone(); + } } diff --git a/src/main/java/spoon/support/reflect/code/CtCodeSnippetExpressionImpl.java b/src/main/java/spoon/support/reflect/code/CtCodeSnippetExpressionImpl.java index 07b3c6acc8c..aa9d8d78b1a 100644 --- a/src/main/java/spoon/support/reflect/code/CtCodeSnippetExpressionImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtCodeSnippetExpressionImpl.java @@ -23,8 +23,7 @@ import spoon.support.compiler.SnippetCompilationError; import spoon.support.compiler.SnippetCompilationHelper; -public class CtCodeSnippetExpressionImpl extends CtExpressionImpl - implements CtCodeSnippetExpression { +public class CtCodeSnippetExpressionImpl extends CtExpressionImpl implements CtCodeSnippetExpression { private static final long serialVersionUID = 1L; @@ -48,4 +47,8 @@ public > E compile() throws SnippetCompilationError { return (E) SnippetCompilationHelper.compileExpression(this); } + @Override + public CtCodeSnippetExpression clone() { + return (CtCodeSnippetExpression) super.clone(); + } } diff --git a/src/main/java/spoon/support/reflect/code/CtCodeSnippetStatementImpl.java b/src/main/java/spoon/support/reflect/code/CtCodeSnippetStatementImpl.java index edcaf51e06b..d9cf58c0292 100644 --- a/src/main/java/spoon/support/reflect/code/CtCodeSnippetStatementImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtCodeSnippetStatementImpl.java @@ -23,8 +23,7 @@ import spoon.support.compiler.SnippetCompilationError; import spoon.support.compiler.SnippetCompilationHelper; -public class CtCodeSnippetStatementImpl extends CtStatementImpl implements - CtCodeSnippetStatement { +public class CtCodeSnippetStatementImpl extends CtStatementImpl implements CtCodeSnippetStatement { private static final long serialVersionUID = 1L; @@ -48,4 +47,8 @@ public S compile() throws SnippetCompilationError { return (S) SnippetCompilationHelper.compileStatement(this); } + @Override + public CtCodeSnippetStatement clone() { + return (CtCodeSnippetStatement) super.clone(); + } } diff --git a/src/main/java/spoon/support/reflect/code/CtCommentImpl.java b/src/main/java/spoon/support/reflect/code/CtCommentImpl.java index 0c35e8ae319..c39b63af99e 100644 --- a/src/main/java/spoon/support/reflect/code/CtCommentImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtCommentImpl.java @@ -84,4 +84,9 @@ public int hashCode() { result = 31 * result + (type != null ? type.hashCode() : 0); return result; } + + @Override + public CtComment clone() { + return (CtComment) super.clone(); + } } diff --git a/src/main/java/spoon/support/reflect/code/CtConditionalImpl.java b/src/main/java/spoon/support/reflect/code/CtConditionalImpl.java index 12cfd491666..b736eb89af6 100644 --- a/src/main/java/spoon/support/reflect/code/CtConditionalImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtConditionalImpl.java @@ -69,4 +69,9 @@ public > C setThenExpression(CtExpression thenExpr this.thenExpression = thenExpression; return (C) this; } + + @Override + public CtConditional clone() { + return (CtConditional) super.clone(); + } } diff --git a/src/main/java/spoon/support/reflect/code/CtConstructorCallImpl.java b/src/main/java/spoon/support/reflect/code/CtConstructorCallImpl.java index baf114d09f2..65a4a7ca3f1 100644 --- a/src/main/java/spoon/support/reflect/code/CtConstructorCallImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtConstructorCallImpl.java @@ -34,8 +34,7 @@ import static spoon.reflect.ModelElementContainerDefaultCapacities.PARAMETERS_CONTAINER_DEFAULT_CAPACITY; -public class CtConstructorCallImpl extends CtTargetedExpressionImpl> - implements CtConstructorCall { +public class CtConstructorCallImpl extends CtTargetedExpressionImpl> implements CtConstructorCall { private static final long serialVersionUID = 1L; List> arguments = emptyList(); @@ -181,4 +180,9 @@ public C setType(CtTypeReference type) { } return (C) this; } + + @Override + public CtConstructorCall clone() { + return (CtConstructorCall) super.clone(); + } } diff --git a/src/main/java/spoon/support/reflect/code/CtContinueImpl.java b/src/main/java/spoon/support/reflect/code/CtContinueImpl.java index a26aceca95c..cb3ccb34aab 100644 --- a/src/main/java/spoon/support/reflect/code/CtContinueImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtContinueImpl.java @@ -57,4 +57,8 @@ public T setTargetLabel(String targetLabel) { return (T) this; } + @Override + public CtContinue clone() { + return (CtContinue) super.clone(); + } } diff --git a/src/main/java/spoon/support/reflect/code/CtDoImpl.java b/src/main/java/spoon/support/reflect/code/CtDoImpl.java index 0ea3ffa0533..7853bd95801 100644 --- a/src/main/java/spoon/support/reflect/code/CtDoImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtDoImpl.java @@ -41,4 +41,9 @@ public T setLoopingExpression(CtExpression expression) this.expression = expression; return (T) this; } + + @Override + public CtDo clone() { + return (CtDo) super.clone(); + } } diff --git a/src/main/java/spoon/support/reflect/code/CtExecutableReferenceExpressionImpl.java b/src/main/java/spoon/support/reflect/code/CtExecutableReferenceExpressionImpl.java index 8a2159cbefa..ac54a9adc25 100644 --- a/src/main/java/spoon/support/reflect/code/CtExecutableReferenceExpressionImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtExecutableReferenceExpressionImpl.java @@ -21,8 +21,7 @@ import spoon.reflect.reference.CtExecutableReference; import spoon.reflect.visitor.CtVisitor; -public class CtExecutableReferenceExpressionImpl> - extends CtTargetedExpressionImpl implements CtExecutableReferenceExpression { +public class CtExecutableReferenceExpressionImpl> extends CtTargetedExpressionImpl implements CtExecutableReferenceExpression { CtExecutableReference executable; @Override @@ -43,4 +42,9 @@ public > C setExecutable(CtExecu this.executable = executable; return (C) this; } + + @Override + public CtExecutableReferenceExpression clone() { + return (CtExecutableReferenceExpression) super.clone(); + } } diff --git a/src/main/java/spoon/support/reflect/code/CtExpressionImpl.java b/src/main/java/spoon/support/reflect/code/CtExpressionImpl.java index c8df99b971e..0ff4f44f9cc 100644 --- a/src/main/java/spoon/support/reflect/code/CtExpressionImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtExpressionImpl.java @@ -26,8 +26,7 @@ import static spoon.reflect.ModelElementContainerDefaultCapacities.CASTS_CONTAINER_DEFAULT_CAPACITY; -public abstract class CtExpressionImpl extends CtCodeElementImpl implements - CtExpression { +public abstract class CtExpressionImpl extends CtCodeElementImpl implements CtExpression { private static final long serialVersionUID = 1L; CtTypeReference type; @@ -85,4 +84,9 @@ public void replace(CtExpression element) { public T S() { return null; } + + @Override + public CtExpression clone() { + return (CtExpression) super.clone(); + } } diff --git a/src/main/java/spoon/support/reflect/code/CtFieldAccessImpl.java b/src/main/java/spoon/support/reflect/code/CtFieldAccessImpl.java index 7eeda3b1a60..cc74d13e59a 100644 --- a/src/main/java/spoon/support/reflect/code/CtFieldAccessImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtFieldAccessImpl.java @@ -58,4 +58,9 @@ public > C setVariable(CtVariableReference vari public CtTypeReference getType() { return getVariable() == null ? null : getVariable().getType(); } + + @Override + public CtFieldAccess clone() { + return (CtFieldAccess) super.clone(); + } } diff --git a/src/main/java/spoon/support/reflect/code/CtFieldReadImpl.java b/src/main/java/spoon/support/reflect/code/CtFieldReadImpl.java index 4659f1927e6..5e8a9f31b49 100644 --- a/src/main/java/spoon/support/reflect/code/CtFieldReadImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtFieldReadImpl.java @@ -26,4 +26,9 @@ public class CtFieldReadImpl extends CtFieldAccessImpl implements CtFieldR public void accept(CtVisitor visitor) { visitor.visitCtFieldRead(this); } + + @Override + public CtFieldRead clone() { + return (CtFieldRead) super.clone(); + } } diff --git a/src/main/java/spoon/support/reflect/code/CtFieldWriteImpl.java b/src/main/java/spoon/support/reflect/code/CtFieldWriteImpl.java index 657c6943bc2..3194b79eaec 100644 --- a/src/main/java/spoon/support/reflect/code/CtFieldWriteImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtFieldWriteImpl.java @@ -26,4 +26,9 @@ public class CtFieldWriteImpl extends CtFieldAccessImpl implements CtField public void accept(CtVisitor visitor) { visitor.visitCtFieldWrite(this); } + + @Override + public CtFieldWrite clone() { + return (CtFieldWrite) super.clone(); + } } diff --git a/src/main/java/spoon/support/reflect/code/CtForEachImpl.java b/src/main/java/spoon/support/reflect/code/CtForEachImpl.java index 69278bd3a64..3de0019beb9 100644 --- a/src/main/java/spoon/support/reflect/code/CtForEachImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtForEachImpl.java @@ -56,4 +56,9 @@ public T setVariable(CtLocalVariable variable) { this.variable = variable; return (T) this; } + + @Override + public CtForEach clone() { + return (CtForEach) super.clone(); + } } diff --git a/src/main/java/spoon/support/reflect/code/CtForImpl.java b/src/main/java/spoon/support/reflect/code/CtForImpl.java index a33a484d97a..1caa4b4cf02 100644 --- a/src/main/java/spoon/support/reflect/code/CtForImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtForImpl.java @@ -16,19 +16,17 @@ */ package spoon.support.reflect.code; -import java.util.ArrayList; -import java.util.List; - import spoon.reflect.code.CtExpression; import spoon.reflect.code.CtFor; import spoon.reflect.code.CtStatement; import spoon.reflect.visitor.CtVisitor; import spoon.support.reflect.declaration.CtElementImpl; -import static spoon.reflect.ModelElementContainerDefaultCapacities - .FOR_INIT_STATEMENTS_CONTAINER_DEFAULT_CAPACITY; -import static spoon.reflect.ModelElementContainerDefaultCapacities - .FOR_UPDATE_STATEMENTS_CONTAINER_DEFAULT_CAPACITY; +import java.util.ArrayList; +import java.util.List; + +import static spoon.reflect.ModelElementContainerDefaultCapacities.FOR_INIT_STATEMENTS_CONTAINER_DEFAULT_CAPACITY; +import static spoon.reflect.ModelElementContainerDefaultCapacities.FOR_UPDATE_STATEMENTS_CONTAINER_DEFAULT_CAPACITY; public class CtForImpl extends CtLoopImpl implements CtFor { private static final long serialVersionUID = 1L; @@ -117,4 +115,8 @@ public boolean removeForUpdate(CtStatement statement) { return forUpdate != CtElementImpl.emptyList() && forUpdate.remove(statement); } + @Override + public CtFor clone() { + return (CtFor) super.clone(); + } } diff --git a/src/main/java/spoon/support/reflect/code/CtIfImpl.java b/src/main/java/spoon/support/reflect/code/CtIfImpl.java index 231db2212d8..8e1585dcead 100644 --- a/src/main/java/spoon/support/reflect/code/CtIfImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtIfImpl.java @@ -82,12 +82,17 @@ public T setThenStatement(CtStatement thenStatement) { return (T) this; } + @Override + public CtIf clone() { + return (CtIf) super.clone(); + } + @Override public Void S() { return null; } public CtCodeElement getSubstitution(CtType targetType) { - return getFactory().Core().clone(this); + return clone(); } } diff --git a/src/main/java/spoon/support/reflect/code/CtInvocationImpl.java b/src/main/java/spoon/support/reflect/code/CtInvocationImpl.java index 719abaa6db0..999d286b470 100644 --- a/src/main/java/spoon/support/reflect/code/CtInvocationImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtInvocationImpl.java @@ -183,4 +183,9 @@ public T addActualTypeArgument(CtTypeReference public boolean removeActualTypeArgument(CtTypeReference actualTypeArgument) { return getExecutable() != null && getExecutable().removeActualTypeArgument(actualTypeArgument); } + + @Override + public CtInvocation clone() { + return (CtInvocation) super.clone(); + } } diff --git a/src/main/java/spoon/support/reflect/code/CtLambdaImpl.java b/src/main/java/spoon/support/reflect/code/CtLambdaImpl.java index 4c7766c343d..e3b9dfb451e 100644 --- a/src/main/java/spoon/support/reflect/code/CtLambdaImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtLambdaImpl.java @@ -164,4 +164,9 @@ public > C setExpression(CtExpression expression) { this.expression = expression; return (C) this; } + + @Override + public CtLambda clone() { + return (CtLambda) super.clone(); + } } diff --git a/src/main/java/spoon/support/reflect/code/CtLiteralImpl.java b/src/main/java/spoon/support/reflect/code/CtLiteralImpl.java index dae7e20dab5..6b261288381 100644 --- a/src/main/java/spoon/support/reflect/code/CtLiteralImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtLiteralImpl.java @@ -20,8 +20,7 @@ import spoon.reflect.declaration.CtElement; import spoon.reflect.visitor.CtVisitor; -public class CtLiteralImpl extends CtExpressionImpl - implements CtLiteral { +public class CtLiteralImpl extends CtExpressionImpl implements CtLiteral { private static final long serialVersionUID = 1L; T value; @@ -45,4 +44,8 @@ public > C setValue(T value) { return (C) this; } + @Override + public CtLiteral clone() { + return (CtLiteral) super.clone(); + } } diff --git a/src/main/java/spoon/support/reflect/code/CtLocalVariableImpl.java b/src/main/java/spoon/support/reflect/code/CtLocalVariableImpl.java index 740c2eefc1b..f5403d963ee 100644 --- a/src/main/java/spoon/support/reflect/code/CtLocalVariableImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtLocalVariableImpl.java @@ -158,4 +158,9 @@ public > C setAssignment(CtExpression assignment) setDefaultExpression(assignment); return (C) this; } + + @Override + public CtLocalVariable clone() { + return (CtLocalVariable) super.clone(); + } } diff --git a/src/main/java/spoon/support/reflect/code/CtLoopImpl.java b/src/main/java/spoon/support/reflect/code/CtLoopImpl.java index 891f972af42..1bab9e4b33c 100644 --- a/src/main/java/spoon/support/reflect/code/CtLoopImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtLoopImpl.java @@ -40,12 +40,17 @@ public T setBody(CtStatement body) { return (T) this; } + @Override + public CtLoop clone() { + return (CtLoop) super.clone(); + } + @Override public Void S() { return null; } public CtCodeElement getSubstitution(CtType targetType) { - return getFactory().Core().clone(this); + return clone(); } } diff --git a/src/main/java/spoon/support/reflect/code/CtNewArrayImpl.java b/src/main/java/spoon/support/reflect/code/CtNewArrayImpl.java index 093349c9ecd..9a7f9cb0029 100644 --- a/src/main/java/spoon/support/reflect/code/CtNewArrayImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtNewArrayImpl.java @@ -16,16 +16,15 @@ */ package spoon.support.reflect.code; -import java.util.ArrayList; -import java.util.List; - import spoon.reflect.code.CtExpression; import spoon.reflect.code.CtNewArray; import spoon.reflect.visitor.CtVisitor; import spoon.support.reflect.declaration.CtElementImpl; -import static spoon.reflect.ModelElementContainerDefaultCapacities - .NEW_ARRAY_DEFAULT_EXPRESSIONS_CONTAINER_DEFAULT_CAPACITY; +import java.util.ArrayList; +import java.util.List; + +import static spoon.reflect.ModelElementContainerDefaultCapacities.NEW_ARRAY_DEFAULT_EXPRESSIONS_CONTAINER_DEFAULT_CAPACITY; public class CtNewArrayImpl extends CtExpressionImpl implements CtNewArray { private static final long serialVersionUID = 1L; @@ -99,4 +98,9 @@ public > C addElement(CtExpression expression) { public boolean removeElement(CtExpression expression) { return expressions != CtElementImpl.>emptyList() && expressions.remove(expression); } + + @Override + public CtNewArray clone() { + return (CtNewArray) super.clone(); + } } diff --git a/src/main/java/spoon/support/reflect/code/CtNewClassImpl.java b/src/main/java/spoon/support/reflect/code/CtNewClassImpl.java index 4904ec9d4b3..4715469bae2 100644 --- a/src/main/java/spoon/support/reflect/code/CtNewClassImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtNewClassImpl.java @@ -41,4 +41,9 @@ public N setAnonymousClass(CtClass anonymousClass) { this.anonymousClass = anonymousClass; return (N) this; } + + @Override + public CtNewClass clone() { + return (CtNewClass) super.clone(); + } } diff --git a/src/main/java/spoon/support/reflect/code/CtOperatorAssignmentImpl.java b/src/main/java/spoon/support/reflect/code/CtOperatorAssignmentImpl.java index c25e847a93e..f1cec987fc9 100644 --- a/src/main/java/spoon/support/reflect/code/CtOperatorAssignmentImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtOperatorAssignmentImpl.java @@ -20,8 +20,7 @@ import spoon.reflect.code.CtOperatorAssignment; import spoon.reflect.visitor.CtVisitor; -public class CtOperatorAssignmentImpl extends CtAssignmentImpl - implements CtOperatorAssignment { +public class CtOperatorAssignmentImpl extends CtAssignmentImpl implements CtOperatorAssignment { private static final long serialVersionUID = 1L; BinaryOperatorKind kind; @@ -41,4 +40,9 @@ public > C setKind(BinaryOperatorKind kind) this.kind = kind; return (C) this; } + + @Override + public CtOperatorAssignment clone() { + return (CtOperatorAssignment) super.clone(); + } } diff --git a/src/main/java/spoon/support/reflect/code/CtReturnImpl.java b/src/main/java/spoon/support/reflect/code/CtReturnImpl.java index e062289ae28..bb99a3b73a3 100644 --- a/src/main/java/spoon/support/reflect/code/CtReturnImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtReturnImpl.java @@ -46,12 +46,17 @@ public > T setReturnedExpression(CtExpression expressio return (T) this; } + @Override + public CtReturn clone() { + return (CtReturn) super.clone(); + } + @Override public Void S() { return null; } public CtCodeElement getSubstitution(CtType targetType) { - return getFactory().Core().clone(this); + return clone(); } } diff --git a/src/main/java/spoon/support/reflect/code/CtStatementImpl.java b/src/main/java/spoon/support/reflect/code/CtStatementImpl.java index f75620e0ba7..f43a0a0d8fa 100644 --- a/src/main/java/spoon/support/reflect/code/CtStatementImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtStatementImpl.java @@ -295,4 +295,9 @@ public T setLabel(String label) { public void replace(CtStatement element) { replace((CtElement) element); } + + @Override + public CtStatement clone() { + return (CtStatement) super.clone(); + } } diff --git a/src/main/java/spoon/support/reflect/code/CtStatementListImpl.java b/src/main/java/spoon/support/reflect/code/CtStatementListImpl.java index 8b2dcb409b5..48a697f6af3 100644 --- a/src/main/java/spoon/support/reflect/code/CtStatementListImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtStatementListImpl.java @@ -16,10 +16,6 @@ */ package spoon.support.reflect.code; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - import spoon.reflect.code.CtStatement; import spoon.reflect.code.CtStatementList; import spoon.reflect.cu.SourcePosition; @@ -28,6 +24,10 @@ import spoon.reflect.visitor.CtVisitor; import spoon.support.reflect.declaration.CtElementImpl; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + import static spoon.reflect.ModelElementContainerDefaultCapacities.BLOCK_STATEMENTS_CONTAINER_DEFAULT_CAPACITY; public class CtStatementListImpl extends CtCodeElementImpl implements CtStatementList { @@ -84,7 +84,12 @@ public Iterator iterator() { return statements.iterator(); } + @Override + public CtStatementList clone() { + return (CtStatementList) super.clone(); + } + public CtStatementList getSubstitution(CtType targetType) { - return getFactory().Core().clone(this); + return clone(); } } diff --git a/src/main/java/spoon/support/reflect/code/CtSuperAccessImpl.java b/src/main/java/spoon/support/reflect/code/CtSuperAccessImpl.java index 9de8dbcaeb8..b22ad8cfbd7 100644 --- a/src/main/java/spoon/support/reflect/code/CtSuperAccessImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtSuperAccessImpl.java @@ -45,4 +45,9 @@ public >> C setTarget(CtExpres this.target = target; return null; } + + @Override + public CtSuperAccess clone() { + return (CtSuperAccess) super.clone(); + } } diff --git a/src/main/java/spoon/support/reflect/code/CtSwitchImpl.java b/src/main/java/spoon/support/reflect/code/CtSwitchImpl.java index 4bd9cb16238..4b2707ee921 100644 --- a/src/main/java/spoon/support/reflect/code/CtSwitchImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtSwitchImpl.java @@ -16,15 +16,15 @@ */ package spoon.support.reflect.code; -import java.util.ArrayList; -import java.util.List; - import spoon.reflect.code.CtCase; import spoon.reflect.code.CtExpression; import spoon.reflect.code.CtSwitch; import spoon.reflect.visitor.CtVisitor; import spoon.support.reflect.declaration.CtElementImpl; +import java.util.ArrayList; +import java.util.List; + import static spoon.reflect.ModelElementContainerDefaultCapacities.SWITCH_CASES_CONTAINER_DEFAULT_CAPACITY; public class CtSwitchImpl extends CtStatementImpl implements CtSwitch { @@ -80,4 +80,8 @@ public boolean removeCase(CtCase c) { return cases != CtElementImpl.>emptyList() && cases.remove(c); } + @Override + public CtSwitch clone() { + return (CtSwitch) super.clone(); + } } diff --git a/src/main/java/spoon/support/reflect/code/CtSynchronizedImpl.java b/src/main/java/spoon/support/reflect/code/CtSynchronizedImpl.java index 6b9eb9e035f..3768fdf39dc 100644 --- a/src/main/java/spoon/support/reflect/code/CtSynchronizedImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtSynchronizedImpl.java @@ -56,4 +56,9 @@ public T setExpression(CtExpression expression) { this.expression = expression; return (T) this; } + + @Override + public CtSynchronized clone() { + return (CtSynchronized) super.clone(); + } } diff --git a/src/main/java/spoon/support/reflect/code/CtTargetedExpressionImpl.java b/src/main/java/spoon/support/reflect/code/CtTargetedExpressionImpl.java index ff22357da6b..b0a8bfc5e2f 100644 --- a/src/main/java/spoon/support/reflect/code/CtTargetedExpressionImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtTargetedExpressionImpl.java @@ -19,8 +19,7 @@ import spoon.reflect.code.CtExpression; import spoon.reflect.code.CtTargetedExpression; -public abstract class CtTargetedExpressionImpl> - extends CtExpressionImpl implements CtTargetedExpression { +public abstract class CtTargetedExpressionImpl> extends CtExpressionImpl implements CtTargetedExpression { private static final long serialVersionUID = 1L; T target; @@ -38,4 +37,9 @@ public > C setTarget(T target) { this.target = target; return (C) this; } + + @Override + public CtTargetedExpression clone() { + return (CtTargetedExpression) super.clone(); + } } diff --git a/src/main/java/spoon/support/reflect/code/CtThisAccessImpl.java b/src/main/java/spoon/support/reflect/code/CtThisAccessImpl.java index 37435bc4704..5f6d378a5e5 100644 --- a/src/main/java/spoon/support/reflect/code/CtThisAccessImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtThisAccessImpl.java @@ -28,4 +28,8 @@ public void accept(CtVisitor visitor) { visitor.visitCtThisAccess(this); } + @Override + public CtThisAccess clone() { + return (CtThisAccess) super.clone(); + } } diff --git a/src/main/java/spoon/support/reflect/code/CtThrowImpl.java b/src/main/java/spoon/support/reflect/code/CtThrowImpl.java index d6fb8791215..a7f359946db 100644 --- a/src/main/java/spoon/support/reflect/code/CtThrowImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtThrowImpl.java @@ -46,13 +46,18 @@ public T setThrownExpression(CtExpression targetType) { - return getFactory().Core().clone(this); + return clone(); } } diff --git a/src/main/java/spoon/support/reflect/code/CtTryImpl.java b/src/main/java/spoon/support/reflect/code/CtTryImpl.java index 58467203b4f..966b096188a 100644 --- a/src/main/java/spoon/support/reflect/code/CtTryImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtTryImpl.java @@ -16,9 +16,6 @@ */ package spoon.support.reflect.code; -import java.util.ArrayList; -import java.util.List; - import spoon.reflect.code.CtBlock; import spoon.reflect.code.CtCatch; import spoon.reflect.code.CtCodeElement; @@ -27,6 +24,9 @@ import spoon.reflect.visitor.CtVisitor; import spoon.support.reflect.declaration.CtElementImpl; +import java.util.ArrayList; +import java.util.List; + import static spoon.reflect.ModelElementContainerDefaultCapacities.CATCH_CASES_CONTAINER_DEFAULT_CAPACITY; public class CtTryImpl extends CtStatementImpl implements CtTry { @@ -96,13 +96,18 @@ public T setBody(CtBlock body) { return (T) this; } + @Override + public CtTry clone() { + return (CtTry) super.clone(); + } + @Override public Void S() { return null; } public CtCodeElement getSubstitution(CtType targetType) { - return getFactory().Core().clone(this); + return clone(); } } diff --git a/src/main/java/spoon/support/reflect/code/CtTryWithResourceImpl.java b/src/main/java/spoon/support/reflect/code/CtTryWithResourceImpl.java index 0ec97312acd..27a429bde02 100644 --- a/src/main/java/spoon/support/reflect/code/CtTryWithResourceImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtTryWithResourceImpl.java @@ -26,8 +26,7 @@ import static spoon.reflect.ModelElementContainerDefaultCapacities.RESOURCES_CONTAINER_DEFAULT_CAPACITY; -public class CtTryWithResourceImpl extends CtTryImpl - implements CtTryWithResource { +public class CtTryWithResourceImpl extends CtTryImpl implements CtTryWithResource { private static final long serialVersionUID = 1L; List> resources = emptyList(); @@ -65,4 +64,9 @@ public T addResource(CtLocalVariable resource) public boolean removeResource(CtLocalVariable resource) { return resources != CtElementImpl.>emptyList() && resources.remove(resource); } + + @Override + public CtTryWithResource clone() { + return (CtTryWithResource) super.clone(); + } } diff --git a/src/main/java/spoon/support/reflect/code/CtTypeAccessImpl.java b/src/main/java/spoon/support/reflect/code/CtTypeAccessImpl.java index ea95e8eb7e7..acf74b2efcd 100644 --- a/src/main/java/spoon/support/reflect/code/CtTypeAccessImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtTypeAccessImpl.java @@ -47,7 +47,7 @@ public > C setAccessedType(CtTypeReference accessed @Override public CtTypeReference getType() { if (voidType == null) { - voidType = getFactory().Core().clone(getFactory().Type().VOID_PRIMITIVE); + voidType = getFactory().Type().VOID_PRIMITIVE.clone(); voidType.setParent(this); } return voidType; @@ -58,4 +58,9 @@ public C setType(CtTypeReference type) { // type is used in setAccessedType now. return (C) this; } + + @Override + public CtTypeAccess clone() { + return (CtTypeAccess) super.clone(); + } } diff --git a/src/main/java/spoon/support/reflect/code/CtUnaryOperatorImpl.java b/src/main/java/spoon/support/reflect/code/CtUnaryOperatorImpl.java index 23d848ce020..30a198589d3 100644 --- a/src/main/java/spoon/support/reflect/code/CtUnaryOperatorImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtUnaryOperatorImpl.java @@ -109,4 +109,9 @@ public C setLabel(String label) { public void replace(CtStatement element) { replace((CtElement) element); } + + @Override + public CtUnaryOperator clone() { + return (CtUnaryOperator) super.clone(); + } } diff --git a/src/main/java/spoon/support/reflect/code/CtVariableAccessImpl.java b/src/main/java/spoon/support/reflect/code/CtVariableAccessImpl.java index 531d9ad7ace..cf5f5166475 100644 --- a/src/main/java/spoon/support/reflect/code/CtVariableAccessImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtVariableAccessImpl.java @@ -37,4 +37,9 @@ public > C setVariable(CtVariableReference vari this.variable = variable; return (C) this; } + + @Override + public CtVariableAccess clone() { + return (CtVariableAccess) super.clone(); + } } diff --git a/src/main/java/spoon/support/reflect/code/CtVariableReadImpl.java b/src/main/java/spoon/support/reflect/code/CtVariableReadImpl.java index ddb50207b99..0d8c3b63a11 100644 --- a/src/main/java/spoon/support/reflect/code/CtVariableReadImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtVariableReadImpl.java @@ -25,4 +25,9 @@ public class CtVariableReadImpl extends CtVariableAccessImpl implements Ct public void accept(CtVisitor visitor) { visitor.visitCtVariableRead(this); } + + @Override + public CtVariableRead clone() { + return (CtVariableRead) super.clone(); + } } diff --git a/src/main/java/spoon/support/reflect/code/CtVariableWriteImpl.java b/src/main/java/spoon/support/reflect/code/CtVariableWriteImpl.java index 19dbe29d175..bda2c063da1 100644 --- a/src/main/java/spoon/support/reflect/code/CtVariableWriteImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtVariableWriteImpl.java @@ -25,4 +25,9 @@ public class CtVariableWriteImpl extends CtVariableAccessImpl implements C public void accept(CtVisitor visitor) { visitor.visitCtVariableWrite(this); } + + @Override + public CtVariableWrite clone() { + return (CtVariableWrite) super.clone(); + } } diff --git a/src/main/java/spoon/support/reflect/code/CtWhileImpl.java b/src/main/java/spoon/support/reflect/code/CtWhileImpl.java index 3b2316c201e..52e271e7894 100644 --- a/src/main/java/spoon/support/reflect/code/CtWhileImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtWhileImpl.java @@ -41,4 +41,9 @@ public T setLoopingExpression(CtExpression expressi this.expression = expression; return (T) this; } + + @Override + public CtWhile clone() { + return (CtWhile) super.clone(); + } } diff --git a/src/main/java/spoon/support/reflect/declaration/CtAnnotationImpl.java b/src/main/java/spoon/support/reflect/declaration/CtAnnotationImpl.java index 0aa38889797..772474495dc 100644 --- a/src/main/java/spoon/support/reflect/declaration/CtAnnotationImpl.java +++ b/src/main/java/spoon/support/reflect/declaration/CtAnnotationImpl.java @@ -82,7 +82,7 @@ public > T addValue(String elementName, Object value) if (value instanceof CtExpression) { return addValueExpression(elementName, (CtExpression) value); } - return addValueExpression(elementName, convertValueToExpression(value)); + return this.addValueExpression(elementName, convertValueToExpression(value)); } private CtExpression convertValueToExpression(Object value) { @@ -462,4 +462,9 @@ public E setShadow(boolean isShadow) { this.isShadow = isShadow; return (E) this; } + + @Override + public CtAnnotation clone() { + return (CtAnnotation) super.clone(); + } } diff --git a/src/main/java/spoon/support/reflect/declaration/CtAnnotationTypeImpl.java b/src/main/java/spoon/support/reflect/declaration/CtAnnotationTypeImpl.java index 74dd6f52df7..185a096e035 100644 --- a/src/main/java/spoon/support/reflect/declaration/CtAnnotationTypeImpl.java +++ b/src/main/java/spoon/support/reflect/declaration/CtAnnotationTypeImpl.java @@ -53,12 +53,12 @@ private CtMethod createGhostMethod(CtField field) { method.setImplicit(true); method.setSimpleName(field.getSimpleName()); method.setModifiers(field.getModifiers()); - method.setType(factory.Core().clone(field.getType())); + method.setType(field.getType() == null ? null : field.getType().clone()); for (CtAnnotation ctAnnotation : field.getAnnotations()) { - method.addAnnotation(factory.Core().clone(ctAnnotation)); + method.addAnnotation(ctAnnotation.clone()); } for (CtComment ctComment : field.getComments()) { - method.addComment(factory.Core().clone(ctComment)); + method.addComment(ctComment.clone()); } method.setDocComment(field.getDocComment()); method.setPosition(field.getPosition()); @@ -158,4 +158,9 @@ public C addFormalTypeParameter(CtTypeParameter public boolean removeFormalTypeParameter(CtTypeParameterReference formalTypeParameter) { throw new UnsupportedOperationException("You can't have generics in an annotation."); } + + @Override + public CtAnnotationType clone() { + return (CtAnnotationType) super.clone(); + } } diff --git a/src/main/java/spoon/support/reflect/declaration/CtAnonymousExecutableImpl.java b/src/main/java/spoon/support/reflect/declaration/CtAnonymousExecutableImpl.java index ec93c7152ec..e96aa6688f3 100644 --- a/src/main/java/spoon/support/reflect/declaration/CtAnonymousExecutableImpl.java +++ b/src/main/java/spoon/support/reflect/declaration/CtAnonymousExecutableImpl.java @@ -161,4 +161,9 @@ public CtTypeReference getType() { public C setType(CtTypeReference type) { throw new UnsupportedOperationException("An anonymous executable isn't typed"); } + + @Override + public CtAnonymousExecutable clone() { + return (CtAnonymousExecutable) super.clone(); + } } diff --git a/src/main/java/spoon/support/reflect/declaration/CtClassImpl.java b/src/main/java/spoon/support/reflect/declaration/CtClassImpl.java index 5f459567f89..a09865c2164 100644 --- a/src/main/java/spoon/support/reflect/declaration/CtClassImpl.java +++ b/src/main/java/spoon/support/reflect/declaration/CtClassImpl.java @@ -246,4 +246,9 @@ public Collection> getDeclaredExecutables() { public void replace(CtStatement element) { replace((CtElement) element); } + + @Override + public CtClass clone() { + return (CtClass) super.clone(); + } } diff --git a/src/main/java/spoon/support/reflect/declaration/CtConstructorImpl.java b/src/main/java/spoon/support/reflect/declaration/CtConstructorImpl.java index 0c42db72bd0..710b411d60f 100644 --- a/src/main/java/spoon/support/reflect/declaration/CtConstructorImpl.java +++ b/src/main/java/spoon/support/reflect/declaration/CtConstructorImpl.java @@ -179,4 +179,9 @@ public E setShadow(boolean isShadow) { this.isShadow = isShadow; return (E) this; } + + @Override + public CtConstructor clone() { + return (CtConstructor) super.clone(); + } } diff --git a/src/main/java/spoon/support/reflect/declaration/CtElementImpl.java b/src/main/java/spoon/support/reflect/declaration/CtElementImpl.java index 54d2c7c42bc..318ca2318d6 100644 --- a/src/main/java/spoon/support/reflect/declaration/CtElementImpl.java +++ b/src/main/java/spoon/support/reflect/declaration/CtElementImpl.java @@ -440,4 +440,9 @@ public E setComments(List comments) { } return (E) this; } + + @Override + public CtElement clone() { + return getFactory().Core().clone(this); + } } diff --git a/src/main/java/spoon/support/reflect/declaration/CtEnumImpl.java b/src/main/java/spoon/support/reflect/declaration/CtEnumImpl.java index 7ce03de6ac0..dc2114a4e1a 100644 --- a/src/main/java/spoon/support/reflect/declaration/CtEnumImpl.java +++ b/src/main/java/spoon/support/reflect/declaration/CtEnumImpl.java @@ -112,4 +112,9 @@ public CtField getField(String name) { } return field; } + + @Override + public CtEnum clone() { + return (CtEnum) super.clone(); + } } diff --git a/src/main/java/spoon/support/reflect/declaration/CtEnumValueImpl.java b/src/main/java/spoon/support/reflect/declaration/CtEnumValueImpl.java index 39a67d361d2..b6e295c6f38 100644 --- a/src/main/java/spoon/support/reflect/declaration/CtEnumValueImpl.java +++ b/src/main/java/spoon/support/reflect/declaration/CtEnumValueImpl.java @@ -24,4 +24,9 @@ public class CtEnumValueImpl extends CtFieldImpl implements CtEnumValue public void accept(CtVisitor v) { v.visitCtEnumValue(this); } + + @Override + public CtEnumValue clone() { + return (CtEnumValue) super.clone(); + } } diff --git a/src/main/java/spoon/support/reflect/declaration/CtExecutableImpl.java b/src/main/java/spoon/support/reflect/declaration/CtExecutableImpl.java index e3067b9b20f..5def248a301 100644 --- a/src/main/java/spoon/support/reflect/declaration/CtExecutableImpl.java +++ b/src/main/java/spoon/support/reflect/declaration/CtExecutableImpl.java @@ -132,4 +132,9 @@ public boolean removeThrownType(CtTypeReference throwType) public CtExecutableReference getReference() { return getFactory().Executable().createReference(this); } + + @Override + public CtExecutable clone() { + return (CtExecutable) super.clone(); + } } diff --git a/src/main/java/spoon/support/reflect/declaration/CtFieldImpl.java b/src/main/java/spoon/support/reflect/declaration/CtFieldImpl.java index 829e90a8b35..cc429a182a8 100644 --- a/src/main/java/spoon/support/reflect/declaration/CtFieldImpl.java +++ b/src/main/java/spoon/support/reflect/declaration/CtFieldImpl.java @@ -178,4 +178,9 @@ public E setShadow(boolean isShadow) { this.isShadow = isShadow; return (E) this; } + + @Override + public CtField clone() { + return (CtField) super.clone(); + } } diff --git a/src/main/java/spoon/support/reflect/declaration/CtInterfaceImpl.java b/src/main/java/spoon/support/reflect/declaration/CtInterfaceImpl.java index cb36422914d..565622207d5 100644 --- a/src/main/java/spoon/support/reflect/declaration/CtInterfaceImpl.java +++ b/src/main/java/spoon/support/reflect/declaration/CtInterfaceImpl.java @@ -16,17 +16,17 @@ */ package spoon.support.reflect.declaration; +import spoon.reflect.declaration.CtInterface; +import spoon.reflect.reference.CtExecutableReference; +import spoon.reflect.reference.CtTypeReference; +import spoon.reflect.visitor.CtVisitor; + import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.Set; -import spoon.reflect.declaration.CtInterface; -import spoon.reflect.reference.CtExecutableReference; -import spoon.reflect.reference.CtTypeReference; -import spoon.reflect.visitor.CtVisitor; - public class CtInterfaceImpl extends CtTypeImpl implements CtInterface { private static final long serialVersionUID = 1L; @@ -63,4 +63,8 @@ public Collection> getDeclaredExecutables() { return Collections.unmodifiableList(l); } + @Override + public CtInterface clone() { + return (CtInterface) super.clone(); + } } diff --git a/src/main/java/spoon/support/reflect/declaration/CtMethodImpl.java b/src/main/java/spoon/support/reflect/declaration/CtMethodImpl.java index ea7f2090d27..c4519d4f2ba 100644 --- a/src/main/java/spoon/support/reflect/declaration/CtMethodImpl.java +++ b/src/main/java/spoon/support/reflect/declaration/CtMethodImpl.java @@ -198,4 +198,9 @@ public E setShadow(boolean isShadow) { this.isShadow = isShadow; return (E) this; } + + @Override + public CtMethod clone() { + return (CtMethod) super.clone(); + } } diff --git a/src/main/java/spoon/support/reflect/declaration/CtNamedElementImpl.java b/src/main/java/spoon/support/reflect/declaration/CtNamedElementImpl.java index 74cd49c94dc..98e3414a1fc 100644 --- a/src/main/java/spoon/support/reflect/declaration/CtNamedElementImpl.java +++ b/src/main/java/spoon/support/reflect/declaration/CtNamedElementImpl.java @@ -46,4 +46,9 @@ public T setSimpleName(String simpleName) { this.simpleName = simpleName; return (T) this; } + + @Override + public CtNamedElement clone() { + return (CtNamedElement) super.clone(); + } } diff --git a/src/main/java/spoon/support/reflect/declaration/CtPackageImpl.java b/src/main/java/spoon/support/reflect/declaration/CtPackageImpl.java index 7b9275b1896..53cc67fa7a8 100644 --- a/src/main/java/spoon/support/reflect/declaration/CtPackageImpl.java +++ b/src/main/java/spoon/support/reflect/declaration/CtPackageImpl.java @@ -16,9 +16,6 @@ */ package spoon.support.reflect.declaration; -import java.util.Set; -import java.util.TreeSet; - import spoon.reflect.cu.SourcePosition; import spoon.reflect.declaration.CtPackage; import spoon.reflect.declaration.CtShadowable; @@ -27,6 +24,9 @@ import spoon.reflect.reference.CtPackageReference; import spoon.reflect.visitor.CtVisitor; +import java.util.Set; +import java.util.TreeSet; + /** * The implementation for {@link spoon.reflect.declaration.CtPackage}. * @@ -210,4 +210,9 @@ public E setShadow(boolean isShadow) { this.isShadow = isShadow; return (E) this; } + + @Override + public CtPackage clone() { + return (CtPackage) super.clone(); + } } diff --git a/src/main/java/spoon/support/reflect/declaration/CtParameterImpl.java b/src/main/java/spoon/support/reflect/declaration/CtParameterImpl.java index a6f616c2b42..e9fe63ed56e 100644 --- a/src/main/java/spoon/support/reflect/declaration/CtParameterImpl.java +++ b/src/main/java/spoon/support/reflect/declaration/CtParameterImpl.java @@ -167,4 +167,9 @@ public E setShadow(boolean isShadow) { this.isShadow = isShadow; return (E) this; } + + @Override + public CtParameter clone() { + return (CtParameter) super.clone(); + } } diff --git a/src/main/java/spoon/support/reflect/declaration/CtTypeImpl.java b/src/main/java/spoon/support/reflect/declaration/CtTypeImpl.java index 49e40cde40a..65357f9e54a 100644 --- a/src/main/java/spoon/support/reflect/declaration/CtTypeImpl.java +++ b/src/main/java/spoon/support/reflect/declaration/CtTypeImpl.java @@ -754,4 +754,9 @@ public E setShadow(boolean isShadow) { this.isShadow = isShadow; return (E) this; } + + @Override + public CtType clone() { + return (CtType) super.clone(); + } } diff --git a/src/main/java/spoon/support/reflect/declaration/CtUncomparableException.java b/src/main/java/spoon/support/reflect/declaration/CtUncomparableException.java deleted file mode 100644 index b88beb80259..00000000000 --- a/src/main/java/spoon/support/reflect/declaration/CtUncomparableException.java +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Copyright (C) 2006-2015 INRIA and contributors - * Spoon - http://spoon.gforge.inria.fr/ - * - * This software is governed by the CeCILL-C License under French law and - * abiding by the rules of distribution of free software. You can use, modify - * and/or redistribute the software under the terms of the CeCILL-C license as - * circulated by CEA, CNRS and INRIA at http://www.cecill.info. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the CeCILL-C License for more details. - * - * The fact that you are presently reading this means that you have had - * knowledge of the CeCILL-C license and that you accept its terms. - */ -package spoon.support.reflect.declaration; - -import spoon.SpoonException; - -public class CtUncomparableException extends SpoonException { - - private static final long serialVersionUID = 1L; - - public CtUncomparableException() { - super(); - } - - public CtUncomparableException(String message) { - super(message); - } - - public CtUncomparableException(Throwable cause) { - super(cause); - } - -} diff --git a/src/main/java/spoon/support/reflect/eval/VisitorPartialEvaluator.java b/src/main/java/spoon/support/reflect/eval/VisitorPartialEvaluator.java index 338447b47e2..ffd9c291da1 100644 --- a/src/main/java/spoon/support/reflect/eval/VisitorPartialEvaluator.java +++ b/src/main/java/spoon/support/reflect/eval/VisitorPartialEvaluator.java @@ -173,17 +173,17 @@ public void visitCtAnonymousExecutable(CtAnonymousExecutable impl) { } public > void visitCtArrayAccess(CtArrayAccess arrayAccess) { - setResult(arrayAccess.getFactory().Core().clone(arrayAccess)); + setResult(arrayAccess.clone()); } @Override public void visitCtArrayRead(CtArrayRead arrayRead) { - setResult(arrayRead.getFactory().Core().clone(arrayRead)); + setResult(arrayRead.clone()); } @Override public void visitCtArrayWrite(CtArrayWrite arrayWrite) { - setResult(arrayWrite.getFactory().Core().clone(arrayWrite)); + setResult(arrayWrite.clone()); } public void visitCtArrayTypeReference(CtArrayTypeReference reference) { @@ -357,7 +357,7 @@ public void visitCtBlock(CtBlock block) { } public void visitCtBreak(CtBreak breakStatement) { - setResult(breakStatement.getFactory().Core().clone(breakStatement)); + setResult(breakStatement.clone()); } public void visitCtCase(CtCase caseStatement) { @@ -365,7 +365,7 @@ public void visitCtCase(CtCase caseStatement) { } public void visitCtCatch(CtCatch catchBlock) { - setResult(catchBlock.getFactory().Core().clone(catchBlock)); + setResult(catchBlock.clone()); } public void visitCtClass(CtClass ctClass) { @@ -377,11 +377,11 @@ public void visitCtConstructor(CtConstructor c) { } public void visitCtContinue(CtContinue continueStatement) { - setResult(continueStatement.getFactory().Core().clone(continueStatement)); + setResult(continueStatement.clone()); } public void visitCtDo(CtDo doLoop) { - CtDo w = doLoop.getFactory().Core().clone(doLoop); + CtDo w = doLoop.clone(); w.setLoopingExpression(evaluate(w, doLoop.getLoopingExpression())); w.setBody(evaluate(w, doLoop.getBody())); setResult(w); @@ -440,12 +440,12 @@ private void visitFieldAccess(CtFieldAccess fieldAccess) { setResult(evaluate(f, f.getDefaultExpression())); return; } - setResult(fieldAccess.getFactory().Core().clone(fieldAccess)); + setResult(fieldAccess.clone()); } @Override public void visitCtThisAccess(CtThisAccess thisAccess) { - setResult(thisAccess.getFactory().Core().clone(thisAccess)); + setResult(thisAccess.clone()); } public void visitCtAnnotationFieldAccess(CtAnnotationFieldAccess annotationFieldAccess) { @@ -480,11 +480,11 @@ public void visitCtFor(CtFor forLoop) { } } - setResult(forLoop.getFactory().Core().clone(forLoop)); + setResult(forLoop.clone()); } public void visitCtForEach(CtForEach foreach) { - setResult(foreach.getFactory().Core().clone(foreach)); + setResult(foreach.clone()); } public void visitCtGenericElementReference(CtActualTypeContainer reference) { @@ -580,7 +580,7 @@ public void visitCtInvocation(CtInvocation invocation) { } public void visitCtLiteral(CtLiteral literal) { - setResult(literal.getFactory().Core().clone(literal)); + setResult(literal.clone()); } public void visitCtLocalVariable(final CtLocalVariable localVariable) { @@ -598,7 +598,7 @@ public void visitCtLocalVariable(final CtLocalVariable localVariable) { // } // }); // if (res.size() != 0) - CtLocalVariable r = localVariable.getFactory().Core().clone(localVariable); + CtLocalVariable r = localVariable.clone(); r.setDefaultExpression(evaluate(r, localVariable.getDefaultExpression())); setResult(r); } @@ -609,7 +609,7 @@ public void visitCtLocalVariableReference(CtLocalVariableReference refere @Override public void visitCtCatchVariable(CtCatchVariable catchVariable) { - CtCatchVariable r = catchVariable.getFactory().Core().clone(catchVariable); + CtCatchVariable r = catchVariable.clone(); r.setDefaultExpression(evaluate(r, catchVariable.getDefaultExpression())); setResult(r); } @@ -624,31 +624,31 @@ public void visitCtMethod(CtMethod m) { } public void visitCtNewArray(CtNewArray newArray) { - setResult(newArray.getFactory().Core().clone(newArray)); + setResult(newArray.clone()); } @Override public void visitCtConstructorCall(CtConstructorCall ctConstructorCall) { - setResult(ctConstructorCall.getFactory().Core().clone(ctConstructorCall)); + setResult(ctConstructorCall.clone()); } public void visitCtNewClass(CtNewClass newClass) { - setResult(newClass.getFactory().Core().clone(newClass)); + setResult(newClass.clone()); } @Override public void visitCtLambda(CtLambda lambda) { - setResult(lambda.getFactory().Core().clone(lambda)); + setResult(lambda.clone()); } @Override public > void visitCtExecutableReferenceExpression( CtExecutableReferenceExpression expression) { - setResult(expression.getFactory().Core().clone(expression)); + setResult(expression.clone()); } public void visitCtOperatorAssignment(CtOperatorAssignment assignment) { - setResult(assignment.getFactory().Core().clone(assignment)); + setResult(assignment.clone()); } public void visitCtPackage(CtPackage ctPackage) { @@ -683,11 +683,11 @@ public void visitCtReturn(CtReturn returnStatement) { } public void visitCtSwitch(CtSwitch switchStatement) { - setResult(switchStatement.getFactory().Core().clone(switchStatement)); + setResult(switchStatement.clone()); } public void visitCtSynchronized(CtSynchronized synchro) { - CtSynchronized s = synchro.getFactory().Core().clone(synchro); + CtSynchronized s = synchro.clone(); s.setBlock(evaluate(s, synchro.getBlock())); setResult(s); } @@ -705,7 +705,7 @@ public void visitCtThrow(CtThrow throwStatement) { } public void visitCtTry(CtTry tryBlock) { - setResult(tryBlock.getFactory().Core().clone(tryBlock)); + setResult(tryBlock.clone()); } @Override @@ -756,7 +756,7 @@ public void visitCtUnaryOperator(CtUnaryOperator operator) { setResult(res); return; } - setResult(operator.getFactory().Core().clone(operator)); + setResult(operator.clone()); } @Override @@ -774,12 +774,12 @@ private void visitVariableAccess(CtVariableAccess variableAccess) { if (v != null && v.hasModifier(ModifierKind.FINAL) && v.getDefaultExpression() != null) { setResult(evaluate(v, v.getDefaultExpression())); } else { - setResult(variableAccess.getFactory().Core().clone(variableAccess)); + setResult(variableAccess.clone()); } } public void visitCtAssignment(CtAssignment variableAssignment) { - CtAssignment a = variableAssignment.getFactory().Core().clone(variableAssignment); + CtAssignment a = variableAssignment.clone(); a.setAssignment(evaluate(a, a.getAssignment())); setResult(a); } @@ -789,7 +789,7 @@ public void visitCtVariableReference(CtVariableReference reference) { } public void visitCtWhile(CtWhile whileLoop) { - CtWhile w = whileLoop.getFactory().Core().clone(whileLoop); + CtWhile w = whileLoop.clone(); w.setLoopingExpression(evaluate(w, whileLoop.getLoopingExpression())); // If lopping Expression always false if ((whileLoop.getLoopingExpression() instanceof CtLiteral) && !((CtLiteral) whileLoop @@ -825,6 +825,6 @@ public void visitCtUnboundVariableReference(CtUnboundVariableReference re @Override public void visitCtSuperAccess(CtSuperAccess f) { - setResult(f.getFactory().Core().clone(f)); + setResult(f.clone()); } } diff --git a/src/main/java/spoon/support/reflect/internal/CtCircularTypeReferenceImpl.java b/src/main/java/spoon/support/reflect/internal/CtCircularTypeReferenceImpl.java index 432a8dba55f..165ab1b7005 100644 --- a/src/main/java/spoon/support/reflect/internal/CtCircularTypeReferenceImpl.java +++ b/src/main/java/spoon/support/reflect/internal/CtCircularTypeReferenceImpl.java @@ -25,4 +25,9 @@ public class CtCircularTypeReferenceImpl extends CtTypeParameterReferenceImpl im public void accept(CtVisitor visitor) { visitor.visitCtCircularTypeReference(this); } + + @Override + public CtCircularTypeReference clone() { + return (CtCircularTypeReference) super.clone(); + } } diff --git a/src/main/java/spoon/support/reflect/reference/CtArrayTypeReferenceImpl.java b/src/main/java/spoon/support/reflect/reference/CtArrayTypeReferenceImpl.java index 8d8fad496d1..f63b239b297 100644 --- a/src/main/java/spoon/support/reflect/reference/CtArrayTypeReferenceImpl.java +++ b/src/main/java/spoon/support/reflect/reference/CtArrayTypeReferenceImpl.java @@ -22,8 +22,7 @@ import java.lang.reflect.Array; -public class CtArrayTypeReferenceImpl extends CtTypeReferenceImpl - implements CtArrayTypeReference { +public class CtArrayTypeReferenceImpl extends CtTypeReferenceImpl implements CtArrayTypeReference { private static final long serialVersionUID = 1L; public static final String ARRAY_SIMPLE_NAME = Array.class.getSimpleName(); @@ -94,4 +93,8 @@ public int getDimensionCount() { return 1; } + @Override + public CtArrayTypeReference clone() { + return (CtArrayTypeReference) super.clone(); + } } diff --git a/src/main/java/spoon/support/reflect/reference/CtCatchVariableReferenceImpl.java b/src/main/java/spoon/support/reflect/reference/CtCatchVariableReferenceImpl.java index 87937d46b86..084f081dbfd 100644 --- a/src/main/java/spoon/support/reflect/reference/CtCatchVariableReferenceImpl.java +++ b/src/main/java/spoon/support/reflect/reference/CtCatchVariableReferenceImpl.java @@ -20,8 +20,7 @@ import spoon.reflect.reference.CtCatchVariableReference; import spoon.reflect.visitor.CtVisitor; -public class CtCatchVariableReferenceImpl extends CtVariableReferenceImpl - implements CtCatchVariableReference { +public class CtCatchVariableReferenceImpl extends CtVariableReferenceImpl implements CtCatchVariableReference { private static final long serialVersionUID = 1L; private CtCatchVariable declaration; @@ -45,4 +44,9 @@ public > C setDeclaration(CtCatchVariable< this.declaration = declaration; return (C) this; } + + @Override + public CtCatchVariableReference clone() { + return (CtCatchVariableReference) super.clone(); + } } diff --git a/src/main/java/spoon/support/reflect/reference/CtExecutableReferenceImpl.java b/src/main/java/spoon/support/reflect/reference/CtExecutableReferenceImpl.java index 855085bf4da..793be096ccf 100644 --- a/src/main/java/spoon/support/reflect/reference/CtExecutableReferenceImpl.java +++ b/src/main/java/spoon/support/reflect/reference/CtExecutableReferenceImpl.java @@ -43,8 +43,7 @@ import static spoon.reflect.ModelElementContainerDefaultCapacities.METHOD_TYPE_PARAMETERS_CONTAINER_DEFAULT_CAPACITY; -public class CtExecutableReferenceImpl extends CtReferenceImpl - implements CtExecutableReference { +public class CtExecutableReferenceImpl extends CtReferenceImpl implements CtExecutableReference { private static final long serialVersionUID = 1L; boolean stat = false; @@ -425,4 +424,9 @@ public boolean removeActualTypeArgument( return actualTypeArguments != CtElementImpl.>emptyList() && actualTypeArguments.remove(actualTypeArgument); } + + @Override + public CtExecutableReference clone() { + return (CtExecutableReference) super.clone(); + } } diff --git a/src/main/java/spoon/support/reflect/reference/CtFieldReferenceImpl.java b/src/main/java/spoon/support/reflect/reference/CtFieldReferenceImpl.java index 72dead4f06c..4c600ea94e2 100644 --- a/src/main/java/spoon/support/reflect/reference/CtFieldReferenceImpl.java +++ b/src/main/java/spoon/support/reflect/reference/CtFieldReferenceImpl.java @@ -32,8 +32,7 @@ import java.util.Set; import java.util.TreeSet; -public class CtFieldReferenceImpl extends CtVariableReferenceImpl - implements CtFieldReference { +public class CtFieldReferenceImpl extends CtVariableReferenceImpl implements CtFieldReference { private static final long serialVersionUID = 1L; CtTypeReference declaringType; @@ -212,4 +211,8 @@ public Set getModifiers() { return new TreeSet(); } + @Override + public CtFieldReference clone() { + return (CtFieldReference) super.clone(); + } } diff --git a/src/main/java/spoon/support/reflect/reference/CtIntersectionTypeReferenceImpl.java b/src/main/java/spoon/support/reflect/reference/CtIntersectionTypeReferenceImpl.java index 308ce2dec9a..3813ba77d88 100644 --- a/src/main/java/spoon/support/reflect/reference/CtIntersectionTypeReferenceImpl.java +++ b/src/main/java/spoon/support/reflect/reference/CtIntersectionTypeReferenceImpl.java @@ -78,4 +78,9 @@ public int compare(CtTypeReference o1, CtTypeReference o2) { return (pos1 < pos2) ? -1 : ((pos1 == pos2) ? 0 : 1); } } + + @Override + public CtIntersectionTypeReference clone() { + return (CtIntersectionTypeReference) super.clone(); + } } diff --git a/src/main/java/spoon/support/reflect/reference/CtLocalVariableReferenceImpl.java b/src/main/java/spoon/support/reflect/reference/CtLocalVariableReferenceImpl.java index 96f6ca4d28e..99859786b98 100644 --- a/src/main/java/spoon/support/reflect/reference/CtLocalVariableReferenceImpl.java +++ b/src/main/java/spoon/support/reflect/reference/CtLocalVariableReferenceImpl.java @@ -20,8 +20,7 @@ import spoon.reflect.reference.CtLocalVariableReference; import spoon.reflect.visitor.CtVisitor; -public class CtLocalVariableReferenceImpl extends CtVariableReferenceImpl - implements CtLocalVariableReference { +public class CtLocalVariableReferenceImpl extends CtVariableReferenceImpl implements CtLocalVariableReference { private static final long serialVersionUID = 1L; private CtLocalVariable declaration; @@ -46,4 +45,8 @@ public > C setDeclaration(CtLocalVariable< return (C) this; } + @Override + public CtLocalVariableReference clone() { + return (CtLocalVariableReference) super.clone(); + } } diff --git a/src/main/java/spoon/support/reflect/reference/CtPackageReferenceImpl.java b/src/main/java/spoon/support/reflect/reference/CtPackageReferenceImpl.java index eada5b4a3d5..17d6c26a814 100644 --- a/src/main/java/spoon/support/reflect/reference/CtPackageReferenceImpl.java +++ b/src/main/java/spoon/support/reflect/reference/CtPackageReferenceImpl.java @@ -22,8 +22,7 @@ import java.lang.reflect.AnnotatedElement; -public class CtPackageReferenceImpl extends CtReferenceImpl - implements CtPackageReference { +public class CtPackageReferenceImpl extends CtReferenceImpl implements CtPackageReference { private static final long serialVersionUID = 1L; public CtPackageReferenceImpl() { @@ -55,4 +54,8 @@ protected AnnotatedElement getActualAnnotatedElement() { return getActualPackage(); } + @Override + public CtPackageReference clone() { + return (CtPackageReference) super.clone(); + } } diff --git a/src/main/java/spoon/support/reflect/reference/CtParameterReferenceImpl.java b/src/main/java/spoon/support/reflect/reference/CtParameterReferenceImpl.java index 1590af94409..4c90d6aba2d 100644 --- a/src/main/java/spoon/support/reflect/reference/CtParameterReferenceImpl.java +++ b/src/main/java/spoon/support/reflect/reference/CtParameterReferenceImpl.java @@ -24,8 +24,7 @@ import java.util.List; -public class CtParameterReferenceImpl extends CtVariableReferenceImpl - implements CtParameterReference { +public class CtParameterReferenceImpl extends CtVariableReferenceImpl implements CtParameterReference { private static final long serialVersionUID = 1L; CtExecutableReference executable; @@ -69,4 +68,9 @@ public > C setDeclaringExecutable(CtExecutable this.executable = executable; return (C) this; } + + @Override + public CtParameterReference clone() { + return (CtParameterReference) super.clone(); + } } diff --git a/src/main/java/spoon/support/reflect/reference/CtReferenceImpl.java b/src/main/java/spoon/support/reflect/reference/CtReferenceImpl.java index bcaf4c74547..504cbf48369 100644 --- a/src/main/java/spoon/support/reflect/reference/CtReferenceImpl.java +++ b/src/main/java/spoon/support/reflect/reference/CtReferenceImpl.java @@ -69,4 +69,9 @@ public String toString() { public void accept(CtVisitor visitor) { throw new UnsupportedOperationException("Must be implemented in subclasses."); } + + @Override + public CtReference clone() { + return (CtReference) super.clone(); + } } diff --git a/src/main/java/spoon/support/reflect/reference/CtTypeParameterReferenceImpl.java b/src/main/java/spoon/support/reflect/reference/CtTypeParameterReferenceImpl.java index 00ebcd876bd..b34145a29c1 100644 --- a/src/main/java/spoon/support/reflect/reference/CtTypeParameterReferenceImpl.java +++ b/src/main/java/spoon/support/reflect/reference/CtTypeParameterReferenceImpl.java @@ -183,4 +183,9 @@ public T setSimpleName(String simplename) { this.simplename = simplename; return (T) this; } + + @Override + public CtTypeParameterReference clone() { + return (CtTypeParameterReference) super.clone(); + } } diff --git a/src/main/java/spoon/support/reflect/reference/CtTypeReferenceImpl.java b/src/main/java/spoon/support/reflect/reference/CtTypeReferenceImpl.java index 69b9310779a..180456ad481 100644 --- a/src/main/java/spoon/support/reflect/reference/CtTypeReferenceImpl.java +++ b/src/main/java/spoon/support/reflect/reference/CtTypeReferenceImpl.java @@ -516,4 +516,9 @@ public E setShadow(boolean isShadow) { this.isShadow = isShadow; return (E) this; } + + @Override + public CtTypeReference clone() { + return (CtTypeReference) super.clone(); + } } diff --git a/src/main/java/spoon/support/reflect/reference/CtUnboundVariableReferenceImpl.java b/src/main/java/spoon/support/reflect/reference/CtUnboundVariableReferenceImpl.java index 11c65d03bca..1c4eaf7003b 100644 --- a/src/main/java/spoon/support/reflect/reference/CtUnboundVariableReferenceImpl.java +++ b/src/main/java/spoon/support/reflect/reference/CtUnboundVariableReferenceImpl.java @@ -20,13 +20,16 @@ import spoon.reflect.visitor.CtVisitor; /** represents a reference to an unbound field (used when no full classpath is available */ -public class CtUnboundVariableReferenceImpl - extends CtVariableReferenceImpl - implements CtUnboundVariableReference { +public class CtUnboundVariableReferenceImpl extends CtVariableReferenceImpl implements CtUnboundVariableReference { private static final long serialVersionUID = -932423216089690817L; @Override public void accept(CtVisitor visitor) { visitor.visitCtUnboundVariableReference(this); } + + @Override + public CtUnboundVariableReference clone() { + return (CtUnboundVariableReference) super.clone(); + } } diff --git a/src/main/java/spoon/support/reflect/reference/CtVariableReferenceImpl.java b/src/main/java/spoon/support/reflect/reference/CtVariableReferenceImpl.java index b028d556110..d047311d3d9 100644 --- a/src/main/java/spoon/support/reflect/reference/CtVariableReferenceImpl.java +++ b/src/main/java/spoon/support/reflect/reference/CtVariableReferenceImpl.java @@ -26,8 +26,7 @@ import java.util.Set; import java.util.TreeSet; -public abstract class CtVariableReferenceImpl extends CtReferenceImpl - implements CtVariableReference { +public abstract class CtVariableReferenceImpl extends CtReferenceImpl implements CtVariableReference { private static final long serialVersionUID = 1L; CtTypeReference type; @@ -79,4 +78,9 @@ public Set getModifiers() { public void replace(CtVariableReference reference) { super.replace(reference); } + + @Override + public CtVariableReference clone() { + return (CtVariableReference) super.clone(); + } } diff --git a/src/main/java/spoon/support/template/SubstitutionVisitor.java b/src/main/java/spoon/support/template/SubstitutionVisitor.java index cf8768a3c1d..0a0189aa748 100644 --- a/src/main/java/spoon/support/template/SubstitutionVisitor.java +++ b/src/main/java/spoon/support/template/SubstitutionVisitor.java @@ -107,7 +107,7 @@ public void scanCtExecutable(CtExecutable e) { if (value instanceof List) { List l = (List) value; for (Object p : l) { - CtParameter p2 = e.getFactory().Core().clone((CtParameter) p); + CtParameter p2 = ((CtParameter) p).clone(); p2.setParent(parameter.getParent()); parameter.getParent().getParameters().add(i++, p2); } @@ -205,7 +205,7 @@ public void visitCtClass(CtClass ctClass) { if (value instanceof List) { List l = (List) value; for (Object f : l) { - CtField f2 = ctClass.getFactory().Core().clone((CtField) f); + CtField f2 = ((CtField) f).clone(); f2.setParent(ctClass); ctClass.getFields().add(i++, f2); } @@ -226,7 +226,7 @@ public void visitCtForEach(CtForEach foreach) { CtBlock l = foreach.getFactory().Core().createBlock(); CtStatement body = foreach.getBody(); for (Object element : value) { - CtStatement b = foreach.getFactory().Core().clone(body); + CtStatement b = body.clone(); for (CtVariableAccess va : Query.getElements(b, new VariableAccessFilter>(foreach.getVariable().getReference()))) { va.replace((CtExpression) element); @@ -299,7 +299,7 @@ private void visitFieldAccess(CtFieldAccess fieldAccess) { toReplace.replace(factory.Code().createLiteral(value)); } } else { - factory.Core().clone(toReplace); + toReplace.clone(); } // do not visit if replaced throw new SkipException(fieldAccess); @@ -330,7 +330,7 @@ public void visitCtInvocation(CtInvocation invocation) { .getValue(template, fa.getVariable().getSimpleName(), Parameters.getIndex(fa)); CtCodeElement r = null; if (tparamValue != null) { - r = (CtCodeElement) factory.Core().clone(tparamValue); + r = ((CtCodeElement) tparamValue).clone(); // substitute in the replacement (for fixing type // references // and @@ -461,7 +461,7 @@ public void visitCtTypeReference(CtTypeReference reference) { if (o instanceof Class) { t = factory.Type().createReference(((Class) o)); } else if (o instanceof CtTypeReference) { - t = factory.Core().clone((CtTypeReference) o); + t = ((CtTypeReference) o).clone(); reference.setActualTypeArguments(t.getActualTypeArguments()); } else { throw new RuntimeException( diff --git a/src/main/java/spoon/template/StatementTemplate.java b/src/main/java/spoon/template/StatementTemplate.java index 22b5929cb39..1705183c983 100644 --- a/src/main/java/spoon/template/StatementTemplate.java +++ b/src/main/java/spoon/template/StatementTemplate.java @@ -58,9 +58,8 @@ public CtStatement apply(CtType targetType) { c = factory.Class().get(this.getClass()); } // we substitute the first statement of method statement - CtStatement result = factory.Core().clone(c.getMethod("statement").getBody().getStatements().get(0)); - new SubstitutionVisitor(factory, targetType, this) - .scan(result); + CtStatement result = c.getMethod("statement").getBody().getStatements().get(0).clone(); + new SubstitutionVisitor(factory, targetType, this).scan(result); return result; } diff --git a/src/main/java/spoon/template/Substitution.java b/src/main/java/spoon/template/Substitution.java index 16aa4328ed7..b1dc23f1625 100644 --- a/src/main/java/spoon/template/Substitution.java +++ b/src/main/java/spoon/template/Substitution.java @@ -16,8 +16,6 @@ */ package spoon.template; -import java.util.List; - import spoon.reflect.code.CtBlock; import spoon.reflect.code.CtExpression; import spoon.reflect.code.CtStatement; @@ -37,6 +35,8 @@ import spoon.support.template.Parameters; import spoon.support.template.SubstitutionVisitor; +import java.util.List; + /** * This class defines the substitution API for templates (see {@link Template}). */ @@ -433,7 +433,7 @@ public static E substitute(CtType targetType, Template< if (targetType == null) { throw new RuntimeException("target is null in substitution"); } - E result = targetType.getFactory().Core().clone(code); + E result = (E) code.clone(); new SubstitutionVisitor(targetType.getFactory(), targetType, template).scan(result); return result; } @@ -479,7 +479,7 @@ public static E substitute(CtType targetType, Template< * substituted */ public static > T substitute(Template template, T templateType) { - T result = templateType.getFactory().Core().clone(templateType); + T result = (T) templateType.clone(); result.setPositions(null); // result.setParent(templateType.getParent()); new SubstitutionVisitor(templateType.getFactory(), result, template).scan(result); diff --git a/src/main/java/spoon/template/TypedBlockTemplateParameter.java b/src/main/java/spoon/template/TypedBlockTemplateParameter.java index 7ba7dc85904..315a436b5db 100644 --- a/src/main/java/spoon/template/TypedBlockTemplateParameter.java +++ b/src/main/java/spoon/template/TypedBlockTemplateParameter.java @@ -55,7 +55,7 @@ public CtBlock getSubstitution(CtType targetType) { if (this instanceof Template) { return Substitution.substitute(targetType, (Template) this, m.getBody()); } - return targetType.getFactory().Core().clone(m.getBody()); + return m.getBody().clone(); } public R S() { diff --git a/src/main/java/spoon/template/TypedStatementListTemplateParameter.java b/src/main/java/spoon/template/TypedStatementListTemplateParameter.java index c99f1c7ccc1..13938e03db3 100644 --- a/src/main/java/spoon/template/TypedStatementListTemplateParameter.java +++ b/src/main/java/spoon/template/TypedStatementListTemplateParameter.java @@ -51,7 +51,7 @@ public CtStatementList getSubstitution(CtType targetType) { if (this instanceof Template) { b = Substitution.substitute(targetType, (Template) this, c.getMethod("statements").getBody()); } else { - b = targetType.getFactory().Core().clone(c.getMethod("statements").getBody()); + b = c.getMethod("statements").getBody().clone(); } l.setStatements(b.getStatements()); return l; diff --git a/src/test/java/spoon/reflect/ast/CloneTest.java b/src/test/java/spoon/reflect/ast/CloneTest.java new file mode 100644 index 00000000000..7018e1d257b --- /dev/null +++ b/src/test/java/spoon/reflect/ast/CloneTest.java @@ -0,0 +1,73 @@ +package spoon.reflect.ast; + +import org.junit.Test; +import spoon.Launcher; +import spoon.reflect.declaration.CtClass; +import spoon.reflect.declaration.CtInterface; +import spoon.reflect.declaration.CtMethod; +import spoon.reflect.visitor.CtScanner; +import spoon.reflect.visitor.Query; +import spoon.reflect.visitor.filter.TypeFilter; + +import java.util.stream.Collectors; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +public class CloneTest { + @Test + public void testCloneMethodsDeclaredInAST() throws Exception { + final Launcher launcher = new Launcher(); + launcher.getEnvironment().setNoClasspath(true); + launcher.setSourceOutputDirectory("./target/trash"); + // 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"); + // implementations. + launcher.addInputResource("./src/main/java/spoon/support/reflect/code"); + launcher.addInputResource("./src/main/java/spoon/support/reflect/declaration"); + launcher.addInputResource("./src/main/java/spoon/support/reflect/reference"); + launcher.run(); + + new CtScanner() { + @Override + public void visitCtClass(CtClass ctClass) { + if (!ctClass.getSimpleName().startsWith("Ct")) { + return; + } + final CtMethod clone = ctClass.getMethod("clone"); + assertNotNull(ctClass.getQualifiedName() + " hasn't clone method.", clone); + assertTrue(ctClass.getQualifiedName() + " hasn't Override annotation on clone method.", clone.getAnnotations().stream().map(ctAnnotation -> ctAnnotation.getActualAnnotation().annotationType()).collect(Collectors.toList()).contains(Override.class)); + } + + @Override + public void visitCtInterface(CtInterface intrface) { + if (!intrface.getSimpleName().startsWith("Ct")) { + return; + } + final CtMethod clone = intrface.getMethod("clone"); + if (hasConcreteImpl(intrface)) { + assertNotNull(intrface.getQualifiedName() + " hasn't clone method.", clone); + if (!isRootDeclaration(intrface)) { + assertTrue(intrface.getQualifiedName() + " hasn't Override annotation on clone method.", + clone.getAnnotations().stream().map(ctAnnotation -> ctAnnotation.getActualAnnotation().annotationType()).collect(Collectors.toList()).contains(Override.class)); + } + } + } + + private boolean hasConcreteImpl(CtInterface intrface) { + return Query.getElements(intrface.getFactory(), new TypeFilter>(CtClass.class) { + @Override + public boolean matches(CtClass element) { + return super.matches(element) && element.getSuperInterfaces().contains(intrface.getReference()); + } + }).size() > 0; + } + + private boolean isRootDeclaration(CtInterface intrface) { + return "CtElement".equals(intrface.getSimpleName()); + } + }.scan(launcher.getModel().getRootPackage()); + } +} diff --git a/src/test/java/spoon/test/api/AwesomeProcessor.java b/src/test/java/spoon/test/api/AwesomeProcessor.java index 2119fa580f6..5bc05ab884b 100644 --- a/src/test/java/spoon/test/api/AwesomeProcessor.java +++ b/src/test/java/spoon/test/api/AwesomeProcessor.java @@ -24,7 +24,7 @@ public void process(CtClass element) { getFactory().Code() .createCodeSnippetStatement("System.out.println(\"Prepare mojito\")")); prepareMojito.setBody(block); - final CtMethod makeMojito = getFactory().Core().clone(prepareMojito); + final CtMethod makeMojito = prepareMojito.clone(); makeMojito.setSimpleName("makeMojito"); final CtBlock blockMake = getFactory().Core().createBlock(); blockMake.addStatement( diff --git a/src/test/java/spoon/test/factory/FactoryTest.java b/src/test/java/spoon/test/factory/FactoryTest.java index 75f3359b312..edde2ea14e7 100644 --- a/src/test/java/spoon/test/factory/FactoryTest.java +++ b/src/test/java/spoon/test/factory/FactoryTest.java @@ -1,14 +1,6 @@ package spoon.test.factory; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; -import static spoon.testing.utils.ModelUtils.build; -import static spoon.testing.utils.ModelUtils.buildClass; - import org.junit.Test; - import spoon.Launcher; import spoon.SpoonAPI; import spoon.processing.AbstractProcessor; @@ -30,6 +22,13 @@ import spoon.support.reflect.declaration.CtMethodImpl; import spoon.test.factory.testclasses.Foo; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import static spoon.testing.utils.ModelUtils.build; +import static spoon.testing.utils.ModelUtils.buildClass; + public class FactoryTest { @Test @@ -38,7 +37,7 @@ public void testClone() throws Exception { CtMethod m = type.getMethodsByName("method3").get(0); int i = m.getBody().getStatements().size(); - m = m.getFactory().Core().clone(m); + m = m.clone(); assertEquals(i, m.getBody().getStatements().size()); // cloned elements must not have an initialized parent @@ -95,21 +94,21 @@ public void testClassAccessCreatedFromFactories() throws Exception { assertEquals(1, ((CtNewArray) foo.getAnnotations().get(0).getElementValues().get("classes")).getElements().size()); assertEquals("spoon.test.factory.testclasses.Foo.class", ((CtNewArray) foo.getAnnotations().get(0).getElementValues().get("classes")).getElements().get(0).toString()); } - + @Test public void testCtModel() throws Exception { SpoonAPI spoon = new Launcher(); spoon.addInputResource("src/test/java/spoon/test/factory/testclasses"); spoon.buildModel(); - + CtModel model = spoon.getModel(); - + // contains Foo and Foo.@Bar assertEquals(1, model.getAllTypes().size()); - + // [, spoon, spoon.test, spoon.test.factory, spoon.test.factory.testclasses] assertEquals(5, model.getAllPackages().size()); - + // add to itself is fine model.getRootPackage().addPackage(model.getRootPackage()); assertEquals(1, model.getAllTypes().size()); @@ -123,8 +122,8 @@ public void testCtModel() throws Exception { assertEquals(1, model.getAllTypes().size()); assertEquals(5, model.getAllPackages().size()); - - CtPackage p = spoon.getFactory().Core().clone(model.getRootPackage().getElements(new NameFilter("spoon")).get(0)); + + CtPackage p = model.getRootPackage().getElements(new NameFilter("spoon")).get(0).clone(); // if we change the implem, merge is impossible CtField f = spoon.getFactory().Core().createField(); f.setSimpleName("foo"); @@ -146,21 +145,21 @@ public void testIncrementalModel() throws Exception { // Build model spoon.buildModel(); assertEquals(1, spoon.getModel().getAllTypes().size()); - + // Do something with that model.. CtModel model = spoon.getModel(); model.processWith(new AbstractProcessor() { @Override public void process(CtMethod element) { element.setDefaultMethod(false); - } + } }); - // Feed some new inputResources + // Feed some new inputResources SpoonAPI spoon2 = new Launcher(); spoon2.addInputResource("src/test/java/spoon/test/factory/testclasses2"); - - // Build models of newly added classes/packages + + // Build models of newly added classes/packages spoon2.buildModel(); assertEquals(1, spoon2.getModel().getAllTypes().size()); @@ -168,7 +167,7 @@ public void process(CtMethod element) { model.getRootPackage().addPackage(spoon2.getModel().getRootPackage()); // checking the results - assertEquals(6, model.getAllPackages().size()); + assertEquals(6, model.getAllPackages().size()); assertEquals(2, model.getAllTypes().size()); assertEquals(1, model.getRootPackage().getElements(new AbstractFilter() { @Override diff --git a/src/test/java/spoon/test/intercession/IntercessionTest.java b/src/test/java/spoon/test/intercession/IntercessionTest.java index ea2ba58f7f7..bd81e65a281 100644 --- a/src/test/java/spoon/test/intercession/IntercessionTest.java +++ b/src/test/java/spoon/test/intercession/IntercessionTest.java @@ -1,17 +1,7 @@ package spoon.test.intercession; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; -import static spoon.testing.utils.ModelUtils.createFactory; - -import java.io.File; -import java.util.List; - import org.junit.Assert; import org.junit.Test; - import spoon.Launcher; import spoon.reflect.code.CtBlock; import spoon.reflect.code.CtCodeSnippetStatement; @@ -24,12 +14,19 @@ import spoon.reflect.declaration.CtConstructor; import spoon.reflect.declaration.CtMethod; import spoon.reflect.factory.Factory; -import spoon.reflect.reference.CtIntersectionTypeReference; import spoon.reflect.reference.CtTypeParameterReference; -import spoon.reflect.reference.CtTypeReference; import spoon.reflect.visitor.Query; import spoon.reflect.visitor.filter.AbstractFilter; +import java.io.File; +import java.util.List; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import static spoon.testing.utils.ModelUtils.createFactory; + public class IntercessionTest { Factory factory = createFactory(); @Test @@ -60,7 +57,7 @@ public void testInsertEnd() { + " String foo=\"toto\";" + "}" + "};") .compile(); CtMethod foo = (CtMethod) clazz.getMethods().toArray()[0]; - CtMethod fooClone = factory.Core().clone(foo); + CtMethod fooClone = foo.clone(); Assert.assertEquals(foo, fooClone); CtBlock body = foo.getBody(); assertEquals(2, body.getStatements().size()); @@ -83,7 +80,7 @@ public void testEqualConstructor() { "" + "class X { public X() {} };") .compile(); CtConstructor foo = (CtConstructor) clazz.getConstructors().toArray()[0]; - CtConstructor fooClone = factory.Core().clone(foo); + CtConstructor fooClone = foo.clone(); Assert.assertEquals(foo, fooClone); CtBlock body = foo.getBody(); diff --git a/src/test/java/spoon/test/intercession/insertBefore/InsertMethodsTest.java b/src/test/java/spoon/test/intercession/insertBefore/InsertMethodsTest.java index 65a30f79a8d..69452398255 100644 --- a/src/test/java/spoon/test/intercession/insertBefore/InsertMethodsTest.java +++ b/src/test/java/spoon/test/intercession/insertBefore/InsertMethodsTest.java @@ -167,7 +167,7 @@ public void testInsertBeforeSwitchCase() throws Exception { assertEquals(snippet, ctCase1.getStatements().get(0)); assertEquals(ctCase1, snippet.getParent()); - CtCodeSnippetStatement snippet2 = factory.Core().clone(snippet); + CtCodeSnippetStatement snippet2 = snippet.clone(); ctCase2.getStatements().get(1).insertBefore(snippet2); assertEquals(snippet2, ctCase2.getStatements().get(1)); assertEquals(ctCase2, snippet2.getParent()); @@ -203,7 +203,7 @@ public void testInsertAfterSwitchCase() throws Exception { assertEquals(snippet, ctCase1.getStatements().get(1)); assertEquals(ctCase1, snippet.getParent()); - CtCodeSnippetStatement snippet2 = factory.Core().clone(snippet); + CtCodeSnippetStatement snippet2 = snippet.clone(); ctCase2.getStatements().get(1).insertAfter(snippet2); assertEquals(snippet2, ctCase2.getStatements().get(2)); assertEquals(ctCase2, snippet2.getParent()); diff --git a/src/test/java/spoon/test/parent/ParentContractTest.java b/src/test/java/spoon/test/parent/ParentContractTest.java index 5446864054a..a845070a808 100644 --- a/src/test/java/spoon/test/parent/ParentContractTest.java +++ b/src/test/java/spoon/test/parent/ParentContractTest.java @@ -129,7 +129,7 @@ public void testContract() throws Throwable { CtElement mockedArgument = (CtElement) mock(setter.getParameters()[0].getType(), Mockito.withSettings().extraInterfaces(Comparable.class)); try { // we create a fresh object - CtElement receiver = (CtElement)factory.Core().clone(o); + CtElement receiver = ((CtElement) o).clone(); // we invoke the setter setter.invoke(receiver, new Object[]{mockedArgument}); // we check that setParent has been called diff --git a/src/test/java/spoon/test/signature/SignatureTest.java b/src/test/java/spoon/test/signature/SignatureTest.java index 8a5af1dbbaa..08b643e0845 100644 --- a/src/test/java/spoon/test/signature/SignatureTest.java +++ b/src/test/java/spoon/test/signature/SignatureTest.java @@ -63,7 +63,7 @@ public void testNullSignature() throws Exception { // since the signature is null, CtElement.equals throws an exception and // should not - CtLiteral lit2 = (CtLiteral) factory.Core().clone(lit); + CtLiteral lit2 = ((CtLiteral) lit).clone(); HashSet> s = new HashSet>(); s.add(lit); s.add(lit2); @@ -170,7 +170,7 @@ public void testMethodInvocationSignatureStaticFieldsVariables(){ assertEquals(signaturestc1, signaturestc2); assertFalse(stc1.equals(stc2)); } - + @Test public void testMethodInvocationSignatureWithVariableAccess() throws Exception{ @@ -305,7 +305,7 @@ public boolean matches(CtExecutableReference reference) { assertNotEquals("#addField(null, null)", reference.getSignature()); } } - + @Test public void testBugSignature() throws Exception { // contract: two methods with same name and return type yet different argument types @@ -327,6 +327,6 @@ public void testBugSignature() throws Exception { "void addInputSource(spoon.compiler.SpoonResource)", method2.getSignature()); assertNotEquals(method, method2); - + } }