Skip to content

Commit

Permalink
Fixed validation propagated errors (#912)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCockx authored Jan 30, 2025
1 parent a0aea37 commit 0cbce89
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 18 deletions.
2 changes: 1 addition & 1 deletion docs/rune-java-documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ title: "Rune Java Documentation"
date: 2023-09-01T12:57:00+02:00
description: "This document describes the interface and usage of classes that are generated from a Rune model using the Java code generator."
draft: false
weight: 2
weight: 3
---

# Rune Java Documentation
Expand Down
4 changes: 2 additions & 2 deletions rosetta-integration-tests/.project
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<name>net.sf.eclipsecs.core.CheckstyleBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>net.sf.eclipsecs.core.CheckstyleBuilder</name>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.regnosys.rosetta.tests;

import javax.inject.Inject;

import org.eclipse.emf.ecore.util.EObjectValidator;
import org.eclipse.xtext.diagnostics.Diagnostic;
import org.eclipse.xtext.testing.InjectWith;
import org.eclipse.xtext.testing.extensions.InjectionExtension;
import org.eclipse.xtext.testing.validation.ValidationTestHelper;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

import com.regnosys.rosetta.rosetta.RosettaModel;
import com.regnosys.rosetta.tests.util.ModelHelper;

import static com.regnosys.rosetta.rosetta.RosettaPackage.Literals.*;

// Verify that we are using Xtext's EcoreValidator, which does not duplicate unresolved reference errors.
@ExtendWith(InjectionExtension.class)
@InjectWith(RosettaTestInjectorProvider.class)
public class NoEcoreValidatorTest {
@Inject ModelHelper modelHelper;
@Inject ValidationTestHelper validationHelper;

@Test
void testNoUnresolvedProxyError() {
RosettaModel model = modelHelper.parseRosetta("""
namespace test
type Foo:
attr UnresolvedType (1..1)
""");
// There should be an unresolved error
validationHelper.assertError(model, TYPE_CALL, Diagnostic.LINKING_DIAGNOSTIC, "Couldn't resolve reference to RosettaType 'UnresolvedType'.");
// There should not be an "unresolved proxy" error:
// "The feature 'type' of 'com.regnosys.rosetta.rosetta.impl.TypeCallImpl@2503ec73{__synthetic1.rosetta#/0/@elements.0/@attributes.0/@typeCall}'
// contains an unresolved proxy 'com.regnosys.rosetta.rosetta.impl.RosettaBasicTypeImpl@76a14c8d{__synthetic1.rosetta#|0}'"
validationHelper.assertNoIssue(model, TYPE_CALL, EObjectValidator.DIAGNOSTIC_SOURCE + "." + EObjectValidator.EOBJECT__EVERY_PROXY_RESOLVES);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,6 @@ class RosettaStandaloneSetup extends RosettaStandaloneSetupGenerated {

override Injector createInjectorAndDoEMFRegistration() {
EValidator.Registry.INSTANCE.clear // This line is to ensure tests don't use the same validator instance.
return super.createInjectorAndDoEMFRegistration()
}

/**
* Register xcore model in standalone setup.
*/
override register(Injector injector) {

if (!EPackage.Registry.INSTANCE.containsKey(RosettaPackage.eNS_URI)) {
EPackage.Registry.INSTANCE.put(RosettaPackage.eNS_URI, RosettaPackage.eINSTANCE);
}
Expand All @@ -38,6 +30,6 @@ class RosettaStandaloneSetup extends RosettaStandaloneSetupGenerated {
if (!EPackage.Registry.INSTANCE.containsKey(ExpressionPackage.eNS_URI)) {
EPackage.Registry.INSTANCE.put(ExpressionPackage.eNS_URI, ExpressionPackage.eINSTANCE);
}
super.register(injector)
return super.createInjectorAndDoEMFRegistration()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ import java.util.List
import com.regnosys.rosetta.types.RFunction
import javax.inject.Inject
import com.regnosys.rosetta.types.RChoiceType
import com.regnosys.rosetta.RosettaEcoreUtil

class RosettaFunctionExtensions {

@Inject RosettaEcoreUtil ecoreUtil
@Inject RosettaTypeProvider typeProvider

/**
Expand Down Expand Up @@ -171,7 +172,8 @@ class RosettaFunctionExtensions {

def getTransformAnnotations(Annotated element) {
element.annotations
.filter[it.annotation.model.name == "com.rosetta.model"]
.filter[ecoreUtil.isResolved(annotation)]
.filter["com.rosetta.model" == it.annotation.model.name]
.filter["ingest" == it.annotation.name || "enrich" == it.annotation.name || "projection" == it.annotation.name].toList
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,8 @@ import javax.inject.Inject
import javax.inject.Provider
import org.eclipse.emf.ecore.EObject

import com.regnosys.rosetta.rosetta.expression.SwitchCaseOrDefault
import static extension com.regnosys.rosetta.types.RMetaAnnotatedType.withMeta
import static extension com.regnosys.rosetta.types.RMetaAnnotatedType.withNoMeta
import com.regnosys.rosetta.rosetta.simple.Attribute
import com.regnosys.rosetta.rosetta.simple.AnnotationPathExpression
import com.regnosys.rosetta.rosetta.simple.AnnotationPathAttributeReference
import com.regnosys.rosetta.rosetta.simple.AnnotationPath
Expand Down Expand Up @@ -175,7 +173,7 @@ class RosettaTypeProvider extends RosettaExpressionSwitch<RMetaAnnotatedType, Ma

def List<RMetaAttribute> getRMetaAttributes(List<AnnotationRef> annotations) {
annotations
.filter[it.annotation.name.equals("metadata") && it.attribute !== null]
.filter[extensions.isResolved(annotation) && "metadata" == annotation.name && extensions.isResolved(attribute)]
.map[new RMetaAttribute(it.attribute.name, it.attribute.RTypeOfSymbol.RType)]
.toList
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ protected INode findDirectKeyword(ICompositeNode node, String keyword) {
}

protected void checkDeprecatedAnnotation(Annotated annotated, EObject owner, EStructuralFeature ref, int index) {
if (annotated.getAnnotations().stream().anyMatch(ann -> ann.getAnnotation() != null && ann.getAnnotation().getName().equals("deprecated"))) {
if (annotated.getAnnotations().stream().anyMatch(ann -> ecoreUtil.isResolved(ann.getAnnotation()) && "deprecated".equals(ann.getAnnotation().getName()))) {
String msg;
if (annotated instanceof RosettaNamed) {
msg = ((RosettaNamed)annotated).getName() + " is deprecated";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.google.inject.Injector;
import com.regnosys.rosetta.RosettaRuntimeModule;
import com.regnosys.rosetta.RosettaStandaloneSetup;

import org.eclipse.xtext.testing.GlobalRegistries;
import org.eclipse.xtext.testing.GlobalRegistries.GlobalStateMemento;
import org.eclipse.xtext.testing.IInjectorProvider;
Expand Down

0 comments on commit 0cbce89

Please sign in to comment.