コード例 #1
0
ファイル: interactive.py プロジェクト: vyesubabu/gradle-mcv
def javaStaticMethods(clazz):
    """Return names of static methods for a given Java class."""
    static_methods = {}
    for method in Class.getDeclaredMethods(clazz):
        modifiers = method.getModifiers()
        if Modifier.isStatic(modifiers) and Modifier.isPublic(modifiers):
            static_methods[method.name] = method
    methods = static_methods.keys()
    for base in clazz.__bases__:
        if not ispython(base):
            methods.extend(javaStaticMethods(base))
    return methods
コード例 #2
0
ファイル: interactive.py プロジェクト: vyesubabu/gradle-mcv
def javaStaticFields(clazz):
    """Return names of static fields for a given Java class."""
    static_fields = {}
    for field in Class.getDeclaredFields(clazz):
        modifiers = field.getModifiers()
        if Modifier.isStatic(modifiers) and Modifier.isPublic(modifiers):
            static_fields[field.name] = field
    fields = static_fields.keys()
    for base in clazz.__bases__:
        if not ispython(base):
            fields.extend(javaStaticFields(base))
    return fields
コード例 #3
0
def staticMethodNames(clazz):
    """return a list of static method name for a class"""
    # TODO get static methods from base classes
    static_methods = {}
    declared_methods = Class.getDeclaredMethods(clazz)
    for method in declared_methods:
        if Modifier.isStatic(method.getModifiers()) and Modifier.isPublic(method.getModifiers()):
            static_methods[method.name] = method
    methods = static_methods.keys()
    
    for eachBase in clazz.__bases__:
        methods.extend(staticMethodNames(eachBase)) 
    
    return methods
コード例 #4
0
def staticFieldNames(clazz):
    """return a list of static field names for class"""
    # TODO get static fields from base classes
    static_fields = {}
    declared_fields = Class.getDeclaredFields(clazz)
    for field in declared_fields:
        if Modifier.isStatic(field.getModifiers()) and Modifier.isPublic(field.getModifiers()):
            static_fields[field.name] = field
    fields = static_fields.keys()   
    
    for eachBase in clazz.__bases__:
         fields.extend(staticFieldNames(eachBase)) 

    return fields        
コード例 #5
0
def staticFieldNames(clazz):
    """return a list of static field names for class"""

    static_fields = {}
    declared_fields = Class.getDeclaredFields(clazz)
    for field in declared_fields:
        if Modifier.isStatic(field.getModifiers()) and Modifier.isPublic(field.getModifiers()):
            static_fields[field.name] = field
    fields = static_fields.keys()   
    
    for eachBase in clazz.__bases__:
        if not ispython(eachBase):
            fields.extend(staticFieldNames(eachBase)) 

    return fields        
コード例 #6
0
ファイル: interactive.py プロジェクト: vyesubabu/gradle-mcv
def javaInstanceMethods(clazz):
    """Return names of instance methods for a given Java class."""
    names = set()
    for method in Class.getDeclaredMethods(clazz):
        modifiers = method.getModifiers()
        if not Modifier.isStatic(modifiers) and Modifier.isPublic(modifiers):
            name = method.name
            names.add(name)
            if name.startswith('get') and len(name) > 3 and not method.getParameterTypes():
                property_name = name[3].lower() + name[4:]
                names.add(property_name)
    for base in clazz.__bases__:
        if not ispython(base):
            names = names | javaInstanceMethods(base)
    return names
コード例 #7
0
def staticMethodNames(clazz):
    """return a list of static method name for a class"""
    # TODO get static methods from base classes
    static_methods = {}
    declared_methods = Class.getDeclaredMethods(clazz)
    for method in declared_methods:
        if Modifier.isStatic(method.getModifiers()) and Modifier.isPublic(
                method.getModifiers()):
            static_methods[method.name] = method
    methods = static_methods.keys()

    for eachBase in clazz.__bases__:
        methods.extend(staticMethodNames(eachBase))

    return methods
コード例 #8
0
ファイル: __init__.py プロジェクト: d0c0nnor/jocelyn
def expose_constants(cls):
    fields = set([f.name for f in cls.getDeclaredFields() if
                  Modifier.isStatic(f.getModifiers())])

    for f in (fields & visible_members) - builtins:
        setattr(module, f, getattr(cls, f))
        members_to_expose.append(f)
