0
0
mirror of https://github.com/vim/vim.git synced 2025-07-04 23:07:33 -04:00
vim/runtime/syntax/testdir/input/java_methods_indent2.java
Aliaksei Budavei c4d0c8c812
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>
2024-04-29 20:24:35 +02:00

93 lines
2.7 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// VIM_TEST_SETUP let g:java_highlight_functions = 'indent2'
import java.lang.annotation.ElementType;
import java.lang.annotation.Target;
abstract class Indent2MethodsTests
{ // DO NOT retab! THIS FILE; REMEMBER ABOUT testdir/ftplugin.
// TYPES.
record Τʬ<α>(α a) { }
enum 𝓔
{
A("𝕬"), B("𝕭"), C("𝕮"), D("𝕯"),
E("𝕰"), F("𝕱"), G("𝕲"), H("𝕳");
final String 𝐬;
private 𝓔(String 𝐬) { this.𝐬 = 𝐬; }
}
@Target({ElementType.METHOD, ElementType.CONSTRUCTOR})
@java.lang.annotation.Repeatable(Tɐggablɘs.class)
@interface Tɐggablɘ
{
String[] value() default "";
}
@Target({ElementType.METHOD, ElementType.CONSTRUCTOR})
@interface Tɐggablɘs
{
Tɐggablɘ[] value();
}
interface Stylable<Α>
{
default void ascii$0_() { }
default Α μʭʭ$0_() { return null; }
}
// FIELDS.
private static final Class<?> CLASS_LOCK = classLock();
private final Object instanceLock = new Object();
// CONSTRUCTORS.
@Tɐggablɘ @Tɐggablɘ protected Indent2MethodsTests() { }
<T extends Comparable<T>> Indent2MethodsTests(T t, Void v) { }
private <T extends Comparable<T>> Indent2MethodsTests(T t) { }
// METHODS.
@Tɐggablɘ @Tɐggablɘ abstract void ascii$0_(////////////////
);
@Tɐggablɘ @Tɐggablɘ abstract <α, β> Τʬ<α> μʭʭ$0_(
/* TODO: @SuppressWarnings("bespoke")*/ β 𝛽);
@Tɐggablɘ private native void ascii$1_(/*////////////*/);
@Tɐggablɘ private native <α, β> Τʬ<α>[] μʭʭ$1_(
java.util.function.Function<β, Τʬ<α>[]> ƒ);
void Ascii$2_() { }
<T, U extends Stylable<T>> void Μʭʭ$2_(U u) { }
static final native synchronized void ascii$98_();
static final native synchronized <α, β> Τʬ<α>[][] μʭʭ$98_(
java.util.function.Function<β, Τʬ<α>[][]> ƒ);
@SuppressWarnings("strictfp")
protected static final synchronized strictfp void ascii$99_()
{ ascii$98_(); }
@SuppressWarnings("strictfp")
protected static final synchronized strictfp <α, β> Τʬ<α>[] μʭʭ$99_(
java.util.function.Function<β, Τʬ<α>[][]> ƒ)
{
return
Indent2MethodsTests.<α, β>μʭʭ$98_(ƒ)[0];
}
public static Class<?> classLock() { return Indent2MethodsTests.class; }
@Override @SuppressWarnings("cast")
public String toString() { return (String) "Indent2MethodsTests"; }
}
enum 𝓔
{
@SuppressWarnings("bespoke") A("𝗔"),
B("𝗕"),
C("𝗖"), D("𝗗"),
E("𝗘"), F("𝗙"), G("𝗚"), H("𝗛");
final String 𝐬;
private 𝓔(String 𝐬) { this.𝐬 = 𝐬; }
}