javaclass

Changeset

110:ed58b4f865e1
2005-01-10 Paul Boddie raw files shortlog changelog graph Moved the lang module contents into the lang package. Fixed various java.lang and java.io circular imports by introducing a java.lang._object module. Corrected various base classes (object -> java.lang.Object, Exception -> java.lang.Exception) and fixed raising of exceptions in certain cases.
java/io.py (file) java/lang.py
     1.1 --- a/java/io.py	Mon Jan 10 23:43:44 2005 +0100
     1.2 +++ b/java/io.py	Mon Jan 10 23:52:19 2005 +0100
     1.3 @@ -1,6 +1,8 @@
     1.4  #!/usr/bin/env python
     1.5  
     1.6 -class InputStream(object):
     1.7 +from java.lang._object import Object, NullPointerException, IndexOutOfBoundsException, Exception as _Exception
     1.8 +
     1.9 +class InputStream(Object):
    1.10      def __init__(self, stream):
    1.11          # NOTE: Python-only method.
    1.12          self.stream = stream
    1.13 @@ -12,15 +14,13 @@
    1.14              return ord(s)
    1.15      def read____B__array_(self, b, off=0, length=None):
    1.16          if b is None:
    1.17 -            import java.lang
    1.18 -            raise java.lang.NullPointerException
    1.19 +            raise Exception, NullPointerException()
    1.20          if len(b) == 0:
    1.21              return 0
    1.22          if length is None:
    1.23              length = len(b)
    1.24          elif length + off > len(b):
    1.25 -            import java.lang
    1.26 -            raise java.lang.IndexOutOfBoundsException
    1.27 +            raise Exception, IndexOutOfBoundsException()
    1.28          s = self.stream.read(length)
    1.29          if s == "":
    1.30              return -1
    1.31 @@ -53,14 +53,14 @@
    1.32          raise NotImplementedError, "markSupported"
    1.33      markSupported___ = markSupported
    1.34  
    1.35 -class IOException(Exception):
    1.36 +class IOException(_Exception):
    1.37      def __init__(self, *args):
    1.38          self.args = args
    1.39  
    1.40  setattr(IOException, "__init_____", IOException.__init__)
    1.41  setattr(IOException, "__init_____java__lang__String", IOException.__init__)
    1.42  
    1.43 -class OutputStream(object):
    1.44 +class OutputStream(Object):
    1.45      def write(self, b, *args):
    1.46          raise NotImplementedError, "write"
    1.47      write___java__lang__String = write
    1.48 @@ -108,14 +108,14 @@
    1.49      def flush(self):
    1.50          FilterOutputStream.flush(self)
    1.51      flush___ = flush
    1.52 -    def print_(self, obj):
    1.53 +    def print_(self, obj, ending=""):
    1.54          # NOTE: Check for arrays.
    1.55          if isinstance(obj, list):
    1.56              for i in obj:
    1.57 -                self.print_(i)
    1.58 +                self.print_(i, ending)
    1.59          else:
    1.60              # NOTE: Using Python string conversion.
    1.61 -            FilterOutputStream.write(self, unicode(obj))
    1.62 +            FilterOutputStream.write(self, unicode(obj) + ending)
    1.63      print____Z_ = print_
    1.64      print____C_ = print_
    1.65      print____C__array_ = print_
    1.66 @@ -126,6 +126,18 @@
    1.67      print___java__lang__Object = print_
    1.68      print___java__lang__String = print_
    1.69  
    1.70 +    def println(self, obj):
    1.71 +        self.print_(obj, "\n")
    1.72 +    println____Z_ = println
    1.73 +    println____C_ = println
    1.74 +    println____C__array_ = println
    1.75 +    println____D_ = println
    1.76 +    println____F_ = println
    1.77 +    println____I_ = println
    1.78 +    println____L_ = println
    1.79 +    println___java__lang__Object = println
    1.80 +    println___java__lang__String = println
    1.81 +
    1.82      # NOTE: To be completed.
    1.83  
    1.84  setattr(PrintStream, "__init_____java__io__OutputStream", PrintStream.init__out)
     2.1 --- a/java/lang.py	Mon Jan 10 23:43:44 2005 +0100
     2.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.3 @@ -1,396 +0,0 @@
     2.4 -#!/usr/bin/env python
     2.5 -
     2.6 -import java.io
     2.7 -import os
     2.8 -import sys
     2.9 -
    2.10 -class Character(object):
    2.11 -    def __init__(self, value):
    2.12 -        raise NotImplementedError, "__init__"
    2.13 -
    2.14 -    def charValue(self):
    2.15 -        raise NotImplementedError, "charValue"
    2.16 -    charValue___ = charValue
    2.17 -
    2.18 -    def hashCode(self):
    2.19 -        raise NotImplementedError, "hashCode"
    2.20 -    hashCode___ = hashCode
    2.21 -
    2.22 -    def equals(self, anObject):
    2.23 -        raise NotImplementedError, "equals"
    2.24 -    equals___java__lang__Object = equals
    2.25 -
    2.26 -    def toString(self):
    2.27 -        raise NotImplementedError, "toString"
    2.28 -    toString___ = toString
    2.29 -
    2.30 -    def isLowerCase(self, ch):
    2.31 -        raise NotImplementedError, "isLowerCase"
    2.32 -    isLowerCase____C_ = staticmethod(isLowerCase)
    2.33 -
    2.34 -    def isUpperCase(self, ch):
    2.35 -        raise NotImplementedError, "isUpperCase"
    2.36 -    isUpperCase____C_ = staticmethod(isUpperCase)
    2.37 -
    2.38 -    def isTitleCase(self, ch):
    2.39 -        raise NotImplementedError, "isTitleCase"
    2.40 -    isTitleCase____C_ = staticmethod(isTitleCase)
    2.41 -
    2.42 -    def isDigit(self, ch):
    2.43 -        raise NotImplementedError, "isDigit"
    2.44 -    isDigit____C_ = staticmethod(isDigit)
    2.45 -
    2.46 -    def isDefined(self, ch):
    2.47 -        raise NotImplementedError, "isDefined"
    2.48 -    isDefined____C_ = staticmethod(isDefined)
    2.49 -
    2.50 -    def isLetter(self, ch):
    2.51 -        raise NotImplementedError, "isLetter"
    2.52 -    isLetter____C_ = staticmethod(isLetter)
    2.53 -
    2.54 -    def isLetterOrDigit(self, ch):
    2.55 -        raise NotImplementedError, "isLetterOrDigit"
    2.56 -    isLetterOrDigit____C_ = staticmethod(isLetterOrDigit)
    2.57 -
    2.58 -    def isJavaLetter(self, ch):
    2.59 -        raise NotImplementedError, "isJavaLetter"
    2.60 -    isJavaLetter____C_ = staticmethod(isJavaLetter)
    2.61 -
    2.62 -    def isJavaLetterOrDigit(self, ch):
    2.63 -        raise NotImplementedError, "isJavaLetterOrDigit"
    2.64 -    isJavaLetterOrDigit____C_ = staticmethod(isJavaLetterOrDigit)
    2.65 -
    2.66 -    def isJavaIdentifierStart(self, ch):
    2.67 -        raise NotImplementedError, "isJavaIdentifierStart"
    2.68 -    isJavaIdentifierStart____C_ = staticmethod(isJavaIdentifierStart)
    2.69 -
    2.70 -    def isJavaIdentifierPart(self, ch):
    2.71 -        raise NotImplementedError, "isJavaIdentifierPart"
    2.72 -    isJavaIdentifierPart____C_ = staticmethod(isJavaIdentifierPart)
    2.73 -
    2.74 -    def isUnicodeIdentifierStart(self, ch):
    2.75 -        raise NotImplementedError, "isUnicodeIdentifierStart"
    2.76 -    isUnicodeIdentifierStart____C_ = staticmethod(isUnicodeIdentifierStart)
    2.77 -
    2.78 -    def isUnicodeIdentifierPart(self, ch):
    2.79 -        raise NotImplementedError, "isUnicodeIdentifierPart"
    2.80 -    isUnicodeIdentifierPart____C_ = staticmethod(isUnicodeIdentifierPart)
    2.81 -
    2.82 -    def isIdentifierIgnorable(self, ch):
    2.83 -        raise NotImplementedError, "isIdentifierIgnorable"
    2.84 -    isIdentifierIgnorable____C_ = staticmethod(isIdentifierIgnorable)
    2.85 -
    2.86 -    def toLowerCase(self, ch):
    2.87 -        raise NotImplementedError, "toLowerCase"
    2.88 -    toLowerCase____C_ = staticmethod(toLowerCase)
    2.89 -
    2.90 -    def toUpperCase(self, ch):
    2.91 -        raise NotImplementedError, "toUpperCase"
    2.92 -    toUpperCase____C_ = staticmethod(toUpperCase)
    2.93 -
    2.94 -    def toTitleCase(self, ch):
    2.95 -        raise NotImplementedError, "toTitleCase"
    2.96 -    toTitleCase____C_ = staticmethod(toTitleCase)
    2.97 -
    2.98 -    def digit(self, ch, radix):
    2.99 -        raise NotImplementedError, "digit"
   2.100 -    digit____C_____I_ = staticmethod(digit)
   2.101 -
   2.102 -    def getNumericValue(self, ch):
   2.103 -        raise NotImplementedError, "getNumericValue"
   2.104 -    getNumericValue____C_ = staticmethod(getNumericValue)
   2.105 -
   2.106 -    def isSpace(self, ch):
   2.107 -        raise NotImplementedError, "isSpace"
   2.108 -    isSpace____C_ = staticmethod(isSpace)
   2.109 -
   2.110 -    def isSpaceChar(self, ch):
   2.111 -        raise NotImplementedError, "isSpaceChar"
   2.112 -    isSpaceChar____C_ = staticmethod(isSpaceChar)
   2.113 -
   2.114 -    def isWhitespace(self, ch):
   2.115 -        raise NotImplementedError, "isWhitespace"
   2.116 -    isWhitespace____C_ = staticmethod(isWhitespace)
   2.117 -
   2.118 -    def isISOControl(self, ch):
   2.119 -        raise NotImplementedError, "isISOControl"
   2.120 -    isISOControl____C_ = staticmethod(isISOControl)
   2.121 -
   2.122 -    def getType(self, ch):
   2.123 -        raise NotImplementedError, "getType"
   2.124 -    getType____C_ = staticmethod(getType)
   2.125 -
   2.126 -    def forDigit(self, ch, radix):
   2.127 -        raise NotImplementedError, "forDigit"
   2.128 -    forDigit____C_____I_ = staticmethod(forDigit)
   2.129 -
   2.130 -    def compareTo(self, *args):
   2.131 -        # compareTo(self, anotherCharacter)
   2.132 -        # compareTo(self, o)
   2.133 -        raise NotImplementedError, "compareTo"
   2.134 -    compareTo____C_ = compareTo
   2.135 -    compareTo___java__lang__Object = compareTo
   2.136 -
   2.137 -setattr(Character, "__init____C_", Character.__init__)
   2.138 -
   2.139 -class Class(object):
   2.140 -    def forName(className):
   2.141 -        parts = unicode(className).split(".")
   2.142 -        obj = __import__(".".join(parts[:-1]), globals(), {}, [])
   2.143 -        for part in parts[1:]:
   2.144 -            obj = getattr(obj, part)
   2.145 -        return obj
   2.146 -
   2.147 -    forName___java__lang__String = staticmethod(forName)
   2.148 -    # NOTE: To be enhanced.
   2.149 -    forName___java__lang__String____Z____java__lang__ClassLoader = staticmethod(forName)
   2.150 -
   2.151 -# NOTE: Establish a better exception hierarchy.
   2.152 -
   2.153 -class Error(object):
   2.154 -    def __init__(self, *args):
   2.155 -        self.args = args
   2.156 -
   2.157 -setattr(Error, "__init_____", Error.__init__)
   2.158 -setattr(Error, "__init_____java__lang__String", Error.__init__)
   2.159 -
   2.160 -class Exception(object):
   2.161 -    def __init__(self, *args):
   2.162 -        self.args = args
   2.163 -
   2.164 -setattr(Exception, "__init_____", Exception.__init__)
   2.165 -setattr(Exception, "__init_____java__lang__String", Exception.__init__)
   2.166 -
   2.167 -class IndexOutOfBoundsException(object):
   2.168 -    def __init__(self, *args):
   2.169 -        self.args = args
   2.170 -
   2.171 -setattr(IndexOutOfBoundsException, "__init_____", IndexOutOfBoundsException.__init__)
   2.172 -setattr(IndexOutOfBoundsException, "__init_____java__lang__String", IndexOutOfBoundsException.__init__)
   2.173 -
   2.174 -class IllegalArgumentException(Exception):
   2.175 -    def __init__(self, *args):
   2.176 -        self.args = args
   2.177 -
   2.178 -setattr(IllegalArgumentException, "__init_____", IllegalArgumentException.__init__)
   2.179 -setattr(IllegalArgumentException, "__init_____java__lang__String", IllegalArgumentException.__init__)
   2.180 -
   2.181 -class NullPointerException(object):
   2.182 -    def __init__(self, *args):
   2.183 -        self.args = args
   2.184 -
   2.185 -setattr(NullPointerException, "__init_____", NullPointerException.__init__)
   2.186 -setattr(NullPointerException, "__init_____java__lang__String", NullPointerException.__init__)
   2.187 -
   2.188 -class SecurityException(Exception):
   2.189 -    def __init__(self, *args):
   2.190 -        self.args = args
   2.191 -
   2.192 -setattr(SecurityException, "__init_____", SecurityException.__init__)
   2.193 -setattr(SecurityException, "__init_____java__lang__String", SecurityException.__init__)
   2.194 -
   2.195 -class String(object):
   2.196 -
   2.197 -    # NOTE: This method should not be needed, really.
   2.198 -    def __str__(self):
   2.199 -        return self.value.encode("utf-8")
   2.200 -
   2.201 -    def __unicode__(self):
   2.202 -        return self.value
   2.203 -
   2.204 -    def init__empty(self):
   2.205 -        self.value = u""
   2.206 -
   2.207 -    def init__String(self, obj):
   2.208 -        self.value = obj.value
   2.209 -
   2.210 -    def __init__(self, *args):
   2.211 -
   2.212 -        "Python string initialisation only."
   2.213 -
   2.214 -        if len(args) == 1 and isinstance(args[0], str):
   2.215 -            self.value = unicode(args[0])
   2.216 -            return
   2.217 -        elif len(args) == 1 and isinstance(args[0], unicode):
   2.218 -            self.value = args[0]
   2.219 -            return
   2.220 -        # __init__(self)
   2.221 -        elif len(args) == 0:
   2.222 -            self.__init__empty()
   2.223 -            return
   2.224 -        # __init__(self, original)
   2.225 -        elif len(args) == 1 and isinstance(args[0], String):
   2.226 -            self.init__String(args[0])
   2.227 -            return
   2.228 -        # __init__(self, value)
   2.229 -        # __init__(self, value, offset, count)
   2.230 -        # __init__(self, ascii, hibyte, offset, count)
   2.231 -        # __init__(self, ascii, hibyte)
   2.232 -        # __init__(self, bytes, offset, length, enc)
   2.233 -        # __init__(self, bytes, enc)
   2.234 -        # __init__(self, bytes, offset, length)
   2.235 -        # __init__(self, bytes)
   2.236 -        elif len(args) >= 1 and isinstance(args[0], list):
   2.237 -            raise NotImplementedError, "__init__"
   2.238 -        # __init__(self, buffer)
   2.239 -        raise NotImplementedError, "__init__"
   2.240 -
   2.241 -    def length(self):
   2.242 -        return len(self.value)
   2.243 -    length___ = length
   2.244 -
   2.245 -    def charAt(self, index):
   2.246 -        return ord(self.value[index])
   2.247 -    charAt____I_ = charAt
   2.248 -
   2.249 -    def getChars(self, srcBegin, srcEnd, dst, dstBegin):
   2.250 -        raise NotImplementedError, "getChars"
   2.251 -    getChars____I_____I_____C__array_____I_ = getChars
   2.252 -
   2.253 -    def getBytes(self, *args):
   2.254 -        # void getBytes(self, srcBegin, srcEnd, dst, dstBegin)
   2.255 -        # byte[] getBytes(self, enc)
   2.256 -        # byte[] getBytes(self)
   2.257 -        raise NotImplementedError, "getBytes"
   2.258 -    getBytes___ = getBytes
   2.259 -    getBytes____I_____I_____B__array_____I_ = getBytes
   2.260 -
   2.261 -    def equals(self, anObject):
   2.262 -        return isinstance(anObject, self.__class__) and self.value == anObject.value
   2.263 -    equals___java__lang__Object = equals
   2.264 -
   2.265 -    def compareTo(self, obj):
   2.266 -        if self.value < obj.value:
   2.267 -            return -1
   2.268 -        elif self.value == obj.value:
   2.269 -            return 0
   2.270 -        else:
   2.271 -            return 1
   2.272 -    compareTo___java__lang__String = compareTo
   2.273 -
   2.274 -    # NOTE: Comparator defined using private classes. This implementation just
   2.275 -    # NOTE: uses Python's lower method.
   2.276 -    def compareToIgnoreCase(self, str):
   2.277 -        value = self.value.lower()
   2.278 -        value2 = str.value.lower()
   2.279 -        if value < value2:
   2.280 -            return -1
   2.281 -        elif value == value2:
   2.282 -            return 0
   2.283 -        else:
   2.284 -            return 1
   2.285 -    compareToIgnoreCase___java__lang__String = compareToIgnoreCase
   2.286 -
   2.287 -    # NOTE: Comparator defined using private classes. This implementation just
   2.288 -    # NOTE: uses Python's lower method.
   2.289 -    def equalsIgnoreCase(self, anotherString):
   2.290 -        value = self.value.lower()
   2.291 -        value2 = anotherString.value.lower()
   2.292 -        return value == value2
   2.293 -    equalsIgnoreCase___java__lang__String = equalsIgnoreCase
   2.294 -
   2.295 -    def regionMatches(self, *args):
   2.296 -        # regionMatches(self, toffset, other, ooffset, len)
   2.297 -        # regionMatches(self, ignoreCase, toffset, other, ooffset, len)
   2.298 -        raise NotImplementedError, "regionMatches"
   2.299 -
   2.300 -    def startsWith(self, *args):
   2.301 -        # startsWith(self, prefix, toffset)
   2.302 -        # startsWith(self, prefix)
   2.303 -        raise NotImplementedError, "startsWith"
   2.304 -
   2.305 -    def endsWith(self, suffix):
   2.306 -        raise NotImplementedError, "endsWith"
   2.307 -
   2.308 -    def hashCode(self):
   2.309 -        raise NotImplementedError, "hashCode"
   2.310 -
   2.311 -    def indexOf____I_(self, ch):
   2.312 -        return self.value.find(chr(ch))
   2.313 -
   2.314 -    def indexOf____I_____I_(self, ch, fromIndex):
   2.315 -        return self.value.find(chr(ch), fromIndex)
   2.316 -
   2.317 -    def indexOf___java__lang__String___(self, str):
   2.318 -        return self.value.find(str.value)
   2.319 -
   2.320 -    def indexOf___java__lang__String____I_(self, str, fromIndex):
   2.321 -        return self.value.find(str.value, fromIndex)
   2.322 -
   2.323 -    def lastIndexOf(self, *args):
   2.324 -        # lastIndexOf(self, ch)
   2.325 -        # lastIndexOf(self, ch, fromIndex)
   2.326 -        # lastIndexOf(self, str)
   2.327 -        # lastIndexOf(self, str, fromIndex)
   2.328 -        raise NotImplementedError, "lastIndexOf"
   2.329 -
   2.330 -    def substring(self, *args):
   2.331 -        # substring(self, beginIndex)
   2.332 -        # substring(self, beginIndex, endIndex)
   2.333 -        raise NotImplementedError, "substring"
   2.334 -
   2.335 -    def concat(self, str):
   2.336 -        raise NotImplementedError, "concat"
   2.337 -
   2.338 -    def replace(self, oldChar, newChar):
   2.339 -        raise NotImplementedError, "replace"
   2.340 -
   2.341 -    def toLowerCase(self, *args):
   2.342 -        # toLowerCase(self, locale)
   2.343 -        # toLowerCase(self)
   2.344 -        raise NotImplementedError, "toLowerCase"
   2.345 -
   2.346 -    def toUpperCase(self, *args):
   2.347 -        # toUpperCase(self, locale)
   2.348 -        # toUpperCase(self)
   2.349 -        raise NotImplementedError, "toUpperCase"
   2.350 -
   2.351 -    def trim(self):
   2.352 -        raise NotImplementedError, "trim"
   2.353 -
   2.354 -    def toString(self):
   2.355 -        return self
   2.356 -
   2.357 -    def toCharArray(self):
   2.358 -        raise NotImplementedError, "toCharArray"
   2.359 -
   2.360 -    def valueOf(self, *args):
   2.361 -        # valueOf(self, obj)
   2.362 -        # valueOf(self, data)
   2.363 -        # valueOf(self, data, offset, count)
   2.364 -        # valueOf(self, b)
   2.365 -        # valueOf(self, c)
   2.366 -        # valueOf(self, l)
   2.367 -        # valueOf(self, f)
   2.368 -        # valueOf(self, d)
   2.369 -        raise NotImplementedError, "valueOf"
   2.370 -    valueOf = staticmethod(valueOf)
   2.371 -
   2.372 -    def copyValueOf(self, *args):
   2.373 -        # copyValueOf(self, data, offset, count)
   2.374 -        # copyValueOf(self, data)
   2.375 -        raise NotImplementedError, "copyValueOf"
   2.376 -    copyValueOf = staticmethod(copyValueOf)
   2.377 -
   2.378 -    def intern(self):
   2.379 -        raise NotImplementedError, "intern"
   2.380 -
   2.381 -setattr(String, "__init_____", String.init__empty)
   2.382 -setattr(String, "__init_____java__lang__String", String.init__String)
   2.383 -
   2.384 -class System(object):
   2.385 -    in_ = java.io.InputStream(sys.stdin)
   2.386 -    out = java.io.PrintStream(sys.stdout)
   2.387 -    err = java.io.PrintStream(sys.stderr)
   2.388 -
   2.389 -    def getProperty___java__lang__String(key):
   2.390 -        try:
   2.391 -            return os.environ[key]
   2.392 -        except KeyError:
   2.393 -            return None
   2.394 -
   2.395 -    getProperty___java__lang__String = staticmethod(getProperty___java__lang__String)
   2.396 -
   2.397 -setattr(System, "in", System.in_)
   2.398 -
   2.399 -# vim: tabstop=4 expandtab shiftwidth=4