Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Unexpected name generation of the Activator of the UI project in Xtext
Unexpected name generation of the Activator of the UI project in Xtext [message #1742115] Wed, 31 August 2016 14:19
Cornelius Mising name is currently offline Cornelius Mising nameFriend
Messages: 4
Registered: October 2011
Junior Member
Hello,

I recognized a strange or even unexpected generation of the name of the UI Activator class during a mwe2 launch.

My setting is as follows:

My language project is located in a folder called 'example.lang'. I've also an IDE and UI project: 'example.lang.ide' and 'example.lang.ui'. My workflow file is in src/java/main/com/mydomain/lang/GenerateExample.mwe2 and looks like this:

module com.mydomain.lang.GenerateExample

import org.eclipse.xtext.xtext.generator.*
import org.eclipse.xtext.xtext.generator.model.project.*

var rootPath = ".."

Workflow {
	
	component = XtextGenerator {
		configuration = {
			project = StandardProjectConfig {
				baseName = "example.lang"
				rootPath = rootPath
				mavenLayout = true
				eclipsePlugin = {
					enabled = true
				}
				createEclipseMetaData = true
			}
			code = {
				encoding = "UTF-8"
				fileHeader = "/*\n * generated by Xtext \${version}\n */"
			}
		}
		language = StandardLanguage {
			name = "com.mydomain.lang.Example"
			fileExtensions = "example"

			serializer = {
				generateStub = false
			}
			validator = {
				// composedCheck = "org.eclipse.xtext.validation.NamesAreUniqueValidator"
			}
		}
	}
}


My grammar definition is in src/main/java/com/mydomain/lang/Example.xtext.

The mwe2 workflow executes without any problems. But one thing is unexpected: Each class is in a package com.mydomain.lang.* despite the Activator class in the UI project: It is located in src/main/xtext-gen/example/lang/ui/internal/ and has the name 'LangActivator.java'.

I took a look at the Xtext code and it turned out that the following method org.eclipse.xtext.xtexst.generator.XtextGeneratorNaming#getEclipsePluginActivator uses the property 'name' of the eclipse plugin project config (with relies on 'basename') to determine the name of the Activator class:

public TypeReference getEclipsePluginActivator() {
    TypeReference _xblockexpression = null;
    {
      IBundleProjectConfig _eclipsePlugin = this.projectConfig.getEclipsePlugin();
      final String pluginName = _eclipsePlugin.getName();
      if ((pluginName == null)) {
        return null;
      }
      String activatorName = pluginName.replaceAll("\\.ui$", "");
      int _lastIndexOf = activatorName.lastIndexOf(".");
      int _plus = (_lastIndexOf + 1);
      String _substring = activatorName.substring(_plus);
      String _firstUpper = StringExtensions.toFirstUpper(_substring);
      String _plus_1 = (_firstUpper + "Activator");
      activatorName = _plus_1;
      _xblockexpression = new TypeReference((pluginName + ".internal"), activatorName);
    }
    return _xblockexpression;
  }


That is quite surprising because it depends on the basename in the workflow configuration. All other resources are generated by using this pattern:

String _eclipsePluginBasePackage = this.getEclipsePluginBasePackage(grammar);
String _simpleName = GrammarUtil.getSimpleName(grammar);
String _plus = (_simpleName + "<ClassNameSuffix>");
return new TypeReference(_eclipsePluginBasePackage, _plus);


In the case you create a Xtext project with the Eclipse wizard everything is fine because the basename is the same as the base package. But if you choose another project setting it differs. So, i suppose that this is some kind of a bug and the getEclipsePluginActivator() method should look like this:

public TypeReference getEclipsePluginActivator(final Grammar grammar) {
	String _eclipsePluginBasePackage = this.getEclipsePluginBasePackage(grammar) + ".internal";
	String _simpleName = GrammarUtil.getSimpleName(grammar);
	String _plus = (_simpleName + "Activator");
	return new TypeReference(_eclipsePluginBasePackage, _plus);
}


Or is there any reason why the generation of the Activator name differs from the generation of the other resource names?

Cornelius
Previous Topic:Xtext grammar related query
Next Topic:news.eclipse.org is shutting down.
Goto Forum:
  


Current Time: Fri Mar 29 08:15:38 GMT 2024

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

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

Back to the top