Skip to content

Commit

Permalink
Remove tests checking lambda is not accepted at 1.7 level
Browse files Browse the repository at this point in the history
ECJ mandates 1.8 thus always accepts it and that's why the tests have
been commented out.
  • Loading branch information
akurtakov committed Dec 28, 2024
1 parent 9d6bfc3 commit 75112be
Showing 1 changed file with 0 additions and 140 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -769,146 +769,6 @@ public void test0020() throws JavaModelException {
IMethodBinding[] methods = binding.getDeclaredMethods();
assertEquals("Wrong size", 2, methods.length);
}
/**
* https://bugs.eclipse.org/bugs/show_bug.cgi?id=402673
*/
public void _2551_test402673a() throws JavaModelException {
String contents = "package test402673;"
+ "public class X {\n"
+ " Runnable r = () -> System.out.println(\"hi\");\n"
+"}\n";
this.workingCopy = getWorkingCopy("/Converter/src/test402673/X.java", true/* resolve */);
this.workingCopy.getBuffer().setContents(contents);
ASTNode node = runConversion(this.workingCopy, true);
assertTrue(node != null);
assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
CompilationUnit unit = (CompilationUnit) node;
assertProblemsSize(unit, 1, "Lambda expressions are allowed only at source level 1.8 or above");
TypeDeclaration type = (TypeDeclaration) getASTNode(unit, 0);
assertTrue((type.getFlags() & ASTNode.MALFORMED) != 0);
node = getASTNode(unit, 0, 0);
assertEquals("Not a field declaration", ASTNode.FIELD_DECLARATION, node.getNodeType());
FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
final List fragments = fieldDeclaration.fragments();
assertEquals("Wrong size", 1, fragments.size());
VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
final Expression initializer = fragment.getInitializer();
assertEquals("Not a null literal", ASTNode.NULL_LITERAL, initializer.getNodeType());
NullLiteral nullLiteral = (NullLiteral) initializer;
assertTrue((nullLiteral.getFlags() & ASTNode.MALFORMED) != 0);
}
/**
* https://bugs.eclipse.org/bugs/show_bug.cgi?id=402673
*/
public void _2551_test402673b() throws JavaModelException {
String contents = "package test402673;"
+ "public class X {\n"
+ " public void foo() {\n"
+ " Runnable r = () -> System.out.println(\"hi\");\n"
+" }\n"
+"}\n";
this.workingCopy = getWorkingCopy("/Converter/src/test402673/X.java", true/* resolve */);
this.workingCopy.getBuffer().setContents(contents);
ASTNode node = runConversion(this.workingCopy, true);
assertTrue(node != null);
assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
CompilationUnit unit = (CompilationUnit) node;
assertProblemsSize(unit, 1, "Lambda expressions are allowed only at source level 1.8 or above");
node = getASTNode(unit, 0, 0);
assertEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, node.getNodeType());
MethodDeclaration methodDecl = (MethodDeclaration) node;
assertTrue((methodDecl.getFlags() & ASTNode.MALFORMED) == 1);
node = getASTNode(unit, 0, 0, 0);
assertEquals("Not a variable declaration statement", ASTNode.VARIABLE_DECLARATION_STATEMENT, node.getNodeType());
VariableDeclarationStatement variableDecl = (VariableDeclarationStatement) node;
final List fragments = variableDecl.fragments();
assertEquals("Wrong size", 1, fragments.size());
VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
final Expression initializer = fragment.getInitializer();
assertEquals("Not a null literal", ASTNode.NULL_LITERAL, initializer.getNodeType());
NullLiteral nullLiteral = (NullLiteral) initializer;
assertTrue((nullLiteral.getFlags() & ASTNode.MALFORMED) != 0);
}
/**
* https://bugs.eclipse.org/bugs/show_bug.cgi?id=402674
*/
public void _2551_test403444() throws JavaModelException {
this.workingCopy = getWorkingCopy("/Converter18/src/test403444/X.java",
true/* resolve */);
String contents = "package test403444;" +
"public class X {\n" +
" public static interface StringToInt {\n" +
" int stoi(String s);\n" +
" }\n" +
" public static interface ReduceInt {\n" +
" int reduce(int a, int b);\n" +
" }\n" +
" void foo(StringToInt s) { }\n" +
" void bar(ReduceInt r) { }\n" +
" void bar() {\n" +
" foo(s -> s.length());\n" +
" foo((s) -> s.length());\n" +
" foo((String s) -> s.length()); //SingleVariableDeclaration is OK\n" +
" bar((x, y) -> x+y);\n" +
" bar((int x, int y) -> x+y); //SingleVariableDeclarations are OK\n" +
" }\n" +
"}\n";


this.workingCopy = getWorkingCopy("/Converter/src/test403444/X.java", true/* resolve */);
this.workingCopy.getBuffer().setContents(contents);
ASTNode node = runConversion(this.workingCopy, true);
assertTrue(node != null);
assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
CompilationUnit unit = (CompilationUnit) node;

String error = "Lambda expressions are allowed only at source level 1.8 or above\n" +
"Lambda expressions are allowed only at source level 1.8 or above\n" +
"Lambda expressions are allowed only at source level 1.8 or above\n" +
"Lambda expressions are allowed only at source level 1.8 or above\n" +
"Lambda expressions are allowed only at source level 1.8 or above";
assertProblemsSize(unit, 5, error);

TypeDeclaration typedeclaration = (TypeDeclaration) getASTNode(unit, 0);
MethodDeclaration methoddecl = (MethodDeclaration)typedeclaration.bodyDeclarations().get(4);
List statements = methoddecl.getBody().statements();
int sCount = 0;

ExpressionStatement statement = (ExpressionStatement)statements.get(sCount++);
MethodInvocation methodInvocation = (MethodInvocation)statement.getExpression();
Expression expression = (Expression) methodInvocation.arguments().get(0);
assertTrue(expression instanceof NullLiteral);
ITypeBinding binding = expression.resolveTypeBinding();
assertNull(binding);

statement = (ExpressionStatement)statements.get(sCount++);
methodInvocation = (MethodInvocation)statement.getExpression();
expression = (Expression) methodInvocation.arguments().get(0);
assertTrue(expression instanceof NullLiteral);
binding = expression.resolveTypeBinding();
assertNull(binding);

statement = (ExpressionStatement)statements.get(sCount++);
methodInvocation = (MethodInvocation)statement.getExpression();
expression = (Expression) methodInvocation.arguments().get(0);
assertTrue(expression instanceof NullLiteral);
binding = expression.resolveTypeBinding();
assertNull(binding);

statement = (ExpressionStatement)statements.get(sCount++);
methodInvocation = (MethodInvocation)statement.getExpression();
expression = (Expression) methodInvocation.arguments().get(0);
assertTrue(expression instanceof NullLiteral);
binding = expression.resolveTypeBinding();
assertNull(binding);

statement = (ExpressionStatement)statements.get(sCount++);
methodInvocation = (MethodInvocation)statement.getExpression();
expression = (Expression) methodInvocation.arguments().get(0);
assertTrue(expression instanceof NullLiteral);
binding = expression.resolveTypeBinding();
assertNull(binding);
}
/*
* https://bugs.eclipse.org/bugs/show_bug.cgi?id=399791
*/
Expand Down

0 comments on commit 75112be

Please sign in to comment.