use of com.google.idea.blaze.base.lang.buildfile.psi.Parameter in project intellij by bazelbuild.
the class LocalReferenceTest method testReferenceToFunctionArg.
@Test
public void testReferenceToFunctionArg() {
BuildFile file = createBuildFile(new WorkspacePath("java/com/google/defs.bzl"), "def function(arg1, arg2):", " arg1(arg2)");
FunctionStatement def = file.findFunctionInScope("function");
FuncallExpression call = PsiUtils.findFirstChildOfClassRecursive(file, FuncallExpression.class);
Parameter fnParam = def.getParameterList().findParameterByName("arg1");
assertThat(fnParam).isNotNull();
assertThat(call.getReference().resolve()).isEqualTo(fnParam);
}
use of com.google.idea.blaze.base.lang.buildfile.psi.Parameter in project intellij by bazelbuild.
the class RenameRefactoringTest method testRenameFunctionParameter.
@Test
public void testRenameFunctionParameter() {
BuildFile extFile = createBuildFile(new WorkspacePath("java/com/google/tools/build_defs.bzl"), "def function(name, deps)");
BuildFile buildFile = createBuildFile(new WorkspacePath("java/com/google/BUILD"), "load(", "\"//java/com/google/tools:build_defs.bzl\",", "\"function\"", ")", "function(name = \"name\", deps = []");
FunctionStatement fn = extFile.findChildByClass(FunctionStatement.class);
Parameter param = fn.getParameterList().findParameterByName("deps");
testFixture.renameElement(param, "exports");
assertFileContents(extFile, "def function(name, exports)");
assertFileContents(buildFile, "load(", "\"//java/com/google/tools:build_defs.bzl\",", "\"function\"", ")", "function(name = \"name\", exports = []");
}
use of com.google.idea.blaze.base.lang.buildfile.psi.Parameter in project intellij by bazelbuild.
the class KeywordArgumentReference method resolve.
/**
* Find the referenced function. If it has a keyword parameter with matching name, return that.
* Otherwise if it has a **kwargs param, return that. Else return the function itself.
*/
@Nullable
@Override
public PsiElement resolve() {
String keyword = myElement.getName();
if (keyword == null) {
return null;
}
FunctionStatement function = resolveFunction();
if (function == null) {
return null;
}
Parameter.StarStar kwargsParameter = null;
for (Parameter param : function.getParameters()) {
if (param instanceof Parameter.StarStar) {
kwargsParameter = (Parameter.StarStar) param;
continue;
}
if (keyword.equals(param.getName())) {
return param;
}
}
if (kwargsParameter != null) {
return kwargsParameter;
}
return null;
}
use of com.google.idea.blaze.base.lang.buildfile.psi.Parameter in project intellij by bazelbuild.
the class ArgumentReference method getVariants.
@Override
public Object[] getVariants() {
FunctionStatement function = resolveFunction();
if (function == null) {
return EMPTY_ARRAY;
}
List<LookupElement> params = Lists.newArrayList();
for (Parameter param : function.getParameters()) {
params.add(new NamedBuildLookupElement(param, QuoteType.NoQuotes));
}
return params.toArray();
}
use of com.google.idea.blaze.base.lang.buildfile.psi.Parameter in project intellij by bazelbuild.
the class ResolveUtil method searchInScope.
/**
* Walks up PSI tree of local file, checking PsiNamedElements
*/
public static void searchInScope(PsiElement originalElement, Processor<BuildElement> processor) {
// TODO: Handle list comprehension (where variable is defined *later* in the code)
boolean topLevelScope = true;
PsiElement element = originalElement;
while (!(element instanceof PsiFileSystemItem)) {
PsiElement parent = element.getParent();
if (parent instanceof BuildFile) {
if (!((BuildFile) parent).searchSymbolsInScope(processor, topLevelScope ? element : null)) {
return;
}
} else if (parent instanceof FunctionStatement) {
topLevelScope = false;
for (Parameter param : ((FunctionStatement) parent).getParameters()) {
if (!processor.process(param)) {
return;
}
}
} else if (parent instanceof ForStatement) {
for (Expression expr : ((ForStatement) parent).getForLoopVariables()) {
if (expr instanceof TargetExpression && !processor.process(expr)) {
return;
}
}
} else if (parent instanceof StatementList) {
if (!visitChildAssignmentStatements((BuildElement) parent, (Processor) processor)) {
return;
}
}
element = parent;
}
}
Aggregations