com.intellij.psi.search.UsageSearchContext Java Examples
The following examples show how to use
com.intellij.psi.search.UsageSearchContext.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PlainTextIndexer.java From consulo with Apache License 2.0 | 6 votes |
@Override @Nonnull public Map<IdIndexEntry, Integer> map(@Nonnull final FileContent inputData) { final IdDataConsumer consumer = new IdDataConsumer(); final CharSequence chars = inputData.getContentAsText(); IdTableBuilding.scanWords(new IdTableBuilding.ScanWordProcessor() { @Override public void run(final CharSequence chars11, @Nullable char[] charsArray, final int start, final int end) { if (charsArray != null) { consumer.addOccurrence(charsArray, start, end, (int)UsageSearchContext.IN_PLAIN_TEXT); } else { consumer.addOccurrence(chars11, start, end, (int)UsageSearchContext.IN_PLAIN_TEXT); } } }, chars, 0, chars.length()); return consumer.getResult(); }
Example #2
Source File: GlobalWordIndexTest.java From intellij with Apache License 2.0 | 6 votes |
@Test public void testWordsInStrings() { VirtualFile file = workspace.createFile( new WorkspacePath("java/com/google/BUILD"), "name = \"long name with spaces\",", "src = [\"name_without_spaces\"]"); assertContainsWords( file, UsageSearchContext.IN_STRINGS, "long", "name", "with", "spaces", "name_without_spaces"); }
Example #3
Source File: GlobalWordIndexTest.java From intellij with Apache License 2.0 | 6 votes |
private void assertContainsWords( VirtualFile file, @MagicConstant(flagsFromClass = UsageSearchContext.class) short occurenceMask, String... words) { for (String word : words) { VirtualFile[] files = CacheManager.SERVICE .getInstance(getProject()) .getVirtualFilesWithWord( word, occurenceMask, GlobalSearchScope.fileScope(getProject(), file), true); if (!Arrays.asList(files).contains(file)) { Assert.fail(String.format("Word '%s' not found in file '%s'", word, file)); } } }
Example #4
Source File: BashFilterLexer.java From BashSupport with Apache License 2.0 | 6 votes |
@Override public void advance() { IElementType tokenType = myDelegate.getTokenType(); if (tokenType == BashTokenTypes.COMMENT) { scanWordsInToken(UsageSearchContext.IN_COMMENTS, false, false); advanceTodoItemCountsInToken(); } else if (tokenType == BashTokenTypes.STRING2) { addOccurrenceInToken(UsageSearchContext.IN_CODE | UsageSearchContext.IN_STRINGS | UsageSearchContext.IN_FOREIGN_LANGUAGES); scanWordsInToken(UsageSearchContext.IN_CODE | UsageSearchContext.IN_STRINGS, true, true); } else { addOccurrenceInToken(UsageSearchContext.IN_CODE | UsageSearchContext.IN_STRINGS); scanWordsInToken(UsageSearchContext.IN_CODE | UsageSearchContext.IN_STRINGS, true, false); } myDelegate.advance(); }
Example #5
Source File: BuildReferenceSearcher.java From intellij with Apache License 2.0 | 5 votes |
private static void searchForString( SearchParameters params, SearchScope scope, PsiElement element, String string) { if (scope instanceof GlobalSearchScope) { scope = GlobalSearchScope.getScopeRestrictedByFileTypes( (GlobalSearchScope) scope, BuildFileType.INSTANCE); } params.getOptimizer().searchWord(string, scope, UsageSearchContext.IN_STRINGS, true, element); }
Example #6
Source File: IdTableBuilding.java From consulo with Apache License 2.0 | 5 votes |
@Override @Nonnull public Map<IdIndexEntry, Integer> map(final FileContent inputData) { final CharSequence chars = inputData.getContentAsText(); final char[] charsArray = CharArrayUtil.fromSequenceWithoutCopying(chars); final IdDataConsumer consumer = new IdDataConsumer(); myScanner.processWords(chars, new Processor<WordOccurrence>() { @Override public boolean process(final WordOccurrence t) { if (charsArray != null && t.getBaseText() == chars) { consumer.addOccurrence(charsArray, t.getStart(), t.getEnd(), convertToMask(t.getKind())); } else { consumer.addOccurrence(t.getBaseText(), t.getStart(), t.getEnd(), convertToMask(t.getKind())); } return true; } private int convertToMask(final WordOccurrence.Kind kind) { if (kind == null) return UsageSearchContext.ANY; if (kind == WordOccurrence.Kind.CODE) return UsageSearchContext.IN_CODE; if (kind == WordOccurrence.Kind.COMMENTS) return UsageSearchContext.IN_COMMENTS; if (kind == WordOccurrence.Kind.LITERALS) return UsageSearchContext.IN_STRINGS; if (kind == WordOccurrence.Kind.FOREIGN_LANGUAGE) return UsageSearchContext.IN_FOREIGN_LANGUAGES; return 0; } }); return consumer.getResult(); }
Example #7
Source File: BaseFilterLexer.java From consulo with Apache License 2.0 | 5 votes |
private void processPossibleComplexFileName(CharSequence chars, char[] cachedArraySequence, int startOffset, int endOffset) { int offset = findCharsWithinRange(chars, startOffset, endOffset, "/\\"); offset = Math.min(offset, endOffset); int start = startOffset; while(start < endOffset) { if (start != offset) { myOccurrenceConsumer.addOccurrence(chars, cachedArraySequence, start, offset, UsageSearchContext.IN_FOREIGN_LANGUAGES); } start = offset + 1; offset = Math.min(endOffset, findCharsWithinRange(chars, start, endOffset, "/\\")); } }
Example #8
Source File: CodeInsightTestFixtureImpl.java From consulo with Apache License 2.0 | 5 votes |
private long collectAndCheckHighlighting(@Nonnull ExpectedHighlightingData data) { final Project project = getProject(); PsiDocumentManager.getInstance(project).commitAllDocuments(); PsiFileImpl file = (PsiFileImpl)getHostFile(); FileElement hardRefToFileElement = file.calcTreeElement();//to load text //to initialize caches if (!DumbService.isDumb(project)) { CacheManager.getInstance(project).getFilesWithWord(XXX, UsageSearchContext.IN_COMMENTS, GlobalSearchScope.allScope(project), true); } List<HighlightInfo> infos; final long start = System.currentTimeMillis(); try { ((PsiManagerImpl)PsiManager.getInstance(project)).setAssertOnFileLoadingFilter(myJavaFilesFilter, myTestRootDisposable); // ProfilingUtil.startCPUProfiling(); infos = doHighlighting(); removeDuplicatedRangesForInjected(infos); // ProfilingUtil.captureCPUSnapshot("testing"); } finally { ((PsiManagerImpl)PsiManager.getInstance(project)).setAssertOnFileLoadingFilter(VirtualFileFilter.NONE, myTestRootDisposable); } final long elapsed = System.currentTimeMillis() - start; data.checkResult(infos, file.getText()); hardRefToFileElement.hashCode(); // use it so gc won't collect it return elapsed; }
Example #9
Source File: LombokReferenceSearcher.java From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License | 5 votes |
private void processClassFields(PsiField refPsiField, SearchRequestCollector collector, PsiClass containingClass) { Arrays.stream(containingClass.getFields()) .filter(LombokLightFieldBuilder.class::isInstance) .filter(psiField -> psiField.getNavigationElement() == refPsiField) .filter(psiField -> Objects.nonNull(psiField.getName())) .forEach(psiField -> { collector.searchWord(psiField.getName(), psiField.getUseScope(), UsageSearchContext.IN_CODE, true, psiField); }); }
Example #10
Source File: LombokReferenceSearcher.java From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License | 5 votes |
private void processClassMethods(PsiField refPsiField, SearchRequestCollector collector, PsiClass containingClass) { Arrays.stream(containingClass.getMethods()) .filter(LombokLightMethodBuilder.class::isInstance) .filter(psiMethod -> psiMethod.getNavigationElement() == refPsiField) .forEach(psiMethod -> { collector.searchWord(psiMethod.getName(), psiMethod.getUseScope(), UsageSearchContext.IN_CODE, true, psiMethod); }); }
Example #11
Source File: CSharpIdFilterLexer.java From consulo-csharp with Apache License 2.0 | 5 votes |
@Override public void advance() { final IElementType tokenType = myDelegate.getTokenType(); if(tokenType == CSharpTokens.IDENTIFIER) { addOccurrenceInToken(UsageSearchContext.IN_CODE); CharSequence tokenSequence = myDelegate.getTokenSequence(); if(tokenSequence.charAt(0) == '@') { scanWordsInToken(UsageSearchContext.IN_CODE, false, false); } } else if(tokenType == CSharpTokens.LONG_LITERAL || tokenType == CSharpTokens.INTEGER_LITERAL || tokenType == CSharpTokens.CHARACTER_LITERAL || tokenType == CSharpTokens.ARROW || tokenType == CSharpTokens.DARROW) { addOccurrenceInToken(UsageSearchContext.IN_CODE); } else if(CSharpTokenSets.STRINGS.contains(tokenType)) { scanWordsInToken(UsageSearchContext.IN_STRINGS | UsageSearchContext.IN_FOREIGN_LANGUAGES, false, true); } else if(CSharpTokenSets.COMMENTS.contains(tokenType)) { scanWordsInToken(UsageSearchContext.IN_COMMENTS, false, false); advanceTodoItemCountsInToken(); } else if(!ourSkipWordsScanSet.contains(tokenType)) { scanWordsInToken(UsageSearchContext.IN_PLAIN_TEXT, false, false); } myDelegate.advance(); }
Example #12
Source File: JSGraphQLEndpointTodoIndexer.java From js-graphql-intellij-plugin with MIT License | 5 votes |
@Override public void advance() { final IElementType tokenType = this.myDelegate.getTokenType(); if (tokenType == JSGraphQLEndpointTokenTypes.LINE_COMMENT) { this.scanWordsInToken(UsageSearchContext.IN_COMMENTS, false, false); this.advanceTodoItemCountsInToken(); } this.myDelegate.advance(); }
Example #13
Source File: GlobalWordIndexTest.java From intellij with Apache License 2.0 | 5 votes |
@Test public void testWordsInCode() { VirtualFile file = workspace.createFile( new WorkspacePath("java/com/google/BUILD"), "java_library(", "name = \"long name with spaces\",", "src = [\"name_without_spaces\"]", ")"); assertContainsWords(file, UsageSearchContext.IN_CODE, "java_library", "name", "src"); }
Example #14
Source File: DotEnvReferencesSearcher.java From idea-php-dotenv-plugin with MIT License | 5 votes |
private static void addPropertyUsages(@NotNull DotEnvProperty property, @NotNull SearchScope scope, @NotNull SearchRequestCollector collector) { final String propertyName = property.getName(); if (StringUtil.isNotEmpty(propertyName)) { /*SearchScope additional = GlobalSearchScope.EMPTY_SCOPE; for (CustomPropertyScopeProvider provider : CustomPropertyScopeProvider.EP_NAME.getExtensionList()) { additional = additional.union(provider.getScope(property.getProject())); } SearchScope propScope = scope.intersectWith(property.getUseScope()).intersectWith(additional);*/ collector.searchWord(propertyName, scope, UsageSearchContext.ANY, true, property); collector.searchWord("process.env." + propertyName, scope, UsageSearchContext.ANY, true, property); } }
Example #15
Source File: GlobalWordIndexTest.java From intellij with Apache License 2.0 | 4 votes |
@Test public void testWordsInComments() { VirtualFile file = workspace.createFile(new WorkspacePath("java/com/google/BUILD"), "# words in comments"); assertContainsWords(file, UsageSearchContext.IN_COMMENTS, "words", "in", "comments"); }
Example #16
Source File: IdIndex.java From consulo with Apache License 2.0 | 4 votes |
@Override public void save(@Nonnull final DataOutput out, final Integer value) throws IOException { out.write(value.intValue() & UsageSearchContext.ANY); }
Example #17
Source File: IdIndex.java From consulo with Apache License 2.0 | 4 votes |
@Override public Integer read(@Nonnull final DataInput in) throws IOException { return Integer.valueOf(in.readByte() & UsageSearchContext.ANY); }