use of org.eclipse.emf.ecore.EClassifier in project xtext-core by eclipse.
the class ValidatorFragment2 method generateValidationToDeprecateRules.
protected StringConcatenationClient generateValidationToDeprecateRules() {
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
{
if (ValidatorFragment2.this.generateDeprecationValidation) {
{
List<AbstractRule> _deprecatedRulesFromGrammar = ValidatorFragment2.this.getDeprecatedRulesFromGrammar();
for (final AbstractRule deprecatedRule : _deprecatedRulesFromGrammar) {
EClassifier _classifier = deprecatedRule.getType().getClassifier();
ResourceSet _resourceSet = ValidatorFragment2.this.getGrammar().eResource().getResourceSet();
final TypeReference elementType = new TypeReference(((EClass) _classifier), _resourceSet);
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.append("@");
_builder.append(Check.class);
_builder.newLineIfNotEmpty();
_builder.append("public void checkDeprecated");
String _simpleName = elementType.getSimpleName();
_builder.append(_simpleName);
_builder.append("(");
_builder.append(elementType);
_builder.append(" element) {");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_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();
}
}
}
}
}
};
return _client;
}
use of org.eclipse.emf.ecore.EClassifier in project xtext-core by eclipse.
the class JUnitFragment method generateExampleRuntimeTest.
protected JavaFileAccess generateExampleRuntimeTest() {
String _testingPackage = this.getTestingPackage();
String _plus = (_testingPackage + ".XtextRunner");
final TypeReference xtextRunner = new TypeReference(_plus);
final TypeReference runWith = new TypeReference("org.junit.runner.RunWith");
String _testingPackage_1 = this.getTestingPackage();
String _plus_1 = (_testingPackage_1 + ".InjectWith");
final TypeReference injectWith = new TypeReference(_plus_1);
final TypeReference extendWith = new TypeReference("org.junit.jupiter.api.^extension.ExtendWith");
final TypeReference injectionExtension = new TypeReference("org.eclipse.xtext.testing.extensions.InjectionExtension");
String _testingPackage_2 = this.getTestingPackage();
String _plus_2 = (_testingPackage_2 + ".util.ParseHelper");
final TypeReference parseHelper = new TypeReference(_plus_2);
TypeReference _switchResult = null;
final JUnitVersion junitVersion = this.junitVersion;
if (junitVersion != null) {
switch(junitVersion) {
case JUNIT_4:
_switchResult = new TypeReference("org.junit.Test");
break;
case JUNIT_5:
_switchResult = new TypeReference("org.junit.jupiter.api.Test");
break;
default:
break;
}
}
final TypeReference test = _switchResult;
TypeReference _switchResult_1 = null;
final JUnitVersion junitVersion_1 = this.junitVersion;
if (junitVersion_1 != null) {
switch(junitVersion_1) {
case JUNIT_4:
_switchResult_1 = new TypeReference("org.junit.Assert");
break;
case JUNIT_5:
_switchResult_1 = new TypeReference("org.junit.jupiter.api.Assertions");
break;
default:
break;
}
}
final TypeReference assert_ = _switchResult_1;
EClassifier _classifier = IterableExtensions.<AbstractRule>head(this.getGrammar().getRules()).getType().getClassifier();
ResourceSet _resourceSet = this.getGrammar().eResource().getResourceSet();
final TypeReference rootType = new TypeReference(((EClass) _classifier), _resourceSet);
TypeReference _exampleRuntimeTest = this.exampleRuntimeTest();
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
{
boolean _equals = Objects.equal(JUnitFragment.this.junitVersion, JUnitVersion.JUNIT_4);
if (_equals) {
_builder.append("@");
_builder.append(runWith);
_builder.append("(");
_builder.append(xtextRunner);
_builder.append(")");
_builder.newLineIfNotEmpty();
}
}
{
boolean _equals_1 = Objects.equal(JUnitFragment.this.junitVersion, JUnitVersion.JUNIT_5);
if (_equals_1) {
_builder.append("@");
_builder.append(extendWith);
_builder.append("(");
_builder.append(injectionExtension);
_builder.append(")");
_builder.newLineIfNotEmpty();
}
}
_builder.append("@");
_builder.append(injectWith);
_builder.append("(");
TypeReference _injectorProvider = JUnitFragment.this.injectorProvider();
_builder.append(_injectorProvider);
_builder.append(")");
_builder.newLineIfNotEmpty();
_builder.append("class ");
TypeReference _exampleRuntimeTest = JUnitFragment.this.exampleRuntimeTest();
_builder.append(_exampleRuntimeTest);
_builder.append(" {");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("@");
_builder.append(Inject.class, "\t");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append(parseHelper, "\t");
_builder.append("<");
_builder.append(rootType, "\t");
_builder.append("> parseHelper");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("@");
_builder.append(test, "\t");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("def void loadModel() {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("val result = parseHelper.parse(\'\'");
_builder.append("\'");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("Hello Xtext!");
_builder.newLine();
_builder.append("\t\t");
_builder.append("\'\'");
_builder.append("\')");
_builder.newLine();
_builder.append("\t\t");
_builder.append(assert_, "\t\t");
_builder.append(".assertNotNull(result)");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("val errors = result.eResource.errors");
_builder.newLine();
{
boolean _equals_2 = Objects.equal(JUnitFragment.this.junitVersion, JUnitVersion.JUNIT_4);
if (_equals_2) {
_builder.append("\t\t");
_builder.append(assert_, "\t\t");
_builder.append(".assertTrue(\'\'");
_builder.append("\'Unexpected errors: ");
_builder.append("�", "\t\t");
_builder.append("errors.join(\", \")");
_builder.append("�", "\t\t");
_builder.append("\'\'");
_builder.append("\', errors.isEmpty)");
_builder.newLineIfNotEmpty();
}
}
{
boolean _equals_3 = Objects.equal(JUnitFragment.this.junitVersion, JUnitVersion.JUNIT_5);
if (_equals_3) {
_builder.append("\t\t");
_builder.append(assert_, "\t\t");
_builder.append(".assertTrue(errors.isEmpty, \'\'");
_builder.append("\'Unexpected errors: ");
_builder.append("�", "\t\t");
_builder.append("errors.join(\", \")");
_builder.append("�", "\t\t");
_builder.append("\'\'");
_builder.append("\')");
_builder.newLineIfNotEmpty();
}
}
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
}
};
return this.fileAccessFactory.createXtendFile(_exampleRuntimeTest, _client);
}
use of org.eclipse.emf.ecore.EClassifier in project xtext-core by eclipse.
the class JUnitFragment method generateJavaExampleRuntimeTest.
protected JavaFileAccess generateJavaExampleRuntimeTest() {
String _testingPackage = this.getTestingPackage();
String _plus = (_testingPackage + ".XtextRunner");
final TypeReference xtextRunner = new TypeReference(_plus);
final TypeReference runWith = new TypeReference("org.junit.runner.RunWith");
final TypeReference extendWith = new TypeReference("org.junit.jupiter.api.extension.ExtendWith");
final TypeReference injectionExtension = new TypeReference("org.eclipse.xtext.testing.extensions.InjectionExtension");
String _testingPackage_1 = this.getTestingPackage();
String _plus_1 = (_testingPackage_1 + ".InjectWith");
final TypeReference injectWith = new TypeReference(_plus_1);
String _testingPackage_2 = this.getTestingPackage();
String _plus_2 = (_testingPackage_2 + ".util.ParseHelper");
final TypeReference parseHelper = new TypeReference(_plus_2);
TypeReference _switchResult = null;
final JUnitVersion junitVersion = this.junitVersion;
if (junitVersion != null) {
switch(junitVersion) {
case JUNIT_4:
_switchResult = new TypeReference("org.junit.Test");
break;
case JUNIT_5:
_switchResult = new TypeReference("org.junit.jupiter.api.Test");
break;
default:
break;
}
}
final TypeReference test = _switchResult;
TypeReference _switchResult_1 = null;
final JUnitVersion junitVersion_1 = this.junitVersion;
if (junitVersion_1 != null) {
switch(junitVersion_1) {
case JUNIT_4:
_switchResult_1 = new TypeReference("org.junit.Assert");
break;
case JUNIT_5:
_switchResult_1 = new TypeReference("org.junit.jupiter.api.Assertions");
break;
default:
break;
}
}
final TypeReference assert_ = _switchResult_1;
EClassifier _classifier = IterableExtensions.<AbstractRule>head(this.getGrammar().getRules()).getType().getClassifier();
ResourceSet _resourceSet = this.getGrammar().eResource().getResourceSet();
final TypeReference rootType = new TypeReference(((EClass) _classifier), _resourceSet);
final TypeReference list = new TypeReference("java.util.List");
final TypeReference diagnostic = new TypeReference("org.eclipse.emf.ecore.resource", "Resource.Diagnostic");
final TypeReference iterableExtensions = new TypeReference("org.eclipse.xtext.xbase.lib.IterableExtensions");
TypeReference _exampleRuntimeTest = this.exampleRuntimeTest();
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
{
boolean _equals = Objects.equal(JUnitFragment.this.junitVersion, JUnitVersion.JUNIT_4);
if (_equals) {
_builder.append("@");
_builder.append(runWith);
_builder.append("(");
_builder.append(xtextRunner);
_builder.append(".class)");
_builder.newLineIfNotEmpty();
}
}
{
boolean _equals_1 = Objects.equal(JUnitFragment.this.junitVersion, JUnitVersion.JUNIT_5);
if (_equals_1) {
_builder.append("@");
_builder.append(extendWith);
_builder.append("(");
_builder.append(injectionExtension);
_builder.append(".class)");
_builder.newLineIfNotEmpty();
}
}
_builder.append("@");
_builder.append(injectWith);
_builder.append("(");
TypeReference _injectorProvider = JUnitFragment.this.injectorProvider();
_builder.append(_injectorProvider);
_builder.append(".class)");
_builder.newLineIfNotEmpty();
_builder.append("public class ");
TypeReference _exampleRuntimeTest = JUnitFragment.this.exampleRuntimeTest();
_builder.append(_exampleRuntimeTest);
_builder.append(" {");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("@");
_builder.append(Inject.class, "\t");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("private ");
_builder.append(parseHelper, "\t");
_builder.append("<");
_builder.append(rootType, "\t");
_builder.append("> parseHelper;");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("@");
_builder.append(test, "\t");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("public void loadModel() throws Exception {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("Model result = parseHelper.parse(\"Hello Xtext!\");");
_builder.newLine();
_builder.append("\t\t");
_builder.append(assert_, "\t\t");
_builder.append(".assertNotNull(result);");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append(list, "\t\t");
_builder.append("<");
_builder.append(diagnostic, "\t\t");
_builder.append("> errors = result.eResource().getErrors();");
_builder.newLineIfNotEmpty();
{
boolean _equals_2 = Objects.equal(JUnitFragment.this.junitVersion, JUnitVersion.JUNIT_4);
if (_equals_2) {
_builder.append("\t\t");
_builder.append(assert_, "\t\t");
_builder.append(".assertTrue(\"Unexpected errors: \" + ");
_builder.append(iterableExtensions, "\t\t");
_builder.append(".join(errors, \", \"), errors.isEmpty());");
_builder.newLineIfNotEmpty();
}
}
{
boolean _equals_3 = Objects.equal(JUnitFragment.this.junitVersion, JUnitVersion.JUNIT_5);
if (_equals_3) {
_builder.append("\t\t");
_builder.append(assert_, "\t\t");
_builder.append(".assertTrue(errors.isEmpty(), \"Unexpected errors: \" + ");
_builder.append(iterableExtensions, "\t\t");
_builder.append(".join(errors, \", \"));");
_builder.newLineIfNotEmpty();
}
}
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
}
};
return this.fileAccessFactory.createJavaFile(_exampleRuntimeTest, _client);
}
use of org.eclipse.emf.ecore.EClassifier in project xtext-core by eclipse.
the class Ecore2XtextGrammarCreator method grammar.
public CharSequence grammar(final WizardConfiguration config) {
CharSequence _xblockexpression = null;
{
final Ecore2XtextConfiguration it = config.getEcore2Xtext();
UniqueNameUtil.clearUniqueNames(it.getDefaultEPackageInfo());
StringConcatenation _builder = new StringConcatenation();
_builder.append("// automatically generated by Xtext");
_builder.newLine();
_builder.append("grammar ");
String _name = config.getLanguage().getName();
_builder.append(_name);
_builder.append(" with org.eclipse.xtext.common.Terminals");
_builder.newLineIfNotEmpty();
_builder.newLine();
{
Collection<EPackage> _allReferencedEPackages = Ecore2XtextExtensions.allReferencedEPackages(it);
for (final EPackage it_1 : _allReferencedEPackages) {
_builder.append("import \"");
String _nsURI = it_1.getNsURI();
_builder.append(_nsURI);
_builder.append("\" ");
{
if (((UniqueNameUtil.uniqueName(it_1) != null) && (!Objects.equal(UniqueNameUtil.uniqueName(it_1), "")))) {
_builder.append("as ");
String _uniqueName = UniqueNameUtil.uniqueName(it_1);
_builder.append(_uniqueName);
}
}
_builder.newLineIfNotEmpty();
}
}
_builder.newLine();
CharSequence _rules = this.rules(it.getRootElementClass());
_builder.append(_rules);
_builder.newLineIfNotEmpty();
{
List<EClass> _but = this.<EClass>but(Ecore2XtextExtensions.allDispatcherRuleClasses(it), it.getRootElementClass());
for (final EClass it_2 : _but) {
_builder.newLine();
CharSequence _subClassDispatcherRule = this.subClassDispatcherRule(it_2);
_builder.append(_subClassDispatcherRule);
_builder.newLineIfNotEmpty();
}
}
{
List<EClassifier> _but_1 = this.<EClassifier>but(Ecore2XtextExtensions.allConcreteRuleClassifiers(it), it.getRootElementClass());
for (final EClassifier it_3 : _but_1) {
_builder.newLine();
CharSequence _rule = this.rule(it_3);
_builder.append(_rule);
_builder.newLineIfNotEmpty();
}
}
_xblockexpression = _builder;
}
return _xblockexpression;
}
use of org.eclipse.emf.ecore.EClassifier in project xtext-core by eclipse.
the class TypeRefImpl method setClassifier.
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public void setClassifier(EClassifier newClassifier) {
EClassifier oldClassifier = classifier;
classifier = newClassifier;
if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.SET, XtextGrammarTestPackage.TYPE_REF__CLASSIFIER, oldClassifier, classifier));
}
Aggregations