Search in sources :

Example 16 with GrDocComment

use of org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocComment in project intellij-community by JetBrains.

the class GrParameterImpl method getUseScope.

@Override
@NotNull
public SearchScope getUseScope() {
    if (!isPhysical()) {
        final PsiFile file = getContainingFile();
        final PsiElement context = file.getContext();
        if (context != null)
            return new LocalSearchScope(context);
        return super.getUseScope();
    }
    final PsiElement scope = getDeclarationScope();
    if (scope instanceof GrDocCommentOwner) {
        GrDocCommentOwner owner = (GrDocCommentOwner) scope;
        final GrDocComment comment = owner.getDocComment();
        if (comment != null) {
            return new LocalSearchScope(new PsiElement[] { scope, comment });
        }
    }
    return new LocalSearchScope(scope);
}
Also used : LocalSearchScope(com.intellij.psi.search.LocalSearchScope) GrDocCommentOwner(org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocCommentOwner) GrDocComment(org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocComment) NotNull(org.jetbrains.annotations.NotNull)

Example 17 with GrDocComment

use of org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocComment in project intellij-community by JetBrains.

the class GrPullUpHelper method deleteMemberWithDocComment.

private static void deleteMemberWithDocComment(GrDocCommentOwner docCommentOwner) {
    GrDocComment oldDoc = docCommentOwner.getDocComment();
    if (oldDoc != null) {
        oldDoc.delete();
    }
    docCommentOwner.delete();
}
Also used : GrDocComment(org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocComment)

Example 18 with GrDocComment

use of org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocComment in project intellij-community by JetBrains.

the class GrPullUpHelper method doMoveMethod.

private void doMoveMethod(PsiSubstitutor substitutor, MemberInfo info) {
    GroovyPsiElementFactory elementFactory = GroovyPsiElementFactory.getInstance(myProject);
    GrMethod method = (GrMethod) info.getMember();
    PsiMethod sibling = method;
    PsiMethod anchor = null;
    while (sibling != null) {
        sibling = PsiTreeUtil.getNextSiblingOfType(sibling, PsiMethod.class);
        if (sibling != null) {
            anchor = MethodSignatureUtil.findMethodInSuperClassBySignatureInDerived(method.getContainingClass(), myTargetSuperClass, sibling.getSignature(PsiSubstitutor.EMPTY), false);
            if (anchor != null) {
                break;
            }
        }
    }
    GrMethod methodCopy = (GrMethod) method.copy();
    if (method.findSuperMethods(myTargetSuperClass).length == 0) {
        deleteOverrideAnnotationIfFound(methodCopy);
    }
    final boolean isOriginalMethodAbstract = method.hasModifierProperty(PsiModifier.ABSTRACT) || method.hasModifierProperty(PsiModifier.DEFAULT);
    if (myTargetSuperClass.isInterface() || info.isToAbstract()) {
        GroovyChangeContextUtil.clearContextInfo(method);
        RefactoringUtil.makeMethodAbstract(myTargetSuperClass, methodCopy);
        if (myTargetSuperClass.isInterface()) {
            PsiUtil.setModifierProperty(methodCopy, PsiModifier.ABSTRACT, false);
        }
        replaceMovedMemberTypeParameters(methodCopy, PsiUtil.typeParametersIterable(mySourceClass), substitutor, elementFactory);
        final GrMethod movedElement = anchor != null ? (GrMethod) myTargetSuperClass.addBefore(methodCopy, anchor) : (GrMethod) myTargetSuperClass.add(methodCopy);
        CodeStyleSettings styleSettings = CodeStyleSettingsManager.getSettings(method.getProject());
        if (styleSettings.INSERT_OVERRIDE_ANNOTATION) {
            if (PsiUtil.isLanguageLevel5OrHigher(mySourceClass) && !myTargetSuperClass.isInterface() || PsiUtil.isLanguageLevel6OrHigher(mySourceClass)) {
                new AddAnnotationFix(CommonClassNames.JAVA_LANG_OVERRIDE, method).invoke(method.getProject(), null, mySourceClass.getContainingFile());
            }
        }
        GrDocComment oldDoc = method.getDocComment();
        if (oldDoc != null) {
            GrDocCommentUtil.setDocComment(movedElement, oldDoc);
        }
        myDocCommentPolicy.processCopiedJavaDoc(methodCopy.getDocComment(), oldDoc, isOriginalMethodAbstract);
        myMembersAfterMove.add(movedElement);
        if (isOriginalMethodAbstract) {
            deleteMemberWithDocComment(method);
        }
    } else {
        if (isOriginalMethodAbstract) {
            PsiUtil.setModifierProperty(myTargetSuperClass, PsiModifier.ABSTRACT, true);
        }
        fixReferencesToStatic(methodCopy);
        replaceMovedMemberTypeParameters(methodCopy, PsiUtil.typeParametersIterable(mySourceClass), substitutor, elementFactory);
        final PsiMethod superClassMethod = myTargetSuperClass.findMethodBySignature(methodCopy, false);
        Language language = myTargetSuperClass.getLanguage();
        final PsiMethod movedElement;
        if (superClassMethod != null && superClassMethod.hasModifierProperty(PsiModifier.ABSTRACT)) {
            movedElement = (PsiMethod) superClassMethod.replace(convertMethodToLanguage(methodCopy, language));
        } else {
            movedElement = anchor != null ? (PsiMethod) myTargetSuperClass.addBefore(convertMethodToLanguage(methodCopy, language), anchor) : (PsiMethod) myTargetSuperClass.add(convertMethodToLanguage(methodCopy, language));
            myMembersAfterMove.add(movedElement);
        }
        if (movedElement instanceof GrMethod) {
            GrDocCommentUtil.setDocComment((GrDocCommentOwner) movedElement, method.getDocComment());
        }
        deleteMemberWithDocComment(method);
    }
}
Also used : GroovyPsiElementFactory(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory) CodeStyleSettings(com.intellij.psi.codeStyle.CodeStyleSettings) Language(com.intellij.lang.Language) GrMethod(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod) AddAnnotationFix(com.intellij.codeInsight.intention.AddAnnotationFix) GrDocComment(org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocComment)

