Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.resource.Resource;
import org.jspecify.annotations.Nullable;
import tools.vitruv.neojoin.Constants;
import tools.vitruv.neojoin.Formatting;
import tools.vitruv.neojoin.aqr.AQR;
import tools.vitruv.neojoin.aqr.AQRFeature;
import tools.vitruv.neojoin.aqr.AQRTargetClass;
Expand Down Expand Up @@ -100,7 +100,7 @@ public EObject transform() throws TransformatorException {
.forEach(target -> {
var instances = transformTargetClass(target);
var rootRef = root.eClass()
.getEStructuralFeature(Constants.RootReferenceNameFormat.formatted(target.name()));
.getEStructuralFeature(Formatting.formatRootReferenceName(target.name()));
root.eSet(rootRef, instances);
});

Expand Down
4 changes: 2 additions & 2 deletions lang/frontend/cli/src/test/resources/models/pizza.ecore
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
eType="#//Food"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="Root">
<eStructuralFeatures xsi:type="ecore:EReference" name="allFoods" ordered="false"
<eStructuralFeatures xsi:type="ecore:EReference" name="foods" ordered="false"
upperBound="-1" eType="#//Food" containment="true"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="allRestaurants" ordered="false"
<eStructuralFeatures xsi:type="ecore:EReference" name="restaurants" ordered="false"
upperBound="-1" eType="#//Restaurant" containment="true"/>
</eClassifiers>
</ecore:EPackage>
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<eStructuralFeatures xsi:type="ecore:EAttribute" name="avgMovieScore" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EDouble"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="Root">
<eStructuralFeatures xsi:type="ecore:EReference" name="allActors" ordered="false"
<eStructuralFeatures xsi:type="ecore:EReference" name="actors" ordered="false"
upperBound="-1" eType="#//Actor" containment="true"/>
</eClassifiers>
</ecore:EPackage>
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<eStructuralFeatures xsi:type="ecore:EAttribute" name="minutesPerPage" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EInt"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="Root">
<eStructuralFeatures xsi:type="ecore:EReference" name="allAudioBooks" ordered="false"
<eStructuralFeatures xsi:type="ecore:EReference" name="audioBooks" ordered="false"
upperBound="-1" eType="#//AudioBook" containment="true"/>
</eClassifiers>
</ecore:EPackage>
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
<eStructuralFeatures xsi:type="ecore:EAttribute" name="title" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="Root">
<eStructuralFeatures xsi:type="ecore:EReference" name="allCustomers" ordered="false"
<eStructuralFeatures xsi:type="ecore:EReference" name="customers" ordered="false"
upperBound="-1" eType="#//Customer" containment="true"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="allBooks" ordered="false"
<eStructuralFeatures xsi:type="ecore:EReference" name="books" ordered="false"
upperBound="-1" eType="#//Book" containment="true"/>
</eClassifiers>
</ecore:EPackage>
4 changes: 2 additions & 2 deletions lang/frontend/cli/src/test/resources/results/movies.ecore
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
<eStructuralFeatures xsi:type="ecore:EAttribute" name="avgRating" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EDouble"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="Root">
<eStructuralFeatures xsi:type="ecore:EReference" name="allMovies" ordered="false"
<eStructuralFeatures xsi:type="ecore:EReference" name="movies" ordered="false"
upperBound="-1" eType="#//Movie" containment="true"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="allActors" ordered="false"
<eStructuralFeatures xsi:type="ecore:EReference" name="actors" ordered="false"
upperBound="-1" eType="#//Actor" containment="true"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="Actor">
Expand Down
8 changes: 4 additions & 4 deletions lang/frontend/cli/src/test/resources/results/pizza.xmi
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="ASCII"?>
<pizza:Root xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:pizza="http://example.org/pizza">
<allFoods name="Pizza Margherita" price="7.0"/>
<allFoods name="Fanta" price="5.0"/>
<allFoods name="Maultaschen" price="8.0"/>
<allRestaurants name="Pizzeria Toni" sells="//@allFoods.0 //@allFoods.1"/>
<foods name="Pizza Margherita" price="7.0"/>
<foods name="Fanta" price="5.0"/>
<foods name="Maultaschen" price="8.0"/>
<restaurants name="Pizzeria Toni" sells="//@foods.0 //@foods.1"/>
</pizza:Root>
82 changes: 81 additions & 1 deletion lang/frontend/language/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<maven.compiler.release>17</maven.compiler.release>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<kotlin.version>2.3.10</kotlin.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -95,6 +96,17 @@
<artifactId>junit-platform-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk8</artifactId>
<version>${kotlin.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-test</artifactId>
<version>${kotlin.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down Expand Up @@ -129,6 +141,74 @@
</filesets>
</configuration>
</plugin>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>${kotlin.version}</version>
<extensions>true</extensions>
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<sourceDirs>
<sourceDir>src/main/java</sourceDir>
<sourceDir>src/main/xtext</sourceDir>
<sourceDir>target/generated-sources/annotations</sourceDir>
<sourceDir>target/generated-sources/xtext-ecore</sourceDir>
<sourceDir>target/generated-sources/xtext-java</sourceDir>
</sourceDirs>
</configuration>
</execution>
<execution>
<id>test-compile</id>
<phase>test-compile</phase>
<goals>
<goal>test-compile</goal>
</goals>
<configuration>
<sourceDirs>
<sourceDir>src/test/java</sourceDir>
<sourceDir>target/generated-test-sources/test-annotations</sourceDir>
</sourceDirs>
</configuration>
</execution>
</executions>
<configuration>
<jvmTarget>${maven.compiler.target}</jvmTarget>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<id>default-compile</id>
<phase>none</phase>
</execution>
<execution>
<id>default-testCompile</id>
<phase>none</phase>
</execution>
<execution>
<id>compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>testCompile</id>
<phase>test-compile</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

Expand All @@ -148,4 +228,4 @@
</build>
</profile>
</profiles>
</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ public final class Constants {

public static final String DefaultRootClassName = "Root";

public static final String RootReferenceNameFormat = "all%ss";

public static final String ExpressionSelfReference = "it";

public static final String EcoreAlias = "ecore";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package tools.vitruv.neojoin;

public class Formatting {

public static String formatRootReferenceName(String name) {
return new StringBuilder(name)
.replace(0, 1, "" + Character.toLowerCase(name.charAt(0)))
.append("s")
.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.eclipse.xtext.xbase.XExpression;
import org.jspecify.annotations.Nullable;
import tools.vitruv.neojoin.Constants;
import tools.vitruv.neojoin.Formatting;
import tools.vitruv.neojoin.ast.Body;
import tools.vitruv.neojoin.ast.Export;
import tools.vitruv.neojoin.ast.Feature;
Expand Down Expand Up @@ -438,7 +439,7 @@ private void populateRoot(AQRTargetClass root) {
continue;
}

var featureName = Constants.RootReferenceNameFormat.formatted(target.name());
var featureName = Formatting.formatRootReferenceName(target.name());
invariant(
root.features().stream().noneMatch(f -> f.name().equals(featureName)),
() -> "Duplicated feature name '%s' in root class".formatted(featureName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference;
import org.jspecify.annotations.Nullable;
import tools.vitruv.neojoin.Constants;
import tools.vitruv.neojoin.Formatting;
import tools.vitruv.neojoin.aqr.AQRFeatureOptionsBuilder;
import tools.vitruv.neojoin.ast.AstPackage;
import tools.vitruv.neojoin.ast.Feature;
Expand All @@ -27,10 +28,7 @@
import tools.vitruv.neojoin.utils.AstUtils;
import tools.vitruv.neojoin.utils.TypeCasts;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.*;
import java.util.function.BiConsumer;
import java.util.stream.Collectors;
import java.util.stream.Stream;
Expand Down Expand Up @@ -423,7 +421,7 @@ public void checkRootFeatureCollision(MainQuery mainQuery) {

var allNames = AstUtils.getAllQueries(AstUtils.getViewType(mainQuery))
.map(q -> AstUtils.getTargetName(q, expressionHelper))
.map(Constants.RootReferenceNameFormat::formatted)
.map(Formatting::formatRootReferenceName)
.collect(Collectors.toSet());

for (var feature : mainQuery.getBody().getFeatures()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ void rootReferences() {
assertThat(root)
.hasNoCondition()
.hasCalculatedAttribute("test", "EInt")
.hasGeneratedReference("allRestaurantys", "Restauranty") // explicit
.hasGeneratedReference("allFoods", "Food") // implicit
.hasGeneratedReference("restaurantys", "Restauranty") // explicit
.hasGeneratedReference("foods", "Food") // implicit
.hasNoMoreFeatures();
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ void featureNameConflict() {
from Food create

create root Rooty {
allFoods := 5
foods := 5
}
""");

Expand Down
Loading