本文整理汇总了Java中com.intellij.psi.search.PsiShortNamesCache.getInstance方法的典型用法代码示例。如果您正苦于以下问题:Java PsiShortNamesCache.getInstance方法的具体用法?Java PsiShortNamesCache.getInstance怎么用?Java PsiShortNamesCache.getInstance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.psi.search.PsiShortNamesCache
的用法示例。
在下文中一共展示了PsiShortNamesCache.getInstance方法的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: 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;
}
示例3: 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);
}
示例4: 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;
}
示例5: 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);
}
}
}
}
}
示例6: 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;
}
示例7: 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;
}
示例8: getWebAppsFolder
import com.intellij.psi.search.PsiShortNamesCache; //导入方法依赖的package包/类
/**
* Returns the most probable WebApps folder
* @param project Project
* @return String value
*/
private String getWebAppsFolder(Project project) {
// Using the api to look for the web.xml
PsiShortNamesCache namesCache = PsiShortNamesCache.getInstance(project);
PsiFile[] webXML = namesCache.getFilesByName("web.xml");
if (webXML == null || webXML.length < 1) return "";
// Grab the first one that the api found
PsiFile file = webXML[0];
// The parent folder is the "WEB-INF" folder
PsiDirectory webInfFolder = file.getParent();
if (webInfFolder == null) return "";
// The parent folder to "WEB-INF" is the WebApps folder
PsiDirectory webappFolder = webInfFolder.getParent();
if (webappFolder == null) return "";
// Folder found, returns it to the user
VirtualFile virtualFile = webappFolder.getVirtualFile();
return virtualFile.getPresentableUrl();
}
示例9: 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;
}
示例10: getMembersToImport
import com.intellij.psi.search.PsiShortNamesCache; //导入方法依赖的package包/类
@NotNull
@Override
protected List<PsiMethod> getMembersToImport(boolean applicableOnly)
{
final Project project = myMethodCall.getProject();
PsiShortNamesCache cache = PsiShortNamesCache.getInstance(project);
final PsiMethodCallExpression element = myMethodCall.getElement();
PsiReferenceExpression reference = element == null ? null : element.getMethodExpression();
String name = reference == null ? null : reference.getReferenceName();
if(name == null)
{
return Collections.emptyList();
}
final StaticMembersProcessor<PsiMethod> processor = new MyStaticMethodProcessor(element);
cache.processMethodsWithName(name, element.getResolveScope(), processor);
return processor.getMembersToImport(applicableOnly);
}
示例11: 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);
}
}
}
示例12: applyFilter
import com.intellij.psi.search.PsiShortNamesCache; //导入方法依赖的package包/类
public Result applyFilter(final String line, final int entireLength) {
if (!line.endsWith(".java\n")) {
return null;
}
try {
final Matcher matcher = PATTERN.matcher(line);
if (matcher.matches()) {
final String method = matcher.group(1);
final int lineNumber = Integer.parseInt(matcher.group(2));
final String fileName = matcher.group(3);
final int textStartOffset = entireLength - line.length();
final PsiShortNamesCache cache = PsiShortNamesCache.getInstance(myProject);
final PsiFile[] psiFiles = cache.getFilesByName(fileName);
if (psiFiles.length == 0) return null;
final HyperlinkInfo info = psiFiles.length == 1 ?
new OpenFileHyperlinkInfo(myProject, psiFiles[0].getVirtualFile(), lineNumber - 1) :
new MyHyperlinkInfo(psiFiles);
return new Result(textStartOffset + matcher.start(2), textStartOffset + matcher.end(3), info);
}
}
catch (NumberFormatException e) {
LOG.debug(e);
}
return null;
}
示例13: findDeclaredFields
import com.intellij.psi.search.PsiShortNamesCache; //导入方法依赖的package包/类
@Override
@NotNull
public PsiField[] findDeclaredFields(@NotNull final PsiManager manager, @NotNull String name) {
final PsiShortNamesCache cache = PsiShortNamesCache.getInstance(manager.getProject());
GlobalSearchScope scope = GlobalSearchScope.allScope(manager.getProject());
return cache.getFieldsByName(name, scope);
}
示例14: findDeclaredMethods
import com.intellij.psi.search.PsiShortNamesCache; //导入方法依赖的package包/类
@Override
@NotNull
public PsiMethod[] findDeclaredMethods(@NotNull final PsiManager manager, @NotNull String name) {
final PsiShortNamesCache cache = PsiShortNamesCache.getInstance(manager.getProject());
GlobalSearchScope scope = GlobalSearchScope.allScope(manager.getProject());
return cache.getMethodsByNameIfNotMoreThan(name, scope, MAX_COUNT);
}
示例15: 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);
}