当前位置: 首页>>代码示例>>Java>>正文


Java PsiShortNamesCache.getClassesByName方法代码示例

本文整理汇总了Java中com.intellij.psi.search.PsiShortNamesCache.getClassesByName方法的典型用法代码示例。如果您正苦于以下问题:Java PsiShortNamesCache.getClassesByName方法的具体用法?Java PsiShortNamesCache.getClassesByName怎么用?Java PsiShortNamesCache.getClassesByName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.intellij.psi.search.PsiShortNamesCache的用法示例。


在下文中一共展示了PsiShortNamesCache.getClassesByName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: findClassesForTest

import com.intellij.psi.search.PsiShortNamesCache; //导入方法依赖的package包/类
@NotNull
public Collection<PsiElement> findClassesForTest(@NotNull PsiElement element) {
  PsiClass klass = findSourceElement(element);
  if (klass == null) return Collections.emptySet();

  GlobalSearchScope scope = getSearchScope(element, true);

  PsiShortNamesCache cache = PsiShortNamesCache.getInstance(element.getProject());

  List<Pair<? extends PsiNamedElement, Integer>> classesWithWeights = new ArrayList<Pair<? extends PsiNamedElement, Integer>>();
  for (Pair<String, Integer> eachNameWithWeight : TestFinderHelper.collectPossibleClassNamesWithWeights(klass.getName())) {
    for (PsiClass eachClass : cache.getClassesByName(eachNameWithWeight.first, scope)) {
      if (isTestSubjectClass(eachClass)) {
        classesWithWeights.add(Pair.create(eachClass, eachNameWithWeight.second));
      }
    }
  }

  return TestFinderHelper.getSortedElements(classesWithWeights, false);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:JavaTestFinder.java

示例2: collectTests

import com.intellij.psi.search.PsiShortNamesCache; //导入方法依赖的package包/类
private boolean collectTests(PsiClass klass, Processor<Pair<? extends PsiNamedElement, Integer>> processor) {
  GlobalSearchScope scope = getSearchScope(klass, false);

  PsiShortNamesCache cache = PsiShortNamesCache.getInstance(klass.getProject());

  String klassName = klass.getName();
  Pattern pattern = Pattern.compile(".*" + StringUtil.escapeToRegexp(klassName) + ".*", Pattern.CASE_INSENSITIVE);

  HashSet<String> names = new HashSet<String>();
  cache.getAllClassNames(names);
  final TestFrameworks frameworks = TestFrameworks.getInstance();
  for (String eachName : names) {
    if (pattern.matcher(eachName).matches()) {
      for (PsiClass eachClass : cache.getClassesByName(eachName, scope)) {
        if (eachClass.isPhysical() && (frameworks.isTestClass(eachClass) || frameworks.isPotentialTestClass(eachClass))) {
          if (!processor.process(Pair.create(eachClass, TestFinderHelper.calcTestNameProximity(klassName, eachName)))) {
            return true;
          }
        }
      }
    }
  }
  return false;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:25,代码来源:JavaTestFinder.java

示例3: appendTestClass

import com.intellij.psi.search.PsiShortNamesCache; //导入方法依赖的package包/类
private void appendTestClass(PsiClass aClass, String testSuffix, final GlobalSearchScope moduleScope) {
  PsiShortNamesCache cache = PsiShortNamesCache.getInstance(aClass.getProject());

  String klassName = aClass.getName();
  Pattern pattern = Pattern.compile(".*" + klassName + ".*" + testSuffix);

  HashSet<String> names = new HashSet<String>();
  cache.getAllClassNames(names);
  for (String eachName : names) {
    if (pattern.matcher(eachName).matches()) {
      for (PsiClass eachClass : cache.getClassesByName(eachName, moduleScope)) {
        if (TestFrameworks.getInstance().isTestClass(eachClass)) {
          myElements.add(eachClass);
        }
      }
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:AutomaticTestRenamerFactory.java

示例4: getItemsByName

import com.intellij.psi.search.PsiShortNamesCache; //导入方法依赖的package包/类
@Override
@NotNull
public NavigationItem[] getItemsByName(String name, final String pattern, Project project, boolean includeNonProjectItems) {
  GlobalSearchScope scope = includeNonProjectItems ? GlobalSearchScope.allScope(project) : GlobalSearchScope.projectScope(project);
  PsiShortNamesCache cache = PsiShortNamesCache.getInstance(project);

  List<PsiMember> result = new ArrayList<PsiMember>();
  for (PsiMethod method : cache.getMethodsByName(name, scope)) {
    if (!method.isConstructor() && isOpenable(method) && !hasSuperMethod(method)) {
      result.add(method);
    }
  }
  for (PsiField field : cache.getFieldsByName(name, scope)) {
    if (isOpenable(field)) {
      result.add(field);
    }
  }
  for (PsiClass aClass : cache.getClassesByName(name, scope)) {
    if (isOpenable(aClass)) {
      result.add(aClass);
    }
  }
  PsiMember[] array = result.toArray(new PsiMember[result.size()]);
  Arrays.sort(array, MyComparator.INSTANCE);
  return array;
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:27,代码来源:DefaultSymbolNavigationContributor.java

示例5: getClassesByName

import com.intellij.psi.search.PsiShortNamesCache; //导入方法依赖的package包/类
@Override
@NotNull
public PsiClass[] getClassesByName(@NotNull String name, @NotNull GlobalSearchScope scope)
{
	Merger<PsiClass> merger = null;
	for(PsiShortNamesCache cache : myCaches)
	{
		PsiClass[] classes = cache.getClassesByName(name, scope);
		if(classes.length != 0)
		{
			if(merger == null)
			{
				merger = new Merger<PsiClass>();
			}
			merger.add(classes);
		}
	}
	PsiClass[] result = merger == null ? null : merger.getResult();
	return result != null ? result : PsiClass.EMPTY_ARRAY;
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:21,代码来源:CompositeShortNamesCache.java

示例6: getClassesByName

import com.intellij.psi.search.PsiShortNamesCache; //导入方法依赖的package包/类
@Override
@NotNull
public PsiClass[] getClassesByName(@NotNull String name, @NotNull GlobalSearchScope scope) {
  Merger<PsiClass> merger = null;
  for (PsiShortNamesCache cache : myCaches) {
    PsiClass[] classes = cache.getClassesByName(name, scope);
    if (classes.length != 0) {
      if (merger == null) merger = new Merger<PsiClass>();
      merger.add(classes);
    }
  }
  PsiClass[] result = merger == null ? null : merger.getResult();
  return result != null ? result : PsiClass.EMPTY_ARRAY;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:15,代码来源:CompositeShortNamesCache.java

示例7: registerVariableParameterizedTypeFixes

import com.intellij.psi.search.PsiShortNamesCache; //导入方法依赖的package包/类
private static void registerVariableParameterizedTypeFixes(HighlightInfo highlightInfo,
                                                           @NotNull PsiVariable variable,
                                                           @NotNull PsiReferenceParameterList parameterList,
                                                           @NotNull JavaSdkVersion version) {
  PsiType type = variable.getType();
  if (!(type instanceof PsiClassType)) return;

  if (DumbService.getInstance(variable.getProject()).isDumb()) return;

  String shortName = ((PsiClassType)type).getClassName();
  PsiManager manager = parameterList.getManager();
  final JavaPsiFacade facade = JavaPsiFacade.getInstance(manager.getProject());
  PsiShortNamesCache shortNamesCache = PsiShortNamesCache.getInstance(parameterList.getProject());
  PsiClass[] classes = shortNamesCache.getClassesByName(shortName, GlobalSearchScope.allScope(manager.getProject()));
  PsiElementFactory factory = facade.getElementFactory();
  for (PsiClass aClass : classes) {
    if (checkReferenceTypeArgumentList(aClass, parameterList, PsiSubstitutor.EMPTY, false, version) == null) {
      PsiType[] actualTypeParameters = parameterList.getTypeArguments();
      PsiTypeParameter[] classTypeParameters = aClass.getTypeParameters();
      Map<PsiTypeParameter, PsiType> map = new java.util.HashMap<PsiTypeParameter, PsiType>();
      for (int j = 0; j < classTypeParameters.length; j++) {
        PsiTypeParameter classTypeParameter = classTypeParameters[j];
        PsiType actualTypeParameter = actualTypeParameters[j];
        map.put(classTypeParameter, actualTypeParameter);
      }
      PsiSubstitutor substitutor = factory.createSubstitutor(map);
      PsiType suggestedType = factory.createType(aClass, substitutor);
      HighlightUtil.registerChangeVariableTypeFixes(variable, suggestedType, variable.getInitializer(), highlightInfo);
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:32,代码来源:GenericsHighlightUtil.java

示例8: getItemsByName

import com.intellij.psi.search.PsiShortNamesCache; //导入方法依赖的package包/类
@Override
@NotNull
public NavigationItem[] getItemsByName(String name, final String pattern, Project project, boolean includeNonProjectItems) {
  GlobalSearchScope scope = includeNonProjectItems ? GlobalSearchScope.allScope(project) : GlobalSearchScope.projectScope(project);
  PsiShortNamesCache cache = PsiShortNamesCache.getInstance(project);

  Condition<PsiMember> qualifiedMatcher = getQualifiedNameMatcher(pattern);

  List<PsiMember> result = new ArrayList<PsiMember>();
  for (PsiMethod method : cache.getMethodsByName(name, scope)) {
    if (!method.isConstructor() && isOpenable(method) && !hasSuperMethod(method, scope, qualifiedMatcher)) {
      result.add(method);
    }
  }
  for (PsiField field : cache.getFieldsByName(name, scope)) {
    if (isOpenable(field)) {
      result.add(field);
    }
  }
  for (PsiClass aClass : cache.getClassesByName(name, scope)) {
    if (isOpenable(aClass)) {
      result.add(aClass);
    }
  }
  PsiMember[] array = result.toArray(new PsiMember[result.size()]);
  Arrays.sort(array, MyComparator.INSTANCE);
  return array;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:29,代码来源:DefaultSymbolNavigationContributor.java

示例9: getClassesByName

import com.intellij.psi.search.PsiShortNamesCache; //导入方法依赖的package包/类
@NotNull
protected List<PsiClass> getClassesByName(final String name,
                                          final boolean checkBoxState,
                                          final String pattern,
                                          final GlobalSearchScope searchScope) {
  final PsiShortNamesCache cache = PsiShortNamesCache.getInstance(getProject());
  PsiClass[] classes =
    cache.getClassesByName(name, checkBoxState ? searchScope : GlobalSearchScope.projectScope(getProject()).intersectWith(searchScope));
  return ContainerUtil.newArrayList(classes);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:11,代码来源:TreeJavaClassChooserDialog.java

示例10: addImportCandidates

import com.intellij.psi.search.PsiShortNamesCache; //导入方法依赖的package包/类
@Override
public void addImportCandidates(PsiReference reference, String name, AutoImportQuickFix quickFix) {
  final PsiElement element = reference.getElement();
  final Project project = element.getProject();
  Module module = ModuleUtil.findModuleForPsiElement(element);
  GlobalSearchScope scope = module == null ? ProjectScope.getAllScope(project) : module.getModuleWithDependenciesAndLibrariesScope(false);
  PsiShortNamesCache cache = PsiShortNamesCache.getInstance(project);
  final PsiClass[] classesByName = cache.getClassesByName(name, scope);
  for (PsiClass psiClass : classesByName) {
    final QualifiedName packageQName = QualifiedName.fromDottedString(psiClass.getQualifiedName()).removeLastComponent();
    quickFix.addImport(psiClass, psiClass.getContainingFile(), packageQName);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:14,代码来源:PyJavaImportCandidateProvider.java

示例11: getGlobalEnvItems

import com.intellij.psi.search.PsiShortNamesCache; //导入方法依赖的package包/类
private Map<PsiElement,Item> getGlobalEnvItems() {
  if (global_envitems_ready) {
    return global_envitems;
  } else {

    synchronized (global_envitems_lock) {

      if (global_envitems == null) {
        // get all classes from IntelliJ
        global_envitems = new HashMap<PsiElement, Item>();
      }

      logger.info("making global_envitems (" + global_envitems.size() + " items already there)");

      PsiShortNamesCache cache = PsiShortNamesCache.getInstance(project);
      String[] classnames = cache.getAllClassNames();
      GlobalSearchScope scope = new ProjectAndLibrariesScope(project, true);

      // Add all classes.  TODO: This includes local classes, but probably shouldn't
      Map<PsiElement,Item> fake_globals = new HashMap<PsiElement,Item>();
      for (String name : classnames)
        for (PsiClass cls : cache.getClassesByName(name, scope))
          if (!isInaccessible(cls, true))
            addClass(fake_globals, global_envitems, cls, true, true);

      logger.info("making global_env with " + global_envitems.size() + " items.");

      // update global_env
      global_env = Tarski.environment(global_envitems.values());

      logger.info("global_env ready.");

      global_envitems_ready = true;

    }

    return global_envitems;
  }
}
 
开发者ID:eddysystems,项目名称:eddy,代码行数:40,代码来源:EnvironmentProcessorTest.java

示例12: registerIntentions

import com.intellij.psi.search.PsiShortNamesCache; //导入方法依赖的package包/类
public static void registerIntentions(HighlightInfo highlightInfo, PsiVariable variable, PsiReferenceParameterList parameterList) {
  PsiType type = variable.getType();
  if (!(type instanceof PsiClassType)) return;

  if (DumbService.getInstance(variable.getProject()).isDumb()) return;

  String shortName = ((PsiClassType)type).getClassName();
  PsiManager manager = parameterList.getManager();
  final JavaPsiFacade facade = JavaPsiFacade.getInstance(manager.getProject());
  PsiShortNamesCache shortNamesCache = PsiShortNamesCache.getInstance(parameterList.getProject());
  PsiClass[] classes = shortNamesCache.getClassesByName(shortName, GlobalSearchScope.allScope(manager.getProject()));
  PsiElementFactory factory = facade.getElementFactory();
  JavaSdkVersion version = JavaSdkVersionUtil.getJavaSdkVersion(parameterList);
  for (PsiClass aClass : classes) {
    if (GenericsHighlightUtil.checkReferenceTypeArgumentList(aClass, parameterList, PsiSubstitutor.EMPTY, false, version) == null) {
      PsiType[] actualTypeParameters = parameterList.getTypeArguments();
      PsiTypeParameter[] classTypeParameters = aClass.getTypeParameters();
      HashMap<PsiTypeParameter, PsiType> map = new HashMap<PsiTypeParameter, PsiType>();
      for (int j = 0; j < classTypeParameters.length; j++) {
        PsiTypeParameter classTypeParameter = classTypeParameters[j];
        PsiType actualTypeParameter = actualTypeParameters[j];
        map.put(classTypeParameter, actualTypeParameter);
      }
      PsiSubstitutor substitutor = factory.createSubstitutor(map);
      PsiType suggestedType = factory.createType(aClass, substitutor);
      HighlightUtil.registerChangeVariableTypeFixes(variable, suggestedType, highlightInfo);
    }
  }
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:30,代码来源:VariableParameterizedTypeFix.java

示例13: findClassesForTest

import com.intellij.psi.search.PsiShortNamesCache; //导入方法依赖的package包/类
@NotNull
public Collection<PsiElement> findClassesForTest(@NotNull PsiElement element) {
  PsiClass klass = findSourceElement(element);
  if (klass == null) return Collections.emptySet();

  GlobalSearchScope scope;
  Module module = getModule(element);
  if (module != null) {
    scope = GlobalSearchScope.moduleWithDependenciesScope(module);
  }
  else {
    scope = GlobalSearchScope.projectScope(element.getProject());
  }

  PsiShortNamesCache cache = PsiShortNamesCache.getInstance(element.getProject());

  List<Pair<? extends PsiNamedElement, Integer>> classesWithWeights = new ArrayList<Pair<? extends PsiNamedElement, Integer>>();
  for (Pair<String, Integer> eachNameWithWeight : TestFinderHelper.collectPossibleClassNamesWithWeights(klass.getName())) {
    for (PsiClass eachClass : cache.getClassesByName(eachNameWithWeight.first, scope)) {
      if (isTestSubjectClass(eachClass)) {
        classesWithWeights.add(new Pair<PsiClass, Integer>(eachClass, eachNameWithWeight.second));
      }
    }
  }

  return TestFinderHelper.getSortedElements(classesWithWeights, false);
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:28,代码来源:JavaTestFinder.java

示例14: findTestsForClass

import com.intellij.psi.search.PsiShortNamesCache; //导入方法依赖的package包/类
@NotNull
public Collection<PsiElement> findTestsForClass(@NotNull PsiElement element) {
  PsiClass klass = findSourceElement(element);
  if (klass == null) return Collections.emptySet();

  GlobalSearchScope scope;
  Module module = getModule(element);
  if (module != null) {
    scope = GlobalSearchScope.moduleWithDependentsScope(module);
  }
  else {
    scope = GlobalSearchScope.projectScope(element.getProject());
  }

  PsiShortNamesCache cache = PsiShortNamesCache.getInstance(element.getProject());

  String klassName = klass.getName();
  Pattern pattern = Pattern.compile(".*" + klassName + ".*");

  List<Pair<? extends PsiNamedElement, Integer>> classesWithProximities = new ArrayList<Pair<? extends PsiNamedElement, Integer>>();

  HashSet<String> names = new HashSet<String>();
  cache.getAllClassNames(names);
  for (String eachName : names) {
    if (pattern.matcher(eachName).matches()) {
      for (PsiClass eachClass : cache.getClassesByName(eachName, scope)) {
        if (TestFrameworks.getInstance().isTestClass(eachClass)) {
          classesWithProximities.add(
              new Pair<PsiClass, Integer>(eachClass, TestFinderHelper.calcTestNameProximity(klassName, eachName)));
        }
      }
    }
  }

  return TestFinderHelper.getSortedElements(classesWithProximities, true);
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:37,代码来源:JavaTestFinder.java

示例15: getItemsByName

import com.intellij.psi.search.PsiShortNamesCache; //导入方法依赖的package包/类
@Override
@NotNull
public NavigationItem[] getItemsByName(String name, final String pattern, Project project, boolean includeNonProjectItems)
{
	GlobalSearchScope scope = includeNonProjectItems ? GlobalSearchScope.allScope(project) : GlobalSearchScope.projectScope(project);
	PsiShortNamesCache cache = PsiShortNamesCache.getInstance(project);

	List<PsiMember> result = new ArrayList<PsiMember>();
	for(PsiMethod method : cache.getMethodsByName(name, scope))
	{
		if(!method.isConstructor() && isOpenable(method) && !hasSuperMethod(method))
		{
			result.add(method);
		}
	}
	for(PsiField field : cache.getFieldsByName(name, scope))
	{
		if(isOpenable(field))
		{
			result.add(field);
		}
	}
	for(PsiClass aClass : cache.getClassesByName(name, scope))
	{
		if(isOpenable(aClass))
		{
			result.add(aClass);
		}
	}
	PsiMember[] array = result.toArray(new PsiMember[result.size()]);
	Arrays.sort(array, MyComparator.INSTANCE);
	return array;
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:34,代码来源:DefaultSymbolNavigationContributor.java


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