This commit is contained in:
Alexey Kudravtsev
2016-04-27 13:31:03 +03:00
parent 641194794f
commit 4a18a8be0d
23 changed files with 87 additions and 44 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2015 JetBrains s.r.o.
* Copyright 2000-2016 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.
@@ -17,10 +17,12 @@ package com.intellij.psi.stubs;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiFile;
import org.jetbrains.annotations.NotNull;
/**
* @author ilyas
*/
public interface PsiClassHolderFileStub<T extends PsiFile> extends PsiFileStub<T> {
@NotNull
PsiClass[] getClasses();
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
* Copyright 2000-2016 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.
@@ -208,7 +208,7 @@ public abstract class JavaClassElementType extends JavaStubElementType<PsiClassS
}
@Override
public String getId(final PsiClassStub stub) {
public String getId(@NotNull final PsiClassStub stub) {
final String name = stub.getName();
return name != null ? name : super.getId(stub);
}
@@ -21,6 +21,7 @@ import com.intellij.psi.impl.java.stubs.*;
import com.intellij.psi.stubs.PsiFileStubImpl;
import com.intellij.psi.tree.IStubFileElementType;
import com.intellij.util.io.StringRef;
import org.jetbrains.annotations.NotNull;
/**
* @author max
@@ -41,11 +42,13 @@ public class PsiJavaFileStubImpl extends PsiFileStubImpl<PsiJavaFile> implements
this(null, StringRef.fromString(packageName), compiled);
}
@NotNull
@Override
public IStubFileElementType getType() {
return JavaStubElementTypes.JAVA_FILE;
}
@NotNull
@Override
public PsiClass[] getClasses() {
return getChildrenByType(JavaStubElementTypes.CLASS, PsiClass.ARRAY_FACTORY);
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2016 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.
@@ -21,13 +21,14 @@ package com.intellij.psi.stubs;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.indexing.FileContent;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* @see com.intellij.psi.stubs.BinaryFileStubBuilders#EXTENSION_POINT_NAME
*/
public interface BinaryFileStubBuilder {
boolean acceptsFile(VirtualFile file);
boolean acceptsFile(@NotNull VirtualFile file);
@Nullable
Stub buildStubTree(FileContent fileContent);
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2016 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.
@@ -40,7 +40,7 @@ public abstract class IStubElementType<StubT extends StubElement, PsiT extends P
return true;
}
public String getId(StubT stub) {
public String getId(@NotNull StubT stub) {
assert stub.getStubType() == this;
final StubElement parent = stub.getParentStub();
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
* Copyright 2000-2016 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.
@@ -30,6 +30,7 @@ public abstract class ObjectStubBase<T extends Stub> extends UserDataHolderBase
myParent = parent;
}
@Override
public T getParentStub() {
return myParent;
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2016 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.
@@ -28,6 +28,7 @@ import org.jetbrains.annotations.Nullable;
public interface PsiFileStub<T extends PsiFile> extends StubElement<T>, UserDataHolder {
PsiFileStub[] EMPTY_ARRAY = new PsiFileStub[0];
@NotNull
StubFileElementType getType();
@NotNull
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
* Copyright 2000-2016 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.
@@ -15,6 +15,8 @@
*/
package com.intellij.psi.stubs;
import org.jetbrains.annotations.NotNull;
import java.util.List;
/**
@@ -22,8 +24,8 @@ import java.util.List;
* Date: 8/2/12
*/
public interface Stub {
Stub getParentStub();
@NotNull
List<? extends Stub> getChildrenStubs();
ObjectStubSerializer getStubType();
@@ -64,7 +64,7 @@ public abstract class StubBase<T extends PsiElement> extends ObjectStubBase<Stub
@Override
@Nullable
public <P extends PsiElement> StubElement<P> findChildStubByType(final IStubElementType<?, P> elementType) {
public <P extends PsiElement> StubElement<P> findChildStubByType(@NotNull final IStubElementType<?, P> elementType) {
final List<StubElement> childrenStubs = getChildrenStubs();
final int size = childrenStubs.size();
@@ -102,6 +102,7 @@ public abstract class StubBase<T extends PsiElement> extends ObjectStubBase<Stub
}
@NotNull
@Override
public <E extends PsiElement> E[] getChildrenByType(@NotNull final IElementType elementType, E[] array) {
final int count = countChildren(elementType);
@@ -113,6 +114,7 @@ public abstract class StubBase<T extends PsiElement> extends ObjectStubBase<Stub
return array;
}
@NotNull
@Override
public <E extends PsiElement> E[] getChildrenByType(@NotNull final TokenSet filter, E[] array) {
final int count = countChildren(filter);
@@ -124,6 +126,7 @@ public abstract class StubBase<T extends PsiElement> extends ObjectStubBase<Stub
return array;
}
@NotNull
@Override
public <E extends PsiElement> E[] getChildrenByType(@NotNull final IElementType elementType, @NotNull final ArrayFactory<E> f) {
int count = countChildren(elementType);
@@ -182,6 +185,7 @@ public abstract class StubBase<T extends PsiElement> extends ObjectStubBase<Stub
assert count == result.length;
}
@NotNull
@Override
public <E extends PsiElement> E[] getChildrenByType(@NotNull final TokenSet filter, @NotNull final ArrayFactory<E> f) {
final int count = countChildren(filter);
@@ -38,14 +38,18 @@ public interface StubElement<T extends PsiElement> extends Stub {
List<StubElement> getChildrenStubs();
@Nullable
<P extends PsiElement> StubElement<P> findChildStubByType(IStubElementType<?, P> elementType);
<P extends PsiElement> StubElement<P> findChildStubByType(@NotNull IStubElementType<?, P> elementType);
T getPsi();
@NotNull
<E extends PsiElement> E[] getChildrenByType(@NotNull IElementType elementType, final E[] array);
@NotNull
<E extends PsiElement> E[] getChildrenByType(@NotNull TokenSet filter, final E[] array);
@NotNull
<E extends PsiElement> E[] getChildrenByType(@NotNull IElementType elementType, @NotNull ArrayFactory<E> f);
@NotNull
<E extends PsiElement> E[] getChildrenByType(@NotNull TokenSet filter, @NotNull ArrayFactory<E> f);
@Nullable
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2016 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.
@@ -22,13 +22,15 @@ package com.intellij.psi.stubs;
import com.intellij.psi.PsiElement;
import com.intellij.util.indexing.ID;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
public final class StubIndexKey<K, Psi extends PsiElement> extends ID<K, Psi> {
private StubIndexKey(@NonNls String name) {
super(name);
}
public static synchronized <K, Psi extends PsiElement> StubIndexKey<K, Psi> createIndexKey(@NonNls String name) {
@NotNull
public static synchronized <K, Psi extends PsiElement> StubIndexKey<K, Psi> createIndexKey(@NonNls @NotNull String name) {
return new StubIndexKey<K, Psi>(name);
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
* Copyright 2000-2016 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.
@@ -15,7 +15,10 @@
*/
package com.intellij.psi.stubs;
import com.intellij.util.io.*;
import com.intellij.util.io.AbstractStringEnumerator;
import com.intellij.util.io.DataInputOutputUtil;
import com.intellij.util.io.DataOutputStream;
import com.intellij.util.io.IOUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -29,7 +32,7 @@ public class StubOutputStream extends DataOutputStream {
private final AbstractStringEnumerator myNameStorage;
private final byte[] myStringIOBuffer = IOUtil.allocReadWriteUTFBuffer();
public StubOutputStream(OutputStream out, AbstractStringEnumerator nameStorage) {
public StubOutputStream(@NotNull OutputStream out, @NotNull AbstractStringEnumerator nameStorage) {
super(out);
myNameStorage = nameStorage;
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
* Copyright 2000-2016 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.
@@ -15,13 +15,15 @@
*/
package com.intellij.psi.stubs;
import org.jetbrains.annotations.NotNull;
/**
* Author: dmitrylomov
*/
public abstract class StubSerializationUtil {
private StubSerializationUtil() {}
public static ObjectStubSerializer getSerializer(Stub rootStub) {
public static ObjectStubSerializer getSerializer(@NotNull Stub rootStub) {
if (rootStub instanceof PsiFileStub) {
final PsiFileStub fileStub = (PsiFileStub)rootStub;
return fileStub.getType();
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2016 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.
@@ -33,7 +33,7 @@ import java.io.*;
public class ID<K, V> {
private static final TIntObjectHashMap<ID> ourRegistry = new TIntObjectHashMap<ID>();
private static final TObjectIntHashMap<String> ourNameToIdRegistry = new TObjectIntHashMap<String>();
public static final int MAX_NUMBER_OF_INDICES = Short.MAX_VALUE;
static final int MAX_NUMBER_OF_INDICES = Short.MAX_VALUE;
private final String myName;
private final short myUniqueId;
@@ -119,7 +119,7 @@ public class ID<K, V> {
}
}
public static <K, V> ID<K, V> create(@NonNls String name) {
public static <K, V> ID<K, V> create(@NonNls @NotNull String name) {
final ID<K, V> found = findByName(name);
return found != null ? found : new ID<K, V>(name);
}
@@ -138,7 +138,7 @@ public class StubBasedPsiElementBase<T extends StubElement> extends ASTDelegateP
return node;
}
private ASTNode failedToBindStubToAst(PsiFileImpl file, FileElement fileElement) {
private ASTNode failedToBindStubToAst(@NotNull PsiFileImpl file, @NotNull FileElement fileElement) {
VirtualFile vFile = file.getVirtualFile();
StubTree stubTree = file.getStubTree();
String stubString = stubTree != null ? ((PsiFileStubImpl)stubTree.getRoot()).printTree() : "is null";
@@ -159,7 +159,8 @@ public class StubBasedPsiElementBase<T extends StubElement> extends ASTDelegateP
throw new IllegalArgumentException(message);
}
private String dumpCreationTraces(FileElement fileElement) {
@NotNull
private String dumpCreationTraces(@NotNull FileElement fileElement) {
final StringBuilder traces = new StringBuilder("\nNow " + Thread.currentThread() + "\n");
traces.append("My creation trace:\n").append(getUserData(CREATION_TRACE));
traces.append("AST creation traces:\n");
@@ -180,7 +181,8 @@ public class StubBasedPsiElementBase<T extends StubElement> extends ASTDelegateP
return traces.toString();
}
private ASTNode notBoundInExistingAst(PsiFileImpl file, FileElement treeElement) {
@SuppressWarnings({"NonConstantStringShouldBeStringBuffer", "StringConcatenationInLoop"})
private ASTNode notBoundInExistingAst(@NotNull PsiFileImpl file, @NotNull FileElement treeElement) {
String message = "file=" + file + "; tree=" + treeElement;
PsiElement each = this;
while (each != null) {
@@ -188,7 +190,8 @@ public class StubBasedPsiElementBase<T extends StubElement> extends ASTDelegateP
if (each instanceof StubBasedPsiElementBase) {
message += "; node=" + ((StubBasedPsiElementBase)each).myNode + "; stub=" + ((StubBasedPsiElementBase)each).myStub;
each = ((StubBasedPsiElementBase)each).getParentByStub();
} else {
}
else {
if (each instanceof PsiFile) {
message += "; same file=" + (each == file) + "; current tree= " + file.getTreeElement() + "; stubTree=" + file.getStubTree() + "; physical=" + file.isPhysical();
}
@@ -383,7 +386,7 @@ public class StubBasedPsiElementBase<T extends StubElement> extends ASTDelegateP
* @return a child of specified type, taken from stubs (if this element is currently stub-based) or AST (otherwise).
*/
@Nullable
public <Psi extends PsiElement> Psi getStubOrPsiChild(final IStubElementType<? extends StubElement, Psi> elementType) {
public <Psi extends PsiElement> Psi getStubOrPsiChild(@NotNull IStubElementType<? extends StubElement, Psi> elementType) {
T stub = myStub;
if (stub != null) {
//noinspection unchecked
@@ -406,7 +409,7 @@ public class StubBasedPsiElementBase<T extends StubElement> extends ASTDelegateP
* @return a not-null child of specified type, taken from stubs (if this element is currently stub-based) or AST (otherwise).
*/
@NotNull
public <S extends StubElement, Psi extends PsiElement> Psi getRequiredStubOrPsiChild(final IStubElementType<S, Psi> elementType) {
public <S extends StubElement, Psi extends PsiElement> Psi getRequiredStubOrPsiChild(@NotNull IStubElementType<S, Psi> elementType) {
Psi result = getStubOrPsiChild(elementType);
assert result != null: "Missing required child of type " + elementType + "; tree: "+DebugUtil.psiToString(this, false);
return result;
@@ -415,7 +418,8 @@ public class StubBasedPsiElementBase<T extends StubElement> extends ASTDelegateP
/**
* @return children of specified type, taken from stubs (if this element is currently stub-based) or AST (otherwise).
*/
public <S extends StubElement, Psi extends PsiElement> Psi[] getStubOrPsiChildren(final IStubElementType<S, Psi> elementType, Psi[] array) {
@NotNull
public <S extends StubElement, Psi extends PsiElement> Psi[] getStubOrPsiChildren(@NotNull IStubElementType<S, Psi> elementType, @NotNull Psi[] array) {
T stub = myStub;
if (stub != null) {
//noinspection unchecked
@@ -436,7 +440,8 @@ public class StubBasedPsiElementBase<T extends StubElement> extends ASTDelegateP
/**
* @return children of specified type, taken from stubs (if this element is currently stub-based) or AST (otherwise).
*/
public <S extends StubElement, Psi extends PsiElement> Psi[] getStubOrPsiChildren(final IStubElementType<S, Psi> elementType, ArrayFactory<Psi> f) {
@NotNull
public <S extends StubElement, Psi extends PsiElement> Psi[] getStubOrPsiChildren(@NotNull IStubElementType<S, Psi> elementType, @NotNull ArrayFactory<Psi> f) {
T stub = myStub;
if (stub != null) {
//noinspection unchecked
@@ -456,7 +461,8 @@ public class StubBasedPsiElementBase<T extends StubElement> extends ASTDelegateP
/**
* @return children of specified type, taken from stubs (if this element is currently stub-based) or AST (otherwise).
*/
public <Psi extends PsiElement> Psi[] getStubOrPsiChildren(TokenSet filter, Psi[] array) {
@NotNull
public <Psi extends PsiElement> Psi[] getStubOrPsiChildren(@NotNull TokenSet filter, @NotNull Psi[] array) {
T stub = myStub;
if (stub != null) {
//noinspection unchecked
@@ -477,7 +483,8 @@ public class StubBasedPsiElementBase<T extends StubElement> extends ASTDelegateP
/**
* @return children of specified type, taken from stubs (if this element is currently stub-based) or AST (otherwise).
*/
public <Psi extends PsiElement> Psi[] getStubOrPsiChildren(TokenSet filter, ArrayFactory<Psi> f) {
@NotNull
public <Psi extends PsiElement> Psi[] getStubOrPsiChildren(@NotNull TokenSet filter, @NotNull ArrayFactory<Psi> f) {
T stub = myStub;
if (stub != null) {
//noinspection unchecked
@@ -498,7 +505,7 @@ public class StubBasedPsiElementBase<T extends StubElement> extends ASTDelegateP
* @return a first ancestor of specified type, in stub hierarchy (if this element is currently stub-based) or AST hierarchy (otherwise).
*/
@Nullable
protected <E extends PsiElement> E getStubOrPsiParentOfType(final Class<E> parentClass) {
protected <E extends PsiElement> E getStubOrPsiParentOfType(@NotNull Class<E> parentClass) {
T stub = myStub;
if (stub != null) {
//noinspection unchecked
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2015 JetBrains s.r.o.
* Copyright 2000-2016 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.
@@ -158,7 +158,8 @@ public class SharedImplUtil {
return node.getTreeParent().getPsi().getManager();
}
public static ASTNode[] getChildrenOfType(ASTNode node, IElementType elementType) {
@NotNull
public static ASTNode[] getChildrenOfType(@NotNull ASTNode node, @NotNull IElementType elementType) {
int count = countChildrenOfType(node, elementType);
if (count == 0) {
return ASTNode.EMPTY_ARRAY;
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2015 JetBrains s.r.o.
* Copyright 2000-2016 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.
@@ -72,6 +72,7 @@ public class PsiFileStubImpl<T extends PsiFile> extends StubBase<T> implements P
return null;
}
@NotNull
@Override
public IStubFileElementType getType() {
return TYPE;
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2016 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.
@@ -19,6 +19,7 @@ import com.intellij.psi.stubs.PsiFileStubImpl;
import com.intellij.psi.tree.IStubFileElementType;
import com.intellij.util.ArrayUtil;
import com.intellij.util.io.StringRef;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.plugins.groovy.lang.parser.GroovyParserDefinition;
import org.jetbrains.plugins.groovy.lang.psi.GroovyFile;
import org.jetbrains.plugins.groovy.lang.psi.api.toplevel.packaging.GrPackageDefinition;
@@ -50,6 +51,7 @@ public class GrFileStub extends PsiFileStubImpl<GroovyFile> {
myAnnotations = annotations;
}
@NotNull
@Override
public IStubFileElementType getType() {
return GroovyParserDefinition.GROOVY_FILE;
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2016 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.
@@ -24,6 +24,7 @@ import com.jetbrains.python.psi.FutureFeature;
import com.jetbrains.python.psi.PyFile;
import com.jetbrains.python.psi.impl.PyFileImpl;
import com.jetbrains.python.psi.stubs.PyFileStub;
import org.jetbrains.annotations.NotNull;
import java.util.BitSet;
import java.util.List;
@@ -72,6 +73,7 @@ public class PyFileStubImpl extends PsiFileStubImpl<PyFile> implements PyFileStu
return myDeprecationMessage == null ? null : myDeprecationMessage.getString();
}
@NotNull
@Override
public IStubFileElementType getType() {
return (IStubFileElementType) LanguageParserDefinitions.INSTANCE.forLanguage(PythonLanguage.getInstance()).getFileNodeType();
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
* Copyright 2000-2016 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.
@@ -17,6 +17,7 @@ package com.intellij.util.xml.stubs;
import com.intellij.psi.stubs.ObjectStubSerializer;
import com.intellij.util.io.StringRef;
import org.jetbrains.annotations.NotNull;
import java.util.Collections;
import java.util.List;
@@ -38,6 +39,7 @@ public class AttributeStub extends DomStub {
return myValue;
}
@NotNull
@Override
public List<DomStub> getChildrenStubs() {
return Collections.emptyList();
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2016 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.
@@ -51,6 +51,7 @@ public abstract class DomStub extends ObjectStubBase<DomStub> {
myLocalName = localName;
}
@NotNull
@Override
public abstract List<DomStub> getChildrenStubs();
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2016 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.
@@ -56,6 +56,7 @@ public class ElementStub extends DomStub {
myChildren.add(child);
}
@NotNull
@Override
public List<DomStub> getChildrenStubs() {
return myChildren;
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2015 JetBrains s.r.o.
* Copyright 2000-2016 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.
@@ -36,6 +36,7 @@ import com.intellij.util.xml.impl.DomApplicationComponent;
import com.intellij.util.xml.impl.DomManagerImpl;
import com.intellij.util.xml.stubs.FileStub;
import com.intellij.xml.util.XmlUtil;
import org.jetbrains.annotations.NotNull;
/**
* @author Dmitry Avdeev
@@ -45,7 +46,7 @@ public class DomStubBuilder implements BinaryFileStubBuilder {
private static final Logger LOG = Logger.getInstance(DomStubBuilder.class);
@Override
public boolean acceptsFile(VirtualFile file) {
public boolean acceptsFile(@NotNull VirtualFile file) {
FileType fileType = file.getFileType();
return fileType == XmlFileType.INSTANCE && !FileBasedIndexImpl.isProjectOrWorkspaceFile(file, fileType);
}