Skip to content

Commit 16a361c

Browse files
authored
Merge pull request #189 from modelix/compile-mps-adapters-with-all-versions
mps-model-adapters: fixed incompatibility with MPS 2021.2
2 parents 28a090d + f89dc61 commit 16a361c

File tree

4 files changed

+88
-6
lines changed

4 files changed

+88
-6
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: MPS compatibility
2+
3+
on:
4+
push:
5+
branches:
6+
- 'main'
7+
pull_request: {}
8+
# allow manual execution just in case
9+
workflow_dispatch:
10+
11+
jobs:
12+
build-mps-model-adapters:
13+
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- uses: actions/checkout@v3
18+
- name: Set up JDK 11
19+
uses: actions/setup-java@v3
20+
with:
21+
distribution: 'temurin'
22+
java-version: '11'
23+
- name: Build with MPS 2020.3.6
24+
run: ./gradlew :mps-model-adapters:build -Pmps.version=2020.3.6
25+
- name: Build with MPS 2021.1.4
26+
run: ./gradlew :mps-model-adapters:build -Pmps.version=2021.1.4
27+
- name: Build with MPS 2021.2.6
28+
run: ./gradlew :mps-model-adapters:build -Pmps.version=2021.2.6
29+
- name: Build with MPS 2021.3.3
30+
run: ./gradlew :mps-model-adapters:build -Pmps.version=2021.3.3
31+
- name: Build with MPS 2022.2
32+
run: ./gradlew :mps-model-adapters:build -Pmps.version=2022.2
33+
- name: Build with MPS 2022.3
34+
run: ./gradlew :mps-model-adapters:build -Pmps.version=2022.3

mps-model-adapters/build.gradle.kts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ plugins {
44
alias(libs.plugins.ktlint)
55
}
66

7+
val mpsVersion = project.findProperty("mps.version")?.toString().takeIf { !it.isNullOrBlank() } ?: "2020.3.6"
8+
79
dependencies {
810
api(project(":model-api"))
911

10-
compileOnly("com.jetbrains:mps-openapi:2021.1.4")
11-
compileOnly("com.jetbrains:mps-core:2021.1.4")
12-
compileOnly("com.jetbrains:mps-environment:2021.1.4")
12+
compileOnly("com.jetbrains:mps-openapi:$mpsVersion")
13+
compileOnly("com.jetbrains:mps-core:$mpsVersion")
14+
compileOnly("com.jetbrains:mps-environment:$mpsVersion")
1315

1416
implementation(kotlin("stdlib"))
1517
implementation(libs.kotlin.logging)
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright (c) 2023.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.modelix.model.mpsadapters;
18+
19+
import org.jetbrains.mps.openapi.language.SAbstractConcept;
20+
import org.jetbrains.mps.openapi.language.SConcept;
21+
import org.jetbrains.mps.openapi.language.SInterfaceConcept;
22+
23+
/**
24+
* The Kotlin compiler cannot disambiguate the call to getSuperConcept/getSuperInterfaces
25+
* that where moved to SAbstractConcept in MPS 2021.2, but still exist in SConcept/SInterfaceConcept.
26+
*/
27+
public class ConceptWorkaround {
28+
public SAbstractConcept concept;
29+
30+
public ConceptWorkaround(SAbstractConcept concept) {
31+
this.concept = concept;
32+
}
33+
34+
public SConcept getSuperConcept() {
35+
return ((SConcept) concept).getSuperConcept();
36+
}
37+
38+
public Iterable<SInterfaceConcept> getSuperInterfaces() {
39+
if (concept instanceof SConcept) {
40+
return ((SConcept) concept).getSuperInterfaces();
41+
} else {
42+
return ((SInterfaceConcept) concept).getSuperInterfaces();
43+
}
44+
}
45+
}

mps-model-adapters/src/main/kotlin/org/modelix/model/mpsadapters/MPSConcept.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,10 @@ data class MPSConcept(val concept: SAbstractConceptAdapter) : IConcept {
6565

6666
override fun getDirectSuperConcepts(): List<IConcept> {
6767
return when (concept) {
68-
is SConcept -> listOfNotNull<SAbstractConcept>(concept.superConcept) + concept.superInterfaces
69-
is SInterfaceConcept -> concept.superInterfaces
70-
else -> emptyList()
68+
is SConcept -> listOfNotNull<SAbstractConcept>(ConceptWorkaround(concept).superConcept) +
69+
ConceptWorkaround(concept).superInterfaces
70+
is SInterfaceConcept -> ConceptWorkaround(concept).superInterfaces
71+
else -> emptyList<SAbstractConcept>()
7172
}.map { MPSConcept(it) }
7273
}
7374

0 commit comments

Comments
 (0)