mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
use correct language level when creating name identifiers for renamed elements (EA-43620 - CCE: PyElementGeneratorImpl.createNameIdentifier)
This commit is contained in:
@@ -29,7 +29,7 @@ public abstract class PyElementGenerator {
|
||||
return ServiceManager.getService(project, PyElementGenerator.class);
|
||||
}
|
||||
|
||||
public abstract ASTNode createNameIdentifier(String name);
|
||||
public abstract ASTNode createNameIdentifier(String name, LanguageLevel languageLevel);
|
||||
|
||||
/**
|
||||
* str must have quotes around it and be fully escaped.
|
||||
|
||||
@@ -713,6 +713,10 @@ public class PyUtil {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static ASTNode createNewName(PyElement element, String name) {
|
||||
return PyElementGenerator.getInstance(element.getProject()).createNameIdentifier(name, LanguageLevel.forElement(element));
|
||||
}
|
||||
|
||||
public static class KnownDecoratorProviderHolder {
|
||||
public static PyKnownDecoratorProvider[] KNOWN_DECORATOR_PROVIDERS = Extensions.getExtensions(PyKnownDecoratorProvider.EP_NAME);
|
||||
|
||||
|
||||
@@ -108,7 +108,7 @@ public class PyClassImpl extends PyPresentableElementImpl<PyClassStub> implement
|
||||
}
|
||||
|
||||
public PsiElement setName(@NotNull String name) throws IncorrectOperationException {
|
||||
final ASTNode nameElement = PyElementGenerator.getInstance(getProject()).createNameIdentifier(name);
|
||||
final ASTNode nameElement = PyUtil.createNewName(this, name);
|
||||
final ASTNode node = getNameNode();
|
||||
if (node != null) {
|
||||
getNode().replaceChild(node, nameElement);
|
||||
|
||||
@@ -172,10 +172,10 @@ public class PyDecoratorImpl extends StubBasedPsiElementBase<PyDecoratorStub> im
|
||||
|
||||
public PsiElement setName(@NonNls @NotNull String name) throws IncorrectOperationException {
|
||||
final ASTNode node = getNode();
|
||||
final ASTNode name_node = node.findChildByType(PyTokenTypes.IDENTIFIER);
|
||||
if (name_node != null) {
|
||||
final ASTNode nameElement = PyElementGenerator.getInstance(getProject()).createNameIdentifier(name);
|
||||
node.replaceChild(name_node, nameElement);
|
||||
final ASTNode nameNode = node.findChildByType(PyTokenTypes.IDENTIFIER);
|
||||
if (nameNode != null) {
|
||||
final ASTNode nameElement = PyUtil.createNewName(this, name);
|
||||
node.replaceChild(nameNode, nameElement);
|
||||
return this;
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -49,8 +49,8 @@ public class PyElementGeneratorImpl extends PyElementGenerator {
|
||||
myProject = project;
|
||||
}
|
||||
|
||||
public ASTNode createNameIdentifier(String name) {
|
||||
final PsiFile dummyFile = createDummyFile(LanguageLevel.getDefault(), name);
|
||||
public ASTNode createNameIdentifier(String name, LanguageLevel languageLevel) {
|
||||
final PsiFile dummyFile = createDummyFile(languageLevel, name);
|
||||
final PyExpressionStatement expressionStatement = (PyExpressionStatement)dummyFile.getFirstChild();
|
||||
final PyReferenceExpression refExpression = (PyReferenceExpression)expressionStatement.getFirstChild();
|
||||
|
||||
|
||||
@@ -104,7 +104,7 @@ public class PyFunctionImpl extends PyPresentableElementImpl<PyFunctionStub> imp
|
||||
}
|
||||
|
||||
public PsiElement setName(@NotNull String name) throws IncorrectOperationException {
|
||||
final ASTNode nameElement = PyElementGenerator.getInstance(getProject()).createNameIdentifier(name);
|
||||
final ASTNode nameElement = PyUtil.createNewName(this, name);
|
||||
final ASTNode nameNode = getNameNode();
|
||||
if (nameNode != null) {
|
||||
getNode().replaceChild(nameNode, nameElement);
|
||||
|
||||
@@ -91,7 +91,7 @@ public class PyNamedParameterImpl extends PyPresentableElementImpl<PyNamedParame
|
||||
public PsiElement setName(@NotNull String name) throws IncorrectOperationException {
|
||||
final ASTNode oldNameIdentifier = getNameIdentifierNode();
|
||||
if (oldNameIdentifier != null) {
|
||||
final ASTNode nameElement = PyElementGenerator.getInstance(getProject()).createNameIdentifier(name);
|
||||
final ASTNode nameElement = PyUtil.createNewName(this, name);
|
||||
getNode().replaceChild(oldNameIdentifier, nameElement);
|
||||
}
|
||||
return this;
|
||||
|
||||
@@ -107,7 +107,7 @@ public class PyTargetExpressionImpl extends PyPresentableElementImpl<PyTargetExp
|
||||
public PsiElement setName(@NotNull String name) throws IncorrectOperationException {
|
||||
final ASTNode oldNameElement = getNameElement();
|
||||
if (oldNameElement != null) {
|
||||
final ASTNode nameElement = PyElementGenerator.getInstance(getProject()).createNameIdentifier(name);
|
||||
final ASTNode nameElement = PyUtil.createNewName(this, name);
|
||||
getNode().replaceChild(oldNameElement, nameElement);
|
||||
}
|
||||
return this;
|
||||
|
||||
@@ -398,7 +398,7 @@ public class PyReferenceImpl implements PsiReferenceEx, PsiPolyVariantReference
|
||||
newElementName = newElementName.substring(0, newElementName.length() - PyNames.DOT_PY.length());
|
||||
}
|
||||
if (nameElement != null && PyNames.isIdentifier(newElementName)) {
|
||||
final ASTNode newNameElement = PyElementGenerator.getInstance(myElement.getProject()).createNameIdentifier(newElementName);
|
||||
final ASTNode newNameElement = PyUtil.createNewName(myElement, newElementName);
|
||||
myElement.getNode().replaceChild(nameElement, newNameElement);
|
||||
}
|
||||
return myElement;
|
||||
|
||||
Reference in New Issue
Block a user