Java Code Examples for com.intellij.lang.folding.FoldingDescriptor

The following examples show how to use com.intellij.lang.folding.FoldingDescriptor. These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: reasonml-idea-plugin   Source File: DuneFoldingBuilder.java    License: MIT License 6 votes vote down vote up
@NotNull
@Override
public FoldingDescriptor[] buildFoldRegions(@NotNull PsiElement root, @NotNull Document document, boolean quick) {
    List<FoldingDescriptor> descriptors = new ArrayList<>();

    PsiTreeUtil.processElements(root, element -> {
        if (isMultiline(element.getTextRange(), document)) {
            FoldingDescriptor fold = null;
            if (element instanceof PsiStanza) {
                fold = foldStanza((PsiStanza) element);
            } else if (DuneTypes.INSTANCE.C_SEXPR == element.getNode().getElementType()) {
                fold = fold(element);
            }
            if (fold != null) {
                descriptors.add(fold);
            }
        }

        return true;
    });

    return descriptors.toArray(new FoldingDescriptor[0]);
}
 
Example 2
Source Project: reasonml-idea-plugin   Source File: DuneFoldingBuilder.java    License: MIT License 6 votes vote down vote up
@Nullable
private FoldingDescriptor fold(@Nullable PsiElement root) {
    if (root == null) {
        return null;
    }

    // find next element
    ASTNode element = root.getFirstChild().getNode();
    ASTNode nextElement = element == null ? null : ORUtil.nextSiblingNode(element);
    ASTNode nextNextElement = nextElement == null ? null : ORUtil.nextSiblingNode(nextElement);

    if (nextNextElement != null) {
        TextRange rootRange = root.getTextRange();
        TextRange nextRange = nextElement.getTextRange();
        return new FoldingDescriptor(root, TextRange.create(nextRange.getEndOffset(), rootRange.getEndOffset() - 1));
    }

    return null;
}
 
Example 3
Source Project: idea-php-typo3-plugin   Source File: RouteFoldingBuilder.java    License: MIT License 6 votes vote down vote up
@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[0]);
}
 
Example 4
Source Project: consulo   Source File: DocumentFoldingInfo.java    License: Apache License 2.0 6 votes vote down vote up
@Nonnull
private static Map<PsiElement, FoldingDescriptor> buildRanges(@Nonnull Editor editor, @Nonnull PsiFile psiFile) {
  final FoldingBuilder foldingBuilder = LanguageFolding.INSTANCE.forLanguage(psiFile.getLanguage());
  final ASTNode node = psiFile.getNode();
  if (node == null) return Collections.emptyMap();
  final FoldingDescriptor[] descriptors = LanguageFolding.buildFoldingDescriptors(foldingBuilder, psiFile, editor.getDocument(), true);
  Map<PsiElement, FoldingDescriptor> ranges = new HashMap<>();
  for (FoldingDescriptor descriptor : descriptors) {
    final ASTNode ast = descriptor.getElement();
    final PsiElement psi = ast.getPsi();
    if (psi != null) {
      ranges.put(psi, descriptor);
    }
  }
  return ranges;
}
 
Example 5
Source Project: idea-php-symfony2-plugin   Source File: PhpFoldingBuilder.java    License: MIT License 6 votes vote down vote up
private void attachTemplateShortcuts(List<FoldingDescriptor> descriptors, final StringLiteralExpression stringLiteralExpression) {

        if (MethodMatcher.getMatchedSignatureWithDepth(stringLiteralExpression, SymfonyPhpReferenceContributor.TEMPLATE_SIGNATURES) == null) {
            return;
        }

        String content = stringLiteralExpression.getContents();

        String templateShortcutName = TwigUtil.getFoldingTemplateName(content);
        if(templateShortcutName == null) {
            return;
        }

        final String finalTemplateShortcutName = templateShortcutName;
        descriptors.add(new FoldingDescriptor(stringLiteralExpression.getNode(),
            new TextRange(stringLiteralExpression.getTextRange().getStartOffset() + 1, stringLiteralExpression.getTextRange().getEndOffset() - 1)) {
            @Nullable
            @Override
            public String getPlaceholderText() {
                return finalTemplateShortcutName;
            }
        });

    }
 
