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


Java ExpressionUtils.isEmptyStringLiteral方法代碼示例

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


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

示例1: visitPolyadicExpression

import com.siyeh.ig.psiutils.ExpressionUtils; //導入方法依賴的package包/類
@Override
public void visitPolyadicExpression(PsiPolyadicExpression expression) {
  super.visitPolyadicExpression(expression);
  if (!ExpressionUtils.hasStringType(expression)) {
    return;
  }
  final PsiExpression[] operands = expression.getOperands();
  for (PsiExpression operand : operands) {
    operand = ParenthesesUtils.stripParentheses(operand);
    if (operand == null) {
      return;
    }
    if (!ExpressionUtils.isEmptyStringLiteral(operand)) {
      continue;
    }
    if (PsiUtil.isConstantExpression(expression)) {
      return;
    }
    registerError(operand, operand);
  }
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:22,代碼來源:TrivialStringConcatenationInspection.java

示例2: doFix

import com.siyeh.ig.psiutils.ExpressionUtils; //導入方法依賴的package包/類
@Override
public void doFix(Project project, ProblemDescriptor descriptor) throws IncorrectOperationException {
  final PsiIdentifier name = (PsiIdentifier)descriptor.getPsiElement();
  final PsiReferenceExpression expression = (PsiReferenceExpression)name.getParent();
  if (expression == null) {
    return;
  }
  final PsiMethodCallExpression call = (PsiMethodCallExpression)expression.getParent();
  final PsiExpressionList argumentList = call.getArgumentList();
  final PsiExpression[] arguments = argumentList.getExpressions();
  if (arguments.length == 0) {
    return;
  }
  final PsiExpression qualifier = expression.getQualifierExpression();
  final PsiExpression argument = arguments[0];
  final PsiExpression checkedExpression;
  final boolean addNullCheck;
  if (ExpressionUtils.isEmptyStringLiteral(argument)) {
    checkedExpression = getCheckedExpression(qualifier);
    addNullCheck = false;
  }
  else {
    checkedExpression = getCheckedExpression(argument);
    addNullCheck = !isCheckedForNull(checkedExpression);
  }
  final StringBuilder newExpression;
  if (addNullCheck) {
    newExpression = new StringBuilder(checkedExpression.getText());
    newExpression.append("!=null&&");
  } else {
    newExpression = new StringBuilder("");
  }
  final PsiElement parent = call.getParent();
  final PsiExpression expressionToReplace;
  if (parent instanceof PsiExpression) {
    final PsiExpression parentExpression = (PsiExpression)parent;
    if (BoolUtils.isNegation(parentExpression)) {
      expressionToReplace = parentExpression;
      if (useIsEmpty) {
        newExpression.append('!').append(checkedExpression.getText()).append(".isEmpty()");
      }
      else {
        newExpression.append(checkedExpression.getText()).append(".length()!=0");
      }
    }
    else {
      expressionToReplace = call;
      if (useIsEmpty) {
        newExpression.append(checkedExpression.getText()).append(".isEmpty()");
      }
      else {
        newExpression.append(checkedExpression.getText()).append(".length()==0");
      }
    }
  }
  else {
    expressionToReplace = call;
    if (useIsEmpty) {
      newExpression.append(checkedExpression.getText()).append(".isEmpty()");
    }
    else {
      newExpression.append(checkedExpression.getText()).append(".length()==0");
    }
  }
  PsiReplacementUtil.replaceExpression(expressionToReplace, newExpression.toString());
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:67,代碼來源:StringEqualsEmptyStringInspection.java

示例3: calculateReplacementExpression

import com.siyeh.ig.psiutils.ExpressionUtils; //導入方法依賴的package包/類
@NonNls
static String calculateReplacementExpression(PsiLiteralExpression expression) {
  final PsiElement parent = ParenthesesUtils.getParentSkipParentheses(expression);
  if (!(parent instanceof PsiPolyadicExpression)) {
    return null;
  }
  if (parent instanceof PsiBinaryExpression) {
    final PsiBinaryExpression binaryExpression = (PsiBinaryExpression)parent;
    final PsiExpression lOperand = ParenthesesUtils.stripParentheses(binaryExpression.getLOperand());
    final PsiExpression rOperand = ParenthesesUtils.stripParentheses(binaryExpression.getROperand());
    final PsiExpression replacement;
    if (ExpressionUtils.isEmptyStringLiteral(lOperand)) {
      replacement = rOperand;
    }
    else {
      replacement = lOperand;
    }
    return replacement == null ? "" : buildReplacement(replacement, false);
  }
  final PsiPolyadicExpression polyadicExpression = (PsiPolyadicExpression)parent;
  final PsiExpression[] operands = polyadicExpression.getOperands();
  final PsiClassType stringType = TypeUtils.getStringType(expression);
  boolean seenString = false;
  boolean seenEmpty = false;
  boolean replaced = false;
  PsiExpression operandToReplace = null;
  final StringBuilder text = new StringBuilder();
  for (PsiExpression operand : operands) {
    if (operandToReplace != null && !replaced) {
      if (ExpressionUtils.hasStringType(operand)) {
        seenString = true;
      }
      if (text.length() > 0) {
        text.append(" + ");
      }
      text.append(buildReplacement(operandToReplace, seenString));
      text.append(" + ");
      text.append(operand.getText());
      replaced = true;
      continue;
    }
    if (ParenthesesUtils.stripParentheses(operand) == expression) {
      seenEmpty = true;
      continue;
    }
    if (seenEmpty && !replaced) {
      operandToReplace = operand;
      continue;
    }
    if (stringType.equals(operand.getType())) {
      seenString = true;
    }
    if (text.length() > 0) {
      text.append(" + ");
    }
    text.append(operand.getText());
  }
  if (!replaced && operandToReplace != null) {
    text.append(" + ");
    text.append(buildReplacement(operandToReplace, seenString));
  }
  return text.toString();
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:64,代碼來源:TrivialStringConcatenationInspection.java

示例4: doFix

import com.siyeh.ig.psiutils.ExpressionUtils; //導入方法依賴的package包/類
@Override
public void doFix(Project project, ProblemDescriptor descriptor) throws IncorrectOperationException {
  final PsiIdentifier name = (PsiIdentifier)descriptor.getPsiElement();
  final PsiReferenceExpression expression = (PsiReferenceExpression)name.getParent();
  if (expression == null) {
    return;
  }
  final PsiMethodCallExpression call = (PsiMethodCallExpression)expression.getParent();
  final PsiExpressionList argumentList = call.getArgumentList();
  final PsiExpression[] arguments = argumentList.getExpressions();
  if (arguments.length == 0) {
    return;
  }
  final PsiExpression qualifier = expression.getQualifierExpression();
  final PsiExpression argument = arguments[0];
  final String variableText;
  final boolean addNullCheck;
  if (ExpressionUtils.isEmptyStringLiteral(argument)) {
    variableText = getRemainingText(qualifier);
    addNullCheck = false;
  }
  else {
    variableText = getRemainingText(argument);
    addNullCheck = true;
  }
  StringBuilder newExpression;
  if (addNullCheck) {
    newExpression = new StringBuilder(variableText);
    newExpression.append("!=null&&");
  } else {
    newExpression = new StringBuilder("");
  }
  final PsiElement parent = call.getParent();
  final PsiExpression expressionToReplace;
  if (parent instanceof PsiExpression) {
    final PsiExpression parentExpression = (PsiExpression)parent;
    if (BoolUtils.isNegation(parentExpression)) {
      expressionToReplace = parentExpression;
      if (useIsEmpty) {
        newExpression.append('!').append(variableText).append(".isEmpty()");
      }
      else {
        newExpression.append(variableText).append(".length()!=0");
      }
    }
    else {
      expressionToReplace = call;
      if (useIsEmpty) {
        newExpression.append(variableText).append(".isEmpty()");
      }
      else {
        newExpression.append(variableText).append(".length()==0");
      }
    }
  }
  else {
    expressionToReplace = call;
    if (useIsEmpty) {
      newExpression.append(variableText).append(".isEmpty()");
    }
    else {
      newExpression.append(variableText).append(".length()==0");
    }
  }
  replaceExpression(expressionToReplace, newExpression.toString());
}
 
開發者ID:lshain-android-source,項目名稱:tools-idea,代碼行數:67,代碼來源:StringEqualsEmptyStringInspection.java

示例5: calculateReplacementExpression

import com.siyeh.ig.psiutils.ExpressionUtils; //導入方法依賴的package包/類
@NonNls
static String calculateReplacementExpression(PsiLiteralExpression expression) {
  final PsiElement parent = ParenthesesUtils.getParentSkipParentheses(expression);
  if (!(parent instanceof PsiPolyadicExpression)) {
    return null;
  }
  if (parent instanceof PsiBinaryExpression) {
    final PsiBinaryExpression binaryExpression = (PsiBinaryExpression)parent;
    final PsiExpression lOperand = ParenthesesUtils.stripParentheses(binaryExpression.getLOperand());
    final PsiExpression rOperand = ParenthesesUtils.stripParentheses(binaryExpression.getROperand());
    final PsiExpression replacement;
    if (ExpressionUtils.isEmptyStringLiteral(lOperand)) {
      replacement = rOperand;
    }
    else {
      replacement = lOperand;
    }
    return replacement == null ? "" : buildReplacement(replacement, false);
  }
  final PsiPolyadicExpression polyadicExpression = (PsiPolyadicExpression)parent;
  final PsiExpression[] operands = polyadicExpression.getOperands();
  final PsiClassType stringType = TypeUtils.getStringType(expression);
  boolean seenString = false;
  boolean seenEmpty = false;
  boolean replaced = false;
  PsiExpression operandToReplace = null;
  final StringBuilder text = new StringBuilder();
  for (PsiExpression operand : operands) {
    if (operandToReplace != null && !replaced) {
      if (ExpressionUtils.hasStringType(operand)) {
        seenString = true;
      }
      if (text.length() > 0) {
        text.append(" + ");
      }
      text.append(buildReplacement(operandToReplace, seenString));
      text.append(" + ");
      text.append(operand.getText());
      replaced = true;
      continue;
    }
    if (operand == expression) {
      seenEmpty = true;
      continue;
    }
    if (seenEmpty && !replaced) {
      operandToReplace = operand;
      continue;
    }
    if (stringType.equals(operand.getType())) {
      seenString = true;
    }
    if (text.length() > 0) {
      text.append(" + ");
    }
    text.append(operand.getText());
  }
  if (!replaced && operandToReplace != null) {
    text.append(" + ");
    text.append(buildReplacement(operandToReplace, seenString));
  }
  return text.toString();
}
 
開發者ID:lshain-android-source,項目名稱:tools-idea,代碼行數:64,代碼來源:TrivialStringConcatenationInspection.java


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