use of org.eclipse.emf.ecore.EClassifier in project xtext-core by eclipse.
the class GrammarUtilTest method testFindCurrentType_06.
@Test
public void testFindCurrentType_06() throws Exception {
this.with(XtextStandaloneSetup.class);
StringConcatenation _builder = new StringConcatenation();
_builder.append("grammar myLang with org.eclipse.xtext.common.Terminals");
_builder.newLine();
_builder.append("generate g \'http://1\'");
_builder.newLine();
_builder.append("Rule:");
_builder.newLine();
_builder.append("\t");
_builder.append("Fragment;");
_builder.newLine();
_builder.append("fragment Fragment returns Rule:");
_builder.newLine();
_builder.append(" ");
_builder.append("name=ID Fragment?");
_builder.newLine();
_builder.append(";");
_builder.newLine();
String model = _builder.toString();
final XtextResource r = this.getResourceFromString(model);
EObject _get = r.getContents().get(0);
final Grammar grammar = ((Grammar) _get);
final AbstractRule rule = IterableExtensions.<AbstractRule>last(grammar.getRules());
AbstractElement _alternatives = rule.getAlternatives();
final AbstractElement fragmentCall = IterableExtensions.<AbstractElement>last(((Group) _alternatives).getElements());
final EClassifier currentType = GrammarUtil.findCurrentType(fragmentCall);
Assert.assertEquals("Rule", currentType.getName());
}
use of org.eclipse.emf.ecore.EClassifier in project xtext-core by eclipse.
the class GrammarUtilTest method testFindCurrentType_03.
@Test
public void testFindCurrentType_03() throws Exception {
this.with(XtextStandaloneSetup.class);
StringConcatenation _builder = new StringConcatenation();
_builder.append("grammar myLang with org.eclipse.xtext.common.Terminals");
_builder.newLine();
_builder.append("generate g \'http://1\'");
_builder.newLine();
_builder.append("Rule:");
_builder.newLine();
_builder.append("\t");
_builder.append("Fragment;");
_builder.newLine();
_builder.append("fragment Fragment: name=ID SecondFragment;");
_builder.newLine();
_builder.append("fragment SecondFragment: {SubRule.named=current} value=ID;");
_builder.newLine();
String model = _builder.toString();
final XtextResource r = this.getResourceFromString(model);
EObject _get = r.getContents().get(0);
final Grammar grammar = ((Grammar) _get);
final AbstractRule rule = IterableExtensions.<AbstractRule>head(grammar.getRules());
final AbstractElement fragmentCall = rule.getAlternatives();
final EClassifier currentType = GrammarUtil.findCurrentType(fragmentCall);
Assert.assertEquals("SubRule", currentType.getName());
}
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("warning(\"This part of the language is marked as deprecated and might get removed in the future!\", element, null);");
_builder.newLine();
_builder.append("}");
_builder.newLine();
}
}
}
}
}
};
return _client;
}
use of org.eclipse.emf.ecore.EClassifier in project xtext-core by eclipse.
the class DeclarativeScopeProviderTest method testScopeByReference2.
@SuppressWarnings("unused")
@Test
public void testScopeByReference2() throws Exception {
final IScope a = new SimpleScope(IScope.NULLSCOPE, Collections.<IEObjectDescription>emptySet());
final IScope b = new SimpleScope(IScope.NULLSCOPE, Collections.<IEObjectDescription>emptySet());
final IScope c = new SimpleScope(IScope.NULLSCOPE, Collections.<IEObjectDescription>emptySet());
AbstractDeclarativeScopeProvider provider = new AbstractDeclarativeScopeProvider() {
private IScope scope_EClass_eSuperTypes(EClassifier clazz, EReference ref) {
return a;
}
private IScope scope_EClass_eSuperTypes(EClass clazz, EReference ref) {
return b;
}
private IScope scope_EClass_eSuperTypes(EReference ctx, EReference ref) {
return c;
}
};
EReference details = EcorePackage.eINSTANCE.getEClass_ESuperTypes();
assertEquals(a, provider.getScope(EcorePackage.eINSTANCE.getEShort(), details));
assertEquals(b, provider.getScope(details.getEContainingClass(), details));
assertEquals(c, provider.getScope(details, details));
}
use of org.eclipse.emf.ecore.EClassifier in project xtext-core by eclipse.
the class DeclarativeScopeProviderTest method testScopeByReference.
@SuppressWarnings("unused")
@Test
public void testScopeByReference() throws Exception {
final IScope a = new SimpleScope(IScope.NULLSCOPE, Collections.<IEObjectDescription>emptySet());
final IScope b = new SimpleScope(IScope.NULLSCOPE, Collections.<IEObjectDescription>emptySet());
final IScope c = new SimpleScope(IScope.NULLSCOPE, Collections.<IEObjectDescription>emptySet());
AbstractDeclarativeScopeProvider provider = new AbstractDeclarativeScopeProvider() {
private IScope scope_EClass_eSuperTypes(EClassifier clazz, EReference ref) {
return a;
}
private IScope scope_EClass(EClass clazz, EReference ref) {
return c;
}
private IScope scope_EClass(EReference ctx, EReference ref) {
return b;
}
};
EReference details = EcorePackage.eINSTANCE.getEClass_ESuperTypes();
assertEquals(a, provider.getScope(details, details));
assertEquals(a, provider.getScope(details.getEContainingClass(), details));
}
Aggregations