mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
SSR: fix & test other constraints availability
This commit is contained in:
+20
-12
@@ -833,10 +833,13 @@ public class JavaStructuralSearchProfile extends StructuralSearchProfile {
|
||||
case UIUtil.TEXT_HIERARCHY:
|
||||
if (variableNode != null) {
|
||||
final PsiElement parent = variableNode.getParent();
|
||||
if (parent instanceof PsiJavaCodeReferenceElement && parent.getParent() instanceof PsiTypeElement ||
|
||||
parent instanceof PsiClass) {
|
||||
return true;
|
||||
if (parent instanceof PsiJavaCodeReferenceElement) {
|
||||
final PsiElement grandParent = parent.getParent();
|
||||
if (grandParent instanceof PsiTypeElement || grandParent instanceof PsiReferenceList ||
|
||||
grandParent instanceof PsiReferenceExpression) return true;
|
||||
}
|
||||
else if (parent instanceof PsiClass) return true;
|
||||
else if (isMemberSurroundedByClass(parent)) return true;
|
||||
}
|
||||
return false;
|
||||
case UIUtil.EXPECTED_TYPE:
|
||||
@@ -923,15 +926,7 @@ public class JavaStructuralSearchProfile extends StructuralSearchProfile {
|
||||
private static boolean isApplicableMinMaxCount(@NotNull PsiElement variableNode) {
|
||||
if (variableNode instanceof PsiDocToken) return true;
|
||||
final PsiElement parent = variableNode.getParent();
|
||||
if (parent instanceof PsiMember && !(parent instanceof PsiTypeParameter)) {
|
||||
final PsiMember member = (PsiMember)parent;
|
||||
final PsiClass aClass = member.getContainingClass();
|
||||
if (aClass == null) {
|
||||
return false;
|
||||
}
|
||||
final String name = aClass.getName();
|
||||
return name != null && !"_Dummy_".equals(name);
|
||||
}
|
||||
if (isMemberSurroundedByClass(parent)) return true;
|
||||
final PsiElement grandParent = parent.getParent();
|
||||
if (grandParent instanceof PsiCatchSection && parent instanceof PsiParameter) return true;
|
||||
if (grandParent instanceof PsiAnnotation && !(grandParent.getParent().getNextSibling() instanceof PsiErrorElement)) return true;
|
||||
@@ -950,6 +945,19 @@ public class JavaStructuralSearchProfile extends StructuralSearchProfile {
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean isMemberSurroundedByClass(PsiElement parent) {
|
||||
if (!(parent instanceof PsiMember) || parent instanceof PsiTypeParameter) {
|
||||
return false;
|
||||
}
|
||||
final PsiMember member = (PsiMember)parent;
|
||||
final PsiClass aClass = member.getContainingClass();
|
||||
if (aClass == null) {
|
||||
return false;
|
||||
}
|
||||
final String name = aClass.getName();
|
||||
return name != null && !"_Dummy_".equals(name);
|
||||
}
|
||||
|
||||
private static boolean hasSemicolon(PsiElement element) {
|
||||
PsiElement lastChild = element.getLastChild();
|
||||
while (lastChild instanceof PsiComment || lastChild instanceof PsiWhiteSpace) {
|
||||
|
||||
+1
-1
@@ -474,7 +474,7 @@ public class StructuralSearchTest extends StructuralSearchTestCase {
|
||||
"}";
|
||||
assertEquals("match literal contents", 1, findMatchesCount(s2, "\"'String:[regex( alpha )]\""));
|
||||
assertEquals("negate match literal contents", 2, findMatchesCount(s2, "\"'String:[!regex( alpha )]\""));
|
||||
assertEquals("match literal contents and all types", 1, findMatchesCount(s2, "\"'String:[regex( alpha ) && exprtype( .* )]\""));
|
||||
assertEquals("match literal contents combined with other constraint", 1, findMatchesCount(s2, "\"'String:[regex( alpha ) && script( true )]\""));
|
||||
|
||||
String s3 = "class A {" +
|
||||
" int i = 0x20;" +
|
||||
|
||||
+12
-1
@@ -73,13 +73,24 @@ public abstract class StructuralSearchTestCase extends LightQuickFixTestCase {
|
||||
if (!StringUtil.isEmpty(constraint.getRegExp())) {
|
||||
usedConstraints.add(UIUtil.TEXT);
|
||||
}
|
||||
if (constraint.isWithinHierarchy()) {
|
||||
usedConstraints.add(UIUtil.TEXT_HIERARCHY);
|
||||
}
|
||||
if (constraint.getMinCount() == 0) {
|
||||
usedConstraints.add(UIUtil.MINIMUM_ZERO);
|
||||
}
|
||||
if (constraint.getMaxCount() > 1) {
|
||||
usedConstraints.add(UIUtil.MAXIMUM_UNLIMITED);
|
||||
}
|
||||
// todo check other constraints
|
||||
if (!StringUtil.isEmpty(constraint.getNameOfExprType())) {
|
||||
usedConstraints.add(UIUtil.TYPE);
|
||||
}
|
||||
if (!StringUtil.isEmpty(constraint.getNameOfFormalArgType())) {
|
||||
usedConstraints.add(UIUtil.EXPECTED_TYPE);
|
||||
}
|
||||
if (!StringUtil.isEmpty(constraint.getReferenceConstraint())) {
|
||||
usedConstraints.add(UIUtil.REFERENCE);
|
||||
}
|
||||
for (String usedConstraint : usedConstraints) {
|
||||
if (!profile.isApplicableConstraint(usedConstraint, nodes, false, constraint.isPartOfSearchResults())) {
|
||||
return usedConstraint + " not applicable for " + varName;
|
||||
|
||||
Reference in New Issue
Block a user