Search in sources :

Example 36 with EClassifier

use of org.eclipse.emf.ecore.EClassifier in project xtext-core by eclipse.

the class Xtext2EcoreInterpretationContext method addFeature.

public void addFeature(Assignment assignment) throws TransformationException {
    final String featureName = assignment.getFeature();
    boolean isMultivalue = GrammarUtil.isMultipleAssignment(assignment);
    boolean isContainment = true;
    EClassifierInfo featureTypeInfo;
    if (GrammarUtil.isBooleanAssignment(assignment)) {
        checkNoFragmentRuleCall(assignment.getTerminal());
        EDataType eBoolean = GrammarUtil.findEBoolean(GrammarUtil.getGrammar(assignment));
        featureTypeInfo = getEClassifierInfoOrThrowException(eBoolean, assignment);
        isMultivalue = false;
    } else {
        AbstractElement terminal = assignment.getTerminal();
        if (terminal == null) {
            throw new TransformationException(TransformationErrorCode.NoSuchTypeAvailable, "Cannot derive type from incomplete assignment.", assignment);
        }
        checkNoFragmentRuleCall(terminal);
        EClassifier type = getTerminalType(terminal);
        isContainment = isContainmentAssignment(assignment);
        featureTypeInfo = getEClassifierInfoOrThrowException(type, assignment);
    }
    addFeature(featureName, featureTypeInfo, isMultivalue, isContainment, assignment);
}
Also used : AbstractElement(org.eclipse.xtext.AbstractElement) EDataType(org.eclipse.emf.ecore.EDataType) EClassifier(org.eclipse.emf.ecore.EClassifier)

Example 37 with EClassifier

use of org.eclipse.emf.ecore.EClassifier in project xtext-core by eclipse.

the class TypeRefImpl method setClassifier.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public void setClassifier(EClassifier newClassifier) {
    EClassifier oldClassifier = classifier;
    classifier = newClassifier;
    if (eNotificationRequired())
        eNotify(new ENotificationImpl(this, Notification.SET, XtextTestPackage.TYPE_REF__CLASSIFIER, oldClassifier, classifier));
}
Also used : ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl) EClassifier(org.eclipse.emf.ecore.EClassifier)

Example 38 with EClassifier

use of org.eclipse.emf.ecore.EClassifier in project xtext-core by eclipse.

the class SlotEntry method findEClasses.

protected Set<EClass> findEClasses(ResourceSet resourceSet, String nsURI2, String typeName2) {
    if (typeName2 == null)
        return Collections.emptySet();
    Set<EClass> result = Sets.newHashSet();
    Set<String> keySet = getNsUris();
    for (String string : keySet) {
        try {
            EPackage ePackage = resourceSet.getPackageRegistry().getEPackage(string);
            if (ePackage != null) {
                EClassifier classifier = ePackage.getEClassifier(typeName2);
                if (classifier instanceof EClass)
                    result.add((EClass) classifier);
            }
        } catch (NoClassDefFoundError e) {
            throw new NoClassDefFoundError("NoClassDefFoundError while loading ePackage: " + string + " - " + e.getMessage());
        }
    }
    if (result.isEmpty()) {
        throw new WorkflowInterruptedException("Couldn't find EClass for name '" + typeName2 + "'.");
    }
    return result;
}
Also used : EClass(org.eclipse.emf.ecore.EClass) WorkflowInterruptedException(org.eclipse.emf.mwe.core.WorkflowInterruptedException) EClassifier(org.eclipse.emf.ecore.EClassifier) EPackage(org.eclipse.emf.ecore.EPackage)

Example 39 with EClassifier

use of org.eclipse.emf.ecore.EClassifier in project xtext-core by eclipse.

the class TreeConstState method getTypesToCheck.

public Collection<TypeRef> getTypesToCheck() {
    Map<EClassifier, TypeRef> localTypes = Maps.newLinkedHashMap();
    for (TypeRef t : sortTypes(getTypes())) if (t != null)
        localTypes.put(t.getClassifier(), t);
    List<TreeConstTransition> incomming = getIncommingWithoutRuleCalls();
    if (incomming.isEmpty())
        return localTypes.values();
    for (TreeConstTransition t : incomming) for (TypeRef r : t.getSource().getTypes()) if (r != null && !localTypes.containsKey(r.getClassifier()))
        return localTypes.values();
    return Collections.emptyList();
}
Also used : TypeRef(org.eclipse.xtext.TypeRef) EClassifier(org.eclipse.emf.ecore.EClassifier)

Example 40 with EClassifier

use of org.eclipse.emf.ecore.EClassifier in project xtext-core by eclipse.

the class GrammarUtilTest method testFindCurrentType_01.

@Test
public void testFindCurrentType_01() throws Exception {
    this.with(XtextStandaloneSetup.class);
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("grammar myLang with org.eclipse.xtext.common.Terminals");
    _builder.newLine();
    _builder.append("generate g \'http://1\'");
    _builder.newLine();
    _builder.append("Rule:");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("Fragment;");
    _builder.newLine();
    _builder.append("fragment Fragment*: name=ID;");
    _builder.newLine();
    String model = _builder.toString();
    final XtextResource r = this.getResourceFromString(model);
    EObject _get = r.getContents().get(0);
    final Grammar grammar = ((Grammar) _get);
    final AbstractRule rule = IterableExtensions.<AbstractRule>head(grammar.getRules());
    final AbstractElement fragmentCall = rule.getAlternatives();
    final EClassifier currentType = GrammarUtil.findCurrentType(fragmentCall);
    Assert.assertEquals("Rule", currentType.getName());
}
Also used : AbstractElement(org.eclipse.xtext.AbstractElement) EObject(org.eclipse.emf.ecore.EObject) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) EClassifier(org.eclipse.emf.ecore.EClassifier) XtextResource(org.eclipse.xtext.resource.XtextResource) Grammar(org.eclipse.xtext.Grammar) AbstractRule(org.eclipse.xtext.AbstractRule) Test(org.junit.Test)

Aggregations

EClassifier (org.eclipse.emf.ecore.EClassifier)192 EClass (org.eclipse.emf.ecore.EClass)132 Test (org.junit.Test)81 EPackage (org.eclipse.emf.ecore.EPackage)75 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)61 EObject (org.eclipse.emf.ecore.EObject)23 EReference (org.eclipse.emf.ecore.EReference)21 AbstractRule (org.eclipse.xtext.AbstractRule)19 EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)18 Grammar (org.eclipse.xtext.Grammar)16 EDataType (org.eclipse.emf.ecore.EDataType)13 XtextResource (org.eclipse.xtext.resource.XtextResource)12 AbstractElement (org.eclipse.xtext.AbstractElement)11 EEnum (org.eclipse.emf.ecore.EEnum)8 ParserRule (org.eclipse.xtext.ParserRule)8 EAttribute (org.eclipse.emf.ecore.EAttribute)7 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)7 AbstractMetamodelDeclaration (org.eclipse.xtext.AbstractMetamodelDeclaration)7 Assignment (org.eclipse.xtext.Assignment)7 ArrayList (java.util.ArrayList)6