32564
|
1 |
#!/bin/bash
|
|
2 |
#
|
|
3 |
# Copyright 2015 Google, Inc. All Rights Reserved.
|
|
4 |
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
5 |
#
|
|
6 |
# This code is free software; you can redistribute it and/or modify it
|
|
7 |
# under the terms of the GNU General Public License version 2 only, as
|
|
8 |
# published by the Free Software Foundation.
|
|
9 |
#
|
|
10 |
# This code is distributed in the hope that it will be useful, but WITHOUT
|
|
11 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
12 |
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
13 |
# version 2 for more details (a copy is included in the LICENSE file that
|
|
14 |
# accompanied this code).
|
|
15 |
#
|
|
16 |
# You should have received a copy of the GNU General Public License version
|
|
17 |
# 2 along with this work; if not, write to the Free Software Foundation,
|
|
18 |
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
19 |
#
|
|
20 |
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
21 |
# or visit www.oracle.com if you need additional information or have any
|
|
22 |
# questions.
|
|
23 |
|
|
24 |
usage() {
|
|
25 |
(
|
|
26 |
echo "$0 DIR ..."
|
|
27 |
echo "Modifies in place all the java source files found"
|
|
28 |
echo "in the given directories so that all java language modifiers"
|
|
29 |
echo "are in the canonical order given by Modifier#toString()."
|
|
30 |
echo "Tries to get it right even within javadoc comments,"
|
|
31 |
echo "and even if the list of modifiers spans 2 lines."
|
|
32 |
echo
|
|
33 |
echo "See:"
|
|
34 |
echo "https://docs.oracle.com/javase/8/docs/api/java/lang/reflect/Modifier.html#toString-int-"
|
|
35 |
echo
|
|
36 |
echo "Example:"
|
|
37 |
echo "$0 jdk/src/java.base jdk/test/java/{util,io,lang}"
|
|
38 |
) >&2
|
|
39 |
exit 1
|
|
40 |
}
|
|
41 |
|
|
42 |
set -eu
|
|
43 |
declare -ar dirs=("$@")
|
|
44 |
[[ "${#dirs[@]}" > 0 ]] || usage
|
|
45 |
for dir in "${dirs[@]}"; do [[ -d "$dir" ]] || usage; done
|
|
46 |
|
|
47 |
declare -ar modifiers=(
|
|
48 |
public protected private
|
|
49 |
abstract static final transient
|
|
50 |
volatile synchronized native strictfp
|
|
51 |
)
|
|
52 |
declare -r SAVE_IFS="$IFS"
|
|
53 |
for ((i = 3; i < "${#modifiers[@]}"; i++)); do
|
|
54 |
IFS='|'; x="${modifiers[*]:0:i}" y="${modifiers[*]:i}"; IFS="$SAVE_IFS"
|
|
55 |
if [[ -n "$x" && -n "$y" ]]; then
|
|
56 |
find "${dirs[@]}" -name '*.java' -type f -print0 | \
|
|
57 |
xargs -0 perl -0777 -p -i -e \
|
|
58 |
"do {} while s/^([A-Za-z@* ]*)\b($y)(\s|(?:\s|\n\s+\*)*\s)($x)\b/\1\4\3\2/mg"
|
|
59 |
fi
|
|
60 |
done
|