summaryrefslogtreecommitdiff
path: root/src/fjbg/ch/epfl/lamp
diff options
context:
space:
mode:
Diffstat (limited to 'src/fjbg/ch/epfl/lamp')
-rw-r--r--src/fjbg/ch/epfl/lamp/fjbg/FJBGContext.java8
-rw-r--r--src/fjbg/ch/epfl/lamp/fjbg/JEnclosingMethodAttribute.java39
2 files changed, 47 insertions, 0 deletions
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);
+ }
+}