• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java TextOccurenceProcessor类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.intellij.psi.search.TextOccurenceProcessor的典型用法代码示例。如果您正苦于以下问题:Java TextOccurenceProcessor类的具体用法?Java TextOccurenceProcessor怎么用?Java TextOccurenceProcessor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



TextOccurenceProcessor类属于com.intellij.psi.search包,在下文中一共展示了TextOccurenceProcessor类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: processElementsAtOffsets

import com.intellij.psi.search.TextOccurenceProcessor; //导入依赖的package包/类
static boolean processElementsAtOffsets(@Nonnull PsiElement scope,
                                        @Nonnull StringSearcher searcher,
                                        boolean processInjectedPsi,
                                        @Nonnull ProgressIndicator progress,
                                        int[] offsetsInScope,
                                        @Nonnull TextOccurenceProcessor processor) {
  if (offsetsInScope.length == 0) return true;

  Project project = scope.getProject();
  TreeElement lastElement = null;
  for (int offset : offsetsInScope) {
    progress.checkCanceled();
    lastElement = processTreeUp(project, processor, scope, searcher, offset, processInjectedPsi, progress, lastElement);
    if (lastElement == null) return false;
  }
  return true;
}
 
开发者ID:consulo,项目名称:consulo,代码行数:18,代码来源:LowLevelSearchUtil.java


示例2: processInjectedFile

