Search in sources :

Example 16 with FuncallExpression

use of com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression in project intellij by bazelbuild.

the class ArgumentReference method resolveFunction.

@Nullable
protected FunctionStatement resolveFunction() {
    FuncallExpression call = PsiTreeUtil.getParentOfType(myElement, FuncallExpression.class);
    if (call == null) {
        return null;
    }
    PsiElement callee = call.getReferencedElement();
    return callee instanceof FunctionStatement ? (FunctionStatement) callee : null;
}
Also used : FunctionStatement(com.google.idea.blaze.base.lang.buildfile.psi.FunctionStatement) FuncallExpression(com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression) PsiElement(com.intellij.psi.PsiElement) Nullable(javax.annotation.Nullable)

Example 17 with FuncallExpression

use of com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression in project intellij by bazelbuild.

the class BuildTargetElementEvaluator method getParentFuncallIfNameString.

@Nullable
private static FuncallExpression getParentFuncallIfNameString(PsiElement element) {
    PsiElement parent = element.getParent();
    if (!(parent instanceof StringLiteral)) {
        return null;
    }
    parent = parent.getParent();
    if (!(parent instanceof Keyword)) {
        return null;
    }
    if (!Objects.equals(((Keyword) parent).getName(), "name")) {
        return null;
    }
    parent = parent.getParent();
    if (!(parent instanceof ArgumentList)) {
        return null;
    }
    parent = parent.getParent();
    return parent instanceof FuncallExpression ? (FuncallExpression) parent : null;
}
Also used : StringLiteral(com.google.idea.blaze.base.lang.buildfile.psi.StringLiteral) Keyword(com.google.idea.blaze.base.lang.buildfile.psi.Argument.Keyword) ArgumentList(com.google.idea.blaze.base.lang.buildfile.psi.ArgumentList) FuncallExpression(com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression) PsiElement(com.intellij.psi.PsiElement) Nullable(javax.annotation.Nullable)

Example 18 with FuncallExpression

use of com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression in project intellij by bazelbuild.

the class ExternalWorkspaceFindUsagesTest method testFindUsagesFromExternalWorkspaceFile.

@Test
public void testFindUsagesFromExternalWorkspaceFile() {
    BuildFile workspaceBuildFile = createBuildFile(new WorkspacePath("BUILD"), "java_library(", "    name = 'lib',", "    exports = ['@junit//:jar'],", ")");
    BuildFile externalFile = (BuildFile) createFileInExternalWorkspace("junit", new WorkspacePath("BUILD"), "java_import(", "    name = 'jar',", "    jars = ['junit-4.11.jar'],", ")");
    FuncallExpression target = externalFile.findRule("jar");
    assertThat(target).isNotNull();
    Argument.Keyword arg = workspaceBuildFile.findRule("lib").getKeywordArgument("exports");
    StringLiteral label = PsiUtils.findFirstChildOfClassRecursive(arg, StringLiteral.class);
    assertThat(label).isNotNull();
    PsiReference[] references = FindUsages.findAllReferences(target);
    assertThat(references).hasLength(1);
    assertThat(references[0].getElement()).isEqualTo(label);
}
Also used : BuildFile(com.google.idea.blaze.base.lang.buildfile.psi.BuildFile) WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) Argument(com.google.idea.blaze.base.lang.buildfile.psi.Argument) StringLiteral(com.google.idea.blaze.base.lang.buildfile.psi.StringLiteral) PsiReference(com.intellij.psi.PsiReference) FuncallExpression(com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression) Test(org.junit.Test)

Example 19 with FuncallExpression

use of com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression in project intellij by bazelbuild.

the class ExternalWorkspaceFindUsagesTest method testFindUsagesFromWorkspaceFile.

