Search in sources :

Example 1 with QuickFixActionRegistrarImpl

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));
    }
}
Also used : HighlightInfo(com.intellij.codeInsight.daemon.impl.HighlightInfo) TextRange(com.intellij.openapi.util.TextRange) HighlightInfoType(com.intellij.codeInsight.daemon.impl.HighlightInfoType) QuickFixActionRegistrarImpl(com.intellij.codeInsight.daemon.impl.quickfix.QuickFixActionRegistrarImpl)

Example 2 with QuickFixActionRegistrarImpl

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;
    }
}
Also used : QuickFixActionRegistrarImpl(com.intellij.codeInsight.daemon.impl.quickfix.QuickFixActionRegistrarImpl) HighlightInfo(com.intellij.codeInsight.daemon.impl.HighlightInfo) IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with QuickFixActionRegistrarImpl

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;
}
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

QuickFixActionRegistrarImpl (com.intellij.codeInsight.daemon.impl.quickfix.QuickFixActionRegistrarImpl)3 HighlightInfo (com.intellij.codeInsight.daemon.impl.HighlightInfo)2 TextRange (com.intellij.openapi.util.TextRange)2 Nullable (org.jetbrains.annotations.Nullable)2 HighlightInfoType (com.intellij.codeInsight.daemon.impl.HighlightInfoType)1 CreateClassOrPackageFix (com.intellij.codeInsight.daemon.quickFix.CreateClassOrPackageFix)1 LocalQuickFix (com.intellij.codeInspection.LocalQuickFix)1 IndexNotReadyException (com.intellij.openapi.project.IndexNotReadyException)1 ClassKind (com.intellij.psi.util.ClassKind)1 ArrayList (java.util.ArrayList)1