Java Code Examples for org.eclipse.xtext.xbase.XMemberFeatureCall#isExplicitStatic()

The following examples show how to use org.eclipse.xtext.xbase.XMemberFeatureCall#isExplicitStatic() . 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: ScopeProviderAccess.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Returns the node that best describes the error, e.g. if there is an expression
 * <code>com::foo::DoesNotExist::method()</code> the error will be rooted at <code>com</code>, but
 * the real problem is <code>com::foo::DoesNotExist</code>.
 */
private INode getErrorNode(XExpression expression, INode node) {
	if (expression instanceof XFeatureCall) {
		XFeatureCall featureCall = (XFeatureCall) expression;
		if (!canBeTypeLiteral(featureCall)) {
			return node;
		}
		if (featureCall.eContainingFeature() == XbasePackage.Literals.XMEMBER_FEATURE_CALL__MEMBER_CALL_TARGET) {
			XMemberFeatureCall container = (XMemberFeatureCall) featureCall.eContainer();
			if (canBeTypeLiteral(container)) {
				boolean explicitStatic = container.isExplicitStatic();
				XMemberFeatureCall outerMost = getLongestTypeLiteralCandidate(container, explicitStatic);
				if (outerMost != null)
					return NodeModelUtils.getNode(outerMost);
			}
		}
	}
	return node;
}
 
Example 2
Source File: ScopeProviderAccess.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
private XMemberFeatureCall getLongestTypeLiteralCandidate(XMemberFeatureCall current, boolean mustBeStatic) {
	if (current.eContainingFeature() == XbasePackage.Literals.XMEMBER_FEATURE_CALL__MEMBER_CALL_TARGET) {
		XMemberFeatureCall container = (XMemberFeatureCall) current.eContainer();
		if (canBeTypeLiteral(container)) {
			if (!mustBeStatic && !container.isExplicitStatic()) {
				return null;
			}
			if (mustBeStatic != container.isExplicitStatic()) {
				return current;
			}
			if (mustBeStatic && container.eContainingFeature() != XbasePackage.Literals.XMEMBER_FEATURE_CALL__MEMBER_CALL_TARGET) {
				return current;
			}
			return getLongestTypeLiteralCandidate(container, mustBeStatic);
		}
	}
	if (mustBeStatic) {
		return null;
	}
	if (!mustBeStatic && !current.isExplicitStatic()) {
		return null;
	}
	return current;
}
 
Example 3
Source File: FeatureCallAsTypeLiteralHelper.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
protected XAbstractFeatureCall doGetRootTypeLiteral(XMemberFeatureCall featureCall) {
	boolean staticNotation = featureCall.isExplicitStatic();
	XMemberFeatureCall current = featureCall;
	while(current.eContainingFeature() == XbasePackage.Literals.XMEMBER_FEATURE_CALL__MEMBER_CALL_TARGET) {
		XMemberFeatureCall container = (XMemberFeatureCall) current.eContainer();
		if (container.isExplicitStatic()) {
			if (staticNotation == false) {
				return current;
			}
			current = container;
		} else if (staticNotation) {
			return (XAbstractFeatureCall) current.getMemberCallTarget();
		} else {
			current = container;
		}
	}
	if (current != featureCall && staticNotation) {
		return (XAbstractFeatureCall) current.getMemberCallTarget();
	}
	return null;
}
 
Example 4
Source File: ImportsCollector.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
protected void _visit(final XMemberFeatureCall semanticObj, final INode originNode, final ImportsAcceptor acceptor) {
  if (((semanticObj.getFeature() instanceof JvmType) && semanticObj.isTypeLiteral())) {
    JvmIdentifiableElement _feature = semanticObj.getFeature();
    this.visit(((JvmType) _feature), originNode, acceptor);
  }
  boolean _isExplicitStatic = semanticObj.isExplicitStatic();
  boolean _not = (!_isExplicitStatic);
  if (_not) {
    final XExpression target = semanticObj.getMemberCallTarget();
    if ((target instanceof XAbstractFeatureCall)) {
      boolean _isTypeLiteral = ((XAbstractFeatureCall)target).isTypeLiteral();
      if (_isTypeLiteral) {
        return;
      }
    }
    this.collectStaticImportsFrom(semanticObj, acceptor);
  }
}
 
