com.intellij.psi.util.PsiElementFilter#com.intellij.openapi.editor.RangeMarker源码实例Demo

下面列出了com.intellij.psi.util.PsiElementFilter#com.intellij.openapi.editor.RangeMarker 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: consulo   文件: HighlightInfoComposite.java
private HighlightInfoComposite(@Nonnull List<? extends HighlightInfo> infos, @Nonnull HighlightInfo anchorInfo) {
  super(null, null, anchorInfo.type, anchorInfo.startOffset, anchorInfo.endOffset, createCompositeDescription(infos), createCompositeTooltip(infos), anchorInfo.type.getSeverity(null), false, null,
        false, 0, anchorInfo.getProblemGroup(), null, anchorInfo.getGutterIconRenderer());
  highlighter = anchorInfo.getHighlighter();
  setGroup(anchorInfo.getGroup());
  List<Pair<IntentionActionDescriptor, RangeMarker>> markers = ContainerUtil.emptyList();
  List<Pair<IntentionActionDescriptor, TextRange>> ranges = ContainerUtil.emptyList();
  for (HighlightInfo info : infos) {
    if (info.quickFixActionMarkers != null) {
      if (markers == ContainerUtil.<Pair<IntentionActionDescriptor, RangeMarker>>emptyList()) markers = new ArrayList<>();
      markers.addAll(info.quickFixActionMarkers);
    }
    if (info.quickFixActionRanges != null) {
      if (ranges == ContainerUtil.<Pair<IntentionActionDescriptor, TextRange>>emptyList()) ranges = new ArrayList<>();
      ranges.addAll(info.quickFixActionRanges);
    }
  }
  quickFixActionMarkers = ContainerUtil.createLockFreeCopyOnWriteList(markers);
  quickFixActionRanges = ContainerUtil.createLockFreeCopyOnWriteList(ranges);
}
 
源代码2 项目: consulo   文件: FileStatusMap.java
@Nonnull
private static RangeMarker combineScopes(RangeMarker old, @Nonnull TextRange scope, int textLength, @Nonnull Document document) {
  if (old == null) {
    if (scope.equalsToRange(0, textLength)) return WHOLE_FILE_DIRTY_MARKER;
    return document.createRangeMarker(scope);
  }
  if (old == WHOLE_FILE_DIRTY_MARKER) return old;
  TextRange oldRange = TextRange.create(old);
  TextRange union = scope.union(oldRange);
  if (old.isValid() && union.equals(oldRange)) {
    return old;
  }
  if (union.getEndOffset() > textLength) {
    union = union.intersection(new TextRange(0, textLength));
  }
  assert union != null;
  return document.createRangeMarker(union);
}
 
源代码3 项目: consulo   文件: ShowIntentionsPass.java
public static boolean markActionInvoked(@Nonnull Project project, @Nonnull final Editor editor, @Nonnull IntentionAction action) {
  final int offset = ((EditorEx)editor).getExpectedCaretOffset();

  List<HighlightInfo> infos = new ArrayList<>();
  DaemonCodeAnalyzerImpl.processHighlightsNearOffset(editor.getDocument(), project, HighlightSeverity.INFORMATION, offset, true, new CommonProcessors.CollectProcessor<>(infos));
  boolean removed = false;
  for (HighlightInfo info : infos) {
    if (info.quickFixActionMarkers != null) {
      for (Pair<HighlightInfo.IntentionActionDescriptor, RangeMarker> pair : info.quickFixActionMarkers) {
        HighlightInfo.IntentionActionDescriptor actionInGroup = pair.first;
        if (actionInGroup.getAction() == action) {
          // no CME because the list is concurrent
          removed |= info.quickFixActionMarkers.remove(pair);
        }
      }
    }
  }
  return removed;
}
 
