Skip to content

Package: LeagueValidator

LeagueValidator

nameinstructionbranchcomplexitylinemethod
LeagueValidator()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
createPlayerDiagnostic(Player, Map)
M: 0 C: 14
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
getValidatedEClassifier()
M: 0 C: 11
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
validate(EClass, EObject, DiagnosticChain, Map)
M: 14 C: 33
70%
M: 2 C: 4
67%
M: 2 C: 3
60%
M: 2 C: 6
75%
M: 0 C: 1
100%
validateAll(EClass, EObject, DiagnosticChain, Map)
M: 0 C: 52
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 9
100%
M: 0 C: 1
100%
validateLeague(EClass, EObject, DiagnosticChain, Map)
M: 0 C: 24
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
validatePlayers(EClass, EObject, DiagnosticChain, Map)
M: 0 C: 25
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 5
100%
M: 0 C: 1
100%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2014 EclipseSource Muenchen GmbH and others.
3: *
4: * All rights reserved. This program and the accompanying materials
5: * are made available under the terms of the Eclipse Public License 2.0
6: * which accompanies this distribution, and is available at
7: * https://www.eclipse.org/legal/epl-2.0/
8: *
9: * SPDX-License-Identifier: EPL-2.0
10: *
11: * Contributors:
12: * Johannes Faltermeier - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emf.ecp.ui.validation.test;
15:
16: import java.util.ArrayList;
17: import java.util.LinkedHashSet;
18: import java.util.List;
19: import java.util.Map;
20: import java.util.Set;
21:
22: import org.eclipse.emf.common.util.Diagnostic;
23: import org.eclipse.emf.common.util.DiagnosticChain;
24: import org.eclipse.emf.common.util.EList;
25: import org.eclipse.emf.ecore.EClass;
26: import org.eclipse.emf.ecore.EClassifier;
27: import org.eclipse.emf.ecore.EObject;
28: import org.eclipse.emf.ecp.diagnostician.ECPValidator;
29: import org.eclipse.emf.emfstore.bowling.BowlingPackage;
30: import org.eclipse.emf.emfstore.bowling.League;
31: import org.eclipse.emf.emfstore.bowling.Player;
32:
33: /**
34: * @author jfaltermeier
35: *
36: */
37: public class LeagueValidator extends ECPValidator {
38:
39:         public static final String LEAGUE_VALIDATOR_MODE = "leagueValidatorMode";
40:
41:         public static final int MODE_ONLY_LEAGUE = 0;
42:         public static final int MODE_ONLY_PLAYER = 1;
43:         public static final int MODE_ALL = 2;
44:
45:         /**
46:          * {@inheritDoc}
47:          *
48:          * @see org.eclipse.emf.ecp.diagnostician.ECPValidator#getValidatedEClassifier()
49:          */
50:         @Override
51:         public Set<EClassifier> getValidatedEClassifier() {
52:                 final Set<EClassifier> classifiers = new LinkedHashSet<EClassifier>();
53:                 classifiers.add(BowlingPackage.eINSTANCE.getLeague());
54:                 return classifiers;
55:         }
56:
57:         /**
58:          * {@inheritDoc}
59:          *
60:          * @see org.eclipse.emf.ecp.diagnostician.ECPValidator#validate(org.eclipse.emf.ecore.EClass,
61:          * org.eclipse.emf.ecore.EObject, org.eclipse.emf.common.util.DiagnosticChain, java.util.Map)
62:          */
63:         @Override
64:         public boolean validate(EClass eClass, EObject eObject, DiagnosticChain diagnostics, Map<Object, Object> context) {
65:•                if (!context.containsKey(LEAGUE_VALIDATOR_MODE)) {
66:                         return super.validate(eClass, eObject, diagnostics, context);
67:                 }
68:                 final int mode = (Integer) context.get(LEAGUE_VALIDATOR_MODE);
69:•                switch (mode) {
70:                 case MODE_ONLY_LEAGUE:
71:                         return validateLeague(eClass, eObject, diagnostics, context);
72:                 case MODE_ONLY_PLAYER:
73:                         return validatePlayers(eClass, eObject, diagnostics, context);
74:                 case MODE_ALL:
75:                         return validateAll(eClass, eObject, diagnostics, context);
76:                 default:
77:                         return super.validate(eClass, eObject, diagnostics, context);
78:                 }
79:         }
80:
81:         private boolean validateLeague(EClass eClass, EObject eObject, DiagnosticChain diagnostics,
82:                 Map<Object, Object> context) {
83:                 final Diagnostic diagnostic = createDiagnostic(Diagnostic.ERROR, "source", 0,
84:                         "There is something wrong with the players",
85:                         new Object[] { eObject, BowlingPackage.eINSTANCE.getLeague_Players() }, context);
86:                 diagnostics.add(diagnostic);
87:                 return false;
88:         }
89:
90:         private boolean validatePlayers(EClass eClass, EObject eObject, DiagnosticChain diagnostics,
91:                 Map<Object, Object> context) {
92:                 final League league = (League) eObject;
93:                 final EList<Player> players = league.getPlayers();
94:•                for (final Player p : players) {
95:                         diagnostics.add(createPlayerDiagnostic(p, context));
96:                 }
97:                 return false;
98:         }
99:
100:         private boolean validateAll(EClass eClass, EObject eObject, DiagnosticChain diagnostics,
101:                 Map<Object, Object> context) {
102:                 final League league = (League) eObject;
103:                 final EList<Player> players = league.getPlayers();
104:                 final List<Diagnostic> childDiagnostics = new ArrayList<Diagnostic>();
105:•                for (final Player p : players) {
106:                         childDiagnostics.add(createPlayerDiagnostic(p, context));
107:                 }
108:                 final Diagnostic diagnostic = createDiagnostic("source", 0, "There is something wrong with the players",
109:                         new Object[] { league, BowlingPackage.eINSTANCE.getLeague_Players() }, context, childDiagnostics);
110:                 diagnostics.add(diagnostic);
111:                 return false;
112:         }
113:
114:         private Diagnostic createPlayerDiagnostic(Player player, Map<Object, Object> context) {
115:                 return createDiagnostic(Diagnostic.ERROR, "source", 0, "There is something wrong with this Player",
116:                         new Object[] { player }, context);
117:         }
118:
119: }