Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: ca0fe0a1e9edef0e0324f9e923a4825d8c7cceb3 (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

/*******************************************************************************
 * 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.List;

import org.eclipse.emf.common.util.TreeIterator;
import org.eclipse.emf.ecore.EObject;
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.StateGraphItem;
import org.eclipse.etrice.core.validation.IRoomValidator;
import org.eclipse.etrice.core.validation.ValidationUtil;
import org.eclipse.xtext.validation.ValidationMessageAcceptor;


public class ReachabilityValidator implements IRoomValidator {

	public static String DIAG_CODE_UNREACHABLE = "etrice.unreachable";
	
	@Override
	public void validate(EObject object, ValidationMessageAcceptor messageAcceptor) {

		if (!(object instanceof ActorClass))
			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 = builder.createExpandedActorClass(ac);
		
		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.";
	}

}

Back to the top