當前位置: 首頁>>代碼示例>>Java>>正文


Java FoldingDescriptor.getRange方法代碼示例

本文整理匯總了Java中com.intellij.lang.folding.FoldingDescriptor.getRange方法的典型用法代碼示例。如果您正苦於以下問題:Java FoldingDescriptor.getRange方法的具體用法?Java FoldingDescriptor.getRange怎麽用?Java FoldingDescriptor.getRange使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.intellij.lang.folding.FoldingDescriptor的用法示例。


在下文中一共展示了FoldingDescriptor.getRange方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getFoldingsFor

import com.intellij.lang.folding.FoldingDescriptor; //導入方法依賴的package包/類
private static void getFoldingsFor(@NotNull PsiFile file,
                                   @NotNull Document document,
                                   @NotNull FoldingMap elementsToFoldMap,
                                   boolean quick) {
  final FileViewProvider viewProvider = file.getViewProvider();
  TextRange docRange = TextRange.from(0, document.getTextLength());
  for (final Language language : viewProvider.getLanguages()) {
    final PsiFile psi = viewProvider.getPsi(language);
    final FoldingBuilder foldingBuilder = LanguageFolding.INSTANCE.forLanguage(language);
    if (psi != null && foldingBuilder != null) {
      for (FoldingDescriptor descriptor : LanguageFolding.buildFoldingDescriptors(foldingBuilder, psi, document, quick)) {
        TextRange range = descriptor.getRange();
        if (!docRange.contains(range)) {
          LOG.error("Folding descriptor " + descriptor +
                    " made by " + foldingBuilder +
                    " for " +language +
                    " and called on file " + psi +
                    " is outside document range: " + docRange);
        }
        elementsToFoldMap.putValue(descriptor.getElement().getPsi(), descriptor);
      }
    }
  }
}
 
開發者ID:lshain-android-source,項目名稱:tools-idea,代碼行數:25,代碼來源:FoldingUpdate.java

示例2: getFoldingsFor

