Beispiel #1
0
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)
Beispiel #2
0
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 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        
Beispiel #4
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        
"""
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):
    """
    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
Beispiel #6
0
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):
    """
    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