org.eclipse.xtext.xbase.XNullLiteral Java Examples

The following examples show how to use org.eclipse.xtext.xbase.XNullLiteral. 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: TypeComputationStateTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void computeTypes(XExpression expression, ITypeComputationState state) {
	try {
		assertTrue("state is instanceof ExpressionTypeComputationState", (state instanceof ExpressionTypeComputationState));
		LightweightTypeReference expectedType = getFirst(state.getExpectations(), null).getExpectedType();
		if (expression instanceof XNullLiteral) {
			ExpressionTypeComputationState casted = ((ExpressionTypeComputationState) state);
			ResolvedTypes resolution = reflectExtensions.get(casted, "resolvedTypes");
			ResolvedTypes parentResolution = reflectExtensions
					.get(reflectExtensions.<ExpressionTypeComputationState> get(casted, "parent"), "resolvedTypes");
			assertNull(parentResolution.getActualType(((XExpression) ((XNullLiteral) expression).eContainer())));
			state.acceptActualType(expectedType);
			assertNull(parentResolution.getActualType(expression));
			assertEquals(expectedType.getIdentifier(), resolution.getActualType(expression).getIdentifier());
			assertNull(parentResolution.getActualType(((XExpression) ((XNullLiteral) expression).eContainer())));
		} else {
			assertTrue((expression instanceof XBlockExpression));
			XNullLiteral nullLiteral = ((XNullLiteral) getFirst(expression.eContents(), null));
			state.computeTypes(nullLiteral);
			ResolvedTypes res = reflectExtensions.get(state, "resolvedTypes");
			assertEquals(expectedType.getIdentifier(), res.getActualType(nullLiteral).getIdentifier());
		}
	} catch (IllegalAccessException | SecurityException | NoSuchFieldException | IllegalArgumentException e) {
		throw Exceptions.sneakyThrow(e);
	}
}
 
Example #2
Source File: JavaInlineExpressionCompiler.java    From sarl with Apache License 2.0 6 votes vote down vote up
/** Append the inline code for the given XNullLiteral.
 *
 * @param expression the expression of the operation.
 * @param parentExpression is the expression that contains this one, or {@code null} if the current expression is
 *     the root expression.
 * @param feature the feature that contains the expression.
 * @param output the output.
 * @return {@code true} if a text was appended.
 */
protected Boolean _generate(XNullLiteral expression, XExpression parentExpression, XtendExecutable feature,
		InlineAnnotationTreeAppendable output) {
	if (parentExpression == null && feature instanceof XtendFunction) {
		final XtendFunction function = (XtendFunction) feature;
		output.append("("); //$NON-NLS-1$
		final JvmTypeReference reference = getFunctionTypeReference(function);
		if (reference != null) {
			final JvmType type = reference.getType();
			if (type != null) {
				output.append(type);
			} else {
				output.append(Object.class);
			}
		} else {
			output.append(Object.class);
		}
		output.append(")"); //$NON-NLS-1$
		output.append(Objects.toString(null));
		output.setConstant(true);
	} else {
		output.appendConstant(Objects.toString(null));
	}
	return Boolean.TRUE;
}
 
Example #3
Source File: LiteralsCompiler.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected void internalToConvertedExpression(XExpression obj, ITreeAppendable appendable) {
	if (obj instanceof XStringLiteral) {
		_toJavaExpression((XStringLiteral) obj, appendable);
	} else if (obj instanceof XNumberLiteral) {
		_toJavaExpression((XNumberLiteral) obj, appendable);
	} else if (obj instanceof XNullLiteral) {
		_toJavaExpression((XNullLiteral) obj, appendable);
	} else if (obj instanceof XBooleanLiteral) {
		_toJavaExpression((XBooleanLiteral) obj, appendable);
	} else if (obj instanceof XTypeLiteral) {
		_toJavaExpression((XTypeLiteral) obj, appendable);
	} else {
		super.internalToConvertedExpression(obj, appendable);
	}
}
 
