Search in sources :

Example 21 with StringLiteral

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

the class LabelReferenceTest method testAbsoluteLabelInSkylarkExtension.

@Test
public void testAbsoluteLabelInSkylarkExtension() {
    BuildFile targetFile = createBuildFile(new WorkspacePath("java/com/google/foo/BUILD"), "rule(name = \"foo\")");
    BuildFile referencingFile = createBuildFile(new WorkspacePath("java/com/google/foo/skylark.bzl"), "LIST = ['//java/com/google/foo:foo']");
    FuncallExpression target = targetFile.findRule("foo");
    assertThat(target).isNotNull();
    StringLiteral label = PsiUtils.findFirstChildOfClassRecursive(referencingFile, StringLiteral.class);
    assertThat(label.getReferencedElement()).isEqualTo(target);
}
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) FuncallExpression(com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression) Test(org.junit.Test)

Example 22 with StringLiteral

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

the class LabelReferenceTest method testExternalFileReference.

@Test
public void testExternalFileReference() {
    BuildFile file = createBuildFile(new WorkspacePath("java/com/google/BUILD"), "exports_files([\"test.txt\", \"//java/com/google:plugin.xml\"])");
    PsiFile txtFile = workspace.createPsiFile(new WorkspacePath("java/com/google/test.txt"));
    PsiFile xmlFile = workspace.createPsiFile(new WorkspacePath("java/com/google/plugin.xml"));
    List<StringLiteral> strings = PsiUtils.findAllChildrenOfClassRecursive(file, StringLiteral.class);
    assertThat(strings).hasSize(2);
    assertThat(strings.get(0).getReferencedElement()).isEqualTo(txtFile);
    assertThat(strings.get(1).getReferencedElement()).isEqualTo(xmlFile);
}
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) PsiFile(com.intellij.psi.PsiFile) Test(org.junit.Test)

Example 23 with StringLiteral

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

the class LabelReferenceTest method testLocalRuleReference.

@Test
public void testLocalRuleReference() {
    BuildFile file = createBuildFile(new WorkspacePath("java/com/google/BUILD"), "java_library(name = \"lib\")", "java_library(name = \"foo\", deps = [\":lib\"])", "java_library(name = \"bar\", deps = [\"//java/com/google:lib\"])");
    FuncallExpression lib = file.findRule("lib");
    FuncallExpression foo = file.findRule("foo");
    FuncallExpression bar = file.findRule("bar");
    assertThat(lib).isNotNull();
    StringLiteral label = PsiUtils.findFirstChildOfClassRecursive(foo.getKeywordArgument("deps"), StringLiteral.class);
    assertThat(label.getReferencedElement()).isEqualTo(lib);
    label = PsiUtils.findFirstChildOfClassRecursive(bar.getKeywordArgument("deps"), StringLiteral.class);
    assertThat(label.getReferencedElement()).isEqualTo(lib);
}
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) FuncallExpression(com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression) Test(org.junit.Test)

Example 24 with StringLiteral

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

the class BlazeBuildFileRunConfigurationProducerTest method testConfigWithDifferentLabelIgnored.

@Test
public void testConfigWithDifferentLabelIgnored() {
    PsiFile buildFile = workspace.createPsiFile(new WorkspacePath("java/com/google/test/BUILD"), "java_test(name='unit_tests'");
    StringLiteral nameString = PsiUtils.findFirstChildOfClassRecursive(buildFile, StringLiteral.class);
    ConfigurationContext context = createContextFromPsi(nameString);
    BlazeCommandRunConfiguration config = (BlazeCommandRunConfiguration) context.getConfiguration().getConfiguration();
    // modify the label, and check that is enough for the producer to class it as different.
    config.setTarget(Label.create("//java/com/google/test:integration_tests"));
    assertThat(new BlazeBuildFileRunConfigurationProducer().isConfigurationFromContext(config, context)).isFalse();
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) BlazeBuildFileRunConfigurationProducer(com.google.idea.blaze.base.run.producers.BlazeBuildFileRunConfigurationProducer) ConfigurationContext(com.intellij.execution.actions.ConfigurationContext) StringLiteral(com.google.idea.blaze.base.lang.buildfile.psi.StringLiteral) PsiFile(com.intellij.psi.PsiFile) BlazeCommandRunConfiguration(com.google.idea.blaze.base.run.BlazeCommandRunConfiguration) Test(org.junit.Test)

Aggregations

StringLiteral (com.google.idea.blaze.base.lang.buildfile.psi.StringLiteral)24 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)20 Test (org.junit.Test)20 BuildFile (com.google.idea.blaze.base.lang.buildfile.psi.BuildFile)17 FuncallExpression (com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression)11 PsiFile (com.intellij.psi.PsiFile)7 Argument (com.google.idea.blaze.base.lang.buildfile.psi.Argument)5 BlazeCommandRunConfiguration (com.google.idea.blaze.base.run.BlazeCommandRunConfiguration)4 ConfigurationContext (com.intellij.execution.actions.ConfigurationContext)4 PsiReference (com.intellij.psi.PsiReference)4 BlazeBuildFileRunConfigurationProducer (com.google.idea.blaze.base.run.producers.BlazeBuildFileRunConfigurationProducer)3 PsiElement (com.intellij.psi.PsiElement)3 FunctionStatement (com.google.idea.blaze.base.lang.buildfile.psi.FunctionStatement)2 Truth.assertThat (com.google.common.truth.Truth.assertThat)1 BuildFileIntegrationTestCase (com.google.idea.blaze.base.lang.buildfile.BuildFileIntegrationTestCase)1 Keyword (com.google.idea.blaze.base.lang.buildfile.psi.Argument.Keyword)1 ArgumentList (com.google.idea.blaze.base.lang.buildfile.psi.ArgumentList)1 Expression (com.google.idea.blaze.base.lang.buildfile.psi.Expression)1 GlobExpression (com.google.idea.blaze.base.lang.buildfile.psi.GlobExpression)1 ListLiteral (com.google.idea.blaze.base.lang.buildfile.psi.ListLiteral)1