|
Re: How to get index of the variable in the text of DSL program? [message #1719617 is a reply to message #1719605] |
Sun, 10 January 2016 07:11 |
|
hi,
if this is a question on xtext the index is ususally the index of a Child in a Parents list
e.g.
Parent:
childs+=Child*
;
Child:
name=ID
;
then the following methods may help you to calculate the index
generically:
org.eclipse.emf.ecore.EObject.eContainer()
org.eclipse.emf.ecore.EObject.eContainingFeature()
org.eclipse.emf.ecore.EObject.eGet(EStructuralFeature)
(+ Cast to list and index of)
or you use:
org.eclipse.emf.ecore.EObject.eContainer() + cast to Parent
Parent.getChild().indexOf(c)
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
Re: How to get index of the variable in the text of DSL program? [message #1719635 is a reply to message #1719617] |
Sun, 10 January 2016 20:10 |
kozhaev Vladimir Messages: 108 Registered: July 2009 |
Senior Member |
|
|
I have following realisation of the validator
/*
* generated by Xtext 2.9.1
*/
package org.casualintellect.validation
import java.util.LinkedList
import java.util.List
import org.casualintellect.casualIntellect.CasualIntellectPackage
import org.casualintellect.casualIntellect.Model
import org.casualintellect.casualIntellect.Transition
import org.eclipse.emf.ecore.EObject
import org.eclipse.xtext.validation.Check
/**
* This class contains custom validation rules.
*
* See https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html#validation
*/
class CasualIntellectValidator extends AbstractCasualIntellectValidator {
@Check
def checkTransitions(Model model) {
var states = model.list_of_states;
val listOfStateNames = new LinkedList<String>();
for (var i = 0; i < states.length; i++) {
var state = states.get(i);
listOfStateNames.add(state.name);
}
for (var i = 0; i < states.length; i++) {
val state = states.get(i);
val name=state.name;
var list = listOfStateNames.filter[equals(name)]
if (list.size > 1) {
//val index=foundIndex(state)
warning('There are several states with the same name:' + name, CasualIntellectPackage.Literals.STATE,
CasualIntellectPackage::eINSTANCE.state_Name)
}
}
for (var i = 0; i < states.length; i++) {
val state=states.get(i);
val transitionsList=state.transitions.list;
transitionsList.forEach[transition|checkTransition(transition,listOfStateNames)]
}
}
def checkTransition(Transition transition,List<String> stateNamesList){
if (!stateNamesList.contains(transition.name)){
val index=foundIndex(transition);
warning('No state for transition ' + transition.name, CasualIntellectPackage.Literals.STATE,
CasualIntellectPackage::eINSTANCE.state_Name,index)
}
}
def foundIndex(EObject object){
val container=object.eContainer;
var index=container.eContents.indexOf(object);
index;
}
}
For validation following DSL program
state state1{
before: salo, pivo, vodka;
after:salo,pivo,vodka;
in_process:pivo, vodka, salo;
transitions : {transition:salo; condition:true; methods:salo,pivo,vodka}
}
Method foundIndex return 0, and I have following exception. Where I'm wrong?
java.lang.IllegalArgumentException: You can only add issues for EObjects contained in the currently validated resource 'platform:/resource/test/test.casual'. But the given EObject was contained in 'http://www.casualintellect.org/CasualIntellect'
at org.eclipse.xtext.validation.AbstractDeclarativeValidator.checkIsFromCurrentlyCheckedResource(AbstractDeclarativeValidator.java:571)
at org.eclipse.xtext.validation.AbstractDeclarativeValidator.acceptWarning(AbstractDeclarativeValidator.java:580)
at org.eclipse.xtext.validation.AbstractDeclarativeValidator.warning(AbstractDeclarativeValidator.java:399)
at org.eclipse.xtext.validation.AbstractDeclarativeValidator.warning(AbstractDeclarativeValidator.java:394)
at org.casualintellect.validation.CasualIntellectValidator.checkTransition(CasualIntellectValidator.java:78)
at org.casualintellect.validation.CasualIntellectValidator.lambda$1(CasualIntellectValidator.java:62)
at org.casualintellect.validation.CasualIntellectValidator$$Lambda$4/2009006352.accept(Unknown Source)
at java.lang.Iterable.forEach(Unknown Source)
at org.casualintellect.validation.CasualIntellectValidator.checkTransitions(CasualIntellectValidator.java:64)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.xtext.validation.AbstractDeclarativeValidator$MethodWrapper.invoke(AbstractDeclarativeValidator.java:118)
at org.eclipse.xtext.validation.AbstractDeclarativeValidator.internalValidate(AbstractDeclarativeValidator.java:312)
at org.eclipse.xtext.validation.AbstractInjectableValidator.validate(AbstractInjectableValidator.java:71)
at org.eclipse.xtext.validation.CompositeEValidator.validate(CompositeEValidator.java:151)
at org.eclipse.emf.ecore.util.Diagnostician.doValidate(Diagnostician.java:171)
at org.eclipse.emf.ecore.util.Diagnostician.validate(Diagnostician.java:158)
at org.eclipse.emf.ecore.util.Diagnostician.validate(Diagnostician.java:137)
at org.eclipse.xtext.validation.CancelableDiagnostician.validate(CancelableDiagnostician.java:39)
at org.eclipse.emf.ecore.util.Diagnostician.validate(Diagnostician.java:120)
at org.eclipse.xtext.validation.ResourceValidatorImpl.validate(ResourceValidatorImpl.java:146)
at org.eclipse.xtext.validation.ResourceValidatorImpl.validate(ResourceValidatorImpl.java:124)
at org.eclipse.xtext.validation.ResourceValidatorImpl.validate(ResourceValidatorImpl.java:90)
at org.eclipse.xtext.ui.validation.DefaultResourceUIValidatorExtension.addMarkers(DefaultResourceUIValidatorExtension.java:60)
at org.eclipse.xtext.ui.validation.DefaultResourceUIValidatorExtension.updateValidationMarkers(DefaultResourceUIValidatorExtension.java:46)
at org.eclipse.xtext.builder.builderState.MarkerUpdaterImpl.processDelta(MarkerUpdaterImpl.java:93)
at org.eclipse.xtext.builder.builderState.MarkerUpdaterImpl.updateMarkers(MarkerUpdaterImpl.java:63)
at org.eclipse.xtext.builder.builderState.AbstractBuilderState.updateMarkers(AbstractBuilderState.java:82)
at org.eclipse.xtext.builder.clustering.ClusteringBuilderState.doUpdate(ClusteringBuilderState.java:283)
at org.eclipse.xtext.builder.builderState.AbstractBuilderState.update(AbstractBuilderState.java:116)
at org.eclipse.xtext.builder.impl.XtextBuilder.doBuild(XtextBuilder.java:287)
at org.eclipse.xtext.builder.impl.XtextBuilder.incrementalBuild(XtextBuilder.java:267)
at org.eclipse.xtext.builder.impl.XtextBuilder.build(XtextBuilder.java:161)
at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:734)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:206)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:246)
at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:299)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:302)
at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:358)
at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:381)
at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:143)
at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:241)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)
Regards,
Vladimir
|
|
|
|
|
Re: How to get index of the variable in the text of DSL program? [message #1719791 is a reply to message #1719771] |
Tue, 12 January 2016 05:50 |
|
actually not
@Check
public void checkSomeething(State state) {
if (true /*..*/) {
warning("SomeMessage",
state,
CasualIntellectPackage::eINSTANCE.state_name,
index,
"IssueCode","Data1","Data2","Data3");
}
//or
warning("SomeMessage",
state,
CasualIntellectPackage::eINSTANCE.state_name, //not sure about the capitallity of the letters
index);
}
}
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02508 seconds