001 /*
002 * Copyright 2010-2016 JetBrains s.r.o.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017 package org.jetbrains.kotlin.asJava;
018
019 import com.intellij.openapi.components.ServiceManager;
020 import com.intellij.openapi.project.Project;
021 import com.intellij.psi.PsiClass;
022 import com.intellij.psi.search.GlobalSearchScope;
023 import org.jetbrains.annotations.NotNull;
024 import org.jetbrains.annotations.Nullable;
025 import org.jetbrains.kotlin.asJava.builder.LightClassConstructionContext;
026 import org.jetbrains.kotlin.asJava.classes.KtLightClass;
027 import org.jetbrains.kotlin.descriptors.DeclarationDescriptor;
028 import org.jetbrains.kotlin.name.FqName;
029 import org.jetbrains.kotlin.psi.KtClassOrObject;
030 import org.jetbrains.kotlin.psi.KtDeclaration;
031 import org.jetbrains.kotlin.psi.KtElement;
032 import org.jetbrains.kotlin.psi.KtFile;
033 import org.jetbrains.kotlin.resolve.BindingContext;
034
035 import java.util.Collection;
036
037 public abstract class LightClassGenerationSupport {
038
039 @NotNull
040 public static LightClassGenerationSupport getInstance(@NotNull Project project) {
041 return ServiceManager.getService(project, LightClassGenerationSupport.class);
042 }
043
044 @NotNull
045 public abstract LightClassConstructionContext getContextForClassOrObject(@NotNull KtClassOrObject classOrObject);
046
047 @NotNull
048 public abstract Collection<KtClassOrObject> findClassOrObjectDeclarations(@NotNull FqName fqName, @NotNull GlobalSearchScope searchScope);
049
050 /*
051 * Finds files whose package declaration is exactly {@code fqName}. For example, if a file declares
052 * package a.b.c
053 * it will not be returned for fqName "a.b"
054 *
055 * If the resulting collection is empty, it means that this package has not other declarations than sub-packages
056 */
057 @NotNull
058 public abstract Collection<KtFile> findFilesForPackage(@NotNull FqName fqName, @NotNull GlobalSearchScope searchScope);
059
060 // Returns only immediately declared classes/objects, package classes are not included (they have no declarations)
061 @NotNull
062 public abstract Collection<KtClassOrObject> findClassOrObjectDeclarationsInPackage(
063 @NotNull FqName packageFqName,
064 @NotNull GlobalSearchScope searchScope
065 );
066
067 public abstract boolean packageExists(@NotNull FqName fqName, @NotNull GlobalSearchScope scope);
068
069 @NotNull
070 public abstract Collection<FqName> getSubPackages(@NotNull FqName fqn, @NotNull GlobalSearchScope scope);
071
072 @Nullable
073 public abstract KtLightClass getLightClass(@NotNull KtClassOrObject classOrObject);
074
075 @Nullable
076 public abstract DeclarationDescriptor resolveToDescriptor(@NotNull KtDeclaration declaration);
077
078 @NotNull
079 public abstract BindingContext analyze(@NotNull KtElement element);
080
081 @NotNull
082 public abstract Collection<PsiClass> getFacadeClasses(@NotNull FqName facadeFqName, @NotNull GlobalSearchScope scope);
083
084 @NotNull
085 public abstract Collection<PsiClass> getMultifilePartClasses(@NotNull FqName partFqName, @NotNull GlobalSearchScope scope);
086
087 @NotNull
088 public abstract Collection<PsiClass> getFacadeClassesInPackage(@NotNull FqName packageFqName, @NotNull GlobalSearchScope scope);
089
090 @NotNull
091 public abstract Collection<String> getFacadeNames(@NotNull FqName packageFqName, @NotNull GlobalSearchScope scope);
092
093 @NotNull
094 public abstract Collection<KtFile> findFilesForFacade(@NotNull FqName facadeFqName, @NotNull GlobalSearchScope scope);
095
096 @NotNull
097 public abstract LightClassConstructionContext getContextForFacade(@NotNull Collection<KtFile> files);
098 }