Search in sources :

Example 26 with PsiMethod

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

the class GrChangeSignatureHandler method invoke.

private static void invoke(PsiMethod method, final Project project) {
    if (!CommonRefactoringUtil.checkReadOnlyStatus(project, method))
        return;
    if (method instanceof GrReflectedMethod)
        method = ((GrReflectedMethod) method).getBaseMethod();
    PsiMethod newMethod = SuperMethodWarningUtil.checkSuperMethod(method, RefactoringBundle.message("to.refactor"));
    if (newMethod == null)
        return;
    if (!newMethod.equals(method)) {
        ChangeSignatureUtil.invokeChangeSignatureOn(newMethod, project);
        return;
    }
    if (!CommonRefactoringUtil.checkReadOnlyStatus(project, method))
        return;
    //todo
    if (!(method instanceof GrMethod))
        return;
    final GrChangeSignatureDialog dialog = new GrChangeSignatureDialog(project, new GrMethodDescriptor((GrMethod) method), true, null);
    dialog.show();
}
Also used : PsiMethod(com.intellij.psi.PsiMethod) GrReflectedMethod(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrReflectedMethod) GrMethod(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod)

Example 27 with PsiMethod

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

the class GrMemberSelectionTable method getOverrideIcon.

@Override
protected Icon getOverrideIcon(GrMemberInfo memberInfo) {
    PsiMember member = memberInfo.getMember();
    Icon overrideIcon = EMPTY_OVERRIDE_ICON;
    if (member instanceof PsiMethod) {
        if (Boolean.TRUE.equals(memberInfo.getOverrides())) {
            overrideIcon = AllIcons.General.OverridingMethod;
        } else if (Boolean.FALSE.equals(memberInfo.getOverrides())) {
            overrideIcon = AllIcons.General.ImplementingMethod;
        } else {
            overrideIcon = EMPTY_OVERRIDE_ICON;
        }
    }
    return overrideIcon;
}
Also used : PsiMethod(com.intellij.psi.PsiMethod) RowIcon(com.intellij.ui.RowIcon) PsiMember(com.intellij.psi.PsiMember)

Example 28 with PsiMethod

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

the class ClassGenerator method shouldBeGenerated.

private static boolean shouldBeGenerated(PsiMethod method) {
    for (PsiMethod psiMethod : method.findSuperMethods()) {
        if (!psiMethod.hasModifierProperty(PsiModifier.ABSTRACT)) {
            final PsiType type = method.getReturnType();
            final PsiType superType = psiMethod.getReturnType();
            if (type != null && superType != null && !superType.isAssignableFrom(type)) {
                return false;
            }
        }
    }
    return true;
}
Also used : PsiMethod(com.intellij.psi.PsiMethod) PsiType(com.intellij.psi.PsiType)

Example 29 with PsiMethod

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

the class GrChangeSignatureHandler method findTargetMember.

@Override
@Nullable
public PsiElement findTargetMember(PsiElement element) {
    final GrParameterList parameterList = PsiTreeUtil.getParentOfType(element, GrParameterList.class);
    if (parameterList != null) {
        final PsiElement parent = parameterList.getParent();
        if (parent instanceof PsiMethod)
            return parent;
    }
    if (element.getParent() instanceof GrMethod && ((GrMethod) element.getParent()).getNameIdentifierGroovy() == element) {
        return element.getParent();
    }
    final GrCall expression = PsiTreeUtil.getParentOfType(element, GrCall.class);
    if (expression != null) {
        return expression.resolveMethod();
    }
    final PsiReference ref = element.getReference();
    if (ref == null)
        return null;
    return ref.resolve();
}
Also used : GrParameterList(org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameterList) PsiMethod(com.intellij.psi.PsiMethod) GrCall(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrCall) GrMethod(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod) PsiReference(com.intellij.psi.PsiReference) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 30 with PsiMethod

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

the class JavaFXRenameTest method testStaticPropertyMethod.

public void testStaticPropertyMethod() throws Exception {
    final String className = "container.MyCustomContainer";
    final String methodName = "setStaticProp";
    final String newName = "setNewMethodName";
    myFixture.configureByFiles(getTestName(true) + ".fxml", className.replace('.', '/') + ".java");
    final PsiClass psiClass = myFixture.findClass(className);
    assertNotNull(psiClass);
    final PsiMethod[] methods = psiClass.findMethodsByName(methodName, false);
    assertEquals(1, methods.length);
    final PsiMethod method = methods[0];
    final RenameRefactoring rename = new JavaRenameRefactoringImpl(getProject(), method, newName, false, false);
    rename.run();
    myFixture.checkResultByFile(getTestName(true) + "_after.fxml");
    assertMethodExists(psiClass, newName);
}
Also used : JavaRenameRefactoringImpl(com.intellij.refactoring.openapi.impl.JavaRenameRefactoringImpl) PsiMethod(com.intellij.psi.PsiMethod) RenameRefactoring(com.intellij.refactoring.RenameRefactoring) PsiClass(com.intellij.psi.PsiClass)

Aggregations

PsiMethod (com.intellij.psi.PsiMethod)229 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 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 UExpression (org.jetbrains.uast.UExpression)5