You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
AttributeError when attempting static access to Class.class #5
$ j2py demoClass.java
Traceback (most recent call last):
File "/pathToPython/bin/j2py", line 258, in <module>
sys.exit(runMain(configScript(sys.argv[1:])))
File "/pathToPython/bin/j2py", line 57, in runMain
return runOneOrMany(options)
File "/pathToPython/bin/j2py", line 82, in runOneOrMany
return runTransform(options)
File "/pathToPython/bin/j2py", line 134, in runTransform
module.walk(tree)
File "/pathToPython/lib/python2.7/site-packages/java2python/compiler/visitor.py", line 86, in walk
visitor.walk(child, memo)
File "/pathToPython/lib/python2.7/site-packages/java2python/compiler/visitor.py", line 86, in walk
visitor.walk(child, memo)
File "/pathToPython/lib/python2.7/site-packages/java2python/compiler/visitor.py", line 86, in walk
visitor.walk(child, memo)
File "/pathToPython/lib/python2.7/site-packages/java2python/compiler/visitor.py", line 86, in walk
visitor.walk(child, memo)
File "/pathToPython/lib/python2.7/site-packages/java2python/compiler/visitor.py", line 86, in walk
visitor.walk(child, memo)
File "/pathToPython/lib/python2.7/site-packages/java2python/compiler/visitor.py", line 86, in walk
visitor.walk(child, memo)
File "/pathToPython/lib/python2.7/site-packages/java2python/compiler/visitor.py", line 86, in walk
visitor.walk(child, memo)
File "/pathToPython/lib/python2.7/site-packages/java2python/compiler/visitor.py", line 86, in walk
visitor.walk(child, memo)
File "/pathToPython/lib/python2.7/site-packages/java2python/compiler/visitor.py", line 83, in walk
visitor = self.accept(tree, memo)
File "/pathToPython/lib/python2.7/site-packages/java2python/compiler/visitor.py", line 43, in accept
return call(node, memo)
File "/pathToPython/lib/python2.7/site-packages/java2python/compiler/visitor.py", line 121, in acceptType
name = node.firstChildOfType(tokens.IDENT).text
AttributeError: 'NoneType' object has no attribute 'text'
The original offending line is actually a call to Logger.getLogger, like so:
In this case I can easily rewrite the Java code via search-and-replace or even comment the code out, but it would be nice to have this handled automatically.
There's actually a bit more to this. The expression is processed correctly if it's in a method. Fixing it to work in a class scope is easy enough, however, the resulting expression will produce invalid python because (in Python) the class object is not available during class definition.
The enum handlers have a technique of working around this -- they place the assignment expressions on the class after it's defined, e.g., :
class demoClass(object):
...
demoClass.klass = demoClass.__class__
I'm working on implementing similar logic here. Thanks for posting the issue.
Activity
natural commentedon Feb 8, 2012
Confirmed.
There's actually a bit more to this. The expression is processed correctly if it's in a method. Fixing it to work in a class scope is easy enough, however, the resulting expression will produce invalid python because (in Python) the class object is not available during class definition.
The enum handlers have a technique of working around this -- they place the assignment expressions on the class after it's defined, e.g., :
I'm working on implementing similar logic here. Thanks for posting the issue.
Blindly moves class-level expressions containing the class name
natural commentedon Feb 8, 2012
Working as of 7a6f0fb. Example:
The implementation is a bit hacky... but that just means it fits with the rest of the package.
Considering this closed for now.