@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; }
@Override public Collection<JetType> invoke() { if (resolveSession.isClassSpecial( DescriptorUtils.getFQName(LazyClassDescriptor.this))) { return Collections.emptyList(); } else { JetClassOrObject classOrObject = declarationProvider.getOwnerInfo().getCorrespondingClassOrObject(); if (classOrObject == null) { return Collections.emptyList(); } else { List<JetType> allSupertypes = resolveSession .getInjector() .getDescriptorResolver() .resolveSupertypes( getScopeForClassHeaderResolution(), LazyClassDescriptor.this, classOrObject, resolveSession.getTrace()); return Lists.newArrayList( Collections2.filter(allSupertypes, VALID_SUPERTYPE)); } } }
@NotNull @Override public Collection<? extends JetType> getSupertypes() { if (supertypes == null) { if (resolveSession.isClassSpecial(DescriptorUtils.getFQName(LazyClassDescriptor.this))) { this.supertypes = Collections.emptyList(); } else { JetClassOrObject classOrObject = declarationProvider.getOwnerInfo().getCorrespondingClassOrObject(); if (classOrObject == null) { this.supertypes = Collections.emptyList(); } else { List<JetType> allSupertypes = resolveSession .getInjector() .getDescriptorResolver() .resolveSupertypes( getScopeForClassHeaderResolution(), LazyClassDescriptor.this, classOrObject, resolveSession.getTrace()); List<JetType> validSupertypes = Lists.newArrayList(Collections2.filter(allSupertypes, VALID_SUPERTYPE)); this.supertypes = validSupertypes; findAndDisconnectLoopsInTypeHierarchy(validSupertypes); } } } return supertypes; }
private String renderDefaultType(JetType type, boolean shortNamesOnly) { StringBuilder sb = new StringBuilder(); ClassifierDescriptor cd = type.getConstructor().getDeclarationDescriptor(); Object typeNameObject; if (cd == null || cd instanceof TypeParameterDescriptor) { typeNameObject = type.getConstructor(); } else { if (shortNamesOnly) { // for nested classes qualified name should be used typeNameObject = cd.getName(); DeclarationDescriptor parent = cd.getContainingDeclaration(); while (parent instanceof ClassDescriptor) { typeNameObject = parent.getName() + "." + typeNameObject; parent = parent.getContainingDeclaration(); } } else { typeNameObject = DescriptorUtils.getFQName(cd); } } sb.append(typeNameObject); if (!type.getArguments().isEmpty()) { sb.append("<"); appendTypeProjections(sb, type.getArguments(), shortNamesOnly); sb.append(">"); } if (type.isNullable()) { sb.append("?"); } return sb.toString(); }
@Override @NotNull public Collection<ClassDescriptor> mapPlatformClass(@NotNull ClassDescriptor classDescriptor) { FqNameUnsafe className = DescriptorUtils.getFQName(classDescriptor); if (!className.isSafe()) { return Collections.emptyList(); } return mapPlatformClass(className.toSafe()); }
@Override public void extendNamespaceScope( @NotNull BindingTrace trace, @NotNull NamespaceDescriptor namespaceDescriptor, @NotNull WritableScope namespaceMemberScope) { namespaceMemberScope.importScope( javaSemanticServices .getDescriptorResolver() .createJavaPackageScope( DescriptorUtils.getFQName(namespaceDescriptor).toSafe(), namespaceDescriptor)); delegateConfiguration.extendNamespaceScope(trace, namespaceDescriptor, namespaceMemberScope); }
@Override @NotNull public Collection<ClassDescriptor> mapPlatformClassesInside( @NotNull DeclarationDescriptor containingDeclaration) { FqNameUnsafe fqName = DescriptorUtils.getFQName(containingDeclaration); if (!fqName.isSafe()) { return Collections.emptyList(); } Collection<ClassDescriptor> result = packagesWithMappedClasses.get(fqName.toSafe()); return result == null ? Collections.<ClassDescriptor>emptySet() : Collections.unmodifiableCollection(result); }
/* METHODS FOR ALL KINDS OF DESCRIPTORS */ private void appendDefinedIn( @NotNull DeclarationDescriptor descriptor, @NotNull StringBuilder builder) { if (descriptor instanceof ModuleDescriptor) { builder.append(" is a module"); return; } builder.append(" ").append(renderMessage("defined in")).append(" "); DeclarationDescriptor containingDeclaration = descriptor.getContainingDeclaration(); if (containingDeclaration != null) { FqNameUnsafe fqName = DescriptorUtils.getFQName(containingDeclaration); builder.append(FqName.ROOT.equalsTo(fqName) ? "root package" : renderFqName(fqName)); } }
@NotNull public static JvmClassName byClassDescriptor(@NotNull ClassifierDescriptor classDescriptor) { DeclarationDescriptor descriptor = classDescriptor; List<String> innerClassNames = Lists.newArrayList(); while (descriptor.getContainingDeclaration() instanceof ClassDescriptor) { innerClassNames.add(descriptor.getName().getName()); descriptor = descriptor.getContainingDeclaration(); assert descriptor != null; } return byFqNameAndInnerClassList( DescriptorUtils.getFQName(descriptor).toSafe(), innerClassNames); }
@NotNull @Override public String render(@NotNull Collection<ClassDescriptor> descriptors) { StringBuilder sb = new StringBuilder(); int index = 0; for (ClassDescriptor descriptor : descriptors) { sb.append(DescriptorUtils.getFQName(descriptor).getFqName()); index++; if (index <= descriptors.size() - 2) { sb.append(", "); } else if (index == descriptors.size() - 1) { sb.append(" or "); } } return sb.toString(); }
/** * Add import directive corresponding to a type to file when it is needed. * * @param type type to import * @param file file where import directive should be added */ public static void addImportDirectivesIfNeeded(@NotNull JetType type, @NotNull JetFile file) { if (JetPluginUtil.checkTypeIsStandard(type, file.getProject()) || ErrorUtils.isErrorType(type)) { return; } BindingContext bindingContext = getContextForSingleFile(file); PsiElement element = BindingContextUtils.descriptorToDeclaration( bindingContext, type.getMemberScope().getContainingDeclaration()); if (element != null && element.getContainingFile() == file) { // declaration is in the same file, so no import is needed return; } for (ClassDescriptor clazz : TypeUtils.getAllClassDescriptors(type)) { addImportDirective(DescriptorUtils.getFQName(getTopLevelClass(clazz)).toSafe(), file); } }
private void renderAnnotations(@NotNull Annotated annotated, @NotNull StringBuilder builder) { if (!modifiers.contains(Modifier.ANNOTATIONS)) return; for (AnnotationDescriptor annotation : annotated.getAnnotations()) { ClassDescriptor annotationClass = (ClassDescriptor) annotation.getType().getConstructor().getDeclarationDescriptor(); assert annotationClass != null; if (!excludedAnnotationClasses.contains( DescriptorUtils.getFQName(annotationClass).toSafe())) { builder.append(renderType(annotation.getType())); if (verbose) { builder .append("(") .append( StringUtil.join(DescriptorUtils.getSortedValueArguments(annotation, this), ", ")) .append(")"); } builder.append(" "); } } }
@NotNull private String renderClassName(@NotNull ClassDescriptor klass) { if (ErrorUtils.isError(klass)) { return klass.getTypeConstructor().toString(); } if (shortNames) { List<Name> qualifiedNameElements = Lists.newArrayList(); // for nested classes qualified name should be used DeclarationDescriptor current = klass; do { if (((ClassDescriptor) current).getKind() != ClassKind.CLASS_OBJECT) { qualifiedNameElements.add(current.getName()); } current = current.getContainingDeclaration(); } while (current instanceof ClassDescriptor); Collections.reverse(qualifiedNameElements); return renderFqName(qualifiedNameElements); } return renderFqName(DescriptorUtils.getFQName(klass)); }
@NotNull public static LookupElement createLookupElement( @NotNull KotlinCodeAnalyzer analyzer, @NotNull DeclarationDescriptor descriptor, @Nullable PsiElement declaration) { if (declaration != null) { MutableLookupElement javaLookupElement = createJavaLookupElementIfPossible(declaration); if (javaLookupElement != null) { InsertHandler<LookupElement> customHandler = getInsertHandler(descriptor); if (customHandler != null) { return javaLookupElement.setInsertHandler(getInsertHandler(descriptor)); } else { return javaLookupElement; } } } LookupElementBuilder element = LookupElementBuilder.create( new JetLookupObject(descriptor, analyzer, declaration), descriptor.getName().getName()); String presentableText = descriptor.getName().getName(); String typeText = ""; String tailText = ""; boolean tailTextGrayed = true; if (descriptor instanceof FunctionDescriptor) { FunctionDescriptor functionDescriptor = (FunctionDescriptor) descriptor; JetType returnType = functionDescriptor.getReturnType(); typeText = DescriptorRenderer.TEXT.renderType(returnType); presentableText += DescriptorRenderer.TEXT.renderFunctionParameters(functionDescriptor); boolean extensionFunction = functionDescriptor.getReceiverParameter() != null; DeclarationDescriptor containingDeclaration = descriptor.getContainingDeclaration(); if (containingDeclaration != null && extensionFunction) { tailText += " for " + DescriptorRenderer.TEXT.renderType( functionDescriptor.getReceiverParameter().getType()); tailText += " in " + DescriptorUtils.getFQName(containingDeclaration); } } else if (descriptor instanceof VariableDescriptor) { JetType outType = ((VariableDescriptor) descriptor).getType(); typeText = DescriptorRenderer.TEXT.renderType(outType); } else if (descriptor instanceof ClassDescriptor) { DeclarationDescriptor declaredIn = descriptor.getContainingDeclaration(); assert declaredIn != null; tailText = " (" + DescriptorUtils.getFQName(declaredIn) + ")"; tailTextGrayed = true; } else { typeText = DescriptorRenderer.TEXT.render(descriptor); } element = element.withInsertHandler(getInsertHandler(descriptor)); element = element .withTailText(tailText, tailTextGrayed) .withTypeText(typeText) .withPresentableText(presentableText); element = element.withIcon( JetDescriptorIconProvider.getIcon(descriptor, Iconable.ICON_FLAG_VISIBILITY)); element = element.withStrikeoutness(KotlinBuiltIns.getInstance().isDeprecated(descriptor)); return element; }
public void serialize(NamespaceDescriptor ns) { sb.append(DescriptorUtils.getFQName(ns)); }
public void serialize(ClassDescriptor clazz) { sb.append(DescriptorUtils.getFQName(clazz)); }