Author: ebourg
Date: Wed Apr 23 21:26:13 2014
New Revision: 1589522
URL: http://svn.apache.org/r1589522
Log:
Added the MethodParameters attribute defined in the class format 52 (Java 8)
(BCEL-175)
Added:
commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/MethodParameter.java
(with props)
commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/MethodParameters.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/Attribute.java
commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/DescendingVisitor.java
commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/EmptyVisitor.java
commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/Visitor.java
commons/proper/bcel/trunk/src/main/java/org/apache/bcel/verifier/statics/StringRepresentation.java
commons/proper/bcel/trunk/src/test/java/org/apache/bcel/visitors/CounterVisitor.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=1589522&r1=1589521&r2=1589522&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 Wed
Apr 23 21:26:13 2014
@@ -215,6 +215,11 @@ public interface Constants {
*/
public final static short ACC_ENUM = 0x4000;
+ /** One of the access flags for fields, methods, or classes.
+ * @see #ACC_PUBLIC
+ */
+ public final static short ACC_MANDATED = (short) 0x8000;
+
// Applies to classes compiled by new compilers only
/** One of the access flags for fields, methods, or classes.
* @see #ACC_PUBLIC
@@ -1445,8 +1450,9 @@ public interface Constants {
public static final byte ATTR_ENCLOSING_METHOD = 18;
public static final byte ATTR_STACK_MAP_TABLE = 19;
public static final byte ATTR_BOOTSTRAP_METHODS = 20;
+ public static final byte ATTR_METHOD_PARAMETERS = 21;
- public static final short KNOWN_ATTRIBUTES = 21;
+ public static final short KNOWN_ATTRIBUTES = 22;
// TOFO: FIXXXXX
public static final String[] ATTRIBUTE_NAMES = {
@@ -1457,7 +1463,7 @@ public interface Constants {
"RuntimeVisibleAnnotations", "RuntimeInvisibleAnnotations",
"RuntimeVisibleParameterAnnotations",
"RuntimeInvisibleParameterAnnotations",
"AnnotationDefault", "LocalVariableTypeTable", "EnclosingMethod",
"StackMapTable",
- "BootstrapMethods"
+ "BootstrapMethods", "MethodParameters"
};
/** Constants used in the StackMap attribute.
Modified:
commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/Attribute.java
URL:
http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/Attribute.java?rev=1589522&r1=1589521&r2=1589522&view=diff
==============================================================================
---
commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/Attribute.java
(original)
+++
commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/Attribute.java
Wed Apr 23 21:26:13 2014
@@ -216,6 +216,8 @@ public abstract class Attribute implemen
return new StackMapTable(name_index, length, file,
constant_pool);
case Constants.ATTR_BOOTSTRAP_METHODS:
return new BootstrapMethods(name_index, length, file,
constant_pool);
+ case Constants.ATTR_METHOD_PARAMETERS:
+ return new MethodParameters(name_index, length, file,
constant_pool);
default: // Never reached
throw new IllegalStateException("Unrecognized attribute
type tag parsed: " + tag);
}
Modified:
commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/DescendingVisitor.java
URL:
http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/DescendingVisitor.java?rev=1589522&r1=1589521&r2=1589522&view=diff
==============================================================================
---
commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/DescendingVisitor.java
(original)
+++
commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/DescendingVisitor.java
Wed Apr 23 21:26:13 2014
@@ -437,4 +437,11 @@ public class DescendingVisitor implement
obj.accept(visitor);
stack.pop();
}
+
+ public void visitMethodParameters(MethodParameters obj)
+ {
+ stack.push(obj);
+ obj.accept(visitor);
+ stack.pop();
+ }
}
Modified:
commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/EmptyVisitor.java
URL:
http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/EmptyVisitor.java?rev=1589522&r1=1589521&r2=1589522&view=diff
==============================================================================
---
commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/EmptyVisitor.java
(original)
+++
commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/EmptyVisitor.java
Wed Apr 23 21:26:13 2014
@@ -193,4 +193,8 @@ public class EmptyVisitor implements Vis
public void visitBootstrapMethods(BootstrapMethods obj)
{
}
+
+ public void visitMethodParameters(MethodParameters obj)
+ {
+ }
}
Added:
commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/MethodParameter.java
URL:
http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/MethodParameter.java?rev=1589522&view=auto
==============================================================================
---
commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/MethodParameter.java
(added)
+++
commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/MethodParameter.java
Wed Apr 23 21:26:13 2014
@@ -0,0 +1,118 @@
+/*
+ * 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.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.io.Serializable;
+
+import org.apache.bcel.Constants;
+
+/**
+ * Entry of the parameters table.
+ *
+ * @see <a
href="http://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.7.24">The
class File Format : The MethodParameters Attribute</a>
+ * @since 6.0
+ */
+public class MethodParameter implements Serializable, Cloneable {
+
+ private static final long serialVersionUID = 6014494029439440326L;
+
+ /** Index of the CONSTANT_Utf8_info structure in the constant_pool table
representing the name of the parameter */
+ private int name_index;
+
+ /** The access flags */
+ private int access_flags;
+
+ public MethodParameter() {
+ }
+
+ /**
+ * Construct object from file stream.
+ *
+ * @param file Input stream
+ * @throws java.io.IOException
+ * @throws ClassFormatException
+ */
+ MethodParameter(DataInputStream file) throws IOException {
+ name_index = file.readUnsignedShort();
+ access_flags = file.readUnsignedShort();
+ }
+
+ public int getNameIndex() {
+ return name_index;
+ }
+
+ public void setNameIndex(int name_index) {
+ this.name_index = name_index;
+ }
+
+ /**
+ * Returns the name of the parameter.
+ */
+ public String getParameterName(ConstantPool constant_pool) {
+ if (name_index == 0) {
+ return null;
+ } else {
+ return ((ConstantUtf8) constant_pool.getConstant(name_index,
Constants.CONSTANT_Utf8)).getBytes();
+ }
+ }
+
+ public int getAccessFlags() {
+ return access_flags;
+ }
+
+ public void setAccessFlags(int access_flags) {
+ this.access_flags = access_flags;
+ }
+
+ public boolean isFinal() {
+ return (access_flags & Constants.ACC_FINAL) != 0;
+ }
+
+ public boolean isSynthetic() {
+ return (access_flags & Constants.ACC_SYNTHETIC) != 0;
+ }
+
+ public boolean isMandated() {
+ return (access_flags & Constants.ACC_MANDATED) != 0;
+ }
+
+ /**
+ * Dump object to file stream on binary format.
+ *
+ * @param file Output file stream
+ * @throws IOException
+ */
+ public final void dump(DataOutputStream file) throws IOException {
+ file.writeShort(name_index);
+ file.writeShort(access_flags);
+ }
+
+ /**
+ * @return deep copy of this object
+ */
+ public MethodParameter copy() {
+ try {
+ return (MethodParameter) clone();
+ } catch (CloneNotSupportedException e) {
+ }
+ return null;
+ }
+}
Propchange:
commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/MethodParameter.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/MethodParameter.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added:
commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/MethodParameters.java
URL:
http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/MethodParameters.java?rev=1589522&view=auto
==============================================================================
---
commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/MethodParameters.java
(added)
+++
commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/MethodParameters.java
Wed Apr 23 21:26:13 2014
@@ -0,0 +1,88 @@
+/*
+ * 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.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+
+import org.apache.bcel.Constants;
+
+/**
+ * This class represents a MethodParameters attribute.
+ *
+ * @see <a
href="http://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.7.24">The
class File Format : The MethodParameters Attribute</a>
+ * @since 6.0
+ */
+public class MethodParameters extends Attribute {
+
+ private static final long serialVersionUID = 2500272580422360140L;
+
+ private MethodParameter[] parameters = new MethodParameter[0];
+
+ MethodParameters(int name_index, int length, DataInputStream file,
ConstantPool constant_pool) throws IOException {
+ super(Constants.ATTR_METHOD_PARAMETERS, name_index, length,
constant_pool);
+ System.out.println("new MethodParameters");
+
+ int parameters_count = file.readUnsignedShort();
+ parameters = new MethodParameter[parameters_count];
+ for (int i = 0; i < parameters_count; i++) {
+ parameters[i] = new MethodParameter(file);
+ }
+ }
+
+ public MethodParameter[] getParameters() {
+ return parameters;
+ }
+
+ public void setParameters(MethodParameter[] parameters) {
+ this.parameters = parameters;
+ }
+
+ @Override
+ public void accept(Visitor v) {
+ v.visitMethodParameters(this);
+ }
+
+ @Override
+ public Attribute copy(ConstantPool _constant_pool) {
+ MethodParameters c = (MethodParameters) clone();
+ c.parameters = new MethodParameter[parameters.length];
+
+ for (int i = 0; i < parameters.length; i++) {
+ c.parameters[i] = parameters[i].copy();
+ }
+ c.constant_pool = _constant_pool;
+ return c;
+ }
+
+ /**
+ * Dump method parameters attribute to file stream in binary format.
+ *
+ * @param file Output file stream
+ * @throws IOException
+ */
+ @Override
+ public void dump(DataOutputStream file) throws IOException {
+ super.dump(file);
+ file.writeByte(parameters.length);
+ for (MethodParameter parameter : parameters) {
+ parameter.dump(file);
+ }
+ }
+}
Propchange:
commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/MethodParameters.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/MethodParameters.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Modified:
commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/Visitor.java
URL:
http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/Visitor.java?rev=1589522&r1=1589521&r2=1589522&view=diff
==============================================================================
---
commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/Visitor.java
(original)
+++
commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/Visitor.java
Wed Apr 23 21:26:13 2014
@@ -108,4 +108,6 @@ public interface Visitor
void visitEnclosingMethod(EnclosingMethod obj);
void visitBootstrapMethods(BootstrapMethods obj);
+
+ void visitMethodParameters(MethodParameters obj);
}
Modified:
commons/proper/bcel/trunk/src/main/java/org/apache/bcel/verifier/statics/StringRepresentation.java
URL:
http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/bcel/verifier/statics/StringRepresentation.java?rev=1589522&r1=1589521&r2=1589522&view=diff
==============================================================================
---
commons/proper/bcel/trunk/src/main/java/org/apache/bcel/verifier/statics/StringRepresentation.java
(original)
+++
commons/proper/bcel/trunk/src/main/java/org/apache/bcel/verifier/statics/StringRepresentation.java
Wed Apr 23 21:26:13 2014
@@ -47,6 +47,7 @@ import org.apache.bcel.classfile.LocalVa
import org.apache.bcel.classfile.LocalVariableTable;
import org.apache.bcel.classfile.LocalVariableTypeTable;
import org.apache.bcel.classfile.Method;
+import org.apache.bcel.classfile.MethodParameters;
import org.apache.bcel.classfile.Node;
import org.apache.bcel.classfile.Signature;
import org.apache.bcel.classfile.SourceFile;
@@ -308,4 +309,9 @@ public class StringRepresentation extend
public void visitBootstrapMethods(BootstrapMethods obj) {
tostring = toString(obj);
}
+
+ @Override
+ public void visitMethodParameters(MethodParameters obj) {
+ tostring = toString(obj);
+ }
}
Modified:
commons/proper/bcel/trunk/src/test/java/org/apache/bcel/visitors/CounterVisitor.java
URL:
http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/test/java/org/apache/bcel/visitors/CounterVisitor.java?rev=1589522&r1=1589521&r2=1589522&view=diff
==============================================================================
---
commons/proper/bcel/trunk/src/test/java/org/apache/bcel/visitors/CounterVisitor.java
(original)
+++
commons/proper/bcel/trunk/src/test/java/org/apache/bcel/visitors/CounterVisitor.java
Wed Apr 23 21:26:13 2014
@@ -50,6 +50,7 @@ import org.apache.bcel.classfile.LocalVa
import org.apache.bcel.classfile.LocalVariableTable;
import org.apache.bcel.classfile.LocalVariableTypeTable;
import org.apache.bcel.classfile.Method;
+import org.apache.bcel.classfile.MethodParameters;
import org.apache.bcel.classfile.ParameterAnnotations;
import org.apache.bcel.classfile.Signature;
import org.apache.bcel.classfile.SourceFile;
@@ -144,6 +145,8 @@ public class CounterVisitor implements V
public int stackMapTableEntryCount = 0;
public int bootstrapMethodsCount = 0;
+
+ public int methodParametersCount = 0;
public void visitAnnotation(Annotations obj)
@@ -350,4 +353,9 @@ public class CounterVisitor implements V
{
bootstrapMethodsCount++;
}
+
+ public void visitMethodParameters(MethodParameters obj)
+ {
+ methodParametersCount++;
+ }
}