org.eclipse.xtext.xbase.XVariableDeclaration Java Examples

The following examples show how to use org.eclipse.xtext.xbase.XVariableDeclaration. 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: ParserTest.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testRichStringFOR_03() throws Exception {
	XtendFunction function = function("def withForLoop(String it) '''�it��val it = 1..10��FOR i: it SEPARATOR it��ENDFOR�'''");
	final RichString richString = (RichString) function.getExpression();
	assertTrue(richString.getExpressions().get(0) instanceof RichStringLiteral);
	assertTrue(richString.getExpressions().get(1) instanceof XFeatureCall);
	JvmOperation operation = associations.getDirectlyInferredOperation(function);
	assertSame(operation.getParameters().get(0), ((XAbstractFeatureCall) richString.getExpressions().get(1)).getFeature());
	assertTrue(richString.getExpressions().get(2) instanceof RichStringLiteral);
	assertTrue(richString.getExpressions().get(3) instanceof XVariableDeclaration);
	assertTrue(richString.getExpressions().get(4) instanceof RichStringLiteral);
	assertTrue(richString.getExpressions().get(5) instanceof RichStringForLoop);
	
	final RichStringForLoop rsFor = (RichStringForLoop) richString.getExpressions().get(5);
	assertTrue(rsFor.getForExpression() instanceof XFeatureCall);
	assertSame(richString.getExpressions().get(3), ((XAbstractFeatureCall) rsFor.getForExpression()).getFeature()); 
	assertEquals("i", rsFor.getDeclaredParam().getName());
	assertTrue(rsFor.getSeparator() instanceof XFeatureCall);
	assertSame(richString.getExpressions().get(3), ((XAbstractFeatureCall) rsFor.getSeparator()).getFeature());
}
 
Example #2
Source File: XTryCatchFinallyExpressionImpl.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@SuppressWarnings("unchecked")
@Override
public void eSet(int featureID, Object newValue)
{
	switch (featureID)
	{
		case XbasePackage.XTRY_CATCH_FINALLY_EXPRESSION__EXPRESSION:
			setExpression((XExpression)newValue);
			return;
		case XbasePackage.XTRY_CATCH_FINALLY_EXPRESSION__FINALLY_EXPRESSION:
			setFinallyExpression((XExpression)newValue);
			return;
		case XbasePackage.XTRY_CATCH_FINALLY_EXPRESSION__CATCH_CLAUSES:
			getCatchClauses().clear();
			getCatchClauses().addAll((Collection<? extends XCatchClause>)newValue);
			return;
		case XbasePackage.XTRY_CATCH_FINALLY_EXPRESSION__RESOURCES:
			getResources().clear();
			getResources().addAll((Collection<? extends XVariableDeclaration>)newValue);
			return;
	}
	super.eSet(featureID, newValue);
}
 
Example #3
Source File: SwitchConstantExpressionsInterpreterTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
protected void evaluatesTo(Pair<String, String> typeAndExpression, Procedure1<? super Object> assertions) throws Exception {
	String type = typeAndExpression.getKey();
	String expression = typeAndExpression.getValue();
	StringBuilder builder = new StringBuilder();
	// @formatter:off
	builder.append("{\n");
	builder.append("    val");
	if (type != null) {
		builder.append(" ");
		builder.append(type);
	}
	builder.append(" testFoo = ");
	builder.append(expression);
	builder.append("\n");
	builder.append("}\n");
	// @formatter:on
	String charSequence = builder.toString();
	XBlockExpression blockExpression = (XBlockExpression) expression(charSequence, true);
	XVariableDeclaration variableDeclaration = (XVariableDeclaration) Iterables.getFirst(blockExpression.getExpressions(), null);
	evaluatesTo(variableDeclaration, assertions);
}
 