Example #4
Source File: LiteralsCompiler.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected void doInternalToJavaStatement(XExpression obj, ITreeAppendable appendable, boolean isReferenced) {
	if (obj instanceof XStringLiteral) {
		_toJavaStatement((XStringLiteral) obj, appendable, isReferenced);
	} else if (obj instanceof XNumberLiteral) {
		_toJavaStatement((XNumberLiteral) obj, appendable, isReferenced);
	} else if (obj instanceof XNullLiteral) {
		_toJavaStatement((XNullLiteral) obj, appendable, isReferenced);
	} else if (obj instanceof XBooleanLiteral) {
		_toJavaStatement((XBooleanLiteral) obj, appendable, isReferenced);
	} else if (obj instanceof XTypeLiteral) {
		_toJavaStatement((XTypeLiteral) obj, appendable, isReferenced);
	} else {
		super.doInternalToJavaStatement(obj, appendable, isReferenced);
	}
}
 
Example #5
Source File: XbaseCompiler.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
protected void appendImmutableCollectionExpression(XCollectionLiteral literal,
		ITreeAppendable b, String collectionsMethod, Class<?> guavaHelper, String guavaHelperMethod) {
	LightweightTypeReference collectionElementType = getCollectionElementType(literal);
	b.append(Collections.class);
	b.append(".<").append(collectionElementType).append(">").append(collectionsMethod).append("(");
	b.append(guavaHelper).append(".<").append(collectionElementType).append(">").append(guavaHelperMethod).append("(");
	boolean isFirst = true;
	for(XExpression element: literal.getElements())  {
		if(!isFirst)
			b.append(", ");
		isFirst = false;
		if(element instanceof XNullLiteral) {
			b.append("(").append(collectionElementType).append(")");
		}
		internalToJavaExpression(element, b);
	}
	b.append("))");
	return;
}
 
Example #6
Source File: VarDeclarationParsingTest.java    From sarl with Apache License 2.0 5 votes vote down vote up
@Test
@Tag("sarlParsing")
public void valueDeclaration_SarlFieldScope() throws Exception {
	SarlScript mas = file(getParseHelper(), getValidationHelper(), multilineString(
		"import java.util.List",
		"agent A1 {",
			"val list : List<Integer> = null",
			"val i = 45",
			"val j : double = 45",
		"}"
	));
	assertEquals(1, mas.getXtendTypes().size());
	//
	assertTrue(Strings.isNullOrEmpty(mas.getPackage()));
	//
	SarlAgent agent = (SarlAgent) mas.getXtendTypes().get(0);
	assertEquals("A1", agent.getName());
	assertNull(agent.getExtends());
	assertEquals(3, agent.getMembers().size());
	//
	SarlField attr1 = (SarlField) agent.getMembers().get(0);
	assertEquals("list", attr1.getName());
	assertTypeReferenceIdentifier(attr1.getType(), "java.util.List<java.lang.Integer>");
	assertXExpression(attr1.getInitialValue(), XNullLiteral.class, null);
	//
	SarlField attr2 = (SarlField) agent.getMembers().get(1);
	assertEquals("i", attr2.getName());
	assertNull(attr2.getType());
	assertXExpression(attr2.getInitialValue(), XNumberLiteral.class, "45");
	//
	SarlField attr3 = (SarlField) agent.getMembers().get(2);
	assertEquals("j", attr3.getName());
	assertTypeReferenceIdentifier(attr3.getType(), "double");
	assertXExpression(attr3.getInitialValue(), XNumberLiteral.class, "45");
}
 
Example #7
Source File: TypeComputationStateTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testChildrenAddEntryForParent() throws Exception {
	resolver.setTypeComputer(this);
	XExpression expression = expression("{ null }");
	resolver.initializeFrom(expression);
	PublicResolvedTypes resolution = new PublicResolvedTypes(resolver);
	AnyTypeReference any = resolution.getReferenceOwner().newAnyTypeReference();
	new ExpressionBasedRootTypeComputationState(resolution, resolver.getBatchScopeProvider().newSession(expression.eResource()),
			expression, any).computeTypes();
	assertEquals(any.toString(), resolution.getActualType(expression).toString());
	assertEquals(any.toString(), resolution.getActualType(((XNullLiteral) getFirst(expression.eContents(), null))).toString());
}
 
