org.eclipse.xtext.xbase.XExpression Java Examples

The following examples show how to use org.eclipse.xtext.xbase.XExpression. 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: SARLOperationHelper.java    From sarl with Apache License 2.0 6 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(XTryCatchFinallyExpression expression, ISideEffectContext context) {
	final List<Map<String, List<XExpression>>> buffers = new ArrayList<>();
	Map<String, List<XExpression>> buffer = context.createVariableAssignmentBufferForBranch();
	if (hasSideEffects(expression.getExpression(), context.branch(buffer))) {
		return true;
	}
	buffers.add(buffer);
	for (final XCatchClause clause : expression.getCatchClauses()) {
		context.open();
		try {
			buffer = context.createVariableAssignmentBufferForBranch();
			if (hasSideEffects(clause.getExpression(), context.branch(buffer))) {
				return true;
			}
			buffers.add(buffer);
		} finally {
			context.close();
		}
	}
	context.mergeBranchVariableAssignments(buffers);
	if (hasSideEffects(expression.getFinallyExpression(), context)) {
		return true;
	}
	return false;
}
 
Example #2
Source File: SarlBehaviorUnitImpl.java    From sarl with Apache License 2.0 6 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public void eUnset(int featureID)
{
	switch (featureID)
	{
		case SarlPackage.SARL_BEHAVIOR_UNIT__NAME:
			setName((JvmParameterizedTypeReference)null);
			return;
		case SarlPackage.SARL_BEHAVIOR_UNIT__GUARD:
			setGuard((XExpression)null);
			return;
		case SarlPackage.SARL_BEHAVIOR_UNIT__EXPRESSION:
			setExpression((XExpression)null);
			return;
	}
	super.eUnset(featureID);
}
 
Example #3
Source File: TypeComputationStateTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testTypeOnlyRegisteredOnce_04() throws Exception {
	XNumberLiteral expression = ((XNumberLiteral) expression("1"));
	resolver.initializeFrom(expression);
	PublicResolvedTypes resolution = new PublicResolvedTypes(resolver);
	AnyTypeReference any = resolution.getReferenceOwner().newAnyTypeReference();
	new ExpressionBasedRootTypeComputationState(resolution, resolver.getBatchScopeProvider().newSession(expression.eResource()),
			expression, any).computeTypes();
	Map<XExpression, List<TypeData>> expressionTypes = resolution.basicGetExpressionTypes();
	TreeIterator<EObject> allContents = expression.eAllContents();
	while (allContents.hasNext()) {
		EObject o = allContents.next();
		List<TypeData> types = expressionTypes.get((o));
		assertEquals(types.toString(), 1, size(filter(types, it -> !it.isReturnType())));
	}
}
 
Example #4
Source File: XtendFieldImpl.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public void setInitialValue(XExpression newInitialValue)
{
	if (newInitialValue != initialValue)
	{
		NotificationChain msgs = null;
		if (initialValue != null)
			msgs = ((InternalEObject)initialValue).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - XtendPackage.XTEND_FIELD__INITIAL_VALUE, null, msgs);
		if (newInitialValue != null)
			msgs = ((InternalEObject)newInitialValue).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - XtendPackage.XTEND_FIELD__INITIAL_VALUE, null, msgs);
		msgs = basicSetInitialValue(newInitialValue, msgs);
		if (msgs != null) msgs.dispatch();
	}
	else if (eNotificationRequired())
		eNotify(new ENotificationImpl(this, Notification.SET, XtendPackage.XTEND_FIELD__INITIAL_VALUE, newInitialValue, newInitialValue));
}
 
Example #5
Source File: XPostfixOperationImpl.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public void setOperand(XExpression newOperand)
{
	if (newOperand != operand)
	{
		NotificationChain msgs = null;
		if (operand != null)
			msgs = ((InternalEObject)operand).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - XbasePackage.XPOSTFIX_OPERATION__OPERAND, null, msgs);
		if (newOperand != null)
			msgs = ((InternalEObject)newOperand).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - XbasePackage.XPOSTFIX_OPERATION__OPERAND, null, msgs);
		msgs = basicSetOperand(newOperand, msgs);
		if (msgs != null) msgs.dispatch();
	}
	else if (eNotificationRequired())
		eNotify(new ENotificationImpl(this, Notification.SET, XbasePackage.XPOSTFIX_OPERATION__OPERAND, newOperand, newOperand));
}
 
