示例#1
0
  public static void genClassOrObject(
      @NotNull CodegenContext parentContext,
      @NotNull JetClassOrObject aClass,
      @NotNull GenerationState state,
      @Nullable MemberCodegen<?> parentCodegen) {
    ClassDescriptor descriptor = state.getBindingContext().get(BindingContext.CLASS, aClass);

    if (descriptor == null || ErrorUtils.isError(descriptor)) {
      badDescriptor(descriptor, state.getClassBuilderMode());
      return;
    }

    if (descriptor.getName().equals(SpecialNames.NO_NAME_PROVIDED)) {
      badDescriptor(descriptor, state.getClassBuilderMode());
    }

    ClassBuilder classBuilder =
        state.getFactory().forClassImplementation(descriptor, aClass.getContainingFile());
    ClassContext classContext =
        parentContext.intoClass(descriptor, OwnerKind.IMPLEMENTATION, state);
    new ImplementationBodyCodegen(aClass, classContext, classBuilder, state, parentCodegen)
        .generate();

    if (aClass instanceof JetClass && ((JetClass) aClass).isTrait()) {
      ClassBuilder traitImplBuilder =
          state.getFactory().forTraitImplementation(descriptor, state, aClass.getContainingFile());
      ClassContext traitImplContext =
          parentContext.intoClass(descriptor, OwnerKind.TRAIT_IMPL, state);
      new TraitImplBodyCodegen(aClass, traitImplContext, traitImplBuilder, state, parentCodegen)
          .generate();
    }
  }
  @Override
  public void prepareRenaming(
      PsiElement element, String newName, Map<PsiElement, String> allRenames) {
    JetClassOrObject clazz = (JetClassOrObject) element;
    JetFile file = (JetFile) clazz.getContainingFile();

    VirtualFile virtualFile = file.getVirtualFile();
    if (virtualFile != null) {
      String nameWithoutExtensions = virtualFile.getNameWithoutExtension();
      if (nameWithoutExtensions.equals(clazz.getName())) {
        allRenames.put(file, newName + "." + virtualFile.getExtension());
      }
    }
    super.prepareRenaming(element, newName, allRenames);
  }