@Override @Nullable public PsiDocCommentOwner getContainer(final PsiElement element) { PsiDocCommentOwner container = super.getContainer(element); if (container == null || container instanceof PsiClass){ return null; } while (container != null ) { final PsiClass parentClass = PsiTreeUtil.getParentOfType(container, PsiClass.class); if ((parentClass == null || container.getParent() instanceof PsiDeclarationStatement || container.getParent() instanceof PsiClass) && container instanceof PsiClass){ return container; } container = parentClass; } return container; }
@Override public int getTextStartOffset(@NotNull final PsiElement parent) { PsiElement element = parent; if (element instanceof PsiDocCommentOwner) { PsiDocComment comment = ((PsiDocCommentOwner)element).getDocComment(); if (comment != null) { element = comment.getNextSibling(); while (element instanceof PsiWhiteSpace) { element = element.getNextSibling(); } } } if (element != null) { TextRange range = element.getTextRange(); if (range != null) { return range.getStartOffset(); } LOG.error("Range should not be null: " + element + "; " + element.getClass()); } LOG.error("Element should not be null: " + parent.getText()); return parent.getTextRange().getStartOffset(); }
private void replaceDocComment(@Nullable String newCommentText, @NotNull final PsiDocCommentOwner psiDocCommentOwner) { final PsiDocComment oldComment = psiDocCommentOwner.getDocComment(); if(newCommentText != null) { newCommentText = stripSpaces(newCommentText); } if(newCommentText == null || oldComment == null || newCommentText.equals(oldComment.getText())) { return; } try { PsiComment newComment = JavaPsiFacade.getInstance(myProject).getElementFactory().createCommentFromText(newCommentText, null); final ASTNode oldNode = oldComment.getNode(); final ASTNode newNode = newComment.getNode(); assert oldNode != null && newNode != null; final ASTNode parent = oldNode.getTreeParent(); parent.replaceChild(oldNode, newNode); //important to replace with tree operation to avoid resolve and repository update } catch(IncorrectOperationException e) { LOG.error(e); } }
@Override protected void addCustomElementsToCentralPanel(JPanel panel) { myJavaDocPanel = new DocCommentPanel(RefactoringBundle.message("javadoc.for.abstracts")); myJavaDocPanel.setPolicy(JavaRefactoringSettings.getInstance().PULL_UP_MEMBERS_JAVADOC); boolean hasJavadoc = false; for(MemberInfo info : myMemberInfos) { final PsiMember member = info.getMember(); if(myMemberInfoModel.isAbstractEnabled(info)) { info.setToAbstract(myMemberInfoModel.isAbstractWhenDisabled(info)); if(!hasJavadoc && member instanceof PsiDocCommentOwner && ((PsiDocCommentOwner) member).getDocComment() != null) { hasJavadoc = true; } } } UIUtil.setEnabled(myJavaDocPanel, hasJavadoc, true); panel.add(myJavaDocPanel, BorderLayout.EAST); }
@Override public boolean isEntryPoint(@NotNull PsiElement element) { if (!(element instanceof PsiModifierListOwner)) return false; PsiModifierListOwner owner = (PsiModifierListOwner)element; if (!ADDITIONAL_ANNOTATIONS.isEmpty() && ADDITIONAL_ANNOTATIONS.contains(Deprecated.class.getName()) && element instanceof PsiDocCommentOwner && ((PsiDocCommentOwner)element).isDeprecated()) { return true; } return AnnotationUtil.checkAnnotatedUsingPatterns(owner, ADDITIONAL_ANNOTATIONS) || AnnotationUtil.checkAnnotatedUsingPatterns(owner, getAdditionalAnnotations()); }
@Override protected boolean isDeprecated() { final PsiModifierListOwner element = getValue(); return element != null && element.isValid() && element instanceof PsiDocCommentOwner && ((PsiDocCommentOwner)element).isDeprecated(); }
@Override public boolean isEntryPoint(@NotNull PsiElement element) { if (!(element instanceof PsiModifierListOwner)) return false; PsiModifierListOwner owner = (PsiModifierListOwner)element; if (!ADDITIONAL_ANNOTATIONS.isEmpty() && ADDITIONAL_ANNOTATIONS.contains(Deprecated.class.getName()) && element instanceof PsiDocCommentOwner && ((PsiDocCommentOwner)element).isDeprecated()) { return true; } return AnnotationUtil.isAnnotated(owner, ADDITIONAL_ANNOTATIONS) || AnnotationUtil.isAnnotated(owner, getAdditionalAnnotations()); }
@Override public PsiDocCommentOwner getOwner() { final PsiElement parent = mOwnerComponent; if (parent instanceof PsiDocCommentOwner) { final PsiDocCommentOwner owner = (PsiDocCommentOwner) parent; if (owner.getDocComment() == this) { return owner; } } // HaxeXXX component owners that are not yet adapted to PsiXXX return null; }
@Override public boolean isEntryPoint(@NotNull PsiElement element) { if(!(element instanceof PsiModifierListOwner)) { return false; } PsiModifierListOwner owner = (PsiModifierListOwner) element; if(!ADDITIONAL_ANNOTATIONS.isEmpty() && ADDITIONAL_ANNOTATIONS.contains(Deprecated.class.getName()) && element instanceof PsiDocCommentOwner && ((PsiDocCommentOwner) element).isDeprecated()) { return true; } return AnnotationUtil.isAnnotated(owner, ADDITIONAL_ANNOTATIONS) || AnnotationUtil.isAnnotated(owner, getAdditionalAnnotations()); }
@Nullable protected ClassMember[] chooseMembers(ClassMember[] members, boolean allowEmptySelection, boolean copyJavadocCheckbox, Project project, @Nullable Editor editor) { MemberChooser<ClassMember> chooser = createMembersChooser(members, allowEmptySelection, copyJavadocCheckbox, project); if(editor != null) { final int offset = editor.getCaretModel().getOffset(); ClassMember preselection = null; for(ClassMember member : members) { if(member instanceof PsiElementClassMember) { final PsiDocCommentOwner owner = ((PsiElementClassMember) member).getElement(); if(owner != null) { final TextRange textRange = owner.getTextRange(); if(textRange != null && textRange.contains(offset)) { preselection = member; break; } } } } if(preselection != null) { chooser.selectElements(new ClassMember[]{preselection}); } } chooser.show(); myToCopyJavaDoc = chooser.isCopyJavadoc(); final List<ClassMember> list = chooser.getSelectedElements(); return list == null ? null : list.toArray(new ClassMember[list.size()]); }
@Nullable public static PsiDocCommentOwner findDocumentationDelegate(@NotNull PsiMember method) { for(DocumentationDelegateProvider delegator : EP_NAME.getExtensions()) { PsiDocCommentOwner type = delegator.computeDocumentationDelegate(method); if(type != null) { return type; } } return null; }
private static void checkReferences(PsiElement psiElement, ProblemsHolder holder) { PsiReference[] references = psiElement.getReferences(); PsiReference last = ArrayUtil.getLastElement(references); if (last != null && (!(last instanceof ResolvingHint) || ((ResolvingHint)last).canResolveTo(PsiDocCommentOwner.class))) { PsiElement resolve = last.resolve(); DeprecationInspection.checkDeprecated(resolve, psiElement, last.getRangeInElement(), holder); } }
@Override protected Object intercept(PsiDocCommentOwner proxy, PsiDocCommentOwner target, Method method, Object[] parameters) throws Throwable { if ( processor == null ) { processor = new DocCommentProcessor(target.getContainingFile()); docComment = processor.processDocComment(target.getDocComment()); } return docComment; }
/** * Returns the class, method or field described by the comment. */ @Override @Nullable PsiDocCommentOwner getOwner();
@Override @Nullable public PsiElement getElementMemberSuppressedIn(@NotNull final PsiDocCommentOwner owner, @NotNull final String inspectionToolID) { return JavaSuppressionUtil.getElementMemberSuppressedIn(owner, inspectionToolID); }
@Override @Nullable public PsiElement getDocCommentToolSuppressedIn(@NotNull final PsiDocCommentOwner owner, @NotNull final String inspectionToolID) { return JavaSuppressionUtil.getDocCommentToolSuppressedIn(owner, inspectionToolID); }
@Override public boolean alreadyHas14Suppressions(@NotNull final PsiDocCommentOwner commentOwner) { return JavaSuppressionUtil.alreadyHas14Suppressions(commentOwner); }
public boolean accepts(PsiElement element) { return element instanceof PsiDocCommentOwner || element instanceof PsiDocComment; }
public PsiDocCommentOwnerMemberChooserObject(@NotNull PsiDocCommentOwner owner, final String text, Icon icon) { super(owner, text, icon); }
public PsiDocCommentOwner getPsiDocCommentOwner() { return (PsiDocCommentOwner)getPsiElement(); }
private static boolean isDeprecated(@Nullable PsiElement element) { return element instanceof PsiDocCommentOwner && ((PsiDocCommentOwner)element).isDeprecated(); }
private static boolean isDeprecated(Object psiElement) { return psiElement instanceof PsiDocCommentOwner && ((PsiDocCommentOwner)psiElement).isDeprecated(); }
@Nullable PsiElement getDocCommentToolSuppressedIn(@NotNull PsiDocCommentOwner owner, @NotNull String inspectionToolID);
@Override @Nullable PsiDocCommentOwner getOwner();
@Override @Nullable public PsiElement getElementMemberSuppressedIn(@NotNull final PsiDocCommentOwner owner, final String inspectionToolID) { return JavaSuppressionUtil.getElementMemberSuppressedIn(owner, inspectionToolID); }
@Override @Nullable public PsiElement getDocCommentToolSuppressedIn(@NotNull final PsiDocCommentOwner owner, final String inspectionToolID) { return JavaSuppressionUtil.getDocCommentToolSuppressedIn(owner, inspectionToolID); }
public PsiDocCommentOwnerMemberChooserObject(final PsiDocCommentOwner owner, final String text, Icon icon) { super(owner, text, icon); }