Search in sources :

Example 6 with CompiledPattern

use of com.intellij.structuralsearch.impl.matcher.CompiledPattern in project intellij-community by JetBrains.

the class JavaCompilingVisitor method visitClass.

@Override
public void visitClass(PsiClass psiClass) {
    super.visitClass(psiClass);
    CompiledPattern pattern = myCompilingVisitor.getContext().getPattern();
    final MatchingHandler handler = pattern.getHandler(psiClass);
    if (needsSupers(psiClass, handler)) {
        ((JavaCompiledPattern) pattern).setRequestsSuperInners(true);
    }
    handleReferenceText(psiClass.getName(), myCompilingVisitor.getContext());
    GlobalCompilingVisitor.setFilter(handler, ClassFilter.getInstance());
}
Also used : JavaCompiledPattern(com.intellij.structuralsearch.impl.matcher.JavaCompiledPattern) CompiledPattern(com.intellij.structuralsearch.impl.matcher.CompiledPattern) JavaCompiledPattern(com.intellij.structuralsearch.impl.matcher.JavaCompiledPattern)

Example 7 with CompiledPattern

use of com.intellij.structuralsearch.impl.matcher.CompiledPattern in project intellij-community by JetBrains.

the class PatternCompiler method compilePattern.

public static CompiledPattern compilePattern(final Project project, final MatchOptions options) throws MalformedPatternException, UnsupportedOperationException {
    FileType fileType = options.getFileType();
    assert fileType instanceof LanguageFileType;
    Language language = ((LanguageFileType) fileType).getLanguage();
    StructuralSearchProfile profile = StructuralSearchUtil.getProfileByLanguage(language);
    assert profile != null;
    CompiledPattern result = profile.createCompiledPattern();
    final String[] prefixes = result.getTypedVarPrefixes();
    assert prefixes.length > 0;
    final CompileContext context = new CompileContext();
    if (ApplicationManager.getApplication().isUnitTestMode())
        lastTestingContext = context;
    try {
        context.init(result, options, project, options.getScope() instanceof GlobalSearchScope);
        List<PsiElement> elements = compileByAllPrefixes(project, options, result, context, prefixes);
        final CompiledPattern pattern = context.getPattern();
        checkForUnknownVariables(pattern, elements);
        pattern.setNodes(elements);
        if (context.getSearchHelper().doOptimizing() && context.getSearchHelper().isScannedSomething()) {
            final Set<PsiFile> set = context.getSearchHelper().getFilesSetToScan();
            final List<PsiFile> filesToScan = new ArrayList<>(set.size());
            final GlobalSearchScope scope = (GlobalSearchScope) options.getScope();
            for (final PsiFile file : set) {
                if (!scope.contains(file.getVirtualFile())) {
                    continue;
                }
                if (file instanceof PsiFileImpl) {
                    ((PsiFileImpl) file).clearCaches();
                }
                filesToScan.add(file);
            }
            if (filesToScan.size() == 0) {
                throw new MalformedPatternException(SSRBundle.message("ssr.will.not.find.anything"));
            }
            result.setScope(new LocalSearchScope(PsiUtilCore.toPsiElementArray(filesToScan)));
        }
    } finally {
        context.clear();
    }
    return result;
}
Also used : LocalSearchScope(com.intellij.psi.search.LocalSearchScope) PsiFileImpl(com.intellij.psi.impl.source.PsiFileImpl) TIntArrayList(gnu.trove.TIntArrayList) LanguageFileType(com.intellij.openapi.fileTypes.LanguageFileType) Language(com.intellij.lang.Language) FileType(com.intellij.openapi.fileTypes.FileType) LanguageFileType(com.intellij.openapi.fileTypes.LanguageFileType) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) CompiledPattern(com.intellij.structuralsearch.impl.matcher.CompiledPattern)

Example 8 with CompiledPattern

use of com.intellij.structuralsearch.impl.matcher.CompiledPattern in project intellij-community by JetBrains.

the class JavaCompilingVisitor method visitField.

@Override
public void visitField(PsiField psiField) {
    super.visitField(psiField);
    CompiledPattern pattern = myCompilingVisitor.getContext().getPattern();
    final MatchingHandler handler = pattern.getHandler(psiField);
    if (needsSupers(psiField, handler)) {
        assert pattern instanceof JavaCompiledPattern;
        ((JavaCompiledPattern) pattern).setRequestsSuperFields(true);
    }
}
Also used : JavaCompiledPattern(com.intellij.structuralsearch.impl.matcher.JavaCompiledPattern) CompiledPattern(com.intellij.structuralsearch.impl.matcher.CompiledPattern) JavaCompiledPattern(com.intellij.structuralsearch.impl.matcher.JavaCompiledPattern)

Example 9 with CompiledPattern

use of com.intellij.structuralsearch.impl.matcher.CompiledPattern in project intellij-community by JetBrains.

the class JavaCompilingVisitor method visitMethod.

@Override
public void visitMethod(PsiMethod psiMethod) {
    super.visitMethod(psiMethod);
    CompiledPattern pattern = myCompilingVisitor.getContext().getPattern();
    final MatchingHandler handler = pattern.getHandler(psiMethod);
    if (needsSupers(psiMethod, handler)) {
        assert pattern instanceof JavaCompiledPattern;
        ((JavaCompiledPattern) pattern).setRequestsSuperMethods(true);
    }
    GlobalCompilingVisitor.setFilter(handler, MethodFilter.getInstance());
    handleReferenceText(psiMethod.getName(), myCompilingVisitor.getContext());
}
Also used : JavaCompiledPattern(com.intellij.structuralsearch.impl.matcher.JavaCompiledPattern) CompiledPattern(com.intellij.structuralsearch.impl.matcher.CompiledPattern) JavaCompiledPattern(com.intellij.structuralsearch.impl.matcher.JavaCompiledPattern)

Aggregations

CompiledPattern (com.intellij.structuralsearch.impl.matcher.CompiledPattern)9 JavaCompiledPattern (com.intellij.structuralsearch.impl.matcher.JavaCompiledPattern)3 Language (com.intellij.lang.Language)2 MatchResultImpl (com.intellij.structuralsearch.impl.matcher.MatchResultImpl)2 HashSet (java.util.HashSet)2 FilteringNodeIterator (com.intellij.dupLocator.iterators.FilteringNodeIterator)1 NodeIterator (com.intellij.dupLocator.iterators.NodeIterator)1 FileType (com.intellij.openapi.fileTypes.FileType)1 LanguageFileType (com.intellij.openapi.fileTypes.LanguageFileType)1 PsiElement (com.intellij.psi.PsiElement)1 PsiFileImpl (com.intellij.psi.impl.source.PsiFileImpl)1 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)1 LocalSearchScope (com.intellij.psi.search.LocalSearchScope)1 TopLevelMatchingHandler (com.intellij.structuralsearch.impl.matcher.handlers.TopLevelMatchingHandler)1 SsrFilteringNodeIterator (com.intellij.structuralsearch.impl.matcher.iterators.SsrFilteringNodeIterator)1 MatchingStrategy (com.intellij.structuralsearch.impl.matcher.strategies.MatchingStrategy)1 TIntArrayList (gnu.trove.TIntArrayList)1