Java 类com.intellij.psi.PsiRecursiveElementVisitor 实例源码

项目:react-css-modules-intellij-plugin    文件:CssModulesUtil.java   
/**
 * Visits the containing file of the specified element to find a require to a style sheet file
 *
 * @param cssReferencingElement starting point for finding an imported style sheet file
 * @return the PSI file for the first imported style sheet file
 */
public static StylesheetFile getImportedStyleSheetFile(PsiElement cssReferencingElement) {
    final Ref<StylesheetFile> file = new Ref<>();
    cssReferencingElement.getContainingFile().accept(new PsiRecursiveElementVisitor() {
        @Override
        public void visitElement(PsiElement element) {
            if (file.get() != null) {
                return;
            }
            if (element instanceof JSLiteralExpression) {
                if (resolveStyleSheetFile(element, file)) return;
            }
            if(element instanceof ES6FromClause) {
                if (resolveStyleSheetFile(element, file)) return;
            }
            super.visitElement(element);
        }
    });
    return file.get();
}
项目:react-css-modules-intellij-plugin    文件:CssModulesUtil.java   
/**
 * Gets the CssClass PSI element whose name matches the specified cssClassName
 *
 * @param stylesheetFile the PSI style sheet file to visit
 * @param cssClass       the class to find, including the leading ".", e.g. ".my-class-name"
 * @return the matching class or <code>null</code> if no matches are found
 */
public static CssClass getCssClass(StylesheetFile stylesheetFile, String cssClass) {
    final Ref<CssClass> cssClassRef = new Ref<>();
    stylesheetFile.accept(new PsiRecursiveElementVisitor() {
        @Override
        public void visitElement(PsiElement element) {
            if (cssClassRef.get() != null) {
                return;
            }
            if (element instanceof CssClass) {
                if (cssClass.equals(element.getText()) && isCssModuleClass((CssClass) element)) {
                    cssClassRef.set((CssClass) element);
                    return;
                }
            }
            super.visitElement(element);
        }
    });
    return cssClassRef.get();
}
项目:react-css-modules-intellij-plugin    文件:CssModulesUtil.java   
/**
 * Resolves the style sheet PSI file that backs a require("./stylesheet.css").
 *
 * @param cssFileNameLiteralParent parent element to a file name string literal that points to a style sheet file
 * @return the matching style sheet PSI file, or <code>null</code> if the file can't be resolved
 */
public static StylesheetFile resolveStyleSheetFile(PsiElement cssFileNameLiteralParent) {
    final Ref<StylesheetFile> stylesheetFileRef = new Ref<>();
    cssFileNameLiteralParent.accept(new PsiRecursiveElementVisitor() {
        @Override
        public void visitElement(PsiElement element) {
            if (stylesheetFileRef.get() != null) {
                return;
            }
            if (element instanceof JSLiteralExpression) {
                if (resolveStyleSheetFile(element, stylesheetFileRef)) return;
            }
            if(element instanceof ES6FromClause) {
                if (resolveStyleSheetFile(element, stylesheetFileRef)) return;
            }
            super.visitElement(element);
        }
    });
    return stylesheetFileRef.get();
}
项目:dotplugin    文件:DotPSITreeUtil.java   
/**
 * Utility method returning all DotIDs with corresponding id the project.
 *
 * @param project - project for searching
 * @param id_     - DotId id for searching
 * @return iterable set of DotIds naming as id
 */
public static Iterable<DotId> findDotIds(Project project, String id_) {
    Set<DotId> ids = new HashSet<>();
    PsiRecursiveElementVisitor psiRecursiveElementVisitor = new PsiRecursiveElementVisitor() {
        @Override
        public void visitElement(PsiElement element) {
            if (element instanceof DotId && element.getText().equals(id_)) {
                ids.add(((DotId) element));
            }
            super.visitElement(element);
        }
    };
    Collection<VirtualFile> virtualFiles =
            FileBasedIndex.getInstance().getContainingFiles(FileTypeIndex.NAME, DotFileType.INSTANCE,
                    GlobalSearchScope.allScope(project));
    for (VirtualFile virtualFile : virtualFiles) {
        DotFile dotFile = (DotFile) PsiManager.getInstance(project).findFile(virtualFile);
        if (dotFile != null) {
            for (PsiElement e : dotFile.getChildren()) {
                psiRecursiveElementVisitor.visitElement(e);
            }
        }
    }
    return ids;
}
项目:dotplugin    文件:DotPSITreeUtil.java   
/**
 * Utility method returning all DotIDs in the project
 *
 * @param project project for searching
 * @return iterable set of all DotIds in project
 */
