|
From: <pj...@us...> - 2011-03-22 02:38:23
|
Revision: 7261
http://jython.svn.sourceforge.net/jython/?rev=7261&view=rev
Author: pjenvey
Date: 2011-03-22 02:38:16 +0000 (Tue, 22 Mar 2011)
Log Message:
-----------
coding standards and other minor changes
Modified Paths:
--------------
trunk/jython/src/org/python/core/PyInstance.java
trunk/jython/src/org/python/core/PyInteger.java
trunk/jython/src/org/python/core/PyLong.java
trunk/jython/src/org/python/core/PyObject.java
trunk/jython/src/org/python/core/PyString.java
trunk/jython/src/org/python/core/__builtin__.java
trunk/jython/src/org/python/core/stringlib/FieldNameIterator.java
trunk/jython/src/org/python/core/stringlib/InternalFormatSpec.java
trunk/jython/src/org/python/core/stringlib/InternalFormatSpecParser.java
trunk/jython/src/org/python/core/stringlib/MarkupIterator.java
Modified: trunk/jython/src/org/python/core/PyInstance.java
===================================================================
--- trunk/jython/src/org/python/core/PyInstance.java 2011-03-21 23:11:25 UTC (rev 7260)
+++ trunk/jython/src/org/python/core/PyInstance.java 2011-03-22 02:38:16 UTC (rev 7261)
@@ -788,16 +788,17 @@
}
@Override
- public PyObject __format__(PyObject format_spec) {
- return instance___format__(format_spec);
+ public PyObject __format__(PyObject formatSpec) {
+ return instance___format__(formatSpec);
}
@ExposedMethod
- final PyObject instance___format__(PyObject format_spec) {
+ final PyObject instance___format__(PyObject formatSpec) {
PyObject func = __findattr__("__format__");
- if (func == null)
- return super.__format__(format_spec);
- return func.__call__(format_spec);
+ if (func == null) {
+ return super.__format__(formatSpec);
+ }
+ return func.__call__(formatSpec);
}
// Generated by make_binops.py
Modified: trunk/jython/src/org/python/core/PyInteger.java
===================================================================
--- trunk/jython/src/org/python/core/PyInteger.java 2011-03-21 23:11:25 UTC (rev 7260)
+++ trunk/jython/src/org/python/core/PyInteger.java 2011-03-22 02:38:16 UTC (rev 7261)
@@ -914,31 +914,30 @@
}
@Override
- public PyObject __format__(PyObject format_spec) {
- return int___format__(format_spec);
+ public PyObject __format__(PyObject formatSpec) {
+ return int___format__(formatSpec);
}
@ExposedMethod(doc = BuiltinDocs.int___format___doc)
- final PyObject int___format__(PyObject format_spec) {
- return formatImpl(getValue(), format_spec);
+ final PyObject int___format__(PyObject formatSpec) {
+ return formatImpl(getValue(), formatSpec);
}
- static PyObject formatImpl(Object value, PyObject format_spec) {
- if (format_spec instanceof PyString) {
- String result;
- try {
- String specString = ((PyString) format_spec).getString();
- InternalFormatSpec spec = new InternalFormatSpecParser(specString).parse();
- result = formatIntOrLong(value, spec);
- } catch (IllegalArgumentException e) {
- throw Py.ValueError(e.getMessage());
- }
- if (format_spec instanceof PyUnicode) {
- return new PyUnicode(result);
- }
- return new PyString(result);
+ static PyObject formatImpl(Object value, PyObject formatSpec) {
+ if (!(formatSpec instanceof PyString)) {
+ throw Py.TypeError("__format__ requires str or unicode");
}
- throw Py.TypeError("__format__ requires str or unicode");
+
+ PyString formatSpecStr = (PyString) formatSpec;
+ String result;
+ try {
+ String specString = formatSpecStr.getString();
+ InternalFormatSpec spec = new InternalFormatSpecParser(specString).parse();
+ result = formatIntOrLong(value, spec);
+ } catch (IllegalArgumentException e) {
+ throw Py.ValueError(e.getMessage());
+ }
+ return formatSpecStr.createInstance(result);
}
/**
@@ -956,15 +955,14 @@
if (value instanceof Integer) {
int intValue = (Integer) value;
sign = intValue < 0 ? -1 : intValue == 0 ? 0 : 1;
- }
- else {
+ } else {
sign = ((BigInteger) value).signum();
}
String strValue;
if (spec.type == 'c') {
if (spec.sign != '\0') {
- throw new IllegalArgumentException("Sign not allowed with " +
- "integer format specifier 'c'");
+ throw new IllegalArgumentException("Sign not allowed with integer format "
+ + "specifier 'c'");
}
if (value instanceof Integer) {
int intValue = (Integer) value;
@@ -972,8 +970,7 @@
throw new IllegalArgumentException("%c arg not in range(0x10000)");
}
strValue = Character.toString((char) intValue);
- }
- else {
+ } else {
BigInteger bigInt = (BigInteger) value;
if (bigInt.intValue() > 0xffff || bigInt.bitCount() > 16) {
throw new IllegalArgumentException("%c arg not in range(0x10000)");
@@ -993,18 +990,18 @@
// TODO locale-specific formatting for 'n'
if (value instanceof BigInteger) {
strValue = ((BigInteger) value).toString(radix);
- }
- else {
+ } else {
strValue = Integer.toString((Integer) value, radix);
}
if (spec.alternate) {
- if (radix == 2)
+ if (radix == 2) {
strValue = "0b" + strValue;
- else if (radix == 8)
+ } else if (radix == 8) {
strValue = "0o" + strValue;
- else if (radix == 16)
+ } else if (radix == 16) {
strValue = "0x" + strValue;
+ }
}
if (spec.type == 'X') {
strValue = strValue.toUpperCase();
Modified: trunk/jython/src/org/python/core/PyLong.java
===================================================================
--- trunk/jython/src/org/python/core/PyLong.java 2011-03-21 23:11:25 UTC (rev 7260)
+++ trunk/jython/src/org/python/core/PyLong.java 2011-03-22 02:38:16 UTC (rev 7261)
@@ -982,13 +982,13 @@
}
@Override
- public PyObject __format__(PyObject format_spec) {
- return long___format__(format_spec);
+ public PyObject __format__(PyObject formatSpec) {
+ return long___format__(formatSpec);
}
@ExposedMethod(doc = BuiltinDocs.long___format___doc)
- final PyObject long___format__(PyObject format_spec) {
- return PyInteger.formatImpl(getValue(), format_spec);
+ final PyObject long___format__(PyObject formatSpec) {
+ return PyInteger.formatImpl(getValue(), formatSpec);
}
@Override
Modified: trunk/jython/src/org/python/core/PyObject.java
===================================================================
--- trunk/jython/src/org/python/core/PyObject.java 2011-03-21 23:11:25 UTC (rev 7260)
+++ trunk/jython/src/org/python/core/PyObject.java 2011-03-22 02:38:16 UTC (rev 7261)
@@ -1710,14 +1710,13 @@
return false;
}
- public PyObject __format__(PyObject format_spec) {
- return object___format__(format_spec);
+ public PyObject __format__(PyObject formatSpec) {
+ return object___format__(formatSpec);
}
@ExposedMethod(doc = BuiltinDocs.object___format___doc)
- final PyObject object___format__(PyObject format_spec) {
- PyString str = __str__();
- return str.__format__(format_spec);
+ final PyObject object___format__(PyObject formatSpec) {
+ return __str__().__format__(formatSpec);
}
/**
Modified: trunk/jython/src/org/python/core/PyString.java
===================================================================
--- trunk/jython/src/org/python/core/PyString.java 2011-03-21 23:11:25 UTC (rev 7260)
+++ trunk/jython/src/org/python/core/PyString.java 2011-03-22 02:38:16 UTC (rev 7261)
@@ -2533,7 +2533,7 @@
final PyObject str_format(PyObject[] args, String[] keywords) {
try {
return new PyString(buildFormattedString(getString(), args, keywords));
- } catch(IllegalArgumentException e) {
+ } catch (IllegalArgumentException e) {
throw Py.ValueError(e.getMessage());
}
}
@@ -2562,11 +2562,9 @@
}
if ("r".equals(chunk.conversion)) {
fieldObj = fieldObj.__repr__();
- }
- else if ("s".equals(chunk.conversion)) {
+ } else if ("s".equals(chunk.conversion)) {
fieldObj = fieldObj.__str__();
- }
- else if (chunk.conversion != null) {
+ } else if (chunk.conversion != null) {
throw Py.ValueError("Unknown conversion specifier " + chunk.conversion);
}
String formatSpec = chunk.formatSpec;
@@ -2581,17 +2579,17 @@
Object head = iterator.head();
PyObject obj = null;
int positionalCount = args.length - keywords.length;
+
if (head instanceof Integer) {
int index = (Integer) head;
if (index >= positionalCount) {
throw Py.IndexError("tuple index out of range");
}
obj = args[index];
- }
- else {
+ } else {
for (int i = 0; i < keywords.length; i++) {
if (keywords[i].equals(head)) {
- obj = args[positionalCount+i];
+ obj = args[positionalCount + i];
break;
}
}
@@ -2607,14 +2605,15 @@
}
if (chunk.is_attr) {
obj = obj.__getattr__((String) chunk.value);
- }
- else {
+ } else {
PyObject key = chunk.value instanceof String
? new PyString((String) chunk.value)
: new PyInteger((Integer) chunk.value);
obj = obj.__getitem__(key);
}
- if (obj == null) break;
+ if (obj == null) {
+ break;
+ }
}
}
return obj;
@@ -2626,27 +2625,26 @@
}
@Override
- public PyObject __format__(PyObject format_spec) {
- return str___format__(format_spec);
+ public PyObject __format__(PyObject formatSpec) {
+ return str___format__(formatSpec);
}
@ExposedMethod(doc = BuiltinDocs.str___format___doc)
- final PyObject str___format__(PyObject format_spec) {
- if (format_spec instanceof PyString) {
- String result;
- try {
- String specString = ((PyString) format_spec).getString();
- InternalFormatSpec spec = new InternalFormatSpecParser(specString).parse();
- result = formatString(getString(), spec);
- } catch (IllegalArgumentException e) {
- throw Py.ValueError(e.getMessage());
- }
- if (format_spec instanceof PyUnicode) {
- return new PyUnicode(result);
- }
- return new PyString(result);
+ final PyObject str___format__(PyObject formatSpec) {
+ if (!(formatSpec instanceof PyString)) {
+ throw Py.TypeError("__format__ requires str or unicode");
}
- throw Py.TypeError("__format__ requires str or unicode");
+
+ PyString formatSpecStr = (PyString) formatSpec;
+ String result;
+ try {
+ String specString = formatSpecStr.getString();
+ InternalFormatSpec spec = new InternalFormatSpecParser(specString).parse();
+ result = formatString(getString(), spec);
+ } catch (IllegalArgumentException e) {
+ throw Py.ValueError(e.getMessage());
+ }
+ return formatSpecStr.createInstance(result);
}
/**
Modified: trunk/jython/src/org/python/core/__builtin__.java
===================================================================
--- trunk/jython/src/org/python/core/__builtin__.java 2011-03-21 23:11:25 UTC (rev 7260)
+++ trunk/jython/src/org/python/core/__builtin__.java 2011-03-22 02:38:16 UTC (rev 7261)
@@ -1314,7 +1314,7 @@
@Override
public PyObject __call__(PyObject arg1) {
- return __call__(arg1, new PyString(""));
+ return __call__(arg1, Py.EmptyString);
}
@Override
Modified: trunk/jython/src/org/python/core/stringlib/FieldNameIterator.java
===================================================================
--- trunk/jython/src/org/python/core/stringlib/FieldNameIterator.java 2011-03-21 23:11:25 UTC (rev 7260)
+++ trunk/jython/src/org/python/core/stringlib/FieldNameIterator.java 2011-03-22 02:38:16 UTC (rev 7261)
@@ -1,6 +1,11 @@
package org.python.core.stringlib;
-import org.python.core.*;
+import org.python.core.PyBoolean;
+import org.python.core.PyInteger;
+import org.python.core.PyObject;
+import org.python.core.PyString;
+import org.python.core.PyTuple;
+import org.python.core.PyType;
import org.python.expose.ExposedMethod;
import org.python.expose.ExposedType;
@@ -9,6 +14,9 @@
*/
@ExposedType(name = "fieldnameiterator", base = PyObject.class, isBaseType = false)
public class FieldNameIterator extends PyObject {
+
+ public static final PyType TYPE = PyType.fromClass(FieldNameIterator.class);
+
private String markup;
private Object head;
private int index;
@@ -26,15 +34,21 @@
@Override
public PyObject __iter__() {
- return this;
+ return fieldnameiterator___iter__();
}
@ExposedMethod
- public PyObject fieldnameiterator___iter__() {
+ final PyObject fieldnameiterator___iter__() {
return this;
}
+ @Override
public PyObject __iternext__() {
+ return fieldnameiterator___iternext__();
+ }
+
+ @ExposedMethod
+ final PyObject fieldnameiterator___iternext__() {
Chunk chunk = nextChunk();
if (chunk == null) {
return null;
@@ -43,23 +57,21 @@
elements [0] = new PyBoolean(chunk.is_attr);
if (chunk.value instanceof Integer) {
elements [1] = new PyInteger((Integer) chunk.value);
- }
- else {
+ } else {
elements [1] = new PyString((String) chunk.value);
}
return new PyTuple(elements);
}
- @ExposedMethod
- public PyObject fieldnameiterator___iternext__() {
- return __iternext__();
- }
-
private int nextDotOrBracket(String markup) {
int dotPos = markup.indexOf('.', index);
- if (dotPos < 0) dotPos = markup.length();
+ if (dotPos < 0) {
+ dotPos = markup.length();
+ }
int bracketPos = markup.indexOf('[', index);
- if (bracketPos < 0) bracketPos = markup.length();
+ if (bracketPos < 0) {
+ bracketPos = markup.length();
+ }
return Math.min(dotPos, bracketPos);
}
@@ -74,8 +86,7 @@
Chunk chunk = new Chunk();
if (markup.charAt(index) == '[') {
parseItemChunk(chunk);
- }
- else if (markup.charAt(index) == '.') {
+ } else if (markup.charAt(index) == '.') {
parseAttrChunk(chunk);
}
return chunk;
@@ -87,7 +98,7 @@
if (endBracket < 0) {
throw new IllegalArgumentException("Missing ']' in format string");
}
- String itemValue = markup.substring(index+1, endBracket);
+ String itemValue = markup.substring(index + 1, endBracket);
if (itemValue.length() == 0) {
throw new IllegalArgumentException("Empty attribute in format string");
}
@@ -96,7 +107,7 @@
} catch (NumberFormatException e) {
chunk.value = itemValue;
}
- index = endBracket+1;
+ index = endBracket + 1;
}
private void parseAttrChunk(Chunk chunk) {
@@ -112,6 +123,7 @@
public static class Chunk {
public boolean is_attr;
- public Object value; // Integer or String
+ /** Integer or String. */
+ public Object value;
}
}
Modified: trunk/jython/src/org/python/core/stringlib/InternalFormatSpec.java
===================================================================
--- trunk/jython/src/org/python/core/stringlib/InternalFormatSpec.java 2011-03-21 23:11:25 UTC (rev 7260)
+++ trunk/jython/src/org/python/core/stringlib/InternalFormatSpec.java 2011-03-22 02:38:16 UTC (rev 7261)
@@ -25,8 +25,7 @@
}
if (useAlign == '^') {
leading = remaining/2;
- }
- else if (useAlign == '<') {
+ } else if (useAlign == '<') {
leading = 0;
}
char fill = fill_char != 0 ? fill_char : ' ';
@@ -34,7 +33,7 @@
result.append(fill);
}
result.append(value);
- for (int i = 0; i < remaining-leading; i++) {
+ for (int i = 0; i < remaining - leading; i++) {
result.append(fill);
}
return result.toString();
Modified: trunk/jython/src/org/python/core/stringlib/InternalFormatSpecParser.java
===================================================================
--- trunk/jython/src/org/python/core/stringlib/InternalFormatSpecParser.java 2011-03-21 23:11:25 UTC (rev 7260)
+++ trunk/jython/src/org/python/core/stringlib/InternalFormatSpecParser.java 2011-03-22 02:38:16 UTC (rev 7261)
@@ -29,8 +29,7 @@
if (spec.length() >= 1 && isAlign(spec.charAt(0))) {
result.align = spec.charAt(index);
index++;
- }
- else if (spec.length() >= 2 && isAlign(spec.charAt(1))) {
+ } else if (spec.length() >= 2 && isAlign(spec.charAt(1))) {
result.fill_char = spec.charAt(0);
result.align = spec.charAt(1);
index += 2;
@@ -73,7 +72,9 @@
index++;
empty = false;
}
- if (empty) return -1;
+ if (empty) {
+ return -1;
+ }
return value;
}
Modified: trunk/jython/src/org/python/core/stringlib/MarkupIterator.java
===================================================================
--- trunk/jython/src/org/python/core/stringlib/MarkupIterator.java 2011-03-21 23:11:25 UTC (rev 7260)
+++ trunk/jython/src/org/python/core/stringlib/MarkupIterator.java 2011-03-22 02:38:16 UTC (rev 7261)
@@ -1,6 +1,10 @@
package org.python.core.stringlib;
-import org.python.core.*;
+import org.python.core.Py;
+import org.python.core.PyObject;
+import org.python.core.PyString;
+import org.python.core.PyTuple;
+import org.python.core.PyType;
import org.python.expose.ExposedMethod;
import org.python.expose.ExposedType;
@@ -9,6 +13,9 @@
*/
@ExposedType(name = "formatteriterator", base = PyObject.class, isBaseType = false)
public class MarkupIterator extends PyObject {
+
+ public static final PyType TYPE = PyType.fromClass(MarkupIterator.class);
+
private final String markup;
private int index;
@@ -18,15 +25,21 @@
@Override
public PyObject __iter__() {
- return this;
+ return formatteriterator___iter__();
}
@ExposedMethod
- public PyObject formatteriterator___iter__() {
+ final PyObject formatteriterator___iter__() {
return this;
}
+ @Override
public PyObject __iternext__() {
+ return formatteriterator___iternext__();
+ }
+
+ @ExposedMethod
+ final PyObject formatteriterator___iternext__() {
Chunk chunk;
try {
chunk = nextChunk();
@@ -40,36 +53,30 @@
elements[0] = new PyString(chunk.literalText);
elements[1] = new PyString(chunk.fieldName);
if (chunk.fieldName.length() > 0) {
- elements[2] = chunk.formatSpec == null ? Py.EmptyString : new PyString(chunk.formatSpec);
- }
- else {
+ elements[2] = chunk.formatSpec == null
+ ? Py.EmptyString : new PyString(chunk.formatSpec);
+ } else {
elements[2] = Py.None;
}
elements[3] = chunk.conversion == null ? Py.None : new PyString(chunk.conversion);
return new PyTuple(elements);
}
- @ExposedMethod
- public PyObject formatteriterator___iternext__() {
- return __iternext__();
- }
-
public Chunk nextChunk() {
if (index == markup.length()) {
return null;
}
Chunk result = new Chunk();
int pos = index;
- while(true) {
+ while (true) {
pos = indexOfFirst(markup, pos, '{', '}');
- if (pos >= 0 && pos < markup.length()-1 &&
- markup.charAt(pos+1) == markup.charAt(pos)) {
- pos += 2; // skip escaped bracket
- }
- else if (pos >= 0 && markup.charAt(pos) == '}') {
+ if (pos >= 0 && pos < markup.length() - 1
+ && markup.charAt(pos + 1) == markup.charAt(pos)) {
+ // skip escaped bracket
+ pos += 2;
+ } else if (pos >= 0 && markup.charAt(pos) == '}') {
throw new IllegalArgumentException("Single '}' encountered in format string");
- }
- else {
+ } else {
break;
}
}
@@ -87,8 +94,7 @@
if (markup.charAt(pos) == '{') {
count++;
result.formatSpecNeedsExpanding = true;
- }
- else if (markup.charAt(pos) == '}') {
+ } else if (markup.charAt(pos) == '}') {
count--;
if (count == 0) {
parseField(result, markup.substring(fieldStart, pos));
@@ -98,8 +104,9 @@
}
pos++;
}
- if (count > 0)
+ if (count > 0) {
throw new IllegalArgumentException("Single '{' encountered in format string");
+ }
index = pos;
}
return result;
@@ -125,14 +132,12 @@
throw new IllegalArgumentException("expected ':' " +
"after conversion specifier");
}
- result.formatSpec = fieldMarkup.substring(pos+1);
+ result.formatSpec = fieldMarkup.substring(pos + 1);
}
+ } else {
+ result.formatSpec = fieldMarkup.substring(pos + 1);
}
- else {
- result.formatSpec = fieldMarkup.substring(pos+1);
- }
- }
- else {
+ } else {
result.fieldName = fieldMarkup;
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|