mirror of
https://github.com/vim/vim.git
synced 2025-09-23 03:43:49 -04:00
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>
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
// VIM_TEST_SETUP let g:java_highlight_functions = 'style'
|
||||
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
abstract class StyleMethodsTests
|
||||
{
|
||||
protected StyleMethodsTests() { }
|
||||
|
||||
// TYPES.
|
||||
record Τʬ<α>(α a) { }
|
||||
|
||||
enum 𝓔
|
||||
@@ -17,14 +17,14 @@ abstract class StyleMethodsTests
|
||||
private 𝓔(String 𝐬) { this.𝐬 = 𝐬; }
|
||||
}
|
||||
|
||||
@Target(java.lang.annotation.ElementType.METHOD)
|
||||
@Target({ElementType.METHOD, ElementType.CONSTRUCTOR})
|
||||
@java.lang.annotation.Repeatable(Tɐggablɘs.class)
|
||||
@interface Tɐggablɘ
|
||||
{
|
||||
String[] value() default "";
|
||||
}
|
||||
|
||||
@Target(java.lang.annotation.ElementType.METHOD)
|
||||
@Target({ElementType.METHOD, ElementType.CONSTRUCTOR})
|
||||
@interface Tɐggablɘs
|
||||
{
|
||||
Tɐggablɘ[] value();
|
||||
@@ -36,6 +36,17 @@ abstract class StyleMethodsTests
|
||||
default Α μʭʭ$0_() { return null; }
|
||||
}
|
||||
|
||||
// FIELDS.
|
||||
private static final Class<?> CLASS_LOCK = classLock();
|
||||
|
||||
private final Object instanceLock = new Object();
|
||||
|
||||
// CONSTRUCTORS.
|
||||
@Tɐggablɘ @Tɐggablɘ protected StyleMethodsTests() { }
|
||||
<T extends Comparable<T>> StyleMethodsTests(T t, Void v) { }
|
||||
private <T extends Comparable<T>> StyleMethodsTests(T t) { }
|
||||
|
||||
// METHODS.
|
||||
@Tɐggablɘ @Tɐggablɘ abstract void ascii$0_(////////////////
|
||||
);
|
||||
@Tɐggablɘ @Tɐggablɘ abstract <α, β> Τʬ<α> μʭʭ$0_(
|
||||
@@ -45,6 +56,9 @@ abstract class StyleMethodsTests
|
||||
@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<β, Τʬ<α>[][]> ƒ);
|
||||
@@ -61,6 +75,8 @@ abstract class StyleMethodsTests
|
||||
StyleMethodsTests.<α, β>μʭʭ$98_(ƒ)[0];
|
||||
}
|
||||
|
||||
public static Class<?> classLock() { return StyleMethodsTests.class; }
|
||||
|
||||
@Override @SuppressWarnings("cast")
|
||||
public String toString() { return (String) "StyleMethodsTests"; }
|
||||
}
|
||||
|
Reference in New Issue
Block a user