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)
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:]
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)
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
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
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
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
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
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
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
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
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
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
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
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)
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): """ A structure to keep in one place all of the templates for generating code for going back and forth between Python and Java. """ def __init__(self, to_python_prefix, to_java_format, typecheck_format): self.to_python_prefix = to_python_prefix self.to_java_format = to_java_format self.typecheck_format = typecheck_format """
#!/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:]
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): """ A structure to keep in one place all of the templates for generating code for going back and forth between Python and Java. """ def __init__(self, to_python_prefix, to_java_format, typecheck_format): self.to_python_prefix = to_python_prefix self.to_java_format = to_java_format self.typecheck_format = typecheck_format """ Map from java types to various expressions needed in code