Java Code Examples for org.eclipse.xtext.xbase.XMemberFeatureCall#isNullSafe()
The following examples show how to use
org.eclipse.xtext.xbase.XMemberFeatureCall#isNullSafe() .
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: XbaseValidator.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@Check void checkNullSafeFeatureCallWithPrimitives(XMemberFeatureCall featureCall) { if (featureCall.isNullSafe()) { if (getActualType(featureCall.getMemberCallTarget()).isPrimitive()) { error("Cannot use null-safe feature call on primitive receiver", featureCall, Literals.XMEMBER_FEATURE_CALL__NULL_SAFE, NULL_SAFE_FEATURE_CALL_ON_PRIMITIVE); return; } LightweightTypeReference type = getActualType(featureCall); if (type.isPrimitive() && isValueExpectedRecursive(featureCall)) { addIssue("Null-safe call of primitive-valued feature " + featureCall.getConcreteSyntaxFeatureName() + ", default value "+ getDefaultValue(type) +" will be used", featureCall, NULL_SAFE_FEATURE_CALL_OF_PRIMITIVE_VALUED_FEATURE); } } }
Example 2
Source File: XbaseInterpreter.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected Object _doEvaluate(final XMemberFeatureCall featureCall, final IEvaluationContext context, final CancelIndicator indicator) { if (featureCall.isTypeLiteral()) { JvmType type = (JvmType) featureCall.getFeature(); Object result = translateJvmTypeToResult(type, 0); return result; } else { XExpression receiver = getActualReceiver(featureCall); //, featureCall.getFeature(), featureCall.getImplicitReceiver()); Object receiverObj = receiver==null?null:internalEvaluate(receiver, context, indicator); if (featureCall.isNullSafe() && receiverObj==null) { return getDefaultObjectValue(typeResolver.resolveTypes(featureCall).getActualType(featureCall)); } return invokeFeature(featureCall.getFeature(), featureCall, receiverObj, context, indicator); } }
Example 3
Source File: XbaseSemanticSequencer.java From xtext-extras with Eclipse Public License 2.0 | 4 votes |
/** * 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(); }
Example 4
Source File: FeatureCallCompiler.java From xtext-extras with Eclipse Public License 2.0 | 4 votes |
protected boolean isVariableDeclarationRequired(XMemberFeatureCall expr, @SuppressWarnings("unused") ITreeAppendable b) { return expr.isNullSafe(); }