Example #6
Source File: XCasePartImpl.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public void setThen(XExpression newThen)
{
	if (newThen != then)
	{
		NotificationChain msgs = null;
		if (then != null)
			msgs = ((InternalEObject)then).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - XbasePackage.XCASE_PART__THEN, null, msgs);
		if (newThen != null)
			msgs = ((InternalEObject)newThen).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - XbasePackage.XCASE_PART__THEN, null, msgs);
		msgs = basicSetThen(newThen, msgs);
		if (msgs != null) msgs.dispatch();
	}
	else if (eNotificationRequired())
		eNotify(new ENotificationImpl(this, Notification.SET, XbasePackage.XCASE_PART__THEN, newThen, newThen));
}
 
Example #7
Source File: XbaseValidationTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testSwitchDeclaredParameter() {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("{");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("switch Object x : \"lalala\" {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    final XExpression block = this.expression(_builder);
    this._validationTestHelper.assertNoErrors(block);
    this._validationTestHelper.assertWarning(block, TypesPackage.Literals.JVM_FORMAL_PARAMETER, IssueCodes.UNUSED_LOCAL_VARIABLE);
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example #8
Source File: XForLoopExpressionImpl.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public void setEachExpression(XExpression newEachExpression)
{
	if (newEachExpression != eachExpression)
	{
		NotificationChain msgs = null;
		if (eachExpression != null)
			msgs = ((InternalEObject)eachExpression).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - XbasePackage.XFOR_LOOP_EXPRESSION__EACH_EXPRESSION, null, msgs);
		if (newEachExpression != null)
			msgs = ((InternalEObject)newEachExpression).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - XbasePackage.XFOR_LOOP_EXPRESSION__EACH_EXPRESSION, null, msgs);
		msgs = basicSetEachExpression(newEachExpression, msgs);
		if (msgs != null) msgs.dispatch();
	}
	else if (eNotificationRequired())
		eNotify(new ENotificationImpl(this, Notification.SET, XbasePackage.XFOR_LOOP_EXPRESSION__EACH_EXPRESSION, newEachExpression, newEachExpression));
}
 
Example #9
Source File: SARLFormatter.java    From sarl with Apache License 2.0 6 votes vote down vote up
@Override
protected void _format(XForLoopExpression expr, IFormattableDocument document) {
	final ISemanticRegionsFinder regionFor = this.textRegionExtensions.regionFor(expr);
	document.append(regionFor.keyword(this.keywords.getForKeyword()), ONE_SPACE);

	final JvmFormalParameter declaredParam = expr.getDeclaredParam();
	document.prepend(declaredParam, NO_SPACE);
	document.append(declaredParam, ONE_SPACE);
	document.format(declaredParam);

	final XExpression forExpression = expr.getForExpression();
	document.prepend(forExpression, ONE_SPACE);
	document.append(forExpression, NO_SPACE);
	document.format(forExpression);

	final XExpression eachExpression = expr.getEachExpression();
	if (eachExpression != null) {
		formatBody(eachExpression, true, document);
	} else {
		document.prepend(regionFor.keyword(this.keywords.getSemicolonKeyword()), NO_SPACE);
	}
}
 
Example #10
Source File: InterpreterTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testInfiniteLoopInJava() throws Exception {
	XExpression expression = expression(
			"try " +
			"  new testdata.ClosureClient().infiniteApply(|{null})" +
			"catch(Exception e)" +
			"  'literal' ", true);
	assertNull(interpreter.evaluate(expression, new DefaultEvaluationContext(), new CancelIndicator() {
		private int i = 0;
		@Override
		public boolean isCanceled() {
			if (i == 500)
				return true;
			i++;
			return false;
		}
	}));
}
 
Example #11
Source File: SARLExpressionHelper.java    From sarl with Apache License 2.0 6 votes vote down vote up
/** Convert the boolean constant to the object equivalent if possible.
 *
 * @param expression the expression to convert.
 * @return one of the boolean constants {@link Boolean#TRUE} or {@link Boolean#FALSE},
 *     or {@code null} if the expression is not a constant boolean expression.
 */
@SuppressWarnings("static-method")
public Boolean toBooleanPrimitiveWrapperConstant(XExpression expression) {
	if (expression instanceof XBooleanLiteral) {
		return ((XBooleanLiteral) expression).isIsTrue() ? Boolean.TRUE : Boolean.FALSE;
	}
	if (expression instanceof XMemberFeatureCall) {
		final XMemberFeatureCall call = (XMemberFeatureCall) expression;
		final XExpression receiver = call.getMemberCallTarget();
		if (receiver instanceof XFeatureCall) {
			final XFeatureCall call2 = (XFeatureCall) receiver;
			final String call2Identifier = call2.getConcreteSyntaxFeatureName();
			if (Boolean.class.getSimpleName().equals(call2Identifier) || Boolean.class.getName().equals(call2Identifier)) {
				final String callIdentifier = call.getConcreteSyntaxFeatureName();
				if ("TRUE".equals(callIdentifier)) { //$NON-NLS-1$
					return Boolean.TRUE;
				} else if ("FALSE".equals(callIdentifier)) { //$NON-NLS-1$
					return Boolean.FALSE;
				}
			}
		}
	}
	return null;
}
 
Example #12
Source File: SARLEarlyExitValidator.java    From sarl with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc}.
 *
 * <p>This function is overriden for:<ul>
 * <li>The XAbstractFeatureCall statements are not considered as potential early exit causes.
 *     in the super function. We need to mark the dead code for the XAbstractFeatureCall statements
 *     which refer to a function with the {@link EarlyExit} annotation.</li>
 * <li>Mark as dead the code after a "break" statement.</li>
 * </ul>
 */
@Override
@Check
public void checkDeadCode(XBlockExpression block) {
	final EList<XExpression> expressions = block.getExpressions();
	final int size = expressions.size();
	for (int i = 0; i < size - 1; ++i) {
		final XExpression expression = expressions.get(i);
		if (this.earlyExitComputer.isEarlyExit(expression)) {
			if (expression instanceof XAbstractFeatureCall) {
				if (this.earlyExitComputer.isEarlyExitAnnotatedElement(
						((XAbstractFeatureCall) expression).getFeature())) {
					markAsDeadCode(expressions.get(i + 1));
				}
			} else {
				// XAbstractFeatureCall does already a decent job for its argument lists
				// no additional error necessary
				markAsDeadCode(expressions.get(i + 1));
			}
			return;
		} else if (this.earlyExitComputer.isEarlyExitLoop(expression)) {
			markAsDeadCode(expressions.get(i + 1));
		}
	}
}
 
Example #13
Source File: XtendUnsugaredHoverTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testBug373054() throws Exception {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("package testpackage");
  _builder.newLine();
  _builder.append("import static extension testpackage.Extension.*");
  _builder.newLine();
  _builder.append("class Foo {");
  _builder.newLine();
  _builder.append("\t");
  _builder.append("def bar(){}");
  _builder.newLine();
  _builder.append("\t");
  _builder.append("def baz(String it, String s){");
  _builder.newLine();
  _builder.append("\t\t");
  _builder.append("zonk = s + s + s");
  _builder.newLine();
  _builder.append("\t");
  _builder.append("}");
  _builder.newLine();
  _builder.append("\t");
  _builder.newLine();
  _builder.append("}");
  _builder.newLine();
  final XtendFile xtendFile = this.testHelper.xtendFile(XtendUnsugaredHoverTest.FILEPATH, _builder.toString());
  IResourcesSetupUtil.waitForBuild();
  XtendMember _get = IterableExtensions.<XtendClass>head(Iterables.<XtendClass>filter(xtendFile.getXtendTypes(), XtendClass.class)).getMembers().get(1);
  final XtendFunction function = ((XtendFunction) _get);
  XExpression _expression = function.getExpression();
  final XBlockExpression block = ((XBlockExpression) _expression);
  final XExpression call = block.getExpressions().get(0);
  Assert.assertEquals("Extension.setZonk(it, s + s + s)", this.serializer.computeUnsugaredExpression(call));
}
 
Example #14
Source File: XbaseCompiler.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected boolean isSimpleFeatureCall(XExpression switch1) {
	if (switch1 instanceof XFeatureCall)  {
		XFeatureCall featureCall = (XFeatureCall) switch1;
		return !(featureCall.getFeature() instanceof JvmOperation);
	}
	return false;
}
 
Example #15
Source File: DynamicExtensionsScope.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected BucketedEObjectDescription createReceiverDescription(QualifiedName name, JvmFeature feature, XExpression receiver,
		LightweightTypeReference receiverType, Map<JvmTypeParameter, LightweightMergedBoundTypeArgument> receiverTypeParameterMapping, ExpressionBucket bucket, boolean validStaticState) {
	return new InstanceFeatureDescriptionWithImplicitReceiver(
			name,
			feature,
			receiver,
			receiverType, 
			receiverTypeParameterMapping,
			ConformanceFlags.CHECKED_SUCCESS,
			bucket.getId(),
			getSession().isVisible(feature),
			validStaticState);
}
 
