diff --git a/bin/WinLauncher/WinLauncher.exe b/bin/WinLauncher/WinLauncher.exe index afe000ae7459..63ac50cb58b0 100644 Binary files a/bin/WinLauncher/WinLauncher.exe and b/bin/WinLauncher/WinLauncher.exe differ diff --git a/bin/WinLauncher/WinLauncher64.exe b/bin/WinLauncher/WinLauncher64.exe index 7dc6ef8deb5e..057f254b556d 100644 Binary files a/bin/WinLauncher/WinLauncher64.exe and b/bin/WinLauncher/WinLauncher64.exe differ diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ProjectStructureConfigurable.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ProjectStructureConfigurable.java index 6ecb0eb721ed..cad34394837e 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ProjectStructureConfigurable.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ProjectStructureConfigurable.java @@ -64,7 +64,8 @@ import java.util.List; import static com.intellij.openapi.roots.ui.configuration.ProjectStructureConfigurableFilter.ConfigurableId; -public class ProjectStructureConfigurable extends BaseConfigurable implements SearchableConfigurable, Place.Navigator { +public class ProjectStructureConfigurable extends BaseConfigurable implements SearchableConfigurable, Place.Navigator, + Configurable.NoMargin, Configurable.NoScroll { public static final DataKey KEY = DataKey.create("ProjectStructureConfiguration"); diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/SideEffectWarningDialog.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/SideEffectWarningDialog.java index df1d14851323..8a992662935d 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/SideEffectWarningDialog.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/SideEffectWarningDialog.java @@ -26,6 +26,7 @@ import org.jetbrains.annotations.NotNull; import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; +import java.text.MessageFormat; import java.util.ArrayList; import java.util.List; @@ -62,7 +63,7 @@ public class SideEffectWarningDialog extends DialogWrapper { } @Override - public void actionPerformed(ActionEvent e) { + public void actionPerformed(@NotNull ActionEvent e) { close(RemoveUnusedVariableUtil.RemoveMode.DELETE_ALL.ordinal()); } @@ -75,7 +76,7 @@ public class SideEffectWarningDialog extends DialogWrapper { } @Override - public void actionPerformed(ActionEvent e) { + public void actionPerformed(@NotNull ActionEvent e) { close(RemoveUnusedVariableUtil.RemoveMode.MAKE_STATEMENT.ordinal()); } }; @@ -87,7 +88,7 @@ public class SideEffectWarningDialog extends DialogWrapper { } @Override - public void actionPerformed(ActionEvent e) { + public void actionPerformed(@NotNull ActionEvent e) { doCancelAction(); } @@ -125,11 +126,34 @@ public class SideEffectWarningDialog extends DialogWrapper { protected String sideEffectsDescription() { if (myCanCopeWithSideEffects) { - return QuickFixBundle.message("side.effect.message2", - myVariable.getName(), - myVariable.getType().getPresentableText(), - myBeforeText, - myAfterText); + String format = "\n" + + "\n" + + "There are possible side effects found in expressions assigned to the variable ''{0}''
\n" + + "You can:\n" + + "
\n" + + "— Remove variable usages along with all expressions involved, or
\n" + + "— Transform expressions assigned to variable into the statements on their own.
\n" + + "
\n" + + " That is,
\n" + + " \n" + + " \n" + + " \n" + + " \n" + + "
{1} {0} = {2};
\n" + + " becomes:
\n" + + " \n" + + " \n" + + " \n" + + " \n" + + "
{3};
\n" + + "
\n" + + "\n" + + ""; + return MessageFormat.format(format, + myVariable.getName(), + myVariable.getType().getPresentableText(), + myBeforeText, + myAfterText); } else { return QuickFixBundle.message("side.effect.message1", myVariable.getName()); diff --git a/java/java-psi-api/src/com/intellij/psi/util/TypeConversionUtil.java b/java/java-psi-api/src/com/intellij/psi/util/TypeConversionUtil.java index d7a60cc4cb88..b75d6687f8ac 100644 --- a/java/java-psi-api/src/com/intellij/psi/util/TypeConversionUtil.java +++ b/java/java-psi-api/src/com/intellij/psi/util/TypeConversionUtil.java @@ -447,7 +447,7 @@ public class TypeConversionUtil { return PsiType.VOID.equals(type); } - public static boolean isBooleanType(PsiType type) { + public static boolean isBooleanType(@Nullable PsiType type) { return PsiType.BOOLEAN.equals(type) || PsiType.BOOLEAN.equals(PsiPrimitiveType.getUnboxedType(type)); } diff --git a/native/WinLauncher/WinLauncher/WinLauncher.rc b/native/WinLauncher/WinLauncher/WinLauncher.rc index 463b099cfefe..6c7a8cf9f763 100644 Binary files a/native/WinLauncher/WinLauncher/WinLauncher.rc and b/native/WinLauncher/WinLauncher/WinLauncher.rc differ diff --git a/platform/core-api/src/com/intellij/psi/util/PsiCacheKey.java b/platform/core-api/src/com/intellij/psi/util/PsiCacheKey.java index 1f31645ed258..cdaf8d067426 100644 --- a/platform/core-api/src/com/intellij/psi/util/PsiCacheKey.java +++ b/platform/core-api/src/com/intellij/psi/util/PsiCacheKey.java @@ -28,12 +28,18 @@ import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -public class PsiCacheKey extends Key>> { - private final Function myFunction; +public class PsiCacheKey extends Key>> { + private final Function myFunction; + /** + * One of {@link com.intellij.psi.util.PsiModificationTracker} constants that marks when to flush cache + */ + @NotNull + private final Key myModifyCause; - private PsiCacheKey(@NonNls @NotNull String name, @NotNull Function function) { + private PsiCacheKey(@NonNls @NotNull String name, @NotNull Function function, @NotNull Key modifyCause) { super(name); myFunction = function; + myModifyCause = modifyCause; } public final T getValue(@NotNull H h) { @@ -43,7 +49,7 @@ public class PsiCacheKey extends Key>(new Pair(count, result))); return result; } @@ -52,14 +58,61 @@ public class PsiCacheKey extends Key> ref = h.getUserData(this); Pair data = SoftReference.dereference(ref); - if (data == null || data.getFirst() != h.getManager().getModificationTracker().getJavaStructureModificationCount()) { + if (data == null || data.getFirst() != getModificationCount(h.getManager().getModificationTracker())) { return null; } return data.getSecond(); } - public static PsiCacheKey create(@NonNls @NotNull String name, @NotNull Function function) { - return new PsiCacheKey(name, function); + + /** + * Gets modification count from tracker based on {@link #myModifyCause} + * + * @param tracker track to get modification count from + * @return modification count + * @throws AssertionError if {@link #myModifyCause} is junk + */ + private long getModificationCount(@NotNull PsiModificationTracker tracker) { + if (myModifyCause.equals(PsiModificationTracker.JAVA_STRUCTURE_MODIFICATION_COUNT)) { + return tracker.getJavaStructureModificationCount(); + } + if (myModifyCause.equals(PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT)) { + return tracker.getOutOfCodeBlockModificationCount(); + } + if (myModifyCause.equals(PsiModificationTracker.MODIFICATION_COUNT)) { + return tracker.getModificationCount(); + } + throw new AssertionError("No modification tracker found for key " + myModifyCause); + } + + /** + * Creates cache key value + * + * @param name key name + * @param function function to reproduce new value when old value is stale + * @param modifyCause one one {@link com.intellij.psi.util.PsiModificationTracker}'s constants that marks when to flush cache + * @param value type + * @param key type + * @return instance + */ + public static PsiCacheKey create(@NonNls @NotNull String name, + @NotNull Function function, + @NotNull Key modifyCause) { + return new PsiCacheKey(name, function, modifyCause); + } + + /** + * Creates cache key value using {@link com.intellij.psi.util.PsiModificationTracker#JAVA_STRUCTURE_MODIFICATION_COUNT} as + * modification count to flush cache + * + * @param name key name + * @param function function to reproduce new value when old value is stale + * @param value type + * @param key type + * @return instance + */ + public static PsiCacheKey create(@NonNls @NotNull String name, @NotNull Function function) { + return create(name, function, PsiModificationTracker.JAVA_STRUCTURE_MODIFICATION_COUNT); } } diff --git a/platform/extensions/src/com/intellij/openapi/extensions/PluginId.java b/platform/extensions/src/com/intellij/openapi/extensions/PluginId.java index 84fba8f3b547..c784bef6eaca 100644 --- a/platform/extensions/src/com/intellij/openapi/extensions/PluginId.java +++ b/platform/extensions/src/com/intellij/openapi/extensions/PluginId.java @@ -41,7 +41,7 @@ public class PluginId implements Comparable { } @NotNull - public static PluginId getId(String idString) { + public static synchronized PluginId getId(String idString) { PluginId pluginId = ourRegisteredIds.get(idString); if (pluginId == null) { pluginId = new PluginId(idString); @@ -60,7 +60,7 @@ public class PluginId implements Comparable { return getIdString(); } - public static Map getRegisteredIds() { - return ourRegisteredIds; + public static synchronized Map getRegisteredIds() { + return new HashMap(ourRegisteredIds); } } diff --git a/platform/lang-impl/src/com/intellij/ide/actions/CreateFileAction.java b/platform/lang-impl/src/com/intellij/ide/actions/CreateFileAction.java index 60d85dcc27d3..50d427b9f5a2 100644 --- a/platform/lang-impl/src/com/intellij/ide/actions/CreateFileAction.java +++ b/platform/lang-impl/src/com/intellij/ide/actions/CreateFileAction.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -85,7 +85,7 @@ public class CreateFileAction extends CreateElementActionBase implements DumbAwa public final String newName; public final PsiDirectory directory; - public MkDirs(String newName, PsiDirectory directory) { + public MkDirs(@NotNull String newName, @NotNull PsiDirectory directory) { if (SystemInfo.isWindows) { newName = newName.replace('\\', '/'); } diff --git a/platform/lang-impl/src/com/intellij/ide/actions/CreateFileFromTemplateAction.java b/platform/lang-impl/src/com/intellij/ide/actions/CreateFileFromTemplateAction.java index 5c1e43ccad85..d9e7ce3c403b 100644 --- a/platform/lang-impl/src/com/intellij/ide/actions/CreateFileFromTemplateAction.java +++ b/platform/lang-impl/src/com/intellij/ide/actions/CreateFileFromTemplateAction.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2010 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -52,14 +52,16 @@ public abstract class CreateFileFromTemplateAction extends CreateFromTemplateAct @NotNull FileTemplate template, @NotNull PsiDirectory dir, @Nullable String defaultTemplateProperty) { - CreateFileAction.MkDirs mkdirs = new CreateFileAction.MkDirs(name, dir); - name = mkdirs.newName; - dir = mkdirs.directory; + if (name != null) { + CreateFileAction.MkDirs mkdirs = new CreateFileAction.MkDirs(name, dir); + name = mkdirs.newName; + dir = mkdirs.directory; + } + PsiElement element; Project project = dir.getProject(); try { - element = FileTemplateUtil - .createFromTemplate(template, name, FileTemplateManager.getInstance().getDefaultProperties(project), dir); + element = FileTemplateUtil.createFromTemplate(template, name, FileTemplateManager.getInstance().getDefaultProperties(project), dir); final PsiFile psiFile = element.getContainingFile(); final VirtualFile virtualFile = psiFile.getVirtualFile(); diff --git a/platform/lang-impl/src/com/intellij/ide/fileTemplates/ui/CreateFromTemplateDialog.java b/platform/lang-impl/src/com/intellij/ide/fileTemplates/ui/CreateFromTemplateDialog.java index c2910689e9cc..c67cac026e55 100644 --- a/platform/lang-impl/src/com/intellij/ide/fileTemplates/ui/CreateFromTemplateDialog.java +++ b/platform/lang-impl/src/com/intellij/ide/fileTemplates/ui/CreateFromTemplateDialog.java @@ -24,6 +24,7 @@ import com.intellij.ide.fileTemplates.FileTemplateManager; import com.intellij.ide.fileTemplates.FileTemplateUtil; import com.intellij.ide.fileTemplates.actions.AttributesDefaults; import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.DialogWrapper; import com.intellij.openapi.ui.Messages; @@ -41,6 +42,7 @@ import java.awt.*; import java.util.Properties; public class CreateFromTemplateDialog extends DialogWrapper { + private static final Logger LOG = Logger.getInstance("#com.intellij.ide.fileTemplates.ui.CreateFromTemplateDialog"); @NotNull private final PsiDirectory myDirectory; @NotNull private final Project myProject; private PsiElement myCreatedElement; @@ -113,16 +115,22 @@ public class CreateFromTemplateDialog extends DialogWrapper { } } - private void doCreate(@Nullable final String fileName) { + private void doCreate(@Nullable String fileName) { try { - final CreateFileAction.MkDirs mkDirs = ApplicationManager.getApplication().runWriteAction(new Computable() { - @Override - public CreateFileAction.MkDirs compute() { - return new CreateFileAction.MkDirs(fileName, myDirectory); - } - }); - myCreatedElement = FileTemplateUtil.createFromTemplate(myTemplate, mkDirs.newName, myAttrPanel.getProperties(myDefaultProperties), - mkDirs.directory); + String newName = fileName; + PsiDirectory directory = myDirectory; + if (fileName != null) { + final String finalFileName = fileName; + CreateFileAction.MkDirs mkDirs = ApplicationManager.getApplication().runWriteAction(new Computable() { + @Override + public CreateFileAction.MkDirs compute() { + return new CreateFileAction.MkDirs(finalFileName, myDirectory); + } + }); + newName = mkDirs.newName; + directory = mkDirs.directory; + } + myCreatedElement = FileTemplateUtil.createFromTemplate(myTemplate, newName, myAttrPanel.getProperties(myDefaultProperties), directory); } catch (Exception e) { showErrorDialog(e); @@ -134,6 +142,7 @@ public class CreateFromTemplateDialog extends DialogWrapper { } private void showErrorDialog(final Exception e) { + LOG.info(e); Messages.showMessageDialog(myProject, filterMessage(e.getMessage()), getErrorMessage(), Messages.getErrorIcon()); } diff --git a/platform/lang-impl/src/com/intellij/openapi/diff/impl/settings/DiffOptionsPanel.form b/platform/lang-impl/src/com/intellij/openapi/diff/impl/settings/DiffOptionsPanel.form index da448f48342f..08ed4f4799a1 100644 --- a/platform/lang-impl/src/com/intellij/openapi/diff/impl/settings/DiffOptionsPanel.form +++ b/platform/lang-impl/src/com/intellij/openapi/diff/impl/settings/DiffOptionsPanel.form @@ -29,7 +29,7 @@ - + @@ -37,24 +37,34 @@ - + - + - - + - + + + + + + + - + + + + + + diff --git a/platform/lang-impl/src/com/intellij/openapi/diff/impl/settings/DiffOptionsPanel.java b/platform/lang-impl/src/com/intellij/openapi/diff/impl/settings/DiffOptionsPanel.java index 74e47bd22079..a21cceaa821f 100644 --- a/platform/lang-impl/src/com/intellij/openapi/diff/impl/settings/DiffOptionsPanel.java +++ b/platform/lang-impl/src/com/intellij/openapi/diff/impl/settings/DiffOptionsPanel.java @@ -22,7 +22,6 @@ import com.intellij.openapi.editor.colors.EditorColorsScheme; import com.intellij.openapi.editor.colors.TextAttributesKey; import com.intellij.openapi.editor.markup.EffectType; import com.intellij.openapi.editor.markup.TextAttributes; -import com.intellij.openapi.ui.LabeledComponent; import com.intellij.openapi.util.Comparing; import com.intellij.ui.*; import com.intellij.util.EventDispatcher; @@ -44,10 +43,10 @@ import java.util.Set; public class DiffOptionsPanel implements OptionsPanel { private final ColorAndFontOptions myOptions; private final EventDispatcher myDispatcher = EventDispatcher.create(ColorAndFontSettingsListener.class); - private LabeledComponent myBackgoundColorPanelComponent; + private ColorPanel myBackgroundColorPanel; private JList myOptionsList; private JPanel myWholePanel; - private LabeledComponent myStripeMarkColorComponent; + private ColorPanel myStripeMarkColorPanel; public DiffOptionsPanel(ColorAndFontOptions options) { @@ -62,18 +61,16 @@ public class DiffOptionsPanel implements OptionsPanel { @Override public void valueChanged(ListSelectionEvent e) { TextDiffType selection = getSelectedOption(); - ColorPanel background = getBackgroundColorPanel(); - ColorPanel stripeMark = getStripeMarkColorPanel(); if (selection == null) { - background.setEnabled(false); - stripeMark.setEnabled(false); + myBackgroundColorPanel.setEnabled(false); + myStripeMarkColorPanel.setEnabled(false); } else { - background.setEnabled(true); - stripeMark.setEnabled(true); + myBackgroundColorPanel.setEnabled(true); + myStripeMarkColorPanel.setEnabled(true); MyColorAndFontDescription description = getSelectedDescription(); if (description != null) { - background.setSelectedColor(description.getBackgroundColor()); - stripeMark.setSelectedColor(description.getStripeMarkColor()); + myBackgroundColorPanel.setSelectedColor(description.getBackgroundColor()); + myStripeMarkColorPanel.setSelectedColor(description.getStripeMarkColor()); } } @@ -81,29 +78,27 @@ public class DiffOptionsPanel implements OptionsPanel { } }); - getBackgroundColorPanel().addActionListener(new ActionListener() { + myBackgroundColorPanel.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { MyColorAndFontDescription selectedDescription = getSelectedDescription(); - ColorPanel colorPanel = getBackgroundColorPanel(); if (!checkModifiableScheme()) { - colorPanel.setSelectedColor(selectedDescription.getBackgroundColor()); + myBackgroundColorPanel.setSelectedColor(selectedDescription.getBackgroundColor()); return; } - selectedDescription.setBackgroundColor(colorPanel.getSelectedColor()); + selectedDescription.setBackgroundColor(myBackgroundColorPanel.getSelectedColor()); myDispatcher.getMulticaster().settingsChanged(); } }); - getStripeMarkColorPanel().addActionListener(new ActionListener() { + myStripeMarkColorPanel.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { MyColorAndFontDescription selectedDescription = getSelectedDescription(); - ColorPanel colorPanel = getStripeMarkColorPanel(); if (!checkModifiableScheme()) { - colorPanel.setSelectedColor(selectedDescription.getStripeMarkColor()); + myStripeMarkColorPanel.setSelectedColor(selectedDescription.getStripeMarkColor()); return; } - selectedDescription.setStripeMarkColor(colorPanel.getSelectedColor()); + selectedDescription.setStripeMarkColor(myStripeMarkColorPanel.getSelectedColor()); myDispatcher.getMulticaster().settingsChanged(); } }); @@ -238,14 +233,6 @@ public class DiffOptionsPanel implements OptionsPanel { return myDescriptions.get(selection.getAttributesKey().getExternalName()); } - private ColorPanel getBackgroundColorPanel() { - return myBackgoundColorPanelComponent.getComponent(); - } - - private ColorPanel getStripeMarkColorPanel() { - return myStripeMarkColorComponent.getComponent(); - } - public static void addSchemeDescriptions(@NotNull List descriptions, @NotNull EditorColorsScheme scheme) { for (TextDiffType diffType : TextDiffType.MERGE_TYPES) { descriptions.add(new MyColorAndFontDescription(diffType, scheme)); diff --git a/platform/lang-impl/src/com/intellij/openapi/diff/impl/settings/DiffPreviewPanel.java b/platform/lang-impl/src/com/intellij/openapi/diff/impl/settings/DiffPreviewPanel.java index 9e329582ddad..7be3f9296978 100644 --- a/platform/lang-impl/src/com/intellij/openapi/diff/impl/settings/DiffPreviewPanel.java +++ b/platform/lang-impl/src/com/intellij/openapi/diff/impl/settings/DiffPreviewPanel.java @@ -54,6 +54,7 @@ public class DiffPreviewPanel implements PreviewPanel { myPanel.add(myMergePanelComponent, BorderLayout.CENTER); myMergePanelComponent.setToolbarEnabled(false); MergePanel2 mergePanel = getMergePanel(); + mergePanel.setScrollToFirstDiff(false); for (int i = 0; i < MergePanel2.EDITORS_COUNT; i++) { final EditorMouseListener motionListener = new EditorMouseListener(i); diff --git a/platform/platform-api/src/com/intellij/ui/components/panels/HorizontalLayout.java b/platform/platform-api/src/com/intellij/ui/components/panels/HorizontalLayout.java new file mode 100644 index 000000000000..63f982b806f3 --- /dev/null +++ b/platform/platform-api/src/com/intellij/ui/components/panels/HorizontalLayout.java @@ -0,0 +1,216 @@ +/* + * Copyright 2000-2014 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * 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.ui.components.panels; + +import javax.swing.SwingConstants; +import java.awt.Component; +import java.awt.Container; +import java.awt.Dimension; +import java.awt.Insets; +import java.awt.LayoutManager; +import java.util.ArrayList; + +/** + * @author Sergey.Malenkov + */ +public final class HorizontalLayout implements LayoutManager { + public static final String LEFT = "LEFT"; + public static final String RIGHT = "RIGHT"; + public static final String CENTER = "CENTER"; + + private final ArrayList myLeft = new ArrayList(); + private final ArrayList myRight = new ArrayList(); + private final ArrayList myCenter = new ArrayList(); + private final int myAlignment; + private final int myGap; + + /** + * Creates a layout with the specified gap. + * All components will have preferred widths, + * but their heights will be set according to the container. + * + * @param gap horizontal gap between components + */ + public HorizontalLayout(int gap) { + myGap = gap; + myAlignment = -1; + } + + /** + * Creates a layout with the specified gap and vertical alignment. + * All components will have preferred sizes. + * + * @param gap horizontal gap between components + * @param alignment vertical alignment for components + * + * @see SwingConstants#TOP + * @see SwingConstants#BOTTOM + * @see SwingConstants#CENTER + */ + public HorizontalLayout(int gap, int alignment) { + myGap = gap; + switch (alignment) { + case SwingConstants.TOP: + case SwingConstants.BOTTOM: + case SwingConstants.CENTER: + myAlignment = alignment; + break; + default: + throw new IllegalArgumentException("unsupported alignment: " + alignment); + } + } + + @Override + public void addLayoutComponent(String name, Component component) { + synchronized (component.getTreeLock()) { + if (name == null || CENTER.equalsIgnoreCase(name)) { + myCenter.add(component); + } + else if (LEFT.equalsIgnoreCase(name)) { + myLeft.add(component); + } + else if (RIGHT.equalsIgnoreCase(name)) { + myRight.add(component); + } + else { + throw new IllegalArgumentException("unsupported name: " + name); + } + } + } + + @Override + public void removeLayoutComponent(Component component) { + myLeft.remove(component); + myRight.remove(component); + myCenter.remove(component); + } + + @Override + public Dimension preferredLayoutSize(Container container) { + return getPreferredSize(container, true); + } + + @Override + public Dimension minimumLayoutSize(Container container) { + return getPreferredSize(container, false); + } + + @Override + public void layoutContainer(Container container) { + synchronized (container.getTreeLock()) { + Dimension left = getPreferredSize(myLeft); + Dimension right = getPreferredSize(myRight); + Dimension center = getPreferredSize(myCenter); + + Insets insets = container.getInsets(); + int width = container.getWidth() - insets.left - insets.right; + int height = container.getHeight() - insets.top - insets.bottom; + + int leftX = 0; + if (left != null) { + leftX = myGap + layout(myLeft, 0, height, insets); + } + int rightX = width; + if (right != null) { + rightX -= right.width; + } + if (rightX < leftX) { + rightX = leftX; + } + if (center != null) { + int centerX = (width - center.width) / 2; + if (centerX > leftX) { + int centerRightX = centerX + center.width + myGap + myGap; + if (centerRightX > rightX) { + centerX = rightX - center.width - myGap - myGap; + } + } + if (centerX < leftX) { + centerX = leftX; + } + centerX = myGap + layout(myCenter, centerX, height, insets); + if (rightX < centerX) { + rightX = centerX; + } + } + if (right != null) { + layout(myRight, rightX, height, insets); + } + } + } + + private int layout(ArrayList list, int x, int height, Insets insets) { + for (Component component : list) { + Dimension size = component.getPreferredSize(); + int y = 0; + if (myAlignment == -1) { + size.height = height; + } + else if (myAlignment != SwingConstants.TOP) { + y = height - size.height; + if (myAlignment == SwingConstants.CENTER) { + y /= 2; + } + } + component.setBounds(x + insets.left, y + insets.top, size.width, size.height); + x += size.width + myGap; + } + return x; + } + + private static Dimension join(Dimension result, int gap, Dimension size) { + if (size == null) { + return result; + } + if (result == null) { + return new Dimension(size); + } + result.width += gap + size.width; + if (result.height < size.height) { + result.height = size.height; + } + return result; + } + + private Dimension getPreferredSize(ArrayList list) { + Dimension result = null; + for (Component component : list) { + result = join(result, myGap, component.getPreferredSize()); + } + return result; + } + + private Dimension getPreferredSize(Container container, boolean aligned) { + synchronized (container.getTreeLock()) { + Dimension left = getPreferredSize(myLeft); + Dimension right = getPreferredSize(myRight); + Dimension center = getPreferredSize(myCenter); + Dimension result = join(join(join(null, myGap + myGap, left), myGap + myGap, center), myGap + myGap, right); + if (result == null) { + result = new Dimension(); + } + else if (aligned) { + int leftWidth = left == null ? 0 : left.width; + int rightWidth = right == null ? 0 : right.width; + result.width += Math.abs(leftWidth - rightWidth); + } + Insets insets = container.getInsets(); + result.width += insets.left + insets.right; + result.height += insets.top + insets.bottom; + return result; + } + } +} diff --git a/platform/platform-api/src/com/intellij/util/ui/ButtonlessScrollBarUI.java b/platform/platform-api/src/com/intellij/util/ui/ButtonlessScrollBarUI.java index 314e33e6c5af..51351040d7bc 100644 --- a/platform/platform-api/src/com/intellij/util/ui/ButtonlessScrollBarUI.java +++ b/platform/platform-api/src/com/intellij/util/ui/ButtonlessScrollBarUI.java @@ -15,7 +15,6 @@ */ package com.intellij.util.ui; -import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.util.Disposer; import com.intellij.openapi.util.SystemInfo; @@ -119,7 +118,8 @@ public class ButtonlessScrollBarUI extends BasicScrollBarUI { if (oldViewportPosition != null) { int scrollH = position.x - oldViewportPosition.x; int scrollV = position.y - oldViewportPosition.y; - scrolled = (scrollH == 0 && scrollV != 0 && vertical) || (scrollV == 0 && scrollH != 0 && !vertical); + scrolled = (vertical && scrollH == 0 && scrollV != 0) || + (!vertical && scrollV == 0 && scrollH != 0); } oldViewportPosition = position; @@ -127,7 +127,7 @@ public class ButtonlessScrollBarUI extends BasicScrollBarUI { if (oldViewportDimension != null) { int resizedH = dimension.width - oldViewportDimension.width; int resizedV = dimension.height - oldViewportDimension.height; - resized = (resizedV != 0 && vertical) || (resizedH != 0 && !vertical); + resized = (vertical && resizedV != 0) || (!vertical && resizedH != 0); } oldViewportDimension = dimension; @@ -339,7 +339,7 @@ public class ButtonlessScrollBarUI extends BasicScrollBarUI { public void run() { myMacScrollbarFadeAnimator.resume(); } - }, 700, ModalityState.any()); + }, 700, null); } } } @@ -504,12 +504,7 @@ public class ButtonlessScrollBarUI extends BasicScrollBarUI { @Override public void paintNow(int frame, int totalFrames, int cycle) { - int delay = (int)(0); - int frameAfterDelay = frame - delay; - - if (frameAfterDelay > 0) { - myMacScrollbarFadeLevel = frameAfterDelay / (float)(totalFrames - delay); - } + myMacScrollbarFadeLevel = frame / (float)totalFrames; if (scrollbar != null) scrollbar.repaint(); } }; diff --git a/platform/platform-impl/src/com/intellij/notification/impl/ui/NotificationsConfigurablePanel.java b/platform/platform-impl/src/com/intellij/notification/impl/ui/NotificationsConfigurablePanel.java index dfbbd69b9ca8..57569e00a154 100644 --- a/platform/platform-impl/src/com/intellij/notification/impl/ui/NotificationsConfigurablePanel.java +++ b/platform/platform-impl/src/com/intellij/notification/impl/ui/NotificationsConfigurablePanel.java @@ -64,7 +64,7 @@ public class NotificationsConfigurablePanel extends JPanel implements Disposable myDisplayBalloons = new JCheckBox("Display balloon notifications"); myDisplayBalloons.setMnemonic('b'); if (newSettings) { - myDisplayBalloons.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); + myDisplayBalloons.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); } add(myDisplayBalloons, BorderLayout.NORTH); myDisplayBalloons.addActionListener(new ActionListener() { diff --git a/platform/platform-impl/src/com/intellij/openapi/diff/actions/DiffWalkerAction.java b/platform/platform-impl/src/com/intellij/openapi/diff/actions/DiffWalkerAction.java index 99766df8e456..4feb09532ee7 100644 --- a/platform/platform-impl/src/com/intellij/openapi/diff/actions/DiffWalkerAction.java +++ b/platform/platform-impl/src/com/intellij/openapi/diff/actions/DiffWalkerAction.java @@ -27,7 +27,7 @@ import com.intellij.openapi.project.DumbAware; import java.awt.event.KeyEvent; -abstract class DiffWalkerAction extends AnAction implements DumbAware { +public abstract class DiffWalkerAction extends AnAction implements DumbAware { protected DiffWalkerAction() { setEnabledInModalContext(true); } diff --git a/platform/platform-impl/src/com/intellij/openapi/diff/ex/DiffStatusBar.java b/platform/platform-impl/src/com/intellij/openapi/diff/ex/DiffStatusBar.java index c56fdd2ee2b3..6c371cda92d4 100644 --- a/platform/platform-impl/src/com/intellij/openapi/diff/ex/DiffStatusBar.java +++ b/platform/platform-impl/src/com/intellij/openapi/diff/ex/DiffStatusBar.java @@ -17,83 +17,34 @@ package com.intellij.openapi.diff.ex; import com.intellij.openapi.editor.colors.EditorColorsManager; import com.intellij.openapi.editor.colors.EditorColorsScheme; +import com.intellij.ui.components.panels.HorizontalLayout; import com.intellij.util.ui.GraphicsUtil; -import com.intellij.util.ui.UIUtil; import org.jetbrains.annotations.Nullable; import javax.swing.*; import java.awt.*; -import java.util.ArrayList; -import java.util.Collection; import java.util.List; /** * @author Yura Cangea */ public class DiffStatusBar extends JPanel { - private final Collection myLabels = new ArrayList(); - private final JLabel myTextLabel = new JLabel(""); - private static final int COMP_HEIGHT = 30; private EditorColorsScheme myColorScheme = null; public DiffStatusBar(List types) { - for (T differenceType : types) { - addDiffType(differenceType); + super(new HorizontalLayout(10)); + setBorder(BorderFactory.createEmptyBorder(5, 10, 10, 10)); + add(HorizontalLayout.LEFT, myTextLabel); + for (LegendTypeDescriptor type : types) { + add(HorizontalLayout.CENTER, new LegendTypeLabel(type)); } - initGui(); - } - - private void addDiffType(final LegendTypeDescriptor diffType){ - addComponent(diffType); - } - - private void addComponent(final LegendTypeDescriptor diffType) { - JComponent component = new SingleDiffLegendComponent(diffType); - myLabels.add(component); - } - - public Dimension getMinimumSize() { - Dimension p = super.getPreferredSize(); - Dimension m = super.getMinimumSize(); - return new Dimension(m.width, p.height); - } - - public Dimension getMaximumSize() { - Dimension p = super.getPreferredSize(); - Dimension m = super.getMaximumSize(); - return new Dimension(m.width, p.height); } public void setText(String text) { myTextLabel.setText(text); } - private void initGui() { - JComponent filler = new JComponent() { - @Override - public Dimension getPreferredSize() { - return myTextLabel.getPreferredSize(); - } - }; - setLayout(new BorderLayout()); - setBorder(BorderFactory.createEmptyBorder(3, 20, 3, 20)); - - add(myTextLabel, BorderLayout.WEST); - Box box = Box.createHorizontalBox(); - box.add(Box.createHorizontalGlue()); - JPanel panel = new JPanel(new GridLayout(1, myLabels.size(), 0, 0)); - for (final JComponent myLabel : myLabels) { - panel.add(myLabel); - } - panel.setMaximumSize(panel.getPreferredSize()); - box.add(panel); - box.add(Box.createHorizontalGlue()); - add(box, BorderLayout.CENTER); - - add(filler, BorderLayout.EAST); - } - public void setColorScheme(EditorColorsScheme colorScheme) { EditorColorsScheme oldScheme = myColorScheme; myColorScheme = colorScheme; @@ -106,47 +57,32 @@ public class DiffStatusBar extends JPanel { Color getLegendColor(EditorColorsScheme colorScheme); } - private class SingleDiffLegendComponent extends JPanel { - private static final int HORIZONTAL_PADDING = 70; - private final LegendTypeDescriptor myDiffType; + private final class LegendTypeLabel extends JLabel implements Icon { + private final LegendTypeDescriptor myType; - public SingleDiffLegendComponent(LegendTypeDescriptor diffType) { - myDiffType = diffType; + public LegendTypeLabel(LegendTypeDescriptor type) { + super(type.getDisplayName(), SwingConstants.LEFT); + myType = type; + setIconTextGap(5); + setIcon(this); } - public void paint(Graphics g) { - setBackground(UIUtil.getPanelBackground()); - super.paint(g); + @Override + public void paintIcon(Component c, Graphics g, int x, int y) { GraphicsUtil.setupAntialiasing(g); - FontMetrics metrics = getFontMetrics(getFont()); - - EditorColorsScheme colorScheme = myColorScheme != null - ? myColorScheme - : EditorColorsManager.getInstance().getGlobalScheme(); - g.setColor(myDiffType.getLegendColor(colorScheme)); - final int RECT_WIDTH = 35; - g.fill3DRect(0, (getHeight() - 10) / 2, RECT_WIDTH, 10, true); - - Font font = g.getFont(); - if (font.getStyle() != Font.PLAIN) { - font = font.deriveFont(Font.PLAIN); - } - g.setFont(font); - g.setColor(UIUtil.getLabelForeground()); - int textBaseline = (getHeight() - metrics.getHeight()) / 2 + metrics.getAscent(); - g.drawString(myDiffType.getDisplayName(), RECT_WIDTH + UIUtil.DEFAULT_HGAP, textBaseline); + g.setColor(myType.getLegendColor(myColorScheme != null ? myColorScheme : EditorColorsManager.getInstance().getGlobalScheme())); + g.fill3DRect(x, y, getIconWidth(), getIconHeight(), true); } @Override - public Dimension getPreferredSize() { - FontMetrics metrics = getFontMetrics(getFont()); - int stringWidth = (int)metrics.getStringBounds(myDiffType.getDisplayName(), getGraphics()).getWidth(); - return new Dimension(HORIZONTAL_PADDING + stringWidth, COMP_HEIGHT); + public int getIconWidth() { + return 35; } @Override - public Dimension getMinimumSize() { - return getPreferredSize(); + public int getIconHeight() { + Font font = getFont(); + return font != null ? font.getSize() - 2 : 10; } } } diff --git a/platform/platform-impl/src/com/intellij/openapi/diff/impl/DiffUtil.java b/platform/platform-impl/src/com/intellij/openapi/diff/impl/DiffUtil.java index a67a6ad5af71..79146f9a3870 100644 --- a/platform/platform-impl/src/com/intellij/openapi/diff/impl/DiffUtil.java +++ b/platform/platform-impl/src/com/intellij/openapi/diff/impl/DiffUtil.java @@ -27,6 +27,7 @@ import com.intellij.openapi.diff.impl.string.DiffString; import com.intellij.openapi.diff.impl.util.FocusDiffSide; import com.intellij.openapi.diff.impl.util.TextDiffType; import com.intellij.openapi.editor.Document; +import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.EditorFactory; import com.intellij.openapi.editor.ex.EditorEx; import com.intellij.openapi.editor.impl.softwrap.SoftWrapAppliancePlaces; @@ -153,4 +154,7 @@ public class DiffUtil { } } + public static boolean isDiffEditor(@NotNull Editor editor) { + return editor.getUserData(DiffManagerImpl.EDITOR_IS_DIFF_KEY) != null; + } } diff --git a/platform/platform-impl/src/com/intellij/openapi/diff/impl/external/DiffManagerImpl.java b/platform/platform-impl/src/com/intellij/openapi/diff/impl/external/DiffManagerImpl.java index 1c7f9bd718a4..9be71af4b6b8 100644 --- a/platform/platform-impl/src/com/intellij/openapi/diff/impl/external/DiffManagerImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/diff/impl/external/DiffManagerImpl.java @@ -23,6 +23,7 @@ import com.intellij.openapi.diff.DiffRequest; import com.intellij.openapi.diff.DiffTool; import com.intellij.openapi.diff.impl.ComparisonPolicy; import com.intellij.openapi.diff.impl.DiffPanelImpl; +import com.intellij.openapi.diff.impl.DiffUtil; import com.intellij.openapi.diff.impl.mergeTool.MergeTool; import com.intellij.openapi.diff.impl.processing.HighlightMode; import com.intellij.openapi.editor.Editor; @@ -75,7 +76,7 @@ public class DiffManagerImpl extends DiffManager implements JDOMExternalizable { public static final Key EDITOR_IS_DIFF_KEY = new Key("EDITOR_IS_DIFF_KEY"); private static final MarkupEditorFilter DIFF_EDITOR_FILTER = new MarkupEditorFilter() { public boolean avaliableIn(Editor editor) { - return editor.getUserData(EDITOR_IS_DIFF_KEY) != null; + return DiffUtil.isDiffEditor(editor); } }; private ComparisonPolicy myComparisonPolicy; diff --git a/platform/platform-impl/src/com/intellij/openapi/diff/impl/incrementalMerge/ChangeList.java b/platform/platform-impl/src/com/intellij/openapi/diff/impl/incrementalMerge/ChangeList.java index 44a399f90d7f..a0d2b9638f47 100644 --- a/platform/platform-impl/src/com/intellij/openapi/diff/impl/incrementalMerge/ChangeList.java +++ b/platform/platform-impl/src/com/intellij/openapi/diff/impl/incrementalMerge/ChangeList.java @@ -200,7 +200,15 @@ public class ChangeList { return myChanges.size(); } + @NotNull public LineBlocks getLineBlocks() { + ArrayList changes = new ArrayList(myChanges); + //changes.addAll(myAppliedChanges); + return LineBlocks.fromChanges(changes); + } + + @NotNull + public LineBlocks getAllLineBlocks() { ArrayList changes = new ArrayList(myChanges); changes.addAll(myAppliedChanges); return LineBlocks.fromChanges(changes); diff --git a/platform/platform-impl/src/com/intellij/openapi/diff/impl/incrementalMerge/ui/MergePanel2.java b/platform/platform-impl/src/com/intellij/openapi/diff/impl/incrementalMerge/ui/MergePanel2.java index 8ca4af03969b..34e8ad3a74cf 100644 --- a/platform/platform-impl/src/com/intellij/openapi/diff/impl/incrementalMerge/ui/MergePanel2.java +++ b/platform/platform-impl/src/com/intellij/openapi/diff/impl/incrementalMerge/ui/MergePanel2.java @@ -238,9 +238,10 @@ public class MergePanel2 implements DiffViewer { myMergeList.setMarkups(left, base, right); EditingSides[] sides = {getFirstEditingSide(), getSecondEditingSide()}; + EditingSides[] sidesWithApplied = {getFirstEditingSide(true), getSecondEditingSide(true)}; myScrollSupport.install(sides); for (int i = 0; i < myDividers.length; i++) { - myDividers[i].listenEditors(sides[i]); + myDividers[i].listenEditors(sidesWithApplied[i]); } if (myScrollToFirstDiff) { myPanel.requestScrollEditors(); @@ -256,12 +257,22 @@ public class MergePanel2 implements DiffViewer { @NotNull EditingSides getFirstEditingSide() { - return new MyEditingSides(FragmentSide.SIDE1); + return getFirstEditingSide(false); + } + + @NotNull + EditingSides getFirstEditingSide(boolean appliedLineBlocks) { + return new MyEditingSides(FragmentSide.SIDE1, appliedLineBlocks); } @NotNull EditingSides getSecondEditingSide() { - return new MyEditingSides(FragmentSide.SIDE2); + return getSecondEditingSide(false); + } + + @NotNull + EditingSides getSecondEditingSide(boolean appliedLineBlocks) { + return new MyEditingSides(FragmentSide.SIDE2, appliedLineBlocks); } public void setAutoScrollEnabled(boolean enabled) { @@ -438,9 +449,11 @@ public class MergePanel2 implements DiffViewer { private class MyEditingSides implements EditingSides { private final FragmentSide mySide; + private final boolean myAppliedLineBlocks; - private MyEditingSides(FragmentSide side) { + private MyEditingSides(FragmentSide side, boolean appliedLineBlocks) { mySide = side; + myAppliedLineBlocks = appliedLineBlocks; } @Nullable @@ -449,18 +462,20 @@ public class MergePanel2 implements DiffViewer { } public LineBlocks getLineBlocks() { - return myMergeList.getChanges(mySide).getLineBlocks(); + if (myAppliedLineBlocks) { + return myMergeList.getChanges(mySide).getAllLineBlocks(); + } else { + return myMergeList.getChanges(mySide).getLineBlocks(); + } } } private class MyScrollingPanel implements DiffPanelOuterComponent.ScrollingPanel { public void scrollEditors() { Editor centerEditor = getEditor(1); - if (!centerEditor.isViewer() && centerEditor.getDocument().isWritable()) { - JComponent centerComponent = centerEditor.getContentComponent(); - if (centerComponent.isShowing()) { - centerComponent.requestFocus(); - } + JComponent centerComponent = centerEditor.getContentComponent(); + if (centerComponent.isShowing()) { + centerComponent.requestFocus(); } int[] toLeft = getPrimaryBeginnings(myDividers[0].getPaint()); int[] toRight = getPrimaryBeginnings(myDividers[1].getPaint()); diff --git a/platform/platform-impl/src/com/intellij/openapi/options/newEditor/SettingsTreeView.java b/platform/platform-impl/src/com/intellij/openapi/options/newEditor/SettingsTreeView.java index 381bb7159796..0f3921c9e1d2 100644 --- a/platform/platform-impl/src/com/intellij/openapi/options/newEditor/SettingsTreeView.java +++ b/platform/platform-impl/src/com/intellij/openapi/options/newEditor/SettingsTreeView.java @@ -136,7 +136,6 @@ final class SettingsTreeView extends JComponent implements Disposable, OptionsEd myBuilder = new MyBuilder(new SimpleTreeStructure.Impl(myRoot)); myBuilder.setFilteringMerge(300, null); - setMinimumSize(new Dimension(200, 100)); Disposer.register(this, myBuilder); } @@ -490,19 +489,6 @@ final class SettingsTreeView extends JComponent implements Disposable, OptionsEd if (myRoot == node.getParent()) { myTextLabel.setFont(myTextLabel.getFont().deriveFont(Font.BOLD)); } - if (tree.isVisible()) { - int indent = node.myLevel * (UIUtil.getTreeLeftChildIndent() + UIUtil.getTreeRightChildIndent()); - Insets treeInsets = tree.getInsets(); - if (treeInsets != null) { - indent += treeInsets.left + treeInsets.right; - } - int visibleWidth = tree.getVisibleRect().width; - if (visibleWidth > indent) { - Dimension size = getPreferredSize(); - size.width = visibleWidth - indent; - //setPreferredSize(size); - } - } } // update font color for modified configurables myTextLabel.setForeground(selected ? UIUtil.getTreeSelectionForeground() : NORMAL_NODE); @@ -564,6 +550,30 @@ final class SettingsTreeView extends JComponent implements Disposable, OptionsEd } } myNodeIcon.setIcon(nodeIcon); + // calculate minimum size + if (node != null && tree.isVisible()) { + int width = getPreferredSize().width; + width += node.myLevel * UIUtil.getTreeLeftChildIndent(); + width += node.myLevel * UIUtil.getTreeRightChildIndent(); + Insets insets = tree.getInsets(); + if (insets != null) { + width += insets.left + insets.right; + } + JScrollBar bar = myScroller.getVerticalScrollBar(); + if (bar != null && bar.isVisible()) { + width += bar.getWidth(); + } + width = Math.min(width, 300); // maximal width for minimum size + JComponent view = SettingsTreeView.this; + Dimension size = view.getMinimumSize(); + if (size.width < width) { + size.width = width; + System.out.println("width = " + width); + view.setMinimumSize(size); + view.revalidate(); + view.repaint(); + } + } return this; } } diff --git a/platform/structuralsearch/source/com/intellij/structuralsearch/impl/matcher/MatcherImpl.java b/platform/structuralsearch/source/com/intellij/structuralsearch/impl/matcher/MatcherImpl.java index b86ae74a5096..100abd8650c8 100644 --- a/platform/structuralsearch/source/com/intellij/structuralsearch/impl/matcher/MatcherImpl.java +++ b/platform/structuralsearch/source/com/intellij/structuralsearch/impl/matcher/MatcherImpl.java @@ -288,11 +288,10 @@ public class MatcherImpl { private boolean findMatches(MatchOptions options, CompiledPattern compiledPattern) { LanguageFileType languageFileType = (LanguageFileType)options.getFileType(); - final StructuralSearchProfile profile = StructuralSearchUtil.getProfileByLanguage(languageFileType.getLanguage()); + final Language patternLanguage = languageFileType.getLanguage(); + final StructuralSearchProfile profile = StructuralSearchUtil.getProfileByLanguage(patternLanguage); assert profile != null; - PsiElement node = compiledPattern.getNodes().current(); - final Language ourPatternLanguage = node != null ? profile.getLanguage(node) : ((LanguageFileType)options.getFileType()).getLanguage(); - final Language ourPatternLanguage2 = ourPatternLanguage == StdLanguages.XML ? StdLanguages.XHTML:null; + final Language patternLanguage2 = patternLanguage == StdLanguages.XML ? StdLanguages.XHTML:null; SearchScope searchScope = compiledPattern.getScope(); boolean ourOptimizedScope = searchScope != null; if (!ourOptimizedScope) searchScope = options.getScope(); @@ -304,7 +303,7 @@ public class MatcherImpl { public boolean processFile(final VirtualFile fileOrDir) { if (!fileOrDir.isDirectory() && scope.contains(fileOrDir) && fileOrDir.getFileType() != FileTypes.UNKNOWN) { ++totalFilesToScan; - scheduler.addOneTask(new MatchOneVirtualFile(fileOrDir, profile, ourPatternLanguage, ourPatternLanguage2)); + scheduler.addOneTask(new MatchOneVirtualFile(fileOrDir, profile, patternLanguage, patternLanguage2)); } return true; } @@ -330,7 +329,7 @@ public class MatcherImpl { PsiFile file = psiElement instanceof PsiFile ? (PsiFile)psiElement : psiElement.getContainingFile(); - if (profile.isMyFile(file, language, ourPatternLanguage, ourPatternLanguage2)) { + if (profile.isMyFile(file, language, patternLanguage, patternLanguage2)) { scheduler.addOneTask(new MatchOnePsiFile(psiElement)); } if (ourOptimizedScope) elementsToScan[i] = null; // to prevent long PsiElement reference diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/actions/VcsActionPromoter.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/actions/VcsActionPromoter.java index 2c38c25737f8..0df802c8566b 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/actions/VcsActionPromoter.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/actions/VcsActionPromoter.java @@ -18,11 +18,10 @@ package com.intellij.openapi.vcs.actions; import com.intellij.openapi.actionSystem.ActionPromoter; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.DataContext; +import com.intellij.openapi.diff.actions.DiffWalkerAction; import com.intellij.openapi.vcs.ex.RollbackLineStatusAction; -import com.intellij.openapi.vcs.ui.Refreshable; -import java.util.Arrays; -import java.util.Collections; +import java.util.ArrayList; import java.util.List; /** @@ -31,18 +30,20 @@ import java.util.List; public class VcsActionPromoter implements ActionPromoter { @Override public List promote(List actions, DataContext context) { - if (Refreshable.PANEL_KEY.getData(context) != null) { - for (AnAction action : actions) { - if (action instanceof ShowMessageHistoryAction) { - return Arrays.asList(action); - } + List list = new ArrayList(0); + + for (AnAction action : actions) { + if (action instanceof RollbackLineStatusAction) { + list.add(action); + } + if (action instanceof ShowMessageHistoryAction) { + list.add(action); + } + if (action instanceof DiffWalkerAction) { + list.add(action); } } - for (AnAction action : actions) { - if (action instanceof RollbackLineStatusAction) return Arrays.asList(action); - } - - return Collections.emptyList(); + return list; } } diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/ex/RollbackLineStatusAction.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/ex/RollbackLineStatusAction.java index 24ac8fd1c2a3..830e86f8c0c6 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/ex/RollbackLineStatusAction.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/ex/RollbackLineStatusAction.java @@ -16,6 +16,7 @@ import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.CommonDataKeys; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.command.CommandProcessor; +import com.intellij.openapi.diff.impl.DiffUtil; import com.intellij.openapi.editor.Caret; import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.Editor; @@ -39,6 +40,10 @@ public class RollbackLineStatusAction extends DumbAwareAction { e.getPresentation().setEnabledAndVisible(false); return; } + if (DiffUtil.isDiffEditor(editor)) { + e.getPresentation().setEnabledAndVisible(false); + return; + } LineStatusTracker tracker = LineStatusTrackerManager.getInstance(project).getLineStatusTracker(editor.getDocument()); if (tracker == null) { e.getPresentation().setEnabledAndVisible(false); diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/CodeSmellDetectorImpl.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/CodeSmellDetectorImpl.java index 48d72083b7d6..3a52951bcc20 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/CodeSmellDetectorImpl.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/CodeSmellDetectorImpl.java @@ -30,6 +30,7 @@ import com.intellij.openapi.progress.ProcessCanceledException; import com.intellij.openapi.progress.ProgressIndicator; import com.intellij.openapi.progress.ProgressManager; import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.Computable; import com.intellij.openapi.util.TextRange; import com.intellij.openapi.vcs.AbstractVcsHelper; import com.intellij.openapi.vcs.CodeSmellDetector; @@ -120,14 +121,19 @@ public class CodeSmellDetectorImpl extends CodeSmellDetector { if (progress != null && progress.isCanceled()) throw new ProcessCanceledException(); - VirtualFile file = filesToCheck.get(i); + final VirtualFile file = filesToCheck.get(i); if (progress != null) { progress.setText(VcsBundle.message("searching.for.code.smells.processing.file.progress.text", file.getPresentableUrl())); progress.setFraction((double)i / (double)filesToCheck.size()); } - final PsiFile psiFile = manager.findFile(file); + final PsiFile psiFile = ApplicationManager.getApplication().runReadAction(new Computable() { + @Override + public PsiFile compute() { + return manager.findFile(file); + } + }); if (psiFile != null) { final Document document = fileManager.getDocument(file); if (document != null) { @@ -156,11 +162,16 @@ public class CodeSmellDetectorImpl extends CodeSmellDetector { } @NotNull - private List findCodeSmells(@NotNull PsiFile psiFile, final ProgressIndicator progress, @NotNull Document document) { + private List findCodeSmells(@NotNull final PsiFile psiFile, final ProgressIndicator progress, @NotNull final Document document) { final List result = new ArrayList(); - DaemonCodeAnalyzerImpl codeAnalyzer = (DaemonCodeAnalyzerImpl)DaemonCodeAnalyzer.getInstance(myProject); - List infos = codeAnalyzer.runMainPasses(psiFile, document, progress); + final DaemonCodeAnalyzerImpl codeAnalyzer = (DaemonCodeAnalyzerImpl)DaemonCodeAnalyzer.getInstance(myProject); + List infos = ApplicationManager.getApplication().runReadAction(new Computable>() { + @Override + public List compute() { + return codeAnalyzer.runMainPasses(psiFile, document, progress); + } + }); collectErrorsAndWarnings(infos, result, document); return result; diff --git a/platform/vcs-impl/src/com/intellij/vcsUtil/VcsFileUtil.java b/platform/vcs-impl/src/com/intellij/vcsUtil/VcsFileUtil.java index ffd309f712ea..e44eb158e55e 100644 --- a/platform/vcs-impl/src/com/intellij/vcsUtil/VcsFileUtil.java +++ b/platform/vcs-impl/src/com/intellij/vcsUtil/VcsFileUtil.java @@ -100,10 +100,6 @@ public class VcsFileUtil { return getRelativeFilePath(file.getPath(), baseDir); } - public static String getRelativeFilePath(FilePath file, @NotNull final VirtualFile baseDir) { - return getRelativeFilePath(file.getPath(), baseDir); - } - public static String getRelativeFilePath(String file, @NotNull final VirtualFile baseDir) { if (SystemInfo.isWindows) { file = file.replace('\\', '/'); @@ -259,27 +255,6 @@ public class VcsFileUtil { } } - /** - * Refresh files - * - * @param project a project - * @param affectedFiles affected files and directories - */ - public static void markFilesDirty(@NotNull final Project project, @NotNull final Collection affectedFiles) { - final VcsDirtyScopeManager dirty = VcsDirtyScopeManager.getInstance(project); - for (VirtualFile file : affectedFiles) { - if (!file.isValid()) { - continue; - } - if (file.isDirectory()) { - dirty.dirDirtyRecursively(file); - } - else { - dirty.fileDirty(file); - } - } - } - /** * Mark files dirty * diff --git a/platform/vcs-log/impl/src/com/intellij/vcs/log/data/VisiblePackBuilder.java b/platform/vcs-log/impl/src/com/intellij/vcs/log/data/VisiblePackBuilder.java index 54be3ea5ae33..9acd1f9acff9 100644 --- a/platform/vcs-log/impl/src/com/intellij/vcs/log/data/VisiblePackBuilder.java +++ b/platform/vcs-log/impl/src/com/intellij/vcs/log/data/VisiblePackBuilder.java @@ -64,10 +64,9 @@ class VisiblePackBuilder { } List detailsFilters = filters.getDetailsFilters(); - Condition filter; - boolean canRequestMore; + List matchingCommits = null; + boolean canRequestMore = false; if (!detailsFilters.isEmpty()) { - List matchingCommits = null; if (commitCount == CommitCountStage.INITIAL) { matchingCommits = filterInMemory(dataPack.getPermanentGraph(), detailsFilters); if (matchingCommits.size() < commitCount.getCount()) { @@ -87,16 +86,17 @@ class VisiblePackBuilder { } } - filter = getFilterFromCommits(matchingCommits); canRequestMore = matchingCommits.size() >= commitCount.getCount(); // from VCS: only "==", but from memory can be ">" } - else { - filter = null; - canRequestMore = false; - } - Set heads = getMatchingHeads(dataPack.getRefs(), filters); - VisibleGraph visibleGraph = dataPack.getPermanentGraph().createVisibleGraph(sortType, heads, filter); + VisibleGraph visibleGraph; + if (matchingCommits != null && matchingCommits.isEmpty()) { + visibleGraph = EmptyVisibleGraph.getInstance(); + } + else { + visibleGraph = dataPack.getPermanentGraph().createVisibleGraph(sortType, getMatchingHeads(dataPack.getRefs(), filters), + getFilterFromCommits(matchingCommits)); + } return Pair.create(new VisiblePack(dataPack, visibleGraph, canRequestMore), commitCount); } diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/tree/nodes/XValueNodeImpl.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/tree/nodes/XValueNodeImpl.java index 9749fd38d770..7020c9a5cf84 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/tree/nodes/XValueNodeImpl.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/tree/nodes/XValueNodeImpl.java @@ -257,6 +257,7 @@ public class XValueNodeImpl extends XValueContainerNode implements XValu else { new HeadlessValueEvaluationCallback(XValueNodeImpl.this).startFetchingValue(myFullValueEvaluator); } + event.consume(); } }; } diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsstatuses/CvsChangeProvider.java b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsstatuses/CvsChangeProvider.java index a652289a59c7..ecc21c9aa3cd 100644 --- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsstatuses/CvsChangeProvider.java +++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsstatuses/CvsChangeProvider.java @@ -159,19 +159,15 @@ public class CvsChangeProvider implements ChangeProvider { } if (recursively) { - final VirtualFile[] children = CvsVfsUtil.getChildrenOf(dir); - if (children != null) { - for (VirtualFile file : children) { - progress.checkCanceled(); - if (file.isDirectory()) { - final boolean isIgnored = myVcsManager.isIgnored(file); - if (!isIgnored) { - processEntriesIn(file, scope, builder, true, progress); - } - else { - if (LOG.isDebugEnabled()) { - LOG.debug("Skipping ignored path " + file.getPath()); - } + for (VirtualFile file : CvsVfsUtil.getChildrenOf(dir)) { + progress.checkCanceled(); + if (file.isDirectory()) { + if (!myVcsManager.isIgnored(file)) { + processEntriesIn(file, scope, builder, true, progress); + } + else { + if (LOG.isDebugEnabled()) { + LOG.debug("Skipping ignored path " + file.getPath()); } } } @@ -188,7 +184,6 @@ public class CvsChangeProvider implements ChangeProvider { return false; } - private void processFile(final FilePath filePath, final ChangelistBuilder builder, final ProgressIndicator progress) throws VcsException { final VirtualFile dir = filePath.getVirtualFileParent(); if (dir == null) return; @@ -224,16 +219,10 @@ public class CvsChangeProvider implements ChangeProvider { private void showBranchImOn(final ChangelistBuilder builder, final VcsDirtyScope scope) { final List dirs = ObjectsConvertor.fp2vf(scope.getRecursivelyDirtyDirectories()); - final Collection roots = new ArrayList(scope.getAffectedContentRoots()); - - for (Iterator iterator = roots.iterator(); iterator.hasNext();) { - final VirtualFile root = iterator.next(); - if (! dirs.contains(root)) iterator.remove(); - } - - if (roots.isEmpty()) return; - for (VirtualFile root : roots) { - checkTopLevelForBeingSwitched(root, builder); + for (VirtualFile root : myVcsManager.getRootsUnderVcs(myVcs)) { + if (dirs.contains(root)) { + checkTopLevelForBeingSwitched(root, builder); + } } } @@ -455,17 +444,12 @@ public class CvsChangeProvider implements ChangeProvider { final CvsInfo cvsInfo = CvsEntriesManager.getInstance().getCvsInfoFor(directory); final DirectoryContent result = new DirectoryContent(cvsInfo); - VirtualFile[] children = CvsVfsUtil.getChildrenOf(directory); - if (children == null) children = VirtualFile.EMPTY_ARRAY; - - final Collection entries = cvsInfo.getEntries(); - final HashMap nameToFileMap = new HashMap(); - for (VirtualFile child : children) { + for (VirtualFile child : CvsVfsUtil.getChildrenOf(directory)) { nameToFileMap.put(child.getName(), child); } - for (final Entry entry : entries) { + for (final Entry entry : cvsInfo.getEntries()) { progress.checkCanceled(); final String fileName = entry.getFileName(); if (entry.isDirectory()) { diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/javacvsImpl/io/LocalFileReaderBasedOnVFS.java b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/javacvsImpl/io/LocalFileReaderBasedOnVFS.java index e4f8174dceae..2a1085358fe2 100644 --- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/javacvsImpl/io/LocalFileReaderBasedOnVFS.java +++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/javacvsImpl/io/LocalFileReaderBasedOnVFS.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -78,10 +78,8 @@ public class LocalFileReaderBasedOnVFS implements ILocalFileReader { ICvsFileSystem cvsFileSystem) { VirtualFile virtualDirectory = getVirtualFile(directoryObject, cvsFileSystem); if (virtualDirectory == null) return; - VirtualFile[] children = CvsVfsUtil.getChildrenOf(virtualDirectory); - if (children == null) return; - for (final VirtualFile fileOrDirectory : children) { + for (final VirtualFile fileOrDirectory : CvsVfsUtil.getChildrenOf(virtualDirectory)) { if (CvsUtil.CVS.equals(fileOrDirectory.getName())) continue; if (!myProjectContentInfoProvider.fileIsUnderProject(fileOrDirectory)) continue; final String name = fileOrDirectory.getName(); @@ -92,7 +90,7 @@ public class LocalFileReaderBasedOnVFS implements ILocalFileReader { } else { if (fileNames != null) { - LOG.assertTrue(name.length() > 0); + LOG.assertTrue(!name.isEmpty()); fileNames.add(name); } } diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/util/CvsVfsUtil.java b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/util/CvsVfsUtil.java index 49f85f527893..b521e17e8e62 100644 --- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/util/CvsVfsUtil.java +++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/util/CvsVfsUtil.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -69,8 +69,13 @@ public class CvsVfsUtil { return LocalFileSystem.getInstance().refreshAndFindFileByIoFile(file); } + @NotNull public static VirtualFile[] getChildrenOf(final VirtualFile directory) { - return directory.isValid() ? directory.getChildren() : null; + if (!directory.isValid()) { + return VirtualFile.EMPTY_ARRAY; + } + final VirtualFile[] children = directory.getChildren(); + return (children == null) ? VirtualFile.EMPTY_ARRAY : children; } public static long getTimeStamp(final VirtualFile file) { diff --git a/plugins/git4idea/src/git4idea/log/GitRefManager.java b/plugins/git4idea/src/git4idea/log/GitRefManager.java index 6469a1fef1bd..70f80fce0a09 100644 --- a/plugins/git4idea/src/git4idea/log/GitRefManager.java +++ b/plugins/git4idea/src/git4idea/log/GitRefManager.java @@ -156,7 +156,7 @@ public class GitRefManager implements VcsLogRefManager { Set locals = getLocalBranches(repository); Set tracked = getTrackedRemoteBranches(repository); - Map nonTracked = getNonTrackedRemoteBranches(repository); + Map allRemote = getAllRemoteBranches(repository); for (VcsRef ref : refsInRoot) { if (ref.getType() == HEAD) { @@ -168,11 +168,11 @@ public class GitRefManager implements VcsLogRefManager { if (locals.contains(refName)) { localBranches.add(ref); } - else if (tracked.contains(refName)) { - trackedBranches.add(ref); - } - else if (nonTracked.containsKey(refName)) { - remoteRefGroups.putValue(nonTracked.get(refName), ref); + else if (allRemote.containsKey(refName)) { + remoteRefGroups.putValue(allRemote.get(refName), ref); + if (tracked.contains(refName)) { + trackedBranches.add(ref); + } } else { LOG.debug("Didn't find ref neither in local nor in remote branches: " + ref); @@ -215,16 +215,13 @@ public class GitRefManager implements VcsLogRefManager { } @NotNull - private static Map getNonTrackedRemoteBranches(@NotNull GitRepository repository) { + private static Map getAllRemoteBranches(@NotNull GitRepository repository) { Set all = new HashSet(repository.getBranches().getRemoteBranches()); - Set tracked = getTrackedRemoteBranchesFromConfig(repository); - Map nonTracked = ContainerUtil.newHashMap(); + Map allRemote = ContainerUtil.newHashMap(); for (GitRemoteBranch remoteBranch : all) { - if (!tracked.contains(remoteBranch.getName())) { - nonTracked.put(remoteBranch.getName(), remoteBranch.getRemote()); - } + allRemote.put(remoteBranch.getName(), remoteBranch.getRemote()); } - return nonTracked; + return allRemote; } private static Set getTrackedRemoteBranchesFromConfig(GitRepository repository) { diff --git a/plugins/java-decompiler/engine/src/org/jetbrains/java/decompiler/main/ClassWriter.java b/plugins/java-decompiler/engine/src/org/jetbrains/java/decompiler/main/ClassWriter.java index 2b61dc2e1fc4..18d3fe7953ac 100644 --- a/plugins/java-decompiler/engine/src/org/jetbrains/java/decompiler/main/ClassWriter.java +++ b/plugins/java-decompiler/engine/src/org/jetbrains/java/decompiler/main/ClassWriter.java @@ -805,7 +805,7 @@ public class ClassWriter { } //TODO: for now only start line set - buffer.setCurrentLine(startLine); + buffer.setCurrentLine(startLine-1); buffer.append('{').appendLineSeparator(); RootStatement root = wrapper.getMethodWrapper(mt.getName(), mt.getDescriptor()).root; diff --git a/plugins/java-decompiler/engine/src/org/jetbrains/java/decompiler/main/TextBuffer.java b/plugins/java-decompiler/engine/src/org/jetbrains/java/decompiler/main/TextBuffer.java index 7dd3d2ff0fde..a803a1edac41 100644 --- a/plugins/java-decompiler/engine/src/org/jetbrains/java/decompiler/main/TextBuffer.java +++ b/plugins/java-decompiler/engine/src/org/jetbrains/java/decompiler/main/TextBuffer.java @@ -32,6 +32,7 @@ public class TextBuffer { private final String myIndent = (String)DecompilerContext.getProperty(IFernflowerPreferences.INDENT_STRING); private final StringBuilder myStringBuilder; private Map myLineToOffsetMapping = null; + private boolean myTrackLines = true; public TextBuffer() { myStringBuilder = new StringBuilder(); @@ -41,8 +42,12 @@ public class TextBuffer { myStringBuilder = new StringBuilder(size); } + public void setTrackLines(boolean trackLines) { + myTrackLines = false; + } + public void setCurrentLine(int line) { - if (line >= 0) { + if (myTrackLines && line >= 0) { checkMapCreated(); myLineToOffsetMapping.put(line, myStringBuilder.length()+1); } @@ -70,16 +75,6 @@ public class TextBuffer { return this; } - public TextBuffer addBanner(String banner) { - myStringBuilder.insert(0, banner); - if (myLineToOffsetMapping != null) { - for (Integer line : myLineToOffsetMapping.keySet()) { - myLineToOffsetMapping.put(line, myLineToOffsetMapping.get(line) + banner.length()); - } - } - return this; - } - @Override public String toString() { String original = myStringBuilder.toString(); @@ -101,9 +96,10 @@ public class TextBuffer { String line = srcLines[currentLine]; int lineEnd = currentLineStartOffset + line.length() + myLineSeparator.length(); if (markOffset >= currentLineStartOffset && markOffset <= lineEnd) { - int requiredLinesNumber = markLine - dumpedLines; - dumpedLines = markLine; - appendLines(res, srcLines, previousMarkLine, currentLine, requiredLinesNumber); + int requiredLine = markLine - 1; + int linesToAdd = requiredLine - dumpedLines; + dumpedLines = requiredLine; + appendLines(res, srcLines, previousMarkLine, currentLine, linesToAdd); previousMarkLine = currentLine; break; } @@ -121,7 +117,7 @@ public class TextBuffer { private void appendLines(StringBuilder res, String[] srcLines, int from, int to, int requiredLineNumber) { if (to - from > requiredLineNumber) { - int separatorsRequired = to - from - requiredLineNumber - 1; + int separatorsRequired = requiredLineNumber - 1; for (int i = from; i < to; i++) { res.append(srcLines[i]); if (separatorsRequired-- > 0) { @@ -163,17 +159,26 @@ public class TextBuffer { return this; } + private void shiftMapping(int startOffset, int shiftOffset) { + if (myLineToOffsetMapping != null) { + for (Map.Entry entry : myLineToOffsetMapping.entrySet()) { + if (entry.getValue() >= startOffset) { + myLineToOffsetMapping.put(entry.getKey(), entry.getValue() + shiftOffset); + } + } + } + } + private void checkMapCreated() { if (myLineToOffsetMapping == null) { myLineToOffsetMapping = new HashMap(); } } - public void insert(int offset, String s) { - if (myLineToOffsetMapping != null) { - throw new IllegalStateException("insert not yet supported with Line mapping"); - } + public TextBuffer insert(int offset, String s) { myStringBuilder.insert(offset, s); + shiftMapping(offset, s.length()); + return this; } public int count(String substring, int from) { diff --git a/plugins/java-decompiler/engine/src/org/jetbrains/java/decompiler/modules/decompiler/exps/NewExprent.java b/plugins/java-decompiler/engine/src/org/jetbrains/java/decompiler/modules/decompiler/exps/NewExprent.java index bb55e45c6306..7537d2b2a704 100644 --- a/plugins/java-decompiler/engine/src/org/jetbrains/java/decompiler/modules/decompiler/exps/NewExprent.java +++ b/plugins/java-decompiler/engine/src/org/jetbrains/java/decompiler/modules/decompiler/exps/NewExprent.java @@ -268,7 +268,10 @@ public class NewExprent extends Exprent { new ClassWriter().classLambdaToJava(child, buf, methodObject, indent); } else { + // do not track lines in sub classes for now + buf.setTrackLines(false); new ClassWriter().classToJava(child, buf, indent); + buf.setTrackLines(true); } } else if (directArrayInit) { diff --git a/python/ipnb/ipnb.iml b/python/ipnb/ipnb.iml index 278d2d296c48..0d6f9d8986a8 100644 --- a/python/ipnb/ipnb.iml +++ b/python/ipnb/ipnb.iml @@ -52,6 +52,15 @@ + + + + + + + + + diff --git a/python/ipnb/lib/commons-io-1.4.jar b/python/ipnb/lib/commons-io-1.4.jar new file mode 100644 index 000000000000..133dc6cb35f5 Binary files /dev/null and b/python/ipnb/lib/commons-io-1.4.jar differ diff --git a/python/ipnb/src/org/jetbrains/plugins/ipnb/editor/IpnbFileEditor.java b/python/ipnb/src/org/jetbrains/plugins/ipnb/editor/IpnbFileEditor.java index 946d6c665a70..0e29fb48fed5 100644 --- a/python/ipnb/src/org/jetbrains/plugins/ipnb/editor/IpnbFileEditor.java +++ b/python/ipnb/src/org/jetbrains/plugins/ipnb/editor/IpnbFileEditor.java @@ -214,6 +214,7 @@ public class IpnbFileEditor extends UserDataHolderBase implements FileEditor, Te } private void updateCellType(@NotNull final String selectedItem, @NotNull final IpnbEditablePanel selectedCell) { + selectedCell.updateCellSource(); if (selectedCell instanceof IpnbHeadingPanel) { final IpnbHeadingCell cell = ((IpnbHeadingPanel)selectedCell).getCell(); if (selectedItem.startsWith(headingCellType)) { diff --git a/python/ipnb/src/org/jetbrains/plugins/ipnb/editor/actions/IpnbCutCellAction.java b/python/ipnb/src/org/jetbrains/plugins/ipnb/editor/actions/IpnbCutCellAction.java index c79ce99a969b..145cd8b2a8cb 100644 --- a/python/ipnb/src/org/jetbrains/plugins/ipnb/editor/actions/IpnbCutCellAction.java +++ b/python/ipnb/src/org/jetbrains/plugins/ipnb/editor/actions/IpnbCutCellAction.java @@ -16,7 +16,7 @@ public class IpnbCutCellAction extends AnAction { } @Override - public void actionPerformed(AnActionEvent event) { + public void actionPerformed(@NotNull AnActionEvent event) { final DataContext context = event.getDataContext(); final FileEditor editor = PlatformDataKeys.FILE_EDITOR.getData(context); if (editor instanceof IpnbFileEditor) { diff --git a/python/ipnb/src/org/jetbrains/plugins/ipnb/editor/panels/IpnbFilePanel.java b/python/ipnb/src/org/jetbrains/plugins/ipnb/editor/panels/IpnbFilePanel.java index b826b9ac9bba..06cbe95a9d05 100644 --- a/python/ipnb/src/org/jetbrains/plugins/ipnb/editor/panels/IpnbFilePanel.java +++ b/python/ipnb/src/org/jetbrains/plugins/ipnb/editor/panels/IpnbFilePanel.java @@ -59,6 +59,10 @@ public class IpnbFilePanel extends JPanel implements Scrollable, DataProvider { public void run() { try { myIpnbFile = IpnbParser.parseIpnbFile(vFile); + if (myIpnbFile.getCells().isEmpty()) { + final IpnbCodeCell cell = new IpnbCodeCell("python", new String[]{""}, null, new ArrayList()); + myIpnbFile.addCell(cell, 0); + } layoutFile(); addMouseListener(new MouseAdapter() { @Override @@ -148,11 +152,6 @@ public class IpnbFilePanel extends JPanel implements Scrollable, DataProvider { } private void addCell(IpnbEditableCell cell, IpnbEditablePanel panel) { - final IpnbEditablePanel selectedCell = getSelectedCell(); - final int index = myIpnbPanels.indexOf(selectedCell); - myIpnbFile.addCell(cell, index+1); - myIpnbPanels.add(index + 1, panel); - final GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.HORIZONTAL; c.gridx = 0; @@ -160,6 +159,17 @@ public class IpnbFilePanel extends JPanel implements Scrollable, DataProvider { c.gridwidth = 1; c.insets = new Insets(INSET_Y, INSET_X, 0, 0); + if (myIpnbPanels.isEmpty()) { + final int width = IpnbEditorUtil.PANEL_WIDTH + IpnbEditorUtil.PROMPT_SIZE.width; + final JLabel label = new JLabel(""); + add(label, c); + } + final IpnbEditablePanel selectedCell = getSelectedCell(); + final int index = myIpnbPanels.indexOf(selectedCell); + myIpnbFile.addCell(cell, index + 1); + myIpnbPanels.add(index + 1, panel); + + final JPanel promptPanel = new JPanel(); promptPanel.setPreferredSize(new Dimension(IpnbEditorUtil.PROMPT_SIZE.width, 1)); promptPanel.setBackground(getBackground()); @@ -191,6 +201,7 @@ public class IpnbFilePanel extends JPanel implements Scrollable, DataProvider { public void cutCell() { myBufferPanel = getSelectedCell(); + if (myBufferPanel == null) return; selectNextOrPrev(myBufferPanel); final int index = myIpnbPanels.indexOf(myBufferPanel); if (index < 0) return; @@ -198,6 +209,9 @@ public class IpnbFilePanel extends JPanel implements Scrollable, DataProvider { myIpnbFile.removeCell(index); remove(myBufferPanel); + if (myIpnbPanels.isEmpty()) { + createAndAddCell(); + } } public void copyCell() { @@ -240,6 +254,9 @@ public class IpnbFilePanel extends JPanel implements Scrollable, DataProvider { myIpnbPanels.remove(index); myIpnbPanels.add(index, panel); } + if (from instanceof IpnbCodePanel) { + panel.switchToEditing(); + } setSelectedCell(panel); remove(from); revalidate(); @@ -254,7 +271,7 @@ public class IpnbFilePanel extends JPanel implements Scrollable, DataProvider { myIpnbPanels.add(comp); } - private JPanel createEmptyPanel() { + private static JPanel createEmptyPanel() { JPanel panel = new JPanel(); panel.setBackground(IpnbEditorUtil.getBackground()); return panel; diff --git a/python/ipnb/src/org/jetbrains/plugins/ipnb/format/IpnbParser.java b/python/ipnb/src/org/jetbrains/plugins/ipnb/format/IpnbParser.java index f7d545bb19ae..b05ede796c2f 100644 --- a/python/ipnb/src/org/jetbrains/plugins/ipnb/format/IpnbParser.java +++ b/python/ipnb/src/org/jetbrains/plugins/ipnb/format/IpnbParser.java @@ -16,6 +16,7 @@ import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -88,8 +89,8 @@ public class IpnbParser { } public static class IpnbFileRaw { - Map metadata; - int nbformat; + Map metadata = new HashMap(); + int nbformat = 3; int nbformat_minor; IpnbWorksheet[] worksheets; } diff --git a/python/pluginResources/META-INF/plugin.xml b/python/pluginResources/META-INF/plugin.xml index 3d8550e82b34..35835075a551 100644 --- a/python/pluginResources/META-INF/plugin.xml +++ b/python/pluginResources/META-INF/plugin.xml @@ -15,7 +15,8 @@ The Python plug-in provides smart editing for Python scripts. The feature set of Issue tracker
]]> - 4.0.@@BUILD_NUMBER@@ + + 4.0 Beta 140.@@BUILD_NUMBER@@ com.intellij.modules.java diff --git a/python/psi-api/src/com/jetbrains/python/nameResolver/NameResolverTools.java b/python/psi-api/src/com/jetbrains/python/nameResolver/NameResolverTools.java index 7fad93339ad6..2817a60400d2 100644 --- a/python/psi-api/src/com/jetbrains/python/nameResolver/NameResolverTools.java +++ b/python/psi-api/src/com/jetbrains/python/nameResolver/NameResolverTools.java @@ -1,9 +1,13 @@ package com.jetbrains.python.nameResolver; import com.intellij.openapi.util.Condition; +import com.intellij.openapi.util.Pair; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiReference; +import com.intellij.psi.util.PsiCacheKey; +import com.intellij.psi.util.PsiModificationTracker; import com.intellij.psi.util.PsiTreeUtil; +import com.intellij.util.Function; import com.jetbrains.python.psi.*; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -16,6 +20,12 @@ import java.util.List; * @author Ilya.Kazakevich */ public final class NameResolverTools { + /** + * Cache: pair [qualified element name, class name (may be null)] by any psi element. + */ + private static final PsiCacheKey, PyElement> QUALIFIED_AND_CLASS_NAME = + PsiCacheKey.create(NameResolverTools.class.getName(), new QualifiedAndClassNameObtainer(), PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT); + private NameResolverTools() { } @@ -45,25 +55,9 @@ public final class NameResolverTools { * @return true if element's fqn is one of names, provided by provider */ public static boolean isName(@NotNull final PyElement element, @NotNull final FQNamesProvider... namesProviders) { - PyElement elementToCheck = element; - final PsiReference reference = element.getReference(); - if (reference != null) { - final PsiElement resolvedElement = reference.resolve(); - if (resolvedElement instanceof PyElement) { - elementToCheck = (PyElement)resolvedElement; - } - } - String qualifiedName = null; - if (elementToCheck instanceof PyQualifiedNameOwner) { - qualifiedName = ((PyQualifiedNameOwner)elementToCheck).getQualifiedName(); - } - String className = null; - if (elementToCheck instanceof PyFunction) { - final PyClass aClass = ((PyFunction)elementToCheck).getContainingClass(); - if (aClass != null) { - className = aClass.getQualifiedName(); - } - } + final Pair qualifiedAndClassName = QUALIFIED_AND_CLASS_NAME.getValue(element); + final String qualifiedName = qualifiedAndClassName.first; + final String className = qualifiedAndClassName.second; for (final FQNamesProvider provider : namesProviders) { final List names = Arrays.asList(provider.getNames()); @@ -79,7 +73,8 @@ public final class NameResolverTools { /** * Looks for parent call of certain function - * @param anchor element to look parent for + * + * @param anchor element to look parent for * @param functionName function to find * @return parent call or null if not found */ @@ -111,4 +106,34 @@ public final class NameResolverTools { return false; } } + + /** + * Returns pair [qualified name, class name (may be null)] by psi element + */ + private static class QualifiedAndClassNameObtainer implements Function> { + @Override + @NotNull + public Pair fun(@NotNull final PyElement element) { + PyElement elementToCheck = element; + final PsiReference reference = element.getReference(); + if (reference != null) { + final PsiElement resolvedElement = reference.resolve(); + if (resolvedElement instanceof PyElement) { + elementToCheck = (PyElement)resolvedElement; + } + } + String qualifiedName = null; + if (elementToCheck instanceof PyQualifiedNameOwner) { + qualifiedName = ((PyQualifiedNameOwner)elementToCheck).getQualifiedName(); + } + String className = null; + if (elementToCheck instanceof PyFunction) { + final PyClass aClass = ((PyFunction)elementToCheck).getContainingClass(); + if (aClass != null) { + className = aClass.getQualifiedName(); + } + } + return Pair.create(qualifiedName, className); + } + } } diff --git a/python/src/com/jetbrains/python/magicLiteral/PyMagicLiteralTools.java b/python/src/com/jetbrains/python/magicLiteral/PyMagicLiteralTools.java index d119ec0646dc..7cd2c052cf79 100644 --- a/python/src/com/jetbrains/python/magicLiteral/PyMagicLiteralTools.java +++ b/python/src/com/jetbrains/python/magicLiteral/PyMagicLiteralTools.java @@ -1,7 +1,11 @@ package com.jetbrains.python.magicLiteral; import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.util.Ref; import com.intellij.psi.PsiElement; +import com.intellij.psi.util.PsiCacheKey; +import com.intellij.psi.util.PsiModificationTracker; +import com.intellij.util.Function; import com.jetbrains.python.psi.StringLiteralExpression; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -12,6 +16,13 @@ import org.jetbrains.annotations.Nullable; * @author Ilya.Kazakevich */ public final class PyMagicLiteralTools { + /** + * Cache: ref (value may be null or extension point) by by string literal + */ + private final static PsiCacheKey, StringLiteralExpression> MAGIC_LITERAL_POINT = + PsiCacheKey + .create(PyMagicLiteralTools.class.getName(), new MagicLiteralChecker(), PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT); + private PyMagicLiteralTools() { } @@ -34,14 +45,24 @@ public final class PyMagicLiteralTools { */ @Nullable public static PyMagicLiteralExtensionPoint getPoint(@NotNull final StringLiteralExpression element) { - final PyMagicLiteralExtensionPoint[] magicLiteralExtPoints = - ApplicationManager.getApplication().getExtensions(PyMagicLiteralExtensionPoint.EP_NAME); + return MAGIC_LITERAL_POINT.getValue(element).get(); + } - for (final PyMagicLiteralExtensionPoint magicLiteralExtensionPoint : magicLiteralExtPoints) { - if (magicLiteralExtensionPoint.isMagicLiteral(element)) { - return magicLiteralExtensionPoint; + /** + * Obtains ref (value may be null or extension point) by by string literal + */ + private static class MagicLiteralChecker implements Function> { + @Override + public Ref fun(StringLiteralExpression element) { + final PyMagicLiteralExtensionPoint[] magicLiteralExtPoints = + ApplicationManager.getApplication().getExtensions(PyMagicLiteralExtensionPoint.EP_NAME); + + for (final PyMagicLiteralExtensionPoint magicLiteralExtensionPoint : magicLiteralExtPoints) { + if (magicLiteralExtensionPoint.isMagicLiteral(element)) { + return Ref.create(magicLiteralExtensionPoint); + } } + return new Ref(); } - return null; } } diff --git a/resources-en/src/messages/QuickFixBundle.properties b/resources-en/src/messages/QuickFixBundle.properties index 08cd32e9972b..dccca1348411 100644 --- a/resources-en/src/messages/QuickFixBundle.properties +++ b/resources-en/src/messages/QuickFixBundle.properties @@ -189,14 +189,6 @@ side.effect.message1=\ You can:
  • Remove variable usages along with all expressions involved
  • \ # {0} - variable name, {1} - variable type, {2} - expression with side effect, {3} - same expression transformed to hold the effect -side.effect.message2=\ - There are possible side effects found in expressions assigned to the variable ''{0}''
    \ - You can:
    • Remove variable usages along with all expressions involved, or
    • \ -
    • Transform expressions assigned to variable into the statements on their own.
      \ - That is,
      \ -
      {1} {0} = {2};

      becomes:
      \ -
      {3};
    • \ - change.parameter.class.family=Change Parameter Class diff --git a/xml/xml-psi-impl/src/com/intellij/psi/impl/source/html/HtmlDocumentImpl.java b/xml/xml-psi-impl/src/com/intellij/psi/impl/source/html/HtmlDocumentImpl.java index 864a854b69f5..55e7e801f012 100644 --- a/xml/xml-psi-impl/src/com/intellij/psi/impl/source/html/HtmlDocumentImpl.java +++ b/xml/xml-psi-impl/src/com/intellij/psi/impl/source/html/HtmlDocumentImpl.java @@ -16,6 +16,7 @@ package com.intellij.psi.impl.source.html; import com.intellij.psi.impl.source.xml.XmlDocumentImpl; +import com.intellij.psi.tree.IElementType; import com.intellij.psi.xml.XmlElementType; import com.intellij.psi.xml.XmlTag; @@ -27,6 +28,10 @@ public class HtmlDocumentImpl extends XmlDocumentImpl { super(XmlElementType.HTML_DOCUMENT); } + public HtmlDocumentImpl(IElementType type) { + super(type); + } + @Override public XmlTag getRootTag() { return (XmlTag)findElementByTokenType(XmlElementType.HTML_TAG);