Example #4
Source File: SerializerScopeProvider.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
public IScope createFeatureCallSerializationScope(EObject context) {
	if (!(context instanceof XAbstractFeatureCall)) {
		return IScope.NULLSCOPE;
	}
	XAbstractFeatureCall call = (XAbstractFeatureCall) context;
	JvmIdentifiableElement feature = call.getFeature();
	// this and super - logical container aware FeatureScopes
	if (feature instanceof JvmType) {
		return getTypeScope(call, (JvmType) feature);
	}
	if (feature instanceof JvmConstructor) {
		return getThisOrSuperScope(call, (JvmConstructor) feature);
	}
	if (feature instanceof JvmExecutable) {
		return getExecutableScope(call, feature);
	}
	if (feature instanceof JvmFormalParameter || feature instanceof JvmField || feature instanceof XVariableDeclaration || feature instanceof XSwitchExpression) {
		return new SingletonScope(EObjectDescription.create(feature.getSimpleName(), feature), IScope.NULLSCOPE);
	}
	return IScope.NULLSCOPE;
}
 
Example #5
Source File: SARLOperationHelper.java    From sarl with Apache License 2.0 6 votes vote down vote up
private static boolean isLocalExpression(XAbstractFeatureCall expression, ISideEffectContext context, boolean dereference) {
	if (expression.isTypeLiteral() || expression.isPackageFragment()) {
		return false;
	}
	final JvmIdentifiableElement feature = expression.getFeature();
	if (feature != null && (feature.eIsProxy() || isExternalFeature(feature))) {
		return false;
	}
	if (feature instanceof XVariableDeclaration) {
		if (dereference) {
			final XVariableDeclaration variable = (XVariableDeclaration) feature;
			for (final XExpression value : context.getVariableValues(variable.getIdentifier())) {
				if (!isLocalExpression(value, context, dereference)) {
					return false;
				}
			}
		}
	}
	return true;
}
 
Example #6
Source File: SARLValidator.java    From sarl with Apache License 2.0 6 votes vote down vote up
/** Check if the given local variable has a valid name.
 *
 * @param variable the variable to test.
 * @see SARLFeatureNameValidator
 */
@Check(CheckType.FAST)
public void checkVariableName(XVariableDeclaration variable) {
	final QualifiedName name = QualifiedName.create(variable.getQualifiedName('.').split("\\.")); //$NON-NLS-1$
	if (isReallyDisallowedName(name)) {
		error(MessageFormat.format(
				Messages.SARLValidator_41,
				variable.getName(), Messages.SARLValidator_15),
				variable,
				XbasePackage.Literals.XVARIABLE_DECLARATION__NAME,
				ValidationMessageAcceptor.INSIGNIFICANT_INDEX,
				VARIABLE_NAME_DISALLOWED);
	} else if (this.grammarAccess.getOccurrenceKeyword().equals(variable.getName())) {
		error(MessageFormat.format(
				Messages.SARLValidator_101,
				this.grammarAccess.getOccurrenceKeyword(), Messages.SARLValidator_15),
				variable,
				XbasePackage.Literals.XVARIABLE_DECLARATION__NAME,
				ValidationMessageAcceptor.INSIGNIFICANT_INDEX,
				VARIABLE_NAME_DISALLOWED);
	}
}
 
Example #7
Source File: SarlCompiler.java    From sarl with Apache License 2.0 6 votes vote down vote up
/** Replies all the variables that are referenced into the given expression.
 *
 * @param expression the expression.
 * @param onlyWritable if {@code true} only the writable variables are replied. Otherwise, all variables are replied.
 * @return the referenced variables.
 */
@SuppressWarnings("static-method")
protected Map<XVariableDeclaration, XFeatureCall> getReferencedLocalVariable(XExpression expression, boolean onlyWritable) {
	final Map<XVariableDeclaration, XFeatureCall> localVariables = new TreeMap<>((k1, k2) -> {
		return k1.getIdentifier().compareTo(k2.getIdentifier());
	});
	for (final XFeatureCall featureCall : EcoreUtil2.getAllContentsOfType(expression, XFeatureCall.class)) {
		if (featureCall.getFeature() instanceof XVariableDeclaration) {
			final XVariableDeclaration localVariable = (XVariableDeclaration) featureCall.getFeature();
			if ((!onlyWritable || localVariable.isWriteable()) && !localVariables.containsKey(localVariable)) {
				localVariables.put(localVariable, featureCall);
			}
		}
	}
	return localVariables;
}
 
