mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
SSR: make scripting variable types a little easier
This commit is contained in:
+21
-1
@@ -151,6 +151,18 @@ public class JavaStructuralSearchProfile extends StructuralSearchProfile {
|
||||
return file;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public PsiElement getPresentableElement(PsiElement element) {
|
||||
if (element instanceof PsiJavaCodeReferenceElement) {
|
||||
final PsiElement parent = element.getParent();
|
||||
if (parent instanceof PsiTypeElement) {
|
||||
return parent;
|
||||
}
|
||||
}
|
||||
return element;
|
||||
}
|
||||
|
||||
public void compile(PsiElement[] elements, @NotNull GlobalCompilingVisitor globalVisitor) {
|
||||
elements[0].getParent().accept(new JavaCompilingVisitor(globalVisitor));
|
||||
}
|
||||
@@ -425,7 +437,15 @@ public class JavaStructuralSearchProfile extends StructuralSearchProfile {
|
||||
if (searchIsExpression && statements[0].getFirstChild() instanceof PsiModifierList && statements2.length == 0) {
|
||||
return;
|
||||
}
|
||||
if (searchIsExpression != replaceIsExpression) {
|
||||
boolean targetFound = false;
|
||||
for (final String name : matchOptions.getVariableConstraintNames()) {
|
||||
final MatchVariableConstraint constraint = matchOptions.getVariableConstraint(name);
|
||||
if (constraint.isPartOfSearchResults()) {
|
||||
targetFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!targetFound && searchIsExpression != replaceIsExpression) {
|
||||
throw new UnsupportedPatternException(
|
||||
searchIsExpression ? SSRBundle.message("replacement.template.is.not.expression.error.message") :
|
||||
SSRBundle.message("search.template.is.not.expression.error.message")
|
||||
|
||||
+5
@@ -278,4 +278,9 @@ public abstract class StructuralSearchProfile {
|
||||
public boolean isDocCommentOwner(PsiElement match) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public PsiElement getPresentableElement(PsiElement element) {
|
||||
return element;
|
||||
}
|
||||
}
|
||||
|
||||
+9
@@ -41,6 +41,15 @@ public class StructuralSearchUtil {
|
||||
return !isIdentifier(element) ? element : element.getParent();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static PsiElement getPresentableElement(@NotNull PsiElement element) {
|
||||
final StructuralSearchProfile profile = getProfileByPsiElement(element);
|
||||
if (profile == null) {
|
||||
return element;
|
||||
}
|
||||
return getParentIfIdentifier(profile.getPresentableElement(element));
|
||||
}
|
||||
|
||||
private static StructuralSearchProfile[] getNewStyleProfiles() {
|
||||
if (ourNewStyleProfiles == null) {
|
||||
final List<StructuralSearchProfile> list = new ArrayList<StructuralSearchProfile>();
|
||||
|
||||
+2
-2
@@ -48,7 +48,7 @@ public class ScriptSupport {
|
||||
final String name = result.getName();
|
||||
if (name != null && !result.isMultipleMatch() && !result.isScopeMatch()) {
|
||||
final Object value = out.get(name);
|
||||
final PsiElement match = StructuralSearchUtil.getParentIfIdentifier(result.getMatch());
|
||||
final PsiElement match = StructuralSearchUtil.getPresentableElement(result.getMatch());
|
||||
if (value == null) {
|
||||
out.put(name, match);
|
||||
}
|
||||
@@ -86,7 +86,7 @@ public class ScriptSupport {
|
||||
}
|
||||
final Binding binding = new Binding(variableMap);
|
||||
|
||||
context = StructuralSearchUtil.getParentIfIdentifier(context);
|
||||
context = StructuralSearchUtil.getPresentableElement(context);
|
||||
binding.setVariable("__context__", context);
|
||||
script.setBinding(binding);
|
||||
|
||||
|
||||
+1
-1
@@ -165,7 +165,7 @@ public class SearchCommand {
|
||||
info = new UsageInfo(parent, startOffset, end - parentStart);
|
||||
}
|
||||
else {
|
||||
info = new UsageInfo(result.getMatch());
|
||||
info = new UsageInfo(StructuralSearchUtil.getPresentableElement(result.getMatch()));
|
||||
}
|
||||
|
||||
Usage usage = new UsageInfo2UsageAdapter(info);
|
||||
|
||||
Reference in New Issue
Block a user