use of com.intellij.lang.ASTNode in project intellij-community by JetBrains.
the class PyParameterListImpl method addParameter.
public void addParameter(final PyNamedParameter param) {
PsiElement paren = getLastChild();
if (paren != null && ")".equals(paren.getText())) {
// the closing paren will be this
ASTNode beforeWhat = paren.getNode();
PyParameter[] params = getParameters();
final boolean hasDefaultValue = param.hasDefaultValue();
boolean isLast = true;
for (PyParameter p : params) {
if (!hasDefaultValue && p.hasDefaultValue()) {
beforeWhat = p.getNode();
isLast = false;
break;
}
if (p instanceof PyNamedParameter) {
PyNamedParameter named = (PyNamedParameter) p;
if (named.isKeywordContainer() || named.isPositionalContainer()) {
beforeWhat = p.getNode();
isLast = false;
break;
}
}
}
final ASTNode previous = PyPsiUtils.getPrevNonWhitespaceSibling(beforeWhat);
PyUtil.addListNode(this, param, beforeWhat, !isLast || params.length == 0 || previous.getElementType() == PyTokenTypes.COMMA, isLast, beforeWhat.getElementType() != PyTokenTypes.RPAR);
}
}
use of com.intellij.lang.ASTNode in project intellij-community by JetBrains.
the class PyPrefixExpressionImpl method getPsiOperator.
@Nullable
public PsiElement getPsiOperator() {
final ASTNode node = getNode();
final ASTNode child = node.findChildByType(PyElementTypes.UNARY_OPS);
return child != null ? child.getPsi() : null;
}
use of com.intellij.lang.ASTNode in project intellij-community by JetBrains.
the class PyStatementListImpl method addInternal.
@Override
public ASTNode addInternal(ASTNode first, ASTNode last, ASTNode anchor, Boolean before) {
if (first.getPsi() instanceof PyStatement && getStatements().length == 1) {
ASTNode treePrev = getNode().getTreePrev();
if (treePrev != null && treePrev.getElementType() == TokenType.WHITE_SPACE && !treePrev.textContains('\n')) {
ASTNode lineBreak = ASTFactory.whitespace("\n");
treePrev.getTreeParent().replaceChild(treePrev, lineBreak);
}
}
return super.addInternal(first, last, anchor, before);
}
use of com.intellij.lang.ASTNode in project intellij-community by JetBrains.
the class PyStringLiteralExpressionImpl method getType.
public PyType getType(@NotNull TypeEvalContext context, @NotNull TypeEvalContext.Key key) {
final List<ASTNode> nodes = getStringNodes();
if (nodes.size() > 0) {
String text = getStringNodes().get(0).getText();
PyFile file = PsiTreeUtil.getParentOfType(this, PyFile.class);
if (file != null) {
IElementType type = PythonHighlightingLexer.convertStringType(getStringNodes().get(0).getElementType(), text, LanguageLevel.forElement(this), file.hasImportFromFuture(FutureFeature.UNICODE_LITERALS));
if (PyTokenTypes.UNICODE_NODES.contains(type)) {
return PyBuiltinCache.getInstance(this).getUnicodeType(LanguageLevel.forElement(this));
}
}
}
return PyBuiltinCache.getInstance(this).getBytesType(LanguageLevel.forElement(this));
}
use of com.intellij.lang.ASTNode in project intellij-community by JetBrains.
the class PyStringLiteralExpressionImpl method getDecodedFragments.
@Override
@NotNull
public List<Pair<TextRange, String>> getDecodedFragments() {
if (myDecodedFragments == null) {
final List<Pair<TextRange, String>> result = new ArrayList<>();
final int elementStart = getTextRange().getStartOffset();
final boolean unicodeByDefault = isUnicodeByDefault();
for (ASTNode node : getStringNodes()) {
final String text = node.getText();
final TextRange textRange = getNodeTextRange(text);
final int offset = node.getTextRange().getStartOffset() - elementStart + textRange.getStartOffset();
final String encoded = textRange.substring(text);
final boolean hasRawPrefix = PyStringLiteralUtil.isRawPrefix(PyStringLiteralUtil.getPrefix(text));
final boolean hasUnicodePrefix = PyStringLiteralUtil.isUnicodePrefix(PyStringLiteralUtil.getPrefix(text));
result.addAll(getDecodedFragments(encoded, offset, hasRawPrefix, unicodeByDefault || hasUnicodePrefix));
}
myDecodedFragments = result;
}
return myDecodedFragments;
}
Aggregations