org.eclipse.xtext.xbase.typesystem.IExpressionScope Java Examples

The following examples show how to use org.eclipse.xtext.xbase.typesystem.IExpressionScope. 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: SARLProposalProvider.java    From sarl with Apache License 2.0 6 votes vote down vote up
@Override
public void completeAOPMember_Guard(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
	if (model instanceof SarlBehaviorUnit) {
		final SarlBehaviorUnit behaviorUnit = (SarlBehaviorUnit) model;
		final XExpression guardExpr = behaviorUnit.getGuard();
		if (guardExpr != null) {
			// Generate the proposals by considering the guard expression as an anchor.
			createLocalVariableAndImplicitProposals(guardExpr, IExpressionScope.Anchor.BEFORE, context, acceptor);
			return;
		}
		final XExpression body = behaviorUnit.getExpression();
		if (body != null) {
			// Generate the proposals by considering that all elements that accessible from the body are accessible from the guard to.
			// "it" is missed => it is manually added.
			final ICompletionProposal itProposal = createCompletionProposal(
					this.keywords.getItKeyword(),
					new StyledString(this.keywords.getItKeyword()),
					this.imageHelper.getImage(this.images.forLocalVariable(0)),
					SARLContentProposalPriorities.CONTEXTUAL_KEYWORD_PRIORITY,
					context.getPrefix(), context);
			acceptor.accept(itProposal);
			createLocalVariableAndImplicitProposals(body, context, acceptor);
		}
	}
}
 
Example #2
Source File: XbaseIdeContentProposalProvider.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
protected void createReceiverProposals(final XExpression receiver, final CrossReference crossReference, final ContentAssistContext context, final IIdeContentProposalAcceptor acceptor) {
  final IResolvedTypes resolvedTypes = this.typeResolver.resolveTypes(receiver);
  final LightweightTypeReference receiverType = resolvedTypes.getActualType(receiver);
  if (((receiverType == null) || receiverType.isPrimitiveVoid())) {
    return;
  }
  final IExpressionScope expressionScope = resolvedTypes.getExpressionScope(receiver, IExpressionScope.Anchor.RECEIVER);
  IScope scope = null;
  final EObject currentModel = context.getCurrentModel();
  if ((currentModel != receiver)) {
    if (((currentModel instanceof XMemberFeatureCall) && 
      (((XMemberFeatureCall) currentModel).getMemberCallTarget() == receiver))) {
      scope = this.syntaxFilteredScopes.create(expressionScope.getFeatureScope(((XAbstractFeatureCall) currentModel)), crossReference);
    } else {
      scope = this.syntaxFilteredScopes.create(expressionScope.getFeatureScope(), crossReference);
    }
  } else {
    scope = this.syntaxFilteredScopes.create(expressionScope.getFeatureScope(), crossReference);
  }
  this.getCrossrefProposalProvider().lookupCrossReference(scope, crossReference, context, acceptor, this.featureDescriptionPredicate);
}
 
Example #3
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 #4
Source File: XbaseIdeContentProposalProvider.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
protected void completeXFeatureCall(final EObject model, final ContentAssistContext context, final IIdeContentProposalAcceptor acceptor) {
  if ((model != null)) {
    boolean _hasExpressionScope = this.typeResolver.resolveTypes(model).hasExpressionScope(model, IExpressionScope.Anchor.WITHIN);
    if (_hasExpressionScope) {
      return;
    }
  }
  if ((model instanceof XMemberFeatureCall)) {
    final ICompositeNode node = NodeModelUtils.getNode(model);
    boolean _isInMemberFeatureCall = this.isInMemberFeatureCall(model, node.getEndOffset(), context);
    if (_isInMemberFeatureCall) {
      return;
    }
  }
  this.createLocalVariableAndImplicitProposals(model, IExpressionScope.Anchor.AFTER, context, acceptor);
}
 
Example #5
Source File: XbaseProposalProvider.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void completeXFeatureCall_Feature(EObject model, Assignment assignment, ContentAssistContext context,
		ICompletionProposalAcceptor acceptor) {
	if (model != null) {
		if (typeResolver.resolveTypes(model).hasExpressionScope(model, IExpressionScope.Anchor.WITHIN)) {
			return;
		}
	}
	if (model instanceof XMemberFeatureCall) {
		ICompositeNode node = NodeModelUtils.getNode(model);
		int endOffset = node.getEndOffset();
		if (isInMemberFeatureCall(model, endOffset, context)) {
			return;
		}
	}
	createLocalVariableAndImplicitProposals(model, IExpressionScope.Anchor.AFTER, context, acceptor);
}
 
