diff options
author | Manoj Palat | 2020-07-29 11:00:48 +0000 |
---|---|---|
committer | Manoj Palat | 2020-07-29 11:00:48 +0000 |
commit | 472ab98dc5d3735c018241ec47a517ecef212edc (patch) | |
tree | e71e2134d5cb51c16fede74e63096558b136d2e3 | |
parent | eacc7a968e5b57af79ddde8ef2755a930c882050 (diff) | |
download | eclipse.jdt.core-472ab98dc5d3735c018241ec47a517ecef212edc.tar.gz eclipse.jdt.core-472ab98dc5d3735c018241ec47a517ecef212edc.tar.xz eclipse.jdt.core-472ab98dc5d3735c018241ec47a517ecef212edc.zip |
inner class
Change-Id: I3e14c9a231d667e6f6462c629a12fdb21bd093ff
Signed-off-by: Manoj Palat <manpalat@in.ibm.com>
3 files changed, 36 insertions, 42 deletions
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SealedTypes15Tests.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SealedTypes15Tests.java index 1fb26edc98..37d754fd88 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SealedTypes15Tests.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SealedTypes15Tests.java @@ -35,7 +35,7 @@ public class SealedTypes15Tests extends AbstractRegressionTest9 { static { // TESTS_NUMBERS = new int [] { 40 }; // TESTS_RANGE = new int[] { 1, -1 }; -// TESTS_NAMES = new String[] { "testBug565116_001"}; +// TESTS_NAMES = new String[] { "testBug564190_2"}; } public static Class<?> testClass() { @@ -1538,8 +1538,8 @@ public class SealedTypes15Tests extends AbstractRegressionTest9 { ""); String expectedOutput = "PermittedSubclasses:\n" + - " #22 p1/A$SubY,\n" + - " #24 p1/A$Z\n" + + " #22 p1/A$Z,\n" + + " #24 p1/A$SubY\n" + "}"; verifyClassFile(expectedOutput, "p1/A$Y.class", ClassFileBytesDisassembler.SYSTEM); expectedOutput = @@ -1567,8 +1567,8 @@ public class SealedTypes15Tests extends AbstractRegressionTest9 { String expectedOutput = "PermittedSubclasses:\n" + " #24 p1/A$Y$SubInnerY,\n" + - " #26 p1/A$SubY,\n" + - " #28 p1/A$Z\n"; + " #26 p1/A$Z,\n" + + " #28 p1/A$SubY\n"; verifyClassFile(expectedOutput, "p1/A$Y.class", ClassFileBytesDisassembler.SYSTEM); } public void testBug564498_4() throws IOException, ClassFormatException { @@ -5150,4 +5150,20 @@ public class SealedTypes15Tests extends AbstractRegressionTest9 { }, ""); } + public void testBug565638_001() throws IOException, ClassFormatException { + runConformTest( + new String[] { + "X.java", + "sealed class X {\n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(0);\n"+ + " }\n"+ + "}\n"+ + "final class Outer {\n"+ + " final class Inner extends X{\n"+ + " }\n"+ + "}", + }, + "0"); + } } 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 cfbfac75a4..02e8f9af2a 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 @@ -39,8 +39,11 @@ package org.eclipse.jdt.internal.compiler.lookup; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; +import java.util.LinkedHashSet; import java.util.List; import java.util.Map; +import java.util.Set; + import org.eclipse.jdt.core.compiler.CharOperation; import org.eclipse.jdt.internal.compiler.ast.ASTNode; import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration; @@ -1163,48 +1166,23 @@ public class ClassScope extends Scope { } // Call only when we know there's no explicit permits clause and this is a sealed type private void connectImplicitPermittedTypes(SourceTypeBinding sourceType) { - List<ReferenceBinding> permitted = null; - // And nested types - if (sourceType.memberTypes != null) { - for (ReferenceBinding subtype : sourceType.memberTypes) { - if (!TypeBinding.equalsEquals(subtype, sourceType)) - if (subtype.findSuperTypeOriginatingFrom(sourceType) != null) { - if (permitted == null) - permitted = new ArrayList<>(); - permitted.add(subtype); - } + List<SourceTypeBinding> types = new ArrayList<>(); + for (TypeDeclaration typeDecl : this.referenceCompilationUnit().types) { + types.addAll(sourceType.collectAllTypeBindings(typeDecl, this.compilationUnitScope())); + } + Set<ReferenceBinding> permSubTypes = new LinkedHashSet<>(); + for (ReferenceBinding type : types) { + if (!TypeBinding.equalsEquals(type, sourceType) && type.findSuperTypeOriginatingFrom(sourceType) != null) { + permSubTypes.add(type); } } - // Siblings - ReferenceBinding[] siblings = null; - if (sourceType.isMemberType()) { - siblings = sourceType.enclosingType().memberTypes(); - } else { - siblings = compilationUnitScope().topLevelTypes; - } - - if (siblings != null) { - for (ReferenceBinding sibling : siblings) { - if (!TypeBinding.equalsEquals(sibling, sourceType)) { - if (sibling.findSuperTypeOriginatingFrom(sourceType) != null) { - if (permitted == null) - permitted = new ArrayList<>(); - permitted.add(sibling); - } - } - } - } - - if (permitted == null || permitted.size() == 0) { + if (permSubTypes.size() == 0) { problemReporter().sealedSealedTypeMissingPermits(sourceType, this.referenceContext); - } else { - ReferenceBinding[] permittedTypeBindings = new ReferenceBinding[permitted.size()]; - permitted.toArray(permittedTypeBindings); - sourceType.setPermittedTypes(permittedTypeBindings); return; } + sourceType.setPermittedTypes(permSubTypes.toArray(new ReferenceBinding[0])); } - /** +/** * @see #connectPermittedTypes() */ void connectImplicitPermittedTypes() { 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 d14135bb8f..7c278e28d4 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 @@ -1209,7 +1209,7 @@ private void checkPermitsInType() { } return; } -private List<SourceTypeBinding> collectAllTypeBindings(TypeDeclaration typeDecl, CompilationUnitScope unitScope) { +public List<SourceTypeBinding> collectAllTypeBindings(TypeDeclaration typeDecl, CompilationUnitScope unitScope) { class TypeBindingsCollector extends ASTVisitor { List<SourceTypeBinding> types = new ArrayList<>(); @Override |