annotate bin/blessed-modifier-order.sh @ 50466:2f0c14b69efa

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