|
| 1 | +// Copyright (c) Microsoft Corporation. |
| 2 | +// Licensed under the MIT license. |
| 3 | + |
| 4 | +package com.microsoft.copilot.eclipse.ui.nes; |
| 5 | + |
| 6 | +import static org.junit.jupiter.api.Assertions.assertFalse; |
| 7 | +import static org.junit.jupiter.api.Assertions.assertNotEquals; |
| 8 | +import static org.junit.jupiter.api.Assertions.assertNotNull; |
| 9 | +import static org.junit.jupiter.api.Assertions.assertTrue; |
| 10 | + |
| 11 | +import org.eclipse.core.resources.IMarker; |
| 12 | +import org.eclipse.core.runtime.IConfigurationElement; |
| 13 | +import org.eclipse.core.runtime.IExtensionPoint; |
| 14 | +import org.eclipse.core.runtime.Platform; |
| 15 | +import org.eclipse.ui.texteditor.AnnotationTypeLookup; |
| 16 | +import org.junit.jupiter.api.Test; |
| 17 | + |
| 18 | +class NesAnnotationTypeMappingTest { |
| 19 | + |
| 20 | + private static final String ANNOTATION_TYPES_EXTENSION_POINT = "org.eclipse.ui.editors.annotationTypes"; |
| 21 | + private static final String FOREIGN_TEXT_MARKER = |
| 22 | + "com.microsoft.copilot.eclipse.ui.test.foreignTextMarker"; |
| 23 | + private static final String NES_ANNOTATION_PREFIX = "com.microsoft.copilot.eclipse.ui.nes."; |
| 24 | + private static final String NES_CHANGE_ANNOTATION = NES_ANNOTATION_PREFIX + "change"; |
| 25 | + private static final String NES_DELETE_ANNOTATION = NES_ANNOTATION_PREFIX + "delete"; |
| 26 | + private static final String ROOT_TEXT_MARKER = "org.eclipse.core.resources.textmarker"; |
| 27 | + |
| 28 | + @Test |
| 29 | + void testForeignTextMarkerSubtypeDoesNotResolveToNesAnnotations() { |
| 30 | + AnnotationTypeLookup lookup = new AnnotationTypeLookup(); |
| 31 | + |
| 32 | + String annotationType = lookup.getAnnotationType(FOREIGN_TEXT_MARKER, IMarker.SEVERITY_INFO); |
| 33 | + |
| 34 | + assertNotEquals(NES_CHANGE_ANNOTATION, annotationType); |
| 35 | + assertNotEquals(NES_DELETE_ANNOTATION, annotationType); |
| 36 | + } |
| 37 | + |
| 38 | + @Test |
| 39 | + void testNesAnnotationTypesDoNotMapToRootTextMarker() { |
| 40 | + IExtensionPoint extensionPoint = Platform.getExtensionRegistry() |
| 41 | + .getExtensionPoint(ANNOTATION_TYPES_EXTENSION_POINT); |
| 42 | + assertNotNull(extensionPoint); |
| 43 | + assertTrue(hasNesAnnotationType(extensionPoint, NES_CHANGE_ANNOTATION)); |
| 44 | + assertTrue(hasNesAnnotationType(extensionPoint, NES_DELETE_ANNOTATION)); |
| 45 | + assertFalse(hasNesRootTextMarkerMapping(extensionPoint)); |
| 46 | + } |
| 47 | + |
| 48 | + private boolean hasNesAnnotationType(IExtensionPoint extensionPoint, String annotationType) { |
| 49 | + for (IConfigurationElement element : extensionPoint.getConfigurationElements()) { |
| 50 | + if ("type".equals(element.getName()) && annotationType.equals(element.getAttribute("name"))) { |
| 51 | + return true; |
| 52 | + } |
| 53 | + } |
| 54 | + return false; |
| 55 | + } |
| 56 | + |
| 57 | + private boolean hasNesRootTextMarkerMapping(IExtensionPoint extensionPoint) { |
| 58 | + for (IConfigurationElement element : extensionPoint.getConfigurationElements()) { |
| 59 | + String annotationType = element.getAttribute("name"); |
| 60 | + if ("type".equals(element.getName()) && annotationType != null |
| 61 | + && annotationType.startsWith(NES_ANNOTATION_PREFIX) |
| 62 | + && ROOT_TEXT_MARKER.equals(element.getAttribute("markerType"))) { |
| 63 | + return true; |
| 64 | + } |
| 65 | + } |
| 66 | + return false; |
| 67 | + } |
| 68 | +} |
0 commit comments