nitpretty: handle super and class-level annotation as property
authorJean Privat <jean@pryen.org>
Tue, 24 Feb 2015 16:15:26 +0000 (23:15 +0700)
committerJean Privat <jean@pryen.org>
Tue, 24 Feb 2015 16:15:26 +0000 (23:15 +0700)
Signed-off-by: Jean Privat <jean@pryen.org>

src/pretty.nit
tests/sav/fixme/nitpretty_args37.res [new file with mode: 0644]
tests/sav/fixme/nitpretty_args6.res [new file with mode: 0644]
tests/sav/nitpretty_args24.res
tests/sav/nitpretty_args28.res
tests/sav/nitpretty_args30.res
tests/sav/nitpretty_args7.res

index 2d08571..83d5a58 100644 (file)
@@ -691,8 +691,8 @@ redef class AStdClassdef
                if can_inline then
                        v.adds
 
-                       if not n_superclasses.is_empty then
-                               for n_superclass in n_superclasses do
+                       if not n_propdefs.is_empty then
+                               for n_superclass in n_propdefs do
                                        v.visit n_superclass
                                        v.adds
                                end
@@ -702,18 +702,6 @@ redef class AStdClassdef
                        if v.skip_empty then v.addn
                        v.indent += 1
 
-                       for n_superclass in n_superclasses do
-                               v.catch_up n_superclass
-                               v.addt
-                               v.visit n_superclass
-                               v.finish_line
-                               v.addn
-                       end
-
-                       if not n_superclasses.is_empty and not n_propdefs.is_empty then
-                               if v.skip_empty then v.addn
-                       end
-
                        super
                        v.catch_up n_kwend
                        v.indent -= 1
@@ -727,8 +715,9 @@ redef class AStdClassdef
 
        redef fun is_inlinable do
                if not super then return false
-               if not n_propdefs.is_empty then return false
-               if n_superclasses.length > 1 then return false
+               # FIXME: repair pretty-printing one-liner classes
+               if n_propdefs.length > 0 then return false
+               #if n_propdefs.length == 1 and not n_propdefs.first isa ASuperPropdef then return false
                if not collect_comments.is_empty then return false
                return true
        end
@@ -785,14 +774,6 @@ redef class AType
        end
 end
 
-redef class ASuperclass
-       redef fun accept_pretty_printer(v) do
-               v.visit n_kwsuper
-               v.adds
-               v.visit n_type
-       end
-end
-
 # Properties
 
 redef class APropdef
@@ -800,7 +781,7 @@ redef class APropdef
                v.visit n_doc
                v.addt
 
-               if not n_visibility isa APublicVisibility then
+               if not n_visibility isa nullable APublicVisibility then
                        v.visit n_visibility
                        v.adds
                end
@@ -1005,6 +986,20 @@ redef class AMainMethPropdef
        end
 end
 
+redef class ASuperPropdef
+       redef fun accept_pretty_printer(v) do
+               super
+               v.visit n_kwsuper
+               v.adds
+               v.visit n_type
+               visit_annotations(v, n_annotations)
+               v.finish_line
+               v.addn
+       end
+
+       redef fun is_inlinable do return true
+end
+
 redef class ASignature
        redef fun accept_pretty_printer(v) do
                if not n_params.is_empty then
diff --git a/tests/sav/fixme/nitpretty_args37.res b/tests/sav/fixme/nitpretty_args37.res
new file mode 100644 (file)
index 0000000..491aedb
--- /dev/null
@@ -0,0 +1,44 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# comment
+class A end
+
+class B[T] # comment
+       # comment
+       # comment
+       super A # comment
+
+
+       super C[A, B[A]]
+       # comment
+end
+
+class C[U, V: B[A]] end # comment
+
+class D
+       super A
+
+
+end # comment
+
+class E
+
+
+
+       super A # comment
+end
+
+# end
+
diff --git a/tests/sav/fixme/nitpretty_args6.res b/tests/sav/fixme/nitpretty_args6.res
new file mode 100644 (file)
index 0000000..658285b
--- /dev/null
@@ -0,0 +1,38 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# comment
+class A end
+
+class B[T] # comment
+
+       # comment
+       # comment
+       super A # comment
+
+       super C[A, B[A]]
+       # comment
+end
+
+class C[U, V: B[A]] end # comment
+
+class D
+       super A
+end # comment
+
+class E
+       super A # comment
+end
+
+# end
index 79ab858..51f9ae3 100644 (file)
@@ -23,7 +23,6 @@ class A # ending comments
        super Object
        # super Int
        super String
-
        # super Truc
 
        # inclass comments
index 1944090..c2df28d 100644 (file)
@@ -23,7 +23,6 @@ end
 
 class B
        super A
-
        redef type FOO: Int
 
        # comment 3
index 57f7966..3d48538 100644 (file)
@@ -23,7 +23,6 @@ end
 
 class B
        super A
-
        redef type FOO: Int
 
        # comment 3
index ea248bc..8d2fb41 100644 (file)
@@ -23,7 +23,6 @@ end
 
 class B
        super A
-
        redef type FOO: Int
 
        # comment 3