源代码4 项目: consulo   文件: MemberInplaceRenamer.java
@Nullable
public PsiElement getSubstituted() {
  if (mySubstituted != null && mySubstituted.isValid()){
    if (mySubstituted instanceof PsiNameIdentifierOwner) {
      if (Comparing.strEqual(myOldName, ((PsiNameIdentifierOwner)mySubstituted).getName())) return mySubstituted;

      final RangeMarker rangeMarker = mySubstitutedRange != null ? mySubstitutedRange : myRenameOffset;
      if (rangeMarker != null) return PsiTreeUtil.getParentOfType(mySubstituted.getContainingFile().findElementAt(rangeMarker.getStartOffset()), PsiNameIdentifierOwner.class);
    }
    return mySubstituted;
  }
  if (mySubstitutedRange != null) {
    final PsiFile psiFile = PsiDocumentManager.getInstance(myProject).getPsiFile(myEditor.getDocument());
    if (psiFile != null) {
      return PsiTreeUtil.getParentOfType(psiFile.findElementAt(mySubstitutedRange.getStartOffset()), PsiNameIdentifierOwner.class);
    }
  }
  return getVariable();
}
 
源代码5 项目: consulo   文件: OffsetMap.java
/**
 * @param key key
 * @return offset An offset registered earlier with this key.
 * -1 if offset wasn't registered or became invalidated due to document changes
 */
public int getOffset(OffsetKey key) {
  synchronized (myMap) {
    final RangeMarker marker = myMap.get(key);
    if (marker == null) throw new IllegalArgumentException("Offset " + key + " is not registered");
    if (!marker.isValid()) {
      removeOffset(key);
      throw new IllegalStateException("Offset " + key + " is invalid: " + marker);
    }

    final int endOffset = marker.getEndOffset();
    if (marker.getStartOffset() != endOffset) {
      saveOffset(key, endOffset, false);
    }
    return endOffset;
  }
}
 
源代码6 项目: consulo   文件: LazyRangeMarkerFactoryImpl.java
@Override
@Nonnull
public RangeMarker createRangeMarker(@Nonnull final VirtualFile file, final int line, final int column, final boolean persistent) {
  return ApplicationManager.getApplication().runReadAction(new Computable<RangeMarker>() {
    @Override
    public RangeMarker compute() {
      final Document document = FileDocumentManager.getInstance().getCachedDocument(file);
      if (document != null) {
        int myTabSize = CodeStyleFacade.getInstance(myProject).getTabSize(file.getFileType());
        final int offset = calculateOffset(document, line, column, myTabSize);
        return document.createRangeMarker(offset, offset, persistent);
      }

      final LazyMarker marker = new LineColumnLazyMarker(myProject, file, line, column);
      addToLazyMarkersList(marker, file);
      return marker;
    }
  });
}
 
源代码7 项目: aem-ide-tooling-4-intellij   文件: ConsoleLog.java
private static void indentNewLines(DocumentImpl logDoc, List<RangeMarker> lineSeparators, RangeMarker afterTitle, boolean hasHtml, String indent) {
    if(!hasHtml) {
        int i = -1;
        while(true) {
            i = StringUtil.indexOf(logDoc.getText(), '\n', i + 1);
            if(i < 0) {
                break;
            }
            lineSeparators.add(logDoc.createRangeMarker(i, i + 1));
        }
    }
    if(!lineSeparators.isEmpty() && afterTitle != null && afterTitle.isValid()) {
        lineSeparators.add(afterTitle);
    }
    int nextLineStart = -1;
    for(RangeMarker separator : lineSeparators) {
        if(separator.isValid()) {
            int start = separator.getStartOffset();
            if(start == nextLineStart) {
                continue;
            }

            logDoc.replaceString(start, separator.getEndOffset(), "\n" + indent);
            nextLineStart = start + 1 + indent.length();
            while(nextLineStart < logDoc.getTextLength() && Character.isWhitespace(logDoc.getCharsSequence().charAt(nextLineStart))) {
                logDoc.deleteString(nextLineStart, nextLineStart + 1);
            }
        }
    }
}
 
