Skip to content

Commit

Permalink
Label annotation support (#904)
Browse files Browse the repository at this point in the history
* WIP

* Added Model Instance Flattener to create a flattened version of any model instance.

* Implemented label provider

* Fixed

* Added Java unit test

* Added highlighting

* Merged

* Fixed tests

* Added flattener test

* Corrected tests

* Add cleaning of rosetta-testing

* Updated tests

* Fixed

---------

Co-authored-by: Minesh Patel <minesh.patel@regnosys.com>
Co-authored-by: minesh-s-patel <minesh-s-patel@users.noreply.github.com>
  • Loading branch information
3 people authored Jan 23, 2025
1 parent f81de67 commit 283600a
Show file tree
Hide file tree
Showing 46 changed files with 1,723 additions and 50 deletions.
2 changes: 2 additions & 0 deletions checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
"-//Puppy Crawl//DTD Check Configuration 1.3//EN"
"http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
<module name="Checker">
<property name="localeCountry" value="UK"/>
<property name="localeLanguage" value="en"/>
<module name="TreeWalker">
<!-- Forbid using Google Inject in favor of javax Inject. -->
<module name="IllegalImport">
Expand Down
1 change: 1 addition & 0 deletions docs/rune-java-documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ reporting rule VehicleClassificationType from VehicleOwnership: <"Classification
In Java, the report is represented by the following class:
``` Java
@RosettaReport(namespace="test.reg", body="EuropeanParliament", corpusList={"EmissionPerformanceStandardsEU"})
@RuneLabelProvider(labelProvider=EuropeanParliamentEmissionPerformanceStandardsEULabelProvider.class)
@ImplementedBy(EuropeanParliamentEmissionPerformanceStandardsEUReportFunction.EuropeanParliamentEmissionPerformanceStandardsEUReportFunctionDefault.class)
public abstract class EuropeanParliamentEmissionPerformanceStandardsEUReportFunction implements ReportFunction<VehicleOwnership, EuropeanParliamentReport> {
@Override
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,12 @@
<module>rosetta-xcore-plugin-dependencies</module>
<module>rosetta-runtime</module>
<module>rosetta-lang</module>
<module>rosetta-testing</module>
<module>rosetta-integration-tests</module>
<module>rosetta-ide</module>
<module>rosetta-tools</module>
<module>rosetta-testing</module>
<module>rosetta-maven-plugin</module>
<module>rosetta-profiling</module>
<module>rosetta-integration-tests</module>
</modules>

<dependencyManagement>
Expand Down
31 changes: 29 additions & 2 deletions rosetta-ide/rosetta.tmLanguage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,7 @@ repository:
- include: '#synonymAnnotationBody'
- include: '#referenceAnnotationBody'
- include: '#ruleReferenceAnnotationBody'
- include: '#labelAnnotationBody'
- include: '#customAnnotationBody'

prefixAnnotationBody:
Expand Down Expand Up @@ -715,6 +716,28 @@ repository:
- name: entity.name.rule.rosetta
match: '{{identifier}}'

labelAnnotationBody:
name: meta.annotated.label.rosetta
begin: '{{wordStart}}label{{wordEnd}}'
beginCaptures:
0: { name: variable.annotation.label.rosetta }
end: (?=\])|{{sectionEnd}}
patterns:
- include: '#comment'
- name: meta.annotated.label.path.rosetta
begin: '(?<={{wordStart}}label{{wordEnd}})'
end: '{{wordStart}}as{{wordEnd}}'
endCaptures:
0: { name: keyword.other.rosetta }
patterns:
- include: '#comment'
- include: '#implicitVariable'
- name: keyword.operator.rosetta
match: ->
- name: variable.other.member.rosetta
match: '{{identifier}}'
- include: '#string'

customAnnotationBody:
name: meta.annotated.rosetta
begin: '{{identifier}}'
Expand Down Expand Up @@ -1138,8 +1161,7 @@ repository:
patterns:
- include: '#comment'
- include: '#literal'
- name: constant.language.rosetta
match: '{{wordStart}}(item|it){{wordEnd}}'
- include: '#implicitVariable'
- name: meta.if-then.rosetta
begin: '{{wordStart}}if{{wordEnd}}'
beginCaptures:
Expand Down Expand Up @@ -1200,6 +1222,10 @@ repository:
- name: variable.rosetta # Need semantic tokens to specify variable
match: '{{identifier}}'

implicitVariable:
name: constant.language.rosetta
match: '{{wordStart}}item{{wordEnd}}'

constructorExpression:
name: meta.constructor.rosetta
begin: (\{)
Expand Down Expand Up @@ -1296,6 +1322,7 @@ repository:
- include: '#synonymAnnotationBody'
- include: '#referenceAnnotationBody'
- include: '#ruleReferenceAnnotationBody'
- include: '#labelAnnotationBody'
- include: '#customAnnotationBody'
- include: '#annotationsFollowedByExpression'
- include: '#expression'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,6 @@ class ContentAssistTest extends AbstractRosettaLanguageServerTest {
flatten -> flatten [[19, 2] .. [19, 2]]
if -> if [[19, 2] .. [19, 2]]
is -> is [[19, 2] .. [19, 2]]
it -> it [[19, 2] .. [19, 2]]
item -> item [[19, 2] .. [19, 2]]
join -> join [[19, 2] .. [19, 2]]
last -> last [[19, 2] .. [19, 2]]
Expand Down
10 changes: 10 additions & 0 deletions rosetta-integration-tests/.checkstyle
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>

<fileset-config file-format-version="1.2.0" simple-config="true" sync-formatter="false">
<local-check-config name="Custom" location="/com.regnosys.rosetta.parent/checkstyle.xml" type="project" description="">
<additional-data name="protect-config-file" value="false"/>
</local-check-config>
<fileset name="all" enabled="true" check-config-name="Custom" local="true">
<file-match-pattern match-pattern="." include-pattern="true"/>
</fileset>
</fileset-config>
35 changes: 35 additions & 0 deletions rosetta-integration-tests/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>rosetta-integration-tests</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.xtext.ui.shared.xtextBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>net.sf.eclipsecs.core.CheckstyleBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.xtext.ui.shared.xtextNature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>net.sf.eclipsecs.core.CheckstyleNature</nature>
</natures>
</projectDescription>
Original file line number Diff line number Diff line change
Expand Up @@ -127,16 +127,19 @@ class DocumentationSamples {
import com.google.inject.ImplementedBy;
import com.rosetta.model.lib.annotations.RosettaReport;
import com.rosetta.model.lib.annotations.RuneLabelProvider;
import com.rosetta.model.lib.functions.ModelObjectValidator;
import com.rosetta.model.lib.reports.ReportFunction;
import java.util.Optional;
import javax.inject.Inject;
import test.reg.EuropeanParliamentReport;
import test.reg.EuropeanParliamentReport.EuropeanParliamentReportBuilder;
import test.reg.VehicleOwnership;
import test.reg.labels.EuropeanParliamentEmissionPerformanceStandardsEULabelProvider;
@RosettaReport(namespace="test.reg", body="EuropeanParliament", corpusList={"EmissionPerformanceStandardsEU"})
@RuneLabelProvider(labelProvider=EuropeanParliamentEmissionPerformanceStandardsEULabelProvider.class)
@ImplementedBy(EuropeanParliamentEmissionPerformanceStandardsEUReportFunction.EuropeanParliamentEmissionPerformanceStandardsEUReportFunctionDefault.class)
public abstract class EuropeanParliamentEmissionPerformanceStandardsEUReportFunction implements ReportFunction<VehicleOwnership, EuropeanParliamentReport> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ class RosettaFormattingTest {
type AllocationOutcome:
condition C1:
if True
then True extract [it = False] = True
then True extract [item = False] = True
condition C2:
True
''', '''
Expand All @@ -548,7 +548,7 @@ class RosettaFormattingTest {
if True
then True
extract [
it = False
item = False
] = True
condition C2:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class ConditionGeneratorTest {
a int (0..1)
condition C:
it -> a exists and [it, it] any = it
item -> a exists and [item, item] any = item
'''.generateCode
val classes = code.compileToClasses

Expand Down
Loading

0 comments on commit 283600a

Please sign in to comment.