Java 类com.intellij.psi.filters.FilterPositionUtil 实例源码

项目:intellij-ce-playground    文件:ModifierChooser.java   
private static boolean shouldSuggestModifiers(PsiElement element) {
  PsiElement parent = element.getParent();
  while (parent != null && (parent instanceof PsiJavaCodeReferenceElement ||
                            parent instanceof PsiErrorElement || parent instanceof PsiTypeElement ||
                            parent instanceof PsiMethod || parent instanceof PsiVariable ||
                            parent instanceof PsiDeclarationStatement || parent instanceof PsiImportList ||
                            parent instanceof PsiDocComment ||
                            element.getText().equals(parent.getText()))) {
    parent = parent.getParent();
    if (parent instanceof JspClassLevelDeclarationStatement) {
      parent = parent.getContext();
    }
  }

  if (parent == null) return false;

  PsiElement prev = FilterPositionUtil.searchNonSpaceNonCommentBack(element);

  if (parent instanceof PsiJavaFile || parent instanceof PsiClass) {
    if (prev == null || JavaKeywordCompletion.END_OF_BLOCK.getValue().isAcceptable(element, prev.getParent())) {
      return true;
    }
  }

  return false;
}
项目:intellij-ce-playground    文件:JavaClassNameInsertHandler.java   
private static boolean shouldInsertParentheses(PsiElement position) {
  final PsiJavaCodeReferenceElement ref = PsiTreeUtil.getParentOfType(position, PsiJavaCodeReferenceElement.class);
  if (ref == null) {
    return false;
  }

  final PsiReferenceParameterList parameterList = ref.getParameterList();
  if (parameterList != null && parameterList.getTextLength() > 0) {
    return false;
  }

  final PsiElement prevElement = FilterPositionUtil.searchNonSpaceNonCommentBack(ref);
  if (prevElement != null && prevElement.getParent() instanceof PsiNewExpression) {
    for (ExpectedTypeInfo info : ExpectedTypesProvider.getExpectedTypes((PsiExpression)prevElement.getParent(), true)) {
      if (info.getType() instanceof PsiArrayType) {
        return false;
      }
    }

    return true;
  }

  return false;
}
项目:tools-idea    文件:ModifierChooser.java   
private static boolean shouldSuggestModifiers(PsiElement element) {
  PsiElement parent = element.getParent();
  while (parent != null && (parent instanceof PsiJavaCodeReferenceElement ||
                            parent instanceof PsiErrorElement || parent instanceof PsiTypeElement ||
                            parent instanceof PsiMethod || parent instanceof PsiVariable ||
                            parent instanceof PsiDeclarationStatement || parent instanceof PsiImportList ||
                            parent instanceof PsiDocComment ||
                            element.getText().equals(parent.getText()))) {
    parent = parent.getParent();
    if (parent instanceof JspClassLevelDeclarationStatement) {
      parent = parent.getContext();
    }
  }

  if (parent == null) return false;

  PsiElement prev = FilterPositionUtil.searchNonSpaceNonCommentBack(element);

  if (parent instanceof PsiJavaFile || parent instanceof PsiClass) {
    if (prev == null || JavaCompletionData.END_OF_BLOCK.isAcceptable(element, prev.getParent())) {
      return true;
    }
  }

  return false;
}
项目:tools-idea    文件:JavaClassNameInsertHandler.java   
private static boolean shouldInsertParentheses(PsiElement position) {
  final PsiJavaCodeReferenceElement ref = PsiTreeUtil.getParentOfType(position, PsiJavaCodeReferenceElement.class);
  if (ref == null) {
    return false;
  }

  final PsiReferenceParameterList parameterList = ref.getParameterList();
  if (parameterList != null && parameterList.getTextLength() > 0) {
    return false;
  }

  final PsiElement prevElement = FilterPositionUtil.searchNonSpaceNonCommentBack(ref);
  if (prevElement != null && prevElement.getParent() instanceof PsiNewExpression) {
    for (ExpectedTypeInfo info : ExpectedTypesProvider.getExpectedTypes((PsiExpression)prevElement.getParent(), true)) {
      if (info.getType() instanceof PsiArrayType) {
        return false;
      }
    }

    return true;
  }

  return false;
}
项目:consulo-java    文件:JavaClassNameInsertHandler.java   
private static boolean shouldInsertParentheses(PsiElement position)
{
    final PsiJavaCodeReferenceElement ref = PsiTreeUtil.getParentOfType(position, PsiJavaCodeReferenceElement.class);
    if(ref == null)
    {
        return false;
    }

    final PsiReferenceParameterList parameterList = ref.getParameterList();
    if(parameterList != null && parameterList.getTextLength() > 0)
    {
        return false;
    }

    final PsiElement prevElement = FilterPositionUtil.searchNonSpaceNonCommentBack(ref);
    if(prevElement != null && prevElement.getParent() instanceof PsiNewExpression)
    {
        return !isArrayTypeExpected((PsiExpression) prevElement.getParent());
    }

    return false;
}
项目:intellij-ce-playground    文件:ModifierChooser.java   
@Nullable
public static PsiModifierList findModifierList(@NotNull PsiElement element) {
  if(element.getParent() instanceof PsiModifierList) {
    return (PsiModifierList)element.getParent();
  }

  return PsiTreeUtil.getParentOfType(FilterPositionUtil.searchNonSpaceNonCommentBack(element), PsiModifierList.class);
}
项目:intellij-ce-playground    文件:AfterElement.java   
@Override
public boolean isAcceptable(Object element, @Nullable PsiElement context){
  if (!(element instanceof PsiElement)) return false;
  final PsiElement previous = FilterPositionUtil.searchNonSpaceNonCommentBack((PsiElement) element, true);
  if(previous != null){
    return getFilter().isAcceptable(previous, context);
  }
  return false;
}
项目:intellij-ce-playground    文件:LeftNeighbour.java   
@Override
public boolean isAcceptable(Object element, PsiElement context){
  if (!(element instanceof PsiElement)) return false;
  final PsiElement previous = FilterPositionUtil.searchNonSpaceNonCommentBack((PsiElement) element);
  if(previous != null){
    return getFilter().isAcceptable(previous, context);
  }
  return false;
}
项目:tools-idea    文件:ModifierChooser.java   
@Nullable
public static PsiModifierList findModifierList(@NotNull PsiElement element) {
  if(element.getParent() instanceof PsiModifierList) {
    return (PsiModifierList)element.getParent();
  }

  return PsiTreeUtil.getParentOfType(FilterPositionUtil.searchNonSpaceNonCommentBack(element), PsiModifierList.class);
}
项目:tools-idea    文件:AfterElement.java   
@Override
public boolean isAcceptable(Object element, @Nullable PsiElement context){
  if (!(element instanceof PsiElement)) return false;
  final PsiElement previous = FilterPositionUtil.searchNonSpaceNonCommentBack((PsiElement) element, true);
  if(previous != null){
    return getFilter().isAcceptable(previous, context);
  }
  return false;
}
项目:tools-idea    文件:LeftNeighbour.java   
@Override
public boolean isAcceptable(Object element, PsiElement context){
  if (!(element instanceof PsiElement)) return false;
  final PsiElement previous = FilterPositionUtil.searchNonSpaceNonCommentBack((PsiElement) element);
  if(previous != null){
    return getFilter().isAcceptable(previous, context);
  }
  return false;
}
项目:consulo    文件:AfterElement.java   
@Override
public boolean isAcceptable(Object element, @Nullable PsiElement context){
  if (!(element instanceof PsiElement)) return false;
  final PsiElement previous = FilterPositionUtil.searchNonSpaceNonCommentBack((PsiElement) element, true);
  if(previous != null){
    return getFilter().isAcceptable(previous, context);
  }
  return false;
}
项目:consulo    文件:LeftNeighbour.java   
@Override
public boolean isAcceptable(Object element, PsiElement context){
  if (!(element instanceof PsiElement)) return false;
  final PsiElement previous = FilterPositionUtil.searchNonSpaceNonCommentBack((PsiElement) element);
  if(previous != null){
    return getFilter().isAcceptable(previous, context);
  }
  return false;
}
项目:consulo-java    文件:ModifierChooser.java   
@Nullable
public static PsiModifierList findModifierList(@NotNull PsiElement element)
{
    if(element.getParent() instanceof PsiModifierList)
    {
        return (PsiModifierList) element.getParent();
    }

    return PsiTreeUtil.getParentOfType(FilterPositionUtil.searchNonSpaceNonCommentBack(element), PsiModifierList.class);
}
项目:consulo-java    文件:ModifierChooser.java   
private static boolean shouldSuggestModifiers(PsiElement element)
{
    PsiElement parent = element.getParent();
    while(parent != null && (parent instanceof PsiJavaCodeReferenceElement ||
            parent instanceof PsiErrorElement || parent instanceof PsiTypeElement ||
            parent instanceof PsiMethod || parent instanceof PsiVariable ||
            parent instanceof PsiDeclarationStatement || parent instanceof PsiImportList ||
            parent instanceof PsiDocComment ||
            element.getText().equals(parent.getText())))
    {
        parent = parent.getParent();
        /*if(parent instanceof JspClassLevelDeclarationStatement)
        {
            parent = parent.getContext();
        }   */
    }

    if(parent == null)
    {
        return false;
    }

    PsiElement prev = FilterPositionUtil.searchNonSpaceNonCommentBack(element);

    if(parent instanceof PsiJavaFile || parent instanceof PsiClass)
    {
        if(prev == null || JavaKeywordCompletion.END_OF_BLOCK.getValue().isAcceptable(element, prev.getParent()))
        {
            return true;
        }
    }

    return false;
}
项目:intellij-ce-playground    文件:GroovyCompletionUtil.java   
public static boolean isInPossibleClosureParameter(PsiElement position) { //Closure cl={String x, <caret>...
  if (position == null) return false;

  if (position instanceof PsiWhiteSpace || position.getNode().getElementType() == GroovyTokenTypes.mNLS) {
    position = FilterPositionUtil.searchNonSpaceNonCommentBack(position);
  }

  boolean hasCommas = false;
  while (position != null) {
    PsiElement parent = position.getParent();
    if (parent instanceof GrVariable) {
      PsiElement prev = FilterPositionUtil.searchNonSpaceNonCommentBack(parent);
      hasCommas = prev != null && prev.getNode().getElementType() == GroovyTokenTypes.mCOMMA;
    }

    if (parent instanceof GrClosableBlock) {
      PsiElement sibling = position.getPrevSibling();
      while (sibling != null) {
        if (sibling instanceof GrParameterList) {
          return hasCommas;
        }

        boolean isComma = sibling instanceof LeafPsiElement && GroovyTokenTypes.mCOMMA == ((LeafPsiElement)sibling).getElementType();
        hasCommas |= isComma;

        if (isComma ||
            sibling instanceof PsiWhiteSpace ||
            sibling instanceof PsiErrorElement ||
            sibling instanceof GrVariableDeclaration ||
            sibling instanceof GrReferenceExpression && !((GrReferenceExpression)sibling).isQualified()
          ) {
          sibling = sibling.getPrevSibling();
        }
        else {
          return false;
        }
      }
      return false;
    }
    position = parent;
  }
  return false;
}
项目:tools-idea    文件:GroovyCompletionContributor.java   
public static boolean isInPossibleClosureParameter(PsiElement position) { //Closure cl={String x, <caret>...
  if (position == null) return false;

  if (position instanceof PsiWhiteSpace || position.getNode().getElementType() == mNLS) {
    position = FilterPositionUtil.searchNonSpaceNonCommentBack(position);
  }

  boolean hasCommas = false;
  while (position != null) {
    PsiElement parent = position.getParent();
    if (parent instanceof GrVariable) {
      PsiElement prev = FilterPositionUtil.searchNonSpaceNonCommentBack(parent);
      hasCommas = prev != null && prev.getNode().getElementType() == mCOMMA;
    }

    if (parent instanceof GrClosableBlock) {
      PsiElement sibling = position.getPrevSibling();
      while (sibling != null) {
        if (sibling instanceof GrParameterList) {
          return hasCommas;
        }

        boolean isComma = sibling instanceof LeafPsiElement && mCOMMA == ((LeafPsiElement)sibling).getElementType();
        hasCommas |= isComma;

        if (isComma ||
            sibling instanceof PsiWhiteSpace ||
            sibling instanceof PsiErrorElement ||
            sibling instanceof GrVariableDeclaration ||
            sibling instanceof GrReferenceExpression && !((GrReferenceExpression)sibling).isQualified()
          ) {
          sibling = sibling.getPrevSibling();
        }
        else {
          return false;
        }
      }
      return false;
    }
    position = parent;
  }
  return false;
}