源代码8 项目: aem-ide-tooling-4-intellij   文件: ConsoleLog.java
private static void insertNewLineSubstitutors(Document document, AtomicBoolean showMore, List<RangeMarker> lineSeparators) {
    for(RangeMarker marker : lineSeparators) {
        if(!marker.isValid()) {
            showMore.set(true);
            continue;
        }

        int offset = marker.getStartOffset();
        if(offset == 0 || offset == document.getTextLength()) {
            continue;
        }
        boolean spaceBefore = offset > 0 && Character.isWhitespace(document.getCharsSequence().charAt(offset - 1));
        if(offset < document.getTextLength()) {
            boolean spaceAfter = Character.isWhitespace(document.getCharsSequence().charAt(offset));
            int next = CharArrayUtil.shiftForward(document.getCharsSequence(), offset, " \t");
            if(next < document.getTextLength() && !Character.isLowerCase(document.getCharsSequence().charAt(next))) {
                document.insertString(offset, (spaceBefore ? "" : " ") + "//" + (spaceAfter ? "" : " "));
                continue;
            }
            if(spaceAfter) {
                continue;
            }
        }
        if(spaceBefore) {
            continue;
        }

        document.insertString(offset, " ");
    }
}
 
源代码9 项目: aem-ide-tooling-4-intellij   文件: ConsoleLog.java
private static void removeJavaNewLines(Document document, List<RangeMarker> lineSeparators, boolean hasHtml) {
    CharSequence text = document.getCharsSequence();
    int i = 0;
    while(true) {
        i = StringUtil.indexOf(text, '\n', i);
        if(i < 0) {
            break;
        }
        document.deleteString(i, i + 1);
        if(!hasHtml) {
            lineSeparators.add(document.createRangeMarker(TextRange.from(i, 0)));
        }
    }
}
 
@Nullable
protected <T> T findIntention(@NotNull HighlightInfo info, @NotNull Class<T> aClass) {
  for (Pair<HighlightInfo.IntentionActionDescriptor, RangeMarker> pair : info.quickFixActionMarkers) {
    final HighlightInfo.IntentionActionDescriptor intensionDescriptor = pair.getFirst();
    final IntentionAction action = intensionDescriptor.getAction();
    if (aClass.isInstance(action)) {
      //noinspection unchecked
      return (T)action;
    }
  }
  return null;
}
 
源代码11 项目: consulo   文件: DocumentFragmentContent.java
@Nonnull
private static RangeMarker createRangeMarker(@Nonnull Document document, @Nonnull TextRange range) {
  RangeMarker rangeMarker = document.createRangeMarker(range.getStartOffset(), range.getEndOffset(), true);
  rangeMarker.setGreedyToLeft(true);
  rangeMarker.setGreedyToRight(true);
  return rangeMarker;
}
 
源代码12 项目: consulo   文件: DocumentFragmentContent.java
public MyDocumentsSynchronizer(@javax.annotation.Nullable Project project,
                               @Nonnull RangeMarker range,
                               @Nonnull Document document1,
                               @Nonnull Document document2) {
  super(project, document1, document2);
  myRangeMarker = range;
}
 
源代码13 项目: consulo   文件: SearchResults.java
public void exclude(FindResult occurrence) {
  boolean include = false;
  for (RangeMarker rangeMarker : myExcluded) {
    if (TextRange.areSegmentsEqual(rangeMarker, occurrence)) {
      myExcluded.remove(rangeMarker);
      rangeMarker.dispose();
      include = true;
      break;
    }
  }
  if (!include) {
    myExcluded.add(myEditor.getDocument().createRangeMarker(occurrence.getStartOffset(), occurrence.getEndOffset(), true));
  }
  notifyChanged();
}
 
