Search in sources :

Example 21 with PsiMethod

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

the class Java15FormInspection method checkComponentProperties.

protected void checkComponentProperties(Module module, final IComponent component, final FormErrorCollector collector) {
    final GlobalSearchScope scope = GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module);
    final PsiManager psiManager = PsiManager.getInstance(module.getProject());
    final PsiClass aClass = JavaPsiFacade.getInstance(psiManager.getProject()).findClass(component.getComponentClassName(), scope);
    if (aClass == null) {
        return;
    }
    for (final IProperty prop : component.getModifiedProperties()) {
        final PsiMethod getter = PropertyUtil.findPropertyGetter(aClass, prop.getName(), false, true);
        if (getter == null)
            continue;
        final LanguageLevel languageLevel = LanguageLevelUtil.getEffectiveLanguageLevel(module);
        if (Java15APIUsageInspection.getLastIncompatibleLanguageLevel(getter, languageLevel) != null) {
            registerError(component, collector, prop, "@since " + Java15APIUsageInspection.getShortName(languageLevel));
        }
    }
}
Also used : GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) IProperty(com.intellij.uiDesigner.lw.IProperty) PsiMethod(com.intellij.psi.PsiMethod) LanguageLevel(com.intellij.pom.java.LanguageLevel) PsiClass(com.intellij.psi.PsiClass) PsiManager(com.intellij.psi.PsiManager)

Example 22 with PsiMethod

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

the class GroovyMethodOverrideHandler method handleInsert.

@Override
public void handleInsert(InsertionContext context, LookupElement item) {
    context.getDocument().deleteString(context.getStartOffset(), context.getTailOffset());
    PsiMethod method = (PsiMethod) item.getObject();
    List<PsiMethod> prototypes = OverrideImplementUtil.overrideOrImplementMethod(myPsiClass, method, false);
    context.commitDocument();
    GenerateMembersUtil.insertMembersAtOffset(context.getFile(), context.getStartOffset(), OverrideImplementUtil.convert2GenerationInfos(prototypes));
}
Also used : PsiMethod(com.intellij.psi.PsiMethod)

Example 23 with PsiMethod

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

the class GrMethodMergingContributor method handleAutoCompletionPossibility.

@Override
public AutoCompletionDecision handleAutoCompletionPossibility(@NotNull AutoCompletionContext context) {
    final CompletionParameters parameters = context.getParameters();
    if (parameters.getCompletionType() != CompletionType.SMART && parameters.getCompletionType() != CompletionType.BASIC) {
        return null;
    }
    boolean needInsertBrace = false;
    boolean needInsertParenth = false;
    final LookupElement[] items = context.getItems();
    if (items.length > 1) {
        String commonName = null;
        final ArrayList<PsiMethod> allMethods = new ArrayList<>();
        for (LookupElement item : items) {
            Object o = item.getPsiElement();
            if (item.getUserData(JavaCompletionUtil.FORCE_SHOW_SIGNATURE_ATTR) != null || !(o instanceof PsiMethod)) {
                return AutoCompletionDecision.SHOW_LOOKUP;
            }
            final PsiMethod method = (PsiMethod) o;
            final JavaChainLookupElement chain = item.as(JavaChainLookupElement.CLASS_CONDITION_KEY);
            final String name = method.getName() + "#" + (chain == null ? "" : chain.getQualifier().getLookupString());
            if (commonName != null && !commonName.equals(name)) {
                return AutoCompletionDecision.SHOW_LOOKUP;
            }
            if (hasOnlyClosureParams(method)) {
                needInsertBrace = true;
            } else {
                needInsertParenth = true;
            }
            if (needInsertBrace && needInsertParenth) {
                return AutoCompletionDecision.SHOW_LOOKUP;
            }
            commonName = name;
            allMethods.add(method);
        }
        for (LookupElement item : items) {
            JavaCompletionUtil.putAllMethods(item, allMethods);
        }
        return AutoCompletionDecision.insertItem(JavaMethodMergingContributor.findBestOverload(items));
    }
    return super.handleAutoCompletionPossibility(context);
}
Also used : PsiMethod(com.intellij.psi.PsiMethod) ArrayList(java.util.ArrayList) LookupElement(com.intellij.codeInsight.lookup.LookupElement)

Example 24 with PsiMethod

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

the class CreateParameterFromUsageFix method findScope.

private void findScope(@NotNull final GrReferenceExpression ref, @NotNull final Editor editor, final Project project) {
    PsiElement place = ref;
    final List<GrMethod> scopes = new ArrayList<>();
    while (true) {
        final GrMethod parent = PsiTreeUtil.getParentOfType(place, GrMethod.class);
        if (parent == null)
            break;
        scopes.add(parent);
        place = parent;
    }
    if (scopes.size() == 1) {
        final GrMethod owner = scopes.get(0);
        final PsiMethod toSearchFor;
        toSearchFor = SuperMethodWarningUtil.checkSuperMethod(owner, RefactoringBundle.message("to.refactor"));
        //if it is null, refactoring was canceled
        if (toSearchFor == null)
            return;
        showDialog(toSearchFor, ref, project);
    } else if (scopes.size() > 1) {
        myEnclosingMethodsPopup = MethodOrClosureScopeChooser.create(scopes, editor, this, (owner, element) -> {
            showDialog((PsiMethod) owner, ref, project);
            return null;
        });
        myEnclosingMethodsPopup.showInBestPositionFor(editor);
    }
}
Also used : PsiMethod(com.intellij.psi.PsiMethod) ArrayList(java.util.ArrayList) GrMethod(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod) PsiElement(com.intellij.psi.PsiElement)

Example 25 with PsiMethod

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

the class ConvertJunitAssertionToAssertStatementIntention method processIntention.

@Override
protected void processIntention(@NotNull PsiElement element, @NotNull Project project, Editor editor) throws IncorrectOperationException {
    GrMethodCall methodCall = (GrMethodCall) element;
    PsiMethod method = methodCall.resolveMethod();
    if (method == null)
        return;
    GrStatement replacementElement = getReplacementElement(method, methodCall);
    if (replacementElement == null)
        return;
    ((GrMethodCall) element).replaceWithStatement(replacementElement);
}
Also used : GrMethodCall(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall) PsiMethod(com.intellij.psi.PsiMethod) GrStatement(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement)

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