Search in sources :

Example 1 with KtClassOrObject

use of org.jetbrains.kotlin.psi.KtClassOrObject in project kotlin by JetBrains.

the class JavaElementFinder method getClasses.

@NotNull
@Override
public PsiClass[] getClasses(@NotNull PsiPackage psiPackage, @NotNull GlobalSearchScope scope) {
    List<PsiClass> answer = new SmartList<PsiClass>();
    FqName packageFQN = new FqName(psiPackage.getQualifiedName());
    answer.addAll(lightClassGenerationSupport.getFacadeClassesInPackage(packageFQN, scope));
    Collection<KtClassOrObject> declarations = lightClassGenerationSupport.findClassOrObjectDeclarationsInPackage(packageFQN, scope);
    for (KtClassOrObject declaration : declarations) {
        PsiClass aClass = toLightClass(declaration);
        if (aClass != null) {
            answer.add(aClass);
        }
    }
    return sortByClasspath(answer, scope).toArray(new PsiClass[answer.size()]);
}
Also used : KtClassOrObject(org.jetbrains.kotlin.psi.KtClassOrObject) FqName(org.jetbrains.kotlin.name.FqName) SmartList(com.intellij.util.SmartList) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with KtClassOrObject

use of org.jetbrains.kotlin.psi.KtClassOrObject in project kotlin by JetBrains.

the class JavaElementFinder method getClassNames.

@NotNull
@Override
public Set<String> getClassNames(@NotNull PsiPackage psiPackage, @NotNull GlobalSearchScope scope) {
    FqName packageFQN = new FqName(psiPackage.getQualifiedName());
    Collection<KtClassOrObject> declarations = lightClassGenerationSupport.findClassOrObjectDeclarationsInPackage(packageFQN, scope);
    Set<String> answer = Sets.newHashSet();
    answer.addAll(lightClassGenerationSupport.getFacadeNames(packageFQN, scope));
    for (KtClassOrObject declaration : declarations) {
        String name = declaration.getName();
        if (name != null) {
            answer.add(name);
        }
    }
    return answer;
}
Also used : KtClassOrObject(org.jetbrains.kotlin.psi.KtClassOrObject) FqName(org.jetbrains.kotlin.name.FqName) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with KtClassOrObject

use of org.jetbrains.kotlin.psi.KtClassOrObject in project kotlin by JetBrains.

the class JavaElementFinder method findClassesAndObjects.

// Finds explicitly declared classes and objects, not package classes
// Also DefaultImpls classes of interfaces
private void findClassesAndObjects(FqName qualifiedName, GlobalSearchScope scope, List<PsiClass> answer) {
    findInterfaceDefaultImpls(qualifiedName, scope, answer);
    Collection<KtClassOrObject> classOrObjectDeclarations = lightClassGenerationSupport.findClassOrObjectDeclarations(qualifiedName, scope);
    for (KtClassOrObject declaration : classOrObjectDeclarations) {
        if (!(declaration instanceof KtEnumEntry)) {
            PsiClass lightClass = toLightClass(declaration);
            if (lightClass != null) {
                answer.add(lightClass);
            }
        }
    }
}
Also used : KtClassOrObject(org.jetbrains.kotlin.psi.KtClassOrObject) KtEnumEntry(org.jetbrains.kotlin.psi.KtEnumEntry)

Example 4 with KtClassOrObject

use of org.jetbrains.kotlin.psi.KtClassOrObject in project kotlin by JetBrains.

the class KotlinBytecodeToolWindow method compileSingleFile.

