本文整理汇总了Java中com.intellij.openapi.util.Segment类的典型用法代码示例。如果您正苦于以下问题:Java Segment类的具体用法?Java Segment怎么用?Java Segment使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Segment类属于com.intellij.openapi.util包,在下文中一共展示了Segment类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: compareTo
import com.intellij.openapi.util.Segment; //导入依赖的package包/类
@Override
public int compareTo(@NotNull UsageGroup usageGroup) {
if (!(usageGroup instanceof MethodUsageGroup)) {
LOG.error("MethodUsageGroup expected but " + usageGroup.getClass() + " found");
}
MethodUsageGroup other = (MethodUsageGroup)usageGroup;
if (SmartPointerManager.getInstance(myProject).pointToTheSameElement(myMethodPointer, other.myMethodPointer)) {
return 0;
}
if (!UsageViewSettings.getInstance().IS_SORT_MEMBERS_ALPHABETICALLY) {
Segment segment1 = myMethodPointer.getRange();
Segment segment2 = other.myMethodPointer.getRange();
if (segment1 != null && segment2 != null) {
return segment1.getStartOffset() - segment2.getStartOffset();
}
}
return myName.compareToIgnoreCase(other.myName);
}
示例2: testEqualPointerRangesWhenCreatedFromStubAndAST
import com.intellij.openapi.util.Segment; //导入依赖的package包/类
public void testEqualPointerRangesWhenCreatedFromStubAndAST() {
final PsiFile file = configureByText(JavaFileType.INSTANCE,
"class S {\n" +
"}");
PsiClass aClass = ((PsiJavaFile)file).getClasses()[0];
assertNotNull(((PsiFileImpl)file).getStubTree());
final SmartPointerManager manager = getPointerManager();
final SmartPsiElementPointer<PsiClass> pointer1 = createPointer(aClass);
Segment range1 = pointer1.getRange();
manager.removePointer(pointer1);
final FileASTNode node = file.getNode();
final SmartPsiElementPointer<PsiClass> pointer2 = createPointer(aClass);
assertEquals(range1, pointer2.getRange());
assertNotNull(node);
}
示例3: flashUsageScriptaculously
import com.intellij.openapi.util.Segment; //导入依赖的package包/类
private static void flashUsageScriptaculously(@NotNull final Usage usage) {
if (!(usage instanceof UsageInfo2UsageAdapter)) {
return;
}
UsageInfo2UsageAdapter usageInfo = (UsageInfo2UsageAdapter)usage;
Editor editor = usageInfo.openTextEditor(true);
if (editor == null) return;
TextAttributes attributes = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(CodeInsightColors.BLINKING_HIGHLIGHTS_ATTRIBUTES);
RangeBlinker rangeBlinker = new RangeBlinker(editor, attributes, 6);
List<Segment> segments = new ArrayList<Segment>();
CommonProcessors.CollectProcessor<Segment> processor = new CommonProcessors.CollectProcessor<Segment>(segments);
usageInfo.processRangeMarkers(processor);
rangeBlinker.resetMarkers(segments);
rangeBlinker.startBlinking();
}
示例4: getRangeInElement
import com.intellij.openapi.util.Segment; //导入依赖的package包/类
/**
* @return range in element
*/
@Nullable("null means range is invalid")
public ProperTextRange getRangeInElement() {
PsiElement element = getElement();
if (element == null) return null;
TextRange elementRange = element.getTextRange();
ProperTextRange result;
if (myPsiFileRange == null) {
int startOffset = element.getTextOffset();
result = ProperTextRange.create(startOffset, elementRange.getEndOffset());
}
else {
Segment rangeInFile = myPsiFileRange.getRange();
if (rangeInFile == null) return null;
result = ProperTextRange.create(rangeInFile);
}
int delta = elementRange.getStartOffset();
return result.getStartOffset() < delta ? null : result.shiftRight(-delta);
}
示例5: ReplacementPreviewDialog
import com.intellij.openapi.util.Segment; //导入依赖的package包/类
public ReplacementPreviewDialog(final Project project, UsageInfo info, String replacementString) {
super(project,true);
setTitle(SSRBundle.message("structural.replace.preview.dialog.title"));
setOKButtonText(SSRBundle.message("replace.preview.oktext"));
this.project = project;
final PsiElement element = info.getElement();
final VirtualFile virtualFile = PsiUtilCore.getVirtualFile(element);
myFileType = virtualFile != null ? virtualFile.getFileType() : FileTypes.PLAIN_TEXT;
init();
Segment range = info.getSegment();
hilight(virtualFile, range.getStartOffset(), range.getEndOffset());
UIUtil.setContent(replacement, replacementString,0,-1,project);
final StructuralSearchProfile profile = StructuralSearchUtil.getProfileByPsiElement(element);
if (profile != null) {
UIUtil.updateHighlighter(replacement, profile);
}
}
示例6: applyChange
import com.intellij.openapi.util.Segment; //导入依赖的package包/类
@Nullable
static Pair<ProperTextRange, LinesCols> applyChange(DocumentEvent event, Segment range, int intervalStart, int intervalEnd, boolean greedyLeft, boolean greedyRight, LinesCols linesCols) {
final boolean shouldTranslateViaDiff = PersistentRangeMarkerUtil.shouldTranslateViaDiff(event, range);
Pair<ProperTextRange, LinesCols> translated = null;
if (shouldTranslateViaDiff) {
translated = translateViaDiff((DocumentEventImpl)event, linesCols);
}
if (translated == null) {
ProperTextRange fallback = applyChange(event, intervalStart, intervalEnd, greedyLeft, greedyRight);
if (fallback == null) return null;
LinesCols lc = storeLinesAndCols(fallback, event.getDocument());
if (lc == null) return null;
translated = Pair.create(fallback, lc);
}
if (translated.first.getEndOffset() > event.getDocument().getTextLength() ||
translated.second.myEndLine < translated.second.myStartLine ||
translated.second.myStartLine == translated.second.myEndLine && translated.second.myEndColumn < translated.second.myStartColumn ||
event.getDocument().getLineCount() < translated.second.myEndLine) {
return null;
}
return translated;
}
示例7: restoreElement
import com.intellij.openapi.util.Segment; //导入依赖的package包/类
@Override
public PsiElement restoreElement() {
PsiFile hostFile = myHostContext.getContainingFile();
if (hostFile == null || !hostFile.isValid()) return null;
PsiElement hostContext = myHostContext.getElement();
if (hostContext == null) return null;
Segment segment = myInjectedFileRangeInHostFile.getPsiRange();
if (segment == null) return null;
PsiFile injectedPsi = getInjectedFileIn(hostContext, hostFile, TextRange.create(segment));
ProperTextRange rangeInInjected = hostToInjected(true, segment, injectedPsi, myAffixOffsets);
if (rangeInInjected == null) return null;
return SelfElementInfo.findElementInside(injectedPsi, rangeInInjected.getStartOffset(), rangeInInjected.getEndOffset(), anchorClass, anchorLanguage);
}
示例8: getNonEditableFragments
import com.intellij.openapi.util.Segment; //导入依赖的package包/类
@NotNull
@Override
public List<TextRange> getNonEditableFragments(@NotNull DocumentWindow window) {
List<TextRange> result = ContainerUtil.newArrayList();
int offset = 0;
for (PsiLanguageInjectionHost.Shred shred : ((DocumentWindowImpl)window).getShreds()) {
Segment hostRange = shred.getHostRangeMarker();
if (hostRange == null) continue;
offset = appendRange(result, offset, shred.getPrefix().length());
offset += hostRange.getEndOffset() - hostRange.getStartOffset();
offset = appendRange(result, offset, shred.getSuffix().length());
}
return result;
}
示例9: getRangeInsideHost
import com.intellij.openapi.util.Segment; //导入依赖的package包/类
@Override
@NotNull
public TextRange getRangeInsideHost() {
PsiLanguageInjectionHost host = getHost();
Segment psiRange = relevantRangeInHost.getPsiRange();
TextRange textRange = psiRange == null ? null : TextRange.create(psiRange);
if (host == null) {
if (textRange != null) return textRange;
Segment fromSP = hostElementPointer.getPsiRange();
if (fromSP != null) return TextRange.create(fromSP);
return new TextRange(0,0);
}
TextRange hostTextRange = host.getTextRange();
textRange = textRange == null ? null : textRange.intersection(hostTextRange);
if (textRange == null) return new ProperTextRange(0, hostTextRange.getLength());
return textRange.shiftRight(-hostTextRange.getStartOffset());
}
示例10: equals
import com.intellij.openapi.util.Segment; //导入依赖的package包/类
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
PsiLanguageInjectionHost.Shred shred = (PsiLanguageInjectionHost.Shred)o;
PsiLanguageInjectionHost host = getHost();
Segment hostRangeMarker = getHostRangeMarker();
Segment hostRangeMarker2 = shred.getHostRangeMarker();
return host != null &&
host.equals(shred.getHost()) &&
prefix.equals(shred.getPrefix()) &&
suffix.equals(shred.getSuffix()) &&
range.equals(shred.getRange()) &&
hostRangeMarker != null &&
hostRangeMarker2 != null &&
TextRange.create(hostRangeMarker).equals(TextRange.create(hostRangeMarker2));
}
示例11: compareTo
import com.intellij.openapi.util.Segment; //导入依赖的package包/类
@Override
public int compareTo(UsageGroup usageGroup) {
if (!(usageGroup instanceof MethodUsageGroup)) {
LOG.error("MethodUsageGroup expected but " + usageGroup.getClass() + " found");
}
MethodUsageGroup other = (MethodUsageGroup)usageGroup;
if (SmartPointerManager.getInstance(myProject).pointToTheSameElement(myMethodPointer, other.myMethodPointer)) {
return 0;
}
if (!UsageViewSettings.getInstance().IS_SORT_MEMBERS_ALPHABETICALLY) {
Segment segment1 = myMethodPointer.getRange();
Segment segment2 = other.myMethodPointer.getRange();
if (segment1 != null && segment2 != null) {
return segment1.getStartOffset() - segment2.getStartOffset();
}
}
return myName.compareToIgnoreCase(other.myName);
}
示例12: compareTo
import com.intellij.openapi.util.Segment; //导入依赖的package包/类
@Override
public int compareTo(final UsageInfo2UsageAdapter o) {
VirtualFile containingFile = getFile();
int shift1 = 0;
if (containingFile instanceof VirtualFileWindow) {
shift1 = ((VirtualFileWindow)containingFile).getDocumentWindow().injectedToHost(0);
containingFile = ((VirtualFileWindow)containingFile).getDelegate();
}
VirtualFile oContainingFile = o.getFile();
int shift2 = 0;
if (oContainingFile instanceof VirtualFileWindow) {
shift2 = ((VirtualFileWindow)oContainingFile).getDocumentWindow().injectedToHost(0);
oContainingFile = ((VirtualFileWindow)oContainingFile).getDelegate();
}
if (containingFile == null && oContainingFile == null || !Comparing.equal(containingFile, oContainingFile)) {
return 0;
}
Segment s1 = getFirstSegment();
Segment s2 = o.getFirstSegment();
if (s1 == null || s2 == null) return 0;
return s1.getStartOffset() + shift1 - s2.getStartOffset() - shift2;
}
示例13: getRangeInsideHost
import com.intellij.openapi.util.Segment; //导入依赖的package包/类
@Override
@NotNull
public TextRange getRangeInsideHost() {
PsiLanguageInjectionHost host = getHost();
ProperTextRange textRange =
relevantRangeInHost.isValid() ? new ProperTextRange(relevantRangeInHost.getStartOffset(), relevantRangeInHost.getEndOffset()) : null;
if (host == null) {
if (textRange != null) return textRange;
Segment fromSP = hostElementPointer.getRange();
if (fromSP != null) return TextRange.create(fromSP);
return new TextRange(0,0);
}
TextRange hostTextRange = host.getTextRange();
textRange = textRange == null ? null : textRange.intersection(hostTextRange);
if (textRange == null) return new ProperTextRange(0, hostTextRange.getLength());
return textRange.shiftRight(-hostTextRange.getStartOffset());
}
示例14: equals
import com.intellij.openapi.util.Segment; //导入依赖的package包/类
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
PsiLanguageInjectionHost.Shred shred = (PsiLanguageInjectionHost.Shred)o;
PsiLanguageInjectionHost host = getHost();
Segment hostRangeMarker = shred.getHostRangeMarker();
return host != null &&
host.equals(shred.getHost()) &&
prefix.equals(shred.getPrefix()) &&
suffix.equals(shred.getSuffix()) &&
range.equals(shred.getRange()) &&
hostRangeMarker != null &&
TextRange.create(relevantRangeInHost).equals(TextRange.create(hostRangeMarker));
}
示例15: flashUsageScriptaculously
import com.intellij.openapi.util.Segment; //导入依赖的package包/类
private static void flashUsageScriptaculously(@Nonnull final Usage usage) {
if (!(usage instanceof UsageInfo2UsageAdapter)) {
return;
}
UsageInfo2UsageAdapter usageInfo = (UsageInfo2UsageAdapter)usage;
Editor editor = usageInfo.openTextEditor(true);
if (editor == null) return;
TextAttributes attributes = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(CodeInsightColors.BLINKING_HIGHLIGHTS_ATTRIBUTES);
RangeBlinker rangeBlinker = new RangeBlinker(editor, attributes, 6);
List<Segment> segments = new ArrayList<>();
Processor<Segment> processor = Processors.cancelableCollectProcessor(segments);
usageInfo.processRangeMarkers(processor);
rangeBlinker.resetMarkers(segments);
rangeBlinker.startBlinking();
}