vincenthz/language-java — pull request #5 by JanBessai (2013-03-02 00:29:16+00:00)
Title: Prettyprinting precedence

Hi,

first of all thanks for your great work!

I think, I discovered an error concerning the operator precedence of cast:
```haskell
import Language.Java.Syntax
import Language.Java.Pretty

castError =
MethodInv $ PrimaryMethodCall
(Cast (RefType . ClassRefType $ ClassType [(Ident "SomeObject", [])])
(ExpName $ Name [Ident "someVar"]))
[]
(Ident "someMethod")
[]

prettyError = pretty castError
```
The code above produces
```java
(SomeObject) someVar.someMethod()
```
but should produce
```java
((SomeObject) someVar).someMethod()
```

The bug is hidden in the code for method invocations:
```haskell
prettyPrec p (MethodInv mi) = parenPrec p 1 $ prettyPrec 1 mi
```
will call `pretty` from `MethodInvocation`, because `MethodInvocation` does not define `prettyPrec`.

My pull request contains a version which uses `prettyPrec p` everywhere. This way precedences always get passed down. It might be improved in a later version to use a state monad hiding the argument in places where it is not necessary.

It would be cool to have the repaired version in darcs.

Thanks for considering my request,
Jan