@NotNull
public static GenerationState compileSingleFile(@NotNull final KtFile ktFile, @NotNull CompilerConfiguration configuration) {
    ResolutionFacade resolutionFacade = ResolutionUtils.getResolutionFacade(ktFile);
    BindingContext bindingContextForFile = resolutionFacade.analyzeFullyAndGetResult(Collections.singletonList(ktFile)).getBindingContext();
    kotlin.Pair<BindingContext, List<KtFile>> result = DebuggerUtils.INSTANCE.analyzeInlinedFunctions(resolutionFacade, ktFile, configuration.getBoolean(CommonConfigurationKeys.DISABLE_INLINE), bindingContextForFile);
    BindingContext bindingContext = result.getFirst();
    List<KtFile> toProcess = result.getSecond();
    GenerationState.GenerateClassFilter generateClassFilter = new GenerationState.GenerateClassFilter() {

        @Override
        public boolean shouldGeneratePackagePart(@NotNull KtFile file) {
            return file == ktFile;
        }

        @Override
        public boolean shouldAnnotateClass(@NotNull KtClassOrObject processingClassOrObject) {
            return true;
        }

        @Override
        public boolean shouldGenerateClass(@NotNull KtClassOrObject processingClassOrObject) {
            return processingClassOrObject.getContainingKtFile() == ktFile;
        }

        @Override
        public boolean shouldGenerateScript(@NotNull KtScript script) {
            return script.getContainingKtFile() == ktFile;
        }
    };
    GenerationState state = new GenerationState(ktFile.getProject(), ClassBuilderFactories.TEST, resolutionFacade.getModuleDescriptor(), bindingContext, toProcess, configuration, generateClassFilter);
    KotlinCodegenFacade.compileCorrectFiles(state, CompilationErrorHandler.THROW_EXCEPTION);
    return state;
}
Also used : KtClassOrObject(org.jetbrains.kotlin.psi.KtClassOrObject) KtScript(org.jetbrains.kotlin.psi.KtScript) BindingContext(org.jetbrains.kotlin.resolve.BindingContext) NotNull(org.jetbrains.annotations.NotNull) GenerationState(org.jetbrains.kotlin.codegen.state.GenerationState) ResolutionFacade(org.jetbrains.kotlin.idea.resolve.ResolutionFacade) List(java.util.List) KtFile(org.jetbrains.kotlin.psi.KtFile) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with KtClassOrObject

use of org.jetbrains.kotlin.psi.KtClassOrObject in project kotlin by JetBrains.

the class KtFileTreeNode method getChildrenImpl.

@Override
public Collection<AbstractTreeNode> getChildrenImpl() {
    KtFile file = (KtFile) getValue();
    if (file == null)
        return Collections.emptyList();
    ArrayList<AbstractTreeNode> result = new ArrayList<AbstractTreeNode>();
    if (getSettings().isShowMembers()) {
        List<KtDeclaration> declarations = file.getDeclarations();
        for (KtDeclaration declaration : declarations) {
            if (declaration instanceof KtClassOrObject) {
                result.add(new KtClassOrObjectTreeNode(file.getProject(), (KtClassOrObject) declaration, getSettings()));
            } else if (getSettings().isShowMembers()) {
                result.add(new KtDeclarationTreeNode(getProject(), declaration, getSettings()));
            }
        }
    }
    return result;
}
Also used : KtClassOrObject(org.jetbrains.kotlin.psi.KtClassOrObject) KtDeclaration(org.jetbrains.kotlin.psi.KtDeclaration) ArrayList(java.util.ArrayList) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) KtFile(org.jetbrains.kotlin.psi.KtFile)

Aggregations

KtClassOrObject (org.jetbrains.kotlin.psi.KtClassOrObject)6 NotNull (org.jetbrains.annotations.NotNull)3 FqName (org.jetbrains.kotlin.name.FqName)2 KtFile (org.jetbrains.kotlin.psi.KtFile)2 AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)1 PsiElement (com.intellij.psi.PsiElement)1 SmartList (com.intellij.util.SmartList)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 GenerationState (org.jetbrains.kotlin.codegen.state.GenerationState)1 ResolutionFacade (org.jetbrains.kotlin.idea.resolve.ResolutionFacade)1 KtDeclaration (org.jetbrains.kotlin.psi.KtDeclaration)1 KtEnumEntry (org.jetbrains.kotlin.psi.KtEnumEntry)1 KtScript (org.jetbrains.kotlin.psi.KtScript)1 BindingContext (org.jetbrains.kotlin.resolve.BindingContext)1