Example #16
Source File: XtendHighlightingCalculator.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
protected void highlightElement(XtendFunction function, IHighlightedPositionAcceptor acceptor, CancelIndicator cancelIndicator) {
	highlightFeature(acceptor, function, XtendPackage.Literals.XTEND_FUNCTION__NAME, METHOD);
	XExpression rootExpression = function.getExpression();
	highlightRichStrings(rootExpression, acceptor);
	CreateExtensionInfo createExtensionInfo = function.getCreateExtensionInfo();
	if (createExtensionInfo != null) {
		highlightRichStrings(createExtensionInfo.getCreateExpression(), acceptor);
	}
}
 
Example #17
Source File: MatcherImpl.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public NotificationChain basicSetCondition(XExpression newCondition, NotificationChain msgs)
{
  XExpression oldCondition = condition;
  condition = newCondition;
  if (eNotificationRequired())
  {
    ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, FormatPackage.MATCHER__CONDITION, oldCondition, newCondition);
    if (msgs == null) msgs = notification; else msgs.add(notification);
  }
  return msgs;
}
 
Example #18
Source File: ValidatingStackedResolvedTypes.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public LightweightTypeReference getExpectedType(XExpression expression) {
	LightweightTypeReference result = super.getExpectedType(expression);
	if (!result.isOwnedBy(getReferenceOwner())) {
		throw new IllegalArgumentException("result is not owned by this resolved types");
	}
	return result;
}
 
Example #19
Source File: FeatureLinkingCandidate.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected CandidateCompareResult getExpectedTypeCompareResultOther(AbstractPendingLinkingCandidate<?> right) {
	if (!(right instanceof FeatureLinkingCandidate) || getState().isIgnored(IssueCodes.SUSPICIOUSLY_OVERLOADED_FEATURE))
		return CandidateCompareResult.OTHER;
	
	FeatureLinkingCandidate casted = (FeatureLinkingCandidate) right;
	XExpression otherImplicitReceiver = casted.getImplicitReceiver();
	if (otherImplicitReceiver != null) {
		if (isStatic() == casted.isStatic()) {
			if (otherImplicitReceiver instanceof XAbstractFeatureCall && getImplicitReceiver() instanceof XAbstractFeatureCall) {
				JvmIdentifiableElement otherImplicitReceiverFeature = ((XAbstractFeatureCall) otherImplicitReceiver).getFeature();
				if (otherImplicitReceiverFeature != ((XAbstractFeatureCall) getImplicitReceiver()).getFeature())
					return CandidateCompareResult.SUSPICIOUS_OTHER;
			}
		}
	} else {
		if (isStatic() && casted.isStatic()) {
			JvmIdentifiableElement otherFeature = casted.getFeature();
			if (getFeature().eContainer() != otherFeature.eContainer() && otherFeature.eResource() == getExpression().eResource()) {
				if (EcoreUtil.isAncestor(otherFeature.eContainer(), getFeature())) {
					return CandidateCompareResult.SUSPICIOUS_OTHER;
				}
			}
		}
	}
	return CandidateCompareResult.OTHER;
}
 
Example #20
Source File: AssignmentLinkingTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
protected XAssignment getAssignment(XtendClass clazz, int assignmentInFunction) {
	XtendFunction function = (XtendFunction) clazz.getMembers().get(0);
	XBlockExpression body = (XBlockExpression) function.getExpression();
	List<XExpression> expressions = body.getExpressions();
	int idx = assignmentInFunction;
	if (idx == -1)
		idx = expressions.size() - 1;
	XAssignment result = (XAssignment) expressions.get(idx);
	return result;
}
 
Example #21
Source File: ReadWriteAccessTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void test002() throws Exception {
	XExpression expr = expression("{ var int f;  f = 2 }");
	helper.assertWarning(expr,
			XbasePackage.eINSTANCE.getXVariableDeclaration(),
			org.eclipse.xtext.xbase.validation.IssueCodes.UNUSED_LOCAL_VARIABLE,
			"variable f");
}
 
