diff options
author | Sarika Sinha | 2020-07-20 10:08:26 +0000 |
---|---|---|
committer | Sarika Sinha | 2020-07-20 10:08:26 +0000 |
commit | 5ec82e1db51e4dad4e1919ccf24d701e57b610f0 (patch) | |
tree | 60ff616c7dbf3515e72909f47beec3cf38ea087d | |
parent | 3c9dec433efd25951176f08ec77f5c8f1773adf1 (diff) | |
download | eclipse.jdt.core-5ec82e1db51e4dad4e1919ccf24d701e57b610f0.tar.gz eclipse.jdt.core-5ec82e1db51e4dad4e1919ccf24d701e57b610f0.tar.xz eclipse.jdt.core-5ec82e1db51e4dad4e1919ccf24d701e57b610f0.zip |
Change-Id: I85cf67f6de61bb799349b3c1ab15e6394fc19661
2 files changed, 95 insertions, 5 deletions
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter_15Test.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter_15Test.java index 4357da4e42..c0b5ef76e6 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter_15Test.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter_15Test.java @@ -163,9 +163,8 @@ public class ASTConverter_15Test extends ConverterTestSetup { " }\n" + "\n" + " public X(int a) {\n" + - " this.param1 = 6;\n" + - " this.param2 = 16;\n" + - " a = 6;\n" + + " this(6,16);\n" + + " System.out.println(a);\n" + " }\n" + "}\n"; this.workingCopy = getWorkingCopy("/Converter_15/src/X.java", true/*resolve*/); @@ -361,6 +360,91 @@ public class ASTConverter_15Test extends ConverterTestSetup { } } + public void _testRecord008() throws CoreException { + if (!isJRE15) { + System.err.println("Test "+getName()+" requires a JRE 15"); + return; + } + String contents = "import java.lang.annotation.ElementType;\n" + + "import java.lang.annotation.Target;\n" + + "record X(@MyAnnot int lo) {\n" + + " public int lo() {\n" + + " return this.lo;\n" + + " }\n" + + "\n" + + "}\n" + + "@Target({ElementType.RECORD_COMPONENT})\n" + + "@interface MyAnnot {}"; + this.workingCopy = getWorkingCopy("/Converter_15/src/X.java", true/*resolve*/); + IJavaProject javaProject = this.workingCopy.getJavaProject(); + String old = javaProject.getOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, true); + try { + javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED); + javaProject.setOption(JavaCore.COMPILER_PB_REPORT_PREVIEW_FEATURES, JavaCore.IGNORE); + ASTNode node = buildAST( + contents, + this.workingCopy); + assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType()); + CompilationUnit compilationUnit = (CompilationUnit) node; + assertProblemsSize(compilationUnit, 0); + node = ((AbstractTypeDeclaration)compilationUnit.types().get(0)); + assertEquals("Not a Record Declaration", ASTNode.RECORD_DECLARATION, node.getNodeType()); + RecordDeclaration record = (RecordDeclaration)node; + List<SingleVariableDeclaration> recordComponents = record.recordComponents(); + assertEquals("There should be 1 record component", 1, recordComponents.size()); + SingleVariableDeclaration recordComponent = recordComponents.get(0); + assertEquals("Record component name should be lo","lo" , recordComponent.getName().toString()); + assertEquals("Record component type is int" , "int", recordComponent.getType().toString()); + IVariableBinding resolveBinding = recordComponent.resolveBinding(); + assertEquals("Record component binding" , true, resolveBinding.isRecordComponent()); + MarkerAnnotation annotation = (MarkerAnnotation)recordComponent.modifiers().get(0); + assertEquals("Record component annotation name should be MyAnnot","@MyAnnot" , annotation.toString()); + assertEquals("Record component binding should not have annotation",0 , resolveBinding.getAnnotations().length); + + + } finally { + javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old); + } + } + + public void _testRecord009() throws CoreException { + if (!isJRE15) { + System.err.println("Test "+getName()+" requires a JRE 15"); + return; + } + String contents = "import java.lang.annotation.ElementType;\n" + + "import java.lang.annotation.Target;\n" + + "record X(@MyAnnot int lo) {\n" + + " public static @MyAnnot int x;\n" + + " public int lo() {\n" + + " return this.lo;\n" + + " }\n" + + "\n" + + "}\n" + + "@Target({ElementType.RECORD_COMPONENT})\n" + + "@interface MyAnnot {}"; + this.workingCopy = getWorkingCopy("/Converter_15/src/X.java", true/*resolve*/); + IJavaProject javaProject = this.workingCopy.getJavaProject(); + String old = javaProject.getOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, true); + try { + javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED); + javaProject.setOption(JavaCore.COMPILER_PB_REPORT_PREVIEW_FEATURES, JavaCore.IGNORE); + ASTNode node = buildAST( + contents, + this.workingCopy); + assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType()); + CompilationUnit compilationUnit = (CompilationUnit) node; + assertProblemsSize(compilationUnit, 0); + node = ((AbstractTypeDeclaration)compilationUnit.types().get(0)); + assertEquals("Not a Record Declaration", ASTNode.RECORD_DECLARATION, node.getNodeType()); + //RecordDeclaration record = (RecordDeclaration)node; + // test for error + + } finally { + javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old); + } + } + public void testTextBlock001() throws JavaModelException { if (!isJRE15) { System.err.println("Test "+getName()+" requires a JRE 15"); diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/RunConverterTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/RunConverterTests.java index cde2ff5a19..0e9b411d14 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/RunConverterTests.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/RunConverterTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2019 IBM Corporation and others. + * Copyright (c) 2000, 2020 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -8,12 +8,17 @@ * * SPDX-License-Identifier: EPL-2.0 * + * This is an implementation of an early-draft specification developed under the Java + * Community Process (JCP) and is made available for testing and evaluation purposes + * only. The code is not compatible with any specification of the JCP. + * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ package org.eclipse.jdt.core.tests.dom; -import java.lang.reflect.*; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Arrays; @@ -53,6 +58,7 @@ public static Class[] getAllTestClasses() { ASTConverter18Test.class, ASTConverter9Test.class, ASTConverter14Test.class, + ASTConverter_15Test.class, }; } public static Test suite() { |