当前位置: 首页>>代码示例>>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;未经允许,请勿转载。