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;
}
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);
}
}
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;
}
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);
}
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;
}
Aggregations