Search in sources :

Example 41 with EClassifier

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());
}
Also used : AbstractElement(org.eclipse.xtext.AbstractElement) EObject(org.eclipse.emf.ecore.EObject) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) EClassifier(org.eclipse.emf.ecore.EClassifier) XtextResource(org.eclipse.xtext.resource.XtextResource) Grammar(org.eclipse.xtext.Grammar) AbstractRule(org.eclipse.xtext.AbstractRule) Test(org.junit.Test)

Example 42 with EClassifier

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());
}
Also used : AbstractElement(org.eclipse.xtext.AbstractElement) EObject(org.eclipse.emf.ecore.EObject) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) EClassifier(org.eclipse.emf.ecore.EClassifier) XtextResource(org.eclipse.xtext.resource.XtextResource) Grammar(org.eclipse.xtext.Grammar) AbstractRule(org.eclipse.xtext.AbstractRule) Test(org.junit.Test)

Example 43 with EClassifier

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;
}
Also used : EClass(org.eclipse.emf.ecore.EClass) StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) EClassifier(org.eclipse.emf.ecore.EClassifier) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) TypeReference(org.eclipse.xtext.xtext.generator.model.TypeReference) AbstractRule(org.eclipse.xtext.AbstractRule)

Example 44 with EClassifier

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));
}
Also used : EClass(org.eclipse.emf.ecore.EClass) IScope(org.eclipse.xtext.scoping.IScope) EClassifier(org.eclipse.emf.ecore.EClassifier) EReference(org.eclipse.emf.ecore.EReference) Test(org.junit.Test)

Example 45 with EClassifier

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));
}
Also used : EClass(org.eclipse.emf.ecore.EClass) IScope(org.eclipse.xtext.scoping.IScope) EClassifier(org.eclipse.emf.ecore.EClassifier) EReference(org.eclipse.emf.ecore.EReference) Test(org.junit.Test)

Aggregations

EClassifier (org.eclipse.emf.ecore.EClassifier)192 EClass (org.eclipse.emf.ecore.EClass)132 Test (org.junit.Test)81 EPackage (org.eclipse.emf.ecore.EPackage)75 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)61 EObject (org.eclipse.emf.ecore.EObject)23 EReference (org.eclipse.emf.ecore.EReference)21 AbstractRule (org.eclipse.xtext.AbstractRule)19 EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)18 Grammar (org.eclipse.xtext.Grammar)16 EDataType (org.eclipse.emf.ecore.EDataType)13 XtextResource (org.eclipse.xtext.resource.XtextResource)12 AbstractElement (org.eclipse.xtext.AbstractElement)11 EEnum (org.eclipse.emf.ecore.EEnum)8 ParserRule (org.eclipse.xtext.ParserRule)8 EAttribute (org.eclipse.emf.ecore.EAttribute)7 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)7 AbstractMetamodelDeclaration (org.eclipse.xtext.AbstractMetamodelDeclaration)7 Assignment (org.eclipse.xtext.Assignment)7 ArrayList (java.util.ArrayList)6