From a061def4dd3d16b226f17a5246470255623177c2 Mon Sep 17 00:00:00 2001 From: Iulian Dragos Date: Fri, 12 Nov 2010 16:26:17 +0000 Subject: Generate EnclosingMethod classfile attributes. This should fix java signatures when they refer to method type parameters. I unrolled Adriaans previous fix for #3249, as this one is more general. Closes #3249, review by moors. --- src/fjbg/ch/epfl/lamp/fjbg/FJBGContext.java | 8 +++++ .../epfl/lamp/fjbg/JEnclosingMethodAttribute.java | 39 ++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 src/fjbg/ch/epfl/lamp/fjbg/JEnclosingMethodAttribute.java (limited to 'src/fjbg/ch') diff --git a/src/fjbg/ch/epfl/lamp/fjbg/FJBGContext.java b/src/fjbg/ch/epfl/lamp/fjbg/FJBGContext.java index 569a9ac272..07030fbb9c 100644 --- a/src/fjbg/ch/epfl/lamp/fjbg/FJBGContext.java +++ b/src/fjbg/ch/epfl/lamp/fjbg/FJBGContext.java @@ -145,6 +145,14 @@ public class FJBGContext { return new JOtherAttribute(this, clazz, owner, name, contents, length); } + public JEnclosingMethodAttribute JEnclosingMethodAttribute(JClass clazz, + String className, + String methodName, + JType methodType) { + return new JEnclosingMethodAttribute(this, clazz, className, methodName, methodType); + } + + public JOtherAttribute JOtherAttribute(JClass clazz, Object owner, String name, diff --git a/src/fjbg/ch/epfl/lamp/fjbg/JEnclosingMethodAttribute.java b/src/fjbg/ch/epfl/lamp/fjbg/JEnclosingMethodAttribute.java new file mode 100644 index 0000000000..4351e2fc7b --- /dev/null +++ b/src/fjbg/ch/epfl/lamp/fjbg/JEnclosingMethodAttribute.java @@ -0,0 +1,39 @@ + +package ch.epfl.lamp.fjbg; + +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; + +/** + * Sourcefile attribute, which can be attached to class files to + * associate them with their enclosing method. A class may have + * at most one EclosingMethod attribute. + * + * @version 1.0 + * @author Michel Schinz + */ + +public class JEnclosingMethodAttribute extends JAttribute { + protected final int classIdx; + protected final int nameAndTypeIdx; + + public JEnclosingMethodAttribute(FJBGContext context, + JClass clazz, + String className, String methodName, JType methodType) { + super(context, clazz); + this.classIdx = clazz.getConstantPool().addClass(className); + this.nameAndTypeIdx = clazz.getConstantPool().addNameAndType(methodName, methodType.getSignature()); + } + + public String getName() { return "EnclosingMethod"; } + + protected int getSize() { + return 4; + } + + protected void writeContentsTo(DataOutputStream stream) throws IOException { + stream.writeShort(classIdx); + stream.writeShort(nameAndTypeIdx); + } +} -- cgit v1.2.3