Skip to content

Package: ECPValidator

ECPValidator

nameinstructionbranchcomplexitylinemethod
ECPValidator()
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%
createDiagnostic(String, int, String, Object[], Map, List)
M: 0 C: 9
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
createDiagnostic(int, String, int, String, Object[], Map)
M: 0 C: 9
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
validate(EClass, EObject, DiagnosticChain, Map)
M: 2 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
validate(EDataType, Object, DiagnosticChain, Map)
M: 2 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
validate(EObject, DiagnosticChain, Map)
M: 0 C: 8
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
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.diagnostician;
15:
16: import java.util.List;
17: import java.util.Map;
18: import java.util.Set;
19:
20: import org.eclipse.emf.common.util.BasicDiagnostic;
21: import org.eclipse.emf.common.util.Diagnostic;
22: import org.eclipse.emf.common.util.DiagnosticChain;
23: import org.eclipse.emf.ecore.EClass;
24: import org.eclipse.emf.ecore.EClassifier;
25: import org.eclipse.emf.ecore.EDataType;
26: import org.eclipse.emf.ecore.EObject;
27: import org.eclipse.emf.ecore.EValidator;
28:
29: /**
30: * Abstract Class defining an {@link EValidator} that can be used with the ECP validation. Users should override
31: * the {@link ECPValidator#validate(EClass, EObject, DiagnosticChain, Map)} and/or
32: * {@link ECPValidator#validate(EDataType, Object, DiagnosticChain, Map)} methods to add their validations.
33: *
34: * @author jfaltermeier
35: *
36: */
37: public abstract class ECPValidator implements EValidator {
38:
39:         /**
40:          * Returns the {@link EClassifier}s which can be validated.
41:          *
42:          * @return the eclassifiers
43:          */
44:         public abstract Set<EClassifier> getValidatedEClassifier();
45:
46:         /**
47:          * {@inheritDoc}
48:          *
49:          * @see org.eclipse.emf.ecore.EValidator#validate(org.eclipse.emf.ecore.EObject,
50:          * org.eclipse.emf.common.util.DiagnosticChain, java.util.Map)
51:          */
52:         @Override
53:         public boolean validate(EObject eObject, DiagnosticChain diagnostics, Map<Object, Object> context) {
54:                 return validate(eObject.eClass(), eObject, diagnostics, context);
55:         }
56:
57:         /**
58:          * {@inheritDoc}
59:          *
60:          * @see org.eclipse.emf.ecore.EValidator#validate(org.eclipse.emf.ecore.EClass, org.eclipse.emf.ecore.EObject,
61:          * 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:                 return true;
66:         }
67:
68:         /**
69:          * {@inheritDoc}
70:          *
71:          * @see org.eclipse.emf.ecore.EValidator#validate(org.eclipse.emf.ecore.EDataType, java.lang.Object,
72:          * org.eclipse.emf.common.util.DiagnosticChain, java.util.Map)
73:          */
74:         @Override
75:         public boolean validate(EDataType eDataType, Object value, DiagnosticChain diagnostics,
76:                 Map<Object, Object> context) {
77:                 return true;
78:         }
79:
80:         /**
81:          * Creates a diagnostic.
82:          *
83:          * @param severity the severity
84:          * @param source the source of the validation
85:          * @param code unique code
86:          * @param message the message describing the validation error
87:          * @param data the data.
88:          * @param context the context
89:          * @return a diagnostic with the given attributes
90:          */
91:         protected Diagnostic createDiagnostic(int severity, String source, int code, String message, Object[] data,
92:                 Map<Object, Object> context) {
93:                 return new BasicDiagnostic(severity, source, code, message, data);
94:         }
95:
96:         /**
97:          * Creates a diagnostic with child diagnostics.
98:          *
99:          * @param source the source of the validation
100:          * @param code unique code
101:          * @param message the message describing the validation error
102:          * @param data the data.
103:          * @param context the context
104:          * @param childDiagnostics the child diagnostics
105:          * @return a diagnostic with the given attributes
106:          */
107:         protected Diagnostic createDiagnostic(String source, int code, String message, Object[] data,
108:                 Map<Object, Object> context, List<Diagnostic> childDiagnostics) {
109:                 return new BasicDiagnostic(source, code, childDiagnostics, message, data);
110:         }
111: }