Bug 527743 - [9] IllegalAccessError from _OT$InitFields for final field
diff --git a/org.eclipse.jdt.core/.settings/.api_filters b/org.eclipse.jdt.core/.settings/.api_filters
index 53a904d..2a97fec 100644
--- a/org.eclipse.jdt.core/.settings/.api_filters
+++ b/org.eclipse.jdt.core/.settings/.api_filters
@@ -368,6 +368,14 @@
</message_arguments>
</filter>
</resource>
+ <resource path="compiler/org/eclipse/objectteams/otdt/core/compiler/IOTConstants.java" type="org.eclipse.objectteams.otdt.core.compiler.IOTConstants">
+ <filter comment="_OT$InitField can not be supported on Java 9" id="405864542">
+ <message_arguments>
+ <message_argument value="org.eclipse.objectteams.otdt.core.compiler.IOTConstants"/>
+ <message_argument value="INIT_METHOD_NAME"/>
+ </message_arguments>
+ </filter>
+ </resource>
<resource path="dom/org/eclipse/jdt/core/dom/AST.java" type="org.eclipse.jdt.core.dom.AST">
<filter id="1141899266">
<message_arguments>
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 a1c18a6..ae39150 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
@@ -49,7 +49,6 @@
import org.eclipse.objectteams.otdt.internal.core.compiler.lifting.Lifting;
import org.eclipse.objectteams.otdt.internal.core.compiler.model.MethodModel;
import org.eclipse.objectteams.otdt.internal.core.compiler.model.RoleModel;
-import org.eclipse.objectteams.otdt.internal.core.compiler.model.TypeModel;
import org.eclipse.objectteams.otdt.internal.core.compiler.model.MethodModel.ProblemDetail;
import org.eclipse.objectteams.otdt.internal.core.compiler.statemachine.transformer.InsertTypeAdjustmentsVisitor;
import org.eclipse.objectteams.otdt.internal.core.compiler.util.AstGenerator;
@@ -593,9 +592,6 @@
boolean needFieldInitializations = this.constructorCall == null || this.constructorCall.accessMode != ExplicitConstructorCall.This;
//{ObjectTeams: some more constructors do not initialize fields:
- // if constructorCall is tsuper() the called ctor contains field initializations already.
- if (this.constructorCall != null)
- needFieldInitializations &= this.constructorCall.accessMode != ExplicitConstructorCall.Tsuper;
// copied team constructors (due to arg lifting) do not initialize fields
if ( !needFieldInitializations
&& this.constructorCall != null
@@ -625,12 +621,6 @@
if (!preInitSyntheticFields){
generateSyntheticFieldInitializationsIfNecessary(this.scope, codeStream, declaringClass);
}
-//{ObjectTeams: only non-role types have standard field initialization:
- if ( !declaringType.isRole()
- || ( declaringClass.enclosingType() != null // also accept roles of o.o.Team
- && declaringClass.enclosingType().id == IOTConstants.T_OrgObjectTeamsTeam))
- {
-// orig:
// generate user field initialization
if (declaringType.fields != null) {
for (int i = 0, max = declaringType.fields.length; i < max; i++) {
@@ -640,29 +630,6 @@
}
}
}
-// :giro
- } else
- callInit: if (!Lifting.isLiftingCtor(this.binding))
- {
- // lifting ctor already contains the invoke statement
- MethodBinding[] initMethods = declaringType.binding.getMethods(IOTConstants.INIT_METHOD_NAME);
- if (initMethods.length >= 1)
- {
- int argCount = TSuperHelper.isTSuper(this.binding) ? 1 : 0;
- for (int i = 0; i < initMethods.length; i++) {
- if (initMethods[i].parameters.length == argCount) {
- codeStream.aload_0(); // this
- codeStream.invoke(Opcodes.OPC_invokevirtual, initMethods[i], declaringType.binding);
- break callInit;
- }
- }
- }
- // no matching role init method should mean we had errors.
- assert TypeModel.isIgnoreFurtherInvestigation(classScope.referenceContext)
- || RoleModel.hasTagBit(declaringClass, RoleModel.BaseclassHasProblems)
- || declaringClass.isTeam(); // might be the "turning constructor" of a nested team (see 2.1.11-otjld-*-1f)
- }
-// SH}
}
// generate statements
if (this.statements != null) {
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/core/compiler/IOTConstants.java b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/core/compiler/IOTConstants.java
index 1570326..bbd3fef 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/core/compiler/IOTConstants.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/core/compiler/IOTConstants.java
@@ -94,8 +94,6 @@
public static final char[] OT_SETFIELD = (OT_DOLLAR+"set$").toCharArray();
public static final String OT_DOLLAR_ARG = OT_DOLLAR + "arg";
- public static final char[] INIT_METHOD_NAME = (OT_DOLLAR + "InitFields").toCharArray();
-
// bytecode attributes:
public static final String PLAYEDBY = "PlayedBy";
public static final char[] PLAYEDBY_NAME = PLAYEDBY.toCharArray();
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/ast/RoleInitializationMethod.java b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/ast/RoleInitializationMethod.java
deleted file mode 100644
index c9339bb..0000000
--- a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/ast/RoleInitializationMethod.java
+++ /dev/null
@@ -1,233 +0,0 @@
-/**********************************************************************
- * This file is part of "Object Teams Development Tooling"-Software
- *
- * Copyright 2004, 2006 Fraunhofer Gesellschaft, Munich, Germany,
- * for its Fraunhofer Institute for Computer Architecture and Software
- * Technology (FIRST), Berlin, Germany and Technical University Berlin,
- * Germany.
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- * $Id: RoleInitializationMethod.java 23401 2010-02-02 23:56:05Z stephan $
- *
- * Please visit http://www.eclipse.org/objectteams for updates and contact.
- *
- * Contributors:
- * Fraunhofer FIRST - Initial API and implementation
- * Technical University Berlin - Initial API and implementation
- **********************************************************************/
-package org.eclipse.objectteams.otdt.internal.core.compiler.ast;
-
-import org.eclipse.jdt.internal.compiler.ClassFile;
-import org.eclipse.jdt.internal.compiler.CompilationResult;
-import org.eclipse.jdt.internal.compiler.ast.ASTNode;
-import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration;
-import org.eclipse.jdt.internal.compiler.ast.Expression;
-import org.eclipse.jdt.internal.compiler.ast.FieldDeclaration;
-import org.eclipse.jdt.internal.compiler.ast.MessageSend;
-import org.eclipse.jdt.internal.compiler.ast.MethodDeclaration;
-import org.eclipse.jdt.internal.compiler.ast.Statement;
-import org.eclipse.jdt.internal.compiler.ast.ThisReference;
-import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration;
-import org.eclipse.jdt.internal.compiler.ast.TypeReference;
-import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
-import org.eclipse.jdt.internal.compiler.flow.FlowInfo;
-import org.eclipse.jdt.internal.compiler.flow.InitializationFlowContext;
-import org.eclipse.jdt.internal.compiler.lookup.ClassScope;
-import org.eclipse.jdt.internal.compiler.lookup.ExtraCompilerModifiers;
-import org.eclipse.jdt.internal.compiler.lookup.MethodBinding;
-import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding;
-import org.eclipse.jdt.internal.compiler.lookup.TypeIds;
-import org.eclipse.jdt.internal.compiler.parser.Parser;
-import org.eclipse.objectteams.otdt.core.compiler.IOTConstants;
-import org.eclipse.objectteams.otdt.internal.core.compiler.model.RoleModel;
-import org.eclipse.objectteams.otdt.internal.core.compiler.util.AstEdit;
-import org.eclipse.objectteams.otdt.internal.core.compiler.util.AstGenerator;
-import org.eclipse.objectteams.otdt.internal.core.compiler.util.TSuperHelper;
-import org.eclipse.objectteams.otdt.internal.core.compiler.util.TypeAnalyzer;
-
-
-/**
- * NEW for OTDT.
- *
- * A declaration for a generated method which performs all field initializations that
- * otherwise each constructor would have to do.
- *
- * Example:
- * int i = 5;
- * yields:
- * private void _OT$InitFields() {
- * tsuper._OT$InitFields(); // if defined.
- * i = 5;
- * }
- * Role () { // any constructor..
- * super();
- * _OT$InitFields();
- * customStatements();
- * }
- *
- * Why: This greatly helps to merge field initializations during copy-inheritance
- * without modifying existing byte-code.
- * How: endOfMethodHook() hooks into AbstractMethodDeclaration.generateCode().
- *
- * What: Insertion of calls to _OT$InitFields depends on the type of constructor:
- * 1. Lifting constructors have an explicit MessageSend (generated by Lifting.genLiftToConstructorStatements)
- * 2. Other constructors of roles invoke this method via ConstructorDeclaration.internalGenerateCode()
- * Why: Lifting constructors must assign _OT$base before executing any user code from field initializations
- * (_OT$base is needed for callouts!).
- *
- * @author stephan
- * @version $Id: RoleInitializationMethod.java 23401 2010-02-02 23:56:05Z stephan $
- */
-public class RoleInitializationMethod extends MethodDeclaration implements IOTConstants {
-
- /**
- * @param compilationResult
- */
- public RoleInitializationMethod(CompilationResult compilationResult) {
- super(compilationResult);
- this.returnType = TypeReference.baseTypeReference(TypeIds.T_void, 0, null);
- this.selector = INIT_METHOD_NAME;
- this.bits |= ASTNode.NeedFreeReturn;
- this.isGenerated = true;
- // set private to disable overriding along extends:
- // (each constructor calls the corresponding init fields,
- // which must stay within the constructor's class).
- this.modifiers = ClassFileConstants.AccPrivate;
- }
-
-
- /*
- * Override with empty implementation
- * (non-Javadoc)
- * @see org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration#analyseCode(org.eclipse.jdt.internal.compiler.lookup.ClassScope, org.eclipse.jdt.internal.compiler.flow.InitializationFlowContext, org.eclipse.jdt.internal.compiler.flow.FlowInfo)
- */
- public void analyseCode(
- ClassScope classScope,
- InitializationFlowContext initializationContext,
- FlowInfo info)
- {
- if (this.statements != null) {
- if (this.binding != null)
- this.binding.modifiers |= ExtraCompilerModifiers.AccLocallyUsed; // avoid unused-warning
- super.analyseCode(classScope, initializationContext, info);
- }
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration#parseStatements(org.eclipse.jdt.internal.compiler.parser.Parser, org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration)
- */
- public void parseStatements(Parser parser, CompilationUnitDeclaration unit) {
- // nothing to do, no statements to parse...
- this.statements = new Statement[0];
- }
-
- /**
- * Instead of parsing statements, possibly generate them just before resolving.
- */
- public void resolveStatements() {
- if (this.ignoreFurtherInvestigation)
- return;
- MethodBinding tsuperInit = getTSuperInit(this.scope.referenceType().getRoleModel());
- if (tsuperInit != null) {
- AstGenerator gen = new AstGenerator(this.sourceStart, this.sourceEnd);
- // there is a tsuper-version, so call it:
- MessageSend tsuperCall = gen.messageSend(
- ThisReference.implicitThis(),
- this.selector,
- null);
- tsuperCall.arguments = TSuperHelper.addMarkerArgument(
- null/*qualification*/, tsuperCall, tsuperCall.arguments, this.scope);
- if (this.statements == null)
- setStatements(new Statement[] { tsuperCall });
- else {
- // already have a casted local due to signature weakening
- int len = this.statements.length;
- Statement[] newStatements = new Statement[len+1];
- System.arraycopy(
- this.statements, 0,
- newStatements, 0,
- len);
- newStatements[len] = tsuperCall;
- setStatements(newStatements);
- }
- super.resolveStatements();
- } else {
- setStatements(new Statement[0]); // maybe remove useless casted local
- }
- }
-
- /**
- * During generateCode this is invoked right before generating the return opcode.
- */
- protected void endOfMethodHook (ClassFile classfile)
- {
- // basically taken from ConstructorDeclaration.internalGenerateCode
- TypeDeclaration declaringType = this.scope.classScope().referenceContext;
- // generate user field initialization
- if (declaringType.fields != null) {
- for (int i = 0, max = declaringType.fields.length; i < max; i++) {
- FieldDeclaration fieldDecl;
- if (!(fieldDecl = declaringType.fields[i]).isStatic()) {
- fieldDecl.generateCode(this.scope, classfile.codeStream);
- }
- }
- }
- }
-
- /**
- * Create and setup a role initialization method.
- *
- * @param role the role class to augment (not an interface).
- */
- public static void setupRoleInitializationMethod(RoleModel role) {
- if (TypeAnalyzer.isTopConfined(role.getBinding()))
- return;
- // Each split role has a method _OT$initFields instead of initializing fields directly from all constructors
- TypeDeclaration roleClassDeclaration = role.getAst();
- AstGenerator gen = new AstGenerator(roleClassDeclaration.sourceStart, roleClassDeclaration.sourceEnd);
- RoleInitializationMethod initMethod = gen.roleInitializationMethod(
- roleClassDeclaration.compilationResult);
- // no arguments
- AstEdit.addMethod(roleClassDeclaration, initMethod);
- if (!role.getBinding().isDirectRole())
- initMethod.resolve(role.getAst().scope);
- }
-
-
- /**
- * Get the init fields method of the tsuper role of the current role OR null.
- * Be sure not to return a method that is already a tsuper-copy.
- *
- * TODO (SH): support multiple tsupers, call all their init methods
- *
- * @param role the current role
- * @return the tsuper version of this method.
- */
- private MethodBinding getTSuperInit(RoleModel role) {
- if (!role.getBinding().isDirectRole())
- return null;
- ReferenceBinding tsuperRole = role.getTSuperRoleBinding(); // TODO(SH) multiple tsupers
- if (tsuperRole != null) {
- if (TypeAnalyzer.isSourceTypeWithErrors(tsuperRole))
- return null;
- MethodBinding[] tsuperInits = tsuperRole.getMethods(INIT_METHOD_NAME);
- if (tsuperInits != null && tsuperInits.length >= 1) {
- for (int i=0; i<tsuperInits.length; i++) {
- if (tsuperInits[i].parameters.length == 0)
- return tsuperInits[i];
- }
- }
- }
- return null;
- }
-
- public static Statement genInvokeInitMethod(Expression receiver, ReferenceBinding receiverType, AstGenerator gen)
- {
- if (TypeAnalyzer.isTopConfined(receiverType))
- return gen.emptyStatement();
- return gen.messageSend(receiver, INIT_METHOD_NAME, null);
- }
-}
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/bytecode/ConstantPoolObjectMapper.java b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/bytecode/ConstantPoolObjectMapper.java
index 23096e9..6590d81 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/bytecode/ConstantPoolObjectMapper.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/bytecode/ConstantPoolObjectMapper.java
@@ -472,13 +472,6 @@
assert(methods.length == 1);
return methods[0];
}
- if ( role.isLocalType()
- && CharOperation.equals(refMethod.selector, IOTConstants.INIT_METHOD_NAME))
- {
- // have no overriding along implicit inheritance due to scoping of locals,
- // so just retrieve the method by its name:
- return role.getMethods(IOTConstants.INIT_METHOD_NAME)[0];
- }
int bestRank = Integer.MAX_VALUE;
MethodBinding bestMethod = null;
methods = role.getMethods(refMethod.selector);
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/control/Dependencies.java b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/control/Dependencies.java
index 5d7fc4f..fb036cc 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/control/Dependencies.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/control/Dependencies.java
@@ -54,7 +54,6 @@
import org.eclipse.objectteams.otdt.core.compiler.Pair;
import org.eclipse.objectteams.otdt.core.exceptions.InternalCompilerError;
import org.eclipse.objectteams.otdt.internal.core.compiler.ast.RoleClassLiteralAccess;
-import org.eclipse.objectteams.otdt.internal.core.compiler.ast.RoleInitializationMethod;
import org.eclipse.objectteams.otdt.internal.core.compiler.lifting.DeclaredLifting;
import org.eclipse.objectteams.otdt.internal.core.compiler.lifting.Lifting.InstantiationPolicy;
import org.eclipse.objectteams.otdt.internal.core.compiler.lifting.LiftingEnvironment;
@@ -600,11 +599,6 @@
success = establishFaultInTypes(model);
done = NESTED_TEAMS;
break;
- case STATE_ROLE_INIT_METHODS:
- if (teamBinding.isRole())
- ensureRoleState(teamBinding.roleModel, nextState);
- done = NONE;
- break;
case STATE_METHODS_CREATED:
success = establishMethodsCreated(model);
done = NONE;
@@ -762,9 +756,6 @@
success &= ensureUnitState(model, nextState);
}
break;
- case STATE_ROLE_INIT_METHODS:
- success &= establishRoleInitializationMethod(model);
- break;
case STATE_ROLE_FEATURES_COPIED:
success &= establishRoleFeaturesCopied(model);
break;
@@ -1014,7 +1005,6 @@
case STATE_NONE:
case STATE_ROLES_SPLIT:
case STATE_ROLES_LINKED:
- case STATE_ROLE_INIT_METHODS:
case STATE_ROLE_FEATURES_COPIED:
case STATE_ROLE_HIERARCHY_ANALYZED:
case STATE_FULL_LIFTING:
@@ -1270,31 +1260,6 @@
* => Parser.getMethodBodies()
*/
- /* **** STATE_ROLE_INIT_METHODS (OT/J) ****
- * Create a method that holds all field initializations for a role.
- *
- * GENERATES:
- * - _OT$InitFields()
- */
-
- /**
- * BinaryTypes: nothing to do.
- */
- private static boolean establishRoleInitializationMethod(RoleModel role)
- {
- // must be done before role features copy
- TypeDeclaration roleClassDeclaration = role.getAst();
- if ( roleClassDeclaration != null
- && !roleClassDeclaration.isInterface()
- && needMethodBodies(roleClassDeclaration))
- {
- RoleInitializationMethod.setupRoleInitializationMethod(role);
- }
-
- role.setState(STATE_ROLE_INIT_METHODS);
- return true;
- }
-
/* **** STATE_ROLE_FEATURES_COPIED (OT/J) ****
* Copy all direct features (methods/ctors/fields/) from tsuper roles.
* Operate on AST and bindings. Link bindings of copied methods to
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/control/ITranslationStates.java b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/control/ITranslationStates.java
index 0d37de4..2d066a4 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/control/ITranslationStates.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/control/ITranslationStates.java
@@ -44,27 +44,29 @@
public static final int STATE_LENV_DONE_FIELDS_AND_METHODS= 7;//LookupEnvironment & Deps.
public static final int STATE_ROLES_LINKED = 8;//LookupEnvironment & RoleSplitter
public static final int STATE_METHODS_PARSED = 9;//Compiler
- public static final int STATE_ROLE_INIT_METHODS = 10;//RoleInitializationMethod
+// removed state:
+// public static final int STATE_ROLE_INIT_METHODS = 10;//RoleInitializationMethod
+//
+ public static final int STATE_ROLE_HIERARCHY_ANALYZED = 10;//Lifting
public static final int STATE_ROLE_FEATURES_COPIED = 11;//Copy inheritance
- public static final int STATE_ROLE_HIERARCHY_ANALYZED = 12;//Lifting
- public static final int STATE_FULL_LIFTING = 13;//Lifting
- public static final int STATE_FAULT_IN_TYPES = 14;//Scope
- public static final int STATE_METHODS_CREATED = 15;//RoleTypeBinding, CopyInheritance
- public static final int STATE_TYPES_ADJUSTED = 16;//RoleTypeBinding, CopyInheritance
- public static final int STATE_STATEMENTS_TRANSFORMED = 17;//TransformStatementsVisitor
- public static final int STATE_CALLINS_TRANSFORMED = 18;//CallinImplementor[Dyn]
- public static final int STATE_LATE_ATTRIBUTES_EVALUATED= 19; // ModelElement, TypeModel
- public static final int STATE_METHODS_VERIFIED = 20;//Scope
- public static final int STATE_RESOLVED = 21;//AST
- public static final int STATE_LATE_ELEMENTS_COPIED = 22;//CopyInheritance
- public static final int STATE_CODE_ANALYZED = 23;//AST
- public static final int STATE_BYTE_CODE_PREPARED = 24;//Dependencies
- public static final int STATE_BYTE_CODE_GENERATED = 25;//AST
+ public static final int STATE_FULL_LIFTING = 12;//Lifting
+ public static final int STATE_FAULT_IN_TYPES = 13;//Scope
+ public static final int STATE_METHODS_CREATED = 14;//RoleTypeBinding, CopyInheritance, CalloutImplementor
+ public static final int STATE_TYPES_ADJUSTED = 15;//RoleTypeBinding, CopyInheritance
+ public static final int STATE_STATEMENTS_TRANSFORMED = 16;//TransformStatementsVisitor
+ public static final int STATE_CALLINS_TRANSFORMED = 17;//CallinImplementor[Dyn]
+ public static final int STATE_LATE_ATTRIBUTES_EVALUATED= 18; // ModelElement, TypeModel
+ public static final int STATE_METHODS_VERIFIED = 19;//Scope
+ public static final int STATE_RESOLVED = 20;//AST
+ public static final int STATE_LATE_ELEMENTS_COPIED = 21;//CopyInheritance
+ public static final int STATE_CODE_ANALYZED = 22;//AST
+ public static final int STATE_BYTE_CODE_PREPARED = 23;//Dependencies
+ public static final int STATE_BYTE_CODE_GENERATED = 24;//AST
/**
* Note, that this state does not trigger intermediate steps, in fact never use it
* with ensureState() but directly invoke Dependencies.cleanup!
*/
- public static final int STATE_FINAL = 26;
+ public static final int STATE_FINAL = 25;
@SuppressWarnings("nls")
public static final String[] STATE_NAMES =
@@ -79,9 +81,8 @@
"bindings: fields and methods [completed]",
"roles linked",
"method bodies parsed",
- "role initialization method",
- "role features copied",
"role hierarchy analyzed",
+ "role features copied",
"full lifting",
"fault in types",
"methods created",
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/lifting/Lifting.java b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/lifting/Lifting.java
index 22661d5..13554a1 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/lifting/Lifting.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/lifting/Lifting.java
@@ -44,7 +44,6 @@
import org.eclipse.jdt.internal.compiler.lookup.TypeVariableBinding;
import org.eclipse.objectteams.otdt.core.compiler.IOTConstants;
import org.eclipse.objectteams.otdt.core.exceptions.InternalCompilerError;
-import org.eclipse.objectteams.otdt.internal.core.compiler.ast.RoleInitializationMethod;
import org.eclipse.objectteams.otdt.internal.core.compiler.control.ITranslationStates;
import org.eclipse.objectteams.otdt.internal.core.compiler.lookup.ITeamAnchor;
import org.eclipse.objectteams.otdt.internal.core.compiler.lookup.RoleTypeBinding;
@@ -225,20 +224,21 @@
TreeNode instantiableBoundRootRoleNode = roleNode.getTopmostBoundParent(false);
if (instantiableBoundRootRoleNode == null) return null;
- TypeDeclaration roleDecl = roleNode.getTreeObject().getAst();
+ RoleModel roleModel = roleNode.getTreeObject();
+ TypeDeclaration roleDecl = roleModel.getAst();
ClassScope scope = roleDecl.scope;
if (instantiableBoundRootRoleNode == TreeNode.ProblemNode) {
scope.problemReporter().
overlappingRoleHierarchies(roleDecl, TreeNode.ProblemNode.toString());
return null;
}
- TypeDeclaration roleType = roleNode.getTreeObject().getAst();
+ TypeDeclaration roleType = roleModel.getAst();
ConstructorDeclaration existingConstructor = findLiftToConstructor(roleType);
if ( existingConstructor == null
&& !roleNode.hasBoundParent(false)
- && !roleNode.getTreeObject().isIgnoreFurtherInvestigation())
+ && !roleModel.isIgnoreFurtherInvestigation())
{
- ReferenceBinding parent = roleNode.getTreeObject().getBinding().superclass();
+ ReferenceBinding parent = roleModel.getBinding().superclass();
MethodBinding defCtor = parent.getExactConstructor(Binding.NO_PARAMETERS);
boolean hasEmptyCtor = (defCtor != null)
? defCtor.isValidBinding()
@@ -253,7 +253,7 @@
// for determining the cache interfaces are allowed:
this._boundRootRoleModel = roleNode.getTopmostBoundParent(true).getTreeObject();
if (this._boundRootRoleModel != null)
- roleNode.getTreeObject()._boundRootRole = this._boundRootRoleModel;
+ roleModel._boundRootRole = this._boundRootRoleModel;
TypeDeclaration teamTypeDeclaration = roleType.enclosingType;
ReferenceBinding baseClassBinding = roleType.binding.baseclass();
@@ -280,12 +280,13 @@
);
gen.addNonNullAnnotation(arg, scope.environment());
+ RoleModel implicitSuperRole = roleModel.getImplicitSuperRole();
// default arg name is base.
char[] baseArgName = BASE;
if (existingConstructor != null) {
if (existingConstructor.isCopied) {
- if (roleNode.getTreeObject().getImplicitSuperRole().isBound()) // parent must be class.
+ if (implicitSuperRole.isBound()) // parent must be class.
return null; // copied constructor has everything we need.
}
// use the argument name of the existing constructor
@@ -293,12 +294,14 @@
}
if (needMethodBodies) {
+ boolean shouldCallTSuper = implicitSuperRole != null && implicitSuperRole.isBound() && !roleModel._refinesExtends;
if (instantiableBoundRootRoleNode == roleNode)
- genLiftToConstructorStatements(
+ genLiftToConstructorStatements(
baseClassBinding,
roleType,
generatedConstructor,
baseArgName,
+ shouldCallTSuper,
gen);
else
genLiftToConstructorSuperCall(
@@ -306,6 +309,7 @@
roleType,
generatedConstructor,
baseArgName,
+ shouldCallTSuper,
gen);
}
@@ -367,6 +371,7 @@
* @param baseClassBinding
* @param liftToConstructorDeclaration generated constructor
* @param baseArgName name of the base argument, either generated or from source
+ * @param hasBoundTSuper
* @param gen for generating AST nodes
*/
private static void genLiftToConstructorSuperCall(
@@ -374,22 +379,18 @@
TypeDeclaration roleType,
ConstructorDeclaration liftToConstructorDeclaration,
char[] baseArgName,
+ boolean shouldCallTSuper,
AstGenerator gen)
{
liftToConstructorDeclaration.constructorCall =
- gen.explicitConstructorCall(ExplicitConstructorCall.Super);
+ gen.explicitConstructorCall(shouldCallTSuper ? ExplicitConstructorCall.Tsuper : ExplicitConstructorCall.Super);
// mode maybe refined in ExplicitConstructorCall.resolve()->updateFromTSuper()
liftToConstructorDeclaration.constructorCall.arguments =
new Expression[] {
gen.singleNameReference(baseArgName)
};
- // start with an empty statements list, except for this._OT$InitFields();
- liftToConstructorDeclaration.setStatements(new Statement[] {
- RoleInitializationMethod.genInvokeInitMethod(
- gen.thisReference(),
- roleType.binding,
- gen)
- });
+ // start with an empty statements list
+ liftToConstructorDeclaration.setStatements(new Statement[0]);
}
private void genLiftToConstructorStatements(
@@ -397,35 +398,33 @@
TypeDeclaration roleType,
ConstructorDeclaration liftToConstructorDeclaration,
char[] baseArgName,
+ boolean shouldCallTSuper,
AstGenerator gen)
{
- liftToConstructorDeclaration.constructorCall =
- gen.explicitConstructorCall(ExplicitConstructorCall.Super);
- boolean useRoleCache = RoleModel.getInstantiationPolicy(roleType.binding).isOndemand();
- Statement[] statements = new Statement[useRoleCache ? 4 : 2];
- // _OT$base = <baseArgName>;
- SingleNameReference lhs = gen.singleNameReference(_OT_BASE);
- statements[0] = gen.assignment(lhs, gen.singleNameReference(baseArgName));
+ Statement[] statements;
+ boolean useRoleCache = RoleModel.getInstantiationPolicy(roleType.binding).isOndemand();
+ int idx = 0;
+ if (shouldCallTSuper) {
+ liftToConstructorDeclaration.constructorCall = gen.explicitConstructorCall(ExplicitConstructorCall.Tsuper);
+ liftToConstructorDeclaration.constructorCall.arguments = new Expression[] { gen.singleNameReference(baseArgName) };
+ statements = new Statement[0];
+ } else {
+ liftToConstructorDeclaration.constructorCall = gen.explicitConstructorCall(ExplicitConstructorCall.Super);
+ statements = new Statement[useRoleCache ? 3 : 1];
+ // _OT$base = <baseArgName>;
+ SingleNameReference lhs = gen.singleNameReference(_OT_BASE);
+ statements[idx++] = gen.assignment(lhs, gen.singleNameReference(baseArgName));
+ if (useRoleCache) {
+ Statement[] regStats = genRoleRegistrationStatements(
+ this._boundRootRoleModel.getAst().scope,
+ this._boundRootRoleModel,
+ baseClassBinding,
+ liftToConstructorDeclaration,
+ gen);
+ System.arraycopy(regStats, 0, statements, idx, regStats.length);
+ }
+ }
- int idx = 1;
- if (useRoleCache) {
- Statement[] regStats = genRoleRegistrationStatements(
- this._boundRootRoleModel.getAst().scope,
- this._boundRootRoleModel,
- baseClassBinding,
- liftToConstructorDeclaration,
- gen);
- System.arraycopy(regStats, 0, statements, idx, regStats.length);
- idx += 2;
- }
-
- // after initializing _OT$base and storing in the cache we are ready to execute field initializers:
-
- // this._OT$InitFields();
- statements[idx] = RoleInitializationMethod.genInvokeInitMethod(
- gen.thisReference(),
- roleType.binding,
- gen);
liftToConstructorDeclaration.setStatements(statements);
}
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/statemachine/copyinheritance/CopyInheritance.java b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/statemachine/copyinheritance/CopyInheritance.java
index 8775c8d..b4721d8 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/statemachine/copyinheritance/CopyInheritance.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/statemachine/copyinheritance/CopyInheritance.java
@@ -879,6 +879,8 @@
*/
public static void copyFeatures(RoleModel role, ReferenceBinding tsuperRoleBinding) {
TypeDeclaration rt = role.getAst();
+ Dependencies.ensureBindingState(tsuperRoleBinding, ITranslationStates.STATE_ROLE_HIERARCHY_ANALYZED); // e.g.: lifting constructors
+
// fields first (may be needed by synthetic methods below).
FieldBinding[] fields = tsuperRoleBinding.fields();
if(fields != null)
@@ -2236,9 +2238,6 @@
}
}
}
- if ( !binding.declaringClass.isDirectRole()
- && CharOperation.equals(binding.selector, IOTConstants.INIT_METHOD_NAME))
- return changed; // no statements, not casted locals.
if (!newLocalStats.isEmpty())
{
if (StateHelper.hasState(binding.declaringClass, ITranslationStates.STATE_RESOLVED))
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/util/AstGenerator.java b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/util/AstGenerator.java
index 03a7ac3..ff2b00c 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/util/AstGenerator.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/util/AstGenerator.java
@@ -63,7 +63,6 @@
import org.eclipse.objectteams.otdt.internal.core.compiler.ast.PotentialLiftExpression;
import org.eclipse.objectteams.otdt.internal.core.compiler.ast.QualifiedBaseReference;
import org.eclipse.objectteams.otdt.internal.core.compiler.ast.ResultReference;
-import org.eclipse.objectteams.otdt.internal.core.compiler.ast.RoleInitializationMethod;
import org.eclipse.objectteams.otdt.internal.core.compiler.ast.TSuperMessageSend;
import org.eclipse.objectteams.otdt.internal.core.compiler.ast.TsuperReference;
import org.eclipse.objectteams.otdt.internal.core.compiler.ast.TypeAnchorReference;
@@ -1274,13 +1273,6 @@
return lifter;
}
- public RoleInitializationMethod roleInitializationMethod(CompilationResult compilationResult)
- {
- RoleInitializationMethod roleInit = new RoleInitializationMethod(compilationResult);
- setMethodPositions(roleInit);
- return roleInit;
- }
-
public ThisReference thisReference() {
return new ThisReference(this.sourceStart, this.sourceEnd);
}
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 234bd58..c531ec6 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
@@ -1158,7 +1158,7 @@
"Team0c14iiif1_2.java",
"public team class Team0c14iiif1_2 extends Team0c14iiif1_1 {\n" +
" protected class R {\n" +
- " protected R() { super(); }\n" + // triggers blank final analysis
+ " protected R() { tsuper(); }\n" + // triggers blank final analysis
" protected void test() {\n" +
" System.out.print(val);\n" +
" }\n" +