[ANN] InspectionGadgets 0.0.5 released
Announcing the release of InspectionGadgets version 0.0.5, available at http://www.intellij.org/twiki/bin/view/Main/InspectionGadgets. Requires Aurora version 944 or higher.
Changes since version 0.0.4
Recompiled to handle PSI changes in 944.
New Inspections
equals() between objects of inconvertible types
Implicit numeric conversion
Numeric cast that lose precision
Method overrides static method of superclass.
Method overrides private method of superclass
Manual array copying
Static collections
Zero-length array allocation
Use of java.lang.reflect
Busy wait
Single class import
Unused import
Redundant import
main() with signature other than public static void main(String[])
Class explicitly extends java.lang.Object
More auto corrections, including corrections for
C-style array declaration
Multiple variables in one declaration
Variables of different types in one declaration
Call to Thread.run
Call to notify() instead of notifyAll()
Transient field on non-serializable class
Bugfixes
请先登录再写评论。
Dave, do you plan to relese 944 version of Intentions PowerPack?
U¿ytkownik "Dave Griffith" <dave.griffith@cnn.com> napisa³ w wiadomo¶ci
news:17757570.1065188017937.JavaMail.itn@is.intellij.net...
>
>
http://www.intellij.org/twiki/bin/view/Main/InspectionGadgets. Requires
Aurora version 944 or higher.
>
>
>
>
>
Dave, I forgot to say:
I LOVE your plugin!
U¿ytkownik "Michal Szklanowski" <szklanowski@acn.waw.pl> napisa³ w
wiadomo¶ci news:blk9ij$n31$1@is.intellij.net...
>
>
>
Certainly. Probably by Tuesday, given how my schedule it looking.
--Dave Griffith
Aw, shucks.
Your amazing :) Thank you for helping out the whole community here with your
plugins and continual support!
--Grant Gochnauer
"Dave Griffith" <dave.griffith@cnn.com> wrote in message
news:24593473.1065201042596.JavaMail.itn@is.intellij.net...
>
Thanks a lot, your plugin simply rocks..
I get a pretty consistent problem whilst typing a switch statement with
IG running. As soon as I hit the closing paren of the switch statement
and before there is any more to it's structure I get this thrown:
Seems very reproducable with 944 and IG 0.0.5. Switching to a different
file and switching off the highlighting gts me out of the error loop.
Guy
ERROR - emon.impl.LocalInspectionsPass - Exception happened
in local
inspection tool: Loop statement that doesn't loop
ERROR - emon.impl.LocalInspectionsPass - IntelliJ IDEA
Aurora) Bui
ld #944
ERROR - emon.impl.LocalInspectionsPass - JDK: 1.4.2
ERROR - emon.impl.LocalInspectionsPass - VM: Java HotSpot(TM)
Client
VM
ERROR - emon.impl.LocalInspectionsPass - Vendor: Sun
Microsystems Inc
.
ERROR - emon.impl.LocalInspectionsPass - OS: Windows XP
ERROR - emon.impl.LocalInspectionsPass - Last Action:
EditorLineEnd
ERROR - emon.impl.LocalInspectionsPass - Exception happened
in local
inspection tool: Loop statement that doesn't loop
java.lang.NullPointerException
at
com.siyeh.ig.psiutils.ControlFlowUtils.switchStatementMayReturnNormal
ly(ControlFlowUtils.java:107)
at
com.siyeh.ig.psiutils.ControlFlowUtils.statementMayCompleteNormally(C
ontrolFlowUtils.java:69)
at
com.siyeh.ig.psiutils.ControlFlowUtils.codeBlockMayCompleteNormally(C
ontrolFlowUtils.java:171)
at
com.siyeh.ig.psiutils.ControlFlowUtils.statementMayCompleteNormally(C
ontrolFlowUtils.java:53)
at
com.siyeh.ig.bugs.LoopStatementsThatDontLoopInspection$LoopStatements
ThatDontLoopVisitor.visitForStatement(LoopStatementsThatDontLoopInspection.java:
46)
at com.intellij.psi.impl.source.g.a.u.accept(u.java:47)
at com.intellij.psi.impl.source.g.u.acceptChildren(u.java:75)
at
com.intellij.psi.PsiRecursiveElementVisitor.visitElement(PsiRecursive
ElementVisitor.java)
at
com.intellij.psi.JavaElementVisitor.visitCodeBlock(JavaElementVisitor
.java:59)
at com.intellij.psi.impl.source.g.a.bt.accept(bt.java:6)
at com.intellij.psi.impl.source.bg.acceptChildren(bg.java:46)
at
com.intellij.psi.PsiRecursiveElementVisitor.visitElement(PsiRecursive
ElementVisitor.java)
at
com.intellij.psi.JavaElementVisitor.visitMethod(JavaElementVisitor.ja
va:7)
at com.intellij.psi.impl.source.bt.accept(bt.java:86)
at
com.siyeh.ig.StatementInspection.checkMethod(StatementInspection.java
:48)
at com.intellij.codeInsight.g.a.bw.a(bw.java:90)
at com.intellij.codeInsight.g.a.cn.run(cn.java:12)
at com.intellij.openapi.application.a.d.runReadAction(d.java:310)
at com.intellij.codeInsight.g.a.db.a(db.java:5)
at com.intellij.codeInsight.g.a.db.b(db.java:3)
at com.intellij.codeInsight.g.a.cm.run(cm.java:0)
at com.intellij.progress.c.a(c.java:9)
at com.intellij.codeInsight.g.a.db.run(db.java:15)
Thanks for catching this one. Those NPEs coming out of the PSI are really tricky to find all of, since they usually only show up on temporarily incorrect java files. I've uploaded a fix for this one to the Wiki (no change to the version number).
--Dave Griffith
What is the price of a new label? Maybe you could use 0.0.5b if you do not want to add a 4th digit or increment the 3rd.
It you make sure that every published version of your software has a unique version id you know exactly what people are running...
On the subject of label you might want to hit the minor number now. I think your software does enough and well enough to label it 0.1 (it does more than all my plugins combined ;-). That way you will be able to use the 3rd digit for quick fixes... ;)
Just my 2 c
Thanks for your amazing work!
Jacques
Dave,
Could you add an inspection that identifies unused labels?
Thanks,
Jon
Hurm. I had actually assumed that that was already covered by the built-in inspection for "Unused code", but a few quick tests show that not to be the case. I never use labels, so I never noticed it before. Easy enough to add. I'll put it on the (rapidly disappearing) TODO list for the plugin. Should be in the next release, as yet unscheduled.
Great. I prefer not to use labels myself too but would still like to
know when I'm inspecting code that has extraneous labels. Is that TODO
list a private list you keep? I didn't see it on the InspectionGadgets
plugin page.
Thanks,
Jon
Dave Griffith wrote:
Dave Griffith wrote:
BTW, have you considered adding an inspection for those whose guidelines
are against use of labels?
Jon
I had been keeping the TODO list private, but mostly out of laziness. For anyone who might be interested, here's the list of inspections I plan to implement eventually. Basically, it was compiled by unioning all of the inspections provided by existing products, subtracting out the ones implemented by IDEA, implemented by me, specifically related to EJBs, better handled by the code formatter, or kinda stupid. There are 202 inspections in InspectionGadgets, and 11 left on my TODO list:
Static Fields should not be read in class initialization before they are initialized.
Fields should not be read in object initialization before they are initialized.
Field may be local
Streams should be opened in a try block, and closed in the finally block.
Non-constant Strings should be replaced by StringBuffers.
Constant StringBuffers should be replaced by Strings.
Unnecessary fully-qualified class names
Method overrides superclass method, when overloading might be intended
Vector and Hashtable usage
Unused labels
For loops with missing initialization|condition|update
--Dave
There are already inspections for labelled continue statements, labelled break statements, and will soon be one for unused labels. Between those, the effect is to ban all label usage. If people think it would make sense, I can certainly add a check for any labels at all. Shouldn't take more than five minutes, cutting and pasting the inspection for continue statements.
My basic plan has been to use the low version numbers to indicate the extreme beta-ish nature of the software, and then jump to 1.0 after I finish my TODO list and Aurora goes into final release (which should be at about the same time, at this rate).
Thanks for the list. Say, have you considered adding some sort of
statistics for inspections that would let one know how frequent a
problem is comparatively speaking? That comparison would be against the
set of code you are inspecting whether a single class (least useful),
package or the entire project (most useful). I'm interested in how sick
one set of code is compared to another for an inspection in whatever is
the best way to express that... perhaps as a percentage of code,
perhaps other ways.
Jon
Perhaps all could be grouped together.
Jon
Dave Griffith wrote:
The Inspection API is more or less designed to keep me from collecting any sort of global information about inspection runs, or indeed getting any other global information (which would enable a couple of really powerful inspections). Inspection statistics seems like a reasonable thing to ask as a core IDEA feature, but it's just not doable in a plug-in.
Has a feature request been submitted for this?
Jon
Dave Griffith wrote:
Not that I know of. Go for it.
Hi Dave,
here is one more exception, which may occur in the
refreshed 0.0.5 (and earlier) version.
The plugin works great until I start to change the inspected
code. Immediatly after saving the changed files I'm getting
the exception pasted in below. Pressing in the Error
dialog doesn't help, the exception reappears soon afterwards.
Please let me know if you need more infos.
java.lang.NullPointerException
at com.intellij.codeInspection.r.z.a(z.java:11)
at com.intellij.ide.by.a(by.java:25)
at com.intellij.ide.by.a(by.java:63)
at com.intellij.ide.by.d(by.java:14)
at com.intellij.ide.f.dv.b(dv.java:1)
at com.intellij.ide.f.ds.update(ds.java:64)
at com.intellij.openapi.actionSystem.b.z.a(z.java:63)
at com.intellij.openapi.actionSystem.b.bh.b(bh.java:77)
at com.intellij.openapi.actionSystem.b.u.run(u.java:11)
at com.intellij.openapi.actionSystem.b.ba.run(ba.java:0)
at com.intellij.openapi.actionSystem.b.h.actionPerformed(h.java:2)
at javax.swing.Timer.fireActionPerformed(Unknown Source)
at javax.swing.Timer$DoPostEvent.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at com.intellij.ide.s.a(s.java:12)
at com.intellij.ide.s.dispatchEvent(s.java:48)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Martin
PS: I'm not sure if related or not, but whenever I start an inspection,
I'm getting the following Exception. The exception pops up
just once and does not stop the plugin. It appears just before the
progress window "Inspecting code..." is shown.
ERROR - plication.impl.ApplicationImpl - VM: Java HotSpot(TM) Client VM
ERROR - plication.impl.ApplicationImpl - Vendor: Sun Microsystems Inc
.
ERROR - plication.impl.ApplicationImpl - OS: Windows XP
ERROR - plication.impl.ApplicationImpl - Last Action: InspectCode
ERROR - plication.impl.ApplicationImpl - Read access is allowed from event dispatch thread or inside read-action only (see com.intellij.openapi.application.Application.runReadAction())
java.lang.Throwable
at com.intellij.openapi.diagnostic.Logger.error(Logger.java:103)
at com.intellij.openapi.application.a.d.assertReadAccessAllowed(d.java:51)
at com.intellij.psi.impl.f.a.c.a(c.java:315)
at com.intellij.psi.impl.bn.b(bn.java:301)
at com.intellij.psi.impl.bn.a(bn.java:263)
at com.intellij.psi.impl.a.t.getParent(t.java:470)
at com.intellij.psi.impl.a.t.getContainingFile(t.java:122)
at com.intellij.psi.impl.f.a.c.c(c.java:139)
at com.intellij.psi.impl.f.a.c.a(c.java:58)
at com.intellij.psi.impl.cd.findClass(cd.java:9)
at com.intellij.psi.impl.cd.findClass(cd.java:262)
at com.intellij.codeInspection.m.l.]]>(l.java:81)
at com.intellij.codeInspection.x.br.f(br.java:113)
at com.intellij.codeInspection.x.br.c(br.java:134)
at com.intellij.codeInspection.x.br.c(br.java:102)
at com.intellij.codeInspection.x.i.run(i.java)
at com.intellij.progress.c.a(c.java:9)
at com.intellij.progress.a.i.b(i.java:29)
at com.intellij.progress.a.i.b(i.java:4)
at com.intellij.progress.a.i.c(i.java:14)
at com.intellij.progress.a.u.run(u.java)
This is a IDEA bug, not IG. I'm pretty sure a tracker item has already been entered for it.
Done. Feature request #18391 is in--
http://www.intellij.net/tracker/idea/viewSCR?publicId=18391
Feel free to expand on it... I'd be interested in an example of a
powerful global inspection.
Thanks,
Jon
Dave Griffith wrote:
FYI Just encountered this exception.
Regards,
Nathan.
java.lang.NullPointerException
at com.intellij.psi.impl.source.d.e.c(e.java:55)
at com.intellij.psi.impl.source.g.t.a(t.java:112)
at com.intellij.psi.impl.source.g.u.replace(u.java:83)
at com.siyeh.ig.BaseInspection.replaceExpression(BaseInspection.java:53)
at
com.siyeh.ig.verbose.UnnecessaryThisInspection.access$200(UnnecessaryThisInspection.java:9)
at
com.siyeh.ig.verbose.UnnecessaryThisInspection$UnnecessaryReturnFix.applyFix(UnnecessaryThisInspection.java:55)
at com.intellij.codeInspection.x.bp.invoke(bp.java:1)
at com.intellij.codeInsight.intention.b.bj.run(bj.java:8)
at com.intellij.openapi.application.a.d.runWriteAction(d.java:170)
at com.intellij.codeInsight.intention.b.bk.run(bk.java)
at com.intellij.openapi.command.b.b.executeCommand(b.java:31)
at com.intellij.codeInsight.intention.b.bs.run(bs.java:4)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at com.intellij.ide.s.a(s.java:12)
at com.intellij.ide.s.dispatchEvent(s.java:48)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Dave Griffith wrote:
Cool plug-in! I've been having lots of fun with it.
One question about an optimization it recommends. To convert a String to a
boolean, it recommends using "Boolean.getBoolean( xx )" instead of "new
Boolean( xx ).booleanValue()". In my benchmarks (Java 1.4.2_01, Windows XP),
the recommended approach is more than twice as SLOW (i.e. it takes 2x
longer) than the old code. I suspect this is because of a
System.getProperty() call in Boolean.getBoolean(). Do you know if this
performance issue would be the same for all versions of the JDK?
Thanks,
--DanR
"Dave Griffith" <dave.griffith@cnn.com> wrote in message
news:17757570.1065188017937.JavaMail.itn@is.intellij.net...
>
>
http://www.intellij.org/twiki/bin/view/Main/InspectionGadgets. Requires
Aurora version 944 or higher.
>
>
>
>
>
Give String str = "true"
It should suggest using
Boolean.toBoolean(str)
instead of
new Boolean(str).booleanValue();
as these are essentially the same. The getBoolean method has a different intent...it returns a system property associated with property "str" not the boolean value of "str".
But Boolean.toBoolean( str ) is private...
"charles decroes" <spam@decroes.com> wrote in message
news:20657294.1066078919618.JavaMail.itn@is.intellij.net...
>
>
>
>
intent...it returns a system property associated with property "str" not the
boolean value of "str".
Boolean.valueOf(str)
FYI an exception:
java.lang.NullPointerException
at
com.siyeh.ig.psiutils.SideEffectChecker.mayHaveSideEffects(SideEffectChecker.java:14)
at
com.siyeh.ig.performance.ManualArrayCopyInspection$ManualArrayCopyVisitor.expressionIsArrayMove(ManualArrayCopyInspection.java:241)
at
com.siyeh.ig.performance.ManualArrayCopyInspection$ManualArrayCopyVisitor.bodyIsArrayMove(ManualArrayCopyInspection.java:191)
at
com.siyeh.ig.performance.ManualArrayCopyInspection$ManualArrayCopyVisitor.bodyIsArrayMove(ManualArrayCopyInspection.java:209)
at
com.siyeh.ig.performance.ManualArrayCopyInspection$ManualArrayCopyVisitor.visitForStatement(ManualArrayCopyInspection.java:169)
at com.intellij.psi.impl.source.g.a.u.accept(u.java:47)
at com.intellij.psi.impl.source.g.u.acceptChildren(u.java:75)
at
com.intellij.psi.PsiRecursiveElementVisitor.visitElement(PsiRecursiveElementVisitor.java)
at
com.intellij.psi.JavaElementVisitor.visitCodeBlock(JavaElementVisitor.java:59)
at com.intellij.psi.impl.source.g.a.bt.accept(bt.java:6)
at com.intellij.psi.impl.source.bg.acceptChildren(bg.java:46)
at
com.intellij.psi.PsiRecursiveElementVisitor.visitElement(PsiRecursiveElementVisitor.java)
at
com.intellij.psi.JavaElementVisitor.visitMethod(JavaElementVisitor.java:7)
at com.intellij.psi.impl.source.bt.accept(bt.java:86)
at com.intellij.psi.impl.source.bg.acceptChildren(bg.java:46)
at
com.intellij.psi.PsiRecursiveElementVisitor.visitElement(PsiRecursiveElementVisitor.java)
at
com.intellij.psi.JavaElementVisitor.visitClass(JavaElementVisitor.java:168)
at
com.intellij.psi.JavaElementVisitor.visitAnonymousClass(JavaElementVisitor.java:110)
at com.intellij.psi.impl.source.bk.accept(bk.java:2)
at com.intellij.psi.impl.source.g.u.acceptChildren(u.java:75)
at
com.intellij.psi.PsiRecursiveElementVisitor.visitElement(PsiRecursiveElementVisitor.java)
at
com.intellij.psi.JavaElementVisitor.visitExpression(JavaElementVisitor.java:26)
at
com.intellij.psi.JavaElementVisitor.visitNewExpression(JavaElementVisitor.java:82)
at com.intellij.psi.impl.source.g.a.bc.accept(bc.java:77)
at com.intellij.psi.impl.source.g.u.acceptChildren(u.java:75)
at
com.intellij.psi.PsiRecursiveElementVisitor.visitElement(PsiRecursiveElementVisitor.java)
at
com.intellij.psi.JavaElementVisitor.visitExpressionList(JavaElementVisitor.java:128)
at com.intellij.psi.impl.source.g.a.r.accept(r.java:6)
at com.intellij.psi.impl.source.g.u.acceptChildren(u.java:75)
at
com.intellij.psi.PsiRecursiveElementVisitor.visitElement(PsiRecursiveElementVisitor.java)
at
com.intellij.psi.JavaElementVisitor.visitExpression(JavaElementVisitor.java:26)
at
com.intellij.psi.JavaElementVisitor.visitMethodCallExpression(JavaElementVisitor.java:65)
at com.intellij.psi.impl.source.g.a.bb.accept(bb.java:3)
at com.intellij.psi.impl.source.g.u.acceptChildren(u.java:75)
at
com.intellij.psi.PsiRecursiveElementVisitor.visitElement(PsiRecursiveElementVisitor.java)
at
com.intellij.psi.JavaElementVisitor.visitStatement(JavaElementVisitor.java:172)
at
com.intellij.psi.JavaElementVisitor.visitExpressionStatement(JavaElementVisitor.java:104)
at com.intellij.psi.impl.source.g.a.t.accept(t.java:5)
at com.intellij.psi.impl.source.g.u.acceptChildren(u.java:75)
at
com.intellij.psi.PsiRecursiveElementVisitor.visitElement(PsiRecursiveElementVisitor.java)
at
com.intellij.psi.JavaElementVisitor.visitCodeBlock(JavaElementVisitor.java:59)
at com.intellij.psi.impl.source.g.a.bt.accept(bt.java:6)
at com.intellij.psi.impl.source.g.u.acceptChildren(u.java:75)
at
com.intellij.psi.PsiRecursiveElementVisitor.visitElement(PsiRecursiveElementVisitor.java)
at
com.intellij.psi.JavaElementVisitor.visitStatement(JavaElementVisitor.java:172)
at
com.intellij.psi.JavaElementVisitor.visitBlockStatement(JavaElementVisitor.java:151)
at com.intellij.psi.impl.source.g.a.i.accept(i.java:2)
at com.intellij.psi.impl.source.g.u.acceptChildren(u.java:75)
at
com.intellij.psi.PsiRecursiveElementVisitor.visitElement(PsiRecursiveElementVisitor.java)
at
com.intellij.psi.JavaElementVisitor.visitStatement(JavaElementVisitor.java:172)
at
com.intellij.psi.JavaElementVisitor.visitIfStatement(JavaElementVisitor.java:133)
at com.intellij.psi.impl.source.g.a.v.accept(v.java:6)
at com.intellij.psi.impl.source.g.u.acceptChildren(u.java:75)
at
com.intellij.psi.PsiRecursiveElementVisitor.visitElement(PsiRecursiveElementVisitor.java)
at
com.intellij.psi.JavaElementVisitor.visitCodeBlock(JavaElementVisitor.java:59)
at com.intellij.psi.impl.source.g.a.bt.accept(bt.java:6)
at com.intellij.psi.impl.source.bg.acceptChildren(bg.java:46)
at
com.intellij.psi.PsiRecursiveElementVisitor.visitElement(PsiRecursiveElementVisitor.java)
at
com.intellij.psi.JavaElementVisitor.visitMethod(JavaElementVisitor.java:7)
at com.intellij.psi.impl.source.bt.accept(bt.java:86)
at
com.siyeh.ig.ExpressionInspection.checkMethod(ExpressionInspection.java:45)
at com.intellij.codeInsight.g.a.bw.a(bw.java:90)
at com.intellij.codeInsight.g.a.cn.run(cn.java:12)
at com.intellij.openapi.application.a.d.runReadAction(d.java:310)
at com.intellij.codeInsight.g.a.db.a(db.java:5)
at com.intellij.codeInsight.g.a.db.b(db.java:3)
at com.intellij.codeInsight.g.a.cm.run(cm.java:0)
at com.intellij.progress.c.a(c.java:9)
at com.intellij.codeInsight.g.a.db.run(db.java:15)
Dave Griffith wrote: