use of com.intellij.codeInsight.AttachSourcesProvider in project intellij-community by JetBrains.
the class AttachSourcesNotificationProvider method createNotificationPanel.
@Override
public EditorNotificationPanel createNotificationPanel(@NotNull final VirtualFile file, @NotNull FileEditor fileEditor) {
if (file.getFileType() != JavaClassFileType.INSTANCE)
return null;
final EditorNotificationPanel panel = new EditorNotificationPanel();
String text = ProjectBundle.message("class.file.decompiled.text");
String classInfo = getClassFileInfo(file);
if (classInfo != null)
text += ", " + classInfo;
panel.setText(text);
final VirtualFile sourceFile = JavaEditorFileSwapper.findSourceFile(myProject, file);
if (sourceFile == null) {
final List<LibraryOrderEntry> libraries = findLibraryEntriesForFile(file);
if (libraries != null) {
List<AttachSourcesProvider.AttachSourcesAction> actions = new ArrayList<>();
PsiFile clsFile = PsiManager.getInstance(myProject).findFile(file);
boolean hasNonLightAction = false;
for (AttachSourcesProvider each : Extensions.getExtensions(EXTENSION_POINT_NAME)) {
for (AttachSourcesProvider.AttachSourcesAction action : each.getActions(libraries, clsFile)) {
if (hasNonLightAction) {
if (action instanceof AttachSourcesProvider.LightAttachSourcesAction) {
// Don't add LightAttachSourcesAction if non light action exists.
continue;
}
} else {
if (!(action instanceof AttachSourcesProvider.LightAttachSourcesAction)) {
// All previous actions is LightAttachSourcesAction and should be removed.
actions.clear();
hasNonLightAction = true;
}
}
actions.add(action);
}
}
Collections.sort(actions, (o1, o2) -> o1.getName().compareToIgnoreCase(o2.getName()));
AttachSourcesProvider.AttachSourcesAction defaultAction;
if (findSourceFileInSameJar(file) != null) {
defaultAction = new AttachJarAsSourcesAction(file);
} else {
defaultAction = new ChooseAndAttachSourcesAction(myProject, panel);
}
actions.add(defaultAction);
for (final AttachSourcesProvider.AttachSourcesAction action : actions) {
panel.createActionLabel(GuiUtils.getTextWithoutMnemonicEscaping(action.getName()), () -> {
List<LibraryOrderEntry> entries = findLibraryEntriesForFile(file);
if (!Comparing.equal(libraries, entries)) {
Messages.showErrorDialog(myProject, "Can't find library for " + file.getName(), "Error");
return;
}
panel.setText(action.getBusyText());
action.perform(entries);
});
}
}
} else {
panel.createActionLabel(ProjectBundle.message("class.file.open.source.action"), () -> {
OpenFileDescriptor descriptor = new OpenFileDescriptor(myProject, sourceFile);
FileEditorManager.getInstance(myProject).openTextEditor(descriptor, true);
});
}
return panel;
}
Aggregations