Now that copyAllNonWideConstants() also copies class-constants, these must be mapped via ConstantPoolObjectMapper, too.
Fixes regression in test115_teamMethodInvocation2() (failed to resolve 2nd-level role-local type from within above method).
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/bytecode/BytecodeTransformer.java b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/bytecode/BytecodeTransformer.java
index e4655e0..61da161 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/bytecode/BytecodeTransformer.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/bytecode/BytecodeTransformer.java
@@ -104,7 +104,7 @@
this._reader = new ConstantPoolObjectReader(srcRole, srcConstantPool, scope.environment());
- copyAllNonWideConstants(srcRole.getConstantPoolOffsets().length);
+ copyAllNonWideConstants(srcRole.getConstantPoolOffsets().length, srcRole.getBinding().enclosingType(), dstType);
}
}
if (dstType.isTeam()) {
@@ -113,7 +113,7 @@
&& !dstType.superclass.isTeam())
{
this._reader = new ConstantPoolObjectReader(TeamMethodGenerator.classBytes, TeamMethodGenerator.constantPoolOffsets, orgObjectteamsTeam.getTeamModel(), scope.environment());
- copyAllNonWideConstants(TeamMethodGenerator.constantPoolOffsets.length);
+ copyAllNonWideConstants(TeamMethodGenerator.constantPoolOffsets.length, dstType.superclass, dstType);
}
TeamModel srcModel= dstType.superclass.getTeamModel();
@@ -124,7 +124,7 @@
method= method.copyInheritanceSrc;
if (method == null || method.model == null) continue; // shouldn't happen anyway
this._reader= new ConstantPoolObjectReader(method.model, srcModel, scope.environment());
- copyAllNonWideConstants(method.model.getConstantPoolOffsets().length);
+ copyAllNonWideConstants(method.model.getConstantPoolOffsets().length, dstType.superclass, dstType);
return; // triggered by any method, this team class is fully handled.
}
}
@@ -491,15 +491,17 @@
}
/**
- * Ths method replaces all references to constantpool of the superclass with references
+ * This method replaces all references to constantpool of the superclass with references
* to current subclass constantpool
* - all References in codeToAdjust will be exchanged
* - unknown references must be added to the ConstantPool of classFile
*
- * @param srcMethodBinding the method from which will be copied
- * (just a stored reference to orignal BinaryMethodBinding)
* @param dstClassFile This is the destination Classfile wich contains the later flushed ConstantPool
+ * @param mModel the destination method
* @param codeToAdjust this is the duplicated code-part of the code_attribute (see getCodeByteCode)
+ * @param codeAttributeOffset attribute offset within codeToAdjust
+ * @param codeLength length of codeToAdjust
+ * @param isCtorAddingMarkArg are we copying into a tsuper ctor with additional marger arg?
*/
private void adjustCode(
ClassFile dstClassFile,
@@ -631,17 +633,24 @@
}
/**
- * Watch out: String/Integer constants require a LDC or a LDCW opcode depending on their index
+ * Watch out: String/Integer & Class constants require a LDC or a LDCW opcode depending on their index
* in the constant pool. This method tries to prioritize constants with low index,
* to avoid that they get a high index in the target class, which will lead to invalid
* copied LDC operations.
* @param nConstants number of constants in the src constant pool
*/
- private void copyAllNonWideConstants(int nConstants) {
+ private void copyAllNonWideConstants(int nConstants, ReferenceBinding srcTeamBinding, ReferenceBinding dstType) {
Iterator<ConstantPoolObject> it = this._reader.getNonWideConstantIterator(nConstants);
+ if (dstType.isRole())
+ dstType = dstType.enclosingType();
while (it.hasNext()) {
ConstantPoolObject src_cpo = it.next();
- this._writer.writeConstantPoolObject(src_cpo);
+ ConstantPoolObject dst_cpo = src_cpo.isClass()
+ ? new ConstantPoolObject(
+ ClassFileConstants.ClassTag,
+ ConstantPoolObjectMapper.mapClass(srcTeamBinding, src_cpo.getClassObject(), dstType))
+ : src_cpo;
+ this._writer.writeConstantPoolObject(dst_cpo);
}
}
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/bytecode/ConstantPoolObject.java b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/bytecode/ConstantPoolObject.java
index df40af8..1653fc4 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/bytecode/ConstantPoolObject.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/bytecode/ConstantPoolObject.java
@@ -70,6 +70,9 @@
public boolean isField() {
return this._type == FieldRefTag;
}
+ public boolean isClass() {
+ return this._type == ClassTag;
+ }
public boolean isSpecificType(char[][] compoundName) {
if (this._type != ClassTag)
return false;
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 4c6761c..b974cdb 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
@@ -61,8 +61,8 @@
private MethodBinding _dstMethod; //The destination-Method for bytecode-copy will receive transformed bytecode from source-Method
/**
- * @param srcRoleBinaryTypeBinding
- * @param dstRoleSourceTypeBinding
+ * @param srcMethodBinding where bytes are copied from
+ * @param dstMethodBinding where bytes are copied to
*/
public ConstantPoolObjectMapper(
MethodBinding srcMethodBinding,
@@ -169,7 +169,11 @@
* this method realizes the logic of the mapping
* @return destination type
*/
- private static TypeBinding mapClass(MethodBinding srcMethod, TypeBinding typeBinding, ReferenceBinding dstTeam)
+ private static TypeBinding mapClass(MethodBinding srcMethod, TypeBinding typeBinding, ReferenceBinding dstTeam) {
+ return mapClass(getTeam(srcMethod), typeBinding, dstTeam);
+ }
+
+ public static TypeBinding mapClass(ReferenceBinding srcTeamBinding, TypeBinding typeBinding, ReferenceBinding dstTeam)
{
boolean isArrayBinding = typeBinding instanceof ArrayBinding;
int dimension = 0;
@@ -190,7 +194,6 @@
ReferenceBinding refTeamBinding=getTeam(refTypeBinding);
if(refTeamBinding != null)
{
- ReferenceBinding srcTeamBinding = getTeam(srcMethod);
if(srcTeamBinding != null)
{
while ( srcTeamBinding != null
@@ -370,8 +373,6 @@
/**
* Is given method a super-call to the constructor of an __OT__Confined role?
- * @param refMethodBinding
- * @return
*/
private static boolean isConfinedSuperCtor(MethodBinding srcMethod, MethodBinding refMethodBinding) {
// constructor?