Search in sources :

Example 1 with BuildElement

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];
}
Also used : TargetExpression(com.google.idea.blaze.base.lang.buildfile.psi.TargetExpression) AssignmentStatement(com.google.idea.blaze.base.lang.buildfile.psi.AssignmentStatement) FunctionStatement(com.google.idea.blaze.base.lang.buildfile.psi.FunctionStatement) Parameter(com.google.idea.blaze.base.lang.buildfile.psi.Parameter) ForStatement(com.google.idea.blaze.base.lang.buildfile.psi.ForStatement) StatementList(com.google.idea.blaze.base.lang.buildfile.psi.StatementList) Expression(com.google.idea.blaze.base.lang.buildfile.psi.Expression) BuildFile(com.google.idea.blaze.base.lang.buildfile.psi.BuildFile) Processor(com.intellij.util.Processor) PsiElement(com.intellij.psi.PsiElement) PsiFile(com.intellij.psi.PsiFile) LoadedSymbol(com.google.idea.blaze.base.lang.buildfile.psi.LoadedSymbol) PsiNamedElement(com.intellij.psi.PsiNamedElement) BuildElement(com.google.idea.blaze.base.lang.buildfile.psi.BuildElement) PsiFileSystemItem(com.intellij.psi.PsiFileSystemItem) Nullable(javax.annotation.Nullable) PsiNamedElement(com.intellij.psi.PsiNamedElement) LoadedSymbol(com.google.idea.blaze.base.lang.buildfile.psi.LoadedSymbol) PsiElement(com.intellij.psi.PsiElement) BuildElement(com.google.idea.blaze.base.lang.buildfile.psi.BuildElement) Nullable(javax.annotation.Nullable)

Example 2 with BuildElement

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();
}
Also used : ASTNode(com.intellij.lang.ASTNode) FileASTNode(com.intellij.lang.FileASTNode) BuildElement(com.google.idea.blaze.base.lang.buildfile.psi.BuildElement) Test(org.junit.Test)

Example 3 with BuildElement

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();
}
Also used : ASTNode(com.intellij.lang.ASTNode) FileASTNode(com.intellij.lang.FileASTNode) BuildElement(com.google.idea.blaze.base.lang.buildfile.psi.BuildElement) Test(org.junit.Test)

Example 4 with BuildElement

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();
}
Also used : ASTNode(com.intellij.lang.ASTNode) FileASTNode(com.intellij.lang.FileASTNode) BuildElement(com.google.idea.blaze.base.lang.buildfile.psi.BuildElement) Test(org.junit.Test)

Example 5 with BuildElement

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();
}
Also used : ASTNode(com.intellij.lang.ASTNode) FileASTNode(com.intellij.lang.FileASTNode) BuildElement(com.google.idea.blaze.base.lang.buildfile.psi.BuildElement) Test(org.junit.Test)

Aggregations

BuildElement (com.google.idea.blaze.base.lang.buildfile.psi.BuildElement)6 ASTNode (com.intellij.lang.ASTNode)4 FileASTNode (com.intellij.lang.FileASTNode)4 Test (org.junit.Test)4 PsiElement (com.intellij.psi.PsiElement)2 Nullable (javax.annotation.Nullable)2 AssignmentStatement (com.google.idea.blaze.base.lang.buildfile.psi.AssignmentStatement)1 BuildFile (com.google.idea.blaze.base.lang.buildfile.psi.BuildFile)1 BuildListType (com.google.idea.blaze.base.lang.buildfile.psi.BuildListType)1 Expression (com.google.idea.blaze.base.lang.buildfile.psi.Expression)1 ForStatement (com.google.idea.blaze.base.lang.buildfile.psi.ForStatement)1 FunctionStatement (com.google.idea.blaze.base.lang.buildfile.psi.FunctionStatement)1 LoadedSymbol (com.google.idea.blaze.base.lang.buildfile.psi.LoadedSymbol)1 Parameter (com.google.idea.blaze.base.lang.buildfile.psi.Parameter)1 StatementList (com.google.idea.blaze.base.lang.buildfile.psi.StatementList)1 StatementListContainer (com.google.idea.blaze.base.lang.buildfile.psi.StatementListContainer)1 TargetExpression (com.google.idea.blaze.base.lang.buildfile.psi.TargetExpression)1 Document (com.intellij.openapi.editor.Document)1 LogicalPosition (com.intellij.openapi.editor.LogicalPosition)1 PsiFile (com.intellij.psi.PsiFile)1