You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by se...@apache.org on 2015/08/24 21:46:43 UTC

svn commit: r1697493 - in /commons/proper/bcel/trunk/src: changes/changes.xml main/java/org/apache/commons/bcel6/classfile/Constant.java main/java/org/apache/commons/bcel6/util/BCELifier.java

Author: sebb
Date: Mon Aug 24 19:46:43 2015
New Revision: 1697493

URL: http://svn.apache.org/r1697493
Log:
BCEL-254 Two more methods that would be nice to be public.

Modified:
    commons/proper/bcel/trunk/src/changes/changes.xml
    commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/classfile/Constant.java
    commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/util/BCELifier.java

Modified: commons/proper/bcel/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/changes/changes.xml?rev=1697493&r1=1697492&r2=1697493&view=diff
==============================================================================
--- commons/proper/bcel/trunk/src/changes/changes.xml (original)
+++ commons/proper/bcel/trunk/src/changes/changes.xml Mon Aug 24 19:46:43 2015
@@ -63,6 +63,7 @@ The <action> type attribute can be add,u
 
   <body>
     <release version="6.0" date="TBA" description="Major release with Java 7 and 8 support">
+      <action issue="BCEL-254" type="fix">Two more methods that would be nice to be public.</action>
       <action issue="BCEL-245" type="fix">Type class includes constants that reference subclasses</action>
       <action issue="BCEL-253" type="fix">Pass 3b verifier is too strict.</action>
       <action issue="BCEL-248" type="fix">StackMapTable[Entry] should be removed and improvements merged into StackMap[Entry]</action>

Modified: commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/classfile/Constant.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/classfile/Constant.java?rev=1697493&r1=1697492&r2=1697493&view=diff
==============================================================================
--- commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/classfile/Constant.java (original)
+++ commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/classfile/Constant.java Mon Aug 24 19:46:43 2015
@@ -125,8 +125,9 @@ public abstract class Constant implement
      *
      * @param input Input stream
      * @return Constant object
+     * @since 6.0 made public
      */
-    static Constant readConstant( DataInput input ) throws IOException,
+    public static Constant readConstant( DataInput input ) throws IOException,
             ClassFormatException {
         byte b = input.readByte(); // Read tag byte
         switch (b) {

Modified: commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/util/BCELifier.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/util/BCELifier.java?rev=1697493&r1=1697492&r2=1697493&view=diff
==============================================================================
--- commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/util/BCELifier.java (original)
+++ commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/util/BCELifier.java Mon Aug 24 19:46:43 2015
@@ -45,16 +45,21 @@ import org.apache.commons.bcel6.generic.
  */
 public class BCELifier extends org.apache.commons.bcel6.classfile.EmptyVisitor {
 
-    private static final int FLAG_FOR_UNKNOWN = -1;
-    private static final int FLAG_FOR_CLASS = 0;
-    private static final int FLAG_FOR_METHOD = 1;
+    /**
+     * Enum corresponding to flag source.
+     */
+    public enum FLAGS {
+        UNKNOWN,
+        CLASS,
+        METHOD,
+    };
+
     // The base package name for imports; assumes Constants is at the top level
     private static final String BASE_PACKAGE = Constants.class.getPackage().getName();
     private final JavaClass _clazz;
     private final PrintWriter _out;
     private final ConstantPoolGen _cp;
 
-
     /** @param clazz Java class to "decompile"
      * @param out where to output Java program
      */
@@ -98,7 +103,7 @@ public class BCELifier extends org.apach
         _out.println("    _cg = new ClassGen(\""
                 + (("".equals(package_name)) ? class_name : package_name + "." + class_name)
                 + "\", \"" + super_name + "\", " + "\"" + clazz.getSourceFileName() + "\", "
-                + printFlags(clazz.getAccessFlags(), FLAG_FOR_CLASS) + ", "
+                + printFlags(clazz.getAccessFlags(), FLAGS.CLASS) + ", "
                 + "new String[] { " + inter + " });");
         _out.println();
         _out.println("    _cp = _cg.getConstantPool();");
@@ -172,7 +177,7 @@ public class BCELifier extends org.apach
         MethodGen mg = new MethodGen(method, _clazz.getClassName(), _cp);
         _out.println("    InstructionList il = new InstructionList();");
         _out.println("    MethodGen method = new MethodGen("
-                + printFlags(method.getAccessFlags(), FLAG_FOR_METHOD) + ", "
+                + printFlags(method.getAccessFlags(), FLAGS.METHOD) + ", "
                 + printType(mg.getReturnType()) + ", "
                 + printArgumentTypes(mg.getArgumentTypes()) + ", "
                 + "new String[] { " + Utility.printArray(mg.getArgumentNames(), false, true)
@@ -188,22 +193,28 @@ public class BCELifier extends org.apach
 
 
     static String printFlags( int flags ) {
-        return printFlags(flags, FLAG_FOR_UNKNOWN);
+        return printFlags(flags, FLAGS.UNKNOWN);
     }
 
-
-    static String printFlags( int flags, int reason ) {
+    /**
+     * Return a string with the flag settings
+     * @param flags the flags field to interpret
+     * @param location the item type
+     * @return the formatted string
+     * @since 6.0 made public
+     */
+    public static String printFlags( int flags, FLAGS location ) {
         if (flags == 0) {
             return "0";
         }
         StringBuilder buf = new StringBuilder();
         for (int i = 0, pow = 1; pow <= Constants.MAX_ACC_FLAG; i++) {
             if ((flags & pow) != 0) {
-                if ((pow == Constants.ACC_SYNCHRONIZED) && (reason == FLAG_FOR_CLASS)) {
+                if ((pow == Constants.ACC_SYNCHRONIZED) && (location == FLAGS.CLASS)) {
                     buf.append("ACC_SUPER | ");
-                } else if ((pow == Constants.ACC_VOLATILE) && (reason == FLAG_FOR_METHOD)) {
+                } else if ((pow == Constants.ACC_VOLATILE) && (location == FLAGS.METHOD)) {
                     buf.append("ACC_BRIDGE | ");
-                } else if ((pow == Constants.ACC_TRANSIENT) && (reason == FLAG_FOR_METHOD)) {
+                } else if ((pow == Constants.ACC_TRANSIENT) && (location == FLAGS.METHOD)) {
                     buf.append("ACC_VARARGS | ");
                 } else {
                     if (i < Constants.ACCESS_NAMES.length) {