Xtext cross-reference across all files in project - eclipse

I am making a very simple DSL with xtext. A project will contain files that either define a message name, or reference to one. I have included a simplified example:
Grammar:
Model:
statements+=(MessageDefinition | MessageUsage)*;
MessageDefinition:
'[MESSAGE_DEF]' name=ID;
MessageUsage:
'[MESSAGE_USAGE]' usage=[MessageDefinition];
File1.ex:
[MESSAGE_DEF] EXAMPLE_1
[MESSAGE_DEF] EXAMPLE_2
[MESSAGE_USAGE] EXAMPLE_1
File2.ex:
[MESSAGE_USAGE] EXAMPLE_2
In this example the cross-reference from EXAMPLE_1 works such that "Open Declaration" on the usage takes me to the definition. However, the cross-reference on EXAMPLE_2 does not work. I think the default scoping rules prevents different files from sharing references.
What do i need to add so that all the files in a project share the same global scope for cross-references?
Additional information:
The option "Build Automatically" is enabled in the runtime project.
The .project file includes a buildCommand for xtextBuilder and a
nature for xtextNature.
I am only attempting to use the IDE
cross-referencing functionality, there is no generation of code.
All of the files in the runtime project exist in the same folder.
The project was created using "Xtext Project" in the standard wizard, I have only edited the grammar from the pre-generated code, everything else is as-per the defaults. I thought I would need to add some custom scoping behaviour/rules to load all files into the global scope, but I am not sure how this is supposed to be done?

it will work fine with your grammar and scoping if you
have build automatically enabled in your runtime workspace
the project you model in has xtext nature and xtext builder enabled (right-click -> configure -> ...)
if it is a java project model files have to reside in a source folder or a package within the source folder

Related

Understanding program organisation and basic terms

I've installed Jaspersoft Studio 6.2.2 in order to edit a couple of existing Jasper reports. Unless I missed something, nowhere in Getting Started documentation do they explain the basic terms specific to this program. They do explain the generic Jasper terms (report, data adapter, field...) but, when it comes to Jaspersoft Studio, they just instruct you to launch wizards and use the defaults. That isn't optimal for me because I prefer to have my work under source control and separated by customer/client rather than having everything together in a local folder within my Windows profile. I also have the impression that they omit stuff because they assume you're familiar with Eclipse (I'm not).
Could you please provide me with a quick overview of the basic terms and some tips about how to use them to effectively organise work:
Workspace
Project
Project Folder
... and some other I might be missing?
My view:
A workspace is a group projects that share some configuration/environment. In project setting, you can use a common workspace configuration or define a project specific configuration.
In java world, e.g. you can define different JDK compatibility per workspace.
In jasper world, e.g. for Chinese projects, you can have projects that all have zh_CN default language set when executing preview. Different fonts might be used in this workspace. No need to set it up for every new project created.
Every workspace has it's own set of data adapters and JRS server connections.
I usually have sources under "Project folder", not in workspace folder. I just import a project into the workspace (do not copy).
BTW. One project can be in multiple workspaces.

What are .files in eclipse

