Search in sources :

Example 16 with StringLiteral

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

the class LoadStatementAnnotator method visitLoadedSymbol.

@Override
public void visitLoadedSymbol(LoadedSymbol node) {
    StringLiteral loadedString = node.getImport();
    if (loadedString == null) {
        return;
    }
    String name = loadedString.getStringContents();
    if (name.startsWith("_")) {
        markError(node, String.format("Symbol '%s' is private and cannot be imported.", name));
    }
}
Also used : StringLiteral(com.google.idea.blaze.base.lang.buildfile.psi.StringLiteral)

Example 17 with StringLiteral

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

the class DeprecatedLoadQuickFixTest method testParentDirectoryHasNoBuildFile.

@Test
public void testParentDirectoryHasNoBuildFile() {
    BuildFile file = createBuildFile(new WorkspacePath("java/com/google/BUILD"), "load('/java/com/google/subdir/build_defs', 'symbol')");
    StringLiteral string = PsiUtils.findFirstChildOfClassRecursive(file, StringLiteral.class);
    applyQuickFix(string);
    assertThat(string.getStringContents()).isEqualTo("//java/com/google:subdir/build_defs.bzl");
}
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) Test(org.junit.Test)

Example 18 with StringLiteral

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

the class DeprecatedLoadQuickFixTest method testBlazePackageIsParentDirectory.

@Test
public void testBlazePackageIsParentDirectory() {
    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', 'symbol')");
    StringLiteral string = PsiUtils.findFirstChildOfClassRecursive(file, StringLiteral.class);
    applyQuickFix(string);
    assertThat(string.getStringContents()).isEqualTo("//foo/bar:build_defs.bzl");
}
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 19 with StringLiteral

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

the class RenameRefactoringTest method testRenameJavaClass.

@Test
public void testRenameJavaClass() {
    PsiFile javaFile = workspace.createPsiFile(new WorkspacePath("com/google/foo/JavaClass.java"), "package com.google.foo;", "public class JavaClass {}");
    createBuildFile(new WorkspacePath("com/google/foo/BUILD"), "java_library(name = \"ref1\", srcs = [\"//com/google/foo:JavaClass.java\"])", "java_library(name = \"ref2\", srcs = [\"JavaClass.java\"])", "java_library(name = \"ref3\", srcs = [\":JavaClass.java\"])");
    List<StringLiteral> references = findAllReferencingElementsOfType(javaFile, StringLiteral.class);
    Set<String> oldStrings = references.stream().map(StringLiteral::getStringContents).collect(Collectors.toSet());
    assertThat(references).hasSize(3);
    testFixture.renameElement(javaFile, "NewName.java");
    Set<String> newStrings = references.stream().map(StringLiteral::getStringContents).collect(Collectors.toSet());
    Set<String> expectedNewStrings = oldStrings.stream().map((s) -> s.replaceAll("JavaClass", "NewName")).collect(Collectors.toSet());
    assertThat(expectedNewStrings).containsExactlyElementsIn(newStrings);
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) Arrays(java.util.Arrays) RenamePsiElementProcessor(com.intellij.refactoring.rename.RenamePsiElementProcessor) FuncallExpression(com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression) VirtualFile(com.intellij.openapi.vfs.VirtualFile) Parameter(com.google.idea.blaze.base.lang.buildfile.psi.Parameter) RunWith(org.junit.runner.RunWith) PsiManager(com.intellij.psi.PsiManager) BuildFile(com.google.idea.blaze.base.lang.buildfile.psi.BuildFile) RenameUtil(com.intellij.refactoring.rename.RenameUtil) BuildFileIntegrationTestCase(com.google.idea.blaze.base.lang.buildfile.BuildFileIntegrationTestCase) PsiElement(com.intellij.psi.PsiElement) PsiFile(com.intellij.psi.PsiFile) MoveDirectoryWithClassesProcessor(com.intellij.refactoring.move.moveClassesOrPackages.MoveDirectoryWithClassesProcessor) TargetExpression(com.google.idea.blaze.base.lang.buildfile.psi.TargetExpression) FunctionStatement(com.google.idea.blaze.base.lang.buildfile.psi.FunctionStatement) StringLiteral(com.google.idea.blaze.base.lang.buildfile.psi.StringLiteral) PsiUtils(com.google.idea.blaze.base.lang.buildfile.psi.util.PsiUtils) PsiReference(com.intellij.psi.PsiReference) Set(java.util.Set) IOException(java.io.IOException) Test(org.junit.Test) RenameDialog(com.intellij.refactoring.rename.RenameDialog) JUnit4(org.junit.runners.JUnit4) Truth.assertThat(com.google.common.truth.Truth.assertThat) Collectors(java.util.stream.Collectors) List(java.util.List) FindUsages(com.google.idea.blaze.base.lang.buildfile.search.FindUsages) PsiDirectory(com.intellij.psi.PsiDirectory) 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 20 with StringLiteral

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

the class ExternalWorkspaceReferenceTest method testLocalTargetReferenceWithinExternalWorkspaceResolves.

@Test
public void testLocalTargetReferenceWithinExternalWorkspaceResolves() {
    BuildFile externalFile = (BuildFile) createFileInExternalWorkspace("junit", new WorkspacePath("BUILD"), "java_import(", "    name = 'jar',", "    jars = ['junit-4.11.jar'],", ")", "java_library(", "    name = 'lib',", "    srcs = [':jar'],", ")");
    FuncallExpression target = externalFile.findRule("jar");
    assertThat(target).isNotNull();
    Argument.Keyword arg = externalFile.findRule("lib").getKeywordArgument("srcs");
    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