当前位置: 首页>>代码示例>>Java>>正文


Java PsiTreeUtil.findChildrenOfType方法代码示例

本文整理汇总了Java中com.intellij.psi.util.PsiTreeUtil.findChildrenOfType方法的典型用法代码示例。如果您正苦于以下问题:Java PsiTreeUtil.findChildrenOfType方法的具体用法?Java PsiTreeUtil.findChildrenOfType怎么用?Java PsiTreeUtil.findChildrenOfType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.intellij.psi.util.PsiTreeUtil的用法示例。


在下文中一共展示了PsiTreeUtil.findChildrenOfType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: generate

import com.intellij.psi.util.PsiTreeUtil; //导入方法依赖的package包/类
@Override
public Set<TSVarExpr> generate(Project project) {
    Set<TSVarExpr> items = new HashSet<>();
    //Search every file in the project
    Collection<VirtualFile> virtualFiles = FileBasedIndex.getInstance().getContainingFiles(FileTypeIndex.NAME, TSFileType.INSTANCE, GlobalSearchScope.projectScope(project));
    for (VirtualFile virtualFile : virtualFiles) {
        TSFile tsFile = (TSFile) PsiManager.getInstance(project).findFile(virtualFile);
        if (tsFile != null) {
            Collection<TSAssignExpr> assignments = PsiTreeUtil.findChildrenOfType(tsFile, TSAssignExpr.class);
            for (TSAssignExpr assignment : assignments) {
                PsiElement first = assignment.getFirstChild();
                if (!(first instanceof TSVarExpr))
                    continue;

                if (((TSVarExpr)first).isLocal())
                    continue;

                items.add((TSVarExpr) first);

            }
        }
        ProgressManager.progress("Loading Symbols");
    }
    return items;
}
 
开发者ID:CouleeApps,项目名称:TS-IJ,代码行数:26,代码来源:TSGlobalCachedListGenerator.java

示例2: buildFoldRegions

import com.intellij.psi.util.PsiTreeUtil; //导入方法依赖的package包/类
@NotNull
@Override
public FoldingDescriptor[] buildFoldRegions(@NotNull PsiElement root, @NotNull Document document, boolean quick) {
    FoldingGroup group = FoldingGroup.newGroup("TYPO3Route");

    List<FoldingDescriptor> descriptors = new ArrayList<>();
    Collection<StringLiteralExpression> literalExpressions = PsiTreeUtil.findChildrenOfType(root, StringLiteralExpression.class);

    for (final StringLiteralExpression literalExpression : literalExpressions) {
        for (PsiReference reference : literalExpression.getReferences()) {
            if (reference instanceof RouteReference) {
                String value = literalExpression.getContents();

                FoldingDescriptor descriptor = foldRouteReferenceString(reference, value, group);
                if (descriptor != null) {
                    descriptors.add(descriptor);
                }
            }
        }


    }

    return descriptors.toArray(new FoldingDescriptor[descriptors.size()]);
}
 
开发者ID:cedricziel,项目名称:idea-php-typo3-plugin,代码行数:26,代码来源:RouteFoldingBuilder.java

示例3: getNamespaceAliases

import com.intellij.psi.util.PsiTreeUtil; //导入方法依赖的package包/类
private static Map<String, String> getNamespaceAliases(PsiFile file) {
  Collection<SoyAliasBlock> aliasElements =
      PsiTreeUtil.findChildrenOfType(file, SoyAliasBlock.class);
  Map<String, String> aliases = new HashMap<>();
  aliasElements.forEach(
      alias -> {
        if (alias.getNamespaceIdentifier() != null) {
          String namespaceIdentifier = alias.getNamespaceIdentifier().getText();
          String aliasIdentifier;
          if (alias.getAliasIdentifier() != null) {
            aliasIdentifier = alias.getAliasIdentifier().getText();
          } else {
            String[] namespaceFragments = namespaceIdentifier.split("\\.");
            aliasIdentifier = namespaceFragments[namespaceFragments.length - 1];
          }

          // Adding dots to prevent in-token matching.
          aliases.put(namespaceIdentifier + ".", aliasIdentifier + ".");
        }
      });
  return aliases;
}
 