Example #6
Source File: XbaseProposalProvider.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void completeXBasicForLoopExpression_InitExpressions(EObject model, Assignment assignment,
		ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
	ICompositeNode node = NodeModelUtils.getNode(model);
	if (node.getOffset() >= context.getOffset()) {
		createLocalVariableAndImplicitProposals(model, IExpressionScope.Anchor.BEFORE, context, acceptor);
		return;
	}
	if (model instanceof XBasicForLoopExpression) {
		List<XExpression> children = ((XBasicForLoopExpression) model).getInitExpressions();
		if (!children.isEmpty()) {
			for(int i = children.size() - 1; i >= 0; i--) {
				XExpression child = children.get(i);
				ICompositeNode childNode = NodeModelUtils.getNode(child);
				if (childNode.getEndOffset() <= context.getOffset()) {
					createLocalVariableAndImplicitProposals(child, IExpressionScope.Anchor.AFTER, context, acceptor);
					return;
				}
			}
		}
	}
	createLocalVariableAndImplicitProposals(model, IExpressionScope.Anchor.BEFORE, context, acceptor);
}
 
Example #7
Source File: XbaseProposalProvider.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
protected void createReceiverProposals(XExpression receiver, CrossReference crossReference, ContentAssistContext contentAssistContext, ICompletionProposalAcceptor acceptor) {
//		long time = System.currentTimeMillis();
		String ruleName = getConcreteSyntaxRuleName(crossReference);
		Function<IEObjectDescription, ICompletionProposal> proposalFactory = getProposalFactory(ruleName, contentAssistContext);
		IResolvedTypes resolvedTypes = typeResolver.resolveTypes(receiver);
		LightweightTypeReference receiverType = resolvedTypes.getActualType(receiver);
		if (receiverType == null || receiverType.isPrimitiveVoid()) {
			return;
		}
		IExpressionScope expressionScope = resolvedTypes.getExpressionScope(receiver, IExpressionScope.Anchor.RECEIVER);
		// TODO exploit the type name information
		IScope scope;
		if (contentAssistContext.getCurrentModel() != receiver) {
			EObject currentModel = contentAssistContext.getCurrentModel();
			if (currentModel instanceof XMemberFeatureCall && ((XMemberFeatureCall) currentModel).getMemberCallTarget() == receiver) {
				scope = filterByConcreteSyntax(expressionScope.getFeatureScope((XAbstractFeatureCall) currentModel), crossReference);
			} else {
				scope = filterByConcreteSyntax(expressionScope.getFeatureScope(), crossReference);
			}
		} else {
			scope = filterByConcreteSyntax(expressionScope.getFeatureScope(), crossReference);
		}
		getCrossReferenceProposalCreator().lookupCrossReference(scope, receiver, XbasePackage.Literals.XABSTRACT_FEATURE_CALL__FEATURE, acceptor, getFeatureDescriptionPredicate(contentAssistContext), proposalFactory);
//		System.out.printf("XbaseProposalProvider.createReceiverProposals = %d\n", System.currentTimeMillis() - time);
	}
 
Example #8
Source File: FeatureScopeTracker.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public IExpressionScope getExpressionScope(EObject context, IExpressionScope.Anchor anchor) {
	EnumMap<Anchor, ExpressionScope> recordedScopes = featureScopeSessions.get(context);
	if (recordedScopes == null) {
		return IExpressionScope.NULL;
	}
	ExpressionScope result = recordedScopes.get(anchor);
	if (result == null && anchor == IExpressionScope.Anchor.RECEIVER) {
		result = recordedScopes.get(IExpressionScope.Anchor.AFTER);
	}
	if (result == null) {
		return IExpressionScope.NULL;
	}
	return result.withAnchor(anchor);
}
 
Example #9
Source File: AbstractTypeComputationState.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected ExpressionAwareStackedResolvedTypes doComputeTypes(XExpression expression) {
	ExpressionAwareStackedResolvedTypes stackedResolvedTypes = pushTypes(expression);
	ExpressionTypeComputationState state = createExpressionComputationState(expression, stackedResolvedTypes);
	stackedResolvedTypes.addExpressionScope(expression, state.getFeatureScopeSession(), IExpressionScope.Anchor.BEFORE);
	getResolver().getTypeComputer().computeTypes(expression, state);
	stackedResolvedTypes.prepareMergeIntoParent();
	if (stackedResolvedTypes.doGetTypeData(expression) == null) {
		state.acceptActualType(stackedResolvedTypes.getReferenceOwner().newAnyTypeReference());
	}
	stackedResolvedTypes.addExpressionScope(expression, getFeatureScopeSession(), IExpressionScope.Anchor.AFTER);
	return stackedResolvedTypes;
}
 
