Index: ClassFile.java =================================================================== RCS file: /home/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ClassFile.java,v retrieving revision 1.79 diff -u -r1.79 ClassFile.java --- ClassFile.java 21 Oct 2004 13:34:44 -0000 1.79 +++ ClassFile.java 19 Nov 2004 21:27:51 -0000 @@ -20,6 +20,7 @@ import org.eclipse.jdt.internal.compiler.codegen.*; import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; import org.eclipse.jdt.internal.compiler.impl.Constant; +import org.eclipse.jdt.internal.compiler.impl.ReferenceContext; import org.eclipse.jdt.internal.compiler.impl.StringConstant; import org.eclipse.jdt.internal.compiler.lookup.*; import org.eclipse.jdt.internal.compiler.problem.ProblemSeverities; @@ -343,6 +344,44 @@ contents[contentsOffset++] = (byte) (signatureIndex >> 8); contents[contentsOffset++] = (byte) signatureIndex; attributeNumber++; + } + if (targetJDK >= ClassFileConstants.JDK1_5 + && (this.referenceBinding.isAnonymousType() || this.referenceBinding.isLocalType())) { + // add enclosing method attribute (1.5 mode only) + if (contentsOffset + 10 >= contents.length) { + resizeContents(10); + } + int enclosingMethodAttributeNameIndex = + constantPool.literalIndex(AttributeNamesConstants.EnclosingMethodName); + contents[contentsOffset++] = (byte) (enclosingMethodAttributeNameIndex >> 8); + contents[contentsOffset++] = (byte) enclosingMethodAttributeNameIndex; + // the length of a signature attribute is equals to 2 + contents[contentsOffset++] = 0; + contents[contentsOffset++] = 0; + contents[contentsOffset++] = 0; + contents[contentsOffset++] = 4; + + int enclosingTypeIndex = constantPool.literalIndexForType(this.referenceBinding.enclosingType().constantPoolName()); + contents[contentsOffset++] = (byte) (enclosingTypeIndex >> 8); + contents[contentsOffset++] = (byte) enclosingTypeIndex; + byte methodIndexByte1 = 0; + byte methodIndexByte2 = 0; + if (this.referenceBinding.scope != null) { + MethodScope methodScope = this.referenceBinding.scope.methodScope(); + if (methodScope != null) { + ReferenceContext referenceContext = methodScope.referenceContext; + if (referenceContext instanceof AbstractMethodDeclaration) { + AbstractMethodDeclaration methodDeclaration = (AbstractMethodDeclaration) referenceContext; + MethodBinding methodBinding = methodDeclaration.binding; + int enclosingMethodIndex = constantPool.literalIndexForMethod(methodBinding.selector, methodBinding.signature()); + methodIndexByte1 = (byte) (enclosingMethodIndex >> 8); + methodIndexByte2 = (byte) enclosingMethodIndex; + } + } + } + contents[contentsOffset++] = methodIndexByte1; + contents[contentsOffset++] = methodIndexByte2; + attributeNumber++; } // update the number of attributes