diff options
author | Manoj Palat | 2020-06-22 13:48:40 +0000 |
---|---|---|
committer | Manoj Palat | 2020-06-22 23:22:40 +0000 |
commit | fe860ad50bfd5103e0c6159d156ae80b61c653f2 (patch) | |
tree | 47ae0dba7236c21212b4573b9a8ddd5d9e2a5959 /org.eclipse.jdt.core/compiler/org/eclipse/jdt | |
parent | ed1bda7127708d490d0583e98e1caa793f784c0b (diff) | |
download | eclipse.jdt.core-fe860ad50bfd5103e0c6159d156ae80b61c653f2.tar.gz eclipse.jdt.core-fe860ad50bfd5103e0c6159d156ae80b61c653f2.tar.xz eclipse.jdt.core-fe860ad50bfd5103e0c6159d156ae80b61c653f2.zip |
Change-Id: Iceec8a50b2f48d21001a4bd71923507b93c9d63e
Signed-off-by: Manoj Palat <manpalat@in.ibm.com>
Diffstat (limited to 'org.eclipse.jdt.core/compiler/org/eclipse/jdt')
5 files changed, 29 insertions, 20 deletions
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 7342897473..285f81b738 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 @@ -2279,7 +2279,7 @@ void setSourceStart(int sourceStart); int RecordCanonicalConstructorHasThrowsClause = PreviewRelated + 1735; /** @since 3.22 * @noreference preview feature error */ - int RecordCanonicalConstructorShouldBePublic = PreviewRelated + 1736; + int RecordCanonicalConstructorVisibilityReduced = PreviewRelated + 1736; /** @since 3.22 * @noreference preview feature error */ int RecordMultipleCanonicalConstructors = PreviewRelated + 1737; diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/MethodScope.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/MethodScope.java index c251ad855c..c4ba690afe 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/MethodScope.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/MethodScope.java @@ -8,7 +8,10 @@ * * SPDX-License-Identifier: EPL-2.0 * - * Contributors: + * 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. + * * IBM Corporation - initial API and implementation * Stephan Herrmann - Contributions for * bug 349326 - [1.7] new warning for missing try-with-resources @@ -153,9 +156,8 @@ private void checkAndSetModifiersForConstructor(MethodBinding methodBinding) { // must check the parse node explicitly problemReporter().illegalModifierForMethod((AbstractMethodDeclaration) this.referenceContext); } else if (this.referenceContext instanceof CompactConstructorDeclaration) { - if ((((AbstractMethodDeclaration) this.referenceContext).modifiers & ClassFileConstants.AccPublic) == 0) { - problemReporter().recordCanonicalConstructorNotPublic((AbstractMethodDeclaration) this.referenceContext); - } +// if (!SourceTypeBinding.isAtleastAsAccessibleAsRecord(methodBinding)) +// problemReporter().recordCanonicalConstructorVisibilityReduced((AbstractMethodDeclaration) this.referenceContext); } // check for incompatible modifiers in the visibility bits, isolate the visibility bits diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java index 8a4ccc50bb..dd978f5b11 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java @@ -2358,11 +2358,27 @@ public MethodBinding[] methods() { return this.methods; } +static boolean isAtleastAsAccessibleAsRecord(MethodBinding canonicalConstructor) { + ReferenceBinding enclosingRecord = canonicalConstructor.declaringClass; + if (enclosingRecord.isPublic()) + return canonicalConstructor.isPublic(); + + if (enclosingRecord.isProtected()) + return canonicalConstructor.isPublic() || canonicalConstructor.isProtected(); + + if (enclosingRecord.isPrivate()) + return true; + + /* package visibility */ + return !canonicalConstructor.isPrivate(); +} + private void checkRecordCanonicalConstructor(MethodBinding explicitCanonicalConstructor) { AbstractMethodDeclaration methodDecl = explicitCanonicalConstructor.sourceMethod(); - if (!explicitCanonicalConstructor.isPublic()) - this.scope.problemReporter().recordCanonicalConstructorNotPublic(methodDecl); + + if (!SourceTypeBinding.isAtleastAsAccessibleAsRecord(explicitCanonicalConstructor)) + this.scope.problemReporter().recordCanonicalConstructorVisibilityReduced(methodDecl); TypeParameter[] typeParameters = methodDecl.typeParameters(); if (typeParameters != null && typeParameters.length > 0) this.scope.problemReporter().recordCanonicalConstructorShouldNotBeGeneric(methodDecl); 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 48fac702c9..8bbfe6f02d 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 @@ -11592,11 +11592,11 @@ public void recordAccessorMethodHasThrowsClause(ASTNode methodDeclaration) { methodDeclaration.sourceStart, methodDeclaration.sourceEnd); } -public void recordCanonicalConstructorNotPublic(AbstractMethodDeclaration methodDecl) { +public void recordCanonicalConstructorVisibilityReduced(AbstractMethodDeclaration methodDecl) { if (!this.options.enablePreviewFeatures) return; this.handle( - IProblem.RecordCanonicalConstructorShouldBePublic, + IProblem.RecordCanonicalConstructorVisibilityReduced, new String[] { new String(methodDecl.selector) }, @@ -11710,16 +11710,6 @@ public void recordCanonicalConstructorShouldNotBeGeneric(AbstractMethodDeclarati methodDecl.sourceStart, methodDecl.sourceEnd); } -public void recordCanonicalConstructorShouldBePublic(MethodDeclaration methodDecl) { - if (!this.options.enablePreviewFeatures) - return; - this.handle( - IProblem.RecordCanonicalConstructorShouldBePublic, - new String[] { new String(methodDecl.selector)}, - new String[] { new String(methodDecl.selector)}, - methodDecl.sourceStart, - methodDecl.sourceEnd); -} public void recordCanonicalConstructorHasThrowsClause(AbstractMethodDeclaration methodDecl) { if (!this.options.enablePreviewFeatures) return; 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 8dd290f34d..cb529bdf17 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 @@ -1034,7 +1034,8 @@ 1733 = User declared non-static fields {0} are not permitted in a record 1734 = Throws clause not allowed for explicitly declared accessor method 1735 = Throws clause not allowed for canonical constructor {0} -1736 = The canonical constructor {0} of a record declaration must be declared public. +1736 = Cannot reduce the visibility of a canonical constructor {0} from that of the record +# The canonical constructor {0} of a record declaration must be declared public. 1737 = Multiple canonical constructors {0} are not allowed 1738 = The body of a compact constructor must not contain a return statement 1739 = Duplicate component {0} in record |