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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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.PsiClass;
import com.intellij.psi.PsiFile; import com.intellij.psi.PsiFile;
import org.jetbrains.annotations.NotNull;
/** /**
* @author ilyas * @author ilyas
*/ */
public interface PsiClassHolderFileStub<T extends PsiFile> extends PsiFileStub<T> { public interface PsiClassHolderFileStub<T extends PsiFile> extends PsiFileStub<T> {
@NotNull
PsiClass[] getClasses(); 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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 @Override
public String getId(final PsiClassStub stub) { public String getId(@NotNull final PsiClassStub stub) {
final String name = stub.getName(); final String name = stub.getName();
return name != null ? name : super.getId(stub); 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.stubs.PsiFileStubImpl;
import com.intellij.psi.tree.IStubFileElementType; import com.intellij.psi.tree.IStubFileElementType;
import com.intellij.util.io.StringRef; import com.intellij.util.io.StringRef;
import org.jetbrains.annotations.NotNull;
/** /**
* @author max * @author max
@@ -41,11 +42,13 @@ public class PsiJavaFileStubImpl extends PsiFileStubImpl<PsiJavaFile> implements
this(null, StringRef.fromString(packageName), compiled); this(null, StringRef.fromString(packageName), compiled);
} }
@NotNull
@Override @Override
public IStubFileElementType getType() { public IStubFileElementType getType() {
return JavaStubElementTypes.JAVA_FILE; return JavaStubElementTypes.JAVA_FILE;
} }
@NotNull
@Override @Override
public PsiClass[] getClasses() { public PsiClass[] getClasses() {
return getChildrenByType(JavaStubElementTypes.CLASS, PsiClass.ARRAY_FACTORY); 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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.openapi.vfs.VirtualFile;
import com.intellij.util.indexing.FileContent; import com.intellij.util.indexing.FileContent;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
/** /**
* @see com.intellij.psi.stubs.BinaryFileStubBuilders#EXTENSION_POINT_NAME * @see com.intellij.psi.stubs.BinaryFileStubBuilders#EXTENSION_POINT_NAME
*/ */
public interface BinaryFileStubBuilder { public interface BinaryFileStubBuilder {
boolean acceptsFile(VirtualFile file); boolean acceptsFile(@NotNull VirtualFile file);
@Nullable @Nullable
Stub buildStubTree(FileContent fileContent); 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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; return true;
} }
public String getId(StubT stub) { public String getId(@NotNull StubT stub) {
assert stub.getStubType() == this; assert stub.getStubType() == this;
final StubElement parent = stub.getParentStub(); 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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; myParent = parent;
} }
@Override
public T getParentStub() { public T getParentStub() {
return myParent; 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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 { public interface PsiFileStub<T extends PsiFile> extends StubElement<T>, UserDataHolder {
PsiFileStub[] EMPTY_ARRAY = new PsiFileStub[0]; PsiFileStub[] EMPTY_ARRAY = new PsiFileStub[0];
@NotNull
StubFileElementType getType(); StubFileElementType getType();
@NotNull @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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -15,6 +15,8 @@
*/ */
package com.intellij.psi.stubs; package com.intellij.psi.stubs;
import org.jetbrains.annotations.NotNull;
import java.util.List; import java.util.List;
/** /**
@@ -22,8 +24,8 @@ import java.util.List;
* Date: 8/2/12 * Date: 8/2/12
*/ */
public interface Stub { public interface Stub {
Stub getParentStub(); Stub getParentStub();
@NotNull
List<? extends Stub> getChildrenStubs(); List<? extends Stub> getChildrenStubs();
ObjectStubSerializer getStubType(); ObjectStubSerializer getStubType();
@@ -64,7 +64,7 @@ public abstract class StubBase<T extends PsiElement> extends ObjectStubBase<Stub
@Override @Override
@Nullable @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 List<StubElement> childrenStubs = getChildrenStubs();
final int size = childrenStubs.size(); final int size = childrenStubs.size();
@@ -102,6 +102,7 @@ public abstract class StubBase<T extends PsiElement> extends ObjectStubBase<Stub
} }
@NotNull
@Override @Override
public <E extends PsiElement> E[] getChildrenByType(@NotNull final IElementType elementType, E[] array) { public <E extends PsiElement> E[] getChildrenByType(@NotNull final IElementType elementType, E[] array) {
final int count = countChildren(elementType); final int count = countChildren(elementType);
@@ -113,6 +114,7 @@ public abstract class StubBase<T extends PsiElement> extends ObjectStubBase<Stub
return array; return array;
} }
@NotNull
@Override @Override
public <E extends PsiElement> E[] getChildrenByType(@NotNull final TokenSet filter, E[] array) { public <E extends PsiElement> E[] getChildrenByType(@NotNull final TokenSet filter, E[] array) {
final int count = countChildren(filter); final int count = countChildren(filter);
@@ -124,6 +126,7 @@ public abstract class StubBase<T extends PsiElement> extends ObjectStubBase<Stub
return array; return array;
} }
@NotNull
@Override @Override
public <E extends PsiElement> E[] getChildrenByType(@NotNull final IElementType elementType, @NotNull final ArrayFactory<E> f) { public <E extends PsiElement> E[] getChildrenByType(@NotNull final IElementType elementType, @NotNull final ArrayFactory<E> f) {
int count = countChildren(elementType); int count = countChildren(elementType);
@@ -182,6 +185,7 @@ public abstract class StubBase<T extends PsiElement> extends ObjectStubBase<Stub
assert count == result.length; assert count == result.length;
} }
@NotNull
@Override @Override
public <E extends PsiElement> E[] getChildrenByType(@NotNull final TokenSet filter, @NotNull final ArrayFactory<E> f) { public <E extends PsiElement> E[] getChildrenByType(@NotNull final TokenSet filter, @NotNull final ArrayFactory<E> f) {
final int count = countChildren(filter); final int count = countChildren(filter);
@@ -38,14 +38,18 @@ public interface StubElement<T extends PsiElement> extends Stub {
List<StubElement> getChildrenStubs(); List<StubElement> getChildrenStubs();
@Nullable @Nullable
<P extends PsiElement> StubElement<P> findChildStubByType(IStubElementType<?, P> elementType); <P extends PsiElement> StubElement<P> findChildStubByType(@NotNull IStubElementType<?, P> elementType);
T getPsi(); T getPsi();
@NotNull
<E extends PsiElement> E[] getChildrenByType(@NotNull IElementType elementType, final E[] array); <E extends PsiElement> E[] getChildrenByType(@NotNull IElementType elementType, final E[] array);
@NotNull
<E extends PsiElement> E[] getChildrenByType(@NotNull TokenSet filter, final E[] array); <E extends PsiElement> E[] getChildrenByType(@NotNull TokenSet filter, final E[] array);
@NotNull
<E extends PsiElement> E[] getChildrenByType(@NotNull IElementType elementType, @NotNull ArrayFactory<E> f); <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); <E extends PsiElement> E[] getChildrenByType(@NotNull TokenSet filter, @NotNull ArrayFactory<E> f);
@Nullable @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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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.psi.PsiElement;
import com.intellij.util.indexing.ID; import com.intellij.util.indexing.ID;
import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
public final class StubIndexKey<K, Psi extends PsiElement> extends ID<K, Psi> { public final class StubIndexKey<K, Psi extends PsiElement> extends ID<K, Psi> {
private StubIndexKey(@NonNls String name) { private StubIndexKey(@NonNls String name) {
super(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); 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -15,7 +15,10 @@
*/ */
package com.intellij.psi.stubs; 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.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@@ -29,7 +32,7 @@ public class StubOutputStream extends DataOutputStream {
private final AbstractStringEnumerator myNameStorage; private final AbstractStringEnumerator myNameStorage;
private final byte[] myStringIOBuffer = IOUtil.allocReadWriteUTFBuffer(); private final byte[] myStringIOBuffer = IOUtil.allocReadWriteUTFBuffer();
public StubOutputStream(OutputStream out, AbstractStringEnumerator nameStorage) { public StubOutputStream(@NotNull OutputStream out, @NotNull AbstractStringEnumerator nameStorage) {
super(out); super(out);
myNameStorage = nameStorage; 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -15,13 +15,15 @@
*/ */
package com.intellij.psi.stubs; package com.intellij.psi.stubs;
import org.jetbrains.annotations.NotNull;
/** /**
* Author: dmitrylomov * Author: dmitrylomov
*/ */
public abstract class StubSerializationUtil { public abstract class StubSerializationUtil {
private StubSerializationUtil() {} private StubSerializationUtil() {}
public static ObjectStubSerializer getSerializer(Stub rootStub) { public static ObjectStubSerializer getSerializer(@NotNull Stub rootStub) {
if (rootStub instanceof PsiFileStub) { if (rootStub instanceof PsiFileStub) {
final PsiFileStub fileStub = (PsiFileStub)rootStub; final PsiFileStub fileStub = (PsiFileStub)rootStub;
return fileStub.getType(); 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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> { public class ID<K, V> {
private static final TIntObjectHashMap<ID> ourRegistry = new TIntObjectHashMap<ID>(); private static final TIntObjectHashMap<ID> ourRegistry = new TIntObjectHashMap<ID>();
private static final TObjectIntHashMap<String> ourNameToIdRegistry = new TObjectIntHashMap<String>(); 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 String myName;
private final short myUniqueId; 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); final ID<K, V> found = findByName(name);
return found != null ? found : new ID<K, V>(name); return found != null ? found : new ID<K, V>(name);
} }
@@ -138,7 +138,7 @@ public class StubBasedPsiElementBase<T extends StubElement> extends ASTDelegateP
return node; return node;
} }
private ASTNode failedToBindStubToAst(PsiFileImpl file, FileElement fileElement) { private ASTNode failedToBindStubToAst(@NotNull PsiFileImpl file, @NotNull FileElement fileElement) {
VirtualFile vFile = file.getVirtualFile(); VirtualFile vFile = file.getVirtualFile();
StubTree stubTree = file.getStubTree(); StubTree stubTree = file.getStubTree();
String stubString = stubTree != null ? ((PsiFileStubImpl)stubTree.getRoot()).printTree() : "is null"; 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); 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"); final StringBuilder traces = new StringBuilder("\nNow " + Thread.currentThread() + "\n");
traces.append("My creation trace:\n").append(getUserData(CREATION_TRACE)); traces.append("My creation trace:\n").append(getUserData(CREATION_TRACE));
traces.append("AST creation traces:\n"); traces.append("AST creation traces:\n");
@@ -180,7 +181,8 @@ public class StubBasedPsiElementBase<T extends StubElement> extends ASTDelegateP
return traces.toString(); 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; String message = "file=" + file + "; tree=" + treeElement;
PsiElement each = this; PsiElement each = this;
while (each != null) { while (each != null) {
@@ -188,7 +190,8 @@ public class StubBasedPsiElementBase<T extends StubElement> extends ASTDelegateP
if (each instanceof StubBasedPsiElementBase) { if (each instanceof StubBasedPsiElementBase) {
message += "; node=" + ((StubBasedPsiElementBase)each).myNode + "; stub=" + ((StubBasedPsiElementBase)each).myStub; message += "; node=" + ((StubBasedPsiElementBase)each).myNode + "; stub=" + ((StubBasedPsiElementBase)each).myStub;
each = ((StubBasedPsiElementBase)each).getParentByStub(); each = ((StubBasedPsiElementBase)each).getParentByStub();
} else { }
else {
if (each instanceof PsiFile) { if (each instanceof PsiFile) {
message += "; same file=" + (each == file) + "; current tree= " + file.getTreeElement() + "; stubTree=" + file.getStubTree() + "; physical=" + file.isPhysical(); 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). * @return a child of specified type, taken from stubs (if this element is currently stub-based) or AST (otherwise).
*/ */
@Nullable @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; T stub = myStub;
if (stub != null) { if (stub != null) {
//noinspection unchecked //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). * @return a not-null child of specified type, taken from stubs (if this element is currently stub-based) or AST (otherwise).
*/ */
@NotNull @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); Psi result = getStubOrPsiChild(elementType);
assert result != null: "Missing required child of type " + elementType + "; tree: "+DebugUtil.psiToString(this, false); assert result != null: "Missing required child of type " + elementType + "; tree: "+DebugUtil.psiToString(this, false);
return result; 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). * @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; T stub = myStub;
if (stub != null) { if (stub != null) {
//noinspection unchecked //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). * @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; T stub = myStub;
if (stub != null) { if (stub != null) {
//noinspection unchecked //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). * @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; T stub = myStub;
if (stub != null) { if (stub != null) {
//noinspection unchecked //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). * @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; T stub = myStub;
if (stub != null) { if (stub != null) {
//noinspection unchecked //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). * @return a first ancestor of specified type, in stub hierarchy (if this element is currently stub-based) or AST hierarchy (otherwise).
*/ */
@Nullable @Nullable
protected <E extends PsiElement> E getStubOrPsiParentOfType(final Class<E> parentClass) { protected <E extends PsiElement> E getStubOrPsiParentOfType(@NotNull Class<E> parentClass) {
T stub = myStub; T stub = myStub;
if (stub != null) { if (stub != null) {
//noinspection unchecked //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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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(); 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); int count = countChildrenOfType(node, elementType);
if (count == 0) { if (count == 0) {
return ASTNode.EMPTY_ARRAY; 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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; return null;
} }
@NotNull
@Override @Override
public IStubFileElementType getType() { public IStubFileElementType getType() {
return TYPE; 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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.psi.tree.IStubFileElementType;
import com.intellij.util.ArrayUtil; import com.intellij.util.ArrayUtil;
import com.intellij.util.io.StringRef; 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.parser.GroovyParserDefinition;
import org.jetbrains.plugins.groovy.lang.psi.GroovyFile; import org.jetbrains.plugins.groovy.lang.psi.GroovyFile;
import org.jetbrains.plugins.groovy.lang.psi.api.toplevel.packaging.GrPackageDefinition; import org.jetbrains.plugins.groovy.lang.psi.api.toplevel.packaging.GrPackageDefinition;
@@ -50,6 +51,7 @@ public class GrFileStub extends PsiFileStubImpl<GroovyFile> {
myAnnotations = annotations; myAnnotations = annotations;
} }
@NotNull
@Override @Override
public IStubFileElementType getType() { public IStubFileElementType getType() {
return GroovyParserDefinition.GROOVY_FILE; 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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.PyFile;
import com.jetbrains.python.psi.impl.PyFileImpl; import com.jetbrains.python.psi.impl.PyFileImpl;
import com.jetbrains.python.psi.stubs.PyFileStub; import com.jetbrains.python.psi.stubs.PyFileStub;
import org.jetbrains.annotations.NotNull;
import java.util.BitSet; import java.util.BitSet;
import java.util.List; import java.util.List;
@@ -72,6 +73,7 @@ public class PyFileStubImpl extends PsiFileStubImpl<PyFile> implements PyFileStu
return myDeprecationMessage == null ? null : myDeprecationMessage.getString(); return myDeprecationMessage == null ? null : myDeprecationMessage.getString();
} }
@NotNull
@Override @Override
public IStubFileElementType getType() { public IStubFileElementType getType() {
return (IStubFileElementType) LanguageParserDefinitions.INSTANCE.forLanguage(PythonLanguage.getInstance()).getFileNodeType(); 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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.psi.stubs.ObjectStubSerializer;
import com.intellij.util.io.StringRef; import com.intellij.util.io.StringRef;
import org.jetbrains.annotations.NotNull;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
@@ -38,6 +39,7 @@ public class AttributeStub extends DomStub {
return myValue; return myValue;
} }
@NotNull
@Override @Override
public List<DomStub> getChildrenStubs() { public List<DomStub> getChildrenStubs() {
return Collections.emptyList(); 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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; myLocalName = localName;
} }
@NotNull
@Override @Override
public abstract List<DomStub> getChildrenStubs(); 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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); myChildren.add(child);
} }
@NotNull
@Override @Override
public List<DomStub> getChildrenStubs() { public List<DomStub> getChildrenStubs() {
return myChildren; 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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.impl.DomManagerImpl;
import com.intellij.util.xml.stubs.FileStub; import com.intellij.util.xml.stubs.FileStub;
import com.intellij.xml.util.XmlUtil; import com.intellij.xml.util.XmlUtil;
import org.jetbrains.annotations.NotNull;
/** /**
* @author Dmitry Avdeev * @author Dmitry Avdeev
@@ -45,7 +46,7 @@ public class DomStubBuilder implements BinaryFileStubBuilder {
private static final Logger LOG = Logger.getInstance(DomStubBuilder.class); private static final Logger LOG = Logger.getInstance(DomStubBuilder.class);
@Override @Override
public boolean acceptsFile(VirtualFile file) { public boolean acceptsFile(@NotNull VirtualFile file) {
FileType fileType = file.getFileType(); FileType fileType = file.getFileType();
return fileType == XmlFileType.INSTANCE && !FileBasedIndexImpl.isProjectOrWorkspaceFile(file, fileType); return fileType == XmlFileType.INSTANCE && !FileBasedIndexImpl.isProjectOrWorkspaceFile(file, fileType);
} }