Example #10
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 #11
Source File: XbaseIdeContentProposalProvider.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void _createProposals(final RuleCall ruleCall, final ContentAssistContext context, final IIdeContentProposalAcceptor acceptor) {
  AbstractRule _rule = ruleCall.getRule();
  boolean _matched = false;
  ParserRule _xExpressionRule = this._xbaseGrammarAccess.getXExpressionRule();
  if (Objects.equal(_rule, _xExpressionRule)) {
    _matched=true;
    if (((ruleCall.eContainer() instanceof Group) && Objects.equal(GrammarUtil.containingRule(ruleCall).getName(), "XParenthesizedExpression"))) {
      this.createLocalVariableAndImplicitProposals(context.getCurrentModel(), IExpressionScope.Anchor.WITHIN, context, acceptor);
    }
  }
  if (!_matched) {
    super._createProposals(ruleCall, context, acceptor);
  }
}
 
Example #12
Source File: XbaseIdeContentProposalProvider.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected void completeXBasicForLoopInit(final EObject model, final ContentAssistContext context, final IIdeContentProposalAcceptor acceptor) {
  final ICompositeNode node = NodeModelUtils.getNode(model);
  int _offset = node.getOffset();
  int _offset_1 = context.getOffset();
  boolean _greaterEqualsThan = (_offset >= _offset_1);
  if (_greaterEqualsThan) {
    this.createLocalVariableAndImplicitProposals(model, IExpressionScope.Anchor.BEFORE, context, acceptor);
    return;
  }
  if ((model instanceof XBasicForLoopExpression)) {
    final EList<XExpression> children = ((XBasicForLoopExpression)model).getInitExpressions();
    for (int i = (children.size() - 1); (i >= 0); i--) {
      {
        final XExpression child = children.get(i);
        final ICompositeNode childNode = NodeModelUtils.getNode(child);
        int _endOffset = childNode.getEndOffset();
        int _offset_2 = context.getOffset();
        boolean _lessEqualsThan = (_endOffset <= _offset_2);
        if (_lessEqualsThan) {
          this.createLocalVariableAndImplicitProposals(child, IExpressionScope.Anchor.AFTER, context, acceptor);
          return;
        }
      }
    }
  }
  this.createLocalVariableAndImplicitProposals(model, IExpressionScope.Anchor.BEFORE, context, acceptor);
}
 
Example #13
Source File: FeatureScopeTracker.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void replacePreviousExpressionScope(EObject context, IFeatureScopeSession session, IExpressionScope.Anchor anchor) {
	EnumMap<Anchor, ExpressionScope> recordedScopes = featureScopeSessions.get(context);
	if (recordedScopes == null) {
		throw new IllegalStateException("Cannot replace scope that was never recorded");
	}
	ExpressionScope scope = recordedScopes.get(anchor);
	if (scope == null) {
		throw new IllegalStateException("Cannot replace scope that was never recorded");
	}
	scope.replacePreviousData(session);
}
 
Example #14
Source File: ExpressionScopeTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testMemberOnIt_03() throws Exception {
	XExpression varInit = ((XVariableDeclaration) Iterables
			.getFirst(((XBlockExpression) expression("{ var (int)=>int it = [] }", false)).getExpressions(), null)).getRight();
	IExpressionScope expressionScope = batchTypeResolver.resolveTypes(varInit).getExpressionScope(varInit,
			IExpressionScope.Anchor.BEFORE);
	contains(expressionScope, "it");
}
 
Example #15
Source File: ExpressionScopeTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testGetExpressionScope_03() throws Exception {
	XExpression varDecl = Iterables.getFirst(((XBlockExpression) expression("{ var x = 1 }", false)).getExpressions(), null);
	IExpressionScope expressionScope = batchTypeResolver.resolveTypes(varDecl).getExpressionScope(varDecl,
			IExpressionScope.Anchor.AFTER);
	contains(expressionScope, "x");
}
 
Example #16
Source File: ExpressionScopeTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testGetExpressionScope_04() throws Exception {
	XExpression varDecl = Iterables.getFirst(((XBlockExpression) expression("{ var x = 1 }", false)).getExpressions(), null);
	IExpressionScope expressionScope = batchTypeResolver.resolveTypes(varDecl).getExpressionScope(varDecl,
			IExpressionScope.Anchor.BEFORE);
	containsNot(expressionScope, "x");
}
 
