Search in sources :

Example 96 with HighlightInfo

use of com.intellij.codeInsight.daemon.impl.HighlightInfo in project intellij-community by JetBrains.

the class HighlightVisitorInternalInspection method buildVisitor.

@NotNull
@Override
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly) {
    final PsiFile file = holder.getFile();
    if (InjectedLanguageManager.getInstance(file.getProject()).isInjectedFragment(file)) {
        return PsiElementVisitor.EMPTY_VISITOR;
    }
    final VirtualFile virtualFile = PsiUtilCore.getVirtualFile(file);
    if (virtualFile == null || virtualFile.getFileType() != StdFileTypes.JAVA || CompilerConfiguration.getInstance(holder.getProject()).isExcludedFromCompilation(virtualFile)) {
        return PsiElementVisitor.EMPTY_VISITOR;
    }
    return new HighlightVisitorImpl(JavaPsiFacade.getInstance(holder.getProject()).getResolveHelper()) {

        {
            prepareToRunAsInspection(new HighlightInfoHolder(file) {

                @Override
                public boolean add(@Nullable HighlightInfo info) {
                    if (super.add(info)) {
                        if (info != null && info.getSeverity() == HighlightSeverity.ERROR) {
                            final int startOffset = info.getStartOffset();
                            final PsiElement element = file.findElementAt(startOffset);
                            if (element != null) {
                                holder.registerProblem(element, info.getDescription());
                            }
                        }
                        return true;
                    }
                    return false;
                }

                @Override
                public boolean hasErrorResults() {
                    //accept multiple errors per file
                    return false;
                }
            });
        }
    };
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) HighlightVisitorImpl(com.intellij.codeInsight.daemon.impl.analysis.HighlightVisitorImpl) HighlightInfoHolder(com.intellij.codeInsight.daemon.impl.analysis.HighlightInfoHolder) HighlightInfo(com.intellij.codeInsight.daemon.impl.HighlightInfo) PsiFile(com.intellij.psi.PsiFile) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 97 with HighlightInfo

use of com.intellij.codeInsight.daemon.impl.HighlightInfo in project intellij-community by JetBrains.

the class InaccessibleElementVisitor method visitReferenceExpression.

@Override
public void visitReferenceExpression(@NotNull GrReferenceExpression referenceExpression) {
    final int size = myInfos.size();
    super.visitReferenceExpression(referenceExpression);
    if (size == myInfos.size()) {
        HighlightInfo info = myReferenceChecker.checkReferenceExpression(referenceExpression);
        if (info != null) {
            myInfos.add(info);
        }
    }
}
Also used : HighlightInfo(com.intellij.codeInsight.daemon.impl.HighlightInfo)

Example 98 with HighlightInfo

use of com.intellij.codeInsight.daemon.impl.HighlightInfo in project intellij-community by JetBrains.

the class GrUnresolvedAccessChecker method registerStaticImportFix.

@Nullable
private static HighlightInfo registerStaticImportFix(@NotNull GrReferenceExpression referenceExpression, @Nullable final HighlightDisplayKey key) {
    final String referenceName = referenceExpression.getReferenceName();
    if (StringUtil.isEmpty(referenceName))
        return null;
    if (referenceExpression.getQualifier() != null)
        return null;
    HighlightInfo info = HighlightInfo.newHighlightInfo(HighlightInfoType.INFORMATION).range(referenceExpression.getParent()).createUnconditionally();
    QuickFixAction.registerQuickFixAction(info, GroovyQuickFixFactory.getInstance().createGroovyStaticImportMethodFix((GrMethodCall) referenceExpression.getParent()), key);
    return info;
}
Also used : HighlightInfo(com.intellij.codeInsight.daemon.impl.HighlightInfo) Nullable(org.jetbrains.annotations.Nullable)

Example 99 with HighlightInfo

use of com.intellij.codeInsight.daemon.impl.HighlightInfo in project intellij-community by JetBrains.

the class GrUnresolvedAccessChecker method checkCodeRefInner.

