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);
}
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();
}
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);
}
}
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);
}
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());
}
Aggregations