Example 6
private static void collectDescriptorsRecursively(@NotNull ASTNode node,
                                                  @NotNull Document document,
                                                  @NotNull List<FoldingDescriptor> descriptors) {
    final IElementType type = node.getElementType();
    if (type == token(COMMENT)
            && spanMultipleLines(node, document)) {
        descriptors.add(new FoldingDescriptor(node, node.getTextRange()));
    }
    if (type == token(LINE_COMMENT)) {
        final Couple<PsiElement> commentRange = expandLineCommentsRange(node.getPsi());
        final int startOffset = commentRange.getFirst().getTextRange().getStartOffset();
        final int endOffset = commentRange.getSecond().getTextRange().getEndOffset();
        if (document.getLineNumber(startOffset) != document.getLineNumber(endOffset)) {
            descriptors.add(new FoldingDescriptor(node, new TextRange(startOffset, endOffset)));
        }
    }
    if (PROVIDERS.keySet().contains(type)
            && spanMultipleLines(node, document)) {
        descriptors.add(new FoldingDescriptor(node, node.getTextRange()));
    }
    for (ASTNode child : node.getChildren(null)) {
        collectDescriptorsRecursively(child, document, descriptors);
    }
}
 
Example 7
Source Project: consulo   Source File: IndentationFoldingBuilder.java    License: Apache License 2.0 6 votes vote down vote up
@RequiredReadAction
private void collectDescriptors(@Nonnull final ASTNode node, @Nonnull final List<FoldingDescriptor> descriptors) {
  final Queue<ASTNode> toProcess = new LinkedList<ASTNode>();
  toProcess.add(node);
  while (!toProcess.isEmpty()) {
    final ASTNode current = toProcess.remove();
    if (current.getTreeParent() != null
        && current.getTextLength() > 1
        && myTokenSet.contains(current.getElementType()))
    {
      descriptors.add(new FoldingDescriptor(current, current.getTextRange()));
    }
    for (ASTNode child = current.getFirstChildNode(); child != null; child = child.getTreeNext()) {
      toProcess.add(child);
    }
  }
}
 
Example 8
Source Project: consulo   Source File: FoldingUpdate.java    License: Apache License 2.0 6 votes vote down vote up
private static void diagnoseIncorrectRange(@Nonnull PsiFile file, @Nonnull Document document, Language language, FoldingBuilder foldingBuilder, FoldingDescriptor descriptor, PsiElement psiElement) {
  String message = "Folding descriptor " +
                   descriptor +
                   " made by " +
                   foldingBuilder +
                   " for " +
                   language +
                   " is outside document range" +
                   ", PSI element: " +
                   psiElement +
                   ", PSI element range: " +
                   psiElement.getTextRange() +
                   "; " +
                   DebugUtil.diagnosePsiDocumentInconsistency(psiElement, document);
  LOG.error(message, ApplicationManager.getApplication().isInternal() ? new Attachment[]{AttachmentFactory.createAttachment(document),
          consulo.logging.attachment.AttachmentFactory.get().create("psiTree.txt", DebugUtil.psiToString(file, false, true))} : Attachment.EMPTY_ARRAY);
}
 
Example 9
Source Project: intellij   Source File: BuildFileFoldingBuilder.java    License: Apache License 2.0 6 votes vote down vote up
private void addDescriptors(List<FoldingDescriptor> descriptors, ASTNode node) {
  IElementType type = node.getElementType();
  if (type == BuildElementTypes.FUNCTION_STATEMENT) {
    foldFunctionDefinition(descriptors, node);
  } else if (type == BuildElementTypes.FUNCALL_EXPRESSION
      || type == BuildElementTypes.LOAD_STATEMENT) {
    foldFunctionCall(descriptors, node);
  } else if (type == BuildElementTypes.STRING_LITERAL) {
    foldLongStrings(descriptors, node);
  } else if (type == BuildToken.COMMENT) {
    foldSequentialComments(descriptors, node);
  }
  ASTNode child = node.getFirstChildNode();
  while (child != null) {
    addDescriptors(descriptors, child);
    child = child.getTreeNext();
  }
}
 
