Skip to content

Commit

Permalink
SdkTypeId extracted
Browse files Browse the repository at this point in the history
  • Loading branch information
yole committed May 17, 2012
1 parent 3e185ce commit b02e6fa
Show file tree
Hide file tree
Showing 25 changed files with 105 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ private static void fillSdks(List<GlobalLibrary> globals) {
}
final SdkAdditionalData data = sdk.getSdkAdditionalData();
final String additionalDataXml;
final SdkType sdkType = sdk.getSdkType();
final SdkType sdkType = (SdkType)sdk.getSdkType();
if (data == null) {
additionalDataXml = null;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* 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.
Expand All @@ -22,7 +22,7 @@
import com.intellij.openapi.project.ex.ProjectEx;
import com.intellij.openapi.projectRoots.JavaSdkType;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.projectRoots.SdkType;
import com.intellij.openapi.projectRoots.SdkTypeId;
import com.intellij.openapi.roots.OrderRootType;
import com.intellij.openapi.roots.ProjectRootManager;
import com.intellij.openapi.roots.libraries.LibraryTable;
Expand Down Expand Up @@ -137,7 +137,7 @@ protected void createJdkGenerators(final Project project) {
if (jdk.getHomeDirectory() == null) {
continue;
}
final SdkType sdkType = jdk.getSdkType();
final SdkTypeId sdkType = jdk.getSdkType();
if (!(sdkType instanceof JavaSdkType) || ((JavaSdkType)sdkType).getBinPath(jdk) == null) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* 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.
Expand Down Expand Up @@ -83,7 +83,7 @@ public boolean checkCompiler(final CompileScope scope) {
continue;
}
checkedJdks.add(jdk);
final SdkType sdkType = jdk.getSdkType();
final SdkTypeId sdkType = jdk.getSdkType();
if (!(sdkType instanceof JavaSdkType)) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ private static void fillSdks(List<GlobalLibrary> globals) {
}
final SdkAdditionalData data = sdk.getSdkAdditionalData();
final String additionalDataXml;
final SdkType sdkType = sdk.getSdkType();
final SdkType sdkType = (SdkType) sdk.getSdkType();
if (data == null) {
additionalDataXml = null;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* 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.
Expand All @@ -22,7 +22,7 @@
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.projectRoots.SdkAdditionalData;
import com.intellij.openapi.projectRoots.SdkModificator;
import com.intellij.openapi.projectRoots.SdkType;
import com.intellij.openapi.projectRoots.SdkTypeId;
import com.intellij.openapi.roots.RootProvider;
import com.intellij.openapi.util.Key;
import com.intellij.openapi.util.io.FileUtil;
Expand Down Expand Up @@ -56,7 +56,7 @@ public String getHomePath() {
}

@NotNull
public SdkType getSdkType() {
public SdkTypeId getSdkType() {
return myDelegate.getSdkType();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2011 JetBrains s.r.o.
* 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.
Expand All @@ -26,7 +26,7 @@
import com.intellij.openapi.projectRoots.JavaSdkType;
import com.intellij.openapi.projectRoots.JdkUtil;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.projectRoots.SdkType;
import com.intellij.openapi.projectRoots.SdkTypeId;
import com.intellij.openapi.util.Computable;

public class CommandLineBuilder {
Expand Down Expand Up @@ -70,7 +70,7 @@ public GeneralCommandLine compute() {
throw new CantRunException(ExecutionBundle.message("run.configuration.error.no.jdk.specified"));
}

final SdkType sdkType = jdk.getSdkType();
final SdkTypeId sdkType = jdk.getSdkType();
if (!(sdkType instanceof JavaSdkType)) {
throw new CantRunException(ExecutionBundle.message("run.configuration.error.no.jdk.specified"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,12 @@ public void actionPerformed(ActionEvent e) {
}

protected boolean showTabForType(OrderRootType type) {
return mySdk.getSdkType().isRootTypeApplicable(type);
return ((SdkType) mySdk.getSdkType()).isRootTypeApplicable(type);
}

private String getHomeFieldLabelValue() {
if (mySdk != null) {
return mySdk.getSdkType().getHomeFieldLabel();
return ((SdkType) mySdk.getSdkType()).getHomeFieldLabel();
}
return ProjectBundle.message("sdk.configure.general.home.path");
}
Expand Down Expand Up @@ -272,7 +272,7 @@ private void setHomePathValue(String absolutePath) {
final Color fg;
if (absolutePath != null && absolutePath.length() > 0) {
final File homeDir = new File(absolutePath);
boolean homeMustBeDirectory = mySdk == null || mySdk.getSdkType().getHomeChooserDescriptor().isChooseFolders();
boolean homeMustBeDirectory = mySdk == null || ((SdkType) mySdk.getSdkType()).getHomeChooserDescriptor().isChooseFolders();
fg = homeDir.exists() && (homeDir.isDirectory() == homeMustBeDirectory)
? UIUtil.getFieldForegroundColor()
: PathEditor.INVALID_COLOR;
Expand All @@ -284,7 +284,7 @@ private void setHomePathValue(String absolutePath) {
}

private void doSelectHomePath(){
final SdkType sdkType = mySdk.getSdkType();
final SdkType sdkType = (SdkType)mySdk.getSdkType();
SdkConfigurationUtil.selectSdkHome(sdkType, new Consumer<String>() {
@Override
public void consume(final String path) {
Expand Down Expand Up @@ -331,7 +331,7 @@ private void doSetHomePath(final String homePath, final SdkType sdkType) {

private String suggestSdkName(final String homePath) {
final String currentName = mySdk.getName();
final String suggestedName = mySdk.getSdkType().suggestSdkName(currentName , homePath);
final String suggestedName = ((SdkType) mySdk.getSdkType()).suggestSdkName(currentName , homePath);
if (Comparing.equal(currentName, suggestedName)) return currentName;
String newSdkName = suggestedName;
final Set<String> allNames = new HashSet<String>();
Expand Down Expand Up @@ -369,7 +369,7 @@ private AdditionalDataConfigurable getAdditionalDataConfigurable() {

@Nullable
private AdditionalDataConfigurable initAdditionalDataConfigurable(Sdk sdk) {
final SdkType sdkType = sdk.getSdkType();
final SdkType sdkType = (SdkType)sdk.getSdkType();
AdditionalDataConfigurable configurable = myAdditionalDataConfigurables.get(sdkType);
if (configurable == null) {
configurable = sdkType.createAdditionalDataConfigurable(mySdkModel, myEditedSdkModificator);
Expand All @@ -394,7 +394,7 @@ public String getHomePath() {
}

public void setHomePath(String path) {
doSetHomePath(path, mySdk.getSdkType());
doSetHomePath(path, (SdkType)mySdk.getSdkType());
}

public String getVersionString() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2011 JetBrains s.r.o.
* 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.
Expand All @@ -20,6 +20,7 @@
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectBundle;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.projectRoots.SdkType;
import com.intellij.openapi.roots.*;
import com.intellij.openapi.roots.impl.libraries.LibraryEx;
import com.intellij.openapi.roots.libraries.Library;
Expand Down Expand Up @@ -120,7 +121,7 @@ public CellAppearanceEx forJdk(@Nullable final Sdk jdk, final boolean isInComboB

String name = jdk.getName();
CompositeAppearance appearance = new CompositeAppearance();
appearance.setIcon(jdk.getSdkType().getIcon());
appearance.setIcon(((SdkType) jdk.getSdkType()).getIcon());
VirtualFile homeDirectory = jdk.getHomeDirectory();
SimpleTextAttributes attributes = getTextAttributes(homeDirectory != null && homeDirectory.isValid(), selected);
CompositeAppearance.DequeEnd ending = appearance.getEnding();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void doCustomize(JList list, Object value, int index, boolean selected, b
else if (value instanceof ProjectJdkComboBoxItem) {
final Sdk jdk = jdkModel.getProjectSdk();
if (jdk != null) {
setIcon(jdk.getSdkType().getIcon());
setIcon(((SdkType) jdk.getSdkType()).getIcon());
append(ProjectBundle.message("project.roots.project.jdk.inherited"), SimpleTextAttributes.REGULAR_ATTRIBUTES);
append(" (" + jdk.getName() + ")", SimpleTextAttributes.GRAYED_ATTRIBUTES);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* 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.
Expand All @@ -25,6 +25,7 @@
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory;
import com.intellij.openapi.project.ProjectBundle;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.projectRoots.SdkType;
import com.intellij.openapi.projectRoots.ui.SdkPathEditor;
import com.intellij.openapi.projectRoots.ui.Util;
import com.intellij.openapi.roots.JavadocOrderRootType;
Expand Down Expand Up @@ -85,7 +86,7 @@ public boolean isEnabled(AnActionEvent e) {
}

private void onSpecifyUrlButtonClicked() {
final String defaultDocsUrl = mySdk == null ? "" : StringUtil.notNullize(mySdk.getSdkType().getDefaultDocumentationUrl(mySdk), "");
final String defaultDocsUrl = mySdk == null ? "" : StringUtil.notNullize(((SdkType) mySdk.getSdkType()).getDefaultDocumentationUrl(mySdk), "");
VirtualFile virtualFile = Util.showSpecifyJavadocUrlDialog(myPanel, defaultDocsUrl);
if(virtualFile != null){
addElement(virtualFile);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* 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.
Expand Down Expand Up @@ -27,7 +27,7 @@
*/
public interface Sdk extends UserDataHolder {
@NotNull
SdkType getSdkType();
SdkTypeId getSdkType();

@NotNull
String getName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import java.util.Collections;
import java.util.List;

public abstract class SdkType {
public abstract class SdkType implements SdkTypeId {
public static ExtensionPointName<SdkType> EP_NAME = ExtensionPointName.create("com.intellij.sdkType");

private final String myName;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2011 JetBrains s.r.o.
* 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.
Expand All @@ -25,6 +25,8 @@
import com.intellij.openapi.module.ModuleUtil;
import com.intellij.openapi.project.IndexNotReadyException;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.projectRoots.SdkType;
import com.intellij.openapi.projectRoots.SdkTypeId;
import com.intellij.openapi.roots.JdkOrderEntry;
import com.intellij.openapi.roots.LibraryOrderEntry;
import com.intellij.openapi.roots.ModuleOrderEntry;
Expand Down Expand Up @@ -84,7 +86,10 @@ public Icon compute() {
catch (IndexNotReadyException e) {
return null;
}
if (object instanceof JdkOrderEntry) return ((JdkOrderEntry)object).getJdk().getSdkType().getIcon();
if (object instanceof JdkOrderEntry) {
final SdkTypeId sdkType = ((JdkOrderEntry)object).getJdk().getSdkType();
return ((SdkType) sdkType).getIcon();
}
if (object instanceof LibraryOrderEntry) return IconLoader.getIcon("/nodes/ppLibClosed.png");
if (object instanceof ModuleOrderEntry) return ModuleType.get(((ModuleOrderEntry)object).getModule()).getNodeIcon(false);
return null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* 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.
Expand All @@ -23,6 +23,7 @@
import com.intellij.ide.util.treeView.AbstractTreeNode;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.projectRoots.SdkType;
import com.intellij.openapi.roots.JdkOrderEntry;
import com.intellij.openapi.roots.LibraryOrderEntry;
import com.intellij.openapi.roots.OrderEntry;
Expand Down Expand Up @@ -62,11 +63,12 @@ public String getTestPresentation() {
}

private static Icon getJdkIcon(JdkOrderEntry entry, boolean isExpanded) {
final Sdk jdk = entry.getJdk();
if (jdk == null) {
final Sdk sdk = entry.getJdk();
if (sdk == null) {
return GENERIC_JDK_ICON;
}
return isExpanded? jdk.getSdkType().getIconForExpandedTreeNode() : jdk.getSdkType().getIcon();
final SdkType sdkType = (SdkType) sdk.getSdkType();
return isExpanded ? sdkType.getIconForExpandedTreeNode() : sdkType.getIcon();
}

public String getName() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import com.intellij.openapi.application.PathManager;
import com.intellij.openapi.components.*;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.fileTypes.StdFileTypes;
import com.intellij.openapi.fileTypes.FileTypes;
import com.intellij.openapi.project.ProjectBundle;
import com.intellij.openapi.projectRoots.JavaSdkType;
import com.intellij.openapi.projectRoots.ProjectJdkTable;
Expand Down Expand Up @@ -74,12 +74,12 @@ public void fileCreated(VirtualFileEvent event) {
}

private void updateJdks(VirtualFile file) {
if (file.isDirectory() || !StdFileTypes.ARCHIVE.equals(file.getFileType())) {
if (file.isDirectory() || !FileTypes.ARCHIVE.equals(file.getFileType())) {
// consider only archive files that may contain libraries
return;
}
for (Sdk sdk : mySdks) {
final SdkType sdkType = sdk.getSdkType();
final SdkType sdkType = (SdkType)sdk.getSdkType();
if (!(sdkType instanceof JavaSdkType)) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.intellij.openapi.projectRoots.impl;

import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.projectRoots.SdkType;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.ui.HtmlListCellRenderer;
import com.intellij.ui.SimpleTextAttributes;
Expand Down Expand Up @@ -63,6 +64,6 @@ protected void doCustomize(final JList list, final Sdk sdk, final int index, fin
}

protected Icon getSdkIcon(Sdk sdk) {
return sdk.getSdkType().getIcon();
return ((SdkType) sdk.getSdkType()).getIcon();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* 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.openapi.projectRoots;

/**
* @author yole
*/
public interface SdkTypeId {
String getName();
}
Loading

0 comments on commit b02e6fa

Please sign in to comment.