mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
resolve for lambda parameters
This commit is contained in:
@@ -14,6 +14,9 @@ public interface PyElementTypes {
|
||||
PyStubElementType FUNCTION_DECLARATION = new PyFunctionElementType();
|
||||
PyStubElementType CLASS_DECLARATION = new PyClassElementType();
|
||||
PyStubElementType PARAMETER_LIST = new PyParameterListElementType();
|
||||
|
||||
TokenSet PARAMETER_LIST_SET = TokenSet.create(PARAMETER_LIST);
|
||||
|
||||
PyStubElementType FORMAL_PARAMETER = new PyFormalParameterElementType();
|
||||
|
||||
PyElementType DECORATED_FUNCTION_DECLARATION = new PyElementType("DECORATED_FUNCTION_DECLARATION", PyDecoratedFunctionImpl.class);
|
||||
|
||||
@@ -24,4 +24,5 @@ package com.jetbrains.python.psi;
|
||||
* To change this template use File | Settings | File Templates.
|
||||
*/
|
||||
public interface PyLambdaExpression extends PyExpression {
|
||||
PyParameterList getParameterList();
|
||||
}
|
||||
|
||||
@@ -17,9 +17,16 @@
|
||||
package com.jetbrains.python.psi.impl;
|
||||
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.ResolveState;
|
||||
import com.intellij.psi.scope.PsiScopeProcessor;
|
||||
import com.jetbrains.python.PyElementTypes;
|
||||
import com.jetbrains.python.psi.PyElementVisitor;
|
||||
import com.jetbrains.python.psi.PyLambdaExpression;
|
||||
import com.jetbrains.python.psi.PyParameter;
|
||||
import com.jetbrains.python.psi.PyParameterList;
|
||||
import com.jetbrains.python.psi.types.PyType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
@@ -40,4 +47,18 @@ public class PyLambdaExpressionImpl extends PyElementImpl implements PyLambdaExp
|
||||
public PyType getType() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public PyParameterList getParameterList() {
|
||||
return childToPsiNotNull(PyElementTypes.PARAMETER_LIST_SET, 0);
|
||||
}
|
||||
|
||||
public boolean processDeclarations(@NotNull final PsiScopeProcessor processor, @NotNull final ResolveState state, final PsiElement lastParent,
|
||||
@NotNull final PsiElement place) {
|
||||
PyParameter[] parameters = getParameterList().getParameters();
|
||||
for(PyParameter param: parameters) {
|
||||
if (param == lastParent) continue;
|
||||
if (!processor.execute(param, state)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
lambda aa: a<ref>a[1]
|
||||
@@ -8,10 +8,7 @@ import com.intellij.openapi.application.PathManager;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiReference;
|
||||
import com.intellij.testFramework.ResolveTestCase;
|
||||
import com.jetbrains.python.psi.PyClass;
|
||||
import com.jetbrains.python.psi.PyFunction;
|
||||
import com.jetbrains.python.psi.PyTargetExpression;
|
||||
import com.jetbrains.python.psi.PyAssignmentStatement;
|
||||
import com.jetbrains.python.psi.*;
|
||||
|
||||
public class PyResolveTest extends ResolveTestCase {
|
||||
private PsiElement resolve() throws Exception {
|
||||
@@ -70,6 +67,11 @@ public class PyResolveTest extends ResolveTestCase {
|
||||
assertTrue(targetElement.getParent() instanceof PyAssignmentStatement);
|
||||
}
|
||||
|
||||
public void testLambda() throws Exception {
|
||||
PsiElement targetElement = resolve();
|
||||
assertTrue(targetElement instanceof PyParameter);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return PathManager.getHomePath() + "/plugins/python/testData/resolve/";
|
||||
|
||||
Reference in New Issue
Block a user