public static Iterable<DotId> findDotIds(Project project) {
    Set<DotId> ids = new HashSet<>();
    PsiRecursiveElementVisitor psiRecursiveElementVisitor = new PsiRecursiveElementVisitor() {
        @Override
        public void visitElement(PsiElement element) {
            if (element instanceof DotId) {
                ids.add(((DotId) element));
            }
            super.visitElement(element);
        }
    };
    Collection<VirtualFile> virtualFiles =
            FileBasedIndex.getInstance().getContainingFiles(FileTypeIndex.NAME, DotFileType.INSTANCE,
                    GlobalSearchScope.allScope(project));
    for (VirtualFile virtualFile : virtualFiles) {
        DotFile dotFile = (DotFile) PsiManager.getInstance(project).findFile(virtualFile);
        if (dotFile != null) {
            for (PsiElement e : dotFile.getChildren()) {
                psiRecursiveElementVisitor.visitElement(e);
            }
        }
    }
    return ids;
}
项目:js-graphql-intellij-plugin    文件:JSGraphQLLanguageInjectionUtil.java   
public static String getEnvironment(PsiFile file) {
    if (file instanceof JSFile) {
        // for JS Files we have to check the kind of environment being used
        final Ref<String> envRef = new Ref<>();
        file.accept(new PsiRecursiveElementVisitor() {
            @Override
            public void visitElement(PsiElement element) {
                if (!isJSGraphQLLanguageInjectionTarget(element, envRef)) {
                    // no match yet, so keep visiting
                    super.visitElement(element);
                }
            }
        });
        final String environment = envRef.get();
        if (environment != null) {
            return environment;
        }
    } else if (file instanceof JSGraphQLFile) {
        final Ref<String> tag = new Ref<>();
        if (file.getContext() != null && isJSGraphQLLanguageInjectionTarget(file.getContext(), tag)) {
            return tag.get();
        }
    }
    // fallback is traditional GraphQL
    return GRAPHQL_ENVIRONMENT;
}
项目:tools-idea    文件:InputExpressionDialog.java   
private Set<String> findUnresolvedPrefixes() {
    final Set<String> prefixes = new HashSet<String>();

    myXPathFile.accept(new PsiRecursiveElementVisitor(){
        public void visitElement(PsiElement element) {
            if (element instanceof QNameElement) {
                final PsiReference[] references = element.getReferences();
                for (PsiReference reference : references) {
                    if (reference instanceof PrefixReference) {
                        final PrefixReference prefixReference = (PrefixReference)reference;
                        if (prefixReference.isUnresolved()) {
                            prefixes.add(prefixReference.getPrefix());
                        }
                    }
                }
            }
            super.visitElement(element);
        }
    });
    return prefixes;
}
项目:idea-php-symfony2-plugin    文件:CaseSensitivityServiceInspection.java   
private void phpVisitor(final @NotNull ProblemsHolder holder, @NotNull PsiFile psiFile) {

        psiFile.acceptChildren(new PsiRecursiveElementVisitor() {
            @Override
            public void visitElement(PsiElement element) {
                PsiElement parent = element.getParent();
                if(!(parent instanceof StringLiteralExpression)) {
                    super.visitElement(element);
                    return;
                }

                MethodReference methodReference = PsiElementUtils.getMethodReferenceWithFirstStringParameter(element);
                if (methodReference != null && PhpElementsUtil.isMethodReferenceInstanceOf(methodReference, ServiceContainerUtil.SERVICE_GET_SIGNATURES)) {
                    String serviceName = ((StringLiteralExpression) parent).getContents();
                    if(StringUtils.isNotBlank(serviceName) && !serviceName.equals(serviceName.toLowerCase())) {
                        holder.registerProblem(element, SYMFONY_LOWERCASE_LETTERS_FOR_SERVICE, ProblemHighlightType.WEAK_WARNING);
                    }
                }

                super.visitElement(element);
            }
        });
    }
项目:idea-php-symfony2-plugin    文件:ContainerConstantInspection.java   
private void yamlVisitor(@NotNull ProblemsHolder holder, @NotNull PsiFile psiFile) {
    psiFile.acceptChildren(new PsiRecursiveElementVisitor() {
        @Override
        public void visitElement(PsiElement psiElement) {
            if(psiElement instanceof YAMLScalar) {
                String textValue = ((YAMLScalar) psiElement).getTextValue();
                if(textValue.length() > 0 && textValue.startsWith("!php/const:")) {
                    String constantName = textValue.substring(11);
                    if(StringUtils.isNotBlank(constantName) && ServiceContainerUtil.getTargetsForConstant(psiElement.getProject(), constantName).size() == 0) {
                        holder.registerProblem(psiElement, MESSAGE, ProblemHighlightType.GENERIC_ERROR_OR_WARNING);
                    }
                }
            }

            super.visitElement(psiElement);
        }
    });
}
项目:consulo-dotnet    文件:DotNetCoverageEngine.java   
@NotNull
@Override
public Set<String> getQualifiedNames(@NotNull final PsiFile sourceFile)
{
    return ApplicationManager.getApplication().runReadAction(new Computable<Set<String>>()
    {
        @Override
        public Set<String> compute()
        {
            final Set<String> set = new THashSet<String>();
            sourceFile.accept(new PsiRecursiveElementVisitor()
            {
                @Override
                public void visitElement(PsiElement element)
                {
                    super.visitElement(element);
                    if(element instanceof DotNetTypeDeclaration)
                    {
                        set.add(((DotNetTypeDeclaration) element).getVmQName());
                    }
                }
            });
            return set;
        }
    });
}
项目:consulo-apache-velocity    文件:ProviderBuilder.java   
CachedValueProvider<Map<String, Set<VtlMacro>>> createAllMacrosProvider()
{
    return new CachedValueProvider<Map<String, Set<VtlMacro>>>()
    {
        public CachedValueProvider.Result<Map<String, Set<VtlMacro>>> compute()
        {
            final Map<String, Set<VtlMacro>> result = new THashMap<String, Set<VtlMacro>>();
            myFile.accept(new PsiRecursiveElementVisitor()
            {
                @Override
                public void visitElement(PsiElement element)
                {
                    super.visitElement(element);
                    if(element instanceof VtlMacro)
                    {
                        registerMacro((VtlMacro) element, result);
                    }
                }
            });
            return CachedValueProvider.Result.create(result, myFile);
        }
    };
}
项目:idea-php-dotenv-plugin    文件:DotEnvLightCodeInsightFixtureTestCase.java   
@NotNull
private List<PsiElement> collectPsiElementsRecursive(@NotNull PsiElement psiElement) {
    final List<PsiElement> elements = new ArrayList<PsiElement>();
    elements.add(psiElement.getContainingFile());

    psiElement.acceptChildren(new PsiRecursiveElementVisitor() {
        @Override
        public void visitElement(PsiElement element) {
            elements.add(element);
            super.visitElement(element);
        }
    });
    return elements;
}
项目:idea-php-behat-plugin    文件:BehatLightCodeInsightFixtureTestCase.java   
@NotNull
private List<PsiElement> collectPsiElementsRecursive(@NotNull PsiElement psiElement) {
    final List<PsiElement> elements = new ArrayList<PsiElement>();
    elements.add(psiElement.getContainingFile());

    psiElement.acceptChildren(new PsiRecursiveElementVisitor() {
        @Override
        public void visitElement(PsiElement element) {
            elements.add(element);
            super.visitElement(element);
        }
    });
    return elements;
}
项目:dotplugin    文件:DotPSITreeUtil.java   
/**
 * Utility method returning all children nodes which have are mentioned in
 * edge statements but not mentioned in node statements.
 * Case when node is used in edge but not initialized earlier
 *
 * @param e - PSI element (root element for sub tree for searching nodes)
 * @return - iterable entity containing used but mentioned nodes
 */