Example 5
Source File: XbaseLocationInFileProvider.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected ITextRegion getLocationOfContainmentReference(EObject owner, EReference reference, int indexInList, RegionDescription query) {
	if (owner instanceof XMemberFeatureCall && reference == XbasePackage.Literals.XMEMBER_FEATURE_CALL__MEMBER_CALL_TARGET) {
		XMemberFeatureCall casted = (XMemberFeatureCall) owner;
		if (casted.isExplicitStatic() || casted.isStaticWithDeclaringType()) {
			XExpression target = ((XMemberFeatureCall) owner).getMemberCallTarget();
			return getTextRegion(target, query);
		}
	}
	return super.getLocationOfContainmentReference(owner, reference, indexInList, query);
}
 
Example 6
Source File: FeatureCallAsTypeLiteralHelper.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
public boolean isDefiniteTypeLiteral(XAbstractFeatureCall featureCall) {
	if (featureCall.isExplicitOperationCallOrBuilderSyntax())
		return false;
	if (!featureCall.getTypeArguments().isEmpty())
		return false;
	if (featureCall.eContainingFeature() == XbasePackage.Literals.XMEMBER_FEATURE_CALL__MEMBER_CALL_TARGET) {
		XMemberFeatureCall container = (XMemberFeatureCall) featureCall.eContainer();
		if (container.isExplicitStatic()) {
			return true;
		}
		return isDefiniteTypeLiteral(container);
	}
	return false;
}
 
Example 7
Source File: UnresolvedFeatureCallTypeAwareMessageProvider.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected boolean isStaticMemberCallTarget(final EObject contextObject) {
  boolean candidate = ((contextObject instanceof XFeatureCall) && (contextObject.eContainingFeature() == 
    XbasePackage.Literals.XMEMBER_FEATURE_CALL__MEMBER_CALL_TARGET));
  if (candidate) {
    EObject _eContainer = contextObject.eContainer();
    XMemberFeatureCall memberFeatureCall = ((XMemberFeatureCall) _eContainer);
    boolean _isExplicitStatic = memberFeatureCall.isExplicitStatic();
    if (_isExplicitStatic) {
      return true;
    }
  }
  return false;
}
 
Example 8
Source File: CreateMemberQuickfixes.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
protected boolean isStaticAccess(XAbstractFeatureCall call) {
	if (call instanceof XMemberFeatureCall) {
		XMemberFeatureCall featureCall = (XMemberFeatureCall) call;
		if (featureCall.isExplicitStatic()) {
			return true;
		}
		if (featureCall.getMemberCallTarget() instanceof XAbstractFeatureCall) {
			XAbstractFeatureCall targetCall = (XAbstractFeatureCall) featureCall.getMemberCallTarget();
			if ( targetCall.isTypeLiteral()) {
				return true;
			}
		}
	}
	return isStatic(logicalContainerProvider.getNearestLogicalContainer(call)); 
}
 
Example 9
Source File: XbaseSemanticSequencer.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Constraint:
 *     (
 *         memberCallTarget=XMemberFeatureCall_XMemberFeatureCall_1_1_0_0_0
 *         (nullSafe?='?.' | spreading?='*.')?
 *         (typeArguments+=JvmArgumentTypeReference typeArguments+=JvmArgumentTypeReference*)?
 *         feature=[JvmIdentifiableElement|ID]
 *         (explicitOperationCall?='(' (memberCallArguments+=XShortClosure | (memberCallArguments+=XExpression memberCallArguments+=XExpression*))?)?
 *     )
 *     
 *
 * Features:
 *    feature[1, 1]
 *    typeArguments[0, *]
 *    memberCallTarget[1, 1]
 *    memberCallArguments[1, *]
 *         EXCLUDE_IF_UNSET explicitOperationCall
 *    explicitOperationCall[0, 1]
 *         MANDATORY_IF_SET memberCallArguments
 *         EXCLUDE_IF_UNSET memberCallArguments
 *         MANDATORY_IF_SET memberCallArguments
 *         MANDATORY_IF_SET memberCallArguments
 *    spreading[0, 1]
 *         EXCLUDE_IF_SET nullSafe
 *    nullSafe[0, 1]
 *         EXCLUDE_IF_SET spreading
 */
