use of com.intellij.psi.PsiType in project intellij-community by JetBrains.
the class SimplifyTernaryOperatorIntention method getElementPredicate.
@NotNull
@Override
protected PsiElementPredicate getElementPredicate() {
return new PsiElementPredicate() {
@Override
public boolean satisfiedBy(PsiElement element) {
if (!(element instanceof GrConditionalExpression)) {
return false;
}
GrConditionalExpression condExp = (GrConditionalExpression) element;
PsiType condType = condExp.getType();
if (condType == null || !PsiType.BOOLEAN.isConvertibleFrom(condType)) {
return false;
}
GrExpression thenBranch = condExp.getThenBranch();
GrExpression elseBranch = condExp.getElseBranch();
Object thenVal = GroovyConstantExpressionEvaluator.evaluate(thenBranch);
if (Boolean.TRUE.equals(thenVal) && elseBranch != null) {
return true;
}
Object elseVal = GroovyConstantExpressionEvaluator.evaluate(elseBranch);
if (thenBranch != null && Boolean.FALSE.equals(elseVal)) {
return true;
}
return false;
}
};
}
use of com.intellij.psi.PsiType in project intellij-community by JetBrains.
the class ConvertIntegerToDecimalPredicate method satisfiedBy.
@Override
public boolean satisfiedBy(PsiElement element) {
if (!(element instanceof GrLiteral)) {
return false;
}
final GrLiteral expression = (GrLiteral) element;
final PsiType type = expression.getType();
if (type == null) {
return false;
}
if (!PsiType.INT.equals(type) && !PsiType.LONG.equals(type) && !type.equalsToText("java.lang.Integer") && !type.equalsToText("java.lang.Long")) {
return false;
}
@NonNls final String text = expression.getText().replaceAll("_", "");
if (text == null || text.length() < 2) {
return false;
}
if ("0".equals(text) || "0L".equals(text) || "0l".equals(text)) {
return false;
}
return text.charAt(0) == '0';
}
use of com.intellij.psi.PsiType in project intellij-community by JetBrains.
the class ConvertIntegerToOctalPredicate method satisfiedBy.
@Override
public boolean satisfiedBy(PsiElement element) {
if (!(element instanceof GrLiteral))
return false;
final GrLiteral expression = (GrLiteral) element;
final PsiType type = expression.getType();
if (type == null)
return false;
if (!PsiType.INT.equals(type) && !PsiType.LONG.equals(type) && !type.equalsToText("java.lang.Integer") && !type.equalsToText("java.lang.Long")) {
return false;
}
@NonNls final String text = expression.getText();
if (text == null || text.isEmpty()) {
return false;
}
if (text.startsWith("0x") || text.startsWith("0X")) {
return true;
}
if (text.startsWith("0b") || text.startsWith("0B")) {
return true;
}
if ("0".equals(text) || "0L".equals(text)) {
return false;
}
return text.charAt(0) != '0';
}
use of com.intellij.psi.PsiType in project intellij-community by JetBrains.
the class IndexingMethodConversionPredicate method satisfiedBy.
@Override
public boolean satisfiedBy(PsiElement element) {
if (!(element instanceof GrMethodCallExpression)) {
return false;
}
if (ErrorUtil.containsError(element)) {
return false;
}
final GrMethodCallExpression callExpression = (GrMethodCallExpression) element;
final GrArgumentList argList = callExpression.getArgumentList();
final GrExpression[] arguments = argList.getExpressionArguments();
final GrExpression invokedExpression = callExpression.getInvokedExpression();
if (!(invokedExpression instanceof GrReferenceExpression)) {
return false;
}
final GrReferenceExpression referenceExpression = (GrReferenceExpression) invokedExpression;
final GrExpression qualifier = referenceExpression.getQualifierExpression();
if (qualifier == null) {
return false;
}
final IElementType referenceType = referenceExpression.getDotTokenType();
if (!GroovyTokenTypes.mDOT.equals(referenceType)) {
return false;
}
final String methodName = referenceExpression.getReferenceName();
if ("getAt".equals(methodName)) {
return arguments.length == 1;
}
if ("get".equals(methodName)) {
final PsiType qualifierType = qualifier.getType();
if (!isMap(qualifierType)) {
return false;
}
return arguments.length == 1;
} else if ("setAt".equals(methodName)) {
return arguments.length == 2;
} else if ("put".equals(methodName)) {
final PsiType qualifierType = qualifier.getType();
if (!isMap(qualifierType)) {
return false;
}
return arguments.length == 2;
}
return false;
}
use of com.intellij.psi.PsiType in project intellij-community by JetBrains.
the class ConvertIntegerToBinaryPredicate method satisfiedBy.
@Override
public boolean satisfiedBy(PsiElement element) {
if (!(element instanceof GrLiteral))
return false;
final GrLiteral expression = (GrLiteral) element;
final PsiType type = expression.getType();
if (type == null)
return false;
if (!PsiType.INT.equals(type) && !PsiType.LONG.equals(type) && !type.equalsToText("java.lang.Integer") && !type.equalsToText("java.lang.Long")) {
return false;
}
@NonNls final String text = expression.getText();
if (text == null || text.isEmpty()) {
return false;
}
if (text.startsWith("0x") || text.startsWith("0X")) {
return true;
}
if (text.startsWith("0b") || text.startsWith("0B")) {
return false;
}
if ("0".equals(text) || "0L".equals(text)) {
return true;
}
return text.charAt(0) != '0';
}
Aggregations