Merge remote-tracking branch 'origin/master'

This commit is contained in:
Vladimir.Orlov
2014-11-06 17:11:58 +03:00
30 changed files with 473 additions and 328 deletions
@@ -420,7 +420,7 @@ public class JavaMatchingVisitor extends JavaElementVisitor {
(elements2 != null) ? elements2.getReferenceElements() : PsiElement.EMPTY_ARRAY
);
}
private boolean compareClasses(final PsiClass clazz, final PsiClass clazz2) {
final PsiClass saveClazz = this.myClazz;
final MatchContext.MatchedElementsListener oldListener = myMatchingVisitor.getMatchContext().getMatchedElementsListener();
@@ -838,6 +838,7 @@ public class JavaMatchingVisitor extends JavaElementVisitor {
String text2;
if (el2 instanceof PsiClass) {
text2 = ((PsiClass)el2).getQualifiedName();
if (text2 == null) text2 = el2.getText();
} else {
text2 = el2.getText();
}
@@ -246,20 +246,24 @@ public class BuildDataManager implements StorageOwner {
finally {
try {
closeSourceToOutputStorages();
myOutputToTargetRegistry.close();
}
finally {
try {
closeStorage(mySrcToFormMap);
myOutputToTargetRegistry.close();
}
finally {
final Mappings mappings = myMappings;
if (mappings != null) {
try {
mappings.close();
}
catch (BuildDataCorruptedException e) {
throw e.getCause();
try {
closeStorage(mySrcToFormMap);
}
finally {
final Mappings mappings = myMappings;
if (mappings != null) {
try {
mappings.close();
}
catch (BuildDataCorruptedException e) {
throw e.getCause();
}
}
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
* Copyright 2000-2014 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.
@@ -18,6 +18,7 @@ package org.jetbrains.jps.model.java.impl;
import com.intellij.openapi.util.SystemInfo;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.File;
@@ -30,11 +31,11 @@ import java.util.Set;
* @author nik
*/
public class JavaSdkUtil {
public static List<File> getJdkClassesRoots(File home, boolean isJre) {
@NotNull
public static List<File> getJdkClassesRoots(@NotNull File home, boolean isJre) {
FileFilter jarFileFilter = new FileFilter() {
@Override
@SuppressWarnings({"HardCodedStringLiteral"})
public boolean accept(File f) {
public boolean accept(@NotNull File f) {
return !f.isDirectory() && f.getName().endsWith(".jar");
}
};
@@ -23,7 +23,8 @@ import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.Result;
import com.intellij.openapi.application.WriteAction;
import com.intellij.openapi.command.WriteCommandAction;
import com.intellij.openapi.compiler.*;
import com.intellij.openapi.compiler.CompileScope;
import com.intellij.openapi.compiler.CompilerMessage;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleManager;
import com.intellij.openapi.module.ModuleType;
@@ -32,8 +33,12 @@ import com.intellij.openapi.project.Project;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.projectRoots.impl.JavaAwareProjectJdkTableImpl;
import com.intellij.openapi.roots.ModuleRootModificationUtil;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.SystemInfo;
import com.intellij.openapi.util.io.ByteSequence;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.io.FileUtilRt;
import com.intellij.openapi.vfs.JarFileSystem;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VfsUtilCore;
import com.intellij.openapi.vfs.VirtualFile;
@@ -50,12 +55,15 @@ import org.junit.After;
import org.junit.Before;
import java.awt.*;
import java.io.File;
import java.io.IOException;
import java.io.*;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.*;
import java.util.List;
import java.util.jar.Attributes;
import java.util.jar.JarEntry;
import java.util.jar.JarOutputStream;
import java.util.jar.Manifest;
/**
* @author Vladislav.Soroka
@@ -337,6 +345,39 @@ public abstract class ExternalSystemTestCase extends UsefulTestCase {
return LocalFileSystem.getInstance().refreshAndFindFileByIoFile(f);
}
@NotNull
protected VirtualFile createProjectJarSubFile(String relativePath, Pair<ByteSequence, String>... contentEntries) throws IOException {
assertTrue("Use 'jar' extension for JAR files: '" + relativePath + "'", FileUtilRt.extensionEquals(relativePath, "jar"));
File f = new File(getProjectPath(), relativePath);
FileUtil.ensureExists(f.getParentFile());
FileUtil.ensureCanCreateFile(f);
final boolean created = f.createNewFile();
if (!created) {
throw new AssertionError("Unable to create the project sub file: " + f.getAbsolutePath());
}
Manifest manifest = new Manifest();
manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
JarOutputStream target = new JarOutputStream(new FileOutputStream(f), manifest);
for (Pair<ByteSequence, String> contentEntry : contentEntries) {
addJarEntry(contentEntry.first.getBytes(), contentEntry.second, target);
}
target.close();
final VirtualFile virtualFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(f);
assertNotNull(virtualFile);
final VirtualFile jarFile = JarFileSystem.getInstance().getJarRootForLocalFile(virtualFile);
assertNotNull(jarFile);
return jarFile;
}
private static void addJarEntry(byte[] bytes, String path, JarOutputStream target) throws IOException {
JarEntry entry = new JarEntry(path.replace("\\", "/"));
target.putNextEntry(entry);
target.write(bytes);
target.close();
}
protected VirtualFile createProjectSubFile(String relativePath, String content) throws IOException {
VirtualFile file = createProjectSubFile(relativePath);
setFileContent(file, content, false);
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
* Copyright 2000-2014 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.
@@ -25,7 +25,6 @@ import com.intellij.execution.configurations.SimpleJavaParameters;
import com.intellij.ide.util.PropertiesComponent;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.text.StringUtilRt;
import com.intellij.openapi.vfs.CharsetToolkit;
@@ -61,16 +60,10 @@ public class JdkUtil {
VirtualFile homeDirectory = jdk.getHomeDirectory();
if (homeDirectory == null) return null;
VirtualFile rtJar = homeDirectory.findFileByRelativePath("jre/lib/rt.jar");
if (rtJar == null) {
rtJar = homeDirectory.findFileByRelativePath("lib/rt.jar");
}
if (rtJar == null) {
rtJar = homeDirectory.findFileByRelativePath("jre/lib/vm.jar"); // for IBM jdk
}
if (rtJar == null) {
rtJar = homeDirectory.findFileByRelativePath("../Classes/classes.jar"); // for mac
}
VirtualFile rtJar = homeDirectory.findFileByRelativePath("jre/lib/rt.jar"); // JDK
if (rtJar == null) rtJar = homeDirectory.findFileByRelativePath("lib/rt.jar"); // JRE
if (rtJar == null) rtJar = homeDirectory.findFileByRelativePath("jre/lib/vm.jar"); // IBM JDK
if (rtJar == null) rtJar = homeDirectory.findFileByRelativePath("../Classes/classes.jar"); // Apple JDK
if (rtJar == null) {
String versionString = jdk.getVersionString();
@@ -107,17 +100,16 @@ public class JdkUtil {
return null;
}
public static boolean checkForJdk(final File homePath) {
public static boolean checkForJdk(@NotNull File homePath) {
File binPath = new File(homePath.getAbsolutePath() + File.separator + "bin");
if (!binPath.exists()) return false;
FileFilter fileFilter = new FileFilter() {
@Override
@SuppressWarnings({"HardCodedStringLiteral"})
public boolean accept(File f) {
public boolean accept(@NotNull File f) {
if (f.isDirectory()) return false;
return Comparing.strEqual(FileUtil.getNameWithoutExtension(f), "javac") ||
Comparing.strEqual(FileUtil.getNameWithoutExtension(f), "javah");
String name = FileUtil.getNameWithoutExtension(f);
return "javac".equals(name) || "javah".equals(name);
}
};
File[] children = binPath.listFiles(fileFilter);
@@ -126,16 +118,15 @@ public class JdkUtil {
checkForRuntime(homePath.getAbsolutePath());
}
public static boolean checkForJre(String homePath) {
public static boolean checkForJre(@NotNull String homePath) {
homePath = new File(FileUtil.toSystemDependentName(homePath)).getAbsolutePath();
File binPath = new File(homePath + File.separator + "bin");
if (!binPath.exists()) return false;
FileFilter fileFilter = new FileFilter() {
@Override
@SuppressWarnings({"HardCodedStringLiteral"})
public boolean accept(File f) {
return !f.isDirectory() && Comparing.strEqual(FileUtil.getNameWithoutExtension(f), "java");
public boolean accept(@NotNull File f) {
return !f.isDirectory() && "java".equals(FileUtil.getNameWithoutExtension(f));
}
};
File[] children = binPath.listFiles(fileFilter);
@@ -144,12 +135,12 @@ public class JdkUtil {
checkForRuntime(homePath);
}
public static boolean checkForRuntime(final String homePath) {
return new File(new File(new File(homePath, "jre"), "lib"), "rt.jar").exists() ||
new File(new File(homePath, "lib"), "rt.jar").exists() ||
new File(new File(new File(homePath, ".."), "Classes"), "classes.jar").exists() || // Apple JDK
new File(new File(new File(homePath, "jre"), "lib"), "vm.jar").exists() || // IBM JDK
new File(homePath, "classes").isDirectory(); // custom build
public static boolean checkForRuntime(@NotNull String homePath) {
return new File(homePath, "jre/lib/rt.jar").exists() || // JDK
new File(homePath, "lib/rt.jar").exists() || // JRE
new File(homePath, "../Classes/classes.jar").exists() || // Apple JDK
new File(homePath, "jre/lib/vm.jar").exists() || // IBM JDK
new File(homePath, "classes").isDirectory(); // custom build
}
public static GeneralCommandLine setupJVMCommandLine(final String exePath,
@@ -258,7 +249,7 @@ public class JdkUtil {
commandLine.addParameters(javaParameters.getProgramParametersList().getList());
commandLine.setWorkDirectory(javaParameters.getWorkingDirectory());
commandLine.withWorkDirectory(javaParameters.getWorkingDirectory());
return commandLine;
}
@@ -275,24 +266,24 @@ public class JdkUtil {
}
private static void appendEncoding(SimpleJavaParameters javaParameters, GeneralCommandLine commandLine, ParametersList parametersList) {
// Value of -Dfile.encoding and charset of GeneralCommandLine should be in sync in order process's input and output be correctly handled.
// Value of file.encoding and charset of GeneralCommandLine should be in sync in order process's input and output be correctly handled.
String encoding = parametersList.getPropertyValue("file.encoding");
if (encoding == null) {
Charset charset = javaParameters.getCharset();
if (charset == null) charset = EncodingManager.getInstance().getDefaultCharset();
if (charset == null) charset = CharsetToolkit.getDefaultSystemCharset();
commandLine.addParameter("-Dfile.encoding=" + charset.name());
commandLine.setCharset(charset);
if (charset != null) {
commandLine.addParameter("-Dfile.encoding=" + charset.name());
commandLine.withCharset(charset);
}
}
else {
try {
Charset charset = Charset.forName(encoding);
commandLine.setCharset(charset);
}
catch (UnsupportedCharsetException ignore) {
}
catch (IllegalCharsetNameException ignore) {
commandLine.withCharset(charset);
}
catch (UnsupportedCharsetException ignore) { }
catch (IllegalCharsetNameException ignore) { }
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
* Copyright 2000-2014 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.
@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.openapi.roots.ui.configuration.projectRoot;
import com.intellij.openapi.actionSystem.AnAction;
@@ -36,14 +35,15 @@ import com.intellij.openapi.util.Condition;
import com.intellij.util.ArrayUtilRt;
import com.intellij.util.Consumer;
import com.intellij.util.EventDispatcher;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import java.util.*;
/**
* User: anna
* Date: 05-Jun-2006
* @author anna
* @since 05-Jun-2006
*/
public class ProjectSdksModel implements SdkModel {
private static final Logger LOG = Logger.getInstance("com.intellij.openapi.roots.ui.configuration.projectRoot.ProjectSdksModel");
@@ -116,7 +116,7 @@ public class ProjectSdksModel implements SdkModel {
return myProjectSdks;
}
public boolean isModified(){
public boolean isModified() {
return myModified;
}
@@ -201,7 +201,7 @@ public class ProjectSdksModel implements SdkModel {
final SdkAdditionalData sdkAdditionalData = currItem.getSdkAdditionalData();
if (sdkAdditionalData instanceof ValidatableSdkAdditionalData) {
try {
((ValidatableSdkAdditionalData) sdkAdditionalData).checkValid(this);
((ValidatableSdkAdditionalData)sdkAdditionalData).checkValid(this);
}
catch (ConfigurationException e) {
if (rootConfigurable != null) {
@@ -249,14 +249,12 @@ public class ProjectSdksModel implements SdkModel {
final SdkType[] types = SdkType.getAllTypes();
for (final SdkType type : types) {
if (filter != null && !filter.value(type)) continue;
final AnAction addAction = new DumbAwareAction(type.getPresentableName(),
null,
type.getIconForAddAction()) {
@Override
public void actionPerformed(AnActionEvent e) {
doAdd(parent, type, updateTree);
}
};
final AnAction addAction = new DumbAwareAction(type.getPresentableName(), null, type.getIconForAddAction()) {
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
doAdd(parent, type, updateTree);
}
};
group.add(addAction);
}
}
@@ -290,8 +288,8 @@ public class ProjectSdksModel implements SdkModel {
if (!sdkType.setupSdkPaths(newJdk, this)) return;
if (newJdk.getVersionString() == null) {
Messages.showMessageDialog(ProjectBundle.message("sdk.java.corrupt.error", home),
ProjectBundle.message("sdk.java.corrupt.title"), Messages.getErrorIcon());
String message = ProjectBundle.message("sdk.java.corrupt.error", home);
Messages.showMessageDialog(message, ProjectBundle.message("sdk.java.corrupt.title"), Messages.getErrorIcon());
}
doAdd(newJdk, callback);
@@ -49,7 +49,7 @@ import java.util.List;
public class OpenFileAction extends AnAction implements DumbAware {
@Override
public void actionPerformed(AnActionEvent e) {
public void actionPerformed(@NotNull AnActionEvent e) {
final Project project = e.getProject();
final boolean showFiles = project != null || PlatformProjectOpenProcessor.getInstanceIfItExists() != null;
final FileChooserDescriptor descriptor = showFiles ? new ProjectOrFileChooserDescriptor() : new ProjectOnlyFileChooserDescriptor();
@@ -141,7 +141,7 @@ public class OpenFileAction extends AnAction implements DumbAware {
}
}
// vanilla OpenProjectFileChooserDescriptor only accepts project files; this on is overridden to accept any files
// vanilla OpenProjectFileChooserDescriptor only accepts project files; this one is overridden to accept any files
private static class ProjectOrFileChooserDescriptor extends OpenProjectFileChooserDescriptor {
private final FileChooserDescriptor myStandardDescriptor = FileChooserDescriptorFactory.createSingleFileNoJarsDescriptor();
@@ -157,7 +157,7 @@ public class OpenFileAction extends AnAction implements DumbAware {
@Override
public boolean isFileSelectable(VirtualFile file) {
return file.isDirectory() ? super.isFileSelectable(file) : myStandardDescriptor.isFileSelectable(file);
return file.isDirectory() ? super.isFileSelectable(file) : myStandardDescriptor.isFileSelectable(file);
}
@Override
+2 -14
View File
@@ -250,23 +250,11 @@ public class JBColor extends Color {
public static final Color CYAN = cyan;
public static Color foreground() {
return new JBColor(new NotNullProducer<Color>() {
@NotNull
@Override
public Color produce() {
return UIUtil.getLabelForeground();
}
});
return UIUtil.getLabelForeground();
}
public static Color background() {
return new JBColor(new NotNullProducer<Color>() {
@NotNull
@Override
public Color produce() {
return UIUtil.getListBackground();
}
});
return UIUtil.getListBackground();
}
public static Color border() {
@@ -680,11 +680,11 @@ public class UIUtil {
}
public static Color getLabelBackground() {
return UIManager.getColor("Label.background");
return getColor("Label.background");
}
public static Color getLabelForeground() {
return UIManager.getColor("Label.foreground");
return getColor("Label.foreground");
}
public static Color getLabelDisabledForeground() {
@@ -734,11 +734,11 @@ public class UIUtil {
}
public static Color getTableHeaderBackground() {
return UIManager.getColor("TableHeader.background");
return getColor("TableHeader.background");
}
public static Color getTreeTextForeground() {
return UIManager.getColor("Tree.textForeground");
return getColor("Tree.textForeground");
}
public static Color getTreeSelectionBackground() {
@@ -748,23 +748,22 @@ public class UIUtil {
color = UIManager.getColor("nimbusSelectionBackground");
if (color != null) return color;
}
return UIManager.getColor("Tree.selectionBackground");
return getColor("Tree.selectionBackground");
}
public static Color getTreeTextBackground() {
return UIManager.getColor("Tree.textBackground");
return getColor("Tree.textBackground");
}
public static Color getListSelectionForeground() {
final Color color = UIManager.getColor("List.selectionForeground");
if (color == null) {
if (isUnderNimbusLookAndFeel()) {
return UIManager.getColor("List[Selected].textForeground"); // Nimbus
}
return color;
return getColor("List.selectionForeground");
}
public static Color getFieldForegroundColor() {
return UIManager.getColor("field.foreground");
return getColor("field.foreground");
}
public static Color getTableSelectionBackground() {
@@ -774,11 +773,23 @@ public class UIUtil {
color = UIManager.getColor("nimbusSelectionBackground");
if (color != null) return color;
}
return UIManager.getColor("Table.selectionBackground");
return getColor("Table.selectionBackground");
}
public static Color getActiveTextColor() {
return UIManager.getColor("textActiveText");
return getColor("textActiveText");
}
@NotNull
private static Color getColor(final String property) {
return new JBColor(new NotNullProducer<Color>() {
@NotNull
@Override
public Color produce() {
final Color color = UIManager.getColor(property);
return color == null ? Gray.TRANSPARENT : color;
}
});
}
public static Color getInactiveTextColor() {
@@ -798,7 +809,7 @@ public class UIUtil {
}
public static Color getInactiveTextFieldBackgroundColor() {
return UIManager.getColor("TextField.inactiveBackground");
return getColor("TextField.inactiveBackground");
}
public static Font getTreeFont() {
@@ -810,7 +821,7 @@ public class UIUtil {
}
public static Color getTreeSelectionForeground() {
return UIManager.getColor("Tree.selectionForeground");
return getColor("Tree.selectionForeground");
}
/**
@@ -829,7 +840,7 @@ public class UIUtil {
}
public static Color getTreeSelectionBorderColor() {
return UIManager.getColor("Tree.selectionBorderColor");
return getColor("Tree.selectionBorderColor");
}
public static int getTreeRightChildIndent() {
@@ -841,23 +852,23 @@ public class UIUtil {
}
public static Color getToolTipBackground() {
return UIManager.getColor("ToolTip.background");
return getColor("ToolTip.background");
}
public static Color getToolTipForeground() {
return UIManager.getColor("ToolTip.foreground");
return getColor("ToolTip.foreground");
}
public static Color getComboBoxDisabledForeground() {
return UIManager.getColor("ComboBox.disabledForeground");
return getColor("ComboBox.disabledForeground");
}
public static Color getComboBoxDisabledBackground() {
return UIManager.getColor("ComboBox.disabledBackground");
return getColor("ComboBox.disabledBackground");
}
public static Color getButtonSelectColor() {
return UIManager.getColor("Button.select");
return getColor("Button.select");
}
public static Integer getPropertyMaxGutterIconWidth(final String propertyPrefix) {
@@ -865,7 +876,7 @@ public class UIUtil {
}
public static Color getMenuItemDisabledForeground() {
return UIManager.getColor("MenuItem.disabledForeground");
return getColor("MenuItem.disabledForeground");
}
public static Object getMenuItemDisabledForegroundObject() {
@@ -882,7 +893,7 @@ public class UIUtil {
public static Color getTableBackground() {
// Under GTK+ L&F "Table.background" often has main panel color, which looks ugly
return isUnderGTKLookAndFeel() ? getTreeTextBackground() : UIManager.getColor("Table.background");
return isUnderGTKLookAndFeel() ? getTreeTextBackground() : getColor("Table.background");
}
public static Color getTableBackground(final boolean isSelected) {
@@ -893,11 +904,11 @@ public class UIUtil {
if (isUnderNimbusLookAndFeel()) {
return UIManager.getColor("Table[Enabled+Selected].textForeground");
}
return UIManager.getColor("Table.selectionForeground");
return getColor("Table.selectionForeground");
}
public static Color getTableForeground() {
return UIManager.getColor("Table.foreground");
return getColor("Table.foreground");
}
public static Color getTableForeground(final boolean isSelected) {
@@ -905,7 +916,7 @@ public class UIUtil {
}
public static Color getTableGridColor() {
return UIManager.getColor("Table.gridColor");
return getColor("Table.gridColor");
}
public static Color getListBackground() {
@@ -915,7 +926,7 @@ public class UIUtil {
return new Color(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha());
}
// Under GTK+ L&F "Table.background" often has main panel color, which looks ugly
return isUnderGTKLookAndFeel() ? getTreeTextBackground() : UIManager.getColor("List.background");
return isUnderGTKLookAndFeel() ? getTreeTextBackground() : getColor("List.background");
}
public static Color getListBackground(boolean isSelected) {
@@ -923,7 +934,7 @@ public class UIUtil {
}
public static Color getListForeground() {
return UIManager.getColor("List.foreground");
return getColor("List.foreground");
}
public static Color getListForeground(boolean isSelected) {
@@ -931,26 +942,26 @@ public class UIUtil {
}
public static Color getPanelBackground() {
return UIManager.getColor("Panel.background");
return getColor("Panel.background");
}
public static Color getTreeBackground() {
return UIManager.getColor("Tree.background");
return getColor("Tree.background");
}
public static Color getTreeForeground() {
return UIManager.getColor("Tree.foreground");
return getColor("Tree.foreground");
}
public static Color getTableFocusCellBackground() {
return UIManager.getColor(TABLE_FOCUS_CELL_BACKGROUND_PROPERTY);
return getColor(TABLE_FOCUS_CELL_BACKGROUND_PROPERTY);
}
public static Color getListSelectionBackground() {
if (isUnderNimbusLookAndFeel()) {
return UIManager.getColor("List[Selected].textBackground"); // Nimbus
}
return UIManager.getColor("List.selectionBackground");
return getColor("List.selectionBackground");
}
public static Color getListUnfocusedSelectionBackground() {
@@ -967,11 +978,11 @@ public class UIUtil {
}
public static Color getTextFieldForeground() {
return UIManager.getColor("TextField.foreground");
return getColor("TextField.foreground");
}
public static Color getTextFieldBackground() {
return isUnderGTKLookAndFeel() ? UIManager.getColor("EditorPane.background") : UIManager.getColor("TextField.background");
return isUnderGTKLookAndFeel() ? UIManager.getColor("EditorPane.background") : getColor("TextField.background");
}
public static Font getButtonFont() {
@@ -983,7 +994,7 @@ public class UIUtil {
}
public static Color getTabbedPaneBackground() {
return UIManager.getColor("TabbedPane.background");
return getColor("TabbedPane.background");
}
public static void setSliderIsFilled(final JSlider slider, final boolean value) {
@@ -991,11 +1002,11 @@ public class UIUtil {
}
public static Color getLabelTextForeground() {
return UIManager.getColor("Label.textForeground");
return getColor("Label.textForeground");
}
public static Color getControlColor() {
return UIManager.getColor("control");
return getColor("control");
}
public static Font getOptionPaneMessageFont() {
@@ -1007,19 +1018,19 @@ public class UIUtil {
}
public static Color getSeparatorForeground() {
return UIManager.getColor("Separator.foreground");
return getColor("Separator.foreground");
}
public static Color getSeparatorBackground() {
return UIManager.getColor("Separator.background");
return getColor("Separator.background");
}
public static Color getSeparatorShadow() {
return UIManager.getColor("Separator.shadow");
return getColor("Separator.shadow");
}
public static Color getSeparatorHighlight() {
return UIManager.getColor("Separator.highlight");
return getColor("Separator.highlight");
}
public static Color getSeparatorColorUnderNimbus() {
@@ -1054,7 +1065,7 @@ public class UIUtil {
}
public static Color getTableFocusCellForeground() {
return UIManager.getColor("Table.focusCellForeground");
return getColor("Table.focusCellForeground");
}
/**
@@ -1149,15 +1160,15 @@ public class UIUtil {
}
public static Color getWindowColor() {
return UIManager.getColor("window");
return getColor("window");
}
public static Color getTextAreaForeground() {
return UIManager.getColor("TextArea.foreground");
return getColor("TextArea.foreground");
}
public static Color getOptionPaneBackground() {
return UIManager.getColor("OptionPane.background");
return getColor("OptionPane.background");
}
@SuppressWarnings({"HardCodedStringLiteral"})
@@ -142,7 +142,7 @@ public abstract class XDebuggerEditorBase {
public abstract JComponent getComponent();
protected abstract void setEditorText(XExpression text);
protected abstract void doSetText(XExpression text);
public void setExpression(@Nullable XExpression text) {
if (text == null) {
@@ -174,7 +174,7 @@ public abstract class XDebuggerEditorBase {
myChooseFactory.setDisabledIcon(IconLoader.getDisabledIcon(icon));
}
setEditorText(text);
doSetText(text);
}
@Nullable
@@ -128,7 +128,7 @@ public class XDebuggerExpressionComboBox extends XDebuggerEditorBase {
}
@Override
protected void setEditorText(XExpression text) {
protected void doSetText(XExpression text) {
if (myComboBox.getItemCount() > 0) {
myComboBox.setSelectedIndex(0);
}
@@ -69,7 +69,7 @@ public class XDebuggerMultilineEditor extends XDebuggerEditorBase {
}
@Override
protected void setEditorText(XExpression text) {
protected void doSetText(XExpression text) {
myExpression = text;
Language language = text.getLanguage();
FileType fileType = language != null ? language.getAssociatedFileType() : getEditorsProvider().getFileType();
@@ -118,9 +118,6 @@ public class GradleResourceCompilerConfigurationGenerator {
continue;
}
final CompilerModuleExtension compilerModuleExtension = CompilerModuleExtension.getInstance(module);
assert compilerModuleExtension != null;
GradleModuleResourceConfiguration resourceConfig = new GradleModuleResourceConfiguration();
resourceConfig.id = new ModuleVersion(externalProject.getGroup(), externalProject.getName(), externalProject.getVersion());
resourceConfig.directory = FileUtil.toSystemIndependentName(externalProject.getProjectDir().getPath());
@@ -131,6 +128,19 @@ public class GradleResourceCompilerConfigurationGenerator {
final ExternalSourceSet testSourcesSet = externalProject.getSourceSets().get("test");
addResources(resourceConfig.testResources, testSourcesSet, ExternalSystemSourceType.TEST_RESOURCE);
final CompilerModuleExtension compilerModuleExtension = CompilerModuleExtension.getInstance(module);
if(compilerModuleExtension != null && compilerModuleExtension.isCompilerOutputPathInherited()) {
String outputPath = VfsUtilCore.urlToPath(compilerModuleExtension.getCompilerOutputUrl());
for (ResourceRootConfiguration resource : resourceConfig.resources) {
resource.targetPath = outputPath;
}
String testOutputPath = VfsUtilCore.urlToPath(compilerModuleExtension.getCompilerOutputUrlForTests());
for (ResourceRootConfiguration resource : resourceConfig.testResources) {
resource.targetPath = testOutputPath;
}
}
projectConfig.moduleConfigurations.put(module.getName(), resourceConfig);
}
@@ -15,7 +15,6 @@
*/
package org.jetbrains.plugins.gradle.execution;
import com.intellij.openapi.application.Application;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ex.ApplicationEx;
import com.intellij.openapi.components.ServiceManager;
@@ -27,9 +26,9 @@ import com.intellij.openapi.externalSystem.model.project.ExternalSystemSourceTyp
import com.intellij.openapi.externalSystem.service.project.manage.ProjectDataManager;
import com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil;
import com.intellij.openapi.externalSystem.util.ExternalSystemConstants;
import com.intellij.openapi.externalSystem.util.ExternalSystemUtil;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.CompilerModuleExtension;
import com.intellij.openapi.roots.ModuleRootModel;
import com.intellij.openapi.roots.OrderEnumerationHandler;
import com.intellij.openapi.roots.OrderRootType;
@@ -54,6 +53,8 @@ public class GradleOrderEnumeratorHandler extends OrderEnumerationHandler {
@Override
public boolean isApplicable(@NotNull Module module) {
CompilerModuleExtension compilerModuleExtension = CompilerModuleExtension.getInstance(module);
if (compilerModuleExtension != null && compilerModuleExtension.isCompilerOutputPathInherited()) return false;
return ExternalSystemApiUtil.isExternalSystemAwareModule(GradleConstants.SYSTEM_ID, module);
}
@@ -68,6 +68,8 @@ import java.io.FilenameFilter;
import java.io.IOException;
import java.net.URL;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* {@link BaseGradleProjectResolverExtension} provides base implementation of Gradle project resolver.
@@ -651,6 +653,18 @@ public class BaseGradleProjectResolverExtension implements GradleProjectResolver
else {
level = LibraryLevel.PROJECT;
libraryName = String.format("%s:%s:%s", moduleVersion.getGroup(), moduleVersion.getName(), moduleVersion.getVersion());
if (binaryPath.isFile()) {
String libraryFileName = FileUtil.getNameWithoutExtension(binaryPath);
final String mavenLibraryFileName = String.format("%s-%s", moduleVersion.getName(), moduleVersion.getVersion());
if (!mavenLibraryFileName.equals(libraryFileName)) {
Pattern pattern = Pattern.compile(moduleVersion.getName() + "-" + moduleVersion.getVersion() + "-(.*)");
Matcher matcher = pattern.matcher(libraryFileName);
if (matcher.matches()) {
final String classifier = matcher.group(1);
libraryName += (":" + classifier);
}
}
}
}
final LibraryData library = new LibraryData(GradleConstants.SYSTEM_ID, libraryName, unresolved);
@@ -16,6 +16,7 @@
package org.jetbrains.plugins.gradle.importing;
import com.intellij.openapi.roots.DependencyScope;
import com.intellij.openapi.vfs.VirtualFile;
import org.gradle.util.GradleVersion;
import org.junit.Test;
@@ -60,4 +61,36 @@ public class GradleDependenciesImportingTest extends GradleImportingTestCase {
assertModuleLibDepScope("project", "Gradle: org.hamcrest:hamcrest-core:1.3", DependencyScope.TEST);
assertModuleLibDepScope("project", "Gradle: junit:junit:4.11", DependencyScope.TEST);
}
@Test
public void testDependencyWithDifferentClassifiers() throws Exception {
final VirtualFile depJar = createProjectJarSubFile("lib/dep/dep/1.0/dep-1.0.jar");
final VirtualFile depTestsJar = createProjectJarSubFile("lib/dep/dep/1.0/dep-1.0-tests.jar");
importProject(
"allprojects {\n" +
" apply plugin: 'java'\n" +
" sourceCompatibility = 1.5\n" +
" version = '1.0'\n" +
"\n" +
" repositories {\n" +
" mavenCentral()\n" +
" maven{ url file('lib') }\n" +
" }\n" +
"}\n" +
"\n" +
"dependencies {\n" +
" compile 'dep:dep:1.0'\n" +
" testCompile 'dep:dep:1.0:tests'\n" +
"}"
);
assertModules("project");
assertModuleLibDep("project", "Gradle: dep:dep:1.0", depJar.getUrl());
assertModuleLibDepScope("project", "Gradle: dep:dep:1.0", DependencyScope.COMPILE);
assertModuleLibDep("project", "Gradle: dep:dep:1.0:tests", depTestsJar.getUrl());
assertModuleLibDepScope("project", "Gradle: dep:dep:1.0:tests", DependencyScope.TEST);
}
}
@@ -385,6 +385,26 @@ class BaseInterpreterInterface:
return xml
def getArray(self, attr, roffset, coffset, rows, cols, format):
xml = "<xml>"
array = pydevd_vars.evalInContext(attr, self.getNamespace(), self.getNamespace())
xml += pydevd_vars.array_to_xml(array, roffset, coffset, rows, cols, format)
xml += "</xml>"
return xml
def evaluate(self, expression):
xml = "<xml>"
result = pydevd_vars.evalInContext(expression, self.getNamespace(), self.getNamespace())
xml += pydevd_vars.varToXML(result, expression)
xml += "</xml>"
return xml
def changeVariable(self, attr, value):
def do_change_variable():
Exec('%s=%s' % (attr, value), self.getNamespace(), self.getNamespace())
+2
View File
@@ -293,6 +293,8 @@ def start_server(host, port, interpreter):
server.register_function(handshake)
server.register_function(interpreter.connectToDebugger)
server.register_function(interpreter.hello)
server.register_function(interpreter.getArray)
server.register_function(interpreter.evaluate)
# Functions for GUI main loop integration
server.register_function(interpreter.enableGui)
+1 -44
View File
@@ -968,8 +968,6 @@ class InternalGetVariable(InternalThreadCommand):
#=======================================================================================================================
from pydevd_vars import getVariable
MAXIMUM_ARRAY_SIZE = 300
class InternalGetArray(InternalThreadCommand):
def __init__(self, seq, roffset, coffset, rows, cols, format, thread_id, frame_id, scope, attrs):
self.sequence = seq
@@ -988,50 +986,9 @@ class InternalGetArray(InternalThreadCommand):
try:
var = getVariable(self.thread_id, self.frame_id, 'EXPRESSION', self.attrs)
rows = min(self.rows, MAXIMUM_ARRAY_SIZE)
cols = min(self.cols, MAXIMUM_ARRAY_SIZE)
if self.rows == 1 and self.cols == 1:
rows = 1
cols = 1
elif self.rows == 1 or self.cols == 1:
is_row = True if (self.rows == 1) else False
pure_1d = False if (len(var) == 1) else True
if not pure_1d:
var = var[0]
if is_row:
var = var[self.coffset:]
cols = min(cols, len(var))
else:
var = var[self.roffset:]
rows = min(rows, len(var))
else:
var = var[self.roffset:, self.coffset:]
rows = min(rows, len(var))
cols = min(cols, len(var[0]))
xml = "<xml>"
xml += "<array name=\"%s\" rows=\"%s\" cols=\"%s\"/>" % (self.name, rows, cols)
for row in range(rows):
xml += "<row index=\"%s\"/>" % to_string(row)
for col in range(cols):
value = var
name = '%s[%s][%s]' % (self.name, row, col)
if self.rows == 1 or self.cols == 1:
if self.rows == 1 and self.cols == 1:
value = var
name = '%s' % self.name
else:
dim = col if (self.rows == 1) else row
value = var[dim]
name = '%s[%s]' % (self.name, dim)
else:
value = var[row][col]
value = self.format % value
xml += pydevd_vars.varToXML(value, name)
xml += pydevd_vars.array_to_xml(var, self.roffset, self.coffset, self.rows, self.cols, self.format)
xml += "</xml>"
cmd = dbg.cmdFactory.makeGetArrayMessage(self.sequence, xml)
+83 -39
View File
@@ -19,6 +19,7 @@ import _pydev_threading as threading
import traceback
import pydevd_save_locals
from pydev_imports import Exec, quote, execfile
from pydevd_utils import to_string
try:
import types
@@ -276,6 +277,43 @@ def customOperation(thread_id, frame_id, scope, attrs, style, code_or_file, oper
traceback.print_exc()
def evalInContext(expression, globals, locals):
result = None
try:
result = eval(expression, globals, locals)
except Exception:
s = StringIO()
traceback.print_exc(file=s)
result = s.getvalue()
try:
try:
etype, value, tb = sys.exc_info()
result = value
finally:
etype = value = tb = None
except:
pass
result = ExceptionOnEvaluate(result)
# Ok, we have the initial error message, but let's see if we're dealing with a name mangling error...
try:
if '__' in expression:
# Try to handle '__' name mangling...
split = expression.split('.')
curr = locals.get(split[0])
for entry in split[1:]:
if entry.startswith('__') and not hasattr(curr, entry):
entry = '_%s%s' % (curr.__class__.__name__, entry)
curr = getattr(curr, entry)
result = curr
except:
pass
return result
def evaluateExpression(thread_id, frame_id, expression, doExec):
'''returns the result of the evaluated expression
@param doExec: determines if we should do an exec or an eval
@@ -284,9 +322,6 @@ def evaluateExpression(thread_id, frame_id, expression, doExec):
if frame is None:
return
expression = str(expression.replace('@LINE@', '\n'))
#Not using frame.f_globals because of https://sourceforge.net/tracker2/?func=detail&aid=2541355&group_id=85796&atid=577329
#(Names not resolved in generator expression in method)
#See message: http://mail.python.org/pipermail/python-list/2009-January/526522.html
@@ -295,6 +330,7 @@ def evaluateExpression(thread_id, frame_id, expression, doExec):
updated_globals.update(frame.f_locals) #locals later because it has precedence over the actual globals
try:
expression = str(expression.replace('@LINE@', '\n'))
if doExec:
try:
@@ -311,42 +347,7 @@ def evaluateExpression(thread_id, frame_id, expression, doExec):
return
else:
result = None
try:
result = eval(expression, updated_globals, frame.f_locals)
except Exception:
s = StringIO()
traceback.print_exc(file=s)
result = s.getvalue()
try:
try:
etype, value, tb = sys.exc_info()
result = value
finally:
etype = value = tb = None
except:
pass
result = ExceptionOnEvaluate(result)
# Ok, we have the initial error message, but let's see if we're dealing with a name mangling error...
try:
if '__' in expression:
# Try to handle '__' name mangling...
split = expression.split('.')
curr = frame.f_locals.get(split[0])
for entry in split[1:]:
if entry.startswith('__') and not hasattr(curr, entry):
entry = '_%s%s' % (curr.__class__.__name__, entry)
curr = getattr(curr, entry)
result = curr
except:
pass
return result
return evalInContext(expression, updated_globals, frame.f_locals)
finally:
#Should not be kept alive if an exception happens and this frame is kept in the stack.
del updated_globals
@@ -387,6 +388,49 @@ def changeAttrExpression(thread_id, frame_id, attr, expression, dbg):
except Exception:
traceback.print_exc()
MAXIMUM_ARRAY_SIZE = 300
def array_to_xml(array, roffset, coffset, rows, cols, format):
xml = ""
rows = min(rows, MAXIMUM_ARRAY_SIZE)
cols = min(cols, MAXIMUM_ARRAY_SIZE)
if rows == 1 and cols == 1:
rows = 1
cols = 1
elif rows == 1 or cols == 1:
is_row = True if (rows == 1) else False
pure_1d = False if (len(array) == 1) else True
if not pure_1d:
array = array[0]
if is_row:
array = array[coffset:]
cols = min(cols, len(array))
else:
array = array[roffset:]
rows = min(rows, len(array))
else:
array = array[roffset:, coffset:]
rows = min(rows, len(array))
cols = min(cols, len(array[0]))
xml += "<array rows=\"%s\" cols=\"%s\"/>" % (rows, cols)
for row in range(rows):
xml += "<row index=\"%s\"/>" % to_string(row)
for col in range(cols):
value = array
if rows == 1 or cols == 1:
if rows == 1 and cols == 1:
value = array
else:
dim = col if (rows == 1) else row
value = array[dim]
else:
value = array[row][col]
value = format % value
xml += varToXML(value, '')
return xml
+4 -4
View File
@@ -45,10 +45,10 @@
<action class="org.jetbrains.plugins.ipnb.editor.actions.IpnbAddCellAboveAction" id="IpnbAddCellAboveAction" text="Insert Cell Above">
<keyboard-shortcut keymap="$default" first-keystroke="ctrl shift EQUALS"/>
</action>
<action class="org.jetbrains.plugins.ipnb.editor.actions.IpnbCutCellAction" id="IpnbCutCellAction" text="Cut Cell" use-shortcut-of="$Cut"/>
<action class="org.jetbrains.plugins.ipnb.editor.actions.IpnbCopyCellAction" id="IpnbCopyCellAction" text="Copy Cell" use-shortcut-of="$Copy"/>
<action class="org.jetbrains.plugins.ipnb.editor.actions.IpnbPasteCellAction" id="IpnbPasteCellAction" text="Paste Cell Below" use-shortcut-of="$Paste"/>
<action class="org.jetbrains.plugins.ipnb.editor.actions.IpnbDeleteCellAction" id="IpnbDeleteCellAction" text="Delete Cell" use-shortcut-of="$Delete"/>
<action class="org.jetbrains.plugins.ipnb.editor.actions.IpnbCutCellAction" id="IpnbCutCellAction" text="Cut Cell"/>
<action class="org.jetbrains.plugins.ipnb.editor.actions.IpnbCopyCellAction" id="IpnbCopyCellAction" text="Copy Cell"/>
<action class="org.jetbrains.plugins.ipnb.editor.actions.IpnbPasteCellAction" id="IpnbPasteCellAction" text="Paste Cell Below"/>
<action class="org.jetbrains.plugins.ipnb.editor.actions.IpnbDeleteCellAction" id="IpnbDeleteCellAction" text="Delete Cell"/>
<action class="org.jetbrains.plugins.ipnb.editor.actions.IpnbMoveCellDownAction" id="IpnbMoveCellDownAction" text="Move Cell Down">
<keyboard-shortcut keymap="$default" first-keystroke="ctrl shift DOWN"/>
@@ -1,5 +1,6 @@
package org.jetbrains.plugins.ipnb.configuration;
import com.google.common.collect.ImmutableMap;
import com.intellij.execution.ExecutionException;
import com.intellij.execution.configurations.GeneralCommandLine;
import com.intellij.execution.process.KillableColoredProcessHandler;
@@ -20,6 +21,7 @@ import com.intellij.openapi.ui.popup.BalloonBuilder;
import com.intellij.openapi.ui.popup.JBPopupFactory;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.jetbrains.python.PythonHelpersLocator;
import com.jetbrains.python.sdk.PythonSdkType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -102,7 +104,7 @@ public final class IpnbConnectionManager implements ProjectComponent {
long time = System.currentTimeMillis() - startTime;
while (time < 5000) {
final String line = reader.readLine();
if (line.contains("The IPython Notebook is running")) {
if (line != null && line.contains("The IPython Notebook is running")) {
break;
}
time = System.currentTimeMillis() - startTime;
@@ -185,16 +187,11 @@ public final class IpnbConnectionManager implements ProjectComponent {
showWarning(fileEditor, "Please check Python Interpreter in Settings->Python Interpreter");
return false;
}
final VirtualFile directory = sdk.getHomeDirectory();
if (directory == null) return false;
final VirtualFile ipython = directory.getParent().findChild("ipython");
if (ipython == null) {
showWarning(fileEditor, "Could not find Ipython Notebook in selected interpreter");
return false;
}
final Map<String, String> env = ImmutableMap.of("PYCHARM_EP_DIST", "ipython", "PYCHARM_EP_NAME", "ipython");
try {
final GeneralCommandLine commandLine = new GeneralCommandLine(ipython.getPath(), "notebook", "--no-browser").
withWorkDirectory(myProject.getBasePath());
final String ipython = PythonHelpersLocator.getHelperPath("pycharm/pycharm_load_entry_point.py");
final GeneralCommandLine commandLine = new GeneralCommandLine(sdk.getHomePath(), ipython, "notebook", "--no-browser").
withWorkDirectory(myProject.getBasePath()).withEnvironment(env);
myProcessHandler = new KillableColoredProcessHandler(commandLine);
@@ -22,6 +22,7 @@ import org.jetbrains.plugins.ipnb.format.cells.output.IpnbOutputCell;
import javax.swing.*;
import java.awt.*;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
@@ -285,6 +286,22 @@ public class IpnbFilePanel extends JPanel implements Scrollable, DataProvider {
}
}
}
else if (e.getKeyCode() == KeyEvent.VK_DELETE) {
if (!mySelectedCell.isEditing())
deleteCell(mySelectedCell);
}
else if (e.getKeyCode() == KeyEvent.VK_X && e.getModifiers() == InputEvent.CTRL_MASK) {
if (!mySelectedCell.isEditing())
cutCell();
}
else if (e.getKeyCode() == KeyEvent.VK_C && e.getModifiers() == InputEvent.CTRL_MASK) {
if (!mySelectedCell.isEditing())
copyCell();
}
else if (e.getKeyCode() == KeyEvent.VK_V && e.getModifiers() == InputEvent.CTRL_MASK) {
if (!mySelectedCell.isEditing())
pasteCell();
}
else {
getParent().dispatchEvent(e);
}
@@ -89,7 +89,7 @@ public class IpnbParser {
}
public static class IpnbFileRaw {
Map<String, String> metadata = new HashMap<String, String>();
Map<String, Object> metadata = new HashMap<String, Object>();
int nbformat = 3;
int nbformat_minor;
IpnbWorksheet[] worksheets;
@@ -21,5 +21,5 @@ public interface PyFrameAccessor {
@Nullable
PyReferrersLoader getReferrersLoader();
Object[][] getArrayItems(PyDebugValue var, int colOffset, int rowOffset, int rows, int cols, String format) throws PyDebuggerException;
Object[][] getArrayItems(PyDebugValue var, int rowOffset, int colOffset, int rows, int cols, String format) throws PyDebuggerException;
}
@@ -63,6 +63,8 @@ public class PydevConsoleCommunication extends AbstractConsoleCommunication impl
private static final String CONNECT_TO_DEBUGGER = "connectToDebugger";
private static final String HANDSHAKE = "handshake";
private static final String CLOSE = "close";
private static final String EVALUATE = "evaluate";
private static final String GET_ARRAY = "getArray";
/**
* XML-RPC client for sending messages to the server.
@@ -461,7 +463,21 @@ public class PydevConsoleCommunication extends AbstractConsoleCommunication impl
@Override
public PyDebugValue evaluate(String expression, boolean execute, boolean doTrunc) throws PyDebuggerException {
return null; //To change body of implemented methods use File | Settings | File Templates.
if (myClient != null) {
try {
Object ret = myClient.execute(EVALUATE, new Object[]{expression});
if (ret instanceof String) {
return ProtocolParser.parseValue((String)ret, this);
}
else {
checkError(ret);
}
}
catch (Exception e) {
throw new PyDebuggerException("Evaluate in console failed", e);
}
}
return null;
}
@Nullable
@@ -532,8 +548,23 @@ public class PydevConsoleCommunication extends AbstractConsoleCommunication impl
}
@Override
public Object[][] getArrayItems(PyDebugValue var, int colOffset, int rowOffset, int rows, int cols, String format) {
return new Object[][]{new Object[]{1, 2}, new Object[]{3, 4}};
public Object[][] getArrayItems(PyDebugValue var, int rowOffset, int colOffset, int rows, int cols, String format)
throws PyDebuggerException {
if (myClient != null) {
try {
Object ret = myClient.execute(GET_ARRAY, new Object[]{var.getName(), rowOffset, colOffset, rows, cols, format});
if (ret instanceof String) {
return ProtocolParser.parseArrayValues((String)ret, this);
}
else {
checkError(ret);
}
}
catch (Exception e) {
throw new PyDebuggerException("Evaluate in console failed", e);
}
}
return null;
}
/**
@@ -143,7 +143,7 @@ public class ArrayTableCellEditor extends AbstractCellEditor implements TableCel
}
@Override
protected void setEditorText(XExpression text) {
protected void doSetText(XExpression text) {
myEditorTextField.setText(text.getExpression());
}
@@ -56,8 +56,8 @@ public class AsyncArrayTableModel extends AbstractTableModel {
@Override
public Object[][] call() throws Exception {
return value.getFrameAccessor()
.getArrayItems(slicedValue, key.first, key.second, Math.min(CHUNK_COL_SIZE, getRowCount() - key.first),
Math.min(CHUNK_ROW_SIZE, getColumnCount() - key.second),
.getArrayItems(slicedValue, key.first, key.second, Math.min(CHUNK_ROW_SIZE, getRowCount() - key.first),
Math.min(CHUNK_COL_SIZE, getColumnCount() - key.second),
myProvider.getFormat());
}
});
@@ -99,10 +99,11 @@ public class AsyncArrayTableModel extends AbstractTableModel {
if (r < chunk.get().length) {
if (c < chunk.get()[r].length) {
return myProvider.correctStringValue((String)chunk.get()[r][c]);
return myProvider.correctStringValue(chunk.get()[r][c]);
}
}
} else {
}
else {
chunk.addListener(new Runnable() {
@Override
public void run() {
@@ -22,11 +22,14 @@ import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.RangeMarker;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Pair;
import com.intellij.util.Consumer;
import com.intellij.util.ui.UIUtil;
import com.intellij.xdebugger.evaluation.XDebuggerEvaluator;
import com.intellij.xdebugger.frame.XValue;
import com.jetbrains.python.debugger.PyDebugValue;
import com.jetbrains.python.debugger.PyDebuggerEvaluator;
import com.jetbrains.python.debugger.PyDebuggerException;
import com.jetbrains.python.debugger.PyFrameAccessor;
import org.jetbrains.annotations.NotNull;
import javax.management.InvalidAttributeValueException;
@@ -164,11 +167,7 @@ public class NumpyArrayTable {
}
private void initSliceFieldActions() {
if (myComponent.getSliceTextField().getEditor() == null) {
LOG.error("Null editor in slice field.");
return;
}
myComponent.getSliceTextField().getEditor().getContentComponent().addKeyListener(new KeyAdapter() {
myComponent.getSliceTextField().addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
@@ -179,11 +178,7 @@ public class NumpyArrayTable {
}
private void initFormatFieldActions() {
if (myComponent.getFormatTextField().getEditor() == null) {
LOG.error("Null editor in format field.");
return;
}
myComponent.getFormatTextField().getEditor().getContentComponent().addKeyListener(new KeyAdapter() {
myComponent.getFormatTextField().addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
@@ -197,8 +192,8 @@ public class NumpyArrayTable {
return myValue;
}
public PyDebuggerEvaluator getEvaluator() {
return myEvaluator;
public PyFrameAccessor getEvaluator() {
return myValue.getFrameAccessor();
}
public void init() {
@@ -244,10 +239,10 @@ public class NumpyArrayTable {
}
private void fillColorRange(@NotNull final Runnable returnToMain) {
XDebuggerEvaluator.XEvaluationCallback callback = new XDebuggerEvaluator.XEvaluationCallback() {
Consumer<PyDebugValue> callback = new Consumer<PyDebugValue>() {
@Override
public void evaluated(@NotNull XValue result) {
String rawValue = ((PyDebugValue)result).getValue();
public void consume(@NotNull PyDebugValue result) {
String rawValue = result.getValue();
double min;
double max;
String minValue = rawValue.substring(1, rawValue.indexOf(","));
@@ -271,11 +266,6 @@ public class NumpyArrayTable {
myTableCellRenderer.setMax(max);
returnToMain.run();
}
@Override
public void errorOccurred(@NotNull String errorMessage) {
showError(errorMessage);
}
};
if (getMaxRow(myShape) * getMaxColumn(myShape) > HUGE_ARRAY_SIZE) {
@@ -284,7 +274,13 @@ public class NumpyArrayTable {
}
String evalTypeCommand = "[" + getNodeName() + ".min(), " + getNodeName() + ".max()]";
getEvaluator().evaluate(evalTypeCommand, callback, null);
try {
PyDebugValue value = getEvaluator().evaluate(evalTypeCommand, false, false);
callback.consume(value);
}
catch (PyDebuggerException e) {
showError(e.getMessage());
}
}
public String getDefaultPresentation() {
@@ -341,46 +337,36 @@ public class NumpyArrayTable {
}
private void fillType(@NotNull final Runnable returnToMain) {
XDebuggerEvaluator.XEvaluationCallback callback = new XDebuggerEvaluator.XEvaluationCallback() {
@Override
public void evaluated(@NotNull XValue result) {
setDtypeKind(((PyDebugValue)result).getValue());
returnToMain.run();
}
@Override
public void errorOccurred(@NotNull String errorMessage) {
showError(errorMessage);
}
};
String evalTypeCommand = getNodeName() + ".dtype.kind";
getEvaluator().evaluate(evalTypeCommand, callback, null);
try {
PyDebugValue value = getEvaluator().evaluate(evalTypeCommand, false, false);
setDtypeKind(value.getValue());
returnToMain.run();
}
catch (PyDebuggerException e) {
showError(e.getMessage());
}
}
private void fillShape(@NotNull final Runnable returnToMain) {
XDebuggerEvaluator.XEvaluationCallback callback = new XDebuggerEvaluator.XEvaluationCallback() {
@Override
public void evaluated(@NotNull XValue result) {
try {
setShape(parseShape(((PyDebugValue)result).getValue()));
returnToMain.run();
}
catch (InvalidAttributeValueException e) {
errorOccurred(e.getMessage());
}
}
@Override
public void errorOccurred(@NotNull String errorMessage) {
showError(errorMessage);
}
};
String evalShapeCommand = getEvalShapeCommand(getNodeName());
getEvaluator().evaluate(evalShapeCommand, callback, null);
try {
PyDebugValue value = getEvaluator().evaluate(evalShapeCommand, false, false);
setShape(parseShape(value.getValue()));
returnToMain.run();
}
catch (Exception e) {
showError(e.getMessage());
}
}
private int[] parseShape(String value) throws InvalidAttributeValueException {
String shape = value.substring(0, value.indexOf('#'));
int index = value.indexOf('#');
if (index == -1) {
LOG.error("Wrong shape format: " + value);
return new int[]{0, 0};
}
String shape = value.substring(0, index);
if (shape.equals("()")) {
return new int[]{1, 1};
}
@@ -542,14 +528,20 @@ public class NumpyArrayTable {
};
}
public String correctStringValue(@NotNull String value) {
String corrected = value;
if (isNumeric()) {
if (value.startsWith("\'") || value.startsWith("\"")) {
corrected = value.substring(1, value.length() - 1);
public String correctStringValue(@NotNull Object value) {
if (value instanceof String) {
String corrected = (String)value;
if (isNumeric()) {
if (corrected.startsWith("\'") || corrected.startsWith("\"")) {
corrected = corrected.substring(1, corrected.length() - 1);
}
}
return corrected;
}
return corrected;
else if (value instanceof Integer) {
return Integer.toString((Integer)value);
}
return value.toString();
}
public void setDtypeKind(String dtype) {
@@ -611,28 +603,18 @@ public class NumpyArrayTable {
private void doReslice(final String newSlice, int[] shape) {
if (shape == null) {
XDebuggerEvaluator.XEvaluationCallback callback = new XDebuggerEvaluator.XEvaluationCallback() {
@Override
public void evaluated(@NotNull XValue result) {
try {
int[] shape = parseShape(((PyDebugValue)result).getValue());
if (!is2DShape(shape)) {
errorOccurred("Incorrect slice shape " + ((PyDebugValue)result).getValue() + ".");
}
doReslice(newSlice, shape);
}
catch (InvalidAttributeValueException e) {
errorOccurred(e.getMessage());
}
}
@Override
public void errorOccurred(@NotNull String errorMessage) {
showError(errorMessage);
}
};
String evalShapeCommand = getEvalShapeCommand(newSlice);
getEvaluator().evaluate(evalShapeCommand, callback, null);
try {
PyDebugValue result = getEvaluator().evaluate(evalShapeCommand, false, false);
shape = parseShape(((PyDebugValue)result).getValue());
if (!is2DShape(shape)) {
showError("Incorrect slice shape " + ((PyDebugValue)result).getValue() + ".");
}
doReslice(newSlice, shape);
}
catch (Exception e) {
showError(e.getMessage());
}
return;
}
@@ -17,6 +17,7 @@ package com.jetbrains.python.refactoring.rename;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiReference;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.search.searches.ReferencesSearch;
import com.intellij.util.Processor;
import com.jetbrains.python.PyNames;
@@ -67,7 +68,7 @@ public class RenamePyClassProcessor extends RenamePyElementProcessor {
if (initMethod != null) {
final List<PsiReference> allRefs = Collections.synchronizedList(new ArrayList<PsiReference>());
allRefs.addAll(super.findReferences(element));
ReferencesSearch.search(initMethod).forEach(new Processor<PsiReference>() {
ReferencesSearch.search(initMethod, GlobalSearchScope.projectScope(element.getProject())).forEach(new Processor<PsiReference>() {
@Override
public boolean process(PsiReference psiReference) {
if (psiReference.getCanonicalText().equals(((PyClass)element).getName())) {