// TODO: probably it makes sense to change PsiElement to GraphStmt
public static Iterable<DotId> getNotMentionedNodeIds(PsiElement e) {
    Set<DotId> nodeIds = new HashSet<>();
    Set<DotId> edgeIds = new HashSet<>();
    Set<DotId> result = new HashSet<>();
    PsiRecursiveElementVisitor psiRecursiveElementVisitor = new PsiRecursiveElementVisitor() {
        @Override
        public void visitElement(PsiElement element) {
            if (element instanceof DotNodeStmt) {
                nodeIds.add(((DotNodeStmt) element).getNodeId().getId());
            } else if (element instanceof DotEdgeStmt) {
                edgeIds.add(((DotEdgeStmt) element).getNodeId().getId());
                edgeIds.add(((DotEdgeStmt) element).getEdgeRHS().getNodeId().getId());
            }
            super.visitElement(element);
        }
    };
    psiRecursiveElementVisitor.visitElement(e);

    for (DotId edgeId : edgeIds) {
        if (nodeIds.stream().noneMatch((i) -> edgeId.getText().equals(i.getText()))) {
            result.add(edgeId);
        }
    }
    return result;
}
项目:js-graphql-intellij-plugin    文件:JSGraphQLCompletionContributor.java   
private List<JSGraphQLFragmentDefinitionPsiElement> getFragmentDefinitions(PsiFile file) {
    List<JSGraphQLFragmentDefinitionPsiElement> ret = Lists.newArrayList();
    file.accept(new PsiRecursiveElementVisitor() {
        @Override
        public void visitElement(PsiElement element) {
            if(element instanceof JSGraphQLFragmentDefinitionPsiElement) {
                ret.add((JSGraphQLFragmentDefinitionPsiElement) element);
            } else {
                super.visitElement(element);
            }
        }
    });
    return ret;
}
项目:js-graphql-intellij-plugin    文件:JSGraphQLEndpointErrorAnnotator.java   
/**
 * Compares the signatures of two fields, ignoring comments, whitespace, and annotations
 */
