problems with TreeClassChooserFactory dialogs

Hi,

I am trying to implement a dialog that allows the user to pick a class that implements an interface. I have something like:

    TreeClassChooserFactory factory = TreeClassChooserFactory.getInstance(project);
    final Module module = moduleSelector.getModule();
    GlobalSearchScope scope = null;
    if (module != null) {
      scope = GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module);
    } else {
      scope = GlobalSearchScope.allScope(project);
    }
    PsiClass listenerClass = JavaPsiFacade.getInstance(project).findClass(Map.class.getName(), scope);

    TreeClassChooser chooser = factory.createInheritanceClassChooser("Choose Listener", scope, listenerClass, null);
    chooser.showDialog();




Map here is java.util.Map. I put it there just to try some more common case. Generally it is a specific listener interface in my project.


What I get as a result shown in the dialog are the classes that I would expect to see (implementing the interface). But also some other classes/interfaces. These extra classes/interfaces are not associated to the base class given (here Map) in any way that I see.


For example, using the code above the dialog shows me a class in the project that extends nothing and implements nothing. In fact, it does not even import "java.util.Map" nor does it have the word "map" in the code anywhere.


Am I doing something wrong with this?


Also, I tried to set up a new plugin project to produce a bug report. My new plugin project keeps loading the old one (which I am actually developing). Is there some way I need to "reset" or clear the plugin development environment to load the environment for another plugin project?


Thanks,
Teemu
(And finally, why does this forum software lose any extra linebreaks I put in after copy-pasting some code in here? The text after the code is always a mess as above)
7 comments

Hello,

Could you provide a minimal but complete sample project which illustrates the problem and your plugin with instructions on how to use it?

Denis

P.S. You can use this plugin for pasting colors-aware code into forum.

0

Hi,

I made a bug report on it with id IDEA-107991. http://youtrack.jetbrains.com/issue/IDEA-107991

I attached what you requested on that. Can you take a look and tell me what is wrong?

Thanks,
Teemu

0

Just checked your files and here is what I see:

    1. It's expected to see classes which implement TransitionFilter interface there because TransitionFilter extends GenerationListener. That effectively makes every class which IS-A TransitionFilter also IS-A GenerationListener. You can provide custom ClassFilter into overloaded TreeClassChooserFactory.createInheritanceClassChooser() method and explicitly reject all classes which indirectly implement GenerationListener (that looks like a bad idea though);
    2. When osmotester jar is detached, no match against GenerationListener is found, that's why list of all classes is displayed;


Denis

0

Hi

Thanks for taking a look. I see it was my bad for not checking the inheritance tree.

So I guess if you create the chooser with the inheritanceXXX factory method, it is not a real filter like it is if you attach one yourself (like in the "classes" tab)? I thought it should not show anything if nothing was there to show. Also, if I changed it to a Map interface it showed me a strange choice, which I still do not quite understand. Not that it matters as I do not really plan to look for Map implementations and I guess I can try to filter the unwanted inheritance tree by creating my own filter. The custom filtering seems slower but I guess I have to look into the indexing API or something. The stuff could be a bit better documented.

Again, thanks for the help.
Teemu

0

Hi

I still have a similar issue but with the end condition chooser in the same project and with the same plugin.

Click the "..." on the right of "Test endcondition". You get the right choices but there is also stuff like "And (com.sun.org.apache.xpath.internal.operations)". I do not know if this is because there is also "And (osmo.tester.generator.endcondition.logical)" which is and should be in the list.

So, can you tell me what did I do wrong with that one?

At least I can't see how the Apache code would inherit my custom class..

associated code:

    TreeClassChooserFactory factory = TreeClassChooserFactory.getInstance(project);
    final Module module = moduleSelector.getModule();
    GlobalSearchScope scope = null;
    if (module != null) {
      scope = GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module);
    } else {
      scope = GlobalSearchScope.allScope(project);
    }
    PsiClass ecClass = JavaPsiFacade.getInstance(project).findClass(EndCondition.class.getName(), scope);
    PsiClass current = JavaPsiFacade.getInstance(project).findClass(ecField.getText(), scope);

    TreeClassChooser chooser = factory.createInheritanceClassChooser(title, scope, ecClass, current);
    chooser.showDialog();


Teemu

0

I don't have any classes from com.sun.org.apache.xpath.internal.operations package there:

tree.png
Btw, you can always debug the processing at local environment if the problem is stabily reproduced there.

Denis

0

OK, I guess you have somehow a different environment when you run it.

However, your screenshot shows two instances of EndCondition. osmo.tester.annotation.EndCondition and osmo.tester.generator.endcondition.EndCondition. So, if we use this as an example, the question is:

With the chooser code as follows:

import osmo.tester.generator.endcondition.EndCondition;

...

public class ECChoiceListener implements ActionListener {
....
    TreeClassChooserFactory factory = TreeClassChooserFactory.getInstance(project);
    GlobalSearchScope scope = GlobalSearchScope.allScope(project);
    PsiClass ecClass = JavaPsiFacade.getInstance(project).findClass(EndCondition.class.getName(), scope);
    PsiClass current = JavaPsiFacade.getInstance(project).findClass(ecField.getText(), scope);

    TreeClassChooser chooser = factory.createInheritanceClassChooser(title, scope, ecClass, current);
    chooser.showDialog();


and the two EndCondition classes as:


package osmo.tester.generator.endcondition;

public interface EndCondition {
...
}


package osmo.tester.annotation;

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface EndCondition {
}



Why is annotation version shown? Because it has the same name as one of the valid ones?
0

Please sign in to leave a comment.