Search in sources :

Example 1 with ClassKind

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

the class JavaClassReference method processSubclassVariants.

public void processSubclassVariants(@NotNull PsiPackage context, @NotNull String[] extendClasses, Consumer<LookupElement> result) {
    GlobalSearchScope packageScope = PackageScope.packageScope(context, true);
    GlobalSearchScope scope = myJavaClassReferenceSet.getProvider().getScope(getElement().getProject());
    if (scope != null) {
        packageScope = packageScope.intersectWith(scope);
    }
    final GlobalSearchScope allScope = ProjectScope.getAllScope(context.getProject());
    final boolean instantiatable = JavaClassReferenceProvider.INSTANTIATABLE.getBooleanValue(getOptions());
    final boolean notInterface = JavaClassReferenceProvider.NOT_INTERFACE.getBooleanValue(getOptions());
    final boolean notEnum = JavaClassReferenceProvider.NOT_ENUM.getBooleanValue(getOptions());
    final boolean concrete = JavaClassReferenceProvider.CONCRETE.getBooleanValue(getOptions());
    final ClassKind classKind = getClassKind();
    for (String extendClassName : extendClasses) {
        final PsiClass extendClass = JavaPsiFacade.getInstance(context.getProject()).findClass(extendClassName, allScope);
        if (extendClass != null) {
            // add itself
            if (packageScope.contains(extendClass.getContainingFile().getVirtualFile())) {
                if (isClassAccepted(extendClass, classKind, instantiatable, concrete, notInterface, notEnum)) {
                    result.consume(createSubclassLookupValue(extendClass));
                }
            }
            for (final PsiClass clazz : ClassInheritorsSearch.search(extendClass, packageScope, true)) {
                String qname = clazz.getQualifiedName();
                if (qname != null && isClassAccepted(clazz, classKind, instantiatable, concrete, notInterface, notEnum)) {
                    result.consume(createSubclassLookupValue(clazz));
                }
            }
        }
    }
}
Also used : GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) ClassKind(com.intellij.psi.util.ClassKind)

Example 2 with ClassKind

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

the class JavaClassReference method processPackage.

@NotNull
private LookupElement[] processPackage(@NotNull PsiPackage aPackage) {
    final ArrayList<LookupElement> list = ContainerUtil.newArrayList();
    final int startOffset = StringUtil.isEmpty(aPackage.getName()) ? 0 : aPackage.getQualifiedName().length() + 1;
    final GlobalSearchScope scope = getScope(getJavaContextFile());
    for (final PsiPackage subPackage : aPackage.getSubPackages(scope)) {
        final String shortName = subPackage.getQualifiedName().substring(startOffset);
        if (PsiNameHelper.getInstance(subPackage.getProject()).isIdentifier(shortName)) {
            list.add(LookupElementBuilder.create(subPackage).withIcon(subPackage.getIcon(Iconable.ICON_FLAG_VISIBILITY)));
        }
    }
    final List<PsiClass> classes = ContainerUtil.filter(aPackage.getClasses(scope), psiClass -> StringUtil.isNotEmpty(psiClass.getName()));
    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(JavaClassNameCompletionContributor.createClassLookupItem(clazz, false));
            }
        }
    } else {
        for (PsiClass clazz : classes) {
            list.add(JavaClassNameCompletionContributor.createClassLookupItem(clazz, false));
        }
    }
    return list.toArray(new LookupElement[list.size()]);
}
Also used : LookupElement(com.intellij.codeInsight.lookup.LookupElement) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) ClassKind(com.intellij.psi.util.ClassKind) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with ClassKind

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

the class JavaClassReference method registerFixes.

@Nullable
private List<? extends LocalQuickFix> registerFixes() {
    final List<LocalQuickFix> list = QuickFixFactory.getInstance().registerOrderEntryFixes(new QuickFixActionRegistrarImpl(null), this);
    final String[] extendClasses = getExtendClassNames();
    final String extendClass = extendClasses != null && extendClasses.length > 0 ? extendClasses[0] : null;
    final JavaClassReference[] references = getJavaClassReferenceSet().getAllReferences();
    PsiPackage contextPackage = null;
    for (int i = myIndex; i >= 0; i--) {
        final PsiElement context = references[i].getContext();
        if (context != null) {
            if (context instanceof PsiPackage) {
                contextPackage = (PsiPackage) context;
            }
            break;
        }
    }
    boolean createJavaClass = !canReferencePackage();
    ClassKind kind = createJavaClass ? getClassKind() : null;
    if (createJavaClass && kind == null)
        kind = ClassKind.CLASS;
    final String templateName = JavaClassReferenceProvider.CLASS_TEMPLATE.getValue(getOptions());
    final TextRange range = new TextRange(references[0].getRangeInElement().getStartOffset(), getRangeInElement().getEndOffset());
    final String qualifiedName = range.substring(getElement().getText());
    final CreateClassOrPackageFix action = CreateClassOrPackageFix.createFix(qualifiedName, getScope(getJavaContextFile()), getElement(), contextPackage, kind, extendClass, templateName);
    if (action != null) {
        if (list == null) {
            return Collections.singletonList(action);
        } else {
            final ArrayList<LocalQuickFix> fixes = new ArrayList<>(list.size() + 1);
            fixes.addAll(list);
            fixes.add(action);
            return fixes;
        }
    }
    return list;
}
Also used : CreateClassOrPackageFix(com.intellij.codeInsight.daemon.quickFix.CreateClassOrPackageFix) ArrayList(java.util.ArrayList) LocalQuickFix(com.intellij.codeInspection.LocalQuickFix) TextRange(com.intellij.openapi.util.TextRange) QuickFixActionRegistrarImpl(com.intellij.codeInsight.daemon.impl.quickfix.QuickFixActionRegistrarImpl) ClassKind(com.intellij.psi.util.ClassKind) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

ClassKind (com.intellij.psi.util.ClassKind)3 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)2 QuickFixActionRegistrarImpl (com.intellij.codeInsight.daemon.impl.quickfix.QuickFixActionRegistrarImpl)1 CreateClassOrPackageFix (com.intellij.codeInsight.daemon.quickFix.CreateClassOrPackageFix)1 LookupElement (com.intellij.codeInsight.lookup.LookupElement)1 LocalQuickFix (com.intellij.codeInspection.LocalQuickFix)1 TextRange (com.intellij.openapi.util.TextRange)1 ArrayList (java.util.ArrayList)1 NotNull (org.jetbrains.annotations.NotNull)1 Nullable (org.jetbrains.annotations.Nullable)1