use of com.intellij.psi.PsiComment in project intellij-plugins by JetBrains.
the class CfmlFoldingBuilder method buildFoldRegions.
@NotNull
public FoldingDescriptor[] buildFoldRegions(@NotNull ASTNode node, @NotNull Document document) {
final PsiElement element = node.getPsi();
if (element instanceof CfmlFile) {
final CfmlFile file = (CfmlFile) element;
final PsiElement[] children = file.getChildren();
Collection<FoldingDescriptor> result = new LinkedList<>();
for (PsiElement child : children) {
if (child != null && (child instanceof CfmlCompositeElement || child instanceof PsiComment)) {
List<FoldingDescriptor> descriptors = new ArrayList<>();
addFoldingDescriptors(descriptors, child, document);
result.addAll(descriptors);
}
}
return result.toArray(FoldingDescriptor.EMPTY);
}
return FoldingDescriptor.EMPTY;
}
use of com.intellij.psi.PsiComment in project intellij-plugins by JetBrains.
the class DartFoldingBuilder method foldFileHeader.
@Nullable
private static TextRange foldFileHeader(@NotNull final List<FoldingDescriptor> descriptors, @NotNull final DartFile dartFile, @NotNull final Document document) {
PsiElement firstComment = dartFile.getFirstChild();
if (firstComment instanceof PsiWhiteSpace)
firstComment = firstComment.getNextSibling();
if (!(firstComment instanceof PsiComment))
return null;
boolean containsCustomRegionMarker = false;
PsiElement nextAfterComments = firstComment;
while (nextAfterComments instanceof PsiComment || nextAfterComments instanceof PsiWhiteSpace) {
containsCustomRegionMarker |= isCustomRegionElement(nextAfterComments);
nextAfterComments = nextAfterComments.getNextSibling();
}
if (nextAfterComments == null)
return null;
if (nextAfterComments instanceof DartLibraryStatement || nextAfterComments instanceof DartPartStatement || nextAfterComments instanceof DartPartOfStatement || nextAfterComments instanceof DartImportOrExportStatement) {
if (nextAfterComments.getPrevSibling() instanceof PsiWhiteSpace)
nextAfterComments = nextAfterComments.getPrevSibling();
if (nextAfterComments.equals(firstComment))
return null;
final TextRange fileHeaderCommentsRange = new UnfairTextRange(firstComment.getTextRange().getStartOffset(), nextAfterComments.getTextRange().getStartOffset());
if (fileHeaderCommentsRange.getLength() > 1 && document.getLineNumber(fileHeaderCommentsRange.getEndOffset()) > document.getLineNumber(fileHeaderCommentsRange.getStartOffset())) {
if (!containsCustomRegionMarker) {
descriptors.add(new FoldingDescriptor(dartFile, fileHeaderCommentsRange));
}
return fileHeaderCommentsRange;
}
}
return null;
}
use of com.intellij.psi.PsiComment in project intellij-plugins by JetBrains.
the class DartFoldingBuilder method foldConsequentStatements.
private static <T extends PsiElement> void foldConsequentStatements(@NotNull final List<FoldingDescriptor> descriptors, @NotNull final DartFile dartFile, @NotNull final Class<T> aClass) {
final T firstStatement = PsiTreeUtil.getChildOfType(dartFile, aClass);
if (firstStatement == null)
return;
PsiElement lastStatement = firstStatement;
PsiElement nextElement = firstStatement;
while (aClass.isInstance(nextElement) || nextElement instanceof PsiComment || nextElement instanceof PsiWhiteSpace) {
if (aClass.isInstance(nextElement)) {
lastStatement = nextElement;
}
nextElement = nextElement.getNextSibling();
}
if (lastStatement != firstStatement) {
// after "import " or "export " or "part "
final int startOffset = firstStatement.getTextRange().getStartOffset() + firstStatement.getFirstChild().getTextLength() + 1;
final int endOffset = lastStatement.getTextRange().getEndOffset();
final FoldingDescriptor descriptor = new FoldingDescriptor(firstStatement, TextRange.create(startOffset, endOffset));
if (aClass == DartImportOrExportStatement.class) {
// imports are often added/removed automatically, so we enable autoupdate of folded region for foldings even if it's collapsed
descriptor.setCanBeRemovedWhenCollapsed(true);
}
descriptors.add(descriptor);
}
}
use of com.intellij.psi.PsiComment in project intellij-plugins by JetBrains.
the class JstdFixtureHtmlLanguageInjector method getLanguagesToInject.
@Override
public void getLanguagesToInject(@NotNull PsiLanguageInjectionHost host, @NotNull InjectedLanguagePlaces injectionPlacesRegistrar) {
if (host instanceof PsiComment) {
PsiComment comment = (PsiComment) host;
if (comment.getTokenType() == JSTokenTypes.C_STYLE_COMMENT) {
String commentStr = comment.getText();
TextRange htmlTextRange = findTextRange(commentStr);
if (htmlTextRange != null && HTML_LANGUAGE != null) {
injectionPlacesRegistrar.addPlace(HTML_LANGUAGE, htmlTextRange, null, null);
}
}
}
}
use of com.intellij.psi.PsiComment in project intellij-community by JetBrains.
the class FileHeaderChecker method checkFileHeader.
static ProblemDescriptor checkFileHeader(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean onTheFly) {
TIntObjectHashMap<String> offsetToProperty = new TIntObjectHashMap<>();
FileTemplate defaultTemplate = FileTemplateManager.getInstance(file.getProject()).getDefaultTemplate(FileTemplateManager.FILE_HEADER_TEMPLATE_NAME);
Pattern pattern = FileTemplateUtil.getTemplatePattern(defaultTemplate, file.getProject(), offsetToProperty);
Matcher matcher = pattern.matcher(file.getViewProvider().getContents());
if (!matcher.matches()) {
return null;
}
PsiComment element = PsiTreeUtil.findElementOfClassAtRange(file, matcher.start(1), matcher.end(1), PsiComment.class);
if (element == null) {
return null;
}
LocalQuickFix[] fixes = createQuickFix(matcher, offsetToProperty, file.getProject(), onTheFly);
String description = InspectionsBundle.message("default.file.template.description");
return manager.createProblemDescriptor(element, description, onTheFly, fixes, ProblemHighlightType.GENERIC_ERROR_OR_WARNING);
}
Aggregations