Example #8
Source File: ConstantConditionsInterpreter.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
public EvaluationResult internalEvaluate(final XExpression it, final EvaluationContext context) {
  if (it instanceof XBinaryOperation) {
    return _internalEvaluate((XBinaryOperation)it, context);
  } else if (it instanceof XUnaryOperation) {
    return _internalEvaluate((XUnaryOperation)it, context);
  } else if (it instanceof XAbstractFeatureCall) {
    return _internalEvaluate((XAbstractFeatureCall)it, context);
  } else if (it instanceof XBooleanLiteral) {
    return _internalEvaluate((XBooleanLiteral)it, context);
  } else if (it instanceof XCastedExpression) {
    return _internalEvaluate((XCastedExpression)it, context);
  } else if (it instanceof XNullLiteral) {
    return _internalEvaluate((XNullLiteral)it, context);
  } else if (it instanceof XNumberLiteral) {
    return _internalEvaluate((XNumberLiteral)it, context);
  } else if (it instanceof XStringLiteral) {
    return _internalEvaluate((XStringLiteral)it, context);
  } else if (it instanceof XTypeLiteral) {
    return _internalEvaluate((XTypeLiteral)it, context);
  } else if (it != null) {
    return _internalEvaluate(it, context);
  } else if (it == null) {
    return _internalEvaluate((Void)null, context);
  } else {
    throw new IllegalArgumentException("Unhandled parameter types: " +
      Arrays.<Object>asList(it, context).toString());
  }
}
 
Example #9
Source File: JvmTypesBuilderTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected <T extends Object> void genericTestInitializeSafely(final Function3<? super EObject, ? super String, ? super Procedure1<? super T>, ? extends EObject> create) {
  final XNullLiteral expr = XbaseFactory.eINSTANCE.createXNullLiteral();
  final Wrapper<Boolean> initialized = new Wrapper<Boolean>(Boolean.valueOf(false));
  final Procedure1<T> _function = (T it) -> {
    initialized.set(Boolean.valueOf(true));
    throw new RuntimeException();
  };
  final EObject element = create.apply(expr, "foo", _function);
  Assert.assertTrue((initialized.get()).booleanValue());
  Assert.assertNotNull(element);
}
 
Example #10
Source File: AssignmentFeatureCallArgumentsTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void test_01() {
  final AssignmentFeatureCallArguments arguments = this.toArguments("", "null");
  Assert.assertTrue(arguments.hasUnprocessedArguments());
  final IFeatureCallArgumentSlot singleSlot = arguments.getNextUnprocessedArgumentSlot();
  Assert.assertNull(singleSlot.getDeclaredType());
  Assert.assertFalse(singleSlot.isVarArg());
  Assert.assertFalse(singleSlot.isSuperfluous());
  XExpression _argumentExpression = singleSlot.getArgumentExpression();
  Assert.assertTrue((_argumentExpression instanceof XNullLiteral));
  singleSlot.markProcessed();
  Assert.assertFalse(arguments.hasUnprocessedArguments());
}
 
Example #11
Source File: LiteralsCompiler.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected boolean isVariableDeclarationRequired(XExpression expr, ITreeAppendable b, boolean recursive) {
	if (expr instanceof XBooleanLiteral
		|| expr instanceof XStringLiteral
		|| expr instanceof XNumberLiteral
		|| expr instanceof XTypeLiteral
		|| expr instanceof XClosure
		|| expr instanceof XNullLiteral)
		return false;
	return super.isVariableDeclarationRequired(expr,b, recursive);
}
 
Example #12
Source File: XExpressionHelper.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @return whether the expression itself (not its children) possibly causes a side-effect
 */
public boolean hasSideEffects(XExpression expr) {
	if (expr instanceof XClosure
		|| expr instanceof XStringLiteral
		|| expr instanceof XTypeLiteral
		|| expr instanceof XBooleanLiteral
		|| expr instanceof XNumberLiteral
		|| expr instanceof XNullLiteral
		|| expr instanceof XAnnotation
		)
		return false;
	if(expr instanceof XCollectionLiteral) {
		for(XExpression element: ((XCollectionLiteral)expr).getElements()) {
			if(hasSideEffects(element))
				return true;
		}
		return false;
	}
	if (expr instanceof XAbstractFeatureCall) {
		XAbstractFeatureCall featureCall = (XAbstractFeatureCall) expr;
		return hasSideEffects(featureCall, true);
	}
	if (expr instanceof XConstructorCall) {
		XConstructorCall constrCall = (XConstructorCall) expr;
		return findPureAnnotation(constrCall.getConstructor()) == null;
	}
	return true;
}
 
