Skip to content

Commit

Permalink
change the entry point for the model change listener
Browse files Browse the repository at this point in the history
  • Loading branch information
tdurieux committed Jun 27, 2017
1 parent 976ddf1 commit f219f44
Show file tree
Hide file tree
Showing 72 changed files with 246 additions and 257 deletions.
3 changes: 0 additions & 3 deletions src/main/java/spoon/reflect/factory/Factory.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -157,8 +156,6 @@ public interface Factory {

QueryFactory Query();

FineModelChangeListener Change();

/**
* @see CodeFactory#createAnnotation(CtTypeReference)
*/
Expand Down
8 changes: 0 additions & 8 deletions src/main/java/spoon/reflect/factory/FactoryImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public <C extends CtArrayAccess<T, V>> C setIndexExpression(CtExpression<Integer
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;
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/spoon/support/reflect/code/CtAssertImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public <A extends CtAssert<T>> A setAssertExpression(CtExpression<Boolean> 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;
}
Expand All @@ -64,7 +64,7 @@ public <A extends CtAssert<T>> A setExpression(CtExpression<T> 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;
}
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/spoon/support/reflect/code/CtAssignmentImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public <C extends CtAssignment<T, A>> C setAssigned(CtExpression<T> 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;
}
Expand All @@ -91,7 +91,7 @@ public <C extends CtRHSReceiver<A>> C setAssignment(CtExpression<A> 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;
}
Expand All @@ -101,7 +101,7 @@ public <C extends CtTypedElement> C setType(CtTypeReference<T> 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;
}
Expand All @@ -115,7 +115,7 @@ public <C extends CtExpression<T>> C setTypeCasts(List<CtTypeReference<?>> casts
if (this.typeCasts == CtElementImpl.<CtTypeReference<?>>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);
Expand All @@ -132,7 +132,7 @@ public <C extends CtExpression<T>> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public <C extends CtBinaryOperator<T>> 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;
}
Expand All @@ -69,14 +69,14 @@ public <C extends CtBinaryOperator<T>> 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 extends CtBinaryOperator<T>> 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;
}
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/spoon/support/reflect/code/CtBlockImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public <T extends CtBlock<R>> 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) {
Expand All @@ -105,7 +105,7 @@ public <T extends CtBlock<R>> 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);
Expand Down Expand Up @@ -166,7 +166,7 @@ public <T extends CtStatementList> T setStatements(List<CtStatement> 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);
Expand All @@ -181,7 +181,7 @@ public <T extends CtStatementList> 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);
Expand All @@ -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;
Expand All @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/spoon/support/reflect/code/CtBreakImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public String getTargetLabel() {

@Override
public <T extends CtLabelledFlowBreak> 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;
}
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/spoon/support/reflect/code/CtCaseImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public <T extends CtCase<E>> T setCaseExpression(CtExpression<E> 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;
}
Expand All @@ -73,7 +73,7 @@ public <T extends CtStatementList> T setStatements(List<CtStatement> 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);
Expand All @@ -90,7 +90,7 @@ public <T extends CtStatementList> 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;
}
Expand All @@ -100,7 +100,7 @@ public void removeStatement(CtStatement statement) {
if (statements == CtElementImpl.<CtStatement>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);
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/spoon/support/reflect/code/CtCatchImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ public CtCatchVariable<? extends Throwable> getParameter() {
public <T extends CtBodyHolder> 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;
}

Expand All @@ -74,7 +74,7 @@ public <T extends CtCatch> T setParameter(CtCatchVariable<? extends Throwable> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public <C extends CtVariable<T>> C setDefaultExpression(CtExpression<T> defaultE

@Override
public <C extends CtNamedElement> 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;
}
Expand All @@ -104,7 +104,7 @@ public <C extends CtTypedElement> C setType(CtTypeReference<T> 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;
}
Expand All @@ -118,7 +118,7 @@ public <T extends CtMultiTypedElement> 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;
}
Expand All @@ -128,7 +128,7 @@ public boolean removeMultiType(CtTypeReference<?> ref) {
if (this.types == CtElementImpl.<CtTypeReference<?>>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);
}

Expand All @@ -139,7 +139,7 @@ public List<CtTypeReference<?>> getMultiTypes() {

@Override
public <T extends CtMultiTypedElement> T setMultiTypes(List<CtTypeReference<?>> 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;
Expand Down Expand Up @@ -167,7 +167,7 @@ public boolean hasModifier(ModifierKind modifier) {
@Override
public <C extends CtModifiable> C setModifiers(Set<ModifierKind> 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);
Expand All @@ -181,7 +181,7 @@ public <C extends CtModifiable> C addModifier(ModifierKind modifier) {
if (modifiers == CtElementImpl.<ModifierKind>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;
}
Expand All @@ -191,7 +191,7 @@ public boolean removeModifier(ModifierKind modifier) {
if (modifiers == CtElementImpl.<ModifierKind>emptySet()) {
return false;
}
getFactory().Change().onSetDelete(this, MODIFIER, modifiers, modifier);
getFactory().getEnvironment().getModelChangeListener().onSetDelete(this, MODIFIER, modifiers, modifier);
return modifiers.remove(modifier);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public String getValue() {
}

public <C extends CtCodeSnippet> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public String getValue() {
}

public <C extends CtCodeSnippet> 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;
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/spoon/support/reflect/code/CtCommentImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public String getContent() {

@Override
public <E extends CtComment> 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;
}
Expand All @@ -59,7 +59,7 @@ public CommentType getCommentType() {

@Override
public <E extends CtComment> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public <C extends CtConditional<T>> C setElseExpression(CtExpression<T> 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;
}
Expand All @@ -73,7 +73,7 @@ public <C extends CtConditional<T>> C setCondition(CtExpression<Boolean> 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;
}
Expand All @@ -83,7 +83,7 @@ public <C extends CtConditional<T>> C setThenExpression(CtExpression<T> 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;
}
Expand Down
Loading

0 comments on commit f219f44

Please sign in to comment.