Example #17
Source File: ExpressionScopeTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testMemberOnIt_01() throws Exception {
	XExpression varDecl = Iterables.getFirst(((XBlockExpression) expression("{ var it = \"\" }", false)).getExpressions(), null);
	IExpressionScope expressionScope = batchTypeResolver.resolveTypes(varDecl).getExpressionScope(varDecl,
			IExpressionScope.Anchor.AFTER);
	contains(expressionScope, "charAt");
	contains(expressionScope, "it");
	contains(expressionScope, "operator_lessThan");
}
 
Example #18
Source File: ExpressionScope.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
public IExpressionScope withAnchor(final Anchor anchor) {
	if (anchor == this.anchor)
		return this;
	return new IExpressionScope() {

		/* @NonNull */
		@Override
		public IScope getFeatureScope() {
			return ExpressionScope.this.getFeatureScope(anchor);
		}

		/* @NonNull */
		@Override
		public IScope getFeatureScope(/* @Nullable */ XAbstractFeatureCall currentFeatureCall) {
			return ExpressionScope.this.getFeatureScope(currentFeatureCall, anchor);
		}

		/* @NonNull */
		@Override
		public List<String> getTypeNamePrefix() {
			return ExpressionScope.this.getTypeNamePrefix();
		}

		@Override
		public boolean isPotentialTypeLiteral() {
			return ExpressionScope.this.isPotentialTypeLiteral();
		}
		
	};
}
 
Example #19
Source File: ExpressionScopeTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testMemberOnIt_02() throws Exception {
	XExpression varDecl = Iterables.getFirst(((XBlockExpression) expression("{ var it = \"\" }", false)).getExpressions(), null);
	IExpressionScope expressionScope = batchTypeResolver.resolveTypes(varDecl).getExpressionScope(varDecl,
			IExpressionScope.Anchor.BEFORE);
	containsNot(expressionScope, "charAt");
	containsNot(expressionScope, "it");
	containsNot(expressionScope, "operator_lessThan");
}
 
Example #20
Source File: ExpressionScopeTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testMemberOnIt_04() throws Exception {
	XExpression varInit = ((XVariableDeclaration) Iterables
			.getFirst(((XBlockExpression) expression("{ var it = [] }", false)).getExpressions(), null)).getRight();
	IExpressionScope expressionScope = batchTypeResolver.resolveTypes(varInit).getExpressionScope(varInit,
			IExpressionScope.Anchor.BEFORE);
	containsNot(expressionScope, "it");
}
 
Example #21
Source File: ExpressionScopeTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testMemberOnIt_05() throws Exception {
	XExpression varInit = ((XVariableDeclaration) Iterables
			.getFirst(((XBlockExpression) expression("{ var (int)=>int it = null }", false)).getExpressions(), null)).getRight();
	IExpressionScope expressionScope = batchTypeResolver.resolveTypes(varInit).getExpressionScope(varInit,
			IExpressionScope.Anchor.BEFORE);
	containsNot(expressionScope, "it");
}
 
Example #22
Source File: ExpressionScopeTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testDefaultStaticMethods_01() throws Exception {
	XExpression varDecl = Iterables.getFirst(((XBlockExpression) expression("{ var it = \"\" }", false)).getExpressions(), null);
	IExpressionScope expressionScope = batchTypeResolver.resolveTypes(varDecl).getExpressionScope(varDecl,
			IExpressionScope.Anchor.BEFORE);
	contains(expressionScope, "newArrayList");
}
 
Example #23
Source File: ExpressionScopeTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testReassignedType_01() throws Exception {
	XIfExpression ifExpr = (XIfExpression) IterableExtensions
			.last(((XBlockExpression) expression("{ var it = new Object() if (it instanceof String) {} }", false)).getExpressions());
	XBlockExpression block = (XBlockExpression) ifExpr.getThen();
	IExpressionScope expressionScope = batchTypeResolver.resolveTypes(block).getExpressionScope(block, IExpressionScope.Anchor.BEFORE);
	contains(expressionScope, "charAt");
	contains(expressionScope, "it");
	contains(expressionScope, "operator_lessThan");
}
 
