Java Code Examples for org.eclipse.xtext.xbase.scoping.batch.IFeatureScopeSession#addToExtensionScope()

The following examples show how to use org.eclipse.xtext.xbase.scoping.batch.IFeatureScopeSession#addToExtensionScope() . 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: LogicalContainerAwareReentrantTypeResolver.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected IFeatureScopeSession addExtensionsToMemberSession(ResolvedTypes resolvedTypes,
		IFeatureScopeSession featureScopeSession, JvmDeclaredType type) {
	IEObjectDescription thisDescription = featureScopeSession.getLocalElement(IFeatureNames.THIS);
	if (thisDescription == null) {
		throw new IllegalStateException("Cannot find feature 'THIS'");
	}
	JvmIdentifiableElement thisFeature = (JvmIdentifiableElement) thisDescription.getEObjectOrProxy();
	IFeatureScopeSession childSession = addExtensionFieldsToMemberSession(
			resolvedTypes, featureScopeSession, type, thisFeature, Sets.<String>newHashSetWithExpectedSize(8), Sets.<JvmType>newHashSetWithExpectedSize(4));
	XFeatureCall thisAccess = getXbaseFactory().createXFeatureCall();
	thisAccess.setFeature(thisFeature);
	LightweightTypeReference thisType = resolvedTypes.getActualType(thisFeature);
	childSession = childSession.addToExtensionScope(Collections.<XExpression, LightweightTypeReference>singletonMap(thisAccess, thisType));
	return childSession;
}
 
Example 2
Source File: LogicalContainerAwareReentrantTypeResolver.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected IFeatureScopeSession addExtensionFieldsToMemberSession(
			ResolvedTypes resolvedTypes, 
			IFeatureScopeSession featureScopeSession, 
			JvmDeclaredType type, 
			JvmIdentifiableElement thisFeature,
			Set<String> seenNames,
			Set<JvmType> seenTypes) {
	if (seenTypes.add(type)) {
		Iterable<JvmField> fields = type.getDeclaredFields();
		// collect local fields first, to populate the set of names
		Map<XExpression, LightweightTypeReference> extensionProviders = null;
		for(JvmField field: fields) {
			if (featureScopeSession.isVisible(field) && seenNames.add(field.getSimpleName()) && isExtensionProvider(field)) {
				if (extensionProviders == null) {
					extensionProviders = Maps2.newLinkedHashMapWithExpectedSize(3);
				}
				XAbstractFeatureCall extensionProvider = createExtensionProvider(thisFeature, field);
				LightweightTypeReference fieldType = resolvedTypes.getActualType(field);
				extensionProviders.put(extensionProvider, fieldType);
			}
		}
		// traverse the type hierarchy to create the feature scope sessions
		JvmTypeReference superType = getExtendedClass(type);
		IFeatureScopeSession result = featureScopeSession;
		if (superType != null) {
			result = addExtensionFieldsToMemberSession(resolvedTypes, featureScopeSession, (JvmDeclaredType) superType.getType(), thisFeature, seenNames, seenTypes);
		}
		if (extensionProviders != null) {
			result = result.addToExtensionScope(extensionProviders);
		}
		return result;
	}
	return featureScopeSession;
}
 
Example 3
Source File: SARLReentrantTypeResolver.java    From sarl with Apache License 2.0 4 votes vote down vote up
@Override
protected IFeatureScopeSession addExtensionFieldsToMemberSession(
		ResolvedTypes resolvedTypes,
		IFeatureScopeSession featureScopeSession,
		JvmDeclaredType type,
		JvmIdentifiableElement thisFeature,
		Set<String> seenNames,
		Set<JvmType> seenTypes) {
	// Overriding for capacity call redirection
	if (seenTypes.add(type)) {
		final Iterable<JvmField> fields = type.getDeclaredFields();
		Map<XExpression, LightweightTypeReference> extensionProviders = null;
		for (final JvmField field : fields) {
			if (featureScopeSession.isVisible(field) && seenNames.add(field.getSimpleName()) && isExtensionProvider(field)) {
				if (extensionProviders == null) {
					extensionProviders = Maps2.newLinkedHashMapWithExpectedSize(3);
				}
				// Sarl specific block of code
				XAbstractFeatureCall extensionProvider = createSarlCapacityExtensionProvider(thisFeature, field);
				final LightweightTypeReference fieldType;
				if (extensionProvider == null) {
					extensionProvider = createExtensionProvider(thisFeature, field);
					fieldType = resolvedTypes.getActualType(field);
				} else {
					fieldType = getSarlCapacityFieldType(resolvedTypes, field);
				}
				// End of Sarl specific
				extensionProviders.put(extensionProvider, fieldType);
			}
		}
		// traverse the type hierarchy to create the feature scope sessions
		final JvmTypeReference superType = getExtendedClass(type);
		IFeatureScopeSession result = featureScopeSession;
		if (superType != null) {
			result = addExtensionFieldsToMemberSession(resolvedTypes, featureScopeSession, (JvmDeclaredType) superType.getType(),
					thisFeature, seenNames, seenTypes);
		}
		if (extensionProviders != null) {
			result = result.addToExtensionScope(extensionProviders);
		}
		return result;
	}
	return featureScopeSession;
}