Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
小 白蛋
Intellij Community
Commits
7febd8f6
Commit
7febd8f6
authored
7 years ago
by
Bas Leijdekkers
Browse files
Options
Download
Email Patches
Plain Diff
SSR: move findRegExpPredicate() to a better place
parent
0d91685e
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
java/structuralsearch-java/src/com/intellij/structuralsearch/impl/matcher/JavaMatchingVisitor.java
+1
-1
...ij/structuralsearch/impl/matcher/JavaMatchingVisitor.java
java/structuralsearch-java/src/com/intellij/structuralsearch/impl/matcher/compiler/JavaCompilingVisitor.java
+2
-2
...ralsearch/impl/matcher/compiler/JavaCompilingVisitor.java
platform/structuralsearch/source/com/intellij/structuralsearch/impl/matcher/compiler/GlobalCompilingVisitor.java
+8
-8
...lsearch/impl/matcher/compiler/GlobalCompilingVisitor.java
platform/structuralsearch/source/com/intellij/structuralsearch/impl/matcher/compiler/XmlCompilingVisitor.java
+1
-2
...uralsearch/impl/matcher/compiler/XmlCompilingVisitor.java
platform/structuralsearch/source/com/intellij/structuralsearch/impl/matcher/handlers/MatchingHandler.java
+0
-25
...ructuralsearch/impl/matcher/handlers/MatchingHandler.java
platform/structuralsearch/source/com/intellij/structuralsearch/impl/matcher/handlers/SubstitutionHandler.java
+25
-0
...uralsearch/impl/matcher/handlers/SubstitutionHandler.java
with
37 additions
and
38 deletions
+37
-38
java/structuralsearch-java/src/com/intellij/structuralsearch/impl/matcher/JavaMatchingVisitor.java
+
1
-
1
View file @
7febd8f6
...
...
@@ -787,7 +787,7 @@ public class JavaMatchingVisitor extends JavaElementVisitor {
}
}
else
if
(
matchedArrayDimensions
!=
0
)
{
regExpPredicate
=
MatchingHandler
.
getSimple
RegExpPredicate
(
handler
);
regExpPredicate
=
handler
.
find
RegExpPredicate
();
if
(
regExpPredicate
!=
null
)
{
regExpPredicate
.
setNodeTextGenerator
(
new
RegExpPredicate
.
NodeTextGenerator
()
{
...
...
This diff is collapsed.
Click to expand it.
java/structuralsearch-java/src/com/intellij/structuralsearch/impl/matcher/compiler/JavaCompilingVisitor.java
+
2
-
2
View file @
7febd8f6
...
...
@@ -118,7 +118,7 @@ public class JavaCompilingVisitor extends JavaRecursiveElementWalkingVisitor {
return
false
;
}
final
RegExpPredicate
predicate
=
MatchingHandler
.
getSimple
RegExpPredicate
(
handler
);
final
RegExpPredicate
predicate
=
handler
.
find
RegExpPredicate
();
if
(
predicate
!=
null
&&
predicate
.
couldBeOptimized
())
{
if
(
handler
.
isStrictSubtype
()
||
handler
.
isSubtype
())
{
addDescendantsOf
(
predicate
.
getRegExp
(),
handler
.
isSubtype
(),
compileContext
);
...
...
@@ -213,7 +213,7 @@ public class JavaCompilingVisitor extends JavaRecursiveElementWalkingVisitor {
((
RegExpPredicate
)
handler
.
getPredicate
()).
setMultiline
(
true
);
}
RegExpPredicate
predicate
=
MatchingHandler
.
getSimple
RegExpPredicate
(
handler
);
RegExpPredicate
predicate
=
handler
.
find
RegExpPredicate
();
if
(
GlobalCompilingVisitor
.
isSuitablePredicate
(
predicate
,
handler
))
{
myCompilingVisitor
.
processTokenizedName
(
predicate
.
getRegExp
(),
true
,
GlobalCompilingVisitor
.
OccurenceKind
.
COMMENT
);
}
...
...
This diff is collapsed.
Click to expand it.
platform/structuralsearch/source/com/intellij/structuralsearch/impl/matcher/compiler/GlobalCompilingVisitor.java
+
8
-
8
View file @
7febd8f6
...
...
@@ -4,6 +4,7 @@ package com.intellij.structuralsearch.impl.matcher.compiler;
import
com.intellij.dupLocator.util.NodeFilter
;
import
com.intellij.openapi.extensions.Extensions
;
import
com.intellij.psi.PsiElement
;
import
com.intellij.structuralsearch.MalformedPatternException
;
import
com.intellij.structuralsearch.StructuralSearchProfile
;
import
com.intellij.structuralsearch.StructuralSearchUtil
;
import
com.intellij.structuralsearch.impl.matcher.filters.CompositeFilter
;
...
...
@@ -151,19 +152,14 @@ public class GlobalCompilingVisitor {
@NonNls
StringBuilder
buf
=
new
StringBuilder
(
content
.
length
());
Matcher
matcher
=
substitutionPattern
.
matcher
(
content
);
List
<
SubstitutionHandler
>
handlers
=
n
ull
;
List
<
SubstitutionHandler
>
handlers
=
n
ew
SmartList
<>()
;
int
start
=
0
;
String
word
;
boolean
hasLiteralContent
=
false
;
SubstitutionHandler
handler
=
null
;
while
(
matcher
.
find
())
{
if
(
handlers
==
null
)
handlers
=
new
SmartList
<>();
handler
=
(
SubstitutionHandler
)
getContext
().
getPattern
().
getHandler
(
matcher
.
group
(
1
));
if
(
handler
!=
null
)
handlers
.
add
(
handler
);
word
=
content
.
substring
(
start
,
matcher
.
start
());
if
(!
word
.
isEmpty
())
{
buf
.
append
(
StructuralSearchUtil
.
shieldRegExpMetaChars
(
word
));
hasLiteralContent
=
true
;
...
...
@@ -171,7 +167,11 @@ public class GlobalCompilingVisitor {
processTokenizedName
(
word
,
false
,
kind
);
}
RegExpPredicate
predicate
=
MatchingHandler
.
getSimpleRegExpPredicate
(
handler
);
handler
=
(
SubstitutionHandler
)
getContext
().
getPattern
().
getHandler
(
matcher
.
group
(
1
));
if
(
handler
==
null
)
throw
new
MalformedPatternException
();
handlers
.
add
(
handler
);
RegExpPredicate
predicate
=
handler
.
findRegExpPredicate
();
if
(
predicate
==
null
||
!
predicate
.
isWholeWords
())
{
buf
.
append
(
"(.*?)"
);
...
...
@@ -204,7 +204,7 @@ public class GlobalCompilingVisitor {
buf
.
append
(
"$"
);
}
if
(
handlers
!=
null
)
{
if
(
!
handlers
.
isEmpty
()
)
{
return
hasLiteralContent
?
new
LiteralWithSubstitutionHandler
(
buf
.
toString
(),
handlers
)
:
handler
;
}
...
...
This diff is collapsed.
Click to expand it.
platform/structuralsearch/source/com/intellij/structuralsearch/impl/matcher/compiler/XmlCompilingVisitor.java
+
1
-
2
View file @
7febd8f6
...
...
@@ -10,7 +10,6 @@ import com.intellij.psi.xml.XmlText;
import
com.intellij.psi.xml.XmlToken
;
import
com.intellij.structuralsearch.impl.matcher.CompiledPattern
;
import
com.intellij.structuralsearch.impl.matcher.filters.TagValueFilter
;
import
com.intellij.structuralsearch.impl.matcher.handlers.MatchingHandler
;
import
com.intellij.structuralsearch.impl.matcher.handlers.SubstitutionHandler
;
import
com.intellij.structuralsearch.impl.matcher.handlers.TopLevelMatchingHandler
;
import
com.intellij.structuralsearch.impl.matcher.predicates.RegExpPredicate
;
...
...
@@ -79,7 +78,7 @@ public class XmlCompilingVisitor extends XmlRecursiveElementVisitor {
return
false
;
}
final
RegExpPredicate
predicate
=
MatchingHandler
.
getSimple
RegExpPredicate
(
handler
);
final
RegExpPredicate
predicate
=
handler
.
find
RegExpPredicate
();
if
(
predicate
!=
null
&&
predicate
.
couldBeOptimized
())
{
GlobalCompilingVisitor
.
addFilesToSearchForGivenWord
(
predicate
.
getRegExp
(),
true
,
CODE
,
compileContext
);
}
...
...
This diff is collapsed.
Click to expand it.
platform/structuralsearch/source/com/intellij/structuralsearch/impl/matcher/handlers/MatchingHandler.java
+
0
-
25
View file @
7febd8f6
...
...
@@ -10,10 +10,6 @@ import com.intellij.structuralsearch.impl.matcher.CompiledPattern;
import
com.intellij.structuralsearch.impl.matcher.MatchContext
;
import
com.intellij.structuralsearch.impl.matcher.MatchResultImpl
;
import
com.intellij.structuralsearch.impl.matcher.filters.DefaultFilter
;
import
com.intellij.structuralsearch.impl.matcher.predicates.AndPredicate
;
import
com.intellij.structuralsearch.impl.matcher.predicates.MatchPredicate
;
import
com.intellij.structuralsearch.impl.matcher.predicates.NotPredicate
;
import
com.intellij.structuralsearch.impl.matcher.predicates.RegExpPredicate
;
import
com.intellij.structuralsearch.impl.matcher.strategies.MatchingStrategy
;
import
java.util.HashSet
;
...
...
@@ -104,27 +100,6 @@ public abstract class MatchingHandler {
return
!
nodes2
.
hasNext
();
}
private
static
MatchPredicate
findRegExpPredicate
(
MatchPredicate
start
)
{
if
(
start
==
null
)
return
null
;
if
(
start
instanceof
RegExpPredicate
)
return
start
;
if
(
start
instanceof
AndPredicate
)
{
AndPredicate
binary
=
(
AndPredicate
)
start
;
final
MatchPredicate
result
=
findRegExpPredicate
(
binary
.
getFirst
());
if
(
result
!=
null
)
return
result
;
return
findRegExpPredicate
(
binary
.
getSecond
());
}
else
if
(
start
instanceof
NotPredicate
)
{
return
null
;
}
return
null
;
}
public
static
RegExpPredicate
getSimpleRegExpPredicate
(
SubstitutionHandler
handler
)
{
if
(
handler
==
null
)
return
null
;
return
(
RegExpPredicate
)
findRegExpPredicate
(
handler
.
getPredicate
());
}
static
class
ClearStateVisitor
extends
PsiRecursiveElementWalkingVisitor
{
private
CompiledPattern
pattern
;
...
...
This diff is collapsed.
Click to expand it.
platform/structuralsearch/source/com/intellij/structuralsearch/impl/matcher/handlers/SubstitutionHandler.java
+
25
-
0
View file @
7febd8f6
...
...
@@ -11,9 +11,13 @@ import com.intellij.structuralsearch.StructuralSearchUtil;
import
com.intellij.structuralsearch.impl.matcher.CompiledPattern
;
import
com.intellij.structuralsearch.impl.matcher.MatchContext
;
import
com.intellij.structuralsearch.impl.matcher.MatchResultImpl
;
import
com.intellij.structuralsearch.impl.matcher.predicates.AndPredicate
;
import
com.intellij.structuralsearch.impl.matcher.predicates.MatchPredicate
;
import
com.intellij.structuralsearch.impl.matcher.predicates.NotPredicate
;
import
com.intellij.structuralsearch.impl.matcher.predicates.RegExpPredicate
;
import
com.intellij.structuralsearch.plugin.ui.Configuration
;
import
com.intellij.structuralsearch.plugin.util.SmartPsiPointer
;
import
org.jetbrains.annotations.Nullable
;
import
java.util.HashSet
;
import
java.util.List
;
...
...
@@ -91,6 +95,27 @@ public class SubstitutionHandler extends MatchingHandler {
return
predicate
;
}
@Nullable
public
RegExpPredicate
findRegExpPredicate
()
{
return
findRegExpPredicate
(
getPredicate
());
}
private
static
RegExpPredicate
findRegExpPredicate
(
MatchPredicate
start
)
{
if
(
start
==
null
)
return
null
;
if
(
start
instanceof
RegExpPredicate
)
return
(
RegExpPredicate
)
start
;
if
(
start
instanceof
AndPredicate
)
{
AndPredicate
binary
=
(
AndPredicate
)
start
;
final
RegExpPredicate
result
=
findRegExpPredicate
(
binary
.
getFirst
());
if
(
result
!=
null
)
return
result
;
return
findRegExpPredicate
(
binary
.
getSecond
());
}
else
if
(
start
instanceof
NotPredicate
)
{
return
null
;
}
return
null
;
}
private
static
boolean
validateOneMatch
(
final
PsiElement
match
,
int
start
,
int
end
,
final
MatchResult
result
,
final
MatchContext
matchContext
)
{
if
(
match
!=
null
)
{
if
(
start
==
0
&&
end
==
-
1
&&
result
.
getStart
()
==
0
&&
result
.
getEnd
()
==
-
1
)
{
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment