Java 类org.eclipse.xtext.XtextStandaloneSetup 实例源码

项目:xtext-core    文件:XtextValidationTest.java   
@Override
public void setUp() throws Exception {
    super.setUp();
    with(XtextStandaloneSetup.class);
    EValidator.Registry.INSTANCE.put(EcorePackage.eINSTANCE, EcoreValidator.INSTANCE);
        File tempFile = File.createTempFile("XtextValidationTest", ".ecore");
        tempFile.deleteOnExit();
        Files.write("<?xml version='1.0' encoding='UTF-8'?>" +
                "<ecore:EPackage xmi:version='2.0' xmlns:xmi='http://www.omg.org/XMI'"+
                "                xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'"+
                "                xmlns:ecore='http://www.eclipse.org/emf/2002/Ecore'"+
                "                name='XtextValidationBugs'"+
                "                nsURI='http://XtextValidationBugs'"+
                "                nsPrefix='XtextValidationBugs'>"+
                "  <eClassifiers xsi:type='ecore:EClass' name='Bug322875'>"+
                "    <eStructuralFeatures xsi:type='ecore:EReference' name='referencesETypeFromClasspathPackage' eType='ecore:EClass classpath:/org/eclipse/xtext/Xtext.ecore#//Grammar'/>"+
                "  </eClassifiers>"+
                "</ecore:EPackage>"
                , tempFile, StandardCharsets.UTF_8);
        xtextValidationTest_ecore = tempFile.toURI().toURL();
}
项目:xtext-core    文件:PartialParserTest.java   
/**
 * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=273209
 */
@Test public void testBug273209_01() throws Exception {
    with(XtextStandaloneSetup.class);
    String model = "grammar org.eclipse.Bug273209_01 with org.eclipse.xtext.common.Terminals \n" +
            "generate testLanguage 'http://www.eclipse.org/2009/tmf/xtext/partialParsing/Bug273209/1'\n" +
            "Model : \n" +
            "        'model' ':' name=ID ';'*;";
    XtextResource resource = getResourceFromString(model);
    assertTrue(resource.getErrors().toString(), resource.getErrors().isEmpty());
    model = resource.getParseResult().getRootNode().getText();
    resource.update(model.indexOf("*;") + 1, 1, "");
    assertEquals(resource.getErrors().toString(), 1, resource.getErrors().size());
    model = resource.getParseResult().getRootNode().getText();
    resource.update(model.indexOf("*") + 1, 0, " ");
    assertEquals(resource.getErrors().toString(), 1, resource.getErrors().size());
    model = resource.getParseResult().getRootNode().getText();
    resource.update(model.indexOf("* ") + 2, 0, ";");
    assertTrue(resource.getErrors().toString(), resource.getErrors().isEmpty());
}
项目:xtext-core    文件:PartialParserTest.java   
/**
 * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=273209
 */
@Test public void testBug273209_02() throws Exception {
    with(XtextStandaloneSetup.class);
    String model = "grammar org.eclipse.Bug273209_01 with org.eclipse.xtext.common.Terminals \n" +
            "generate testLanguage 'http://www.eclipse.org/2009/tmf/xtext/partialParsing/Bug273209/2'\n" +
            "importa : \n" +
            "        name=ID;\n" +
            "Model : \n" +
            "        import;";
    XtextResource resource = getResourceFromStringAndExpect(model, 1);
    assertEquals(resource.getErrors().toString(), 1, resource.getErrors().size());
    model = resource.getParseResult().getRootNode().getText();
    resource.update(model.indexOf("import;") + "import".length(), 1, "");
    assertEquals(resource.getErrors().toString(), 1, resource.getErrors().size());
    model = resource.getParseResult().getRootNode().getText();
    resource.update(model.indexOf(" import") + " import".length(), 0, "a");
    assertEquals(resource.getErrors().toString(), 1, resource.getErrors().size());
    model = resource.getParseResult().getRootNode().getText();
    resource.update(model.indexOf(" importa") + " importa".length(), 0, ";");
    assertTrue(resource.getErrors().toString(), resource.getErrors().isEmpty());
}
项目:xtext-core    文件:PartialParserTest.java   
/**
 * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=273209
 */
