Exemplo n.º 1
0
  // Note: headers of member classes' members are not resolved
  public void resolveMemberHeaders() {
    ForceResolveUtil.forceResolveAllContents(getAnnotations());
    ForceResolveUtil.forceResolveAllContents(getDanglingAnnotations());

    getCompanionObjectDescriptor();

    getDescriptorsForExtraCompanionObjects();

    getConstructors();
    getContainingDeclaration();
    getThisAsReceiverParameter();
    getKind();
    getModality();
    getName();
    getOriginal();
    getScopeForClassHeaderResolution();
    getScopeForMemberDeclarationResolution();
    DescriptorUtils.getAllDescriptors(getUnsubstitutedMemberScope());
    getScopeForInitializerResolution();
    getUnsubstitutedInnerClassesScope();
    getTypeConstructor().getSupertypes();
    for (TypeParameterDescriptor typeParameterDescriptor : getTypeConstructor().getParameters()) {
      typeParameterDescriptor.getUpperBounds();
    }
    getUnsubstitutedPrimaryConstructor();
    getVisibility();
  }
  private static Collection<DeclarationDescriptor> getAllStandardDescriptors() {
    final List<DeclarationDescriptor> descriptors = new ArrayList<DeclarationDescriptor>();

    PackageFragmentDescriptor builtinsPackageFragment =
        DefaultBuiltIns.getInstance().getBuiltInsPackageFragment();

    for (DeclarationDescriptor packageMember :
        DescriptorUtils.getAllDescriptors(builtinsPackageFragment.getMemberScope())) {
      packageMember.acceptVoid(
          new DeclarationDescriptorVisitorEmptyBodies<Void, Void>() {
            @Override
            public Void visitClassDescriptor(ClassDescriptor descriptor, Void data) {
              descriptors.add(descriptor);
              for (DeclarationDescriptor classMember :
                  DescriptorUtils.getAllDescriptors(descriptor.getDefaultType().getMemberScope())) {
                classMember.acceptVoid(this);
              }
              return null;
            }

            @Override
            public Void visitDeclarationDescriptor(DeclarationDescriptor descriptor, Void data) {
              descriptors.add(descriptor);
              return null;
            }
          });
    }

    return descriptors;
  }
Exemplo n.º 3
0
  @Override
  protected void generateBody() {
    List<KtObjectDeclaration> companions = new ArrayList<KtObjectDeclaration>();
    if (kind != OwnerKind.DEFAULT_IMPLS) {
      // generate nested classes first and only then generate class body. It necessary to access to
      // nested CodegenContexts
      for (KtDeclaration declaration : myClass.getDeclarations()) {
        if (shouldProcessFirst(declaration)) {
          // Generate companions after class body generation (need to record all synthetic
          // accessors)
          if (declaration instanceof KtObjectDeclaration
              && ((KtObjectDeclaration) declaration).isCompanion()) {
            companions.add((KtObjectDeclaration) declaration);
            CodegenUtilKt.populateCompanionBackingFieldNamesToOuterContextIfNeeded(
                (KtObjectDeclaration) declaration, context, state);
          } else {
            generateDeclaration(declaration);
          }
        }
      }
    }

    for (KtDeclaration declaration : myClass.getDeclarations()) {
      if (!shouldProcessFirst(declaration)) {
        generateDeclaration(declaration);
      }
    }

    generatePrimaryConstructorProperties();
    generateConstructors();
    generateDefaultImplsIfNeeded();

    for (KtObjectDeclaration companion : companions) {
      generateDeclaration(companion);
    }

    if (!DescriptorUtils.isInterface(descriptor)) {
      for (DeclarationDescriptor memberDescriptor :
          DescriptorUtils.getAllDescriptors(descriptor.getDefaultType().getMemberScope())) {
        if (memberDescriptor instanceof CallableMemberDescriptor) {
          CallableMemberDescriptor member = (CallableMemberDescriptor) memberDescriptor;
          if (!member.getKind().isReal() && ImplKt.findInterfaceImplementation(member) == null) {
            if (member instanceof FunctionDescriptor) {
              functionCodegen.generateBridges((FunctionDescriptor) member);
            } else if (member instanceof PropertyDescriptor) {
              PropertyGetterDescriptor getter = ((PropertyDescriptor) member).getGetter();
              if (getter != null) {
                functionCodegen.generateBridges(getter);
              }
              PropertySetterDescriptor setter = ((PropertyDescriptor) member).getSetter();
              if (setter != null) {
                functionCodegen.generateBridges(setter);
              }
            }
          }
        }
      }
    }
  }
Exemplo n.º 4
0
 private static Collection<DeclarationDescriptor> getAllVariables(LexicalScope scope) {
   Collection<DeclarationDescriptor> result = ContainerUtil.newArrayList();
   result.addAll(
       ScopeUtilsKt.collectDescriptorsFiltered(
           scope, DescriptorKindFilter.VARIABLES, MemberScope.Companion.getALL_NAME_FILTER()));
   for (ReceiverParameterDescriptor implicitReceiver :
       ScopeUtilsKt.getImplicitReceiversHierarchy(scope)) {
     result.addAll(DescriptorUtils.getAllDescriptors(implicitReceiver.getType().getMemberScope()));
   }
   return result;
 }
Exemplo n.º 5
0
 @NotNull
 @Override
 public Collection<CallableMemberDescriptor> getDeclaredCallableMembers() {
   //noinspection unchecked
   return (Collection)
       CollectionsKt.filter(
           DescriptorUtils.getAllDescriptors(unsubstitutedMemberScope),
           new Function1<DeclarationDescriptor, Boolean>() {
             @Override
             public Boolean invoke(DeclarationDescriptor descriptor) {
               return descriptor instanceof CallableMemberDescriptor
                   && ((CallableMemberDescriptor) descriptor).getKind()
                       != CallableMemberDescriptor.Kind.FAKE_OVERRIDE;
             }
           });
 }
 @NotNull
 private Collection<DeclarationDescriptor> analyzeAndGetAllDescriptors(
     @NotNull File... extraClassPath) throws IOException {
   return DescriptorUtils.getAllDescriptors(
       analyzeFileToPackageView(extraClassPath).getMemberScope());
 }