Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » PROBLEM: JvmTypeReference to Enum within a class does NOT work
icon4.gif  PROBLEM: JvmTypeReference to Enum within a class does NOT work [message #744098] Fri, 21 October 2011 23:31 Go to next message
Erik  is currently offline Erik Friend
Messages: 3
Registered: October 2011
Junior Member
I have the following (partly) grammar:


Import:
	'import' importedNamespace=QualifiedNameWithWildCard ';'
;

QualifiedNameWithWildCard:
	QualifiedName ('.' '*')?
;

Attribute:
	name = ID ':' type = JvmTypeReference ';'
;


It accepts the creation of an attribute, but there is a problem with the JvmTypeReference to an enum. Referring to an enum that is in a file of its own works fine, after importing it. But when trying to refer to an enum within an (abstract) class, both public does not work.

Example Code:
AbstractClass.java does NOT work
public abstract class AbstractClass {
	
	public enum InnerEnum{
		One(1),
		Two(2)

		private int number = -1;
		private InnerEnum(int code){
			this.number = code;
		}

		public int getNumber(){
			return number;
		}
	}
}


and this DOES work:
InnerEnum.java
public enum InnerEnum{
	One(1),
	Two(2)

	private int number = -1;
	private InnerEnum(int code){
		this.number = code;
	}

	public int getNumber(){
		return number;
	}
}


How can I change my syntax to allow the InnerEnum to be accepted as the type for the Attribute?

Thanks a lot,
Erik

[Updated on: Fri, 21 October 2011 23:45]

Report message to a moderator

Re: PROBLEM: JvmTypeReference to Enum within a class [message #744102 is a reply to message #744098] Fri, 21 October 2011 23:33 Go to previous messageGo to next message
Erik  is currently offline Erik Friend
Messages: 3
Registered: October 2011
Junior Member
It did not allow me to add the import links, because I did not yet post 5 messages, but I have these two lines in my grammar:
import "http :// www . eclipse .org / xtext / common / JavaVMTypes" as types
import "http :// www . eclipse .org / emf / 2002 / Ecore" as ecore

Without the spaces of course.

[Updated on: Fri, 21 October 2011 23:33]

Report message to a moderator

Re: PROBLEM: JvmTypeReference to Enum within a class [message #744764 is a reply to message #744102] Sat, 22 October 2011 10:16 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

how does your import look like?

aimport like

import org.eclipse.xtext.example.domainmodel.AbstractClass$InnerEnum

attr : AbstractClass$InnerEnum


works for me

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: PROBLEM: JvmTypeReference to Enum within a class [message #748103 is a reply to message #744764] Mon, 24 October 2011 13:44 Go to previous message
Erik  is currently offline Erik Friend
Messages: 3
Registered: October 2011
Junior Member
Ah thanks a lot. That works!

The $ feels slightly cumbersome and counter intuitive though, just for my understanding, why isn't this possible?
import org.eclipse.xtext.example.domainmodel.AbstractClass.InnerEnum

attr : InnerEnum


Like it would be in java.

Anyway, thanks again!
Previous Topic:Matching braces in comments
Next Topic:Xbase - Custom XVariableDeclaration
Goto Forum:
  


Current Time: Wed Apr 24 18:10:12 GMT 2024

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

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

Back to the top