private boolean hasSameSignature(JSGraphQLEndpointFieldDefinition override, JSGraphQLEndpointFieldDefinition toImplement) {
    final StringBuilder toImplementSignature = new StringBuilder();
    final StringBuilder overrideSignature = new StringBuilder();

    final Ref<StringBuilder> sb = new Ref<>();
    final PsiElementVisitor visitor = new PsiRecursiveElementVisitor() {
        @Override
        public void visitElement(PsiElement element) {
            if (element instanceof JSGraphQLEndpointAnnotation) {
                return;
            }
            if (element instanceof PsiWhiteSpace) {
                return;
            }
            if (element instanceof PsiComment) {
                return;
            }
            if (element instanceof LeafPsiElement) {
                sb.get().append(element.getText()).append(" ");
            }
            super.visitElement(element);
        }
    };

    sb.set(overrideSignature);
    override.accept(visitor);

    sb.set(toImplementSignature);
    toImplement.accept(visitor);

    return toImplementSignature.toString().equals(overrideSignature.toString());
}
项目:idea-php-laravel-plugin    文件:LaravelDicUtil.java   
public static void visitRegisterCoreContainerAliases(@NotNull Project project, @NotNull DicAliasVisitor visitor) {
    for (PhpClass phpClass : PhpElementsUtil.getClassesOrInterfaces(project, "Illuminate\\Foundation\\Application")) {
        Method registerMethod = phpClass.findMethodByName("registerCoreContainerAliases");
        if(registerMethod == null) {
            continue;
        }

        final Collection<Variable> aliases = new HashSet<>();
        registerMethod.acceptChildren(new PsiRecursiveElementVisitor() {
            @Override
            public void visitElement(PsiElement element) {
                if(element instanceof Variable && ((Variable) element).isDeclaration() && "aliases".equals(((Variable) element).getName())) {
                    aliases.add((Variable) element);
                }
                super.visitElement(element);
            }
        });

        if(aliases.size() == 0) {
            continue;
        }

        for (Variable alias : aliases) {
            ArrayCreationExpression arrayCreation = PsiTreeUtil.getNextSiblingOfType(alias, ArrayCreationExpression.class);
            if(arrayCreation == null) {
                continue;
            }

            Map<String, PsiElement> arrayCreationKeyMap = PhpElementsUtil.getArrayValueMap(arrayCreation);
            for (Map.Entry<String, PsiElement> entry : arrayCreationKeyMap.entrySet()) {
                PsiElement value = entry.getValue();
                visitor.visit(value, entry.getKey());
            }

        }

    }
}
项目:idea-php-laravel-plugin    文件:BladeEachStubIndex.java   
@NotNull
@Override
public DataIndexer<String, Void, FileContent> getIndexer() {
    return fileContent -> {
        final Map<String, Void> map = new THashMap<>();
        PsiFile psiFile = fileContent.getPsiFile();

        if(!(psiFile instanceof BladeFileImpl)) {
            return map;
        }

        psiFile.acceptChildren(new PsiRecursiveElementVisitor() {
            @Override
            public void visitElement(PsiElement element) {
                if(!(element instanceof BladePsiDirectiveParameter)) {
                    super.visitElement(element);
                    return;
                }

                for (String s : BladePsiUtil.getEachDirectiveTemplateParameter((BladePsiDirectiveParameter) element)) {
                    map.put(s, null);
                }
            }
        });

        return map;
    };
}
项目:idea-php-laravel-plugin    文件:LaravelLightCodeInsightFixtureTestCase.java   
@NotNull
private List<PsiElement> collectPsiElementsRecursive(@NotNull PsiElement psiElement) {
    final List<PsiElement> elements = new ArrayList<PsiElement>();
    elements.add(psiElement.getContainingFile());

    psiElement.acceptChildren(new PsiRecursiveElementVisitor() {
        @Override
        public void visitElement(PsiElement element) {
            elements.add(element);
            super.visitElement(element);
        }
    });
    return elements;
}
项目:idea-php-shopware-plugin    文件:HookSubscriberUtil.java   
public static void visitSubscriberEvents(@NotNull Method method, @NotNull SubscriberEventsVisitor visitor) {
    method.acceptChildren(new PsiRecursiveElementVisitor() {
        @Override
        public void visitElement(PsiElement element) {
            if(element instanceof PhpReturn) {
                visitSubscriberEvents((PhpReturn) element, visitor);
            }
            super.visitElement(element);
        }
    });
}
项目:idea-php-shopware-plugin    文件:SnippetUtil.java   
/**
 * {s name="foobar" namespace ="foobar/foobar"}{/s}
 */
private static void visitSnippets(@NotNull SmartyFile file, @NotNull Consumer<ShopwareSnippet> consumer) {
    LazySmartyFileNamespace lazyFileNamespace = new LazySmartyFileNamespace(file);

    file.acceptChildren(new PsiRecursiveElementVisitor() {
        @Override
        public void visitElement(PsiElement element) {
            if(!SmartyPattern.getTagAttributePattern("s", "name").accepts(element)) {
                super.visitElement(element);
                return;
            }

            String text = element.getText();
            if(StringUtils.isBlank(text)) {
                super.visitElement(element);
                return;
            }

            PsiElement parent = element.getParent();
            String namespace = TemplateUtil.getTagAttributeValueByName((SmartyTag) parent, "namespace");
            if(namespace == null) {
                namespace = lazyFileNamespace.getNamespace();
            }

            if(namespace != null) {
                consumer.accept(new ShopwareSnippet(element, namespace, text));
            }

            super.visitElement(element);
        }
    });
}
项目:tools-idea    文件:DependenciesVisitorFactory.java   
public PsiElementVisitor createVisitor(final DependenciesBuilder.DependencyProcessor processor) {
  return new PsiRecursiveElementVisitor() {
    @Override
    public void visitElement(PsiElement element) {
      super.visitElement(element);
      PsiReference[] refs = element.getReferences();
      for (PsiReference ref : refs) {
        PsiElement resolved = ref.resolve();
        if (resolved != null) {
          processor.process(ref.getElement(), resolved);
        }
      }
    }
  };
}
项目:consulo-csharp    文件:CSharpUsingHighlightUsagesHandler.java   
@Override
public List<PsiElement> getTargets()
{
    final OurVisitor visitor = new OurVisitor(myListChild);
    myFile.accept(new PsiRecursiveElementVisitor()
    {
        @Override
        public void visitElement(PsiElement element)
        {
            element.accept(visitor);
            super.visitElement(element);
        }
    });
    return visitor.getElements();
}
项目:idea-php-symfony2-plugin    文件:CaseSensitivityServiceInspection.java   
private void yamlVisitor(final @NotNull ProblemsHolder holder, @NotNull PsiFile psiFile) {

        // usage in service arguments or every other service condition
        psiFile.acceptChildren(new PsiRecursiveElementVisitor() {
            @Override
            public void visitElement(PsiElement psiElement) {

                // @TODO: support key itself
                if (YamlElementPatternHelper.getServiceDefinition().accepts(psiElement) && YamlElementPatternHelper.getInsideServiceKeyPattern().accepts(psiElement)) {
                    // @foo, @=foo, @?foo
                    String serviceText = PsiElementUtils.trimQuote(psiElement.getText());
                    if (isValidService(serviceText)) {
                        String serviceName = YamlHelper.trimSpecialSyntaxServiceName(serviceText);

                        // dont mark "@", "@?", "@@" escaping and expressions
                        if (StringUtils.isNotBlank(serviceName) && !serviceName.equals(serviceName.toLowerCase()) && !YamlHelper.isClassServiceId(serviceName)) {
                            holder.registerProblem(psiElement, SYMFONY_LOWERCASE_LETTERS_FOR_SERVICE, ProblemHighlightType.WEAK_WARNING);
                        }
                    }
                }

                super.visitElement(psiElement);
            }
        });

        // services and parameter
        YamlHelper.processKeysAfterRoot(psiFile, yamlKeyValue -> {
            String keyText = yamlKeyValue.getKeyText();
            if(StringUtils.isNotBlank(keyText) && !keyText.equals(keyText.toLowerCase()) && !YamlHelper.isClassServiceId(keyText)) {
                PsiElement firstChild = yamlKeyValue.getFirstChild();
                if(firstChild != null) {
                    holder.registerProblem(firstChild, SYMFONY_LOWERCASE_LETTERS_FOR_SERVICE, ProblemHighlightType.WEAK_WARNING);
                }
            }

            return false;
        }, "services", "parameters");
    }
