Path: blob/master/bin/blessed-modifier-order.sh
40675 views
#!/bin/bash1#2# Copyright 2015 Google, Inc. All Rights Reserved.3# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.4#5# This code is free software; you can redistribute it and/or modify it6# under the terms of the GNU General Public License version 2 only, as7# published by the Free Software Foundation.8#9# This code is distributed in the hope that it will be useful, but WITHOUT10# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or11# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License12# version 2 for more details (a copy is included in the LICENSE file that13# accompanied this code).14#15# You should have received a copy of the GNU General Public License version16# 2 along with this work; if not, write to the Free Software Foundation,17# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.18#19# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA20# or visit www.oracle.com if you need additional information or have any21# questions.2223usage() {24(25echo "$0 DIR ..."26echo "Modifies in place all the java source files found"27echo "in the given directories so that all java language modifiers"28echo "are in the canonical order given by Modifier#toString()."29echo "Tries to get it right even within javadoc comments,"30echo "and even if the list of modifiers spans 2 lines."31echo32echo "See:"33echo "https://docs.oracle.com/javase/8/docs/api/java/lang/reflect/Modifier.html#toString-int-"34echo35echo "Example:"36echo "$0 jdk/src/java.base jdk/test/java/{util,io,lang}"37) >&238exit 139}4041set -eu42declare -ar dirs=("$@")43[[ "${#dirs[@]}" > 0 ]] || usage44for dir in "${dirs[@]}"; do [[ -d "$dir" ]] || usage; done4546declare -ar modifiers=(47public protected private48abstract static final transient49volatile synchronized native strictfp50)51declare -r SAVE_IFS="$IFS"52for ((i = 3; i < "${#modifiers[@]}"; i++)); do53IFS='|'; x="${modifiers[*]:0:i}" y="${modifiers[*]:i}"; IFS="$SAVE_IFS"54if [[ -n "$x" && -n "$y" ]]; then55find "${dirs[@]}" -name '*.java' -type f -print0 | \56xargs -0 perl -0777 -p -i -e \57"do {} while s/^([A-Za-z@* ]*)\b($y)(\s|(?:\s|\n\s+\*)*\s)($x)\b/\1\4\3\2/mg"58fi59done606162