use of org.eclipse.emf.ecore.EClassifier in project xtext-core by eclipse.
the class Junit4Fragment2 method generateExampleRuntimeTest.
protected JavaFileAccess generateExampleRuntimeTest() {
String _testingPackage = this.getTestingPackage();
String _plus = (_testingPackage + ".XtextRunner");
final TypeReference xtextRunner = new TypeReference(_plus);
final TypeReference runWith = new TypeReference("org.junit.runner.RunWith");
String _testingPackage_1 = this.getTestingPackage();
String _plus_1 = (_testingPackage_1 + ".InjectWith");
final TypeReference injectWith = new TypeReference(_plus_1);
String _testingPackage_2 = this.getTestingPackage();
String _plus_2 = (_testingPackage_2 + ".util.ParseHelper");
final TypeReference parseHelper = new TypeReference(_plus_2);
final TypeReference test = new TypeReference("org.junit.Test");
final TypeReference assert_ = new TypeReference("org.junit.Assert");
EClassifier _classifier = IterableExtensions.<AbstractRule>head(this.getGrammar().getRules()).getType().getClassifier();
ResourceSet _resourceSet = this.getGrammar().eResource().getResourceSet();
final TypeReference rootType = new TypeReference(((EClass) _classifier), _resourceSet);
TypeReference _exampleRuntimeTest = this.exampleRuntimeTest();
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append("@");
_builder.append(runWith);
_builder.append("(");
_builder.append(xtextRunner);
_builder.append(")");
_builder.newLineIfNotEmpty();
_builder.append("@");
_builder.append(injectWith);
_builder.append("(");
TypeReference _injectorProvider = Junit4Fragment2.this.injectorProvider();
_builder.append(_injectorProvider);
_builder.append(")");
_builder.newLineIfNotEmpty();
_builder.append("class ");
TypeReference _exampleRuntimeTest = Junit4Fragment2.this.exampleRuntimeTest();
_builder.append(_exampleRuntimeTest);
_builder.append(" {");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("@");
_builder.append(Inject.class, "\t");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append(parseHelper, "\t");
_builder.append("<");
_builder.append(rootType, "\t");
_builder.append("> parseHelper");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("@");
_builder.append(test, "\t");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("def void loadModel() {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("val result = parseHelper.parse(\'\'");
_builder.append("\'");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("Hello Xtext!");
_builder.newLine();
_builder.append("\t\t");
_builder.append("\'\'");
_builder.append("\')");
_builder.newLine();
_builder.append("\t\t");
_builder.append(assert_, "\t\t");
_builder.append(".assertNotNull(result)");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("val errors = result.eResource.errors");
_builder.newLine();
_builder.append("\t\t");
_builder.append(assert_, "\t\t");
_builder.append(".assertTrue(\'\'");
_builder.append("\'Unexpected errors: ");
_builder.append("�", "\t\t");
_builder.append("errors.join(\", \")");
_builder.append("�", "\t\t");
_builder.append("\'\'");
_builder.append("\', errors.isEmpty)");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
}
};
return this.fileAccessFactory.createXtendFile(_exampleRuntimeTest, _client);
}
use of org.eclipse.emf.ecore.EClassifier in project n4js by eclipse.
the class TokenTypeRewriter method rewriteNumberLiterals.
private static void rewriteNumberLiterals(N4JSGrammarAccess ga, ImmutableMap.Builder<AbstractElement, Integer> builder) {
for (ParserRule rule : GrammarUtil.allParserRules(ga.getGrammar())) {
for (EObject obj : EcoreUtil2.eAllContents(rule.getAlternatives())) {
if (obj instanceof Assignment) {
Assignment assignment = (Assignment) obj;
AbstractElement terminal = assignment.getTerminal();
if (terminal instanceof RuleCall) {
AbstractRule calledRule = ((RuleCall) terminal).getRule();
EClassifier classifier = calledRule.getType().getClassifier();
if (classifier == EcorePackage.Literals.EBIG_DECIMAL) {
builder.put(assignment, NUMBER_LITERAL_TOKEN);
}
}
}
}
}
}
use of org.eclipse.emf.ecore.EClassifier in project dsl-devkit by dsldevkit.
the class TransformUtil method lookupEClass.
/**
* Looks up an EClass visible in the context of a grammar.
*
* @param grammar
* context grammar
* @param packageName
* package name
* @param className
* class name
* @return EClass or null
*/
public static EClass lookupEClass(final Grammar grammar, final String packageName, final String className) {
EPackage ePackage = lookupEPackage(grammar, packageName);
if (ePackage != null) {
EClassifier eClassifier = ePackage.getEClassifier(className);
if (eClassifier instanceof EClass) {
return (EClass) eClassifier;
}
}
LOG.info("no class found with name " + packageName + "::" + className);
return null;
}
use of org.eclipse.emf.ecore.EClassifier in project dsl-devkit by dsldevkit.
the class GeneratorUtil method collectInstantiatedTypes.
/**
* Collects instantiated EClasses for a grammar and all included grammar recursively.
*
* @param grammar
* Xtext grammar
* @param result
* set to add instantiated types to
*/
private static void collectInstantiatedTypes(final Grammar grammar, final Set<EClass> result) {
XtextSwitch<Void> xtextSwitch = new XtextSwitch<Void>() {
@Override
public Void caseParserRule(final ParserRule object) {
EClassifier eClassifier = object.getType().getClassifier();
if (eClassifier instanceof EClass) {
result.add((EClass) eClassifier);
}
return null;
}
@Override
public Void caseAction(final Action object) {
EClassifier eClassifier = object.getType().getClassifier();
result.add((EClass) eClassifier);
return null;
}
};
for (TreeIterator<EObject> it = EcoreUtil.getAllProperContents(grammar, false); it.hasNext(); ) {
xtextSwitch.doSwitch(it.next());
}
for (Grammar includedGrammar : grammar.getUsedGrammars()) {
collectInstantiatedTypes(includedGrammar, result);
}
}
use of org.eclipse.emf.ecore.EClassifier in project statecharts by Yakindu.
the class SCTUnitClassifierTest method checkEClassesCoveredByTestModels.
@Test
public void checkEClassesCoveredByTestModels() throws Exception {
Set<EClassifier> classifier = new HashSet<EClassifier>();
Iterables.addAll(classifier, SGraphPackage.eINSTANCE.getEClassifiers());
Iterables.addAll(classifier, StextPackage.eINSTANCE.getEClassifiers());
Iterables.addAll(classifier, ExpressionsPackage.eINSTANCE.getEClassifiers());
classifier = Sets.newHashSet(Iterables.filter(classifier, new Predicate<EClassifier>() {
public boolean apply(EClassifier clazz) {
if (clazz instanceof EClass) {
return !((EClass) clazz).isAbstract();
}
return false;
}
}));
// Remove classes to ignore
for (EClassifier eClassifier : IGNORE_ME) {
classifier.remove(eClassifier);
}
// Remove all classes used within SCTUnit tests
List<Statechart> allStatecharts = testModels.loadAllStatecharts();
for (Statechart statechart : allStatecharts) {
TreeIterator<EObject> eAllContents = statechart.eAllContents();
while (eAllContents.hasNext()) {
EClass eClass = eAllContents.next().eClass();
if (classifier.contains(eClass)) {
classifier.remove(eClass);
}
}
}
for (EClassifier current : classifier) {
System.out.println(current.getInstanceTypeName());
}
org.junit.Assert.assertTrue("Classifiers not covered by SCTUnit Tests: " + classifier, classifier.size() == 0);
}
Aggregations