Example #13
Source File: TestAssertions.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Assert that the given actual formal parameters have the expected default values.
 *
 * The order of the parameters and the expected types is significant.
 *
 * The parameter <code>expectedDefaultValues</code> is a sequence of pairs, where
 * the first element is the type of the default value and the second element is
 * the representation of the default value.
 * If the first element of the pair is null (meaning no default value), then
 * the second element must be missed.
 *
 * @param actualFormalParameters the list of the formal parameters.
 * @param expectedDefaultValues the expected default values.
 */
@SuppressWarnings("rawtypes")
public static void assertParameterDefaultValues(Iterable<? extends XtendParameter> actualFormalParameters, Object... expectedDefaultValues) {
	int i = 0;
	for (XtendParameter parameter : actualFormalParameters) {
		if (expectedDefaultValues[i] == null) {
			if (parameter instanceof SarlFormalParameter) {
				assertNull(((SarlFormalParameter) parameter).getDefaultValue(), () -> "No default value expected");
			}
		} else {
			assertTrue(parameter instanceof SarlFormalParameter);
			final int ii = i;
			assertTrue(expectedDefaultValues[i] instanceof Class, () -> "The #" + ii + " in expectedDefaultValues is not a Class");
			Class type = (Class) expectedDefaultValues[i];
			assertTrue(type.isInstance(((SarlFormalParameter) parameter).getDefaultValue()), () -> "Unexpected type for the default value.");
			if (XNumberLiteral.class.isAssignableFrom(type)) {
				++i;
				assertEquals(expectedDefaultValues[i], ((XNumberLiteral) ((SarlFormalParameter) parameter).getDefaultValue()).getValue());
			} else if (XStringLiteral.class.isAssignableFrom(type)) {
				++i;
				assertEquals(expectedDefaultValues[i], ((XStringLiteral) ((SarlFormalParameter) parameter).getDefaultValue()).getValue());
			} else if (XNullLiteral.class.isAssignableFrom(type)) {
				//
			} else {
				throw new RuntimeException("Unsupported type of literal for this assertion function");
			}
		}
		++i;
	}
	if (i < expectedDefaultValues.length) {
		fail("Not enough default values. Expected: " + Arrays.toString(expectedDefaultValues)
			+ "Actual: " + Iterables.toString(actualFormalParameters));
	}
}
 
Example #14
Source File: TestAssertions.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Assert the actual XExpression is of the given type and initialized with the given literal.
 *
 * @param actualExpression the expression to test.
 * @param expectedType the expected type of expression.
 * @param expectedValue the expected value.
 */
public static void assertXExpression(XExpression actualExpression, Class<? extends XExpression> expectedType, String expectedValue) {
	assertTrue(expectedType.isInstance(actualExpression), () -> "Expecting type of expression: " + expectedType.getName());
	if (XNumberLiteral.class.isAssignableFrom(expectedType)) {
		assertEquals(expectedValue, ((XNumberLiteral) actualExpression).getValue(), () -> "Invalid value.");
	}
	else if (XStringLiteral.class.isAssignableFrom(expectedType)) {
		assertEquals(expectedValue, ((XStringLiteral) actualExpression).getValue(), () -> "Invalid value.");
	}
	else if (XNullLiteral.class.isAssignableFrom(expectedType)) {
		//
	}
}
 
Example #15
Source File: ShouldExtensions.java    From sarl with Apache License 2.0 4 votes vote down vote up
/** Ensure that the given type literal is equal to the given type.
 *
 * @param actual the type literal to test.
 * @param expected the name of the expected type.
 * @return the validation status
 */
