From f94f207732825e4976c5de417ff48ccfb2d96ba0 Mon Sep 17 00:00:00 2001 From: Jean Privat Date: Tue, 24 Feb 2015 23:15:26 +0700 Subject: [PATCH] nitpretty: handle super and class-level annotation as property Signed-off-by: Jean Privat --- src/pretty.nit | 45 +++++++++++++++------------------- tests/sav/fixme/nitpretty_args37.res | 44 +++++++++++++++++++++++++++++++++ tests/sav/fixme/nitpretty_args6.res | 38 ++++++++++++++++++++++++++++ tests/sav/nitpretty_args24.res | 1 - tests/sav/nitpretty_args28.res | 1 - tests/sav/nitpretty_args30.res | 1 - tests/sav/nitpretty_args7.res | 1 - 7 files changed, 102 insertions(+), 29 deletions(-) create mode 100644 tests/sav/fixme/nitpretty_args37.res create mode 100644 tests/sav/fixme/nitpretty_args6.res diff --git a/src/pretty.nit b/src/pretty.nit index 2d08571..83d5a58 100644 --- a/src/pretty.nit +++ b/src/pretty.nit @@ -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 index 0000000..491aedb --- /dev/null +++ b/tests/sav/fixme/nitpretty_args37.res @@ -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 index 0000000..658285b --- /dev/null +++ b/tests/sav/fixme/nitpretty_args6.res @@ -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 diff --git a/tests/sav/nitpretty_args24.res b/tests/sav/nitpretty_args24.res index 79ab858..51f9ae3 100644 --- a/tests/sav/nitpretty_args24.res +++ b/tests/sav/nitpretty_args24.res @@ -23,7 +23,6 @@ class A # ending comments super Object # super Int super String - # super Truc # inclass comments diff --git a/tests/sav/nitpretty_args28.res b/tests/sav/nitpretty_args28.res index 1944090..c2df28d 100644 --- a/tests/sav/nitpretty_args28.res +++ b/tests/sav/nitpretty_args28.res @@ -23,7 +23,6 @@ end class B super A - redef type FOO: Int # comment 3 diff --git a/tests/sav/nitpretty_args30.res b/tests/sav/nitpretty_args30.res index 57f7966..3d48538 100644 --- a/tests/sav/nitpretty_args30.res +++ b/tests/sav/nitpretty_args30.res @@ -23,7 +23,6 @@ end class B super A - redef type FOO: Int # comment 3 diff --git a/tests/sav/nitpretty_args7.res b/tests/sav/nitpretty_args7.res index ea248bc..8d2fb41 100644 --- a/tests/sav/nitpretty_args7.res +++ b/tests/sav/nitpretty_args7.res @@ -23,7 +23,6 @@ end class B super A - redef type FOO: Int # comment 3 -- 1.7.9.5