コード例 #9
0
ファイル: recipe-502222.py プロジェクト: zlrs/code-1
def javaClassToHtml(javaClass, level=0):
    """return html class representation."""
    if type(javaClass) is StringType or type(javaClass) is UnicodeType:
        class_ = Class.forName(javaClass)
        className = javaClass
    else:
        class_ = javaClass
        className = javaClass.__name__
    if Class.isInterface(class_):
        typeStr = 'interface'
    elif Modifier.isAbstract(Class.getModifiers(class_)):
        typeStr = 'abstract class'
    else:
        typeStr = 'class'
    #indent = (' '*level+1)*4)
    indent = ' ' * (level + 1) * 4
    header = '%s<p>%s %s' % (indent, typeStr, className)
    super_ = Class.getSuperclass(class_)
    if super_ is not None:
        header += ' extends ' + Class.getName(super_)
    interfaces = Class.getInterfaces(class_)
    if len(interfaces) > 0:
        interfacesNames = join(map(Class.getName, interfaces), ', ')
        header += ' implements %s' % (interfacesNames)
    body = membersToHtml(lambda: Class.getDeclaredFields(class_), level)
    body += membersToHtml(lambda: Class.getDeclaredConstructors(class_), level)
    body += membersToHtml(lambda: Class.getDeclaredMethods(class_), level)
    body = '%s{</p>\n%s<ul class="ind%i">\n%s' % (header, indent, level, body)
    body = boldJavaKeywords(classLink(className, body))
    li = '%s<li>\n%s\n%s</li>\n'
    ind2 = (' ' * (level + 2) * 4)
    for cl in Class.getDeclaredClasses(class_):
        body += li % (ind2, javaClassToHtml(Class.getName(cl), level+1), \
                indent*2)
    return '%s%s</ul>}' % (body, indent)
コード例 #10
0
 def __init__(self):
     self.key_names = defaultdict(lambda:'UNKNOWN')
     
     for f in KeyEvent.getDeclaredFields():
         if Modifier.isStatic(f.getModifiers()):
             self.name = f.getName()
             if self.name.startswith("VK_"):
                 self.key_names[f.getInt(None)] = self.name[3:]
コード例 #11
0
def expose_constants(cls):
    fields = set([
        f.name for f in cls.getDeclaredFields()
        if Modifier.isStatic(f.getModifiers())
    ])

    for f in (fields & visible_members) - builtins:
        setattr(module, f, getattr(cls, f))
        members_to_expose.append(f)
コード例 #12
0
ファイル: jintrospect.py プロジェクト: Adama94/ggp-base
def staticMethodNames(clazz):
    """return a list of static method name for a class"""

    static_methods = {}
    declared_methods = Class.getDeclaredMethods(clazz)
    for method in declared_methods:
        if Modifier.isStatic(method.getModifiers()) and Modifier.isPublic(method.getModifiers()):
            static_methods[method.name] = method
    methods = static_methods.keys()
    
    for eachBase in clazz.__bases__:
        # with Jython 2.5 type is a base of Object, which puts asName in the list        
        # will be a problem for real Java objects that extend Python objects
        # see similar "fixes" in instanceMethodNames and staticFieldNames
        if not ispython(eachBase):
            methods.extend(staticMethodNames(eachBase)) 
    
    return methods
コード例 #13
0
def staticMethodNames(clazz):
    """return a list of static method name for a class"""

    static_methods = {}
    declared_methods = Class.getDeclaredMethods(clazz)
    for method in declared_methods:
        if Modifier.isStatic(method.getModifiers()) and Modifier.isPublic(method.getModifiers()):
            static_methods[method.name] = method
    methods = static_methods.keys()
    
    for eachBase in clazz.__bases__:
        # with Jython 2.5 type is a base of Object, which puts asName in the list        
        # will be a problem for real Java objects that extend Python objects
        # see similar "fixes" in instanceMethodNames and staticFieldNames
        if not ispython(eachBase):
            methods.extend(staticMethodNames(eachBase)) 
    
    return methods
