blob: 35b5ed6f096345457632c1ddf07c57ec1b1b425f (
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
|
/*******************************************************************************
* Copyright (c) 2012 Rohit Agrawal
* 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:
* Rohit Agrawal (initial contribution)
*
*******************************************************************************/
package org.eclipse.etrice.abstractexec.behavior;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.eclipse.emf.common.util.TreeIterator;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.etrice.core.common.validation.ICustomValidator;
import org.eclipse.etrice.core.genmodel.base.NullDiagnostician;
import org.eclipse.etrice.core.genmodel.base.NullLogger;
import org.eclipse.etrice.core.genmodel.builder.GeneratorModelBuilder;
import org.eclipse.etrice.core.genmodel.etricegen.ExpandedActorClass;
import org.eclipse.etrice.core.room.ActorClass;
import org.eclipse.etrice.core.room.RoomPackage;
import org.eclipse.etrice.core.room.StateGraphItem;
import org.eclipse.etrice.core.validation.ValidationUtil;
import org.eclipse.xtext.validation.ValidationMessageAcceptor;
public class ReachabilityValidator implements ICustomValidator {
public static final String DIAG_CODE_UNREACHABLE = "etrice.unreachable";
private static final Set<EClass> classesToCheck = new HashSet<EClass>();
{
classesToCheck.add(RoomPackage.Literals.ACTOR_CLASS);
}
@Override
public void validate(EObject object, ValidationMessageAcceptor messageAcceptor, ICustomValidator.ValidationContext context) {
if (!(object instanceof ActorClass))
return;
if(context.isGeneration())
return;
ActorClass ac = (ActorClass) object;
if (ac.isAbstract())
return;
if (ValidationUtil.isCircularClassHierarchy(ac))
// is checked elsewhere
return;
NullDiagnostician diagnostician = new NullDiagnostician();
GeneratorModelBuilder builder = new GeneratorModelBuilder(new NullLogger(), diagnostician);
ExpandedActorClass xpac = null;
try {
xpac = builder.createExpandedActorClass(ac);
}
catch (Throwable t) {
return;
}
if (xpac != null && !diagnostician.isFailed()) {
ReachabilityCheck checker = new ReachabilityCheck(xpac);
checker.computeReachability();
TreeIterator<EObject> it = xpac.getStateMachine().eAllContents();
while (it.hasNext()) {
EObject item = it.next();
if (item instanceof StateGraphItem)
{
StateGraphItem toCheck = (StateGraphItem) item;
if (!checker.isReachable(toCheck)) {
EObject orig = xpac.getOrig(toCheck);
EObject container = orig.eContainer();
@SuppressWarnings("unchecked")
int idx = ((List<? extends EObject>)container.eGet(orig.eContainingFeature())).indexOf(orig);
messageAcceptor.acceptWarning(
"Unreachable state/point of graph",
xpac.getOrig(toCheck).eContainer(), xpac.getOrig(toCheck).eContainingFeature(), idx,
DIAG_CODE_UNREACHABLE, toCheck.getName());
}
}
}
}
}
@Override
public String getName() {
return "State Reachability Validator";
}
@Override
public String getDescription() {
return "This validator checks the reachability of state graph items.";
}
@Override
public Set<EClass> getClassesToCheck() {
return classesToCheck;
}
}
|