源代码14 项目: consulo   文件: OffsetMap.java
@Override
public void dispose() {
  synchronized (myMap) {
    myDisposed = true;
    for (RangeMarker rangeMarker : myMap.values()) {
      rangeMarker.dispose();
    }
  }
}
 
源代码15 项目: consulo   文件: InplaceVariableIntroducer.java
protected void initOccurrencesMarkers() {
  if (myOccurrenceMarkers != null) return;
  myOccurrenceMarkers = new ArrayList<RangeMarker>();
  for (E occurrence : myOccurrences) {
    myOccurrenceMarkers.add(createMarker(occurrence));
  }
}
 
源代码16 项目: consulo   文件: GuardBlockTest.java
public void testGreedyEnd() throws Exception {
  configureFromFileText("x.txt", "012345678");
  {
    RangeMarker guard = createGuard(0, 5);
    guard.setGreedyToLeft(true);
    guard.setGreedyToRight(true);
  }
  checkUnableToTypeIn(5);
}
 
源代码17 项目: consulo   文件: FileStatusMap.java
private void setDirtyScope(int passId, RangeMarker scope) {
  RangeMarker marker = dirtyScopes.get(passId);
  if (marker != scope) {
    if (marker != null) {
      marker.dispose();
    }
    dirtyScopes.put(passId, scope);
  }
}
 
源代码18 项目: consulo   文件: Bookmark.java
public int getLine() {
  RangeMarker marker = myTarget.getRangeMarker();
  if (marker != null && marker.isValid()) {
    Document document = marker.getDocument();
    return document.getLineNumber(marker.getStartOffset());
  }
  return myTarget.getLine();
}
 
源代码19 项目: consulo   文件: SearchResults.java
public boolean isExcluded(FindResult occurrence) {
  for (RangeMarker rangeMarker : myExcluded) {
    if (TextRange.areSegmentsEqual(rangeMarker, occurrence)) {
      return true;
    }
  }
  return false;
}
 
源代码20 项目: consulo   文件: TodoItemNode.java
public TodoItemNode(Project project, @Nonnull SmartTodoItemPointer value, TodoTreeBuilder builder) {
  super(project, value, builder);
  RangeMarker rangeMarker = getValue().getRangeMarker();
  LOG.assertTrue(rangeMarker.isValid());

  myHighlightedRegions = new ArrayList<>();
  myAdditionalLines = new ArrayList<>();
}
 
源代码21 项目: consulo   文件: TemplateBuilderImpl.java
public void replaceElement(PsiElement element, TextRange textRange, String primaryVariableName, String otherVariableName, boolean alwaysStopAt) {
  final RangeMarker key = myDocument.createRangeMarker(textRange.shiftRight(element.getTextRange().getStartOffset()));
  myAlwaysStopAtMap.put(key, alwaysStopAt ? Boolean.TRUE : Boolean.FALSE);
  myVariableNamesMap.put(key, primaryVariableName);
  myVariableExpressions.put(key, otherVariableName);
  myElements.add(key);
}
 
源代码22 项目: consulo   文件: IdeDocumentHistoryImpl.java
public PlaceInfo(@Nonnull VirtualFile file, @Nonnull FileEditorState navigationState, @Nonnull String editorTypeId, @Nullable EditorWindow window, @Nullable RangeMarker caretPosition) {
  myNavigationState = navigationState;
  myFile = file;
  myEditorTypeId = editorTypeId;
  myWindow = new WeakReference<>(window);
  myCaretPosition = caretPosition;
  myTimeStamp = -1;
}
 
源代码23 项目: consulo   文件: IdeDocumentHistoryImpl.java
public PlaceInfo(@Nonnull VirtualFile file,
                 @Nonnull FileEditorState navigationState,
                 @Nonnull String editorTypeId,
                 @Nullable EditorWindow window,
                 @Nullable RangeMarker caretPosition,
                 long stamp) {
  myNavigationState = navigationState;
  myFile = file;
  myEditorTypeId = editorTypeId;
  myWindow = new WeakReference<>(window);
  myCaretPosition = caretPosition;
  myTimeStamp = stamp;
}
 