Example #8
Source File: XbaseCompiler.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
protected LightweightTypeReference appendVariableTypeAndName(XVariableDeclaration varDeclaration, ITreeAppendable appendable) {
	if (!varDeclaration.isWriteable()) {
		appendable.append("final ");
	}
	LightweightTypeReference type = null;
	if (varDeclaration.getType() != null) {
		serialize(varDeclaration.getType(), varDeclaration, appendable);
		type = getLightweightType((JvmIdentifiableElement) varDeclaration);
	} else {
		type = getLightweightType(varDeclaration.getRight());
		if (type.isAny()) {
			type = getTypeForVariableDeclaration(varDeclaration.getRight());
		}
		appendable.append(type);
	}
	appendable.append(" ");
	appendable.append(appendable.declareVariable(varDeclaration, makeJavaIdentifier(varDeclaration.getName())));
	return type;
}
 
Example #9
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 #10
Source File: UIStringsTest.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
/** The qualified name of the type is specified.
 * The JvmTypeReference is not a proxy.
 */
@Test
public void testReferenceToString_2() throws Exception {
	XtendFile file = file(
			  "package org.eclipse.xtend.core.tests.validation.uistrings\n"
			+ "public interface InterfaceA { }\n"
			+ "public class ClassB implements InterfaceA { }\n"
			+ "public class ClassC extends ClassB {\n"
			+ "}\n"
			+ "class XtendClass1 {\n"
			+ "  def test() {\n"
			+ "    val x = new List<org.eclipse.xtend.core.tests.validation.uistrings.ClassC>\n"
			+ "  }\n"
			+ "}\n");
	XtendClass clazz = (XtendClass) file.getXtendTypes().get(3);
	XBlockExpression block = (XBlockExpression) ((XtendFunction) clazz.getMembers().get(0)).getExpression();
	XVariableDeclaration declaration = (XVariableDeclaration) block.getExpressions().get(0);
	XConstructorCall cons = (XConstructorCall) declaration.getRight();
	JvmTypeReference reference = cons.getTypeArguments().get(0);
	assertNotNull(reference);
	assertNotNull(reference.getType());
	assertFalse(reference.getType().eIsProxy());
	assertNotNull(reference.eResource());
	assertEquals("ClassC", this.uiStrings.referenceToString(reference, "the-default-label"));
}
 
Example #11
Source File: ExtractMethodRefactoring.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
protected List<XExpression> calculateExpressions(final List<XExpression> expressions) {
	final XExpression firstExpression = expressions.get(0);
	// If there is a XVariableDeclaration selected and there is a usage of that variable outside of the selected expressions, we need to take the right side
	// instead of the complete XVariableDeclaration
	if(expressions.size() == 1 && firstExpression instanceof XVariableDeclaration){
		final XtendFunction originalMethod = EcoreUtil2.getContainerOfType(firstExpression, XtendFunction.class);
		for (final EObject element : Iterables.filter(EcoreUtil2.eAllContents(originalMethod.getExpression()), new Predicate<EObject>() {
			@Override
			public boolean apply(EObject input) {
				return !EcoreUtil.isAncestor(expressions, input);
			}
		}
		)){
			if (element instanceof XFeatureCall) {
				XFeatureCall featureCall = (XFeatureCall) element;
				JvmIdentifiableElement feature = featureCall.getFeature();
				if(EcoreUtil.isAncestor(expressions, feature)){
					return singletonList(((XVariableDeclaration) firstExpression).getRight());
				}
			}
		}
	}
	return expressions;
}
 
Example #12
Source File: PyExpressionGenerator.java    From sarl with Apache License 2.0 6 votes vote down vote up
/** Generate the given object.
 *
 * @param varDeclaration the variable declaration.
 * @param it the target for the generated content.
 * @param context the context.
 * @return the statement.
 */
