Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » How to define dsl to call static field constant
How to define dsl to call static field constant [message #1815373] Tue, 01 October 2019 18:00 Go to next message
Dimg Cim is currently offline Dimg CimFriend
Messages: 59
Registered: December 2015
Member
Hello together,

first I have this dsl

Page returns Page:
	{Page}
	'Page' name=ID '{'
               'icon;' icon =XExpression
		'control:' controller=JvmTypeReference
	'}' 
;


How can I define the icon to call a static string field of a class,e.g. FontAwesome.ARROW .

The Result looks like:

Page MyFirstPage{
   icon: UIConstant.ICON_1
  controller: MyFirstPageController
}


I think it is possible, but I haven't any idea to describe this in my xtext dsl.

Best regards
dimg
Re: How to define dsl to call static field constant [message #1815631 is a reply to message #1815373] Mon, 07 October 2019 13:56 Go to previous messageGo to next message
Dimg Cim is currently offline Dimg CimFriend
Messages: 59
Registered: December 2015
Member
FYI, after analyzing the Spray Project, I found this, maybe it is better to set the existing resource file as path indeed of using static constants

URI uri = model.eResource().getURI();
        if (!uri.isPlatformResource()) {
            return;
        }
        final String projectName = uri.segment(1);
        IPath iconFolderPath = new Path(projectName).append("icons");
        IFolder folder = root.getFolder(iconFolderPath);
        if (!folder.exists()) {
            return;
        }
        try {
            folder.accept(new IResourceVisitor() {
                @Override
                public boolean visit(IResource resource) {
                    if (resource instanceof IFile) {
                        IFile file = (IFile) resource;
                        if (validIconFileExtensions.contains(file.getFileExtension())) {
                            final String proposalText = "\"" + file.getFullPath().removeFirstSegments(2).toString() + "\"";
                            final StyledString displayString = new StyledString(file.getFullPath().removeFirstSegments(2).toString());
                            final Image image = getImage(file.getLocation());
                            ICompletionProposal proposal = doCreateProposal(proposalText, displayString, image, 0, context);
                            acceptor.accept(proposal);
                        }
                    }
                    return true;
                }
            });
        } catch (CoreException e) {
            ; // ignore
        }
Re: How to define dsl to call static field constant [message #1815634 is a reply to message #1815631] Mon, 07 October 2019 14:36 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
hi, i did not understand what your problem was in the first place. what was not working?

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Guice configuration error
Next Topic:How to attatch Comments to the semantic model and serialize them
Goto Forum:
  


Current Time: Thu Apr 25 23:24:09 GMT 2024

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

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

Back to the top