use of com.intellij.psi.PsiExpression in project intellij-community by JetBrains.
the class JNDIResourceInspection method isResourceCreation.
protected boolean isResourceCreation(PsiExpression expression) {
if (expression instanceof PsiMethodCallExpression) {
final PsiMethodCallExpression methodCallExpression = (PsiMethodCallExpression) expression;
final PsiReferenceExpression methodExpression = methodCallExpression.getMethodExpression();
@NonNls final String methodName = methodExpression.getReferenceName();
if ("list".equals(methodName) || "listBindings".equals(methodName)) {
final PsiExpression qualifier = methodExpression.getQualifierExpression();
if (qualifier == null) {
return false;
}
return TypeUtils.expressionHasTypeOrSubtype(qualifier, "javax.naming.Context");
} else if ("getAll".equals(methodName)) {
final PsiExpression qualifier = methodExpression.getQualifierExpression();
if (qualifier == null) {
return false;
}
return TypeUtils.expressionHasTypeOrSubtype(qualifier, "javax.naming.directory.Attribute", "javax.naming.directory.Attributes") != null;
} else {
return false;
}
} else if (expression instanceof PsiNewExpression) {
return TypeUtils.expressionHasTypeOrSubtype(expression, "javax.naming.InitialContext");
}
return false;
}
use of com.intellij.psi.PsiExpression in project intellij-community by JetBrains.
the class SocketResourceInspection method isResourceCreation.
@Override
protected boolean isResourceCreation(PsiExpression expression) {
if (expression instanceof PsiMethodCallExpression) {
final PsiMethodCallExpression methodCallExpression = (PsiMethodCallExpression) expression;
final PsiReferenceExpression methodExpression = methodCallExpression.getMethodExpression();
@NonNls final String methodName = methodExpression.getReferenceName();
if (!"accept".equals(methodName)) {
return false;
}
final PsiExpression qualifier = methodExpression.getQualifierExpression();
if (qualifier == null || !TypeUtils.expressionHasTypeOrSubtype(qualifier, "java.net.ServerSocket")) {
return false;
}
return TypeUtils.expressionHasTypeOrSubtype(methodCallExpression, "java.net.Socket");
} else if (expression instanceof PsiNewExpression) {
return TypeUtils.expressionHasTypeOrSubtype(expression, "java.net.Socket", "java.net.DatagramSocket", "java.net.ServerSocket") != null;
}
return false;
}
use of com.intellij.psi.PsiExpression in project intellij-community by JetBrains.
the class ConvertToGrayQuickFix method applyFix.
@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
final PsiElement element = descriptor.getPsiElement();
final PsiElementFactory factory = JavaPsiFacade.getInstance(project).getElementFactory();
final PsiExpression expression = factory.createExpressionFromText("com.intellij.ui.Gray._" + myNum, element.getContext());
final PsiElement newElement = element.replace(expression);
JavaCodeStyleManager.getInstance(project).shortenClassReferences(newElement);
}
use of com.intellij.psi.PsiExpression in project intellij-community by JetBrains.
the class ConvertNumberIntentionBase method processIntention.
@Override
protected void processIntention(@NotNull final PsiElement element) throws IncorrectOperationException {
final PsiExpression expression = (PsiExpression) element;
final Number value = (Number) ExpressionUtils.computeConstantExpression(expression);
if (value == null)
return;
final PsiType type = expression.getType();
final boolean negated = ExpressionUtils.isNegative(expression);
final String resultString = convertValue(value, type, negated);
if (resultString == null)
return;
if (negated) {
PsiReplacementUtil.replaceExpression((PsiExpression) expression.getParent(), resultString);
} else {
PsiReplacementUtil.replaceExpression(expression, resultString);
}
}
use of com.intellij.psi.PsiExpression in project intellij-community by JetBrains.
the class FlipConditionalIntention method processIntention.
@Override
public void processIntention(PsiElement element) {
final PsiConditionalExpression exp = (PsiConditionalExpression) element;
final PsiExpression condition = exp.getCondition();
final PsiExpression elseExpression = exp.getElseExpression();
final PsiExpression thenExpression = exp.getThenExpression();
assert elseExpression != null;
assert thenExpression != null;
final String newExpression = BoolUtils.getNegatedExpressionText(condition) + '?' + elseExpression.getText() + ':' + thenExpression.getText();
PsiReplacementUtil.replaceExpression(exp, newExpression);
}
Aggregations