mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-05 01:50:56 +07:00
add javadoc intention: do not handle type parameter as comment owner IDEA-169732
This commit is contained in:
@@ -20,16 +20,10 @@ import com.intellij.codeInsight.intention.BaseElementAtCaretIntentionAction;
|
||||
import com.intellij.codeInsight.intention.LowPriorityAction;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiAnonymousClass;
|
||||
import com.intellij.psi.PsiDocCommentOwner;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiIdentifier;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author Dmitry Batkovich
|
||||
*/
|
||||
public class AddJavadocIntention extends BaseElementAtCaretIntentionAction implements LowPriorityAction {
|
||||
@Override
|
||||
public void invoke(@NotNull final Project project, final Editor editor, @NotNull final PsiElement element) throws IncorrectOperationException {
|
||||
@@ -42,9 +36,8 @@ public class AddJavadocIntention extends BaseElementAtCaretIntentionAction imple
|
||||
if (!(element instanceof PsiIdentifier)) {
|
||||
return false;
|
||||
}
|
||||
final PsiElement docCommentOwner = element.getParent();
|
||||
return docCommentOwner instanceof PsiDocCommentOwner &&
|
||||
!(docCommentOwner instanceof PsiAnonymousClass) && ((PsiDocCommentOwner)docCommentOwner).getDocComment() == null;
|
||||
final PsiElement parent = element.getParent();
|
||||
return parent instanceof PsiDocCommentOwner && !(parent instanceof PsiTypeParameter);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -403,12 +403,13 @@ public class JavaDocumentationProvider extends DocumentationProviderEx implement
|
||||
@Nullable
|
||||
@Override
|
||||
public Pair<PsiElement, PsiComment> parseContext(@NotNull PsiElement startPoint) {
|
||||
for (PsiElement e = startPoint; e != null; e = e.getParent()) {
|
||||
if (e instanceof PsiDocCommentOwner) {
|
||||
return Pair.create(e, ((PsiDocCommentOwner)e).getDocComment());
|
||||
PsiElement docCommentOwner = PsiTreeUtil.findFirstParent(startPoint, e -> {
|
||||
if (e instanceof PsiDocCommentOwner && !(e instanceof PsiTypeParameter) && !(e instanceof PsiAnonymousClass)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
return false;
|
||||
});
|
||||
return docCommentOwner == null ? null : Pair.create(docCommentOwner, ((PsiDocCommentOwner)docCommentOwner).getDocComment());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
// "Add Javadoc" "false"
|
||||
class A {
|
||||
|
||||
void m() {
|
||||
new Ru<caret>nnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
// "Add Javadoc" "false"
|
||||
class A {
|
||||
|
||||
<T<caret>TTT> void mmmm() {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user