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