From 58ccc4c14b2f7f039e4c49622f85c3a4edf77f61 Mon Sep 17 00:00:00 2001 From: anna Date: Wed, 21 Oct 2009 13:37:49 +0400 Subject: [PATCH] try to find referenced member inside inner class if failed try enclosing (IDEADEV-40929) --- .../javadoc/PsiDocMethodOrFieldRef.java | 32 +++-- .../javaDoc/BadReference.java | 8 ++ .../javaDoc/Exception0.java | 8 ++ .../javaDoc/Exception1.java | 8 ++ .../javaDoc/Exception2.java | 6 + .../javaDoc/Exception3.java | 6 + .../javaDoc/Exception4.java | 6 + .../javaDoc/InheritJavaDoc.java | 7 ++ .../javaDoc/InlineTagAsDescription.java | 18 +++ .../javaDoc/JavadocPeriod.java | 6 + .../javaDoc/JavadocPeriod1.java | 6 + .../javaDoc/JavadocPeriod2.java | 7 ++ .../daemonCodeAnalyzer/javaDoc/Link0.java | 8 ++ .../LinkFromInnerClassToSelfMethod.java | 13 ++ .../javaDoc/MissingReturnDescription.java | 9 ++ .../javaDoc/MultipleThrows.java | 10 ++ .../daemonCodeAnalyzer/javaDoc/Param0.java | 5 + .../daemonCodeAnalyzer/javaDoc/Param1.java | 7 ++ .../daemonCodeAnalyzer/javaDoc/Param2.java | 7 ++ .../daemonCodeAnalyzer/javaDoc/Param3.java | 7 ++ .../daemonCodeAnalyzer/javaDoc/Param4.java | 8 ++ .../daemonCodeAnalyzer/javaDoc/Return0.java | 6 + .../daemonCodeAnalyzer/javaDoc/See0.java | 8 ++ .../daemonCodeAnalyzer/javaDoc/See1.java | 8 ++ .../daemonCodeAnalyzer/javaDoc/See2.java | 8 ++ .../daemonCodeAnalyzer/javaDoc/See3.java | 8 ++ .../daemonCodeAnalyzer/javaDoc/See4.java | 8 ++ .../daemonCodeAnalyzer/javaDoc/See5.java | 8 ++ .../daemonCodeAnalyzer/javaDoc/See6.java | 6 + .../javaDoc/SeeConstants.java | 12 ++ .../javaDoc/UnknownInlineTag.java | 14 +++ .../javaDoc/UnknownTags.java | 14 +++ .../javaDoc/ValueBadReference.java | 7 ++ .../javaDoc/ValueEmpty.java | 6 + .../javaDoc/ValueGoodReference.java | 9 ++ .../javaDoc/ValueNotOnField.java | 8 ++ .../javaDoc/ValueNotOnStaticField.java | 8 ++ .../javaDoc/ValueOnNotInitializedField.java | 8 ++ .../javaDoc/ValueReference14.java | 9 ++ .../daemonCodeAnalyzer/javaDoc/Vararg.java | 9 ++ .../daemon/JavadocHighlightingTest.java | 116 ++++++++++++++++++ 41 files changed, 465 insertions(+), 7 deletions(-) create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/BadReference.java create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/Exception0.java create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/Exception1.java create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/Exception2.java create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/Exception3.java create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/Exception4.java create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/InheritJavaDoc.java create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/InlineTagAsDescription.java create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/JavadocPeriod.java create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/JavadocPeriod1.java create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/JavadocPeriod2.java create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/Link0.java create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/LinkFromInnerClassToSelfMethod.java create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/MissingReturnDescription.java create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/MultipleThrows.java create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/Param0.java create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/Param1.java create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/Param2.java create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/Param3.java create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/Param4.java create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/Return0.java create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/See0.java create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/See1.java create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/See2.java create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/See3.java create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/See4.java create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/See5.java create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/See6.java create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/SeeConstants.java create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/UnknownInlineTag.java create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/UnknownTags.java create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/ValueBadReference.java create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/ValueEmpty.java create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/ValueGoodReference.java create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/ValueNotOnField.java create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/ValueNotOnStaticField.java create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/ValueOnNotInitializedField.java create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/ValueReference14.java create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/Vararg.java create mode 100644 java/java-tests/testSrc/com/intellij/codeInsight/daemon/JavadocHighlightingTest.java diff --git a/java/java-impl/src/com/intellij/psi/impl/source/javadoc/PsiDocMethodOrFieldRef.java b/java/java-impl/src/com/intellij/psi/impl/source/javadoc/PsiDocMethodOrFieldRef.java index f44a18d003a7..c6559dfd1a1e 100644 --- a/java/java-impl/src/com/intellij/psi/impl/source/javadoc/PsiDocMethodOrFieldRef.java +++ b/java/java-impl/src/com/intellij/psi/impl/source/javadoc/PsiDocMethodOrFieldRef.java @@ -36,6 +36,7 @@ import com.intellij.util.IncorrectOperationException; import com.intellij.util.SmartList; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.Arrays; @@ -62,6 +63,25 @@ public class PsiDocMethodOrFieldRef extends CompositePsiElement implements PsiDo final PsiElement scope = getScope(); final PsiElement element = getNameElement(); if (scope == null || element == null) return new MyReference(null); + + PsiReference psiReference = getReferenceInScope(scope, element); + if (psiReference != null) return psiReference; + + if (scope instanceof PsiClass) { + PsiClass classScope = ((PsiClass)scope); + PsiClass containingClass = classScope.getContainingClass(); + while (containingClass != null) { + classScope = containingClass; + psiReference = getReferenceInScope(classScope, element); + if (psiReference != null) return psiReference; + containingClass = classScope.getContainingClass(); + } + } + return new MyReference(null); + } + + @Nullable + private PsiReference getReferenceInScope(PsiElement scope, PsiElement element) { final String name = element.getText(); @@ -107,9 +127,7 @@ public class PsiDocMethodOrFieldRef extends CompositePsiElement implements PsiDo }; } } - - - return new MyReference(null); + return null; } public static PsiVariable[] getAllVariables(PsiElement scope, PsiElement place) { @@ -152,7 +170,7 @@ public class PsiDocMethodOrFieldRef extends CompositePsiElement implements PsiDo List types = new ArrayList(); for (PsiElement child = element.getFirstChild(); child != null; child = child.getNextSibling()) { - if (child.getNode().getElementType() == JavaDocElementType.DOC_TYPE_HOLDER) { + if (child.getNode().getElementType() == DOC_TYPE_HOLDER) { final String[] typeStrings = child.getText().split("[, ]"); //avoid param types list parsing hmm mathod(paramType1, paramType2, ...) -> typeElement1, identifier2, ... if (typeStrings != null) { for (String type : typeStrings) { @@ -167,12 +185,12 @@ public class PsiDocMethodOrFieldRef extends CompositePsiElement implements PsiDo return types.toArray(new String[types.size()]); } + @Nullable private PsiElement getScope(){ if (getFirstChildNode().getElementType() == ElementType.DOC_REFERENCE_HOLDER) { final PsiElement firstChildPsi = SourceTreeToPsiMap.treeElementToPsi(getFirstChildNode().getFirstChildNode()); if (firstChildPsi instanceof PsiJavaCodeReferenceElement) { PsiJavaCodeReferenceElement referenceElement = (PsiJavaCodeReferenceElement)firstChildPsi; - if(referenceElement == null) return null; final PsiElement referencedElement = referenceElement.resolve(); if (referencedElement instanceof PsiClass) return referencedElement; return null; @@ -180,9 +198,9 @@ public class PsiDocMethodOrFieldRef extends CompositePsiElement implements PsiDo else if (firstChildPsi instanceof PsiKeyword) { final PsiKeyword keyword = (PsiKeyword)firstChildPsi; - if (keyword.getTokenType().equals(JavaTokenType.THIS_KEYWORD)) { + if (keyword.getTokenType().equals(THIS_KEYWORD)) { return JavaResolveUtil.getContextClass(this); - } else if (keyword.getTokenType().equals(JavaTokenType.SUPER_KEYWORD)) { + } else if (keyword.getTokenType().equals(SUPER_KEYWORD)) { final PsiClass contextClass = JavaResolveUtil.getContextClass(this); if (contextClass != null) return contextClass.getSuperClass(); return null; diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/BadReference.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/BadReference.java new file mode 100644 index 000000000000..36c2c8581051 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/BadReference.java @@ -0,0 +1,8 @@ +class Test { + /** + * This element was written by {@link Test#write(Object, XmlWriter)} + * method. So read and write methods should be consistent. + */ + public void read(){} + public void write(Object o, XmlWriter writer){} +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/Exception0.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/Exception0.java new file mode 100644 index 000000000000..66281ea58bb7 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/Exception0.java @@ -0,0 +1,8 @@ +class Test { + /** + * @throws SomeClass asdfasd + */ + public void foo() {} + + class SomeClass {} +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/Exception1.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/Exception1.java new file mode 100644 index 000000000000..89ee9f6e4267 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/Exception1.java @@ -0,0 +1,8 @@ +class Test { + /** + * @throws + */ + public void foo() {} + + class SomeClass {} +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/Exception2.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/Exception2.java new file mode 100644 index 000000000000..026bcc63bd4b --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/Exception2.java @@ -0,0 +1,6 @@ +class Test { + /** + * @throws IllegalArgumentException sometimes + */ + public void foo() {} +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/Exception3.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/Exception3.java new file mode 100644 index 000000000000..e6d2ca123afe --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/Exception3.java @@ -0,0 +1,6 @@ +class Test { + /** + * @throws java.io.EOFException sometimes + */ + public void foo() throws java.io.IOException {} +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/Exception4.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/Exception4.java new file mode 100644 index 000000000000..982cd2cc9368 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/Exception4.java @@ -0,0 +1,6 @@ +class Test { + /** + * @throws Integer sometimes + */ + public void foo() throws Exception {} +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/InheritJavaDoc.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/InheritJavaDoc.java new file mode 100644 index 000000000000..75abbd9cb85b --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/InheritJavaDoc.java @@ -0,0 +1,7 @@ +class Test { + /** + * @inheritDoc + */ + void a() { + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/InlineTagAsDescription.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/InlineTagAsDescription.java new file mode 100644 index 000000000000..4e1c3308f793 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/InlineTagAsDescription.java @@ -0,0 +1,18 @@ +class A { + /** + * @return + * {@inheritDoc} + **/ + int foo(){ + return 0; + } +} + +class B { + /** + * @return bar + **/ + int foo(){ + return 0; + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/JavadocPeriod.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/JavadocPeriod.java new file mode 100644 index 000000000000..f7ef1c13ea0b --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/JavadocPeriod.java @@ -0,0 +1,6 @@ +/** + * Missing dot + */ +class Test { + +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/JavadocPeriod1.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/JavadocPeriod1.java new file mode 100644 index 000000000000..96a863eefdc0 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/JavadocPeriod1.java @@ -0,0 +1,6 @@ +/** +* Do smth @linkplain #link}. +*/ +public class Test { + private void link(){} +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/JavadocPeriod2.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/JavadocPeriod2.java new file mode 100644 index 000000000000..731e5088d9ef --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/JavadocPeriod2.java @@ -0,0 +1,7 @@ +/** +* Do smth +* @author me. +*/ +public class Test { + +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/Link0.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/Link0.java new file mode 100644 index 000000000000..b317f020e162 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/Link0.java @@ -0,0 +1,8 @@ +class Test { + /** + * @param ppp see {@link #Test} + */ + public void i(int ppp) {} + + class A{ public void foo() {}} +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/LinkFromInnerClassToSelfMethod.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/LinkFromInnerClassToSelfMethod.java new file mode 100644 index 000000000000..728c62bd2142 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/LinkFromInnerClassToSelfMethod.java @@ -0,0 +1,13 @@ +class Test { + + public void i(int ppp) {} + /** + * {@link #foo(int)} + * {@link #foo()} + * {@link #i(int)} + */ + class A{ + public void foo() {} + } + +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/MissingReturnDescription.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/MissingReturnDescription.java new file mode 100644 index 000000000000..e42ee86bbcbc --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/MissingReturnDescription.java @@ -0,0 +1,9 @@ +class MissingRetunDescription { + /** + * @return + * @throws Exception in some case + */ + public boolean foo() throws Exception { + return false; + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/MultipleThrows.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/MultipleThrows.java new file mode 100644 index 000000000000..6fc69105c3e9 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/MultipleThrows.java @@ -0,0 +1,10 @@ +import java.io.IOException; +class Test { + /** + * @throws IOException in some case + * @throws IOException + */ + void a() throws IOException{ + throw new IOException(); + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/Param0.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/Param0.java new file mode 100644 index 000000000000..485ae4576695 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/Param0.java @@ -0,0 +1,5 @@ +/** + * @param myParam paramDescription + */ +class Test { +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/Param1.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/Param1.java new file mode 100644 index 000000000000..f616594f6496 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/Param1.java @@ -0,0 +1,7 @@ +class Test { + /** + * @param + */ + public void foo() { + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/Param2.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/Param2.java new file mode 100644 index 000000000000..b81780d00505 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/Param2.java @@ -0,0 +1,7 @@ +class Test { + /** + * @param param some param + */ + public void foo() { + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/Param3.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/Param3.java new file mode 100644 index 000000000000..6ca40938851d --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/Param3.java @@ -0,0 +1,7 @@ +class Test { + /** + * @param param some param + */ + public void foo(int param) { + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/Param4.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/Param4.java new file mode 100644 index 000000000000..ee18442465b8 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/Param4.java @@ -0,0 +1,8 @@ +class Test { + + /** + * @param i here description goes + * @return + */ + int d(){return 1;} +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/Return0.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/Return0.java new file mode 100644 index 000000000000..08614e1eae6e --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/Return0.java @@ -0,0 +1,6 @@ +class Test { + /** + * @return returns + */ + public void foo() {} +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/See0.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/See0.java new file mode 100644 index 000000000000..8fba319447b9 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/See0.java @@ -0,0 +1,8 @@ +class Test { + /** + * @see A#someField + */ + public void i() {} + + class A{ public void foo() {}} +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/See1.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/See1.java new file mode 100644 index 000000000000..3703473316e3 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/See1.java @@ -0,0 +1,8 @@ +class Test { + /** + * @see A#foo + */ + public void i() {} + + class A{ public void foo() {}} +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/See2.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/See2.java new file mode 100644 index 000000000000..7b842427978c --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/See2.java @@ -0,0 +1,8 @@ +class Test { + /** + * @see A# + */ + public void i() {} + + class A{ public void foo() {}} +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/See3.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/See3.java new file mode 100644 index 000000000000..84a76108a039 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/See3.java @@ -0,0 +1,8 @@ +class Test { + /** + * @see #perform(int) + */ + public void i() {} + + public void perform() {} +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/See4.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/See4.java new file mode 100644 index 000000000000..dd2614bf8cc8 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/See4.java @@ -0,0 +1,8 @@ +class Test { + /** + * @see #perform(int) + */ + public void i() {} + + public void perform(int a) {} +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/See5.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/See5.java new file mode 100644 index 000000000000..0a53160fc6c3 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/See5.java @@ -0,0 +1,8 @@ +class Test { + /** + * @see #perform(String, int) + */ + public void i() {} + + public void perform(String s, int a) {} +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/See6.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/See6.java new file mode 100644 index 000000000000..91b8c48404ab --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/See6.java @@ -0,0 +1,6 @@ +class Foo { + /** + * {@link #foo()} + */ + void foo(){} +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/SeeConstants.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/SeeConstants.java new file mode 100644 index 000000000000..04658752ea22 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/SeeConstants.java @@ -0,0 +1,12 @@ +public class SeeConstants { + public static final String III = ""; + public static final String UUU=""; + + /** + * @see SeeConstants.III + * @see SeeConstants#UUU + * @param args blah-blah + */ + public static void main(String[] args) { + } +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/UnknownInlineTag.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/UnknownInlineTag.java new file mode 100644 index 000000000000..4d62cd0dbfaa --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/UnknownInlineTag.java @@ -0,0 +1,14 @@ +/** + * {@linked} + */ +public class Foo { + /** + * @param i some param {@vaaalue #field} + */ + void foo(int i) {} + + /** + * {@linke} + */ + int field; +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/UnknownTags.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/UnknownTags.java new file mode 100644 index 000000000000..3c2e4744e8c0 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/UnknownTags.java @@ -0,0 +1,14 @@ +/** + * @foo + */ +public class Foo { + /** + * @foo + */ + void foo() {} + + /** + * @foo + */ + int field; +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/ValueBadReference.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/ValueBadReference.java new file mode 100644 index 000000000000..955ac0c9f975 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/ValueBadReference.java @@ -0,0 +1,7 @@ +class Test { + /** + * Value is {@value #badReference} + * @param ppp . + */ + public void i(int ppp) {} +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/ValueEmpty.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/ValueEmpty.java new file mode 100644 index 000000000000..1a4ca1cf0a70 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/ValueEmpty.java @@ -0,0 +1,6 @@ +class Test { + /** + * Value is {@value } + */ + public static final int A = 1; +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/ValueGoodReference.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/ValueGoodReference.java new file mode 100644 index 000000000000..1a1e4445dd3c --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/ValueGoodReference.java @@ -0,0 +1,9 @@ +class Test { + public static final int A = 1; + + /** + * Value is {@value #A} + * @param ppp . + */ + public void i(int ppp) {} +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/ValueNotOnField.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/ValueNotOnField.java new file mode 100644 index 000000000000..69cc30527921 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/ValueNotOnField.java @@ -0,0 +1,8 @@ +class Test { + /** + * Value is {@value #g} + */ + public void i() {} + + public void g() {} +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/ValueNotOnStaticField.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/ValueNotOnStaticField.java new file mode 100644 index 000000000000..9489b82d22d4 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/ValueNotOnStaticField.java @@ -0,0 +1,8 @@ +class Test { + public int A = 1; + + /** + * Value is {@value #A} + */ + public void i() {} +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/ValueOnNotInitializedField.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/ValueOnNotInitializedField.java new file mode 100644 index 000000000000..a386784bcb6f --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/ValueOnNotInitializedField.java @@ -0,0 +1,8 @@ +class Test { + public static int A; + + /** + * Value is {@value #A} + */ + public void i() {} +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/ValueReference14.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/ValueReference14.java new file mode 100644 index 000000000000..3534826a72f0 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/ValueReference14.java @@ -0,0 +1,9 @@ +class Test { + public static final int A = 1; + + /** + * Value is {@value #A} + * @param ppp . + */ + public void i(int ppp) {} +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/Vararg.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/Vararg.java new file mode 100644 index 000000000000..cfe0f303f84e --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/Vararg.java @@ -0,0 +1,9 @@ +public class Test { + /** + * @see Test#test(String, int...) + * @see Test#test(String, long...) + **/ + void foo() {} + + void test (String u, int ... i) {} +} diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/JavadocHighlightingTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/JavadocHighlightingTest.java new file mode 100644 index 000000000000..39d2f102fb98 --- /dev/null +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/JavadocHighlightingTest.java @@ -0,0 +1,116 @@ +package com.intellij.codeInsight.daemon; + +import com.intellij.JavaTestUtil; +import com.intellij.codeInspection.LocalInspectionTool; +import com.intellij.codeInspection.javaDoc.JavaDocLocalInspection; +import com.intellij.codeInspection.javaDoc.JavaDocReferenceInspection; +import com.intellij.openapi.projectRoots.Sdk; +import com.intellij.openapi.projectRoots.impl.JavaSdkImpl; +import com.intellij.openapi.roots.LanguageLevelProjectExtension; +import com.intellij.pom.java.LanguageLevel; +import com.intellij.psi.JavaPsiFacade; + + +public class JavadocHighlightingTest extends LightDaemonAnalyzerTestCase { + private static final String BASE_PATH = "/codeInsight/daemonCodeAnalyzer/javaDoc"; + + @Override + protected String getTestDataPath() { + return JavaTestUtil.getJavaTestDataPath(); + } + + protected LocalInspectionTool[] configureLocalInspectionTools() { + return new LocalInspectionTool[]{ + new JavaDocLocalInspection(), + new JavaDocReferenceInspection() + }; + } + + public void testJavadocPeriod() throws Exception { + final JavaDocLocalInspection javaDocLocalInspection = new JavaDocLocalInspection(); + javaDocLocalInspection.IGNORE_JAVADOC_PERIOD = false; + enableInspectionTool(javaDocLocalInspection); + doTest(); + } + + public void testJavadocPeriod1() throws Exception { + final JavaDocLocalInspection javaDocLocalInspection = new JavaDocLocalInspection(); + javaDocLocalInspection.IGNORE_JAVADOC_PERIOD = false; + enableInspectionTool(javaDocLocalInspection); + doTest(); + } + + public void testJavadocPeriod2() throws Exception { + final JavaDocLocalInspection javaDocLocalInspection = new JavaDocLocalInspection(); + javaDocLocalInspection.IGNORE_JAVADOC_PERIOD = false; + enableInspectionTool(javaDocLocalInspection); + doTest(); + } + + public void testInlineTagAsDescription() throws Exception { + doTest(); + } + + public void testParam0() throws Exception { doTestWithLangLevel(LanguageLevel.HIGHEST); } + public void testParam1() throws Exception { doTest(); } + public void testParam2() throws Exception { doTest(); } + public void testParam3() throws Exception { doTest(); } + public void testParam4() throws Exception { doTest(); } + public void testSee0() throws Exception { doTest(); } + public void testSee1() throws Exception { doTest(); } + public void testSee2() throws Exception { doTest(); } + public void testSee3() throws Exception { doTest(); } + public void testSee4() throws Exception { doTest(); } + public void testSee5() throws Exception { doTest(); } + public void testSee6() throws Exception {doTest();} + public void testSeeConstants() throws Exception { doTest();} + public void testReturn0() throws Exception { doTest(); } + public void testException0() throws Exception { doTest(); } + public void testException1() throws Exception { doTest(); } + public void testException2() throws Exception { doTest(); } + public void testException3() throws Exception { doTest(); } + public void testException4() throws Exception { doTest(); } + public void testMultipleThrows() throws Exception { doTest(); } + public void testInheritJavaDoc() throws Exception {doTestWithLangLevel(LanguageLevel.JDK_1_3);} + public void testLink0() throws Exception { doTest(); } + public void testLinkFromInnerClassToSelfMethod() throws Exception {doTest();} + + public void testValueBadReference() throws Exception { doTestWithLangLevel(LanguageLevel.HIGHEST); } + public void testValueGoodReference() throws Exception { doTestWithLangLevel(LanguageLevel.HIGHEST); } + public void testValueReference14() throws Exception { doTestWithLangLevel(LanguageLevel.JDK_1_4); } + public void testValueEmpty() throws Exception { doTestWithLangLevel(LanguageLevel.JDK_1_4); } + public void testValueNotOnField() throws Exception { doTestWithLangLevel(LanguageLevel.HIGHEST); } + public void testValueNotOnStaticField() throws Exception { doTestWithLangLevel(LanguageLevel.HIGHEST); } + public void testValueOnNotInitializedField() throws Exception { doTestWithLangLevel(LanguageLevel.HIGHEST); } + + public void testUnknownInlineTag() throws Exception {doTest();} + public void testUnknownTags() throws Exception {doTest();} + + public void testVararg() throws Exception {doTest();} + + public void testBadReference() throws Exception{ + doTest(); + } + + public void testMissingReturnDescription() throws Exception {doTest();} + + private void doTestWithLangLevel(final LanguageLevel langLevel) throws Exception { + JavaPsiFacade manager = getJavaFacade(); + final LanguageLevel effectiveLanguageLevel = LanguageLevelProjectExtension.getInstance(manager.getProject()).getLanguageLevel(); + LanguageLevelProjectExtension.getInstance(manager.getProject()).setLanguageLevel(langLevel); + try { + doTest(); + } + finally { + LanguageLevelProjectExtension.getInstance(manager.getProject()).setLanguageLevel(effectiveLanguageLevel); + } + } + + protected void doTest() throws Exception { + super.doTest(BASE_PATH + "/" + getTestName(false) + ".java", true, false); + } + + protected Sdk getProjectJDK() { + return JavaSdkImpl.getMockJdk15("java 1.5"); + } +} \ No newline at end of file