From f3ce02aa66bc951d4bf5ef4c8485ac2118f0b66f Mon Sep 17 00:00:00 2001 From: David Ortiz Date: Fri, 15 May 2015 20:39:54 +0200 Subject: [PATCH 01/42] Put help message on separated def for easier testing --- src/app/interactive.clj | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/app/interactive.clj b/src/app/interactive.clj index 65f04e2..8e2e1c2 100644 --- a/src/app/interactive.clj +++ b/src/app/interactive.clj @@ -33,6 +33,17 @@ (def no-classes-loaded-error "No classes loaded. Use first") +(def help-message + (str + "h/help : print this help message \n" + "q/quit/exit : close the shell \n" + "list : list classes loaded \n" + "load DIR : load classes from DIR \n" + "mc/many-constructors th NUM : list classes with NUM or more constructors \n" + "mcp/many-constructor-params th NUM : list constructors with NUM or more parameters \n" + "f/finalizers : list classes that use finalizers \n" + "st/singletons : list singletons")) + (declare interactive) (defn- exit [] @@ -49,15 +60,8 @@ (println no-classes-loaded-error)) (interactive state))) -(defn- help [state] - (println "h/help : print this help message") - (println "q/quit/exit : close the shell") - (println "list : list classes loaded") - (println "load DIR : load classes from DIR") - (println "mc/many-constructors th NUM : list classes with NUM or more constructors") - (println "mcp/many-constructor-params th NUM : list constructors with NUM or more parameters") - (println "f/finalizers : list classes that use finalizers") - (println "st/singletons : list singletons") +(defn- show-help [state] + (println help-message) (interactive state)) (defn- load-classes [ast] @@ -100,7 +104,7 @@ (case command :EXIT (exit) :LIST (list-loaded-classes state) - :HELP (help state) + :HELP (show-help state) :LOAD (load-classes ast) :MC (let [threshold (read-string (last (last (first ast))))] (mc-operation state threshold)) From 8a321cee5441dfc18b233fec2daa28c4dc9c2189 Mon Sep 17 00:00:00 2001 From: David Ortiz Date: Fri, 15 May 2015 20:45:22 +0200 Subject: [PATCH 02/42] Add test for show-help in interactive mode --- test/app/test/interactive.clj | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/app/test/interactive.clj b/test/app/test/interactive.clj index 39f9451..ed7e852 100644 --- a/test/app/test/interactive.clj +++ b/test/app/test/interactive.clj @@ -12,6 +12,16 @@ (verify-call-times-for println 1) (verify-first-call-args-for println "Exit..."))))) +(deftest shows-help + (let [command-sequence ["help" "quit"] + input-string (clojure.string/join "\r" command-sequence)] + (with-in-str + input-string + (mocking [println print flush] + (interactive []) + (verify-call-times-for println 2) + (verify-first-call-args-for println help-message))))) + (deftest list-shows-error-if-no-classes-loaded (let [command-sequence ["list" "quit"] input-string (clojure.string/join "\r" command-sequence)] From 884913de1184010c2bc86aa569d03aebbe032b37 Mon Sep 17 00:00:00 2001 From: David Ortiz Date: Fri, 15 May 2015 20:47:40 +0200 Subject: [PATCH 03/42] Extract command-sequence->input-str function --- test/app/test/interactive.clj | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/test/app/test/interactive.clj b/test/app/test/interactive.clj index ed7e852..42fd8ff 100644 --- a/test/app/test/interactive.clj +++ b/test/app/test/interactive.clj @@ -3,6 +3,9 @@ [conjure.core] [clojure.test])) +(defn- command-sequence->input-str [command-sequence] + (clojure.string/join "\r" command-sequence)) + (deftest can-quit (let [input-command "quit\r"] (with-in-str @@ -14,7 +17,7 @@ (deftest shows-help (let [command-sequence ["help" "quit"] - input-string (clojure.string/join "\r" command-sequence)] + input-string (command-sequence->input-str command-sequence)] (with-in-str input-string (mocking [println print flush] @@ -24,7 +27,7 @@ (deftest list-shows-error-if-no-classes-loaded (let [command-sequence ["list" "quit"] - input-string (clojure.string/join "\r" command-sequence)] + input-string (command-sequence->input-str command-sequence)] (with-in-str input-string (mocking [println print flush] From 82d3ed855ef83f3aa26b1c163ff388e240b715e7 Mon Sep 17 00:00:00 2001 From: David Ortiz Date: Fri, 15 May 2015 23:57:55 +0200 Subject: [PATCH 04/42] Delete redundant :use calls --- src/app/interactive.clj | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/app/interactive.clj b/src/app/interactive.clj index 8e2e1c2..b39a071 100644 --- a/src/app/interactive.clj +++ b/src/app/interactive.clj @@ -1,10 +1,10 @@ (ns app.interactive - (:use [app.model.protocols]) - (:use [app.model.javaparser]) - (:use [app.javaparser.navigation]) - (:use [app.operations]) - (:use [app.itemsOnLifecycle]) - (:use [app.utils]) + (:use [app.model.protocols] + [app.model.javaparser] + [app.javaparser.navigation] + [app.operations] + [app.itemsOnLifecycle] + [app.utils]) (:require [instaparse.core :as insta]) (:import [app.operations Operation])) From 2479c12a7954ebba91f5f4db06e8ec466982b1c1 Mon Sep 17 00:00:00 2001 From: David Ortiz Date: Sat, 16 May 2015 00:51:05 +0200 Subject: [PATCH 05/42] Add test for mc operation in interactive mode --- test/app/test/interactive.clj | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/test/app/test/interactive.clj b/test/app/test/interactive.clj index 42fd8ff..7316589 100644 --- a/test/app/test/interactive.clj +++ b/test/app/test/interactive.clj @@ -1,8 +1,14 @@ (ns app.test.interactive (:use [app.interactive] + [app.javaparser.navigation] + [app.operations] + [app.itemsOnLifecycle] [conjure.core] [clojure.test])) +(def javaparser-cus-path + "test-resources/sample-codebases/javaparser/") + (defn- command-sequence->input-str [command-sequence] (clojure.string/join "\r" command-sequence)) @@ -35,3 +41,19 @@ (verify-call-times-for println 2) (verify-first-call-args-for println no-classes-loaded-error))))) + +(deftest can-execute-mc-operation + (let [javaparser-cus {:cus (take 2 (cus javaparser-cus-path))} + mc-op-threshold 3 + command-sequence [(str "mc th " mc-op-threshold) "quit"] + input-string (command-sequence->input-str command-sequence)] + (with-in-str + input-string + (mocking [println print flush printOperation] + (interactive javaparser-cus) + (verify-call-times-for printOperation 1) + (verify-first-call-args-for + printOperation + classesWithManyConstructorsOp + (:cus javaparser-cus) + mc-op-threshold))))) From 53d64975408bf0b5e083a7b4dc9414ca12bd5300 Mon Sep 17 00:00:00 2001 From: Federico Tomassetti Date: Sat, 16 May 2015 10:53:55 +0100 Subject: [PATCH 06/42] rename protocol scope to Scope --- src/app/symbol_solver/scope.clj | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/app/symbol_solver/scope.clj b/src/app/symbol_solver/scope.clj index cb89923..d1236ef 100644 --- a/src/app/symbol_solver/scope.clj +++ b/src/app/symbol_solver/scope.clj @@ -64,28 +64,28 @@ ; scope: we define which declarations are visible ; ================================================ -(defprotocol scope +(defprotocol Scope ; for example in a BlockStmt containing statements [a b c d e], when solving symbols in the context of c ; it will contains only statements preceeding it [a b] (solveSymbol [this context nameToSolve]) ; solveClass solve on a subset of the elements of solveSymbol (solveClass [this context nameToSolve])) -(extend-protocol scope +(extend-protocol Scope nil (solveClass [this context nameToSolve] (typeSolver nameToSolve))) (defn declare-symbol? [symbol-name symbols-declarator] (get (declared-symbols symbols-declarator) symbol-name)) -(extend-protocol scope +(extend-protocol Scope com.github.javaparser.ast.Node (solveSymbol [this context nameToSolve] (solveSymbol (.getParentNode this) this nameToSolve)) (solveClass [this context nameToSolve] (solveClass (.getParentNode this) this nameToSolve))) -(extend-protocol scope +(extend-protocol Scope BlockStmt (solveSymbol [this context nameToSolve] (let [elementsToConsider (if (nil? context) (.getStmts this) (preceedingChildren (.getStmts this) context)) @@ -118,7 +118,7 @@ solvedSymbols' (remove nil? solvedSymbols)] (first solvedSymbols'))) -(extend-protocol scope +(extend-protocol Scope com.github.javaparser.ast.body.ClassOrInterfaceDeclaration (solveSymbol [this context nameToSolve] (let [amongDeclaredFields (solveAmongDeclaredFields this nameToSolve)] @@ -140,7 +140,7 @@ matchingParameters (filter (fn [p] (= nameToSolve (.getName (.getId p)))) parameters)] (first matchingParameters))) -(extend-protocol scope +(extend-protocol Scope com.github.javaparser.ast.body.MethodDeclaration (solveSymbol [this context nameToSolve] (or (solve-among-parameters this nameToSolve) @@ -166,7 +166,7 @@ correspondingClasses (map typeSolver importNames)] (first correspondingClasses))) -(extend-protocol scope +(extend-protocol Scope com.github.javaparser.ast.CompilationUnit ; TODO consider imports (solveClass [this context nameToSolve] From 5b21a9b40ac045d713e3e236de00d1ee047eb1be Mon Sep 17 00:00:00 2001 From: David Ortiz Date: Sat, 16 May 2015 13:46:36 +0200 Subject: [PATCH 07/42] Use clojure.string/join instead of repeating \n --- src/app/interactive.clj | 46 +++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/src/app/interactive.clj b/src/app/interactive.clj index b39a071..cb0035a 100644 --- a/src/app/interactive.clj +++ b/src/app/interactive.clj @@ -13,19 +13,20 @@ ; ============================================ (def commands-grammar - (str - " = HELP | EXIT | LOAD | LIST | MC | MCP | F | ST \n" - "HELP = 'help' | 'h' \n" - "EXIT = 'exit' | 'quit' | 'q' \n" - "LOAD = 'load' STR \n" - "LIST = 'list' \n" - "MC = ('mc'|'many-constructors') 'th' NUM \n" - "MCP = ('mcp'|'many-costructor-params') 'th' NUM \n" - "F = ('f'|'finalizers') \n" - "ST = ('st'|'singletons') \n" - "WS = #'[\t ]+' \n" - "NUM = #'[0-9]+' \n" - "STR = #'\"[^\"]*\"' \n")) + (clojure.string/join + "\n" + [" = HELP | EXIT | LOAD | LIST | MC | MCP | F | ST" + "HELP = 'help' | 'h'" + "EXIT = 'exit' | 'quit' | 'q'" + "LOAD = 'load' STR" + "LIST = 'list'" + "MC = ('mc'|'many-constructors') 'th' NUM" + "MCP = ('mcp'|'many-costructor-params') 'th' NUM" + "F = ('f'|'finalizers')" + "ST = ('st'|'singletons')" + "WS = #'[\t ]+'" + "NUM = #'[0-9]+'" + "STR = #'\"[^\"]*\"'"])) (def command-parser (insta/parser commands-grammar)) @@ -34,15 +35,16 @@ "No classes loaded. Use first") (def help-message - (str - "h/help : print this help message \n" - "q/quit/exit : close the shell \n" - "list : list classes loaded \n" - "load DIR : load classes from DIR \n" - "mc/many-constructors th NUM : list classes with NUM or more constructors \n" - "mcp/many-constructor-params th NUM : list constructors with NUM or more parameters \n" - "f/finalizers : list classes that use finalizers \n" - "st/singletons : list singletons")) + (clojure.string/join + "\n" + ["h/help : print this help message" + "q/quit/exit : close the shell" + "list : list classes loaded" + "load DIR : load classes from DIR" + "mc/many-constructors th NUM : list classes with NUM or more constructors" + "mcp/many-constructor-params th NUM : list constructors with NUM or more parameters" + "f/finalizers : list classes that use finalizers" + "st/singletons : list singletons"])) (declare interactive) From eb60d06213643d56185bb2a1586bd7ffb23cf788 Mon Sep 17 00:00:00 2001 From: David Ortiz Date: Sat, 16 May 2015 13:49:36 +0200 Subject: [PATCH 08/42] Change indentation in interactive tests to make cljfmt happy --- test/app/test/interactive.clj | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/app/test/interactive.clj b/test/app/test/interactive.clj index 7316589..f3d5003 100644 --- a/test/app/test/interactive.clj +++ b/test/app/test/interactive.clj @@ -53,7 +53,7 @@ (interactive javaparser-cus) (verify-call-times-for printOperation 1) (verify-first-call-args-for - printOperation - classesWithManyConstructorsOp - (:cus javaparser-cus) - mc-op-threshold))))) + printOperation + classesWithManyConstructorsOp + (:cus javaparser-cus) + mc-op-threshold))))) From 119dca6dfbd528777d635e29be7934ee01f21cfe Mon Sep 17 00:00:00 2001 From: David Ortiz Date: Sat, 16 May 2015 14:07:20 +0200 Subject: [PATCH 09/42] Add clarifying comment in can-execute-mc-operation test --- test/app/test/interactive.clj | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/app/test/interactive.clj b/test/app/test/interactive.clj index f3d5003..8552feb 100644 --- a/test/app/test/interactive.clj +++ b/test/app/test/interactive.clj @@ -43,6 +43,9 @@ no-classes-loaded-error))))) (deftest can-execute-mc-operation + ;; In this test we want to check whether the printOperation function of the + ;; app.operations namespace is called with the correct parameters. + ;; For this reason, we can use any compilation units and any threshold. (let [javaparser-cus {:cus (take 2 (cus javaparser-cus-path))} mc-op-threshold 3 command-sequence [(str "mc th " mc-op-threshold) "quit"] From a2977131203093a6e24f73ec964b8a28b5e51e6d Mon Sep 17 00:00:00 2001 From: Federico Tomassetti Date: Mon, 18 May 2015 17:21:41 +0100 Subject: [PATCH 10/42] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c03b38c..809e9d1 100644 --- a/README.md +++ b/README.md @@ -126,4 +126,4 @@ Hope you enjoy this small project of mine. Feel free to open issues and ask ques Contributors ============ -Thanks to [David Ortiz](https://github.com/davidor) who fixed bugs, set up Travis and it is contributing many other improvements. +[David Ortiz](https://github.com/davidor) is a regular contributor: he started fixing bugs, setting up Travis and it is contributing many other improvements. From fcfac62dcd065c8ea93e0bb79de6fe62694d368e Mon Sep 17 00:00:00 2001 From: David Ortiz Date: Mon, 18 May 2015 20:05:22 +0200 Subject: [PATCH 11/42] Add test for mcp op in interactive mode --- test/app/test/interactive.clj | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/app/test/interactive.clj b/test/app/test/interactive.clj index 8552feb..7456806 100644 --- a/test/app/test/interactive.clj +++ b/test/app/test/interactive.clj @@ -60,3 +60,19 @@ classesWithManyConstructorsOp (:cus javaparser-cus) mc-op-threshold))))) + +(deftest can-execute-mcp-operation + (let [javaparser-cus {:cus (take 2 (cus javaparser-cus-path))} + mcp-op-threshold 3 + command-sequence [(str "mcp th " mcp-op-threshold) "quit"] + input-string (command-sequence->input-str command-sequence)] + (with-in-str + input-string + (mocking [println print flush printOperation] + (interactive javaparser-cus) + (verify-call-times-for printOperation 1) + (verify-first-call-args-for + printOperation + constructorsWithManyParametersOp + (:cus javaparser-cus) + mcp-op-threshold))))) From 410e8bdd95c5240b4bda6a9436dcd4ea26d8cc9b Mon Sep 17 00:00:00 2001 From: David Ortiz Date: Mon, 18 May 2015 20:15:32 +0200 Subject: [PATCH 12/42] Add test for st op in interactive mode --- test/app/test/interactive.clj | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/test/app/test/interactive.clj b/test/app/test/interactive.clj index 7456806..b92ce4a 100644 --- a/test/app/test/interactive.clj +++ b/test/app/test/interactive.clj @@ -76,3 +76,18 @@ constructorsWithManyParametersOp (:cus javaparser-cus) mcp-op-threshold))))) + +(deftest can-execute-st-operation + (let [javaparser-cus {:cus (take 2 (cus javaparser-cus-path))} + command-sequence ["st" "quit"] + input-string (command-sequence->input-str command-sequence)] + (with-in-str + input-string + (mocking [println print flush printOperation] + (interactive javaparser-cus) + (verify-call-times-for printOperation 1) + (verify-first-call-args-for + printOperation + classesAndSingletonTypeOp + (:cus javaparser-cus) + nil))))) From a0ad41714d193e7b638c4b4bc6c878ddd5e4b1da Mon Sep 17 00:00:00 2001 From: David Ortiz Date: Mon, 18 May 2015 20:25:23 +0200 Subject: [PATCH 13/42] Add test for f op in interactive mode --- test/app/test/interactive.clj | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/test/app/test/interactive.clj b/test/app/test/interactive.clj index b92ce4a..3aa00f4 100644 --- a/test/app/test/interactive.clj +++ b/test/app/test/interactive.clj @@ -91,3 +91,18 @@ classesAndSingletonTypeOp (:cus javaparser-cus) nil))))) + +(deftest can-execute-f-operation + (let [javaparser-cus {:cus (take 2 (cus javaparser-cus-path))} + command-sequence ["f" "quit"] + input-string (command-sequence->input-str command-sequence)] + (with-in-str + input-string + (mocking [println print flush printOperation] + (interactive javaparser-cus) + (verify-call-times-for printOperation 1) + (verify-first-call-args-for + printOperation + finalizersOp + (:cus javaparser-cus) + nil))))) From 5582bd70bb3b025776e4c85650d55321148edc28 Mon Sep 17 00:00:00 2001 From: David Ortiz Date: Mon, 18 May 2015 20:28:22 +0200 Subject: [PATCH 14/42] Rewrite clarifying comment in interactive mode tests --- test/app/test/interactive.clj | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/test/app/test/interactive.clj b/test/app/test/interactive.clj index 3aa00f4..c218e34 100644 --- a/test/app/test/interactive.clj +++ b/test/app/test/interactive.clj @@ -42,10 +42,15 @@ (verify-first-call-args-for println no-classes-loaded-error))))) + +;; The next four tests check that the operations that can +;; be used from the interactive mode (mc, mcp, etc.) work as expected. +;; We are interested in checking whether the printOperation function of the +;; app.operations namespace is called with the correct parameters. +;; For this reason, we can use any compilation units and any threshold (for +;; the operations that require one). + (deftest can-execute-mc-operation - ;; In this test we want to check whether the printOperation function of the - ;; app.operations namespace is called with the correct parameters. - ;; For this reason, we can use any compilation units and any threshold. (let [javaparser-cus {:cus (take 2 (cus javaparser-cus-path))} mc-op-threshold 3 command-sequence [(str "mc th " mc-op-threshold) "quit"] From e1e4701cd890c539ccad7f2efaaf0955af18f5b8 Mon Sep 17 00:00:00 2001 From: David Ortiz Date: Mon, 18 May 2015 20:30:53 +0200 Subject: [PATCH 15/42] Put exit message in a separated def for easier testing --- src/app/interactive.clj | 5 ++++- test/app/test/interactive.clj | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/app/interactive.clj b/src/app/interactive.clj index cb0035a..10b26cb 100644 --- a/src/app/interactive.clj +++ b/src/app/interactive.clj @@ -46,10 +46,13 @@ "f/finalizers : list classes that use finalizers" "st/singletons : list singletons"])) +(def exit-message + "Exit...") + (declare interactive) (defn- exit [] - (println "Exit...")) + (println exit-message)) (defn- list-loaded-classes [state] (let [loadedCus (:cus state)] diff --git a/test/app/test/interactive.clj b/test/app/test/interactive.clj index c218e34..ffebad5 100644 --- a/test/app/test/interactive.clj +++ b/test/app/test/interactive.clj @@ -19,7 +19,7 @@ (mocking [println print flush] (interactive []) (verify-call-times-for println 1) - (verify-first-call-args-for println "Exit..."))))) + (verify-first-call-args-for println exit-message))))) (deftest shows-help (let [command-sequence ["help" "quit"] From f83ebee85c59f82159ce8ad3b0150ae5234b0039 Mon Sep 17 00:00:00 2001 From: David Ortiz Date: Mon, 18 May 2015 20:48:02 +0200 Subject: [PATCH 16/42] Extract common code into separated function --- test/app/test/interactive.clj | 64 ++++++++--------------------------- 1 file changed, 15 insertions(+), 49 deletions(-) diff --git a/test/app/test/interactive.clj b/test/app/test/interactive.clj index ffebad5..85cdb11 100644 --- a/test/app/test/interactive.clj +++ b/test/app/test/interactive.clj @@ -50,10 +50,13 @@ ;; For this reason, we can use any compilation units and any threshold (for ;; the operations that require one). -(deftest can-execute-mc-operation +;; All the operations can be tested in the same way. +(defn- test-operation [op-command operation threshold] (let [javaparser-cus {:cus (take 2 (cus javaparser-cus-path))} - mc-op-threshold 3 - command-sequence [(str "mc th " mc-op-threshold) "quit"] + first-command (if threshold + (str op-command " th " threshold) + (str op-command)) + command-sequence [first-command "quit"] input-string (command-sequence->input-str command-sequence)] (with-in-str input-string @@ -61,53 +64,16 @@ (interactive javaparser-cus) (verify-call-times-for printOperation 1) (verify-first-call-args-for - printOperation - classesWithManyConstructorsOp - (:cus javaparser-cus) - mc-op-threshold))))) + printOperation operation (:cus javaparser-cus) threshold))))) -(deftest can-execute-mcp-operation - (let [javaparser-cus {:cus (take 2 (cus javaparser-cus-path))} - mcp-op-threshold 3 - command-sequence [(str "mcp th " mcp-op-threshold) "quit"] - input-string (command-sequence->input-str command-sequence)] - (with-in-str - input-string - (mocking [println print flush printOperation] - (interactive javaparser-cus) - (verify-call-times-for printOperation 1) - (verify-first-call-args-for - printOperation - constructorsWithManyParametersOp - (:cus javaparser-cus) - mcp-op-threshold))))) +(deftest can-execute-mc-operation + (test-operation "mc" classesWithManyConstructorsOp 2)) -(deftest can-execute-st-operation - (let [javaparser-cus {:cus (take 2 (cus javaparser-cus-path))} - command-sequence ["st" "quit"] - input-string (command-sequence->input-str command-sequence)] - (with-in-str - input-string - (mocking [println print flush printOperation] - (interactive javaparser-cus) - (verify-call-times-for printOperation 1) - (verify-first-call-args-for - printOperation - classesAndSingletonTypeOp - (:cus javaparser-cus) - nil))))) +(deftest can-execute-mcp-operation + (test-operation "mcp" constructorsWithManyParametersOp 3)) (deftest can-execute-f-operation - (let [javaparser-cus {:cus (take 2 (cus javaparser-cus-path))} - command-sequence ["f" "quit"] - input-string (command-sequence->input-str command-sequence)] - (with-in-str - input-string - (mocking [println print flush printOperation] - (interactive javaparser-cus) - (verify-call-times-for printOperation 1) - (verify-first-call-args-for - printOperation - finalizersOp - (:cus javaparser-cus) - nil))))) + (test-operation "f" finalizersOp nil)) + +(deftest can-execute-st-operation + (test-operation "st" classesAndSingletonTypeOp nil)) From 40340a79efaf12688abe0839987e55a10f008a25 Mon Sep 17 00:00:00 2001 From: David Ortiz Date: Mon, 18 May 2015 20:57:01 +0200 Subject: [PATCH 17/42] Use optional param in test-operation fn --- test/app/test/interactive.clj | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/app/test/interactive.clj b/test/app/test/interactive.clj index 85cdb11..8f7f0df 100644 --- a/test/app/test/interactive.clj +++ b/test/app/test/interactive.clj @@ -51,7 +51,7 @@ ;; the operations that require one). ;; All the operations can be tested in the same way. -(defn- test-operation [op-command operation threshold] +(defn- test-operation [op-command operation & [threshold]] (let [javaparser-cus {:cus (take 2 (cus javaparser-cus-path))} first-command (if threshold (str op-command " th " threshold) @@ -73,7 +73,7 @@ (test-operation "mcp" constructorsWithManyParametersOp 3)) (deftest can-execute-f-operation - (test-operation "f" finalizersOp nil)) + (test-operation "f" finalizersOp)) (deftest can-execute-st-operation - (test-operation "st" classesAndSingletonTypeOp nil)) + (test-operation "st" classesAndSingletonTypeOp)) From 69dbc73fe44be8aa4a1479723807f011093fbed7 Mon Sep 17 00:00:00 2001 From: David Ortiz Date: Mon, 18 May 2015 21:04:20 +0200 Subject: [PATCH 18/42] Fix format in interactive mode tests --- test/app/test/interactive.clj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/app/test/interactive.clj b/test/app/test/interactive.clj index 8f7f0df..785eb6a 100644 --- a/test/app/test/interactive.clj +++ b/test/app/test/interactive.clj @@ -64,7 +64,7 @@ (interactive javaparser-cus) (verify-call-times-for printOperation 1) (verify-first-call-args-for - printOperation operation (:cus javaparser-cus) threshold))))) + printOperation operation (:cus javaparser-cus) threshold))))) (deftest can-execute-mc-operation (test-operation "mc" classesWithManyConstructorsOp 2)) From e4383314b478cd9ef04a4aa09fa938a0e49ff53f Mon Sep 17 00:00:00 2001 From: David Ortiz Date: Mon, 18 May 2015 21:42:41 +0200 Subject: [PATCH 19/42] Add common function for all ops in interactive mode --- src/app/interactive.clj | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/src/app/interactive.clj b/src/app/interactive.clj index 10b26cb..1dfd1f6 100644 --- a/src/app/interactive.clj +++ b/src/app/interactive.clj @@ -49,6 +49,12 @@ (def exit-message "Exit...") +(def operation-commands + {:MC classesWithManyConstructorsOp + :MCP constructorsWithManyParametersOp + :F finalizersOp + :ST classesAndSingletonTypeOp}) + (declare interactive) (defn- exit [] @@ -77,26 +83,14 @@ (println "Java files loaded:" (count loadedCus)) (interactive {:cus loadedCus})))) -(defn- mc-operation [state threshold] - (printOperation classesWithManyConstructorsOp (:cus state) threshold) - (interactive state)) - -(defn- mcp-operation [state threshold] - (printOperation constructorsWithManyParametersOp (:cus state) threshold) - (interactive state)) - -(defn- f-operation [state] - (printOperation finalizersOp (:cus state) nil) - (interactive state)) - -(defn- st-operation [state] - (printOperation classesAndSingletonTypeOp (:cus state) nil) - (interactive state)) - (defn- command-not-implemented [command state] (println "Command not implemented: " command) (interactive state)) +(defn- operation [op-command state & [threshold]] + (printOperation (op-command operation-commands) (:cus state) threshold) + (interactive state)) + (defn- process [state input] (let [ast (command-parser input)] @@ -112,11 +106,11 @@ :HELP (show-help state) :LOAD (load-classes ast) :MC (let [threshold (read-string (last (last (first ast))))] - (mc-operation state threshold)) + (operation :MC state threshold)) :MCP (let [threshold (read-string (last (last (first ast))))] - (mcp-operation state threshold)) - :F (f-operation state) - :ST (st-operation state) + (operation :MCP state threshold)) + :F (operation :F state) + :ST (operation :ST state) (command-not-implemented command state)))))) (defn interactive [state] From cdd017b054ffea74acc628fe7949c2a955f2a220 Mon Sep 17 00:00:00 2001 From: Federico Tomassetti Date: Tue, 19 May 2015 10:03:41 +0100 Subject: [PATCH 20/42] move to javaparser 2.1.0 --- project.clj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project.clj b/project.clj index e5213a3..46816e9 100644 --- a/project.clj +++ b/project.clj @@ -1,7 +1,7 @@ (defproject effectivejava "0.2.0-SNAPSHOT" :description "A Java linter and a tool for running queries on your Java codebase" :dependencies [[org.clojure/clojure "1.6.0"] - [com.github.javaparser/javaparser-core "2.0.0"] + [com.github.javaparser/javaparser-core "2.1.0"] [org.clojure/tools.cli "0.3.1"] [instaparse "1.3.6"] [org.javassist/javassist "3.19.0-GA"] From af7b45207fa4a568ba464ccc234f3da948fc304c Mon Sep 17 00:00:00 2001 From: Federico Tomassetti Date: Tue, 26 May 2015 19:10:31 +0100 Subject: [PATCH 21/42] add solveSuperclass --- src/app/model/javaparser.clj | 6 ++++++ src/app/symbol_solver/funcs.clj | 7 ++++++- .../sample-codebases/samples/Superclasses.java | 13 +++++++++++++ test/app/test/symbol_solver/funcs_test.clj | 16 ++++++++++++++++ 4 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 test-resources/sample-codebases/samples/Superclasses.java diff --git a/src/app/model/javaparser.clj b/src/app/model/javaparser.clj index 46611ec..3274be4 100644 --- a/src/app/model/javaparser.clj +++ b/src/app/model/javaparser.clj @@ -1,4 +1,5 @@ (ns app.model.javaparser + (:import [clojure.lang Named]) (:use [app.utils]) (:use [app.model.protocols]) (:use [app.javaparser.parsing]) @@ -291,6 +292,11 @@ (getName [this] (getName (.getId (.variable this))))) +(extend-protocol Named + com.github.javaparser.ast.type.ClassOrInterfaceType + (getName [this] + (.getName this))) + ; ============================================ ; Accessing nodes ; ============================================ diff --git a/src/app/symbol_solver/funcs.clj b/src/app/symbol_solver/funcs.clj index 01ad709..9459edc 100644 --- a/src/app/symbol_solver/funcs.clj +++ b/src/app/symbol_solver/funcs.clj @@ -14,4 +14,9 @@ (defn solveImportStmt [importStmt] (let [name (importQName importStmt)] - (solveClass (getCu importStmt) nil name))) \ No newline at end of file + (solveClass (getCu importStmt) nil name))) + +(defn solveSuperclass [classDecl] + (let [superclass (first (.getExtends classDecl))] + (when superclass + (solveClass classDecl nil (getName superclass))))) \ No newline at end of file diff --git a/test-resources/sample-codebases/samples/Superclasses.java b/test-resources/sample-codebases/samples/Superclasses.java new file mode 100644 index 0000000..7e48a08 --- /dev/null +++ b/test-resources/sample-codebases/samples/Superclasses.java @@ -0,0 +1,13 @@ +package sample; + +class SC_C { + +} + +class SC_B extends SC_C { + +} + +public class SC_A extends SC_B { + +} \ No newline at end of file diff --git a/test/app/test/symbol_solver/funcs_test.clj b/test/app/test/symbol_solver/funcs_test.clj index dd33747..06b1df0 100644 --- a/test/app/test/symbol_solver/funcs_test.clj +++ b/test/app/test/symbol_solver/funcs_test.clj @@ -114,3 +114,19 @@ _ (assert importStmt) importedType (solveImportStmt importStmt)] (is importedType)))) + +; ============================================ +; solveSuperclass +; ============================================ + +(deftest testSolveSuperclassSimpleCase + (binding [typeSolver (typeSolverOnJar javaparser2)] + (let [scA (sampleClass "SC_A") + _ (assert scA) + scB (sampleClass "SC_B") + _ (assert scB) + scC (sampleClass "SC_C") + _ (assert scC)] + (is (= scB (solveSuperclass scA))) + (is (= scC (solveSuperclass scB))) + (is (nil? (solveSuperclass scC)))))) \ No newline at end of file From 276f81b4093eabc6c7bb226a2e17d25c4417aef5 Mon Sep 17 00:00:00 2001 From: Federico Tomassetti Date: Tue, 26 May 2015 19:32:40 +0100 Subject: [PATCH 22/42] add getAllSuperclasses --- src/app/symbol_solver/funcs.clj | 14 ++++++++++++-- test/app/test/symbol_solver/funcs_test.clj | 18 +++++++++++++++++- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/app/symbol_solver/funcs.clj b/src/app/symbol_solver/funcs.clj index 9459edc..fbd0dac 100644 --- a/src/app/symbol_solver/funcs.clj +++ b/src/app/symbol_solver/funcs.clj @@ -16,7 +16,17 @@ (let [name (importQName importStmt)] (solveClass (getCu importStmt) nil name))) -(defn solveSuperclass [classDecl] +(defn solveSuperclass + "Return the definition of the superclass if the class has a superclass and if can be solved" + [classDecl] (let [superclass (first (.getExtends classDecl))] (when superclass - (solveClass classDecl nil (getName superclass))))) \ No newline at end of file + (solveClass classDecl nil (getName superclass))))) + +(defn getAllSuperclasses + "Get all the superclasses of the given class declaration (recursively)" + [classDecl] + (let [directSuperclass (solveSuperclass classDecl)] + (if directSuperclass + (into [directSuperclass] (getAllSuperclasses directSuperclass)) + []))) \ No newline at end of file diff --git a/test/app/test/symbol_solver/funcs_test.clj b/test/app/test/symbol_solver/funcs_test.clj index 06b1df0..a3f363a 100644 --- a/test/app/test/symbol_solver/funcs_test.clj +++ b/test/app/test/symbol_solver/funcs_test.clj @@ -129,4 +129,20 @@ _ (assert scC)] (is (= scB (solveSuperclass scA))) (is (= scC (solveSuperclass scB))) - (is (nil? (solveSuperclass scC)))))) \ No newline at end of file + (is (nil? (solveSuperclass scC)))))) + +; ============================================ +; getAllSuperclasses +; ============================================ + +(deftest testGetAllSuperclasses + (binding [typeSolver (typeSolverOnJar javaparser2)] + (let [scA (sampleClass "SC_A") + _ (assert scA) + scB (sampleClass "SC_B") + _ (assert scB) + scC (sampleClass "SC_C") + _ (assert scC)] + (is (= [scB scC] (getAllSuperclasses scA))) + (is (= [scC] (getAllSuperclasses scB))) + (is (= [] (getAllSuperclasses scC)))))) \ No newline at end of file From 7a286e5d730df2aaf8c9c5f747d3ba0947a05912 Mon Sep 17 00:00:00 2001 From: David Ortiz Date: Wed, 3 Jun 2015 01:30:32 +0200 Subject: [PATCH 23/42] Add first version of item10 checks --- src/app/itemsOnLifecycle.clj | 35 +++++++++++++++++-- src/app/linter.clj | 4 ++- src/app/symbol_solver/scope.clj | 1 - src/app/symbol_solver/type_solver.clj | 1 - .../ClassThatDeclaresToStringWithParams.java | 19 ++++++++++ .../ClassThatDoesNotOverrideToString.java | 15 ++++++++ .../ClassThatOverridesToString.java | 22 ++++++++++++ .../ClassWhoseParentOverridesToString.java | 16 +++++++++ .../ParentClassThatOverridesToString.java | 22 ++++++++++++ test/app/test/core.clj | 27 ++++++++++++++ 10 files changed, 157 insertions(+), 5 deletions(-) create mode 100644 test-resources/sample-codebases/samples/test_item10/ClassThatDeclaresToStringWithParams.java create mode 100644 test-resources/sample-codebases/samples/test_item10/ClassThatDoesNotOverrideToString.java create mode 100644 test-resources/sample-codebases/samples/test_item10/ClassThatOverridesToString.java create mode 100644 test-resources/sample-codebases/samples/test_item10/ClassWhoseParentOverridesToString.java create mode 100644 test-resources/sample-codebases/samples/test_item10/ParentClassThatOverridesToString.java diff --git a/src/app/itemsOnLifecycle.clj b/src/app/itemsOnLifecycle.clj index 8512c4e..4b22293 100644 --- a/src/app/itemsOnLifecycle.clj +++ b/src/app/itemsOnLifecycle.clj @@ -4,6 +4,8 @@ (:use [app.operations]) (:use [app.utils]) (:use [app.javaparser.navigation]) + (:use [app.symbol_solver.funcs]) + (:use [app.symbol_solver.type_solver]) (:import [app.operations Operation])) ; ============================================ @@ -118,10 +120,10 @@ ; ITEM 4 ; ============================================ -(defn isUtilClass? +(defn isUtilClass? [cl] (let [ms (getMethods cl)] - (and + (and (pos? (count ms)) (every? isStatic? ms)))) @@ -190,3 +192,32 @@ classes-using-finalizers [] [:class])) + +; ============================================ +; ITEM 10 +; ============================================ + +(defn overrides-toString? [class] + (->> (getMethods class) + (filter #(= (getName %) "toString")) + (filter #(empty? (getParameters %))) + (count) + (= 1))) + +(defn hierarchy-overrides-toString? [type-solver-classes class] + (binding [typeSolver (typeSolverOnList type-solver-classes)] + (->> (conj (getAllSuperclasses class) class) + (some overrides-toString?) + (true?)))) + +(defn classes-that-do-not-override-toString [params] + (let [classes (flatten (map allClasses (:cus params)))] + (map #(vec (list % nil)) + (filter #(complement (hierarchy-overrides-toString? classes %)) + classes)))) + +(def toStringOp + (Operation. + classes-that-do-not-override-toString + [] + [:class])) diff --git a/src/app/linter.clj b/src/app/linter.clj index f08c35e..fada91c 100644 --- a/src/app/linter.clj +++ b/src/app/linter.clj @@ -27,7 +27,9 @@ (Check. utilsClassesOp {:onlyIncorrect true} "This is a utils class and it should have exactly one private constructor taking no params") (Check. finalizersOp {} - "This class calls finalize(). Finalizers are considered to be unpredictable and often dangerous.")]) + "This class calls finalize(). Finalizers are considered to be unpredictable and often dangerous.") + (Check. toStringOp {} + "This class and its superclasses do not override toString().")]) (defn replaceParamsInMessage [message result] (clojure.string/replace message "#1#" (toString (nth result 1)))) diff --git a/src/app/symbol_solver/scope.clj b/src/app/symbol_solver/scope.clj index d1236ef..77e858d 100644 --- a/src/app/symbol_solver/scope.clj +++ b/src/app/symbol_solver/scope.clj @@ -3,7 +3,6 @@ (:use [app.model.javaparser]) (:use [app.javaparser.navigation]) (:use [app.operations]) - (:use [app.itemsOnLifecycle]) (:use [app.utils]) (:use [app.symbol_solver.type_solver]) (:require [instaparse.core :as insta]) diff --git a/src/app/symbol_solver/type_solver.clj b/src/app/symbol_solver/type_solver.clj index 6ae6b6c..c38bb7a 100644 --- a/src/app/symbol_solver/type_solver.clj +++ b/src/app/symbol_solver/type_solver.clj @@ -2,7 +2,6 @@ (:use [app.model.protocols]) (:use [app.model.javaparser]) (:use [app.operations]) - (:use [app.itemsOnLifecycle]) (:use [app.jarloading]) (:use [app.utils]) (:require [instaparse.core :as insta]) diff --git a/test-resources/sample-codebases/samples/test_item10/ClassThatDeclaresToStringWithParams.java b/test-resources/sample-codebases/samples/test_item10/ClassThatDeclaresToStringWithParams.java new file mode 100644 index 0000000..3edf66f --- /dev/null +++ b/test-resources/sample-codebases/samples/test_item10/ClassThatDeclaresToStringWithParams.java @@ -0,0 +1,19 @@ +package app.test.samples; + +public class ClassThatDeclaresToStringWithParams { + + private final int a; + + public ClassThatDeclaresToStringWithParams(int a) { + this.a = a; + } + + public int getA() { + return a; + } + + public String toString(int b) { + return Integer.toString(b); + } + +} diff --git a/test-resources/sample-codebases/samples/test_item10/ClassThatDoesNotOverrideToString.java b/test-resources/sample-codebases/samples/test_item10/ClassThatDoesNotOverrideToString.java new file mode 100644 index 0000000..563000f --- /dev/null +++ b/test-resources/sample-codebases/samples/test_item10/ClassThatDoesNotOverrideToString.java @@ -0,0 +1,15 @@ +package app.test.samples; + +public class ClassThatDoesNotOverrideToString { + + private final int a; + + public ClassThatDoesNotOverrideToString(int a) { + this.a = a; + } + + public int getA() { + return a; + } + +} diff --git a/test-resources/sample-codebases/samples/test_item10/ClassThatOverridesToString.java b/test-resources/sample-codebases/samples/test_item10/ClassThatOverridesToString.java new file mode 100644 index 0000000..af5676e --- /dev/null +++ b/test-resources/sample-codebases/samples/test_item10/ClassThatOverridesToString.java @@ -0,0 +1,22 @@ +package app.test.samples; + +public class ClassThatOverridesToString { + + private final int a; + + public ClassThatOverridesToString(int a) { + this.a = a; + } + + public int getA() { + return a; + } + + @Override + public String toString() { + return "app.test.samples.ClassThatOverridesToString{" + + "a=" + a + + '}'; + } + +} diff --git a/test-resources/sample-codebases/samples/test_item10/ClassWhoseParentOverridesToString.java b/test-resources/sample-codebases/samples/test_item10/ClassWhoseParentOverridesToString.java new file mode 100644 index 0000000..4d73446 --- /dev/null +++ b/test-resources/sample-codebases/samples/test_item10/ClassWhoseParentOverridesToString.java @@ -0,0 +1,16 @@ +package app.test.samples; + +public class ClassWhoseParentOverridesToString extends ParentClassThatOverridesToString { + + private final int a; + + public ClassWhoseParentOverridesToString (int a, int b) { + super(b); + this.a = a; + } + + public int getA() { + return a; + } + +} diff --git a/test-resources/sample-codebases/samples/test_item10/ParentClassThatOverridesToString.java b/test-resources/sample-codebases/samples/test_item10/ParentClassThatOverridesToString.java new file mode 100644 index 0000000..037e67a --- /dev/null +++ b/test-resources/sample-codebases/samples/test_item10/ParentClassThatOverridesToString.java @@ -0,0 +1,22 @@ +package app.test.samples; + +public class ParentClassThatOverridesToString { + + private final int b; + + public ParentClassThatOverridesToString(int b) { + this.b = b; + } + + public int getB() { + return b; + } + + @Override + public String toString() { + return "app.test.samples.ParentClassThatOverridesToString{" + + "b=" + b + + '}'; + } + +} diff --git a/test/app/test/core.clj b/test/app/test/core.clj index b4f5474..a8945d3 100644 --- a/test/app/test/core.clj +++ b/test/app/test/core.clj @@ -3,12 +3,15 @@ (:use [app.test.helper]) (:use [app.itemsOnLifecycle]) (:use [app.interactive]) + (:use [app.javaparser.navigation]) (:use [clojure.test]) (:use [conjure.core]) (:require [instaparse.core :as insta])) (load "helper") +(def sampleClassesItem10Test (cus "test-resources/sample-codebases/samples/test_item10")) + ; ============================================ ; usageError ; ============================================ @@ -148,6 +151,30 @@ (let [cl (parseType "ClassWithCallToFinalizeWithParams")] (is (false? (calls-finalizers? cl))))) +(deftest testClassThatOverridesToString + (let [type-solver-classes (flatten (map allTypes sampleClassesItem10Test)) + cl (first (filter #(= (.getName %) "ClassThatOverridesToString") + type-solver-classes))] + (is (hierarchy-overrides-toString? type-solver-classes cl)))) + +(deftest testClassWhoseParentsOverrideToString + (let [type-solver-classes (flatten (map allTypes sampleClassesItem10Test)) + cl (first (filter #(= (.getName %) "ClassWhoseParentOverridesToString") + type-solver-classes))] + (is (hierarchy-overrides-toString? type-solver-classes cl)))) + +(deftest testClassThatDeclaresToStringWithParams + (let [type-solver-classes (flatten (map allTypes sampleClassesItem10Test)) + cl (first (filter #(= (.getName %) "ClassThatDeclaresToStringWithParams") + type-solver-classes))] + (is (false? (hierarchy-overrides-toString? type-solver-classes cl))))) + +(deftest testClassThatDoesNotOverrideToString + (let [type-solver-classes (flatten (map allTypes sampleClassesItem10Test)) + cl (first (filter #(= (.getName %) "ClassThatDoesNotOverrideToString") + type-solver-classes))] + (is (false? (hierarchy-overrides-toString? type-solver-classes cl))))) + ; ============================================================= ; Command parser ; ============================================================= From 6053b2e4f57b3a7c11efa9e852e1c111c1a07371 Mon Sep 17 00:00:00 2001 From: Federico Tomassetti Date: Sat, 6 Jun 2015 11:06:52 +0100 Subject: [PATCH 24/42] when solving types use the fully qualified name --- src/app/symbol_solver/scope.clj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app/symbol_solver/scope.clj b/src/app/symbol_solver/scope.clj index 77e858d..e6f1151 100644 --- a/src/app/symbol_solver/scope.clj +++ b/src/app/symbol_solver/scope.clj @@ -93,8 +93,8 @@ (defn solveClassInPackage [pakage nameToSolve] {:pre [typeSolver]} - ; TODO first look into the package - (typeSolver nameToSolve)) + (let [qualified-name (if pakage (str (packageName pakage) "." nameToSolve) nameToSolve)] + (typeSolver qualified-name))) (defn solveAmongVariableDeclarator [nameToSolve variableDeclarator] From 818a459054d3a85e6f605d099132d06691aaa8a2 Mon Sep 17 00:00:00 2001 From: Federico Tomassetti Date: Sat, 6 Jun 2015 11:07:14 +0100 Subject: [PATCH 25/42] add tests for getAllSuperclasses --- test/app/test/core.clj | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/test/app/test/core.clj b/test/app/test/core.clj index a8945d3..f688213 100644 --- a/test/app/test/core.clj +++ b/test/app/test/core.clj @@ -6,6 +6,8 @@ (:use [app.javaparser.navigation]) (:use [clojure.test]) (:use [conjure.core]) + (:use [app.symbol_solver.funcs]) + (:use [app.symbol_solver.type_solver]) (:require [instaparse.core :as insta])) (load "helper") @@ -157,6 +159,22 @@ type-solver-classes))] (is (hierarchy-overrides-toString? type-solver-classes cl)))) +(deftest test-getAllSuperclasses-depth-0 + (let [type-solver-classes (flatten (map allTypes sampleClassesItem10Test)) + cl (first (filter #(= (.getName %) "ParentClassThatOverridesToString") type-solver-classes))] + (binding [typeSolver (typeSolverOnList type-solver-classes)] + (let [superclasses (getAllSuperclasses cl)] + (is (= 0 (count superclasses))))))) + + +(deftest test-getAllSuperclasses-depth-1 + (let [type-solver-classes (flatten (map allTypes sampleClassesItem10Test)) + cl (first (filter #(= (.getName %) "ClassWhoseParentOverridesToString") type-solver-classes))] + (binding [typeSolver (typeSolverOnList type-solver-classes)] + (let [superclasses (getAllSuperclasses cl)] + (is (= 1 (count superclasses))))))) + + (deftest testClassWhoseParentsOverrideToString (let [type-solver-classes (flatten (map allTypes sampleClassesItem10Test)) cl (first (filter #(= (.getName %) "ClassWhoseParentOverridesToString") From ca8a2f4252c80d91dbaef3cd1825e0be80c42de9 Mon Sep 17 00:00:00 2001 From: David Ortiz Date: Mon, 8 Jun 2015 20:47:47 +0200 Subject: [PATCH 26/42] Reorganize tests so all the ones that have to do with item10 are together --- test/app/test/core.clj | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/test/app/test/core.clj b/test/app/test/core.clj index f688213..9dd9576 100644 --- a/test/app/test/core.clj +++ b/test/app/test/core.clj @@ -159,22 +159,6 @@ type-solver-classes))] (is (hierarchy-overrides-toString? type-solver-classes cl)))) -(deftest test-getAllSuperclasses-depth-0 - (let [type-solver-classes (flatten (map allTypes sampleClassesItem10Test)) - cl (first (filter #(= (.getName %) "ParentClassThatOverridesToString") type-solver-classes))] - (binding [typeSolver (typeSolverOnList type-solver-classes)] - (let [superclasses (getAllSuperclasses cl)] - (is (= 0 (count superclasses))))))) - - -(deftest test-getAllSuperclasses-depth-1 - (let [type-solver-classes (flatten (map allTypes sampleClassesItem10Test)) - cl (first (filter #(= (.getName %) "ClassWhoseParentOverridesToString") type-solver-classes))] - (binding [typeSolver (typeSolverOnList type-solver-classes)] - (let [superclasses (getAllSuperclasses cl)] - (is (= 1 (count superclasses))))))) - - (deftest testClassWhoseParentsOverrideToString (let [type-solver-classes (flatten (map allTypes sampleClassesItem10Test)) cl (first (filter #(= (.getName %) "ClassWhoseParentOverridesToString") @@ -193,6 +177,21 @@ type-solver-classes))] (is (false? (hierarchy-overrides-toString? type-solver-classes cl))))) +(deftest test-getAllSuperclasses-depth-0 + (let [type-solver-classes (flatten (map allTypes sampleClassesItem10Test)) + cl (first (filter #(= (.getName %) "ParentClassThatOverridesToString") type-solver-classes))] + (binding [typeSolver (typeSolverOnList type-solver-classes)] + (let [superclasses (getAllSuperclasses cl)] + (is (= 0 (count superclasses))))))) + + +(deftest test-getAllSuperclasses-depth-1 + (let [type-solver-classes (flatten (map allTypes sampleClassesItem10Test)) + cl (first (filter #(= (.getName %) "ClassWhoseParentOverridesToString") type-solver-classes))] + (binding [typeSolver (typeSolverOnList type-solver-classes)] + (let [superclasses (getAllSuperclasses cl)] + (is (= 1 (count superclasses))))))) + ; ============================================================= ; Command parser ; ============================================================= From 8798789a79dfd85b4ff803f688b9c06d4c26214f Mon Sep 17 00:00:00 2001 From: David Ortiz Date: Tue, 9 Jun 2015 00:14:02 +0200 Subject: [PATCH 27/42] Add example utils class that does not override toString --- .../test_item10/UtilsClassDoesNotOverrideToString.java | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 test-resources/sample-codebases/samples/test_item10/UtilsClassDoesNotOverrideToString.java diff --git a/test-resources/sample-codebases/samples/test_item10/UtilsClassDoesNotOverrideToString.java b/test-resources/sample-codebases/samples/test_item10/UtilsClassDoesNotOverrideToString.java new file mode 100644 index 0000000..35d9a30 --- /dev/null +++ b/test-resources/sample-codebases/samples/test_item10/UtilsClassDoesNotOverrideToString.java @@ -0,0 +1,9 @@ +package app.test.samples; + +public class UtilsClassDoesNotOverrideToString { + + public static int performSomeOperation(int a) { + return a + 5; + } + +} \ No newline at end of file From ec3a8b81992093e6a1528d29c764ee59e56114cb Mon Sep 17 00:00:00 2001 From: David Ortiz Date: Tue, 9 Jun 2015 00:14:31 +0200 Subject: [PATCH 28/42] Take into account util classes when performing checks for item10 --- src/app/itemsOnLifecycle.clj | 24 +++++++++++++++++------- test/app/test/core.clj | 31 +++++++++++++++++++++---------- 2 files changed, 38 insertions(+), 17 deletions(-) diff --git a/src/app/itemsOnLifecycle.clj b/src/app/itemsOnLifecycle.clj index 4b22293..cf6a060 100644 --- a/src/app/itemsOnLifecycle.clj +++ b/src/app/itemsOnLifecycle.clj @@ -197,27 +197,37 @@ ; ITEM 10 ; ============================================ -(defn overrides-toString? [class] +(defn- overrides-toString? [class] (->> (getMethods class) (filter #(= (getName %) "toString")) (filter #(empty? (getParameters %))) (count) (= 1))) -(defn hierarchy-overrides-toString? [type-solver-classes class] +(defn- hierarchy-overrides-toString? [type-solver-classes class] (binding [typeSolver (typeSolverOnList type-solver-classes)] (->> (conj (getAllSuperclasses class) class) (some overrides-toString?) (true?)))) -(defn classes-that-do-not-override-toString [params] +(defn does-not-override-toString-but-should? [classes class] + (and (not (hierarchy-overrides-toString? classes class)) + (not (isUtilClass? class)))) + +(defn classes-that-do-not-override-toString-but-should + "Item10 of Effective Java recommends that all classes should override + toString or one of its parents in the class hierarchy should. There is + one exception: util classes, because they do not have any parameters. + This method returns all the classes that are not util classes and that + do not override toString (and neither do their parent classes)." + [params] (let [classes (flatten (map allClasses (:cus params)))] (map #(vec (list % nil)) - (filter #(complement (hierarchy-overrides-toString? classes %)) + (filter #(does-not-override-toString-but-should? classes %) classes)))) (def toStringOp (Operation. - classes-that-do-not-override-toString - [] - [:class])) + classes-that-do-not-override-toString-but-should + [] + [:class])) diff --git a/test/app/test/core.clj b/test/app/test/core.clj index 9dd9576..7c50d46 100644 --- a/test/app/test/core.clj +++ b/test/app/test/core.clj @@ -157,37 +157,48 @@ (let [type-solver-classes (flatten (map allTypes sampleClassesItem10Test)) cl (first (filter #(= (.getName %) "ClassThatOverridesToString") type-solver-classes))] - (is (hierarchy-overrides-toString? type-solver-classes cl)))) + (is (false? (does-not-override-toString-but-should? + type-solver-classes cl))))) (deftest testClassWhoseParentsOverrideToString (let [type-solver-classes (flatten (map allTypes sampleClassesItem10Test)) cl (first (filter #(= (.getName %) "ClassWhoseParentOverridesToString") type-solver-classes))] - (is (hierarchy-overrides-toString? type-solver-classes cl)))) + (is (false? (does-not-override-toString-but-should? + type-solver-classes cl))))) (deftest testClassThatDeclaresToStringWithParams (let [type-solver-classes (flatten (map allTypes sampleClassesItem10Test)) - cl (first (filter #(= (.getName %) "ClassThatDeclaresToStringWithParams") - type-solver-classes))] - (is (false? (hierarchy-overrides-toString? type-solver-classes cl))))) + cl (first (filter + #(= (.getName %) "ClassThatDeclaresToStringWithParams") + type-solver-classes))] + (is (does-not-override-toString-but-should? type-solver-classes cl)))) (deftest testClassThatDoesNotOverrideToString (let [type-solver-classes (flatten (map allTypes sampleClassesItem10Test)) cl (first (filter #(= (.getName %) "ClassThatDoesNotOverrideToString") type-solver-classes))] - (is (false? (hierarchy-overrides-toString? type-solver-classes cl))))) + (is (does-not-override-toString-but-should? type-solver-classes cl)))) + +(deftest testUtilClassThatDoesNotOverrideToString + (let [type-solver-classes (flatten (map allTypes sampleClassesItem10Test)) + cl (first (filter #(= (.getName %) "UtilsClassDoesNotOverrideToString") + type-solver-classes))] + (is (false? (does-not-override-toString-but-should? + type-solver-classes cl))))) (deftest test-getAllSuperclasses-depth-0 (let [type-solver-classes (flatten (map allTypes sampleClassesItem10Test)) - cl (first (filter #(= (.getName %) "ParentClassThatOverridesToString") type-solver-classes))] + cl (first (filter #(= (.getName %) "ParentClassThatOverridesToString") + type-solver-classes))] (binding [typeSolver (typeSolverOnList type-solver-classes)] (let [superclasses (getAllSuperclasses cl)] (is (= 0 (count superclasses))))))) - (deftest test-getAllSuperclasses-depth-1 (let [type-solver-classes (flatten (map allTypes sampleClassesItem10Test)) - cl (first (filter #(= (.getName %) "ClassWhoseParentOverridesToString") type-solver-classes))] + cl (first (filter #(= (.getName %) "ClassWhoseParentOverridesToString") + type-solver-classes))] (binding [typeSolver (typeSolverOnList type-solver-classes)] (let [superclasses (getAllSuperclasses cl)] (is (= 1 (count superclasses))))))) @@ -206,4 +217,4 @@ (is (= '([:EXIT "quit"]) (command-parser "quit")))) (deftest testParsingExit - (is (= '([:EXIT "exit"]) (command-parser "exit")))) + (is (= '([:EXIT "exit"]) (command-parser "exit")))) \ No newline at end of file From 1ae5813c6d89df0599203f9831974c50efd4ace7 Mon Sep 17 00:00:00 2001 From: David Ortiz Date: Tue, 9 Jun 2015 00:33:53 +0200 Subject: [PATCH 29/42] Add accidentally deleted EOF --- test/app/test/core.clj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/app/test/core.clj b/test/app/test/core.clj index 7c50d46..6afda45 100644 --- a/test/app/test/core.clj +++ b/test/app/test/core.clj @@ -217,4 +217,4 @@ (is (= '([:EXIT "quit"]) (command-parser "quit")))) (deftest testParsingExit - (is (= '([:EXIT "exit"]) (command-parser "exit")))) \ No newline at end of file + (is (= '([:EXIT "exit"]) (command-parser "exit")))) From 8f8ea9aa095e7b402536042d12c4adfae5432af4 Mon Sep 17 00:00:00 2001 From: David Ortiz Date: Tue, 9 Jun 2015 23:47:08 +0200 Subject: [PATCH 30/42] Fix typo --- src/app/itemsOnLifecycle.clj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/itemsOnLifecycle.clj b/src/app/itemsOnLifecycle.clj index cf6a060..8d5be13 100644 --- a/src/app/itemsOnLifecycle.clj +++ b/src/app/itemsOnLifecycle.clj @@ -215,7 +215,7 @@ (not (isUtilClass? class)))) (defn classes-that-do-not-override-toString-but-should - "Item10 of Effective Java recommends that all classes should override + "Item 10 of Effective Java recommends that all classes should override toString or one of its parents in the class hierarchy should. There is one exception: util classes, because they do not have any parameters. This method returns all the classes that are not util classes and that From 98e1737a298a13402422b53b7a3875f9ca9f6337 Mon Sep 17 00:00:00 2001 From: David Ortiz Date: Wed, 10 Jun 2015 00:01:34 +0200 Subject: [PATCH 31/42] Add some headers in core.clj tests --- test/app/test/core.clj | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/test/app/test/core.clj b/test/app/test/core.clj index 6afda45..a2b08a1 100644 --- a/test/app/test/core.clj +++ b/test/app/test/core.clj @@ -98,7 +98,7 @@ (verify-first-call-args-for exit-error!))) ; ============================================ -; Other FIXME organize! +; Item 3 - Singletons ; ============================================ (deftest testIsPublicFieldSingletonPositive @@ -137,6 +137,10 @@ (let [cl (parseType "NotSingletonEnum_NotOnlyInstance")] (is (not (isSingletonEnum? cl))))) +; ============================================ +; Item 7 - Avoid finalizers +; ============================================ + (deftest testClassCallsFinalizer (let [cl (parseType "ClassWithFinalizers")] (is (true? (calls-finalizers? cl))))) @@ -153,6 +157,10 @@ (let [cl (parseType "ClassWithCallToFinalizeWithParams")] (is (false? (calls-finalizers? cl))))) +; ============================================ +; Item 10 - Override toString() +; ============================================ + (deftest testClassThatOverridesToString (let [type-solver-classes (flatten (map allTypes sampleClassesItem10Test)) cl (first (filter #(= (.getName %) "ClassThatOverridesToString") @@ -187,6 +195,10 @@ (is (false? (does-not-override-toString-but-should? type-solver-classes cl))))) +; ============================================ +; Type solver gets superclasses correctly +; ============================================ + (deftest test-getAllSuperclasses-depth-0 (let [type-solver-classes (flatten (map allTypes sampleClassesItem10Test)) cl (first (filter #(= (.getName %) "ParentClassThatOverridesToString") @@ -203,9 +215,9 @@ (let [superclasses (getAllSuperclasses cl)] (is (= 1 (count superclasses))))))) -; ============================================================= +; ============================================ ; Command parser -; ============================================================= +; ============================================ (deftest testUnknown (is (insta/failure? (command-parser "a not valid command")))) From 6814c63516019430feb0a3488bff8af3ab317fcd Mon Sep 17 00:00:00 2001 From: David Ortiz Date: Wed, 10 Jun 2015 20:40:25 +0200 Subject: [PATCH 32/42] Add test abstract class for testing item 10 --- .../samples/test_item10/AbstractClassDoesNotOverrideToString.java | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 test-resources/sample-codebases/samples/test_item10/AbstractClassDoesNotOverrideToString.java diff --git a/test-resources/sample-codebases/samples/test_item10/AbstractClassDoesNotOverrideToString.java b/test-resources/sample-codebases/samples/test_item10/AbstractClassDoesNotOverrideToString.java new file mode 100644 index 0000000..e69de29 From 3230a7649b2b48a2ae0be5b375bf88e12d63115f Mon Sep 17 00:00:00 2001 From: David Ortiz Date: Wed, 10 Jun 2015 20:41:17 +0200 Subject: [PATCH 33/42] Add isAbstract? method to the Java parser --- src/app/model/javaparser.clj | 4 +++- src/app/model/protocols.clj | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/app/model/javaparser.clj b/src/app/model/javaparser.clj index 3274be4..0751f9b 100644 --- a/src/app/model/javaparser.clj +++ b/src/app/model/javaparser.clj @@ -140,7 +140,9 @@ (isStatic? [this] (ModifierSet/isStatic (.getModifiers this))) (isFinal? [this] - (ModifierSet/isFinal (.getModifiers this)))) + (ModifierSet/isFinal (.getModifiers this))) + (isAbstract? [this] + (ModifierSet/isAbstract (.getModifiers this)))) (extend-protocol WithModifiers ConstructorDeclaration diff --git a/src/app/model/protocols.clj b/src/app/model/protocols.clj index 4abe2a5..227c8b3 100644 --- a/src/app/model/protocols.clj +++ b/src/app/model/protocols.clj @@ -81,7 +81,8 @@ (isPublic? [this]) (isProtected? [this]) (isStatic? [this]) - (isFinal? [this])) + (isFinal? [this]) + (isAbstract? [this])) (defn hasPackageLevelAccess? [withModifiers] (not From 23f289db7ef0b7f9a1773153c6b1e84cbdc91d62 Mon Sep 17 00:00:00 2001 From: David Ortiz Date: Wed, 10 Jun 2015 20:46:45 +0200 Subject: [PATCH 34/42] Add test for item 10. Test abstract classes are ignored --- .../test_item10/AbstractClassDoesNotOverrideToString.java | 7 +++++++ test/app/test/core.clj | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/test-resources/sample-codebases/samples/test_item10/AbstractClassDoesNotOverrideToString.java b/test-resources/sample-codebases/samples/test_item10/AbstractClassDoesNotOverrideToString.java index e69de29..1d85b2f 100644 --- a/test-resources/sample-codebases/samples/test_item10/AbstractClassDoesNotOverrideToString.java +++ b/test-resources/sample-codebases/samples/test_item10/AbstractClassDoesNotOverrideToString.java @@ -0,0 +1,7 @@ +package app.test.samples; + +public abstract class AbstractClassDoesNotOverrideToString { + + abstract void aMethod(); + +} \ No newline at end of file diff --git a/test/app/test/core.clj b/test/app/test/core.clj index a2b08a1..a65e692 100644 --- a/test/app/test/core.clj +++ b/test/app/test/core.clj @@ -195,6 +195,13 @@ (is (false? (does-not-override-toString-but-should? type-solver-classes cl))))) +(deftest abstractClassDoesNotNeedToOverrideToString + (let [type-solver-classes (flatten (map allTypes sampleClassesItem10Test)) + cl (first (filter #(= (.getName %) "AbstractClassDoesNotOverrideToString") + type-solver-classes))] + (is (false? (does-not-override-toString-but-should? + type-solver-classes cl))))) + ; ============================================ ; Type solver gets superclasses correctly ; ============================================ From 423c497458e158f80bc297909d462cd22968e769 Mon Sep 17 00:00:00 2001 From: David Ortiz Date: Wed, 10 Jun 2015 20:51:16 +0200 Subject: [PATCH 35/42] Ignore abstract classes in item 10 checks --- src/app/itemsOnLifecycle.clj | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/app/itemsOnLifecycle.clj b/src/app/itemsOnLifecycle.clj index 8d5be13..72ef672 100644 --- a/src/app/itemsOnLifecycle.clj +++ b/src/app/itemsOnLifecycle.clj @@ -212,7 +212,8 @@ (defn does-not-override-toString-but-should? [classes class] (and (not (hierarchy-overrides-toString? classes class)) - (not (isUtilClass? class)))) + (not (isUtilClass? class)) + (not (isAbstract? class)))) (defn classes-that-do-not-override-toString-but-should "Item 10 of Effective Java recommends that all classes should override From 8b926a9af6ab2595fa282621100ee2c4f88a6c68 Mon Sep 17 00:00:00 2001 From: Federico Tomassetti Date: Fri, 12 Jun 2015 15:07:30 +0100 Subject: [PATCH 36/42] Update README.md --- README.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/README.md b/README.md index 809e9d1..7d3c15c 100644 --- a/README.md +++ b/README.md @@ -85,6 +85,23 @@ I am just getting started so I implemented only a few queries for now: * _st=singleton type_: find if a type implements the singleton pattern and distinguish between the three types (public field, static factory, singleton enum) * _u=utils classes_: find classes having only static methods and verify they have exactly one private constructor taking no parameters +Effective Java (the book) items implemented +=========================================== + +| Item | Status | +| ------ |---------| +| Item 1 | TODO | +| item 2 | TODO | +| item 3 | TODO | +| item 4 | Done | +| item 5 | TODO | +| item 6 | TODO | +| item 7 | Done | +| item 8 | Planned for v0.2 | +| item 9 | Planned for v0.2 | +| item 10 | Done | +| item 2 | TODO | + Dev info ======== The project is written in Clojure using a java library called [JavaParser](https://github.com/javaparser/javaparser). From c1e77bd4c216a63b254bee3164179f327c70b4ff Mon Sep 17 00:00:00 2001 From: Federico Tomassetti Date: Fri, 12 Jun 2015 15:10:23 +0100 Subject: [PATCH 37/42] Update README.md --- README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 7d3c15c..9f88ff7 100644 --- a/README.md +++ b/README.md @@ -90,9 +90,9 @@ Effective Java (the book) items implemented | Item | Status | | ------ |---------| -| Item 1 | TODO | +| Item 1 | Done | | item 2 | TODO | -| item 3 | TODO | +| item 3 | Done | | item 4 | Done | | item 5 | TODO | | item 6 | TODO | @@ -100,7 +100,8 @@ Effective Java (the book) items implemented | item 8 | Planned for v0.2 | | item 9 | Planned for v0.2 | | item 10 | Done | -| item 2 | TODO | +| item 11 | TODO | +| ...item 78 | TODO | Dev info ======== From e592589b8c863e4fd2d7e9b0858169173c2c368a Mon Sep 17 00:00:00 2001 From: David Ortiz Date: Tue, 16 Jun 2015 10:08:50 +0200 Subject: [PATCH 38/42] Support item 10 checkings in interactive mode --- src/app/interactive.clj | 10 +++++++--- test/app/test/interactive.clj | 3 +++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/app/interactive.clj b/src/app/interactive.clj index 1dfd1f6..0a99b21 100644 --- a/src/app/interactive.clj +++ b/src/app/interactive.clj @@ -15,7 +15,7 @@ (def commands-grammar (clojure.string/join "\n" - [" = HELP | EXIT | LOAD | LIST | MC | MCP | F | ST" + [" = HELP | EXIT | LOAD | LIST | MC | MCP | F | ST | TS" "HELP = 'help' | 'h'" "EXIT = 'exit' | 'quit' | 'q'" "LOAD = 'load' STR" @@ -24,6 +24,7 @@ "MCP = ('mcp'|'many-costructor-params') 'th' NUM" "F = ('f'|'finalizers')" "ST = ('st'|'singletons')" + "TS = ('ts'|'toString')" "WS = #'[\t ]+'" "NUM = #'[0-9]+'" "STR = #'\"[^\"]*\"'"])) @@ -44,7 +45,8 @@ "mc/many-constructors th NUM : list classes with NUM or more constructors" "mcp/many-constructor-params th NUM : list constructors with NUM or more parameters" "f/finalizers : list classes that use finalizers" - "st/singletons : list singletons"])) + "st/singletons : list singletons" + "ts/toString : list classes that do not override toString()"])) (def exit-message "Exit...") @@ -53,7 +55,8 @@ {:MC classesWithManyConstructorsOp :MCP constructorsWithManyParametersOp :F finalizersOp - :ST classesAndSingletonTypeOp}) + :ST classesAndSingletonTypeOp + :TS toStringOp}) (declare interactive) @@ -111,6 +114,7 @@ (operation :MCP state threshold)) :F (operation :F state) :ST (operation :ST state) + :TS (operation :TS state) (command-not-implemented command state)))))) (defn interactive [state] diff --git a/test/app/test/interactive.clj b/test/app/test/interactive.clj index 785eb6a..ca2b630 100644 --- a/test/app/test/interactive.clj +++ b/test/app/test/interactive.clj @@ -77,3 +77,6 @@ (deftest can-execute-st-operation (test-operation "st" classesAndSingletonTypeOp)) + +(deftest can-execute-ts-operation + (test-operation "ts" toStringOp)) From 7a5abb7ede4e705c888ab054660ce92bc7f8aa4f Mon Sep 17 00:00:00 2001 From: David Ortiz Date: Tue, 16 Jun 2015 10:38:18 +0200 Subject: [PATCH 39/42] Support item 10 checkings in query mode --- src/app/cli.clj | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/app/cli.clj b/src/app/cli.clj index 537343b..22ac2eb 100644 --- a/src/app/cli.clj +++ b/src/app/cli.clj @@ -16,7 +16,7 @@ ["-i" "--interactive" "launch interactive mode" :flag true :default false] ["-l" "--linter" "launch linter mode" :flag true :default false] ["-d" "--dir DIRNAME" "directory containing the code to check (default current dir)" :default "."] - ["-q" "--query QUERYNAME" "REQUIRED: Query to perform: mc=many constructors, mcp=many constructor parameters, st=singleton type, u=utils classes"] + ["-q" "--query QUERYNAME" "REQUIRED: Query to perform: mc=many constructors, mcp=many constructor parameters, st=singleton type, ts=overrides toString()?, u=utils classes"] ["-t" "--threshold VALUE" "Threshold to be used in the query" :default 0 :parse-fn #(Integer/parseInt %) :validate [#(>= % 0) "Must be a number equal or greater to 0"]]]) @@ -26,6 +26,7 @@ :mc classesWithManyConstructorsOp :mcp constructorsWithManyParametersOp :st classesAndSingletonTypeOp + :ts toStringOp :u utilsClassesOp}) (defn run [opts] From 6b9609d3e8bc0d7400bb9fab8bc9631d3d5a7689 Mon Sep 17 00:00:00 2001 From: Federico Tomassetti Date: Wed, 15 Jul 2015 14:08:54 +0200 Subject: [PATCH 40/42] rename package app to effectivejaca --- src/{app => effectivejava}/cli.clj | 16 +++++++------- src/{app => effectivejava}/core.clj | 8 +++---- src/{app => effectivejava}/find.clj | 20 ++++++++--------- src/{app => effectivejava}/interactive.clj | 16 +++++++------- .../itemsOnLifecycle.clj | 18 +++++++-------- src/{app => effectivejava}/jarloading.clj | 12 +++++----- .../javaparser/navigation.clj | 8 +++---- .../javaparser/parsing.clj | 6 ++--- src/{app => effectivejava}/linter.clj | 16 +++++++------- .../model/javaparser.clj | 10 ++++----- .../model/javassist.clj | 6 ++--- .../model/protocols.clj | 2 +- .../model/reflection.clj | 10 ++++----- src/{app => effectivejava}/operations.clj | 6 ++--- .../symbol_solver/funcs.clj | 12 +++++----- .../symbol_solver/scope.clj | 16 +++++++------- .../symbol_solver/type_solver.clj | 14 ++++++------ src/{app => effectivejava}/utils.clj | 2 +- .../AbstractClassDoesNotOverrideToString.java | 2 +- .../ClassThatDeclaresToStringWithParams.java | 2 +- .../ClassThatDoesNotOverrideToString.java | 2 +- .../ClassThatOverridesToString.java | 4 ++-- .../ClassWhoseParentOverridesToString.java | 2 +- .../ParentClassThatOverridesToString.java | 4 ++-- .../UtilsClassDoesNotOverrideToString.java | 2 +- test/app/test/symbol_solver/helper.clj | 18 --------------- .../test/acceptance.clj | 12 +++++----- test/{app => effectivejava}/test/cli.clj | 16 +++++++------- test/{app => effectivejava}/test/core.clj | 16 +++++++------- .../{app => effectivejava}/test/find_test.clj | 20 ++++++++--------- test/{app => effectivejava}/test/helper.clj | 8 +++---- .../test/interactive.clj | 12 +++++----- .../test/itemsOnLifecycle.clj | 16 +++++++------- .../test/jarloading.clj | 8 +++---- .../test/javaparser.clj | 14 ++++++------ .../test/javaparser/navigation_test.clj | 14 ++++++------ .../test/model/javaparser_test.clj | 12 +++++----- .../test/operations.clj | 12 +++++----- .../test/samples/ASimpleClass.java.txt | 0 .../samples/ASimpleClassInAPackage.java.txt | 0 .../test/samples/ASimpleEnum.java.txt | 0 .../test/samples/ASimpleInterface.java.txt | 0 .../test/samples/ASimplePackage.java.txt | 0 .../samples/ASimplePublicFinalClass.java.txt | 0 .../test/samples/AnnidatedTypes.java.txt | 0 ...ClassWithCallToFinalizeWithParams.java.txt | 0 .../ClassWithCommentedCallToFinalize.java.txt | 0 .../test/samples/ClassWithErrors.java.txt | 0 .../test/samples/ClassWithFinalizers.java.txt | 0 .../ClassWithPublicFieldSingleton.java.txt | 0 .../ClassWithPublicMethodSingleton.java.txt | 0 .../samples/ClassWithoutFinalizers.java.txt | 0 ...icFieldSingleton_NotNamedInstance.java.txt | 0 ...outPublicFieldSingleton_NotPublic.java.txt | 0 ...outPublicFieldSingleton_NotStatic.java.txt | 0 ...thodSingleton_NotNamedGetInstance.java.txt | 0 .../test/samples/LotOfTypes.java.txt | 0 .../NotSingletonEnum_NoInstance.java.txt | 0 .../NotSingletonEnum_NotOnlyInstance.java.txt | 0 .../test/samples/RefTypes.java.txt | 0 .../test/samples/SingletonEnum.java.txt | 0 .../test/samples/TypesToMatch.java.txt | 0 .../test/symbol_solver/funcs_test.clj | 20 ++++++++--------- .../test/symbol_solver/helper.clj | 18 +++++++++++++++ .../test/symbol_solver/scope_test.clj | 22 +++++++++---------- .../test/symbol_solver/type_solver_test.clj | 16 +++++++------- test/{app => effectivejava}/test/utils.clj | 4 ++-- 67 files changed, 237 insertions(+), 237 deletions(-) rename src/{app => effectivejava}/cli.clj (81%) rename src/{app => effectivejava}/core.clj (94%) rename src/{app => effectivejava}/find.clj (86%) rename src/{app => effectivejava}/interactive.clj (92%) rename src/{app => effectivejava}/itemsOnLifecycle.clj (94%) rename src/{app => effectivejava}/jarloading.clj (88%) rename src/{app => effectivejava}/javaparser/navigation.clj (97%) rename src/{app => effectivejava}/javaparser/parsing.clj (93%) rename src/{app => effectivejava}/linter.clj (84%) rename src/{app => effectivejava}/model/javaparser.clj (98%) rename src/{app => effectivejava}/model/javassist.clj (79%) rename src/{app => effectivejava}/model/protocols.clj (98%) rename src/{app => effectivejava}/model/reflection.clj (69%) rename src/{app => effectivejava}/operations.clj (97%) rename src/{app => effectivejava}/symbol_solver/funcs.clj (78%) rename src/{app => effectivejava}/symbol_solver/scope.clj (95%) rename src/{app => effectivejava}/symbol_solver/type_solver.clj (87%) rename src/{app => effectivejava}/utils.clj (97%) delete mode 100644 test/app/test/symbol_solver/helper.clj rename test/{app => effectivejava}/test/acceptance.clj (92%) rename test/{app => effectivejava}/test/cli.clj (93%) rename test/{app => effectivejava}/test/core.clj (96%) rename test/{app => effectivejava}/test/find_test.clj (89%) rename test/{app => effectivejava}/test/helper.clj (66%) rename test/{app => effectivejava}/test/interactive.clj (91%) rename test/{app => effectivejava}/test/itemsOnLifecycle.clj (60%) rename test/{app => effectivejava}/test/jarloading.clj (91%) rename test/{app => effectivejava}/test/javaparser.clj (90%) rename test/{app => effectivejava}/test/javaparser/navigation_test.clj (92%) rename test/{app => effectivejava}/test/model/javaparser_test.clj (92%) rename test/{app => effectivejava}/test/operations.clj (86%) rename test/{app => effectivejava}/test/samples/ASimpleClass.java.txt (100%) rename test/{app => effectivejava}/test/samples/ASimpleClassInAPackage.java.txt (100%) rename test/{app => effectivejava}/test/samples/ASimpleEnum.java.txt (100%) rename test/{app => effectivejava}/test/samples/ASimpleInterface.java.txt (100%) rename test/{app => effectivejava}/test/samples/ASimplePackage.java.txt (100%) rename test/{app => effectivejava}/test/samples/ASimplePublicFinalClass.java.txt (100%) rename test/{app => effectivejava}/test/samples/AnnidatedTypes.java.txt (100%) rename test/{app => effectivejava}/test/samples/ClassWithCallToFinalizeWithParams.java.txt (100%) rename test/{app => effectivejava}/test/samples/ClassWithCommentedCallToFinalize.java.txt (100%) rename test/{app => effectivejava}/test/samples/ClassWithErrors.java.txt (100%) rename test/{app => effectivejava}/test/samples/ClassWithFinalizers.java.txt (100%) rename test/{app => effectivejava}/test/samples/ClassWithPublicFieldSingleton.java.txt (100%) rename test/{app => effectivejava}/test/samples/ClassWithPublicMethodSingleton.java.txt (100%) rename test/{app => effectivejava}/test/samples/ClassWithoutFinalizers.java.txt (100%) rename test/{app => effectivejava}/test/samples/ClassWithoutPublicFieldSingleton_NotNamedInstance.java.txt (100%) rename test/{app => effectivejava}/test/samples/ClassWithoutPublicFieldSingleton_NotPublic.java.txt (100%) rename test/{app => effectivejava}/test/samples/ClassWithoutPublicFieldSingleton_NotStatic.java.txt (100%) rename test/{app => effectivejava}/test/samples/ClassWithoutPublicMethodSingleton_NotNamedGetInstance.java.txt (100%) rename test/{app => effectivejava}/test/samples/LotOfTypes.java.txt (100%) rename test/{app => effectivejava}/test/samples/NotSingletonEnum_NoInstance.java.txt (100%) rename test/{app => effectivejava}/test/samples/NotSingletonEnum_NotOnlyInstance.java.txt (100%) rename test/{app => effectivejava}/test/samples/RefTypes.java.txt (100%) rename test/{app => effectivejava}/test/samples/SingletonEnum.java.txt (100%) rename test/{app => effectivejava}/test/samples/TypesToMatch.java.txt (100%) rename test/{app => effectivejava}/test/symbol_solver/funcs_test.clj (92%) create mode 100644 test/effectivejava/test/symbol_solver/helper.clj rename test/{app => effectivejava}/test/symbol_solver/scope_test.clj (89%) rename test/{app => effectivejava}/test/symbol_solver/type_solver_test.clj (79%) rename test/{app => effectivejava}/test/utils.clj (84%) diff --git a/src/app/cli.clj b/src/effectivejava/cli.clj similarity index 81% rename from src/app/cli.clj rename to src/effectivejava/cli.clj index 22ac2eb..177da14 100644 --- a/src/app/cli.clj +++ b/src/effectivejava/cli.clj @@ -1,12 +1,12 @@ -(ns app.cli - (:use [app.model.protocols]) - (:use [app.model.javaparser]) - (:use [app.javaparser.navigation]) - (:use [app.operations]) - (:use [app.itemsOnLifecycle]) - (:use [app.utils]) +(ns effectivejava.cli + (:use [effectivejava.model.protocols]) + (:use [effectivejava.model.javaparser]) + (:use [effectivejava.javaparser.navigation]) + (:use [effectivejava.operations]) + (:use [effectivejava.itemsOnLifecycle]) + (:use [effectivejava.utils]) (:require [instaparse.core :as insta]) - (:import [app.operations Operation])) + (:import [effectivejava.operations Operation])) ; ============================================ ; CLI diff --git a/src/app/core.clj b/src/effectivejava/core.clj similarity index 94% rename from src/app/core.clj rename to src/effectivejava/core.clj index 71eca23..65db0c3 100644 --- a/src/app/core.clj +++ b/src/effectivejava/core.clj @@ -1,8 +1,8 @@ -(ns app.core +(ns effectivejava.core (:require [clojure.tools.cli :refer [parse-opts]]) - (:use [app.linter]) - (:use [app.interactive]) - (:use [app.cli]) + (:use [effectivejava.linter]) + (:use [effectivejava.interactive]) + (:use [effectivejava.cli]) (:gen-class :main true)) (def self-exclusive-modes-error diff --git a/src/app/find.clj b/src/effectivejava/find.clj similarity index 86% rename from src/app/find.clj rename to src/effectivejava/find.clj index 5f6fa43..ffec524 100644 --- a/src/app/find.clj +++ b/src/effectivejava/find.clj @@ -1,15 +1,15 @@ -(ns app.find ^{:author "Federico Tomassetti" +(ns effectivejava.find ^{:author "Federico Tomassetti" :doc "This namespace contains methods to find elements in a collection of compilation units"} - (:use [app.model.protocols]) - (:use [app.model.javaparser]) - (:use [app.javaparser.navigation]) - (:use [app.operations]) - (:use [app.itemsOnLifecycle]) - (:use [app.symbol_solver.type_solver]) - (:use [app.symbol_solver.scope]) - (:use [app.utils]) + (:use [effectivejava.model.protocols]) + (:use [effectivejava.model.javaparser]) + (:use [effectivejava.javaparser.navigation]) + (:use [effectivejava.operations]) + (:use [effectivejava.itemsOnLifecycle]) + (:use [effectivejava.symbol_solver.type_solver]) + (:use [effectivejava.symbol_solver.scope]) + (:use [effectivejava.utils]) (:require [instaparse.core :as insta]) - (:import [app.operations Operation])) + (:import [effectivejava.operations Operation])) (defn type-exact-match? [type-ref1 type-ref2] (and diff --git a/src/app/interactive.clj b/src/effectivejava/interactive.clj similarity index 92% rename from src/app/interactive.clj rename to src/effectivejava/interactive.clj index 0a99b21..9786a84 100644 --- a/src/app/interactive.clj +++ b/src/effectivejava/interactive.clj @@ -1,12 +1,12 @@ -(ns app.interactive - (:use [app.model.protocols] - [app.model.javaparser] - [app.javaparser.navigation] - [app.operations] - [app.itemsOnLifecycle] - [app.utils]) +(ns effectivejava.interactive + (:use [effectivejava.model.protocols] + [effectivejava.model.javaparser] + [effectivejava.javaparser.navigation] + [effectivejava.operations] + [effectivejava.itemsOnLifecycle] + [effectivejava.utils]) (:require [instaparse.core :as insta]) - (:import [app.operations Operation])) + (:import [effectivejava.operations Operation])) ; ============================================ ; Interactive mode diff --git a/src/app/itemsOnLifecycle.clj b/src/effectivejava/itemsOnLifecycle.clj similarity index 94% rename from src/app/itemsOnLifecycle.clj rename to src/effectivejava/itemsOnLifecycle.clj index 72ef672..09f45b8 100644 --- a/src/app/itemsOnLifecycle.clj +++ b/src/effectivejava/itemsOnLifecycle.clj @@ -1,12 +1,12 @@ -(ns app.itemsOnLifecycle - (:use [app.model.protocols]) - (:use [app.model.javaparser]) - (:use [app.operations]) - (:use [app.utils]) - (:use [app.javaparser.navigation]) - (:use [app.symbol_solver.funcs]) - (:use [app.symbol_solver.type_solver]) - (:import [app.operations Operation])) +(ns effectivejava.itemsOnLifecycle + (:use [effectivejava.model.protocols]) + (:use [effectivejava.model.javaparser]) + (:use [effectivejava.operations]) + (:use [effectivejava.utils]) + (:use [effectivejava.javaparser.navigation]) + (:use [effectivejava.symbol_solver.funcs]) + (:use [effectivejava.symbol_solver.type_solver]) + (:import [effectivejava.operations Operation])) ; ============================================ ; ITEM 1 diff --git a/src/app/jarloading.clj b/src/effectivejava/jarloading.clj similarity index 88% rename from src/app/jarloading.clj rename to src/effectivejava/jarloading.clj index af61470..7cffc5c 100644 --- a/src/app/jarloading.clj +++ b/src/effectivejava/jarloading.clj @@ -1,9 +1,9 @@ -(ns app.jarloading - (:use [app.model.protocols]) - (:use [app.model.javaparser]) - (:use [app.operations]) - (:use [app.utils]) - (:import [app.operations Operation])) +(ns effectivejava.jarloading + (:use [effectivejava.model.protocols]) + (:use [effectivejava.model.javaparser]) + (:use [effectivejava.operations]) + (:use [effectivejava.utils]) + (:import [effectivejava.operations Operation])) (import java.net.URLDecoder) (import java.util.jar.JarEntry) diff --git a/src/app/javaparser/navigation.clj b/src/effectivejava/javaparser/navigation.clj similarity index 97% rename from src/app/javaparser/navigation.clj rename to src/effectivejava/javaparser/navigation.clj index 3d72cdf..f164193 100644 --- a/src/app/javaparser/navigation.clj +++ b/src/effectivejava/javaparser/navigation.clj @@ -1,7 +1,7 @@ -(ns app.javaparser.navigation - (:use [app.utils]) - (:use [app.model.protocols]) - (:use [app.javaparser.parsing])) +(ns effectivejava.javaparser.navigation + (:use [effectivejava.utils]) + (:use [effectivejava.model.protocols]) + (:use [effectivejava.javaparser.parsing])) (import com.github.javaparser.JavaParser) (import com.github.javaparser.ast.CompilationUnit) diff --git a/src/app/javaparser/parsing.clj b/src/effectivejava/javaparser/parsing.clj similarity index 93% rename from src/app/javaparser/parsing.clj rename to src/effectivejava/javaparser/parsing.clj index b2eb371..6ece8c6 100644 --- a/src/app/javaparser/parsing.clj +++ b/src/effectivejava/javaparser/parsing.clj @@ -1,6 +1,6 @@ -(ns app.javaparser.parsing - (:use [app.utils]) - (:use [app.model.protocols])) +(ns effectivejava.javaparser.parsing + (:use [effectivejava.utils]) + (:use [effectivejava.model.protocols])) (import com.github.javaparser.JavaParser) (import com.github.javaparser.ast.CompilationUnit) diff --git a/src/app/linter.clj b/src/effectivejava/linter.clj similarity index 84% rename from src/app/linter.clj rename to src/effectivejava/linter.clj index fada91c..bcce1f2 100644 --- a/src/app/linter.clj +++ b/src/effectivejava/linter.clj @@ -1,12 +1,12 @@ -(ns app.linter - (:use [app.model.protocols]) - (:use [app.model.javaparser]) - (:use [app.javaparser.navigation]) - (:use [app.operations]) - (:use [app.itemsOnLifecycle]) - (:use [app.utils]) +(ns effectivejava.linter + (:use [effectivejava.model.protocols]) + (:use [effectivejava.model.javaparser]) + (:use [effectivejava.javaparser.navigation]) + (:use [effectivejava.operations]) + (:use [effectivejava.itemsOnLifecycle]) + (:use [effectivejava.utils]) (:require [instaparse.core :as insta]) - (:import [app.operations Operation])) + (:import [effectivejava.operations Operation])) ; ============================================ ; Linter diff --git a/src/app/model/javaparser.clj b/src/effectivejava/model/javaparser.clj similarity index 98% rename from src/app/model/javaparser.clj rename to src/effectivejava/model/javaparser.clj index 0751f9b..0f497e5 100644 --- a/src/app/model/javaparser.clj +++ b/src/effectivejava/model/javaparser.clj @@ -1,9 +1,9 @@ -(ns app.model.javaparser +(ns effectivejava.model.javaparser (:import [clojure.lang Named]) - (:use [app.utils]) - (:use [app.model.protocols]) - (:use [app.javaparser.parsing]) - (:use [app.javaparser.navigation])) + (:use [effectivejava.utils]) + (:use [effectivejava.model.protocols]) + (:use [effectivejava.javaparser.parsing]) + (:use [effectivejava.javaparser.navigation])) (import com.github.javaparser.JavaParser) (import com.github.javaparser.ast.CompilationUnit) diff --git a/src/app/model/javassist.clj b/src/effectivejava/model/javassist.clj similarity index 79% rename from src/app/model/javassist.clj rename to src/effectivejava/model/javassist.clj index be00c9d..a4765c4 100644 --- a/src/app/model/javassist.clj +++ b/src/effectivejava/model/javassist.clj @@ -1,6 +1,6 @@ -(ns app.model.javassist - (:use [app.utils]) - (:use [app.model.protocols])) +(ns effectivejava.model.javassist + (:use [effectivejava.utils]) + (:use [effectivejava.model.protocols])) ; ============================================ ; Naming diff --git a/src/app/model/protocols.clj b/src/effectivejava/model/protocols.clj similarity index 98% rename from src/app/model/protocols.clj rename to src/effectivejava/model/protocols.clj index 227c8b3..d1eac59 100644 --- a/src/app/model/protocols.clj +++ b/src/effectivejava/model/protocols.clj @@ -1,4 +1,4 @@ -(ns app.model.protocols) +(ns effectivejava.model.protocols) ; In the namespace we define the protocols describing Java elements. ; We will then implement these protocols both using Javaparser ASTs and Javassist elements obtained by diff --git a/src/app/model/reflection.clj b/src/effectivejava/model/reflection.clj similarity index 69% rename from src/app/model/reflection.clj rename to src/effectivejava/model/reflection.clj index dd04c3f..a4633bb 100644 --- a/src/app/model/reflection.clj +++ b/src/effectivejava/model/reflection.clj @@ -1,8 +1,8 @@ -(ns app.model.reflection - (:use [app.utils]) - (:use [app.model.protocols]) - (:use [app.javaparser.parsing]) - (:use [app.javaparser.navigation])) +(ns effectivejava.model.reflection + (:use [effectivejava.utils]) + (:use [effectivejava.model.protocols]) + (:use [effectivejava.javaparser.parsing]) + (:use [effectivejava.javaparser.navigation])) ; Needed only for system classes diff --git a/src/app/operations.clj b/src/effectivejava/operations.clj similarity index 97% rename from src/app/operations.clj rename to src/effectivejava/operations.clj index 19a3f3d..db20eb5 100644 --- a/src/app/operations.clj +++ b/src/effectivejava/operations.clj @@ -1,6 +1,6 @@ -(ns app.operations - (:use [app.model.protocols]) - (:use [app.model.javaparser])) +(ns effectivejava.operations + (:use [effectivejava.model.protocols]) + (:use [effectivejava.model.javaparser])) (import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration) (import com.github.javaparser.ast.body.ConstructorDeclaration) diff --git a/src/app/symbol_solver/funcs.clj b/src/effectivejava/symbol_solver/funcs.clj similarity index 78% rename from src/app/symbol_solver/funcs.clj rename to src/effectivejava/symbol_solver/funcs.clj index fbd0dac..17c36e9 100644 --- a/src/app/symbol_solver/funcs.clj +++ b/src/effectivejava/symbol_solver/funcs.clj @@ -1,9 +1,9 @@ -(ns app.symbol_solver.funcs - (:use [app.model.protocols]) - (:use [app.model.javaparser]) - (:use [app.javaparser.navigation]) - (:use [app.utils]) - (:use [app.symbol_solver.scope])) +(ns effectivejava.symbol_solver.funcs + (:use [effectivejava.model.protocols]) + (:use [effectivejava.model.javaparser]) + (:use [effectivejava.javaparser.navigation]) + (:use [effectivejava.utils]) + (:use [effectivejava.symbol_solver.scope])) (defn solveNameExpr "given an instance of com.github.javaparser.ast.expr.NameExpr returns the declaration it refers to, diff --git a/src/app/symbol_solver/scope.clj b/src/effectivejava/symbol_solver/scope.clj similarity index 95% rename from src/app/symbol_solver/scope.clj rename to src/effectivejava/symbol_solver/scope.clj index e6f1151..cceea5d 100644 --- a/src/app/symbol_solver/scope.clj +++ b/src/effectivejava/symbol_solver/scope.clj @@ -1,12 +1,12 @@ -(ns app.symbol_solver.scope - (:use [app.model.protocols]) - (:use [app.model.javaparser]) - (:use [app.javaparser.navigation]) - (:use [app.operations]) - (:use [app.utils]) - (:use [app.symbol_solver.type_solver]) +(ns effectivejava.symbol_solver.scope + (:use [effectivejava.model.protocols]) + (:use [effectivejava.model.javaparser]) + (:use [effectivejava.javaparser.navigation]) + (:use [effectivejava.operations]) + (:use [effectivejava.utils]) + (:use [effectivejava.symbol_solver.type_solver]) (:require [instaparse.core :as insta]) - (:import [app.operations Operation])) + (:import [effectivejava.operations Operation])) (import com.github.javaparser.JavaParser) (import com.github.javaparser.ast.CompilationUnit) diff --git a/src/app/symbol_solver/type_solver.clj b/src/effectivejava/symbol_solver/type_solver.clj similarity index 87% rename from src/app/symbol_solver/type_solver.clj rename to src/effectivejava/symbol_solver/type_solver.clj index c38bb7a..aa6cffe 100644 --- a/src/app/symbol_solver/type_solver.clj +++ b/src/effectivejava/symbol_solver/type_solver.clj @@ -1,11 +1,11 @@ -(ns app.symbol_solver.type_solver - (:use [app.model.protocols]) - (:use [app.model.javaparser]) - (:use [app.operations]) - (:use [app.jarloading]) - (:use [app.utils]) +(ns effectivejava.symbol_solver.type_solver + (:use [effectivejava.model.protocols]) + (:use [effectivejava.model.javaparser]) + (:use [effectivejava.operations]) + (:use [effectivejava.jarloading]) + (:use [effectivejava.utils]) (:require [instaparse.core :as insta]) - (:import [app.operations Operation])) + (:import [effectivejava.operations Operation])) ; A TypeSolver is a function which, given a name, return a TypeRef or nil (if not found) diff --git a/src/app/utils.clj b/src/effectivejava/utils.clj similarity index 97% rename from src/app/utils.clj rename to src/effectivejava/utils.clj index b282d7b..c7f07a7 100644 --- a/src/app/utils.clj +++ b/src/effectivejava/utils.clj @@ -1,4 +1,4 @@ -(ns app.utils) +(ns effectivejava.utils) (def not-nil? (complement nil?)) diff --git a/test-resources/sample-codebases/samples/test_item10/AbstractClassDoesNotOverrideToString.java b/test-resources/sample-codebases/samples/test_item10/AbstractClassDoesNotOverrideToString.java index 1d85b2f..10dd633 100644 --- a/test-resources/sample-codebases/samples/test_item10/AbstractClassDoesNotOverrideToString.java +++ b/test-resources/sample-codebases/samples/test_item10/AbstractClassDoesNotOverrideToString.java @@ -1,4 +1,4 @@ -package app.test.samples; +package effectivejava.test.samples; public abstract class AbstractClassDoesNotOverrideToString { diff --git a/test-resources/sample-codebases/samples/test_item10/ClassThatDeclaresToStringWithParams.java b/test-resources/sample-codebases/samples/test_item10/ClassThatDeclaresToStringWithParams.java index 3edf66f..be2c9f0 100644 --- a/test-resources/sample-codebases/samples/test_item10/ClassThatDeclaresToStringWithParams.java +++ b/test-resources/sample-codebases/samples/test_item10/ClassThatDeclaresToStringWithParams.java @@ -1,4 +1,4 @@ -package app.test.samples; +package effectivejava.test.samples; public class ClassThatDeclaresToStringWithParams { diff --git a/test-resources/sample-codebases/samples/test_item10/ClassThatDoesNotOverrideToString.java b/test-resources/sample-codebases/samples/test_item10/ClassThatDoesNotOverrideToString.java index 563000f..d912600 100644 --- a/test-resources/sample-codebases/samples/test_item10/ClassThatDoesNotOverrideToString.java +++ b/test-resources/sample-codebases/samples/test_item10/ClassThatDoesNotOverrideToString.java @@ -1,4 +1,4 @@ -package app.test.samples; +package effectivejava.test.samples; public class ClassThatDoesNotOverrideToString { diff --git a/test-resources/sample-codebases/samples/test_item10/ClassThatOverridesToString.java b/test-resources/sample-codebases/samples/test_item10/ClassThatOverridesToString.java index af5676e..c604560 100644 --- a/test-resources/sample-codebases/samples/test_item10/ClassThatOverridesToString.java +++ b/test-resources/sample-codebases/samples/test_item10/ClassThatOverridesToString.java @@ -1,4 +1,4 @@ -package app.test.samples; +package effectivejava.test.samples; public class ClassThatOverridesToString { @@ -14,7 +14,7 @@ public int getA() { @Override public String toString() { - return "app.test.samples.ClassThatOverridesToString{" + + return "effectivejava.test.samples.ClassThatOverridesToString{" + "a=" + a + '}'; } diff --git a/test-resources/sample-codebases/samples/test_item10/ClassWhoseParentOverridesToString.java b/test-resources/sample-codebases/samples/test_item10/ClassWhoseParentOverridesToString.java index 4d73446..2ca05f9 100644 --- a/test-resources/sample-codebases/samples/test_item10/ClassWhoseParentOverridesToString.java +++ b/test-resources/sample-codebases/samples/test_item10/ClassWhoseParentOverridesToString.java @@ -1,4 +1,4 @@ -package app.test.samples; +package effectivejava.test.samples; public class ClassWhoseParentOverridesToString extends ParentClassThatOverridesToString { diff --git a/test-resources/sample-codebases/samples/test_item10/ParentClassThatOverridesToString.java b/test-resources/sample-codebases/samples/test_item10/ParentClassThatOverridesToString.java index 037e67a..d1d28d2 100644 --- a/test-resources/sample-codebases/samples/test_item10/ParentClassThatOverridesToString.java +++ b/test-resources/sample-codebases/samples/test_item10/ParentClassThatOverridesToString.java @@ -1,4 +1,4 @@ -package app.test.samples; +package effectivejava.test.samples; public class ParentClassThatOverridesToString { @@ -14,7 +14,7 @@ public int getB() { @Override public String toString() { - return "app.test.samples.ParentClassThatOverridesToString{" + + return "effectivejava.test.samples.ParentClassThatOverridesToString{" + "b=" + b + '}'; } diff --git a/test-resources/sample-codebases/samples/test_item10/UtilsClassDoesNotOverrideToString.java b/test-resources/sample-codebases/samples/test_item10/UtilsClassDoesNotOverrideToString.java index 35d9a30..e816625 100644 --- a/test-resources/sample-codebases/samples/test_item10/UtilsClassDoesNotOverrideToString.java +++ b/test-resources/sample-codebases/samples/test_item10/UtilsClassDoesNotOverrideToString.java @@ -1,4 +1,4 @@ -package app.test.samples; +package effectivejava.test.samples; public class UtilsClassDoesNotOverrideToString { diff --git a/test/app/test/symbol_solver/helper.clj b/test/app/test/symbol_solver/helper.clj deleted file mode 100644 index 858ac3b..0000000 --- a/test/app/test/symbol_solver/helper.clj +++ /dev/null @@ -1,18 +0,0 @@ -(ns app.test.symbol_solver.helper - (:use [app.jarloading]) - (:use [app.model.protocols]) - (:use [app.model.javaparser]) - (:use [app.javaparser.navigation]) - (:use [app.symbol_solver.funcs]) - (:use [app.symbol_solver.type_solver]) - (:use [app.symbol_solver.scope]) - (:use [app.utils]) - (:use [clojure.test])) - -(def javaparser2 "test-resources/sample-jars/javaparser-core-2.0.0.jar") -(def samplesCus (cus "test-resources/sample-codebases/samples/")) -(def sampleClasses (flatten (map allTypes samplesCus))) - -(defn sampleClass [name] - {:post [%]} - (first (filter (fn [c] (= name (.getName c))) sampleClasses))) diff --git a/test/app/test/acceptance.clj b/test/effectivejava/test/acceptance.clj similarity index 92% rename from test/app/test/acceptance.clj rename to test/effectivejava/test/acceptance.clj index 5d533ee..70a08ed 100644 --- a/test/app/test/acceptance.clj +++ b/test/effectivejava/test/acceptance.clj @@ -1,9 +1,9 @@ -(ns app.test.acceptance - (:use [app.model.javaparser]) - (:use [app.operations]) - (:use [app.itemsOnLifecycle]) - (:use [app.javaparser.parsing]) - (:use [app.javaparser.navigation]) +(ns effectivejava.test.acceptance + (:use [effectivejava.model.javaparser]) + (:use [effectivejava.operations]) + (:use [effectivejava.itemsOnLifecycle]) + (:use [effectivejava.javaparser.parsing]) + (:use [effectivejava.javaparser.navigation]) (:use [clojure.test])) (def javaparserCus (cus "test-resources/sample-codebases/javaparser/")) diff --git a/test/app/test/cli.clj b/test/effectivejava/test/cli.clj similarity index 93% rename from test/app/test/cli.clj rename to test/effectivejava/test/cli.clj index 76d25fb..3a6f183 100644 --- a/test/app/test/cli.clj +++ b/test/effectivejava/test/cli.clj @@ -1,13 +1,13 @@ -(ns app.test.cli +(ns effectivejava.test.cli (:require [clojure.tools.cli :refer [parse-opts]]) (:use [conjure.core]) - (:use [app.cli]) - (:use [app.core]) - (:use [app.model.protocols]) - (:use [app.model.javaparser]) - (:use [app.itemsOnLifecycle]) - (:use [app.javaparser.navigation]) - (:use [app.operations]) + (:use [effectivejava.cli]) + (:use [effectivejava.core]) + (:use [effectivejava.model.protocols]) + (:use [effectivejava.model.javaparser]) + (:use [effectivejava.itemsOnLifecycle]) + (:use [effectivejava.javaparser.navigation]) + (:use [effectivejava.operations]) (:use [clojure.test])) (def javaparserCus (cus "test-resources/sample-codebases/javaparser/")) diff --git a/test/app/test/core.clj b/test/effectivejava/test/core.clj similarity index 96% rename from test/app/test/core.clj rename to test/effectivejava/test/core.clj index a65e692..d60ef47 100644 --- a/test/app/test/core.clj +++ b/test/effectivejava/test/core.clj @@ -1,13 +1,13 @@ -(ns app.test.core - (:use [app.core]) - (:use [app.test.helper]) - (:use [app.itemsOnLifecycle]) - (:use [app.interactive]) - (:use [app.javaparser.navigation]) +(ns effectivejava.test.core + (:use [effectivejava.core]) + (:use [effectivejava.test.helper]) + (:use [effectivejava.itemsOnLifecycle]) + (:use [effectivejava.interactive]) + (:use [effectivejava.javaparser.navigation]) (:use [clojure.test]) (:use [conjure.core]) - (:use [app.symbol_solver.funcs]) - (:use [app.symbol_solver.type_solver]) + (:use [effectivejava.symbol_solver.funcs]) + (:use [effectivejava.symbol_solver.type_solver]) (:require [instaparse.core :as insta])) (load "helper") diff --git a/test/app/test/find_test.clj b/test/effectivejava/test/find_test.clj similarity index 89% rename from test/app/test/find_test.clj rename to test/effectivejava/test/find_test.clj index daea5c3..23fad53 100644 --- a/test/app/test/find_test.clj +++ b/test/effectivejava/test/find_test.clj @@ -1,13 +1,13 @@ -(ns app.test.find_test - (:use [app.core]) - (:use [app.test.helper]) - (:use [app.find]) - (:use [app.model.protocols]) - (:use [app.model.javaparser]) - (:use [app.javaparser.parsing]) - (:use [app.javaparser.navigation]) - (:use [app.symbol_solver.type_solver]) - (:use [app.symbol_solver.scope]) +(ns effectivejava.test.find_test + (:use [effectivejava.core]) + (:use [effectivejava.test.helper]) + (:use [effectivejava.find]) + (:use [effectivejava.model.protocols]) + (:use [effectivejava.model.javaparser]) + (:use [effectivejava.javaparser.parsing]) + (:use [effectivejava.javaparser.navigation]) + (:use [effectivejava.symbol_solver.type_solver]) + (:use [effectivejava.symbol_solver.scope]) (:use [clojure.test]) (:use [conjure.core]) (:require [instaparse.core :as insta])) diff --git a/test/app/test/helper.clj b/test/effectivejava/test/helper.clj similarity index 66% rename from test/app/test/helper.clj rename to test/effectivejava/test/helper.clj index 919fd9b..1578e96 100644 --- a/test/app/test/helper.clj +++ b/test/effectivejava/test/helper.clj @@ -1,10 +1,10 @@ -(ns app.test.helper - (:use [app.model.javaparser]) +(ns effectivejava.test.helper + (:use [effectivejava.model.javaparser]) (:use [clojure.test]) - (:use [app.javaparser.parsing])) + (:use [effectivejava.javaparser.parsing])) (defn readResource [filename] - (let [resourceName (str "app/test/samples/" filename ".java.txt") + (let [resourceName (str "effectivejava/test/samples/" filename ".java.txt") code (slurp (clojure.java.io/resource resourceName))] code)) diff --git a/test/app/test/interactive.clj b/test/effectivejava/test/interactive.clj similarity index 91% rename from test/app/test/interactive.clj rename to test/effectivejava/test/interactive.clj index ca2b630..757c8b3 100644 --- a/test/app/test/interactive.clj +++ b/test/effectivejava/test/interactive.clj @@ -1,8 +1,8 @@ -(ns app.test.interactive - (:use [app.interactive] - [app.javaparser.navigation] - [app.operations] - [app.itemsOnLifecycle] +(ns effectivejava.test.interactive + (:use [effectivejava.interactive] + [effectivejava.javaparser.navigation] + [effectivejava.operations] + [effectivejava.itemsOnLifecycle] [conjure.core] [clojure.test])) @@ -46,7 +46,7 @@ ;; The next four tests check that the operations that can ;; be used from the interactive mode (mc, mcp, etc.) work as expected. ;; We are interested in checking whether the printOperation function of the -;; app.operations namespace is called with the correct parameters. +;; effectivejava.operations namespace is called with the correct parameters. ;; For this reason, we can use any compilation units and any threshold (for ;; the operations that require one). diff --git a/test/app/test/itemsOnLifecycle.clj b/test/effectivejava/test/itemsOnLifecycle.clj similarity index 60% rename from test/app/test/itemsOnLifecycle.clj rename to test/effectivejava/test/itemsOnLifecycle.clj index ebf996b..3f0ed5f 100644 --- a/test/app/test/itemsOnLifecycle.clj +++ b/test/effectivejava/test/itemsOnLifecycle.clj @@ -1,12 +1,12 @@ -(ns app.test.itemsOnLifecycle - (:use [app.core]) - (:use [app.operations]) - (:use [app.itemsOnLifecycle]) - (:use [app.model.protocols]) - (:use [app.model.javaparser]) - (:use [app.javaparser.navigation]) +(ns effectivejava.test.itemsOnLifecycle + (:use [effectivejava.core]) + (:use [effectivejava.operations]) + (:use [effectivejava.itemsOnLifecycle]) + (:use [effectivejava.model.protocols]) + (:use [effectivejava.model.javaparser]) + (:use [effectivejava.javaparser.navigation]) (:use [clojure.test]) - (:use [app.test.helper]) + (:use [effectivejava.test.helper]) (:require [instaparse.core :as insta])) (def javaparserCus (cus "test-resources/sample-codebases/javaparser/")) diff --git a/test/app/test/jarloading.clj b/test/effectivejava/test/jarloading.clj similarity index 91% rename from test/app/test/jarloading.clj rename to test/effectivejava/test/jarloading.clj index 442661e..cf0c59f 100644 --- a/test/app/test/jarloading.clj +++ b/test/effectivejava/test/jarloading.clj @@ -1,7 +1,7 @@ -(ns app.test.jarloading - (:use [app.jarloading]) - (:use [app.model.javaparser]) - (:use [app.javaparser.navigation]) +(ns effectivejava.test.jarloading + (:use [effectivejava.jarloading]) + (:use [effectivejava.model.javaparser]) + (:use [effectivejava.javaparser.navigation]) (:use [clojure.test])) (def javaparser2 "test-resources/sample-jars/javaparser-core-2.0.0.jar") diff --git a/test/app/test/javaparser.clj b/test/effectivejava/test/javaparser.clj similarity index 90% rename from test/app/test/javaparser.clj rename to test/effectivejava/test/javaparser.clj index 640d918..1464ee4 100644 --- a/test/app/test/javaparser.clj +++ b/test/effectivejava/test/javaparser.clj @@ -1,11 +1,11 @@ -(ns app.test.javaparser - (:use [app.core]) - (:use [app.itemsOnLifecycle]) - (:use [app.model.protocols]) - (:use [app.model.javaparser]) - (:use [app.javaparser.navigation]) +(ns effectivejava.test.javaparser + (:use [effectivejava.core]) + (:use [effectivejava.itemsOnLifecycle]) + (:use [effectivejava.model.protocols]) + (:use [effectivejava.model.javaparser]) + (:use [effectivejava.javaparser.navigation]) (:use [clojure.test]) - (:use [app.test.helper]) + (:use [effectivejava.test.helper]) (:require [instaparse.core :as insta])) (load "helper") diff --git a/test/app/test/javaparser/navigation_test.clj b/test/effectivejava/test/javaparser/navigation_test.clj similarity index 92% rename from test/app/test/javaparser/navigation_test.clj rename to test/effectivejava/test/javaparser/navigation_test.clj index fbce012..0ebf58f 100644 --- a/test/app/test/javaparser/navigation_test.clj +++ b/test/effectivejava/test/javaparser/navigation_test.clj @@ -1,10 +1,10 @@ -(ns app.test.javaparser.navigation_test - (:use [app.itemsOnLifecycle]) - (:use [app.model.protocols]) - (:use [app.model.javaparser]) - (:use [app.javaparser.navigation]) - (:use [app.javaparser.parsing]) - (:use [app.test.helper]) +(ns effectivejava.test.javaparser.navigation_test + (:use [effectivejava.itemsOnLifecycle]) + (:use [effectivejava.model.protocols]) + (:use [effectivejava.model.javaparser]) + (:use [effectivejava.javaparser.navigation]) + (:use [effectivejava.javaparser.parsing]) + (:use [effectivejava.test.helper]) (:use [clojure.test])) ; ============================================ diff --git a/test/app/test/model/javaparser_test.clj b/test/effectivejava/test/model/javaparser_test.clj similarity index 92% rename from test/app/test/model/javaparser_test.clj rename to test/effectivejava/test/model/javaparser_test.clj index 90a4ebb..b583a9f 100644 --- a/test/app/test/model/javaparser_test.clj +++ b/test/effectivejava/test/model/javaparser_test.clj @@ -1,9 +1,9 @@ -(ns app.test.model.javaparser_test - (:use [app.itemsOnLifecycle]) - (:use [app.model.protocols]) - (:use [app.model.javaparser]) - (:use [app.javaparser.navigation]) - (:use [app.test.helper]) +(ns effectivejava.test.model.javaparser_test + (:use [effectivejava.itemsOnLifecycle]) + (:use [effectivejava.model.protocols]) + (:use [effectivejava.model.javaparser]) + (:use [effectivejava.javaparser.navigation]) + (:use [effectivejava.test.helper]) (:use [clojure.test])) ; ============================================ diff --git a/test/app/test/operations.clj b/test/effectivejava/test/operations.clj similarity index 86% rename from test/app/test/operations.clj rename to test/effectivejava/test/operations.clj index 49c62c5..b62e79f 100644 --- a/test/app/test/operations.clj +++ b/test/effectivejava/test/operations.clj @@ -1,10 +1,10 @@ -(ns app.test.operations - (:use [app.core]) - (:use [app.operations]) - (:use [app.itemsOnLifecycle]) - (:use [app.model.javaparser]) +(ns effectivejava.test.operations + (:use [effectivejava.core]) + (:use [effectivejava.operations]) + (:use [effectivejava.itemsOnLifecycle]) + (:use [effectivejava.model.javaparser]) (:use [clojure.test]) - (:use [app.test.helper]) + (:use [effectivejava.test.helper]) (:require [instaparse.core :as insta])) (deftest testFormatValueNoCutOnStartNeeded diff --git a/test/app/test/samples/ASimpleClass.java.txt b/test/effectivejava/test/samples/ASimpleClass.java.txt similarity index 100% rename from test/app/test/samples/ASimpleClass.java.txt rename to test/effectivejava/test/samples/ASimpleClass.java.txt diff --git a/test/app/test/samples/ASimpleClassInAPackage.java.txt b/test/effectivejava/test/samples/ASimpleClassInAPackage.java.txt similarity index 100% rename from test/app/test/samples/ASimpleClassInAPackage.java.txt rename to test/effectivejava/test/samples/ASimpleClassInAPackage.java.txt diff --git a/test/app/test/samples/ASimpleEnum.java.txt b/test/effectivejava/test/samples/ASimpleEnum.java.txt similarity index 100% rename from test/app/test/samples/ASimpleEnum.java.txt rename to test/effectivejava/test/samples/ASimpleEnum.java.txt diff --git a/test/app/test/samples/ASimpleInterface.java.txt b/test/effectivejava/test/samples/ASimpleInterface.java.txt similarity index 100% rename from test/app/test/samples/ASimpleInterface.java.txt rename to test/effectivejava/test/samples/ASimpleInterface.java.txt diff --git a/test/app/test/samples/ASimplePackage.java.txt b/test/effectivejava/test/samples/ASimplePackage.java.txt similarity index 100% rename from test/app/test/samples/ASimplePackage.java.txt rename to test/effectivejava/test/samples/ASimplePackage.java.txt diff --git a/test/app/test/samples/ASimplePublicFinalClass.java.txt b/test/effectivejava/test/samples/ASimplePublicFinalClass.java.txt similarity index 100% rename from test/app/test/samples/ASimplePublicFinalClass.java.txt rename to test/effectivejava/test/samples/ASimplePublicFinalClass.java.txt diff --git a/test/app/test/samples/AnnidatedTypes.java.txt b/test/effectivejava/test/samples/AnnidatedTypes.java.txt similarity index 100% rename from test/app/test/samples/AnnidatedTypes.java.txt rename to test/effectivejava/test/samples/AnnidatedTypes.java.txt diff --git a/test/app/test/samples/ClassWithCallToFinalizeWithParams.java.txt b/test/effectivejava/test/samples/ClassWithCallToFinalizeWithParams.java.txt similarity index 100% rename from test/app/test/samples/ClassWithCallToFinalizeWithParams.java.txt rename to test/effectivejava/test/samples/ClassWithCallToFinalizeWithParams.java.txt diff --git a/test/app/test/samples/ClassWithCommentedCallToFinalize.java.txt b/test/effectivejava/test/samples/ClassWithCommentedCallToFinalize.java.txt similarity index 100% rename from test/app/test/samples/ClassWithCommentedCallToFinalize.java.txt rename to test/effectivejava/test/samples/ClassWithCommentedCallToFinalize.java.txt diff --git a/test/app/test/samples/ClassWithErrors.java.txt b/test/effectivejava/test/samples/ClassWithErrors.java.txt similarity index 100% rename from test/app/test/samples/ClassWithErrors.java.txt rename to test/effectivejava/test/samples/ClassWithErrors.java.txt diff --git a/test/app/test/samples/ClassWithFinalizers.java.txt b/test/effectivejava/test/samples/ClassWithFinalizers.java.txt similarity index 100% rename from test/app/test/samples/ClassWithFinalizers.java.txt rename to test/effectivejava/test/samples/ClassWithFinalizers.java.txt diff --git a/test/app/test/samples/ClassWithPublicFieldSingleton.java.txt b/test/effectivejava/test/samples/ClassWithPublicFieldSingleton.java.txt similarity index 100% rename from test/app/test/samples/ClassWithPublicFieldSingleton.java.txt rename to test/effectivejava/test/samples/ClassWithPublicFieldSingleton.java.txt diff --git a/test/app/test/samples/ClassWithPublicMethodSingleton.java.txt b/test/effectivejava/test/samples/ClassWithPublicMethodSingleton.java.txt similarity index 100% rename from test/app/test/samples/ClassWithPublicMethodSingleton.java.txt rename to test/effectivejava/test/samples/ClassWithPublicMethodSingleton.java.txt diff --git a/test/app/test/samples/ClassWithoutFinalizers.java.txt b/test/effectivejava/test/samples/ClassWithoutFinalizers.java.txt similarity index 100% rename from test/app/test/samples/ClassWithoutFinalizers.java.txt rename to test/effectivejava/test/samples/ClassWithoutFinalizers.java.txt diff --git a/test/app/test/samples/ClassWithoutPublicFieldSingleton_NotNamedInstance.java.txt b/test/effectivejava/test/samples/ClassWithoutPublicFieldSingleton_NotNamedInstance.java.txt similarity index 100% rename from test/app/test/samples/ClassWithoutPublicFieldSingleton_NotNamedInstance.java.txt rename to test/effectivejava/test/samples/ClassWithoutPublicFieldSingleton_NotNamedInstance.java.txt diff --git a/test/app/test/samples/ClassWithoutPublicFieldSingleton_NotPublic.java.txt b/test/effectivejava/test/samples/ClassWithoutPublicFieldSingleton_NotPublic.java.txt similarity index 100% rename from test/app/test/samples/ClassWithoutPublicFieldSingleton_NotPublic.java.txt rename to test/effectivejava/test/samples/ClassWithoutPublicFieldSingleton_NotPublic.java.txt diff --git a/test/app/test/samples/ClassWithoutPublicFieldSingleton_NotStatic.java.txt b/test/effectivejava/test/samples/ClassWithoutPublicFieldSingleton_NotStatic.java.txt similarity index 100% rename from test/app/test/samples/ClassWithoutPublicFieldSingleton_NotStatic.java.txt rename to test/effectivejava/test/samples/ClassWithoutPublicFieldSingleton_NotStatic.java.txt diff --git a/test/app/test/samples/ClassWithoutPublicMethodSingleton_NotNamedGetInstance.java.txt b/test/effectivejava/test/samples/ClassWithoutPublicMethodSingleton_NotNamedGetInstance.java.txt similarity index 100% rename from test/app/test/samples/ClassWithoutPublicMethodSingleton_NotNamedGetInstance.java.txt rename to test/effectivejava/test/samples/ClassWithoutPublicMethodSingleton_NotNamedGetInstance.java.txt diff --git a/test/app/test/samples/LotOfTypes.java.txt b/test/effectivejava/test/samples/LotOfTypes.java.txt similarity index 100% rename from test/app/test/samples/LotOfTypes.java.txt rename to test/effectivejava/test/samples/LotOfTypes.java.txt diff --git a/test/app/test/samples/NotSingletonEnum_NoInstance.java.txt b/test/effectivejava/test/samples/NotSingletonEnum_NoInstance.java.txt similarity index 100% rename from test/app/test/samples/NotSingletonEnum_NoInstance.java.txt rename to test/effectivejava/test/samples/NotSingletonEnum_NoInstance.java.txt diff --git a/test/app/test/samples/NotSingletonEnum_NotOnlyInstance.java.txt b/test/effectivejava/test/samples/NotSingletonEnum_NotOnlyInstance.java.txt similarity index 100% rename from test/app/test/samples/NotSingletonEnum_NotOnlyInstance.java.txt rename to test/effectivejava/test/samples/NotSingletonEnum_NotOnlyInstance.java.txt diff --git a/test/app/test/samples/RefTypes.java.txt b/test/effectivejava/test/samples/RefTypes.java.txt similarity index 100% rename from test/app/test/samples/RefTypes.java.txt rename to test/effectivejava/test/samples/RefTypes.java.txt diff --git a/test/app/test/samples/SingletonEnum.java.txt b/test/effectivejava/test/samples/SingletonEnum.java.txt similarity index 100% rename from test/app/test/samples/SingletonEnum.java.txt rename to test/effectivejava/test/samples/SingletonEnum.java.txt diff --git a/test/app/test/samples/TypesToMatch.java.txt b/test/effectivejava/test/samples/TypesToMatch.java.txt similarity index 100% rename from test/app/test/samples/TypesToMatch.java.txt rename to test/effectivejava/test/samples/TypesToMatch.java.txt diff --git a/test/app/test/symbol_solver/funcs_test.clj b/test/effectivejava/test/symbol_solver/funcs_test.clj similarity index 92% rename from test/app/test/symbol_solver/funcs_test.clj rename to test/effectivejava/test/symbol_solver/funcs_test.clj index a3f363a..6a166c2 100644 --- a/test/app/test/symbol_solver/funcs_test.clj +++ b/test/effectivejava/test/symbol_solver/funcs_test.clj @@ -1,13 +1,13 @@ -(ns app.test.symbol_solver.funcs_test - (:use [app.jarloading]) - (:use [app.model.protocols]) - (:use [app.model.javaparser]) - (:use [app.javaparser.navigation]) - (:use [app.symbol_solver.funcs]) - (:use [app.symbol_solver.type_solver]) - (:use [app.symbol_solver.scope]) - (:use [app.test.symbol_solver.helper]) - (:use [app.utils]) +(ns effectivejava.test.symbol_solver.funcs_test + (:use [effectivejava.jarloading]) + (:use [effectivejava.model.protocols]) + (:use [effectivejava.model.javaparser]) + (:use [effectivejava.javaparser.navigation]) + (:use [effectivejava.symbol_solver.funcs]) + (:use [effectivejava.symbol_solver.type_solver]) + (:use [effectivejava.symbol_solver.scope]) + (:use [effectivejava.test.symbol_solver.helper]) + (:use [effectivejava.utils]) (:use [clojure.test])) ; ============================================ diff --git a/test/effectivejava/test/symbol_solver/helper.clj b/test/effectivejava/test/symbol_solver/helper.clj new file mode 100644 index 0000000..b4eb055 --- /dev/null +++ b/test/effectivejava/test/symbol_solver/helper.clj @@ -0,0 +1,18 @@ +(ns effectivejava.test.symbol_solver.helper + (:use [effectivejava.jarloading]) + (:use [effectivejava.model.protocols]) + (:use [effectivejava.model.javaparser]) + (:use [effectivejava.javaparser.navigation]) + (:use [effectivejava.symbol_solver.funcs]) + (:use [effectivejava.symbol_solver.type_solver]) + (:use [effectivejava.symbol_solver.scope]) + (:use [effectivejava.utils]) + (:use [clojure.test])) + +(def javaparser2 "test-resources/sample-jars/javaparser-core-2.0.0.jar") +(def samplesCus (cus "test-resources/sample-codebases/samples/")) +(def sampleClasses (flatten (map allTypes samplesCus))) + +(defn sampleClass [name] + {:post [%]} + (first (filter (fn [c] (= name (.getName c))) sampleClasses))) diff --git a/test/app/test/symbol_solver/scope_test.clj b/test/effectivejava/test/symbol_solver/scope_test.clj similarity index 89% rename from test/app/test/symbol_solver/scope_test.clj rename to test/effectivejava/test/symbol_solver/scope_test.clj index 53f6bdc..6bbec02 100644 --- a/test/app/test/symbol_solver/scope_test.clj +++ b/test/effectivejava/test/symbol_solver/scope_test.clj @@ -1,15 +1,15 @@ -(ns app.test.symbol_solver.scope_test - (:use [app.jarloading]) - (:use [app.model.protocols]) - (:use [app.model.javaparser]) - (:use [app.javaparser.navigation]) - (:use [app.symbol_solver.funcs]) - (:use [app.symbol_solver.type_solver]) - (:use [app.symbol_solver.scope]) - (:use [app.utils]) - (:use [app.test.helper]) +(ns effectivejava.test.symbol_solver.scope_test + (:use [effectivejava.jarloading]) + (:use [effectivejava.model.protocols]) + (:use [effectivejava.model.javaparser]) + (:use [effectivejava.javaparser.navigation]) + (:use [effectivejava.symbol_solver.funcs]) + (:use [effectivejava.symbol_solver.type_solver]) + (:use [effectivejava.symbol_solver.scope]) + (:use [effectivejava.utils]) + (:use [effectivejava.test.helper]) (:use [clojure.test]) - (:use [app.test.symbol_solver.helper])) + (:use [effectivejava.test.symbol_solver.helper])) (deftest testSolveNameInVariableDeclarator (let [aClassResolvingToLocalVar (sampleClass "AClassResolvingToLocalVar") diff --git a/test/app/test/symbol_solver/type_solver_test.clj b/test/effectivejava/test/symbol_solver/type_solver_test.clj similarity index 79% rename from test/app/test/symbol_solver/type_solver_test.clj rename to test/effectivejava/test/symbol_solver/type_solver_test.clj index 65a9b3a..40989df 100644 --- a/test/app/test/symbol_solver/type_solver_test.clj +++ b/test/effectivejava/test/symbol_solver/type_solver_test.clj @@ -1,11 +1,11 @@ -(ns app.test.symbol_solver.type_solver_test - (:use [app.jarloading]) - (:use [app.model.protocols]) - (:use [app.model.javaparser]) - (:use [app.model.reflection]) - (:use [app.javaparser.navigation]) - (:use [app.symbol_solver.type_solver]) - (:use [app.model.javassist]) +(ns effectivejava.test.symbol_solver.type_solver_test + (:use [effectivejava.jarloading]) + (:use [effectivejava.model.protocols]) + (:use [effectivejava.model.javaparser]) + (:use [effectivejava.model.reflection]) + (:use [effectivejava.javaparser.navigation]) + (:use [effectivejava.symbol_solver.type_solver]) + (:use [effectivejava.model.javassist]) (:use [clojure.test])) (def samplesCus (cus "test-resources/sample-codebases/type_solver_samples/")) diff --git a/test/app/test/utils.clj b/test/effectivejava/test/utils.clj similarity index 84% rename from test/app/test/utils.clj rename to test/effectivejava/test/utils.clj index 459656f..3dd24f2 100644 --- a/test/app/test/utils.clj +++ b/test/effectivejava/test/utils.clj @@ -1,6 +1,6 @@ -(ns app.test.utils +(ns effectivejava.test.utils (:use [clojure.test]) - (:use [app.utils])) + (:use [effectivejava.utils])) ; ============================================ ; preceedingChildren From abf97e5de7f80aa7e0f09ca7447496a8d56f3a68 Mon Sep 17 00:00:00 2001 From: Federico Tomassetti Date: Wed, 15 Jul 2015 14:38:32 +0200 Subject: [PATCH 41/42] introduce javaparser.facade --- project.clj | 3 ++- src/effectivejava/javaparser/facade.clj | 7 +++++++ test/effectivejava/test/cli.clj | 2 +- test/effectivejava/test/core.clj | 2 +- test/effectivejava/test/find_test.clj | 3 +-- test/effectivejava/test/helper.clj | 2 +- test/effectivejava/test/interactive.clj | 2 +- test/effectivejava/test/itemsOnLifecycle.clj | 2 +- test/effectivejava/test/jarloading.clj | 2 +- test/effectivejava/test/javaparser.clj | 2 +- test/effectivejava/test/javaparser/navigation_test.clj | 3 +-- test/effectivejava/test/model/javaparser_test.clj | 2 +- test/effectivejava/test/symbol_solver/funcs_test.clj | 2 +- test/effectivejava/test/symbol_solver/scope_test.clj | 2 +- test/effectivejava/test/symbol_solver/type_solver_test.clj | 2 +- 15 files changed, 22 insertions(+), 16 deletions(-) create mode 100644 src/effectivejava/javaparser/facade.clj diff --git a/project.clj b/project.clj index 46816e9..ce647ac 100644 --- a/project.clj +++ b/project.clj @@ -5,7 +5,8 @@ [org.clojure/tools.cli "0.3.1"] [instaparse "1.3.6"] [org.javassist/javassist "3.19.0-GA"] - [org.clojars.runa/conjure "2.1.3"]] + [org.clojars.runa/conjure "2.1.3"] + [potemkin "0.3.13"]] :resource-paths ["test-resources"] :plugins [[lein-cljfmt "0.1.10"] [lein-ancient "0.6.7"] [lein-kibit "0.1.2"] [jonase/eastwood "0.2.1"] [lein-cloverage "1.0.3"]] diff --git a/src/effectivejava/javaparser/facade.clj b/src/effectivejava/javaparser/facade.clj new file mode 100644 index 0000000..f858d2a --- /dev/null +++ b/src/effectivejava/javaparser/facade.clj @@ -0,0 +1,7 @@ +(ns effectivejava.javaparser.facade + (:use [potemkin]) + (:import [effectivejava.javaparser.navigation]) + (:import [effectivejava.javaparser.parsing])) + +(import-vars [effectivejava.javaparser.navigation allTypes allClasses allInterfaces allEnums allClassesForCus cus topLevelTypes getConstructors allConstructorsForCus getMethodDeclaration getNameExprFor getImports getVariableDeclarators getBlockStmts]) +(import-vars [effectivejava.javaparser.parsing parseFile parseString parseFileByName]) \ No newline at end of file diff --git a/test/effectivejava/test/cli.clj b/test/effectivejava/test/cli.clj index 3a6f183..0712ce2 100644 --- a/test/effectivejava/test/cli.clj +++ b/test/effectivejava/test/cli.clj @@ -6,7 +6,7 @@ (:use [effectivejava.model.protocols]) (:use [effectivejava.model.javaparser]) (:use [effectivejava.itemsOnLifecycle]) - (:use [effectivejava.javaparser.navigation]) + (:use [effectivejava.javaparser.facade]) (:use [effectivejava.operations]) (:use [clojure.test])) diff --git a/test/effectivejava/test/core.clj b/test/effectivejava/test/core.clj index d60ef47..8a60a08 100644 --- a/test/effectivejava/test/core.clj +++ b/test/effectivejava/test/core.clj @@ -3,7 +3,7 @@ (:use [effectivejava.test.helper]) (:use [effectivejava.itemsOnLifecycle]) (:use [effectivejava.interactive]) - (:use [effectivejava.javaparser.navigation]) + (:use [effectivejava.javaparser.facade]) (:use [clojure.test]) (:use [conjure.core]) (:use [effectivejava.symbol_solver.funcs]) diff --git a/test/effectivejava/test/find_test.clj b/test/effectivejava/test/find_test.clj index 23fad53..408a31a 100644 --- a/test/effectivejava/test/find_test.clj +++ b/test/effectivejava/test/find_test.clj @@ -4,8 +4,7 @@ (:use [effectivejava.find]) (:use [effectivejava.model.protocols]) (:use [effectivejava.model.javaparser]) - (:use [effectivejava.javaparser.parsing]) - (:use [effectivejava.javaparser.navigation]) + (:use [effectivejava.javaparser.facade]) (:use [effectivejava.symbol_solver.type_solver]) (:use [effectivejava.symbol_solver.scope]) (:use [clojure.test]) diff --git a/test/effectivejava/test/helper.clj b/test/effectivejava/test/helper.clj index 1578e96..be4eede 100644 --- a/test/effectivejava/test/helper.clj +++ b/test/effectivejava/test/helper.clj @@ -1,7 +1,7 @@ (ns effectivejava.test.helper (:use [effectivejava.model.javaparser]) (:use [clojure.test]) - (:use [effectivejava.javaparser.parsing])) + (:use [effectivejava.javaparser.facade])) (defn readResource [filename] (let [resourceName (str "effectivejava/test/samples/" filename ".java.txt") diff --git a/test/effectivejava/test/interactive.clj b/test/effectivejava/test/interactive.clj index 757c8b3..5058ae9 100644 --- a/test/effectivejava/test/interactive.clj +++ b/test/effectivejava/test/interactive.clj @@ -1,6 +1,6 @@ (ns effectivejava.test.interactive (:use [effectivejava.interactive] - [effectivejava.javaparser.navigation] + [effectivejava.javaparser.facade] [effectivejava.operations] [effectivejava.itemsOnLifecycle] [conjure.core] diff --git a/test/effectivejava/test/itemsOnLifecycle.clj b/test/effectivejava/test/itemsOnLifecycle.clj index 3f0ed5f..06c8e88 100644 --- a/test/effectivejava/test/itemsOnLifecycle.clj +++ b/test/effectivejava/test/itemsOnLifecycle.clj @@ -4,7 +4,7 @@ (:use [effectivejava.itemsOnLifecycle]) (:use [effectivejava.model.protocols]) (:use [effectivejava.model.javaparser]) - (:use [effectivejava.javaparser.navigation]) + (:use [effectivejava.javaparser.facade]) (:use [clojure.test]) (:use [effectivejava.test.helper]) (:require [instaparse.core :as insta])) diff --git a/test/effectivejava/test/jarloading.clj b/test/effectivejava/test/jarloading.clj index cf0c59f..f0b47af 100644 --- a/test/effectivejava/test/jarloading.clj +++ b/test/effectivejava/test/jarloading.clj @@ -1,7 +1,7 @@ (ns effectivejava.test.jarloading (:use [effectivejava.jarloading]) (:use [effectivejava.model.javaparser]) - (:use [effectivejava.javaparser.navigation]) + (:use [effectivejava.javaparser.facade]) (:use [clojure.test])) (def javaparser2 "test-resources/sample-jars/javaparser-core-2.0.0.jar") diff --git a/test/effectivejava/test/javaparser.clj b/test/effectivejava/test/javaparser.clj index 1464ee4..8e5695b 100644 --- a/test/effectivejava/test/javaparser.clj +++ b/test/effectivejava/test/javaparser.clj @@ -3,7 +3,7 @@ (:use [effectivejava.itemsOnLifecycle]) (:use [effectivejava.model.protocols]) (:use [effectivejava.model.javaparser]) - (:use [effectivejava.javaparser.navigation]) + (:use [effectivejava.javaparser.facade]) (:use [clojure.test]) (:use [effectivejava.test.helper]) (:require [instaparse.core :as insta])) diff --git a/test/effectivejava/test/javaparser/navigation_test.clj b/test/effectivejava/test/javaparser/navigation_test.clj index 0ebf58f..743b59b 100644 --- a/test/effectivejava/test/javaparser/navigation_test.clj +++ b/test/effectivejava/test/javaparser/navigation_test.clj @@ -2,8 +2,7 @@ (:use [effectivejava.itemsOnLifecycle]) (:use [effectivejava.model.protocols]) (:use [effectivejava.model.javaparser]) - (:use [effectivejava.javaparser.navigation]) - (:use [effectivejava.javaparser.parsing]) + (:use [effectivejava.javaparser.facade]) (:use [effectivejava.test.helper]) (:use [clojure.test])) diff --git a/test/effectivejava/test/model/javaparser_test.clj b/test/effectivejava/test/model/javaparser_test.clj index b583a9f..ff61351 100644 --- a/test/effectivejava/test/model/javaparser_test.clj +++ b/test/effectivejava/test/model/javaparser_test.clj @@ -2,7 +2,7 @@ (:use [effectivejava.itemsOnLifecycle]) (:use [effectivejava.model.protocols]) (:use [effectivejava.model.javaparser]) - (:use [effectivejava.javaparser.navigation]) + (:use [effectivejava.javaparser.facade]) (:use [effectivejava.test.helper]) (:use [clojure.test])) diff --git a/test/effectivejava/test/symbol_solver/funcs_test.clj b/test/effectivejava/test/symbol_solver/funcs_test.clj index 6a166c2..a9a8484 100644 --- a/test/effectivejava/test/symbol_solver/funcs_test.clj +++ b/test/effectivejava/test/symbol_solver/funcs_test.clj @@ -2,7 +2,7 @@ (:use [effectivejava.jarloading]) (:use [effectivejava.model.protocols]) (:use [effectivejava.model.javaparser]) - (:use [effectivejava.javaparser.navigation]) + (:use [effectivejava.javaparser.facade]) (:use [effectivejava.symbol_solver.funcs]) (:use [effectivejava.symbol_solver.type_solver]) (:use [effectivejava.symbol_solver.scope]) diff --git a/test/effectivejava/test/symbol_solver/scope_test.clj b/test/effectivejava/test/symbol_solver/scope_test.clj index 6bbec02..4b50cb4 100644 --- a/test/effectivejava/test/symbol_solver/scope_test.clj +++ b/test/effectivejava/test/symbol_solver/scope_test.clj @@ -2,7 +2,7 @@ (:use [effectivejava.jarloading]) (:use [effectivejava.model.protocols]) (:use [effectivejava.model.javaparser]) - (:use [effectivejava.javaparser.navigation]) + (:use [effectivejava.javaparser.facade]) (:use [effectivejava.symbol_solver.funcs]) (:use [effectivejava.symbol_solver.type_solver]) (:use [effectivejava.symbol_solver.scope]) diff --git a/test/effectivejava/test/symbol_solver/type_solver_test.clj b/test/effectivejava/test/symbol_solver/type_solver_test.clj index 40989df..7eb7365 100644 --- a/test/effectivejava/test/symbol_solver/type_solver_test.clj +++ b/test/effectivejava/test/symbol_solver/type_solver_test.clj @@ -3,7 +3,7 @@ (:use [effectivejava.model.protocols]) (:use [effectivejava.model.javaparser]) (:use [effectivejava.model.reflection]) - (:use [effectivejava.javaparser.navigation]) + (:use [effectivejava.javaparser.facade]) (:use [effectivejava.symbol_solver.type_solver]) (:use [effectivejava.model.javassist]) (:use [clojure.test])) From 999f677ea8a1d3f567f06453d3cb2fe7df00a98c Mon Sep 17 00:00:00 2001 From: Federico Tomassetti Date: Wed, 15 Jul 2015 14:53:04 +0200 Subject: [PATCH 42/42] fix failing test --- test/effectivejava/test/cli.clj | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/test/effectivejava/test/cli.clj b/test/effectivejava/test/cli.clj index 0712ce2..0e0deda 100644 --- a/test/effectivejava/test/cli.clj +++ b/test/effectivejava/test/cli.clj @@ -6,7 +6,7 @@ (:use [effectivejava.model.protocols]) (:use [effectivejava.model.javaparser]) (:use [effectivejava.itemsOnLifecycle]) - (:use [effectivejava.javaparser.facade]) + (:use [effectivejava.javaparser.navigation]) (:use [effectivejava.operations]) (:use [clojure.test])) @@ -127,10 +127,10 @@ (deftest run-invoke-the-right-stuff (let [opts {:dir "mydir", :threshold 43, :query :mcp}] (stubbing [cus '(:cu1 :cu2 :cu3)] - (mocking [println printOperation] - (run opts) - (verify-call-times-for println 1) - (verify-call-times-for printOperation 1) - (verify-first-call-args-for println "Considering" 3 "Java files") - (verify-first-call-args-for printOperation constructorsWithManyParametersOp '(:cu1 :cu2 :cu3) 43))))) + (mocking [println printOperation] + (run opts) + (verify-call-times-for println 1) + (verify-call-times-for printOperation 1) + (verify-first-call-args-for println "Considering" 3 "Java files") + (verify-first-call-args-for printOperation constructorsWithManyParametersOp '(:cu1 :cu2 :cu3) 43)))))