@Test
public void testFindUsagesFromWorkspaceFile() {
    BuildFile workspaceBuildFile = createBuildFile(new WorkspacePath("WORKSPACE"), "maven_jar(", "    name = 'javax_inject',", "    artifact = 'javax.inject:javax.inject:1',", "    sha1 = '6975da39a7040257bd51d21a231b76c915872d38',", ")");
    BuildFile refFile1 = createBuildFile(new WorkspacePath("java/com/foo/BUILD"), "java_library(name = 'javax_inject', exports = ['@javax_inject//jar'])");
    BuildFile refFile2 = createBuildFile(new WorkspacePath("java/com/bar/build_defs.bzl"), "DEP = '@javax_inject//invalid:nonsense'");
    FuncallExpression target = workspaceBuildFile.findRule("javax_inject");
    StringLiteral ref1 = PsiUtils.findFirstChildOfClassRecursive(refFile1.findRule("javax_inject").getKeywordArgument("exports"), StringLiteral.class);
    StringLiteral ref2 = PsiUtils.findFirstChildOfClassRecursive(refFile2, StringLiteral.class);
    PsiReference[] references = FindUsages.findAllReferences(target);
    assertThat(references).hasLength(2);
    assertThat(Arrays.stream(references).map(PsiReference::getElement).collect(Collectors.toList())).containsExactly(ref1, ref2);
}
Also used : BuildFile(com.google.idea.blaze.base.lang.buildfile.psi.BuildFile) WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) StringLiteral(com.google.idea.blaze.base.lang.buildfile.psi.StringLiteral) PsiReference(com.intellij.psi.PsiReference) FuncallExpression(com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression) Test(org.junit.Test)

Example 20 with FuncallExpression

use of com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression in project intellij by bazelbuild.

the class FindRuleUsagesTest method testLocalFullReference.

// test full package references, made locally
@Test
public void testLocalFullReference() {
    BuildFile buildFile = createBuildFile(new WorkspacePath("java/com/google/BUILD"), "java_library(name = \"target\")", "java_library(name = \"other\", deps = [\"//java/com/google:target\"]");
    FuncallExpression target = buildFile.findChildByClass(FuncallExpression.class);
    PsiReference[] references = FindUsages.findAllReferences(target);
    assertThat(references).hasLength(1);
    PsiElement ref = references[0].getElement();
    assertThat(ref).isInstanceOf(StringLiteral.class);
    assertThat(ref.getParent()).isInstanceOf(ListLiteral.class);
}
Also used : BuildFile(com.google.idea.blaze.base.lang.buildfile.psi.BuildFile) WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) PsiReference(com.intellij.psi.PsiReference) FuncallExpression(com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression) PsiElement(com.intellij.psi.PsiElement) Test(org.junit.Test)

Aggregations

FuncallExpression (com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression)44 BuildFile (com.google.idea.blaze.base.lang.buildfile.psi.BuildFile)33 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)32 Test (org.junit.Test)32 PsiElement (com.intellij.psi.PsiElement)13 StringLiteral (com.google.idea.blaze.base.lang.buildfile.psi.StringLiteral)10 PsiReference (com.intellij.psi.PsiReference)10 Argument (com.google.idea.blaze.base.lang.buildfile.psi.Argument)7 FunctionStatement (com.google.idea.blaze.base.lang.buildfile.psi.FunctionStatement)6 PsiFile (com.intellij.psi.PsiFile)6 Nullable (javax.annotation.Nullable)5 TargetExpression (com.google.idea.blaze.base.lang.buildfile.psi.TargetExpression)4 AssignmentStatement (com.google.idea.blaze.base.lang.buildfile.psi.AssignmentStatement)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 TargetMap (com.google.idea.blaze.base.ideinfo.TargetMap)2 Expression (com.google.idea.blaze.base.lang.buildfile.psi.Expression)2 LoadedSymbol (com.google.idea.blaze.base.lang.buildfile.psi.LoadedSymbol)2 ReferenceExpression (com.google.idea.blaze.base.lang.buildfile.psi.ReferenceExpression)2 BlazeProjectData (com.google.idea.blaze.base.model.BlazeProjectData)2 MockBlazeProjectDataManager (com.google.idea.blaze.base.model.MockBlazeProjectDataManager)2