Unnamed: 0
int64
0
305k
body
stringlengths
7
52.9k
name
stringlengths
1
185
293,000
void (@NotNull String criteria, @NotNull MatchOptions options) { final StringBuilder pattern = new StringBuilder(); int anonymousTypedVarsCount = 0; boolean targetFound = false; final MatchVariableConstraint context = options.addNewVariableConstraint(Configuration.CONTEXT_VAR_NAME); final int length = criteria.length(); for (int index = 0; index < length; ++index) { char ch = criteria.charAt(index); if (index == 0 && ch == '[') { index = handleTypedVarCondition(0, criteria, context); if (index == length) break; ch = criteria.charAt(index); } if (ch == '\\' && index + 1 < length) { ch = criteria.charAt(++index); } else if (ch == '\'') { final int newIndex = handleCharacterLiteral(criteria, index, pattern); if (newIndex != index) { index = newIndex; continue; } // typed variable; eat the name of typed var int endIndex = ++index; while (endIndex < length && Character.isJavaIdentifierPart(criteria.charAt(endIndex))) endIndex++; if (endIndex == index) throw new MalformedPatternException(SSRBundle.message("error.expected.character")); boolean target = true; final String typedVar; if (criteria.charAt(index) == '_') { target = false; if (endIndex == index + 1) { // anonymous var, make it unique for the case of constraints anonymousTypedVarsCount++; typedVar = "_" + anonymousTypedVarsCount; } else { typedVar = criteria.substring(index + 1, endIndex); } } else { typedVar = criteria.substring(index, endIndex); } pattern.append("$").append(typedVar).append("$"); index = endIndex; MatchVariableConstraint constraint = options.getVariableConstraint(typedVar); boolean constraintCreated = false; if (constraint == null) { constraint = new MatchVariableConstraint(typedVar); constraintCreated = true; } // Check the number of occurrences for typed variable final int savedIndex = index; int minOccurs = 1; int maxOccurs = 1; boolean greedy = true; if (index < length) { ch = criteria.charAt(index); if (ch == '+') { maxOccurs = Integer.MAX_VALUE; ++index; } else if (ch == '?') { minOccurs = 0; ++index; } else if (ch == '*') { minOccurs = 0; maxOccurs = Integer.MAX_VALUE; ++index; } else if (ch == '{') { ++index; minOccurs = -1; maxOccurs = -1; while (index < length && (ch = criteria.charAt(index)) >= '0' && ch <= '9') { if (minOccurs < 0) minOccurs = 0; minOccurs = (minOccurs * 10) + (ch - '0'); if (minOccurs < 0) throw new MalformedPatternException(SSRBundle.message("error.overflow")); ++index; } if (ch == ',') { ++index; while (index < length && (ch = criteria.charAt(index)) >= '0' && ch <= '9') { if (maxOccurs < 0) maxOccurs = 0; maxOccurs = (maxOccurs * 10) + (ch - '0'); if (maxOccurs < 0) throw new MalformedPatternException(SSRBundle.message("error.overflow")); ++index; } } else { maxOccurs = -2; } if (ch != '}') { if (minOccurs < 0 && maxOccurs < 0) throw new MalformedPatternException(SSRBundle.message("error.expected.digit")); if (maxOccurs < 0) { throw new MalformedPatternException(SSRBundle.message("error.expected.brace1")); } else { throw new MalformedPatternException(SSRBundle.message("error.expected.brace2")); } } if (minOccurs < 0 && maxOccurs < 0) { throw new MalformedPatternException(SSRBundle.message("error.empty.quantifier")); } else if (minOccurs == -1) { minOccurs = 0; } else if (maxOccurs == -1) { maxOccurs = Integer.MAX_VALUE; } else if (maxOccurs == -2) maxOccurs = minOccurs; ++index; } if (index < length) { ch = criteria.charAt(index); if (ch == '?') { greedy = false; ++index; } } } if (constraintCreated) { constraint.setMinCount(minOccurs); constraint.setMaxCount(maxOccurs); constraint.setGreedy(greedy); constraint.setPartOfSearchResults(target); if (targetFound && target) { throw new MalformedPatternException(SSRBundle.message("error.only.one.target.allowed")); } targetFound |= target; } else if (savedIndex != index) { throw new MalformedPatternException(SSRBundle.message("error.condition.only.on.first.variable.reference")); } if (index < length && criteria.charAt(index) == ':') { ++index; if (index >= length) throw new MalformedPatternException(SSRBundle.message("error.expected.condition", ":")); ch = criteria.charAt(index); if (ch == ':') { // double colon instead of condition pattern.append(ch); } else { if (!constraintCreated) { throw new MalformedPatternException(SSRBundle.message("error.condition.only.on.first.variable.reference")); } index = handleTypedVarCondition(index, criteria, constraint); } } if (constraintCreated) { options.addVariableConstraint(constraint); } if (index == length) break; // rewind to process white space or unrelated symbol index--; continue; } pattern.append(ch); } options.setSearchPattern(pattern.toString()); }
transformCriteria
293,001
int (@NotNull String criteria, int index, @NotNull StringBuilder pattern) { final int length = criteria.length(); if (index + 1 < length && criteria.charAt(index + 1) == '\'') { // ignore next ' pattern.append('\''); return index + 1; } else if (index + 2 < length && criteria.charAt(index + 2) == '\'') { // eat simple character pattern.append(criteria, index, index + 3); return index + 2; } else if (index + 3 < length && criteria.charAt(index + 1) == '\\' && criteria.charAt(index + 3) == '\'') { // eat simple escape character pattern.append(criteria, index, index + 4); return index + 3; } else if (index + 7 < length && criteria.charAt(index + 1) == '\\' && criteria.charAt(index + 2) == 'u' && criteria.charAt(index + 7) == '\'') { // eat unicode escape character pattern.append(criteria, index, index + 8); return index + 7; } return index; }
handleCharacterLiteral
293,002
int (int index, @NotNull String criteria, @NotNull MatchVariableConstraint constraint) { final int length = criteria.length(); char ch = criteria.charAt(index); if (ch == '!') { constraint.setInvertRegExp(true); ++index; if (index >= length) throw new MalformedPatternException(SSRBundle.message("error.expected.condition", Character.valueOf(ch))); ch = criteria.charAt(index); } if (ch == '+' || ch == '*') { // this is type axis navigation relation switch (ch) { case '+' -> constraint.setStrictlyWithinHierarchy(true); case '*' -> constraint.setWithinHierarchy(true); } ++index; if (index >= length) throw new MalformedPatternException(SSRBundle.message("error.expected.condition", Character.valueOf(ch))); ch = criteria.charAt(index); } if (ch == '[') { int spaces = 0; // balance spaces surrounding content between brackets while (++index < length && criteria.charAt(index) == ' ') spaces++; // eat complete condition boolean quoted = false; boolean closed = false; int endIndex = index - 1; while (++endIndex < length) { if (criteria.charAt(endIndex - 1) != '\\') { ch = criteria.charAt(endIndex); if (ch == '"') { quoted = !quoted; } else if (ch == ']' && !quoted) { int j = 1; while (j <= spaces && criteria.charAt(endIndex - j) == ' ') j++; if (j - 1 == spaces) { endIndex -= spaces; closed = true; break; } } } } if (quoted) throw new MalformedPatternException(SSRBundle.message("error.expected.value", "\"")); if (!closed) throw new MalformedPatternException(SSRBundle.message("error.expected.value", " ".repeat(spaces) + "]")); if (index > endIndex) throw new MalformedPatternException(SSRBundle.message("error.expected.condition", "[")); parseCondition(constraint, criteria.substring(index, endIndex)); return endIndex + spaces + 1; } else { // eat reg exp constraint return handleRegExp(index, criteria, constraint); } }
handleTypedVarCondition
293,003
int (int index, @NotNull String criteria, @NotNull MatchVariableConstraint constraint) { final int length = criteria.length(); int endIndex = index; while (endIndex < length && !Character.isWhitespace(criteria.charAt(endIndex))) { ++endIndex; } if (endIndex == index) { if (criteria.charAt(index - 1) == ':') { throw new MalformedPatternException(SSRBundle.message("error.expected.condition", ":")); } else { return endIndex; } } final String regexp = criteria.substring(index, endIndex); if (!constraint.getRegExp().isEmpty() && !constraint.getRegExp().equals(regexp)) { throw new MalformedPatternException(SSRBundle.message("error.two.different.type.constraints")); } else { checkRegex(regexp); constraint.setRegExp(regexp); } return endIndex; }
handleRegExp
293,004
void (@NotNull MatchVariableConstraint constraint, @NotNull String condition) { final int length = condition.length(); final StringBuilder text = new StringBuilder(); boolean invert = false; boolean optionExpected = true; for (int i = 0; i < length; i++) { char c = condition.charAt(i); if (Character.isWhitespace(c)) { if (text.length() == 0) continue; handleOption(constraint, text.toString(), "", invert); optionExpected = false; } else if (c == '(') { if (text.length() == 0) throw new MalformedPatternException(SSRBundle.message("error.expected.condition.name")); final String option = text.toString(); if (!option.startsWith("_") && !knownOptions.contains(option)) { throw new MalformedPatternException(SSRBundle.message("option.is.not.recognized.error.message", option)); } text.setLength(0); int spaces = 0; // balance spaces surrounding content between parentheses while (++i < length && condition.charAt(i) == ' ') spaces++; i--; boolean quoted = false; boolean closed = false; while (++i < length) { c = condition.charAt(i); if (condition.charAt(i - 1) != '\\') { if (c == '"') { quoted = !quoted; } else if (c == ')' && !quoted) { int j = 1; while (j <= spaces && condition.charAt(i - j) == ' ') j++; if (j - 1 == spaces) { closed = true; break; } } } text.append(c); } if (text.length() == 0) throw new MalformedPatternException(SSRBundle.message("error.argument.expected", option)); if (quoted) throw new MalformedPatternException(SSRBundle.message("error.expected.value", "\"")); if (!closed) throw new MalformedPatternException(SSRBundle.message("error.expected.value", " ".repeat(spaces) + ")")); handleOption(constraint, option, text.toString(), invert); text.setLength(0); invert = false; optionExpected = false; } else if (c == '&') { if (text.length() != 0) { handleOption(constraint, text.toString(), "", invert); optionExpected = false; } if (++i == length || condition.charAt(i) != '&' || optionExpected) { throw new MalformedPatternException(SSRBundle.message("error.unexpected.value", "&")); } text.setLength(0); invert = false; optionExpected = true; } else if (!optionExpected) { throw new MalformedPatternException(SSRBundle.message("error.expected.value", "&&")); } else if (c == '!') { if (text.length() != 0) throw new MalformedPatternException(SSRBundle.message("error.unexpected.value", "!")); invert = !invert; } else { text.append(c); } } if (text.length() != 0) { handleOption(constraint, text.toString(), "", invert); } else if (invert) { throw new MalformedPatternException(SSRBundle.message("error.expected.condition", "!")); } else if (optionExpected) throw new MalformedPatternException(SSRBundle.message("error.expected.condition", length == 0 ? "[" : "&&")); }
parseCondition
293,005
void (@NotNull MatchVariableConstraint constraint, @NotNull String option, @NotNull String argument, boolean invert) { argument = argument.trim(); if (option.equals(REF)) { constraint.setReferenceConstraint(argument); constraint.setInvertReference(invert); } else if (option.equals(REGEX) || option.equals(REGEXW)) { if (argument.charAt(0) == '*') { argument = argument.substring(1); constraint.setWithinHierarchy(true); } checkRegex(argument); constraint.setRegExp(argument); constraint.setInvertRegExp(invert); if (option.equals(REGEXW)) { constraint.setWholeWordsOnly(true); } } else if (option.equals(EXPRTYPE)) { if (argument.charAt(0) == '*') { argument = argument.substring(1); constraint.setExprTypeWithinHierarchy(true); } boolean regex = false; if (argument.charAt(0) == '~') { argument = argument.substring(1); regex = true; } argument = unescape(argument); if (regex) constraint.setNameOfExprType(argument); else constraint.setExpressionTypes(argument); constraint.setInvertExprType(invert); } else if (option.equals(FORMAL)) { if (argument.charAt(0) == '*') { argument = argument.substring(1); constraint.setFormalArgTypeWithinHierarchy(true); } argument = unescape(argument); constraint.setExpectedTypes(argument); constraint.setInvertFormalType(invert); } else if (option.equals(SCRIPT)) { if (invert) throw new MalformedPatternException(SSRBundle.message("error.cannot.invert", option)); constraint.setScriptCodeConstraint(argument); } else if (option.equals(CONTAINS)) { constraint.setContainsConstraint(argument); constraint.setInvertContainsConstraint(invert); } else if (option.equals(WITHIN)) { if (!Configuration.CONTEXT_VAR_NAME.equals(constraint.getName())) { throw new MalformedPatternException(SSRBundle.message("error.only.applicable.to.complete.match", option)); } constraint.setWithinConstraint(argument); constraint.setInvertWithinConstraint(invert); } else if (option.equals(CONTEXT)) { if (invert) throw new MalformedPatternException(SSRBundle.message("error.cannot.invert", option)); if (!Configuration.CONTEXT_VAR_NAME.equals(constraint.getName())) { throw new MalformedPatternException(SSRBundle.message("error.only.applicable.to.complete.match", option)); } constraint.setContextConstraint(argument); } else if (option.startsWith("_")) { if (invert) throw new MalformedPatternException(SSRBundle.message("error.cannot.invert", option)); constraint.putAdditionalConstraint(option.substring(1), argument); } else { assert false; } }
handleOption
293,006
void (@NotNull String regex) { try { Pattern.compile(regex); } catch (PatternSyntaxException e) { throw new MalformedPatternException(SSRBundle.message("invalid.regular.expression", e.getMessage())); } }
checkRegex
293,007
String (@NotNull String s) { final StringBuilder result = new StringBuilder(); boolean escaped = false; for (int i = 0, length = s.length(); i < length; i++) { final int c = s.codePointAt(i); if (c == '\\' && !escaped) { escaped = true; } else { escaped = false; result.appendCodePoint(c); } } return result.toString(); }
unescape
293,008
boolean () { return true; }
doOptimizing
293,009
void (@NotNull String word, @NotNull String prefix) { myWords.add(prefix + word); myTransactionStarted = true; }
append
293,010
void (@NotNull String word) { append(word, "in code:"); }
doAddSearchWordInCode
293,011
void (@NotNull String word) { append(word, "in text:"); }
doAddSearchWordInText
293,012
void (@NotNull String word) { append(word, "in comments:"); }
doAddSearchWordInComments
293,013
void (@NotNull String word) { append(word, "in literals:"); }
doAddSearchWordInLiterals
293,014
void () { if (!myTransactionStarted) return; myTransactionStarted = false; super.endTransaction(); Collections.sort(myWords); // to ensure stable ordering builder.append('['); boolean bar = false; for (String word : myWords) { if (bar) builder.append('|'); else bar = true; builder.append(word); } this.builder.append(']'); myWords.clear(); }
endTransaction
293,015
boolean () { return false; }
isScannedSomething
293,016
Set<VirtualFile> () { assert !myTransactionStarted; return Collections.emptySet(); }
getFilesSetToScan
293,017
String () { assert !myTransactionStarted; final String plan = builder.toString(); builder.setLength(0); return plan; }
getSearchPlan
293,018
void () { mySearchHelper.clear(); }
clear
293,019
OptimizingSearchHelper () { return mySearchHelper; }
getSearchHelper
293,020
CompiledPattern () { return myPattern; }
getPattern
293,021
MatchOptions () { return myOptions; }
getOptions
293,022
Project () { return myProject; }
getProject
293,023
void () { scanned.clear(); scannedText.clear(); scannedComments.clear(); scannedLiterals.clear(); }
clear
293,024
void (@NotNull String word) { if (doOptimizing() && scanned.add(word)) { doAddSearchWordInCode(word); } }
addWordToSearchInCode
293,025
void (@NotNull String word) { if (doOptimizing() && scannedText.add(word)) { doAddSearchWordInText(word); } }
addWordToSearchInText
293,026
void (@NotNull String word) { if (doOptimizing() && scannedComments.add(word)) { doAddSearchWordInComments(word); } }
addWordToSearchInComments
293,027
void (@NotNull String word) { if (doOptimizing() && scannedLiterals.add(word)) { doAddSearchWordInLiterals(word); } }
addWordToSearchInLiterals
293,028
void () { scanRequest++; }
endTransaction
293,029
boolean () { return !scanned.isEmpty() || !scannedText.isEmpty() || !scannedComments.isEmpty() || !scannedLiterals.isEmpty(); }
isScannedSomething
293,030
void (@NotNull PsiElement element) { collectNode(element, element.getUserData(CompiledPattern.HANDLER_KEY)); super.visitElement(element); if (element instanceof LeafElement) { collectNode(element, pattern.getHandler(pattern.getTypedVarString(element))); } }
visitElement
293,031
void (PsiElement element, MatchingHandler handler) { if (handler instanceof DelegatingHandler) { handler = ((DelegatingHandler)handler).getDelegate(); } if (handler instanceof SubstitutionHandler){ pattern.putVariableNode(((SubstitutionHandler)handler).getName(), element); } }
collectNode
293,032
void (CompiledPattern pattern, PsiElement element) { element.accept(new PsiRecursiveElementWalkingVisitor() { @Override public void visitElement(@NotNull PsiElement element) { if (element.getUserData(CompiledPattern.HANDLER_KEY) != null) { return; } super.visitElement(element); if (!(element instanceof LeafElement)) { return; } final String text = element.getText(); if (!pattern.isTypedVar(text)) { for (String prefix : pattern.getTypedVarPrefixes()) { if (text.contains(prefix)) { throw new MalformedPatternException(); } } return; } final MatchingHandler handler = pattern.getHandler(pattern.getTypedVarString(element)); if (handler == null) { throw new MalformedPatternException(); } } }); }
checkForUnknownVariables
293,033
void (@NotNull PsiElement element) { if (element.getUserData(CompiledPattern.HANDLER_KEY) != null) { return; } super.visitElement(element); if (!(element instanceof LeafElement)) { return; } final String text = element.getText(); if (!pattern.isTypedVar(text)) { for (String prefix : pattern.getTypedVarPrefixes()) { if (text.contains(prefix)) { throw new MalformedPatternException(); } } return; } final MatchingHandler handler = pattern.getHandler(pattern.getTypedVarString(element)); if (handler == null) { throw new MalformedPatternException(); } }
visitElement
293,034
String () { return ourLastSearchPlan; }
getLastSearchPlan
293,035
void (@NotNull PsiElement element) { super.visitElement(element); if (element instanceof LeafElement) { final String text = element.getText(); for (Pattern pattern : substitutionPatterns) { final Matcher matcher = pattern.matcher(text); while (matcher.find()) { result.add(element.getTextRange().getStartOffset() + matcher.end()); } } } }
visitElement
293,036
Boolean (PsiElement element, final int offset, final int patternEndOffset, final int[] varEndOffsets, final boolean strict) { final IntList errorOffsets = new IntArrayList(); final boolean[] containsErrorTail = {false}; final IntSet varEndOffsetsSet = new IntOpenHashSet(varEndOffsets); element.accept(new PsiRecursiveElementWalkingVisitor() { @Override public void visitErrorElement(@NotNull PsiErrorElement element) { super.visitErrorElement(element); final int startOffset = element.getTextRange().getStartOffset(); if ((strict || !varEndOffsetsSet.contains(startOffset)) && startOffset != patternEndOffset) { errorOffsets.add(startOffset); } if (startOffset == offset) { containsErrorTail[0] = true; } } }); for (int i = 0; i < errorOffsets.size(); i++) { final int errorOffset = errorOffsets.getInt(i); if (errorOffset <= offset) { return true; } } return containsErrorTail[0] ? null : false; }
checkErrorElements
293,037
void (@NotNull PsiErrorElement element) { super.visitErrorElement(element); final int startOffset = element.getTextRange().getStartOffset(); if ((strict || !varEndOffsetsSet.contains(startOffset)) && startOffset != patternEndOffset) { errorOffsets.add(startOffset); } if (startOffset == offset) { containsErrorTail[0] = true; } }
visitErrorElement
293,038
String (int varIndex) { return myPrefix; }
getPrefix
293,039
String (int varIndex) { if (varIndex >= myPrefixes.length) return null; return myPrefixes[varIndex]; }
getPrefix
293,040
void (@NotNull MatchOptions options, @NotNull MatchVariableConstraint constraint, @NotNull SubstitutionHandler handler) { final StructuralSearchProfile profile = StructuralSearchUtil.getProfileByFileType(options.getFileType()); assert profile != null; for (MatchPredicate matchPredicate : profile.getCustomPredicates(constraint, handler.getName(), options)) { addPredicate(handler, matchPredicate); } }
addExtensionPredicates
293,041
void (SubstitutionHandler handler, @NotNull MatchPredicate predicate) { handler.setPredicate(handler.getPredicate() == null ? predicate : new AndPredicate(handler.getPredicate(), predicate)); }
addPredicate
293,042
boolean (final PsiElement start) { // XmlElements can also appear under languages which are not a kind of XMLLanguage e.g. TypeScript JSX // assume here that when the user specifies to search for generic XML, these elements should also be found if (myLanguage != XMLLanguage.INSTANCE && !start.getLanguage().isKindOf(myLanguage)) { return false; } return start instanceof XmlElement; }
continueMatching
293,043
boolean (PsiElement element, PsiElement elementToMatchWith) { return false; }
shouldSkip
293,044
NodeIterator (@Nullable PsiElement element) { return (element == null) ? SingleNodeIterator.EMPTY : new SsrFilteringNodeIterator(element); }
create
293,045
NodeIterator (PsiElement @NotNull [] elements) { return new SsrFilteringNodeIterator(new ArrayBackedNodeIterator(elements)); }
create
293,046
boolean () { return index < myList.size(); }
hasNext
293,047
PsiElement () { if (index >= myList.size()) return null; return myList.get(index); }
current
293,048
void () { index++; }
advance
293,049
void () { index--; }
rewind
293,050
void () { index = 0; }
reset
293,051
boolean (@NotNull PsiElement patternNode, @Nullable PsiElement matchNode) { if (patternNode instanceof LeafElement && matchNode instanceof LeafElement) { return ((LeafElement)patternNode).getElementType() == ((LeafElement)matchNode).getElementType(); } return matchNode != null && patternNode.getClass() == matchNode.getClass(); }
accepts
293,052
NodeFilter () { return NodeFilterHolder.INSTANCE; }
getInstance
293,053
boolean (PsiElement element) { if (element == null) return false; final StructuralSearchProfile profile = StructuralSearchUtil.getProfileByPsiElement(element); return profile != null && !profile.isMatchNode(element); }
accepts
293,054
boolean (PsiElement element) { return first.accepts(element) || second.accepts(element); }
accepts
293,055
boolean (PsiElement element) { return element instanceof XmlTagChild || XmlUtil.isXmlToken(element, XmlTokenType.XML_DATA_CHARACTERS); }
accepts
293,056
NodeFilter () { return INSTANCE; }
getInstance
293,057
void (@Nullable NodeFilter filter) { this.filter = filter; }
setFilter
293,058
boolean (PsiElement patternNode, PsiElement matchedNode, @NotNull MatchContext context) { return (patternNode == null) ? matchedNode == null : canMatch(patternNode, matchedNode, context); }
match
293,059
boolean (@NotNull PsiElement patternNode, final PsiElement matchedNode, @NotNull MatchContext context) { return (filter != null) ? filter.accepts(matchedNode) : DefaultFilter.accepts(patternNode, matchedNode); }
canMatch
293,060
boolean (@NotNull NodeIterator patternNodes, @NotNull NodeIterator matchNodes, @NotNull MatchContext context) { final MatchingStrategy strategy = context.getPattern().getStrategy(); final PsiElement currentPatternNode = patternNodes.current(); final PsiElement currentMatchNode = matchNodes.current(); skipIfNecessary(matchNodes, currentPatternNode, strategy); skipIfNecessary(patternNodes, matchNodes.current(), strategy); if (!patternNodes.hasNext()) { return !matchNodes.hasNext(); } final PsiElement patternElement = patternNodes.current(); final MatchingHandler handler = context.getPattern().getHandler(patternElement); if (!(handler instanceof TopLevelMatchingHandler)) skipComments(matchNodes, currentPatternNode); if (matchNodes.hasNext() && handler.match(patternElement, matchNodes.current(), context)) { patternNodes.advance(); skipIfNecessary(patternNodes, matchNodes.current(), strategy); if (shouldAdvanceTheMatchFor(patternElement, matchNodes.current())) { matchNodes.advance(); skipIfNecessary(matchNodes, patternNodes.current(), strategy); if (patternNodes.hasNext()) skipComments(matchNodes, patternNodes.current()); } if (patternNodes.hasNext()) { final MatchingHandler nextHandler = context.getPattern().getHandler(patternNodes.current()); if (nextHandler.matchSequentially(patternNodes, matchNodes, context)) { return true; } else { patternNodes.rewindTo(currentPatternNode); matchNodes.rewindTo(currentMatchNode); } } else { // match was found return handler.isMatchSequentiallySucceeded(matchNodes); } } return false; }
matchSequentially
293,061
void (@NotNull NodeIterator matchNodes, PsiElement patternNode) { if (patternNode instanceof PsiComment) return; while (matchNodes.current() instanceof PsiComment) matchNodes.advance(); }
skipComments
293,062
void (@NotNull NodeIterator nodes, PsiElement elementToMatchWith, @NotNull MatchingStrategy strategy) { while (nodes.hasNext() && strategy.shouldSkip(nodes.current(), elementToMatchWith)) { nodes.advance(); } }
skipIfNecessary
293,063
boolean (@NotNull NodeIterator matchNodes) { skipComments(matchNodes, null); return !matchNodes.hasNext(); }
isMatchSequentiallySucceeded
293,064
void (@NotNull PsiElement element) { // We do not reset certain handlers because they are also bound to higher level nodes // e.g. Identifier handler in name is also bound to PsiMethod if (pattern.isToResetHandler(element)) { final MatchingHandler handler = pattern.getHandlerSimple(element); if (handler != null) { handler.reset(); } } super.visitElement(element); }
visitElement
293,065
boolean (@NotNull NodeIterator patternNodes, @NotNull NodeIterator matchedNodes, @NotNull MatchContext context) { if (patternNodes.hasNext() && !matchedNodes.hasNext()) { return validateSatisfactionOfHandlers(patternNodes, context); } Set<PsiElement> matchedElements = null; while (patternNodes.hasNext()) { final PsiElement patternNode = patternNodes.current(); patternNodes.advance(); final CompiledPattern pattern = context.getPattern(); final MatchingHandler handler = pattern.getHandler(patternNode); matchedNodes.reset(); boolean allElementsMatched = true; int matchedOccurs = 0; do { final PsiElement pinnedNode = handler.getPinnedNode(); final PsiElement matchedNode = (pinnedNode != null) ? pinnedNode : matchedNodes.current(); if (pinnedNode == null) matchedNodes.advance(); if (matchedElements == null || !matchedElements.contains(matchedNode)) { allElementsMatched = false; if (handler.match(patternNode, matchedNode, context)) { matchedOccurs++; if (matchedElements == null) matchedElements = new HashSet<>(); matchedElements.add(matchedNode); if (handler.shouldAdvanceThePatternFor(patternNode, matchedNode)) { break; } } else if (pinnedNode != null) { return false; } // clear state of dependent objects clearingVisitor.clearState(pattern, patternNode); } if (!matchedNodes.hasNext() || pinnedNode != null) { if (!handler.validate(context, matchedOccurs)) return false; if (allElementsMatched || !patternNodes.hasNext()) { final boolean result = validateSatisfactionOfHandlers(patternNodes, context); if (result && matchedElements != null) { context.notifyMatchedElements(matchedElements); } return result; } break; } } while(true); if (!handler.validate(context, matchedOccurs)) return false; } final boolean result = validateSatisfactionOfHandlers(patternNodes, context); if (result && matchedElements != null) { context.notifyMatchedElements(matchedElements); } return result; }
matchInAnyOrder
293,066
boolean (@NotNull NodeIterator patternNodes, @NotNull MatchContext context) { for (; patternNodes.hasNext(); patternNodes.advance()) { if (!context.getPattern().getHandler(patternNodes.current()).validate(context, 0)) { return false; } } return true; }
validateSatisfactionOfHandlers
293,067
boolean (@NotNull MatchContext context, int matchedOccurs) { return matchedOccurs == 1; }
validate
293,068
NodeFilter () { return filter; }
getFilter
293,069
boolean (@NotNull PsiElement patternElement, @NotNull PsiElement matchedElement) { return true; }
shouldAdvanceThePatternFor
293,070
boolean (PsiElement patternElement, PsiElement matchedElement) { return true; }
shouldAdvanceTheMatchFor
293,071
void () { //pinnedElement = null; }
reset
293,072
PsiElement () { return pinnedElement; }
getPinnedNode
293,073
void (@NotNull PsiElement pinnedElement) { this.pinnedElement = pinnedElement; }
setPinnedElement
293,074
boolean (final PsiElement patternNode, final PsiElement matchedNode, final @NotNull MatchContext matchContext) { return myDelegate.match(patternNode, matchedNode, matchContext); }
match
293,075
boolean (@NotNull PsiElement patternNode, PsiElement matchedNode, @NotNull MatchContext context) { return myDelegate.canMatch(patternNode, matchedNode, context); }
canMatch
293,076
boolean (final @NotNull NodeIterator patternNodes, final @NotNull NodeIterator matchNodes, final @NotNull MatchContext context) { return myDelegate.matchSequentially(patternNodes, matchNodes, context); }
matchSequentially
293,077
boolean (final @NotNull NodeIterator matchNodes) { return true; }
isMatchSequentiallySucceeded
293,078
boolean (final PsiElement patternElement, final PsiElement matchedElement) { return myDelegate.shouldAdvanceTheMatchFor(patternElement, matchedElement); }
shouldAdvanceTheMatchFor
293,079
MatchingHandler () { return myDelegate; }
getDelegate
293,080
boolean (PsiElement patternNode, PsiElement matchedNode, @NotNull MatchContext context) { if (!super.match(patternNode,matchedNode,context)) { return false; } return context.getMatcher().match( patternNode.getFirstChild(), matchedNode ); }
match
293,081
boolean (PsiElement patternNode, PsiElement matchedNode, @NotNull MatchContext matchContext) { final boolean matched = delegate.match(patternNode, matchedNode, matchContext); if (matched) { matchContext.addMatchedNode(matchedNode); } if ((!matched || matchContext.getOptions().isRecursiveSearch()) && matchContext.getPattern().getStrategy().continueMatching(matchedNode) && matchContext.shouldRecursivelyMatch() ) { final PsiElement child = matchedNode.getFirstChild(); if (child != null) { matchContext.getMatcher().matchContext(SsrFilteringNodeIterator.create(child)); } } return matched; }
match
293,082
boolean (@NotNull PsiElement patternNode, PsiElement matchedNode, @NotNull MatchContext context) { return delegate.canMatch(patternNode, matchedNode, context); }
canMatch
293,083
boolean (@NotNull NodeIterator patternNodes, @NotNull NodeIterator matchNodes, @NotNull MatchContext context) { return delegate.matchSequentially(patternNodes, matchNodes, context); }
matchSequentially
293,084
boolean (@NotNull NodeIterator matchNodes) { return true; }
isMatchSequentiallySucceeded
293,085
boolean (PsiElement patternElement, PsiElement matchedElement) { return delegate.shouldAdvanceTheMatchFor(patternElement, matchedElement); }
shouldAdvanceTheMatchFor
293,086
MatchingHandler () { return delegate; }
getDelegate
293,087
boolean () { return subtype; }
isSubtype
293,088
boolean () { return strictSubtype; }
isStrictSubtype
293,089
void (boolean strictSubtype) { this.strictSubtype = strictSubtype; }
setStrictSubtype
293,090
void (boolean subtype) { this.subtype = subtype; }
setSubtype
293,091
void (boolean repeatedVar) { myRepeatedVar = repeatedVar; }
setRepeatedVar
293,092
void (@NotNull MatchPredicate handler) { predicate = handler; }
setPredicate
293,093
MatchPredicate () { return predicate; }
getPredicate
293,094
boolean (@NotNull PsiElement match, int start, int end, @NotNull MatchResult result, @NotNull MatchContext matchContext) { if (!myRepeatedVar) { return true; } if (start == 0 && end == -1 && result.getStart() == 0 && result.getEnd() == -1) { return matchContext.getMatcher().match(match, result.getMatch()); } else { final StructuralSearchProfile profile = StructuralSearchUtil.getProfileByPsiElement(match); assert profile != null; return profile.getText(match, start, end).equals(result.getMatchImage()); } }
validateOneMatch
293,095
boolean (PsiElement match, @NotNull MatchContext context) { return validate(match, 0, -1, context); }
validate
293,096
boolean (PsiElement match, int start, int end, @NotNull MatchContext context) { if (match == null || predicate != null && !predicate.match(match, start, end, context)) { return false; } MatchResult result = context.hasResult() ? context.getResult().findChild(name) : null; if (result == null && myNestedResult != null) { result = myNestedResult.findChild(name); } if (result == null) { final MatchResultImpl previous = context.getPreviousResult(); if (previous != null) { result = previous.findChild(name); } } if (result != null) { if (minOccurs == 1 && maxOccurs == 1) { // check if they are the same return validateOneMatch(match, start, end, result, context); } if (maxOccurs > 1 && totalMatchedOccurs != -1) { if (result.isMultipleMatch()) { final List<MatchResult> children = result.getChildren(); final int size = children.size(); if (matchedOccurs >= size) { return false; } if (size != 0) { result = children.get(matchedOccurs); } } // check if they are the same return validateOneMatch(match, start, end, result, context); } } return true; }
validate
293,097
boolean (PsiElement node, PsiElement match, @NotNull MatchContext context) { if (!super.match(node, match, context)) return false; return matchHandler == null ? context.getMatcher().match(node, match): matchHandler.match(node, match, context); }
match
293,098
void (@NotNull PsiElement match, @NotNull MatchContext context) { addResult(match, 0, -1, context); }
addResult
293,099
void (@NotNull PsiElement match, int start, int end, @NotNull MatchContext context) { if (totalMatchedOccurs == -1) { final MatchResultImpl matchResult = context.getResult(); final MatchResultImpl substitution = matchResult.getChild(name); if (substitution == null) { matchResult.addChild(createMatch(match, start, end) ); } else if (maxOccurs > 1 || target && !myRepeatedVar) { final MatchResultImpl result = createMatch(match, start, end); if (!substitution.isMultipleMatch()) { // adding intermediate node to contain all multiple matches final MatchResultImpl sonresult = new MatchResultImpl( substitution.getName(), substitution.getMatchImage(), substitution.getMatchRef(), substitution.getStart(), substitution.getEnd(), target ); substitution.setMatch(match); substitution.setMultipleMatch(true); if (substitution.isScopeMatch()) { substitution.setScopeMatch(false); sonresult.setScopeMatch(true); for (MatchResult r : substitution.getChildren()) { sonresult.addChild(r); } substitution.removeChildren(); } substitution.addChild(sonresult); } substitution.addChild(result); } } }
addResult