use of com.intellij.psi.PsiWhiteSpace in project kotlin by JetBrains.
the class UpdateKotlinCopyright method scanFile.
@Override
protected void scanFile() {
PsiElement first = getFile().getFirstChild();
PsiElement last = first;
PsiElement next = first;
while (next != null) {
if (next instanceof PsiComment || next instanceof PsiWhiteSpace) {
next = getNextSibling(next);
} else {
break;
}
last = next;
}
if (first != null) {
checkComments(first, last, true);
}
}
use of com.intellij.psi.PsiWhiteSpace in project idea-handlebars by dmarcotte.
the class HbBlockMismatchFix method invoke.
@Override
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
final int offset = editor.getCaretModel().getOffset();
PsiElement psiElement = file.findElementAt(offset);
if (psiElement == null || !psiElement.isValid())
return;
if (!FileModificationService.getInstance().prepareFileForWrite(psiElement.getContainingFile()))
return;
if (psiElement instanceof PsiWhiteSpace)
psiElement = PsiTreeUtil.prevLeaf(psiElement);
HbBlockMustache blockMustache = (HbBlockMustache) PsiTreeUtil.findFirstParent(psiElement, true, new Condition<PsiElement>() {
@Override
public boolean value(PsiElement psiElement) {
return psiElement instanceof HbBlockMustache;
}
});
if (blockMustache == null) {
return;
}
HbBlockMustache targetBlockMustache = blockMustache;
// ensure we update the open or close mustache for this block appropriately
if (myUpdateOpenMustache != (targetBlockMustache instanceof HbOpenBlockMustache)) {
targetBlockMustache = blockMustache.getPairedElement();
}
HbPath path = PsiTreeUtil.findChildOfType(targetBlockMustache, HbPath.class);
final Document document = PsiDocumentManager.getInstance(project).getDocument(file);
if (path != null && document != null) {
final TextRange textRange = path.getTextRange();
document.replaceString(textRange.getStartOffset(), textRange.getEndOffset(), myCorrectedName);
}
}
use of com.intellij.psi.PsiWhiteSpace in project idea-handlebars by dmarcotte.
the class HbErrorFilter method hasWhitespacesInHtmlBetweenErrorAndOpenTokens.
private static boolean hasWhitespacesInHtmlBetweenErrorAndOpenTokens(int offset, TemplateLanguageFileViewProvider viewProvider) {
PsiElement at = viewProvider.findElementAt(offset, viewProvider.getTemplateDataLanguage());
if (!(at instanceof PsiWhiteSpace))
return false;
PsiElement elementAt = viewProvider.findElementAt(at.getTextRange().getEndOffset() + 1, viewProvider.getBaseLanguage());
if (elementAt != null && START_TEMPLATE_TOKENS.contains(elementAt.getNode().getElementType()))
return true;
return false;
}
use of com.intellij.psi.PsiWhiteSpace in project go-lang-idea-plugin by go-lang-plugin-org.
the class GoMethodSeparatorProvider method findAnchorElement.
@NotNull
private static PsiElement findAnchorElement(@NotNull GoTopLevelDeclaration o) {
PsiElement result = o;
PsiElement p = o;
while ((p = p.getPrevSibling()) != null) {
if (p instanceof PsiComment) {
result = p;
} else if (p instanceof PsiWhiteSpace) {
if (p.getText().contains("\n\n"))
return result;
} else {
break;
}
}
return result;
}
use of com.intellij.psi.PsiWhiteSpace in project intellij-community by JetBrains.
the class SimpleSurroundDescriptor method getElementsToSurround.
@NotNull
public PsiElement[] getElementsToSurround(PsiFile file, int startOffset, int endOffset) {
// adjust start/end
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();
}
RegExpElement pattern = findElementAtStrict(file, startOffset, endOffset, RegExpPattern.class);
if (pattern != null)
return new RegExpElement[] { pattern };
RegExpElement branch = findElementAtStrict(file, startOffset, endOffset, RegExpBranch.class);
if (branch != null)
return new RegExpElement[] { branch };
List<PsiElement> atoms = new ArrayList<>();
RegExpAtom atom = PsiTreeUtil.findElementOfClassAtRange(file, startOffset, endOffset, RegExpAtom.class);
for (; atom != null; atom = PsiTreeUtil.findElementOfClassAtRange(file, startOffset, endOffset, RegExpAtom.class)) {
atoms.add(atom);
startOffset = atom.getTextRange().getEndOffset();
// handle embedded whitespace
if ((element1 = file.findElementAt(startOffset)) instanceof PsiWhiteSpace) {
startOffset = element1.getTextRange().getEndOffset();
atoms.add(element1);
}
}
if (startOffset == endOffset && atoms.size() > 0) {
PsiElement[] elements = PsiUtilCore.toPsiElementArray(atoms);
if ((atoms.size() == 1 || PsiTreeUtil.findCommonParent(elements) == elements[0].getParent())) {
return elements;
}
}
return PsiElement.EMPTY_ARRAY;
}
Aggregations