use of com.intellij.psi.PsiMethod in project intellij-community by JetBrains.
the class SearchInitializer method add.
private boolean add(final UsageIndexValue indexValue, final Set<String> excludedParamsTypesQNames) {
final MethodIncompleteSignature methodInvocation = indexValue.getMethodIncompleteSignature();
final PsiMethod[] psiMethods = myContext.resolveNotDeprecated(methodInvocation);
if (psiMethods.length != 0 && MethodChainsSearchUtil.checkParametersForTypesQNames(psiMethods, excludedParamsTypesQNames)) {
final int occurrences = indexValue.getOccurrences();
final MethodsChain methodsChain = new MethodsChain(psiMethods, occurrences, indexValue.getMethodIncompleteSignature().getOwner());
myChains.put(methodInvocation, Pair.create(methodsChain, occurrences));
return true;
}
return false;
}
use of com.intellij.psi.PsiMethod in project smali by JesusFreke.
the class MethodReferenceTest method testSmaliReferenceFromJava.
/**
* Test a reference to a smali method from a java class
*/
public void testSmaliReferenceFromJava() throws Exception {
createFile("blarg.smali", ".class public Lblarg; .super Ljava/lang/Object;" + ".method public static blort(ILjava/lang/String;)V\n" + " .locals 0\n" + " return-void\n" + ".end method\n");
String text = "public class blah { public static void something() {" + "blarg.bl<ref>ort(10, \"bob\");" + "}}";
PsiReference methodReference = configureByFileText(text, "blah.java");
Assert.assertNotNull(methodReference);
PsiMethod resolvedMethod = (PsiMethod) methodReference.resolve();
Assert.assertNotNull(resolvedMethod);
Assert.assertEquals("blort", resolvedMethod.getName());
Assert.assertNotNull(resolvedMethod.getContainingClass());
Assert.assertEquals("blarg", resolvedMethod.getContainingClass().getQualifiedName());
Assert.assertEquals(2, resolvedMethod.getParameterList().getParametersCount());
Assert.assertEquals("int", resolvedMethod.getParameterList().getParameters()[0].getType().getCanonicalText());
Assert.assertEquals("java.lang.String", resolvedMethod.getParameterList().getParameters()[1].getType().getCanonicalText());
Assert.assertNotNull(resolvedMethod.getReturnType());
Assert.assertEquals("void", resolvedMethod.getReturnType().getCanonicalText());
}
use of com.intellij.psi.PsiMethod in project intellij-community by JetBrains.
the class GutterIconTooltipHelper method composeText.
public static String composeText(@NotNull Iterable<? extends PsiElement> elements, @NotNull String start, @NotNull String pattern, @NotNull String postfix) {
@NonNls StringBuilder result = new StringBuilder();
result.append("<html><body>");
result.append(start);
Set<String> names = new LinkedHashSet<>();
for (PsiElement element : elements) {
String descr = "";
if (element instanceof PsiClass) {
String className = ClassPresentationUtil.getNameForClass((PsiClass) element, true);
descr = MessageFormat.format(pattern, className);
} else if (element instanceof PsiMethod) {
String methodName = ((PsiMethod) element).getName();
PsiClass aClass = ((PsiMethod) element).getContainingClass();
String className = aClass == null ? "" : ClassPresentationUtil.getNameForClass(aClass, true);
descr = MessageFormat.format(pattern, methodName, className);
} else if (element instanceof PsiFile) {
descr = MessageFormat.format(pattern, ((PsiFile) element).getName());
}
names.add(descr);
}
@NonNls String sep = "";
for (String name : names) {
result.append(sep);
sep = "<br>";
result.append(name);
}
result.append(postfix);
result.append("</body></html>");
return result.toString();
}
use of com.intellij.psi.PsiMethod in project intellij-community by JetBrains.
the class SuperMethodWarningUtil method checkSuperMethod.
public static void checkSuperMethod(@NotNull PsiMethod method, @NotNull String actionString, @NotNull final PsiElementProcessor<PsiMethod> processor, @NotNull Editor editor) {
PsiClass aClass = method.getContainingClass();
if (aClass == null) {
processor.execute(method);
return;
}
PsiMethod superMethod = method.findDeepestSuperMethod();
if (superMethod == null) {
processor.execute(method);
return;
}
final PsiClass containingClass = superMethod.getContainingClass();
if (containingClass == null) {
processor.execute(method);
return;
}
if (ApplicationManager.getApplication().isUnitTestMode()) {
processor.execute(superMethod);
return;
}
final PsiMethod[] methods = { superMethod, method };
final String renameBase = actionString + " base method";
final String renameCurrent = actionString + " only current method";
final JBList list = new JBList(renameBase, renameCurrent);
JBPopupFactory.getInstance().createListPopupBuilder(list).setTitle(method.getName() + (containingClass.isInterface() && !aClass.isInterface() ? " implements" : " overrides") + " method of " + SymbolPresentationUtil.getSymbolPresentableText(containingClass)).setMovable(false).setResizable(false).setRequestFocus(true).setItemChoosenCallback(() -> {
final Object value = list.getSelectedValue();
if (value instanceof String) {
processor.execute(methods[value.equals(renameBase) ? 0 : 1]);
}
}).createPopup().showInBestPositionFor(editor);
}
use of com.intellij.psi.PsiMethod in project intellij-community by JetBrains.
the class SuperMethodWarningUtil method getSuperMethods.
@NotNull
static Collection<PsiMethod> getSuperMethods(@NotNull PsiMethod method, PsiClass aClass, @NotNull Collection<PsiElement> ignore) {
final Collection<PsiMethod> superMethods = DeepestSuperMethodsSearch.search(method).findAll();
superMethods.removeAll(ignore);
if (superMethods.isEmpty()) {
VirtualFile virtualFile = PsiUtilCore.getVirtualFile(aClass);
if (virtualFile != null && ProjectRootManager.getInstance(aClass.getProject()).getFileIndex().isInSourceContent(virtualFile)) {
PsiMethod siblingSuperMethod = FindSuperElementsHelper.getSiblingInheritedViaSubClass(method);
if (siblingSuperMethod != null) {
superMethods.add(siblingSuperMethod);
}
}
}
return superMethods;
}
Aggregations