From 7b0a1d62571a6c331c96c3cb51fac0f400a5a534 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Thu, 20 Sep 2012 15:26:49 +0200 Subject: [PATCH] Cleanup --- .../com/intellij/psi/tree/IElementType.java | 114 +++++++++--------- .../src/com/intellij/psi/tree/TokenSet.java | 8 +- .../ide/util/treeView/AbstractTreeNode.java | 4 +- .../testFramework/PlatformTestUtil.java | 7 +- 4 files changed, 68 insertions(+), 65 deletions(-) diff --git a/platform/core-api/src/com/intellij/psi/tree/IElementType.java b/platform/core-api/src/com/intellij/psi/tree/IElementType.java index a731db42ab14..1726c27832ed 100644 --- a/platform/core-api/src/com/intellij/psi/tree/IElementType.java +++ b/platform/core-api/src/com/intellij/psi/tree/IElementType.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 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. @@ -35,12 +35,7 @@ import java.util.List; public class IElementType { private static final Logger LOG = Logger.getInstance("#com.intellij.psi.tree.IElementType"); - public static final short FIRST_TOKEN_INDEX = 1; - private static short ourCounter = FIRST_TOKEN_INDEX; - - private static final short MAX_INDEXED_TYPES = 15000; - private static final List ourRegistry = new ArrayList(700); - private final short myIndex; + public static final IElementType[] EMPTY_ARRAY = new IElementType[0]; /** * Default enumeration predicate which matches all token types. @@ -54,34 +49,16 @@ public class IElementType { } }; - static int getAllocatedTypesCount() { - return ourCounter; - } + public static final short FIRST_TOKEN_INDEX = 1; + public static final short MAX_INDEXED_TYPES = 15000; - public static final IElementType[] EMPTY_ARRAY = new IElementType[0]; - private final String myDebugName; + private static short ourCounter = FIRST_TOKEN_INDEX; + private static final List ourRegistry = new ArrayList(700); + + private final short myIndex; + @NotNull private final String myDebugName; @NotNull private final Language myLanguage; - /** - * Enumerates all registered token types which match the specified predicate. - * - * @param p the predicate which should be matched by the element types. - * @return the array of matching element types. - */ - public static IElementType[] enumerate(Predicate p) { - List matches = new ArrayList(); - IElementType[] copy; - synchronized (ourRegistry) { - copy = ourRegistry.toArray(new IElementType[ourRegistry.size()]); - } - for (IElementType value : copy) { - if (p.matches(value)) { - matches.add(value); - } - } - return matches.toArray(new IElementType[matches.size()]); - } - /** * Creates and registers a new element type for the specified language. * @@ -92,7 +69,7 @@ public class IElementType { this(debugName, language, true); } - protected IElementType(String debugName, Language language, final boolean register) { + protected IElementType(@NotNull @NonNls String debugName, @Nullable Language language, boolean register) { myDebugName = debugName; myLanguage = language == null ? Language.ANY : language; if (register) { @@ -132,15 +109,41 @@ public class IElementType { return myDebugName; } + /** + * Controls whitespace balancing behavior of PsiBuilder. + *

By default, empty composite elements (containing no children) are bounded to the right (previous) neighbour, forming following tree: + *

+   *  [previous_element]
+   *  [whitespace]
+   *  [empty_element]
+   *    <empty>
+   *  [next_element]
+   * 
+ *

Left-bound elements are bounded to the left (next) neighbour instead: + *

+   *  [previous_element]
+   *  [empty_element]
+   *    <empty>
+   *  [whitespace]
+   *  [next_element]
+   * 
+ *

See com.intellij.lang.impl.PsiBuilderImpl.prepareLightTree() for details. + * @return true if empty elements of this type should be bound to the left. + */ + public boolean isLeftBound() { + return false; + } + /** * Returns the element type registered at the specified index. * * @param idx the index for which the element type should be returned. * @return the element type at the specified index. + * @throws IndexOutOfBoundsException if the index is out of registered elements' range. */ public static IElementType find(short idx) { synchronized (ourRegistry) { - if (idx == 0) return ourRegistry.get(0); // We've changed FIRST_TOKEN_INDEX from 0 to 1. This is just for old plugins to avoid crashes. + if (idx == 0) return ourRegistry.get(0); // We've changed FIRST_TOKEN_INDEX from 0 to 1. This is just for old plugins to avoid crashes. return ourRegistry.get(idx - FIRST_TOKEN_INDEX); } } @@ -154,28 +157,29 @@ public class IElementType { boolean matches(IElementType type); } + static short getAllocatedTypesCount() { + return ourCounter; + } + /** - * Controls whitespace balancing behavior of PsiBuilder. - *

By default, empty composite elements (containing no children) are bounded to the right neighbour, forming following tree: - *

-   *  [previous_element]
-   *  [whitespace]
-   *  [empty_element]
-   *    <empty>
-   *  [next_element]
-   * 
- *

Left-bound elements are bounded to the left neighbour instead: - *

-   *  [previous_element]
-   *  [empty_element]
-   *    <empty>
-   *  [whitespace]
-   *  [next_element]
-   * 
- *

See {@linkplain com.intellij.lang.impl.PsiBuilderImpl#prepareLightTree()} for details. - * @return true if empty elements of this type should be bound to the left. + * Enumerates all registered token types which match the specified predicate. + * + * @param p the predicate which should be matched by the element types. + * @return the array of matching element types. */ - public boolean isLeftBound() { - return false; + @NotNull + public static IElementType[] enumerate(@NotNull Predicate p) { + IElementType[] copy; + synchronized (ourRegistry) { + copy = ourRegistry.toArray(new IElementType[ourRegistry.size()]); + } + + List matches = new ArrayList(); + for (IElementType value : copy) { + if (p.matches(value)) { + matches.add(value); + } + } + return matches.toArray(new IElementType[matches.size()]); } } \ No newline at end of file diff --git a/platform/core-api/src/com/intellij/psi/tree/TokenSet.java b/platform/core-api/src/com/intellij/psi/tree/TokenSet.java index 1628366f9f16..9fe1d116aefe 100644 --- a/platform/core-api/src/com/intellij/psi/tree/TokenSet.java +++ b/platform/core-api/src/com/intellij/psi/tree/TokenSet.java @@ -25,7 +25,7 @@ import java.util.Arrays; public class TokenSet { public static final TokenSet EMPTY = new TokenSet(); - private final boolean[] mySet = new boolean[IElementType.getAllocatedTypesCount()] ; + private final boolean[] mySet = new boolean[IElementType.getAllocatedTypesCount()]; private volatile IElementType[] myTypes; /** @@ -48,7 +48,7 @@ public class TokenSet { types[count++] = IElementType.find(i); } } - + myTypes = types; } @@ -127,7 +127,7 @@ public class TokenSet { public TokenSet minus(TokenSet t) { TokenSet set = new TokenSet(); for (int i = 0; i < mySet.length; i++) { - set.mySet [i] = mySet [i] && (i >= t.mySet.length || !t.mySet[i]); + set.mySet[i] = mySet[i] && (i >= t.mySet.length || !t.mySet[i]); } return set; } @@ -135,7 +135,7 @@ public class TokenSet { public static TokenSet not(TokenSet t) { TokenSet set = new TokenSet(); for (int i = 0; i < t.mySet.length; i++) { - set.mySet [i] = (i >= t.mySet.length || !t.mySet[i]); + set.mySet[i] = !t.mySet[i]; } return set; } diff --git a/platform/platform-api/src/com/intellij/ide/util/treeView/AbstractTreeNode.java b/platform/platform-api/src/com/intellij/ide/util/treeView/AbstractTreeNode.java index c8e7b0709c3e..edd655ec8b12 100644 --- a/platform/platform-api/src/com/intellij/ide/util/treeView/AbstractTreeNode.java +++ b/platform/platform-api/src/com/intellij/ide/util/treeView/AbstractTreeNode.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 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. @@ -156,7 +156,7 @@ public abstract class AbstractTreeNode extends PresentableNodeDescriptor impl } @Nullable - public String toTestString(Queryable.PrintInfo printInfo) { + public String toTestString(@Nullable Queryable.PrintInfo printInfo) { if (getValue() instanceof Queryable) { String text = Queryable.Util.print((Queryable)getValue(), printInfo, this); if (text != null) return text; diff --git a/platform/testFramework/src/com/intellij/testFramework/PlatformTestUtil.java b/platform/testFramework/src/com/intellij/testFramework/PlatformTestUtil.java index f9a458da2e55..46810a7a055a 100644 --- a/platform/testFramework/src/com/intellij/testFramework/PlatformTestUtil.java +++ b/platform/testFramework/src/com/intellij/testFramework/PlatformTestUtil.java @@ -98,7 +98,7 @@ public class PlatformTestUtil { } @Nullable - protected static String toString(Object node, @Nullable Queryable.PrintInfo printInfo) { + protected static String toString(@Nullable Object node, @Nullable Queryable.PrintInfo printInfo) { if (node instanceof AbstractTreeNode) { if (printInfo != null) { return ((AbstractTreeNode)node).toTestString(printInfo); @@ -492,10 +492,9 @@ public class PlatformTestUtil { String logMessage = message; if (duration > expectedOnMyMachine) { int percentage = (int)(100.0 * (duration - expectedOnMyMachine) / expectedOnMyMachine); - logMessage += ". (" + percentage + "% longer)."; + logMessage += ". (" + percentage + "% longer)"; } - logMessage += " Expected: " + expectedOnMyMachine + "." + - " Actual: " + duration + "." + Timings.getStatistics() ; + logMessage += ". Expected: " + expectedOnMyMachine + ". Actual: " + duration + "." + Timings.getStatistics() ; if (duration < expectedOnMyMachine) { int percentage = (int)(100.0 * (expectedOnMyMachine - duration) / expectedOnMyMachine); logMessage = "(" + percentage + "% faster). " + logMessage;