Java Code Examples for org.eclipse.xtext.xbase.typesystem.IExpressionScope#getFeatureScope()

The following examples show how to use org.eclipse.xtext.xbase.typesystem.IExpressionScope#getFeatureScope() . 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: XbaseIdeContentProposalProvider.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
protected void createLocalVariableAndImplicitProposals(final EObject model, final IExpressionScope.Anchor anchor, final ContentAssistContext context, final IIdeContentProposalAcceptor acceptor) {
  String prefix = context.getPrefix();
  if (((prefix.length() > 0) && (!Character.isJavaIdentifierStart(prefix.charAt(0))))) {
    return;
  }
  IResolvedTypes _xifexpression = null;
  if ((model != null)) {
    _xifexpression = this.typeResolver.resolveTypes(model);
  } else {
    _xifexpression = this.typeResolver.resolveTypes(context.getResource());
  }
  final IResolvedTypes resolvedTypes = _xifexpression;
  final IExpressionScope expressionScope = resolvedTypes.getExpressionScope(model, anchor);
  final IScope scope = expressionScope.getFeatureScope();
  this.getCrossrefProposalProvider().lookupCrossReference(scope, this._xbaseGrammarAccess.getXFeatureCallAccess().getFeatureJvmIdentifiableElementCrossReference_2_0(), context, acceptor, this.featureDescriptionPredicate);
}
 
Example 2
Source File: XbaseBatchScopeProvider.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public IScope getScope(EObject context, EReference reference) {
	if (context == null || context.eResource() == null || context.eResource().getResourceSet() == null) {
		return IScope.NULLSCOPE;
	}
	if (isFeatureCallScope(reference)) {
		IExpressionScope.Anchor anchor = IExpressionScope.Anchor.BEFORE;
		if (context instanceof XAbstractFeatureCall) {
			EObject proxyOrResolved = (EObject) context.eGet(reference, false);
			if (proxyOrResolved != null && !proxyOrResolved.eIsProxy()) {
				XExpression receiver = ((XAbstractFeatureCall) context).getActualReceiver();
				if (receiver == null && context instanceof XMemberFeatureCall) {
					receiver = ((XMemberFeatureCall) context).getMemberCallTarget();
				}
				if (receiver != null) {
					anchor = IExpressionScope.Anchor.RECEIVER;
					context = receiver;
				}
			} else if (context instanceof XBinaryOperation) {
				context = ((XBinaryOperation) context).getLeftOperand();
				anchor = IExpressionScope.Anchor.RECEIVER;
			} else if (context instanceof XMemberFeatureCall) {
				context = ((XMemberFeatureCall) context).getMemberCallTarget();
				anchor = IExpressionScope.Anchor.RECEIVER;
			}
		}
		IExpressionScope expressionScope = typeResolver.resolveTypes(context).getExpressionScope(context, anchor);
		return expressionScope.getFeatureScope();
	}
	if (isTypeScope(reference)) {
		return typeScopes.createTypeScope(context, reference);
	}
	return delegateGetScope(context, reference);
}
 
Example 3
Source File: NewFeatureNameUtil.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public void setFeatureScopeContext(XExpression siblingExpression) {
	XBlockExpression containerBlock = 
			(siblingExpression.eContainer() instanceof XBlockExpression) 
			? (XBlockExpression) siblingExpression.eContainer() 
			: null;
	EObject context = siblingExpression;
	if (containerBlock != null && !containerBlock.getExpressions().isEmpty()) {
		context = containerBlock.getExpressions().get(containerBlock.getExpressions().size() - 1);
	}
	IExpressionScope expressionScope = batchTypeResolver.resolveTypes(context).getExpressionScope(context, IExpressionScope.Anchor.AFTER);
	featureCallScope = expressionScope.getFeatureScope();
}
 
Example 4
Source File: XbaseProposalProvider.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
protected void createLocalVariableAndImplicitProposals(
			EObject context,
			IExpressionScope.Anchor anchor,
			ContentAssistContext contentAssistContext,
			ICompletionProposalAcceptor acceptor) {
		String prefix = contentAssistContext.getPrefix();
		if (prefix.length() > 0) {
			if (!Character.isJavaIdentifierStart(prefix.charAt(0))) {
				if (prefix.length() > 1) {
					if (prefix.charAt(0) == '^' && !Character.isJavaIdentifierStart(prefix.charAt(1))) {
						return;
					}
				}
			}
		}
		
//		long time = System.currentTimeMillis();
		Function<IEObjectDescription, ICompletionProposal> proposalFactory = getProposalFactory(getFeatureCallRuleName(), contentAssistContext);
		IResolvedTypes resolvedTypes = context != null ? typeResolver.resolveTypes(context) : typeResolver.resolveTypes(contentAssistContext.getResource());
		IExpressionScope expressionScope = resolvedTypes.getExpressionScope(context, anchor);
		// TODO use the type name information
		IScope scope = expressionScope.getFeatureScope();
		getCrossReferenceProposalCreator().lookupCrossReference(scope, context, XbasePackage.Literals.XABSTRACT_FEATURE_CALL__FEATURE, acceptor, getFeatureDescriptionPredicate(contentAssistContext), proposalFactory);
//		System.out.printf("XbaseProposalProvider.createLocalVariableAndImplicitProposals = %d\n", System.currentTimeMillis() - time);
//		time = System.currentTimeMillis();
		
		// TODO use the type name information
		proposeDeclaringTypeForStaticInvocation(context, null /* ignore */, contentAssistContext, acceptor);
//		System.out.printf("XbaseProposalProvider.proposeDeclaringTypeForStaticInvocation = %d\n", System.currentTimeMillis() - time);
		if(context != null && !(context instanceof XMemberFeatureCall)) {
			Iterable<JvmFeature> featuresToImport = getFavoriteStaticFeatures(context, input->true);
			// Create StaticFeatureDescription instead of SimpleIdentifiableElementDescription since we want the Proposal to show parameters
			Iterable<IEObjectDescription> scopedFeatures = Iterables.transform(featuresToImport, feature -> {
				QualifiedName qualifiedName = QualifiedName.create(feature.getSimpleName());
				return new StaticFeatureDescription(qualifiedName, feature, 0, true);	
			});
			// Scope for all static features
			IScope staticMemberScope = new SimpleScope(IScope.NULLSCOPE, scopedFeatures);
			proposeFavoriteStaticFeatures(context, contentAssistContext, acceptor, staticMemberScope);
		}
	}