You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ma...@apache.org on 2012/08/27 00:02:59 UTC

svn commit: r1377530 - in /commons/proper/bcel/trunk/src/main/java/org/apache/bcel: Constants.java classfile/Constant.java classfile/ConstantInvokeDynamic.java classfile/ConstantMethodHandle.java classfile/ConstantMethodType.java

Author: markt
Date: Sun Aug 26 22:02:59 2012
New Revision: 1377530

URL: http://svn.apache.org/viewvc?rev=1377530&view=rev
Log:
https://issues.apache.org/bugzilla/show_bug.cgi?id=51661
Add some initial plumbing for InvokeDynamic (Java 7) support. This is not complete.

Added:
    commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/ConstantInvokeDynamic.java   (with props)
    commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/ConstantMethodHandle.java   (with props)
    commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/ConstantMethodType.java   (with props)
Modified:
    commons/proper/bcel/trunk/src/main/java/org/apache/bcel/Constants.java
    commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/Constant.java

Modified: commons/proper/bcel/trunk/src/main/java/org/apache/bcel/Constants.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/bcel/Constants.java?rev=1377530&r1=1377529&r2=1377530&view=diff
==============================================================================
--- commons/proper/bcel/trunk/src/main/java/org/apache/bcel/Constants.java (original)
+++ commons/proper/bcel/trunk/src/main/java/org/apache/bcel/Constants.java Sun Aug 26 22:02:59 2012
@@ -256,13 +256,23 @@ public interface Constants {
   /** Marks a constant pool entry as a name and type.  */
   public final static byte CONSTANT_NameAndType        = 12;
 
+  /** Marks a constant pool entry as a Method Handle.  */
+  public static final byte CONSTANT_MethodHandle       = 15;
+
+  /** Marks a constant pool entry as a Method Type.    */
+  public static final byte CONSTANT_MethodType         = 16;
+
+  /** Marks a constant pool entry as an Invoke Dynamic */
+  public static final byte CONSTANT_InvokeDynamic      = 18;
+
   /** The names of the types of entries in a constant pool. */
-  public final static String[] CONSTANT_NAMES = {
+  public static final String[] CONSTANT_NAMES = {
     "", "CONSTANT_Utf8", "", "CONSTANT_Integer",
     "CONSTANT_Float", "CONSTANT_Long", "CONSTANT_Double",
     "CONSTANT_Class", "CONSTANT_String", "CONSTANT_Fieldref",
     "CONSTANT_Methodref", "CONSTANT_InterfaceMethodref",
-    "CONSTANT_NameAndType" };
+    "CONSTANT_NameAndType", "CONSTANT_MethodHandle",
+    "CONSTANT_MethodType", "CONSTANT_InvokeDynamic" };
 
   /** The name of the static initializer, also called "class
    *  initialization method" or "interface initialization

Modified: commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/Constant.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/Constant.java?rev=1377530&r1=1377529&r2=1377530&view=diff
==============================================================================
--- commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/Constant.java (original)
+++ commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/Constant.java Sun Aug 26 22:02:59 2012
@@ -146,6 +146,12 @@ public abstract class Constant implement
                 return new ConstantNameAndType(file);
             case Constants.CONSTANT_Utf8:
                 return new ConstantUtf8(file);
+            case Constants.CONSTANT_MethodHandle:
+                return new ConstantMethodHandle(file);
+            case Constants.CONSTANT_MethodType:
+                return new ConstantMethodType(file);
+            case Constants.CONSTANT_InvokeDynamic:
+                return new ConstantInvokeDynamic(file);
             default:
                 throw new ClassFormatException("Invalid byte tag in constant pool: " + b);
         }

Added: commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/ConstantInvokeDynamic.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/ConstantInvokeDynamic.java?rev=1377530&view=auto
==============================================================================
--- commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/ConstantInvokeDynamic.java (added)
+++ commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/ConstantInvokeDynamic.java Sun Aug 26 22:02:59 2012
@@ -0,0 +1,123 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package org.apache.bcel.classfile;
+
+import java.io.DataInput;
+import java.io.DataOutputStream;
+import java.io.IOException;
+
+import org.apache.bcel.Constants;
+
+/** 
+ * This class is derived from the abstract 
+ * <A HREF="org.apache.bcel.classfile.Constant.html">Constant</A> class 
+ * and represents a reference to a invoke dynamic.
+ * 
+ * @see     Constant
+ */
+public final class ConstantInvokeDynamic extends Constant {
+
+    private static final long serialVersionUID = 4310367359017396174L;
+    private int bootstrap_method_attr_index;
+    private int name_and_type_index;
+
+
+    /**
+     * Initialize from another object.
+     */
+    public ConstantInvokeDynamic(ConstantInvokeDynamic c) {
+        this(c.getBootstrapMethodAttrIndex(), c.getNameAndTypeIndex());
+    }
+
+
+    /**
+     * Initialize instance from file data.
+     *
+     * @param file Input stream
+     * @throws IOException
+     */
+    ConstantInvokeDynamic(DataInput file) throws IOException {
+        this(file.readUnsignedShort(), file.readUnsignedShort());
+    }
+
+
+    public ConstantInvokeDynamic(int bootstrap_method_attr_index,
+            int name_and_type_index) {
+        super(Constants.CONSTANT_InvokeDynamic);
+        this.bootstrap_method_attr_index = bootstrap_method_attr_index;
+        this.name_and_type_index = name_and_type_index;
+    }
+
+
+    /**
+     * Called by objects that are traversing the nodes of the tree implicitly
+     * defined by the contents of a Java class. I.e., the hierarchy of methods,
+     * fields, attributes, etc. spawns a tree of objects.
+     *
+     * @param v Visitor object
+     */
+    @Override
+    public void accept( Visitor v ) {
+        // TODO Add .visitMethodType to Visitor interface
+    }
+
+
+    /**
+     * Dump name and signature index to file stream in binary format.
+     *
+     * @param file Output file stream
+     * @throws IOException
+     */
+    @Override
+    public final void dump( DataOutputStream file ) throws IOException {
+        file.writeByte(tag);
+        file.writeShort(bootstrap_method_attr_index);
+        file.writeShort(name_and_type_index);
+    }
+
+
+    public int getBootstrapMethodAttrIndex() {
+        return bootstrap_method_attr_index;
+    }
+
+
+    public void setBootstrapMethodAttrIndex(int bootstrap_method_attr_index) {
+        this.bootstrap_method_attr_index = bootstrap_method_attr_index;
+    }
+
+
+    public int getNameAndTypeIndex() {
+        return name_and_type_index;
+    }
+
+
+    public void setNameAndTypeIndex(int name_and_type_index) {
+        this.name_and_type_index = name_and_type_index;
+    }
+
+
+    /**
+     * @return String representation
+     */
+    @Override
+    public final String toString() {
+        return super.toString() + "(bootstrap_method_attr_index = " +
+                bootstrap_method_attr_index + ", name_and_type_index = " +
+                name_and_type_index + ")";
+    }
+}

Propchange: commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/ConstantInvokeDynamic.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/ConstantMethodHandle.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/ConstantMethodHandle.java?rev=1377530&view=auto
==============================================================================
--- commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/ConstantMethodHandle.java (added)
+++ commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/ConstantMethodHandle.java Sun Aug 26 22:02:59 2012
@@ -0,0 +1,121 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package org.apache.bcel.classfile;
+
+import java.io.DataInput;
+import java.io.DataOutputStream;
+import java.io.IOException;
+
+import org.apache.bcel.Constants;
+
+/** 
+ * This class is derived from the abstract 
+ * <A HREF="org.apache.bcel.classfile.Constant.html">Constant</A> class 
+ * and represents a reference to a method handle.
+ * 
+ * @see     Constant
+ */
+public final class ConstantMethodHandle extends Constant {
+
+    private static final long serialVersionUID = -7875124116920198044L;
+    private int reference_kind;
+    private int reference_index;
+
+
+    /**
+     * Initialize from another object.
+     */
+    public ConstantMethodHandle(ConstantMethodHandle c) {
+        this(c.getReferenceKind(), c.getReferenceIndex());
+    }
+
+
+    /**
+     * Initialize instance from file data.
+     *
+     * @param file Input stream
+     * @throws IOException
+     */
+    ConstantMethodHandle(DataInput file) throws IOException {
+        this(file.readUnsignedByte(), file.readUnsignedShort());
+    }
+
+
+    public ConstantMethodHandle(int reference_kind, int reference_index) {
+        super(Constants.CONSTANT_MethodHandle);
+        this.reference_kind = reference_kind;
+        this.reference_index = reference_index;
+    }
+
+
+    /**
+     * Called by objects that are traversing the nodes of the tree implicitly
+     * defined by the contents of a Java class. I.e., the hierarchy of methods,
+     * fields, attributes, etc. spawns a tree of objects.
+     *
+     * @param v Visitor object
+     */
+    @Override
+    public void accept( Visitor v ) {
+        // TODO Add .visitMethodHandle to Visitor interface
+    }
+
+
+    /**
+     * Dump method kind and index to file stream in binary format.
+     *
+     * @param file Output file stream
+     * @throws IOException
+     */
+    @Override
+    public final void dump( DataOutputStream file ) throws IOException {
+        file.writeByte(tag);
+        file.writeByte(reference_kind);
+        file.writeShort(reference_index);
+    }
+
+
+    public int getReferenceKind() {
+        return reference_kind;
+    }
+
+
+    public void setReferenceKind(int reference_kind) {
+        this.reference_kind = reference_kind;
+    }
+
+
+    public int getReferenceIndex() {
+        return reference_index;
+    }
+
+
+    public void setReferenceIndex(int reference_index) {
+        this.reference_index = reference_index;
+    }
+
+
+    /**
+     * @return String representation
+     */
+    @Override
+    public final String toString() {
+        return super.toString() + "(reference_kind = " + reference_kind +
+                ", reference_index = " + reference_index + ")";
+    }
+}

Propchange: commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/ConstantMethodHandle.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/ConstantMethodType.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/ConstantMethodType.java?rev=1377530&view=auto
==============================================================================
--- commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/ConstantMethodType.java (added)
+++ commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/ConstantMethodType.java Sun Aug 26 22:02:59 2012
@@ -0,0 +1,107 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package org.apache.bcel.classfile;
+
+import java.io.DataInput;
+import java.io.DataOutputStream;
+import java.io.IOException;
+
+import org.apache.bcel.Constants;
+
+/** 
+ * This class is derived from the abstract 
+ * <A HREF="org.apache.bcel.classfile.Constant.html">Constant</A> class 
+ * and represents a reference to a method type.
+ * 
+ * @see     Constant
+ */
+public final class ConstantMethodType extends Constant {
+
+    private static final long serialVersionUID = 6750768220616618881L;
+    private int descriptor_index;
+
+
+    /**
+     * Initialize from another object.
+     */
+    public ConstantMethodType(ConstantMethodType c) {
+        this(c.getDescriptorIndex());
+    }
+
+
+    /**
+     * Initialize instance from file data.
+     *
+     * @param file Input stream
+     * @throws IOException
+     */
+    ConstantMethodType(DataInput file) throws IOException {
+        this(file.readUnsignedShort());
+    }
+
+
+    public ConstantMethodType(int descriptor_index) {
+        super(Constants.CONSTANT_MethodType);
+        this.descriptor_index = descriptor_index;
+    }
+
+
+    /**
+     * Called by objects that are traversing the nodes of the tree implicitly
+     * defined by the contents of a Java class. I.e., the hierarchy of methods,
+     * fields, attributes, etc. spawns a tree of objects.
+     *
+     * @param v Visitor object
+     */
+    @Override
+    public void accept( Visitor v ) {
+        // TODO Add .visitMethodType to Visitor interface
+    }
+
+
+    /**
+     * Dump name and signature index to file stream in binary format.
+     *
+     * @param file Output file stream
+     * @throws IOException
+     */
+    @Override
+    public final void dump( DataOutputStream file ) throws IOException {
+        file.writeByte(tag);
+        file.writeShort(descriptor_index);
+    }
+
+
+    public int getDescriptorIndex() {
+        return descriptor_index;
+    }
+
+
+    public void setDescriptorIndex(int descriptor_index) {
+        this.descriptor_index = descriptor_index;
+    }
+
+
+    /**
+     * @return String representation
+     */
+    @Override
+    public final String toString() {
+        return super.toString() + "(descriptor_index = " + descriptor_index + ")";
+    }
+}

Propchange: commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/ConstantMethodType.java
------------------------------------------------------------------------------
    svn:eol-style = native