开发者ID:google,项目名称:bamboo-soy,代码行数:23,代码来源:TemplateNameUtils.java

示例4: testVariableReferences

import com.intellij.psi.util.PsiTreeUtil; //导入方法依赖的package包/类
public void testVariableReferences() throws Throwable {
  myFixture.configureByFiles("CompletionSource.soy");
  PsiElement container = PsiTreeUtil.findChildOfType(myFixture.getFile(), SoyMsgStatement.class);
  Collection<SoyVariableReferenceIdentifier> vars =
      PsiTreeUtil.findChildrenOfType(container, SoyVariableReferenceIdentifier.class);
  assertSize(3, vars);
  for (SoyVariableReferenceIdentifier var : vars) {
    Class expectedClass;
    if (var.getText().equals("$planet")) {
      // @param
      expectedClass = SoyParamDefinitionIdentifier.class;
    } else if (var.getText().equals("$probe")) {
      // @inject
      expectedClass = SoyParamDefinitionIdentifier.class;
    } else {
      // {let}
      expectedClass = SoyVariableDefinitionIdentifier.class;
    }
    PsiElement id = var.getReference().resolve();
    assertInstanceOf(id, expectedClass);
  }
}
 
开发者ID:google,项目名称:bamboo-soy,代码行数:23,代码来源:SoyReferenceTest.java

示例5: addCompletions

import com.intellij.psi.util.PsiTreeUtil; //导入方法依赖的package包/类
@Override
protected void addCompletions(
    @NotNull final CompletionParameters parameters,
    final ProcessingContext context,
    @NotNull final CompletionResultSet result
) {
    final PsiFile originalFile = parameters.getOriginalFile();

    final Collection<ImpexMacroDeclaration> macroDeclarations = PsiTreeUtil.findChildrenOfType(
        originalFile, ImpexMacroDeclaration.class
    );

    if (macroDeclarations.isEmpty()) {
        return;
    }

    for (final ImpexMacroDeclaration macroDeclaration : macroDeclarations) {
        final PsiElement declaration = macroDeclaration.getFirstChild();
        result.addElement(LookupElementBuilder.create(declaration.getText())
                                              .withIcon(HybrisIcons.MACROS));
    }
}
 
开发者ID:AlexanderBartash,项目名称:hybris-integration-intellij-idea-plugin,代码行数:23,代码来源:ImpexMacrosCompletionProvider.java

示例6: getGotoDeclarationTarget

import com.intellij.psi.util.PsiTreeUtil; //导入方法依赖的package包/类
@Nullable
@Override
public PsiElement getGotoDeclarationTarget(final PsiElement sourceElement, final Editor editor) {
    if (!(sourceElement instanceof LeafPsiElement)
        || !(((LeafPsiElement) sourceElement)
                 .getElementType().equals(ImpexTypes.MACRO_USAGE))) {
        return null;
    }

    final PsiFile originalFile = sourceElement.getContainingFile();

    final Collection<ImpexMacroDeclaration> macroDeclarations =
        PsiTreeUtil.findChildrenOfType(
            originalFile,
            ImpexMacroDeclaration.class
        );

    if (!macroDeclarations.isEmpty()) {
        for (final ImpexMacroDeclaration declaration : macroDeclarations) {
            if (sourceElement.textMatches(declaration.getFirstChild())) {
                return declaration.getFirstChild();
            }
        }
    }
    return null;
}
 
开发者ID:AlexanderBartash,项目名称:hybris-integration-intellij-idea-plugin,代码行数:27,代码来源:ImpexMacrosGoToDeclarationHandler.java

示例7: multiResolve

import com.intellij.psi.util.PsiTreeUtil; //导入方法依赖的package包/类
@NotNull
@Override
public ResolveResult[] multiResolve(final boolean incompleteCode) {
    final PsiFile originalFile = getElement().getContainingFile();

    final Collection<ImpexMacroDeclaration> macroDeclarations =
        PsiTreeUtil.findChildrenOfType(
            originalFile,
            ImpexMacroDeclaration.class
        );

    if (!macroDeclarations.isEmpty()) {
        final ArrayList<PsiElement> references = ContainerUtil.newArrayList();
        for (final ImpexMacroDeclaration declaration : macroDeclarations) {
            if (getElement().textMatches(declaration.getFirstChild())) {
                references.add(declaration.getFirstChild());
            }
        }
        return PsiElementResolveResult.createResults(references);
    }
    return ResolveResult.EMPTY_ARRAY;
}
 
