org.eclipse.xtext.xbase.XAssignment Java Examples

The following examples show how to use org.eclipse.xtext.xbase.XAssignment. 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: SARLJvmModelInferrer.java    From sarl with Apache License 2.0 6 votes vote down vote up
/** Infer the function's return type.
 *
 * @param body the body of the function.
 * @return the return type.
 */
protected JvmTypeReference inferFunctionReturnType(XExpression body) {
	XExpression expr = body;
	boolean stop = false;
	while (!stop && expr instanceof XBlockExpression) {
		final XBlockExpression block = (XBlockExpression) expr;
		switch (block.getExpressions().size()) {
		case 0:
			expr = null;
			break;
		case 1:
			expr = block.getExpressions().get(0);
			break;
		default:
			stop = true;
		}
	}
	if (expr == null || expr instanceof XAssignment || expr instanceof XVariableDeclaration
			|| expr instanceof SarlBreakExpression || expr instanceof SarlContinueExpression
			|| expr instanceof SarlAssertExpression) {
		return this._typeReferenceBuilder.typeRef(Void.TYPE);
	}
	return this.typeBuilder.inferredType(body);
}
 
Example #2
Source File: FeatureLinkHelper.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
public XExpression getSyntacticReceiver(XExpression expression) {
	if (expression instanceof XAbstractFeatureCall) {
		if (expression instanceof XFeatureCall) {
			return null;
		}
		if (expression instanceof XMemberFeatureCall) {
			return ((XMemberFeatureCall) expression).getMemberCallTarget();
		}
		if (expression instanceof XAssignment) {
			return ((XAssignment) expression).getAssignable();
		}
		if (expression instanceof XBinaryOperation) {
			return ((XBinaryOperation) expression).getLeftOperand();
		}
		if (expression instanceof XUnaryOperation) {
			return ((XUnaryOperation) expression).getOperand();
		}
		if (expression instanceof XPostfixOperation) {
			return ((XPostfixOperation) expression).getOperand();
		}
	}
	return null;
}
 
Example #3
Source File: FeatureLinkHelper.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
public List<XExpression> getSyntacticArguments(XAbstractFeatureCall expression) {
	if (expression instanceof XFeatureCall) {
		return ((XFeatureCall) expression).getFeatureCallArguments();
	}
	if (expression instanceof XMemberFeatureCall) {
		return ((XMemberFeatureCall) expression).getMemberCallArguments();
	}
	if (expression instanceof XAssignment) {
		return Collections.singletonList(((XAssignment) expression).getValue());
	}
	if (expression instanceof XBinaryOperation) {
		return Collections.singletonList(((XBinaryOperation) expression).getRightOperand());
	}
	// explicit condition to make sure we thought about it
	if (expression instanceof XUnaryOperation) {
		return Collections.emptyList();
	}
	if (expression instanceof XPostfixOperation) {
		return Collections.emptyList();
	}
	return Collections.emptyList();
}
 
Example #4
Source File: FeatureLinkingCandidate.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected int getConformanceFlags(int idx, boolean recompute) {
	if (isStatic()) {
		if (idx == -1) {
			return ConformanceFlags.CHECKED_SUCCESS;
		}
	}
	if (idx == 0) {
		if (getReceiver() != null) {
			int result = getReceiverConformanceFlags();
			return result;
		}
	} else if (idx == 1) {
		if (getExpression() instanceof XAssignment && getFeature() instanceof JvmField) {
			return super.getConformanceFlags(0, recompute);
		}
	}
	return super.getConformanceFlags(idx, recompute);
}
 
