Make multiple annotations on enum rule possible

Add validations to see if Annotation works on the rule in the grammar
Add configurable issue for @Deprecate Annotation
This commit is contained in:
Holger Schill 2018-03-28 18:03:29 +02:00
parent 1f61d373c9
commit 026df8e630
13 changed files with 655 additions and 102 deletions

View file

@ -265,7 +265,7 @@ public class XtextValidationTest extends AbstractValidationMessageAcceptingTestC
Diagnostic diag = Diagnostician.INSTANCE.validate(resource.getContents().get(0));
List<Diagnostic> issues = diag.getChildren();
assertEquals(issues.toString(), 1, issues.size());
assertEquals("TerminalRule cannot be deprecated!", issues.get(0).getMessage());
assertEquals("Rule cannot be deprecated!", issues.get(0).getMessage());
assertEquals("diag.isError", diag.getSeverity(), Diagnostic.ERROR);
}
@ -278,7 +278,33 @@ public class XtextValidationTest extends AbstractValidationMessageAcceptingTestC
Diagnostic diag = Diagnostician.INSTANCE.validate(resource.getContents().get(0));
List<Diagnostic> issues = diag.getChildren();
assertEquals(issues.toString(), 1, issues.size());
assertEquals("TerminalRule cannot be exported!", issues.get(0).getMessage());
assertEquals("Rule cannot be exported!", issues.get(0).getMessage());
assertEquals("diag.isError", diag.getSeverity(), Diagnostic.ERROR);
}
@Test public void testEnumAnnotation() throws Exception {
Resource resource = getResourceFromString("grammar org.xtext.Supergrammar with org.eclipse.xtext.common.Terminals\n" +
"generate supergrammar \"http://org.xtext.supergrammar\"\n" +
"Rule: name=ID;\n"+
"@Deprecated\n"+
"enum MyEnum: FOO | BAR;");
Diagnostic diag = Diagnostician.INSTANCE.validate(resource.getContents().get(0));
List<Diagnostic> issues = diag.getChildren();
assertEquals(issues.toString(), 1, issues.size());
assertEquals("Rule cannot be deprecated!", issues.get(0).getMessage());
assertEquals("diag.isError", diag.getSeverity(), Diagnostic.ERROR);
}
@Test public void testEnumAnnotation_1() throws Exception {
Resource resource = getResourceFromString("grammar org.xtext.Supergrammar with org.eclipse.xtext.common.Terminals\n" +
"generate supergrammar \"http://org.xtext.supergrammar\"\n" +
"Rule: name=ID;\n"+
"@Exported\n"+
"enum MyEnum: FOO | BAR;");
Diagnostic diag = Diagnostician.INSTANCE.validate(resource.getContents().get(0));
List<Diagnostic> issues = diag.getChildren();
assertEquals(issues.toString(), 1, issues.size());
assertEquals("Rule cannot be exported!", issues.get(0).getMessage());
assertEquals("diag.isError", diag.getSeverity(), Diagnostic.ERROR);
}

View file

