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


Java ExpressionUtils.isLiteral方法代碼示例

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


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

示例1: visitSynchronizedStatement

import com.siyeh.ig.psiutils.ExpressionUtils; //導入方法依賴的package包/類
@Override
public void visitSynchronizedStatement(@NotNull PsiSynchronizedStatement statement) {
  super.visitSynchronizedStatement(statement);
  final PsiExpression lockExpression = statement.getLockExpression();
  if (lockExpression == null) {
    return;
  }
  final PsiType type = lockExpression.getType();
  if (type == null) {
    return;
  }
  if (!type.equalsToText(CommonClassNames.JAVA_LANG_STRING) &&
      !type.equalsToText(CommonClassNames.JAVA_LANG_BOOLEAN) &&
      !type.equalsToText(CommonClassNames.JAVA_LANG_CHARACTER)) {
    final PsiClassType javaLangNumberType = TypeUtils.getType(CommonClassNames.JAVA_LANG_NUMBER, statement);
    if (!javaLangNumberType.isAssignableFrom(type)) {
      return;
    }
  }
  if (!(lockExpression instanceof PsiReferenceExpression)) {
    if (ExpressionUtils.isLiteral(lockExpression)) {
      registerError(lockExpression, type, Integer.valueOf(2));
    }
    else if (warnOnAllPossiblyLiterals) {
      registerError(lockExpression, type, Integer.valueOf(3));
    }
    return;
  }
  final PsiReferenceExpression referenceExpression = (PsiReferenceExpression)lockExpression;
  final PsiElement target = referenceExpression.resolve();
  if (!(target instanceof PsiVariable)) {
    if (warnOnAllPossiblyLiterals) {
      registerError(lockExpression, type, Integer.valueOf(3));
    }
    return;
  }
  final PsiVariable variable = (PsiVariable)target;
  final PsiExpression initializer = variable.getInitializer();
  if (!ExpressionUtils.isLiteral(initializer)) {
    if (warnOnAllPossiblyLiterals) {
      registerError(lockExpression, type, Integer.valueOf(3));
    }
    return;
  }
  registerError(lockExpression, type, Integer.valueOf(1));
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:47,代碼來源:SynchronizedOnLiteralObjectInspection.java

示例2: isCompileTimeFlagCheck

import com.siyeh.ig.psiutils.ExpressionUtils; //導入方法依賴的package包/類
private static boolean isCompileTimeFlagCheck(PsiElement element)
{
	if(element instanceof PsiBinaryExpression)
	{
		PsiBinaryExpression binOp = (PsiBinaryExpression) element;
		if(ComparisonUtils.isComparisonOperation(binOp.getOperationTokenType()))
		{
			PsiExpression comparedWith = null;
			if(ExpressionUtils.isLiteral(binOp.getROperand()))
			{
				comparedWith = binOp.getLOperand();
			}
			else if(ExpressionUtils.isLiteral(binOp.getLOperand()))
			{
				comparedWith = binOp.getROperand();
			}
			comparedWith = PsiUtil.skipParenthesizedExprDown(comparedWith);
			if(isConstantOfType(comparedWith, PsiType.INT, PsiType.LONG))
			{
				// like "if(DEBUG_LEVEL > 2)"
				return true;
			}
			if(comparedWith instanceof PsiBinaryExpression)
			{
				PsiBinaryExpression subOp = (PsiBinaryExpression) comparedWith;
				if(subOp.getOperationTokenType().equals(JavaTokenType.AND))
				{
					PsiExpression left = PsiUtil.skipParenthesizedExprDown(subOp.getLOperand());
					PsiExpression right = PsiUtil.skipParenthesizedExprDown(subOp.getROperand());
					if(isConstantOfType(left, PsiType.INT, PsiType.LONG) || isConstantOfType(right, PsiType.INT, PsiType.LONG))
					{
						// like "if((FLAGS & SOME_FLAG) != 0)"
						return true;
					}
				}
			}
		}
	}
	// like "if(DEBUG)"
	return isConstantOfType(element, PsiType.BOOLEAN);
}
 
開發者ID:consulo,項目名稱:consulo-java,代碼行數:42,代碼來源:DataFlowInspectionBase.java


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