Example 19 with GrDocComment

use of org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocComment in project intellij-community by JetBrains.

the class GroovyPsiElementFactoryImpl method createDocMemberReferenceFromText.

@NotNull
@Override
public GrDocMemberReference createDocMemberReferenceFromText(@NotNull String className, @NotNull String text) {
    PsiFile file = createGroovyFileChecked("/** @see " + className + "#" + text + " */");
    PsiElement element = file.getFirstChild();
    assert element instanceof GrDocComment;
    GrDocTag tag = PsiTreeUtil.getChildOfType(element, GrDocTag.class);
    assert tag != null : "Doc tag points to null";
    return PsiTreeUtil.getChildOfType(tag, GrDocMemberReference.class);
}
Also used : GrDocTag(org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocTag) GrDocComment(org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocComment) NotNull(org.jetbrains.annotations.NotNull)

Example 20 with GrDocComment

use of org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocComment in project intellij-community by JetBrains.

the class MoveClassToNewFileIntention method processIntention.

@Override
protected void processIntention(@NotNull PsiElement element, @NotNull Project project, Editor editor) throws IncorrectOperationException {
    final GrTypeDefinition psiClass = (GrTypeDefinition) element.getParent();
    final String name = psiClass.getName();
    final PsiFile file = psiClass.getContainingFile();
    final String fileExtension = FileUtilRt.getExtension(file.getName());
    final String newFileName = name + "." + fileExtension;
    final PsiDirectory dir = file.getParent();
    if (dir != null) {
        if (dir.findFile(newFileName) != null) {
            if (!ApplicationManager.getApplication().isUnitTestMode()) {
                final String message = GroovyIntentionsBundle.message("file.exists", newFileName, dir.getName());
                CommonRefactoringUtil.showErrorHint(project, editor, message, getFamilyName(), null);
            }
            return;
        }
    }
    final GroovyFile newFile = (GroovyFile) GroovyTemplatesFactory.createFromTemplate(dir, name, newFileName, GroovyTemplates.GROOVY_CLASS, true);
    final GrTypeDefinition template = newFile.getTypeDefinitions()[0];
    final PsiElement newClass = template.replace(psiClass);
    final GrDocComment docComment = psiClass.getDocComment();
    if (newClass instanceof GrTypeDefinition && docComment != null) {
        final GrDocComment newDoc = ((GrTypeDefinition) newClass).getDocComment();
        if (newDoc != null) {
            newDoc.replace(docComment);
        } else {
            final PsiElement parent = newClass.getParent();
            parent.addBefore(docComment, psiClass);
            parent.getNode().addLeaf(GroovyTokenTypes.mNLS, "\n", psiClass.getNode());
        }
        docComment.delete();
    }
    psiClass.delete();
    IntentionUtils.positionCursor(project, newClass.getContainingFile(), newClass.getNavigationElement());
}
Also used : GrTypeDefinition(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition) PsiDirectory(com.intellij.psi.PsiDirectory) PsiFile(com.intellij.psi.PsiFile) GroovyFile(org.jetbrains.plugins.groovy.lang.psi.GroovyFile) PsiElement(com.intellij.psi.PsiElement) GrDocComment(org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocComment)

Aggregations

GrDocComment (org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocComment)22 PsiElement (com.intellij.psi.PsiElement)9 GrDocCommentOwner (org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocCommentOwner)8 NotNull (org.jetbrains.annotations.NotNull)5 Project (com.intellij.openapi.project.Project)4 Nullable (org.jetbrains.annotations.Nullable)4 GrDocTag (org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocTag)4 GrMethod (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod)4 GroovyFile (org.jetbrains.plugins.groovy.lang.psi.GroovyFile)3 GroovyPsiElement (org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement)3 GroovyPsiElementFactory (org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory)3 GrField (org.jetbrains.plugins.groovy.lang.psi.api.statements.GrField)3 GrVariable (org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable)3 GrTypeDefinition (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition)3 ASTNode (com.intellij.lang.ASTNode)2 Document (com.intellij.openapi.editor.Document)2 PsiComment (com.intellij.psi.PsiComment)2 PsiFile (com.intellij.psi.PsiFile)2 PsiDocComment (com.intellij.psi.javadoc.PsiDocComment)2 LocalSearchScope (com.intellij.psi.search.LocalSearchScope)2