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);
}
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);
}
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);
}
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();
}
Aggregations