Files
openide/java/java-psi-impl/src/com/intellij/psi/stub/JavaStubImplUtil.java
Dmitry Batkovich 86829cac3e java property index
2017-09-06 10:40:47 +03:00

46 lines
1.6 KiB
Java

/*
* Copyright 2000-2017 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.psi.stub;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiMethod;
import com.intellij.psi.impl.source.PsiFileImpl;
import com.intellij.psi.impl.source.PsiMethodImpl;
import com.intellij.psi.impl.source.tree.JavaElementType;
import com.intellij.psi.stubs.StubElement;
import com.intellij.psi.stubs.StubTree;
import com.intellij.util.ArrayUtil;
public class JavaStubImplUtil {
public static int getMethodStubIndex(PsiMethod method) {
if (!(method instanceof PsiMethodImpl)) return -1;
PsiFileImpl file = (PsiFileImpl)method.getContainingFile();
if (file.getElementTypeForStubBuilder() == null) return -1;
StubTree stubTree = file.getStubTree();
if (stubTree == null) {
stubTree = file.calcStubTree();
}
PsiElement[] stubs = stubTree
.getPlainList()
.stream()
.filter(e -> e.getStubType() == JavaElementType.METHOD)
.map(StubElement::getPsi)
.toArray(PsiElement[]::new);
return ArrayUtil.indexOf(stubs, method);
}
}