Search in sources :

Example 6 with EDataType

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

the class EcoreUtil2Test method testGetCompatibleType_06.

@Test
public void testGetCompatibleType_06() {
    EDataType aCharSequence = createEDataType("a", CharSequence.class);
    EDataType anAppendable = createEDataType("b", Appendable.class);
    assertSame(null, EcoreUtil2.getCompatibleType(aCharSequence, anAppendable));
    assertSame(null, EcoreUtil2.getCompatibleType(anAppendable, aCharSequence));
}
Also used : EDataType(org.eclipse.emf.ecore.EDataType) Test(org.junit.Test)

Example 7 with EDataType

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

the class EcoreUtil2Test method testGetCompatibleType_02.

@Test
public void testGetCompatibleType_02() {
    EDataType aString = createEDataType("a", String.class);
    EDataType anObject = createEDataType("b", Object.class);
    assertSame(anObject, EcoreUtil2.getCompatibleType(aString, anObject, null));
    assertSame(anObject, EcoreUtil2.getCompatibleType(anObject, aString, null));
}
Also used : EDataType(org.eclipse.emf.ecore.EDataType) Test(org.junit.Test)

Example 8 with EDataType

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

the class TreeConstructionReportImpl method getDiagnosticMessage.

protected String getDiagnosticMessage(AssignmentToken token) {
    Assignment ass = (Assignment) token.getGrammarElement();
    Object value = token.getEObjectConsumer().getConsumable(ass.getFeature(), false);
    if (value == null) {
        EStructuralFeature f = token.getEObjectConsumer().getEObject().eClass().getEStructuralFeature(ass.getFeature());
        if (f == null)
            return "The current object of type '" + token.getEObjectConsumer().getEObject().eClass().getName() + "' does not have a feature named '" + ass.getFeature() + "'";
        String cls = f.getEContainingClass() == token.getEObjectConsumer().getEObject().eClass() ? f.getEContainingClass().getName() : f.getEContainingClass().getName() + "(" + token.getEObjectConsumer().getEObject().eClass().getName() + ")";
        String feat = cls + "." + f.getName();
        if (f.isMany()) {
            int size = ((List<?>) token.getEObjectConsumer().getEObject().eGet(f)).size();
            return "All " + size + " values of " + feat + " have been consumed. " + "More are needed to continue here.";
        } else
            return feat + " is not set.";
    } else {
        ErrorAcceptor err = new ErrorAcceptor();
        for (RuleCall ruleCall : GrammarUtil.containedRuleCalls(token.getGrammarElement())) {
            if (ruleCall.getRule() instanceof EnumRule) {
                if (enumSerializer.isValid(token.getEObject(), ruleCall, value, err))
                    return null;
            } else if (ruleCall.getRule().getType().getClassifier() instanceof EDataType) {
                if (valueSerializer.isValid(token.getEObject(), ruleCall, value, err))
                    return null;
            }
        }
        return err.getMessage();
    }
}
Also used : Assignment(org.eclipse.xtext.Assignment) EnumRule(org.eclipse.xtext.EnumRule) EDataType(org.eclipse.emf.ecore.EDataType) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) EObject(org.eclipse.emf.ecore.EObject) ArrayList(java.util.ArrayList) List(java.util.List) IErrorAcceptor(org.eclipse.xtext.parsetree.reconstr.ITokenSerializer.IErrorAcceptor) RuleCall(org.eclipse.xtext.RuleCall)

Example 9 with EDataType

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

the class EcoreUtil2 method getCompatibleType.

/**
 * @since 2.1
 */
public static EClassifier getCompatibleType(EClassifier typeA, EClassifier typeB, EObject grammarContext) {
    if (typeA.equals(typeB))
        return typeA;
    if (typeA instanceof EDataType && typeB instanceof EDataType) {
        Class<?> instanceClassA = typeA.getInstanceClass();
        Class<?> instanceClassB = typeB.getInstanceClass();
        if (instanceClassA != null && instanceClassB != null) {
            if (instanceClassA.isAssignableFrom(instanceClassB))
                return typeA;
            if (instanceClassB.isAssignableFrom(instanceClassA))
                return typeB;
        }
    }
    // no common type for simple datatypes available
    if (!(typeA instanceof EClass && typeB instanceof EClass))
        return null;
    List<EClass> sortedCandidates = getSortedCommonCompatibleTypeCandidates((EClass) typeA, (EClass) typeB);
    for (EClass candidate : sortedCandidates) if (isCommonCompatibleType(candidate, sortedCandidates))
        return candidate;
    EClass result = GrammarUtil.findEObject(GrammarUtil.getGrammar(grammarContext));
    return result;
}
Also used : EClass(org.eclipse.emf.ecore.EClass) EDataType(org.eclipse.emf.ecore.EDataType)

Example 10 with EDataType

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

the class ScopesTest method testWithDifferentElements.

@Test
public void testWithDifferentElements() throws Exception {
    EAttribute attr = EcoreFactory.eINSTANCE.createEAttribute();
    attr.setName("Foo");
    EDataType datatype = EcoreFactory.eINSTANCE.createEDataType();
    datatype.setName("Bar");
    ArrayList<EObject> list = new ArrayList<EObject>();
    list.add(attr);
    list.add(EcoreFactory.eINSTANCE.createEObject());
    list.add(datatype);
    Iterable<IEObjectDescription> iterable = Scopes.scopedElementsFor(list);
    Iterator<IEObjectDescription> iterator = iterable.iterator();
    IEObjectDescription next = iterator.next();
    assertEquals(FOO, next.getName());
    assertEquals(attr, next.getEObjectOrProxy());
    next = iterator.next();
    assertEquals(BAR, next.getName());
    assertEquals(datatype, next.getEObjectOrProxy());
    assertFalse(iterator.hasNext());
}
Also used : EAttribute(org.eclipse.emf.ecore.EAttribute) EDataType(org.eclipse.emf.ecore.EDataType) EObject(org.eclipse.emf.ecore.EObject) ArrayList(java.util.ArrayList) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription) Test(org.junit.Test)

Aggregations

EDataType (org.eclipse.emf.ecore.EDataType)25 Test (org.junit.Test)10 EObject (org.eclipse.emf.ecore.EObject)8 EClassifier (org.eclipse.emf.ecore.EClassifier)7 EClass (org.eclipse.emf.ecore.EClass)5 EAttribute (org.eclipse.emf.ecore.EAttribute)3 AbstractRule (org.eclipse.xtext.AbstractRule)3 ArrayList (java.util.ArrayList)2 EPackage (org.eclipse.emf.ecore.EPackage)2 EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)2 Grammar (org.eclipse.xtext.Grammar)2 RuleCall (org.eclipse.xtext.RuleCall)2 IEObjectDescription (org.eclipse.xtext.resource.IEObjectDescription)2 Collection (java.util.Collection)1 List (java.util.List)1 BasicDiagnostic (org.eclipse.emf.common.util.BasicDiagnostic)1 DiagnosticChain (org.eclipse.emf.common.util.DiagnosticChain)1 URI (org.eclipse.emf.common.util.URI)1 EEnum (org.eclipse.emf.ecore.EEnum)1 EEnumLiteral (org.eclipse.emf.ecore.EEnumLiteral)1