Java Code Examples for org.eclipse.xtext.EcoreUtil2#getCompatibleType()

The following examples show how to use org.eclipse.xtext.EcoreUtil2#getCompatibleType() . 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: FollowElementComputer.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
public void collectAbstractElements(Grammar grammar, EStructuralFeature feature, IFollowElementAcceptor followElementAcceptor) {
	for (Grammar superGrammar : grammar.getUsedGrammars()) {
		collectAbstractElements(superGrammar, feature, followElementAcceptor);
	}
	EClass declarator = feature.getEContainingClass();
	for (ParserRule rule : GrammarUtil.allParserRules(grammar)) {
		for (Assignment assignment : GrammarUtil.containedAssignments(rule)) {
			if (assignment.getFeature().equals(feature.getName())) {
				EClassifier classifier = GrammarUtil.findCurrentType(assignment);
				EClassifier compType = EcoreUtil2.getCompatibleType(declarator, classifier);
				if (compType == declarator) {
					followElementAcceptor.accept(assignment);
				}
			}
		}
	}
}
 
Example 2
Source File: EClassifierInfos.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
private EClassifierInfo getCompatibleType(EClassifierInfo infoA, EClassifierInfo infoB) {
	if (infoA.equals(infoB))
		return infoA;

	if (infoA.getEClassifier() instanceof EDataType || infoB.getEClassifier() instanceof EDataType)
		throw new IllegalArgumentException(
				"Simple Datatypes (lexer rules or keywords) do not have a common supertype (" + infoA + ", "
						+ infoB + ")");

	EClassifier compatibleType = EcoreUtil2.getCompatibleType(infoA.getEClassifier(), infoB.getEClassifier(), grammar);

	return getInfoOrNull(compatibleType);
}
 
Example 3
Source File: TypeHierarchyHelper.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
private void pushFeaturesUp(EClassInfo info, Collection<EClass> traversedClasses) {
	EClass eClass = info.getEClass();
	if (info.isGenerated()) {
		if (traversedClasses.add(eClass)) {
			if (eClass.getESuperTypes().isEmpty())
				return;
			for(EClass superType: eClass.getESuperTypes()) {
				EClassInfo superInfo = (EClassInfo) infos.getInfoOrNull(superType);
				pushFeaturesUp(superInfo, traversedClasses);
			}
			Map<String, EStructuralFeature> allFeatures = Maps.newLinkedHashMap();
			Set<String> skippedNames = Sets.newLinkedHashSet();
			for(EStructuralFeature feature: eClass.getEAllStructuralFeatures()) {
				if (feature.getEContainingClass() != eClass) {
					if (allFeatures.containsKey(feature.getName())) {
						allFeatures.remove(feature.getName());
					} else if (skippedNames.add(feature.getName())) {
						allFeatures.put(feature.getName(), feature);
					}
				}
			}
			Iterator<EStructuralFeature> iter = eClass.getEStructuralFeatures().iterator();
			while(iter.hasNext()) {
				EStructuralFeature declared = iter.next();
				EStructuralFeature existing = allFeatures.get(declared.getName());
				if (existing != null) {
					EClassifier compatibleType = EcoreUtil2.getCompatibleType(declared.getEType(), existing.getEType(), grammar);
					if (compatibleType != null) {
						iter.remove();
						existing.setEType(compatibleType);
					}
				}
			}
		}
	}
}
 
Example 4
Source File: CurrentTypeFinder.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected EClassifier getCompatibleType(EClassifier a, EClassifier b, EObject context) {
	if (a == null)
		return b;
	if (b == null)
		return a;
	return EcoreUtil2.getCompatibleType(a, b, context);
}