From 6f98f4c4f1b3edff7f72224db3c8a50b6c318af8 Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Thu, 29 Jan 2009 09:21:30 +0300 Subject: [PATCH] cleanup --- .../com/intellij/psi/util/TypeConversionUtil.java | 8 ++++---- util/src/com/intellij/util/ArrayUtil.java | 11 ++++++++++ .../intellij/util/text/ReverseCharSequence.java | 24 ++++++++++++++++++++++ 3 files changed, 39 insertions(+), 4 deletions(-) create mode 100644 util/src/com/intellij/util/text/ReverseCharSequence.java diff --git a/openapi/src/com/intellij/psi/util/TypeConversionUtil.java b/openapi/src/com/intellij/psi/util/TypeConversionUtil.java index 11856e0af6..5f4023f08e 100644 --- a/openapi/src/com/intellij/psi/util/TypeConversionUtil.java +++ b/openapi/src/com/intellij/psi/util/TypeConversionUtil.java @@ -34,7 +34,7 @@ import java.util.Set; public class TypeConversionUtil { private static final Logger LOG = Logger.getInstance("#com.intellij.psi.util.TypeConversionUtil"); - private static final boolean[][] IS_ASSIGNABLE_BIT_SET = new boolean[][]{ + private static final boolean[][] IS_ASSIGNABLE_BIT_SET = { {true, true, false, true, true, true, true}, // byte {false, true, false, true, true, true, true}, // short {false, false, true, true, true, true, true}, // char @@ -89,8 +89,8 @@ public class TypeConversionUtil { return boxedType != null && areTypesConvertible(boxedType, toType); } if (!fromIsPrimitive) { - if (fromTypeRank == toTypeRank) return true; - return fromTypeRank <= MAX_NUMERIC_RANK && toTypeRank <= MAX_NUMERIC_RANK && fromTypeRank < toTypeRank; + return fromTypeRank == toTypeRank || + fromTypeRank <= MAX_NUMERIC_RANK && toTypeRank <= MAX_NUMERIC_RANK && fromTypeRank < toTypeRank; } return fromTypeRank == toTypeRank || fromTypeRank <= MAX_NUMERIC_RANK && toTypeRank <= MAX_NUMERIC_RANK; @@ -1130,7 +1130,7 @@ public class TypeConversionUtil { Object cast(Object operand); } - private static final Caster[][] caster = new Caster[][]{ + private static final Caster[][] caster = { { new Caster() { public Object cast(Object operand) { diff --git a/util/src/com/intellij/util/ArrayUtil.java b/util/src/com/intellij/util/ArrayUtil.java index f8b16a3e77..3a50e7e231 100644 --- a/util/src/com/intellij/util/ArrayUtil.java +++ b/util/src/com/intellij/util/ArrayUtil.java @@ -360,6 +360,12 @@ public class ArrayUtil { } return newArray; } + + public static void reverse(char[] array) { + for (int i = 0; i < array.length; i++) { + swap(array, array.length - i - 1, i); + } + } public static int lexicographicCompare(@NotNull String[] obj1, @NotNull String[] obj2) { for (int i = 0; i < Math.max(obj1.length, obj2.length); i++) { @@ -396,6 +402,11 @@ public class ArrayUtil { array[i1] = array[i2]; array[i2] = t; } + public static void swap(char[] array, int i1, int i2) { + final char t = array[i1]; + array[i1] = array[i2]; + array[i2] = t; + } public static void rotateLeft(T[] array, int i1, int i2) { final T t = array[i1]; diff --git a/util/src/com/intellij/util/text/ReverseCharSequence.java b/util/src/com/intellij/util/text/ReverseCharSequence.java new file mode 100644 index 0000000000..f5e9b3540c --- /dev/null +++ b/util/src/com/intellij/util/text/ReverseCharSequence.java @@ -0,0 +1,24 @@ +package com.intellij.util.text; + +/** + * @author cdr + */ +public class ReverseCharSequence implements CharSequence{ + private final CharSequence mySequence; + + public ReverseCharSequence(CharSequence sequence) { + mySequence = sequence; + } + + public int length() { + return mySequence.length(); + } + + public char charAt(int index) { + return mySequence.charAt(mySequence.length()-index-1); + } + + public CharSequence subSequence(int start, int end) { + return new ReverseCharSequence(mySequence.subSequence(start, end)); + } +} -- 2.11.4.GIT