Exemple #1
0
 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);
 }
Exemple #2
0
 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");
 }
Exemple #3
0
 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");
 }
Exemple #4
0
 public void testInvalidEarlyExit_04() throws Exception {
   XExpression expression = expression("if (return 1) {}");
   helper.assertError(
       expression,
       XbasePackage.Literals.XRETURN_EXPRESSION,
       INCOMPATIBLE_TYPES,
       "void",
       "boolean");
 }
Exemple #5
0
 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");
 }
Exemple #6
0
 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);
 }
Exemple #7
0
 public void testNewAbstractClass() throws Exception {
   XExpression expression = expression("new testdata.AbstractClassWithPublicConstructor()");
   helper.assertError(
       expression,
       XCONSTRUCTOR_CALL,
       ABSTRACT_CLASS_INSTANTIATION,
       "abstract",
       "instantiate",
       "class");
 }
Exemple #8
0
 public void testUnreachableCode_00() throws Exception {
   XExpression expression =
       expression(
           "{"
               + "	for (e : new java.util.ArrayList<String>()) "
               + "      throw new Exception() "
               + "   null"
               + "}");
   helper.assertNoErrors(expression);
 }
Exemple #9
0
 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);
   }
 }
Exemple #11
0
 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");
 }
Exemple #12
0
 public void testLocalVarOfTypeVoid_02() throws Exception {
   XBlockExpression block = (XBlockExpression) expression("{ var String s = while(true) {} }");
   helper.assertError(block, XWHILE_EXPRESSION, INCOMPATIBLE_TYPES, "void", "String");
 }
Exemple #13
0
 public void testLocalVarOfTypeVoid_01() throws Exception {
   XBlockExpression block =
       (XBlockExpression) expression("{ var illegalAssignmentOfVoid = while(true) {} }");
   helper.assertError(block, XVARIABLE_DECLARATION, INVALID_USE_OF_TYPE, "void");
 }
Exemple #14
0
 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");
 }
Exemple #15
0
 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);
 }
Exemple #16
0
 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);
 }
Exemple #17
0
 public void testToLittleTypeInformation() throws Exception {
   XExpression expr = expression("{ val x = [e | e.toString()] }");
   helper.assertError(expr, XCLOSURE, TOO_LITTLE_TYPE_INFORMATION);
 }
Exemple #18
0
 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");
 }
Exemple #19
0
 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);
 }
Exemple #20
0
 public void testInvalidEarlyExit_05() throws Exception {
   XExpression expression = expression("if (true) return 1 else throw new Exception()");
   helper.assertNoErrors(expression);
 }
Exemple #21
0
 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);
 }
Exemple #22
0
 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);
 }
Exemple #23
0
 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);
 }
Exemple #24
0
 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);
 }
Exemple #25
0
 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");
 }
Exemple #26
0
 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);
 }
Exemple #27
0
 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");
 }
Exemple #28
0
 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);
 }
Exemple #29
0
 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);
 }
Exemple #30
0
 public void testUnreachableCode_01() throws Exception {
   XExpression expression =
       expression("{" + "	while (false) " + "      throw new Exception() " + "   null" + "}");
   helper.assertNoErrors(expression);
 }