Java Code Examples for com.intellij.lang.folding.FoldingDescriptor#EMPTY
The following examples show how to use
com.intellij.lang.folding.FoldingDescriptor#EMPTY .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XQueryFoldingBuilder.java From intellij-xquery with Apache License 2.0 | 6 votes |
@NotNull @Override public FoldingDescriptor[] buildFoldRegions(@NotNull PsiElement root, @NotNull Document document, boolean quick) { if (!(root instanceof XQueryFile)) return FoldingDescriptor.EMPTY; XQueryFile file = (XQueryFile) root; List<FoldingDescriptor> descriptorList = new ArrayList<FoldingDescriptor>(); updateImportFoldingDescriptors(descriptorList, new ArrayList<XQueryPsiElement>(file.getModuleImports())); updateImportFoldingDescriptors(descriptorList, new ArrayList<XQueryPsiElement>(file.getNamespaceDeclarations())); for (XQueryFunctionDecl function : file.getFunctionDeclarations()) { final XQueryFunctionBody functionBody = function.getFunctionBody(); if (functionBody != null && functionBody.getTextLength() > 2) { descriptorList.add(new FoldingDescriptor(function, functionBody.getTextRange())); } } return descriptorList.toArray(new FoldingDescriptor[descriptorList.size()]); }
Example 2
Source File: TranslationFoldingBuilder.java From idea-php-typo3-plugin with MIT License | 5 votes |
@NotNull @Override public FoldingDescriptor[] buildFoldRegions(@NotNull PsiElement root, @NotNull Document document, boolean quick) { if (!TYPO3CMSProjectSettings.isEnabled(root) || !TYPO3CMSProjectSettings.getInstance(root.getProject()).translationEnableTextFolding) { return FoldingDescriptor.EMPTY; } FoldingGroup group = FoldingGroup.newGroup("TYPO3Translation"); List<FoldingDescriptor> descriptors = new ArrayList<>(); Collection<StringLiteralExpression> literalExpressions = PsiTreeUtil.findChildrenOfType(root, StringLiteralExpression.class); for (final StringLiteralExpression literalExpression : literalExpressions) { String value = literalExpression.getContents(); if (value.startsWith("LLL:")) { final String transResult = Translator.translateLLLString(literalExpression); if (transResult != null) { TextRange foldingRange = new TextRange(literalExpression.getTextRange().getStartOffset() + 1, literalExpression.getTextRange().getEndOffset() - 1); descriptors.add(new FoldingDescriptor(literalExpression.getNode(), foldingRange, group) { @Override public String getPlaceholderText() { return transResult; } }); } } } return descriptors.toArray(new FoldingDescriptor[0]); }
Example 3
Source File: NutzLocalizationFoldingBuilder.java From NutzCodeInsight with Apache License 2.0 | 5 votes |
@NotNull @Override public FoldingDescriptor[] buildFoldRegions(@NotNull PsiElement root, @NotNull Document document, boolean quick) { Project project = root.getProject(); String localizationPackage = NutzLocalUtil.getLocalizationPackage(project); if (null == localizationPackage) { return FoldingDescriptor.EMPTY; } List<FoldingDescriptor> descriptors = new ArrayList<>(); Collection<VirtualFile> propertiesFiles = FilenameIndex.getAllFilesByExt(project, "properties", GlobalSearchScope.projectScope(project)); Collection<PsiLiteralExpression> literalExpressions = PsiTreeUtil.findChildrenOfType(root, PsiLiteralExpression.class); for (final PsiLiteralExpression literalExpression : literalExpressions) { if (!NutzLocalUtil.isLocal(literalExpression)) { continue; } String key = literalExpression.getValue() instanceof String ? (String) literalExpression.getValue() : null; if (key != null) { final List<String> properties = NutzLocalUtil.findProperties(project, propertiesFiles, localizationPackage, key); TextRange textRange = new TextRange(literalExpression.getTextRange().getStartOffset() + 1, literalExpression.getTextRange().getEndOffset() - 1); String value; if (properties.size() == 1) { value = properties.get(0); } else if (properties.size() > 1) { value = properties.get(0) + "[该键值存在多个配置文件中!]"; } else { value = "国际化信息中不存在[" + key + "],使用时可能产生异常,请检查!"; } descriptors.add(new NutzLocalizationFoldingDescriptor(literalExpression.getNode(), textRange, value)); } } return descriptors.toArray(new FoldingDescriptor[descriptors.size()]); }
Example 4
Source File: BuildFileFoldingBuilder.java From intellij with Apache License 2.0 | 5 votes |
@Override public FoldingDescriptor[] buildFoldRegions(ASTNode node, Document document) { if (!enabled.getValue()) { return FoldingDescriptor.EMPTY; } List<FoldingDescriptor> descriptors = Lists.newArrayList(); addDescriptors(descriptors, node); return descriptors.toArray(FoldingDescriptor.EMPTY); }
Example 5
Source File: CSharpDocFoldingBuilder.java From consulo-csharp with Apache License 2.0 | 5 votes |
@RequiredReadAction @Nonnull @Override public FoldingDescriptor[] buildFoldRegions(@Nonnull PsiElement root, @Nonnull Document document, boolean quick) { // build by CSharpFoldingBuilder return FoldingDescriptor.EMPTY; }
Example 6
Source File: DefaultPropertyFoldingBuilder.java From litho with Apache License 2.0 | 4 votes |
@NotNull @Override public FoldingDescriptor[] buildFoldRegions( @NotNull PsiElement root, @NotNull Document document, boolean quick) { FoldingGroup group = FoldingGroup.newGroup(FOLDING_GROUP_NAME); final Map<String, PsiExpression> defaultProps = PsiTreeUtil.findChildrenOfType(root, PsiField.class).stream() .filter(LithoPluginUtils::isPropDefault) .filter(field -> field.getInitializer() != null) .collect(Collectors.toMap(PsiField::getName, PsiField::getInitializer)); if (defaultProps.isEmpty()) { return FoldingDescriptor.EMPTY; } return PsiTreeUtil.findChildrenOfType(root, PsiParameter.class).stream() .filter(LithoPluginUtils::isProp) .map( parameter -> { String name = parameter.getName(); if (name == null) { return null; } PsiExpression nameExpression = defaultProps.get(name); if (nameExpression == null) { return null; } PsiIdentifier nameIdentifier = parameter.getNameIdentifier(); if (nameIdentifier == null) { return null; } return new FoldingDescriptor( nameIdentifier.getNode(), nameIdentifier.getTextRange(), group) { @Override public String getPlaceholderText() { return name + ": " + nameExpression.getText(); } }; }) .filter(Objects::nonNull) .toArray(FoldingDescriptor[]::new); }