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