Search in sources :

Example 91 with WorkspacePath

use of com.google.idea.blaze.base.model.primitives.WorkspacePath in project intellij by bazelbuild.

the class GlobReferenceTest method testSimpleGlobReferencingSingleFile3.

@Test
public void testSimpleGlobReferencingSingleFile3() {
    PsiFile ref = workspace.createPsiFile(new WorkspacePath("java/com/google/Test.java"));
    BuildFile file = createBuildFile(new WorkspacePath("java/com/google/BUILD"), "glob(['T*t.java'])");
    GlobExpression glob = PsiUtils.findFirstChildOfClassRecursive(file, GlobExpression.class);
    List<PsiElement> references = multiResolve(glob);
    assertThat(references).hasSize(1);
    assertThat(references).containsExactly(ref);
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) BuildFile(com.google.idea.blaze.base.lang.buildfile.psi.BuildFile) PsiFile(com.intellij.psi.PsiFile) GlobExpression(com.google.idea.blaze.base.lang.buildfile.psi.GlobExpression) PsiElement(com.intellij.psi.PsiElement) Test(org.junit.Test)

Example 92 with WorkspacePath

use of com.google.idea.blaze.base.model.primitives.WorkspacePath in project intellij by bazelbuild.

the class KeywordReferenceTest method testKwargsReference.

@Test
public void testKwargsReference() {
    BuildFile file = createBuildFile(new WorkspacePath("java/com/google/build_defs.bzl"), "def function(name, **kwargs)", "function(name = \"name\", deps = [])");
    ArgumentList args = file.firstChildOfClass(FuncallExpression.class).getArgList();
    assertThat(args.getKeywordArgument("deps").getReferencedElement()).isInstanceOf(Parameter.StarStar.class);
}
Also used : BuildFile(com.google.idea.blaze.base.lang.buildfile.psi.BuildFile) WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) Parameter(com.google.idea.blaze.base.lang.buildfile.psi.Parameter) ArgumentList(com.google.idea.blaze.base.lang.buildfile.psi.ArgumentList) FuncallExpression(com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression) Test(org.junit.Test)

Example 93 with WorkspacePath

use of com.google.idea.blaze.base.model.primitives.WorkspacePath in project intellij by bazelbuild.

the class LabelReferenceTest method testRuleNameDoesntCrossPackageBoundaries.

@Test
public void testRuleNameDoesntCrossPackageBoundaries() {
    BuildFile targetFile = createBuildFile(new WorkspacePath("java/com/google/pkg/subpkg/BUILD"), "rule(name = \"target\")");
    BuildFile referencingFile = createBuildFile(new WorkspacePath("java/com/google/pkg/BUILD"), "rule(name = \"other\", dep = \":subpkg/target\")");
    Argument.Keyword depArgument = referencingFile.findRule("other").getKeywordArgument("dep");
    LabelReference ref = (LabelReference) depArgument.getValue().getReference();
    assertThat(ref.resolve()).isNull();
    editorTest.replaceStringContents(ref.getElement(), "//java/com/google/pkg/subpkg:target");
    assertThat(ref.resolve()).isNotNull();
    assertThat(ref.resolve()).isEqualTo(targetFile.findRule("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) Test(org.junit.Test)

Example 94 with WorkspacePath

use of com.google.idea.blaze.base.model.primitives.WorkspacePath in project intellij by bazelbuild.

the class LabelReferenceTest method testRulePreferredOverFile.

@Test
public void testRulePreferredOverFile() {
    BuildFile targetFile = createBuildFile(new WorkspacePath("java/com/foo/BUILD"), "java_library(name = 'lib')");
    workspace.createDirectory(new WorkspacePath("java/com/foo/lib"));
    BuildFile referencingFile = createBuildFile(new WorkspacePath("java/com/google/bar/BUILD"), "java_library(", "    name = 'bar',", "    src = glob(['**/*.java'])," + "    deps = ['//java/com/foo:lib'],", ")");
    FuncallExpression target = targetFile.findRule("lib");
    assertThat(target).isNotNull();
    PsiReference[] references = FindUsages.findAllReferences(target);
    assertThat(references).hasLength(1);
    PsiElement element = references[0].getElement();
    FuncallExpression rule = PsiUtils.getParentOfType(element, FuncallExpression.class, true);
    assertThat(rule.getName()).isEqualTo("bar");
    assertThat(rule.getContainingFile()).isEqualTo(referencingFile);
}
Also used : BuildFile(com.google.idea.blaze.base.lang.buildfile.psi.BuildFile) WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) PsiReference(com.intellij.psi.PsiReference) FuncallExpression(com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression) PsiElement(com.intellij.psi.PsiElement) Test(org.junit.Test)

Example 95 with WorkspacePath

use of com.google.idea.blaze.base.model.primitives.WorkspacePath in project intellij by bazelbuild.

the class BuildQuoteHandlerTest method testClosingSingleQuoteInserted.

@Test
public void testClosingSingleQuoteInserted() {
    BuildFile file = createBuildFile(new WorkspacePath("BUILD"), "");
    editorTest.performTypingAction(file, '\'');
    assertFileContents(file, "''");
}
Also used : BuildFile(com.google.idea.blaze.base.lang.buildfile.psi.BuildFile) WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) Test(org.junit.Test)

Aggregations

WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)509 Test (org.junit.Test)454 BuildFile (com.google.idea.blaze.base.lang.buildfile.psi.BuildFile)197 PsiFile (com.intellij.psi.PsiFile)84 File (java.io.File)75 ProjectView (com.google.idea.blaze.base.projectview.ProjectView)53 TargetMapBuilder (com.google.idea.blaze.base.ideinfo.TargetMapBuilder)48 Editor (com.intellij.openapi.editor.Editor)46 VirtualFile (com.intellij.openapi.vfs.VirtualFile)41 BlazeJavaImportResult (com.google.idea.blaze.java.sync.model.BlazeJavaImportResult)40 FuncallExpression (com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression)37 PsiReference (com.intellij.psi.PsiReference)37 MockBlazeProjectDataManager (com.google.idea.blaze.base.model.MockBlazeProjectDataManager)34 ConfigurationContext (com.intellij.execution.actions.ConfigurationContext)34 BlazeContentEntry (com.google.idea.blaze.java.sync.model.BlazeContentEntry)33 BlazeCommandRunConfiguration (com.google.idea.blaze.base.run.BlazeCommandRunConfiguration)29 MockBlazeProjectDataBuilder (com.google.idea.blaze.base.model.MockBlazeProjectDataBuilder)26 ImportRoots (com.google.idea.blaze.base.sync.projectview.ImportRoots)26 TargetMap (com.google.idea.blaze.base.ideinfo.TargetMap)25 PsiElement (com.intellij.psi.PsiElement)25