use of com.google.idea.blaze.base.lang.buildfile.psi.TargetExpression in project intellij by bazelbuild.
the class LoadedSkylarkExtensionTest method testOverridenBuiltInSymbolReference.
@Test
public void testOverridenBuiltInSymbolReference() {
setBuiltInRuleNames("java_library");
BuildFile extFile = createBuildFile(new WorkspacePath("java/com/google/tools/build_defs.bzl"), "java_library = rule()");
BuildFile buildFile = createBuildFile(new WorkspacePath("java/com/google/BUILD"), "load(", "\"//java/com/google/tools:build_defs.bzl\",", "\"java_library\"", ")", "java_library(name = 'name')");
TargetExpression target = PsiUtils.findFirstChildOfClassRecursive(extFile, TargetExpression.class);
FuncallExpression funcall = buildFile.firstChildOfClass(FuncallExpression.class);
LoadedSymbol loadElement = PsiUtils.findFirstChildOfClassRecursive(buildFile, LoadedSymbol.class);
assertThat(target).isNotNull();
assertThat(funcall.getReferencedElement()).isEqualTo(target);
assertThat(loadElement.getImport().getReferencedElement()).isEqualTo(target);
assertThat(Arrays.stream(FindUsages.findAllReferences(target)).map(PsiReference::getElement).collect(Collectors.toList())).containsExactly(funcall, loadElement.getImport());
}
use of com.google.idea.blaze.base.lang.buildfile.psi.TargetExpression 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.TargetExpression in project intellij by bazelbuild.
the class RenameRefactoringTest method testRenameLocalVariable.
@Test
public void testRenameLocalVariable() {
BuildFile file = createBuildFile(new WorkspacePath("java/com/google/BUILD"), "a = 1", "c = a");
TargetExpression target = PsiUtils.findFirstChildOfClassRecursive(file, TargetExpression.class);
assertThat(target.getText()).isEqualTo("a");
testFixture.renameElement(target, "b");
assertFileContents(file, "b = 1", "c = b");
}
use of com.google.idea.blaze.base.lang.buildfile.psi.TargetExpression in project intellij by bazelbuild.
the class LocalVariableUsagesTest method testMultipleAssignments.
// the case where a symbol is the target of multiple assignment statements
@Test
public void testMultipleAssignments() {
BuildFile buildFile = createBuildFile(new WorkspacePath("java/com/google/BUILD"), "var = 5", "var += 1", "var = 0");
TargetExpression target = buildFile.findChildByClass(AssignmentStatement.class).getLeftHandSideExpression();
PsiReference[] references = FindUsages.findAllReferences(target);
assertThat(references).hasLength(2);
assertThat(references[0]).isInstanceOf(LocalReference.class);
assertThat(references[1]).isInstanceOf(TargetReference.class);
}
use of com.google.idea.blaze.base.lang.buildfile.psi.TargetExpression in project intellij by bazelbuild.
the class LocalVariableUsagesTest method testLocalReferences.
@Test
public void testLocalReferences() {
BuildFile buildFile = createBuildFile(new WorkspacePath("java/com/google/BUILD"), "localVar = 5", "funcall(localVar)", "def function(name):", " tempVar = localVar");
TargetExpression target = buildFile.findChildByClass(AssignmentStatement.class).getLeftHandSideExpression();
PsiReference[] references = FindUsages.findAllReferences(target);
assertThat(references).hasLength(2);
FuncallExpression funcall = buildFile.findChildByClass(FuncallExpression.class);
assertThat(funcall).isNotNull();
PsiElement firstRef = references[0].getElement();
assertThat(PsiUtils.getParentOfType(firstRef, FuncallExpression.class, true)).isEqualTo(funcall);
FunctionStatement function = buildFile.findChildByClass(FunctionStatement.class);
assertThat(function).isNotNull();
PsiElement secondRef = references[1].getElement();
assertThat(secondRef.getParent()).isInstanceOf(AssignmentStatement.class);
assertThat(PsiUtils.getParentOfType(secondRef, FunctionStatement.class, true)).isEqualTo(function);
}
Aggregations