项目:idea-php-symfony2-plugin    文件:CaseSensitivityServiceInspection.java   
private void xmlVisitor(final @NotNull ProblemsHolder holder, @NotNull PsiFile psiFile) {
    psiFile.acceptChildren(new PsiRecursiveElementVisitor() {
        @Override
        public void visitElement(PsiElement psiElement) {
            if(psiElement instanceof XmlAttributeValue && (XmlHelper.getArgumentServiceIdPattern().accepts(psiElement) || XmlHelper.getServiceIdAttributePattern().accepts(psiElement))) {
                String serviceName = ((XmlAttributeValue) psiElement).getValue();
                if(StringUtils.isNotBlank(serviceName) && !serviceName.equals(serviceName.toLowerCase()) && !YamlHelper.isClassServiceId(serviceName)) {
                    holder.registerProblem(psiElement, SYMFONY_LOWERCASE_LETTERS_FOR_SERVICE, ProblemHighlightType.WEAK_WARNING);
                }
            }

            super.visitElement(psiElement);
        }
    });
}
项目:idea-php-symfony2-plugin    文件:ContainerConstantInspection.java   
private void xmlVisitor(@NotNull ProblemsHolder holder, @NotNull PsiFile psiFile) {
    psiFile.acceptChildren(new PsiRecursiveElementVisitor() {
        @Override
        public void visitElement(PsiElement psiElement) {
            if(!XmlHelper.getArgumentValueWithTypePattern("constant").accepts(psiElement)) {
                super.visitElement(psiElement);
                return;
            }

            PsiElement xmlText = psiElement.getParent();
            if(!(xmlText instanceof XmlText)) {
                super.visitElement(psiElement);
                return;
            }

            String value = ((XmlText) xmlText).getValue();
            if(StringUtils.isBlank(value)) {
                super.visitElement(psiElement);
                return;
            }

            if(ServiceContainerUtil.getTargetsForConstant(xmlText.getProject(), value).size() == 0) {
                holder.registerProblem(xmlText, MESSAGE, ProblemHighlightType.GENERIC_ERROR_OR_WARNING);
            }

            super.visitElement(psiElement);
        }
    });
}
项目:consulo-dotnet    文件:DotNetCoverageEngine.java   
@Nullable
@Override
public String getQualifiedName(@NotNull File outputFile, @NotNull final PsiFile sourceFile)
{

    return ApplicationManager.getApplication().runReadAction(new Computable<String>()
    {
        @Override
        public String compute()
        {
            final Ref<String> ref = Ref.create();
            sourceFile.accept(new PsiRecursiveElementVisitor()
            {
                @Override
                public void visitElement(PsiElement element)
                {
                    super.visitElement(element);
                    if(element instanceof DotNetTypeDeclaration)
                    {
                        ref.set(((DotNetTypeDeclaration) element).getVmQName());
                    }
                }
            });
            return ref.get();
        }
    });
}
项目:consulo    文件:DependenciesVisitorFactory.java   
public PsiElementVisitor createVisitor(final DependenciesBuilder.DependencyProcessor processor) {
  return new PsiRecursiveElementVisitor() {
    @Override
    public void visitElement(PsiElement element) {
      super.visitElement(element);
      PsiReference[] refs = element.getReferences();
      for (PsiReference ref : refs) {
        PsiElement resolved = ref.resolve();
        if (resolved != null) {
          processor.process(ref.getElement(), resolved);
        }
      }
    }
  };
}
项目:consulo-apache-velocity    文件:ProviderBuilder.java   
public CachedValueProvider<Collection<VtlFileProxy>> createMacroLibrariesProvider()
{
    return new CachedValueProvider<Collection<VtlFileProxy>>()
    {
        public CachedValueProvider.Result<Collection<VtlFileProxy>> compute()
        {
            final Collection<VtlFileProxy> result = new THashSet<VtlFileProxy>();
            myFile.accept(new PsiRecursiveElementVisitor()
            {
                @Override
                public void visitComment(PsiComment comment)
                {
                    final String text = comment.getText();
                    String[] pathAndScopeFilePath = VtlFile.findMacroLibraryPathAndScopeFilePath(text);
                    if(pathAndScopeFilePath == null)
                    {
                        return;
                    }
                    VtlFile libraryFile = findVtlFile(comment, text, pathAndScopeFilePath[0]);
                    if(libraryFile == null)
                    {
                        return;
                    }
                    VtlFile scopeFile = findVtlFile(comment, text, pathAndScopeFilePath[1]);
                    if(pathAndScopeFilePath[1] == null || scopeFile != null)
                    {
                        result.add(new VtlFileProxy(libraryFile, scopeFile));
                    }
                }
            });
            return CachedValueProvider.Result.create(result, myFile);
        }
    };
}
项目:otto-intellij-plugin    文件:OttoProjectHandler.java   
private void maybeRecomputeEventClasses() {
  List<VirtualFile> myFilesToScan;
  synchronized (filesToScan) {
    if (filesToScan.isEmpty()) return;

    myFilesToScan = new ArrayList<VirtualFile>(filesToScan);
    filesToScan.clear();
  }

  for (VirtualFile virtualFile : myFilesToScan) {
    synchronized (fileToEventClasses) {
      getEventClasses(virtualFile).clear();
    }
    PsiFile psiFile = PsiManager.getInstance(myProject).findFile(virtualFile);
    if (psiFile == null) throw new IllegalStateException("huh? " + virtualFile);
    if (psiFile.getFileType() instanceof JavaFileType) {

      final long startTime = System.currentTimeMillis();
      psiFile.accept(new PsiRecursiveElementVisitor() {
        @Override public void visitElement(PsiElement element) {
          if (element instanceof PsiMethod
              && SubscriberMetadata.isAnnotatedWithSubscriber((PsiMethod) element)) {
            maybeAddSubscriberMethod((PsiMethod) element);
          } else {
            super.visitElement(element);
          }
        }
      });
      if (LOGGER.isDebugEnabled()) {
        LOGGER.debug(String.format("Searched for @Subscribe in %s in %dms",
            virtualFile, System.currentTimeMillis() - startTime));
      }
    }
  }

  optimizeEventClassIndex();
}
项目:js-graphql-intellij-plugin    文件:JSGraphQLEndpointDefinitionsSearchExecutor.java   
private static boolean doExecute(PsiElement sourceElement, final Processor<PsiElement> consumer) {

        // must be an interface definition with a named type to be applicable
        final Ref<JSGraphQLEndpointNamedTypeDef> sourceNamedTypeDef = new Ref<>();
        final Ref<JSGraphQLEndpointProperty> sourceProperty = new Ref<>();
        final Ref<JSGraphQLEndpointInterfaceTypeDefinition> sourceInterfaceDefinition = new Ref<>();

        if (sourceElement instanceof JSGraphQLEndpointNamedTypeDef) {
            sourceNamedTypeDef.set((JSGraphQLEndpointNamedTypeDef) sourceElement);
            sourceInterfaceDefinition.set(PsiTreeUtil.getParentOfType(sourceNamedTypeDef.get(), JSGraphQLEndpointInterfaceTypeDefinition.class));
        } else if (sourceElement instanceof JSGraphQLEndpointProperty) {
            sourceProperty.set((JSGraphQLEndpointProperty) sourceElement);
            sourceInterfaceDefinition.set(PsiTreeUtil.getParentOfType(sourceProperty.get(), JSGraphQLEndpointInterfaceTypeDefinition.class));
            if (sourceInterfaceDefinition.get() != null) {
                sourceNamedTypeDef.set(sourceInterfaceDefinition.get().getNamedTypeDef());
            }
        }

        if (sourceNamedTypeDef.get() != null && sourceInterfaceDefinition.get() != null) {

            final String interfaceName = sourceNamedTypeDef.get().getText();

            final JSGraphQLEndpointNamedTypeRegistry typeRegistry = JSGraphQLEndpointNamedTypeRegistry.getService(sourceElement.getProject());
            typeRegistry.enumerateTypes(jsGraphQLNamedType -> {
                if (jsGraphQLNamedType.definitionElement instanceof JSGraphQLEndpointObjectTypeDefinition) {
                    final JSGraphQLEndpointObjectTypeDefinition typeDefinition = (JSGraphQLEndpointObjectTypeDefinition) jsGraphQLNamedType.definitionElement;
                    final JSGraphQLEndpointImplementsInterfaces implementsInterfaces = typeDefinition.getImplementsInterfaces();
                    if (implementsInterfaces != null) {
                        for (JSGraphQLEndpointNamedType namedType : implementsInterfaces.getNamedTypeList()) {
                            if (interfaceName.equals(namedType.getName())) {
                                if (sourceProperty.get() == null) {
                                    // type implements the interface
                                    consumer.process(typeDefinition.getNamedTypeDef());
                                } else {
                                    // locate field overrides
                                    final String propertyName = sourceProperty.get().getName();
                                    jsGraphQLNamedType.definitionElement.accept(new PsiRecursiveElementVisitor() {
                                        @Override
                                        public void visitElement(PsiElement element) {
                                            if (element instanceof JSGraphQLEndpointProperty) {
                                                if ((Objects.equals(propertyName, ((JSGraphQLEndpointProperty) element).getName()))) {
                                                    consumer.process(element);
                                                }
                                                return; // don't visit deeper than properties
                                            }
                                            super.visitElement(element);
                                        }
                                    });
                                }
                                break;
                            }
                        }
                    }
                }
            });


        }
        return true;
    }
