From b962b05073a3978bf25252c5fbbf45a093208d7d Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Fri, 17 Aug 2012 14:40:40 +0200 Subject: [PATCH 1/4] IDEA-90184 ("Non-constant logger" inspection does not work properly) --- .../src/inspectionDescriptions/NonStaticFinalLogger.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/NonStaticFinalLogger.html b/plugins/InspectionGadgets/src/inspectionDescriptions/NonStaticFinalLogger.html index 3ad9f7c20a57..6c5afcde7a20 100644 --- a/plugins/InspectionGadgets/src/inspectionDescriptions/NonStaticFinalLogger.html +++ b/plugins/InspectionGadgets/src/inspectionDescriptions/NonStaticFinalLogger.html @@ -4,7 +4,7 @@ This inspection reports logger fields on classes which are not declared stati and final. Ensuring that every classes logger is effectively constant and bound to that class simplifies the task of providing a unified logging implementation for an application. Interfaces, -enumerations, annotations, inner classes, and abstract classes are not reported by this inspection. +enumerations, annotations and inner classes are not reported by this inspection.

Use the table below to specify Logger class names. From 7ad6bc8256e67a24a7aaba30738ff469d5011bf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yann=20C=C3=A9bron?= Date: Sun, 19 Aug 2012 00:27:39 +0200 Subject: [PATCH 2/4] performance --- .../codeInsight/daemon/RelatedItemLineMarkerProvider.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/platform/lang-api/src/com/intellij/codeInsight/daemon/RelatedItemLineMarkerProvider.java b/platform/lang-api/src/com/intellij/codeInsight/daemon/RelatedItemLineMarkerProvider.java index ccda13a1dda5..28af427a227b 100644 --- a/platform/lang-api/src/com/intellij/codeInsight/daemon/RelatedItemLineMarkerProvider.java +++ b/platform/lang-api/src/com/intellij/codeInsight/daemon/RelatedItemLineMarkerProvider.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2011 JetBrains s.r.o. + * Copyright 2000-2012 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. @@ -42,7 +42,9 @@ public abstract class RelatedItemLineMarkerProvider implements LineMarkerProvide public void collectNavigationMarkers(List elements, Collection result, boolean forNavigation) { - for (PsiElement element : elements) { + //noinspection ForLoopReplaceableByForEach + for (int i = 0, size = elements.size(); i < size; i++) { + PsiElement element = elements.get(i); collectNavigationMarkers(element, result); if (forNavigation && element instanceof PsiNameIdentifierOwner) { PsiElement nameIdentifier = ((PsiNameIdentifierOwner)element).getNameIdentifier(); From 71b89a5595a4b10618ffd396bb3b27534ca904d9 Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Sun, 19 Aug 2012 13:49:17 +0200 Subject: [PATCH 3/4] better description --- .../src/inspectionDescriptions/NonStaticFinalLogger.html | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/NonStaticFinalLogger.html b/plugins/InspectionGadgets/src/inspectionDescriptions/NonStaticFinalLogger.html index 6c5afcde7a20..d6d1b98db0b6 100644 --- a/plugins/InspectionGadgets/src/inspectionDescriptions/NonStaticFinalLogger.html +++ b/plugins/InspectionGadgets/src/inspectionDescriptions/NonStaticFinalLogger.html @@ -1,14 +1,13 @@ -This inspection reports logger fields on classes which are not declared static. -and final. +This inspection reports logger fields on classes which are not declared static and final. Ensuring that every classes logger is effectively constant and bound to that class simplifies the task of providing a unified logging implementation for an application. Interfaces, enumerations, annotations and inner classes are not reported by this inspection.

Use the table below to specify Logger class names. -Fields which have the type of one of the classes specified and which are not static. +Fields which have a type equal to one of the class names specified and which are not static and final, will be reported by this inspection.

Powered by InspectionGadgets From a406824efda0fd53df9740f940b02b6a74f6a612 Mon Sep 17 00:00:00 2001 From: "Denis.Zhdanov" Date: Sun, 19 Aug 2012 23:18:36 +0400 Subject: [PATCH 4/4] IDEA-19061 Integrate the Rearranger-plugin into core-IDE Tree modification utilities --- .../ArrangementConfigUtilTest.groovy | 99 ++++++++++++ .../ArrangementRuleEditingModelImplTest.java | 37 +++-- .../arrangement/ArrangementConfigUtil.java | 152 ++++++++++++++++++ 3 files changed, 276 insertions(+), 12 deletions(-) create mode 100644 java/java-tests/testSrc/com/intellij/application/options/codeStyle/arrangement/ArrangementConfigUtilTest.groovy diff --git a/java/java-tests/testSrc/com/intellij/application/options/codeStyle/arrangement/ArrangementConfigUtilTest.groovy b/java/java-tests/testSrc/com/intellij/application/options/codeStyle/arrangement/ArrangementConfigUtilTest.groovy new file mode 100644 index 000000000000..409a728079c9 --- /dev/null +++ b/java/java-tests/testSrc/com/intellij/application/options/codeStyle/arrangement/ArrangementConfigUtilTest.groovy @@ -0,0 +1,99 @@ +/* + * Copyright 2000-2012 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.application.options.codeStyle.arrangement + +import org.jetbrains.annotations.NotNull +import org.junit.Test + +import javax.swing.tree.DefaultMutableTreeNode + +import static org.junit.Assert.assertEquals +/** + * @author Denis Zhdanov + * @since 8/17/12 1:12 PM + */ +class ArrangementConfigUtilTest { + + @Test + void replace() { + // Init. + def one; + def four; + def initial = new TreeNodeBuilder(). + '0' { + one = '1' { + '2' { + '3'() + four = '4'() + '5'() + } + '6'() + } + } + + // Modify. + def replacement = new TreeNodeBuilder(). + '1' { + '4'() + } + ArrangementConfigUtil.replace(one, four, replacement) + + // Check + def expected = new TreeNodeBuilder(). + '0' { + '1' { + '2' { + '3'() + } + '4'() + '2' { + '5' + } + '6'() + } + } + // TODO den uncomment + //assertNodesEqual(expected, initial) + } + + private static void assertNodesEqual(@NotNull DefaultMutableTreeNode expected, @NotNull DefaultMutableTreeNode actual) { + assertEquals(expected.userObject, actual.userObject) + assertEquals(expected.childCount, actual.childCount) + for (i in [0.. from' path; + // 2. Remove 'to -> from' sub-hierarchy' by going bottom-up and stopping as soon as a current node has a child over than one + // from the sub-hierarchy to remove; + // 3. Add 'replacement' sub-hierarchy starting after the 'from' index at its parent; + // 4. Add sub-hierarchy cut at the 1) starting after the 'replacement' sub-hierarchy index; + // Example: + // Initial: + // 0 + // |_1 + // |_2 + // | |_3 + // | |_4 + // | |_5 + // | + // |_6 + // Let's say we want to replace the sub-hierarchy '1 -> 2 -> 4' by the sub-hierarchy '1 -> 4'. The algorithm in action: + // 1. Cut bottom sub-hierarchy: + // Current: Cut: + // 0 1 + // |_1 |_2 + // |_2 | |_5 + // |_3 | + // |_4 |_6 + // + // 2. Remove target sub-hierarchy: + // Current: + // 0 + // |_1 + // |_2 <-- stop at this node because it has a child node '3' which doesn't belong to the '1 -> 2 -> 4' + // |_3 + // 3. Add 'replacement' sub-hierarchy: + // Current: + // 0 + // |_1 <-- re-use this node for '1 -> 4' addition + // |_2 + // | |_3 + // | + // |_4 + // 4. Add 'bottom' sub-hierarchy: + // Current: + // 0 + // |_1 <-- re-use this node either for '1 -> 2 -> 5' or '1 -> 6' addition + // |_2 + // | |_3 + // | + // |_4 + // | + // |_2 + // | |_5 + // | + // |_6 + // + // Note: we need to have a notion of 'equal nodes' for node re-usage. It's provided by comparing node user objects. + + DefaultMutableTreeNode root = (DefaultMutableTreeNode)from.getParent(); + + //region Cut bottom sub-hierarchy + DefaultMutableTreeNode cutHierarchy = null; + for (DefaultMutableTreeNode current = to; current != root; current = (DefaultMutableTreeNode)current.getParent()) { + DefaultMutableTreeNode parent = (DefaultMutableTreeNode)current.getParent(); + int i = parent.getIndex(current); + if (i >= parent.getChildCount() - 1) { + continue; + } + DefaultMutableTreeNode parentCopy = new DefaultMutableTreeNode(parent.getUserObject()); + if (cutHierarchy != null) { + parentCopy.add(cutHierarchy); + } + for (int j = i + 1, limit = parent.getChildCount(); j < limit; j++) { + DefaultMutableTreeNode child = (DefaultMutableTreeNode)parent.getChildAt(j); + parent.remove(j); + parentCopy.add(child); + } + cutHierarchy = parentCopy; + } + //endregion + + int insertionIndex = root.getIndex(from) + 1; + + //region Remove target sub-hierarchy + for (DefaultMutableTreeNode current = to; current != root; current = (DefaultMutableTreeNode)current.getParent()) { + DefaultMutableTreeNode parent = (DefaultMutableTreeNode)current.getParent(); + parent.remove(current); + if (parent.getChildCount() > 0) { + break; + } + } + //endregion + + //region Insert nodes. + insert(root, insertionIndex, replacement); + if (cutHierarchy != null) { + insert(root, insertionIndex + 1, cutHierarchy); + } + //endregion + } + + /** + * Inserts given child to the given parent re-using existing nodes under the parent sub-hierarchy if possible (two nodes are + * considered equals if their {@link DefaultMutableTreeNode#getUserObject() user objects} are equal. + *

+ * Example: + *

+   *   parent:  0         to-insert: 2     
+   *            |_1                  |_3   
+   *            |_2                    |_6 
+   *            | |_3                      
+   *            |   |_4                    
+   *            |_5                        
+   *   -------------------------------------------------------------------------------------------------
+   *  | index:  |       0             |       1             |       2             |       3             |
+   *  |-------------------------------------------------------------------------------------------------
+   *  | result: |       0             |       0             |       0             |       0             |
+   *  |         |       |_2           |       |_1           |       |_1           |       |_1           |
+   *  |         |       | |_3         |       |_2           |       |_2           |       |_2           |
+   *  |         |       |   |_6       |       | |_3         |       | |_3         |       | |_3         |
+   *  |         |       |_1           |       |   |_6       |       |   |_4       |       |   |_4       |
+   *  |         |       |_2           |       |   |_4       |       |   |_6       |       |_5           |
+   *  |         |       | |_3         |       |_5           |       |_5           |       |_2           |
+   *  |         |       |   |_4       |                     |                     |         |_3         |
+   *  |         |       |_5           |                     |                     |           |_6       |
+   * 
+ * + * @param parent parent node to insert into + * @param index insertion index to use for the given parent node + * @param child node to insert to the given parent node at the given insertion index + */ + public static void insert(@NotNull DefaultMutableTreeNode parent, int index, @NotNull DefaultMutableTreeNode child) { + + } }