SSR: fix field javadoc matching (part of IDEA-126909)

This commit is contained in:
Bas Leijdekkers
2015-02-12 22:23:29 +01:00
parent d5d11aa539
commit 2c686dff7a
2 changed files with 21 additions and 13 deletions
@@ -48,18 +48,18 @@ public class JavaMatchingVisitor extends JavaElementVisitor {
@Override
public void visitComment(PsiComment comment) {
PsiElement comment2 = null;
PsiComment comment2 = null;
if (!(myMatchingVisitor.getElement() instanceof PsiComment)) {
if (myMatchingVisitor.getElement() instanceof PsiMember) {
final PsiElement[] children = myMatchingVisitor.getElement().getChildren();
if (children[0] instanceof PsiComment) {
comment2 = children[0];
comment2 = (PsiComment)children[0];
}
}
}
else {
comment2 = myMatchingVisitor.getElement();
comment2 = (PsiComment)myMatchingVisitor.getElement();
}
if (comment2 == null) {
@@ -70,10 +70,10 @@ public class JavaMatchingVisitor extends JavaElementVisitor {
final Object userData = comment.getUserData(CompiledPattern.HANDLER_KEY);
if (userData instanceof String) {
String str = (String)userData;
final String str = (String)userData;
int end = comment2.getTextLength();
if (((PsiComment)comment2).getTokenType() == JavaTokenType.C_STYLE_COMMENT) {
if (comment2.getTokenType() == JavaTokenType.C_STYLE_COMMENT) {
end -= 2;
}
myMatchingVisitor.setResult(((SubstitutionHandler)myMatchingVisitor.getMatchContext().getPattern().getHandler(str)).handle(
@@ -362,7 +362,13 @@ public class JavaMatchingVisitor extends JavaElementVisitor {
@Override
public void visitField(PsiField psiField) {
if (!checkHierarchy((PsiField)myMatchingVisitor.getElement(), psiField)) {
final PsiDocComment comment = psiField.getDocComment();
final PsiField other = (PsiField)myMatchingVisitor.getElement();
if (comment != null) {
myMatchingVisitor.setResult(myMatchingVisitor.match(comment, other));
if (!myMatchingVisitor.getResult()) return;
}
if (!checkHierarchy(other, psiField)) {
myMatchingVisitor.setResult(false);
return;
}
@@ -170,17 +170,19 @@ public class StructuralSearchTest extends StructuralSearchTestCase {
private static final String s55 = " a = b.class; ";
private static final String s56 = "'T.class";
private static final String s57 = "{ /** @author Maxim */ class C { " +
private static final String s57 = "/** @author Maxim */ class C {" +
" private int value; " +
"} " +
"class D {" +
"/** @serializable */ private int value; " +
"/** @since 1.4 */ void a() {} "+
" /** @serializable */ private int value;" +
"private int value2; " +
" /** @since 1.4 */ void a() {} "+
"}" +
"class F { " +
"/** @since 1.4 */ void a() {} "+
"/** @serializable */ private int value2; " +
" /** @since 1.4 */ void a() {} "+
" /** @serializable */ private int value2; " +
"}" +
"class G { /** @param a*/ void a() {} } }";
"class G { /** @param a*/ void a() {} }";
private static final String s57_2 = "/** @author Maxim */ class C { " +
"} " +
"class D {" +
@@ -193,7 +195,7 @@ public class StructuralSearchTest extends StructuralSearchTestCase {
"}" +
"class G { /** @param a*/ void a() {} }";
private static final String s58 = "/** @'T '_T2 */ class '_ { }";
private static final String s58_2 = "class '_ { /** @serializable '_ */ '_ '_; }";
private static final String s58_2 = "class '_ { /** @serializable '_* */ '_ '_; }";
private static final String s58_3 = "class '_ { /** @'T 1.4 */ '_ '_() {} }";
private static final String s58_4 = "/** @'T '_T2 */";
private static final String s58_5 = "/** @'T '_T2? */";