polygene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nic...@apache.org
Subject [14/50] [abbrv] zest-qi4j git commit: Core Runtime, minor: Fragment and Transient loaders gen 1.7 OpCodes only
Date Fri, 24 Apr 2015 06:36:27 GMT
Core Runtime, minor: Fragment and Transient loaders gen 1.7 OpCodes only

Seems fair as we now require Java 7.


Project: http://git-wip-us.apache.org/repos/asf/zest-qi4j/repo
Commit: http://git-wip-us.apache.org/repos/asf/zest-qi4j/commit/cf478f2f
Tree: http://git-wip-us.apache.org/repos/asf/zest-qi4j/tree/cf478f2f
Diff: http://git-wip-us.apache.org/repos/asf/zest-qi4j/diff/cf478f2f

Branch: refs/heads/master
Commit: cf478f2f608c1730a91aeef6554f0083d885623f
Parents: 3dd0f6a
Author: Paul Merlin <paul@nosphere.org>
Authored: Thu Jun 12 15:04:28 2014 +0200
Committer: Paul Merlin <paul@nosphere.org>
Committed: Thu Jun 12 15:04:28 2014 +0200

----------------------------------------------------------------------
 .../runtime/composite/FragmentClassLoader.java  | 62 ++++++++++++++++----
 .../runtime/composite/TransientClassLoader.java | 31 +++-------
 2 files changed, 59 insertions(+), 34 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/cf478f2f/core/runtime/src/main/java/org/qi4j/runtime/composite/FragmentClassLoader.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/qi4j/runtime/composite/FragmentClassLoader.java
b/core/runtime/src/main/java/org/qi4j/runtime/composite/FragmentClassLoader.java
index 183308f..c140511 100644
--- a/core/runtime/src/main/java/org/qi4j/runtime/composite/FragmentClassLoader.java
+++ b/core/runtime/src/main/java/org/qi4j/runtime/composite/FragmentClassLoader.java
@@ -19,14 +19,55 @@ import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
 import java.util.ArrayList;
 import java.util.List;
-import org.objectweb.asm.*;
+import org.objectweb.asm.ClassWriter;
+import org.objectweb.asm.Label;
+import org.objectweb.asm.MethodVisitor;
+import org.objectweb.asm.Opcodes;
+import org.objectweb.asm.Type;
 import org.qi4j.api.entity.Lifecycle;
 import org.qi4j.api.mixin.Initializable;
 import org.qi4j.api.util.Classes;
 import org.qi4j.api.util.Methods;
 import org.qi4j.functional.Iterables;
 
-import static org.objectweb.asm.Opcodes.*;
+import static org.objectweb.asm.Opcodes.AASTORE;
+import static org.objectweb.asm.Opcodes.ACC_PRIVATE;
+import static org.objectweb.asm.Opcodes.ACC_PUBLIC;
+import static org.objectweb.asm.Opcodes.ACC_STATIC;
+import static org.objectweb.asm.Opcodes.ACC_SUPER;
+import static org.objectweb.asm.Opcodes.ACONST_NULL;
+import static org.objectweb.asm.Opcodes.ALOAD;
+import static org.objectweb.asm.Opcodes.ANEWARRAY;
+import static org.objectweb.asm.Opcodes.ARETURN;
+import static org.objectweb.asm.Opcodes.ASTORE;
+import static org.objectweb.asm.Opcodes.ATHROW;
+import static org.objectweb.asm.Opcodes.BIPUSH;
+import static org.objectweb.asm.Opcodes.CHECKCAST;
+import static org.objectweb.asm.Opcodes.DLOAD;
+import static org.objectweb.asm.Opcodes.DRETURN;
+import static org.objectweb.asm.Opcodes.DUP;
+import static org.objectweb.asm.Opcodes.FLOAD;
+import static org.objectweb.asm.Opcodes.FRETURN;
+import static org.objectweb.asm.Opcodes.GETFIELD;
+import static org.objectweb.asm.Opcodes.GETSTATIC;
+import static org.objectweb.asm.Opcodes.GOTO;
+import static org.objectweb.asm.Opcodes.ICONST_0;
+import static org.objectweb.asm.Opcodes.ICONST_1;
+import static org.objectweb.asm.Opcodes.ICONST_2;
+import static org.objectweb.asm.Opcodes.ICONST_3;
+import static org.objectweb.asm.Opcodes.ICONST_4;
+import static org.objectweb.asm.Opcodes.ICONST_5;
+import static org.objectweb.asm.Opcodes.ILOAD;
+import static org.objectweb.asm.Opcodes.INVOKEINTERFACE;
+import static org.objectweb.asm.Opcodes.INVOKESPECIAL;
+import static org.objectweb.asm.Opcodes.INVOKESTATIC;
+import static org.objectweb.asm.Opcodes.INVOKEVIRTUAL;
+import static org.objectweb.asm.Opcodes.IRETURN;
+import static org.objectweb.asm.Opcodes.LLOAD;
+import static org.objectweb.asm.Opcodes.LRETURN;
+import static org.objectweb.asm.Opcodes.POP;
+import static org.objectweb.asm.Opcodes.PUTSTATIC;
+import static org.objectweb.asm.Opcodes.RETURN;
 import static org.objectweb.asm.Type.getInternalName;
 import static org.qi4j.api.util.Classes.interfacesOf;
 
