Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJay Arthanareeswaran2020-02-18 03:34:11 -0500
committerJay Arthanareeswaran2020-02-18 03:34:11 -0500
commit89f366a91c008f7ff476d2cde4a14dc21ddaf6fa (patch)
tree0a6bd309d09cde894335d9c7da947575011d029e
parentf8f67606ae10780ec62f44189f86b4bf1a166ba8 (diff)
downloadeclipse.jdt.core-89f366a91c008f7ff476d2cde4a14dc21ddaf6fa.tar.gz
eclipse.jdt.core-89f366a91c008f7ff476d2cde4a14dc21ddaf6fa.tar.xz
eclipse.jdt.core-89f366a91c008f7ff476d2cde4a14dc21ddaf6fa.zip
Bug 560260 - [14] Provide JSR 269 support for Java 14 featuresY20200218-1420Y20200218-1210
Change-Id: I2ba1bdbc3fd3cb05b9888efbc21d7cf62454b7e8 Signed-off-by: Jay Arthanareeswaran <jarthana@in.ibm.com>
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/.classpath2
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/META-INF/MANIFEST.MF2
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/build.properties4
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/lib/apttestprocessors8.jarbin267785 -> 278872 bytes
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/lib/java13api.jarbin111292 -> 0 bytes
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/lib/java14api.jarbin0 -> 110903 bytes
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/processors8/META-INF/services/javax.annotation.processing.Processor1
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/processors8/org/eclipse/jdt/compiler/apt/tests/processors/elements/Java14ElementProcessor.java362
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/records/mod.records/module-info.java3
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/records/mod.records/records/MyAnnot.java10
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/records/mod.records/records/Point.java6
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/Java14ElementsTests.java130
-rw-r--r--org.eclipse.jdt.compiler.apt/build.properties4
-rw-r--r--org.eclipse.jdt.compiler.apt/lib/java13api.jarbin111292 -> 0 bytes
-rw-r--r--org.eclipse.jdt.compiler.apt/lib/java14api.jarbin0 -> 110903 bytes
-rw-r--r--org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/model/Factory.java13
-rw-r--r--org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/model/RecordComponentElementImpl.java44
-rw-r--r--org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/model/TypeElementImpl.java40
-rw-r--r--org.eclipse.jdt.compiler.tool.tests/.classpath2
-rw-r--r--org.eclipse.jdt.compiler.tool.tests/build.properties6
-rw-r--r--org.eclipse.jdt.compiler.tool.tests/lib/java13api.jarbin111292 -> 0 bytes
-rw-r--r--org.eclipse.jdt.compiler.tool.tests/lib/java14api.jarbin0 -> 110903 bytes
-rw-r--r--org.eclipse.jdt.compiler.tool/.classpath2
-rw-r--r--org.eclipse.jdt.compiler.tool/META-INF/MANIFEST.MF2
-rw-r--r--org.eclipse.jdt.compiler.tool/build.properties6
-rw-r--r--org.eclipse.jdt.compiler.tool/lib/java13api.jarbin111292 -> 0 bytes
-rw-r--r--org.eclipse.jdt.compiler.tool/lib/java14api.jarbin0 -> 110903 bytes
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/BinaryTypeBinding.java8
28 files changed, 626 insertions, 21 deletions
diff --git a/org.eclipse.jdt.compiler.apt.tests/.classpath b/org.eclipse.jdt.compiler.apt.tests/.classpath
index 6d7726d275..b3e488f935 100644
--- a/org.eclipse.jdt.compiler.apt.tests/.classpath
+++ b/org.eclipse.jdt.compiler.apt.tests/.classpath
@@ -16,7 +16,7 @@
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
- <classpathentry kind="lib" path="lib/java13api.jar"/>
+ <classpathentry kind="lib" path="lib/java14api.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="output" path="bin"/>
</classpath>
diff --git a/org.eclipse.jdt.compiler.apt.tests/META-INF/MANIFEST.MF b/org.eclipse.jdt.compiler.apt.tests/META-INF/MANIFEST.MF
index c699a3e298..7e2da9e6a3 100644
--- a/org.eclipse.jdt.compiler.apt.tests/META-INF/MANIFEST.MF
+++ b/org.eclipse.jdt.compiler.apt.tests/META-INF/MANIFEST.MF
@@ -19,6 +19,6 @@ Export-Package: org.eclipse.jdt.compiler.apt.tests,
org.eclipse.jdt.compiler.apt.tests.processors.visitors
Import-Package: org.eclipse.jdt.internal.compiler.tool;resolution:=optional
Eclipse-BundleShape: dir
-Bundle-ClassPath: lib/java13api.jar,
+Bundle-ClassPath: lib/java14api.jar,
.
Automatic-Module-Name: org.eclipse.jdt.compiler.apt.tests
diff --git a/org.eclipse.jdt.compiler.apt.tests/build.properties b/org.eclipse.jdt.compiler.apt.tests/build.properties
index cddfe5d640..0f35ce6bb2 100644
--- a/org.eclipse.jdt.compiler.apt.tests/build.properties
+++ b/org.eclipse.jdt.compiler.apt.tests/build.properties
@@ -1,5 +1,5 @@
###############################################################################
-# Copyright (c) 2006, 2019 BEA Systems Inc. and others
+# Copyright (c) 2006, 2020 BEA Systems Inc. and others
#
# This program and the accompanying materials
# are made available under the terms of the Eclipse Public License 2.0
@@ -27,4 +27,4 @@ bin.includes = about.html,\
.
src.includes = about.html
compilerArg=-proc:none
-jars.extra.classpath = lib/java13api.jar
+jars.extra.classpath = lib/java14api.jar
diff --git a/org.eclipse.jdt.compiler.apt.tests/lib/apttestprocessors8.jar b/org.eclipse.jdt.compiler.apt.tests/lib/apttestprocessors8.jar
index 9cc48c8cac..f0c67485f8 100644
--- a/org.eclipse.jdt.compiler.apt.tests/lib/apttestprocessors8.jar
+++ b/org.eclipse.jdt.compiler.apt.tests/lib/apttestprocessors8.jar
Binary files differ
diff --git a/org.eclipse.jdt.compiler.apt.tests/lib/java13api.jar b/org.eclipse.jdt.compiler.apt.tests/lib/java13api.jar
deleted file mode 100644
index d8bbb8b501..0000000000
--- a/org.eclipse.jdt.compiler.apt.tests/lib/java13api.jar
+++ /dev/null
Binary files differ
diff --git a/org.eclipse.jdt.compiler.apt.tests/lib/java14api.jar b/org.eclipse.jdt.compiler.apt.tests/lib/java14api.jar
new file mode 100644
index 0000000000..fcf9985dae
--- /dev/null
+++ b/org.eclipse.jdt.compiler.apt.tests/lib/java14api.jar
Binary files differ
diff --git a/org.eclipse.jdt.compiler.apt.tests/processors8/META-INF/services/javax.annotation.processing.Processor b/org.eclipse.jdt.compiler.apt.tests/processors8/META-INF/services/javax.annotation.processing.Processor
index da24c14493..8f85647c93 100644
--- a/org.eclipse.jdt.compiler.apt.tests/processors8/META-INF/services/javax.annotation.processing.Processor
+++ b/org.eclipse.jdt.compiler.apt.tests/processors8/META-INF/services/javax.annotation.processing.Processor
@@ -3,3 +3,4 @@ org.eclipse.jdt.compiler.apt.tests.processors.elements.Java9ElementProcessor
org.eclipse.jdt.compiler.apt.tests.processors.elements.Java11ElementProcessor
org.eclipse.jdt.compiler.apt.tests.processors.elements.Java12ElementProcessor
org.eclipse.jdt.compiler.apt.tests.processors.elements.Java13ElementProcessor
+org.eclipse.jdt.compiler.apt.tests.processors.elements.Java14ElementProcessor
diff --git a/org.eclipse.jdt.compiler.apt.tests/processors8/org/eclipse/jdt/compiler/apt/tests/processors/elements/Java14ElementProcessor.java b/org.eclipse.jdt.compiler.apt.tests/processors8/org/eclipse/jdt/compiler/apt/tests/processors/elements/Java14ElementProcessor.java
new file mode 100644
index 0000000000..94e37de2b5
--- /dev/null
+++ b/org.eclipse.jdt.compiler.apt.tests/processors8/org/eclipse/jdt/compiler/apt/tests/processors/elements/Java14ElementProcessor.java
@@ -0,0 +1,362 @@
+/*******************************************************************************
+ * Copyright (c) 2020 IBM Corporation.
+ *
+ * This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * 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.compiler.apt.tests.processors.elements;
+
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.annotation.processing.Filer;
+import javax.annotation.processing.Messager;
+import javax.annotation.processing.ProcessingEnvironment;
+import javax.annotation.processing.RoundEnvironment;
+import javax.annotation.processing.SupportedAnnotationTypes;
+import javax.lang.model.AnnotatedConstruct;
+import javax.lang.model.element.AnnotationMirror;
+import javax.lang.model.element.AnnotationValue;
+import javax.lang.model.element.Element;
+import javax.lang.model.element.ElementKind;
+import javax.lang.model.element.ExecutableElement;
+import javax.lang.model.element.Modifier;
+import javax.lang.model.element.ModuleElement;
+import javax.lang.model.element.PackageElement;
+import javax.lang.model.element.RecordComponentElement;
+import javax.lang.model.element.TypeElement;
+import javax.lang.model.type.DeclaredType;
+import javax.lang.model.util.ElementFilter;
+
+import org.eclipse.jdt.internal.compiler.apt.dispatch.BaseProcessingEnvImpl;
+import org.eclipse.jdt.compiler.apt.tests.processors.base.BaseProcessor;
+
+@SupportedAnnotationTypes("*")
+public class Java14ElementProcessor extends BaseProcessor {
+ boolean reportSuccessAlready = true;
+ RoundEnvironment roundEnv = null;
+ Messager _messager = null;
+ Filer _filer = null;
+ boolean isBinaryMode = false;
+ String mode;
+ @Override
+ public synchronized void init(ProcessingEnvironment processingEnv) {
+ super.init(processingEnv);
+ _elementUtils = processingEnv.getElementUtils();
+ _messager = processingEnv.getMessager();
+ _filer = processingEnv.getFiler();
+ }
+ // Always return false from this processor, because it supports "*".
+ // The return value does not signify success or failure!
+ @Override
+ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
+ if (roundEnv.processingOver()) {
+ return false;
+ }
+
+ this.roundEnv = roundEnv;
+ Map<String, String> options = processingEnv.getOptions();
+ if (!options.containsKey(this.getClass().getName())) {
+ // Disable this processor unless we are intentionally performing the test.
+ return false;
+ } else {
+ try {
+ if (options.containsKey("binary")) {
+ this.isBinaryMode = true;
+ this.mode = "binary";
+ } else {
+ this.mode = "source";
+ }
+ if (!invokeTestMethods(options)) {
+ testAll();
+ }
+ if (this.reportSuccessAlready) {
+ super.reportSuccess();
+ }
+ } catch (AssertionFailedError e) {
+ super.reportError(getExceptionStackTrace(e));
+ } catch (Throwable e) {
+ e.printStackTrace();
+ }
+ }
+ return false;
+ }
+
+ private boolean invokeTestMethods(Map<String, String> options) throws Throwable {
+ Method testMethod = null;
+ Set<String> keys = options.keySet();
+ boolean testsFound = false;
+ for (String option : keys) {
+ if (option.startsWith("test")) {
+ try {
+ testMethod = this.getClass().getDeclaredMethod(option, new Class[0]);
+ if (testMethod != null) {
+ testsFound = true;
+ testMethod.invoke(this, new Object[0]);
+ }
+ } catch (InvocationTargetException e) {
+ throw e.getCause();
+ } catch (Exception e) {
+ super.reportError(getExceptionStackTrace(e));
+ }
+ }
+ }
+ return testsFound;
+ }
+
+ public void testAll() throws AssertionFailedError, IOException {
+ testPreviewFlagTrue();
+ }
+
+ public void testPreviewFlagTrue() throws IOException {
+ if (this.processingEnv instanceof BaseProcessingEnvImpl) {
+ boolean preview = ((BaseProcessingEnvImpl) this.processingEnv).isPreviewEnabled();
+ assertTrue("Preview flag not seen as enabled", preview);
+ }
+ }
+ /*
+ * Basic test for record element and kind
+ */
+ public void testRecords1() {
+ Set<? extends Element> elements = roundEnv.getRootElements();
+ TypeElement record = null;
+ for (Element element : elements) {
+ if ("Point".equals(element.getSimpleName().toString())) {
+ record = (TypeElement) element;
+ }
+ }
+ assertNotNull("TypeElement for record should not be null", record);
+ assertEquals("Name for record should not be null", "records.Point", record.getQualifiedName().toString());
+ assertEquals("Incorrect element kind", ElementKind.RECORD, record.getKind());
+ }
+ /*
+ * Test for presence of record component in a record element
+ */
+ public void testRecords2() {
+ Set<? extends Element> elements = roundEnv.getRootElements();
+ TypeElement record = null;
+ for (Element element : elements) {
+ if ("Point".equals(element.getSimpleName().toString())) {
+ record = (TypeElement) element;
+ }
+ }
+ assertNotNull("TypeElement for record should not be null", record);
+ List<? extends Element> enclosedElements = record.getEnclosedElements();
+ assertNotNull("enclosedElements for record should not be null", enclosedElements);
+ List<RecordComponentElement> recordComponentsIn = ElementFilter.recordComponentsIn(enclosedElements);
+ int size = recordComponentsIn.size();
+ assertEquals("incorrect no of record components", 1, size);
+ Element element = enclosedElements.get(0);
+ assertEquals("Incorrect kind of element", ElementKind.RECORD_COMPONENT, element.getKind());
+ RecordComponentElement recordComponent = (RecordComponentElement) element;
+ assertEquals("Incorrect name for record component", "comp_", recordComponent.getSimpleName().toString());
+ Element enclosingElement = recordComponent.getEnclosingElement();
+ assertEquals("Elements should be same", record, enclosingElement);
+ }
+ /*
+ * Test that the implicit modifiers are set for a record
+ */
+ public void testRecords3() {
+ Set<? extends Element> elements = roundEnv.getRootElements();
+ TypeElement record = null;
+ for (Element element : elements) {
+ if ("Point".equals(element.getSimpleName().toString())) {
+ record = (TypeElement) element;
+ }
+ }
+ assertNotNull("TypeElement for record should not be null", record);
+ Set<Modifier> modifiers = record.getModifiers();
+ assertTrue("record should be public", modifiers.contains(Modifier.PUBLIC));
+ assertTrue("record should be final", modifiers.contains(Modifier.FINAL));
+ }
+ /*
+ * Test for annotations on record and record components
+ */
+ public void testRecords4() {
+ Set<? extends Element> elements = roundEnv.getRootElements();
+ System.out.println(elements);
+ TypeElement record = null;
+ for (Element element : elements) {
+ if ("Point".equals(element.getSimpleName().toString())) {
+ record = (TypeElement) element;
+ }
+ }
+ assertNotNull("TypeElement for record should not be null", record);
+ verifyAnnotations(record, new String[]{"@Deprecated()"});
+
+ List<? extends Element> enclosedElements = record.getEnclosedElements();
+ assertNotNull("enclosedElements for record should not be null", enclosedElements);
+ List<RecordComponentElement> recordComponentsIn = ElementFilter.recordComponentsIn(enclosedElements);
+ int size = recordComponentsIn.size();
+ assertEquals("incorrect no of record components", 1, size);
+ Element element = enclosedElements.get(0);
+ assertEquals("Incorrect kind of element", ElementKind.RECORD_COMPONENT, element.getKind());
+ RecordComponentElement recordComponent = (RecordComponentElement) element;
+
+ verifyAnnotations(recordComponent, new String[]{"@MyAnnot()"});
+ }
+ /*
+ * Test for getAccessor of a record component
+ */
+ public void testRecords5() {
+ // This is not yet implemented.
+ }
+
+ @Override
+ public void reportError(String msg) {
+ throw new AssertionFailedError(msg);
+ }
+ private String getExceptionStackTrace(Throwable t) {
+ StringBuffer buf = new StringBuffer(t.getMessage());
+ StackTraceElement[] traces = t.getStackTrace();
+ for (int i = 0; i < traces.length; i++) {
+ StackTraceElement trace = traces[i];
+ buf.append("\n\tat " + trace);
+ if (i == 12)
+ break; // Don't dump all stacks
+ }
+ return buf.toString();
+ }
+ protected String getElementsAsString(List<? extends Element> list) {
+ StringBuilder builder = new StringBuilder("[");
+ for (Element element : list) {
+ if (element instanceof PackageElement) {
+ builder.append(((PackageElement) element).getQualifiedName());
+ } else if (element instanceof ModuleElement) {
+ builder.append(((ModuleElement) element).getQualifiedName());
+ } else if (element instanceof TypeElement) {
+ builder.append(((TypeElement) element).getQualifiedName());
+ } else {
+ builder.append(element.getSimpleName());
+ }
+ builder.append(", ");
+ }
+ builder.append("]");
+ return builder.toString();
+ }
+ public void assertModifiers(Set<Modifier> modifiers, String[] expected) {
+ assertEquals("Incorrect no of modifiers", modifiers.size(), expected.length);
+ Set<String> actual = new HashSet<String>(expected.length);
+ for (Modifier modifier : modifiers) {
+ actual.add(modifier.toString());
+ }
+ for(int i = 0, length = expected.length; i < length; i++) {
+ boolean result = actual.remove(expected[i]);
+ if (!result) reportError("Modifier not present :" + expected[i]);
+ }
+ if (!actual.isEmpty()) {
+ reportError("Unexpected modifiers present:" + actual.toString());
+ }
+ }
+ public void assertTrue(String msg, boolean value) {
+ if (!value) reportError(msg);
+ }
+ public void assertFalse(String msg, boolean value) {
+ if (value) reportError(msg);
+ }
+ public void assertSame(String msg, Object obj1, Object obj2) {
+ if (obj1 != obj2) {
+ reportError(msg + ", should be " + obj1.toString() + " but " + obj2.toString());
+ }
+ }
+ public void assertNotSame(String msg, Object obj1, Object obj2) {
+ if (obj1 == obj2) {
+ reportError(msg + ", " + obj1.toString() + " should not be same as " + obj2.toString());
+ }
+ }
+ public void assertNotNull(String msg, Object obj) {
+ if (obj == null) {
+ reportError(msg);
+ }
+ }
+ public void assertNull(String msg, Object obj) {
+ if (obj != null) {
+ reportError(msg);
+ }
+ }
+ public void assertEquals(String message, Object expected, Object actual) {
+ if (equalsRegardingNull(expected, actual)) {
+ return;
+ } else {
+ reportError(message + ", expected " + expected.toString() + " but was " + actual.toString());
+ }
+ }
+
+ public void assertEquals(String message, Object expected, Object alternateExpected, Object actual) {
+ if (equalsRegardingNull(expected, actual) || equalsRegardingNull(alternateExpected, actual)) {
+ return;
+ } else {
+ reportError(message + ", expected " + expected.toString() + " but was " + actual.toString());
+ }
+ }
+
+ static boolean equalsRegardingNull(Object expected, Object actual) {
+ if (expected == null) {
+ return actual == null;
+ }
+ return expected.equals(actual);
+ }
+
+ public void assertEquals(String msg, int expected, int actual) {
+ if (expected != actual) {
+ StringBuffer buf = new StringBuffer();
+ buf.append(msg);
+ buf.append(", expected " + expected + " but was " + actual);
+ reportError(buf.toString());
+ }
+ }
+ public void assertEquals(Object expected, Object actual) {
+ if (expected != actual) {
+
+ }
+ }
+ private void verifyAnnotations(AnnotatedConstruct construct, String[] annots) {
+ List<? extends AnnotationMirror> annotations = construct.getAnnotationMirrors();
+ assertEquals("Incorrect no of annotations", annots.length, annotations.size());
+ for(int i = 0, length = annots.length; i < length; i++) {
+ AnnotationMirror mirror = annotations.get(i);
+ assertEquals("Invalid annotation value", annots[i], getAnnotationString(mirror));
+ }
+ }
+
+ private String getAnnotationString(AnnotationMirror annot) {
+ DeclaredType annotType = annot.getAnnotationType();
+ TypeElement type = (TypeElement) annotType.asElement();
+ StringBuffer buf = new StringBuffer("@" + type.getSimpleName());
+ Map<? extends ExecutableElement, ? extends AnnotationValue> values = annot.getElementValues();
+ Set<? extends ExecutableElement> keys = values.keySet();
+ buf.append('(');
+ for (ExecutableElement executableElement : keys) { // @Marker3()
+ buf.append(executableElement.getSimpleName());
+ buf.append('=');
+ AnnotationValue value = values.get(executableElement);
+ buf.append(value.getValue());
+ }
+ buf.append(')');
+ return buf.toString();
+ }
+ private class AssertionFailedError extends Error {
+ private static final long serialVersionUID = 1L;
+
+ public AssertionFailedError(String msg) {
+ super(msg);
+ }
+ }
+}
diff --git a/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/records/mod.records/module-info.java b/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/records/mod.records/module-info.java
new file mode 100644
index 0000000000..c61e6d99e3
--- /dev/null
+++ b/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/records/mod.records/module-info.java
@@ -0,0 +1,3 @@
+module mod.records {
+}
+
diff --git a/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/records/mod.records/records/MyAnnot.java b/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/records/mod.records/records/MyAnnot.java
new file mode 100644
index 0000000000..e7b47bcb68
--- /dev/null
+++ b/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/records/mod.records/records/MyAnnot.java
@@ -0,0 +1,10 @@
+package records;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Target({ElementType.FIELD, ElementType.TYPE})
+@Retention(RetentionPolicy.RUNTIME)
+@interface MyAnnot {} \ No newline at end of file
diff --git a/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/records/mod.records/records/Point.java b/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/records/mod.records/records/Point.java
new file mode 100644
index 0000000000..cf6880b412
--- /dev/null
+++ b/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/records/mod.records/records/Point.java
@@ -0,0 +1,6 @@
+package records;
+@Deprecated
+public record Point(@MyAnnot int comp_) {
+ public Point {
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/Java14ElementsTests.java b/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/Java14ElementsTests.java
new file mode 100644
index 0000000000..3898287508
--- /dev/null
+++ b/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/Java14ElementsTests.java
@@ -0,0 +1,130 @@
+/*******************************************************************************
+ * Copyright (c) 2020 IBM Corporation.
+ *
+ * This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * 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.compiler.apt.tests;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.lang.model.SourceVersion;
+import javax.tools.JavaCompiler;
+import javax.tools.ToolProvider;
+
+import org.eclipse.jdt.internal.compiler.tool.EclipseCompiler;
+
+import junit.framework.TestCase;
+
+public class Java14ElementsTests extends TestCase {
+ private static final String MODULE_PROC = "org.eclipse.jdt.compiler.apt.tests.processors.elements.Java14ElementProcessor";
+
+ public void testPreviewFlagTrue() throws IOException {
+ JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
+ internalTestWithPreview(compiler, MODULE_PROC, "14", "testPreviewFlagTrue", null, "records", true);
+ }
+ public void testRecords1() throws IOException {
+ JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
+ internalTestWithPreview(compiler, MODULE_PROC, "14", "testRecords1", null, "records", true);
+ }
+ public void testRecords1Javac() throws Exception {
+ JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
+ internalTestWithPreview(compiler, MODULE_PROC, "14", "testRecords1", null, "records", true);
+ }
+ public void testRecords2() throws IOException {
+ JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
+ internalTestWithPreview(compiler, MODULE_PROC, "14", "testRecords2", null, "records", true);
+ }
+ public void _testRecords2Javac() throws Exception {
+ JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
+ internalTestWithPreview(compiler, MODULE_PROC, "14", "testRecords2", null, "records", true);
+ }
+ public void testRecords3() throws IOException {
+ JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
+ internalTestWithPreview(compiler, MODULE_PROC, "14", "testRecords3", null, "records", true);
+ }
+ public void testRecords3Javac() throws Exception {
+ JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
+ internalTestWithPreview(compiler, MODULE_PROC, "14", "testRecords3", null, "records", true);
+ }
+ public void testRecords4() throws IOException {
+ JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
+ internalTestWithPreview(compiler, MODULE_PROC, "14", "testRecords4", null, "records", true);
+ }
+ public void _testRecords4Javac() throws Exception {
+ JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
+ internalTestWithPreview(compiler, MODULE_PROC, "14", "testRecords4", null, "records", true);
+ }
+
+ protected void internalTestWithPreview(JavaCompiler compiler, String processor, String compliance,
+ String testMethod, String testClass, String resourceArea, boolean preview) throws IOException {
+ if (!canRunJava14()) {
+ return;
+ }
+ System.clearProperty(processor);
+ File targetFolder = TestUtils.concatPath(BatchTestUtils.getSrcFolderName(), "mod_locations", resourceArea);
+ if (testClass == null || testClass.equals("")) {
+ BatchTestUtils.copyResources("mod_locations/" + resourceArea, targetFolder);
+ } else {
+ BatchTestUtils.copyResource("mod_locations/" + resourceArea + "/" + testClass, targetFolder);
+ }
+
+ List<String> options = new ArrayList<String>();
+ options.add("-A" + processor);
+ options.add("-A" + testMethod);
+ options.add("-processor");
+ options.add(processor);
+ if (compiler instanceof EclipseCompiler) {
+ options.add("-" + compliance);
+ } else {
+ options.add("-source");
+ options.add(compliance);
+ }
+ if (preview)
+ options.add("--enable-preview");
+ BatchTestUtils.compileInModuleMode(compiler, options, processor, targetFolder, null, true, true);
+ // If it succeeded, the processor will have set this property to "succeeded";
+ // if not, it will set it to an error value.
+ assertEquals("succeeded", System.getProperty(processor));
+ }
+ public boolean canRunJava14() {
+ try {
+ SourceVersion.valueOf("RELEASE_14");
+ } catch(IllegalArgumentException iae) {
+ return false;
+ }
+ return true;
+ }
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#setUp()
+ */
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ BatchTestUtils.init();
+ }
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#tearDown()
+ */
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+} \ No newline at end of file
diff --git a/org.eclipse.jdt.compiler.apt/build.properties b/org.eclipse.jdt.compiler.apt/build.properties
index 6b49b018ed..13410ff307 100644
--- a/org.eclipse.jdt.compiler.apt/build.properties
+++ b/org.eclipse.jdt.compiler.apt/build.properties
@@ -1,5 +1,5 @@
###############################################################################
-# Copyright (c) 2005, 2019 IBM Corporation and others.
+# Copyright (c) 2005, 2020 IBM Corporation and others.
#
# This program and the accompanying materials
# are made available under the terms of the Eclipse Public License 2.0
@@ -22,4 +22,4 @@ jars.compile.order = .
output.. = bin/
source.. = src/
-jars.extra.classpath = lib/java13api.jar
+jars.extra.classpath = lib/java14api.jar
diff --git a/org.eclipse.jdt.compiler.apt/lib/java13api.jar b/org.eclipse.jdt.compiler.apt/lib/java13api.jar
deleted file mode 100644
index d8bbb8b501..0000000000
--- a/org.eclipse.jdt.compiler.apt/lib/java13api.jar
+++ /dev/null
Binary files differ
diff --git a/org.eclipse.jdt.compiler.apt/lib/java14api.jar b/org.eclipse.jdt.compiler.apt/lib/java14api.jar
new file mode 100644
index 0000000000..fcf9985dae
--- /dev/null
+++ b/org.eclipse.jdt.compiler.apt/lib/java14api.jar
Binary files differ
diff --git a/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/model/Factory.java b/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/model/Factory.java
index 8ea41f0242..23720dc569 100644
--- a/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/model/Factory.java
+++ b/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/model/Factory.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2017 BEA Systems, Inc. and others
+ * Copyright (c) 2007, 2020 BEA Systems, Inc. and others
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -7,7 +7,11 @@
* https://www.eclipse.org/legal/epl-2.0/
*
* 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:
* wharley@bea.com - initial API and implementation
* IBM Corporation - fix for 342598
@@ -47,6 +51,7 @@ import org.eclipse.jdt.internal.compiler.lookup.BaseTypeBinding;
import org.eclipse.jdt.internal.compiler.lookup.Binding;
import org.eclipse.jdt.internal.compiler.lookup.ElementValuePair;
import org.eclipse.jdt.internal.compiler.lookup.ExtraCompilerModifiers;
+import org.eclipse.jdt.internal.compiler.lookup.FieldBinding;
import org.eclipse.jdt.internal.compiler.lookup.MethodBinding;
import org.eclipse.jdt.internal.compiler.lookup.ModuleBinding;
import org.eclipse.jdt.internal.compiler.lookup.PackageBinding;
@@ -312,6 +317,7 @@ public class Factory {
case ANNOTATION_TYPE :
case INTERFACE :
case CLASS :
+ case RECORD :
// for type
decodeModifiers(result, modifiers, new int[] {
ClassFileConstants.AccPublic,
@@ -347,6 +353,9 @@ public class Factory {
return null;
switch (binding.kind()) {
case Binding.FIELD:
+ if (((FieldBinding) binding).isRecordComponent()) {
+ return new RecordComponentElementImpl(_env, (FieldBinding) binding);
+ }
case Binding.LOCAL:
case Binding.VARIABLE:
return new VariableElementImpl(_env, (VariableBinding) binding);
diff --git a/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/model/RecordComponentElementImpl.java b/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/model/RecordComponentElementImpl.java
new file mode 100644
index 0000000000..2aade6ff4e
--- /dev/null
+++ b/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/model/RecordComponentElementImpl.java
@@ -0,0 +1,44 @@
+/*******************************************************************************
+ * Copyright (c) 2020 IBM Corporation.
+ *
+ * This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * 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.internal.compiler.apt.model;
+
+import javax.lang.model.element.ElementKind;
+import javax.lang.model.element.ExecutableElement;
+import javax.lang.model.element.RecordComponentElement;
+
+import org.eclipse.jdt.internal.compiler.apt.dispatch.BaseProcessingEnvImpl;
+import org.eclipse.jdt.internal.compiler.lookup.FieldBinding;
+
+public class RecordComponentElementImpl extends VariableElementImpl implements RecordComponentElement {
+
+ protected RecordComponentElementImpl(BaseProcessingEnvImpl env, FieldBinding binding) {
+ super(env, binding);
+ }
+
+ @Override
+ public ElementKind getKind() {
+ return ElementKind.RECORD_COMPONENT;
+ }
+
+ @Override
+ public ExecutableElement getAccessor() {
+ // TODO: Looks like no direct way of accessing the synthetic directly from the field binding.
+ return null;
+ }
+}
diff --git a/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/model/TypeElementImpl.java b/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/model/TypeElementImpl.java
index 8a8afde554..58d08c8613 100644
--- a/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/model/TypeElementImpl.java
+++ b/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/model/TypeElementImpl.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2017 IBM Corporation and others.
+ * Copyright (c) 2005, 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,6 +8,10 @@
*
* 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
*******************************************************************************/
@@ -29,6 +33,7 @@ import javax.lang.model.element.Modifier;
import javax.lang.model.element.Name;
import javax.lang.model.element.NestingKind;
import javax.lang.model.element.PackageElement;
+import javax.lang.model.element.RecordComponentElement;
import javax.lang.model.element.TypeElement;
import javax.lang.model.element.TypeParameterElement;
import javax.lang.model.element.VariableElement;
@@ -155,9 +160,14 @@ public class TypeElementImpl extends ElementImpl implements TypeElement {
}
for (FieldBinding field : binding.fields()) {
// TODO no field should be excluded according to the JLS
- if (!field.isSynthetic()) {
- VariableElement variable = new VariableElementImpl(_env, field);
- enclosed.add(variable);
+ if (binding.isRecord()) {
+ RecordComponentElement rec = new RecordComponentElementImpl(_env, field);
+ enclosed.add(rec);
+ } else {
+ if (!field.isSynthetic()) {
+ VariableElement variable = new VariableElementImpl(_env, field);
+ enclosed.add(variable);
+ }
}
}
for (ReferenceBinding memberType : binding.memberTypes()) {
@@ -171,6 +181,25 @@ public class TypeElementImpl extends ElementImpl implements TypeElement {
}
@Override
+ public List<? extends RecordComponentElement> getRecordComponents() {
+ if (_binding instanceof SourceTypeBinding) {
+ SourceTypeBinding binding = (SourceTypeBinding) _binding;
+ FieldBinding[] components = ((SourceTypeBinding) _binding).getRecordComponents();
+ List<RecordComponentElement> enclosed = new ArrayList<>(components.length);
+ for (FieldBinding field : binding.fields()) {
+ if (!field.isSynthetic()) {
+ RecordComponentElement variable = new RecordComponentElementImpl(_env, field);
+ enclosed.add(variable);
+ }
+ }
+ Collections.sort(enclosed, new SourceLocationComparator());
+ return Collections.unmodifiableList(enclosed);
+ }
+ // TODO: Add code for BinaryTypeBinding, which, as of now doesn't seem to contain components
+ return Collections.emptyList();
+ }
+
+ @Override
public Element getEnclosingElement() {
ReferenceBinding binding = (ReferenceBinding)_binding;
ReferenceBinding enclosingType = binding.enclosingType();
@@ -222,6 +251,9 @@ public class TypeElementImpl extends ElementImpl implements TypeElement {
if (refBinding.isEnum()) {
return ElementKind.ENUM;
}
+ else if (refBinding.isRecord()) {
+ return ElementKind.RECORD;
+ }
else if (refBinding.isAnnotationType()) {
return ElementKind.ANNOTATION_TYPE;
}
diff --git a/org.eclipse.jdt.compiler.tool.tests/.classpath b/org.eclipse.jdt.compiler.tool.tests/.classpath
index 1aaf22970c..64151d68fb 100644
--- a/org.eclipse.jdt.compiler.tool.tests/.classpath
+++ b/org.eclipse.jdt.compiler.tool.tests/.classpath
@@ -6,7 +6,7 @@
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
- <classpathentry kind="lib" path="lib/java13api.jar"/>
+ <classpathentry kind="lib" path="lib/java14api.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="output" path="bin"/>
</classpath>
diff --git a/org.eclipse.jdt.compiler.tool.tests/build.properties b/org.eclipse.jdt.compiler.tool.tests/build.properties
index e40bb4927f..1d7f36b531 100644
--- a/org.eclipse.jdt.compiler.tool.tests/build.properties
+++ b/org.eclipse.jdt.compiler.tool.tests/build.properties
@@ -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
@@ -16,9 +16,9 @@ bin.includes = META-INF/,\
about.html,\
plugin.properties,\
test.xml,\
- lib/java13api.jar,\
+ lib/java14api.jar,\
resources/
src.includes = about.html
source.. = src/
output.. = bin/
-jars.extra.classpath = lib/java13api.jar
+jars.extra.classpath = lib/java14api.jar
diff --git a/org.eclipse.jdt.compiler.tool.tests/lib/java13api.jar b/org.eclipse.jdt.compiler.tool.tests/lib/java13api.jar
deleted file mode 100644
index d8bbb8b501..0000000000
--- a/org.eclipse.jdt.compiler.tool.tests/lib/java13api.jar
+++ /dev/null
Binary files differ
diff --git a/org.eclipse.jdt.compiler.tool.tests/lib/java14api.jar b/org.eclipse.jdt.compiler.tool.tests/lib/java14api.jar
new file mode 100644
index 0000000000..fcf9985dae
--- /dev/null
+++ b/org.eclipse.jdt.compiler.tool.tests/lib/java14api.jar
Binary files differ
diff --git a/org.eclipse.jdt.compiler.tool/.classpath b/org.eclipse.jdt.compiler.tool/.classpath
index 59c1bb0063..e71451ab4d 100644
--- a/org.eclipse.jdt.compiler.tool/.classpath
+++ b/org.eclipse.jdt.compiler.tool/.classpath
@@ -2,7 +2,7 @@
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
- <classpathentry kind="lib" path="lib/java13api.jar"/>
+ <classpathentry kind="lib" path="lib/java14api.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="output" path="bin"/>
</classpath>
diff --git a/org.eclipse.jdt.compiler.tool/META-INF/MANIFEST.MF b/org.eclipse.jdt.compiler.tool/META-INF/MANIFEST.MF
index aaf5da7abf..6d32b4cbf4 100644
--- a/org.eclipse.jdt.compiler.tool/META-INF/MANIFEST.MF
+++ b/org.eclipse.jdt.compiler.tool/META-INF/MANIFEST.MF
@@ -9,6 +9,6 @@ Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Export-Package: META-INF.services,
org.eclipse.jdt.internal.compiler.tool;x-internal:=true
Fragment-Host: org.eclipse.jdt.core;bundle-version="[3.3.0,4.0.0)"
-Bundle-ClassPath: lib/java13api.jar,
+Bundle-ClassPath: lib/java14api.jar,
.
Automatic-Module-Name: org.eclipse.jdt.compiler.tool
diff --git a/org.eclipse.jdt.compiler.tool/build.properties b/org.eclipse.jdt.compiler.tool/build.properties
index 42961c2cfe..862d4e462a 100644
--- a/org.eclipse.jdt.compiler.tool/build.properties
+++ b/org.eclipse.jdt.compiler.tool/build.properties
@@ -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
@@ -18,6 +18,6 @@ bin.includes = META-INF/,\
.,\
about.html,\
compiler_tool_fragment.properties,\
- lib/java13api.jar
+ lib/java14api.jar
src.includes = about.html
-jars.extra.classpath = lib/java13api.jar \ No newline at end of file
+jars.extra.classpath = lib/java14api.jar \ No newline at end of file
diff --git a/org.eclipse.jdt.compiler.tool/lib/java13api.jar b/org.eclipse.jdt.compiler.tool/lib/java13api.jar
deleted file mode 100644
index d8bbb8b501..0000000000
--- a/org.eclipse.jdt.compiler.tool/lib/java13api.jar
+++ /dev/null
Binary files differ
diff --git a/org.eclipse.jdt.compiler.tool/lib/java14api.jar b/org.eclipse.jdt.compiler.tool/lib/java14api.jar
new file mode 100644
index 0000000000..fcf9985dae
--- /dev/null
+++ b/org.eclipse.jdt.compiler.tool/lib/java14api.jar
Binary files differ
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/BinaryTypeBinding.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/BinaryTypeBinding.java
index 8c8c8c47b3..e80bd6da4c 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/BinaryTypeBinding.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/BinaryTypeBinding.java
@@ -8,6 +8,10 @@
*
* 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
* Stephan Herrmann - Contributions for
@@ -1624,6 +1628,10 @@ public TypeBinding prototype() {
private boolean isPrototype() {
return this == this.prototype; //$IDENTITY-COMPARISON$
}
+@Override
+public boolean isRecord() {
+ return (this.modifiers & ExtraCompilerModifiers.AccRecord) != 0;
+}
@Override
public ReferenceBinding containerAnnotationType() {

Back to the top