use of com.google.idea.blaze.base.lang.buildfile.psi.StringLiteral in project intellij by bazelbuild.
the class BuildDocumentationProvider method buildDocs.
private static String buildDocs(DocStringOwner element) {
StringBuilder docs = new StringBuilder();
describeFile(element.getContainingFile(), docs, !(element instanceof BuildFile));
if (element instanceof FunctionStatement) {
describeFunction((FunctionStatement) element, docs);
}
StringLiteral docString = element.getDocString();
if (docString != null) {
docs.append(DocStringFormatter.formatDocString(docString, element));
}
return wrapDocInHtml(docs.toString());
}
use of com.google.idea.blaze.base.lang.buildfile.psi.StringLiteral in project intellij by bazelbuild.
the class BuildTargetElementEvaluator method getParentFuncallIfNameString.
@Nullable
private static FuncallExpression getParentFuncallIfNameString(PsiElement element) {
PsiElement parent = element.getParent();
if (!(parent instanceof StringLiteral)) {
return null;
}
parent = parent.getParent();
if (!(parent instanceof Keyword)) {
return null;
}
if (!Objects.equals(((Keyword) parent).getName(), "name")) {
return null;
}
parent = parent.getParent();
if (!(parent instanceof ArgumentList)) {
return null;
}
parent = parent.getParent();
return parent instanceof FuncallExpression ? (FuncallExpression) parent : null;
}
use of com.google.idea.blaze.base.lang.buildfile.psi.StringLiteral in project intellij by bazelbuild.
the class ExternalWorkspaceFindUsagesTest method testFindUsagesFromExternalWorkspaceFile.
@Test
public void testFindUsagesFromExternalWorkspaceFile() {
BuildFile workspaceBuildFile = createBuildFile(new WorkspacePath("BUILD"), "java_library(", " name = 'lib',", " exports = ['@junit//:jar'],", ")");
BuildFile externalFile = (BuildFile) createFileInExternalWorkspace("junit", new WorkspacePath("BUILD"), "java_import(", " name = 'jar',", " jars = ['junit-4.11.jar'],", ")");
FuncallExpression target = externalFile.findRule("jar");
assertThat(target).isNotNull();
Argument.Keyword arg = workspaceBuildFile.findRule("lib").getKeywordArgument("exports");
StringLiteral label = PsiUtils.findFirstChildOfClassRecursive(arg, StringLiteral.class);
assertThat(label).isNotNull();
PsiReference[] references = FindUsages.findAllReferences(target);
assertThat(references).hasLength(1);
assertThat(references[0].getElement()).isEqualTo(label);
}
use of com.google.idea.blaze.base.lang.buildfile.psi.StringLiteral in project intellij by bazelbuild.
the class ExternalWorkspaceFindUsagesTest method testFindUsagesFromWorkspaceFile.
@Test
public void testFindUsagesFromWorkspaceFile() {
BuildFile workspaceBuildFile = createBuildFile(new WorkspacePath("WORKSPACE"), "maven_jar(", " name = 'javax_inject',", " artifact = 'javax.inject:javax.inject:1',", " sha1 = '6975da39a7040257bd51d21a231b76c915872d38',", ")");
BuildFile refFile1 = createBuildFile(new WorkspacePath("java/com/foo/BUILD"), "java_library(name = 'javax_inject', exports = ['@javax_inject//jar'])");
BuildFile refFile2 = createBuildFile(new WorkspacePath("java/com/bar/build_defs.bzl"), "DEP = '@javax_inject//invalid:nonsense'");
FuncallExpression target = workspaceBuildFile.findRule("javax_inject");
StringLiteral ref1 = PsiUtils.findFirstChildOfClassRecursive(refFile1.findRule("javax_inject").getKeywordArgument("exports"), StringLiteral.class);
StringLiteral ref2 = PsiUtils.findFirstChildOfClassRecursive(refFile2, StringLiteral.class);
PsiReference[] references = FindUsages.findAllReferences(target);
assertThat(references).hasLength(2);
assertThat(Arrays.stream(references).map(PsiReference::getElement).collect(Collectors.toList())).containsExactly(ref1, ref2);
}
use of com.google.idea.blaze.base.lang.buildfile.psi.StringLiteral in project intellij by bazelbuild.
the class GlobReference method resolveListContents.
private static List<String> resolveListContents(Expression expr) {
if (expr == null) {
return ImmutableList.of();
}
PsiElement rootElement = PsiUtils.getReferencedTargetValue(expr);
if (!(rootElement instanceof ListLiteral)) {
return ImmutableList.of();
}
Expression[] children = ((ListLiteral) rootElement).getElements();
List<String> strings = Lists.newArrayListWithCapacity(children.length);
for (Expression child : children) {
if (child instanceof StringLiteral) {
strings.add(((StringLiteral) child).getStringContents());
}
}
return strings;
}
Aggregations