use of com.intellij.codeInsight.daemon.quickFix.CreateClassOrPackageFix 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