Unnamed: 0
int64
0
305k
body
stringlengths
7
52.9k
name
stringlengths
1
185
292,200
PatternContext () { final Language dialect = getDialect(); return (dialect == null) ? null : StructuralSearchUtil.findPatternContextByID(myPatternContextId, dialect); }
getPatternContext
292,201
void (PatternContext patternContext) { myPatternContextId = (patternContext == null) ? null : patternContext.getId(); }
setPatternContext
292,202
boolean (PsiElement element) { return !(element instanceof PsiWhiteSpace) && !(element instanceof PsiErrorElement); }
isMatchNode
292,203
List<MatchPredicate> (@NotNull MatchVariableConstraint constraint, @NotNull String name, @NotNull MatchOptions options) { return Collections.emptyList(); }
getCustomPredicates
292,204
List<PatternContext> () { return Collections.emptyList(); }
getPatternContexts
292,205
String () { return PATTERN_PLACEHOLDER; }
getPlaceholderVarName
292,206
String (@NotNull String pattern, @Nullable Language language, @Nullable String contextId) { return getPlaceholderVarName(); }
getContext
292,207
String (@NotNull String contextConstraint, @NotNull Project project) { Configuration configuration = ConfigurationManager.getInstance(project).findConfigurationByName(contextConstraint); return configuration != null ? configuration.getMatchOptions().getSearchPattern() : getPlaceholderVarName(); }
getContextByConstraint
292,208
PsiCodeFragment (@NotNull Project project, @NotNull String text, @Nullable String contextId) { return null; }
createCodeFragment
292,209
String (@NotNull PsiFile fragment) { return fragment.getText(); }
getCodeFragmentText
292,210
LanguageFileType (@NotNull PsiElement context) { return null; }
detectFileType
292,211
StructuralReplaceHandler (@NotNull Project project, @NotNull ReplaceOptions replaceOptions) { return null; }
getReplaceHandler
292,212
boolean () { return false; }
supportsShortenFQNames
292,213
boolean () { return false; }
supportsUseStaticImports
292,214
void (@NotNull CompiledPattern pattern) {}
checkSearchPattern
292,215
void (@NotNull Project project, @NotNull ReplaceOptions options) { if (isReplaceSupported()) return; final LanguageFileType fileType = options.getMatchOptions().getFileType(); if (fileType == null) return; final String fileTypeName = StringUtil.toLowerCase(fileType.getName()); throw new UnsupportedPatternException(SSRBundle.message("replacement.not.supported.for.filetype", fileTypeName)); }
checkReplacementPattern
292,216
boolean () { if (myReplaceSupported != null) return myReplaceSupported; Class<?> declaringClass = ReflectionUtil.getMethodDeclaringClass(getClass(), "getReplaceHandler", Project.class, ReplaceOptions.class); return myReplaceSupported = !StructuralSearchProfile.class.equals(declaringClass); }
isReplaceSupported
292,217
boolean (@NotNull PsiErrorElement error) { return false; }
shouldShowProblem
292,218
boolean (@NotNull PsiElement element) { return false; }
canBeVarDelimiter
292,219
String (@NotNull PsiElement match, int start, int end) { final String matchText = match.getText(); if (start == 0 && end == -1) return matchText; return matchText.substring(start, end == -1 ? matchText.length() : end); }
getText
292,220
String (@NotNull PsiElement element) { if (element instanceof PsiNamedElement) { final String name = ((PsiNamedElement)element).getName(); if (name != null) { return name; } } return element.getText(); }
getTypedVarString
292,221
String (@NotNull PsiElement element) { return getTypedVarString(element); }
getMeaningfulText
292,222
String (@NotNull PsiElement element, @NotNull String previousText) { return null; }
getAlternativeText
292,223
PsiElement (@NotNull PsiElement node) { return node; }
updateCurrentNode
292,224
PsiElement (@NotNull PsiElement node) { return node; }
extendMatchedByDownUp
292,225
LanguageFileType (@Nullable LanguageFileType fileType) { return fileType; }
getDefaultFileType
292,226
void (@NotNull PsiElement node, @NotNull ReplaceOptions options, @NotNull ReplacementBuilder builder) {}
provideAdditionalReplaceOptions
292,227
void (@NotNull ParameterInfo info, @NotNull MatchResult match, @NotNull StringBuilder result, @NotNull ReplacementInfo replacementInfo) { if (info.getName().equals(match.getName())) { final String replacementString; boolean removeSemicolon = false; if (match.hasChildren() && !match.isScopeMatch()) { // compound matches final StringBuilder buf = new StringBuilder(); for (final MatchResult matchResult : match.getChildren()) { final PsiElement currentElement = matchResult.getMatch(); if (buf.length() > 0) { if (info.isArgumentContext()) { buf.append(','); } else { final PsiElement sibling = currentElement.getPrevSibling(); buf.append(sibling instanceof PsiWhiteSpace ? sibling.getText() : " "); } } buf.append(matchResult.getMatchImage()); removeSemicolon = currentElement instanceof PsiComment; } replacementString = buf.toString(); } else { if (info.isStatementContext()) { removeSemicolon = match.getMatch() instanceof PsiComment; } replacementString = match.getMatchImage(); } int offset = Replacer.insertSubstitution(result, 0, info, replacementString); if (info.isStatementContext() && (removeSemicolon || StringUtil.endsWithChar(replacementString, ';') || StringUtil.endsWithChar(replacementString, '}'))) { final int start = info.getStartIndex() + offset; result.delete(start, start + 1); } }
handleSubstitution
292,228
void (@NotNull ParameterInfo info, @NotNull StringBuilder result) { if (info.isHasCommaBefore()) { result.delete(info.getBeforeDelimiterPos(), info.getBeforeDelimiterPos() + 1); } else if (info.isHasCommaAfter()) { result.delete(info.getAfterDelimiterPos(), info.getAfterDelimiterPos() + 1); } else if (info.getStartIndex() < result.length() && StringUtil.isLineBreak(result.charAt(info.getStartIndex()))) { result.deleteCharAt(info.getStartIndex()); // delete line break when count filter matches nothing } }
handleNoSubstitution
292,229
boolean (@Nullable PsiElement element) { return false; }
isIdentifier
292,230
Collection<String> () { return Collections.emptySet(); }
getReservedWords
292,231
boolean (@NotNull PsiElement match) { return false; }
isDocCommentOwner
292,232
PsiElement (@NotNull PsiElement element) { if (isIdentifier(element)) { final PsiElement parent = element.getParent(); if (parent != null) return parent; } return element; }
getPresentableElement
292,233
boolean (@NotNull String constraintName, @Nullable PsiElement variableNode, boolean completePattern, boolean target) { switch (constraintName) { case UIUtil.MINIMUM_ZERO: if (target) return false; case UIUtil.MAXIMUM_UNLIMITED: case UIUtil.TEXT: case UIUtil.REFERENCE: return !completePattern; } return false; }
isApplicableConstraint
292,234
boolean (@NotNull String constraintName, @NotNull List<? extends PsiElement> nodes, boolean completePattern, boolean target) { if (nodes.isEmpty()) { return isApplicableConstraint(constraintName, (PsiElement)null, completePattern, target); } boolean result = true; for (PsiElement node : nodes) { result &= isApplicableConstraint(constraintName, node, completePattern, target); } return result; }
isApplicableConstraint
292,235
boolean (@NotNull Configuration configuration) { return !configuration.isPredefined(); }
isApplicableContextConfiguration
292,236
Matcher (@NotNull Project project, @NotNull LanguageFileType fileType, @NotNull String constraint) { if (StringUtil.isQuotedString(constraint)) { // keep old configurations working, also useful for testing final MatchOptions matchOptions = new MatchOptions(); matchOptions.setFileType(fileType); matchOptions.fillSearchCriteria(StringUtil.unquoteString(constraint)); return new Matcher(project, matchOptions); } else { final Set<String> set = ourRecursionGuard.get(); if (!set.add(constraint)) { throw new MalformedPatternException(SSRBundle.message("error.pattern.recursively.references.itself")); } try { final Configuration configuration = ConfigurationManager.getInstance(project).findConfigurationByName(constraint); if (configuration == null) { throw new MalformedPatternException(SSRBundle.message("error.configuration.0.not.found", constraint)); } return new Matcher(project, configuration.getMatchOptions()); } finally { set.remove(constraint); if (set.isEmpty()) { // we're finished with this thread local ourRecursionGuard.remove(); } } } }
buildMatcher
292,237
void (Project project, MatchOptions options) { PatternCompiler.compilePattern(project, options, true, true); }
validate
292,238
boolean (@NotNull NodeIterator matchedNodes) { final MatchContext matchContext = getMatchContext(); final CompiledPattern pattern = matchContext.getPattern(); final NodeIterator patternNodes = pattern.getNodes(); try { while (true) { final PsiElement patternNode = patternNodes.current(); if (patternNode == null) { return true; } final PsiElement matchedNode = matchedNodes.current(); if (matchedNode == null) { return false; } final MatchingHandler matchingHandler = pattern.getHandler(patternNode); if (!matchingHandler.canMatch(patternNode, matchedNode, matchContext)) { return false; } matchedNodes.advance(); patternNodes.advance(); } } finally { patternNodes.reset(); matchedNodes.reset(); } }
checkIfShouldAttemptToMatch
292,239
void (NodeIterator matchedNodes) { try { visitor.matchContext(matchedNodes); } finally { matchedNodes.reset(); } }
processMatchesInElement
292,240
boolean (@NotNull PsiElement element) { final MatchContext matchContext = getMatchContext(); matchContext.clear(); final CollectingMatchResultSink sink = new CollectingMatchResultSink(); matchContext.setSink(new DuplicateFilteringResultSink(sink)); final CompiledPattern compiledPattern = matchContext.getPattern(); if (compiledPattern == null) { return false; } matchContext.setShouldRecursivelyMatch(false); visitor.matchContext(SingleNodeIterator.create(element)); return !sink.getMatches().isEmpty(); }
matchNode
292,241
void () { final MatchContext matchContext = getMatchContext(); final MatchOptions options = matchContext.getOptions(); final CompiledPattern compiledPattern = matchContext.getPattern(); SearchScope searchScope = compiledPattern.getScope(); final boolean ourOptimizedScope = searchScope != null; if (!ourOptimizedScope) searchScope = options.getScope(); if (searchScope instanceof GlobalSearchScope) { final GlobalSearchScope scope = (GlobalSearchScope)searchScope; final ContentIterator ci = fileOrDir -> { if (!fileOrDir.isDirectory() && scope.contains(fileOrDir) && !FileTypeRegistry.getInstance().isFileOfType(fileOrDir, FileTypes.UNKNOWN)) { ++totalFilesToScan; scheduler.addOneTask(new MatchOneVirtualFile(fileOrDir)); } return true; }; final ProgressIndicator progress = matchContext.getSink().getProgressIndicator(); ReadAction.run(() -> FileBasedIndex.getInstance().iterateIndexableFiles(ci, project, progress)); if (progress != null) progress.setText2(""); } else { final LocalSearchScope scope = (LocalSearchScope)searchScope; assert scope != null; final PsiElement[] elementsToScan = scope.getScope(); totalFilesToScan = elementsToScan.length; for (int i = 0; i < elementsToScan.length; ++i) { final PsiElement psiElement = elementsToScan[i]; if (psiElement == null) continue; scheduler.addOneTask(new MatchOnePsiFile(psiElement)); if (ourOptimizedScope) elementsToScan[i] = null; // to prevent long PsiElement reference } } }
findMatches
292,242
MatchContext () { return visitor.getMatchContext(); }
getMatchContext
292,243
Project () { return project; }
getProject
292,244
void () { ended = true; }
stop
292,245
void () { suspended = true; }
pause
292,246
void () { if (!suspended) return; suspended = false; PsiManager.getInstance(project).runInBatchFilesMode(() -> { executeNext(); return null; }); }
resume
292,247
boolean () { return suspended; }
isSuspended
292,248
boolean () { return ended; }
isEnded
292,249
void () { assert project != null; if (tasks != null) { taskQueueEndAction.run(); tasks = null; } }
clearSchedule
292,250
void (@NotNull PsiElement element) { final MatchContext context = getMatchContext(); final MatchingStrategy strategy = context.getPattern().getStrategy(); if (strategy.continueMatching(element)) { visitor.matchContext(SingleNodeIterator.create(element)); return; } if (context.getOptions().isSearchInjectedCode()) { for (PsiElement el = element.getFirstChild(); el != null; el = el.getNextSibling()) { match(el); } if (element instanceof PsiLanguageInjectionHost) { InjectedLanguageManager.getInstance(project).enumerateEx(element, element.getContainingFile(), false, (injectedPsi, places) -> match(injectedPsi)); } } }
match
292,251
List<PsiElement> () { final PsiElement file = this.file; this.file = null; return new SmartList<>(file); }
getPsiElementsToProcess
292,252
List<PsiElement> () { assert project != null; return ReadAction.compute( () -> { if (!myFile.isValid()) { // file may be been deleted since search started return Collections.emptyList(); } final PsiFile file = PsiManager.getInstance(project).findFile(myFile); if (file == null) { return Collections.emptyList(); } final FileViewProvider viewProvider = file.getViewProvider(); final List<PsiElement> elementsToProcess = new SmartList<>(); for (Language lang : viewProvider.getLanguages()) { elementsToProcess.add(viewProvider.getPsi(lang)); } return elementsToProcess; } ); }
getPsiElementsToProcess
292,253
void () { assert project != null; final List<PsiElement> files = getPsiElementsToProcess(); final MatchContext matchContext = getMatchContext(); final ProgressIndicator progress = matchContext.getSink().getProgressIndicator(); if (progress != null) progress.setFraction((double)scannedFilesCount/totalFilesToScan); ++scannedFilesCount; if (files.isEmpty()) return; for (final PsiElement file : files) { if (file instanceof PsiFile) { matchContext.getSink().processFile((PsiFile)file); } ReadAction.nonBlocking( () -> { if (!file.isValid()) return; match(file); } ).inSmartMode(project).executeSynchronously(); } }
run
292,254
void (@NotNull ReplacementInfo info) {}
prepare
292,255
void (@NotNull PsiElement affectedElement, @NotNull ReplaceOptions options) {}
postProcess
292,256
void (@NotNull AnActionEvent event) { triggerAction(null, new SearchContext(event.getDataContext()), true); }
actionPerformed
292,257
DialogWrapper () { return myDialog; }
getDialog
292,258
void (DialogWrapper dialog) { if (dialog != null && (dialog.isDisposed() || dialog.isModal())) { return; } myDialog = dialog; }
setDialog
292,259
StructuralSearchPlugin (@NotNull Project project) { return project.getService(StructuralSearchPlugin.class); }
getInstance
292,260
ActionUpdateThread () { return ActionUpdateThread.BGT; }
getActionUpdateThread
292,261
void (@NotNull AnActionEvent event) { triggerAction(null, new SearchContext(event.getDataContext()), false); }
actionPerformed
292,262
void (Configuration config, @NotNull SearchContext searchContext, boolean replace) { final Project project = searchContext.getProject(); PsiDocumentManager.getInstance(project).commitAllDocuments(); final DialogWrapper dialog = StructuralSearchPlugin.getInstance(project).getDialog(); if (dialog != null) { assert !dialog.isDisposed() && dialog.isVisible(); final JComponent component = dialog.getPreferredFocusedComponent(); assert component != null; IdeFocusManager.getInstance(project).requestFocus(component, true); return; } final StructuralSearchDialog searchDialog = new StructuralSearchDialog(searchContext, replace); if (config != null) { searchDialog.loadConfiguration(config); } StructuralSearchPlugin.getInstance(project).setDialog(searchDialog); searchDialog.show(); }
triggerAction
292,263
VirtualFile () { return pointer.getVirtualFile(); }
getFile
292,264
int () { PsiElement element = getElement(); return element == null ? -1 : element.getTextRange().getStartOffset(); }
getOffset
292,265
int () { PsiElement element = getElement(); return element == null ? 0 : element.getTextRange().getEndOffset(); }
getLength
292,266
PsiElement () { return pointer.getElement(); }
getElement
292,267
boolean (Object o) { if (!(o instanceof SmartPsiPointer ref)) { return false; } return ref.pointer.equals(pointer); }
equals
292,268
int () { PsiElement element = getElement(); return element == null ? 0 : element.hashCode(); }
hashCode
292,269
void (@NotNull MatchResult result) { matches.add(result); }
newMatch
292,270
List<MatchResult> () { return matches; }
getMatches
292,271
void (@NotNull MatchResult result) { if (!duplicates.add(result.getMatchRef())) { return; } delegate.newMatch(result); }
newMatch
292,272
void (@NotNull PsiFile element) { delegate.processFile(element); }
processFile
292,273
void (@NotNull MatchingProcess matchingProcess) { delegate.setMatchingProcess(matchingProcess); }
setMatchingProcess
292,274
void () { duplicates.clear(); delegate.matchingFinished(); }
matchingFinished
292,275
ProgressIndicator () { return delegate.getProgressIndicator(); }
getProgressIndicator
292,276
ReplaceOptions () { return new ReplaceOptions(this); }
copy
292,277
void (@NotNull String replacement) { this.replacement = replacement; }
setReplacement
292,278
boolean () { return toShortenFQN; }
isToShortenFQN
292,279
void (boolean shortedFQN) { this.toShortenFQN = shortedFQN; }
setToShortenFQN
292,280
boolean () { return myToReformatAccordingToStyle; }
isToReformatAccordingToStyle
292,281
MatchOptions () { return matchOptions; }
getMatchOptions
292,282
void (boolean reformatAccordingToStyle) { myToReformatAccordingToStyle = reformatAccordingToStyle; }
setToReformatAccordingToStyle
292,283
boolean () { return myToUseStaticImport; }
isToUseStaticImport
292,284
void (boolean useStaticImport) { myToUseStaticImport = useStaticImport; }
setToUseStaticImport
292,285
Set<String> () { return TemplateImplUtil.parseVariableNames(replacement); }
getUsedVariableNames
292,286
void () { variableDefs.keySet().removeIf(key -> !getUsedVariableNames().contains(key)); }
removeUnusedVariables
292,287
void (Element element) { matchOptions.readExternal(element); Attribute attribute = element.getAttribute(REFORMAT_ATTR_NAME); try { myToReformatAccordingToStyle = attribute == null || attribute.getBooleanValue(); } catch(DataConversionException ignored) {} attribute = element.getAttribute(SHORTEN_FQN_ATTR_NAME); try { toShortenFQN = attribute == null || attribute.getBooleanValue(); } catch(DataConversionException ignored) {} attribute = element.getAttribute(USE_STATIC_IMPORT_ATTR_NAME); if (attribute != null) { // old saved configurations without this attribute present try { myToUseStaticImport = attribute.getBooleanValue(); } catch (DataConversionException ignore) {} } replacement = element.getAttributeValue(REPLACEMENT_ATTR_NAME); for (final Element child : element.getChildren(VARIABLE_DEFINITION_TAG_NAME)) { final ReplacementVariableDefinition variableDefinition = new ReplacementVariableDefinition(); variableDefinition.readExternal(child); addVariableDefinition(variableDefinition); } }
readExternal
292,288
void (Element element) { matchOptions.writeExternal(element); element.setAttribute(REFORMAT_ATTR_NAME,String.valueOf(myToReformatAccordingToStyle)); element.setAttribute(SHORTEN_FQN_ATTR_NAME,String.valueOf(toShortenFQN)); if (myToUseStaticImport) { element.setAttribute(USE_STATIC_IMPORT_ATTR_NAME, String.valueOf(true)); } element.setAttribute(REPLACEMENT_ATTR_NAME,replacement); final Set<String> nameSet = getUsedVariableNames(); for (final ReplacementVariableDefinition variableDefinition : variableDefs.values()) { if (!nameSet.contains(variableDefinition.getName())) { continue; } final Element infoElement = new Element(VARIABLE_DEFINITION_TAG_NAME); element.addContent(infoElement); variableDefinition.writeExternal(infoElement); } }
writeExternal
292,289
boolean (Object o) { if (this == o) return true; if (!(o instanceof ReplaceOptions replaceOptions)) return false; if (myToReformatAccordingToStyle != replaceOptions.myToReformatAccordingToStyle) return false; if (toShortenFQN != replaceOptions.toShortenFQN) return false; if (myToUseStaticImport != replaceOptions.myToUseStaticImport) return false; if (!matchOptions.equals(replaceOptions.matchOptions)) return false; if (!Objects.equals(replacement, replaceOptions.replacement)) return false; if (!variableDefs.equals(replaceOptions.variableDefs)) return false; return true; }
equals
292,290
int () { int result = replacement.hashCode(); result = 29 * result + (toShortenFQN ? 1 : 0); result = 29 * result + (myToReformatAccordingToStyle ? 1 : 0); result = 29 * result + (myToUseStaticImport ? 1 : 0); result = 29 * result + matchOptions.hashCode(); result = 29 * result + variableDefs.hashCode(); return result; }
hashCode
292,291
ReplacementVariableDefinition (@NotNull String name) { return variableDefs != null ? variableDefs.get(name): null; }
getVariableDefinition
292,292
void (@NotNull ReplacementVariableDefinition definition) { variableDefs.put(definition.getName(), definition); }
addVariableDefinition
292,293
ReplacementVariableDefinition (@NotNull String name) { final ReplacementVariableDefinition definition = new ReplacementVariableDefinition(name); variableDefs.put(name, definition); return definition; }
addNewVariableDefinition
292,294
Collection<ReplacementVariableDefinition> () { return variableDefs.values(); }
getVariableDefinitions
292,295
void () { variableDefs.clear(); }
clearVariableDefinitions
292,296
void (@NotNull Usage usage, @NotNull MatchResult result) { usage2ReplacementInfo.put(usage, replacer.buildReplacement(result)); }
addReplaceUsage
292,297
boolean (@NotNull UsageInfo2UsageAdapter info) { final PsiElement element = info.getUsageInfo().getElement(); return element != null && element.isValid(); }
isValid
292,298
void () { super.configureActions(); myUsageView.addButtonToLowerPane(() -> replace(myUsageView.getSortedUsages()), SSRBundle.message("do.replace.all.button")); myUsageView.addButtonToLowerPane(() -> replace(myUsageView.getSelectedUsages()), SSRBundle.message("replace.selected.button")); final Runnable previewReplacement = () -> { final Set<Usage> selection = myUsageView.getSelectedUsages(); if (selection.isEmpty()) { return; } for (Usage usage : selection) { final UsageInfo2UsageAdapter info = (UsageInfo2UsageAdapter)usage; if (!isValid(info) || myUsageView.getExcludedUsages().contains(usage)) { continue; } final ReplacementInfo replacementInfo = usage2ReplacementInfo.get(usage); final ReplacementPreviewDialog previewDialog = new ReplacementPreviewDialog(mySearchContext.getProject(), info.getUsageInfo(), replacementInfo.getReplacement()); if (!previewDialog.showAndGet()) { return; } replace(Collections.singleton(info)); } }; myUsageView.addButtonToLowerPane(previewReplacement, SSRBundle.message("preview.replacement.button")); }
configureActions
292,299
void (@NotNull Collection<? extends Usage> usages) { final Set<Usage> excluded = myUsageView.getExcludedUsages(); usages = usages.stream().filter(u -> !excluded.contains(u)).filter(u -> isValid((UsageInfo2UsageAdapter)u)).collect(Collectors.toList()); final List<VirtualFile> files = ContainerUtil.map(usages, i -> ((UsageInFile)i).getFile()); if (ReadonlyStatusHandler.getInstance(mySearchContext.getProject()).ensureFilesWritable(files).hasReadonlyFiles()) { return; } removeUsagesAndSelectNext(usages, excluded); final List<ReplacementInfo> replacementInfos = ContainerUtil.map(usages, usage2ReplacementInfo::get); final LocalHistoryAction action = LocalHistory.getInstance().startAction(SSRBundle.message("structural.replace.title")); try { CommandProcessor.getInstance().executeCommand( mySearchContext.getProject(), () -> replacer.replaceAll(replacementInfos), SSRBundle.message("structural.replace.title"), null); } finally { action.finish(); } }
replace