本文整理汇总了Java中com.siyeh.ig.psiutils.ExpressionUtils.hasStringType方法的典型用法代码示例。如果您正苦于以下问题:Java ExpressionUtils.hasStringType方法的具体用法?Java ExpressionUtils.hasStringType怎么用?Java ExpressionUtils.hasStringType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.siyeh.ig.psiutils.ExpressionUtils
的用法示例。
在下文中一共展示了ExpressionUtils.hasStringType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: containsNonConstantConcatenation
import com.siyeh.ig.psiutils.ExpressionUtils; //导入方法依赖的package包/类
private boolean containsNonConstantConcatenation(@Nullable PsiExpression expression) {
if (expression instanceof PsiParenthesizedExpression) {
final PsiParenthesizedExpression parenthesizedExpression = (PsiParenthesizedExpression)expression;
return containsNonConstantConcatenation(parenthesizedExpression.getExpression());
}
else if (expression instanceof PsiPolyadicExpression) {
final PsiPolyadicExpression polyadicExpression = (PsiPolyadicExpression)expression;
if (!ExpressionUtils.hasStringType(polyadicExpression)) {
return false;
}
if (!JavaTokenType.PLUS.equals(polyadicExpression.getOperationTokenType())) {
return false;
}
final PsiExpression[] operands = polyadicExpression.getOperands();
for (PsiExpression operand : operands) {
if (!ExpressionUtils.isEvaluatedAtCompileTime(operand)) {
return true;
}
}
}
return false;
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:StringConcatenationArgumentToLogCallInspectionBase.java
示例2: 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);
}
}
示例3: visitPolyadicExpression
import com.siyeh.ig.psiutils.ExpressionUtils; //导入方法依赖的package包/类
@Override
public void visitPolyadicExpression(PsiPolyadicExpression expression) {
super.visitPolyadicExpression(expression);
final IElementType tokenType = expression.getOperationTokenType();
if (!JavaTokenType.PLUS.equals(tokenType) || !ExpressionUtils.hasStringType(expression)) {
return;
}
final boolean formatCall = FormatUtils.isFormatCallArgument(expression);
final PsiExpression[] operands = expression.getOperands();
PsiExpression lhs = operands[0];
for (int i = 1; i < operands.length; i++) {
final PsiExpression rhs = operands[i];
if (isMissingWhitespace(lhs, rhs, formatCall)) {
final PsiJavaToken token = expression.getTokenBeforeOperand(rhs);
if (token != null) {
registerError(token);
}
}
lhs = rhs;
}
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:StringConcatenationMissingWhitespaceInspection.java
示例4: 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);
}
示例5: containsNonConstantConcatenation
import com.siyeh.ig.psiutils.ExpressionUtils; //导入方法依赖的package包/类
private static boolean containsNonConstantConcatenation(@Nullable PsiExpression expression) {
if (expression instanceof PsiParenthesizedExpression) {
final PsiParenthesizedExpression parenthesizedExpression = (PsiParenthesizedExpression)expression;
return containsNonConstantConcatenation(parenthesizedExpression.getExpression());
}
else if (expression instanceof PsiPolyadicExpression) {
final PsiPolyadicExpression polyadicExpression = (PsiPolyadicExpression)expression;
if (!ExpressionUtils.hasStringType(polyadicExpression)) {
return false;
}
if (!JavaTokenType.PLUS.equals(polyadicExpression.getOperationTokenType())) {
return false;
}
final PsiExpression[] operands = polyadicExpression.getOperands();
for (PsiExpression operand : operands) {
if (!ExpressionUtils.isEvaluatedAtCompileTime(operand)) {
return true;
}
}
}
return false;
}
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:23,代码来源:StringConcatenationArgumentToLogCallInspection.java
示例6: 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;
}
final String lhsText = lhs.getText();
if (PsiKeyword.NULL.equals(lhsText)) {
return;
}
final String rhsText = rhs.getText();
if (PsiKeyword.NULL.equals(rhsText)) {
return;
}
final PsiJavaToken sign = expression.getOperationSign();
registerError(sign);
}
示例7: 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() + ')';
}
示例8: visitMethodCallExpression
import com.siyeh.ig.psiutils.ExpressionUtils; //导入方法依赖的package包/类
@Override
public void visitMethodCallExpression(@NotNull PsiMethodCallExpression expression) {
super.visitMethodCallExpression(expression);
final PsiExpressionList argumentList = expression.getArgumentList();
final PsiExpression[] arguments = argumentList.getExpressions();
if (arguments.length == 0) {
return;
}
final PsiExpression xpathArgument = arguments[0];
if (!ExpressionUtils.hasStringType(xpathArgument)) {
return;
}
if (!PsiUtil.isConstantExpression(xpathArgument)) {
return;
}
final PsiType type = xpathArgument.getType();
if (type == null) {
return;
}
final String value = (String)ConstantExpressionUtil.computeCastTo(xpathArgument, type);
if (value == null) {
return;
}
if (!callTakesXPathExpression(expression)) {
return;
}
final XPathFactory xpathFactory = XPathFactory.newInstance();
final XPath xpath = xpathFactory.newXPath();
//noinspection UnusedCatchParameter,ProhibitedExceptionCaught
try {
xpath.compile(value);
}
catch (XPathExpressionException ignore) {
registerError(xpathArgument);
}
}
示例9: 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) {
checkExpression(operand);
}
}
示例10: visitAssignmentExpression
import com.siyeh.ig.psiutils.ExpressionUtils; //导入方法依赖的package包/类
@Override
public void visitAssignmentExpression(@NotNull PsiAssignmentExpression expression) {
super.visitAssignmentExpression(expression);
final IElementType tokenType = expression.getOperationTokenType();
if (!tokenType.equals(JavaTokenType.PLUSEQ)) {
return;
}
final PsiExpression lhs = expression.getLExpression();
if (!ExpressionUtils.hasStringType(lhs)) {
return;
}
final PsiExpression rhs = expression.getRExpression();
checkExpression(rhs);
}
示例11: visitMethodCallExpression
import com.siyeh.ig.psiutils.ExpressionUtils; //导入方法依赖的package包/类
@Override
public void visitMethodCallExpression(PsiMethodCallExpression expression) {
super.visitMethodCallExpression(expression);
if (!FormatUtils.isFormatCall(expression)) {
return;
}
final PsiExpressionList argumentList = expression.getArgumentList();
final PsiExpression formatArgument = FormatUtils.getFormatArgument(argumentList);
if (!ExpressionUtils.hasStringType(formatArgument)) {
return;
}
if (!(formatArgument instanceof PsiPolyadicExpression)) {
return;
}
final PsiPolyadicExpression polyadicExpression = (PsiPolyadicExpression)formatArgument;
final PsiExpression[] operands = polyadicExpression.getOperands();
int count = 0;
for (final PsiExpression operand : operands) {
if (!(operand instanceof PsiReferenceExpression)) {
continue;
}
count++;
if (count > 1) {
break;
}
}
if (count == 0) {
return;
}
registerMethodCallError(expression, Boolean.valueOf(count > 1));
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:32,代码来源:StringConcatenationInFormatCallInspection.java
示例12: buildFixes
import com.siyeh.ig.psiutils.ExpressionUtils; //导入方法依赖的package包/类
@NotNull
@Override
protected InspectionGadgetsFix[] buildFixes(Object... infos) {
final List<InspectionGadgetsFix> result = new ArrayList<InspectionGadgetsFix>();
final PsiElement expression = (PsiElement)infos[0];
PsiElement parent = expression.getParent();
if (parent instanceof PsiExpression) {
final PsiExpression binaryExpression = (PsiExpression)parent;
final PsiType type = binaryExpression.getType();
if (type instanceof PsiPrimitiveType && !type.equals(PsiType.CHAR)) {
final String typeText = type.getCanonicalText();
result.add(new CharUsedInArithmeticContentCastFix(typeText));
}
}
if (!(expression instanceof PsiLiteralExpression)) {
return result.toArray(new InspectionGadgetsFix[result.size()]);
}
while (parent instanceof PsiPolyadicExpression) {
if (ExpressionUtils.hasStringType((PsiExpression)parent)) {
result.add(new CharUsedInArithmeticContentFix());
break;
}
parent = parent.getParent();
}
return result.toArray(new InspectionGadgetsFix[result.size()]);
}
示例13: visitPolyadicExpression
import com.siyeh.ig.psiutils.ExpressionUtils; //导入方法依赖的package包/类
@Override
public void visitPolyadicExpression(@NotNull PsiPolyadicExpression expression) {
super.visitPolyadicExpression(expression);
final PsiType expressionType = expression.getType();
if (expressionType == null ||
PsiType.DOUBLE.equals(expressionType) ||
PsiType.FLOAT.equals(expressionType)) {
return;
}
if (!arithmeticTokens.contains(expression.getOperationTokenType())) {
return;
}
if (ExpressionUtils.hasStringType(expression) || PsiUtilCore.hasErrorElementChild(expression)) {
return;
}
final PsiExpression[] operands = expression.getOperands();
final IElementType tokenType = expression.getOperationTokenType();
final boolean isPointless;
if (tokenType.equals(JavaTokenType.PLUS)) {
isPointless = additionExpressionIsPointless(operands);
}
else if (tokenType.equals(JavaTokenType.MINUS)) {
isPointless = subtractionExpressionIsPointless(operands);
}
else if (tokenType.equals(JavaTokenType.ASTERISK)) {
isPointless = multiplyExpressionIsPointless(operands);
}
else if (tokenType.equals(JavaTokenType.DIV) || tokenType.equals(JavaTokenType.PERC)) {
isPointless = divideExpressionIsPointless(operands);
}
else {
isPointless = false;
}
if (!isPointless) {
return;
}
registerError(expression, expression);
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:39,代码来源:PointlessArithmeticExpressionInspection.java
示例14: visitMethodCallExpression
import com.siyeh.ig.psiutils.ExpressionUtils; //导入方法依赖的package包/类
@Override
public void visitMethodCallExpression(PsiMethodCallExpression expression) {
super.visitMethodCallExpression(expression);
final PsiReferenceExpression methodExpression = expression.getMethodExpression();
final String referenceName = methodExpression.getReferenceName();
if (!logNames.contains(referenceName)) {
return;
}
final PsiMethod method = expression.resolveMethod();
if (method == null) {
return;
}
final PsiClass containingClass = method.getContainingClass();
if (containingClass == null || !"org.slf4j.Logger".equals(containingClass.getQualifiedName())) {
return;
}
final PsiExpressionList argumentList = expression.getArgumentList();
final PsiExpression[] arguments = argumentList.getExpressions();
if (arguments.length == 0) {
return;
}
PsiExpression argument = arguments[0];
if (!ExpressionUtils.hasStringType(argument)) {
if (arguments.length < 2) {
return;
}
argument = arguments[1];
if (!ExpressionUtils.hasStringType(argument)) {
return;
}
}
if (!containsNonConstantConcatenation(argument)) {
return;
}
registerMethodCallError(expression, argument);
}
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:37,代码来源:StringConcatenationArgumentToLogCallInspection.java
示例15: 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() + ')';
}