use of com.intellij.psi.PsiWhiteSpace in project intellij-plugins by JetBrains.
the class DartDocUtil method getMultilineDocCommentText.
@NotNull
private static String getMultilineDocCommentText(@NotNull final DartDocComment docComment) {
final StringBuilder buf = new StringBuilder();
boolean afterAsterisk = false;
for (PsiElement child = docComment.getFirstChild(); child != null; child = child.getNextSibling()) {
final IElementType elementType = child.getNode().getElementType();
final String text = child.getText();
if (elementType != DartTokenTypesSets.MULTI_LINE_DOC_COMMENT_START && elementType != DartTokenTypesSets.DOC_COMMENT_LEADING_ASTERISK && elementType != DartTokenTypesSets.MULTI_LINE_COMMENT_END) {
int newLinesCount;
if (child instanceof PsiWhiteSpace && (newLinesCount = StringUtil.countNewLines(text)) > 0) {
buf.append(StringUtil.repeatSymbol('\n', newLinesCount));
} else {
if (afterAsterisk && text.startsWith(" ")) {
buf.append(text.substring(1));
} else {
buf.append(text);
}
}
}
afterAsterisk = elementType == DartTokenTypesSets.DOC_COMMENT_LEADING_ASTERISK;
}
return buf.toString();
}
use of com.intellij.psi.PsiWhiteSpace in project intellij-plugins by JetBrains.
the class DartRefactoringUtil method findExpressionInRange.
@Nullable
public static DartExpression findExpressionInRange(PsiFile file, int startOffset, int endOffset) {
PsiElement element1 = file.findElementAt(startOffset);
PsiElement element2 = file.findElementAt(endOffset - 1);
if (element1 instanceof PsiWhiteSpace) {
startOffset = element1.getTextRange().getEndOffset();
}
if (element2 instanceof PsiWhiteSpace) {
endOffset = element2.getTextRange().getStartOffset();
}
DartExpression expression = PsiTreeUtil.findElementOfClassAtRange(file, startOffset, endOffset, DartExpression.class);
if (expression == null || expression.getTextRange().getEndOffset() != endOffset)
return null;
if (expression instanceof DartReference && expression.getParent() instanceof DartCallExpression)
return null;
return expression;
}
use of com.intellij.psi.PsiWhiteSpace in project intellij-plugins by JetBrains.
the class AngularJSIndexingHandler method processJSDocComment.
@Override
public JSElementIndexingData processJSDocComment(@NotNull final JSDocComment comment, @Nullable JSElementIndexingData outData) {
JSDocTag ngdocTag = null;
JSDocTag nameTag = null;
for (JSDocTag tag : comment.getTags()) {
if ("ngdoc".equals(tag.getName()))
ngdocTag = tag;
else if ("name".equals(tag.getName()))
nameTag = tag;
}
if (ngdocTag != null && nameTag != null) {
final JSDocTagValue nameValue = nameTag.getValue();
String name = nameValue != null ? nameValue.getText() : null;
if (name != null)
name = name.substring(name.indexOf(':') + 1);
String ngdocValue = null;
PsiElement nextSibling = ngdocTag.getNextSibling();
if (nextSibling instanceof PsiWhiteSpace)
nextSibling = nextSibling.getNextSibling();
if (nextSibling != null && nextSibling.getNode().getElementType() == JSDocTokenTypes.DOC_COMMENT_DATA) {
ngdocValue = nextSibling.getText();
}
if (ngdocValue != null && name != null) {
final String[] commentLines = StringUtil.splitByLines(comment.getText());
final boolean directive = ngdocValue.contains(DIRECTIVE);
final boolean component = ngdocValue.contains(COMPONENT);
if (directive || component) {
final String restrictions = calculateRestrictions(commentLines, directive ? DEFAULT_RESTRICTIONS : "E");
if (outData == null)
outData = new JSElementIndexingDataImpl();
addImplicitElements(comment, directive ? DIRECTIVE : COMPONENT, AngularDirectivesDocIndex.KEY, name, restrictions, outData);
} else if (ngdocValue.contains(FILTER)) {
if (outData == null)
outData = new JSElementIndexingDataImpl();
addImplicitElements(comment, FILTER, AngularFilterIndex.KEY, name, null, outData);
}
}
}
return outData;
}
use of com.intellij.psi.PsiWhiteSpace in project intellij-plugins by JetBrains.
the class DartRefactoringUtil method findStatementsInRange.
@NotNull
public static PsiElement[] findStatementsInRange(PsiFile file, int startOffset, int endOffset) {
PsiElement element1 = file.findElementAt(startOffset);
PsiElement element2 = file.findElementAt(endOffset - 1);
if (element1 instanceof PsiWhiteSpace) {
startOffset = element1.getTextRange().getEndOffset();
element1 = file.findElementAt(startOffset);
}
if (element2 instanceof PsiWhiteSpace) {
endOffset = element2.getTextRange().getStartOffset();
element2 = file.findElementAt(endOffset - 1);
}
if (element1 != null && element2 != null) {
PsiElement commonParent = PsiTreeUtil.findCommonParent(element1, element2);
if (commonParent instanceof DartExpression) {
return new PsiElement[] { commonParent };
}
}
final DartStatements statements = PsiTreeUtil.getParentOfType(element1, DartStatements.class);
if (statements == null || element2 == null || !PsiTreeUtil.isAncestor(statements, element2, true)) {
return PsiElement.EMPTY_ARRAY;
}
// don't forget about leafs (ex. ';')
final ASTNode[] astResult = UsefulPsiTreeUtil.findChildrenRange(statements.getNode().getChildren(null), startOffset, endOffset);
return ContainerUtil.map2Array(astResult, PsiElement.class, ASTNode::getPsi);
}
use of com.intellij.psi.PsiWhiteSpace in project intellij-community by JetBrains.
the class SMTRunnerConsoleProperties method findSuitableNavigatableForLine.
@Nullable
protected Navigatable findSuitableNavigatableForLine(@NotNull Project project, @NotNull VirtualFile file, int line) {
// lets find first non-ws psi element
final Document doc = FileDocumentManager.getInstance().getDocument(file);
final PsiFile psi = doc == null ? null : PsiDocumentManager.getInstance(project).getPsiFile(doc);
if (psi == null) {
return null;
}
int offset = doc.getLineStartOffset(line);
int endOffset = doc.getLineEndOffset(line);
for (int i = offset + 1; i < endOffset; i++) {
PsiElement el = psi.findElementAt(i);
if (el != null && !(el instanceof PsiWhiteSpace)) {
offset = el.getTextOffset();
break;
}
}
return new OpenFileDescriptor(project, file, offset);
}
Aggregations