コード例 #1
0
    private void reportCyclicInheritanceHierarchyError(
        @NotNull BindingTrace trace,
        @NotNull ClassDescriptor classDescriptor,
        @NotNull ClassDescriptor superclass) {
      PsiElement psiElement = DescriptorToSourceUtils.getSourceFromDescriptor(classDescriptor);

      PsiElement elementToMark = null;
      if (psiElement instanceof KtClassOrObject) {
        KtClassOrObject classOrObject = (KtClassOrObject) psiElement;
        for (KtSuperTypeListEntry delegationSpecifier : classOrObject.getSuperTypeListEntries()) {
          KtTypeReference typeReference = delegationSpecifier.getTypeReference();
          if (typeReference == null) continue;
          KotlinType supertype = trace.get(TYPE, typeReference);
          if (supertype != null && supertype.getConstructor() == superclass.getTypeConstructor()) {
            elementToMark = typeReference;
          }
        }
      }
      if (elementToMark == null && psiElement instanceof PsiNameIdentifierOwner) {
        PsiNameIdentifierOwner namedElement = (PsiNameIdentifierOwner) psiElement;
        PsiElement nameIdentifier = namedElement.getNameIdentifier();
        if (nameIdentifier != null) {
          elementToMark = nameIdentifier;
        }
      }
      if (elementToMark != null) {
        trace.report(CYCLIC_INHERITANCE_HIERARCHY.on(elementToMark));
      }
    }
コード例 #2
0
  @Nullable
  public PsiElement resolveBuiltInSymbol(@NotNull DeclarationDescriptor declarationDescriptor) {
    if (moduleDescriptor == null) {
      return null;
    }

    DeclarationDescriptor descriptor = findCurrentDescriptor(declarationDescriptor);
    if (descriptor != null) {
      return DescriptorToSourceUtils.getSourceFromDescriptor(descriptor);
    }
    return null;
  }
コード例 #3
0
ファイル: ScriptContext.java プロジェクト: manidesto/kotlin
 public ScriptContext(
     @NotNull JetTypeMapper typeMapper,
     @NotNull ScriptDescriptor scriptDescriptor,
     @NotNull List<ScriptDescriptor> earlierScripts,
     @NotNull ClassDescriptor contextDescriptor,
     @Nullable CodegenContext parentContext) {
   super(typeMapper, contextDescriptor, OwnerKind.IMPLEMENTATION, parentContext, null);
   this.scriptDescriptor = scriptDescriptor;
   this.earlierScripts = earlierScripts;
   KtScript script = (KtScript) DescriptorToSourceUtils.getSourceFromDescriptor(scriptDescriptor);
   assert script != null : "Declaration should be present for script: " + scriptDescriptor;
   KtDeclaration lastDeclaration = CollectionsKt.lastOrNull(script.getDeclarations());
   if (lastDeclaration instanceof KtAnonymousInitializer) {
     this.lastStatement = ((KtAnonymousInitializer) lastDeclaration).getBody();
   } else {
     this.lastStatement = null;
   }
 }