コード例 #14
0
ファイル: jintrospect.py プロジェクト: Adama94/ggp-base
def instanceMethodNames(clazz):
    """return a Set of instance method name for a Class"""

    method_names = Set()
    declared_methods = Class.getDeclaredMethods(clazz)
    for method in declared_methods:
        modifiers = method.getModifiers()
        if not Modifier.isStatic(modifiers) and Modifier.isPublic(modifiers):
            name = method.name            
            method_names.add(name)
            if name.startswith("get") and len(name) > 3 and len(method.getParameterTypes()) == 0:
                property_name = name[3].lower() + name[4:]
                method_names.add(property_name)                
                                      
    for eachBase in clazz.__bases__:
        if not ispython(eachBase):
            method_names = method_names | instanceMethodNames(eachBase)

    return method_names
コード例 #15
0
def instanceMethodNames(clazz):
    """return a Set of instance method name for a Class"""

    method_names = Set()
    declared_methods = Class.getDeclaredMethods(clazz)
    for method in declared_methods:
        modifiers = method.getModifiers()
        if not Modifier.isStatic(modifiers) and Modifier.isPublic(modifiers):
            name = method.name            
            method_names.add(name)
            if name.startswith("get") and len(name) > 3 and len(method.getParameterTypes()) == 0:
                property_name = name[3].lower() + name[4:]
                method_names.add(property_name)                
                                      
    for eachBase in clazz.__bases__:
        if not ispython(eachBase):
            method_names = method_names | instanceMethodNames(eachBase)

    return method_names
コード例 #16
0
def setup():
    size(640, 640)
    global colors
    global bobble
    global position
    global key_names

    key_names = defaultdict(lambda: 'UNKNOWN')
    for f in KeyEvent.getDeclaredFields():
        if Modifier.isStatic(f.getModifiers()):
            name = f.getName()
            if name.startswith("VK_"):
                key_names[f.getInt(None)] = name[3:]

    position = {}
    position['x'] = width / 2
    position['y'] = height / 2

    colors = {}
    colors['white'] = color(255, 255, 255)
    colors['blueish'] = color(39, 61, 183)
    colors['redish'] = color(211, 17, 24)

    # initialize our avatar shape
    d = 55
    bobble = createShape(GROUP)
    bubble = createShape(ELLIPSE, 0, 0, d, d)
    bubble.setFill(colors['blueish'])
    bobble.noStroke()
    bobble.addChild(bubble)
    sight = createShape()
    sight.beginShape()
    sight.vertex(0, 0)
    sight.vertex(d / 2, -d / 2)
    # correction of 45 deg
    sight.rotate(radians(45))
    sight.endShape(CLOSE)
    bobble.addChild(sight)
コード例 #17
0
    def from_reflectedfield(reflectedfield, name, cls):
        name = name
        my_type = reflectedfield.field.getType()
        modifiers = Modifier(reflectedfield.field.getModifiers())

        value_repr = None
        has_value = False

        if modifiers.is_static and modifiers.is_final:
            try:
                value = getattr(cls, name)
                value_repr = pretty_repr(value)
                has_value = True
            except java.lang.IllegalArgumentException:
                pass

        return Field(
            name=name,
            my_type=BasicType.from_type(my_type),
            modifiers=modifiers,
            value_repr=value_repr,
            has_value=has_value,
        )
コード例 #18
0
               'byte': prim("Byte"),
               'long': prim("Long"),
               'double': prim("Double"),
               'float': prim("Float"),
               'boolean': prim("Boolean") }

USELESS_TYPES = (PRIMITIVES['char'], Class.forName('[C'), PRIMITIVES['byte'])

"""
We want to create Jython wrappers for all public methods of PApplet except
those in "BAD_METHOD". Also, if we have both foo(int) and foo(char), we throw
away the char variant, and always call the int variant. Same with foo(byte).
Sadly, Java has no unisgned types, so the distinction is weird.
"""
WANTED_METHODS = [m for m in Class.getDeclaredMethods(PApplet)
                      if Modifier.isPublic(m.getModifiers())
                      and not BAD_METHOD.match(m.getName())
                      and not any(k in USELESS_TYPES for k in m.getParameterTypes())]

"""
We want to create Jython wrappers for all variables visible during the
Processing runtime.
"""
WANTED_FIELDS = [f for f in Class.getDeclaredFields(PApplet)
                    if Modifier.isPublic(f.getModifiers())
                    and not Modifier.isStatic(f.getModifiers())
                    and not BAD_FIELD.match(f.getName())]


