polygene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From paulmer...@apache.org
Subject [5/6] polygene-java git commit: Use AccessibleObjects.accessible(T) everywhere applicable
Date Mon, 05 Jun 2017 09:54:44 GMT
Use AccessibleObjects.accessible(T) everywhere applicable


Project: http://git-wip-us.apache.org/repos/asf/polygene-java/repo
Commit: http://git-wip-us.apache.org/repos/asf/polygene-java/commit/a4e13185
Tree: http://git-wip-us.apache.org/repos/asf/polygene-java/tree/a4e13185
Diff: http://git-wip-us.apache.org/repos/asf/polygene-java/diff/a4e13185

Branch: refs/heads/develop
Commit: a4e13185803be0fc1d899d45187d5cbb1eb13052
Parents: b50f0ac
Author: Paul Merlin <paulmerlin@apache.org>
Authored: Mon Jun 5 08:27:35 2017 +0200
Committer: Paul Merlin <paulmerlin@apache.org>
Committed: Mon Jun 5 10:42:11 2017 +0200

----------------------------------------------------------------------
 .../polygene/api/composite/PropertyMapperTest.java |  4 ++--
 .../layered/LayeredApplicationAssembler.java       | 17 +++++++----------
 .../bootstrap/layered/LayeredLayerAssembler.java   |  8 ++++----
 .../polygene/runtime/bootstrap/AssemblyHelper.java |  5 +++--
 .../composite/InterfaceDefaultMethodsMixin.java    |  5 +++--
 .../polygene/index/solr/EmbeddedSolrService.java   |  5 +++--
 .../apache/polygene/sample/rental/web/Page.java    |  6 +++---
 7 files changed, 25 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a4e13185/core/api/src/test/java/org/apache/polygene/api/composite/PropertyMapperTest.java
----------------------------------------------------------------------
diff --git a/core/api/src/test/java/org/apache/polygene/api/composite/PropertyMapperTest.java
b/core/api/src/test/java/org/apache/polygene/api/composite/PropertyMapperTest.java
index d285102..c2b6ccb 100644
--- a/core/api/src/test/java/org/apache/polygene/api/composite/PropertyMapperTest.java
+++ b/core/api/src/test/java/org/apache/polygene/api/composite/PropertyMapperTest.java
@@ -30,6 +30,7 @@ import java.util.Map;
 import java.util.Set;
 import org.junit.Test;
 
+import static org.apache.polygene.api.util.AccessibleObjects.accessible;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 
@@ -41,8 +42,7 @@ public class PropertyMapperTest
     {
         try
         {
-            MAP_TO_TYPE = PropertyMapper.class.getDeclaredMethod( "mapToType", Composite.class,
Type.class, Object.class );
-            MAP_TO_TYPE.setAccessible( true );
+            MAP_TO_TYPE = accessible( PropertyMapper.class.getDeclaredMethod( "mapToType",
Composite.class, Type.class, Object.class ) );
         }
         catch( NoSuchMethodException e )
         {

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a4e13185/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/layered/LayeredApplicationAssembler.java
----------------------------------------------------------------------
diff --git a/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/layered/LayeredApplicationAssembler.java
b/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/layered/LayeredApplicationAssembler.java
index 7301907..3ed2e9f 100644
--- a/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/layered/LayeredApplicationAssembler.java
+++ b/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/layered/LayeredApplicationAssembler.java
@@ -36,6 +36,8 @@ import org.apache.polygene.bootstrap.AssemblyException;
 import org.apache.polygene.bootstrap.Energy4Java;
 import org.apache.polygene.bootstrap.LayerAssembly;
 
+import static org.apache.polygene.api.util.AccessibleObjects.accessible;
+
 public abstract class LayeredApplicationAssembler
     implements ApplicationAssembler
 {
@@ -200,8 +202,7 @@ public abstract class LayeredApplicationAssembler
     {
         try
         {
-            Method factoryMethod = layerAssemblerClass.getDeclaredMethod( "create", LayerAssembly.class
);
-            factoryMethod.setAccessible( true );
+            Method factoryMethod = accessible( layerAssemblerClass.getDeclaredMethod( "create",
LayerAssembly.class ) );
             int modifiers = factoryMethod.getModifiers();
             if( Modifier.isStatic( modifiers ) && LayerAssembler.class.isAssignableFrom(
factoryMethod.getReturnType() ) )
             {
@@ -212,8 +213,7 @@ public abstract class LayeredApplicationAssembler
         {
             try
             {
-                Method factoryMethod = layerAssemblerClass.getDeclaredMethod( "create" );
-                factoryMethod.setAccessible( true );
+                Method factoryMethod = accessible( layerAssemblerClass.getDeclaredMethod(
"create" ) );
                 int modifiers = factoryMethod.getModifiers();
                 if( Modifier.isStatic( modifiers ) && LayerAssembler.class.isAssignableFrom(
factoryMethod.getReturnType() ) )
                 {
@@ -237,8 +237,7 @@ public abstract class LayeredApplicationAssembler
             Constructor<? extends LayerAssembler> constructor = layerAssemblerClass.getConstructor(
LayerAssembly.class );
             if( constructor != null )
             {
-                constructor.setAccessible( true );
-                return constructor.newInstance( assembly );
+                return accessible( constructor ).newInstance( assembly );
             }
         }
         catch( NoSuchMethodException e )
@@ -248,8 +247,7 @@ public abstract class LayeredApplicationAssembler
                 Constructor<? extends LayerAssembler> constructor = layerAssemblerClass.getDeclaredConstructor();
                 if( constructor != null )
                 {
-                    constructor.setAccessible( true );
-                    return constructor.newInstance();
+                    return accessible( constructor ).newInstance();
                 }
             }
             catch( NoSuchMethodException e1 )
@@ -268,8 +266,7 @@ public abstract class LayeredApplicationAssembler
             Field field = clazz.getDeclaredField( "NAME" );
             if( Modifier.isStatic( field.getModifiers() ) )
             {
-                field.setAccessible( true );
-                field.set( null, classname );
+                accessible( field ).set( null, classname );
             }
         }
         catch( Exception e )

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a4e13185/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/layered/LayeredLayerAssembler.java
----------------------------------------------------------------------
diff --git a/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/layered/LayeredLayerAssembler.java
b/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/layered/LayeredLayerAssembler.java
index 9866f89..0f0b624 100644
--- a/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/layered/LayeredLayerAssembler.java
+++ b/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/layered/LayeredLayerAssembler.java
@@ -24,6 +24,8 @@ import java.util.HashMap;
 import org.apache.polygene.bootstrap.LayerAssembly;
 import org.apache.polygene.bootstrap.ModuleAssembly;
 
+import static org.apache.polygene.api.util.AccessibleObjects.accessible;
+
 public abstract class LayeredLayerAssembler
     implements LayerAssembler
 {
@@ -76,14 +78,12 @@ public abstract class LayeredLayerAssembler
         try
         {
             Constructor<? extends ModuleAssembler> assemblyConstructor = modulerAssemblerClass.getDeclaredConstructor(
ModuleAssembly.class );
-            assemblyConstructor.setAccessible( true );
-            moduleAssembler = assemblyConstructor.newInstance( constructorArgument );
+            moduleAssembler = accessible( assemblyConstructor ).newInstance( constructorArgument
);
         }
         catch( NoSuchMethodException e )
         {
             Constructor<? extends ModuleAssembler> assemblyConstructor = modulerAssemblerClass.getDeclaredConstructor();
-            assemblyConstructor.setAccessible( true );
-            moduleAssembler = assemblyConstructor.newInstance();
+            moduleAssembler = accessible( assemblyConstructor ).newInstance();
         }
         return moduleAssembler;
     }

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a4e13185/core/runtime/src/main/java/org/apache/polygene/runtime/bootstrap/AssemblyHelper.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/polygene/runtime/bootstrap/AssemblyHelper.java
b/core/runtime/src/main/java/org/apache/polygene/runtime/bootstrap/AssemblyHelper.java
index b456a1e..206289a 100644
--- a/core/runtime/src/main/java/org/apache/polygene/runtime/bootstrap/AssemblyHelper.java
+++ b/core/runtime/src/main/java/org/apache/polygene/runtime/bootstrap/AssemblyHelper.java
@@ -38,6 +38,8 @@ import org.apache.polygene.runtime.composite.FragmentClassLoader;
 import org.apache.polygene.runtime.composite.MixinModel;
 import org.apache.polygene.runtime.composite.SideEffectModel;
 
+import static org.apache.polygene.api.util.AccessibleObjects.accessible;
+
 /**
  * This helper is used when building the application model. It keeps track
  * of already created classloaders and various models
@@ -147,8 +149,7 @@ public class AssemblyHelper
                     {
                         @SuppressWarnings("unchecked")
                         Constructor<AppliesToFilter> cons = (Constructor<AppliesToFilter>)
appliesToClass.getDeclaredConstructor();
-                        cons.setAccessible(true);
-                        filter = cons.newInstance();
+                        filter = accessible( cons ).newInstance();
                     }
                     catch( Exception e )
                     {

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a4e13185/core/runtime/src/main/java/org/apache/polygene/runtime/composite/InterfaceDefaultMethodsMixin.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/polygene/runtime/composite/InterfaceDefaultMethodsMixin.java
b/core/runtime/src/main/java/org/apache/polygene/runtime/composite/InterfaceDefaultMethodsMixin.java
index cb2875f..938cde8 100644
--- a/core/runtime/src/main/java/org/apache/polygene/runtime/composite/InterfaceDefaultMethodsMixin.java
+++ b/core/runtime/src/main/java/org/apache/polygene/runtime/composite/InterfaceDefaultMethodsMixin.java
@@ -30,6 +30,8 @@ import org.apache.polygene.api.composite.Composite;
 import org.apache.polygene.api.composite.DefaultMethodsFilter;
 import org.apache.polygene.api.injection.scope.This;
 
+import static org.apache.polygene.api.util.AccessibleObjects.accessible;
+
 @AppliesTo( { DefaultMethodsFilter.class } )
 public class InterfaceDefaultMethodsMixin
     implements InvocationHandler
@@ -65,8 +67,7 @@ public class InterfaceDefaultMethodsMixin
         try
         {
             Constructor<MethodHandles.Lookup> constructor = MethodHandles.Lookup.class.getDeclaredConstructor(
Class.class, int.class );
-            constructor.setAccessible( true );
-            MethodHandles.Lookup lookup = constructor.newInstance( declaringClass, MethodHandles.Lookup.PRIVATE
);
+            MethodHandles.Lookup lookup = accessible( constructor ).newInstance( declaringClass,
MethodHandles.Lookup.PRIVATE );
             MethodHandle handle = lookup.unreflectSpecial( method, declaringClass );
             return ( proxy, args ) -> handle.bindTo( proxy ).invokeWithArguments( args
);
         }

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a4e13185/extensions/indexing-solr/src/main/java/org/apache/polygene/index/solr/EmbeddedSolrService.java
----------------------------------------------------------------------
diff --git a/extensions/indexing-solr/src/main/java/org/apache/polygene/index/solr/EmbeddedSolrService.java
b/extensions/indexing-solr/src/main/java/org/apache/polygene/index/solr/EmbeddedSolrService.java
index 29653a3..1d2dbb3 100644
--- a/extensions/indexing-solr/src/main/java/org/apache/polygene/index/solr/EmbeddedSolrService.java
+++ b/extensions/indexing-solr/src/main/java/org/apache/polygene/index/solr/EmbeddedSolrService.java
@@ -35,6 +35,8 @@ import org.apache.polygene.api.service.ServiceDescriptor;
 import org.apache.polygene.api.service.ServiceReference;
 import org.apache.polygene.library.fileconfig.FileConfiguration;
 
+import static org.apache.polygene.api.util.AccessibleObjects.accessible;
+
 @Mixins( EmbeddedSolrService.Mixin.class )
 @Activators( EmbeddedSolrService.Activator.class )
 public interface EmbeddedSolrService
@@ -112,8 +114,7 @@ public interface EmbeddedSolrService
 
          // Clear instance fields for GC purposes
          Field instanceField = SolrCore.class.getDeclaredField( "instance" );
-         instanceField.setAccessible( true );
-         instanceField.set( null, null );
+         accessible( instanceField ).set( null, null );
 
          SolrConfig.config = null;
       }

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a4e13185/samples/rental/src/main/java/org/apache/polygene/sample/rental/web/Page.java
----------------------------------------------------------------------
diff --git a/samples/rental/src/main/java/org/apache/polygene/sample/rental/web/Page.java
b/samples/rental/src/main/java/org/apache/polygene/sample/rental/web/Page.java
index 876e4ad..5f0f827 100644
--- a/samples/rental/src/main/java/org/apache/polygene/sample/rental/web/Page.java
+++ b/samples/rental/src/main/java/org/apache/polygene/sample/rental/web/Page.java
@@ -35,6 +35,8 @@ import org.w3c.dom.Element;
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
 
+import static org.apache.polygene.api.util.AccessibleObjects.accessible;
+
 @Concerns( PageUowManagement.class )
 @Mixins( { Page.MountPointMixin.class, Page.DefaultPageRenderMixin.class } )
 public interface Page
@@ -160,9 +162,7 @@ public interface Page
             throws NoSuchMethodException
         {
             // TODO: Add caching since locating the methods and the throwing of exceptions
are expensive.
-            Method method = compositeType.getMethod( methodName, QuikitContext.class );
-            method.setAccessible( true );
-            return method;
+            return accessible( compositeType.getMethod( methodName, QuikitContext.class )
);
         }
     }
 


Mime
View raw message