@Test public void testBug273209_03() throws Exception {
    with(XtextStandaloneSetup.class);
    String model = "grammar org.eclipse.Bug273209_01 with org.eclipse.xtext.common.Terminals \n" +
            "generate testLanguage 'http://www.eclipse.org/2009/tmf/xtext/partialParsing/Bug273209/3'\n" +
            "Model : \n" +
            "        ('model' ':' name=ID ';'*);";
    XtextResource resource = getResourceFromString(model);
    assertTrue(resource.getErrors().toString(), resource.getErrors().isEmpty());
    model = resource.getParseResult().getRootNode().getText();
    resource.update(model.indexOf("*);") + 1, 2, "");
    assertEquals(resource.getErrors().toString(), 1, resource.getErrors().size());
    model = resource.getParseResult().getRootNode().getText();
    resource.update(model.indexOf("*") + 1, 0, " ");
    assertEquals(resource.getErrors().toString(), 1, resource.getErrors().size());
    model = resource.getParseResult().getRootNode().getText();
    resource.update(model.indexOf("* ") + 2, 0, ");");
    assertTrue(resource.getErrors().toString(), resource.getErrors().isEmpty());
}
项目:xtext-core    文件:MetamodelTransformationTest.java   
@Override
public void setUp() throws Exception {
    super.setUp();
    with(XtextStandaloneSetup.class);
    model = "grammar datatypetests with org.eclipse.xtext.common.Terminals\n" +
            "import 'http://www.eclipse.org/emf/2002/Ecore' as ecore\n" +
            "generate metamodel 'http://fooo'\n" +
            "Start:\n" +
            "  id=StartId id2=RecursiveId id3=CalledId value=Value;\n" +
            "StartId returns ecore::EInt: ID '.' (ID|INT);\n" +
            "RecursiveId: ID ('/' RecursiveId)?;\n" +
            "CalledId: StartId '-' ID;\n" +
            "Value: name=StartId;\n" +
            "OnlyKeywords: 'foo';\n" +
            "AssignmentWithAlternative: foo=('1'|'2');\n" +
            "Farbe :\n" + 
            "    wert=(\"ROT\" | \"BLAU\" | \"GELB\" | \"GR�N\");\n" +
            "UnorderedGroupDataType: ID & STRING & CalledId & 'keyword';\n" +
            "UnorderedGroupClass: ID & name=STRING & CalledId & 'keyword';\n";
    grammar = (Grammar) getModel(model);
    pack = grammar.getMetamodelDeclarations().get(1).getEPackage();
}
项目:xtext-core    文件:XtextFormatterTest.java   
@Override
public void setUp() throws Exception {
    super.setUp();
    with(new XtextStandaloneSetup() {
        @Override
        public Injector createInjector() {
            return Guice.createInjector(new org.eclipse.xtext.XtextRuntimeModule() {
                @SuppressWarnings("unused")
                public Class<? extends ILineSeparatorInformation> bindILineSeparatorInformation() {
                    return FormatterTestLineSeparatorInformation.class;
                }
            });
        }
    });
    get(FormatterTestLineSeparatorInformation.class).setLineSeparator("\n");
}
项目:xtext-core    文件:ParsetreeUtilTest.java   
@Override
public void setUp() throws Exception {
    super.setUp();
    with(XtextStandaloneSetup.class);
    modelAsString = "\n" +
            "grammar org.eclipse.xtext.parsetree.impl.LineTestLanguage with org.eclipse.xtext.common.Terminals\n" +
            "\n" +
            "generate testLanguage \"http://www.eclipse.org/2009/tmf/xtext/ParsetreeUtilTest\"\n" +
            " \n" +
            "Model:\n" +
            "  name=ID\n" +
            ";\n" +
            "\n" +
            "\n";
    grammar = (Grammar) getModel(modelAsString);
    grammarNode = NodeModelUtils.getNode(grammar);
    metamodelNode = NodeModelUtils.getNode(grammar.getMetamodelDeclarations().get(0));
    parentMetamodelNode = metamodelNode.getParent();
}
项目:xtext-core    文件:DeclarativeValueConverterServiceTest.java   
@Override
public void setUp() throws Exception {
    super.setUp();
    with(new XtextStandaloneSetup() {
        @Override
        public Injector createInjector() {
            return Guice.createInjector(new org.eclipse.xtext.XtextRuntimeModule() {
                @SuppressWarnings("unused")
                public DeclarativeValueConverterServiceTest bindTest() {
                    return DeclarativeValueConverterServiceTest.this;
                }
            });
        }
    });

}
项目:xtext-core    文件:GrammarUtilTest.java   
@Test
public void testFindCurrentType_01() 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;");
  _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("Rule", currentType.getName());
}
项目:xtext-core    文件:GrammarUtilTest.java   
@Test
public void testFindCurrentType_02() 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 {SubRule.named=current};");
  _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());
}
项目:xtext-core    文件:GrammarUtilTest.java   
@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());
}
项目:xtext-core    文件:GrammarUtilTest.java   
@Test
public void testFindCurrentType_04() 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("Rule", currentType.getName());
}
项目:xtext-core    文件:GrammarUtilTest.java   
@Test
public void testFindRuleByName() 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("name=ID;");
  _builder.newLine();
  _builder.append("terminal STRING: \'\"\';");
  _builder.newLine();
  String model = _builder.toString();
  XtextResource r = this.getResourceFromString(model);
  EObject _get = r.getContents().get(0);
  Grammar grammar = ((Grammar) _get);
  Assert.assertEquals(grammar, GrammarUtil.findRuleForName(grammar, "Rule").eContainer());
  Assert.assertNull(GrammarUtil.findRuleForName(grammar, "org.eclipse.xtext.common.Terminals.Rule"));
  Assert.assertEquals(IterableExtensions.<Grammar>head(grammar.getUsedGrammars()), GrammarUtil.findRuleForName(grammar, "ID").eContainer());
  Assert.assertEquals(grammar, GrammarUtil.findRuleForName(grammar, "STRING").eContainer());
  Assert.assertEquals(IterableExtensions.<Grammar>head(grammar.getUsedGrammars()), GrammarUtil.findRuleForName(grammar, "org.eclipse.xtext.common.Terminals.STRING").eContainer());
}
项目:xtext-extras    文件:XtextInjectorProvider.java   
@Override
public Injector getInjector() {
    if (injector == null) {
        stateBeforeInjectorCreation = GlobalRegistries.makeCopyOfGlobalState();
        this.injector = new XtextStandaloneSetup().createInjectorAndDoEMFRegistration();
        stateAfterInjectorCreation = GlobalRegistries.makeCopyOfGlobalState();
    }
    return injector;
}
项目:xtext-extras    文件:Xtext2EcoreTransformerTest.java   
@Override
public void setUp() throws Exception {
  super.setUp();
  EPackage.Registry.INSTANCE.put(TypesPackage.eNS_URI, TypesPackage.eINSTANCE);
  TestErrorAcceptor _testErrorAcceptor = new TestErrorAcceptor();
  this.errorAcceptorMock = _testErrorAcceptor;
  EcoreSupportStandaloneSetup.setup();
  this.with(XtextStandaloneSetup.class);
}
项目:Vitruv    文件:MappingsLanguageExtendedGenerator.java   
public MappingsLanguageExtendedGenerator() {
        new XtextStandaloneSetup() {
            public Injector createInjector() {
                return Guice.createInjector(new XtextRuntimeModule() {
                    public void configureIXtext2EcorePostProcessor(com.google.inject.Binder binder) {
//                      binder.bind(IXtext2EcorePostProcessor.class).to(ReactionsLanguageXtext2EcorePostProcessor.class);
                    };
                });             
            };          
        }.createInjectorAndDoEMFRegistration();
    }
