diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightNamesUtil.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightNamesUtil.java index 0f0c0932f84b..7eaa8c8889ae 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightNamesUtil.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightNamesUtil.java @@ -47,7 +47,7 @@ public class HighlightNamesUtil { public static HighlightInfo highlightMethodName(final PsiMethod method, final PsiElement elementToHighlight, final boolean isDeclaration, - final EditorColorsScheme colorsScheme) { + @NotNull EditorColorsScheme colorsScheme) { HighlightInfoType type = getMethodNameHighlightType(method, isDeclaration); if (type != null && elementToHighlight != null) { TextAttributes attributes = mergeWithScopeAttributes(method, type, colorsScheme); @@ -59,7 +59,7 @@ public class HighlightNamesUtil { private static TextAttributes mergeWithScopeAttributes(final PsiElement element, final HighlightInfoType type, - final EditorColorsScheme colorsScheme) { + @NotNull EditorColorsScheme colorsScheme) { TextAttributes regularAttributes = HighlightInfo.getAttributesByType(element, type, colorsScheme); if (element == null) return regularAttributes; TextAttributes scopeAttributes = getScopeAttributes(element, colorsScheme); @@ -67,7 +67,7 @@ public class HighlightNamesUtil { } @Nullable - public static HighlightInfo highlightClassName(PsiClass aClass, PsiElement elementToHighlight, final EditorColorsScheme colorsScheme) { + public static HighlightInfo highlightClassName(PsiClass aClass, PsiElement elementToHighlight, @NotNull EditorColorsScheme colorsScheme) { HighlightInfoType type = getClassNameHighlightType(aClass, elementToHighlight); if (elementToHighlight != null) { TextAttributes attributes = mergeWithScopeAttributes(aClass, type, colorsScheme); @@ -98,7 +98,7 @@ public class HighlightNamesUtil { @Nullable public static HighlightInfo highlightVariableName(final PsiVariable variable, final PsiElement elementToHighlight, - final EditorColorsScheme colorsScheme) { + @NotNull EditorColorsScheme colorsScheme) { HighlightInfoType varType = getVariableNameHighlightType(variable); if (varType != null) { if (variable instanceof PsiField) { @@ -112,7 +112,7 @@ public class HighlightNamesUtil { @Nullable public static HighlightInfo highlightClassNameInQualifier(final PsiJavaCodeReferenceElement element, - final EditorColorsScheme colorsScheme) { + @NotNull EditorColorsScheme colorsScheme) { PsiExpression qualifierExpression = null; if (element instanceof PsiReferenceExpression) { qualifierExpression = ((PsiReferenceExpression)element).getQualifierExpression(); diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/DefaultHighlightVisitor.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/DefaultHighlightVisitor.java index fdb1b94119a6..3d527a50f1ea 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/DefaultHighlightVisitor.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/DefaultHighlightVisitor.java @@ -57,6 +57,7 @@ public class DefaultHighlightVisitor implements HighlightVisitor, DumbAware { private final DumbService myDumbService; private HighlightInfoHolder myHolder; + @SuppressWarnings("UnusedDeclaration") public DefaultHighlightVisitor(@NotNull Project project) { this(project, true, true); } @@ -166,10 +167,11 @@ public class DefaultHighlightVisitor implements HighlightVisitor, DumbAware { myHolder.add(info); } - private static HighlightInfo createErrorElementInfo(final PsiErrorElement element) { + private static HighlightInfo createErrorElementInfo(@NotNull PsiErrorElement element) { TextRange range = element.getTextRange(); + String errorDescription = element.getErrorDescription(); if (!range.isEmpty()) { - final HighlightInfo highlightInfo = HighlightInfo.createHighlightInfo(HighlightInfoType.ERROR, range, element.getErrorDescription()); + final HighlightInfo highlightInfo = HighlightInfo.createHighlightInfo(HighlightInfoType.ERROR, range, errorDescription); for(ErrorQuickFixProvider provider: Extensions.getExtensions(ErrorQuickFixProvider.EP_NAME)) { provider.registerErrorQuickFix(element, highlightInfo); } @@ -183,7 +185,7 @@ public class DefaultHighlightVisitor implements HighlightVisitor, DumbAware { String text = elementAtOffset == null ? null : elementAtOffset.getText(); HighlightInfo info; if (offset < fileLength && text != null && !StringUtil.startsWithChar(text, '\n') && !StringUtil.startsWithChar(text, '\r')) { - info = HighlightInfo.createHighlightInfo(HighlightInfoType.ERROR, offset, offset + 1, element.getErrorDescription()); + info = HighlightInfo.createHighlightInfo(HighlightInfoType.ERROR, offset, offset + 1, errorDescription); } else { int start; @@ -196,7 +198,7 @@ public class DefaultHighlightVisitor implements HighlightVisitor, DumbAware { start = offset; end = offset < fileLength ? offset + 1 : offset; } - info = HighlightInfo.createHighlightInfo(HighlightInfoType.ERROR, element, start, end, element.getErrorDescription(),element.getErrorDescription(), true, null); + info = HighlightInfo.createHighlightInfo(HighlightInfoType.ERROR, element, start, end, errorDescription, errorDescription, true, null); } return info; } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/GeneralHighlightingPass.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/GeneralHighlightingPass.java index 9c8af680b995..5b449a89a6b5 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/GeneralHighlightingPass.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/GeneralHighlightingPass.java @@ -185,10 +185,10 @@ public class GeneralHighlightingPass extends ProgressableTextEditorHighlightingP DaemonCodeAnalyzer daemonCodeAnalyzer = DaemonCodeAnalyzer.getInstance(myProject); HighlightVisitor[] highlightVisitors = getHighlightVisitors(); - final HighlightVisitor[] filteredVisitors = filterVisitors(highlightVisitors, myFile); final List inside = new ArrayList(); final List outside = new ArrayList(); try { + final HighlightVisitor[] filteredVisitors = filterVisitors(highlightVisitors, myFile); Divider.divideInsideAndOutside(myFile, myStartOffset, myEndOffset, myPriorityRange, inside, outside, HighlightLevelUtil.AnalysisLevel.HIGHLIGHT,false); @@ -570,6 +570,26 @@ public class GeneralHighlightingPass extends ProgressableTextEditorHighlightingP final int chunkSize = Math.max(1, (elements1.size()+elements2.size()) / 100); // one percent precision is enough + final Map ranges2markersCache = new THashMap(); + final TransferToEDTQueue myTransferToEDTQueue + = new TransferToEDTQueue("Apply highlighting results", new Processor() { + @Override + public boolean process(HighlightInfo info) { + ApplicationManager.getApplication().assertIsDispatchThread(); + final EditorColorsScheme colorsScheme = getColorsScheme(); + UpdateHighlightersUtil.addHighlighterToEditorIncrementally(myProject, myDocument, myFile, myStartOffset, myEndOffset, + info, colorsScheme, Pass.UPDATE_ALL, ranges2markersCache); + + return true; + } + }, new Condition() { + @Override + public boolean value(Object o) { + return myProject.isDisposed() || progress.isCanceled(); + } + }, 200); + + final Runnable action = new Runnable() { @Override public void run() { @@ -630,7 +650,7 @@ public class GeneralHighlightingPass extends ProgressableTextEditorHighlightingP } myErrorFound = true; } - myTransferToEDTQueue.offer(Pair.create(info, progress)); + myTransferToEDTQueue.offer(info); } } advanceProgress(elements.size() - (nextLimit-chunkSize)); @@ -642,130 +662,6 @@ public class GeneralHighlightingPass extends ProgressableTextEditorHighlightingP analyzeByVisitors(progress, visitors, holder, 0, action); } - //private void collectHighlights(@NotNull final List elements1, - // @NotNull final Runnable after1, - // @NotNull final List elements2, - // @NotNull final ProgressIndicator progress, - // @NotNull final HighlightVisitor[] visitors, - // @NotNull final Set gotHighlights, - // final boolean forceHighlightParents) { - // final HighlightInfoHolder holder = createInfoHolder(myFile); - // - // final int chunkSize = Math.max(1, (elements1.size()+elements2.size()) / 100); // one percent precision is enough - // - // final Runnable action = new Runnable() { - // public void run() { - // //noinspection unchecked - // boolean failed = false; - // PsiNodeTask task = createPsiTask(myFile); - // JobSchedulerImpl.submitTask(task); - // - // for (List elements : new List[]{elements1, elements2}) { - // int nextLimit = chunkSize; - // for (int i = 0; i < elements.size(); i++) { - // PsiElement element = elements.get(i); - // progress.checkCanceled(); - // - // if (element != myFile && !skipParentsSet.isEmpty() && element.getFirstChild() != null && skipParentsSet.contains(element)) { - // skipParentsSet.add(element.getParent()); - // continue; - // } - // - // if (element instanceof PsiErrorElement) { - // myHasErrorElement = true; - // } - // kjlhkjh - // if (i == nextLimit) { - // advanceProgress(chunkSize); - // nextLimit = i + chunkSize; - // } - // - // } - // advanceProgress(elements.size() - (nextLimit-chunkSize)); - // if (elements == elements1) after1.run(); - // } - // } - // - // private PsiNodeTask createPsiTask(@NotNull PsiElement root) { - // return new PsiNodeTask(root) { - // @Override - // public void onEnter(@NotNull PsiElement element) { - // if (element instanceof PsiErrorElement) { - // myHasErrorElement = true; - // } - // super.onEnter(element); - // } - // - // @Override - // protected PsiNodeTask forkNode(@NotNull PsiElement child) { - // return createPsiTask(child); - // } - // - // @Override - // protected boolean highlight(PsiElement element) { - // holder.clear(); - // - // for (final HighlightVisitor visitor : visitors) { - // try { - // visitor.visit(element); - // } - // catch (ProcessCanceledException e) { - // throw e; - // } - // catch (IndexNotReadyException e) { - // throw e; - // } - // catch (WolfTheProblemSolverImpl.HaveGotErrorException e) { - // throw e; - // } - // catch (Exception e) { - // LOG.error(e); - // } - // } - // - // //noinspection ForLoopReplaceableByForEach - // for (int j = 0; j < holder.size(); j++) { - // final HighlightInfo info = holder.get(j); - // assert info != null; - // // have to filter out already obtained highlights - // if (!gotHighlights.add(info)) continue; - // boolean isError = info.getSeverity() == HighlightSeverity.ERROR; - // if (isError) { - // if (!forceHighlightParents) { - // skipParentsSet.add(element.getParent()); - // } - // myErrorFound = true; - // } - // myTransferToEDTQueue.offer(Pair.create(info, progress)); - // } - // return true; - // } - // }; - // } - // }; - // - // analyzeByVisitors(progress, visitors, holder, 0, action); - //} - - private final Map ranges2markersCache = new THashMap(); - private final TransferToEDTQueue> myTransferToEDTQueue - = new TransferToEDTQueue>("Apply highlighting results", new Processor>() { - @Override - public boolean process(Pair pair) { - ApplicationManager.getApplication().assertIsDispatchThread(); - ProgressIndicator indicator = pair.getSecond(); - if (indicator.isCanceled()) { - return false; - } - HighlightInfo info = pair.getFirst(); - final EditorColorsScheme colorsScheme = getColorsScheme(); - UpdateHighlightersUtil.addHighlighterToEditorIncrementally(myProject, myDocument, myFile, myStartOffset, myEndOffset, - info, colorsScheme, Pass.UPDATE_ALL, ranges2markersCache); - - return true; - } - }, myProject.getDisposed(), 200); - private void analyzeByVisitors(@NotNull final ProgressIndicator progress, @NotNull final HighlightVisitor[] visitors, @NotNull final HighlightInfoHolder holder, @@ -785,7 +681,8 @@ public class GeneralHighlightingPass extends ProgressableTextEditorHighlightingP } } - private static HighlightVisitor[] filterVisitors(HighlightVisitor[] highlightVisitors, final PsiFile file) { + @NotNull + private static HighlightVisitor[] filterVisitors(@NotNull HighlightVisitor[] highlightVisitors, @NotNull PsiFile file) { final List visitors = new ArrayList(highlightVisitors.length); List list = Arrays.asList(highlightVisitors); for (HighlightVisitor visitor : DumbService.getInstance(file.getProject()).filterByDumbAwareness(list)) { @@ -798,7 +695,7 @@ public class GeneralHighlightingPass extends ProgressableTextEditorHighlightingP return visitorArray; } - static Void cancelAndRestartDaemonLater(ProgressIndicator progress, final Project project, TextEditorHighlightingPass pass) { + static void cancelAndRestartDaemonLater(ProgressIndicator progress, final Project project, TextEditorHighlightingPass pass) { PassExecutorService.log(progress, pass, "Cancel and restart"); progress.cancel(); ApplicationManager.getApplication().invokeLater(new Runnable() { @@ -885,8 +782,8 @@ public class GeneralHighlightingPass extends ProgressableTextEditorHighlightingP return myUpdateAll ? super.getProgress() : -1; } - private static List convertToProblems(final Collection infos, - final VirtualFile file, + private static List convertToProblems(@NotNull Collection infos, + @NotNull VirtualFile file, final boolean hasErrorElement) { List problems = new SmartList(); for (HighlightInfo info : infos) { diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/HighlightInfo.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/HighlightInfo.java index 30915b710bd7..4f0cc0719f27 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/HighlightInfo.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/HighlightInfo.java @@ -20,7 +20,10 @@ import com.intellij.codeInsight.daemon.HighlightDisplayKey; import com.intellij.codeInsight.daemon.impl.quickfix.QuickFixAction; import com.intellij.codeInsight.intention.IntentionAction; import com.intellij.codeInsight.intention.IntentionManager; -import com.intellij.codeInspection.*; +import com.intellij.codeInspection.CustomSuppressableInspectionTool; +import com.intellij.codeInspection.InspectionProfile; +import com.intellij.codeInspection.InspectionProfileEntry; +import com.intellij.codeInspection.ProblemHighlightType; import com.intellij.codeInspection.actions.CleanupInspectionIntention; import com.intellij.codeInspection.ex.GlobalInspectionToolWrapper; import com.intellij.codeInspection.ex.LocalInspectionToolWrapper; @@ -46,7 +49,6 @@ import com.intellij.openapi.util.TextRange; import com.intellij.profile.codeInspection.InspectionProjectProfileManager; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; -import com.intellij.psi.impl.source.SourceTreeToPsiMap; import com.intellij.util.ArrayUtil; import com.intellij.util.containers.ContainerUtil; import com.intellij.xml.util.XmlStringUtil; @@ -67,13 +69,41 @@ public class HighlightInfo implements Segment { public final TextAttributes forcedTextAttributes; public final TextAttributesKey forcedTextAttributesKey; + public final HighlightInfoType type; + public int group; + public final int startOffset; + public final int endOffset; + + public int fixStartOffset; + public int fixEndOffset; + public RangeMarker fixMarker; // null means it the same as highlighter + + public final String description; + public final String toolTip; + public final HighlightSeverity severity; + + public final boolean isAfterEndOfLine; + public final boolean isFileLevelAnnotation; + public int navigationShift = 0; + + public RangeHighlighterEx highlighter; + public String text; + + public List> quickFixActionRanges; + public List> quickFixActionMarkers; + private boolean hasHint; + public boolean fromInjection; + + private GutterIconRenderer gutterIconRenderer; + private String myProblemGroup; + public boolean bijective; + public HighlightSeverity getSeverity() { return severity; } @Nullable - public TextAttributes getTextAttributes(@Nullable final PsiElement element, - @Nullable final EditorColorsScheme editorColorsScheme) { + public TextAttributes getTextAttributes(@Nullable final PsiElement element, @Nullable final EditorColorsScheme editorColorsScheme) { if (forcedTextAttributes != null) { return forcedTextAttributes; } @@ -92,7 +122,7 @@ public class HighlightInfo implements Segment { public static TextAttributes getAttributesByType(@Nullable final PsiElement element, @NotNull HighlightInfoType type, - final EditorColorsScheme colorsScheme) { + @NotNull EditorColorsScheme colorsScheme) { final SeverityRegistrar severityRegistrar = SeverityRegistrar.getInstance(element != null ? element.getProject() : null); final TextAttributes textAttributes = severityRegistrar.getTextAttributesBySeverity(type.getSeverity(element)); if (textAttributes != null) { @@ -103,7 +133,7 @@ public class HighlightInfo implements Segment { } @Nullable - public Color getErrorStripeMarkColor(final PsiElement element, + public Color getErrorStripeMarkColor(@NotNull PsiElement element, @Nullable final EditorColorsScheme colorsScheme) { // if null global scheme will be used if (forcedTextAttributes != null && forcedTextAttributes.getErrorStripeColor() != null) { return forcedTextAttributes.getErrorStripeColor(); @@ -174,7 +204,8 @@ public class HighlightInfo implements Segment { boolean isEndOfLine, TextAttributes forcedAttributes) { LOG.assertTrue(element != null || ArrayUtil.find(HighlightSeverity.DEFAULT_SEVERITIES, type.getSeverity(element)) != -1, "Custom type demands element to detect its text attributes"); - HighlightInfo highlightInfo = new HighlightInfo(forcedAttributes, type, start, end, description, toolTip, type.getSeverity(element), isEndOfLine, null, false); + HighlightInfo highlightInfo = new HighlightInfo(forcedAttributes, null, type, start, end, description, toolTip, + type.getSeverity(element), isEndOfLine, null, false); PsiFile file = element == null ? null : element.getContainingFile(); for (HighlightInfoFilter filter : getFilters()) { if (!filter.accept(highlightInfo, file)) { @@ -201,57 +232,19 @@ public class HighlightInfo implements Segment { public static HighlightInfo createHighlightInfo(@NotNull HighlightInfoType type, @NotNull TextRange textRange, String description, String toolTip, TextAttributes textAttributes) { // do not use HighlightInfoFilter - return new HighlightInfo(textAttributes, type, textRange.getStartOffset(), textRange.getEndOffset(), description, htmlEscapeToolTip(toolTip),type.getSeverity(null), false, null, - false); + return new HighlightInfo(textAttributes, null, type, textRange.getStartOffset(), textRange.getEndOffset(), description, + htmlEscapeToolTip(toolTip), type.getSeverity(null), false, null, false); } public boolean needUpdateOnTyping() { return myNeedsUpdateOnTyping; } - public final HighlightInfoType type; - public int group; - public final int startOffset; - public final int endOffset; - - public int fixStartOffset; - public int fixEndOffset; - public RangeMarker fixMarker; - - public final String description; - public final String toolTip; - public final HighlightSeverity severity; - - public final boolean isAfterEndOfLine; - public final boolean isFileLevelAnnotation; - public int navigationShift = 0; - - public RangeHighlighterEx highlighter; - public String text; - - public List> quickFixActionRanges; - public List> quickFixActionMarkers; - private boolean hasHint; - public boolean fromInjection; - - private GutterIconRenderer gutterIconRenderer; - private String myProblemGroup; - - public HighlightInfo(HighlightInfoType type, int startOffset, int endOffset, String description, String toolTip) { - this(null, type, startOffset, endOffset, description, toolTip, type.getSeverity(null), false, null, false); + public HighlightInfo(@NotNull HighlightInfoType type, int startOffset, int endOffset, String description, String toolTip) { + this(null, null, type, startOffset, endOffset, description, toolTip, type.getSeverity(null), false, null, false); } - public HighlightInfo(@Nullable TextAttributes forcedTextAttributes, - @NotNull HighlightInfoType type, - int startOffset, - int endOffset, - @Nullable String description, - @Nullable String toolTip, - @NotNull HighlightSeverity severity, - boolean afterEndOfLine, - @Nullable Boolean needsUpdateOnTyping, boolean isFileLevelAnnotation) { - this(forcedTextAttributes, null, type, startOffset, endOffset, description, toolTip, severity, afterEndOfLine, needsUpdateOnTyping, isFileLevelAnnotation); - } + //primary public HighlightInfo(@Nullable TextAttributes forcedTextAttributes, @Nullable TextAttributesKey forcedTextAttributesKey, @NotNull HighlightInfoType type, @@ -261,7 +254,8 @@ public class HighlightInfo implements Segment { @Nullable String toolTip, @NotNull HighlightSeverity severity, boolean afterEndOfLine, - @Nullable Boolean needsUpdateOnTyping, boolean isFileLevelAnnotation) { + @Nullable Boolean needsUpdateOnTyping, + boolean isFileLevelAnnotation) { if (startOffset < 0 || startOffset > endOffset) { LOG.error("Incorrect highlightInfo bounds. description="+description+"; startOffset="+startOffset+"; endOffset="+endOffset+";type="+type); } @@ -353,7 +347,7 @@ public class HighlightInfo implements Segment { } public static HighlightInfo createHighlightInfo(@NotNull HighlightInfoType type, @NotNull ASTNode childByRole, String localizedMessage) { - return createHighlightInfo(type, SourceTreeToPsiMap.treeElementToPsi(childByRole), localizedMessage); + return createHighlightInfo(type, childByRole.getPsi(), localizedMessage); } public GutterIconRenderer getGutterIconRenderer() { @@ -379,8 +373,8 @@ public class HighlightInfo implements Segment { final TextAttributes attributes) { TextRange textRange = element.getTextRange(); // do not use HighlightInfoFilter - return new HighlightInfo(attributes, type, textRange.getStartOffset(), textRange.getEndOffset(), message, htmlEscapeToolTip(message), - type.getSeverity(element), false, Boolean.FALSE, false); + return new HighlightInfo(attributes, null, type, textRange.getStartOffset(), textRange.getEndOffset(), message, + htmlEscapeToolTip(message), type.getSeverity(element), false, Boolean.FALSE, false); } @@ -548,7 +542,7 @@ public class HighlightInfo implements Segment { @NonNls public String toString() { String text = getAction().getText(); - return "descriptor: " + (text.length()==0 ? getAction().getClass() : text); + return "descriptor: " + (text.isEmpty() ? getAction().getClass() : text); } public Icon getIcon() { diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/LocalInspectionsPass.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/LocalInspectionsPass.java index ed110d1bd749..52fb9139dc94 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/LocalInspectionsPass.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/LocalInspectionsPass.java @@ -436,8 +436,7 @@ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass final HighlightSeverity severity = highlightInfoType.getSeverity(psiElement); TextAttributes attributes = mySeverityRegistrar.getTextAttributesBySeverity(severity); - return new HighlightInfo(attributes, highlightInfoType, textRange.getStartOffset(), - textRange.getEndOffset(), message, toolTip, + return new HighlightInfo(attributes, null, highlightInfoType, textRange.getStartOffset(), textRange.getEndOffset(), message, toolTip, severity, problemDescriptor.isAfterEndOfLine(), null, isFileLevel); } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/problems/ProblemImpl.java b/platform/lang-impl/src/com/intellij/codeInsight/problems/ProblemImpl.java index 9d04290132f0..bc877859793d 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/problems/ProblemImpl.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/problems/ProblemImpl.java @@ -20,6 +20,7 @@ import com.intellij.openapi.vfs.VirtualFile; import com.intellij.codeInsight.daemon.impl.HighlightInfo; import com.intellij.problems.Problem; import org.jetbrains.annotations.NonNls; +import org.jetbrains.annotations.NotNull; /** * @author cdr @@ -29,12 +30,13 @@ public class ProblemImpl implements Problem { private final HighlightInfo highlightInfo; private final boolean isSyntax; - public ProblemImpl(final VirtualFile virtualFile, final HighlightInfo highlightInfo, final boolean isSyntax) { + public ProblemImpl(@NotNull VirtualFile virtualFile, @NotNull HighlightInfo highlightInfo, final boolean isSyntax) { this.isSyntax = isSyntax; this.virtualFile = virtualFile; this.highlightInfo = highlightInfo; } + @Override public VirtualFile getVirtualFile() { return virtualFile; } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/problems/WolfTheProblemSolverImpl.java b/platform/lang-impl/src/com/intellij/codeInsight/problems/WolfTheProblemSolverImpl.java index a61cc16648c6..db77ad23abb5 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/problems/WolfTheProblemSolverImpl.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/problems/WolfTheProblemSolverImpl.java @@ -66,18 +66,21 @@ public class WolfTheProblemSolverImpl extends WolfTheProblemSolver { private final List> myFilters = ContainerUtil.createEmptyCOWList(); private boolean myFiltersLoaded = false; private final ProblemListener fireProblemListeners = new ProblemListener() { + @Override public void problemsAppeared(VirtualFile file) { for (final ProblemListener problemListener : myProblemListeners) { problemListener.problemsAppeared(file); } } + @Override public void problemsChanged(VirtualFile file) { for (final ProblemListener problemListener : myProblemListeners) { problemListener.problemsChanged(file); } } + @Override public void problemsDisappeared(VirtualFile file) { for (final ProblemListener problemListener : myProblemListeners) { problemListener.problemsDisappeared(file); @@ -122,36 +125,44 @@ public class WolfTheProblemSolverImpl extends WolfTheProblemSolver { public WolfTheProblemSolverImpl(Project project, PsiManager psiManager, VirtualFileManager virtualFileManager) { myProject = project; PsiTreeChangeListener changeListener = new PsiTreeChangeAdapter() { + @Override public void childAdded(@NotNull PsiTreeChangeEvent event) { childrenChanged(event); } + @Override public void childRemoved(@NotNull PsiTreeChangeEvent event) { childrenChanged(event); } + @Override public void childReplaced(@NotNull PsiTreeChangeEvent event) { childrenChanged(event); } + @Override public void childMoved(@NotNull PsiTreeChangeEvent event) { childrenChanged(event); } + @Override public void propertyChanged(@NotNull PsiTreeChangeEvent event) { childrenChanged(event); } + @Override public void childrenChanged(@NotNull PsiTreeChangeEvent event) { clearSyntaxErrorFlag(event); } }; psiManager.addPsiTreeChangeListener(changeListener); VirtualFileListener virtualFileListener = new VirtualFileAdapter() { + @Override public void fileDeleted(final VirtualFileEvent event) { onDeleted(event.getFile()); } + @Override public void fileMoved(final VirtualFileMoveEvent event) { onDeleted(event.getFile()); } @@ -169,10 +180,12 @@ public class WolfTheProblemSolverImpl extends WolfTheProblemSolver { FileStatusManager fileStatusManager = FileStatusManager.getInstance(myProject); if (fileStatusManager != null) { //tests? fileStatusManager.addFileStatusListener(new FileStatusListener() { + @Override public void fileStatusesChanged() { clearInvalidFiles(); } + @Override public void fileStatusChanged(@NotNull VirtualFile virtualFile) { fileStatusesChanged(); } @@ -204,22 +217,27 @@ public class WolfTheProblemSolverImpl extends WolfTheProblemSolver { } } + @Override public void projectOpened() { } + @Override public void projectClosed() { } + @Override @NotNull @NonNls public String getComponentName() { return "Problems"; } + @Override public void initComponent() { } + @Override public void disposeComponent() { } @@ -257,14 +275,16 @@ public class WolfTheProblemSolverImpl extends WolfTheProblemSolver { private final HighlightInfo myHighlightInfo; private final boolean myHasErrorElement; - private HaveGotErrorException(HighlightInfo info, final boolean hasErrorElement) { + private HaveGotErrorException(@NotNull HighlightInfo info, final boolean hasErrorElement) { myHighlightInfo = info; myHasErrorElement = hasErrorElement; } } // returns true if car has been cleaned - private boolean orderVincentToCleanTheCar(final VirtualFile file, final ProgressIndicator progressIndicator, final StatusBar statusBar) throws ProcessCanceledException { + private boolean orderVincentToCleanTheCar(@NotNull final VirtualFile file, + @NotNull final ProgressIndicator progressIndicator, + @NotNull final StatusBar statusBar) throws ProcessCanceledException { if (!isToBeHighlighted(file)) { clearProblems(file); return true; // file is going to be red waved no more @@ -282,8 +302,10 @@ public class WolfTheProblemSolverImpl extends WolfTheProblemSolver { try { GeneralHighlightingPass pass = new GeneralHighlightingPass(myProject, psiFile, document, 0, document.getTextLength(), false) { + @Override protected HighlightInfoHolder createInfoHolder(final PsiFile file) { return new HighlightInfoHolder(file, HighlightInfoFilter.EMPTY_ARRAY) { + @Override public boolean add(HighlightInfo info) { if (info != null && info.getSeverity() == HighlightSeverity.ERROR) { throw new HaveGotErrorException(info, myHasErrorElement); @@ -294,6 +316,7 @@ public class WolfTheProblemSolverImpl extends WolfTheProblemSolver { } }; ApplicationManager.getApplication().invokeLater(new Runnable() { + @Override public void run() { if (progressIndicator.isCanceled()) return; statusBar.setInfo("Checking '" + file.getPresentableUrl() + "'"); @@ -323,6 +346,7 @@ public class WolfTheProblemSolverImpl extends WolfTheProblemSolver { private static void restoreStatusBarInfo(final StatusBar statusBar, final Pair oldInfo) { if (statusBar instanceof StatusBarEx) { LaterInvocator.invokeLater(new Runnable() { + @Override public void run() { statusBar.setInfo(oldInfo.first, oldInfo.second); } @@ -330,6 +354,7 @@ public class WolfTheProblemSolverImpl extends WolfTheProblemSolver { } } + @Override public boolean hasSyntaxErrors(final VirtualFile file) { synchronized (myProblems) { ProblemFileInfo info = myProblems.get(file); @@ -350,6 +375,7 @@ public class WolfTheProblemSolverImpl extends WolfTheProblemSolver { return false; } + @Override public boolean hasProblemFilesBeneath(Condition condition) { if (!myProject.isOpen()) return false; synchronized (myProblems) { @@ -363,34 +389,42 @@ public class WolfTheProblemSolverImpl extends WolfTheProblemSolver { } } + @Override public boolean hasProblemFilesBeneath(final Module scope) { return hasProblemFilesBeneath(new Condition() { + @Override public boolean value(final VirtualFile virtualFile) { return ModuleUtil.moduleContainsFile(scope, virtualFile, false); } }); } + @Override public void addProblemListener(ProblemListener listener) { myProblemListeners.add(listener); } + @Override public void addProblemListener(final ProblemListener listener, Disposable parentDisposable) { addProblemListener(listener); Disposer.register(parentDisposable, new Disposable() { + @Override public void dispose() { removeProblemListener(listener); } }); } + @Override public void removeProblemListener(ProblemListener listener) { myProblemListeners.remove(listener); } + @Override public void registerFileHighlightFilter(final Condition filter, Disposable parentDisposable) { myFilters.add(filter); Disposer.register(parentDisposable, new Disposable() { + @Override public void dispose() { myFilters.remove(filter); } @@ -405,6 +439,7 @@ public class WolfTheProblemSolverImpl extends WolfTheProblemSolver { } } + @Override public boolean isProblemFile(VirtualFile virtualFile) { synchronized (myProblems) { return myProblems.containsKey(virtualFile); @@ -430,6 +465,7 @@ public class WolfTheProblemSolverImpl extends WolfTheProblemSolver { return false; } + @Override public void weHaveGotProblems(@NotNull final VirtualFile virtualFile, @NotNull List problems) { if (problems.isEmpty()) return; if (!isToBeHighlighted(virtualFile)) return; @@ -452,14 +488,17 @@ public class WolfTheProblemSolverImpl extends WolfTheProblemSolver { } } + @Override public void clearProblems(@NotNull VirtualFile virtualFile) { doRemove(virtualFile); } + @Override public Problem convertToProblem(final VirtualFile virtualFile, final HighlightSeverity severity, final TextRange textRange, final String messageText) { if (virtualFile == null || textRange.getStartOffset() < 0 || textRange.getLength() < 0 ) return null; HighlightInfo info = ApplicationManager.getApplication().runReadAction(new Computable() { + @Override public HighlightInfo compute() { return HighlightInfo.createHighlightInfo(HighlightInfo.convertSeverity(severity), textRange, messageText); } @@ -467,9 +506,11 @@ public class WolfTheProblemSolverImpl extends WolfTheProblemSolver { return new ProblemImpl(virtualFile, info, false); } + @Override public Problem convertToProblem(final VirtualFile virtualFile, final int line, final int column, final String[] message) { if (virtualFile == null || virtualFile.isDirectory() || virtualFile.getFileType().isBinary()) return null; HighlightInfo info = ApplicationManager.getApplication().runReadAction(new Computable() { + @Override public HighlightInfo compute() { TextRange textRange = getTextRange(virtualFile, line, column); return HighlightInfo.createHighlightInfo(HighlightInfoType.ERROR, textRange, StringUtil.join(message, "\n")); @@ -479,6 +520,7 @@ public class WolfTheProblemSolverImpl extends WolfTheProblemSolver { return new ProblemImpl(virtualFile, info, false); } + @Override public void reportProblems(final VirtualFile file, Collection problems) { if (problems.isEmpty()) { clearProblems(file); diff --git a/platform/lang-impl/src/com/intellij/refactoring/changeSignature/ChangeSignaturePassFactory.java b/platform/lang-impl/src/com/intellij/refactoring/changeSignature/ChangeSignaturePassFactory.java index c599b8b6e752..069fa045c2bc 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/changeSignature/ChangeSignaturePassFactory.java +++ b/platform/lang-impl/src/com/intellij/refactoring/changeSignature/ChangeSignaturePassFactory.java @@ -96,11 +96,10 @@ public class ChangeSignaturePassFactory extends AbstractProjectComponent impleme HighlightInfo info = null; if (myRange != null) { info = new HighlightInfo(new TextAttributes(null, null, - myEditor.getColorsScheme().getAttributes(CodeInsightColors.WEAK_WARNING_ATTRIBUTES).getEffectColor(), - null, Font.PLAIN), - HighlightInfoType.INFORMATION, myRange.getStartOffset(), myRange.getEndOffset(), - SIGNATURE_SHOULD_BE_POSSIBLY_CHANGED, SIGNATURE_SHOULD_BE_POSSIBLY_CHANGED, - HighlightSeverity.INFORMATION, false, true, false); + myEditor.getColorsScheme().getAttributes(CodeInsightColors.WEAK_WARNING_ATTRIBUTES).getEffectColor(), + null, Font.PLAIN), null, HighlightInfoType.INFORMATION, + myRange.getStartOffset(), myRange.getEndOffset(), SIGNATURE_SHOULD_BE_POSSIBLY_CHANGED, + SIGNATURE_SHOULD_BE_POSSIBLY_CHANGED, HighlightSeverity.INFORMATION, false, true, false); final ArrayList options = new ArrayList(); options.add(new DismissNewSignatureIntentionAction()); QuickFixAction.registerQuickFixAction(info, new ChangeSignatureDetectorAction(), options, null); diff --git a/xml/impl/src/com/intellij/codeInsight/daemon/impl/tagTreeHighlighting/XmlTagTreeHighlightingPass.java b/xml/impl/src/com/intellij/codeInsight/daemon/impl/tagTreeHighlighting/XmlTagTreeHighlightingPass.java index 082e009a7150..9e3aedfa4525 100644 --- a/xml/impl/src/com/intellij/codeInsight/daemon/impl/tagTreeHighlighting/XmlTagTreeHighlightingPass.java +++ b/xml/impl/src/com/intellij/codeInsight/daemon/impl/tagTreeHighlighting/XmlTagTreeHighlightingPass.java @@ -220,7 +220,7 @@ public class XmlTagTreeHighlightingPass extends TextEditorHighlightingPass { @NotNull private static HighlightInfo createHighlightInfo(Color color, @NotNull TextRange range) { - return new HighlightInfo(new TextAttributes(null, color, null, null, Font.PLAIN), TYPE, range.getStartOffset(), + return new HighlightInfo(new TextAttributes(null, color, null, null, Font.PLAIN), null, TYPE, range.getStartOffset(), range.getEndOffset(), null, null, HighlightSeverity.INFORMATION, false, null, false); }