use of com.intellij.psi.PsiMethodCallExpression 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.PsiMethodCallExpression 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.PsiMethodCallExpression in project intellij-community by JetBrains.
the class AssertEqualsBetweenInconvertibleTypesTestNGInspection method buildVisitor.
@NotNull
@Override
public PsiElementVisitor buildVisitor(@NotNull ProblemsHolder holder, boolean isOnTheFly) {
return new JavaElementVisitor() {
@Override
public void visitMethodCallExpression(@NotNull PsiMethodCallExpression expression) {
super.visitMethodCallExpression(expression);
final String errorMessage = AssertHint.areExpectedActualTypesCompatible(expression, true);
if (errorMessage != null) {
final PsiElement referenceNameElement = expression.getMethodExpression().getReferenceNameElement();
if (referenceNameElement == null) {
return;
}
holder.registerProblem(referenceNameElement, errorMessage);
}
}
};
}
use of com.intellij.psi.PsiMethodCallExpression in project android by JetBrains.
the class InlinedResource method getResolvedString.
@Nullable
public String getResolvedString() {
if (myResourceRepository != null) {
if (myResourceRepository.hasResourceItem(myType, myKey)) {
FolderConfiguration referenceConfig = new FolderConfiguration();
// Nonexistent language qualifier: trick it to fall back to the default locale
referenceConfig.setLocaleQualifier(new LocaleQualifier("xx"));
ResourceValue value = myResourceRepository.getConfiguredValue(myType, myKey, referenceConfig);
if (value != null) {
String text = value.getValue();
if (text != null) {
if (myElement instanceof PsiMethodCallExpression) {
text = insertArguments((PsiMethodCallExpression) myElement, text);
}
if (myType == ResourceType.PLURALS && text.startsWith(STRING_PREFIX)) {
value = myResourceRepository.getConfiguredValue(ResourceType.STRING, text.substring(STRING_PREFIX.length()), referenceConfig);
if (value != null && value.getValue() != null) {
text = value.getValue();
return '"' + StringUtil.shortenTextWithEllipsis(text, FOLD_MAX_LENGTH - 2, 0) + '"';
}
}
if (myType == ResourceType.STRING || myElement instanceof XmlAttributeValue) {
return '"' + StringUtil.shortenTextWithEllipsis(text, FOLD_MAX_LENGTH - 2, 0) + '"';
} else if (text.length() <= 1) {
// This is similar to how IntelliJ 14 handles call parameters
return myKey + ": " + text;
} else {
return StringUtil.shortenTextWithEllipsis(text, FOLD_MAX_LENGTH, 0);
}
}
}
}
}
return null;
}
use of com.intellij.psi.PsiMethodCallExpression in project Main by SpartanRefactoring.
the class LispLastElementTest method testCreateReplacement2.
public void testCreateReplacement2() {
PsiMethodCallExpression methodCallExpression = createTestMethodCallExpression("x.get", "x.size()-1");
assert new LispLastElement().canTip(methodCallExpression);
assertEquals("last(x)", new LispLastElement().createReplacement(methodCallExpression).getText());
}
Aggregations