Search in sources :

Example 11 with StringLiteral

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());
}
Also used : BuildFile(com.google.idea.blaze.base.lang.buildfile.psi.BuildFile) FunctionStatement(com.google.idea.blaze.base.lang.buildfile.psi.FunctionStatement) StringLiteral(com.google.idea.blaze.base.lang.buildfile.psi.StringLiteral)

Example 12 with StringLiteral

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;
}
Also used : StringLiteral(com.google.idea.blaze.base.lang.buildfile.psi.StringLiteral) Keyword(com.google.idea.blaze.base.lang.buildfile.psi.Argument.Keyword) ArgumentList(com.google.idea.blaze.base.lang.buildfile.psi.ArgumentList) FuncallExpression(com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression) PsiElement(com.intellij.psi.PsiElement) Nullable(javax.annotation.Nullable)

Example 13 with StringLiteral

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);
}
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) PsiReference(com.intellij.psi.PsiReference) FuncallExpression(com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression) Test(org.junit.Test)

Example 14 with StringLiteral

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);
}
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) PsiReference(com.intellij.psi.PsiReference) FuncallExpression(com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression) Test(org.junit.Test)

Example 15 with StringLiteral

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;
}
Also used : ListLiteral(com.google.idea.blaze.base.lang.buildfile.psi.ListLiteral) StringLiteral(com.google.idea.blaze.base.lang.buildfile.psi.StringLiteral) GlobExpression(com.google.idea.blaze.base.lang.buildfile.psi.GlobExpression) Expression(com.google.idea.blaze.base.lang.buildfile.psi.Expression) PsiElement(com.intellij.psi.PsiElement)

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