mirror of
https://github.com/sigmasternchen/xtext-core
synced 2025-03-16 16:58:56 +00:00
First shot at XtextMetamodelResource
This commit is contained in:
parent
023d19f60a
commit
38c7352aff
5 changed files with 126 additions and 8 deletions
|
@ -5,7 +5,7 @@
|
|||
<copyright>
|
||||
</copyright>
|
||||
|
||||
$Id: plugin.xml,v 1.3 2008/05/23 08:53:11 jkohnlein Exp $
|
||||
$Id: plugin.xml,v 1.4 2008/10/01 13:40:11 jkohnlein Exp $
|
||||
-->
|
||||
|
||||
<plugin>
|
||||
|
@ -30,5 +30,13 @@
|
|||
class = "org.eclipse.xtext.xtextutil.XtextutilPackage"
|
||||
genModel = "model/parsetree.genmodel" />
|
||||
</extension>
|
||||
|
||||
<!--
|
||||
<extension
|
||||
point="org.eclipse.emf.ecore.extension_parser">
|
||||
<parser
|
||||
class="org.eclipse.xtext.resource.metamodel.XtextMetamodelResourceFactory"
|
||||
type="xtext">
|
||||
</parser>
|
||||
</extension>
|
||||
-->
|
||||
</plugin>
|
||||
|
|
|
@ -12,20 +12,67 @@ import java.io.IOException;
|
|||
import java.io.InputStream;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.emf.common.util.URI;
|
||||
import org.eclipse.emf.ecore.resource.Resource;
|
||||
import org.eclipse.emf.ecore.resource.impl.ResourceImpl;
|
||||
import org.eclipse.xtext.Grammar;
|
||||
import org.eclipse.xtext.IGrammarAccess;
|
||||
import org.eclipse.xtext.service.IServiceScope;
|
||||
import org.eclipse.xtext.service.ServiceRegistry;
|
||||
import org.eclipse.xtext.service.ServiceScopeFactory;
|
||||
import org.eclipse.xtext.services.XtextResourceFactory;
|
||||
|
||||
/**
|
||||
* @author Jan Köhnlein - Initial contribution and API
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class XtextMetamodelResource extends ResourceImpl {
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.emf.ecore.resource.impl.ResourceImpl#doLoad(java.io.InputStream, java.util.Map)
|
||||
public XtextMetamodelResource(URI uri) {
|
||||
super(uri);
|
||||
}
|
||||
|
||||
private Grammar getGrammar(String languageID) {
|
||||
IServiceScope serviceScope = ServiceScopeFactory.get(languageID);
|
||||
IGrammarAccess service = ServiceRegistry.getService(serviceScope, IGrammarAccess.class);
|
||||
return service.getGrammar();
|
||||
}
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* org.eclipse.emf.ecore.resource.impl.ResourceImpl#doLoad(java.io.InputStream
|
||||
* , java.util.Map)
|
||||
*/
|
||||
@Override
|
||||
protected void doLoad(InputStream inputStream, Map<?, ?> options) throws IOException {
|
||||
// TODO: implement
|
||||
super.doLoad(inputStream, options);
|
||||
XtextResourceFactory xtextResourceFactory = new XtextResourceFactory();
|
||||
Resource xtextResource = xtextResourceFactory.createResource(getURI());
|
||||
// xtextResource.load(inputStream, options);
|
||||
// EList<EObject> grammarResourceContents = xtextResource.getContents();
|
||||
// if (grammarResourceContents.size() != 1) {
|
||||
// throw new IllegalStateException("XtextResource " + Strings.notNull(getURI().toString())
|
||||
// + " contains other than 1 elements");
|
||||
// }
|
||||
// EObject firstObject = grammarResourceContents.get(0);
|
||||
// if (!(firstObject instanceof Grammar)) {
|
||||
// throw new IllegalStateException("XtextResource " + Strings.notNull(getURI().toString())
|
||||
// + " does not contain a root element of type Grammar");
|
||||
// }
|
||||
// Grammar grammar = (Grammar) firstObject;
|
||||
// Xtext2EcoreTransformer xtext2EcoreTransformer = new Xtext2EcoreTransformer();
|
||||
// List<EPackage> ePackages = xtext2EcoreTransformer.transform(grammar);
|
||||
// getContents().addAll(ePackages);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.eclipse.emf.ecore.resource.impl.ResourceImpl#doUnload()
|
||||
*/
|
||||
@Override
|
||||
protected void doUnload() {
|
||||
// TODO Auto-generated method stub
|
||||
super.doUnload();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2008 itemis AG (http://www.itemis.eu) and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*******************************************************************************/
|
||||
package org.eclipse.xtext.resource.metamodel;
|
||||
|
||||
import org.eclipse.emf.common.util.URI;
|
||||
import org.eclipse.emf.ecore.resource.Resource;
|
||||
import org.eclipse.emf.ecore.resource.impl.ResourceFactoryImpl;
|
||||
|
||||
/**
|
||||
* @author Jan Köhnlein - Initial contribution and API
|
||||
*/
|
||||
public class XtextMetamodelResourceFactory extends ResourceFactoryImpl {
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.emf.ecore.resource.impl.ResourceFactoryImpl#createResource(org.eclipse.emf.common.util.URI)
|
||||
*/
|
||||
@Override
|
||||
public Resource createResource(URI uri) {
|
||||
// TODO Auto-generated method stub
|
||||
return new XtextMetamodelResource(uri);
|
||||
}
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>org.eclipse.xtext.reference.ui_gen</name>
|
||||
<name>org.eclipse.xtext.generator.tests</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2008 itemis AG (http://www.itemis.eu) and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*******************************************************************************/
|
||||
package org.eclipse.xtext.resource.metamodel;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.eclipse.emf.common.util.EList;
|
||||
import org.eclipse.emf.common.util.URI;
|
||||
import org.eclipse.emf.ecore.EObject;
|
||||
import org.eclipse.emf.ecore.resource.Resource;
|
||||
import org.eclipse.xtext.XtextStandaloneSetup;
|
||||
import org.eclipse.xtext.resource.XtextResourceSet;
|
||||
import org.eclipse.xtext.testlanguages.TestLanguageStandaloneSetup;
|
||||
|
||||
/**
|
||||
* @author Jan Köhnlein - Initial contribution and API
|
||||
*/
|
||||
public class XtextMetamodelResourceTest extends TestCase {
|
||||
|
||||
public void testResourceLoad() throws Exception {
|
||||
XtextStandaloneSetup.doSetup();
|
||||
TestLanguageStandaloneSetup.doSetup();
|
||||
XtextResourceSet rs = new XtextResourceSet();
|
||||
rs.setClasspathURIContext(XtextMetamodelResourceTest.class.getClassLoader());
|
||||
rs.getResourceFactoryRegistry().getExtensionToFactoryMap().put("xtext", new XtextMetamodelResourceFactory());
|
||||
Resource resource = rs.getResource(URI.createURI("classpath:/org/eclipse/xtext/testlanguages/TestLanguage.xtext"), true);
|
||||
EList<EObject> contents = resource.getContents();
|
||||
assertEquals(1, contents.size());
|
||||
fail();
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue