Search in sources :

Example 1 with ReferenceExpression

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

the class LoadedSkylarkExtensionTest method testLoadedSymbolReference.

@Test
public void testLoadedSymbolReference() {
    BuildFile extFile = createBuildFile(new WorkspacePath("java/com/google/tools/build_defs.bzl"), "CONSTANT = 1");
    BuildFile buildFile = createBuildFile(new WorkspacePath("java/com/google/BUILD"), "load(", "\"//java/com/google/tools:build_defs.bzl\",", "\"CONSTANT\"", ")", "NEW_CONSTANT = CONSTANT");
    TargetExpression target = PsiUtils.findFirstChildOfClassRecursive(extFile, TargetExpression.class);
    ReferenceExpression ref = PsiUtils.findFirstChildOfClassRecursive(buildFile, ReferenceExpression.class);
    LoadedSymbol loadElement = PsiUtils.findFirstChildOfClassRecursive(buildFile, LoadedSymbol.class);
    assertThat(target).isNotNull();
    assertThat(ref.getReferencedElement()).isEqualTo(target);
    assertThat(loadElement.getImport().getReferencedElement()).isEqualTo(target);
    assertThat(Arrays.stream(FindUsages.findAllReferences(target)).map(PsiReference::getElement).collect(Collectors.toList())).containsExactly(ref, loadElement.getImport());
}
Also used : BuildFile(com.google.idea.blaze.base.lang.buildfile.psi.BuildFile) WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) LoadedSymbol(com.google.idea.blaze.base.lang.buildfile.psi.LoadedSymbol) TargetExpression(com.google.idea.blaze.base.lang.buildfile.psi.TargetExpression) ReferenceExpression(com.google.idea.blaze.base.lang.buildfile.psi.ReferenceExpression) Test(org.junit.Test)

Example 2 with ReferenceExpression

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

the class HighlightingAnnotatorTest method testBuiltInNamesSimple.

@Test
public void testBuiltInNamesSimple() {
    BuildFile file = createBuildFile(new WorkspacePath("BUILD"), "None");
    ReferenceExpression ref = file.findChildByClass(ReferenceExpression.class);
    assertThat(ref.getText()).isEqualTo("None");
    editorTest.openFileInEditor(file.getVirtualFile());
    List<HighlightInfo> result = testFixture.doHighlighting();
    assertThat(result).hasSize(1);
    assertThat(result.get(0).startOffset).isEqualTo(ref.getNode().getStartOffset());
    assertThat(result.get(0).forcedTextAttributesKey).isEqualTo(BuildSyntaxHighlighter.BUILD_BUILTIN_NAME);
}
Also used : BuildFile(com.google.idea.blaze.base.lang.buildfile.psi.BuildFile) WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) HighlightInfo(com.intellij.codeInsight.daemon.impl.HighlightInfo) ReferenceExpression(com.google.idea.blaze.base.lang.buildfile.psi.ReferenceExpression) Test(org.junit.Test)

Example 3 with ReferenceExpression

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

the class HighlightingAnnotatorTest method testBuiltInNames.

@Test
public void testBuiltInNames() {
    BuildFile file = createBuildFile(new WorkspacePath("BUILD"), "a = True", "b = False", "type(a)");
    List<ReferenceExpression> refs = PsiUtils.findAllChildrenOfClassRecursive(file, ReferenceExpression.class);
    assertThat(refs).hasSize(4);
    assertThat(refs.get(0).getText()).isEqualTo("True");
    assertThat(refs.get(1).getText()).isEqualTo("False");
    assertThat(refs.get(2).getText()).isEqualTo("type");
    editorTest.openFileInEditor(file.getVirtualFile());
    List<HighlightInfo> result = testFixture.doHighlighting();
    assertThat(result).hasSize(3);
    for (int i = 0; i < result.size(); i++) {
        assertThat(result.get(i).startOffset).isEqualTo(refs.get(i).getNode().getStartOffset());
        assertThat(result.get(i).forcedTextAttributesKey).isEqualTo(BuildSyntaxHighlighter.BUILD_BUILTIN_NAME);
    }
}
Also used : BuildFile(com.google.idea.blaze.base.lang.buildfile.psi.BuildFile) WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) HighlightInfo(com.intellij.codeInsight.daemon.impl.HighlightInfo) ReferenceExpression(com.google.idea.blaze.base.lang.buildfile.psi.ReferenceExpression) Test(org.junit.Test)

Example 4 with ReferenceExpression

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

the class LocalReferenceTest method testReferenceInsideFuncallExpression.

@Test
public void testReferenceInsideFuncallExpression() {
    BuildFile file = createBuildFile(new WorkspacePath("java/com/google/BUILD"), "a = 1", "a.function(c)");
    TargetExpression target = file.findChildByClass(AssignmentStatement.class).getLeftHandSideExpression();
    FuncallExpression funcall = file.findChildByClass(FuncallExpression.class);
    ReferenceExpression ref = funcall.firstChildOfClass(ReferenceExpression.class);
    assertThat(ref.getReferencedElement()).isEqualTo(target);
}
Also used : BuildFile(com.google.idea.blaze.base.lang.buildfile.psi.BuildFile) WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) AssignmentStatement(com.google.idea.blaze.base.lang.buildfile.psi.AssignmentStatement) TargetExpression(com.google.idea.blaze.base.lang.buildfile.psi.TargetExpression) ReferenceExpression(com.google.idea.blaze.base.lang.buildfile.psi.ReferenceExpression) FuncallExpression(com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression) Test(org.junit.Test)

Example 5 with ReferenceExpression

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

the class LocalReferenceTest method testTargetInOuterScope.

@Test
public void testTargetInOuterScope() {
    BuildFile file = createBuildFile(new WorkspacePath("java/com/google/BUILD"), "a = 1", "function(c = a)");
    TargetExpression target = file.findChildByClass(AssignmentStatement.class).getLeftHandSideExpression();
    FuncallExpression funcall = file.findChildByClass(FuncallExpression.class);
    ReferenceExpression ref = funcall.getKeywordArgument("c").firstChildOfClass(ReferenceExpression.class);
    assertThat(ref.getReferencedElement()).isEqualTo(target);
}
Also used : BuildFile(com.google.idea.blaze.base.lang.buildfile.psi.BuildFile) WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) AssignmentStatement(com.google.idea.blaze.base.lang.buildfile.psi.AssignmentStatement) TargetExpression(com.google.idea.blaze.base.lang.buildfile.psi.TargetExpression) ReferenceExpression(com.google.idea.blaze.base.lang.buildfile.psi.ReferenceExpression) FuncallExpression(com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression) Test(org.junit.Test)

Aggregations

BuildFile (com.google.idea.blaze.base.lang.buildfile.psi.BuildFile)7 ReferenceExpression (com.google.idea.blaze.base.lang.buildfile.psi.ReferenceExpression)7 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)7 Test (org.junit.Test)7 AssignmentStatement (com.google.idea.blaze.base.lang.buildfile.psi.AssignmentStatement)4 TargetExpression (com.google.idea.blaze.base.lang.buildfile.psi.TargetExpression)3 FuncallExpression (com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression)2 HighlightInfo (com.intellij.codeInsight.daemon.impl.HighlightInfo)2 LoadedSymbol (com.google.idea.blaze.base.lang.buildfile.psi.LoadedSymbol)1 PsiElement (com.intellij.psi.PsiElement)1