/
UMLTraversalStrategy.java
94 lines (82 loc) · 2.61 KB
/
UMLTraversalStrategy.java
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
/*
* Copyright (c) 2013, 2018 CEA LIST and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v20.html
*
* Contributors:
* E.D.Willink (CEA LIST) - initial API and implementation
* Christian W. Damus (CEA) - 397508
* Kenn Hussey - 535301
*/
package org.eclipse.uml2.uml.validation;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.validation.service.ITraversalStrategy;
import org.eclipse.uml2.uml.Element;
/**
* A UMLTraversalStrategy extends a standard recursive traversal to insert
* stereotype applications following each each stereotyped element.
*
* @since 5.0
*/
public class UMLTraversalStrategy
implements ITraversalStrategy {
private final ITraversalStrategy delegate;
// non-null if stereotypeApplications may be pending
private Iterator<EObject> stereotypeApplications = null;
/**
* Initializes me with the default recursive strategy as delegate.
*/
public UMLTraversalStrategy() {
this(new ITraversalStrategy.Recursive());
}
/**
* Initializes me with the specified traversal {@code delegate}. I insert
* stereotype applications following each element that it produces.
*
* @param delegate
* the traversal strategy to decorate
*/
public UMLTraversalStrategy(ITraversalStrategy delegate) {
this.delegate = delegate;
}
public void elementValidated(EObject element, IStatus status) {
delegate.elementValidated(element, status);
}
public boolean hasNext() {
if (stereotypeApplications != null) {
if (stereotypeApplications.hasNext()) {
return true;
}
stereotypeApplications = null;
}
return delegate.hasNext();
}
public boolean isClientContextChanged() {
return delegate.isClientContextChanged();
}
public EObject next() {
if (stereotypeApplications != null) {
return stereotypeApplications.next();
}
EObject next = delegate.next();
if (next instanceof Element) {
List<EObject> stereotypeApplicationsList = ((Element) next)
.getStereotypeApplications();
if (stereotypeApplicationsList.size() > 0) {
stereotypeApplications = stereotypeApplicationsList.iterator();
}
}
return next;
}
public void startTraversal(Collection<? extends EObject> traversalRoots,
IProgressMonitor monitor) {
delegate.startTraversal(traversalRoots, monitor);
}
}