项目:idea-php-laravel-plugin    文件:LaravelDicUtil.java   
public static Map<String, Collection<String>> getServiceProviderMap(@NotNull Project project) {

        Map<String, Collection<String>> map = new HashMap<>();

        for (PhpClass phpClass : PhpIndex.getInstance(project).getAllSubclasses("\\Illuminate\\Support\\ServiceProvider")) {

            Collection<MethodReference> methodReferences = new ArrayList<>();

            for (Method method : phpClass.getMethods()) {
                method.acceptChildren(new AppDicRecursiveElementVisitor(methodReferences));
            }

            if(methodReferences.size() == 0) {
                continue;
            }

            for (MethodReference methodReference : methodReferences) {

                PsiElement[] parameters = methodReference.getParameters();
                if(parameters.length < 2 || !(parameters[0] instanceof StringLiteralExpression) || parameters[1].getNode().getElementType() != PhpElementTypes.CLOSURE) {
                    continue;
                }

                String dicName = ((StringLiteralExpression) parameters[0]).getContents();
                if(StringUtils.isBlank(dicName)) {
                    continue;
                }

                final Set<String> types = new HashSet<>();

                parameters[1].acceptChildren(new PsiRecursiveElementVisitor() {
                    @Override
                    public void visitElement(PsiElement element) {
                        if(element instanceof PhpReturn) {
                            PhpPsiElement firstPsiChild = ((PhpReturn) element).getFirstPsiChild();
                            if(firstPsiChild instanceof PhpTypedElement) {
                                for (String s : ((PhpTypedElement) firstPsiChild).getType().getTypes()) {
                                    if(s.startsWith("#")) {
                                        continue;
                                    }
                                    types.add(StringUtils.stripStart(s, "\\"));
                                }
                            }
                        }
                        super.visitElement(element);
                    }
                });

                map.put(dicName, types);
            }

        }

        return map;
    }
