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