Created
December 9, 2013 14:01
-
-
Save balazsgrill/7872651 to your computer and use it in GitHub Desktop.
Textualmodeler example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* | |
*/ | |
package hu.textualmodeler.parser.test; | |
import hu.textualmodeler.grammar.GrammarModel; | |
import hu.textualmodeler.grammar.Terminal; | |
import hu.textualmodeler.parser.AbstractTextualResource; | |
import hu.textualmodeler.parser.BasicFeatureResolver; | |
import hu.textualmodeler.parser.IFeatureResolver; | |
import hu.textualmodeler.parser.grammar.GrammarRegistry; | |
import org.eclipse.emf.common.util.URI; | |
import org.eclipse.emf.ecore.EObject; | |
import org.eclipse.emf.ecore.EStructuralFeature; | |
import people.Human; | |
import people.People; | |
import people.PeoplePackage; | |
/** | |
* Resource implementation for "people" models | |
* | |
*/ | |
public class PeopleResource extends AbstractTextualResource { | |
/** | |
* @param uri | |
*/ | |
public PeopleResource(URI uri) { | |
super(uri); | |
} | |
/* (non-Javadoc) | |
* @see hu.textualmodeler.parser.AbstractTextualResource#loadGrammar() | |
*/ | |
@Override | |
protected GrammarModel loadGrammar() { | |
return GrammarRegistry.getInstance().getGrammar("people"); | |
} | |
private static Human findByName(People people, String name){ | |
for(Human h : people.getPeople()){ | |
if (name.equals(h.getName())){ | |
return h; | |
} | |
} | |
return null; | |
} | |
@Override | |
protected IFeatureResolver createFeatureResolver() { | |
return new BasicFeatureResolver(){ | |
@Override | |
public Object resolve(EObject context, EStructuralFeature feature, | |
Terminal terminal, String value) { | |
if (PeoplePackage.eINSTANCE.getHuman_Father().equals(feature) || PeoplePackage.eINSTANCE.getHuman_Mother().equals(feature)){ | |
People p = (People) context.eContainer(); | |
return findByName(p, value); | |
} | |
return super.resolve(context, feature, terminal, value); | |
} | |
}; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* | |
*/ | |
package hu.textualmodeler.parser.test; | |
import org.eclipse.emf.common.util.URI; | |
import org.eclipse.emf.ecore.resource.Resource; | |
import org.eclipse.emf.ecore.resource.Resource.Factory; | |
/** | |
* Resource factory implementation for "people" models | |
* | |
*/ | |
public class PeopleResourceFactory implements Factory { | |
/* (non-Javadoc) | |
* @see org.eclipse.emf.ecore.resource.Resource.Factory#createResource(org.eclipse.emf.common.util.URI) | |
*/ | |
@Override | |
public Resource createResource(URI uri) { | |
return new PeopleResource(uri); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<?eclipse version="3.4"?> | |
<plugin> | |
<extension | |
point="hu.textualmodeler.grammars"> | |
<grammar | |
id="people" | |
model="people.grammar"> | |
</grammar> | |
</extension> | |
<extension | |
point="org.eclipse.ui.editors"> | |
<editor | |
class="hu.textualmodeler.editor.TextualModelEditor" | |
default="false" | |
extensions="people" | |
id="hu.textualmodeler.parser.test.editor" | |
name="People editor"> | |
</editor> | |
</extension> | |
<extension | |
point="org.eclipse.emf.ecore.extension_parser"> | |
<parser | |
class="hu.textualmodeler.parser.test.PeopleResourceFactory" | |
type="people"> | |
</parser> | |
</extension> | |
</plugin> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment