Skip to content

Instantly share code, notes, and snippets.

@henrik242 henrik242/java2kt2java.sh
Last active Jan 11, 2019

Embed
What would you like to do?
Preliminary work that commits renames of .java files to .kt, and renames them back to prepare for IntelliJ code conversion
#!/usr/bin/env bash
set -o errexit -o pipefail -o nounset
if [[ $# -eq 0 ]]; then
echo "Usage: $0 someclass.java [someotherclass.groovy ...]"
exit 1
fi
printf "\n\nMoving files with git\n\n"
function resolveFile {
EXT=${1##*.}
BASE=$(basename $1 .$EXT)
BASEFILE=$(dirname $1)/$BASE
}
for file in $@; do
if [[ ! -f $file ]]; then
echo Error: Does not exist: $file
exit 1
fi
resolveFile $file
git mv -v $file $BASEFILE.kt \
&& FILES+="-i $BASEFILE.kt -i $file " \
&& NAMES+="$BASE "
done
if [[ -n "$FILES" ]]; then
printf "\n\nCommitting\n\n"
git commit -m"$NAMES -> kt, part 1" $FILES
printf "\n\nMoving files back\n\n"
for file in $@; do
resolveFile $file
mv -v $BASEFILE.kt $BASEFILE.java
done
printf "\n\nOkay, if there are no errors above, run Code » Convert Java to Kotlin in IntelliJ\n\n"
else
printf "\n\nSomething failed\n\n"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.