@Nullable
private HighlightInfo checkCodeRefInner(GrCodeReferenceElement refElement) {
    if (PsiTreeUtil.getParentOfType(refElement, GroovyDocPsiElement.class) != null)
        return null;
    PsiElement nameElement = refElement.getReferenceNameElement();
    if (nameElement == null)
        return null;
    if (isResolvedStaticImport(refElement))
        return null;
    GroovyResolveResult resolveResult = refElement.advancedResolve();
    final PsiElement resolved = resolveResult.getElement();
    if (!(refElement.getParent() instanceof GrPackageDefinition) && resolved == null) {
        String message = GroovyBundle.message("cannot.resolve", refElement.getReferenceName());
        HighlightInfo info = HighlightInfo.newHighlightInfo(HighlightInfoType.WRONG_REF).range(nameElement).descriptionAndTooltip(message).create();
        // todo implement for nested classes
        registerCreateClassByTypeFix(refElement, info, myDisplayKey);
        registerAddImportFixes(refElement, info, myDisplayKey);
        UnresolvedReferenceQuickFixProvider.registerReferenceFixes(refElement, new QuickFixActionRegistrarAdapter(info, myDisplayKey));
        QuickFixFactory.getInstance().registerOrderEntryFixes(new QuickFixActionRegistrarAdapter(info, myDisplayKey), refElement);
        return info;
    }
    if (refElement.getParent() instanceof GrNewExpression) {
        boolean inStaticContext = GrStaticChecker.isInStaticContext(refElement);
        if (!inStaticContext && GrUnresolvedAccessInspection.isSuppressed(refElement))
            return null;
        if (!inStaticContext) {
            if (!myInspectionEnabled)
                return null;
            assert myInspection != null;
            if (!myInspection.myHighlightInnerClasses)
                return null;
        }
        GrNewExpression newExpression = (GrNewExpression) refElement.getParent();
        if (resolved instanceof PsiClass) {
            PsiClass clazz = (PsiClass) resolved;
            final PsiClass outerClass = clazz.getContainingClass();
            if (com.intellij.psi.util.PsiUtil.isInnerClass(clazz) && outerClass != null && newExpression.getArgumentList() != null && !PsiUtil.hasEnclosingInstanceInScope(outerClass, newExpression, true) && !hasEnclosingInstanceInArgList(newExpression.getArgumentList(), outerClass)) {
                String qname = clazz.getQualifiedName();
                LOG.assertTrue(qname != null, clazz.getText());
                return createAnnotationForRef(refElement, inStaticContext, GroovyBundle.message("cannot.reference.non.static", qname));
            }
        }
    }
    return null;
}
Also used : GroovyResolveResult(org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult) GroovyDocPsiElement(org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GroovyDocPsiElement) HighlightInfo(com.intellij.codeInsight.daemon.impl.HighlightInfo) GrPackageDefinition(org.jetbrains.plugins.groovy.lang.psi.api.toplevel.packaging.GrPackageDefinition) GroovyPsiElement(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement) GroovyDocPsiElement(org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GroovyDocPsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 100 with HighlightInfo

use of com.intellij.codeInsight.daemon.impl.HighlightInfo in project intellij-community by JetBrains.

the class GrUnresolvedAccessChecker method checkCodeReferenceElement.

@Nullable
public HighlightInfo checkCodeReferenceElement(GrCodeReferenceElement refElement) {
    HighlightInfo info = checkCodeRefInner(refElement);
    addEmptyIntentionIfNeeded(info);
    return info;
}
Also used : HighlightInfo(com.intellij.codeInsight.daemon.impl.HighlightInfo) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

HighlightInfo (com.intellij.codeInsight.daemon.impl.HighlightInfo)221 Nullable (org.jetbrains.annotations.Nullable)51 TextRange (com.intellij.openapi.util.TextRange)33 IntentionAction (com.intellij.codeInsight.intention.IntentionAction)30 VirtualFile (com.intellij.openapi.vfs.VirtualFile)28 NotNull (org.jetbrains.annotations.NotNull)17 HighlightInfoType (com.intellij.codeInsight.daemon.impl.HighlightInfoType)16 Document (com.intellij.openapi.editor.Document)12 ArrayList (java.util.ArrayList)11 PsiElement (com.intellij.psi.PsiElement)10 File (java.io.File)8 TextAttributes (com.intellij.openapi.editor.markup.TextAttributes)7 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)6 Pair (com.intellij.openapi.util.Pair)6 PsiFile (com.intellij.psi.PsiFile)6 Editor (com.intellij.openapi.editor.Editor)5 NonNls (org.jetbrains.annotations.NonNls)5 StringUtil (com.intellij.openapi.util.text.StringUtil)4 IElementType (com.intellij.psi.tree.IElementType)4 ContainerUtil (com.intellij.util.containers.ContainerUtil)4