Search in sources :

Example 91 with PsiMethod

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

the class MethodInheritanceUtils method calculateSiblingMethods.

public static Set<PsiMethod> calculateSiblingMethods(PsiMethod method) {
    final Set<PsiMethod> siblingMethods = new HashSet<>();
    final Stack<PsiMethod> pendingMethods = new Stack<>();
    pendingMethods.add(method);
    while (!pendingMethods.isEmpty()) {
        final PsiMethod methodToAnalyze = pendingMethods.pop();
        siblingMethods.add(methodToAnalyze);
        final Iterable<PsiMethod> overridingMethods = OverridingMethodsSearch.search(methodToAnalyze, false);
        for (PsiMethod overridingMethod : overridingMethods) {
            if (!siblingMethods.contains(overridingMethod) && !pendingMethods.contains(overridingMethod)) {
                pendingMethods.add(overridingMethod);
            }
        }
        final PsiMethod[] superMethods = methodToAnalyze.findSuperMethods();
        for (PsiMethod superMethod : superMethods) {
            if (!siblingMethods.contains(superMethod) && !pendingMethods.contains(superMethod)) {
                pendingMethods.add(superMethod);
            }
        }
    }
    return siblingMethods;
}
Also used : PsiMethod(com.intellij.psi.PsiMethod) HashSet(java.util.HashSet) Stack(com.intellij.util.containers.Stack)

Example 92 with PsiMethod

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

the class MethodInheritanceUtils method findAvailableSubClassesForMethod.

public static PsiClass[] findAvailableSubClassesForMethod(PsiMethod method) {
    final Iterable<PsiMethod> query = SearchUtils.findOverridingMethods(method);
    final List<PsiClass> sourceClasses = new ArrayList<>();
    for (PsiMethod superMethod : query) {
        final PsiClass containingClass = superMethod.getContainingClass();
        if (!(containingClass instanceof PsiCompiledElement)) {
            sourceClasses.add(containingClass);
        }
    }
    return sourceClasses.toArray(new PsiClass[sourceClasses.size()]);
}
Also used : PsiMethod(com.intellij.psi.PsiMethod) ArrayList(java.util.ArrayList) PsiClass(com.intellij.psi.PsiClass) PsiCompiledElement(com.intellij.psi.PsiCompiledElement)

Example 93 with PsiMethod

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

the class ReturnDocTagInfo method isValidInContext.

@Override
public boolean isValidInContext(PsiElement element) {
    if (!(element instanceof PsiMethod))
        return false;
    PsiMethod method = (PsiMethod) element;
    final PsiType type = method.getReturnType();
    if (type == null)
        return false;
    return !PsiType.VOID.equals(type);
}
Also used : PsiMethod(com.intellij.psi.PsiMethod) PsiType(com.intellij.psi.PsiType)

Example 94 with PsiMethod

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

the class ExtractMethodObjectTest method doTest.

private void doTest(final boolean createInnerClass) throws Exception {
    final String testName = getTestName(false);
    configureByFile("/refactoring/extractMethodObject/" + testName + ".java");
    PsiElement element = TargetElementUtil.findTargetElement(myEditor, TargetElementUtil.ELEMENT_NAME_ACCEPTED);
    assertTrue(element instanceof PsiMethod);
    final PsiMethod method = (PsiMethod) element;
    final ExtractMethodObjectProcessor processor = new ExtractMethodObjectProcessor(getProject(), getEditor(), method.getBody().getStatements(), "InnerClass");
    final ExtractMethodObjectProcessor.MyExtractMethodProcessor extractProcessor = processor.getExtractProcessor();
    processor.setCreateInnerClass(createInnerClass);
    extractProcessor.setShowErrorDialogs(false);
    extractProcessor.prepare();
    extractProcessor.testPrepare();
    ExtractMethodObjectHandler.run(getProject(), getEditor(), processor, extractProcessor);
    checkResultByFile("/refactoring/extractMethodObject/" + testName + ".java" + ".after");
}
Also used : ExtractMethodObjectProcessor(com.intellij.refactoring.extractMethodObject.ExtractMethodObjectProcessor) PsiMethod(com.intellij.psi.PsiMethod) PsiElement(com.intellij.psi.PsiElement)

Example 95 with PsiMethod

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

the class AbstractApplicationConfigurationProducer method isConfigurationFromContext.

@Override
public boolean isConfigurationFromContext(T appConfiguration, ConfigurationContext context) {
    final PsiElement location = context.getPsiLocation();
    final PsiClass aClass = ApplicationConfigurationType.getMainClass(location);
    if (aClass != null && Comparing.equal(JavaExecutionUtil.getRuntimeQualifiedName(aClass), appConfiguration.MAIN_CLASS_NAME)) {
        final PsiMethod method = PsiTreeUtil.getParentOfType(location, PsiMethod.class, false);
        if (method != null && TestFrameworks.getInstance().isTestMethod(method)) {
            return false;
        }
        final Module configurationModule = appConfiguration.getConfigurationModule().getModule();
        if (Comparing.equal(context.getModule(), configurationModule))
            return true;
        ApplicationConfiguration template = (ApplicationConfiguration) context.getRunManager().getConfigurationTemplate(getConfigurationFactory()).getConfiguration();
        final Module predefinedModule = template.getConfigurationModule().getModule();
        if (Comparing.equal(predefinedModule, configurationModule)) {
            return true;
        }
    }
    return false;
}
Also used : PsiMethod(com.intellij.psi.PsiMethod) PsiClass(com.intellij.psi.PsiClass) Module(com.intellij.openapi.module.Module) 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