@@ -34,23 +75,22 @@ import static org.qi4j.api.util.Classes.interfacesOf;
  * Generate subclasses of mixins/modifiers that implement all interfaces not in the class
itself
  * and which delegates those calls to a given composite invoker.
  */
+@SuppressWarnings( "raw" )
 public class FragmentClassLoader
     extends ClassLoader
 {
-    private static int jdkVersion = Opcodes.V1_5;
+    private static final int JDK_VERSION;
     public static final String GENERATED_POSTFIX = "_Stub";
 
     static
     {
         String jdkString = System.getProperty( "java.specification.version" );
-
-        if( jdkString.equals( "1.6" ) )
-        {
-            jdkVersion = Opcodes.V1_6;
-        }
-        else if( jdkString.equals( "1.7" ) )
+        switch( jdkString )
         {
-            jdkVersion = Opcodes.V1_7;
+            case "1.7":
+            default:
+                JDK_VERSION = Opcodes.V1_7;
+                break;
         }
     }
 
@@ -117,7 +157,7 @@ public class FragmentClassLoader
         ClassWriter cw = new ClassWriter( ClassWriter.COMPUTE_MAXS );
 
         // Class definition start
-        cw.visit( jdkVersion, ACC_PUBLIC + ACC_SUPER, classSlash, null, baseClassSlash, null
);
+        cw.visit( JDK_VERSION, ACC_PUBLIC + ACC_SUPER, classSlash, null, baseClassSlash,
null );
 
         // Composite reference
         {

http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/cf478f2f/core/runtime/src/main/java/org/qi4j/runtime/composite/TransientClassLoader.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/qi4j/runtime/composite/TransientClassLoader.java
b/core/runtime/src/main/java/org/qi4j/runtime/composite/TransientClassLoader.java
index 7e9f639..f3e0aa6 100644
--- a/core/runtime/src/main/java/org/qi4j/runtime/composite/TransientClassLoader.java
+++ b/core/runtime/src/main/java/org/qi4j/runtime/composite/TransientClassLoader.java
@@ -76,7 +76,8 @@ import static org.qi4j.api.util.Classes.interfacesOf;
 /**
  * Generate subclasses of classes used for transients. All methods delegate to CompositeInvoker.
  */
-public class TransientClassLoader
+@SuppressWarnings( "raw" )
+/* package */ final class TransientClassLoader
     extends ClassLoader
 {
     private static final int JDK_VERSION;
@@ -88,31 +89,24 @@ public class TransientClassLoader
         switch( jdkString )
         {
             case "1.7":
-                JDK_VERSION = Opcodes.V1_7;
-                break;
-            case "1.6":
-                JDK_VERSION = Opcodes.V1_6;
-                break;
-            case "1.5":
             default:
-                JDK_VERSION = Opcodes.V1_5;
+                JDK_VERSION = Opcodes.V1_7;
                 break;
         }
     }
 
-    public TransientClassLoader( ClassLoader parent )
+    /* package */ TransientClassLoader( ClassLoader parent )
     {
         super( parent );
     }
 
     @Override
-    @SuppressWarnings( "raw" )
     protected Class findClass( String name )
         throws ClassNotFoundException
     {
         if( name.endsWith( GENERATED_POSTFIX ) )
         {
-            Class baseClass = null;
+            Class baseClass;
             String baseName = name.substring( 0, name.length() - 6 );
             try
             {
@@ -152,7 +146,6 @@ public class TransientClassLoader
         return getClass().getClassLoader().loadClass( name );
     }
 
-    @SuppressWarnings( "raw" )
     public static byte[] generateClass( String name, Class baseClass )
         throws ClassNotFoundException
     {
@@ -441,7 +434,6 @@ public class TransientClassLoader
         return cw.toByteArray();
     }
 
-    @SuppressWarnings( "raw" )
     private static boolean isOverloaded( Method method, Class baseClass )
     {
         if( Modifier.isFinal( method.getModifiers() ) )
@@ -454,15 +446,13 @@ public class TransientClassLoader
         }
     }
 
-    @SuppressWarnings( "raw" )
     private static boolean isInternalQi4jMethod( Method method, Class baseClass )
     {
         return isDeclaredIn( method, Initializable.class, baseClass )
                || isDeclaredIn( method, Lifecycle.class, baseClass );
     }
 
-    @SuppressWarnings( {"raw", "unchecked"} )
-    private static boolean isDeclaredIn( Method method, Class clazz, Class baseClass )
+    private static boolean isDeclaredIn( Method method, Class<?> clazz, Class<?>
baseClass )
     {
         if( !clazz.isAssignableFrom( baseClass ) )
         {
@@ -480,7 +470,6 @@ public class TransientClassLoader
         }
     }
 
-    @SuppressWarnings( "raw" )
     private static Class getInterfaceMethodDeclaration( Method method, Class clazz )
         throws NoSuchMethodException
     {
@@ -501,10 +490,9 @@ public class TransientClassLoader
         throw new NoSuchMethodException( method.getName() );
     }
 
-    @SuppressWarnings( {"raw", "unchecked"} )
-    private static boolean isInterfaceMethod( Method method, Class baseClass )
+    private static boolean isInterfaceMethod( Method method, Class<?> baseClass )
     {
-        for( Class aClass : Iterables.filter( Methods.HAS_METHODS, Iterables.map( Classes.RAW_CLASS,
interfacesOf( baseClass ) ) ) )
+        for( Class<?> aClass : Iterables.filter( Methods.HAS_METHODS, Iterables.map(
Classes.RAW_CLASS, interfacesOf( baseClass ) ) ) )
         {
             try
             {
@@ -790,7 +778,6 @@ public class TransientClassLoader
         }
     }
 
-    @SuppressWarnings( "raw" )
     public static boolean isGenerated( Class clazz )
     {
         return clazz.getName().endsWith( GENERATED_POSTFIX );
@@ -801,14 +788,12 @@ public class TransientClassLoader
         return object.getClass().getName().endsWith( GENERATED_POSTFIX );
     }
 
-    @SuppressWarnings( "raw" )
     public Class loadFragmentClass( Class fragmentClass )
         throws ClassNotFoundException
     {
         return loadClass( fragmentClass.getName().replace( '$', '_' ) + GENERATED_POSTFIX
);
     }
 
-    @SuppressWarnings( "raw" )
     public static Class getSourceClass( Class fragmentClass )
     {
         return fragmentClass.getName().endsWith( GENERATED_POSTFIX ) ? fragmentClass.getSuperclass()
: fragmentClass;


Mime
View raw message