blob: 411abc3558cd5152646c1a988f1f0655d0ed5075 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
/*******************************************************************************
* Copyright (c) 2013, 2016 Willink Transformations and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* E.D.Willink - Initial API and implementation
*******************************************************************************/
package org.eclipse.qvtd.runtime.evaluation;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.ocl.pivot.ids.CollectionTypeId;
import org.eclipse.qvtd.runtime.internal.evaluation.AbstractInvocationInternal;
/**
* AbstractInvocation provides the mandatory shared functionality of the intrusive blocked/waiting linked list functionality.
*/
public abstract class AbstractInvocation extends AbstractInvocationInternal
{
public abstract static class Incremental extends AbstractInvocation implements Invocation.Incremental
{
public static final @NonNull List<@NonNull Object> EMPTY_OBJECT_LIST = Collections.emptyList();
public static final @NonNull List<SlotState.@NonNull Incremental> EMPTY_SLOT_LIST = Collections.emptyList();
protected final @NonNull InvocationConstructor constructor;
protected final int sequence;
private Set<@NonNull Object> createdObjects = null;
private Set<SlotState.@NonNull Incremental> readSlots = null;
private Set<SlotState.@NonNull Incremental> writeSlots = null;
protected Incremental(InvocationConstructor.@NonNull Incremental constructor) {
super(constructor);
this.constructor = constructor;
this.sequence = constructor.nextSequence();
}
@Override
public void addCreatedObject(@NonNull Object createdObject) {
if (createdObjects == null) {
createdObjects = new HashSet<>();
}
createdObjects.add(createdObject);
}
@Override
public void addReadSlot(SlotState.@NonNull Incremental readSlot) {
if (readSlots == null) {
readSlots = new HashSet<>();
}
readSlots.add(readSlot);
readSlot.addTargetInternal(this);
}
@Override
public void addWriteSlot(SlotState.@NonNull Incremental writeSlot) {
if (writeSlots == null) {
writeSlots = new HashSet<>();
}
writeSlots.add(writeSlot);
writeSlot.addSourceInternal(this);
}
protected @NonNull Connection createConnection(@NonNull String name, @NonNull CollectionTypeId typeId, boolean isStrict) {
return constructor.getInterval().createConnection(name, typeId, isStrict);
}
protected Connection.@NonNull Incremental createIncrementalConnection(@NonNull String name, @NonNull CollectionTypeId typeId, boolean isStrict) {
return constructor.getInterval().createIncrementalConnection(name, typeId, isStrict);
}
@Override
public @NonNull Iterable<@NonNull Object> getCreatedObjects() {
return createdObjects != null ? createdObjects : EMPTY_OBJECT_LIST;
}
@SuppressWarnings("null")
@Override
public @NonNull String getName() {
InvocationConstructor constructor2 = constructor; // May be invoked from toString() during constructor debugging
return (constructor2 != null ? constructor2.getName() : "null") + "-" + sequence;
}
@Override
public @NonNull Iterable<SlotState.@NonNull Incremental> getReadSlots() {
return readSlots != null ? readSlots : EMPTY_SLOT_LIST;
}
@Override
public @NonNull Iterable<SlotState.@NonNull Incremental> getWriteSlots() {
return writeSlots != null ? writeSlots : EMPTY_SLOT_LIST;
}
@Override
public @NonNull String toString() {
return getName();
}
}
protected AbstractInvocation(@NonNull InvocationConstructor constructor) {
super(constructor.getInterval());
}
@Override
public <R> R accept(@NonNull ExecutionVisitor<R> visitor) {
return visitor.visitInvocation(this);
}
@Override
public @NonNull String getName() {
return toString().replace("@", "\n@");
}
}
|