Example #5
Source File: SerializerScopeProvider.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
protected IScope getExecutableScope(XAbstractFeatureCall call, JvmIdentifiableElement feature) {
	final String simpleName = feature.getSimpleName();
	QualifiedName name = QualifiedName.create(simpleName);
	if (call.isOperation()) {
		QualifiedName operator = getOperator(call, name);
		if (operator == null) {
			return IScope.NULLSCOPE;
		}
		return new SingletonScope(EObjectDescription.create(operator, feature), IScope.NULLSCOPE);
	}
	if (call instanceof XAssignment) {
		return getAccessorScope(simpleName, name, feature);
	}
	if (call.isExplicitOperationCallOrBuilderSyntax() || ((JvmExecutable) feature).getParameters().size() > 1
			|| (!call.isExtension() && ((JvmExecutable) feature).getParameters().size() == 1)) {
		return new SingletonScope(EObjectDescription.create(name, feature), IScope.NULLSCOPE);
	}

	return getAccessorScope(simpleName, name, feature);
}
 
Example #6
Source File: AbstractSessionBasedScope.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Considers the given name to be a property name. If the concrete syntax of the
 * processed feature matches a feature call or assignment, a prefix is added to the
 * name and that one is used as a variant that should be processed. 
 */
protected void processAsPropertyNames(QualifiedName name, NameAcceptor acceptor) {
	String nameAsPropertyName = tryGetAsPropertyName(name.toString());
	if (nameAsPropertyName != null) {
		if (featureCall == null || featureCall instanceof XAssignment) {
			String aliasedSetter = "set" + nameAsPropertyName;
			acceptor.accept(aliasedSetter, 2);
		}
		if (!(featureCall instanceof XAssignment)) {
			if (featureCall == null || !getFeatureCall().isExplicitOperationCallOrBuilderSyntax()) {
				String aliasedGetter = "get" + nameAsPropertyName;
				acceptor.accept(aliasedGetter, 2);
				String aliasedBooleanGetter = "is" + nameAsPropertyName;
				acceptor.accept(aliasedBooleanGetter, 2);
			}
		}
	}
}
 
Example #7
Source File: SARLValidator.java    From sarl with Apache License 2.0 6 votes vote down vote up
/** Replies if the given object is locally assigned.
 *
 * <p>An object is locally assigned when it is the left operand of an assignment operation.
 *
 * @param target the object to test.
 * @param containerToFindUsage the container in which the usages should be find.
 * @return {@code true} if the given object is assigned.
 * @since 0.7
 */
protected boolean isLocallyAssigned(EObject target, EObject containerToFindUsage) {
	if (this.readAndWriteTracking.isAssigned(target)) {
		return true;
	}
	final Collection<Setting> usages = XbaseUsageCrossReferencer.find(target, containerToFindUsage);
	// field are assigned when they are not used as the left operand of an assignment operator.
	for (final Setting usage : usages) {
		final EObject object = usage.getEObject();
		if (object instanceof XAssignment) {
			final XAssignment assignment = (XAssignment) object;
			if (assignment.getFeature() == target) {
				// Mark the field as assigned in order to be faster during the next assignment test.
				this.readAndWriteTracking.markAssignmentAccess(target);
				return true;
			}
		}
	}
	return false;
}
 
Example #8
Source File: AssignmentLinkingTest.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
@Test public void testParameter() throws Exception {
	XtendClass clazz = clazz(
			"class SomeClass {\n" +
			"  def void method(String aString) {\n" + 
			"    aString = 'foo'\n" + 
			"  }\n" + 
			"}");
	XAssignment assignment = getLastAssignment(clazz);
	assertNotNull("feature is available", assignment.getFeature());
	JvmIdentifiableElement linked = assignment.getFeature();
	assertFalse("is resolved", linked.eIsProxy());
	assertEquals("aString", linked.getIdentifier());
	assertTrue(TypesPackage.Literals.JVM_FORMAL_PARAMETER.isInstance(linked));
	assertNull(assignment.getInvalidFeatureIssueCode(), assignment.getInvalidFeatureIssueCode());
}
 