@SuppressWarnings({"checkstyle:returncount", "checkstyle:npathcomplexity"})
public static boolean shouldBeLiteral(XExpression actual, Object expected) {
	if (actual instanceof XNumberLiteral) {
		return shouldBe((XNumberLiteral) actual, expected);
	}
	if (actual instanceof XBooleanLiteral) {
		return shouldBe((XBooleanLiteral) actual, expected);
	}
	if (actual instanceof XStringLiteral) {
		return shouldBe((XStringLiteral) actual, expected);
	}
	if (actual instanceof XTypeLiteral) {
		return shouldBe((XTypeLiteral) actual, expected);
	}
	if (actual instanceof XNullLiteral) {
		return Objects.equals("null", expected); //$NON-NLS-1$
	}
	if (actual instanceof XCollectionLiteral) {
		return shouldBe((XCollectionLiteral) actual, expected);
	}
	if (actual instanceof XBinaryOperation) {
		final XBinaryOperation op = (XBinaryOperation) actual;
		if ("operator_mappedTo".equals(op.getFeature().getSimpleName())) { //$NON-NLS-1$
			final Object key;
			final Object value;
			if (expected instanceof Pair<?, ?>) {
				key = ((Pair<?, ?>) expected).getKey();
				value = ((Pair<?, ?>) expected).getValue();
			} else if (expected instanceof Entry<?, ?>) {
				key = ((Entry<?, ?>) expected).getKey();
				value = ((Entry<?, ?>) expected).getValue();
			} else {
				return false;
			}
			return shouldBeLiteral(op.getLeftOperand(), key)
					&& shouldBeLiteral(op.getRightOperand(), value);
		}
	}
	return false;
}
 
Example #16
Source File: XtendImplicitReturnFinder.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
public void findImplicitReturns(final XExpression expression, final ImplicitReturnFinder.Acceptor acceptor) {
  if (expression instanceof AnonymousClass) {
    _findImplicitReturns((AnonymousClass)expression, acceptor);
    return;
  } else if (expression instanceof RichString) {
    _findImplicitReturns((RichString)expression, acceptor);
    return;
  } else if (expression instanceof XAbstractFeatureCall) {
    _findImplicitReturns((XAbstractFeatureCall)expression, acceptor);
    return;
  } else if (expression instanceof XBlockExpression) {
    _findImplicitReturns((XBlockExpression)expression, acceptor);
    return;
  } else if (expression instanceof XBooleanLiteral) {
    _findImplicitReturns((XBooleanLiteral)expression, acceptor);
    return;
  } else if (expression instanceof XCastedExpression) {
    _findImplicitReturns((XCastedExpression)expression, acceptor);
    return;
  } else if (expression instanceof XClosure) {
    _findImplicitReturns((XClosure)expression, acceptor);
    return;
  } else if (expression instanceof XCollectionLiteral) {
    _findImplicitReturns((XCollectionLiteral)expression, acceptor);
    return;
  } else if (expression instanceof XConstructorCall) {
    _findImplicitReturns((XConstructorCall)expression, acceptor);
    return;
  } else if (expression instanceof XIfExpression) {
    _findImplicitReturns((XIfExpression)expression, acceptor);
    return;
  } else if (expression instanceof XInstanceOfExpression) {
    _findImplicitReturns((XInstanceOfExpression)expression, acceptor);
    return;
  } else if (expression instanceof XNullLiteral) {
    _findImplicitReturns((XNullLiteral)expression, acceptor);
    return;
  } else if (expression instanceof XNumberLiteral) {
    _findImplicitReturns((XNumberLiteral)expression, acceptor);
    return;
  } else if (expression instanceof XStringLiteral) {
    _findImplicitReturns((XStringLiteral)expression, acceptor);
    return;
  } else if (expression instanceof XSwitchExpression) {
    _findImplicitReturns((XSwitchExpression)expression, acceptor);
    return;
  } else if (expression instanceof XSynchronizedExpression) {
    _findImplicitReturns((XSynchronizedExpression)expression, acceptor);
    return;
  } else if (expression instanceof XTryCatchFinallyExpression) {
    _findImplicitReturns((XTryCatchFinallyExpression)expression, acceptor);
    return;
  } else if (expression instanceof XTypeLiteral) {
    _findImplicitReturns((XTypeLiteral)expression, acceptor);
    return;
  } else if (expression != null) {
    _findImplicitReturns(expression, acceptor);
    return;
  } else if (expression == null) {
    _findImplicitReturns((Void)null, acceptor);
    return;
  } else {
    throw new IllegalArgumentException("Unhandled parameter types: " +
      Arrays.<Object>asList(expression, acceptor).toString());
  }
}
 
Example #17
Source File: XtendCompiler.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
private boolean isEmptyEmission(XExpression expression) {
	return expression instanceof XStringLiteral && StringExtensions.isNullOrEmpty(((XStringLiteral)expression).getValue()) || expression instanceof XNullLiteral;
}
 