开发者ID:AlexanderBartash,项目名称:hybris-integration-intellij-idea-plugin,代码行数:23,代码来源:ImpexMacrosReferenceBase.java

示例8: setProcessParameters

import com.intellij.psi.util.PsiTreeUtil; //导入方法依赖的package包/类
@Override
protected void setProcessParameters(Project project, ApplicationConfiguration configuration, Module module, @NotNull VirtualFile testsFile) {
  configuration.setMainClassName(EduIntelliJNames.TEST_RUNNER_CLASS);
  configuration.setModule(module);
  PsiFile psiFile = PsiManager.getInstance(project).findFile(testsFile);
  Collection<KtClass> ktClasses = PsiTreeUtil.findChildrenOfType(psiFile, KtClass.class);
  for (KtClass ktClass : ktClasses) {
    String name = ktClass.getName();
    configuration.setProgramParameters(name);
  }
}
 
开发者ID:medvector,项目名称:educational-plugin,代码行数:12,代码来源:EduKotlinPyCharmTaskChecker.java

示例9: migrateColorToIntegerType

import com.intellij.psi.util.PsiTreeUtil; //导入方法依赖的package包/类
private void migrateColorToIntegerType(@NotNull PsiFile sketchFile, PsiElementFactory elementFactory) {
    Collection<PsiTypeElement> typeElementsInFile = PsiTreeUtil.findChildrenOfType(sketchFile, PsiTypeElement.class);

    for (PsiTypeElement typeElement : typeElementsInFile) {
        boolean isProcessingColorType = typeElement.getType().equalsToText("color");
        if (isProcessingColorType) {
            PsiTypeElement integerType = elementFactory.createTypeElementFromText("int", null);
            typeElement.replace(integerType);
        }
    }
}
 
开发者ID:mistodev,项目名称:processing-idea,代码行数:12,代码来源:ImportSketchClasses.java

示例10: buildFoldRegions

import com.intellij.psi.util.PsiTreeUtil; //导入方法依赖的package包/类
@NotNull
@Override
public FoldingDescriptor[] buildFoldRegions(@NotNull PsiElement psiElement, @NotNull Document document, boolean b) {
    List<FoldingDescriptor> descriptors = new ArrayList<>();
    Collection<OneScriptSubdeclaration> subs = PsiTreeUtil.findChildrenOfType(psiElement, OneScriptSubdeclaration.class);
    for (final OneScriptSubdeclaration sub : subs) {
        final String subName = sub.getSubName().getText();

        PsiElement endOfSub = sub.getNextSibling();
        while (endOfSub != null && !(endOfSub instanceof OneScriptEndOfSub)) {
            endOfSub = endOfSub.getNextSibling();
        }

        if (endOfSub == null) {
            continue;
        }

        TextRange r = new TextRange(sub.getTextRange().getStartOffset(), endOfSub.getTextRange().getEndOffset());
        FoldingDescriptor d = new FoldingDescriptor(sub.getNode(), r) {
            @Nullable
            @Override
            public String getPlaceholderText() {
                return subName;
            }
        };
        descriptors.add(d);
    }
    return descriptors.toArray(new FoldingDescriptor[descriptors.size()]);
}
 
开发者ID:dmpas,项目名称:idea-onescript,代码行数:30,代码来源:OneScriptFoldingBuilder.java

示例11: bindToElement