Example #24
Source File: ExpressionScopeTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testReassignedType_02() throws Exception {
	XIfExpression ifExpr = (XIfExpression) IterableExtensions
			.last(((XBlockExpression) expression("{ var it = new Object() if (it instanceof String) { it = new Object() } }", false))
					.getExpressions());
	XBlockExpression block = (XBlockExpression) ifExpr.getThen();
	IExpressionScope expressionScope = batchTypeResolver.resolveTypes(block).getExpressionScope(block, IExpressionScope.Anchor.BEFORE);
	contains(expressionScope, "charAt");
	contains(expressionScope, "it");
	contains(expressionScope, "operator_lessThan");
}
 
Example #25
Source File: ExpressionScopeTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testReassignedType_03() throws Exception {
	XIfExpression ifExpr = (XIfExpression) IterableExtensions
			.last(((XBlockExpression) expression("{ var it = new Object() if (it instanceof String) { it = new Object() } }", false))
					.getExpressions());
	XBlockExpression block = (XBlockExpression) ifExpr.getThen();
	XExpression assignment = Iterables.getFirst(block.getExpressions(), null);
	IExpressionScope expressionScope = batchTypeResolver.resolveTypes(assignment).getExpressionScope(assignment,
			IExpressionScope.Anchor.AFTER);
	containsNot(expressionScope, "charAt");
	contains(expressionScope, "it");
	containsNot(expressionScope, "operator_lessThan");
}
 
Example #26
Source File: XbaseProposalProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected void completeWithinBlock(EObject model, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
	ICompositeNode node = NodeModelUtils.getNode(model);
	if (node.getOffset() >= context.getOffset()) {
		createLocalVariableAndImplicitProposals(model, IExpressionScope.Anchor.BEFORE, context, acceptor);
		return;
	}
	if (model instanceof XBlockExpression) {
		List<XExpression> children = ((XBlockExpression) model).getExpressions();
		if (!children.isEmpty()) {
			for(int i = children.size() - 1; i >= 0; i--) {
				XExpression child = children.get(i);
				ICompositeNode childNode = NodeModelUtils.getNode(child);
				if (childNode.getEndOffset() <= context.getOffset()) {
					createLocalVariableAndImplicitProposals(child, IExpressionScope.Anchor.AFTER, context, acceptor);
					return;
				}
			}
		}
	}
	int endOffset = node.getEndOffset();
	if (endOffset <= context.getOffset()) {
		if (model instanceof XFeatureCall && model.eContainer() instanceof XClosure || endOffset == context.getOffset() && context.getPrefix().length() == 0)
			return;
		if (isInMemberFeatureCall(model, endOffset, context))
			return;
		createLocalVariableAndImplicitProposals(model, IExpressionScope.Anchor.AFTER, context, acceptor);
		return;
	} else if (isInMemberFeatureCall(model, endOffset, context)) {
		return;
	}
	if (model instanceof XClosure)
		return;
	createLocalVariableAndImplicitProposals(model, IExpressionScope.Anchor.BEFORE, context, acceptor);
}
 
Example #27
Source File: XbaseProposalProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void complete_XExpression(EObject model, RuleCall ruleCall, ContentAssistContext context,
		ICompletionProposalAcceptor acceptor) {
	// likely XParenthesizedExpression
	EObject container = ruleCall.eContainer();
	// avoid dependency on XbaseGrammarAccess
	if (container instanceof Group && "XParenthesizedExpression".equals(GrammarUtil.containingRule(ruleCall).getName())) {
		createLocalVariableAndImplicitProposals(model, IExpressionScope.Anchor.WITHIN, context, acceptor);
	}
}
 
Example #28
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 #29
Source File: XbaseWithAnnotationsProposalProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void completeXFeatureCall_Feature(EObject model, Assignment assignment, ContentAssistContext context,
		ICompletionProposalAcceptor acceptor) {
	if (model instanceof XAnnotation) {
		createLocalVariableAndImplicitProposals(model, IExpressionScope.Anchor.WITHIN, context, acceptor);
		return;
	} else if (model instanceof XAnnotationElementValuePair) {
		XAnnotationElementValuePair pair = (XAnnotationElementValuePair) model;
		XAnnotation annotation = (XAnnotation) pair.eContainer();
		createLocalVariableAndImplicitProposals(annotation, IExpressionScope.Anchor.WITHIN, context, acceptor);
		return;
	}
	super.completeXFeatureCall_Feature(model, assignment, context, acceptor);
}
 
Example #30
Source File: XbaseProposalProvider.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void completeXBasicForLoopExpression_EachExpression(EObject model, Assignment assignment,
		ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
	createLocalVariableAndImplicitProposals(model, IExpressionScope.Anchor.WITHIN, context, acceptor);
}