@ -20,6 +20,8 @@ import org.eclipse.xtext.Grammar
import org.eclipse.xtext.validation.AbstractDeclarativeValidator
import org.eclipse.xtext.validation.Check
import org.eclipse.xtext.validation.ComposedChecks
import org.eclipse.xtext.validation.ConfigurableIssueCodesProvider
import org.eclipse.xtext.validation.SeverityConverter
import org.eclipse.xtext.xtext.AnnotationNames
import org.eclipse.xtext.xtext.generator.AbstractInheritingFragment
import org.eclipse.xtext.xtext.generator.XtextGeneratorNaming
@ -30,6 +32,9 @@ import org.eclipse.xtext.xtext.generator.model.TypeReference
import static extension org.eclipse.xtext.GrammarUtil.*
import static extension org.eclipse.xtext.xtext.generator.model.TypeReference.*
import static extension org.eclipse.xtext.xtext.generator.util.GrammarUtil2.*
import org.eclipse.xtext.util.IAcceptor
import org.eclipse.xtext.preferences.PreferenceKey
/**
* By using this fragment validation gets enabled.
* By using @Deprecated in the grammar on a ParserRule a validation gets generated that raises an issue for that.
@ -55,6 +60,34 @@ class ValidatorFragment2 extends AbstractInheritingFragment {
def void addComposedCheck(String composedCheckValidator) {
composedChecks += composedCheckValidator
}
/**
* @since 2.14
*/
protected def getConfigurableIssueCodesProviderClass(){
return new TypeReference(grammar.runtimeBasePackage + '.validation.' + grammar.simpleName + 'ConfigurableIssueCodesProvider')
}
/**
* @since 2.14
*/
protected def getValidatorConfigurationBlockClass(){
return new TypeReference(grammar.runtimeBasePackage + '.validation.' + grammar.simpleName + 'ValidatorConfigurationBlock')
}
/**
* @since 2.14
*/
protected def getAbstractValidatorConfigurationBlockClass(){
return new TypeReference("org.eclipse.xtext.ui.validation.AbstractValidatorConfigurationBlock")
}
/**
* @since 2.14
*/
protected def getSuperConfigurableIssueCodesProviderClass(){
return new TypeReference(ConfigurableIssueCodesProvider)
}
protected def TypeReference getGenValidatorSuperClass(Grammar grammar) {
val superGrammar = grammar.nonTerminalsSuperGrammar
@ -67,11 +100,29 @@ class ValidatorFragment2 extends AbstractInheritingFragment {
protected def TypeReference getDefaultValidatorSuperClass() {
new TypeReference(AbstractDeclarativeValidator)
}
/**
* @since 2.14
*/
protected def contributeRuntimeGuiceBindings() {
val bindingFactory = new GuiceModuleAccess.BindingFactory
bindingFactory.addTypeToTypeEagerSingleton(grammar.validatorClass, grammar.validatorClass)
bindingFactory.addTypeToType(superConfigurableIssueCodesProviderClass,configurableIssueCodesProviderClass)
bindingFactory.contributeTo(language.runtimeGenModule)
}
/**
* @since 2.14
*/
protected def contributePluginGuiceBindings() {
val bindingFactory = new GuiceModuleAccess.BindingFactory
bindingFactory.addTypeToType(abstractValidatorConfigurationBlockClass,validatorConfigurationBlockClass)
bindingFactory.contributeTo(language.eclipsePluginGenModule)
}
override generate() {
new GuiceModuleAccess.BindingFactory().addTypeToTypeEagerSingleton(grammar.validatorClass,
grammar.validatorClass).contributeTo(language.runtimeGenModule)
contributeRuntimeGuiceBindings
contributePluginGuiceBindings
if (isGenerateStub) {
if (generateXtendStub)
generateXtendValidatorStub()
@ -79,6 +130,8 @@ class ValidatorFragment2 extends AbstractInheritingFragment {
generateJavaValidatorStub()
}
generateGenValidator().writeTo(projectConfig.runtime.srcGen)
generateIssueProvider().writeTo(projectConfig.runtime.srcGen)
generateValidationConfigurationBlock().writeTo(projectConfig.eclipsePlugin.srcGen)
if (projectConfig.runtime.manifest !== null)
projectConfig.runtime.manifest.exportedPackages += grammar.validatorClass.packageName
@ -164,6 +217,84 @@ class ValidatorFragment2 extends AbstractInheritingFragment {
'''
javaFile
}
/**
* @since 2.14
*/
protected def generateIssueProvider(){
val javaFile = fileAccessFactory.createGeneratedJavaFile(configurableIssueCodesProviderClass)
javaFile.content = '''
@SuppressWarnings("restriction")
public class «configurableIssueCodesProviderClass» extends «superConfigurableIssueCodesProviderClass» {
protected static final String ISSUE_CODE_PREFIX = "org.xtext.example.mydsl.";
public static final String DEPRECATED_MODEL_PART = ISSUE_CODE_PREFIX + "deprecatedModelPart";
@Override
protected void initialize(«IAcceptor»<«PreferenceKey»> acceptor) {
acceptor.accept(create(DEPRECATED_MODEL_PART, «SeverityConverter».SEVERITY_WARNING));
}
}
'''
javaFile
}
protected def generateValidationConfigurationBlock() {
val javaFile = fileAccessFactory.createGeneratedJavaFile(validatorConfigurationBlockClass)
javaFile.content = '''
@SuppressWarnings("restriction")
public class «validatorConfigurationBlockClass» extends «abstractValidatorConfigurationBlockClass» {
@Override
protected void fillSettingsPage(«typeRef("org.eclipse.swt.widgets.Composite")» composite, int nColumns, int defaultIndent) {
addComboBox(«getConfigurableIssueCodesProviderClass».DEPRECATED_MODEL_PART, "Deprecated Model Part", composite, defaultIndent);
}
@Override
protected «typeRef('org.eclipse.core.runtime.jobs.Job')» getBuildJob(«typeRef('org.eclipse.core.resources.IProject')» project) {
«typeRef('org.eclipse.core.runtime.jobs.Job')» buildJob = new «typeRef('org.eclipse.xtext.ui.preferences.OptionsConfigurationBlock')».BuildJob("Validation Settings Changed", project);
buildJob.setRule(«typeRef('org.eclipse.core.resources.ResourcesPlugin')».getWorkspace().getRuleFactory().buildRule());
buildJob.setUser(true);
return buildJob;
}
@Override
protected String[] getFullBuildDialogStrings(boolean workspaceSettings) {
return new String[] { "Validation Settings Changed",
"Validation settings have changed. A full rebuild is required for changes to take effect. Do the full build now?" };
}
@Override
protected void validateSettings(String changedKey, String oldValue, String newValue) {
}
protected «typeRef('org.eclipse.swt.widgets.Combo')» addComboBox(String prefKey, String label, Composite parent, int indent) {
String[] values = new String[] { «typeRef('org.eclipse.xtext.validation.SeverityConverter')».SEVERITY_ERROR, «typeRef('org.eclipse.xtext.validation.SeverityConverter')».SEVERITY_WARNING,
«typeRef('org.eclipse.xtext.validation.SeverityConverter')».SEVERITY_INFO, «typeRef('org.eclipse.xtext.validation.SeverityConverter')».SEVERITY_IGNORE };
String[] valueLabels = new String[] { "Error", "Warning", "Info", "Ignore" };
«typeRef('org.eclipse.swt.widgets.Combo')» comboBox = addComboBox(parent, label, prefKey, indent, values, valueLabels);
return comboBox;
}
@Override
public void dispose() {
storeSectionExpansionStates(getDialogSettings());
super.dispose();
}
@Override
protected «typeRef('org.eclipse.jface.dialogs.IDialogSettings')» getDialogSettings() {
«typeRef('org.eclipse.jface.dialogs.IDialogSettings')» dialogSettings = super.getDialogSettings();
«typeRef('org.eclipse.jface.dialogs.IDialogSettings')» section = dialogSettings.getSection("MyDsl");
if (section == null) {
return dialogSettings.addNewSection("MyDsl");
}
return section;
}
}
'''
javaFile
}
protected def StringConcatenationClient generateValidationToDeprecateRules() '''
«IF generateDeprecationValidation»
@ -172,7 +303,7 @@ class ValidatorFragment2 extends AbstractInheritingFragment {
@«Check»
public void checkDeprecated«elementType.simpleName»(«elementType» element) {
warning("This part of the language is marked as deprecated and might get removed in the future!", element, null);
addIssue("This part of the language is marked as deprecated and might get removed in the future!", element, «configurableIssueCodesProviderClass».DEPRECATED_MODEL_PART);
}
«ENDFOR»
«ENDIF»
@ -217,6 +348,15 @@ class ValidatorFragment2 extends AbstractInheritingFragment {
<super type="org.eclipse.xtext.ui.check.expensive"/>
<persistent value="true"/>
</extension>
<extension point="org.eclipse.ui.preferencePages">
<page
category="«grammar.name»"
class="«grammar.eclipsePluginExecutableExtensionFactory»:org.eclipse.xtext.ui.validation.ValidatorPreferencePage"
id="«grammar.name».validator.preferencePage"
name="Errors/Warnings">
<keywordReference id="«grammar.eclipsePluginBasePackage».keyword_«simpleName»"/>
</page>
</extension>
'''
}

View file

@ -26,9 +26,13 @@ import org.eclipse.xtext.Annotation;
import org.eclipse.xtext.GeneratedMetamodel;
import org.eclipse.xtext.Grammar;
import org.eclipse.xtext.GrammarUtil;
import org.eclipse.xtext.preferences.PreferenceKey;
import org.eclipse.xtext.util.IAcceptor;
import org.eclipse.xtext.validation.AbstractDeclarativeValidator;
import org.eclipse.xtext.validation.Check;
import org.eclipse.xtext.validation.ComposedChecks;
import org.eclipse.xtext.validation.ConfigurableIssueCodesProvider;
import org.eclipse.xtext.validation.SeverityConverter;
import org.eclipse.xtext.xbase.lib.CollectionLiterals;
import org.eclipse.xtext.xbase.lib.Extension;
import org.eclipse.xtext.xbase.lib.Functions.Function1;
@ -80,6 +84,44 @@ public class ValidatorFragment2 extends AbstractInheritingFragment {
this.composedChecks.add(composedCheckValidator);
}
/**
* @since 2.14
*/
protected TypeReference getConfigurableIssueCodesProviderClass() {
String _runtimeBasePackage = this._xtextGeneratorNaming.getRuntimeBasePackage(this.getGrammar());
String _plus = (_runtimeBasePackage + ".validation.");
String _simpleName = GrammarUtil.getSimpleName(this.getGrammar());
String _plus_1 = (_plus + _simpleName);
String _plus_2 = (_plus_1 + "ConfigurableIssueCodesProvider");
return new TypeReference(_plus_2);
}
/**
* @since 2.14
*/
protected TypeReference getValidatorConfigurationBlockClass() {
String _runtimeBasePackage = this._xtextGeneratorNaming.getRuntimeBasePackage(this.getGrammar());
String _plus = (_runtimeBasePackage + ".validation.");
String _simpleName = GrammarUtil.getSimpleName(this.getGrammar());
String _plus_1 = (_plus + _simpleName);
String _plus_2 = (_plus_1 + "ValidatorConfigurationBlock");
return new TypeReference(_plus_2);
}
/**
* @since 2.14
*/
protected TypeReference getAbstractValidatorConfigurationBlockClass() {
return new TypeReference("org.eclipse.xtext.ui.validation.AbstractValidatorConfigurationBlock");
}
/**
* @since 2.14
*/
protected TypeReference getSuperConfigurableIssueCodesProviderClass() {
return new TypeReference(ConfigurableIssueCodesProvider.class);
}
protected TypeReference getGenValidatorSuperClass(final Grammar grammar) {
TypeReference _xblockexpression = null;
{
@ -99,10 +141,29 @@ public class ValidatorFragment2 extends AbstractInheritingFragment {
return new TypeReference(AbstractDeclarativeValidator.class);
}
/**
* @since 2.14
*/
protected void contributeRuntimeGuiceBindings() {
final GuiceModuleAccess.BindingFactory bindingFactory = new GuiceModuleAccess.BindingFactory();
bindingFactory.addTypeToTypeEagerSingleton(this._validatorNaming.getValidatorClass(this.getGrammar()), this._validatorNaming.getValidatorClass(this.getGrammar()));
bindingFactory.addTypeToType(this.getSuperConfigurableIssueCodesProviderClass(), this.getConfigurableIssueCodesProviderClass());
bindingFactory.contributeTo(this.getLanguage().getRuntimeGenModule());
}
/**
* @since 2.14
*/
protected void contributePluginGuiceBindings() {
final GuiceModuleAccess.BindingFactory bindingFactory = new GuiceModuleAccess.BindingFactory();
bindingFactory.addTypeToType(this.getAbstractValidatorConfigurationBlockClass(), this.getValidatorConfigurationBlockClass());
bindingFactory.contributeTo(this.getLanguage().getEclipsePluginGenModule());
}
@Override
public void generate() {
new GuiceModuleAccess.BindingFactory().addTypeToTypeEagerSingleton(this._validatorNaming.getValidatorClass(this.getGrammar()),
this._validatorNaming.getValidatorClass(this.getGrammar())).contributeTo(this.getLanguage().getRuntimeGenModule());
this.contributeRuntimeGuiceBindings();
this.contributePluginGuiceBindings();
boolean _isGenerateStub = this.isGenerateStub();
if (_isGenerateStub) {
boolean _isGenerateXtendStub = this.isGenerateXtendStub();
@ -113,6 +174,8 @@ public class ValidatorFragment2 extends AbstractInheritingFragment {
}
}
this.generateGenValidator().writeTo(this.getProjectConfig().getRuntime().getSrcGen());
this.generateIssueProvider().writeTo(this.getProjectConfig().getRuntime().getSrcGen());
this.generateValidationConfigurationBlock().writeTo(this.getProjectConfig().getEclipsePlugin().getSrcGen());
ManifestAccess _manifest = this.getProjectConfig().getRuntime().getManifest();
boolean _tripleNotEquals = (_manifest != null);
if (_tripleNotEquals) {
@ -373,6 +436,259 @@ public class ValidatorFragment2 extends AbstractInheritingFragment {
return _xblockexpression;
}
/**
* @since 2.14
*/
protected GeneratedJavaFileAccess generateIssueProvider() {
GeneratedJavaFileAccess _xblockexpression = null;
{
final GeneratedJavaFileAccess javaFile = this.fileAccessFactory.createGeneratedJavaFile(this.getConfigurableIssueCodesProviderClass());
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append("@SuppressWarnings(\"restriction\")");
_builder.newLine();
_builder.append("public class ");
TypeReference _configurableIssueCodesProviderClass = ValidatorFragment2.this.getConfigurableIssueCodesProviderClass();
_builder.append(_configurableIssueCodesProviderClass);
_builder.append(" extends ");
TypeReference _superConfigurableIssueCodesProviderClass = ValidatorFragment2.this.getSuperConfigurableIssueCodesProviderClass();
_builder.append(_superConfigurableIssueCodesProviderClass);
_builder.append(" {");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("protected static final String ISSUE_CODE_PREFIX = \"org.xtext.example.mydsl.\";");
_builder.newLine();
_builder.newLine();
_builder.append("\t");
_builder.append("public static final String DEPRECATED_MODEL_PART = ISSUE_CODE_PREFIX + \"deprecatedModelPart\";");
_builder.newLine();
_builder.newLine();
_builder.append("\t");
_builder.append("@Override");
_builder.newLine();
_builder.append("\t");
_builder.append("protected void initialize(");
_builder.append(IAcceptor.class, "\t");
_builder.append("<");
_builder.append(PreferenceKey.class, "\t");
_builder.append("> acceptor) {");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("acceptor.accept(create(DEPRECATED_MODEL_PART, ");
_builder.append(SeverityConverter.class, "\t\t");
_builder.append(".SEVERITY_WARNING));");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
}
};
javaFile.setContent(_client);
_xblockexpression = javaFile;
}
return _xblockexpression;
}
protected GeneratedJavaFileAccess generateValidationConfigurationBlock() {
GeneratedJavaFileAccess _xblockexpression = null;
{
final GeneratedJavaFileAccess javaFile = this.fileAccessFactory.createGeneratedJavaFile(this.getValidatorConfigurationBlockClass());
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append("@SuppressWarnings(\"restriction\")");
_builder.newLine();
_builder.append("public class ");
TypeReference _validatorConfigurationBlockClass = ValidatorFragment2.this.getValidatorConfigurationBlockClass();
_builder.append(_validatorConfigurationBlockClass);
_builder.append(" extends ");
TypeReference _abstractValidatorConfigurationBlockClass = ValidatorFragment2.this.getAbstractValidatorConfigurationBlockClass();
_builder.append(_abstractValidatorConfigurationBlockClass);
_builder.append(" {");
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.append("\t");
_builder.append("@Override");
_builder.newLine();
_builder.append("\t");
_builder.append("protected void fillSettingsPage(");
TypeReference _typeRef = TypeReference.typeRef("org.eclipse.swt.widgets.Composite");
_builder.append(_typeRef, "\t");
_builder.append(" composite, int nColumns, int defaultIndent) {");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("addComboBox(");
TypeReference _configurableIssueCodesProviderClass = ValidatorFragment2.this.getConfigurableIssueCodesProviderClass();
_builder.append(_configurableIssueCodesProviderClass, "\t\t");
_builder.append(".DEPRECATED_MODEL_PART, \"Deprecated Model Part\", composite, defaultIndent);");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.append("\t");
_builder.append("@Override");
_builder.newLine();
_builder.append("\t");
_builder.append("protected ");
TypeReference _typeRef_1 = TypeReference.typeRef("org.eclipse.core.runtime.jobs.Job");
_builder.append(_typeRef_1, "\t");
_builder.append(" getBuildJob(");
TypeReference _typeRef_2 = TypeReference.typeRef("org.eclipse.core.resources.IProject");
_builder.append(_typeRef_2, "\t");
_builder.append(" project) {");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
TypeReference _typeRef_3 = TypeReference.typeRef("org.eclipse.core.runtime.jobs.Job");
_builder.append(_typeRef_3, "\t\t");
_builder.append(" buildJob = new ");
TypeReference _typeRef_4 = TypeReference.typeRef("org.eclipse.xtext.ui.preferences.OptionsConfigurationBlock");
_builder.append(_typeRef_4, "\t\t");
_builder.append(".BuildJob(\"Validation Settings Changed\", project);");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("buildJob.setRule(");
TypeReference _typeRef_5 = TypeReference.typeRef("org.eclipse.core.resources.ResourcesPlugin");
_builder.append(_typeRef_5, "\t\t");
_builder.append(".getWorkspace().getRuleFactory().buildRule());");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("buildJob.setUser(true);");
_builder.newLine();
_builder.append("\t\t");
_builder.append("return buildJob;");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.append("\t");
_builder.append("@Override");
_builder.newLine();
_builder.append("\t");
_builder.append("protected String[] getFullBuildDialogStrings(boolean workspaceSettings) {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("return new String[] { \"Validation Settings Changed\",");
_builder.newLine();
_builder.append("\t\t\t\t");
_builder.append("\"Validation settings have changed. A full rebuild is required for changes to take effect. Do the full build now?\" };");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.append("\t");
_builder.append("@Override");
_builder.newLine();
_builder.append("\t");
_builder.append("protected void validateSettings(String changedKey, String oldValue, String newValue) {");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.append("\t");
_builder.append("protected ");
TypeReference _typeRef_6 = TypeReference.typeRef("org.eclipse.swt.widgets.Combo");
_builder.append(_typeRef_6, "\t");
_builder.append(" addComboBox(String prefKey, String label, Composite parent, int indent) {");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("String[] values = new String[] { ");
TypeReference _typeRef_7 = TypeReference.typeRef("org.eclipse.xtext.validation.SeverityConverter");
_builder.append(_typeRef_7, "\t\t");
_builder.append(".SEVERITY_ERROR, ");
TypeReference _typeRef_8 = TypeReference.typeRef("org.eclipse.xtext.validation.SeverityConverter");
_builder.append(_typeRef_8, "\t\t");
_builder.append(".SEVERITY_WARNING,");
_builder.newLineIfNotEmpty();
_builder.append("\t\t\t\t");
TypeReference _typeRef_9 = TypeReference.typeRef("org.eclipse.xtext.validation.SeverityConverter");
_builder.append(_typeRef_9, "\t\t\t\t");
_builder.append(".SEVERITY_INFO, ");
TypeReference _typeRef_10 = TypeReference.typeRef("org.eclipse.xtext.validation.SeverityConverter");
_builder.append(_typeRef_10, "\t\t\t\t");
_builder.append(".SEVERITY_IGNORE };");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("String[] valueLabels = new String[] { \"Error\", \"Warning\", \"Info\", \"Ignore\" };");
_builder.newLine();
_builder.append("\t\t");
TypeReference _typeRef_11 = TypeReference.typeRef("org.eclipse.swt.widgets.Combo");
_builder.append(_typeRef_11, "\t\t");
_builder.append(" comboBox = addComboBox(parent, label, prefKey, indent, values, valueLabels);");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("return comboBox;");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.append("\t");
_builder.append("@Override");
_builder.newLine();
_builder.append("\t");
_builder.append("public void dispose() {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("storeSectionExpansionStates(getDialogSettings());");
_builder.newLine();
_builder.append("\t\t");
_builder.append("super.dispose();");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.append("\t");
_builder.append("@Override");
_builder.newLine();
_builder.append("\t");
_builder.append("protected ");
TypeReference _typeRef_12 = TypeReference.typeRef("org.eclipse.jface.dialogs.IDialogSettings");
_builder.append(_typeRef_12, "\t");
_builder.append(" getDialogSettings() {");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
TypeReference _typeRef_13 = TypeReference.typeRef("org.eclipse.jface.dialogs.IDialogSettings");
_builder.append(_typeRef_13, "\t\t");
_builder.append(" dialogSettings = super.getDialogSettings();");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
TypeReference _typeRef_14 = TypeReference.typeRef("org.eclipse.jface.dialogs.IDialogSettings");
_builder.append(_typeRef_14, "\t\t");
_builder.append(" section = dialogSettings.getSection(\"MyDsl\");");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("if (section == null) {");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("return dialogSettings.addNewSection(\"MyDsl\");");
_builder.newLine();
_builder.append("\t\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t\t");
_builder.append("return section;");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
}
};
javaFile.setContent(_client);
_xblockexpression = javaFile;
}
return _xblockexpression;
}
protected StringConcatenationClient generateValidationToDeprecateRules() {
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
@ -398,8 +714,11 @@ public class ValidatorFragment2 extends AbstractInheritingFragment {
_builder.append(" element) {");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("warning(\"This part of the language is marked as deprecated and might get removed in the future!\", element, null);");
_builder.newLine();
_builder.append("addIssue(\"This part of the language is marked as deprecated and might get removed in the future!\", element, ");
TypeReference _configurableIssueCodesProviderClass = ValidatorFragment2.this.getConfigurableIssueCodesProviderClass();
_builder.append(_configurableIssueCodesProviderClass, "\t");
_builder.append(".DEPRECATED_MODEL_PART);");
_builder.newLineIfNotEmpty();
_builder.append("}");
_builder.newLine();
}
@ -524,6 +843,45 @@ public class ValidatorFragment2 extends AbstractInheritingFragment {
_builder.newLine();
_builder.append("</extension>");
_builder.newLine();
_builder.append("<extension point=\"org.eclipse.ui.preferencePages\">");
_builder.newLine();
_builder.append("\t");
_builder.append("<page");
_builder.newLine();
_builder.append("\t\t");
_builder.append("category=\"");
String _name_1 = this.getGrammar().getName();
_builder.append(_name_1, "\t\t");
_builder.append("\"");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("class=\"");
TypeReference _eclipsePluginExecutableExtensionFactory = this._xtextGeneratorNaming.getEclipsePluginExecutableExtensionFactory(this.getGrammar());
_builder.append(_eclipsePluginExecutableExtensionFactory, "\t\t");
_builder.append(":org.eclipse.xtext.ui.validation.ValidatorPreferencePage\"");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("id=\"");
String _name_2 = this.getGrammar().getName();
_builder.append(_name_2, "\t\t");
_builder.append(".validator.preferencePage\"");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("name=\"Errors/Warnings\">");
_builder.newLine();
_builder.append("\t\t");
_builder.append("<keywordReference id=\"");
String _eclipsePluginBasePackage = this._xtextGeneratorNaming.getEclipsePluginBasePackage(this.getGrammar());
_builder.append(_eclipsePluginBasePackage, "\t\t");
_builder.append(".keyword_");
_builder.append(simpleName, "\t\t");
_builder.append("\"/>");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("</page>");
_builder.newLine();
_builder.append("</extension>");
_builder.newLine();
_xblockexpression = _entries.add(_builder.toString());
}
return _xblockexpression;

View file

@ -7940,7 +7940,7 @@ rule__EnumRule__Group__0__Impl
:
(
{ before(grammarAccess.getEnumRuleAccess().getAnnotationsAssignment_0()); }
(rule__EnumRule__AnnotationsAssignment_0)?
(rule__EnumRule__AnnotationsAssignment_0)*
{ after(grammarAccess.getEnumRuleAccess().getAnnotationsAssignment_0()); }
)
;

View file

@ -24718,40 +24718,47 @@ public class InternalXtextParser extends AbstractInternalContentAssistParser {
// $ANTLR start "rule__EnumRule__Group__0__Impl"
// InternalXtext.g:7936:1: rule__EnumRule__Group__0__Impl : ( ( rule__EnumRule__AnnotationsAssignment_0 )? ) ;
// InternalXtext.g:7936:1: rule__EnumRule__Group__0__Impl : ( ( rule__EnumRule__AnnotationsAssignment_0 )* ) ;
public final void rule__EnumRule__Group__0__Impl() throws RecognitionException {
int stackSize = keepStackSize();
try {
// InternalXtext.g:7940:1: ( ( ( rule__EnumRule__AnnotationsAssignment_0 )? ) )
// InternalXtext.g:7941:1: ( ( rule__EnumRule__AnnotationsAssignment_0 )? )
// InternalXtext.g:7940:1: ( ( ( rule__EnumRule__AnnotationsAssignment_0 )* ) )
// InternalXtext.g:7941:1: ( ( rule__EnumRule__AnnotationsAssignment_0 )* )
{
// InternalXtext.g:7941:1: ( ( rule__EnumRule__AnnotationsAssignment_0 )? )
// InternalXtext.g:7942:2: ( rule__EnumRule__AnnotationsAssignment_0 )?
// InternalXtext.g:7941:1: ( ( rule__EnumRule__AnnotationsAssignment_0 )* )
// InternalXtext.g:7942:2: ( rule__EnumRule__AnnotationsAssignment_0 )*
{
before(grammarAccess.getEnumRuleAccess().getAnnotationsAssignment_0());
// InternalXtext.g:7943:2: ( rule__EnumRule__AnnotationsAssignment_0 )?
int alt75=2;
int LA75_0 = input.LA(1);
// InternalXtext.g:7943:2: ( rule__EnumRule__AnnotationsAssignment_0 )*
loop75:
do {
int alt75=2;
int LA75_0 = input.LA(1);
if ( (LA75_0==28) ) {
alt75=1;
}
switch (alt75) {
case 1 :
// InternalXtext.g:7943:3: rule__EnumRule__AnnotationsAssignment_0
{
pushFollow(FollowSets000.FOLLOW_2);
rule__EnumRule__AnnotationsAssignment_0();
state._fsp--;
if ( (LA75_0==28) ) {
alt75=1;
}
}
break;
switch (alt75) {
case 1 :
// InternalXtext.g:7943:3: rule__EnumRule__AnnotationsAssignment_0
{
pushFollow(FollowSets000.FOLLOW_17);
rule__EnumRule__AnnotationsAssignment_0();
}
state._fsp--;
}
break;
default :
break loop75;
}
} while (true);
after(grammarAccess.getEnumRuleAccess().getAnnotationsAssignment_0());
@ -30091,20 +30098,18 @@ public class InternalXtextParser extends AbstractInternalContentAssistParser {
protected DFA1 dfa1 = new DFA1(this);
protected DFA8 dfa8 = new DFA8(this);
static final String dfa_1s = "\10\uffff";
static final String dfa_2s = "\2\4\3\uffff\3\4";
static final String dfa_3s = "\1\61\1\4\3\uffff\1\61\1\4\1\61";
static final String dfa_4s = "\2\uffff\1\1\1\2\1\3\3\uffff";
static final String dfa_5s = "\10\uffff}>";
static final String dfa_1s = "\6\uffff";
static final String dfa_2s = "\2\4\3\uffff\1\4";
static final String dfa_3s = "\1\61\1\4\3\uffff\1\61";
static final String dfa_4s = "\2\uffff\1\1\1\2\1\3\1\uffff";
static final String dfa_5s = "\6\uffff}>";
static final String[] dfa_6s = {
"\1\2\13\uffff\2\2\12\uffff\1\1\16\uffff\1\3\3\uffff\1\4\1\uffff\1\2",
"\1\5",
"",
"",
"",
"\1\2\13\uffff\2\2\12\uffff\1\6\16\uffff\1\3\3\uffff\1\4\1\uffff\1\2",
"\1\7",
"\1\2\13\uffff\2\2\12\uffff\1\6\16\uffff\1\3\5\uffff\1\2"
"\1\2\13\uffff\2\2\12\uffff\1\1\16\uffff\1\3\3\uffff\1\4\1\uffff\1\2"
};
static final short[] dfa_1 = DFA.unpackEncodedString(dfa_1s);

View file

@ -3556,7 +3556,7 @@ ruleEnumRule returns [EObject current=null]
afterParserOrEnumRuleCall();
}
)
)?
)*
otherlv_1='enum'
{
newLeafNode(otherlv_1, grammarAccess.getEnumRuleAccess().getEnumKeyword_1());

View file

@ -9759,7 +9759,7 @@ public class InternalXtextParser extends AbstractInternalAntlrParser {
// $ANTLR start "ruleEnumRule"
// InternalXtext.g:3533:1: ruleEnumRule returns [EObject current=null] : ( ( (lv_annotations_0_0= ruleAnnotation ) )? otherlv_1= 'enum' ( (lv_name_2_0= ruleValidID ) ) (otherlv_3= 'returns' ( (lv_type_4_0= ruleTypeRef ) ) )? otherlv_5= ':' ( (lv_alternatives_6_0= ruleEnumLiterals ) ) otherlv_7= ';' ) ;
// InternalXtext.g:3533:1: ruleEnumRule returns [EObject current=null] : ( ( (lv_annotations_0_0= ruleAnnotation ) )* otherlv_1= 'enum' ( (lv_name_2_0= ruleValidID ) ) (otherlv_3= 'returns' ( (lv_type_4_0= ruleTypeRef ) ) )? otherlv_5= ':' ( (lv_alternatives_6_0= ruleEnumLiterals ) ) otherlv_7= ';' ) ;
public final EObject ruleEnumRule() throws RecognitionException {
EObject current = null;
@ -9780,53 +9780,60 @@ public class InternalXtextParser extends AbstractInternalAntlrParser {
enterRule();
try {
// InternalXtext.g:3539:2: ( ( ( (lv_annotations_0_0= ruleAnnotation ) )? otherlv_1= 'enum' ( (lv_name_2_0= ruleValidID ) ) (otherlv_3= 'returns' ( (lv_type_4_0= ruleTypeRef ) ) )? otherlv_5= ':' ( (lv_alternatives_6_0= ruleEnumLiterals ) ) otherlv_7= ';' ) )
// InternalXtext.g:3540:2: ( ( (lv_annotations_0_0= ruleAnnotation ) )? otherlv_1= 'enum' ( (lv_name_2_0= ruleValidID ) ) (otherlv_3= 'returns' ( (lv_type_4_0= ruleTypeRef ) ) )? otherlv_5= ':' ( (lv_alternatives_6_0= ruleEnumLiterals ) ) otherlv_7= ';' )
// InternalXtext.g:3539:2: ( ( ( (lv_annotations_0_0= ruleAnnotation ) )* otherlv_1= 'enum' ( (lv_name_2_0= ruleValidID ) ) (otherlv_3= 'returns' ( (lv_type_4_0= ruleTypeRef ) ) )? otherlv_5= ':' ( (lv_alternatives_6_0= ruleEnumLiterals ) ) otherlv_7= ';' ) )
// InternalXtext.g:3540:2: ( ( (lv_annotations_0_0= ruleAnnotation ) )* otherlv_1= 'enum' ( (lv_name_2_0= ruleValidID ) ) (otherlv_3= 'returns' ( (lv_type_4_0= ruleTypeRef ) ) )? otherlv_5= ':' ( (lv_alternatives_6_0= ruleEnumLiterals ) ) otherlv_7= ';' )
{
// InternalXtext.g:3540:2: ( ( (lv_annotations_0_0= ruleAnnotation ) )? otherlv_1= 'enum' ( (lv_name_2_0= ruleValidID ) ) (otherlv_3= 'returns' ( (lv_type_4_0= ruleTypeRef ) ) )? otherlv_5= ':' ( (lv_alternatives_6_0= ruleEnumLiterals ) ) otherlv_7= ';' )
// InternalXtext.g:3541:3: ( (lv_annotations_0_0= ruleAnnotation ) )? otherlv_1= 'enum' ( (lv_name_2_0= ruleValidID ) ) (otherlv_3= 'returns' ( (lv_type_4_0= ruleTypeRef ) ) )? otherlv_5= ':' ( (lv_alternatives_6_0= ruleEnumLiterals ) ) otherlv_7= ';'
// InternalXtext.g:3540:2: ( ( (lv_annotations_0_0= ruleAnnotation ) )* otherlv_1= 'enum' ( (lv_name_2_0= ruleValidID ) ) (otherlv_3= 'returns' ( (lv_type_4_0= ruleTypeRef ) ) )? otherlv_5= ':' ( (lv_alternatives_6_0= ruleEnumLiterals ) ) otherlv_7= ';' )
// InternalXtext.g:3541:3: ( (lv_annotations_0_0= ruleAnnotation ) )* otherlv_1= 'enum' ( (lv_name_2_0= ruleValidID ) ) (otherlv_3= 'returns' ( (lv_type_4_0= ruleTypeRef ) ) )? otherlv_5= ':' ( (lv_alternatives_6_0= ruleEnumLiterals ) ) otherlv_7= ';'
{
// InternalXtext.g:3541:3: ( (lv_annotations_0_0= ruleAnnotation ) )?
int alt74=2;
int LA74_0 = input.LA(1);
// InternalXtext.g:3541:3: ( (lv_annotations_0_0= ruleAnnotation ) )*
loop74:
do {
int alt74=2;
int LA74_0 = input.LA(1);
if ( (LA74_0==21) ) {
alt74=1;
}
switch (alt74) {
case 1 :
// InternalXtext.g:3542:4: (lv_annotations_0_0= ruleAnnotation )
{
// InternalXtext.g:3542:4: (lv_annotations_0_0= ruleAnnotation )
// InternalXtext.g:3543:5: lv_annotations_0_0= ruleAnnotation
{
newCompositeNode(grammarAccess.getEnumRuleAccess().getAnnotationsAnnotationParserRuleCall_0_0());
pushFollow(FollowSets000.FOLLOW_50);
lv_annotations_0_0=ruleAnnotation();
state._fsp--;
if ( (LA74_0==21) ) {
alt74=1;
}
if (current==null) {
current = createModelElementForParent(grammarAccess.getEnumRuleRule());
}
add(
current,
"annotations",
lv_annotations_0_0,
"org.eclipse.xtext.Xtext.Annotation");
afterParserOrEnumRuleCall();
switch (alt74) {
case 1 :
// InternalXtext.g:3542:4: (lv_annotations_0_0= ruleAnnotation )
{
// InternalXtext.g:3542:4: (lv_annotations_0_0= ruleAnnotation )
// InternalXtext.g:3543:5: lv_annotations_0_0= ruleAnnotation
{
}
newCompositeNode(grammarAccess.getEnumRuleAccess().getAnnotationsAnnotationParserRuleCall_0_0());
pushFollow(FollowSets000.FOLLOW_50);
lv_annotations_0_0=ruleAnnotation();
state._fsp--;
}
break;
if (current==null) {
current = createModelElementForParent(grammarAccess.getEnumRuleRule());
}
add(
current,
"annotations",
lv_annotations_0_0,
"org.eclipse.xtext.Xtext.Annotation");
afterParserOrEnumRuleCall();
}
}
}
break;
default :
break loop74;
}
} while (true);
otherlv_1=(Token)match(input,50,FollowSets000.FOLLOW_3);
@ -10314,20 +10321,18 @@ public class InternalXtextParser extends AbstractInternalAntlrParser {
protected DFA9 dfa9 = new DFA9(this);
protected DFA34 dfa34 = new DFA34(this);
static final String dfa_1s = "\10\uffff";
static final String dfa_2s = "\2\5\3\uffff\3\5";
static final String dfa_3s = "\1\62\1\5\3\uffff\1\62\1\5\1\57";
static final String dfa_4s = "\2\uffff\1\1\1\2\1\3\3\uffff";
static final String dfa_5s = "\10\uffff}>";
static final String dfa_1s = "\6\uffff";
static final String dfa_2s = "\2\5\3\uffff\1\5";
static final String dfa_3s = "\1\62\1\5\3\uffff\1\62";
static final String dfa_4s = "\2\uffff\1\1\1\2\1\3\1\uffff";
static final String dfa_5s = "\6\uffff}>";
static final String[] dfa_6s = {
"\1\2\17\uffff\1\1\1\2\20\uffff\2\2\6\uffff\1\3\2\uffff\1\4",
"\1\5",
"",
"",
"",
"\1\2\17\uffff\1\6\1\2\20\uffff\2\2\6\uffff\1\3\2\uffff\1\4",
"\1\7",
"\1\2\17\uffff\1\6\1\2\20\uffff\2\2\6\uffff\1\3"
"\1\2\17\uffff\1\1\1\2\20\uffff\2\2\6\uffff\1\3\2\uffff\1\4"
};
static final short[] dfa_1 = DFA.unpackEncodedString(dfa_1s);
@ -10452,7 +10457,7 @@ public class InternalXtextParser extends AbstractInternalAntlrParser {
public static final BitSet FOLLOW_47 = new BitSet(new long[]{0x00010B8000028030L});
public static final BitSet FOLLOW_48 = new BitSet(new long[]{0x00010B8000028032L});
public static final BitSet FOLLOW_49 = new BitSet(new long[]{0x0002000000000002L});
public static final BitSet FOLLOW_50 = new BitSet(new long[]{0x0004000000000000L});
public static final BitSet FOLLOW_50 = new BitSet(new long[]{0x0004000000200000L});
public static final BitSet FOLLOW_51 = new BitSet(new long[]{0x0000000800000002L});
}

View file

@ -789,7 +789,7 @@ public class XtextSemanticSequencer extends AbstractDelegatingSemanticSequencer
* EnumRule returns EnumRule
*
* Constraint:
* (annotations+=Annotation? name=ValidID type=TypeRef? alternatives=EnumLiterals)
* (annotations+=Annotation* name=ValidID type=TypeRef? alternatives=EnumLiterals)
*/
protected void sequence_EnumRule(ISerializationContext context, EnumRule semanticObject) {
genericSequencer.createSequence(context, semanticObject);

View file

@ -2181,16 +2181,16 @@ public class XtextGrammarAccess extends AbstractGrammarElementFinder {
private final Keyword cSemicolonKeyword_6 = (Keyword)cGroup.eContents().get(6);
//EnumRule:
// annotations+=Annotation?
// annotations+=Annotation*
// 'enum' name=ValidID ('returns' type=TypeRef)? ':'
// alternatives=EnumLiterals
// ';';
@Override public ParserRule getRule() { return rule; }
//annotations+=Annotation? 'enum' name=ValidID ('returns' type=TypeRef)? ':' alternatives=EnumLiterals ';'
//annotations+=Annotation* 'enum' name=ValidID ('returns' type=TypeRef)? ':' alternatives=EnumLiterals ';'
public Group getGroup() { return cGroup; }
//annotations+=Annotation?
//annotations+=Annotation*
public Assignment getAnnotationsAssignment_0() { return cAnnotationsAssignment_0; }
//Annotation
@ -3026,7 +3026,7 @@ public class XtextGrammarAccess extends AbstractGrammarElementFinder {
}
//EnumRule:
// annotations+=Annotation?
// annotations+=Annotation*
// 'enum' name=ValidID ('returns' type=TypeRef)? ':'
// alternatives=EnumLiterals
// ';';

View file

@ -257,7 +257,7 @@ CharacterRange returns AbstractElement:
;
EnumRule:
(annotations += Annotation)?
(annotations += Annotation)*
'enum' name=ValidID ('returns' type=TypeRef)? ':'
alternatives=EnumLiterals
';'

View file

@ -0,0 +1,17 @@
/*******************************************************************************
* Copyright (c) 2018 itemis AG (http://www.itemis.eu) and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.eclipse.xtext.xtext;
/**
* @author Holger Schill - Initial contribution and API
*/
public enum GeneratorAnnotationTarget {
PARSERRULE, ENUM, TERMINAL
}

View file

@ -1218,12 +1218,14 @@ public class XtextValidator extends AbstractDeclarativeValidator {
}
@Check
public void checkTerminalRuleAnnotations(TerminalRule terminalRule){
if(hasAnnotation(terminalRule, AnnotationNames.EXPORTED)) {
error("TerminalRule cannot be exported!",terminalRule, XtextPackage.eINSTANCE.getAbstractRule_Name(), INVALID_ANNOTAION);
}
if(hasAnnotation(terminalRule, AnnotationNames.DEPRECATED)) {
error("TerminalRule cannot be deprecated!",terminalRule, XtextPackage.eINSTANCE.getAbstractRule_Name(), INVALID_ANNOTAION);
public void checkTerminalRuleAnnotations(AbstractRule rule){
if(rule instanceof TerminalRule || rule instanceof EnumRule) {
if(hasAnnotation(rule, AnnotationNames.EXPORTED)) {
error("Rule cannot be exported!",rule, XtextPackage.eINSTANCE.getAbstractRule_Name(), INVALID_ANNOTAION);
}
if(hasAnnotation(rule, AnnotationNames.DEPRECATED)) {
error("Rule cannot be deprecated!",rule, XtextPackage.eINSTANCE.getAbstractRule_Name(), INVALID_ANNOTAION);
}
}
}