@NotNull
 public static WritableScopeImpl newWritableScopeImpl(ExpressionTypingContext context) {
   WritableScopeImpl scope =
       new WritableScopeImpl(
           context.scope,
           context.scope.getContainingDeclaration(),
           new TraceBasedRedeclarationHandler(context.trace));
   scope.changeLockLevel(WritableScope.LockLevel.BOTH);
   return scope;
 }
Example #2
0
  @NotNull
  public JetScope getScopeForClassHeaderResolution() {
    if (scopeForClassHeaderResolution == null) {
      WritableScopeImpl scope =
          new WritableScopeImpl(
              JetScope.EMPTY, this, RedeclarationHandler.DO_NOTHING, "Class Header Resolution");
      for (TypeParameterDescriptor typeParameterDescriptor : getTypeConstructor().getParameters()) {
        scope.addClassifierDescriptor(typeParameterDescriptor);
      }
      scope.changeLockLevel(WritableScope.LockLevel.READING);

      scopeForClassHeaderResolution =
          new ChainedScope(
              this,
              scope,
              resolveSession.getResolutionScope(
                  declarationProvider.getOwnerInfo().getScopeAnchor()));
    }
    return scopeForClassHeaderResolution;
  }
Example #3
0
  public JetScope getScopeForMemberDeclarationResolution() {
    if (scopeForMemberDeclarationResolution == null) {
      WritableScopeImpl scope =
          new WritableScopeImpl(
              JetScope.EMPTY,
              this,
              RedeclarationHandler.DO_NOTHING,
              "Member Declaration Resolution");
      scope.addLabeledDeclaration(this);
      scope.changeLockLevel(WritableScope.LockLevel.READING);

      scopeForMemberDeclarationResolution =
          new ChainedScope(
              this,
              getScopeForMemberLookup().getImplicitReceiver(),
              scope,
              getScopeForMemberLookup(),
              getScopeForClassHeaderResolution());
    }
    return scopeForMemberDeclarationResolution;
  }
  @NotNull
  private JetScope computeScopeForClassHeaderResolution() {
    WritableScopeImpl scope =
        new WritableScopeImpl(
            JetScope.EMPTY,
            this,
            RedeclarationHandler.DO_NOTHING,
            "Scope with type parameters for " + getName());
    for (TypeParameterDescriptor typeParameterDescriptor : getTypeConstructor().getParameters()) {
      scope.addClassifierDescriptor(typeParameterDescriptor);
    }
    scope.changeLockLevel(WritableScope.LockLevel.READING);

    PsiElement scopeAnchor = declarationProvider.getOwnerInfo().getScopeAnchor();

    return new ChainedScope(
        this,
        "ScopeForClassHeaderResolution: " + getName(),
        scope,
        getScopeProvider().getResolutionScopeForDeclaration(scopeAnchor));
  }
Example #5
0
 @SuppressWarnings("ConstantConditions")
 private WritableScopeImpl addImports(JetScope scope) {
   WritableScopeImpl writableScope =
       new WritableScopeImpl(
           scope,
           scope.getContainingDeclaration(),
           RedeclarationHandler.DO_NOTHING,
           "JetTypeCheckerTest.addImports");
   InjectorForJavaDescriptorResolver injector =
       new InjectorForJavaDescriptorResolver(getProject(), new BindingTraceContext());
   JavaDescriptorResolver javaDescriptorResolver = injector.getJavaDescriptorResolver();
   writableScope.importScope(
       javaDescriptorResolver
           .resolveNamespace(FqName.ROOT, INCLUDE_KOTLIN_SOURCES)
           .getMemberScope());
   writableScope.importScope(
       javaDescriptorResolver
           .resolveNamespace(new FqName("java.lang"), IGNORE_KOTLIN_SOURCES)
           .getMemberScope());
   writableScope.changeLockLevel(WritableScope.LockLevel.BOTH);
   writableScope.importScope(builtIns.getBuiltInsScope());
   return writableScope;
 }
  @NotNull
  private JetScope computeScopeForPropertyInitializerResolution() {
    ConstructorDescriptor primaryConstructor = getUnsubstitutedPrimaryConstructor();
    if (primaryConstructor == null) return getScopeForMemberDeclarationResolution();

    WritableScopeImpl scope =
        new WritableScopeImpl(
            JetScope.EMPTY,
            this,
            RedeclarationHandler.DO_NOTHING,
            "Scope with constructor parameters in " + getName());
    for (ValueParameterDescriptor valueParameterDescriptor :
        primaryConstructor.getValueParameters()) {
      scope.addVariableDescriptor(valueParameterDescriptor);
    }
    scope.changeLockLevel(WritableScope.LockLevel.READING);

    return new ChainedScope(
        this,
        "ScopeForPropertyInitializerResolution: " + getName(),
        scope,
        getScopeForMemberDeclarationResolution());
  }
  @NotNull
  private JetScope computeScopeForMemberDeclarationResolution() {
    WritableScopeImpl thisScope =
        new WritableScopeImpl(
            JetScope.EMPTY,
            this,
            RedeclarationHandler.DO_NOTHING,
            "Scope with 'this' for " + getName());
    thisScope.addLabeledDeclaration(this);
    thisScope.changeLockLevel(WritableScope.LockLevel.READING);

    ClassDescriptor classObject = getClassObjectDescriptor();
    JetScope classObjectAdapterScope =
        (classObject != null) ? new ClassObjectMixinScope(classObject) : JetScope.EMPTY;

    return new ChainedScope(
        this,
        "ScopeForMemberDeclarationResolution: " + getName(),
        thisScope,
        getScopeForMemberLookup(),
        getScopeForClassHeaderResolution(),
        classObjectAdapterScope);
  }
Example #8
0
  public JetScope getScopeForPropertyInitializerResolution() {
    ConstructorDescriptor primaryConstructor = getUnsubstitutedPrimaryConstructor();
    if (primaryConstructor == null) return getScopeForMemberDeclarationResolution();

    if (scopeForPropertyInitializerResolution == null) {
      WritableScopeImpl scope =
          new WritableScopeImpl(
              JetScope.EMPTY,
              this,
              RedeclarationHandler.DO_NOTHING,
              "Property Initializer Resolution");

      List<ValueParameterDescriptor> parameters = primaryConstructor.getValueParameters();
      for (ValueParameterDescriptor valueParameterDescriptor : parameters) {
        scope.addVariableDescriptor(valueParameterDescriptor);
      }

      scope.changeLockLevel(WritableScope.LockLevel.READING);

      scopeForPropertyInitializerResolution =
          new ChainedScope(this, scope, getScopeForMemberDeclarationResolution());
    }
    return scopeForPropertyInitializerResolution;
  }