mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Extracted CythonReferenceExpression with its own getReference()
This commit is contained in:
@@ -16,4 +16,5 @@ public interface PythonDialectsTokenSetContributor {
|
||||
TokenSet getParameterTokens();
|
||||
TokenSet getFunctionDeclarationTokens();
|
||||
TokenSet getUnbalancedBracesRecoveryTokens();
|
||||
TokenSet getReferenceExpressionTokens();
|
||||
}
|
||||
|
||||
@@ -72,8 +72,6 @@ public interface PyElementTypes {
|
||||
PyElementType EMPTY_EXPRESSION = new PyElementType("EMPTY_EXPRESSION", PyEmptyExpressionImpl.class);
|
||||
PyElementType REFERENCE_EXPRESSION = new PyElementType("REFERENCE_EXPRESSION", PyReferenceExpressionImpl.class);
|
||||
|
||||
TokenSet REFERENCE_EXPRESSION_SET = TokenSet.create(REFERENCE_EXPRESSION);
|
||||
|
||||
PyStubElementType<PyTargetExpressionStub, PyTargetExpression> TARGET_EXPRESSION = new PyTargetExpressionElementType();
|
||||
PyElementType INTEGER_LITERAL_EXPRESSION = new PyElementType("INTEGER_LITERAL_EXPRESSION", PyNumericLiteralExpressionImpl.class);
|
||||
PyElementType FLOAT_LITERAL_EXPRESSION = new PyElementType("FLOAT_LITERAL_EXPRESSION", PyNumericLiteralExpressionImpl.class);
|
||||
|
||||
@@ -16,6 +16,7 @@ public class PythonDialectsTokenSetProvider {
|
||||
private final TokenSet myParameterTokens;
|
||||
private final TokenSet myFunctionDeclarationTokens;
|
||||
private final TokenSet myUnbalancedBracesRecoveryTokens;
|
||||
private final TokenSet myReferenceExpressionTokens;
|
||||
|
||||
private PythonDialectsTokenSetProvider() {
|
||||
TokenSet stmts = TokenSet.EMPTY;
|
||||
@@ -25,6 +26,7 @@ public class PythonDialectsTokenSetProvider {
|
||||
TokenSet parameters = TokenSet.EMPTY;
|
||||
TokenSet functionDeclarations = TokenSet.EMPTY;
|
||||
TokenSet recoveryTokens = TokenSet.EMPTY;
|
||||
TokenSet referenceExpressions = TokenSet.EMPTY;
|
||||
for(PythonDialectsTokenSetContributor contributor: Extensions.getExtensions(PythonDialectsTokenSetContributor.EP_NAME)) {
|
||||
stmts = TokenSet.orSet(stmts, contributor.getStatementTokens());
|
||||
exprs = TokenSet.orSet(exprs, contributor.getExpressionTokens());
|
||||
@@ -33,6 +35,7 @@ public class PythonDialectsTokenSetProvider {
|
||||
parameters = TokenSet.orSet(parameters, contributor.getParameterTokens());
|
||||
functionDeclarations = TokenSet.orSet(functionDeclarations, contributor.getFunctionDeclarationTokens());
|
||||
recoveryTokens = TokenSet.orSet(recoveryTokens, contributor.getUnbalancedBracesRecoveryTokens());
|
||||
referenceExpressions = TokenSet.orSet(referenceExpressions, contributor.getReferenceExpressionTokens());
|
||||
}
|
||||
myStatementTokens = stmts;
|
||||
myExpressionTokens = exprs;
|
||||
@@ -41,6 +44,7 @@ public class PythonDialectsTokenSetProvider {
|
||||
myParameterTokens = parameters;
|
||||
myFunctionDeclarationTokens = functionDeclarations;
|
||||
myUnbalancedBracesRecoveryTokens = recoveryTokens;
|
||||
myReferenceExpressionTokens = referenceExpressions;
|
||||
}
|
||||
|
||||
public TokenSet getStatementTokens() {
|
||||
@@ -70,4 +74,8 @@ public class PythonDialectsTokenSetProvider {
|
||||
public TokenSet getUnbalancedBracesRecoveryTokens() {
|
||||
return myUnbalancedBracesRecoveryTokens;
|
||||
}
|
||||
|
||||
public TokenSet getReferenceExpressionTokens() {
|
||||
return myReferenceExpressionTokens;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,4 +70,9 @@ public class PythonTokenSetContributor implements PythonDialectsTokenSetContribu
|
||||
return TokenSet.create(DEF_KEYWORD, CLASS_KEYWORD, RETURN_KEYWORD, WITH_KEYWORD, WHILE_KEYWORD, BREAK_KEYWORD, CONTINUE_KEYWORD,
|
||||
RAISE_KEYWORD, TRY_KEYWORD, EXCEPT_KEYWORD, FINALLY_KEYWORD);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TokenSet getReferenceExpressionTokens() {
|
||||
return TokenSet.create(REFERENCE_EXPRESSION);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.jetbrains.python.PyElementTypes;
|
||||
import com.jetbrains.python.PyTokenTypes;
|
||||
import com.jetbrains.python.PythonDialectsTokenSetProvider;
|
||||
import com.jetbrains.python.psi.*;
|
||||
import com.jetbrains.python.psi.resolve.PyResolveContext;
|
||||
import com.jetbrains.python.psi.resolve.PyResolveUtil;
|
||||
@@ -47,7 +48,7 @@ public class PyDecoratorImpl extends StubBasedPsiElementBase<PyDecoratorStub> im
|
||||
}
|
||||
|
||||
public boolean isBuiltin() {
|
||||
ASTNode node = getNode().findChildByType(PyElementTypes.REFERENCE_EXPRESSION_SET);
|
||||
ASTNode node = getNode().findChildByType(PythonDialectsTokenSetProvider.INSTANCE.getReferenceExpressionTokens());
|
||||
if (node != null) {
|
||||
PyReferenceExpression ref = (PyReferenceExpression)node.getPsi();
|
||||
PsiElement target = ref.getReference().resolve();
|
||||
|
||||
@@ -8,6 +8,7 @@ import com.intellij.util.ArrayFactory;
|
||||
import com.jetbrains.python.PyElementTypes;
|
||||
import com.jetbrains.python.PyNames;
|
||||
import com.jetbrains.python.PyTokenTypes;
|
||||
import com.jetbrains.python.PythonDialectsTokenSetProvider;
|
||||
import com.jetbrains.python.psi.*;
|
||||
import com.jetbrains.python.psi.resolve.ResolveImportUtil;
|
||||
import com.jetbrains.python.psi.stubs.PyFromImportStatementStub;
|
||||
@@ -49,7 +50,7 @@ public class PyFromImportStatementImpl extends PyBaseElementImpl<PyFromImportSta
|
||||
|
||||
@Nullable
|
||||
public PyReferenceExpression getImportSource() {
|
||||
return childToPsi(PyElementTypes.REFERENCE_EXPRESSION_SET, 0);
|
||||
return childToPsi(PythonDialectsTokenSetProvider.INSTANCE.getReferenceExpressionTokens(), 0);
|
||||
}
|
||||
|
||||
public PyQualifiedName getImportSourceQName() {
|
||||
|
||||
@@ -10,6 +10,7 @@ import com.intellij.psi.stubs.IStubElementType;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.util.containers.EmptyIterable;
|
||||
import com.jetbrains.python.PyElementTypes;
|
||||
import com.jetbrains.python.PythonDialectsTokenSetProvider;
|
||||
import com.jetbrains.python.psi.*;
|
||||
import com.jetbrains.python.psi.resolve.PyResolveUtil;
|
||||
import com.jetbrains.python.psi.resolve.ResolveImportUtil;
|
||||
@@ -41,7 +42,7 @@ public class PyImportElementImpl extends PyBaseElementImpl<PyImportElementStub>
|
||||
|
||||
@Nullable
|
||||
public PyReferenceExpression getImportReferenceExpression() {
|
||||
final ASTNode node = getNode().findChildByType(PyElementTypes.REFERENCE_EXPRESSION_SET);
|
||||
final ASTNode node = getNode().findChildByType(PythonDialectsTokenSetProvider.INSTANCE.getReferenceExpressionTokens());
|
||||
return node == null ? null : (PyReferenceExpression) node.getPsi();
|
||||
}
|
||||
|
||||
|
||||
@@ -6,11 +6,6 @@ import com.intellij.openapi.extensions.Extensions;
|
||||
import com.intellij.openapi.util.Ref;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.jetbrains.cython.CythonLanguageDialect;
|
||||
import com.jetbrains.cython.psi.CythonCImportElement;
|
||||
import com.jetbrains.cython.psi.CythonFromCImportStatement;
|
||||
import com.jetbrains.cython.psi.CythonImportReference;
|
||||
import com.jetbrains.cython.psi.CythonReference;
|
||||
import com.jetbrains.python.PyNames;
|
||||
import com.jetbrains.python.PyTokenTypes;
|
||||
import com.jetbrains.python.PythonDialectsTokenSetProvider;
|
||||
@@ -56,12 +51,6 @@ public class PyReferenceExpressionImpl extends PyElementImpl implements PyRefere
|
||||
final PyExpression qualifier = getQualifier();
|
||||
|
||||
// Handle import reference
|
||||
final boolean inCythonFile = CythonLanguageDialect.isInsideCythonFile(this);
|
||||
if (inCythonFile) {
|
||||
if (PsiTreeUtil.getParentOfType(this, CythonCImportElement.class, CythonFromCImportStatement.class) != null) {
|
||||
return new CythonImportReference(this, context);
|
||||
}
|
||||
}
|
||||
final PsiElement importParent = PsiTreeUtil.getParentOfType(this, PyImportElement.class, PyFromImportStatement.class);
|
||||
if (importParent != null) {
|
||||
return PyImportReference.forElement(this, importParent, context);
|
||||
@@ -80,10 +69,6 @@ public class PyReferenceExpressionImpl extends PyElementImpl implements PyRefere
|
||||
return new PyQualifiedReference(this, context);
|
||||
}
|
||||
|
||||
if (inCythonFile) {
|
||||
return new CythonReference(this, context);
|
||||
}
|
||||
|
||||
return new PyReferenceImpl(this, context);
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.util.io.StringRef;
|
||||
import com.jetbrains.python.PyElementTypes;
|
||||
import com.jetbrains.python.PyNames;
|
||||
import com.jetbrains.python.PythonDialectsTokenSetProvider;
|
||||
import com.jetbrains.python.documentation.DocStringUtil;
|
||||
import com.jetbrains.python.psi.*;
|
||||
import com.jetbrains.python.psi.impl.PyQualifiedName;
|
||||
@@ -118,7 +119,7 @@ public class PyTargetExpressionElementType extends PyStubElementType<PyTargetExp
|
||||
return false;
|
||||
}
|
||||
final ASTNode functionNode = TreeUtil.findParent(node, PyElementTypes.FUNCTION_DECLARATION);
|
||||
final ASTNode qualifierNode = node.findChildByType(PyElementTypes.REFERENCE_EXPRESSION_SET);
|
||||
final ASTNode qualifierNode = node.findChildByType(PythonDialectsTokenSetProvider.INSTANCE.getReferenceExpressionTokens());
|
||||
if (functionNode != null && qualifierNode != null) {
|
||||
final PsiElement function = functionNode.getPsi();
|
||||
if (function instanceof PyFunction && PyNames.NEW.equals(((PyFunction)function).getName())) {
|
||||
|
||||
Reference in New Issue
Block a user