Search in sources :

Example 1 with PsiPackage

use of com.intellij.psi.PsiPackage in project buck by facebook.

the class BuckCopyPasteProcessor method referenceNameToBuckFile.

private VirtualFile referenceNameToBuckFile(Project project, String reference) {
    // First test if it is a absolute path of a file.
    File tryFile = new File(reference);
    if (tryFile != null) {
        VirtualFile file = VfsUtil.findFileByIoFile(tryFile, true);
        if (file != null) {
            return BuckBuildUtil.getBuckFileFromDirectory(file.getParent());
        }
    }
    // Try class firstly.
    PsiClass classElement = JavaPsiFacade.getInstance(project).findClass(reference, GlobalSearchScope.allScope(project));
    if (classElement != null) {
        VirtualFile file = PsiUtilCore.getVirtualFile(classElement);
        return BuckBuildUtil.getBuckFileFromDirectory(file.getParent());
    }
    // Then try package.
    PsiPackage packageElement = JavaPsiFacade.getInstance(project).findPackage(reference);
    if (packageElement != null) {
        PsiDirectory directory = packageElement.getDirectories()[0];
        return BuckBuildUtil.getBuckFileFromDirectory(directory.getVirtualFile());
    }
    // Extract the package from the reference.
    int index = reference.lastIndexOf(".");
    if (index == -1) {
        return null;
    }
    reference = reference.substring(0, index);
    // Try to find the package again.
    packageElement = JavaPsiFacade.getInstance(project).findPackage(reference);
    if (packageElement != null) {
        PsiDirectory directory = packageElement.getDirectories()[0];
        return BuckBuildUtil.getBuckFileFromDirectory(directory.getVirtualFile());
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiDirectory(com.intellij.psi.PsiDirectory) PsiClass(com.intellij.psi.PsiClass) PsiPackage(com.intellij.psi.PsiPackage) VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiFile(com.intellij.psi.PsiFile) BuckFile(com.facebook.buck.intellij.ideabuck.lang.BuckFile) File(java.io.File)

Example 2 with PsiPackage

use of com.intellij.psi.PsiPackage in project intellij-community by JetBrains.

the class GroovyDocAddPackageAction method actionPerformed.

@Override
public void actionPerformed(final AnActionEvent e) {
    final Project project = e.getProject();
    PackageChooserDialog chooser = new PackageChooserDialog("Choose packages", project);
    chooser.show();
    final List<PsiPackage> packages = chooser.getSelectedPackages();
    for (PsiPackage aPackage : packages) {
        final String qualifiedName = aPackage.getQualifiedName();
        if (qualifiedName.isEmpty()) {
            myDataModel.addElement(GroovyDocConfiguration.ALL_PACKAGES);
        }
        myDataModel.addElement(qualifiedName);
    }
}
Also used : Project(com.intellij.openapi.project.Project) PackageChooserDialog(com.intellij.ide.util.PackageChooserDialog) PsiPackage(com.intellij.psi.PsiPackage)

Example 3 with PsiPackage

use of com.intellij.psi.PsiPackage in project intellij-community by JetBrains.

the class PyJavaImportResolver method resolveImportReference.

@Nullable
public PsiElement resolveImportReference(QualifiedName name, PyQualifiedNameResolveContext context, boolean withRoots) {
    String fqn = name.toString();
    final JavaPsiFacade psiFacade = JavaPsiFacade.getInstance(context.getProject());
    final PsiPackage aPackage = psiFacade.findPackage(fqn);
    if (aPackage != null) {
        return aPackage;
    }
    Module module = context.getModule();
    if (module != null) {
        final PsiClass aClass = psiFacade.findClass(fqn, module.getModuleWithDependenciesAndLibrariesScope(false));
        if (aClass != null)
            return aClass;
    }
    return null;
}
Also used : JavaPsiFacade(com.intellij.psi.JavaPsiFacade) PsiClass(com.intellij.psi.PsiClass) PsiPackage(com.intellij.psi.PsiPackage) Module(com.intellij.openapi.module.Module) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with PsiPackage

use of com.intellij.psi.PsiPackage in project intellij-community by JetBrains.

the class PyJavaPackageType method getCompletionVariants.

@Override
public Object[] getCompletionVariants(String completionPrefix, PsiElement location, ProcessingContext context) {
    List<Object> variants = new ArrayList<>();
    final GlobalSearchScope scope = getScope(location.getProject());
    final PsiClass[] classes = myPackage.getClasses(scope);
    for (PsiClass psiClass : classes) {
        variants.add(LookupElementBuilder.create(psiClass).withIcon(psiClass.getIcon(0)));
    }
    final PsiPackage[] subPackages = myPackage.getSubPackages(scope);
    for (PsiPackage subPackage : subPackages) {
        variants.add(LookupElementBuilder.create(subPackage).withIcon(subPackage.getIcon(0)));
    }
    return ArrayUtil.toObjectArray(variants);
}
Also used : GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) ArrayList(java.util.ArrayList) PsiClass(com.intellij.psi.PsiClass) PsiPackage(com.intellij.psi.PsiPackage)

Example 5 with PsiPackage

use of com.intellij.psi.PsiPackage in project intellij-community by JetBrains.

the class MvcTargetDialogCompletionUtils method completeClassesAndPackages.

public static List<LookupElement> completeClassesAndPackages(@NotNull String prefix, @NotNull GlobalSearchScope scope) {
    if (scope.getProject() == null)
        return Collections.emptyList();
    JavaPsiFacade facade = JavaPsiFacade.getInstance(scope.getProject());
    final List<LookupElement> res = new ArrayList<>();
    // Complete class names if prefix is a package name with dot at end.
    if (prefix.endsWith(".") && prefix.length() > 1) {
        PsiPackage p = facade.findPackage(prefix.substring(0, prefix.length() - 1));
        if (p != null) {
            for (PsiClass aClass : p.getClasses(scope)) {
                String qualifiedName = aClass.getQualifiedName();
                if (qualifiedName != null) {
                    res.add(LookupElementBuilder.create(aClass, qualifiedName));
                }
            }
        }
    }
    PsiPackage defaultPackage = facade.findPackage("");
    if (defaultPackage != null) {
        collectClassesAndPackageNames(res, defaultPackage, scope);
    }
    return res;
}
Also used : JavaPsiFacade(com.intellij.psi.JavaPsiFacade) PsiClass(com.intellij.psi.PsiClass) PsiPackage(com.intellij.psi.PsiPackage) LookupElement(com.intellij.codeInsight.lookup.LookupElement)

Aggregations

PsiPackage (com.intellij.psi.PsiPackage)93 PsiDirectory (com.intellij.psi.PsiDirectory)24 PsiClass (com.intellij.psi.PsiClass)22 Module (com.intellij.openapi.module.Module)19 Project (com.intellij.openapi.project.Project)14 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)14 VirtualFile (com.intellij.openapi.vfs.VirtualFile)13 JavaAnalysisScope (com.intellij.analysis.JavaAnalysisScope)12 PsiFile (com.intellij.psi.PsiFile)12 PsiElement (com.intellij.psi.PsiElement)11 JavaPsiFacade (com.intellij.psi.JavaPsiFacade)10 NotNull (org.jetbrains.annotations.NotNull)10 CyclicDependenciesBuilder (com.intellij.cyclicDependencies.CyclicDependenciesBuilder)9 Nullable (org.jetbrains.annotations.Nullable)9 AnalysisScope (com.intellij.analysis.AnalysisScope)8 HashSet (java.util.HashSet)6 List (java.util.List)5 LookupElement (com.intellij.codeInsight.lookup.LookupElement)4 AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)4 ArrayList (java.util.ArrayList)4