Xtext - Couldn't resolve reference to Object - eclipse

I'm new to Xtext and having a problem with a simple Xtext program:
my grammar looks like this:
grammar org.xtext.example.domainmodel.Domainmodel with org.eclipse.xtext.common.Terminals
generate domainmodel "http://www.xtext.org/example/domainmodel/Domainmodel"
Library:
(books+=Book)*;
Book:
'Book'
isbn=ID
title=STRING
(subtitle=STRING)?
pages=INT
('sequelof' sequelof=[Book])?
('hardcover'|'softcover');
and my script looks like this
Book J123 "LotR1" "The Fellowship" 608 hardcover
Book J124 "LotR2" "Two Towers" 510 sequelof J123 hardcover
but the "J123" in the second line is red underlined and it says "Couldn't resolve reference to Book 'J123'"
Everthing else works fine, like Content Assist (Strg+Space)
Maybe you can help me :)

By default, references work on name properties. I.e. you need to change your grammar to the following:
grammar org.xtext.example.domainmodel.Domainmodel with
org.eclipse.xtext.common.Terminals
generate domainmodel "http://www.xtext.org/example/domainmodel/Domainmodel"
Library:
(books+=Book)*;
Book:
'Book'
name=ID
title=STRING
(subtitle=STRING)?
pages=INT
('sequelof' sequelof=[Book])?
('hardcover'|'softcover');
If you don't want to do that, you can implement the IQualifiedName provider so that it computes the name using the isbn property.

Related

How to exclude UnityEditor reference from asmdef?