Example #9
Source File: FeatureCallCompiler.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
protected void featureCalltoJavaExpression(final XAbstractFeatureCall call, ITreeAppendable b, boolean isExpressionContext) {
	if (call instanceof XAssignment) {
		assignmentToJavaExpression((XAssignment) call, b, isExpressionContext);
	} else {
		if (needMultiAssignment(call)) {
			appendLeftOperand(call, b, isExpressionContext).append(" = ");
		}
		final JvmAnnotationReference annotationRef = this.expressionHelper.findInlineAnnotation(call);
		if (annotationRef == null || !isConstantExpression(annotationRef)) {
			boolean hasReceiver = appendReceiver(call, b, isExpressionContext);
			if (hasReceiver) {
				b.append(".");
				b = appendTypeArguments(call, b);
			}
		}
		appendFeatureCall(call, b);
	}
}
 
Example #10
Source File: LinkingTest.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testDeclaredConstructor_01() throws Exception {
	XtendClass clazz = clazz(
			"class Foo { " +
			"  int i" +
			"  new(int i) { this.i = i }" +
			"}");
	assertEquals(2, clazz.getMembers().size());
	
	XtendConstructor constructor = (XtendConstructor) clazz.getMembers().get(1);
	XAssignment assignment = (XAssignment) ((XBlockExpression)constructor.getExpression()).getExpressions().get(0);
	JvmField field = (JvmField) assignment.getFeature();
	assertEquals("i", field.getSimpleName());
	XFeatureCall target = (XFeatureCall) assignment.getAssignable();
	JvmDeclaredType identifiableElement = (JvmDeclaredType) target.getFeature();
	assertEquals("Foo", identifiableElement.getSimpleName());
	XFeatureCall value = (XFeatureCall) assignment.getValue();
	JvmFormalParameter parameter = (JvmFormalParameter) value.getFeature();
	assertEquals("i", parameter.getSimpleName());
}
 
Example #11
Source File: XbaseNodeModelTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testAssignment_rhs_05() throws Exception {
	String text = "a = b += c = d";
	XAssignment assignment = (XAssignment) expression(text);
	List<INode> nodesForFeature = NodeModelUtils.findNodesForFeature(assignment, XbasePackage.Literals.XASSIGNMENT__VALUE);
	assertEquals(1, nodesForFeature.size());
	String nodeText = nodesForFeature.get(0).getText();
	assertEquals(" b += c = d", nodeText);
}
 
Example #12
Source File: AssignmentLinkingTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testSugaredAssignment_onThis_withIt() throws Exception {
	XtendClass clazz = clazz(
			"class SomeClass {\n" +
			"  def void method(String it) {\n" + 
			"    value = 'foo'\n" + 
			"  }\n" +
			"  def void setValue(String receiver, String value) {}" +
			"}");
	XAssignment assignment = getLastAssignment(clazz);
	assertLinksTo("SomeClass.setValue(java.lang.String,java.lang.String)", assignment);
	assertImplicitReceiver("SomeClass", assignment);
}
 
Example #13
Source File: AssignmentLinkingTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
protected void assertImplicitReceiver(String identifier, XAssignment assignment) {
	assertTrue("assignment.implicitReceiver instanceof XFeatureCall", assignment.getImplicitReceiver() instanceof XAbstractFeatureCall);
	XAbstractFeatureCall implicitReceiver = (XAbstractFeatureCall) assignment.getImplicitReceiver();
	JvmIdentifiableElement linked = implicitReceiver.getFeature();
	assertFalse("is resolved", linked.eIsProxy());
	assertEquals(identifier, linked.getIdentifier());
}
 
Example #14
Source File: AssignmentLinkingTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testSugaredAssignment_asExtension() throws Exception {
	XtendClass clazz = clazz(
			"class SomeClass {\n" +
			"  def void method(String something) {\n" + 
			"    something.myValue = 'foo'\n" + 
			"  }\n" +
			"  def void setMyValue(String something, String value) {}" +
			"}");
	XAssignment assignment = getLastAssignment(clazz);
	assertLinksTo("SomeClass.setMyValue(java.lang.String,java.lang.String)", assignment);
	assertImplicitReceiver("SomeClass", assignment);
}
 
