本文整理汇总了Java中com.intellij.psi.search.PsiShortNamesCache.getAllClassNames方法的典型用法代码示例。如果您正苦于以下问题:Java PsiShortNamesCache.getAllClassNames方法的具体用法?Java PsiShortNamesCache.getAllClassNames怎么用?Java PsiShortNamesCache.getAllClassNames使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.psi.search.PsiShortNamesCache
的用法示例。
在下文中一共展示了PsiShortNamesCache.getAllClassNames方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: 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);
}
}
}
}
}
示例3: getAllClassNames
import com.intellij.psi.search.PsiShortNamesCache; //导入方法依赖的package包/类
@Override
@NotNull
public String[] getAllClassNames() {
Merger<String> merger = new Merger<String>();
for (PsiShortNamesCache cache : myCaches) {
String[] names = cache.getAllClassNames();
merger.add(names);
}
String[] result = merger.getResult();
return result != null ? result : ArrayUtil.EMPTY_STRING_ARRAY;
}
示例4: getNames
import com.intellij.psi.search.PsiShortNamesCache; //导入方法依赖的package包/类
@Override
@NotNull
public String[] getNames(Project project, boolean includeNonProjectItems) {
PsiShortNamesCache cache = PsiShortNamesCache.getInstance(project);
HashSet<String> set = new HashSet<String>();
cache.getAllMethodNames(set);
cache.getAllFieldNames(set);
cache.getAllClassNames(set);
return ArrayUtil.toStringArray(set);
}
示例5: 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;
}
}
示例6: 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);
}
示例7: getAllClassNames
import com.intellij.psi.search.PsiShortNamesCache; //导入方法依赖的package包/类
@Override
@NotNull
public String[] getAllClassNames()
{
Merger<String> merger = new Merger<String>();
for(PsiShortNamesCache cache : myCaches)
{
String[] names = cache.getAllClassNames();
merger.add(names);
}
String[] result = merger.getResult();
return result != null ? result : ArrayUtil.EMPTY_STRING_ARRAY;
}
示例8: getNames
import com.intellij.psi.search.PsiShortNamesCache; //导入方法依赖的package包/类
@Override
@NotNull
public String[] getNames(Project project, boolean includeNonProjectItems)
{
PsiShortNamesCache cache = PsiShortNamesCache.getInstance(project);
HashSet<String> set = new HashSet<String>();
cache.getAllMethodNames(set);
cache.getAllFieldNames(set);
cache.getAllClassNames(set);
return ArrayUtil.toStringArray(set);
}
示例9: testRandomEditingForUnused
import com.intellij.psi.search.PsiShortNamesCache; //导入方法依赖的package包/类
public void testRandomEditingForUnused() throws Exception {
configureFromFileText("Stress.java", "class X {<caret>}");
PsiShortNamesCache cache = PsiShortNamesCache.getInstance(getProject());
String[] names = cache.getAllClassNames();
final StringBuilder imports = new StringBuilder();
final StringBuilder usages = new StringBuilder();
int v = 0;
List<PsiClass> aclasses = new ArrayList<>();
for (String name : names) {
PsiClass[] classes = cache.getClassesByName(name, GlobalSearchScope.allScope(getProject()));
if (classes.length == 0) continue;
PsiClass aClass = classes[0];
if (!aClass.hasModifierProperty(PsiModifier.PUBLIC)) continue;
if (aClass.getSuperClass() == null) continue;
PsiClassType[] superTypes = aClass.getSuperTypes();
if (superTypes.length == 0 || superTypes[0].resolve() == null) continue;
String qualifiedName = aClass.getQualifiedName();
if (qualifiedName.startsWith("java.lang.invoke")) continue; // java.lang.invoke.MethodHandle has weird access attributes in recent rt.jar which causes spurious highlighting errors
imports.append("import " + qualifiedName + ";\n");
usages.append("/**/ "+aClass.getName() + " var" + v + " = null; var" + v + ".toString();\n");
aclasses.add(aClass);
v++;
if (v>100) break;
}
final String text = imports + "\n class X {{\n" + usages + "}}";
WriteCommandAction.runWriteCommandAction(null, () -> {
getEditor().getDocument().setText(text);
});
List<HighlightInfo> errors = DaemonAnalyzerTestCase.filter(doHighlighting(), HighlightSeverity.WARNING);
assertEmpty(errors);
Random random = new Random();
int unused = 0;
for (int i = 0; i < 100; i++) {
String s = myFile.getText();
int offset;
while (true) {
offset = random.nextInt(s.length());
if (CharArrayUtil.regionMatches(s, offset, "/**/") || CharArrayUtil.regionMatches(s, offset, "//")) break;
}
char next = offset < s.length()-1 ? s.charAt(offset+1) : 0;
if (next == '/') {
myEditor.getCaretModel().moveToOffset(offset + 1);
type("**");
unused--;
}
else if (next == '*') {
myEditor.getCaretModel().moveToOffset(offset + 1);
delete();
delete();
unused++;
}
else {
continue;
}
PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
getFile().accept(new PsiRecursiveElementVisitor() {
@Override
public void visitElement(PsiElement element) {
assertTrue(element.toString(), element.isValid());
super.visitElement(element);
}
});
System.out.println("i = " + i + " " + next + " at "+offset);
List<HighlightInfo> infos = doHighlighting();
errors = DaemonAnalyzerTestCase.filter(infos, HighlightSeverity.ERROR);
assertEmpty(errors);
List<HighlightInfo> warns = DaemonAnalyzerTestCase.filter(infos, HighlightSeverity.WARNING);
if (unused != warns.size()) {
assertEquals(warns.toString(), unused, warns.size());
}
}
FileEditorManagerEx.getInstanceEx(getProject()).closeAllFiles();
}