use of com.intellij.openapi.util.Segment in project intellij-community by JetBrains.
the class RefManagerImpl method export.
@Override
public Element export(@NotNull RefEntity refEntity, @NotNull final Element element, final int actualLine) {
refEntity = getRefinedElement(refEntity);
Element problem = new Element("problem");
if (refEntity instanceof RefDirectory) {
Element fileElement = new Element("file");
VirtualFile virtualFile = ((PsiDirectory) ((RefDirectory) refEntity).getElement()).getVirtualFile();
fileElement.addContent(virtualFile.getUrl());
problem.addContent(fileElement);
} else if (refEntity instanceof RefElement) {
final RefElement refElement = (RefElement) refEntity;
final SmartPsiElementPointer pointer = refElement.getPointer();
PsiFile psiFile = pointer.getContainingFile();
if (psiFile == null)
return null;
Element fileElement = new Element("file");
Element lineElement = new Element("line");
final VirtualFile virtualFile = psiFile.getVirtualFile();
LOG.assertTrue(virtualFile != null);
fileElement.addContent(virtualFile.getUrl());
if (actualLine == -1) {
final Document document = PsiDocumentManager.getInstance(pointer.getProject()).getDocument(psiFile);
LOG.assertTrue(document != null);
final Segment range = pointer.getRange();
lineElement.addContent(String.valueOf(range != null ? document.getLineNumber(range.getStartOffset()) + 1 : -1));
} else {
lineElement.addContent(String.valueOf(actualLine + 1));
}
problem.addContent(fileElement);
problem.addContent(lineElement);
appendModule(problem, refElement.getModule());
} else if (refEntity instanceof RefModule) {
final RefModule refModule = (RefModule) refEntity;
final VirtualFile moduleFile = refModule.getModule().getModuleFile();
final Element fileElement = new Element("file");
fileElement.addContent(moduleFile != null ? moduleFile.getUrl() : refEntity.getName());
problem.addContent(fileElement);
appendModule(problem, refModule);
}
for (RefManagerExtension extension : myExtensions.values()) {
extension.export(refEntity, problem);
}
new SmartRefElementPointerImpl(refEntity, true).writeExternal(problem);
element.addContent(problem);
return problem;
}
use of com.intellij.openapi.util.Segment in project intellij-community by JetBrains.
the class FindResultUsageInfo method isValid.
@Override
public boolean isValid() {
if (!super.isValid())
return false;
Document document = PsiDocumentManager.getInstance(getProject()).getDocument(getPsiFile());
if (document == null) {
myCachedResult = null;
return false;
}
Boolean cachedResult = myCachedResult;
if (document.getModificationStamp() == myTimestamp && cachedResult != null) {
return cachedResult;
}
myTimestamp = document.getModificationStamp();
Segment segment = getSegment();
if (segment == null) {
myCachedResult = false;
return false;
}
VirtualFile file = getPsiFile().getVirtualFile();
Segment searchOffset;
if (myAnchor != null) {
searchOffset = myAnchor.getRange();
if (searchOffset == null) {
myCachedResult = false;
return false;
}
} else {
searchOffset = segment;
}
int offset = searchOffset.getStartOffset();
Long data = myFindModel.getUserData(DOCUMENT_TIMESTAMP_KEY);
if (data == null || data != myTimestamp) {
data = myTimestamp;
FindManagerImpl.clearPreviousFindData(myFindModel);
}
myFindModel.putUserData(DOCUMENT_TIMESTAMP_KEY, data);
FindResult result;
do {
result = myFindManager.findString(document.getCharsSequence(), offset, myFindModel, file);
offset = result.getEndOffset() == offset ? offset + 1 : result.getEndOffset();
if (!result.isStringFound()) {
myCachedResult = false;
return false;
}
} while (result.getStartOffset() < segment.getStartOffset());
boolean ret = segment.getStartOffset() == result.getStartOffset() && segment.getEndOffset() == result.getEndOffset();
myCachedResult = ret;
return ret;
}
use of com.intellij.openapi.util.Segment in project intellij-community by JetBrains.
the class InjectedSelfElementInfo method restoreElement.
@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 myType.findPsiElement(injectedPsi, rangeInInjected.getStartOffset(), rangeInInjected.getEndOffset());
}
use of com.intellij.openapi.util.Segment in project intellij-community by JetBrains.
the class ShredImpl method getRangeInsideHost.
@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());
}
use of com.intellij.openapi.util.Segment in project intellij-community by JetBrains.
the class ShredImpl method equals.
@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));
}
Aggregations