Example #22
Source File: Context.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
public Context(JvmTypeReference expectedType, ClassFinder classFinder,
		Map<String, JvmIdentifiableElement> visibleFeatures, Set<XExpression> alreadyEvaluating) {
	this.expectedType = expectedType;
	this.classFinder = classFinder;
	this.visibleFeatures = visibleFeatures;
	this.alreadyEvaluating = alreadyEvaluating;
}
 
Example #23
Source File: ConstantExpressionsInterpreter.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
public String getFullName(final XExpression call) {
  if (call instanceof XFeatureCall) {
    return _getFullName((XFeatureCall)call);
  } else if (call instanceof XMemberFeatureCall) {
    return _getFullName((XMemberFeatureCall)call);
  } else if (call != null) {
    return _getFullName(call);
  } else {
    throw new IllegalArgumentException("Unhandled parameter types: " +
      Arrays.<Object>asList(call).toString());
  }
}
 
Example #24
Source File: DefaultEarlyExitComputer.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected Collection<IEarlyExitComputer.ExitPoint> _exitPoints(final XBlockExpression expression) {
  EList<XExpression> _expressions = expression.getExpressions();
  for (final XExpression child : _expressions) {
    {
      Collection<IEarlyExitComputer.ExitPoint> exitPoints = this.getExitPoints(child);
      boolean _isNotEmpty = this.isNotEmpty(exitPoints);
      if (_isNotEmpty) {
        return exitPoints;
      }
    }
  }
  return Collections.<IEarlyExitComputer.ExitPoint>emptyList();
}
 
Example #25
Source File: DynamicExtensionsScope.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected void getAllLocalElements(ExpressionBucket bucket, List<IEObjectDescription> result) {
	Map<XExpression, LightweightTypeReference> extensionProviders = bucket.getExtensionProviders();
	for (Map.Entry<XExpression, LightweightTypeReference> extensionProvider : extensionProviders.entrySet()) {
		LightweightTypeReference extensionType = extensionProvider.getValue();
		Set<JvmFeature> allFeatures = getAllFeatures(extensionType, bucket.getResolvedFeaturesProvider());
		if (!allFeatures.isEmpty()) {
			Map<JvmTypeParameter, LightweightMergedBoundTypeArgument> receiverTypeParameterMapping = new DeclaratorTypeArgumentCollector().getTypeParameterMapping(extensionType);
			for (JvmFeature feature : allFeatures) {
				if (!feature.isStatic()) {
					addDescriptions(feature, extensionProvider.getKey(), extensionType, receiverTypeParameterMapping, bucket, result);
				}
			}
		}
	}
}
 
Example #26
Source File: SarlScriptExecutor.java    From sarl with Apache License 2.0 5 votes vote down vote up
@Override
public Object execute(int lineno, String code) throws Exception {
	final List<String> issues = new ArrayList<>();
	final Collection<Resource> resources = new ArrayList<>();

	final CompiledFile outFile = compile(lineno,
			"package x.x.x;\n" //$NON-NLS-1$
			+ "class ____Fake_Class____ {\nstatic var __fake_attr__ : Object = {\n" //$NON-NLS-1$
			+ code + ";\n};\n}", //$NON-NLS-1$
			issues, (it) -> {
				resources.add(it);
			});
	try {
		assertNoIssue(lineno, issues);
		if (resources.isEmpty()) {
			throw new NoXtextResourceException(lineno);
		}
		for (Resource resource : resources) {
			SarlScript script = (SarlScript) resource.getContents().get(0);
			SarlClass clazz = (SarlClass) script.getXtendTypes().get(0);
			SarlField field = (SarlField) clazz.getMembers().get(0);
			XExpression xexpression = field.getInitialValue();
			final IExpressionInterpreter interpreter = this.interpreterProvider.get();
			if (interpreter instanceof SarlExpressionInterpreter && this.classLoaderBuilder != null) {
				final SarlExpressionInterpreter exprEvaluator = (SarlExpressionInterpreter) interpreter;
				exprEvaluator.expandClassLoader(this.classLoaderBuilder);
			}
			IEvaluationResult result = interpreter.evaluate(xexpression);
			if (result.getException() == null) {
				return result.getResult();
			}
			throw new RuntimeException(result.getException());
		}
	} finally {
		if (outFile != null && outFile.getRootFolder() != null) {
			FileSystem.delete(outFile.getRootFolder());
		}
	}
	return null;
}
 
