Search in sources :

Example 86 with EClassifier

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);
}
Also used : EClass(org.eclipse.emf.ecore.EClass) StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) EClassifier(org.eclipse.emf.ecore.EClassifier) TypeReference(org.eclipse.xtext.xtext.generator.model.TypeReference) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) AbstractRule(org.eclipse.xtext.AbstractRule)

Example 87 with EClassifier

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);
                    }
                }
            }
        }
    }
}
Also used : Assignment(org.eclipse.xtext.Assignment) ParserRule(org.eclipse.xtext.ParserRule) AbstractElement(org.eclipse.xtext.AbstractElement) EObject(org.eclipse.emf.ecore.EObject) EClassifier(org.eclipse.emf.ecore.EClassifier) AbstractRule(org.eclipse.xtext.AbstractRule) RuleCall(org.eclipse.xtext.RuleCall)

Example 88 with EClassifier

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;
}
Also used : EClass(org.eclipse.emf.ecore.EClass) EClassifier(org.eclipse.emf.ecore.EClassifier) EPackage(org.eclipse.emf.ecore.EPackage)

Example 89 with EClassifier

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);
    }
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) EClass(org.eclipse.emf.ecore.EClass) Action(org.eclipse.xtext.Action) EObject(org.eclipse.emf.ecore.EObject) EClassifier(org.eclipse.emf.ecore.EClassifier) Grammar(org.eclipse.xtext.Grammar) XtextSwitch(org.eclipse.xtext.util.XtextSwitch)

Example 90 with EClassifier

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);
}
Also used : EClass(org.eclipse.emf.ecore.EClass) EObject(org.eclipse.emf.ecore.EObject) EClassifier(org.eclipse.emf.ecore.EClassifier) Statechart(org.yakindu.sct.model.sgraph.Statechart) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

EClassifier (org.eclipse.emf.ecore.EClassifier)153 EClass (org.eclipse.emf.ecore.EClass)94 Test (org.junit.Test)36 EPackage (org.eclipse.emf.ecore.EPackage)32 EReference (org.eclipse.emf.ecore.EReference)22 EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)16 AbstractRule (org.eclipse.xtext.AbstractRule)14 EDataType (org.eclipse.emf.ecore.EDataType)13 EObject (org.eclipse.emf.ecore.EObject)13 XtextResource (org.eclipse.xtext.resource.XtextResource)10 EAttribute (org.eclipse.emf.ecore.EAttribute)8 EEnum (org.eclipse.emf.ecore.EEnum)8 Grammar (org.eclipse.xtext.Grammar)8 ParserRule (org.eclipse.xtext.ParserRule)8 ArrayList (java.util.ArrayList)7 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)7 Assignment (org.eclipse.xtext.Assignment)7 IScope (org.eclipse.xtext.scoping.IScope)6 HashSet (java.util.HashSet)5 BimserverDatabaseException (org.bimserver.BimserverDatabaseException)5