use of com.google.idea.blaze.base.lang.buildfile.psi.BuildElement in project intellij by bazelbuild.
the class ResolveUtil method findInScope.
/**
* Walks up PSI tree of local file, checking PsiNamedElements
*/
@Nullable
public static PsiNamedElement findInScope(PsiElement element, String name) {
PsiNamedElement[] resultHolder = new PsiNamedElement[1];
Processor<BuildElement> processor = buildElement -> {
if (buildElement == element) {
return true;
}
if (buildElement instanceof PsiNamedElement && name.equals(buildElement.getName())) {
resultHolder[0] = (PsiNamedElement) buildElement;
return false;
} else if (buildElement instanceof LoadedSymbol) {
LoadedSymbol loadedSymbol = (LoadedSymbol) buildElement;
if (name.equals(loadedSymbol.getSymbolString())) {
PsiElement referencedElement = loadedSymbol.getVisibleElement();
if (referencedElement instanceof PsiNamedElement) {
resultHolder[0] = (PsiNamedElement) referencedElement;
return false;
}
}
}
return true;
};
searchInScope(element, processor);
return resultHolder[0];
}
use of com.google.idea.blaze.base.lang.buildfile.psi.BuildElement in project intellij by bazelbuild.
the class BuildParserTest method testFunctionCall.
@Test
public void testFunctionCall() throws Exception {
ASTNode tree = createAST("function(name = 'foo', srcs, *args, **kwargs)");
List<BuildElement> stmts = getTopLevelNodesOfType(tree, BuildElement.class);
assertThat(stmts).hasSize(1);
assertThat(treeToString(tree)).isEqualTo(Joiner.on("").join("function_call(reference, arg_list(", "keyword(string), ", "positional(reference), ", "*(reference), ", "**(reference)))"));
assertNoErrors();
}
use of com.google.idea.blaze.base.lang.buildfile.psi.BuildElement in project intellij by bazelbuild.
the class BuildParserTest method testParseBuildFileWithSingeRule.
@Test
public void testParseBuildFileWithSingeRule() throws Exception {
ASTNode tree = createAST("genrule(name = 'foo',", " srcs = ['input.csv'],", " outs = [ 'result.txt',", " 'result.log'],", " cmd = 'touch result.txt result.log')");
List<BuildElement> stmts = getTopLevelNodesOfType(tree, BuildElement.class);
assertThat(stmts).hasSize(1);
assertNoErrors();
}
use of com.google.idea.blaze.base.lang.buildfile.psi.BuildElement in project intellij by bazelbuild.
the class BuildParserTest method testParseBuildFileWithMultipleRules.
@Test
public void testParseBuildFileWithMultipleRules() throws Exception {
ASTNode tree = createAST("genrule(name = 'foo',", " srcs = ['input.csv'],", " outs = [ 'result.txt',", " 'result.log'],", " srcs = ['input.csv'],", " cmd = 'touch result.txt result.log')", "", "genrule(name = 'bar',", " outs = [ 'graph.svg'],", " cmd = 'touch graph.svg')");
List<BuildElement> stmts = getTopLevelNodesOfType(tree, BuildElement.class);
assertThat(stmts).hasSize(2);
assertNoErrors();
}
use of com.google.idea.blaze.base.lang.buildfile.psi.BuildElement in project intellij by bazelbuild.
the class BuildParserTest method testFunctionDefinition.
@Test
public void testFunctionDefinition() throws Exception {
ASTNode tree = createAST("def function(name = 'foo', srcs, outs, *args, **kwargs):", " native.java_library(", " name = name,", " srcs = srcs,", " )", " return");
List<BuildElement> stmts = getTopLevelNodesOfType(tree, BuildElement.class);
assertThat(stmts).hasSize(1);
assertNoErrors();
}
Aggregations