From 60b4a4cb15b4c8a453065f6c1e05497409129cdd Mon Sep 17 00:00:00 2001 From: nik Date: Wed, 18 Sep 2013 13:23:21 +0400 Subject: [PATCH] unnecessary intermediate class removed --- .../library/DownloadableLibraryType.java | 49 ++++++++++--- .../library/DownloadableLibraryTypeBase.java | 72 ------------------- 2 files changed, 40 insertions(+), 81 deletions(-) delete mode 100644 java/idea-ui/src/com/intellij/framework/library/DownloadableLibraryTypeBase.java diff --git a/java/idea-ui/src/com/intellij/framework/library/DownloadableLibraryType.java b/java/idea-ui/src/com/intellij/framework/library/DownloadableLibraryType.java index 0db89aa9dfc0..8d3d7cc4f6e0 100644 --- a/java/idea-ui/src/com/intellij/framework/library/DownloadableLibraryType.java +++ b/java/idea-ui/src/com/intellij/framework/library/DownloadableLibraryType.java @@ -16,9 +16,7 @@ package com.intellij.framework.library; import com.intellij.openapi.project.Project; -import com.intellij.openapi.roots.libraries.LibraryType; -import com.intellij.openapi.roots.libraries.NewLibraryConfiguration; -import com.intellij.openapi.roots.libraries.PersistentLibraryKind; +import com.intellij.openapi.roots.libraries.*; import com.intellij.openapi.roots.libraries.ui.LibraryEditorComponent; import com.intellij.openapi.roots.libraries.ui.LibraryPropertiesEditor; import com.intellij.openapi.util.text.StringUtil; @@ -27,19 +25,41 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import javax.swing.*; +import java.net.URL; +import java.util.List; /** * @author nik */ -public class DownloadableLibraryType extends LibraryType { +public abstract class DownloadableLibraryType extends LibraryType { + protected final Icon myIcon; private final String myLibraryCategoryName; private final DownloadableLibraryDescription myLibraryDescription; - public DownloadableLibraryType(@NotNull PersistentLibraryKind kind, @NotNull String libraryCategoryName, - @NotNull DownloadableLibraryDescription description) { - super(kind); + public DownloadableLibraryType(@NotNull String libraryCategoryName, + @NotNull String libraryTypeId, + @NotNull String groupId, + @NotNull Icon icon, + @NotNull URL... localUrls) { + super(new PersistentLibraryKind(libraryTypeId) { + @NotNull + @Override + public LibraryVersionProperties createDefaultProperties() { + return new LibraryVersionProperties(); + } + }); myLibraryCategoryName = libraryCategoryName; - myLibraryDescription = description; + myLibraryDescription = DownloadableLibraryService.getInstance().createLibraryDescription(groupId, localUrls); + myIcon = icon; + } + + @Nullable + private static LibraryVersionProperties detectVersion(List classesRoots, String detectionClass) { + if (!LibraryUtil.isClassAvailableInLibrary(classesRoots, detectionClass)) { + return null; + } + final String version = JarVersionDetectionUtil.detectJarVersion(detectionClass, classesRoots); + return new LibraryVersionProperties(version); } @Override @@ -74,8 +94,19 @@ public class DownloadableLibraryType extends LibraryType classesRoots) { + for (String className : getDetectionClassNames()) { + final LibraryVersionProperties versionProperties = detectVersion(classesRoots, className); + if (versionProperties != null) return versionProperties; + } return null; } } diff --git a/java/idea-ui/src/com/intellij/framework/library/DownloadableLibraryTypeBase.java b/java/idea-ui/src/com/intellij/framework/library/DownloadableLibraryTypeBase.java deleted file mode 100644 index a3b54aa69713..000000000000 --- a/java/idea-ui/src/com/intellij/framework/library/DownloadableLibraryTypeBase.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright 2000-2012 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.framework.library; - -import com.intellij.openapi.roots.libraries.JarVersionDetectionUtil; -import com.intellij.openapi.roots.libraries.LibraryUtil; -import com.intellij.openapi.roots.libraries.PersistentLibraryKind; -import com.intellij.openapi.vfs.VirtualFile; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import javax.swing.*; -import java.net.URL; -import java.util.List; - -public abstract class DownloadableLibraryTypeBase extends DownloadableLibraryType { - private final Icon myIcon; - - protected DownloadableLibraryTypeBase(@NotNull String libraryCategoryName, - @NotNull String libraryTypeId, - @NotNull String groupId, - @NotNull Icon icon, - @NotNull URL... localUrls) { - super(new PersistentLibraryKind(libraryTypeId) { - @NotNull - @Override - public LibraryVersionProperties createDefaultProperties() { - return new LibraryVersionProperties(); - } - }, libraryCategoryName, - DownloadableLibraryService.getInstance().createLibraryDescription(groupId, localUrls)); - myIcon = icon; - } - - public Icon getIcon() { - return myIcon; - } - - protected abstract String[] getDetectionClassNames(); - - @Override - public LibraryVersionProperties detect(@NotNull List classesRoots) { - for (String className : getDetectionClassNames()) { - - final LibraryVersionProperties versionProperties = detectVersion(classesRoots, className); - if (versionProperties != null) return versionProperties; - } - return null; - } - - @Nullable - private static LibraryVersionProperties detectVersion(List classesRoots, String detectionClass) { - if (!LibraryUtil.isClassAvailableInLibrary(classesRoots, detectionClass)) { - return null; - } - final String version = JarVersionDetectionUtil.detectJarVersion(detectionClass, classesRoots); - return new LibraryVersionProperties(version); - } -}