Search in sources :

Example 56 with PsiMethod

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

the class MakeMethodStaticTest method perform.

private static void perform(boolean addClassParameter, boolean delegate) {
    PsiElement element = TargetElementUtil.findTargetElement(myEditor, TargetElementUtil.ELEMENT_NAME_ACCEPTED);
    assertTrue(element instanceof PsiMethod);
    PsiMethod method = (PsiMethod) element;
    new MakeMethodStaticProcessor(getProject(), method, new Settings(true, addClassParameter ? "anObject" : null, null, delegate)).run();
}
Also used : PsiMethod(com.intellij.psi.PsiMethod) MakeMethodStaticProcessor(com.intellij.refactoring.makeStatic.MakeMethodStaticProcessor) PsiElement(com.intellij.psi.PsiElement) Settings(com.intellij.refactoring.makeStatic.Settings)

Example 57 with PsiMethod

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

the class MakeMethodStaticTest method performWithFields.

private static void performWithFields(boolean delegate) {
    PsiElement element = TargetElementUtil.findTargetElement(myEditor, TargetElementUtil.ELEMENT_NAME_ACCEPTED);
    assertTrue(element instanceof PsiMethod);
    PsiMethod method = (PsiMethod) element;
    final ArrayList<VariableData> parametersForFields = new ArrayList<>();
    final boolean addClassParameter = MakeStaticUtil.buildVariableData(method, parametersForFields);
    new MakeMethodStaticProcessor(getProject(), method, new Settings(true, addClassParameter ? "anObject" : null, parametersForFields.toArray(new VariableData[parametersForFields.size()]), delegate)).run();
}
Also used : PsiMethod(com.intellij.psi.PsiMethod) ArrayList(java.util.ArrayList) MakeMethodStaticProcessor(com.intellij.refactoring.makeStatic.MakeMethodStaticProcessor) VariableData(com.intellij.refactoring.util.VariableData) PsiElement(com.intellij.psi.PsiElement) Settings(com.intellij.refactoring.makeStatic.Settings)

Example 58 with PsiMethod

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

the class SimpleAccessorReferenceSearcher method processQuery.

@Override
public void processQuery(@NotNull ReferencesSearch.SearchParameters queryParameters, @NotNull Processor<PsiReference> consumer) {
    PsiElement refElement = queryParameters.getElementToSearch();
    if (!(refElement instanceof PsiMethod))
        return;
    addPropertyAccessUsages((PsiMethod) refElement, queryParameters.getEffectiveSearchScope(), queryParameters.getOptimizer());
}
Also used : PsiMethod(com.intellij.psi.PsiMethod) PsiElement(com.intellij.psi.PsiElement)

Example 59 with PsiMethod

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

the class TestDataGuessByExistingFilesUtil method guessTestDataName.

static String guessTestDataName(PsiMethod method) {
    String testName = getTestName(method);
    if (testName == null)
        return null;
    PsiClass psiClass = method.getContainingClass();
    if (psiClass == null)
        return null;
    int count = 5;
    PsiMethod prev = PsiTreeUtil.getPrevSiblingOfType(method, PsiMethod.class);
    while (prev != null && count-- > 0) {
        String s = getFilePath(prev, testName);
        if (s != null)
            return s;
        prev = PsiTreeUtil.getPrevSiblingOfType(prev, PsiMethod.class);
    }
    count = 5;
    PsiMethod next = PsiTreeUtil.getNextSiblingOfType(method, PsiMethod.class);
    while (next != null && count-- > 0) {
        String s = getFilePath(next, testName);
        if (s != null)
            return s;
        next = PsiTreeUtil.getNextSiblingOfType(next, PsiMethod.class);
    }
    return null;
}
Also used : PsiMethod(com.intellij.psi.PsiMethod) PsiClass(com.intellij.psi.PsiClass)

Example 60 with PsiMethod

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

the class TestDataReferenceCollectorTest method doTest.

private List<String> doTest() {
    myFixture.configureByFile("referenceCollector/" + getTestName(false) + ".java");
    final PsiClass[] classes = ((PsiJavaFile) myFixture.getFile()).getClasses();
    for (PsiClass aClass : classes) {
        if (aClass.getName().equals("ATest")) {
            final PsiMethod theMethod = aClass.getMethods()[0];
            return new TestDataReferenceCollector("", theMethod.getName().substring(4)).collectTestDataReferences(theMethod);
        }
    }
    throw new RuntimeException("Couldn't find class ATest in test data file");
}
Also used : PsiMethod(com.intellij.psi.PsiMethod) PsiClass(com.intellij.psi.PsiClass) PsiJavaFile(com.intellij.psi.PsiJavaFile)

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