简体   繁体   中英

How to deprecate generated Xtext elements?

I am developing a dsl with Xtext. I want to deprecate some of the language elements. I have an Xtext file from which the language elements are generated. I want those elements to be shown to be deprecated.

Adding @Deprecated over an element does sadly nothing, even though the editor does not complain. I could not find anything regarding deprecation and Xtext.

the

        validator = {
            generateDeprecationValidation = true
        }

in the workflow does not help?

Model:
    greetings+=Greeting*;

@Deprecated 
Greeting:
    'Hello' name=ID '!';

this will generate

public abstract class AbstractMyDslValidator extends AbstractDeclarativeValidator {

    @Override
    protected List<EPackage> getEPackages() {
        List<EPackage> result = new ArrayList<EPackage>();
        result.add(org.xtext.example.mydsl.myDsl.MyDslPackage.eINSTANCE);
        return result;
    }

    @Check
    public void checkDeprecatedGreeting(Greeting element) {
        addIssue("This part of the language is marked as deprecated and might get removed in the future!", element, MyDslConfigurableIssueCodesProvider.DEPRECATED_MODEL_PART);
    }
}

so that this unit test will fail

@ExtendWith(InjectionExtension)
@InjectWith(MyDslInjectorProvider)
class MyDslParsingTest {
    @Inject ParseHelper<Model> parseHelper
    @Inject extension ValidationTestHelper
    @Test
    def void loadModel() {
        val result = parseHelper.parse('''
            Hello Xtext!
        ''')
        Assertions.assertNotNull(result)
        val errors = result.eResource.errors
        Assertions.assertTrue(errors.isEmpty, '''Unexpected errors: «errors.join(", ")»''')
        result.assertNoIssues
    }
}

results in

编辑

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM