use of com.intellij.psi.javadoc.PsiDocComment in project intellij-community by JetBrains.
the class SuppressFix method suppressByDocComment.
private void suppressByDocComment(@NotNull Project project, PsiJavaDocumentedElement container) {
PsiDocComment docComment = container.getDocComment();
PsiManager manager = PsiManager.getInstance(project);
if (docComment == null) {
String commentText = "/** @" + SuppressionUtilCore.SUPPRESS_INSPECTIONS_TAG_NAME + " " + getID(container) + "*/";
docComment = JavaPsiFacade.getInstance(manager.getProject()).getElementFactory().createDocCommentFromText(commentText);
PsiElement firstChild = container.getFirstChild();
container.addBefore(docComment, firstChild);
} else {
PsiDocTag noInspectionTag = docComment.findTagByName(SuppressionUtilCore.SUPPRESS_INSPECTIONS_TAG_NAME);
if (noInspectionTag != null) {
String tagText = noInspectionTag.getText() + ", " + getID(container);
noInspectionTag.replace(JavaPsiFacade.getInstance(manager.getProject()).getElementFactory().createDocTagFromText(tagText));
} else {
String tagText = "@" + SuppressionUtilCore.SUPPRESS_INSPECTIONS_TAG_NAME + " " + getID(container);
docComment.add(JavaPsiFacade.getInstance(manager.getProject()).getElementFactory().createDocTagFromText(tagText));
}
}
}
use of com.intellij.psi.javadoc.PsiDocComment in project intellij-community by JetBrains.
the class MoveJavaInnerHandler method copyClass.
@NotNull
@Override
public PsiClass copyClass(@NotNull final MoveInnerOptions options) {
PsiClass innerClass = options.getInnerClass();
PsiClass newClass;
if (options.getTargetContainer() instanceof PsiDirectory) {
newClass = createNewClass(options);
PsiDocComment defaultDocComment = newClass.getDocComment();
if (defaultDocComment != null && innerClass.getDocComment() == null) {
final CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(defaultDocComment.getProject());
innerClass = (PsiClass) codeStyleManager.reformat(innerClass.addAfter(defaultDocComment, null).getParent());
}
newClass = (PsiClass) newClass.replace(innerClass);
PsiUtil.setModifierProperty(newClass, PsiModifier.STATIC, false);
PsiUtil.setModifierProperty(newClass, PsiModifier.PRIVATE, false);
PsiUtil.setModifierProperty(newClass, PsiModifier.PROTECTED, false);
final boolean makePublic = needPublicAccess(options.getOuterClass(), options.getTargetContainer());
if (makePublic) {
PsiUtil.setModifierProperty(newClass, PsiModifier.PUBLIC, true);
}
} else {
newClass = (PsiClass) options.getTargetContainer().add(innerClass);
}
newClass.setName(options.getNewClassName());
return newClass;
}
use of com.intellij.psi.javadoc.PsiDocComment in project intellij-community by JetBrains.
the class JavaRefactoringSupportProvider method isElementWithComment.
private static boolean isElementWithComment(final PsiElement[] scopeElements) {
if (scopeElements.length > 2)
return false;
PsiDocComment comment = null;
PsiDocCommentOwner owner = null;
for (PsiElement element : scopeElements) {
if (element instanceof PsiDocComment) {
comment = (PsiDocComment) element;
} else if (element instanceof PsiDocCommentOwner)
owner = (PsiDocCommentOwner) element;
}
return comment != null && comment.getOwner() == owner;
}
use of com.intellij.psi.javadoc.PsiDocComment in project intellij-community by JetBrains.
the class JavaFoldingBuilderBase method addElementsToFold.
private void addElementsToFold(@NotNull List<FoldingDescriptor> list, @NotNull PsiClass aClass, @NotNull Document document, boolean foldJavaDocs, boolean quick) {
if (!(aClass.getParent() instanceof PsiJavaFile) || ((PsiJavaFile) aClass.getParent()).getClasses().length > 1) {
addToFold(list, aClass, document, true);
}
PsiDocComment docComment;
if (foldJavaDocs) {
docComment = aClass.getDocComment();
if (docComment != null) {
addToFold(list, docComment, document, true);
}
}
addAnnotationsToFold(aClass.getModifierList(), list, document);
PsiElement[] children = aClass.getChildren();
Set<PsiElement> processedComments = new HashSet<>();
for (PsiElement child : children) {
ProgressIndicatorProvider.checkCanceled();
if (child instanceof PsiMethod) {
PsiMethod method = (PsiMethod) child;
boolean oneLiner = addOneLineMethodFolding(list, method);
if (!oneLiner) {
addToFold(list, method, document, true);
}
addAnnotationsToFold(method.getModifierList(), list, document);
if (foldJavaDocs) {
docComment = method.getDocComment();
if (docComment != null) {
addToFold(list, docComment, document, true);
}
}
PsiCodeBlock body = method.getBody();
if (body != null && !oneLiner) {
addCodeBlockFolds(body, list, processedComments, document, quick);
}
} else if (child instanceof PsiField) {
PsiField field = (PsiField) child;
if (foldJavaDocs) {
docComment = field.getDocComment();
if (docComment != null) {
addToFold(list, docComment, document, true);
}
}
addAnnotationsToFold(field.getModifierList(), list, document);
PsiExpression initializer = field.getInitializer();
if (initializer != null) {
addCodeBlockFolds(initializer, list, processedComments, document, quick);
} else if (field instanceof PsiEnumConstant) {
addCodeBlockFolds(field, list, processedComments, document, quick);
}
} else if (child instanceof PsiClassInitializer) {
PsiClassInitializer initializer = (PsiClassInitializer) child;
addToFold(list, initializer, document, true);
addCodeBlockFolds(initializer, list, processedComments, document, quick);
} else if (child instanceof PsiClass) {
addElementsToFold(list, (PsiClass) child, document, true, quick);
} else if (child instanceof PsiComment) {
addCommentFolds((PsiComment) child, processedComments, list);
}
}
}
use of com.intellij.psi.javadoc.PsiDocComment in project intellij-community by JetBrains.
the class JCiPUtil method isImmutable.
public static boolean isImmutable(@NotNull PsiClass aClass) {
final PsiAnnotation annotation = AnnotationUtil.findAnnotation(aClass, ConcurrencyAnnotationsManager.getInstance(aClass.getProject()).getImmutableAnnotations());
if (annotation != null) {
return true;
}
final PsiDocComment comment = aClass.getDocComment();
return comment != null && comment.findTagByName("@Immutable") != null;
}
Aggregations