use of com.intellij.psi.javadoc.PsiDocComment in project intellij-community by JetBrains.
the class GenerateDelegateHandler method clearMethod.
private void clearMethod(PsiMethod method) throws IncorrectOperationException {
LOG.assertTrue(!method.isPhysical());
PsiCodeBlock codeBlock = JavaPsiFacade.getInstance(method.getProject()).getElementFactory().createCodeBlock();
if (method.getBody() != null) {
method.getBody().replace(codeBlock);
} else {
method.add(codeBlock);
}
if (!myToCopyJavaDoc) {
final PsiDocComment docComment = method.getDocComment();
if (docComment != null) {
docComment.delete();
}
}
}
use of com.intellij.psi.javadoc.PsiDocComment in project intellij-community by JetBrains.
the class JavaImplementationTextSelectioner method getTextStartOffset.
@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();
}
use of com.intellij.psi.javadoc.PsiDocComment in project intellij-community by JetBrains.
the class JavaFoldingBuilderBase method isRegionCollapsedByDefault.
@Override
protected boolean isRegionCollapsedByDefault(@NotNull ASTNode node) {
final PsiElement element = SourceTreeToPsiMap.treeElementToPsi(node);
JavaCodeFoldingSettings settings = JavaCodeFoldingSettings.getInstance();
if (element instanceof PsiNewExpression || element instanceof PsiJavaToken && element.getParent() instanceof PsiAnonymousClass) {
return settings.isCollapseLambdas();
}
if (element instanceof PsiJavaToken && element.getParent() instanceof PsiCodeBlock && element.getParent().getParent() instanceof PsiMethod) {
return settings.isCollapseOneLineMethods();
}
if (element instanceof PsiReferenceParameterList) {
return settings.isCollapseConstructorGenericParameters();
}
if (element instanceof PsiImportList) {
return settings.isCollapseImports();
} else if (element instanceof PsiMethod || element instanceof PsiClassInitializer || element instanceof PsiCodeBlock) {
if (element instanceof PsiMethod) {
if (!settings.isCollapseAccessors() && !settings.isCollapseMethods()) {
return false;
}
if (isSimplePropertyAccessor((PsiMethod) element)) {
return settings.isCollapseAccessors();
}
}
return settings.isCollapseMethods();
} else if (element instanceof PsiAnonymousClass) {
return settings.isCollapseAnonymousClasses();
} else if (element instanceof PsiClass) {
return !(element.getParent() instanceof PsiFile) && settings.isCollapseInnerClasses();
} else if (element instanceof PsiDocComment) {
PsiElement parent = element.getParent();
if (parent instanceof PsiJavaFile) {
if (((PsiJavaFile) parent).getName().equals(PsiPackage.PACKAGE_INFO_FILE)) {
return false;
}
PsiElement firstChild = parent.getFirstChild();
if (firstChild instanceof PsiWhiteSpace) {
firstChild = firstChild.getNextSibling();
}
if (element.equals(firstChild)) {
return settings.isCollapseFileHeader();
}
}
return settings.isCollapseJavadocs();
} else if (element instanceof PsiJavaFile) {
return settings.isCollapseFileHeader();
} else if (element instanceof PsiAnnotation) {
return settings.isCollapseAnnotations();
} else if (element instanceof PsiComment) {
return settings.isCollapseEndOfLineComments();
} else if (element instanceof PsiLambdaExpression) {
return settings.isCollapseAnonymousClasses();
} else {
LOG.error("Unknown element:" + element);
return false;
}
}
use of com.intellij.psi.javadoc.PsiDocComment in project intellij-community by JetBrains.
the class JavadocParamTagsTest method testAddTag2.
public void testAddTag2() throws Exception {
final PsiElementFactory factory = getFactory();
final PsiMethod method = factory.createMethodFromText("/**\n" + " * Javadoc\n" + " * @param p1\n" + " */\n" + "void m();", null);
final PsiDocComment docComment = method.getDocComment();
assertNotNull(docComment);
final PsiDocTag[] tags = docComment.getTags();
final PsiDocTag tag2 = factory.createParamTag("p2", "");
docComment.addBefore(tag2, tags[0]);
assertEquals("/**\n" + " * Javadoc\n" + " * @param p2\n" + " * @param p1\n" + " */", docComment.getText());
}
use of com.intellij.psi.javadoc.PsiDocComment in project intellij-community by JetBrains.
the class JavadocParamTagsTest method testDeleteTag2.
public void testDeleteTag2() throws Exception {
final PsiElementFactory factory = getFactory();
final PsiMethod method = factory.createMethodFromText("/**\n" + " * Javadoc\n" + " * @param p1\n" + " * @param p2\n" + " */" + " void m() {}", null);
final PsiDocComment docComment = method.getDocComment();
assertNotNull(docComment);
final PsiDocTag[] tags = docComment.getTags();
ApplicationManager.getApplication().runWriteAction(() -> tags[1].delete());
assertEquals("/**\n" + " * Javadoc\n" + " * @param p1\n" + " */", docComment.getText());
}
Aggregations