Search in sources :

Example 81 with PsiMethod

use of com.intellij.psi.PsiMethod in project intellij-community by JetBrains.

the class JavaSuperMethodTest method testDoNotGoToSiblingInheritanceIfInLibrary.

public void testDoNotGoToSiblingInheritanceIfInLibrary() throws Throwable {
    configureByFile(getBasePath() + "OverridingLibrary.java");
    PsiClass aThread = getJavaFacade().findClass("java.lang.Thread");
    PsiMethod startMethod = aThread.findMethodsByName("start", false)[0];
    PsiMethod sibling = FindSuperElementsHelper.getSiblingInheritedViaSubClass(startMethod);
    assertNotNull(sibling);
    Collection<PsiMethod> superMethods = SuperMethodWarningUtil.getSuperMethods(startMethod, aThread, Collections.emptyList());
    assertEmpty(superMethods);
}
Also used : PsiMethod(com.intellij.psi.PsiMethod) PsiClass(com.intellij.psi.PsiClass)

Example 82 with PsiMethod

use of com.intellij.psi.PsiMethod in project intellij-community by JetBrains.

the class ContextConfigurationTest method testMethodInAbstractJUnit3TestCase.

public void testMethodInAbstractJUnit3TestCase() throws Exception {
    String packageName = "abstractTests";
    String shortName = "AbstractTestImpl1";
    String qualifiedName = StringUtil.getQualifiedName(packageName, shortName);
    PsiClass psiClass = findClass(getModule1(), qualifiedName);
    PsiMethod testMethod = psiClass.findMethodsByName(METHOD_NAME, true)[0];
    MapDataContext dataContext = new MapDataContext();
    dataContext.put(CommonDataKeys.PROJECT, myProject);
    if (LangDataKeys.MODULE.getData(dataContext) == null) {
        dataContext.put(LangDataKeys.MODULE, ModuleUtilCore.findModuleForPsiElement(testMethod));
    }
    dataContext.put(Location.DATA_KEY, MethodLocation.elementInClass(testMethod, psiClass));
    ConfigurationContext context = ConfigurationContext.getFromContext(dataContext);
    RunnerAndConfigurationSettings settings = context.getConfiguration();
    JUnitConfiguration configuration = (JUnitConfiguration) settings.getConfiguration();
    checkClassName(qualifiedName, configuration);
    checkMethodName(METHOD_NAME, configuration);
    checkPackage(packageName, configuration);
    checkGeneretedName(configuration, shortName + "." + METHOD_NAME);
}
Also used : MapDataContext(com.intellij.testFramework.MapDataContext) PsiMethod(com.intellij.psi.PsiMethod) PsiClass(com.intellij.psi.PsiClass) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings)

Example 83 with PsiMethod

use of com.intellij.psi.PsiMethod in project intellij-community by JetBrains.

the class ContextConfigurationTest method testJUnitMethodTest.

public void testJUnitMethodTest() {
    PsiClass psiClass = findClass(getModule1(), CLASS_NAME);
    PsiMethod testMethod = psiClass.findMethodsByName(METHOD_NAME, false)[0];
    JUnitConfiguration configuration = createConfiguration(testMethod);
    checkTestObject(JUnitConfiguration.TEST_METHOD, configuration);
    checkClassName(CLASS_NAME, configuration);
    checkMethodName(METHOD_NAME, configuration);
    checkPackage(PACKAGE_NAME, configuration);
    checkGeneretedName(configuration, SHORT_CLASS_NAME + "." + METHOD_NAME);
}
Also used : PsiMethod(com.intellij.psi.PsiMethod) PsiClass(com.intellij.psi.PsiClass)

Example 84 with PsiMethod

use of com.intellij.psi.PsiMethod in project intellij-community by JetBrains.

the class ContextConfigurationTest method testApplication.

public void testApplication() {
    PsiClass psiClass = findClass(getModule1(), CLASS_NAME);
    PsiMethod psiMethod = psiClass.findMethodsByName("main", false)[0];
    ApplicationConfiguration configuration = createConfiguration(psiMethod);
    assertEquals(CLASS_NAME, configuration.MAIN_CLASS_NAME);
    assertEquals(configuration.suggestedName(), configuration.getName());
    assertEquals(SHORT_CLASS_NAME, configuration.getName());
}
Also used : PsiMethod(com.intellij.psi.PsiMethod) PsiClass(com.intellij.psi.PsiClass) ApplicationConfiguration(com.intellij.execution.application.ApplicationConfiguration)

Example 85 with PsiMethod

use of com.intellij.psi.PsiMethod in project intellij-community by JetBrains.

the class GotoImplementationHandlerTest method testMethodReferences.

public void testMethodReferences() {
    PsiFile file = myFixture.addFileToProject("Foo.java", "interface I {void f();}\n" + "class A implements I { public void f(){}}\n" + "class B implements I { public void f(){}}\n" + "class C {\n" + "  void foo(java.util.List<I> l) {l.stream().forEach(I::<caret>f);}" + "}");
    myFixture.configureFromExistingVirtualFile(file.getVirtualFile());
    final PsiElement[] impls = getTargets(file);
    assertEquals(2, impls.length);
    // target are non-deterministic now
    Arrays.sort(impls, (o1, o2) -> {
        String name1 = ((PsiMethod) o1).getContainingClass().getName();
        String name2 = ((PsiMethod) o2).getContainingClass().getName();
        return StringUtil.compare(name1, name2, false);
    });
    final PsiElement method = impls[0];
    assertTrue(method instanceof PsiMethod);
    final PsiClass aClass = ((PsiMethod) method).getContainingClass();
    assertNotNull(aClass);
    assertEquals("A", aClass.getName());
}
Also used : PsiMethod(com.intellij.psi.PsiMethod) PsiClass(com.intellij.psi.PsiClass) PsiFile(com.intellij.psi.PsiFile) PsiElement(com.intellij.psi.PsiElement)

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