Search in sources :

Example 36 with Attachment

use of com.intellij.openapi.diagnostic.Attachment in project intellij-community by JetBrains.

the class GroovyStringLexerBase method start.

@Override
public void start(@NotNull CharSequence buffer, int startOffset, int endOffset, int initialState) {
    if (buffer.length() < endOffset) {
        LOG.error("buffer Length: " + buffer.length() + ", endOffset: " + endOffset, new Attachment("", buffer.toString()));
    }
    myBuffer = buffer;
    myEnd = startOffset;
    myBufferEnd = endOffset;
    myTokenType = locateToken();
}
Also used : Attachment(com.intellij.openapi.diagnostic.Attachment)

Example 37 with Attachment

use of com.intellij.openapi.diagnostic.Attachment in project intellij-community by JetBrains.

the class ControlFlowBuilder method error.

private void error(String descr) {
    PsiFile file = myScope.getContainingFile();
    String fileText = file != null ? file.getText() : null;
    VirtualFile virtualFile = PsiUtilCore.getVirtualFile(file);
    String path = virtualFile == null ? null : virtualFile.getPresentableUrl();
    LOG.error(descr + myScope.getText(), new Attachment(path + "", fileText + ""));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Attachment(com.intellij.openapi.diagnostic.Attachment)

Example 38 with Attachment

use of com.intellij.openapi.diagnostic.Attachment in project intellij-community by JetBrains.

the class TemplateState method getCurrentSegmentNumber.

private int getCurrentSegmentNumber() {
    int varNumber = myCurrentVariableNumber;
    if (varNumber == -1) {
        return -1;
    }
    String variableName = myTemplate.getVariableNameAt(varNumber);
    int segmentNumber = myTemplate.getVariableSegmentNumber(variableName);
    if (segmentNumber < 0) {
        Throwable trace = myTemplate.getBuildingTemplateTrace();
        LOG.error("No segment for variable: var=" + varNumber + "; name=" + variableName + "; " + presentTemplate(myTemplate) + "; offset: " + myEditor.getCaretModel().getOffset(), AttachmentFactory.createAttachment(myDocument), new Attachment("trace.txt", trace != null ? ExceptionUtil.getThrowableText(trace) : "<empty>"));
    }
    return segmentNumber;
}
Also used : Attachment(com.intellij.openapi.diagnostic.Attachment)

Example 39 with Attachment

use of com.intellij.openapi.diagnostic.Attachment in project intellij-community by JetBrains.

the class ShowIntentionsPass method collectIntentionsFromDoNotShowLeveledInspections.

/**
   * Can be invoked in EDT, each inspection should be fast
   */
private static void collectIntentionsFromDoNotShowLeveledInspections(@NotNull final Project project, @NotNull final PsiFile hostFile, PsiElement psiElement, final int offset, @NotNull final IntentionsInfo intentions) {
    if (psiElement != null) {
        if (!psiElement.isPhysical()) {
            VirtualFile virtualFile = hostFile.getVirtualFile();
            String text = hostFile.getText();
            LOG.error("not physical: '" + psiElement.getText() + "' @" + offset + psiElement.getTextRange() + " elem:" + psiElement + " (" + psiElement.getClass().getName() + ")" + " in:" + psiElement.getContainingFile() + " host:" + hostFile + "(" + hostFile.getClass().getName() + ")", new Attachment(virtualFile != null ? virtualFile.getPresentableUrl() : "null", text != null ? text : "null"));
        }
        if (DumbService.isDumb(project)) {
            return;
        }
        final List<LocalInspectionToolWrapper> intentionTools = new ArrayList<>();
        final InspectionProfile profile = InspectionProjectProfileManager.getInstance(project).getInspectionProfile();
        final InspectionToolWrapper[] tools = profile.getInspectionTools(hostFile);
        for (InspectionToolWrapper toolWrapper : tools) {
            if (toolWrapper instanceof LocalInspectionToolWrapper && !((LocalInspectionToolWrapper) toolWrapper).isUnfair()) {
                final HighlightDisplayKey key = HighlightDisplayKey.find(toolWrapper.getShortName());
                if (profile.isToolEnabled(key, hostFile) && HighlightDisplayLevel.DO_NOT_SHOW.equals(profile.getErrorLevel(key, hostFile))) {
                    intentionTools.add((LocalInspectionToolWrapper) toolWrapper);
                }
            }
        }
        if (!intentionTools.isEmpty()) {
            final List<PsiElement> elements = new ArrayList<>();
            PsiElement el = psiElement;
            while (el != null) {
                elements.add(el);
                if (el instanceof PsiFile)
                    break;
                el = el.getParent();
            }
            final Set<String> dialectIds = InspectionEngine.calcElementDialectIds(elements);
            final LocalInspectionToolSession session = new LocalInspectionToolSession(hostFile, 0, hostFile.getTextLength());
            final Processor<LocalInspectionToolWrapper> processor = toolWrapper -> {
                final LocalInspectionTool localInspectionTool = toolWrapper.getTool();
                final HighlightDisplayKey key = HighlightDisplayKey.find(toolWrapper.getShortName());
                final String displayName = toolWrapper.getDisplayName();
                final ProblemsHolder holder = new ProblemsHolder(InspectionManager.getInstance(project), hostFile, true) {

                    @Override
                    public void registerProblem(@NotNull ProblemDescriptor problemDescriptor) {
                        super.registerProblem(problemDescriptor);
                        if (problemDescriptor instanceof ProblemDescriptorBase) {
                            final TextRange range = ((ProblemDescriptorBase) problemDescriptor).getTextRange();
                            if (range != null && range.contains(offset)) {
                                final QuickFix[] fixes = problemDescriptor.getFixes();
                                if (fixes != null) {
                                    for (int k = 0; k < fixes.length; k++) {
                                        final IntentionAction intentionAction = QuickFixWrapper.wrap(problemDescriptor, k);
                                        final HighlightInfo.IntentionActionDescriptor actionDescriptor = new HighlightInfo.IntentionActionDescriptor(intentionAction, null, displayName, null, key, null, HighlightSeverity.INFORMATION);
                                        intentions.intentionsToShow.add(actionDescriptor);
                                    }
                                }
                            }
                        }
                    }
                };
                InspectionEngine.createVisitorAndAcceptElements(localInspectionTool, holder, true, session, elements, dialectIds, InspectionEngine.getDialectIdsSpecifiedForTool(toolWrapper));
                localInspectionTool.inspectionFinished(session, holder);
                return true;
            };
            JobLauncher.getInstance().invokeConcurrentlyUnderProgress(intentionTools, new DaemonProgressIndicator(), false, processor);
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VirtualFile(com.intellij.openapi.vfs.VirtualFile) HighlightSeverity(com.intellij.lang.annotation.HighlightSeverity) Document(com.intellij.openapi.editor.Document) MarkupModelEx(com.intellij.openapi.editor.ex.MarkupModelEx) DocumentMarkupModel(com.intellij.openapi.editor.impl.DocumentMarkupModel) QuickFixWrapper(com.intellij.codeInspection.ex.QuickFixWrapper) RangeHighlighterEx(com.intellij.openapi.editor.ex.RangeHighlighterEx) EditorEx(com.intellij.openapi.editor.ex.EditorEx) HighlightingLevelManager(com.intellij.codeInsight.daemon.impl.analysis.HighlightingLevelManager) Logger(com.intellij.openapi.diagnostic.Logger) CommonProcessors(com.intellij.util.CommonProcessors) RangeMarker(com.intellij.openapi.editor.RangeMarker) DumbService(com.intellij.openapi.project.DumbService) HighlightDisplayKey(com.intellij.codeInsight.daemon.HighlightDisplayKey) IntentionHintComponent(com.intellij.codeInsight.intention.impl.IntentionHintComponent) Processors(com.intellij.util.Processors) Set(java.util.Set) TextRange(com.intellij.openapi.util.TextRange) LogicalPosition(com.intellij.openapi.editor.LogicalPosition) CleanupAllIntention(com.intellij.codeInspection.actions.CleanupAllIntention) Nullable(org.jetbrains.annotations.Nullable) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) List(java.util.List) TextEditorHighlightingPass(com.intellij.codeHighlighting.TextEditorHighlightingPass) Processor(com.intellij.util.Processor) ApplicationManager(com.intellij.openapi.application.ApplicationManager) IntentionManagerSettings(com.intellij.codeInsight.intention.impl.config.IntentionManagerSettings) IntentionAction(com.intellij.codeInsight.intention.IntentionAction) NotNull(org.jetbrains.annotations.NotNull) InspectionProjectProfileManager(com.intellij.profile.codeInspection.InspectionProjectProfileManager) TemplateManagerImpl(com.intellij.codeInsight.template.impl.TemplateManagerImpl) JobLauncher(com.intellij.concurrency.JobLauncher) LocalInspectionToolWrapper(com.intellij.codeInspection.ex.LocalInspectionToolWrapper) NonNls(org.jetbrains.annotations.NonNls) DaemonCodeAnalyzer(com.intellij.codeInsight.daemon.DaemonCodeAnalyzer) ContainerUtil(com.intellij.util.containers.ContainerUtil) ArrayList(java.util.ArrayList) PsiElement(com.intellij.psi.PsiElement) PsiWhiteSpace(com.intellij.psi.PsiWhiteSpace) IntentionManager(com.intellij.codeInsight.intention.IntentionManager) Project(com.intellij.openapi.project.Project) PsiFile(com.intellij.psi.PsiFile) Segment(com.intellij.openapi.util.Segment) InjectedLanguageUtil(com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil) PsiDocumentManager(com.intellij.psi.PsiDocumentManager) Iterator(java.util.Iterator) FileDocumentManager(com.intellij.openapi.fileEditor.FileDocumentManager) com.intellij.codeInspection(com.intellij.codeInspection) HighlightDisplayLevel(com.intellij.codeHighlighting.HighlightDisplayLevel) Editor(com.intellij.openapi.editor.Editor) java.awt(java.awt) ShowIntentionActionsHandler(com.intellij.codeInsight.intention.impl.ShowIntentionActionsHandler) InspectionToolWrapper(com.intellij.codeInspection.ex.InspectionToolWrapper) Pair(com.intellij.openapi.util.Pair) Attachment(com.intellij.openapi.diagnostic.Attachment) HintManager(com.intellij.codeInsight.hint.HintManager) TemplateState(com.intellij.codeInsight.template.impl.TemplateState) HighlightDisplayKey(com.intellij.codeInsight.daemon.HighlightDisplayKey) ArrayList(java.util.ArrayList) Attachment(com.intellij.openapi.diagnostic.Attachment) PsiFile(com.intellij.psi.PsiFile) LocalInspectionToolWrapper(com.intellij.codeInspection.ex.LocalInspectionToolWrapper) PsiElement(com.intellij.psi.PsiElement) TextRange(com.intellij.openapi.util.TextRange) IntentionAction(com.intellij.codeInsight.intention.IntentionAction) LocalInspectionToolWrapper(com.intellij.codeInspection.ex.LocalInspectionToolWrapper) InspectionToolWrapper(com.intellij.codeInspection.ex.InspectionToolWrapper)

Example 40 with Attachment

use of com.intellij.openapi.diagnostic.Attachment in project intellij-community by JetBrains.

the class PhysicalDomParentStrategy method strategyEquals.

public static boolean strategyEquals(DomParentStrategy strategy, final Object o) {
    if (strategy == o)
        return true;
    if (!(o instanceof DomParentStrategy))
        return false;
    final XmlElement thatElement = ((DomParentStrategy) o).getXmlElement();
    if (thatElement == null)
        return false;
    XmlElement element = strategy.getXmlElement();
    if (element == null)
        return false;
    if (xmlElementsEqual(element, thatElement)) {
        if (element != thatElement) {
            final PsiElement nav1 = element.getNavigationElement();
            final PsiElement nav2 = thatElement.getNavigationElement();
            if (nav1 != nav2) {
                PsiElement curContext = findIncluder(element);
                PsiElement navContext = findIncluder(nav1);
                LOG.error(LogMessageEx.createEvent("x:include processing error", "nav1,nav2=" + nav1 + ", " + nav2 + ";\n" + nav1.getContainingFile() + ":" + nav1.getTextRange().getStartOffset() + "!=" + nav2.getContainingFile() + ":" + nav2.getTextRange().getStartOffset() + ";\n" + (nav1 == element) + ";" + (nav2 == thatElement) + ";\n" + "contexts equal: " + (curContext == navContext) + ";\n" + "curContext?.physical=" + (curContext != null && curContext.isPhysical()) + ";\n" + "navContext?.physical=" + (navContext != null && navContext.isPhysical()) + ";\n" + "myElement.physical=" + element.isPhysical() + ";\n" + "thatElement.physical=" + thatElement.isPhysical() + "\n" + DebugUtil.currentStackTrace(), new Attachment("Including tag text 1.xml", curContext == null ? "null" : curContext.getText()), new Attachment("Including tag text 2.xml", navContext == null ? "null" : navContext.getText())));
                throw new AssertionError();
            }
        }
        return true;
    }
    return false;
}
Also used : XmlElement(com.intellij.psi.xml.XmlElement) Attachment(com.intellij.openapi.diagnostic.Attachment) PsiElement(com.intellij.psi.PsiElement)

Aggregations

Attachment (com.intellij.openapi.diagnostic.Attachment)41 VirtualFile (com.intellij.openapi.vfs.VirtualFile)12 NotNull (org.jetbrains.annotations.NotNull)10 Project (com.intellij.openapi.project.Project)6 ArrayList (java.util.ArrayList)6 Document (com.intellij.openapi.editor.Document)5 TextRange (com.intellij.openapi.util.TextRange)4 LogEventException (com.intellij.diagnostic.LogEventException)3 Logger (com.intellij.openapi.diagnostic.Logger)3 PsiElement (com.intellij.psi.PsiElement)3 PsiFile (com.intellij.psi.PsiFile)3 LogMessageEx (com.intellij.diagnostic.LogMessageEx)2 JSQualifiedNamedElement (com.intellij.lang.javascript.psi.ecmal4.JSQualifiedNamedElement)2 Pair (com.intellij.openapi.util.Pair)2 PsiDocumentManager (com.intellij.psi.PsiDocumentManager)2 List (java.util.List)2 NonNls (org.jetbrains.annotations.NonNls)2 HighlightDisplayLevel (com.intellij.codeHighlighting.HighlightDisplayLevel)1 TextEditorHighlightingPass (com.intellij.codeHighlighting.TextEditorHighlightingPass)1 DaemonCodeAnalyzer (com.intellij.codeInsight.daemon.DaemonCodeAnalyzer)1