How to exclude UnityEditor reference from asmdef?
Why I need it:
I have an asmdef file. For example, it is MyAssembly/MyAssembly.asmdef. The MyAssembly contains a lot of features and each feature staff is placed in its own folder. And some of these features has a code that is needed only in editor, and it refers to UnityEditor namespace. Such editor code is placed into an Editor folder.
But as you know, Editor folder name means nothing in terms of asmdef usage. So I add AssemblyDefenitionReference in each folder and refer it to the MyAssemblyEditor.asmdef assembly definition. So the paths looks like this:
MyAssembly/MyAssembly.asmdef
MyAssembly/Editor/MyAssemblyEditor.asmdef - this folder contains no code. It's needed just to place asmdef, because it's not allowed to place two asmdefs in a single folder.
MyAssembly/SomeFeature/Editor/*feature editor staff*
MyAssembly/SomeFeature/Editor/Editor.asmref - refers to MyAssemblyEditor.asmdef
MyAssembly/SomeFeature/*feature staff*
All this works good. But the problem is that, when some developer adds a new feature, he can forget to add a reference to the MyAssemblyEditor.asmdef in the editor folder. And there are no any errors will be shown in this case. This mistake will be revealed only when the build will be cooked. But I'd like that using of UnityEditor in MyAssembly will be instantly marked as an error.
Feel free to suggest other solution for this problem.
This thread got me thinking I can use CsprojPostprocessor to remove all references to UnityEditor from my csproj file. I wrote such class:
using System.Text.RegularExpressions;
using UnityEditor;
// ReSharper disable once CheckNamespace
public class CsprojPostprocessor : AssetPostprocessor
{
public static string OnGeneratedCSProject(string path, string content)
{
if (!path.EndsWith("Editor.csproj") && !path.EndsWith("Tests.csproj"))
{
var newContent =
Regex.Replace(content, "<Reference Include=\"UnityEditor(.|\n)*?</Reference>", "");
return newContent;
}
return content;
}
}
It also can be done with an xml parser or something.
The only thing, that confuse me is that this mechanism is badly documented and doesn't look like something simple users should use. So I use it at my own risk, but looks like there is no guarantee it will be strongly supported in future.

What C# feature is this?

In my C# application (which uses C# 9) I had a line of code like this:
var filterCallback = new HitTestFilterCallback(
el => el is Path s && s.DataContext is IShape shp ?
HitTestFilterBehavior.Continue : HitTestFilterBehavior.ContinueSkipSelf);
Resharper suggested I "merge sequential checks". It rewrote the code to this
var filterCallback = new HitTestFilterCallback(
el => el is Path {DataContext: IShape shp}
?
HitTestFilterBehavior.Continue : HitTestFilterBehavior.ContinueSkipSelf);
I am interested in the bit that lets me write
{DataContext: IShape shp}
in place of
s.DataContext is IShape shp
Is there a specific technical language name for this feature? I want to read up on it to understand it better but I don't even know what to call it. I tried looking under "pattern matching" and reading about the "is" keyword but don't see anything that looks like it?
The feature is called "recursive patterns". In particular it is using a "property pattern" as part of a "recursive pattern".
You can find the proposal document here: https://github.com/dotnet/csharplang/blob/master/proposals/csharp-8.0/patterns.md
You can find a more informal blog post about it here: https://devblogs.microsoft.com/dotnet/do-more-with-patterns-in-c-8-0/

ArangoDB "Spring Data Demo" Tutorial outdated?

Like the title says, is it possible the tutorial at https://www.arangodb.com/tutorials/spring-data/ is outdated? I'm having several problems, but don't know how to workaround the last one:
Part 2, "Save and read an entity"
I get an error: method getId() is undefined.
Workaround: I added a getter in class Character.
Also in "Save and read an entity"
final Character foundNed = repository.findOne(nedStark.getId());
The method findOne(Example) in the type QueryByExampleExecutor is not applicable for the arguments (String)
Workaround: I used find by example:
final Optional<Person> foundNed = repository.findOne(Example.of(nedStark));
Part 1, "Create a Configuration class"
public class DemoConfiguration extends AbstractArangoConfiguration {
Gives me an error:
"No constructor with 1 argument defined in class 'com.arangodb.springframework.repository.ArangoRepositoryFactoryBean'"
Workaround: ?
Can anyone point me in the right direction?
I found the demo project on github: https://github.com/arangodb/spring-data-demo
Number 1: They use a getter too.
Number 2: Was my fault, I did try ArangoRepository (of Character, Integer) but forgot that Id is a string.
Number 3: They don't seem use any Configuration (AbstractArangoConfiguration) class in the source at all although it is still mentioned in that tutorial. I think now the config and connection is handled by spring autoconfigure. Though I would like to know how the Arango driver is set, all I could find that may point further is ArangoOperations.
Anyway it works now, maybe this helps somebody else who is having the same problems.

Making vscode snippets only trigger after specific characters

Let's say I have a bunch of functions below:
library.object1.function1()
library.object1.function2()
library.object2.function1()
library.object2.function2()
library.object3.function1()
library.object3.function2()
With what they provide in current custom snippet, when I type lib, it will show all those above functions, which will be a mess if there are too many functions.
I want to make my snippets work like what they did in default code completion:
When I type lib, it only shows:
library
When I type library., it shows:
object1
object2
object3
When I type library.object1., it shows
function1()
function2()
Also, if I type lib, and leave it there, then comeback and add rary, the snippet doesn't work at all, I want it to continue the completion.
Is there a way to achieve it?
I think the closest you can get is something like this (using javascript.json snippet file as an example):
"my library": {
"prefix": "lib",
"body": [
"library.${1|object1,object2,object3|}.${2|function1,function2,function3,function4|}()",
],
"description": "my library functions"
}
With that, when you type lib you get only the library suggested completion. Tab and you will get all the object choices you included in the snippet in the suggestion panel. Tab again and will get the function options that you listed in the snippet.
See snippet choices.

Property Mapping Exception in Helhum upload example

I am using helhum File Upload Demo to upload the images. But currently i got below error.
Exception while property mapping at property path "images.0":Property "name" was not found in target object of type "XXXX\XXXXX\Domain\Model\FileReference
Please help here.. How can i move forward.
Thanks in advace.
If you followed the example extension, you are maybe missing the registration of UploadedFileReferenceConverter and ObjectStorageConverter in your ext_localconf.php. Took me a day to find that one:
ext_localconf.php
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerTypeConverter('Vendor\\EXT\\Property\\TypeConverter\\UploadedFileReferenceConverter');
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerTypeConverter('Vendor\\EXT\\Property\\TypeConverter\\ObjectStorageConverter');
In the initializeUpdateAction (or initializeCreateAction) you have to use the name of the parameter in the updateAction (or createAction) as argument.
If your updateAction looks like this:
public function updateAction(\Classname $yourObject)
You have to call the helhum function with the argument:
$this->setTypeConverterConfigurationForImageUpload('yourObject');
As a small hint for later problems: In the setTypeConverterConfigurationForImageUpload function you should register your own file attributes if they are not named image and/or imageCollection.0 like in the example.