Skip to content

Commit

Permalink
Attribute restrictions (#875)
Browse files Browse the repository at this point in the history
* Implemented syntax and validation

* WIP

* Implemented code gen

* Fixed tests

* Location fix

* Relaxed errors

* Fixed errors

* Cleaned

* Made metadata unmodifiable

* Made metadata unmodifiable

* Implemented autocompletion

* Typos

* Fix rule inheritance

* Fixed

* Auto-complete

* Clean

* Inherit deprecated annotation
  • Loading branch information
SimonCockx authored Dec 13, 2024
1 parent 6bd6e67 commit 9b917aa
Show file tree
Hide file tree
Showing 79 changed files with 6,131 additions and 4,050 deletions.
4 changes: 4 additions & 0 deletions rosetta-ide/rosetta.tmLanguage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,8 @@ repository:
- include: '#comment'
- include: '#annotation'
- include: '#documentation'
- name: keyword.other.override.rosetta
match: '{{wordStart}}override{{wordEnd}}'
- name: meta.attribute.rosetta
begin: '{{identifier}}'
beginCaptures:
Expand All @@ -776,6 +778,8 @@ repository:
- include: '#comment'
- include: '#annotation'
- include: '#documentation'
- name: keyword.other.override.rosetta
match: '{{wordStart}}override{{wordEnd}}'
- name: meta.attribute.rosetta
begin: '{{identifier}}'
beginCaptures:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ import com.regnosys.rosetta.ide.contentassist.cancellable.RosettaOperationCancel
import com.regnosys.rosetta.ide.semantictokens.RosettaSemanticTokenModifiersProvider
import org.eclipse.xtext.ide.server.hover.IHoverService
import com.regnosys.rosetta.ide.hover.RosettaHoverService
import org.eclipse.xtext.ide.editor.contentassist.IdeContentProposalProvider
import com.regnosys.rosetta.ide.contentassist.RosettaContentProposalProvider

/**
* Use this class to register ide components.
Expand Down Expand Up @@ -101,4 +103,8 @@ class RosettaIdeModule extends AbstractRosettaIdeModule {
def Class<? extends IHoverService> bindIHoverService() {
RosettaHoverService
}

def Class<? extends IdeContentProposalProvider> bindIdeContentProposalProvider() {
RosettaContentProposalProvider
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.regnosys.rosetta.ide.contentassist;

import javax.inject.Inject;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.xtext.RuleCall;
import org.eclipse.xtext.ide.editor.contentassist.ContentAssistContext;
import org.eclipse.xtext.ide.editor.contentassist.ContentAssistEntry;
import org.eclipse.xtext.ide.editor.contentassist.IIdeContentProposalAcceptor;
import org.eclipse.xtext.ide.editor.contentassist.IdeContentProposalProvider;
import org.eclipse.xtext.resource.EObjectDescription;

import com.regnosys.rosetta.RosettaEcoreUtil;
import com.regnosys.rosetta.rosetta.simple.Attribute;
import com.regnosys.rosetta.rosetta.simple.Data;
import com.regnosys.rosetta.services.RosettaGrammarAccess;

public class RosettaContentProposalProvider extends IdeContentProposalProvider {
@Inject
private RosettaGrammarAccess grammarAccess;
@Inject
private RosettaEcoreUtil ecoreUtil;

@Override
protected void _createProposals(RuleCall ruleCall, ContentAssistContext context, IIdeContentProposalAcceptor acceptor) {
if (context.getCurrentModel() instanceof Attribute && ruleCall.equals(grammarAccess.getAttributeAccess().getRosettaNamedParserRuleCall_1())) {
createProposalsForAttributeName((Attribute) context.getCurrentModel(), context, acceptor);
}
super._createProposals(ruleCall, context, acceptor);
}

private void createProposalsForAttributeName(Attribute attr, ContentAssistContext context, IIdeContentProposalAcceptor acceptor) {
if (attr.isOverride()) {
EObject container = attr.eContainer();
if (container instanceof Data) {
Data data = (Data) container;
if (data.getSuperType() != null) {
ecoreUtil.getAllAttributes(data.getSuperType())
.forEach((superAttr) -> {
ContentAssistEntry proposal = getProposalCreator().createProposal(superAttr.getName(), context);
int priority = getProposalPriorities().getCrossRefPriority(EObjectDescription.create(superAttr.getName(), superAttr), proposal);
acceptor.accept(proposal, priority);
});
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
import com.regnosys.rosetta.services.RosettaGrammarAccess;

public class GenerateTmGrammar {
private static List<String> ignoredRosettaKeywords = List.of("..", "namespace", "condition", "required", "optional", /* @Compat */"qualifiedType", "calculationType");
private static List<String> ignoredRosettaKeywords = List.of("..", "namespace", "condition", "required", "optional", "override", /* @Compat */"qualifiedType", "calculationType");

/**
* param 0: path to input yaml file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -469,4 +469,33 @@ class ContentAssistTest extends AbstractRosettaLanguageServerTest {
'''
]
}

@Test
def void testAttributeOverride() {
val model = '''
namespace my.ns
type Parent:
attr int (0..1)
parentAttr int (1..1)
type Foo extends Parent:
override attr int (1..1)
otherAttr string (1..1)
type Bar extends Foo:
override
barAttr int (1..1)
'''
testCompletion[
it.model = model
it.line = 11
it.column = 10
it.expectedCompletionItems = '''
attr -> attr [[11, 10] .. [11, 10]]
otherAttr -> otherAttr [[11, 10] .. [11, 10]]
parentAttr -> parentAttr [[11, 10] .. [11, 10]]
'''
]
}
}
Loading

0 comments on commit 9b917aa

Please sign in to comment.