Example #15
Source File: AssignmentLinkingTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testUnqualifiedField_withConflict_onIt() throws Exception {
	XtendClass clazz = clazz(
			"class SomeClass {\n" +
			"  def void method(testdata.Properties1 it) {\n" + 
			"    prop1 = 'foo'\n" + 
			"  }" +
			"}");
	XAssignment assignment = getLastAssignment(clazz);
	assertLinksTo("testdata.Properties1.prop1", assignment);
	assertImplicitReceiver("it", assignment);
}
 
Example #16
Source File: AssignmentLinkingTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testSugaredAssignment_onThis() throws Exception {
	XtendClass clazz = clazz(
			"class SomeClass {\n" +
			"  def void method() {\n" + 
			"    string = 'foo'\n" + 
			"  }" +
			"  def setString(String aString) {}\n" + 
			"}");
	XAssignment assignment = getLastAssignment(clazz);
	assertLinksTo("SomeClass.setString(java.lang.String)", assignment);
	assertImplicitReceiver("SomeClass", assignment);
}
 
Example #17
Source File: AssignmentLinkingTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testUnqualifiedField_onExtension() throws Exception {
	XtendClass clazz = clazz(
			"class SomeClass {\n" +
			"  def void method() {\n" + 
			"    stringField = 'foo'\n" + 
			"  }\n" +
			"  extension testdata.FieldAccess" +
			"}");
	XAssignment assignment = getLastAssignment(clazz);
	assertLinksTo("testdata.FieldAccess.stringField", assignment);
	assertImplicitReceiver("SomeClass._fieldAccess", assignment);
}
 
Example #18
Source File: AssignmentLinkingTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testUnqualifiedField_onIt() throws Exception {
	XtendClass clazz = clazz(
			"class SomeClass {\n" +
			"  def void method(testdata.FieldAccess it) {\n" + 
			"    stringField = 'foo'\n" + 
			"  }" +
			"}");
	XAssignment assignment = getLastAssignment(clazz);
	assertLinksTo("testdata.FieldAccess.stringField", assignment);
	assertImplicitReceiver("it", assignment);
}
 
Example #19
Source File: AssignmentLinkingTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testSugaredAssignment_onIt() throws Exception {
	XtendClass clazz = clazz(
			"class SomeClass {\n" +
			"  def void method(testdata.Properties1 it) {\n" + 
			"    prop2 = 'foo'\n" + 
			"  }" +
			"}");
	XAssignment assignment = getLastAssignment(clazz);
	assertLinksTo("testdata.Properties1.setProp2(java.lang.String)", assignment);
	assertImplicitReceiver("it", assignment);
}
 
Example #20
Source File: XbaseQuickfixProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Fix(IssueCodes.FEATURE_NOT_VISIBLE)
public void fixInvisibleFeature(final Issue issue, IssueResolutionAcceptor acceptor) {
	if (issue.getData() != null && issue.getData().length >= 1 && "subclass-context".equals(issue.getData()[0])) {
		String fixup;
		if (issue.getData().length == 1)
			fixup = "Add type cast.";
		else
			fixup = "Add cast to " + issue.getData()[1] + ".";
		acceptor.accept(issue, fixup, fixup, null,
				new ISemanticModification() {

					@Override
					public void apply(EObject element, IModificationContext context) throws Exception {
						if (!(element instanceof XAbstractFeatureCall))
							return;
						XAbstractFeatureCall featureCall = (XAbstractFeatureCall) element;
						if (!(featureCall.getFeature() instanceof JvmMember))
							return;
						JvmType declaringType = ((JvmMember) featureCall.getFeature()).getDeclaringType();
						if (featureCall instanceof XMemberFeatureCall) {
							addTypeCastToExplicitReceiver(featureCall, context, declaringType,
									XbasePackage.Literals.XMEMBER_FEATURE_CALL__MEMBER_CALL_TARGET);
						} else if (featureCall instanceof XAssignment) {
							addTypeCastToExplicitReceiver(featureCall, context, declaringType,
									XbasePackage.Literals.XASSIGNMENT__ASSIGNABLE);
						} else if (featureCall instanceof XFeatureCall) {
							addTypeCastToImplicitReceiver((XFeatureCall) featureCall, context, declaringType);
						}
					}

				});
	}
}
 