项目:tools-idea    文件:BackwardDependenciesBuilder.java   
@Override
public void analyze() {
  AnalysisScope scope = myForwardScope;
  final DependenciesBuilder builder = new ForwardDependenciesBuilder(getProject(), scope, getScopeOfInterest());
  builder.setTotalFileCount(myTotalFileCount);
  builder.analyze();

  subtractScope(builder, getScope());
  final PsiManager psiManager = PsiManager.getInstance(getProject());
  psiManager.startBatchFilesProcessingMode();
  try {
    final int fileCount = getScope().getFileCount();
    getScope().accept(new PsiRecursiveElementVisitor() {
      @Override public void visitFile(final PsiFile file) {
        ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
        if (indicator != null) {
          if (indicator.isCanceled()) {
            throw new ProcessCanceledException();
          }
          indicator.setText(AnalysisScopeBundle.message("package.dependencies.progress.text"));
          final VirtualFile virtualFile = file.getVirtualFile();
          if (virtualFile != null) {
            indicator.setText2(getRelativeToProjectPath(virtualFile));
          }
          if (fileCount > 0) {
            indicator.setFraction(((double)++myFileCount) / myTotalFileCount);
          }
        }
        final Map<PsiFile, Set<PsiFile>> dependencies = builder.getDependencies();
        for (final PsiFile psiFile : dependencies.keySet()) {
          if (dependencies.get(psiFile).contains(file)) {
            Set<PsiFile> fileDeps = getDependencies().get(file);
            if (fileDeps == null) {
              fileDeps = new HashSet<PsiFile>();
              getDependencies().put(file, fileDeps);
            }
            fileDeps.add(psiFile);
          }
        }
        psiManager.dropResolveCaches();
        InjectedLanguageManager.getInstance(file.getProject()).dropFileCaches(file);
      }
    });
  }
  finally {
    psiManager.finishBatchFilesProcessingMode();
  }
}
项目:consulo    文件:BackwardDependenciesBuilder.java   
@Override
public void analyze() {
  AnalysisScope scope = myForwardScope;
  final DependenciesBuilder builder = new ForwardDependenciesBuilder(getProject(), scope, getScopeOfInterest());
  builder.setTotalFileCount(myTotalFileCount);
  builder.analyze();

  subtractScope(builder, getScope());
  final PsiManager psiManager = PsiManager.getInstance(getProject());
  psiManager.startBatchFilesProcessingMode();
  try {
    final int fileCount = getScope().getFileCount();
    getScope().accept(new PsiRecursiveElementVisitor() {
      @Override public void visitFile(final PsiFile file) {
        ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
        if (indicator != null) {
          if (indicator.isCanceled()) {
            throw new ProcessCanceledException();
          }
          indicator.setText(AnalysisScopeBundle.message("package.dependencies.progress.text"));
          final VirtualFile virtualFile = file.getVirtualFile();
          if (virtualFile != null) {
            indicator.setText2(ProjectUtil.calcRelativeToProjectPath(virtualFile, getProject()));
          }
          if (fileCount > 0) {
            indicator.setFraction(((double)++myFileCount) / myTotalFileCount);
          }
        }
        final Map<PsiFile, Set<PsiFile>> dependencies = builder.getDependencies();
        for (final PsiFile psiFile : dependencies.keySet()) {
          if (dependencies.get(psiFile).contains(file)) {
            Set<PsiFile> fileDeps = getDependencies().get(file);
            if (fileDeps == null) {
              fileDeps = new HashSet<PsiFile>();
              getDependencies().put(file, fileDeps);
            }
            fileDeps.add(psiFile);
          }
        }
        psiManager.dropResolveCaches();
        InjectedLanguageManager.getInstance(file.getProject()).dropFileCaches(file);
      }
    });
  }
  finally {
    psiManager.finishBatchFilesProcessingMode();
  }
}
项目:consulo-xml    文件:DtdReferencesProvider.java   
@Override
@NotNull
public PsiReference[] getReferencesByElement(@NotNull final PsiElement element, @NotNull final ProcessingContext context)
{
    XmlElement nameElement = null;

    if(element instanceof XmlDoctype)
    {
        nameElement = ((XmlDoctype) element).getNameElement();
    }
    else if(element instanceof XmlElementDecl)
    {
        nameElement = ((XmlElementDecl) element).getNameElement();
    }
    else if(element instanceof XmlAttlistDecl)
    {
        nameElement = ((XmlAttlistDecl) element).getNameElement();
    }
    else if(element instanceof XmlElementContentSpec)
    {
        final List<PsiReference> psiRefs = new ArrayList<>();
        element.accept(new PsiRecursiveElementVisitor()
        {
            @Override
            public void visitElement(PsiElement child)
            {
                if(child instanceof XmlToken && ((XmlToken) child).getTokenType() == XmlTokenType.XML_NAME)
                {
                    psiRefs.add(new ElementReference((XmlElement) element, (XmlElement) child));
                }
                super.visitElement(child);
            }
        });
        return psiRefs.toArray(new PsiReference[psiRefs.size()]);
    }

    if(nameElement != null)
    {
        return new PsiReference[]{new ElementReference((XmlElement) element, nameElement)};
    }

    if(element instanceof XmlEntityRef || (element instanceof XmlToken && ((XmlToken) element).getTokenType() == XmlTokenType.XML_CHAR_ENTITY_REF))
    {
        return new PsiReference[]{new EntityReference(element)};
    }

    return PsiReference.EMPTY_ARRAY;
}
项目:consulo-apache-velocity    文件:ProviderBuilder.java   
public CachedValueProvider<VelocityPropertiesProvider> createVelocityPropertiesProvider()
{
    return new CachedValueProvider<VelocityPropertiesProvider>()
    {
        public CachedValueProvider.Result<VelocityPropertiesProvider> compute()
        {
            final Set dependencies = new HashSet(3);
            final Ref<VelocityPropertiesProvider> result = new Ref<VelocityPropertiesProvider>();

            PsiRecursiveElementVisitor visitor = new PsiRecursiveElementVisitor()
            {

                @Override
                public void visitFile(PsiFile file)
                {
                    dependencies.add(file);
                    super.visitFile(file);
                }

                @Override
                public void visitComment(PsiComment comment)
                {
                    if(result.get() != null)
                    {
                        return;
                    }
                    final String text = comment.getText();
                    String[] velocityPropertiesPathAndScopeFilePath = VtlFile.findVelocityPropertiesPathAndScopeFilePath(text);
                    if(velocityPropertiesPathAndScopeFilePath == null)
                    {
                        return;
                    }
                    VtlFile scopeFile = findVtlFile(comment, text, velocityPropertiesPathAndScopeFilePath[2]);
                    if(velocityPropertiesPathAndScopeFilePath[2] != null && (scopeFile == null || !isOriginalEquivalent(myFile, scopeFile)))
                    {
                        return;
                    }
                    PsiFile psiFile = findFile(comment, text, velocityPropertiesPathAndScopeFilePath[0], PsiFile.class);
                    if(psiFile instanceof PropertiesFile)
                    {
                        dependencies.add(psiFile);
                        VirtualFile runtimeRoot = findRuntimeRoot(comment.getContainingFile(), velocityPropertiesPathAndScopeFilePath[1]);
                        result.set(new VelocityPropertiesProvider((PropertiesFile)psiFile, runtimeRoot));
                    }
                }
            }; myFile.accept(visitor);
            if(result.get() == null)
            {
                final Collection<VtlFile> implicitlyIncludedFiles = VtlFileIndex.getImplicitlyIncludedFiles(myFile);
                if(implicitlyIncludedFiles.size() == 0)
                {
                    dependencies.add(PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT);
                }
                for(VtlFile implicitlyIncludedFile : implicitlyIncludedFiles)
                {
                    implicitlyIncludedFile.accept(visitor);
                    if(result.get() != null)
                    {
                        break;
                    }
                }
            }
            return CachedValueProvider.Result.create(result.get(), dependencies.toArray());
        }
    };
}