Skip to main content



      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 14:00 Go to next message
Eclipse UserFriend
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 09:56 Go to previous messageGo to next message
Eclipse UserFriend
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 10:36 Go to previous message
Eclipse UserFriend
hi, i did not understand what your problem was in the first place. what was not working?
Previous Topic:Guice configuration error
Next Topic:How to attatch Comments to the semantic model and serialize them
Goto Forum:
  


Current Time: Sat Mar 22 09:23:17 EDT 2025

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

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

Back to the top