ftomassetti / effectivejava Goto Github PK
View Code? Open in Web Editor NEWRun queries on your Java code to check if it meets the criteria suggested by the book Effective Java. And some others.
License: Apache License 2.0
Run queries on your Java code to check if it meets the criteria suggested by the book Effective Java. And some others.
License: Apache License 2.0
Convert also the cli and repl to take advantage of the names and shortcuts of queries
To distinguish among constructors of the same class.
Same applies to MethodDeclaration.
It should be fixed in javaparser.clj, around line 70
When I execute lein run -- --query mcp the program raises a NullPointerException.
It does not happen if I specify a threshold: lein run -- --query mcp -t 1, but raises the same kind of exception if the threshold is <= 0.
Javaparser does not solve symbols, it just builds ASTs. We need to do that and to do that we need also to examine Jar files and binary components. I should have some initial Java code somewhere to be used as an initial inspiration. Fun times are ahead...
I think names should be separated by hyphens instead of using camel-case, so:
foo-bar ; good
fooBar ; bad
Ideally I would know which errors/warnings refer to the lines/classes I am changing, so I would like to somehow pipe it with svn diff or git diff.
While it could be easy to assign each warning to a class, it could be trickier to assign specific lines.
I should think about that.
It is wrong to use the constructor in the clone method of not-final classes
Run kibit and use suggestions to improve quality
Constructors of non final classes should not invoke overridable methods
The threshold seems to be set to 5 ignoring the user input.
For example, using the examples classes included in the project:
mc th 7
class | numberOfConstructors
japa.parser.ast.body.BaseParameter | 5
japa.parser.ast.body.FieldDeclaration | 5
japa.parser.ast.body.MethodDeclaration | 5
japa.parser.ast.expr.ArrayCreationExpr | 5
org.springframework.jdbc.core.ResultSetSupportingSqlParameter | 6
org.springframework.jdbc.core.SqlInOutParameter | 7
org.springframework.jdbc.core.SqlOutParameter | 7
org.springframework.jdbc.core.SqlParameter | 7
org.springframework.jdbc.core.support.SqlLobValue | 8
So, downloaded the 01.2-SNAPSHOT.jar file. Trying to run it on Windows 7 with java 8:
$ java -version
java version "1.8.0_31"
Java(TM) SE Runtime Environment (build 1.8.0_31-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.31-b07, mixed mode)
Both from bash and from the cmd prompt, I get a null pointer exception:
C:\Users\dan.moore\project\effectivejava>java -jar effectivejava-0.1.2-SNAPSHOT-standalone.jar
Exception in thread "main" java.lang.ExceptionInInitializerError
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:344)
at clojure.lang.RT.loadClassForName(RT.java:2093)
at clojure.lang.RT.load(RT.java:430)
at clojure.lang.RT.load(RT.java:411)
at clojure.core$load$fn__5066.invoke(core.clj:5641)
at clojure.core$load.doInvoke(core.clj:5640)
at clojure.lang.RestFn.invoke(RestFn.java:408)
at app.core__init.load(Unknown Source)
at app.core__init.<clinit>(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:344)
at clojure.lang.RT.loadClassForName(RT.java:2093)
at clojure.lang.RT.load(RT.java:430)
at clojure.lang.RT.load(RT.java:411)
at clojure.core$load$fn__5066.invoke(core.clj:5641)
at clojure.core$load.doInvoke(core.clj:5640)
at clojure.lang.RestFn.invoke(RestFn.java:408)
at clojure.lang.Var.invoke(Var.java:379)
at app.core.<clinit>(Unknown Source)
Caused by: java.lang.NullPointerException
at app.javaparser__init.load(Unknown Source)
at app.javaparser__init.<clinit>(Unknown Source)
... 20 more
I get a similar error when running it in lint mode.
As suggested here (http://tomassetti.me/effective-java-a-tool-to-explore-and-measure-your-java-code-written-in-clojure/#comment-3321) we could assign a score to classes to help find out which classes should be examined first in an unknown codebase
Maybe for certain commands I want to consider only one package
Check every class override it (or a superclass different from Object does it)
When in the interactive mode, if the user presses the enter key, he will get an error like this:
ERROR: Parse error at line 1, column 1:
nil
^
Expected one of:
singletons (followed by end-of-string)
st (followed by end-of-string)
finalizers (followed by end-of-string)
f (followed by end-of-string)
list (followed by end-of-string)
q (followed by end-of-string)
quit (followed by end-of-string)
exit (followed by end-of-string)
h (followed by end-of-string)
help (followed by end-of-string)
many-costructor-params
mcp
many-constructors
mc
load
Wouldn't it be more intuitive to get something like this when pressing enter multiple times?
If you think so, I can fix this.
When in interactive mode the help command produce this output:
h/help : print this help message
q/quit/exit : close the shell
list : list classes loaded
mc/many-constructors th NUM : list classes with NUM or more constructors
it should also include the load command
As a follow up of #30
Are there acceptable exceptions?
And explain how to use it in the Readme.
What should we do to make it usable from Maven?
Implement and document it
Should we fear to have null parent somewhere along the line?
We want to recognize Utils classes. We could use the name and/or look for classes which has only static methods and fields (and at least one method)
Running lein cloverage
I get this:
Produced output in /home/federico/repos/effectivejava/target/coverage .
HTML: file:///home/federico/repos/effectivejava/target/coverage/index.html
| :name | :forms_percent | :lines_percent |
|-------------------------------+----------------+----------------|
| app.cli | 63.27 % | 33.33 % |
| app.core | 12.45 % | 27.12 % |
| app.interactive | 10.39 % | 21.79 % |
| app.itemsOnLifecycle | 72.66 % | 81.37 % |
| app.jarloading | 97.20 % | 96.88 % |
| app.javaparser.navigation | 63.34 % | 94.12 % |
| app.javaparser.parsing | 98.68 % | 100.00 % |
| app.linter | 17.44 % | 45.83 % |
| app.model.javaparser | 61.66 % | 78.17 % |
| app.model.javassist | 90.91 % | 66.67 % |
| app.operations | 60.80 % | 82.14 % |
| app.symbol_solver.scope | 97.85 % | 98.89 % |
| app.symbol_solver.type_solver | 90.91 % | 100.00 % |
| app.utils | 92.96 % | 94.44 % |
Files with 100% coverage: 2
Forms covered: 59.73 %
Lines covered: 75.79 %
We should first of all organize better the tests (especially w.r.t the new modules for symbol resolution) and then focus on improving code coverage where possible. I would try to track progress in this issue.
We could recognize classes which has finalizers. This one should be easy.
I get this warning while executing the program:
WARNING: Named already refers to: interface clojure.lang.Named in namespace: app.model.javaparser, being replaced by: #'app.model.protocols/Named
For example running "lein run -l -q" should be an error
And those fields should be note arrays (which are mutable)
Integer should be aligned to right, class qnames to left
Please create a Maven wrapper plugin so that this tool can be used easily in automated builds
It is best for interface to not extend it and for not final classes to not implement it
Given this example:
class B extends A {
}
class C extends B {
}
We need to find the superclasses of C (A and B).
We have most of the logic in place for that, but I could write the last bit for this particular case.
I would write a function named "solveSuperclass" in funcs.clj which would get a ClassDeclaration instance and basically call
(solveClass classDeclaration nil (.getSuperclass classDeclaration)
solveClass is a method from a protocol.
Once we have this function we can create getAllSuperclasses calling recursively solveSuperclass.
...maybe a screencast?
Otherwise force programmer to call toString
maybe we can shorten package to one letter (when non ambiguos) or remove the common prefix of packages. We could also avoid printing the parameters of generics maybe
Clone should return the same class of the defining class and do not declare to throw CloneNotSUpportedException.
They should also not call not-final methods.
Start with Travis, it should be enough for now.
After loading some classes, running 'list' shows the loaded classes, but it also shows this error: 'No classes loaded. Use < load > first' and exits the program.
Fill information in this line Copyright {yyyy} {name of copyright owner}
in License
Probably app
is a very bad name for the namespace. We should rename all of them and then we could use import-vars from https://github.com/ztellman/potemkin to import and re-export the symbols defined in the namespace. For example we could have one namespace name app.model.facade which expose all the content of all the namespaces with name app.model.*
When using the linter mode, if the user does not specify a directory, the program uses the current one. On the other hand, when using the query mode, the program raises an error if the user does not specify a directory.
Avoid any warning to be produced.
Do not suppress Warning on entire classes.
We should prefer composition
Does it work for SingleFieldDeclaration?
Does it work for MethodDeclaration?
Does it work for TypeDeclaration?
Does it work for FieldDeclaration?
In the interactive mode, ff the user tries to execute a command that is not implemented, he gets an error such as: Command not implemented: , and the program closes.
I think that it would be more natural to show the error and continue the execution.
In the equals
method float and double fields should be compared using Float.compare and Double.compare because of the existence of NaN and -0.0f (see Float documentation).
We could write a query that check that.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.