I am working in project generated by the xtext project wizard.
On the the Internet there is a lot of examples but I cannot see in which project and the package name the code formatting class must be defined.
Must the class also be register?
PS my Java skills is not very good.
You can add a
formatter = {
generateStub = true
}
To the Workflow
Related
I have an XText project setup with multiple grammars and am able to edit each grammar with cross-linking within the IDE generated by the mwe2 workflow. When I run the example web editor, the first grammar defined in the mwe2 workflow functions correctly.
If I change the the generated index.html to use one of the alternate grammar extensions the editor no longer functions, and I get an error message that looks like:
Xtext service 'occurrences' failed: Unable to identify the Xtext
language for resource 3c05cdd1.ed
I'd like to understand what is wrong in order to better understand how I can begin minimal integration of editors for the grammars into our existing console.
Thanks!
Pierre Padovani
P.S. I've posted this same question on the Eclipse Community Forums, but my post seems to be stuck in a moderator queue.
Having found the thread which #ppadovani mentions, it seems that the only necessary change is to ignore all the generated Servlet.xtend files except the one whose grammar is working.
In that one which works, it is necessary to initialise run the WebSetup for the other languages.
override init() {
super.init()
// call createInjectorAndDoEMFRegistration for each WebSetup
new DerivedDslWebSetup().createInjectorAndDoEMFRegistration
// keep the rest as-is
val injector = new CoreDslWebSetup().createInjectorAndDoEMFRegistration()
disposableRegistry = injector.getInstance(DisposableRegistry)
}
Reference: https://www.eclipse.org/forums/index.php?t=msg&th=1096166&goto=1798287&#msg_1798287
I've got a List of classes I want to send down to a Scala Template in Play! Framework 2.2.3
however I ran into some issues while trying to do so.
The class I want the list to contain is an arbitrary class type that comes from a package outside of my workspace, but not natively from Java. See the picture below.
Note: I do not have a project/Build.scala file.
The above image represents the first line in my scala template, I have tried to use #import as well (#import com.***.***.type._, com.***.***.type.Version, etc) but to no avail.
This is the error message given to me by Play! Framework.
Is there an issue with the namespacing? Everything works fine when using classes located in my workspace.
The Paths are correct, I've double checked that. For reasons I cannot disclose more code in this region, if more information is required please ask for it and I'll edit the post.
The problem is related to package named type. This word is reserved in Scala as language keyword. You need to escape it like this:
#import List[com.your.package.`type`.Version]
I'm doing a small academic assignment, in which I'm supposed to implement an eclipse plugin for the NuSMV language (a model checking language) using Xtext. The xtext grammar was provided (with some minor bugs).
I've created an Xtext project and called it "smv.project" with language name of "NuSMV" and extension of "*.smv". I've coppied the provided Xtext grammar into smv.project/src/NuSMV.xtext, generated artifacts, and created runtime eclipse. Seems to work fine except those minor bugs (which are originated in the grammar in my opinion).
Now, my next step is to change the default colors in my DSL. Obviously, every user can do that for himself in the eclipse menus when using my plugin, but I wand the DEFAULT color to change. I've read the Xtext documentation for syntax coloring. It was short and had many terms I didn't understand. What I did understand is that there are 2 kinds of syntax coloring in Xtext, Lexical and Semantic. I didn't understand the meaning of each but it seemed to me that Lexical coloring is simpler, so I went for it.
The documentation said that I should implement the interface IHighlightingConfiguration. It showed an example of implementation called DefaultHighlightingConfiguration (full source can be seen here https://github.com/eclipse/xtext/blob/master/plugins/org.eclipse.xtext.ui/src/org/eclipse/xtext/ui/editor/syntaxcoloring/DefaultHighlightingConfiguration.java). I've coppied this implementation into my project, to smv.project.ui/src/smv.project.ui.editor.syntaxcoloring. Of course, I changed the "package" line in the beginning of the file.
I've changed all red values to 255 to see difference.
I've generated the artifacts again, created runtime eclipse, created a *.smv file but the colors were the same.
My guess was that I need to set my new class in some variable or configuration class... I tried searching for "DefaultHighlightingConfiguration" in the example's repository and found out that it's used in the file XtextProposalProvider.java (full source https://github.com/eclipse/xtext/blob/87a6c7dc25074ca4ff28429c059e728ef420b926/plugins/org.eclipse.xtext.xtext.ui/src/org/eclipse/xtext/ui/contentassist/XtextProposalProvider.java) in line 235 - We're overriding getKeywordDisplayString(). So I've went to the already existing NuSMVProposalProvider.java in my repository and tried to add the same lines:
#Override
protected StyledString getKeywordDisplayString(Keyword keyword) {
return stylerFactory.createFromXtextStyle(keyword.getValue(),
defaultLexicalHighlightingConfiguration.keywordTextStyle());
}
Here is my full NuSMVProposalProvider.xtend:
/*
* generated by Xtext
*/
package smv.project.ui.contentassist
import smv.project.ui.contentassist.AbstractNuSMVProposalProvider
import javax.inject.Inject
import org.eclipse.xtext.ui.editor.syntaxcoloring.DefaultHighlightingConfiguration
import org.eclipse.jface.viewers.StyledString
import org.eclipse.xtext.Keyword
/**
* see http://www.eclipse.org/Xtext/documentation.html#contentAssist on how to customize content assistant
*/
class NuSMVProposalProvider extends AbstractNuSMVProposalProvider {
#Inject
private DefaultHighlightingConfiguration defaultLexicalHighlightingConfiguration;
#Override
protected StyledString getKeywordDisplayString(Keyword keyword) {
return stylerFactory.createFromXtextStyle(keyword.getValue(),
defaultLexicalHighlightingConfiguration.keywordTextStyle());
}
}
However, the next errors appeared:
"The annotation #Override is disallowed for this location."
"extraneous input 'keyword' expecting ')'"
"mismatched input '{' expecting '=>'"
in the first 3 lines, respectively.
My questions are:
What exactly should I do with my class that implements
IHighlightingConfiguration?
What is Lexical and Semantic highlighing?
Is there something else I need to know for my syntax coloring to work?
Thanks a lot!! :)
Chai
NuSMVProposalProvider wasn't the way to go.
I didn't have to add any code there at all.
What I was looking for was adding the next lines in NuSMVUiModule.java:
public Class<? extends IHighlightingConfiguration> bindIHighlightingConfiguration () {
return DefaultHighlightingConfiguration.class;
}
Thanks everyone for their comments!
Chai
I have a rather silly question. I am using xtext to define a simple dsl and Xpand to generate code.
Now I want to use xpand to read my dsl models and generate code. How can i do that?
I read lot of tutorials saying that I can simple do that by creating a new xtext project from the wizard. Then, among others, the following project will be created:
org.xtext.example.domainmodel.generator.
And inside, the generator looks like this:
src
model (place the dsl model)
templates (place the template for the code generator)
workflow (workflow file)
Then i simple run the workflow and generate the code from the dsl file. That s straightforwards and easy.
My problem is that when I create a new xtext project I dont get the org.xtext.example.domainmodel.generator. project. I only have the following four:
org.xtext.example.domainmodel
org.xtext.example.domainmodel.sdk
org.xtext.example.domainmodel.tests
org.xtext.example.domainmodel.ui
So how can i produce the org.xtext.example.domainmodel.generator file???
Which tutorials do you mean? (links please) And do they really talk about a generator project? Talking about the package org.xtext.example.domainmodel.generator inside the org.xtext.example.domainmodel project is the usual thing.
Probably not relevant to the original person who asked this :) but I had a similar problem and the reason was that in my grammar extended xbase.
When extending xbase building the mwe2 skips the generator stub generation and uses the xbase code generation which is generated instead (the antlr parser, serializer etc.)
I have been using CodeDom to do some code generation. It works great, but I haven't found a way to include the generated source code files in a project. I started using T4 and the T4Toolbox to generate code because it supports integration with project files.
Does anyone know if CodeDom supports this functionality too? I'd consider taking a second look at CodeDom if it only supported this one feature.
Here is an example of how I make a source code file with CodeDom:
protected void CreateSourceFile(CodeCompileUnit codeCompileUnit,
string fileName,
out string fileNameWithExtension)
{
fileNameWithExtension = string.Format("{0}.{1}",
fileName,
CodeProvider.FileExtension);
var indentedTextWriter =
new IndentedTextWriter(new StreamWriter(fileNameWithExtension,
false),
TabString);
CodeProvider.GenerateCodeFromCompileUnit(codeCompileUnit,
indentedTextWriter,
new CodeGeneratorOptions());
indentedTextWriter.Close();
}
That works fine but it just outputs the file to the hard drive somewhere (probably bin folder).
Here is a second example of some code I use with T4, this one specifies the output as part of the project the template is transformed in:
public class RDFSClassGenerator : Generator
{
private readonly string rootNamespace;
private readonly string ontologyLocation;
public RDFSClassGenerator(
string rootNamespace,
string ontologyLocation)
{
this.rootNamespace = rootNamespace;
this.ontologyLocation = ontologyLocation;
}
protected override void RunCore()
{
XElement ontology = XElement.Load(ontologyLocation);
var service = new RDFSGeneratorService(ontology);
foreach (MetaClass metaClass in service.MetaClasses)
{
var rdfsClassTemplate = new RDFSClassTemplate(rootNamespace, metaClass);
rdfsClassTemplate.Output.File = "Domain/" + metaClass.Name + ".cs";
rdfsClassTemplate.Render();
}
}
}
So the T4 code will output the file into the "Domain" folder of my project. But the CodeGen stuff just outputs the file on disk and doesn't update the project file.
Here is a visual:
Yes, it can. Here is how: http://www.olegsych.com/2009/09/t4-and-codedom-better-together/
Short answer is no, but I could be wrong (ever try to prove a negative?)
Your question was a little confusing as CodeDom isn't exactly equitable with T4. T4 templates are a convenient way of generating code files the same way, for example, asp.net generates HTML files, mixing text and code that gets executed to generate a file that is then interpreted by something else (such as a compiler or a browser). CodeDom is usually used to generate assemblies at runtime rather than files, although you can do it (as you have discovered).
While T4 makes it easy to add files to the solution, you can do this with CodeDom as well. I don't believe it supports interaction with the solution directly, but you can manage this using EnvDTE, or the automation model for Visual Studio.
The problem with this is that the automation model isn't easy to work with. EnvDTE is a wrapper around COM classes, which is always fun to code against. Also, you have to be careful when attempting to get the object. The naive implementation will get the object from the first instance of Visual Studio loaded. You have to poll the Running Object Table to find the current instance. Once you have it, you must deal with searching through the dte for the location you're looking for, deal with source control, locked files, etc etc.
Working with it, you start to learn why T4 was created in the first place.
The question you have to ask yourself is, "Does CodeDom give me enough that T4 doesn't to make up for all its shortcomings?"