Example 10
Source Project: buck   Source File: BuckFoldingBuilder.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void buildLanguageFoldRegions(
    @NotNull List<FoldingDescriptor> descriptors,
    @NotNull PsiElement root,
    @NotNull Document document,
    boolean quick) {

  foldLoadCalls(root, PsiTreeUtil.findChildrenOfType(root, BuckLoadCall.class), descriptors);

  PsiTreeUtil.findChildrenOfType(root, BuckFunctionDefinition.class)
      .forEach(e -> foldFunctionDefinition(e, descriptors));

  PsiTreeUtil.findChildrenOfType(root, BuckFunctionTrailer.class)
      .forEach(e -> foldFunctionTrailer(e, descriptors));

  PsiTreeUtil.findChildrenOfType(root, BuckDictMaker.class)
      .forEach(e -> foldDictMaker(e, descriptors));

  PsiTreeUtil.findChildrenOfType(root, BuckExpressionListOrComprehension.class)
      .forEach(e -> foldExpressionListOrComprehension(e, descriptors));
}
 
Example 11
Source Project: consulo   Source File: CustomFoldingRegionsPopup.java    License: Apache License 2.0 6 votes vote down vote up
CustomFoldingRegionsPopup(@Nonnull Collection<FoldingDescriptor> descriptors,
                          @Nonnull final Editor editor,
                          @Nonnull final Project project) {
  myEditor = editor;
  myRegionsList = new JBList();
  //noinspection unchecked
  myRegionsList.setModel(new MyListModel(orderByPosition(descriptors)));
  myRegionsList.setSelectedIndex(0);

  final PopupChooserBuilder popupBuilder = JBPopupFactory.getInstance().createListPopupBuilder(myRegionsList);
  myPopup = popupBuilder
          .setTitle(IdeBundle.message("goto.custom.region.command"))
          .setResizable(false)
          .setMovable(false)
          .setItemChoosenCallback(new Runnable() {
            @Override
            public void run() {
              PsiElement navigationElement = getNavigationElement();
              if (navigationElement != null) {
                navigateTo(editor, navigationElement);
                IdeDocumentHistory.getInstance(project).includeCurrentCommandAsNavigation();
              }
            }
          }).createPopup();
}
 
Example 12
Source Project: intellij   Source File: BuildFileFoldingBuilderTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testMultilineCommentFolded() {
  BuildFile file =
      createBuildFile(
          new WorkspacePath("java/com/google/BUILD"),
          "# multi-line comment, folded",
          "# second line of comment",
          "def function(arg1, arg2):",
          "    stmt1",
          "    stmt2",
          "",
          "variable = 1");

  FoldingDescriptor[] foldingRegions = getFoldingRegions(file);
  assertThat(foldingRegions).hasLength(2);
  assertThat(foldingRegions[0].getElement().getPsi())
      .isEqualTo(file.firstChildOfClass(PsiComment.class));
}
 
Example 13
Source Project: intellij   Source File: BuildFileFoldingBuilderTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testFuncDefStatementsFolded() {
  BuildFile file =
      createBuildFile(
          new WorkspacePath("java/com/google/BUILD"),
          "# multi-line comment, folded",
          "# second line of comment",
          "def function(arg1, arg2):",
          "    stmt1",
          "    stmt2",
          "",
          "variable = 1");

  FoldingDescriptor[] foldingRegions = getFoldingRegions(file);
  assertThat(foldingRegions).hasLength(2);
  assertThat(foldingRegions[1].getElement().getPsi())
      .isEqualTo(file.findFunctionInScope("function"));
}
 
Example 14
Source Project: intellij   Source File: BuildFileFoldingBuilderTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testLoadStatementFolded() {
  BuildFile file =
      createBuildFile(
          new WorkspacePath("java/com/google/BUILD"),
          "load(",
          "   '//java/com/foo/build_defs.bzl',",
          "   'function1',",
          "   'function2',",
          ")");

  FoldingDescriptor[] foldingRegions = getFoldingRegions(file);
  assertThat(foldingRegions).hasLength(1);
  assertThat(foldingRegions[0].getElement().getPsi())
      .isEqualTo(file.findChildByClass(LoadStatement.class));
}
 
