diff --git a/build/scripts/utils.gant b/build/scripts/utils.gant index 900381b45908..5a10eaa016a2 100644 --- a/build/scripts/utils.gant +++ b/build/scripts/utils.gant @@ -272,7 +272,9 @@ binding.setVariable("classPathLibs", [ binding.setVariable("platformApiModules", [ "analysis-api", + "built-in-server-api", "core-api", + "diff-api", "dvcs-api", "editor-ui-api", "external-system-api", @@ -280,60 +282,57 @@ binding.setVariable("platformApiModules", [ "jps-model-api", "lang-api", "lvcs-api", - "projectModel-api", "platform-api", + "projectModel-api", + "remote-servers-agent-rt", + "remote-servers-api", "structure-view-api", "usageView", - "diff-api", - "vcs-api", "vcs-api-core", + "vcs-api", "vcs-log-api", "vcs-log-graph-api", "xdebugger-api", - "remote-servers-api", - "remote-servers-agent-rt", "xml-analysis-api", "xml-openapi", "xml-psi-api", - "xml-structure-view-api", - "built-in-server-api" + "xml-structure-view-api" ]) - binding.setVariable("platformImplementationModules", [ "analysis-impl", + "built-in-server", "core-impl", + "diff-impl", "dvcs-impl", "editor-ui-ex", "images", "indexing-impl", "jps-model-impl", "jps-model-serialization", + "json", "lang-impl", "lvcs-impl", - "projectModel-impl", "platform-impl", + "projectModel-impl", + "protocol-reader-runtime", + "RegExpSupport", + "relaxng", + "remote-servers-impl", + "script-debugger-backend", + "script-debugger-ui", + "smRunner", + "spellchecker", "structure-view-impl", - "diff-impl", + "testRunner", "vcs-impl", "vcs-log-graph", "vcs-log-impl", - "testRunner", - "smRunner", - "relaxng", - "RegExpSupport", - "spellchecker", "xdebugger-impl", - "remote-servers-impl", - "xml", "xml-analysis-impl", "xml-psi-impl", "xml-structure-view-impl", - "json", - "protocol-reader-runtime", - "script-debugger-backend", - "script-debugger-ui", - "built-in-server" + "xml" ]) binding.setVariable("layoutMacApp", { String path, String ch, Map args -> diff --git a/java/idea-ui/src/com/intellij/ide/impl/NewProjectUtil.java b/java/idea-ui/src/com/intellij/ide/impl/NewProjectUtil.java index f2738ff51dcf..edd6516ce5c5 100644 --- a/java/idea-ui/src/com/intellij/ide/impl/NewProjectUtil.java +++ b/java/idea-ui/src/com/intellij/ide/impl/NewProjectUtil.java @@ -225,9 +225,8 @@ public class NewProjectUtil { if (version != null) { LanguageLevel maxLevel = version.getMaxLanguageLevel(); LanguageLevelProjectExtension extension = LanguageLevelProjectExtension.getInstance(ProjectManager.getInstance().getDefaultProject()); - Boolean aDefault = extension.isDefault(); LanguageLevelProjectExtension ext = LanguageLevelProjectExtension.getInstance(project); - if (aDefault != null && aDefault || maxLevel.compareTo(ext.getLanguageLevel()) < 0) { + if (extension.isDefault() || maxLevel.compareTo(ext.getLanguageLevel()) < 0) { ext.setLanguageLevel(maxLevel); } } diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ContentEntriesEditor.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ContentEntriesEditor.java index d4677c1f7a09..188a4f90ea4f 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ContentEntriesEditor.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ContentEntriesEditor.java @@ -17,6 +17,7 @@ package com.intellij.openapi.roots.ui.configuration; import com.intellij.openapi.options.ConfigurationException; import com.intellij.openapi.roots.LanguageLevelModuleExtensionImpl; +import com.intellij.openapi.roots.LanguageLevelProjectExtension; import javax.swing.*; import java.awt.*; @@ -52,6 +53,7 @@ public class ContentEntriesEditor extends JavaContentEntriesEditor { return getModel().getModuleExtension(LanguageLevelModuleExtensionImpl.class); } }; + myLanguageLevelConfigurable.addProjectDefault(LanguageLevelProjectExtension.getInstance(myProject).getLanguageLevel()); mainPanel.add(myLanguageLevelConfigurable.createComponent(), BorderLayout.NORTH); myLanguageLevelConfigurable.reset(); } diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/LanguageLevelCombo.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/LanguageLevelCombo.java index 9716dbee0f6d..6c158a9e4ca0 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/LanguageLevelCombo.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/LanguageLevelCombo.java @@ -16,16 +16,18 @@ package com.intellij.openapi.roots.ui.configuration; import com.intellij.core.JavaCoreBundle; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.project.ProjectBundle; import com.intellij.openapi.projectRoots.JavaSdk; import com.intellij.openapi.projectRoots.JavaSdkVersion; import com.intellij.openapi.projectRoots.Sdk; -import com.intellij.openapi.roots.ex.ProjectRootManagerEx; -import com.intellij.ui.ListCellRendererWrapper; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.project.ProjectBundle; import com.intellij.openapi.roots.LanguageLevelProjectExtension; +import com.intellij.openapi.roots.ex.ProjectRootManagerEx; import com.intellij.openapi.ui.ComboBox; +import com.intellij.openapi.util.Pair; import com.intellij.pom.java.LanguageLevel; +import com.intellij.ui.ColoredListCellRendererWrapper; +import com.intellij.ui.SimpleTextAttributes; import org.jetbrains.annotations.Nullable; import javax.swing.*; @@ -33,24 +35,30 @@ import javax.swing.*; /** * @author ven */ +@SuppressWarnings("unchecked") public class LanguageLevelCombo extends ComboBox { - public static final String USE_PROJECT_LANGUAGE_LEVEL = ProjectBundle.message("project.language.level.combo.item"); + /** Default from current SDK */ @Nullable private LanguageLevel myDefaultLevel; + private Pair myProjectDefault; public LanguageLevelCombo() { for (LanguageLevel level : LanguageLevel.values()) { addItem(level); } - setRenderer(new ListCellRendererWrapper() { + setRenderer(new ColoredListCellRendererWrapper() { @Override - public void customize(final JList list, final Object value, final int index, final boolean selected, final boolean hasFocus) { + protected void doCustomize(JList list, Object value, int index, boolean selected, boolean hasFocus) { if (value instanceof LanguageLevel) { - setText(((LanguageLevel)value).getPresentableText()); + append(((LanguageLevel)value).getPresentableText()); } - else if (value instanceof String) { - setText((String)value); + else if (value instanceof Pair) { + Pair pair = (Pair)value; + append(pair.first); + if (pair.second != null) { + append(" (" + pair.second + ")", SimpleTextAttributes.GRAYED_ATTRIBUTES); + } } } }); @@ -69,20 +77,19 @@ public class LanguageLevelCombo extends ComboBox { myDefaultLevel = version.getMaxLanguageLevel(); } } - String item = null; + Pair item = null; if (myDefaultLevel != null) { - item = JavaCoreBundle.message("default.jdk.level.description", myDefaultLevel.getPresentableText()); + item = Pair.create(JavaCoreBundle.message("default.language.level.description"), myDefaultLevel.getPresentableText()); addItem(item); } else if (project.isDefault()) { - item = JavaCoreBundle.message("default.language.level.description"); + item = Pair.create(JavaCoreBundle.message("default.language.level.description"), null); addItem(item); myDefaultLevel = LanguageLevelProjectExtension.getInstance(project).getLanguageLevel(); } LanguageLevelProjectExtension extension = LanguageLevelProjectExtension.getInstance(project); - Boolean aDefault = extension.isDefault(); - if (item != null && aDefault != null && aDefault) { + if (item != null && extension.isDefault()) { setSelectedItem(item); } else { @@ -102,9 +109,11 @@ public class LanguageLevelCombo extends ComboBox { @Override public void setSelectedItem(Object anObject) { - if (anObject == null) { - anObject = USE_PROJECT_LANGUAGE_LEVEL; - } - super.setSelectedItem(anObject); + super.setSelectedItem(anObject == null ? myProjectDefault : anObject); + } + + void addProjectDefault(String projectLevel) { + myProjectDefault = Pair.create(ProjectBundle.message("project.language.level.combo.item"), projectLevel); + insertItemAt(myProjectDefault, 0); } } diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/LanguageLevelConfigurable.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/LanguageLevelConfigurable.java index a22242f4093a..8199f714eab5 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/LanguageLevelConfigurable.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/LanguageLevelConfigurable.java @@ -21,6 +21,7 @@ import com.intellij.openapi.options.UnnamedConfigurable; import com.intellij.openapi.project.ProjectBundle; import com.intellij.openapi.roots.LanguageLevelModuleExtensionImpl; import com.intellij.pom.java.LanguageLevel; +import org.jetbrains.annotations.NotNull; import javax.swing.*; import java.awt.*; @@ -44,7 +45,6 @@ public abstract class LanguageLevelConfigurable implements UnnamedConfigurable { getLanguageLevelExtension().setLanguageLevel(languageLevel instanceof LanguageLevel ? (LanguageLevel)languageLevel : null); } }); - myLanguageLevelCombo.insertItemAt(LanguageLevelCombo.USE_PROJECT_LANGUAGE_LEVEL, 0); JLabel label = new JLabel(ProjectBundle.message("module.module.language.level")); label.setLabelFor(myLanguageLevelCombo); @@ -54,6 +54,7 @@ public abstract class LanguageLevelConfigurable implements UnnamedConfigurable { new GridBagConstraints(1, 0, 1, 1, 1, 0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(6, 6, 12, 0), 0, 0)); } + @NotNull @Override public JComponent createComponent() { return myPanel; @@ -81,4 +82,8 @@ public abstract class LanguageLevelConfigurable implements UnnamedConfigurable { } public abstract LanguageLevelModuleExtensionImpl getLanguageLevelExtension(); + + public void addProjectDefault(LanguageLevel projectDefault) { + myLanguageLevelCombo.addProjectDefault(projectDefault.getPresentableText()); + } } diff --git a/java/java-impl/src/com/intellij/openapi/roots/impl/LanguageLevelProjectExtensionImpl.java b/java/java-impl/src/com/intellij/openapi/roots/impl/LanguageLevelProjectExtensionImpl.java index 2335a0e23a86..d9e5a703efef 100644 --- a/java/java-impl/src/com/intellij/openapi/roots/impl/LanguageLevelProjectExtensionImpl.java +++ b/java/java-impl/src/com/intellij/openapi/roots/impl/LanguageLevelProjectExtensionImpl.java @@ -22,6 +22,9 @@ package com.intellij.openapi.roots.impl; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; +import com.intellij.openapi.projectRoots.JavaSdk; +import com.intellij.openapi.projectRoots.JavaSdkVersion; +import com.intellij.openapi.projectRoots.Sdk; import com.intellij.openapi.roots.LanguageLevelProjectExtension; import com.intellij.openapi.roots.ProjectExtension; import com.intellij.openapi.util.InvalidDataException; @@ -30,6 +33,7 @@ import com.intellij.pom.java.LanguageLevel; import org.jdom.Element; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; public class LanguageLevelProjectExtensionImpl extends LanguageLevelProjectExtension { private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.roots.impl.LanguageLevelProjectExtensionImpl"); @@ -76,7 +80,7 @@ import org.jetbrains.annotations.NotNull; private void writeExternal(final Element element) { element.setAttribute(LANGUAGE_LEVEL, myLanguageLevel.name()); - Boolean aBoolean = isDefault(); + Boolean aBoolean = getDefault(); if (aBoolean != null) { element.setAttribute(DEFAULT_ATTRIBUTE, Boolean.toString(aBoolean)); } @@ -116,21 +120,35 @@ import org.jetbrains.annotations.NotNull; LOG.warn("Calling deprecated LanguageLevelProjectExtensionImpl.reloadProjectOnLanguageLevelChange, while project reloading is not needed on language level changes"); } + private void projectSdkChanged(@Nullable Sdk sdk) { + if (isDefault() && sdk != null) { + JavaSdkVersion version = JavaSdk.getInstance().getVersion(sdk); + if (version != null) { + setLanguageLevel(version.getMaxLanguageLevel()); + } + } + } + public static class MyProjectExtension extends ProjectExtension { - private final Project myProject; + private final LanguageLevelProjectExtensionImpl myInstance; public MyProjectExtension(final Project project) { - myProject = project; + myInstance = ((LanguageLevelProjectExtensionImpl)getInstance(project)); } @Override public void readExternal(final Element element) throws InvalidDataException { - ((LanguageLevelProjectExtensionImpl)getInstance(myProject)).readExternal(element); + myInstance.readExternal(element); } @Override public void writeExternal(final Element element) throws WriteExternalException { - ((LanguageLevelProjectExtensionImpl)getInstance(myProject)).writeExternal(element); + myInstance.writeExternal(element); + } + + @Override + public void projectSdkChanged(@Nullable Sdk sdk) { + myInstance.projectSdkChanged(sdk); } } -} \ No newline at end of file + } \ No newline at end of file diff --git a/java/java-psi-api/src/com/intellij/openapi/roots/LanguageLevelProjectExtension.java b/java/java-psi-api/src/com/intellij/openapi/roots/LanguageLevelProjectExtension.java index dee5fb7de932..f91d24e685e9 100644 --- a/java/java-psi-api/src/com/intellij/openapi/roots/LanguageLevelProjectExtension.java +++ b/java/java-psi-api/src/com/intellij/openapi/roots/LanguageLevelProjectExtension.java @@ -42,7 +42,7 @@ public abstract class LanguageLevelProjectExtension { * @return null if the property is not set yet (e.g. after migration). */ @Nullable - public Boolean isDefault() { + public Boolean getDefault() { return myDefault; } @@ -50,6 +50,10 @@ public abstract class LanguageLevelProjectExtension { myDefault = value; } + public boolean isDefault() { + return myDefault != null && myDefault; + } + public abstract void languageLevelsChanged(); /** diff --git a/java/java-psi-api/src/messages/JavaCoreBundle.properties b/java/java-psi-api/src/messages/JavaCoreBundle.properties index c9646f45f3b0..5ff783532c04 100644 --- a/java/java-psi-api/src/messages/JavaCoreBundle.properties +++ b/java/java-psi-api/src/messages/JavaCoreBundle.properties @@ -1,7 +1,6 @@ psi.error.attempt.to.edit.class.file=Cannot modify compiled element -default.language.level.description=JDK default -default.jdk.level.description=JDK default ({0}) +default.language.level.description=SDK default jdk.1.3.language.level.description=1.3 - Plain old Java jdk.1.4.language.level.description=1.4 - 'assert' keyword jdk.1.5.language.level.description=5.0 - 'enum' keyword, generics, autoboxing etc. diff --git a/java/openapi/src/com/intellij/ide/util/projectWizard/JavaModuleBuilder.java b/java/openapi/src/com/intellij/ide/util/projectWizard/JavaModuleBuilder.java index 8a48d8389014..069c08cd3a57 100644 --- a/java/openapi/src/com/intellij/ide/util/projectWizard/JavaModuleBuilder.java +++ b/java/openapi/src/com/intellij/ide/util/projectWizard/JavaModuleBuilder.java @@ -155,7 +155,7 @@ public class JavaModuleBuilder extends ModuleBuilder implements SourcePathsBuild @Override public List commit(@NotNull Project project, ModifiableModuleModel model, ModulesProvider modulesProvider) { LanguageLevelProjectExtension extension = LanguageLevelProjectExtension.getInstance(ProjectManager.getInstance().getDefaultProject()); - Boolean aDefault = extension.isDefault(); + Boolean aDefault = extension.getDefault(); LanguageLevelProjectExtension instance = LanguageLevelProjectExtension.getInstance(project); if (aDefault != null && !aDefault) { instance.setLanguageLevel(extension.getLanguageLevel()); diff --git a/java/structuralsearch-java/src/com/intellij/structuralsearch/impl/matcher/JavaMatchingVisitor.java b/java/structuralsearch-java/src/com/intellij/structuralsearch/impl/matcher/JavaMatchingVisitor.java index 9fdc4c29cb0e..6e33cd89b61b 100644 --- a/java/structuralsearch-java/src/com/intellij/structuralsearch/impl/matcher/JavaMatchingVisitor.java +++ b/java/structuralsearch-java/src/com/intellij/structuralsearch/impl/matcher/JavaMatchingVisitor.java @@ -1453,7 +1453,7 @@ public class JavaMatchingVisitor extends JavaElementVisitor { if (myMatchingVisitor.getResult()) { final PsiTypeElement checkType = instanceOf.getCheckType(); if (checkType != null) { - myMatchingVisitor.setResult(matchType(checkType, instanceOf2.getCheckType())); + myMatchingVisitor.setResult(myMatchingVisitor.match(checkType, instanceOf2.getCheckType())); } } } diff --git a/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/DaemonProgressIndicator.java b/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/DaemonProgressIndicator.java index 378564c7a6c1..6afba8d8eaa0 100644 --- a/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/DaemonProgressIndicator.java +++ b/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/DaemonProgressIndicator.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 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. @@ -83,7 +83,7 @@ public class DaemonProgressIndicator extends AbstractProgressIndicatorBase imple } @TestOnly - static void setDebug(boolean debug) { + public static void setDebug(boolean debug) { DaemonProgressIndicator.debug = debug; } diff --git a/platform/core-impl/src/com/intellij/psi/impl/smartPointers/SmartPointerManagerImpl.java b/platform/core-impl/src/com/intellij/psi/impl/smartPointers/SmartPointerManagerImpl.java index 401ab76370e0..dc66978ba613 100644 --- a/platform/core-impl/src/com/intellij/psi/impl/smartPointers/SmartPointerManagerImpl.java +++ b/platform/core-impl/src/com/intellij/psi/impl/smartPointers/SmartPointerManagerImpl.java @@ -200,6 +200,7 @@ public class SmartPointerManagerImpl extends SmartPointerManager { if (!file.isValid()) { LOG.error("Invalid element:" + file); } + processQueue(); SmartPsiFileRangePointerImpl pointer = new SmartPsiFileRangePointerImpl(file, ProperTextRange.create(range)); initPointer(pointer, file.getViewProvider().getVirtualFile()); diff --git a/platform/external-system-api/src/com/intellij/openapi/externalSystem/model/DataNode.java b/platform/external-system-api/src/com/intellij/openapi/externalSystem/model/DataNode.java index 869731d2d90b..1e879da7e922 100644 --- a/platform/external-system-api/src/com/intellij/openapi/externalSystem/model/DataNode.java +++ b/platform/external-system-api/src/com/intellij/openapi/externalSystem/model/DataNode.java @@ -24,10 +24,7 @@ import org.jetbrains.annotations.Nullable; import java.io.*; import java.lang.reflect.Modifier; import java.lang.reflect.Proxy; -import java.util.Arrays; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; +import java.util.*; /** * This class provides a generic graph infrastructure with ability to store particular data. The main purpose is to @@ -48,6 +45,7 @@ public class DataNode implements Serializable { private static final Logger LOG = Logger.getInstance(DataNode.class); @NotNull private final List> myChildren = ContainerUtilRt.newArrayList(); + @NotNull private final List> myChildrenView = Collections.unmodifiableList(myChildren); @NotNull private final Key myKey; private transient T myData; @@ -73,18 +71,6 @@ public class DataNode implements Serializable { return result; } - @NotNull - public DataNode createOrReplaceChild(@NotNull Key key, @NotNull T data) { - for (Iterator> iterator = myChildren.iterator(); iterator.hasNext(); ) { - DataNode child = iterator.next(); - if (child.getKey().equals(key)) { - iterator.remove(); - break; - } - } - return createChild(key, data); - } - @NotNull public Key getKey() { return myKey; @@ -237,7 +223,7 @@ public class DataNode implements Serializable { @NotNull public Collection> getChildren() { - return myChildren; + return myChildrenView; } private void writeObject(ObjectOutputStream out) throws IOException { @@ -304,7 +290,7 @@ public class DataNode implements Serializable { public void clear(boolean removeFromGraph) { if (removeFromGraph && myParent != null) { - for (Iterator> iterator = myParent.getChildren().iterator(); iterator.hasNext(); ) { + for (Iterator> iterator = myParent.myChildren.iterator(); iterator.hasNext(); ) { DataNode dataNode = iterator.next(); if (System.identityHashCode(dataNode) == System.identityHashCode(this)) { iterator.remove(); @@ -316,4 +302,17 @@ public class DataNode implements Serializable { myRawData = null; myChildren.clear(); } + + public DataNode graphCopy() { + return nodeCopy(this, null); + } + + private static DataNode nodeCopy(@NotNull DataNode dataNode, @Nullable DataNode newParent) { + DataNode copy = new DataNode(dataNode.myKey, dataNode.myData, newParent); + copy.myRawData = dataNode.myRawData; + for (DataNode child : dataNode.myChildren) { + copy.addChild(nodeCopy(child, copy)); + } + return copy; + } } diff --git a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/project/manage/ExternalProjectsDataStorage.java b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/project/manage/ExternalProjectsDataStorage.java index 4b487ca55232..0c61d23d6a7a 100644 --- a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/project/manage/ExternalProjectsDataStorage.java +++ b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/project/manage/ExternalProjectsDataStorage.java @@ -138,7 +138,7 @@ public class ExternalProjectsDataStorage implements SettingsSavingComponent { InternalExternalProjectInfo merged = new InternalExternalProjectInfo( projectSystemId, projectPath, - externalProjectStructure + externalProjectStructure != null ? externalProjectStructure.graphCopy() : null ); merged.setLastImportTimestamp(lastImportTimestamp); merged.setLastSuccessfulImportTimestamp(lastSuccessfulImportTimestamp); diff --git a/platform/lang-api/src/com/intellij/psi/codeStyle/EditorNotificationInfo.java b/platform/lang-api/src/com/intellij/psi/codeStyle/EditorNotificationInfo.java index 59315c245631..8455382bf1e6 100644 --- a/platform/lang-api/src/com/intellij/psi/codeStyle/EditorNotificationInfo.java +++ b/platform/lang-api/src/com/intellij/psi/codeStyle/EditorNotificationInfo.java @@ -15,53 +15,33 @@ */ package com.intellij.psi.codeStyle; -import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import javax.swing.*; -import java.util.Collections; +import javax.swing.Icon; import java.util.List; -public class EditorNotificationInfo { - - private String myTitle; - private Icon myIcon; - private List myLabelsWithActions = ContainerUtil.newArrayList(); - - public EditorNotificationInfo(@NotNull String title, - @NotNull LabelWithAction firstLabel, - @Nullable LabelWithAction... otherLabels) - { - myTitle = title; - myLabelsWithActions.add(firstLabel); - if (otherLabels != null) { - Collections.addAll(myLabelsWithActions, otherLabels); - } - } - - public EditorNotificationInfo(@NotNull String title, - @NotNull Icon icon, - @NotNull LabelWithAction firstLabel, - @Nullable LabelWithAction... otherLabels) - { - this(title, firstLabel, otherLabels); - myIcon = icon; - } +public abstract class EditorNotificationInfo { @NotNull - public List getLabelAndActions() { - return myLabelsWithActions; - } + public abstract List getLabelAndActions(); + + @NotNull + public abstract String getTitle(); @Nullable public Icon getIcon() { - return myIcon; + return null; } - @NotNull - public String getTitle() { - return myTitle; + public static class ActionLabelData { + public final String label; + public final Runnable action; + + public ActionLabelData(@NotNull String label, @NotNull Runnable action) { + this.label = label; + this.action = action; + } } } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/DaemonListeners.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/DaemonListeners.java index 083ea16e5091..6dfc2cb1079e 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/DaemonListeners.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/DaemonListeners.java @@ -429,7 +429,7 @@ public class DaemonListeners implements Disposable { @Override public void beforeWriteActionStart(Object action) { myDaemonWasRunning = myDaemonCodeAnalyzer.isRunning(); - if (!myDaemonWasRunning || isUnderIgnoredAction(action)) return; // we'll restart in writeActionFinished() + if (!myDaemonWasRunning) return; // we'll restart in writeActionFinished() stopDaemon(true, "Write action start"); } diff --git a/platform/lang-impl/src/com/intellij/ide/util/FileStructurePopup.java b/platform/lang-impl/src/com/intellij/ide/util/FileStructurePopup.java index 5c1f4cc35402..6f13af4fed19 100644 --- a/platform/lang-impl/src/com/intellij/ide/util/FileStructurePopup.java +++ b/platform/lang-impl/src/com/intellij/ide/util/FileStructurePopup.java @@ -242,7 +242,7 @@ public class FileStructurePopup implements Disposable { public void show() { //final long time = System.currentTimeMillis(); JComponent panel = createCenterPanel(); - new MnemonicHelper().register(panel); + MnemonicHelper.init(panel); boolean shouldSetWidth = DimensionService.getInstance().getSize(getDimensionServiceKey(), myProject) == null; myPopup = JBPopupFactory.getInstance().createComponentPopupBuilder(panel, null) .setTitle(myTitle) diff --git a/platform/lang-impl/src/com/intellij/ide/util/gotoByName/ChooseByNameBase.java b/platform/lang-impl/src/com/intellij/ide/util/gotoByName/ChooseByNameBase.java index ff3ad83bcafe..5ccd42cfd4cb 100644 --- a/platform/lang-impl/src/com/intellij/ide/util/gotoByName/ChooseByNameBase.java +++ b/platform/lang-impl/src/com/intellij/ide/util/gotoByName/ChooseByNameBase.java @@ -897,7 +897,7 @@ public abstract class ChooseByNameBase { myTextPopup.setSize(bounds.getSize()); myTextPopup.setLocation(bounds.getLocation()); - new MnemonicHelper().register(myTextFieldPanel); + MnemonicHelper.init(myTextFieldPanel); if (myProject != null && !myProject.isDefault()) { DaemonCodeAnalyzer.getInstance(myProject).disableUpdateByTimer(myTextPopup); } diff --git a/platform/lang-impl/src/com/intellij/internal/statistic/editor/EditorSettingsStatisticsCollector.java b/platform/lang-impl/src/com/intellij/internal/statistic/editor/EditorSettingsStatisticsCollector.java new file mode 100644 index 000000000000..f2591af1689f --- /dev/null +++ b/platform/lang-impl/src/com/intellij/internal/statistic/editor/EditorSettingsStatisticsCollector.java @@ -0,0 +1,122 @@ +/* + * Copyright 2000-2015 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.internal.statistic.editor; + +import com.intellij.codeInsight.CodeInsightSettings; +import com.intellij.codeInsight.editorActions.SmartBackspaceMode; +import com.intellij.internal.statistic.CollectUsagesException; +import com.intellij.internal.statistic.UsagesCollector; +import com.intellij.internal.statistic.beans.GroupDescriptor; +import com.intellij.internal.statistic.beans.UsageDescriptor; +import com.intellij.openapi.editor.ex.EditorSettingsExternalizable; +import com.intellij.openapi.editor.impl.softwrap.SoftWrapAppliancePlaces; +import com.intellij.openapi.editor.richcopy.settings.RichCopySettings; +import com.intellij.openapi.util.Comparing; +import org.jetbrains.annotations.NotNull; + +import java.util.HashSet; +import java.util.Set; + +class EditorSettingsStatisticsCollector extends UsagesCollector { + @NotNull + @Override + public GroupDescriptor getGroupId() { + return GroupDescriptor.create("Editor"); + } + + @NotNull + @Override + public Set getUsages() throws CollectUsagesException { + Set set = new HashSet(); + + EditorSettingsExternalizable es = EditorSettingsExternalizable.getInstance(); + addIfDiffers(set, es.isVirtualSpace(), false, "caretAfterLineEnd"); + addIfDiffers(set, es.isCaretInsideTabs(), false, "caretInsideTabs"); + addIfDiffers(set, es.isAdditionalPageAtBottom(), false, "virtualSpaceAtFileBottom"); + addIfDiffers(set, es.isUseSoftWraps(SoftWrapAppliancePlaces.MAIN_EDITOR), false, "softWraps"); + addIfDiffers(set, es.isUseSoftWraps(SoftWrapAppliancePlaces.CONSOLE), false, "softWraps.console"); + addIfDiffers(set, es.isUseCustomSoftWrapIndent(), false, "softWraps.relativeIndent"); + addIfDiffers(set, es.isAllSoftWrapsShown(), false, "softWraps.showAll"); + addIfDiffers(set, es.getStripTrailingSpaces(), EditorSettingsExternalizable.STRIP_TRAILING_SPACES_CHANGED, "stripTrailingSpaces"); + addIfDiffers(set, es.isEnsureNewLineAtEOF(), false, "ensureNewlineAtEOF"); + addIfDiffers(set, es.isShowQuickDocOnMouseOverElement(), false, "quickDocOnMouseHover"); + addIfDiffers(set, es.isBlinkCaret(), true, "nonBlinkingCaret"); + addIfDiffers(set, es.isBlockCursor(), false, "blockCaret"); + addIfDiffers(set, es.isRightMarginShown(), true, "noRightMargin"); + addIfDiffers(set, es.isLineNumbersShown(), false, "lineNumbers"); + addIfDiffers(set, es.isFoldingOutlineShown(), true, "noFoldingOutline"); + addIfDiffers(set, es.isWhitespacesShown() && es.isLeadingWhitespacesShown(), false, "showLeadingWhitespace"); + addIfDiffers(set, es.isWhitespacesShown() && es.isInnerWhitespacesShown(), false, "showInnerWhitespace"); + addIfDiffers(set, es.isWhitespacesShown() && es.isTrailingWhitespacesShown(), false, "showTrailingWhitespace"); + addIfDiffers(set, es.isIndentGuidesShown(), true, "noIndentGuides"); + addIfDiffers(set, es.isSmoothScrolling(), true, "noAnimatedScroll"); + addIfDiffers(set, es.isDndEnabled(), false, "dragNDrop"); + addIfDiffers(set, es.isWheelFontChangeEnabled(), false, "wheelZoom"); + addIfDiffers(set, es.isMouseClickSelectionHonorsCamelWords(), true, "mouseNoCamel"); + addIfDiffers(set, es.isVariableInplaceRenameEnabled(), true, "noInplaceRename"); + addIfDiffers(set, es.isPreselectRename(), true, "noPreselectOnRename"); + addIfDiffers(set, es.isShowInlineLocalDialog(), true, "noInlineDialog"); + addIfDiffers(set, es.isRefrainFromScrolling(), false, "minimizeScrolling"); + addIfDiffers(set, es.getOptions().SHOW_REFORMAT_DIALOG, true, "noReformatDialog"); + addIfDiffers(set, es.getOptions().SHOW_OPIMIZE_IMPORTS_DIALOG, true, "noOptimizeImportsDialog"); + addIfDiffers(set, es.isSmartHome(), true, "noSmartHome"); + addIfDiffers(set, es.isCamelWords(), false, "camelWords"); + + RichCopySettings rcs = RichCopySettings.getInstance(); + addIfDiffers(set, rcs.isEnabled(), true, "noRichCopy"); + + CodeInsightSettings cis = CodeInsightSettings.getInstance(); + addIfDiffers(set, cis.AUTO_POPUP_PARAMETER_INFO, true, "noParameterAutoPopup"); + addIfDiffers(set, cis.AUTO_POPUP_JAVADOC_INFO, false, "javadocAutoPopup"); + addIfDiffers(set, cis.AUTO_POPUP_COMPLETION_LOOKUP, true, "noCompletionAutoPopup"); + addIfDiffers(set, cis.COMPLETION_CASE_SENSITIVE, CodeInsightSettings.FIRST_LETTER, "completionCaseSensitivity"); + addIfDiffers(set, cis.SELECT_AUTOPOPUP_SUGGESTIONS_BY_CHARS, false, "autoPopupCharComplete"); + addIfDiffers(set, cis.AUTOCOMPLETE_ON_CODE_COMPLETION, true, "noAutoCompleteBasic"); + addIfDiffers(set, cis.AUTOCOMPLETE_ON_SMART_TYPE_COMPLETION, true, "noAutoCompleteSmart"); + addIfDiffers(set, cis.SHOW_FULL_SIGNATURES_IN_PARAMETER_INFO, false, "parameterInfoFullSignature"); + addIfDiffers(set, cis.getBackspaceMode(), SmartBackspaceMode.AUTOINDENT, "smartBackspace"); + addIfDiffers(set, cis.SMART_INDENT_ON_ENTER, true, "noIndentOnEnter"); + addIfDiffers(set, cis.INSERT_BRACE_ON_ENTER, true, "noBraceOnEnter"); + addIfDiffers(set, cis.JAVADOC_STUB_ON_ENTER, true, "noJavadocOnEnter"); + addIfDiffers(set, cis.SMART_END_ACTION, true, "noSmartEnd"); + addIfDiffers(set, cis.JAVADOC_GENERATE_CLOSING_TAG, true, "noAutoCloseJavadocTags"); + addIfDiffers(set, cis.SURROUND_SELECTION_ON_QUOTE_TYPED, false, "surroundByQuoteOrBrace"); + addIfDiffers(set, cis.AUTOINSERT_PAIR_BRACKET, true, "noPairBracketAutoInsert"); + addIfDiffers(set, cis.AUTOINSERT_PAIR_QUOTE, true, "noPairQuoteAutoInsert"); + addIfDiffers(set, cis.REFORMAT_BLOCK_ON_RBRACE, true, "noReformatOnRBrace"); + addIfDiffers(set, cis.REFORMAT_ON_PASTE, CodeInsightSettings.INDENT_EACH_LINE, "reformatOnPaste"); + addIfDiffers(set, cis.ADD_IMPORTS_ON_PASTE, CodeInsightSettings.ASK, "importsOnPaste"); + addIfDiffers(set, cis.HIGHLIGHT_BRACES, true, "noBracesHighlight"); + addIfDiffers(set, cis.HIGHLIGHT_SCOPE, false, "scopeHighlight"); + addIfDiffers(set, cis.HIGHLIGHT_IDENTIFIER_UNDER_CARET, true, "noIdentifierUnderCaretHighlight"); + addIfDiffers(set, cis.OPTIMIZE_IMPORTS_ON_THE_FLY, false, "autoOptimizeImports"); + addIfDiffers(set, cis.ADD_UNAMBIGIOUS_IMPORTS_ON_THE_FLY, false, "autoAddImports"); + + return set; + } + + private static void addIfDiffers(Set set, boolean value, boolean defaultValue, String featureId) { + if (value != defaultValue) { + set.add(new UsageDescriptor(featureId, 1)); + } + } + + private static void addIfDiffers(Set set, Object value, Object defaultValue, String featureIdPrefix) { + if (!Comparing.equal(value, defaultValue)) { + set.add(new UsageDescriptor(featureIdPrefix + "." + value, 1)); + } + } +} diff --git a/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/header/ProfilesConfigurableComboBox.java b/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/header/ProfilesConfigurableComboBox.java index 3e8992f48012..36148ffb920e 100644 --- a/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/header/ProfilesConfigurableComboBox.java +++ b/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/header/ProfilesConfigurableComboBox.java @@ -77,7 +77,12 @@ public abstract class ProfilesConfigurableComboBox extends JPanel { mySaveListener.setDelegate(inputValidator); mySubmitNameComponent.setText(initialValue); myCardLayout.show(myComboBoxPanel, EDIT_CARD); - mySubmitNameComponent.requestFocus(); + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + mySubmitNameComponent.requestFocus(); + } + }); } public void reset(final Collection profiles) { diff --git a/platform/lang-impl/src/com/intellij/psi/codeStyle/autodetect/DetectableIndentOptionsProvider.java b/platform/lang-impl/src/com/intellij/psi/codeStyle/autodetect/DetectableIndentOptionsProvider.java index 1687817f5a22..7dc8bdbd2dd3 100644 --- a/platform/lang-impl/src/com/intellij/psi/codeStyle/autodetect/DetectableIndentOptionsProvider.java +++ b/platform/lang-impl/src/com/intellij/psi/codeStyle/autodetect/DetectableIndentOptionsProvider.java @@ -27,7 +27,7 @@ import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiFile; import com.intellij.psi.codeStyle.*; import com.intellij.testFramework.LightVirtualFile; -import com.intellij.ui.EditorNotifications; +import com.intellij.util.containers.ContainerUtil; import com.intellij.util.containers.WeakList; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -35,6 +35,8 @@ import org.jetbrains.annotations.TestOnly; import java.util.List; +import static com.intellij.psi.codeStyle.EditorNotificationInfo.*; + /** * @author Rustam Vishnyakov */ @@ -82,22 +84,21 @@ public class DetectableIndentOptionsProvider extends FileIndentOptionsProvider { @NotNull CommonCodeStyleSettings.IndentOptions userOptions, @NotNull CommonCodeStyleSettings.IndentOptions detectedOptions) { - NotificationLabels labels = getNotificationLabels(userOptions, detectedOptions); + final NotificationLabels labels = getNotificationLabels(userOptions, detectedOptions); final Editor editor = fileEditor instanceof TextEditor ? ((TextEditor)fileEditor).getEditor() : null; if (labels == null || editor == null) return null; - LabelWithAction okAction = new LabelWithAction( + ActionLabelData okAction = new ActionLabelData( ApplicationBundle.message("code.style.indents.detector.accept"), new Runnable() { @Override public void run() { setAccepted(file); - EditorNotifications.getInstance(project).updateAllNotifications(); } } ); - LabelWithAction disableForSingleFile = new LabelWithAction( + ActionLabelData disableForSingleFile = new ActionLabelData( labels.revertToOldSettingsLabel, new Runnable() { @Override @@ -106,24 +107,35 @@ public class DetectableIndentOptionsProvider extends FileIndentOptionsProvider { if (editor instanceof EditorEx) { ((EditorEx)editor).reinitSettings(); } - EditorNotifications.getInstance(project).updateAllNotifications(); } } ); - LabelWithAction showSettings = new LabelWithAction( + ActionLabelData showSettings = new ActionLabelData( ApplicationBundle.message("code.style.indents.detector.show.settings"), new Runnable() { @Override public void run() { ShowSettingsUtilImpl.showSettingsDialog(project, "preferences.sourceCode", ApplicationBundle.message("settings.code.style.general.autodetect.indents")); - EditorNotifications.getInstance(project).updateAllNotifications(); } } ); - return new EditorNotificationInfo(labels.title, okAction, disableForSingleFile, showSettings); + final List actions = ContainerUtil.newArrayList(okAction, disableForSingleFile, showSettings); + return new EditorNotificationInfo() { + @NotNull + @Override + public List getLabelAndActions() { + return actions; + } + + @NotNull + @Override + public String getTitle() { + return labels.title; + } + }; } @Nullable diff --git a/platform/lang-impl/src/com/intellij/psi/codeStyle/autodetect/DetectedIndentOptionsNotificationProvider.java b/platform/lang-impl/src/com/intellij/psi/codeStyle/autodetect/DetectedIndentOptionsNotificationProvider.java index b0be0cee284f..078d8f5eff0f 100644 --- a/platform/lang-impl/src/com/intellij/psi/codeStyle/autodetect/DetectedIndentOptionsNotificationProvider.java +++ b/platform/lang-impl/src/com/intellij/psi/codeStyle/autodetect/DetectedIndentOptionsNotificationProvider.java @@ -32,6 +32,8 @@ import com.intellij.util.Processor; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import static com.intellij.psi.codeStyle.EditorNotificationInfo.*; + /** * @author Rustam Vishnyakov */ @@ -77,8 +79,15 @@ public class DetectedIndentOptionsNotificationProvider extends EditorNotificatio if (info.getIcon() != null) { panel.icon(info.getIcon()); } - for (LabelWithAction action : info.getLabelAndActions()) { - panel.createActionLabel(action.label, action.action); + for (final ActionLabelData actionLabelData : info.getLabelAndActions()) { + Runnable onClickAction = new Runnable() { + @Override + public void run() { + actionLabelData.action.run(); + EditorNotifications.getInstance(project).updateAllNotifications(); + } + }; + panel.createActionLabel(actionLabelData.label, onClickAction); } return panel; } diff --git a/platform/platform-api/src/com/intellij/openapi/MnemonicContainerListener.java b/platform/platform-api/src/com/intellij/openapi/MnemonicContainerListener.java new file mode 100644 index 000000000000..fb3ffd1fe25d --- /dev/null +++ b/platform/platform-api/src/com/intellij/openapi/MnemonicContainerListener.java @@ -0,0 +1,79 @@ +/* + * Copyright 2000-2015 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; + +import javax.swing.CellRendererPane; +import java.awt.*; +import java.awt.event.ContainerEvent; +import java.awt.event.ContainerListener; + +/** + * @author Sergey.Malenkov + */ +final class MnemonicContainerListener implements ContainerListener { + void addTo(Component component) { + if (component == null || component instanceof CellRendererPane) { + return; + } + if (component instanceof Container) { + addTo((Container)component); + } + MnemonicWrapper.getWrapper(component); + } + + void removeFrom(Component component) { + if (component instanceof Container) { + removeFrom((Container)component); + } + } + + @Override + public void componentAdded(ContainerEvent event) { + addTo(event.getChild()); + } + + @Override + public void componentRemoved(ContainerEvent event) { + removeFrom(event.getChild()); + } + + private void addTo(Container container) { + if (!isAddedTo(container)) { + container.addContainerListener(this); + for (Component component : container.getComponents()) { + addTo(component); + } + } + } + + private void removeFrom(Container container) { + if (isAddedTo(container)) { + container.removeContainerListener(this); + for (Component component : container.getComponents()) { + removeFrom(component); + } + } + } + + private boolean isAddedTo(Container container) { + for (ContainerListener listener : container.getContainerListeners()) { + if (listener == this) { + return true; + } + } + return false; + } +} diff --git a/platform/platform-api/src/com/intellij/openapi/MnemonicHelper.java b/platform/platform-api/src/com/intellij/openapi/MnemonicHelper.java index 1e4577c58dac..e18ac0958634 100644 --- a/platform/platform-api/src/com/intellij/openapi/MnemonicHelper.java +++ b/platform/platform-api/src/com/intellij/openapi/MnemonicHelper.java @@ -42,6 +42,7 @@ import java.util.Map; * @since 5.1 */ public class MnemonicHelper extends ComponentTreeWatcher { + private static final MnemonicContainerListener LISTENER = new MnemonicContainerListener(); private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.MnemonicHelper"); private Map myMnemonics = null; @@ -57,6 +58,11 @@ public class MnemonicHelper extends ComponentTreeWatcher { }; @NonNls public static final String TEXT_CHANGED_PROPERTY = "text"; + /** + * @see #init(Component) + * @deprecated do not use this object as a tree watcher + */ + @Deprecated public MnemonicHelper() { super(ArrayUtil.EMPTY_CLASS_ARRAY); } @@ -143,4 +149,18 @@ public class MnemonicHelper extends ComponentTreeWatcher { "alt pressed " + mnemonic; return CustomShortcutSet.fromString(shortcut); } + + /** + * Initializes mnemonics support for the specified component and for its children if needed. + * + * @param component the root component of the hierarchy + */ + public static void init(Component component) { + if (Registry.is("ide.mnemonic.helper.old") || Registry.is("ide.checkDuplicateMnemonics")) { + new MnemonicHelper().register(component); + } + else { + LISTENER.addTo(component); + } + } } diff --git a/platform/platform-api/src/com/intellij/openapi/ui/DialogWrapper.java b/platform/platform-api/src/com/intellij/openapi/ui/DialogWrapper.java index 35f0b92cdb8b..bd6daff16513 100644 --- a/platform/platform-api/src/com/intellij/openapi/ui/DialogWrapper.java +++ b/platform/platform-api/src/com/intellij/openapi/ui/DialogWrapper.java @@ -1242,7 +1242,7 @@ public abstract class DialogWrapper { southSection.add(south, BorderLayout.SOUTH); } - new MnemonicHelper().register(root); + MnemonicHelper.init(root); if (!postponeValidation()) { startTrackingValidation(); } diff --git a/platform/platform-api/src/com/intellij/util/net/AuthenticationDialog.java b/platform/platform-api/src/com/intellij/util/net/AuthenticationDialog.java index 83cca8a039df..0f8c2495f929 100644 --- a/platform/platform-api/src/com/intellij/util/net/AuthenticationDialog.java +++ b/platform/platform-api/src/com/intellij/util/net/AuthenticationDialog.java @@ -30,7 +30,7 @@ public class AuthenticationDialog extends DialogWrapper { super(component, true); setTitle(title); - new MnemonicHelper().register(getContentPane()); + MnemonicHelper.init(getContentPane()); panel = new AuthenticationPanel(description, login, password, rememberPassword); final Window window = getWindow(); @@ -45,7 +45,7 @@ public class AuthenticationDialog extends DialogWrapper { super(JOptionPane.getRootFrame(), true); setTitle(title); - new MnemonicHelper().register(getContentPane()); + MnemonicHelper.init(getContentPane()); panel = new AuthenticationPanel(description, login, password, rememberPassword); final Window window = getWindow(); diff --git a/platform/platform-impl/src/com/intellij/openapi/application/ImportOldConfigsPanel.java b/platform/platform-impl/src/com/intellij/openapi/application/ImportOldConfigsPanel.java index d25f2949b347..1097409baaee 100644 --- a/platform/platform-impl/src/com/intellij/openapi/application/ImportOldConfigsPanel.java +++ b/platform/platform-impl/src/com/intellij/openapi/application/ImportOldConfigsPanel.java @@ -57,7 +57,7 @@ public class ImportOldConfigsPanel extends JDialog { } private void init() { - new MnemonicHelper().register(getContentPane()); + MnemonicHelper.init(getContentPane()); ButtonGroup group = new ButtonGroup(); group.add(myRbDoNotImport); diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/actions/EditorActionUtil.java b/platform/platform-impl/src/com/intellij/openapi/editor/actions/EditorActionUtil.java index 9ddac3c2aae5..e1c160f2f7f5 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/actions/EditorActionUtil.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/actions/EditorActionUtil.java @@ -198,9 +198,13 @@ public class EditorActionUtil { } } + int newSpacesEnd = lineStart + buf.length(); if (newCaretOffset >= spacesEnd) { newCaretOffset += buf.length() - (spacesEnd - lineStart); } + else if (newCaretOffset >= lineStart && newCaretOffset < spacesEnd && newCaretOffset > newSpacesEnd) { + newCaretOffset = newSpacesEnd; + } if (buf.length() > 0) { if (spacesEnd > lineStart) { diff --git a/platform/platform-impl/src/com/intellij/openapi/fileChooser/ex/FileChooserDialogImpl.java b/platform/platform-impl/src/com/intellij/openapi/fileChooser/ex/FileChooserDialogImpl.java index f022a4a92280..db2e8c7a6e84 100644 --- a/platform/platform-impl/src/com/intellij/openapi/fileChooser/ex/FileChooserDialogImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/fileChooser/ex/FileChooserDialogImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 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. @@ -46,6 +46,7 @@ import com.intellij.util.ArrayUtil; import com.intellij.util.Consumer; import com.intellij.util.IconUtil; import com.intellij.util.containers.HashMap; +import com.intellij.util.ui.JBUI; import com.intellij.util.ui.UIUtil; import com.intellij.util.ui.update.MergingUpdateQueue; import com.intellij.util.ui.update.UiNotifyConnector; @@ -55,7 +56,6 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import javax.swing.*; -import javax.swing.border.EmptyBorder; import javax.swing.event.TreeExpansionEvent; import javax.swing.event.TreeExpansionListener; import javax.swing.event.TreeSelectionEvent; @@ -286,7 +286,7 @@ public class FileChooserDialogImpl extends DialogWrapper implements FileChooserD final JLabel label = new JLabel(description); label.setBorder(BorderFactory.createCompoundBorder( new SideBorder(UIUtil.getPanelBackground().darker(), SideBorder.BOTTOM), - BorderFactory.createEmptyBorder(0, 5, 10, 5))); + JBUI.Borders.empty(0, 5, 10, 5))); return label; } @@ -297,7 +297,7 @@ public class FileChooserDialogImpl extends DialogWrapper implements FileChooserD Disposer.register(myDisposable, myUiUpdater); new UiNotifyConnector(panel, myUiUpdater); - panel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); + panel.setBorder(JBUI.Borders.empty()); createTree(); @@ -316,7 +316,7 @@ public class FileChooserDialogImpl extends DialogWrapper implements FileChooserD toolbarPanel.add(myTextFieldAction, BorderLayout.EAST); myPathTextFieldWrapper = new JPanel(new BorderLayout()); - myPathTextFieldWrapper.setBorder(new EmptyBorder(0, 0, 2, 0)); + myPathTextFieldWrapper.setBorder(JBUI.Borders.emptyBottom(2)); myPathTextField = new FileTextFieldImpl.Vfs( FileChooserFactoryImpl.getMacroMap(), getDisposable(), new LocalFsFinder.FileChooserFilter(myChooserDescriptor, myFileSystemTree)) { @@ -344,7 +344,7 @@ public class FileChooserDialogImpl extends DialogWrapper implements FileChooserD JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(myFileSystemTree.getTree()); //scrollPane.setBorder(BorderFactory.createLineBorder(new Color(148, 154, 156))); panel.add(scrollPane, BorderLayout.CENTER); - panel.setPreferredSize(new Dimension(400, 400)); + panel.setPreferredSize(JBUI.size(400)); panel.add(new JLabel( diff --git a/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UpdateChecker.java b/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UpdateChecker.java index 6bb4d1116278..1ced92ad9f97 100644 --- a/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UpdateChecker.java +++ b/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UpdateChecker.java @@ -566,7 +566,7 @@ public final class UpdateChecker { String bundledJdk = ""; String jdkMacRedist = System.getProperty("idea.java.redist"); - if (jdkMacRedist != null && jdkMacRedist.lastIndexOf("jdk-bundled") >= 0 ){ + if (jdkMacRedist != null && jdkMacRedist.lastIndexOf("jdk-bundled") >= 0) { bundledJdk = "jdk-bundled".equals(jdkMacRedist) ? "-jdk-bundled" : "-custom-jdk-bundled"; } diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/FloatingDecorator.java b/platform/platform-impl/src/com/intellij/openapi/wm/impl/FloatingDecorator.java index fb494bb140d7..5a0a20351c29 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/FloatingDecorator.java +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/FloatingDecorator.java @@ -66,7 +66,7 @@ public final class FloatingDecorator extends JDialog { FloatingDecorator(final IdeFrameImpl owner,final WindowInfoImpl info,final InternalDecorator internalDecorator){ super(owner,internalDecorator.getToolWindow().getId()); - new MnemonicHelper().register(getContentPane()); + MnemonicHelper.init(getContentPane()); myInternalDecorator=internalDecorator; setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/IdeFrameImpl.java b/platform/platform-impl/src/com/intellij/openapi/wm/impl/IdeFrameImpl.java index cbb8931a2225..a20bca20cd63 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/IdeFrameImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/IdeFrameImpl.java @@ -109,7 +109,7 @@ public class IdeFrameImpl extends JFrame implements IdeFrameEx, DataProvider { setFocusTraversalPolicy(layoutFocusTraversalPolicy); setupCloseAction(); - new MnemonicHelper().register(this); + MnemonicHelper.init(this); myBalloonLayout = new BalloonLayoutImpl(myRootPane, new Insets(8, 8, 8, 8)); diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/ProjectWindowAction.java b/platform/platform-impl/src/com/intellij/openapi/wm/impl/ProjectWindowAction.java index 15045cedc05c..7941484edafd 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/ProjectWindowAction.java +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/ProjectWindowAction.java @@ -21,6 +21,7 @@ import com.intellij.openapi.actionSystem.ToggleAction; import com.intellij.openapi.project.DumbAware; import com.intellij.openapi.project.Project; import com.intellij.openapi.project.ProjectManager; +import com.intellij.openapi.util.SystemInfo; import com.intellij.openapi.wm.WindowManager; import com.intellij.util.BitUtil; import org.jetbrains.annotations.NotNull; @@ -121,6 +122,12 @@ public class ProjectWindowAction extends ToggleAction implements DumbAware { } final JFrame projectFrame = WindowManager.getInstance().getFrame(project); final int frameState = projectFrame.getExtendedState(); + + if (SystemInfo.isMac && (projectFrame.getExtendedState() & Frame.ICONIFIED) != 0) { + // On Mac minimized window should not be restored this way + return; + } + if (BitUtil.isSet(frameState, Frame.ICONIFIED)) { // restore the frame if it is minimized projectFrame.setExtendedState(frameState ^ Frame.ICONIFIED); diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/welcomeScreen/FlatWelcomeFrame.java b/platform/platform-impl/src/com/intellij/openapi/wm/impl/welcomeScreen/FlatWelcomeFrame.java index 80d4739c5631..0da90ca293a1 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/welcomeScreen/FlatWelcomeFrame.java +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/welcomeScreen/FlatWelcomeFrame.java @@ -113,7 +113,7 @@ public class FlatWelcomeFrame extends JFrame implements IdeFrame { myBalloonLayout = new BalloonLayoutImpl(rootPane, new JBInsets(8, 8, 8, 8)); WelcomeFrame.setupCloseAction(this); - new MnemonicHelper().register(this); + MnemonicHelper.init(this); Disposer.register(ApplicationManager.getApplication(), new Disposable() { @Override public void dispose() { diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/welcomeScreen/WelcomeFrame.java b/platform/platform-impl/src/com/intellij/openapi/wm/impl/welcomeScreen/WelcomeFrame.java index d638fde23562..339f6a3e76a3 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/welcomeScreen/WelcomeFrame.java +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/welcomeScreen/WelcomeFrame.java @@ -80,7 +80,7 @@ public class WelcomeFrame extends JFrame implements IdeFrame { myScreen = screen; setupCloseAction(this); - new MnemonicHelper().register(this); + MnemonicHelper.init(this); myScreen.setupFrame(this); Disposer.register(ApplicationManager.getApplication(), new Disposable() { @Override diff --git a/platform/platform-resources-en/src/messages/XmlBundle.properties b/platform/platform-resources-en/src/messages/XmlBundle.properties index a1995ad5bb2b..6388c4b08a5d 100644 --- a/platform/platform-resources-en/src/messages/XmlBundle.properties +++ b/platform/platform-resources-en/src/messages/XmlBundle.properties @@ -32,6 +32,8 @@ html.inspections.check.image.width.fix.message=Set width value to {0} html.inspections.check.image.height.message=Original image height is {0} html.inspections.check.image.height.fix.message=Set height value to {0} html.inspections.check.deprecated.tag=Deprecated HTML tag +html.intentions.insert.image.size=Insert background-image size +html.intentions.update.image.size=Update background-image size unwrap.enclosing.tag.name.action.name=Remove Enclosing Tag {0} jsp.inspections.group.name=JSP Inspections # color dialog @@ -218,7 +220,7 @@ select.xsd.schema.dialog.title=Select XSD Schema emmet.title=Emmet emmet.update.tag.title=Update tag with Emmet emmet.configuration.title=Emmet -emmet.enable.label=&Enable XML Emmet +emmet.enable.label=&Enable XML/HTML Emmet emmet.filters.enabled.by.default=Filters enabled by default emmet.enable.preview=Enable &abbreviation preview emmet.expand.abbreviation.with=Expand &abbreviation with diff --git a/platform/platform-resources/src/META-INF/LangExtensions.xml b/platform/platform-resources/src/META-INF/LangExtensions.xml index 65f8821d530a..091211c6d028 100644 --- a/platform/platform-resources/src/META-INF/LangExtensions.xml +++ b/platform/platform-resources/src/META-INF/LangExtensions.xml @@ -813,6 +813,7 @@ + diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/editor/actions/EditorActionTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/editor/actions/EditorActionTest.java index 2545df56d20c..13381591fb4d 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/editor/actions/EditorActionTest.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/editor/actions/EditorActionTest.java @@ -22,6 +22,7 @@ import com.intellij.openapi.editor.ex.EditorEx; import com.intellij.openapi.editor.impl.AbstractEditorTest; import com.intellij.openapi.ide.CopyPasteManager; import com.intellij.testFramework.EditorTestUtil; +import com.intellij.testFramework.LightPlatformCodeInsightTestCase; import com.intellij.testFramework.TestFileType; import java.awt.datatransfer.StringSelection; @@ -187,4 +188,10 @@ public class EditorActionTest extends AbstractEditorTest { "blah blah\n" + "blah blah"); } + + public void testCaretComesBeforeTextOnUnindent() throws IOException { + initText(" text"); + unindent(); + checkResultByText(" text"); + } } \ No newline at end of file diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/progress/impl/ProgressIndicatorTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/progress/impl/ProgressIndicatorTest.java index e172c7d55f52..1b3f39f2546d 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/progress/impl/ProgressIndicatorTest.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/progress/impl/ProgressIndicatorTest.java @@ -55,7 +55,9 @@ public class ProgressIndicatorTest extends LightPlatformTestCase { } catch(ProcessCanceledException ex) { boolean isInternal = SystemProperties.getBooleanProperty("idea.is.internal", false); - assertTrue("Should have no stackframe", isInternal ? ex.getStackTrace().length != 0 : ex.getStackTrace().length == 0); + boolean isTest = SystemProperties.getBooleanProperty("idea.is.unit.test", false); + boolean hasStackFrame = ex.getStackTrace().length != 0; + assertTrue("Should have no stackframe", (isInternal || isTest) == hasStackFrame); } } @@ -112,7 +114,7 @@ public class ProgressIndicatorTest extends LightPlatformTestCase { }, "", false, getProject(), null, ""); long averageDelay = PlatformTestUtil.averageAmongMedians(times.toNativeArray(), 5); System.out.println("averageDelay = " + averageDelay); - assertTrue(averageDelay < ProgressManagerImpl.CHECK_CANCELED_DELAY_MILLIS*3); + assertTrue(averageDelay < CoreProgressManager.CHECK_CANCELED_DELAY_MILLIS *3); } public void testProgressIndicatorUtilsScheduleWithWriteActionPriority() throws Throwable { @@ -133,7 +135,7 @@ public class ProgressIndicatorTest extends LightPlatformTestCase { }); UIUtil.dispatchAllInvocationEvents(); while (!insideReadAction.get()) { - ; + } ApplicationManager.getApplication().runWriteAction(new Runnable() { @Override @@ -316,11 +318,11 @@ public class ProgressIndicatorTest extends LightPlatformTestCase { ProgressManager.getInstance().executeProcessUnderProgress(new Runnable() { @Override public void run() { - assertFalse(ProgressManagerImpl.threadsUnderCanceledIndicator.contains(Thread.currentThread())); + assertFalse(CoreProgressManager.threadsUnderCanceledIndicator.contains(Thread.currentThread())); ProgressIndicator indicator = ProgressIndicatorProvider.getGlobalProgressIndicator(); assertTrue(indicator != null && !indicator.isCanceled()); indicator.cancel(); - assertTrue(ProgressManagerImpl.threadsUnderCanceledIndicator.contains(Thread.currentThread())); + assertTrue(CoreProgressManager.threadsUnderCanceledIndicator.contains(Thread.currentThread())); assertTrue(indicator.isCanceled()); final ProgressIndicatorEx nested = new ProgressIndicatorBase(); nested.addStateDelegate(new ProgressIndicatorStub() { @@ -332,7 +334,7 @@ public class ProgressIndicatorTest extends LightPlatformTestCase { ProgressManager.getInstance().executeProcessUnderProgress(new Runnable() { @Override public void run() { - assertFalse(ProgressManagerImpl.threadsUnderCanceledIndicator.contains(Thread.currentThread())); + assertFalse(CoreProgressManager.threadsUnderCanceledIndicator.contains(Thread.currentThread())); ProgressIndicator indicator2 = ProgressIndicatorProvider.getGlobalProgressIndicator(); assertTrue(indicator2 != null && !indicator2.isCanceled()); assertSame(indicator2, nested); @@ -343,7 +345,7 @@ public class ProgressIndicatorTest extends LightPlatformTestCase { ProgressIndicator indicator3 = ProgressIndicatorProvider.getGlobalProgressIndicator(); assertSame(indicator, indicator3); - assertTrue(ProgressManagerImpl.threadsUnderCanceledIndicator.contains(Thread.currentThread())); + assertTrue(CoreProgressManager.threadsUnderCanceledIndicator.contains(Thread.currentThread())); } }, new EmptyProgressIndicator()); assertFalse(checkCanceledCalled); @@ -386,10 +388,10 @@ public class ProgressIndicatorTest extends LightPlatformTestCase { ProgressManager.getInstance().executeProcessUnderProgress(new Runnable() { @Override public void run() { - assertFalse(ProgressManagerImpl.threadsUnderCanceledIndicator.contains(Thread.currentThread())); + assertFalse(CoreProgressManager.threadsUnderCanceledIndicator.contains(Thread.currentThread())); assertTrue(!progress.isCanceled()); progress.cancel(); - assertTrue(ProgressManagerImpl.threadsUnderCanceledIndicator.contains(Thread.currentThread())); + assertTrue(CoreProgressManager.threadsUnderCanceledIndicator.contains(Thread.currentThread())); assertTrue(progress.isCanceled()); while (true) { // wait for PCE ProgressManager.checkCanceled(); diff --git a/platform/projectModel-api/src/com/intellij/openapi/roots/ex/ProjectRootManagerEx.java b/platform/projectModel-api/src/com/intellij/openapi/roots/ex/ProjectRootManagerEx.java index 5b9164fd5579..9358d9242449 100644 --- a/platform/projectModel-api/src/com/intellij/openapi/roots/ex/ProjectRootManagerEx.java +++ b/platform/projectModel-api/src/com/intellij/openapi/roots/ex/ProjectRootManagerEx.java @@ -37,7 +37,10 @@ public abstract class ProjectRootManagerEx extends ProjectRootManager { public abstract void clearScopesCachesForModules(); - + /** + * @see ProjectRootManagerEx#addProjectJdkListener(ProjectJdkListener) + * @see ProjectRootManagerEx#removeProjectJdkListener(ProjectJdkListener) + */ public interface ProjectJdkListener extends EventListener { void projectJdkChanged(); } diff --git a/platform/projectModel-impl/src/com/intellij/openapi/module/impl/ModuleManagerImpl.java b/platform/projectModel-impl/src/com/intellij/openapi/module/impl/ModuleManagerImpl.java index c19ba91e3346..e122fd11c826 100644 --- a/platform/projectModel-impl/src/com/intellij/openapi/module/impl/ModuleManagerImpl.java +++ b/platform/projectModel-impl/src/com/intellij/openapi/module/impl/ModuleManagerImpl.java @@ -504,7 +504,7 @@ public abstract class ModuleManagerImpl extends ModuleManager implements Project return myModuleModel.getModules(); } - private Module[] myCachedSortedModules = null; + private volatile Module[] myCachedSortedModules = null; @Override @NotNull @@ -523,7 +523,7 @@ public abstract class ModuleManagerImpl extends ModuleManager implements Project return myModuleModel.findModuleByName(name); } - private Comparator myCachedModuleComparator = null; + private volatile Comparator myCachedModuleComparator = null; @Override @NotNull @@ -602,7 +602,7 @@ public abstract class ModuleManagerImpl extends ModuleManager implements Project class ModuleModelImpl implements ModifiableModuleModel { final Map myPathToModule = new LinkedHashMap(new EqualityPolicy.ByHashingStrategy(FilePathHashingStrategy.create())); - private Module[] myModulesCache; + private volatile Module[] myModulesCache; private final List myModulesToDispose = new ArrayList(); private final Map myModuleToNewName = new HashMap(); diff --git a/platform/projectModel-impl/src/com/intellij/openapi/roots/ProjectExtension.java b/platform/projectModel-impl/src/com/intellij/openapi/roots/ProjectExtension.java index f4e5bc76eb0d..7c1c395cc0f6 100644 --- a/platform/projectModel-impl/src/com/intellij/openapi/roots/ProjectExtension.java +++ b/platform/projectModel-impl/src/com/intellij/openapi/roots/ProjectExtension.java @@ -21,8 +21,12 @@ package com.intellij.openapi.roots; import com.intellij.openapi.extensions.ExtensionPointName; +import com.intellij.openapi.projectRoots.Sdk; import com.intellij.openapi.util.JDOMExternalizable; +import org.jetbrains.annotations.Nullable; public abstract class ProjectExtension implements JDOMExternalizable{ public static final ExtensionPointName EP_NAME = ExtensionPointName.create("com.intellij.projectExtension"); + + public void projectSdkChanged(@Nullable Sdk sdk) {} } \ No newline at end of file diff --git a/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/ProjectRootManagerImpl.java b/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/ProjectRootManagerImpl.java index c439a35d0a36..42098948966f 100644 --- a/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/ProjectRootManagerImpl.java +++ b/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/ProjectRootManagerImpl.java @@ -231,12 +231,20 @@ public class ProjectRootManagerImpl extends ProjectRootManagerEx implements Proj myProjectSdkName = sdk.getName(); myProjectSdkType = sdk.getSdkType().getName(); } + projectJdkChanged(); + } + + private void projectJdkChanged() { mergeRootsChangesDuring(new Runnable() { @Override public void run() { myProjectJdkEventDispatcher.getMulticaster().projectJdkChanged(); } }); + Sdk sdk = getProjectSdk(); + for (ProjectExtension extension : Extensions.getExtensions(ProjectExtension.EP_NAME, myProject)) { + extension.projectSdkChanged(sdk); + } } @Override @@ -244,12 +252,7 @@ public class ProjectRootManagerImpl extends ProjectRootManagerEx implements Proj ApplicationManager.getApplication().assertWriteAccessAllowed(); myProjectSdkName = name; - mergeRootsChangesDuring(new Runnable() { - @Override - public void run() { - myProjectJdkEventDispatcher.getMulticaster().projectJdkChanged(); - } - }); + projectJdkChanged(); } @Override diff --git a/platform/projectModel-impl/src/messages/ProjectBundle.properties b/platform/projectModel-impl/src/messages/ProjectBundle.properties index 4b31b4aaca45..acf81ec454ef 100644 --- a/platform/projectModel-impl/src/messages/ProjectBundle.properties +++ b/platform/projectModel-impl/src/messages/ProjectBundle.properties @@ -246,7 +246,7 @@ libraries.node.text.module=Libraries contain classes that add up various functio \ To attach a library to a module, select that module, click the Dependencies tab, click Add and specify the library location. jdks.node.display.name=SDKs -project.language.level.combo.item= +project.language.level.combo.item=Project default add.action.name=Add new ... add.new.jdk.text=Add New SDK add.new.global.library.text=New Global Library diff --git a/platform/structuralsearch/testSource/com/intellij/structuralsearch/StructuralSearchTest.java b/platform/structuralsearch/testSource/com/intellij/structuralsearch/StructuralSearchTest.java index 23250d8fe2fe..c57c93805464 100644 --- a/platform/structuralsearch/testSource/com/intellij/structuralsearch/StructuralSearchTest.java +++ b/platform/structuralsearch/testSource/com/intellij/structuralsearch/StructuralSearchTest.java @@ -2476,6 +2476,14 @@ public class StructuralSearchTest extends StructuralSearchTestCase { "@Deprecated\n" + "package one.two;"; assertEquals("Find annotation on package statement", 1, findMatchesCount(source4, "@'_Annotation", true)); + + final String source5 ="class A {" + + " boolean a(Object o) {" + + " return o instanceof @HH String;" + + " }" + + "}"; + assertEquals("Find annotation on instanceof expression", 1, findMatchesCount(source5, "'_a instanceof @HH String")); + assertEquals("Match annotation correctly on instanceof expression", 0, findMatchesCount(source5, "'_a instanceof @GG String")); } public void testBoxingAndUnboxing() { diff --git a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java index 0b958006e33a..37c08ee7baf9 100644 --- a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java +++ b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java @@ -1624,7 +1624,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig DaemonCodeAnalyzerImpl codeAnalyzer = (DaemonCodeAnalyzerImpl)DaemonCodeAnalyzer.getInstance(project); TextEditor textEditor = TextEditorProvider.getInstance().getTextEditor(editor); ProcessCanceledException exception = null; - for (int i = 0; i < 100; i++) { + for (int i = 0; i < 1000; i++) { try { List infos = codeAnalyzer.runPasses(file, editor.getDocument(), textEditor, toIgnore, canChangeDocument, null); infos.addAll(DaemonCodeAnalyzerEx.getInstanceEx(project).getFileLevelHighlights(project, file)); diff --git a/platform/util/resources/misc/registry.properties b/platform/util/resources/misc/registry.properties index 0136a7f74244..4cc3d152fc74 100644 --- a/platform/util/resources/misc/registry.properties +++ b/platform/util/resources/misc/registry.properties @@ -54,6 +54,9 @@ ide.popup.resizable.border.sensitivity=4 ide.consumeKnownToolkitBugs=true ide.highlight.match.in.selected.only=true ide.lazyIconLoading=true +ide.mnemonic.helper.old=true +ide.mnemonic.helper.old.restartRequired=true +ide.mnemonic.helper.old.description=Use new algorithm of mnemonics processing ide.checkDuplicateMnemonics=false ide.checkDuplicateMnemonics.description=Check for duplicate mnemonics. ide.dnd.textHints=false diff --git a/platform/util/src/com/intellij/openapi/progress/ProcessCanceledException.java b/platform/util/src/com/intellij/openapi/progress/ProcessCanceledException.java index e6133b255411..0cdde2c48e87 100644 --- a/platform/util/src/com/intellij/openapi/progress/ProcessCanceledException.java +++ b/platform/util/src/com/intellij/openapi/progress/ProcessCanceledException.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 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,7 +18,7 @@ package com.intellij.openapi.progress; import com.intellij.util.SystemProperties; public class ProcessCanceledException extends RuntimeException { - private static final boolean ourHasStackTraces = SystemProperties.getBooleanProperty("idea.is.internal", false); + private static final boolean ourHasStackTraces = SystemProperties.getBooleanProperty("idea.is.internal", false) || SystemProperties.getBooleanProperty("idea.is.unit.test", false); public ProcessCanceledException() { } diff --git a/platform/util/src/com/intellij/util/Restarter.java b/platform/util/src/com/intellij/util/Restarter.java index 3e8692d7b9bd..aa0f024463a5 100644 --- a/platform/util/src/com/intellij/util/Restarter.java +++ b/platform/util/src/com/intellij/util/Restarter.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 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. @@ -54,7 +54,7 @@ public class Restarter { public static boolean isSupported() { if (getRestartCode() != 0) return true; - if (SystemInfo.isWindows) return true; + if (SystemInfo.isWindows) return new File(PathManager.getBinPath(), "restarter.exe").exists(); if (SystemInfo.isMac) return PathManager.getHomePath().contains(".app"); return false; } diff --git a/platform/vcs-log/graph/src/com/intellij/vcs/log/graph/api/printer/PrintElementGenerator.java b/platform/vcs-log/graph/src/com/intellij/vcs/log/graph/api/printer/PrintElementGenerator.java index 16b787447af0..1ed689cde270 100644 --- a/platform/vcs-log/graph/src/com/intellij/vcs/log/graph/api/printer/PrintElementGenerator.java +++ b/platform/vcs-log/graph/src/com/intellij/vcs/log/graph/api/printer/PrintElementGenerator.java @@ -29,6 +29,4 @@ public interface PrintElementGenerator { @NotNull PrintElementWithGraphElement toPrintElementWithGraphElement(@NotNull PrintElement printElement); - - void invalidate(); } diff --git a/platform/vcs-log/graph/src/com/intellij/vcs/log/graph/impl/facade/VisibleGraphImpl.java b/platform/vcs-log/graph/src/com/intellij/vcs/log/graph/impl/facade/VisibleGraphImpl.java index bfbd5bc54825..c230e0fc0fa6 100644 --- a/platform/vcs-log/graph/src/com/intellij/vcs/log/graph/impl/facade/VisibleGraphImpl.java +++ b/platform/vcs-log/graph/src/com/intellij/vcs/log/graph/impl/facade/VisibleGraphImpl.java @@ -142,8 +142,12 @@ public class VisibleGraphImpl implements VisibleGraph { targetId = edge.getTargetId(); } if (edge.getType().isNormalEdge()) { - if (printElementType == DOWN_ARROW) targetId = convertToNodeId(edge.getDownNodeIndex()); - else targetId = convertToNodeId(edge.getUpNodeIndex()); + if (printElementType == DOWN_ARROW) { + targetId = convertToNodeId(edge.getDownNodeIndex()); + } + else { + targetId = convertToNodeId(edge.getUpNodeIndex()); + } } if (targetId == null) return null; @@ -198,7 +202,14 @@ public class VisibleGraphImpl implements VisibleGraph { CommitId commitToJump = null; Integer nodeId = answer.getCommitToJump(); if (nodeId != null) commitToJump = myPermanentGraph.getPermanentCommitsInfo().getCommitId(nodeId); - return new GraphAnswerImpl(answer.getCursorToSet(), commitToJump, answer.getGraphUpdater()); + final Runnable graphUpdater = answer.getGraphUpdater(); + return new GraphAnswerImpl(answer.getCursorToSet(), commitToJump, graphUpdater == null ? null : new Runnable() { + @Override + public void run() { + graphUpdater.run(); + updatePrintElementGenerator(); + } + }); } } diff --git a/platform/vcs-log/graph/src/com/intellij/vcs/log/graph/impl/print/PrintElementGeneratorImpl.java b/platform/vcs-log/graph/src/com/intellij/vcs/log/graph/impl/print/PrintElementGeneratorImpl.java index 6e9061d54ec4..63bfeaced5c0 100644 --- a/platform/vcs-log/graph/src/com/intellij/vcs/log/graph/impl/print/PrintElementGeneratorImpl.java +++ b/platform/vcs-log/graph/src/com/intellij/vcs/log/graph/impl/print/PrintElementGeneratorImpl.java @@ -203,12 +203,6 @@ public class PrintElementGeneratorImpl extends AbstractPrintElementGenerator { result.add(new SimpleRowElement(edge, SimplePrintElement.Type.UP_ARROW, position)); } - @Override - public void invalidate() { - myEdgesInRowGenerator.invalidate(); - cache.clear(); - } - private boolean edgeIsVisibleInRow(@NotNull GraphEdge edge, int visibleRowIndex) { Pair normalEdge = LinearGraphUtils.asNormalEdge(edge); if (normalEdge == null) // e.d. edge is special. See addSpecialEdges diff --git a/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/VcsLogUiImpl.java b/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/VcsLogUiImpl.java index 8a3260ca3ef4..f2e345ce044b 100644 --- a/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/VcsLogUiImpl.java +++ b/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/VcsLogUiImpl.java @@ -17,19 +17,15 @@ import com.intellij.vcs.log.data.VcsLogFilterer; import com.intellij.vcs.log.data.VcsLogUiProperties; import com.intellij.vcs.log.data.VisiblePack; import com.intellij.vcs.log.graph.PermanentGraph; -import com.intellij.vcs.log.graph.VisibleGraph; import com.intellij.vcs.log.graph.actions.GraphAction; import com.intellij.vcs.log.graph.actions.GraphAnswer; import com.intellij.vcs.log.impl.VcsLogImpl; import com.intellij.vcs.log.ui.frame.MainFrame; import com.intellij.vcs.log.ui.frame.VcsLogGraphTable; import com.intellij.vcs.log.ui.tables.GraphTableModel; -import gnu.trove.TIntHashSet; -import gnu.trove.TIntProcedure; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import javax.swing.table.AbstractTableModel; import javax.swing.table.TableModel; import java.awt.*; import java.util.ArrayList; @@ -79,7 +75,7 @@ public class VcsLogUiImpl implements VcsLogUi, Disposable { ApplicationManager.getApplication().assertIsDispatchThread(); PermanentGraph previousPermGraph = myVisiblePack.getPermanentGraph(); - TIntHashSet previouslySelected = getSelectedCommits(); + VcsLogGraphTable.Selection previousSelection = getTable().getSelection(); myVisiblePack = pack; boolean permGraphChanged = previousPermGraph != myVisiblePack.getPermanentGraph(); @@ -90,7 +86,7 @@ public class VcsLogUiImpl implements VcsLogUi, Disposable { } else { currentModel.setVisiblePack(myVisiblePack); - restoreSelection(currentModel, myVisiblePack.getVisibleGraph(), previouslySelected, getTable()); + previousSelection.restore(myVisiblePack.getVisibleGraph()); } getTable().setPaintBusy(false); @@ -105,42 +101,6 @@ public class VcsLogUiImpl implements VcsLogUi, Disposable { return myMainFrame; } - private static void restoreSelection(@NotNull GraphTableModel newModel, - @NotNull VisibleGraph newVisibleGraph, - @NotNull TIntHashSet previouslySelectedCommits, - @NotNull final VcsLogGraphTable table) { - TIntHashSet rowsToSelect = findNewRowsToSelect(newModel, newVisibleGraph, previouslySelectedCommits); - rowsToSelect.forEach(new TIntProcedure() { - @Override - public boolean execute(int row) { - table.addRowSelectionInterval(row, row); - return true; - } - }); - } - - @NotNull - private static TIntHashSet findNewRowsToSelect(@NotNull GraphTableModel newModel, - @NotNull VisibleGraph visibleGraph, - @NotNull TIntHashSet selectedHashes) { - TIntHashSet rowsToSelect = new TIntHashSet(); - if (newModel.getRowCount() == 0) { - // this should have been covered by facade.getVisibleCommitCount, - // but if the table is empty (no commits match the filter), the GraphFacade is not updated, because it can't handle it - // => it has previous values set. - return rowsToSelect; - } - for (int row = 0; - row < visibleGraph.getVisibleCommitCount() && rowsToSelect.size() < selectedHashes.size(); - row++) { //stop iterating if found all hashes - int commit = visibleGraph.getRowInfo(row).getCommit(); - if (selectedHashes.contains(commit)) { - rowsToSelect.add(row); - } - } - return rowsToSelect; - } - public void repaintUI() { myMainFrame.getGraphTable().repaint(); } @@ -156,7 +116,7 @@ public class VcsLogUiImpl implements VcsLogUi, Disposable { public void run() { assert updater != null : "Action:" + title + "\nController: " + myVisiblePack.getVisibleGraph().getActionController() + "\nAnswer:" + answer; updater.run(); - handleAnswer(answer, true); + getTable().handleAnswer(answer, true, null); } }); } @@ -226,31 +186,6 @@ public class VcsLogUiImpl implements VcsLogUi, Disposable { return future; } - public void handleAnswer(@Nullable GraphAnswer answer, boolean dataCouldChange) { - if (dataCouldChange) { - ((AbstractTableModel)(getTable().getModel())).fireTableDataChanged(); - } - - repaintUI(); - - if (answer == null) { - return; - } - - if (answer.getCursorToSet() != null) { - myMainFrame.getGraphTable().setCursor(answer.getCursorToSet()); - } - if (answer.getCommitToJump() != null) { - int row = myVisiblePack.getVisibleGraph().getVisibleRowIndex(answer.getCommitToJump()); - if (row >= 0) { - myMainFrame.getGraphTable().jumpToRow(row); - } - else { - // TODO wait for the full log and then jump - } - } - } - private void jumpTo(@NotNull final T commitId, @NotNull final PairFunction rowGetter, @NotNull final SettableFuture future) { @@ -327,23 +262,6 @@ public class VcsLogUiImpl implements VcsLogUi, Disposable { return myColorManager; } - @NotNull - public TIntHashSet getSelectedCommits() { - int[] selectedRows = getTable().getSelectedRows(); - return getCommitsAtRows(myVisiblePack.getVisibleGraph(), selectedRows); - } - - @NotNull - private static TIntHashSet getCommitsAtRows(@NotNull VisibleGraph graph, int[] rows) { - TIntHashSet commits = new TIntHashSet(); - for (int row : rows) { - if (row < graph.getVisibleCommitCount()) { - commits.add(graph.getRowInfo(row).getCommit()); - } - } - return commits; - } - public void applyFiltersAndUpdateUi() { VcsLogFilterCollection filters = myMainFrame.getFilterUi().getFilters(); myFilterer.onFiltersChange(filters); diff --git a/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/frame/VcsLogGraphTable.java b/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/frame/VcsLogGraphTable.java index 933fe986b943..ab79d9af9be1 100644 --- a/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/frame/VcsLogGraphTable.java +++ b/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/frame/VcsLogGraphTable.java @@ -38,10 +38,7 @@ import com.intellij.vcs.log.VcsFullCommitDetails; import com.intellij.vcs.log.VcsLogHighlighter; import com.intellij.vcs.log.data.VcsLogDataHolder; import com.intellij.vcs.log.data.VisiblePack; -import com.intellij.vcs.log.graph.ColorGenerator; -import com.intellij.vcs.log.graph.PrintElement; -import com.intellij.vcs.log.graph.RowInfo; -import com.intellij.vcs.log.graph.RowType; +import com.intellij.vcs.log.graph.*; import com.intellij.vcs.log.graph.actions.GraphAction; import com.intellij.vcs.log.graph.actions.GraphAnswer; import com.intellij.vcs.log.printer.idea.GraphCellPainter; @@ -52,11 +49,14 @@ import com.intellij.vcs.log.ui.VcsLogUiImpl; import com.intellij.vcs.log.ui.render.GraphCommitCell; import com.intellij.vcs.log.ui.render.GraphCommitCellRender; import com.intellij.vcs.log.ui.tables.GraphTableModel; +import gnu.trove.TIntHashSet; +import gnu.trove.TIntProcedure; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import sun.swing.table.DefaultTableCellHeaderRenderer; import javax.swing.*; +import javax.swing.event.CellEditorListener; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import javax.swing.event.TableModelEvent; @@ -65,9 +65,7 @@ import java.awt.*; import java.awt.datatransfer.StringSelection; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; -import java.util.Collection; -import java.util.Collections; -import java.util.Date; +import java.util.*; import java.util.List; import static com.intellij.vcs.log.printer.idea.PrintParameters.HEIGHT_CELL; @@ -85,6 +83,7 @@ public class VcsLogGraphTable extends JBTable implements TypeSafeDataProvider, C @NotNull private final VcsLogUiImpl myUI; private final VcsLogDataHolder myLogDataHolder; private final GraphCommitCellRender myGraphCommitCellRender; + private final MyDummyTableCellEditor myDummyEditor = new MyDummyTableCellEditor(); private boolean myColumnsSizeInitialized = false; @@ -364,6 +363,103 @@ public class VcsLogGraphTable extends JBTable implements TypeSafeDataProvider, C }); } + public void handleAnswer(@Nullable GraphAnswer answer, boolean dataCouldChange, @Nullable Selection previousSelection) { + if (dataCouldChange) { + GraphTableModel graphTableModel = (GraphTableModel)getModel(); + + graphTableModel.fireTableDataChanged(); + + // since fireTableDataChanged clears selection we restore it here + if (previousSelection != null) { + previousSelection.restore(myDataPack.getVisibleGraph()); + } + } + + myUI.repaintUI(); // in case of repaintUI doing something more than just repainting this table in some distant future + + if (answer == null) { + return; + } + + if (answer.getCursorToSet() != null) { + setCursor(answer.getCursorToSet()); + } + if (answer.getCommitToJump() != null) { + Integer row = myDataPack.getVisibleGraph().getVisibleRowIndex(answer.getCommitToJump()); + if (row != null && row >= 0) { + jumpToRow(row); + } + // TODO wait for the full log and then jump + } + } + + private GraphTableModel getGraphTableModel() { + return (GraphTableModel)getModel(); + } + + @NotNull + public Selection getSelection() { + return new Selection(); + } + + public class Selection { + private final TIntHashSet myCommits; + + public Selection() { + myCommits = getCommitsAtRows(myDataPack.getVisibleGraph(), getSelectedRows()); + } + + public void restore(@NotNull VisibleGraph newVisibleGraph) { + TIntHashSet rowsToSelect = findNewRowsToSelect(getGraphTableModel(), newVisibleGraph, myCommits); + if (!rowsToSelect.isEmpty()) { + rowsToSelect.forEach(new TIntProcedure() { + @Override + public boolean execute(int row) { + addRowSelectionInterval(row, row); + return true; + } + }); + } + // sometimes commits that were selected are now collapsed + // currently in this case selection disappears + // in the future we need to create a method in LinearGraphController that allows to calculate visible commit for our commit + // or answer from collapse action could return a map that gives us some information about what commits were collapsed and where + } + + @NotNull + private TIntHashSet findNewRowsToSelect(@NotNull GraphTableModel newModel, + @NotNull VisibleGraph visibleGraph, + @NotNull TIntHashSet selectedHashes) { + TIntHashSet rowsToSelect = new TIntHashSet(); + if (newModel.getRowCount() == 0) { + // this should have been covered by facade.getVisibleCommitCount, + // but if the table is empty (no commits match the filter), the GraphFacade is not updated, because it can't handle it + // => it has previous values set. + return rowsToSelect; + } + for (int row = 0; + row < visibleGraph.getVisibleCommitCount() && rowsToSelect.size() < selectedHashes.size(); + row++) { //stop iterating if found all hashes + int commit = visibleGraph.getRowInfo(row).getCommit(); + if (selectedHashes.contains(commit)) { + rowsToSelect.add(row); + } + } + return rowsToSelect; + } + + @NotNull + private TIntHashSet getCommitsAtRows(@NotNull VisibleGraph graph, int[] rows) { + TIntHashSet commits = new TIntHashSet(); + for (int row : rows) { + if (row < graph.getVisibleCommitCount()) { + commits.add(graph.getRowInfo(row).getCommit()); + } + } + return commits; + } + } + private class MyHeaderMouseAdapter extends MouseAdapter { @Override public void mouseMoved(MouseEvent e) { @@ -423,11 +519,13 @@ public class VcsLogGraphTable extends JBTable implements TypeSafeDataProvider, C Collection printElements = myDataPack.getVisibleGraph().getRowInfo(row).getPrintElements(); PrintElement printElement = myGraphCellPainter.mouseOver(printElements, point.x, point.y); + Selection previousSelection = getSelection(); GraphAnswer answer = myDataPack.getVisibleGraph().getActionController().performAction(new GraphAction.GraphActionImpl(printElement, actionType)); - myUI.handleAnswer(answer, actionType == GraphAction.Type.MOUSE_CLICK && printElement != null); + handleAnswer(answer, actionType == GraphAction.Type.MOUSE_CLICK && printElement != null, previousSelection); } + private boolean isAboveLink(MouseEvent e) { return myLinkListener.getTagAt(e) != null; } @@ -532,6 +630,13 @@ public class VcsLogGraphTable extends JBTable implements TypeSafeDataProvider, C } } + @Override + public TableCellEditor getCellEditor() { + // this fixes selection problems by prohibiting selection when user clicks on graph (CellEditor does that) + // what is fun about this code is that if you set cell editor in constructor with setCellEditor method it would not work + return myDummyEditor; + } + private class StringCellRenderer extends ColoredTableCellRenderer { @Override protected void customizeCellRenderer(JTable table, Object value, boolean selected, boolean hasFocus, int row, int column) { @@ -577,4 +682,55 @@ public class VcsLogGraphTable extends JBTable implements TypeSafeDataProvider, C } } + private class MyDummyTableCellEditor implements TableCellEditor { + @Override + public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { + return null; + } + + @Override + public Object getCellEditorValue() { + return null; + } + + @Override + public boolean isCellEditable(EventObject anEvent) { + return false; + } + + @Override + public boolean shouldSelectCell(EventObject anEvent) { + if (!(anEvent instanceof MouseEvent)) return true; + MouseEvent e = (MouseEvent)anEvent; + + int row = PositionUtil.getRowIndex(e.getPoint()); + if (row > getRowCount() - 1) { + return false; + } + Point point = calcPoint4Graph(e.getPoint()); + Collection printElements = myDataPack.getVisibleGraph().getRowInfo(row).getPrintElements(); + PrintElement printElement = myGraphCellPainter.mouseOver(printElements, point.x, point.y); + return printElement == null; + } + + @Override + public boolean stopCellEditing() { + return false; + } + + @Override + public void cancelCellEditing() { + + } + + @Override + public void addCellEditorListener(CellEditorListener l) { + + } + + @Override + public void removeCellEditorListener(CellEditorListener l) { + + } + } } diff --git a/platform/xdebugger-api/src/com/intellij/xdebugger/frame/XValueNode.java b/platform/xdebugger-api/src/com/intellij/xdebugger/frame/XValueNode.java index e50de966192d..5d63f0beddb5 100644 --- a/platform/xdebugger-api/src/com/intellij/xdebugger/frame/XValueNode.java +++ b/platform/xdebugger-api/src/com/intellij/xdebugger/frame/XValueNode.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2015 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. @@ -36,7 +36,7 @@ public interface XValueNode extends Obsolescent { * If value text exceeds this constant it's recommended to truncate it and use {@link #setFullValueEvaluator(XFullValueEvaluator)} method * to provide full value */ - int MAX_VALUE_LENGTH = 100; + int MAX_VALUE_LENGTH = 1000; /** * Setup presentation of the value diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/DebuggerUIUtil.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/DebuggerUIUtil.java index 6758d5e9b356..c4c7ab6a148b 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/DebuggerUIUtil.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/DebuggerUIUtil.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2015 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. @@ -40,6 +40,7 @@ import com.intellij.xdebugger.frame.XFullValueEvaluator; import com.intellij.xdebugger.impl.breakpoints.XBreakpointBase; import com.intellij.xdebugger.impl.breakpoints.ui.BreakpointsDialogFactory; import com.intellij.xdebugger.impl.breakpoints.ui.XLightBreakpointPropertiesPanel; +import com.intellij.xdebugger.impl.ui.tree.nodes.XValueNodeImpl; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -127,8 +128,8 @@ public class DebuggerUIUtil { JComponent component, @Nullable final FullValueEvaluationCallbackImpl callback) { ComponentPopupBuilder builder = JBPopupFactory.getInstance().createComponentPopupBuilder(component, null); - builder.setResizable(true).setAlpha(1) - .setMovable(true) + builder.setResizable(true) + .setMovable(true) .setDimensionServiceKey(project, FULL_VALUE_POPUP_DIMENSION_KEY, false) .setRequestFocus(false); if (callback != null) { @@ -328,4 +329,14 @@ public class DebuggerUIUtil { return myObsolete.get(); } } + + @Nullable + public static String getNodeRawValue(@NotNull XValueNodeImpl valueNode) { + if (valueNode.getValueContainer() instanceof XValueTextProvider) { + return ((XValueTextProvider)valueNode.getValueContainer()).getValueText(); + } + else { + return valueNode.getRawValue(); + } + } } diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/tree/XDebuggerTreeRenderer.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/tree/XDebuggerTreeRenderer.java index ee95281b6c9d..e8b6008656d1 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/tree/XDebuggerTreeRenderer.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/tree/XDebuggerTreeRenderer.java @@ -15,18 +15,24 @@ */ package com.intellij.xdebugger.impl.ui.tree; +import com.intellij.openapi.project.Project; import com.intellij.ui.AbstractExpandableItemsHandler; import com.intellij.ui.ColoredTreeCellRenderer; import com.intellij.ui.SimpleTextAttributes; import com.intellij.util.ui.JBInsets; +import com.intellij.xdebugger.XDebuggerBundle; +import com.intellij.xdebugger.frame.ImmediateFullValueEvaluator; import com.intellij.xdebugger.frame.XDebuggerTreeNodeHyperlink; +import com.intellij.xdebugger.impl.ui.DebuggerUIUtil; import com.intellij.xdebugger.impl.ui.tree.nodes.XDebuggerTreeNode; +import com.intellij.xdebugger.impl.ui.tree.nodes.XValueNodeImpl; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import javax.swing.*; import javax.swing.tree.TreePath; import java.awt.*; +import java.awt.event.MouseEvent; /** * @author nik @@ -37,6 +43,8 @@ class XDebuggerTreeRenderer extends ColoredTreeCellRenderer { private int myLinkOffset; private int myLinkWidth; + private final MyLongTextHyperlink myLongTextLink = new MyLongTextHyperlink(); + public XDebuggerTreeRenderer() { Insets myLinkIpad = myLink.getIpad(); myLink.setIpad(new JBInsets(myLinkIpad.top, 0, myLinkIpad.bottom, myLinkIpad.right)); @@ -56,18 +64,38 @@ class XDebuggerTreeRenderer extends ColoredTreeCellRenderer { XDebuggerTreeNode node = (XDebuggerTreeNode)value; node.appendToComponent(this); setIcon(node.getIcon()); + + Rectangle treeVisibleRect = tree.getVisibleRect(); + TreePath path = tree.getPathForRow(row); + int rowX = path != null ? ((XDebuggerTree.LinkTreeUI)tree.getUI()).getRowX(row, path.getPathCount() - 1) : 0; + if (myHaveLink) { - Dimension linkSize = myLink.getPreferredSize(); - myLinkWidth = linkSize.width; - myLink.setBounds(0, 0, linkSize.width, linkSize.height); - Rectangle treeVisibleRect = tree.getVisibleRect(); - TreePath path = tree.getPathForRow(row); - int rowX = path != null ? ((XDebuggerTree.LinkTreeUI)tree.getUI()).getRowX(row, path.getPathCount() - 1) : 0; - myLinkOffset = Math.min(super.getPreferredSize().width, treeVisibleRect.x + treeVisibleRect.width - myLinkWidth - rowX); + setupLinkDimensions(treeVisibleRect, rowX); + } + else { + if (rowX + super.getPreferredSize().width > treeVisibleRect.x + treeVisibleRect.width) { + // text does not fit visible area - show link + if (node instanceof XValueNodeImpl) { + final String rawValue = DebuggerUIUtil.getNodeRawValue((XValueNodeImpl)node); + if (rawValue != null) { + myLongTextLink.setupComponent(rawValue, ((XDebuggerTree)tree).getProject()); + append(myLongTextLink.getLinkText(), myLongTextLink.getTextAttributes(), myLongTextLink); + setupLinkDimensions(treeVisibleRect, rowX); + myLinkWidth = 0; + } + } + } } putClientProperty(AbstractExpandableItemsHandler.DISABLE_EXPANDABLE_HANDLER, myHaveLink ? true : null); } + private void setupLinkDimensions(Rectangle treeVisibleRect, int rowX) { + Dimension linkSize = myLink.getPreferredSize(); + myLinkWidth = linkSize.width; + myLink.setBounds(0, 0, linkSize.width, linkSize.height); + myLinkOffset = Math.min(super.getPreferredSize().width, treeVisibleRect.x + treeVisibleRect.width - myLinkWidth - rowX); + } + @Override public void append(@NotNull String fragment, @NotNull SimpleTextAttributes attributes, Object tag) { if (tag instanceof XDebuggerTreeNodeHyperlink && ((XDebuggerTreeNodeHyperlink)tag).alwaysOnScreen()) { @@ -131,4 +159,29 @@ class XDebuggerTreeRenderer extends ColoredTreeCellRenderer { super.doPaint(g); } } + + private static class MyLongTextHyperlink extends XDebuggerTreeNodeHyperlink { + private String myText; + private Project myProject; + + public MyLongTextHyperlink() { + super(XDebuggerBundle.message("node.test.show.full.value")); + } + + public void setupComponent(String text, Project project) { + myText = text; + myProject = project; + } + + @Override + public boolean alwaysOnScreen() { + return true; + } + + @Override + public void onClick(MouseEvent event) { + DebuggerUIUtil.showValuePopup(new ImmediateFullValueEvaluator(myText), event, myProject, null); + event.consume(); + } + } } diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/tree/actions/XFetchValueActionBase.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/tree/actions/XFetchValueActionBase.java index e155ee5a02ad..bd7c2ff75200 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/tree/actions/XFetchValueActionBase.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/tree/actions/XFetchValueActionBase.java @@ -23,7 +23,7 @@ import com.intellij.openapi.util.text.StringUtil; import com.intellij.ui.AppUIUtil; import com.intellij.util.SmartList; import com.intellij.xdebugger.frame.XFullValueEvaluator; -import com.intellij.xdebugger.impl.ui.XValueTextProvider; +import com.intellij.xdebugger.impl.ui.DebuggerUIUtil; import com.intellij.xdebugger.impl.ui.tree.XDebuggerTree; import com.intellij.xdebugger.impl.ui.tree.nodes.HeadlessValueEvaluationCallback; import com.intellij.xdebugger.impl.ui.tree.nodes.WatchMessageNode; @@ -76,14 +76,7 @@ public abstract class XFetchValueActionBase extends AnAction { XValueNodeImpl valueNode = (XValueNodeImpl)node; XFullValueEvaluator fullValueEvaluator = valueNode.getFullValueEvaluator(); if (fullValueEvaluator == null || !fullValueEvaluator.isShowValuePopup()) { - String rawValue; - if (valueNode.getValueContainer() instanceof XValueTextProvider) { - rawValue = ((XValueTextProvider)valueNode.getValueContainer()).getValueText(); - } - else { - rawValue = valueNode.getRawValue(); - } - valueCollector.add(StringUtil.notNullize(rawValue)); + valueCollector.add(StringUtil.notNullize(DebuggerUIUtil.getNodeRawValue(valueNode))); } else { new CopyValueEvaluationCallback(valueNode, valueCollector).startFetchingValue(fullValueEvaluator); diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/modifiers/ModifierIntention.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/modifiers/ModifierIntention.java index 728c07cdf6fa..bb3fdb60124a 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/modifiers/ModifierIntention.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/modifiers/ModifierIntention.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 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. @@ -17,8 +17,10 @@ package com.siyeh.ipp.modifiers; import com.intellij.codeInsight.intention.LowPriorityAction; import com.intellij.openapi.application.AccessToken; +import com.intellij.openapi.project.Project; import com.intellij.openapi.util.io.FileUtil; import com.intellij.psi.*; +import com.intellij.psi.codeStyle.CodeStyleManager; import com.intellij.psi.impl.source.resolve.JavaResolveUtil; import com.intellij.psi.search.searches.OverridingMethodsSearch; import com.intellij.psi.search.searches.ReferencesSearch; @@ -60,11 +62,12 @@ abstract class ModifierIntention extends Intention implements LowPriorityAction return; } final MultiMap conflicts = checkForConflicts(member); + final Project project = member.getProject(); final boolean conflictsDialogOK; if (conflicts.isEmpty()) { conflictsDialogOK = true; } else { - final ConflictsDialog conflictsDialog = new ConflictsDialog(member.getProject(), conflicts, new Runnable() { + final ConflictsDialog conflictsDialog = new ConflictsDialog(project, conflicts, new Runnable() { @Override public void run() { final AccessToken token = start(); @@ -80,6 +83,13 @@ abstract class ModifierIntention extends Intention implements LowPriorityAction } if (conflictsDialogOK) { modifierList.setModifierProperty(getModifier(), true); + final PsiElement whitespace = PsiParserFacade.SERVICE.getInstance(project).createWhiteSpaceFromText(" "); + final PsiElement sibling = modifierList.getNextSibling(); + if (sibling instanceof PsiWhiteSpace) { + sibling.replace(whitespace); + CodeStyleManager.getInstance(project).reformatRange(member, modifierList.getTextOffset() + 1, + modifierList.getNextSibling().getTextOffset()); + } } } diff --git a/plugins/IntentionPowerPak/test/com/siyeh/ipp/modifiers/make_public/AnnotatedMember.java b/plugins/IntentionPowerPak/test/com/siyeh/ipp/modifiers/make_public/AnnotatedMember.java new file mode 100644 index 000000000000..76b2ae6f4def --- /dev/null +++ b/plugins/IntentionPowerPak/test/com/siyeh/ipp/modifiers/make_public/AnnotatedMember.java @@ -0,0 +1,5 @@ +class AnnotatedMember { + + @SuppressWarnings("ALL") + String s; +} \ No newline at end of file diff --git a/plugins/IntentionPowerPak/test/com/siyeh/ipp/modifiers/make_public/AnnotatedMember_after.java b/plugins/IntentionPowerPak/test/com/siyeh/ipp/modifiers/make_public/AnnotatedMember_after.java new file mode 100644 index 000000000000..5f0fe6e1ab04 --- /dev/null +++ b/plugins/IntentionPowerPak/test/com/siyeh/ipp/modifiers/make_public/AnnotatedMember_after.java @@ -0,0 +1,5 @@ +class AnnotatedMember { + + @SuppressWarnings("ALL") + private String s; +} \ No newline at end of file diff --git a/plugins/IntentionPowerPak/testSrc/com/siyeh/ipp/modifiers/MakePrivateIntentionTest.java b/plugins/IntentionPowerPak/testSrc/com/siyeh/ipp/modifiers/MakePrivateIntentionTest.java index e7e39115c918..5dd3f794e0ee 100644 --- a/plugins/IntentionPowerPak/testSrc/com/siyeh/ipp/modifiers/MakePrivateIntentionTest.java +++ b/plugins/IntentionPowerPak/testSrc/com/siyeh/ipp/modifiers/MakePrivateIntentionTest.java @@ -27,6 +27,7 @@ public class MakePrivateIntentionTest extends IPPTestCase { public void testMyClass() { assertIntentionNotAvailable(); } public void testMyInterface() { assertIntentionNotAvailable(); } public void testMethod() { doTest(); } + public void testAnnotatedMember() { doTest(); } @Override protected String getRelativePath() { diff --git a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/codeInspection/type/GroovyTypeCheckVisitor.java b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/codeInspection/type/GroovyTypeCheckVisitor.java index cac417a1fd39..782f10c65d49 100644 --- a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/codeInspection/type/GroovyTypeCheckVisitor.java +++ b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/codeInspection/type/GroovyTypeCheckVisitor.java @@ -701,6 +701,7 @@ public class GroovyTypeCheckVisitor extends BaseInspectionVisitor { } private void registerCannotApplyError(@NotNull String invokedText, @NotNull CallInfo info) { + if (info.getArgumentTypes() == null) return; final String typesString = buildArgTypesList(info.getArgumentTypes()); registerError( info.getElementToHighlight(), @@ -839,12 +840,14 @@ public class GroovyTypeCheckVisitor extends BaseInspectionVisitor { public void visitCastExpression(GrTypeCastExpression expression) { super.visitCastExpression(expression); - if (expression.getCastTypeElement() == null) return; - final PsiType expectedType = expression.getCastTypeElement().getType(); final GrExpression operand = expression.getOperand(); + if (operand == null) return; final PsiType actualType = operand.getType(); if (actualType == null) return; + if (expression.getCastTypeElement() == null) return; + final PsiType expectedType = expression.getCastTypeElement().getType(); + final ConversionResult result = TypesUtil.canCast(expectedType, actualType, expression); if (result == ConversionResult.OK) return; final ProblemHighlightType highlightType = result == ConversionResult.ERROR diff --git a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/api/statements/expressions/GrTypeCastExpression.java b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/api/statements/expressions/GrTypeCastExpression.java index b4fe54f956bd..6cccb4832cc3 100644 --- a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/api/statements/expressions/GrTypeCastExpression.java +++ b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/api/statements/expressions/GrTypeCastExpression.java @@ -16,6 +16,7 @@ package org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions; +import org.jetbrains.annotations.Nullable; import org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeElement; import org.jetbrains.annotations.NotNull; import com.intellij.psi.PsiElement; @@ -26,6 +27,7 @@ import com.intellij.psi.PsiElement; public interface GrTypeCastExpression extends GrExpression { GrTypeElement getCastTypeElement(); + @Nullable GrExpression getOperand(); @NotNull diff --git a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/types/GrTypeCastExpressionImpl.java b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/types/GrTypeCastExpressionImpl.java index 54665477304c..06f8ed1e356e 100644 --- a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/types/GrTypeCastExpressionImpl.java +++ b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/types/GrTypeCastExpressionImpl.java @@ -20,6 +20,7 @@ import com.intellij.lang.ASTNode; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiType; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes; import org.jetbrains.plugins.groovy.lang.psi.GroovyElementVisitor; import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression; @@ -58,6 +59,7 @@ public class GrTypeCastExpressionImpl extends GrExpressionImpl implements GrType } @Override + @Nullable public GrExpression getOperand() { return findExpressionChild(this); } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/resources/TypeCustomizerInspection.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/resources/TypeCustomizerInspection.java index e55cc758c4ef..541f041bf51d 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/resources/TypeCustomizerInspection.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/resources/TypeCustomizerInspection.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2015 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. @@ -50,12 +50,11 @@ public class TypeCustomizerInspection extends BaseInspection { return new BaseInspectionVisitor() { @Override public void visitFile(GroovyFileBase file) { - if (!CompilerConfiguration.getInstance(file.getProject()).isResourceFile(file.getVirtualFile())) { - if (fileSeemsToBeTypeCustomizer(file)) { - final LocalQuickFix[] fixes = {new AddToResourceFix(file)}; - final String message = GroovyInspectionBundle.message("type.customizer.is.not.marked.as.a.resource.file"); - registerError(file, message, fixes, ProblemHighlightType.GENERIC_ERROR_OR_WARNING); - } + CompilerConfiguration configuration = CompilerConfiguration.getInstance(file.getProject()); + if (configuration != null && !configuration.isResourceFile(file.getVirtualFile()) && fileSeemsToBeTypeCustomizer(file)) { + final LocalQuickFix[] fixes = {new AddToResourceFix(file)}; + final String message = GroovyInspectionBundle.message("type.customizer.is.not.marked.as.a.resource.file"); + registerError(file, message, fixes, ProblemHighlightType.GENERIC_ERROR_OR_WARNING); } } }; diff --git a/plugins/properties/properties-psi-impl/src/com/intellij/lang/properties/xml/XmlPropertiesFileImpl.java b/plugins/properties/properties-psi-impl/src/com/intellij/lang/properties/xml/XmlPropertiesFileImpl.java index a3a94c8f7f18..3590681522f8 100644 --- a/plugins/properties/properties-psi-impl/src/com/intellij/lang/properties/xml/XmlPropertiesFileImpl.java +++ b/plugins/properties/properties-psi-impl/src/com/intellij/lang/properties/xml/XmlPropertiesFileImpl.java @@ -33,7 +33,10 @@ import com.intellij.psi.util.CachedValuesManager; import com.intellij.psi.xml.XmlFile; import com.intellij.psi.xml.XmlTag; import com.intellij.reference.SoftLazyValue; +import com.intellij.util.Function; import com.intellij.util.IncorrectOperationException; +import com.intellij.util.SmartList; +import com.intellij.util.containers.ContainerUtil; import com.intellij.util.containers.MultiMap; import gnu.trove.THashMap; import org.jetbrains.annotations.NonNls; @@ -47,29 +50,54 @@ import java.util.*; * Date: 7/26/11 */ public class XmlPropertiesFileImpl extends XmlPropertiesFile { - private static final Key> KEY = Key.create("xml properties file"); private final XmlFile myFile; - private final SoftLazyValue> myPropertiesMap = new SoftLazyValue>() { + private final SoftLazyValue myInfo = new SoftLazyValue() { @NotNull @Override - protected MultiMap compute() { - XmlTag rootTag = myFile.getRootTag(); - if (rootTag == null) { - return MultiMap.emptyInstance(); - } - - XmlTag[] entries = rootTag.findSubTags("entry"); - MultiMap map = new MultiMap(); - - for (XmlTag entry : entries) { - XmlProperty property = new XmlProperty(entry, XmlPropertiesFileImpl.this); - map.putValue(property.getKey(), property); - } - return map; + protected Info compute() { + return new Info(); } }; + private class Info { + private final MultiMap myPropertiesMap = MultiMap.create(); + private List myPropertiesOrder; + private boolean mySorted; + + public Info() { + XmlTag rootTag = myFile.getRootTag(); + final List propertiesOrder = new ArrayList(); + if (rootTag != null) { + XmlTag[] entries = rootTag.findSubTags("entry"); + for (XmlTag entry : entries) { + XmlProperty property = new XmlProperty(entry, XmlPropertiesFileImpl.this); + propertiesOrder.add(property); + myPropertiesMap.putValue(property.getKey(), property); + } + } + mySorted = PropertiesImplUtil.isAlphaSorted(propertiesOrder); + myPropertiesOrder = mySorted ? propertiesOrder : null; + } + + public void setSorted(boolean sorted) { + mySorted = sorted; + myPropertiesOrder = null; + } + + public MultiMap getPropertiesMap() { + return myPropertiesMap; + } + + public List getPropertiesOrder() { + return myPropertiesOrder; + } + + public boolean isSorted() { + return mySorted; + } + } + private XmlPropertiesFileImpl(XmlFile file) { myFile = file; } @@ -83,19 +111,19 @@ public class XmlPropertiesFileImpl extends XmlPropertiesFile { @NotNull @Override public List getProperties() { - return new ArrayList(myPropertiesMap.getValue().values()); + return new ArrayList(myInfo.getValue().getPropertiesMap().values()); } @Override public IProperty findPropertyByKey(@NotNull @NonNls String key) { - Collection properties = myPropertiesMap.getValue().get(key); + Collection properties = myInfo.getValue().getPropertiesMap().get(key); return properties.isEmpty() ? null : properties.iterator().next(); } @NotNull @Override public List findPropertiesByKey(@NotNull @NonNls String key) { - return new ArrayList(myPropertiesMap.getValue().get(key)); + return new ArrayList(myInfo.getValue().getPropertiesMap().get(key)); } @NotNull @@ -122,22 +150,62 @@ public class XmlPropertiesFileImpl extends XmlPropertiesFile { @Override public IProperty addPropertyAfter(String key, String value, Property anchor) { - return null; + return addPropertyAfterAndCheckAlphaSorting(key, value, anchor, true, true); + } + + @NotNull + public IProperty addPropertyAfterAndCheckAlphaSorting(String key, String value, @Nullable IProperty anchor, boolean addToEnd, boolean checkAlphaSorting) { + final XmlTag anchorTag = anchor == null ? null : (XmlTag)anchor.getPsiElement(); + final XmlTag rootTag = myFile.getRootTag(); + final XmlTag entry = createPropertyTag(key, value); + final XmlTag addedEntry = (XmlTag) (anchorTag == null ? myFile.getRootTag().addSubTag(entry, !addToEnd) : rootTag.addAfter(entry, anchorTag)); + final XmlProperty property = new XmlProperty(addedEntry, this); + myInfo.getValue().getPropertiesMap().putValue(key, property); + if (checkAlphaSorting) { + checkAlphaSorting(property); + } + return property; } @NotNull @Override public IProperty addProperty(String key, String value) { + final XmlTag entry = createPropertyTag(key, value); + if (myInfo.getValue().isSorted()) { + final XmlProperty dummyProperty = new XmlProperty(entry, this); + final int insertIndex = Collections.binarySearch(myInfo.getValue().getPropertiesOrder(), dummyProperty, new Comparator() { + @Override + public int compare(IProperty p1, IProperty p2) { + final String k1 = p1.getKey(); + final String k2 = p2.getKey(); + return k1.compareTo(k2); + } + }); + final IProperty insertPosition; + final IProperty inserted; + if (insertIndex == -1) { + inserted = addPropertyAfterAndCheckAlphaSorting(key, value, null, false, false); + myInfo.getValue().getPropertiesOrder().add(0, inserted); + } + else { + final int position = insertIndex < 0 ? -insertIndex - 2 : insertIndex; + insertPosition = myInfo.getValue().getPropertiesOrder().get(position); + inserted = addPropertyAfterAndCheckAlphaSorting(key, value, insertPosition, false, false); + myInfo.getValue().getPropertiesOrder().add(position + 1, inserted); + } + return inserted; + } else { + return addPropertyAfterAndCheckAlphaSorting(key, value, null, true, false); + } + } + + private XmlTag createPropertyTag(final String key, final String value) { XmlTag rootTag = myFile.getRootTag(); XmlTag entry = rootTag.createChildTag("entry", "", value, false); entry.setAttribute("key", key); - rootTag.addSubTag(entry, false); - final XmlProperty property = new XmlProperty(entry, this); - myPropertiesMap.getValue().putValue(key, property); - return property; + return entry; } - public static PropertiesFile getPropertiesFile(final PsiFile file) { CachedValuesManager manager = CachedValuesManager.getManager(file.getProject()); if (file instanceof XmlFile) { @@ -194,7 +262,7 @@ public class XmlPropertiesFileImpl extends XmlPropertiesFile { @Override public boolean isAlphaSorted() { - return PropertiesImplUtil.isAlphaSorted(getProperties()); + return myInfo.getValue().isSorted(); } @Override @@ -213,4 +281,29 @@ public class XmlPropertiesFileImpl extends XmlPropertiesFile { public int hashCode() { return myFile.hashCode(); } + + private void checkAlphaSorting(final IProperty property) { + if (myInfo.getValue().isSorted()) { + final String key = property.getKey(); + final XmlTag prev = getSibling((XmlTag)property.getPsiElement(), true); + final String prevKey = prev == null ? null : new XmlProperty(prev, this).getKey(); + if (prevKey != null && key != null && prevKey.compareTo(key) > 0) { + myInfo.getValue().setSorted(false); + } else { + final XmlTag next = getSibling((XmlTag)property.getPsiElement(), false); + final String nextKey = next == null ? null : new XmlProperty(next, this).getKey(); + if (nextKey != null && key != null && nextKey.compareTo(key) < 0) { + myInfo.getValue().setSorted(false); + } + } + } + } + + private static XmlTag getSibling(final XmlTag entry, final boolean prev) { + XmlTag sibling = (XmlTag)(prev ? entry.getPrevSibling() : entry.getNextSibling()); + while (sibling != null && !"entry".equals(sibling.getName())) { + sibling = (XmlTag)(prev ? sibling.getPrevSibling() : sibling.getNextSibling()); + } + return sibling; + } } diff --git a/plugins/properties/testData/xml/bar.xml b/plugins/properties/testData/xml/bar.xml new file mode 100644 index 000000000000..b85abb53cc8e --- /dev/null +++ b/plugins/properties/testData/xml/bar.xml @@ -0,0 +1,7 @@ + + + + Hi + bar + baz + \ No newline at end of file diff --git a/plugins/properties/testSrc/com/intellij/lang/properties/PropertiesFileTest.java b/plugins/properties/testSrc/com/intellij/lang/properties/PropertiesFileTest.java index 159dd58d140d..b0d0c5e162f2 100644 --- a/plugins/properties/testSrc/com/intellij/lang/properties/PropertiesFileTest.java +++ b/plugins/properties/testSrc/com/intellij/lang/properties/PropertiesFileTest.java @@ -22,6 +22,7 @@ import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.command.WriteCommandAction; import com.intellij.testFramework.LightPlatformTestCase; import com.intellij.testFramework.PlatformTestCase; +import com.intellij.testFramework.fixtures.LightPlatformCodeInsightFixtureTestCase; import com.intellij.util.IncorrectOperationException; import org.jetbrains.annotations.NonNls; @@ -30,16 +31,13 @@ import java.util.List; /** * @author max */ -public class PropertiesFileTest extends LightPlatformTestCase { +public class PropertiesFileTest extends LightPlatformCodeInsightFixtureTestCase { private Property myPropertyToAdd; - public PropertiesFileTest() { - PlatformTestCase.initPlatformLangPrefix(); - } - @Override protected void setUp() throws Exception { super.setUp(); + PlatformTestCase.initPlatformLangPrefix(); myPropertyToAdd = (Property)PropertiesElementFactory.createProperty(getProject(), "kkk", "vvv"); } @@ -73,8 +71,8 @@ public class PropertiesFileTest extends LightPlatformTestCase { List properties = propertiesFile.getProperties(); assertEquals(2, properties.size()); - assertPropertyEquals(properties.get(0), "xxx", "yyy"); - assertPropertyEquals(properties.get(1), myPropertyToAdd.getName(), myPropertyToAdd.getValue()); + assertPropertyEquals(properties.get(1), "xxx", "yyy"); + assertPropertyEquals(properties.get(0), myPropertyToAdd.getName(), myPropertyToAdd.getValue()); } public void testDeleteProperty() throws Exception { PropertiesFile propertiesFile = PropertiesElementFactory.createPropertiesFile(getProject(), "xxx=yyy\n#s\nzzz=ttt\n\n"); diff --git a/plugins/properties/testSrc/com/intellij/lang/properties/xml/XmlPropertiesTest.java b/plugins/properties/testSrc/com/intellij/lang/properties/xml/XmlPropertiesTest.java index d16eaf352f38..fd4b1212107f 100644 --- a/plugins/properties/testSrc/com/intellij/lang/properties/xml/XmlPropertiesTest.java +++ b/plugins/properties/testSrc/com/intellij/lang/properties/xml/XmlPropertiesTest.java @@ -9,6 +9,8 @@ import com.intellij.openapi.command.WriteCommandAction; import com.intellij.psi.PsiFile; import com.intellij.testFramework.PlatformTestCase; import com.intellij.testFramework.fixtures.LightPlatformCodeInsightFixtureTestCase; +import com.intellij.util.Function; +import com.intellij.util.containers.ContainerUtil; import java.util.List; @@ -81,6 +83,23 @@ public class XmlPropertiesTest extends LightPlatformCodeInsightFixtureTestCase { assertEquals("vvv", property2.getValue()); } + public void testAddPropertyInAlphaOrder() { + final PsiFile psiFile = myFixture.configureByFile("bar.xml"); + final PropertiesFile propertiesFile = PropertiesImplUtil.getPropertiesFile(psiFile); + assertNotNull(propertiesFile); + + WriteCommandAction.runWriteCommandAction(getProject(), new Runnable() { + public void run() { + propertiesFile.addProperty("d", "vvv"); + propertiesFile.addProperty("a", "vvv"); + propertiesFile.addProperty("l", "vvv"); + propertiesFile.addProperty("v", "vvv"); + } + }); + assertTrue(propertiesFile.isAlphaSorted()); + assertTrue(PropertiesImplUtil.getPropertiesFile(psiFile).isAlphaSorted()); + } + @Override protected String getTestDataPath() { return PluginPathManager.getPluginHomePath("properties") + "/testData/xml/"; diff --git a/python/build/pycharm_community_build.gant b/python/build/pycharm_community_build.gant index 27ca91008a8b..dc268982e831 100644 --- a/python/build/pycharm_community_build.gant +++ b/python/build/pycharm_community_build.gant @@ -377,5 +377,6 @@ private layoutMac(Map _args, String target) { args.help_id = "PY" args."idea.properties.path" = "${paths.distAll}/bin/idea.properties" args."idea.properties" = ["idea.no.jre.check": true, "ide.mac.useNativeClipboard": "false"]; + args.executable = "pycharm" layoutMacApp(target, ch, args) } diff --git a/python/edu/course-creator-python/src/com/jetbrains/edu/coursecreator/PyStudyLanguageManager.java b/python/edu/course-creator-python/src/com/jetbrains/edu/coursecreator/PyStudyLanguageManager.java index 1b711f818b90..be2f399ffe58 100644 --- a/python/edu/course-creator-python/src/com/jetbrains/edu/coursecreator/PyStudyLanguageManager.java +++ b/python/edu/course-creator-python/src/com/jetbrains/edu/coursecreator/PyStudyLanguageManager.java @@ -6,6 +6,8 @@ import com.intellij.openapi.project.Project; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.io.File; + public class PyStudyLanguageManager implements StudyLanguageManager { @Nullable @Override @@ -28,6 +30,17 @@ public class PyStudyLanguageManager implements StudyLanguageManager { return getInternalTemplateByName(project, "tests.py"); } + @Override + public boolean packFile(File pathname) { + String name = pathname.getName(); + return !name.contains("__pycache__") && !name.contains(".pyc"); + } + + @Override + public String[] getAdditionalFilesToPack() { + return new String[]{"test_helper.py"}; + } + private static FileTemplate getInternalTemplateByName(@NotNull final Project project, String name) { return FileTemplateManager.getInstance(project).getInternalTemplate(name); } diff --git a/python/educational/course-creator/src/com/jetbrains/edu/coursecreator/CCProjectService.java b/python/educational/course-creator/src/com/jetbrains/edu/coursecreator/CCProjectService.java index 8b9659353313..f49baee259f1 100644 --- a/python/educational/course-creator/src/com/jetbrains/edu/coursecreator/CCProjectService.java +++ b/python/educational/course-creator/src/com/jetbrains/edu/coursecreator/CCProjectService.java @@ -25,6 +25,8 @@ import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.io.FileUtil; +import com.intellij.openapi.util.io.FileUtilRt; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.VirtualFileManager; import com.intellij.util.xmlb.XmlSerializer; @@ -184,11 +186,13 @@ public class CCProjectService implements PersistentStateComponent { return Integer.parseInt(fullName.substring(logicalName.length())) - 1; } public static String getRealTaskFileName(String name) { - if (!name.contains(".answer")) { + String nameWithoutExtension = FileUtil.getNameWithoutExtension(name); + String extension = FileUtilRt.getExtension(name); + if (!nameWithoutExtension.endsWith(".answer")) { return null; } int nameEnd = name.indexOf(".answer"); - return name.substring(0, nameEnd) + ".py"; + return name.substring(0, nameEnd) + "." + extension; } public static boolean setCCActionAvailable(@NotNull AnActionEvent e) { diff --git a/python/educational/course-creator/src/com/jetbrains/edu/coursecreator/CCUtils.java b/python/educational/course-creator/src/com/jetbrains/edu/coursecreator/CCUtils.java index 1e82811a6d8d..d453a59c92ae 100644 --- a/python/educational/course-creator/src/com/jetbrains/edu/coursecreator/CCUtils.java +++ b/python/educational/course-creator/src/com/jetbrains/edu/coursecreator/CCUtils.java @@ -1,6 +1,7 @@ package com.jetbrains.edu.coursecreator; import com.intellij.ide.projectView.actions.MarkRootActionBase; +import com.intellij.lang.Language; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.Presentation; import com.intellij.openapi.application.ApplicationManager; @@ -12,7 +13,9 @@ import com.intellij.openapi.roots.ContentEntry; import com.intellij.openapi.roots.ModifiableRootModel; import com.intellij.openapi.roots.ModuleRootManager; import com.intellij.openapi.vfs.VirtualFile; +import com.jetbrains.edu.coursecreator.format.Course; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; public class CCUtils { private static final Logger LOG = Logger.getInstance(CCUtils.class.getName()); @@ -56,4 +59,10 @@ public class CCUtils { return -1; } } + + @Nullable + public static StudyLanguageManager getStudyLanguageManager(@NotNull final Course course) { + Language language = Language.findLanguageByID(course.getLanguage()); + return language == null ? null : StudyLanguageManager.INSTANCE.forLanguage(language); + } } diff --git a/python/educational/course-creator/src/com/jetbrains/edu/coursecreator/StudyLanguageManager.java b/python/educational/course-creator/src/com/jetbrains/edu/coursecreator/StudyLanguageManager.java index bdef802bab94..cce016575e09 100644 --- a/python/educational/course-creator/src/com/jetbrains/edu/coursecreator/StudyLanguageManager.java +++ b/python/educational/course-creator/src/com/jetbrains/edu/coursecreator/StudyLanguageManager.java @@ -6,6 +6,8 @@ import com.intellij.openapi.project.Project; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.io.File; + public interface StudyLanguageManager { LanguageExtension INSTANCE = new LanguageExtension("Edu.StudyLanguageManager"); @@ -17,4 +19,8 @@ public interface StudyLanguageManager { @Nullable FileTemplate getTestsTemplate(@NotNull final Project project); + + boolean packFile(File pathname); + + String[] getAdditionalFilesToPack(); } diff --git a/python/educational/course-creator/src/com/jetbrains/edu/coursecreator/actions/CCCreateCourseArchive.java b/python/educational/course-creator/src/com/jetbrains/edu/coursecreator/actions/CCCreateCourseArchive.java index f34aacba345f..ac774b3659e7 100644 --- a/python/educational/course-creator/src/com/jetbrains/edu/coursecreator/actions/CCCreateCourseArchive.java +++ b/python/educational/course-creator/src/com/jetbrains/edu/coursecreator/actions/CCCreateCourseArchive.java @@ -21,6 +21,8 @@ import com.intellij.openapi.vfs.VirtualFileManager; import com.intellij.util.io.ZipUtil; import com.jetbrains.edu.coursecreator.CCDocumentListener; import com.jetbrains.edu.coursecreator.CCProjectService; +import com.jetbrains.edu.coursecreator.CCUtils; +import com.jetbrains.edu.coursecreator.StudyLanguageManager; import com.jetbrains.edu.coursecreator.format.*; import com.jetbrains.edu.coursecreator.ui.CreateCourseArchiveDialog; import org.jetbrains.annotations.NotNull; @@ -92,7 +94,7 @@ public class CCCreateCourseArchive extends DumbAwareAction { } } generateJson(project); - packCourse(baseDir, lessons); + packCourse(baseDir, lessons, course); resetTaskFiles(taskFiles); synchronize(project); } @@ -204,11 +206,11 @@ public class CCCreateCourseArchive extends DumbAwareAction { } } - private void packCourse(@NotNull final VirtualFile baseDir, @NotNull final Map lessons) { + private void packCourse(@NotNull final VirtualFile baseDir, @NotNull final Map lessons, @NotNull final Course course) { try { File zipFile = new File(myLocationDir, myZipName + ".zip"); ZipOutputStream zos = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(zipFile))); - + final StudyLanguageManager manager = CCUtils.getStudyLanguageManager(course); for (Map.Entry entry : lessons.entrySet()) { final VirtualFile lessonDir = baseDir.findChild(entry.getKey()); if (lessonDir == null) continue; @@ -217,13 +219,21 @@ public class CCCreateCourseArchive extends DumbAwareAction { public boolean accept(File pathname) { String name = pathname.getName(); String nameWithoutExtension = FileUtil.getNameWithoutExtension(pathname); - return !nameWithoutExtension.endsWith(".answer") && !name.contains("__pycache__") && !name.contains("_windows") && !name.contains(".pyc"); + if (nameWithoutExtension.endsWith(".answer") || name.contains("_windows")) { + return false; + } + return manager == null || manager.packFile(pathname); } }, null); } - ZipUtil.addFileOrDirRecursively(zos, null, new File(baseDir.getPath(), "hints"), "hints", null, null); - ZipUtil.addFileOrDirRecursively(zos, null, new File(baseDir.getPath(), "course.json"), "course.json", null, null); - ZipUtil.addFileOrDirRecursively(zos, null, new File(baseDir.getPath(), "test_helper.py"), "test_helper.py", null, null); + packFile("hints", zos, baseDir); + packFile("course.json", zos, baseDir); + if (manager != null) { + String[] additionalFilesToPack = manager.getAdditionalFilesToPack(); + for (String filename: additionalFilesToPack) { + packFile(filename, zos, baseDir); + } + } zos.close(); Messages.showInfoMessage("Course archive was saved to " + zipFile.getPath(), "Course Archive Was Created Successfully"); } @@ -271,4 +281,19 @@ public class CCCreateCourseArchive extends DumbAwareAction { return true; } } + + private static void packFile(@NotNull final String filename, + @NotNull final ZipOutputStream zipOutputStream, + @NotNull final VirtualFile baseDir) { + try { + File file = new File(baseDir.getPath(), filename); + if (!file.exists()) { + return; + } + ZipUtil.addFileOrDirRecursively(zipOutputStream, null, file, filename, null, null); + } + catch (IOException e) { + LOG.error(e); + } + } } \ No newline at end of file diff --git a/python/educational/course-creator/src/com/jetbrains/edu/coursecreator/actions/CCCreateTask.java b/python/educational/course-creator/src/com/jetbrains/edu/coursecreator/actions/CCCreateTask.java index fefa795f4ff6..538fc76b59f2 100644 --- a/python/educational/course-creator/src/com/jetbrains/edu/coursecreator/actions/CCCreateTask.java +++ b/python/educational/course-creator/src/com/jetbrains/edu/coursecreator/actions/CCCreateTask.java @@ -18,6 +18,7 @@ import com.intellij.openapi.fileEditor.FileEditorManager; import com.intellij.openapi.project.DumbAwareAction; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.Messages; +import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiDirectory; import com.intellij.psi.PsiElement; @@ -80,25 +81,23 @@ public class CCCreateTask extends DumbAwareAction { final StudyLanguageManager studyLanguageManager = StudyLanguageManager.INSTANCE.forLanguage(language); CCUtils.markDirAsSourceRoot(taskDirectory.getVirtualFile(), project); + final Task task = new Task(taskName); + task.setIndex(size + 1); + lesson.addTask(task, taskDirectory); + createFromTemplateAndOpen(taskDirectory, studyLanguageManager.getTestsTemplate(project), view); createFromTemplateAndOpen(taskDirectory, FileTemplateManager.getInstance(project).getInternalTemplate("task.html"), view); String defaultExtension = studyLanguageManager.getDefaultTaskFileExtension(); - String taskFileName = null; if (defaultExtension != null) { FileTemplate taskFileTemplate = studyLanguageManager.getTaskFileTemplateForExtension(project, defaultExtension); createFromTemplateAndOpen(taskDirectory, taskFileTemplate, view); if (taskFileTemplate != null) { - taskFileName = taskFileTemplate.getName(); + String taskFileName = FileUtil.getNameWithoutExtension(taskFileTemplate.getName()); + task.addTaskFile(taskFileName + "." + defaultExtension, size + 1); } } - final Task task = new Task(taskName); - task.setIndex(size + 1); - lesson.addTask(task, taskDirectory); - if (taskFileName != null) { - task.addTaskFile(taskFileName, size + 1); - } ApplicationManager.getApplication().invokeLater(new Runnable() { @Override public void run() { diff --git a/python/educational/course-creator/src/com/jetbrains/edu/coursecreator/actions/CCCreateTaskFile.java b/python/educational/course-creator/src/com/jetbrains/edu/coursecreator/actions/CCCreateTaskFile.java index 73b50d39b3be..374a141fa067 100644 --- a/python/educational/course-creator/src/com/jetbrains/edu/coursecreator/actions/CCCreateTaskFile.java +++ b/python/educational/course-creator/src/com/jetbrains/edu/coursecreator/actions/CCCreateTaskFile.java @@ -7,7 +7,6 @@ import com.intellij.ide.fileTemplates.FileTemplateUtil; import com.intellij.ide.projectView.ProjectView; import com.intellij.ide.util.DirectoryChooserUtil; import com.intellij.ide.util.EditorHelper; -import com.intellij.lang.Language; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.CommonDataKeys; import com.intellij.openapi.actionSystem.LangDataKeys; @@ -21,6 +20,7 @@ import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiDirectory; import com.intellij.psi.PsiElement; import com.jetbrains.edu.coursecreator.CCProjectService; +import com.jetbrains.edu.coursecreator.CCUtils; import com.jetbrains.edu.coursecreator.StudyLanguageManager; import com.jetbrains.edu.coursecreator.format.Course; import com.jetbrains.edu.coursecreator.format.Lesson; @@ -57,7 +57,7 @@ public class CCCreateTaskFile extends DumbAwareAction { final int index = task.getTaskFiles().size() + 1; String generatedName = "file" + index; - CreateTaskFileDialog dialog = new CreateTaskFileDialog(project, generatedName); + CreateTaskFileDialog dialog = new CreateTaskFileDialog(project, generatedName, course); dialog.show(); if (dialog.getExitCode() != OK_EXIT_CODE) { return; @@ -68,11 +68,10 @@ public class CCCreateTaskFile extends DumbAwareAction { if (type == null) { return; } - Language language = Language.findLanguageByID(course.getLanguage()); - if (language == null) { + final StudyLanguageManager studyLanguageManager = CCUtils.getStudyLanguageManager(course); + if (studyLanguageManager == null) { return; } - final StudyLanguageManager studyLanguageManager = StudyLanguageManager.INSTANCE.forLanguage(language); final String extension = type.getDefaultExtension(); ApplicationManager.getApplication().runWriteAction(new Runnable() { @Override diff --git a/python/educational/course-creator/src/com/jetbrains/edu/coursecreator/actions/CCRunTestsAction.java b/python/educational/course-creator/src/com/jetbrains/edu/coursecreator/actions/CCRunTestsAction.java index e8ea54843535..bb4187026691 100644 --- a/python/educational/course-creator/src/com/jetbrains/edu/coursecreator/actions/CCRunTestsAction.java +++ b/python/educational/course-creator/src/com/jetbrains/edu/coursecreator/actions/CCRunTestsAction.java @@ -18,6 +18,7 @@ package com.jetbrains.edu.coursecreator.actions; import com.intellij.execution.Location; import com.intellij.execution.actions.ConfigurationContext; import com.intellij.icons.AllIcons; +import com.intellij.ide.fileTemplates.FileTemplate; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.Presentation; @@ -34,6 +35,8 @@ import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.util.containers.HashMap; import com.jetbrains.edu.coursecreator.CCProjectService; +import com.jetbrains.edu.coursecreator.CCUtils; +import com.jetbrains.edu.coursecreator.StudyLanguageManager; import com.jetbrains.edu.coursecreator.format.*; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -130,8 +133,16 @@ public abstract class CCRunTestsAction extends AnAction { clearTestEnvironment(taskDir, project); for (final Map.Entry entry : task.getTaskFiles().entrySet()) { final String name = entry.getKey(); + StudyLanguageManager manager = CCUtils.getStudyLanguageManager(course); + if (manager == null) { + return; + } createTestEnvironment(taskDir, name, entry.getValue(), project); - VirtualFile testFile = taskDir.findChild("tests.py"); + FileTemplate testsTemplate = manager.getTestsTemplate(project); + if (testsTemplate == null) { + return; + } + VirtualFile testFile = taskDir.findChild(testsTemplate.getName()); if (testFile == null) { return; } diff --git a/python/educational/course-creator/src/com/jetbrains/edu/coursecreator/actions/CCShowPreview.java b/python/educational/course-creator/src/com/jetbrains/edu/coursecreator/actions/CCShowPreview.java index 42fa66169633..7dfed6ef223d 100644 --- a/python/educational/course-creator/src/com/jetbrains/edu/coursecreator/actions/CCShowPreview.java +++ b/python/educational/course-creator/src/com/jetbrains/edu/coursecreator/actions/CCShowPreview.java @@ -30,7 +30,6 @@ import com.intellij.openapi.project.DumbAwareAction; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.FrameWrapper; import com.intellij.openapi.util.Disposer; -import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiDirectory; import com.intellij.psi.PsiFile; @@ -92,6 +91,9 @@ public class CCShowPreview extends DumbAwareAction { Lesson lesson = course.getLesson(lessonDir.getName()); Task task = lesson.getTask(taskDir.getName()); TaskFile taskFile = task.getTaskFile(file.getName()); + if (taskFile == null) { + return; + } final Map taskFilesCopy = new HashMap(); for (final Map.Entry entry : task.getTaskFiles().entrySet()) { if (entry.getValue() == taskFile) { @@ -103,7 +105,10 @@ public class CCShowPreview extends DumbAwareAction { }); } } - String userFileName = FileUtil.getNameWithoutExtension(file.getName()) + ".py"; + String userFileName = CCProjectService.getRealTaskFileName(file.getName()); + if (userFileName == null) { + return; + } VirtualFile userFile = taskDir.getVirtualFile().findChild(userFileName); if (userFile == null) { LOG.info("Generated file " + userFileName + "was not found"); diff --git a/python/educational/course-creator/src/com/jetbrains/edu/coursecreator/ui/CreateTaskFileDialog.java b/python/educational/course-creator/src/com/jetbrains/edu/coursecreator/ui/CreateTaskFileDialog.java index 40abda126c58..6c79854aaba8 100644 --- a/python/educational/course-creator/src/com/jetbrains/edu/coursecreator/ui/CreateTaskFileDialog.java +++ b/python/educational/course-creator/src/com/jetbrains/edu/coursecreator/ui/CreateTaskFileDialog.java @@ -8,21 +8,25 @@ import com.intellij.openapi.ui.DialogWrapper; import com.intellij.ui.DoubleClickListener; import com.intellij.ui.ListScrollingUtil; import com.intellij.ui.components.JBList; +import com.jetbrains.edu.coursecreator.CCUtils; +import com.jetbrains.edu.coursecreator.StudyLanguageManager; +import com.jetbrains.edu.coursecreator.format.Course; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import javax.swing.*; -import javax.swing.event.ListSelectionEvent; -import javax.swing.event.ListSelectionListener; import java.awt.event.MouseEvent; public class CreateTaskFileDialog extends DialogWrapper { + private final Course myCourse; private JPanel myPanel; private JBList myList; private JTextField myTextField; @SuppressWarnings("unchecked") - public CreateTaskFileDialog(@Nullable Project project, String generatedFileName) { + public CreateTaskFileDialog(@Nullable Project project, String generatedFileName, @NotNull final Course course) { super(project); + myCourse = course; FileType[] fileTypes = FileTypeManager.getInstance().getRegisteredFileTypes(); DefaultListModel model = new DefaultListModel(); @@ -51,16 +55,11 @@ public class CreateTaskFileDialog extends DialogWrapper { } }.installOn(myList); - myList.getSelectionModel().addListSelectionListener( - new ListSelectionListener() { - @Override - public void valueChanged(ListSelectionEvent e) { - //TODO: do smth to check validness - } - } - ); - - ListScrollingUtil.selectItem(myList, FileTypeManager.getInstance().getFileTypeByExtension("py")); + StudyLanguageManager manager = CCUtils.getStudyLanguageManager(myCourse); + if (manager != null) { + String extension = manager.getDefaultTaskFileExtension(); + ListScrollingUtil.selectItem(myList, FileTypeManager.getInstance().getFileTypeByExtension(extension != null ? extension : "txt")); + } return myPanel; } diff --git a/python/helpers/pycharm/django_manage_commands_provider/_optparse.py b/python/helpers/pycharm/django_manage_commands_provider/_optparse.py index 16617ab40fcb..5680b80569c6 100644 --- a/python/helpers/pycharm/django_manage_commands_provider/_optparse.py +++ b/python/helpers/pycharm/django_manage_commands_provider/_optparse.py @@ -24,17 +24,26 @@ def report_data(dumper): command = utility.fetch_command(command_name) assert isinstance(command, BaseCommand) dumper.start_command(command_name=command_name, - command_help_text=str(command.usage("").replace("%prog", command_name)), # TODO: support subcommands + command_help_text=str(command.usage("").replace("%prog", command_name)), + # TODO: support subcommands command_args_text=str(command.args)) for opt in command.option_list: - opt_type = opt.type if opt.type in Option.TYPES else "" # Empty for unknown + num_of_args = int(opt.nargs) if opt.nargs else 0 + opt_type = None + if num_of_args > 0: + # If option accepts arg, we need to determine its type. It could be int, choices, or something other + # See https://docs.python.org/2/library/optparse.html#standard-option-types + if opt.type in ["int", "long"]: + opt_type = "int" + elif opt.choices: + assert isinstance(opt.choices, list), "Choices should be list" + opt_type = opt.choices + # There is no official way to access this field, so I use protected one. At least it is public API. # noinspection PyProtectedMember dumper.add_command_option( - opt_type=opt_type, - choices=opt.choices, long_opt_names=opt._long_opts, short_opt_names=opt._short_opts, help_text=opt.help, - num_of_args=opt.nargs) + argument_info=(num_of_args, opt_type) if num_of_args else None) dumper.close_command() \ No newline at end of file diff --git a/python/helpers/pycharm/django_manage_commands_provider/_xml.py b/python/helpers/pycharm/django_manage_commands_provider/_xml.py index 40260a01ab83..4f034026dd4d 100644 --- a/python/helpers/pycharm/django_manage_commands_provider/_xml.py +++ b/python/helpers/pycharm/django_manage_commands_provider/_xml.py @@ -6,13 +6,17 @@ It does not have schema (yet!) but here is XML format it uses. -- root -- info about command - +"option_type" is only set if "numberOfArgs" > 0, and it can be: "int" (means integer), +"choices" (means opt can have one of the values, provided in choices) or "str" that means "string" (option may have any value) + Classes like DjangoCommandsInfo is used on Java side. """ @@ -77,35 +81,45 @@ class XmlDumper(object): self.__command_element.setAttribute("args", command_args_text) self.__root.appendChild(self.__command_element) - def add_command_option(self, opt_type, choices, long_opt_names, short_opt_names, help_text, num_of_args): + def add_command_option(self, long_opt_names, short_opt_names, help_text, argument_info): """ Adds command option - :param opt_type: "string", "int", "long", "float", "complex", "choice" - :param choices: list of choices for "choice" type + :param argument_info: None if option does not accept any arguments or tuple of (num_of_args, type_info) \ + where num_of_args is int > 0 and type_info is str, representing type (only "int" and "string" are supported) \ + or list of available types in case of choices + :param long_opt_names: list of long opt names :param short_opt_names: list of short opt names :param help_text: help text - :param num_of_args: number of arguments - :type opt_type str - :type choices list of string :type long_opt_names list of str :type short_opt_names list of str :type help_text str - :type num_of_args int + :type argument_info tuple """ assert isinstance(self.__command_element, Element), "Add option in command only" - option = self.__document.createElement("option") - option.setAttribute("type", opt_type) - if choices: - self.__create_text_array(option, "choices", choices) + option = self.__document.createElement("option") + + opt_type_to_report = None + num_of_args = 0 + + if argument_info: + (num_of_args, type_info) = argument_info + if isinstance(type_info, list): + self.__create_text_array(option, "choices", type_info) + opt_type_to_report = "choices" + else: + opt_type_to_report = "int" if str(type_info) == "int" else "str" + if long_opt_names: self.__create_text_array(option, "longNames", long_opt_names) if short_opt_names: self.__create_text_array(option, "shortNames", short_opt_names) + if opt_type_to_report: + option.setAttribute("type", opt_type_to_report) option.setAttribute("help", help_text) if num_of_args: option.setAttribute("numberOfArgs", str(num_of_args)) diff --git a/python/src/com/jetbrains/python/commandInterface/commandBasedChunkDriver/Argument.java b/python/src/com/jetbrains/python/commandInterface/command/Argument.java similarity index 96% rename from python/src/com/jetbrains/python/commandInterface/commandBasedChunkDriver/Argument.java rename to python/src/com/jetbrains/python/commandInterface/command/Argument.java index fc3f64192c17..4e33c3b585e9 100644 --- a/python/src/com/jetbrains/python/commandInterface/commandBasedChunkDriver/Argument.java +++ b/python/src/com/jetbrains/python/commandInterface/command/Argument.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.jetbrains.python.commandInterface.commandBasedChunkDriver; +package com.jetbrains.python.commandInterface.command; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/python/src/com/jetbrains/python/commandInterface/commandBasedChunkDriver/ArgumentsInfo.java b/python/src/com/jetbrains/python/commandInterface/command/ArgumentsInfo.java similarity index 95% rename from python/src/com/jetbrains/python/commandInterface/commandBasedChunkDriver/ArgumentsInfo.java rename to python/src/com/jetbrains/python/commandInterface/command/ArgumentsInfo.java index ad43da45adcd..c1eb793702e9 100644 --- a/python/src/com/jetbrains/python/commandInterface/commandBasedChunkDriver/ArgumentsInfo.java +++ b/python/src/com/jetbrains/python/commandInterface/command/ArgumentsInfo.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.jetbrains.python.commandInterface.commandBasedChunkDriver; +package com.jetbrains.python.commandInterface.command; import com.intellij.openapi.util.Pair; import org.jetbrains.annotations.Nullable; diff --git a/python/src/com/jetbrains/python/commandInterface/commandBasedChunkDriver/Command.java b/python/src/com/jetbrains/python/commandInterface/command/Command.java similarity index 87% rename from python/src/com/jetbrains/python/commandInterface/commandBasedChunkDriver/Command.java rename to python/src/com/jetbrains/python/commandInterface/command/Command.java index 694021964fea..2d15d152c3c1 100644 --- a/python/src/com/jetbrains/python/commandInterface/commandBasedChunkDriver/Command.java +++ b/python/src/com/jetbrains/python/commandInterface/command/Command.java @@ -13,15 +13,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.jetbrains.python.commandInterface.commandBasedChunkDriver; +package com.jetbrains.python.commandInterface.command; import com.intellij.openapi.module.Module; import com.jetbrains.python.commandLineParser.CommandLineParseResult; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.List; + /** - * Command with arguments + * Command with arguments and options * * @author Ilya.Kazakevich */ @@ -47,6 +49,12 @@ public interface Command { @NotNull ArgumentsInfo getArgumentsInfo(); + /** + * @return command options + */ + @NotNull + List