Example #21
Source File: CreateMemberQuickfixes.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
protected LightweightTypeReference getNewMemberType(XAbstractFeatureCall call) {
	IResolvedTypes resolvedTypes = typeResolver.resolveTypes(call);
	if(call instanceof XAssignment) {
		XExpression value = ((XAssignment) call).getValue();
		return resolvedTypes.getActualType(value);
	} else {
		return resolvedTypes.getExpectedType(call);
	}
}
 
Example #22
Source File: JvmModelReferenceUpdater.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @since 2.4
 */
protected ReferenceSyntax getReferenceSyntax(EObject referringElement, EReference reference, int indexInList) {
	if (reference == XbasePackage.Literals.XABSTRACT_FEATURE_CALL__FEATURE) {
		if (referringElement instanceof XAssignment) 
			return ReferenceSyntax.SET_BY_ASSIGNMENT;
		List<INode> nodes = NodeModelUtils.findNodesForFeature(referringElement, reference);
		int index = Math.max(indexInList, 0);
		if (nodes.size() < index)
			return null;
		INode oldNode = nodes.get(index);
		String referenceText = oldNode.getText().trim();
		return getReferenceSyntax(referenceText);
	}
	return null;
}
 
Example #23
Source File: XbaseParserTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testAssignment_RightAssociativity() throws Exception {
	XAssignment ass = (XAssignment) expression("foo = bar += baz");
	assertEquals(1,ass.getExplicitArguments().size());
	assertEquals("foo", ass.getConcreteSyntaxFeatureName());
	assertNull(ass.getAssignable());
	XBinaryOperation op = (XBinaryOperation) ass.getExplicitArguments().get(0);
	assertEquals(2,op.getExplicitArguments().size());
	assertEquals("+=", op.getConcreteSyntaxFeatureName());
	assertEquals("bar", ((XFeatureCall)op.getExplicitArguments().get(0)).getConcreteSyntaxFeatureName());
	assertEquals("baz", ((XFeatureCall)op.getExplicitArguments().get(1)).getConcreteSyntaxFeatureName());
}
 
Example #24
Source File: XbaseProposalProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void completeXMemberFeatureCall_Feature(EObject model, Assignment assignment, ContentAssistContext context,
		ICompletionProposalAcceptor acceptor) {
	if (model instanceof XMemberFeatureCall) {
		XExpression memberCallTarget = ((XMemberFeatureCall) model).getMemberCallTarget();
		IResolvedTypes resolvedTypes = typeResolver.resolveTypes(memberCallTarget);
		LightweightTypeReference memberCallTargetType = resolvedTypes.getActualType(memberCallTarget);
		Iterable<JvmFeature> featuresToImport = getFavoriteStaticFeatures(model, input -> {
			if(input instanceof JvmOperation && input.isStatic()) {
				List<JvmFormalParameter> parameters = ((JvmOperation) input).getParameters();
				if(parameters.size() > 0) {
					JvmFormalParameter firstParam = parameters.get(0);
					JvmTypeReference parameterType = firstParam.getParameterType();
					if(parameterType != null) {
						LightweightTypeReference lightweightTypeReference = memberCallTargetType.getOwner().toLightweightTypeReference(parameterType);
						if(lightweightTypeReference != null) {
							return memberCallTargetType.isAssignableFrom(lightweightTypeReference);
						}
					}
				}
			}
			return false;
		});
		// Create StaticExtensionFeatureDescriptionWithImplicitFirstArgument 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 StaticExtensionFeatureDescriptionWithImplicitFirstArgument(qualifiedName, feature, memberCallTarget, memberCallTargetType, 0, true);
		});
		// Scope for all static features
		IScope staticMemberScope = new SimpleScope(IScope.NULLSCOPE, scopedFeatures);
		proposeFavoriteStaticFeatures(model, context, acceptor, staticMemberScope);
		// Regular proposals
		createReceiverProposals(((XMemberFeatureCall) model).getMemberCallTarget(), (CrossReference) assignment.getTerminal(),
				context, acceptor);
	} else if (model instanceof XAssignment) {
		createReceiverProposals(((XAssignment) model).getAssignable(), (CrossReference) assignment.getTerminal(),
				context, acceptor);
	}
}
 
