コード例 #1
0
 @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;
 }
コード例 #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;
  }
コード例 #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;
  }
コード例 #4
0
  @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));
  }
コード例 #5
0
ファイル: JetTypeCheckerTest.java プロジェクト: ymkawb/kotlin
 @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;
 }
コード例 #6
0
  @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());
  }
コード例 #7
0
  @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);
  }
コード例 #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;
  }