How to inspect only the elements modified since the last (class) inspection?

If you modify only a single field, is there a way for a given inspection
to visit/inspect only this field, instead of all the methods and all the
class fields, like it does now?

Motivation: some inspections are very expensive (use findReferences():
50-100 ms/call), and for some of those, reinspecting unmodified
elements is useless (cannot discover new errors).

Alain

4 comments
Comment actions Permalink

No, if this is really so, it is a certain bug. Only modified
fields/classes/methods should be inspected?
A test case to reproduce please?

Eugene.

"Alain Ravet" <alain.ravet@biz.tiscali.be> wrote in message
news:d938m9$3rt$1@is.intellij.net...

If you modify only a single field, is there a way for a given inspection
to visit/inspect only this field, instead of all the methods and all the
class fields, like it does now?

>

Motivation: some inspections are very expensive (use findReferences():
50-100 ms/call), and for some of those, reinspecting unmodified
elements is useless (cannot discover new errors).

>

Alain



0
Comment actions Permalink

Eugene


>No, if this is really so, it is a certain bug. Only modified fields/classes/methods should be inspected?
>A test case to reproduce please?
>

>

(I could send full working project later, if still necessary)

In one inspection, I want to inspect all the members => the inspection
visitor captures visitClass, visitMethod, and visitField (see below).
Could that be the reason?

Thanks to the println in the code below, I clearly see in the console
that, after modifying a single field, all the fields, methods and the
class are visited.

public class AllMembersVisitor
extends PsiRecursiveElementVisitor
{

public final void visitField (PsiField field ) {
System.out.println ("* visitField (" + field.getName ());
doVisitMember (field);
}
public final void visitMethod (PsiMethod method) {
System.out.println ("** visitMethod(" + method.getName ());
doVisitMember (method);
}
public final void visitClass (PsiClass aClass) {
if (ClassUtils.isInnerClass(aClass))
return;
System.out.println ("*** visitClass(" + aClass.getName ());
doVisitMember (aClass);
}

private void doVisitMember (PsiMember i_member)
{
if(filter (i_member))
inspect (i_member);
}

protected boolean filter (PsiMember i_member) {
return true;
}

private void inspect (PsiMember i_member)
{
ProblemHandler problemHandler = this;
getElementInspector ().inspectAndReport (i_member,
problemHandler, getProblemInfo ());
}
..
}

0
Comment actions Permalink

Alain,
I was wrong:
Indeed in case you edit a field, the whole class gets reinspected due to possible non-local resolve targets changes. However if you edit inside the body of the method,
then only this method is inspected.


Eugene.
"Alain Ravet" <alain.ravet@biz.tiscali.be> wrote in message news:d93lni$mhn$1@is.intellij.net...
Eugene



No, if this is really so, it is a certain bug. Only modified fields/classes/methods should be inspected?
A test case to reproduce please?


(I could send full working project later, if still necessary)

In one inspection, I want to inspect all the members => the inspection visitor captures visitClass, visitMethod, and visitField (see below). Could that be the reason?

Thanks to the println in the code below, I clearly see in the console that, after modifying a single field, all the fields, methods and the class are visited.

public class AllMembersVisitor
extends PsiRecursiveElementVisitor
{

public final void visitField (PsiField field ) {
System.out.println ("* visitField (" + field.getName ());
doVisitMember (field);
}
public final void visitMethod (PsiMethod method) {
System.out.println ("** visitMethod(" + method.getName ());
doVisitMember (method);
}
public final void visitClass (PsiClass aClass) {
if (ClassUtils.isInnerClass(aClass))
return;
System.out.println ("*** visitClass(" + aClass.getName ());
doVisitMember (aClass);
}

private void doVisitMember (PsiMember i_member)
{
if(filter (i_member))
inspect (i_member);
}

protected boolean filter (PsiMember i_member) {
return true;
}

private void inspect (PsiMember i_member)
{
ProblemHandler problemHandler = this;
getElementInspector ().inspectAndReport (i_member, problemHandler, getProblemInfo ());
}
..
}

0
Comment actions Permalink

Eugene

Indeed in case you edit a field, the whole class gets reinspected due
to possible non-local resolve targets changes. However if you edit
inside the body of the method, then only this method is inspected.


When you say "the whole class", it's actually, visitClass + all
visitField + all visitMethod. That's a lot, especially if it's
absolutely not needed!
There should be a way for a given inspection to prevent this rippling
when it serves no purpose. It can make an inspection unusable in the
Highlighting errors set, because it's too slow.

Alain



0

Please sign in to leave a comment.