groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sun...@apache.org
Subject [groovy] branch master updated: Trivial refactoring: avoid redundant checks
Date Sun, 03 Nov 2019 16:01:27 GMT
This is an automated email from the ASF dual-hosted git repository.

sunlan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git


The following commit(s) were added to refs/heads/master by this push:
     new 6ae7993  Trivial refactoring: avoid redundant checks
6ae7993 is described below

commit 6ae79930dcc0e18556cac9fcee7649f867ee55e6
Author: Daniel Sun <sunlan@apache.org>
AuthorDate: Mon Nov 4 00:00:37 2019 +0800

    Trivial refactoring: avoid redundant checks
---
 src/main/java/org/codehaus/groovy/vmplugin/v9/Java9.java | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/vmplugin/v9/Java9.java b/src/main/java/org/codehaus/groovy/vmplugin/v9/Java9.java
index 639dcbe..9337e5a 100644
--- a/src/main/java/org/codehaus/groovy/vmplugin/v9/Java9.java
+++ b/src/main/java/org/codehaus/groovy/vmplugin/v9/Java9.java
@@ -37,8 +37,6 @@ import java.lang.module.ModuleFinder;
 import java.lang.module.ModuleReference;
 import java.lang.reflect.AccessibleObject;
 import java.lang.reflect.Constructor;
-import java.lang.reflect.Executable;
-import java.lang.reflect.Field;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Member;
 import java.lang.reflect.Method;
@@ -145,7 +143,8 @@ public class Java9 extends Java8 {
             throw new IllegalArgumentException("accessibleObject should be a member of type:
" + accessibleObject);   // should not happen
         }
 
-        Class<?> declaringClass = ((Member) accessibleObject).getDeclaringClass();
+        Member member = (Member) accessibleObject;
+        Class<?> declaringClass = member.getDeclaringClass();
 
         Module callerModule = callerClass.getModule();
         Module declaringModule = declaringClass.getModule();
@@ -154,9 +153,7 @@ public class Java9 extends Java8 {
         if (callerModule == Object.class.getModule()) return true;
         if (!declaringModule.isNamed()) return true;
 
-        int modifiers = accessibleObject instanceof Executable
-                            ? ((Executable) accessibleObject).getModifiers()
-                            : ((Field) accessibleObject).getModifiers();
+        int modifiers = member.getModifiers();
 
         return checkAccessible(callerClass, declaringClass, modifiers, true);
     }


Mime
View raw message