protected XExpression _generate(XVariableDeclaration varDeclaration, IAppendable it, IExtraLanguageGeneratorContext context) {
	final String name = it.declareUniqueNameVariable(varDeclaration, varDeclaration.getName());
	it.append(name);
	it.append(" = "); //$NON-NLS-1$
	if (varDeclaration.getRight() != null) {
		generate(varDeclaration.getRight(), it, context);
	} else if (varDeclaration.getType() != null) {
		it.append(toDefaultValue(varDeclaration.getType()));
	} else {
		it.append("None"); //$NON-NLS-1$
	}
	if (context.getExpectedExpressionType() != null) {
		it.newLine();
		it.append("return ").append(name); //$NON-NLS-1$
	}
	return varDeclaration;
}
 
Example #13
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 #14
Source File: AbstractXbaseLinkingTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testShadowing_2() throws Exception {
	XBlockExpression bop = (XBlockExpression) expression(
			"{ " +
			"	val size = 23;" +
			"	val this = new java.util.ArrayList<String>(); " +
			"	size;" +
			"}");
	JvmIdentifiableElement feature = ((XFeatureCall)bop.getExpressions().get(2)).getFeature();
	assertTrue(feature.toString(), feature instanceof XVariableDeclaration);
}
 
Example #15
Source File: XbaseInterpreter.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @param assignment unused in this context but required for dispatching
 * @param indicator unused in this context but required for dispatching
 */
protected Object _assignValueTo(XVariableDeclaration variable, XAbstractFeatureCall assignment, Object value,
		IEvaluationContext context, CancelIndicator indicator) {
	if (variable.getType() != null) {
		JvmTypeReference type = variable.getType();
		Object coerced = coerceArgumentType(value, type);
		context.assignValue(QualifiedName.create(variable.getName()), coerced);
	} else {
		context.assignValue(QualifiedName.create(variable.getName()), value);
	}
	return value;
}
 
Example #16
Source File: AbstractXbaseLinkingTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testRecursiveClosure() throws Exception {
	XBlockExpression block = (XBlockExpression) expression("{ val (int)=>int fun = [ fun.apply(it) ] }");
	XVariableDeclaration variable = (XVariableDeclaration) block.getExpressions().get(0);
	XClosure closure = (XClosure) variable.getRight();
	XBlockExpression body = (XBlockExpression) closure.getExpression();
	XMemberFeatureCall member = (XMemberFeatureCall) body.getExpressions().get(0);
	XFeatureCall recursive = (XFeatureCall) member.getMemberCallTarget();
	assertSame(variable, recursive.getFeature());
}
 
