[JS] Remove binding context from NameSuggestion instance

Pass bindingContext to suggest method instead.
Revert creating multiple instances of NameSuggestion in checkers.
This commit is contained in:
Svyatoslav Kuzmich
2020-05-22 13:37:04 +03:00
parent 104352b313
commit c9adf22697
9 changed files with 46 additions and 46 deletions
@@ -46,7 +46,7 @@ internal class DeclarationExporter(val context: StaticContext) {
if (isNativeObject(descriptor) || isLibraryObject(descriptor)) return
if (descriptor.isEffectivelyInlineOnly()) return
val suggestedName = context.nameSuggestion.suggest(descriptor) ?: return
val suggestedName = context.nameSuggestion.suggest(descriptor, context.bindingContext) ?: return
val container = suggestedName.scope
if (!descriptor.shouldBeExported(force)) return
@@ -151,7 +151,7 @@ public final class Namer {
qualifier = fqNameParent.asString();
}
SuggestedName suggestedName = new NameSuggestion(bindingContext).suggest(functionDescriptor);
SuggestedName suggestedName = new NameSuggestion().suggest(functionDescriptor, bindingContext);
assert suggestedName != null : "Suggested name can be null only for module descriptors: " + functionDescriptor;
String mangledName = suggestedName.getNames().get(0);
return StringUtil.join(Arrays.asList(moduleName, qualifier, mangledName), ".");
@@ -169,7 +169,7 @@ public final class StaticContext {
fragment = new JsProgramFragment(rootFunction.getScope(), packageFqn);
this.bindingTrace = bindingTrace;
this.nameSuggestion = new NameSuggestion(bindingTrace.getBindingContext());
this.nameSuggestion = new NameSuggestion();
this.namer = Namer.newInstance(program.getRootScope());
this.intrinsics = new Intrinsics();
this.rootScope = fragment.getScope();
@@ -271,7 +271,7 @@ public final class StaticContext {
@Nullable
public SuggestedName suggestName(@NotNull DeclarationDescriptor descriptor) {
return nameSuggestion.suggest(descriptor);
return nameSuggestion.suggest(descriptor, getBindingContext());
}
@NotNull
@@ -368,7 +368,7 @@ public final class StaticContext {
MetadataProperties.setDescriptor(result, descriptor);
return result;
}
SuggestedName suggested = nameSuggestion.suggest(descriptor);
SuggestedName suggested = nameSuggestion.suggest(descriptor, getBindingContext());
if (suggested == null) {
throw new IllegalArgumentException("Can't generate name for root declarations: " + descriptor);
}
@@ -380,7 +380,7 @@ public final class StaticContext {
JsName name = backingFieldNameCache.get(property);
if (name == null) {
SuggestedName fqn = nameSuggestion.suggest(property);
SuggestedName fqn = nameSuggestion.suggest(property, getBindingContext());
assert fqn != null : "Properties are non-root declarations: " + property;
assert fqn.getNames().size() == 1 : "Private names must always consist of exactly one name";
@@ -741,7 +741,7 @@ public final class StaticContext {
@NotNull
private String getPlainId(@NotNull DeclarationDescriptor declaration) {
SuggestedName suggestedName = nameSuggestion.suggest(declaration);
SuggestedName suggestedName = nameSuggestion.suggest(declaration, getBindingContext());
assert suggestedName != null : "Declaration should not be ModuleDescriptor, therefore suggestedName should be non-null";
return suggestedName.getNames().get(0);
}
@@ -177,7 +177,7 @@ class UsageTracker(
// Append 'closure$' prefix to avoid name clash between closure and member fields in case of local classes
else -> {
val mangled = NameSuggestion.sanitizeName(NameSuggestion(bindingContext).suggest(this)!!.names.last())
val mangled = NameSuggestion.sanitizeName(NameSuggestion().suggest(this, bindingContext)!!.names.last())
"closure\$$mangled"
}
}