Every projects in eclipse has 4 .files(.settings,.classpath,.cprojects and .projects).
Can anyone explain me why are these files generated and what happens if I delete these 4 files. I have deleted these files from one app which resulted in changing the name of app.
Eclipse is a runtime environment for plugins. Virtually everything you see in Eclipse is the result of plugins installed on Eclipse, rather than Eclipse itself.
The .project file is maintained by the core Eclipse platform, and its goal is to describe the project from a generic, plugin-independent Eclipse view. What's the project's name? what other projects in the workspace does it refer to? What are the builders that are used in order to build the project? (remember, the concept of "build" doesn't pertain specifically to Java projects, but also to other types of projects)
The .classpath file is maintained by Eclipse's JDT feature (feature = set of plugins). JDT holds multiple such "meta" files in the project (see the .settings directory inside the project); the .classpath file is just one of them. Specifically, the .classpath file contains information that the JDT feature needs in order to properly compile the project: the project's source folders (that is, what to compile); the output folders (where to compile to); and classpath entries (such as other projects in the workspace, arbitrary JAR files on the file system, and so forth).
Blindly copying such files from one machine to another may be risky. For example, if arbitrary JAR files are placed on the classpath (that is, JAR files that are located outside the workspace and are referred-to by absolute path naming), the .classpath file is rendered non-portable and must be modified in order to be portable. There are certain best practices that can be followed to guarantee .classpath file portability.
The .settings folder is used by various plugins to set persistent 'Properties' as opposed to 'Prefereneces' to specify project specific settings that should be preserved.
.settings is usually a directory you most definitely want checked into svn/cvs/git etc as it will ensure that all users who check that project out into eclipse use the right project specific settings.
In our case we use it to supply a minimum compiler version of java but we want things compiled to 5 for our servers. We also use it to enforce some coding standards and auto-formaters which makes version diffs much easier to read.
In your specific case you selected 'Enable Project Specific Settings' under "Properties->Java Compiler" by right clicking on the project and choosing properties.

Eclipse ctrl+Shift+G not working as expected

Ctrl+Shift+G used to find references to the current selection within ALL projects in my Workspace.
Now is seems to only return references within the current Project.
Details:
I have 3 projects in the same database. 1 project is common code. The other 2 projects include the source folder of the common code on the build path. I prefer to link to common source instead of including the common code as a Project on the build path because then when I deploy by exporting WAR each project has its own self-contained version of the common code.
However Ctrl+Shift+G seems to work when I include the common code as a Project. So it looks like I need to do both. I just don't know why the searching results have changed. I did install JBoss Tools and as a result of Jboss needed to install a newer version of Indigo.
Similar issue, but no good answer.
EDIT:
Open two editors with a common class file, one from the linked source folder and one for the actual project folder. When the Ctrl+Shift+G is performed on the linked source, only references with in the project containing the linked folder are found. Ctrl+Shift+G from the actual common project finds references to all projects in the workspace, when those projects have the common project referenced on the build path.
The problem is when I am in a project and I control click a common code method I am taken to the linked source class file. So then when I do a Ctrl+Shift+G on that method, I miss all the other projects that reference this common method, because the editor contains the file from the linked source. This never used behaved this way and used to find all projects that referenced this method regardless of which file (linked or actual) was used.
I find the command..It is
Ctrl+ALT +G // search through out workspace
not
Ctrl +shift +G // searching within class/project
And one tip
Ctrl+shift+L to see all commands in Eclipse
This can occur if you are using Maven and your version numbers do not match. I had a dependent project with <version>1.0.0.RELEASE</version> that was being referenced in another project as <version>1.0.0-SNAPSHOT</version>. Fixing the mismatch so that versions were correct allowed CTRL-SHIFT-G to find the references in the workspace that it could not find before.

ScalaMacros and Eclipse

I am trying to compile a (Scala) macro in Eclipse 3.7.2 with the Scala IDE Plugin available for Scala 2.10.0-M3, but I am experiencing the following error:
"macro implementation not found: XXXXX (the most common reason for that is that you cannot use macro implementations in the same compilation run that defines them) if you do need to define macro implementations along with the rest of your program, consider two-phase compilation with -Xmacro-fallback-classpath in the second phase pointing to the output of the first phase"
I already know how to avoid it with a simple editor and a terminal (just following the error message), but is it possible to achieve the dual phase task in Eclipse?
How to create a macro project to link to an existing project:
Create a scala project named for example ProjectMacros, put a file named for example Macros.scala containing macros in it. This project should compile without problems, because there are only macros.
Right-click on the existing scala project, then "Properties". The Properties window opens.
In the Java Build Path section:
Under the tab Projects, add ProjectMacros.
Under the tab Libraries, click Add Class Folder, and select the ProjectMacros/bin directory.
In the Project References section, check ProjectMacros
Now, after adding in the existing project an import like import Macros._ you can use the macros functions and annotations.
Well, separating macro implementation and macro invocation in two differents projects (and playing with project references) seems to solve the issue. Anyway, the Scala-IDE plugin has been notably improved with its version for Scala 2.10-M4 (in terms of macro support), so I recommend to update to it.
You could probably use Ant for building, but since you are saying that you already achieved this with terminal I think it would be easier to create script, and run it using custom builder (go to project properties, click Builders -> New... -> Program and then set it up to run your script.

eclipse does not resolve all includes

I am working on an avr project in eclipse and include files supplied by the compiler. Eclipse recognize the includes in code (i.e. no question mark by the #include) but it does not resolve the defines in the included files, i.e. PINA is not recognized as a memory address.
I've tried to add the include directory as a library path in Paths and Symbols. I've tried to add it as a library path to the build settings. Neither one worked.
I am using Eclipse Indigo and ImageCraft compiler. Furthermore, in the projects I've included imagecraft's include directory as a link (to enable search).
Any ideas?
Project should be created as a standard C project. Under Project / Properties / C/C++ General / Paths and Symbols in the Includes tab. Choose Add... and point it to the library path (in my case: C:\icc7avr\include). That seems to solve it for most projects.
However I have a nested project (project is a subset of another project) where this doesn't work.