From d180b7e50f26ee490223908adc63df89e949ab59 Mon Sep 17 00:00:00 2001 From: Konstantin Bulenkov Date: Mon, 5 Jan 2015 22:58:10 +0100 Subject: [PATCH 1/8] Darcula & HiDPI: Radio buttons --- .../laf/darcula/ui/DarculaRadioButtonUI.java | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/ui/DarculaRadioButtonUI.java b/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/ui/DarculaRadioButtonUI.java index e6674a643331..40dac24b4f8f 100644 --- a/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/ui/DarculaRadioButtonUI.java +++ b/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/ui/DarculaRadioButtonUI.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. @@ -19,14 +19,13 @@ import com.intellij.ide.ui.laf.darcula.DarculaUIUtil; import com.intellij.openapi.ui.GraphicsConfig; import com.intellij.ui.ColorUtil; import com.intellij.ui.Gray; -import com.intellij.util.ui.EmptyIcon; import com.intellij.util.ui.GraphicsUtil; +import com.intellij.util.ui.JBUI; import com.intellij.util.ui.UIUtil; import sun.swing.SwingUtilities2; import javax.swing.*; import javax.swing.plaf.ComponentUI; -import javax.swing.plaf.IconUIResource; import javax.swing.plaf.basic.BasicHTML; import javax.swing.plaf.metal.MetalRadioButtonUI; import javax.swing.text.View; @@ -75,13 +74,13 @@ public class DarculaRadioButtonUI extends MetalRadioButtonUI { g.fillRect(0,0, size.width, size.height); } - int rad = 5; + int rad = JBUI.scale(5); // Paint the radio button - final int x = iconRect.x + (rad-1)/2; - final int y = iconRect.y + (rad-1)/2; - final int w = iconRect.width - (rad + 5) / 2; - final int h = iconRect.height - (rad + 5) / 2; + final int x = iconRect.x + (rad - (rad % 2 == 1?1:0))/2; + final int y = iconRect.y + (rad - (rad % 2 == 1?1:0))/2; + final int w = iconRect.width - rad; + final int h = iconRect.height - rad; g.translate(x, y); @@ -91,36 +90,37 @@ public class DarculaRadioButtonUI extends MetalRadioButtonUI { g.setPaint(UIUtil.getGradientPaint(0, 0, ColorUtil.shift(c.getBackground(), 1.5), 0, c.getHeight(), ColorUtil.shift(c.getBackground(), 1.2))); if (focus) { - g.fillOval(0, 1, w, h); + g.fillOval(0, JBUI.scale(1), w, h); } else { - g.fillOval(0, 1, w - 1, h - 1); + g.fillOval(0, JBUI.scale(1), w - JBUI.scale(1), h - JBUI.scale(1)); } if (focus) { - if (UIUtil.isRetina()) { - DarculaUIUtil.paintFocusOval(g, 1, 2, w-2, h-2); + if (UIUtil.isRetina() || JBUI.isHiDPI()) { + DarculaUIUtil.paintFocusOval(g, JBUI.scale(1), JBUI.scale(1)+1, w-JBUI.scale(2), h-JBUI.scale(2)); } else { - DarculaUIUtil.paintFocusOval(g, 0, 1, w, h); + DarculaUIUtil.paintFocusOval(g, 0, JBUI.scale(1), w, h); } } else { if (UIUtil.isUnderDarcula()) { g.setPaint(UIUtil.getGradientPaint(w / 2, 1, Gray._160.withAlpha(90), w / 2, h, Gray._100.withAlpha(90))); - g.drawOval(0, 2, w - 1, h - 1); + g.drawOval(0, JBUI.scale(1)+1, w - 1, h - 1); g.setPaint(Gray._40.withAlpha(200)); - g.drawOval(0, 1, w - 1, h - 1); + g.drawOval(0, JBUI.scale(1), w - 1, h - 1); } else { g.setPaint(b.isEnabled() ? Gray._30 : Gray._130); - g.drawOval(0, 1, w - 1, h - 1); + g.drawOval(0, JBUI.scale(1), w - 1, h - 1); } } if (b.isSelected()) { final boolean enabled = b.isEnabled(); g.setColor(UIManager.getColor(enabled ? "RadioButton.darcula.selectionEnabledShadowColor" : "RadioButton.darcula.selectionDisabledShadowColor"));// ? Gray._30 : Gray._60); - g.fillOval(w/2 - rad/2, h/2 , rad, rad); + final int yOff = UIUtil.isUnderDarcula() ? 2:1; + g.fillOval(w/2 - rad/2, h/2 - rad/2 + yOff , rad, rad); g.setColor(UIManager.getColor(enabled ? "RadioButton.darcula.selectionEnabledColor" : "RadioButton.darcula.selectionDisabledColor")); //Gray._170 : Gray._120); - g.fillOval(w/2 - rad/2, h/2 - 1, rad, rad); + g.fillOval(w/2 - rad/2, h/2 - rad/2 -1 + yOff, rad, rad); } config.restore(); g.translate(-x, -y); @@ -147,6 +147,6 @@ public class DarculaRadioButtonUI extends MetalRadioButtonUI { @Override public Icon getDefaultIcon() { - return new IconUIResource(EmptyIcon.create(20)); + return JBUI.emptyIcon(20).asUIResource(); } } From fe4da758e3b88e162b47ef7370ba4a48f1dbfb4c Mon Sep 17 00:00:00 2001 From: Konstantin Bulenkov Date: Mon, 5 Jan 2015 23:00:07 +0100 Subject: [PATCH 2/8] use RenderingHints.VALUE_STROKE_PURE for better drawing of ovals and other curves (HiDPI + Darcula + Radio Button quality) --- platform/util/src/com/intellij/util/ui/GraphicsUtil.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/platform/util/src/com/intellij/util/ui/GraphicsUtil.java b/platform/util/src/com/intellij/util/ui/GraphicsUtil.java index fdd86de13296..83b5a0212d2e 100644 --- a/platform/util/src/com/intellij/util/ui/GraphicsUtil.java +++ b/platform/util/src/com/intellij/util/ui/GraphicsUtil.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. @@ -16,7 +16,6 @@ package com.intellij.util.ui; import com.intellij.openapi.ui.GraphicsConfig; -import com.intellij.openapi.util.registry.Registry; import org.jetbrains.annotations.NotNull; import java.awt.*; @@ -81,7 +80,7 @@ public class GraphicsUtil { final GraphicsConfig config = new GraphicsConfig(g); final Graphics2D g2 = (Graphics2D)g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); - g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE); + g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE); return config; } From 216e32ca0c1c580d3cb2c4272709159dbdb036f3 Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Tue, 6 Jan 2015 01:09:11 +0100 Subject: [PATCH 3/8] =?UTF-8?q?TestAppBackend=20=E2=80=94=20correct=20term?= =?UTF-8?q?ination=20(dispose=20project/app)=20call=20setResult=20on=20det?= =?UTF-8?q?ach=20if=20nio=20used=20(otherwise=20inifnite=20JS=20debug=20pr?= =?UTF-8?q?ocess=20closing)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../concurrency/CountDownConsumer.java | 13 +-- .../org/jetbrains/concurrency/Promise.java | 12 ++- .../connection/BrowserConnection.java | 3 +- .../debugger/connection/VmConnection.java | 12 ++- .../jetbrains/debugger/TestCompositeNode.java | 83 +++++++++---------- .../org/jetbrains/debugger/TestValueNode.java | 24 +++--- 6 files changed, 78 insertions(+), 69 deletions(-) diff --git a/platform/script-debugger/backend/src/org/jetbrains/concurrency/CountDownConsumer.java b/platform/script-debugger/backend/src/org/jetbrains/concurrency/CountDownConsumer.java index deed0153c4bf..6baecd16cb03 100644 --- a/platform/script-debugger/backend/src/org/jetbrains/concurrency/CountDownConsumer.java +++ b/platform/script-debugger/backend/src/org/jetbrains/concurrency/CountDownConsumer.java @@ -2,20 +2,23 @@ package org.jetbrains.concurrency; import com.intellij.util.Consumer; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; -class CountDownConsumer implements Consumer { +class CountDownConsumer implements Consumer { private volatile int countDown; - private final AsyncPromise promise; + private final AsyncPromise promise; + private final T totalResult; - public CountDownConsumer(int countDown, @NotNull AsyncPromise promise) { + public CountDownConsumer(int countDown, @NotNull AsyncPromise promise, @Nullable T totalResult) { this.countDown = countDown; this.promise = promise; + this.totalResult = totalResult; } @Override - public void consume(Void t) { + public void consume(T t) { if (--countDown == 0) { - promise.setResult(null); + promise.setResult(totalResult); } } } \ No newline at end of file diff --git a/platform/script-debugger/backend/src/org/jetbrains/concurrency/Promise.java b/platform/script-debugger/backend/src/org/jetbrains/concurrency/Promise.java index 1e1485ecbf88..c68d45780c06 100644 --- a/platform/script-debugger/backend/src/org/jetbrains/concurrency/Promise.java +++ b/platform/script-debugger/backend/src/org/jetbrains/concurrency/Promise.java @@ -51,12 +51,18 @@ public abstract class Promise { @NotNull public static Promise all(@NotNull Collection> promises) { + return all(promises, null); + } + + @NotNull + public static Promise all(@NotNull Collection> promises, @Nullable T totalResult) { if (promises.isEmpty()) { - return DONE; + //noinspection unchecked + return (Promise)DONE; } - final AsyncPromise totalPromise = new AsyncPromise(); - Consumer done = new CountDownConsumer(promises.size(), totalPromise); + final AsyncPromise totalPromise = new AsyncPromise(); + Consumer done = new CountDownConsumer(promises.size(), totalPromise, totalResult); Consumer rejected = new Consumer() { @Override public void consume(Throwable error) { diff --git a/platform/script-debugger/debugger-ui/src/org/jetbrains/debugger/connection/BrowserConnection.java b/platform/script-debugger/debugger-ui/src/org/jetbrains/debugger/connection/BrowserConnection.java index 71eb20571a35..352138ddfd7b 100644 --- a/platform/script-debugger/debugger-ui/src/org/jetbrains/debugger/connection/BrowserConnection.java +++ b/platform/script-debugger/debugger-ui/src/org/jetbrains/debugger/connection/BrowserConnection.java @@ -1,7 +1,6 @@ package org.jetbrains.debugger.connection; import com.intellij.ide.browsers.WebBrowser; -import com.intellij.openapi.Disposable; import com.intellij.util.io.socketConnection.ConnectionState; import com.intellij.util.io.socketConnection.SocketConnectionListener; import org.jetbrains.annotations.NotNull; @@ -11,7 +10,7 @@ public interface BrowserConnection { @NotNull ConnectionState getState(); - void addListener(@NotNull SocketConnectionListener listener, @NotNull Disposable parentDisposable); + void addListener(@NotNull SocketConnectionListener listener); void executeOnStart(@NotNull Runnable runnable); diff --git a/platform/script-debugger/debugger-ui/src/org/jetbrains/debugger/connection/VmConnection.java b/platform/script-debugger/debugger-ui/src/org/jetbrains/debugger/connection/VmConnection.java index 9a1b105bd9f8..9f9debf07bee 100644 --- a/platform/script-debugger/debugger-ui/src/org/jetbrains/debugger/connection/VmConnection.java +++ b/platform/script-debugger/debugger-ui/src/org/jetbrains/debugger/connection/VmConnection.java @@ -73,8 +73,8 @@ public abstract class VmConnection implements Disposable, BrowserC } @Override - public void addListener(@NotNull SocketConnectionListener listener, @NotNull Disposable parentDisposable) { - connectionDispatcher.addListener(listener, parentDisposable); + public void addListener(@NotNull SocketConnectionListener listener) { + connectionDispatcher.addListener(listener); } public DebugEventListener getDebugEventListener() { @@ -90,7 +90,9 @@ public abstract class VmConnection implements Disposable, BrowserC return; } - opened.setError(Promise.createError("closed")); + if (opened.getState() == Promise.State.PENDING) { + opened.setError(Promise.createError("closed")); + } setState(status, message); Disposer.dispose(this, false); } @@ -102,7 +104,9 @@ public abstract class VmConnection implements Disposable, BrowserC @NotNull public Promise detachAndClose() { - opened.setError(Promise.createError("detached and closed")); + if (opened.getState() == Promise.State.PENDING) { + opened.setError(Promise.createError("detached and closed")); + } Vm currentVm = vm; Promise callback; diff --git a/platform/script-debugger/debugger-ui/testSrc/org/jetbrains/debugger/TestCompositeNode.java b/platform/script-debugger/debugger-ui/testSrc/org/jetbrains/debugger/TestCompositeNode.java index 8824dcefa4ac..5690136f82a7 100644 --- a/platform/script-debugger/debugger-ui/testSrc/org/jetbrains/debugger/TestCompositeNode.java +++ b/platform/script-debugger/debugger-ui/testSrc/org/jetbrains/debugger/TestCompositeNode.java @@ -1,21 +1,22 @@ package org.jetbrains.debugger; -import com.intellij.openapi.util.ActionCallback; -import com.intellij.openapi.util.AsyncResult; import com.intellij.openapi.util.Condition; import com.intellij.openapi.util.Conditions; import com.intellij.ui.SimpleTextAttributes; -import com.intellij.util.Consumer; import com.intellij.xdebugger.frame.*; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.jetbrains.concurrency.AsyncFunction; +import org.jetbrains.concurrency.AsyncPromise; +import org.jetbrains.concurrency.Promise; import org.jetbrains.debugger.values.ObjectValue; import javax.swing.*; +import java.util.ArrayList; import java.util.List; public class TestCompositeNode implements XCompositeNode { - private final AsyncResult result = new AsyncResult(); + private final AsyncPromise result = new AsyncPromise(); private final XValueChildrenList children = new XValueChildrenList(); private final XValueGroup valueGroup; @@ -47,13 +48,13 @@ public class TestCompositeNode implements XCompositeNode { } if (last) { - result.setDone(this.children); + result.setResult(this.children); } } @Override public void tooManyChildren(int remaining) { - result.setDone(children); + result.setResult(children); } @Override @@ -62,7 +63,7 @@ public class TestCompositeNode implements XCompositeNode { @Override public void setErrorMessage(@NotNull String errorMessage) { - result.reject(errorMessage); + result.setError(Promise.createError(errorMessage)); } @Override @@ -80,47 +81,17 @@ public class TestCompositeNode implements XCompositeNode { } @NotNull - public AsyncResult getResult() { + public Promise getResult() { return result; } @NotNull - public AsyncResult loadContent(@NotNull final Condition groupContentResolveCondition, @NotNull final Condition valueSubContentResolveCondition) { + public Promise loadContent(@NotNull final Condition groupContentResolveCondition, @NotNull final Condition valueSubContentResolveCondition) { assert content == null; - final AsyncResult compoundResult = new AsyncResult(); content = new Content(); - result.doWhenDone(new Consumer() { - @Override - public void consume(XValueChildrenList children) { - ActionCallback.Chunk chunk = new ActionCallback.Chunk(); - resolveGroups(children.getTopGroups(), content.topGroups, chunk); - - for (int i = 0; i < children.size(); i++) { - XValue value = children.getValue(i); - TestValueNode node = new TestValueNode(); - node.myName = children.getName(i); - value.computePresentation(node, XValuePlace.TREE); - content.values.add(node); - chunk.add(node.getResult()); - - // myHasChildren could be not computed yet - if (value instanceof VariableView && ((VariableView)value).getValue() instanceof ObjectValue && valueSubContentResolveCondition.value((VariableView)value)) { - chunk.add(node.loadChildren(value)); - } - } - - resolveGroups(children.getBottomGroups(), content.bottomGroups, chunk); - - chunk.create().doWhenDone(new Runnable() { - @Override - public void run() { - compoundResult.setDone(content); - } - }).notifyWhenRejected(compoundResult); - } - - private void resolveGroups(@NotNull List valueGroups, @NotNull List resultNodes, @NotNull ActionCallback.Chunk chunk) { + return result.then(new AsyncFunction() { + private void resolveGroups(@NotNull List valueGroups, @NotNull List resultNodes, @NotNull List> promises) { for (XValueGroup group : valueGroups) { TestCompositeNode node = new TestCompositeNode(group); boolean computeChildren = groupContentResolveCondition.value(group); @@ -129,11 +100,35 @@ public class TestCompositeNode implements XCompositeNode { } resultNodes.add(node); if (computeChildren) { - chunk.add(node.loadContent(Conditions.alwaysFalse(), valueSubContentResolveCondition)); + promises.add(node.loadContent(Conditions.alwaysFalse(), valueSubContentResolveCondition)); } } } - }).notifyWhenRejected(compoundResult); - return compoundResult; + + @NotNull + @Override + public Promise fun(XValueChildrenList list) { + List> promises = new ArrayList>(); + resolveGroups(children.getTopGroups(), content.topGroups, promises); + + for (int i = 0; i < children.size(); i++) { + XValue value = children.getValue(i); + TestValueNode node = new TestValueNode(); + node.myName = children.getName(i); + value.computePresentation(node, XValuePlace.TREE); + content.values.add(node); + promises.add(node.getResult()); + + // myHasChildren could be not computed yet + if (value instanceof VariableView && ((VariableView)value).getValue() instanceof ObjectValue && valueSubContentResolveCondition.value((VariableView)value)) { + promises.add(node.loadChildren(value)); + } + } + + resolveGroups(children.getBottomGroups(), content.bottomGroups, promises); + + return Promise.all(promises, content); + } + }); } } \ No newline at end of file diff --git a/platform/script-debugger/debugger-ui/testSrc/org/jetbrains/debugger/TestValueNode.java b/platform/script-debugger/debugger-ui/testSrc/org/jetbrains/debugger/TestValueNode.java index 37cbcd916640..5b6885ebac4e 100644 --- a/platform/script-debugger/debugger-ui/testSrc/org/jetbrains/debugger/TestValueNode.java +++ b/platform/script-debugger/debugger-ui/testSrc/org/jetbrains/debugger/TestValueNode.java @@ -1,6 +1,5 @@ package org.jetbrains.debugger; -import com.intellij.openapi.util.AsyncResult; import com.intellij.openapi.util.Conditions; import com.intellij.util.Consumer; import com.intellij.xdebugger.XTestValueNode; @@ -9,29 +8,32 @@ import com.intellij.xdebugger.frame.XValueGroup; import com.intellij.xdebugger.frame.presentation.XValuePresentation; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.jetbrains.concurrency.AsyncPromise; +import org.jetbrains.concurrency.Promise; import javax.swing.*; public class TestValueNode extends XTestValueNode { - private final AsyncResult result = new AsyncResult(); + private final AsyncPromise result = new AsyncPromise(); private volatile Content children; @NotNull - public AsyncResult getResult() { + public Promise getResult() { return result; } @NotNull - public AsyncResult loadChildren(@NotNull XValue value) { + public Promise loadChildren(@NotNull XValue value) { TestCompositeNode childrenNode = new TestCompositeNode(); value.computeChildren(childrenNode); - return childrenNode.loadContent(Conditions.alwaysFalse(), Conditions.alwaysFalse()).doWhenDone(new Consumer() { - @Override - public void consume(Content content) { - children = content; - } - }); + return childrenNode.loadContent(Conditions.alwaysFalse(), Conditions.alwaysFalse()) + .done(new Consumer() { + @Override + public void consume(Content content) { + children = content; + } + }); } @Nullable @@ -43,6 +45,6 @@ public class TestValueNode extends XTestValueNode { public void applyPresentation(@Nullable Icon icon, @NotNull XValuePresentation valuePresentation, boolean hasChildren) { super.applyPresentation(icon, valuePresentation, hasChildren); - result.setDone(this); + result.setResult(this); } } \ No newline at end of file From 4d566519e90708fc0bf2aa2b1adb9d0fa871919b Mon Sep 17 00:00:00 2001 From: Konstantin Bulenkov Date: Tue, 6 Jan 2015 01:18:22 +0100 Subject: [PATCH 4/8] a hacky way to get MS windows scaling --- platform/util/src/com/intellij/util/ui/JBFont.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/platform/util/src/com/intellij/util/ui/JBFont.java b/platform/util/src/com/intellij/util/ui/JBFont.java index cf83f6c5f1db..312c1e8de934 100644 --- a/platform/util/src/com/intellij/util/ui/JBFont.java +++ b/platform/util/src/com/intellij/util/ui/JBFont.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. @@ -36,7 +36,9 @@ public class JBFont extends Font { } Font scaled = font; if (tryToScale) { - scaled = font.deriveFont(font.getSize() * JBUI.scale(1f)); + Object value = Toolkit.getDefaultToolkit().getDesktopProperty("win.systemFixed.font.height"); + float scale = value instanceof Integer ? ((Integer)value).floatValue() / 12f : 1f; + scaled = font.deriveFont(font.getSize() / scale * JBUI.scale(1f)); } if (font instanceof UIResource) { From 8615312c3492105870e1898428818497b25ed234 Mon Sep 17 00:00:00 2001 From: Konstantin Bulenkov Date: Tue, 6 Jan 2015 01:26:04 +0100 Subject: [PATCH 5/8] HiDPI: don't scale system fonts --- platform/util/src/com/intellij/util/ui/JBUI.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/platform/util/src/com/intellij/util/ui/JBUI.java b/platform/util/src/com/intellij/util/ui/JBUI.java index 6db8c0894913..37db53bff7e4 100644 --- a/platform/util/src/com/intellij/util/ui/JBUI.java +++ b/platform/util/src/com/intellij/util/ui/JBUI.java @@ -16,8 +16,6 @@ package com.intellij.util.ui; import javax.swing.*; -import javax.swing.border.Border; -import javax.swing.border.EmptyBorder; import java.awt.*; /** @@ -60,7 +58,7 @@ public class JBUI { public static class Fonts { public static JBFont label() { - return JBFont.create(UIManager.getFont("Label.font")); + return JBFont.create(UIManager.getFont("Label.font"), false); } public static JBFont label(float size) { From 04b63a3be29489062fbe2c2973b33242369fb26c Mon Sep 17 00:00:00 2001 From: Konstantin Bulenkov Date: Tue, 6 Jan 2015 01:27:23 +0100 Subject: [PATCH 6/8] HiDPI: don't patch system fonts. Windows LaF does its job --- .../intellij/ide/ui/laf/LafManagerImpl.java | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/ide/ui/laf/LafManagerImpl.java b/platform/platform-impl/src/com/intellij/ide/ui/laf/LafManagerImpl.java index 7ee720a0ca37..7056dd32a27d 100644 --- a/platform/platform-impl/src/com/intellij/ide/ui/laf/LafManagerImpl.java +++ b/platform/platform-impl/src/com/intellij/ide/ui/laf/LafManagerImpl.java @@ -51,7 +51,6 @@ import com.intellij.util.IJSwingUtilities; import com.intellij.util.ObjectUtils; import com.intellij.util.PlatformUtils; import com.intellij.util.containers.ContainerUtil; -import com.intellij.util.ui.JBFont; import com.intellij.util.ui.JBUI; import com.intellij.util.ui.UIUtil; import org.jdom.Element; @@ -729,18 +728,19 @@ public final class LafManagerImpl extends LafManager implements ApplicationCompo } private void patchLafFonts(UIDefaults uiDefaults) { - if (JBUI.isHiDPI()) { - HashMap newFonts = new HashMap(); - for (Object key : uiDefaults.keySet().toArray()) { - Object val = uiDefaults.get(key); - if (val instanceof Font) { - newFonts.put(key, JBFont.create((Font)val)); - } - } - for (Map.Entry entry : newFonts.entrySet()) { - uiDefaults.put(entry.getKey(), entry.getValue()); - } - } else if (UISettings.getInstance().OVERRIDE_NONIDEA_LAF_FONTS) { + //if (JBUI.isHiDPI()) { + // HashMap newFonts = new HashMap(); + // for (Object key : uiDefaults.keySet().toArray()) { + // Object val = uiDefaults.get(key); + // if (val instanceof Font) { + // newFonts.put(key, JBFont.create((Font)val)); + // } + // } + // for (Map.Entry entry : newFonts.entrySet()) { + // uiDefaults.put(entry.getKey(), entry.getValue()); + // } + //} else + if (UISettings.getInstance().OVERRIDE_NONIDEA_LAF_FONTS) { storeOriginalFontDefaults(uiDefaults); initFontDefaults(uiDefaults, myUiSettings.FONT_FACE, myUiSettings.FONT_SIZE); } From 7432a4307ca5c9a08f8b66f936a71b9649205bb5 Mon Sep 17 00:00:00 2001 From: Artem Govorov Date: Tue, 6 Jan 2015 13:20:59 +1000 Subject: [PATCH 7/8] Fixing IAE on attempt to create line comment in read-only file (WEB-14673), project field is used in postInvoke method (to get code style manager), so has to be assigned regardless on whether the file is read-only or not --- .../codeInsight/generation/CommentByLineCommentHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/generation/CommentByLineCommentHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/generation/CommentByLineCommentHandler.java index ef38b0bc31ac..313f49bfc962 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/generation/CommentByLineCommentHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/generation/CommentByLineCommentHandler.java @@ -66,8 +66,8 @@ public class CommentByLineCommentHandler extends MultiCaretCodeInsightActionHand @Override // first pass - adjacent carets are grouped into blocks public void invoke(@NotNull Project project, @NotNull Editor editor, @NotNull Caret caret, @NotNull PsiFile file) { - if (!CodeInsightUtilBase.prepareEditorForWrite(editor)) return; myProject = project; + if (!CodeInsightUtilBase.prepareEditorForWrite(editor)) return; file = file.getViewProvider().getPsi(file.getViewProvider().getBaseLanguage()); PsiElement context = InjectedLanguageManager.getInstance(file.getProject()).getInjectionHost(file); From 28653758fd37b3e6013167b44203ebf6147dafea Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Tue, 6 Jan 2015 14:31:21 +0100 Subject: [PATCH 8/8] SSR: expand search for "formal argument type of the method" to expected type --- .../JavaPredefinedConfigurations.java | 8 +++--- .../predicates/FormalArgTypePredicate.java | 26 +++++-------------- .../source/messages/SSRBundle.properties | 6 +++-- .../StructuralSearchTest.java | 10 ++++++- 4 files changed, 24 insertions(+), 26 deletions(-) diff --git a/java/structuralsearch-java/src/com/intellij/structuralsearch/JavaPredefinedConfigurations.java b/java/structuralsearch-java/src/com/intellij/structuralsearch/JavaPredefinedConfigurations.java index b90ef12355b2..45c38a57154f 100644 --- a/java/structuralsearch-java/src/com/intellij/structuralsearch/JavaPredefinedConfigurations.java +++ b/java/structuralsearch-java/src/com/intellij/structuralsearch/JavaPredefinedConfigurations.java @@ -286,10 +286,12 @@ class JavaPredefinedConfigurations { createSearchTemplateInfo(SSRBundle.message("predefined.configuration.fields.variables.read"),"'Symbol:[read]",INTERESTING_TYPE), createSearchTemplateInfo(SSRBundle.message("predefined.configuration.fields_variables.with.given.name.pattern.updated"),"'Symbol:[regex( name ) && write]",INTERESTING_TYPE), createSearchTemplateInfo(SSRBundle.message("predefined.configuration.usage.of.derived.type.in.cast"),"('CastType:*Base ) 'Expr",INTERESTING_TYPE), - createSearchTemplateInfo(SSRBundle.message("predefined.configuration.boxing.in.declarations"),"'_Type:Integer|Boolean|Long|Character|Short|Byte 'Var = '_Value:[formal( int|boolean|long|char|short|byte )]",INTERESTING_TYPE), - createSearchTemplateInfo(SSRBundle.message("predefined.configuration.unboxing.in.declarations"),"'_Type:int|boolean|long|char|short|byte 'Var = '_Value:[formal( Integer|Boolean|Long|Character|Short|Byte )]",INTERESTING_TYPE), - createSearchTemplateInfo(SSRBundle.message("predefined.configuration.boxing.in.method.calls"),"'_Instance?.'Call('_BeforeParam*,'_Param:[ exprtype( int|boolean|long|char|short|byte ) && formal( Integer|Boolean|Long|Character|Short|Byte )],'_AfterParam*)",INTERESTING_TYPE), + createSearchTemplateInfo(SSRBundle.message("predefined.configuration.boxing.in.declarations"),"'_Type:Object|Integer|Boolean|Long|Character|Short|Byte 'Var = '_Value:[exprtype( int|boolean|long|char|short|byte )]",INTERESTING_TYPE), + createSearchTemplateInfo(SSRBundle.message("predefined.configuration.unboxing.in.declarations"),"'_Type:int|boolean|long|char|short|byte 'Var = '_Value:[exprtype( Integer|Boolean|Long|Character|Short|Byte )]",INTERESTING_TYPE), + createSearchTemplateInfo(SSRBundle.message("predefined.configuration.boxing.in.method.calls"),"'_Instance?.'Call('_BeforeParam*,'_Param:[ exprtype( int|boolean|long|char|short|byte ) && formal( Object|Integer|Boolean|Long|Character|Short|Byte )],'_AfterParam*)",INTERESTING_TYPE), createSearchTemplateInfo(SSRBundle.message("predefined.configuration.unboxing.in.method.calls"), "'_Instance?.'Call('_BeforeParam*,'_Param:[ formal( int|boolean|long|char|short|byte ) && exprtype( Integer|Boolean|Long|Character|Short|Byte )],'_AfterParam*)",INTERESTING_TYPE), + createSearchTemplateInfo(SSRBundle.message("predefined.configuration.any.boxing"), "'_expression:[ exprtype( int|boolean|long|char|short|byte ) && formal( Object|Integer|Boolean|Long|Character|Short|Byte )]", INTERESTING_TYPE), + createSearchTemplateInfo(SSRBundle.message("predefined.configuration.any.unboxing"), "'_expression:[ formal( int|boolean|long|char|short|byte ) && exprtype( Integer|Boolean|Long|Character|Short|Byte )]", INTERESTING_TYPE), //createSearchTemplateInfo("methods called","'_?.'_:[ref('Method)] ('_*)", INTERESTING_TYPE), //createSearchTemplateInfo("fields selected","'_?.'_:[ref('Field)] ", INTERESTING_TYPE), //createSearchTemplateInfo("symbols used","'_:[ref('Symbol)] ", INTERESTING_TYPE), diff --git a/java/structuralsearch-java/src/com/intellij/structuralsearch/impl/matcher/predicates/FormalArgTypePredicate.java b/java/structuralsearch-java/src/com/intellij/structuralsearch/impl/matcher/predicates/FormalArgTypePredicate.java index 02f1ee7d08e0..08d015af7854 100644 --- a/java/structuralsearch-java/src/com/intellij/structuralsearch/impl/matcher/predicates/FormalArgTypePredicate.java +++ b/java/structuralsearch-java/src/com/intellij/structuralsearch/impl/matcher/predicates/FormalArgTypePredicate.java @@ -1,8 +1,9 @@ package com.intellij.structuralsearch.impl.matcher.predicates; +import com.intellij.psi.PsiExpression; +import com.intellij.psi.PsiType; import com.intellij.structuralsearch.impl.matcher.MatchContext; -import com.intellij.psi.*; -import com.intellij.psi.util.PsiTreeUtil; +import com.siyeh.ig.psiutils.ExpectedTypeUtils; /** * Created by IntelliJ IDEA. @@ -13,26 +14,11 @@ import com.intellij.psi.util.PsiTreeUtil; */ public class FormalArgTypePredicate extends ExprTypePredicate { - public FormalArgTypePredicate(String type, String baseName, boolean _withinHierarchy, boolean caseSensitiveMatch,boolean target) { - super(type, baseName, _withinHierarchy, caseSensitiveMatch, target); + public FormalArgTypePredicate(String type, String baseName, boolean withinHierarchy, boolean caseSensitiveMatch, boolean target) { + super(type, baseName, withinHierarchy, caseSensitiveMatch, target); } protected PsiType evalType(PsiExpression match, MatchContext context) { - final PsiMethodCallExpression expr = PsiTreeUtil.getParentOfType(match,PsiMethodCallExpression.class); - if (expr == null) return null; - - // find our parent in parameters of the method - final PsiMethod psiMethod = expr.resolveMethod(); - if (psiMethod == null) return null; - final PsiParameter[] methodParameters = psiMethod.getParameterList().getParameters(); - final PsiExpression[] expressions = expr.getArgumentList().getExpressions(); - - for(int i = 0;i < methodParameters.length; ++i) { - if (expressions[i] == match) { - if (i < methodParameters.length) return methodParameters[i].getType(); - break; - } - } - return null; + return ExpectedTypeUtils.findExpectedType(match, true, true); } } diff --git a/platform/structuralsearch/source/messages/SSRBundle.properties b/platform/structuralsearch/source/messages/SSRBundle.properties index d65271e16c46..9ffc141b32b0 100644 --- a/platform/structuralsearch/source/messages/SSRBundle.properties +++ b/platform/structuralsearch/source/messages/SSRBundle.properties @@ -86,6 +86,8 @@ predefined.configuration.unboxing.in.method.calls=unboxing in method calls predefined.configuration.boxing.in.method.calls=boxing in method calls predefined.configuration.unboxing.in.declarations=unboxing in declarations predefined.configuration.boxing.in.declarations=boxing in declarations +predefined.configuration.any.unboxing=unboxed expressions +predefined.configuration.any.boxing=boxed expressions predefined.configuration.filters=filters predefined.configuration.session.ejb=session ejb predefined.configuration.fields.variables.read=fields/variables read @@ -158,8 +160,8 @@ editvarcontraints.maximum.count=Maximum count\: editvarcontraints.minimum.count=Minimum count\: editvarcontraints.apply.constraint.within.type.hierarchy=Apply constraint within type hierarchy editvarcontraints.invert.condition=Invert condition -editvarcontraints.text.regular.expression.for.formal.argument.type.of.the.method=Text/regexp for formal argument type of the method\: -editvarcontraints.text.regular.expression.for.java.expression.type=Text/regexp for java expression type\: +editvarcontraints.text.regular.expression.for.formal.argument.type.of.the.method=Expected type of expression (regexp)\: +editvarcontraints.text.regular.expression.for.java.expression.type=Expression type (regexp)\: editvarcontraints.value.is.written=Value is written editvarcontraints.value.is.read=Value is read editvarcontraints.whole.words.only=Whole words only diff --git a/platform/structuralsearch/testSource/com/intellij/structuralsearch/StructuralSearchTest.java b/platform/structuralsearch/testSource/com/intellij/structuralsearch/StructuralSearchTest.java index 4503712bd3ac..002d0cea3aee 100644 --- a/platform/structuralsearch/testSource/com/intellij/structuralsearch/StructuralSearchTest.java +++ b/platform/structuralsearch/testSource/com/intellij/structuralsearch/StructuralSearchTest.java @@ -2464,12 +2464,20 @@ public class StructuralSearchTest extends StructuralSearchTestCase { "a.c(new Integer(2));\n" + "a.c(new Integer(3));\n" + "a.c2(new Integer(3));\n" + - "a.c(3);"; + "a.c(3);\n" + + "Integer i = 4;\n" + + "int j = Integer.valueOf(4);\n"; String s2 = "a.'b('_Params:[formal( Integer ) && exprtype( int ) ])"; String s2_2 = "a.c('_Params:[formal( int ) && exprtype( Integer ) ])"; assertEquals("Find boxing in method call",1,findMatchesCount(s1,s2,false)); assertEquals("Find unboxing in method call",2,findMatchesCount(s1,s2_2,false)); + + String pattern1 = "'_a:[formal( Integer ) && exprtype( int ) ]"; + assertEquals("Find any boxing", 2, findMatchesCount(s1, pattern1)); + + String pattern2 = "'_a:[formal( int ) && exprtype( Integer ) ]"; + assertEquals("Find any unboxing", 3, findMatchesCount(s1, pattern2)); } public void testCommentsInDclSearch() {