Java Code Examples for org.eclipse.xtext.xbase.XFeatureCall#setFeature()

The following examples show how to use org.eclipse.xtext.xbase.XFeatureCall#setFeature() . 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: AbstractTypeComputationState.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void addExtensionsToCurrentScope(List<? extends JvmIdentifiableElement> extensionProviders) {
	if (extensionProviders.isEmpty())
		return;
	if (extensionProviders.size() == 1) {
		addExtensionToCurrentScope(extensionProviders.get(0));
		return;
	}
	Map<XExpression, LightweightTypeReference> prototypeToType = Maps2.newLinkedHashMapWithExpectedSize(extensionProviders.size());
	for(JvmIdentifiableElement extensionProvider: extensionProviders) {
		LightweightTypeReference knownType = getResolvedTypes().getActualType(extensionProvider);
		if (knownType != null && !knownType.isAny() && !knownType.isUnknown()) {
			XFeatureCall prototype = getResolver().getXbaseFactory().createXFeatureCall();
			prototype.setFeature(extensionProvider);
			prototypeToType.put(prototype, knownType);
		}
	}
	if (!prototypeToType.isEmpty())
		featureScopeSession = featureScopeSession.addToExtensionScope(prototypeToType);
}
 
Example 2
Source File: FeatureScopes.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
protected IScope createImplicitFeatureCallScope(QualifiedName implicitName, EObject featureCall,
		IFeatureScopeSession session, IResolvedTypes resolvedTypes, IScope parent) {
	IEObjectDescription thisDescription = session.getLocalElement(implicitName);
	if (thisDescription != null) {
		JvmIdentifiableElement thisElement = (JvmIdentifiableElement) thisDescription.getEObjectOrProxy();
		boolean validStaticScope = true;
		if (thisElement instanceof JvmType && THIS.equals(implicitName) && !session.isInstanceContext()) {
			validStaticScope = false;
		}
		LightweightTypeReference type = resolvedTypes.getActualType(thisElement);
		if (type !=null && !type.isUnknown()) {
			XFeatureCall implicitReceiver = xbaseFactory.createXFeatureCall();
			implicitReceiver.setFeature(thisElement);
			return createFeatureScopeForTypeRef(implicitReceiver, type, true, featureCall, session, thisElement, parent, validStaticScope);
		}
	}
	return parent;
}
 
Example 3
Source File: ExpressionBuilderImpl.java    From sarl with Apache License 2.0 6 votes vote down vote up
/** Create a reference to "super" object or to the super type.
 *
 * @return the reference.
 */
public XFeatureCall createReferenceToSuper() {
	final XExpression expr = getXExpression();
	XtendTypeDeclaration type = EcoreUtil2.getContainerOfType(expr, XtendTypeDeclaration.class);
	JvmType jvmObject = getAssociatedElement(JvmType.class, type, expr.eResource());
	final XFeatureCall superFeature = XbaseFactory.eINSTANCE.createXFeatureCall();
	JvmIdentifiableElement feature;
	if (jvmObject instanceof JvmDeclaredType) {
		feature = ((JvmDeclaredType) jvmObject).getExtendedClass().getType();
	} else {
		feature = findType(expr, getQualifiedName(type)).getType();
		if (feature instanceof JvmDeclaredType) {
			feature = ((JvmDeclaredType) feature).getExtendedClass().getType();
		} else {
			feature = null;
		}
	}
	if (feature == null) {
		return null;
	}
	superFeature.setFeature(feature);
	return superFeature;

}
 
Example 4
Source File: SARLReentrantTypeResolver.java    From sarl with Apache License 2.0 6 votes vote down vote up
/** Create the extension provider dedicated to the access to the used capacity functions.
 *
 * @param thisFeature the current object.
 * @param field the extension field.
 * @return the SARL capacity extension provider, or {@code null}.
 */
protected XAbstractFeatureCall createSarlCapacityExtensionProvider(JvmIdentifiableElement thisFeature, JvmField field) {
	// For capacity call redirection
	if (thisFeature instanceof JvmDeclaredType) {
		final JvmAnnotationReference capacityAnnotation = this.annotationLookup.findAnnotation(field,
				ImportedCapacityFeature.class);
		if (capacityAnnotation != null) {
			final String methodName = Utils.createNameForHiddenCapacityImplementationCallingMethodFromFieldName(
					field.getSimpleName());
			final JvmOperation callerOperation = findOperation((JvmDeclaredType) thisFeature, methodName);
			if (callerOperation != null) {
				final XbaseFactory baseFactory = getXbaseFactory();
				final XMemberFeatureCall extensionProvider = baseFactory.createXMemberFeatureCall();
				extensionProvider.setFeature(callerOperation);
				final XFeatureCall thisAccess = baseFactory.createXFeatureCall();
				thisAccess.setFeature(thisFeature);
				extensionProvider.setMemberCallTarget(thisAccess);
				return extensionProvider;
			}
		}
	}
	return null;
}
 
Example 5
Source File: AbstractTypeComputationState.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void addExtensionToCurrentScope(JvmIdentifiableElement extensionProvider) {
	LightweightTypeReference knownType = getResolvedTypes().getActualType(extensionProvider);
	if (knownType != null && !knownType.isAny() && !knownType.isUnknown()) {
		XFeatureCall prototype = getResolver().getXbaseFactory().createXFeatureCall();
		prototype.setFeature(extensionProvider);
		featureScopeSession = featureScopeSession.addToExtensionScope(Collections.<XExpression, LightweightTypeReference>singletonMap(prototype, knownType));
	}
}
 
