com.intellij.psi.StubBasedPsiElement Java Examples

The following examples show how to use com.intellij.psi.StubBasedPsiElement. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SoyElementIconProvider.java    From bamboo-soy with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example #2
Source File: DefaultStubBuilder.java    From consulo with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example #3
Source File: FileStructurePopup.java    From consulo with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example #4
Source File: CSharpRefactoringSupportProvider.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #5
Source File: AstSpine.java    From consulo with Apache License 2.0 4 votes vote down vote up
public int getStubIndex(@Nonnull StubBasedPsiElement psi) {
  return myNodes.indexOf((CompositeElement)psi.getNode());
}