From 47966559ee47bdc41d7e6c660630ecf86f4dec48 Mon Sep 17 00:00:00 2001 From: GerardPaligot Date: Wed, 6 Jul 2016 19:30:11 +0200 Subject: [PATCH 01/40] feat: Adds actions to stack. --- src/main/java/spoon/compiler/Environment.java | 18 +++++++++ src/main/java/spoon/diff/Action.java | 40 +++++++++++++++++++ src/main/java/spoon/diff/AddAction.java | 30 ++++++++++++++ src/main/java/spoon/diff/DeleteAction.java | 31 ++++++++++++++ src/main/java/spoon/diff/DeleteAllAction.java | 33 +++++++++++++++ src/main/java/spoon/diff/UpdateAction.java | 38 ++++++++++++++++++ .../spoon/diff/context/CollectionContext.java | 27 +++++++++++++ src/main/java/spoon/diff/context/Context.java | 20 ++++++++++ .../java/spoon/diff/context/ListContext.java | 33 +++++++++++++++ .../java/spoon/diff/context/MapContext.java | 20 ++++++++++ .../spoon/diff/context/ObjectContext.java | 37 +++++++++++++++++ .../java/spoon/diff/context/SetContext.java | 25 ++++++++++++ .../spoon/support/StandardEnvironment.java | 18 +++++++++ .../reflect/declaration/CtClassImpl.java | 37 ++++++++++++++++- 14 files changed, 405 insertions(+), 2 deletions(-) create mode 100644 src/main/java/spoon/diff/Action.java create mode 100644 src/main/java/spoon/diff/AddAction.java create mode 100644 src/main/java/spoon/diff/DeleteAction.java create mode 100644 src/main/java/spoon/diff/DeleteAllAction.java create mode 100644 src/main/java/spoon/diff/UpdateAction.java create mode 100644 src/main/java/spoon/diff/context/CollectionContext.java create mode 100644 src/main/java/spoon/diff/context/Context.java create mode 100644 src/main/java/spoon/diff/context/ListContext.java create mode 100644 src/main/java/spoon/diff/context/MapContext.java create mode 100644 src/main/java/spoon/diff/context/ObjectContext.java create mode 100644 src/main/java/spoon/diff/context/SetContext.java diff --git a/src/main/java/spoon/compiler/Environment.java b/src/main/java/spoon/compiler/Environment.java index e89a68b975a..ecff90848c9 100644 --- a/src/main/java/spoon/compiler/Environment.java +++ b/src/main/java/spoon/compiler/Environment.java @@ -17,6 +17,8 @@ package spoon.compiler; import org.apache.log4j.Level; +import spoon.diff.Action; +import spoon.diff.AddAction; import spoon.processing.FileGenerator; import spoon.processing.ProblemFixer; import spoon.processing.ProcessingManager; @@ -330,4 +332,20 @@ void report(Processor processor, Level level, /** Set the directory where binary .class files are created */ String getBinaryOutputDirectory(); + + /** + * Checks if we want to build the stack changes on the AST. + */ + boolean buildStackChanges(); + + /** + * If you set at true this method, you'll stack any changes done on your AST but you can't modify + * list or set returned by the AST. + */ + void setBuildStackChanges(boolean buildStackChanges); + + /** + * Push an action on the stack changes. + */ + void pushToStack(Action action); } diff --git a/src/main/java/spoon/diff/Action.java b/src/main/java/spoon/diff/Action.java new file mode 100644 index 00000000000..7366a2bfe5e --- /dev/null +++ b/src/main/java/spoon/diff/Action.java @@ -0,0 +1,40 @@ +/** + * Copyright (C) 2006-2017 INRIA and contributors + * Spoon - http://spoon.gforge.inria.fr/ + * + * This software is governed by the CeCILL-C License under French law and + * abiding by the rules of distribution of free software. You can use, modify + * and/or redistribute the software under the terms of the CeCILL-C license as + * circulated by CEA, CNRS and INRIA at http://www.cecill.info. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the CeCILL-C License for more details. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL-C license and that you accept its terms. + */ +package spoon.diff; + +import spoon.diff.context.Context; +import spoon.reflect.declaration.CtElement; + +public abstract class Action { + private final Context context; + private final CtElement newElement; + + Action(Context context, CtElement newElement) { + this.context = context; + this.newElement = newElement; + } + + public abstract void rollback(); + + public Context getContext() { + return context; + } + + public CtElement getNewElement() { + return newElement; + } +} diff --git a/src/main/java/spoon/diff/AddAction.java b/src/main/java/spoon/diff/AddAction.java new file mode 100644 index 00000000000..f66b6e41441 --- /dev/null +++ b/src/main/java/spoon/diff/AddAction.java @@ -0,0 +1,30 @@ +/** + * Copyright (C) 2006-2017 INRIA and contributors + * Spoon - http://spoon.gforge.inria.fr/ + * + * This software is governed by the CeCILL-C License under French law and + * abiding by the rules of distribution of free software. You can use, modify + * and/or redistribute the software under the terms of the CeCILL-C license as + * circulated by CEA, CNRS and INRIA at http://www.cecill.info. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the CeCILL-C License for more details. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL-C license and that you accept its terms. + */ +package spoon.diff; + +import spoon.diff.context.Context; +import spoon.reflect.declaration.CtElement; + +public class AddAction extends Action { + public AddAction(Context context, CtElement newElement) { + super(context, newElement); + } + + @Override + public void rollback() { + } +} diff --git a/src/main/java/spoon/diff/DeleteAction.java b/src/main/java/spoon/diff/DeleteAction.java new file mode 100644 index 00000000000..05755077060 --- /dev/null +++ b/src/main/java/spoon/diff/DeleteAction.java @@ -0,0 +1,31 @@ +/** + * Copyright (C) 2006-2017 INRIA and contributors + * Spoon - http://spoon.gforge.inria.fr/ + * + * This software is governed by the CeCILL-C License under French law and + * abiding by the rules of distribution of free software. You can use, modify + * and/or redistribute the software under the terms of the CeCILL-C license as + * circulated by CEA, CNRS and INRIA at http://www.cecill.info. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the CeCILL-C License for more details. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL-C license and that you accept its terms. + */ +package spoon.diff; + +import spoon.diff.context.Context; +import spoon.reflect.declaration.CtElement; + +public class DeleteAction extends Action { + public DeleteAction(Context context, CtElement oldElement) { + super(context, oldElement); + } + + @Override + public void rollback() { + + } +} diff --git a/src/main/java/spoon/diff/DeleteAllAction.java b/src/main/java/spoon/diff/DeleteAllAction.java new file mode 100644 index 00000000000..cdebfdeea42 --- /dev/null +++ b/src/main/java/spoon/diff/DeleteAllAction.java @@ -0,0 +1,33 @@ +/** + * Copyright (C) 2006-2017 INRIA and contributors + * Spoon - http://spoon.gforge.inria.fr/ + * + * This software is governed by the CeCILL-C License under French law and + * abiding by the rules of distribution of free software. You can use, modify + * and/or redistribute the software under the terms of the CeCILL-C license as + * circulated by CEA, CNRS and INRIA at http://www.cecill.info. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the CeCILL-C License for more details. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL-C license and that you accept its terms. + */ +package spoon.diff; + +import spoon.diff.context.CollectionContext; +import spoon.diff.context.Context; +import spoon.reflect.declaration.CtElement; + +import java.util.Collection; + +public class DeleteAllAction extends DeleteAction { + public DeleteAllAction(Context context, CtElement oldElement) { + super(context, oldElement); + } + + public DeleteAllAction(CollectionContext context, Collection copy) { + super(context, null); + } +} diff --git a/src/main/java/spoon/diff/UpdateAction.java b/src/main/java/spoon/diff/UpdateAction.java new file mode 100644 index 00000000000..e469a21fa72 --- /dev/null +++ b/src/main/java/spoon/diff/UpdateAction.java @@ -0,0 +1,38 @@ +/** + * Copyright (C) 2006-2017 INRIA and contributors + * Spoon - http://spoon.gforge.inria.fr/ + * + * This software is governed by the CeCILL-C License under French law and + * abiding by the rules of distribution of free software. You can use, modify + * and/or redistribute the software under the terms of the CeCILL-C license as + * circulated by CEA, CNRS and INRIA at http://www.cecill.info. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the CeCILL-C License for more details. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL-C license and that you accept its terms. + */ +package spoon.diff; + +import spoon.diff.context.Context; +import spoon.reflect.declaration.CtElement; + +public class UpdateAction extends Action { + private final CtElement oldElement; + + public UpdateAction(Context context, CtElement newElement, CtElement oldElement) { + super(context, newElement); + this.oldElement = oldElement; + } + + @Override + public void rollback() { + + } + + public CtElement getOldElement() { + return oldElement; + } +} diff --git a/src/main/java/spoon/diff/context/CollectionContext.java b/src/main/java/spoon/diff/context/CollectionContext.java new file mode 100644 index 00000000000..63a2d60c241 --- /dev/null +++ b/src/main/java/spoon/diff/context/CollectionContext.java @@ -0,0 +1,27 @@ +/** + * Copyright (C) 2006-2017 INRIA and contributors + * Spoon - http://spoon.gforge.inria.fr/ + * + * This software is governed by the CeCILL-C License under French law and + * abiding by the rules of distribution of free software. You can use, modify + * and/or redistribute the software under the terms of the CeCILL-C license as + * circulated by CEA, CNRS and INRIA at http://www.cecill.info. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the CeCILL-C License for more details. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL-C license and that you accept its terms. + */ +package spoon.diff.context; + +import java.util.Collection; + +public class CollectionContext> extends Context { + protected final T original; + + public CollectionContext(T original) { + this.original = original; + } +} diff --git a/src/main/java/spoon/diff/context/Context.java b/src/main/java/spoon/diff/context/Context.java new file mode 100644 index 00000000000..fd77a537953 --- /dev/null +++ b/src/main/java/spoon/diff/context/Context.java @@ -0,0 +1,20 @@ +/** + * Copyright (C) 2006-2017 INRIA and contributors + * Spoon - http://spoon.gforge.inria.fr/ + * + * This software is governed by the CeCILL-C License under French law and + * abiding by the rules of distribution of free software. You can use, modify + * and/or redistribute the software under the terms of the CeCILL-C license as + * circulated by CEA, CNRS and INRIA at http://www.cecill.info. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the CeCILL-C License for more details. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL-C license and that you accept its terms. + */ +package spoon.diff.context; + +public abstract class Context { +} diff --git a/src/main/java/spoon/diff/context/ListContext.java b/src/main/java/spoon/diff/context/ListContext.java new file mode 100644 index 00000000000..e275e7e83c4 --- /dev/null +++ b/src/main/java/spoon/diff/context/ListContext.java @@ -0,0 +1,33 @@ +/** + * Copyright (C) 2006-2017 INRIA and contributors + * Spoon - http://spoon.gforge.inria.fr/ + * + * This software is governed by the CeCILL-C License under French law and + * abiding by the rules of distribution of free software. You can use, modify + * and/or redistribute the software under the terms of the CeCILL-C license as + * circulated by CEA, CNRS and INRIA at http://www.cecill.info. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the CeCILL-C License for more details. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL-C license and that you accept its terms. + */ +package spoon.diff.context; + +import java.util.List; + +public class ListContext extends CollectionContext> { + private final int position; + + public ListContext(List original) { + super(original); + this.position = -1; + } + + public ListContext(List original, int position) { + super(original); + this.position = position; + } +} diff --git a/src/main/java/spoon/diff/context/MapContext.java b/src/main/java/spoon/diff/context/MapContext.java new file mode 100644 index 00000000000..9392378de1e --- /dev/null +++ b/src/main/java/spoon/diff/context/MapContext.java @@ -0,0 +1,20 @@ +/** + * Copyright (C) 2006-2017 INRIA and contributors + * Spoon - http://spoon.gforge.inria.fr/ + * + * This software is governed by the CeCILL-C License under French law and + * abiding by the rules of distribution of free software. You can use, modify + * and/or redistribute the software under the terms of the CeCILL-C license as + * circulated by CEA, CNRS and INRIA at http://www.cecill.info. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the CeCILL-C License for more details. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL-C license and that you accept its terms. + */ +package spoon.diff.context; + +public class MapContext extends Context { +} diff --git a/src/main/java/spoon/diff/context/ObjectContext.java b/src/main/java/spoon/diff/context/ObjectContext.java new file mode 100644 index 00000000000..c131bf4cbf8 --- /dev/null +++ b/src/main/java/spoon/diff/context/ObjectContext.java @@ -0,0 +1,37 @@ +/** + * Copyright (C) 2006-2017 INRIA and contributors + * Spoon - http://spoon.gforge.inria.fr/ + * + * This software is governed by the CeCILL-C License under French law and + * abiding by the rules of distribution of free software. You can use, modify + * and/or redistribute the software under the terms of the CeCILL-C license as + * circulated by CEA, CNRS and INRIA at http://www.cecill.info. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the CeCILL-C License for more details. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL-C license and that you accept its terms. + */ +package spoon.diff.context; + +import spoon.reflect.declaration.CtElement; + +public class ObjectContext extends Context { + private final CtElement ctElement; + private final String fieldName; + + public ObjectContext(CtElement ctElement, String fieldName) { + this.ctElement = ctElement; + this.fieldName = fieldName; + } + +/* + try { + final Field field = ctElement.getClass().getField(fieldName); + } catch (NoSuchFieldException e) { + throw new IllegalArgumentException("Can't find the field named by " + fieldName, e); + } +*/ +} diff --git a/src/main/java/spoon/diff/context/SetContext.java b/src/main/java/spoon/diff/context/SetContext.java new file mode 100644 index 00000000000..0d75cda3aef --- /dev/null +++ b/src/main/java/spoon/diff/context/SetContext.java @@ -0,0 +1,25 @@ +/** + * Copyright (C) 2006-2017 INRIA and contributors + * Spoon - http://spoon.gforge.inria.fr/ + * + * This software is governed by the CeCILL-C License under French law and + * abiding by the rules of distribution of free software. You can use, modify + * and/or redistribute the software under the terms of the CeCILL-C license as + * circulated by CEA, CNRS and INRIA at http://www.cecill.info. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the CeCILL-C License for more details. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL-C license and that you accept its terms. + */ +package spoon.diff.context; + +import java.util.Set; + +public class SetContext extends CollectionContext> { + public SetContext(Set original) { + super(original); + } +} diff --git a/src/main/java/spoon/support/StandardEnvironment.java b/src/main/java/spoon/support/StandardEnvironment.java index f9b5bbad084..056005c1445 100644 --- a/src/main/java/spoon/support/StandardEnvironment.java +++ b/src/main/java/spoon/support/StandardEnvironment.java @@ -24,6 +24,7 @@ import spoon.compiler.InvalidClassPathException; import spoon.compiler.SpoonFile; import spoon.compiler.SpoonFolder; +import spoon.diff.Action; import spoon.processing.FileGenerator; import spoon.processing.ProblemFixer; import spoon.processing.ProcessingManager; @@ -85,6 +86,8 @@ public class StandardEnvironment implements Serializable, Environment { private boolean skipSelfChecks; + private boolean buildStackChanges; + /** * Creates a new environment with a null default file * generator. @@ -149,6 +152,21 @@ public void setSelfChecks(boolean skip) { skipSelfChecks = skip; } + @Override + public boolean buildStackChanges() { + return buildStackChanges; + } + + @Override + public void setBuildStackChanges(boolean buildStackChanges) { + this.buildStackChanges = buildStackChanges; + } + + @Override + public void pushToStack(Action action) { + + } + private Level toLevel(String level) { if (level == null || level.isEmpty()) { throw new SpoonException("Wrong level given at Spoon."); diff --git a/src/main/java/spoon/support/reflect/declaration/CtClassImpl.java b/src/main/java/spoon/support/reflect/declaration/CtClassImpl.java index f850c153488..97f71a9e7f2 100644 --- a/src/main/java/spoon/support/reflect/declaration/CtClassImpl.java +++ b/src/main/java/spoon/support/reflect/declaration/CtClassImpl.java @@ -18,6 +18,13 @@ import spoon.SpoonException; import spoon.SpoonModelBuilder.InputType; +import spoon.diff.AddAction; +import spoon.diff.DeleteAction; +import spoon.diff.DeleteAllAction; +import spoon.diff.UpdateAction; +import spoon.diff.context.ListContext; +import spoon.diff.context.ObjectContext; +import spoon.diff.context.SetContext; import spoon.reflect.code.CtCodeElement; import spoon.reflect.code.CtStatement; import spoon.reflect.code.CtStatementList; @@ -46,6 +53,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; +import java.util.HashSet; import java.util.List; import java.util.Set; @@ -109,11 +117,23 @@ public Set> getConstructors() { @Override public > C addAnonymousExecutable(CtAnonymousExecutable e) { + if (e == null) { + return (C) this; + } + e.setParent(this); + if (getFactory().getEnvironment().buildStackChanges()) { + List anonymousExecutables = getAnonymousExecutables(); + getFactory().getEnvironment().pushToStack(new AddAction(new ListContext(anonymousExecutables, anonymousExecutables.size()), e)); + } return addTypeMember(e); } @Override public boolean removeAnonymousExecutable(CtAnonymousExecutable e) { + if (getFactory().getEnvironment().buildStackChanges()) { + List anonymousExecutables = getAnonymousExecutables(); + getFactory().getEnvironment().pushToStack(new DeleteAction(new ListContext(anonymousExecutables, anonymousExecutables.indexOf(e)), e)); + } return removeTypeMember(e); } @@ -124,6 +144,9 @@ public CtTypeReference getSuperclass() { @Override public > C setAnonymousExecutables(List anonymousExecutables) { + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new DeleteAllAction(new ListContext(typeMembers), new ArrayList<>(getAnonymousExecutables()))); + } if (anonymousExecutables == null || anonymousExecutables.isEmpty()) { this.typeMembers.removeAll(getAnonymousExecutables()); return (C) this; @@ -137,11 +160,15 @@ public > C setAnonymousExecutables(List> C setConstructors(Set> constructors) { + Set> oldConstructor = getConstructors(); + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new DeleteAllAction(new ListContext(typeMembers), new HashSet<>(oldConstructor))); + } if (constructors == null || constructors.isEmpty()) { - this.typeMembers.removeAll(getConstructors()); + this.typeMembers.removeAll(oldConstructor); return (C) this; } - typeMembers.removeAll(getConstructors()); + typeMembers.removeAll(oldConstructor); for (CtConstructor constructor : constructors) { addConstructor(constructor); } @@ -150,6 +177,9 @@ public > C setConstructors(Set> constructo @Override public > C addConstructor(CtConstructor constructor) { + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new AddAction(new ListContext(typeMembers), constructor)); + } return addTypeMember(constructor); } @@ -163,6 +193,9 @@ public > C setSuperclass(CtTypeReference superClass) { if (superClass != null) { superClass.setParent(this); } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "superClass"), superClass, this.superClass)); + } this.superClass = superClass; return (C) this; } From 7755be1fb99f09ec056912b56e0f5527f93bdff8 Mon Sep 17 00:00:00 2001 From: GerardPaligot Date: Sat, 9 Jul 2016 00:04:50 +0200 Subject: [PATCH 02/40] feat: Push to stack in all setters. --- src/main/java/spoon/compiler/Environment.java | 5 +- src/main/java/spoon/diff/Action.java | 12 + src/main/java/spoon/diff/AddAction.java | 4 + src/main/java/spoon/diff/DeleteAction.java | 4 + src/main/java/spoon/diff/DeleteAllAction.java | 21 +- src/main/java/spoon/diff/UpdateAction.java | 12 + .../spoon/diff/context/CollectionContext.java | 5 +- src/main/java/spoon/diff/context/Context.java | 11 + .../java/spoon/diff/context/ListContext.java | 10 +- .../java/spoon/diff/context/MapContext.java | 28 +- .../spoon/diff/context/ObjectContext.java | 3 +- .../java/spoon/diff/context/SetContext.java | 6 +- .../generating/CloneVisitorGenerator.java | 8 +- .../generating/CtBiScannerGenerator.java | 4 +- .../reflect/code/CtAbstractInvocation.java | 9 +- .../spoon/reflect/declaration/CtPackage.java | 2 +- .../spoon/support/DefaultCoreFactory.java | 2 +- .../spoon/support/StandardEnvironment.java | 9 + .../reflect/code/CtArrayAccessImpl.java | 7 +- .../support/reflect/code/CtAssertImpl.java | 10 +- .../reflect/code/CtAssignmentImpl.java | 24 +- .../reflect/code/CtBinaryOperatorImpl.java | 13 +- .../support/reflect/code/CtBlockImpl.java | 21 +- .../support/reflect/code/CtBreakImpl.java | 7 +- .../support/reflect/code/CtCaseImpl.java | 23 +- .../support/reflect/code/CtCatchImpl.java | 14 +- .../reflect/code/CtCatchVariableImpl.java | 59 +++- .../code/CtCodeSnippetExpressionImpl.java | 7 +- .../code/CtCodeSnippetStatementImpl.java | 7 +- .../support/reflect/code/CtCommentImpl.java | 10 +- .../reflect/code/CtConditionalImpl.java | 13 +- .../reflect/code/CtConstructorCallImpl.java | 53 ++- .../support/reflect/code/CtContinueImpl.java | 5 + .../spoon/support/reflect/code/CtDoImpl.java | 7 +- .../CtExecutableReferenceExpressionImpl.java | 7 +- .../reflect/code/CtExpressionImpl.java | 18 +- .../reflect/code/CtFieldAccessImpl.java | 10 +- .../support/reflect/code/CtForEachImpl.java | 10 +- .../spoon/support/reflect/code/CtForImpl.java | 45 ++- .../spoon/support/reflect/code/CtIfImpl.java | 13 +- .../reflect/code/CtInvocationImpl.java | 50 ++- .../support/reflect/code/CtJavaDocImpl.java | 26 +- .../reflect/code/CtJavaDocTagImpl.java | 13 +- .../support/reflect/code/CtLambdaImpl.java | 54 ++- .../support/reflect/code/CtLiteralImpl.java | 9 +- .../reflect/code/CtLocalVariableImpl.java | 40 ++- .../support/reflect/code/CtLoopImpl.java | 11 +- .../support/reflect/code/CtNewArrayImpl.java | 42 ++- .../support/reflect/code/CtNewClassImpl.java | 7 +- .../code/CtOperatorAssignmentImpl.java | 7 +- .../support/reflect/code/CtReturnImpl.java | 7 +- .../support/reflect/code/CtStatementImpl.java | 7 +- .../reflect/code/CtStatementListImpl.java | 23 +- .../reflect/code/CtSuperAccessImpl.java | 7 +- .../support/reflect/code/CtSwitchImpl.java | 28 +- .../reflect/code/CtSynchronizedImpl.java | 10 +- .../code/CtTargetedExpressionImpl.java | 7 +- .../support/reflect/code/CtThrowImpl.java | 7 +- .../spoon/support/reflect/code/CtTryImpl.java | 34 +- .../reflect/code/CtTryWithResourceImpl.java | 23 +- .../reflect/code/CtTypeAccessImpl.java | 7 +- .../reflect/code/CtUnaryOperatorImpl.java | 13 +- .../reflect/code/CtVariableAccessImpl.java | 8 +- .../support/reflect/code/CtWhileImpl.java | 7 +- .../reflect/declaration/CtAnnotationImpl.java | 27 +- .../declaration/CtAnnotationMethodImpl.java | 7 +- .../CtAnonymousExecutableImpl.java | 27 +- .../reflect/declaration/CtClassImpl.java | 18 +- .../declaration/CtConstructorImpl.java | 47 ++- .../reflect/declaration/CtElementImpl.java | 61 +++- .../reflect/declaration/CtEnumImpl.java | 20 +- .../reflect/declaration/CtExecutableImpl.java | 48 ++- .../reflect/declaration/CtFieldImpl.java | 39 ++- .../reflect/declaration/CtMethodImpl.java | 54 ++- .../declaration/CtNamedElementImpl.java | 12 +- .../reflect/declaration/CtPackageImpl.java | 47 ++- .../reflect/declaration/CtParameterImpl.java | 37 ++- .../reflect/declaration/CtTypeImpl.java | 103 +++++- .../declaration/CtTypeParameterImpl.java | 7 +- .../reference/CtArrayTypeReferenceImpl.java | 5 + .../reference/CtExecutableReferenceImpl.java | 72 +++- .../reference/CtFieldReferenceImpl.java | 15 +- .../CtIntersectionTypeReferenceImpl.java | 29 +- .../reference/CtParameterReferenceImpl.java | 5 + .../reflect/reference/CtReferenceImpl.java | 9 + .../CtTypeParameterReferenceImpl.java | 9 + .../reference/CtTypeReferenceImpl.java | 32 +- .../reference/CtVariableReferenceImpl.java | 5 + .../reference/CtWildcardReferenceImpl.java | 2 + .../spoon/reflect/ast/AstCheckerTest.java | 309 ++++++++++++++++++ 90 files changed, 1841 insertions(+), 190 deletions(-) create mode 100644 src/test/java/spoon/reflect/ast/AstCheckerTest.java diff --git a/src/main/java/spoon/compiler/Environment.java b/src/main/java/spoon/compiler/Environment.java index ecff90848c9..72e24192104 100644 --- a/src/main/java/spoon/compiler/Environment.java +++ b/src/main/java/spoon/compiler/Environment.java @@ -18,7 +18,6 @@ import org.apache.log4j.Level; import spoon.diff.Action; -import spoon.diff.AddAction; import spoon.processing.FileGenerator; import spoon.processing.ProblemFixer; import spoon.processing.ProcessingManager; @@ -28,6 +27,8 @@ import spoon.reflect.declaration.CtMethod; import spoon.reflect.factory.Factory; +import java.util.Deque; + /** * This interface represents the environment in which Spoon is launched - * accessible through {@link spoon.reflect.factory.Factory#getEnvironment()}. Its @@ -348,4 +349,6 @@ void report(Processor processor, Level level, * Push an action on the stack changes. */ void pushToStack(Action action); + + Deque getActionChanges(); } diff --git a/src/main/java/spoon/diff/Action.java b/src/main/java/spoon/diff/Action.java index 7366a2bfe5e..5a69c465d6a 100644 --- a/src/main/java/spoon/diff/Action.java +++ b/src/main/java/spoon/diff/Action.java @@ -22,10 +22,18 @@ public abstract class Action { private final Context context; private final CtElement newElement; + private final Object newValue; Action(Context context, CtElement newElement) { this.context = context; this.newElement = newElement; + this.newValue = null; + } + + Action(Context context, Object newValue) { + this.context = context; + this.newValue = newValue; + this.newElement = null; } public abstract void rollback(); @@ -37,4 +45,8 @@ public Context getContext() { public CtElement getNewElement() { return newElement; } + + public Object getNewValue() { + return newValue; + } } diff --git a/src/main/java/spoon/diff/AddAction.java b/src/main/java/spoon/diff/AddAction.java index f66b6e41441..871fdc2d79e 100644 --- a/src/main/java/spoon/diff/AddAction.java +++ b/src/main/java/spoon/diff/AddAction.java @@ -24,6 +24,10 @@ public AddAction(Context context, CtElement newElement) { super(context, newElement); } + public AddAction(Context context, Object newValue) { + super(context, newValue); + } + @Override public void rollback() { } diff --git a/src/main/java/spoon/diff/DeleteAction.java b/src/main/java/spoon/diff/DeleteAction.java index 05755077060..945791816d5 100644 --- a/src/main/java/spoon/diff/DeleteAction.java +++ b/src/main/java/spoon/diff/DeleteAction.java @@ -24,6 +24,10 @@ public DeleteAction(Context context, CtElement oldElement) { super(context, oldElement); } + public DeleteAction(Context context, Object oldElement) { + super(context, oldElement); + } + @Override public void rollback() { diff --git a/src/main/java/spoon/diff/DeleteAllAction.java b/src/main/java/spoon/diff/DeleteAllAction.java index cdebfdeea42..6371740ad2a 100644 --- a/src/main/java/spoon/diff/DeleteAllAction.java +++ b/src/main/java/spoon/diff/DeleteAllAction.java @@ -18,16 +18,27 @@ import spoon.diff.context.CollectionContext; import spoon.diff.context.Context; -import spoon.reflect.declaration.CtElement; +import spoon.diff.context.MapContext; -import java.util.Collection; +public class DeleteAllAction extends DeleteAction { + private T oldContent; -public class DeleteAllAction extends DeleteAction { - public DeleteAllAction(Context context, CtElement oldElement) { + public DeleteAllAction(Context context, T oldElement) { super(context, oldElement); + oldContent = oldElement; } - public DeleteAllAction(CollectionContext context, Collection copy) { + public DeleteAllAction(CollectionContext context, T copy) { super(context, null); + oldContent = copy; + } + + public DeleteAllAction(MapContext context, T copy) { + super(context, null); + oldContent = copy; + } + + public T getOldContent() { + return oldContent; } } diff --git a/src/main/java/spoon/diff/UpdateAction.java b/src/main/java/spoon/diff/UpdateAction.java index e469a21fa72..fb856f26ab0 100644 --- a/src/main/java/spoon/diff/UpdateAction.java +++ b/src/main/java/spoon/diff/UpdateAction.java @@ -21,10 +21,18 @@ public class UpdateAction extends Action { private final CtElement oldElement; + private final Object oldValue; public UpdateAction(Context context, CtElement newElement, CtElement oldElement) { super(context, newElement); this.oldElement = oldElement; + this.oldValue = null; + } + + public UpdateAction(Context context, Object newValue, Object oldValue) { + super(context, newValue); + this.oldValue = oldValue; + this.oldElement = null; } @Override @@ -35,4 +43,8 @@ public void rollback() { public CtElement getOldElement() { return oldElement; } + + public Object getOldValue() { + return oldValue; + } } diff --git a/src/main/java/spoon/diff/context/CollectionContext.java b/src/main/java/spoon/diff/context/CollectionContext.java index 63a2d60c241..ac556a2f86b 100644 --- a/src/main/java/spoon/diff/context/CollectionContext.java +++ b/src/main/java/spoon/diff/context/CollectionContext.java @@ -16,12 +16,15 @@ */ package spoon.diff.context; +import spoon.reflect.declaration.CtElement; + import java.util.Collection; public class CollectionContext> extends Context { protected final T original; - public CollectionContext(T original) { + public CollectionContext(CtElement element, T original) { + super(element); this.original = original; } } diff --git a/src/main/java/spoon/diff/context/Context.java b/src/main/java/spoon/diff/context/Context.java index fd77a537953..e934b709a12 100644 --- a/src/main/java/spoon/diff/context/Context.java +++ b/src/main/java/spoon/diff/context/Context.java @@ -16,5 +16,16 @@ */ package spoon.diff.context; +import spoon.reflect.declaration.CtElement; + public abstract class Context { + private CtElement element; + + public Context(CtElement element) { + this.element = element; + } + + public CtElement getElement() { + return element; + } } diff --git a/src/main/java/spoon/diff/context/ListContext.java b/src/main/java/spoon/diff/context/ListContext.java index e275e7e83c4..3ae2f66f809 100644 --- a/src/main/java/spoon/diff/context/ListContext.java +++ b/src/main/java/spoon/diff/context/ListContext.java @@ -16,18 +16,20 @@ */ package spoon.diff.context; +import spoon.reflect.declaration.CtElement; + import java.util.List; public class ListContext extends CollectionContext> { private final int position; - public ListContext(List original) { - super(original); + public ListContext(CtElement element, List original) { + super(element, original); this.position = -1; } - public ListContext(List original, int position) { - super(original); + public ListContext(CtElement element, List original, int position) { + super(element, original); this.position = position; } } diff --git a/src/main/java/spoon/diff/context/MapContext.java b/src/main/java/spoon/diff/context/MapContext.java index 9392378de1e..e421c5908c1 100644 --- a/src/main/java/spoon/diff/context/MapContext.java +++ b/src/main/java/spoon/diff/context/MapContext.java @@ -16,5 +16,29 @@ */ package spoon.diff.context; -public class MapContext extends Context { -} +import spoon.reflect.declaration.CtElement; + +import java.util.Map; + +public class MapContext extends Context { + private final Map map; + private K key; + + public MapContext(CtElement element, Map map) { + super(element); + this.map = map; + } + + public MapContext(CtElement element, Map map, K key) { + this(element, map); + this.key = key; + } + + public K getKey() { + return key; + } + + public Map getMap() { + return map; + } +} \ No newline at end of file diff --git a/src/main/java/spoon/diff/context/ObjectContext.java b/src/main/java/spoon/diff/context/ObjectContext.java index c131bf4cbf8..43a0845d4c1 100644 --- a/src/main/java/spoon/diff/context/ObjectContext.java +++ b/src/main/java/spoon/diff/context/ObjectContext.java @@ -19,11 +19,10 @@ import spoon.reflect.declaration.CtElement; public class ObjectContext extends Context { - private final CtElement ctElement; private final String fieldName; public ObjectContext(CtElement ctElement, String fieldName) { - this.ctElement = ctElement; + super(ctElement); this.fieldName = fieldName; } diff --git a/src/main/java/spoon/diff/context/SetContext.java b/src/main/java/spoon/diff/context/SetContext.java index 0d75cda3aef..cb50aa52f76 100644 --- a/src/main/java/spoon/diff/context/SetContext.java +++ b/src/main/java/spoon/diff/context/SetContext.java @@ -16,10 +16,12 @@ */ package spoon.diff.context; +import spoon.reflect.declaration.CtElement; + import java.util.Set; public class SetContext extends CollectionContext> { - public SetContext(Set original) { - super(original); + public SetContext(CtElement element, Set original) { + super(element, original); } } diff --git a/src/main/java/spoon/generating/CloneVisitorGenerator.java b/src/main/java/spoon/generating/CloneVisitorGenerator.java index 36d8a618d42..a0b50105c18 100644 --- a/src/main/java/spoon/generating/CloneVisitorGenerator.java +++ b/src/main/java/spoon/generating/CloneVisitorGenerator.java @@ -422,11 +422,11 @@ private CtMethod getSetterOf(final CtField ctField) { @Override public boolean matches(CtMethod element) { final CtBlock body = element.getBody(); - if (body.getStatements().size() != 2) { + if (body.getStatements().size() != 3) { return false; } - if (body.getStatement(0) instanceof CtAssignment) { - final CtExpression assigned = ((CtAssignment) body.getStatement(0)).getAssigned(); + if (body.getStatement(1) instanceof CtAssignment) { + final CtExpression assigned = ((CtAssignment) body.getStatement(1)).getAssigned(); if (!(assigned instanceof CtFieldAccess)) { return false; } @@ -440,7 +440,7 @@ public boolean matches(CtMethod element) { } }); if (matchers.size() != 1) { - throw new SpoonException("Get more than one setter. Please make an more ingenious method to get setter method."); + throw new SpoonException("Get more than one setter. Please make an more ingenious method to get setter method. " + matchers.size() + " " + ctField); } return matchers.get(0); } diff --git a/src/main/java/spoon/generating/CtBiScannerGenerator.java b/src/main/java/spoon/generating/CtBiScannerGenerator.java index ff937e9ce09..80d3c18e8d2 100644 --- a/src/main/java/spoon/generating/CtBiScannerGenerator.java +++ b/src/main/java/spoon/generating/CtBiScannerGenerator.java @@ -85,8 +85,8 @@ public void process() { if ("Map".equals(targetInvocation.getExecutable().getType().getSimpleName())) { ((CtExpression) replace.getArguments().get(0)).replace(factory.Code().createInvocation(targetInvocation, factory.Executable().createReference("List Map#values()"))); - replace.getArguments().add(1, factory.Code().createInvocation((CtExpression) replace.getArguments().get(1), factory.Executable().createReference("List Map#values()"))); - replace.getArguments().remove(2); + replace.addArgument(1, factory.Code().createInvocation((CtExpression) replace.getArguments().get(1), factory.Executable().createReference("List Map#values()"))); + replace.removeArgument((CtExpression) replace.getArguments().get(2)); } clone.getBody().getStatement(i).replace(replace); diff --git a/src/main/java/spoon/reflect/code/CtAbstractInvocation.java b/src/main/java/spoon/reflect/code/CtAbstractInvocation.java index d2b24fc45b6..1a92e6719c0 100644 --- a/src/main/java/spoon/reflect/code/CtAbstractInvocation.java +++ b/src/main/java/spoon/reflect/code/CtAbstractInvocation.java @@ -26,6 +26,8 @@ import static spoon.reflect.path.CtRole.ARGUMENT; import static spoon.reflect.path.CtRole.EXECUTABLE; +import java.util.List; + /** * This code element defines an abstract invocation on a * {@link spoon.reflect.declaration.CtExecutable}. @@ -48,11 +50,16 @@ public interface CtAbstractInvocation extends CtElement { @PropertySetter(role = ARGUMENT) > C addArgument(CtExpression argument); + /** + * Adds an argument expression to the invocation at a position. + */ + > C addArgument(int position, CtExpression argument); + /** * Removes an argument expression from the invocation. */ @PropertySetter(role = ARGUMENT) - void removeArgument(CtExpression argument); + boolean removeArgument(CtExpression argument); /** * Sets the invocation's arguments. diff --git a/src/main/java/spoon/reflect/declaration/CtPackage.java b/src/main/java/spoon/reflect/declaration/CtPackage.java index d45c3ebca70..d9d189c4bb6 100644 --- a/src/main/java/spoon/reflect/declaration/CtPackage.java +++ b/src/main/java/spoon/reflect/declaration/CtPackage.java @@ -104,7 +104,7 @@ public interface CtPackage extends CtNamedElement, CtShadowable { * Removes a type from this package. */ @PropertySetter(role = TYPE) - void removeType(CtType type); + boolean removeType(CtType type); /** * Sets the children defined in this package diff --git a/src/main/java/spoon/support/DefaultCoreFactory.java b/src/main/java/spoon/support/DefaultCoreFactory.java index 5edc6e633c2..63c922b3578 100644 --- a/src/main/java/spoon/support/DefaultCoreFactory.java +++ b/src/main/java/spoon/support/DefaultCoreFactory.java @@ -625,9 +625,9 @@ public CtCodeSnippetStatement createCodeSnippetStatement() { public CtComment createComment() { CtComment e = new CtCommentImpl(); + e.setFactory(getMainFactory()); e.setCommentType(CtComment.CommentType.BLOCK); e.setContent(""); - e.setFactory(getMainFactory()); return e; } diff --git a/src/main/java/spoon/support/StandardEnvironment.java b/src/main/java/spoon/support/StandardEnvironment.java index 056005c1445..b83c1311074 100644 --- a/src/main/java/spoon/support/StandardEnvironment.java +++ b/src/main/java/spoon/support/StandardEnvironment.java @@ -43,7 +43,9 @@ import java.net.MalformedURLException; import java.net.URL; import java.net.URLClassLoader; +import java.util.ArrayDeque; import java.util.ArrayList; +import java.util.Deque; import java.util.List; import java.util.Map; import java.util.TreeMap; @@ -88,6 +90,8 @@ public class StandardEnvironment implements Serializable, Environment { private boolean buildStackChanges; + private Deque actions = new ArrayDeque<>(); + /** * Creates a new environment with a null default file * generator. @@ -164,7 +168,12 @@ public void setBuildStackChanges(boolean buildStackChanges) { @Override public void pushToStack(Action action) { + actions.push(action); + } + @Override + public Deque getActionChanges() { + return actions; } private Level toLevel(String level) { diff --git a/src/main/java/spoon/support/reflect/code/CtArrayAccessImpl.java b/src/main/java/spoon/support/reflect/code/CtArrayAccessImpl.java index 1070f7875c4..60a40d48ea8 100644 --- a/src/main/java/spoon/support/reflect/code/CtArrayAccessImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtArrayAccessImpl.java @@ -16,10 +16,12 @@ */ package spoon.support.reflect.code; +import spoon.diff.UpdateAction; +import spoon.diff.context.ObjectContext; +import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.code.CtArrayAccess; import spoon.reflect.code.CtExpression; import spoon.reflect.path.CtRole; -import spoon.reflect.annotations.MetamodelPropertyField; public abstract class CtArrayAccessImpl> extends CtTargetedExpressionImpl implements CtArrayAccess { private static final long serialVersionUID = 1L; @@ -37,6 +39,9 @@ public > C setIndexExpression(CtExpression extends CtStatementImpl implements CtAssert { private static final long serialVersionUID = 1L; @@ -46,6 +48,9 @@ public > A setAssertExpression(CtExpression asser if (asserted != null) { asserted.setParent(this); } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "asserted"), asserted, this.asserted)); + } this.asserted = asserted; return (A) this; } @@ -60,6 +65,9 @@ public > A setExpression(CtExpression value) { if (value != null) { value.setParent(this); } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "value"), value, this.value)); + } this.value = value; return (A) this; } diff --git a/src/main/java/spoon/support/reflect/code/CtAssignmentImpl.java b/src/main/java/spoon/support/reflect/code/CtAssignmentImpl.java index e5e198736f5..f266f7067b2 100644 --- a/src/main/java/spoon/support/reflect/code/CtAssignmentImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtAssignmentImpl.java @@ -16,6 +16,12 @@ */ package spoon.support.reflect.code; +import spoon.diff.AddAction; +import spoon.diff.DeleteAllAction; +import spoon.diff.UpdateAction; +import spoon.diff.context.ListContext; +import spoon.diff.context.ObjectContext; +import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.code.CtAssignment; import spoon.reflect.code.CtExpression; import spoon.reflect.code.CtRHSReceiver; @@ -24,7 +30,6 @@ import spoon.reflect.path.CtRole; import spoon.reflect.reference.CtTypeReference; import spoon.reflect.visitor.CtVisitor; -import spoon.reflect.annotations.MetamodelPropertyField; import spoon.support.reflect.declaration.CtElementImpl; import java.util.ArrayList; @@ -77,6 +82,9 @@ public > C setAssigned(CtExpression assigned) { if (assigned != null) { assigned.setParent(this); } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "assigned"), assigned, this.assigned)); + } this.assigned = assigned; return (C) this; } @@ -86,6 +94,9 @@ public > C setAssignment(CtExpression assignment) if (assignment != null) { assignment.setParent(this); } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "assignment"), assignment, this.assignment)); + } this.assignment = assignment; return (C) this; } @@ -95,6 +106,9 @@ public C setType(CtTypeReference type) { if (type != null) { type.setParent(this); } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "type"), type, this.type)); + } this.type = type; return (C) this; } @@ -108,6 +122,10 @@ public > C setTypeCasts(List> casts if (this.typeCasts == CtElementImpl.>emptyList()) { this.typeCasts = new ArrayList<>(CASTS_CONTAINER_DEFAULT_CAPACITY); } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new DeleteAllAction(new ListContext( + this, this.typeCasts), new ArrayList<>(this.typeCasts))); + } this.typeCasts.clear(); for (CtTypeReference cast : casts) { addTypeCast(cast); @@ -124,6 +142,10 @@ public > C addTypeCast(CtTypeReference type) { typeCasts = new ArrayList<>(CASTS_CONTAINER_DEFAULT_CAPACITY); } type.setParent(this); + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new AddAction(new ListContext( + this, typeCasts), type)); + } typeCasts.add(type); return (C) this; } diff --git a/src/main/java/spoon/support/reflect/code/CtBinaryOperatorImpl.java b/src/main/java/spoon/support/reflect/code/CtBinaryOperatorImpl.java index 00e15e52acc..a7307ffa4a0 100644 --- a/src/main/java/spoon/support/reflect/code/CtBinaryOperatorImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtBinaryOperatorImpl.java @@ -16,12 +16,14 @@ */ package spoon.support.reflect.code; +import spoon.diff.UpdateAction; +import spoon.diff.context.ObjectContext; +import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.code.BinaryOperatorKind; import spoon.reflect.code.CtBinaryOperator; import spoon.reflect.code.CtExpression; import spoon.reflect.path.CtRole; import spoon.reflect.visitor.CtVisitor; -import spoon.reflect.annotations.MetamodelPropertyField; public class CtBinaryOperatorImpl extends CtExpressionImpl implements CtBinaryOperator { private static final long serialVersionUID = 1L; @@ -55,6 +57,9 @@ public > C setLeftHandOperand(CtExpression expr if (expression != null) { expression.setParent(this); } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "leftHandOperand"), expression, this.leftHandOperand)); + } leftHandOperand = expression; return (C) this; } @@ -64,12 +69,18 @@ public > C setRightHandOperand(CtExpression exp if (expression != null) { expression.setParent(this); } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "rightHandOperand"), expression, this.rightHandOperand)); + } rightHandOperand = expression; return (C) this; } @Override public > C setKind(BinaryOperatorKind kind) { + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "kind"), kind, this.kind)); + } this.kind = kind; return (C) this; } diff --git a/src/main/java/spoon/support/reflect/code/CtBlockImpl.java b/src/main/java/spoon/support/reflect/code/CtBlockImpl.java index a719069f79e..d2f84d04cfa 100644 --- a/src/main/java/spoon/support/reflect/code/CtBlockImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtBlockImpl.java @@ -16,6 +16,11 @@ */ package spoon.support.reflect.code; +import spoon.diff.AddAction; +import spoon.diff.DeleteAction; +import spoon.diff.DeleteAllAction; +import spoon.diff.context.ListContext; +import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.code.CtBlock; import spoon.reflect.code.CtInvocation; import spoon.reflect.code.CtStatement; @@ -27,7 +32,6 @@ import spoon.reflect.visitor.CtVisitor; import spoon.reflect.visitor.Filter; import spoon.reflect.visitor.Query; -import spoon.reflect.annotations.MetamodelPropertyField; import spoon.support.reflect.declaration.CtElementImpl; import spoon.support.util.EmptyIterator; @@ -163,6 +167,10 @@ public T setStatements(List statements) this.statements = CtElementImpl.emptyList(); return (T) this; } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new DeleteAllAction(new ListContext( + this, this.statements), new ArrayList<>(this.statements))); + } this.statements.clear(); for (CtStatement s : statements) { addStatement(s); @@ -177,6 +185,10 @@ public T addStatement(CtStatement statement) { } ensureModifiableStatementsList(); statement.setParent(this); + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new AddAction(new ListContext( + this, this.statements), statement)); + } this.statements.add(statement); if (isImplicit() && this.statements.size() > 1) { setImplicit(false); @@ -193,12 +205,14 @@ private void ensureModifiableStatementsList() { @Override public void removeStatement(CtStatement statement) { if (this.statements != CtElementImpl.emptyList()) { - boolean hasBeenRemoved = false; // we cannot use a remove(statement) as it uses the equals // and a block can have twice exactly the same statement. for (int i = 0; i < this.statements.size(); i++) { if (this.statements.get(i) == statement) { + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new DeleteAction(new ListContext(this, statements, i), statement)); + } this.statements.remove(i); hasBeenRemoved = true; break; @@ -207,6 +221,9 @@ public void removeStatement(CtStatement statement) { // in case we use it with a statement manually built if (!hasBeenRemoved) { + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new DeleteAction(new ListContext(this, statements, statements.indexOf(statement)), statement)); + } this.statements.remove(statement); } diff --git a/src/main/java/spoon/support/reflect/code/CtBreakImpl.java b/src/main/java/spoon/support/reflect/code/CtBreakImpl.java index 6ec6972170f..8b5b71a1b85 100644 --- a/src/main/java/spoon/support/reflect/code/CtBreakImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtBreakImpl.java @@ -17,12 +17,14 @@ package spoon.support.reflect.code; import spoon.reflect.code.CtLabelledFlowBreak; +import spoon.diff.UpdateAction; +import spoon.diff.context.ObjectContext; +import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.code.CtBreak; import spoon.reflect.code.CtStatement; import spoon.reflect.declaration.CtElement; import spoon.reflect.path.CtRole; import spoon.reflect.visitor.CtVisitor; -import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.visitor.filter.ParentFunction; import java.util.List; @@ -45,6 +47,9 @@ public String getTargetLabel() { @Override public T setTargetLabel(String targetLabel) { + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "targetLabel"), targetLabel, this.targetLabel)); + } this.targetLabel = targetLabel; return (T) this; } diff --git a/src/main/java/spoon/support/reflect/code/CtCaseImpl.java b/src/main/java/spoon/support/reflect/code/CtCaseImpl.java index 534d6c80b86..899c32bcc71 100644 --- a/src/main/java/spoon/support/reflect/code/CtCaseImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtCaseImpl.java @@ -16,13 +16,19 @@ */ package spoon.support.reflect.code; +import spoon.diff.AddAction; +import spoon.diff.DeleteAction; +import spoon.diff.DeleteAllAction; +import spoon.diff.UpdateAction; +import spoon.diff.context.ListContext; +import spoon.diff.context.ObjectContext; +import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.code.CtCase; import spoon.reflect.code.CtExpression; import spoon.reflect.code.CtStatement; import spoon.reflect.code.CtStatementList; import spoon.reflect.path.CtRole; import spoon.reflect.visitor.CtVisitor; -import spoon.reflect.annotations.MetamodelPropertyField; import spoon.support.reflect.declaration.CtElementImpl; import java.util.ArrayList; @@ -60,6 +66,9 @@ public > T setCaseExpression(CtExpression caseExpression) if (caseExpression != null) { caseExpression.setParent(this); } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "caseExpression"), caseExpression, this.caseExpression)); + } this.caseExpression = caseExpression; return (T) this; } @@ -70,6 +79,10 @@ public T setStatements(List statements) this.statements = CtElementImpl.emptyList(); return (T) this; } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new DeleteAllAction(new ListContext( + this, this.statements), new ArrayList<>(this.statements))); + } this.statements.clear(); for (CtStatement stmt : statements) { addStatement(stmt); @@ -86,6 +99,10 @@ public T addStatement(CtStatement statement) { statements = new ArrayList<>(CASE_STATEMENTS_CONTAINER_DEFAULT_CAPACITY); } statement.setParent(this); + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new AddAction(new ListContext( + this, this.statements), statement)); + } statements.add(statement); return (T) this; } @@ -95,6 +112,10 @@ public void removeStatement(CtStatement statement) { if (statements == CtElementImpl.emptyList()) { return; } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new DeleteAction(new ListContext( + this, statements, statements.indexOf(statement)), statement)); + } statements.remove(statement); } diff --git a/src/main/java/spoon/support/reflect/code/CtCatchImpl.java b/src/main/java/spoon/support/reflect/code/CtCatchImpl.java index 9f0a1d11574..2422f9696bb 100644 --- a/src/main/java/spoon/support/reflect/code/CtCatchImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtCatchImpl.java @@ -16,6 +16,10 @@ */ package spoon.support.reflect.code; +import spoon.diff.DeleteAction; +import spoon.diff.UpdateAction; +import spoon.diff.context.ObjectContext; +import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.code.CtBlock; import spoon.reflect.code.CtBodyHolder; import spoon.reflect.code.CtCatch; @@ -23,7 +27,6 @@ import spoon.reflect.code.CtStatement; import spoon.reflect.path.CtRole; import spoon.reflect.visitor.CtVisitor; -import spoon.reflect.annotations.MetamodelPropertyField; public class CtCatchImpl extends CtCodeElementImpl implements CtCatch { private static final long serialVersionUID = 1L; @@ -53,11 +56,17 @@ public CtCatchVariable getParameter() { public T setBody(CtStatement statement) { if (statement != null) { CtBlock body = getFactory().Code().getOrCreateCtBlock(statement); + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "body"), body, this.body)); + } if (body != null) { body.setParent(this); } this.body = body; } else { + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new DeleteAction(new ObjectContext(this, "body"), this.body)); + } this.body = null; } @@ -69,6 +78,9 @@ public T setParameter(CtCatchVariable p if (parameter != null) { parameter.setParent(this); } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "parameter"), parameter, this.parameter)); + } this.parameter = parameter; return (T) this; } diff --git a/src/main/java/spoon/support/reflect/code/CtCatchVariableImpl.java b/src/main/java/spoon/support/reflect/code/CtCatchVariableImpl.java index 4de149fb5f5..c057b6a1e89 100644 --- a/src/main/java/spoon/support/reflect/code/CtCatchVariableImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtCatchVariableImpl.java @@ -16,6 +16,14 @@ */ package spoon.support.reflect.code; +import spoon.diff.AddAction; +import spoon.diff.DeleteAction; +import spoon.diff.DeleteAllAction; +import spoon.diff.UpdateAction; +import spoon.diff.context.ListContext; +import spoon.diff.context.ObjectContext; +import spoon.diff.context.SetContext; +import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.code.CtCatchVariable; import spoon.reflect.code.CtExpression; import spoon.reflect.declaration.CtModifiable; @@ -29,12 +37,12 @@ import spoon.reflect.reference.CtTypeReference; import spoon.reflect.visitor.CtVisitor; import spoon.support.DerivedProperty; -import spoon.reflect.annotations.MetamodelPropertyField; import spoon.support.UnsettableProperty; import spoon.support.reflect.declaration.CtElementImpl; import java.util.ArrayList; import java.util.EnumSet; +import java.util.HashSet; import java.util.List; import java.util.Set; @@ -90,6 +98,9 @@ public > C setDefaultExpression(CtExpression defaultE @Override public C setSimpleName(String simpleName) { + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "name"), simpleName, this.name)); + } this.name = simpleName; return (C) this; } @@ -99,25 +110,39 @@ public C setType(CtTypeReference type) { if (type != null) { type.setParent(this); } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "type"), type, this.type)); + } this.type = type; return (C) this; } @Override - public T addMultiType(CtTypeReference ref) { - if (ref == null) { + public T addMultiType(CtTypeReference type) { + if (type == null) { return (T) this; } if (types == CtElementImpl.>emptyList()) { types = new ArrayList<>(CATCH_VARIABLE_MULTI_TYPES_CONTAINER_DEFAULT_CAPACITY); } - ref.setParent(this); - types.add(ref); + type.setParent(this); + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new AddAction(new ListContext( + this, this.types), type)); + } + types.add(type); return (T) this; } @Override public boolean removeMultiType(CtTypeReference ref) { + if (this.types == CtElementImpl.>emptyList()) { + return false; + } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new DeleteAction(new ListContext( + this, types, types.indexOf(ref)), ref)); + } return types.remove(ref); } @@ -128,6 +153,9 @@ public List> getMultiTypes() { @Override public T setMultiTypes(List> types) { + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new DeleteAllAction(new ListContext(this, this.types), new ArrayList<>(this.types))); + } if (types == null || types.isEmpty()) { this.types = CtElementImpl.emptyList(); return (T) this; @@ -155,7 +183,13 @@ public boolean hasModifier(ModifierKind modifier) { @Override public C setModifiers(Set modifiers) { if (modifiers.size() > 0) { - this.modifiers = EnumSet.copyOf(modifiers); + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new DeleteAllAction(new SetContext(this, this.modifiers), new HashSet<>(this.modifiers))); + } + this.modifiers.clear(); + for (ModifierKind modifier : modifiers) { + addModifier(modifier); + } } return (C) this; } @@ -165,13 +199,24 @@ public C addModifier(ModifierKind modifier) { if (modifiers == CtElementImpl.emptySet()) { this.modifiers = EnumSet.noneOf(ModifierKind.class); } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new AddAction(new SetContext( + this, this.modifiers), modifier)); + } modifiers.add(modifier); return (C) this; } @Override public boolean removeModifier(ModifierKind modifier) { - return !modifiers.isEmpty() && modifiers.remove(modifier); + if (modifiers == CtElementImpl.emptySet()) { + return false; + } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new DeleteAction(new SetContext( + this, modifiers), modifier)); + } + return modifiers.remove(modifier); } @Override diff --git a/src/main/java/spoon/support/reflect/code/CtCodeSnippetExpressionImpl.java b/src/main/java/spoon/support/reflect/code/CtCodeSnippetExpressionImpl.java index a4d7e2df8ad..b56fb5231b6 100644 --- a/src/main/java/spoon/support/reflect/code/CtCodeSnippetExpressionImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtCodeSnippetExpressionImpl.java @@ -16,12 +16,14 @@ */ package spoon.support.reflect.code; +import spoon.diff.UpdateAction; +import spoon.diff.context.ObjectContext; +import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.code.CtCodeSnippetExpression; import spoon.reflect.code.CtExpression; import spoon.reflect.declaration.CtCodeSnippet; import spoon.reflect.path.CtRole; import spoon.reflect.visitor.CtVisitor; -import spoon.reflect.annotations.MetamodelPropertyField; import spoon.support.compiler.SnippetCompilationError; import spoon.support.compiler.SnippetCompilationHelper; @@ -41,6 +43,9 @@ public String getValue() { } public C setValue(String value) { + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "value"), value, this.value)); + } this.value = value; return (C) this; } diff --git a/src/main/java/spoon/support/reflect/code/CtCodeSnippetStatementImpl.java b/src/main/java/spoon/support/reflect/code/CtCodeSnippetStatementImpl.java index 06d95a872c0..6d701e94265 100644 --- a/src/main/java/spoon/support/reflect/code/CtCodeSnippetStatementImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtCodeSnippetStatementImpl.java @@ -16,12 +16,14 @@ */ package spoon.support.reflect.code; +import spoon.diff.UpdateAction; +import spoon.diff.context.ObjectContext; +import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.code.CtCodeSnippetStatement; import spoon.reflect.code.CtStatement; import spoon.reflect.declaration.CtCodeSnippet; import spoon.reflect.path.CtRole; import spoon.reflect.visitor.CtVisitor; -import spoon.reflect.annotations.MetamodelPropertyField; import spoon.support.compiler.SnippetCompilationError; import spoon.support.compiler.SnippetCompilationHelper; @@ -41,6 +43,9 @@ public String getValue() { } public C setValue(String value) { + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "value"), value, this.value)); + } this.value = value; return (C) this; } diff --git a/src/main/java/spoon/support/reflect/code/CtCommentImpl.java b/src/main/java/spoon/support/reflect/code/CtCommentImpl.java index 3062686f19f..a09009eb97f 100644 --- a/src/main/java/spoon/support/reflect/code/CtCommentImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtCommentImpl.java @@ -16,10 +16,12 @@ */ package spoon.support.reflect.code; +import spoon.diff.UpdateAction; +import spoon.diff.context.ObjectContext; +import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.code.CtComment; import spoon.reflect.path.CtRole; import spoon.reflect.visitor.CtVisitor; -import spoon.reflect.annotations.MetamodelPropertyField; public class CtCommentImpl extends CtStatementImpl implements CtComment { private static final long serialVersionUID = 1L; @@ -37,6 +39,9 @@ public String getContent() { @Override public E setContent(String content) { + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "content"), content, this.content)); + } this.content = content; return (E) this; } @@ -48,6 +53,9 @@ public CommentType getCommentType() { @Override public E setCommentType(CommentType commentType) { + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "type"), commentType, this.type)); + } type = commentType; return (E) this; } diff --git a/src/main/java/spoon/support/reflect/code/CtConditionalImpl.java b/src/main/java/spoon/support/reflect/code/CtConditionalImpl.java index 91d7c71caf7..bd854fa8039 100644 --- a/src/main/java/spoon/support/reflect/code/CtConditionalImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtConditionalImpl.java @@ -16,11 +16,13 @@ */ package spoon.support.reflect.code; +import spoon.diff.UpdateAction; +import spoon.diff.context.ObjectContext; +import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.code.CtConditional; import spoon.reflect.code.CtExpression; import spoon.reflect.path.CtRole; import spoon.reflect.visitor.CtVisitor; -import spoon.reflect.annotations.MetamodelPropertyField; public class CtConditionalImpl extends CtExpressionImpl implements CtConditional { private static final long serialVersionUID = 1L; @@ -59,6 +61,9 @@ public > C setElseExpression(CtExpression elseExpr if (elseExpression != null) { elseExpression.setParent(this); } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "elseExpression"), elseExpression, this.elseExpression)); + } this.elseExpression = elseExpression; return (C) this; } @@ -68,6 +73,9 @@ public > C setCondition(CtExpression conditi if (condition != null) { condition.setParent(this); } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "condition"), condition, this.condition)); + } this.condition = condition; return (C) this; } @@ -77,6 +85,9 @@ public > C setThenExpression(CtExpression thenExpr if (thenExpression != null) { thenExpression.setParent(this); } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "thenExpression"), thenExpression, this.thenExpression)); + } this.thenExpression = thenExpression; return (C) this; } diff --git a/src/main/java/spoon/support/reflect/code/CtConstructorCallImpl.java b/src/main/java/spoon/support/reflect/code/CtConstructorCallImpl.java index 3b9b9a786bb..54ab61d923d 100644 --- a/src/main/java/spoon/support/reflect/code/CtConstructorCallImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtConstructorCallImpl.java @@ -16,6 +16,13 @@ */ package spoon.support.reflect.code; +import spoon.diff.AddAction; +import spoon.diff.DeleteAction; +import spoon.diff.DeleteAllAction; +import spoon.diff.UpdateAction; +import spoon.diff.context.ListContext; +import spoon.diff.context.ObjectContext; +import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.code.CtAbstractInvocation; import spoon.reflect.code.CtConstructorCall; import spoon.reflect.code.CtExpression; @@ -28,7 +35,7 @@ import spoon.reflect.reference.CtExecutableReference; import spoon.reflect.reference.CtTypeReference; import spoon.reflect.visitor.CtVisitor; -import spoon.reflect.annotations.MetamodelPropertyField; +import spoon.support.DerivedProperty; import spoon.support.reflect.declaration.CtElementImpl; import java.util.ArrayList; @@ -102,6 +109,10 @@ public > C setArguments(List> if (this.arguments == CtElementImpl.>emptyList()) { this.arguments = new ArrayList<>(PARAMETERS_CONTAINER_DEFAULT_CAPACITY); } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new DeleteAllAction(new ListContext( + this, this.arguments), new ArrayList<>(this.arguments))); + } this.arguments.clear(); for (CtExpression expr : arguments) { addArgument(expr); @@ -110,7 +121,7 @@ public > C setArguments(List> } @Override - public > C addArgument(CtExpression argument) { + public > C addArgument(int position, CtExpression argument) { if (argument == null) { return (C) this; } @@ -118,15 +129,28 @@ public > C addArgument(CtExpression argumen arguments = new ArrayList<>(PARAMETERS_CONTAINER_DEFAULT_CAPACITY); } argument.setParent(this); - arguments.add(argument); + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new AddAction(new ListContext(this, this.arguments, position), argument)); + } + arguments.add(position, argument); return (C) this; } @Override - public void removeArgument(CtExpression argument) { - if (arguments != CtElementImpl.>emptyList()) { - arguments.remove(argument); + public > C addArgument(CtExpression argument) { + return addArgument(arguments.size(), argument); + } + + @Override + public boolean removeArgument(CtExpression argument) { + if (arguments == CtElementImpl.>emptyList()) { + return false; } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new DeleteAction(new ListContext( + this, arguments, arguments.indexOf(argument)), argument)); + } + return arguments.remove(argument); } @Override @@ -134,12 +158,18 @@ public > C setExecutable(CtExecutableReference if (executable != null) { executable.setParent(this); } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "executable"), executable, this.executable)); + } this.executable = executable; return (C) this; } @Override public C setLabel(String label) { + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "label"), label, this.label)); + } this.label = label; return (C) this; } @@ -150,11 +180,13 @@ public void replace(CtStatement element) { } @Override + @DerivedProperty public List> getActualTypeArguments() { return getExecutable() == null ? CtElementImpl.>emptyList() : getExecutable().getActualTypeArguments(); } @Override + @DerivedProperty public T setActualTypeArguments(List> actualTypeArguments) { if (getExecutable() != null) { getExecutable().setActualTypeArguments(actualTypeArguments); @@ -163,6 +195,7 @@ public T setActualTypeArguments(List T addActualTypeArgument(CtTypeReference actualTypeArgument) { if (getExecutable() != null) { getExecutable().addActualTypeArgument(actualTypeArgument); @@ -171,16 +204,22 @@ public T addActualTypeArgument(CtTypeReference } @Override + @DerivedProperty public boolean removeActualTypeArgument(CtTypeReference actualTypeArgument) { - return getExecutable() != null && getExecutable().removeActualTypeArgument(actualTypeArgument); + if (getExecutable() != null) { + return getExecutable().removeActualTypeArgument(actualTypeArgument); + } + return false; } @Override + @DerivedProperty public CtTypeReference getType() { return getExecutable() == null ? null : getExecutable().getType(); } @Override + @DerivedProperty public C setType(CtTypeReference type) { if (type != null) { type.setParent(this); diff --git a/src/main/java/spoon/support/reflect/code/CtContinueImpl.java b/src/main/java/spoon/support/reflect/code/CtContinueImpl.java index aeb9893c230..eb51ea3a94e 100644 --- a/src/main/java/spoon/support/reflect/code/CtContinueImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtContinueImpl.java @@ -17,6 +17,8 @@ package spoon.support.reflect.code; import spoon.reflect.code.CtLabelledFlowBreak; +import spoon.diff.UpdateAction; +import spoon.diff.context.ObjectContext; import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.code.CtContinue; import spoon.reflect.code.CtStatement; @@ -45,6 +47,9 @@ public String getTargetLabel() { @Override public T setTargetLabel(String targetLabel) { + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "targetLabel"), targetLabel, this.targetLabel)); + } this.targetLabel = targetLabel; return (T) this; } diff --git a/src/main/java/spoon/support/reflect/code/CtDoImpl.java b/src/main/java/spoon/support/reflect/code/CtDoImpl.java index d1e236e40e4..3359d0fc4dc 100644 --- a/src/main/java/spoon/support/reflect/code/CtDoImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtDoImpl.java @@ -16,11 +16,13 @@ */ package spoon.support.reflect.code; +import spoon.diff.UpdateAction; +import spoon.diff.context.ObjectContext; +import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.code.CtDo; import spoon.reflect.code.CtExpression; import spoon.reflect.path.CtRole; import spoon.reflect.visitor.CtVisitor; -import spoon.reflect.annotations.MetamodelPropertyField; public class CtDoImpl extends CtLoopImpl implements CtDo { private static final long serialVersionUID = 1L; @@ -43,6 +45,9 @@ public T setLoopingExpression(CtExpression expression) if (expression != null) { expression.setParent(this); } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "expression"), expression, this.expression)); + } this.expression = expression; return (T) this; } diff --git a/src/main/java/spoon/support/reflect/code/CtExecutableReferenceExpressionImpl.java b/src/main/java/spoon/support/reflect/code/CtExecutableReferenceExpressionImpl.java index 66e4fc46251..f94ec2fdd74 100644 --- a/src/main/java/spoon/support/reflect/code/CtExecutableReferenceExpressionImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtExecutableReferenceExpressionImpl.java @@ -16,12 +16,14 @@ */ package spoon.support.reflect.code; +import spoon.diff.UpdateAction; +import spoon.diff.context.ObjectContext; +import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.code.CtExecutableReferenceExpression; import spoon.reflect.code.CtExpression; import spoon.reflect.path.CtRole; import spoon.reflect.reference.CtExecutableReference; import spoon.reflect.visitor.CtVisitor; -import spoon.reflect.annotations.MetamodelPropertyField; public class CtExecutableReferenceExpressionImpl> extends CtTargetedExpressionImpl implements CtExecutableReferenceExpression { @MetamodelPropertyField(role = CtRole.EXECUTABLE) @@ -42,6 +44,9 @@ public > C setExecutable(CtExecu if (executable != null) { executable.setParent(this); } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "executable"), executable, this.executable)); + } this.executable = executable; return (C) this; } diff --git a/src/main/java/spoon/support/reflect/code/CtExpressionImpl.java b/src/main/java/spoon/support/reflect/code/CtExpressionImpl.java index 45d2922bb74..6feb31f2e8d 100644 --- a/src/main/java/spoon/support/reflect/code/CtExpressionImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtExpressionImpl.java @@ -16,11 +16,16 @@ */ package spoon.support.reflect.code; +import spoon.diff.AddAction; +import spoon.diff.DeleteAllAction; +import spoon.diff.UpdateAction; +import spoon.diff.context.ListContext; +import spoon.diff.context.ObjectContext; +import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.code.CtExpression; import spoon.reflect.declaration.CtTypedElement; import spoon.reflect.path.CtRole; import spoon.reflect.reference.CtTypeReference; -import spoon.reflect.annotations.MetamodelPropertyField; import spoon.support.reflect.declaration.CtElementImpl; import java.util.ArrayList; @@ -51,6 +56,9 @@ public C setType(CtTypeReference type) { if (type != null) { type.setParent(this); } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "type"), type, this.type)); + } this.type = type; return (C) this; } @@ -64,6 +72,10 @@ public > C setTypeCasts(List> casts if (this.typeCasts == CtElementImpl.>emptyList()) { this.typeCasts = new ArrayList<>(CASTS_CONTAINER_DEFAULT_CAPACITY); } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new DeleteAllAction(new ListContext( + this, this.typeCasts), new ArrayList<>(this.typeCasts))); + } this.typeCasts.clear(); for (CtTypeReference cast : casts) { addTypeCast(cast); @@ -80,6 +92,10 @@ public > C addTypeCast(CtTypeReference type) { typeCasts = new ArrayList<>(CASTS_CONTAINER_DEFAULT_CAPACITY); } type.setParent(this); + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new AddAction(new ListContext( + this, this.typeCasts), type)); + } typeCasts.add(type); return (C) this; } diff --git a/src/main/java/spoon/support/reflect/code/CtFieldAccessImpl.java b/src/main/java/spoon/support/reflect/code/CtFieldAccessImpl.java index 65f9cdb9313..ad3d35baac1 100644 --- a/src/main/java/spoon/support/reflect/code/CtFieldAccessImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtFieldAccessImpl.java @@ -16,12 +16,14 @@ */ package spoon.support.reflect.code; +import spoon.diff.UpdateAction; +import spoon.diff.context.ObjectContext; +import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.code.CtExpression; import spoon.reflect.code.CtFieldAccess; import spoon.reflect.code.CtTargetedExpression; import spoon.reflect.path.CtRole; import spoon.reflect.reference.CtFieldReference; -import spoon.reflect.annotations.MetamodelPropertyField; public abstract class CtFieldAccessImpl extends CtVariableAccessImpl implements CtFieldAccess { private static final long serialVersionUID = 1L; @@ -35,11 +37,13 @@ public CtExpression getTarget() { } @Override - public >> C setTarget( - CtExpression target) { + public >> C setTarget(CtExpression target) { if (target != null) { target.setParent(this); } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "target"), target, this.target)); + } this.target = target; return null; } diff --git a/src/main/java/spoon/support/reflect/code/CtForEachImpl.java b/src/main/java/spoon/support/reflect/code/CtForEachImpl.java index 7487e3ecb17..c0d211d39c4 100644 --- a/src/main/java/spoon/support/reflect/code/CtForEachImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtForEachImpl.java @@ -16,12 +16,14 @@ */ package spoon.support.reflect.code; +import spoon.diff.UpdateAction; +import spoon.diff.context.ObjectContext; +import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.code.CtExpression; import spoon.reflect.code.CtForEach; import spoon.reflect.code.CtLocalVariable; import spoon.reflect.path.CtRole; import spoon.reflect.visitor.CtVisitor; -import spoon.reflect.annotations.MetamodelPropertyField; public class CtForEachImpl extends CtLoopImpl implements CtForEach { private static final long serialVersionUID = 1L; @@ -52,6 +54,9 @@ public T setExpression(CtExpression expression) { if (expression != null) { expression.setParent(this); } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "expression"), expression, this.expression)); + } this.expression = expression; return (T) this; } @@ -61,6 +66,9 @@ public T setVariable(CtLocalVariable variable) { if (variable != null) { variable.setParent(this); } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "variable"), variable, this.variable)); + } this.variable = variable; return (T) this; } diff --git a/src/main/java/spoon/support/reflect/code/CtForImpl.java b/src/main/java/spoon/support/reflect/code/CtForImpl.java index 5e54ff4bb5f..de8028b199c 100644 --- a/src/main/java/spoon/support/reflect/code/CtForImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtForImpl.java @@ -16,12 +16,18 @@ */ package spoon.support.reflect.code; +import spoon.diff.AddAction; +import spoon.diff.DeleteAction; +import spoon.diff.DeleteAllAction; +import spoon.diff.UpdateAction; +import spoon.diff.context.ListContext; +import spoon.diff.context.ObjectContext; +import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.code.CtExpression; import spoon.reflect.code.CtFor; import spoon.reflect.code.CtStatement; import spoon.reflect.path.CtRole; import spoon.reflect.visitor.CtVisitor; -import spoon.reflect.annotations.MetamodelPropertyField; import spoon.support.reflect.declaration.CtElementImpl; import java.util.ArrayList; @@ -57,6 +63,9 @@ public T setExpression(CtExpression expression) { if (expression != null) { expression.setParent(this); } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "expression"), expression, this.expression)); + } this.expression = expression; return (T) this; } @@ -75,6 +84,10 @@ public T addForInit(CtStatement statement) { forInit = new ArrayList<>(FOR_INIT_STATEMENTS_CONTAINER_DEFAULT_CAPACITY); } statement.setParent(this); + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new AddAction(new ListContext( + this, this.forInit), statement)); + } forInit.add(statement); return (T) this; } @@ -85,6 +98,10 @@ public T setForInit(List statements) { this.forInit = CtElementImpl.emptyList(); return (T) this; } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new DeleteAllAction(new ListContext( + this, this.forInit), new ArrayList<>(this.forInit))); + } this.forInit.clear(); for (CtStatement stmt : statements) { addForInit(stmt); @@ -94,7 +111,14 @@ public T setForInit(List statements) { @Override public boolean removeForInit(CtStatement statement) { - return forInit != CtElementImpl.emptyList() && forInit.remove(statement); + if (forInit == CtElementImpl.emptyList()) { + return false; + } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new DeleteAction(new ListContext( + this, forInit, forInit.indexOf(statement)), statement)); + } + return forInit.remove(statement); } @Override @@ -111,6 +135,10 @@ public T addForUpdate(CtStatement statement) { forUpdate = new ArrayList<>(FOR_UPDATE_STATEMENTS_CONTAINER_DEFAULT_CAPACITY); } statement.setParent(this); + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new AddAction(new ListContext( + this, this.forUpdate), statement)); + } forUpdate.add(statement); return (T) this; } @@ -121,6 +149,10 @@ public T setForUpdate(List statements) { this.forUpdate = CtElementImpl.emptyList(); return (T) this; } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new DeleteAllAction(new ListContext( + this, this.forUpdate), new ArrayList<>(this.forUpdate))); + } this.forUpdate.clear(); for (CtStatement stmt : statements) { addForUpdate(stmt); @@ -130,7 +162,14 @@ public T setForUpdate(List statements) { @Override public boolean removeForUpdate(CtStatement statement) { - return forUpdate != CtElementImpl.emptyList() && forUpdate.remove(statement); + if (forUpdate == CtElementImpl.emptyList()) { + return false; + } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new DeleteAction(new ListContext( + this, forUpdate, forUpdate.indexOf(statement)), statement)); + } + return forUpdate.remove(statement); } @Override diff --git a/src/main/java/spoon/support/reflect/code/CtIfImpl.java b/src/main/java/spoon/support/reflect/code/CtIfImpl.java index a18138c8255..7169c8e26b4 100644 --- a/src/main/java/spoon/support/reflect/code/CtIfImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtIfImpl.java @@ -16,6 +16,9 @@ */ package spoon.support.reflect.code; +import spoon.diff.UpdateAction; +import spoon.diff.context.ObjectContext; +import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.code.CtCodeElement; import spoon.reflect.code.CtExpression; import spoon.reflect.code.CtIf; @@ -23,7 +26,6 @@ import spoon.reflect.declaration.CtType; import spoon.reflect.path.CtRole; import spoon.reflect.visitor.CtVisitor; -import spoon.reflect.annotations.MetamodelPropertyField; public class CtIfImpl extends CtStatementImpl implements CtIf { private static final long serialVersionUID = 1L; @@ -64,6 +66,9 @@ public T setCondition(CtExpression condition) { if (condition != null) { condition.setParent(this); } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "condition"), condition, this.condition)); + } this.condition = condition; return (T) this; } @@ -73,6 +78,9 @@ public T setElseStatement(CtStatement elseStatement) { if (elseStatement != null) { elseStatement.setParent(this); } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "elseStatement"), elseStatement, this.elseStatement)); + } this.elseStatement = elseStatement; return (T) this; } @@ -83,6 +91,9 @@ public T setThenStatement(CtStatement thenStatement) { if (thenStatement != null) { thenStatement.setParent(this); } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "thenStatement"), thenStatement, this.thenStatement)); + } this.thenStatement = thenStatement; return (T) this; } diff --git a/src/main/java/spoon/support/reflect/code/CtInvocationImpl.java b/src/main/java/spoon/support/reflect/code/CtInvocationImpl.java index 664fed51cfe..c581b3798bd 100644 --- a/src/main/java/spoon/support/reflect/code/CtInvocationImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtInvocationImpl.java @@ -16,6 +16,13 @@ */ package spoon.support.reflect.code; +import spoon.diff.AddAction; +import spoon.diff.DeleteAction; +import spoon.diff.DeleteAllAction; +import spoon.diff.UpdateAction; +import spoon.diff.context.ListContext; +import spoon.diff.context.ObjectContext; +import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.code.CtAbstractInvocation; import spoon.reflect.code.CtExpression; import spoon.reflect.code.CtInvocation; @@ -28,7 +35,7 @@ import spoon.reflect.reference.CtExecutableReference; import spoon.reflect.reference.CtTypeReference; import spoon.reflect.visitor.CtVisitor; -import spoon.reflect.annotations.MetamodelPropertyField; +import spoon.support.DerivedProperty; import spoon.support.reflect.declaration.CtElementImpl; import java.util.ArrayList; @@ -59,7 +66,7 @@ public List> getArguments() { } @Override - public > C addArgument(CtExpression argument) { + public > C addArgument(int position, CtExpression argument) { if (argument == null) { return (C) this; } @@ -67,15 +74,29 @@ public > C addArgument(CtExpression argumen arguments = new ArrayList<>(PARAMETERS_CONTAINER_DEFAULT_CAPACITY); } argument.setParent(this); - arguments.add(argument); + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new AddAction(new ListContext( + this, this.arguments, position), argument)); + } + arguments.add(position, argument); return (C) this; } @Override - public void removeArgument(CtExpression argument) { - if (arguments != CtElementImpl.>emptyList()) { - arguments.remove(argument); + public > C addArgument(CtExpression argument) { + return addArgument(arguments.size(), argument); + } + + @Override + public boolean removeArgument(CtExpression argument) { + if (arguments == CtElementImpl.>emptyList()) { + return false; + } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new DeleteAction(new ListContext( + this, arguments, arguments.indexOf(argument)), argument)); } + return arguments.remove(argument); } @Override @@ -120,6 +141,10 @@ public > C setArguments(List> if (this.arguments == CtElementImpl.>emptyList()) { this.arguments = new ArrayList<>(PARAMETERS_CONTAINER_DEFAULT_CAPACITY); } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new DeleteAllAction(new ListContext( + this, this.arguments), new ArrayList<>(this.arguments))); + } this.arguments.clear(); for (CtExpression expr : arguments) { addArgument(expr); @@ -132,6 +157,9 @@ public > C setExecutable(CtExecutableReference if (executable != null) { executable.setParent(this); } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "executable"), executable, this.executable)); + } this.executable = executable; return (C) this; } @@ -143,6 +171,9 @@ public String getLabel() { @Override public C setLabel(String label) { + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "label"), label, this.label)); + } this.label = label; return (C) this; } @@ -153,11 +184,13 @@ public void replace(CtStatement element) { } @Override + @DerivedProperty public CtTypeReference getType() { return getExecutable() == null ? null : getExecutable().getType(); } @Override + @DerivedProperty public C setType(CtTypeReference type) { if (type != null) { type.setParent(this); @@ -191,7 +224,10 @@ public T addActualTypeArgument(CtTypeReference @Override public boolean removeActualTypeArgument(CtTypeReference actualTypeArgument) { - return getExecutable() != null && getExecutable().removeActualTypeArgument(actualTypeArgument); + if (getExecutable() != null) { + return getExecutable().removeActualTypeArgument(actualTypeArgument); + } + return false; } @Override diff --git a/src/main/java/spoon/support/reflect/code/CtJavaDocImpl.java b/src/main/java/spoon/support/reflect/code/CtJavaDocImpl.java index 17ca630c1ee..30e8730b837 100644 --- a/src/main/java/spoon/support/reflect/code/CtJavaDocImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtJavaDocImpl.java @@ -16,11 +16,19 @@ */ package spoon.support.reflect.code; +import spoon.diff.AddAction; +import spoon.diff.DeleteAction; +import spoon.diff.DeleteAllAction; +import spoon.diff.context.ListContext; +import spoon.reflect.annotations.MetamodelPropertyField; +import spoon.diff.AddAction; +import spoon.diff.DeleteAction; +import spoon.diff.DeleteAllAction; +import spoon.diff.context.ListContext; import spoon.reflect.code.CtJavaDoc; import spoon.reflect.code.CtJavaDocTag; import spoon.reflect.path.CtRole; import spoon.reflect.visitor.CtVisitor; -import spoon.reflect.annotations.MetamodelPropertyField; import java.util.ArrayList; import java.util.List; @@ -49,6 +57,10 @@ public E setTags(List tags) { if (tags == null) { return (E) this; } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new DeleteAllAction<>(new ListContext(this, this.tags), new ArrayList<>(this.tags))); + } + this.tags = new ArrayList<>(); for (CtJavaDocTag tag : tags) { this.addTag(tag); } @@ -59,6 +71,9 @@ public E setTags(List tags) { public E addTag(CtJavaDocTag tag) { if (tag != null) { tag.setParent(this); + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new AddAction(new ListContext(this, tags), tag)); + } tags.add(tag); } return (E) this; @@ -67,18 +82,27 @@ public E addTag(CtJavaDocTag tag) { @Override public E addTag(int index, CtJavaDocTag tag) { tag.setParent(this); + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new AddAction(new ListContext(this, tags, index), tag)); + } tags.add(index, tag); return (E) this; } @Override public E removeTag(int index) { + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new DeleteAction(new ListContext(this, tags, index), tags.get(index))); + } tags.remove(index); return (E) this; } @Override public E removeTag(CtJavaDocTag tag) { + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new DeleteAction(new ListContext(this, tags, tags.indexOf(tag)), tag)); + } tags.remove(tag); return (E) this; } diff --git a/src/main/java/spoon/support/reflect/code/CtJavaDocTagImpl.java b/src/main/java/spoon/support/reflect/code/CtJavaDocTagImpl.java index 1cfe7a53e17..f729ef04119 100644 --- a/src/main/java/spoon/support/reflect/code/CtJavaDocTagImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtJavaDocTagImpl.java @@ -16,10 +16,12 @@ */ package spoon.support.reflect.code; +import spoon.reflect.annotations.MetamodelPropertyField; +import spoon.diff.UpdateAction; +import spoon.diff.context.ObjectContext; import spoon.reflect.code.CtJavaDocTag; import spoon.reflect.path.CtRole; import spoon.reflect.visitor.CtVisitor; -import spoon.reflect.annotations.MetamodelPropertyField; import spoon.support.reflect.declaration.CtElementImpl; public class CtJavaDocTagImpl extends CtElementImpl implements CtJavaDocTag { @@ -44,6 +46,9 @@ public E setType(String type) { @Override public E setType(TagType type) { + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "type"), type, this.type)); + } this.type = type; return (E) this; } @@ -55,6 +60,9 @@ public String getContent() { @Override public E setContent(String content) { + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "content"), content, this.content)); + } this.content = content; return (E) this; } @@ -66,6 +74,9 @@ public String getParam() { @Override public E setParam(String param) { + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "param"), param, this.param)); + } this.param = param; return (E) this; } diff --git a/src/main/java/spoon/support/reflect/code/CtLambdaImpl.java b/src/main/java/spoon/support/reflect/code/CtLambdaImpl.java index 015a8d45f2c..f9345a3f3d2 100644 --- a/src/main/java/spoon/support/reflect/code/CtLambdaImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtLambdaImpl.java @@ -17,6 +17,14 @@ package spoon.support.reflect.code; import spoon.SpoonException; +import spoon.diff.AddAction; +import spoon.diff.DeleteAction; +import spoon.diff.DeleteAllAction; +import spoon.diff.UpdateAction; +import spoon.diff.context.ListContext; +import spoon.diff.context.ObjectContext; +import spoon.diff.context.SetContext; +import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.code.CtBlock; import spoon.reflect.code.CtBodyHolder; import spoon.reflect.code.CtExpression; @@ -32,12 +40,12 @@ import spoon.reflect.reference.CtExecutableReference; import spoon.reflect.reference.CtTypeReference; import spoon.reflect.visitor.CtVisitor; -import spoon.reflect.annotations.MetamodelPropertyField; import spoon.support.reflect.declaration.CtElementImpl; import spoon.support.util.QualifiedNameBasedSortedSet; import spoon.support.visitor.SignaturePrinter; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; import java.util.Set; @@ -67,6 +75,9 @@ public String getSimpleName() { @Override public C setSimpleName(String simpleName) { + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "simpleName"), simpleName, this.simpleName)); + } this.simpleName = simpleName; return (C) this; } @@ -79,9 +90,11 @@ public CtBlock getBody() { @Override public C setBody(CtStatement statement) { - if (statement != null) { CtBlock body = getFactory().Code().getOrCreateCtBlock(statement); + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "body"), body, this.body)); + } if (expression != null && body != null) { throw new SpoonException("A lambda can't have two bodys."); } @@ -90,6 +103,9 @@ public C setBody(CtStatement statement) { } this.body = body; } else { + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new DeleteAction(new ObjectContext(this, "body"), this.body)); + } this.body = null; } @@ -145,6 +161,10 @@ public > C setParameters(List> params) if (this.parameters == CtElementImpl.>emptyList()) { this.parameters = new ArrayList<>(PARAMETERS_CONTAINER_DEFAULT_CAPACITY); } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new DeleteAllAction(new ListContext( + this, this.parameters), new ArrayList<>(this.parameters))); + } this.parameters.clear(); for (CtParameter p : params) { addParameter(p); @@ -161,14 +181,22 @@ public > C addParameter(CtParameter parameter) { parameters = new ArrayList<>(PARAMETERS_CONTAINER_DEFAULT_CAPACITY); } parameter.setParent(this); + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new AddAction(new ListContext(this, this.parameters), parameter)); + } parameters.add(parameter); return (C) this; } @Override public boolean removeParameter(CtParameter parameter) { - return parameters != CtElementImpl.>emptyList() - && parameters.remove(parameter); + if (parameters == CtElementImpl.>emptyList()) { + return false; + } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new DeleteAction(new ListContext(this, parameters, parameters.indexOf(parameter)), parameter)); + } + return parameters.remove(parameter); } @Override @@ -185,6 +213,10 @@ public > C setThrownTypes(Set>emptySet()) { this.thrownTypes = new QualifiedNameBasedSortedSet<>(); } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new DeleteAllAction(new SetContext( + this, this.thrownTypes), new HashSet<>(this.thrownTypes))); + } this.thrownTypes.clear(); for (CtTypeReference thrownType : thrownTypes) { addThrownType(thrownType); @@ -201,12 +233,23 @@ public > C addThrownType(CtTypeReference(); } throwType.setParent(this); + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new AddAction(new SetContext( + this, this.thrownTypes), throwType)); + } thrownTypes.add(throwType); return (C) this; } @Override public boolean removeThrownType(CtTypeReference throwType) { + if (thrownTypes == CtElementImpl.>emptySet()) { + return false; + } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new DeleteAction(new SetContext( + this, thrownTypes), throwType)); + } return thrownTypes.remove(throwType); } @@ -235,6 +278,9 @@ public > C setExpression(CtExpression expression) { if (expression != null) { expression.setParent(this); } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "expression"), expression, this.expression)); + } this.expression = expression; } return (C) this; diff --git a/src/main/java/spoon/support/reflect/code/CtLiteralImpl.java b/src/main/java/spoon/support/reflect/code/CtLiteralImpl.java index 3bca282afd2..cb60431cb21 100644 --- a/src/main/java/spoon/support/reflect/code/CtLiteralImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtLiteralImpl.java @@ -16,11 +16,13 @@ */ package spoon.support.reflect.code; +import spoon.diff.UpdateAction; +import spoon.diff.context.ObjectContext; +import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.code.CtLiteral; import spoon.reflect.declaration.CtElement; import spoon.reflect.path.CtRole; import spoon.reflect.visitor.CtVisitor; -import spoon.reflect.annotations.MetamodelPropertyField; public class CtLiteralImpl extends CtExpressionImpl implements CtLiteral { private static final long serialVersionUID = 1L; @@ -40,10 +42,13 @@ public T getValue() { @Override public > C setValue(T value) { - this.value = value; if (this.value instanceof CtElement) { ((CtElement) this.value).setParent(this); } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "value"), value, this.value)); + } + this.value = value; return (C) this; } diff --git a/src/main/java/spoon/support/reflect/code/CtLocalVariableImpl.java b/src/main/java/spoon/support/reflect/code/CtLocalVariableImpl.java index a1c9efe5061..04c71d173fe 100644 --- a/src/main/java/spoon/support/reflect/code/CtLocalVariableImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtLocalVariableImpl.java @@ -16,6 +16,13 @@ */ package spoon.support.reflect.code; +import spoon.diff.AddAction; +import spoon.diff.DeleteAction; +import spoon.diff.DeleteAllAction; +import spoon.diff.UpdateAction; +import spoon.diff.context.ObjectContext; +import spoon.diff.context.SetContext; +import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.code.CtExpression; import spoon.reflect.code.CtLocalVariable; import spoon.reflect.code.CtRHSReceiver; @@ -28,11 +35,11 @@ import spoon.reflect.reference.CtLocalVariableReference; import spoon.reflect.reference.CtTypeReference; import spoon.reflect.visitor.CtVisitor; -import spoon.reflect.annotations.MetamodelPropertyField; import spoon.support.UnsettableProperty; import spoon.support.reflect.declaration.CtElementImpl; import java.util.EnumSet; +import java.util.HashSet; import java.util.Set; public class CtLocalVariableImpl extends CtStatementImpl implements CtLocalVariable { @@ -80,12 +87,18 @@ public > C setDefaultExpression(CtExpression defaultE if (defaultExpression != null) { defaultExpression.setParent(this); } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "defaultExpression"), defaultExpression, this.defaultExpression)); + } this.defaultExpression = defaultExpression; return (C) this; } @Override public C setSimpleName(String simpleName) { + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "name"), simpleName, this.name)); + } this.name = simpleName; return (C) this; } @@ -95,6 +108,9 @@ public C setType(CtTypeReference type) { if (type != null) { type.setParent(this); } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "type"), type, this.type)); + } this.type = type; return (C) this; } @@ -112,7 +128,14 @@ public boolean hasModifier(ModifierKind modifier) { @Override public C setModifiers(Set modifiers) { if (modifiers.size() > 0) { - this.modifiers = EnumSet.copyOf(modifiers); + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new DeleteAllAction(new SetContext(this, this.modifiers), new HashSet<>(this.modifiers))); + } + this.modifiers.clear(); + for (ModifierKind modifier : modifiers) { + addModifier(modifier); + } + } return (C) this; } @@ -122,13 +145,24 @@ public C addModifier(ModifierKind modifier) { if (modifiers == CtElementImpl.emptySet()) { this.modifiers = EnumSet.noneOf(ModifierKind.class); } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new AddAction(new SetContext( + this, this.modifiers), modifier)); + } modifiers.add(modifier); return (C) this; } @Override public boolean removeModifier(ModifierKind modifier) { - return !modifiers.isEmpty() && modifiers.remove(modifier); + if (modifiers == CtElementImpl.emptySet()) { + return false; + } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new DeleteAction(new SetContext( + this, modifiers), modifier)); + } + return modifiers.remove(modifier); } @Override diff --git a/src/main/java/spoon/support/reflect/code/CtLoopImpl.java b/src/main/java/spoon/support/reflect/code/CtLoopImpl.java index 7b44fa4a16f..72a370b3561 100644 --- a/src/main/java/spoon/support/reflect/code/CtLoopImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtLoopImpl.java @@ -16,6 +16,10 @@ */ package spoon.support.reflect.code; +import spoon.diff.UpdateAction; +import spoon.diff.context.ObjectContext; +import spoon.reflect.annotations.MetamodelPropertyField; +import spoon.diff.DeleteAction; import spoon.reflect.code.CtBlock; import spoon.reflect.code.CtBodyHolder; import spoon.reflect.code.CtCodeElement; @@ -23,7 +27,6 @@ import spoon.reflect.code.CtStatement; import spoon.reflect.declaration.CtType; import spoon.reflect.path.CtRole; -import spoon.reflect.annotations.MetamodelPropertyField; public abstract class CtLoopImpl extends CtStatementImpl implements CtLoop { private static final long serialVersionUID = 1L; @@ -41,11 +44,17 @@ public CtStatement getBody() { public T setBody(CtStatement statement) { if (statement != null) { CtBlock body = getFactory().Code().getOrCreateCtBlock(statement); + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "body"), body, this.body)); + } if (body != null) { body.setParent(this); } this.body = body; } else { + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new DeleteAction(new ObjectContext(this, "body"), this.body)); + } this.body = null; } return (T) this; diff --git a/src/main/java/spoon/support/reflect/code/CtNewArrayImpl.java b/src/main/java/spoon/support/reflect/code/CtNewArrayImpl.java index b86b240ef0e..69dc2aff599 100644 --- a/src/main/java/spoon/support/reflect/code/CtNewArrayImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtNewArrayImpl.java @@ -16,11 +16,15 @@ */ package spoon.support.reflect.code; +import spoon.diff.AddAction; +import spoon.diff.DeleteAction; +import spoon.diff.DeleteAllAction; +import spoon.diff.context.ListContext; +import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.code.CtExpression; import spoon.reflect.code.CtNewArray; import spoon.reflect.path.CtRole; import spoon.reflect.visitor.CtVisitor; -import spoon.reflect.annotations.MetamodelPropertyField; import spoon.support.reflect.declaration.CtElementImpl; import java.util.ArrayList; @@ -58,6 +62,10 @@ public > C setDimensionExpressions(List(this.dimensionExpressions))); + } this.dimensionExpressions.clear(); for (CtExpression expr : dimensionExpressions) { addDimensionExpression(expr); @@ -74,15 +82,24 @@ public > C addDimensionExpression(CtExpression dimensionExpressions = new ArrayList<>(NEW_ARRAY_DEFAULT_EXPRESSIONS_CONTAINER_DEFAULT_CAPACITY); } dimension.setParent(this); + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new AddAction(new ListContext( + this, this.dimensionExpressions), dimension)); + } dimensionExpressions.add(dimension); return (C) this; } @Override public boolean removeDimensionExpression(CtExpression dimension) { - return dimensionExpressions - != CtElementImpl.>emptyList() - && dimensionExpressions.remove(dimension); + if (dimensionExpressions == CtElementImpl.>emptyList()) { + return false; + } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new DeleteAction(new ListContext( + this, dimensionExpressions, dimensionExpressions.indexOf(dimension)), dimension)); + } + return dimensionExpressions.remove(dimension); } @Override @@ -91,6 +108,10 @@ public > C setElements(List> expressions this.expressions = CtElementImpl.emptyList(); return (C) this; } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new DeleteAllAction(new ListContext( + this, this.expressions), new ArrayList<>(this.expressions))); + } this.expressions.clear(); for (CtExpression expr : expressions) { addElement(expr); @@ -107,13 +128,24 @@ public > C addElement(CtExpression expression) { this.expressions = new ArrayList<>(); } expression.setParent(this); + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new AddAction(new ListContext( + this, this.expressions), expression)); + } expressions.add(expression); return (C) this; } @Override public boolean removeElement(CtExpression expression) { - return expressions != CtElementImpl.>emptyList() && expressions.remove(expression); + if (expressions == CtElementImpl.>emptyList()) { + return false; + } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new DeleteAction(new ListContext( + this, expressions, expressions.indexOf(expression)), expression)); + } + return expressions.remove(expression); } @Override diff --git a/src/main/java/spoon/support/reflect/code/CtNewClassImpl.java b/src/main/java/spoon/support/reflect/code/CtNewClassImpl.java index d2fd191375f..6885322f8cd 100644 --- a/src/main/java/spoon/support/reflect/code/CtNewClassImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtNewClassImpl.java @@ -16,11 +16,13 @@ */ package spoon.support.reflect.code; +import spoon.diff.UpdateAction; +import spoon.diff.context.ObjectContext; +import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.code.CtNewClass; import spoon.reflect.declaration.CtClass; import spoon.reflect.path.CtRole; import spoon.reflect.visitor.CtVisitor; -import spoon.reflect.annotations.MetamodelPropertyField; public class CtNewClassImpl extends CtConstructorCallImpl implements CtNewClass { private static final long serialVersionUID = 1L; @@ -43,6 +45,9 @@ public N setAnonymousClass(CtClass anonymousClass) { if (anonymousClass != null) { anonymousClass.setParent(this); } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "anonymousClass"), anonymousClass, this.anonymousClass)); + } this.anonymousClass = anonymousClass; return (N) this; } diff --git a/src/main/java/spoon/support/reflect/code/CtOperatorAssignmentImpl.java b/src/main/java/spoon/support/reflect/code/CtOperatorAssignmentImpl.java index 38b83000df9..b77b8723490 100644 --- a/src/main/java/spoon/support/reflect/code/CtOperatorAssignmentImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtOperatorAssignmentImpl.java @@ -16,11 +16,13 @@ */ package spoon.support.reflect.code; +import spoon.diff.UpdateAction; +import spoon.diff.context.ObjectContext; +import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.code.BinaryOperatorKind; import spoon.reflect.code.CtOperatorAssignment; import spoon.reflect.path.CtRole; import spoon.reflect.visitor.CtVisitor; -import spoon.reflect.annotations.MetamodelPropertyField; public class CtOperatorAssignmentImpl extends CtAssignmentImpl implements CtOperatorAssignment { private static final long serialVersionUID = 1L; @@ -40,6 +42,9 @@ public BinaryOperatorKind getKind() { @Override public > C setKind(BinaryOperatorKind kind) { + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "kind"), kind, this.kind)); + } this.kind = kind; return (C) this; } diff --git a/src/main/java/spoon/support/reflect/code/CtReturnImpl.java b/src/main/java/spoon/support/reflect/code/CtReturnImpl.java index d4668c30f31..14b8d4ae598 100644 --- a/src/main/java/spoon/support/reflect/code/CtReturnImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtReturnImpl.java @@ -16,13 +16,15 @@ */ package spoon.support.reflect.code; +import spoon.diff.UpdateAction; +import spoon.diff.context.ObjectContext; +import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.code.CtCodeElement; import spoon.reflect.code.CtExpression; import spoon.reflect.code.CtReturn; import spoon.reflect.declaration.CtType; import spoon.reflect.path.CtRole; import spoon.reflect.visitor.CtVisitor; -import spoon.reflect.annotations.MetamodelPropertyField; public class CtReturnImpl extends CtStatementImpl implements CtReturn { private static final long serialVersionUID = 1L; @@ -45,6 +47,9 @@ public > T setReturnedExpression(CtExpression expressio if (expression != null) { expression.setParent(this); } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "returnedExpression"), expression, this.returnedExpression)); + } this.returnedExpression = expression; return (T) this; } diff --git a/src/main/java/spoon/support/reflect/code/CtStatementImpl.java b/src/main/java/spoon/support/reflect/code/CtStatementImpl.java index 57e32d0f63a..e9b6a7f8d39 100644 --- a/src/main/java/spoon/support/reflect/code/CtStatementImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtStatementImpl.java @@ -17,6 +17,9 @@ package spoon.support.reflect.code; import spoon.SpoonException; +import spoon.diff.UpdateAction; +import spoon.diff.context.ObjectContext; +import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.code.CtBlock; import spoon.reflect.code.CtCase; import spoon.reflect.code.CtIf; @@ -32,7 +35,6 @@ import spoon.reflect.path.CtRole; import spoon.reflect.reference.CtExecutableReference; import spoon.reflect.visitor.CtInheritanceScanner; -import spoon.reflect.annotations.MetamodelPropertyField; import java.util.ArrayList; import java.util.List; @@ -272,6 +274,9 @@ public String getLabel() { @Override public T setLabel(String label) { + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "label"), label, this.label)); + } this.label = label; return (T) this; } diff --git a/src/main/java/spoon/support/reflect/code/CtStatementListImpl.java b/src/main/java/spoon/support/reflect/code/CtStatementListImpl.java index 67e1c90e099..d962daa231b 100644 --- a/src/main/java/spoon/support/reflect/code/CtStatementListImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtStatementListImpl.java @@ -16,6 +16,11 @@ */ package spoon.support.reflect.code; +import spoon.diff.AddAction; +import spoon.diff.DeleteAction; +import spoon.diff.DeleteAllAction; +import spoon.diff.context.ListContext; +import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.code.CtStatement; import spoon.reflect.code.CtStatementList; import spoon.reflect.cu.SourcePosition; @@ -23,7 +28,6 @@ import spoon.reflect.declaration.CtType; import spoon.reflect.path.CtRole; import spoon.reflect.visitor.CtVisitor; -import spoon.reflect.annotations.MetamodelPropertyField; import spoon.support.reflect.declaration.CtElementImpl; import java.util.ArrayList; @@ -54,6 +58,10 @@ public T setStatements(List stmts) { this.statements = CtElementImpl.emptyList(); return (T) this; } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new DeleteAllAction(new ListContext( + this, this.statements), new ArrayList<>(this.statements))); + } this.statements.clear(); for (CtStatement stmt : stmts) { addStatement(stmt); @@ -70,15 +78,24 @@ public T addStatement(CtStatement statement) { this.statements = new ArrayList<>(BLOCK_STATEMENTS_CONTAINER_DEFAULT_CAPACITY); } statement.setParent(this); + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new AddAction(new ListContext( + this, this.statements), statement)); + } this.statements.add(statement); return (T) this; } @Override public void removeStatement(CtStatement statement) { - if (this.statements != CtElementImpl.emptyList()) { - this.statements.remove(statement); + if (this.statements == CtElementImpl.emptyList()) { + return ; + } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new DeleteAction(new ListContext( + this, statements, statements.indexOf(statement)), statement)); } + statements.remove(statement); } @Override diff --git a/src/main/java/spoon/support/reflect/code/CtSuperAccessImpl.java b/src/main/java/spoon/support/reflect/code/CtSuperAccessImpl.java index 2e094ba76bf..9e8098470bc 100644 --- a/src/main/java/spoon/support/reflect/code/CtSuperAccessImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtSuperAccessImpl.java @@ -16,12 +16,14 @@ */ package spoon.support.reflect.code; +import spoon.diff.UpdateAction; +import spoon.diff.context.ObjectContext; +import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.code.CtExpression; import spoon.reflect.code.CtSuperAccess; import spoon.reflect.code.CtTargetedExpression; import spoon.reflect.path.CtRole; import spoon.reflect.visitor.CtVisitor; -import spoon.reflect.annotations.MetamodelPropertyField; public class CtSuperAccessImpl extends CtVariableReadImpl implements CtSuperAccess { @@ -45,6 +47,9 @@ public >> C setTarget(CtExpres if (target != null) { target.setParent(this); } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "target"), target, this.target)); + } this.target = target; return null; } diff --git a/src/main/java/spoon/support/reflect/code/CtSwitchImpl.java b/src/main/java/spoon/support/reflect/code/CtSwitchImpl.java index 5bc2395843a..6476868f80a 100644 --- a/src/main/java/spoon/support/reflect/code/CtSwitchImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtSwitchImpl.java @@ -16,12 +16,18 @@ */ package spoon.support.reflect.code; +import spoon.diff.AddAction; +import spoon.diff.DeleteAction; +import spoon.diff.DeleteAllAction; +import spoon.diff.UpdateAction; +import spoon.diff.context.ListContext; +import spoon.diff.context.ObjectContext; +import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.code.CtCase; import spoon.reflect.code.CtExpression; import spoon.reflect.code.CtSwitch; import spoon.reflect.path.CtRole; import spoon.reflect.visitor.CtVisitor; -import spoon.reflect.annotations.MetamodelPropertyField; import spoon.support.reflect.declaration.CtElementImpl; import java.util.ArrayList; @@ -59,6 +65,10 @@ public > T setCases(List> cases) { this.cases = CtElementImpl.emptyList(); return (T) this; } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new DeleteAllAction(new ListContext( + this, this.cases), new ArrayList<>(this.cases))); + } this.cases.clear(); for (CtCase aCase : cases) { addCase(aCase); @@ -71,6 +81,9 @@ public > T setSelector(CtExpression selector) { if (selector != null) { selector.setParent(this); } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "expression"), selector, this.expression)); + } this.expression = selector; return (T) this; } @@ -84,13 +97,24 @@ public > T addCase(CtCase c) { cases = new ArrayList<>(SWITCH_CASES_CONTAINER_DEFAULT_CAPACITY); } c.setParent(this); + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new AddAction(new ListContext( + this, this.cases), c)); + } cases.add(c); return (T) this; } @Override public boolean removeCase(CtCase c) { - return cases != CtElementImpl.>emptyList() && cases.remove(c); + if (cases == CtElementImpl.>emptyList()) { + return false; + } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new DeleteAction(new ListContext( + this, cases, cases.indexOf(c)), c)); + } + return cases.remove(c); } @Override diff --git a/src/main/java/spoon/support/reflect/code/CtSynchronizedImpl.java b/src/main/java/spoon/support/reflect/code/CtSynchronizedImpl.java index e6f9b9691c9..e54cc277988 100644 --- a/src/main/java/spoon/support/reflect/code/CtSynchronizedImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtSynchronizedImpl.java @@ -16,12 +16,14 @@ */ package spoon.support.reflect.code; +import spoon.diff.UpdateAction; +import spoon.diff.context.ObjectContext; +import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.code.CtBlock; import spoon.reflect.code.CtExpression; import spoon.reflect.code.CtSynchronized; import spoon.reflect.path.CtRole; import spoon.reflect.visitor.CtVisitor; -import spoon.reflect.annotations.MetamodelPropertyField; public class CtSynchronizedImpl extends CtStatementImpl implements CtSynchronized { private static final long serialVersionUID = 1L; @@ -52,6 +54,9 @@ public T setBlock(CtBlock block) { if (block != null) { block.setParent(this); } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "block"), block, this.block)); + } this.block = block; return (T) this; } @@ -61,6 +66,9 @@ public T setExpression(CtExpression expression) { if (expression != null) { expression.setParent(this); } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "expression"), expression, this.expression)); + } this.expression = expression; return (T) this; } diff --git a/src/main/java/spoon/support/reflect/code/CtTargetedExpressionImpl.java b/src/main/java/spoon/support/reflect/code/CtTargetedExpressionImpl.java index fb0dd1a2666..17c10344b00 100644 --- a/src/main/java/spoon/support/reflect/code/CtTargetedExpressionImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtTargetedExpressionImpl.java @@ -16,10 +16,12 @@ */ package spoon.support.reflect.code; +import spoon.diff.UpdateAction; +import spoon.diff.context.ObjectContext; +import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.code.CtExpression; import spoon.reflect.code.CtTargetedExpression; import spoon.reflect.path.CtRole; -import spoon.reflect.annotations.MetamodelPropertyField; public abstract class CtTargetedExpressionImpl> extends CtExpressionImpl implements CtTargetedExpression { private static final long serialVersionUID = 1L; @@ -37,6 +39,9 @@ public > C setTarget(T target) { if (target != null) { target.setParent(this); } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "target"), target, this.target)); + } this.target = target; return (C) this; } diff --git a/src/main/java/spoon/support/reflect/code/CtThrowImpl.java b/src/main/java/spoon/support/reflect/code/CtThrowImpl.java index 2f85845f1b8..375a6684ceb 100644 --- a/src/main/java/spoon/support/reflect/code/CtThrowImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtThrowImpl.java @@ -16,13 +16,15 @@ */ package spoon.support.reflect.code; +import spoon.diff.UpdateAction; +import spoon.diff.context.ObjectContext; +import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.code.CtCodeElement; import spoon.reflect.code.CtExpression; import spoon.reflect.code.CtThrow; import spoon.reflect.declaration.CtType; import spoon.reflect.path.CtRole; import spoon.reflect.visitor.CtVisitor; -import spoon.reflect.annotations.MetamodelPropertyField; public class CtThrowImpl extends CtStatementImpl implements CtThrow { private static final long serialVersionUID = 1L; @@ -45,6 +47,9 @@ public T setThrownExpression(CtExpression T setCatchers(List catchers) { this.catchers = CtElementImpl.emptyList(); return (T) this; } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new DeleteAllAction(new ListContext( + this, this.catchers), new ArrayList<>(this.catchers))); + } this.catchers.clear(); for (CtCatch c : catchers) { addCatcher(c); @@ -77,13 +87,24 @@ public T addCatcher(CtCatch catcher) { catchers = new ArrayList<>(CATCH_CASES_CONTAINER_DEFAULT_CAPACITY); } catcher.setParent(this); + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new AddAction(new ListContext( + this, this.catchers), catcher)); + } catchers.add(catcher); return (T) this; } @Override public boolean removeCatcher(CtCatch catcher) { - return catchers != CtElementImpl.emptyList() && catchers.remove(catcher); + if (catchers == CtElementImpl.emptyList()) { + return false; + } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new DeleteAction(new ListContext( + this, catchers, catchers.indexOf(catcher)), catcher)); + } + return catchers.remove(catcher); } @Override @@ -96,6 +117,9 @@ public T setFinalizer(CtBlock finalizer) { if (finalizer != null) { finalizer.setParent(this); } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "finalizer"), finalizer, this.finalizer)); + } this.finalizer = finalizer; return (T) this; } @@ -109,11 +133,17 @@ public CtBlock getBody() { public T setBody(CtStatement statement) { if (statement != null) { CtBlock body = getFactory().Code().getOrCreateCtBlock(statement); + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "body"), body, this.body)); + } if (body != null) { body.setParent(this); } this.body = body; } else { + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new DeleteAction(new ObjectContext(this, "body"), this.body)); + } this.body = null; } diff --git a/src/main/java/spoon/support/reflect/code/CtTryWithResourceImpl.java b/src/main/java/spoon/support/reflect/code/CtTryWithResourceImpl.java index 74d4ca0f9a6..39dea93d430 100644 --- a/src/main/java/spoon/support/reflect/code/CtTryWithResourceImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtTryWithResourceImpl.java @@ -16,11 +16,15 @@ */ package spoon.support.reflect.code; +import spoon.diff.AddAction; +import spoon.diff.DeleteAction; +import spoon.diff.DeleteAllAction; +import spoon.diff.context.ListContext; +import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.code.CtLocalVariable; import spoon.reflect.code.CtTryWithResource; import spoon.reflect.path.CtRole; import spoon.reflect.visitor.CtVisitor; -import spoon.reflect.annotations.MetamodelPropertyField; import spoon.support.reflect.declaration.CtElementImpl; import java.util.ArrayList; @@ -50,6 +54,10 @@ public T setResources(List> res this.resources = CtElementImpl.emptyList(); return (T) this; } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new DeleteAllAction(new ListContext( + this, this.resources), new ArrayList<>(this.resources))); + } this.resources.clear(); for (CtLocalVariable l : resources) { addResource(l); @@ -66,13 +74,24 @@ public T addResource(CtLocalVariable resource) resources = new ArrayList<>(RESOURCES_CONTAINER_DEFAULT_CAPACITY); } resource.setParent(this); + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new AddAction(new ListContext( + this, this.resources), resource)); + } resources.add(resource); return (T) this; } @Override public boolean removeResource(CtLocalVariable resource) { - return resources != CtElementImpl.>emptyList() && resources.remove(resource); + if (resources == CtElementImpl.>emptyList()) { + return false; + } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new DeleteAction(new ListContext( + this, resources, resources.indexOf(resource)), resource)); + } + return resources.remove(resource); } @Override diff --git a/src/main/java/spoon/support/reflect/code/CtTypeAccessImpl.java b/src/main/java/spoon/support/reflect/code/CtTypeAccessImpl.java index 23049eea7d9..69661fcc976 100644 --- a/src/main/java/spoon/support/reflect/code/CtTypeAccessImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtTypeAccessImpl.java @@ -16,12 +16,14 @@ */ package spoon.support.reflect.code; +import spoon.diff.UpdateAction; +import spoon.diff.context.ObjectContext; +import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.code.CtTypeAccess; import spoon.reflect.declaration.CtTypedElement; import spoon.reflect.path.CtRole; import spoon.reflect.reference.CtTypeReference; import spoon.reflect.visitor.CtVisitor; -import spoon.reflect.annotations.MetamodelPropertyField; import spoon.support.UnsettableProperty; public class CtTypeAccessImpl extends CtExpressionImpl implements CtTypeAccess { @@ -44,6 +46,9 @@ public > C setAccessedType(CtTypeReference accessed if (accessedType != null) { accessedType.setParent(this); } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "type"), accessedType, this.type)); + } type = accessedType; return (C) this; } diff --git a/src/main/java/spoon/support/reflect/code/CtUnaryOperatorImpl.java b/src/main/java/spoon/support/reflect/code/CtUnaryOperatorImpl.java index a8714e40cc7..1335e29f8a7 100644 --- a/src/main/java/spoon/support/reflect/code/CtUnaryOperatorImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtUnaryOperatorImpl.java @@ -16,6 +16,9 @@ */ package spoon.support.reflect.code; +import spoon.diff.UpdateAction; +import spoon.diff.context.ObjectContext; +import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.code.CtExpression; import spoon.reflect.code.CtStatement; import spoon.reflect.code.CtStatementList; @@ -24,7 +27,6 @@ import spoon.reflect.declaration.CtElement; import spoon.reflect.path.CtRole; import spoon.reflect.visitor.CtVisitor; -import spoon.reflect.annotations.MetamodelPropertyField; public class CtUnaryOperatorImpl extends CtExpressionImpl implements CtUnaryOperator { private static final long serialVersionUID = 1L; @@ -87,18 +89,27 @@ public C setOperand(CtExpression expression) { if (expression != null) { expression.setParent(this); } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "operand"), expression, this.operand)); + } this.operand = expression; return (C) this; } @Override public C setKind(UnaryOperatorKind kind) { + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "kind"), kind, this.kind)); + } this.kind = kind; return (C) this; } @Override public C setLabel(String label) { + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "label"), label, this.label)); + } this.label = label; return (C) this; } diff --git a/src/main/java/spoon/support/reflect/code/CtVariableAccessImpl.java b/src/main/java/spoon/support/reflect/code/CtVariableAccessImpl.java index f6af9c81390..9e853ea5ae0 100644 --- a/src/main/java/spoon/support/reflect/code/CtVariableAccessImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtVariableAccessImpl.java @@ -16,13 +16,15 @@ */ package spoon.support.reflect.code; +import spoon.diff.UpdateAction; +import spoon.diff.context.ObjectContext; +import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.code.CtVariableAccess; import spoon.reflect.declaration.CtTypedElement; import spoon.reflect.path.CtRole; import spoon.reflect.reference.CtTypeReference; import spoon.reflect.reference.CtVariableReference; import spoon.support.DerivedProperty; -import spoon.reflect.annotations.MetamodelPropertyField; public abstract class CtVariableAccessImpl extends CtExpressionImpl implements CtVariableAccess { private static final long serialVersionUID = 1L; @@ -48,6 +50,9 @@ public > C setVariable(CtVariableReference vari if (variable != null) { variable.setParent(this); } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "variable"), variable, this.variable)); + } this.variable = variable; return (C) this; } @@ -59,6 +64,7 @@ public CtTypeReference getType() { } @Override + @DerivedProperty public C setType(CtTypeReference type) { if (type != null) { type.setParent(this); diff --git a/src/main/java/spoon/support/reflect/code/CtWhileImpl.java b/src/main/java/spoon/support/reflect/code/CtWhileImpl.java index 2bc0404c631..fa4ff2d2da4 100644 --- a/src/main/java/spoon/support/reflect/code/CtWhileImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtWhileImpl.java @@ -16,11 +16,13 @@ */ package spoon.support.reflect.code; +import spoon.diff.UpdateAction; +import spoon.diff.context.ObjectContext; +import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.code.CtExpression; import spoon.reflect.code.CtWhile; import spoon.reflect.path.CtRole; import spoon.reflect.visitor.CtVisitor; -import spoon.reflect.annotations.MetamodelPropertyField; public class CtWhileImpl extends CtLoopImpl implements CtWhile { private static final long serialVersionUID = 1L; @@ -43,6 +45,9 @@ public T setLoopingExpression(CtExpression expressi if (expression != null) { expression.setParent(this); } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "expression"), expression, this.expression)); + } this.expression = expression; return (T) this; } diff --git a/src/main/java/spoon/support/reflect/declaration/CtAnnotationImpl.java b/src/main/java/spoon/support/reflect/declaration/CtAnnotationImpl.java index 1f22e6d5ced..51bd8d376aa 100644 --- a/src/main/java/spoon/support/reflect/declaration/CtAnnotationImpl.java +++ b/src/main/java/spoon/support/reflect/declaration/CtAnnotationImpl.java @@ -18,6 +18,12 @@ import spoon.Launcher; import spoon.SpoonException; +import spoon.diff.AddAction; +import spoon.diff.DeleteAllAction; +import spoon.diff.UpdateAction; +import spoon.diff.context.MapContext; +import spoon.diff.context.ObjectContext; +import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.code.CtCodeElement; import spoon.reflect.code.CtExpression; import spoon.reflect.code.CtFieldAccess; @@ -44,7 +50,6 @@ import spoon.reflect.reference.CtTypeParameterReference; import spoon.reflect.reference.CtTypeReference; import spoon.reflect.visitor.CtVisitor; -import spoon.reflect.annotations.MetamodelPropertyField; import spoon.support.comparator.CtLineElementComparator; import spoon.support.reflect.code.CtExpressionImpl; @@ -57,6 +62,7 @@ import java.util.Collection; import java.util.Collections; import java.util.Comparator; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -187,8 +193,11 @@ private > T addValueExpression(String elementName, CtE } } else { // Add the new value. - elementValues.put(elementName, expression); expression.setParent(this); + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new AddAction(new MapContext(this, this.elementValues, elementName), expression)); + } + elementValues.put(elementName, expression); } return (T) this; } @@ -383,12 +392,19 @@ public > T setAnnotationType(CtTypeReference) annotationType; return (T) this; } @Override public > T setElementValues(Map values) { + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new DeleteAllAction(new MapContext( + this, this.elementValues), new HashMap<>(elementValues))); + } this.elementValues.clear(); for (Entry e : values.entrySet()) { addValue(e.getKey(), e.getValue()); @@ -398,6 +414,10 @@ public > T setElementValues(Map values @Override public > T setValues(Map values) { + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new DeleteAllAction(new MapContext( + this, this.elementValues), new HashMap<>(elementValues))); + } this.elementValues.clear(); for (Entry e : values.entrySet()) { addValue(e.getKey(), e.getValue()); @@ -493,6 +513,9 @@ public boolean isShadow() { @Override public E setShadow(boolean isShadow) { + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "isShadow"), isShadow, this.isShadow)); + } this.isShadow = isShadow; return (E) this; } diff --git a/src/main/java/spoon/support/reflect/declaration/CtAnnotationMethodImpl.java b/src/main/java/spoon/support/reflect/declaration/CtAnnotationMethodImpl.java index 18b418b4805..9f92907296a 100644 --- a/src/main/java/spoon/support/reflect/declaration/CtAnnotationMethodImpl.java +++ b/src/main/java/spoon/support/reflect/declaration/CtAnnotationMethodImpl.java @@ -16,11 +16,13 @@ */ package spoon.support.reflect.declaration; +import spoon.diff.UpdateAction; +import spoon.diff.context.ObjectContext; +import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.code.CtExpression; import spoon.reflect.declaration.CtAnnotationMethod; import spoon.reflect.path.CtRole; import spoon.reflect.visitor.CtVisitor; -import spoon.reflect.annotations.MetamodelPropertyField; /** * The implementation for {@link spoon.reflect.declaration.CtAnnotationMethod}. @@ -44,6 +46,9 @@ public > C setDefaultExpression(CtExpression if (assignedExpression != null) { assignedExpression.setParent(this); } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "defaultExpression"), assignedExpression, this.defaultExpression)); + } this.defaultExpression = assignedExpression; return (C) this; } diff --git a/src/main/java/spoon/support/reflect/declaration/CtAnonymousExecutableImpl.java b/src/main/java/spoon/support/reflect/declaration/CtAnonymousExecutableImpl.java index 4ed9f2bf4eb..a72d8d95fd5 100644 --- a/src/main/java/spoon/support/reflect/declaration/CtAnonymousExecutableImpl.java +++ b/src/main/java/spoon/support/reflect/declaration/CtAnonymousExecutableImpl.java @@ -16,6 +16,11 @@ */ package spoon.support.reflect.declaration; +import spoon.diff.AddAction; +import spoon.diff.DeleteAction; +import spoon.diff.DeleteAllAction; +import spoon.diff.context.SetContext; +import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.declaration.CtAnonymousExecutable; import spoon.reflect.declaration.CtExecutable; import spoon.reflect.declaration.CtModifiable; @@ -26,10 +31,10 @@ import spoon.reflect.path.CtRole; import spoon.reflect.reference.CtTypeReference; import spoon.reflect.visitor.CtVisitor; -import spoon.reflect.annotations.MetamodelPropertyField; import spoon.support.UnsettableProperty; import java.util.EnumSet; +import java.util.HashSet; import java.util.List; import java.util.Set; @@ -49,13 +54,23 @@ public T addModifier(ModifierKind modifier) { if (modifiers == CtElementImpl.emptySet()) { modifiers = EnumSet.noneOf(ModifierKind.class); } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new AddAction(new SetContext(this, this.modifiers), modifier)); + } modifiers.add(modifier); return (T) this; } @Override public boolean removeModifier(ModifierKind modifier) { - return !modifiers.isEmpty() && modifiers.remove(modifier); + if (modifiers == CtElementImpl.emptySet()) { + return false; + } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new DeleteAction(new SetContext( + this, modifiers), modifier)); + } + return modifiers.remove(modifier); } @Override @@ -85,7 +100,13 @@ public boolean hasModifier(ModifierKind modifier) { @Override public T setModifiers(Set modifiers) { if (modifiers.size() > 0) { - this.modifiers = EnumSet.copyOf(modifiers); + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new DeleteAllAction(new SetContext(this, this.modifiers), new HashSet<>(this.modifiers))); + } + this.modifiers.clear(); + for (ModifierKind modifier : modifiers) { + addModifier(modifier); + } } return (T) this; } diff --git a/src/main/java/spoon/support/reflect/declaration/CtClassImpl.java b/src/main/java/spoon/support/reflect/declaration/CtClassImpl.java index 97f71a9e7f2..828e818d958 100644 --- a/src/main/java/spoon/support/reflect/declaration/CtClassImpl.java +++ b/src/main/java/spoon/support/reflect/declaration/CtClassImpl.java @@ -24,7 +24,7 @@ import spoon.diff.UpdateAction; import spoon.diff.context.ListContext; import spoon.diff.context.ObjectContext; -import spoon.diff.context.SetContext; +import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.code.CtCodeElement; import spoon.reflect.code.CtStatement; import spoon.reflect.code.CtStatementList; @@ -39,7 +39,6 @@ import spoon.reflect.reference.CtExecutableReference; import spoon.reflect.reference.CtTypeReference; import spoon.reflect.visitor.CtVisitor; -import spoon.reflect.annotations.MetamodelPropertyField; import spoon.support.UnsettableProperty; import spoon.support.compiler.jdt.JDTBasedSpoonCompiler; import spoon.support.reflect.code.CtStatementImpl; @@ -53,7 +52,6 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; -import java.util.HashSet; import java.util.List; import java.util.Set; @@ -122,8 +120,7 @@ public > C addAnonymousExecutable(CtAnonymousExecutable e) } e.setParent(this); if (getFactory().getEnvironment().buildStackChanges()) { - List anonymousExecutables = getAnonymousExecutables(); - getFactory().getEnvironment().pushToStack(new AddAction(new ListContext(anonymousExecutables, anonymousExecutables.size()), e)); + getFactory().getEnvironment().pushToStack(new AddAction(new ListContext(this, typeMembers), e)); } return addTypeMember(e); } @@ -131,8 +128,7 @@ public > C addAnonymousExecutable(CtAnonymousExecutable e) @Override public boolean removeAnonymousExecutable(CtAnonymousExecutable e) { if (getFactory().getEnvironment().buildStackChanges()) { - List anonymousExecutables = getAnonymousExecutables(); - getFactory().getEnvironment().pushToStack(new DeleteAction(new ListContext(anonymousExecutables, anonymousExecutables.indexOf(e)), e)); + getFactory().getEnvironment().pushToStack(new DeleteAction(new ListContext(this, typeMembers, typeMembers.indexOf(e)), e)); } return removeTypeMember(e); } @@ -145,7 +141,7 @@ public CtTypeReference getSuperclass() { @Override public > C setAnonymousExecutables(List anonymousExecutables) { if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new DeleteAllAction(new ListContext(typeMembers), new ArrayList<>(getAnonymousExecutables()))); + getFactory().getEnvironment().pushToStack(new DeleteAllAction(new ListContext(this, typeMembers), new ArrayList<>(getAnonymousExecutables()))); } if (anonymousExecutables == null || anonymousExecutables.isEmpty()) { this.typeMembers.removeAll(getAnonymousExecutables()); @@ -162,7 +158,9 @@ public > C setAnonymousExecutables(List> C setConstructors(Set> constructors) { Set> oldConstructor = getConstructors(); if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new DeleteAllAction(new ListContext(typeMembers), new HashSet<>(oldConstructor))); + for (CtConstructor constructor : oldConstructor) { + getFactory().getEnvironment().pushToStack(new DeleteAction(new ListContext(this, typeMembers), constructor)); + } } if (constructors == null || constructors.isEmpty()) { this.typeMembers.removeAll(oldConstructor); @@ -178,7 +176,7 @@ public > C setConstructors(Set> constructo @Override public > C addConstructor(CtConstructor constructor) { if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new AddAction(new ListContext(typeMembers), constructor)); + getFactory().getEnvironment().pushToStack(new AddAction(new ListContext(this, typeMembers), constructor)); } return addTypeMember(constructor); } diff --git a/src/main/java/spoon/support/reflect/declaration/CtConstructorImpl.java b/src/main/java/spoon/support/reflect/declaration/CtConstructorImpl.java index ba127a9fc2e..3e4835acc31 100644 --- a/src/main/java/spoon/support/reflect/declaration/CtConstructorImpl.java +++ b/src/main/java/spoon/support/reflect/declaration/CtConstructorImpl.java @@ -16,6 +16,14 @@ */ package spoon.support.reflect.declaration; +import spoon.diff.AddAction; +import spoon.diff.DeleteAction; +import spoon.diff.DeleteAllAction; +import spoon.diff.UpdateAction; +import spoon.diff.context.ListContext; +import spoon.diff.context.ObjectContext; +import spoon.diff.context.SetContext; +import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.declaration.CtConstructor; import spoon.reflect.declaration.CtFormalTypeDeclarer; import spoon.reflect.declaration.CtModifiable; @@ -30,11 +38,11 @@ import spoon.reflect.reference.CtTypeReference; import spoon.reflect.visitor.CtVisitor; import spoon.support.DerivedProperty; -import spoon.reflect.annotations.MetamodelPropertyField; import spoon.support.UnsettableProperty; import java.util.ArrayList; import java.util.EnumSet; +import java.util.HashSet; import java.util.List; import java.util.Set; @@ -101,6 +109,9 @@ public C setFormalCtTypeParameters(ListemptyList()) { this.formalCtTypeParameters = new ArrayList<>(TYPE_TYPE_PARAMETERS_CONTAINER_DEFAULT_CAPACITY); } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new DeleteAllAction(new ListContext(this, this.formalCtTypeParameters), new ArrayList<>(this.formalCtTypeParameters))); + } this.formalCtTypeParameters.clear(); for (CtTypeParameter formalTypeParameter : formalTypeParameters) { addFormalCtTypeParameter(formalTypeParameter); @@ -113,6 +124,9 @@ public C addFormalCtTypeParameter(CtTypeParamet if (formalTypeParameter == null) { return (C) this; } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new AddAction(new ListContext(this, this.formalCtTypeParameters), formalTypeParameter)); + } if (formalCtTypeParameters == CtElementImpl.emptyList()) { formalCtTypeParameters = new ArrayList<>(TYPE_TYPE_PARAMETERS_CONTAINER_DEFAULT_CAPACITY); } @@ -123,7 +137,14 @@ public C addFormalCtTypeParameter(CtTypeParamet @Override public boolean removeFormalCtTypeParameter(CtTypeParameter formalTypeParameter) { - return formalCtTypeParameters.contains(formalTypeParameter) && formalCtTypeParameters.remove(formalTypeParameter); + if (!formalCtTypeParameters.contains(formalTypeParameter)) { + return false; + } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new DeleteAction(new ListContext( + this, formalCtTypeParameters, formalCtTypeParameters.indexOf(formalTypeParameter)), formalTypeParameter)); + } + return formalCtTypeParameters.remove(formalTypeParameter); } @Override @@ -139,7 +160,13 @@ public boolean hasModifier(ModifierKind modifier) { @Override public C setModifiers(Set modifiers) { if (modifiers.size() > 0) { - this.modifiers = EnumSet.copyOf(modifiers); + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new DeleteAllAction(new SetContext(this, this.modifiers), new HashSet<>(this.modifiers))); + } + this.modifiers.clear(); + for (ModifierKind modifier : modifiers) { + addModifier(modifier); + } } return (C) this; } @@ -149,13 +176,22 @@ public C addModifier(ModifierKind modifier) { if (modifiers == CtElementImpl.emptySet()) { this.modifiers = EnumSet.noneOf(ModifierKind.class); } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new AddAction(new SetContext(this, this.modifiers), modifier)); + } modifiers.add(modifier); return (C) this; } @Override public boolean removeModifier(ModifierKind modifier) { - return !modifiers.isEmpty() && modifiers.remove(modifier); + if (modifiers == CtElementImpl.emptySet()) { + return false; + } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new DeleteAction(new SetContext(this, modifiers), modifier)); + } + return modifiers.remove(modifier); } @Override @@ -194,6 +230,9 @@ public boolean isShadow() { @Override public E setShadow(boolean isShadow) { + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "isShadow"), isShadow, this.isShadow)); + } this.isShadow = isShadow; return (E) this; } diff --git a/src/main/java/spoon/support/reflect/declaration/CtElementImpl.java b/src/main/java/spoon/support/reflect/declaration/CtElementImpl.java index 7309907586f..1bc1f7411e8 100644 --- a/src/main/java/spoon/support/reflect/declaration/CtElementImpl.java +++ b/src/main/java/spoon/support/reflect/declaration/CtElementImpl.java @@ -17,6 +17,13 @@ package spoon.support.reflect.declaration; import org.apache.log4j.Logger; +import spoon.diff.AddAction; +import spoon.diff.DeleteAction; +import spoon.diff.DeleteAllAction; +import spoon.diff.UpdateAction; +import spoon.diff.context.ListContext; +import spoon.diff.context.ObjectContext; +import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.code.CtComment; import spoon.reflect.cu.SourcePosition; import spoon.reflect.declaration.CtAnnotation; @@ -36,7 +43,6 @@ import spoon.reflect.visitor.chain.CtFunction; import spoon.reflect.visitor.chain.CtQuery; import spoon.reflect.visitor.filter.AnnotationFilter; -import spoon.reflect.annotations.MetamodelPropertyField; import spoon.support.util.EmptyClearableList; import spoon.support.util.EmptyClearableSet; import spoon.support.visitor.HashcodeVisitor; @@ -169,6 +175,10 @@ public E setAnnotations(List(this.annotations))); + } this.annotations.clear(); for (CtAnnotation annot : annotations) { addAnnotation(annot); @@ -186,16 +196,27 @@ public E addAnnotation(CtAnnotation if (annotation == null) { return (E) this; } - if ((List) this.annotations == (List) emptyList()) { + if (this.annotations == CtElementImpl.>emptyList()) { this.annotations = new ArrayList<>(ANNOTATIONS_CONTAINER_DEFAULT_CAPACITY); } annotation.setParent(this); + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new AddAction(new ListContext( + this, this.annotations), annotation)); + } this.annotations.add(annotation); return (E) this; } public boolean removeAnnotation(CtAnnotation annotation) { - return (List) annotations != (List) emptyList() && this.annotations.remove(annotation); + if (this.annotations == CtElementImpl.>emptyList()) { + return false; + } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new DeleteAction(new ListContext( + this, annotations, annotations.indexOf(annotation)), annotation)); + } + return this.annotations.remove(annotation); } public E setDocComment(String docComment) { @@ -210,6 +231,9 @@ public E setDocComment(String docComment) { } public E setPosition(SourcePosition position) { + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "position"), position, this.position)); + } this.position = position; return (E) this; } @@ -253,6 +277,9 @@ public boolean isImplicit() { } public E setImplicit(boolean implicit) { + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "implicit"), implicit, this.implicit)); + } this.implicit = implicit; return (E) this; } @@ -304,6 +331,13 @@ public CtElement getParent() throws ParentNotInitializedException { @Override public E setParent(E parent) { + if (getFactory() == null) { + this.parent = parent; + return (E) this; + } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "parent"), parent, this.parent)); + } this.parent = parent; return (E) this; } @@ -417,19 +451,28 @@ public E addComment(CtComment comment) { if (comment == null) { return (E) this; } - if ((List) comments == emptyList()) { + if (this.comments == CtElementImpl.emptyList()) { comments = new ArrayList<>(COMMENT_CONTAINER_DEFAULT_CAPACITY); } - comments.add(comment); comment.setParent(this); + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new AddAction(new ListContext( + this, this.comments), comment)); + } + comments.add(comment); return (E) this; } @Override public E removeComment(CtComment comment) { - if ((List) comments != emptyList()) { - comments.remove(comment); + if (this.comments == CtElementImpl.emptyList()) { + return (E) this; } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new DeleteAction(new ListContext( + this, comments, comments.indexOf(comment)), comment)); + } + this.comments.remove(comment); return (E) this; } @@ -439,6 +482,10 @@ public E setComments(List comments) { this.comments = CtElementImpl.emptyList(); return (E) this; } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new DeleteAllAction(new ListContext( + this, this.comments), new ArrayList<>(this.comments))); + } this.comments.clear(); for (CtComment comment : comments) { addComment(comment); diff --git a/src/main/java/spoon/support/reflect/declaration/CtEnumImpl.java b/src/main/java/spoon/support/reflect/declaration/CtEnumImpl.java index ed643a39baf..331cab75377 100644 --- a/src/main/java/spoon/support/reflect/declaration/CtEnumImpl.java +++ b/src/main/java/spoon/support/reflect/declaration/CtEnumImpl.java @@ -16,6 +16,11 @@ */ package spoon.support.reflect.declaration; +import spoon.diff.AddAction; +import spoon.diff.DeleteAction; +import spoon.diff.DeleteAllAction; +import spoon.diff.context.ListContext; +import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.declaration.CtEnum; import spoon.reflect.declaration.CtEnumValue; import spoon.reflect.declaration.CtField; @@ -24,7 +29,6 @@ import spoon.reflect.path.CtRole; import spoon.reflect.reference.CtTypeReference; import spoon.reflect.visitor.CtVisitor; -import spoon.reflect.annotations.MetamodelPropertyField; import spoon.support.util.SignatureBasedSortedSet; import java.util.ArrayList; @@ -73,6 +77,10 @@ public > C addEnumValue(CtEnumValue enumValue) { } if (!enumValues.contains(enumValue)) { enumValue.setParent(this); + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new AddAction(new ListContext( + this, this.enumValues), enumValue)); + } enumValues.add(enumValue); } @@ -82,6 +90,13 @@ public > C addEnumValue(CtEnumValue enumValue) { @Override public boolean removeEnumValue(CtEnumValue enumValue) { + if (enumValues == CtElementImpl.>emptyList()) { + return false; + } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new DeleteAction(new ListContext( + this, enumValues, enumValues.indexOf(enumValue)), enumValue)); + } return enumValues.remove(enumValue); } @@ -102,6 +117,9 @@ public List> getEnumValues() { @Override public > C setEnumValues(List> enumValues) { + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new DeleteAllAction(new ListContext(this, this.enumValues), new ArrayList<>(enumValues))); + } if (enumValues == null || enumValues.isEmpty()) { this.enumValues = emptyList(); return (C) this; diff --git a/src/main/java/spoon/support/reflect/declaration/CtExecutableImpl.java b/src/main/java/spoon/support/reflect/declaration/CtExecutableImpl.java index 320cb5f649b..4a77278f327 100644 --- a/src/main/java/spoon/support/reflect/declaration/CtExecutableImpl.java +++ b/src/main/java/spoon/support/reflect/declaration/CtExecutableImpl.java @@ -16,6 +16,14 @@ */ package spoon.support.reflect.declaration; +import spoon.diff.AddAction; +import spoon.diff.DeleteAction; +import spoon.diff.DeleteAllAction; +import spoon.diff.UpdateAction; +import spoon.diff.context.ListContext; +import spoon.diff.context.ObjectContext; +import spoon.diff.context.SetContext; +import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.code.CtBlock; import spoon.reflect.code.CtBodyHolder; import spoon.reflect.code.CtStatement; @@ -25,11 +33,11 @@ import spoon.reflect.path.CtRole; import spoon.reflect.reference.CtExecutableReference; import spoon.reflect.reference.CtTypeReference; -import spoon.reflect.annotations.MetamodelPropertyField; import spoon.support.util.QualifiedNameBasedSortedSet; import spoon.support.visitor.SignaturePrinter; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; import java.util.Set; @@ -74,11 +82,17 @@ public CtBlock getBody() { public T setBody(CtStatement statement) { if (statement != null) { CtBlock body = getFactory().Code().getOrCreateCtBlock(statement); + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "body"), body, this.body)); + } if (body != null) { body.setParent(this); } this.body = body; } else { + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new DeleteAction(new ObjectContext(this, "body"), this.body)); + } this.body = null; } return (T) this; @@ -98,6 +112,10 @@ public > T setParameters(List> paramete if (this.parameters == CtElementImpl.>emptyList()) { this.parameters = new ArrayList<>(PARAMETERS_CONTAINER_DEFAULT_CAPACITY); } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new DeleteAllAction(new ListContext( + this, this.parameters), new ArrayList<>(this.parameters))); + } this.parameters.clear(); for (CtParameter p : parameters) { addParameter(p); @@ -114,13 +132,24 @@ public > T addParameter(CtParameter parameter) { parameters = new ArrayList<>(PARAMETERS_CONTAINER_DEFAULT_CAPACITY); } parameter.setParent(this); + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new AddAction(new ListContext( + this, this.parameters), parameter)); + } parameters.add(parameter); return (T) this; } @Override public boolean removeParameter(CtParameter parameter) { - return parameters != CtElementImpl.>emptyList() && parameters.remove(parameter); + if (parameters == CtElementImpl.>emptyList()) { + return false; + } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new DeleteAction(new ListContext( + this, parameters, parameters.indexOf(parameter)), parameter)); + } + return parameters.remove(parameter); } @Override @@ -137,6 +166,10 @@ public > T setThrownTypes(Set>emptySet()) { this.thrownTypes = new QualifiedNameBasedSortedSet<>(); } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new DeleteAllAction(new SetContext( + this, this.thrownTypes), new HashSet(this.thrownTypes))); + } this.thrownTypes.clear(); for (CtTypeReference thrownType : thrownTypes) { addThrownType(thrownType); @@ -153,12 +186,23 @@ public > T addThrownType(CtTypeReference(); } throwType.setParent(this); + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new AddAction(new SetContext( + this, this.thrownTypes), throwType)); + } thrownTypes.add(throwType); return (T) this; } @Override public boolean removeThrownType(CtTypeReference throwType) { + if (thrownTypes == CtElementImpl.>emptySet()) { + return false; + } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new DeleteAction(new SetContext( + this, thrownTypes), throwType)); + } return thrownTypes.remove(throwType); } diff --git a/src/main/java/spoon/support/reflect/declaration/CtFieldImpl.java b/src/main/java/spoon/support/reflect/declaration/CtFieldImpl.java index 412e0bfbe86..6a188b5b40e 100644 --- a/src/main/java/spoon/support/reflect/declaration/CtFieldImpl.java +++ b/src/main/java/spoon/support/reflect/declaration/CtFieldImpl.java @@ -16,6 +16,13 @@ */ package spoon.support.reflect.declaration; +import spoon.diff.AddAction; +import spoon.diff.DeleteAction; +import spoon.diff.DeleteAllAction; +import spoon.diff.UpdateAction; +import spoon.diff.context.ObjectContext; +import spoon.diff.context.SetContext; +import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.code.CtExpression; import spoon.reflect.code.CtRHSReceiver; import spoon.reflect.declaration.CtElement; @@ -30,10 +37,10 @@ import spoon.reflect.reference.CtFieldReference; import spoon.reflect.reference.CtTypeReference; import spoon.reflect.visitor.CtVisitor; -import spoon.reflect.annotations.MetamodelPropertyField; import spoon.support.UnsettableProperty; import java.util.EnumSet; +import java.util.HashSet; import java.util.Set; /** @@ -92,6 +99,9 @@ public > C setDefaultExpression(CtExpression defaultE if (defaultExpression != null) { defaultExpression.setParent(this); } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "defaultExpression"), defaultExpression, this.defaultExpression)); + } this.defaultExpression = defaultExpression; return (C) this; } @@ -101,6 +111,9 @@ public C setType(CtTypeReference type) { if (type != null) { type.setParent(this); } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "type"), type, this.type)); + } this.type = type; return (C) this; } @@ -118,7 +131,13 @@ public boolean hasModifier(ModifierKind modifier) { @Override public C setModifiers(Set modifiers) { if (modifiers.size() > 0) { - this.modifiers = EnumSet.copyOf(modifiers); + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new DeleteAllAction(new SetContext(this, this.modifiers), new HashSet<>(this.modifiers))); + } + this.modifiers.clear(); + for (ModifierKind modifier : modifiers) { + addModifier(modifier); + } } return (C) this; } @@ -128,13 +147,24 @@ public C addModifier(ModifierKind modifier) { if (modifiers == CtElementImpl.emptySet()) { this.modifiers = EnumSet.noneOf(ModifierKind.class); } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new AddAction(new SetContext( + this, this.modifiers), modifier)); + } modifiers.add(modifier); return (C) this; } @Override public boolean removeModifier(ModifierKind modifier) { - return !modifiers.isEmpty() && modifiers.remove(modifier); + if (modifiers == CtElementImpl.emptySet()) { + return false; + } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new DeleteAction(new SetContext( + this, modifiers), modifier)); + } + return modifiers.remove(modifier); } @Override @@ -190,6 +220,9 @@ public boolean isShadow() { @Override public E setShadow(boolean isShadow) { + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "isShadow"), isShadow, this.isShadow)); + } this.isShadow = isShadow; return (E) this; } diff --git a/src/main/java/spoon/support/reflect/declaration/CtMethodImpl.java b/src/main/java/spoon/support/reflect/declaration/CtMethodImpl.java index 7bcb3128296..7473f4471ff 100644 --- a/src/main/java/spoon/support/reflect/declaration/CtMethodImpl.java +++ b/src/main/java/spoon/support/reflect/declaration/CtMethodImpl.java @@ -16,6 +16,14 @@ */ package spoon.support.reflect.declaration; +import spoon.diff.AddAction; +import spoon.diff.DeleteAction; +import spoon.diff.DeleteAllAction; +import spoon.diff.UpdateAction; +import spoon.diff.context.ListContext; +import spoon.diff.context.ObjectContext; +import spoon.diff.context.SetContext; +import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.declaration.CtElement; import spoon.reflect.declaration.CtFormalTypeDeclarer; import spoon.reflect.declaration.CtMethod; @@ -27,11 +35,11 @@ import spoon.reflect.path.CtRole; import spoon.reflect.reference.CtTypeReference; import spoon.reflect.visitor.CtVisitor; -import spoon.reflect.annotations.MetamodelPropertyField; import spoon.support.visitor.ClassTypingContext; import java.util.ArrayList; import java.util.EnumSet; +import java.util.HashSet; import java.util.List; import java.util.Set; @@ -76,6 +84,9 @@ public C setType(CtTypeReference type) { if (type != null) { type.setParent(this); } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "returnType"), type, this.returnType)); + } this.returnType = type; return (C) this; } @@ -87,6 +98,9 @@ public boolean isDefaultMethod() { @Override public > C setDefaultMethod(boolean defaultMethod) { + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "defaultMethod"), defaultMethod, this.defaultMethod)); + } this.defaultMethod = defaultMethod; return (C) this; } @@ -98,6 +112,9 @@ public List getFormalCtTypeParameters() { @Override public C setFormalCtTypeParameters(List formalTypeParameters) { + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new DeleteAllAction(new ListContext(this, this.formalCtTypeParameters), new ArrayList<>(this.formalCtTypeParameters))); + } if (formalTypeParameters == null || formalTypeParameters.isEmpty()) { this.formalCtTypeParameters = CtElementImpl.emptyList(); return (C) this; @@ -120,6 +137,9 @@ public C addFormalCtTypeParameter(CtTypeParamet if (formalCtTypeParameters == CtElementImpl.emptyList()) { formalCtTypeParameters = new ArrayList<>(TYPE_TYPE_PARAMETERS_CONTAINER_DEFAULT_CAPACITY); } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new AddAction(new ListContext(this, this.formalCtTypeParameters), formalTypeParameter)); + } formalTypeParameter.setParent(this); formalCtTypeParameters.add(formalTypeParameter); return (C) this; @@ -127,7 +147,13 @@ public C addFormalCtTypeParameter(CtTypeParamet @Override public boolean removeFormalCtTypeParameter(CtTypeParameter formalTypeParameter) { - return formalCtTypeParameters.contains(formalTypeParameter) && formalCtTypeParameters.remove(formalTypeParameter); + if (formalCtTypeParameters == CtElementImpl.emptyList()) { + return false; + } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new DeleteAction(new ListContext(this, formalCtTypeParameters, formalCtTypeParameters.indexOf(formalTypeParameter)), formalTypeParameter)); + } + return formalCtTypeParameters.remove(formalTypeParameter); } @Override @@ -143,7 +169,13 @@ public boolean hasModifier(ModifierKind modifier) { @Override public C setModifiers(Set modifiers) { if (modifiers.size() > 0) { - this.modifiers = EnumSet.copyOf(modifiers); + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new DeleteAllAction(new SetContext(this, this.modifiers), new HashSet<>(this.modifiers))); + } + this.modifiers.clear(); + for (ModifierKind modifier : modifiers) { + addModifier(modifier); + } } return (C) this; } @@ -153,13 +185,24 @@ public C addModifier(ModifierKind modifier) { if (modifiers == CtElementImpl.emptySet()) { this.modifiers = EnumSet.noneOf(ModifierKind.class); } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new AddAction(new SetContext( + this, this.modifiers), modifier)); + } modifiers.add(modifier); return (C) this; } @Override public boolean removeModifier(ModifierKind modifier) { - return !modifiers.isEmpty() && modifiers.remove(modifier); + if (modifiers == CtElementImpl.emptySet()) { + return false; + } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new DeleteAction(new SetContext( + this, modifiers), modifier)); + } + return modifiers.remove(modifier); } @Override @@ -208,6 +251,9 @@ public boolean isShadow() { @Override public E setShadow(boolean isShadow) { + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "isShadow"), isShadow, this.isShadow)); + } this.isShadow = isShadow; return (E) this; } diff --git a/src/main/java/spoon/support/reflect/declaration/CtNamedElementImpl.java b/src/main/java/spoon/support/reflect/declaration/CtNamedElementImpl.java index acbea0be12a..8aeee28e620 100644 --- a/src/main/java/spoon/support/reflect/declaration/CtNamedElementImpl.java +++ b/src/main/java/spoon/support/reflect/declaration/CtNamedElementImpl.java @@ -16,12 +16,14 @@ */ package spoon.support.reflect.declaration; +import spoon.diff.UpdateAction; +import spoon.diff.context.ObjectContext; +import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.declaration.CtNamedElement; import spoon.reflect.factory.Factory; import spoon.reflect.factory.FactoryImpl; import spoon.reflect.path.CtRole; import spoon.reflect.reference.CtReference; -import spoon.reflect.annotations.MetamodelPropertyField; public abstract class CtNamedElementImpl extends CtElementImpl implements CtNamedElement { @@ -43,10 +45,16 @@ public String getSimpleName() { @Override public T setSimpleName(String simpleName) { Factory factory = getFactory(); + if (factory == null) { + this.simpleName = simpleName; + return (T) this; + } if (factory instanceof FactoryImpl) { simpleName = ((FactoryImpl) factory).dedup(simpleName); } - + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "simpleName"), simpleName, this.simpleName)); + } this.simpleName = simpleName; return (T) this; } diff --git a/src/main/java/spoon/support/reflect/declaration/CtPackageImpl.java b/src/main/java/spoon/support/reflect/declaration/CtPackageImpl.java index da1334b39ae..ab01a9ed807 100644 --- a/src/main/java/spoon/support/reflect/declaration/CtPackageImpl.java +++ b/src/main/java/spoon/support/reflect/declaration/CtPackageImpl.java @@ -16,6 +16,13 @@ */ package spoon.support.reflect.declaration; +import spoon.diff.AddAction; +import spoon.diff.DeleteAction; +import spoon.diff.DeleteAllAction; +import spoon.diff.UpdateAction; +import spoon.diff.context.ObjectContext; +import spoon.diff.context.SetContext; +import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.cu.SourcePosition; import spoon.reflect.declaration.CtPackage; import spoon.reflect.declaration.CtShadowable; @@ -24,11 +31,10 @@ import spoon.reflect.path.CtRole; import spoon.reflect.reference.CtPackageReference; import spoon.reflect.visitor.CtVisitor; -import spoon.reflect.annotations.MetamodelPropertyField; import spoon.support.util.QualifiedNameBasedSortedSet; +import java.util.HashSet; import java.util.Set; - /** * The implementation for {@link spoon.reflect.declaration.CtPackage}. * @@ -77,6 +83,10 @@ public T addPackage(CtPackage pack) { } pack.setParent(this); + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new AddAction(new SetContext( + this, this.packs), pack)); + } this.packs.add(pack); return (T) this; @@ -111,6 +121,13 @@ private void addAllPackages(CtPackage from, CtPackage to) { @Override public boolean removePackage(CtPackage pack) { + if (packs == CtElementImpl.emptySet()) { + return false; + } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new DeleteAction(new SetContext( + this, packs), pack)); + } return packs.remove(pack); } @@ -169,6 +186,10 @@ public T setPackages(Set packs) { this.packs = CtElementImpl.emptySet(); return (T) this; } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new DeleteAllAction(new SetContext( + this, this.packs), new HashSet<>(this.packs))); + } this.packs.clear(); for (CtPackage p : packs) { addPackage(p); @@ -182,6 +203,10 @@ public T setTypes(Set> types) { this.types = CtElementImpl.emptySet(); return (T) this; } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new DeleteAllAction(new SetContext( + this, this.types), new HashSet<>(this.types))); + } this.types.clear(); for (CtType t : types) { addType(t); @@ -203,13 +228,24 @@ public T addType(CtType type) { this.types = orderedTypeSet(); } type.setParent(this); + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new AddAction(new SetContext( + this, this.types), type)); + } types.add(type); return (T) this; } @Override - public void removeType(CtType type) { - types.remove(type); + public boolean removeType(CtType type) { + if (types == CtElementImpl.>emptySet()) { + return false; + } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new DeleteAction(new SetContext( + this, types), type)); + } + return types.remove(type); } @Override @@ -240,6 +276,9 @@ public boolean isShadow() { @Override public E setShadow(boolean isShadow) { + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "isShadow"), isShadow, this.isShadow)); + } this.isShadow = isShadow; return (E) this; } diff --git a/src/main/java/spoon/support/reflect/declaration/CtParameterImpl.java b/src/main/java/spoon/support/reflect/declaration/CtParameterImpl.java index d1f425046d8..ac4b376df96 100644 --- a/src/main/java/spoon/support/reflect/declaration/CtParameterImpl.java +++ b/src/main/java/spoon/support/reflect/declaration/CtParameterImpl.java @@ -16,6 +16,13 @@ */ package spoon.support.reflect.declaration; +import spoon.diff.AddAction; +import spoon.diff.DeleteAction; +import spoon.diff.DeleteAllAction; +import spoon.diff.UpdateAction; +import spoon.diff.context.ObjectContext; +import spoon.diff.context.SetContext; +import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.code.CtExpression; import spoon.reflect.declaration.CtExecutable; import spoon.reflect.declaration.CtModifiable; @@ -28,10 +35,10 @@ import spoon.reflect.reference.CtParameterReference; import spoon.reflect.reference.CtTypeReference; import spoon.reflect.visitor.CtVisitor; -import spoon.reflect.annotations.MetamodelPropertyField; import spoon.support.UnsettableProperty; import java.util.EnumSet; +import java.util.HashSet; import java.util.Set; /** @@ -87,6 +94,9 @@ public C setType(CtTypeReference type) { if (type != null) { type.setParent(this); } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "type"), type, this.type)); + } this.type = type; return (C) this; } @@ -98,6 +108,9 @@ public boolean isVarArgs() { @Override public > C setVarArgs(boolean varArgs) { + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "varArgs"), varArgs, this.varArgs)); + } this.varArgs = varArgs; return (C) this; } @@ -115,7 +128,13 @@ public boolean hasModifier(ModifierKind modifier) { @Override public C setModifiers(Set modifiers) { if (modifiers.size() > 0) { - this.modifiers = EnumSet.copyOf(modifiers); + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new DeleteAllAction(new SetContext(this, this.modifiers), new HashSet<>(this.modifiers))); + } + this.modifiers.clear(); + for (ModifierKind modifier : modifiers) { + addModifier(modifier); + } } return (C) this; } @@ -125,12 +144,23 @@ public C addModifier(ModifierKind modifier) { if (modifiers == CtElementImpl.emptySet()) { this.modifiers = EnumSet.noneOf(ModifierKind.class); } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new AddAction(new SetContext( + this, this.modifiers), modifier)); + } modifiers.add(modifier); return (C) this; } @Override public boolean removeModifier(ModifierKind modifier) { + if (modifiers == CtElementImpl.emptySet()) { + return false; + } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new DeleteAction(new SetContext( + this, modifiers), modifier)); + } return modifiers.remove(modifier); } @@ -175,6 +205,9 @@ public boolean isShadow() { @Override public E setShadow(boolean isShadow) { + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "isShadow"), isShadow, this.isShadow)); + } this.isShadow = isShadow; return (E) this; } diff --git a/src/main/java/spoon/support/reflect/declaration/CtTypeImpl.java b/src/main/java/spoon/support/reflect/declaration/CtTypeImpl.java index 70011464c2a..c2f3f3099db 100644 --- a/src/main/java/spoon/support/reflect/declaration/CtTypeImpl.java +++ b/src/main/java/spoon/support/reflect/declaration/CtTypeImpl.java @@ -17,6 +17,14 @@ package spoon.support.reflect.declaration; import spoon.SpoonException; +import spoon.diff.AddAction; +import spoon.diff.DeleteAction; +import spoon.diff.DeleteAllAction; +import spoon.diff.UpdateAction; +import spoon.diff.context.ListContext; +import spoon.diff.context.ObjectContext; +import spoon.diff.context.SetContext; +import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.code.CtBlock; import spoon.reflect.declaration.CtAnnotation; import spoon.reflect.declaration.CtAnnotationType; @@ -47,7 +55,6 @@ import spoon.reflect.visitor.filter.AllTypeMembersFunction; import spoon.reflect.visitor.filter.NameFilter; import spoon.reflect.visitor.filter.ReferenceTypeFilter; -import spoon.reflect.annotations.MetamodelPropertyField; import spoon.support.UnsettableProperty; import spoon.support.compiler.SnippetCompilationHelper; import spoon.support.util.QualifiedNameBasedSortedSet; @@ -91,6 +98,9 @@ public CtTypeImpl() { @Override public List getTypeMembers() { + if (getFactory().getEnvironment().buildStackChanges()) { + return Collections.unmodifiableList(typeMembers); + } return typeMembers; } @@ -112,6 +122,9 @@ public > C addTypeMemberAt(int position, CtTypeMember member } if (!this.typeMembers.contains(member)) { member.setParent(this); + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new AddAction(new ListContext(this, this.typeMembers, position), member)); + } this.typeMembers.add(position, member); } return (C) this; @@ -121,17 +134,29 @@ public > C addTypeMemberAt(int position, CtTypeMember member public boolean removeTypeMember(CtTypeMember member) { if (typeMembers.size() == 1) { if (typeMembers.contains(member)) { + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new DeleteAction(new ListContext(this, this.typeMembers, this.typeMembers.indexOf(member)), typeMembers)); + } typeMembers = emptyList(); return true; } else { return false; } } - return typeMembers.remove(member); + if (typeMembers.contains(member)) { + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new DeleteAction(new ListContext(this, this.typeMembers, this.typeMembers.indexOf(member)), typeMembers)); + } + return typeMembers.remove(member); + } + return false; } @Override public > C setTypeMembers(List members) { + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new DeleteAllAction(new ListContext(this, typeMembers), new ArrayList<>(typeMembers))); + } if (members == null || members.isEmpty()) { this.typeMembers = emptyList(); return (C) this; @@ -160,11 +185,15 @@ public > C addField(int index, CtField field) { @Override public > C setFields(List> fields) { + List> oldFields = getFields(); if (fields == null || fields.isEmpty()) { - this.typeMembers.removeAll(getFields()); + this.typeMembers.removeAll(oldFields); return (C) this; } - typeMembers.removeAll(getFields()); + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new DeleteAllAction(new ListContext(this, this.typeMembers), new ArrayList<>(oldFields))); + } + typeMembers.removeAll(oldFields); for (CtField field : fields) { addField(field); } @@ -222,11 +251,17 @@ public boolean removeNestedType(CtType nestedType) { @Override public > C setNestedTypes(Set> nestedTypes) { + Set> oldNestedTypes = getNestedTypes(); + if (getFactory().getEnvironment().buildStackChanges()) { + for (CtType oldNestedType : oldNestedTypes) { + getFactory().getEnvironment().pushToStack(new DeleteAction(new ListContext(this, typeMembers), oldNestedType)); + } + } if (nestedTypes == null || nestedTypes.isEmpty()) { - this.typeMembers.removeAll(getNestedTypes()); + this.typeMembers.removeAll(oldNestedTypes); return (C) this; } - typeMembers.removeAll(getNestedTypes()); + typeMembers.removeAll(oldNestedTypes); for (CtType nestedType : nestedTypes) { addNestedType(nestedType); } @@ -419,7 +454,13 @@ public boolean hasModifier(ModifierKind modifier) { @Override public C setModifiers(Set modifiers) { if (modifiers.size() > 0) { - this.modifiers = EnumSet.copyOf(modifiers); + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new DeleteAllAction(new SetContext(this, this.modifiers), new HashSet<>(this.modifiers))); + } + this.modifiers.clear(); + for (ModifierKind modifier : modifiers) { + addModifier(modifier); + } } return (C) this; } @@ -429,13 +470,24 @@ public C addModifier(ModifierKind modifier) { if (modifiers == CtElementImpl.emptySet()) { this.modifiers = EnumSet.of(modifier); } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new AddAction(new SetContext( + this, this.modifiers), modifier)); + } modifiers.add(modifier); return (C) this; } @Override public boolean removeModifier(ModifierKind modifier) { - return modifiers != CtElementImpl.emptySet() && modifiers.remove(modifier); + if (modifiers == CtElementImpl.emptySet()) { + return false; + } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new DeleteAction(new SetContext( + this, modifiers), modifier)); + } + return modifiers.remove(modifier); } @Override @@ -547,7 +599,7 @@ public > C addMethod(CtMethod method) { if (m.getSignature().equals(method.getSignature())) { // replace old method by new one (based on signature and not equality) // we have to do it by hand - typeMembers.remove(m); + removeTypeMember(m); } else { // checking contract signature implies equal if (!factory.getEnvironment().checksAreSkipped() && m.equals(method)) { @@ -573,13 +625,20 @@ public > C addSuperInterface(CtTypeReference interfac) interfaces = new QualifiedNameBasedSortedSet<>(); } interfac.setParent(this); + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new AddAction(new SetContext( + this, this.interfaces), interfac)); + } interfaces.add(interfac); return (C) this; } @Override public boolean removeSuperInterface(CtTypeReference interfac) { - if (interfaces.isEmpty()) { + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new DeleteAction(new SetContext(this, interfaces), interfac)); + } + if (interfaces == CtElementImpl.>emptySet()) { return false; } else if (interfaces.size() == 1) { if (interfaces.contains(interfac)) { @@ -601,6 +660,9 @@ public List getFormalCtTypeParameters() { @Override public C setFormalCtTypeParameters(List formalTypeParameters) { + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new DeleteAllAction(new ListContext(this, formalCtTypeParameters), new ArrayList<>(formalCtTypeParameters))); + } if (formalTypeParameters == null || formalTypeParameters.isEmpty()) { this.formalCtTypeParameters = CtElementImpl.emptyList(); return (C) this; @@ -624,13 +686,22 @@ public C addFormalCtTypeParameter(CtTypeParamet formalCtTypeParameters = new ArrayList<>(TYPE_TYPE_PARAMETERS_CONTAINER_DEFAULT_CAPACITY); } formalTypeParameter.setParent(this); + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new AddAction(new ListContext(this, this.formalCtTypeParameters), formalTypeParameter)); + } formalCtTypeParameters.add(formalTypeParameter); return (C) this; } @Override public boolean removeFormalCtTypeParameter(CtTypeParameter formalTypeParameter) { - return formalCtTypeParameters.contains(formalTypeParameter) && formalCtTypeParameters.remove(formalTypeParameter); + if (formalCtTypeParameters == CtElementImpl.emptyList()) { + return false; + } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new DeleteAction(new ListContext(this, formalCtTypeParameters, formalCtTypeParameters.indexOf(formalTypeParameter)), formalTypeParameter)); + } + return formalCtTypeParameters.remove(formalTypeParameter); } @Override @@ -843,6 +914,9 @@ public > C setMethods(Set> methods) { this.typeMembers.removeAll(getMethods()); return (C) this; } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new DeleteAllAction(new ListContext(this, this.typeMembers), new ArrayList(getMethods()))); + } typeMembers.removeAll(getMethods()); for (CtMethod meth : methods) { addMethod(meth); @@ -866,6 +940,10 @@ public > C setSuperInterfaces(Set> interf if (this.interfaces == CtElementImpl.>emptySet()) { this.interfaces = new QualifiedNameBasedSortedSet<>(); } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new DeleteAllAction(new SetContext( + this, this.interfaces), new HashSet<>(this.interfaces))); + } this.interfaces.clear(); for (CtTypeReference anInterface : interfaces) { addSuperInterface(anInterface); @@ -928,6 +1006,9 @@ public boolean isShadow() { @Override public E setShadow(boolean isShadow) { + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "isShadow"), isShadow, this.isShadow)); + } this.isShadow = isShadow; return (E) this; } diff --git a/src/main/java/spoon/support/reflect/declaration/CtTypeParameterImpl.java b/src/main/java/spoon/support/reflect/declaration/CtTypeParameterImpl.java index 27ca533f756..3498f6c9fc2 100644 --- a/src/main/java/spoon/support/reflect/declaration/CtTypeParameterImpl.java +++ b/src/main/java/spoon/support/reflect/declaration/CtTypeParameterImpl.java @@ -16,6 +16,9 @@ */ package spoon.support.reflect.declaration; +import spoon.diff.UpdateAction; +import spoon.diff.context.ObjectContext; +import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.declaration.CtField; import spoon.reflect.declaration.CtFormalTypeDeclarer; import spoon.reflect.declaration.CtMethod; @@ -32,7 +35,6 @@ import spoon.reflect.reference.CtTypeReference; import spoon.reflect.visitor.CtVisitor; import spoon.support.DerivedProperty; -import spoon.reflect.annotations.MetamodelPropertyField; import spoon.support.UnsettableProperty; import spoon.support.visitor.GenericTypeAdapter; @@ -60,6 +62,9 @@ public > C setSuperclass(CtTypeReference superClass) if (superClass != null) { superClass.setParent(this); } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "superClass"), superClass, this.superClass)); + } this.superClass = superClass; return (C) this; } diff --git a/src/main/java/spoon/support/reflect/reference/CtArrayTypeReferenceImpl.java b/src/main/java/spoon/support/reflect/reference/CtArrayTypeReferenceImpl.java index e8d4cd73d68..2446e744ddf 100644 --- a/src/main/java/spoon/support/reflect/reference/CtArrayTypeReferenceImpl.java +++ b/src/main/java/spoon/support/reflect/reference/CtArrayTypeReferenceImpl.java @@ -16,6 +16,8 @@ */ package spoon.support.reflect.reference; +import spoon.diff.UpdateAction; +import spoon.diff.context.ObjectContext; import spoon.reflect.reference.CtArrayTypeReference; import spoon.reflect.reference.CtTypeReference; import spoon.reflect.visitor.CtVisitor; @@ -59,6 +61,9 @@ public > C setComponentType(CtTypeReference if (componentType != null) { componentType.setParent(this); } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "componentType"), componentType, this.componentType)); + } this.componentType = componentType; return (C) this; } diff --git a/src/main/java/spoon/support/reflect/reference/CtExecutableReferenceImpl.java b/src/main/java/spoon/support/reflect/reference/CtExecutableReferenceImpl.java index 94d6a336e60..4330b1095ef 100644 --- a/src/main/java/spoon/support/reflect/reference/CtExecutableReferenceImpl.java +++ b/src/main/java/spoon/support/reflect/reference/CtExecutableReferenceImpl.java @@ -17,6 +17,12 @@ package spoon.support.reflect.reference; import spoon.Launcher; +import spoon.diff.AddAction; +import spoon.diff.DeleteAction; +import spoon.diff.DeleteAllAction; +import spoon.diff.UpdateAction; +import spoon.diff.context.ListContext; +import spoon.diff.context.ObjectContext; import spoon.reflect.code.CtLambda; import spoon.reflect.declaration.CtClass; import spoon.reflect.declaration.CtConstructor; @@ -43,6 +49,7 @@ import java.util.Collections; import java.util.List; import java.util.Set; + import static spoon.reflect.ModelElementContainerDefaultCapacities.METHOD_TYPE_PARAMETERS_CONTAINER_DEFAULT_CAPACITY; public class CtExecutableReferenceImpl extends CtReferenceImpl implements CtExecutableReference { @@ -198,21 +205,32 @@ public > C setParameters(List>emptyList()) { this.parameters = new ArrayList<>(); } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new DeleteAllAction(new ListContext( + this, this.parameters), new ArrayList<>(this.parameters))); + } this.parameters.clear(); for (CtTypeReference parameter : parameters) { - if (parameter == null) { - continue; - } - parameter.setParent(this); - this.parameters.add(parameter); + addParameter(parameter); } return (C) this; } + private boolean addParameter(CtTypeReference parameter) { + if (parameter == null) { + return false; + } + parameter.setParent(this); + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new AddAction(new ListContext( + this, this.parameters), parameter)); + } + return this.parameters.add(parameter); + } + @Override @SuppressWarnings("unchecked") - public CtExecutableReference getOverridingExecutable( - CtTypeReference subType) { + public CtExecutableReference getOverridingExecutable(CtTypeReference subType) { if ((subType == null) || subType.equals(getDeclaringType())) { return null; } @@ -264,6 +282,10 @@ public C setActualTypeArguments(List>emptyList()) { this.actualTypeArguments = new ArrayList<>(); } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new DeleteAllAction(new ListContext( + this, this.actualTypeArguments), new ArrayList<>(this.actualTypeArguments))); + } this.actualTypeArguments.clear(); for (CtTypeReference actualTypeArgument : actualTypeArguments) { addActualTypeArgument(actualTypeArgument); @@ -276,6 +298,9 @@ public > C setDeclaringType(CtTypeReference> C setType(CtTypeReference type) { if (type != null) { type.setParent(this); } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "type"), type, this.type)); + } this.type = type; return (C) this; } @@ -304,8 +332,7 @@ public Method getActualMethod() { method_loop: for (Method m : getDeclaringType().getActualClass().getDeclaredMethods()) { - if (!m.getDeclaringClass().isSynthetic() - && m.isSynthetic()) { + if (!m.getDeclaringClass().isSynthetic() && m.isSynthetic()) { continue; } if (!m.getName().equals(getSimpleName())) { @@ -350,8 +377,11 @@ public boolean isStatic() { } @Override - public > C setStatic(boolean b) { - this.stat = b; + public > C setStatic(boolean stat) { + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "stat"), stat, this.stat)); + } + this.stat = stat; return (C) this; } @@ -406,8 +436,7 @@ public CtExecutableReference getOverridingExecutable() { return getOverloadedExecutable(st, objectType); } - private CtExecutableReference getOverloadedExecutable( - CtTypeReference t, CtTypeReference objectType) { + private CtExecutableReference getOverloadedExecutable(CtTypeReference t, CtTypeReference objectType) { if (t == null) { return null; } @@ -435,15 +464,24 @@ public C addActualTypeArgument(CtTypeReference actualTypeArguments = new ArrayList<>(METHOD_TYPE_PARAMETERS_CONTAINER_DEFAULT_CAPACITY); } actualTypeArgument.setParent(this); + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new AddAction(new ListContext( + this, this.actualTypeArguments), actualTypeArgument)); + } actualTypeArguments.add(actualTypeArgument); return (C) this; } @Override - public boolean removeActualTypeArgument( - CtTypeReference actualTypeArgument) { - return actualTypeArguments != CtElementImpl.>emptyList() - && actualTypeArguments.remove(actualTypeArgument); + public boolean removeActualTypeArgument(CtTypeReference actualTypeArgument) { + if (actualTypeArguments == CtElementImpl.>emptyList()) { + return false; + } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new DeleteAction(new ListContext( + this, actualTypeArguments, actualTypeArguments.indexOf(actualTypeArgument)), actualTypeArgument)); + } + return actualTypeArguments.remove(actualTypeArgument); } @Override diff --git a/src/main/java/spoon/support/reflect/reference/CtFieldReferenceImpl.java b/src/main/java/spoon/support/reflect/reference/CtFieldReferenceImpl.java index fc7c6338700..7b6a760ff08 100644 --- a/src/main/java/spoon/support/reflect/reference/CtFieldReferenceImpl.java +++ b/src/main/java/spoon/support/reflect/reference/CtFieldReferenceImpl.java @@ -17,6 +17,8 @@ package spoon.support.reflect.reference; import spoon.Launcher; +import spoon.diff.UpdateAction; +import spoon.diff.context.ObjectContext; import spoon.reflect.declaration.CtEnum; import spoon.reflect.declaration.CtField; import spoon.reflect.declaration.CtType; @@ -186,18 +188,27 @@ public > C setDeclaringType(CtTypeReference dec if (declaringType != null) { declaringType.setParent(this); } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "declaringType"), declaringType, this.declaringType)); + } this.declaringType = declaringType; return (C) this; } @Override - public > C setFinal(boolean b) { - fina = b; + public > C setFinal(boolean fina) { + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "fina"), fina, this.fina)); + } + this.fina = fina; return (C) this; } @Override public > C setStatic(boolean stat) { + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "stat"), stat, this.stat)); + } this.stat = stat; return (C) this; } diff --git a/src/main/java/spoon/support/reflect/reference/CtIntersectionTypeReferenceImpl.java b/src/main/java/spoon/support/reflect/reference/CtIntersectionTypeReferenceImpl.java index 2a7fe2ee989..e4547c06138 100644 --- a/src/main/java/spoon/support/reflect/reference/CtIntersectionTypeReferenceImpl.java +++ b/src/main/java/spoon/support/reflect/reference/CtIntersectionTypeReferenceImpl.java @@ -16,14 +16,19 @@ */ package spoon.support.reflect.reference; -import java.util.ArrayList; -import java.util.List; - +import spoon.diff.AddAction; +import spoon.diff.DeleteAction; +import spoon.diff.DeleteAllAction; +import spoon.diff.context.ListContext; import spoon.reflect.reference.CtIntersectionTypeReference; import spoon.reflect.reference.CtTypeReference; import spoon.reflect.visitor.CtVisitor; import spoon.support.reflect.declaration.CtElementImpl; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + public class CtIntersectionTypeReferenceImpl extends CtTypeReferenceImpl implements CtIntersectionTypeReference { List> bounds = CtElementImpl.emptyList(); @@ -34,6 +39,9 @@ public void accept(CtVisitor visitor) { @Override public List> getBounds() { + if (getFactory().getEnvironment().buildStackChanges()) { + return Collections.unmodifiableList(bounds); + } return bounds; } @@ -46,6 +54,9 @@ public C setBounds(List>emptySet()) { this.bounds = new ArrayList<>(); } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new DeleteAllAction(new ListContext(this, this.bounds), new ArrayList<>(this.bounds))); + } this.bounds.clear(); for (CtTypeReference bound : bounds) { addBound(bound); @@ -63,6 +74,9 @@ public C addBound(CtTypeReference bou } if (!bounds.contains(bound)) { bound.setParent(this); + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new AddAction(new ListContext(this, this.bounds), bound)); + } bounds.add(bound); } return (C) this; @@ -70,7 +84,14 @@ public C addBound(CtTypeReference bou @Override public boolean removeBound(CtTypeReference bound) { - return bounds != CtElementImpl.>emptyList() && bounds.remove(bound); + if (bounds == CtElementImpl.>emptyList()) { + return false; + } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new DeleteAction(new ListContext(this, bounds, bounds.indexOf(bound)), bound)); + + } + return bounds.remove(bound); } @Override diff --git a/src/main/java/spoon/support/reflect/reference/CtParameterReferenceImpl.java b/src/main/java/spoon/support/reflect/reference/CtParameterReferenceImpl.java index 1d77e2186bf..a822f04f7ae 100644 --- a/src/main/java/spoon/support/reflect/reference/CtParameterReferenceImpl.java +++ b/src/main/java/spoon/support/reflect/reference/CtParameterReferenceImpl.java @@ -16,6 +16,8 @@ */ package spoon.support.reflect.reference; +import spoon.diff.UpdateAction; +import spoon.diff.context.ObjectContext; import spoon.reflect.declaration.CtElement; import spoon.reflect.declaration.CtExecutable; import spoon.reflect.declaration.CtParameter; @@ -97,6 +99,9 @@ public > C setDeclaringExecutable(CtExecutable if (executable != null) { executable.setParent(this); } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "executable"), executable, this.executable)); + } this.executable = executable; return (C) this; } diff --git a/src/main/java/spoon/support/reflect/reference/CtReferenceImpl.java b/src/main/java/spoon/support/reflect/reference/CtReferenceImpl.java index 5d44b2c3fe3..a8a74a0ca18 100644 --- a/src/main/java/spoon/support/reflect/reference/CtReferenceImpl.java +++ b/src/main/java/spoon/support/reflect/reference/CtReferenceImpl.java @@ -16,6 +16,8 @@ */ package spoon.support.reflect.reference; +import spoon.diff.UpdateAction; +import spoon.diff.context.ObjectContext; import spoon.reflect.factory.Factory; import spoon.reflect.factory.FactoryImpl; import spoon.reflect.reference.CtReference; @@ -46,9 +48,16 @@ public String getSimpleName() { @Override public T setSimpleName(String simplename) { Factory factory = getFactory(); + if (factory == null) { + this.simplename = simplename; + return (T) this; + } if (factory instanceof FactoryImpl) { simplename = ((FactoryImpl) factory).dedup(simplename); } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "simplename"), simplename, this.simplename)); + } this.simplename = simplename; return (T) this; } diff --git a/src/main/java/spoon/support/reflect/reference/CtTypeParameterReferenceImpl.java b/src/main/java/spoon/support/reflect/reference/CtTypeParameterReferenceImpl.java index 943b7624a7e..62aeec3e0b8 100644 --- a/src/main/java/spoon/support/reflect/reference/CtTypeParameterReferenceImpl.java +++ b/src/main/java/spoon/support/reflect/reference/CtTypeParameterReferenceImpl.java @@ -17,6 +17,8 @@ package spoon.support.reflect.reference; import spoon.SpoonException; +import spoon.diff.UpdateAction; +import spoon.diff.context.ObjectContext; import spoon.reflect.declaration.CtElement; import spoon.reflect.declaration.CtFormalTypeDeclarer; import spoon.reflect.declaration.CtMethod; @@ -75,6 +77,9 @@ public T setBounds(List> @Override public T setUpper(boolean upper) { + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "upper"), upper, this.upper)); + } this.upper = upper; return (T) this; } @@ -114,6 +119,7 @@ public C addActualTypeArgument(CtTypeReference } @Override + @UnsettableProperty public boolean removeActualTypeArgument(CtTypeReference actualTypeArgument) { return false; } @@ -159,6 +165,9 @@ public T setBoundingType(CtTypeReference if (superType != null) { superType.setParent(this); } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "superType"), superType, this.superType)); + } this.superType = superType; return (T) this; } diff --git a/src/main/java/spoon/support/reflect/reference/CtTypeReferenceImpl.java b/src/main/java/spoon/support/reflect/reference/CtTypeReferenceImpl.java index 9c5687f6837..ce5cccf7a22 100644 --- a/src/main/java/spoon/support/reflect/reference/CtTypeReferenceImpl.java +++ b/src/main/java/spoon/support/reflect/reference/CtTypeReferenceImpl.java @@ -18,6 +18,12 @@ import spoon.Launcher; import spoon.SpoonException; +import spoon.diff.AddAction; +import spoon.diff.DeleteAction; +import spoon.diff.DeleteAllAction; +import spoon.diff.UpdateAction; +import spoon.diff.context.ListContext; +import spoon.diff.context.ObjectContext; import spoon.reflect.declaration.CtConstructor; import spoon.reflect.declaration.CtElement; import spoon.reflect.declaration.CtExecutable; @@ -252,6 +258,10 @@ public C setActualTypeArguments(List>emptyList()) { this.actualTypeArguments = new ArrayList<>(TYPE_TYPE_PARAMETERS_CONTAINER_DEFAULT_CAPACITY); } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new DeleteAllAction(new ListContext( + this, this.actualTypeArguments), new ArrayList<>(this.actualTypeArguments))); + } this.actualTypeArguments.clear(); for (CtTypeReference actualTypeArgument : actualTypeArguments) { addActualTypeArgument(actualTypeArgument); @@ -264,6 +274,9 @@ public > C setDeclaringType(CtTypeReference decl if (declaringType != null) { declaringType.setParent(this); } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "declaringType"), declaringType, this.declaringType)); + } this.declaringType = declaringType; return (C) this; } @@ -273,6 +286,9 @@ public > C setPackage(CtPackageReference pack) { if (pack != null) { pack.setParent(this); } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "pack"), pack, this.pack)); + } this.pack = pack; return (C) this; } @@ -557,13 +573,24 @@ public C addActualTypeArgument(CtTypeReference actualTypeArguments = new ArrayList<>(TYPE_TYPE_PARAMETERS_CONTAINER_DEFAULT_CAPACITY); } actualTypeArgument.setParent(this); + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new AddAction(new ListContext( + this, this.actualTypeArguments), actualTypeArgument)); + } actualTypeArguments.add(actualTypeArgument); return (C) this; } @Override public boolean removeActualTypeArgument(CtTypeReference actualTypeArgument) { - return actualTypeArguments != CtElementImpl.>emptyList() && actualTypeArguments.remove(actualTypeArgument); + if (actualTypeArguments == CtElementImpl.>emptyList()) { + return false; + } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new DeleteAction(new ListContext( + this, actualTypeArguments, actualTypeArguments.indexOf(actualTypeArgument)), actualTypeArgument)); + } + return actualTypeArguments.remove(actualTypeArgument); } @Override @@ -780,6 +807,9 @@ public boolean isShadow() { @Override public E setShadow(boolean isShadow) { + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "isShadow"), isShadow, this.isShadow)); + } this.isShadow = isShadow; return (E) this; } diff --git a/src/main/java/spoon/support/reflect/reference/CtVariableReferenceImpl.java b/src/main/java/spoon/support/reflect/reference/CtVariableReferenceImpl.java index 6d2dbe661af..410c8f1fed3 100644 --- a/src/main/java/spoon/support/reflect/reference/CtVariableReferenceImpl.java +++ b/src/main/java/spoon/support/reflect/reference/CtVariableReferenceImpl.java @@ -16,6 +16,8 @@ */ package spoon.support.reflect.reference; +import spoon.diff.UpdateAction; +import spoon.diff.context.ObjectContext; import spoon.reflect.declaration.CtVariable; import spoon.reflect.declaration.ModifierKind; import spoon.reflect.reference.CtTypeReference; @@ -50,6 +52,9 @@ public > C setType(CtTypeReference type) { if (type != null) { type.setParent(this); } + if (getFactory().getEnvironment().buildStackChanges()) { + getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "type"), type, this.type)); + } this.type = type; return (C) this; } diff --git a/src/main/java/spoon/support/reflect/reference/CtWildcardReferenceImpl.java b/src/main/java/spoon/support/reflect/reference/CtWildcardReferenceImpl.java index 2ffe4153fe3..ef1214504bd 100644 --- a/src/main/java/spoon/support/reflect/reference/CtWildcardReferenceImpl.java +++ b/src/main/java/spoon/support/reflect/reference/CtWildcardReferenceImpl.java @@ -20,6 +20,7 @@ import spoon.reflect.reference.CtReference; import spoon.reflect.reference.CtWildcardReference; import spoon.reflect.visitor.CtVisitor; +import spoon.support.UnsettableProperty; public class CtWildcardReferenceImpl extends CtTypeParameterReferenceImpl implements CtWildcardReference { @Override @@ -32,6 +33,7 @@ public CtWildcardReferenceImpl() { } @Override + @UnsettableProperty public T setSimpleName(String simplename) { return (T) this; } diff --git a/src/test/java/spoon/reflect/ast/AstCheckerTest.java b/src/test/java/spoon/reflect/ast/AstCheckerTest.java new file mode 100644 index 00000000000..c45ff4b7f9e --- /dev/null +++ b/src/test/java/spoon/reflect/ast/AstCheckerTest.java @@ -0,0 +1,309 @@ +package spoon.reflect.ast; + +import org.junit.Test; +import spoon.Launcher; +import spoon.diff.Action; +import spoon.reflect.code.CtBlock; +import spoon.reflect.code.CtExpression; +import spoon.reflect.code.CtFieldRead; +import spoon.reflect.code.CtIf; +import spoon.reflect.code.CtInvocation; +import spoon.reflect.code.CtReturn; +import spoon.reflect.code.CtStatement; +import spoon.reflect.code.CtThrow; +import spoon.reflect.declaration.CtMethod; +import spoon.reflect.declaration.CtType; +import spoon.reflect.declaration.ModifierKind; +import spoon.reflect.factory.Factory; +import spoon.reflect.reference.CtTypeReference; +import spoon.reflect.visitor.CtScanner; +import spoon.reflect.visitor.Query; +import spoon.reflect.visitor.filter.TypeFilter; +import spoon.support.DerivedProperty; +import spoon.support.UnsettableProperty; +import spoon.support.comparator.CtLineElementComparator; +import spoon.template.TemplateMatcher; +import spoon.template.TemplateParameter; + +import java.io.File; +import java.util.Arrays; +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; + +public class AstCheckerTest { + @Test + public void testStackChanges() throws Exception { + final Launcher launcher = new Launcher(); + launcher.getModelBuilder().setSourceClasspath(System.getProperty("java.class.path").split(File.pathSeparator)); + // interfaces. + launcher.addInputResource("./src/main/java/spoon/reflect/code"); + launcher.addInputResource("./src/main/java/spoon/reflect/declaration"); + launcher.addInputResource("./src/main/java/spoon/reflect/reference"); + launcher.addInputResource("./src/main/java/spoon/reflect/internal"); + // 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.addInputResource("./src/main/java/spoon/support/reflect/internal"); + // Utils. + launcher.addInputResource("./src/test/java/spoon/reflect/ast/AstCheckerTest.java"); + launcher.buildModel(); + + final GetterListChecker getterListChecker = new GetterListChecker(launcher.getFactory()); + getterListChecker.scan(launcher.getModel().getRootPackage()); + if (getterListChecker.result != null) { + throw new AssertionError(getterListChecker.result); + } + } + + @Test + public void testAvoidSetCollectionSavedOnAST() throws Exception { + final Launcher launcher = new Launcher(); + launcher.getEnvironment().setNoClasspath(true); + launcher.getEnvironment().setBuildStackChanges(true); + launcher.addInputResource("src/main/java"); + launcher.buildModel(); + + final Factory factory = launcher.getFactory(); + final List> collectionsRef = Arrays.asList( // + factory.Type().createReference(Collection.class), // + factory.Type().createReference(List.class), // + factory.Type().createReference(Set.class), // + factory.Type().createReference(Map.class)); + + final List> invocations = Query.getElements(factory, new TypeFilter>(CtInvocation.class) { + @Override + public boolean matches(CtInvocation element) { + if (!element.getExecutable().getSimpleName().startsWith("get")) { + return false; + } + if (!collectionsRef.contains(element.getType())) { + return false; + } + if (!element.getExecutable().getDeclaringType().getSimpleName().startsWith("Ct")) { + return false; + } + if (!(element.getParent() instanceof CtInvocation)) { + return false; + } + final CtInvocation parent = (CtInvocation) element.getParent(); + if (!parent.getTarget().equals(element)) { + return false; + } + final String simpleName = parent.getExecutable().getSimpleName(); + return simpleName.startsWith("add") || simpleName.startsWith("remove"); + } + }); + if (invocations.size() > 0) { + final String error = invocations.stream() // + .sorted(new CtLineElementComparator()) // + .map(i -> "see " + i.getPosition().getFile().getName() + " at " + i.getPosition().getLine()) // + .collect(Collectors.joining(",\n")); + throw new AssertionError(error); + } + } + + @Test + public void testPushToStackChanges() throws Exception { + final Launcher launcher = new Launcher(); + launcher.getEnvironment().setNoClasspath(true); + launcher.getEnvironment().setBuildStackChanges(true); + // 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.addInputResource("./src/main/java/spoon/support/reflect/internal"); + // Utils. + launcher.addInputResource("./src/test/java/spoon/reflect/ast/AstCheckerTest.java"); + launcher.buildModel(); + + final PushStackInIntercessionChecker checker = new PushStackInIntercessionChecker(launcher.getFactory()); + checker.scan(launcher.getModel().getRootPackage()); + if (!checker.result.isEmpty()) { + System.err.println(checker.count); + throw new AssertionError(checker.result); + } + } + + private class PushStackInIntercessionChecker extends CtScanner { + private final CtInvocation template; + private final List notCandidates; + private String result = ""; + private int count; + + PushStackInIntercessionChecker(Factory factory) { + final CtType templateClass = factory.Type().get(Template.class); + template = templateClass.getMethod("templatePush").getBody().getStatement(0); + notCandidates = Arrays.asList( // + "CtTypeImpl#addTypeMember", // + "CtTypeImpl#removeTypeMember", // + "CtTypeImpl#addFieldAtTop", // + "CtTypeImpl#addField", // + "CtTypeImpl#removeField", // + "CtTypeImpl#addBound", // + "CtTypeImpl#addNestedType", // + "CtTypeImpl#removeNestedType", // + "CtTypeImpl#addMethod", // + "CtTypeImpl#removeMethod", // + "CtBlockImpl#removeStatement", // + "CtAnnotationTypeImpl#addMethod", // + "CtClassImpl#removeConstructor", // + "CtConstructorCallImpl#addArgument", // + "CtInvocationImpl#addArgument", // + "CtTypeParameterReferenceImpl#addBound", // + "CtTypeParameterReferenceImpl#removeBound", // + "CtTypeParameterReferenceImpl#setBounds", // + "CtElementImpl#setFactory", // + "CtElementImpl#setPositions", // + "CtElementImpl#setDocComment", // + "CtStatementListImpl#setPosition", // + "CtAnnotationImpl#addValue", // + "CtAnnotationTypeImpl#setFields" // + ); + } + + private boolean isToBeProcessed(CtMethod candidate) { + if (candidate.getAnnotation(UnsettableProperty.class) != null) { + return false; + } + if (candidate.getAnnotation(DerivedProperty.class) != null) { + return false; + } + return candidate.getBody() != null // + && candidate.getParameters().size() != 0 // + && candidate.hasModifier(ModifierKind.PUBLIC) // + && (candidate.getSimpleName().startsWith("add") || candidate.getSimpleName().startsWith("set") || candidate.getSimpleName().startsWith("remove")) // + && candidate.getDeclaringType().getSimpleName().startsWith("Ct") // + && !isNotCandidate(candidate) // + && !isDelegateMethod(candidate) // + && !isUnsupported(candidate.getBody()) // + && !hasPushToStackInvocation(candidate.getBody()) + && isSettable(candidate); + } + + private boolean isSettable(CtMethod candidate) { + return candidate.getAnnotation(UnsettableProperty.class) == null; + } + private boolean isNotCandidate(CtMethod candidate) { + return "setVisibility".equals(candidate.getSimpleName()) || notCandidates.contains(candidate.getDeclaringType().getSimpleName() + "#" + candidate.getSimpleName()); + } + + private boolean isDelegateMethod(CtMethod candidate) { + if (candidate.getBody().getStatements().size() == 0) { + return false; + } + if (!(candidate.getBody().getStatement(0) instanceof CtIf)) { + return false; + } + if (!(((CtIf) candidate.getBody().getStatement(0)).getThenStatement() instanceof CtBlock)) { + return false; + } + final CtBlock block = ((CtIf) candidate.getBody().getStatement(0)).getThenStatement(); + if (!(block.getStatement(0) instanceof CtInvocation || block.getStatement(0) instanceof CtReturn)) { + return false; + } + CtInvocation potentialDelegate; + if (block.getStatement(0) instanceof CtReturn) { + if (!(((CtReturn) block.getStatement(0)).getReturnedExpression() instanceof CtInvocation)) { + return false; + } + potentialDelegate = (CtInvocation) ((CtReturn) block.getStatement(0)).getReturnedExpression(); + } else { + potentialDelegate = (CtInvocation) block.getStatement(0); + } + return potentialDelegate.getExecutable().getSimpleName().equals(candidate.getSimpleName()); + } + + private boolean isUnsupported(CtBlock body) { + return body.getStatements().size() != 0 // + && body.getStatements().get(0) instanceof CtThrow // + && "UnsupportedOperationException".equals(((CtThrow) body.getStatements().get(0)).getThrownExpression().getType().getSimpleName()); + } + + private boolean hasPushToStackInvocation(CtBlock body) { + return body.getElements(new TypeFilter>(CtInvocation.class) { + @Override + public boolean matches(CtInvocation element) { + return element.getExecutable().getSimpleName().equals(template.getExecutable().getSimpleName()) && super.matches(element); + } + }).size() == 1; + } + + private void process(CtMethod element) { + count++; + result += element.getSignature() + " on " + element.getDeclaringType().getQualifiedName() + "\n"; + } + + @Override + public void visitCtMethod(CtMethod m) { + if (isToBeProcessed(m)) { + process(m); + } + super.visitCtMethod(m); + } + } + + private class GetterListChecker extends CtScanner { + private final List> COLLECTIONS; + private final CtExpression conditionExpected; + private String result; + + GetterListChecker(Factory factory) { + COLLECTIONS = Arrays.asList(factory.Type().createReference(Collection.class), factory.Type().createReference(List.class), factory.Type().createReference(Set.class)); + final CtType templateClass = factory.Type().get(Template.class); + conditionExpected = ((CtIf) templateClass.getMethod("template").getBody().getStatement(0)).getCondition(); + } + + private boolean isToBeProcessed(CtMethod candidate) { + return candidate.getBody() != null // + && candidate.getParameters().size() == 0 // + && candidate.getDeclaringType().getSimpleName().startsWith("Ct") // + && COLLECTIONS.contains(candidate.getType()) // + && isConditionExpected(candidate.getBody().getStatement(0)) // + && isReturnCollection(candidate.getBody().getLastStatement()); + } + + private boolean isConditionExpected(CtStatement statement) { + final TemplateMatcher matcher = new TemplateMatcher(conditionExpected); + return matcher.find(statement).size() == 0; + } + + private boolean isReturnCollection(CtStatement statement) { + return statement instanceof CtReturn // + && ((CtReturn) statement).getReturnedExpression() instanceof CtFieldRead // + && COLLECTIONS.contains(((CtFieldRead) ((CtReturn) statement).getReturnedExpression()).getVariable().getType()); + } + + private void process(CtMethod element) { + result += element.getSignature() + " on " + element.getDeclaringType().getQualifiedName() + "\n"; + } + + @Override + public void visitCtMethod(CtMethod m) { + if (isToBeProcessed(m)) { + process(m); + } + super.visitCtMethod(m); + } + } + + class Template { + TemplateParameter _action_; + + public void template() { + if (getFactory().getEnvironment().buildStackChanges()) { + } + } + + public void templatePush() { + getFactory().getEnvironment().pushToStack(_action_.S()); + } + + public Factory getFactory() { + return null; + } + } +} From ea580806e31672abfda6e1f8a13ad901f3646ba7 Mon Sep 17 00:00:00 2001 From: tdurieux Date: Sun, 4 Jun 2017 20:57:44 +0200 Subject: [PATCH 03/40] fix javadoc constructor --- .../java/spoon/support/reflect/code/CtCommentImpl.java | 7 +++++++ .../java/spoon/support/reflect/code/CtJavaDocImpl.java | 7 +------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main/java/spoon/support/reflect/code/CtCommentImpl.java b/src/main/java/spoon/support/reflect/code/CtCommentImpl.java index a09009eb97f..04f3eececd8 100644 --- a/src/main/java/spoon/support/reflect/code/CtCommentImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtCommentImpl.java @@ -32,6 +32,13 @@ public class CtCommentImpl extends CtStatementImpl implements CtComment { @MetamodelPropertyField(role = CtRole.COMMENT_TYPE) private CommentType type; + public CtCommentImpl() { + } + + protected CtCommentImpl(CommentType type) { + this.type = type; + } + @Override public String getContent() { return content; diff --git a/src/main/java/spoon/support/reflect/code/CtJavaDocImpl.java b/src/main/java/spoon/support/reflect/code/CtJavaDocImpl.java index 30e8730b837..16f99324157 100644 --- a/src/main/java/spoon/support/reflect/code/CtJavaDocImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtJavaDocImpl.java @@ -39,12 +39,7 @@ public class CtJavaDocImpl extends CtCommentImpl implements CtJavaDoc { List tags = new ArrayList<>(); public CtJavaDocImpl() { - this(""); - } - - public CtJavaDocImpl(String content) { - super.setContent(content); - super.setCommentType(CommentType.JAVADOC); + super(CommentType.JAVADOC); } @Override From 99e9525a9b910a220042a9b4bafb8fa7976250f2 Mon Sep 17 00:00:00 2001 From: tdurieux Date: Mon, 5 Jun 2017 10:06:33 +0200 Subject: [PATCH 04/40] create change factory --- .../diff/AbstractModelChangeListener.java | 47 ++++++ .../java/spoon/diff/ModelChangeListener.java | 52 ++++++ .../spoon/reflect/factory/ChangeFactory.java | 159 ++++++++++++++++++ .../java/spoon/reflect/factory/Factory.java | 2 + .../spoon/reflect/factory/FactoryImpl.java | 13 ++ .../spoon/support/StandardEnvironment.java | 13 ++ 6 files changed, 286 insertions(+) create mode 100644 src/main/java/spoon/diff/AbstractModelChangeListener.java create mode 100644 src/main/java/spoon/diff/ModelChangeListener.java create mode 100644 src/main/java/spoon/reflect/factory/ChangeFactory.java diff --git a/src/main/java/spoon/diff/AbstractModelChangeListener.java b/src/main/java/spoon/diff/AbstractModelChangeListener.java new file mode 100644 index 00000000000..7b59bae7711 --- /dev/null +++ b/src/main/java/spoon/diff/AbstractModelChangeListener.java @@ -0,0 +1,47 @@ +/** + * Copyright (C) 2006-2017 INRIA and contributors + * Spoon - http://spoon.gforge.inria.fr/ + * + * This software is governed by the CeCILL-C License under French law and + * abiding by the rules of distribution of free software. You can use, modify + * and/or redistribute the software under the terms of the CeCILL-C license as + * circulated by CEA, CNRS and INRIA at http://www.cecill.info. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the CeCILL-C License for more details. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL-C license and that you accept its terms. + */ +package spoon.diff; + +/** + * notifies all change on the AST + */ +public abstract class AbstractModelChangeListener implements ModelChangeListener { + @Override + public void onDelete(DeleteAction action) { + + } + + @Override + public void onDeleteAll(DeleteAllAction action) { + + } + + @Override + public void onAdd(AddAction action) { + + } + + @Override + public void onUpdate(UpdateAction action) { + + } + + @Override + public void onAction(Action action) { + + } +} diff --git a/src/main/java/spoon/diff/ModelChangeListener.java b/src/main/java/spoon/diff/ModelChangeListener.java new file mode 100644 index 00000000000..a5211f33206 --- /dev/null +++ b/src/main/java/spoon/diff/ModelChangeListener.java @@ -0,0 +1,52 @@ +/** + * Copyright (C) 2006-2017 INRIA and contributors + * Spoon - http://spoon.gforge.inria.fr/ + * + * This software is governed by the CeCILL-C License under French law and + * abiding by the rules of distribution of free software. You can use, modify + * and/or redistribute the software under the terms of the CeCILL-C license as + * circulated by CEA, CNRS and INRIA at http://www.cecill.info. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the CeCILL-C License for more details. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL-C license and that you accept its terms. + */ +package spoon.diff; + +/** + * notifies all change on the AST + */ +public interface ModelChangeListener { + /** + * when an element is removed + * @param action contains information of the change + */ + void onDelete(DeleteAction action); + + /** + * when all element are removed + * @param action contains information of the change + */ + void onDeleteAll(DeleteAllAction action); + + /** + * when an element is added + * @param action contains information of the change + */ + void onAdd(AddAction action); + + /** + * when an element is modified + * @param action contains information of the change + */ + void onUpdate(UpdateAction action); + + /** + * when an element is changed + * @param action contains information of the change + */ + void onAction(Action action); +} diff --git a/src/main/java/spoon/reflect/factory/ChangeFactory.java b/src/main/java/spoon/reflect/factory/ChangeFactory.java new file mode 100644 index 00000000000..eaf8b98099f --- /dev/null +++ b/src/main/java/spoon/reflect/factory/ChangeFactory.java @@ -0,0 +1,159 @@ +/** + * Copyright (C) 2006-2017 INRIA and contributors + * Spoon - http://spoon.gforge.inria.fr/ + * + * This software is governed by the CeCILL-C License under French law and + * abiding by the rules of distribution of free software. You can use, modify + * and/or redistribute the software under the terms of the CeCILL-C license as + * circulated by CEA, CNRS and INRIA at http://www.cecill.info. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the CeCILL-C License for more details. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL-C license and that you accept its terms. + */ +package spoon.reflect.factory; + +import spoon.diff.Action; +import spoon.diff.ModelChangeListener; +import spoon.diff.AddAction; +import spoon.diff.DeleteAction; +import spoon.diff.DeleteAllAction; +import spoon.diff.UpdateAction; +import spoon.diff.context.ListContext; +import spoon.diff.context.MapContext; +import spoon.diff.context.ObjectContext; +import spoon.diff.context.SetContext; +import spoon.reflect.declaration.CtElement; +import spoon.reflect.declaration.ModifierKind; +import spoon.reflect.path.CtRole; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.Set; + +public class ChangeFactory extends SubFactory { + + private final List listeners = new ArrayList<>(2); + + public ChangeFactory(Factory factory) { + super(factory); + } + + public void addModelChangeListener(final ModelChangeListener listener) { + listeners.add(listener); + } + + public void removeModelChangeListener(final ModelChangeListener listener) { + listeners.remove(listener); + } + + private void propagateModelChange(final Action action) { + for (ModelChangeListener listener : listeners) { + listener.onAction(action); + if (action instanceof DeleteAllAction) { + listener.onDeleteAll((DeleteAllAction) action); + } else if (action instanceof DeleteAction) { + listener.onDelete((DeleteAction) action); + } else if (action instanceof AddAction) { + listener.onAdd((AddAction) action); + } else if (action instanceof UpdateAction) { + listener.onUpdate((UpdateAction) action); + } + } + } + + public void onObjectUpdate(CtElement currentElement, CtRole role, String changedField, CtElement newValue, CtElement oldValue) { + Action action = new UpdateAction(new ObjectContext(currentElement, changedField), newValue, oldValue); + propagateModelChange(action); + } + + public void onObjectUpdate(CtElement currentElement, CtRole role, String changedField, Object newValue, Object oldValue) { + UpdateAction action = new UpdateAction(new ObjectContext(currentElement, changedField), newValue, oldValue); + propagateModelChange(action); + } + + public void onObjectDelete(CtElement currentElement, CtRole role, String changedField, CtElement oldValue) { + DeleteAction action = new DeleteAction(new ObjectContext(currentElement, changedField), oldValue); + propagateModelChange(action); + } + + public void onListAdd(CtElement currentElement, CtRole role, List field, CtElement newValue) { + AddAction action = new AddAction(new ListContext(currentElement, field), newValue); + propagateModelChange(action); + } + + public void onListAdd(CtElement currentElement, CtRole role, List field, int index, CtElement newValue) { + AddAction action = new AddAction(new ListContext(currentElement, field, index), newValue); + propagateModelChange(action); + } + + + public void onListDelete(CtElement currentElement, CtRole role, List field, Collection oldValue) { + if (factory.getEnvironment().buildStackChanges()) { + for (CtElement ctElement : oldValue) { + onListDelete(currentElement, role, field, field.indexOf(ctElement), ctElement); + } + } + } + + public void onListDelete(CtElement currentElement, CtRole role, List field, int index, CtElement oldValue) { + DeleteAction action = new DeleteAction(new ListContext(currentElement, field, index), oldValue); + propagateModelChange(action); + } + + + public void onListDeleteAll(CtElement currentElement, CtRole role, List field, List oldValue) { + DeleteAllAction action = new DeleteAllAction(new ListContext(currentElement, field), oldValue); + propagateModelChange(action); + } + + + public void onMapAdd(CtElement currentElement, CtRole role, Map field, K key, CtElement newValue) { + AddAction action = new AddAction(new MapContext<>(currentElement, field, key), newValue); + propagateModelChange(action); + } + + public void onMapDeleteAll(CtElement currentElement, CtRole role, Map field, Map oldValue) { + DeleteAllAction action = new DeleteAllAction(new MapContext<>(currentElement, field), oldValue); + propagateModelChange(action); + } + + public void onSetAdd(CtElement currentElement, CtRole role, Set field, CtElement newValue) { + AddAction action = new AddAction(new SetContext(currentElement, field), newValue); + propagateModelChange(action); + } + + public void onSetAdd(CtElement currentElement, CtRole role, Set field, ModifierKind newValue) { + AddAction action = new AddAction(new SetContext(currentElement, field), newValue); + propagateModelChange(action); + } + + + public void onSetDelete(CtElement currentElement, CtRole role, Set field, CtElement oldValue) { + DeleteAction action = new DeleteAction(new SetContext(currentElement, field), oldValue); + propagateModelChange(action); + } + + public void onSetDelete(CtElement currentElement, CtRole role, Set field, Collection oldValue) { + if (factory.getEnvironment().buildStackChanges()) { + for (ModifierKind modifierKind : oldValue) { + onSetDelete(currentElement, role, field, modifierKind); + } + } + } + + public void onSetDelete(CtElement currentElement, CtRole role, Set field, ModifierKind oldValue) { + DeleteAction action = new DeleteAction(new SetContext(currentElement, field), oldValue); + propagateModelChange(action); + } + + public void onSetDeleteAll(CtElement currentElement, CtRole role, Set field, Set oldValue) { + DeleteAllAction action = new DeleteAllAction(new SetContext(currentElement, field), oldValue); + propagateModelChange(action); + } +} diff --git a/src/main/java/spoon/reflect/factory/Factory.java b/src/main/java/spoon/reflect/factory/Factory.java index 671638f9e95..bc0af89ff10 100644 --- a/src/main/java/spoon/reflect/factory/Factory.java +++ b/src/main/java/spoon/reflect/factory/Factory.java @@ -156,6 +156,8 @@ public interface Factory { QueryFactory Query(); + ChangeFactory Change(); + /** * @see CodeFactory#createAnnotation(CtTypeReference) */ diff --git a/src/main/java/spoon/reflect/factory/FactoryImpl.java b/src/main/java/spoon/reflect/factory/FactoryImpl.java index 09fcb541199..038a0c2d21d 100644 --- a/src/main/java/spoon/reflect/factory/FactoryImpl.java +++ b/src/main/java/spoon/reflect/factory/FactoryImpl.java @@ -352,6 +352,19 @@ public QueryFactory Query() { return query; } + private transient ChangeFactory change; + + /** + * The change sub-factory. + */ + @Override + public ChangeFactory Change() { + if (change == null) { + change = new ChangeFactory(this); + } + return change; + } + /** * A constructor that takes the parent factory */ diff --git a/src/main/java/spoon/support/StandardEnvironment.java b/src/main/java/spoon/support/StandardEnvironment.java index b83c1311074..eaa57a9350c 100644 --- a/src/main/java/spoon/support/StandardEnvironment.java +++ b/src/main/java/spoon/support/StandardEnvironment.java @@ -24,6 +24,7 @@ import spoon.compiler.InvalidClassPathException; import spoon.compiler.SpoonFile; import spoon.compiler.SpoonFolder; +import spoon.diff.AbstractModelChangeListener; import spoon.diff.Action; import spoon.processing.FileGenerator; import spoon.processing.ProblemFixer; @@ -161,9 +162,21 @@ public boolean buildStackChanges() { return buildStackChanges; } + private AbstractModelChangeListener stackListener = new AbstractModelChangeListener() { + @Override + public void onAction(Action action) { + factory.getEnvironment().pushToStack(action); + } + }; + @Override public void setBuildStackChanges(boolean buildStackChanges) { this.buildStackChanges = buildStackChanges; + if (buildStackChanges) { + getFactory().Change().addModelChangeListener(stackListener); + } else { + getFactory().Change().removeModelChangeListener(stackListener); + } } @Override From 02a7a28b3a2d502b14e13249df94f36d90b088b7 Mon Sep 17 00:00:00 2001 From: tdurieux Date: Fri, 23 Jun 2017 11:13:46 +0200 Subject: [PATCH 05/40] improve action --- src/main/java/spoon/diff/Action.java | 23 ++----------- src/main/java/spoon/diff/AddAction.java | 23 ++++++++----- src/main/java/spoon/diff/DeleteAction.java | 22 +++++++----- src/main/java/spoon/diff/DeleteAllAction.java | 23 ++++--------- src/main/java/spoon/diff/UpdateAction.java | 31 +++++++---------- .../spoon/diff/context/CollectionContext.java | 5 +-- src/main/java/spoon/diff/context/Context.java | 9 ++++- .../java/spoon/diff/context/ListContext.java | 14 +++++--- .../java/spoon/diff/context/MapContext.java | 11 +++--- .../spoon/diff/context/ObjectContext.java | 15 ++------ .../java/spoon/diff/context/SetContext.java | 5 +-- .../spoon/reflect/factory/ChangeFactory.java | 34 +++++++++---------- .../spoon/support/StandardEnvironment.java | 6 ++++ 13 files changed, 104 insertions(+), 117 deletions(-) diff --git a/src/main/java/spoon/diff/Action.java b/src/main/java/spoon/diff/Action.java index 5a69c465d6a..5b12768ebac 100644 --- a/src/main/java/spoon/diff/Action.java +++ b/src/main/java/spoon/diff/Action.java @@ -17,36 +17,17 @@ package spoon.diff; import spoon.diff.context.Context; -import spoon.reflect.declaration.CtElement; public abstract class Action { private final Context context; - private final CtElement newElement; - private final Object newValue; - Action(Context context, CtElement newElement) { + Action(Context context) { this.context = context; - this.newElement = newElement; - this.newValue = null; } - Action(Context context, Object newValue) { - this.context = context; - this.newValue = newValue; - this.newElement = null; - } - - public abstract void rollback(); + public abstract T getChangedElement(); public Context getContext() { return context; } - - public CtElement getNewElement() { - return newElement; - } - - public Object getNewValue() { - return newValue; - } } diff --git a/src/main/java/spoon/diff/AddAction.java b/src/main/java/spoon/diff/AddAction.java index 871fdc2d79e..672f39dba42 100644 --- a/src/main/java/spoon/diff/AddAction.java +++ b/src/main/java/spoon/diff/AddAction.java @@ -17,18 +17,25 @@ package spoon.diff; import spoon.diff.context.Context; -import spoon.reflect.declaration.CtElement; -public class AddAction extends Action { - public AddAction(Context context, CtElement newElement) { - super(context, newElement); - } +public class AddAction extends Action { + private T newElement; - public AddAction(Context context, Object newValue) { - super(context, newValue); + public AddAction(Context context, T newElement) { + super(context); + this.newElement = newElement; } @Override - public void rollback() { + public T getChangedElement() { + return getNewElement(); + } + + /** + * Returns the added element + * @return the new element + */ + public T getNewElement() { + return newElement; } } diff --git a/src/main/java/spoon/diff/DeleteAction.java b/src/main/java/spoon/diff/DeleteAction.java index 945791816d5..38319514c47 100644 --- a/src/main/java/spoon/diff/DeleteAction.java +++ b/src/main/java/spoon/diff/DeleteAction.java @@ -17,19 +17,25 @@ package spoon.diff; import spoon.diff.context.Context; -import spoon.reflect.declaration.CtElement; -public class DeleteAction extends Action { - public DeleteAction(Context context, CtElement oldElement) { - super(context, oldElement); - } +public class DeleteAction extends Action { + private T oldElement; - public DeleteAction(Context context, Object oldElement) { - super(context, oldElement); + public DeleteAction(Context context, T oldElement) { + super(context); + this.oldElement = oldElement; } @Override - public void rollback() { + public T getChangedElement() { + return getRemovedElement(); + } + /** + * Returns the removed element + * @return the removed element + */ + public T getRemovedElement() { + return oldElement; } } diff --git a/src/main/java/spoon/diff/DeleteAllAction.java b/src/main/java/spoon/diff/DeleteAllAction.java index 6371740ad2a..c92174d0190 100644 --- a/src/main/java/spoon/diff/DeleteAllAction.java +++ b/src/main/java/spoon/diff/DeleteAllAction.java @@ -16,29 +16,18 @@ */ package spoon.diff; -import spoon.diff.context.CollectionContext; import spoon.diff.context.Context; -import spoon.diff.context.MapContext; + +import java.util.Collection; +import java.util.Map; public class DeleteAllAction extends DeleteAction { - private T oldContent; - public DeleteAllAction(Context context, T oldElement) { + public DeleteAllAction(Context context, Collection oldElement) { super(context, oldElement); - oldContent = oldElement; - } - - public DeleteAllAction(CollectionContext context, T copy) { - super(context, null); - oldContent = copy; } - public DeleteAllAction(MapContext context, T copy) { - super(context, null); - oldContent = copy; - } - - public T getOldContent() { - return oldContent; + public DeleteAllAction(Context context, Map oldElement) { + super(context, oldElement); } } diff --git a/src/main/java/spoon/diff/UpdateAction.java b/src/main/java/spoon/diff/UpdateAction.java index fb856f26ab0..17033120f46 100644 --- a/src/main/java/spoon/diff/UpdateAction.java +++ b/src/main/java/spoon/diff/UpdateAction.java @@ -17,34 +17,27 @@ package spoon.diff; import spoon.diff.context.Context; -import spoon.reflect.declaration.CtElement; -public class UpdateAction extends Action { - private final CtElement oldElement; - private final Object oldValue; +public class UpdateAction extends Action { + private final T oldElement; + private final T newElement; - public UpdateAction(Context context, CtElement newElement, CtElement oldElement) { - super(context, newElement); + public UpdateAction(Context context, T newElement, T oldElement) { + super(context); this.oldElement = oldElement; - this.oldValue = null; - } - - public UpdateAction(Context context, Object newValue, Object oldValue) { - super(context, newValue); - this.oldValue = oldValue; - this.oldElement = null; + this.newElement = newElement; } @Override - public void rollback() { - + public T getChangedElement() { + return getNewElement(); } - public CtElement getOldElement() { - return oldElement; + public T getNewElement() { + return newElement; } - public Object getOldValue() { - return oldValue; + public T getOldElement() { + return oldElement; } } diff --git a/src/main/java/spoon/diff/context/CollectionContext.java b/src/main/java/spoon/diff/context/CollectionContext.java index ac556a2f86b..2800f287d70 100644 --- a/src/main/java/spoon/diff/context/CollectionContext.java +++ b/src/main/java/spoon/diff/context/CollectionContext.java @@ -17,14 +17,15 @@ package spoon.diff.context; import spoon.reflect.declaration.CtElement; +import spoon.reflect.path.CtRole; import java.util.Collection; public class CollectionContext> extends Context { protected final T original; - public CollectionContext(CtElement element, T original) { - super(element); + public CollectionContext(CtElement element, CtRole role, T original) { + super(element, role); this.original = original; } } diff --git a/src/main/java/spoon/diff/context/Context.java b/src/main/java/spoon/diff/context/Context.java index e934b709a12..ad625ba6d1a 100644 --- a/src/main/java/spoon/diff/context/Context.java +++ b/src/main/java/spoon/diff/context/Context.java @@ -17,15 +17,22 @@ package spoon.diff.context; import spoon.reflect.declaration.CtElement; +import spoon.reflect.path.CtRole; public abstract class Context { private CtElement element; + private CtRole role; - public Context(CtElement element) { + public Context(CtElement element, CtRole role) { this.element = element; + this.role = role; } public CtElement getElement() { return element; } + + public CtRole getRole() { + return role; + } } diff --git a/src/main/java/spoon/diff/context/ListContext.java b/src/main/java/spoon/diff/context/ListContext.java index 3ae2f66f809..66e8c7674b7 100644 --- a/src/main/java/spoon/diff/context/ListContext.java +++ b/src/main/java/spoon/diff/context/ListContext.java @@ -17,19 +17,23 @@ package spoon.diff.context; import spoon.reflect.declaration.CtElement; +import spoon.reflect.path.CtRole; import java.util.List; public class ListContext extends CollectionContext> { private final int position; - public ListContext(CtElement element, List original) { - super(element, original); - this.position = -1; + public ListContext(CtElement element, CtRole role, List original) { + this(element, role, original, -1); } - public ListContext(CtElement element, List original, int position) { - super(element, original); + public ListContext(CtElement element, CtRole role, List original, int position) { + super(element, role, original); this.position = position; } + + public int getPosition() { + return position; + } } diff --git a/src/main/java/spoon/diff/context/MapContext.java b/src/main/java/spoon/diff/context/MapContext.java index e421c5908c1..289984129cd 100644 --- a/src/main/java/spoon/diff/context/MapContext.java +++ b/src/main/java/spoon/diff/context/MapContext.java @@ -17,20 +17,21 @@ package spoon.diff.context; import spoon.reflect.declaration.CtElement; +import spoon.reflect.path.CtRole; import java.util.Map; public class MapContext extends Context { private final Map map; - private K key; + private K key; - public MapContext(CtElement element, Map map) { - super(element); + public MapContext(CtElement element, CtRole role, Map map) { + super(element, role); this.map = map; } - public MapContext(CtElement element, Map map, K key) { - this(element, map); + public MapContext(CtElement element, CtRole role, Map map, K key) { + this(element, role, map); this.key = key; } diff --git a/src/main/java/spoon/diff/context/ObjectContext.java b/src/main/java/spoon/diff/context/ObjectContext.java index 43a0845d4c1..0b08d95c101 100644 --- a/src/main/java/spoon/diff/context/ObjectContext.java +++ b/src/main/java/spoon/diff/context/ObjectContext.java @@ -17,20 +17,11 @@ package spoon.diff.context; import spoon.reflect.declaration.CtElement; +import spoon.reflect.path.CtRole; public class ObjectContext extends Context { - private final String fieldName; - public ObjectContext(CtElement ctElement, String fieldName) { - super(ctElement); - this.fieldName = fieldName; + public ObjectContext(CtElement ctElement, CtRole role) { + super(ctElement, role); } - -/* - try { - final Field field = ctElement.getClass().getField(fieldName); - } catch (NoSuchFieldException e) { - throw new IllegalArgumentException("Can't find the field named by " + fieldName, e); - } -*/ } diff --git a/src/main/java/spoon/diff/context/SetContext.java b/src/main/java/spoon/diff/context/SetContext.java index cb50aa52f76..488e2d04304 100644 --- a/src/main/java/spoon/diff/context/SetContext.java +++ b/src/main/java/spoon/diff/context/SetContext.java @@ -17,11 +17,12 @@ package spoon.diff.context; import spoon.reflect.declaration.CtElement; +import spoon.reflect.path.CtRole; import java.util.Set; public class SetContext extends CollectionContext> { - public SetContext(CtElement element, Set original) { - super(element, original); + public SetContext(CtElement element, CtRole role, Set original) { + super(element, role, original); } } diff --git a/src/main/java/spoon/reflect/factory/ChangeFactory.java b/src/main/java/spoon/reflect/factory/ChangeFactory.java index eaf8b98099f..bb854a1f096 100644 --- a/src/main/java/spoon/reflect/factory/ChangeFactory.java +++ b/src/main/java/spoon/reflect/factory/ChangeFactory.java @@ -67,28 +67,28 @@ private void propagateModelChange(final Action action) { } } - public void onObjectUpdate(CtElement currentElement, CtRole role, String changedField, CtElement newValue, CtElement oldValue) { - Action action = new UpdateAction(new ObjectContext(currentElement, changedField), newValue, oldValue); + public void onObjectUpdate(CtElement currentElement, CtRole role, CtElement newValue, CtElement oldValue) { + Action action = new UpdateAction<>(new ObjectContext(currentElement, role), newValue, oldValue); propagateModelChange(action); } - public void onObjectUpdate(CtElement currentElement, CtRole role, String changedField, Object newValue, Object oldValue) { - UpdateAction action = new UpdateAction(new ObjectContext(currentElement, changedField), newValue, oldValue); + public void onObjectUpdate(CtElement currentElement, CtRole role, Object newValue, Object oldValue) { + UpdateAction action = new UpdateAction<>(new ObjectContext(currentElement, role), newValue, oldValue); propagateModelChange(action); } - public void onObjectDelete(CtElement currentElement, CtRole role, String changedField, CtElement oldValue) { - DeleteAction action = new DeleteAction(new ObjectContext(currentElement, changedField), oldValue); + public void onObjectDelete(CtElement currentElement, CtRole role, CtElement oldValue) { + DeleteAction action = new DeleteAction<>(new ObjectContext(currentElement, role), oldValue); propagateModelChange(action); } public void onListAdd(CtElement currentElement, CtRole role, List field, CtElement newValue) { - AddAction action = new AddAction(new ListContext(currentElement, field), newValue); + AddAction action = new AddAction<>(new ListContext(currentElement, role,field), newValue); propagateModelChange(action); } public void onListAdd(CtElement currentElement, CtRole role, List field, int index, CtElement newValue) { - AddAction action = new AddAction(new ListContext(currentElement, field, index), newValue); + AddAction action = new AddAction<>(new ListContext(currentElement, role, field, index), newValue); propagateModelChange(action); } @@ -102,40 +102,40 @@ public void onListDelete(CtElement currentElement, CtRole role, List field, Coll } public void onListDelete(CtElement currentElement, CtRole role, List field, int index, CtElement oldValue) { - DeleteAction action = new DeleteAction(new ListContext(currentElement, field, index), oldValue); + DeleteAction action = new DeleteAction<>(new ListContext(currentElement, role, field, index), oldValue); propagateModelChange(action); } public void onListDeleteAll(CtElement currentElement, CtRole role, List field, List oldValue) { - DeleteAllAction action = new DeleteAllAction(new ListContext(currentElement, field), oldValue); + DeleteAllAction action = new DeleteAllAction(new ListContext(currentElement, role, field), oldValue); propagateModelChange(action); } public void onMapAdd(CtElement currentElement, CtRole role, Map field, K key, CtElement newValue) { - AddAction action = new AddAction(new MapContext<>(currentElement, field, key), newValue); + AddAction action = new AddAction<>(new MapContext<>(currentElement, role, field, key), newValue); propagateModelChange(action); } public void onMapDeleteAll(CtElement currentElement, CtRole role, Map field, Map oldValue) { - DeleteAllAction action = new DeleteAllAction(new MapContext<>(currentElement, field), oldValue); + DeleteAllAction action = new DeleteAllAction(new MapContext<>(currentElement, role, field), oldValue); propagateModelChange(action); } public void onSetAdd(CtElement currentElement, CtRole role, Set field, CtElement newValue) { - AddAction action = new AddAction(new SetContext(currentElement, field), newValue); + AddAction action = new AddAction<>(new SetContext(currentElement, role, field), newValue); propagateModelChange(action); } public void onSetAdd(CtElement currentElement, CtRole role, Set field, ModifierKind newValue) { - AddAction action = new AddAction(new SetContext(currentElement, field), newValue); + AddAction action = new AddAction<>(new SetContext(currentElement, role, field), newValue); propagateModelChange(action); } public void onSetDelete(CtElement currentElement, CtRole role, Set field, CtElement oldValue) { - DeleteAction action = new DeleteAction(new SetContext(currentElement, field), oldValue); + DeleteAction action = new DeleteAction<>(new SetContext(currentElement, role, field), oldValue); propagateModelChange(action); } @@ -148,12 +148,12 @@ public void onSetDelete(CtElement currentElement, CtRole role, Set field, Collec } public void onSetDelete(CtElement currentElement, CtRole role, Set field, ModifierKind oldValue) { - DeleteAction action = new DeleteAction(new SetContext(currentElement, field), oldValue); + DeleteAction action = new DeleteAction(new SetContext(currentElement, role, field), oldValue); propagateModelChange(action); } public void onSetDeleteAll(CtElement currentElement, CtRole role, Set field, Set oldValue) { - DeleteAllAction action = new DeleteAllAction(new SetContext(currentElement, field), oldValue); + DeleteAllAction action = new DeleteAllAction(new SetContext(currentElement, role, field), oldValue); propagateModelChange(action); } } diff --git a/src/main/java/spoon/support/StandardEnvironment.java b/src/main/java/spoon/support/StandardEnvironment.java index eaa57a9350c..ddc638c0349 100644 --- a/src/main/java/spoon/support/StandardEnvironment.java +++ b/src/main/java/spoon/support/StandardEnvironment.java @@ -26,6 +26,7 @@ import spoon.compiler.SpoonFolder; import spoon.diff.AbstractModelChangeListener; import spoon.diff.Action; +import spoon.diff.UpdateAction; import spoon.processing.FileGenerator; import spoon.processing.ProblemFixer; import spoon.processing.ProcessingManager; @@ -181,6 +182,11 @@ public void setBuildStackChanges(boolean buildStackChanges) { @Override public void pushToStack(Action action) { + if (action instanceof UpdateAction) { + if (((UpdateAction) action).getOldElement() == ((UpdateAction) action).getNewElement()) { + return; + } + } actions.push(action); } From 89a8ec69d31551c4ab86a2af69257b1deadb9a96 Mon Sep 17 00:00:00 2001 From: tdurieux Date: Mon, 5 Jun 2017 22:36:35 +0200 Subject: [PATCH 06/40] new version of the stack collector --- src/main/java/spoon/reflect/path/CtRole.java | 9 +- .../reflect/code/CtArrayAccessImpl.java | 8 +- .../support/reflect/code/CtAssertImpl.java | 13 +- .../reflect/code/CtAssignmentImpl.java | 31 ++--- .../reflect/code/CtBinaryOperatorImpl.java | 18 ++- .../support/reflect/code/CtBlockImpl.java | 23 +--- .../support/reflect/code/CtBreakImpl.java | 10 +- .../support/reflect/code/CtCaseImpl.java | 27 +--- .../support/reflect/code/CtCatchImpl.java | 18 +-- .../reflect/code/CtCatchVariableImpl.java | 54 +++----- .../code/CtCodeSnippetExpressionImpl.java | 8 +- .../code/CtCodeSnippetStatementImpl.java | 8 +- .../support/reflect/code/CtCommentImpl.java | 13 +- .../reflect/code/CtConditionalImpl.java | 18 ++- .../reflect/code/CtConstructorCallImpl.java | 31 ++--- .../support/reflect/code/CtContinueImpl.java | 10 +- .../spoon/support/reflect/code/CtDoImpl.java | 8 +- .../CtExecutableReferenceExpressionImpl.java | 8 +- .../reflect/code/CtExpressionImpl.java | 21 +--- .../reflect/code/CtFieldAccessImpl.java | 8 +- .../support/reflect/code/CtForEachImpl.java | 13 +- .../spoon/support/reflect/code/CtForImpl.java | 43 ++----- .../spoon/support/reflect/code/CtIfImpl.java | 18 ++- .../reflect/code/CtInvocationImpl.java | 32 ++--- .../support/reflect/code/CtJavaDocImpl.java | 30 ++--- .../reflect/code/CtJavaDocTagImpl.java | 18 ++- .../support/reflect/code/CtLambdaImpl.java | 58 +++------ .../support/reflect/code/CtLiteralImpl.java | 8 +- .../reflect/code/CtLocalVariableImpl.java | 45 +++---- .../support/reflect/code/CtLoopImpl.java | 13 +- .../support/reflect/code/CtNewArrayImpl.java | 36 ++---- .../support/reflect/code/CtNewClassImpl.java | 8 +- .../code/CtOperatorAssignmentImpl.java | 8 +- .../support/reflect/code/CtReturnImpl.java | 8 +- .../support/reflect/code/CtStatementImpl.java | 8 +- .../reflect/code/CtStatementListImpl.java | 20 +-- .../reflect/code/CtSuperAccessImpl.java | 8 +- .../support/reflect/code/CtSwitchImpl.java | 27 +--- .../reflect/code/CtSynchronizedImpl.java | 13 +- .../code/CtTargetedExpressionImpl.java | 8 +- .../support/reflect/code/CtThrowImpl.java | 8 +- .../spoon/support/reflect/code/CtTryImpl.java | 36 ++---- .../reflect/code/CtTryWithResourceImpl.java | 20 +-- .../reflect/code/CtTypeAccessImpl.java | 8 +- .../reflect/code/CtUnaryOperatorImpl.java | 18 ++- .../reflect/code/CtVariableAccessImpl.java | 8 +- .../support/reflect/code/CtWhileImpl.java | 8 +- .../reflect/declaration/CtAnnotationImpl.java | 31 ++--- .../declaration/CtAnnotationMethodImpl.java | 8 +- .../CtAnonymousExecutableImpl.java | 19 +-- .../reflect/declaration/CtClassImpl.java | 36 ++---- .../declaration/CtConstructorImpl.java | 47 +++---- .../reflect/declaration/CtElementImpl.java | 49 ++------ .../reflect/declaration/CtEnumImpl.java | 20 +-- .../reflect/declaration/CtExecutableImpl.java | 49 ++------ .../reflect/declaration/CtFieldImpl.java | 45 +++---- .../reflect/declaration/CtMethodImpl.java | 50 +++----- .../declaration/CtNamedElementImpl.java | 8 +- .../reflect/declaration/CtPackageImpl.java | 45 ++----- .../reflect/declaration/CtParameterImpl.java | 45 +++---- .../reflect/declaration/CtTypeImpl.java | 119 ++++++++---------- .../declaration/CtTypeParameterImpl.java | 8 +- .../reference/CtArrayTypeReferenceImpl.java | 8 +- .../reference/CtExecutableReferenceImpl.java | 47 ++----- .../reference/CtFieldReferenceImpl.java | 18 ++- .../CtIntersectionTypeReferenceImpl.java | 20 +-- .../reference/CtParameterReferenceImpl.java | 8 +- .../reflect/reference/CtReferenceImpl.java | 8 +- .../CtTypeParameterReferenceImpl.java | 13 +- .../reference/CtTypeReferenceImpl.java | 37 ++---- .../reference/CtVariableReferenceImpl.java | 8 +- 71 files changed, 497 insertions(+), 1121 deletions(-) diff --git a/src/main/java/spoon/reflect/path/CtRole.java b/src/main/java/spoon/reflect/path/CtRole.java index ad72d75bade..c247e76b5ab 100644 --- a/src/main/java/spoon/reflect/path/CtRole.java +++ b/src/main/java/spoon/reflect/path/CtRole.java @@ -24,16 +24,17 @@ public enum CtRole { TYPE, BODY, IS_SHADOW, - //BOUND, // in reference only - //IS_FINAL, // in reference only - //IS_STATIC, // in reference only - //IS_UPPER, // in reference only + BOUND, // in reference only + IS_FINAL, // in reference only + IS_STATIC, // in reference only + IS_UPPER, // in reference only IS_IMPLICIT, IS_DEFAULT, IS_VARARGS, DEFAULT_EXPRESSION, THEN, ELSE, + PACKAGE_REF, SUB_PACKAGE, CONDITION, RIGHT_OPERAND, diff --git a/src/main/java/spoon/support/reflect/code/CtArrayAccessImpl.java b/src/main/java/spoon/support/reflect/code/CtArrayAccessImpl.java index 60a40d48ea8..4d470941cb4 100644 --- a/src/main/java/spoon/support/reflect/code/CtArrayAccessImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtArrayAccessImpl.java @@ -16,13 +16,13 @@ */ package spoon.support.reflect.code; -import spoon.diff.UpdateAction; -import spoon.diff.context.ObjectContext; import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.code.CtArrayAccess; import spoon.reflect.code.CtExpression; import spoon.reflect.path.CtRole; +import static spoon.reflect.path.CtRole.EXPRESSION; + public abstract class CtArrayAccessImpl> extends CtTargetedExpressionImpl implements CtArrayAccess { private static final long serialVersionUID = 1L; @@ -39,9 +39,7 @@ public > C setIndexExpression(CtExpression extends CtStatementImpl implements CtAssert { private static final long serialVersionUID = 1L; @@ -48,9 +49,7 @@ public > A setAssertExpression(CtExpression asser if (asserted != null) { asserted.setParent(this); } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "asserted"), asserted, this.asserted)); - } + getFactory().Change().onObjectUpdate(this, CONDITION, asserted, this.asserted); this.asserted = asserted; return (A) this; } @@ -65,9 +64,7 @@ public > A setExpression(CtExpression value) { if (value != null) { value.setParent(this); } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "value"), value, this.value)); - } + getFactory().Change().onObjectUpdate(this, EXPRESSION, value, this.value); this.value = value; return (A) this; } diff --git a/src/main/java/spoon/support/reflect/code/CtAssignmentImpl.java b/src/main/java/spoon/support/reflect/code/CtAssignmentImpl.java index f266f7067b2..74e5eecf08b 100644 --- a/src/main/java/spoon/support/reflect/code/CtAssignmentImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtAssignmentImpl.java @@ -16,11 +16,6 @@ */ package spoon.support.reflect.code; -import spoon.diff.AddAction; -import spoon.diff.DeleteAllAction; -import spoon.diff.UpdateAction; -import spoon.diff.context.ListContext; -import spoon.diff.context.ObjectContext; import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.code.CtAssignment; import spoon.reflect.code.CtExpression; @@ -36,6 +31,10 @@ import java.util.List; import static spoon.reflect.ModelElementContainerDefaultCapacities.CASTS_CONTAINER_DEFAULT_CAPACITY; +import static spoon.reflect.path.CtRole.ASSIGNED; +import static spoon.reflect.path.CtRole.ASSIGNMENT; +import static spoon.reflect.path.CtRole.CAST; +import static spoon.reflect.path.CtRole.TYPE; public class CtAssignmentImpl extends CtStatementImpl implements CtAssignment { private static final long serialVersionUID = 1L; @@ -82,9 +81,7 @@ public > C setAssigned(CtExpression assigned) { if (assigned != null) { assigned.setParent(this); } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "assigned"), assigned, this.assigned)); - } + getFactory().Change().onObjectUpdate(this, ASSIGNED, assigned, this.assigned); this.assigned = assigned; return (C) this; } @@ -94,9 +91,7 @@ public > C setAssignment(CtExpression assignment) if (assignment != null) { assignment.setParent(this); } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "assignment"), assignment, this.assignment)); - } + getFactory().Change().onObjectUpdate(this, ASSIGNMENT, assignment, this.assignment); this.assignment = assignment; return (C) this; } @@ -106,9 +101,7 @@ public C setType(CtTypeReference type) { if (type != null) { type.setParent(this); } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "type"), type, this.type)); - } + getFactory().Change().onObjectUpdate(this, TYPE, type, this.type); this.type = type; return (C) this; } @@ -122,10 +115,7 @@ public > C setTypeCasts(List> casts if (this.typeCasts == CtElementImpl.>emptyList()) { this.typeCasts = new ArrayList<>(CASTS_CONTAINER_DEFAULT_CAPACITY); } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new DeleteAllAction(new ListContext( - this, this.typeCasts), new ArrayList<>(this.typeCasts))); - } + getFactory().Change().onListDeleteAll(this, CAST, this.typeCasts, new ArrayList<>(this.typeCasts)); this.typeCasts.clear(); for (CtTypeReference cast : casts) { addTypeCast(cast); @@ -142,10 +132,7 @@ public > C addTypeCast(CtTypeReference type) { typeCasts = new ArrayList<>(CASTS_CONTAINER_DEFAULT_CAPACITY); } type.setParent(this); - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new AddAction(new ListContext( - this, typeCasts), type)); - } + getFactory().Change().onListAdd(this, CAST, typeCasts, type); typeCasts.add(type); return (C) this; } diff --git a/src/main/java/spoon/support/reflect/code/CtBinaryOperatorImpl.java b/src/main/java/spoon/support/reflect/code/CtBinaryOperatorImpl.java index a7307ffa4a0..b4890852b90 100644 --- a/src/main/java/spoon/support/reflect/code/CtBinaryOperatorImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtBinaryOperatorImpl.java @@ -16,8 +16,6 @@ */ package spoon.support.reflect.code; -import spoon.diff.UpdateAction; -import spoon.diff.context.ObjectContext; import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.code.BinaryOperatorKind; import spoon.reflect.code.CtBinaryOperator; @@ -25,6 +23,10 @@ import spoon.reflect.path.CtRole; import spoon.reflect.visitor.CtVisitor; +import static spoon.reflect.path.CtRole.LEFT_OPERAND; +import static spoon.reflect.path.CtRole.OPERATOR_KIND; +import static spoon.reflect.path.CtRole.RIGHT_OPERAND; + public class CtBinaryOperatorImpl extends CtExpressionImpl implements CtBinaryOperator { private static final long serialVersionUID = 1L; @@ -57,9 +59,7 @@ public > C setLeftHandOperand(CtExpression expr if (expression != null) { expression.setParent(this); } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "leftHandOperand"), expression, this.leftHandOperand)); - } + getFactory().Change().onObjectUpdate(this, LEFT_OPERAND, expression, this.leftHandOperand); leftHandOperand = expression; return (C) this; } @@ -69,18 +69,14 @@ public > C setRightHandOperand(CtExpression exp if (expression != null) { expression.setParent(this); } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "rightHandOperand"), expression, this.rightHandOperand)); - } + getFactory().Change().onObjectUpdate(this, RIGHT_OPERAND, expression, this.rightHandOperand); rightHandOperand = expression; return (C) this; } @Override public > C setKind(BinaryOperatorKind kind) { - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "kind"), kind, this.kind)); - } + getFactory().Change().onObjectUpdate(this, OPERATOR_KIND, kind, this.kind); this.kind = kind; return (C) this; } diff --git a/src/main/java/spoon/support/reflect/code/CtBlockImpl.java b/src/main/java/spoon/support/reflect/code/CtBlockImpl.java index d2f84d04cfa..c88baf0a879 100644 --- a/src/main/java/spoon/support/reflect/code/CtBlockImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtBlockImpl.java @@ -16,10 +16,6 @@ */ package spoon.support.reflect.code; -import spoon.diff.AddAction; -import spoon.diff.DeleteAction; -import spoon.diff.DeleteAllAction; -import spoon.diff.context.ListContext; import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.code.CtBlock; import spoon.reflect.code.CtInvocation; @@ -41,6 +37,7 @@ import java.util.List; import static spoon.reflect.ModelElementContainerDefaultCapacities.BLOCK_STATEMENTS_CONTAINER_DEFAULT_CAPACITY; +import static spoon.reflect.path.CtRole.STATEMENT; public class CtBlockImpl extends CtStatementImpl implements CtBlock { private static final long serialVersionUID = 1L; @@ -167,10 +164,7 @@ public T setStatements(List statements) this.statements = CtElementImpl.emptyList(); return (T) this; } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new DeleteAllAction(new ListContext( - this, this.statements), new ArrayList<>(this.statements))); - } + getFactory().Change().onListDeleteAll(this, STATEMENT, this.statements, new ArrayList<>(this.statements)); this.statements.clear(); for (CtStatement s : statements) { addStatement(s); @@ -185,10 +179,7 @@ public T addStatement(CtStatement statement) { } ensureModifiableStatementsList(); statement.setParent(this); - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new AddAction(new ListContext( - this, this.statements), statement)); - } + getFactory().Change().onListAdd(this, STATEMENT, this.statements, statement); this.statements.add(statement); if (isImplicit() && this.statements.size() > 1) { setImplicit(false); @@ -210,9 +201,7 @@ public void removeStatement(CtStatement statement) { // and a block can have twice exactly the same statement. for (int i = 0; i < this.statements.size(); i++) { if (this.statements.get(i) == statement) { - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new DeleteAction(new ListContext(this, statements, i), statement)); - } + getFactory().Change().onListDelete(this, STATEMENT, statements, i, statement); this.statements.remove(i); hasBeenRemoved = true; break; @@ -221,9 +210,7 @@ public void removeStatement(CtStatement statement) { // in case we use it with a statement manually built if (!hasBeenRemoved) { - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new DeleteAction(new ListContext(this, statements, statements.indexOf(statement)), statement)); - } + getFactory().Change().onListDelete(this, STATEMENT, statements, statements.indexOf(statement), statement); this.statements.remove(statement); } diff --git a/src/main/java/spoon/support/reflect/code/CtBreakImpl.java b/src/main/java/spoon/support/reflect/code/CtBreakImpl.java index 8b5b71a1b85..f92e851413e 100644 --- a/src/main/java/spoon/support/reflect/code/CtBreakImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtBreakImpl.java @@ -16,11 +16,9 @@ */ package spoon.support.reflect.code; -import spoon.reflect.code.CtLabelledFlowBreak; -import spoon.diff.UpdateAction; -import spoon.diff.context.ObjectContext; import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.code.CtBreak; +import spoon.reflect.code.CtLabelledFlowBreak; import spoon.reflect.code.CtStatement; import spoon.reflect.declaration.CtElement; import spoon.reflect.path.CtRole; @@ -29,6 +27,8 @@ import java.util.List; +import static spoon.reflect.path.CtRole.TARGET_LABEL; + public class CtBreakImpl extends CtStatementImpl implements CtBreak { private static final long serialVersionUID = 1L; @@ -47,9 +47,7 @@ public String getTargetLabel() { @Override public T setTargetLabel(String targetLabel) { - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "targetLabel"), targetLabel, this.targetLabel)); - } + getFactory().Change().onObjectUpdate(this, TARGET_LABEL, targetLabel, this.targetLabel); this.targetLabel = targetLabel; return (T) this; } diff --git a/src/main/java/spoon/support/reflect/code/CtCaseImpl.java b/src/main/java/spoon/support/reflect/code/CtCaseImpl.java index 899c32bcc71..fb54277f2f1 100644 --- a/src/main/java/spoon/support/reflect/code/CtCaseImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtCaseImpl.java @@ -16,12 +16,6 @@ */ package spoon.support.reflect.code; -import spoon.diff.AddAction; -import spoon.diff.DeleteAction; -import spoon.diff.DeleteAllAction; -import spoon.diff.UpdateAction; -import spoon.diff.context.ListContext; -import spoon.diff.context.ObjectContext; import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.code.CtCase; import spoon.reflect.code.CtExpression; @@ -36,6 +30,8 @@ import java.util.List; import static spoon.reflect.ModelElementContainerDefaultCapacities.CASE_STATEMENTS_CONTAINER_DEFAULT_CAPACITY; +import static spoon.reflect.path.CtRole.CASE; +import static spoon.reflect.path.CtRole.STATEMENT; public class CtCaseImpl extends CtStatementImpl implements CtCase { private static final long serialVersionUID = 1L; @@ -66,9 +62,7 @@ public > T setCaseExpression(CtExpression caseExpression) if (caseExpression != null) { caseExpression.setParent(this); } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "caseExpression"), caseExpression, this.caseExpression)); - } + getFactory().Change().onObjectUpdate(this, CASE, caseExpression, this.caseExpression); this.caseExpression = caseExpression; return (T) this; } @@ -79,10 +73,7 @@ public T setStatements(List statements) this.statements = CtElementImpl.emptyList(); return (T) this; } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new DeleteAllAction(new ListContext( - this, this.statements), new ArrayList<>(this.statements))); - } + getFactory().Change().onListDeleteAll(this, STATEMENT, this.statements, new ArrayList<>(this.statements)); this.statements.clear(); for (CtStatement stmt : statements) { addStatement(stmt); @@ -99,10 +90,7 @@ public T addStatement(CtStatement statement) { statements = new ArrayList<>(CASE_STATEMENTS_CONTAINER_DEFAULT_CAPACITY); } statement.setParent(this); - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new AddAction(new ListContext( - this, this.statements), statement)); - } + getFactory().Change().onListAdd(this, STATEMENT, this.statements, statement); statements.add(statement); return (T) this; } @@ -112,10 +100,7 @@ public void removeStatement(CtStatement statement) { if (statements == CtElementImpl.emptyList()) { return; } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new DeleteAction(new ListContext( - this, statements, statements.indexOf(statement)), statement)); - } + getFactory().Change().onListDelete(this, STATEMENT, statements, statements.indexOf(statement), statement); statements.remove(statement); } diff --git a/src/main/java/spoon/support/reflect/code/CtCatchImpl.java b/src/main/java/spoon/support/reflect/code/CtCatchImpl.java index 2422f9696bb..2b8e676fbc9 100644 --- a/src/main/java/spoon/support/reflect/code/CtCatchImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtCatchImpl.java @@ -16,9 +16,6 @@ */ package spoon.support.reflect.code; -import spoon.diff.DeleteAction; -import spoon.diff.UpdateAction; -import spoon.diff.context.ObjectContext; import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.code.CtBlock; import spoon.reflect.code.CtBodyHolder; @@ -28,6 +25,9 @@ import spoon.reflect.path.CtRole; import spoon.reflect.visitor.CtVisitor; +import static spoon.reflect.path.CtRole.BODY; +import static spoon.reflect.path.CtRole.PARAMETER; + public class CtCatchImpl extends CtCodeElementImpl implements CtCatch { private static final long serialVersionUID = 1L; @@ -56,17 +56,13 @@ public CtCatchVariable getParameter() { public T setBody(CtStatement statement) { if (statement != null) { CtBlock body = getFactory().Code().getOrCreateCtBlock(statement); - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "body"), body, this.body)); - } + getFactory().Change().onObjectUpdate(this, BODY, body, this.body); if (body != null) { body.setParent(this); } this.body = body; } else { - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new DeleteAction(new ObjectContext(this, "body"), this.body)); - } + getFactory().Change().onObjectDelete(this, BODY, this.body); this.body = null; } @@ -78,9 +74,7 @@ public T setParameter(CtCatchVariable p if (parameter != null) { parameter.setParent(this); } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "parameter"), parameter, this.parameter)); - } + getFactory().Change().onObjectUpdate(this, PARAMETER, parameter, this.parameter); this.parameter = parameter; return (T) this; } diff --git a/src/main/java/spoon/support/reflect/code/CtCatchVariableImpl.java b/src/main/java/spoon/support/reflect/code/CtCatchVariableImpl.java index c057b6a1e89..8b014e8b486 100644 --- a/src/main/java/spoon/support/reflect/code/CtCatchVariableImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtCatchVariableImpl.java @@ -16,13 +16,6 @@ */ package spoon.support.reflect.code; -import spoon.diff.AddAction; -import spoon.diff.DeleteAction; -import spoon.diff.DeleteAllAction; -import spoon.diff.UpdateAction; -import spoon.diff.context.ListContext; -import spoon.diff.context.ObjectContext; -import spoon.diff.context.SetContext; import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.code.CtCatchVariable; import spoon.reflect.code.CtExpression; @@ -47,6 +40,9 @@ import java.util.Set; import static spoon.reflect.ModelElementContainerDefaultCapacities.CATCH_VARIABLE_MULTI_TYPES_CONTAINER_DEFAULT_CAPACITY; +import static spoon.reflect.path.CtRole.MODIFIER; +import static spoon.reflect.path.CtRole.NAME; +import static spoon.reflect.path.CtRole.TYPE; public class CtCatchVariableImpl extends CtCodeElementImpl implements CtCatchVariable { private static final long serialVersionUID = 1L; @@ -98,9 +94,7 @@ public > C setDefaultExpression(CtExpression defaultE @Override public C setSimpleName(String simpleName) { - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "name"), simpleName, this.name)); - } + getFactory().Change().onObjectUpdate(this, NAME, simpleName, this.name); this.name = simpleName; return (C) this; } @@ -110,9 +104,7 @@ public C setType(CtTypeReference type) { if (type != null) { type.setParent(this); } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "type"), type, this.type)); - } + getFactory().Change().onObjectUpdate(this, TYPE, type, this.type); this.type = type; return (C) this; } @@ -126,10 +118,7 @@ public T addMultiType(CtTypeReference type) { types = new ArrayList<>(CATCH_VARIABLE_MULTI_TYPES_CONTAINER_DEFAULT_CAPACITY); } type.setParent(this); - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new AddAction(new ListContext( - this, this.types), type)); - } + getFactory().Change().onListAdd(this, TYPE, this.types, type); types.add(type); return (T) this; } @@ -139,10 +128,7 @@ public boolean removeMultiType(CtTypeReference ref) { if (this.types == CtElementImpl.>emptyList()) { return false; } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new DeleteAction(new ListContext( - this, types, types.indexOf(ref)), ref)); - } + getFactory().Change().onListDelete(this, TYPE, types, types.indexOf(ref), ref); return types.remove(ref); } @@ -153,9 +139,7 @@ public List> getMultiTypes() { @Override public T setMultiTypes(List> types) { - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new DeleteAllAction(new ListContext(this, this.types), new ArrayList<>(this.types))); - } + getFactory().Change().onListDeleteAll(this, TYPE, this.types, new ArrayList<>(this.types)); if (types == null || types.isEmpty()) { this.types = CtElementImpl.emptyList(); return (T) this; @@ -183,9 +167,7 @@ public boolean hasModifier(ModifierKind modifier) { @Override public C setModifiers(Set modifiers) { if (modifiers.size() > 0) { - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new DeleteAllAction(new SetContext(this, this.modifiers), new HashSet<>(this.modifiers))); - } + getFactory().Change().onSetDeleteAll(this, MODIFIER, this.modifiers, new HashSet<>(this.modifiers)); this.modifiers.clear(); for (ModifierKind modifier : modifiers) { addModifier(modifier); @@ -199,10 +181,7 @@ public C addModifier(ModifierKind modifier) { if (modifiers == CtElementImpl.emptySet()) { this.modifiers = EnumSet.noneOf(ModifierKind.class); } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new AddAction(new SetContext( - this, this.modifiers), modifier)); - } + getFactory().Change().onSetAdd(this, MODIFIER, this.modifiers, modifier); modifiers.add(modifier); return (C) this; } @@ -212,10 +191,7 @@ public boolean removeModifier(ModifierKind modifier) { if (modifiers == CtElementImpl.emptySet()) { return false; } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new DeleteAction(new SetContext( - this, modifiers), modifier)); - } + getFactory().Change().onSetDelete(this, MODIFIER, modifiers, modifier); return modifiers.remove(modifier); } @@ -224,10 +200,10 @@ public C setVisibility(ModifierKind visibility) { if (modifiers == CtElementImpl.emptySet()) { this.modifiers = EnumSet.noneOf(ModifierKind.class); } - getModifiers().remove(ModifierKind.PUBLIC); - getModifiers().remove(ModifierKind.PROTECTED); - getModifiers().remove(ModifierKind.PRIVATE); - getModifiers().add(visibility); + removeModifier(ModifierKind.PUBLIC); + removeModifier(ModifierKind.PROTECTED); + removeModifier(ModifierKind.PRIVATE); + addModifier(visibility); return (C) this; } diff --git a/src/main/java/spoon/support/reflect/code/CtCodeSnippetExpressionImpl.java b/src/main/java/spoon/support/reflect/code/CtCodeSnippetExpressionImpl.java index b56fb5231b6..fe2de6de1a0 100644 --- a/src/main/java/spoon/support/reflect/code/CtCodeSnippetExpressionImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtCodeSnippetExpressionImpl.java @@ -16,8 +16,6 @@ */ package spoon.support.reflect.code; -import spoon.diff.UpdateAction; -import spoon.diff.context.ObjectContext; import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.code.CtCodeSnippetExpression; import spoon.reflect.code.CtExpression; @@ -27,6 +25,8 @@ import spoon.support.compiler.SnippetCompilationError; import spoon.support.compiler.SnippetCompilationHelper; +import static spoon.reflect.path.CtRole.EXPRESSION; + public class CtCodeSnippetExpressionImpl extends CtExpressionImpl implements CtCodeSnippetExpression { private static final long serialVersionUID = 1L; @@ -43,9 +43,7 @@ public String getValue() { } public C setValue(String value) { - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "value"), value, this.value)); - } + getFactory().Change().onObjectUpdate(this, EXPRESSION, value, this.value); this.value = value; return (C) this; } diff --git a/src/main/java/spoon/support/reflect/code/CtCodeSnippetStatementImpl.java b/src/main/java/spoon/support/reflect/code/CtCodeSnippetStatementImpl.java index 6d701e94265..15895ec2606 100644 --- a/src/main/java/spoon/support/reflect/code/CtCodeSnippetStatementImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtCodeSnippetStatementImpl.java @@ -16,8 +16,6 @@ */ package spoon.support.reflect.code; -import spoon.diff.UpdateAction; -import spoon.diff.context.ObjectContext; import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.code.CtCodeSnippetStatement; import spoon.reflect.code.CtStatement; @@ -27,6 +25,8 @@ import spoon.support.compiler.SnippetCompilationError; import spoon.support.compiler.SnippetCompilationHelper; +import static spoon.reflect.path.CtRole.EXPRESSION; + public class CtCodeSnippetStatementImpl extends CtStatementImpl implements CtCodeSnippetStatement { private static final long serialVersionUID = 1L; @@ -43,9 +43,7 @@ public String getValue() { } public C setValue(String value) { - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "value"), value, this.value)); - } + getFactory().Change().onObjectUpdate(this, EXPRESSION, value, this.value); this.value = value; return (C) this; } diff --git a/src/main/java/spoon/support/reflect/code/CtCommentImpl.java b/src/main/java/spoon/support/reflect/code/CtCommentImpl.java index 04f3eececd8..ee3f7cee0ae 100644 --- a/src/main/java/spoon/support/reflect/code/CtCommentImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtCommentImpl.java @@ -16,13 +16,14 @@ */ package spoon.support.reflect.code; -import spoon.diff.UpdateAction; -import spoon.diff.context.ObjectContext; import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.code.CtComment; import spoon.reflect.path.CtRole; import spoon.reflect.visitor.CtVisitor; +import static spoon.reflect.path.CtRole.COMMENT_CONTENT; +import static spoon.reflect.path.CtRole.TYPE; + public class CtCommentImpl extends CtStatementImpl implements CtComment { private static final long serialVersionUID = 1L; @@ -46,9 +47,7 @@ public String getContent() { @Override public E setContent(String content) { - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "content"), content, this.content)); - } + getFactory().Change().onObjectUpdate(this, COMMENT_CONTENT, content, this.content); this.content = content; return (E) this; } @@ -60,9 +59,7 @@ public CommentType getCommentType() { @Override public E setCommentType(CommentType commentType) { - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "type"), commentType, this.type)); - } + getFactory().Change().onObjectUpdate(this, TYPE, commentType, this.type); type = commentType; return (E) this; } diff --git a/src/main/java/spoon/support/reflect/code/CtConditionalImpl.java b/src/main/java/spoon/support/reflect/code/CtConditionalImpl.java index bd854fa8039..d1a5f0234dd 100644 --- a/src/main/java/spoon/support/reflect/code/CtConditionalImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtConditionalImpl.java @@ -16,14 +16,16 @@ */ package spoon.support.reflect.code; -import spoon.diff.UpdateAction; -import spoon.diff.context.ObjectContext; import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.code.CtConditional; import spoon.reflect.code.CtExpression; import spoon.reflect.path.CtRole; import spoon.reflect.visitor.CtVisitor; +import static spoon.reflect.path.CtRole.CONDITION; +import static spoon.reflect.path.CtRole.ELSE; +import static spoon.reflect.path.CtRole.THEN; + public class CtConditionalImpl extends CtExpressionImpl implements CtConditional { private static final long serialVersionUID = 1L; @@ -61,9 +63,7 @@ public > C setElseExpression(CtExpression elseExpr if (elseExpression != null) { elseExpression.setParent(this); } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "elseExpression"), elseExpression, this.elseExpression)); - } + getFactory().Change().onObjectUpdate(this, ELSE, elseExpression, this.elseExpression); this.elseExpression = elseExpression; return (C) this; } @@ -73,9 +73,7 @@ public > C setCondition(CtExpression conditi if (condition != null) { condition.setParent(this); } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "condition"), condition, this.condition)); - } + getFactory().Change().onObjectUpdate(this, CONDITION, condition, this.condition); this.condition = condition; return (C) this; } @@ -85,9 +83,7 @@ public > C setThenExpression(CtExpression thenExpr if (thenExpression != null) { thenExpression.setParent(this); } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "thenExpression"), thenExpression, this.thenExpression)); - } + getFactory().Change().onObjectUpdate(this, THEN, thenExpression, this.thenExpression); this.thenExpression = thenExpression; return (C) this; } diff --git a/src/main/java/spoon/support/reflect/code/CtConstructorCallImpl.java b/src/main/java/spoon/support/reflect/code/CtConstructorCallImpl.java index 54ab61d923d..d3c20246e0b 100644 --- a/src/main/java/spoon/support/reflect/code/CtConstructorCallImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtConstructorCallImpl.java @@ -16,12 +16,6 @@ */ package spoon.support.reflect.code; -import spoon.diff.AddAction; -import spoon.diff.DeleteAction; -import spoon.diff.DeleteAllAction; -import spoon.diff.UpdateAction; -import spoon.diff.context.ListContext; -import spoon.diff.context.ObjectContext; import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.code.CtAbstractInvocation; import spoon.reflect.code.CtConstructorCall; @@ -42,6 +36,9 @@ import java.util.List; import static spoon.reflect.ModelElementContainerDefaultCapacities.PARAMETERS_CONTAINER_DEFAULT_CAPACITY; +import static spoon.reflect.path.CtRole.ARGUMENT; +import static spoon.reflect.path.CtRole.EXECUTABLE; +import static spoon.reflect.path.CtRole.LABEL; public class CtConstructorCallImpl extends CtTargetedExpressionImpl> implements CtConstructorCall { private static final long serialVersionUID = 1L; @@ -109,10 +106,7 @@ public > C setArguments(List> if (this.arguments == CtElementImpl.>emptyList()) { this.arguments = new ArrayList<>(PARAMETERS_CONTAINER_DEFAULT_CAPACITY); } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new DeleteAllAction(new ListContext( - this, this.arguments), new ArrayList<>(this.arguments))); - } + getFactory().Change().onListDeleteAll(this, ARGUMENT, this.arguments, new ArrayList<>(this.arguments)); this.arguments.clear(); for (CtExpression expr : arguments) { addArgument(expr); @@ -129,9 +123,7 @@ public > C addArgument(int position, CtExpress arguments = new ArrayList<>(PARAMETERS_CONTAINER_DEFAULT_CAPACITY); } argument.setParent(this); - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new AddAction(new ListContext(this, this.arguments, position), argument)); - } + getFactory().Change().onListAdd(this, ARGUMENT, this.arguments, position, argument); arguments.add(position, argument); return (C) this; } @@ -146,10 +138,7 @@ public boolean removeArgument(CtExpression argument) { if (arguments == CtElementImpl.>emptyList()) { return false; } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new DeleteAction(new ListContext( - this, arguments, arguments.indexOf(argument)), argument)); - } + getFactory().Change().onListDelete(this, ARGUMENT, arguments, arguments.indexOf(argument), argument); return arguments.remove(argument); } @@ -158,18 +147,14 @@ public > C setExecutable(CtExecutableReference if (executable != null) { executable.setParent(this); } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "executable"), executable, this.executable)); - } + getFactory().Change().onObjectUpdate(this, EXECUTABLE, executable, this.executable); this.executable = executable; return (C) this; } @Override public C setLabel(String label) { - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "label"), label, this.label)); - } + getFactory().Change().onObjectUpdate(this, LABEL, label, this.label); this.label = label; return (C) this; } diff --git a/src/main/java/spoon/support/reflect/code/CtContinueImpl.java b/src/main/java/spoon/support/reflect/code/CtContinueImpl.java index eb51ea3a94e..a3b042546f1 100644 --- a/src/main/java/spoon/support/reflect/code/CtContinueImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtContinueImpl.java @@ -16,11 +16,9 @@ */ package spoon.support.reflect.code; -import spoon.reflect.code.CtLabelledFlowBreak; -import spoon.diff.UpdateAction; -import spoon.diff.context.ObjectContext; import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.code.CtContinue; +import spoon.reflect.code.CtLabelledFlowBreak; import spoon.reflect.code.CtStatement; import spoon.reflect.declaration.CtElement; import spoon.reflect.path.CtRole; @@ -29,6 +27,8 @@ import java.util.List; +import static spoon.reflect.path.CtRole.TARGET_LABEL; + public class CtContinueImpl extends CtStatementImpl implements CtContinue { private static final long serialVersionUID = 1L; @@ -47,9 +47,7 @@ public String getTargetLabel() { @Override public T setTargetLabel(String targetLabel) { - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "targetLabel"), targetLabel, this.targetLabel)); - } + getFactory().Change().onObjectUpdate(this, TARGET_LABEL, targetLabel, this.targetLabel); this.targetLabel = targetLabel; return (T) this; } diff --git a/src/main/java/spoon/support/reflect/code/CtDoImpl.java b/src/main/java/spoon/support/reflect/code/CtDoImpl.java index 3359d0fc4dc..3d80a7ec902 100644 --- a/src/main/java/spoon/support/reflect/code/CtDoImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtDoImpl.java @@ -16,14 +16,14 @@ */ package spoon.support.reflect.code; -import spoon.diff.UpdateAction; -import spoon.diff.context.ObjectContext; import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.code.CtDo; import spoon.reflect.code.CtExpression; import spoon.reflect.path.CtRole; import spoon.reflect.visitor.CtVisitor; +import static spoon.reflect.path.CtRole.EXPRESSION; + public class CtDoImpl extends CtLoopImpl implements CtDo { private static final long serialVersionUID = 1L; @@ -45,9 +45,7 @@ public T setLoopingExpression(CtExpression expression) if (expression != null) { expression.setParent(this); } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "expression"), expression, this.expression)); - } + getFactory().Change().onObjectUpdate(this, EXPRESSION, expression, this.expression); this.expression = expression; return (T) this; } diff --git a/src/main/java/spoon/support/reflect/code/CtExecutableReferenceExpressionImpl.java b/src/main/java/spoon/support/reflect/code/CtExecutableReferenceExpressionImpl.java index f94ec2fdd74..a0efc17510f 100644 --- a/src/main/java/spoon/support/reflect/code/CtExecutableReferenceExpressionImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtExecutableReferenceExpressionImpl.java @@ -16,8 +16,6 @@ */ package spoon.support.reflect.code; -import spoon.diff.UpdateAction; -import spoon.diff.context.ObjectContext; import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.code.CtExecutableReferenceExpression; import spoon.reflect.code.CtExpression; @@ -25,6 +23,8 @@ import spoon.reflect.reference.CtExecutableReference; import spoon.reflect.visitor.CtVisitor; +import static spoon.reflect.path.CtRole.EXECUTABLE; + public class CtExecutableReferenceExpressionImpl> extends CtTargetedExpressionImpl implements CtExecutableReferenceExpression { @MetamodelPropertyField(role = CtRole.EXECUTABLE) CtExecutableReference executable; @@ -44,9 +44,7 @@ public > C setExecutable(CtExecu if (executable != null) { executable.setParent(this); } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "executable"), executable, this.executable)); - } + getFactory().Change().onObjectUpdate(this, EXECUTABLE, executable, this.executable); this.executable = executable; return (C) this; } diff --git a/src/main/java/spoon/support/reflect/code/CtExpressionImpl.java b/src/main/java/spoon/support/reflect/code/CtExpressionImpl.java index 6feb31f2e8d..85bc53e7c3b 100644 --- a/src/main/java/spoon/support/reflect/code/CtExpressionImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtExpressionImpl.java @@ -16,11 +16,6 @@ */ package spoon.support.reflect.code; -import spoon.diff.AddAction; -import spoon.diff.DeleteAllAction; -import spoon.diff.UpdateAction; -import spoon.diff.context.ListContext; -import spoon.diff.context.ObjectContext; import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.code.CtExpression; import spoon.reflect.declaration.CtTypedElement; @@ -32,6 +27,8 @@ import java.util.List; import static spoon.reflect.ModelElementContainerDefaultCapacities.CASTS_CONTAINER_DEFAULT_CAPACITY; +import static spoon.reflect.path.CtRole.CAST; +import static spoon.reflect.path.CtRole.TYPE; public abstract class CtExpressionImpl extends CtCodeElementImpl implements CtExpression { private static final long serialVersionUID = 1L; @@ -56,9 +53,7 @@ public C setType(CtTypeReference type) { if (type != null) { type.setParent(this); } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "type"), type, this.type)); - } + getFactory().Change().onObjectUpdate(this, TYPE, type, this.type); this.type = type; return (C) this; } @@ -72,10 +67,7 @@ public > C setTypeCasts(List> casts if (this.typeCasts == CtElementImpl.>emptyList()) { this.typeCasts = new ArrayList<>(CASTS_CONTAINER_DEFAULT_CAPACITY); } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new DeleteAllAction(new ListContext( - this, this.typeCasts), new ArrayList<>(this.typeCasts))); - } + getFactory().Change().onListDeleteAll(this, CAST, this.typeCasts, new ArrayList<>(this.typeCasts)); this.typeCasts.clear(); for (CtTypeReference cast : casts) { addTypeCast(cast); @@ -92,10 +84,7 @@ public > C addTypeCast(CtTypeReference type) { typeCasts = new ArrayList<>(CASTS_CONTAINER_DEFAULT_CAPACITY); } type.setParent(this); - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new AddAction(new ListContext( - this, this.typeCasts), type)); - } + getFactory().Change().onListAdd(this, CAST, this.typeCasts, type); typeCasts.add(type); return (C) this; } diff --git a/src/main/java/spoon/support/reflect/code/CtFieldAccessImpl.java b/src/main/java/spoon/support/reflect/code/CtFieldAccessImpl.java index ad3d35baac1..ee2e3186565 100644 --- a/src/main/java/spoon/support/reflect/code/CtFieldAccessImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtFieldAccessImpl.java @@ -16,8 +16,6 @@ */ package spoon.support.reflect.code; -import spoon.diff.UpdateAction; -import spoon.diff.context.ObjectContext; import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.code.CtExpression; import spoon.reflect.code.CtFieldAccess; @@ -25,6 +23,8 @@ import spoon.reflect.path.CtRole; import spoon.reflect.reference.CtFieldReference; +import static spoon.reflect.path.CtRole.TARGET; + public abstract class CtFieldAccessImpl extends CtVariableAccessImpl implements CtFieldAccess { private static final long serialVersionUID = 1L; @@ -41,9 +41,7 @@ public >> C setTarget(CtExpres if (target != null) { target.setParent(this); } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "target"), target, this.target)); - } + getFactory().Change().onObjectUpdate(this, TARGET, target, this.target); this.target = target; return null; } diff --git a/src/main/java/spoon/support/reflect/code/CtForEachImpl.java b/src/main/java/spoon/support/reflect/code/CtForEachImpl.java index c0d211d39c4..d075c8dd883 100644 --- a/src/main/java/spoon/support/reflect/code/CtForEachImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtForEachImpl.java @@ -16,8 +16,6 @@ */ package spoon.support.reflect.code; -import spoon.diff.UpdateAction; -import spoon.diff.context.ObjectContext; import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.code.CtExpression; import spoon.reflect.code.CtForEach; @@ -25,6 +23,9 @@ import spoon.reflect.path.CtRole; import spoon.reflect.visitor.CtVisitor; +import static spoon.reflect.path.CtRole.EXPRESSION; +import static spoon.reflect.path.CtRole.VARIABLE; + public class CtForEachImpl extends CtLoopImpl implements CtForEach { private static final long serialVersionUID = 1L; @@ -54,9 +55,7 @@ public T setExpression(CtExpression expression) { if (expression != null) { expression.setParent(this); } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "expression"), expression, this.expression)); - } + getFactory().Change().onObjectUpdate(this, EXPRESSION, expression, this.expression); this.expression = expression; return (T) this; } @@ -66,9 +65,7 @@ public T setVariable(CtLocalVariable variable) { if (variable != null) { variable.setParent(this); } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "variable"), variable, this.variable)); - } + getFactory().Change().onObjectUpdate(this, VARIABLE, variable, this.variable); this.variable = variable; return (T) this; } diff --git a/src/main/java/spoon/support/reflect/code/CtForImpl.java b/src/main/java/spoon/support/reflect/code/CtForImpl.java index de8028b199c..a10708c10bc 100644 --- a/src/main/java/spoon/support/reflect/code/CtForImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtForImpl.java @@ -16,12 +16,6 @@ */ package spoon.support.reflect.code; -import spoon.diff.AddAction; -import spoon.diff.DeleteAction; -import spoon.diff.DeleteAllAction; -import spoon.diff.UpdateAction; -import spoon.diff.context.ListContext; -import spoon.diff.context.ObjectContext; import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.code.CtExpression; import spoon.reflect.code.CtFor; @@ -35,6 +29,9 @@ import static spoon.reflect.ModelElementContainerDefaultCapacities.FOR_INIT_STATEMENTS_CONTAINER_DEFAULT_CAPACITY; import static spoon.reflect.ModelElementContainerDefaultCapacities.FOR_UPDATE_STATEMENTS_CONTAINER_DEFAULT_CAPACITY; +import static spoon.reflect.path.CtRole.EXPRESSION; +import static spoon.reflect.path.CtRole.FOR_INIT; +import static spoon.reflect.path.CtRole.FOR_UPDATE; public class CtForImpl extends CtLoopImpl implements CtFor { private static final long serialVersionUID = 1L; @@ -63,9 +60,7 @@ public T setExpression(CtExpression expression) { if (expression != null) { expression.setParent(this); } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "expression"), expression, this.expression)); - } + getFactory().Change().onObjectUpdate(this, EXPRESSION, expression, this.expression); this.expression = expression; return (T) this; } @@ -84,10 +79,7 @@ public T addForInit(CtStatement statement) { forInit = new ArrayList<>(FOR_INIT_STATEMENTS_CONTAINER_DEFAULT_CAPACITY); } statement.setParent(this); - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new AddAction(new ListContext( - this, this.forInit), statement)); - } + getFactory().Change().onListAdd(this, FOR_INIT, this.forInit, statement); forInit.add(statement); return (T) this; } @@ -98,10 +90,7 @@ public T setForInit(List statements) { this.forInit = CtElementImpl.emptyList(); return (T) this; } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new DeleteAllAction(new ListContext( - this, this.forInit), new ArrayList<>(this.forInit))); - } + getFactory().Change().onListDeleteAll(this, FOR_INIT, this.forInit, new ArrayList<>(this.forInit)); this.forInit.clear(); for (CtStatement stmt : statements) { addForInit(stmt); @@ -114,10 +103,7 @@ public boolean removeForInit(CtStatement statement) { if (forInit == CtElementImpl.emptyList()) { return false; } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new DeleteAction(new ListContext( - this, forInit, forInit.indexOf(statement)), statement)); - } + getFactory().Change().onListDelete(this, FOR_INIT, forInit, forInit.indexOf(statement), statement); return forInit.remove(statement); } @@ -135,10 +121,7 @@ public T addForUpdate(CtStatement statement) { forUpdate = new ArrayList<>(FOR_UPDATE_STATEMENTS_CONTAINER_DEFAULT_CAPACITY); } statement.setParent(this); - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new AddAction(new ListContext( - this, this.forUpdate), statement)); - } + getFactory().Change().onListAdd(this, FOR_UPDATE, this.forUpdate, statement); forUpdate.add(statement); return (T) this; } @@ -149,10 +132,7 @@ public T setForUpdate(List statements) { this.forUpdate = CtElementImpl.emptyList(); return (T) this; } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new DeleteAllAction(new ListContext( - this, this.forUpdate), new ArrayList<>(this.forUpdate))); - } + getFactory().Change().onListDeleteAll(this, FOR_UPDATE, this.forUpdate, new ArrayList<>(this.forUpdate)); this.forUpdate.clear(); for (CtStatement stmt : statements) { addForUpdate(stmt); @@ -165,10 +145,7 @@ public boolean removeForUpdate(CtStatement statement) { if (forUpdate == CtElementImpl.emptyList()) { return false; } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new DeleteAction(new ListContext( - this, forUpdate, forUpdate.indexOf(statement)), statement)); - } + getFactory().Change().onListDelete(this, FOR_UPDATE, forUpdate, forUpdate.indexOf(statement), statement); return forUpdate.remove(statement); } diff --git a/src/main/java/spoon/support/reflect/code/CtIfImpl.java b/src/main/java/spoon/support/reflect/code/CtIfImpl.java index 7169c8e26b4..b876777fb37 100644 --- a/src/main/java/spoon/support/reflect/code/CtIfImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtIfImpl.java @@ -16,8 +16,6 @@ */ package spoon.support.reflect.code; -import spoon.diff.UpdateAction; -import spoon.diff.context.ObjectContext; import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.code.CtCodeElement; import spoon.reflect.code.CtExpression; @@ -27,6 +25,10 @@ import spoon.reflect.path.CtRole; import spoon.reflect.visitor.CtVisitor; +import static spoon.reflect.path.CtRole.CONDITION; +import static spoon.reflect.path.CtRole.ELSE; +import static spoon.reflect.path.CtRole.THEN; + public class CtIfImpl extends CtStatementImpl implements CtIf { private static final long serialVersionUID = 1L; @@ -66,9 +68,7 @@ public T setCondition(CtExpression condition) { if (condition != null) { condition.setParent(this); } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "condition"), condition, this.condition)); - } + getFactory().Change().onObjectUpdate(this, CONDITION, condition, this.condition); this.condition = condition; return (T) this; } @@ -78,9 +78,7 @@ public T setElseStatement(CtStatement elseStatement) { if (elseStatement != null) { elseStatement.setParent(this); } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "elseStatement"), elseStatement, this.elseStatement)); - } + getFactory().Change().onObjectUpdate(this, ELSE, elseStatement, this.elseStatement); this.elseStatement = elseStatement; return (T) this; } @@ -91,9 +89,7 @@ public T setThenStatement(CtStatement thenStatement) { if (thenStatement != null) { thenStatement.setParent(this); } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "thenStatement"), thenStatement, this.thenStatement)); - } + getFactory().Change().onObjectUpdate(this, THEN, thenStatement, this.thenStatement); this.thenStatement = thenStatement; return (T) this; } diff --git a/src/main/java/spoon/support/reflect/code/CtInvocationImpl.java b/src/main/java/spoon/support/reflect/code/CtInvocationImpl.java index c581b3798bd..c06e0671b4e 100644 --- a/src/main/java/spoon/support/reflect/code/CtInvocationImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtInvocationImpl.java @@ -16,12 +16,6 @@ */ package spoon.support.reflect.code; -import spoon.diff.AddAction; -import spoon.diff.DeleteAction; -import spoon.diff.DeleteAllAction; -import spoon.diff.UpdateAction; -import spoon.diff.context.ListContext; -import spoon.diff.context.ObjectContext; import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.code.CtAbstractInvocation; import spoon.reflect.code.CtExpression; @@ -42,6 +36,9 @@ import java.util.List; import static spoon.reflect.ModelElementContainerDefaultCapacities.PARAMETERS_CONTAINER_DEFAULT_CAPACITY; +import static spoon.reflect.path.CtRole.ARGUMENT; +import static spoon.reflect.path.CtRole.EXECUTABLE; +import static spoon.reflect.path.CtRole.LABEL; public class CtInvocationImpl extends CtTargetedExpressionImpl> implements CtInvocation { private static final long serialVersionUID = 1L; @@ -74,10 +71,7 @@ public > C addArgument(int position, CtExpress arguments = new ArrayList<>(PARAMETERS_CONTAINER_DEFAULT_CAPACITY); } argument.setParent(this); - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new AddAction(new ListContext( - this, this.arguments, position), argument)); - } + getFactory().Change().onListAdd(this, ARGUMENT, this.arguments, position, argument); arguments.add(position, argument); return (C) this; } @@ -92,10 +86,7 @@ public boolean removeArgument(CtExpression argument) { if (arguments == CtElementImpl.>emptyList()) { return false; } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new DeleteAction(new ListContext( - this, arguments, arguments.indexOf(argument)), argument)); - } + getFactory().Change().onListDelete(this, ARGUMENT, arguments, arguments.indexOf(argument), argument); return arguments.remove(argument); } @@ -141,10 +132,7 @@ public > C setArguments(List> if (this.arguments == CtElementImpl.>emptyList()) { this.arguments = new ArrayList<>(PARAMETERS_CONTAINER_DEFAULT_CAPACITY); } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new DeleteAllAction(new ListContext( - this, this.arguments), new ArrayList<>(this.arguments))); - } + getFactory().Change().onListDeleteAll(this, ARGUMENT, this.arguments, new ArrayList<>(this.arguments)); this.arguments.clear(); for (CtExpression expr : arguments) { addArgument(expr); @@ -157,9 +145,7 @@ public > C setExecutable(CtExecutableReference if (executable != null) { executable.setParent(this); } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "executable"), executable, this.executable)); - } + getFactory().Change().onObjectUpdate(this, EXECUTABLE, executable, this.executable); this.executable = executable; return (C) this; } @@ -171,9 +157,7 @@ public String getLabel() { @Override public C setLabel(String label) { - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "label"), label, this.label)); - } + getFactory().Change().onObjectUpdate(this, LABEL, label, this.label); this.label = label; return (C) this; } diff --git a/src/main/java/spoon/support/reflect/code/CtJavaDocImpl.java b/src/main/java/spoon/support/reflect/code/CtJavaDocImpl.java index 16f99324157..7e911245341 100644 --- a/src/main/java/spoon/support/reflect/code/CtJavaDocImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtJavaDocImpl.java @@ -16,15 +16,7 @@ */ package spoon.support.reflect.code; -import spoon.diff.AddAction; -import spoon.diff.DeleteAction; -import spoon.diff.DeleteAllAction; -import spoon.diff.context.ListContext; import spoon.reflect.annotations.MetamodelPropertyField; -import spoon.diff.AddAction; -import spoon.diff.DeleteAction; -import spoon.diff.DeleteAllAction; -import spoon.diff.context.ListContext; import spoon.reflect.code.CtJavaDoc; import spoon.reflect.code.CtJavaDocTag; import spoon.reflect.path.CtRole; @@ -33,6 +25,8 @@ import java.util.ArrayList; import java.util.List; +import static spoon.reflect.path.CtRole.COMMENT_TAG; + public class CtJavaDocImpl extends CtCommentImpl implements CtJavaDoc { @MetamodelPropertyField(role = CtRole.COMMENT_TAG) @@ -52,9 +46,7 @@ public E setTags(List tags) { if (tags == null) { return (E) this; } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new DeleteAllAction<>(new ListContext(this, this.tags), new ArrayList<>(this.tags))); - } + getFactory().Change().onListDeleteAll(this, COMMENT_TAG, this.tags, new ArrayList<>(this.tags)); this.tags = new ArrayList<>(); for (CtJavaDocTag tag : tags) { this.addTag(tag); @@ -66,9 +58,7 @@ public E setTags(List tags) { public E addTag(CtJavaDocTag tag) { if (tag != null) { tag.setParent(this); - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new AddAction(new ListContext(this, tags), tag)); - } + getFactory().Change().onListAdd(this, COMMENT_TAG, tags, tag); tags.add(tag); } return (E) this; @@ -77,27 +67,21 @@ public E addTag(CtJavaDocTag tag) { @Override public E addTag(int index, CtJavaDocTag tag) { tag.setParent(this); - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new AddAction(new ListContext(this, tags, index), tag)); - } + getFactory().Change().onListAdd(this, COMMENT_TAG, tags, index, tag); tags.add(index, tag); return (E) this; } @Override public E removeTag(int index) { - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new DeleteAction(new ListContext(this, tags, index), tags.get(index))); - } + getFactory().Change().onListDelete(this, COMMENT_TAG, tags, index, tags.get(index)); tags.remove(index); return (E) this; } @Override public E removeTag(CtJavaDocTag tag) { - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new DeleteAction(new ListContext(this, tags, tags.indexOf(tag)), tag)); - } + getFactory().Change().onListDelete(this, COMMENT_TAG, tags, tags.indexOf(tag), tag); tags.remove(tag); return (E) this; } diff --git a/src/main/java/spoon/support/reflect/code/CtJavaDocTagImpl.java b/src/main/java/spoon/support/reflect/code/CtJavaDocTagImpl.java index f729ef04119..178b93307e3 100644 --- a/src/main/java/spoon/support/reflect/code/CtJavaDocTagImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtJavaDocTagImpl.java @@ -17,13 +17,15 @@ package spoon.support.reflect.code; import spoon.reflect.annotations.MetamodelPropertyField; -import spoon.diff.UpdateAction; -import spoon.diff.context.ObjectContext; import spoon.reflect.code.CtJavaDocTag; import spoon.reflect.path.CtRole; import spoon.reflect.visitor.CtVisitor; import spoon.support.reflect.declaration.CtElementImpl; +import static spoon.reflect.path.CtRole.COMMENT_CONTENT; +import static spoon.reflect.path.CtRole.PARAMETER; +import static spoon.reflect.path.CtRole.TYPE; + public class CtJavaDocTagImpl extends CtElementImpl implements CtJavaDocTag { @MetamodelPropertyField(role = CtRole.TYPE) @@ -46,9 +48,7 @@ public E setType(String type) { @Override public E setType(TagType type) { - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "type"), type, this.type)); - } + getFactory().Change().onObjectUpdate(this, TYPE, type, this.type); this.type = type; return (E) this; } @@ -60,9 +60,7 @@ public String getContent() { @Override public E setContent(String content) { - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "content"), content, this.content)); - } + getFactory().Change().onObjectUpdate(this, COMMENT_CONTENT, content, this.content); this.content = content; return (E) this; } @@ -74,9 +72,7 @@ public String getParam() { @Override public E setParam(String param) { - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "param"), param, this.param)); - } + getFactory().Change().onObjectUpdate(this, PARAMETER, param, this.param); this.param = param; return (E) this; } diff --git a/src/main/java/spoon/support/reflect/code/CtLambdaImpl.java b/src/main/java/spoon/support/reflect/code/CtLambdaImpl.java index f9345a3f3d2..b98a0dd18f1 100644 --- a/src/main/java/spoon/support/reflect/code/CtLambdaImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtLambdaImpl.java @@ -17,13 +17,6 @@ package spoon.support.reflect.code; import spoon.SpoonException; -import spoon.diff.AddAction; -import spoon.diff.DeleteAction; -import spoon.diff.DeleteAllAction; -import spoon.diff.UpdateAction; -import spoon.diff.context.ListContext; -import spoon.diff.context.ObjectContext; -import spoon.diff.context.SetContext; import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.code.CtBlock; import spoon.reflect.code.CtBodyHolder; @@ -50,6 +43,11 @@ import java.util.Set; import static spoon.reflect.ModelElementContainerDefaultCapacities.PARAMETERS_CONTAINER_DEFAULT_CAPACITY; +import static spoon.reflect.path.CtRole.BODY; +import static spoon.reflect.path.CtRole.EXPRESSION; +import static spoon.reflect.path.CtRole.NAME; +import static spoon.reflect.path.CtRole.PARAMETER; +import static spoon.reflect.path.CtRole.THROWN; public class CtLambdaImpl extends CtExpressionImpl implements CtLambda { @MetamodelPropertyField(role = CtRole.NAME) @@ -75,9 +73,7 @@ public String getSimpleName() { @Override public C setSimpleName(String simpleName) { - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "simpleName"), simpleName, this.simpleName)); - } + getFactory().Change().onObjectUpdate(this, NAME, simpleName, this.simpleName); this.simpleName = simpleName; return (C) this; } @@ -92,9 +88,7 @@ public CtBlock getBody() { public C setBody(CtStatement statement) { if (statement != null) { CtBlock body = getFactory().Code().getOrCreateCtBlock(statement); - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "body"), body, this.body)); - } + getFactory().Change().onObjectUpdate(this, BODY, body, this.body); if (expression != null && body != null) { throw new SpoonException("A lambda can't have two bodys."); } @@ -103,9 +97,7 @@ public C setBody(CtStatement statement) { } this.body = body; } else { - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new DeleteAction(new ObjectContext(this, "body"), this.body)); - } + getFactory().Change().onObjectDelete(this, BODY, this.body); this.body = null; } @@ -161,10 +153,7 @@ public > C setParameters(List> params) if (this.parameters == CtElementImpl.>emptyList()) { this.parameters = new ArrayList<>(PARAMETERS_CONTAINER_DEFAULT_CAPACITY); } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new DeleteAllAction(new ListContext( - this, this.parameters), new ArrayList<>(this.parameters))); - } + getFactory().Change().onListDeleteAll(this, PARAMETER, this.parameters, new ArrayList<>(this.parameters)); this.parameters.clear(); for (CtParameter p : params) { addParameter(p); @@ -181,9 +170,7 @@ public > C addParameter(CtParameter parameter) { parameters = new ArrayList<>(PARAMETERS_CONTAINER_DEFAULT_CAPACITY); } parameter.setParent(this); - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new AddAction(new ListContext(this, this.parameters), parameter)); - } + getFactory().Change().onListAdd(this, PARAMETER, this.parameters, parameter); parameters.add(parameter); return (C) this; } @@ -193,9 +180,7 @@ public boolean removeParameter(CtParameter parameter) { if (parameters == CtElementImpl.>emptyList()) { return false; } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new DeleteAction(new ListContext(this, parameters, parameters.indexOf(parameter)), parameter)); - } + getFactory().Change().onListDelete(this, PARAMETER, parameters, parameters.indexOf(parameter), parameter); return parameters.remove(parameter); } @@ -213,10 +198,7 @@ public > C setThrownTypes(Set>emptySet()) { this.thrownTypes = new QualifiedNameBasedSortedSet<>(); } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new DeleteAllAction(new SetContext( - this, this.thrownTypes), new HashSet<>(this.thrownTypes))); - } + getFactory().Change().onSetDeleteAll(this, THROWN, this.thrownTypes, new HashSet<>(this.thrownTypes)); this.thrownTypes.clear(); for (CtTypeReference thrownType : thrownTypes) { addThrownType(thrownType); @@ -233,10 +215,7 @@ public > C addThrownType(CtTypeReference(); } throwType.setParent(this); - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new AddAction(new SetContext( - this, this.thrownTypes), throwType)); - } + getFactory().Change().onSetAdd(this, THROWN, this.thrownTypes, throwType); thrownTypes.add(throwType); return (C) this; } @@ -246,10 +225,7 @@ public boolean removeThrownType(CtTypeReference throwType) if (thrownTypes == CtElementImpl.>emptySet()) { return false; } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new DeleteAction(new SetContext( - this, thrownTypes), throwType)); - } + getFactory().Change().onSetDelete(this, THROWN, thrownTypes, throwType); return thrownTypes.remove(throwType); } @@ -273,14 +249,12 @@ public CtExpression getExpression() { @Override public > C setExpression(CtExpression expression) { if (body != null && expression != null) { - throw new SpoonException("A lambda can't have two bodys."); + throw new SpoonException("A lambda can't have two bodies."); } else { if (expression != null) { expression.setParent(this); } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "expression"), expression, this.expression)); - } + getFactory().Change().onObjectUpdate(this, EXPRESSION, expression, this.expression); this.expression = expression; } return (C) this; diff --git a/src/main/java/spoon/support/reflect/code/CtLiteralImpl.java b/src/main/java/spoon/support/reflect/code/CtLiteralImpl.java index cb60431cb21..f2f167dec7a 100644 --- a/src/main/java/spoon/support/reflect/code/CtLiteralImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtLiteralImpl.java @@ -16,14 +16,14 @@ */ package spoon.support.reflect.code; -import spoon.diff.UpdateAction; -import spoon.diff.context.ObjectContext; import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.code.CtLiteral; import spoon.reflect.declaration.CtElement; import spoon.reflect.path.CtRole; import spoon.reflect.visitor.CtVisitor; +import static spoon.reflect.path.CtRole.EXPRESSION; + public class CtLiteralImpl extends CtExpressionImpl implements CtLiteral { private static final long serialVersionUID = 1L; @@ -45,9 +45,7 @@ public > C setValue(T value) { if (this.value instanceof CtElement) { ((CtElement) this.value).setParent(this); } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "value"), value, this.value)); - } + getFactory().Change().onObjectUpdate(this, EXPRESSION, value, this.value); this.value = value; return (C) this; } diff --git a/src/main/java/spoon/support/reflect/code/CtLocalVariableImpl.java b/src/main/java/spoon/support/reflect/code/CtLocalVariableImpl.java index 04c71d173fe..18eae81a477 100644 --- a/src/main/java/spoon/support/reflect/code/CtLocalVariableImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtLocalVariableImpl.java @@ -16,12 +16,6 @@ */ package spoon.support.reflect.code; -import spoon.diff.AddAction; -import spoon.diff.DeleteAction; -import spoon.diff.DeleteAllAction; -import spoon.diff.UpdateAction; -import spoon.diff.context.ObjectContext; -import spoon.diff.context.SetContext; import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.code.CtExpression; import spoon.reflect.code.CtLocalVariable; @@ -42,6 +36,11 @@ import java.util.HashSet; import java.util.Set; +import static spoon.reflect.path.CtRole.DEFAULT_EXPRESSION; +import static spoon.reflect.path.CtRole.MODIFIER; +import static spoon.reflect.path.CtRole.NAME; +import static spoon.reflect.path.CtRole.TYPE; + public class CtLocalVariableImpl extends CtStatementImpl implements CtLocalVariable { private static final long serialVersionUID = 1L; @@ -87,18 +86,14 @@ public > C setDefaultExpression(CtExpression defaultE if (defaultExpression != null) { defaultExpression.setParent(this); } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "defaultExpression"), defaultExpression, this.defaultExpression)); - } + getFactory().Change().onObjectUpdate(this, DEFAULT_EXPRESSION, defaultExpression, this.defaultExpression); this.defaultExpression = defaultExpression; return (C) this; } @Override public C setSimpleName(String simpleName) { - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "name"), simpleName, this.name)); - } + getFactory().Change().onObjectUpdate(this, NAME, simpleName, this.name); this.name = simpleName; return (C) this; } @@ -108,9 +103,7 @@ public C setType(CtTypeReference type) { if (type != null) { type.setParent(this); } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "type"), type, this.type)); - } + getFactory().Change().onObjectUpdate(this, TYPE, type, this.type); this.type = type; return (C) this; } @@ -128,9 +121,7 @@ public boolean hasModifier(ModifierKind modifier) { @Override public C setModifiers(Set modifiers) { if (modifiers.size() > 0) { - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new DeleteAllAction(new SetContext(this, this.modifiers), new HashSet<>(this.modifiers))); - } + getFactory().Change().onSetDeleteAll(this, MODIFIER, this.modifiers, new HashSet<>(this.modifiers)); this.modifiers.clear(); for (ModifierKind modifier : modifiers) { addModifier(modifier); @@ -145,10 +136,7 @@ public C addModifier(ModifierKind modifier) { if (modifiers == CtElementImpl.emptySet()) { this.modifiers = EnumSet.noneOf(ModifierKind.class); } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new AddAction(new SetContext( - this, this.modifiers), modifier)); - } + getFactory().Change().onSetAdd(this, MODIFIER, this.modifiers, modifier); modifiers.add(modifier); return (C) this; } @@ -158,10 +146,7 @@ public boolean removeModifier(ModifierKind modifier) { if (modifiers == CtElementImpl.emptySet()) { return false; } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new DeleteAction(new SetContext( - this, modifiers), modifier)); - } + getFactory().Change().onSetDelete(this, MODIFIER, modifiers, modifier); return modifiers.remove(modifier); } @@ -170,10 +155,10 @@ public C setVisibility(ModifierKind visibility) { if (modifiers == CtElementImpl.emptySet()) { this.modifiers = EnumSet.noneOf(ModifierKind.class); } - getModifiers().remove(ModifierKind.PUBLIC); - getModifiers().remove(ModifierKind.PROTECTED); - getModifiers().remove(ModifierKind.PRIVATE); - getModifiers().add(visibility); + removeModifier(ModifierKind.PUBLIC); + removeModifier(ModifierKind.PROTECTED); + removeModifier(ModifierKind.PRIVATE); + addModifier(visibility); return (C) this; } diff --git a/src/main/java/spoon/support/reflect/code/CtLoopImpl.java b/src/main/java/spoon/support/reflect/code/CtLoopImpl.java index 72a370b3561..aa1749b04af 100644 --- a/src/main/java/spoon/support/reflect/code/CtLoopImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtLoopImpl.java @@ -16,10 +16,7 @@ */ package spoon.support.reflect.code; -import spoon.diff.UpdateAction; -import spoon.diff.context.ObjectContext; import spoon.reflect.annotations.MetamodelPropertyField; -import spoon.diff.DeleteAction; import spoon.reflect.code.CtBlock; import spoon.reflect.code.CtBodyHolder; import spoon.reflect.code.CtCodeElement; @@ -28,6 +25,8 @@ import spoon.reflect.declaration.CtType; import spoon.reflect.path.CtRole; +import static spoon.reflect.path.CtRole.BODY; + public abstract class CtLoopImpl extends CtStatementImpl implements CtLoop { private static final long serialVersionUID = 1L; @@ -44,17 +43,13 @@ public CtStatement getBody() { public T setBody(CtStatement statement) { if (statement != null) { CtBlock body = getFactory().Code().getOrCreateCtBlock(statement); - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "body"), body, this.body)); - } + getFactory().Change().onObjectUpdate(this, BODY, body, this.body); if (body != null) { body.setParent(this); } this.body = body; } else { - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new DeleteAction(new ObjectContext(this, "body"), this.body)); - } + getFactory().Change().onObjectDelete(this, BODY, this.body); this.body = null; } return (T) this; diff --git a/src/main/java/spoon/support/reflect/code/CtNewArrayImpl.java b/src/main/java/spoon/support/reflect/code/CtNewArrayImpl.java index 69dc2aff599..93e0ba02790 100644 --- a/src/main/java/spoon/support/reflect/code/CtNewArrayImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtNewArrayImpl.java @@ -16,10 +16,6 @@ */ package spoon.support.reflect.code; -import spoon.diff.AddAction; -import spoon.diff.DeleteAction; -import spoon.diff.DeleteAllAction; -import spoon.diff.context.ListContext; import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.code.CtExpression; import spoon.reflect.code.CtNewArray; @@ -31,6 +27,8 @@ import java.util.List; import static spoon.reflect.ModelElementContainerDefaultCapacities.NEW_ARRAY_DEFAULT_EXPRESSIONS_CONTAINER_DEFAULT_CAPACITY; +import static spoon.reflect.path.CtRole.DIMENSION; +import static spoon.reflect.path.CtRole.EXPRESSION; public class CtNewArrayImpl extends CtExpressionImpl implements CtNewArray { private static final long serialVersionUID = 1L; @@ -62,10 +60,7 @@ public > C setDimensionExpressions(List(this.dimensionExpressions))); - } + getFactory().Change().onListDeleteAll(this, DIMENSION, this.dimensionExpressions, new ArrayList<>(this.dimensionExpressions)); this.dimensionExpressions.clear(); for (CtExpression expr : dimensionExpressions) { addDimensionExpression(expr); @@ -82,10 +77,7 @@ public > C addDimensionExpression(CtExpression dimensionExpressions = new ArrayList<>(NEW_ARRAY_DEFAULT_EXPRESSIONS_CONTAINER_DEFAULT_CAPACITY); } dimension.setParent(this); - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new AddAction(new ListContext( - this, this.dimensionExpressions), dimension)); - } + getFactory().Change().onListAdd(this, DIMENSION, this.dimensionExpressions, dimension); dimensionExpressions.add(dimension); return (C) this; } @@ -95,10 +87,7 @@ public boolean removeDimensionExpression(CtExpression dimension) { if (dimensionExpressions == CtElementImpl.>emptyList()) { return false; } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new DeleteAction(new ListContext( - this, dimensionExpressions, dimensionExpressions.indexOf(dimension)), dimension)); - } + getFactory().Change().onListDelete(this, DIMENSION, dimensionExpressions, dimensionExpressions.indexOf(dimension), dimension); return dimensionExpressions.remove(dimension); } @@ -108,10 +97,7 @@ public > C setElements(List> expressions this.expressions = CtElementImpl.emptyList(); return (C) this; } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new DeleteAllAction(new ListContext( - this, this.expressions), new ArrayList<>(this.expressions))); - } + getFactory().Change().onListDeleteAll(this, EXPRESSION, this.expressions, new ArrayList<>(this.expressions)); this.expressions.clear(); for (CtExpression expr : expressions) { addElement(expr); @@ -128,10 +114,7 @@ public > C addElement(CtExpression expression) { this.expressions = new ArrayList<>(); } expression.setParent(this); - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new AddAction(new ListContext( - this, this.expressions), expression)); - } + getFactory().Change().onListAdd(this, EXPRESSION, this.expressions, expression); expressions.add(expression); return (C) this; } @@ -141,10 +124,7 @@ public boolean removeElement(CtExpression expression) { if (expressions == CtElementImpl.>emptyList()) { return false; } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new DeleteAction(new ListContext( - this, expressions, expressions.indexOf(expression)), expression)); - } + getFactory().Change().onListDelete(this, EXPRESSION, expressions, expressions.indexOf(expression), expression); return expressions.remove(expression); } diff --git a/src/main/java/spoon/support/reflect/code/CtNewClassImpl.java b/src/main/java/spoon/support/reflect/code/CtNewClassImpl.java index 6885322f8cd..bd3addde974 100644 --- a/src/main/java/spoon/support/reflect/code/CtNewClassImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtNewClassImpl.java @@ -16,14 +16,14 @@ */ package spoon.support.reflect.code; -import spoon.diff.UpdateAction; -import spoon.diff.context.ObjectContext; import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.code.CtNewClass; import spoon.reflect.declaration.CtClass; import spoon.reflect.path.CtRole; import spoon.reflect.visitor.CtVisitor; +import static spoon.reflect.path.CtRole.EXECUTABLE; + public class CtNewClassImpl extends CtConstructorCallImpl implements CtNewClass { private static final long serialVersionUID = 1L; @@ -45,9 +45,7 @@ public N setAnonymousClass(CtClass anonymousClass) { if (anonymousClass != null) { anonymousClass.setParent(this); } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "anonymousClass"), anonymousClass, this.anonymousClass)); - } + getFactory().Change().onObjectUpdate(this, EXECUTABLE, anonymousClass, this.anonymousClass); this.anonymousClass = anonymousClass; return (N) this; } diff --git a/src/main/java/spoon/support/reflect/code/CtOperatorAssignmentImpl.java b/src/main/java/spoon/support/reflect/code/CtOperatorAssignmentImpl.java index b77b8723490..4720fcd4644 100644 --- a/src/main/java/spoon/support/reflect/code/CtOperatorAssignmentImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtOperatorAssignmentImpl.java @@ -16,14 +16,14 @@ */ package spoon.support.reflect.code; -import spoon.diff.UpdateAction; -import spoon.diff.context.ObjectContext; import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.code.BinaryOperatorKind; import spoon.reflect.code.CtOperatorAssignment; import spoon.reflect.path.CtRole; import spoon.reflect.visitor.CtVisitor; +import static spoon.reflect.path.CtRole.OPERATOR_KIND; + public class CtOperatorAssignmentImpl extends CtAssignmentImpl implements CtOperatorAssignment { private static final long serialVersionUID = 1L; @@ -42,9 +42,7 @@ public BinaryOperatorKind getKind() { @Override public > C setKind(BinaryOperatorKind kind) { - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "kind"), kind, this.kind)); - } + getFactory().Change().onObjectUpdate(this, OPERATOR_KIND, kind, this.kind); this.kind = kind; return (C) this; } diff --git a/src/main/java/spoon/support/reflect/code/CtReturnImpl.java b/src/main/java/spoon/support/reflect/code/CtReturnImpl.java index 14b8d4ae598..4674f1dd4ab 100644 --- a/src/main/java/spoon/support/reflect/code/CtReturnImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtReturnImpl.java @@ -16,8 +16,6 @@ */ package spoon.support.reflect.code; -import spoon.diff.UpdateAction; -import spoon.diff.context.ObjectContext; import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.code.CtCodeElement; import spoon.reflect.code.CtExpression; @@ -26,6 +24,8 @@ import spoon.reflect.path.CtRole; import spoon.reflect.visitor.CtVisitor; +import static spoon.reflect.path.CtRole.EXPRESSION; + public class CtReturnImpl extends CtStatementImpl implements CtReturn { private static final long serialVersionUID = 1L; @@ -47,9 +47,7 @@ public > T setReturnedExpression(CtExpression expressio if (expression != null) { expression.setParent(this); } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "returnedExpression"), expression, this.returnedExpression)); - } + getFactory().Change().onObjectUpdate(this, EXPRESSION, expression, this.returnedExpression); this.returnedExpression = expression; return (T) this; } diff --git a/src/main/java/spoon/support/reflect/code/CtStatementImpl.java b/src/main/java/spoon/support/reflect/code/CtStatementImpl.java index e9b6a7f8d39..28d3ff71919 100644 --- a/src/main/java/spoon/support/reflect/code/CtStatementImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtStatementImpl.java @@ -17,8 +17,6 @@ package spoon.support.reflect.code; import spoon.SpoonException; -import spoon.diff.UpdateAction; -import spoon.diff.context.ObjectContext; import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.code.CtBlock; import spoon.reflect.code.CtCase; @@ -39,6 +37,8 @@ import java.util.ArrayList; import java.util.List; +import static spoon.reflect.path.CtRole.LABEL; + public abstract class CtStatementImpl extends CtCodeElementImpl implements CtStatement { private static final long serialVersionUID = 1L; @@ -274,9 +274,7 @@ public String getLabel() { @Override public T setLabel(String label) { - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "label"), label, this.label)); - } + getFactory().Change().onObjectUpdate(this, LABEL, label, this.label); this.label = label; return (T) this; } diff --git a/src/main/java/spoon/support/reflect/code/CtStatementListImpl.java b/src/main/java/spoon/support/reflect/code/CtStatementListImpl.java index d962daa231b..948579a52be 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 spoon.diff.AddAction; -import spoon.diff.DeleteAction; -import spoon.diff.DeleteAllAction; -import spoon.diff.context.ListContext; import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.code.CtStatement; import spoon.reflect.code.CtStatementList; @@ -35,6 +31,7 @@ import java.util.List; import static spoon.reflect.ModelElementContainerDefaultCapacities.BLOCK_STATEMENTS_CONTAINER_DEFAULT_CAPACITY; +import static spoon.reflect.path.CtRole.STATEMENT; public class CtStatementListImpl extends CtCodeElementImpl implements CtStatementList { private static final long serialVersionUID = 1L; @@ -58,10 +55,7 @@ public T setStatements(List stmts) { this.statements = CtElementImpl.emptyList(); return (T) this; } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new DeleteAllAction(new ListContext( - this, this.statements), new ArrayList<>(this.statements))); - } + getFactory().Change().onListDeleteAll(this, STATEMENT, this.statements, new ArrayList<>(this.statements)); this.statements.clear(); for (CtStatement stmt : stmts) { addStatement(stmt); @@ -78,10 +72,7 @@ public T addStatement(CtStatement statement) { this.statements = new ArrayList<>(BLOCK_STATEMENTS_CONTAINER_DEFAULT_CAPACITY); } statement.setParent(this); - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new AddAction(new ListContext( - this, this.statements), statement)); - } + getFactory().Change().onListAdd(this, STATEMENT, this.statements, statement); this.statements.add(statement); return (T) this; } @@ -91,10 +82,7 @@ public void removeStatement(CtStatement statement) { if (this.statements == CtElementImpl.emptyList()) { return ; } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new DeleteAction(new ListContext( - this, statements, statements.indexOf(statement)), statement)); - } + getFactory().Change().onListDelete(this, STATEMENT, statements, statements.indexOf(statement), statement); statements.remove(statement); } diff --git a/src/main/java/spoon/support/reflect/code/CtSuperAccessImpl.java b/src/main/java/spoon/support/reflect/code/CtSuperAccessImpl.java index 9e8098470bc..103a9b9979f 100644 --- a/src/main/java/spoon/support/reflect/code/CtSuperAccessImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtSuperAccessImpl.java @@ -16,8 +16,6 @@ */ package spoon.support.reflect.code; -import spoon.diff.UpdateAction; -import spoon.diff.context.ObjectContext; import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.code.CtExpression; import spoon.reflect.code.CtSuperAccess; @@ -25,6 +23,8 @@ import spoon.reflect.path.CtRole; import spoon.reflect.visitor.CtVisitor; +import static spoon.reflect.path.CtRole.TARGET; + public class CtSuperAccessImpl extends CtVariableReadImpl implements CtSuperAccess { private static final long serialVersionUID = 1L; @@ -47,9 +47,7 @@ public >> C setTarget(CtExpres if (target != null) { target.setParent(this); } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "target"), target, this.target)); - } + getFactory().Change().onObjectUpdate(this, TARGET, target, this.target); this.target = target; return null; } diff --git a/src/main/java/spoon/support/reflect/code/CtSwitchImpl.java b/src/main/java/spoon/support/reflect/code/CtSwitchImpl.java index 6476868f80a..82b31c966a3 100644 --- a/src/main/java/spoon/support/reflect/code/CtSwitchImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtSwitchImpl.java @@ -16,12 +16,6 @@ */ package spoon.support.reflect.code; -import spoon.diff.AddAction; -import spoon.diff.DeleteAction; -import spoon.diff.DeleteAllAction; -import spoon.diff.UpdateAction; -import spoon.diff.context.ListContext; -import spoon.diff.context.ObjectContext; import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.code.CtCase; import spoon.reflect.code.CtExpression; @@ -34,6 +28,8 @@ import java.util.List; import static spoon.reflect.ModelElementContainerDefaultCapacities.SWITCH_CASES_CONTAINER_DEFAULT_CAPACITY; +import static spoon.reflect.path.CtRole.CASE; +import static spoon.reflect.path.CtRole.EXPRESSION; public class CtSwitchImpl extends CtStatementImpl implements CtSwitch { private static final long serialVersionUID = 1L; @@ -65,10 +61,7 @@ public > T setCases(List> cases) { this.cases = CtElementImpl.emptyList(); return (T) this; } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new DeleteAllAction(new ListContext( - this, this.cases), new ArrayList<>(this.cases))); - } + getFactory().Change().onListDeleteAll(this, CASE, this.cases, new ArrayList<>(this.cases)); this.cases.clear(); for (CtCase aCase : cases) { addCase(aCase); @@ -81,9 +74,7 @@ public > T setSelector(CtExpression selector) { if (selector != null) { selector.setParent(this); } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "expression"), selector, this.expression)); - } + getFactory().Change().onObjectUpdate(this, EXPRESSION, selector, this.expression); this.expression = selector; return (T) this; } @@ -97,10 +88,7 @@ public > T addCase(CtCase c) { cases = new ArrayList<>(SWITCH_CASES_CONTAINER_DEFAULT_CAPACITY); } c.setParent(this); - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new AddAction(new ListContext( - this, this.cases), c)); - } + getFactory().Change().onListAdd(this, CASE, this.cases, c); cases.add(c); return (T) this; } @@ -110,10 +98,7 @@ public boolean removeCase(CtCase c) { if (cases == CtElementImpl.>emptyList()) { return false; } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new DeleteAction(new ListContext( - this, cases, cases.indexOf(c)), c)); - } + getFactory().Change().onListDelete(this, CASE, cases, cases.indexOf(c), c); return cases.remove(c); } diff --git a/src/main/java/spoon/support/reflect/code/CtSynchronizedImpl.java b/src/main/java/spoon/support/reflect/code/CtSynchronizedImpl.java index e54cc277988..8eaace2fbae 100644 --- a/src/main/java/spoon/support/reflect/code/CtSynchronizedImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtSynchronizedImpl.java @@ -16,8 +16,6 @@ */ package spoon.support.reflect.code; -import spoon.diff.UpdateAction; -import spoon.diff.context.ObjectContext; import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.code.CtBlock; import spoon.reflect.code.CtExpression; @@ -25,6 +23,9 @@ import spoon.reflect.path.CtRole; import spoon.reflect.visitor.CtVisitor; +import static spoon.reflect.path.CtRole.BODY; +import static spoon.reflect.path.CtRole.EXPRESSION; + public class CtSynchronizedImpl extends CtStatementImpl implements CtSynchronized { private static final long serialVersionUID = 1L; @@ -54,9 +55,7 @@ public T setBlock(CtBlock block) { if (block != null) { block.setParent(this); } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "block"), block, this.block)); - } + getFactory().Change().onObjectUpdate(this, BODY, block, this.block); this.block = block; return (T) this; } @@ -66,9 +65,7 @@ public T setExpression(CtExpression expression) { if (expression != null) { expression.setParent(this); } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "expression"), expression, this.expression)); - } + getFactory().Change().onObjectUpdate(this, EXPRESSION, expression, this.expression); this.expression = expression; return (T) this; } diff --git a/src/main/java/spoon/support/reflect/code/CtTargetedExpressionImpl.java b/src/main/java/spoon/support/reflect/code/CtTargetedExpressionImpl.java index 17c10344b00..f9549120171 100644 --- a/src/main/java/spoon/support/reflect/code/CtTargetedExpressionImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtTargetedExpressionImpl.java @@ -16,13 +16,13 @@ */ package spoon.support.reflect.code; -import spoon.diff.UpdateAction; -import spoon.diff.context.ObjectContext; import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.code.CtExpression; import spoon.reflect.code.CtTargetedExpression; import spoon.reflect.path.CtRole; +import static spoon.reflect.path.CtRole.TARGET; + public abstract class CtTargetedExpressionImpl> extends CtExpressionImpl implements CtTargetedExpression { private static final long serialVersionUID = 1L; @@ -39,9 +39,7 @@ public > C setTarget(T target) { if (target != null) { target.setParent(this); } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "target"), target, this.target)); - } + getFactory().Change().onObjectUpdate(this, TARGET, target, this.target); this.target = target; return (C) this; } diff --git a/src/main/java/spoon/support/reflect/code/CtThrowImpl.java b/src/main/java/spoon/support/reflect/code/CtThrowImpl.java index 375a6684ceb..0837a5a5f0c 100644 --- a/src/main/java/spoon/support/reflect/code/CtThrowImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtThrowImpl.java @@ -16,8 +16,6 @@ */ package spoon.support.reflect.code; -import spoon.diff.UpdateAction; -import spoon.diff.context.ObjectContext; import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.code.CtCodeElement; import spoon.reflect.code.CtExpression; @@ -26,6 +24,8 @@ import spoon.reflect.path.CtRole; import spoon.reflect.visitor.CtVisitor; +import static spoon.reflect.path.CtRole.THROWN; + public class CtThrowImpl extends CtStatementImpl implements CtThrow { private static final long serialVersionUID = 1L; @@ -47,9 +47,7 @@ public T setThrownExpression(CtExpression T setCatchers(List catchers) { this.catchers = CtElementImpl.emptyList(); return (T) this; } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new DeleteAllAction(new ListContext( - this, this.catchers), new ArrayList<>(this.catchers))); - } + getFactory().Change().onListDeleteAll(this, CATCH, this.catchers, new ArrayList<>(this.catchers)); this.catchers.clear(); for (CtCatch c : catchers) { addCatcher(c); @@ -87,10 +81,7 @@ public T addCatcher(CtCatch catcher) { catchers = new ArrayList<>(CATCH_CASES_CONTAINER_DEFAULT_CAPACITY); } catcher.setParent(this); - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new AddAction(new ListContext( - this, this.catchers), catcher)); - } + getFactory().Change().onListAdd(this, CATCH, this.catchers, catcher); catchers.add(catcher); return (T) this; } @@ -100,10 +91,7 @@ public boolean removeCatcher(CtCatch catcher) { if (catchers == CtElementImpl.emptyList()) { return false; } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new DeleteAction(new ListContext( - this, catchers, catchers.indexOf(catcher)), catcher)); - } + getFactory().Change().onListDelete(this, CATCH, catchers, catchers.indexOf(catcher), catcher); return catchers.remove(catcher); } @@ -117,9 +105,7 @@ public T setFinalizer(CtBlock finalizer) { if (finalizer != null) { finalizer.setParent(this); } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "finalizer"), finalizer, this.finalizer)); - } + getFactory().Change().onObjectUpdate(this, FINALIZER, finalizer, this.finalizer); this.finalizer = finalizer; return (T) this; } @@ -133,17 +119,13 @@ public CtBlock getBody() { public T setBody(CtStatement statement) { if (statement != null) { CtBlock body = getFactory().Code().getOrCreateCtBlock(statement); - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "body"), body, this.body)); - } + getFactory().Change().onObjectUpdate(this, BODY, body, this.body); if (body != null) { body.setParent(this); } this.body = body; } else { - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new DeleteAction(new ObjectContext(this, "body"), this.body)); - } + getFactory().Change().onObjectDelete(this, BODY, this.body); this.body = null; } diff --git a/src/main/java/spoon/support/reflect/code/CtTryWithResourceImpl.java b/src/main/java/spoon/support/reflect/code/CtTryWithResourceImpl.java index 39dea93d430..bc0bf7d49bf 100644 --- a/src/main/java/spoon/support/reflect/code/CtTryWithResourceImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtTryWithResourceImpl.java @@ -16,10 +16,6 @@ */ package spoon.support.reflect.code; -import spoon.diff.AddAction; -import spoon.diff.DeleteAction; -import spoon.diff.DeleteAllAction; -import spoon.diff.context.ListContext; import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.code.CtLocalVariable; import spoon.reflect.code.CtTryWithResource; @@ -31,6 +27,7 @@ import java.util.List; import static spoon.reflect.ModelElementContainerDefaultCapacities.RESOURCES_CONTAINER_DEFAULT_CAPACITY; +import static spoon.reflect.path.CtRole.TRY_RESOURCE; public class CtTryWithResourceImpl extends CtTryImpl implements CtTryWithResource { private static final long serialVersionUID = 1L; @@ -54,10 +51,7 @@ public T setResources(List> res this.resources = CtElementImpl.emptyList(); return (T) this; } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new DeleteAllAction(new ListContext( - this, this.resources), new ArrayList<>(this.resources))); - } + getFactory().Change().onListDeleteAll(this, TRY_RESOURCE, this.resources, new ArrayList<>(this.resources)); this.resources.clear(); for (CtLocalVariable l : resources) { addResource(l); @@ -74,10 +68,7 @@ public T addResource(CtLocalVariable resource) resources = new ArrayList<>(RESOURCES_CONTAINER_DEFAULT_CAPACITY); } resource.setParent(this); - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new AddAction(new ListContext( - this, this.resources), resource)); - } + getFactory().Change().onListAdd(this, TRY_RESOURCE, this.resources, resource); resources.add(resource); return (T) this; } @@ -87,10 +78,7 @@ public boolean removeResource(CtLocalVariable resource) { if (resources == CtElementImpl.>emptyList()) { return false; } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new DeleteAction(new ListContext( - this, resources, resources.indexOf(resource)), resource)); - } + getFactory().Change().onListDelete(this, TRY_RESOURCE, resources, resources.indexOf(resource), resource); return resources.remove(resource); } diff --git a/src/main/java/spoon/support/reflect/code/CtTypeAccessImpl.java b/src/main/java/spoon/support/reflect/code/CtTypeAccessImpl.java index 69661fcc976..24997493f54 100644 --- a/src/main/java/spoon/support/reflect/code/CtTypeAccessImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtTypeAccessImpl.java @@ -16,8 +16,6 @@ */ package spoon.support.reflect.code; -import spoon.diff.UpdateAction; -import spoon.diff.context.ObjectContext; import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.code.CtTypeAccess; import spoon.reflect.declaration.CtTypedElement; @@ -26,6 +24,8 @@ import spoon.reflect.visitor.CtVisitor; import spoon.support.UnsettableProperty; +import static spoon.reflect.path.CtRole.TYPE; + public class CtTypeAccessImpl extends CtExpressionImpl implements CtTypeAccess { @MetamodelPropertyField(role = CtRole.TYPE) @@ -46,9 +46,7 @@ public > C setAccessedType(CtTypeReference accessed if (accessedType != null) { accessedType.setParent(this); } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "type"), accessedType, this.type)); - } + getFactory().Change().onObjectUpdate(this, TYPE, accessedType, this.type); type = accessedType; return (C) this; } diff --git a/src/main/java/spoon/support/reflect/code/CtUnaryOperatorImpl.java b/src/main/java/spoon/support/reflect/code/CtUnaryOperatorImpl.java index 1335e29f8a7..0cfada9644d 100644 --- a/src/main/java/spoon/support/reflect/code/CtUnaryOperatorImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtUnaryOperatorImpl.java @@ -16,8 +16,6 @@ */ package spoon.support.reflect.code; -import spoon.diff.UpdateAction; -import spoon.diff.context.ObjectContext; import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.code.CtExpression; import spoon.reflect.code.CtStatement; @@ -28,6 +26,10 @@ import spoon.reflect.path.CtRole; import spoon.reflect.visitor.CtVisitor; +import static spoon.reflect.path.CtRole.EXPRESSION; +import static spoon.reflect.path.CtRole.LABEL; +import static spoon.reflect.path.CtRole.OPERATOR_KIND; + public class CtUnaryOperatorImpl extends CtExpressionImpl implements CtUnaryOperator { private static final long serialVersionUID = 1L; @@ -89,27 +91,21 @@ public C setOperand(CtExpression expression) { if (expression != null) { expression.setParent(this); } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "operand"), expression, this.operand)); - } + getFactory().Change().onObjectUpdate(this, EXPRESSION, expression, this.operand); this.operand = expression; return (C) this; } @Override public C setKind(UnaryOperatorKind kind) { - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "kind"), kind, this.kind)); - } + getFactory().Change().onObjectUpdate(this, OPERATOR_KIND, kind, this.kind); this.kind = kind; return (C) this; } @Override public C setLabel(String label) { - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "label"), label, this.label)); - } + getFactory().Change().onObjectUpdate(this, LABEL, label, this.label); this.label = label; return (C) this; } diff --git a/src/main/java/spoon/support/reflect/code/CtVariableAccessImpl.java b/src/main/java/spoon/support/reflect/code/CtVariableAccessImpl.java index 9e853ea5ae0..39955928e53 100644 --- a/src/main/java/spoon/support/reflect/code/CtVariableAccessImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtVariableAccessImpl.java @@ -16,8 +16,6 @@ */ package spoon.support.reflect.code; -import spoon.diff.UpdateAction; -import spoon.diff.context.ObjectContext; import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.code.CtVariableAccess; import spoon.reflect.declaration.CtTypedElement; @@ -26,6 +24,8 @@ import spoon.reflect.reference.CtVariableReference; import spoon.support.DerivedProperty; +import static spoon.reflect.path.CtRole.VARIABLE; + public abstract class CtVariableAccessImpl extends CtExpressionImpl implements CtVariableAccess { private static final long serialVersionUID = 1L; @@ -50,9 +50,7 @@ public > C setVariable(CtVariableReference vari if (variable != null) { variable.setParent(this); } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "variable"), variable, this.variable)); - } + getFactory().Change().onObjectUpdate(this, VARIABLE, variable, this.variable); this.variable = variable; return (C) this; } diff --git a/src/main/java/spoon/support/reflect/code/CtWhileImpl.java b/src/main/java/spoon/support/reflect/code/CtWhileImpl.java index fa4ff2d2da4..8ee422fec78 100644 --- a/src/main/java/spoon/support/reflect/code/CtWhileImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtWhileImpl.java @@ -16,14 +16,14 @@ */ package spoon.support.reflect.code; -import spoon.diff.UpdateAction; -import spoon.diff.context.ObjectContext; import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.code.CtExpression; import spoon.reflect.code.CtWhile; import spoon.reflect.path.CtRole; import spoon.reflect.visitor.CtVisitor; +import static spoon.reflect.path.CtRole.EXPRESSION; + public class CtWhileImpl extends CtLoopImpl implements CtWhile { private static final long serialVersionUID = 1L; @@ -45,9 +45,7 @@ public T setLoopingExpression(CtExpression expressi if (expression != null) { expression.setParent(this); } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "expression"), expression, this.expression)); - } + getFactory().Change().onObjectUpdate(this, EXPRESSION, expression, this.expression); this.expression = expression; return (T) this; } diff --git a/src/main/java/spoon/support/reflect/declaration/CtAnnotationImpl.java b/src/main/java/spoon/support/reflect/declaration/CtAnnotationImpl.java index 51bd8d376aa..1bdaa1df2c9 100644 --- a/src/main/java/spoon/support/reflect/declaration/CtAnnotationImpl.java +++ b/src/main/java/spoon/support/reflect/declaration/CtAnnotationImpl.java @@ -18,11 +18,6 @@ import spoon.Launcher; import spoon.SpoonException; -import spoon.diff.AddAction; -import spoon.diff.DeleteAllAction; -import spoon.diff.UpdateAction; -import spoon.diff.context.MapContext; -import spoon.diff.context.ObjectContext; import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.code.CtCodeElement; import spoon.reflect.code.CtExpression; @@ -70,6 +65,10 @@ import java.util.TreeMap; import java.util.TreeSet; +import static spoon.reflect.path.CtRole.IS_SHADOW; +import static spoon.reflect.path.CtRole.TYPE; +import static spoon.reflect.path.CtRole.VALUE; + /** * The implementation for {@link spoon.reflect.declaration.CtAnnotation}. * @@ -194,9 +193,7 @@ private > T addValueExpression(String elementName, CtE } else { // Add the new value. expression.setParent(this); - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new AddAction(new MapContext(this, this.elementValues, elementName), expression)); - } + getFactory().Change().onMapAdd(this, VALUE, this.elementValues, elementName, expression); elementValues.put(elementName, expression); } return (T) this; @@ -392,19 +389,14 @@ public > T setAnnotationType(CtTypeReference) annotationType; return (T) this; } @Override public > T setElementValues(Map values) { - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new DeleteAllAction(new MapContext( - this, this.elementValues), new HashMap<>(elementValues))); - } + getFactory().Change().onMapDeleteAll(this, VALUE, this.elementValues, new HashMap<>(elementValues)); this.elementValues.clear(); for (Entry e : values.entrySet()) { addValue(e.getKey(), e.getValue()); @@ -414,10 +406,7 @@ public > T setElementValues(Map values @Override public > T setValues(Map values) { - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new DeleteAllAction(new MapContext( - this, this.elementValues), new HashMap<>(elementValues))); - } + getFactory().Change().onMapDeleteAll(this, VALUE, this.elementValues, new HashMap<>(elementValues)); this.elementValues.clear(); for (Entry e : values.entrySet()) { addValue(e.getKey(), e.getValue()); @@ -513,9 +502,7 @@ public boolean isShadow() { @Override public E setShadow(boolean isShadow) { - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "isShadow"), isShadow, this.isShadow)); - } + getFactory().Change().onObjectUpdate(this, IS_SHADOW, isShadow, this.isShadow); this.isShadow = isShadow; return (E) this; } diff --git a/src/main/java/spoon/support/reflect/declaration/CtAnnotationMethodImpl.java b/src/main/java/spoon/support/reflect/declaration/CtAnnotationMethodImpl.java index 9f92907296a..e1f2bb3d811 100644 --- a/src/main/java/spoon/support/reflect/declaration/CtAnnotationMethodImpl.java +++ b/src/main/java/spoon/support/reflect/declaration/CtAnnotationMethodImpl.java @@ -16,14 +16,14 @@ */ package spoon.support.reflect.declaration; -import spoon.diff.UpdateAction; -import spoon.diff.context.ObjectContext; import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.code.CtExpression; import spoon.reflect.declaration.CtAnnotationMethod; import spoon.reflect.path.CtRole; import spoon.reflect.visitor.CtVisitor; +import static spoon.reflect.path.CtRole.DEFAULT_EXPRESSION; + /** * The implementation for {@link spoon.reflect.declaration.CtAnnotationMethod}. */ @@ -46,9 +46,7 @@ public > C setDefaultExpression(CtExpression if (assignedExpression != null) { assignedExpression.setParent(this); } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "defaultExpression"), assignedExpression, this.defaultExpression)); - } + getFactory().Change().onObjectUpdate(this, DEFAULT_EXPRESSION, assignedExpression, this.defaultExpression); this.defaultExpression = assignedExpression; return (C) this; } diff --git a/src/main/java/spoon/support/reflect/declaration/CtAnonymousExecutableImpl.java b/src/main/java/spoon/support/reflect/declaration/CtAnonymousExecutableImpl.java index a72d8d95fd5..8a0ef4b80ac 100644 --- a/src/main/java/spoon/support/reflect/declaration/CtAnonymousExecutableImpl.java +++ b/src/main/java/spoon/support/reflect/declaration/CtAnonymousExecutableImpl.java @@ -16,10 +16,6 @@ */ package spoon.support.reflect.declaration; -import spoon.diff.AddAction; -import spoon.diff.DeleteAction; -import spoon.diff.DeleteAllAction; -import spoon.diff.context.SetContext; import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.declaration.CtAnonymousExecutable; import spoon.reflect.declaration.CtExecutable; @@ -38,6 +34,8 @@ import java.util.List; import java.util.Set; +import static spoon.reflect.path.CtRole.MODIFIER; + public class CtAnonymousExecutableImpl extends CtExecutableImpl implements CtAnonymousExecutable { private static final long serialVersionUID = 1L; @@ -54,9 +52,7 @@ public T addModifier(ModifierKind modifier) { if (modifiers == CtElementImpl.emptySet()) { modifiers = EnumSet.noneOf(ModifierKind.class); } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new AddAction(new SetContext(this, this.modifiers), modifier)); - } + getFactory().Change().onSetAdd(this, MODIFIER, this.modifiers, modifier); modifiers.add(modifier); return (T) this; } @@ -66,10 +62,7 @@ public boolean removeModifier(ModifierKind modifier) { if (modifiers == CtElementImpl.emptySet()) { return false; } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new DeleteAction(new SetContext( - this, modifiers), modifier)); - } + getFactory().Change().onSetDelete(this, MODIFIER, modifiers, modifier); return modifiers.remove(modifier); } @@ -100,9 +93,7 @@ public boolean hasModifier(ModifierKind modifier) { @Override public T setModifiers(Set modifiers) { if (modifiers.size() > 0) { - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new DeleteAllAction(new SetContext(this, this.modifiers), new HashSet<>(this.modifiers))); - } + getFactory().Change().onSetDelete(this, MODIFIER, this.modifiers, new HashSet<>(this.modifiers)); this.modifiers.clear(); for (ModifierKind modifier : modifiers) { addModifier(modifier); diff --git a/src/main/java/spoon/support/reflect/declaration/CtClassImpl.java b/src/main/java/spoon/support/reflect/declaration/CtClassImpl.java index 828e818d958..1f428c70cbd 100644 --- a/src/main/java/spoon/support/reflect/declaration/CtClassImpl.java +++ b/src/main/java/spoon/support/reflect/declaration/CtClassImpl.java @@ -18,12 +18,6 @@ import spoon.SpoonException; import spoon.SpoonModelBuilder.InputType; -import spoon.diff.AddAction; -import spoon.diff.DeleteAction; -import spoon.diff.DeleteAllAction; -import spoon.diff.UpdateAction; -import spoon.diff.context.ListContext; -import spoon.diff.context.ObjectContext; import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.code.CtCodeElement; import spoon.reflect.code.CtStatement; @@ -55,6 +49,10 @@ import java.util.List; import java.util.Set; +import static spoon.reflect.path.CtRole.CONSTRUCTOR; +import static spoon.reflect.path.CtRole.EXECUTABLE; +import static spoon.reflect.path.CtRole.SUPER_TYPE; + /** * The implementation for {@link spoon.reflect.declaration.CtClass}. * @@ -119,17 +117,13 @@ public > C addAnonymousExecutable(CtAnonymousExecutable e) return (C) this; } e.setParent(this); - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new AddAction(new ListContext(this, typeMembers), e)); - } + getFactory().Change().onListAdd(this, EXECUTABLE, typeMembers, e); return addTypeMember(e); } @Override public boolean removeAnonymousExecutable(CtAnonymousExecutable e) { - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new DeleteAction(new ListContext(this, typeMembers, typeMembers.indexOf(e)), e)); - } + getFactory().Change().onListDelete(this, EXECUTABLE, typeMembers, typeMembers.indexOf(e), e); return removeTypeMember(e); } @@ -140,9 +134,7 @@ public CtTypeReference getSuperclass() { @Override public > C setAnonymousExecutables(List anonymousExecutables) { - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new DeleteAllAction(new ListContext(this, typeMembers), new ArrayList<>(getAnonymousExecutables()))); - } + getFactory().Change().onListDelete(this, EXECUTABLE, typeMembers, new ArrayList<>(getAnonymousExecutables())); if (anonymousExecutables == null || anonymousExecutables.isEmpty()) { this.typeMembers.removeAll(getAnonymousExecutables()); return (C) this; @@ -157,11 +149,7 @@ public > C setAnonymousExecutables(List> C setConstructors(Set> constructors) { Set> oldConstructor = getConstructors(); - if (getFactory().getEnvironment().buildStackChanges()) { - for (CtConstructor constructor : oldConstructor) { - getFactory().getEnvironment().pushToStack(new DeleteAction(new ListContext(this, typeMembers), constructor)); - } - } + getFactory().Change().onListDelete(this, CONSTRUCTOR, typeMembers, oldConstructor); if (constructors == null || constructors.isEmpty()) { this.typeMembers.removeAll(oldConstructor); return (C) this; @@ -175,9 +163,7 @@ public > C setConstructors(Set> constructo @Override public > C addConstructor(CtConstructor constructor) { - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new AddAction(new ListContext(this, typeMembers), constructor)); - } + getFactory().Change().onListAdd(this, CONSTRUCTOR, typeMembers, constructor); return addTypeMember(constructor); } @@ -191,9 +177,7 @@ public > C setSuperclass(CtTypeReference superClass) { if (superClass != null) { superClass.setParent(this); } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "superClass"), superClass, this.superClass)); - } + getFactory().Change().onObjectUpdate(this, SUPER_TYPE, superClass, this.superClass); this.superClass = superClass; return (C) this; } diff --git a/src/main/java/spoon/support/reflect/declaration/CtConstructorImpl.java b/src/main/java/spoon/support/reflect/declaration/CtConstructorImpl.java index 3e4835acc31..ced1083f1d6 100644 --- a/src/main/java/spoon/support/reflect/declaration/CtConstructorImpl.java +++ b/src/main/java/spoon/support/reflect/declaration/CtConstructorImpl.java @@ -16,13 +16,6 @@ */ package spoon.support.reflect.declaration; -import spoon.diff.AddAction; -import spoon.diff.DeleteAction; -import spoon.diff.DeleteAllAction; -import spoon.diff.UpdateAction; -import spoon.diff.context.ListContext; -import spoon.diff.context.ObjectContext; -import spoon.diff.context.SetContext; import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.declaration.CtConstructor; import spoon.reflect.declaration.CtFormalTypeDeclarer; @@ -47,6 +40,9 @@ import java.util.Set; import static spoon.reflect.ModelElementContainerDefaultCapacities.TYPE_TYPE_PARAMETERS_CONTAINER_DEFAULT_CAPACITY; +import static spoon.reflect.path.CtRole.IS_SHADOW; +import static spoon.reflect.path.CtRole.MODIFIER; +import static spoon.reflect.path.CtRole.TYPE_PARAMETER; public class CtConstructorImpl extends CtExecutableImpl implements CtConstructor { private static final long serialVersionUID = 1L; @@ -109,9 +105,7 @@ public C setFormalCtTypeParameters(ListemptyList()) { this.formalCtTypeParameters = new ArrayList<>(TYPE_TYPE_PARAMETERS_CONTAINER_DEFAULT_CAPACITY); } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new DeleteAllAction(new ListContext(this, this.formalCtTypeParameters), new ArrayList<>(this.formalCtTypeParameters))); - } + getFactory().Change().onListDeleteAll(this, TYPE_PARAMETER, this.formalCtTypeParameters, new ArrayList<>(this.formalCtTypeParameters)); this.formalCtTypeParameters.clear(); for (CtTypeParameter formalTypeParameter : formalTypeParameters) { addFormalCtTypeParameter(formalTypeParameter); @@ -124,9 +118,7 @@ public C addFormalCtTypeParameter(CtTypeParamet if (formalTypeParameter == null) { return (C) this; } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new AddAction(new ListContext(this, this.formalCtTypeParameters), formalTypeParameter)); - } + getFactory().Change().onListAdd(this, TYPE_PARAMETER, this.formalCtTypeParameters, formalTypeParameter); if (formalCtTypeParameters == CtElementImpl.emptyList()) { formalCtTypeParameters = new ArrayList<>(TYPE_TYPE_PARAMETERS_CONTAINER_DEFAULT_CAPACITY); } @@ -140,10 +132,7 @@ public boolean removeFormalCtTypeParameter(CtTypeParameter formalTypeParameter) if (!formalCtTypeParameters.contains(formalTypeParameter)) { return false; } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new DeleteAction(new ListContext( - this, formalCtTypeParameters, formalCtTypeParameters.indexOf(formalTypeParameter)), formalTypeParameter)); - } + getFactory().Change().onListDelete(this, TYPE_PARAMETER, formalCtTypeParameters, formalCtTypeParameters.indexOf(formalTypeParameter), formalTypeParameter); return formalCtTypeParameters.remove(formalTypeParameter); } @@ -160,9 +149,7 @@ public boolean hasModifier(ModifierKind modifier) { @Override public C setModifiers(Set modifiers) { if (modifiers.size() > 0) { - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new DeleteAllAction(new SetContext(this, this.modifiers), new HashSet<>(this.modifiers))); - } + getFactory().Change().onSetDeleteAll(this, MODIFIER, this.modifiers, new HashSet<>(this.modifiers)); this.modifiers.clear(); for (ModifierKind modifier : modifiers) { addModifier(modifier); @@ -176,9 +163,7 @@ public C addModifier(ModifierKind modifier) { if (modifiers == CtElementImpl.emptySet()) { this.modifiers = EnumSet.noneOf(ModifierKind.class); } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new AddAction(new SetContext(this, this.modifiers), modifier)); - } + getFactory().Change().onSetAdd(this, MODIFIER, this.modifiers, modifier); modifiers.add(modifier); return (C) this; } @@ -188,9 +173,7 @@ public boolean removeModifier(ModifierKind modifier) { if (modifiers == CtElementImpl.emptySet()) { return false; } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new DeleteAction(new SetContext(this, modifiers), modifier)); - } + getFactory().Change().onSetDelete(this, MODIFIER, modifiers, modifier); return modifiers.remove(modifier); } @@ -199,10 +182,10 @@ public C setVisibility(ModifierKind visibility) { if (modifiers == CtElementImpl.emptySet()) { this.modifiers = EnumSet.noneOf(ModifierKind.class); } - getModifiers().remove(ModifierKind.PUBLIC); - getModifiers().remove(ModifierKind.PROTECTED); - getModifiers().remove(ModifierKind.PRIVATE); - getModifiers().add(visibility); + removeModifier(ModifierKind.PUBLIC); + removeModifier(ModifierKind.PROTECTED); + removeModifier(ModifierKind.PRIVATE); + addModifier(visibility); return (C) this; } @@ -230,9 +213,7 @@ public boolean isShadow() { @Override public E setShadow(boolean isShadow) { - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "isShadow"), isShadow, this.isShadow)); - } + getFactory().Change().onObjectUpdate(this, IS_SHADOW, isShadow, this.isShadow); this.isShadow = isShadow; return (E) this; } diff --git a/src/main/java/spoon/support/reflect/declaration/CtElementImpl.java b/src/main/java/spoon/support/reflect/declaration/CtElementImpl.java index 1bc1f7411e8..d8729778c56 100644 --- a/src/main/java/spoon/support/reflect/declaration/CtElementImpl.java +++ b/src/main/java/spoon/support/reflect/declaration/CtElementImpl.java @@ -17,12 +17,6 @@ package spoon.support.reflect.declaration; import org.apache.log4j.Logger; -import spoon.diff.AddAction; -import spoon.diff.DeleteAction; -import spoon.diff.DeleteAllAction; -import spoon.diff.UpdateAction; -import spoon.diff.context.ListContext; -import spoon.diff.context.ObjectContext; import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.code.CtComment; import spoon.reflect.cu.SourcePosition; @@ -63,6 +57,9 @@ import static spoon.reflect.ModelElementContainerDefaultCapacities.ANNOTATIONS_CONTAINER_DEFAULT_CAPACITY; import static spoon.reflect.ModelElementContainerDefaultCapacities.COMMENT_CONTAINER_DEFAULT_CAPACITY; +import static spoon.reflect.path.CtRole.ANNOTATION; +import static spoon.reflect.path.CtRole.COMMENT; +import static spoon.reflect.path.CtRole.IS_IMPLICIT; /** * Contains the default implementation of most CtElement methods. @@ -175,10 +172,7 @@ public E setAnnotations(List(this.annotations))); - } + getFactory().Change().onListDeleteAll(this, ANNOTATION, this.annotations, new ArrayList<>(this.annotations)); this.annotations.clear(); for (CtAnnotation annot : annotations) { addAnnotation(annot); @@ -200,10 +194,7 @@ public E addAnnotation(CtAnnotation this.annotations = new ArrayList<>(ANNOTATIONS_CONTAINER_DEFAULT_CAPACITY); } annotation.setParent(this); - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new AddAction(new ListContext( - this, this.annotations), annotation)); - } + getFactory().Change().onListAdd(this, ANNOTATION, this.annotations, annotation); this.annotations.add(annotation); return (E) this; } @@ -212,10 +203,7 @@ public boolean removeAnnotation(CtAnnotation annotation) { if (this.annotations == CtElementImpl.>emptyList()) { return false; } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new DeleteAction(new ListContext( - this, annotations, annotations.indexOf(annotation)), annotation)); - } + getFactory().Change().onListDelete(this, ANNOTATION, annotations, annotations.indexOf(annotation), annotation); return this.annotations.remove(annotation); } @@ -231,9 +219,6 @@ public E setDocComment(String docComment) { } public E setPosition(SourcePosition position) { - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "position"), position, this.position)); - } this.position = position; return (E) this; } @@ -277,9 +262,7 @@ public boolean isImplicit() { } public E setImplicit(boolean implicit) { - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "implicit"), implicit, this.implicit)); - } + getFactory().Change().onObjectUpdate(this, IS_IMPLICIT, implicit, this.implicit); this.implicit = implicit; return (E) this; } @@ -335,9 +318,6 @@ public E setParent(E parent) { this.parent = parent; return (E) this; } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "parent"), parent, this.parent)); - } this.parent = parent; return (E) this; } @@ -455,10 +435,7 @@ public E addComment(CtComment comment) { comments = new ArrayList<>(COMMENT_CONTAINER_DEFAULT_CAPACITY); } comment.setParent(this); - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new AddAction(new ListContext( - this, this.comments), comment)); - } + getFactory().Change().onListAdd(this, COMMENT, this.comments, comment); comments.add(comment); return (E) this; } @@ -468,10 +445,7 @@ public E removeComment(CtComment comment) { if (this.comments == CtElementImpl.emptyList()) { return (E) this; } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new DeleteAction(new ListContext( - this, comments, comments.indexOf(comment)), comment)); - } + getFactory().Change().onListDelete(this, COMMENT, comments, comments.indexOf(comment), comment); this.comments.remove(comment); return (E) this; } @@ -482,10 +456,7 @@ public E setComments(List comments) { this.comments = CtElementImpl.emptyList(); return (E) this; } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new DeleteAllAction(new ListContext( - this, this.comments), new ArrayList<>(this.comments))); - } + getFactory().Change().onListDeleteAll(this, COMMENT, this.comments, new ArrayList<>(this.comments)); this.comments.clear(); for (CtComment comment : comments) { addComment(comment); diff --git a/src/main/java/spoon/support/reflect/declaration/CtEnumImpl.java b/src/main/java/spoon/support/reflect/declaration/CtEnumImpl.java index 331cab75377..12e6433283c 100644 --- a/src/main/java/spoon/support/reflect/declaration/CtEnumImpl.java +++ b/src/main/java/spoon/support/reflect/declaration/CtEnumImpl.java @@ -16,10 +16,6 @@ */ package spoon.support.reflect.declaration; -import spoon.diff.AddAction; -import spoon.diff.DeleteAction; -import spoon.diff.DeleteAllAction; -import spoon.diff.context.ListContext; import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.declaration.CtEnum; import spoon.reflect.declaration.CtEnumValue; @@ -36,6 +32,8 @@ import java.util.List; import java.util.Set; +import static spoon.reflect.path.CtRole.VALUE; + public class CtEnumImpl> extends CtClassImpl implements CtEnum { private static final long serialVersionUID = 1L; @@ -77,10 +75,7 @@ public > C addEnumValue(CtEnumValue enumValue) { } if (!enumValues.contains(enumValue)) { enumValue.setParent(this); - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new AddAction(new ListContext( - this, this.enumValues), enumValue)); - } + getFactory().Change().onListAdd(this, VALUE, this.enumValues, enumValue); enumValues.add(enumValue); } @@ -93,10 +88,7 @@ public boolean removeEnumValue(CtEnumValue enumValue) { if (enumValues == CtElementImpl.>emptyList()) { return false; } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new DeleteAction(new ListContext( - this, enumValues, enumValues.indexOf(enumValue)), enumValue)); - } + getFactory().Change().onListDelete(this, VALUE, enumValues, enumValues.indexOf(enumValue), enumValue); return enumValues.remove(enumValue); } @@ -117,9 +109,7 @@ public List> getEnumValues() { @Override public > C setEnumValues(List> enumValues) { - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new DeleteAllAction(new ListContext(this, this.enumValues), new ArrayList<>(enumValues))); - } + getFactory().Change().onListDeleteAll(this, VALUE, this.enumValues, new ArrayList<>(enumValues)); if (enumValues == null || enumValues.isEmpty()) { this.enumValues = emptyList(); return (C) this; diff --git a/src/main/java/spoon/support/reflect/declaration/CtExecutableImpl.java b/src/main/java/spoon/support/reflect/declaration/CtExecutableImpl.java index 4a77278f327..14f22539098 100644 --- a/src/main/java/spoon/support/reflect/declaration/CtExecutableImpl.java +++ b/src/main/java/spoon/support/reflect/declaration/CtExecutableImpl.java @@ -16,13 +16,6 @@ */ package spoon.support.reflect.declaration; -import spoon.diff.AddAction; -import spoon.diff.DeleteAction; -import spoon.diff.DeleteAllAction; -import spoon.diff.UpdateAction; -import spoon.diff.context.ListContext; -import spoon.diff.context.ObjectContext; -import spoon.diff.context.SetContext; import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.code.CtBlock; import spoon.reflect.code.CtBodyHolder; @@ -42,6 +35,10 @@ import java.util.Set; import static spoon.reflect.ModelElementContainerDefaultCapacities.PARAMETERS_CONTAINER_DEFAULT_CAPACITY; +import static spoon.reflect.path.CtRole.BODY; +import static spoon.reflect.path.CtRole.PARAMETER; +import static spoon.reflect.path.CtRole.THROWN; + /** * The implementation for {@link spoon.reflect.declaration.CtExecutable}. @@ -82,17 +79,13 @@ public CtBlock getBody() { public T setBody(CtStatement statement) { if (statement != null) { CtBlock body = getFactory().Code().getOrCreateCtBlock(statement); - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "body"), body, this.body)); - } + getFactory().Change().onObjectUpdate(this, BODY, body, this.body); if (body != null) { body.setParent(this); } this.body = body; } else { - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new DeleteAction(new ObjectContext(this, "body"), this.body)); - } + getFactory().Change().onObjectDelete(this, BODY, this.body); this.body = null; } return (T) this; @@ -112,10 +105,7 @@ public > T setParameters(List> paramete if (this.parameters == CtElementImpl.>emptyList()) { this.parameters = new ArrayList<>(PARAMETERS_CONTAINER_DEFAULT_CAPACITY); } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new DeleteAllAction(new ListContext( - this, this.parameters), new ArrayList<>(this.parameters))); - } + getFactory().Change().onListDeleteAll(this, PARAMETER, this.parameters, new ArrayList<>(this.parameters)); this.parameters.clear(); for (CtParameter p : parameters) { addParameter(p); @@ -132,10 +122,7 @@ public > T addParameter(CtParameter parameter) { parameters = new ArrayList<>(PARAMETERS_CONTAINER_DEFAULT_CAPACITY); } parameter.setParent(this); - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new AddAction(new ListContext( - this, this.parameters), parameter)); - } + getFactory().Change().onListAdd(this, PARAMETER, this.parameters, parameter); parameters.add(parameter); return (T) this; } @@ -145,10 +132,7 @@ public boolean removeParameter(CtParameter parameter) { if (parameters == CtElementImpl.>emptyList()) { return false; } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new DeleteAction(new ListContext( - this, parameters, parameters.indexOf(parameter)), parameter)); - } + getFactory().Change().onListDelete(this, PARAMETER, parameters, parameters.indexOf(parameter), parameter); return parameters.remove(parameter); } @@ -166,10 +150,7 @@ public > T setThrownTypes(Set>emptySet()) { this.thrownTypes = new QualifiedNameBasedSortedSet<>(); } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new DeleteAllAction(new SetContext( - this, this.thrownTypes), new HashSet(this.thrownTypes))); - } + getFactory().Change().onSetDeleteAll(this, THROWN, this.thrownTypes, new HashSet(this.thrownTypes)); this.thrownTypes.clear(); for (CtTypeReference thrownType : thrownTypes) { addThrownType(thrownType); @@ -186,10 +167,7 @@ public > T addThrownType(CtTypeReference(); } throwType.setParent(this); - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new AddAction(new SetContext( - this, this.thrownTypes), throwType)); - } + getFactory().Change().onSetAdd(this, THROWN, this.thrownTypes, throwType); thrownTypes.add(throwType); return (T) this; } @@ -199,10 +177,7 @@ public boolean removeThrownType(CtTypeReference throwType) if (thrownTypes == CtElementImpl.>emptySet()) { return false; } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new DeleteAction(new SetContext( - this, thrownTypes), throwType)); - } + getFactory().Change().onSetDelete(this, THROWN, thrownTypes, throwType); return thrownTypes.remove(throwType); } diff --git a/src/main/java/spoon/support/reflect/declaration/CtFieldImpl.java b/src/main/java/spoon/support/reflect/declaration/CtFieldImpl.java index 6a188b5b40e..206ac142bdf 100644 --- a/src/main/java/spoon/support/reflect/declaration/CtFieldImpl.java +++ b/src/main/java/spoon/support/reflect/declaration/CtFieldImpl.java @@ -16,12 +16,6 @@ */ package spoon.support.reflect.declaration; -import spoon.diff.AddAction; -import spoon.diff.DeleteAction; -import spoon.diff.DeleteAllAction; -import spoon.diff.UpdateAction; -import spoon.diff.context.ObjectContext; -import spoon.diff.context.SetContext; import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.code.CtExpression; import spoon.reflect.code.CtRHSReceiver; @@ -43,6 +37,11 @@ import java.util.HashSet; import java.util.Set; +import static spoon.reflect.path.CtRole.DEFAULT_EXPRESSION; +import static spoon.reflect.path.CtRole.IS_SHADOW; +import static spoon.reflect.path.CtRole.MODIFIER; +import static spoon.reflect.path.CtRole.TYPE; + /** * The implementation for {@link spoon.reflect.declaration.CtField}. * @@ -99,9 +98,7 @@ public > C setDefaultExpression(CtExpression defaultE if (defaultExpression != null) { defaultExpression.setParent(this); } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "defaultExpression"), defaultExpression, this.defaultExpression)); - } + getFactory().Change().onObjectUpdate(this, DEFAULT_EXPRESSION, defaultExpression, this.defaultExpression); this.defaultExpression = defaultExpression; return (C) this; } @@ -111,9 +108,7 @@ public C setType(CtTypeReference type) { if (type != null) { type.setParent(this); } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "type"), type, this.type)); - } + getFactory().Change().onObjectUpdate(this, TYPE, type, this.type); this.type = type; return (C) this; } @@ -131,9 +126,7 @@ public boolean hasModifier(ModifierKind modifier) { @Override public C setModifiers(Set modifiers) { if (modifiers.size() > 0) { - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new DeleteAllAction(new SetContext(this, this.modifiers), new HashSet<>(this.modifiers))); - } + getFactory().Change().onSetDeleteAll(this, MODIFIER, this.modifiers, new HashSet<>(this.modifiers)); this.modifiers.clear(); for (ModifierKind modifier : modifiers) { addModifier(modifier); @@ -147,10 +140,7 @@ public C addModifier(ModifierKind modifier) { if (modifiers == CtElementImpl.emptySet()) { this.modifiers = EnumSet.noneOf(ModifierKind.class); } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new AddAction(new SetContext( - this, this.modifiers), modifier)); - } + getFactory().Change().onSetAdd(this, MODIFIER, this.modifiers, modifier); modifiers.add(modifier); return (C) this; } @@ -160,10 +150,7 @@ public boolean removeModifier(ModifierKind modifier) { if (modifiers == CtElementImpl.emptySet()) { return false; } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new DeleteAction(new SetContext( - this, modifiers), modifier)); - } + getFactory().Change().onSetDelete(this, MODIFIER, modifiers, modifier); return modifiers.remove(modifier); } @@ -172,10 +159,10 @@ public C setVisibility(ModifierKind visibility) { if (modifiers == CtElementImpl.emptySet()) { this.modifiers = EnumSet.noneOf(ModifierKind.class); } - getModifiers().remove(ModifierKind.PUBLIC); - getModifiers().remove(ModifierKind.PROTECTED); - getModifiers().remove(ModifierKind.PRIVATE); - getModifiers().add(visibility); + removeModifier(ModifierKind.PUBLIC); + removeModifier(ModifierKind.PROTECTED); + removeModifier(ModifierKind.PRIVATE); + addModifier(visibility); return (C) this; } @@ -220,9 +207,7 @@ public boolean isShadow() { @Override public E setShadow(boolean isShadow) { - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "isShadow"), isShadow, this.isShadow)); - } + getFactory().Change().onObjectUpdate(this, IS_SHADOW, isShadow, this.isShadow); this.isShadow = isShadow; return (E) this; } diff --git a/src/main/java/spoon/support/reflect/declaration/CtMethodImpl.java b/src/main/java/spoon/support/reflect/declaration/CtMethodImpl.java index 7473f4471ff..92bff39d89a 100644 --- a/src/main/java/spoon/support/reflect/declaration/CtMethodImpl.java +++ b/src/main/java/spoon/support/reflect/declaration/CtMethodImpl.java @@ -16,13 +16,6 @@ */ package spoon.support.reflect.declaration; -import spoon.diff.AddAction; -import spoon.diff.DeleteAction; -import spoon.diff.DeleteAllAction; -import spoon.diff.UpdateAction; -import spoon.diff.context.ListContext; -import spoon.diff.context.ObjectContext; -import spoon.diff.context.SetContext; import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.declaration.CtElement; import spoon.reflect.declaration.CtFormalTypeDeclarer; @@ -44,6 +37,11 @@ import java.util.Set; import static spoon.reflect.ModelElementContainerDefaultCapacities.TYPE_TYPE_PARAMETERS_CONTAINER_DEFAULT_CAPACITY; +import static spoon.reflect.path.CtRole.IS_DEFAULT; +import static spoon.reflect.path.CtRole.IS_SHADOW; +import static spoon.reflect.path.CtRole.MODIFIER; +import static spoon.reflect.path.CtRole.TYPE; +import static spoon.reflect.path.CtRole.TYPE_PARAMETER; /** * The implementation for {@link spoon.reflect.declaration.CtMethod}. @@ -84,9 +82,7 @@ public C setType(CtTypeReference type) { if (type != null) { type.setParent(this); } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "returnType"), type, this.returnType)); - } + getFactory().Change().onObjectUpdate(this, TYPE, type, this.returnType); this.returnType = type; return (C) this; } @@ -98,9 +94,7 @@ public boolean isDefaultMethod() { @Override public > C setDefaultMethod(boolean defaultMethod) { - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "defaultMethod"), defaultMethod, this.defaultMethod)); - } + getFactory().Change().onObjectUpdate(this, IS_DEFAULT, defaultMethod, this.defaultMethod); this.defaultMethod = defaultMethod; return (C) this; } @@ -112,9 +106,7 @@ public List getFormalCtTypeParameters() { @Override public C setFormalCtTypeParameters(List formalTypeParameters) { - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new DeleteAllAction(new ListContext(this, this.formalCtTypeParameters), new ArrayList<>(this.formalCtTypeParameters))); - } + getFactory().Change().onListDeleteAll(this, TYPE_PARAMETER, this.formalCtTypeParameters, new ArrayList<>(this.formalCtTypeParameters)); if (formalTypeParameters == null || formalTypeParameters.isEmpty()) { this.formalCtTypeParameters = CtElementImpl.emptyList(); return (C) this; @@ -137,9 +129,7 @@ public C addFormalCtTypeParameter(CtTypeParamet if (formalCtTypeParameters == CtElementImpl.emptyList()) { formalCtTypeParameters = new ArrayList<>(TYPE_TYPE_PARAMETERS_CONTAINER_DEFAULT_CAPACITY); } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new AddAction(new ListContext(this, this.formalCtTypeParameters), formalTypeParameter)); - } + getFactory().Change().onListAdd(this, TYPE_PARAMETER, this.formalCtTypeParameters, formalTypeParameter); formalTypeParameter.setParent(this); formalCtTypeParameters.add(formalTypeParameter); return (C) this; @@ -150,9 +140,7 @@ public boolean removeFormalCtTypeParameter(CtTypeParameter formalTypeParameter) if (formalCtTypeParameters == CtElementImpl.emptyList()) { return false; } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new DeleteAction(new ListContext(this, formalCtTypeParameters, formalCtTypeParameters.indexOf(formalTypeParameter)), formalTypeParameter)); - } + getFactory().Change().onListDelete(this, TYPE_PARAMETER, formalCtTypeParameters, formalCtTypeParameters.indexOf(formalTypeParameter), formalTypeParameter); return formalCtTypeParameters.remove(formalTypeParameter); } @@ -169,9 +157,7 @@ public boolean hasModifier(ModifierKind modifier) { @Override public C setModifiers(Set modifiers) { if (modifiers.size() > 0) { - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new DeleteAllAction(new SetContext(this, this.modifiers), new HashSet<>(this.modifiers))); - } + getFactory().Change().onSetDeleteAll(this, MODIFIER, this.modifiers, new HashSet<>(this.modifiers)); this.modifiers.clear(); for (ModifierKind modifier : modifiers) { addModifier(modifier); @@ -185,10 +171,7 @@ public C addModifier(ModifierKind modifier) { if (modifiers == CtElementImpl.emptySet()) { this.modifiers = EnumSet.noneOf(ModifierKind.class); } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new AddAction(new SetContext( - this, this.modifiers), modifier)); - } + getFactory().Change().onSetAdd(this, MODIFIER, this.modifiers, modifier); modifiers.add(modifier); return (C) this; } @@ -198,10 +181,7 @@ public boolean removeModifier(ModifierKind modifier) { if (modifiers == CtElementImpl.emptySet()) { return false; } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new DeleteAction(new SetContext( - this, modifiers), modifier)); - } + getFactory().Change().onSetDelete(this, MODIFIER, modifiers, modifier); return modifiers.remove(modifier); } @@ -251,9 +231,7 @@ public boolean isShadow() { @Override public E setShadow(boolean isShadow) { - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "isShadow"), isShadow, this.isShadow)); - } + getFactory().Change().onObjectUpdate(this, IS_SHADOW, isShadow, this.isShadow); this.isShadow = isShadow; return (E) this; } diff --git a/src/main/java/spoon/support/reflect/declaration/CtNamedElementImpl.java b/src/main/java/spoon/support/reflect/declaration/CtNamedElementImpl.java index 8aeee28e620..f2677d56fd2 100644 --- a/src/main/java/spoon/support/reflect/declaration/CtNamedElementImpl.java +++ b/src/main/java/spoon/support/reflect/declaration/CtNamedElementImpl.java @@ -16,8 +16,6 @@ */ package spoon.support.reflect.declaration; -import spoon.diff.UpdateAction; -import spoon.diff.context.ObjectContext; import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.declaration.CtNamedElement; import spoon.reflect.factory.Factory; @@ -25,6 +23,8 @@ import spoon.reflect.path.CtRole; import spoon.reflect.reference.CtReference; +import static spoon.reflect.path.CtRole.NAME; + public abstract class CtNamedElementImpl extends CtElementImpl implements CtNamedElement { private static final long serialVersionUID = 1L; @@ -52,9 +52,7 @@ public T setSimpleName(String simpleName) { if (factory instanceof FactoryImpl) { simpleName = ((FactoryImpl) factory).dedup(simpleName); } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "simpleName"), simpleName, this.simpleName)); - } + getFactory().Change().onObjectUpdate(this, NAME, simpleName, this.simpleName); this.simpleName = simpleName; return (T) this; } diff --git a/src/main/java/spoon/support/reflect/declaration/CtPackageImpl.java b/src/main/java/spoon/support/reflect/declaration/CtPackageImpl.java index ab01a9ed807..3d36b4d9530 100644 --- a/src/main/java/spoon/support/reflect/declaration/CtPackageImpl.java +++ b/src/main/java/spoon/support/reflect/declaration/CtPackageImpl.java @@ -16,12 +16,6 @@ */ package spoon.support.reflect.declaration; -import spoon.diff.AddAction; -import spoon.diff.DeleteAction; -import spoon.diff.DeleteAllAction; -import spoon.diff.UpdateAction; -import spoon.diff.context.ObjectContext; -import spoon.diff.context.SetContext; import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.cu.SourcePosition; import spoon.reflect.declaration.CtPackage; @@ -35,6 +29,11 @@ import java.util.HashSet; import java.util.Set; + +import static spoon.reflect.path.CtRole.IS_SHADOW; +import static spoon.reflect.path.CtRole.SUB_PACKAGE; +import static spoon.reflect.path.CtRole.TYPE; + /** * The implementation for {@link spoon.reflect.declaration.CtPackage}. * @@ -83,10 +82,7 @@ public T addPackage(CtPackage pack) { } pack.setParent(this); - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new AddAction(new SetContext( - this, this.packs), pack)); - } + getFactory().Change().onSetAdd(this, SUB_PACKAGE, this.packs, pack); this.packs.add(pack); return (T) this; @@ -124,10 +120,7 @@ public boolean removePackage(CtPackage pack) { if (packs == CtElementImpl.emptySet()) { return false; } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new DeleteAction(new SetContext( - this, packs), pack)); - } + getFactory().Change().onSetDelete(this, SUB_PACKAGE, packs, pack); return packs.remove(pack); } @@ -186,10 +179,7 @@ public T setPackages(Set packs) { this.packs = CtElementImpl.emptySet(); return (T) this; } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new DeleteAllAction(new SetContext( - this, this.packs), new HashSet<>(this.packs))); - } + getFactory().Change().onSetDeleteAll(this, SUB_PACKAGE, this.packs, new HashSet<>(this.packs)); this.packs.clear(); for (CtPackage p : packs) { addPackage(p); @@ -203,10 +193,7 @@ public T setTypes(Set> types) { this.types = CtElementImpl.emptySet(); return (T) this; } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new DeleteAllAction(new SetContext( - this, this.types), new HashSet<>(this.types))); - } + getFactory().Change().onSetDeleteAll(this, TYPE, this.types, new HashSet<>(this.types)); this.types.clear(); for (CtType t : types) { addType(t); @@ -228,10 +215,7 @@ public T addType(CtType type) { this.types = orderedTypeSet(); } type.setParent(this); - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new AddAction(new SetContext( - this, this.types), type)); - } + getFactory().Change().onSetAdd(this, TYPE, this.types, type); types.add(type); return (T) this; } @@ -241,10 +225,7 @@ public boolean removeType(CtType type) { if (types == CtElementImpl.>emptySet()) { return false; } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new DeleteAction(new SetContext( - this, types), type)); - } + getFactory().Change().onSetDelete(this, TYPE, types, type); return types.remove(type); } @@ -276,9 +257,7 @@ public boolean isShadow() { @Override public E setShadow(boolean isShadow) { - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "isShadow"), isShadow, this.isShadow)); - } + getFactory().Change().onObjectUpdate(this, IS_SHADOW, isShadow, this.isShadow); this.isShadow = isShadow; return (E) this; } diff --git a/src/main/java/spoon/support/reflect/declaration/CtParameterImpl.java b/src/main/java/spoon/support/reflect/declaration/CtParameterImpl.java index ac4b376df96..e37abede0be 100644 --- a/src/main/java/spoon/support/reflect/declaration/CtParameterImpl.java +++ b/src/main/java/spoon/support/reflect/declaration/CtParameterImpl.java @@ -16,12 +16,6 @@ */ package spoon.support.reflect.declaration; -import spoon.diff.AddAction; -import spoon.diff.DeleteAction; -import spoon.diff.DeleteAllAction; -import spoon.diff.UpdateAction; -import spoon.diff.context.ObjectContext; -import spoon.diff.context.SetContext; import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.code.CtExpression; import spoon.reflect.declaration.CtExecutable; @@ -41,6 +35,11 @@ import java.util.HashSet; import java.util.Set; +import static spoon.reflect.path.CtRole.IS_SHADOW; +import static spoon.reflect.path.CtRole.IS_VARARGS; +import static spoon.reflect.path.CtRole.MODIFIER; +import static spoon.reflect.path.CtRole.TYPE; + /** * The implementation for {@link spoon.reflect.declaration.CtParameter}. * @@ -94,9 +93,7 @@ public C setType(CtTypeReference type) { if (type != null) { type.setParent(this); } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "type"), type, this.type)); - } + getFactory().Change().onObjectUpdate(this, TYPE, type, this.type); this.type = type; return (C) this; } @@ -108,9 +105,7 @@ public boolean isVarArgs() { @Override public > C setVarArgs(boolean varArgs) { - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "varArgs"), varArgs, this.varArgs)); - } + getFactory().Change().onObjectUpdate(this, IS_VARARGS, varArgs, this.varArgs); this.varArgs = varArgs; return (C) this; } @@ -128,9 +123,7 @@ public boolean hasModifier(ModifierKind modifier) { @Override public C setModifiers(Set modifiers) { if (modifiers.size() > 0) { - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new DeleteAllAction(new SetContext(this, this.modifiers), new HashSet<>(this.modifiers))); - } + getFactory().Change().onSetDeleteAll(this, MODIFIER, this.modifiers, new HashSet<>(this.modifiers)); this.modifiers.clear(); for (ModifierKind modifier : modifiers) { addModifier(modifier); @@ -144,10 +137,7 @@ public C addModifier(ModifierKind modifier) { if (modifiers == CtElementImpl.emptySet()) { this.modifiers = EnumSet.noneOf(ModifierKind.class); } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new AddAction(new SetContext( - this, this.modifiers), modifier)); - } + getFactory().Change().onSetAdd(this, MODIFIER, this.modifiers, modifier); modifiers.add(modifier); return (C) this; } @@ -157,10 +147,7 @@ public boolean removeModifier(ModifierKind modifier) { if (modifiers == CtElementImpl.emptySet()) { return false; } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new DeleteAction(new SetContext( - this, modifiers), modifier)); - } + getFactory().Change().onSetDelete(this, MODIFIER, modifiers, modifier); return modifiers.remove(modifier); } @@ -169,10 +156,10 @@ public C setVisibility(ModifierKind visibility) { if (modifiers == CtElementImpl.emptySet()) { this.modifiers = EnumSet.noneOf(ModifierKind.class); } - getModifiers().remove(ModifierKind.PUBLIC); - getModifiers().remove(ModifierKind.PROTECTED); - getModifiers().remove(ModifierKind.PRIVATE); - getModifiers().add(visibility); + removeModifier(ModifierKind.PUBLIC); + removeModifier(ModifierKind.PROTECTED); + removeModifier(ModifierKind.PRIVATE); + addModifier(visibility); return (C) this; } @@ -205,9 +192,7 @@ public boolean isShadow() { @Override public E setShadow(boolean isShadow) { - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "isShadow"), isShadow, this.isShadow)); - } + getFactory().Change().onObjectUpdate(this, IS_SHADOW, isShadow, this.isShadow); this.isShadow = isShadow; return (E) this; } diff --git a/src/main/java/spoon/support/reflect/declaration/CtTypeImpl.java b/src/main/java/spoon/support/reflect/declaration/CtTypeImpl.java index c2f3f3099db..4b09a5795f0 100644 --- a/src/main/java/spoon/support/reflect/declaration/CtTypeImpl.java +++ b/src/main/java/spoon/support/reflect/declaration/CtTypeImpl.java @@ -17,13 +17,6 @@ package spoon.support.reflect.declaration; import spoon.SpoonException; -import spoon.diff.AddAction; -import spoon.diff.DeleteAction; -import spoon.diff.DeleteAllAction; -import spoon.diff.UpdateAction; -import spoon.diff.context.ListContext; -import spoon.diff.context.ObjectContext; -import spoon.diff.context.SetContext; import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.code.CtBlock; import spoon.reflect.declaration.CtAnnotation; @@ -72,6 +65,14 @@ import java.util.Set; import static spoon.reflect.ModelElementContainerDefaultCapacities.TYPE_TYPE_PARAMETERS_CONTAINER_DEFAULT_CAPACITY; +import static spoon.reflect.path.CtRole.CONSTRUCTOR; +import static spoon.reflect.path.CtRole.EXECUTABLE; +import static spoon.reflect.path.CtRole.FIELD; +import static spoon.reflect.path.CtRole.INTERFACE; +import static spoon.reflect.path.CtRole.IS_SHADOW; +import static spoon.reflect.path.CtRole.MODIFIER; +import static spoon.reflect.path.CtRole.NESTED_TYPE; +import static spoon.reflect.path.CtRole.TYPE_PARAMETER; /** * The implementation for {@link spoon.reflect.declaration.CtType}. @@ -122,9 +123,17 @@ public > C addTypeMemberAt(int position, CtTypeMember member } if (!this.typeMembers.contains(member)) { member.setParent(this); - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new AddAction(new ListContext(this, this.typeMembers, position), member)); + CtRole role; + if (member instanceof CtMethod) { + role = EXECUTABLE; + } else if (member instanceof CtConstructor) { + role = CONSTRUCTOR; + } else if (member instanceof CtField) { + role = FIELD; + } else { + role = NESTED_TYPE; } + getFactory().Change().onListAdd(this, role, this.typeMembers, position, member); this.typeMembers.add(position, member); } return (C) this; @@ -132,11 +141,19 @@ public > C addTypeMemberAt(int position, CtTypeMember member @Override public boolean removeTypeMember(CtTypeMember member) { + CtRole role; + if (member instanceof CtMethod) { + role = EXECUTABLE; + } else if (member instanceof CtConstructor) { + role = CONSTRUCTOR; + } else if (member instanceof CtField) { + role = FIELD; + } else { + role = NESTED_TYPE; + } if (typeMembers.size() == 1) { if (typeMembers.contains(member)) { - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new DeleteAction(new ListContext(this, this.typeMembers, this.typeMembers.indexOf(member)), typeMembers)); - } + getFactory().Change().onListDelete(this, role, this.typeMembers, this.typeMembers.indexOf(member), member); typeMembers = emptyList(); return true; } else { @@ -144,9 +161,7 @@ public boolean removeTypeMember(CtTypeMember member) { } } if (typeMembers.contains(member)) { - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new DeleteAction(new ListContext(this, this.typeMembers, this.typeMembers.indexOf(member)), typeMembers)); - } + getFactory().Change().onListDelete(this, role, this.typeMembers, this.typeMembers.indexOf(member), member); return typeMembers.remove(member); } return false; @@ -154,8 +169,8 @@ public boolean removeTypeMember(CtTypeMember member) { @Override public > C setTypeMembers(List members) { - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new DeleteAllAction(new ListContext(this, typeMembers), new ArrayList<>(typeMembers))); + for (CtTypeMember typeMember : new ArrayList<>(typeMembers)) { + removeTypeMember(typeMember); } if (members == null || members.isEmpty()) { this.typeMembers = emptyList(); @@ -190,9 +205,7 @@ public > C setFields(List> fields) { this.typeMembers.removeAll(oldFields); return (C) this; } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new DeleteAllAction(new ListContext(this, this.typeMembers), new ArrayList<>(oldFields))); - } + getFactory().Change().onListDelete(this, FIELD, this.typeMembers, new ArrayList<>(oldFields)); typeMembers.removeAll(oldFields); for (CtField field : fields) { addField(field); @@ -252,11 +265,7 @@ public boolean removeNestedType(CtType nestedType) { @Override public > C setNestedTypes(Set> nestedTypes) { Set> oldNestedTypes = getNestedTypes(); - if (getFactory().getEnvironment().buildStackChanges()) { - for (CtType oldNestedType : oldNestedTypes) { - getFactory().getEnvironment().pushToStack(new DeleteAction(new ListContext(this, typeMembers), oldNestedType)); - } - } + getFactory().Change().onListDelete(this, NESTED_TYPE, typeMembers, oldNestedTypes); if (nestedTypes == null || nestedTypes.isEmpty()) { this.typeMembers.removeAll(oldNestedTypes); return (C) this; @@ -454,9 +463,7 @@ public boolean hasModifier(ModifierKind modifier) { @Override public C setModifiers(Set modifiers) { if (modifiers.size() > 0) { - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new DeleteAllAction(new SetContext(this, this.modifiers), new HashSet<>(this.modifiers))); - } + getFactory().Change().onSetDeleteAll(this, MODIFIER, this.modifiers, new HashSet<>(this.modifiers)); this.modifiers.clear(); for (ModifierKind modifier : modifiers) { addModifier(modifier); @@ -470,10 +477,7 @@ public C addModifier(ModifierKind modifier) { if (modifiers == CtElementImpl.emptySet()) { this.modifiers = EnumSet.of(modifier); } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new AddAction(new SetContext( - this, this.modifiers), modifier)); - } + getFactory().Change().onSetAdd(this, MODIFIER, this.modifiers, modifier); modifiers.add(modifier); return (C) this; } @@ -483,10 +487,7 @@ public boolean removeModifier(ModifierKind modifier) { if (modifiers == CtElementImpl.emptySet()) { return false; } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new DeleteAction(new SetContext( - this, modifiers), modifier)); - } + getFactory().Change().onSetDelete(this, MODIFIER, modifiers, modifier); return modifiers.remove(modifier); } @@ -495,10 +496,10 @@ public C setVisibility(ModifierKind visibility) { if (modifiers == CtElementImpl.emptySet()) { this.modifiers = EnumSet.noneOf(ModifierKind.class); } - getModifiers().remove(ModifierKind.PUBLIC); - getModifiers().remove(ModifierKind.PROTECTED); - getModifiers().remove(ModifierKind.PRIVATE); - getModifiers().add(visibility); + removeModifier(ModifierKind.PUBLIC); + removeModifier(ModifierKind.PROTECTED); + removeModifier(ModifierKind.PRIVATE); + addModifier(visibility); return (C) this; } @@ -625,19 +626,14 @@ public > C addSuperInterface(CtTypeReference interfac) interfaces = new QualifiedNameBasedSortedSet<>(); } interfac.setParent(this); - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new AddAction(new SetContext( - this, this.interfaces), interfac)); - } + getFactory().Change().onSetAdd(this, INTERFACE, this.interfaces, interfac); interfaces.add(interfac); return (C) this; } @Override public boolean removeSuperInterface(CtTypeReference interfac) { - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new DeleteAction(new SetContext(this, interfaces), interfac)); - } + getFactory().Change().onSetDelete(this, INTERFACE, interfaces, interfac); if (interfaces == CtElementImpl.>emptySet()) { return false; } else if (interfaces.size() == 1) { @@ -660,9 +656,7 @@ public List getFormalCtTypeParameters() { @Override public C setFormalCtTypeParameters(List formalTypeParameters) { - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new DeleteAllAction(new ListContext(this, formalCtTypeParameters), new ArrayList<>(formalCtTypeParameters))); - } + getFactory().Change().onListDeleteAll(this, TYPE_PARAMETER, formalCtTypeParameters, new ArrayList<>(formalCtTypeParameters)); if (formalTypeParameters == null || formalTypeParameters.isEmpty()) { this.formalCtTypeParameters = CtElementImpl.emptyList(); return (C) this; @@ -686,9 +680,7 @@ public C addFormalCtTypeParameter(CtTypeParamet formalCtTypeParameters = new ArrayList<>(TYPE_TYPE_PARAMETERS_CONTAINER_DEFAULT_CAPACITY); } formalTypeParameter.setParent(this); - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new AddAction(new ListContext(this, this.formalCtTypeParameters), formalTypeParameter)); - } + getFactory().Change().onListAdd(this, TYPE_PARAMETER, this.formalCtTypeParameters, formalTypeParameter); formalCtTypeParameters.add(formalTypeParameter); return (C) this; } @@ -698,9 +690,7 @@ public boolean removeFormalCtTypeParameter(CtTypeParameter formalTypeParameter) if (formalCtTypeParameters == CtElementImpl.emptyList()) { return false; } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new DeleteAction(new ListContext(this, formalCtTypeParameters, formalCtTypeParameters.indexOf(formalTypeParameter)), formalTypeParameter)); - } + getFactory().Change().onListDelete(this, TYPE_PARAMETER, formalCtTypeParameters, formalCtTypeParameters.indexOf(formalTypeParameter), formalTypeParameter); return formalCtTypeParameters.remove(formalTypeParameter); } @@ -910,14 +900,12 @@ public Set> getSuperInterfaces() { @Override public > C setMethods(Set> methods) { + Set> allMethods = getMethods(); + getFactory().Change().onListDelete(this, EXECUTABLE, this.typeMembers, new ArrayList(allMethods)); + typeMembers.removeAll(allMethods); if (methods == null || methods.isEmpty()) { - this.typeMembers.removeAll(getMethods()); return (C) this; } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new DeleteAllAction(new ListContext(this, this.typeMembers), new ArrayList(getMethods()))); - } - typeMembers.removeAll(getMethods()); for (CtMethod meth : methods) { addMethod(meth); } @@ -940,10 +928,7 @@ public > C setSuperInterfaces(Set> interf if (this.interfaces == CtElementImpl.>emptySet()) { this.interfaces = new QualifiedNameBasedSortedSet<>(); } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new DeleteAllAction(new SetContext( - this, this.interfaces), new HashSet<>(this.interfaces))); - } + getFactory().Change().onSetDeleteAll(this, INTERFACE, this.interfaces, new HashSet<>(this.interfaces)); this.interfaces.clear(); for (CtTypeReference anInterface : interfaces) { addSuperInterface(anInterface); @@ -1006,9 +991,7 @@ public boolean isShadow() { @Override public E setShadow(boolean isShadow) { - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "isShadow"), isShadow, this.isShadow)); - } + getFactory().Change().onObjectUpdate(this, IS_SHADOW, isShadow, this.isShadow); this.isShadow = isShadow; return (E) this; } diff --git a/src/main/java/spoon/support/reflect/declaration/CtTypeParameterImpl.java b/src/main/java/spoon/support/reflect/declaration/CtTypeParameterImpl.java index 3498f6c9fc2..57fb4e750f0 100644 --- a/src/main/java/spoon/support/reflect/declaration/CtTypeParameterImpl.java +++ b/src/main/java/spoon/support/reflect/declaration/CtTypeParameterImpl.java @@ -16,8 +16,6 @@ */ package spoon.support.reflect.declaration; -import spoon.diff.UpdateAction; -import spoon.diff.context.ObjectContext; import spoon.reflect.annotations.MetamodelPropertyField; import spoon.reflect.declaration.CtField; import spoon.reflect.declaration.CtFormalTypeDeclarer; @@ -43,6 +41,8 @@ import java.util.List; import java.util.Set; +import static spoon.reflect.path.CtRole.SUPER_TYPE; + public class CtTypeParameterImpl extends CtTypeImpl implements CtTypeParameter { @MetamodelPropertyField(role = CtRole.SUPER_TYPE) CtTypeReference superClass; @@ -62,9 +62,7 @@ public > C setSuperclass(CtTypeReference superClass) if (superClass != null) { superClass.setParent(this); } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "superClass"), superClass, this.superClass)); - } + getFactory().Change().onObjectUpdate(this, SUPER_TYPE, superClass, this.superClass); this.superClass = superClass; return (C) this; } diff --git a/src/main/java/spoon/support/reflect/reference/CtArrayTypeReferenceImpl.java b/src/main/java/spoon/support/reflect/reference/CtArrayTypeReferenceImpl.java index 2446e744ddf..4296d176ddf 100644 --- a/src/main/java/spoon/support/reflect/reference/CtArrayTypeReferenceImpl.java +++ b/src/main/java/spoon/support/reflect/reference/CtArrayTypeReferenceImpl.java @@ -16,14 +16,14 @@ */ package spoon.support.reflect.reference; -import spoon.diff.UpdateAction; -import spoon.diff.context.ObjectContext; import spoon.reflect.reference.CtArrayTypeReference; import spoon.reflect.reference.CtTypeReference; import spoon.reflect.visitor.CtVisitor; import java.lang.reflect.Array; +import static spoon.reflect.path.CtRole.TYPE; + public class CtArrayTypeReferenceImpl extends CtTypeReferenceImpl implements CtArrayTypeReference { private static final long serialVersionUID = 1L; @@ -61,9 +61,7 @@ public > C setComponentType(CtTypeReference if (componentType != null) { componentType.setParent(this); } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "componentType"), componentType, this.componentType)); - } + getFactory().Change().onObjectUpdate(this, TYPE, componentType, this.componentType); this.componentType = componentType; return (C) this; } diff --git a/src/main/java/spoon/support/reflect/reference/CtExecutableReferenceImpl.java b/src/main/java/spoon/support/reflect/reference/CtExecutableReferenceImpl.java index 4330b1095ef..7a0192e2259 100644 --- a/src/main/java/spoon/support/reflect/reference/CtExecutableReferenceImpl.java +++ b/src/main/java/spoon/support/reflect/reference/CtExecutableReferenceImpl.java @@ -17,12 +17,6 @@ package spoon.support.reflect.reference; import spoon.Launcher; -import spoon.diff.AddAction; -import spoon.diff.DeleteAction; -import spoon.diff.DeleteAllAction; -import spoon.diff.UpdateAction; -import spoon.diff.context.ListContext; -import spoon.diff.context.ObjectContext; import spoon.reflect.code.CtLambda; import spoon.reflect.declaration.CtClass; import spoon.reflect.declaration.CtConstructor; @@ -51,6 +45,10 @@ import java.util.Set; import static spoon.reflect.ModelElementContainerDefaultCapacities.METHOD_TYPE_PARAMETERS_CONTAINER_DEFAULT_CAPACITY; +import static spoon.reflect.path.CtRole.IS_STATIC; +import static spoon.reflect.path.CtRole.PARAMETER; +import static spoon.reflect.path.CtRole.TYPE; +import static spoon.reflect.path.CtRole.TYPE_PARAMETER; public class CtExecutableReferenceImpl extends CtReferenceImpl implements CtExecutableReference { private static final long serialVersionUID = 1L; @@ -205,10 +203,7 @@ public > C setParameters(List>emptyList()) { this.parameters = new ArrayList<>(); } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new DeleteAllAction(new ListContext( - this, this.parameters), new ArrayList<>(this.parameters))); - } + getFactory().Change().onListDeleteAll(this, PARAMETER, this.parameters, new ArrayList<>(this.parameters)); this.parameters.clear(); for (CtTypeReference parameter : parameters) { addParameter(parameter); @@ -221,10 +216,7 @@ private boolean addParameter(CtTypeReference parameter) { return false; } parameter.setParent(this); - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new AddAction(new ListContext( - this, this.parameters), parameter)); - } + getFactory().Change().onListAdd(this, PARAMETER, this.parameters, parameter); return this.parameters.add(parameter); } @@ -282,10 +274,7 @@ public C setActualTypeArguments(List>emptyList()) { this.actualTypeArguments = new ArrayList<>(); } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new DeleteAllAction(new ListContext( - this, this.actualTypeArguments), new ArrayList<>(this.actualTypeArguments))); - } + getFactory().Change().onListDeleteAll(this, TYPE_PARAMETER, this.actualTypeArguments, new ArrayList<>(this.actualTypeArguments)); this.actualTypeArguments.clear(); for (CtTypeReference actualTypeArgument : actualTypeArguments) { addActualTypeArgument(actualTypeArgument); @@ -298,9 +287,7 @@ public > C setDeclaringType(CtTypeReference> C setType(CtTypeReference type) { if (type != null) { type.setParent(this); } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "type"), type, this.type)); - } + getFactory().Change().onObjectUpdate(this, TYPE, type, this.type); this.type = type; return (C) this; } @@ -378,9 +363,7 @@ public boolean isStatic() { @Override public > C setStatic(boolean stat) { - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "stat"), stat, this.stat)); - } + getFactory().Change().onObjectUpdate(this, IS_STATIC, stat, this.stat); this.stat = stat; return (C) this; } @@ -464,10 +447,7 @@ public C addActualTypeArgument(CtTypeReference actualTypeArguments = new ArrayList<>(METHOD_TYPE_PARAMETERS_CONTAINER_DEFAULT_CAPACITY); } actualTypeArgument.setParent(this); - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new AddAction(new ListContext( - this, this.actualTypeArguments), actualTypeArgument)); - } + getFactory().Change().onListAdd(this, TYPE_PARAMETER, this.actualTypeArguments, actualTypeArgument); actualTypeArguments.add(actualTypeArgument); return (C) this; } @@ -477,10 +457,7 @@ public boolean removeActualTypeArgument(CtTypeReference actualTypeArgument) { if (actualTypeArguments == CtElementImpl.>emptyList()) { return false; } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new DeleteAction(new ListContext( - this, actualTypeArguments, actualTypeArguments.indexOf(actualTypeArgument)), actualTypeArgument)); - } + getFactory().Change().onListDelete(this, TYPE_PARAMETER, actualTypeArguments, actualTypeArguments.indexOf(actualTypeArgument), actualTypeArgument); return actualTypeArguments.remove(actualTypeArgument); } diff --git a/src/main/java/spoon/support/reflect/reference/CtFieldReferenceImpl.java b/src/main/java/spoon/support/reflect/reference/CtFieldReferenceImpl.java index 7b6a760ff08..6ccfb75df84 100644 --- a/src/main/java/spoon/support/reflect/reference/CtFieldReferenceImpl.java +++ b/src/main/java/spoon/support/reflect/reference/CtFieldReferenceImpl.java @@ -17,8 +17,6 @@ package spoon.support.reflect.reference; import spoon.Launcher; -import spoon.diff.UpdateAction; -import spoon.diff.context.ObjectContext; import spoon.reflect.declaration.CtEnum; import spoon.reflect.declaration.CtField; import spoon.reflect.declaration.CtType; @@ -34,6 +32,10 @@ import java.util.Collections; import java.util.Set; +import static spoon.reflect.path.CtRole.IS_FINAL; +import static spoon.reflect.path.CtRole.IS_STATIC; +import static spoon.reflect.path.CtRole.TYPE; + public class CtFieldReferenceImpl extends CtVariableReferenceImpl implements CtFieldReference { private static final long serialVersionUID = 1L; @@ -188,27 +190,21 @@ public > C setDeclaringType(CtTypeReference dec if (declaringType != null) { declaringType.setParent(this); } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "declaringType"), declaringType, this.declaringType)); - } + getFactory().Change().onObjectUpdate(this, TYPE, declaringType, this.declaringType); this.declaringType = declaringType; return (C) this; } @Override public > C setFinal(boolean fina) { - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "fina"), fina, this.fina)); - } + getFactory().Change().onObjectUpdate(this, IS_FINAL, fina, this.fina); this.fina = fina; return (C) this; } @Override public > C setStatic(boolean stat) { - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "stat"), stat, this.stat)); - } + getFactory().Change().onObjectUpdate(this, IS_STATIC, stat, this.stat); this.stat = stat; return (C) this; } diff --git a/src/main/java/spoon/support/reflect/reference/CtIntersectionTypeReferenceImpl.java b/src/main/java/spoon/support/reflect/reference/CtIntersectionTypeReferenceImpl.java index e4547c06138..4ffee4df7ca 100644 --- a/src/main/java/spoon/support/reflect/reference/CtIntersectionTypeReferenceImpl.java +++ b/src/main/java/spoon/support/reflect/reference/CtIntersectionTypeReferenceImpl.java @@ -16,10 +16,6 @@ */ package spoon.support.reflect.reference; -import spoon.diff.AddAction; -import spoon.diff.DeleteAction; -import spoon.diff.DeleteAllAction; -import spoon.diff.context.ListContext; import spoon.reflect.reference.CtIntersectionTypeReference; import spoon.reflect.reference.CtTypeReference; import spoon.reflect.visitor.CtVisitor; @@ -29,6 +25,9 @@ import java.util.Collections; import java.util.List; +import static spoon.reflect.path.CtRole.BOUND; + + public class CtIntersectionTypeReferenceImpl extends CtTypeReferenceImpl implements CtIntersectionTypeReference { List> bounds = CtElementImpl.emptyList(); @@ -54,9 +53,7 @@ public C setBounds(List>emptySet()) { this.bounds = new ArrayList<>(); } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new DeleteAllAction(new ListContext(this, this.bounds), new ArrayList<>(this.bounds))); - } + getFactory().Change().onListDeleteAll(this, BOUND, this.bounds, new ArrayList<>(this.bounds)); this.bounds.clear(); for (CtTypeReference bound : bounds) { addBound(bound); @@ -74,9 +71,7 @@ public C addBound(CtTypeReference bou } if (!bounds.contains(bound)) { bound.setParent(this); - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new AddAction(new ListContext(this, this.bounds), bound)); - } + getFactory().Change().onListAdd(this, BOUND, this.bounds, bound); bounds.add(bound); } return (C) this; @@ -87,10 +82,7 @@ public boolean removeBound(CtTypeReference bound) { if (bounds == CtElementImpl.>emptyList()) { return false; } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new DeleteAction(new ListContext(this, bounds, bounds.indexOf(bound)), bound)); - - } + getFactory().Change().onListDelete(this, BOUND, bounds, bounds.indexOf(bound), bound); return bounds.remove(bound); } diff --git a/src/main/java/spoon/support/reflect/reference/CtParameterReferenceImpl.java b/src/main/java/spoon/support/reflect/reference/CtParameterReferenceImpl.java index a822f04f7ae..0933c55f677 100644 --- a/src/main/java/spoon/support/reflect/reference/CtParameterReferenceImpl.java +++ b/src/main/java/spoon/support/reflect/reference/CtParameterReferenceImpl.java @@ -16,8 +16,6 @@ */ package spoon.support.reflect.reference; -import spoon.diff.UpdateAction; -import spoon.diff.context.ObjectContext; import spoon.reflect.declaration.CtElement; import spoon.reflect.declaration.CtExecutable; import spoon.reflect.declaration.CtParameter; @@ -28,6 +26,8 @@ import java.util.List; +import static spoon.reflect.path.CtRole.EXECUTABLE; + public class CtParameterReferenceImpl extends CtVariableReferenceImpl implements CtParameterReference { private static final long serialVersionUID = 1L; @@ -99,9 +99,7 @@ public > C setDeclaringExecutable(CtExecutable if (executable != null) { executable.setParent(this); } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "executable"), executable, this.executable)); - } + getFactory().Change().onObjectUpdate(this, EXECUTABLE, executable, this.executable); this.executable = executable; return (C) this; } diff --git a/src/main/java/spoon/support/reflect/reference/CtReferenceImpl.java b/src/main/java/spoon/support/reflect/reference/CtReferenceImpl.java index a8a74a0ca18..9ccf7cb19c2 100644 --- a/src/main/java/spoon/support/reflect/reference/CtReferenceImpl.java +++ b/src/main/java/spoon/support/reflect/reference/CtReferenceImpl.java @@ -16,8 +16,6 @@ */ package spoon.support.reflect.reference; -import spoon.diff.UpdateAction; -import spoon.diff.context.ObjectContext; import spoon.reflect.factory.Factory; import spoon.reflect.factory.FactoryImpl; import spoon.reflect.reference.CtReference; @@ -28,6 +26,8 @@ import java.io.Serializable; import java.lang.reflect.AnnotatedElement; +import static spoon.reflect.path.CtRole.NAME; + public abstract class CtReferenceImpl extends CtElementImpl implements CtReference, Serializable { private static final long serialVersionUID = 1L; @@ -55,9 +55,7 @@ public T setSimpleName(String simplename) { if (factory instanceof FactoryImpl) { simplename = ((FactoryImpl) factory).dedup(simplename); } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "simplename"), simplename, this.simplename)); - } + getFactory().Change().onObjectUpdate(this, NAME, simplename, this.simplename); this.simplename = simplename; return (T) this; } diff --git a/src/main/java/spoon/support/reflect/reference/CtTypeParameterReferenceImpl.java b/src/main/java/spoon/support/reflect/reference/CtTypeParameterReferenceImpl.java index 62aeec3e0b8..f9effbbb873 100644 --- a/src/main/java/spoon/support/reflect/reference/CtTypeParameterReferenceImpl.java +++ b/src/main/java/spoon/support/reflect/reference/CtTypeParameterReferenceImpl.java @@ -17,8 +17,6 @@ package spoon.support.reflect.reference; import spoon.SpoonException; -import spoon.diff.UpdateAction; -import spoon.diff.context.ObjectContext; import spoon.reflect.declaration.CtElement; import spoon.reflect.declaration.CtFormalTypeDeclarer; import spoon.reflect.declaration.CtMethod; @@ -36,6 +34,9 @@ import java.util.ArrayList; import java.util.List; +import static spoon.reflect.path.CtRole.SUPER_TYPE; +import static spoon.reflect.path.CtRole.IS_UPPER; + public class CtTypeParameterReferenceImpl extends CtTypeReferenceImpl implements CtTypeParameterReference { private static final long serialVersionUID = 1L; @@ -77,9 +78,7 @@ public T setBounds(List> @Override public T setUpper(boolean upper) { - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "upper"), upper, this.upper)); - } + getFactory().Change().onObjectUpdate(this, IS_UPPER, upper, this.upper); this.upper = upper; return (T) this; } @@ -165,9 +164,7 @@ public T setBoundingType(CtTypeReference if (superType != null) { superType.setParent(this); } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "superType"), superType, this.superType)); - } + getFactory().Change().onObjectUpdate(this, SUPER_TYPE, superType, this.superType); this.superType = superType; return (T) this; } diff --git a/src/main/java/spoon/support/reflect/reference/CtTypeReferenceImpl.java b/src/main/java/spoon/support/reflect/reference/CtTypeReferenceImpl.java index ce5cccf7a22..58da884e891 100644 --- a/src/main/java/spoon/support/reflect/reference/CtTypeReferenceImpl.java +++ b/src/main/java/spoon/support/reflect/reference/CtTypeReferenceImpl.java @@ -18,12 +18,6 @@ import spoon.Launcher; import spoon.SpoonException; -import spoon.diff.AddAction; -import spoon.diff.DeleteAction; -import spoon.diff.DeleteAllAction; -import spoon.diff.UpdateAction; -import spoon.diff.context.ListContext; -import spoon.diff.context.ObjectContext; import spoon.reflect.declaration.CtConstructor; import spoon.reflect.declaration.CtElement; import spoon.reflect.declaration.CtExecutable; @@ -61,6 +55,10 @@ import java.util.regex.Pattern; import static spoon.reflect.ModelElementContainerDefaultCapacities.TYPE_TYPE_PARAMETERS_CONTAINER_DEFAULT_CAPACITY; +import static spoon.reflect.path.CtRole.IS_SHADOW; +import static spoon.reflect.path.CtRole.PACKAGE_REF; +import static spoon.reflect.path.CtRole.TYPE; +import static spoon.reflect.path.CtRole.TYPE_PARAMETER; public class CtTypeReferenceImpl extends CtReferenceImpl implements CtTypeReference { private static final long serialVersionUID = 1L; @@ -258,10 +256,7 @@ public C setActualTypeArguments(List>emptyList()) { this.actualTypeArguments = new ArrayList<>(TYPE_TYPE_PARAMETERS_CONTAINER_DEFAULT_CAPACITY); } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new DeleteAllAction(new ListContext( - this, this.actualTypeArguments), new ArrayList<>(this.actualTypeArguments))); - } + getFactory().Change().onListDeleteAll(this, TYPE_PARAMETER, this.actualTypeArguments, new ArrayList<>(this.actualTypeArguments)); this.actualTypeArguments.clear(); for (CtTypeReference actualTypeArgument : actualTypeArguments) { addActualTypeArgument(actualTypeArgument); @@ -274,9 +269,7 @@ public > C setDeclaringType(CtTypeReference decl if (declaringType != null) { declaringType.setParent(this); } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "declaringType"), declaringType, this.declaringType)); - } + getFactory().Change().onObjectUpdate(this, TYPE, declaringType, this.declaringType); this.declaringType = declaringType; return (C) this; } @@ -286,9 +279,7 @@ public > C setPackage(CtPackageReference pack) { if (pack != null) { pack.setParent(this); } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "pack"), pack, this.pack)); - } + getFactory().Change().onObjectUpdate(this, PACKAGE_REF, pack, this.pack); this.pack = pack; return (C) this; } @@ -573,10 +564,7 @@ public C addActualTypeArgument(CtTypeReference actualTypeArguments = new ArrayList<>(TYPE_TYPE_PARAMETERS_CONTAINER_DEFAULT_CAPACITY); } actualTypeArgument.setParent(this); - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new AddAction(new ListContext( - this, this.actualTypeArguments), actualTypeArgument)); - } + getFactory().Change().onListAdd(this, TYPE_PARAMETER, this.actualTypeArguments, actualTypeArgument); actualTypeArguments.add(actualTypeArgument); return (C) this; } @@ -586,10 +574,7 @@ public boolean removeActualTypeArgument(CtTypeReference actualTypeArgument) { if (actualTypeArguments == CtElementImpl.>emptyList()) { return false; } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new DeleteAction(new ListContext( - this, actualTypeArguments, actualTypeArguments.indexOf(actualTypeArgument)), actualTypeArgument)); - } + getFactory().Change().onListDelete(this, TYPE_PARAMETER, actualTypeArguments, actualTypeArguments.indexOf(actualTypeArgument), actualTypeArgument); return actualTypeArguments.remove(actualTypeArgument); } @@ -807,9 +792,7 @@ public boolean isShadow() { @Override public E setShadow(boolean isShadow) { - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "isShadow"), isShadow, this.isShadow)); - } + getFactory().Change().onObjectUpdate(this, IS_SHADOW, isShadow, this.isShadow); this.isShadow = isShadow; return (E) this; } diff --git a/src/main/java/spoon/support/reflect/reference/CtVariableReferenceImpl.java b/src/main/java/spoon/support/reflect/reference/CtVariableReferenceImpl.java index 410c8f1fed3..05ff29c163a 100644 --- a/src/main/java/spoon/support/reflect/reference/CtVariableReferenceImpl.java +++ b/src/main/java/spoon/support/reflect/reference/CtVariableReferenceImpl.java @@ -16,8 +16,6 @@ */ package spoon.support.reflect.reference; -import spoon.diff.UpdateAction; -import spoon.diff.context.ObjectContext; import spoon.reflect.declaration.CtVariable; import spoon.reflect.declaration.ModifierKind; import spoon.reflect.reference.CtTypeReference; @@ -28,6 +26,8 @@ import java.util.Collections; import java.util.Set; +import static spoon.reflect.path.CtRole.TYPE; + public abstract class CtVariableReferenceImpl extends CtReferenceImpl implements CtVariableReference { private static final long serialVersionUID = 1L; @@ -52,9 +52,7 @@ public > C setType(CtTypeReference type) { if (type != null) { type.setParent(this); } - if (getFactory().getEnvironment().buildStackChanges()) { - getFactory().getEnvironment().pushToStack(new UpdateAction(new ObjectContext(this, "type"), type, this.type)); - } + getFactory().Change().onObjectUpdate(this, TYPE, type, this.type); this.type = type; return (C) this; } From 0b14e247f9a168f237729d4340df9eb030eb66b3 Mon Sep 17 00:00:00 2001 From: tdurieux Date: Fri, 23 Jun 2017 11:40:43 +0200 Subject: [PATCH 07/40] remove stack --- src/main/java/spoon/compiler/Environment.java | 18 -------- .../spoon/support/StandardEnvironment.java | 46 ------------------- 2 files changed, 64 deletions(-) diff --git a/src/main/java/spoon/compiler/Environment.java b/src/main/java/spoon/compiler/Environment.java index 72e24192104..1c8c3187e51 100644 --- a/src/main/java/spoon/compiler/Environment.java +++ b/src/main/java/spoon/compiler/Environment.java @@ -333,22 +333,4 @@ void report(Processor processor, Level level, /** Set the directory where binary .class files are created */ String getBinaryOutputDirectory(); - - /** - * Checks if we want to build the stack changes on the AST. - */ - boolean buildStackChanges(); - - /** - * If you set at true this method, you'll stack any changes done on your AST but you can't modify - * list or set returned by the AST. - */ - void setBuildStackChanges(boolean buildStackChanges); - - /** - * Push an action on the stack changes. - */ - void pushToStack(Action action); - - Deque getActionChanges(); } diff --git a/src/main/java/spoon/support/StandardEnvironment.java b/src/main/java/spoon/support/StandardEnvironment.java index ddc638c0349..f9b5bbad084 100644 --- a/src/main/java/spoon/support/StandardEnvironment.java +++ b/src/main/java/spoon/support/StandardEnvironment.java @@ -24,9 +24,6 @@ import spoon.compiler.InvalidClassPathException; import spoon.compiler.SpoonFile; import spoon.compiler.SpoonFolder; -import spoon.diff.AbstractModelChangeListener; -import spoon.diff.Action; -import spoon.diff.UpdateAction; import spoon.processing.FileGenerator; import spoon.processing.ProblemFixer; import spoon.processing.ProcessingManager; @@ -45,9 +42,7 @@ import java.net.MalformedURLException; import java.net.URL; import java.net.URLClassLoader; -import java.util.ArrayDeque; import java.util.ArrayList; -import java.util.Deque; import java.util.List; import java.util.Map; import java.util.TreeMap; @@ -90,10 +85,6 @@ public class StandardEnvironment implements Serializable, Environment { private boolean skipSelfChecks; - private boolean buildStackChanges; - - private Deque actions = new ArrayDeque<>(); - /** * Creates a new environment with a null default file * generator. @@ -158,43 +149,6 @@ public void setSelfChecks(boolean skip) { skipSelfChecks = skip; } - @Override - public boolean buildStackChanges() { - return buildStackChanges; - } - - private AbstractModelChangeListener stackListener = new AbstractModelChangeListener() { - @Override - public void onAction(Action action) { - factory.getEnvironment().pushToStack(action); - } - }; - - @Override - public void setBuildStackChanges(boolean buildStackChanges) { - this.buildStackChanges = buildStackChanges; - if (buildStackChanges) { - getFactory().Change().addModelChangeListener(stackListener); - } else { - getFactory().Change().removeModelChangeListener(stackListener); - } - } - - @Override - public void pushToStack(Action action) { - if (action instanceof UpdateAction) { - if (((UpdateAction) action).getOldElement() == ((UpdateAction) action).getNewElement()) { - return; - } - } - actions.push(action); - } - - @Override - public Deque getActionChanges() { - return actions; - } - private Level toLevel(String level) { if (level == null || level.isEmpty()) { throw new SpoonException("Wrong level given at Spoon."); From 2fd79e3315456e7aec336bcb572b578d05e97923 Mon Sep 17 00:00:00 2001 From: tdurieux Date: Fri, 23 Jun 2017 11:44:36 +0200 Subject: [PATCH 08/40] use spoon method to change modifiers --- .../reflect/declaration/CtAnonymousExecutableImpl.java | 8 ++++---- .../spoon/support/reflect/declaration/CtMethodImpl.java | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/java/spoon/support/reflect/declaration/CtAnonymousExecutableImpl.java b/src/main/java/spoon/support/reflect/declaration/CtAnonymousExecutableImpl.java index 8a0ef4b80ac..91b670bf1cd 100644 --- a/src/main/java/spoon/support/reflect/declaration/CtAnonymousExecutableImpl.java +++ b/src/main/java/spoon/support/reflect/declaration/CtAnonymousExecutableImpl.java @@ -107,10 +107,10 @@ public T setVisibility(ModifierKind visibility) { if (modifiers == CtElementImpl.emptySet()) { modifiers = EnumSet.noneOf(ModifierKind.class); } - getModifiers().remove(ModifierKind.PUBLIC); - getModifiers().remove(ModifierKind.PROTECTED); - getModifiers().remove(ModifierKind.PRIVATE); - getModifiers().add(visibility); + removeModifier(ModifierKind.PUBLIC); + removeModifier(ModifierKind.PROTECTED); + removeModifier(ModifierKind.PRIVATE); + addModifier(visibility); return (T) this; } diff --git a/src/main/java/spoon/support/reflect/declaration/CtMethodImpl.java b/src/main/java/spoon/support/reflect/declaration/CtMethodImpl.java index 92bff39d89a..c99075fd865 100644 --- a/src/main/java/spoon/support/reflect/declaration/CtMethodImpl.java +++ b/src/main/java/spoon/support/reflect/declaration/CtMethodImpl.java @@ -190,10 +190,10 @@ public C setVisibility(ModifierKind visibility) { if (modifiers == CtElementImpl.emptySet()) { this.modifiers = EnumSet.noneOf(ModifierKind.class); } - getModifiers().remove(ModifierKind.PUBLIC); - getModifiers().remove(ModifierKind.PROTECTED); - getModifiers().remove(ModifierKind.PRIVATE); - getModifiers().add(visibility); + removeModifier(ModifierKind.PUBLIC); + removeModifier(ModifierKind.PROTECTED); + removeModifier(ModifierKind.PRIVATE); + addModifier(visibility); return (C) this; } From b350422234555b5158b372d77a95d44a57ae23a5 Mon Sep 17 00:00:00 2001 From: tdurieux Date: Fri, 23 Jun 2017 13:55:50 +0200 Subject: [PATCH 09/40] add getter and setter annotation for new roles --- .../java/spoon/reflect/reference/CtFieldReference.java | 7 +++++++ .../reflect/reference/CtIntersectionTypeReference.java | 7 +++++++ .../spoon/reflect/reference/CtTypeParameterReference.java | 5 +++++ src/main/java/spoon/reflect/reference/CtTypeReference.java | 5 +++++ .../spoon/support/reflect/declaration/CtElementImpl.java | 2 ++ 5 files changed, 26 insertions(+) diff --git a/src/main/java/spoon/reflect/reference/CtFieldReference.java b/src/main/java/spoon/reflect/reference/CtFieldReference.java index 44c179f1980..33b29b4bb8a 100644 --- a/src/main/java/spoon/reflect/reference/CtFieldReference.java +++ b/src/main/java/spoon/reflect/reference/CtFieldReference.java @@ -16,7 +16,10 @@ */ package spoon.reflect.reference; +import spoon.reflect.annotations.PropertyGetter; +import spoon.reflect.annotations.PropertySetter; import spoon.reflect.declaration.CtField; +import spoon.reflect.path.CtRole; import spoon.support.DerivedProperty; import java.lang.reflect.Member; @@ -62,11 +65,13 @@ public interface CtFieldReference extends CtVariableReference { /** * Tells if the referenced field is final. */ + @PropertyGetter(role = CtRole.IS_FINAL) boolean isFinal(); /** * Tells if the referenced field is static. */ + @PropertyGetter(role = CtRole.IS_STATIC) boolean isStatic(); /** @@ -77,11 +82,13 @@ public interface CtFieldReference extends CtVariableReference { /** * Forces a reference to a final element. */ + @PropertySetter(role = CtRole.IS_FINAL) > C setFinal(boolean b); /** * Forces a reference to a static element. */ + @PropertySetter(role = CtRole.IS_STATIC) > C setStatic(boolean b); @Override diff --git a/src/main/java/spoon/reflect/reference/CtIntersectionTypeReference.java b/src/main/java/spoon/reflect/reference/CtIntersectionTypeReference.java index 096f68114c0..438e3a5497d 100644 --- a/src/main/java/spoon/reflect/reference/CtIntersectionTypeReference.java +++ b/src/main/java/spoon/reflect/reference/CtIntersectionTypeReference.java @@ -16,10 +16,13 @@ */ package spoon.reflect.reference; +import spoon.reflect.annotations.PropertyGetter; +import spoon.reflect.annotations.PropertySetter; import spoon.support.UnsettableProperty; import java.util.List; +import static spoon.reflect.path.CtRole.BOUND; /** * This interface defines a reference to an intersection type in generics or in casts. @@ -31,21 +34,25 @@ public interface CtIntersectionTypeReference extends CtTypeReference { * T extends Interface1 & Interface2 // CtTypeParameterReference#getBoundingType == Interface1 and getBounds().get(0) == Interface1 * */ + @PropertyGetter(role = BOUND) List> getBounds(); /** * Sets the bounds of the intersection type. */ + @PropertySetter(role = BOUND) C setBounds(List> bounds); /** * Adds a bound. */ + @PropertySetter(role = BOUND) C addBound(CtTypeReference bound); /** * Removes a bound. */ + @PropertySetter(role = BOUND) boolean removeBound(CtTypeReference bound); @Override diff --git a/src/main/java/spoon/reflect/reference/CtTypeParameterReference.java b/src/main/java/spoon/reflect/reference/CtTypeParameterReference.java index 219d02437ca..a4558a80826 100644 --- a/src/main/java/spoon/reflect/reference/CtTypeParameterReference.java +++ b/src/main/java/spoon/reflect/reference/CtTypeParameterReference.java @@ -16,7 +16,10 @@ */ package spoon.reflect.reference; +import spoon.reflect.annotations.PropertyGetter; +import spoon.reflect.annotations.PropertySetter; import spoon.reflect.declaration.CtTypeParameter; +import spoon.reflect.path.CtRole; import spoon.support.DerivedProperty; import spoon.support.UnsettableProperty; @@ -32,6 +35,7 @@ public interface CtTypeParameterReference extends CtTypeReference { * Returns {@code true} if the bounds are in extends clause. * {@code false} means a super clause. */ + @PropertyGetter(role = CtRole.IS_UPPER) boolean isUpper(); /** @@ -44,6 +48,7 @@ public interface CtTypeParameterReference extends CtTypeReference { /** * Set to {@code true} to write extends clause for bounds types. */ + @PropertySetter(role = CtRole.IS_UPPER) T setUpper(boolean upper); /** diff --git a/src/main/java/spoon/reflect/reference/CtTypeReference.java b/src/main/java/spoon/reflect/reference/CtTypeReference.java index fede9a8edc8..0616cbd4bdb 100644 --- a/src/main/java/spoon/reflect/reference/CtTypeReference.java +++ b/src/main/java/spoon/reflect/reference/CtTypeReference.java @@ -16,6 +16,8 @@ */ package spoon.reflect.reference; +import spoon.reflect.annotations.PropertyGetter; +import spoon.reflect.annotations.PropertySetter; import spoon.reflect.declaration.CtShadowable; import spoon.reflect.declaration.CtType; import spoon.reflect.declaration.CtTypeInformation; @@ -25,6 +27,7 @@ import java.util.Set; +import static spoon.reflect.path.CtRole.PACKAGE_REF; /** * This interface defines a reference to a @@ -96,6 +99,7 @@ public interface CtTypeReference extends CtReference, CtActualTypeContainer, * * @return the declaring package or null if this if a inner class */ + @PropertyGetter(role = PACKAGE_REF) CtPackageReference getPackage(); /** @@ -119,6 +123,7 @@ public interface CtTypeReference extends CtReference, CtActualTypeContainer, /** * Sets the reference to the declaring package. */ + @PropertySetter(role = PACKAGE_REF) > C setPackage(CtPackageReference pack); /** diff --git a/src/main/java/spoon/support/reflect/declaration/CtElementImpl.java b/src/main/java/spoon/support/reflect/declaration/CtElementImpl.java index d8729778c56..bb56d2623b5 100644 --- a/src/main/java/spoon/support/reflect/declaration/CtElementImpl.java +++ b/src/main/java/spoon/support/reflect/declaration/CtElementImpl.java @@ -60,6 +60,7 @@ import static spoon.reflect.path.CtRole.ANNOTATION; import static spoon.reflect.path.CtRole.COMMENT; import static spoon.reflect.path.CtRole.IS_IMPLICIT; +import static spoon.reflect.path.CtRole.POSITION; /** * Contains the default implementation of most CtElement methods. @@ -219,6 +220,7 @@ public E setDocComment(String docComment) { } public E setPosition(SourcePosition position) { + getFactory().Change().onObjectUpdate(this, POSITION, position, this.position); this.position = position; return (E) this; } From f2b7b061db285057031d63acdafadb95d5bb97f8 Mon Sep 17 00:00:00 2001 From: tdurieux Date: Fri, 23 Jun 2017 13:57:23 +0200 Subject: [PATCH 10/40] use spoon api instead of collection api --- .../java/spoon/support/compiler/SnippetCompilationHelper.java | 4 ++-- src/main/java/spoon/support/compiler/jdt/ParentExiter.java | 4 ++-- src/main/java/spoon/template/Substitution.java | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/spoon/support/compiler/SnippetCompilationHelper.java b/src/main/java/spoon/support/compiler/SnippetCompilationHelper.java index 6cf175613be..468af8a3d05 100644 --- a/src/main/java/spoon/support/compiler/SnippetCompilationHelper.java +++ b/src/main/java/spoon/support/compiler/SnippetCompilationHelper.java @@ -90,7 +90,7 @@ private static CtStatement internalCompileStatement(CtElement st, CtTypeReferenc CtStatement ret = statements.get(statements.size() - 1); // Clean up - c.getPackage().getTypes().remove(c); + c.getPackage().removeType(c); if (ret instanceof CtClass) { CtClass klass = (CtClass) ret; @@ -147,7 +147,7 @@ private static String createWrapperContent(final CtElement element, final Factor String contents = w.toString(); // Clean up (delete wrapper from factory) after it is printed. The DefaultJavaPrettyPrinter needs w in model to be able to print it correctly - w.getPackage().getTypes().remove(w); + w.getPackage().removeType(w); return contents; } diff --git a/src/main/java/spoon/support/compiler/jdt/ParentExiter.java b/src/main/java/spoon/support/compiler/jdt/ParentExiter.java index 2cbf529f66c..4b2703494c8 100644 --- a/src/main/java/spoon/support/compiler/jdt/ParentExiter.java +++ b/src/main/java/spoon/support/compiler/jdt/ParentExiter.java @@ -771,9 +771,9 @@ public > void visitCtExecutableReferenceExpression( public void visitCtPackage(CtPackage ctPackage) { if (child instanceof CtType) { if (ctPackage.getTypes().contains(child)) { - ctPackage.getTypes().remove(child); + ctPackage.removeType((CtType) child); } - ctPackage.getTypes().add((CtType) child); + ctPackage.addType((CtType) child); if (child.getPosition() != null && child.getPosition().getCompilationUnit() != null) { child.getPosition().getCompilationUnit().getDeclaredTypes().add((CtType) child); } diff --git a/src/main/java/spoon/template/Substitution.java b/src/main/java/spoon/template/Substitution.java index 6407de5aca7..97f59c127a3 100644 --- a/src/main/java/spoon/template/Substitution.java +++ b/src/main/java/spoon/template/Substitution.java @@ -438,7 +438,7 @@ public static CtConstructor insertConstructor(CtClass targetClass, Tem if (newConstrutor.getParameters().isEmpty()) { CtConstructor c = targetClass.getConstructor(); if (c != null && c.isImplicit()) { - targetClass.getConstructors().remove(c); + targetClass.removeConstructor((CtConstructor) c); } } targetClass.addConstructor(newConstrutor); From fe2c16d1d89e44ba9ff139000314ba84c2eb1ecd Mon Sep 17 00:00:00 2001 From: tdurieux Date: Fri, 23 Jun 2017 13:59:39 +0200 Subject: [PATCH 11/40] return unmodifiableList is list getter --- .../java/spoon/generating/CloneVisitorGenerator.java | 3 --- .../java/spoon/support/compiler/jdt/JDTTreeBuilder.java | 5 ----- .../spoon/support/reflect/declaration/CtTypeImpl.java | 9 ++++----- .../reference/CtIntersectionTypeReferenceImpl.java | 5 +---- 4 files changed, 5 insertions(+), 17 deletions(-) diff --git a/src/main/java/spoon/generating/CloneVisitorGenerator.java b/src/main/java/spoon/generating/CloneVisitorGenerator.java index a0b50105c18..7a197e47235 100644 --- a/src/main/java/spoon/generating/CloneVisitorGenerator.java +++ b/src/main/java/spoon/generating/CloneVisitorGenerator.java @@ -498,9 +498,6 @@ private boolean isConstantOrStatic(CtField ctField) { return ctField.getModifiers().contains(ModifierKind.FINAL) || ctField.getModifiers().contains(ModifierKind.STATIC); } }.scan(getFactory().Class().get(CtInheritanceScanner.class)); - - Collections.sort(target.getTypeMembers(), new CtLineElementComparator()); - Collections.sort(targetBuilder.getTypeMembers(), new CtLineElementComparator()); } private CtClass createCloneVisitor() { diff --git a/src/main/java/spoon/support/compiler/jdt/JDTTreeBuilder.java b/src/main/java/spoon/support/compiler/jdt/JDTTreeBuilder.java index cb0d1873d91..bc32429890f 100644 --- a/src/main/java/spoon/support/compiler/jdt/JDTTreeBuilder.java +++ b/src/main/java/spoon/support/compiler/jdt/JDTTreeBuilder.java @@ -681,14 +681,12 @@ public void endVisit(TypeParameter typeParameter, ClassScope scope) { @Override public void endVisit(TypeDeclaration localTypeDeclaration, BlockScope scope) { - Collections.sort(((CtType) context.stack.peek().element).getTypeMembers(), new CtLineElementComparator()); context.exit(localTypeDeclaration); } @Override public void endVisit(TypeDeclaration memberTypeDeclaration, ClassScope scope) { while (!context.stack.isEmpty() && context.stack.peek().node == memberTypeDeclaration) { - Collections.sort(((CtType) context.stack.peek().element).getTypeMembers(), new CtLineElementComparator()); context.exit(memberTypeDeclaration); } } @@ -696,9 +694,6 @@ public void endVisit(TypeDeclaration memberTypeDeclaration, ClassScope scope) { @Override public void endVisit(TypeDeclaration typeDeclaration, CompilationUnitScope scope) { while (!context.stack.isEmpty() && context.stack.peek().node == typeDeclaration) { - if (context.stack.peek().element instanceof CtType) { - Collections.sort(((CtType) context.stack.peek().element).getTypeMembers(), new CtLineElementComparator()); - } context.exit(typeDeclaration); } } diff --git a/src/main/java/spoon/support/reflect/declaration/CtTypeImpl.java b/src/main/java/spoon/support/reflect/declaration/CtTypeImpl.java index 4b09a5795f0..5e8e353086c 100644 --- a/src/main/java/spoon/support/reflect/declaration/CtTypeImpl.java +++ b/src/main/java/spoon/support/reflect/declaration/CtTypeImpl.java @@ -49,9 +49,11 @@ import spoon.reflect.visitor.filter.NameFilter; import spoon.reflect.visitor.filter.ReferenceTypeFilter; import spoon.support.UnsettableProperty; +import spoon.support.comparator.CtLineElementComparator; import spoon.support.compiler.SnippetCompilationHelper; import spoon.support.util.QualifiedNameBasedSortedSet; import spoon.support.util.SignatureBasedSortedSet; +import spoon.support.util.SortedList; import spoon.support.visitor.ClassTypingContext; import java.lang.annotation.Annotation; @@ -99,10 +101,7 @@ public CtTypeImpl() { @Override public List getTypeMembers() { - if (getFactory().getEnvironment().buildStackChanges()) { - return Collections.unmodifiableList(typeMembers); - } - return typeMembers; + return Collections.unmodifiableList(typeMembers); } @Override @@ -119,7 +118,7 @@ public > C addTypeMemberAt(int position, CtTypeMember member return (C) this; } if (this.typeMembers == CtElementImpl.emptyList()) { - this.typeMembers = new ArrayList<>(); + this.typeMembers = new SortedList<>(new CtLineElementComparator()); } if (!this.typeMembers.contains(member)) { member.setParent(this); diff --git a/src/main/java/spoon/support/reflect/reference/CtIntersectionTypeReferenceImpl.java b/src/main/java/spoon/support/reflect/reference/CtIntersectionTypeReferenceImpl.java index 4ffee4df7ca..1ef9c1adccd 100644 --- a/src/main/java/spoon/support/reflect/reference/CtIntersectionTypeReferenceImpl.java +++ b/src/main/java/spoon/support/reflect/reference/CtIntersectionTypeReferenceImpl.java @@ -38,10 +38,7 @@ public void accept(CtVisitor visitor) { @Override public List> getBounds() { - if (getFactory().getEnvironment().buildStackChanges()) { - return Collections.unmodifiableList(bounds); - } - return bounds; + return Collections.unmodifiableList(bounds); } @Override From f657f6001b3fc7d06265a35d1b20cb2887c074a5 Mon Sep 17 00:00:00 2001 From: tdurieux Date: Fri, 23 Jun 2017 14:03:30 +0200 Subject: [PATCH 12/40] fix change factory --- .../java/spoon/reflect/factory/ChangeFactory.java | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/main/java/spoon/reflect/factory/ChangeFactory.java b/src/main/java/spoon/reflect/factory/ChangeFactory.java index bb854a1f096..a257ee45401 100644 --- a/src/main/java/spoon/reflect/factory/ChangeFactory.java +++ b/src/main/java/spoon/reflect/factory/ChangeFactory.java @@ -94,10 +94,8 @@ public void onListAdd(CtElement currentElement, CtRole role, List field, int ind public void onListDelete(CtElement currentElement, CtRole role, List field, Collection oldValue) { - if (factory.getEnvironment().buildStackChanges()) { - for (CtElement ctElement : oldValue) { - onListDelete(currentElement, role, field, field.indexOf(ctElement), ctElement); - } + for (CtElement ctElement : oldValue) { + onListDelete(currentElement, role, field, field.indexOf(ctElement), ctElement); } } @@ -140,10 +138,8 @@ public void onSetDelete(CtElement currentElement, CtRole role, Set field, CtElem } public void onSetDelete(CtElement currentElement, CtRole role, Set field, Collection oldValue) { - if (factory.getEnvironment().buildStackChanges()) { - for (ModifierKind modifierKind : oldValue) { - onSetDelete(currentElement, role, field, modifierKind); - } + for (ModifierKind modifierKind : oldValue) { + onSetDelete(currentElement, role, field, modifierKind); } } From c07fc0fa5f31684893849d25bff31e956da8b15d Mon Sep 17 00:00:00 2001 From: tdurieux Date: Fri, 23 Jun 2017 14:03:50 +0200 Subject: [PATCH 13/40] fix import test --- src/test/java/spoon/test/imports/ImportTest.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/test/java/spoon/test/imports/ImportTest.java b/src/test/java/spoon/test/imports/ImportTest.java index 8ede55aae61..a77abf3a36c 100644 --- a/src/test/java/spoon/test/imports/ImportTest.java +++ b/src/test/java/spoon/test/imports/ImportTest.java @@ -185,10 +185,9 @@ public void testNewInnerClassDefinesInItsClassAndSuperClass() throws Exception { final CtConstructorCall ctConstructorCall = subClass.getElements(new TypeFilter>(CtConstructorCall.class)).get(0); assertEquals("new spoon.test.imports.testclasses.SubClass.Item(\"\")", ctConstructorCall.toString()); - final String expected = "public class SubClass extends spoon.test.imports.testclasses.SuperClass {" + System.lineSeparator() + " public void aMethod() {" + System.lineSeparator() - + " new spoon.test.imports.testclasses.SubClass.Item(\"\");" + System.lineSeparator() + " }" + System.lineSeparator() + System.lineSeparator() - + " public static class Item extends spoon.test.imports.testclasses.SuperClass.Item {" + System.lineSeparator() + " public Item(java.lang.String s) {" + System - .lineSeparator() + " super(1, s);" + System.lineSeparator() + " }" + System.lineSeparator() + " }" + System.lineSeparator() + "}"; + final String expected = "public class SubClass extends spoon.test.imports.testclasses.SuperClass {" + System.lineSeparator() + " public static class Item extends spoon.test.imports.testclasses.SuperClass.Item {" + System.lineSeparator() + " public Item(java.lang.String s) {" + System + .lineSeparator() + " super(1, s);" + System.lineSeparator() + " }" + System.lineSeparator() + " }" + System.lineSeparator() + System.lineSeparator() + " public void aMethod() {" + System.lineSeparator() + + " new spoon.test.imports.testclasses.SubClass.Item(\"\");" + System.lineSeparator() + " }" + System.lineSeparator() + "}"; assertEquals(expected, subClass.toString()); } From 8a5f87f4d0f4abbe3557bb1f02ba29a168a90429 Mon Sep 17 00:00:00 2001 From: tdurieux Date: Fri, 23 Jun 2017 14:05:16 +0200 Subject: [PATCH 14/40] fix test model change listener --- .../spoon/reflect/ast/AstCheckerTest.java | 105 ++++++++++-------- 1 file changed, 56 insertions(+), 49 deletions(-) diff --git a/src/test/java/spoon/reflect/ast/AstCheckerTest.java b/src/test/java/spoon/reflect/ast/AstCheckerTest.java index c45ff4b7f9e..6914be413ba 100644 --- a/src/test/java/spoon/reflect/ast/AstCheckerTest.java +++ b/src/test/java/spoon/reflect/ast/AstCheckerTest.java @@ -2,17 +2,13 @@ import org.junit.Test; import spoon.Launcher; -import spoon.diff.Action; import spoon.reflect.code.CtBlock; -import spoon.reflect.code.CtExpression; -import spoon.reflect.code.CtFieldRead; import spoon.reflect.code.CtIf; import spoon.reflect.code.CtInvocation; import spoon.reflect.code.CtReturn; -import spoon.reflect.code.CtStatement; import spoon.reflect.code.CtThrow; +import spoon.reflect.declaration.CtExecutable; import spoon.reflect.declaration.CtMethod; -import spoon.reflect.declaration.CtType; import spoon.reflect.declaration.ModifierKind; import spoon.reflect.factory.Factory; import spoon.reflect.reference.CtTypeReference; @@ -22,8 +18,6 @@ import spoon.support.DerivedProperty; import spoon.support.UnsettableProperty; import spoon.support.comparator.CtLineElementComparator; -import spoon.template.TemplateMatcher; -import spoon.template.TemplateParameter; import java.io.File; import java.util.Arrays; @@ -77,30 +71,36 @@ public void testAvoidSetCollectionSavedOnAST() throws Exception { final List> invocations = Query.getElements(factory, new TypeFilter>(CtInvocation.class) { @Override public boolean matches(CtInvocation element) { - if (!element.getExecutable().getSimpleName().startsWith("get")) { + if (!(element.getParent() instanceof CtInvocation)) { return false; } - if (!collectionsRef.contains(element.getType())) { + final CtInvocation parent = (CtInvocation) element.getParent(); + if (parent.getTarget() == null || !parent.getTarget().equals(element)) { return false; } if (!element.getExecutable().getDeclaringType().getSimpleName().startsWith("Ct")) { return false; } - if (!(element.getParent() instanceof CtInvocation)) { - return false; + boolean isDataStructure = false; + for (int i = 0; i < collectionsRef.size(); i++) { + CtTypeReference ctTypeReference = collectionsRef.get(i); + if (element.getType().isSubtypeOf(ctTypeReference)) { + isDataStructure = true; + break; + } } - final CtInvocation parent = (CtInvocation) element.getParent(); - if (!parent.getTarget().equals(element)) { + if (!isDataStructure) { return false; } + final String simpleName = parent.getExecutable().getSimpleName(); - return simpleName.startsWith("add") || simpleName.startsWith("remove"); + return simpleName.startsWith("add") || simpleName.startsWith("remove") || simpleName.startsWith("put"); } }); if (invocations.size() > 0) { final String error = invocations.stream() // .sorted(new CtLineElementComparator()) // - .map(i -> "see " + i.getPosition().getFile().getName() + " at " + i.getPosition().getLine()) // + .map(i -> "see " + i.getPosition().getFile().getAbsoluteFile() + " at " + i.getPosition().getLine()) // .collect(Collectors.joining(",\n")); throw new AssertionError(error); } @@ -110,7 +110,6 @@ public boolean matches(CtInvocation element) { public void testPushToStackChanges() throws Exception { final Launcher launcher = new Launcher(); launcher.getEnvironment().setNoClasspath(true); - launcher.getEnvironment().setBuildStackChanges(true); // Implementations. launcher.addInputResource("./src/main/java/spoon/support/reflect/code"); launcher.addInputResource("./src/main/java/spoon/support/reflect/declaration"); @@ -120,7 +119,7 @@ public void testPushToStackChanges() throws Exception { launcher.addInputResource("./src/test/java/spoon/reflect/ast/AstCheckerTest.java"); launcher.buildModel(); - final PushStackInIntercessionChecker checker = new PushStackInIntercessionChecker(launcher.getFactory()); + final PushStackInIntercessionChecker checker = new PushStackInIntercessionChecker(); checker.scan(launcher.getModel().getRootPackage()); if (!checker.result.isEmpty()) { System.err.println(checker.count); @@ -129,39 +128,21 @@ public void testPushToStackChanges() throws Exception { } private class PushStackInIntercessionChecker extends CtScanner { - private final CtInvocation template; private final List notCandidates; private String result = ""; private int count; - PushStackInIntercessionChecker(Factory factory) { - final CtType templateClass = factory.Type().get(Template.class); - template = templateClass.getMethod("templatePush").getBody().getStatement(0); + PushStackInIntercessionChecker() { notCandidates = Arrays.asList( // - "CtTypeImpl#addTypeMember", // - "CtTypeImpl#removeTypeMember", // - "CtTypeImpl#addFieldAtTop", // - "CtTypeImpl#addField", // - "CtTypeImpl#removeField", // - "CtTypeImpl#addBound", // - "CtTypeImpl#addNestedType", // - "CtTypeImpl#removeNestedType", // - "CtTypeImpl#addMethod", // - "CtTypeImpl#removeMethod", // - "CtBlockImpl#removeStatement", // - "CtAnnotationTypeImpl#addMethod", // - "CtClassImpl#removeConstructor", // - "CtConstructorCallImpl#addArgument", // - "CtInvocationImpl#addArgument", // - "CtTypeParameterReferenceImpl#addBound", // - "CtTypeParameterReferenceImpl#removeBound", // - "CtTypeParameterReferenceImpl#setBounds", // + "CtTypeImpl#setTypeMembers", // + "CtStatementListImpl#setPosition", // "CtElementImpl#setFactory", // "CtElementImpl#setPositions", // "CtElementImpl#setDocComment", // - "CtStatementListImpl#setPosition", // - "CtAnnotationImpl#addValue", // - "CtAnnotationTypeImpl#setFields" // + "CtElementImpl#setParent", // + "CtTypeParameterReferenceImpl#addBound", // + "CtTypeParameterReferenceImpl#removeBound", // + "CtTypeParameterReferenceImpl#setBounds" // ); } @@ -178,19 +159,45 @@ private boolean isToBeProcessed(CtMethod candidate) { && (candidate.getSimpleName().startsWith("add") || candidate.getSimpleName().startsWith("set") || candidate.getSimpleName().startsWith("remove")) // && candidate.getDeclaringType().getSimpleName().startsWith("Ct") // && !isNotCandidate(candidate) // + && !isSurcharged(candidate) // && !isDelegateMethod(candidate) // && !isUnsupported(candidate.getBody()) // - && !hasPushToStackInvocation(candidate.getBody()) - && isSettable(candidate); + && !hasPushToStackInvocation(candidate.getBody()); } - private boolean isSettable(CtMethod candidate) { - return candidate.getAnnotation(UnsettableProperty.class) == null; - } private boolean isNotCandidate(CtMethod candidate) { return "setVisibility".equals(candidate.getSimpleName()) || notCandidates.contains(candidate.getDeclaringType().getSimpleName() + "#" + candidate.getSimpleName()); } + private boolean isSurcharged(CtMethod candidate) { + CtBlock block = candidate.getBody(); + if (block.getStatements().size() == 0) { + return false; + } + CtInvocation potentialDelegate; + if (block.getLastStatement() instanceof CtReturn) { + if (!(((CtReturn) block.getLastStatement()).getReturnedExpression() instanceof CtInvocation)) { + if (block.getStatement(0) instanceof CtInvocation) { + potentialDelegate = block.getStatement(0); + } else { + return false; + } + } else { + potentialDelegate = (CtInvocation) ((CtReturn) block.getLastStatement()).getReturnedExpression(); + } + } else if (block.getStatement(0) instanceof CtInvocation && block.getStatements().size() == 1) { + potentialDelegate = block.getStatement(0); + } else { + return false; + } + CtExecutable declaration = potentialDelegate.getExecutable().getDeclaration(); + if (declaration == null || !(declaration instanceof CtMethod)) { + return false; + } + // check if the invocation has a model change listener + return !isToBeProcessed((CtMethod) declaration); + } + private boolean isDelegateMethod(CtMethod candidate) { if (candidate.getBody().getStatements().size() == 0) { return false; @@ -227,9 +234,9 @@ private boolean hasPushToStackInvocation(CtBlock body) { return body.getElements(new TypeFilter>(CtInvocation.class) { @Override public boolean matches(CtInvocation element) { - return element.getExecutable().getSimpleName().equals(template.getExecutable().getSimpleName()) && super.matches(element); + return "ChangeFactory".equals(element.getExecutable().getDeclaringType().getSimpleName()) && super.matches(element); } - }).size() == 1; + }).size() > 0; } private void process(CtMethod element) { From 900ddccc4e5aebcf8baf6805edf329643c4b2f58 Mon Sep 17 00:00:00 2001 From: tdurieux Date: Fri, 23 Jun 2017 14:07:02 +0200 Subject: [PATCH 15/40] remove useless tests --- .../spoon/reflect/ast/AstCheckerTest.java | 87 ------------------- 1 file changed, 87 deletions(-) diff --git a/src/test/java/spoon/reflect/ast/AstCheckerTest.java b/src/test/java/spoon/reflect/ast/AstCheckerTest.java index 6914be413ba..05724370044 100644 --- a/src/test/java/spoon/reflect/ast/AstCheckerTest.java +++ b/src/test/java/spoon/reflect/ast/AstCheckerTest.java @@ -19,7 +19,6 @@ import spoon.support.UnsettableProperty; import spoon.support.comparator.CtLineElementComparator; -import java.io.File; import java.util.Arrays; import java.util.Collection; import java.util.List; @@ -28,36 +27,11 @@ import java.util.stream.Collectors; public class AstCheckerTest { - @Test - public void testStackChanges() throws Exception { - final Launcher launcher = new Launcher(); - launcher.getModelBuilder().setSourceClasspath(System.getProperty("java.class.path").split(File.pathSeparator)); - // interfaces. - launcher.addInputResource("./src/main/java/spoon/reflect/code"); - launcher.addInputResource("./src/main/java/spoon/reflect/declaration"); - launcher.addInputResource("./src/main/java/spoon/reflect/reference"); - launcher.addInputResource("./src/main/java/spoon/reflect/internal"); - // 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.addInputResource("./src/main/java/spoon/support/reflect/internal"); - // Utils. - launcher.addInputResource("./src/test/java/spoon/reflect/ast/AstCheckerTest.java"); - launcher.buildModel(); - - final GetterListChecker getterListChecker = new GetterListChecker(launcher.getFactory()); - getterListChecker.scan(launcher.getModel().getRootPackage()); - if (getterListChecker.result != null) { - throw new AssertionError(getterListChecker.result); - } - } @Test public void testAvoidSetCollectionSavedOnAST() throws Exception { final Launcher launcher = new Launcher(); launcher.getEnvironment().setNoClasspath(true); - launcher.getEnvironment().setBuildStackChanges(true); launcher.addInputResource("src/main/java"); launcher.buildModel(); @@ -252,65 +226,4 @@ public void visitCtMethod(CtMethod m) { super.visitCtMethod(m); } } - - private class GetterListChecker extends CtScanner { - private final List> COLLECTIONS; - private final CtExpression conditionExpected; - private String result; - - GetterListChecker(Factory factory) { - COLLECTIONS = Arrays.asList(factory.Type().createReference(Collection.class), factory.Type().createReference(List.class), factory.Type().createReference(Set.class)); - final CtType templateClass = factory.Type().get(Template.class); - conditionExpected = ((CtIf) templateClass.getMethod("template").getBody().getStatement(0)).getCondition(); - } - - private boolean isToBeProcessed(CtMethod candidate) { - return candidate.getBody() != null // - && candidate.getParameters().size() == 0 // - && candidate.getDeclaringType().getSimpleName().startsWith("Ct") // - && COLLECTIONS.contains(candidate.getType()) // - && isConditionExpected(candidate.getBody().getStatement(0)) // - && isReturnCollection(candidate.getBody().getLastStatement()); - } - - private boolean isConditionExpected(CtStatement statement) { - final TemplateMatcher matcher = new TemplateMatcher(conditionExpected); - return matcher.find(statement).size() == 0; - } - - private boolean isReturnCollection(CtStatement statement) { - return statement instanceof CtReturn // - && ((CtReturn) statement).getReturnedExpression() instanceof CtFieldRead // - && COLLECTIONS.contains(((CtFieldRead) ((CtReturn) statement).getReturnedExpression()).getVariable().getType()); - } - - private void process(CtMethod element) { - result += element.getSignature() + " on " + element.getDeclaringType().getQualifiedName() + "\n"; - } - - @Override - public void visitCtMethod(CtMethod m) { - if (isToBeProcessed(m)) { - process(m); - } - super.visitCtMethod(m); - } - } - - class Template { - TemplateParameter _action_; - - public void template() { - if (getFactory().getEnvironment().buildStackChanges()) { - } - } - - public void templatePush() { - getFactory().getEnvironment().pushToStack(_action_.S()); - } - - public Factory getFactory() { - return null; - } - } } From 5866f9530a34f045c9f2a9fd657664c087964c29 Mon Sep 17 00:00:00 2001 From: tdurieux Date: Fri, 23 Jun 2017 14:59:26 +0200 Subject: [PATCH 16/40] fix checkstyle --- src/main/java/spoon/compiler/Environment.java | 3 --- src/main/java/spoon/diff/context/MapContext.java | 4 ++-- .../spoon/generating/CloneVisitorGenerator.java | 15 +++++++-------- .../spoon/reflect/code/CtAbstractInvocation.java | 2 -- .../java/spoon/reflect/factory/ChangeFactory.java | 6 +++--- .../support/compiler/jdt/JDTBatchCompiler.java | 2 +- .../support/compiler/jdt/JDTTreeBuilder.java | 3 --- .../support/reflect/code/CtStatementListImpl.java | 2 +- 8 files changed, 14 insertions(+), 23 deletions(-) diff --git a/src/main/java/spoon/compiler/Environment.java b/src/main/java/spoon/compiler/Environment.java index 1c8c3187e51..e89a68b975a 100644 --- a/src/main/java/spoon/compiler/Environment.java +++ b/src/main/java/spoon/compiler/Environment.java @@ -17,7 +17,6 @@ package spoon.compiler; import org.apache.log4j.Level; -import spoon.diff.Action; import spoon.processing.FileGenerator; import spoon.processing.ProblemFixer; import spoon.processing.ProcessingManager; @@ -27,8 +26,6 @@ import spoon.reflect.declaration.CtMethod; import spoon.reflect.factory.Factory; -import java.util.Deque; - /** * This interface represents the environment in which Spoon is launched - * accessible through {@link spoon.reflect.factory.Factory#getEnvironment()}. Its diff --git a/src/main/java/spoon/diff/context/MapContext.java b/src/main/java/spoon/diff/context/MapContext.java index 289984129cd..5f428a81faf 100644 --- a/src/main/java/spoon/diff/context/MapContext.java +++ b/src/main/java/spoon/diff/context/MapContext.java @@ -21,7 +21,7 @@ import java.util.Map; -public class MapContext extends Context { +public class MapContext extends Context { private final Map map; private K key; @@ -42,4 +42,4 @@ public K getKey() { public Map getMap() { return map; } -} \ No newline at end of file +} diff --git a/src/main/java/spoon/generating/CloneVisitorGenerator.java b/src/main/java/spoon/generating/CloneVisitorGenerator.java index 7a197e47235..152fa542175 100644 --- a/src/main/java/spoon/generating/CloneVisitorGenerator.java +++ b/src/main/java/spoon/generating/CloneVisitorGenerator.java @@ -16,13 +16,6 @@ */ package spoon.generating; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.Set; - import spoon.SpoonException; import spoon.processing.AbstractManualProcessor; import spoon.reflect.code.BinaryOperatorKind; @@ -58,9 +51,15 @@ import spoon.reflect.visitor.Query; import spoon.reflect.visitor.filter.OverridingMethodFilter; import spoon.reflect.visitor.filter.TypeFilter; -import spoon.support.comparator.CtLineElementComparator; import spoon.support.visitor.clone.CloneBuilder; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Set; + public class CloneVisitorGenerator extends AbstractManualProcessor { private static final String TARGET_CLONE_PACKAGE = "spoon.support.visitor.clone"; private static final String TARGET_CLONE_TYPE = "CloneVisitor"; diff --git a/src/main/java/spoon/reflect/code/CtAbstractInvocation.java b/src/main/java/spoon/reflect/code/CtAbstractInvocation.java index 1a92e6719c0..fd8936fcb35 100644 --- a/src/main/java/spoon/reflect/code/CtAbstractInvocation.java +++ b/src/main/java/spoon/reflect/code/CtAbstractInvocation.java @@ -26,8 +26,6 @@ import static spoon.reflect.path.CtRole.ARGUMENT; import static spoon.reflect.path.CtRole.EXECUTABLE; -import java.util.List; - /** * This code element defines an abstract invocation on a * {@link spoon.reflect.declaration.CtExecutable}. diff --git a/src/main/java/spoon/reflect/factory/ChangeFactory.java b/src/main/java/spoon/reflect/factory/ChangeFactory.java index a257ee45401..cfa7a05e3d5 100644 --- a/src/main/java/spoon/reflect/factory/ChangeFactory.java +++ b/src/main/java/spoon/reflect/factory/ChangeFactory.java @@ -83,7 +83,7 @@ public void onObjectDelete(CtElement currentElement, CtRole role, CtElement oldV } public void onListAdd(CtElement currentElement, CtRole role, List field, CtElement newValue) { - AddAction action = new AddAction<>(new ListContext(currentElement, role,field), newValue); + AddAction action = new AddAction<>(new ListContext(currentElement, role, field), newValue); propagateModelChange(action); } @@ -111,12 +111,12 @@ public void onListDeleteAll(CtElement currentElement, CtRole role, List field, L } - public void onMapAdd(CtElement currentElement, CtRole role, Map field, K key, CtElement newValue) { + public void onMapAdd(CtElement currentElement, CtRole role, Map field, K key, CtElement newValue) { AddAction action = new AddAction<>(new MapContext<>(currentElement, role, field, key), newValue); propagateModelChange(action); } - public void onMapDeleteAll(CtElement currentElement, CtRole role, Map field, Map oldValue) { + public void onMapDeleteAll(CtElement currentElement, CtRole role, Map field, Map oldValue) { DeleteAllAction action = new DeleteAllAction(new MapContext<>(currentElement, role, field), oldValue); propagateModelChange(action); } diff --git a/src/main/java/spoon/support/compiler/jdt/JDTBatchCompiler.java b/src/main/java/spoon/support/compiler/jdt/JDTBatchCompiler.java index ca62f475fd2..5e5dee9fbec 100644 --- a/src/main/java/spoon/support/compiler/jdt/JDTBatchCompiler.java +++ b/src/main/java/spoon/support/compiler/jdt/JDTBatchCompiler.java @@ -109,7 +109,7 @@ public CompilationUnitDeclaration[] getUnits() { CompilerOptions compilerOptions = new CompilerOptions(this.options); compilerOptions.parseLiteralExpressionsAsConstants = false; TreeBuilderCompiler treeBuilderCompiler = new TreeBuilderCompiler( - environment, getHandlingPolicy(), compilerOptions, + environment, DefaultErrorHandlingPolicies.ignoreAllProblems(), compilerOptions, this.jdtCompiler.requestor, getProblemFactory(), this.out, null); if (jdtCompiler.getEnvironment().getNoClasspath()) { diff --git a/src/main/java/spoon/support/compiler/jdt/JDTTreeBuilder.java b/src/main/java/spoon/support/compiler/jdt/JDTTreeBuilder.java index bc32429890f..051ffa6e4d1 100644 --- a/src/main/java/spoon/support/compiler/jdt/JDTTreeBuilder.java +++ b/src/main/java/spoon/support/compiler/jdt/JDTTreeBuilder.java @@ -21,8 +21,6 @@ import static spoon.support.compiler.jdt.JDTTreeBuilderQuery.getUnaryOperator; import static spoon.support.compiler.jdt.JDTTreeBuilderQuery.isLhsAssignment; -import java.util.Collections; - import org.apache.log4j.Logger; import org.eclipse.jdt.core.compiler.CharOperation; import org.eclipse.jdt.internal.compiler.ASTVisitor; @@ -156,7 +154,6 @@ import spoon.reflect.reference.CtReference; import spoon.reflect.reference.CtTypeReference; import spoon.reflect.reference.CtUnboundVariableReference; -import spoon.support.comparator.CtLineElementComparator; /** * A visitor for iterating through the parse tree. diff --git a/src/main/java/spoon/support/reflect/code/CtStatementListImpl.java b/src/main/java/spoon/support/reflect/code/CtStatementListImpl.java index 948579a52be..ba6ee23990e 100644 --- a/src/main/java/spoon/support/reflect/code/CtStatementListImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtStatementListImpl.java @@ -80,7 +80,7 @@ public T addStatement(CtStatement statement) { @Override public void removeStatement(CtStatement statement) { if (this.statements == CtElementImpl.emptyList()) { - return ; + return; } getFactory().Change().onListDelete(this, STATEMENT, statements, statements.indexOf(statement), statement); statements.remove(statement); From 446bc8258b7caf15574291b6c14685472895d6af Mon Sep 17 00:00:00 2001 From: tdurieux Date: Fri, 23 Jun 2017 15:10:54 +0200 Subject: [PATCH 17/40] move Actions --- .../AbstractModelChangeListener.java | 2 +- .../modelobs}/Action.java | 4 ++-- .../modelobs}/AddAction.java | 4 ++-- .../modelobs}/DeleteAction.java | 4 ++-- .../modelobs}/DeleteAllAction.java | 4 ++-- .../modelobs}/ModelChangeListener.java | 2 +- .../modelobs}/UpdateAction.java | 4 ++-- .../modelobs}/context/CollectionContext.java | 2 +- .../modelobs}/context/Context.java | 2 +- .../modelobs}/context/ListContext.java | 2 +- .../modelobs}/context/MapContext.java | 2 +- .../modelobs}/context/ObjectContext.java | 2 +- .../modelobs}/context/SetContext.java | 2 +- .../spoon/reflect/factory/ChangeFactory.java | 20 +++++++++---------- 14 files changed, 28 insertions(+), 28 deletions(-) rename src/main/java/spoon/{diff => experimental/modelobs}/AbstractModelChangeListener.java (97%) rename src/main/java/spoon/{diff => experimental/modelobs}/Action.java (91%) rename src/main/java/spoon/{diff => experimental/modelobs}/AddAction.java (92%) rename src/main/java/spoon/{diff => experimental/modelobs}/DeleteAction.java (92%) rename src/main/java/spoon/{diff => experimental/modelobs}/DeleteAllAction.java (92%) rename src/main/java/spoon/{diff => experimental/modelobs}/ModelChangeListener.java (97%) rename src/main/java/spoon/{diff => experimental/modelobs}/UpdateAction.java (93%) rename src/main/java/spoon/{diff => experimental/modelobs}/context/CollectionContext.java (96%) rename src/main/java/spoon/{diff => experimental/modelobs}/context/Context.java (96%) rename src/main/java/spoon/{diff => experimental/modelobs}/context/ListContext.java (96%) rename src/main/java/spoon/{diff => experimental/modelobs}/context/MapContext.java (96%) rename src/main/java/spoon/{diff => experimental/modelobs}/context/ObjectContext.java (95%) rename src/main/java/spoon/{diff => experimental/modelobs}/context/SetContext.java (95%) diff --git a/src/main/java/spoon/diff/AbstractModelChangeListener.java b/src/main/java/spoon/experimental/modelobs/AbstractModelChangeListener.java similarity index 97% rename from src/main/java/spoon/diff/AbstractModelChangeListener.java rename to src/main/java/spoon/experimental/modelobs/AbstractModelChangeListener.java index 7b59bae7711..656cd74654a 100644 --- a/src/main/java/spoon/diff/AbstractModelChangeListener.java +++ b/src/main/java/spoon/experimental/modelobs/AbstractModelChangeListener.java @@ -14,7 +14,7 @@ * 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.diff; +package spoon.experimental.modelobs; /** * notifies all change on the AST diff --git a/src/main/java/spoon/diff/Action.java b/src/main/java/spoon/experimental/modelobs/Action.java similarity index 91% rename from src/main/java/spoon/diff/Action.java rename to src/main/java/spoon/experimental/modelobs/Action.java index 5b12768ebac..a0fff8cc9f7 100644 --- a/src/main/java/spoon/diff/Action.java +++ b/src/main/java/spoon/experimental/modelobs/Action.java @@ -14,9 +14,9 @@ * 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.diff; +package spoon.experimental.modelobs; -import spoon.diff.context.Context; +import spoon.experimental.modelobs.context.Context; public abstract class Action { private final Context context; diff --git a/src/main/java/spoon/diff/AddAction.java b/src/main/java/spoon/experimental/modelobs/AddAction.java similarity index 92% rename from src/main/java/spoon/diff/AddAction.java rename to src/main/java/spoon/experimental/modelobs/AddAction.java index 672f39dba42..1bbbe2c45f8 100644 --- a/src/main/java/spoon/diff/AddAction.java +++ b/src/main/java/spoon/experimental/modelobs/AddAction.java @@ -14,9 +14,9 @@ * 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.diff; +package spoon.experimental.modelobs; -import spoon.diff.context.Context; +import spoon.experimental.modelobs.context.Context; public class AddAction extends Action { private T newElement; diff --git a/src/main/java/spoon/diff/DeleteAction.java b/src/main/java/spoon/experimental/modelobs/DeleteAction.java similarity index 92% rename from src/main/java/spoon/diff/DeleteAction.java rename to src/main/java/spoon/experimental/modelobs/DeleteAction.java index 38319514c47..77d07f4fb57 100644 --- a/src/main/java/spoon/diff/DeleteAction.java +++ b/src/main/java/spoon/experimental/modelobs/DeleteAction.java @@ -14,9 +14,9 @@ * 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.diff; +package spoon.experimental.modelobs; -import spoon.diff.context.Context; +import spoon.experimental.modelobs.context.Context; public class DeleteAction extends Action { private T oldElement; diff --git a/src/main/java/spoon/diff/DeleteAllAction.java b/src/main/java/spoon/experimental/modelobs/DeleteAllAction.java similarity index 92% rename from src/main/java/spoon/diff/DeleteAllAction.java rename to src/main/java/spoon/experimental/modelobs/DeleteAllAction.java index c92174d0190..e21468a155f 100644 --- a/src/main/java/spoon/diff/DeleteAllAction.java +++ b/src/main/java/spoon/experimental/modelobs/DeleteAllAction.java @@ -14,9 +14,9 @@ * 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.diff; +package spoon.experimental.modelobs; -import spoon.diff.context.Context; +import spoon.experimental.modelobs.context.Context; import java.util.Collection; import java.util.Map; diff --git a/src/main/java/spoon/diff/ModelChangeListener.java b/src/main/java/spoon/experimental/modelobs/ModelChangeListener.java similarity index 97% rename from src/main/java/spoon/diff/ModelChangeListener.java rename to src/main/java/spoon/experimental/modelobs/ModelChangeListener.java index a5211f33206..ab352eb397d 100644 --- a/src/main/java/spoon/diff/ModelChangeListener.java +++ b/src/main/java/spoon/experimental/modelobs/ModelChangeListener.java @@ -14,7 +14,7 @@ * 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.diff; +package spoon.experimental.modelobs; /** * notifies all change on the AST diff --git a/src/main/java/spoon/diff/UpdateAction.java b/src/main/java/spoon/experimental/modelobs/UpdateAction.java similarity index 93% rename from src/main/java/spoon/diff/UpdateAction.java rename to src/main/java/spoon/experimental/modelobs/UpdateAction.java index 17033120f46..ed4515a5275 100644 --- a/src/main/java/spoon/diff/UpdateAction.java +++ b/src/main/java/spoon/experimental/modelobs/UpdateAction.java @@ -14,9 +14,9 @@ * 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.diff; +package spoon.experimental.modelobs; -import spoon.diff.context.Context; +import spoon.experimental.modelobs.context.Context; public class UpdateAction extends Action { private final T oldElement; diff --git a/src/main/java/spoon/diff/context/CollectionContext.java b/src/main/java/spoon/experimental/modelobs/context/CollectionContext.java similarity index 96% rename from src/main/java/spoon/diff/context/CollectionContext.java rename to src/main/java/spoon/experimental/modelobs/context/CollectionContext.java index 2800f287d70..a70b24bc76c 100644 --- a/src/main/java/spoon/diff/context/CollectionContext.java +++ b/src/main/java/spoon/experimental/modelobs/context/CollectionContext.java @@ -14,7 +14,7 @@ * 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.diff.context; +package spoon.experimental.modelobs.context; import spoon.reflect.declaration.CtElement; import spoon.reflect.path.CtRole; diff --git a/src/main/java/spoon/diff/context/Context.java b/src/main/java/spoon/experimental/modelobs/context/Context.java similarity index 96% rename from src/main/java/spoon/diff/context/Context.java rename to src/main/java/spoon/experimental/modelobs/context/Context.java index ad625ba6d1a..fbb1d6a1770 100644 --- a/src/main/java/spoon/diff/context/Context.java +++ b/src/main/java/spoon/experimental/modelobs/context/Context.java @@ -14,7 +14,7 @@ * 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.diff.context; +package spoon.experimental.modelobs.context; import spoon.reflect.declaration.CtElement; import spoon.reflect.path.CtRole; diff --git a/src/main/java/spoon/diff/context/ListContext.java b/src/main/java/spoon/experimental/modelobs/context/ListContext.java similarity index 96% rename from src/main/java/spoon/diff/context/ListContext.java rename to src/main/java/spoon/experimental/modelobs/context/ListContext.java index 66e8c7674b7..3ce9cb89aaf 100644 --- a/src/main/java/spoon/diff/context/ListContext.java +++ b/src/main/java/spoon/experimental/modelobs/context/ListContext.java @@ -14,7 +14,7 @@ * 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.diff.context; +package spoon.experimental.modelobs.context; import spoon.reflect.declaration.CtElement; import spoon.reflect.path.CtRole; diff --git a/src/main/java/spoon/diff/context/MapContext.java b/src/main/java/spoon/experimental/modelobs/context/MapContext.java similarity index 96% rename from src/main/java/spoon/diff/context/MapContext.java rename to src/main/java/spoon/experimental/modelobs/context/MapContext.java index 5f428a81faf..12cc56ad316 100644 --- a/src/main/java/spoon/diff/context/MapContext.java +++ b/src/main/java/spoon/experimental/modelobs/context/MapContext.java @@ -14,7 +14,7 @@ * 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.diff.context; +package spoon.experimental.modelobs.context; import spoon.reflect.declaration.CtElement; import spoon.reflect.path.CtRole; diff --git a/src/main/java/spoon/diff/context/ObjectContext.java b/src/main/java/spoon/experimental/modelobs/context/ObjectContext.java similarity index 95% rename from src/main/java/spoon/diff/context/ObjectContext.java rename to src/main/java/spoon/experimental/modelobs/context/ObjectContext.java index 0b08d95c101..3ae75f56ef6 100644 --- a/src/main/java/spoon/diff/context/ObjectContext.java +++ b/src/main/java/spoon/experimental/modelobs/context/ObjectContext.java @@ -14,7 +14,7 @@ * 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.diff.context; +package spoon.experimental.modelobs.context; import spoon.reflect.declaration.CtElement; import spoon.reflect.path.CtRole; diff --git a/src/main/java/spoon/diff/context/SetContext.java b/src/main/java/spoon/experimental/modelobs/context/SetContext.java similarity index 95% rename from src/main/java/spoon/diff/context/SetContext.java rename to src/main/java/spoon/experimental/modelobs/context/SetContext.java index 488e2d04304..a4e70fd23d4 100644 --- a/src/main/java/spoon/diff/context/SetContext.java +++ b/src/main/java/spoon/experimental/modelobs/context/SetContext.java @@ -14,7 +14,7 @@ * 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.diff.context; +package spoon.experimental.modelobs.context; import spoon.reflect.declaration.CtElement; import spoon.reflect.path.CtRole; diff --git a/src/main/java/spoon/reflect/factory/ChangeFactory.java b/src/main/java/spoon/reflect/factory/ChangeFactory.java index cfa7a05e3d5..a0687fa1b8b 100644 --- a/src/main/java/spoon/reflect/factory/ChangeFactory.java +++ b/src/main/java/spoon/reflect/factory/ChangeFactory.java @@ -16,16 +16,16 @@ */ package spoon.reflect.factory; -import spoon.diff.Action; -import spoon.diff.ModelChangeListener; -import spoon.diff.AddAction; -import spoon.diff.DeleteAction; -import spoon.diff.DeleteAllAction; -import spoon.diff.UpdateAction; -import spoon.diff.context.ListContext; -import spoon.diff.context.MapContext; -import spoon.diff.context.ObjectContext; -import spoon.diff.context.SetContext; +import spoon.experimental.modelobs.Action; +import spoon.experimental.modelobs.ModelChangeListener; +import spoon.experimental.modelobs.AddAction; +import spoon.experimental.modelobs.DeleteAction; +import spoon.experimental.modelobs.DeleteAllAction; +import spoon.experimental.modelobs.UpdateAction; +import spoon.experimental.modelobs.context.ListContext; +import spoon.experimental.modelobs.context.MapContext; +import spoon.experimental.modelobs.context.ObjectContext; +import spoon.experimental.modelobs.context.SetContext; import spoon.reflect.declaration.CtElement; import spoon.reflect.declaration.ModifierKind; import spoon.reflect.path.CtRole; From 14ad3d08336d9aef1ee690e355030c99a4cc440b Mon Sep 17 00:00:00 2001 From: tdurieux Date: Fri, 23 Jun 2017 15:29:52 +0200 Subject: [PATCH 18/40] create ListeningChangeFactory --- src/main/java/spoon/compiler/Environment.java | 3 + .../spoon/reflect/factory/ChangeFactory.java | 107 ++++++++++++------ .../spoon/reflect/factory/FactoryImpl.java | 7 +- .../spoon/support/StandardEnvironment.java | 12 ++ 4 files changed, 90 insertions(+), 39 deletions(-) diff --git a/src/main/java/spoon/compiler/Environment.java b/src/main/java/spoon/compiler/Environment.java index e89a68b975a..b6c009d7dbe 100644 --- a/src/main/java/spoon/compiler/Environment.java +++ b/src/main/java/spoon/compiler/Environment.java @@ -24,6 +24,7 @@ import spoon.processing.ProcessorProperties; import spoon.reflect.declaration.CtElement; import spoon.reflect.declaration.CtMethod; +import spoon.reflect.factory.ChangeFactory; import spoon.reflect.factory.Factory; /** @@ -330,4 +331,6 @@ void report(Processor processor, Level level, /** Set the directory where binary .class files are created */ String getBinaryOutputDirectory(); + + ChangeFactory getChangeFactory(); } diff --git a/src/main/java/spoon/reflect/factory/ChangeFactory.java b/src/main/java/spoon/reflect/factory/ChangeFactory.java index a0687fa1b8b..2a5210b0471 100644 --- a/src/main/java/spoon/reflect/factory/ChangeFactory.java +++ b/src/main/java/spoon/reflect/factory/ChangeFactory.java @@ -36,14 +36,10 @@ import java.util.Map; import java.util.Set; -public class ChangeFactory extends SubFactory { +public class ChangeFactory { private final List listeners = new ArrayList<>(2); - public ChangeFactory(Factory factory) { - super(factory); - } - public void addModelChangeListener(final ModelChangeListener listener) { listeners.add(listener); } @@ -68,28 +64,18 @@ private void propagateModelChange(final Action action) { } public void onObjectUpdate(CtElement currentElement, CtRole role, CtElement newValue, CtElement oldValue) { - Action action = new UpdateAction<>(new ObjectContext(currentElement, role), newValue, oldValue); - propagateModelChange(action); } public void onObjectUpdate(CtElement currentElement, CtRole role, Object newValue, Object oldValue) { - UpdateAction action = new UpdateAction<>(new ObjectContext(currentElement, role), newValue, oldValue); - propagateModelChange(action); } public void onObjectDelete(CtElement currentElement, CtRole role, CtElement oldValue) { - DeleteAction action = new DeleteAction<>(new ObjectContext(currentElement, role), oldValue); - propagateModelChange(action); } public void onListAdd(CtElement currentElement, CtRole role, List field, CtElement newValue) { - AddAction action = new AddAction<>(new ListContext(currentElement, role, field), newValue); - propagateModelChange(action); } public void onListAdd(CtElement currentElement, CtRole role, List field, int index, CtElement newValue) { - AddAction action = new AddAction<>(new ListContext(currentElement, role, field, index), newValue); - propagateModelChange(action); } @@ -100,41 +86,27 @@ public void onListDelete(CtElement currentElement, CtRole role, List field, Coll } public void onListDelete(CtElement currentElement, CtRole role, List field, int index, CtElement oldValue) { - DeleteAction action = new DeleteAction<>(new ListContext(currentElement, role, field, index), oldValue); - propagateModelChange(action); } public void onListDeleteAll(CtElement currentElement, CtRole role, List field, List oldValue) { - DeleteAllAction action = new DeleteAllAction(new ListContext(currentElement, role, field), oldValue); - propagateModelChange(action); } public void onMapAdd(CtElement currentElement, CtRole role, Map field, K key, CtElement newValue) { - AddAction action = new AddAction<>(new MapContext<>(currentElement, role, field, key), newValue); - propagateModelChange(action); } public void onMapDeleteAll(CtElement currentElement, CtRole role, Map field, Map oldValue) { - DeleteAllAction action = new DeleteAllAction(new MapContext<>(currentElement, role, field), oldValue); - propagateModelChange(action); } public void onSetAdd(CtElement currentElement, CtRole role, Set field, CtElement newValue) { - AddAction action = new AddAction<>(new SetContext(currentElement, role, field), newValue); - propagateModelChange(action); } public void onSetAdd(CtElement currentElement, CtRole role, Set field, ModifierKind newValue) { - AddAction action = new AddAction<>(new SetContext(currentElement, role, field), newValue); - propagateModelChange(action); } public void onSetDelete(CtElement currentElement, CtRole role, Set field, CtElement oldValue) { - DeleteAction action = new DeleteAction<>(new SetContext(currentElement, role, field), oldValue); - propagateModelChange(action); } public void onSetDelete(CtElement currentElement, CtRole role, Set field, Collection oldValue) { @@ -144,12 +116,81 @@ public void onSetDelete(CtElement currentElement, CtRole role, Set field, Collec } public void onSetDelete(CtElement currentElement, CtRole role, Set field, ModifierKind oldValue) { - DeleteAction action = new DeleteAction(new SetContext(currentElement, role, field), oldValue); - propagateModelChange(action); } public void onSetDeleteAll(CtElement currentElement, CtRole role, Set field, Set oldValue) { - DeleteAllAction action = new DeleteAllAction(new SetContext(currentElement, role, field), oldValue); - propagateModelChange(action); + } + + public class ListeningChangeFactory extends ChangeFactory { + + @Override + public void onObjectUpdate(CtElement currentElement, CtRole role, CtElement newValue, CtElement oldValue) { + propagateModelChange(new UpdateAction<>(new ObjectContext(currentElement, role), newValue, oldValue)); + } + + @Override + public void onObjectUpdate(CtElement currentElement, CtRole role, Object newValue, Object oldValue) { + propagateModelChange(new UpdateAction<>(new ObjectContext(currentElement, role), newValue, oldValue)); + } + + @Override + public void onObjectDelete(CtElement currentElement, CtRole role, CtElement oldValue) { + propagateModelChange(new DeleteAction<>(new ObjectContext(currentElement, role), oldValue)); + } + + @Override + public void onListAdd(CtElement currentElement, CtRole role, List field, CtElement newValue) { + propagateModelChange(new AddAction<>(new ListContext(currentElement, role, field), newValue)); + } + + @Override + public void onListAdd(CtElement currentElement, CtRole role, List field, int index, CtElement newValue) { + propagateModelChange(new AddAction<>(new ListContext(currentElement, role, field, index), newValue)); + } + + @Override + public void onListDelete(CtElement currentElement, CtRole role, List field, int index, CtElement oldValue) { + propagateModelChange(new DeleteAction<>(new ListContext(currentElement, role, field, index), oldValue)); + } + + @Override + public void onListDeleteAll(CtElement currentElement, CtRole role, List field, List oldValue) { + propagateModelChange(new DeleteAllAction(new ListContext(currentElement, role, field), oldValue)); + } + + @Override + public void onMapAdd(CtElement currentElement, CtRole role, Map field, K key, CtElement newValue) { + propagateModelChange(new AddAction<>(new MapContext<>(currentElement, role, field, key), newValue)); + } + + @Override + public void onMapDeleteAll(CtElement currentElement, CtRole role, Map field, Map oldValue) { + propagateModelChange(new DeleteAllAction(new MapContext<>(currentElement, role, field), oldValue)); + } + + @Override + public void onSetAdd(CtElement currentElement, CtRole role, Set field, CtElement newValue) { + propagateModelChange(new AddAction<>(new SetContext(currentElement, role, field), newValue)); + } + + @Override + public void onSetAdd(CtElement currentElement, CtRole role, Set field, ModifierKind newValue) { + propagateModelChange(new AddAction<>(new SetContext(currentElement, role, field), newValue)); + } + + @Override + public void onSetDelete(CtElement currentElement, CtRole role, Set field, CtElement oldValue) { + propagateModelChange(new DeleteAction<>(new SetContext(currentElement, role, field), oldValue)); + } + + @Override + public void onSetDelete(CtElement currentElement, CtRole role, Set field, ModifierKind oldValue) { + propagateModelChange(new DeleteAction(new SetContext(currentElement, role, field), oldValue)); + } + + @Override + public void onSetDeleteAll(CtElement currentElement, CtRole role, Set field, Set oldValue) { + propagateModelChange(new DeleteAllAction(new SetContext(currentElement, role, field), oldValue)); + } } } diff --git a/src/main/java/spoon/reflect/factory/FactoryImpl.java b/src/main/java/spoon/reflect/factory/FactoryImpl.java index 038a0c2d21d..8955e87123b 100644 --- a/src/main/java/spoon/reflect/factory/FactoryImpl.java +++ b/src/main/java/spoon/reflect/factory/FactoryImpl.java @@ -352,17 +352,12 @@ public QueryFactory Query() { return query; } - private transient ChangeFactory change; - /** * The change sub-factory. */ @Override public ChangeFactory Change() { - if (change == null) { - change = new ChangeFactory(this); - } - return change; + return getEnvironment().getChangeFactory(); } /** diff --git a/src/main/java/spoon/support/StandardEnvironment.java b/src/main/java/spoon/support/StandardEnvironment.java index f9b5bbad084..79a10c3f665 100644 --- a/src/main/java/spoon/support/StandardEnvironment.java +++ b/src/main/java/spoon/support/StandardEnvironment.java @@ -34,6 +34,7 @@ import spoon.reflect.declaration.CtExecutable; import spoon.reflect.declaration.CtType; import spoon.reflect.declaration.ParentNotInitializedException; +import spoon.reflect.factory.ChangeFactory; import spoon.reflect.factory.Factory; import spoon.support.compiler.FileSystemFolder; @@ -85,6 +86,8 @@ public class StandardEnvironment implements Serializable, Environment { private boolean skipSelfChecks; + private ChangeFactory changeFactory = new ChangeFactory(); + /** * Creates a new environment with a null default file * generator. @@ -480,4 +483,13 @@ public void setBinaryOutputDirectory(String s) { public String getBinaryOutputDirectory() { return binaryOutputDirectory; } + + @Override + public ChangeFactory getChangeFactory() { + return changeFactory; + } + + public void setChangeFactory(ChangeFactory changeFactory) { + this.changeFactory = changeFactory; + } } From c4a286a9f28cdfa0927f74687959945ec9c66c15 Mon Sep 17 00:00:00 2001 From: tdurieux Date: Fri, 23 Jun 2017 15:31:59 +0200 Subject: [PATCH 19/40] move ChangeFactory --- src/main/java/spoon/compiler/Environment.java | 2 +- .../modelobs}/ChangeFactory.java | 10 ++-------- src/main/java/spoon/experimental/package-info.java | 4 ++++ src/main/java/spoon/reflect/factory/Factory.java | 1 + src/main/java/spoon/reflect/factory/FactoryImpl.java | 1 + src/main/java/spoon/support/StandardEnvironment.java | 2 +- 6 files changed, 10 insertions(+), 10 deletions(-) rename src/main/java/spoon/{reflect/factory => experimental/modelobs}/ChangeFactory.java (95%) create mode 100644 src/main/java/spoon/experimental/package-info.java diff --git a/src/main/java/spoon/compiler/Environment.java b/src/main/java/spoon/compiler/Environment.java index b6c009d7dbe..a1737161580 100644 --- a/src/main/java/spoon/compiler/Environment.java +++ b/src/main/java/spoon/compiler/Environment.java @@ -24,7 +24,7 @@ import spoon.processing.ProcessorProperties; import spoon.reflect.declaration.CtElement; import spoon.reflect.declaration.CtMethod; -import spoon.reflect.factory.ChangeFactory; +import spoon.experimental.modelobs.ChangeFactory; import spoon.reflect.factory.Factory; /** diff --git a/src/main/java/spoon/reflect/factory/ChangeFactory.java b/src/main/java/spoon/experimental/modelobs/ChangeFactory.java similarity index 95% rename from src/main/java/spoon/reflect/factory/ChangeFactory.java rename to src/main/java/spoon/experimental/modelobs/ChangeFactory.java index 2a5210b0471..fba0764eb58 100644 --- a/src/main/java/spoon/reflect/factory/ChangeFactory.java +++ b/src/main/java/spoon/experimental/modelobs/ChangeFactory.java @@ -14,14 +14,8 @@ * The fact that you are presently reading this means that you have had * knowledge of the CeCILL-C license and that you accept its terms. */ -package spoon.reflect.factory; - -import spoon.experimental.modelobs.Action; -import spoon.experimental.modelobs.ModelChangeListener; -import spoon.experimental.modelobs.AddAction; -import spoon.experimental.modelobs.DeleteAction; -import spoon.experimental.modelobs.DeleteAllAction; -import spoon.experimental.modelobs.UpdateAction; +package spoon.experimental.modelobs; + import spoon.experimental.modelobs.context.ListContext; import spoon.experimental.modelobs.context.MapContext; import spoon.experimental.modelobs.context.ObjectContext; diff --git a/src/main/java/spoon/experimental/package-info.java b/src/main/java/spoon/experimental/package-info.java new file mode 100644 index 00000000000..824a300c926 --- /dev/null +++ b/src/main/java/spoon/experimental/package-info.java @@ -0,0 +1,4 @@ +/** + * this is unstable code, subject to potential complete redesign, not only in snapshots but also in releases. you can use this code but you'll probably be impacted upon future changes. + */ +package spoon.experimental; diff --git a/src/main/java/spoon/reflect/factory/Factory.java b/src/main/java/spoon/reflect/factory/Factory.java index bc0af89ff10..1f1bf05f986 100644 --- a/src/main/java/spoon/reflect/factory/Factory.java +++ b/src/main/java/spoon/reflect/factory/Factory.java @@ -17,6 +17,7 @@ package spoon.reflect.factory; import spoon.compiler.Environment; +import spoon.experimental.modelobs.ChangeFactory; import spoon.reflect.CtModel; import spoon.reflect.code.BinaryOperatorKind; import spoon.reflect.code.CtAnnotationFieldAccess; diff --git a/src/main/java/spoon/reflect/factory/FactoryImpl.java b/src/main/java/spoon/reflect/factory/FactoryImpl.java index 8955e87123b..acd6ebd4062 100644 --- a/src/main/java/spoon/reflect/factory/FactoryImpl.java +++ b/src/main/java/spoon/reflect/factory/FactoryImpl.java @@ -17,6 +17,7 @@ package spoon.reflect.factory; import spoon.compiler.Environment; +import spoon.experimental.modelobs.ChangeFactory; import spoon.reflect.CtModel; import spoon.reflect.CtModelImpl; import spoon.reflect.code.BinaryOperatorKind; diff --git a/src/main/java/spoon/support/StandardEnvironment.java b/src/main/java/spoon/support/StandardEnvironment.java index 79a10c3f665..5395eccf8b8 100644 --- a/src/main/java/spoon/support/StandardEnvironment.java +++ b/src/main/java/spoon/support/StandardEnvironment.java @@ -34,7 +34,7 @@ import spoon.reflect.declaration.CtExecutable; import spoon.reflect.declaration.CtType; import spoon.reflect.declaration.ParentNotInitializedException; -import spoon.reflect.factory.ChangeFactory; +import spoon.experimental.modelobs.ChangeFactory; import spoon.reflect.factory.Factory; import spoon.support.compiler.FileSystemFolder; From 1db2c75c3855b68cb0312b3802645c09b3ca3f61 Mon Sep 17 00:00:00 2001 From: tdurieux Date: Fri, 23 Jun 2017 15:40:29 +0200 Subject: [PATCH 20/40] add documentation --- .../modelobs/AbstractModelChangeListener.java | 2 +- .../java/spoon/experimental/modelobs/Action.java | 14 +++++++++++++- .../spoon/experimental/modelobs/AddAction.java | 2 +- .../spoon/experimental/modelobs/ChangeFactory.java | 3 +++ .../spoon/experimental/modelobs/DeleteAction.java | 6 +++++- .../experimental/modelobs/DeleteAllAction.java | 10 +++++++--- .../spoon/experimental/modelobs/UpdateAction.java | 14 +++++++++++++- .../experimental/modelobs/context/Context.java | 11 +++++++++++ .../experimental/modelobs/context/ListContext.java | 8 ++++++++ .../experimental/modelobs/context/MapContext.java | 13 +++++++++++++ 10 files changed, 75 insertions(+), 8 deletions(-) diff --git a/src/main/java/spoon/experimental/modelobs/AbstractModelChangeListener.java b/src/main/java/spoon/experimental/modelobs/AbstractModelChangeListener.java index 656cd74654a..8747ec162c5 100644 --- a/src/main/java/spoon/experimental/modelobs/AbstractModelChangeListener.java +++ b/src/main/java/spoon/experimental/modelobs/AbstractModelChangeListener.java @@ -17,7 +17,7 @@ package spoon.experimental.modelobs; /** - * notifies all change on the AST + * abstract implementation of the ModelChangeListener */ public abstract class AbstractModelChangeListener implements ModelChangeListener { @Override diff --git a/src/main/java/spoon/experimental/modelobs/Action.java b/src/main/java/spoon/experimental/modelobs/Action.java index a0fff8cc9f7..b0fb592a6a6 100644 --- a/src/main/java/spoon/experimental/modelobs/Action.java +++ b/src/main/java/spoon/experimental/modelobs/Action.java @@ -18,6 +18,9 @@ import spoon.experimental.modelobs.context.Context; +/** + * defines an action change on the model + */ public abstract class Action { private final Context context; @@ -25,8 +28,17 @@ public abstract class Action { this.context = context; } - public abstract T getChangedElement(); + /** + * get the changed value of the model + * @param the type of the element + * @return the changed value + */ + public abstract T getChangedValue(); + /** + * get the context of the change + * @return the context + */ public Context getContext() { return context; } diff --git a/src/main/java/spoon/experimental/modelobs/AddAction.java b/src/main/java/spoon/experimental/modelobs/AddAction.java index 1bbbe2c45f8..38182aa3141 100644 --- a/src/main/java/spoon/experimental/modelobs/AddAction.java +++ b/src/main/java/spoon/experimental/modelobs/AddAction.java @@ -27,7 +27,7 @@ public AddAction(Context context, T newElement) { } @Override - public T getChangedElement() { + public T getChangedValue() { return getNewElement(); } diff --git a/src/main/java/spoon/experimental/modelobs/ChangeFactory.java b/src/main/java/spoon/experimental/modelobs/ChangeFactory.java index fba0764eb58..afe4d933948 100644 --- a/src/main/java/spoon/experimental/modelobs/ChangeFactory.java +++ b/src/main/java/spoon/experimental/modelobs/ChangeFactory.java @@ -30,6 +30,9 @@ import java.util.Map; import java.util.Set; +/** + * is the factory that create the action on the model + */ public class ChangeFactory { private final List listeners = new ArrayList<>(2); diff --git a/src/main/java/spoon/experimental/modelobs/DeleteAction.java b/src/main/java/spoon/experimental/modelobs/DeleteAction.java index 77d07f4fb57..7ef78ae1452 100644 --- a/src/main/java/spoon/experimental/modelobs/DeleteAction.java +++ b/src/main/java/spoon/experimental/modelobs/DeleteAction.java @@ -18,6 +18,10 @@ import spoon.experimental.modelobs.context.Context; +/** + * defines the delete action + * @param + */ public class DeleteAction extends Action { private T oldElement; @@ -27,7 +31,7 @@ public DeleteAction(Context context, T oldElement) { } @Override - public T getChangedElement() { + public T getChangedValue() { return getRemovedElement(); } diff --git a/src/main/java/spoon/experimental/modelobs/DeleteAllAction.java b/src/main/java/spoon/experimental/modelobs/DeleteAllAction.java index e21468a155f..6bda8b17ab4 100644 --- a/src/main/java/spoon/experimental/modelobs/DeleteAllAction.java +++ b/src/main/java/spoon/experimental/modelobs/DeleteAllAction.java @@ -21,13 +21,17 @@ import java.util.Collection; import java.util.Map; -public class DeleteAllAction extends DeleteAction { +/** + * defines the delete all action. + * @param + */ +public class DeleteAllAction extends DeleteAction { public DeleteAllAction(Context context, Collection oldElement) { - super(context, oldElement); + super(context, (T) oldElement); } public DeleteAllAction(Context context, Map oldElement) { - super(context, oldElement); + super(context, (T) oldElement); } } diff --git a/src/main/java/spoon/experimental/modelobs/UpdateAction.java b/src/main/java/spoon/experimental/modelobs/UpdateAction.java index ed4515a5275..695a8c6f418 100644 --- a/src/main/java/spoon/experimental/modelobs/UpdateAction.java +++ b/src/main/java/spoon/experimental/modelobs/UpdateAction.java @@ -18,6 +18,10 @@ import spoon.experimental.modelobs.context.Context; +/** + * defines the update action + * @param + */ public class UpdateAction extends Action { private final T oldElement; private final T newElement; @@ -29,14 +33,22 @@ public UpdateAction(Context context, T newElement, T oldElement) { } @Override - public T getChangedElement() { + public T getChangedValue() { return getNewElement(); } + /** + * the new value in the model + * @return the new value + */ public T getNewElement() { return newElement; } + /** + * the old value in the model + * @return the old value + */ public T getOldElement() { return oldElement; } diff --git a/src/main/java/spoon/experimental/modelobs/context/Context.java b/src/main/java/spoon/experimental/modelobs/context/Context.java index fbb1d6a1770..f074a1d8840 100644 --- a/src/main/java/spoon/experimental/modelobs/context/Context.java +++ b/src/main/java/spoon/experimental/modelobs/context/Context.java @@ -19,6 +19,9 @@ import spoon.reflect.declaration.CtElement; import spoon.reflect.path.CtRole; +/** + * defines the context of an action + */ public abstract class Context { private CtElement element; private CtRole role; @@ -28,10 +31,18 @@ public Context(CtElement element, CtRole role) { this.role = role; } + /** + * the changed parent + * @return the changed parent + */ public CtElement getElement() { return element; } + /** + * the role that has been modified + * @return the role that has been modified + */ public CtRole getRole() { return role; } diff --git a/src/main/java/spoon/experimental/modelobs/context/ListContext.java b/src/main/java/spoon/experimental/modelobs/context/ListContext.java index 3ce9cb89aaf..2d07cee42e2 100644 --- a/src/main/java/spoon/experimental/modelobs/context/ListContext.java +++ b/src/main/java/spoon/experimental/modelobs/context/ListContext.java @@ -21,6 +21,9 @@ import java.util.List; +/** + * defines a list context + */ public class ListContext extends CollectionContext> { private final int position; @@ -33,6 +36,11 @@ public ListContext(CtElement element, CtRole role, List original, int positio this.position = position; } + /** + * the position where the change has been made (returns -1 if no position is defined). + * + * @return the position of the change + */ public int getPosition() { return position; } diff --git a/src/main/java/spoon/experimental/modelobs/context/MapContext.java b/src/main/java/spoon/experimental/modelobs/context/MapContext.java index 12cc56ad316..36ba506178b 100644 --- a/src/main/java/spoon/experimental/modelobs/context/MapContext.java +++ b/src/main/java/spoon/experimental/modelobs/context/MapContext.java @@ -21,6 +21,11 @@ import java.util.Map; +/** + * defines the map context + * @param + * @param + */ public class MapContext extends Context { private final Map map; private K key; @@ -35,10 +40,18 @@ public MapContext(CtElement element, CtRole role, Map map, K key) { this.key = key; } + /** + * get the changed key + * @return the changed key + */ public K getKey() { return key; } + /** + * the changed map + * @return the changed map + */ public Map getMap() { return map; } From a25774984ef943726d78cf8f337fc5531c2bb9d0 Mon Sep 17 00:00:00 2001 From: tdurieux Date: Fri, 23 Jun 2017 15:42:49 +0200 Subject: [PATCH 21/40] update license --- .../java/spoon/experimental/package-info.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/main/java/spoon/experimental/package-info.java b/src/main/java/spoon/experimental/package-info.java index 824a300c926..44372bbe3a7 100644 --- a/src/main/java/spoon/experimental/package-info.java +++ b/src/main/java/spoon/experimental/package-info.java @@ -1,3 +1,20 @@ +/** + * Copyright (C) 2006-2017 INRIA and contributors + * Spoon - http://spoon.gforge.inria.fr/ + * + * This software is governed by the CeCILL-C License under French law and + * abiding by the rules of distribution of free software. You can use, modify + * and/or redistribute the software under the terms of the CeCILL-C license as + * circulated by CEA, CNRS and INRIA at http://www.cecill.info. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the CeCILL-C License for more details. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL-C license and that you accept its terms. + */ + /** * this is unstable code, subject to potential complete redesign, not only in snapshots but also in releases. you can use this code but you'll probably be impacted upon future changes. */ From 01810536ddee1ddff7900aedce9b47ed45873d37 Mon Sep 17 00:00:00 2001 From: tdurieux Date: Fri, 23 Jun 2017 15:55:18 +0200 Subject: [PATCH 22/40] fix handling policy --- src/main/java/spoon/support/compiler/jdt/JDTBatchCompiler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/spoon/support/compiler/jdt/JDTBatchCompiler.java b/src/main/java/spoon/support/compiler/jdt/JDTBatchCompiler.java index 5e5dee9fbec..ca62f475fd2 100644 --- a/src/main/java/spoon/support/compiler/jdt/JDTBatchCompiler.java +++ b/src/main/java/spoon/support/compiler/jdt/JDTBatchCompiler.java @@ -109,7 +109,7 @@ public CompilationUnitDeclaration[] getUnits() { CompilerOptions compilerOptions = new CompilerOptions(this.options); compilerOptions.parseLiteralExpressionsAsConstants = false; TreeBuilderCompiler treeBuilderCompiler = new TreeBuilderCompiler( - environment, DefaultErrorHandlingPolicies.ignoreAllProblems(), compilerOptions, + environment, getHandlingPolicy(), compilerOptions, this.jdtCompiler.requestor, getProblemFactory(), this.out, null); if (jdtCompiler.getEnvironment().getNoClasspath()) { From 507d03679b3202ff9307ed8769dfb54089fa3e40 Mon Sep 17 00:00:00 2001 From: tdurieux Date: Fri, 23 Jun 2017 16:04:03 +0200 Subject: [PATCH 23/40] remove type parameter warning --- src/main/java/spoon/experimental/modelobs/ChangeFactory.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/spoon/experimental/modelobs/ChangeFactory.java b/src/main/java/spoon/experimental/modelobs/ChangeFactory.java index afe4d933948..165bedadee6 100644 --- a/src/main/java/spoon/experimental/modelobs/ChangeFactory.java +++ b/src/main/java/spoon/experimental/modelobs/ChangeFactory.java @@ -182,7 +182,7 @@ public void onSetDelete(CtElement currentElement, CtRole role, Set field, CtElem @Override public void onSetDelete(CtElement currentElement, CtRole role, Set field, ModifierKind oldValue) { - propagateModelChange(new DeleteAction(new SetContext(currentElement, role, field), oldValue)); + propagateModelChange(new DeleteAction<>(new SetContext(currentElement, role, field), oldValue)); } @Override From f48f492c319df6cc471e021918de27d12602e96b Mon Sep 17 00:00:00 2001 From: tdurieux Date: Fri, 23 Jun 2017 16:31:32 +0200 Subject: [PATCH 24/40] refactor: rename --- src/main/java/spoon/compiler/Environment.java | 4 ++-- ...=> AbstractActionBasedChangeListener.java} | 8 ++------ ...er.java => ActionBasedChangeListener.java} | 2 +- .../experimental/modelobs/AddAction.java | 10 +++++----- .../experimental/modelobs/DeleteAction.java | 12 +++++------ .../modelobs/DeleteAllAction.java | 8 ++++---- ...ctory.java => FineModelChangeHandler.java} | 14 ++++++------- .../experimental/modelobs/UpdateAction.java | 20 +++++++++---------- .../modelobs/context/CollectionContext.java | 8 ++++---- .../modelobs/context/Context.java | 18 ++++++++--------- .../modelobs/context/SetContext.java | 1 + .../java/spoon/reflect/factory/Factory.java | 4 ++-- .../spoon/reflect/factory/FactoryImpl.java | 6 +++--- .../spoon/support/StandardEnvironment.java | 12 +++++------ 14 files changed, 62 insertions(+), 65 deletions(-) rename src/main/java/spoon/experimental/modelobs/{AbstractModelChangeListener.java => AbstractActionBasedChangeListener.java} (92%) rename src/main/java/spoon/experimental/modelobs/{ModelChangeListener.java => ActionBasedChangeListener.java} (97%) rename src/main/java/spoon/experimental/modelobs/{ChangeFactory.java => FineModelChangeHandler.java} (93%) diff --git a/src/main/java/spoon/compiler/Environment.java b/src/main/java/spoon/compiler/Environment.java index a1737161580..0872c12de36 100644 --- a/src/main/java/spoon/compiler/Environment.java +++ b/src/main/java/spoon/compiler/Environment.java @@ -24,7 +24,7 @@ import spoon.processing.ProcessorProperties; import spoon.reflect.declaration.CtElement; import spoon.reflect.declaration.CtMethod; -import spoon.experimental.modelobs.ChangeFactory; +import spoon.experimental.modelobs.FineModelChangeHandler; import spoon.reflect.factory.Factory; /** @@ -332,5 +332,5 @@ void report(Processor processor, Level level, /** Set the directory where binary .class files are created */ String getBinaryOutputDirectory(); - ChangeFactory getChangeFactory(); + FineModelChangeHandler getModelChangeHandler(); } diff --git a/src/main/java/spoon/experimental/modelobs/AbstractModelChangeListener.java b/src/main/java/spoon/experimental/modelobs/AbstractActionBasedChangeListener.java similarity index 92% rename from src/main/java/spoon/experimental/modelobs/AbstractModelChangeListener.java rename to src/main/java/spoon/experimental/modelobs/AbstractActionBasedChangeListener.java index 8747ec162c5..dfb935ef562 100644 --- a/src/main/java/spoon/experimental/modelobs/AbstractModelChangeListener.java +++ b/src/main/java/spoon/experimental/modelobs/AbstractActionBasedChangeListener.java @@ -19,29 +19,25 @@ /** * abstract implementation of the ModelChangeListener */ -public abstract class AbstractModelChangeListener implements ModelChangeListener { +public abstract class AbstractActionBasedChangeListener + implements ActionBasedChangeListener { @Override public void onDelete(DeleteAction action) { - } @Override public void onDeleteAll(DeleteAllAction action) { - } @Override public void onAdd(AddAction action) { - } @Override public void onUpdate(UpdateAction action) { - } @Override public void onAction(Action action) { - } } diff --git a/src/main/java/spoon/experimental/modelobs/ModelChangeListener.java b/src/main/java/spoon/experimental/modelobs/ActionBasedChangeListener.java similarity index 97% rename from src/main/java/spoon/experimental/modelobs/ModelChangeListener.java rename to src/main/java/spoon/experimental/modelobs/ActionBasedChangeListener.java index ab352eb397d..b25501c1a73 100644 --- a/src/main/java/spoon/experimental/modelobs/ModelChangeListener.java +++ b/src/main/java/spoon/experimental/modelobs/ActionBasedChangeListener.java @@ -19,7 +19,7 @@ /** * notifies all change on the AST */ -public interface ModelChangeListener { +public interface ActionBasedChangeListener { /** * when an element is removed * @param action contains information of the change diff --git a/src/main/java/spoon/experimental/modelobs/AddAction.java b/src/main/java/spoon/experimental/modelobs/AddAction.java index 38182aa3141..9afb2e34805 100644 --- a/src/main/java/spoon/experimental/modelobs/AddAction.java +++ b/src/main/java/spoon/experimental/modelobs/AddAction.java @@ -19,23 +19,23 @@ import spoon.experimental.modelobs.context.Context; public class AddAction extends Action { - private T newElement; + private T newValue; public AddAction(Context context, T newElement) { super(context); - this.newElement = newElement; + this.newValue = newElement; } @Override public T getChangedValue() { - return getNewElement(); + return getNewValue(); } /** * Returns the added element * @return the new element */ - public T getNewElement() { - return newElement; + public T getNewValue() { + return newValue; } } diff --git a/src/main/java/spoon/experimental/modelobs/DeleteAction.java b/src/main/java/spoon/experimental/modelobs/DeleteAction.java index 7ef78ae1452..d56fd38d245 100644 --- a/src/main/java/spoon/experimental/modelobs/DeleteAction.java +++ b/src/main/java/spoon/experimental/modelobs/DeleteAction.java @@ -23,23 +23,23 @@ * @param */ public class DeleteAction extends Action { - private T oldElement; + private T oldValue; - public DeleteAction(Context context, T oldElement) { + public DeleteAction(Context context, T oldValue) { super(context); - this.oldElement = oldElement; + this.oldValue = oldValue; } @Override public T getChangedValue() { - return getRemovedElement(); + return getRemovedValue(); } /** * Returns the removed element * @return the removed element */ - public T getRemovedElement() { - return oldElement; + public T getRemovedValue() { + return oldValue; } } diff --git a/src/main/java/spoon/experimental/modelobs/DeleteAllAction.java b/src/main/java/spoon/experimental/modelobs/DeleteAllAction.java index 6bda8b17ab4..797e6207080 100644 --- a/src/main/java/spoon/experimental/modelobs/DeleteAllAction.java +++ b/src/main/java/spoon/experimental/modelobs/DeleteAllAction.java @@ -27,11 +27,11 @@ */ public class DeleteAllAction extends DeleteAction { - public DeleteAllAction(Context context, Collection oldElement) { - super(context, (T) oldElement); + public DeleteAllAction(Context context, Collection oldValue) { + super(context, (T) oldValue); } - public DeleteAllAction(Context context, Map oldElement) { - super(context, (T) oldElement); + public DeleteAllAction(Context context, Map oldValue) { + super(context, (T) oldValue); } } diff --git a/src/main/java/spoon/experimental/modelobs/ChangeFactory.java b/src/main/java/spoon/experimental/modelobs/FineModelChangeHandler.java similarity index 93% rename from src/main/java/spoon/experimental/modelobs/ChangeFactory.java rename to src/main/java/spoon/experimental/modelobs/FineModelChangeHandler.java index 165bedadee6..a6c3db38592 100644 --- a/src/main/java/spoon/experimental/modelobs/ChangeFactory.java +++ b/src/main/java/spoon/experimental/modelobs/FineModelChangeHandler.java @@ -31,22 +31,22 @@ import java.util.Set; /** - * is the factory that create the action on the model + * is the listener that creates the action on the model */ -public class ChangeFactory { +public class FineModelChangeHandler { - private final List listeners = new ArrayList<>(2); + private final List listeners = new ArrayList<>(2); - public void addModelChangeListener(final ModelChangeListener listener) { + public void addModelChangeListener(final ActionBasedChangeListener listener) { listeners.add(listener); } - public void removeModelChangeListener(final ModelChangeListener listener) { + public void removeModelChangeListener(final ActionBasedChangeListener listener) { listeners.remove(listener); } private void propagateModelChange(final Action action) { - for (ModelChangeListener listener : listeners) { + for (ActionBasedChangeListener listener : listeners) { listener.onAction(action); if (action instanceof DeleteAllAction) { listener.onDeleteAll((DeleteAllAction) action); @@ -118,7 +118,7 @@ public void onSetDelete(CtElement currentElement, CtRole role, Set field, Modifi public void onSetDeleteAll(CtElement currentElement, CtRole role, Set field, Set oldValue) { } - public class ListeningChangeFactory extends ChangeFactory { + public class ListeningChangeFactory extends FineModelChangeHandler { @Override public void onObjectUpdate(CtElement currentElement, CtRole role, CtElement newValue, CtElement oldValue) { diff --git a/src/main/java/spoon/experimental/modelobs/UpdateAction.java b/src/main/java/spoon/experimental/modelobs/UpdateAction.java index 695a8c6f418..4b0c2b97bc2 100644 --- a/src/main/java/spoon/experimental/modelobs/UpdateAction.java +++ b/src/main/java/spoon/experimental/modelobs/UpdateAction.java @@ -23,33 +23,33 @@ * @param */ public class UpdateAction extends Action { - private final T oldElement; - private final T newElement; + private final T oldValue; + private final T newValue; - public UpdateAction(Context context, T newElement, T oldElement) { + public UpdateAction(Context context, T newValue, T oldValue) { super(context); - this.oldElement = oldElement; - this.newElement = newElement; + this.oldValue = oldValue; + this.newValue = newValue; } @Override public T getChangedValue() { - return getNewElement(); + return getNewValue(); } /** * the new value in the model * @return the new value */ - public T getNewElement() { - return newElement; + public T getNewValue() { + return newValue; } /** * the old value in the model * @return the old value */ - public T getOldElement() { - return oldElement; + public T getOldValue() { + return oldValue; } } diff --git a/src/main/java/spoon/experimental/modelobs/context/CollectionContext.java b/src/main/java/spoon/experimental/modelobs/context/CollectionContext.java index a70b24bc76c..bc1692d9f7d 100644 --- a/src/main/java/spoon/experimental/modelobs/context/CollectionContext.java +++ b/src/main/java/spoon/experimental/modelobs/context/CollectionContext.java @@ -21,11 +21,11 @@ import java.util.Collection; -public class CollectionContext> extends Context { - protected final T original; +public abstract class CollectionContext> extends Context { + protected final T copyOfTheCollection; - public CollectionContext(CtElement element, CtRole role, T original) { + public CollectionContext(CtElement element, CtRole role, T copyOfTheCollection) { super(element, role); - this.original = original; + this.copyOfTheCollection = copyOfTheCollection; } } diff --git a/src/main/java/spoon/experimental/modelobs/context/Context.java b/src/main/java/spoon/experimental/modelobs/context/Context.java index f074a1d8840..828436c120b 100644 --- a/src/main/java/spoon/experimental/modelobs/context/Context.java +++ b/src/main/java/spoon/experimental/modelobs/context/Context.java @@ -23,27 +23,27 @@ * defines the context of an action */ public abstract class Context { - private CtElement element; - private CtRole role; + private CtElement elementWhereChangeHappens; + private CtRole changedProperty; - public Context(CtElement element, CtRole role) { - this.element = element; - this.role = role; + public Context(CtElement element, CtRole changedProperty) { + this.elementWhereChangeHappens = element; + this.changedProperty = changedProperty; } /** * the changed parent * @return the changed parent */ - public CtElement getElement() { - return element; + public CtElement getElementWhereChangeHappens() { + return elementWhereChangeHappens; } /** * the role that has been modified * @return the role that has been modified */ - public CtRole getRole() { - return role; + public CtRole getChangedProperty() { + return changedProperty; } } diff --git a/src/main/java/spoon/experimental/modelobs/context/SetContext.java b/src/main/java/spoon/experimental/modelobs/context/SetContext.java index a4e70fd23d4..b914da39698 100644 --- a/src/main/java/spoon/experimental/modelobs/context/SetContext.java +++ b/src/main/java/spoon/experimental/modelobs/context/SetContext.java @@ -22,6 +22,7 @@ import java.util.Set; public class SetContext extends CollectionContext> { + public SetContext(CtElement element, CtRole role, Set original) { super(element, role, original); } diff --git a/src/main/java/spoon/reflect/factory/Factory.java b/src/main/java/spoon/reflect/factory/Factory.java index 1f1bf05f986..c10180f32c5 100644 --- a/src/main/java/spoon/reflect/factory/Factory.java +++ b/src/main/java/spoon/reflect/factory/Factory.java @@ -17,7 +17,7 @@ package spoon.reflect.factory; import spoon.compiler.Environment; -import spoon.experimental.modelobs.ChangeFactory; +import spoon.experimental.modelobs.FineModelChangeHandler; import spoon.reflect.CtModel; import spoon.reflect.code.BinaryOperatorKind; import spoon.reflect.code.CtAnnotationFieldAccess; @@ -157,7 +157,7 @@ public interface Factory { QueryFactory Query(); - ChangeFactory Change(); + FineModelChangeHandler Change(); /** * @see CodeFactory#createAnnotation(CtTypeReference) diff --git a/src/main/java/spoon/reflect/factory/FactoryImpl.java b/src/main/java/spoon/reflect/factory/FactoryImpl.java index acd6ebd4062..9bb694e3697 100644 --- a/src/main/java/spoon/reflect/factory/FactoryImpl.java +++ b/src/main/java/spoon/reflect/factory/FactoryImpl.java @@ -17,7 +17,7 @@ package spoon.reflect.factory; import spoon.compiler.Environment; -import spoon.experimental.modelobs.ChangeFactory; +import spoon.experimental.modelobs.FineModelChangeHandler; import spoon.reflect.CtModel; import spoon.reflect.CtModelImpl; import spoon.reflect.code.BinaryOperatorKind; @@ -357,8 +357,8 @@ public QueryFactory Query() { * The change sub-factory. */ @Override - public ChangeFactory Change() { - return getEnvironment().getChangeFactory(); + public FineModelChangeHandler Change() { + return getEnvironment().getModelChangeHandler(); } /** diff --git a/src/main/java/spoon/support/StandardEnvironment.java b/src/main/java/spoon/support/StandardEnvironment.java index 5395eccf8b8..eb2a3ea9be1 100644 --- a/src/main/java/spoon/support/StandardEnvironment.java +++ b/src/main/java/spoon/support/StandardEnvironment.java @@ -34,7 +34,7 @@ import spoon.reflect.declaration.CtExecutable; import spoon.reflect.declaration.CtType; import spoon.reflect.declaration.ParentNotInitializedException; -import spoon.experimental.modelobs.ChangeFactory; +import spoon.experimental.modelobs.FineModelChangeHandler; import spoon.reflect.factory.Factory; import spoon.support.compiler.FileSystemFolder; @@ -86,7 +86,7 @@ public class StandardEnvironment implements Serializable, Environment { private boolean skipSelfChecks; - private ChangeFactory changeFactory = new ChangeFactory(); + private FineModelChangeHandler modelChangeHandler = new FineModelChangeHandler(); /** * Creates a new environment with a null default file @@ -485,11 +485,11 @@ public String getBinaryOutputDirectory() { } @Override - public ChangeFactory getChangeFactory() { - return changeFactory; + public FineModelChangeHandler getModelChangeHandler() { + return modelChangeHandler; } - public void setChangeFactory(ChangeFactory changeFactory) { - this.changeFactory = changeFactory; + public void setModelChangeHandler(FineModelChangeHandler modelChangeHandler) { + this.modelChangeHandler = modelChangeHandler; } } From 032da4fec3c35f65726e97ffddaf7e0f4022d947 Mon Sep 17 00:00:00 2001 From: tdurieux Date: Fri, 23 Jun 2017 16:32:36 +0200 Subject: [PATCH 25/40] move actions to package --- .../modelobs/AbstractActionBasedChangeListener.java | 6 ++++++ .../experimental/modelobs/ActionBasedChangeListener.java | 6 ++++++ .../spoon/experimental/modelobs/FineModelChangeHandler.java | 5 +++++ .../spoon/experimental/modelobs/{ => action}/Action.java | 2 +- .../spoon/experimental/modelobs/{ => action}/AddAction.java | 2 +- .../experimental/modelobs/{ => action}/DeleteAction.java | 2 +- .../experimental/modelobs/{ => action}/DeleteAllAction.java | 2 +- .../experimental/modelobs/{ => action}/UpdateAction.java | 2 +- 8 files changed, 22 insertions(+), 5 deletions(-) rename src/main/java/spoon/experimental/modelobs/{ => action}/Action.java (96%) rename src/main/java/spoon/experimental/modelobs/{ => action}/AddAction.java (96%) rename src/main/java/spoon/experimental/modelobs/{ => action}/DeleteAction.java (96%) rename src/main/java/spoon/experimental/modelobs/{ => action}/DeleteAllAction.java (96%) rename src/main/java/spoon/experimental/modelobs/{ => action}/UpdateAction.java (97%) diff --git a/src/main/java/spoon/experimental/modelobs/AbstractActionBasedChangeListener.java b/src/main/java/spoon/experimental/modelobs/AbstractActionBasedChangeListener.java index dfb935ef562..d8c4232aa80 100644 --- a/src/main/java/spoon/experimental/modelobs/AbstractActionBasedChangeListener.java +++ b/src/main/java/spoon/experimental/modelobs/AbstractActionBasedChangeListener.java @@ -16,6 +16,12 @@ */ package spoon.experimental.modelobs; +import spoon.experimental.modelobs.action.Action; +import spoon.experimental.modelobs.action.AddAction; +import spoon.experimental.modelobs.action.DeleteAction; +import spoon.experimental.modelobs.action.DeleteAllAction; +import spoon.experimental.modelobs.action.UpdateAction; + /** * abstract implementation of the ModelChangeListener */ diff --git a/src/main/java/spoon/experimental/modelobs/ActionBasedChangeListener.java b/src/main/java/spoon/experimental/modelobs/ActionBasedChangeListener.java index b25501c1a73..0d92181e87a 100644 --- a/src/main/java/spoon/experimental/modelobs/ActionBasedChangeListener.java +++ b/src/main/java/spoon/experimental/modelobs/ActionBasedChangeListener.java @@ -16,6 +16,12 @@ */ package spoon.experimental.modelobs; +import spoon.experimental.modelobs.action.Action; +import spoon.experimental.modelobs.action.AddAction; +import spoon.experimental.modelobs.action.DeleteAction; +import spoon.experimental.modelobs.action.DeleteAllAction; +import spoon.experimental.modelobs.action.UpdateAction; + /** * notifies all change on the AST */ diff --git a/src/main/java/spoon/experimental/modelobs/FineModelChangeHandler.java b/src/main/java/spoon/experimental/modelobs/FineModelChangeHandler.java index a6c3db38592..fbca913201d 100644 --- a/src/main/java/spoon/experimental/modelobs/FineModelChangeHandler.java +++ b/src/main/java/spoon/experimental/modelobs/FineModelChangeHandler.java @@ -16,6 +16,11 @@ */ package spoon.experimental.modelobs; +import spoon.experimental.modelobs.action.Action; +import spoon.experimental.modelobs.action.AddAction; +import spoon.experimental.modelobs.action.DeleteAction; +import spoon.experimental.modelobs.action.DeleteAllAction; +import spoon.experimental.modelobs.action.UpdateAction; import spoon.experimental.modelobs.context.ListContext; import spoon.experimental.modelobs.context.MapContext; import spoon.experimental.modelobs.context.ObjectContext; diff --git a/src/main/java/spoon/experimental/modelobs/Action.java b/src/main/java/spoon/experimental/modelobs/action/Action.java similarity index 96% rename from src/main/java/spoon/experimental/modelobs/Action.java rename to src/main/java/spoon/experimental/modelobs/action/Action.java index b0fb592a6a6..eebe3cd3e33 100644 --- a/src/main/java/spoon/experimental/modelobs/Action.java +++ b/src/main/java/spoon/experimental/modelobs/action/Action.java @@ -14,7 +14,7 @@ * 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.experimental.modelobs; +package spoon.experimental.modelobs.action; import spoon.experimental.modelobs.context.Context; diff --git a/src/main/java/spoon/experimental/modelobs/AddAction.java b/src/main/java/spoon/experimental/modelobs/action/AddAction.java similarity index 96% rename from src/main/java/spoon/experimental/modelobs/AddAction.java rename to src/main/java/spoon/experimental/modelobs/action/AddAction.java index 9afb2e34805..1e64d51669a 100644 --- a/src/main/java/spoon/experimental/modelobs/AddAction.java +++ b/src/main/java/spoon/experimental/modelobs/action/AddAction.java @@ -14,7 +14,7 @@ * 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.experimental.modelobs; +package spoon.experimental.modelobs.action; import spoon.experimental.modelobs.context.Context; diff --git a/src/main/java/spoon/experimental/modelobs/DeleteAction.java b/src/main/java/spoon/experimental/modelobs/action/DeleteAction.java similarity index 96% rename from src/main/java/spoon/experimental/modelobs/DeleteAction.java rename to src/main/java/spoon/experimental/modelobs/action/DeleteAction.java index d56fd38d245..b8413d6be9d 100644 --- a/src/main/java/spoon/experimental/modelobs/DeleteAction.java +++ b/src/main/java/spoon/experimental/modelobs/action/DeleteAction.java @@ -14,7 +14,7 @@ * 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.experimental.modelobs; +package spoon.experimental.modelobs.action; import spoon.experimental.modelobs.context.Context; diff --git a/src/main/java/spoon/experimental/modelobs/DeleteAllAction.java b/src/main/java/spoon/experimental/modelobs/action/DeleteAllAction.java similarity index 96% rename from src/main/java/spoon/experimental/modelobs/DeleteAllAction.java rename to src/main/java/spoon/experimental/modelobs/action/DeleteAllAction.java index 797e6207080..d230bbcaca5 100644 --- a/src/main/java/spoon/experimental/modelobs/DeleteAllAction.java +++ b/src/main/java/spoon/experimental/modelobs/action/DeleteAllAction.java @@ -14,7 +14,7 @@ * 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.experimental.modelobs; +package spoon.experimental.modelobs.action; import spoon.experimental.modelobs.context.Context; diff --git a/src/main/java/spoon/experimental/modelobs/UpdateAction.java b/src/main/java/spoon/experimental/modelobs/action/UpdateAction.java similarity index 97% rename from src/main/java/spoon/experimental/modelobs/UpdateAction.java rename to src/main/java/spoon/experimental/modelobs/action/UpdateAction.java index 4b0c2b97bc2..19bd9342408 100644 --- a/src/main/java/spoon/experimental/modelobs/UpdateAction.java +++ b/src/main/java/spoon/experimental/modelobs/action/UpdateAction.java @@ -14,7 +14,7 @@ * 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.experimental.modelobs; +package spoon.experimental.modelobs.action; import spoon.experimental.modelobs.context.Context; From 069ba331febbe79a824a8a38a2d08d2e66a20a34 Mon Sep 17 00:00:00 2001 From: tdurieux Date: Fri, 23 Jun 2017 16:33:41 +0200 Subject: [PATCH 26/40] refactor: rename --- src/main/java/spoon/compiler/Environment.java | 4 ++-- ...delChangeHandler.java => FineModelChangeListener.java} | 4 ++-- .../spoon/experimental/modelobs/action/AddAction.java | 4 ++-- src/main/java/spoon/reflect/factory/Factory.java | 4 ++-- src/main/java/spoon/reflect/factory/FactoryImpl.java | 4 ++-- src/main/java/spoon/support/StandardEnvironment.java | 8 ++++---- 6 files changed, 14 insertions(+), 14 deletions(-) rename src/main/java/spoon/experimental/modelobs/{FineModelChangeHandler.java => FineModelChangeListener.java} (98%) diff --git a/src/main/java/spoon/compiler/Environment.java b/src/main/java/spoon/compiler/Environment.java index 0872c12de36..e6423439c0f 100644 --- a/src/main/java/spoon/compiler/Environment.java +++ b/src/main/java/spoon/compiler/Environment.java @@ -24,7 +24,7 @@ import spoon.processing.ProcessorProperties; import spoon.reflect.declaration.CtElement; import spoon.reflect.declaration.CtMethod; -import spoon.experimental.modelobs.FineModelChangeHandler; +import spoon.experimental.modelobs.FineModelChangeListener; import spoon.reflect.factory.Factory; /** @@ -332,5 +332,5 @@ void report(Processor processor, Level level, /** Set the directory where binary .class files are created */ String getBinaryOutputDirectory(); - FineModelChangeHandler getModelChangeHandler(); + FineModelChangeListener getModelChangeHandler(); } diff --git a/src/main/java/spoon/experimental/modelobs/FineModelChangeHandler.java b/src/main/java/spoon/experimental/modelobs/FineModelChangeListener.java similarity index 98% rename from src/main/java/spoon/experimental/modelobs/FineModelChangeHandler.java rename to src/main/java/spoon/experimental/modelobs/FineModelChangeListener.java index fbca913201d..20030b1479d 100644 --- a/src/main/java/spoon/experimental/modelobs/FineModelChangeHandler.java +++ b/src/main/java/spoon/experimental/modelobs/FineModelChangeListener.java @@ -38,7 +38,7 @@ /** * is the listener that creates the action on the model */ -public class FineModelChangeHandler { +public class FineModelChangeListener { private final List listeners = new ArrayList<>(2); @@ -123,7 +123,7 @@ public void onSetDelete(CtElement currentElement, CtRole role, Set field, Modifi public void onSetDeleteAll(CtElement currentElement, CtRole role, Set field, Set oldValue) { } - public class ListeningChangeFactory extends FineModelChangeHandler { + public class ListeningChangeFactory extends FineModelChangeListener { @Override public void onObjectUpdate(CtElement currentElement, CtRole role, CtElement newValue, CtElement oldValue) { diff --git a/src/main/java/spoon/experimental/modelobs/action/AddAction.java b/src/main/java/spoon/experimental/modelobs/action/AddAction.java index 1e64d51669a..ba8d40a48ef 100644 --- a/src/main/java/spoon/experimental/modelobs/action/AddAction.java +++ b/src/main/java/spoon/experimental/modelobs/action/AddAction.java @@ -21,9 +21,9 @@ public class AddAction extends Action { private T newValue; - public AddAction(Context context, T newElement) { + public AddAction(Context context, T newValue) { super(context); - this.newValue = newElement; + this.newValue = newValue; } @Override diff --git a/src/main/java/spoon/reflect/factory/Factory.java b/src/main/java/spoon/reflect/factory/Factory.java index c10180f32c5..e612b0a81fd 100644 --- a/src/main/java/spoon/reflect/factory/Factory.java +++ b/src/main/java/spoon/reflect/factory/Factory.java @@ -17,7 +17,7 @@ package spoon.reflect.factory; import spoon.compiler.Environment; -import spoon.experimental.modelobs.FineModelChangeHandler; +import spoon.experimental.modelobs.FineModelChangeListener; import spoon.reflect.CtModel; import spoon.reflect.code.BinaryOperatorKind; import spoon.reflect.code.CtAnnotationFieldAccess; @@ -157,7 +157,7 @@ public interface Factory { QueryFactory Query(); - FineModelChangeHandler Change(); + FineModelChangeListener Change(); /** * @see CodeFactory#createAnnotation(CtTypeReference) diff --git a/src/main/java/spoon/reflect/factory/FactoryImpl.java b/src/main/java/spoon/reflect/factory/FactoryImpl.java index 9bb694e3697..87d25807750 100644 --- a/src/main/java/spoon/reflect/factory/FactoryImpl.java +++ b/src/main/java/spoon/reflect/factory/FactoryImpl.java @@ -17,7 +17,7 @@ package spoon.reflect.factory; import spoon.compiler.Environment; -import spoon.experimental.modelobs.FineModelChangeHandler; +import spoon.experimental.modelobs.FineModelChangeListener; import spoon.reflect.CtModel; import spoon.reflect.CtModelImpl; import spoon.reflect.code.BinaryOperatorKind; @@ -357,7 +357,7 @@ public QueryFactory Query() { * The change sub-factory. */ @Override - public FineModelChangeHandler Change() { + public FineModelChangeListener Change() { return getEnvironment().getModelChangeHandler(); } diff --git a/src/main/java/spoon/support/StandardEnvironment.java b/src/main/java/spoon/support/StandardEnvironment.java index eb2a3ea9be1..9421b5ccd9a 100644 --- a/src/main/java/spoon/support/StandardEnvironment.java +++ b/src/main/java/spoon/support/StandardEnvironment.java @@ -34,7 +34,7 @@ import spoon.reflect.declaration.CtExecutable; import spoon.reflect.declaration.CtType; import spoon.reflect.declaration.ParentNotInitializedException; -import spoon.experimental.modelobs.FineModelChangeHandler; +import spoon.experimental.modelobs.FineModelChangeListener; import spoon.reflect.factory.Factory; import spoon.support.compiler.FileSystemFolder; @@ -86,7 +86,7 @@ public class StandardEnvironment implements Serializable, Environment { private boolean skipSelfChecks; - private FineModelChangeHandler modelChangeHandler = new FineModelChangeHandler(); + private FineModelChangeListener modelChangeHandler = new FineModelChangeListener(); /** * Creates a new environment with a null default file @@ -485,11 +485,11 @@ public String getBinaryOutputDirectory() { } @Override - public FineModelChangeHandler getModelChangeHandler() { + public FineModelChangeListener getModelChangeHandler() { return modelChangeHandler; } - public void setModelChangeHandler(FineModelChangeHandler modelChangeHandler) { + public void setModelChangeHandler(FineModelChangeListener modelChangeHandler) { this.modelChangeHandler = modelChangeHandler; } } From c95ba0f5f8e51a6f4bac15efc3dc0eeb0e14d683 Mon Sep 17 00:00:00 2001 From: tdurieux Date: Fri, 23 Jun 2017 16:36:58 +0200 Subject: [PATCH 27/40] refactor: rename --- src/main/java/spoon/compiler/Environment.java | 2 +- src/main/java/spoon/reflect/factory/FactoryImpl.java | 2 +- src/main/java/spoon/support/StandardEnvironment.java | 10 +++++----- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/spoon/compiler/Environment.java b/src/main/java/spoon/compiler/Environment.java index e6423439c0f..b3a8b80652d 100644 --- a/src/main/java/spoon/compiler/Environment.java +++ b/src/main/java/spoon/compiler/Environment.java @@ -332,5 +332,5 @@ void report(Processor processor, Level level, /** Set the directory where binary .class files are created */ String getBinaryOutputDirectory(); - FineModelChangeListener getModelChangeHandler(); + FineModelChangeListener getModelChangeListener(); } diff --git a/src/main/java/spoon/reflect/factory/FactoryImpl.java b/src/main/java/spoon/reflect/factory/FactoryImpl.java index 87d25807750..33a5f943a0d 100644 --- a/src/main/java/spoon/reflect/factory/FactoryImpl.java +++ b/src/main/java/spoon/reflect/factory/FactoryImpl.java @@ -358,7 +358,7 @@ public QueryFactory Query() { */ @Override public FineModelChangeListener Change() { - return getEnvironment().getModelChangeHandler(); + return getEnvironment().getModelChangeListener(); } /** diff --git a/src/main/java/spoon/support/StandardEnvironment.java b/src/main/java/spoon/support/StandardEnvironment.java index 9421b5ccd9a..8d671efb1f7 100644 --- a/src/main/java/spoon/support/StandardEnvironment.java +++ b/src/main/java/spoon/support/StandardEnvironment.java @@ -86,7 +86,7 @@ public class StandardEnvironment implements Serializable, Environment { private boolean skipSelfChecks; - private FineModelChangeListener modelChangeHandler = new FineModelChangeListener(); + private FineModelChangeListener modelChangeListener = new FineModelChangeListener(); /** * Creates a new environment with a null default file @@ -485,11 +485,11 @@ public String getBinaryOutputDirectory() { } @Override - public FineModelChangeListener getModelChangeHandler() { - return modelChangeHandler; + public FineModelChangeListener getModelChangeListener() { + return modelChangeListener; } - public void setModelChangeHandler(FineModelChangeListener modelChangeHandler) { - this.modelChangeHandler = modelChangeHandler; + public void setModelChangeListener(FineModelChangeListener modelChangeListener) { + this.modelChangeListener = modelChangeListener; } } From 01e3a6527129e17252b050d5ae329fb8cb179717 Mon Sep 17 00:00:00 2001 From: tdurieux Date: Fri, 23 Jun 2017 16:45:04 +0200 Subject: [PATCH 28/40] fix test --- src/test/java/spoon/reflect/ast/AstCheckerTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/test/java/spoon/reflect/ast/AstCheckerTest.java b/src/test/java/spoon/reflect/ast/AstCheckerTest.java index 05724370044..b1e0dbc0183 100644 --- a/src/test/java/spoon/reflect/ast/AstCheckerTest.java +++ b/src/test/java/spoon/reflect/ast/AstCheckerTest.java @@ -2,6 +2,7 @@ import org.junit.Test; import spoon.Launcher; +import spoon.experimental.modelobs.FineModelChangeListener; import spoon.reflect.code.CtBlock; import spoon.reflect.code.CtIf; import spoon.reflect.code.CtInvocation; @@ -208,7 +209,7 @@ private boolean hasPushToStackInvocation(CtBlock body) { return body.getElements(new TypeFilter>(CtInvocation.class) { @Override public boolean matches(CtInvocation element) { - return "ChangeFactory".equals(element.getExecutable().getDeclaringType().getSimpleName()) && super.matches(element); + return FineModelChangeListener.class.getSimpleName().equals(element.getExecutable().getDeclaringType().getSimpleName()) && super.matches(element); } }).size() > 0; } From 9300bd12cc8108ace252b02972cc80c7368e3902 Mon Sep 17 00:00:00 2001 From: tdurieux Date: Sat, 24 Jun 2017 08:18:04 +0200 Subject: [PATCH 29/40] add missing change collector --- src/main/java/spoon/support/reflect/code/CtBlockImpl.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/spoon/support/reflect/code/CtBlockImpl.java b/src/main/java/spoon/support/reflect/code/CtBlockImpl.java index c88baf0a879..01a85c83985 100644 --- a/src/main/java/spoon/support/reflect/code/CtBlockImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtBlockImpl.java @@ -81,6 +81,7 @@ public > T insertBegin(CtStatementList statements) { } for (CtStatement statement : statements.getStatements()) { statement.setParent(this); + getFactory().Change().onListAdd(this, STATEMENT, this.statements, 0, statement); this.statements.add(0, statement); } if (isImplicit() && this.statements.size() > 1) { @@ -104,6 +105,7 @@ public > T insertBegin(CtStatement statement) { } ensureModifiableStatementsList(); statement.setParent(this); + getFactory().Change().onListAdd(this, STATEMENT, this.statements, 0, statement); this.statements.add(0, statement); if (isImplicit() && this.statements.size() > 1) { setImplicit(false); @@ -179,7 +181,7 @@ public T addStatement(CtStatement statement) { } ensureModifiableStatementsList(); statement.setParent(this); - getFactory().Change().onListAdd(this, STATEMENT, this.statements, statement); + getFactory().Change().onListAdd(this, STATEMENT, this.statements, this.statements.size(), statement); this.statements.add(statement); if (isImplicit() && this.statements.size() > 1) { setImplicit(false); From 4ed1bce95741cd7b10c5a3ce30f68b696ae0d649 Mon Sep 17 00:00:00 2001 From: tdurieux Date: Sat, 24 Jun 2017 08:40:16 +0200 Subject: [PATCH 30/40] improve FineModelChangeListener --- src/main/java/spoon/compiler/Environment.java | 8 ++ .../modelobs/FineModelChangeListener.java | 81 +--------------- .../modelobs/ListeningChangeFactory.java | 93 +++++++++++++++++++ .../spoon/support/StandardEnvironment.java | 1 + 4 files changed, 104 insertions(+), 79 deletions(-) create mode 100644 src/main/java/spoon/experimental/modelobs/ListeningChangeFactory.java diff --git a/src/main/java/spoon/compiler/Environment.java b/src/main/java/spoon/compiler/Environment.java index b3a8b80652d..78875061194 100644 --- a/src/main/java/spoon/compiler/Environment.java +++ b/src/main/java/spoon/compiler/Environment.java @@ -332,5 +332,13 @@ void report(Processor processor, Level level, /** Set the directory where binary .class files are created */ String getBinaryOutputDirectory(); + /** + * get the model change listener that is used to follow the change of the AST. + */ FineModelChangeListener getModelChangeListener(); + + /** + * set the model change listener + */ + void setModelChangeListener(FineModelChangeListener modelChangeListener); } diff --git a/src/main/java/spoon/experimental/modelobs/FineModelChangeListener.java b/src/main/java/spoon/experimental/modelobs/FineModelChangeListener.java index 20030b1479d..f769f7b02a7 100644 --- a/src/main/java/spoon/experimental/modelobs/FineModelChangeListener.java +++ b/src/main/java/spoon/experimental/modelobs/FineModelChangeListener.java @@ -21,10 +21,6 @@ import spoon.experimental.modelobs.action.DeleteAction; import spoon.experimental.modelobs.action.DeleteAllAction; import spoon.experimental.modelobs.action.UpdateAction; -import spoon.experimental.modelobs.context.ListContext; -import spoon.experimental.modelobs.context.MapContext; -import spoon.experimental.modelobs.context.ObjectContext; -import spoon.experimental.modelobs.context.SetContext; import spoon.reflect.declaration.CtElement; import spoon.reflect.declaration.ModifierKind; import spoon.reflect.path.CtRole; @@ -36,7 +32,7 @@ import java.util.Set; /** - * is the listener that creates the action on the model + * is the listener that creates the action on the model. This default listener does nothing. */ public class FineModelChangeListener { @@ -50,7 +46,7 @@ public void removeModelChangeListener(final ActionBasedChangeListener listener) listeners.remove(listener); } - private void propagateModelChange(final Action action) { + protected void propagateModelChange(final Action action) { for (ActionBasedChangeListener listener : listeners) { listener.onAction(action); if (action instanceof DeleteAllAction) { @@ -122,77 +118,4 @@ public void onSetDelete(CtElement currentElement, CtRole role, Set field, Modifi public void onSetDeleteAll(CtElement currentElement, CtRole role, Set field, Set oldValue) { } - - public class ListeningChangeFactory extends FineModelChangeListener { - - @Override - public void onObjectUpdate(CtElement currentElement, CtRole role, CtElement newValue, CtElement oldValue) { - propagateModelChange(new UpdateAction<>(new ObjectContext(currentElement, role), newValue, oldValue)); - } - - @Override - public void onObjectUpdate(CtElement currentElement, CtRole role, Object newValue, Object oldValue) { - propagateModelChange(new UpdateAction<>(new ObjectContext(currentElement, role), newValue, oldValue)); - } - - @Override - public void onObjectDelete(CtElement currentElement, CtRole role, CtElement oldValue) { - propagateModelChange(new DeleteAction<>(new ObjectContext(currentElement, role), oldValue)); - } - - @Override - public void onListAdd(CtElement currentElement, CtRole role, List field, CtElement newValue) { - propagateModelChange(new AddAction<>(new ListContext(currentElement, role, field), newValue)); - } - - @Override - public void onListAdd(CtElement currentElement, CtRole role, List field, int index, CtElement newValue) { - propagateModelChange(new AddAction<>(new ListContext(currentElement, role, field, index), newValue)); - } - - @Override - public void onListDelete(CtElement currentElement, CtRole role, List field, int index, CtElement oldValue) { - propagateModelChange(new DeleteAction<>(new ListContext(currentElement, role, field, index), oldValue)); - } - - @Override - public void onListDeleteAll(CtElement currentElement, CtRole role, List field, List oldValue) { - propagateModelChange(new DeleteAllAction(new ListContext(currentElement, role, field), oldValue)); - } - - @Override - public void onMapAdd(CtElement currentElement, CtRole role, Map field, K key, CtElement newValue) { - propagateModelChange(new AddAction<>(new MapContext<>(currentElement, role, field, key), newValue)); - } - - @Override - public void onMapDeleteAll(CtElement currentElement, CtRole role, Map field, Map oldValue) { - propagateModelChange(new DeleteAllAction(new MapContext<>(currentElement, role, field), oldValue)); - } - - @Override - public void onSetAdd(CtElement currentElement, CtRole role, Set field, CtElement newValue) { - propagateModelChange(new AddAction<>(new SetContext(currentElement, role, field), newValue)); - } - - @Override - public void onSetAdd(CtElement currentElement, CtRole role, Set field, ModifierKind newValue) { - propagateModelChange(new AddAction<>(new SetContext(currentElement, role, field), newValue)); - } - - @Override - public void onSetDelete(CtElement currentElement, CtRole role, Set field, CtElement oldValue) { - propagateModelChange(new DeleteAction<>(new SetContext(currentElement, role, field), oldValue)); - } - - @Override - public void onSetDelete(CtElement currentElement, CtRole role, Set field, ModifierKind oldValue) { - propagateModelChange(new DeleteAction<>(new SetContext(currentElement, role, field), oldValue)); - } - - @Override - public void onSetDeleteAll(CtElement currentElement, CtRole role, Set field, Set oldValue) { - propagateModelChange(new DeleteAllAction(new SetContext(currentElement, role, field), oldValue)); - } - } } diff --git a/src/main/java/spoon/experimental/modelobs/ListeningChangeFactory.java b/src/main/java/spoon/experimental/modelobs/ListeningChangeFactory.java new file mode 100644 index 00000000000..b80b3924ff7 --- /dev/null +++ b/src/main/java/spoon/experimental/modelobs/ListeningChangeFactory.java @@ -0,0 +1,93 @@ +package spoon.experimental.modelobs; + +import spoon.experimental.modelobs.action.AddAction; +import spoon.experimental.modelobs.action.DeleteAction; +import spoon.experimental.modelobs.action.DeleteAllAction; +import spoon.experimental.modelobs.action.UpdateAction; +import spoon.experimental.modelobs.context.ListContext; +import spoon.experimental.modelobs.context.MapContext; +import spoon.experimental.modelobs.context.ObjectContext; +import spoon.experimental.modelobs.context.SetContext; +import spoon.reflect.declaration.CtElement; +import spoon.reflect.declaration.ModifierKind; +import spoon.reflect.path.CtRole; + +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** + * This listener will propagate the change to the listener + */ +public class ListeningChangeFactory extends FineModelChangeListener { + + @Override + public void onObjectUpdate(CtElement currentElement, CtRole role, CtElement newValue, CtElement oldValue) { + propagateModelChange(new UpdateAction<>(new ObjectContext(currentElement, role), newValue, oldValue)); + } + + @Override + public void onObjectUpdate(CtElement currentElement, CtRole role, Object newValue, Object oldValue) { + propagateModelChange(new UpdateAction<>(new ObjectContext(currentElement, role), newValue, oldValue)); + } + + @Override + public void onObjectDelete(CtElement currentElement, CtRole role, CtElement oldValue) { + propagateModelChange(new DeleteAction<>(new ObjectContext(currentElement, role), oldValue)); + } + + @Override + public void onListAdd(CtElement currentElement, CtRole role, List field, CtElement newValue) { + propagateModelChange(new AddAction<>(new ListContext(currentElement, role, field), newValue)); + } + + @Override + public void onListAdd(CtElement currentElement, CtRole role, List field, int index, CtElement newValue) { + propagateModelChange(new AddAction<>(new ListContext(currentElement, role, field, index), newValue)); + } + + @Override + public void onListDelete(CtElement currentElement, CtRole role, List field, int index, CtElement oldValue) { + propagateModelChange(new DeleteAction<>(new ListContext(currentElement, role, field, index), oldValue)); + } + + @Override + public void onListDeleteAll(CtElement currentElement, CtRole role, List field, List oldValue) { + propagateModelChange(new DeleteAllAction(new ListContext(currentElement, role, field), oldValue)); + } + + @Override + public void onMapAdd(CtElement currentElement, CtRole role, Map field, K key, CtElement newValue) { + propagateModelChange(new AddAction<>(new MapContext<>(currentElement, role, field, key), newValue)); + } + + @Override + public void onMapDeleteAll(CtElement currentElement, CtRole role, Map field, Map oldValue) { + propagateModelChange(new DeleteAllAction(new MapContext<>(currentElement, role, field), oldValue)); + } + + @Override + public void onSetAdd(CtElement currentElement, CtRole role, Set field, CtElement newValue) { + propagateModelChange(new AddAction<>(new SetContext(currentElement, role, field), newValue)); + } + + @Override + public void onSetAdd(CtElement currentElement, CtRole role, Set field, ModifierKind newValue) { + propagateModelChange(new AddAction<>(new SetContext(currentElement, role, field), newValue)); + } + + @Override + public void onSetDelete(CtElement currentElement, CtRole role, Set field, CtElement oldValue) { + propagateModelChange(new DeleteAction<>(new SetContext(currentElement, role, field), oldValue)); + } + + @Override + public void onSetDelete(CtElement currentElement, CtRole role, Set field, ModifierKind oldValue) { + propagateModelChange(new DeleteAction<>(new SetContext(currentElement, role, field), oldValue)); + } + + @Override + public void onSetDeleteAll(CtElement currentElement, CtRole role, Set field, Set oldValue) { + propagateModelChange(new DeleteAllAction(new SetContext(currentElement, role, field), oldValue)); + } + } \ No newline at end of file diff --git a/src/main/java/spoon/support/StandardEnvironment.java b/src/main/java/spoon/support/StandardEnvironment.java index 8d671efb1f7..d31aa8c559e 100644 --- a/src/main/java/spoon/support/StandardEnvironment.java +++ b/src/main/java/spoon/support/StandardEnvironment.java @@ -489,6 +489,7 @@ public FineModelChangeListener getModelChangeListener() { return modelChangeListener; } + @Override public void setModelChangeListener(FineModelChangeListener modelChangeListener) { this.modelChangeListener = modelChangeListener; } From 18b5f1b9cb8f9ae66f90e13cb8ec6d679e43ae31 Mon Sep 17 00:00:00 2001 From: tdurieux Date: Sat, 24 Jun 2017 09:10:04 +0200 Subject: [PATCH 31/40] fix chackstyle --- .../modelobs/ListeningChangeFactory.java | 156 ++++++++++-------- 1 file changed, 86 insertions(+), 70 deletions(-) diff --git a/src/main/java/spoon/experimental/modelobs/ListeningChangeFactory.java b/src/main/java/spoon/experimental/modelobs/ListeningChangeFactory.java index b80b3924ff7..c8d20cdc033 100644 --- a/src/main/java/spoon/experimental/modelobs/ListeningChangeFactory.java +++ b/src/main/java/spoon/experimental/modelobs/ListeningChangeFactory.java @@ -1,3 +1,19 @@ +/** + * Copyright (C) 2006-2017 INRIA and contributors + * Spoon - http://spoon.gforge.inria.fr/ + * + * This software is governed by the CeCILL-C License under French law and + * abiding by the rules of distribution of free software. You can use, modify + * and/or redistribute the software under the terms of the CeCILL-C license as + * circulated by CEA, CNRS and INRIA at http://www.cecill.info. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the CeCILL-C License for more details. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL-C license and that you accept its terms. + */ package spoon.experimental.modelobs; import spoon.experimental.modelobs.action.AddAction; @@ -21,73 +37,73 @@ */ public class ListeningChangeFactory extends FineModelChangeListener { - @Override - public void onObjectUpdate(CtElement currentElement, CtRole role, CtElement newValue, CtElement oldValue) { - propagateModelChange(new UpdateAction<>(new ObjectContext(currentElement, role), newValue, oldValue)); - } - - @Override - public void onObjectUpdate(CtElement currentElement, CtRole role, Object newValue, Object oldValue) { - propagateModelChange(new UpdateAction<>(new ObjectContext(currentElement, role), newValue, oldValue)); - } - - @Override - public void onObjectDelete(CtElement currentElement, CtRole role, CtElement oldValue) { - propagateModelChange(new DeleteAction<>(new ObjectContext(currentElement, role), oldValue)); - } - - @Override - public void onListAdd(CtElement currentElement, CtRole role, List field, CtElement newValue) { - propagateModelChange(new AddAction<>(new ListContext(currentElement, role, field), newValue)); - } - - @Override - public void onListAdd(CtElement currentElement, CtRole role, List field, int index, CtElement newValue) { - propagateModelChange(new AddAction<>(new ListContext(currentElement, role, field, index), newValue)); - } - - @Override - public void onListDelete(CtElement currentElement, CtRole role, List field, int index, CtElement oldValue) { - propagateModelChange(new DeleteAction<>(new ListContext(currentElement, role, field, index), oldValue)); - } - - @Override - public void onListDeleteAll(CtElement currentElement, CtRole role, List field, List oldValue) { - propagateModelChange(new DeleteAllAction(new ListContext(currentElement, role, field), oldValue)); - } - - @Override - public void onMapAdd(CtElement currentElement, CtRole role, Map field, K key, CtElement newValue) { - propagateModelChange(new AddAction<>(new MapContext<>(currentElement, role, field, key), newValue)); - } - - @Override - public void onMapDeleteAll(CtElement currentElement, CtRole role, Map field, Map oldValue) { - propagateModelChange(new DeleteAllAction(new MapContext<>(currentElement, role, field), oldValue)); - } - - @Override - public void onSetAdd(CtElement currentElement, CtRole role, Set field, CtElement newValue) { - propagateModelChange(new AddAction<>(new SetContext(currentElement, role, field), newValue)); - } - - @Override - public void onSetAdd(CtElement currentElement, CtRole role, Set field, ModifierKind newValue) { - propagateModelChange(new AddAction<>(new SetContext(currentElement, role, field), newValue)); - } - - @Override - public void onSetDelete(CtElement currentElement, CtRole role, Set field, CtElement oldValue) { - propagateModelChange(new DeleteAction<>(new SetContext(currentElement, role, field), oldValue)); - } - - @Override - public void onSetDelete(CtElement currentElement, CtRole role, Set field, ModifierKind oldValue) { - propagateModelChange(new DeleteAction<>(new SetContext(currentElement, role, field), oldValue)); - } - - @Override - public void onSetDeleteAll(CtElement currentElement, CtRole role, Set field, Set oldValue) { - propagateModelChange(new DeleteAllAction(new SetContext(currentElement, role, field), oldValue)); - } - } \ No newline at end of file + @Override + public void onObjectUpdate(CtElement currentElement, CtRole role, CtElement newValue, CtElement oldValue) { + propagateModelChange(new UpdateAction<>(new ObjectContext(currentElement, role), newValue, oldValue)); + } + + @Override + public void onObjectUpdate(CtElement currentElement, CtRole role, Object newValue, Object oldValue) { + propagateModelChange(new UpdateAction<>(new ObjectContext(currentElement, role), newValue, oldValue)); + } + + @Override + public void onObjectDelete(CtElement currentElement, CtRole role, CtElement oldValue) { + propagateModelChange(new DeleteAction<>(new ObjectContext(currentElement, role), oldValue)); + } + + @Override + public void onListAdd(CtElement currentElement, CtRole role, List field, CtElement newValue) { + propagateModelChange(new AddAction<>(new ListContext(currentElement, role, field), newValue)); + } + + @Override + public void onListAdd(CtElement currentElement, CtRole role, List field, int index, CtElement newValue) { + propagateModelChange(new AddAction<>(new ListContext(currentElement, role, field, index), newValue)); + } + + @Override + public void onListDelete(CtElement currentElement, CtRole role, List field, int index, CtElement oldValue) { + propagateModelChange(new DeleteAction<>(new ListContext(currentElement, role, field, index), oldValue)); + } + + @Override + public void onListDeleteAll(CtElement currentElement, CtRole role, List field, List oldValue) { + propagateModelChange(new DeleteAllAction(new ListContext(currentElement, role, field), oldValue)); + } + + @Override + public void onMapAdd(CtElement currentElement, CtRole role, Map field, K key, CtElement newValue) { + propagateModelChange(new AddAction<>(new MapContext<>(currentElement, role, field, key), newValue)); + } + + @Override + public void onMapDeleteAll(CtElement currentElement, CtRole role, Map field, Map oldValue) { + propagateModelChange(new DeleteAllAction(new MapContext<>(currentElement, role, field), oldValue)); + } + + @Override + public void onSetAdd(CtElement currentElement, CtRole role, Set field, CtElement newValue) { + propagateModelChange(new AddAction<>(new SetContext(currentElement, role, field), newValue)); + } + + @Override + public void onSetAdd(CtElement currentElement, CtRole role, Set field, ModifierKind newValue) { + propagateModelChange(new AddAction<>(new SetContext(currentElement, role, field), newValue)); + } + + @Override + public void onSetDelete(CtElement currentElement, CtRole role, Set field, CtElement oldValue) { + propagateModelChange(new DeleteAction<>(new SetContext(currentElement, role, field), oldValue)); + } + + @Override + public void onSetDelete(CtElement currentElement, CtRole role, Set field, ModifierKind oldValue) { + propagateModelChange(new DeleteAction<>(new SetContext(currentElement, role, field), oldValue)); + } + + @Override + public void onSetDeleteAll(CtElement currentElement, CtRole role, Set field, Set oldValue) { + propagateModelChange(new DeleteAllAction(new SetContext(currentElement, role, field), oldValue)); + } +} From f3d2325858d7a33ad5d50b1b9a0ec73c0c5be6c6 Mon Sep 17 00:00:00 2001 From: tdurieux Date: Sat, 24 Jun 2017 09:11:34 +0200 Subject: [PATCH 32/40] move the actionbasedchangelistener to ListeningChangeFactory --- .../modelobs/FineModelChangeListener.java | 31 ------------------- .../modelobs/ListeningChangeFactory.java | 27 ++++++++++++++++ 2 files changed, 27 insertions(+), 31 deletions(-) diff --git a/src/main/java/spoon/experimental/modelobs/FineModelChangeListener.java b/src/main/java/spoon/experimental/modelobs/FineModelChangeListener.java index f769f7b02a7..248f0f6b9c6 100644 --- a/src/main/java/spoon/experimental/modelobs/FineModelChangeListener.java +++ b/src/main/java/spoon/experimental/modelobs/FineModelChangeListener.java @@ -16,16 +16,10 @@ */ package spoon.experimental.modelobs; -import spoon.experimental.modelobs.action.Action; -import spoon.experimental.modelobs.action.AddAction; -import spoon.experimental.modelobs.action.DeleteAction; -import spoon.experimental.modelobs.action.DeleteAllAction; -import spoon.experimental.modelobs.action.UpdateAction; import spoon.reflect.declaration.CtElement; import spoon.reflect.declaration.ModifierKind; import spoon.reflect.path.CtRole; -import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.Map; @@ -36,31 +30,6 @@ */ public class FineModelChangeListener { - private final List listeners = new ArrayList<>(2); - - public void addModelChangeListener(final ActionBasedChangeListener listener) { - listeners.add(listener); - } - - public void removeModelChangeListener(final ActionBasedChangeListener listener) { - listeners.remove(listener); - } - - protected void propagateModelChange(final Action action) { - for (ActionBasedChangeListener listener : listeners) { - listener.onAction(action); - if (action instanceof DeleteAllAction) { - listener.onDeleteAll((DeleteAllAction) action); - } else if (action instanceof DeleteAction) { - listener.onDelete((DeleteAction) action); - } else if (action instanceof AddAction) { - listener.onAdd((AddAction) action); - } else if (action instanceof UpdateAction) { - listener.onUpdate((UpdateAction) action); - } - } - } - public void onObjectUpdate(CtElement currentElement, CtRole role, CtElement newValue, CtElement oldValue) { } diff --git a/src/main/java/spoon/experimental/modelobs/ListeningChangeFactory.java b/src/main/java/spoon/experimental/modelobs/ListeningChangeFactory.java index c8d20cdc033..1e19ce41731 100644 --- a/src/main/java/spoon/experimental/modelobs/ListeningChangeFactory.java +++ b/src/main/java/spoon/experimental/modelobs/ListeningChangeFactory.java @@ -16,6 +16,7 @@ */ package spoon.experimental.modelobs; +import spoon.experimental.modelobs.action.Action; import spoon.experimental.modelobs.action.AddAction; import spoon.experimental.modelobs.action.DeleteAction; import spoon.experimental.modelobs.action.DeleteAllAction; @@ -28,6 +29,7 @@ import spoon.reflect.declaration.ModifierKind; import spoon.reflect.path.CtRole; +import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Set; @@ -37,6 +39,31 @@ */ public class ListeningChangeFactory extends FineModelChangeListener { + private final List listeners = new ArrayList<>(2); + + public void addModelChangeListener(final ActionBasedChangeListener listener) { + listeners.add(listener); + } + + public void removeModelChangeListener(final ActionBasedChangeListener listener) { + listeners.remove(listener); + } + + private void propagateModelChange(final Action action) { + for (ActionBasedChangeListener listener : listeners) { + listener.onAction(action); + if (action instanceof DeleteAllAction) { + listener.onDeleteAll((DeleteAllAction) action); + } else if (action instanceof DeleteAction) { + listener.onDelete((DeleteAction) action); + } else if (action instanceof AddAction) { + listener.onAdd((AddAction) action); + } else if (action instanceof UpdateAction) { + listener.onUpdate((UpdateAction) action); + } + } + } + @Override public void onObjectUpdate(CtElement currentElement, CtRole role, CtElement newValue, CtElement oldValue) { propagateModelChange(new UpdateAction<>(new ObjectContext(currentElement, role), newValue, oldValue)); From 61253dce33f9360d8c83e3f8ca2ebd1e19e32909 Mon Sep 17 00:00:00 2001 From: tdurieux Date: Mon, 26 Jun 2017 15:35:21 +0200 Subject: [PATCH 33/40] refactor ListeningChangeFactory --- .../{ListeningChangeFactory.java => ModelChangePropagator.java} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename src/main/java/spoon/experimental/modelobs/{ListeningChangeFactory.java => ModelChangePropagator.java} (98%) diff --git a/src/main/java/spoon/experimental/modelobs/ListeningChangeFactory.java b/src/main/java/spoon/experimental/modelobs/ModelChangePropagator.java similarity index 98% rename from src/main/java/spoon/experimental/modelobs/ListeningChangeFactory.java rename to src/main/java/spoon/experimental/modelobs/ModelChangePropagator.java index 1e19ce41731..b1cbe5191b8 100644 --- a/src/main/java/spoon/experimental/modelobs/ListeningChangeFactory.java +++ b/src/main/java/spoon/experimental/modelobs/ModelChangePropagator.java @@ -37,7 +37,7 @@ /** * This listener will propagate the change to the listener */ -public class ListeningChangeFactory extends FineModelChangeListener { +public class ModelChangePropagator extends FineModelChangeListener { private final List listeners = new ArrayList<>(2); From 6c938541fa937973b2101833210901caa04e8127 Mon Sep 17 00:00:00 2001 From: tdurieux Date: Mon, 26 Jun 2017 15:52:53 +0200 Subject: [PATCH 34/40] refactor ModelChangePropagator --- .../AbstractActionBasedChangeListener.java | 49 ----------------- .../modelobs/ModelChangePropagator.java | 53 +++++++++++-------- 2 files changed, 30 insertions(+), 72 deletions(-) delete mode 100644 src/main/java/spoon/experimental/modelobs/AbstractActionBasedChangeListener.java diff --git a/src/main/java/spoon/experimental/modelobs/AbstractActionBasedChangeListener.java b/src/main/java/spoon/experimental/modelobs/AbstractActionBasedChangeListener.java deleted file mode 100644 index d8c4232aa80..00000000000 --- a/src/main/java/spoon/experimental/modelobs/AbstractActionBasedChangeListener.java +++ /dev/null @@ -1,49 +0,0 @@ -/** - * Copyright (C) 2006-2017 INRIA and contributors - * Spoon - http://spoon.gforge.inria.fr/ - * - * This software is governed by the CeCILL-C License under French law and - * abiding by the rules of distribution of free software. You can use, modify - * and/or redistribute the software under the terms of the CeCILL-C license as - * circulated by CEA, CNRS and INRIA at http://www.cecill.info. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the CeCILL-C License for more details. - * - * The fact that you are presently reading this means that you have had - * knowledge of the CeCILL-C license and that you accept its terms. - */ -package spoon.experimental.modelobs; - -import spoon.experimental.modelobs.action.Action; -import spoon.experimental.modelobs.action.AddAction; -import spoon.experimental.modelobs.action.DeleteAction; -import spoon.experimental.modelobs.action.DeleteAllAction; -import spoon.experimental.modelobs.action.UpdateAction; - -/** - * abstract implementation of the ModelChangeListener - */ -public abstract class AbstractActionBasedChangeListener - implements ActionBasedChangeListener { - @Override - public void onDelete(DeleteAction action) { - } - - @Override - public void onDeleteAll(DeleteAllAction action) { - } - - @Override - public void onAdd(AddAction action) { - } - - @Override - public void onUpdate(UpdateAction action) { - } - - @Override - public void onAction(Action action) { - } -} diff --git a/src/main/java/spoon/experimental/modelobs/ModelChangePropagator.java b/src/main/java/spoon/experimental/modelobs/ModelChangePropagator.java index b1cbe5191b8..e7b3e81ce9f 100644 --- a/src/main/java/spoon/experimental/modelobs/ModelChangePropagator.java +++ b/src/main/java/spoon/experimental/modelobs/ModelChangePropagator.java @@ -29,7 +29,6 @@ import spoon.reflect.declaration.ModifierKind; import spoon.reflect.path.CtRole; -import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Set; @@ -37,30 +36,18 @@ /** * This listener will propagate the change to the listener */ -public class ModelChangePropagator extends FineModelChangeListener { - - private final List listeners = new ArrayList<>(2); - - public void addModelChangeListener(final ActionBasedChangeListener listener) { - listeners.add(listener); - } - - public void removeModelChangeListener(final ActionBasedChangeListener listener) { - listeners.remove(listener); - } +public abstract class ModelChangePropagator extends FineModelChangeListener implements ActionBasedChangeListener{ private void propagateModelChange(final Action action) { - for (ActionBasedChangeListener listener : listeners) { - listener.onAction(action); - if (action instanceof DeleteAllAction) { - listener.onDeleteAll((DeleteAllAction) action); - } else if (action instanceof DeleteAction) { - listener.onDelete((DeleteAction) action); - } else if (action instanceof AddAction) { - listener.onAdd((AddAction) action); - } else if (action instanceof UpdateAction) { - listener.onUpdate((UpdateAction) action); - } + this.onAction(action); + if (action instanceof DeleteAllAction) { + this.onDeleteAll((DeleteAllAction) action); + } else if (action instanceof DeleteAction) { + this.onDelete((DeleteAction) action); + } else if (action instanceof AddAction) { + this.onAdd((AddAction) action); + } else if (action instanceof UpdateAction) { + this.onUpdate((UpdateAction) action); } } @@ -133,4 +120,24 @@ public void onSetDelete(CtElement currentElement, CtRole role, Set field, Modifi public void onSetDeleteAll(CtElement currentElement, CtRole role, Set field, Set oldValue) { propagateModelChange(new DeleteAllAction(new SetContext(currentElement, role, field), oldValue)); } + + @Override + public void onDelete(DeleteAction action) { + } + + @Override + public void onDeleteAll(DeleteAllAction action) { + } + + @Override + public void onAdd(AddAction action) { + } + + @Override + public void onUpdate(UpdateAction action) { + } + + @Override + public void onAction(Action action) { + } } From 37df2eb5e38611d8991afad6e91dbc3ae553f021 Mon Sep 17 00:00:00 2001 From: tdurieux Date: Mon, 26 Jun 2017 15:57:27 +0200 Subject: [PATCH 35/40] change the name to ActionBasedChangeListenerImpl --- ...ChangePropagator.java => ActionBasedChangeListenerImpl.java} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename src/main/java/spoon/experimental/modelobs/{ModelChangePropagator.java => ActionBasedChangeListenerImpl.java} (97%) diff --git a/src/main/java/spoon/experimental/modelobs/ModelChangePropagator.java b/src/main/java/spoon/experimental/modelobs/ActionBasedChangeListenerImpl.java similarity index 97% rename from src/main/java/spoon/experimental/modelobs/ModelChangePropagator.java rename to src/main/java/spoon/experimental/modelobs/ActionBasedChangeListenerImpl.java index e7b3e81ce9f..70ccbc8bcf5 100644 --- a/src/main/java/spoon/experimental/modelobs/ModelChangePropagator.java +++ b/src/main/java/spoon/experimental/modelobs/ActionBasedChangeListenerImpl.java @@ -36,7 +36,7 @@ /** * This listener will propagate the change to the listener */ -public abstract class ModelChangePropagator extends FineModelChangeListener implements ActionBasedChangeListener{ +public abstract class ActionBasedChangeListenerImpl extends FineModelChangeListener implements ActionBasedChangeListener { private void propagateModelChange(final Action action) { this.onAction(action); From bd6ddd80448cfcb20fabf32d3299f8c2204c3e39 Mon Sep 17 00:00:00 2001 From: tdurieux Date: Mon, 26 Jun 2017 17:32:50 +0200 Subject: [PATCH 36/40] remove addArgument(int i, ...) --- src/main/java/spoon/generating/CtBiScannerGenerator.java | 6 +++--- src/main/java/spoon/reflect/code/CtAbstractInvocation.java | 5 ----- .../spoon/support/reflect/code/CtConstructorCallImpl.java | 3 +-- .../java/spoon/support/reflect/code/CtInvocationImpl.java | 3 +-- 4 files changed, 5 insertions(+), 12 deletions(-) diff --git a/src/main/java/spoon/generating/CtBiScannerGenerator.java b/src/main/java/spoon/generating/CtBiScannerGenerator.java index 80d3c18e8d2..4954b5752a9 100644 --- a/src/main/java/spoon/generating/CtBiScannerGenerator.java +++ b/src/main/java/spoon/generating/CtBiScannerGenerator.java @@ -74,7 +74,7 @@ public void process() { clone.getBody().getStatement(i--).delete(); continue; } - CtInvocation replace = (CtInvocation) factory.Core().clone(clone.getBody().getStatement(i)); + CtInvocation replace = factory.Core().clone(clone.getBody().getStatement(i)); // Changes to biScan method. replace.getExecutable().setSimpleName("biScan"); @@ -85,8 +85,8 @@ public void process() { if ("Map".equals(targetInvocation.getExecutable().getType().getSimpleName())) { ((CtExpression) replace.getArguments().get(0)).replace(factory.Code().createInvocation(targetInvocation, factory.Executable().createReference("List Map#values()"))); - replace.addArgument(1, factory.Code().createInvocation((CtExpression) replace.getArguments().get(1), factory.Executable().createReference("List Map#values()"))); - replace.removeArgument((CtExpression) replace.getArguments().get(2)); + CtInvocation invocation = factory.Code().createInvocation(replace.getArguments().get(1).clone(), factory.Executable().createReference("List Map#values()")); + replace.getArguments().get(1).replace(invocation); } clone.getBody().getStatement(i).replace(replace); diff --git a/src/main/java/spoon/reflect/code/CtAbstractInvocation.java b/src/main/java/spoon/reflect/code/CtAbstractInvocation.java index fd8936fcb35..7e4420e6ee7 100644 --- a/src/main/java/spoon/reflect/code/CtAbstractInvocation.java +++ b/src/main/java/spoon/reflect/code/CtAbstractInvocation.java @@ -48,11 +48,6 @@ public interface CtAbstractInvocation extends CtElement { @PropertySetter(role = ARGUMENT) > C addArgument(CtExpression argument); - /** - * Adds an argument expression to the invocation at a position. - */ - > C addArgument(int position, CtExpression argument); - /** * Removes an argument expression from the invocation. */ diff --git a/src/main/java/spoon/support/reflect/code/CtConstructorCallImpl.java b/src/main/java/spoon/support/reflect/code/CtConstructorCallImpl.java index d3c20246e0b..81f44fccea1 100644 --- a/src/main/java/spoon/support/reflect/code/CtConstructorCallImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtConstructorCallImpl.java @@ -114,8 +114,7 @@ public > C setArguments(List> return (C) this; } - @Override - public > C addArgument(int position, CtExpression argument) { + private > C addArgument(int position, CtExpression argument) { if (argument == null) { return (C) this; } diff --git a/src/main/java/spoon/support/reflect/code/CtInvocationImpl.java b/src/main/java/spoon/support/reflect/code/CtInvocationImpl.java index c06e0671b4e..a2e6ac38d8b 100644 --- a/src/main/java/spoon/support/reflect/code/CtInvocationImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtInvocationImpl.java @@ -62,8 +62,7 @@ public List> getArguments() { return arguments; } - @Override - public > C addArgument(int position, CtExpression argument) { + private > C addArgument(int position, CtExpression argument) { if (argument == null) { return (C) this; } From 7f98f192dffa22b7308144730b90026af4a1b3ca Mon Sep 17 00:00:00 2001 From: tdurieux Date: Mon, 26 Jun 2017 17:34:40 +0200 Subject: [PATCH 37/40] change boolean to void with removeXXX method --- src/main/java/spoon/reflect/code/CtAbstractInvocation.java | 2 +- src/main/java/spoon/reflect/declaration/CtPackage.java | 2 +- .../spoon/support/reflect/code/CtConstructorCallImpl.java | 6 +++--- .../java/spoon/support/reflect/code/CtInvocationImpl.java | 6 +++--- .../spoon/support/reflect/declaration/CtPackageImpl.java | 6 +++--- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/main/java/spoon/reflect/code/CtAbstractInvocation.java b/src/main/java/spoon/reflect/code/CtAbstractInvocation.java index 7e4420e6ee7..d2b24fc45b6 100644 --- a/src/main/java/spoon/reflect/code/CtAbstractInvocation.java +++ b/src/main/java/spoon/reflect/code/CtAbstractInvocation.java @@ -52,7 +52,7 @@ public interface CtAbstractInvocation extends CtElement { * Removes an argument expression from the invocation. */ @PropertySetter(role = ARGUMENT) - boolean removeArgument(CtExpression argument); + void removeArgument(CtExpression argument); /** * Sets the invocation's arguments. diff --git a/src/main/java/spoon/reflect/declaration/CtPackage.java b/src/main/java/spoon/reflect/declaration/CtPackage.java index d9d189c4bb6..d45c3ebca70 100644 --- a/src/main/java/spoon/reflect/declaration/CtPackage.java +++ b/src/main/java/spoon/reflect/declaration/CtPackage.java @@ -104,7 +104,7 @@ public interface CtPackage extends CtNamedElement, CtShadowable { * Removes a type from this package. */ @PropertySetter(role = TYPE) - boolean removeType(CtType type); + void removeType(CtType type); /** * Sets the children defined in this package diff --git a/src/main/java/spoon/support/reflect/code/CtConstructorCallImpl.java b/src/main/java/spoon/support/reflect/code/CtConstructorCallImpl.java index 81f44fccea1..24e4befc39f 100644 --- a/src/main/java/spoon/support/reflect/code/CtConstructorCallImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtConstructorCallImpl.java @@ -133,12 +133,12 @@ public > C addArgument(CtExpression argumen } @Override - public boolean removeArgument(CtExpression argument) { + public void removeArgument(CtExpression argument) { if (arguments == CtElementImpl.>emptyList()) { - return false; + return; } getFactory().Change().onListDelete(this, ARGUMENT, arguments, arguments.indexOf(argument), argument); - return arguments.remove(argument); + arguments.remove(argument); } @Override diff --git a/src/main/java/spoon/support/reflect/code/CtInvocationImpl.java b/src/main/java/spoon/support/reflect/code/CtInvocationImpl.java index a2e6ac38d8b..b46dd365969 100644 --- a/src/main/java/spoon/support/reflect/code/CtInvocationImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtInvocationImpl.java @@ -81,12 +81,12 @@ public > C addArgument(CtExpression argumen } @Override - public boolean removeArgument(CtExpression argument) { + public void removeArgument(CtExpression argument) { if (arguments == CtElementImpl.>emptyList()) { - return false; + return; } getFactory().Change().onListDelete(this, ARGUMENT, arguments, arguments.indexOf(argument), argument); - return arguments.remove(argument); + arguments.remove(argument); } @Override diff --git a/src/main/java/spoon/support/reflect/declaration/CtPackageImpl.java b/src/main/java/spoon/support/reflect/declaration/CtPackageImpl.java index 3d36b4d9530..bb2c85770fc 100644 --- a/src/main/java/spoon/support/reflect/declaration/CtPackageImpl.java +++ b/src/main/java/spoon/support/reflect/declaration/CtPackageImpl.java @@ -221,12 +221,12 @@ public T addType(CtType type) { } @Override - public boolean removeType(CtType type) { + public void removeType(CtType type) { if (types == CtElementImpl.>emptySet()) { - return false; + return; } getFactory().Change().onSetDelete(this, TYPE, types, type); - return types.remove(type); + types.remove(type); } @Override From 014ef0547b238d7b8651621b1015716cb2ff1e8e Mon Sep 17 00:00:00 2001 From: tdurieux Date: Mon, 26 Jun 2017 17:37:28 +0200 Subject: [PATCH 38/40] fix compilation issue --- src/main/java/spoon/generating/CtBiScannerGenerator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/spoon/generating/CtBiScannerGenerator.java b/src/main/java/spoon/generating/CtBiScannerGenerator.java index 4954b5752a9..cd483c2302c 100644 --- a/src/main/java/spoon/generating/CtBiScannerGenerator.java +++ b/src/main/java/spoon/generating/CtBiScannerGenerator.java @@ -74,7 +74,7 @@ public void process() { clone.getBody().getStatement(i--).delete(); continue; } - CtInvocation replace = factory.Core().clone(clone.getBody().getStatement(i)); + CtInvocation replace = (CtInvocation) clone.getBody().getStatement(i).clone(); // Changes to biScan method. replace.getExecutable().setSimpleName("biScan"); From 86c80bb31654a4b1caec7ce27ae3102bb6ae7fda Mon Sep 17 00:00:00 2001 From: tdurieux Date: Tue, 27 Jun 2017 10:10:21 +0200 Subject: [PATCH 39/40] change the entry point for the model change listener --- .../java/spoon/reflect/factory/Factory.java | 3 -- .../spoon/reflect/factory/FactoryImpl.java | 8 ----- .../reflect/code/CtArrayAccessImpl.java | 2 +- .../support/reflect/code/CtAssertImpl.java | 4 +-- .../reflect/code/CtAssignmentImpl.java | 10 +++--- .../reflect/code/CtBinaryOperatorImpl.java | 6 ++-- .../support/reflect/code/CtBlockImpl.java | 12 +++---- .../support/reflect/code/CtBreakImpl.java | 2 +- .../support/reflect/code/CtCaseImpl.java | 8 ++--- .../support/reflect/code/CtCatchImpl.java | 6 ++-- .../reflect/code/CtCatchVariableImpl.java | 16 +++++----- .../code/CtCodeSnippetExpressionImpl.java | 2 +- .../code/CtCodeSnippetStatementImpl.java | 2 +- .../support/reflect/code/CtCommentImpl.java | 4 +-- .../reflect/code/CtConditionalImpl.java | 6 ++-- .../reflect/code/CtConstructorCallImpl.java | 10 +++--- .../support/reflect/code/CtContinueImpl.java | 2 +- .../spoon/support/reflect/code/CtDoImpl.java | 2 +- .../CtExecutableReferenceExpressionImpl.java | 2 +- .../reflect/code/CtExpressionImpl.java | 6 ++-- .../reflect/code/CtFieldAccessImpl.java | 2 +- .../support/reflect/code/CtForEachImpl.java | 4 +-- .../spoon/support/reflect/code/CtForImpl.java | 14 ++++---- .../spoon/support/reflect/code/CtIfImpl.java | 6 ++-- .../reflect/code/CtInvocationImpl.java | 10 +++--- .../support/reflect/code/CtJavaDocImpl.java | 10 +++--- .../reflect/code/CtJavaDocTagImpl.java | 6 ++-- .../support/reflect/code/CtLambdaImpl.java | 20 ++++++------ .../support/reflect/code/CtLiteralImpl.java | 2 +- .../reflect/code/CtLocalVariableImpl.java | 12 +++---- .../support/reflect/code/CtLoopImpl.java | 4 +-- .../support/reflect/code/CtNewArrayImpl.java | 12 +++---- .../support/reflect/code/CtNewClassImpl.java | 2 +- .../code/CtOperatorAssignmentImpl.java | 2 +- .../support/reflect/code/CtReturnImpl.java | 2 +- .../support/reflect/code/CtStatementImpl.java | 2 +- .../reflect/code/CtStatementListImpl.java | 6 ++-- .../reflect/code/CtSuperAccessImpl.java | 2 +- .../support/reflect/code/CtSwitchImpl.java | 8 ++--- .../reflect/code/CtSynchronizedImpl.java | 4 +-- .../code/CtTargetedExpressionImpl.java | 2 +- .../support/reflect/code/CtThrowImpl.java | 2 +- .../spoon/support/reflect/code/CtTryImpl.java | 12 +++---- .../reflect/code/CtTryWithResourceImpl.java | 6 ++-- .../reflect/code/CtTypeAccessImpl.java | 2 +- .../reflect/code/CtUnaryOperatorImpl.java | 6 ++-- .../reflect/code/CtVariableAccessImpl.java | 2 +- .../support/reflect/code/CtWhileImpl.java | 2 +- .../reflect/declaration/CtAnnotationImpl.java | 10 +++--- .../declaration/CtAnnotationMethodImpl.java | 2 +- .../CtAnonymousExecutableImpl.java | 6 ++-- .../reflect/declaration/CtClassImpl.java | 12 +++---- .../declaration/CtConstructorImpl.java | 14 ++++---- .../reflect/declaration/CtElementImpl.java | 16 +++++----- .../reflect/declaration/CtEnumImpl.java | 6 ++-- .../reflect/declaration/CtExecutableImpl.java | 16 +++++----- .../reflect/declaration/CtFieldImpl.java | 12 +++---- .../reflect/declaration/CtMethodImpl.java | 18 +++++------ .../declaration/CtNamedElementImpl.java | 2 +- .../reflect/declaration/CtPackageImpl.java | 14 ++++---- .../reflect/declaration/CtParameterImpl.java | 12 +++---- .../reflect/declaration/CtTypeImpl.java | 32 +++++++++---------- .../declaration/CtTypeParameterImpl.java | 2 +- .../reference/CtArrayTypeReferenceImpl.java | 2 +- .../reference/CtExecutableReferenceImpl.java | 16 +++++----- .../reference/CtFieldReferenceImpl.java | 6 ++-- .../CtIntersectionTypeReferenceImpl.java | 6 ++-- .../reference/CtParameterReferenceImpl.java | 2 +- .../reflect/reference/CtReferenceImpl.java | 2 +- .../CtTypeParameterReferenceImpl.java | 4 +-- .../reference/CtTypeReferenceImpl.java | 12 +++---- .../reference/CtVariableReferenceImpl.java | 2 +- 72 files changed, 246 insertions(+), 257 deletions(-) diff --git a/src/main/java/spoon/reflect/factory/Factory.java b/src/main/java/spoon/reflect/factory/Factory.java index e612b0a81fd..671638f9e95 100644 --- a/src/main/java/spoon/reflect/factory/Factory.java +++ b/src/main/java/spoon/reflect/factory/Factory.java @@ -17,7 +17,6 @@ package spoon.reflect.factory; import spoon.compiler.Environment; -import spoon.experimental.modelobs.FineModelChangeListener; import spoon.reflect.CtModel; import spoon.reflect.code.BinaryOperatorKind; import spoon.reflect.code.CtAnnotationFieldAccess; @@ -157,8 +156,6 @@ public interface Factory { QueryFactory Query(); - FineModelChangeListener Change(); - /** * @see CodeFactory#createAnnotation(CtTypeReference) */ diff --git a/src/main/java/spoon/reflect/factory/FactoryImpl.java b/src/main/java/spoon/reflect/factory/FactoryImpl.java index 33a5f943a0d..b0f41eaec98 100644 --- a/src/main/java/spoon/reflect/factory/FactoryImpl.java +++ b/src/main/java/spoon/reflect/factory/FactoryImpl.java @@ -17,7 +17,6 @@ package spoon.reflect.factory; import spoon.compiler.Environment; -import spoon.experimental.modelobs.FineModelChangeListener; import spoon.reflect.CtModel; import spoon.reflect.CtModelImpl; import spoon.reflect.code.BinaryOperatorKind; @@ -353,13 +352,6 @@ public QueryFactory Query() { return query; } - /** - * The change sub-factory. - */ - @Override - public FineModelChangeListener Change() { - return getEnvironment().getModelChangeListener(); - } /** * A constructor that takes the parent factory diff --git a/src/main/java/spoon/support/reflect/code/CtArrayAccessImpl.java b/src/main/java/spoon/support/reflect/code/CtArrayAccessImpl.java index 4d470941cb4..0f0dd566a6f 100644 --- a/src/main/java/spoon/support/reflect/code/CtArrayAccessImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtArrayAccessImpl.java @@ -39,7 +39,7 @@ public > C setIndexExpression(CtExpression> A setAssertExpression(CtExpression asser if (asserted != null) { asserted.setParent(this); } - getFactory().Change().onObjectUpdate(this, CONDITION, asserted, this.asserted); + getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, CONDITION, asserted, this.asserted); this.asserted = asserted; return (A) this; } @@ -64,7 +64,7 @@ public > A setExpression(CtExpression value) { if (value != null) { value.setParent(this); } - getFactory().Change().onObjectUpdate(this, EXPRESSION, value, this.value); + getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, EXPRESSION, value, this.value); this.value = value; return (A) this; } diff --git a/src/main/java/spoon/support/reflect/code/CtAssignmentImpl.java b/src/main/java/spoon/support/reflect/code/CtAssignmentImpl.java index 74e5eecf08b..b2affcd5cc1 100644 --- a/src/main/java/spoon/support/reflect/code/CtAssignmentImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtAssignmentImpl.java @@ -81,7 +81,7 @@ public > C setAssigned(CtExpression assigned) { if (assigned != null) { assigned.setParent(this); } - getFactory().Change().onObjectUpdate(this, ASSIGNED, assigned, this.assigned); + getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, ASSIGNED, assigned, this.assigned); this.assigned = assigned; return (C) this; } @@ -91,7 +91,7 @@ public > C setAssignment(CtExpression assignment) if (assignment != null) { assignment.setParent(this); } - getFactory().Change().onObjectUpdate(this, ASSIGNMENT, assignment, this.assignment); + getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, ASSIGNMENT, assignment, this.assignment); this.assignment = assignment; return (C) this; } @@ -101,7 +101,7 @@ public C setType(CtTypeReference type) { if (type != null) { type.setParent(this); } - getFactory().Change().onObjectUpdate(this, TYPE, type, this.type); + getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, TYPE, type, this.type); this.type = type; return (C) this; } @@ -115,7 +115,7 @@ public > C setTypeCasts(List> casts if (this.typeCasts == CtElementImpl.>emptyList()) { this.typeCasts = new ArrayList<>(CASTS_CONTAINER_DEFAULT_CAPACITY); } - getFactory().Change().onListDeleteAll(this, CAST, this.typeCasts, new ArrayList<>(this.typeCasts)); + getFactory().getEnvironment().getModelChangeListener().onListDeleteAll(this, CAST, this.typeCasts, new ArrayList<>(this.typeCasts)); this.typeCasts.clear(); for (CtTypeReference cast : casts) { addTypeCast(cast); @@ -132,7 +132,7 @@ public > C addTypeCast(CtTypeReference type) { typeCasts = new ArrayList<>(CASTS_CONTAINER_DEFAULT_CAPACITY); } type.setParent(this); - getFactory().Change().onListAdd(this, CAST, typeCasts, type); + getFactory().getEnvironment().getModelChangeListener().onListAdd(this, CAST, typeCasts, type); typeCasts.add(type); return (C) this; } diff --git a/src/main/java/spoon/support/reflect/code/CtBinaryOperatorImpl.java b/src/main/java/spoon/support/reflect/code/CtBinaryOperatorImpl.java index b4890852b90..4a8023dfc50 100644 --- a/src/main/java/spoon/support/reflect/code/CtBinaryOperatorImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtBinaryOperatorImpl.java @@ -59,7 +59,7 @@ public > C setLeftHandOperand(CtExpression expr if (expression != null) { expression.setParent(this); } - getFactory().Change().onObjectUpdate(this, LEFT_OPERAND, expression, this.leftHandOperand); + getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, LEFT_OPERAND, expression, this.leftHandOperand); leftHandOperand = expression; return (C) this; } @@ -69,14 +69,14 @@ public > C setRightHandOperand(CtExpression exp if (expression != null) { expression.setParent(this); } - getFactory().Change().onObjectUpdate(this, RIGHT_OPERAND, expression, this.rightHandOperand); + getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, RIGHT_OPERAND, expression, this.rightHandOperand); rightHandOperand = expression; return (C) this; } @Override public > C setKind(BinaryOperatorKind kind) { - getFactory().Change().onObjectUpdate(this, OPERATOR_KIND, kind, this.kind); + getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, OPERATOR_KIND, kind, this.kind); this.kind = kind; return (C) this; } diff --git a/src/main/java/spoon/support/reflect/code/CtBlockImpl.java b/src/main/java/spoon/support/reflect/code/CtBlockImpl.java index 01a85c83985..7dd3680eb7d 100644 --- a/src/main/java/spoon/support/reflect/code/CtBlockImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtBlockImpl.java @@ -81,7 +81,7 @@ public > T insertBegin(CtStatementList statements) { } for (CtStatement statement : statements.getStatements()) { statement.setParent(this); - getFactory().Change().onListAdd(this, STATEMENT, this.statements, 0, statement); + getFactory().getEnvironment().getModelChangeListener().onListAdd(this, STATEMENT, this.statements, 0, statement); this.statements.add(0, statement); } if (isImplicit() && this.statements.size() > 1) { @@ -105,7 +105,7 @@ public > T insertBegin(CtStatement statement) { } ensureModifiableStatementsList(); statement.setParent(this); - getFactory().Change().onListAdd(this, STATEMENT, this.statements, 0, statement); + getFactory().getEnvironment().getModelChangeListener().onListAdd(this, STATEMENT, this.statements, 0, statement); this.statements.add(0, statement); if (isImplicit() && this.statements.size() > 1) { setImplicit(false); @@ -166,7 +166,7 @@ public T setStatements(List statements) this.statements = CtElementImpl.emptyList(); return (T) this; } - getFactory().Change().onListDeleteAll(this, STATEMENT, this.statements, new ArrayList<>(this.statements)); + getFactory().getEnvironment().getModelChangeListener().onListDeleteAll(this, STATEMENT, this.statements, new ArrayList<>(this.statements)); this.statements.clear(); for (CtStatement s : statements) { addStatement(s); @@ -181,7 +181,7 @@ public T addStatement(CtStatement statement) { } ensureModifiableStatementsList(); statement.setParent(this); - getFactory().Change().onListAdd(this, STATEMENT, this.statements, this.statements.size(), statement); + getFactory().getEnvironment().getModelChangeListener().onListAdd(this, STATEMENT, this.statements, this.statements.size(), statement); this.statements.add(statement); if (isImplicit() && this.statements.size() > 1) { setImplicit(false); @@ -203,7 +203,7 @@ public void removeStatement(CtStatement statement) { // and a block can have twice exactly the same statement. for (int i = 0; i < this.statements.size(); i++) { if (this.statements.get(i) == statement) { - getFactory().Change().onListDelete(this, STATEMENT, statements, i, statement); + getFactory().getEnvironment().getModelChangeListener().onListDelete(this, STATEMENT, statements, i, statement); this.statements.remove(i); hasBeenRemoved = true; break; @@ -212,7 +212,7 @@ public void removeStatement(CtStatement statement) { // in case we use it with a statement manually built if (!hasBeenRemoved) { - getFactory().Change().onListDelete(this, STATEMENT, statements, statements.indexOf(statement), statement); + getFactory().getEnvironment().getModelChangeListener().onListDelete(this, STATEMENT, statements, statements.indexOf(statement), statement); this.statements.remove(statement); } diff --git a/src/main/java/spoon/support/reflect/code/CtBreakImpl.java b/src/main/java/spoon/support/reflect/code/CtBreakImpl.java index f92e851413e..27733802511 100644 --- a/src/main/java/spoon/support/reflect/code/CtBreakImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtBreakImpl.java @@ -47,7 +47,7 @@ public String getTargetLabel() { @Override public T setTargetLabel(String targetLabel) { - getFactory().Change().onObjectUpdate(this, TARGET_LABEL, targetLabel, this.targetLabel); + getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, TARGET_LABEL, targetLabel, this.targetLabel); this.targetLabel = targetLabel; return (T) this; } diff --git a/src/main/java/spoon/support/reflect/code/CtCaseImpl.java b/src/main/java/spoon/support/reflect/code/CtCaseImpl.java index fb54277f2f1..1d717fd2bdc 100644 --- a/src/main/java/spoon/support/reflect/code/CtCaseImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtCaseImpl.java @@ -62,7 +62,7 @@ public > T setCaseExpression(CtExpression caseExpression) if (caseExpression != null) { caseExpression.setParent(this); } - getFactory().Change().onObjectUpdate(this, CASE, caseExpression, this.caseExpression); + getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, CASE, caseExpression, this.caseExpression); this.caseExpression = caseExpression; return (T) this; } @@ -73,7 +73,7 @@ public T setStatements(List statements) this.statements = CtElementImpl.emptyList(); return (T) this; } - getFactory().Change().onListDeleteAll(this, STATEMENT, this.statements, new ArrayList<>(this.statements)); + getFactory().getEnvironment().getModelChangeListener().onListDeleteAll(this, STATEMENT, this.statements, new ArrayList<>(this.statements)); this.statements.clear(); for (CtStatement stmt : statements) { addStatement(stmt); @@ -90,7 +90,7 @@ public T addStatement(CtStatement statement) { statements = new ArrayList<>(CASE_STATEMENTS_CONTAINER_DEFAULT_CAPACITY); } statement.setParent(this); - getFactory().Change().onListAdd(this, STATEMENT, this.statements, statement); + getFactory().getEnvironment().getModelChangeListener().onListAdd(this, STATEMENT, this.statements, statement); statements.add(statement); return (T) this; } @@ -100,7 +100,7 @@ public void removeStatement(CtStatement statement) { if (statements == CtElementImpl.emptyList()) { return; } - getFactory().Change().onListDelete(this, STATEMENT, statements, statements.indexOf(statement), statement); + getFactory().getEnvironment().getModelChangeListener().onListDelete(this, STATEMENT, statements, statements.indexOf(statement), statement); statements.remove(statement); } diff --git a/src/main/java/spoon/support/reflect/code/CtCatchImpl.java b/src/main/java/spoon/support/reflect/code/CtCatchImpl.java index 2b8e676fbc9..4dd20cece1c 100644 --- a/src/main/java/spoon/support/reflect/code/CtCatchImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtCatchImpl.java @@ -56,13 +56,13 @@ public CtCatchVariable getParameter() { public T setBody(CtStatement statement) { if (statement != null) { CtBlock body = getFactory().Code().getOrCreateCtBlock(statement); - getFactory().Change().onObjectUpdate(this, BODY, body, this.body); + getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, BODY, body, this.body); if (body != null) { body.setParent(this); } this.body = body; } else { - getFactory().Change().onObjectDelete(this, BODY, this.body); + getFactory().getEnvironment().getModelChangeListener().onObjectDelete(this, BODY, this.body); this.body = null; } @@ -74,7 +74,7 @@ public T setParameter(CtCatchVariable p if (parameter != null) { parameter.setParent(this); } - getFactory().Change().onObjectUpdate(this, PARAMETER, parameter, this.parameter); + getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, PARAMETER, parameter, this.parameter); this.parameter = parameter; return (T) this; } diff --git a/src/main/java/spoon/support/reflect/code/CtCatchVariableImpl.java b/src/main/java/spoon/support/reflect/code/CtCatchVariableImpl.java index 8b014e8b486..eeda9f9ef4f 100644 --- a/src/main/java/spoon/support/reflect/code/CtCatchVariableImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtCatchVariableImpl.java @@ -94,7 +94,7 @@ public > C setDefaultExpression(CtExpression defaultE @Override public C setSimpleName(String simpleName) { - getFactory().Change().onObjectUpdate(this, NAME, simpleName, this.name); + getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, NAME, simpleName, this.name); this.name = simpleName; return (C) this; } @@ -104,7 +104,7 @@ public C setType(CtTypeReference type) { if (type != null) { type.setParent(this); } - getFactory().Change().onObjectUpdate(this, TYPE, type, this.type); + getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, TYPE, type, this.type); this.type = type; return (C) this; } @@ -118,7 +118,7 @@ public T addMultiType(CtTypeReference type) { types = new ArrayList<>(CATCH_VARIABLE_MULTI_TYPES_CONTAINER_DEFAULT_CAPACITY); } type.setParent(this); - getFactory().Change().onListAdd(this, TYPE, this.types, type); + getFactory().getEnvironment().getModelChangeListener().onListAdd(this, TYPE, this.types, type); types.add(type); return (T) this; } @@ -128,7 +128,7 @@ public boolean removeMultiType(CtTypeReference ref) { if (this.types == CtElementImpl.>emptyList()) { return false; } - getFactory().Change().onListDelete(this, TYPE, types, types.indexOf(ref), ref); + getFactory().getEnvironment().getModelChangeListener().onListDelete(this, TYPE, types, types.indexOf(ref), ref); return types.remove(ref); } @@ -139,7 +139,7 @@ public List> getMultiTypes() { @Override public T setMultiTypes(List> types) { - getFactory().Change().onListDeleteAll(this, TYPE, this.types, new ArrayList<>(this.types)); + getFactory().getEnvironment().getModelChangeListener().onListDeleteAll(this, TYPE, this.types, new ArrayList<>(this.types)); if (types == null || types.isEmpty()) { this.types = CtElementImpl.emptyList(); return (T) this; @@ -167,7 +167,7 @@ public boolean hasModifier(ModifierKind modifier) { @Override public C setModifiers(Set modifiers) { if (modifiers.size() > 0) { - getFactory().Change().onSetDeleteAll(this, MODIFIER, this.modifiers, new HashSet<>(this.modifiers)); + getFactory().getEnvironment().getModelChangeListener().onSetDeleteAll(this, MODIFIER, this.modifiers, new HashSet<>(this.modifiers)); this.modifiers.clear(); for (ModifierKind modifier : modifiers) { addModifier(modifier); @@ -181,7 +181,7 @@ public C addModifier(ModifierKind modifier) { if (modifiers == CtElementImpl.emptySet()) { this.modifiers = EnumSet.noneOf(ModifierKind.class); } - getFactory().Change().onSetAdd(this, MODIFIER, this.modifiers, modifier); + getFactory().getEnvironment().getModelChangeListener().onSetAdd(this, MODIFIER, this.modifiers, modifier); modifiers.add(modifier); return (C) this; } @@ -191,7 +191,7 @@ public boolean removeModifier(ModifierKind modifier) { if (modifiers == CtElementImpl.emptySet()) { return false; } - getFactory().Change().onSetDelete(this, MODIFIER, modifiers, modifier); + getFactory().getEnvironment().getModelChangeListener().onSetDelete(this, MODIFIER, modifiers, modifier); return modifiers.remove(modifier); } diff --git a/src/main/java/spoon/support/reflect/code/CtCodeSnippetExpressionImpl.java b/src/main/java/spoon/support/reflect/code/CtCodeSnippetExpressionImpl.java index fe2de6de1a0..48259b679bb 100644 --- a/src/main/java/spoon/support/reflect/code/CtCodeSnippetExpressionImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtCodeSnippetExpressionImpl.java @@ -43,7 +43,7 @@ public String getValue() { } public C setValue(String value) { - getFactory().Change().onObjectUpdate(this, EXPRESSION, value, this.value); + getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, EXPRESSION, value, this.value); this.value = value; return (C) this; } diff --git a/src/main/java/spoon/support/reflect/code/CtCodeSnippetStatementImpl.java b/src/main/java/spoon/support/reflect/code/CtCodeSnippetStatementImpl.java index 15895ec2606..c987546a20f 100644 --- a/src/main/java/spoon/support/reflect/code/CtCodeSnippetStatementImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtCodeSnippetStatementImpl.java @@ -43,7 +43,7 @@ public String getValue() { } public C setValue(String value) { - getFactory().Change().onObjectUpdate(this, EXPRESSION, value, this.value); + getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, EXPRESSION, value, this.value); this.value = value; return (C) this; } diff --git a/src/main/java/spoon/support/reflect/code/CtCommentImpl.java b/src/main/java/spoon/support/reflect/code/CtCommentImpl.java index ee3f7cee0ae..013f1a8cec0 100644 --- a/src/main/java/spoon/support/reflect/code/CtCommentImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtCommentImpl.java @@ -47,7 +47,7 @@ public String getContent() { @Override public E setContent(String content) { - getFactory().Change().onObjectUpdate(this, COMMENT_CONTENT, content, this.content); + getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, COMMENT_CONTENT, content, this.content); this.content = content; return (E) this; } @@ -59,7 +59,7 @@ public CommentType getCommentType() { @Override public E setCommentType(CommentType commentType) { - getFactory().Change().onObjectUpdate(this, TYPE, commentType, this.type); + getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, TYPE, commentType, this.type); type = commentType; return (E) this; } diff --git a/src/main/java/spoon/support/reflect/code/CtConditionalImpl.java b/src/main/java/spoon/support/reflect/code/CtConditionalImpl.java index d1a5f0234dd..aeded2030f1 100644 --- a/src/main/java/spoon/support/reflect/code/CtConditionalImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtConditionalImpl.java @@ -63,7 +63,7 @@ public > C setElseExpression(CtExpression elseExpr if (elseExpression != null) { elseExpression.setParent(this); } - getFactory().Change().onObjectUpdate(this, ELSE, elseExpression, this.elseExpression); + getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, ELSE, elseExpression, this.elseExpression); this.elseExpression = elseExpression; return (C) this; } @@ -73,7 +73,7 @@ public > C setCondition(CtExpression conditi if (condition != null) { condition.setParent(this); } - getFactory().Change().onObjectUpdate(this, CONDITION, condition, this.condition); + getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, CONDITION, condition, this.condition); this.condition = condition; return (C) this; } @@ -83,7 +83,7 @@ public > C setThenExpression(CtExpression thenExpr if (thenExpression != null) { thenExpression.setParent(this); } - getFactory().Change().onObjectUpdate(this, THEN, thenExpression, this.thenExpression); + getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, THEN, thenExpression, this.thenExpression); this.thenExpression = thenExpression; return (C) this; } diff --git a/src/main/java/spoon/support/reflect/code/CtConstructorCallImpl.java b/src/main/java/spoon/support/reflect/code/CtConstructorCallImpl.java index 24e4befc39f..fdffdf7608f 100644 --- a/src/main/java/spoon/support/reflect/code/CtConstructorCallImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtConstructorCallImpl.java @@ -106,7 +106,7 @@ public > C setArguments(List> if (this.arguments == CtElementImpl.>emptyList()) { this.arguments = new ArrayList<>(PARAMETERS_CONTAINER_DEFAULT_CAPACITY); } - getFactory().Change().onListDeleteAll(this, ARGUMENT, this.arguments, new ArrayList<>(this.arguments)); + getFactory().getEnvironment().getModelChangeListener().onListDeleteAll(this, ARGUMENT, this.arguments, new ArrayList<>(this.arguments)); this.arguments.clear(); for (CtExpression expr : arguments) { addArgument(expr); @@ -122,7 +122,7 @@ private > C addArgument(int position, CtExpres arguments = new ArrayList<>(PARAMETERS_CONTAINER_DEFAULT_CAPACITY); } argument.setParent(this); - getFactory().Change().onListAdd(this, ARGUMENT, this.arguments, position, argument); + getFactory().getEnvironment().getModelChangeListener().onListAdd(this, ARGUMENT, this.arguments, position, argument); arguments.add(position, argument); return (C) this; } @@ -137,7 +137,7 @@ public void removeArgument(CtExpression argument) { if (arguments == CtElementImpl.>emptyList()) { return; } - getFactory().Change().onListDelete(this, ARGUMENT, arguments, arguments.indexOf(argument), argument); + getFactory().getEnvironment().getModelChangeListener().onListDelete(this, ARGUMENT, arguments, arguments.indexOf(argument), argument); arguments.remove(argument); } @@ -146,14 +146,14 @@ public > C setExecutable(CtExecutableReference if (executable != null) { executable.setParent(this); } - getFactory().Change().onObjectUpdate(this, EXECUTABLE, executable, this.executable); + getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, EXECUTABLE, executable, this.executable); this.executable = executable; return (C) this; } @Override public C setLabel(String label) { - getFactory().Change().onObjectUpdate(this, LABEL, label, this.label); + getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, LABEL, label, this.label); this.label = label; return (C) this; } diff --git a/src/main/java/spoon/support/reflect/code/CtContinueImpl.java b/src/main/java/spoon/support/reflect/code/CtContinueImpl.java index a3b042546f1..05c537a0e68 100644 --- a/src/main/java/spoon/support/reflect/code/CtContinueImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtContinueImpl.java @@ -47,7 +47,7 @@ public String getTargetLabel() { @Override public T setTargetLabel(String targetLabel) { - getFactory().Change().onObjectUpdate(this, TARGET_LABEL, targetLabel, this.targetLabel); + getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, TARGET_LABEL, targetLabel, this.targetLabel); this.targetLabel = targetLabel; return (T) this; } diff --git a/src/main/java/spoon/support/reflect/code/CtDoImpl.java b/src/main/java/spoon/support/reflect/code/CtDoImpl.java index 3d80a7ec902..802b0dfae2f 100644 --- a/src/main/java/spoon/support/reflect/code/CtDoImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtDoImpl.java @@ -45,7 +45,7 @@ public T setLoopingExpression(CtExpression expression) if (expression != null) { expression.setParent(this); } - getFactory().Change().onObjectUpdate(this, EXPRESSION, expression, this.expression); + getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, EXPRESSION, expression, this.expression); this.expression = expression; return (T) this; } diff --git a/src/main/java/spoon/support/reflect/code/CtExecutableReferenceExpressionImpl.java b/src/main/java/spoon/support/reflect/code/CtExecutableReferenceExpressionImpl.java index a0efc17510f..207d4d9ee46 100644 --- a/src/main/java/spoon/support/reflect/code/CtExecutableReferenceExpressionImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtExecutableReferenceExpressionImpl.java @@ -44,7 +44,7 @@ public > C setExecutable(CtExecu if (executable != null) { executable.setParent(this); } - getFactory().Change().onObjectUpdate(this, EXECUTABLE, executable, this.executable); + getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, EXECUTABLE, executable, this.executable); this.executable = executable; return (C) this; } diff --git a/src/main/java/spoon/support/reflect/code/CtExpressionImpl.java b/src/main/java/spoon/support/reflect/code/CtExpressionImpl.java index 85bc53e7c3b..7adc465bbe6 100644 --- a/src/main/java/spoon/support/reflect/code/CtExpressionImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtExpressionImpl.java @@ -53,7 +53,7 @@ public C setType(CtTypeReference type) { if (type != null) { type.setParent(this); } - getFactory().Change().onObjectUpdate(this, TYPE, type, this.type); + getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, TYPE, type, this.type); this.type = type; return (C) this; } @@ -67,7 +67,7 @@ public > C setTypeCasts(List> casts if (this.typeCasts == CtElementImpl.>emptyList()) { this.typeCasts = new ArrayList<>(CASTS_CONTAINER_DEFAULT_CAPACITY); } - getFactory().Change().onListDeleteAll(this, CAST, this.typeCasts, new ArrayList<>(this.typeCasts)); + getFactory().getEnvironment().getModelChangeListener().onListDeleteAll(this, CAST, this.typeCasts, new ArrayList<>(this.typeCasts)); this.typeCasts.clear(); for (CtTypeReference cast : casts) { addTypeCast(cast); @@ -84,7 +84,7 @@ public > C addTypeCast(CtTypeReference type) { typeCasts = new ArrayList<>(CASTS_CONTAINER_DEFAULT_CAPACITY); } type.setParent(this); - getFactory().Change().onListAdd(this, CAST, this.typeCasts, type); + getFactory().getEnvironment().getModelChangeListener().onListAdd(this, CAST, this.typeCasts, type); typeCasts.add(type); return (C) this; } diff --git a/src/main/java/spoon/support/reflect/code/CtFieldAccessImpl.java b/src/main/java/spoon/support/reflect/code/CtFieldAccessImpl.java index ee2e3186565..c11e178ee8e 100644 --- a/src/main/java/spoon/support/reflect/code/CtFieldAccessImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtFieldAccessImpl.java @@ -41,7 +41,7 @@ public >> C setTarget(CtExpres if (target != null) { target.setParent(this); } - getFactory().Change().onObjectUpdate(this, TARGET, target, this.target); + getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, TARGET, target, this.target); this.target = target; return null; } diff --git a/src/main/java/spoon/support/reflect/code/CtForEachImpl.java b/src/main/java/spoon/support/reflect/code/CtForEachImpl.java index d075c8dd883..99034e958cf 100644 --- a/src/main/java/spoon/support/reflect/code/CtForEachImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtForEachImpl.java @@ -55,7 +55,7 @@ public T setExpression(CtExpression expression) { if (expression != null) { expression.setParent(this); } - getFactory().Change().onObjectUpdate(this, EXPRESSION, expression, this.expression); + getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, EXPRESSION, expression, this.expression); this.expression = expression; return (T) this; } @@ -65,7 +65,7 @@ public T setVariable(CtLocalVariable variable) { if (variable != null) { variable.setParent(this); } - getFactory().Change().onObjectUpdate(this, VARIABLE, variable, this.variable); + getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, VARIABLE, variable, this.variable); this.variable = variable; return (T) this; } diff --git a/src/main/java/spoon/support/reflect/code/CtForImpl.java b/src/main/java/spoon/support/reflect/code/CtForImpl.java index a10708c10bc..c34161c9bee 100644 --- a/src/main/java/spoon/support/reflect/code/CtForImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtForImpl.java @@ -60,7 +60,7 @@ public T setExpression(CtExpression expression) { if (expression != null) { expression.setParent(this); } - getFactory().Change().onObjectUpdate(this, EXPRESSION, expression, this.expression); + getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, EXPRESSION, expression, this.expression); this.expression = expression; return (T) this; } @@ -79,7 +79,7 @@ public T addForInit(CtStatement statement) { forInit = new ArrayList<>(FOR_INIT_STATEMENTS_CONTAINER_DEFAULT_CAPACITY); } statement.setParent(this); - getFactory().Change().onListAdd(this, FOR_INIT, this.forInit, statement); + getFactory().getEnvironment().getModelChangeListener().onListAdd(this, FOR_INIT, this.forInit, statement); forInit.add(statement); return (T) this; } @@ -90,7 +90,7 @@ public T setForInit(List statements) { this.forInit = CtElementImpl.emptyList(); return (T) this; } - getFactory().Change().onListDeleteAll(this, FOR_INIT, this.forInit, new ArrayList<>(this.forInit)); + getFactory().getEnvironment().getModelChangeListener().onListDeleteAll(this, FOR_INIT, this.forInit, new ArrayList<>(this.forInit)); this.forInit.clear(); for (CtStatement stmt : statements) { addForInit(stmt); @@ -103,7 +103,7 @@ public boolean removeForInit(CtStatement statement) { if (forInit == CtElementImpl.emptyList()) { return false; } - getFactory().Change().onListDelete(this, FOR_INIT, forInit, forInit.indexOf(statement), statement); + getFactory().getEnvironment().getModelChangeListener().onListDelete(this, FOR_INIT, forInit, forInit.indexOf(statement), statement); return forInit.remove(statement); } @@ -121,7 +121,7 @@ public T addForUpdate(CtStatement statement) { forUpdate = new ArrayList<>(FOR_UPDATE_STATEMENTS_CONTAINER_DEFAULT_CAPACITY); } statement.setParent(this); - getFactory().Change().onListAdd(this, FOR_UPDATE, this.forUpdate, statement); + getFactory().getEnvironment().getModelChangeListener().onListAdd(this, FOR_UPDATE, this.forUpdate, statement); forUpdate.add(statement); return (T) this; } @@ -132,7 +132,7 @@ public T setForUpdate(List statements) { this.forUpdate = CtElementImpl.emptyList(); return (T) this; } - getFactory().Change().onListDeleteAll(this, FOR_UPDATE, this.forUpdate, new ArrayList<>(this.forUpdate)); + getFactory().getEnvironment().getModelChangeListener().onListDeleteAll(this, FOR_UPDATE, this.forUpdate, new ArrayList<>(this.forUpdate)); this.forUpdate.clear(); for (CtStatement stmt : statements) { addForUpdate(stmt); @@ -145,7 +145,7 @@ public boolean removeForUpdate(CtStatement statement) { if (forUpdate == CtElementImpl.emptyList()) { return false; } - getFactory().Change().onListDelete(this, FOR_UPDATE, forUpdate, forUpdate.indexOf(statement), statement); + getFactory().getEnvironment().getModelChangeListener().onListDelete(this, FOR_UPDATE, forUpdate, forUpdate.indexOf(statement), statement); return forUpdate.remove(statement); } diff --git a/src/main/java/spoon/support/reflect/code/CtIfImpl.java b/src/main/java/spoon/support/reflect/code/CtIfImpl.java index b876777fb37..a5301c78772 100644 --- a/src/main/java/spoon/support/reflect/code/CtIfImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtIfImpl.java @@ -68,7 +68,7 @@ public T setCondition(CtExpression condition) { if (condition != null) { condition.setParent(this); } - getFactory().Change().onObjectUpdate(this, CONDITION, condition, this.condition); + getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, CONDITION, condition, this.condition); this.condition = condition; return (T) this; } @@ -78,7 +78,7 @@ public T setElseStatement(CtStatement elseStatement) { if (elseStatement != null) { elseStatement.setParent(this); } - getFactory().Change().onObjectUpdate(this, ELSE, elseStatement, this.elseStatement); + getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, ELSE, elseStatement, this.elseStatement); this.elseStatement = elseStatement; return (T) this; } @@ -89,7 +89,7 @@ public T setThenStatement(CtStatement thenStatement) { if (thenStatement != null) { thenStatement.setParent(this); } - getFactory().Change().onObjectUpdate(this, THEN, thenStatement, this.thenStatement); + getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, THEN, thenStatement, this.thenStatement); this.thenStatement = thenStatement; return (T) this; } diff --git a/src/main/java/spoon/support/reflect/code/CtInvocationImpl.java b/src/main/java/spoon/support/reflect/code/CtInvocationImpl.java index b46dd365969..2500d976a20 100644 --- a/src/main/java/spoon/support/reflect/code/CtInvocationImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtInvocationImpl.java @@ -70,7 +70,7 @@ private > C addArgument(int position, CtExpres arguments = new ArrayList<>(PARAMETERS_CONTAINER_DEFAULT_CAPACITY); } argument.setParent(this); - getFactory().Change().onListAdd(this, ARGUMENT, this.arguments, position, argument); + getFactory().getEnvironment().getModelChangeListener().onListAdd(this, ARGUMENT, this.arguments, position, argument); arguments.add(position, argument); return (C) this; } @@ -85,7 +85,7 @@ public void removeArgument(CtExpression argument) { if (arguments == CtElementImpl.>emptyList()) { return; } - getFactory().Change().onListDelete(this, ARGUMENT, arguments, arguments.indexOf(argument), argument); + getFactory().getEnvironment().getModelChangeListener().onListDelete(this, ARGUMENT, arguments, arguments.indexOf(argument), argument); arguments.remove(argument); } @@ -131,7 +131,7 @@ public > C setArguments(List> if (this.arguments == CtElementImpl.>emptyList()) { this.arguments = new ArrayList<>(PARAMETERS_CONTAINER_DEFAULT_CAPACITY); } - getFactory().Change().onListDeleteAll(this, ARGUMENT, this.arguments, new ArrayList<>(this.arguments)); + getFactory().getEnvironment().getModelChangeListener().onListDeleteAll(this, ARGUMENT, this.arguments, new ArrayList<>(this.arguments)); this.arguments.clear(); for (CtExpression expr : arguments) { addArgument(expr); @@ -144,7 +144,7 @@ public > C setExecutable(CtExecutableReference if (executable != null) { executable.setParent(this); } - getFactory().Change().onObjectUpdate(this, EXECUTABLE, executable, this.executable); + getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, EXECUTABLE, executable, this.executable); this.executable = executable; return (C) this; } @@ -156,7 +156,7 @@ public String getLabel() { @Override public C setLabel(String label) { - getFactory().Change().onObjectUpdate(this, LABEL, label, this.label); + getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, LABEL, label, this.label); this.label = label; return (C) this; } diff --git a/src/main/java/spoon/support/reflect/code/CtJavaDocImpl.java b/src/main/java/spoon/support/reflect/code/CtJavaDocImpl.java index 7e911245341..fbd4d316ca4 100644 --- a/src/main/java/spoon/support/reflect/code/CtJavaDocImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtJavaDocImpl.java @@ -46,7 +46,7 @@ public E setTags(List tags) { if (tags == null) { return (E) this; } - getFactory().Change().onListDeleteAll(this, COMMENT_TAG, this.tags, new ArrayList<>(this.tags)); + getFactory().getEnvironment().getModelChangeListener().onListDeleteAll(this, COMMENT_TAG, this.tags, new ArrayList<>(this.tags)); this.tags = new ArrayList<>(); for (CtJavaDocTag tag : tags) { this.addTag(tag); @@ -58,7 +58,7 @@ public E setTags(List tags) { public E addTag(CtJavaDocTag tag) { if (tag != null) { tag.setParent(this); - getFactory().Change().onListAdd(this, COMMENT_TAG, tags, tag); + getFactory().getEnvironment().getModelChangeListener().onListAdd(this, COMMENT_TAG, tags, tag); tags.add(tag); } return (E) this; @@ -67,21 +67,21 @@ public E addTag(CtJavaDocTag tag) { @Override public E addTag(int index, CtJavaDocTag tag) { tag.setParent(this); - getFactory().Change().onListAdd(this, COMMENT_TAG, tags, index, tag); + getFactory().getEnvironment().getModelChangeListener().onListAdd(this, COMMENT_TAG, tags, index, tag); tags.add(index, tag); return (E) this; } @Override public E removeTag(int index) { - getFactory().Change().onListDelete(this, COMMENT_TAG, tags, index, tags.get(index)); + getFactory().getEnvironment().getModelChangeListener().onListDelete(this, COMMENT_TAG, tags, index, tags.get(index)); tags.remove(index); return (E) this; } @Override public E removeTag(CtJavaDocTag tag) { - getFactory().Change().onListDelete(this, COMMENT_TAG, tags, tags.indexOf(tag), tag); + getFactory().getEnvironment().getModelChangeListener().onListDelete(this, COMMENT_TAG, tags, tags.indexOf(tag), tag); tags.remove(tag); return (E) this; } diff --git a/src/main/java/spoon/support/reflect/code/CtJavaDocTagImpl.java b/src/main/java/spoon/support/reflect/code/CtJavaDocTagImpl.java index 178b93307e3..253fb20158d 100644 --- a/src/main/java/spoon/support/reflect/code/CtJavaDocTagImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtJavaDocTagImpl.java @@ -48,7 +48,7 @@ public E setType(String type) { @Override public E setType(TagType type) { - getFactory().Change().onObjectUpdate(this, TYPE, type, this.type); + getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, TYPE, type, this.type); this.type = type; return (E) this; } @@ -60,7 +60,7 @@ public String getContent() { @Override public E setContent(String content) { - getFactory().Change().onObjectUpdate(this, COMMENT_CONTENT, content, this.content); + getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, COMMENT_CONTENT, content, this.content); this.content = content; return (E) this; } @@ -72,7 +72,7 @@ public String getParam() { @Override public E setParam(String param) { - getFactory().Change().onObjectUpdate(this, PARAMETER, param, this.param); + getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, PARAMETER, param, this.param); this.param = param; return (E) this; } diff --git a/src/main/java/spoon/support/reflect/code/CtLambdaImpl.java b/src/main/java/spoon/support/reflect/code/CtLambdaImpl.java index b98a0dd18f1..9b27c6e9855 100644 --- a/src/main/java/spoon/support/reflect/code/CtLambdaImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtLambdaImpl.java @@ -73,7 +73,7 @@ public String getSimpleName() { @Override public C setSimpleName(String simpleName) { - getFactory().Change().onObjectUpdate(this, NAME, simpleName, this.simpleName); + getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, NAME, simpleName, this.simpleName); this.simpleName = simpleName; return (C) this; } @@ -88,7 +88,7 @@ public CtBlock getBody() { public C setBody(CtStatement statement) { if (statement != null) { CtBlock body = getFactory().Code().getOrCreateCtBlock(statement); - getFactory().Change().onObjectUpdate(this, BODY, body, this.body); + getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, BODY, body, this.body); if (expression != null && body != null) { throw new SpoonException("A lambda can't have two bodys."); } @@ -97,7 +97,7 @@ public C setBody(CtStatement statement) { } this.body = body; } else { - getFactory().Change().onObjectDelete(this, BODY, this.body); + getFactory().getEnvironment().getModelChangeListener().onObjectDelete(this, BODY, this.body); this.body = null; } @@ -153,7 +153,7 @@ public > C setParameters(List> params) if (this.parameters == CtElementImpl.>emptyList()) { this.parameters = new ArrayList<>(PARAMETERS_CONTAINER_DEFAULT_CAPACITY); } - getFactory().Change().onListDeleteAll(this, PARAMETER, this.parameters, new ArrayList<>(this.parameters)); + getFactory().getEnvironment().getModelChangeListener().onListDeleteAll(this, PARAMETER, this.parameters, new ArrayList<>(this.parameters)); this.parameters.clear(); for (CtParameter p : params) { addParameter(p); @@ -170,7 +170,7 @@ public > C addParameter(CtParameter parameter) { parameters = new ArrayList<>(PARAMETERS_CONTAINER_DEFAULT_CAPACITY); } parameter.setParent(this); - getFactory().Change().onListAdd(this, PARAMETER, this.parameters, parameter); + getFactory().getEnvironment().getModelChangeListener().onListAdd(this, PARAMETER, this.parameters, parameter); parameters.add(parameter); return (C) this; } @@ -180,7 +180,7 @@ public boolean removeParameter(CtParameter parameter) { if (parameters == CtElementImpl.>emptyList()) { return false; } - getFactory().Change().onListDelete(this, PARAMETER, parameters, parameters.indexOf(parameter), parameter); + getFactory().getEnvironment().getModelChangeListener().onListDelete(this, PARAMETER, parameters, parameters.indexOf(parameter), parameter); return parameters.remove(parameter); } @@ -198,7 +198,7 @@ public > C setThrownTypes(Set>emptySet()) { this.thrownTypes = new QualifiedNameBasedSortedSet<>(); } - getFactory().Change().onSetDeleteAll(this, THROWN, this.thrownTypes, new HashSet<>(this.thrownTypes)); + getFactory().getEnvironment().getModelChangeListener().onSetDeleteAll(this, THROWN, this.thrownTypes, new HashSet<>(this.thrownTypes)); this.thrownTypes.clear(); for (CtTypeReference thrownType : thrownTypes) { addThrownType(thrownType); @@ -215,7 +215,7 @@ public > C addThrownType(CtTypeReference(); } throwType.setParent(this); - getFactory().Change().onSetAdd(this, THROWN, this.thrownTypes, throwType); + getFactory().getEnvironment().getModelChangeListener().onSetAdd(this, THROWN, this.thrownTypes, throwType); thrownTypes.add(throwType); return (C) this; } @@ -225,7 +225,7 @@ public boolean removeThrownType(CtTypeReference throwType) if (thrownTypes == CtElementImpl.>emptySet()) { return false; } - getFactory().Change().onSetDelete(this, THROWN, thrownTypes, throwType); + getFactory().getEnvironment().getModelChangeListener().onSetDelete(this, THROWN, thrownTypes, throwType); return thrownTypes.remove(throwType); } @@ -254,7 +254,7 @@ public > C setExpression(CtExpression expression) { if (expression != null) { expression.setParent(this); } - getFactory().Change().onObjectUpdate(this, EXPRESSION, expression, this.expression); + getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, EXPRESSION, expression, this.expression); this.expression = expression; } return (C) this; diff --git a/src/main/java/spoon/support/reflect/code/CtLiteralImpl.java b/src/main/java/spoon/support/reflect/code/CtLiteralImpl.java index f2f167dec7a..000c8c9f3a1 100644 --- a/src/main/java/spoon/support/reflect/code/CtLiteralImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtLiteralImpl.java @@ -45,7 +45,7 @@ public > C setValue(T value) { if (this.value instanceof CtElement) { ((CtElement) this.value).setParent(this); } - getFactory().Change().onObjectUpdate(this, EXPRESSION, value, this.value); + getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, EXPRESSION, value, this.value); this.value = value; return (C) this; } diff --git a/src/main/java/spoon/support/reflect/code/CtLocalVariableImpl.java b/src/main/java/spoon/support/reflect/code/CtLocalVariableImpl.java index 18eae81a477..80262fa819c 100644 --- a/src/main/java/spoon/support/reflect/code/CtLocalVariableImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtLocalVariableImpl.java @@ -86,14 +86,14 @@ public > C setDefaultExpression(CtExpression defaultE if (defaultExpression != null) { defaultExpression.setParent(this); } - getFactory().Change().onObjectUpdate(this, DEFAULT_EXPRESSION, defaultExpression, this.defaultExpression); + getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, DEFAULT_EXPRESSION, defaultExpression, this.defaultExpression); this.defaultExpression = defaultExpression; return (C) this; } @Override public C setSimpleName(String simpleName) { - getFactory().Change().onObjectUpdate(this, NAME, simpleName, this.name); + getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, NAME, simpleName, this.name); this.name = simpleName; return (C) this; } @@ -103,7 +103,7 @@ public C setType(CtTypeReference type) { if (type != null) { type.setParent(this); } - getFactory().Change().onObjectUpdate(this, TYPE, type, this.type); + getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, TYPE, type, this.type); this.type = type; return (C) this; } @@ -121,7 +121,7 @@ public boolean hasModifier(ModifierKind modifier) { @Override public C setModifiers(Set modifiers) { if (modifiers.size() > 0) { - getFactory().Change().onSetDeleteAll(this, MODIFIER, this.modifiers, new HashSet<>(this.modifiers)); + getFactory().getEnvironment().getModelChangeListener().onSetDeleteAll(this, MODIFIER, this.modifiers, new HashSet<>(this.modifiers)); this.modifiers.clear(); for (ModifierKind modifier : modifiers) { addModifier(modifier); @@ -136,7 +136,7 @@ public C addModifier(ModifierKind modifier) { if (modifiers == CtElementImpl.emptySet()) { this.modifiers = EnumSet.noneOf(ModifierKind.class); } - getFactory().Change().onSetAdd(this, MODIFIER, this.modifiers, modifier); + getFactory().getEnvironment().getModelChangeListener().onSetAdd(this, MODIFIER, this.modifiers, modifier); modifiers.add(modifier); return (C) this; } @@ -146,7 +146,7 @@ public boolean removeModifier(ModifierKind modifier) { if (modifiers == CtElementImpl.emptySet()) { return false; } - getFactory().Change().onSetDelete(this, MODIFIER, modifiers, modifier); + getFactory().getEnvironment().getModelChangeListener().onSetDelete(this, MODIFIER, modifiers, modifier); return modifiers.remove(modifier); } diff --git a/src/main/java/spoon/support/reflect/code/CtLoopImpl.java b/src/main/java/spoon/support/reflect/code/CtLoopImpl.java index aa1749b04af..47b56e62906 100644 --- a/src/main/java/spoon/support/reflect/code/CtLoopImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtLoopImpl.java @@ -43,13 +43,13 @@ public CtStatement getBody() { public T setBody(CtStatement statement) { if (statement != null) { CtBlock body = getFactory().Code().getOrCreateCtBlock(statement); - getFactory().Change().onObjectUpdate(this, BODY, body, this.body); + getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, BODY, body, this.body); if (body != null) { body.setParent(this); } this.body = body; } else { - getFactory().Change().onObjectDelete(this, BODY, this.body); + getFactory().getEnvironment().getModelChangeListener().onObjectDelete(this, BODY, this.body); this.body = null; } return (T) this; diff --git a/src/main/java/spoon/support/reflect/code/CtNewArrayImpl.java b/src/main/java/spoon/support/reflect/code/CtNewArrayImpl.java index 93e0ba02790..2044d66240a 100644 --- a/src/main/java/spoon/support/reflect/code/CtNewArrayImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtNewArrayImpl.java @@ -60,7 +60,7 @@ public > C setDimensionExpressions(List(this.dimensionExpressions)); + getFactory().getEnvironment().getModelChangeListener().onListDeleteAll(this, DIMENSION, this.dimensionExpressions, new ArrayList<>(this.dimensionExpressions)); this.dimensionExpressions.clear(); for (CtExpression expr : dimensionExpressions) { addDimensionExpression(expr); @@ -77,7 +77,7 @@ public > C addDimensionExpression(CtExpression dimensionExpressions = new ArrayList<>(NEW_ARRAY_DEFAULT_EXPRESSIONS_CONTAINER_DEFAULT_CAPACITY); } dimension.setParent(this); - getFactory().Change().onListAdd(this, DIMENSION, this.dimensionExpressions, dimension); + getFactory().getEnvironment().getModelChangeListener().onListAdd(this, DIMENSION, this.dimensionExpressions, dimension); dimensionExpressions.add(dimension); return (C) this; } @@ -87,7 +87,7 @@ public boolean removeDimensionExpression(CtExpression dimension) { if (dimensionExpressions == CtElementImpl.>emptyList()) { return false; } - getFactory().Change().onListDelete(this, DIMENSION, dimensionExpressions, dimensionExpressions.indexOf(dimension), dimension); + getFactory().getEnvironment().getModelChangeListener().onListDelete(this, DIMENSION, dimensionExpressions, dimensionExpressions.indexOf(dimension), dimension); return dimensionExpressions.remove(dimension); } @@ -97,7 +97,7 @@ public > C setElements(List> expressions this.expressions = CtElementImpl.emptyList(); return (C) this; } - getFactory().Change().onListDeleteAll(this, EXPRESSION, this.expressions, new ArrayList<>(this.expressions)); + getFactory().getEnvironment().getModelChangeListener().onListDeleteAll(this, EXPRESSION, this.expressions, new ArrayList<>(this.expressions)); this.expressions.clear(); for (CtExpression expr : expressions) { addElement(expr); @@ -114,7 +114,7 @@ public > C addElement(CtExpression expression) { this.expressions = new ArrayList<>(); } expression.setParent(this); - getFactory().Change().onListAdd(this, EXPRESSION, this.expressions, expression); + getFactory().getEnvironment().getModelChangeListener().onListAdd(this, EXPRESSION, this.expressions, expression); expressions.add(expression); return (C) this; } @@ -124,7 +124,7 @@ public boolean removeElement(CtExpression expression) { if (expressions == CtElementImpl.>emptyList()) { return false; } - getFactory().Change().onListDelete(this, EXPRESSION, expressions, expressions.indexOf(expression), expression); + getFactory().getEnvironment().getModelChangeListener().onListDelete(this, EXPRESSION, expressions, expressions.indexOf(expression), expression); return expressions.remove(expression); } diff --git a/src/main/java/spoon/support/reflect/code/CtNewClassImpl.java b/src/main/java/spoon/support/reflect/code/CtNewClassImpl.java index bd3addde974..3bdf9cb094a 100644 --- a/src/main/java/spoon/support/reflect/code/CtNewClassImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtNewClassImpl.java @@ -45,7 +45,7 @@ public N setAnonymousClass(CtClass anonymousClass) { if (anonymousClass != null) { anonymousClass.setParent(this); } - getFactory().Change().onObjectUpdate(this, EXECUTABLE, anonymousClass, this.anonymousClass); + getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, EXECUTABLE, anonymousClass, this.anonymousClass); this.anonymousClass = anonymousClass; return (N) this; } diff --git a/src/main/java/spoon/support/reflect/code/CtOperatorAssignmentImpl.java b/src/main/java/spoon/support/reflect/code/CtOperatorAssignmentImpl.java index 4720fcd4644..44c0a44f157 100644 --- a/src/main/java/spoon/support/reflect/code/CtOperatorAssignmentImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtOperatorAssignmentImpl.java @@ -42,7 +42,7 @@ public BinaryOperatorKind getKind() { @Override public > C setKind(BinaryOperatorKind kind) { - getFactory().Change().onObjectUpdate(this, OPERATOR_KIND, kind, this.kind); + getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, OPERATOR_KIND, kind, this.kind); this.kind = kind; return (C) this; } diff --git a/src/main/java/spoon/support/reflect/code/CtReturnImpl.java b/src/main/java/spoon/support/reflect/code/CtReturnImpl.java index 4674f1dd4ab..407d69c9966 100644 --- a/src/main/java/spoon/support/reflect/code/CtReturnImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtReturnImpl.java @@ -47,7 +47,7 @@ public > T setReturnedExpression(CtExpression expressio if (expression != null) { expression.setParent(this); } - getFactory().Change().onObjectUpdate(this, EXPRESSION, expression, this.returnedExpression); + getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, EXPRESSION, expression, this.returnedExpression); this.returnedExpression = expression; return (T) this; } diff --git a/src/main/java/spoon/support/reflect/code/CtStatementImpl.java b/src/main/java/spoon/support/reflect/code/CtStatementImpl.java index 28d3ff71919..f6a439f7711 100644 --- a/src/main/java/spoon/support/reflect/code/CtStatementImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtStatementImpl.java @@ -274,7 +274,7 @@ public String getLabel() { @Override public T setLabel(String label) { - getFactory().Change().onObjectUpdate(this, LABEL, label, this.label); + getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, LABEL, label, this.label); this.label = label; return (T) this; } diff --git a/src/main/java/spoon/support/reflect/code/CtStatementListImpl.java b/src/main/java/spoon/support/reflect/code/CtStatementListImpl.java index ba6ee23990e..a389bdbc484 100644 --- a/src/main/java/spoon/support/reflect/code/CtStatementListImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtStatementListImpl.java @@ -55,7 +55,7 @@ public T setStatements(List stmts) { this.statements = CtElementImpl.emptyList(); return (T) this; } - getFactory().Change().onListDeleteAll(this, STATEMENT, this.statements, new ArrayList<>(this.statements)); + getFactory().getEnvironment().getModelChangeListener().onListDeleteAll(this, STATEMENT, this.statements, new ArrayList<>(this.statements)); this.statements.clear(); for (CtStatement stmt : stmts) { addStatement(stmt); @@ -72,7 +72,7 @@ public T addStatement(CtStatement statement) { this.statements = new ArrayList<>(BLOCK_STATEMENTS_CONTAINER_DEFAULT_CAPACITY); } statement.setParent(this); - getFactory().Change().onListAdd(this, STATEMENT, this.statements, statement); + getFactory().getEnvironment().getModelChangeListener().onListAdd(this, STATEMENT, this.statements, statement); this.statements.add(statement); return (T) this; } @@ -82,7 +82,7 @@ public void removeStatement(CtStatement statement) { if (this.statements == CtElementImpl.emptyList()) { return; } - getFactory().Change().onListDelete(this, STATEMENT, statements, statements.indexOf(statement), statement); + getFactory().getEnvironment().getModelChangeListener().onListDelete(this, STATEMENT, statements, statements.indexOf(statement), statement); statements.remove(statement); } diff --git a/src/main/java/spoon/support/reflect/code/CtSuperAccessImpl.java b/src/main/java/spoon/support/reflect/code/CtSuperAccessImpl.java index 103a9b9979f..3d32920b3d7 100644 --- a/src/main/java/spoon/support/reflect/code/CtSuperAccessImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtSuperAccessImpl.java @@ -47,7 +47,7 @@ public >> C setTarget(CtExpres if (target != null) { target.setParent(this); } - getFactory().Change().onObjectUpdate(this, TARGET, target, this.target); + getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, TARGET, target, this.target); this.target = target; return null; } diff --git a/src/main/java/spoon/support/reflect/code/CtSwitchImpl.java b/src/main/java/spoon/support/reflect/code/CtSwitchImpl.java index 82b31c966a3..e0a6bd5bd01 100644 --- a/src/main/java/spoon/support/reflect/code/CtSwitchImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtSwitchImpl.java @@ -61,7 +61,7 @@ public > T setCases(List> cases) { this.cases = CtElementImpl.emptyList(); return (T) this; } - getFactory().Change().onListDeleteAll(this, CASE, this.cases, new ArrayList<>(this.cases)); + getFactory().getEnvironment().getModelChangeListener().onListDeleteAll(this, CASE, this.cases, new ArrayList<>(this.cases)); this.cases.clear(); for (CtCase aCase : cases) { addCase(aCase); @@ -74,7 +74,7 @@ public > T setSelector(CtExpression selector) { if (selector != null) { selector.setParent(this); } - getFactory().Change().onObjectUpdate(this, EXPRESSION, selector, this.expression); + getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, EXPRESSION, selector, this.expression); this.expression = selector; return (T) this; } @@ -88,7 +88,7 @@ public > T addCase(CtCase c) { cases = new ArrayList<>(SWITCH_CASES_CONTAINER_DEFAULT_CAPACITY); } c.setParent(this); - getFactory().Change().onListAdd(this, CASE, this.cases, c); + getFactory().getEnvironment().getModelChangeListener().onListAdd(this, CASE, this.cases, c); cases.add(c); return (T) this; } @@ -98,7 +98,7 @@ public boolean removeCase(CtCase c) { if (cases == CtElementImpl.>emptyList()) { return false; } - getFactory().Change().onListDelete(this, CASE, cases, cases.indexOf(c), c); + getFactory().getEnvironment().getModelChangeListener().onListDelete(this, CASE, cases, cases.indexOf(c), c); return cases.remove(c); } diff --git a/src/main/java/spoon/support/reflect/code/CtSynchronizedImpl.java b/src/main/java/spoon/support/reflect/code/CtSynchronizedImpl.java index 8eaace2fbae..289032a4b55 100644 --- a/src/main/java/spoon/support/reflect/code/CtSynchronizedImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtSynchronizedImpl.java @@ -55,7 +55,7 @@ public T setBlock(CtBlock block) { if (block != null) { block.setParent(this); } - getFactory().Change().onObjectUpdate(this, BODY, block, this.block); + getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, BODY, block, this.block); this.block = block; return (T) this; } @@ -65,7 +65,7 @@ public T setExpression(CtExpression expression) { if (expression != null) { expression.setParent(this); } - getFactory().Change().onObjectUpdate(this, EXPRESSION, expression, this.expression); + getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, EXPRESSION, expression, this.expression); this.expression = expression; return (T) this; } diff --git a/src/main/java/spoon/support/reflect/code/CtTargetedExpressionImpl.java b/src/main/java/spoon/support/reflect/code/CtTargetedExpressionImpl.java index f9549120171..1f454f58ed7 100644 --- a/src/main/java/spoon/support/reflect/code/CtTargetedExpressionImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtTargetedExpressionImpl.java @@ -39,7 +39,7 @@ public > C setTarget(T target) { if (target != null) { target.setParent(this); } - getFactory().Change().onObjectUpdate(this, TARGET, target, this.target); + getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, TARGET, target, this.target); this.target = target; return (C) this; } diff --git a/src/main/java/spoon/support/reflect/code/CtThrowImpl.java b/src/main/java/spoon/support/reflect/code/CtThrowImpl.java index 0837a5a5f0c..dce47ba94a1 100644 --- a/src/main/java/spoon/support/reflect/code/CtThrowImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtThrowImpl.java @@ -47,7 +47,7 @@ public T setThrownExpression(CtExpression T setCatchers(List catchers) { this.catchers = CtElementImpl.emptyList(); return (T) this; } - getFactory().Change().onListDeleteAll(this, CATCH, this.catchers, new ArrayList<>(this.catchers)); + getFactory().getEnvironment().getModelChangeListener().onListDeleteAll(this, CATCH, this.catchers, new ArrayList<>(this.catchers)); this.catchers.clear(); for (CtCatch c : catchers) { addCatcher(c); @@ -81,7 +81,7 @@ public T addCatcher(CtCatch catcher) { catchers = new ArrayList<>(CATCH_CASES_CONTAINER_DEFAULT_CAPACITY); } catcher.setParent(this); - getFactory().Change().onListAdd(this, CATCH, this.catchers, catcher); + getFactory().getEnvironment().getModelChangeListener().onListAdd(this, CATCH, this.catchers, catcher); catchers.add(catcher); return (T) this; } @@ -91,7 +91,7 @@ public boolean removeCatcher(CtCatch catcher) { if (catchers == CtElementImpl.emptyList()) { return false; } - getFactory().Change().onListDelete(this, CATCH, catchers, catchers.indexOf(catcher), catcher); + getFactory().getEnvironment().getModelChangeListener().onListDelete(this, CATCH, catchers, catchers.indexOf(catcher), catcher); return catchers.remove(catcher); } @@ -105,7 +105,7 @@ public T setFinalizer(CtBlock finalizer) { if (finalizer != null) { finalizer.setParent(this); } - getFactory().Change().onObjectUpdate(this, FINALIZER, finalizer, this.finalizer); + getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, FINALIZER, finalizer, this.finalizer); this.finalizer = finalizer; return (T) this; } @@ -119,13 +119,13 @@ public CtBlock getBody() { public T setBody(CtStatement statement) { if (statement != null) { CtBlock body = getFactory().Code().getOrCreateCtBlock(statement); - getFactory().Change().onObjectUpdate(this, BODY, body, this.body); + getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, BODY, body, this.body); if (body != null) { body.setParent(this); } this.body = body; } else { - getFactory().Change().onObjectDelete(this, BODY, this.body); + getFactory().getEnvironment().getModelChangeListener().onObjectDelete(this, BODY, this.body); this.body = null; } diff --git a/src/main/java/spoon/support/reflect/code/CtTryWithResourceImpl.java b/src/main/java/spoon/support/reflect/code/CtTryWithResourceImpl.java index bc0bf7d49bf..5cef71b879d 100644 --- a/src/main/java/spoon/support/reflect/code/CtTryWithResourceImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtTryWithResourceImpl.java @@ -51,7 +51,7 @@ public T setResources(List> res this.resources = CtElementImpl.emptyList(); return (T) this; } - getFactory().Change().onListDeleteAll(this, TRY_RESOURCE, this.resources, new ArrayList<>(this.resources)); + getFactory().getEnvironment().getModelChangeListener().onListDeleteAll(this, TRY_RESOURCE, this.resources, new ArrayList<>(this.resources)); this.resources.clear(); for (CtLocalVariable l : resources) { addResource(l); @@ -68,7 +68,7 @@ public T addResource(CtLocalVariable resource) resources = new ArrayList<>(RESOURCES_CONTAINER_DEFAULT_CAPACITY); } resource.setParent(this); - getFactory().Change().onListAdd(this, TRY_RESOURCE, this.resources, resource); + getFactory().getEnvironment().getModelChangeListener().onListAdd(this, TRY_RESOURCE, this.resources, resource); resources.add(resource); return (T) this; } @@ -78,7 +78,7 @@ public boolean removeResource(CtLocalVariable resource) { if (resources == CtElementImpl.>emptyList()) { return false; } - getFactory().Change().onListDelete(this, TRY_RESOURCE, resources, resources.indexOf(resource), resource); + getFactory().getEnvironment().getModelChangeListener().onListDelete(this, TRY_RESOURCE, resources, resources.indexOf(resource), resource); return resources.remove(resource); } diff --git a/src/main/java/spoon/support/reflect/code/CtTypeAccessImpl.java b/src/main/java/spoon/support/reflect/code/CtTypeAccessImpl.java index 24997493f54..25000da53af 100644 --- a/src/main/java/spoon/support/reflect/code/CtTypeAccessImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtTypeAccessImpl.java @@ -46,7 +46,7 @@ public > C setAccessedType(CtTypeReference accessed if (accessedType != null) { accessedType.setParent(this); } - getFactory().Change().onObjectUpdate(this, TYPE, accessedType, this.type); + getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, TYPE, accessedType, this.type); type = accessedType; return (C) this; } diff --git a/src/main/java/spoon/support/reflect/code/CtUnaryOperatorImpl.java b/src/main/java/spoon/support/reflect/code/CtUnaryOperatorImpl.java index 0cfada9644d..22cc6d3245f 100644 --- a/src/main/java/spoon/support/reflect/code/CtUnaryOperatorImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtUnaryOperatorImpl.java @@ -91,21 +91,21 @@ public C setOperand(CtExpression expression) { if (expression != null) { expression.setParent(this); } - getFactory().Change().onObjectUpdate(this, EXPRESSION, expression, this.operand); + getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, EXPRESSION, expression, this.operand); this.operand = expression; return (C) this; } @Override public C setKind(UnaryOperatorKind kind) { - getFactory().Change().onObjectUpdate(this, OPERATOR_KIND, kind, this.kind); + getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, OPERATOR_KIND, kind, this.kind); this.kind = kind; return (C) this; } @Override public C setLabel(String label) { - getFactory().Change().onObjectUpdate(this, LABEL, label, this.label); + getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, LABEL, label, this.label); this.label = label; return (C) this; } diff --git a/src/main/java/spoon/support/reflect/code/CtVariableAccessImpl.java b/src/main/java/spoon/support/reflect/code/CtVariableAccessImpl.java index 39955928e53..7b78ad32637 100644 --- a/src/main/java/spoon/support/reflect/code/CtVariableAccessImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtVariableAccessImpl.java @@ -50,7 +50,7 @@ public > C setVariable(CtVariableReference vari if (variable != null) { variable.setParent(this); } - getFactory().Change().onObjectUpdate(this, VARIABLE, variable, this.variable); + getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, VARIABLE, variable, this.variable); this.variable = variable; return (C) this; } diff --git a/src/main/java/spoon/support/reflect/code/CtWhileImpl.java b/src/main/java/spoon/support/reflect/code/CtWhileImpl.java index 8ee422fec78..b4bfd30242a 100644 --- a/src/main/java/spoon/support/reflect/code/CtWhileImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtWhileImpl.java @@ -45,7 +45,7 @@ public T setLoopingExpression(CtExpression expressi if (expression != null) { expression.setParent(this); } - getFactory().Change().onObjectUpdate(this, EXPRESSION, expression, this.expression); + getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, EXPRESSION, expression, this.expression); this.expression = expression; return (T) this; } diff --git a/src/main/java/spoon/support/reflect/declaration/CtAnnotationImpl.java b/src/main/java/spoon/support/reflect/declaration/CtAnnotationImpl.java index 1bdaa1df2c9..1c9f70b22b7 100644 --- a/src/main/java/spoon/support/reflect/declaration/CtAnnotationImpl.java +++ b/src/main/java/spoon/support/reflect/declaration/CtAnnotationImpl.java @@ -193,7 +193,7 @@ private > T addValueExpression(String elementName, CtE } else { // Add the new value. expression.setParent(this); - getFactory().Change().onMapAdd(this, VALUE, this.elementValues, elementName, expression); + getFactory().getEnvironment().getModelChangeListener().onMapAdd(this, VALUE, this.elementValues, elementName, expression); elementValues.put(elementName, expression); } return (T) this; @@ -389,14 +389,14 @@ public > T setAnnotationType(CtTypeReference) annotationType; return (T) this; } @Override public > T setElementValues(Map values) { - getFactory().Change().onMapDeleteAll(this, VALUE, this.elementValues, new HashMap<>(elementValues)); + getFactory().getEnvironment().getModelChangeListener().onMapDeleteAll(this, VALUE, this.elementValues, new HashMap<>(elementValues)); this.elementValues.clear(); for (Entry e : values.entrySet()) { addValue(e.getKey(), e.getValue()); @@ -406,7 +406,7 @@ public > T setElementValues(Map values @Override public > T setValues(Map values) { - getFactory().Change().onMapDeleteAll(this, VALUE, this.elementValues, new HashMap<>(elementValues)); + getFactory().getEnvironment().getModelChangeListener().onMapDeleteAll(this, VALUE, this.elementValues, new HashMap<>(elementValues)); this.elementValues.clear(); for (Entry e : values.entrySet()) { addValue(e.getKey(), e.getValue()); @@ -502,7 +502,7 @@ public boolean isShadow() { @Override public E setShadow(boolean isShadow) { - getFactory().Change().onObjectUpdate(this, IS_SHADOW, isShadow, this.isShadow); + getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, IS_SHADOW, isShadow, this.isShadow); this.isShadow = isShadow; return (E) this; } diff --git a/src/main/java/spoon/support/reflect/declaration/CtAnnotationMethodImpl.java b/src/main/java/spoon/support/reflect/declaration/CtAnnotationMethodImpl.java index e1f2bb3d811..90dfc487da5 100644 --- a/src/main/java/spoon/support/reflect/declaration/CtAnnotationMethodImpl.java +++ b/src/main/java/spoon/support/reflect/declaration/CtAnnotationMethodImpl.java @@ -46,7 +46,7 @@ public > C setDefaultExpression(CtExpression if (assignedExpression != null) { assignedExpression.setParent(this); } - getFactory().Change().onObjectUpdate(this, DEFAULT_EXPRESSION, assignedExpression, this.defaultExpression); + getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, DEFAULT_EXPRESSION, assignedExpression, this.defaultExpression); this.defaultExpression = assignedExpression; return (C) this; } diff --git a/src/main/java/spoon/support/reflect/declaration/CtAnonymousExecutableImpl.java b/src/main/java/spoon/support/reflect/declaration/CtAnonymousExecutableImpl.java index 91b670bf1cd..11d5c9db83d 100644 --- a/src/main/java/spoon/support/reflect/declaration/CtAnonymousExecutableImpl.java +++ b/src/main/java/spoon/support/reflect/declaration/CtAnonymousExecutableImpl.java @@ -52,7 +52,7 @@ public T addModifier(ModifierKind modifier) { if (modifiers == CtElementImpl.emptySet()) { modifiers = EnumSet.noneOf(ModifierKind.class); } - getFactory().Change().onSetAdd(this, MODIFIER, this.modifiers, modifier); + getFactory().getEnvironment().getModelChangeListener().onSetAdd(this, MODIFIER, this.modifiers, modifier); modifiers.add(modifier); return (T) this; } @@ -62,7 +62,7 @@ public boolean removeModifier(ModifierKind modifier) { if (modifiers == CtElementImpl.emptySet()) { return false; } - getFactory().Change().onSetDelete(this, MODIFIER, modifiers, modifier); + getFactory().getEnvironment().getModelChangeListener().onSetDelete(this, MODIFIER, modifiers, modifier); return modifiers.remove(modifier); } @@ -93,7 +93,7 @@ public boolean hasModifier(ModifierKind modifier) { @Override public T setModifiers(Set modifiers) { if (modifiers.size() > 0) { - getFactory().Change().onSetDelete(this, MODIFIER, this.modifiers, new HashSet<>(this.modifiers)); + getFactory().getEnvironment().getModelChangeListener().onSetDelete(this, MODIFIER, this.modifiers, new HashSet<>(this.modifiers)); this.modifiers.clear(); for (ModifierKind modifier : modifiers) { addModifier(modifier); diff --git a/src/main/java/spoon/support/reflect/declaration/CtClassImpl.java b/src/main/java/spoon/support/reflect/declaration/CtClassImpl.java index 1f428c70cbd..281f6814035 100644 --- a/src/main/java/spoon/support/reflect/declaration/CtClassImpl.java +++ b/src/main/java/spoon/support/reflect/declaration/CtClassImpl.java @@ -117,13 +117,13 @@ public > C addAnonymousExecutable(CtAnonymousExecutable e) return (C) this; } e.setParent(this); - getFactory().Change().onListAdd(this, EXECUTABLE, typeMembers, e); + getFactory().getEnvironment().getModelChangeListener().onListAdd(this, EXECUTABLE, typeMembers, e); return addTypeMember(e); } @Override public boolean removeAnonymousExecutable(CtAnonymousExecutable e) { - getFactory().Change().onListDelete(this, EXECUTABLE, typeMembers, typeMembers.indexOf(e), e); + getFactory().getEnvironment().getModelChangeListener().onListDelete(this, EXECUTABLE, typeMembers, typeMembers.indexOf(e), e); return removeTypeMember(e); } @@ -134,7 +134,7 @@ public CtTypeReference getSuperclass() { @Override public > C setAnonymousExecutables(List anonymousExecutables) { - getFactory().Change().onListDelete(this, EXECUTABLE, typeMembers, new ArrayList<>(getAnonymousExecutables())); + getFactory().getEnvironment().getModelChangeListener().onListDelete(this, EXECUTABLE, typeMembers, new ArrayList<>(getAnonymousExecutables())); if (anonymousExecutables == null || anonymousExecutables.isEmpty()) { this.typeMembers.removeAll(getAnonymousExecutables()); return (C) this; @@ -149,7 +149,7 @@ public > C setAnonymousExecutables(List> C setConstructors(Set> constructors) { Set> oldConstructor = getConstructors(); - getFactory().Change().onListDelete(this, CONSTRUCTOR, typeMembers, oldConstructor); + getFactory().getEnvironment().getModelChangeListener().onListDelete(this, CONSTRUCTOR, typeMembers, oldConstructor); if (constructors == null || constructors.isEmpty()) { this.typeMembers.removeAll(oldConstructor); return (C) this; @@ -163,7 +163,7 @@ public > C setConstructors(Set> constructo @Override public > C addConstructor(CtConstructor constructor) { - getFactory().Change().onListAdd(this, CONSTRUCTOR, typeMembers, constructor); + getFactory().getEnvironment().getModelChangeListener().onListAdd(this, CONSTRUCTOR, typeMembers, constructor); return addTypeMember(constructor); } @@ -177,7 +177,7 @@ public > C setSuperclass(CtTypeReference superClass) { if (superClass != null) { superClass.setParent(this); } - getFactory().Change().onObjectUpdate(this, SUPER_TYPE, superClass, this.superClass); + getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, SUPER_TYPE, superClass, this.superClass); this.superClass = superClass; return (C) this; } diff --git a/src/main/java/spoon/support/reflect/declaration/CtConstructorImpl.java b/src/main/java/spoon/support/reflect/declaration/CtConstructorImpl.java index ced1083f1d6..2d3177e35a3 100644 --- a/src/main/java/spoon/support/reflect/declaration/CtConstructorImpl.java +++ b/src/main/java/spoon/support/reflect/declaration/CtConstructorImpl.java @@ -105,7 +105,7 @@ public C setFormalCtTypeParameters(ListemptyList()) { this.formalCtTypeParameters = new ArrayList<>(TYPE_TYPE_PARAMETERS_CONTAINER_DEFAULT_CAPACITY); } - getFactory().Change().onListDeleteAll(this, TYPE_PARAMETER, this.formalCtTypeParameters, new ArrayList<>(this.formalCtTypeParameters)); + getFactory().getEnvironment().getModelChangeListener().onListDeleteAll(this, TYPE_PARAMETER, this.formalCtTypeParameters, new ArrayList<>(this.formalCtTypeParameters)); this.formalCtTypeParameters.clear(); for (CtTypeParameter formalTypeParameter : formalTypeParameters) { addFormalCtTypeParameter(formalTypeParameter); @@ -118,7 +118,7 @@ public C addFormalCtTypeParameter(CtTypeParamet if (formalTypeParameter == null) { return (C) this; } - getFactory().Change().onListAdd(this, TYPE_PARAMETER, this.formalCtTypeParameters, formalTypeParameter); + getFactory().getEnvironment().getModelChangeListener().onListAdd(this, TYPE_PARAMETER, this.formalCtTypeParameters, formalTypeParameter); if (formalCtTypeParameters == CtElementImpl.emptyList()) { formalCtTypeParameters = new ArrayList<>(TYPE_TYPE_PARAMETERS_CONTAINER_DEFAULT_CAPACITY); } @@ -132,7 +132,7 @@ public boolean removeFormalCtTypeParameter(CtTypeParameter formalTypeParameter) if (!formalCtTypeParameters.contains(formalTypeParameter)) { return false; } - getFactory().Change().onListDelete(this, TYPE_PARAMETER, formalCtTypeParameters, formalCtTypeParameters.indexOf(formalTypeParameter), formalTypeParameter); + getFactory().getEnvironment().getModelChangeListener().onListDelete(this, TYPE_PARAMETER, formalCtTypeParameters, formalCtTypeParameters.indexOf(formalTypeParameter), formalTypeParameter); return formalCtTypeParameters.remove(formalTypeParameter); } @@ -149,7 +149,7 @@ public boolean hasModifier(ModifierKind modifier) { @Override public C setModifiers(Set modifiers) { if (modifiers.size() > 0) { - getFactory().Change().onSetDeleteAll(this, MODIFIER, this.modifiers, new HashSet<>(this.modifiers)); + getFactory().getEnvironment().getModelChangeListener().onSetDeleteAll(this, MODIFIER, this.modifiers, new HashSet<>(this.modifiers)); this.modifiers.clear(); for (ModifierKind modifier : modifiers) { addModifier(modifier); @@ -163,7 +163,7 @@ public C addModifier(ModifierKind modifier) { if (modifiers == CtElementImpl.emptySet()) { this.modifiers = EnumSet.noneOf(ModifierKind.class); } - getFactory().Change().onSetAdd(this, MODIFIER, this.modifiers, modifier); + getFactory().getEnvironment().getModelChangeListener().onSetAdd(this, MODIFIER, this.modifiers, modifier); modifiers.add(modifier); return (C) this; } @@ -173,7 +173,7 @@ public boolean removeModifier(ModifierKind modifier) { if (modifiers == CtElementImpl.emptySet()) { return false; } - getFactory().Change().onSetDelete(this, MODIFIER, modifiers, modifier); + getFactory().getEnvironment().getModelChangeListener().onSetDelete(this, MODIFIER, modifiers, modifier); return modifiers.remove(modifier); } @@ -213,7 +213,7 @@ public boolean isShadow() { @Override public E setShadow(boolean isShadow) { - getFactory().Change().onObjectUpdate(this, IS_SHADOW, isShadow, this.isShadow); + getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, IS_SHADOW, isShadow, this.isShadow); this.isShadow = isShadow; return (E) this; } diff --git a/src/main/java/spoon/support/reflect/declaration/CtElementImpl.java b/src/main/java/spoon/support/reflect/declaration/CtElementImpl.java index bb56d2623b5..6395a36ec69 100644 --- a/src/main/java/spoon/support/reflect/declaration/CtElementImpl.java +++ b/src/main/java/spoon/support/reflect/declaration/CtElementImpl.java @@ -173,7 +173,7 @@ public E setAnnotations(List(this.annotations)); + getFactory().getEnvironment().getModelChangeListener().onListDeleteAll(this, ANNOTATION, this.annotations, new ArrayList<>(this.annotations)); this.annotations.clear(); for (CtAnnotation annot : annotations) { addAnnotation(annot); @@ -195,7 +195,7 @@ public E addAnnotation(CtAnnotation this.annotations = new ArrayList<>(ANNOTATIONS_CONTAINER_DEFAULT_CAPACITY); } annotation.setParent(this); - getFactory().Change().onListAdd(this, ANNOTATION, this.annotations, annotation); + getFactory().getEnvironment().getModelChangeListener().onListAdd(this, ANNOTATION, this.annotations, annotation); this.annotations.add(annotation); return (E) this; } @@ -204,7 +204,7 @@ public boolean removeAnnotation(CtAnnotation annotation) { if (this.annotations == CtElementImpl.>emptyList()) { return false; } - getFactory().Change().onListDelete(this, ANNOTATION, annotations, annotations.indexOf(annotation), annotation); + getFactory().getEnvironment().getModelChangeListener().onListDelete(this, ANNOTATION, annotations, annotations.indexOf(annotation), annotation); return this.annotations.remove(annotation); } @@ -220,7 +220,7 @@ public E setDocComment(String docComment) { } public E setPosition(SourcePosition position) { - getFactory().Change().onObjectUpdate(this, POSITION, position, this.position); + getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, POSITION, position, this.position); this.position = position; return (E) this; } @@ -264,7 +264,7 @@ public boolean isImplicit() { } public E setImplicit(boolean implicit) { - getFactory().Change().onObjectUpdate(this, IS_IMPLICIT, implicit, this.implicit); + getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, IS_IMPLICIT, implicit, this.implicit); this.implicit = implicit; return (E) this; } @@ -437,7 +437,7 @@ public E addComment(CtComment comment) { comments = new ArrayList<>(COMMENT_CONTAINER_DEFAULT_CAPACITY); } comment.setParent(this); - getFactory().Change().onListAdd(this, COMMENT, this.comments, comment); + getFactory().getEnvironment().getModelChangeListener().onListAdd(this, COMMENT, this.comments, comment); comments.add(comment); return (E) this; } @@ -447,7 +447,7 @@ public E removeComment(CtComment comment) { if (this.comments == CtElementImpl.emptyList()) { return (E) this; } - getFactory().Change().onListDelete(this, COMMENT, comments, comments.indexOf(comment), comment); + getFactory().getEnvironment().getModelChangeListener().onListDelete(this, COMMENT, comments, comments.indexOf(comment), comment); this.comments.remove(comment); return (E) this; } @@ -458,7 +458,7 @@ public E setComments(List comments) { this.comments = CtElementImpl.emptyList(); return (E) this; } - getFactory().Change().onListDeleteAll(this, COMMENT, this.comments, new ArrayList<>(this.comments)); + getFactory().getEnvironment().getModelChangeListener().onListDeleteAll(this, COMMENT, this.comments, new ArrayList<>(this.comments)); this.comments.clear(); for (CtComment comment : comments) { addComment(comment); diff --git a/src/main/java/spoon/support/reflect/declaration/CtEnumImpl.java b/src/main/java/spoon/support/reflect/declaration/CtEnumImpl.java index 12e6433283c..a31aecbd8c1 100644 --- a/src/main/java/spoon/support/reflect/declaration/CtEnumImpl.java +++ b/src/main/java/spoon/support/reflect/declaration/CtEnumImpl.java @@ -75,7 +75,7 @@ public > C addEnumValue(CtEnumValue enumValue) { } if (!enumValues.contains(enumValue)) { enumValue.setParent(this); - getFactory().Change().onListAdd(this, VALUE, this.enumValues, enumValue); + getFactory().getEnvironment().getModelChangeListener().onListAdd(this, VALUE, this.enumValues, enumValue); enumValues.add(enumValue); } @@ -88,7 +88,7 @@ public boolean removeEnumValue(CtEnumValue enumValue) { if (enumValues == CtElementImpl.>emptyList()) { return false; } - getFactory().Change().onListDelete(this, VALUE, enumValues, enumValues.indexOf(enumValue), enumValue); + getFactory().getEnvironment().getModelChangeListener().onListDelete(this, VALUE, enumValues, enumValues.indexOf(enumValue), enumValue); return enumValues.remove(enumValue); } @@ -109,7 +109,7 @@ public List> getEnumValues() { @Override public > C setEnumValues(List> enumValues) { - getFactory().Change().onListDeleteAll(this, VALUE, this.enumValues, new ArrayList<>(enumValues)); + getFactory().getEnvironment().getModelChangeListener().onListDeleteAll(this, VALUE, this.enumValues, new ArrayList<>(enumValues)); if (enumValues == null || enumValues.isEmpty()) { this.enumValues = emptyList(); return (C) this; diff --git a/src/main/java/spoon/support/reflect/declaration/CtExecutableImpl.java b/src/main/java/spoon/support/reflect/declaration/CtExecutableImpl.java index 14f22539098..46b9c2aaa2d 100644 --- a/src/main/java/spoon/support/reflect/declaration/CtExecutableImpl.java +++ b/src/main/java/spoon/support/reflect/declaration/CtExecutableImpl.java @@ -79,13 +79,13 @@ public CtBlock getBody() { public T setBody(CtStatement statement) { if (statement != null) { CtBlock body = getFactory().Code().getOrCreateCtBlock(statement); - getFactory().Change().onObjectUpdate(this, BODY, body, this.body); + getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, BODY, body, this.body); if (body != null) { body.setParent(this); } this.body = body; } else { - getFactory().Change().onObjectDelete(this, BODY, this.body); + getFactory().getEnvironment().getModelChangeListener().onObjectDelete(this, BODY, this.body); this.body = null; } return (T) this; @@ -105,7 +105,7 @@ public > T setParameters(List> paramete if (this.parameters == CtElementImpl.>emptyList()) { this.parameters = new ArrayList<>(PARAMETERS_CONTAINER_DEFAULT_CAPACITY); } - getFactory().Change().onListDeleteAll(this, PARAMETER, this.parameters, new ArrayList<>(this.parameters)); + getFactory().getEnvironment().getModelChangeListener().onListDeleteAll(this, PARAMETER, this.parameters, new ArrayList<>(this.parameters)); this.parameters.clear(); for (CtParameter p : parameters) { addParameter(p); @@ -122,7 +122,7 @@ public > T addParameter(CtParameter parameter) { parameters = new ArrayList<>(PARAMETERS_CONTAINER_DEFAULT_CAPACITY); } parameter.setParent(this); - getFactory().Change().onListAdd(this, PARAMETER, this.parameters, parameter); + getFactory().getEnvironment().getModelChangeListener().onListAdd(this, PARAMETER, this.parameters, parameter); parameters.add(parameter); return (T) this; } @@ -132,7 +132,7 @@ public boolean removeParameter(CtParameter parameter) { if (parameters == CtElementImpl.>emptyList()) { return false; } - getFactory().Change().onListDelete(this, PARAMETER, parameters, parameters.indexOf(parameter), parameter); + getFactory().getEnvironment().getModelChangeListener().onListDelete(this, PARAMETER, parameters, parameters.indexOf(parameter), parameter); return parameters.remove(parameter); } @@ -150,7 +150,7 @@ public > T setThrownTypes(Set>emptySet()) { this.thrownTypes = new QualifiedNameBasedSortedSet<>(); } - getFactory().Change().onSetDeleteAll(this, THROWN, this.thrownTypes, new HashSet(this.thrownTypes)); + getFactory().getEnvironment().getModelChangeListener().onSetDeleteAll(this, THROWN, this.thrownTypes, new HashSet(this.thrownTypes)); this.thrownTypes.clear(); for (CtTypeReference thrownType : thrownTypes) { addThrownType(thrownType); @@ -167,7 +167,7 @@ public > T addThrownType(CtTypeReference(); } throwType.setParent(this); - getFactory().Change().onSetAdd(this, THROWN, this.thrownTypes, throwType); + getFactory().getEnvironment().getModelChangeListener().onSetAdd(this, THROWN, this.thrownTypes, throwType); thrownTypes.add(throwType); return (T) this; } @@ -177,7 +177,7 @@ public boolean removeThrownType(CtTypeReference throwType) if (thrownTypes == CtElementImpl.>emptySet()) { return false; } - getFactory().Change().onSetDelete(this, THROWN, thrownTypes, throwType); + getFactory().getEnvironment().getModelChangeListener().onSetDelete(this, THROWN, thrownTypes, throwType); return thrownTypes.remove(throwType); } diff --git a/src/main/java/spoon/support/reflect/declaration/CtFieldImpl.java b/src/main/java/spoon/support/reflect/declaration/CtFieldImpl.java index 206ac142bdf..a0b0a4d0e02 100644 --- a/src/main/java/spoon/support/reflect/declaration/CtFieldImpl.java +++ b/src/main/java/spoon/support/reflect/declaration/CtFieldImpl.java @@ -98,7 +98,7 @@ public > C setDefaultExpression(CtExpression defaultE if (defaultExpression != null) { defaultExpression.setParent(this); } - getFactory().Change().onObjectUpdate(this, DEFAULT_EXPRESSION, defaultExpression, this.defaultExpression); + getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, DEFAULT_EXPRESSION, defaultExpression, this.defaultExpression); this.defaultExpression = defaultExpression; return (C) this; } @@ -108,7 +108,7 @@ public C setType(CtTypeReference type) { if (type != null) { type.setParent(this); } - getFactory().Change().onObjectUpdate(this, TYPE, type, this.type); + getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, TYPE, type, this.type); this.type = type; return (C) this; } @@ -126,7 +126,7 @@ public boolean hasModifier(ModifierKind modifier) { @Override public C setModifiers(Set modifiers) { if (modifiers.size() > 0) { - getFactory().Change().onSetDeleteAll(this, MODIFIER, this.modifiers, new HashSet<>(this.modifiers)); + getFactory().getEnvironment().getModelChangeListener().onSetDeleteAll(this, MODIFIER, this.modifiers, new HashSet<>(this.modifiers)); this.modifiers.clear(); for (ModifierKind modifier : modifiers) { addModifier(modifier); @@ -140,7 +140,7 @@ public C addModifier(ModifierKind modifier) { if (modifiers == CtElementImpl.emptySet()) { this.modifiers = EnumSet.noneOf(ModifierKind.class); } - getFactory().Change().onSetAdd(this, MODIFIER, this.modifiers, modifier); + getFactory().getEnvironment().getModelChangeListener().onSetAdd(this, MODIFIER, this.modifiers, modifier); modifiers.add(modifier); return (C) this; } @@ -150,7 +150,7 @@ public boolean removeModifier(ModifierKind modifier) { if (modifiers == CtElementImpl.emptySet()) { return false; } - getFactory().Change().onSetDelete(this, MODIFIER, modifiers, modifier); + getFactory().getEnvironment().getModelChangeListener().onSetDelete(this, MODIFIER, modifiers, modifier); return modifiers.remove(modifier); } @@ -207,7 +207,7 @@ public boolean isShadow() { @Override public E setShadow(boolean isShadow) { - getFactory().Change().onObjectUpdate(this, IS_SHADOW, isShadow, this.isShadow); + getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, IS_SHADOW, isShadow, this.isShadow); this.isShadow = isShadow; return (E) this; } diff --git a/src/main/java/spoon/support/reflect/declaration/CtMethodImpl.java b/src/main/java/spoon/support/reflect/declaration/CtMethodImpl.java index c99075fd865..bab5e8f12db 100644 --- a/src/main/java/spoon/support/reflect/declaration/CtMethodImpl.java +++ b/src/main/java/spoon/support/reflect/declaration/CtMethodImpl.java @@ -82,7 +82,7 @@ public C setType(CtTypeReference type) { if (type != null) { type.setParent(this); } - getFactory().Change().onObjectUpdate(this, TYPE, type, this.returnType); + getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, TYPE, type, this.returnType); this.returnType = type; return (C) this; } @@ -94,7 +94,7 @@ public boolean isDefaultMethod() { @Override public > C setDefaultMethod(boolean defaultMethod) { - getFactory().Change().onObjectUpdate(this, IS_DEFAULT, defaultMethod, this.defaultMethod); + getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, IS_DEFAULT, defaultMethod, this.defaultMethod); this.defaultMethod = defaultMethod; return (C) this; } @@ -106,7 +106,7 @@ public List getFormalCtTypeParameters() { @Override public C setFormalCtTypeParameters(List formalTypeParameters) { - getFactory().Change().onListDeleteAll(this, TYPE_PARAMETER, this.formalCtTypeParameters, new ArrayList<>(this.formalCtTypeParameters)); + getFactory().getEnvironment().getModelChangeListener().onListDeleteAll(this, TYPE_PARAMETER, this.formalCtTypeParameters, new ArrayList<>(this.formalCtTypeParameters)); if (formalTypeParameters == null || formalTypeParameters.isEmpty()) { this.formalCtTypeParameters = CtElementImpl.emptyList(); return (C) this; @@ -129,7 +129,7 @@ public C addFormalCtTypeParameter(CtTypeParamet if (formalCtTypeParameters == CtElementImpl.emptyList()) { formalCtTypeParameters = new ArrayList<>(TYPE_TYPE_PARAMETERS_CONTAINER_DEFAULT_CAPACITY); } - getFactory().Change().onListAdd(this, TYPE_PARAMETER, this.formalCtTypeParameters, formalTypeParameter); + getFactory().getEnvironment().getModelChangeListener().onListAdd(this, TYPE_PARAMETER, this.formalCtTypeParameters, formalTypeParameter); formalTypeParameter.setParent(this); formalCtTypeParameters.add(formalTypeParameter); return (C) this; @@ -140,7 +140,7 @@ public boolean removeFormalCtTypeParameter(CtTypeParameter formalTypeParameter) if (formalCtTypeParameters == CtElementImpl.emptyList()) { return false; } - getFactory().Change().onListDelete(this, TYPE_PARAMETER, formalCtTypeParameters, formalCtTypeParameters.indexOf(formalTypeParameter), formalTypeParameter); + getFactory().getEnvironment().getModelChangeListener().onListDelete(this, TYPE_PARAMETER, formalCtTypeParameters, formalCtTypeParameters.indexOf(formalTypeParameter), formalTypeParameter); return formalCtTypeParameters.remove(formalTypeParameter); } @@ -157,7 +157,7 @@ public boolean hasModifier(ModifierKind modifier) { @Override public C setModifiers(Set modifiers) { if (modifiers.size() > 0) { - getFactory().Change().onSetDeleteAll(this, MODIFIER, this.modifiers, new HashSet<>(this.modifiers)); + getFactory().getEnvironment().getModelChangeListener().onSetDeleteAll(this, MODIFIER, this.modifiers, new HashSet<>(this.modifiers)); this.modifiers.clear(); for (ModifierKind modifier : modifiers) { addModifier(modifier); @@ -171,7 +171,7 @@ public C addModifier(ModifierKind modifier) { if (modifiers == CtElementImpl.emptySet()) { this.modifiers = EnumSet.noneOf(ModifierKind.class); } - getFactory().Change().onSetAdd(this, MODIFIER, this.modifiers, modifier); + getFactory().getEnvironment().getModelChangeListener().onSetAdd(this, MODIFIER, this.modifiers, modifier); modifiers.add(modifier); return (C) this; } @@ -181,7 +181,7 @@ public boolean removeModifier(ModifierKind modifier) { if (modifiers == CtElementImpl.emptySet()) { return false; } - getFactory().Change().onSetDelete(this, MODIFIER, modifiers, modifier); + getFactory().getEnvironment().getModelChangeListener().onSetDelete(this, MODIFIER, modifiers, modifier); return modifiers.remove(modifier); } @@ -231,7 +231,7 @@ public boolean isShadow() { @Override public E setShadow(boolean isShadow) { - getFactory().Change().onObjectUpdate(this, IS_SHADOW, isShadow, this.isShadow); + getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, IS_SHADOW, isShadow, this.isShadow); this.isShadow = isShadow; return (E) this; } diff --git a/src/main/java/spoon/support/reflect/declaration/CtNamedElementImpl.java b/src/main/java/spoon/support/reflect/declaration/CtNamedElementImpl.java index f2677d56fd2..39a5ddcbbc9 100644 --- a/src/main/java/spoon/support/reflect/declaration/CtNamedElementImpl.java +++ b/src/main/java/spoon/support/reflect/declaration/CtNamedElementImpl.java @@ -52,7 +52,7 @@ public T setSimpleName(String simpleName) { if (factory instanceof FactoryImpl) { simpleName = ((FactoryImpl) factory).dedup(simpleName); } - getFactory().Change().onObjectUpdate(this, NAME, simpleName, this.simpleName); + getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, NAME, simpleName, this.simpleName); this.simpleName = simpleName; return (T) this; } diff --git a/src/main/java/spoon/support/reflect/declaration/CtPackageImpl.java b/src/main/java/spoon/support/reflect/declaration/CtPackageImpl.java index bb2c85770fc..6f6d9746fef 100644 --- a/src/main/java/spoon/support/reflect/declaration/CtPackageImpl.java +++ b/src/main/java/spoon/support/reflect/declaration/CtPackageImpl.java @@ -82,7 +82,7 @@ public T addPackage(CtPackage pack) { } pack.setParent(this); - getFactory().Change().onSetAdd(this, SUB_PACKAGE, this.packs, pack); + getFactory().getEnvironment().getModelChangeListener().onSetAdd(this, SUB_PACKAGE, this.packs, pack); this.packs.add(pack); return (T) this; @@ -120,7 +120,7 @@ public boolean removePackage(CtPackage pack) { if (packs == CtElementImpl.emptySet()) { return false; } - getFactory().Change().onSetDelete(this, SUB_PACKAGE, packs, pack); + getFactory().getEnvironment().getModelChangeListener().onSetDelete(this, SUB_PACKAGE, packs, pack); return packs.remove(pack); } @@ -179,7 +179,7 @@ public T setPackages(Set packs) { this.packs = CtElementImpl.emptySet(); return (T) this; } - getFactory().Change().onSetDeleteAll(this, SUB_PACKAGE, this.packs, new HashSet<>(this.packs)); + getFactory().getEnvironment().getModelChangeListener().onSetDeleteAll(this, SUB_PACKAGE, this.packs, new HashSet<>(this.packs)); this.packs.clear(); for (CtPackage p : packs) { addPackage(p); @@ -193,7 +193,7 @@ public T setTypes(Set> types) { this.types = CtElementImpl.emptySet(); return (T) this; } - getFactory().Change().onSetDeleteAll(this, TYPE, this.types, new HashSet<>(this.types)); + getFactory().getEnvironment().getModelChangeListener().onSetDeleteAll(this, TYPE, this.types, new HashSet<>(this.types)); this.types.clear(); for (CtType t : types) { addType(t); @@ -215,7 +215,7 @@ public T addType(CtType type) { this.types = orderedTypeSet(); } type.setParent(this); - getFactory().Change().onSetAdd(this, TYPE, this.types, type); + getFactory().getEnvironment().getModelChangeListener().onSetAdd(this, TYPE, this.types, type); types.add(type); return (T) this; } @@ -225,7 +225,7 @@ public void removeType(CtType type) { if (types == CtElementImpl.>emptySet()) { return; } - getFactory().Change().onSetDelete(this, TYPE, types, type); + getFactory().getEnvironment().getModelChangeListener().onSetDelete(this, TYPE, types, type); types.remove(type); } @@ -257,7 +257,7 @@ public boolean isShadow() { @Override public E setShadow(boolean isShadow) { - getFactory().Change().onObjectUpdate(this, IS_SHADOW, isShadow, this.isShadow); + getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, IS_SHADOW, isShadow, this.isShadow); this.isShadow = isShadow; return (E) this; } diff --git a/src/main/java/spoon/support/reflect/declaration/CtParameterImpl.java b/src/main/java/spoon/support/reflect/declaration/CtParameterImpl.java index e37abede0be..58b906ea184 100644 --- a/src/main/java/spoon/support/reflect/declaration/CtParameterImpl.java +++ b/src/main/java/spoon/support/reflect/declaration/CtParameterImpl.java @@ -93,7 +93,7 @@ public C setType(CtTypeReference type) { if (type != null) { type.setParent(this); } - getFactory().Change().onObjectUpdate(this, TYPE, type, this.type); + getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, TYPE, type, this.type); this.type = type; return (C) this; } @@ -105,7 +105,7 @@ public boolean isVarArgs() { @Override public > C setVarArgs(boolean varArgs) { - getFactory().Change().onObjectUpdate(this, IS_VARARGS, varArgs, this.varArgs); + getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, IS_VARARGS, varArgs, this.varArgs); this.varArgs = varArgs; return (C) this; } @@ -123,7 +123,7 @@ public boolean hasModifier(ModifierKind modifier) { @Override public C setModifiers(Set modifiers) { if (modifiers.size() > 0) { - getFactory().Change().onSetDeleteAll(this, MODIFIER, this.modifiers, new HashSet<>(this.modifiers)); + getFactory().getEnvironment().getModelChangeListener().onSetDeleteAll(this, MODIFIER, this.modifiers, new HashSet<>(this.modifiers)); this.modifiers.clear(); for (ModifierKind modifier : modifiers) { addModifier(modifier); @@ -137,7 +137,7 @@ public C addModifier(ModifierKind modifier) { if (modifiers == CtElementImpl.emptySet()) { this.modifiers = EnumSet.noneOf(ModifierKind.class); } - getFactory().Change().onSetAdd(this, MODIFIER, this.modifiers, modifier); + getFactory().getEnvironment().getModelChangeListener().onSetAdd(this, MODIFIER, this.modifiers, modifier); modifiers.add(modifier); return (C) this; } @@ -147,7 +147,7 @@ public boolean removeModifier(ModifierKind modifier) { if (modifiers == CtElementImpl.emptySet()) { return false; } - getFactory().Change().onSetDelete(this, MODIFIER, modifiers, modifier); + getFactory().getEnvironment().getModelChangeListener().onSetDelete(this, MODIFIER, modifiers, modifier); return modifiers.remove(modifier); } @@ -192,7 +192,7 @@ public boolean isShadow() { @Override public E setShadow(boolean isShadow) { - getFactory().Change().onObjectUpdate(this, IS_SHADOW, isShadow, this.isShadow); + getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, IS_SHADOW, isShadow, this.isShadow); this.isShadow = isShadow; return (E) this; } diff --git a/src/main/java/spoon/support/reflect/declaration/CtTypeImpl.java b/src/main/java/spoon/support/reflect/declaration/CtTypeImpl.java index 5e8e353086c..0725be185b7 100644 --- a/src/main/java/spoon/support/reflect/declaration/CtTypeImpl.java +++ b/src/main/java/spoon/support/reflect/declaration/CtTypeImpl.java @@ -132,7 +132,7 @@ public > C addTypeMemberAt(int position, CtTypeMember member } else { role = NESTED_TYPE; } - getFactory().Change().onListAdd(this, role, this.typeMembers, position, member); + getFactory().getEnvironment().getModelChangeListener().onListAdd(this, role, this.typeMembers, position, member); this.typeMembers.add(position, member); } return (C) this; @@ -152,7 +152,7 @@ public boolean removeTypeMember(CtTypeMember member) { } if (typeMembers.size() == 1) { if (typeMembers.contains(member)) { - getFactory().Change().onListDelete(this, role, this.typeMembers, this.typeMembers.indexOf(member), member); + getFactory().getEnvironment().getModelChangeListener().onListDelete(this, role, this.typeMembers, this.typeMembers.indexOf(member), member); typeMembers = emptyList(); return true; } else { @@ -160,7 +160,7 @@ public boolean removeTypeMember(CtTypeMember member) { } } if (typeMembers.contains(member)) { - getFactory().Change().onListDelete(this, role, this.typeMembers, this.typeMembers.indexOf(member), member); + getFactory().getEnvironment().getModelChangeListener().onListDelete(this, role, this.typeMembers, this.typeMembers.indexOf(member), member); return typeMembers.remove(member); } return false; @@ -204,7 +204,7 @@ public > C setFields(List> fields) { this.typeMembers.removeAll(oldFields); return (C) this; } - getFactory().Change().onListDelete(this, FIELD, this.typeMembers, new ArrayList<>(oldFields)); + getFactory().getEnvironment().getModelChangeListener().onListDelete(this, FIELD, this.typeMembers, new ArrayList<>(oldFields)); typeMembers.removeAll(oldFields); for (CtField field : fields) { addField(field); @@ -264,7 +264,7 @@ public boolean removeNestedType(CtType nestedType) { @Override public > C setNestedTypes(Set> nestedTypes) { Set> oldNestedTypes = getNestedTypes(); - getFactory().Change().onListDelete(this, NESTED_TYPE, typeMembers, oldNestedTypes); + getFactory().getEnvironment().getModelChangeListener().onListDelete(this, NESTED_TYPE, typeMembers, oldNestedTypes); if (nestedTypes == null || nestedTypes.isEmpty()) { this.typeMembers.removeAll(oldNestedTypes); return (C) this; @@ -462,7 +462,7 @@ public boolean hasModifier(ModifierKind modifier) { @Override public C setModifiers(Set modifiers) { if (modifiers.size() > 0) { - getFactory().Change().onSetDeleteAll(this, MODIFIER, this.modifiers, new HashSet<>(this.modifiers)); + getFactory().getEnvironment().getModelChangeListener().onSetDeleteAll(this, MODIFIER, this.modifiers, new HashSet<>(this.modifiers)); this.modifiers.clear(); for (ModifierKind modifier : modifiers) { addModifier(modifier); @@ -476,7 +476,7 @@ public C addModifier(ModifierKind modifier) { if (modifiers == CtElementImpl.emptySet()) { this.modifiers = EnumSet.of(modifier); } - getFactory().Change().onSetAdd(this, MODIFIER, this.modifiers, modifier); + getFactory().getEnvironment().getModelChangeListener().onSetAdd(this, MODIFIER, this.modifiers, modifier); modifiers.add(modifier); return (C) this; } @@ -486,7 +486,7 @@ public boolean removeModifier(ModifierKind modifier) { if (modifiers == CtElementImpl.emptySet()) { return false; } - getFactory().Change().onSetDelete(this, MODIFIER, modifiers, modifier); + getFactory().getEnvironment().getModelChangeListener().onSetDelete(this, MODIFIER, modifiers, modifier); return modifiers.remove(modifier); } @@ -625,14 +625,14 @@ public > C addSuperInterface(CtTypeReference interfac) interfaces = new QualifiedNameBasedSortedSet<>(); } interfac.setParent(this); - getFactory().Change().onSetAdd(this, INTERFACE, this.interfaces, interfac); + getFactory().getEnvironment().getModelChangeListener().onSetAdd(this, INTERFACE, this.interfaces, interfac); interfaces.add(interfac); return (C) this; } @Override public boolean removeSuperInterface(CtTypeReference interfac) { - getFactory().Change().onSetDelete(this, INTERFACE, interfaces, interfac); + getFactory().getEnvironment().getModelChangeListener().onSetDelete(this, INTERFACE, interfaces, interfac); if (interfaces == CtElementImpl.>emptySet()) { return false; } else if (interfaces.size() == 1) { @@ -655,7 +655,7 @@ public List getFormalCtTypeParameters() { @Override public C setFormalCtTypeParameters(List formalTypeParameters) { - getFactory().Change().onListDeleteAll(this, TYPE_PARAMETER, formalCtTypeParameters, new ArrayList<>(formalCtTypeParameters)); + getFactory().getEnvironment().getModelChangeListener().onListDeleteAll(this, TYPE_PARAMETER, formalCtTypeParameters, new ArrayList<>(formalCtTypeParameters)); if (formalTypeParameters == null || formalTypeParameters.isEmpty()) { this.formalCtTypeParameters = CtElementImpl.emptyList(); return (C) this; @@ -679,7 +679,7 @@ public C addFormalCtTypeParameter(CtTypeParamet formalCtTypeParameters = new ArrayList<>(TYPE_TYPE_PARAMETERS_CONTAINER_DEFAULT_CAPACITY); } formalTypeParameter.setParent(this); - getFactory().Change().onListAdd(this, TYPE_PARAMETER, this.formalCtTypeParameters, formalTypeParameter); + getFactory().getEnvironment().getModelChangeListener().onListAdd(this, TYPE_PARAMETER, this.formalCtTypeParameters, formalTypeParameter); formalCtTypeParameters.add(formalTypeParameter); return (C) this; } @@ -689,7 +689,7 @@ public boolean removeFormalCtTypeParameter(CtTypeParameter formalTypeParameter) if (formalCtTypeParameters == CtElementImpl.emptyList()) { return false; } - getFactory().Change().onListDelete(this, TYPE_PARAMETER, formalCtTypeParameters, formalCtTypeParameters.indexOf(formalTypeParameter), formalTypeParameter); + getFactory().getEnvironment().getModelChangeListener().onListDelete(this, TYPE_PARAMETER, formalCtTypeParameters, formalCtTypeParameters.indexOf(formalTypeParameter), formalTypeParameter); return formalCtTypeParameters.remove(formalTypeParameter); } @@ -900,7 +900,7 @@ public Set> getSuperInterfaces() { @Override public > C setMethods(Set> methods) { Set> allMethods = getMethods(); - getFactory().Change().onListDelete(this, EXECUTABLE, this.typeMembers, new ArrayList(allMethods)); + getFactory().getEnvironment().getModelChangeListener().onListDelete(this, EXECUTABLE, this.typeMembers, new ArrayList(allMethods)); typeMembers.removeAll(allMethods); if (methods == null || methods.isEmpty()) { return (C) this; @@ -927,7 +927,7 @@ public > C setSuperInterfaces(Set> interf if (this.interfaces == CtElementImpl.>emptySet()) { this.interfaces = new QualifiedNameBasedSortedSet<>(); } - getFactory().Change().onSetDeleteAll(this, INTERFACE, this.interfaces, new HashSet<>(this.interfaces)); + getFactory().getEnvironment().getModelChangeListener().onSetDeleteAll(this, INTERFACE, this.interfaces, new HashSet<>(this.interfaces)); this.interfaces.clear(); for (CtTypeReference anInterface : interfaces) { addSuperInterface(anInterface); @@ -990,7 +990,7 @@ public boolean isShadow() { @Override public E setShadow(boolean isShadow) { - getFactory().Change().onObjectUpdate(this, IS_SHADOW, isShadow, this.isShadow); + getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, IS_SHADOW, isShadow, this.isShadow); this.isShadow = isShadow; return (E) this; } diff --git a/src/main/java/spoon/support/reflect/declaration/CtTypeParameterImpl.java b/src/main/java/spoon/support/reflect/declaration/CtTypeParameterImpl.java index 57fb4e750f0..f804efaee23 100644 --- a/src/main/java/spoon/support/reflect/declaration/CtTypeParameterImpl.java +++ b/src/main/java/spoon/support/reflect/declaration/CtTypeParameterImpl.java @@ -62,7 +62,7 @@ public > C setSuperclass(CtTypeReference superClass) if (superClass != null) { superClass.setParent(this); } - getFactory().Change().onObjectUpdate(this, SUPER_TYPE, superClass, this.superClass); + getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, SUPER_TYPE, superClass, this.superClass); this.superClass = superClass; return (C) this; } diff --git a/src/main/java/spoon/support/reflect/reference/CtArrayTypeReferenceImpl.java b/src/main/java/spoon/support/reflect/reference/CtArrayTypeReferenceImpl.java index 4296d176ddf..92e6030447c 100644 --- a/src/main/java/spoon/support/reflect/reference/CtArrayTypeReferenceImpl.java +++ b/src/main/java/spoon/support/reflect/reference/CtArrayTypeReferenceImpl.java @@ -61,7 +61,7 @@ public > C setComponentType(CtTypeReference if (componentType != null) { componentType.setParent(this); } - getFactory().Change().onObjectUpdate(this, TYPE, componentType, this.componentType); + getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, TYPE, componentType, this.componentType); this.componentType = componentType; return (C) this; } diff --git a/src/main/java/spoon/support/reflect/reference/CtExecutableReferenceImpl.java b/src/main/java/spoon/support/reflect/reference/CtExecutableReferenceImpl.java index 7a0192e2259..8dddb381c57 100644 --- a/src/main/java/spoon/support/reflect/reference/CtExecutableReferenceImpl.java +++ b/src/main/java/spoon/support/reflect/reference/CtExecutableReferenceImpl.java @@ -203,7 +203,7 @@ public > C setParameters(List>emptyList()) { this.parameters = new ArrayList<>(); } - getFactory().Change().onListDeleteAll(this, PARAMETER, this.parameters, new ArrayList<>(this.parameters)); + getFactory().getEnvironment().getModelChangeListener().onListDeleteAll(this, PARAMETER, this.parameters, new ArrayList<>(this.parameters)); this.parameters.clear(); for (CtTypeReference parameter : parameters) { addParameter(parameter); @@ -216,7 +216,7 @@ private boolean addParameter(CtTypeReference parameter) { return false; } parameter.setParent(this); - getFactory().Change().onListAdd(this, PARAMETER, this.parameters, parameter); + getFactory().getEnvironment().getModelChangeListener().onListAdd(this, PARAMETER, this.parameters, parameter); return this.parameters.add(parameter); } @@ -274,7 +274,7 @@ public C setActualTypeArguments(List>emptyList()) { this.actualTypeArguments = new ArrayList<>(); } - getFactory().Change().onListDeleteAll(this, TYPE_PARAMETER, this.actualTypeArguments, new ArrayList<>(this.actualTypeArguments)); + getFactory().getEnvironment().getModelChangeListener().onListDeleteAll(this, TYPE_PARAMETER, this.actualTypeArguments, new ArrayList<>(this.actualTypeArguments)); this.actualTypeArguments.clear(); for (CtTypeReference actualTypeArgument : actualTypeArguments) { addActualTypeArgument(actualTypeArgument); @@ -287,7 +287,7 @@ public > C setDeclaringType(CtTypeReference> C setType(CtTypeReference type) { if (type != null) { type.setParent(this); } - getFactory().Change().onObjectUpdate(this, TYPE, type, this.type); + getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, TYPE, type, this.type); this.type = type; return (C) this; } @@ -363,7 +363,7 @@ public boolean isStatic() { @Override public > C setStatic(boolean stat) { - getFactory().Change().onObjectUpdate(this, IS_STATIC, stat, this.stat); + getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, IS_STATIC, stat, this.stat); this.stat = stat; return (C) this; } @@ -447,7 +447,7 @@ public C addActualTypeArgument(CtTypeReference actualTypeArguments = new ArrayList<>(METHOD_TYPE_PARAMETERS_CONTAINER_DEFAULT_CAPACITY); } actualTypeArgument.setParent(this); - getFactory().Change().onListAdd(this, TYPE_PARAMETER, this.actualTypeArguments, actualTypeArgument); + getFactory().getEnvironment().getModelChangeListener().onListAdd(this, TYPE_PARAMETER, this.actualTypeArguments, actualTypeArgument); actualTypeArguments.add(actualTypeArgument); return (C) this; } @@ -457,7 +457,7 @@ public boolean removeActualTypeArgument(CtTypeReference actualTypeArgument) { if (actualTypeArguments == CtElementImpl.>emptyList()) { return false; } - getFactory().Change().onListDelete(this, TYPE_PARAMETER, actualTypeArguments, actualTypeArguments.indexOf(actualTypeArgument), actualTypeArgument); + getFactory().getEnvironment().getModelChangeListener().onListDelete(this, TYPE_PARAMETER, actualTypeArguments, actualTypeArguments.indexOf(actualTypeArgument), actualTypeArgument); return actualTypeArguments.remove(actualTypeArgument); } diff --git a/src/main/java/spoon/support/reflect/reference/CtFieldReferenceImpl.java b/src/main/java/spoon/support/reflect/reference/CtFieldReferenceImpl.java index 6ccfb75df84..78dade084e3 100644 --- a/src/main/java/spoon/support/reflect/reference/CtFieldReferenceImpl.java +++ b/src/main/java/spoon/support/reflect/reference/CtFieldReferenceImpl.java @@ -190,21 +190,21 @@ public > C setDeclaringType(CtTypeReference dec if (declaringType != null) { declaringType.setParent(this); } - getFactory().Change().onObjectUpdate(this, TYPE, declaringType, this.declaringType); + getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, TYPE, declaringType, this.declaringType); this.declaringType = declaringType; return (C) this; } @Override public > C setFinal(boolean fina) { - getFactory().Change().onObjectUpdate(this, IS_FINAL, fina, this.fina); + getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, IS_FINAL, fina, this.fina); this.fina = fina; return (C) this; } @Override public > C setStatic(boolean stat) { - getFactory().Change().onObjectUpdate(this, IS_STATIC, stat, this.stat); + getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, IS_STATIC, stat, this.stat); this.stat = stat; return (C) this; } diff --git a/src/main/java/spoon/support/reflect/reference/CtIntersectionTypeReferenceImpl.java b/src/main/java/spoon/support/reflect/reference/CtIntersectionTypeReferenceImpl.java index 1ef9c1adccd..d116c48f25f 100644 --- a/src/main/java/spoon/support/reflect/reference/CtIntersectionTypeReferenceImpl.java +++ b/src/main/java/spoon/support/reflect/reference/CtIntersectionTypeReferenceImpl.java @@ -50,7 +50,7 @@ public C setBounds(List>emptySet()) { this.bounds = new ArrayList<>(); } - getFactory().Change().onListDeleteAll(this, BOUND, this.bounds, new ArrayList<>(this.bounds)); + getFactory().getEnvironment().getModelChangeListener().onListDeleteAll(this, BOUND, this.bounds, new ArrayList<>(this.bounds)); this.bounds.clear(); for (CtTypeReference bound : bounds) { addBound(bound); @@ -68,7 +68,7 @@ public C addBound(CtTypeReference bou } if (!bounds.contains(bound)) { bound.setParent(this); - getFactory().Change().onListAdd(this, BOUND, this.bounds, bound); + getFactory().getEnvironment().getModelChangeListener().onListAdd(this, BOUND, this.bounds, bound); bounds.add(bound); } return (C) this; @@ -79,7 +79,7 @@ public boolean removeBound(CtTypeReference bound) { if (bounds == CtElementImpl.>emptyList()) { return false; } - getFactory().Change().onListDelete(this, BOUND, bounds, bounds.indexOf(bound), bound); + getFactory().getEnvironment().getModelChangeListener().onListDelete(this, BOUND, bounds, bounds.indexOf(bound), bound); return bounds.remove(bound); } diff --git a/src/main/java/spoon/support/reflect/reference/CtParameterReferenceImpl.java b/src/main/java/spoon/support/reflect/reference/CtParameterReferenceImpl.java index 0933c55f677..5dcc3a3f552 100644 --- a/src/main/java/spoon/support/reflect/reference/CtParameterReferenceImpl.java +++ b/src/main/java/spoon/support/reflect/reference/CtParameterReferenceImpl.java @@ -99,7 +99,7 @@ public > C setDeclaringExecutable(CtExecutable if (executable != null) { executable.setParent(this); } - getFactory().Change().onObjectUpdate(this, EXECUTABLE, executable, this.executable); + getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, EXECUTABLE, executable, this.executable); this.executable = executable; return (C) this; } diff --git a/src/main/java/spoon/support/reflect/reference/CtReferenceImpl.java b/src/main/java/spoon/support/reflect/reference/CtReferenceImpl.java index 9ccf7cb19c2..0aef2e6291d 100644 --- a/src/main/java/spoon/support/reflect/reference/CtReferenceImpl.java +++ b/src/main/java/spoon/support/reflect/reference/CtReferenceImpl.java @@ -55,7 +55,7 @@ public T setSimpleName(String simplename) { if (factory instanceof FactoryImpl) { simplename = ((FactoryImpl) factory).dedup(simplename); } - getFactory().Change().onObjectUpdate(this, NAME, simplename, this.simplename); + getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, NAME, simplename, this.simplename); this.simplename = simplename; return (T) this; } diff --git a/src/main/java/spoon/support/reflect/reference/CtTypeParameterReferenceImpl.java b/src/main/java/spoon/support/reflect/reference/CtTypeParameterReferenceImpl.java index f9effbbb873..f2bc30ba6b1 100644 --- a/src/main/java/spoon/support/reflect/reference/CtTypeParameterReferenceImpl.java +++ b/src/main/java/spoon/support/reflect/reference/CtTypeParameterReferenceImpl.java @@ -78,7 +78,7 @@ public T setBounds(List> @Override public T setUpper(boolean upper) { - getFactory().Change().onObjectUpdate(this, IS_UPPER, upper, this.upper); + getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, IS_UPPER, upper, this.upper); this.upper = upper; return (T) this; } @@ -164,7 +164,7 @@ public T setBoundingType(CtTypeReference if (superType != null) { superType.setParent(this); } - getFactory().Change().onObjectUpdate(this, SUPER_TYPE, superType, this.superType); + getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, SUPER_TYPE, superType, this.superType); this.superType = superType; return (T) this; } diff --git a/src/main/java/spoon/support/reflect/reference/CtTypeReferenceImpl.java b/src/main/java/spoon/support/reflect/reference/CtTypeReferenceImpl.java index 58da884e891..3ee8b4c3c92 100644 --- a/src/main/java/spoon/support/reflect/reference/CtTypeReferenceImpl.java +++ b/src/main/java/spoon/support/reflect/reference/CtTypeReferenceImpl.java @@ -256,7 +256,7 @@ public C setActualTypeArguments(List>emptyList()) { this.actualTypeArguments = new ArrayList<>(TYPE_TYPE_PARAMETERS_CONTAINER_DEFAULT_CAPACITY); } - getFactory().Change().onListDeleteAll(this, TYPE_PARAMETER, this.actualTypeArguments, new ArrayList<>(this.actualTypeArguments)); + getFactory().getEnvironment().getModelChangeListener().onListDeleteAll(this, TYPE_PARAMETER, this.actualTypeArguments, new ArrayList<>(this.actualTypeArguments)); this.actualTypeArguments.clear(); for (CtTypeReference actualTypeArgument : actualTypeArguments) { addActualTypeArgument(actualTypeArgument); @@ -269,7 +269,7 @@ public > C setDeclaringType(CtTypeReference decl if (declaringType != null) { declaringType.setParent(this); } - getFactory().Change().onObjectUpdate(this, TYPE, declaringType, this.declaringType); + getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, TYPE, declaringType, this.declaringType); this.declaringType = declaringType; return (C) this; } @@ -279,7 +279,7 @@ public > C setPackage(CtPackageReference pack) { if (pack != null) { pack.setParent(this); } - getFactory().Change().onObjectUpdate(this, PACKAGE_REF, pack, this.pack); + getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, PACKAGE_REF, pack, this.pack); this.pack = pack; return (C) this; } @@ -564,7 +564,7 @@ public C addActualTypeArgument(CtTypeReference actualTypeArguments = new ArrayList<>(TYPE_TYPE_PARAMETERS_CONTAINER_DEFAULT_CAPACITY); } actualTypeArgument.setParent(this); - getFactory().Change().onListAdd(this, TYPE_PARAMETER, this.actualTypeArguments, actualTypeArgument); + getFactory().getEnvironment().getModelChangeListener().onListAdd(this, TYPE_PARAMETER, this.actualTypeArguments, actualTypeArgument); actualTypeArguments.add(actualTypeArgument); return (C) this; } @@ -574,7 +574,7 @@ public boolean removeActualTypeArgument(CtTypeReference actualTypeArgument) { if (actualTypeArguments == CtElementImpl.>emptyList()) { return false; } - getFactory().Change().onListDelete(this, TYPE_PARAMETER, actualTypeArguments, actualTypeArguments.indexOf(actualTypeArgument), actualTypeArgument); + getFactory().getEnvironment().getModelChangeListener().onListDelete(this, TYPE_PARAMETER, actualTypeArguments, actualTypeArguments.indexOf(actualTypeArgument), actualTypeArgument); return actualTypeArguments.remove(actualTypeArgument); } @@ -792,7 +792,7 @@ public boolean isShadow() { @Override public E setShadow(boolean isShadow) { - getFactory().Change().onObjectUpdate(this, IS_SHADOW, isShadow, this.isShadow); + getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, IS_SHADOW, isShadow, this.isShadow); this.isShadow = isShadow; return (E) this; } diff --git a/src/main/java/spoon/support/reflect/reference/CtVariableReferenceImpl.java b/src/main/java/spoon/support/reflect/reference/CtVariableReferenceImpl.java index 05ff29c163a..3bc1f14cd5c 100644 --- a/src/main/java/spoon/support/reflect/reference/CtVariableReferenceImpl.java +++ b/src/main/java/spoon/support/reflect/reference/CtVariableReferenceImpl.java @@ -52,7 +52,7 @@ public > C setType(CtTypeReference type) { if (type != null) { type.setParent(this); } - getFactory().Change().onObjectUpdate(this, TYPE, type, this.type); + getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, TYPE, type, this.type); this.type = type; return (C) this; } From d5cf83427571efcded3338ae1fb1ad96be870b1b Mon Sep 17 00:00:00 2001 From: tdurieux Date: Tue, 27 Jun 2017 15:22:41 +0200 Subject: [PATCH 40/40] extract interface for finemodelchangelistener --- .../ActionBasedChangeListenerImpl.java | 17 ++- .../modelobs/EmptyModelChangeListener.java | 121 ++++++++++++++++++ .../modelobs/FineModelChangeListener.java | 63 +++------ .../spoon/support/StandardEnvironment.java | 3 +- 4 files changed, 156 insertions(+), 48 deletions(-) create mode 100644 src/main/java/spoon/experimental/modelobs/EmptyModelChangeListener.java diff --git a/src/main/java/spoon/experimental/modelobs/ActionBasedChangeListenerImpl.java b/src/main/java/spoon/experimental/modelobs/ActionBasedChangeListenerImpl.java index 70ccbc8bcf5..1aab485138d 100644 --- a/src/main/java/spoon/experimental/modelobs/ActionBasedChangeListenerImpl.java +++ b/src/main/java/spoon/experimental/modelobs/ActionBasedChangeListenerImpl.java @@ -29,6 +29,7 @@ import spoon.reflect.declaration.ModifierKind; import spoon.reflect.path.CtRole; +import java.util.Collection; import java.util.List; import java.util.Map; import java.util.Set; @@ -36,7 +37,7 @@ /** * This listener will propagate the change to the listener */ -public abstract class ActionBasedChangeListenerImpl extends FineModelChangeListener implements ActionBasedChangeListener { +public abstract class ActionBasedChangeListenerImpl implements ActionBasedChangeListener, FineModelChangeListener { private void propagateModelChange(final Action action) { this.onAction(action); @@ -76,6 +77,13 @@ public void onListAdd(CtElement currentElement, CtRole role, List field, int ind propagateModelChange(new AddAction<>(new ListContext(currentElement, role, field, index), newValue)); } + @Override + public void onListDelete(CtElement currentElement, CtRole role, List field, Collection oldValue) { + for (CtElement ctElement : oldValue) { + onListDelete(currentElement, role, field, field.indexOf(ctElement), ctElement); + } + } + @Override public void onListDelete(CtElement currentElement, CtRole role, List field, int index, CtElement oldValue) { propagateModelChange(new DeleteAction<>(new ListContext(currentElement, role, field, index), oldValue)); @@ -111,6 +119,13 @@ public void onSetDelete(CtElement currentElement, CtRole role, Set field, CtElem propagateModelChange(new DeleteAction<>(new SetContext(currentElement, role, field), oldValue)); } + @Override + public void onSetDelete(CtElement currentElement, CtRole role, Set field, Collection oldValue) { + for (ModifierKind modifierKind : oldValue) { + onSetDelete(currentElement, role, field, modifierKind); + } + } + @Override public void onSetDelete(CtElement currentElement, CtRole role, Set field, ModifierKind oldValue) { propagateModelChange(new DeleteAction<>(new SetContext(currentElement, role, field), oldValue)); diff --git a/src/main/java/spoon/experimental/modelobs/EmptyModelChangeListener.java b/src/main/java/spoon/experimental/modelobs/EmptyModelChangeListener.java new file mode 100644 index 00000000000..ca6dbc942bf --- /dev/null +++ b/src/main/java/spoon/experimental/modelobs/EmptyModelChangeListener.java @@ -0,0 +1,121 @@ +/** + * Copyright (C) 2006-2017 INRIA and contributors + * Spoon - http://spoon.gforge.inria.fr/ + * + * This software is governed by the CeCILL-C License under French law and + * abiding by the rules of distribution of free software. You can use, modify + * and/or redistribute the software under the terms of the CeCILL-C license as + * circulated by CEA, CNRS and INRIA at http://www.cecill.info. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the CeCILL-C License for more details. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL-C license and that you accept its terms. + */ +package spoon.experimental.modelobs; + +import spoon.reflect.declaration.CtElement; +import spoon.reflect.declaration.ModifierKind; +import spoon.reflect.path.CtRole; + +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** + * is the listener that creates the action on the model. This default listener does nothing. + */ +public class EmptyModelChangeListener implements FineModelChangeListener { + + @Override + public void onObjectUpdate(CtElement currentElement, CtRole role, + CtElement newValue, CtElement oldValue) { + } + + @Override + public void onObjectUpdate(CtElement currentElement, CtRole role, + Object newValue, Object oldValue) { + } + + @Override + public void onObjectDelete(CtElement currentElement, CtRole role, + CtElement oldValue) { + } + + @Override + public void onListAdd(CtElement currentElement, CtRole role, List field, + CtElement newValue) { + } + + @Override + public void onListAdd(CtElement currentElement, CtRole role, List field, + int index, CtElement newValue) { + } + + + @Override + public void onListDelete(CtElement currentElement, CtRole role, List field, + Collection oldValue) { + for (CtElement ctElement : oldValue) { + onListDelete(currentElement, role, field, field.indexOf(ctElement), ctElement); + } + } + + @Override + public void onListDelete(CtElement currentElement, CtRole role, List field, + int index, CtElement oldValue) { + } + + + @Override + public void onListDeleteAll(CtElement currentElement, CtRole role, + List field, List oldValue) { + } + + + @Override + public void onMapAdd(CtElement currentElement, CtRole role, + Map field, K key, CtElement newValue) { + } + + @Override + public void onMapDeleteAll(CtElement currentElement, CtRole role, + Map field, Map oldValue) { + } + + @Override + public void onSetAdd(CtElement currentElement, CtRole role, Set field, + CtElement newValue) { + } + + @Override + public void onSetAdd(CtElement currentElement, CtRole role, Set field, + ModifierKind newValue) { + } + + + @Override + public void onSetDelete(CtElement currentElement, CtRole role, Set field, + CtElement oldValue) { + } + + @Override + public void onSetDelete(CtElement currentElement, CtRole role, Set field, Collection oldValue) { + for (ModifierKind modifierKind : oldValue) { + onSetDelete(currentElement, role, field, modifierKind); + } + } + + @Override + public void onSetDelete(CtElement currentElement, CtRole role, Set field, + ModifierKind oldValue) { + } + + @Override + public void onSetDeleteAll(CtElement currentElement, CtRole role, Set field, + Set oldValue) { + } +} diff --git a/src/main/java/spoon/experimental/modelobs/FineModelChangeListener.java b/src/main/java/spoon/experimental/modelobs/FineModelChangeListener.java index 248f0f6b9c6..3504477261b 100644 --- a/src/main/java/spoon/experimental/modelobs/FineModelChangeListener.java +++ b/src/main/java/spoon/experimental/modelobs/FineModelChangeListener.java @@ -25,66 +25,37 @@ import java.util.Map; import java.util.Set; -/** - * is the listener that creates the action on the model. This default listener does nothing. - */ -public class FineModelChangeListener { - - public void onObjectUpdate(CtElement currentElement, CtRole role, CtElement newValue, CtElement oldValue) { - } - - public void onObjectUpdate(CtElement currentElement, CtRole role, Object newValue, Object oldValue) { - } - - public void onObjectDelete(CtElement currentElement, CtRole role, CtElement oldValue) { - } - - public void onListAdd(CtElement currentElement, CtRole role, List field, CtElement newValue) { - } - public void onListAdd(CtElement currentElement, CtRole role, List field, int index, CtElement newValue) { - } +public interface FineModelChangeListener { + void onObjectUpdate(CtElement currentElement, CtRole role, CtElement newValue, CtElement oldValue); + void onObjectUpdate(CtElement currentElement, CtRole role, Object newValue, Object oldValue); - public void onListDelete(CtElement currentElement, CtRole role, List field, Collection oldValue) { - for (CtElement ctElement : oldValue) { - onListDelete(currentElement, role, field, field.indexOf(ctElement), ctElement); - } - } + void onObjectDelete(CtElement currentElement, CtRole role, CtElement oldValue); - public void onListDelete(CtElement currentElement, CtRole role, List field, int index, CtElement oldValue) { - } + void onListAdd(CtElement currentElement, CtRole role, List field, CtElement newValue); + void onListAdd(CtElement currentElement, CtRole role, List field, int index, CtElement newValue); - public void onListDeleteAll(CtElement currentElement, CtRole role, List field, List oldValue) { - } + void onListDelete(CtElement currentElement, CtRole role, List field, Collection oldValue); + void onListDelete(CtElement currentElement, CtRole role, List field, int index, CtElement oldValue); - public void onMapAdd(CtElement currentElement, CtRole role, Map field, K key, CtElement newValue) { - } + void onListDeleteAll(CtElement currentElement, CtRole role, List field, List oldValue); - public void onMapDeleteAll(CtElement currentElement, CtRole role, Map field, Map oldValue) { - } + void onMapAdd(CtElement currentElement, CtRole role, Map field, K key, CtElement newValue); - public void onSetAdd(CtElement currentElement, CtRole role, Set field, CtElement newValue) { - } + void onMapDeleteAll(CtElement currentElement, CtRole role, Map field, Map oldValue); - public void onSetAdd(CtElement currentElement, CtRole role, Set field, ModifierKind newValue) { - } + void onSetAdd(CtElement currentElement, CtRole role, Set field, CtElement newValue); + void onSetAdd(CtElement currentElement, CtRole role, Set field, ModifierKind newValue); - public void onSetDelete(CtElement currentElement, CtRole role, Set field, CtElement oldValue) { - } + void onSetDelete(CtElement currentElement, CtRole role, Set field, CtElement oldValue); - public void onSetDelete(CtElement currentElement, CtRole role, Set field, Collection oldValue) { - for (ModifierKind modifierKind : oldValue) { - onSetDelete(currentElement, role, field, modifierKind); - } - } + void onSetDelete(CtElement currentElement, CtRole role, Set field, Collection oldValue); - public void onSetDelete(CtElement currentElement, CtRole role, Set field, ModifierKind oldValue) { - } + void onSetDelete(CtElement currentElement, CtRole role, Set field, ModifierKind oldValue); - public void onSetDeleteAll(CtElement currentElement, CtRole role, Set field, Set oldValue) { - } + void onSetDeleteAll(CtElement currentElement, CtRole role, Set field, Set oldValue); } diff --git a/src/main/java/spoon/support/StandardEnvironment.java b/src/main/java/spoon/support/StandardEnvironment.java index d31aa8c559e..35e9833e6ff 100644 --- a/src/main/java/spoon/support/StandardEnvironment.java +++ b/src/main/java/spoon/support/StandardEnvironment.java @@ -24,6 +24,7 @@ import spoon.compiler.InvalidClassPathException; import spoon.compiler.SpoonFile; import spoon.compiler.SpoonFolder; +import spoon.experimental.modelobs.EmptyModelChangeListener; import spoon.processing.FileGenerator; import spoon.processing.ProblemFixer; import spoon.processing.ProcessingManager; @@ -86,7 +87,7 @@ public class StandardEnvironment implements Serializable, Environment { private boolean skipSelfChecks; - private FineModelChangeListener modelChangeListener = new FineModelChangeListener(); + private FineModelChangeListener modelChangeListener = new EmptyModelChangeListener(); /** * Creates a new environment with a null default file