源代码24 项目: consulo   文件: FoldingTransformation.java
public FoldingTransformation(Editor editor) {
  myEditor = editor;
  FoldRegion[] foldRegions = myEditor.getFoldingModel().getAllFoldRegions();
  Arrays.sort(foldRegions, RangeMarker.BY_START_OFFSET);
  TIntArrayList foldBeginings = new TIntArrayList();
  for (FoldRegion foldRegion : foldRegions) {
    if (!foldRegion.isValid() || foldRegion.isExpanded()) continue;
    foldBeginings.add(getStartLine(foldRegion));
    myCollapsed.add(foldRegion);
  }
  myFoldBeginings = foldBeginings.toNativeArray();
}
 
源代码25 项目: consulo   文件: InplaceVariableIntroducer.java
@Override
protected void moveOffsetAfter(boolean success) {
  super.moveOffsetAfter(success);
  if (myOccurrenceMarkers != null) {
    for (RangeMarker marker : myOccurrenceMarkers) {
      marker.dispose();
    }
  }
  if (myExprMarker != null && !isRestart()) {
    myExprMarker.dispose();
  }
}
 
源代码26 项目: consulo   文件: TabOutScopesTrackerImpl.java
private List<RangeMarker> getCurrentScopes(boolean create) {
  Caret currentCaret = myEditor.getCaretModel().getCurrentCaret();
  List<RangeMarker> result = currentCaret.getUserData(TRACKED_SCOPES);
  if (result == null && create) {
    currentCaret.putUserData(TRACKED_SCOPES, result = new ArrayList<>());
  }
  return result;
}
 
源代码27 项目: consulo   文件: PostprocessReformattingAspect.java
@Override
public void dispose() {
  for (Pair<Integer, RangeMarker> pair : myRangesToReindent) {
    RangeMarker marker = pair.second;
    if (marker.isValid()) {
      marker.dispose();
    }
  }
}
 
源代码28 项目: consulo   文件: PostprocessReformattingAspect.java
@Override
public int compareTo(@Nonnull PostprocessFormattingTask o) {
  RangeMarker o1 = myRange;
  RangeMarker o2 = o.myRange;
  if (o1.equals(o2)) return 0;
  final int diff = o2.getEndOffset() - o1.getEndOffset();
  if (diff == 0) {
    if (o1.getStartOffset() == o2.getStartOffset()) return 0;
    if (o1.getStartOffset() == o1.getEndOffset()) return -1; // empty ranges first
    if (o2.getStartOffset() == o2.getEndOffset()) return 1; // empty ranges first
    return o1.getStartOffset() - o2.getStartOffset();
  }
  return diff;
}
 
源代码29 项目: consulo   文件: LazyRangeMarkerFactoryImpl.java
@Override
@Nonnull
public RangeMarker createRangeMarker(@Nonnull final VirtualFile file, final int offset) {
  return ApplicationManager.getApplication().runReadAction(new Computable<RangeMarker>() {
    @Override
    public RangeMarker compute() {
      // even for already loaded document do not create range marker yet - wait until it really needed when e.g. user clicked to jump to OpenFileDescriptor
      final LazyMarker marker = new OffsetLazyMarker(file, offset);
      addToLazyMarkersList(marker, file);
      return marker;
    }
  });
}
 
源代码30 项目: consulo   文件: TemplateBuilderImpl.java
public void replaceElement (PsiElement element, String varName, String dependantVariableName, boolean alwaysStopAt) {
  final RangeMarker key = wrapElement(element);
  myAlwaysStopAtMap.put(key, alwaysStopAt ? Boolean.TRUE : Boolean.FALSE);
  myVariableNamesMap.put(key, varName);
  myVariableExpressions.put(key, dependantVariableName);
  myElements.add(key);
}