项目:Vitruv    文件:ReactionsLanguageExtendedGenerator.java   
public ReactionsLanguageExtendedGenerator() {
    new XtextStandaloneSetup() {
        public Injector createInjector() {
            return Guice.createInjector(new XtextRuntimeModule() {
                public void configureIXtext2EcorePostProcessor(com.google.inject.Binder binder) {
                    binder.bind(IXtext2EcorePostProcessor.class).to(ReactionsLanguageXtext2EcorePostProcessor.class);
                };
            });             
        };          
    }.createInjectorAndDoEMFRegistration();
}
项目:xtext-core    文件:TerminalRuleToLexerBodyTest.java   
@Override
public void setUp() throws Exception {
    super.setUp();
    with(XtextStandaloneSetup.class);
    String model = "grammar foo\n" +
            "generate fooModel 'uri' as foo\n" +
            "import 'http://www.eclipse.org/emf/2002/Ecore' as ecore\n" +
            "Model returns foo::Model: name=ADA_STRING\n;" +
            "terminal ADA_STRING: '\"' ((!'\"')|'\"\"')* '\"'\n;" +
            "terminal WORKAROUND_STRING: '\"' ((!'\"')|'\"''\"')* '\"'\n;";
    grammar = (Grammar) getModel(model);
    adaString = (TerminalRule) GrammarUtil.findRuleForName(grammar, "ADA_STRING");
    workaroundString = (TerminalRule) GrammarUtil.findRuleForName(grammar, "WORKAROUND_STRING");
}
项目:xtext-core    文件:ValidatorTesterTest.java   
@Override
public void setUp() throws Exception {
    super.setUp();
    with(XtextStandaloneSetup.class);
    TestingValidator validator = get(TestingValidator.class);
    tester = new ValidatorTester<TestingValidator>(validator, getInjector());
}
项目:xtext-core    文件:MultiGenMMTest.java   
@Override
public void setUp() throws Exception {
    super.setUp();
    with(new XtextStandaloneSetup());

    with(new MultiGenMMTestLanguageStandaloneSetup());
}
项目:xtext-core    文件:AbstractXtextInspectorTest.java   
@Override
public void setUp() throws Exception {
    super.setUp();
    with(XtextStandaloneSetup.class);
    warnings = Lists.newArrayList();
    errors = Lists.newArrayList();
    infos = Lists.newArrayList();
}
项目:xtext-core    文件:XtextScopingTest.java   
@Override
public void setUp() throws Exception {
    super.setUp();
    with(XtextStandaloneSetup.class);
    XtextResourceSet resourceSet = get(XtextResourceSet.class);
    resourceSet.setClasspathURIContext(getClass().getClassLoader());
    Resource resource = resourceSet.getResource(
            URI.createURI("classpath:/org/eclipse/xtext/grammarinheritance/ConcreteTestLanguage.xtext"), true);
    grammar = (Grammar) resource.getContents().get(0);
}
项目:xtext-core    文件:PartialParserTest.java   
@Test public void testReparseEmptyString() throws Exception {
    with(XtextStandaloneSetup.class);
    String model = "grammar org.eclipse.Bug273209_01 with org.eclipse.xtext.common.Terminals \n" +
    "generate testLanguage 'http://www.eclipse.org/2009/tmf/xtext/partialParsing/Bug273209/3'\n" +
    "Model : \n" +
    "        ('model' ':' name=ID ';'*);";
    XtextResource resource = getResourceFromString(model);
    assertTrue(resource.getErrors().toString(), resource.getErrors().isEmpty());
    resource.update(0, model.length(), "");
    assertTrue(resource.getContents().isEmpty());
}
项目:xtext-core    文件:MetamodelTransformationErrorTest.java   
@Override
public void setUp() throws Exception {
    super.setUp();
    with(XtextStandaloneSetup.class);
    model = "grammar datatypetests with org.eclipse.xtext.common.Terminals\n"
            + "import 'http://www.eclipse.org/emf/2002/Ecore' as ecore\n" + "generate metamodel 'http://fooo'\n"
            + "Start:\n" + "  id=ValidId id2=ValidId2 failure1=FailureId failure2=Failure2;\n"
            + "ValidId returns ecore::EString: ID '.' ID;\n" + "ValidId2 returns ecore::EString: ID '.' ValidId;\n"
            + "FailureId returns ecore::EString: name=ID;\n" + "Failure2 returns ecore::EString: name=Start;";
    resource = getResourceFromStringAndExpect(model, 2);
    grammar = (Grammar) resource.getContents().get(0);
    transformer = new Xtext2EcoreTransformer(grammar);
    errorAcceptor = new TestErrorAcceptor();
    transformer.setErrorAcceptor(errorAcceptor);
}
项目:xtext-core    文件:ExternalContentSupportTest.java   
@Override
public void setUp() throws Exception {
    super.setUp();
    with(XtextStandaloneSetup.class);
    uriToContent = Maps.newHashMap();
    support = new ExternalContentSupport();
}
项目:xtext-core    文件:UriBasedReaderTest.java   
@Test public void testMissingUri() throws Exception {
    UriBasedReader reader = new UriBasedReader();
    reader.setClasspathURIContext(getClass());
    reader.addRegister(new XtextStandaloneSetup());
    //      reader.setUri("classpath:/"+getClass().getName().replace('.', '/')+".xtext");
    IssuesImpl issues = new IssuesImpl();
    reader.checkConfiguration(issues);
    assertTrue(issues.hasErrors());
}
项目:xtext-core    文件:IDValueConverterTest.java   
@Override
public void setUp() throws Exception {
    super.setUp();
    with(XtextStandaloneSetup.class);
    idConverter = get(IDValueConverter.class);
    idConverter.setRule(GrammarUtil.findRuleForName(getGrammarAccess().getGrammar(), "ID"));
}
项目:xtext-core    文件:IgnoreCaseIDValueConverterTest.java   
@Override
public void setUp() throws Exception {
    super.setUp();
    with(XtextStandaloneSetup.class);
    idConverter = get(IgnoreCaseIDValueConverter.class);
    idConverter.setRule(GrammarUtil.findRuleForName(getGrammarAccess().getGrammar(), "ID"));
}
项目:xtext-core    文件:STRINGConverterTest.java   
@Override
public void setUp() throws Exception {
    super.setUp();
    with(XtextStandaloneSetup.class);
    valueConverter = get(STRINGValueConverter.class);
    valueConverter.setRule(GrammarUtil.findRuleForName(getGrammarAccess().getGrammar(), "STRING"));
}
项目:xtext-core    文件:INTValueConverterTest.java   
@Override
public void setUp() throws Exception {
    super.setUp();
    with(XtextStandaloneSetup.class);
    valueConverter = get(INTValueConverter.class);
    valueConverter.setRule(GrammarUtil.findRuleForName(getGrammarAccess().getGrammar(), "INT"));
}
项目:xtext-core    文件:XtextInjectorProvider.java   
@Override
public Injector getInjector() {
    if (injector == null) {
        stateBeforeInjectorCreation = GlobalRegistries.makeCopyOfGlobalState();
        this.injector = new XtextStandaloneSetup().createInjectorAndDoEMFRegistration();
        stateAfterInjectorCreation = GlobalRegistries.makeCopyOfGlobalState();
    }
    return injector;
}
项目:xtext-core    文件:Bug281990Test.java   
@Override
public void setUp() throws Exception {
    super.setUp();
    XtextStandaloneSetup.doSetup();
    with(new LazyLinkingTestLanguageRuntimeModule() {
        @Override
        public Class<? extends IScopeProvider> bindIScopeProvider() {
            return org.eclipse.xtext.linking.lazy.Bug281990Test.RecursiveScopeProvider.class;
        }
    });
    new LazyLinkingTestLanguageStandaloneSetup().register(getInjector());
}
项目:xtext-core    文件:Xtext2EcoreTransformerTest.java   
@Override
public void setUp() throws Exception {
  super.setUp();
  TestErrorAcceptor _testErrorAcceptor = new TestErrorAcceptor();
  this.errorAcceptorMock = _testErrorAcceptor;
  this.with(XtextStandaloneSetup.class);
}
项目:xtext-core    文件:ReducedXtextResourceValidatorTest.java   
@Override
public void setUp() throws Exception {
  super.setUp();
  XtextStandaloneSetup _xtextStandaloneSetup = new XtextStandaloneSetup();
  this.with(_xtextStandaloneSetup);
  this.resourceValidator = this.<ReducedXtextResourceValidator>get(ReducedXtextResourceValidator.class);
}
项目:xtext-core    文件:GrammarUtilTest.java   
@Test
public void testFindCurrentType_05() 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>head(grammar.getRules());
  final AbstractElement fragmentCall = rule.getAlternatives();
  final EClassifier currentType = GrammarUtil.findCurrentType(fragmentCall);
  Assert.assertEquals("Rule", currentType.getName());
}
项目:xtext-core    文件:GrammarUtilTest.java   
@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());
}
项目:xtext-core    文件:GrammarUtilTest.java   
@Test
public void testAllRules() 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("name=super::STRING;");
  _builder.newLine();
  _builder.append("terminal STRING: \'\"\';");
  _builder.newLine();
  String model = _builder.toString();
  final XtextResource r = this.getResourceFromString(model);
  EObject _get = r.getContents().get(0);
  final Grammar grammar = ((Grammar) _get);
  final List<AbstractRule> allRules = GrammarUtil.allRules(grammar);
  final Function1<AbstractRule, String> _function = (AbstractRule it) -> {
    return it.getName();
  };
  Assert.assertEquals(
    Collections.<String>unmodifiableList(CollectionLiterals.<String>newArrayList("Rule", "STRING", "ID", "INT", "STRING", "ML_COMMENT", "SL_COMMENT", "WS", "ANY_OTHER")).toString(), 
    ListExtensions.<AbstractRule, String>map(allRules, _function).toString());
}
项目:xtext-core    文件:GrammarUtilTest.java   
@Test
public void testAllMetamodelDeclarations_01() throws Exception {
  this.with(XtextStandaloneSetup.class);
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("grammar foo with org.eclipse.xtext.common.Terminals");
  _builder.newLine();
  _builder.append("import \'http://www.eclipse.org/emf/2002/Ecore\' as ecore");
  _builder.newLine();
  _builder.append("generate g \'http://3\' as ecore");
  _builder.newLine();
  _builder.append("startrule returns ecore::startrule: name=ID;");
  _builder.newLine();
  String model = _builder.toString();
  Resource r = this.getResourceFromString(model);
  EObject _get = r.getContents().get(0);
  Grammar g = ((Grammar) _get);
  List<AbstractMetamodelDeclaration> decls = GrammarUtil.allMetamodelDeclarations(g);
  Assert.assertEquals(2, decls.size());
  AbstractMetamodelDeclaration decl = decls.get(0);
  Assert.assertTrue((decl instanceof ReferencedMetamodel));
  Assert.assertNotNull(decl.getEPackage());
  Assert.assertEquals("http://www.eclipse.org/emf/2002/Ecore", decl.getEPackage().getNsURI());
  Assert.assertEquals("ecore", decl.getAlias());
  decl = decls.get(1);
  Assert.assertEquals("ecore", decl.getAlias());
  Assert.assertNotNull(decl.getEPackage());
  Assert.assertEquals("http://3", decl.getEPackage().getNsURI());
}
项目:xtext-core    文件:GrammarUtilTest.java   
@Test
public void testAllMetamodelDeclarations_02() throws Exception {
  this.with(XtextStandaloneSetup.class);
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("grammar foo with org.eclipse.xtext.common.Terminals");
  _builder.newLine();
  _builder.append("import \'http://www.eclipse.org/emf/2002/Ecore\' as bar");
  _builder.newLine();
  _builder.append("generate g \'http://3\' as bar");
  _builder.newLine();
  _builder.append("startrule returns bar::startrule: name=ID;");
  _builder.newLine();
  String model = _builder.toString();
  Resource r = this.getResourceFromString(model);
  EObject _get = r.getContents().get(0);
  Grammar g = ((Grammar) _get);
  List<AbstractMetamodelDeclaration> decls = GrammarUtil.allMetamodelDeclarations(g);
  Assert.assertEquals(3, decls.size());
  AbstractMetamodelDeclaration decl = decls.get(0);
  Assert.assertTrue((decl instanceof ReferencedMetamodel));
  Assert.assertNotNull(decl.getEPackage());
  Assert.assertEquals("http://www.eclipse.org/emf/2002/Ecore", decl.getEPackage().getNsURI());
  Assert.assertEquals("bar", decl.getAlias());
  decl = decls.get(1);
  Assert.assertEquals("bar", decl.getAlias());
  Assert.assertNotNull(decl.getEPackage());
  Assert.assertEquals("http://3", decl.getEPackage().getNsURI());
  decl = decls.get(2);
  Assert.assertTrue((decl instanceof ReferencedMetamodel));
  Assert.assertNotNull(decl.getEPackage());
  Assert.assertEquals("http://www.eclipse.org/emf/2002/Ecore", decl.getEPackage().getNsURI());
  Assert.assertEquals("ecore", decl.getAlias());
  AbstractRule abstractRule = g.getRules().get(0);
  Assert.assertSame(decls.get(1), abstractRule.getType().getMetamodel());
}
项目:xtext-core    文件:GrammarUtilTest.java   
@Test
public void testAllMetamodelDeclarations_03() throws Exception {
  this.with(XtextStandaloneSetup.class);
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("grammar foo with org.eclipse.xtext.common.Terminals");
  _builder.newLine();
  _builder.append("generate g \'http://3\' as bar");
  _builder.newLine();
  _builder.append("import \'http://www.eclipse.org/emf/2002/Ecore\' as bar");
  _builder.newLine();
  _builder.append("startrule returns bar::startrule: name=ID;");
  _builder.newLine();
  String model = _builder.toString();
  Resource r = this.getResourceFromString(model);
  EObject _get = r.getContents().get(0);
  Grammar g = ((Grammar) _get);
  List<AbstractMetamodelDeclaration> decls = GrammarUtil.allMetamodelDeclarations(g);
  Assert.assertEquals(3, decls.size());
  AbstractMetamodelDeclaration decl = decls.get(0);
  Assert.assertTrue((decl instanceof GeneratedMetamodel));
  Assert.assertEquals("bar", decl.getAlias());
  Assert.assertNotNull(decl.getEPackage());
  Assert.assertEquals("http://3", decl.getEPackage().getNsURI());
  decl = decls.get(1);
  Assert.assertTrue((decl instanceof ReferencedMetamodel));
  Assert.assertNotNull(decl.getEPackage());
  Assert.assertEquals("http://www.eclipse.org/emf/2002/Ecore", decl.getEPackage().getNsURI());
  Assert.assertEquals("bar", decl.getAlias());
  decl = decls.get(2);
  Assert.assertTrue((decl instanceof ReferencedMetamodel));
  Assert.assertNotNull(decl.getEPackage());
  Assert.assertEquals("http://www.eclipse.org/emf/2002/Ecore", decl.getEPackage().getNsURI());
  Assert.assertEquals("ecore", decl.getAlias());
  AbstractRule abstractRule = g.getRules().get(0);
  Assert.assertSame(decls.get(0), abstractRule.getType().getMetamodel());
}