use of com.intellij.lang.ASTNode in project intellij-community by JetBrains.
the class PyArgumentListImpl method addArgumentFirst.
public void addArgumentFirst(PyExpression arg) {
ASTNode node = getNode();
ASTNode[] pars = node.getChildren(TokenSet.create(PyTokenTypes.LPAR));
if (pars.length == 0) {
// there's no starting paren
try {
add(arg);
} catch (IncorrectOperationException e1) {
throw new IllegalStateException(e1);
}
} else {
ASTNode before = PyPsiUtils.getNextNonWhitespaceSibling(pars[0]);
ASTNode anchorBefore;
if (before != null && elementPrecedesElementsOfType(before, PythonDialectsTokenSetProvider.INSTANCE.getExpressionTokens())) {
ASTNode comma = createComma();
node.addChild(comma, before);
node.addChild(ASTFactory.whitespace(" "), before);
anchorBefore = comma;
} else {
anchorBefore = before;
}
ASTNode argNode = arg.getNode();
if (anchorBefore == null) {
node.addChild(argNode);
} else {
node.addChild(argNode, anchorBefore);
}
}
}
use of com.intellij.lang.ASTNode in project intellij-community by JetBrains.
the class PyArgumentListImpl method getClosingParen.
@Nullable
public ASTNode getClosingParen() {
ASTNode node = getNode();
final ASTNode[] children = node.getChildren(TokenSet.create(PyTokenTypes.RPAR));
return children.length == 0 ? null : children[children.length - 1];
}
use of com.intellij.lang.ASTNode in project intellij-community by JetBrains.
the class PyBinaryExpressionImpl method getPsiOperator.
@Nullable
public PsiElement getPsiOperator() {
ASTNode node = getNode();
final ASTNode child = node.findChildByType(PyElementTypes.BINARY_OPS);
if (child != null)
return child.getPsi();
return null;
}
use of com.intellij.lang.ASTNode in project intellij-community by JetBrains.
the class GroovyCodeStyleManagerImpl method addLineFeedBefore.
protected void addLineFeedBefore(@NotNull PsiElement psiFile, @NotNull GrImportStatement result) {
final CodeStyleSettings commonSettings = CodeStyleSettingsManager.getInstance(psiFile.getProject()).getCurrentSettings();
final GroovyCodeStyleSettings settings = commonSettings.getCustomSettings(GroovyCodeStyleSettings.class);
final PackageEntryTable layoutTable = settings.IMPORT_LAYOUT_TABLE;
final PackageEntry[] entries = layoutTable.getEntries();
PsiElement prev = result.getPrevSibling();
while (PsiImplUtil.isWhiteSpaceOrNls(prev)) {
prev = prev.getPrevSibling();
}
if (PsiImplUtil.hasElementType(prev, GroovyTokenTypes.mSEMI))
prev = prev.getPrevSibling();
if (PsiImplUtil.isWhiteSpaceOrNls(prev))
prev = prev.getPrevSibling();
ASTNode node = psiFile.getNode();
if (prev instanceof GrImportStatement) {
final int idx_before = getPackageEntryIdx(entries, (GrImportStatement) prev);
final int idx = getPackageEntryIdx(entries, result);
final int spaceCount = getMaxSpaceCount(entries, idx_before, idx);
//skip space and semicolon after import
if (PsiImplUtil.isWhiteSpaceOrNls(prev.getNextSibling()) && PsiImplUtil.hasElementType(prev.getNextSibling().getNextSibling(), GroovyTokenTypes.mSEMI))
prev = prev.getNextSibling().getNextSibling();
while (PsiImplUtil.isWhiteSpaceOrNls(prev.getNextSibling())) {
node.removeChild(prev.getNextSibling().getNode());
}
node.addLeaf(GroovyTokenTypes.mNLS, StringUtil.repeat("\n", spaceCount + 1), result.getNode());
} else if (prev instanceof GrPackageDefinition) {
node.addLeaf(GroovyTokenTypes.mNLS, StringUtil.repeat("\n", commonSettings.BLANK_LINES_AFTER_PACKAGE), result.getNode());
}
}
use of com.intellij.lang.ASTNode in project intellij-community by JetBrains.
the class StubsTest method doTest.
public void doTest() throws Exception {
final List<String> data = TestUtils.readInput(getTestDataPath() + "/" + getTestName(true) + ".test");
String fileText = data.get(0);
PsiFile psiFile = TestUtils.createPseudoPhysicalGroovyFile(getProject(), fileText);
ASTNode node = psiFile.getNode();
Assert.assertNotNull(node);
IElementType type = node.getElementType();
Assert.assertTrue(type instanceof IStubFileElementType);
IStubFileElementType stubFileType = (IStubFileElementType) type;
StubBuilder builder = stubFileType.getBuilder();
StubElement element = builder.buildStubTree(psiFile);
StringBuffer buffer = new StringBuffer();
getStubsTreeImpl(element, buffer, "");
String stubTree = buffer.toString().trim();
assertEquals(data.get(1), stubTree);
}
Aggregations