From 054a84b54b8a382a8ee674452fe39417d2ded1b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Dinis=20Ferreira?= Date: Thu, 11 Jun 2026 15:02:09 +0100 Subject: [PATCH 1/3] refactor: migrate Xtend to Java - com.avaloq.tools.ddk.checkcfg.core --- com.avaloq.tools.ddk.checkcfg.core/.classpath | 5 - .../build.properties | 3 +- .../checkcfg/generator/CheckCfgGenerator.java | 62 +++++++ .../generator/CheckCfgGenerator.xtend | 56 ------ ...er.xtend => CheckCfgJvmModelInferrer.java} | 42 ++--- .../util/PropertiesInferenceHelper.java | 159 ++++++++++++++++++ .../util/PropertiesInferenceHelper.xtend | 140 --------------- .../validation/ConfiguredParameterChecks.java | 81 +++++++++ .../ConfiguredParameterChecks.xtend | 66 -------- .../xtend-gen/.gitignore | 0 10 files changed, 326 insertions(+), 288 deletions(-) create mode 100644 com.avaloq.tools.ddk.checkcfg.core/src/com/avaloq/tools/ddk/checkcfg/generator/CheckCfgGenerator.java delete mode 100644 com.avaloq.tools.ddk.checkcfg.core/src/com/avaloq/tools/ddk/checkcfg/generator/CheckCfgGenerator.xtend rename com.avaloq.tools.ddk.checkcfg.core/src/com/avaloq/tools/ddk/checkcfg/jvmmodel/{CheckCfgJvmModelInferrer.xtend => CheckCfgJvmModelInferrer.java} (52%) create mode 100644 com.avaloq.tools.ddk.checkcfg.core/src/com/avaloq/tools/ddk/checkcfg/util/PropertiesInferenceHelper.java delete mode 100644 com.avaloq.tools.ddk.checkcfg.core/src/com/avaloq/tools/ddk/checkcfg/util/PropertiesInferenceHelper.xtend create mode 100644 com.avaloq.tools.ddk.checkcfg.core/src/com/avaloq/tools/ddk/checkcfg/validation/ConfiguredParameterChecks.java delete mode 100644 com.avaloq.tools.ddk.checkcfg.core/src/com/avaloq/tools/ddk/checkcfg/validation/ConfiguredParameterChecks.xtend delete mode 100644 com.avaloq.tools.ddk.checkcfg.core/xtend-gen/.gitignore diff --git a/com.avaloq.tools.ddk.checkcfg.core/.classpath b/com.avaloq.tools.ddk.checkcfg.core/.classpath index 0f2735e0da..657ce4953b 100644 --- a/com.avaloq.tools.ddk.checkcfg.core/.classpath +++ b/com.avaloq.tools.ddk.checkcfg.core/.classpath @@ -6,11 +6,6 @@ - - - - - diff --git a/com.avaloq.tools.ddk.checkcfg.core/build.properties b/com.avaloq.tools.ddk.checkcfg.core/build.properties index 7838757824..d69df83aa0 100644 --- a/com.avaloq.tools.ddk.checkcfg.core/build.properties +++ b/com.avaloq.tools.ddk.checkcfg.core/build.properties @@ -1,6 +1,5 @@ source.. = src/,\ - src-gen/,\ - xtend-gen/ + src-gen/ bin.includes = META-INF/,\ .,\ plugin.xml,\ diff --git a/com.avaloq.tools.ddk.checkcfg.core/src/com/avaloq/tools/ddk/checkcfg/generator/CheckCfgGenerator.java b/com.avaloq.tools.ddk.checkcfg.core/src/com/avaloq/tools/ddk/checkcfg/generator/CheckCfgGenerator.java new file mode 100644 index 0000000000..b7cbf606ae --- /dev/null +++ b/com.avaloq.tools.ddk.checkcfg.core/src/com/avaloq/tools/ddk/checkcfg/generator/CheckCfgGenerator.java @@ -0,0 +1,62 @@ +/******************************************************************************* + * Copyright (c) 2016 Avaloq Group AG and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Avaloq Group AG - initial API and implementation + *******************************************************************************/ +package com.avaloq.tools.ddk.checkcfg.generator; + +import java.util.Properties; + +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.xtext.generator.AbstractFileSystemAccess; +import org.eclipse.xtext.generator.IFileSystemAccess; +import org.eclipse.xtext.generator.IFileSystemAccess2; +import org.eclipse.xtext.generator.IGenerator; +import org.eclipse.xtext.xbase.lib.IteratorExtensions; + +import com.avaloq.tools.ddk.check.generator.LfNormalizingFileSystemAccess; +import com.avaloq.tools.ddk.check.runtime.configuration.ICheckConfigurationStoreService; +import com.avaloq.tools.ddk.checkcfg.checkcfg.CheckConfiguration; +import com.google.common.collect.Iterables; +import com.google.inject.Inject; + +@SuppressWarnings("nls") +public class CheckCfgGenerator implements IGenerator { + + @Inject + private CheckConfigurationPropertiesGenerator propertiesGenerator; + + public String outputPath() { + return ".settings"; + } + + @SuppressWarnings("PMD.UnusedFormalParameter") // parameter kept for API consistency + public String fileName(final CheckConfiguration configuration) { + return ICheckConfigurationStoreService.DEFAULT_CHECK_CONFIGURATION_NODE + ".prefs"; + } + + @Override + public void doGenerate(final Resource resource, final IFileSystemAccess fsa) { + if (fsa instanceof AbstractFileSystemAccess abstractFsa) { + abstractFsa.setOutputPath(outputPath()); + } + final LfNormalizingFileSystemAccess lfFsa = new LfNormalizingFileSystemAccess((IFileSystemAccess2) fsa); + for (final CheckConfiguration configuration : Iterables.filter(IteratorExtensions.toIterable(resource.getAllContents()), CheckConfiguration.class)) { + lfFsa.generateFile(fileName(configuration), compile(configuration)); + } + } + + public CharSequence compile(final CheckConfiguration config) { + final Properties properties = propertiesGenerator.convertToProperties(config); + final StringBuilder builder = new StringBuilder(512); + for (final Object k : properties.keySet()) { + builder.append(k).append('=').append(properties.get(k)).append('\n'); + } + return builder.toString(); + } +} diff --git a/com.avaloq.tools.ddk.checkcfg.core/src/com/avaloq/tools/ddk/checkcfg/generator/CheckCfgGenerator.xtend b/com.avaloq.tools.ddk.checkcfg.core/src/com/avaloq/tools/ddk/checkcfg/generator/CheckCfgGenerator.xtend deleted file mode 100644 index e7a49aa53e..0000000000 --- a/com.avaloq.tools.ddk.checkcfg.core/src/com/avaloq/tools/ddk/checkcfg/generator/CheckCfgGenerator.xtend +++ /dev/null @@ -1,56 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016 Avaloq Group AG and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Avaloq Group AG - initial API and implementation - *******************************************************************************/ -package com.avaloq.tools.ddk.checkcfg.generator - -import com.avaloq.tools.ddk.check.generator.LfNormalizingFileSystemAccess -import com.avaloq.tools.ddk.check.runtime.configuration.ICheckConfigurationStoreService -import com.avaloq.tools.ddk.checkcfg.checkcfg.CheckConfiguration -import com.google.inject.Inject -import org.eclipse.emf.ecore.resource.Resource -import org.eclipse.xtext.generator.AbstractFileSystemAccess -import org.eclipse.xtext.generator.IFileSystemAccess -import org.eclipse.xtext.generator.IFileSystemAccess2 -import org.eclipse.xtext.generator.IGenerator - -import static org.eclipse.xtext.xbase.lib.IteratorExtensions.* - -class CheckCfgGenerator implements IGenerator { - - @Inject - CheckConfigurationPropertiesGenerator propertiesGenerator; - - def outputPath() { - '.settings' - } - - def fileName(CheckConfiguration configuration) { - ICheckConfigurationStoreService.DEFAULT_CHECK_CONFIGURATION_NODE + '.prefs' - } - - override void doGenerate(Resource resource, IFileSystemAccess fsa) { - if (fsa instanceof AbstractFileSystemAccess) { - fsa.setOutputPath(outputPath) - } - val lfFsa = new LfNormalizingFileSystemAccess(fsa as IFileSystemAccess2) - for (configuration:toIterable(resource.allContents).filter(typeof(CheckConfiguration))) { - lfFsa.generateFile(configuration.fileName, configuration.compile) - } - } - - def compile(CheckConfiguration config) { - val properties = propertiesGenerator.convertToProperties(config); - ''' - «FOR k:properties.keySet» - «k»=«properties.get(k)» - «ENDFOR» - ''' - } -} diff --git a/com.avaloq.tools.ddk.checkcfg.core/src/com/avaloq/tools/ddk/checkcfg/jvmmodel/CheckCfgJvmModelInferrer.xtend b/com.avaloq.tools.ddk.checkcfg.core/src/com/avaloq/tools/ddk/checkcfg/jvmmodel/CheckCfgJvmModelInferrer.java similarity index 52% rename from com.avaloq.tools.ddk.checkcfg.core/src/com/avaloq/tools/ddk/checkcfg/jvmmodel/CheckCfgJvmModelInferrer.xtend rename to com.avaloq.tools.ddk.checkcfg.core/src/com/avaloq/tools/ddk/checkcfg/jvmmodel/CheckCfgJvmModelInferrer.java index 05a1ab5b2c..272e4e0ff7 100644 --- a/com.avaloq.tools.ddk.checkcfg.core/src/com/avaloq/tools/ddk/checkcfg/jvmmodel/CheckCfgJvmModelInferrer.xtend +++ b/com.avaloq.tools.ddk.checkcfg.core/src/com/avaloq/tools/ddk/checkcfg/jvmmodel/CheckCfgJvmModelInferrer.java @@ -8,13 +8,14 @@ * Contributors: * Avaloq Group AG - initial API and implementation *******************************************************************************/ -package com.avaloq.tools.ddk.checkcfg.jvmmodel +package com.avaloq.tools.ddk.checkcfg.jvmmodel; -import org.eclipse.emf.ecore.EObject -import org.eclipse.xtext.xbase.jvmmodel.AbstractModelInferrer -import org.eclipse.xtext.xbase.jvmmodel.IJvmDeclaredTypeAcceptor -import com.google.inject.Inject -import org.eclipse.xtext.xbase.jvmmodel.JvmTypesBuilder +import org.eclipse.emf.ecore.EObject; +import org.eclipse.xtext.xbase.jvmmodel.AbstractModelInferrer; +import org.eclipse.xtext.xbase.jvmmodel.IJvmDeclaredTypeAcceptor; +import org.eclipse.xtext.xbase.jvmmodel.JvmTypesBuilder; + +import com.google.inject.Inject; /** *

Infers a JVM model from the source model.

@@ -22,24 +23,27 @@ *

The JVM model should contain all elements that would appear in the Java code * which is generated from the source model. Other models link against the JVM model rather than the source model.

*/ -class CheckCfgJvmModelInferrer extends AbstractModelInferrer { +@SuppressWarnings("nls") +public class CheckCfgJvmModelInferrer extends AbstractModelInferrer { - @Inject extension JvmTypesBuilder + @Inject + private JvmTypesBuilder jvmTypesBuilder; - override void _infer(EObject element, IJvmDeclaredTypeAcceptor acceptor, boolean preIndexingPhase) { + @Override + public void _infer(final EObject element, final IJvmDeclaredTypeAcceptor acceptor, final boolean preIndexingPhase) { // Infer dummy class as type resolver expects at least one root Java type - acceptor.accept(element.toClass("xxxyyyzzz.dummy.class.name")[]) + acceptor.accept(jvmTypesBuilder.toClass(element, "xxxyyyzzz.dummy.class.name", it -> {})); } // Here you explain how your model is mapped to Java elements, by writing the actual translation code. // An example based on the initial hellow world example could look like this: -// acceptor.accept(element.toClass("my.company.greeting.MyGreetings") [ -// for (greeting : element.greetings) { -// members += greeting.toMethod(greeting.name, greeting.newTypeRef(typeof(String))) [ -// it.body [''' -// return "Hello «greeting.name»"; -// '''] -// ] -// } -// ]) +// acceptor.accept(element.toClass("my.company.greeting.MyGreetings") [ +// for (greeting : element.greetings) { +// members += greeting.toMethod(greeting.name, greeting.newTypeRef(typeof(String))) [ +// it.body [''' +// return "Hello «greeting.name»"; +// '''] +// ] +// } +// ]) } diff --git a/com.avaloq.tools.ddk.checkcfg.core/src/com/avaloq/tools/ddk/checkcfg/util/PropertiesInferenceHelper.java b/com.avaloq.tools.ddk.checkcfg.core/src/com/avaloq/tools/ddk/checkcfg/util/PropertiesInferenceHelper.java new file mode 100644 index 0000000000..2813dcbea1 --- /dev/null +++ b/com.avaloq.tools.ddk.checkcfg.core/src/com/avaloq/tools/ddk/checkcfg/util/PropertiesInferenceHelper.java @@ -0,0 +1,159 @@ +/******************************************************************************* + * Copyright (c) 2016 Avaloq Group AG and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Avaloq Group AG - initial API and implementation + *******************************************************************************/ + +package com.avaloq.tools.ddk.checkcfg.util; + +import java.util.Collection; +import java.util.List; + +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.common.util.URI; +import org.eclipse.xtext.EcoreUtil2; +import org.eclipse.xtext.common.types.JvmTypeReference; +import org.eclipse.xtext.resource.IResourceServiceProvider; +import org.eclipse.xtext.xbase.XBooleanLiteral; +import org.eclipse.xtext.xbase.XExpression; +import org.eclipse.xtext.xbase.XListLiteral; +import org.eclipse.xtext.xbase.XNumberLiteral; +import org.eclipse.xtext.xbase.XStringLiteral; +import org.eclipse.xtext.xbase.jvmmodel.JvmTypeReferenceBuilder; + +import com.avaloq.tools.ddk.check.check.FormalParameter; +import com.avaloq.tools.ddk.check.check.impl.CheckFactoryImpl; +import com.avaloq.tools.ddk.checkcfg.CheckCfgUtil; +import com.avaloq.tools.ddk.checkcfg.ICheckCfgPropertySpecification; +import com.avaloq.tools.ddk.checkcfg.checkcfg.CheckConfiguration; +import com.avaloq.tools.ddk.checkcfg.checkcfg.CheckcfgPackage; +import com.avaloq.tools.ddk.checkcfg.checkcfg.ConfigurableSection; +import com.avaloq.tools.ddk.checkcfg.checkcfg.ConfiguredParameter; +import com.avaloq.tools.ddk.xtext.util.ParseTreeUtil; +import com.google.inject.Inject; + +@SuppressWarnings("nls") +public class PropertiesInferenceHelper { + + @Inject + private JvmTypeReferenceBuilder.Factory typeRefBuilderFactory; + + private static final String BOOLEAN = "boolean"; + private static final String STRING = "java.lang.String"; + private static final String NUMBER = "int"; + private static final String STRING_LIST = "List"; + private static final String NUMBER_LIST = "List"; + private static final String BOOLEAN_LIST = "List"; + + public EList getProperties(final CheckConfiguration checkConfiguration, final EList properties) { + final JvmTypeReferenceBuilder referenceBuilder = typeRefBuilderFactory.create(checkConfiguration.eResource().getResourceSet()); + + // get all ConfigurableSections + final List configurableSections = EcoreUtil2.getAllContentsOfType(checkConfiguration, ConfigurableSection.class); + // the CheckConfiguration itself is a configurable section + configurableSections.add(0, checkConfiguration); + + // infer properties for all sections + for (final ConfigurableSection section : configurableSections) { + final EList parameters = section.getParameterConfigurations(); + for (final ConfiguredParameter parameter : parameters) { + final FormalParameter formalParameter = inferFormalParameter(parameter, referenceBuilder); + if (formalParameter != null) { + properties.add(formalParameter); + } + } + } + + // add contributed properties + final Collection contributions = CheckCfgUtil.getAllPropertyContributions(); + for (final ICheckCfgPropertySpecification contribution : contributions) { + final FormalParameter formalParameter = inferFormalParameter(contribution, referenceBuilder); + if (formalParameter != null) { + properties.add(formalParameter); + } + } + return properties; + } + + public JvmTypeReference inferType(final ICheckCfgPropertySpecification contribution, final JvmTypeReferenceBuilder referenceBuilder) { + final ICheckCfgPropertySpecification.PropertyType type = contribution.getType(); + if (type == null) { + return null; + } + return switch (type) { + case BOOLEAN -> referenceBuilder.typeRef(BOOLEAN); + case NUMBER -> referenceBuilder.typeRef(NUMBER); + case STRING -> referenceBuilder.typeRef(STRING); + case NUMBERS -> referenceBuilder.typeRef(NUMBER_LIST); + case STRINGS -> referenceBuilder.typeRef(STRING_LIST); + case BOOLEANS -> referenceBuilder.typeRef(BOOLEAN_LIST); + }; + } + + public JvmTypeReference inferListType(final XListLiteral newValue, final JvmTypeReferenceBuilder referenceBuilder) { + if (newValue.getElements().isEmpty()) { + return null; + } + final XExpression firstElement = newValue.getElements().get(0); + if (firstElement instanceof XBooleanLiteral) { + return referenceBuilder.typeRef(BOOLEAN_LIST); + } else if (firstElement instanceof XNumberLiteral) { + return referenceBuilder.typeRef(NUMBER_LIST); + } else if (firstElement instanceof XStringLiteral) { + return referenceBuilder.typeRef(STRING_LIST); + } else { + return null; + } + } + + public JvmTypeReference inferType(final ConfiguredParameter parameter, final JvmTypeReferenceBuilder referenceBuilder) { + final XExpression newValue = parameter.getNewValue(); + if (newValue instanceof XBooleanLiteral) { + return referenceBuilder.typeRef(BOOLEAN); + } else if (newValue instanceof XNumberLiteral) { + return referenceBuilder.typeRef(NUMBER); + } else if (newValue instanceof XStringLiteral) { + return referenceBuilder.typeRef(STRING); + } else if (newValue instanceof XListLiteral xListLiteral) { + return inferListType(xListLiteral, referenceBuilder); + } else { + return null; + } + } + + public FormalParameter inferFormalParameter(final ConfiguredParameter parameter, final JvmTypeReferenceBuilder referenceBuilder) { + if (parameter == null) { + return null; + } + return inferFormalParameter(ParseTreeUtil.getParsedString(parameter, CheckcfgPackage.Literals.CONFIGURED_PARAMETER__PARAMETER), + inferType(parameter, referenceBuilder)); + } + + public FormalParameter inferFormalParameter(final ICheckCfgPropertySpecification contribution, final JvmTypeReferenceBuilder referenceBuilder) { + if (contribution == null) { + return null; + } + return inferFormalParameter(contribution.getName(), inferType(contribution, referenceBuilder)); + } + + public FormalParameter inferFormalParameter(final String name, final JvmTypeReference type) { + if (type == null) { + return null; + } + final FormalParameter formalParameter = CheckFactoryImpl.eINSTANCE.createFormalParameter(); + formalParameter.setName(name); + formalParameter.setType(type); + return formalParameter; + } + + public static PropertiesInferenceHelper getHelper() { + return IResourceServiceProvider.Registry.INSTANCE.getResourceServiceProvider(URI.createURI("DUMMY.checkcfg")).get( + PropertiesInferenceHelper.class); + } + +} diff --git a/com.avaloq.tools.ddk.checkcfg.core/src/com/avaloq/tools/ddk/checkcfg/util/PropertiesInferenceHelper.xtend b/com.avaloq.tools.ddk.checkcfg.core/src/com/avaloq/tools/ddk/checkcfg/util/PropertiesInferenceHelper.xtend deleted file mode 100644 index 4ae3fb62a0..0000000000 --- a/com.avaloq.tools.ddk.checkcfg.core/src/com/avaloq/tools/ddk/checkcfg/util/PropertiesInferenceHelper.xtend +++ /dev/null @@ -1,140 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016 Avaloq Group AG and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Avaloq Group AG - initial API and implementation - *******************************************************************************/ - -package com.avaloq.tools.ddk.checkcfg.util - -import com.avaloq.tools.ddk.check.check.FormalParameter -import com.avaloq.tools.ddk.check.check.impl.CheckFactoryImpl -import com.avaloq.tools.ddk.checkcfg.CheckCfgUtil -import com.avaloq.tools.ddk.checkcfg.checkcfg.CheckConfiguration -import com.avaloq.tools.ddk.checkcfg.checkcfg.CheckcfgPackage -import com.avaloq.tools.ddk.checkcfg.checkcfg.ConfigurableSection -import com.avaloq.tools.ddk.checkcfg.checkcfg.ConfiguredParameter -import com.avaloq.tools.ddk.xtext.util.ParseTreeUtil -import com.google.inject.Inject -import org.eclipse.emf.common.util.EList -import org.eclipse.emf.common.util.URI -import org.eclipse.xtext.EcoreUtil2 -import org.eclipse.xtext.common.types.JvmTypeReference -import org.eclipse.xtext.resource.IResourceServiceProvider -import org.eclipse.xtext.xbase.XBooleanLiteral -import org.eclipse.xtext.xbase.XNumberLiteral -import org.eclipse.xtext.xbase.XStringLiteral -import org.eclipse.xtext.xbase.jvmmodel.JvmTypeReferenceBuilder -import com.avaloq.tools.ddk.checkcfg.ICheckCfgPropertySpecification -import org.eclipse.xtext.xbase.XListLiteral - -class PropertiesInferenceHelper { - @Inject JvmTypeReferenceBuilder.Factory typeRefBuilderFactory; - - static val BOOLEAN = "boolean" - static val STRING = "java.lang.String" - static val NUMBER = "int" - static val STRING_LIST = "List" - static val NUMBER_LIST = "List" - static val BOOLEAN_LIST = "List" - - def getProperties(CheckConfiguration checkConfiguration, EList properties) { - val referenceBuilder = typeRefBuilderFactory.create(checkConfiguration.eResource().resourceSet) - - // get all ConfigurableSections - val configurableSections = EcoreUtil2.getAllContentsOfType(checkConfiguration, typeof(ConfigurableSection)) - // the CheckConfiguration itself is a configurable section - configurableSections.add(0, checkConfiguration) - - // infer properties for all sections - for (section : configurableSections) { - val parameters = section.parameterConfigurations; - for (parameter : parameters) { - val formalParameter = parameter.inferFormalParameter(referenceBuilder) - if (formalParameter !== null) { - properties.add(formalParameter) - } - } - } - - // add contributed properties - val contributions = CheckCfgUtil.allPropertyContributions - for (contribution : contributions) { - val formalParameter = contribution.inferFormalParameter(referenceBuilder) - if (formalParameter !== null) { - properties.add(formalParameter) - } - } - properties - } - - def inferType(ICheckCfgPropertySpecification contribution, JvmTypeReferenceBuilder referenceBuilder) { - switch contribution.type { - case ICheckCfgPropertySpecification.PropertyType.BOOLEAN: referenceBuilder.typeRef(BOOLEAN) - case ICheckCfgPropertySpecification.PropertyType.NUMBER: referenceBuilder.typeRef(NUMBER) - case ICheckCfgPropertySpecification.PropertyType.STRING: referenceBuilder.typeRef(STRING) - case ICheckCfgPropertySpecification.PropertyType.NUMBERS: referenceBuilder.typeRef(NUMBER_LIST) - case ICheckCfgPropertySpecification.PropertyType.STRINGS: referenceBuilder.typeRef(STRING_LIST) - case ICheckCfgPropertySpecification.PropertyType.BOOLEANS: referenceBuilder.typeRef(BOOLEAN_LIST) - default: null - } - } - - def inferListType(XListLiteral newValue, JvmTypeReferenceBuilder referenceBuilder) { - if (newValue.elements.size < 1) { - return null - } - switch newValue.elements.get(0) { - XBooleanLiteral: referenceBuilder.typeRef(BOOLEAN_LIST) - XNumberLiteral: referenceBuilder.typeRef(NUMBER_LIST) - XStringLiteral: referenceBuilder.typeRef(STRING_LIST) - default: null - } - } - - def inferType(ConfiguredParameter parameter, JvmTypeReferenceBuilder referenceBuilder) { - val newValue = parameter.newValue - switch newValue { - XBooleanLiteral: referenceBuilder.typeRef(BOOLEAN) - XNumberLiteral: referenceBuilder.typeRef(NUMBER) - XStringLiteral: referenceBuilder.typeRef(STRING) - XListLiteral: inferListType(newValue, referenceBuilder) - default: null - } - } - - def inferFormalParameter(ConfiguredParameter parameter, JvmTypeReferenceBuilder referenceBuilder) { - if (parameter === null) { - return null - } - inferFormalParameter(ParseTreeUtil.getParsedString(parameter, CheckcfgPackage.Literals.CONFIGURED_PARAMETER__PARAMETER), - inferType(parameter, referenceBuilder)) - } - - def inferFormalParameter(ICheckCfgPropertySpecification contribution, JvmTypeReferenceBuilder referenceBuilder) { - if (contribution === null) { - return null - } - inferFormalParameter(contribution.name, inferType(contribution, referenceBuilder)) - } - - def inferFormalParameter(String name, JvmTypeReference type) { - if (type === null) { - return null - } - val formalParameter = CheckFactoryImpl.eINSTANCE.createFormalParameter(); - formalParameter.name = name - formalParameter.type = type - formalParameter - } - - def static getHelper() { - IResourceServiceProvider.Registry.INSTANCE.getResourceServiceProvider(URI.createURI("DUMMY.checkcfg")).get( - typeof(PropertiesInferenceHelper)); - } - -} \ No newline at end of file diff --git a/com.avaloq.tools.ddk.checkcfg.core/src/com/avaloq/tools/ddk/checkcfg/validation/ConfiguredParameterChecks.java b/com.avaloq.tools.ddk.checkcfg.core/src/com/avaloq/tools/ddk/checkcfg/validation/ConfiguredParameterChecks.java new file mode 100644 index 0000000000..00511160d9 --- /dev/null +++ b/com.avaloq.tools.ddk.checkcfg.core/src/com/avaloq/tools/ddk/checkcfg/validation/ConfiguredParameterChecks.java @@ -0,0 +1,81 @@ +/******************************************************************************* + * Copyright (c) 2016 Avaloq Group AG and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Avaloq Group AG - initial API and implementation + *******************************************************************************/ +package com.avaloq.tools.ddk.checkcfg.validation; + +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.Set; + +import org.eclipse.xtext.validation.Check; +import org.eclipse.xtext.xbase.XExpression; +import org.eclipse.xtext.xbase.XListLiteral; +import org.eclipse.xtext.xbase.XStringLiteral; + +import com.avaloq.tools.ddk.check.check.FormalParameter; +import com.avaloq.tools.ddk.check.validation.FormalParameterCheckBase; +import com.avaloq.tools.ddk.checkcfg.CheckCfgUtil; +import com.avaloq.tools.ddk.checkcfg.ICheckCfgPropertySpecification; +import com.avaloq.tools.ddk.checkcfg.checkcfg.ConfiguredParameter; +import com.google.common.collect.Sets; + +/** + * Checkcfg formal parameter checks. + */ +@SuppressWarnings("nls") +public class ConfiguredParameterChecks extends FormalParameterCheckBase { + + private static final Map> ALLOWED_PROPERTY_VALUES = new HashMap<>(); + + /** + * Verifies that numeric literals in the default values of formal parameters are all integral values. + * @param parameter to check. + */ + @Check + public void checkFormalParameterNumbersAreIntegers(final ConfiguredParameter parameter) { + checkRightHandSideHasOnlyIntegralNumbers(parameter.getNewValue(), IssueCodes.FORMAL_PARAMETER_MUST_BE_INTEGER); + } + + /** + * Verifies that formal parameters defined via extension point only set values expected by the extension. + * @param parameter to check. + */ + @Check + public void checkFormalParameterValuesAreValid(final ConfiguredParameter parameter) { + final FormalParameter formalParameter = parameter.getParameter(); + final String name = formalParameter != null ? formalParameter.getName() : null; + final String propertyName = name != null ? name.toLowerCase(Locale.ENGLISH) : null; + if (propertyName != null) { + Set permitted = ALLOWED_PROPERTY_VALUES.get(propertyName); + if (permitted == null) { + final ICheckCfgPropertySpecification propertySpecification = CheckCfgUtil.getPropertySpecification(propertyName); + String[] expected = propertySpecification != null ? propertySpecification.getExpectedValues() : null; + if (expected == null) { + expected = new String[0]; + } + permitted = Sets.newHashSet(expected); + ALLOWED_PROPERTY_VALUES.put(propertyName, permitted); + } + final XExpression value = parameter.getNewValue(); + if (!permitted.isEmpty() && value != null) { + final List expressions = value instanceof XListLiteral xListLiteral ? xListLiteral.getElements() + : Collections.singletonList(value); + for (final XExpression expression : expressions) { + if (!(expression instanceof XStringLiteral) || !permitted.contains(((XStringLiteral) expression).getValue().toLowerCase(Locale.ENGLISH))) { + error("Not a meaningful value for %s".formatted(propertyName), expression, null, IssueCodes.PARAMETER_VALUE_NOT_ALLOWED); + } + } + } + } + } +} diff --git a/com.avaloq.tools.ddk.checkcfg.core/src/com/avaloq/tools/ddk/checkcfg/validation/ConfiguredParameterChecks.xtend b/com.avaloq.tools.ddk.checkcfg.core/src/com/avaloq/tools/ddk/checkcfg/validation/ConfiguredParameterChecks.xtend deleted file mode 100644 index d037bd1349..0000000000 --- a/com.avaloq.tools.ddk.checkcfg.core/src/com/avaloq/tools/ddk/checkcfg/validation/ConfiguredParameterChecks.xtend +++ /dev/null @@ -1,66 +0,0 @@ -/** - * Copyright (c) 2016 Avaloq Group AG and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * Contributors: - * Avaloq Group AG - initial API and implementation - */ -package com.avaloq.tools.ddk.checkcfg.validation - -import com.avaloq.tools.ddk.check.validation.FormalParameterCheckBase -import com.avaloq.tools.ddk.checkcfg.CheckCfgUtil -import com.avaloq.tools.ddk.checkcfg.checkcfg.ConfiguredParameter -import com.google.common.collect.Maps -import com.google.common.collect.Sets -import java.util.Collections -import java.util.Locale -import java.util.Map -import java.util.Set -import org.eclipse.xtext.validation.Check -import org.eclipse.xtext.xbase.XListLiteral -import org.eclipse.xtext.xbase.XStringLiteral - -/** - * Checkcfg formal parameter checks. - */ -class ConfiguredParameterChecks extends FormalParameterCheckBase { - static Map> allowedPropertyValues = Maps.newHashMap() - - /** - * Verifies that numeric literals in the default values of formal parameters are all integral values. - * @param parameterto check. - */ - @Check - def checkFormalParameterNumbersAreIntegers(ConfiguredParameter parameter) { - checkRightHandSideHasOnlyIntegralNumbers(parameter.getNewValue(), IssueCodes.FORMAL_PARAMETER_MUST_BE_INTEGER) - } - - /** - * Verifies that formal parameters defined via extension point only set values expected by the extension. - * @param parameter to check. - */ - @Check - def checkFormalParameterValuesAreValid(ConfiguredParameter parameter) { - val propertyName = parameter.parameter?.name?.toLowerCase(Locale.ENGLISH) - if (propertyName !== null) { - var permitted = allowedPropertyValues.get(propertyName) - if (permitted === null) { - val expected = CheckCfgUtil.getPropertySpecification(propertyName)?.expectedValues ?: newArrayOfSize(0) - permitted = Sets.newHashSet(expected) - allowedPropertyValues.put(propertyName, permitted) - } - val value = parameter.newValue - if (!permitted.isNullOrEmpty && value !== null) { - val expressions = if (value instanceof XListLiteral) value.elements else Collections.singletonList(value) - for (expression : expressions) { - if (!(expression instanceof XStringLiteral) || !permitted.contains((expression as XStringLiteral).value.toLowerCase(Locale.ENGLISH))) { - error('''Not a meaningful value for «propertyName»''', expression, null, IssueCodes.PARAMETER_VALUE_NOT_ALLOWED) - } - } - } - } - } - -} diff --git a/com.avaloq.tools.ddk.checkcfg.core/xtend-gen/.gitignore b/com.avaloq.tools.ddk.checkcfg.core/xtend-gen/.gitignore deleted file mode 100644 index e69de29bb2..0000000000 From 6988cd545a11957ae3a8eacae5145c479d225c92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Dinis=20Ferreira?= Date: Thu, 11 Jun 2026 15:02:59 +0100 Subject: [PATCH 2/3] refactor: migrate Xtend to Java - com.avaloq.tools.ddk.checkcfg.core.test --- .../.classpath | 5 - .../.project | 6 - .../META-INF/MANIFEST.MF | 1 - .../build.properties | 3 +- .../CheckCfgContentAssistTest.java | 82 ++++++++++++++ .../CheckCfgContentAssistTest.xtend | 84 -------------- .../scoping/CheckCfgScopeProviderTest.java | 88 +++++++++++++++ .../scoping/CheckCfgScopeProviderTest.xtend | 77 ------------- .../checkcfg/syntax/CheckCfgSyntaxTest.java | 105 ++++++++++++++++++ .../checkcfg/syntax/CheckCfgSyntaxTest.xtend | 99 ----------------- ...ModelUtil.xtend => CheckCfgModelUtil.java} | 28 ++--- .../ddk/checkcfg/util/CheckCfgTestUtil.java | 37 ++++++ .../ddk/checkcfg/util/CheckCfgTestUtil.xtend | 32 ------ ...CfgConfiguredParameterValidationsTest.java | 72 ++++++++++++ ...fgConfiguredParameterValidationsTest.xtend | 63 ----------- .../ddk/checkcfg/validation/CheckCfgTest.java | 61 ++++++++++ .../checkcfg/validation/CheckCfgTest.xtend | 63 ----------- .../xtend-gen/.gitignore | 0 18 files changed, 458 insertions(+), 448 deletions(-) create mode 100644 com.avaloq.tools.ddk.checkcfg.core.test/src/com/avaloq/tools/ddk/checkcfg/contentassist/CheckCfgContentAssistTest.java delete mode 100644 com.avaloq.tools.ddk.checkcfg.core.test/src/com/avaloq/tools/ddk/checkcfg/contentassist/CheckCfgContentAssistTest.xtend create mode 100644 com.avaloq.tools.ddk.checkcfg.core.test/src/com/avaloq/tools/ddk/checkcfg/scoping/CheckCfgScopeProviderTest.java delete mode 100644 com.avaloq.tools.ddk.checkcfg.core.test/src/com/avaloq/tools/ddk/checkcfg/scoping/CheckCfgScopeProviderTest.xtend create mode 100644 com.avaloq.tools.ddk.checkcfg.core.test/src/com/avaloq/tools/ddk/checkcfg/syntax/CheckCfgSyntaxTest.java delete mode 100644 com.avaloq.tools.ddk.checkcfg.core.test/src/com/avaloq/tools/ddk/checkcfg/syntax/CheckCfgSyntaxTest.xtend rename com.avaloq.tools.ddk.checkcfg.core.test/src/com/avaloq/tools/ddk/checkcfg/util/{CheckCfgModelUtil.xtend => CheckCfgModelUtil.java} (57%) create mode 100644 com.avaloq.tools.ddk.checkcfg.core.test/src/com/avaloq/tools/ddk/checkcfg/util/CheckCfgTestUtil.java delete mode 100644 com.avaloq.tools.ddk.checkcfg.core.test/src/com/avaloq/tools/ddk/checkcfg/util/CheckCfgTestUtil.xtend create mode 100644 com.avaloq.tools.ddk.checkcfg.core.test/src/com/avaloq/tools/ddk/checkcfg/validation/CheckCfgConfiguredParameterValidationsTest.java delete mode 100644 com.avaloq.tools.ddk.checkcfg.core.test/src/com/avaloq/tools/ddk/checkcfg/validation/CheckCfgConfiguredParameterValidationsTest.xtend create mode 100644 com.avaloq.tools.ddk.checkcfg.core.test/src/com/avaloq/tools/ddk/checkcfg/validation/CheckCfgTest.java delete mode 100644 com.avaloq.tools.ddk.checkcfg.core.test/src/com/avaloq/tools/ddk/checkcfg/validation/CheckCfgTest.xtend delete mode 100644 com.avaloq.tools.ddk.checkcfg.core.test/xtend-gen/.gitignore diff --git a/com.avaloq.tools.ddk.checkcfg.core.test/.classpath b/com.avaloq.tools.ddk.checkcfg.core.test/.classpath index 75e880803d..97bf0dc637 100644 --- a/com.avaloq.tools.ddk.checkcfg.core.test/.classpath +++ b/com.avaloq.tools.ddk.checkcfg.core.test/.classpath @@ -1,11 +1,6 @@ - - - - - diff --git a/com.avaloq.tools.ddk.checkcfg.core.test/.project b/com.avaloq.tools.ddk.checkcfg.core.test/.project index a933d1a336..b335bfe7d5 100644 --- a/com.avaloq.tools.ddk.checkcfg.core.test/.project +++ b/com.avaloq.tools.ddk.checkcfg.core.test/.project @@ -20,11 +20,6 @@ - - org.eclipse.xtext.ui.shared.xtextBuilder - - - net.sf.eclipsecs.core.CheckstyleBuilder @@ -44,7 +39,6 @@ org.eclipse.jdt.core.javanature org.eclipse.pde.PluginNature - org.eclipse.xtext.ui.shared.xtextNature net.sourceforge.pmd.eclipse.plugin.pmdNature net.sf.eclipsecs.core.CheckstyleNature edu.umd.cs.findbugs.plugin.eclipse.findbugsNature diff --git a/com.avaloq.tools.ddk.checkcfg.core.test/META-INF/MANIFEST.MF b/com.avaloq.tools.ddk.checkcfg.core.test/META-INF/MANIFEST.MF index 690bd6a78e..de08269cf3 100644 --- a/com.avaloq.tools.ddk.checkcfg.core.test/META-INF/MANIFEST.MF +++ b/com.avaloq.tools.ddk.checkcfg.core.test/META-INF/MANIFEST.MF @@ -16,7 +16,6 @@ Require-Bundle: com.avaloq.tools.ddk.test.core, org.eclipse.ui, org.eclipse.ui.ide, org.eclipse.core.runtime, - org.eclipse.xtend.lib, org.eclipse.xtext.ui.testing, org.eclipse.xtext.xbase.lib, org.eclipse.ui.workbench;resolution:=optional, diff --git a/com.avaloq.tools.ddk.checkcfg.core.test/build.properties b/com.avaloq.tools.ddk.checkcfg.core.test/build.properties index d8e2f0e92e..34d2e4d2da 100644 --- a/com.avaloq.tools.ddk.checkcfg.core.test/build.properties +++ b/com.avaloq.tools.ddk.checkcfg.core.test/build.properties @@ -1,5 +1,4 @@ -source.. = src/,\ - xtend-gen/ +source.. = src/ output.. = bin/ bin.includes = META-INF/,\ . diff --git a/com.avaloq.tools.ddk.checkcfg.core.test/src/com/avaloq/tools/ddk/checkcfg/contentassist/CheckCfgContentAssistTest.java b/com.avaloq.tools.ddk.checkcfg.core.test/src/com/avaloq/tools/ddk/checkcfg/contentassist/CheckCfgContentAssistTest.java new file mode 100644 index 0000000000..54b19545d0 --- /dev/null +++ b/com.avaloq.tools.ddk.checkcfg.core.test/src/com/avaloq/tools/ddk/checkcfg/contentassist/CheckCfgContentAssistTest.java @@ -0,0 +1,82 @@ +/******************************************************************************* + * Copyright (c) 2016 Avaloq Group AG and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Avaloq Group AG - initial API and implementation + *******************************************************************************/ + +package com.avaloq.tools.ddk.checkcfg.contentassist; + +import static com.avaloq.tools.ddk.checkcfg.CheckCfgConstants.PROPERTY_EXECUTABLE_EXTENSION_ATTRIBUTE; +import static com.avaloq.tools.ddk.checkcfg.CheckCfgConstants.PROPERTY_EXTENSION_POINT; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.xtext.testing.InjectWith; +import org.eclipse.xtext.testing.extensions.InjectionExtension; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import com.avaloq.tools.ddk.checkcfg.CheckCfgUiInjectorProvider; +import com.avaloq.tools.ddk.checkcfg.util.CheckCfgTestUtil; +import com.avaloq.tools.ddk.test.checkcfg.TestPropertySpecificationWithExpectedValues; +import com.avaloq.tools.ddk.test.checkcfg.TestPropertySpecificationWithOutExpectedValues; +import com.avaloq.tools.ddk.test.core.jupiter.BugTest; +import com.avaloq.tools.ddk.test.core.mock.ExtensionRegistryMock; +import com.avaloq.tools.ddk.xtext.test.jupiter.AbstractAcfContentAssistTest; +import com.avaloq.tools.ddk.xtext.test.jupiter.AbstractXtextTestUtil; + +@ExtendWith(InjectionExtension.class) +@InjectWith(CheckCfgUiInjectorProvider.class) +public class CheckCfgContentAssistTest extends AbstractAcfContentAssistTest { + + private static final String SOURCE_TEMPLATE = """ + check configuration Test { + catalog TestChecks { + default Test ( + %s = %s"banana" + ) + } + } + """; + + @Override + protected AbstractXtextTestUtil getXtextTestUtil() { + return CheckCfgTestUtil.getInstance(); + } + + @Override + protected List getRequiredSourceFileNames() { + return new ArrayList(0); + } + + @Override + protected void beforeAllTests() { + ExtensionRegistryMock.mockExecutableExtension(ExtensionRegistryMock.mockConfigurationElement(PROPERTY_EXTENSION_POINT), PROPERTY_EXECUTABLE_EXTENSION_ATTRIBUTE, TestPropertySpecificationWithExpectedValues.INSTANCE); + ExtensionRegistryMock.mockExecutableExtension(ExtensionRegistryMock.mockConfigurationElement(PROPERTY_EXTENSION_POINT), PROPERTY_EXECUTABLE_EXTENSION_ATTRIBUTE, TestPropertySpecificationWithOutExpectedValues.INSTANCE); + super.beforeAllTests(); + } + + @Override + protected void afterAllTests() { + super.afterAllTests(); + ExtensionRegistryMock.unMock(PROPERTY_EXTENSION_POINT); + } + + @Test + public void testConfiguredParameterProposals() { + final String source = SOURCE_TEMPLATE.formatted(TestPropertySpecificationWithExpectedValues.INSTANCE.getName(), expected(TestPropertySpecificationWithExpectedValues.INSTANCE.getExpectedValues())); + assertKernelSourceProposals("ConfiguredParameterProposals.checkcfg", source); + } + + @BugTest(value = "DSL-1811", unresolved = true) + public void testNoTypeMismatchedParameterValueProposals() { + final String source = SOURCE_TEMPLATE.formatted(TestPropertySpecificationWithExpectedValues.INSTANCE.getName(), expectedExactly(TestPropertySpecificationWithExpectedValues.INSTANCE.getExpectedValues())); + assertKernelSourceProposals("NoTypeMismatchedParameterValueProposals.checkcfg", source); + } +} diff --git a/com.avaloq.tools.ddk.checkcfg.core.test/src/com/avaloq/tools/ddk/checkcfg/contentassist/CheckCfgContentAssistTest.xtend b/com.avaloq.tools.ddk.checkcfg.core.test/src/com/avaloq/tools/ddk/checkcfg/contentassist/CheckCfgContentAssistTest.xtend deleted file mode 100644 index fbbe5de591..0000000000 --- a/com.avaloq.tools.ddk.checkcfg.core.test/src/com/avaloq/tools/ddk/checkcfg/contentassist/CheckCfgContentAssistTest.xtend +++ /dev/null @@ -1,84 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016 Avaloq Group AG and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Avaloq Group AG - initial API and implementation - *******************************************************************************/ - -package com.avaloq.tools.ddk.checkcfg.contentassist - -import com.avaloq.tools.ddk.test.checkcfg.TestPropertySpecificationWithExpectedValues -import com.avaloq.tools.ddk.test.checkcfg.TestPropertySpecificationWithOutExpectedValues -import com.google.common.collect.Lists - -import static com.avaloq.tools.ddk.checkcfg.CheckCfgConstants.PROPERTY_EXECUTABLE_EXTENSION_ATTRIBUTE -import static com.avaloq.tools.ddk.checkcfg.CheckCfgConstants.PROPERTY_EXTENSION_POINT - -import static extension com.avaloq.tools.ddk.test.core.mock.ExtensionRegistryMock.mockConfigurationElement -import static extension com.avaloq.tools.ddk.test.core.mock.ExtensionRegistryMock.mockExecutableExtension -import static extension com.avaloq.tools.ddk.test.core.mock.ExtensionRegistryMock.unMock -import com.avaloq.tools.ddk.test.core.jupiter.BugTest -import com.avaloq.tools.ddk.xtext.test.jupiter.AbstractAcfContentAssistTest -import org.junit.jupiter.api.Test -import com.avaloq.tools.ddk.checkcfg.util.CheckCfgTestUtil -import org.junit.jupiter.api.^extension.ExtendWith -import org.eclipse.xtext.testing.extensions.InjectionExtension -import com.avaloq.tools.ddk.checkcfg.CheckCfgUiInjectorProvider -import org.eclipse.xtext.testing.InjectWith - -@ExtendWith(InjectionExtension) -@InjectWith(CheckCfgUiInjectorProvider) -class CheckCfgContentAssistTest extends AbstractAcfContentAssistTest { - - override protected getXtextTestUtil() { - return CheckCfgTestUtil.instance - } - - override protected getRequiredSourceFileNames() { - Lists.newArrayListWithCapacity(0) - } - - override protected beforeAllTests() { - PROPERTY_EXTENSION_POINT.mockConfigurationElement.mockExecutableExtension(PROPERTY_EXECUTABLE_EXTENSION_ATTRIBUTE, TestPropertySpecificationWithExpectedValues.INSTANCE) - PROPERTY_EXTENSION_POINT.mockConfigurationElement.mockExecutableExtension(PROPERTY_EXECUTABLE_EXTENSION_ATTRIBUTE, TestPropertySpecificationWithOutExpectedValues.INSTANCE) - super.beforeAllTests() - } - - override protected afterAllTests() { - super.afterAllTests() - PROPERTY_EXTENSION_POINT.unMock - } - - @Test - def testConfiguredParameterProposals() { - assertKernelSourceProposals("ConfiguredParameterProposals.checkcfg", ''' - check configuration Test { - catalog TestChecks { - default Test ( - «TestPropertySpecificationWithExpectedValues.INSTANCE.name» = «expected(TestPropertySpecificationWithExpectedValues.INSTANCE.expectedValues)»"banana" - ) - } - } - ''') - } - - @BugTest(value="DSL-1811", unresolved=true) - def testNoTypeMismatchedParameterValueProposals() { - assertKernelSourceProposals("NoTypeMismatchedParameterValueProposals.checkcfg", ''' - check configuration Test { - catalog TestChecks { - default Test ( - «TestPropertySpecificationWithExpectedValues.INSTANCE.name» = «expectedExactly(TestPropertySpecificationWithExpectedValues.INSTANCE.expectedValues)»"banana" - ) - } - } - ''') - } - - - -} diff --git a/com.avaloq.tools.ddk.checkcfg.core.test/src/com/avaloq/tools/ddk/checkcfg/scoping/CheckCfgScopeProviderTest.java b/com.avaloq.tools.ddk.checkcfg.core.test/src/com/avaloq/tools/ddk/checkcfg/scoping/CheckCfgScopeProviderTest.java new file mode 100644 index 0000000000..3b8ceca6e1 --- /dev/null +++ b/com.avaloq.tools.ddk.checkcfg.core.test/src/com/avaloq/tools/ddk/checkcfg/scoping/CheckCfgScopeProviderTest.java @@ -0,0 +1,88 @@ +/******************************************************************************* + * Copyright (c) 2016 Avaloq Group AG and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Avaloq Group AG - initial API and implementation + *******************************************************************************/ + +package com.avaloq.tools.ddk.checkcfg.scoping; + +import static org.junit.jupiter.api.Assertions.assertArrayEquals; + +import java.util.List; + +import org.eclipse.emf.ecore.EObject; +import org.eclipse.xtext.resource.IEObjectDescription; +import org.eclipse.xtext.scoping.IScopeProvider; + +import com.avaloq.tools.ddk.checkcfg.checkcfg.CheckcfgPackage; +import com.avaloq.tools.ddk.checkcfg.util.CheckCfgTestUtil; +import com.avaloq.tools.ddk.test.core.jupiter.BugTest; +import com.avaloq.tools.ddk.xtext.test.jupiter.AbstractScopingTest; +import com.avaloq.tools.ddk.xtext.test.jupiter.AbstractXtextTestUtil; + +public final class CheckCfgScopeProviderTest extends AbstractScopingTest { + + private final IScopeProvider scopeProvider = getScopeProvider(); + + /** {@inheritDoc} */ + @Override + protected AbstractXtextTestUtil getXtextTestUtil() { + return CheckCfgTestUtil.getInstance(); + } + + /** {@inheritDoc} */ + @Override + protected void registerRequiredSources() { + } + + /** + * Regression test for DSL-1498 Incorrect Catalog Name inserted by Content Assist + *

+ * All catalogs supplied to Context Assist should be in the correct fully-qualified package. + *

+ */ + @BugTest(value = "DSL-1498") + public void testCatalogsAreInCorrectPackage() { + + // ARRANGE + + final List expPackageNamePrefix = List.of("com", "avaloq", "tools", "ddk"); + + // Define test data + final int cursorPos = getTag(); + final String sourceContent = """ + check configuration testCheckCfg { + %s + } + """.formatted(mark(cursorPos)); + + // Register a check configuration source, and get a context model + registerModel(getTestSourceFileName(), sourceContent); + final EObject context = getMarkerTagsInfo().getModel(cursorPos); + if (null == context) { + throw new IllegalStateException("Got null context model"); + } + + // ACT + + // Get catalogs + final Iterable elements = scopeProvider.getScope(context, CheckcfgPackage.Literals.CONFIGURED_CATALOG__CATALOG).getAllElements(); + if (!elements.iterator().hasNext()) { + throw new IllegalStateException("Scope has no elements"); + } + + // ASSERT + + elements.forEach((IEObjectDescription element) -> { + // Check catalog has the correct fully-qualified package name + final List actualName = element.getName().getSegments(); + final Object[] actualPackageName = actualName.stream().limit(expPackageNamePrefix.size()).toArray(); + assertArrayEquals(expPackageNamePrefix.toArray(), actualPackageName, "Catalog must have the correct fully-qualified package name"); + }); + } +} diff --git a/com.avaloq.tools.ddk.checkcfg.core.test/src/com/avaloq/tools/ddk/checkcfg/scoping/CheckCfgScopeProviderTest.xtend b/com.avaloq.tools.ddk.checkcfg.core.test/src/com/avaloq/tools/ddk/checkcfg/scoping/CheckCfgScopeProviderTest.xtend deleted file mode 100644 index 9a373583d3..0000000000 --- a/com.avaloq.tools.ddk.checkcfg.core.test/src/com/avaloq/tools/ddk/checkcfg/scoping/CheckCfgScopeProviderTest.xtend +++ /dev/null @@ -1,77 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016 Avaloq Group AG and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Avaloq Group AG - initial API and implementation - *******************************************************************************/ - -package com.avaloq.tools.ddk.checkcfg.scoping - -import com.avaloq.tools.ddk.test.core.jupiter.BugTest -import com.avaloq.tools.ddk.checkcfg.checkcfg.CheckcfgPackage -import com.avaloq.tools.ddk.checkcfg.util.CheckCfgTestUtil -import com.avaloq.tools.ddk.xtext.test.jupiter.AbstractScopingTest -import static org.junit.jupiter.api.Assertions.assertArrayEquals - -final class CheckCfgScopeProviderTest extends AbstractScopingTest { - - val scopeProvider = getScopeProvider(); - - /** {@inheritDoc} */ - override protected getXtextTestUtil() { - return CheckCfgTestUtil.getInstance; - } - - /** {@inheritDoc} */ - override protected registerRequiredSources() {} - - /** - * Regression test for DSL-1498 Incorrect Catalog Name inserted by Content Assist - *

- * All catalogs supplied to Context Assist should be in the correct fully-qualified package. - *

- */ - @BugTest(value="DSL-1498") - def testCatalogsAreInCorrectPackage() { - - // ARRANGE - - val EXP_PACKAGE_NAME_PREFIX = #["com", "avaloq", "tools", "ddk"]; - - // Define test data - val CURSOR_POS = getTag; - val SOURCE_CONTENT = ''' - check configuration testCheckCfg { - «mark(CURSOR_POS)» - } - '''; - - // Register a check configuration source, and get a context model - registerModel(getTestSourceFileName, SOURCE_CONTENT); - val context = getMarkerTagsInfo().getModel(CURSOR_POS); - if (null === context) { - throw new NullPointerException("Got null context model"); - } - - // ACT - - // Get catalogs - val elements = scopeProvider.getScope(context, CheckcfgPackage.Literals.CONFIGURED_CATALOG__CATALOG).getAllElements; - if (elements.empty) { - throw new Exception("Scope has no elements"); - } - - // ASSERT - - elements.forEach[element | - // Check catalog has the correct fully-qualified package name - val actualName = element.name.segments; - val actualPackageName = actualName.take(EXP_PACKAGE_NAME_PREFIX.size); - assertArrayEquals(EXP_PACKAGE_NAME_PREFIX, actualPackageName, "Catalog must have the correct fully-qualified package name"); - ] - } -} diff --git a/com.avaloq.tools.ddk.checkcfg.core.test/src/com/avaloq/tools/ddk/checkcfg/syntax/CheckCfgSyntaxTest.java b/com.avaloq.tools.ddk.checkcfg.core.test/src/com/avaloq/tools/ddk/checkcfg/syntax/CheckCfgSyntaxTest.java new file mode 100644 index 0000000000..55deec23ff --- /dev/null +++ b/com.avaloq.tools.ddk.checkcfg.core.test/src/com/avaloq/tools/ddk/checkcfg/syntax/CheckCfgSyntaxTest.java @@ -0,0 +1,105 @@ +/******************************************************************************* + * Copyright (c) 2016 Avaloq Group AG and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Avaloq Group AG - initial API and implementation + *******************************************************************************/ + +package com.avaloq.tools.ddk.checkcfg.syntax; + +import java.util.LinkedList; +import java.util.List; + +import org.eclipse.xtext.ui.testing.util.IResourcesSetupUtil; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +import com.avaloq.tools.ddk.checkcfg.util.CheckCfgTestUtil; +import com.avaloq.tools.ddk.xtext.test.jupiter.AbstractValidationTest; +import com.avaloq.tools.ddk.xtext.test.jupiter.AbstractXtextTestUtil; + +public class CheckCfgSyntaxTest extends AbstractValidationTest { + + private static final String CHECKCFG_SOURCE_FILE_NAME = "checkconfiguration.checkcfg"; + + @Override + protected AbstractXtextTestUtil getXtextTestUtil() { + return CheckCfgTestUtil.getInstance(); + } + + @Override + protected List getRequiredSourceFileNames() { + return new LinkedList(); + } + + @BeforeAll + public void setup() { + final String checkSource = """ + package checkcfgtest + + import com.avaloq.tools.ddk.check.check.Check + + catalog CheckCfgTestChecks + for grammar com.avaloq.tools.ddk.check.Check { + /** + * Test Error Documentation + */ + live error TestError "Test Error" + message "Test Error message." { + for Check c { + issue on c#name; + } + } + } + """; + addCustomerSourceToWorkspace("customer$sca_testchecks.check", checkSource); + IResourcesSetupUtil.waitForBuild(); + } + + @Test + public void testSyntax() { + final String checkcfgSource = """ + check configuration checkconfiguration { + catalog checkcfgtest.CheckCfgTestChecks { + default TestError + } + } + """; + validateCustomerSourceStrictly(CHECKCFG_SOURCE_FILE_NAME, checkcfgSource); + } + + @Test + public void testSyntaxConfiguredLanguage() { + final String checkcfgSource = """ + check configuration checkconfiguration + for com.avaloq.tools.ddk.^check.TestLanguage { + catalog checkcfgtest.CheckCfgTestChecks { + default TestError + } + } + """; + validateCustomerSourceStrictly(CHECKCFG_SOURCE_FILE_NAME, checkcfgSource); + } + + @Test + public void testPropertiesOnAllLevels() { + final String checkcfgSource = """ + check configuration checkconfiguration + integrationRelevant = true + testBooleanList = #[true, false, false] + + for com.avaloq.tools.ddk.^check.TestLanguage { + nameOverrides = #['altName1', 'altName2'] + + catalog checkcfgtest.CheckCfgTestChecks { + default TestError(testNumber = 3, testNumberList = #[1, 2, 3]) + } + } + """; + validateCustomerSourceStrictly(CHECKCFG_SOURCE_FILE_NAME, checkcfgSource); + } +} diff --git a/com.avaloq.tools.ddk.checkcfg.core.test/src/com/avaloq/tools/ddk/checkcfg/syntax/CheckCfgSyntaxTest.xtend b/com.avaloq.tools.ddk.checkcfg.core.test/src/com/avaloq/tools/ddk/checkcfg/syntax/CheckCfgSyntaxTest.xtend deleted file mode 100644 index ac539b135e..0000000000 --- a/com.avaloq.tools.ddk.checkcfg.core.test/src/com/avaloq/tools/ddk/checkcfg/syntax/CheckCfgSyntaxTest.xtend +++ /dev/null @@ -1,99 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016 Avaloq Group AG and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Avaloq Group AG - initial API and implementation - *******************************************************************************/ - -package com.avaloq.tools.ddk.checkcfg.syntax - -import com.avaloq.tools.ddk.checkcfg.util.CheckCfgTestUtil -import com.avaloq.tools.ddk.xtext.test.jupiter.AbstractValidationTest -import java.util.LinkedList -import org.eclipse.xtext.ui.testing.util.IResourcesSetupUtil -import org.junit.jupiter.api.Test -import org.junit.jupiter.api.BeforeAll - -class CheckCfgSyntaxTest extends AbstractValidationTest { - - override protected getXtextTestUtil() { - CheckCfgTestUtil.instance - } - - override protected getRequiredSourceFileNames() { - new LinkedList - } - - @BeforeAll - def void setup() { - val checkSource = ''' - package checkcfgtest - - import com.avaloq.tools.ddk.check.check.Check - - catalog CheckCfgTestChecks - for grammar com.avaloq.tools.ddk.check.Check { - /** - * Test Error Documentation - */ - live error TestError "Test Error" - message "Test Error message." { - for Check c { - issue on c#name; - } - } - } - ''' - addCustomerSourceToWorkspace("customer$sca_testchecks.check", checkSource) - IResourcesSetupUtil.waitForBuild - } - - - @Test - def void testSyntax() { - val checkcfgSource = ''' - check configuration checkconfiguration { - catalog checkcfgtest.CheckCfgTestChecks { - default TestError - } - } - ''' - validateCustomerSourceStrictly("checkconfiguration.checkcfg", checkcfgSource) - - } - - @Test - def void testSyntaxConfiguredLanguage() { - val checkcfgSource = ''' - check configuration checkconfiguration - for com.avaloq.tools.ddk.^check.TestLanguage { - catalog checkcfgtest.CheckCfgTestChecks { - default TestError - } - } - ''' - validateCustomerSourceStrictly("checkconfiguration.checkcfg", checkcfgSource) -} - - @Test - def void testPropertiesOnAllLevels() { - val checkcfgSource = ''' - check configuration checkconfiguration - integrationRelevant = true - testBooleanList = #[true, false, false] - - for com.avaloq.tools.ddk.^check.TestLanguage { - nameOverrides = #['altName1', 'altName2'] - - catalog checkcfgtest.CheckCfgTestChecks { - default TestError(testNumber = 3, testNumberList = #[1, 2, 3]) - } - } - ''' - validateCustomerSourceStrictly("checkconfiguration.checkcfg", checkcfgSource) - } -} diff --git a/com.avaloq.tools.ddk.checkcfg.core.test/src/com/avaloq/tools/ddk/checkcfg/util/CheckCfgModelUtil.xtend b/com.avaloq.tools.ddk.checkcfg.core.test/src/com/avaloq/tools/ddk/checkcfg/util/CheckCfgModelUtil.java similarity index 57% rename from com.avaloq.tools.ddk.checkcfg.core.test/src/com/avaloq/tools/ddk/checkcfg/util/CheckCfgModelUtil.xtend rename to com.avaloq.tools.ddk.checkcfg.core.test/src/com/avaloq/tools/ddk/checkcfg/util/CheckCfgModelUtil.java index 7eb2eecaa0..22d63ddf57 100644 --- a/com.avaloq.tools.ddk.checkcfg.core.test/src/com/avaloq/tools/ddk/checkcfg/util/CheckCfgModelUtil.xtend +++ b/com.avaloq.tools.ddk.checkcfg.core.test/src/com/avaloq/tools/ddk/checkcfg/util/CheckCfgModelUtil.java @@ -8,35 +8,31 @@ * Contributors: * Avaloq Group AG - initial API and implementation *******************************************************************************/ -package com.avaloq.tools.ddk.checkcfg.util +package com.avaloq.tools.ddk.checkcfg.util; /* * Provides utility operations for Check Configuration model stubs. Only partial models * are returned as strings. */ -class CheckCfgModelUtil { +public class CheckCfgModelUtil { - def String basicModel(String name) {''' - check configuration «name» {'''.toString + public String basicModel(final String name) { + return "check configuration " + name + " {"; } - def String basicModel() { - basicModel("testing") + public String basicModel() { + return basicModel("testing"); } - def String basicModelWithCatalog() { - basicModel + ''' - catalog Sample {'''.toString + public String basicModelWithCatalog() { + return basicModel() + "catalog Sample {"; } - def String basicModelWithTest() { - basicModelWithCatalog + ''' - Test'''.toString + public String basicModelWithTest() { + return basicModelWithCatalog() + "Test"; } - def String basicModelWithDisabledTest() { - basicModelWithCatalog + ''' - ignore Test'''.toString + public String basicModelWithDisabledTest() { + return basicModelWithCatalog() + "ignore Test"; } - } diff --git a/com.avaloq.tools.ddk.checkcfg.core.test/src/com/avaloq/tools/ddk/checkcfg/util/CheckCfgTestUtil.java b/com.avaloq.tools.ddk.checkcfg.core.test/src/com/avaloq/tools/ddk/checkcfg/util/CheckCfgTestUtil.java new file mode 100644 index 0000000000..e790f933bc --- /dev/null +++ b/com.avaloq.tools.ddk.checkcfg.core.test/src/com/avaloq/tools/ddk/checkcfg/util/CheckCfgTestUtil.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * Copyright (c) 2016 Avaloq Group AG and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Avaloq Group AG - initial API and implementation + *******************************************************************************/ + +package com.avaloq.tools.ddk.checkcfg.util; + +import com.avaloq.tools.ddk.checkcfg.ui.internal.CheckcfgActivator; +import com.avaloq.tools.ddk.xtext.test.ITestProjectManager; +import com.avaloq.tools.ddk.xtext.test.PluginTestProjectManager; +import com.avaloq.tools.ddk.xtext.test.jupiter.AbstractXtextTestUtil; +import com.google.inject.Injector; + +public class CheckCfgTestUtil extends AbstractXtextTestUtil { + + private static final AbstractXtextTestUtil UTIL_INSTANCE = new CheckCfgTestUtil(); + + public static AbstractXtextTestUtil getInstance() { + return UTIL_INSTANCE; + } + + @Override + protected Injector getInjector() { + return CheckcfgActivator.getInstance().getInjector(CheckcfgActivator.COM_AVALOQ_TOOLS_DDK_CHECKCFG_CHECKCFG); + } + + @Override + protected ITestProjectManager createTestProjectManager() { + return new PluginTestProjectManager(getInjector()); + } +} diff --git a/com.avaloq.tools.ddk.checkcfg.core.test/src/com/avaloq/tools/ddk/checkcfg/util/CheckCfgTestUtil.xtend b/com.avaloq.tools.ddk.checkcfg.core.test/src/com/avaloq/tools/ddk/checkcfg/util/CheckCfgTestUtil.xtend deleted file mode 100644 index fe4a7562f8..0000000000 --- a/com.avaloq.tools.ddk.checkcfg.core.test/src/com/avaloq/tools/ddk/checkcfg/util/CheckCfgTestUtil.xtend +++ /dev/null @@ -1,32 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016 Avaloq Group AG and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Avaloq Group AG - initial API and implementation - *******************************************************************************/ - -package com.avaloq.tools.ddk.checkcfg.util - -import com.avaloq.tools.ddk.xtext.test.PluginTestProjectManager -import com.avaloq.tools.ddk.xtext.test.ITestProjectManager -import com.avaloq.tools.ddk.checkcfg.ui.internal.CheckcfgActivator -import com.avaloq.tools.ddk.xtext.test.jupiter.AbstractXtextTestUtil - -class CheckCfgTestUtil extends AbstractXtextTestUtil{ - - - static AbstractXtextTestUtil UTIL_INSTANCE = new CheckCfgTestUtil() - def static AbstractXtextTestUtil getInstance(){UTIL_INSTANCE} - - override protected getInjector() { - CheckcfgActivator.getInstance().getInjector(CheckcfgActivator.COM_AVALOQ_TOOLS_DDK_CHECKCFG_CHECKCFG) - } - - override protected ITestProjectManager createTestProjectManager() { - new PluginTestProjectManager(getInjector()); - } -} diff --git a/com.avaloq.tools.ddk.checkcfg.core.test/src/com/avaloq/tools/ddk/checkcfg/validation/CheckCfgConfiguredParameterValidationsTest.java b/com.avaloq.tools.ddk.checkcfg.core.test/src/com/avaloq/tools/ddk/checkcfg/validation/CheckCfgConfiguredParameterValidationsTest.java new file mode 100644 index 0000000000..cffcfbea44 --- /dev/null +++ b/com.avaloq.tools.ddk.checkcfg.core.test/src/com/avaloq/tools/ddk/checkcfg/validation/CheckCfgConfiguredParameterValidationsTest.java @@ -0,0 +1,72 @@ +/******************************************************************************* + * Copyright (c) 2016 Avaloq Group AG and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Avaloq Group AG - initial API and implementation + *******************************************************************************/ + +package com.avaloq.tools.ddk.checkcfg.validation; + +import static com.avaloq.tools.ddk.checkcfg.CheckCfgConstants.PROPERTY_EXECUTABLE_EXTENSION_ATTRIBUTE; +import static com.avaloq.tools.ddk.checkcfg.CheckCfgConstants.PROPERTY_EXTENSION_POINT; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.jupiter.api.Test; + +import com.avaloq.tools.ddk.checkcfg.util.CheckCfgTestUtil; +import com.avaloq.tools.ddk.test.checkcfg.TestPropertySpecificationWithExpectedValues; +import com.avaloq.tools.ddk.test.checkcfg.TestPropertySpecificationWithOutExpectedValues; +import com.avaloq.tools.ddk.test.core.mock.ExtensionRegistryMock; +import com.avaloq.tools.ddk.xtext.test.jupiter.AbstractValidationTest; +import com.avaloq.tools.ddk.xtext.test.jupiter.AbstractXtextTestUtil; + +public class CheckCfgConfiguredParameterValidationsTest extends AbstractValidationTest { + + @Override + protected AbstractXtextTestUtil getXtextTestUtil() { + return CheckCfgTestUtil.getInstance(); + } + + @Override + protected List getRequiredSourceFileNames() { + return new ArrayList(0); + } + + @Override + protected void beforeAllTests() { + ExtensionRegistryMock.mockExecutableExtension(ExtensionRegistryMock.mockConfigurationElement(PROPERTY_EXTENSION_POINT), PROPERTY_EXECUTABLE_EXTENSION_ATTRIBUTE, TestPropertySpecificationWithExpectedValues.INSTANCE); + ExtensionRegistryMock.mockExecutableExtension(ExtensionRegistryMock.mockConfigurationElement(PROPERTY_EXTENSION_POINT), PROPERTY_EXECUTABLE_EXTENSION_ATTRIBUTE, TestPropertySpecificationWithOutExpectedValues.INSTANCE); + super.beforeAllTests(); + } + + @Override + protected void afterAllTests() { + super.afterAllTests(); + ExtensionRegistryMock.unMock(PROPERTY_EXTENSION_POINT); + } + + @Test + public void testConfiguredParameterValues() { + final TestPropertySpecificationWithExpectedValues allowedOnly = TestPropertySpecificationWithExpectedValues.INSTANCE; + final TestPropertySpecificationWithOutExpectedValues acceptsAny = TestPropertySpecificationWithOutExpectedValues.INSTANCE; + final String source = """ + check configuration Test + %s = %s"notAllowed" + for com.avaloq.tools.ddk.^check.TestLanguage { + %s = %s"%s" + %s = %s"whatever" + } + """.formatted( + allowedOnly.getName(), error(IssueCodes.PARAMETER_VALUE_NOT_ALLOWED), + allowedOnly.getName(), noDiagnostic(IssueCodes.PARAMETER_VALUE_NOT_ALLOWED), allowedOnly.getExpectedValues()[0], + acceptsAny.getName(), noDiagnostic(IssueCodes.PARAMETER_VALUE_NOT_ALLOWED)); + validateKernelSourceStrictly("ConfiguredParameterValues.checkcfg", source); + } + +} diff --git a/com.avaloq.tools.ddk.checkcfg.core.test/src/com/avaloq/tools/ddk/checkcfg/validation/CheckCfgConfiguredParameterValidationsTest.xtend b/com.avaloq.tools.ddk.checkcfg.core.test/src/com/avaloq/tools/ddk/checkcfg/validation/CheckCfgConfiguredParameterValidationsTest.xtend deleted file mode 100644 index f689a3bb18..0000000000 --- a/com.avaloq.tools.ddk.checkcfg.core.test/src/com/avaloq/tools/ddk/checkcfg/validation/CheckCfgConfiguredParameterValidationsTest.xtend +++ /dev/null @@ -1,63 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016 Avaloq Group AG and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Avaloq Group AG - initial API and implementation - *******************************************************************************/ - -package com.avaloq.tools.ddk.checkcfg.validation - -import com.avaloq.tools.ddk.checkcfg.util.CheckCfgTestUtil -import com.avaloq.tools.ddk.test.checkcfg.TestPropertySpecificationWithExpectedValues -import com.avaloq.tools.ddk.test.checkcfg.TestPropertySpecificationWithOutExpectedValues -import com.google.common.collect.Lists - -import static com.avaloq.tools.ddk.checkcfg.CheckCfgConstants.PROPERTY_EXECUTABLE_EXTENSION_ATTRIBUTE -import static com.avaloq.tools.ddk.checkcfg.CheckCfgConstants.PROPERTY_EXTENSION_POINT - -import static extension com.avaloq.tools.ddk.test.core.mock.ExtensionRegistryMock.mockConfigurationElement -import static extension com.avaloq.tools.ddk.test.core.mock.ExtensionRegistryMock.mockExecutableExtension -import static extension com.avaloq.tools.ddk.test.core.mock.ExtensionRegistryMock.unMock -import com.avaloq.tools.ddk.xtext.test.jupiter.AbstractValidationTest -import org.junit.jupiter.api.Test - -class CheckCfgConfiguredParameterValidationsTest extends AbstractValidationTest { - - override protected getXtextTestUtil() { - return CheckCfgTestUtil.instance - } - - override protected getRequiredSourceFileNames() { - Lists.newArrayListWithCapacity(0) - } - - override protected beforeAllTests() { - PROPERTY_EXTENSION_POINT.mockConfigurationElement.mockExecutableExtension(PROPERTY_EXECUTABLE_EXTENSION_ATTRIBUTE, TestPropertySpecificationWithExpectedValues.INSTANCE) - PROPERTY_EXTENSION_POINT.mockConfigurationElement.mockExecutableExtension(PROPERTY_EXECUTABLE_EXTENSION_ATTRIBUTE, TestPropertySpecificationWithOutExpectedValues.INSTANCE) - super.beforeAllTests() - } - - override protected afterAllTests() { - super.afterAllTests() - PROPERTY_EXTENSION_POINT.unMock - } - - @Test - def testConfiguredParameterValues() { - val allowedOnly = TestPropertySpecificationWithExpectedValues.INSTANCE - val acceptsAny = TestPropertySpecificationWithOutExpectedValues.INSTANCE - validateKernelSourceStrictly("ConfiguredParameterValues.checkcfg", ''' - check configuration Test - «allowedOnly.name» = «error(IssueCodes.PARAMETER_VALUE_NOT_ALLOWED)»"notAllowed" - for com.avaloq.tools.ddk.^check.TestLanguage { - «allowedOnly.name» = «noDiagnostic(IssueCodes.PARAMETER_VALUE_NOT_ALLOWED)»"«allowedOnly.expectedValues.head»" - «acceptsAny.name» = «noDiagnostic(IssueCodes.PARAMETER_VALUE_NOT_ALLOWED)»"whatever" - } - ''') - } - -} diff --git a/com.avaloq.tools.ddk.checkcfg.core.test/src/com/avaloq/tools/ddk/checkcfg/validation/CheckCfgTest.java b/com.avaloq.tools.ddk.checkcfg.core.test/src/com/avaloq/tools/ddk/checkcfg/validation/CheckCfgTest.java new file mode 100644 index 0000000000..dbad41e807 --- /dev/null +++ b/com.avaloq.tools.ddk.checkcfg.core.test/src/com/avaloq/tools/ddk/checkcfg/validation/CheckCfgTest.java @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2016 Avaloq Group AG and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Avaloq Group AG - initial API and implementation + *******************************************************************************/ +package com.avaloq.tools.ddk.checkcfg.validation; + +import org.eclipse.xtext.testing.InjectWith; +import org.eclipse.xtext.testing.extensions.InjectionExtension; +import org.eclipse.xtext.testing.util.ParseHelper; +import org.eclipse.xtext.testing.validation.ValidationTestHelper; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import com.avaloq.tools.ddk.checkcfg.CheckCfgUiInjectorProvider; +import com.avaloq.tools.ddk.checkcfg.checkcfg.CheckConfiguration; +import com.avaloq.tools.ddk.checkcfg.checkcfg.CheckcfgPackage; +import com.google.inject.Inject; + +@InjectWith(CheckCfgUiInjectorProvider.class) +@ExtendWith(InjectionExtension.class) +public class CheckCfgTest { + + @Inject + private ValidationTestHelper helper; + + @Inject + private ParseHelper parser; + + @Test + public void testValidLanguageOk() throws Exception { + final CheckConfiguration model = parser.parse(""" + check configuration Test + + for com.avaloq.tools.ddk.^check.TestLanguage { + + } + + """); + helper.assertNoIssues(model); + } + + @Test + public void testUnknownLanguageNotOk() throws Exception { + final CheckConfiguration model = parser.parse(""" + check configuration Test + + for com.avaloq.tools.ddk.^check.Unknown { + + } + + """); + helper.assertError(model, CheckcfgPackage.Literals.CONFIGURED_LANGUAGE_VALIDATOR, IssueCodes.UNKNOWN_LANGUAGE); + } + +} diff --git a/com.avaloq.tools.ddk.checkcfg.core.test/src/com/avaloq/tools/ddk/checkcfg/validation/CheckCfgTest.xtend b/com.avaloq.tools.ddk.checkcfg.core.test/src/com/avaloq/tools/ddk/checkcfg/validation/CheckCfgTest.xtend deleted file mode 100644 index db200957f3..0000000000 --- a/com.avaloq.tools.ddk.checkcfg.core.test/src/com/avaloq/tools/ddk/checkcfg/validation/CheckCfgTest.xtend +++ /dev/null @@ -1,63 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016 Avaloq Group AG and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Avaloq Group AG - initial API and implementation - *******************************************************************************/ -package com.avaloq.tools.ddk.checkcfg.validation - -import com.avaloq.tools.ddk.checkcfg.checkcfg.CheckConfiguration -import com.avaloq.tools.ddk.checkcfg.checkcfg.CheckcfgPackage -import com.google.inject.Inject -import org.eclipse.xtext.testing.util.ParseHelper -import org.eclipse.xtext.testing.validation.ValidationTestHelper -import org.eclipse.xtext.testing.InjectWith -import com.avaloq.tools.ddk.checkcfg.CheckCfgUiInjectorProvider -import org.junit.jupiter.api.Test -import org.junit.jupiter.api.^extension.ExtendWith -import org.eclipse.xtext.testing.extensions.InjectionExtension - -@InjectWith(typeof(CheckCfgUiInjectorProvider)) -@ExtendWith(InjectionExtension) -class CheckCfgTest { - - - @Inject - ValidationTestHelper helper; - - @Inject - ParseHelper parser; - - @Test - def testValidLanguageOk() { - - val model = parser.parse(''' - check configuration Test - - for com.avaloq.tools.ddk.^check.TestLanguage { - - } - - '''); - helper.assertNoIssues(model); - } - - @Test - def testUnknownLanguageNotOk() { - - val model = parser.parse(''' - check configuration Test - - for com.avaloq.tools.ddk.^check.Unknown { - - } - - '''); - helper.assertError(model, CheckcfgPackage.Literals::CONFIGURED_LANGUAGE_VALIDATOR, IssueCodes.UNKNOWN_LANGUAGE); - } - -} diff --git a/com.avaloq.tools.ddk.checkcfg.core.test/xtend-gen/.gitignore b/com.avaloq.tools.ddk.checkcfg.core.test/xtend-gen/.gitignore deleted file mode 100644 index e69de29bb2..0000000000 From 6bb6de82db23cfe57a8dcf0e47f7661f77d04f43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Dinis=20Ferreira?= Date: Thu, 11 Jun 2026 15:02:59 +0100 Subject: [PATCH 3/3] refactor: drop unused xtend-gen scaffolding - com.avaloq.tools.ddk.checkcfg.ide The bundle has no Xtend sources; the xtend-gen entries in .classpath and build.properties and the empty xtend-gen directory are leftovers. --- com.avaloq.tools.ddk.checkcfg.ide/.classpath | 5 ----- com.avaloq.tools.ddk.checkcfg.ide/build.properties | 3 +-- com.avaloq.tools.ddk.checkcfg.ide/xtend-gen/.gitignore | 0 3 files changed, 1 insertion(+), 7 deletions(-) delete mode 100644 com.avaloq.tools.ddk.checkcfg.ide/xtend-gen/.gitignore diff --git a/com.avaloq.tools.ddk.checkcfg.ide/.classpath b/com.avaloq.tools.ddk.checkcfg.ide/.classpath index 0f2735e0da..657ce4953b 100644 --- a/com.avaloq.tools.ddk.checkcfg.ide/.classpath +++ b/com.avaloq.tools.ddk.checkcfg.ide/.classpath @@ -6,11 +6,6 @@
- - - - - diff --git a/com.avaloq.tools.ddk.checkcfg.ide/build.properties b/com.avaloq.tools.ddk.checkcfg.ide/build.properties index bef28d3d93..ec65859a4c 100644 --- a/com.avaloq.tools.ddk.checkcfg.ide/build.properties +++ b/com.avaloq.tools.ddk.checkcfg.ide/build.properties @@ -1,5 +1,4 @@ source.. = src/,\ - src-gen/,\ - xtend-gen/ + src-gen/ bin.includes = META-INF/,\ . diff --git a/com.avaloq.tools.ddk.checkcfg.ide/xtend-gen/.gitignore b/com.avaloq.tools.ddk.checkcfg.ide/xtend-gen/.gitignore deleted file mode 100644 index e69de29bb2..0000000000