Example 6
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 7
Source File: FeatureScopes.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected IScope createDynamicExtensionsScope(QualifiedName implicitFirstArgumentName, IEObjectDescription firstArgumentDescription, EObject featureCall,
		IFeatureScopeSession captureLayer, IFeatureScopeSession session, IResolvedTypes resolvedTypes, IScope parent) {
	JvmIdentifiableElement feature = (JvmIdentifiableElement) firstArgumentDescription.getEObjectOrProxy();
	if (feature instanceof JvmType && THIS.equals(implicitFirstArgumentName) && !session.isInstanceContext()) {
		return parent;
	}
	LightweightTypeReference type = resolvedTypes.getActualType(feature);
	if (type != null && !type.isUnknown()) {
		XFeatureCall implicitArgument = xbaseFactory.createXFeatureCall();
		implicitArgument.setFeature(feature);
		return createDynamicExtensionsScope(featureCall, implicitArgument, type, true, parent, captureLayer);
	}
	return parent;
}
 
Example 8
Source File: FeatureScopes.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected IScope createImplicitExtensionScope(QualifiedName implicitName, EObject featureCall,
		IFeatureScopeSession session, IResolvedTypes resolvedTypes, IScope parent) {
	IEObjectDescription thisDescription = session.getLocalElement(implicitName);
	if (thisDescription != null) {
		JvmIdentifiableElement thisElement = (JvmIdentifiableElement) thisDescription.getEObjectOrProxy();
		LightweightTypeReference type = resolvedTypes.getActualType(thisElement);
		if (type != null && !type.isUnknown()) {
			XFeatureCall implicitReceiver = xbaseFactory.createXFeatureCall();
			implicitReceiver.setFeature(thisElement);
			return createStaticExtensionsScope(featureCall, implicitReceiver, type, true, parent, session);
		}
	}
	return parent;
}
 
Example 9
Source File: Jdt2Ecore.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Add the given constructors to the Ecore container.
 *
 * @param codeBuilder the code builder to use.
 * @param superClassConstructors the constructors defined in the super class.
 * @param context the context of the constructors.
 * @throws JavaModelException if the Java model is invalid.
 */
public void createStandardConstructorsWith(
		ConstructorBuilder codeBuilder,
		Collection<IMethod> superClassConstructors,
		XtendTypeDeclaration context) throws JavaModelException {
	if (superClassConstructors != null) {
		for (final IMethod constructor : superClassConstructors) {
			if (!isGeneratedOperation(constructor)) {
				final ISarlConstructorBuilder cons = codeBuilder.addConstructor();
				// Create parameters
				final IFormalParameterBuilder[] sarlParams = createFormalParametersWith(
					name -> cons.addParameter(name), constructor);
				// Create the block
				final IBlockExpressionBuilder block = cons.getExpression();
				// Create thre super-call expression
				final IExpressionBuilder superCall = block.addExpression();
				final XFeatureCall call = XbaseFactory.eINSTANCE.createXFeatureCall();
				superCall.setXExpression(call);
				// Set the todo comment.
				superCall.setDocumentation(block.getAutoGeneratedActionString());
				// Create the super-call XExpression
				call.setFeature(getJvmConstructor(constructor, context));
				call.setExplicitOperationCall(true);
				final List<XExpression> arguments = call.getFeatureCallArguments();
				for (final IFormalParameterBuilder currentParam : sarlParams) {
					final XFeatureCall argumentSource = XbaseFactory.eINSTANCE.createXFeatureCall();
					arguments.add(argumentSource);
					currentParam.setReferenceInto(argumentSource);
				}
			}
		}
	}
}
 
Example 10
Source File: ExpressionBuilderImpl.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Create a reference to "this" object or to the current type.
 *
 * @return the reference.
 */
public XFeatureCall createReferenceToThis() {
	final XExpression expr = getXExpression();
	XtendTypeDeclaration type = EcoreUtil2.getContainerOfType(expr, XtendTypeDeclaration.class);
	JvmType jvmObject = getAssociatedElement(JvmType.class, type, expr.eResource());
	final XFeatureCall thisFeature = XbaseFactory.eINSTANCE.createXFeatureCall();
	thisFeature.setFeature(jvmObject);
	return thisFeature;
}
 
Example 11
Source File: FormalParameterBuilderImpl.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Replies the JvmIdentifiable that corresponds to the formal parameter.
 *
 * @param container the feature call that is supposed to contains the replied identifiable element.
 */
public void setReferenceInto(XFeatureCall container) {
	JvmVoid jvmVoid = this.jvmTypesFactory.createJvmVoid();
	if (jvmVoid instanceof InternalEObject) {
		final InternalEObject			jvmVoidProxy = (InternalEObject) jvmVoid;
		final EObject param = getSarlFormalParameter();
		final Resource resource = param.eResource();
		// Get the derived object
		final SarlFormalParameter jvmParam = getAssociatedElement(SarlFormalParameter.class, param, resource);
		// Set the proxy URI
		final URI uri = EcoreUtil2.getNormalizedURI(jvmParam);
		jvmVoidProxy.eSetProxyURI(uri);
	}
	container.setFeature(jvmVoid);
}