Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManoj Palat2019-07-10 07:03:47 +0000
committerManoj Palat2019-07-10 07:03:47 +0000
commitf3e907f648a653fdefbef0c008dc31ed3d7a3e31 (patch)
tree897aed485d599232b790f8b678cec75839cd6b0b
parent2c6016ae14bdff2265ed063480a576ecf956527c (diff)
downloadeclipse.jdt.core-f3e907f648a653fdefbef0c008dc31ed3d7a3e31.tar.gz
eclipse.jdt.core-f3e907f648a653fdefbef0c008dc31ed3d7a3e31.tar.xz
eclipse.jdt.core-f3e907f648a653fdefbef0c008dc31ed3d7a3e31.zip
bug 548416 - dom ast standalone test fix
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/dom/StandAloneASTParserTest.java40
1 files changed, 35 insertions, 5 deletions
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/dom/StandAloneASTParserTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/dom/StandAloneASTParserTest.java
index 99cc029400..31253d5dd4 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/dom/StandAloneASTParserTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/dom/StandAloneASTParserTest.java
@@ -32,7 +32,6 @@ import org.eclipse.jdt.core.dom.AST;
import org.eclipse.jdt.core.dom.ASTNode;
import org.eclipse.jdt.core.dom.ASTParser;
import org.eclipse.jdt.core.dom.Block;
-import org.eclipse.jdt.core.dom.BreakStatement;
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jdt.core.dom.Expression;
import org.eclipse.jdt.core.dom.ExpressionStatement;
@@ -55,6 +54,7 @@ import org.eclipse.jdt.core.dom.Type;
import org.eclipse.jdt.core.dom.TypeDeclaration;
import org.eclipse.jdt.core.dom.VariableDeclarationFragment;
import org.eclipse.jdt.core.dom.VariableDeclarationStatement;
+import org.eclipse.jdt.core.dom.YieldStatement;
import org.eclipse.jdt.core.tests.compiler.regression.AbstractRegressionTest;
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
@@ -64,7 +64,7 @@ public class StandAloneASTParserTest extends AbstractRegressionTest {
super(name);
}
- private static final int AST_JLS_LATEST = AST.JLS12;
+ private static final int AST_JLS_LATEST = AST.JLS13;
public ASTNode runConversion(
int astLevel,
@@ -1786,14 +1786,44 @@ public class StandAloneASTParserTest extends AbstractRegressionTest {
ASTNode node = parser.createAST(null);
assertTrue("Should be a compilation unit", node instanceof CompilationUnit);
CompilationUnit cu = (CompilationUnit) node;
+ IProblem[] problems = cu.getProblems();
+ assertTrue(problems.length > 0);
+ assertTrue(problems[0].toString().contains("preview"));
+ }
+ public void testBug547900_01() throws JavaModelException {
+ String contents =
+ "class X {\n"+
+ " public static int foo(int i) {\n"+
+ " int result = switch (i) {\n"+
+ " case 1 -> {yield 5;}\n"+
+ " default -> 0;\n"+
+ " };\n"+
+ " return result;\n"+
+ " }\n"+
+ "}\n";
+
+ ASTParser parser = ASTParser.newParser(AST_JLS_LATEST);
+ parser.setSource(contents.toCharArray());
+ parser.setEnvironment(null, null, null, true);
+ parser.setResolveBindings(false);
+ Map<String, String> options = getCompilerOptions();
+ options.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_13);
+ options.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_13);
+ options.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_13);
+ options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
+ options.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
+ parser.setCompilerOptions(options);
+
+ ASTNode node = parser.createAST(null);
+ assertTrue("Should be a compilation unit", node instanceof CompilationUnit);
+ CompilationUnit cu = (CompilationUnit) node;
TypeDeclaration typeDeclaration = (TypeDeclaration) cu.types().get(0);
MethodDeclaration[] methods = typeDeclaration.getMethods();
MethodDeclaration methodDeclaration = methods[0];
VariableDeclarationStatement stmt = (VariableDeclarationStatement) methodDeclaration.getBody().statements().get(0);
VariableDeclarationFragment fragment = (VariableDeclarationFragment) stmt.fragments().get(0);
SwitchExpression se = (SwitchExpression) fragment.getInitializer();
- BreakStatement breakStatement = (BreakStatement) ((Block)se.statements().get(1)).statements().get(0);
- assertNull("Unexpected Non null label", breakStatement.getLabel());
- assertNotNull("Expression null", breakStatement.getExpression());
+ YieldStatement yieldStatement = (YieldStatement) ((Block)se.statements().get(1)).statements().get(0);
+ assertNotNull("Expression null", yieldStatement.getExpression());
}
} \ No newline at end of file

Back to the top