本文整理汇总了Java中com.intellij.psi.search.PsiShortNamesCache类的典型用法代码示例。如果您正苦于以下问题:Java PsiShortNamesCache类的具体用法?Java PsiShortNamesCache怎么用?Java PsiShortNamesCache使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PsiShortNamesCache类属于com.intellij.psi.search包,在下文中一共展示了PsiShortNamesCache类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: multiResolve
import com.intellij.psi.search.PsiShortNamesCache; //导入依赖的package包/类
@NotNull
@Override
public ResolveResult[] multiResolve(final boolean incompleteCode) {
Project project = myElement.getProject();
final String enumLiteralJavaModelName = myElement.getText().replaceAll("\"", "").toUpperCase();
final PsiShortNamesCache psiShortNamesCache = PsiShortNamesCache.getInstance(project);
final PsiField[] javaEnumLiteralFields = psiShortNamesCache.getFieldsByName(
enumLiteralJavaModelName, GlobalSearchScope.allScope(project)
);
final Set<PsiField> enumFields = stream(javaEnumLiteralFields)
.filter(literal -> literal.getParent() != null)
.filter(literal -> literal.getParent() instanceof ClsClassImpl)
.filter(literal -> ((ClsClassImpl) literal.getParent()).isEnum())
.collect(Collectors.toSet());
return PsiElementResolveResult.createResults(enumFields);
}
开发者ID:AlexanderBartash,项目名称:hybris-integration-intellij-idea-plugin,代码行数:20,代码来源:HybrisEnumLiteralItemReference.java
示例2: multiResolve
import com.intellij.psi.search.PsiShortNamesCache; //导入依赖的package包/类
@NotNull
@Override
public ResolveResult[] multiResolve(final boolean incompleteCode) {
final Project project = myElement.getProject();
final String modelName = PATTERN.matcher(myElement.getText()).replaceAll("");
final String javaModelName = modelName + JAVA_MODEL_SUFFIX;
final String jaloModelName = modelName;
final PsiClass[] javaModelClasses = PsiShortNamesCache.getInstance(project).getClassesByName(
javaModelName, GlobalSearchScope.allScope(project)
);
final PsiClass[] jaloModelClasses = PsiShortNamesCache.getInstance(project).getClassesByName(
jaloModelName, GlobalSearchScope.projectScope(project)
);
final PsiClass[] psiClasses = ArrayUtil.mergeArrays(javaModelClasses, jaloModelClasses);
return PsiElementResolveResult.createResults(psiClasses);
}
开发者ID:AlexanderBartash,项目名称:hybris-integration-intellij-idea-plugin,代码行数:21,代码来源:HybrisModelItemReference.java
示例3: searchClassByName
import com.intellij.psi.search.PsiShortNamesCache; //导入依赖的package包/类
/**
* search class by class name.
*
* @param name
* @param project
* @return
*/
private static PsiClass searchClassByName(String name, Project project) {
GlobalSearchScope searchScope = GlobalSearchScope.allScope(project);
PsiClass[] psiClasses = PsiShortNamesCache.getInstance(project).getClassesByName(name, searchScope);
if (psiClasses.length == 1) {
return psiClasses[0];
}
if (psiClasses.length > 1) {
for (PsiClass pc :
psiClasses) {
PsiJavaFile psiJavaFile = (PsiJavaFile) pc.getContainingFile();
String packageName = psiJavaFile.getPackageName();
if (List.class.getPackage().getName().equals(packageName) ||
packageName.contains("io.xujiaji.xmvp")) {
return pc;
}
}
}
return null;
}
示例4: processClassesByNames
import com.intellij.psi.search.PsiShortNamesCache; //导入依赖的package包/类
public static boolean processClassesByNames(Project project,
final GlobalSearchScope scope,
Collection<String> names,
Processor<PsiClass> processor) {
final PsiShortNamesCache cache = PsiShortNamesCache.getInstance(project);
for (final String name : names) {
ProgressIndicatorProvider.checkCanceled();
final PsiClass[] classes = MethodUsagesSearcher.resolveInReadAction(project, new Computable<PsiClass[]>() {
@Override
public PsiClass[] compute() {
return cache.getClassesByName(name, scope);
}
});
for (PsiClass psiClass : classes) {
ProgressIndicatorProvider.checkCanceled();
if (!processor.process(psiClass)) {
return false;
}
}
}
return true;
}
示例5: MoveClassToModuleFix
import com.intellij.psi.search.PsiShortNamesCache; //导入依赖的package包/类
public MoveClassToModuleFix(String referenceName, Module currentModule, PsiDirectory root, PsiElement psiElement) {
myReferenceName = referenceName;
myCurrentModule = currentModule;
mySourceRoot = root;
final Project project = psiElement.getProject();
final PsiClass[] classes = PsiShortNamesCache.getInstance(project).getClassesByName(referenceName, GlobalSearchScope.allScope(project));
final JavaPsiFacade facade = JavaPsiFacade.getInstance(project);
final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
for (final PsiClass aClass : classes) {
if (!facade.getResolveHelper().isAccessible(aClass, psiElement, aClass)) continue;
final PsiFile psiFile = aClass.getContainingFile();
if (!(psiFile instanceof PsiJavaFile)) continue;
if (aClass.getQualifiedName() == null) continue;
VirtualFile virtualFile = psiFile.getVirtualFile();
if (virtualFile == null) continue;
final Module classModule = fileIndex.getModuleForFile(virtualFile);
if (classModule != null && classModule != currentModule && !ModuleRootManager.getInstance(currentModule).isDependsOn(classModule)) {
myModules.put(aClass, classModule);
}
}
}
示例6: 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);
}
示例7: 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;
}
示例8: 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);
}
}
}
}
}
示例9: resolveInner
import com.intellij.psi.search.PsiShortNamesCache; //导入依赖的package包/类
private ResolveResult[] resolveInner() {
final String value = myValue.getStringValue();
if (value == null || value.length() <= 0) {
return ResolveResult.EMPTY_ARRAY;
}
// Search for custom views with the same name as the declare styleable, such that
// you can navigate from the XML styleable declaration to the corresponding custom view
final PsiClass[] classes = PsiShortNamesCache.getInstance(myElement.getProject())
.getClassesByName(value, myFacet.getModule().getModuleWithDependenciesAndLibrariesScope(false));
if (classes.length == 0) {
return ResolveResult.EMPTY_ARRAY;
}
final ResolveResult[] result = new ResolveResult[classes.length];
for (int i = 0; i < result.length; i++) {
result[i] = new PsiElementResolveResult(classes[i]);
}
return result;
}
示例10: findClassByText
import com.intellij.psi.search.PsiShortNamesCache; //导入依赖的package包/类
private static boolean findClassByText(GrReferenceExpression ref) {
final String text = ref.getText();
final int i = text.indexOf('<');
String className = i == -1 ? text : text.substring(0, i);
PsiClass[] names = PsiShortNamesCache.getInstance(ref.getProject()).getClassesByName(className, ref.getResolveScope());
if (names.length > 0) return true;
PsiFile file = ref.getContainingFile();
if (file instanceof GroovyFile) {
GrImportStatement[] imports = ((GroovyFile)file).getImportStatements();
for (GrImportStatement anImport : imports) {
if (className.equals(anImport.getImportedName())) return true;
}
}
return false;
}
示例11: getTemplateString
import com.intellij.psi.search.PsiShortNamesCache; //导入依赖的package包/类
@Override
public String getTemplateString(@NotNull PsiElement element) {
Project project = element.getProject();
final GlobalSearchScope resolveScope = element.getResolveScope();
PsiClass[] buildConfigClasses = PsiShortNamesCache.getInstance(project).getClassesByName("BuildConfig", resolveScope);
String buildConfigDebug = "BuildConfig.DEBUG";
if (buildConfigClasses.length != 0) {
// Get BuildConfig QualifiedName
PsiClass buildConfig = buildConfigClasses[0];
String qualifiedName = buildConfig.getQualifiedName();
buildConfigDebug = qualifiedName + ".DEBUG";
}
return "if (" + buildConfigDebug + ") " + getStaticPrefix(LOG, "d", element) + "($TAG$, $expr$)$END$";
}
示例12: ByItem
import com.intellij.psi.search.PsiShortNamesCache; //导入依赖的package包/类
ByItem(final Converter converter,
final Map<String,Set<String>> globalFields, final Map<String,Set<String>> globalMethods,
final List<TypeNameItemNamePair> pairFields, final List<TypeNameItemNamePair> pairMethods,
final List<Item> locals,
final GlobalSearchScope scope, final IdFilter filter) {
this.converter = converter;
final ByItemMaps maps = JavaItems.valuesByItem(locals, true); // locals byItem map contains an entry for ObjectItem
this.localValues = maps.values;
this.localMethods = maps.methods;
this.globalFields = globalFields;
this.globalMethods = globalMethods;
this.pairFields = pairFields;
this.pairMethods = pairMethods;
this.psiCache = PsiShortNamesCache.getInstance(converter.project);
this.scope = scope;
this.filter = filter;
}
示例13: prepareNameTrie
import com.intellij.psi.search.PsiShortNamesCache; //导入依赖的package包/类
private int[] prepareNameTrie(final String[] fieldNames, final String[] methodNames, final String[] packageNames) {
pushScope("prepare lazy trie");
try {
if (updateFuture.isCancelled())
return null;
final String[] classNames = DumbService.getInstance(project).runReadActionInSmartMode(new Computable<String[]>() {
@Override
public String[] compute() {
return PsiShortNamesCache.getInstance(project).getAllClassNames();
}
});
if (updateFuture.isCancelled())
return null;
final String[] allNames = concatenate(classNames,fieldNames,methodNames,packageNames);
if (updateFuture.isCancelled())
return null;
// there may be duplicates, but we don't particularly care
Arrays.sort(allNames);
return JavaTrie.makeTrieStructure(allNames);
} finally { popScope(); }
}
示例14: getAllClassNames
import com.intellij.psi.search.PsiShortNamesCache; //导入依赖的package包/类
@NotNull
private static String[] getAllClassNames(@NotNull final Project project) {
return ApplicationManager.getApplication().runReadAction(new Computable<String[]>() {
@Override
public String[] compute() {
final long modCount = PsiManager.getInstance(project).getModificationTracker().getJavaStructureModificationCount();
TimedReference<SoftReference<Pair<String[], Long>>> ref1 = project.getUserData(ALL_CLASS_NAMES_CACHE);
SoftReference<Pair<String[], Long>> ref2 = ref1 == null ? null : ref1.get();
Pair<String[], Long> pair = ref2 == null ? null : ref2.get();
if (pair != null && pair.second.equals(modCount)) {
return pair.first;
}
String[] names = PsiShortNamesCache.getInstance(project).getAllClassNames();
ref1 = new TimedReference<SoftReference<Pair<String[], Long>>>(null);
ref1.set(new SoftReference<Pair<String[], Long>>(Pair.create(names, modCount)));
project.putUserData(ALL_CLASS_NAMES_CACHE, ref1);
return names;
}
});
}
示例15: suggestQualifierItems
import com.intellij.psi.search.PsiShortNamesCache; //导入依赖的package包/类
private static Set<LookupElement> suggestQualifierItems(CompletionParameters parameters,
PsiJavaCodeReferenceElement qualifier,
ElementFilter filter) {
String referenceName = qualifier.getReferenceName();
if (referenceName == null) {
return Collections.emptySet();
}
PrefixMatcher qMatcher = new CamelHumpMatcher(referenceName);
Set<LookupElement> plainVariants =
JavaSmartCompletionContributor.completeReference(qualifier, qualifier, filter, true, true, parameters, qMatcher);
for (PsiClass aClass : PsiShortNamesCache.getInstance(qualifier.getProject()).getClassesByName(referenceName, qualifier.getResolveScope())) {
plainVariants.add(JavaClassNameCompletionContributor.createClassLookupItem(aClass, true));
}
if (!plainVariants.isEmpty()) {
return plainVariants;
}
final Set<LookupElement> allClasses = new LinkedHashSet<LookupElement>();
JavaClassNameCompletionContributor.addAllClasses(parameters.withPosition(qualifier.getReferenceNameElement(), qualifier.getTextRange().getEndOffset()),
true, qMatcher, new CollectConsumer<LookupElement>(allClasses));
return allClasses;
}