Example #18
Source File: SarlCompiler.java    From sarl with Apache License 2.0 4 votes vote down vote up
private static boolean isLiteral(XExpression expr) {
	return expr instanceof XBooleanLiteral || expr instanceof XStringLiteral
			|| expr instanceof XNumberLiteral || expr instanceof XCollectionLiteral
			|| expr instanceof XSetLiteral || expr instanceof XNullLiteral || expr instanceof XTypeLiteral;
}
 
Example #19
Source File: AbstractXbaseSemanticSequencer.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
@Deprecated
protected void sequence_XNullLiteral(EObject context, XNullLiteral semanticObject) {
	sequence_XNullLiteral(createContext(context, semanticObject), semanticObject);
}
 
Example #20
Source File: ConstantConditionsInterpreter.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
protected EvaluationResult _internalEvaluate(final XNullLiteral it, final EvaluationContext context) {
  return new EvaluationResult(null, true);
}
 
Example #21
Source File: XbaseImplicitReturnFinder.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
public void findImplicitReturns(final XExpression expression, final ImplicitReturnFinder.Acceptor acceptor) {
  if (expression instanceof XAbstractFeatureCall) {
    _findImplicitReturns((XAbstractFeatureCall)expression, acceptor);
    return;
  } else if (expression instanceof XBlockExpression) {
    _findImplicitReturns((XBlockExpression)expression, acceptor);
    return;
  } else if (expression instanceof XBooleanLiteral) {
    _findImplicitReturns((XBooleanLiteral)expression, acceptor);
    return;
  } else if (expression instanceof XCastedExpression) {
    _findImplicitReturns((XCastedExpression)expression, acceptor);
    return;
  } else if (expression instanceof XClosure) {
    _findImplicitReturns((XClosure)expression, acceptor);
    return;
  } else if (expression instanceof XCollectionLiteral) {
    _findImplicitReturns((XCollectionLiteral)expression, acceptor);
    return;
  } else if (expression instanceof XConstructorCall) {
    _findImplicitReturns((XConstructorCall)expression, acceptor);
    return;
  } else if (expression instanceof XIfExpression) {
    _findImplicitReturns((XIfExpression)expression, acceptor);
    return;
  } else if (expression instanceof XInstanceOfExpression) {
    _findImplicitReturns((XInstanceOfExpression)expression, acceptor);
    return;
  } else if (expression instanceof XNullLiteral) {
    _findImplicitReturns((XNullLiteral)expression, acceptor);
    return;
  } else if (expression instanceof XNumberLiteral) {
    _findImplicitReturns((XNumberLiteral)expression, acceptor);
    return;
  } else if (expression instanceof XStringLiteral) {
    _findImplicitReturns((XStringLiteral)expression, acceptor);
    return;
  } else if (expression instanceof XSwitchExpression) {
    _findImplicitReturns((XSwitchExpression)expression, acceptor);
    return;
  } else if (expression instanceof XSynchronizedExpression) {
    _findImplicitReturns((XSynchronizedExpression)expression, acceptor);
    return;
  } else if (expression instanceof XTryCatchFinallyExpression) {
    _findImplicitReturns((XTryCatchFinallyExpression)expression, acceptor);
    return;
  } else if (expression instanceof XTypeLiteral) {
    _findImplicitReturns((XTypeLiteral)expression, acceptor);
    return;
  } else if (expression != null) {
    _findImplicitReturns(expression, acceptor);
    return;
  } else if (expression == null) {
    _findImplicitReturns((Void)null, acceptor);
    return;
  } else {
    throw new IllegalArgumentException("Unhandled parameter types: " +
      Arrays.<Object>asList(expression, acceptor).toString());
  }
}
 
Example #22
Source File: XbaseImplicitReturnFinder.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
protected void _findImplicitReturns(final XNullLiteral expression, final ImplicitReturnFinder.Acceptor acceptor) {
  acceptor.accept(expression);
}
 
Example #23
Source File: XbaseInterpreter.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * don't call this directly. Always call evaluate() internalEvaluate()
 */