Example #17
Source File: XtendHoverSignatureProviderTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testSignatureForAnonymousClassLocalVarTypeTest_03() {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("package testPackage");
    _builder.newLine();
    _builder.newLine();
    _builder.append("class C {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("def m() {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("val r = newArrayList(new Runnable { override run() {} })");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("r");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    final XtendFile xtendFile = this.parseHelper.parse(_builder, this.getResourceSet());
    final XtendClass clazz = IterableExtensions.<XtendClass>head(Iterables.<XtendClass>filter(xtendFile.getXtendTypes(), XtendClass.class));
    XtendMember _get = clazz.getMembers().get(0);
    final XtendFunction function = ((XtendFunction) _get);
    XExpression _expression = function.getExpression();
    final XBlockExpression body = ((XBlockExpression) _expression);
    XExpression _head = IterableExtensions.<XExpression>head(body.getExpressions());
    final XVariableDeclaration variable = ((XVariableDeclaration) _head);
    final String signature = this.signatureProvider.getSignature(variable);
    Assert.assertEquals("ArrayList<new Runnable(){}> r", signature);
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example #18
Source File: AbstractXbaseLinkingTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Ignore("TODO eager binding of type arguments to expectation")
@Test public void testStaticFeatureCall_17() throws Exception {
	XBlockExpression block = (XBlockExpression) expression("{ val Iterable<CharSequence> iterable = testdata.MethodOverrides4::staticM5(null) }");
	XVariableDeclaration variable = (XVariableDeclaration) block.getExpressions().get(0);
	XMemberFeatureCall featureCall = (XMemberFeatureCall) variable.getRight();
	assertEquals("testdata.MethodOverrides3.staticM5(T)", featureCall.getFeature().getIdentifier());
}
 
Example #19
Source File: SARLOperationHelper.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Test if the given expression has side effects.
 *
 * @param expression the expression.
 * @param context the list of context expressions.
 * @return {@code true} if the expression has side effects.
 */
protected Boolean _hasSideEffects(XVariableDeclaration expression, ISideEffectContext context) {
	if (hasSideEffects(expression.getRight(), context)) {
		return true;
	}
	context.declareVariable(expression.getIdentifier(), expression.getRight());
	return false;
}
 
Example #20
Source File: AbstractXbaseLinkingTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testParameterizedInnerTypes_02() throws Exception {
	XBlockExpression block = (XBlockExpression) expression("{ val nested.ParameterizedInnerTypes.Sub<String>.Inner x = null }", true);
	XVariableDeclaration variableDecl = (XVariableDeclaration) block.getExpressions().get(0);
	JvmType type = variableDecl.getType().getType();
	assertEquals("nested.ParameterizedInnerTypes$Inner", type.getIdentifier());
	assertEquals("nested.ParameterizedInnerTypes$Sub<java.lang.String>$Inner", variableDecl.getType().getIdentifier());
}
 
Example #21
Source File: AbstractXbaseLinkingTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testParameterizedInnerTypes_01() throws Exception {
	XBlockExpression block = (XBlockExpression) expression("{ val nested.ParameterizedInnerTypes<String>.Inner x = null }", true);
	XVariableDeclaration variableDecl = (XVariableDeclaration) block.getExpressions().get(0);
	JvmType type = variableDecl.getType().getType();
	assertEquals("nested.ParameterizedInnerTypes$Inner", type.getIdentifier());
	assertEquals("nested.ParameterizedInnerTypes<java.lang.String>$Inner", variableDecl.getType().getIdentifier());
}
 
Example #22
Source File: SarlCompiler.java    From sarl with Apache License 2.0 5 votes vote down vote up
private static void updateReferenceList(List<XAbstractFeatureCall> references, Set<String> identifiers,
		XAbstractFeatureCall featureCall) {
	final JvmIdentifiableElement feature = featureCall.getFeature();
	if (feature instanceof JvmFormalParameter || feature instanceof XVariableDeclaration || feature instanceof JvmField) {
		if (identifiers.add(feature.getIdentifier())) {
			references.add(featureCall);
		}
	} else if (!references.contains(featureCall)) {
		references.add(featureCall);
	}
}
 
Example #23
Source File: XbaseHighlightingCalculator.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected void highlightVariableDeclaration(XVariableDeclaration varDecl, IHighlightedPositionAcceptor acceptor) {
	if (!SPECIAL_FEATURE_NAMES.contains(varDecl.getName())) {
		// highlighting of special identifiers is done separately, so it's omitted here 
		highlightFeature(acceptor, varDecl, XbasePackage.Literals.XVARIABLE_DECLARATION__NAME, LOCAL_VARIABLE_DECLARATION);
		if (!varDecl.isWriteable()) {
			highlightFeature(acceptor, varDecl, XbasePackage.Literals.XVARIABLE_DECLARATION__NAME, LOCAL_FINAL_VARIABLE_DECLARATION);
		}
	}
}
 
Example #24
Source File: UIStringsTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
/** Only the simple name of the type is specified.
 * The JvmTypeReference is proxy.
 */
@Test
public void testReferenceToString_1() throws Exception {
	XtendFile file1 = file(
			  "package org.eclipse.xtend.core.tests.validation.uistrings\n"
			+ "public interface InterfaceA { }\n"
			+ "public class ClassB implements InterfaceA { }\n"
			+ "public class ClassC extends ClassB {\n"
			+ "}\n");
	assertNotNull(file1);
	XtendFile file2 = file(
			  "package org.eclipse.xtend.core.tests.validation.uistrings\n"
			+ "class XtendClass1 {\n"
			+ "  def test() {\n"
			+ "    val x = new List<ClassC>\n"
			+ "  }\n"
			+ "}\n");
	XtendClass clazz = (XtendClass) file2.getXtendTypes().get(0);
	XBlockExpression block = (XBlockExpression) ((XtendFunction) clazz.getMembers().get(0)).getExpression();
	XVariableDeclaration declaration = (XVariableDeclaration) block.getExpressions().get(0);
	XConstructorCall cons = (XConstructorCall) declaration.getRight();
	JvmTypeReference reference = cons.getTypeArguments().get(0);
	assertNotNull(reference);
	assertNotNull(reference.getType());
	assertTrue(reference.getType().eIsProxy());
	assertNotNull(reference.eResource());
	assertEquals("ClassC", this.uiStrings.referenceToString(reference, "the-default-label"));
}
 
Example #25
Source File: BeforeLinkingTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testImplicitLambdaParameter() throws Exception {
	XBlockExpression block = (XBlockExpression) parseHelper.parse("{ val Comparable<String> c = [ length ] c.toString } ");
	BatchLinkableResource resource = (BatchLinkableResource) block.eResource();
	resource.resolveLazyCrossReferences(null);
	XVariableDeclaration assignment = (XVariableDeclaration) Iterables.getFirst(block.getExpressions(), null);
	XClosure lambda = (XClosure) assignment.getRight();
	JvmFormalParameter implicitParameter = Iterables.getFirst(lambda.getImplicitFormalParameters(), null);
	Assert.assertEquals("String", implicitParameter.getParameterType().getSimpleName());
	resource.update(0, 0, "");
	Assert.assertNull(implicitParameter.eResource());
}
 
Example #26
Source File: XbaseTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testFeatureCall_26() throws Exception {
	XBlockExpression block = (XBlockExpression) expression(
			"{ val Object o = newArrayList(if (false) new Double('-20') else new Integer('20')).map(v|v.intValue).head }", true);
	XVariableDeclaration variableDeclaration = (XVariableDeclaration) block.getExpressions().get(0);
	XExpression memberCallTarget = ((XMemberFeatureCall) variableDeclaration.getRight()).getMemberCallTarget();
	LightweightTypeReference typeRef = getType(memberCallTarget);
	assertNotNull("type ref was null for " + memberCallTarget, typeRef);
	assertEquals("java.util.List<java.lang.Integer>", toString(typeRef));
}
 
Example #27
Source File: UIStringsTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testReferenceToString_3() throws Exception {
	XExpression expr = expression("{ var foo.String x }", false);
	assertNotNull(expr);
	XVariableDeclaration declaration = (XVariableDeclaration) (((XBlockExpression) expr).getExpressions().get(0));
	JvmTypeReference reference = declaration.getType();
	assertEquals("String", this.uiStrings.referenceToString(reference, "the-default-value"));
}
 
Example #28
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 #29
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 #30
Source File: XbaseQuickfixProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Fix(IssueCodes.UNUSED_LOCAL_VARIABLE)
public void removeUnusedLocalVariable(final Issue issue, IssueResolutionAcceptor acceptor) {
	// use the same label, description and image
	// to be able to use the quickfixes (issue resolution) in batch mode
	String label = "Remove local variable.";
	String description = "Remove the unused local variable.";
	String image = "delete_edit.png";
	acceptor.acceptMulti(issue, label, description, image, (ICompositeModification<XVariableDeclaration>) (element, ctx) -> {
		ctx.setUpdateCrossReferences(false);
		ctx.setUpdateRelatedFiles(false);
		ctx.addModification(element, ele -> EcoreUtil.remove(ele));
	});
}