Search in sources :

Example 41 with PsiMethod

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;
}
Also used : MethodIncompleteSignature(com.intellij.compiler.classFilesIndex.impl.MethodIncompleteSignature) PsiMethod(com.intellij.psi.PsiMethod)

Example 42 with PsiMethod

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());
}
Also used : PsiMethod(com.intellij.psi.PsiMethod) PsiReference(com.intellij.psi.PsiReference)

Example 43 with PsiMethod

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();
}
Also used : LinkedHashSet(java.util.LinkedHashSet) NonNls(org.jetbrains.annotations.NonNls) PsiMethod(com.intellij.psi.PsiMethod) PsiClass(com.intellij.psi.PsiClass) PsiFile(com.intellij.psi.PsiFile) PsiElement(com.intellij.psi.PsiElement)

Example 44 with PsiMethod

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);
}
Also used : PsiMethod(com.intellij.psi.PsiMethod) PsiClass(com.intellij.psi.PsiClass) JBList(com.intellij.ui.components.JBList)

Example 45 with PsiMethod

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;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiMethod(com.intellij.psi.PsiMethod) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

PsiMethod (com.intellij.psi.PsiMethod)232 PsiClass (com.intellij.psi.PsiClass)97 PsiElement (com.intellij.psi.PsiElement)71 ArrayList (java.util.ArrayList)24 NotNull (org.jetbrains.annotations.NotNull)22 Nullable (org.jetbrains.annotations.Nullable)19 Project (com.intellij.openapi.project.Project)16 PsiField (com.intellij.psi.PsiField)13 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)12 Location (com.intellij.execution.Location)11 JavaEvaluator (com.android.tools.klint.client.api.JavaEvaluator)9 PsiReference (com.intellij.psi.PsiReference)9 PsiFile (com.intellij.psi.PsiFile)8 PsiAnnotation (com.intellij.psi.PsiAnnotation)7 List (java.util.List)7 Nullable (com.android.annotations.Nullable)6 Module (com.intellij.openapi.module.Module)6 PsiType (com.intellij.psi.PsiType)6 SearchScope (com.intellij.psi.search.SearchScope)6 PsiParameter (com.intellij.psi.PsiParameter)5