From 49e2e5444d2a8e104fcf8c992b04d16dfea44b4b Mon Sep 17 00:00:00 2001 From: Dmitry Avdeev Date: Thu, 22 Jan 2015 14:54:13 +0300 Subject: [PATCH 1/4] AnnotateCapitalizationIntention --- .../codeInsight/intention/AddAnnotationFix.java | 5 ++--- .../intention/AddAnnotationPsiFix.java | 15 ++++++--------- .../LocalQuickFixOnPsiElement.java | 3 +-- .../AnnotateCapitalizationIntention.java | 16 +++++++++++----- 4 files changed, 20 insertions(+), 19 deletions(-) diff --git a/java/java-analysis-impl/src/com/intellij/codeInsight/intention/AddAnnotationFix.java b/java/java-analysis-impl/src/com/intellij/codeInsight/intention/AddAnnotationFix.java index 91d2440442ab..1d72ba7728af 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInsight/intention/AddAnnotationFix.java +++ b/java/java-analysis-impl/src/com/intellij/codeInsight/intention/AddAnnotationFix.java @@ -23,18 +23,17 @@ import com.intellij.psi.PsiModifierListOwner; import com.intellij.psi.PsiNameValuePair; import com.intellij.util.IncorrectOperationException; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; /** * @author ven */ public class AddAnnotationFix extends AddAnnotationPsiFix implements IntentionAction { - public AddAnnotationFix(@NotNull String fqn, @Nullable PsiModifierListOwner modifierListOwner, @NotNull String... annotationsToRemove) { + public AddAnnotationFix(@NotNull String fqn, @NotNull PsiModifierListOwner modifierListOwner, @NotNull String... annotationsToRemove) { this(fqn, modifierListOwner, PsiNameValuePair.EMPTY_ARRAY, annotationsToRemove); } public AddAnnotationFix(@NotNull String fqn, - @Nullable PsiModifierListOwner modifierListOwner, + @NotNull PsiModifierListOwner modifierListOwner, @NotNull PsiNameValuePair[] values, @NotNull String... annotationsToRemove) { super(fqn, modifierListOwner, values, annotationsToRemove); diff --git a/java/java-analysis-impl/src/com/intellij/codeInsight/intention/AddAnnotationPsiFix.java b/java/java-analysis-impl/src/com/intellij/codeInsight/intention/AddAnnotationPsiFix.java index bcd365b1d8f0..e5e4bb68d11e 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInsight/intention/AddAnnotationPsiFix.java +++ b/java/java-analysis-impl/src/com/intellij/codeInsight/intention/AddAnnotationPsiFix.java @@ -37,10 +37,10 @@ public class AddAnnotationPsiFix extends LocalQuickFixOnPsiElement { protected final String myAnnotation; protected final String[] myAnnotationsToRemove; protected final PsiNameValuePair[] myPairs; // not used when registering local quick fix - protected String myText; + protected final String myText; public AddAnnotationPsiFix(@NotNull String fqn, - @Nullable PsiModifierListOwner modifierListOwner, + @NotNull PsiModifierListOwner modifierListOwner, @NotNull PsiNameValuePair[] values, @NotNull String... annotationsToRemove) { super(modifierListOwner); @@ -117,29 +117,26 @@ public class AddAnnotationPsiFix extends LocalQuickFixOnPsiElement { @NotNull PsiFile file, @NotNull PsiElement startElement, @NotNull PsiElement endElement) { + final PsiModifierListOwner myModifierListOwner = (PsiModifierListOwner)startElement; - invoke(project, file, (PsiModifierListOwner)startElement, myPairs); - } - - protected void invoke(@NotNull Project project, @NotNull PsiFile file, PsiModifierListOwner myModifierListOwner, PsiNameValuePair[] pairs) { + final ExternalAnnotationsManager annotationsManager = ExternalAnnotationsManager.getInstance(project); final PsiModifierList modifierList = myModifierListOwner.getModifierList(); LOG.assertTrue(modifierList != null); if (modifierList.findAnnotation(myAnnotation) != null) return; - final ExternalAnnotationsManager annotationsManager = ExternalAnnotationsManager.getInstance(project); final ExternalAnnotationsManager.AnnotationPlace annotationAnnotationPlace = annotationsManager.chooseAnnotationsPlace(myModifierListOwner); if (annotationAnnotationPlace == ExternalAnnotationsManager.AnnotationPlace.NOWHERE) return; if (annotationAnnotationPlace == ExternalAnnotationsManager.AnnotationPlace.EXTERNAL) { for (String fqn : myAnnotationsToRemove) { annotationsManager.deannotate(myModifierListOwner, fqn); } - annotationsManager.annotateExternally(myModifierListOwner, myAnnotation, file, pairs); + annotationsManager.annotateExternally(myModifierListOwner, myAnnotation, file, myPairs); } else { final PsiFile containingFile = myModifierListOwner.getContainingFile(); if (!FileModificationService.getInstance().preparePsiElementForWrite(containingFile)) return; removePhysicalAnnotations(myModifierListOwner, myAnnotationsToRemove); - PsiAnnotation inserted = addPhysicalAnnotation(myAnnotation, pairs, modifierList); + PsiAnnotation inserted = addPhysicalAnnotation(myAnnotation, myPairs, modifierList); JavaCodeStyleManager.getInstance(project).shortenClassReferences(inserted); if (containingFile != file) { UndoUtil.markPsiFileForUndo(file); diff --git a/platform/analysis-api/src/com/intellij/codeInspection/LocalQuickFixOnPsiElement.java b/platform/analysis-api/src/com/intellij/codeInspection/LocalQuickFixOnPsiElement.java index 26d0a4efeb62..404dc235f3ae 100644 --- a/platform/analysis-api/src/com/intellij/codeInspection/LocalQuickFixOnPsiElement.java +++ b/platform/analysis-api/src/com/intellij/codeInspection/LocalQuickFixOnPsiElement.java @@ -22,14 +22,13 @@ import com.intellij.psi.PsiFile; import com.intellij.psi.SmartPointerManager; import com.intellij.psi.SmartPsiElementPointer; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; public abstract class LocalQuickFixOnPsiElement implements LocalQuickFix { protected static final Logger LOG = Logger.getInstance("#com.intellij.codeInspection.LocalQuickFixAndIntentionAction"); protected final SmartPsiElementPointer myStartElement; protected final SmartPsiElementPointer myEndElement; - protected LocalQuickFixOnPsiElement(@Nullable PsiElement element) { + protected LocalQuickFixOnPsiElement(@NotNull PsiElement element) { this(element, element); } diff --git a/plugins/devkit/src/inspections/AnnotateCapitalizationIntention.java b/plugins/devkit/src/inspections/AnnotateCapitalizationIntention.java index 444c1b2324c9..45ebf47b036c 100644 --- a/plugins/devkit/src/inspections/AnnotateCapitalizationIntention.java +++ b/plugins/devkit/src/inspections/AnnotateCapitalizationIntention.java @@ -17,6 +17,7 @@ package org.jetbrains.idea.devkit.inspections; import com.intellij.codeInsight.AnnotationUtil; import com.intellij.codeInsight.intention.AddAnnotationFix; +import com.intellij.codeInsight.intention.IntentionAction; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.command.WriteCommandAction; import com.intellij.openapi.editor.Editor; @@ -34,10 +35,9 @@ import org.jetbrains.annotations.Nullable; /** * @author Dmitry Avdeev */ -public class AnnotateCapitalizationIntention extends AddAnnotationFix { +public class AnnotateCapitalizationIntention implements IntentionAction { public AnnotateCapitalizationIntention() { - super(Nls.class.getName(), null); } @Override @@ -46,10 +46,16 @@ public class AnnotateCapitalizationIntention extends AddAnnotationFix { if (element == null || (!ApplicationManager.getApplication().isUnitTestMode() && element.getManager().isInProject(element)) || AnnotationUtil.findAnnotation(element, Nls.class.getName()) != null) return false; - myText = "Annotate capitalization type"; return true; } + @Nls + @NotNull + @Override + public String getText() { + return getFamilyName(); + } + @NotNull @Override public String getFamilyName() { @@ -57,7 +63,7 @@ public class AnnotateCapitalizationIntention extends AddAnnotationFix { } @Override - public void invoke(@NotNull final Project project, Editor editor, final PsiFile file) throws IncorrectOperationException { + public void invoke(@NotNull final Project project, final Editor editor, final PsiFile file) throws IncorrectOperationException { final PsiModifierListOwner modifierListOwner = getElement(editor, file); if (modifierListOwner == null) throw new IncorrectOperationException(); @@ -72,7 +78,7 @@ public class AnnotateCapitalizationIntention extends AddAnnotationFix { PsiAnnotation annotation = JavaPsiFacade.getInstance(project).getElementFactory() .createAnnotationFromText("@" + nls + "(capitalization = " + nls + ".Capitalization." + selectedValue.toString() + ")", modifierListOwner); - invoke(project, file, modifierListOwner, annotation.getParameterList().getAttributes()); + new AddAnnotationFix(Nls.class.getName(), modifierListOwner, annotation.getParameterList().getAttributes()).applyFix(); } }.execute(); return FINAL_CHOICE; From 1d4e355369971356a6cb04cd96dbca99953187a3 Mon Sep 17 00:00:00 2001 From: Konstantin Bulenkov Date: Thu, 22 Jan 2015 13:00:33 +0100 Subject: [PATCH 2/4] Darcula: make triangle look the same for different sizes + HiDPI aware --- .../ui/laf/darcula/ui/DarculaComboBoxUI.java | 66 +++++++++++-------- 1 file changed, 37 insertions(+), 29 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/ui/DarculaComboBoxUI.java b/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/ui/DarculaComboBoxUI.java index 9c61666f3a2d..5b186e578795 100644 --- a/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/ui/DarculaComboBoxUI.java +++ b/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/ui/DarculaComboBoxUI.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. @@ -19,6 +19,7 @@ import com.intellij.ide.ui.laf.darcula.DarculaUIUtil; import com.intellij.openapi.ui.GraphicsConfig; import com.intellij.ui.Gray; import com.intellij.ui.JBColor; +import com.intellij.util.ui.JBUI; import com.intellij.util.ui.UIUtil; import sun.swing.DefaultLookup; @@ -46,7 +47,7 @@ public class DarculaComboBoxUI extends BasicComboBoxUI implements Border { private boolean myDisplaySizeDirty = true; // Cached the size that the display needs to render the largest item - private Dimension myDisplaySizeCache = new Dimension(0, 0); + private Dimension myDisplaySizeCache = JBUI.emptySize(); private Insets myPadding; public DarculaComboBoxUI(JComboBox comboBox) { @@ -87,17 +88,23 @@ public class DarculaComboBoxUI extends BasicComboBoxUI implements Border { g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE); g.setStroke(new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL)); - final int xU = w / 4; - final int yU = h / 4; + final int tW = JBUI.scale(8); + final int tH = JBUI.scale(6); + final int xU = (w - tW) / 2; + final int yU = (h - tH) / 2; + g.translate(JBUI.scale(2), 0); final Path2D.Double path = new Path2D.Double(); - g.translate(2, 0); - path.moveTo(xU + 1, yU + 2); - path.lineTo(3 * xU + 1, yU + 2); - path.lineTo(2 * xU + 1, 3 * yU); - path.lineTo(xU + 1, yU + 2); + path.moveTo(xU, yU); + path.lineTo(xU + tW, yU); + path.lineTo(xU + tW/2, yU + tH); + path.lineTo(xU, yU); + //path.moveTo(xU + 1, yU + 2); + //path.lineTo(3 * xU + 1, yU + 2); + //path.lineTo(2 * xU + 1, 3 * yU); + //path.lineTo(xU + 1, yU + 2); path.closePath(); g.fill(path); - g.translate(-2, 0); + g.translate(-JBUI.scale(2), 0); if (!isTableCellEditor(myComboBox)) { g.setColor(getArrowButtonFillColor(getBorderColor())); g.drawLine(0, -1, 0, h); @@ -125,7 +132,7 @@ public class DarculaComboBoxUI extends BasicComboBoxUI implements Border { @Override protected Insets getInsets() { - return new InsetsUIResource(4, 7, 4, 5); + return JBUI.insets(4, 7, 4, 5).asUIResource(); } protected Dimension getDisplaySize() { @@ -171,7 +178,7 @@ public class DarculaComboBoxUI extends BasicComboBoxUI implements Border { else { display = getDefaultSize(); if (comboBox.isEditable()) { - display.width = 100; + display.width = JBUI.scale(100); } } } @@ -218,8 +225,8 @@ public class DarculaComboBoxUI extends BasicComboBoxUI implements Border { @Override protected Rectangle rectangleForCurrentValue() { final Rectangle r = super.rectangleForCurrentValue(); - r.x-=2; - r.y-= isTableCellEditor(myComboBox) ? 0 : 1; + r.x-= JBUI.scale(2); + r.y-= isTableCellEditor(myComboBox) ? 0 : JBUI.scale(1); return r; } @@ -227,11 +234,8 @@ public class DarculaComboBoxUI extends BasicComboBoxUI implements Border { ListCellRenderer renderer = comboBox.getRenderer(); Component c; - if (hasFocus && !isPopupVisible(comboBox)) { - c = renderer.getListCellRendererComponent(listBox, comboBox.getSelectedItem(), -1, false, false); - } - else { - c = renderer.getListCellRendererComponent(listBox, comboBox.getSelectedItem(), -1, false, false); + c = renderer.getListCellRendererComponent(listBox, comboBox.getSelectedItem(), -1, false, false); + if (!hasFocus || isPopupVisible(comboBox)) { c.setBackground(UIManager.getColor("ComboBox.background")); } c.setFont(comboBox.getFont()); @@ -338,41 +342,45 @@ public class DarculaComboBoxUI extends BasicComboBoxUI implements Border { checkFocus(); final Graphics2D g = (Graphics2D)g2; final Rectangle arrowButtonBounds = arrowButton.getBounds(); - final int xxx = arrowButtonBounds.x - 5; + final int xxx = arrowButtonBounds.x - JBUI.scale(5); + final int H = height - JBUI.scale(4); + final int W = width - JBUI.scale(2); + final GraphicsConfig config = new GraphicsConfig(g); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE); + final int R = JBUI.scale(5); if (editor != null && comboBox.isEditable()) { ((JComponent)editor).setBorder(null); g.setColor(editor.getBackground()); - g.fillRoundRect(x + 1, y + 1, width - 2, height - 4, 5, 5); + g.fillRoundRect(x + 1, y + 1, W, H, R, R); g.setColor(getArrowButtonFillColor(arrowButton.getBackground())); - g.fillRoundRect(xxx, y + 1, width - xxx, height - 4, 5, 5); + g.fillRoundRect(xxx, y + 1, width - xxx, H, R, R); g.setColor(editor.getBackground()); - g.fillRect(xxx, y + 1, 5, height - 4); + g.fillRect(xxx, y + 1, 5, H); } else { g.setColor(UIUtil.getPanelBackground()); - g.fillRoundRect(x + 1, y + 1, width - 2, height - 4, 5, 5); + g.fillRoundRect(x + 1, y + 1, W, H, R, R); g.setColor(getArrowButtonFillColor(arrowButton.getBackground())); - g.fillRoundRect(xxx, y + 1, width - xxx, height - 4, 5, 5); + g.fillRoundRect(xxx, y + 1, width - xxx, H, R, R); g.setColor(UIUtil.getPanelBackground()); - g.fillRect(xxx, y + 1, 5, height - 4); + g.fillRect(xxx, y + 1, 5, H); } final Color borderColor = getBorderColor();//ColorUtil.shift(UIUtil.getBorderColor(), 4); g.setColor(getArrowButtonFillColor(borderColor)); int off = hasFocus ? 1 : 0; - g.drawLine(xxx + 5, y + 1 + off, xxx + 5, height - 3); + g.drawLine(xxx + JBUI.scale(5), y + JBUI.scale(1) + off, xxx + JBUI.scale(5), height - JBUI.scale(3)); Rectangle r = rectangleForCurrentValue(); paintCurrentValueBackground(g, r, hasFocus); paintCurrentValue(g, r, false); if (hasFocus) { - DarculaUIUtil.paintFocusRing(g, 2, 2, width - 4, height - 5); + DarculaUIUtil.paintFocusRing(g, JBUI.scale(2), JBUI.scale(2), width - JBUI.scale(4), height - JBUI.scale(5)); } else { g.setColor(borderColor); - g.drawRoundRect(1, 1, width - 2, height - 4, 5, 5); + g.drawRoundRect(JBUI.scale(1), JBUI.scale(1), width - JBUI.scale(2), height - JBUI.scale(4), R, R); } config.restore(); } From 65064ac05322bc681a2a6467c234f3bb3a2b4d91 Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Wed, 21 Jan 2015 16:49:42 +0100 Subject: [PATCH 3/4] include InterruptedException into mock1.7 testdata fixed --- .../daemonCodeAnalyzer/advHighlighting/aThinlet_hl.java | 4 ++-- .../daemon/LightAdvHighlightingPerformanceTest.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/aThinlet_hl.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/aThinlet_hl.java index ba880aba4979..137a9f7a48ec 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/aThinlet_hl.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/aThinlet_hl.java @@ -2000,7 +2000,7 @@ class Thinlet extends Container //java } } } - } catch (InterruptedException ie) {} //ie.printStackTrace(); + } catch (InterruptedException ie) {} //ie.printStackTrace(); } } @@ -5234,7 +5234,7 @@ class Thinlet extends Container //java mediatracker.addImage(image, 1); try { mediatracker.waitForID(1, 50); - } catch (InterruptedException ie) { } + } catch (InterruptedException ie) { } //imagepool.put(path, image); } // errors = doTest(Math.max(10000, 24000 - JobSchedulerImpl.CORES_COUNT * 1000)); - if (1172 != errors.size()) { + if (1170 != errors.size()) { doTest(getFilePath("_hl"), false, false); fail("Actual: " + errors.size()); } From b0dedb829665b4eacac8aefd9394f37d28554640 Mon Sep 17 00:00:00 2001 From: Sergey Malenkov Date: Thu, 22 Jan 2015 15:35:51 +0300 Subject: [PATCH 4/4] remove duplicates --- .../options/CodeStyleAbstractPanel.java | 2 +- .../options/TabbedLanguageCodeStylePanel.java | 23 ------------------- 2 files changed, 1 insertion(+), 24 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/application/options/CodeStyleAbstractPanel.java b/platform/lang-impl/src/com/intellij/application/options/CodeStyleAbstractPanel.java index 5e3d0cab5175..2cac88a86890 100644 --- a/platform/lang-impl/src/com/intellij/application/options/CodeStyleAbstractPanel.java +++ b/platform/lang-impl/src/com/intellij/application/options/CodeStyleAbstractPanel.java @@ -457,7 +457,7 @@ public abstract class CodeStyleAbstractPanel implements Disposable { protected void installPreviewPanel(final JPanel previewPanel) { previewPanel.setLayout(new BorderLayout()); - previewPanel.add(myEditor.getComponent(), BorderLayout.CENTER); + previewPanel.add(getEditor().getComponent(), BorderLayout.CENTER); previewPanel.setBorder(new CustomLineBorder(OnePixelDivider.BACKGROUND, 0, 1, 0, 0)); } diff --git a/platform/lang-impl/src/com/intellij/application/options/TabbedLanguageCodeStylePanel.java b/platform/lang-impl/src/com/intellij/application/options/TabbedLanguageCodeStylePanel.java index 81f2c875d574..4633ef9dcd22 100644 --- a/platform/lang-impl/src/com/intellij/application/options/TabbedLanguageCodeStylePanel.java +++ b/platform/lang-impl/src/com/intellij/application/options/TabbedLanguageCodeStylePanel.java @@ -31,12 +31,10 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.project.ProjectUtil; import com.intellij.openapi.ui.JBMenuItem; import com.intellij.openapi.ui.JBPopupMenu; -import com.intellij.openapi.ui.OnePixelDivider; import com.intellij.openapi.util.Disposer; import com.intellij.psi.codeStyle.*; import com.intellij.ui.ScrollPaneFactory; import com.intellij.ui.TabbedPaneWrapper; -import com.intellij.ui.border.CustomLineBorder; import com.intellij.util.containers.hash.HashSet; import com.intellij.util.ui.GraphicsUtil; import org.jetbrains.annotations.NotNull; @@ -407,13 +405,6 @@ public abstract class TabbedLanguageCodeStylePanel extends CodeStyleAbstractPane super(settings); } - @Override - protected void installPreviewPanel(JPanel previewPanel) { - previewPanel.setLayout(new BorderLayout()); - previewPanel.add(getEditor().getComponent(), BorderLayout.CENTER); - previewPanel.setBorder(new CustomLineBorder(OnePixelDivider.BACKGROUND, 0, 1, 0, 0)); - } - @Override protected boolean shouldHideOptions() { return true; @@ -431,13 +422,6 @@ public abstract class TabbedLanguageCodeStylePanel extends CodeStyleAbstractPane super(settings); } - @Override - protected void installPreviewPanel(JPanel previewPanel) { - previewPanel.setLayout(new BorderLayout()); - previewPanel.add(getEditor().getComponent(), BorderLayout.CENTER); - previewPanel.setBorder(new CustomLineBorder(OnePixelDivider.BACKGROUND, 0, 1, 0, 0)); - } - @Override public Language getDefaultLanguage() { return TabbedLanguageCodeStylePanel.this.getDefaultLanguage(); @@ -450,13 +434,6 @@ public abstract class TabbedLanguageCodeStylePanel extends CodeStyleAbstractPane super(settings); } - @Override - protected void installPreviewPanel(JPanel previewPanel) { - previewPanel.setLayout(new BorderLayout()); - previewPanel.add(getEditor().getComponent(), BorderLayout.CENTER); - previewPanel.setBorder(new CustomLineBorder(OnePixelDivider.BACKGROUND, 0, 1, 0, 0)); - } - @Override public Language getDefaultLanguage() { return TabbedLanguageCodeStylePanel.this.getDefaultLanguage();