當前位置: 首頁>>代碼示例>>Java>>正文


Java GlobalSearchScope.getScopeRestrictedByFileTypes方法代碼示例

本文整理匯總了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);
}
 
開發者ID:TNG,項目名稱:jgiven-intellij-plugin,代碼行數:5,代碼來源:ScenarioStateReferenceProvider.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());
                }
            }
        }
    };
}
 
開發者ID:kalessil,項目名稱:yii2inspections,代碼行數:50,代碼來源:UnusedTranslationsInspector.java

示例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();
        }
    };
}
 
開發者ID:kalessil,項目名稱:yii2inspections,代碼行數:68,代碼來源:TranslationsCorrectnessInspector.java


注:本文中的com.intellij.psi.search.GlobalSearchScope.getScopeRestrictedByFileTypes方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。