org.eclipse.xtext.xtext.ecoreInference.Xtext2EcoreTransformer的实例源码

项目:xtext-core    文件XtextLinker.java   
@Override
public void linkModel(EObject model,IDiagnosticConsumer consumer) {
    if (model instanceof Grammar) {
        final Xtext2EcoreTransformer transformer = createTransformer((Grammar) model,consumer);
        //Todo duplicate
        transformer.removeGeneratedPackages();
        super.linkModel(model,consumer);
        updateOverriddenRules((Grammar) model);
        try {
            transformer.transform();
        } catch (Exception e) {
            log.error(e.getMessage(),e);
            consumer.consume(new ExceptionDiagnostic(e),Severity.ERROR);
        }
        if (!model.eResource().eAdapters().contains(packageRemover))
            model.eResource().eAdapters().add(packageRemover);
    } else {
        super.linkModel(model,consumer);
    }
}
项目:xtext-core    文件ToEcoreTrafoTest.java   
@Test public void testAbstractLanguagetometamodel() throws Exception {
    XtextResource r = getResource("classpath:/" + AbstractTestLanguage.class.getName().replace('.','/') + ".xtext");
    Grammar element = (Grammar) r.getParseResult().getRootASTElement();
    if (!r.getErrors().isEmpty()) {
        EList<Diagnostic> errors = r.getErrors();
        for (Diagnostic SyntaxError : errors) {
            logger.debug(SyntaxError.getMessage() + " - " + SyntaxError.getLine());
        }
        fail(errors.toString());
    }
    List<TerminalRule> lexerRules = GrammarUtil.allTerminalRules(element);
    assertEquals(8,lexerRules.size());

    List<EPackage> list = Xtext2EcoreTransformer.doGetGeneratedPackages(element);
    assertNotNull(list);
    assertEquals(0,list.size());
}
项目:xtext-core    文件ToEcoreTrafoTest.java   
@Test public void testConcreteLanguagetometamodel() throws Exception {
    XtextResource r = getResource("classpath:/" + ConcreteTestLanguage.class.getName().replace('.','/') + ".xtext");
    Grammar element = (Grammar) r.getContents().get(0);
    List<TerminalRule> lexerRules = GrammarUtil.allTerminalRules(element);
    assertEquals("Number of lexer-rules in Grammar",9,lexerRules.size());
    List<EPackage> list = Xtext2EcoreTransformer.doGetGeneratedPackages(element);
    EPackage metamodel = list.get(0);
    assertNotNull(metamodel);
    assertNotNull(metamodel.getnsprefix());
    assertNotNull(metamodel.getNsURI());
    assertNotNull(metamodel.getName());
    EList<EClassifier> types = metamodel.getEClassifiers();
    EClass type = (EClass) types.get(1);
    EStructuralFeature feature = type.getEStructuralFeature("elements");
    assertNotNull(feature.getEType());
}
项目:xtext-extras    文件Xtext2EcoreTransformerTest.java   
@Override
public XtextResource doGetResource(final InputStream in,final URI uri) throws Exception {
  XtextResourceSet rs = this.<XtextResourceSet>get(XtextResourceSet.class);
  rs.getURIConverter().getURIMap().put(URI.createPlatformPluginURI("org.eclipse.xtext/",false),URI.createURI("classpath:/"));
  rs.getURIConverter().getURIMap().put(URI.createPlatformPluginURI("org.eclipse.xtext.xbase/",URI.createURI("classpath:/"));
  rs.getURIConverter().getURIMap().put(URI.createPlatformPluginURI("org.eclipse.xtext.common.types/",URI.createURI("classpath:/"));
  rs.getURIConverter().getURIMap().put(URI.createPlatformPluginURI("org.eclipse.emf.ecore/",URI.createURI("classpath:/"));
  rs.getURIConverter().getURIMap().put(URI.createPlatformResourceURI("org.eclipse.xtext.xbase/",URI.createURI("classpath:/"));
  rs.getURIConverter().getURIMap().put(URI.createPlatformResourceURI("org.eclipse.emf.ecore/",URI.createURI("classpath:/"));
  rs.getURIConverter().getURIMap().put(URI.createPlatformResourceURI("org.eclipse.xtext.common.types/",URI.createURI("classpath:/"));
  rs.setClasspathURIContext(this.getClass());
  Resource _createResource = this.getResourceFactory().createResource(uri);
  final XtextResource resource = ((XtextResource) _createResource);
  rs.getResources().add(resource);
  XtextLinker linker = new XtextLinker() {
    @Override
    protected Xtext2EcoreTransformer createTransformer(final Grammar grammar,final IDiagnosticConsumer consumer) {
      Xtext2EcoreTransformer result = super.createTransformer(grammar,consumer);
      ErrorAcceptor _errorAcceptor = result.getErrorAcceptor();
      Xtext2EcoreTransformerTest.MyErrorAcceptor _myErrorAcceptor = new Xtext2EcoreTransformerTest.MyErrorAcceptor(_errorAcceptor,Xtext2EcoreTransformerTest.this.errorAcceptorMock);
      result.setErrorAcceptor(_myErrorAcceptor);
      return result;
    }
  };
  ILinker _linker = resource.getLinker();
  linker.setScopeProvider(((XtextLinker) _linker).getScopeProvider());
  ILinker _linker_1 = resource.getLinker();
  linker.setLinkingService(((Linker) _linker_1).getLinkingService());
  ILinker _linker_2 = resource.getLinker();
  linker.setLinkingHelper(((Linker) _linker_2).getLinkingHelper());
  XtextLinker.PackageRemover _packageRemover = new XtextLinker.PackageRemover();
  linker.setPackageRemover(_packageRemover);
  LinkingDiagnosticmessageProvider _linkingDiagnosticmessageProvider = new LinkingDiagnosticmessageProvider();
  linker.setDiagnosticmessageProvider(_linkingDiagnosticmessageProvider);
  OnChangeevictingCache _onChangeevictingCache = new OnChangeevictingCache();
  linker.setCache(_onChangeevictingCache);
  resource.setLinker(linker);
  resource.load(in,null);
  return resource;
}
项目: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    文件Xtext2EcoreTransformerTest.java   
@Override
public XtextResource doGetResource(final InputStream in,final URI uri) throws Exception {
  XtextResourceSet rs = this.<XtextResourceSet>get(XtextResourceSet.class);
  rs.setClasspathURIContext(this.getClass());
  Resource _createResource = this.getResourceFactory().createResource(uri);
  final XtextResource resource = ((XtextResource) _createResource);
  rs.getResources().add(resource);
  XtextLinker linker = new XtextLinker() {
    @Override
    protected Xtext2EcoreTransformer createTransformer(final Grammar grammar,null);
  return resource;
}
项目:xtext-core    文件Xtext2EcoreTransformerTest.java   
private List<EPackage> getEPackagesFromGrammar(final String xtextGrammar,final int expectedErrors) throws Exception {
  this.errorAcceptorMock.replay();
  EObject _modelAndExpect = this.getModelAndExpect(xtextGrammar,expectedErrors);
  final Grammar grammar = ((Grammar) _modelAndExpect);
  this.errorAcceptorMock.verify();
  final List<EPackage> metamodels = Xtext2EcoreTransformer.doGetGeneratedPackages(grammar);
  Assert.assertNotNull(metamodels);
  return metamodels;
}
项目:xtext-core    文件Xtext2EcoreTransformerTest.java   
@Test
public void testTypesOfImplicitSuperGrammar() throws Exception {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("grammar test with org.eclipse.xtext.common.Terminals");
  _builder.newLine();
  _builder.append("generate test \'http://test\'");
  _builder.newLine();
  _builder.append("MyRule: myFeature=INT;");
  _builder.newLine();
  final String xtextGrammar = _builder.toString();
  EObject _model = this.getModel(xtextGrammar);
  final Grammar grammar = ((Grammar) _model);
  final Xtext2EcoreTransformer transformer = new Xtext2EcoreTransformer(grammar);
  transformer.removeGeneratedPackages();
  transformer.transform();
  final AbstractRule rule = IterableExtensions.<AbstractRule>head(grammar.getRules());
  TypeRef type = rule.getType();
  Assert.assertNotNull(type);
  Assert.assertNotNull(transformer.getEClassifierInfos().getInfo(type));
  AbstractmetamodelDeclaration _get = GrammarUtil.allmetamodelDeclarations(grammar).get(1);
  final Referencedmetamodel referenced = ((Referencedmetamodel) _get);
  Assert.assertNotNull(referenced);
  Assert.assertEquals("ecore",referenced.getAlias());
  Assert.assertNull(transformer.getEClassifierInfos().getInfo(referenced,"EString"));
  Assert.assertNull(transformer.getEClassifierInfos().getInfo(referenced,"EInt"));
  EClassifierInfos parentInfos = IterableExtensions.<EClassifierInfos>head(transformer.getEClassifierInfos().getParents());
  Assert.assertNotNull(parentInfos.getInfo(referenced,"EString"));
  Assert.assertNotNull(parentInfos.getInfo(referenced,"EInt"));
}
项目:xtext-core    文件Xtext2EcoreTransformerTest.java   
@Test
public void testPostProcessorHook() throws Exception {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("grammar test with org.eclipse.xtext.common.Terminals import \'http://www.eclipse.org/emf/2002/Ecore\' as ecore  generate test \'http://test\' MyRule: myFeature=INT;");
  final String xtextGrammar = _builder.toString();
  EObject _model = this.getModel(xtextGrammar);
  final Grammar grammar = ((Grammar) _model);
  final Xtext2EcoreTransformer transformer = new Xtext2EcoreTransformer(grammar);
  AbstractmetamodelDeclaration _get = grammar.getmetamodelDeclarations().get(1);
  Generatedmetamodel testmetamodel = ((Generatedmetamodel) _get);
  final Xtext2EcoreTransformerTest.MockedXtext2EcorePostProcessor postProcessor = new Xtext2EcoreTransformerTest.MockedXtext2EcorePostProcessor(testmetamodel);
  transformer.setPostProcessor(postProcessor);
  transformer.transform();
  Assert.assertEquals("process mthde called once",1,postProcessor.proccessMethCalled());
}
项目:xtext-core    文件XtextLinker.java   
protected Xtext2EcoreTransformer createTransformer(Grammar grammar,IDiagnosticConsumer consumer) {
    final Xtext2EcoreTransformer transformer = new Xtext2EcoreTransformer(grammar);
    transformer.setErrorAcceptor(new TransformationDiagnosticsProducer(consumer));
    transformer.setPostProcessor(postProcessor);
    return transformer;
}

相关文章

买水果
比较全面的redis工具类
gson 反序列化到多态子类
java 版本的 mb_strwidth
JAVA 反转字符串的最快方法,大概比StringBuffer.reverse()性...
com.google.gson.internal.bind.ArrayTypeAdapter的实例源码...