distinguish annotation interfaces in Ctrl-hover popup (IDEADEV-40633)
[fedora-idea.git] / java / idea-ui / src / com / intellij / jar / JarPackagingEditorPolicy.java
blobdb2aceaa4cb73e0005b6c05c6d4ebc91ec81436b
1 package com.intellij.jar;
3 import com.intellij.openapi.deployment.*;
4 import com.intellij.openapi.diagnostic.Logger;
5 import com.intellij.openapi.module.Module;
6 import com.intellij.openapi.module.StdModuleTypes;
7 import com.intellij.openapi.roots.ModuleRootManager;
8 import com.intellij.openapi.roots.libraries.Library;
9 import com.intellij.openapi.roots.ui.configuration.packaging.PackagingEditor;
10 import com.intellij.openapi.roots.ui.configuration.packaging.PackagingEditorPolicy;
11 import com.intellij.openapi.roots.ui.configuration.packaging.PackagingEditorUtil;
12 import org.jetbrains.annotations.NonNls;
13 import org.jetbrains.annotations.NotNull;
15 import java.util.List;
17 /**
18 * @author nik
20 public class JarPackagingEditorPolicy extends PackagingEditorPolicy {
21 private static final Logger LOG = Logger.getInstance("#com.intellij.jar.JarPackagingEditorPolicy");
22 @NonNls private static final String JAR_EXTENSION = ".jar";
23 private static final PackagingMethod[] COPY_OR_JAR_PACKAGING_METHODS = new PackagingMethod[]{
24 PackagingMethod.COPY_FILES,
25 PackagingMethod.JAR_AND_COPY_FILE,
26 PackagingMethod.JAR_AND_COPY_FILE_AND_LINK_VIA_MANIFEST
28 private static final PackagingMethod[] COPY_PACKAGING_METHODS = new PackagingMethod[]{
29 PackagingMethod.COPY_FILES,
30 PackagingMethod.COPY_FILES_AND_LINK_VIA_MANIFEST
33 public JarPackagingEditorPolicy(final @NotNull Module module) {
34 super(module);
37 protected PackagingMethod[] getAllowedPackagingMethodsForLibrary(LibraryLink libraryLink) {
38 return libraryLink.hasDirectoriesOnly() ? COPY_OR_JAR_PACKAGING_METHODS : COPY_PACKAGING_METHODS;
41 protected PackagingMethod[] getAllowedPackagingMethodsForModule(@NotNull Module module) {
42 if (StdModuleTypes.JAVA.equals(module.getModuleType())) {
43 return COPY_OR_JAR_PACKAGING_METHODS;
45 return PackagingMethod.EMPTY_ARRAY;
48 protected ContainerElement[] getModifiedElements(final PackagingEditor packagingEditor) {
49 return packagingEditor.getModifiedConfiguration().getElements();
52 protected PackagingMethod[] getPackagingMethodForUnresolvedElement(final ContainerElement element) {
53 return PackagingMethod.EMPTY_ARRAY;
56 public void setDefaultAttributes(ContainerElement element) {
57 if (element instanceof LibraryLink) {
58 element.setPackagingMethod(PackagingMethod.DO_NOT_PACKAGE);
60 if (element instanceof ModuleLink) {
61 PackagingMethod[] allowedDeploymentMethods = getAllowedPackagingMethods(element);
62 if (allowedDeploymentMethods.length < 1) {
63 LOG.error("illegal Packaging methods for " + element);
65 element.setPackagingMethod(allowedDeploymentMethods[0]);
67 element.setURI(suggestDefaultRelativePath(element));
70 public String suggestDefaultRelativePath(ContainerElement element) {
71 PackagingMethod packagingMethod = element.getPackagingMethod();
72 if (packagingMethod == PackagingMethod.DO_NOT_PACKAGE) return NOT_APPLICABLE;
73 boolean targetIsJar = packagingMethod == PackagingMethod.JAR_AND_COPY_FILE
74 || packagingMethod == PackagingMethod.JAR_AND_COPY_FILE_AND_LINK_VIA_MANIFEST;
75 String relativePath = "/";
76 if (targetIsJar && element instanceof ModuleLink) {
77 relativePath = DeploymentUtil.appendToPath(relativePath, element.getPresentableName());
78 if (!relativePath.endsWith(JAR_EXTENSION)) {
79 relativePath += JAR_EXTENSION;
82 return relativePath;
85 protected List<Module> getSuitableModules(final PackagingEditor packagingEditor) {
86 List<Module> moduleList = PackagingEditorUtil.getModulesFromDependentOrderEntries(ModuleRootManager.getInstance(getModule()));
87 moduleList.add(getModule());
88 return moduleList;
91 protected List<Library> getSuitableLibraries(final PackagingEditor packagingEditor) {
92 return PackagingEditorUtil.getLibrariesFromDependentOrderEntries(ModuleRootManager.getInstance(getModule()));