nashorn/src/jdk/internal/dynalink/beans/BeansLinker.java
changeset 18876 ada98218aaae
parent 16267 cd471d62bb6a
child 24778 2ff5d7041566
equal deleted inserted replaced
18874:8ba96bd382d3 18876:ada98218aaae
    82 */
    82 */
    83 
    83 
    84 package jdk.internal.dynalink.beans;
    84 package jdk.internal.dynalink.beans;
    85 
    85 
    86 import java.lang.invoke.MethodHandles;
    86 import java.lang.invoke.MethodHandles;
       
    87 import java.util.Collection;
       
    88 import java.util.Collections;
    87 import jdk.internal.dynalink.CallSiteDescriptor;
    89 import jdk.internal.dynalink.CallSiteDescriptor;
    88 import jdk.internal.dynalink.DynamicLinkerFactory;
    90 import jdk.internal.dynalink.DynamicLinkerFactory;
    89 import jdk.internal.dynalink.linker.GuardedInvocation;
    91 import jdk.internal.dynalink.linker.GuardedInvocation;
    90 import jdk.internal.dynalink.linker.GuardingDynamicLinker;
    92 import jdk.internal.dynalink.linker.GuardingDynamicLinker;
    91 import jdk.internal.dynalink.linker.LinkRequest;
    93 import jdk.internal.dynalink.linker.LinkRequest;
   164      */
   166      */
   165     public static boolean isDynamicMethod(final Object obj) {
   167     public static boolean isDynamicMethod(final Object obj) {
   166         return obj instanceof DynamicMethod;
   168         return obj instanceof DynamicMethod;
   167     }
   169     }
   168 
   170 
       
   171     /**
       
   172      * Returns a collection of names of all readable instance properties of a class.
       
   173      * @param clazz the class
       
   174      * @return a collection of names of all readable instance properties of a class.
       
   175      */
       
   176     public static Collection<String> getReadableInstancePropertyNames(Class<?> clazz) {
       
   177         TypeBasedGuardingDynamicLinker linker = getLinkerForClass(clazz);
       
   178         if(linker instanceof BeanLinker) {
       
   179             return ((BeanLinker)linker).getReadablePropertyNames();
       
   180         }
       
   181         return Collections.emptySet();
       
   182     }
       
   183 
       
   184     /**
       
   185      * Returns a collection of names of all writable instance properties of a class.
       
   186      * @param clazz the class
       
   187      * @return a collection of names of all writable instance properties of a class.
       
   188      */
       
   189     public static Collection<String> getWritableInstancePropertyNames(Class<?> clazz) {
       
   190         TypeBasedGuardingDynamicLinker linker = getLinkerForClass(clazz);
       
   191         if(linker instanceof BeanLinker) {
       
   192             return ((BeanLinker)linker).getWritablePropertyNames();
       
   193         }
       
   194         return Collections.emptySet();
       
   195     }
       
   196 
       
   197     /**
       
   198      * Returns a collection of names of all instance methods of a class.
       
   199      * @param clazz the class
       
   200      * @return a collection of names of all instance methods of a class.
       
   201      */
       
   202     public static Collection<String> getInstanceMethodNames(Class<?> clazz) {
       
   203         TypeBasedGuardingDynamicLinker linker = getLinkerForClass(clazz);
       
   204         if(linker instanceof BeanLinker) {
       
   205             return ((BeanLinker)linker).getMethodNames();
       
   206         }
       
   207         return Collections.emptySet();
       
   208     }
       
   209 
       
   210     /**
       
   211      * Returns a collection of names of all readable static properties of a class.
       
   212      * @param clazz the class
       
   213      * @return a collection of names of all readable static properties of a class.
       
   214      */
       
   215     public static Collection<String> getReadableStaticPropertyNames(Class<?> clazz) {
       
   216         return StaticClassLinker.getReadableStaticPropertyNames(clazz);
       
   217     }
       
   218 
       
   219     /**
       
   220      * Returns a collection of names of all writable static properties of a class.
       
   221      * @param clazz the class
       
   222      * @return a collection of names of all writable static properties of a class.
       
   223      */
       
   224     public static Collection<String> getWritableStaticPropertyNames(Class<?> clazz) {
       
   225         return StaticClassLinker.getWritableStaticPropertyNames(clazz);
       
   226     }
       
   227 
       
   228     /**
       
   229      * Returns a collection of names of all static methods of a class.
       
   230      * @param clazz the class
       
   231      * @return a collection of names of all static methods of a class.
       
   232      */
       
   233     public static Collection<String> getStaticMethodNames(Class<?> clazz) {
       
   234         return StaticClassLinker.getStaticMethodNames(clazz);
       
   235     }
       
   236 
   169     @Override
   237     @Override
   170     public GuardedInvocation getGuardedInvocation(LinkRequest request, final LinkerServices linkerServices)
   238     public GuardedInvocation getGuardedInvocation(LinkRequest request, final LinkerServices linkerServices)
   171             throws Exception {
   239             throws Exception {
   172         final CallSiteDescriptor callSiteDescriptor = request.getCallSiteDescriptor();
   240         final CallSiteDescriptor callSiteDescriptor = request.getCallSiteDescriptor();
   173         final int l = callSiteDescriptor.getNameTokenCount();
   241         final int l = callSiteDescriptor.getNameTokenCount();