下面列出了怎么用com.intellij.psi.StubBasedPsiElement的API类实例代码及写法,或者点击链接到github查看源代码。
@Nullable
@Override
public Icon getIcon(@NotNull PsiElement element, int flags) {
if (element instanceof StubBasedPsiElement) {
return ICONS_BY_STUB_ELEMENT_TYPE.get(
((StubBasedPsiElement<? extends StubElement<?>>) element).getElementType());
}
ASTNode node = element.getNode();
if (node == null) {
return null;
}
IElementType elementType = node.getElementType();
if (!(elementType instanceof SoyElementType)) {
return null;
}
if (elementType == SoyTypes.VARIABLE_DEFINITION_IDENTIFIER) {
elementType = maybeGetVariableDefinitionElementType(element, elementType);
}
Icon icon = ICONS_BY_ELEMENT_TYPE.get(elementType);
return icon == null ? SoyIcons.FILE : icon;
}
@Nullable
private StubElement createStub(StubElement parentStub, ASTNode node) {
IElementType nodeType = node.getElementType();
if (nodeType instanceof IStubElementType) {
final IStubElementType type = (IStubElementType)nodeType;
if (type.shouldCreateStub(node)) {
PsiElement element = node.getPsi();
if (!(element instanceof StubBasedPsiElement)) {
LOG.error("Non-StubBasedPsiElement requests stub creation. Stub type: " + type + ", PSI: " + element);
}
@SuppressWarnings("unchecked") StubElement stub = type.createStub(element, parentStub);
//noinspection ConstantConditions
LOG.assertTrue(stub != null, element);
return stub;
}
}
return null;
}
@Nullable
private static Object findClosestPsiElement(@Nonnull PsiElement element, @Nonnull TreePath adjusted, @Nonnull TreeModel treeModel) {
TextRange range = element.getTextRange();
if (range == null) return null;
Object parent = adjusted.getLastPathComponent();
int minDistance = 0;
Object minChild = null;
for (int i = 0, count = treeModel.getChildCount(parent); i < count; i++) {
Object child = treeModel.getChild(parent, i);
Object value = StructureViewComponent.unwrapValue(child);
if (value instanceof StubBasedPsiElement && ((StubBasedPsiElement)value).getStub() != null) continue;
TextRange r = value instanceof PsiElement ? ((PsiElement)value).getTextRange() : null;
if (r == null) continue;
int distance = TextRangeUtil.getDistance(range, r);
if (minChild == null || distance < minDistance) {
minDistance = distance;
minChild = child;
}
}
return minChild;
}
@Override
@RequiredReadAction
public boolean isMemberInplaceRenameAvailable(PsiElement element, PsiElement context)
{
if(element instanceof DotNetParameter && element instanceof StubBasedPsiElement)
{
return true;
}
if(element instanceof CSharpTypeDeclaration && ((CSharpTypeDeclaration) element).hasModifier(CSharpModifier.PARTIAL))
{
return false;
}
return element instanceof DotNetQualifiedElement && !(element instanceof DotNetNamespaceAsElement);
}
public int getStubIndex(@Nonnull StubBasedPsiElement psi) {
return myNodes.indexOf((CompositeElement)psi.getNode());
}