CR-IC-417 (bad API fixed)

This commit is contained in:
Roman Shevchenko
2013-03-18 21:32:14 +01:00
parent 49aa40bd67
commit 05ab431c42
3 changed files with 17 additions and 21 deletions
@@ -30,6 +30,7 @@ import com.intellij.psi.tree.TokenSet;
import com.intellij.psi.util.PsiUtil;
import com.intellij.util.ArrayUtil;
import com.intellij.util.SmartList;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -72,19 +73,20 @@ public class PsiNewExpressionImpl extends ExpressionPsiElement implements PsiNew
else if (ElementType.PRIMITIVE_TYPE_BIT_SET.contains(elementType)) {
assert type == null : this;
PsiElementFactory factory = JavaPsiFacade.getInstance(getProject()).getElementFactory();
type = factory.createPrimitiveType(child.getText(), annotations.toArray(PsiAnnotation.ARRAY_FACTORY, true));
type = factory.createPrimitiveType(child.getText(), ContainerUtil.copyAndClear(annotations, PsiAnnotation.ARRAY_FACTORY, true));
if (stop) return type;
}
else if (elementType == JavaTokenType.LBRACKET) {
assert type != null : this;
type = type.createArrayType(annotations.toArray(PsiAnnotation.ARRAY_FACTORY, true));
type = type.createArrayType(ContainerUtil.copyAndClear(annotations, PsiAnnotation.ARRAY_FACTORY, true));
if (stop) return type;
}
else if (elementType == JavaElementType.ANONYMOUS_CLASS) {
PsiElementFactory factory = JavaPsiFacade.getInstance(getProject()).getElementFactory();
PsiClass aClass = (PsiClass)child.getPsi();
PsiSubstitutor substitutor = aClass instanceof PsiTypeParameter ? PsiSubstitutor.EMPTY : factory.createRawSubstitutor(aClass);
type = factory.createType(aClass, substitutor, PsiUtil.getLanguageLevel(aClass), annotations.toArray(PsiAnnotation.ARRAY_FACTORY, true));
type = factory.createType(aClass, substitutor, PsiUtil.getLanguageLevel(aClass),
ContainerUtil.copyAndClear(annotations, PsiAnnotation.ARRAY_FACTORY, true));
if (stop) return type;
}
}
@@ -267,23 +267,6 @@ public class SmartList<E> extends AbstractList<E> {
return super.toArray(a);
}
/**
* Copies list elements into new array and clears the list if requested.
*
* @param factory a factory to allocate arrays.
* @param clear clear this lists after copying.
* @return allocated array.
*/
@NotNull
public <T> T[] toArray(@NotNull ArrayFactory<T> factory, boolean clear) {
T[] a = factory.create(mySize);
if (size() > 0) {
a = toArray(a);
if (clear) clear();
}
return a;
}
/**
* Trims the capacity of this list to be the
* list's current size. An application can use this operation to minimize
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
* Copyright 2000-2013 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.
@@ -1927,6 +1927,17 @@ public class ContainerUtil extends ContainerUtilRt {
return ContainerUtilRt.toArray(c, sample);
}
@NotNull
public static <T> T[] copyAndClear(@NotNull Collection<T> collection, @NotNull ArrayFactory<T> factory, boolean clear) {
int size = collection.size();
T[] a = factory.create(size);
if (size > 0) {
a = collection.toArray(a);
if (clear) collection.clear();
}
return a;
}
@NotNull
public static <T> Collection<T> toCollection(@NotNull Iterable<T> iterable) {
return iterable instanceof Collection ? (Collection<T>)iterable : newArrayList(iterable);