Example #25
Source File: XbaseLocationInFileProviderTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testQualifiedAssignment_01() throws Exception {
	String text = "'a'.doesNotExist = 'b'";
	XAssignment assignment = castedExpression(text);
	ITextRegion region = locationInFileProvider.getSignificantTextRegion(assignment);
	String significant = text.substring(region.getOffset(), region.getOffset() + region.getLength());
	assertEquals(text.substring(text.indexOf('.') + 1) , significant);
}
 
Example #26
Source File: XbaseLocationInFileProviderTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testAssignment_rhs_01() throws Exception {
	String text = "a = b";
	XAssignment assignment = (XAssignment) expression(text);
	ITextRegion region = locationInFileProvider.getSignificantTextRegion(assignment, XbasePackage.Literals.XASSIGNMENT__VALUE, 0);
	String significant = text.substring(region.getOffset(), region.getOffset() + region.getLength());
	assertEquals("b", significant);
}
 
Example #27
Source File: XbaseLocationInFileProviderTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testAssignment_rhs_02() throws Exception {
	String text = "a = b += c";
	XAssignment assignment = (XAssignment) expression(text);
	ITextRegion region = locationInFileProvider.getSignificantTextRegion(assignment, XbasePackage.Literals.XASSIGNMENT__VALUE, 0);
	String significant = text.substring(region.getOffset(), region.getOffset() + region.getLength());
	assertEquals("b += c", significant);
}
 
Example #28
Source File: PyExpressionGenerator.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Generate the given object.
 *
 * @param assignment the assignment operator.
 * @param it the target for the generated content.
 * @param context the context.
 * @return the assignment.
 */
protected XExpression _generate(XAssignment assignment, IAppendable it, IExtraLanguageGeneratorContext context) {
	appendReturnIfExpectedReturnedExpression(it, context);
	it.append("("); //$NON-NLS-1$
	newFeatureCallGenerator(context, it).generate(assignment);
	it.append(" = "); //$NON-NLS-1$
	generate(assignment.getValue(), it, context);
	it.append(")"); //$NON-NLS-1$
	return assignment;
}
 
Example #29
Source File: AbstractXbaseLinkingTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testLocalVarAssignment_1() throws Exception {
	XBlockExpression block = (XBlockExpression) expression("{ var x = ''; x = '' }");
	XAssignment assignment = (XAssignment) block.getExpressions().get(1);
	assertNull(assignment.getAssignable());
	assertTrue(String.valueOf(assignment.getFeature()), assignment.getFeature() instanceof XVariableDeclaration);
	assertSame(block.getExpressions().get(0), assignment.getFeature());
}
 
Example #30
Source File: XbaseLocationInFileProviderTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testAssignment_rhs_04() throws Exception {
	String text = "a = b += c";
	XBinaryOperation assignment = (XBinaryOperation) ((XAssignment) expression(text)).getValue();
	ITextRegion region = locationInFileProvider.getSignificantTextRegion(assignment, XbasePackage.Literals.XBINARY_OPERATION__LEFT_OPERAND, 0);
	String significant = text.substring(region.getOffset(), region.getOffset() + region.getLength());
	assertEquals("b", significant);
}