Search in sources :

Example 6 with StringLiteral

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

the class DeprecatedLoadQuickFixTest method testRelativeLoadStatementUntouched.

@Test
public void testRelativeLoadStatementUntouched() {
    workspace.createPsiFile(new WorkspacePath("foo/bar/build_defs.bzl"));
    BuildFile file = createBuildFile(new WorkspacePath("foo/bar/BUILD"), "load(':build_defs.bzl', 'symbol')");
    StringLiteral string = PsiUtils.findFirstChildOfClassRecursive(file, StringLiteral.class);
    String prevString = string.getStringContents();
    applyQuickFix(string);
    assertThat(string.getStringContents()).isEqualTo(prevString);
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) BuildFile(com.google.idea.blaze.base.lang.buildfile.psi.BuildFile) StringLiteral(com.google.idea.blaze.base.lang.buildfile.psi.StringLiteral) Test(org.junit.Test)

Example 7 with StringLiteral

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

the class DeprecatedLoadQuickFixTest method testNormalLoadStatementUntouched.

@Test
public void testNormalLoadStatementUntouched() {
    workspace.createPsiFile(new WorkspacePath("foo/bar/BUILD"));
    workspace.createPsiFile(new WorkspacePath("foo/bar/build_defs.bzl"));
    BuildFile file = createBuildFile(new WorkspacePath("java/com/google/BUILD"), "load('//foo/bar:build_defs.bzl', 'symbol')");
    StringLiteral string = PsiUtils.findFirstChildOfClassRecursive(file, StringLiteral.class);
    String prevString = string.getStringContents();
    applyQuickFix(string);
    assertThat(string.getStringContents()).isEqualTo(prevString);
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) BuildFile(com.google.idea.blaze.base.lang.buildfile.psi.BuildFile) StringLiteral(com.google.idea.blaze.base.lang.buildfile.psi.StringLiteral) Test(org.junit.Test)

Example 8 with StringLiteral

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

the class ExternalWorkspaceReferenceTest method testReferenceToWorkspaceFileContents.

@Test
public void testReferenceToWorkspaceFileContents() {
    BuildFile workspaceFile = createBuildFile(new WorkspacePath("WORKSPACE"), "maven_jar(", "    name = 'w3c_css_sac',", "    artifact = 'org.w3c.css:sac:1.3',", "    sha1 = 'cdb2dcb4e22b83d6b32b93095f644c3462739e82',", ")");
    BuildFile referencingFile = createBuildFile(new WorkspacePath("java/com/google/pkg/BUILD"), "rule(", "    name = 'other',", "    dep = '@w3c_css_sac//jar'", ")");
    FuncallExpression target = workspaceFile.findRule("w3c_css_sac");
    assertThat(target).isNotNull();
    FuncallExpression other = referencingFile.findRule("other");
    StringLiteral label = PsiUtils.findFirstChildOfClassRecursive(other.getKeywordArgument("dep"), 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 9 with StringLiteral

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

the class ExternalWorkspaceReferenceTest method testFileReferenceWithinExternalWorkspaceResolves.

@Test
public void testFileReferenceWithinExternalWorkspaceResolves() {
    BuildFile externalFile = (BuildFile) createFileInExternalWorkspace("junit", new WorkspacePath("BUILD"), "java_import(", "    name = 'target',", "    jars = ['junit-4.11.jar'],", ")");
    PsiFile jarFile = createFileInExternalWorkspace("junit", new WorkspacePath("junit-4.11.jar"));
    FuncallExpression target = externalFile.findRule("target");
    StringLiteral label = PsiUtils.findFirstChildOfClassRecursive(target.getKeywordArgument("jars"), StringLiteral.class);
    assertThat(label.getReferencedElement()).isEqualTo(jarFile);
}
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) FuncallExpression(com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression) Test(org.junit.Test)

Example 10 with StringLiteral

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

the class ExternalWorkspaceReferenceTest method testExternalWorkspaceTargetReference.

@Test
public void testExternalWorkspaceTargetReference() {
    BuildFile workspaceBuildFile = createBuildFile(new WorkspacePath("BUILD"), "java_library(", "    name = 'lib',", "    exports = ['@junit//:jar'],", ")");
    BuildFile externalBuildFile = (BuildFile) createFileInExternalWorkspace("junit", new WorkspacePath("BUILD"), "java_import(", "    name = 'jar',", "    jars = ['junit-4.11.jar'],", ")");
    FuncallExpression target = externalBuildFile.findRule("jar");
    assertThat(target).isNotNull();
    Argument.Keyword arg = workspaceBuildFile.findRule("lib").getKeywordArgument("exports");
    StringLiteral label = PsiUtils.findFirstChildOfClassRecursive(arg, 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) Argument(com.google.idea.blaze.base.lang.buildfile.psi.Argument) StringLiteral(com.google.idea.blaze.base.lang.buildfile.psi.StringLiteral) FuncallExpression(com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression) 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