import com.intellij.psi.util.PsiTreeUtil; //导入方法依赖的package包/类
@Override
public PsiElement bindToElement(@NotNull PsiElement element) throws IncorrectOperationException {
    final StringLiteralExpression string = (StringLiteralExpression) this.getElement();
    final PsiDirectory context = ViewsUtil.getContextDirectory(string);
    final PsiFile file = (PsiFile) element;
    final PsiElement newValue;

    String fileName = string.getContents();
    if (fileName.contains("/")) {
        fileName = fileName.substring(fileName.lastIndexOf('/') + 1);
    }
    if (!file.getContainingDirectory().equals(context)) {
        final PsiDirectory root = ViewsUtil.getRootDirectory(string);
        if (root == null) {
            return null;
        }

        PsiDirectory dir = file.getContainingDirectory();
        while (dir != null && !(dir.equals(root) || dir.equals(context))) {
            fileName = dir.getName() + "/" + fileName;
            dir = dir.getParent();
        }

        if (dir == null) {
            return null;
        }

        if (dir.equals(root)) {
            fileName = "/" + fileName;
        }
    }
    fileName = string.isSingleQuote() ? "'" + fileName + "'" : "\"" + fileName + "\"";
    newValue = PhpPsiElementFactory.createFromText(element.getProject(), StringLiteralExpression.class, fileName);

    if (newValue != null) {
        string.replace(newValue);
    }

    for (MethodReference reference : PsiTreeUtil.findChildrenOfType(file, MethodReference.class)) {
        if (reference.getName() != null && ArrayUtil.contains(reference.getName(), ViewsUtil.renderMethods)) {
            reference.putUserData(ViewsUtil.RENDER_VIEW_FILE, null);
        }
    }

    return newValue;
}
 
开发者ID:nvlad,项目名称:yii2support,代码行数:47,代码来源:PsiReference.java

示例12: buildFoldRegions

import com.intellij.psi.util.PsiTreeUtil; //导入方法依赖的package包/类
@NotNull
@Override
public FoldingDescriptor[] buildFoldRegions(@NotNull PsiElement root, @NotNull Document document, boolean quick) {
    List<FoldingDescriptor> descriptors = new ArrayList<>();

    //Folding of block statements
    Collection<TSStmtBlock> blocks = PsiTreeUtil.findChildrenOfType(root, TSStmtBlock.class);
    for (final TSStmtBlock block : blocks) {
        if (!block.getFirstChild().getNode().getElementType().equals(TSTypes.BRACE_OPEN))
            continue;

        descriptors.add(new FoldingDescriptor(
                block.getNode(),
                new TextRange(block.getFirstChild().getTextOffset() + 1, block.getLastChild().getTextOffset()),
                null
        ) {
            @Override
            public String getPlaceholderText() {
                return "...";
            }
        });
    }

    //Function folding for the entire function
    Collection<TSFnDeclStmt> functions = PsiTreeUtil.findChildrenOfType(root, TSFnDeclStmt.class);
    for (final TSFnDeclStmt function : functions) {
        descriptors.add(new FoldingDescriptor(
                function.getNode(),
                //Entire function is the folded region, not just braces
                new TextRange(function.getFirstChild().getTextOffset(), function.getLastChild().getTextOffset() + function.getLastChild().getTextLength()),
                null
        ) {
            @Nullable
            @Override
            public String getPlaceholderText() {
                switch (function.getFunctionType()) {
                    case GLOBAL:
                        return "function " +  function.getFunctionName();
                    case GLOBAL_NS:
                        return "function " +  function.getNamespace() + "::" + function.getFunctionName();
                    case METHOD:
                        return "function " +  function.getNamespace() + "::" + function.getFunctionName();
                }
                return "function " +  function.getFunctionName();
            }
        });
    }

    //Function folding for the entire function
    Collection<TSPackageDecl> packages = PsiTreeUtil.findChildrenOfType(root, TSPackageDecl.class);
    for (final TSPackageDecl pkg : packages) {
        descriptors.add(new FoldingDescriptor(
                pkg.getNode(),
                //Entire pkg is the folded region, not just braces
                new TextRange(pkg.getFirstChild().getTextOffset(), pkg.getLastChild().getTextOffset() + pkg.getLastChild().getTextLength()),
                null
        ) {
            @Nullable
            @Override
            public String getPlaceholderText() {
                return "package " + pkg.getName();
            }
        });
    }



    return descriptors.toArray(new FoldingDescriptor[descriptors.size()]);
}
 
