use of com.intellij.codeInsight.daemon.impl.quickfix.QuickFixActionRegistrarImpl in project intellij-community by JetBrains.
the class XmlHighlightVisitor method doCheckRefs.
private void doCheckRefs(final PsiElement value, final PsiReference[] references, int start) {
for (int i = start; i < references.length; ++i) {
PsiReference reference = references[i];
ProgressManager.checkCanceled();
if (isUrlReference(reference))
continue;
if (!hasBadResolve(reference, false)) {
continue;
}
String description = getErrorDescription(reference);
final int startOffset = reference.getElement().getTextRange().getStartOffset();
final TextRange referenceRange = reference.getRangeInElement();
// logging for IDEADEV-29655
if (referenceRange.getStartOffset() > referenceRange.getEndOffset()) {
LOG.error("Reference range start offset > end offset: " + reference + ", start offset: " + referenceRange.getStartOffset() + ", end offset: " + referenceRange.getEndOffset());
}
HighlightInfoType type = getTagProblemInfoType(PsiTreeUtil.getParentOfType(value, XmlTag.class));
if (value instanceof XmlAttributeValue) {
PsiElement parent = value.getParent();
if (parent instanceof XmlAttribute) {
String name = ((XmlAttribute) parent).getName().toLowerCase();
if (type.getSeverity(null).compareTo(HighlightInfoType.WARNING.getSeverity(null)) > 0 && name.endsWith("stylename")) {
type = HighlightInfoType.WARNING;
}
}
}
HighlightInfo info = HighlightInfo.newHighlightInfo(type).range(startOffset + referenceRange.getStartOffset(), startOffset + referenceRange.getEndOffset()).descriptionAndTooltip(description).create();
addToResults(info);
if (reference instanceof LocalQuickFixProvider) {
LocalQuickFix[] fixes = ((LocalQuickFixProvider) reference).getQuickFixes();
if (fixes != null) {
InspectionManager manager = InspectionManager.getInstance(reference.getElement().getProject());
for (LocalQuickFix fix : fixes) {
ProblemDescriptor descriptor = manager.createProblemDescriptor(value, description, fix, ProblemHighlightType.GENERIC_ERROR_OR_WARNING, true);
QuickFixAction.registerQuickFixAction(info, new LocalQuickFixAsIntentionAdapter(fix, descriptor));
}
}
}
UnresolvedReferenceQuickFixProvider.registerReferenceFixes(reference, new QuickFixActionRegistrarImpl(info));
}
}
use of com.intellij.codeInsight.daemon.impl.quickfix.QuickFixActionRegistrarImpl in project intellij-community by JetBrains.
the class GenericsHighlightUtil method checkOverrideAnnotation.
@Nullable
static HighlightInfo checkOverrideAnnotation(@NotNull PsiMethod method, @NotNull PsiAnnotation overrideAnnotation, @NotNull LanguageLevel languageLevel) {
try {
MethodSignatureBackedByPsiMethod superMethod = SuperMethodsSearch.search(method, null, true, false).findFirst();
if (superMethod != null && method.getContainingClass().isInterface()) {
final PsiMethod psiMethod = superMethod.getMethod();
final PsiClass containingClass = psiMethod.getContainingClass();
if (containingClass != null && CommonClassNames.JAVA_LANG_OBJECT.equals(containingClass.getQualifiedName()) && psiMethod.hasModifierProperty(PsiModifier.PROTECTED)) {
superMethod = null;
}
}
if (superMethod == null) {
String description = JavaErrorMessages.message("method.does.not.override.super");
HighlightInfo highlightInfo = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(overrideAnnotation).descriptionAndTooltip(description).create();
QUICK_FIX_FACTORY.registerPullAsAbstractUpFixes(method, new QuickFixActionRegistrarImpl(highlightInfo));
return highlightInfo;
}
PsiClass superClass = superMethod.getMethod().getContainingClass();
if (languageLevel.equals(LanguageLevel.JDK_1_5) && superClass != null && superClass.isInterface()) {
String description = JavaErrorMessages.message("override.not.allowed.in.interfaces");
HighlightInfo info = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(overrideAnnotation).descriptionAndTooltip(description).create();
QuickFixAction.registerQuickFixAction(info, QUICK_FIX_FACTORY.createIncreaseLanguageLevelFix(LanguageLevel.JDK_1_6));
return info;
}
return null;
} catch (IndexNotReadyException e) {
return null;
}
}
use of com.intellij.codeInsight.daemon.impl.quickfix.QuickFixActionRegistrarImpl 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