@Nullable public JsPropertyInitializer translate( @NotNull JetClassOrObject declaration, TranslationContext context) { ClassDescriptor descriptor = getClassDescriptor(context().bindingContext(), declaration); JsExpression value; if (descriptor.getModality() == Modality.FINAL) { value = new ClassTranslator(declaration, classDescriptorToQualifiedLabel, context).translate(); } else { String label = createNameForClass(descriptor); JsName name = dummyFunction.getScope().declareName(label); JsNameRef qualifiedLabel = openClassDescriptorToQualifiedLabel.get(descriptor); if (qualifiedLabel == null) { qualifiedLabel = new JsNameRef(name); openClassDescriptorToQualifiedLabel.put(descriptor, qualifiedLabel); } else { qualifiedLabel.resolve(name); } qualifiedLabel.setQualifier(declarationsObjectRef); OpenClassInfo item = new OpenClassInfo((JetClass) declaration, descriptor, name.makeRef()); openList.add(item); openClassDescriptorToItem.put(descriptor, item); value = qualifiedLabel; // not public api classes referenced to internal var _c if (!descriptor.getVisibility().isPublicAPI()) { return null; } } return InitializerUtils.createPropertyInitializer(descriptor, value, context()); }
public ClassDeclarationTranslator(@NotNull TranslationContext context) { super(context); dummyFunction = new JsFunction(context.scope()); JsName declarationsObject = context().scope().declareName(Namer.nameForClassesVariable()); classesVar = new JsVars.JsVar(declarationsObject); declarationsObjectRef = declarationsObject.makeRef(); }
@Nullable private JsNameRef getTargetLabel(@NotNull Node statementWithLabel) { int type = statementWithLabel.getType(); if (type != TokenStream.BREAK && type != TokenStream.CONTINUE) { String tokenTypeName = TokenStream.tokenToName(statementWithLabel.getType()); throw new AssertionError("Unexpected node type with label: " + tokenTypeName); } Node label = statementWithLabel.getFirstChild(); if (label == null) return null; String identifier = label.getString(); assert identifier != null : "If label exists identifier should not be null"; JsName labelName = scopeContext.labelFor(identifier); assert labelName != null : "Unknown label name: " + identifier; return labelName.makeRef(); }
@NotNull public JsPropertyInitializer getDeclarationAsInitializer() { return new JsPropertyInitializer(namespaceName.makeRef(), getNamespaceDeclaration()); }