mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
structural search: split into java and common parts: isIdentifier
This commit is contained in:
+5
@@ -77,4 +77,9 @@ public class GroovyStructuralSearchProfile extends StructuralSearchProfileBase {
|
||||
return PsiExpression.class;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isIdentifier(PsiElement element) {
|
||||
return element instanceof PsiIdentifier;
|
||||
}
|
||||
}
|
||||
|
||||
+4
@@ -264,4 +264,8 @@ public abstract class StructuralSearchProfile {
|
||||
public int processAdditionalOptions(ParameterInfo info, int offset, StringBuilder result, MatchResult r) {
|
||||
return offset;
|
||||
}
|
||||
|
||||
public boolean isIdentifier(PsiElement element) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
+7
@@ -8,6 +8,7 @@ import com.intellij.structuralsearch.impl.matcher.MatchUtils;
|
||||
import com.intellij.structuralsearch.plugin.ui.Configuration;
|
||||
import com.intellij.tokenindex.LanguageTokenizer;
|
||||
import com.intellij.tokenindex.Tokenizer;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -30,6 +31,12 @@ public class StructuralSearchUtil {
|
||||
return getProfileByLanguage(element.getLanguage());
|
||||
}
|
||||
|
||||
@Contract("null -> false")
|
||||
public static boolean isIdentifier(PsiElement element) {
|
||||
final StructuralSearchProfile profile = getProfileByPsiElement(element);
|
||||
return profile != null && profile.isIdentifier(element);
|
||||
}
|
||||
|
||||
private static StructuralSearchProfile[] getNewStyleProfiles() {
|
||||
if (ourNewStyleProfiles == null) {
|
||||
final List<StructuralSearchProfile> list = new ArrayList<StructuralSearchProfile>();
|
||||
|
||||
+1
-2
@@ -2,7 +2,6 @@ package com.intellij.structuralsearch.impl.matcher.compiler;
|
||||
|
||||
import com.intellij.dupLocator.util.NodeFilter;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiIdentifier;
|
||||
import com.intellij.psi.PsiModifier;
|
||||
import com.intellij.structuralsearch.StructuralSearchProfile;
|
||||
import com.intellij.structuralsearch.StructuralSearchUtil;
|
||||
@@ -61,7 +60,7 @@ public class GlobalCompilingVisitor {
|
||||
public final void handle(PsiElement element) {
|
||||
|
||||
if ((!ourFilter.accepts(element) ||
|
||||
element instanceof PsiIdentifier) &&
|
||||
StructuralSearchUtil.isIdentifier(element)) &&
|
||||
context.getPattern().isRealTypedVar(element) &&
|
||||
context.getPattern().getHandlerSimple(element) == null
|
||||
) {
|
||||
|
||||
+2
-1
@@ -1,6 +1,7 @@
|
||||
package com.intellij.structuralsearch.impl.matcher.predicates;
|
||||
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.structuralsearch.StructuralSearchUtil;
|
||||
import com.intellij.structuralsearch.impl.matcher.handlers.SubstitutionHandler;
|
||||
import com.intellij.structuralsearch.impl.matcher.MatchContext;
|
||||
import com.intellij.structuralsearch.impl.matcher.MatchUtils;
|
||||
@@ -14,7 +15,7 @@ public final class ReferencePredicate extends SubstitutionHandler {
|
||||
}
|
||||
|
||||
public boolean match(PsiElement node, PsiElement match, MatchContext context) {
|
||||
if (match instanceof PsiIdentifier) {
|
||||
if (StructuralSearchUtil.isIdentifier(match)) {
|
||||
// since we pickup tokens
|
||||
match = match.getParent();
|
||||
}
|
||||
|
||||
+1
-1
@@ -102,7 +102,7 @@ public final class RegExpPredicate extends MatchPredicate {
|
||||
|
||||
if (!result) {
|
||||
|
||||
if(matchedNode instanceof PsiIdentifier) {
|
||||
if(StructuralSearchUtil.isIdentifier(matchedNode)) {
|
||||
matchedNode = matchedNode.getParent();
|
||||
}
|
||||
|
||||
|
||||
+2
-4
@@ -2,10 +2,8 @@ package com.intellij.structuralsearch.impl.matcher.predicates;
|
||||
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiIdentifier;
|
||||
import com.intellij.structuralsearch.MatchResult;
|
||||
import com.intellij.structuralsearch.SSRBundle;
|
||||
import com.intellij.structuralsearch.StructuralSearchException;
|
||||
import com.intellij.structuralsearch.StructuralSearchUtil;
|
||||
import com.intellij.structuralsearch.impl.matcher.MatchResultImpl;
|
||||
import groovy.lang.Binding;
|
||||
import groovy.lang.GroovyRuntimeException;
|
||||
@@ -54,7 +52,7 @@ public class ScriptSupport {
|
||||
if (context == null) {
|
||||
context = result.getMatchRef().getElement();
|
||||
}
|
||||
if (context instanceof PsiIdentifier) context = context.getParent();
|
||||
if (StructuralSearchUtil.isIdentifier(context)) context = context.getParent();
|
||||
binding.setVariable("__context__", context);
|
||||
script.setBinding(binding);
|
||||
|
||||
|
||||
+2
-2
@@ -2,9 +2,9 @@ package com.intellij.structuralsearch.plugin.replace.impl;
|
||||
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiIdentifier;
|
||||
import com.intellij.psi.PsiNamedElement;
|
||||
import com.intellij.structuralsearch.MatchResult;
|
||||
import com.intellij.structuralsearch.StructuralSearchUtil;
|
||||
import com.intellij.structuralsearch.plugin.replace.ReplaceOptions;
|
||||
|
||||
import java.util.HashMap;
|
||||
@@ -43,7 +43,7 @@ public class ReplacementContext {
|
||||
for (String s : variableMap.keySet()) {
|
||||
final MatchResult matchResult = replacementInfo.getVariableMap().get(s);
|
||||
PsiElement match = matchResult.getMatchRef() != null ? matchResult.getMatch() : null;
|
||||
if (match instanceof PsiIdentifier) match = match.getParent();
|
||||
if (StructuralSearchUtil.isIdentifier(match)) match = match.getParent();
|
||||
|
||||
if (match instanceof PsiNamedElement) {
|
||||
final String name = ((PsiNamedElement)match).getName();
|
||||
|
||||
+1
-2
@@ -396,8 +396,7 @@ public class Replacer {
|
||||
MatchResult matchResult = i.next();
|
||||
|
||||
if (MatchResult.LINE_MATCH.equals(matchResult.getName()) &&
|
||||
matchResult.getMatch() instanceof PsiMember
|
||||
) {
|
||||
matchResult.getMatch() instanceof PsiMember) {
|
||||
element = matchResult.getMatch();
|
||||
} else {
|
||||
l.add( manager.createSmartPsiElementPointer(element) );
|
||||
|
||||
+5
@@ -578,6 +578,11 @@ public class JavaStructuralSearchProfile extends StructuralSearchProfile {
|
||||
return offset;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isIdentifier(PsiElement element) {
|
||||
return element instanceof PsiIdentifier;
|
||||
}
|
||||
|
||||
private static void handleMethodParameter(StringBuilder buf, ParameterInfo info, HashMap<String, MatchResult> matchMap) {
|
||||
if(info.getElement() ==null) {
|
||||
// no specific handling for name of method parameter since it is handled with type
|
||||
|
||||
Reference in New Issue
Block a user