开发者ID:CouleeApps,项目名称:TS-IJ,代码行数:70,代码来源:TSFoldingBuilder.java

示例13: getLetExpressions

import com.intellij.psi.util.PsiTreeUtil; //导入方法依赖的package包/类
@Override
public Collection<PsiLet> getLetExpressions() {
    PsiScopedExpr body = getBody();
    return body == null ? Collections.emptyList() : PsiTreeUtil.findChildrenOfType(body, PsiLet.class);
}
 
开发者ID:reasonml-editor,项目名称:reasonml-idea-plugin,代码行数:6,代码来源:PsiModuleImpl.java

示例14: getTypeExpressions

import com.intellij.psi.util.PsiTreeUtil; //导入方法依赖的package包/类
@Override
public Collection<PsiType> getTypeExpressions() {
    PsiScopedExpr body = getBody();
    return body == null ? Collections.emptyList() : PsiTreeUtil.findChildrenOfType(body, PsiType.class);
}
 
开发者ID:reasonml-editor,项目名称:reasonml-idea-plugin,代码行数:6,代码来源:PsiModuleImpl.java

示例15: getLineExtensions

import com.intellij.psi.util.PsiTreeUtil; //导入方法依赖的package包/类
@Override
    public Collection<LineExtensionInfo> getLineExtensions(@NotNull Project project, @NotNull VirtualFile file, int lineNumber) {
        final Document document = FileDocumentManager.getInstance().getDocument(file);
        if (document == null) {
            return null;
        }

        Editor selectedTextEditor = FileEditorManager.getInstance(project).getSelectedTextEditor();
        if (selectedTextEditor == null) {
            return null;
        }

        PsiFile psiFile = PsiDocumentManager.getInstance(project).getPsiFile(document);
        LineNumbering lineNumbering = new LineNumbering(document.getCharsSequence());

        Collection<PsiLet> letStatements = PsiTreeUtil.findChildrenOfType(psiFile, PsiLet.class);

        String inferredType = null;
        for (PsiLet letStatement : letStatements) {
            int letOffset = letStatement.getTextOffset();
            // TODO: I'm using the LineNumbering class to avoid frequent exceptions about read access,
            // but I would prefer to use runReadAction method.
            MerlinPosition letPosition = lineNumbering.offsetToPosition(letOffset);
//            LogicalPosition letPosition = new LogicalPosition;
//            letPosition[0] = selectedTextEditor.offsetToLogicalPosition(letOffset);
            if (letPosition.line - 1 == lineNumber) {
                inferredType = letStatement.getInferredType();
                break;
            }
        }

/*
        Function<PsiLet, String> findInferredType = letStatement -> {
            // Found a let statement, try to get its type if in correct line number
            final int[] letOffset = new int[]{-1};
//            ApplicationManager.getApplication().runReadAction(() -> { // Freezing pb ?
                letOffset[0] = letStatement.getTextOffset();
//            });
            // TODO: I'm using the LineNumbering class to avoid frequent exceptions about read access,
            // but I would prefer to use runReadAction method.
            MerlinPosition letPosition = lineNumbering.offsetToPosition(letOffset[0]);
//            LogicalPosition letPosition = new LogicalPosition;
//            ApplicationManager.getApplication().runReadAction(() -> {
//                letPosition[0] = selectedTextEditor.offsetToLogicalPosition(letOffset);
//            });
            return letPosition.line - 1 == lineNumber ? letStatement.getInferredType() : null;
        };


        String inferredType;
        inferredType = letStatements.parallelStream().map(findInferredType).filter(Objects::nonNull).findFirst().orElse(null);
*/
        if (inferredType == null) {
            return null;
        }

        final TextAttributes attributes = getNormalAttributes();
        LineExtensionInfo info = new LineExtensionInfo("  " + inferredType, attributes);
        return Collections.singletonList(info);
    }
 
开发者ID:reasonml-editor,项目名称:reasonml-idea-plugin,代码行数:61,代码来源:RmlEditorLinePainter.java


注:本文中的com.intellij.psi.util.PsiTreeUtil.findChildrenOfType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。