Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManoj Palat2020-01-07 05:50:29 +0000
committerManoj Palat2020-01-07 05:51:10 +0000
commitba481134be15d3d72d078f1809b466546ade7d0d (patch)
treea05629dd72b74810f43ffa5e3df55370ee9b990f
parentd17be6f2786df4c53f78eac09ef37efc6f9a0ddb (diff)
downloadeclipse.jdt.core-ba481134be15d3d72d078f1809b466546ade7d0d.tar.gz
eclipse.jdt.core-ba481134be15d3d72d078f1809b466546ade7d0d.tar.xz
eclipse.jdt.core-ba481134be15d3d72d078f1809b466546ade7d0d.zip
Bug 553567 - [14] Records - Flag error for Record ClassType
Change-Id: I0ee28b922a4c59b30df7002fb048a024d9d20868 Signed-off-by: Manoj Palat <manpalat@in.ibm.com>
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java4
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/RecordsRestrictedClassTest.java33
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/core/compiler/IProblem.java4
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ClassScope.java14
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ReferenceBinding.java8
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/TypeIds.java11
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java14
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties1
8 files changed, 81 insertions, 8 deletions
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java
index d735af5018..614b7b5881 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2019 IBM Corporation and others.
+ * Copyright (c) 2006, 2020 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -1243,6 +1243,7 @@ public void test011_problem_categories() {
expectedProblemAttributes.put("RecordCompactConstructorHasExplicitConstructorCall", new ProblemAttributes(CategorizedProblem.CAT_PREVIEW_RELATED));
expectedProblemAttributes.put("RecordNestedRecordInherentlyStatic", new ProblemAttributes(CategorizedProblem.CAT_PREVIEW_RELATED));
expectedProblemAttributes.put("RecordAccessorMethodShouldNotBeStatic", new ProblemAttributes(CategorizedProblem.CAT_PREVIEW_RELATED));
+ expectedProblemAttributes.put("RecordCannotExtendRecord", new ProblemAttributes(CategorizedProblem.CAT_PREVIEW_RELATED));
StringBuffer failures = new StringBuffer();
StringBuffer correctResult = new StringBuffer(70000);
Field[] fields = (iProblemClass = IProblem.class).getFields();
@@ -2253,6 +2254,7 @@ public void test012_compiler_problems_tuning() {
expectedProblemAttributes.put("RecordCompactConstructorHasExplicitConstructorCall", SKIP);
expectedProblemAttributes.put("RecordNestedRecordInherentlyStatic", SKIP);
expectedProblemAttributes.put("RecordAccessorMethodShouldNotBeStatic", SKIP);
+ expectedProblemAttributes.put("RecordCannotExtendRecord", SKIP);
Map constantNamesIndex = new HashMap();
Field[] fields = JavaCore.class.getFields();
for (int i = 0, length = fields.length; i < length; i++) {
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/RecordsRestrictedClassTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/RecordsRestrictedClassTest.java
index 3009ec9584..c52d84582f 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/RecordsRestrictedClassTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/RecordsRestrictedClassTest.java
@@ -33,7 +33,7 @@ public class RecordsRestrictedClassTest extends AbstractRegressionTest {
static {
// TESTS_NUMBERS = new int [] { 40 };
// TESTS_RANGE = new int[] { 1, -1 };
-// TESTS_NAMES = new String[] { "testBug550750_001" };
+// TESTS_NAMES = new String[] { "testBug553567" };
}
public static Class<?> testClass() {
@@ -1741,4 +1741,35 @@ public void testBug558764_004() {
"The annotation @MyAnnotation is disallowed for this location\n" +
"----------\n");
}
+public void testBug553567_001() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "class X extends Record{\n"+
+ " public static void main(String[] args){\n"+
+ " System.out.println(0);\n" +
+ " }\n"+
+ "}\n"
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 1)\n" +
+ " class X extends Record{\n" +
+ " ^^^^^^\n" +
+ "The type X may not subclass Record explicitly\n" +
+ "----------\n");
+}
+public void testBug553567_002() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "class X {\n"+
+ " public static void main(String[] args){\n"+
+ " System.out.println(0);\n" +
+ " }\n"+
+ "}\n" +
+ "class Record {\n"+
+ "}\n"
+ },
+ "0");
+}
} \ No newline at end of file
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/core/compiler/IProblem.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/core/compiler/IProblem.java
index d51e9046d1..1d1cf6752d 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/core/compiler/IProblem.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/core/compiler/IProblem.java
@@ -2293,7 +2293,9 @@ void setSourceStart(int sourceStart);
/** @since 3.20 BETA_JAVA14
* @noreference preview feature error */
int RecordAccessorMethodShouldNotBeStatic= PreviewRelated + 1751;
-
+ /** @since 3.20 BETA_JAVA14
+ * @noreference preview feature error */
+ int RecordCannotExtendRecord= PreviewRelated + 1752;
/* records - end */
/* Java14 errors - end */
}
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ClassScope.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ClassScope.java
index 34037e15be..20937e3244 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ClassScope.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ClassScope.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
@@ -46,7 +46,7 @@ import org.eclipse.jdt.internal.compiler.ast.ASTNode;
import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration;
import org.eclipse.jdt.internal.compiler.ast.AbstractVariableDeclaration;
import org.eclipse.jdt.internal.compiler.ast.FieldDeclaration;
-import org.eclipse.jdt.internal.compiler.ast.QualifiedAllocationExpression;
+import org.eclipse.jdt.internal.compiler.ast.QualifiedAllocationExpression;import org.eclipse.jdt.internal.compiler.ast.RecordDeclaration;
import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration;
import org.eclipse.jdt.internal.compiler.ast.TypeParameter;
import org.eclipse.jdt.internal.compiler.ast.TypeReference;
@@ -108,6 +108,12 @@ public class ClassScope extends Scope {
problemReporter().cannotExtendEnum(anonymousType, typeReference, supertype);
anonymousType.tagBits |= TagBits.HierarchyHasProblems;
anonymousType.setSuperClass(getJavaLangObject());
+ } else if (supertype.erasure().id == TypeIds.T_JavaLangRecord) {
+ if (!(this.referenceContext instanceof RecordDeclaration)) {
+ problemReporter().recordCannotExtendRecord(anonymousType, typeReference, supertype);
+ anonymousType.tagBits |= TagBits.HierarchyHasProblems;
+ anonymousType.setSuperClass(getJavaLangObject());
+ }
} else if (supertype.isFinal()) {
problemReporter().anonymousClassCannotExtendFinalClass(typeReference, supertype);
anonymousType.tagBits |= TagBits.HierarchyHasProblems;
@@ -998,6 +1004,10 @@ public class ClassScope extends Scope {
problemReporter().superTypeCannotUseWildcard(sourceType, superclassRef, superclass);
} else if (superclass.erasure().id == TypeIds.T_JavaLangEnum) {
problemReporter().cannotExtendEnum(sourceType, superclassRef, superclass);
+ } else if (superclass.erasure().id == TypeIds.T_JavaLangRecord) {
+ if (!(this.referenceContext instanceof RecordDeclaration)) {
+ problemReporter().recordCannotExtendRecord(sourceType, superclassRef, superclass);
+ }
} else if ((superclass.tagBits & TagBits.HierarchyHasProblems) != 0
|| !superclassRef.resolvedType.isValidBinding()) {
sourceType.setSuperClass(superclass);
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ReferenceBinding.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ReferenceBinding.java
index 98a822baae..f9aa45340a 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ReferenceBinding.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ReferenceBinding.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,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
@@ -702,6 +706,8 @@ public void computeId() {
case 'R' :
if (CharOperation.equals(typeName, TypeConstants.JAVA_LANG_RUNTIMEEXCEPTION[2]))
this.id = TypeIds.T_JavaLangRuntimeException;
+ if (CharOperation.equals(typeName, TypeConstants.JAVA_LANG_RECORD[2]))
+ this.id = TypeIds.T_JavaLangRecord;
break;
case 'S' :
switch (typeName.length) {
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/TypeIds.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/TypeIds.java
index 52c1428f80..dcabf0642b 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/TypeIds.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/TypeIds.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2018 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
@@ -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:
* IBM Corporation - initial API and implementation
* Stephan Herrmann - Contributions for
@@ -146,6 +150,9 @@ public interface TypeIds {
// @MethodSource
final int T_OrgJunitJupiterParamsProviderMethodSource = 93;
+ // Java 14 preview
+ final int T_JavaLangRecord = 93;
+
// If you add new type id, make sure to bump up T_LastWellKnownTypeId if there is a cross over.
final int T_LastWellKnownTypeId = 128;
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java
index c8d1426f9e..3e2d5f223c 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java
@@ -11594,4 +11594,18 @@ public void recordAccessorMethodShouldNotBeStatic(ASTNode methodDecl) {
methodDecl.sourceStart,
methodDecl.sourceEnd);
}
+public void recordCannotExtendRecord(SourceTypeBinding type, TypeReference superclass, TypeBinding superTypeBinding) {
+ if (!this.options.enablePreviewFeatures)
+ return;
+ String name = new String(type.sourceName());
+ String superTypeFullName = new String(superTypeBinding.readableName());
+ String superTypeShortName = new String(superTypeBinding.shortReadableName());
+ if (superTypeShortName.equals(name)) superTypeShortName = superTypeFullName;
+ this.handle(
+ IProblem.RecordCannotExtendRecord,
+ new String[] {superTypeFullName, name},
+ new String[] {superTypeShortName, name},
+ superclass.sourceStart,
+ superclass.sourceEnd);
+}
} \ No newline at end of file
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties
index ea09f18baa..5090c70970 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties
@@ -1044,6 +1044,7 @@
1749 = The body of a compact constructor must not contain an explicit constructor call
1750 = Nested Record is (implicitly) static and hence enclosing type should be static
1751 = The accessor method must not be static
+1752 = The type {1} may not subclass {0} explicitly
# Java 14 Preview - end

Back to the top