Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » [Xtext 2.1.1] interface segregation
[Xtext 2.1.1] interface segregation [message #761143] Tue, 06 December 2011 00:50 Go to next message
Max Goltzsche is currently offline Max GoltzscheFriend
Messages: 40
Registered: November 2011
Member
Hey,

I'm facing some problems with interface segregation. If one defines interfaces as unused grammar rules syntactic predicates / backtracking also has to be used. This enlarges the generated code of ...ui.contentassist.antlr.internal.InternalSomeViewLanguageParser until that error comes up: "The code for the static initializer is exceeding the 65535 bytes limit".
The following sample grammar works but the error occures after adding a few more interfaces.
grammar org.someViewLanguage.SomeViewLanguage with org.eclipse.xtext.xbase.Xbase

generate someViewLanguage "http://www.someViewLanguage.org/SomeViewLanguage"

import "http://www.eclipse.org/xtext/xbase/Xbase" as xbase
import "http://www.eclipse.org/xtext/common/JavaVMTypes" as types

View:
	'view' name=ValidID '(' (args+=FullJvmFormalParameter (',' args+=FullJvmFormalParameter)*)? ')' '{'
		elements+=OuterViewElement*
	'}';

OuterViewElement:
	CtrlBlock | CtrlLoop | Text | Button | Table;

CtrlLoop:
	(name=ValidID ':')? 'for' declaredParam=JvmFormalParameter ':' iterable=XExpression
		eachElement=OuterViewElement;
	
CtrlBlock:
	{CtrlBlock}
	(name=ValidID ':')? '{'
		elements+=OuterViewElement*
	'}';

Table:
	(name=ValidID ':')? 'table' declaredParam=JvmFormalParameter ':' iterable=XExpression
	(('label' '=' label=XExpression)? &
	('visible' '=' visible=XExpression)?)
	'{'
		columns+=Column*
	'}';
	
Column:
	{Column}
	(name=ValidID ':')? 'col'
	('visible' '=' visible=XExpression)?
	'{'
		('title' title=OuterViewElement)?
		contents+=OuterViewElement*
	'}';

Text:
	(name=ValidID ':')? 'text'
	(label=XExpression &
	('visible' '=' visible=XExpression)?);

Button:
	(name=ValidID ':')? 'button'
	label=XExpression
	('action' '=' action=XExpression &
	('visible' '=' visible=XExpression)? & 
	('disabled' '=' disabled=XExpression)?);

/*
 * begin cross-cutting interfaces
 */
ViewElement:
	name=ValidID | OuterViewElement | =>(HideableViewElement | =>(=>DeactivatableViewElement | LoopViewElement));
	
LabeledViewElement:
	ViewElement | label=XExpression | Button | Table;
	
HideableViewElement:
	visible=XExpression | Button | Table | Column;

DeactivatableViewElement:
	disabled=XExpression | Button;

LoopViewElement:
	iterable=XExpression declaredParam=JvmFormalParameter | =>(CtrlLoop | Table);
/*
 * end cross-cutting interfaces
 */


Is there a better way to add such rule independent interfaces without generating unused code that produces fatal errors?
I've already split my grammar in a model language and an extending view language but it doesn't make the parser code shorter. I've also tried to set classSplitting = true option in the XtextAntlrGeneratorFragment but I do not see any change. How to minimize the initializer code?

Please help!!!

regards,
Max

[Updated on: Thu, 08 December 2011 19:54]

Report message to a moderator

Re: [Xtext 2.1.1] interface segregation with unused grammar rules [message #761235 is a reply to message #761143] Tue, 06 December 2011 06:48 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3107
Registered: July 2009
Senior Member
Hi Max,

please enable classSplitting in both Antlr fragments in your workflow.
Also note that it's almost ever a good idea to switch to imported
packages if you pollute your grammar to influence the package inference.

Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com

Am 06.12.11 01:50, schrieb Max:
> Hey,
>
> I'm facing some problems with interface segregation. If one defines them
> as unused grammar rules syntactic predicates / backtracking also has to
> be used. This enlarges the generated code of
> ...ui.contentassist.antlr.internal.InternalSomeViewLanguageParser until
> that error comes up: "The code for the static initializer is exceeding
> the 65535 bytes limit".
> The following sample grammar works but the error occures after adding a
> few more interfaces.
> grammar org.someViewLanguage.SomeViewLanguage with
> org.eclipse.xtext.xbase.Xbase
>
> generate someViewLanguage
> "http://www.someViewLanguage.org/SomeViewLanguage"
>
> import "http://www.eclipse.org/xtext/xbase/Xbase" as xbase
> import "http://www.eclipse.org/xtext/common/JavaVMTypes" as types
>
> View:
> 'view' name=ValidID '(' (args+=FullJvmFormalParameter (','
> args+=FullJvmFormalParameter)*)? ')' '{'
> elements+=OuterViewElement*
> '}';
>
> OuterViewElement:
> CtrlBlock | CtrlLoop | Text | Button | Table;
>
> CtrlLoop:
> (name=ValidID ':')? 'for' declaredParam=JvmFormalParameter ':'
> iterable=XExpression
> eachElement=OuterViewElement;
>
> CtrlBlock:
> {CtrlBlock}
> (name=ValidID ':')? '{'
> elements+=OuterViewElement*
> '}';
>
> Table:
> (name=ValidID ':')? 'table' declaredParam=JvmFormalParameter ':'
> iterable=XExpression
> (('label' '=' label=XExpression)? &
> ('visible' '=' visible=XExpression)?)
> '{'
> columns+=Column*
> '}';
>
> Column:
> {Column}
> (name=ValidID ':')? 'col'
> ('visible' '=' visible=XExpression)?
> '{'
> ('title' title=OuterViewElement)?
> contents+=OuterViewElement*
> '}';
>
> Text:
> (name=ValidID ':')? 'text'
> (label=XExpression &
> ('visible' '=' visible=XExpression)?);
>
> Button:
> (name=ValidID ':')? 'button'
> label=XExpression
> ('action' '=' action=XExpression &
> ('visible' '=' visible=XExpression)? & ('disabled' '='
> disabled=XExpression)?);
>
> /*
> * begin cross-cutting interfaces
> */
> ViewElement:
> name=ValidID | OuterViewElement | =>(HideableViewElement |
> =>(=>DeactivatableViewElement | LoopViewElement));
>
> LabeledViewElement:
> ViewElement | label=XExpression | Button | Table;
>
> HideableViewElement:
> visible=XExpression | Button | Table | Column;
>
> DeactivatableViewElement:
> disabled=XExpression | Button;
>
> LoopViewElement:
> iterable=XExpression declaredParam=JvmFormalParameter | =>(CtrlLoop |
> Table);
> /*
> * end cross-cutting interfaces
> */
>
> Is there a better way to add such rule independent interfaces without
> generating unused code that produces fatal errors?
> I've already split my grammar in a model language and an extending view
> language but it doesn't make the parser code shorter. I've also tried to
> set classSplitting = true option in the XtextAntlrGeneratorFragment but
> I do not see any change. How to minimize the initializer code?
>
> Please help!!!
>
> regards,
> Max
Re: [Xtext 2.1.1] interface segregation with unused grammar rules [message #761608 is a reply to message #761235] Tue, 06 December 2011 18:26 Go to previous messageGo to next message
Max Goltzsche is currently offline Max GoltzscheFriend
Messages: 40
Registered: November 2011
Member
Hey Sebastian,

thanks for your reply. I think you meant defining the ecore model by myself and import the package in my grammar?!
I've tried to do this with the above example grammar by with the following steps:
- move the successfully generated ecore model + genmodel into a separate "model" folder like in an EMF-project
- register genmodel and generated EPackage at StandaloneSetup in mwe2 workflow:
        registerGeneratedEPackage = "org.someViewLanguage.someViewLanguage.SomeViewLanguagePackage"
        registerGenModelFile = "platform:/resource/org.someViewLanguage/model/SomeViewLanguage.genmodel"

- in the grammar replace
generate someViewLanguage "http://www.someViewLanguage.org/SomeViewLanguage"
with
import "http://www.someViewLanguage.org/SomeViewLanguage"

- remove all unused rules (last 5) from the grammar

But when I want to generate Xtext Artifacts it throws the following exception that doesn't tell anything:
0 [main] INFO lipse.emf.mwe.utils.StandaloneSetup - Registering platform uri '/home/max/development/emf'
181 [main] INFO lipse.emf.mwe.utils.StandaloneSetup - Adding generated EPackage 'org.someViewLanguage.someViewLanguage.SomeViewLanguagePackage'
269 [main] INFO clipse.emf.mwe.utils.GenModelHelper - Registered GenModel 'http://www.someViewLanguage.org/SomeViewLanguage' from 'platform:/resource/org.someViewLanguage/model/SomeViewLanguage.genmodel'
270 [main] ERROR mf.mwe2.launch.runtime.Mwe2Launcher - Problems instantiating module org.someViewLanguage.GenerateSomeViewLanguage: java.lang.reflect.InvocationTargetException
java.lang.RuntimeException: Problems instantiating module org.someViewLanguage.GenerateSomeViewLanguage: java.lang.reflect.InvocationTargetException
at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:90)
at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:73)
at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:64)
at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:55)
at org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher.run(Mwe2Launcher.java:74)
at org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher.main(Mwe2Launcher.java:35)
Caused by: org.eclipse.emf.common.util.WrappedException: java.lang.reflect.InvocationTargetException
at org.eclipse.emf.mwe2.language.factory.SettingProviderImpl$1$1.setValue(SettingProviderImpl.java:56)
at org.eclipse.emf.mwe2.language.factory.Mwe2ExecutionEngine.internalApplyAssignments(Mwe2ExecutionEngine.java:143)
at org.eclipse.emf.mwe2.language.factory.Mwe2ExecutionEngine.inCase(Mwe2ExecutionEngine.java:114)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.eclipse.xtext.util.PolymorphicDispatcher.invoke(PolymorphicDispatcher.java:291)
at org.eclipse.emf.mwe2.language.factory.Mwe2ExecutionEngine.internalSwitch(Mwe2ExecutionEngine.java:66)
at org.eclipse.emf.mwe2.language.factory.Mwe2ExecutionEngine.internalApplyAssignments(Mwe2ExecutionEngine.java:142)
at org.eclipse.emf.mwe2.language.factory.Mwe2ExecutionEngine.inCase(Mwe2ExecutionEngine.java:114)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.eclipse.xtext.util.PolymorphicDispatcher.invoke(PolymorphicDispatcher.java:291)
at org.eclipse.emf.mwe2.language.factory.Mwe2ExecutionEngine.internalSwitch(Mwe2ExecutionEngine.java:66)
at org.eclipse.emf.mwe2.language.factory.Mwe2ExecutionEngine.inCase(Mwe2ExecutionEngine.java:80)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.eclipse.xtext.util.PolymorphicDispatcher.invoke(PolymorphicDispatcher.java:291)
at org.eclipse.emf.mwe2.language.factory.Mwe2ExecutionEngine.internalSwitch(Mwe2ExecutionEngine.java:66)
at org.eclipse.emf.mwe2.language.factory.Mwe2ExecutionEngine.create(Mwe2ExecutionEngine.java:62)
at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:88)
... 5 more
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.eclipse.emf.mwe2.language.factory.SettingProviderImpl$1$1.setValue(SettingProviderImpl.java:54)
... 30 more
Caused by: java.lang.NullPointerException
at org.eclipse.emf.mwe.utils.GenModelHelper.registerGenModel(GenModelHelper.java:64)
at org.eclipse.emf.mwe.utils.GenModelHelper.registerGenModel(GenModelHelper.java:39)
at org.eclipse.emf.mwe.utils.StandaloneSetup.addRegisterGenModelFile(StandaloneSetup.java:340)
... 35 more