protected Object doEvaluate(XExpression expression, IEvaluationContext context, CancelIndicator indicator) {
	if (expression instanceof XAssignment) {
      return _doEvaluate((XAssignment)expression, context, indicator);
    } else if (expression instanceof XDoWhileExpression) {
      return _doEvaluate((XDoWhileExpression)expression, context, indicator);
    } else if (expression instanceof XMemberFeatureCall) {
      return _doEvaluate((XMemberFeatureCall)expression, context, indicator);
    } else if (expression instanceof XWhileExpression) {
      return _doEvaluate((XWhileExpression)expression, context, indicator);
    } else if (expression instanceof XFeatureCall) {
    	return _doEvaluate((XFeatureCall)expression, context, indicator);
    } else if (expression instanceof XAbstractFeatureCall) {
    	return _doEvaluate((XAbstractFeatureCall)expression, context, indicator);
    } else if (expression instanceof XBlockExpression) {
      return _doEvaluate((XBlockExpression)expression, context, indicator);
    } else if (expression instanceof XSynchronizedExpression) {
	  return _doEvaluate((XSynchronizedExpression)expression, context, indicator);
	} else if (expression instanceof XBooleanLiteral) {
      return _doEvaluate((XBooleanLiteral)expression, context, indicator);
    } else if (expression instanceof XCastedExpression) {
      return _doEvaluate((XCastedExpression)expression, context, indicator);
    } else if (expression instanceof XClosure) {
      return _doEvaluate((XClosure)expression, context, indicator);
    } else if (expression instanceof XConstructorCall) {
      return _doEvaluate((XConstructorCall)expression, context, indicator);
    } else if (expression instanceof XForLoopExpression) {
      return _doEvaluate((XForLoopExpression)expression, context, indicator);
    } else if (expression instanceof XBasicForLoopExpression) {
	  return _doEvaluate((XBasicForLoopExpression)expression, context, indicator);
	} else if (expression instanceof XIfExpression) {
      return _doEvaluate((XIfExpression)expression, context, indicator);
    } else if (expression instanceof XInstanceOfExpression) {
      return _doEvaluate((XInstanceOfExpression)expression, context, indicator);
    } else if (expression instanceof XNullLiteral) {
      return _doEvaluate((XNullLiteral)expression, context, indicator);
    } else if (expression instanceof XNumberLiteral) {
      return _doEvaluate((XNumberLiteral)expression, context, indicator);
    } else if (expression instanceof XReturnExpression) {
      return _doEvaluate((XReturnExpression)expression, context, indicator);
    } else if (expression instanceof XStringLiteral) {
      return _doEvaluate((XStringLiteral)expression, context, indicator);
    } else if (expression instanceof XSwitchExpression) {
      return _doEvaluate((XSwitchExpression)expression, context, indicator);
    } else if (expression instanceof XThrowExpression) {
      return _doEvaluate((XThrowExpression)expression, context, indicator);
    } else if (expression instanceof XTryCatchFinallyExpression) {
      return _doEvaluate((XTryCatchFinallyExpression)expression, context, indicator);
    } else if (expression instanceof XTypeLiteral) {
      return _doEvaluate((XTypeLiteral)expression, context, indicator);
    } else if (expression instanceof XVariableDeclaration) {
	      return _doEvaluate((XVariableDeclaration)expression, context, indicator);
    } else if (expression instanceof XListLiteral) {
	      return _doEvaluate((XListLiteral)expression, context, indicator);
    } else if (expression instanceof XSetLiteral) {
	      return _doEvaluate((XSetLiteral)expression, context, indicator);
    } else {
      throw new IllegalArgumentException("Unhandled parameter types: " +
        Arrays.<Object>asList(expression, context, indicator).toString());
    }
}
 
Example #24
Source File: LiteralsCompiler.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
public void _toJavaStatement(XNullLiteral expr, ITreeAppendable b, boolean isReferenced) {
	generateComment(expr, b, isReferenced);
}
 
Example #25
Source File: LiteralsCompiler.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * @param expr the expression. Used by the dispatch strategy.
 */
public void _toJavaExpression(XNullLiteral expr, ITreeAppendable b) {
	b.append("null");
}
 
Example #26
Source File: XbaseSemanticSequencer.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * This is for backwards compatibility &lt; 2.3RC2 due to change in the naming strategy for sequencer methods
 */
@Deprecated
protected void sequence_XExpression(EObject context, XNullLiteral semanticObject) {
	super.sequence_XNullLiteral(context, semanticObject);
}
 
