use of com.intellij.psi.PsiReferenceExpression 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.PsiReferenceExpression 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.PsiReferenceExpression in project intellij-community by JetBrains.
the class GuessContainerElementTypeTest method guessContainerElementTypes.
private PsiType[] guessContainerElementTypes() {
int offset = getEditor().getCaretModel().getOffset();
PsiElement element = getFile().findElementAt(offset);
assertNotNull(element);
PsiElement parent = element.getParent();
assertTrue(parent instanceof PsiReferenceExpression);
PsiExpression expr = (PsiExpression) parent;
return GuessManager.getInstance(getProject()).guessContainerElementType(expr, null);
}
use of com.intellij.psi.PsiReferenceExpression in project intellij-community by JetBrains.
the class ReplaceThisCallWithDelegateCall method fixUsage.
public void fixUsage() throws IncorrectOperationException {
final PsiReferenceExpression methodExpression = call.getMethodExpression();
final PsiExpression qualifierExpression = methodExpression.getQualifierExpression();
if (qualifierExpression == null) {
MutationUtils.replaceExpression(delegateFieldName + '.' + call.getText(), call);
} else {
MutationUtils.replaceExpression(delegateFieldName, qualifierExpression);
}
}
use of com.intellij.psi.PsiReferenceExpression in project intellij-community by JetBrains.
the class InlineLocalTest method performDefInline.
public static void performDefInline(Project project, Editor editor) {
PsiReference reference = TargetElementUtil.findReference(editor);
assertTrue(reference instanceof PsiReferenceExpression);
final PsiElement local = reference.resolve();
assertTrue(local instanceof PsiLocalVariable);
InlineLocalHandler.invoke(project, editor, (PsiLocalVariable) local, (PsiReferenceExpression) reference);
}
Aggregations