Skip to content

Package: ThresholdDiagnostic$Factory

ThresholdDiagnostic$Factory

nameinstructionbranchcomplexitylinemethod
ThresholdDiagnostic.Factory(EMFFormsLocalizationService)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
create(int)
M: 0 C: 11
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
get(int)
M: 33 C: 13
28%
M: 7 C: 3
30%
M: 5 C: 2
29%
M: 7 C: 4
36%
M: 0 C: 1
100%
notThresholdDiagnostic()
M: 0 C: 9
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2019 Christian W. Damus 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: * Christian W. Damus - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emf.ecp.view.internal.validation;
15:
16: import java.util.function.Predicate;
17:
18: import org.eclipse.emf.common.util.BasicDiagnostic;
19: import org.eclipse.emf.common.util.Diagnostic;
20: import org.eclipse.emfforms.spi.localization.EMFFormsLocalizationService;
21:
22: /**
23: * A specialized diagnostic indicating a reporting threshold that was reached,
24: * representing all of the unreported problems.
25: */
26: final class ThresholdDiagnostic extends BasicDiagnostic {
27:
28:         /**
29:          * Initializes me.
30:          *
31:          * @param severity the problem severity
32:          * @param message the message
33:          */
34:         private ThresholdDiagnostic(int severity, String message) {
35:                 super(severity, Activator.PLUGIN_ID, 0, message, null);
36:         }
37:
38:         //
39:         // Nested types
40:         //
41:
42:         /**
43:          * A factory of (pooled) threshold diagnostics.
44:          */
45:         static final class Factory {
46:                 private final EMFFormsLocalizationService l10n;
47:
48:                 private ThresholdDiagnostic errorInstance;
49:                 private ThresholdDiagnostic warningInstance;
50:                 private ThresholdDiagnostic infoInstance;
51:
52:                 /**
53:                  * Initializes me with the localization service from which to get messages.
54:                  *
55:                  * @param l10n the localization service for access to messages
56:                  */
57:                 Factory(EMFFormsLocalizationService l10n) {
58:                         super();
59:
60:                         this.l10n = l10n;
61:                 }
62:
63:                 /**
64:                  * Get the threshold diagnostic representing unreported problems of the
65:                  * given {@code severity} and less.
66:                  *
67:                  * @param severity the maximal unreported problem severity
68:                  * @return the threshold diagnostic for that {@code severity}
69:                  */
70:                 ThresholdDiagnostic get(int severity) {
71:•                        switch (severity) {
72:                         case Diagnostic.CANCEL:
73:                         case Diagnostic.ERROR:
74:•                                if (errorInstance == null) {
75:                                         errorInstance = create(Diagnostic.ERROR);
76:                                 }
77:                                 return errorInstance;
78:                         case Diagnostic.WARNING:
79:•                                if (warningInstance == null) {
80:                                         warningInstance = create(Diagnostic.WARNING);
81:                                 }
82:                                 return warningInstance;
83:                         case Diagnostic.INFO:
84:•                                if (infoInstance == null) {
85:                                         infoInstance = create(Diagnostic.INFO);
86:                                 }
87:                                 return infoInstance;
88:                         default:
89:                                 throw new IllegalArgumentException("severity: " + severity); //$NON-NLS-1$
90:                         }
91:                 }
92:
93:                 private ThresholdDiagnostic create(int severity) {
94:                         return new ThresholdDiagnostic(severity,
95:                                 l10n.getString(ThresholdDiagnostic.class, "ValidationServiceImpl_moreProblems")); //$NON-NLS-1$
96:                 }
97:
98:                 /**
99:                  * Obtain a predicate matching diagnostics that are not threshold diagnostic
100:                  * placeholders.
101:                  *
102:                  * @return a not-a-threshold-diagnostic filter
103:                  */
104:                 Predicate<Diagnostic> notThresholdDiagnostic() {
105:                         final Predicate<Diagnostic> isThreshold = ThresholdDiagnostic.class::isInstance;
106:                         return isThreshold.negate();
107:                 }
108:
109:         }
110:
111: }