use of com.intellij.psi.PsiComment in project intellij-community by JetBrains.
the class PsiCommentManipulator method handleContentChange.
@Override
public PsiComment handleContentChange(@NotNull PsiComment psiComment, @NotNull TextRange range, String newContent) throws IncorrectOperationException {
String oldText = psiComment.getText();
String newText = oldText.substring(0, range.getStartOffset()) + newContent + oldText.substring(range.getEndOffset());
FileType type = psiComment.getContainingFile().getFileType();
PsiFile fromText = PsiFileFactory.getInstance(psiComment.getProject()).createFileFromText("__." + type.getDefaultExtension(), type, newText);
PsiComment newElement = PsiTreeUtil.getParentOfType(fromText.findElementAt(0), psiComment.getClass(), false);
assert newElement != null : type + " " + type.getDefaultExtension() + " " + newText;
return (PsiComment) psiComment.replace(newElement);
}
use of com.intellij.psi.PsiComment in project intellij-plugins by JetBrains.
the class DartServerFindUsagesHandler method getUsageInfo.
@Nullable
public static UsageInfo getUsageInfo(@NotNull final PsiElement usageElement, @NotNull final TextRange range, final boolean potentialUsage) {
final int offset = range.getStartOffset() - usageElement.getTextRange().getStartOffset();
boolean nonCodeUsage = usageElement instanceof PsiComment || usageElement.getParent() instanceof PsiComment;
final UsageInfo usageInfo = new UsageInfo(usageElement, offset, offset + range.getLength(), nonCodeUsage);
usageInfo.setDynamicUsage(potentialUsage);
return usageInfo;
}
use of com.intellij.psi.PsiComment in project intellij-plugins by JetBrains.
the class DartFoldingBuilder method foldComments.
private static void foldComments(@NotNull final List<FoldingDescriptor> descriptors, @NotNull final Collection<PsiElement> psiElements, @Nullable final TextRange fileHeaderRange) {
PsiElement psiElement;
for (Iterator<PsiElement> iter = psiElements.iterator(); iter.hasNext(); ) {
psiElement = iter.next();
if (!(psiElement instanceof PsiComment)) {
continue;
}
if (fileHeaderRange != null && fileHeaderRange.intersects(psiElement.getTextRange())) {
continue;
}
final IElementType elementType = psiElement.getNode().getElementType();
if ((elementType == DartTokenTypesSets.MULTI_LINE_DOC_COMMENT || elementType == DartTokenTypesSets.MULTI_LINE_COMMENT) && !isCustomRegionElement(psiElement)) {
descriptors.add(new FoldingDescriptor(psiElement, psiElement.getTextRange()));
} else if (elementType == DartTokenTypesSets.SINGLE_LINE_DOC_COMMENT || elementType == DartTokenTypesSets.SINGLE_LINE_COMMENT) {
final PsiElement firstCommentInSequence = psiElement;
PsiElement lastCommentInSequence = firstCommentInSequence;
PsiElement nextElement = firstCommentInSequence;
boolean containsCustomRegionMarker = isCustomRegionElement(nextElement);
while (iter.hasNext() && (nextElement = nextElement.getNextSibling()) != null && (nextElement instanceof PsiWhiteSpace || nextElement.getNode().getElementType() == elementType)) {
if (nextElement.getNode().getElementType() == elementType) {
// advance iterator to skip processed comments sequence
iter.next();
lastCommentInSequence = nextElement;
containsCustomRegionMarker |= isCustomRegionElement(nextElement);
}
}
if (lastCommentInSequence != firstCommentInSequence && !containsCustomRegionMarker) {
final TextRange range = TextRange.create(firstCommentInSequence.getTextRange().getStartOffset(), lastCommentInSequence.getTextRange().getEndOffset());
descriptors.add(new FoldingDescriptor(firstCommentInSequence, range));
}
}
}
}
use of com.intellij.psi.PsiComment in project intellij-plugins by JetBrains.
the class GherkinSuppressionUtil method getSuppressionComment.
@Nullable
private static PsiComment getSuppressionComment(@NotNull String toolId, @NotNull PsiElement element) {
final PsiElement comment = PsiTreeUtil.skipSiblingsBackward(element, PsiWhiteSpace.class);
if (comment instanceof PsiComment) {
String text = comment.getText();
Matcher matcher = SUPPRESS_IN_LINE_COMMENT_PATTERN.matcher(text);
if (matcher.matches() && SuppressionUtil.isInspectionToolIdMentioned(matcher.group(1), toolId)) {
return (PsiComment) comment;
}
}
return null;
}
use of com.intellij.psi.PsiComment in project intellij-plugins by JetBrains.
the class GherkinSuppressionUtil method getSuppressedIn.
@Nullable
private static PsiComment getSuppressedIn(@NotNull PsiElement place, @NotNull String toolId) {
// find suppression holder with suppression comment about given inspection tool
PsiElement suppressionHolder = PsiTreeUtil.getNonStrictParentOfType(place, GherkinSuppressionHolder.class);
while (suppressionHolder != null) {
final PsiComment suppressionHolderElement = getSuppressionComment(toolId, suppressionHolder);
if (suppressionHolderElement != null) {
return suppressionHolderElement;
}
suppressionHolder = PsiTreeUtil.getParentOfType(suppressionHolder, GherkinSuppressionHolder.class);
}
return null;
}
Aggregations