Skip to content

Package: DefaultMarkerHelper

DefaultMarkerHelper

nameinstructionbranchcomplexitylinemethod
DefaultMarkerHelper()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
adjustMarker(IMarker, Diagnostic, Diagnostic)
M: 4 C: 61
94%
M: 1 C: 11
92%
M: 1 C: 6
86%
M: 1 C: 16
94%
M: 0 C: 1
100%
createMarkers(IResource, Diagnostic, Diagnostic)
M: 0 C: 28
100%
M: 0 C: 4
100%
M: 0 C: 3
100%
M: 0 C: 6
100%
M: 0 C: 1
100%
getFile(Object)
M: 10 C: 7
41%
M: 3 C: 1
25%
M: 2 C: 1
33%
M: 1 C: 2
67%
M: 0 C: 1
100%
getMarkerID()
M: 0 C: 2
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) 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.emfforms.ide.builder;
15:
16: import org.eclipse.core.resources.IFile;
17: import org.eclipse.core.resources.IMarker;
18: import org.eclipse.core.resources.IResource;
19: import org.eclipse.core.runtime.CoreException;
20: import org.eclipse.emf.common.ui.MarkerHelper;
21: import org.eclipse.emf.common.util.Diagnostic;
22: import org.eclipse.emf.common.util.URI;
23: import org.eclipse.emf.ecore.EObject;
24: import org.eclipse.emf.ecore.EValidator;
25: import org.eclipse.emf.ecore.util.EcoreUtil;
26: import org.eclipse.emf.edit.ui.util.EditUIMarkerHelper;
27: import org.eclipse.emfforms.ide.internal.builder.ValidationBuilder;
28:
29: /**
30: * Default implementation of the {@link MarkerHelper} that accounts for the fact
31: * that the {@link ValidationServiceDelegate} unloads its resource set before markers
32: * are created, so that objects in the {@linkplain Diagnostic diagnostics} are
33: * proxies by the time markers are created.
34: */
35: public class DefaultMarkerHelper extends EditUIMarkerHelper {
36:
37:         /**
38:          * Initializes me.
39:          */
40:         public DefaultMarkerHelper() {
41:                 super();
42:         }
43:
44:         @Override
45:         protected String getMarkerID() {
46:                 return ValidationBuilder.MARKER_ID;
47:         }
48:
49:         @Override
50:         protected IFile getFile(Object datum) {
51:•                return datum instanceof EObject && ((EObject) datum).eIsProxy()
52:                         ? getFile(EcoreUtil.getURI((EObject) datum))
53:                         : super.getFile(datum);
54:         }
55:
56:         @Override
57:         protected void createMarkers(IResource resource, Diagnostic diagnostic, Diagnostic parentDiagnostic)
58:                 throws CoreException {
59:
60:•                if (diagnostic.getChildren().isEmpty()) {
61:                         super.createMarkers(resource, diagnostic, parentDiagnostic);
62:                 } else {
63:                         // From the ValidationServiceDelegate, we can get more than two levels of nesting
64:•                        for (final Diagnostic next : diagnostic.getChildren()) {
65:                                 createMarkers(resource, next, diagnostic);
66:                         }
67:                 }
68:         }
69:
70:         /**
71:          * Add attributes to store the URIs of the problematic object and the feature (if any).
72:          * Match exactly the specification or main and related URIs attributes expected by EMF's
73:          * marker utility.
74:          */
75:         @Override
76:         protected void adjustMarker(IMarker marker, Diagnostic diagnostic, Diagnostic parentDiagnostic)
77:                 throws CoreException {
78:
79:                 // The first URI is not encoded because there is only one, so spaces in the string don't
80:                 // matter. But the related URIs are a list separated by spaces, so they are encoded and
81:                 // will be decoded by the MarkerUtil as needed
82:                 String uri = null;
83:                 final StringBuilder relatedURIs = new StringBuilder();
84:
85:•                for (final Object next : diagnostic.getData()) {
86:•                        if (next instanceof EObject) {
87:                                 final EObject eObject = (EObject) next;
88:•                                if (uri == null) {
89:                                         uri = EcoreUtil.getURI(eObject).toString();
90:                                 } else {
91:•                                        if (relatedURIs.length() > 0) {
92:                                                 relatedURIs.append(' '); // Space to separate encoded URIs
93:                                         }
94:                                         relatedURIs.append(URI.encodeFragment(EcoreUtil.getURI(eObject).toString(), false));
95:                                 }
96:                         }
97:                 }
98:
99:•                if (uri != null) {
100:                         marker.setAttribute(EValidator.URI_ATTRIBUTE, uri);
101:                 }
102:•                if (relatedURIs.length() > 0) {
103:                         marker.setAttribute(EValidator.RELATED_URIS_ATTRIBUTE, relatedURIs.toString());
104:                 }
105:
106:                 super.adjustMarker(marker, diagnostic, parentDiagnostic);
107:         }
108:
109: }