Search in sources :

Example 1 with PackageReferenceSet

use of com.intellij.psi.impl.source.resolve.reference.impl.providers.PackageReferenceSet in project intellij-community by JetBrains.

the class PsiPackageConverter method createReferences.

@NotNull
public PsiReference[] createReferences(GenericDomValue<PsiPackage> genericDomValue, PsiElement element, ConvertContext context) {
    final String s = genericDomValue.getStringValue();
    if (s == null) {
        return PsiReference.EMPTY_ARRAY;
    }
    GlobalSearchScope scope = context.getSearchScope();
    return new PackageReferenceSet(s, element, ElementManipulators.getOffsetInElement(element), scope != null ? scope : GlobalSearchScope.allScope(element.getProject())).getPsiReferences();
}
Also used : GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) PackageReferenceSet(com.intellij.psi.impl.source.resolve.reference.impl.providers.PackageReferenceSet) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with PackageReferenceSet

use of com.intellij.psi.impl.source.resolve.reference.impl.providers.PackageReferenceSet in project intellij-plugins by JetBrains.

the class BasePackageParser method getPackageReferences.

protected static PsiReference[] getPackageReferences(PsiElement psiElement) {
    String packageName = psiElement.getText();
    if (StringUtil.isEmptyOrSpaces(packageName)) {
        return PsiReference.EMPTY_ARRAY;
    }
    int offset = 0;
    if (packageName.charAt(0) == '!') {
        packageName = packageName.substring(1);
        offset = 1;
    }
    int size = packageName.length() - 1;
    if (packageName.charAt(size) == '?') {
        packageName = packageName.substring(0, size);
    }
    PackageReferenceSet refSet = new PackageReferenceSet(packageName, psiElement, offset) {

        @Override
        public Collection<PsiPackage> resolvePackageName(@Nullable PsiPackage context, String packageName) {
            if (context == null)
                return Collections.emptyList();
            String unwrappedPackageName = packageName.replaceAll("\\s+", "");
            return ContainerUtil.filter(context.getSubPackages(), pkg -> unwrappedPackageName.equals(pkg.getName()));
        }
    };
    return refSet.getReferences().toArray(new PsiPackageReference[0]);
}
Also used : PackageReferenceSet(com.intellij.psi.impl.source.resolve.reference.impl.providers.PackageReferenceSet) PsiPackage(com.intellij.psi.PsiPackage) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

PackageReferenceSet (com.intellij.psi.impl.source.resolve.reference.impl.providers.PackageReferenceSet)2 PsiPackage (com.intellij.psi.PsiPackage)1 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)1 NotNull (org.jetbrains.annotations.NotNull)1 Nullable (org.jetbrains.annotations.Nullable)1