当前位置: 首页>>代码示例>>Java>>正文


Java CollectionUtils.isCollectionClassOrInterface方法代码示例

本文整理汇总了Java中com.siyeh.ig.psiutils.CollectionUtils.isCollectionClassOrInterface方法的典型用法代码示例。如果您正苦于以下问题:Java CollectionUtils.isCollectionClassOrInterface方法的具体用法?Java CollectionUtils.isCollectionClassOrInterface怎么用?Java CollectionUtils.isCollectionClassOrInterface使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.siyeh.ig.psiutils.CollectionUtils的用法示例。


在下文中一共展示了CollectionUtils.isCollectionClassOrInterface方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: isEmptyCollectionInitializer

import com.siyeh.ig.psiutils.CollectionUtils; //导入方法依赖的package包/类
private static boolean isEmptyCollectionInitializer(PsiExpression initializer) {
  if (!(initializer instanceof PsiNewExpression)) {
    return false;
  }
  final PsiNewExpression newExpression = (PsiNewExpression)initializer;
  final PsiExpressionList argumentList = newExpression.getArgumentList();
  if (argumentList == null) {
    return false;
  }
  final PsiExpression[] arguments = argumentList.getExpressions();
  for (final PsiExpression argument : arguments) {
    final PsiType argumentType = argument.getType();
    if (argumentType == null) {
      return false;
    }
    if (CollectionUtils.isCollectionClassOrInterface(argumentType)) {
      return false;
    }
    if (argumentType instanceof PsiArrayType) {
      return false;
    }
  }
  return true;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:25,代码来源:MismatchedCollectionQueryUpdateInspectionBase.java

示例2: checkVariable

import com.siyeh.ig.psiutils.CollectionUtils; //导入方法依赖的package包/类
private boolean checkVariable(PsiVariable variable, PsiElement context) {
  if (context == null) {
    return false;
  }
  final PsiType type = variable.getType();
  if (!CollectionUtils.isCollectionClassOrInterface(type)) {
    return false;
  }
  if (VariableAccessUtils.variableIsAssignedFrom(variable, context)) {
    return false;
  }
  if (VariableAccessUtils.variableIsReturned(variable, context)) {
    return false;
  }
  return !VariableAccessUtils.variableIsUsedInArrayInitializer(variable, context);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:MismatchedCollectionQueryUpdateInspectionBase.java

示例3: checkVariable

import com.siyeh.ig.psiutils.CollectionUtils; //导入方法依赖的package包/类
private boolean checkVariable(PsiVariable variable, PsiElement context) {
  if (context == null) {
    return false;
  }
  final PsiType type = variable.getType();
  if (!CollectionUtils.isCollectionClassOrInterface(type)) {
    return false;
  }
  if (VariableAccessUtils.variableIsAssignedFrom(variable, context)) {
    return false;
  }
  if (VariableAccessUtils.variableIsReturned(variable, context)) {
    return false;
  }
  if (VariableAccessUtils.variableIsPassedAsMethodArgument(variable, context)) {
    return false;
  }
  return !VariableAccessUtils.variableIsUsedInArrayInitializer(variable, context);
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:20,代码来源:MismatchedCollectionQueryUpdateInspectionBase.java

示例4: visitField

import com.siyeh.ig.psiutils.CollectionUtils; //导入方法依赖的package包/类
@Override
public void visitField(@NotNull PsiField field) {
  super.visitField(field);
  if (!field.hasModifierProperty(PsiModifier.PUBLIC)) {
    return;
  }
  if (!field.hasModifierProperty(PsiModifier.STATIC)) {
    return;
  }
  final PsiType type = field.getType();
  if (!CollectionUtils.isCollectionClassOrInterface(type)) {
    return;
  }
  registerFieldError(field);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:16,代码来源:PublicStaticCollectionFieldInspection.java

示例5: visitField

import com.siyeh.ig.psiutils.CollectionUtils; //导入方法依赖的package包/类
@Override
public void visitField(@NotNull PsiField field) {
  if (!field.hasModifierProperty(PsiModifier.STATIC)) {
    return;
  }
  final PsiType type = field.getType();
  if (!CollectionUtils.isCollectionClassOrInterface(type)) {
    return;
  }
  if (!m_ignoreWeakCollections ||
      CollectionUtils.isWeakCollectionClass(type)) {
    return;
  }
  registerFieldError(field);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:16,代码来源:StaticCollectionInspection.java

示例6: visitMethodCallExpression

import com.siyeh.ig.psiutils.CollectionUtils; //导入方法依赖的package包/类
@Override
public void visitMethodCallExpression(@NotNull PsiMethodCallExpression call) {
  super.visitMethodCallExpression(call);
  final PsiReferenceExpression methodExpression =
    call.getMethodExpression();
  @NonNls final String methodName = methodExpression.getReferenceName();
  if ("equals".equals(methodName)) {
    return; // object method
  }
  final PsiExpression qualifier =
    methodExpression.getQualifierExpression();
  if (!(qualifier instanceof PsiReferenceExpression)) {
    return;
  }
  final PsiElement referent = ((PsiReference)qualifier).resolve();
  if (!(referent instanceof PsiVariable)) {
    return;
  }
  final PsiExpressionList argumentList = call.getArgumentList();
  PsiExpression selfArgument = null;
  final PsiExpression[] arguments = argumentList.getExpressions();
  for (PsiExpression argument : arguments) {
    if (EquivalenceChecker.expressionsAreEquivalent(qualifier, argument)) {
      selfArgument = argument;
    }
  }
  if (selfArgument == null) {
    return;
  }
  final PsiType qualifierType = qualifier.getType();
  if (!InheritanceUtil.isInheritor(qualifierType, CommonClassNames.JAVA_UTIL_COLLECTION) &&
      !InheritanceUtil.isInheritor(qualifierType, CommonClassNames.JAVA_UTIL_MAP)) {
    return;
  }
  final PsiMethod method = call.resolveMethod();
  if (method == null) {
    return;
  }
  final PsiClass aClass = method.getContainingClass();
  if (!CollectionUtils.isCollectionClassOrInterface(aClass)) {
    return;
  }
  registerError(selfArgument, methodName);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:45,代码来源:CollectionAddedToSelfInspection.java

示例7: visitLiteralExpression

import com.siyeh.ig.psiutils.CollectionUtils; //导入方法依赖的package包/类
@Override
public void visitLiteralExpression(@NotNull PsiLiteralExpression value) {
  super.visitLiteralExpression(value);
  final String text = value.getText();
  if (!PsiKeyword.NULL.equals(text)) {
    return;
  }
  PsiElement parent = value.getParent();
  while (parent instanceof PsiParenthesizedExpression ||
         parent instanceof PsiConditionalExpression ||
         parent instanceof PsiTypeCastExpression) {
    parent = parent.getParent();
  }
  if (!(parent instanceof PsiReturnStatement)) {
    return;
  }
  final PsiElement element = PsiTreeUtil.getParentOfType(value, PsiMethod.class, PsiLambdaExpression.class);
  final PsiMethod method;
  final PsiType returnType;
  if (element instanceof PsiMethod) {
    method = (PsiMethod)element;
    returnType = method.getReturnType();
  } 
  else if (element instanceof PsiLambdaExpression) {
    final PsiType functionalInterfaceType = ((PsiLambdaExpression)element).getFunctionalInterfaceType();
    method = LambdaUtil.getFunctionalInterfaceMethod(functionalInterfaceType);
    returnType = LambdaUtil.getFunctionalInterfaceReturnType(functionalInterfaceType);
  } 
  else {
    return;
  }
  if (method == null || returnType == null) {
    return;
  }

  if (m_ignorePrivateMethods && method.hasModifierProperty(PsiModifier.PRIVATE)) {
    return;
  }

  final boolean isArray = returnType.getArrayDimensions() > 0;
  final NullableNotNullManager nullableNotNullManager = NullableNotNullManager.getInstance(method.getProject());
  if (nullableNotNullManager.isNullable(method, false)) {
    return;
  }
  if (CollectionUtils.isCollectionClassOrInterface(returnType)) {
    if (m_reportCollectionMethods) {
      registerError(value, value);
    }
  }
  else if (isArray) {
    if (m_reportArrayMethods) {
      registerError(value, value);
    }
  }
  else {
    if (m_reportObjectMethods) {
      registerError(value, value);
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:61,代码来源:ReturnNullInspectionBase.java

示例8: visitLiteralExpression

import com.siyeh.ig.psiutils.CollectionUtils; //导入方法依赖的package包/类
@Override
public void visitLiteralExpression(
  @NotNull PsiLiteralExpression value) {
  super.visitLiteralExpression(value);
  final String text = value.getText();
  if (!PsiKeyword.NULL.equals(text)) {
    return;
  }
  PsiElement parent = value.getParent();
  while (parent instanceof PsiParenthesizedExpression ||
         parent instanceof PsiConditionalExpression ||
         parent instanceof PsiTypeCastExpression) {
    parent = parent.getParent();
  }
  if (!(parent instanceof PsiReturnStatement)) {
    return;
  }
  final PsiMethod method =
    PsiTreeUtil.getParentOfType(value, PsiMethod.class);
  if (method == null) {
    return;
  }
  if (m_ignorePrivateMethods &&
      method.hasModifierProperty(PsiModifier.PRIVATE)) {
    return;
  }
  final PsiType returnType = method.getReturnType();
  if (returnType == null) {
    return;
  }
  final boolean isArray = returnType.getArrayDimensions() > 0;
  final NullableNotNullManager nullableNotNullManager =
    NullableNotNullManager.getInstance(method.getProject());
  if (nullableNotNullManager.isNullable(method, false)) {
    return;
  }
  if (CollectionUtils.isCollectionClassOrInterface(returnType)) {
    if (m_reportCollectionMethods) {
      registerError(value, value);
    }
  }
  else if (isArray) {
    if (m_reportArrayMethods) {
      registerError(value, value);
    }
  }
  else {
    if (m_reportObjectMethods) {
      registerError(value, value);
    }
  }
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:53,代码来源:ReturnNullInspectionBase.java


注:本文中的com.siyeh.ig.psiutils.CollectionUtils.isCollectionClassOrInterface方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。