class ClassConversionInfo(object):
    """
コード例 #19
0
ファイル: ListaPrivados.py プロジェクト: cadu-leite/ppqsp
from java.lang.reflect import Modifier
import ObjetoSecreto

oSecreto = ObjetoSecreto('senha super secreta')
campos = ObjetoSecreto.getDeclaredFields()
for campo in campos:
    if Modifier.isPrivate(campo.getModifiers()): # so campos privados!
        print campo
        campo.setAccessible(True) # arrombamos a porta
        print '\t', campo.getName(), '=', campo.get(oSecreto)
コード例 #20
0
    'long': prim("Long"),
    'double': prim("Double"),
    'float': prim("Float"),
    'boolean': prim("Boolean")
}

USELESS_TYPES = (PRIMITIVES['char'], Class.forName('[C'), PRIMITIVES['byte'])
"""
We want to create Jython wrappers for all public methods of PApplet except
those in "BAD_METHOD". Also, if we have both foo(int) and foo(char), we throw
away the char variant, and always call the int variant. Same with foo(byte).
Sadly, Java has no unsigned types, so the distinction is weird.
"""
WANTED_METHODS = [
    m for m in Class.getDeclaredMethods(PApplet)
    if Modifier.isPublic(m.getModifiers()) and not m.getExceptionTypes()
    and not BAD_METHOD.match(m.getName()) and not any(
        k in USELESS_TYPES for k in m.getParameterTypes())
]
"""
We want to create Jython wrappers for all variables visible during the
Processing runtime.
"""
WANTED_FIELDS = [
    f for f in Class.getDeclaredFields(PApplet)
    if Modifier.isPublic(f.getModifiers()) and not Modifier.isStatic(
        f.getModifiers()) and not BAD_FIELD.match(f.getName())
]


class ClassConversionInfo(object):
コード例 #21
0
ファイル: keys.py プロジェクト: YatharthROCK/agar
#!/usr/bin/env python3

__author__ = 'Yatharth Agarwal <*****@*****.**>'

"""Map keys for decoding raw key data"""

from collections import defaultdict

from java.awt.event import KeyEvent
from java.lang.reflect import Modifier


KEY_NAMES = defaultdict(lambda: 'UNKNOWN')

for f in KeyEvent.getDeclaredFields():
    if Modifier.isStatic(f.getModifiers()):
        name = f.getName()
        if name.startswith("VK_"):
            KEY_NAMES[f.getInt(None)] = name[3:]
コード例 #22
0
ファイル: listapriv.py プロジェクト: jameszh/example-code
from java.lang.reflect import Modifier
import ObjetoSecreto

oSecreto = ObjetoSecreto('senha super secreta')
campos = ObjetoSecreto.getDeclaredFields()
for campo in campos:
    # so campos privados!
    if Modifier.isPrivate(campo.getModifiers()):
        print campo
        campo.setAccessible(True) # arrombamos a porta
        print '\t', campo.getName(), '=', campo.get(oSecreto)
コード例 #23
0
ファイル: listapriv.py プロジェクト: nfredrik/example-code
from java.lang.reflect import Modifier
import ObjetoSecreto

oSecreto = ObjetoSecreto('senha super secreta')
campos = ObjetoSecreto.getDeclaredFields()
for campo in campos:
    # so campos privados!
    if Modifier.isPrivate(campo.getModifiers()):
        print campo
        campo.setAccessible(True)  # arrombamos a porta
        print '\t', campo.getName(), '=', campo.get(oSecreto)
コード例 #24
0
from java.lang.reflect import Modifier
import Confidential

message = Confidential('top secret text')
fields = Confidential.getDeclaredFields()
for field in fields:
    # list private fields only
    if Modifier.isPrivate(field.getModifiers()):
        field.setAccessible(True) # break the lock
        print 'field:', field
        print '\t', field.getName(), '=', field.get(message)
コード例 #25
0
ファイル: ProjectSearcher.py プロジェクト: hobson/ggpy
 def apply(self, klass):
     """ generated source for method apply """
     return not Modifier.isAbstract(klass.getModifiers())
コード例 #26
0
#!/usr/bin/env jython
# NOTE: Jython is still Python 2.7 in late2020

from java.lang.reflect import Modifier
import Confidential

message = Confidential('top secret text')
fields = Confidential.getDeclaredFields()
for field in fields:
    # list private fields only
    if Modifier.isPrivate(field.getModifiers()):
        field.setAccessible(True)  # break the lock
        print 'field:', field
        print '\t', field.getName(), '=', field.get(message)