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

项目:intellij-ce-playground    文件:InstanceOfLeftPartTypeGetter.java   
public static PsiType[] getLeftTypes(PsiElement context) {
  if((context = FilterUtil.getPreviousElement(context, true)) == null) return PsiType.EMPTY_ARRAY;
  if(!PsiKeyword.INSTANCEOF.equals(context.getText())) return PsiType.EMPTY_ARRAY;
  if((context = FilterUtil.getPreviousElement(context, false)) == null) return PsiType.EMPTY_ARRAY;

  final PsiExpression contextOfType = PsiTreeUtil.getContextOfType(context, PsiExpression.class, false);
  if (contextOfType == null) return PsiType.EMPTY_ARRAY;

  PsiType type = contextOfType.getType();
  if (type == null) return PsiType.EMPTY_ARRAY;

  if (type instanceof PsiClassType) {
    final PsiClass psiClass = ((PsiClassType)type).resolve();
    if (psiClass instanceof PsiTypeParameter) {
      return psiClass.getExtendsListTypes();
    }
  }

  return new PsiType[]{type};
}
项目:intellij-ce-playground    文件:AssignableFromFilter.java   
public static boolean isAcceptable(PsiElement element, PsiElement context, PsiType expectedType, PsiSubstitutor substitutor) {
  if (element instanceof PsiMethod && isReturnTypeInferrable((PsiMethod)element, context, expectedType, substitutor)) {
    return true;
  }

  PsiType typeByElement = FilterUtil.getTypeByElement(element, context);
  if (typeByElement == null) {
    return false;
  }

  if(substitutor != null) {
    typeByElement = substitutor.substitute(typeByElement);
  }

  if (!allowBoxing(context) && (expectedType instanceof PsiPrimitiveType != typeByElement instanceof PsiPrimitiveType)) {
    return false;
  }

  return expectedType.isAssignableFrom(typeByElement);
}
项目:tools-idea    文件:InstanceOfLeftPartTypeGetter.java   
public static PsiType[] getLeftTypes(PsiElement context) {
  if((context = FilterUtil.getPreviousElement(context, true)) == null) return PsiType.EMPTY_ARRAY;
  if(!PsiKeyword.INSTANCEOF.equals(context.getText())) return PsiType.EMPTY_ARRAY;
  if((context = FilterUtil.getPreviousElement(context, false)) == null) return PsiType.EMPTY_ARRAY;

  final PsiExpression contextOfType = PsiTreeUtil.getContextOfType(context, PsiExpression.class, false);
  if (contextOfType == null) return PsiType.EMPTY_ARRAY;

  PsiType type = contextOfType.getType();
  if (type == null) return PsiType.EMPTY_ARRAY;

  if (type instanceof PsiClassType) {
    final PsiClass psiClass = ((PsiClassType)type).resolve();
    if (psiClass instanceof PsiTypeParameter) {
      return psiClass.getExtendsListTypes();
    }
  }

  return new PsiType[]{type};
}
项目:tools-idea    文件:AssignableFromFilter.java   
public static boolean isAcceptable(PsiElement element, PsiElement context, PsiType expectedType, PsiSubstitutor substitutor) {
  if (element instanceof PsiMethod && isReturnTypeInferrable((PsiMethod)element, context, expectedType, substitutor)) {
    return true;
  }

  PsiType typeByElement = FilterUtil.getTypeByElement(element, context);
  if (typeByElement == null) {
    return false;
  }

  if(substitutor != null) {
    typeByElement = substitutor.substitute(typeByElement);
  }

  if (!allowBoxing(context) && (expectedType instanceof PsiPrimitiveType != typeByElement instanceof PsiPrimitiveType)) {
    return false;
  }

  return expectedType.isAssignableFrom(typeByElement);
}
项目:tools-idea    文件:AssignableToFilter.java   
@Override
public boolean isAcceptable(Object element, PsiElement context){
  if(myType != null){
    if(element == null) return false;
    if (element instanceof PsiType) return myType.isAssignableFrom((PsiType) element);
    PsiSubstitutor substitutor = null;
    if(element instanceof CandidateInfo){
      final CandidateInfo info = (CandidateInfo)element;
      substitutor = info.getSubstitutor();
      element = info.getElement();
    }

    PsiType typeByElement = FilterUtil.getTypeByElement((PsiElement)element, context);
    if(substitutor != null) typeByElement = substitutor.substitute(typeByElement);
    return typeByElement != null && typeByElement.isAssignableFrom(myType) && !typeByElement.equals(myType);
  }
  else if(myFilter != null){
    if(element == null) return false;
    return myFilter.isAcceptable(element, context);
  }
  else return false;
}
项目:consulo-java    文件:InstanceOfLeftPartTypeGetter.java   
public static PsiType[] getLeftTypes(PsiElement context) {
  if((context = FilterUtil.getPreviousElement(context, true)) == null) return PsiType.EMPTY_ARRAY;
  if(!PsiKeyword.INSTANCEOF.equals(context.getText())) return PsiType.EMPTY_ARRAY;
  if((context = FilterUtil.getPreviousElement(context, false)) == null) return PsiType.EMPTY_ARRAY;

  final PsiExpression contextOfType = PsiTreeUtil.getContextOfType(context, PsiExpression.class, false);
  if (contextOfType == null) return PsiType.EMPTY_ARRAY;

  PsiType type = contextOfType.getType();
  if (type == null) return PsiType.EMPTY_ARRAY;

  if (type instanceof PsiClassType) {
    final PsiClass psiClass = ((PsiClassType)type).resolve();
    if (psiClass instanceof PsiTypeParameter) {
      return psiClass.getExtendsListTypes();
    }
  }

  return new PsiType[]{type};
}
项目:consulo-java    文件:AssignableFromFilter.java   
public static boolean isAcceptable(PsiElement element, PsiElement context, PsiType expectedType, PsiSubstitutor substitutor) {
  if (element instanceof PsiMethod && isReturnTypeInferrable((PsiMethod)element, context, expectedType, substitutor)) {
    return true;
  }

  PsiType typeByElement = FilterUtil.getTypeByElement(element, context);
  if (typeByElement == null) {
    return false;
  }

  if(substitutor != null) {
    typeByElement = substitutor.substitute(typeByElement);
  }

  if (!allowBoxing(context) && (expectedType instanceof PsiPrimitiveType != typeByElement instanceof PsiPrimitiveType)) {
    return false;
  }

  return expectedType.isAssignableFrom(typeByElement);
}
项目:consulo-java    文件:AssignableToFilter.java   
@Override
public boolean isAcceptable(Object element, PsiElement context)
{
    if(element == null)
    {
        return false;
    }
    if(element instanceof PsiType)
    {
        return myType.isAssignableFrom((PsiType) element);
    }
    PsiSubstitutor substitutor = null;
    if(element instanceof CandidateInfo)
    {
        final CandidateInfo info = (CandidateInfo) element;
        substitutor = info.getSubstitutor();
        element = info.getElement();
    }

    PsiType typeByElement = FilterUtil.getTypeByElement((PsiElement) element, context);
    if(substitutor != null)
    {
        typeByElement = substitutor.substitute(typeByElement);
    }
    return typeByElement != null && typeByElement.isAssignableFrom(myType) && !typeByElement.equals(myType);
}
项目:intellij-ce-playground    文件:AssignableToFilter.java   
@Override
public boolean isAcceptable(Object element, PsiElement context){
  if(element == null) return false;
  if (element instanceof PsiType) return myType.isAssignableFrom((PsiType) element);
  PsiSubstitutor substitutor = null;
  if(element instanceof CandidateInfo){
    final CandidateInfo info = (CandidateInfo)element;
    substitutor = info.getSubstitutor();
    element = info.getElement();
  }

  PsiType typeByElement = FilterUtil.getTypeByElement((PsiElement)element, context);
  if(substitutor != null) typeByElement = substitutor.substitute(typeByElement);
  return typeByElement != null && typeByElement.isAssignableFrom(myType) && !typeByElement.equals(myType);
}
项目:intellij-ce-playground    文件:KeywordLookupItem.java   
@Override
public PsiType getType() {
  return FilterUtil.getKeywordItemType(myPosition, getLookupString());
}
项目:intellij-ce-playground    文件:StartElementFilter.java   
@Override
public boolean isAcceptable(Object element, PsiElement context){
  if (!(element instanceof PsiElement)) return false;
  return FilterUtil.getPreviousElement((PsiElement) element, false) == null;
}
项目:tools-idea    文件:KeywordLookupItem.java   
@Override
public PsiType getType() {
  return FilterUtil.getKeywordItemType(myPosition, getLookupString());
}
项目:tools-idea    文件:StartElementFilter.java   
@Override
public boolean isAcceptable(Object element, PsiElement context){
  if (!(element instanceof PsiElement)) return false;
  return FilterUtil.getPreviousElement((PsiElement) element, false) == null;
}
项目:consulo-java    文件:KeywordLookupItem.java   
@Override
public PsiType getType() {
  return FilterUtil.getKeywordItemType(myPosition, getLookupString());
}
项目:consulo-java    文件:StartElementFilter.java   
@Override
public boolean isAcceptable(Object element, PsiElement context){
  if (!(element instanceof PsiElement)) return false;
  return FilterUtil.getPreviousElement((PsiElement) element, false) == null;
}