Example 15
Source Project: BashSupport   Source File: BashFoldingBuilder.java    License: Apache License 2.0 6 votes vote down vote up
private static ASTNode appendDescriptors(final ASTNode node, final Document document, final List<FoldingDescriptor> descriptors) {
    if (isFoldable(node)) {
        final IElementType type = node.getElementType();

        int startLine = document.getLineNumber(node.getStartOffset());

        TextRange adjustedFoldingRange = adjustFoldingRange(node);
        int endLine = document.getLineNumber(adjustedFoldingRange.getEndOffset());

        if (startLine + minumumLineOffset(type) <= endLine) {
            descriptors.add(new FoldingDescriptor(node, adjustedFoldingRange));
        }
    }

    if (mayContainFoldBlocks(node)) {
        //work on all child elements
        ASTNode child = node.getFirstChildNode();
        while (child != null) {
            child = appendDescriptors(child, document, descriptors).getTreeNext();
        }
    }

    return node;
}
 
Example 16
Source Project: BashSupport   Source File: BashFoldingBuilderTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testVariablesFolding() {
    try {
        BashProjectSettings.storedSettings(getProject()).setVariableFolding(true);
        String fileContent = "TMP_DIR=tmpDir\nDECOMPILED_SRC_DIR=\"$TMP_DIR/../../data/decompiled_src\"";
        PsiFile psiFile = myFixture.configureByText(BashFileType.BASH_FILE_TYPE, fileContent);

        BashVariableFoldingBuilder builder = new BashVariableFoldingBuilder();
        FoldingDescriptor[] regions = builder.buildFoldRegions(psiFile.getNode(), myFixture.getDocument(psiFile));

        Assert.assertEquals(1, regions.length);
        Assert.assertEquals("(35,43)", regions[0].getRange().toString());
    } finally {
        BashProjectSettings.storedSettings(getProject()).setVariableFolding(true);
    }
}
 
Example 17
Source Project: consulo-unity3d   Source File: ShaderLabFoldingBuilder.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void buildLanguageFoldRegions(@Nonnull final List<FoldingDescriptor> descriptors, @Nonnull PsiElement root, @Nonnull Document document, boolean quick)
{
	root.accept(new SharpLabElementVisitor()
	{
		@Override
		public void visitElement(PsiElement element)
		{
			if(element instanceof ShaderBraceOwner)
			{
				descriptors.add(new FoldingDescriptor(element, element.getTextRange()));
			}
			element.acceptChildren(this);
		}
	});
}
 
Example 18
@SuppressWarnings("unchecked")
private static void addRuleRefFoldingDescriptors(List<FoldingDescriptor> descriptors, PsiElement root) {
    for (RuleSpecNode specNode : PsiTreeUtil.findChildrenOfType(root, RuleSpecNode.class)) {
        GrammarElementRefNode refNode = PsiTreeUtil.findChildOfAnyType(specNode, GrammarElementRefNode.class);
        if (refNode == null) continue;
        PsiElement nextSibling = refNode.getNextSibling();
        if (nextSibling == null) continue;
        int startOffset = nextSibling.getTextOffset();

        ASTNode backward = TreeUtil.findChildBackward(specNode.getNode(), SEMICOLON);
        if (backward == null) continue;
        int endOffset = backward.getTextRange().getEndOffset();
        if (startOffset >= endOffset) continue;

        descriptors.add(new FoldingDescriptor(specNode, new TextRange(startOffset, endOffset)));

    }
}
 
Example 19
Source Project: intellij-latte   Source File: LatteFoldingBuilder.java    License: MIT License 6 votes vote down vote up
@SuppressWarnings("unchecked")
@NotNull
@Override
public FoldingDescriptor[] buildFoldRegions(@NotNull PsiElement root, @NotNull Document document, boolean quick) {
	List<FoldingDescriptor> descriptors = new ArrayList<FoldingDescriptor>();

	if (!quick) {
		Collection<LatteMacroClassic> nodes = PsiTreeUtil.findChildrenOfAnyType(root, LatteMacroClassic.class);
		for (PsiElement node : nodes) {
			int start = node.getFirstChild().getTextRange().getEndOffset();
			int end = node.getLastChild().getTextRange().getEndOffset();
			if (end == start) {
				continue;
			}
			if (node instanceof LatteMacroClassic) {
				start--;
				end--;
			}

			descriptors.add(new FoldingDescriptor(node, TextRange.create(start, end)));

		}
	}

	return descriptors.toArray(new FoldingDescriptor[descriptors.size()]);
}
 
