public void testFinalCast() throws Exception { XExpression expression = expression("'foo' as Cloneable"); helper.assertError( expression, TypesPackage.Literals.JVM_TYPE_REFERENCE, INVALID_CAST, "sealed"); expression = expression("'foo' as CharSequence"); helper.assertNoError(expression, INVALID_CAST); }
protected void checkInnerExpressionInBlock(String innerExpression, EClass innerExpressionClass) throws Exception { XExpression validExpression = expression("{ " + innerExpression + " }"); helper.assertNoError(validExpression, INVALID_INNER_EXPRESSION); XExpression invalidExpression = expression("{ " + innerExpression + " " + innerExpression + " }"); helper.assertError( invalidExpression, innerExpressionClass, INVALID_INNER_EXPRESSION, "block", "last", "element"); }
public void testThrowsInBlock_02() throws Exception { XExpression block = expression("{ throw new Exception() new Object()}"); helper.assertError( block, XbasePackage.Literals.XCONSTRUCTOR_CALL, UNREACHABLE_CODE, "unreachable", "expression"); }
public void testInvalidEarlyExit_04() throws Exception { XExpression expression = expression("if (return 1) {}"); helper.assertError( expression, XbasePackage.Literals.XRETURN_EXPRESSION, INCOMPATIBLE_TYPES, "void", "boolean"); }
public void testInvalidEarlyExit_03() throws Exception { XExpression expression = expression("try {} finally return null"); helper.assertError( expression, XbasePackage.Literals.XRETURN_EXPRESSION, INVALID_EARLY_EXIT, "return", "context"); }
public void testUnreachableCode_02() throws Exception { XExpression expression = expression( "{" + " do " + " throw new Exception() " + " while (false)" + " null" + "}"); helper.assertError( ((XBlockExpression) expression).getExpressions().get(1), XbasePackage.Literals.XNULL_LITERAL, UNREACHABLE_CODE); }
public void testNewAbstractClass() throws Exception { XExpression expression = expression("new testdata.AbstractClassWithPublicConstructor()"); helper.assertError( expression, XCONSTRUCTOR_CALL, ABSTRACT_CLASS_INSTANTIATION, "abstract", "instantiate", "class"); }
public void testUnreachableCode_00() throws Exception { XExpression expression = expression( "{" + " for (e : new java.util.ArrayList<String>()) " + " throw new Exception() " + " null" + "}"); helper.assertNoErrors(expression); }
public void testInvalidEarlyExit_01() throws Exception { XExpression expression = expression("try {} finally throw new Exception()"); helper.assertError( expression, XbasePackage.Literals.XTHROW_EXPRESSION, INVALID_EARLY_EXIT, "throw", "not allowed", "context"); }
protected String compileToJavaCode(String xtendCode) { try { final String text = "package foo class Test { def Object foo() throws Exception {" + xtendCode + "} }"; final XtendFile file = parseHelper.parse(text); validationHelper.assertNoErrors(file); JvmGenericType inferredType = associations.getInferredType(file.getXtendClass()); CharSequence javaCode = generator.generateType(inferredType); return javaCode.toString(); } catch (Exception e) { throw new RuntimeException("Xtend compilation failed for: " + xtendCode, e); } }
public void testPrimitiveAsTypeGuard() throws Exception { XCasePart expression = ((XSwitchExpression) expression("switch(new Object()) { int: 1 }")).getCases().get(0); helper.assertError( expression, XCASE_PART, INVALID_USE_OF_TYPE, "primitive", "not", "allowed", "type", "guard"); }
public void testLocalVarOfTypeVoid_02() throws Exception { XBlockExpression block = (XBlockExpression) expression("{ var String s = while(true) {} }"); helper.assertError(block, XWHILE_EXPRESSION, INCOMPATIBLE_TYPES, "void", "String"); }
public void testLocalVarOfTypeVoid_01() throws Exception { XBlockExpression block = (XBlockExpression) expression("{ var illegalAssignmentOfVoid = while(true) {} }"); helper.assertError(block, XVARIABLE_DECLARATION, INVALID_USE_OF_TYPE, "void"); }
public void testLocalVarWithArguments() throws Exception { XExpression expr = expression("{ val x = 'foo' x(42) }"); helper.assertError(expr, XFEATURE_CALL, LOCAL_VAR_ACCESS_WITH_PARENTHESES, "local", "variable"); }
public void testSideEffectFreeExpressionInBlock_04() throws Exception { XExpression expr = expression("{ val x = 'foo' x as String 42 }"); helper.assertError(expr, XCASTED_EXPRESSION, SIDE_EFFECT_FREE_EXPRESSION_IN_BLOCK); }
public void testSideEffectFreeExpressionInBlock_03() throws Exception { XExpression expr = expression("{ val x = 'foo' 42 x }"); helper.assertError(expr, XINT_LITERAL, SIDE_EFFECT_FREE_EXPRESSION_IN_BLOCK); }
public void testToLittleTypeInformation() throws Exception { XExpression expr = expression("{ val x = [e | e.toString()] }"); helper.assertError(expr, XCLOSURE, TOO_LITTLE_TYPE_INFORMATION); }
public void testVariableShadowing_01() throws Exception { XExpression expression = expression("{ val x = 'foo' for ( x : newArrayList('foo')) x.length }"); helper.assertError( expression, TypesPackage.Literals.JVM_FORMAL_PARAMETER, VARIABLE_NAME_SHADOWING, "x"); }
public void testInstanceOf_2() throws Exception { XExpression expression = expression("new String() instanceof Boolean"); helper.assertError( expression, XINSTANCE_OF_EXPRESSION, INVALID_INSTANCEOF, "incompatible", "type"); helper.assertNoError(expression, OBSOLETE_INSTANCEOF); }
public void testInvalidEarlyExit_05() throws Exception { XExpression expression = expression("if (true) return 1 else throw new Exception()"); helper.assertNoErrors(expression); }
public void testInstanceOf_1() throws Exception { XExpression expression = expression("'foo' instanceof Cloneable"); helper.assertError( expression, XINSTANCE_OF_EXPRESSION, INVALID_INSTANCEOF, "incompatible", "type"); helper.assertNoError(expression, OBSOLETE_INSTANCEOF); }
public void testNoWildCardsInTypeArgs() throws Exception { XExpression expr = expression("java::util::Collections::<? extends String>singleton()"); helper.assertError( expr, TypesPackage.Literals.JVM_WILDCARD_TYPE_REFERENCE, INVALID_USE_OF_WILDCARD); }
public void testCast_2() throws Exception { XExpression expression = expression("new String() as Boolean"); helper.assertError( expression, TypesPackage.Literals.JVM_TYPE_REFERENCE, INVALID_CAST, "Cannot", "cast"); helper.assertNoError(expression, OBSOLETE_CAST); }
public void testCast_1() throws Exception { XExpression expression = expression("'foo' as Cloneable"); helper.assertError( expression, TypesPackage.Literals.JVM_TYPE_REFERENCE, INVALID_CAST, "sealed", "type"); helper.assertNoError(expression, OBSOLETE_CAST); }
public void testLocalVarOfTypeVoid_03() throws Exception { XBlockExpression block = (XBlockExpression) expression("{ var void illegalVoid; }"); helper.assertError( block, TypesPackage.Literals.JVM_PARAMETERIZED_TYPE_REFERENCE, INVALID_USE_OF_TYPE, "void"); }
public void testNoWildCardsInTypeArgs_01() throws Exception { XExpression expr = expression("new java.util.ArrayList<?>()"); helper.assertError( expr, TypesPackage.Literals.JVM_WILDCARD_TYPE_REFERENCE, INVALID_USE_OF_WILDCARD); }
public void testVariableShadowing_00() throws Exception { XExpression expression = expression("{ val x = 'foo' { val x= 'bar' return x } }"); helper.assertError( expression, XbasePackage.Literals.XVARIABLE_DECLARATION, VARIABLE_NAME_SHADOWING, "x"); }
public void testSideEffectFreeExpressionInBlock_01() throws Exception { XExpression expr = expression("{ val x = 'foo' x 42 }"); helper.assertError(expr, XFEATURE_CALL, SIDE_EFFECT_FREE_EXPRESSION_IN_BLOCK); }
public void testInstanceOf_0() throws Exception { XExpression expression = expression("'foo' instanceof String"); helper.assertWarning( expression, XINSTANCE_OF_EXPRESSION, OBSOLETE_INSTANCEOF, "already", "java.lang.String"); helper.assertNoError(expression, INVALID_INSTANCEOF); }
public void testUnreachableCode_01() throws Exception { XExpression expression = expression("{" + " while (false) " + " throw new Exception() " + " null" + "}"); helper.assertNoErrors(expression); }