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