diff --git a/plugins/org.eclipse.elk.core.meta.ui/src/org/eclipse/elk/core/meta/ui/MetaDataUiModule.xtend b/plugins/org.eclipse.elk.core.meta.ui/src/org/eclipse/elk/core/meta/ui/MetaDataUiModule.xtend index adbf92b137..50782e5a61 100644 --- a/plugins/org.eclipse.elk.core.meta.ui/src/org/eclipse/elk/core/meta/ui/MetaDataUiModule.xtend +++ b/plugins/org.eclipse.elk.core.meta.ui/src/org/eclipse/elk/core/meta/ui/MetaDataUiModule.xtend @@ -9,11 +9,24 @@ *******************************************************************************/ package org.eclipse.elk.core.meta.ui +import org.eclipse.elk.core.meta.validation.MelkUniqueClassNameValidator import org.eclipse.xtend.lib.annotations.FinalFieldsConstructor +import org.eclipse.xtext.service.SingletonBinding /** * Use this class to register components to be used within the Eclipse IDE. */ @FinalFieldsConstructor class MetaDataUiModule extends AbstractMetaDataUiModule { + +// If the Metacompiler has hiccups this can be used to always generate the Java source files, +// regardles of any errors. +// override bindIShouldGenerate() { +// return Always +// } + + @SingletonBinding(eager = true) + override bindUniqueClassNameValidator() { + return MelkUniqueClassNameValidator + } } diff --git a/plugins/org.eclipse.elk.core.meta/src/org/eclipse/elk/core/meta/MetaDataRuntimeModule.xtend b/plugins/org.eclipse.elk.core.meta/src/org/eclipse/elk/core/meta/MetaDataRuntimeModule.xtend index 52b98a5a10..a61fa406f5 100644 --- a/plugins/org.eclipse.elk.core.meta/src/org/eclipse/elk/core/meta/MetaDataRuntimeModule.xtend +++ b/plugins/org.eclipse.elk.core.meta/src/org/eclipse/elk/core/meta/MetaDataRuntimeModule.xtend @@ -15,6 +15,8 @@ import org.eclipse.elk.core.meta.jvmmodel.MelkDocumentationGenerator import org.eclipse.xtext.generator.IOutputConfigurationProvider import org.eclipse.xtext.generator.OutputConfiguration import org.eclipse.xtext.generator.OutputConfigurationProvider +import org.eclipse.elk.core.meta.validation.MelkUniqueClassNameValidator +import org.eclipse.xtext.service.SingletonBinding /** * Use this class to register components to be used at runtime / without the Equinox extension registry. @@ -25,6 +27,11 @@ class MetaDataRuntimeModule extends AbstractMetaDataRuntimeModule { return MelkDocumentationGenerator } + @SingletonBinding(eager = true) + override bindUniqueClassNameValidator() { + return MelkUniqueClassNameValidator + } + // register MelkOutputConfigurationProvider that inserts a configuration used to read files in the project override configure(Binder binder) { super.configure(binder) diff --git a/plugins/org.eclipse.elk.core.meta/src/org/eclipse/elk/core/meta/validation/MelkUniqueClassNameValidator.xtend b/plugins/org.eclipse.elk.core.meta/src/org/eclipse/elk/core/meta/validation/MelkUniqueClassNameValidator.xtend new file mode 100644 index 0000000000..799788da5f --- /dev/null +++ b/plugins/org.eclipse.elk.core.meta/src/org/eclipse/elk/core/meta/validation/MelkUniqueClassNameValidator.xtend @@ -0,0 +1,34 @@ +/******************************************************************************* + * Copyright (c) 2024 mka and others. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + *******************************************************************************/ +package org.eclipse.elk.core.meta.validation + +import com.google.inject.Inject +import org.eclipse.xtext.common.types.JvmDeclaredType +import org.eclipse.xtext.common.types.TypesPackage +import org.eclipse.xtext.naming.QualifiedName +import org.eclipse.xtext.xbase.validation.UniqueClassNameValidator +import org.eclipse.xtext.resource.impl.ResourceDescriptionsProvider + +/** + * Overwrites the UniqueClassNameValidator to only check for melk files in src folders. This probably + * prevents some special use cases where ELK is used as a library and a new melk file is created. + * + */ +class MelkUniqueClassNameValidator extends UniqueClassNameValidator { + + @Inject + var ResourceDescriptionsProvider resourceDescriptionsProvider; + + override doCheckUniqueName(QualifiedName name, JvmDeclaredType type) { + val index = resourceDescriptionsProvider.getResourceDescriptions(type.eResource()) + val others = index.getExportedObjects(TypesPackage.Literals.JVM_DECLARED_TYPE, name, false) + return checkUniqueInIndex(type, others.filter[it.EObjectURI.segments.exists[it.contains("src")]]) + } +}