Example 20
Source Project: idea-latex   Source File: LatexFoldingBuilder.java    License: MIT License 6 votes vote down vote up
@Override
public void visitSection(@NotNull LatexSection section) {
    LatexInstructionBegin begin = ((LatexSectionExtImpl) section).getBeginInstruction();
    LatexInstructionEnd end = ((LatexSectionExtImpl) section).getEndInstruction();

    if (begin == null || end == null) {
        return;
    }

    int startOffset = begin.getTextOffset();
    int endOffset = end.getTextOffset() + end.getTextLength();
    if (endOffset - startOffset > 0) {
        descriptors.add(new FoldingDescriptor(section, new TextRange(startOffset, endOffset)));
    }

    section.acceptChildren(visitor);
}
 
Example 21
Source Project: intellij-haxe   Source File: HaxeFoldingBuilder.java    License: Apache License 2.0 6 votes vote down vote up
@NotNull
@Override
public FoldingDescriptor[] buildFoldRegions(@NotNull ASTNode node, @NotNull Document document) {
  List<FoldingDescriptor> descriptorList = new ArrayList<>();
  List<RegionMarker> regionMarkers = new ArrayList<>();
  List<RegionMarker> ccMarkers = new ArrayList<>();

  buildFolding(node, descriptorList, regionMarkers, ccMarkers);

  buildMarkerRegions(descriptorList, regionMarkers);

  buildCCMarkerRegions(descriptorList, ccMarkers, document);

  FoldingDescriptor[] descriptors = new FoldingDescriptor[descriptorList.size()];
  return descriptorList.toArray(descriptors);
}
 
Example 22
Source Project: intellij-xquery   Source File: XQueryFoldingBuilder.java    License: Apache License 2.0 6 votes vote down vote up
@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 23
private static void addTokensFoldingDescriptor(List<FoldingDescriptor> descriptors, PsiElement root) {
    PsiElement tokensSpec = MyPsiUtils.findFirstChildOfType(root, TOKENSSPEC);
    if (tokensSpec != null) {
        PsiElement tokens = tokensSpec.getFirstChild();
        if ( tokens.getNode().getElementType() == TOKENS ) {
            PsiElement rbrace = tokensSpec.getLastChild();
            if ( rbrace.getNode().getElementType()==RBRACE ) {
                descriptors.add(new FoldingDescriptor(tokensSpec,
                                                      new TextRange(tokens.getTextRange().getEndOffset(), rbrace.getTextRange().getEndOffset())));
            }
        }
    }
}
 
Example 24
Source Project: consulo   Source File: FoldingPolicy.java    License: Apache License 2.0 5 votes vote down vote up
static boolean isCollapsedByDefault(@Nonnull FoldingDescriptor foldingDescriptor, @Nonnull FoldingBuilder foldingBuilder) {
  try {
    return foldingBuilder.isCollapsedByDefault(foldingDescriptor);
  }
  catch (IndexNotReadyException e) {
    LOG.error(e);
    return false;
  }
}
 
Example 25
Source Project: buck   Source File: BcfgFoldingBuilder.java    License: Apache License 2.0 5 votes vote down vote up
/** Create a folding descriptor for the given property. */
static FoldingDescriptor propertyFoldingDescriptor(BcfgProperty property) {
  BcfgPropertyName name = property.getPropertyName();
  BcfgPropertyValue value = property.getPropertyValue();
  int start = name.getTextRange().getStartOffset();
  int end = value.getTextRange().getEndOffset();
  return new FoldingDescriptor(property.getNode(), new TextRange(start, end)) {
    @Nullable
    @Override
    public String getPlaceholderText() {
      return name.getValue() + " = " + value.getValue();
    }
  };
}
 
