diff --git a/controller_checkstyle.py b/controller_checkstyle.py new file mode 100644 index 0000000..ace6ee5 --- /dev/null +++ b/controller_checkstyle.py @@ -0,0 +1,25 @@ +import sys +import json + +import multiDeclRefactor + +### key: issue name in checkstyle, +### value: refactor method main entry +REFACTOR_DICT = { + "HackedMultipleVariableDeclarations" : multiDeclRefactor.refactor_decls +} + +def main(): + try: + data = json.load(sys.stdin) + + for issue, refactor in REFACTOR_DICT.iteritems(): + refactor(data[issue]) + + except ValueError: + for line in sys.stdin: + print line + sys.exit(1) + +if __name__ == '__main__': + main() \ No newline at end of file diff --git a/multiDeclRefactor.py b/multiDeclRefactor.py index 58539cc..1e69ffb 100644 --- a/multiDeclRefactor.py +++ b/multiDeclRefactor.py @@ -2,21 +2,21 @@ import shutil, tempfile import json -REFACTOR_ISSUE_NAME = "HackedMultipleVariableDeclarations" - def main(): try: - data = json.load(sys.stdin) - total_multi_decls = data[REFACTOR_ISSUE_NAME] - file_based_multi_decls = collect_by_file(total_multi_decls) - for refactor_file, multi_decls in file_based_multi_decls.iteritems(): - refactor_decls(refactor_file, multi_decls) + total_multi_decls = json.load(sys.stdin) + refactor_decls(total_multi_decls) except ValueError: for line in sys.stdin: print line sys.exit(1) -def refactor_decls(refactor_file, multi_decls): +def refactor_decls(total_multi_decls): + file_based_multi_decls = collect_by_file(total_multi_decls) + for refactor_file, multi_decls in file_based_multi_decls.iteritems(): + refactor_decls_in_single_file(refactor_file, multi_decls) + +def refactor_decls_in_single_file(refactor_file, multi_decls): # print multi_decls backup = refactor_file + ".origin" shutil.copyfile(refactor_file, backup) diff --git a/run-refactor.sh b/run-refactor.sh index 4073b3e..33d87d3 100755 --- a/run-refactor.sh +++ b/run-refactor.sh @@ -5,10 +5,10 @@ CHECK_STYLE_DIR=$SCRIPT_DIR/checkstyle CHECK_STYLE_ALL_JAR=$CHECK_STYLE_DIR/target/checkstyle-7.4-SNAPSHOT-all.jar -java -jar $CHECK_STYLE_ALL_JAR -c $SCRIPT_DIR/multiDeclChecks.xml -f json "$@" | python $SCRIPT_DIR/multiDeclRefactor.py +java -jar $CHECK_STYLE_ALL_JAR -c $SCRIPT_DIR/multiDeclChecks.xml -f json "$@" | python $SCRIPT_DIR/controller_checkstyle.py ##develop version call: using eclipse output of checkstyle, running refactor frontend -# java -cp $ROOT_DIR/checkstyle/target/classes:$(ls $ROOT_DIR/checkstyle/target/dependency/*.jar | tr '\n' : | rev | cut -c 2- | rev) com.puppycrawl.tools.checkstyle.Main -c $SCRIPT_DIR/multiDeclChecks.xml -f json "$@" | python $SCRIPT_DIR/multiDeclRefactor.py +# java -cp $ROOT_DIR/checkstyle/target/classes:$(ls $ROOT_DIR/checkstyle/target/dependency/*.jar | tr '\n' : | rev | cut -c 2- | rev) com.puppycrawl.tools.checkstyle.Main -c $SCRIPT_DIR/multiDeclChecks.xml -f json "$@" | python $SCRIPT_DIR/controller_checkstyle.py ## develop version call: using eclipse output of checkstyle, print AST tree # java -cp $ROOT_DIR/checkstyle/target/classes:$(ls $ROOT_DIR/checkstyle/target/dependency/*.jar | tr '\n' : | rev | cut -c 2- | rev) com.puppycrawl.tools.checkstyle.Main -t "$@"