From 1a8c0300c3794b37507a5b973dac35ea6dd8120b Mon Sep 17 00:00:00 2001 From: David Thompson Date: Thu, 6 May 2021 12:03:46 -0400 Subject: [PATCH] Fix ability to disable "no grammar" message Fixes redhat-developer/vscode-xml#467 Signed-off-by: David Thompson --- .../settings/XMLValidationSettings.java | 1 + .../lemminx/settings/SettingsMergeTest.java | 56 +++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/settings/SettingsMergeTest.java diff --git a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/extensions/contentmodel/settings/XMLValidationSettings.java b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/extensions/contentmodel/settings/XMLValidationSettings.java index b81692bd29..330e361bee 100644 --- a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/extensions/contentmodel/settings/XMLValidationSettings.java +++ b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/extensions/contentmodel/settings/XMLValidationSettings.java @@ -182,6 +182,7 @@ public XMLValidationSettings merge(XMLValidationSettings settings) { this.namespaces = settings.namespaces; this.schema = settings.schema; this.enabled = settings.enabled; + this.noGrammar = settings.noGrammar; this.disallowDocTypeDecl = settings.disallowDocTypeDecl; this.resolveExternalEntities = settings.resolveExternalEntities; } diff --git a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/settings/SettingsMergeTest.java b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/settings/SettingsMergeTest.java new file mode 100644 index 0000000000..f80d28c57e --- /dev/null +++ b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/settings/SettingsMergeTest.java @@ -0,0 +1,56 @@ +/******************************************************************************* +* Copyright (c) 2021 Red Hat Inc. and others. +* All rights reserved. This program and the accompanying materials +* which accompanies this distribution, and is available at +* http://www.eclipse.org/legal/epl-v20.html +* +* Contributors: +* Red Hat Inc. - initial API and implementation +*******************************************************************************/ +package org.eclipse.lemminx.settings; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.lang.reflect.Field; +import java.lang.reflect.Type; + +import org.eclipse.lemminx.extensions.contentmodel.settings.XMLValidationSettings; +import org.junit.jupiter.api.Test; + +public class SettingsMergeTest { + + @Test + public void testValidationSettingsMerge() throws IllegalArgumentException, IllegalAccessException { + XMLValidationSettings settings = new XMLValidationSettings(); + mutateValues(settings); + XMLValidationSettings mergeTargetSettings = new XMLValidationSettings(); + mergeTargetSettings.merge(settings); + assertEquals(settings, mergeTargetSettings); + } + + /** + * Mutates all the values of all the fields, under the assumption that all Object fields are non-null + */ + public static void mutateValues(Object obj) throws IllegalArgumentException, IllegalAccessException { + for (Field field : XMLValidationSettings.class.getFields()) { + Type type = field.getGenericType(); + switch (type.getTypeName()) { + case "boolean": + field.set(obj, !(Boolean)field.get(obj)); + break; + case "int": + case "short": + case "long": + case "char": + case "byte": + case "float": + case "double": + field.set(field, (Integer)field.get(obj) == 0 ? 1 : 0); + break; + default: + field.set(field, null); + } + } + } + +}