/* * Copyright (c) 2024 Qualcomm Innovation Center, Inc. * and other copyright owners as documented in the project's IP log. * * This program and the accompanying materials are made available under the * terms of the Eclipse Distribution License v. 1.0 which is available at * https://www.eclipse.org/org/documents/edl-v10.php. * * SPDX-License-Identifier: BSD-3-Clause */ package org.eclipse.jgit.diff; import java.util.List; import java.util.regex.Pattern; import java.util.stream.Collectors; /** * Built-in drivers for various languages, sorted by name. These drivers will be * used to determine function names for a hunk. *
* When writing or updating patterns, assume the contents are syntactically
* correct. Patterns can be simple and need not cover all syntactical corner
* cases, as long as they are sufficiently permissive.
*
* @since 6.10.1
*/
@SuppressWarnings({"ImmutableEnumChecker", "nls"})
public enum DiffDriver {
/**
* Built-in diff driver for c++
*/
cpp(List.of(
/* Jump targets or access declarations */
"^[ \\t]*[A-Za-z_][A-Za-z_0-9]*:\\s*($|/[/*])"), List.of(
/* functions/methods, variables, and compounds at top level */
"^((::\\s*)?[A-Za-z_].*)$")),
/**
* Built-in diff driver for device
* tree files
*/
dts(List.of(";", "="), List.of(
/* lines beginning with a word optionally preceded by '&' or the root */
"^[ \\t]*((/[ \\t]*\\{|&?[a-zA-Z_]).*)")),
/**
* Built-in diff driver for java
*/
java(List.of(
"^[ \\t]*(catch|do|for|if|instanceof|new|return|switch|throw|while)"),
List.of(
/* Class, enum, interface, and record declarations */
"^[ \\t]*(([a-z-]+[ \\t]+)*(class|enum|interface|record)[ \\t]+.*)$",
/* Method definitions; note that constructor signatures are not */
/* matched because they are indistinguishable from method calls. */
"^[ \\t]*(([A-Za-z_<>&\\]\\[][?&<>.,A-Za-z_0-9]*[ \\t]+)+[A-Za-z_]"
+ "[A-Za-z_0-9]*[ \\t]*\\([^;]*)$")),
/**
* Built-in diff driver for
* python
*/
python(List.of("^[ \\t]*((class|(async[ \\t]+)?def)[ \\t].*)$")),
/**
* Built-in diff driver for
* rust
*/
rust(List.of("^[\\t ]*((pub(\\([^\\)]+\\))?[\\t ]+)?"
+ "((async|const|unsafe|extern([\\t ]+\"[^\"]+\"))[\\t ]+)?"
+ "(struct|enum|union|mod|trait|fn|impl|macro_rules!)[< \\t]+[^;]*)$"));
private final List