本文整理汇总了Java中com.intellij.psi.search.GlobalSearchScope.getScopeRestrictedByFileTypes方法的典型用法代码示例。如果您正苦于以下问题:Java GlobalSearchScope.getScopeRestrictedByFileTypes方法的具体用法?Java GlobalSearchScope.getScopeRestrictedByFileTypes怎么用?Java GlobalSearchScope.getScopeRestrictedByFileTypes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.psi.search.GlobalSearchScope
的用法示例。
在下文中一共展示了GlobalSearchScope.getScopeRestrictedByFileTypes方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: javaFilesScope
import com.intellij.psi.search.GlobalSearchScope; //导入方法依赖的package包/类
@NotNull
private GlobalSearchScope javaFilesScope(Project project) {
return GlobalSearchScope.getScopeRestrictedByFileTypes(GlobalSearchScope.allScope(project), StdFileTypes.JAVA);
}
示例2: buildVisitor
import com.intellij.psi.search.GlobalSearchScope; //导入方法依赖的package包/类
@Override
@NotNull
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly) {
return new PhpElementVisitor() {
@Override
public void visitPhpArrayCreationExpression(ArrayCreationExpression expression) {
final PsiFile file = expression.getContainingFile();
if (!TranslationProviderUtil.isProvider(file)) {
return;
}
/* prepare scope of index search */
GlobalSearchScope theScope = GlobalSearchScope.allScope(expression.getProject());
theScope = GlobalSearchScope.getScopeRestrictedByFileTypes(theScope, PhpFileType.INSTANCE, HtmlFileType.INSTANCE, TwigFileType.INSTANCE);
/* iterate defined translations and report unused */
final String searchPrefix = file.getName().replaceAll("\\.php$", "|");
final Project project = expression.getProject();
for (ArrayHashElement pair : expression.getHashElements()) {
final PhpPsiElement key = pair.getKey();
if (!(key instanceof StringLiteralExpression)) {
continue;
}
final StringLiteralExpression literal = (StringLiteralExpression) key;
final String messageToFind = PhpStringUtil.unescapeText(literal.getContents(), literal.isSingleQuote());
final String regularEntry = searchPrefix + messageToFind;
final Set<String> usages
= new HashSet<>(FileBasedIndex.getInstance().getAllKeys(TranslationCallsIndexer.identity, project));
boolean found = usages.contains(regularEntry);
if (!found && usages.size() > 0) {
final String slashedCategoryEntry = "/" + regularEntry;
for (String usage : usages) {
if (usage.endsWith(slashedCategoryEntry)) {
found = true;
break;
}
}
}
usages.clear();
if (!found) {
holder.registerProblem(pair, messagePattern, ProblemHighlightType.LIKE_UNUSED_SYMBOL, new TheLocalFix());
}
}
}
};
}
示例3: buildVisitor
import com.intellij.psi.search.GlobalSearchScope; //导入方法依赖的package包/类
@Override
@NotNull
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly) {
return new PhpElementVisitor() {
@Override
public void visitPhpMethodReference(MethodReference reference) {
/* ensure that it's a target call; category is not empty and has no injections; we have messages */
TranslationCallsProcessUtil.ProcessingResult extracted = TranslationCallsProcessUtil.process(reference, true);
if (null == extracted) {
return;
}
/* handle `category` and `category/subcategory` cases */
String categoryForFileName = extracted.getCategory().getContents();
if (-1 != categoryForFileName.indexOf('/')) {
categoryForFileName
= categoryForFileName.substring(1 + categoryForFileName.lastIndexOf('/'), categoryForFileName.length());
}
final String expectedFileName = categoryForFileName + ".php";
/* iterate found translations and validate correctness */
final Map<StringLiteralExpression, PsiElement> messages = extracted.getMessages();
for (StringLiteralExpression literal : messages.keySet()) {
/* only quotes, no content presented */
if (literal.getTextLength() <= 2) {
continue;
}
final String message = literal.getContents();
final PsiElement reportingTarget = messages.get(literal);
/* warn injections are presented and skip further processing */
if (REPORT_INJECTIONS && null != literal.getFirstPsiChild()) {
holder.registerProblem(reportingTarget, messageInjection, ProblemHighlightType.WEAK_WARNING);
continue;
}
/* warn if non-ascii characters has been used */
if (REPORT_NONASCII_CHARACTERS && nonAsciiCharsRegex.matcher(message).matches()) {
holder.registerProblem(reportingTarget, messageNonAscii, ProblemHighlightType.WEAK_WARNING);
}
/* warn if the message is have no translations in the group */
final Set<String> searchEntry
= new HashSet<>(Collections.singletonList(PhpStringUtil.unescapeText(message, literal.isSingleQuote())));
GlobalSearchScope theScope = GlobalSearchScope.allScope(reference.getProject());
theScope = GlobalSearchScope.getScopeRestrictedByFileTypes(theScope, PhpFileType.INSTANCE);
final Set<VirtualFile> providers = new HashSet<>();
FileBasedIndex.getInstance()
.getFilesWithKey(TranslationKeysIndexer.identity, searchEntry, virtualFile -> {
if (virtualFile.getName().equals(expectedFileName)) {
providers.add(virtualFile);
}
return true;
}, theScope);
/* report found cases */
if (REPORT_UNKNOWN_TRANSLATIONS && 0 == providers.size()) {
holder.registerProblem(reportingTarget, messageNoTranslations, ProblemHighlightType.WEAK_WARNING);
}
providers.clear();
}
extracted.dispose();
}
};
}