import com.intellij.psi.search.TextOccurenceProcessor; //导入依赖的package包/类
private static Boolean processInjectedFile(PsiElement element,
                                           final TextOccurenceProcessor processor,
                                           final StringSearcher searcher,
                                           ProgressIndicator progress,
                                           InjectedLanguageManager injectedLanguageManager) {
  if (!(element instanceof PsiLanguageInjectionHost)) return null;
  if (injectedLanguageManager == null) return null;
  List<Pair<PsiElement,TextRange>> list = injectedLanguageManager.getInjectedPsiFiles(element);
  if (list == null) return null;
  for (Pair<PsiElement, TextRange> pair : list) {
    final PsiElement injected = pair.getFirst();
    if (!processElementsContainingWordInElement(processor, injected, searcher, false, progress)) return Boolean.FALSE;
  }
  return Boolean.TRUE;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:16,代码来源:LowLevelSearchUtil.java


示例3: processElementsContainingWordInElement

import com.intellij.psi.search.TextOccurenceProcessor; //导入依赖的package包/类
public static boolean processElementsContainingWordInElement(@NotNull final TextOccurenceProcessor processor,
                                                             @NotNull final PsiElement scope,
                                                             @NotNull final StringSearcher searcher,
                                                             final boolean processInjectedPsi,
                                                             final ProgressIndicator progress) {
  if (progress != null) progress.checkCanceled();

  PsiFile file = scope.getContainingFile();
  FileViewProvider viewProvider = file.getViewProvider();
  final CharSequence buffer = viewProvider.getContents();

  TextRange range = scope.getTextRange();
  if (range == null) {
    LOG.error("Element " + scope + " of class " + scope.getClass() + " has null range");
    return true;
  }

  final int scopeStart = range.getStartOffset();
  final int startOffset = scopeStart;
  int endOffset = range.getEndOffset();
  if (endOffset > buffer.length()) {
    diagnoseInvalidRange(scope, file, viewProvider, buffer, range);
    return true;
  }

  final Project project = file.getProject();
  final TreeElement[] lastElement = {null};
  return processTextOccurrences(buffer, startOffset, endOffset, searcher, progress, new TIntProcedure() {
    @Override
    public boolean execute(int offset) {
      if (progress != null) progress.checkCanceled();
      lastElement[0] = processTreeUp(project, processor, scope, searcher, offset - scopeStart, processInjectedPsi, progress,
                                     lastElement[0]);
      return lastElement[0] != null;
    }
  });
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:38,代码来源:LowLevelSearchUtil.java


示例4: calcDevPatternClassNames

import com.intellij.psi.search.TextOccurenceProcessor; //导入依赖的package包/类
private static Set<String> calcDevPatternClassNames(@NotNull final Project project) {
  final List<String> roots = ContainerUtil.createLockFreeCopyOnWriteList();
  JavaPsiFacade psiFacade = JavaPsiFacade.getInstance(project);
  PsiClass beanClass = psiFacade.findClass(PatternClassBean.class.getName(), GlobalSearchScope.allScope(project));
  if (beanClass != null) {
    GlobalSearchScope scope = GlobalSearchScope.getScopeRestrictedByFileTypes(GlobalSearchScope.allScope(project), StdFileTypes.XML);
    final TextOccurenceProcessor occurenceProcessor = new TextOccurenceProcessor() {
      @Override
      public boolean execute(@NotNull PsiElement element, int offsetInElement) {
        XmlTag tag = PsiTreeUtil.getParentOfType(element, XmlTag.class);
        String className = tag == null ? null : tag.getAttributeValue("className");
        if (StringUtil.isNotEmpty(className) && tag.getLocalName().endsWith("patternClass")) {
          roots.add(className);
        }
        return true;
      }
    };
    final StringSearcher searcher = new StringSearcher("patternClass", true, true);
    CacheManager.SERVICE.getInstance(beanClass.getProject()).processFilesWithWord(new Processor<PsiFile>() {
      @Override
      public boolean process(PsiFile psiFile) {
        LowLevelSearchUtil.processElementsContainingWordInElement(occurenceProcessor, psiFile, searcher, true,
                                                                   new EmptyProgressIndicator());
        return true;
      }
    }, searcher.getPattern(), UsageSearchContext.IN_FOREIGN_LANGUAGES, scope, searcher.isCaseSensitive());
  }
  return ContainerUtil.newHashSet(roots);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:30,代码来源:PatternEditorContextMembersProvider.java


示例5: processElementsContainingWordInElement

import com.intellij.psi.search.TextOccurenceProcessor; //导入依赖的package包/类
public static boolean processElementsContainingWordInElement(@NotNull TextOccurenceProcessor processor,
                                                             @NotNull final PsiElement scope,
                                                             @NotNull StringSearcher searcher,
                                                             final boolean processInjectedPsi,
                                                             ProgressIndicator progress) {
  if (progress != null) progress.checkCanceled();

  PsiFile file = scope.getContainingFile();
  final CharSequence buffer = file.getViewProvider().getContents();

  TextRange range = scope.getTextRange();
  if (range == null) {
    throw new AssertionError("Element " + scope + " of class " + scope.getClass() + " has null range");
  }

  int scopeStart = range.getStartOffset();
  int startOffset = scopeStart;
  int endOffset = range.getEndOffset();
  if (endOffset > buffer.length()) {
    LOG.error("Range for element: '"+scope+"' = "+range+" is out of file '" + file + "' range: " + file.getTextLength());
  }

  final char[] bufferArray = CharArrayUtil.fromSequenceWithoutCopying(buffer);

  Project project = file.getProject();
  do {
    if (progress != null) progress.checkCanceled();
    startOffset  = searchWord(buffer, bufferArray, startOffset, endOffset, searcher, progress);
    if (startOffset < 0) {
      return true;
    }
    if (!processTreeUp(project, processor, scope, searcher, startOffset - scopeStart, processInjectedPsi, progress)) return false;

    startOffset++;
  }
  while (startOffset < endOffset);

  return true;
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:40,代码来源:LowLevelSearchUtil.java


示例6: getRootsByClassNames

import com.intellij.psi.search.TextOccurenceProcessor; //导入依赖的package包/类
private static List<PsiElement> getRootsByClassNames(PsiFile file, String type) {
  final List<PsiElement> roots = ContainerUtil.createLockFreeCopyOnWriteList();

  final Project project = file.getProject();
  final JavaPsiFacade psiFacade = JavaPsiFacade.getInstance(project);
  final PsiClass beanClass = psiFacade.findClass(PatternClassBean.class.getName(), GlobalSearchScope.allScope(project));
  if (beanClass != null) {
    final GlobalSearchScope scope =
      GlobalSearchScope.getScopeRestrictedByFileTypes(GlobalSearchScope.allScope(project), StdFileTypes.XML);
    final TextOccurenceProcessor occurenceProcessor = new TextOccurenceProcessor() {
      @Override
      public boolean execute(PsiElement element, int offsetInElement) {
        final XmlTag tag = PsiTreeUtil.getParentOfType(element, XmlTag.class);
        final String className = tag == null ? null : tag.getAttributeValue("className");
        if (className != null && tag.getLocalName().endsWith("patternClass")) {
          ContainerUtil.addIfNotNull(psiFacade.findClass(className, GlobalSearchScope.allScope(project)), roots);
        }
        return true;
      }
    };
    final StringSearcher searcher = new StringSearcher("patternClass", true, true);
    CacheManager.SERVICE.getInstance(beanClass.getProject()).processFilesWithWord(new Processor<PsiFile>() {
      @Override
      public boolean process(PsiFile psiFile) {
        LowLevelSearchUtil
          .processElementsContainingWordInElement(occurenceProcessor, psiFile, searcher, true, new EmptyProgressIndicator());
        return true;
      }
    }, searcher.getPattern(), UsageSearchContext.IN_FOREIGN_LANGUAGES, scope, searcher.isCaseSensitive());
  }
  final Class[] classes = PatternCompilerFactory.getFactory().getPatternClasses(type);
  if (classes.length != 0) {
    roots.add(getRootByClasses(classes, project));
  }
  return roots;
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:37,代码来源:PatternEditorContextMembersProvider.java


示例7: processInjectedFile

import com.intellij.psi.search.TextOccurenceProcessor; //导入依赖的package包/类
private static Boolean processInjectedFile(PsiElement element,
                                           final TextOccurenceProcessor processor,
                                           final StringSearcher searcher,
                                           @Nonnull ProgressIndicator progress,
                                           InjectedLanguageManager injectedLanguageManager) {
  if (!(element instanceof PsiLanguageInjectionHost)) return null;
  if (injectedLanguageManager == null) return null;
  List<Pair<PsiElement, TextRange>> list = injectedLanguageManager.getInjectedPsiFiles(element);
  if (list == null) return null;
  for (Pair<PsiElement, TextRange> pair : list) {
    final PsiElement injected = pair.getFirst();
    if (!processElementsContainingWordInElement(processor, injected, searcher, false, progress)) return Boolean.FALSE;
  }
  return Boolean.TRUE;
}
 
开发者ID:consulo,项目名称:consulo,代码行数:16,代码来源:LowLevelSearchUtil.java


示例8: processElementsContainingWordInElement

import com.intellij.psi.search.TextOccurenceProcessor; //导入依赖的package包/类
@RequiredReadAction
public static boolean processElementsContainingWordInElement(@Nonnull final TextOccurenceProcessor processor,
                                                             @Nonnull final PsiElement scope,
                                                             @Nonnull final StringSearcher searcher,
                                                             boolean processInjectedPsi,
                                                             @Nonnull ProgressIndicator progress) {
  int[] occurrences = getTextOccurrencesInScope(scope, searcher, progress);
  return processElementsAtOffsets(scope, searcher, processInjectedPsi, progress, occurrences, processor);
}
 
开发者ID:consulo,项目名称:consulo,代码行数:10,代码来源:LowLevelSearchUtil.java


示例9: processIdentifiers

import com.intellij.psi.search.TextOccurenceProcessor; //导入依赖的package包/类
private static boolean processIdentifiers(PsiSearchHelper helper,
                                          @NotNull final PsiElementProcessor<PsiIdentifier> processor,
                                          @NotNull final String identifier,
                                          @NotNull SearchScope searchScope,
                                          short searchContext) {
  TextOccurenceProcessor processor1 = new TextOccurenceProcessor() {
    public boolean execute(PsiElement element, int offsetInElement) {
      return !(element instanceof PsiIdentifier) || processor.execute((PsiIdentifier)element);
    }
  };
  return helper.processElementsWithWord(processor1, searchScope, identifier, searchContext, true);
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:13,代码来源:ChangedConstantsDependencyProcessor.java


示例10: processTreeUp

import com.intellij.psi.search.TextOccurenceProcessor; //导入依赖的package包/类
private static boolean processTreeUp(@NotNull Project project,
                                     @NotNull TextOccurenceProcessor processor,
                                     @NotNull PsiElement scope,
                                     @NotNull StringSearcher searcher,
                                     final int offset,
                                     final boolean processInjectedPsi,
                                     ProgressIndicator progress) {
  final int scopeStartOffset = scope.getTextRange().getStartOffset();
  final int patternLength = searcher.getPatternLength();
  ASTNode scopeNode = scope.getNode();
  boolean useTree = scopeNode != null;
  assert scope.isValid();

  int start;
  TreeElement leafNode = null;
  PsiElement leafElement = null;
  if (useTree) {
    leafNode = (LeafElement)scopeNode.findLeafElementAt(offset);
    if (leafNode == null) return true;
    start = offset - leafNode.getStartOffset() + scopeStartOffset;
  }
  else {
    if (scope instanceof PsiFile) {
      leafElement = ((PsiFile)scope).getViewProvider().findElementAt(offset, scope.getLanguage());
    }
    else {
      leafElement = scope.findElementAt(offset);
    }
    if (leafElement == null) return true;
    assert leafElement.isValid();
    start = offset - leafElement.getTextRange().getStartOffset() + scopeStartOffset;
  }
  if (start < 0) {
    LOG.error("offset=" + offset + " scopeStartOffset=" + scopeStartOffset + " leafElement=" + leafElement + "  scope=" + scope);
  }
  boolean contains = false;
  PsiElement prev = null;
  TreeElement prevNode = null;
  PsiElement run = null;
  InjectedLanguageManager injectedLanguageManager = InjectedLanguageManager.getInstance(project);
  while (run != scope) {
    if (progress != null) progress.checkCanceled();
    if (useTree) {
      start += prevNode == null ? 0 : prevNode.getStartOffsetInParent();
      prevNode = leafNode;
      run = leafNode.getPsi();
    }
    else {
      start += prev == null ? 0 : prev.getStartOffsetInParent();
      prev = run;
      run = leafElement;
    }
    if (!contains) contains = run.getTextLength() - start >= patternLength;  //do not compute if already contains
    if (contains) {
      if (processInjectedPsi) {
        Boolean result = processInjectedFile(run, processor, searcher, progress, injectedLanguageManager);
        if (result != null) {
          return result.booleanValue();
        }
      }
      if (!processor.execute(run, start)) {
        return false;
      }
    }
    if (useTree) {
      leafNode = leafNode.getTreeParent();
      if (leafNode == null) break;
    }
    else {
      leafElement = leafElement.getParent();
      if (leafElement == null) break;
    }
  }
  assert run == scope: "Malbuilt PSI: scopeNode="+scope+"; leafNode="+run+"; isAncestor="+ PsiTreeUtil.isAncestor(scope, run, false);

  return true;
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:78,代码来源:LowLevelSearchUtil.java


示例11: execute

import com.intellij.psi.search.TextOccurenceProcessor; //导入依赖的package包/类
@Override
public boolean execute(@NotNull final MethodReferencesSearch.SearchParameters parameters, @NotNull final Processor<PsiReference> consumer)
{
	final PsiMethod method = parameters.getMethod();
	final Ref<String> name = Ref.create(null);
	final Ref<Project> project = Ref.create(null);
	ApplicationManager.getApplication().runReadAction(new Runnable()
	{
		@Override
		public void run()
		{
			if(!method.isValid())
			{
				return;
			}
			project.set(method.getProject());
			name.set(VelocityNamingUtil.getPropertyNameFromAccessor(method));
		}
	});
	String nameRefValue = name.get();
	if(StringUtil.isEmpty(nameRefValue))
	{
		return true;
	}
	SearchScope searchScope = parameters.getScope();
	if(searchScope instanceof GlobalSearchScope)
	{
		searchScope = GlobalSearchScope.getScopeRestrictedByFileTypes((GlobalSearchScope) searchScope, VtlFileType.INSTANCE);
	}

	final TextOccurenceProcessor processor = new TextOccurenceProcessor()
	{
		@Override
		public boolean execute(PsiElement element, int offsetInElement)
		{
			final PsiReference[] refs = element.getReferences();
			for(PsiReference ref : refs)
			{
				if(ref.getRangeInElement().contains(offsetInElement) && ref.isReferenceTo(method))
				{
					return consumer.process(ref);
				}
			}
			return true;
		}
	};
	final PsiSearchHelper helper = PsiSearchHelper.SERVICE.getInstance(project.get());
	return helper.processElementsWithWord(processor, searchScope, nameRefValue, UsageSearchContext.IN_FOREIGN_LANGUAGES, false);
}
 
开发者ID:consulo,项目名称:consulo-apache-velocity,代码行数:50,代码来源:VelocityStylePropertySearcher.java



注:本文中的com.intellij.psi.search.TextOccurenceProcessor类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Timed类代码示例发布时间:2022-05-23
下一篇:
Java XMLDTDSource类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap