unnecessary intermediate class removed

This commit is contained in:
nik
2013-09-18 14:30:37 +04:00
parent fdec7af717
commit 60b4a4cb15
2 changed files with 40 additions and 81 deletions
@@ -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<LibraryVersionProperties> {
public abstract class DownloadableLibraryType extends LibraryType<LibraryVersionProperties> {
protected final Icon myIcon;
private final String myLibraryCategoryName;
private final DownloadableLibraryDescription myLibraryDescription;
public DownloadableLibraryType(@NotNull PersistentLibraryKind<LibraryVersionProperties> 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<LibraryVersionProperties>(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<VirtualFile> 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<LibraryVersionPropertie
return DownloadableLibraryService.getInstance().createDownloadableLibraryEditor(myLibraryDescription, editorComponent, this);
}
@Override
@NotNull
public Icon getIcon() {
return myIcon;
}
protected abstract String[] getDetectionClassNames();
@Override
public LibraryVersionProperties detect(@NotNull List<VirtualFile> classesRoots) {
for (String className : getDetectionClassNames()) {
final LibraryVersionProperties versionProperties = detectVersion(classesRoots, className);
if (versionProperties != null) return versionProperties;
}
return 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<LibraryVersionProperties>(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<VirtualFile> classesRoots) {
for (String className : getDetectionClassNames()) {
final LibraryVersionProperties versionProperties = detectVersion(classesRoots, className);
if (versionProperties != null) return versionProperties;
}
return null;
}
@Nullable
private static LibraryVersionProperties detectVersion(List<VirtualFile> classesRoots, String detectionClass) {
if (!LibraryUtil.isClassAvailableInLibrary(classesRoots, detectionClass)) {
return null;
}
final String version = JarVersionDetectionUtil.detectJarVersion(detectionClass, classesRoots);
return new LibraryVersionProperties(version);
}
}