本文整理汇总了Java中com.siyeh.ig.psiutils.ExpressionUtils.isNullLiteral方法的典型用法代码示例。如果您正苦于以下问题:Java ExpressionUtils.isNullLiteral方法的具体用法?Java ExpressionUtils.isNullLiteral怎么用?Java ExpressionUtils.isNullLiteral使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.siyeh.ig.psiutils.ExpressionUtils
的用法示例。
在下文中一共展示了ExpressionUtils.isNullLiteral方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isNotNullMatcher
import com.siyeh.ig.psiutils.ExpressionUtils; //导入方法依赖的package包/类
private static boolean isNotNullMatcher(PsiExpression expr) {
if (expr instanceof PsiMethodCallExpression) {
String calledName = ((PsiMethodCallExpression)expr).getMethodExpression().getReferenceName();
if ("notNullValue".equals(calledName)) {
return true;
}
if ("not".equals(calledName)) {
PsiExpression[] notArgs = ((PsiMethodCallExpression)expr).getArgumentList().getExpressions();
if (notArgs.length == 1 &&
notArgs[0] instanceof PsiMethodCallExpression &&
"equalTo".equals(((PsiMethodCallExpression)notArgs[0]).getMethodExpression().getReferenceName())) {
PsiExpression[] equalArgs = ((PsiMethodCallExpression)notArgs[0]).getArgumentList().getExpressions();
if (equalArgs.length == 1 && ExpressionUtils.isNullLiteral(equalArgs[0])) {
return true;
}
}
}
}
return false;
}
示例2: isNullComparison
import com.siyeh.ig.psiutils.ExpressionUtils; //导入方法依赖的package包/类
private static boolean isNullComparison(PsiExpression condition, PsiVariable variable) {
if (!(condition instanceof PsiBinaryExpression)) {
return false;
}
final PsiBinaryExpression comparison = (PsiBinaryExpression)condition;
final IElementType tokenType = comparison.getOperationTokenType();
if (!tokenType.equals(JavaTokenType.EQEQ)) {
return false;
}
final PsiExpression lhs = comparison.getLOperand();
final PsiExpression rhs = comparison.getROperand();
if (ExpressionUtils.isNullLiteral(rhs)) {
return VariableAccessUtils.evaluatesToVariable(lhs, variable);
}
else if (ExpressionUtils.isNullLiteral(lhs)) {
return VariableAccessUtils.evaluatesToVariable(rhs, variable);
}
return false;
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:20,代码来源:NonThreadSafeLazyInitializationInspectionBase.java
示例3: visitBinaryExpression
import com.siyeh.ig.psiutils.ExpressionUtils; //导入方法依赖的package包/类
@Override
public void visitBinaryExpression(@NotNull PsiBinaryExpression expression) {
super.visitBinaryExpression(expression);
if (!ComparisonUtils.isEqualityComparison(expression)) {
return;
}
final PsiExpression lhs = expression.getLOperand();
if (!ExpressionUtils.hasStringType(lhs)) {
return;
}
final PsiExpression rhs = expression.getROperand();
if (rhs == null || !ExpressionUtils.hasStringType(rhs)) {
return;
}
if (ExpressionUtils.isNullLiteral(lhs) || ExpressionUtils.isNullLiteral(rhs)) {
return;
}
final PsiJavaToken sign = expression.getOperationSign();
registerError(sign);
}
示例4: isNullComparison
import com.siyeh.ig.psiutils.ExpressionUtils; //导入方法依赖的package包/类
private static boolean isNullComparison(PsiExpression expression) {
if (!(expression instanceof PsiBinaryExpression)) {
return false;
}
final PsiBinaryExpression binaryExpression = (PsiBinaryExpression)expression;
final IElementType tokenType = binaryExpression.getOperationTokenType();
if (!JavaTokenType.EQEQ.equals(tokenType) && !JavaTokenType.NE.equals(tokenType)) {
return false;
}
final PsiExpression lhs = binaryExpression.getLOperand();
if (ExpressionUtils.isNullLiteral(lhs)) {
return true;
}
final PsiExpression rhs = binaryExpression.getROperand();
return ExpressionUtils.isNullLiteral(rhs);
}
示例5: buildReplacement
import com.siyeh.ig.psiutils.ExpressionUtils; //导入方法依赖的package包/类
@NonNls
static String buildReplacement(@NotNull PsiExpression operandToReplace, boolean seenString) {
if (ExpressionUtils.isNullLiteral(operandToReplace)) {
if (seenString) {
return "null";
}
else {
return "String.valueOf((Object)null)";
}
}
if (seenString || ExpressionUtils.hasStringType(operandToReplace)) {
return operandToReplace.getText();
}
return "String.valueOf(" + operandToReplace.getText() + ')';
}
示例6: visitMethodCallExpression
import com.siyeh.ig.psiutils.ExpressionUtils; //导入方法依赖的package包/类
@Override
public void visitMethodCallExpression(
@NotNull PsiMethodCallExpression call) {
super.visitMethodCallExpression(call);
final PsiExpressionList argumentList = call.getArgumentList();
final PsiExpression[] args = argumentList.getExpressions();
if (args.length == 0) {
return;
}
final PsiExpression lastArg = args[args.length - 1];
if (!ExpressionUtils.isNullLiteral(lastArg)) {
return;
}
final PsiMethod method = call.resolveMethod();
if (method == null) {
return;
}
final PsiParameterList parameterList = method.getParameterList();
if (parameterList.getParametersCount() != args.length) {
return;
}
final PsiParameter[] parameters = parameterList.getParameters();
final PsiParameter lastParameter =
parameters[parameters.length - 1];
if (!lastParameter.isVarArgs()) {
return;
}
registerError(lastArg);
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:31,代码来源:NullArgumentToVariableArgMethodInspection.java
示例7: visitMethodCallExpression
import com.siyeh.ig.psiutils.ExpressionUtils; //导入方法依赖的package包/类
@Override
public void visitMethodCallExpression(
@NotNull PsiMethodCallExpression call) {
super.visitMethodCallExpression(call);
if (!MethodCallUtils.isEqualsCall(call)) {
return;
}
final PsiExpressionList argumentList = call.getArgumentList();
final PsiExpression[] args = argumentList.getExpressions();
if (args.length == 0 || !ExpressionUtils.isNullLiteral(args[0])) {
return;
}
registerError(args[0]);
}
示例8: buildReplacement
import com.siyeh.ig.psiutils.ExpressionUtils; //导入方法依赖的package包/类
static String buildReplacement(@NotNull PsiExpression operandToReplace, boolean seenString) {
if (ExpressionUtils.isNullLiteral(operandToReplace)) {
if (seenString) {
return "null";
}
else {
return "String.valueOf((Object)null)";
}
}
if (seenString || ExpressionUtils.hasStringType(operandToReplace)) {
return operandToReplace.getText();
}
return "String.valueOf(" + operandToReplace.getText() + ')';
}
示例9: visitMethodCallExpression
import com.siyeh.ig.psiutils.ExpressionUtils; //导入方法依赖的package包/类
@Override
public void visitMethodCallExpression(
@NotNull PsiMethodCallExpression call) {
super.visitMethodCallExpression(call);
if (!PsiUtil.isLanguageLevel5OrHigher(call)) {
return;
}
final PsiExpressionList argumentList = call.getArgumentList();
final PsiExpression[] args = argumentList.getExpressions();
if (args.length == 0) {
return;
}
final PsiExpression lastArg = args[args.length - 1];
if (!ExpressionUtils.isNullLiteral(lastArg)) {
return;
}
final PsiMethod method = call.resolveMethod();
if (method == null) {
return;
}
final PsiParameterList parameterList = method.getParameterList();
if (parameterList.getParametersCount() != args.length) {
return;
}
final PsiParameter[] parameters = parameterList.getParameters();
final PsiParameter lastParameter =
parameters[parameters.length - 1];
if (!lastParameter.isVarArgs()) {
return;
}
registerError(lastArg);
}
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:34,代码来源:NullArgumentToVariableArgMethodInspection.java
示例10: isNotNullMatcher
import com.siyeh.ig.psiutils.ExpressionUtils; //导入方法依赖的package包/类
private static boolean isNotNullMatcher(PsiExpression expr)
{
if(expr instanceof PsiMethodCallExpression)
{
String calledName = ((PsiMethodCallExpression) expr).getMethodExpression().getReferenceName();
if("notNullValue".equals(calledName))
{
return true;
}
if("not".equals(calledName))
{
PsiExpression[] notArgs = ((PsiMethodCallExpression) expr).getArgumentList().getExpressions();
if(notArgs.length == 1 && notArgs[0] instanceof PsiMethodCallExpression && "equalTo".equals(((PsiMethodCallExpression) notArgs[0]).getMethodExpression().getReferenceName()))
{
PsiExpression[] equalArgs = ((PsiMethodCallExpression) notArgs[0]).getArgumentList().getExpressions();
if(equalArgs.length == 1 && ExpressionUtils.isNullLiteral(equalArgs[0]))
{
return true;
}
}
}
if("is".equals(calledName))
{
PsiExpression[] args = ((PsiMethodCallExpression) expr).getArgumentList().getExpressions();
if(args.length == 1)
{
return isNotNullMatcher(args[0]);
}
}
}
return false;
}
示例11: isConstantExpression
import com.siyeh.ig.psiutils.ExpressionUtils; //导入方法依赖的package包/类
private static boolean isConstantExpression(PsiExpression expression) {
return ExpressionUtils.isNullLiteral(expression) || PsiUtil.isConstantExpression(expression);
}
示例12: 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;
}
示例13: createNPEFixes
import com.siyeh.ig.psiutils.ExpressionUtils; //导入方法依赖的package包/类
@NotNull
protected List<LocalQuickFix> createNPEFixes(PsiExpression qualifier, PsiExpression expression, boolean onTheFly)
{
qualifier = PsiUtil.deparenthesizeExpression(qualifier);
final List<LocalQuickFix> fixes = new SmartList<>();
if(qualifier == null || expression == null)
{
return fixes;
}
try
{
ContainerUtil.addIfNotNull(fixes, StreamFilterNotNullFix.makeFix(qualifier));
if(isVolatileFieldReference(qualifier))
{
ContainerUtil.addIfNotNull(fixes, createIntroduceVariableFix(qualifier));
}
else if(!ExpressionUtils.isNullLiteral(qualifier) && !SideEffectChecker.mayHaveSideEffects(qualifier))
{
if(PsiUtil.getLanguageLevel(qualifier).isAtLeast(LanguageLevel.JDK_1_4))
{
final Project project = qualifier.getProject();
final PsiElementFactory elementFactory = JavaPsiFacade.getInstance(project).getElementFactory();
final PsiBinaryExpression binary = (PsiBinaryExpression) elementFactory.createExpressionFromText("a != null", null);
binary.getLOperand().replace(qualifier);
if(RefactoringUtil.getParentStatement(expression, false) != null)
{
fixes.add(new AddAssertStatementFix(binary));
}
}
if(onTheFly && SurroundWithIfFix.isAvailable(qualifier))
{
fixes.add(new SurroundWithIfFix(qualifier));
}
if(ReplaceWithTernaryOperatorFix.isAvailable(qualifier, expression))
{
fixes.add(new ReplaceWithTernaryOperatorFix(qualifier));
}
}
if(!ExpressionUtils.isNullLiteral(qualifier) && PsiUtil.isLanguageLevel7OrHigher(qualifier))
{
fixes.add(new SurroundWithRequireNonNullFix(qualifier));
}
ContainerUtil.addIfNotNull(fixes, DfaOptionalSupport.registerReplaceOptionalOfWithOfNullableFix(qualifier));
}
catch(IncorrectOperationException e)
{
LOG.error(e);
}
return fixes;
}
示例14: 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;
}