]> git.ipfire.org Git - thirdparty/vim.git/commit
runtime(java): Improve the recognition of the "indent" method declarations (#14659)
authorAliaksei Budavei <32549825+zzzyxwvut@users.noreply.github.com>
Mon, 29 Apr 2024 18:24:35 +0000 (21:24 +0300)
committerGitHub <noreply@github.com>
Mon, 29 Apr 2024 18:24:35 +0000 (20:24 +0200)
commitc4d0c8c81245918632a9d3c2c20a390546fad065
treebec7d33035961dba690baf41e20a2fc2686c4679
parent04e1aaa94e3b7bf3ae6d376f52504aeb02bc9ca5
runtime(java): Improve the recognition of the "indent" method declarations (#14659)

There is a flaw in the current implementation that has been
exacerbated around v5.2.  It lies in the recognition of all
three indentation styles simultaneously: a tab, two space,
and eight space character(s).  With it, it is not uncommon
to misidentify various constructs as method declarations
when they belong to two-space indented members and other
blocks of a type and are offset at eight space characters or
a tab from the start of the line.

For example,

------------------------------------------------------------
class Test
{
  static String hello() { return "hello"; }

  public static void main(String[] args)
  {
    try {
      if (args.length > 0) {
        // FIXME: eight spaces.
        System.out.println(args[0]);
      } else {
        // FIXME: a tab.
System.out.println(hello());
      }
    } catch (Exception e) {
      throw new Error(e);
    }
  }
}
------------------------------------------------------------

------------------------------------------------------------
:let g:java_highlight_functions = 'indent'
:doautocmd Syntax
------------------------------------------------------------

A better approach is to pick an only indentation style out
of all supported styles (so either two spaces _or_ eight
spaces _or_ a tab).  Note that tabs and spaces can still be
mixed, only the leading tab or the leading run of spaces
matters for the recognition.  And there is no reason to not
complement the set of valid styles with any number of spaces
from 1 to 8, inclusively.

Please proceed with the necessary change as follows:

- rename from "indent" to "indent2" for a 2-space run;
- rename from "indent" to "indent8" for an 8-space run;
- continue to have "indent" for a tab run;
- define an "indent" variable with a suffix number denoting
  the preferred amount of indentation for any other run of
  spaces [1-8].

As before, this alternative style of recognition of method
declarations still does not prescribe naming conventions and
still cannot recognise method declarations in nested types
that are conventionally indented.

The proposed changes also follow suit of "style" in stopping
the claiming of constructor and enum constant declarations.

Signed-off-by: Aliaksei Budavei <0x000c70@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
36 files changed:
runtime/doc/syntax.txt
runtime/syntax/java.vim
runtime/syntax/testdir/dumps/java_methods_indent2_00.dump [new file with mode: 0644]
runtime/syntax/testdir/dumps/java_methods_indent2_01.dump [new file with mode: 0644]
runtime/syntax/testdir/dumps/java_methods_indent2_02.dump [new file with mode: 0644]
runtime/syntax/testdir/dumps/java_methods_indent2_03.dump [new file with mode: 0644]
runtime/syntax/testdir/dumps/java_methods_indent2_04.dump [new file with mode: 0644]
runtime/syntax/testdir/dumps/java_methods_indent2_99.dump [new file with mode: 0644]
runtime/syntax/testdir/dumps/java_methods_indent4_00.dump [new file with mode: 0644]
runtime/syntax/testdir/dumps/java_methods_indent4_01.dump [new file with mode: 0644]
runtime/syntax/testdir/dumps/java_methods_indent4_02.dump [new file with mode: 0644]
runtime/syntax/testdir/dumps/java_methods_indent4_03.dump [new file with mode: 0644]
runtime/syntax/testdir/dumps/java_methods_indent4_04.dump [new file with mode: 0644]
runtime/syntax/testdir/dumps/java_methods_indent4_99.dump [new file with mode: 0644]
runtime/syntax/testdir/dumps/java_methods_indent8_00.dump [new file with mode: 0644]
runtime/syntax/testdir/dumps/java_methods_indent8_01.dump [new file with mode: 0644]
runtime/syntax/testdir/dumps/java_methods_indent8_02.dump [new file with mode: 0644]
runtime/syntax/testdir/dumps/java_methods_indent8_03.dump [new file with mode: 0644]
runtime/syntax/testdir/dumps/java_methods_indent8_04.dump [new file with mode: 0644]
runtime/syntax/testdir/dumps/java_methods_indent8_99.dump [new file with mode: 0644]
runtime/syntax/testdir/dumps/java_methods_indent_00.dump [deleted file]
runtime/syntax/testdir/dumps/java_methods_indent_01.dump [deleted file]
runtime/syntax/testdir/dumps/java_methods_indent_02.dump [deleted file]
runtime/syntax/testdir/dumps/java_methods_indent_03.dump [deleted file]
runtime/syntax/testdir/dumps/java_methods_indent_99.dump [deleted file]
runtime/syntax/testdir/dumps/java_methods_style_00.dump
runtime/syntax/testdir/dumps/java_methods_style_01.dump
runtime/syntax/testdir/dumps/java_methods_style_02.dump
runtime/syntax/testdir/dumps/java_methods_style_03.dump
runtime/syntax/testdir/dumps/java_methods_style_04.dump [new file with mode: 0644]
runtime/syntax/testdir/dumps/java_methods_style_99.dump
runtime/syntax/testdir/input/java_methods_indent.java [deleted file]
runtime/syntax/testdir/input/java_methods_indent2.java [new file with mode: 0644]
runtime/syntax/testdir/input/java_methods_indent4.java [new file with mode: 0644]
runtime/syntax/testdir/input/java_methods_indent8.java [new file with mode: 0644]
runtime/syntax/testdir/input/java_methods_style.java