Do you have any idea what I am doing wrong?

regards,
Max

[Updated on: Wed, 07 December 2011 13:40]

Report message to a moderator

Re: [Xtext 2.1.1] interface segregation with unused grammar rules [message #762039 is a reply to message #761608] Wed, 07 December 2011 13:17 Go to previous messageGo to next message
Max Goltzsche is currently offline Max GoltzscheFriend
Messages: 40
Registered: November 2011
Member
The "Xtext Project From Existing Ecore Models"-Wizard also fails with the message "Nullevaluation!".

Anybody any idea? Please help!!!

regards,
Max

[Updated on: Wed, 07 December 2011 13:34]

Report message to a moderator

Re: [Xtext 2.1.1] interface segregation with unused grammar rules [message #762065 is a reply to message #762039] Wed, 07 December 2011 13:53 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3107
Registered: July 2009
Senior Member
Hi Max,

it's hard to provide assistance based on a partial data, e.g. please
provide more information about the workflow, your ecore file (how does
the xmi look like) and the genmodel. did you try to reproduce it with a
minimal example?

Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com

Am 07.12.11 14:17, schrieb Max:
> Anybody any idea? Please help!!!
>
> regards,
> Max
Re: [Xtext 2.1.1] interface segregation with unused grammar rules [message #762104 is a reply to message #762065] Wed, 07 December 2011 14:55 Go to previous messageGo to next message
Max Goltzsche is currently offline Max GoltzscheFriend
Messages: 40
Registered: November 2011
Member
Hey Sebastian,

Everything in this thread is a minimal example but 1st post contained errors and I minimalized it once again with the same result:
grammar org.someViewLanguage.SomeViewLanguage with org.eclipse.xtext.xbase.Xbase

//generate someViewLanguage "http://www.someViewLanguage.org/SomeViewLanguage"

import "http://www.someViewLanguage.org/SomeViewLanguage"
import "http://www.eclipse.org/xtext/xbase/Xbase" as xbase
import "http://www.eclipse.org/xtext/common/JavaVMTypes" as types

View:
	'view' name=ValidID '(' (args+=FullJvmFormalParameter (',' args+=FullJvmFormalParameter)*)? ')' '{'
		elements+=OuterViewElement*
	'}';

OuterViewElement:
	Table;

Table:
	(name=ValidID ':')? 'table' declaredParam=JvmFormalParameter ':' iterable=XExpression
	('label' '=' label=XExpression)?
	'{'
		columns+=Column*
	'}';
	
Column:
	{Column}
	(name=ValidID ':')? 'col' '{'
		('title' title=OuterViewElement)?
		contents+=OuterViewElement*
	'}';

// begin cross-cutting interfaces
/*ViewElement:
	name=ValidID | OuterViewElement | LabeledViewElement | LoopViewElement | Column;
	
LabeledViewElement:
	label=XExpression | Table;

LoopViewElement:
	iterable=XExpression declaredParam=JvmFormalParameter | Table;*/

* I have used the outcommented parts of the grammar to generate the ecore model in a first step

Simply, I created a new Xtext project org.someViewLanguage.SomeViewLanguage with that grammar. Afterwards I perform the steps given in the 3rd post to use a generated epackage in the grammar instead of generating it by
- moving the generated ecore + genmodel from src-gen to src, changing relative references to jvmtypes and xbase to platform:/plugin/...,
- setting some of the classes to interfaces + abstract,
- changing path of the Model Directory in the genmodel from src-gen/... to src/...,
- refreshing and generating the genmodel,
- removing all unused grammar rules used to define the interfaces
- replace generate ... with import .... in the grammar
- add the following to standalone setup of workflow:
registerGeneratedEPackage = "org.someViewLanguage.someViewLanguage.SomeViewLanguagePackage"
registerGenModelFile = "platform:/resource/org.someViewLanguage/model/SomeViewLanguage.genmodel"
But generating Xtext artifacts leads me to the NullPointerException listed in the 3rd post and creating a new Xtext Project from (the just generated and changed) Ecore Model results with the message dialog "Nullevaluation!" in the Wizard and the following exception:
71934 [main] ERROR org.eclipse.xtext.ui.wizard.XtextNewProjectWizard -
java.lang.reflect.InvocationTargetException
at org.eclipse.xtext.ui.wizard.XtextNewProjectWizard$1.run(XtextNewProjectWizard.java:57)
at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:121)
Caused by: EvaluationException : Nullevaluation!
org::eclipse::xtext::xtext::ui::wizard::ecore2xtext::Ecore2Xtext.xpt[2530,21] on line 73 'needsDispatcherRule()'
org::eclipse::xtext::xtext::ui::wizard::ecore2xtext::Ecore2Xtext.xpt[997,89] on line 22 'EXPAND subClassDispatcherRule FOREACH allDispatcherRuleClasses().remove(rootElementClass)'
org::eclipse::xtext::xtext::ui::wizard::ecore2xtext::Ecore2XtextDslProject.xpt[748,27] on line 18 'EXPAND Ecore2Xtext::grammar'

at org.eclipse.internal.xpand2.ast.IfStatement.evaluateInternal(IfStatement.java:88)
at org.eclipse.internal.xpand2.ast.Statement.evaluate(Statement.java:41)
at org.eclipse.internal.xpand2.ast.AbstractDefinition.evaluate(AbstractDefinition.java:180)
at org.eclipse.internal.xpand2.ast.ExpandStatement.invokeDefinition(ExpandStatement.java:246)
at org.eclipse.internal.xpand2.ast.ExpandStatement.evaluateInternal(ExpandStatement.java:191)
at org.eclipse.internal.xpand2.ast.Statement.evaluate(Statement.java:41)
at org.eclipse.internal.xpand2.ast.FileStatement.evaluateInternal(FileStatement.java:86)
at org.eclipse.internal.xpand2.ast.Statement.evaluate(Statement.java:41)
at org.eclipse.internal.xpand2.ast.AbstractDefinition.evaluate(AbstractDefinition.java:180)
at org.eclipse.internal.xpand2.ast.ExpandStatement.invokeDefinition(ExpandStatement.java:246)
at org.eclipse.internal.xpand2.ast.ExpandStatement.evaluateInternal(ExpandStatement.java:226)
at org.eclipse.internal.xpand2.ast.Statement.evaluate(Statement.java:41)
at org.eclipse.internal.xpand2.ast.AbstractDefinition.evaluate(AbstractDefinition.java:180)
at org.eclipse.xpand2.XpandFacade.evaluate2(XpandFacade.java:62)
at org.eclipse.xpand2.XpandFacade.evaluate(XpandFacade.java:43)
at org.eclipse.xtext.xtext.ui.wizard.project.XtextProjectCreator.createProject(XtextProjectCreator.java:259)
at org.eclipse.xtext.xtext.ui.wizard.project.XtextProjectCreator.createDslProject(XtextProjectCreator.java:155)
at org.eclipse.xtext.xtext.ui.wizard.project.XtextProjectCreator.execute(XtextProjectCreator.java:94)
at org.eclipse.ui.actions.WorkspaceModifyOperation$1.run(WorkspaceModifyOperation.java:106)
at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2344)
at org.eclipse.ui.actions.WorkspaceModifyOperation.run(WorkspaceModifyOperation.java:118)
at org.eclipse.xtext.ui.wizard.XtextNewProjectWizard.doFinish(XtextNewProjectWizard.java:82)
at org.eclipse.xtext.ui.wizard.XtextNewProjectWizard$1.run(XtextNewProjectWizard.java:54)
... 1 more

...so that a new xtext project from my existing Ecore Model cannot be created.

My generated and changed Ecore model from the example grammar looks as follows:
<?xml version="1.0" encoding="UTF-8"?>
<ecore:EPackage xmi:version="2.0"
    xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="someViewLanguage"
    nsURI="http://www.someViewLanguage.org/SomeViewLanguage" nsPrefix="someViewLanguage">
  <eClassifiers xsi:type="ecore:EClass" name="View">
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="name" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
    <eStructuralFeatures xsi:type="ecore:EReference" name="args" upperBound="-1" eType="ecore:EClass platform:/plugin/org.eclipse.xtext.common.types/model/JavaVMTypes.ecore#//JvmFormalParameter"
        containment="true"/>
    <eStructuralFeatures xsi:type="ecore:EReference" name="elements" upperBound="-1"
        eType="#//OuterViewElement" containment="true"/>
  </eClassifiers>
  <eClassifiers xsi:type="ecore:EClass" name="OuterViewElement" abstract="true" interface="true"
      eSuperTypes="#//ViewElement"/>
  <eClassifiers xsi:type="ecore:EClass" name="Table" eSuperTypes="#//OuterViewElement #//LabeledViewElement #//LoopViewElement">
    <eStructuralFeatures xsi:type="ecore:EReference" name="columns" upperBound="-1"
        eType="#//Column" containment="true"/>
  </eClassifiers>
  <eClassifiers xsi:type="ecore:EClass" name="Column" eSuperTypes="#//ViewElement">
    <eStructuralFeatures xsi:type="ecore:EReference" name="title" eType="#//OuterViewElement"
        containment="true"/>
    <eStructuralFeatures xsi:type="ecore:EReference" name="contents" upperBound="-1"
        eType="#//OuterViewElement" containment="true"/>
  </eClassifiers>
  <eClassifiers xsi:type="ecore:EClass" name="ViewElement" abstract="true" interface="true">
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="name" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
  </eClassifiers>
  <eClassifiers xsi:type="ecore:EClass" name="LabeledViewElement" abstract="true"
      interface="true" eSuperTypes="#//ViewElement">
    <eStructuralFeatures xsi:type="ecore:EReference" name="label" eType="ecore:EClass platform:/plugin/org.eclipse.xtext.xbase/model/Xbase.ecore#//XExpression"
        containment="true"/>
  </eClassifiers>
  <eClassifiers xsi:type="ecore:EClass" name="LoopViewElement" abstract="true" interface="true"
      eSuperTypes="#//ViewElement">
    <eStructuralFeatures xsi:type="ecore:EReference" name="iterable" eType="ecore:EClass platform:/plugin/org.eclipse.xtext.xbase/model/Xbase.ecore#//XExpression"
        containment="true"/>
    <eStructuralFeatures xsi:type="ecore:EReference" name="declaredParam" eType="ecore:EClass platform:/plugin/org.eclipse.xtext.common.types/model/JavaVMTypes.ecore#//JvmFormalParameter"
        containment="true"/>
  </eClassifiers>
</ecore:EPackage>


Help please! That cannot be that difficult. I would like to understand my mistake.

regards,
Max

[Updated on: Wed, 07 December 2011 15:00]

Report message to a moderator

Re: [Xtext 2.1.1] interface segregation with unused grammar rules [message #762207 is a reply to message #762104] Wed, 07 December 2011 17:41 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3107
Registered: July 2009
Senior Member
Max,

the workflow would be helpful. Do you use scanClasspath=true in the
standalone setup?

Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com

Am 07.12.11 15:55, schrieb Max:
> Hey Sebastian,
>
> Everything in this thread is a minimal example but 1st post contained
> errors and I minimalized it once again with the same result:
> grammar org.someViewLanguage.SomeViewLanguage with
> org.eclipse.xtext.xbase.Xbase
>
> //generate someViewLanguage
> "http://www.someViewLanguage.org/SomeViewLanguage"
>
> import "http://www.someViewLanguage.org/SomeViewLanguage"
> import "http://www.eclipse.org/xtext/xbase/Xbase" as xbase
> import "http://www.eclipse.org/xtext/common/JavaVMTypes" as types
>
> View:
> 'view' name=ValidID '(' (args+=FullJvmFormalParameter (','
> args+=FullJvmFormalParameter)*)? ')' '{'
> elements+=OuterViewElement*
> '}';
>
> OuterViewElement:
> Table;
>
> Table:
> (name=ValidID ':')? 'table' declaredParam=JvmFormalParameter ':'
> iterable=XExpression
> ('label' '=' label=XExpression)?
> '{'
> columns+=Column*
> '}';
>
> Column:
> {Column}
> (name=ValidID ':')? 'col' '{'
> ('title' title=OuterViewElement)?
> contents+=OuterViewElement*
> '}';
>
> // begin cross-cutting interfaces
> /*ViewElement:
> name=ValidID | OuterViewElement | LabeledViewElement | LoopViewElement |
> Column;
>
> LabeledViewElement:
> label=XExpression | Table;
>
> LoopViewElement:
> iterable=XExpression declaredParam=JvmFormalParameter | Table;*/
> * I have used the outcommented parts of the grammar to generate the
> ecore model in a first step
>
> Simply, I created a new Xtext project
> org.someViewLanguage.SomeViewLanguage with that grammar. Afterwards I
> perform the steps given in the 3rd post to use a generated epackage in
> the grammar instead of generating it by
> - moving the generated ecore + genmodel from src-gen to src, changing
> relative references to jvmtypes and xbase to platform:/plugin/...,
> - setting some of the classes to interfaces + abstract,
> - changing path of the Model Directory in the genmodel from src-gen/...
> to src/...,
> - refreshing and generating the genmodel,
> - removing all unused grammar rules used to define the interfaces
> - replace generate ... with import ....
> But generating Xtext artifacts leads me to the NullPointerException
> listed in the 3rd post and creating a new Xtext Project from (the just
> generated and changed) Ecore Model results with the message dialog
> "Nullevaluation!" in the Wizard and the following exception:
> 71934 [main] ERROR org.eclipse.xtext.ui.wizard.XtextNewProjectWizard -
> java.lang.reflect.InvocationTargetException
> at
> org.eclipse.xtext.ui.wizard.XtextNewProjectWizard$1.run(XtextNewProjectWizard.java:57)
>
> at
> org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:121)
>
> Caused by: EvaluationException : Nullevaluation!
> org::eclipse::xtext::xtext::ui::wizard::ecore2xtext::Ecore2Xtext.xpt[2530,21]
> on line 73 'needsDispatcherRule()'
> org::eclipse::xtext::xtext::ui::wizard::ecore2xtext::Ecore2Xtext.xpt[997,89]
> on line 22 'EXPAND subClassDispatcherRule FOREACH
> allDispatcherRuleClasses().remove(rootElementClass)'
> org::eclipse::xtext::xtext::ui::wizard::ecore2xtext::Ecore2XtextDslProject.xpt[748,27]
> on line 18 'EXPAND Ecore2Xtext::grammar'
>
> at
> org.eclipse.internal.xpand2.ast.IfStatement.evaluateInternal(IfStatement.java:88)
>
> at org.eclipse.internal.xpand2.ast.Statement.evaluate(Statement.java:41)
> at
> org.eclipse.internal.xpand2.ast.AbstractDefinition.evaluate(AbstractDefinition.java:180)
>
> at
> org.eclipse.internal.xpand2.ast.ExpandStatement.invokeDefinition(ExpandStatement.java:246)
>
> at
> org.eclipse.internal.xpand2.ast.ExpandStatement.evaluateInternal(ExpandStatement.java:191)
>
> at org.eclipse.internal.xpand2.ast.Statement.evaluate(Statement.java:41)
> at
> org.eclipse.internal.xpand2.ast.FileStatement.evaluateInternal(FileStatement.java:86)
>
> at org.eclipse.internal.xpand2.ast.Statement.evaluate(Statement.java:41)
> at
> org.eclipse.internal.xpand2.ast.AbstractDefinition.evaluate(AbstractDefinition.java:180)
>
> at
> org.eclipse.internal.xpand2.ast.ExpandStatement.invokeDefinition(ExpandStatement.java:246)
>
> at
> org.eclipse.internal.xpand2.ast.ExpandStatement.evaluateInternal(ExpandStatement.java:226)
>
> at org.eclipse.internal.xpand2.ast.Statement.evaluate(Statement.java:41)
> at
> org.eclipse.internal.xpand2.ast.AbstractDefinition.evaluate(AbstractDefinition.java:180)
>
> at org.eclipse.xpand2.XpandFacade.evaluate2(XpandFacade.java:62)
> at org.eclipse.xpand2.XpandFacade.evaluate(XpandFacade.java:43)
> at
> org.eclipse.xtext.xtext.ui.wizard.project.XtextProjectCreator.createProject(XtextProjectCreator.java:259)
>
> at
> org.eclipse.xtext.xtext.ui.wizard.project.XtextProjectCreator.createDslProject(XtextProjectCreator.java:155)
>
> at
> org.eclipse.xtext.xtext.ui.wizard.project.XtextProjectCreator.execute(XtextProjectCreator.java:94)
>
> at
> org.eclipse.ui.actions.WorkspaceModifyOperation$1.run(WorkspaceModifyOperation.java:106)
>
> at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2344)
> at
> org.eclipse.ui.actions.WorkspaceModifyOperation.run(WorkspaceModifyOperation.java:118)
>
> at
> org.eclipse.xtext.ui.wizard.XtextNewProjectWizard.doFinish(XtextNewProjectWizard.java:82)
>
> at
> org.eclipse.xtext.ui.wizard.XtextNewProjectWizard$1.run(XtextNewProjectWizard.java:54)
>
> ... 1 more
>
> ...so that a new xtext project from my existing Ecore Model cannot be
> created.
>
> My generated and changed Ecore model from the example grammar looks as
> follows:
> <?xml version="1.0" encoding="UTF-8"?>
> <ecore:EPackage xmi:version="2.0"
> xmlns:xmi="http://www.omg.org/XMI"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="someViewLanguage"
> nsURI="http://www.someViewLanguage.org/SomeViewLanguage"
> nsPrefix="someViewLanguage">
> <eClassifiers xsi:type="ecore:EClass" name="View">
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="name"
> eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
> <eStructuralFeatures xsi:type="ecore:EReference" name="args"
> upperBound="-1" eType="ecore:EClass
> platform:/plugin/org.eclipse.xtext.common.types/model/JavaVMTypes.ecore#//JvmFormalParameter"
>
> containment="true"/>
> <eStructuralFeatures xsi:type="ecore:EReference" name="elements"
> upperBound="-1"
> eType="#//OuterViewElement" containment="true"/>
> </eClassifiers>
> <eClassifiers xsi:type="ecore:EClass" name="OuterViewElement"
> abstract="true" interface="true"
> eSuperTypes="#//ViewElement"/>
> <eClassifiers xsi:type="ecore:EClass" name="Table"
> eSuperTypes="#//OuterViewElement #//LabeledViewElement #//LoopViewElement">
> <eStructuralFeatures xsi:type="ecore:EReference" name="columns"
> upperBound="-1"
> eType="#//Column" containment="true"/>
> </eClassifiers>
> <eClassifiers xsi:type="ecore:EClass" name="Column"
> eSuperTypes="#//ViewElement">
> <eStructuralFeatures xsi:type="ecore:EReference" name="title"
> eType="#//OuterViewElement"
> containment="true"/>
> <eStructuralFeatures xsi:type="ecore:EReference" name="contents"
> upperBound="-1"
> eType="#//OuterViewElement" containment="true"/>
> </eClassifiers>
> <eClassifiers xsi:type="ecore:EClass" name="ViewElement" abstract="true"
> interface="true">
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="name"
> eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
> </eClassifiers>
> <eClassifiers xsi:type="ecore:EClass" name="LabeledViewElement"
> abstract="true"
> interface="true" eSuperTypes="#//ViewElement">
> <eStructuralFeatures xsi:type="ecore:EReference" name="label"
> eType="ecore:EClass
> platform:/plugin/org.eclipse.xtext.xbase/model/Xbase.ecore#//XExpression"
> containment="true"/>
> </eClassifiers>
> <eClassifiers xsi:type="ecore:EClass" name="LoopViewElement"
> abstract="true" interface="true"
> eSuperTypes="#//ViewElement">
> <eStructuralFeatures xsi:type="ecore:EReference" name="iterable"
> eType="ecore:EClass
> platform:/plugin/org.eclipse.xtext.xbase/model/Xbase.ecore#//XExpression"
> containment="true"/>
> <eStructuralFeatures xsi:type="ecore:EReference" name="declaredParam"
> eType="ecore:EClass
> platform:/plugin/org.eclipse.xtext.common.types/model/JavaVMTypes.ecore#//JvmFormalParameter"
>
> containment="true"/>
> </eClassifiers>
> </ecore:EPackage>
>
> Help please! That cannot be that difficult. I would like to understand
> my mistake.
>
> regards,
> Max
Re: [Xtext 2.1.1] interface segregation with unused grammar rules [message #762399 is a reply to message #762207] Thu, 08 December 2011 01:52 Go to previous messageGo to next message
Max Goltzsche is currently offline Max GoltzscheFriend
Messages: 40
Registered: November 2011
Member
yes, I use scanClassPath = true.

complete workflow file (xtext 2.1.1 default, with generated EPackages registered):
module org.someViewLanguage.GenerateSomeViewLanguage

import org.eclipse.emf.mwe.utils.*
import org.eclipse.xtext.generator.*
import org.eclipse.xtext.ui.generator.*

var grammarURI = "classpath:/org/someViewLanguage/SomeViewLanguage.xtext"
var file.extensions = "view"
var projectName = "org.someViewLanguage"
var runtimeProject = "../${projectName}"

Workflow {
    bean = StandaloneSetup {
        scanClassPath = true
        platformUri = "${runtimeProject}/.."
        registerGeneratedEPackage = "org.someViewLanguage.someViewLanguage.SomeViewLanguagePackage"
        registerGenModelFile = "platform:/resource/${projectName}/model/SomeViewLanguage.genmodel"
        registerGeneratedEPackage = "org.eclipse.xtext.xbase.XbasePackage"
        registerGenModelFile = "platform:/resource/org.eclipse.xtext.xbase/model/Xbase.genmodel"
    }

    component = DirectoryCleaner {
        directory = "${runtimeProject}/src-gen"
    }

    component = DirectoryCleaner {
        directory = "${runtimeProject}.ui/src-gen"
    }

    component = Generator {
        pathRtProject = runtimeProject
        pathUiProject = "${runtimeProject}.ui"
        pathTestProject = "${runtimeProject}.tests"
        projectNameRt = projectName
        projectNameUi = "${projectName}.ui"
        language = {
            uri = grammarURI
            fileExtensions = file.extensions

            // Java API to access grammar elements (required by several other fragments)
            fragment = grammarAccess.GrammarAccessFragment {}

            // generates Java API for the generated EPackages
            fragment = ecore.EcoreGeneratorFragment {
            // referencedGenModels = "
            //  platform:/resource/org.eclipse.xtext.xbase/model/Xbase.genmodel,
            //  platform:/resource/org.eclipse.xtext.common.types/model/JavaVMTypes.genmodel
            // "
            }

            // Serializer 2.0
            fragment = serializer.SerializerFragment {
            	generateStub = false
            }
            
            // the serialization component (1.0)
            // fragment = parseTreeConstructor.ParseTreeConstructorFragment {}

            // a custom ResourceFactory for use with EMF
            fragment = resourceFactory.ResourceFactoryFragment {
                fileExtensions = file.extensions
            }

            // The antlr parser generator fragment.
            fragment = parser.antlr.XtextAntlrGeneratorFragment {
            //  options = {
            //      backtrack = true
            //  }
            }

            // java-based API for validation
            fragment = validation.JavaValidatorFragment {
            //    composedCheck = "org.eclipse.xtext.validation.ImportUriValidator"
            //    composedCheck = "org.eclipse.xtext.validation.NamesAreUniqueValidator"
            }

            // scoping and exporting API
            // fragment = scoping.ImportURIScopingFragment {}
            // fragment = exporting.SimpleNamesFragment {}

            // scoping and exporting API
            fragment = scoping.ImportNamespacesScopingFragment {}
            fragment = exporting.QualifiedNamesFragment {}
            fragment = builder.BuilderIntegrationFragment {}

            // generator API
            fragment = generator.GeneratorFragment {
                generateMwe = false
                generateJavaMain = false
            }

            // formatter API
            fragment = formatting.FormatterFragment {}

            // labeling API
            fragment = labeling.LabelProviderFragment {}

            // outline API
            fragment = outline.OutlineTreeProviderFragment {}
            fragment = outline.QuickOutlineFragment {}

            // quickfix API
            fragment = quickfix.QuickfixProviderFragment {}

            // content assist API
            fragment = contentAssist.JavaBasedContentAssistFragment {}

            // generates a more lightweight Antlr parser and lexer tailored for content assist
            fragment = parser.antlr.XtextAntlrUiGeneratorFragment {}

            // generates junit test support classes into Generator#pathTestProject
            fragment = junit.Junit4Fragment {}

            // project wizard (optional)
            // fragment = projectWizard.SimpleProjectWizardFragment {
            //      generatorProjectName = "${projectName}"
            //      modelFileExtension = file.extensions
            // }

            // rename refactoring
            fragment = refactoring.RefactorElementNameFragment {}

            // provides the necessary bindings for java types integration
            fragment = types.TypesGeneratorFragment {}

            // generates the required bindings only if the grammar inherits from Xbase
            fragment = xbase.XbaseGeneratorFragment {}

            // provides a preference page for template proposals
            fragment = templates.CodetemplatesGeneratorFragment {}

            // provides a compare view
            fragment = compare.CompareFragment {
                 fileExtensions = file.extensions
            }

        }
    }
}

[Updated on: Thu, 08 December 2011 15:03]

Report message to a moderator

Re: [Xtext 2.1.1] interface segregation with unused grammar rules [message #762732 is a reply to message #762399] Thu, 08 December 2011 15:02 Go to previous messageGo to next message
Max Goltzsche is currently offline Max GoltzscheFriend
Messages: 40
Registered: November 2011
Member
Hey again,

Additionally, I've found two more possible solutions in this blog and the first comment's link: http://christiandietrich.wordpress.com/2011/07/22/customizing-xtext-metamodel-inference-using-xtend2/, http://www.slideshare.net/meysholdt/codegeneration-goodies.
But the 2nd solution (Generation Gap Pattern with Ecore Model, given in lwc11, 7.5.5) doesn't work for me. Although I create e.g. a TableCustom / TableImplCustom class extending Table / TableImpl it is not used in the SomeViewLanguageFactory.
What would I have to change in the workflow above to let the SomeViewLanguageFactory create my extended types disregarded from
registerGeneratedEPackage = "org.someViewLanguage.someViewLanguage.SomeViewLanguagePackage"
registerGenModelFile = "platform:/resource/${projectName}/model/SomeViewLanguage.genmodel"?
This may be another question but the same problem. A solution for my last question would also be useful.

regards,
Max

[Updated on: Thu, 08 December 2011 17:08]

Report message to a moderator

Re: [Xtext 2.1.1] interface segregation with unused grammar rules [message #763515 is a reply to message #762732] Fri, 09 December 2011 22:32 Go to previous message
Max Goltzsche is currently offline Max GoltzscheFriend
Messages: 40
Registered: November 2011
Member
I don't get it. Of course, I can import generated packages and genmodels in my language but since I create a reference to another ecore model's type it throws a NPE.

Help, please!!!

regards,
Max
Previous Topic:content assist across files
Next Topic:how to override XbaseCompiler
Goto Forum:
  


Current Time: Wed Apr 08 19:15:56 GMT 2020

Powered by FUDForum. Page generated in 0.01821 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top