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


Java CollectionUtils类代码示例

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


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

示例1: 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 (!(type instanceof PsiArrayType)) {
    return;
  }
  if (CollectionUtils.isConstantEmptyArray(field)) {
    return;
  }
  registerFieldError(field);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:PublicStaticArrayFieldInspection.java

示例2: 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

示例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;
  }
  return !VariableAccessUtils.variableIsUsedInArrayInitializer(variable, context);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:MismatchedCollectionQueryUpdateInspectionBase.java

示例4: visitMethod

import com.siyeh.ig.psiutils.CollectionUtils; //导入依赖的package包/类
@Override
public void visitMethod(@NotNull PsiMethod method) {
  super.visitMethod(method);
  if (ignorePrivateMethodsAndFields &&
      method.hasModifierProperty(PsiModifier.PRIVATE)) {
    return;
  }
  if (isOnTheFly() && !isCheapEnoughToSearch(method)) {
    return;
  }
  final PsiType type = method.getReturnType();
  if (!CollectionUtils.isConcreteCollectionClass(type) || LibraryUtil.isOverrideOfLibraryMethod(method)) {
    return;
  }

  checkToWeaken(type, method.getReturnTypeElement(), method);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:DeclareCollectionAsInterfaceInspection.java

示例5: visitNewExpression

import com.siyeh.ig.psiutils.CollectionUtils; //导入依赖的package包/类
@Override
public void visitNewExpression(@NotNull PsiNewExpression expression) {
  super.visitNewExpression(expression);
  final PsiType type = expression.getType();

  if (type == null) {
    return;
  }
  if (!CollectionUtils.isCollectionWithInitialCapacity(type)) {
    return;
  }
  final PsiExpressionList argumentList = expression.getArgumentList();
  if (argumentList == null) {
    return;
  }
  final PsiExpression[] parameters = argumentList.getExpressions();
  if (parameters.length != 0) {
    return;
  }
  registerError(expression);
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:22,代码来源:CollectionsMustHaveInitialCapacityInspection.java

示例6: 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

示例7: visitMethod

import com.siyeh.ig.psiutils.CollectionUtils; //导入依赖的package包/类
@Override
public void visitMethod(@NotNull PsiMethod method)
{
	super.visitMethod(method);
	if(ignorePrivateMethodsAndFields && method.hasModifierProperty(PsiModifier.PRIVATE))
	{
		return;
	}
	if(isOnTheFly() && DeclarationSearchUtils.isTooExpensiveToSearch(method, false))
	{
		return;
	}
	final PsiType type = method.getReturnType();
	if(!CollectionUtils.isConcreteCollectionClass(type) || LibraryUtil.isOverrideOfLibraryMethod(method))
	{
		return;
	}

	checkToWeaken(type, method.getReturnTypeElement(), method);
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:21,代码来源:DeclareCollectionAsInterfaceInspection.java

示例8: 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

示例9: visitClass

import com.siyeh.ig.psiutils.CollectionUtils; //导入依赖的package包/类
@Override
public void visitClass(@NotNull PsiClass aClass) {
  if (aClass.isInterface() || aClass.isAnnotationType() || aClass.isEnum()) {
    return;
  }
  final PsiClass superClass = aClass.getSuperClass();
  if (!CollectionUtils.isConcreteCollectionClass(superClass)) {
    return;
  }
  final String qualifiedName = superClass.getQualifiedName();
  if ("java.util.LinkedHashMap".equals(qualifiedName)) {
    final PsiMethod[] methods = aClass.findMethodsByName("removeEldestEntry", false);
    final PsiClassType entryType = TypeUtils.getType("java.util.Map.Entry", aClass);
    for (PsiMethod method : methods) {
      if (!PsiType.BOOLEAN.equals(method.getReturnType())) {
        continue;
      }
      final PsiParameterList parameterList = method.getParameterList();
      if (  parameterList.getParametersCount() != 1) {
        continue;
      }
      final PsiParameter parameter = parameterList.getParameters()[0];
      if (entryType.isAssignableFrom(parameter.getType())) {
        return;
      }
    }
  }
  registerClassError(aClass, superClass, aClass);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:30,代码来源:ExtendsConcreteCollectionInspectionBase.java

示例10: 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

示例11: visitReturnStatement

import com.siyeh.ig.psiutils.CollectionUtils; //导入依赖的package包/类
@Override
public void visitReturnStatement(@NotNull PsiReturnStatement statement) {
  super.visitReturnStatement(statement);
  final PsiExpression returnValue = statement.getReturnValue();
  if (returnValue == null) {
    return;
  }
  final PsiElement element = PsiTreeUtil.getParentOfType(statement, PsiMethod.class, PsiLambdaExpression.class);
  if (element == null) {
    return;
  }
  if (ignorePrivateMethods && element instanceof PsiMethod && ((PsiMethod)element).hasModifierProperty(PsiModifier.PRIVATE)) {
    return;
  }
  final PsiClass returnStatementClass = PsiTreeUtil.getParentOfType(statement, PsiClass.class);
  if (returnStatementClass == null) {
    return;
  }
  if (!(returnValue instanceof PsiReferenceExpression)) {
    return;
  }
  final PsiReferenceExpression referenceExpression = (PsiReferenceExpression)returnValue;
  final PsiElement referent = referenceExpression.resolve();
  if (!(referent instanceof PsiField)) {
    return;
  }
  final PsiField field = (PsiField)referent;
  final PsiClass fieldClass = field.getContainingClass();
  if (!returnStatementClass.equals(fieldClass)) {
    return;
  }
  if (!CollectionUtils.isArrayOrCollectionField(field)) {
    return;
  }
  registerError(returnValue, field, returnValue);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:37,代码来源:ReturnOfCollectionFieldInspectionBase.java

示例12: visitVariable

import com.siyeh.ig.psiutils.CollectionUtils; //导入依赖的package包/类
@Override
public void visitVariable(@NotNull PsiVariable variable) {
  if (isOnTheFly() && !isCheapEnoughToSearch(variable)) {
    return;
  }
  if (ignoreLocalVariables && variable instanceof PsiLocalVariable) {
    return;
  }
  if (ignorePrivateMethodsAndFields) {
    if (variable instanceof PsiField) {
      if (variable.hasModifierProperty(PsiModifier.PRIVATE)) {
        return;
      }
    }
  }
  if (variable instanceof PsiParameter) {
    final PsiParameter parameter = (PsiParameter)variable;
    final PsiElement scope = parameter.getDeclarationScope();
    if (scope instanceof PsiMethod) {
      if (ignorePrivateMethodsAndFields) {
        final PsiMethod method = (PsiMethod)scope;
        if (method.hasModifierProperty(PsiModifier.PRIVATE)) {
          return;
        }
      }
    }
    else if (ignoreLocalVariables) {
      return;
    }
  }
  final PsiType type = variable.getType();
  if (!CollectionUtils.isConcreteCollectionClass(type) || LibraryUtil.isOverrideOfLibraryMethodParameter(variable)) {
    return;
  }

  checkToWeaken(type, variable.getTypeElement(), variable);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:38,代码来源:DeclareCollectionAsInterfaceInspection.java

示例13: checkToWeaken

import com.siyeh.ig.psiutils.CollectionUtils; //导入依赖的package包/类
private void checkToWeaken(PsiType type, PsiTypeElement typeElement, PsiElement variable) {
  if (typeElement == null) {
    return;
  }
  final PsiJavaCodeReferenceElement reference = typeElement.getInnermostComponentReferenceElement();
  if (reference == null) {
    return;
  }
  final PsiElement nameElement = reference.getReferenceNameElement();
  if (nameElement == null) {
    return;
  }
  final Collection<PsiClass> weaklings = WeakestTypeFinder.calculateWeakestClassesNecessary(variable, false, true);
  if (weaklings.isEmpty()) {
    return;
  }
  final PsiClassType javaLangObject = PsiType.getJavaLangObject(nameElement.getManager(), nameElement.getResolveScope());
  final List<PsiClass> weaklingList = new ArrayList<PsiClass>(weaklings);
  final PsiClass objectClass = javaLangObject.resolve();
  weaklingList.remove(objectClass);
  if (weaklingList.isEmpty()) {
    final String typeText = type.getCanonicalText();
    final String interfaceText = CollectionUtils.getInterfaceForClass(typeText);
    if (interfaceText == null) {
      return;
    }
    registerError(nameElement, interfaceText);
  }
  else {
    final PsiClass weakling = weaklingList.get(0);
    final String qualifiedName = weakling.getQualifiedName();
    registerError(nameElement, qualifiedName);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:35,代码来源:DeclareCollectionAsInterfaceInspection.java

示例14: visitClass

import com.siyeh.ig.psiutils.CollectionUtils; //导入依赖的package包/类
@Override
public void visitClass(@NotNull PsiClass aClass) {
  if (aClass.isInterface() || aClass.isAnnotationType() || aClass.isEnum()) {
    return;
  }
  final PsiClass superClass = aClass.getSuperClass();
  if (superClass == null) {
    return;
  }
  if (!CollectionUtils.isCollectionClass(superClass)) {
    return;
  }
  registerClassError(aClass, superClass, aClass);
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:15,代码来源:ExtendsConcreteCollectionInspection.java

示例15: visitReturnStatement

import com.siyeh.ig.psiutils.CollectionUtils; //导入依赖的package包/类
@Override
public void visitReturnStatement(@NotNull PsiReturnStatement statement) {
  super.visitReturnStatement(statement);
  final PsiExpression returnValue = statement.getReturnValue();
  if (returnValue == null) {
    return;
  }
  final PsiMethod containingMethod = PsiTreeUtil.getParentOfType(statement, PsiMethod.class);
  if (containingMethod == null) {
    return;
  }
  if (ignorePrivateMethods && containingMethod.hasModifierProperty(PsiModifier.PRIVATE)) {
    return;
  }
  final PsiClass returnStatementClass = containingMethod.getContainingClass();
  if (returnStatementClass == null) {
    return;
  }
  if (!(returnValue instanceof PsiReferenceExpression)) {
    return;
  }
  final PsiReferenceExpression referenceExpression = (PsiReferenceExpression)returnValue;
  final PsiElement referent = referenceExpression.resolve();
  if (!(referent instanceof PsiField)) {
    return;
  }
  final PsiField field = (PsiField)referent;
  final PsiClass fieldClass = field.getContainingClass();
  if (!returnStatementClass.equals(fieldClass)) {
    return;
  }
  if (!CollectionUtils.isArrayOrCollectionField(field)) {
    return;
  }
  registerError(returnValue, field, returnValue);
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:37,代码来源:ReturnOfCollectionFieldInspectionBase.java


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