com.intellij.lang.folding.FoldingDescriptor Java Examples

The following examples show how to use com.intellij.lang.folding.FoldingDescriptor. 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: HaxeFoldingBuilder.java    From intellij-haxe with 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 #2
Source File: DocumentFoldingInfo.java    From consulo with 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 #3
Source File: ANTLRv4FoldingBuilder.java    From intellij-plugin-v4 with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@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 #4
Source File: ShaderLabFoldingBuilder.java    From consulo-unity3d with 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 #5
Source File: BuckFoldingBuilder.java    From buck with 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 #6
Source File: LatteFoldingBuilder.java    From intellij-latte with 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 #7
Source File: LatexFoldingBuilder.java    From idea-latex with 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 #8
Source File: BuildFileFoldingBuilder.java    From intellij with 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 #9
Source File: CustomFoldingRegionsPopup.java    From consulo with 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 #10
Source File: RouteFoldingBuilder.java    From idea-php-typo3-plugin with 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 #11
Source File: BuildFileFoldingBuilderTest.java    From intellij with 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 #12
Source File: FoldingUpdate.java    From consulo with 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 #13
Source File: PhpFoldingBuilder.java    From idea-php-symfony2-plugin with 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 #14
Source File: BuildFileFoldingBuilderTest.java    From intellij with 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 #15
Source File: ProtoFoldingBuilder.java    From protobuf-jetbrains-plugin with Apache License 2.0 6 votes vote down vote up
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 #16
Source File: BuildFileFoldingBuilderTest.java    From intellij with 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 #17
Source File: IndentationFoldingBuilder.java    From consulo with 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 #18
Source File: BashFoldingBuilderTest.java    From BashSupport with 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 #19
Source File: XQueryFoldingBuilder.java    From intellij-xquery with 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 #20
Source File: DuneFoldingBuilder.java    From reasonml-idea-plugin with 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 #21
Source File: BashFoldingBuilder.java    From BashSupport with 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 #22
Source File: DuneFoldingBuilder.java    From reasonml-idea-plugin with 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 #23
Source File: BuckFoldingBuilder.java    From buck with Apache License 2.0 5 votes vote down vote up
private static void foldSuite(BuckSuite suite, List<FoldingDescriptor> descriptors) {
  TextRange textRange = rangeExcludingWhitespace(suite, suite);
  if (!textRange.isEmpty()) {
    FoldingDescriptor descriptor = new FoldingDescriptor(suite.getNode(), textRange);
    descriptors.add(descriptor);
  }
}
 
Example #24
Source File: ANTLRv4FoldingBuilder.java    From intellij-plugin-v4 with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private static void addOptionsFoldingDescriptor(List<FoldingDescriptor> descriptors, PsiElement root) {
    PsiElement optionsSpec = MyPsiUtils.findFirstChildOfType(root, OPTIONSSPEC);
    if (optionsSpec != null) {
        PsiElement options = optionsSpec.getFirstChild();
        if ( options.getNode().getElementType() == OPTIONS ) {
            PsiElement rbrace = optionsSpec.getLastChild();
            if ( rbrace.getNode().getElementType()==RBRACE ) {
                descriptors.add(new FoldingDescriptor(optionsSpec,
                                                      new TextRange(options.getTextRange().getEndOffset(), rbrace.getTextRange().getEndOffset())));
            }
        }
    }
}
 
