Search in sources :

Example 1 with ChangeSignatureHandler

use of com.intellij.refactoring.changeSignature.ChangeSignatureHandler in project intellij-community by JetBrains.

the class ChangeSignatureAction method findTargetMember.

@Nullable
private static PsiElement findTargetMember(@Nullable PsiElement element) {
    if (element == null)
        return null;
    final ChangeSignatureHandler fileHandler = getChangeSignatureHandler(element.getLanguage());
    if (fileHandler != null) {
        final PsiElement targetMember = fileHandler.findTargetMember(element);
        if (targetMember != null)
            return targetMember;
    }
    PsiReference reference = element.getReference();
    if (reference == null && element instanceof PsiNameIdentifierOwner) {
        return element;
    }
    if (reference != null) {
        return reference.resolve();
    }
    return null;
}
Also used : PsiNameIdentifierOwner(com.intellij.psi.PsiNameIdentifierOwner) ChangeSignatureHandler(com.intellij.refactoring.changeSignature.ChangeSignatureHandler) PsiReference(com.intellij.psi.PsiReference) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with ChangeSignatureHandler

use of com.intellij.refactoring.changeSignature.ChangeSignatureHandler in project intellij-community by JetBrains.

the class ChangeSignatureAction method isAvailableOnElementInEditorAndFile.

@Override
protected boolean isAvailableOnElementInEditorAndFile(@NotNull final PsiElement element, @NotNull final Editor editor, @NotNull PsiFile file, @NotNull DataContext context) {
    PsiElement targetMember = findTargetMember(element);
    if (targetMember == null) {
        final ChangeSignatureHandler targetHandler = getChangeSignatureHandler(file.getLanguage());
        if (targetHandler != null) {
            return true;
        }
        return false;
    }
    final ChangeSignatureHandler targetHandler = getChangeSignatureHandler(targetMember.getLanguage());
    if (targetHandler == null)
        return false;
    return true;
}
Also used : ChangeSignatureHandler(com.intellij.refactoring.changeSignature.ChangeSignatureHandler) PsiElement(com.intellij.psi.PsiElement)

Example 3 with ChangeSignatureHandler

use of com.intellij.refactoring.changeSignature.ChangeSignatureHandler in project intellij-community by JetBrains.

the class ChangeSignatureAction method getRefactoringHandler.

@Nullable
@Override
protected RefactoringActionHandler getRefactoringHandler(@NotNull RefactoringSupportProvider provider, final PsiElement element) {
    abstract class ContextAwareChangeSignatureHandler implements RefactoringActionHandler, ContextAwareActionHandler {
    }
    return new ContextAwareChangeSignatureHandler() {

        @Override
        public boolean isAvailableForQuickList(@NotNull Editor editor, @NotNull PsiFile file, @NotNull DataContext dataContext) {
            return findTargetMember(element) != null;
        }

        @Override
        public void invoke(@NotNull Project project, Editor editor, PsiFile file, DataContext dataContext) {
            editor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE);
            final PsiElement targetMember = findTargetMember(element);
            if (targetMember == null) {
                final ChangeSignatureHandler handler = getChangeSignatureHandler(file.getLanguage());
                if (handler != null) {
                    final String notFoundMessage = handler.getTargetNotFoundMessage();
                    if (notFoundMessage != null) {
                        CommonRefactoringUtil.showErrorHint(project, editor, notFoundMessage, ChangeSignatureHandler.REFACTORING_NAME, null);
                    }
                }
                return;
            }
            final ChangeSignatureHandler handler = getChangeSignatureHandler(targetMember.getLanguage());
            if (handler == null)
                return;
            handler.invoke(project, new PsiElement[] { targetMember }, dataContext);
        }

        @Override
        public void invoke(@NotNull Project project, @NotNull PsiElement[] elements, DataContext dataContext) {
            if (elements.length != 1)
                return;
            final PsiElement targetMember = findTargetMember(elements[0]);
            if (targetMember == null)
                return;
            final ChangeSignatureHandler handler = getChangeSignatureHandler(targetMember.getLanguage());
            if (handler == null)
                return;
            handler.invoke(project, new PsiElement[] { targetMember }, dataContext);
        }
    };
}
Also used : Project(com.intellij.openapi.project.Project) DataContext(com.intellij.openapi.actionSystem.DataContext) ChangeSignatureHandler(com.intellij.refactoring.changeSignature.ChangeSignatureHandler) PsiFile(com.intellij.psi.PsiFile) RefactoringActionHandler(com.intellij.refactoring.RefactoringActionHandler) Editor(com.intellij.openapi.editor.Editor) ContextAwareActionHandler(com.intellij.lang.ContextAwareActionHandler) NotNull(org.jetbrains.annotations.NotNull) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

PsiElement (com.intellij.psi.PsiElement)3 ChangeSignatureHandler (com.intellij.refactoring.changeSignature.ChangeSignatureHandler)3 Nullable (org.jetbrains.annotations.Nullable)2 ContextAwareActionHandler (com.intellij.lang.ContextAwareActionHandler)1 DataContext (com.intellij.openapi.actionSystem.DataContext)1 Editor (com.intellij.openapi.editor.Editor)1 Project (com.intellij.openapi.project.Project)1 PsiFile (com.intellij.psi.PsiFile)1 PsiNameIdentifierOwner (com.intellij.psi.PsiNameIdentifierOwner)1 PsiReference (com.intellij.psi.PsiReference)1 RefactoringActionHandler (com.intellij.refactoring.RefactoringActionHandler)1 NotNull (org.jetbrains.annotations.NotNull)1