mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
SSR: improve reference predicate and add some example templates for it
This commit is contained in:
+9
@@ -1,6 +1,7 @@
|
||||
// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.structuralsearch;
|
||||
|
||||
import com.intellij.openapi.fileTypes.StdFileTypes;
|
||||
import com.intellij.structuralsearch.plugin.ui.Configuration;
|
||||
|
||||
import static com.intellij.structuralsearch.PredefinedConfigurationUtil.createSearchTemplateInfo;
|
||||
@@ -36,6 +37,7 @@ class JavaPredefinedConfigurations {
|
||||
createSearchTemplateInfo(SSRBundle.message("predefined.configuration.sample.method.invokation.with.constant.argument"),"Integer.parseInt('_a:[script( \"com.intellij.psi.util.PsiUtil.isConstantExpression(__context__)\" )])",EXPRESSION_TYPE),
|
||||
createSearchTemplateInfo(SSRBundle.message("predefined.configuration.method.references"), "'_Qualifier::'Method", EXPRESSION_TYPE),
|
||||
createSearchTemplateInfo(SSRBundle.message("predefined.configuration.string.concatenations"), "[exprtype( java\\.lang\\.String )]'_a + '_b+", EXPRESSION_TYPE),
|
||||
createSearchTemplateInfo(SSRBundle.message("predefined.configuration.deprecated.method.calls"), "'_Instance?.'MethodCall:[ref( deprecated methods )]('_Parameter*)", EXPRESSION_TYPE),
|
||||
|
||||
// Operators
|
||||
createSearchTemplateInfo(SSRBundle.message("predefined.configuration.block.dcls"),"{\n '_Type 'Var+ = '_Init?;\n '_BlockStatements*;\n}",OPERATOR_TYPE),
|
||||
@@ -52,6 +54,11 @@ class JavaPredefinedConfigurations {
|
||||
"'_ReturnType '_Method('_ParameterType '_Parameter*);",
|
||||
CLASS_TYPE
|
||||
),
|
||||
createSearchTemplateInfo(
|
||||
SSRBundle.message("predefined.configuration.deprecated.methods"),
|
||||
"@Deprecated\n'_ReturnType '_Method('_ParameterType '_Parameter*);",
|
||||
CLASS_TYPE
|
||||
),
|
||||
createSearchTemplateInfo(
|
||||
SSRBundle.message("predefined.configuration.fields.of.the.class"),
|
||||
"class '_Class { \n '_FieldType 'Field+ = '_Init?;\n}",
|
||||
@@ -307,6 +314,8 @@ class JavaPredefinedConfigurations {
|
||||
//createSearchTemplateInfo("fields selected","'_?.'_:[ref('Field)] ", INTERESTING_TYPE),
|
||||
//createSearchTemplateInfo("symbols used","'_:[ref('Symbol)] ", INTERESTING_TYPE),
|
||||
//createSearchTemplateInfo("types used","'_:[ref('Type)] '_;", INTERESTING_TYPE),
|
||||
|
||||
createSearchTemplateInfo("xml attribute references java class", "<'_tag 'attribute=\"'_value:[ref( classes, interfaces & enums )]\"/>", SSRBundle.message("xml_html.category"), StdFileTypes.XML),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -172,7 +172,7 @@ public class Matcher {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean matchNode(PsiElement element) {
|
||||
public boolean matchNode(@NotNull PsiElement element) {
|
||||
final CollectingMatchResultSink sink = new CollectingMatchResultSink();
|
||||
final MatchOptions options = matchContext.getOptions();
|
||||
final CompiledPattern compiledPattern = prepareMatching(sink, options);
|
||||
|
||||
+10
-6
@@ -1,14 +1,21 @@
|
||||
// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.s
|
||||
// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.structuralsearch.impl.matcher.predicates;
|
||||
|
||||
import com.intellij.openapi.fileTypes.FileType;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiReference;
|
||||
import com.intellij.psi.PsiReferenceService;
|
||||
import com.intellij.structuralsearch.Matcher;
|
||||
import com.intellij.structuralsearch.StructuralSearchUtil;
|
||||
import com.intellij.structuralsearch.impl.matcher.MatchContext;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @author Bas Leijdekkers
|
||||
*/
|
||||
public final class ReferencePredicate extends MatchPredicate {
|
||||
|
||||
private final Matcher matcher;
|
||||
@@ -20,10 +27,7 @@ public final class ReferencePredicate extends MatchPredicate {
|
||||
@Override
|
||||
public boolean match(PsiElement matchedNode, int start, int end, MatchContext context) {
|
||||
matchedNode = StructuralSearchUtil.getParentIfIdentifier(matchedNode);
|
||||
if (!(matchedNode instanceof PsiReference)) {
|
||||
return false;
|
||||
}
|
||||
final PsiElement target = ((PsiReference)matchedNode).resolve();
|
||||
return target != null && matcher.matchNode(target);
|
||||
final List<PsiReference> references = PsiReferenceService.getService().getReferences(matchedNode, PsiReferenceService.Hints.NO_HINTS);
|
||||
return references.stream().map(PsiReference::resolve).filter(Objects::nonNull).anyMatch(t -> matcher.matchNode(t));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -146,7 +146,7 @@ predefined.configuration.all.fields.of.the.class=all fields of the class
|
||||
predefined.configuration.instance.fields.of.the.class=instance fields of the class
|
||||
predefined.configuration.packagelocal.fields.of.the.class=package-private fields of the class
|
||||
predefined.configuration.classes=classes
|
||||
predefined.configuration.classes.interfaces.enums=classes, interfaces & enums
|
||||
predefined.configuration.classes.interfaces.enums=classes, interfaces \\& enums
|
||||
predefined.configuration.new.expressions=new expressions
|
||||
predefined.configuration.lambdas=lambdas
|
||||
predefined.configuration.method.references=method references
|
||||
|
||||
Reference in New Issue
Block a user