Example #25
Source File: JavascriptFoldingBuilder.java    From idea-php-shopware-plugin with MIT License 5 votes vote down vote up
@NotNull
@Override
public FoldingDescriptor[] buildFoldRegions(@NotNull PsiElement psiElement, @NotNull Document document, boolean b) {
    if(!ShopwareProjectComponent.isValidForProject(psiElement)) {
        return new FoldingDescriptor[0];
    }

    Collection<FoldingDescriptor> foldingDescriptors = new ArrayList<>();

    for (PsiElement element : psiElement.getChildren()) {
        if(element instanceof PsiComment) {
            String text = element.getText();
            Matcher matcher = Pattern.compile(ExtJsUtil.JS_NAMESPACE_PATTERN).matcher(text);
            if(!matcher.find()) {
                return new FoldingDescriptor[0];
            }

            String namespace = StringUtils.trim(matcher.group(1));
            if(StringUtils.isBlank(namespace)) {
                return new FoldingDescriptor[0];
            }

            foldingDescriptors.add(
                new MyFoldingDescriptor(String.format("{s namespace=%s}", namespace), element, element.getTextRange())
            );
        }
    }

    return foldingDescriptors.toArray(new FoldingDescriptor[0]);
}
 
Example #26
Source File: BashFoldingBuilderTest.java    From BashSupport with Apache License 2.0 5 votes vote down vote up
private <T extends PsiElement> FoldingDescriptor[] buildRegions(String fileContent, Class<T> foldedElementType) {
    PsiFile psiFile = myFixture.configureByText(BashFileType.BASH_FILE_TYPE, fileContent);

    T hereDoc = PsiTreeUtil.findChildOfType(psiFile, foldedElementType);
    Assert.assertNotNull(hereDoc);

    BashFoldingBuilder builder = new BashFoldingBuilder();
    return builder.buildFoldRegions(hereDoc.getNode(), myFixture.getDocument(psiFile));
}
 
Example #27
Source File: BashFoldingBuilderTest.java    From BashSupport with Apache License 2.0 5 votes vote down vote up
@Test
public void testHeredocFoldingWithSubExpressions() throws Exception {
    FoldingDescriptor[] regions = buildRegions("cat - << EOF\nline $(a)\nline ${a}\nline $((1+1))\nEOF", BashHereDoc.class);

    Assert.assertEquals(1, regions.length);
    Assert.assertEquals("(13,46)", regions[0].getRange().toString());
}
 
Example #28
Source File: FoldingUpdate.java    From consulo with Apache License 2.0 5 votes vote down vote up
private RegionInfo(@Nonnull FoldingDescriptor descriptor, @Nonnull PsiElement psiElement, @Nonnull FoldingBuilder foldingBuilder) {
  this.descriptor = descriptor;
  element = psiElement;
  Boolean hardCoded = descriptor.isCollapsedByDefault();
  collapsedByDefault = hardCoded == null ? FoldingPolicy.isCollapsedByDefault(descriptor, foldingBuilder) : hardCoded;
  signature = createSignature(psiElement);
}
 
Example #29
Source File: BashFoldingBuilderTest.java    From BashSupport with Apache License 2.0 5 votes vote down vote up
@Test
public void testHeredocFolding() throws Exception {
    FoldingDescriptor[] regions = buildRegions("cat - << EOF\nline 1\nline 2\nline 3\nEOF", BashHereDoc.class);

    Assert.assertEquals(1, regions.length);
    Assert.assertEquals("(13,33)", regions[0].getRange().toString());
}
 
Example #30
Source File: PhpFoldingBuilder.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
private void attachModelShortcuts(List<FoldingDescriptor> descriptors, final StringLiteralExpression stringLiteralExpression) {

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

        String content = stringLiteralExpression.getContents();

        for(String lastChar: new String[] {":", "\\"}) {
            if(content.contains(lastChar)) {
                final String replace = content.substring(content.lastIndexOf(lastChar) + 1);
                if(replace.length() > 0) {
                    descriptors.add(new FoldingDescriptor(stringLiteralExpression.getNode(),
                        new TextRange(stringLiteralExpression.getTextRange().getStartOffset() + 1, stringLiteralExpression.getTextRange().getEndOffset() - 1)) {
                        @Nullable
                        @Override
                        public String getPlaceholderText() {
                            return replace;
                        }
                    });
                }

                return;
            }
        }

    }