Example 26
Source Project: reasonml-idea-plugin   Source File: FoldingBuilder.java    License: MIT License 5 votes vote down vote up
private void foldType(@NotNull List<FoldingDescriptor> descriptors, @NotNull PsiType typeExpression) {
    PsiElement constrName = PsiTreeUtil.findChildOfType(typeExpression, PsiTypeConstrName.class);
    if (constrName != null) {
        ORTypes types = ORTypesUtil.getInstance(typeExpression.getLanguage());
        PsiElement eqElement = ORUtil.nextSiblingWithTokenType(constrName, types.EQ);
        if (eqElement != null) {
            TextRange eqRange = eqElement.getTextRange();
            TextRange typeRange = typeExpression.getTextRange();
            TextRange textRange = TextRange.create(eqRange.getStartOffset(), typeRange.getEndOffset());
            if (textRange.getLength() > 5) {
                descriptors.add(new FoldingDescriptor(typeExpression, textRange));
            }
        }
    }
}
 
Example 27
Source Project: reasonml-idea-plugin   Source File: FoldingBuilder.java    License: MIT License 5 votes vote down vote up
private void foldModule(@NotNull List<FoldingDescriptor> descriptors, @NotNull PsiInnerModule module) {
    FoldingDescriptor foldSignature = fold(module.getSignature());
    if (foldSignature != null) {
        descriptors.add(foldSignature);
    }

    FoldingDescriptor foldBody = fold(module.getBody());
    if (foldBody != null) {
        descriptors.add(foldBody);
    }
}
 
Example 28
Source Project: reasonml-idea-plugin   Source File: FoldingBuilder.java    License: MIT License 5 votes vote down vote up
private void foldTag(@NotNull List<FoldingDescriptor> descriptors, @NotNull PsiTag tag) {
    PsiTagStart start = ORUtil.findImmediateFirstChildOfClass(tag, PsiTagStart.class);
    PsiTagClose close = start == null ? null : ORUtil.findImmediateFirstChildOfClass(tag, PsiTagClose.class);
    // Auto-closed tags are not foldable
    if (close != null) {
        PsiElement lastChild = start.getLastChild();
        TextRange textRange = TextRange.create(lastChild.getTextOffset(), tag.getTextRange().getEndOffset() - 1);
        descriptors.add(new FoldingDescriptor(tag, textRange));
    }
}
 
Example 29
Source Project: buck   Source File: BuckFoldingBuilder.java    License: Apache License 2.0 5 votes vote down vote up
private static void foldDictMaker(BuckDictMaker dictMaker, List<FoldingDescriptor> descriptors) {
  if (dictMaker.getDictEntryList().size() < 5) {
    return;
  }
  TextRange textRange = rangeIncludingWhitespace(dictMaker, dictMaker);
  if (!textRange.isEmpty()) {
    FoldingDescriptor descriptor =
        new FoldingDescriptor(dictMaker.getParent().getNode(), textRange);
    descriptors.add(descriptor);
  }
}
 
Example 30
Source Project: idea-php-typo3-plugin   Source File: RouteFoldingBuilder.java    License: MIT License 5 votes vote down vote up
@Nullable
private FoldingDescriptor foldRouteReferenceString(PsiReference reference, String value, FoldingGroup group) {
    PsiElement element = reference.getElement();
    TextRange foldingRange = new TextRange(element.getTextRange().getStartOffset() + 1, element.getTextRange().getEndOffset() - 1);

    if (!RouteIndex.hasRoute(element.getProject(), value)) {
        return null;
    }

    Collection<RouteStub> route = RouteIndex.getRoute(element.getProject(), value);
    if (route.size() == 0) {
        return null;
    }

    RouteStub routeDef = route.iterator().next();

    return new FoldingDescriptor(element.getNode(), foldingRange, group) {
        @Nullable
        @Override
        public String getPlaceholderText() {
            if (routeDef.getPath() == null) {
                return routeDef.getController() + "::" + routeDef.getMethod();
            }

            return routeDef.getPath();
        }
    };
}