本文整理汇总了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);
}
}
示例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());
}
示例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();
}
示例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());
}
示例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();
}