use of com.intellij.openapi.editor.FoldingGroup in project intellij-community by JetBrains.
the class GroovyFoldingBuilder method addFoldingForStrings.
private static void addFoldingForStrings(List<FoldingDescriptor> descriptors, ASTNode node) {
if (!isMultiLineStringLiteral(node))
return;
if (!node.getElementType().equals(GroovyElementTypes.GSTRING) && !node.getElementType().equals(GroovyElementTypes.REGEX)) {
descriptors.add(new FoldingDescriptor(node, node.getTextRange()));
return;
}
final GrString grString = (GrString) node.getPsi();
if (grString == null)
return;
final GrStringInjection[] injections = grString.getInjections();
if (injections.length == 0) {
descriptors.add(new FoldingDescriptor(node, node.getTextRange()));
return;
}
final String start_quote = GrStringUtil.getStartQuote(node.getText());
final String end_quote = GrStringUtil.getEndQuote(node.getText());
final FoldingGroup group = FoldingGroup.newGroup("GString");
final TextRange nodeRange = node.getTextRange();
int startOffset = nodeRange.getStartOffset();
GrStringInjection injection = injections[0];
TextRange injectionRange = injection.getTextRange();
if (startOffset + 1 < injectionRange.getStartOffset()) {
descriptors.add(new NamedFoldingDescriptor(node, startOffset, injectionRange.getStartOffset(), group, start_quote));
}
final String placeholder = " ";
startOffset = injectionRange.getEndOffset();
for (int i = 1; i < injections.length; i++) {
injection = injections[i];
injectionRange = injection.getTextRange();
final int endOffset = injectionRange.getStartOffset();
if (endOffset - startOffset >= 2) {
descriptors.add(new NamedFoldingDescriptor(injection.getNode().getTreePrev(), startOffset, endOffset, group, placeholder));
}
startOffset = injectionRange.getEndOffset();
}
if (startOffset + 1 < nodeRange.getEndOffset()) {
descriptors.add(new NamedFoldingDescriptor(node.getLastChildNode(), startOffset, nodeRange.getEndOffset(), group, end_quote));
}
}
use of com.intellij.openapi.editor.FoldingGroup in project intellij-community by JetBrains.
the class GroovyFoldingBuilder method collapseBlock.
private static void collapseBlock(List<FoldingDescriptor> descriptors, PsiElement psi) {
if (psi instanceof GrCodeBlock) {
final int lineFeedCount = StringUtil.countChars(psi.getText(), '\n');
if (lineFeedCount <= 2) {
final PsiElement lbrace = ((GrCodeBlock) psi).getLBrace();
final PsiElement rbrace = ((GrCodeBlock) psi).getRBrace();
if (lbrace != null && rbrace != null) {
final PsiElement next = lbrace.getNextSibling();
final PsiElement prev = rbrace.getPrevSibling();
if (next != null && PsiImplUtil.isWhiteSpaceOrNls(next) && prev != null && PsiImplUtil.isWhiteSpaceOrNls(prev)) {
final FoldingGroup group = FoldingGroup.newGroup("block_group");
descriptors.add(new NamedFoldingDescriptor(psi, lbrace.getTextRange().getStartOffset(), next.getTextRange().getEndOffset(), group, "{"));
descriptors.add(new NamedFoldingDescriptor(psi, prev.getTextRange().getStartOffset(), rbrace.getTextRange().getEndOffset(), group, "}"));
return;
}
}
}
}
descriptors.add(new FoldingDescriptor(psi, psi.getTextRange()));
}
use of com.intellij.openapi.editor.FoldingGroup in project intellij-community by JetBrains.
the class UpdateFoldRegionsOperation method applyExpandStatus.
private static void applyExpandStatus(@NotNull List<FoldRegion> newRegions, @NotNull Map<FoldRegion, Boolean> shouldExpand, @NotNull Map<FoldingGroup, Boolean> groupExpand) {
for (final FoldRegion region : newRegions) {
final FoldingGroup group = region.getGroup();
final Boolean expanded = group == null ? shouldExpand.get(region) : groupExpand.get(group);
if (expanded != null) {
region.setExpanded(expanded.booleanValue());
}
}
}
use of com.intellij.openapi.editor.FoldingGroup in project idea-php-typo3-plugin by cedricziel.
the class RouteFoldingBuilder method buildFoldRegions.
@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()]);
}
use of com.intellij.openapi.editor.FoldingGroup in project idea-php-typo3-plugin by cedricziel.
the class TranslationFoldingBuilder method buildFoldRegions.
@NotNull
@Override
public FoldingDescriptor[] buildFoldRegions(@NotNull PsiElement root, @NotNull Document document, boolean quick) {
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:")) {
Project project = literalExpression.getProject();
final List<StubTranslation> properties = TranslationIndex.findById(project, value);
StubTranslation defaultTranslation = findDefaultTranslationFromVariants(properties);
if (defaultTranslation != null) {
TextRange foldingRange = new TextRange(literalExpression.getTextRange().getStartOffset() + 1, literalExpression.getTextRange().getEndOffset() - 1);
descriptors.add(new FoldingDescriptor(literalExpression.getNode(), foldingRange, group) {
@Nullable
@Override
public String getPlaceholderText() {
PsiElement[] definitionElements = TranslationUtil.findDefinitionElements(project, value);
for (PsiElement definitionElement : definitionElements) {
if (definitionElement instanceof XmlTag) {
if (((XmlTag) definitionElement).getName().equals("label")) {
return ((XmlTag) definitionElement).getValue().getTrimmedText();
}
for (XmlTag xmlTag : ((XmlTag) definitionElement).getSubTags()) {
if (xmlTag.getName().equals("source")) {
return xmlTag.getValue().getTrimmedText();
}
}
}
if (definitionElement instanceof XmlAttributeValue) {
if (((XmlTag) definitionElement.getParent().getParent()).getName().equals("label")) {
return ((XmlTag) definitionElement).getValue().getTrimmedText();
}
for (XmlTag xmlTag : ((XmlTag) definitionElement.getParent().getParent()).getSubTags()) {
if (xmlTag.getName().equals("source")) {
return xmlTag.getValue().getTrimmedText();
}
}
}
}
return null;
}
});
}
}
}
return descriptors.toArray(new FoldingDescriptor[descriptors.size()]);
}
Aggregations