import com.intellij.lang.folding.FoldingDescriptor; //導入方法依賴的package包/類
private static void getFoldingsFor(@NotNull PsiFile file,
                                   @NotNull Document document,
                                   @NotNull FoldingMap elementsToFoldMap,
                                   boolean quick) {
  final FileViewProvider viewProvider = file.getViewProvider();
  TextRange docRange = TextRange.from(0, document.getTextLength());
  for (final Language language : viewProvider.getLanguages()) {
    final PsiFile psi = viewProvider.getPsi(language);
    final FoldingBuilder foldingBuilder = LanguageFolding.INSTANCE.forLanguage(language);
    if (psi != null && foldingBuilder != null) {
      for (FoldingDescriptor descriptor : LanguageFolding.buildFoldingDescriptors(foldingBuilder, psi, document, quick)) {
        TextRange range = descriptor.getRange();
        ASTNode element = descriptor.getElement();
        PsiElement psiElement = element.getPsi();
        if (!docRange.contains(range)) {
          PsiDocumentManager psiDocumentManager = PsiDocumentManager.getInstance(file.getProject());
          LOG.error("Folding descriptor " + descriptor +
                    " made by " + foldingBuilder +
                    " for " + language +
                    " and called on file " + psi +
                    " is outside document range: " + docRange +
                    ", document committed: " + psiDocumentManager.isCommitted(document) +
                    ", element range: " + element.getTextRange() +
                    ", PSI element: " + psiElement +
                    ", PSI element range: " + (psiElement == null ? null : psiElement.getTextRange()) +
                    ", PSI element is valid: " + (psiElement != null && psiElement.isValid()) +
                    ", PSI file is valid: " + file.isValid() +
                    ", PSI file range: " + file.getTextRange() +
                    ", PSI file corresponds to document: " + (file == psiDocumentManager.getCachedPsiFile(document)),
                    ApplicationManager.getApplication().isInternal()
                    ? new Attachment[] {AttachmentFactory.createAttachment(document), new Attachment("psiTree.txt", DebugUtil.psiToString(psi, false, true))}
                    : new Attachment[0]);
        }
        elementsToFoldMap.putValue(psiElement, descriptor);
      }
    }
  }
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:39,代碼來源:FoldingUpdate.java

示例3: addNewRegions

import com.intellij.lang.folding.FoldingDescriptor; //導入方法依賴的package包/類
private List<FoldRegion> addNewRegions(@NotNull EditorFoldingInfo info,
                                       @NotNull FoldingModelEx foldingModel,
                                       FoldingUpdate.FoldingMap elementsToFold, @NotNull Map<TextRange, Boolean> rangeToExpandStatusMap,
                                       @NotNull Map<FoldRegion, Boolean> shouldExpand,
                                       @NotNull Map<FoldingGroup, Boolean> groupExpand) {
  List<FoldRegion> newRegions = newArrayList();
  SmartPointerManager smartPointerManager = SmartPointerManager.getInstance(myProject);
  for (PsiElement element : elementsToFold.keySet()) {
    ProgressManager.checkCanceled();
    final Collection<FoldingDescriptor> descriptors = elementsToFold.get(element);
    for (FoldingDescriptor descriptor : descriptors) {
      FoldingGroup group = descriptor.getGroup();
      TextRange range = descriptor.getRange();
      String placeholder = descriptor.getPlaceholderText();
      if (range.getEndOffset() > myEditor.getDocument().getTextLength()) {
        LOG.error(String.format("Invalid folding descriptor detected (%s). It ends beyond the document range (%d)",
                                descriptor, myEditor.getDocument().getTextLength()));
        continue;
      }
      FoldRegion region = foldingModel.createFoldRegion(range.getStartOffset(), range.getEndOffset(),
                                                        placeholder == null ? "..." : placeholder,
                                                        group,
                                                        descriptor.isNonExpandable());
      if (region == null) continue;

      PsiElement psi = descriptor.getElement().getPsi();

      if (psi == null || !psi.isValid() || !foldingModel.addFoldRegion(region) || !myFile.isValid()) {
        region.dispose();
        continue;
      }

      info.addRegion(region, smartPointerManager.createSmartPsiElementPointer(psi));
      newRegions.add(region);

      boolean expandStatus = !descriptor.isNonExpandable() && shouldExpandNewRegion(element, range, rangeToExpandStatusMap);
      if (group == null) {
        shouldExpand.put(region, expandStatus);
      }
      else {
        final Boolean alreadyExpanded = groupExpand.get(group);
        groupExpand.put(group, alreadyExpanded == null ? expandStatus : alreadyExpanded.booleanValue() || expandStatus);
      }
    }
  }

  return newRegions;
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:49,代碼來源:UpdateFoldRegionsOperation.java

示例4: addNewRegions

import com.intellij.lang.folding.FoldingDescriptor; //導入方法依賴的package包/類
private List<FoldRegion> addNewRegions(@NotNull EditorFoldingInfo info,
                                       @NotNull FoldingModelEx foldingModel,
                                       @NotNull Map<TextRange, Boolean> rangeToExpandStatusMap,
                                       @NotNull Map<FoldRegion, Boolean> shouldExpand,
                                       @NotNull Map<FoldingGroup, Boolean> groupExpand) {
  List<FoldRegion> newRegions = newArrayList();
  SmartPointerManager smartPointerManager = SmartPointerManager.getInstance(myProject);
  for (PsiElement element : myElementsToFoldMap.keySet()) {
    ProgressManager.checkCanceled();
    final Collection<FoldingDescriptor> descriptors = myElementsToFoldMap.get(element);
    for (FoldingDescriptor descriptor : descriptors) {
      FoldingGroup group = descriptor.getGroup();
      TextRange range = descriptor.getRange();
      String placeholder = descriptor.getPlaceholderText();
      if (range.getEndOffset() > myEditor.getDocument().getTextLength()) {
        LOG.error(String.format("Invalid folding descriptor detected (%s). It ends beyond the document range (%d)",
                                descriptor, myEditor.getDocument().getTextLength()));
        continue;
      }
      FoldRegion region = foldingModel.createFoldRegion(range.getStartOffset(), range.getEndOffset(),
                                                        placeholder == null ? "..." : placeholder,
                                                        group,
                                                        descriptor.isNonExpandable());
      if (region == null) continue;

      PsiElement psi = descriptor.getElement().getPsi();

      if (psi == null || !psi.isValid() || !foldingModel.addFoldRegion(region)) {
        region.dispose();
        continue;
      }

      info.addRegion(region, smartPointerManager.createSmartPsiElementPointer(psi, myFile));
      newRegions.add(region);

      boolean expandStatus = !descriptor.isNonExpandable() && shouldExpandNewRegion(element, range, rangeToExpandStatusMap);
      if (group == null) {
        shouldExpand.put(region, expandStatus);
      }
      else {
        final Boolean alreadyExpanded = groupExpand.get(group);
        groupExpand.put(group, alreadyExpanded == null ? expandStatus : alreadyExpanded.booleanValue() || expandStatus);
      }
    }
  }

  return newRegions;
}
 
開發者ID:lshain-android-source,項目名稱:tools-idea,代碼行數:49,代碼來源:UpdateFoldRegionsOperation.java

示例5: addNewRegions

import com.intellij.lang.folding.FoldingDescriptor; //導入方法依賴的package包/類
private List<FoldRegion> addNewRegions(@Nonnull EditorFoldingInfo info,
                                       @Nonnull FoldingModelEx foldingModel,
                                       @Nonnull Map<TextRange, Boolean> rangeToExpandStatusMap,
                                       @Nonnull Map<FoldRegion, Boolean> shouldExpand,
                                       @Nonnull Map<FoldingGroup, Boolean> groupExpand) {
  List<FoldRegion> newRegions = new ArrayList<>();
  SmartPointerManager smartPointerManager = SmartPointerManager.getInstance(myProject);
  for (FoldingUpdate.RegionInfo regionInfo : myRegionInfos) {
    ProgressManager.checkCanceled();
    FoldingDescriptor descriptor = regionInfo.descriptor;
    FoldingGroup group = descriptor.getGroup();
    TextRange range = descriptor.getRange();
    String placeholder = null;
    try {
      placeholder = descriptor.getPlaceholderText();
    }
    catch (IndexNotReadyException ignore) {
    }
    if (range.getEndOffset() > myEditor.getDocument().getTextLength()) {
      LOG.error(String.format("Invalid folding descriptor detected (%s). It ends beyond the document range (%d)",
                              descriptor, myEditor.getDocument().getTextLength()));
      continue;
    }
    FoldRegion region = foldingModel.createFoldRegion(range.getStartOffset(), range.getEndOffset(),
                                                      placeholder == null ? "..." : placeholder,
                                                      group,
                                                      descriptor.isNonExpandable());
    if (region == null) continue;

    if (descriptor.isNonExpandable()) region.putUserData(FoldingModelImpl.SELECT_REGION_ON_CARET_NEARBY, Boolean.TRUE);

    PsiElement psi = descriptor.getElement().getPsi();

    if (psi == null || !psi.isValid() || !myFile.isValid()) {
      region.dispose();
      continue;
    }

    if (descriptor.canBeRemovedWhenCollapsed()) region.putUserData(CAN_BE_REMOVED_WHEN_COLLAPSED, Boolean.TRUE);
    region.putUserData(COLLAPSED_BY_DEFAULT, regionInfo.collapsedByDefault);
    region.putUserData(SIGNATURE, regionInfo.signature);

    info.addRegion(region, smartPointerManager.createSmartPsiElementPointer(psi));
    newRegions.add(region);

    boolean expandStatus = !descriptor.isNonExpandable() && shouldExpandNewRegion(range, rangeToExpandStatusMap,
                                                                                  regionInfo.collapsedByDefault);
    if (group == null) {
      shouldExpand.put(region, expandStatus);
    }
    else {
      final Boolean alreadyExpanded = groupExpand.get(group);
      groupExpand.put(group, alreadyExpanded == null ? expandStatus : alreadyExpanded.booleanValue() || expandStatus);
    }
  }

  return newRegions;
}
 
開發者ID:consulo,項目名稱:consulo,代碼行數:59,代碼來源:UpdateFoldRegionsOperation.java


注:本文中的com.intellij.lang.folding.FoldingDescriptor.getRange方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。