Create package from QuickFix

I am trying to create a package in a QuickFix, when a user has specified a package in an XML-attribute that doesn't exist.

The XML looks like this:
...snip...
<pages package="com.qpr.costcontrol.portal.page" >
...snip...

I have been able to make an inspection complain about a non-existent package, so I want to create it using a QuickFix. I though CreateClassOrPackageFix would be able to do that, but it fails.

My quickfix looks like this:
...snip...
    public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor problemDescriptor) {
        String path = attribute.getValue();
        CreateClassOrPackageFix classOrPackageFix = CreateClassOrPackageFix.createFix(path, problemDescriptor.getPsiElement(), null, null);
        classOrPackageFix.applyFix(project, problemDescriptor);
    }

...snip...

When I debug the above code, I see that the createFix method returns null, effectively crashing the next line with an NPE. Since I have the source for CreateClassOrPackageFix, I'm able to find out why it returns null:
...snip...
    final List<PsiDirectory> directories = getWritableDirectoryListDefault(basePackage, scope, context.getManager());
    if (directories.isEmpty()) {
      return null;
    }

...snip...

I am not sure why this returns null since I can't debug into that source. I am not sure either about the PsiElement parameter. Should that be preoblemDescriptor.getPsiElement?

Do you have any ideas? Or perhaps there is a better way to generate packages...

Cheers!

WarnerJan

1 comment
Comment actions Permalink

Hello WarnerJan,

Off the top of my head, I don't know what the problem is, but if you copy
the .class file from CE to UE jar, you should be able to debug the whole
thing.

I am trying to create a package in a QuickFix, when a user has
specified a package in an XML-attribute that doesn't exist.

The XML looks like this:
..snip...
<pages package="com.qpr.costcontrol.portal.page" >
..snip...
I have been able to make an inspection complain about a non-existent
package, so I want to create it using a QuickFix. I though
CreateClassOrPackageFix would be able to do that, but it fails.

My quickfix looks like this:
..snip...
public void applyFix(@NotNull Project project, @NotNull
ProblemDescriptor problemDescriptor) {
String path = attribute.getValue();
CreateClassOrPackageFix classOrPackageFix =
CreateClassOrPackageFix.createFix(path,
problemDescriptor.getPsiElement(), null, null);
classOrPackageFix.applyFix(project, problemDescriptor);
}
..snip...
When I debug the above code, I see that the createFix method returns
null, effectively crashing the next line with an NPE. Since I have the
source for CreateClassOrPackageFix, I'm able to find out why it
returns null:
..snip...
final List<PsiDirectory> directories =
getWritableDirectoryListDefault(basePackage, scope,
context.getManager());
if (directories.isEmpty()) {
return null;
}
..snip...
I am not sure why this returns null since I can't debug into that
source. I am not sure either about the PsiElement parameter. Should
that be preoblemDescriptor.getPsiElement?

Do you have any ideas? Or perhaps there is a better way to generate
packages...

Cheers!

WarnerJan

---
Original message URL:
http://www.jetbrains.net/devnet/message/5252459#5252459

--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


0

Please sign in to leave a comment.