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));
}
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));
}
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();
}
}
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;
}
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());
}
Aggregations