Java Code Examples for org.eclipse.emf.ecore.EClassifier#getInstanceClass()

The following examples show how to use org.eclipse.emf.ecore.EClassifier#getInstanceClass() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EcoreUtil2.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * @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;
}
 
Example 2
Source File: EmfModelsTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
public Class<?> toJavaClass(final EClassifier eClassifier) {
  Class<?> _instanceClass = eClassifier.getInstanceClass();
  boolean _tripleNotEquals = (_instanceClass != null);
  if (_tripleNotEquals) {
    return eClassifier.getInstanceClass();
  }
  return null;
}
 
Example 3
Source File: PackageMetaData.java    From BIMserver with GNU Affero General Public License v3.0 5 votes vote down vote up
private void initEClassClassMap() {
	for (EClassifier eClassifier : ePackage.getEClassifiers()) {
		if (eClassifier instanceof EClass) {
			if (eClassifier.getInstanceClass() != null) {
				EClass eClass = (EClass) eClassifier;
				eClassClassMap.put(eClass, eClass.getInstanceClass());
			}
		}
	}
}
 
Example 4
Source File: GenerateUtils.java    From BIMserver with GNU Affero General Public License v3.0 4 votes vote down vote up
public static String getType(EStructuralFeature eStructuralFeature) {
	boolean embedsReference = eStructuralFeature.getEAnnotation("embedsreference") != null;
	EClassifier eType = eStructuralFeature.getEType();
	if (eStructuralFeature.isMany()) {
		if (eType instanceof EDataType) {
			if (eType == EcorePackage.eINSTANCE.getEString()) {
				return "List<String>";
			} else if (eType == EcorePackage.eINSTANCE.getEInt() || eType == EcorePackage.eINSTANCE.getEIntegerObject()) {
				return "List<Integer>";
			} else if (eType == EcorePackage.eINSTANCE.getELong() || eType == EcorePackage.eINSTANCE.getELongObject()) {
				return "List<Long>";
			} else if (eType == EcorePackage.eINSTANCE.getEDouble() || eType == EcorePackage.eINSTANCE.getEDoubleObject()) {
				return "List<Double>";
			} else if (eType == EcorePackage.eINSTANCE.getEBoolean() || eType == EcorePackage.eINSTANCE.getEBooleanObject()) {
				return "List<Boolean>";
			} else if (eType == EcorePackage.eINSTANCE.getEFloat() || eType == EcorePackage.eINSTANCE.getEFloatObject()) {
				return "List<Float>";
			} else if (eType == EcorePackage.eINSTANCE.getEDate()) {
				return "List<Date>";
			}
		} else if (eType instanceof EClass) {
			if (embedsReference) {
				return "List<S" + eType.getName() + ">";
			} else {
				return "List<Long>";
			}
		}
	} else {
		if (eType instanceof EDataType) {
			if (eType == EcorePackage.eINSTANCE.getEString()) {
				return "String";
			} else if (eType == EcorePackage.eINSTANCE.getEInt() || eType == EcorePackage.eINSTANCE.getEIntegerObject()) {
				return "Integer";
			} else if (eType == EcorePackage.eINSTANCE.getELong() || eType == EcorePackage.eINSTANCE.getELongObject()) {
				return "Long";
			} else if (eType == EcorePackage.eINSTANCE.getEShort() || eType == EcorePackage.eINSTANCE.getEShortObject()) {
				return "Short";
			} else if (eType == EcorePackage.eINSTANCE.getEDouble() || eType == EcorePackage.eINSTANCE.getEDoubleObject()) {
				return "Double";
			} else if (eType == EcorePackage.eINSTANCE.getEBoolean() || eType == EcorePackage.eINSTANCE.getEBooleanObject()) {
				return "Boolean";
			} else if (eType == EcorePackage.eINSTANCE.getEFloat() || eType == EcorePackage.eINSTANCE.getEFloatObject()) {
				return "Float";
			} else if (eType == EcorePackage.eINSTANCE.getEDate()) {
				return "Date";
			} else if (eType == EcorePackage.eINSTANCE.getEByteArray()) {
				return "byte[]";
			} else if (eType.getInstanceClass() == DataHandler.class) {
				return "DataHandler";
			}
		} else if (eType instanceof EClass) {
			if (embedsReference) {
				return "S" + eType.getName();
			} else {
				return "Long";
			}
		}
	}
	return "S" + eType.getName();
}