try to find referenced member inside inner class if failed try enclosing (IDEADEV-40929)

This commit is contained in:
anna
2009-10-21 13:37:49 +04:00
parent d349ae724f
commit 58ccc4c14b
41 changed files with 465 additions and 7 deletions

View File

@@ -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<String> types = new ArrayList<String>();
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;

View File

@@ -0,0 +1,8 @@
class Test {
/**
* This element was written by {@link Test#write(Object, <error>XmlWriter</error>)}
* method. So <code>read</code> and <code>write</code> methods should be consistent.
*/
public void read(){}
public void write(Object o, <error>XmlWriter</error> writer){}
}

View File

@@ -0,0 +1,8 @@
class Test {
/**
* @throws <warning>SomeClass</warning> asdfasd
*/
public void foo() {}
class SomeClass {}
}

View File

@@ -0,0 +1,8 @@
class Test {
/**
* @throws<EOLWarning/>
*/
public void foo() {}
class SomeClass {}
}

View File

@@ -0,0 +1,6 @@
class Test {
/**
* @throws IllegalArgumentException sometimes
*/
public void foo() {}
}

View File

@@ -0,0 +1,6 @@
class Test {
/**
* @throws java.io.EOFException sometimes
*/
public void foo() throws java.io.IOException {}
}

View File

@@ -0,0 +1,6 @@
class Test {
/**
* @throws <warning>Integer</warning> sometimes
*/
public void <warning>foo</warning>() throws Exception {}
}

View File

@@ -0,0 +1,7 @@
class Test {
/**
* <warning>@inheritDoc</warning>
*/
void a() {
}
}

View File

@@ -0,0 +1,18 @@
class A {
/**
* @return
* {@inheritDoc}
**/
int foo(){
return 0;
}
}
class B {
/**
* @return bar
**/
int foo(){
return 0;
}
}

View File

@@ -0,0 +1,6 @@
<warning>/**</warning>
* Missing dot
*/
class Test {
}

View File

@@ -0,0 +1,6 @@
/**
* Do smth @linkplain #link}.
*/
public class Test {
private void link(){}
}

View File

@@ -0,0 +1,7 @@
<warning>/**</warning>
* Do smth
* @author me.
*/
public class Test {
}

View File

@@ -0,0 +1,8 @@
class Test {
/**
* @param ppp see {@link <error>#Test</error>}
*/
public void i(int ppp) {}
class A{ public void foo() {}}
}

View File

@@ -0,0 +1,13 @@
class Test {
public void i(int ppp) {}
/**
* {@link <error>#foo(int)</error>}
* {@link #foo()}
* {@link #i(int)}
*/
class A{
public void foo() {}
}
}

View File

@@ -0,0 +1,9 @@
class MissingRetunDescription {
/**
* @return<EOLWarning/>
* @throws Exception in some case
*/
public boolean foo() throws Exception {
return false;
}
}

View File

@@ -0,0 +1,10 @@
import java.io.IOException;
class Test {
/**
* @throws IOException in some case
* <warning>@throws</warning> IOException
*/
void a() throws IOException{
throw new IOException();
}
}

View File

@@ -0,0 +1,5 @@
/**
* @param <error>myParam</error> paramDescription
*/
class Test {
}

View File

@@ -0,0 +1,7 @@
class Test {
/**
* @param<EOLWarning/>
*/
public void foo() {
}
}

View File

@@ -0,0 +1,7 @@
class Test {
/**
* @param <error>param</error> some param
*/
public void foo() {
}
}

View File

@@ -0,0 +1,7 @@
class Test {
/**
* @param param some param
*/
public void foo(int param) {
}
}

View File

@@ -0,0 +1,8 @@
class Test {
/**
* @param <error>i</error> here description goes
* @return<EOLWarning/>
*/
int d(){return 1;}
}

View File

@@ -0,0 +1,6 @@
class Test {
/**
* <warning>@return</warning> returns
*/
public void foo() {}
}

View File

@@ -0,0 +1,8 @@
class Test {
/**
* @see <error>A#someField</error>
*/
public void i() {}
class A{ public void foo() {}}
}

View File

@@ -0,0 +1,8 @@
class Test {
/**
* @see A#foo
*/
public void i() {}
class A{ public void foo() {}}
}

View File

@@ -0,0 +1,8 @@
class Test {
/**
* @see A#<EOLWarning/>
*/
public void i() {}
class A{ public void foo() {}}
}

View File

@@ -0,0 +1,8 @@
class Test {
/**
* @see <error>#perform(int)</error>
*/
public void i() {}
public void perform() {}
}

View File

@@ -0,0 +1,8 @@
class Test {
/**
* @see #perform(int)
*/
public void i() {}
public void perform(int a) {}
}

View File

@@ -0,0 +1,8 @@
class Test {
/**
* @see #perform(String, int)
*/
public void i() {}
public void perform(String s, int a) {}
}

View File

@@ -0,0 +1,6 @@
class Foo {
/**
* {<warning>@link</warning> #foo()}
*/
void foo(){}
}

View File

@@ -0,0 +1,12 @@
public class SeeConstants {
public static final String III = "";
public static final String UUU="";
/**
* @see <error>SeeConstants.III</error>
* @see SeeConstants#UUU
* @param args blah-blah
*/
public static void main(String[] args) {
}
}

View File

@@ -0,0 +1,14 @@
/**
* {<warning>@linked</warning>}
*/
public class Foo {
/**
* @param i some param {<warning>@vaaalue</warning> #field}
*/
void foo(int i) {}
/**
* {<warning>@linke</warning>}
*/
int field;
}

View File

@@ -0,0 +1,14 @@
/**
* <warning>@foo</warning>
*/
public class Foo {
/**
* <warning>@foo</warning>
*/
void foo() {}
/**
* <warning>@foo</warning>
*/
int field;
}

View File

@@ -0,0 +1,7 @@
class Test {
/**
* Value is {@value <error>#badReference</error>}
* @param ppp .
*/
public void i(int ppp) {}
}

View File

@@ -0,0 +1,6 @@
class Test {
/**
* Value is {@value }
*/
public static final int A = 1;
}

View File

@@ -0,0 +1,9 @@
class Test {
public static final int A = 1;
/**
* Value is {@value #A}
* @param ppp .
*/
public void i(int ppp) {}
}

View File

@@ -0,0 +1,8 @@
class Test {
/**
* Value is {@value <error>#g</error>}
*/
public void i() {}
public void g() {}
}

View File

@@ -0,0 +1,8 @@
class Test {
public int A = 1;
/**
* Value is {@value <error>#A</error>}
*/
public void i() {}
}

View File

@@ -0,0 +1,8 @@
class Test {
public static int A;
/**
* Value is {@value <error>#A</error>}
*/
public void i() {}
}

View File

@@ -0,0 +1,9 @@
class Test {
public static final int A = 1;
/**
* Value is {@value <error>#A</error>}
* @param ppp .
*/
public void i(int ppp) {}
}

View File

@@ -0,0 +1,9 @@
public class Test {
/**
* @see Test#test(String, int...)
* @see <error>Test#test(String, long...)</error>
**/
void foo() {}
void test (String u, int ... i) {}
}

View File

@@ -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");
}
}