consistent ARRAY_FACTORY

This commit is contained in:
Alexey Kudravtsev
2017-04-13 15:30:00 +03:00
parent e48005b3cc
commit 8deb16a12f
21 changed files with 35 additions and 35 deletions
@@ -15,6 +15,7 @@
*/
package com.intellij.codeInspection.bytecodeAnalysis;
import com.intellij.util.ArrayFactory;
import org.jetbrains.annotations.NotNull;
import java.util.Arrays;
@@ -90,6 +91,8 @@ final class HKey {
* Represents a lattice product of a constant {@link #value} and all {@link #ids}.
*/
final class HComponent {
static final HComponent[] EMPTY_ARRAY = new HComponent[0];
static final ArrayFactory<HComponent> ARRAY_FACTORY = count -> count == 0 ? EMPTY_ARRAY : new HComponent[count];
@NotNull Value value;
@NotNull final HKey[] ids;
@@ -15,7 +15,6 @@
*/
package com.intellij.codeInspection.bytecodeAnalysis;
import com.intellij.util.ArrayFactory;
import com.intellij.util.ArrayUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.org.objectweb.asm.tree.analysis.AnalyzerException;
@@ -101,7 +100,6 @@ class ResultUtil {
class HResultUtil {
private static final HKey[] EMPTY_PRODUCT = new HKey[0];
private static final ArrayFactory<HComponent> HCOMPONENT_ARRAY_FACTORY = count -> new HComponent[count];
private final ELattice<Value> lattice;
final Value top;
@@ -138,7 +136,7 @@ class HResultUtil {
}
HPending pending1 = (HPending) r1;
HPending pending2 = (HPending) r2;
return new HPending(ArrayUtil.mergeArrays(pending1.delta, pending2.delta, HCOMPONENT_ARRAY_FACTORY));
return new HPending(ArrayUtil.mergeArrays(pending1.delta, pending2.delta, HComponent.ARRAY_FACTORY));
}
}
@@ -31,7 +31,7 @@ import org.jetbrains.annotations.Nullable;
*/
public abstract class PsiClassType extends PsiType {
public static final PsiClassType[] EMPTY_ARRAY = new PsiClassType[0];
public static final ArrayFactory<PsiClassType> ARRAY_FACTORY = count -> new PsiClassType[count];
public static final ArrayFactory<PsiClassType> ARRAY_FACTORY = count -> count == 0 ? EMPTY_ARRAY : new PsiClassType[count];
protected final LanguageLevel myLanguageLevel;
@@ -289,7 +289,7 @@ public abstract class PsiClassType extends PsiType {
};
}
public static abstract class Stub extends PsiClassType {
public abstract static class Stub extends PsiClassType {
protected Stub(LanguageLevel languageLevel, @NotNull PsiAnnotation[] annotations) {
super(languageLevel, annotations);
}
@@ -40,24 +40,21 @@ public class IElementType {
private static final Logger LOG = Logger.getInstance("#com.intellij.psi.tree.IElementType");
public static final IElementType[] EMPTY_ARRAY = new IElementType[0];
public static final ArrayFactory<IElementType> ARRAY_FACTORY = count -> count == 0 ? EMPTY_ARRAY : new IElementType[count];
/**
* Default enumeration predicate which matches all token types.
*
* @see #enumerate(Predicate)
*/
public static final Predicate TRUE = new Predicate() {
@Override
public boolean matches(@NotNull IElementType type) {
return true;
}
};
public static final Predicate TRUE = type -> true;
public static final short FIRST_TOKEN_INDEX = 1;
private static final short MAX_INDEXED_TYPES = 15000;
private static short size; // guarded by lock
private static volatile IElementType[] ourRegistry = EMPTY_ARRAY; // writes are guarded by lock
@SuppressWarnings("RedundantStringConstructorCall")
private static final Object lock = new String("registry lock");
static {
@@ -91,7 +88,6 @@ public class IElementType {
this(debugName, language, true);
}
private static final ArrayFactory<IElementType> FACTORY = count -> new IElementType[count];
/**
* Allows to construct element types for some temporary purposes without registering them.
@@ -107,7 +103,7 @@ public class IElementType {
myIndex = size++;
LOG.assertTrue(myIndex < MAX_INDEXED_TYPES, "Too many element types registered. Out of (short) range.");
IElementType[] newRegistry =
myIndex >= ourRegistry.length ? ArrayUtil.realloc(ourRegistry, ourRegistry.length * 3 / 2 + 1, FACTORY) : ourRegistry;
myIndex >= ourRegistry.length ? ArrayUtil.realloc(ourRegistry, ourRegistry.length * 3 / 2 + 1, ARRAY_FACTORY) : ourRegistry;
newRegistry[myIndex] = this;
ourRegistry = newRegistry;
}
@@ -189,6 +185,7 @@ public class IElementType {
*
* @see IElementType#enumerate(Predicate)
*/
@FunctionalInterface
public interface Predicate {
boolean matches(@NotNull IElementType type);
}
@@ -126,8 +126,6 @@ public class PsiBuilderImpl extends UserDataHolderBase implements PsiBuilder {
doneMarker.clean();
}
});
private static final ArrayFactory<IElementType> myElementTypeArrayFactory =
count -> count == 0 ? IElementType.EMPTY_ARRAY : new IElementType[count];
public static void registerWhitespaceToken(@NotNull IElementType type) {
ourAnyLanguageWhitespaceTokens = TokenSet.orSet(ourAnyLanguageWhitespaceTokens, TokenSet.create(type));
@@ -918,7 +916,7 @@ public class PsiBuilderImpl extends UserDataHolderBase implements PsiBuilder {
private void resizeLexemes(final int newSize) {
myLexStarts = ArrayUtil.realloc(myLexStarts, newSize+1);
myLexTypes = ArrayUtil.realloc(myLexTypes, newSize, myElementTypeArrayFactory);
myLexTypes = ArrayUtil.realloc(myLexTypes, newSize, IElementType.ARRAY_FACTORY);
clearCachedTokenType();
}
@@ -19,6 +19,7 @@ import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiElement;
import com.intellij.util.ArrayFactory;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -30,6 +31,9 @@ import org.jetbrains.annotations.Nullable;
* @see SurroundDescriptor
*/
public interface Surrounder {
Surrounder[] EMPTY_ARRAY = new Surrounder[0];
ArrayFactory<Surrounder> myArrayFactory = count -> count == 0 ? EMPTY_ARRAY : new Surrounder[count];
/**
* Returns the user-visible name of the Surround With template.
*
@@ -17,6 +17,7 @@
package org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation;
import com.intellij.psi.PsiAnnotation;
import com.intellij.util.ArrayFactory;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.GrCondition;
import org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement;
@@ -28,6 +29,7 @@ import org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement;
public interface GrAnnotation extends GrCondition, PsiAnnotation, GrAnnotationMemberValue {
GrAnnotation[] EMPTY_ARRAY = new GrAnnotation[0];
ArrayFactory<GrAnnotation> ARRAY_FACTORY = count -> count == 0 ? EMPTY_ARRAY : new GrAnnotation[count];
@NotNull
GrCodeReferenceElement getClassReference();
@@ -35,7 +35,7 @@ import org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeElement;
*/
public interface GrVariable extends PsiVariable, GrNamedElement {
GrVariable[] EMPTY_ARRAY = new GrVariable[0];
ArrayFactory<GrVariable> ARRAY_FACTORY = GrVariable[]::new;
ArrayFactory<GrVariable> ARRAY_FACTORY = count -> count == 0 ? EMPTY_ARRAY : new GrVariable[count];
@Override
@NotNull
@@ -31,7 +31,7 @@ import org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeElement;
*/
public interface GrVariableDeclaration extends GrStatement, GrMembersDeclaration {
GrVariableDeclaration[] EMPTY_ARRAY = new GrVariableDeclaration[0];
ArrayFactory<GrVariableDeclaration> ARRAY_FACTORY = count -> new GrVariableDeclaration[count];
ArrayFactory<GrVariableDeclaration> ARRAY_FACTORY = count -> count == 0 ? EMPTY_ARRAY : new GrVariableDeclaration[count];
@Nullable
GrTypeElement getTypeElementGroovy();
@@ -33,7 +33,7 @@ import org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeElement;
*/
public interface GrParameter extends PsiParameter, GrVariable, GrCondition {
GrParameter[] EMPTY_ARRAY = new GrParameter[0];
ArrayFactory<GrParameter> ARRAY_FACTORY = count -> new GrParameter[count];
ArrayFactory<GrParameter> ARRAY_FACTORY = count -> count == 0 ? EMPTY_ARRAY : new GrParameter[count];
@Override
@Nullable
@@ -27,7 +27,8 @@ import org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement;
* @author ilyas
*/
public interface GrReferenceList extends GroovyPsiElement, PsiReferenceList {
ArrayFactory<GrReferenceList> ARRAY_FACTORY = count -> new GrReferenceList[0];
GrReferenceList[] EMPTY_ARRAY = new GrReferenceList[0];
ArrayFactory<GrReferenceList> ARRAY_FACTORY = count -> count == 0 ? EMPTY_ARRAY : new GrReferenceList[count];
@Nullable
PsiElement getKeyword();
@@ -37,7 +37,7 @@ import org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeParameterList;
public interface GrTypeDefinition extends PsiClass, GrDocCommentOwner, GrMember, GrNamedElement, GrTopStatement {
GrTypeDefinition[] EMPTY_ARRAY = new GrTypeDefinition[0];
ArrayFactory<GrTypeDefinition> ARRAY_FACTORY = GrTypeDefinition[]::new;
ArrayFactory<GrTypeDefinition> ARRAY_FACTORY = count -> count == 0 ? EMPTY_ARRAY : new GrTypeDefinition[count];
@NotNull
@Override
@@ -19,7 +19,6 @@ package org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members;
import com.intellij.psi.PsiEnumConstant;
import com.intellij.psi.PsiMethod;
import com.intellij.util.ArrayFactory;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrField;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList;
@@ -32,7 +31,7 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrEnumConsta
*/
public interface GrEnumConstant extends GrField, GrConstructorCall, PsiEnumConstant {
GrEnumConstant[] EMPTY_ARRAY = new GrEnumConstant[0];
ArrayFactory<GrEnumConstant> ARRAY_FACTORY = count -> new GrEnumConstant[count];
ArrayFactory<GrEnumConstant> ARRAY_FACTORY = count -> count == 0 ? EMPTY_ARRAY : new GrEnumConstant[count];
@Override
@Nullable
@@ -43,7 +43,7 @@ import java.util.Map;
public interface GrMethod extends GrMembersDeclaration, GrNamedElement, PsiMethod, GrMember,
GrParametersOwner, GrTopStatement, GrTypeParameterListOwner, GrDocCommentOwner {
GrMethod[] EMPTY_ARRAY = new GrMethod[0];
ArrayFactory<GrMethod> ARRAY_FACTORY = count -> new GrMethod[count];
ArrayFactory<GrMethod> ARRAY_FACTORY = count -> count == 0 ? EMPTY_ARRAY : new GrMethod[count];
@Nullable
GrOpenBlock getBlock();
@@ -31,7 +31,7 @@ import org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement;
public interface GrImportStatement extends GrTopStatement {
GrImportStatement[] EMPTY_ARRAY = new GrImportStatement[0];
ArrayFactory<GrImportStatement> ARRAY_FACTORY = count -> new GrImportStatement[count];
ArrayFactory<GrImportStatement> ARRAY_FACTORY = count -> count == 0 ? EMPTY_ARRAY : new GrImportStatement[count];
@Nullable
GrCodeReferenceElement getImportReference();
@@ -17,6 +17,7 @@
package org.jetbrains.plugins.groovy.lang.psi.api.types;
import com.intellij.psi.PsiTypeParameter;
import com.intellij.util.ArrayFactory;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition;
/**
@@ -24,4 +25,5 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefini
*/
public interface GrTypeParameter extends GrTypeDefinition, PsiTypeParameter {
public static final GrTypeParameter[] EMPTY_ARRAY = new GrTypeParameter[0];
ArrayFactory<GrTypeParameter> ARRAY_FACTORY = count -> count == 0 ? EMPTY_ARRAY : new GrTypeParameter[count];
}
@@ -23,7 +23,6 @@ import com.intellij.psi.tree.IElementType;
import com.intellij.psi.util.CachedValueProvider.Result;
import com.intellij.psi.util.CachedValuesManager;
import com.intellij.psi.util.PsiModificationTracker;
import com.intellij.util.ArrayFactory;
import com.intellij.util.IncorrectOperationException;
import com.intellij.util.containers.ContainerUtil;
import gnu.trove.TObjectIntHashMap;
@@ -57,7 +56,6 @@ import java.util.Map;
public class GrModifierListImpl extends GrStubElementBase<GrModifierListStub> implements GrModifierList, StubBasedPsiElement<GrModifierListStub> {
public static final TObjectIntHashMap<String> NAME_TO_MODIFIER_FLAG_MAP = new TObjectIntHashMap<>();
public static final Map<String, IElementType> NAME_TO_MODIFIER_ELEMENT_TYPE = ContainerUtil.newHashMap();
private static final ArrayFactory<GrAnnotation> ARRAY_FACTORY = GrAnnotation[]::new;
private static final TObjectIntHashMap<String> PRIORITY = new TObjectIntHashMap<>(16);
@@ -208,7 +206,7 @@ public class GrModifierListImpl extends GrStubElementBase<GrModifierListStub> im
@NotNull
@Override
public GrAnnotation[] getRawAnnotations() {
return getStubOrPsiChildren(GroovyElementTypes.ANNOTATION, ARRAY_FACTORY);
return getStubOrPsiChildren(GroovyElementTypes.ANNOTATION, GrAnnotation.ARRAY_FACTORY);
}
private void setModifierPropertyInternal(String name, boolean doSet) {
@@ -21,7 +21,6 @@ import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiTypeParameter;
import com.intellij.psi.StubBasedPsiElement;
import com.intellij.psi.stubs.EmptyStub;
import com.intellij.util.ArrayFactory;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes;
import org.jetbrains.plugins.groovy.lang.parser.GroovyElementTypes;
@@ -37,7 +36,6 @@ import org.jetbrains.plugins.groovy.lang.psi.impl.GrStubElementBase;
* @author ilyas
*/
public class GrTypeParameterListImpl extends GrStubElementBase<EmptyStub> implements GrTypeParameterList, StubBasedPsiElement<EmptyStub> {
private static final ArrayFactory<GrTypeParameter> ARRAY_FACTORY = count -> new GrTypeParameter[count];
public GrTypeParameterListImpl(EmptyStub stub) {
super(stub, GroovyElementTypes.TYPE_PARAMETER_LIST);
@@ -54,7 +52,7 @@ public class GrTypeParameterListImpl extends GrStubElementBase<EmptyStub> implem
@NotNull
@Override
public GrTypeParameter[] getTypeParameters() {
return getStubOrPsiChildren(GroovyElementTypes.TYPE_PARAMETER, ARRAY_FACTORY);
return getStubOrPsiChildren(GroovyElementTypes.TYPE_PARAMETER, GrTypeParameter.ARRAY_FACTORY);
}
@Override
@@ -39,7 +39,8 @@ import java.util.Map;
*/
public interface PyClass extends PsiNameIdentifierOwner, PyStatement, PyDocStringOwner, StubBasedPsiElement<PyClassStub>,
ScopeOwner, PyDecoratable, PyTypedElement, PyQualifiedNameOwner, PyStatementListContainer, PyWithAncestors {
ArrayFactory<PyClass> ARRAY_FACTORY = count -> new PyClass[count];
PyClass[] EMPTY_ARRAY = new PyClass[0];
ArrayFactory<PyClass> ARRAY_FACTORY = count -> count == 0 ? EMPTY_ARRAY : new PyClass[count];
@Nullable
ASTNode getNameNode();
@@ -39,7 +39,7 @@ public interface PyFunction extends PsiNamedElement, StubBasedPsiElement<PyFunct
PyPossibleClassMember, PyTypeCommentOwner, PyAnnotationOwner {
PyFunction[] EMPTY_ARRAY = new PyFunction[0];
ArrayFactory<PyFunction> ARRAY_FACTORY = count -> new PyFunction[count];
ArrayFactory<PyFunction> ARRAY_FACTORY = count -> count == 0 ? EMPTY_ARRAY : new PyFunction[count];
/**
* Returns the AST node for the function name identifier.
@@ -19,7 +19,6 @@ package com.intellij.xml;
import com.intellij.psi.meta.PsiMetaData;
import com.intellij.psi.xml.XmlElement;
import com.intellij.util.ArrayFactory;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
@@ -27,7 +26,7 @@ import org.jetbrains.annotations.Nullable;
*/
public interface XmlAttributeDescriptor extends PsiMetaData {
XmlAttributeDescriptor[] EMPTY = new XmlAttributeDescriptor[0];
ArrayFactory<XmlAttributeDescriptor> ARRAY_FACTORY = count -> new XmlAttributeDescriptor[count];
ArrayFactory<XmlAttributeDescriptor> ARRAY_FACTORY = count -> count == 0 ? EMPTY : new XmlAttributeDescriptor[count];
boolean isRequired();
boolean isFixed();