Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephan Herrmann2020-12-21 19:08:18 +0000
committerStephan Herrmann2020-12-21 19:08:18 +0000
commit4a0b430a128e4e318cd09baefc50f47af13df049 (patch)
tree9f6445a99a76fd5d5f0f96b14b1251f08312705c
parent5ad1e037f91a4c91c43791c30bba9ed323995aec (diff)
downloadorg.eclipse.objectteams-4a0b430a128e4e318cd09baefc50f47af13df049.tar.gz
org.eclipse.objectteams-4a0b430a128e4e318cd09baefc50f47af13df049.tar.xz
org.eclipse.objectteams-4a0b430a128e4e318cd09baefc50f47af13df049.zip
Bug 569756 - Revisit field initialization in roles - discriminate final
/ non-final - fix field initialization for unbound->bound implicit inheritance
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ConstructorDeclaration.java19
-rw-r--r--testplugins/org.eclipse.objectteams.otdt.tests/otjld/org/eclipse/objectteams/otdt/tests/otjld/rolesandteams/ImplicitInheritance.java37
2 files changed, 49 insertions, 7 deletions
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ConstructorDeclaration.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ConstructorDeclaration.java
index 9fd2f0862..727128fee 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ConstructorDeclaration.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ConstructorDeclaration.java
@@ -728,14 +728,19 @@ private boolean isRoleUsingInitFields(TypeDeclaration typeDecl, ReferenceBinding
|| ( typeBinding.enclosingType() != null // also accept roles of o.o.Team
&& typeBinding.enclosingType().id == IOTConstants.T_OrgObjectTeamsTeam))
return false;
- if (typeDecl.fields == null)
- return false;
boolean hasInitialization = false;
- for (FieldDeclaration fieldDeclaration : typeDecl.fields) {
- if (fieldDeclaration.initialization != null) {
- if (fieldDeclaration.isFinal())
- return false; // needs to be set inside a proper constructor!
- hasInitialization = true;
+ if (typeDecl.fields != null) {
+ for (FieldDeclaration fieldDeclaration : typeDecl.fields) {
+ if (fieldDeclaration.initialization != null) {
+ if (fieldDeclaration.isFinal())
+ return false; // needs to be set inside a proper constructor!
+ hasInitialization = true;
+ }
+ }
+ }
+ for (ReferenceBinding tsuperRole : typeDecl.getRoleModel().getTSuperRoleBindings()) {
+ if (tsuperRole.fields() != Binding.NO_FIELDS && !tsuperRole.roleModel.hasFinalFieldInit()) {
+ hasInitialization = true; // conservative, would need another flag to test if tsuper has field init
}
}
return hasInitialization;
diff --git a/testplugins/org.eclipse.objectteams.otdt.tests/otjld/org/eclipse/objectteams/otdt/tests/otjld/rolesandteams/ImplicitInheritance.java b/testplugins/org.eclipse.objectteams.otdt.tests/otjld/org/eclipse/objectteams/otdt/tests/otjld/rolesandteams/ImplicitInheritance.java
index c5339afd0..9dcb6bb28 100644
--- a/testplugins/org.eclipse.objectteams.otdt.tests/otjld/org/eclipse/objectteams/otdt/tests/otjld/rolesandteams/ImplicitInheritance.java
+++ b/testplugins/org.eclipse.objectteams.otdt.tests/otjld/org/eclipse/objectteams/otdt/tests/otjld/rolesandteams/ImplicitInheritance.java
@@ -2010,4 +2010,41 @@ public class ImplicitInheritance extends AbstractOTJLDTest {
"Need to invoke a tsuper constructor because tsuper role \'SuperTeamFI5.R2\' has initializations for final fields.\n" +
"----------\n");
}
+
+ public void testFieldInitialization6_bound_tsuperUnbound_OK() throws Exception {
+ // variants with implicit lifting constructors
+ runConformTest(
+ new String[] {
+ "SubTeamFI6btU.java",
+ "public team class SubTeamFI6btU extends SuperTeamFI6btU {\n" +
+ " @Override\n" +
+ " protected class R1 playedBy Base1 {\n" +
+ " }\n" +
+ " @Override\n" +
+ " protected class R2 {\n" +
+ " }\n" +
+ " public static void main(String... args) {\n" +
+ " new SubTeamFI6btU().test();\n" +
+ " }\n" +
+ " @SuppressWarnings(\"roleinstantiation\")\n" +
+ " void test() {\n" +
+ " System.out.print(new R1(new Base1()).s1);\n" +
+ " System.out.print(new R2(new Base1()).s1);\n" +
+ " System.out.print(new R2(new Base1()).s2);\n" +
+ " }\n" +
+ "}\n",
+ "SuperTeamFI6btU.java",
+ "public team class SuperTeamFI6btU {\n" +
+ " protected class R1 {\n" +
+ " public String s1 = \"s1\";\n" +
+ " }\n" +
+ " protected class R2 extends R1 {\n" +
+ " public String s2 = \"s2\";\n" +
+ " }\n" +
+ "}\n",
+ "Base1.java",
+ "public class Base1 {}\n",
+ },
+ "s1s1s2");
+ }
}

Back to the top