use of com.intellij.psi.PsiExpression in project timber by JakeWharton.
the class WrongTimberUsageDetector method checkTagLength.
private static void checkTagLength(JavaContext context, PsiMethodCallExpression call) {
PsiExpression argument = call.getArgumentList().getExpressions()[0];
String tag = findLiteralValue(argument);
if (tag != null && tag.length() > 23) {
String message = String.format("The logging tag can be at most 23 characters, was %1$d (%2$s)", tag.length(), tag);
context.report(ISSUE_TAG_LENGTH, argument, context.getLocation(argument), message);
}
}
use of com.intellij.psi.PsiExpression in project intellij-community by JetBrains.
the class InputValidator method isOK.
public boolean isOK(IntroduceVariableSettings settings) {
String name = settings.getEnteredName();
final PsiElement anchor;
final boolean replaceAllOccurrences = settings.isReplaceAllOccurrences();
if (replaceAllOccurrences) {
anchor = myAnchorStatementIfAll;
} else {
anchor = myAnchorStatement;
}
final PsiElement scope = anchor.getParent();
if (scope == null)
return true;
final MultiMap<PsiElement, String> conflicts = new MultiMap<>();
final HashSet<PsiVariable> reportedVariables = new HashSet<>();
JavaUnresolvableLocalCollisionDetector.CollidingVariableVisitor visitor = new JavaUnresolvableLocalCollisionDetector.CollidingVariableVisitor() {
public void visitCollidingElement(PsiVariable collidingVariable) {
if (!reportedVariables.contains(collidingVariable)) {
reportedVariables.add(collidingVariable);
String message = RefactoringBundle.message("introduced.variable.will.conflict.with.0", RefactoringUIUtil.getDescription(collidingVariable, true));
conflicts.putValue(collidingVariable, message);
}
}
};
JavaUnresolvableLocalCollisionDetector.visitLocalsCollisions(anchor, name, scope, anchor, visitor);
if (replaceAllOccurrences) {
final PsiExpression[] occurences = myOccurenceManager.getOccurrences();
for (PsiExpression occurence : occurences) {
IntroduceVariableBase.checkInLoopCondition(occurence, conflicts);
}
} else {
IntroduceVariableBase.checkInLoopCondition(myOccurenceManager.getMainOccurence(), conflicts);
}
if (conflicts.size() > 0) {
return myIntroduceVariableBase.reportConflicts(conflicts, myProject, settings);
} else {
return true;
}
}
use of com.intellij.psi.PsiExpression in project intellij-community by JetBrains.
the class ReplaceParameterAssignmentWithCall method fixUsage.
public void fixUsage() throws IncorrectOperationException {
final PsiAssignmentExpression assignment = PsiTreeUtil.getParentOfType(expression, PsiAssignmentExpression.class);
assert assignment != null;
final PsiExpression rhs = assignment.getRExpression();
if (rhs == null) {
return;
}
final String rhsText = rhs.getText();
final String operator = assignment.getOperationSign().getText();
final String newExpression;
if ("=".equals(operator)) {
newExpression = newParameterName + '.' + setterName + '(' + rhsText + ')';
} else {
final String strippedOperator = operator.substring(0, operator.length() - 1);
newExpression = newParameterName + '.' + setterName + '(' + newParameterName + '.' + getterName + "()" + strippedOperator + rhsText + ')';
}
MutationUtils.replaceExpression(newExpression, assignment);
}
use of com.intellij.psi.PsiExpression in project intellij-community by JetBrains.
the class SimplifiableConditionalExpressionInspection method calculateReplacementExpression.
@NonNls
static String calculateReplacementExpression(PsiConditionalExpression expression) {
final PsiExpression thenExpression = expression.getThenExpression();
final PsiExpression elseExpression = expression.getElseExpression();
final PsiExpression condition = expression.getCondition();
assert thenExpression != null;
assert elseExpression != null;
if (EquivalenceChecker.getCanonicalPsiEquivalence().expressionsAreEquivalent(BoolUtils.getNegated(thenExpression), elseExpression)) {
return ParenthesesUtils.getText(condition, ParenthesesUtils.EQUALITY_PRECEDENCE) + " != " + BoolUtils.getNegatedExpressionText(thenExpression, ParenthesesUtils.EQUALITY_PRECEDENCE);
} else if (EquivalenceChecker.getCanonicalPsiEquivalence().expressionsAreEquivalent(thenExpression, BoolUtils.getNegated(elseExpression))) {
return ParenthesesUtils.getText(condition, ParenthesesUtils.EQUALITY_PRECEDENCE) + " == " + ParenthesesUtils.getText(thenExpression, ParenthesesUtils.EQUALITY_PRECEDENCE);
}
if (BoolUtils.isTrue(thenExpression)) {
final String elseExpressionText = ParenthesesUtils.getText(elseExpression, ParenthesesUtils.OR_PRECEDENCE);
return ParenthesesUtils.getText(condition, ParenthesesUtils.OR_PRECEDENCE) + " || " + elseExpressionText;
} else if (BoolUtils.isFalse(thenExpression)) {
@NonNls final String elseExpressionText = ParenthesesUtils.getText(elseExpression, ParenthesesUtils.AND_PRECEDENCE);
return BoolUtils.getNegatedExpressionText(condition, ParenthesesUtils.AND_PRECEDENCE) + " && " + elseExpressionText;
}
if (BoolUtils.isFalse(elseExpression)) {
@NonNls final String thenExpressionText = ParenthesesUtils.getText(thenExpression, ParenthesesUtils.AND_PRECEDENCE);
return ParenthesesUtils.getText(condition, ParenthesesUtils.AND_PRECEDENCE) + " && " + thenExpressionText;
} else {
@NonNls final String thenExpressionText = ParenthesesUtils.getText(thenExpression, ParenthesesUtils.OR_PRECEDENCE);
return BoolUtils.getNegatedExpressionText(condition, ParenthesesUtils.OR_PRECEDENCE) + " || " + thenExpressionText;
}
}
use of com.intellij.psi.PsiExpression in project intellij-community by JetBrains.
the class AddThisQualifierFix method doFix.
@Override
public void doFix(Project project, ProblemDescriptor descriptor) throws IncorrectOperationException {
final PsiReferenceExpression expression = (PsiReferenceExpression) descriptor.getPsiElement();
if (expression.getQualifierExpression() != null) {
return;
}
final PsiExpression thisQualifier = ExpressionUtils.getQualifierOrThis(expression);
@NonNls final String newExpression = thisQualifier.getText() + "." + expression.getText();
PsiReplacementUtil.replaceExpressionAndShorten(expression, newExpression);
}
Aggregations