use of com.google.idea.blaze.base.lang.buildfile.psi.LoadedSymbol in project intellij by bazelbuild.
the class CompletionResultsProcessor method process.
@Override
public boolean process(BuildElement buildElement) {
if (buildElement == originalElement) {
return true;
}
if (buildElement instanceof LoadedSymbol) {
LoadedSymbol loadedSymbol = (LoadedSymbol) buildElement;
String string = loadedSymbol.getSymbolString();
results.put(string, new LoadedSymbolReferenceLookupElement(loadedSymbol, string, quoteType));
} else if (buildElement instanceof PsiNamedElement) {
PsiNamedElement namedElement = (PsiNamedElement) buildElement;
String name = namedElement.getName();
if (!allowPrivateSymbols && name != null && name.startsWith("_")) {
return true;
}
results.put(name, new NamedBuildLookupElement((PsiNamedElement) buildElement, quoteType));
}
return true;
}
use of com.google.idea.blaze.base.lang.buildfile.psi.LoadedSymbol in project intellij by bazelbuild.
the class ResolveUtil method findInScope.
/**
* Walks up PSI tree of local file, checking PsiNamedElements
*/
@Nullable
public static PsiNamedElement findInScope(PsiElement element, String name) {
PsiNamedElement[] resultHolder = new PsiNamedElement[1];
Processor<BuildElement> processor = buildElement -> {
if (buildElement == element) {
return true;
}
if (buildElement instanceof PsiNamedElement && name.equals(buildElement.getName())) {
resultHolder[0] = (PsiNamedElement) buildElement;
return false;
} else if (buildElement instanceof LoadedSymbol) {
LoadedSymbol loadedSymbol = (LoadedSymbol) buildElement;
if (name.equals(loadedSymbol.getSymbolString())) {
PsiElement referencedElement = loadedSymbol.getVisibleElement();
if (referencedElement instanceof PsiNamedElement) {
resultHolder[0] = (PsiNamedElement) referencedElement;
return false;
}
}
}
return true;
};
searchInScope(element, processor);
return resultHolder[0];
}
use of com.google.idea.blaze.base.lang.buildfile.psi.LoadedSymbol 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.LoadedSymbol 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());
}
use of com.google.idea.blaze.base.lang.buildfile.psi.LoadedSymbol 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());
}
Aggregations