use of com.google.idea.blaze.base.lang.buildfile.psi.BuildFile in project intellij by bazelbuild.
the class BuildFileModifierImpl method addRule.
@Override
public boolean addRule(Project project, Label newRule, Kind ruleKind) {
BuildReferenceManager manager = BuildReferenceManager.getInstance(project);
File file = manager.resolvePackage(newRule.blazePackage());
if (file == null) {
return false;
}
LocalFileSystem.getInstance().refreshIoFiles(ImmutableList.of(file));
BuildFile buildFile = manager.resolveBlazePackage(newRule.blazePackage());
if (buildFile == null) {
logger.error("No BUILD file found at location: " + newRule.blazePackage());
return false;
}
buildFile.add(createRule(project, ruleKind, newRule.targetName().toString()));
return true;
}
use of com.google.idea.blaze.base.lang.buildfile.psi.BuildFile in project intellij by bazelbuild.
the class LoadedSymbolReference method getVariants.
@Override
public Object[] getVariants() {
PsiElement bzlFile = bzlFileReference.resolve();
if (!(bzlFile instanceof BuildFile)) {
return EMPTY_ARRAY;
}
CompletionResultsProcessor processor = new CompletionResultsProcessor(myElement, myElement.getQuoteType(), false);
((BuildFile) bzlFile).searchSymbolsInScope(processor, null);
return processor.getResults().toArray();
}
use of com.google.idea.blaze.base.lang.buildfile.psi.BuildFile in project intellij by bazelbuild.
the class BlazePackage method getContainingPackage.
@Nullable
public static BlazePackage getContainingPackage(@Nullable PsiDirectory dir) {
while (dir != null) {
VirtualFile buildFile = Blaze.getBuildSystemProvider(dir.getProject()).findBuildFileInDirectory(dir.getVirtualFile());
if (buildFile != null) {
PsiFile psiFile = dir.getManager().findFile(buildFile);
if (psiFile != null) {
return psiFile instanceof BuildFile ? new BlazePackage((BuildFile) psiFile) : null;
}
}
dir = dir.getParentDirectory();
}
return null;
}
use of com.google.idea.blaze.base.lang.buildfile.psi.BuildFile 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.BuildFile in project intellij by bazelbuild.
the class LoadedSkylarkExtensionTest method testAliasedFuncallReference.
@Test
public void testAliasedFuncallReference() {
createBuildFile(new WorkspacePath("java/com/google/tools/build_defs.bzl"), "def function(name, deps)");
BuildFile buildFile = createBuildFile(new WorkspacePath("java/com/google/BUILD"), "load('//java/com/google/tools:build_defs.bzl', newName = 'function'),", "newName(name = \"name\", deps = []");
LoadedSymbol loadedSymbol = PsiUtils.findFirstChildOfClassRecursive(buildFile, LoadedSymbol.class);
FuncallExpression funcall = buildFile.firstChildOfClass(FuncallExpression.class);
assertThat(funcall.getReferencedElement()).isEqualTo(loadedSymbol.getVisibleElement());
}
Aggregations