Skip to content

Commit

Permalink
Metacompiler fix (#1024)
Browse files Browse the repository at this point in the history
* Fix metacompiler when installed together with KLighD.

Previously the metacompiler would fail to compile some melk files due to
the name already being defined. This modifies the validator to
explicitly only check in paths containing "src".

* add missing newline
  • Loading branch information
Eddykasp authored Apr 15, 2024
1 parent dcde056 commit 9bc9347
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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")]])
}
}

0 comments on commit 9bc9347

Please sign in to comment.