コード例 #1
0
  private Object[] processPackage(final PsiPackage aPackage) {
    final ArrayList<Object> list = new ArrayList<Object>();
    final int startOffset =
        StringUtil.isEmpty(aPackage.getName()) ? 0 : aPackage.getQualifiedName().length() + 1;
    final GlobalSearchScope scope = getScope();
    for (final PsiPackage subPackage : aPackage.getSubPackages(scope)) {
      final String shortName = subPackage.getQualifiedName().substring(startOffset);
      if (JavaPsiFacade.getInstance(subPackage.getProject())
          .getNameHelper()
          .isIdentifier(shortName)) {
        list.add(subPackage);
      }
    }

    final PsiClass[] classes = aPackage.getClasses(scope);
    final Map<CustomizableReferenceProvider.CustomizationKey, Object> options = getOptions();
    if (options != null) {
      final boolean instantiatable =
          JavaClassReferenceProvider.INSTANTIATABLE.getBooleanValue(options);
      final boolean concrete = JavaClassReferenceProvider.CONCRETE.getBooleanValue(options);
      final boolean notInterface =
          JavaClassReferenceProvider.NOT_INTERFACE.getBooleanValue(options);
      final boolean notEnum = JavaClassReferenceProvider.NOT_ENUM.getBooleanValue(options);
      final ClassKind classKind = getClassKind();

      for (PsiClass clazz : classes) {
        if (isClassAccepted(clazz, classKind, instantiatable, concrete, notInterface, notEnum)) {
          list.add(clazz);
        }
      }
    } else {
      ContainerUtil.addAll(list, classes);
    }
    return list.toArray();
  }
コード例 #2
0
  @Override
  @NotNull
  public Object[] getVariants() {
    Set<PsiPackage> subPackages = new HashSet<>();
    for (PsiPackage psiPackage : getContext()) {
      subPackages.addAll(
          Arrays.asList(psiPackage.getSubPackages(myReferenceSet.getResolveScope())));
    }

    return subPackages.toArray();
  }
コード例 #3
0
 private static PsiPackage getBasePackage(PsiPackage pack, GlobalSearchScope scope) {
   List<PsiPackage> subPackages =
       ContainerUtil.filter(pack.getSubPackages(scope), PACKAGE_CONDITION);
   return subPackages.size() == 1 ? getBasePackage(subPackages.get(0), scope) : pack;
 }
コード例 #4
0
ファイル: JavaPackageScope.java プロジェクト: mjedynak/kotlin
  /** @see JavaClassMembersScope#getAllDescriptors() */
  @NotNull
  @Override
  public Collection<DeclarationDescriptor> getAllDescriptors() {
    if (allDescriptors == null) {
      allDescriptors = Sets.newHashSet();

      if (psiClass != null) {
        allDescriptors.addAll(
            semanticServices.getDescriptorResolver().resolveMethods(psiClass, descriptor));

        allDescriptors.addAll(
            semanticServices
                .getDescriptorResolver()
                .resolveFieldGroup(descriptor, psiClass, staticMembers()));
      }

      final PsiPackage javaPackage =
          semanticServices.getDescriptorResolver().findPackage(packageFQN);

      if (javaPackage != null) {
        boolean isKotlinNamespace =
            semanticServices.getKotlinNamespaceDescriptor(
                    new FqName(javaPackage.getQualifiedName()))
                != null;
        final JavaDescriptorResolver descriptorResolver = semanticServices.getDescriptorResolver();

        for (PsiPackage psiSubPackage : javaPackage.getSubPackages()) {
          NamespaceDescriptor childNs =
              descriptorResolver.resolveNamespace(
                  new FqName(psiSubPackage.getQualifiedName()),
                  DescriptorSearchRule.IGNORE_IF_FOUND_IN_KOTLIN);
          if (childNs != null) {
            allDescriptors.add(childNs);
          }
        }

        for (PsiClass psiClass : javaPackage.getClasses()) {
          if (isKotlinNamespace && JvmAbi.PACKAGE_CLASS.equals(psiClass.getName())) {
            continue;
          }

          if (psiClass instanceof JetJavaMirrorMarker) {
            continue;
          }

          // TODO: Temp hack for collection function descriptors from java
          if (JvmAbi.PACKAGE_CLASS.equals(psiClass.getName())) {
            continue;
          }

          if (psiClass.hasModifierProperty(PsiModifier.PUBLIC)) {
            ClassDescriptor classDescriptor =
                descriptorResolver.resolveClass(
                    psiClass, DescriptorSearchRule.ERROR_IF_FOUND_IN_KOTLIN);
            if (classDescriptor != null) {
              allDescriptors.add(classDescriptor);
            }
          }
        }
      }
    }

    return allDescriptors;
  }