@Override
protected void sequence_XMemberFeatureCall(ISerializationContext context, XMemberFeatureCall featureCall) {
	INodesForEObjectProvider nodes = createNodeProvider(featureCall);
	SequenceFeeder acceptor = createSequencerFeeder(context, featureCall, nodes);
	XMemberFeatureCallElements memberFeatureCallElements= grammarAccess.getXMemberFeatureCallAccess();

	// memberCallTarget=XMemberFeatureCall_XMemberFeatureCall_1_1_0_0_0
	acceptor.accept(memberFeatureCallElements.getXMemberFeatureCallMemberCallTargetAction_1_1_0_0_0(), featureCall.getMemberCallTarget());

	// (nullSafe?='?.' | explicitStatic?='::')?
	if (featureCall.isNullSafe())
		acceptor.accept(memberFeatureCallElements.getNullSafeQuestionMarkFullStopKeyword_1_1_0_0_1_1_0());
	else if (featureCall.isExplicitStatic())
		acceptor.accept(memberFeatureCallElements.getExplicitStaticColonColonKeyword_1_1_0_0_1_2_0());

	// (typeArguments+=JvmArgumentTypeReference typeArguments+=JvmArgumentTypeReference*)?
	List<JvmTypeReference> typeArguments = featureCall.getTypeArguments();
	if (!typeArguments.isEmpty()) {
		acceptor.accept(memberFeatureCallElements.getTypeArgumentsJvmArgumentTypeReferenceParserRuleCall_1_1_1_1_0(), typeArguments.get(0), 0);
		for (int i = 1; i < typeArguments.size(); i++)
			acceptor.accept(memberFeatureCallElements.getTypeArgumentsJvmArgumentTypeReferenceParserRuleCall_1_1_1_2_1_0(), typeArguments.get(i), i);
	}

	// feature=[JvmIdentifiableElement|ID]
	acceptor.accept(memberFeatureCallElements.getFeatureJvmIdentifiableElementIdOrSuperParserRuleCall_1_1_2_0_1(), featureCall.getFeature());

	// (explicitOperationCall?='(' (memberCallArguments+=XShortClosure | (memberCallArguments+=XExpression memberCallArguments+=XExpression*))?)? memberCallArguments+=XClosure? 
	if (featureCall.isExplicitOperationCallOrBuilderSyntax()) {
		if (featureCall.isExplicitOperationCall())
			acceptor.accept(memberFeatureCallElements.getExplicitOperationCallLeftParenthesisKeyword_1_1_3_0_0());
		List<XExpression> arguments = featureCall.getMemberCallArguments();
		if (!arguments.isEmpty()) {
			if (featureCall.isExplicitOperationCall() && isXShortClosureAndBuilderSyntax(arguments, XbasePackage.Literals.XFEATURE_CALL__FEATURE_CALL_ARGUMENTS, nodes)) {
				acceptor.accept(memberFeatureCallElements.getMemberCallArgumentsXShortClosureParserRuleCall_1_1_3_1_0_0(), arguments.get(0), 0);
				acceptor.accept(memberFeatureCallElements.getMemberCallArgumentsXClosureParserRuleCall_1_1_4_0(), arguments.get(1), 1);
			} else if (featureCall.isExplicitOperationCall() && isXShortClosure(featureCall, XbasePackage.Literals.XMEMBER_FEATURE_CALL__MEMBER_CALL_ARGUMENTS, nodes)) {
				acceptor.accept(memberFeatureCallElements.getMemberCallArgumentsXShortClosureParserRuleCall_1_1_3_1_0_0(), arguments.get(0), 0);
			} else {
				int diff = 0;
				if (isBuilderSyntax(featureCall, XbasePackage.Literals.XMEMBER_FEATURE_CALL__MEMBER_CALL_ARGUMENTS, featureCall.isExplicitOperationCall(), nodes)) {
					diff = 1;
				}
				if (featureCall.isExplicitOperationCall()) {
					if (arguments.size() - diff > 0)
						acceptor.accept(memberFeatureCallElements.getMemberCallArgumentsXExpressionParserRuleCall_1_1_3_1_1_0_0(), arguments.get(0), 0);
					for (int i = 1; i < arguments.size() - diff; i++)
						acceptor.accept(memberFeatureCallElements.getMemberCallArgumentsXExpressionParserRuleCall_1_1_3_1_1_1_1_0(), arguments.get(i), i);
				}
				if (diff != 0) {
					int lastIdx = arguments.size() - 1;
					acceptor.accept(memberFeatureCallElements.getMemberCallArgumentsXClosureParserRuleCall_1_1_4_0(), arguments.get(lastIdx), lastIdx);
				}
			}
		}
	}
	acceptor.finish();
}