Example #27
Source File: XbaseShufflingInjectorProvider.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected IFeatureCallArguments createArgumentsForExecutable(boolean varArgs, List<XExpression> arguments,
		List<JvmFormalParameter> parameters, boolean hasReceiver, ITypeReferenceOwner owner) {
	if (varArgs) {
		List<JvmFormalParameter> reversedParameters = Lists.newArrayList(Lists.reverse(parameters.subList(0, parameters.size() - 1)));
		reversedParameters.add(parameters.get(parameters.size() - 1));
		List<XExpression> reversedArgumetns = Lists.newArrayList(Lists.reverse(arguments.subList(0, parameters.size() - 1)));
		reversedArgumetns.addAll(Lists.reverse(arguments.subList(parameters.size() - 1, arguments.size())));
		return super.createArgumentsForExecutable(varArgs, reversedArgumetns, reversedParameters, hasReceiver, owner);
	}
	return super.createArgumentsForExecutable(varArgs, Lists.reverse(arguments), Lists.reverse(parameters), hasReceiver, owner);
}
 
Example #28
Source File: VarArgFeatureCallArgumentsTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
protected IFeatureCallArguments toArguments(final String signature, final String invocation, final boolean receiver) {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("def void m(");
    _builder.append(signature);
    _builder.append(") {");
    _builder.newLineIfNotEmpty();
    _builder.append("\t");
    _builder.append("m(");
    _builder.append(invocation, "\t");
    _builder.append(")");
    _builder.newLineIfNotEmpty();
    _builder.append("}");
    _builder.newLine();
    final String functionString = _builder.toString();
    final XtendFunction function = this.function(functionString);
    XExpression _expression = function.getExpression();
    final XBlockExpression body = ((XBlockExpression) _expression);
    XExpression _head = IterableExtensions.<XExpression>head(body.getExpressions());
    final XFeatureCall featureCall = ((XFeatureCall) _head);
    final EList<XExpression> arguments = featureCall.getFeatureCallArguments();
    final JvmOperation operation = this._iXtendJvmAssociations.getDirectlyInferredOperation(function);
    final IFeatureCallArguments result = this.factory.createVarArgArguments(arguments, operation.getParameters(), receiver, this.getOwner());
    Class<? extends IFeatureCallArguments> _class = result.getClass();
    boolean _equals = Objects.equal(_class, VarArgFeatureCallArguments.class);
    Assert.assertTrue(_equals);
    return result;
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example #29
Source File: XbaseFormatter2.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected boolean isMultiParamInOwnLine(final XExpression fc, final FormattableDocument doc) {
  if (fc instanceof XFeatureCall) {
    return _isMultiParamInOwnLine((XFeatureCall)fc, doc);
  } else if (fc instanceof XMemberFeatureCall) {
    return _isMultiParamInOwnLine((XMemberFeatureCall)fc, doc);
  } else if (fc instanceof XConstructorCall) {
    return _isMultiParamInOwnLine((XConstructorCall)fc, doc);
  } else {
    throw new IllegalArgumentException("Unhandled parameter types: " +
      Arrays.<Object>asList(fc, doc).toString());
  }
}
 
Example #30
Source File: JavaConverterTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testRichStringCase() throws Exception {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("public class Clazz {");
  _builder.newLine();
  _builder.append("\t");
  _builder.append("static int i = 2;");
  _builder.newLine();
  _builder.append("\t");
  _builder.append("static String a = (i-i)+i+\"4=\"+(--i)+\"1=\"+(i++)+i;");
  _builder.newLine();
  _builder.append("\t");
  _builder.append("static String b =\"4=\"+\"1=\";");
  _builder.newLine();
  _builder.append("}");
  XtendClass clazz = this.toValidXtendClass(_builder);
  Assert.assertNotNull(clazz);
  XtendMember _get = clazz.getMembers().get(1);
  XtendField xtendMember = ((XtendField) _get);
  Assert.assertEquals("a", xtendMember.getName());
  XExpression _initialValue = xtendMember.getInitialValue();
  Assert.assertTrue((_initialValue instanceof RichString));
  XtendMember _get_1 = clazz.getMembers().get(2);
  XExpression _initialValue_1 = ((XtendField) _get_1).getInitialValue();
  Assert.assertTrue((_initialValue_1 instanceof RichString));
  Assert.assertEquals("static package String a=\'\'\'�(i - i)��i�4=�({i=i - 1})�1=�(i++)��i�\'\'\'", 
    this.toXtendClassBodyDeclr("static String a = (i-i)+i+\"4=\"+(--i)+\"1=\"+(i++)+i;"));
}