eclipse-xtext / eclipse-xtext/xtext

Bogus behavior of JvmMember.identifier in EmfFormatter/ SerializerTestHelper

Open
#2,364 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
831
Forks
330
Avg merge
3d 7h
Merged PRs (30d)
12

Description

Given the grammar

grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.xbase.Xbase

generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"

import "http://www.eclipse.org/xtext/common/JavaVMTypes" as types

Model:
	greetings+=Greeting*;
	
Greeting returns types::JvmMember:
	{Greeting} 'Hello' simpleName=ID '!';

and validator

class MyDslValidator extends AbstractMyDslValidator {
	
	public static val INVALID_NAME = 'invalidName'

	@Check
	def checkGreetingStartsWithCapital(Greeting greeting) {
		System.err.println(greeting.identifier)
	}
	
}

the following test fails

@RunWith(XtextRunner.class)
@InjectWith(MyDslInjectorProvider.class)
public class DemoTest {
	
	@Test
	public void testSeShit() throws Exception {
		Model m = parseHelper.parse("Hello A! Hello B!");
		h.assertNoErrors(m);
		sth.assertSerializeWithoutNodeModel(m);
	}
	
	@Inject
	ValidationTestHelper h;
	
	@Inject
	ParseHelper<Model> parseHelper;
	
	@Inject
	SerializerTestHelper sth;
}

org.junit.ComparisonFailure: expected:<...pleName 'A'
        [    attr EString identifier 'A'
        }
        1: Greeting {
            attr EString simpleName 'B'
            attr EString identifier] 'B'
        }
    ]...> but was:<...pleName 'A'
        [}
        1: Greeting {
            attr EString simpleName] 'B'
        }
    ]...>
	at org.junit.Assert.assertEquals(Assert.java:115)
	at org.junit.Assert.assertEquals(Assert.java:144)
	at 

depending on somebody visits
identifier or not the eIsSet for member is different
and thus the serialization is.

the serializationTestHelper has no overloaded api for the calls to formatter to exclude features
thus i think the eIsSet for identifier always should return true.
or we should use the formatter in a way that excludes transients for such tests

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the failure with the grammar, validator, and DemoTest shown, then inspect JvmMember.identifier, EmfFormatter, and SerializerTestHelper. Compare serialization when identifier is accessed versus not accessed, and confirm that the chosen fix makes the serializer test deterministic without changing the reported model output unexpectedly.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.