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