Пример #1
0
  @NotNull
  private static Multimap<FqName, Pair<FunctionDescriptor, PsiMethod>>
      getSuperclassToFunctionsMultimap(
          @NotNull PsiMethodWrapper method,
          @NotNull BindingContext bindingContext,
          @NotNull ClassDescriptor containingClass) {
    Multimap<FqName, Pair<FunctionDescriptor, PsiMethod>> result = HashMultimap.create();

    Name functionName = Name.identifier(method.getName());
    int parameterCount = method.getParameters().size();

    for (JetType supertype : TypeUtils.getAllSupertypes(containingClass.getDefaultType())) {
      ClassifierDescriptor klass = supertype.getConstructor().getDeclarationDescriptor();
      assert klass != null;
      FqName fqName = DescriptorUtils.getFQName(klass).toSafe();

      for (FunctionDescriptor fun :
          klass.getDefaultType().getMemberScope().getFunctions(functionName)) {
        if (fun.getKind().isReal() && fun.getValueParameters().size() == parameterCount) {
          PsiElement declaration = BindingContextUtils.descriptorToDeclaration(bindingContext, fun);
          if (declaration instanceof PsiMethod) {
            result.put(fqName, Pair.create(fun, (PsiMethod) declaration));
          } // else declaration is null or JetNamedFunction: both cases are processed later
        }
      }
    }
    return result;
  }
Пример #2
0
 private static Map<ClassDescriptor, JetType> getSuperclassToSupertypeMap(
     ClassDescriptor containingClass) {
   Map<ClassDescriptor, JetType> superclassToSupertype = Maps.newHashMap();
   for (JetType supertype : TypeUtils.getAllSupertypes(containingClass.getDefaultType())) {
     ClassifierDescriptor superclass = supertype.getConstructor().getDeclarationDescriptor();
     assert superclass instanceof ClassDescriptor;
     superclassToSupertype.put((ClassDescriptor) superclass, supertype);
   }
   return superclassToSupertype;
 }
Пример #3
0
  private void appendDescriptor(DeclarationDescriptor descriptor, String indent) {
    int startOffset = myBuilder.length();
    myBuilder.append(DescriptorRenderer.COMPACT.render(descriptor));
    int endOffset = myBuilder.length();

    if (descriptor instanceof FunctionDescriptor || descriptor instanceof PropertyDescriptor) {
      if (((CallableMemberDescriptor) descriptor).getModality() != Modality.ABSTRACT) {
        if (descriptor instanceof FunctionDescriptor) {
          myBuilder.append(" { ").append(DECOMPILED_COMMENT).append(" }");
          endOffset = myBuilder.length();
        } else { // descriptor instanceof PropertyDescriptor
          if (((PropertyDescriptor) descriptor).getModality() != Modality.ABSTRACT) {
            myBuilder.append(" ").append(DECOMPILED_COMMENT);
          }
        }
      }
    } else if (descriptor instanceof ClassDescriptor) {
      myBuilder.append(" {\n");
      ClassDescriptor classDescriptor = (ClassDescriptor) descriptor;
      boolean firstPassed = false;
      String subindent = indent + "    ";
      if (classDescriptor.getClassObjectDescriptor() != null) {
        firstPassed = true;
        myBuilder.append(subindent).append("class ");
        appendDescriptor(classDescriptor.getClassObjectDescriptor(), subindent);
      }
      for (DeclarationDescriptor member :
          sortDeclarations(classDescriptor.getDefaultType().getMemberScope().getAllDescriptors())) {
        if (member.getContainingDeclaration() == descriptor) {
          if (firstPassed) {
            myBuilder.append("\n");
          } else {
            firstPassed = true;
          }
          myBuilder.append(subindent);
          appendDescriptor(member, subindent);
        }
      }
      myBuilder.append(indent).append("}");
      endOffset = myBuilder.length();
    }

    myBuilder.append("\n");
    PsiElement clsMember =
        myBindingContext.get(BindingContext.DESCRIPTOR_TO_DECLARATION, descriptor);
    if (clsMember != null) {
      myClsMembersToRanges.put(clsMember, new TextRange(startOffset, endOffset));
    }
  }