Ejemplo n.º 1
0
  private void resolveFunctionAndPropertyHeaders(
      @NotNull final TopDownAnalysisContext c,
      @NotNull List<JetDeclaration> declarations,
      @NotNull final JetScope scopeForFunctions,
      @NotNull final JetScope scopeForPropertyInitializers,
      @NotNull final JetScope scopeForPropertyAccessors,
      @NotNull final PackageLikeBuilder packageLike) {
    for (JetDeclaration declaration : declarations) {
      declaration.accept(
          new JetVisitorVoid() {
            @Override
            public void visitNamedFunction(@NotNull JetNamedFunction function) {
              SimpleFunctionDescriptor functionDescriptor =
                  descriptorResolver.resolveFunctionDescriptor(
                      packageLike.getOwnerForChildren(),
                      scopeForFunctions,
                      function,
                      trace,
                      c.getOuterDataFlowInfo());
              packageLike.addFunctionDescriptor(functionDescriptor);
              c.getFunctions().put(function, functionDescriptor);
              c.registerDeclaringScope(function, scopeForFunctions);
            }

            @Override
            public void visitProperty(@NotNull JetProperty property) {
              PropertyDescriptor propertyDescriptor =
                  descriptorResolver.resolvePropertyDescriptor(
                      packageLike.getOwnerForChildren(),
                      scopeForPropertyInitializers,
                      property,
                      trace,
                      c.getOuterDataFlowInfo());
              packageLike.addPropertyDescriptor(propertyDescriptor);
              c.getProperties().put(property, propertyDescriptor);
              c.registerDeclaringScope(property, scopeForPropertyInitializers);
              JetPropertyAccessor getter = property.getGetter();
              if (getter != null) {
                c.registerDeclaringScope(getter, scopeForPropertyAccessors);
              }
              JetPropertyAccessor setter = property.getSetter();
              if (setter != null) {
                c.registerDeclaringScope(setter, scopeForPropertyAccessors);
              }
            }
          });
    }
  }
Ejemplo n.º 2
0
  private void resolveFunctionAndPropertyHeaders(
      @NotNull List<JetDeclaration> declarations,
      final @NotNull JetScope scopeForFunctions,
      final @NotNull JetScope scopeForPropertyInitializers,
      final @NotNull JetScope scopeForPropertyAccessors,
      final @NotNull NamespaceLike namespaceLike) {
    for (JetDeclaration declaration : declarations) {
      declaration.accept(
          new JetVisitorVoid() {
            @Override
            public void visitNamedFunction(JetNamedFunction function) {
              NamedFunctionDescriptor functionDescriptor =
                  context
                      .getDescriptorResolver()
                      .resolveFunctionDescriptor(namespaceLike, scopeForFunctions, function);
              namespaceLike.addFunctionDescriptor(functionDescriptor);
              context.getFunctions().put(function, functionDescriptor);
              context.getDeclaringScopes().put(function, scopeForFunctions);
            }

            @Override
            public void visitProperty(JetProperty property) {
              PropertyDescriptor propertyDescriptor =
                  context
                      .getDescriptorResolver()
                      .resolvePropertyDescriptor(
                          namespaceLike, scopeForPropertyInitializers, property);
              namespaceLike.addPropertyDescriptor(propertyDescriptor);
              context.getProperties().put(property, propertyDescriptor);
              context.getDeclaringScopes().put(property, scopeForPropertyInitializers);
              if (property.getGetter() != null) {
                context.getDeclaringScopes().put(property.getGetter(), scopeForPropertyAccessors);
              }
              if (property.getSetter() != null) {
                context.getDeclaringScopes().put(property.getSetter(), scopeForPropertyAccessors);
              }
            }

            @Override
            public void visitObjectDeclaration(JetObjectDeclaration declaration) {
              PropertyDescriptor propertyDescriptor =
                  context
                      .getDescriptorResolver()
                      .resolveObjectDeclarationAsPropertyDescriptor(
                          namespaceLike, declaration, context.getObjects().get(declaration));
              namespaceLike.addPropertyDescriptor(propertyDescriptor);
            }

            @Override
            public void visitEnumEntry(JetEnumEntry enumEntry) {
              if (enumEntry.getPrimaryConstructorParameterList() == null) {
                MutableClassDescriptorLite classObjectDescriptor =
                    ((MutableClassDescriptor) namespaceLike).getClassObjectDescriptor();
                assert classObjectDescriptor != null;
                PropertyDescriptor propertyDescriptor =
                    context
                        .getDescriptorResolver()
                        .resolveObjectDeclarationAsPropertyDescriptor(
                            classObjectDescriptor, enumEntry, context.getClasses().get(enumEntry));
                classObjectDescriptor.addPropertyDescriptor(propertyDescriptor);
              }
            }
          });
    }
  }