Exemplo n.º 1
0
def _getJavaMethods(javaclass,inherited=False,regexp=None,argTypes=None,methodFilterFun=None,natives=False):
  """ returns java methods from a metaclass
      regexp : None or a regular expression to filter method names (e.g. "^get|is")
      methodFilterFun : None or a predicate on a java.lang.reflect.Method object that will be used to filter methods
  """
  try:  
    javaMethods = javaclass.getMethods() if inherited else javaclass.getDeclaredMethods()
  except:
    # it seems that the code above fail in some case
    javaMethods = []
  if not natives:
    # remove methods starting with _ which seems to be natives ones
    # (should be improved using getModifiers instead ...)
    javaMethods = reject(lambda m:m.getName().startswith('-'), javaMethods)
  if regexp is not None:
    javaMethods = filter(lambda m:re.match(regexp,m.getName()), javaMethods) 
  if argTypes is not None:
    javaMethods = filter(lambda m:list(m.getParameterTypes())==list(argTypes), javaMethods)
  if methodFilterFun is not None:
    javaMethods = filter(methodFilterFun,javaMethods)
  return javaMethods
Exemplo n.º 2
0
 def getSlotList(self,emptySlots=True):
   slots = self._getSlotList()
   if not emptySlots:
     slots = reject(MetaFeatureSlot.isEmpty,slots)
   return slots