當前位置: 首頁>>代碼示例>>Java>>正文


Java ExpressionUtils.isConstant方法代碼示例

本文整理匯總了Java中com.siyeh.ig.psiutils.ExpressionUtils.isConstant方法的典型用法代碼示例。如果您正苦於以下問題:Java ExpressionUtils.isConstant方法的具體用法?Java ExpressionUtils.isConstant怎麽用?Java ExpressionUtils.isConstant使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.siyeh.ig.psiutils.ExpressionUtils的用法示例。


在下文中一共展示了ExpressionUtils.isConstant方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: visitMethod

import com.siyeh.ig.psiutils.ExpressionUtils; //導入方法依賴的package包/類
@Override
public void visitMethod(@NotNull PsiMethod method) {
  final PsiIdentifier nameIdentifier = method.getNameIdentifier();
  if (nameIdentifier == null) {
    return;
  }
  final VariableAccessVisitor visitor = new VariableAccessVisitor();
  method.accept(visitor);
  final Set<PsiField> fields = visitor.getOveraccessedFields();
  for (PsiField field : fields) {
    if (ExpressionUtils.isConstant(field)) {
      continue;
    }
    if (m_ignoreFinalFields &&
        field.hasModifierProperty(PsiModifier.FINAL)) {
      continue;
    }
    registerError(nameIdentifier, field);
  }
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:21,代碼來源:FieldRepeatedlyAccessedInspection.java

示例2: visitReferenceExpression

import com.siyeh.ig.psiutils.ExpressionUtils; //導入方法依賴的package包/類
@Override
public void visitReferenceExpression(PsiReferenceExpression expression) {
  final PsiElement target = expression.resolve();
  if (target instanceof PsiField && ExpressionUtils.isConstant((PsiField)target)) {
    referenceFound = true;
  }
  else {
    super.visitReferenceExpression(expression);
  }
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:11,代碼來源:PointlessBooleanExpressionInspection.java

示例3: isMoveable

import com.siyeh.ig.psiutils.ExpressionUtils; //導入方法依賴的package包/類
protected boolean isMoveable(PsiExpression expression) {
  if (expression == null) {
    return true;
  }
  if (PsiUtil.isConstantExpression(expression) || ExpressionUtils.isNullLiteral(expression)) {
    return true;
  }
  if (expression instanceof PsiNewExpression) {
    final PsiNewExpression newExpression = (PsiNewExpression)expression;
    final PsiExpression[] arrayDimensions = newExpression.getArrayDimensions();
    if (arrayDimensions.length > 0) {
      for (PsiExpression arrayDimension : arrayDimensions) {
        if (!isMoveable(arrayDimension)) {
          return false;
        }
      }
      return true;
    }
    final PsiArrayInitializerExpression arrayInitializer = newExpression.getArrayInitializer();
    boolean result = true;
    if (arrayInitializer != null) {
      final PsiExpression[] initializers = arrayInitializer.getInitializers();
      for (final PsiExpression initializerExpression : initializers) {
        result &= isMoveable(initializerExpression);
      }
    }
    else if (!m_allowConstructorAsInitializer) {
      final PsiType type = newExpression.getType();
      if (!ClassUtils.isImmutable(type)) {
        return false;
      }
    }
    final PsiExpressionList argumentList = newExpression.getArgumentList();
    if (argumentList == null) {
      return result;
    }
    final PsiExpression[] expressions = argumentList.getExpressions();
    for (final PsiExpression argumentExpression : expressions) {
      result &= isMoveable(argumentExpression);
    }
    return result;
  }
  if (expression instanceof PsiReferenceExpression) {
    final PsiReferenceExpression referenceExpression = (PsiReferenceExpression)expression;
    final PsiElement target = referenceExpression.resolve();
    if (!(target instanceof PsiField)) {
      return false;
    }
    final PsiField field = (PsiField)target;
    if (ExpressionUtils.isConstant(field)) {
      return true;
    }
  }
  return false;
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:56,代碼來源:TooBroadScopeInspectionBase.java

示例4: visitReferenceExpression

import com.siyeh.ig.psiutils.ExpressionUtils; //導入方法依賴的package包/類
@Override
public void visitReferenceExpression(@NotNull PsiReferenceExpression expression) {
  super.visitReferenceExpression(expression);
  final PsiElement target = expression.resolve();
  if (!(target instanceof PsiField)) {
    return;
  }
  final PsiField lockedField = (PsiField)target;
  if (!lockedField.hasModifierProperty(PsiModifier.STATIC) || ExpressionUtils.isConstant(lockedField)) {
    return;
  }
  final PsiClass containingClass = lockedField.getContainingClass();
  if (!PsiTreeUtil.isAncestor(containingClass, expression, false)) {
    return;
  }
  if (!ignoredClasses.isEmpty()) {
    final PsiType type = lockedField.getType();
    if (type instanceof PsiClassType) {
      final PsiClassType classType = (PsiClassType)type;
      final PsiClass aClass = classType.resolve();
      if (aClass != null && ignoredClasses.contains(aClass.getQualifiedName())) {
        return;
      }
    }
  }

  boolean isLockedOnInstance = false;
  boolean isLockedOnClass = false;
  final PsiMethod containingMethod = PsiTreeUtil.getParentOfType(expression, PsiMethod.class);
  if (containingMethod != null && containingMethod.hasModifierProperty(PsiModifier.SYNCHRONIZED)) {
    if (containingMethod.hasModifierProperty(PsiModifier.STATIC)) {
      isLockedOnClass = true;
    }
    else {
      isLockedOnInstance = true;
    }
  }
  final PsiClass expressionClass = PsiTreeUtil.getParentOfType(expression, PsiClass.class);
  if (expressionClass == null) {
    return;
  }
  PsiElement elementToCheck = expression;
  while (true) {
    final PsiSynchronizedStatement synchronizedStatement = PsiTreeUtil.getParentOfType(elementToCheck, PsiSynchronizedStatement.class);
    if (synchronizedStatement == null || !PsiTreeUtil.isAncestor(expressionClass, synchronizedStatement, true)) {
      break;
    }
    final PsiExpression lockExpression = synchronizedStatement.getLockExpression();
    if (lockExpression instanceof PsiReferenceExpression) {
      final PsiReferenceExpression reference = (PsiReferenceExpression)lockExpression;
      final PsiElement lockTarget = reference.resolve();
      if (lockTarget instanceof PsiField) {
        final PsiField lockField = (PsiField)lockTarget;
        if (lockField.hasModifierProperty(PsiModifier.STATIC)) {
          isLockedOnClass = true;
        }
        else {
          isLockedOnInstance = true;
        }
      }
    }
    else if (lockExpression instanceof PsiThisExpression) {
      isLockedOnInstance = true;
    }
    else if (lockExpression instanceof PsiClassObjectAccessExpression) {
      isLockedOnClass = true;
    }
    elementToCheck = synchronizedStatement;
  }
  if (!isLockedOnInstance || isLockedOnClass) {
    return;
  }
  registerError(expression);
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:75,代碼來源:AccessToStaticFieldLockedOnInstanceInspectionBase.java

示例5: isMoveable

import com.siyeh.ig.psiutils.ExpressionUtils; //導入方法依賴的package包/類
private boolean isMoveable(PsiExpression expression) {
  if (expression == null) {
    return true;
  }
  if (PsiUtil.isConstantExpression(expression) || ExpressionUtils.isNullLiteral(expression)) {
    return true;
  }
  if (expression instanceof PsiNewExpression) {
    final PsiNewExpression newExpression = (PsiNewExpression)expression;
    final PsiExpression[] arrayDimensions = newExpression.getArrayDimensions();
    if (arrayDimensions.length > 0) {
      for (PsiExpression arrayDimension : arrayDimensions) {
        if (!isMoveable(arrayDimension)) {
          return false;
        }
      }
      return true;
    }
    final PsiArrayInitializerExpression arrayInitializer = newExpression.getArrayInitializer();
    boolean result = true;
    if (arrayInitializer != null) {
      final PsiExpression[] initializers = arrayInitializer.getInitializers();
      for (final PsiExpression initializerExpression : initializers) {
        result &= isMoveable(initializerExpression);
      }
    }
    else if (!m_allowConstructorAsInitializer) {
      final PsiType type = newExpression.getType();
      if (!ClassUtils.isImmutable(type)) {
        return false;
      }
    }
    final PsiExpressionList argumentList = newExpression.getArgumentList();
    if (argumentList == null) {
      return result;
    }
    final PsiExpression[] expressions = argumentList.getExpressions();
    for (final PsiExpression argumentExpression : expressions) {
      result &= isMoveable(argumentExpression);
    }
    return result;
  }
  if (expression instanceof PsiReferenceExpression) {
    final PsiReferenceExpression referenceExpression = (PsiReferenceExpression)expression;
    final PsiElement target = referenceExpression.resolve();
    if (!(target instanceof PsiField)) {
      return false;
    }
    final PsiField field = (PsiField)target;
    if (ExpressionUtils.isConstant(field)) {
      return true;
    }
  }
  return false;
}
 
開發者ID:consulo,項目名稱:consulo-java,代碼行數:56,代碼來源:TooBroadScopeInspection.java


注:本文中的com.siyeh.ig.psiutils.ExpressionUtils.isConstant方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。