Skip to content

Commit

Permalink
extract interface for finemodelchangelistener
Browse files Browse the repository at this point in the history
  • Loading branch information
tdurieux committed Jun 27, 2017
1 parent 86c80bb commit d5cf834
Show file tree
Hide file tree
Showing 4 changed files with 156 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,15 @@
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;

/**
* 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);
Expand Down Expand Up @@ -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<? extends CtElement> 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));
Expand Down Expand Up @@ -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<ModifierKind> 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));
Expand Down
Original file line number Diff line number Diff line change
@@ -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<? extends CtElement> 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 <K, V> void onMapAdd(CtElement currentElement, CtRole role,
Map<K, V> field, K key, CtElement newValue) {
}

@Override
public <K, V> void onMapDeleteAll(CtElement currentElement, CtRole role,
Map<K, V> field, Map<K, V> 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<ModifierKind> 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) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<? extends CtElement> 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<? extends CtElement> oldValue);

void onListDelete(CtElement currentElement, CtRole role, List field, int index, CtElement oldValue);

public <K, V> void onMapAdd(CtElement currentElement, CtRole role, Map<K, V> field, K key, CtElement newValue) {
}
void onListDeleteAll(CtElement currentElement, CtRole role, List field, List oldValue);

public <K, V> void onMapDeleteAll(CtElement currentElement, CtRole role, Map<K, V> field, Map<K, V> oldValue) {
}
<K, V> void onMapAdd(CtElement currentElement, CtRole role, Map<K, V> field, K key, CtElement newValue);

public void onSetAdd(CtElement currentElement, CtRole role, Set field, CtElement newValue) {
}
<K, V> void onMapDeleteAll(CtElement currentElement, CtRole role, Map<K, V> field, Map<K, V> 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<ModifierKind> oldValue) {
for (ModifierKind modifierKind : oldValue) {
onSetDelete(currentElement, role, field, modifierKind);
}
}
void onSetDelete(CtElement currentElement, CtRole role, Set field, Collection<ModifierKind> 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);
}
3 changes: 2 additions & 1 deletion src/main/java/spoon/support/StandardEnvironment.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 <code>null</code> default file
Expand Down

0 comments on commit d5cf834

Please sign in to comment.