Example #27
Source File: XbaseTypeComputer.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * @param object used for dispatching
 */
protected void _computeTypes(XNullLiteral object, ITypeComputationState state) {
	state.acceptActualType(state.getReferenceOwner().newAnyTypeReference());
}
 
Example #28
Source File: XbaseTypeComputer.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void computeTypes(XExpression expression, ITypeComputationState state) {
	if (expression instanceof XAssignment) {
		_computeTypes((XAssignment)expression, state);
	} else if (expression instanceof XAbstractFeatureCall) {
		_computeTypes((XAbstractFeatureCall)expression, state);
	} else if (expression instanceof XDoWhileExpression) {
		_computeTypes((XDoWhileExpression)expression, state);
	} else if (expression instanceof XWhileExpression) {
		_computeTypes((XWhileExpression)expression, state);
	} else if (expression instanceof XBlockExpression) {
		_computeTypes((XBlockExpression)expression, state);
	} else if (expression instanceof XBooleanLiteral) {
		_computeTypes((XBooleanLiteral)expression, state);
	} else if (expression instanceof XCastedExpression) {
		_computeTypes((XCastedExpression)expression, state);
	} else if (expression instanceof XClosure) {
		_computeTypes((XClosure)expression, state);
	} else if (expression instanceof XConstructorCall) {
		_computeTypes((XConstructorCall)expression, state);
	} else if (expression instanceof XForLoopExpression) {
		_computeTypes((XForLoopExpression)expression, state);
	} else if (expression instanceof XBasicForLoopExpression) {
		_computeTypes((XBasicForLoopExpression)expression, state);
	} else if (expression instanceof XIfExpression) {
		_computeTypes((XIfExpression)expression, state);
	} else if (expression instanceof XInstanceOfExpression) {
		_computeTypes((XInstanceOfExpression)expression, state);
	} else if (expression instanceof XNumberLiteral) {
		_computeTypes((XNumberLiteral)expression, state);
	} else if (expression instanceof XNullLiteral) {
		_computeTypes((XNullLiteral)expression, state);
	} else if (expression instanceof XReturnExpression) {
		_computeTypes((XReturnExpression)expression, state);
	} else if (expression instanceof XStringLiteral) {
		_computeTypes((XStringLiteral)expression, state);
	} else if (expression instanceof XSwitchExpression) {
		_computeTypes((XSwitchExpression)expression, state);
	} else if (expression instanceof XThrowExpression) {
		_computeTypes((XThrowExpression)expression, state);
	} else if (expression instanceof XTryCatchFinallyExpression) {
		_computeTypes((XTryCatchFinallyExpression)expression, state);
	} else if (expression instanceof XTypeLiteral) {
		_computeTypes((XTypeLiteral)expression, state);
	} else if (expression instanceof XVariableDeclaration) {
		_computeTypes((XVariableDeclaration)expression, state);
	} else if (expression instanceof XListLiteral) {
		_computeTypes((XListLiteral)expression, state);
	} else if (expression instanceof XSetLiteral) {
		_computeTypes((XSetLiteral)expression, state);
	} else if (expression instanceof XSynchronizedExpression) {
		_computeTypes((XSynchronizedExpression)expression, state);
	} else {
		throw new UnsupportedOperationException("Missing type computation for expression type: " + expression.eClass().getName() + " / " + state);
	}
}
 
Example #29
Source File: PyExpressionGenerator.java    From sarl with Apache License 2.0 3 votes vote down vote up
/** Generate the given object.
 *
 * @param literal the null literal.
 * @param it the target for the generated content.
 * @param context the context.
 * @return the literal.
 */
@SuppressWarnings("static-method")
protected XExpression _generate(XNullLiteral literal, IAppendable it, IExtraLanguageGeneratorContext context) {
	appendReturnIfExpectedReturnedExpression(it, context);
	it.append("None"); //$NON-NLS-1$
	return literal;
}
 
Example #30
Source File: XbaseInterpreter.java    From xtext-extras with Eclipse Public License 2.0 2 votes vote down vote up
/**
 * @param literal unused in this context but required for dispatching 
 * @param context unused in this context but required for dispatching
 * @param indicator unused in this context but required for dispatching
 */
protected Object _doEvaluate(XNullLiteral literal, IEvaluationContext context, CancelIndicator indicator) {
	return null;
}