Skip to content
Snippets Groups Projects
Commit 3b49d047 authored by Johannes Mey's avatar Johannes Mey
Browse files

update the specialized variant to use the preprocessor

parent 7c51c3ed
No related branches found
No related tags found
No related merge requests found
Showing
with 45 additions and 778 deletions
......@@ -24,18 +24,21 @@ public class JastaddTransformationRepairConnectedSegments<TJastaddDriver extends
java.util.List<Sensor> sensorsToRemoveSegmentFrom = new java.util.ArrayList<>();
// delete all references to segment2 (monitoring sensors and other segments connecting to it)
segment2.monitoredBy().clear();
for (Sensor sensor : new java.util.ArrayList<Sensor>(segment2.monitoredBy())) {
segment2.removeFromMonitoredBy(sensor);
}
for (Region region : driver.getModel().getRegionList()) {
for (TrackElement element : region.getTrackElementList()) {
element.removeConnectsTo(segment2);
element.removeFromConnectsTo(segment2);
}
}
segment2.removeSelf();
// connect segment1 to segment3
match.getSegment1().addConnectsTo(match.getSegment3());
match.getSegment1().addToConnectsTo(match.getSegment3());
}
driver.flushCache();
}
......
......@@ -20,7 +20,7 @@ public class JastaddTransformationRepairRouteSensor<TJastaddDriver extends Jasta
for (final JastaddRouteSensorMatch rsm : matches) {
final Route route = rsm.getRoute();
final Sensor sensor = rsm.getSensor();
route.getRequiredSensorList().add(sensor);
route.addToRequires(sensor);
driver.flushCache();
}
}
......
......@@ -19,18 +19,15 @@ public class JastaddTransformationRepairSwitchMonitored<TJastaddDriver extends J
public void activate(final Collection<JastaddSwitchMonitoredMatch> matches) {
for (final JastaddSwitchMonitoredMatch ssnm : matches) {
// gather the stuff we need to create a sensor:
RefList<TrackElement> monitors = new RefList<>();
RefList<TrackElement> requiringRoutes = new RefList<>();
monitors.add(ssnm.getSw());
// TODO something about the requiring routes?
Sensor sensor = new Sensor(driver.nextId(), monitors, requiringRoutes);
Sensor sensor = new Sensor();
sensor.setId(driver.nextId());
sensor.addToMonitors(ssnm.getSw());
ssnm.getSw().containingRegion().getSensorList().add(sensor);
ssnm.getSw().addMonitoringSensor(sensor);
ssnm.getSw().addToMonitoredBy(sensor);
}
driver.flushCache();
}
......
......@@ -5,6 +5,20 @@ shadowJar {
manifest { attributes 'Main-Class': 'de.tudresden.inf.st.train.jastadd.JastaddBenchmarkMain' }
}
task preprocess(type: JavaExec) {
group = 'Build'
main = "-jar"
args = [
"../trainbenchmark-tool-jastadd-base/libs/relast-compiler.jar",
"../trainbenchmark-tool-jastadd-specialized-base/src/main/jastadd/Train.relast",
"--listClass=RefList",
"--file"
]
inputs.files file("../trainbenchmark-tool-jastadd-specialized-base/src/main/jastadd/Train.relast")
outputs.files file("../trainbenchmark-tool-jastadd-specialized-base/src/main/jastadd/TrainGen.ast"), file("../trainbenchmark-tool-jastadd-specialized-base/src/main/jastadd/TrainGen.jadd")
}
task jastadd(type: JavaExec) {
group = 'Build'
main = "-jar"
......@@ -17,7 +31,7 @@ task jastadd(type: JavaExec) {
"--package=de.tudresden.inf.st.train.jastadd.ast",
"--o=src/main/java-gen",
"--tracing=api",
] + fileTree("../trainbenchmark-tool-jastadd-base/src/main/jastadd/") + fileTree("../trainbenchmark-tool-jastadd-specialized-base/src/main/jastadd/").matching {exclude "*.relast"} + fileTree("../trainbenchmark-tool-jastadd-specialized-incremental/src/main/jastadd/")
] + fileTree("../trainbenchmark-tool-jastadd-base/src/main/jastadd/") + fileTree("../trainbenchmark-tool-jastadd-specialized-base/src/main/jastadd/").matching {exclude "*.relast"}
doFirst {
delete fileTree('src/main/java-gen')
}
......@@ -27,7 +41,7 @@ task jastadd(type: JavaExec) {
}
}
inputs.files fileTree("../trainbenchmark-tool-jastadd-base/src/main/jastadd/") + fileTree("../trainbenchmark-tool-jastadd-specialized-base/src/main/jastadd/") + fileTree("../trainbenchmark-tool-jastadd-specialized-incremental/src/main/jastadd/")
inputs.files fileTree("../trainbenchmark-tool-jastadd-base/src/main/jastadd/") + fileTree("../trainbenchmark-tool-jastadd-specialized-base/src/main/jastadd/")
outputs.files file("src/main/java-gen")
}
......@@ -53,4 +67,5 @@ dependencies {
compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.8.8.1'
}
jastadd.dependsOn preprocess
compileJava.dependsOn jastadd
// all of these will be generated later
aspect initChildren {
refine ASTNode public Sensor.Sensor() {
state().enterConstruction();
this.setManagedMonitors(new RefList<>());
this.setManagedRequiringRoutes(new RefList<>());
refined();
state().exitConstruction();
}
refine ASTNode public TrackElement.TrackElement() {
state().enterConstruction();
this.setManagedMonitoredBy(new RefList<>());
this.setManagedConnectsTo(new RefList<>());
refined();
state().exitConstruction();
}
refine ASTNode public Switch.Switch() {
state().enterConstruction();
this.setManagedPositions(new RefList<>());
refined();
state().exitConstruction();
}
refine ASTNode public Route.Route() {
state().enterConstruction();
this.setManagedRequiredSensors(new RefList<>());
refined();
state().exitConstruction();
}
}
aspect RouteEntry {
// rel Route.entry -> [Semaphore];
public Semaphore Route.entry() {
// Returns null if 0 cardinality.
return this.getManagedEntry();
}
public boolean Route.hasEntry() {
return this.getManagedEntry() != null;
}
public void Route.setEntry(Semaphore s) {
// Semaphore allowed to be null.
this.setManagedEntry(s);
}
}
aspect RouteExit {
// rel Route.exit -> [Semaphore];
public Semaphore Route.exit() {
// Returns null if 0 cardinality.
return this.getManagedExit();
}
public boolean Route.hasExit() {
return this.getManagedExit() != null;
}
public void Route.setExit(Semaphore s) {
// Semaphore allowed to be null.
this.setManagedExit(s);
}
}
aspect SensorMonitorsTrackElement {
// rel Sensor*.monitors <-> TrackElement*.monitoredBy;
public RefList<TrackElement> Sensor.monitors() {
return this.getManagedMonitors();
}
public boolean Sensor.monitors(TrackElement t) {
return this.getManagedMonitors().contains(t);
}
public RefList<Sensor> TrackElement.monitoredBy() {
return this.getManagedMonitoredBy();
}
public boolean TrackElement.monitoredBy(Sensor s) {
return this.getManagedMonitoredBy().contains(s);
}
public void Sensor.addMonitoredElement(TrackElement t) {
this.getManagedMonitors().add(t);
t.getManagedMonitoredBy().add(this);
}
public void Sensor.removeMonitoredElement(TrackElement t) {
this.getManagedMonitors().remove(t);
t.getManagedMonitoredBy().remove(this);
}
public RefList<TrackElement> Sensor.getMonitoredElements() {
return this.getManagedMonitors();
}
public RefList<TrackElement> Sensor.getMonitoredElementList() {
return this.getManagedMonitors();
}
public TrackElement Sensor.getMonitoredElement(int i) {
return (TrackElement) this.getManagedMonitors().getChild(i);
}
public void TrackElement.addMonitoringSensor(Sensor s) {
this.getManagedMonitoredBy().add(s);
s.getManagedMonitors().add(this);
}
public void TrackElement.removeMonitoringSensor(Sensor s) {
this.getManagedMonitoredBy().remove(s);
s.getManagedMonitors().remove(this);
}
public RefList<Sensor> TrackElement.getMonitoringSensors(){
return this.getManagedMonitoredBy();
}
public RefList<Sensor> TrackElement.getMonitoringSensorList() {
return this.getManagedMonitoredBy();
}
public Sensor TrackElement.getMonitoringSensor(int i) {
return (Sensor) this.getManagedMonitoredBy().getChild(i);
}
}
aspect TrackElementConnectsToTrackElement {
// rel TrackElement.connectsTo -> TrackElement*;
public RefList<TrackElement> TrackElement.getConnectsTos() {
return this.getManagedConnectsTo();
}
public RefList<TrackElement> TrackElement.getConnectsToList() {
return this.getManagedConnectsTo();
}
public TrackElement TrackElement.getConnectsTo(int i) {
return (TrackElement) this.getManagedConnectsTo().getChild(i);
}
public boolean TrackElement.connectsTo(TrackElement t) {
return this.getManagedConnectsTo().contains(t);
}
public void TrackElement.addConnectsTo(TrackElement t) {
this.getManagedConnectsTo().add(t);
}
public void TrackElement.removeConnectsTo(TrackElement t) {
this.getManagedConnectsTo().remove(t);
}
}
aspect SwitchPositionsTargetSwitch {
// rel SwitchPosition*.target <-> Switch.positions;
public Switch SwitchPosition.target() {
// test2
return this.getManagedTarget();
}
public RefList<SwitchPosition> Switch.positions() {
return this.getManagedPositions();
}
public boolean Switch.positions(SwitchPosition s) {
return ((RefList)this.getManagedPositions()).contains(s);
}
public void SwitchPosition.setTarget(Switch s) {
Switch old_Target = this.getManagedTarget();
if (old_Target != null) {
old_Target.getManagedPositions().remove(this);
}
this.setManagedTarget(s);
if (s != null) {
s.getManagedPositions().add(this);
}
}
public void Switch.addPosition(SwitchPosition s) {
Switch old_Target = s.getManagedTarget();
if (old_Target != null) {
old_Target.getManagedPositions().remove(s);
}
this.getManagedPositions().add(s);
s.setManagedTarget(this);
}
public void Switch.removePosition(SwitchPosition s) {
this.getManagedPositions().remove(s);
s.setManagedTarget(null);
}
}
aspect RouteRequireSensor {
// rel Route*.requiredSensor <-> Sensor*.requiringRoutes;
public RefList<Route> Sensor.getRequiringRoutes() {
return this.getManagedRequiringRoutes();
}
public RefList<Route> Sensor.getRequiringRouteList() {
return this.getManagedRequiringRoutes();
}
public Route Sensor.getRequiringRoute(int i) {
return (Route) this.getManagedRequiringRoutes().getChild(i);
}
public boolean Sensor.requiresRoute(Route r) {
return ((RefList)this.getManagedRequiringRoutes()).contains(r);
}
public RefList<Sensor> Route.getRequiredSensors() {
return this.getManagedRequiredSensors();
}
public Sensor Route.getRequiredSensor(int i) {
return (Sensor) this.getManagedRequiredSensors().getChild(i);
}
public RefList<Sensor> Route.getRequiredSensorList() {
return this.getManagedRequiredSensors();
}
public boolean Route.requiredSensors(Sensor s) {
return ((RefList)this.getManagedRequiredSensors()).contains(s);
}
public void Sensor.addRequiringRoute(Route r) {
this.getManagedRequiringRoutes().add(r);
r.getManagedRequiredSensors().add(this);
}
public boolean Sensor.removeRequiringRoute(Route r) {
boolean a = this.getManagedRequiringRoutes().remove(r);
boolean b = r.getManagedRequiredSensors().remove(this);
if (a != b) {
System.out.println("Not a clean remove of requiring routes");
}
return a || b;
}
public void Route.addRequiredSensor(Sensor s) {
this.getManagedRequiredSensors().add(s);
s.getManagedRequiringRoutes().add(this);
}
public boolean Route.removeRequiredSensor(Sensor s) {
boolean a = this.getManagedRequiredSensors().remove(s);
boolean b = s.getManagedRequiringRoutes().remove(this);
if (a != b) {
System.out.println("Not a clean remove of required sensor");
}
return a || b;
}
}
import java.util.Iterator;
aspect NTList {
// Useful ASTNode annotations:
// @SuppressWarnings({"unused", "WeakerAccess", "Convert2Lambda", "Anonymous2MethodRef", "UnnecessaryBoxing", "unchecked"})
/**
* Copy of List implement without parent handling.
*
* @author rschoene - Initial contribution
*/
RefList implements Iterable<T>;
public void RefList.setChild(ASTNode node, int i) {
if (!state().IN_CONSTRUCTION && !state().IN_ATTR_STORE_EVAL) {
if (children != null && i < children.length && children[i] != null) {
children[i].inc_notifyForRemove();
}
if (children == null) {
numChildren_handler.notifyDependencies();
} else if (i >= numChildren) {
numChildren_handler.notifyDependencies();
if (i > 0 && getChild_handler[i-1] != null) {
getChild_handler[i-1].notifyDependencies();
}
} else {
if (getChild_handler[i] != null) {
getChild_handler[i].notifyDependencies();
} else {
getChild_handler[i] = ASTNode$DepGraphNode.createAttrHandler(this, "getChild", Integer.valueOf(i));
}
}
}
if (children == null) {
children = new ASTNode[(i + 1 > 4 || !(this instanceof List)) ? i + 1 : 4];
getChild_handler = new ASTNode$DepGraphNode[(i + 1 > 4 || !(this instanceof List)) ? i + 1 : 4];
} else if (i >= children.length) {
ASTNode c[] = new ASTNode[i << 1];
System.arraycopy(children, 0, c, 0, children.length);
children = c;
if (getChild_handler != null) {
ASTNode$DepGraphNode h[] = new ASTNode$DepGraphNode[i << 1];
System.arraycopy(getChild_handler, 0, h, 0, getChild_handler.length);
getChild_handler = h;
}
}
children[i] = node;
if (i >= numChildren) {
numChildren = i+1;
}
}
public void RefList.insertChild(ASTNode node, int i) {
if (!state().IN_CONSTRUCTION && !state().IN_ATTR_STORE_EVAL) {
if (children == null || i > numChildren) {
numChildren_handler.notifyDependencies();
} else {
numChildren_handler.notifyDependencies();
for (int k = i; k < children.length; k++) {
if (getChild_handler[k] != null) {
getChild_handler[k].notifyDependencies();
}
}
}
}
if (children == null) {
children = new ASTNode[(i + 1 > 4 || !(this instanceof List)) ? i + 1 : 4];
children[i] = node;
getChild_handler = new ASTNode$DepGraphNode[i + 1];
getChild_handler[i] = ASTNode$DepGraphNode.createAttrHandler(this, "getChild", Integer.valueOf(i));
} else {
ASTNode c[] = new ASTNode[children.length + 1];
System.arraycopy(children, 0, c, 0, i);
c[i] = node;
if (i < children.length) {
System.arraycopy(children, i, c, i+1, children.length-i);
}
children = c;
if (getChild_handler != null) {
ASTNode$DepGraphNode h[] = new ASTNode$DepGraphNode[getChild_handler.length + 1];
System.arraycopy(getChild_handler, 0, h, 0, getChild_handler.length);
getChild_handler = h;
}
}
numChildren++;
}
public void RefList.removeChild(int i) {
if (children != null) {
if (!state().IN_CONSTRUCTION && !state().IN_ATTR_STORE_EVAL) {
if (children[i] != null) {
children[i].inc_notifyForRemove();
}
numChildren_handler.notifyDependencies();
for (int k = i; k < children.length; k++) {
if (getChild_handler[k] != null) {
getChild_handler[k].notifyDependencies();
}
}
}
ASTNode child = (ASTNode) children[i];
// rschoene: no check needed, as RefList is always a list
System.arraycopy(children, i+1, children, i, children.length-i-1);
children[children.length-1] = null;
numChildren--;
if (getChild_handler != null) {
getChild_handler[numChildren] = null;
}
}
}
refine ASTNode protected int RefList.numChildren() {
state().addHandlerDepTo(numChildren_handler);
return numChildren;
}
refine ASTNode public List<T> RefList.treeCopyNoTransform() {
return copy();
}
refine ASTNode public List<T> RefList.fullCopy() {
return fullCopy();
}
refine ASTNode public List<T> RefList.treeCopy() {
return copy();
}
public void RefList.flushTreeCache() {
flushCache();
}
public RefList.RefList(T... initialChildren) {
children = new ASTNode[initialChildren.length];
for (int i = 0; i < children.length; ++i) {
addChild(initialChildren[i]);
}
}
public int RefList.getIndexOf(ASTNode element) {
int i = 0;
for (T child : this) {
if (child.equals(element)) {
return i;
}
++i;
}
return -1;
}
public boolean RefList.contains(ASTNode element) {
return getIndexOf(element) != -1;
}
public boolean RefList.remove(T element) {
int index = getIndexOf(element);
if (index == -1) {
// element not in the list
return false;
}
removeChild(index);
return true;
}
public void RefList.clear() {
while (numChildren() > 0) {
removeChild(0);
}
}
public boolean RefList.isEmpty() {
return numChildren() == 0;
}
refine ASTNode public void RefList.inc_throwAway() {
if (inc_throwAway_visited) {
return;
}
inc_throwAway_visited = true;
inc_state = inc_GARBAGE;
// super.inc_throwAway();
inc_throwAway_visited = false;
}
}
......@@ -5,6 +5,20 @@ shadowJar {
manifest { attributes 'Main-Class': 'de.tudresden.inf.st.train.jastadd.JastaddBenchmarkMain' }
}
task preprocess(type: JavaExec) {
group = 'Build'
main = "-jar"
args = [
"../trainbenchmark-tool-jastadd-base/libs/relast-compiler.jar",
"../trainbenchmark-tool-jastadd-specialized-base/src/main/jastadd/Train.relast",
"--listClass=RefList",
"--file"
]
inputs.files file("../trainbenchmark-tool-jastadd-specialized-base/src/main/jastadd/Train.relast")
outputs.files file("../trainbenchmark-tool-jastadd-specialized-base/src/main/jastadd/TrainGen.ast"), file("../trainbenchmark-tool-jastadd-specialized-base/src/main/jastadd/TrainGen.jadd")
}
task jastadd(type: JavaExec) {
group = 'Build'
main = "-jar"
......@@ -15,7 +29,7 @@ task jastadd(type: JavaExec) {
"--package=de.tudresden.inf.st.train.jastadd.ast",
"--o=src/main/java-gen",
"--tracing=api",
] + fileTree("../trainbenchmark-tool-jastadd-base/src/main/jastadd/") + fileTree("../trainbenchmark-tool-jastadd-specialized-base/src/main/jastadd/").matching {exclude "*.relast"} + fileTree("../trainbenchmark-tool-jastadd-specialized/src/main/jastadd/")
] + fileTree("../trainbenchmark-tool-jastadd-base/src/main/jastadd/") + fileTree("../trainbenchmark-tool-jastadd-specialized-base/src/main/jastadd/").matching {exclude "*.relast"}
doFirst {
delete fileTree('src/main/java-gen')
}
......@@ -25,7 +39,7 @@ task jastadd(type: JavaExec) {
}
}
inputs.files fileTree("../trainbenchmark-tool-jastadd-base/src/main/jastadd/") + fileTree("../trainbenchmark-tool-jastadd-specialized-base/src/main/jastadd/") + fileTree("../trainbenchmark-tool-jastadd-specialized/src/main/jastadd/")
inputs.files fileTree("../trainbenchmark-tool-jastadd-base/src/main/jastadd/") + fileTree("../trainbenchmark-tool-jastadd-specialized-base/src/main/jastadd/")
outputs.files file("src/main/java-gen")
}
......@@ -51,4 +65,5 @@ dependencies {
compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.8.8.1'
}
jastadd.dependsOn preprocess
compileJava.dependsOn jastadd
// all of these will be generated later
aspect initChildren {
refine ASTNode public Sensor.Sensor() {
this.setManagedMonitors(new RefList<>());
this.setManagedRequiringRoutes(new RefList<>());
refined();
}
refine ASTNode public TrackElement.TrackElement() {
this.setManagedMonitoredBy(new RefList<>());
this.setManagedConnectsTo(new RefList<>());
refined();
}
refine ASTNode public Switch.Switch() {
this.setManagedPositions(new RefList<>());
refined();
}
refine ASTNode public Route.Route() {
this.setManagedRequiredSensors(new RefList<>());
refined();
}
}
aspect RouteEntry {
// rel Route.entry -> [Semaphore];
public Semaphore Route.entry() {
// Returns null if 0 cardinality.
return this.getManagedEntry();
}
public boolean Route.hasEntry() {
return this.getManagedEntry() != null;
}
public void Route.setEntry(Semaphore s) {
// Semaphore allowed to be null.
this.setManagedEntry(s);
}
}
aspect RouteExit {
// rel Route.exit -> [Semaphore];
public Semaphore Route.exit() {
// Returns null if 0 cardinality.
return this.getManagedExit();
}
public boolean Route.hasExit() {
return this.getManagedExit() != null;
}
public void Route.setExit(Semaphore s) {
// Semaphore allowed to be null.
this.setManagedExit(s);
}
}
aspect SensorMonitorsTrackElement {
// rel Sensor*.monitors <-> TrackElement*.monitoredBy;
public RefList<TrackElement> Sensor.monitors() {
return this.getManagedMonitors();
}
public boolean Sensor.monitors(TrackElement t) {
return this.getManagedMonitors().contains(t);
}
public RefList<Sensor> TrackElement.monitoredBy() {
return this.getManagedMonitoredBy();
}
public boolean TrackElement.monitoredBy(Sensor s) {
return this.getManagedMonitoredBy().contains(s);
}
public void Sensor.addMonitoredElement(TrackElement t) {
this.getManagedMonitors().add(t);
t.getManagedMonitoredBy().add(this);
}
public void Sensor.removeMonitoredElement(TrackElement t) {
this.getManagedMonitors().remove(t);
t.getManagedMonitoredBy().remove(this);
}
public RefList<TrackElement> Sensor.getMonitoredElements() {
return this.getManagedMonitors();
}
public RefList<TrackElement> Sensor.getMonitoredElementList() {
return this.getManagedMonitors();
}
public TrackElement Sensor.getMonitoredElement(int i) {
return (TrackElement) this.getManagedMonitors().getChild(i);
}
public void TrackElement.addMonitoringSensor(Sensor s) {
this.getManagedMonitoredBy().add(s);
s.getManagedMonitors().add(this);
}
public void TrackElement.removeMonitoringSensor(Sensor s) {
this.getManagedMonitoredBy().remove(s);
s.getManagedMonitors().remove(this);
}
public RefList<Sensor> TrackElement.getMonitoringSensors(){
return this.getManagedMonitoredBy();
}
public RefList<Sensor> TrackElement.getMonitoringSensorList() {
return this.getManagedMonitoredBy();
}
public Sensor TrackElement.getMonitoringSensor(int i) {
return (Sensor) this.getManagedMonitoredBy().getChild(i);
}
}
aspect TrackElementConnectsToTrackElement {
// rel TrackElement.connectsTo -> TrackElement*;
public RefList<TrackElement> TrackElement.getConnectsTos() {
return this.getManagedConnectsTo();
}
public RefList<TrackElement> TrackElement.getConnectsToList() {
return this.getManagedConnectsTo();
}
public TrackElement TrackElement.getConnectsTo(int i) {
return (TrackElement) this.getManagedConnectsTo().getChild(i);
}
public boolean TrackElement.connectsTo(TrackElement t) {
return this.getManagedConnectsTo().contains(t);
}
public void TrackElement.addConnectsTo(TrackElement t) {
this.getManagedConnectsTo().add(t);
}
public void TrackElement.removeConnectsTo(TrackElement t) {
this.getManagedConnectsTo().remove(t);
}
}
aspect SwitchPositionsTargetSwitch {
// rel SwitchPosition*.target <-> Switch.positions;
public Switch SwitchPosition.target() {
// test2
return this.getManagedTarget();
}
public RefList<SwitchPosition> Switch.positions() {
return this.getManagedPositions();
}
public boolean Switch.positions(SwitchPosition s) {
return ((RefList)this.getManagedPositions()).contains(s);
}
public void SwitchPosition.setTarget(Switch s) {
Switch old_Target = this.getManagedTarget();
if (old_Target != null) {
old_Target.getManagedPositions().remove(this);
}
this.setManagedTarget(s);
if (s != null) {
s.getManagedPositions().add(this);
}
}
public void Switch.addPosition(SwitchPosition s) {
Switch old_Target = s.getManagedTarget();
if (old_Target != null) {
old_Target.getManagedPositions().remove(s);
}
this.getManagedPositions().add(s);
s.setManagedTarget(this);
}
public void Switch.removePosition(SwitchPosition s) {
this.getManagedPositions().remove(s);
s.setManagedTarget(null);
}
}
aspect RouteRequireSensor {
// rel Route*.requiredSensor <-> Sensor*.requiringRoutes;
public RefList<Route> Sensor.getRequiringRoutes() {
return this.getManagedRequiringRoutes();
}
public RefList<Route> Sensor.getRequiringRouteList() {
return this.getManagedRequiringRoutes();
}
public Route Sensor.getRequiringRoute(int i) {
return (Route) this.getManagedRequiringRoutes().getChild(i);
}
public boolean Sensor.requiresRoute(Route r) {
return ((RefList)this.getManagedRequiringRoutes()).contains(r);
}
public RefList<Sensor> Route.getRequiredSensors() {
return this.getManagedRequiredSensors();
}
public Sensor Route.getRequiredSensor(int i) {
return (Sensor) this.getManagedRequiredSensors().getChild(i);
}
public RefList<Sensor> Route.getRequiredSensorList() {
return this.getManagedRequiredSensors();
}
public boolean Route.requiredSensors(Sensor s) {
return ((RefList)this.getManagedRequiredSensors()).contains(s);
}
public void Sensor.addRequiringRoute(Route r) {
this.getManagedRequiringRoutes().add(r);
r.getManagedRequiredSensors().add(this);
}
public boolean Sensor.removeRequiringRoute(Route r) {
boolean a = this.getManagedRequiringRoutes().remove(r);
boolean b = r.getManagedRequiredSensors().remove(this);
if (a != b) {
System.out.println("Not a clean remove of requiring routes");
}
return a || b;
}
public void Route.addRequiredSensor(Sensor s) {
this.getManagedRequiredSensors().add(s);
s.getManagedRequiringRoutes().add(this);
}
public boolean Route.removeRequiredSensor(Sensor s) {
boolean a = this.getManagedRequiredSensors().remove(s);
boolean b = s.getManagedRequiringRoutes().remove(this);
if (a != b) {
System.out.println("Not a clean remove of required sensor");
}
return a || b;
}
}
import java.util.Iterator;
aspect NTList {
// Useful ASTNode annotations:
// @SuppressWarnings({"unused", "WeakerAccess", "Convert2Lambda", "Anonymous2MethodRef", "UnnecessaryBoxing", "unchecked"})
/**
* Copy of List implement without parent handling.
*
* @author rschoene - Initial contribution
*/
RefList implements Iterable<T>;
public void RefList.setChild(ASTNode node, int i) {
if (children == null) {
children = new ASTNode[(i + 1 > 4 || !(this instanceof List)) ? i + 1 : 4];
} else if (i >= children.length) {
ASTNode c[] = new ASTNode[i << 1];
System.arraycopy(children, 0, c, 0, children.length);
children = c;
}
children[i] = node;
if (i >= numChildren) {
numChildren = i+1;
}
}
public void RefList.insertChild(ASTNode node, int i) {
if (children == null) {
children = new ASTNode[(i + 1 > 4 || !(this instanceof List)) ? i + 1 : 4];
children[i] = node;
} else {
ASTNode c[] = new ASTNode[children.length + 1];
System.arraycopy(children, 0, c, 0, i);
c[i] = node;
if (i < children.length) {
System.arraycopy(children, i, c, i+1, children.length-i);
}
children = c;
}
numChildren++;
}
public void RefList.removeChild(int i) {
if (children != null) {
ASTNode child = (ASTNode) children[i];
// rschoene: no check needed, as RefList is always a list
System.arraycopy(children, i+1, children, i, children.length-i-1);
children[children.length-1] = null;
numChildren--;
}
}
refine ASTNode protected int RefList.numChildren() {
return numChildren;
}
refine ASTNode public List<T> RefList.treeCopyNoTransform() {
return copy();
}
refine ASTNode public List<T> RefList.fullCopy() {
return fullCopy();
}
refine ASTNode public List<T> RefList.treeCopy() {
return copy();
}
public void RefList.flushTreeCache() {
flushCache();
}
public RefList.RefList(T... initialChildren) {
children = new ASTNode[initialChildren.length];
for (int i = 0; i < children.length; ++i) {
addChild(initialChildren[i]);
}
}
public int RefList.getIndexOf(ASTNode element) {
int i = 0;
for (T child : this) {
if (child.equals(element)) {
return i;
}
++i;
}
return -1;
}
public boolean RefList.contains(ASTNode element) {
return getIndexOf(element) != -1;
}
public boolean RefList.remove(T element) {
int index = getIndexOf(element);
if (index == -1) {
// element not in the list
return false;
}
removeChild(index);
return true;
}
public void RefList.clear() {
while (numChildren() > 0) {
removeChild(0);
}
}
public boolean RefList.isEmpty() {
return numChildren() == 0;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment