From 7ea87fc63e8b6825ddb00d17733af9cf6ed8b259 Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Mon, 25 Jul 2016 18:36:45 +0300 Subject: [PATCH] cleanup, lambdify --- .../daemon/impl/GeneralHighlightingPass.java | 2 +- .../daemon/impl/ExternalToolPass.java | 14 +- .../codeInsight/daemon/impl/IndentsPass.java | 239 +++++++++--------- .../daemon/impl/LocalInspectionsPass.java | 57 +++-- .../daemon/impl/PassExecutorService.java | 119 ++++----- 5 files changed, 201 insertions(+), 230 deletions(-) diff --git a/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/GeneralHighlightingPass.java b/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/GeneralHighlightingPass.java index 7fa629d937e2..65dc4dd90921 100644 --- a/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/GeneralHighlightingPass.java +++ b/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/GeneralHighlightingPass.java @@ -76,7 +76,7 @@ public class GeneralHighlightingPass extends ProgressableTextEditorHighlightingP protected volatile boolean myHasErrorElement; private volatile boolean myErrorFound; protected final EditorColorsScheme myGlobalScheme; - private volatile NotNullProducer myHighlightVisitorProducer = () -> cloneHighlightVisitors(); + private volatile NotNullProducer myHighlightVisitorProducer = this::cloneHighlightVisitors; public GeneralHighlightingPass(@NotNull Project project, @NotNull PsiFile file, diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/ExternalToolPass.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/ExternalToolPass.java index 041831ed8ffc..ca7c807f6661 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/ExternalToolPass.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/ExternalToolPass.java @@ -44,7 +44,7 @@ import java.util.*; public class ExternalToolPass extends ProgressableTextEditorHighlightingPass { private final AnnotationHolderImpl myAnnotationHolder; - private final Map myAnnotator2DataMap = new HashMap(); + private final Map myAnnotator2DataMap = new HashMap<>(); private final ExternalToolPassFactory myExternalToolPassFactory; private final boolean myMainHighlightingPass; @@ -60,11 +60,11 @@ public class ExternalToolPass extends ProgressableTextEditorHighlightingPass { } } - public ExternalToolPass(@NotNull ExternalToolPassFactory externalToolPassFactory, - @NotNull PsiFile file, - @NotNull Editor editor, - int startOffset, - int endOffset) { + ExternalToolPass(@NotNull ExternalToolPassFactory externalToolPassFactory, + @NotNull PsiFile file, + @NotNull Editor editor, + int startOffset, + int endOffset) { super(file.getProject(), editor.getDocument(), "External annotators", file, editor, new TextRange(startOffset, endOffset), false, new DefaultHighlightInfoProcessor()); myAnnotationHolder = new AnnotationHolderImpl(new AnnotationSession(file)); myExternalToolPassFactory = externalToolPassFactory; @@ -178,7 +178,7 @@ public class ExternalToolPass extends ProgressableTextEditorHighlightingPass { @NotNull private List getHighlights() { - List infos = new ArrayList(); + List infos = new ArrayList<>(myAnnotationHolder.size()); for (Annotation annotation : myAnnotationHolder) { infos.add(HighlightInfo.fromAnnotation(annotation)); } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/IndentsPass.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/IndentsPass.java index 9ba968b7ce69..7fd35030b13a 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/IndentsPass.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/IndentsPass.java @@ -30,7 +30,6 @@ import com.intellij.openapi.editor.colors.EditorColorsScheme; import com.intellij.openapi.editor.ex.EditorEx; import com.intellij.openapi.editor.ex.util.EditorUtil; import com.intellij.openapi.editor.highlighter.HighlighterIterator; -import com.intellij.openapi.editor.impl.EditorImpl; import com.intellij.openapi.editor.markup.CustomHighlighterRenderer; import com.intellij.openapi.editor.markup.HighlighterTargetArea; import com.intellij.openapi.editor.markup.MarkupModel; @@ -69,134 +68,127 @@ public class IndentsPass extends TextEditorHighlightingPass implements DumbAware return o1.getStartOffset() - o2.getStartOffset(); }; - private static final CustomHighlighterRenderer RENDERER = new CustomHighlighterRenderer() { - @Override - @SuppressWarnings({"AssignmentToForLoopParameter"}) - public void paint(@NotNull Editor editor, - @NotNull RangeHighlighter highlighter, - @NotNull Graphics g) - { - int startOffset = highlighter.getStartOffset(); - final Document doc = highlighter.getDocument(); - if (startOffset >= doc.getTextLength()) return; + private static final CustomHighlighterRenderer RENDERER = (editor, highlighter, g) -> { + int startOffset = highlighter.getStartOffset(); + final Document doc = highlighter.getDocument(); + if (startOffset >= doc.getTextLength()) return; - final int endOffset = highlighter.getEndOffset(); - final int endLine = doc.getLineNumber(endOffset); + final int endOffset = highlighter.getEndOffset(); + final int endLine = doc.getLineNumber(endOffset); - int off; - int startLine = doc.getLineNumber(startOffset); - IndentGuideDescriptor descriptor = editor.getIndentsModel().getDescriptor(startLine, endLine); + int off; + int startLine = doc.getLineNumber(startOffset); + IndentGuideDescriptor descriptor = editor.getIndentsModel().getDescriptor(startLine, endLine); - final CharSequence chars = doc.getCharsSequence(); - do { - int start = doc.getLineStartOffset(startLine); - int end = doc.getLineEndOffset(startLine); - off = CharArrayUtil.shiftForward(chars, start, end, " \t"); - startLine--; + final CharSequence chars = doc.getCharsSequence(); + do { + int start = doc.getLineStartOffset(startLine); + int end = doc.getLineEndOffset(startLine); + off = CharArrayUtil.shiftForward(chars, start, end, " \t"); + startLine--; + } + while (startLine > 1 && off < doc.getTextLength() && chars.charAt(off) == '\n'); + + final VisualPosition startPosition = editor.offsetToVisualPosition(off); + int indentColumn = startPosition.column; + + // It's considered that indent guide can cross not only white space but comments, javadocs etc. Hence, there is a possible + // case that the first indent guide line is, say, single-line comment where comment symbols ('//') are located at the first + // visual column. We need to calculate correct indent guide column then. + int lineShift = 1; + if (indentColumn <= 0 && descriptor != null) { + indentColumn = descriptor.indentLevel; + lineShift = 0; + } + if (indentColumn <= 0) return; + + final FoldingModel foldingModel = editor.getFoldingModel(); + if (foldingModel.isOffsetCollapsed(off)) return; + + final FoldRegion headerRegion = foldingModel.getCollapsedRegionAtOffset(doc.getLineEndOffset(doc.getLineNumber(off))); + final FoldRegion tailRegion = foldingModel.getCollapsedRegionAtOffset(doc.getLineStartOffset(doc.getLineNumber(endOffset))); + + if (tailRegion != null && tailRegion == headerRegion) return; + + final boolean selected; + final IndentGuideDescriptor guide = editor.getIndentsModel().getCaretIndentGuide(); + if (guide != null) { + final CaretModel caretModel = editor.getCaretModel(); + final int caretOffset = caretModel.getOffset(); + selected = + caretOffset >= off && caretOffset < endOffset && caretModel.getLogicalPosition().column == indentColumn; + } + else { + selected = false; + } + + Point start = editor.visualPositionToXY(new VisualPosition(startPosition.line + lineShift, indentColumn)); + final VisualPosition endPosition = editor.offsetToVisualPosition(endOffset); + Point end = editor.visualPositionToXY(new VisualPosition(endPosition.line, endPosition.column)); + int maxY = end.y; + if (endPosition.line == editor.offsetToVisualPosition(doc.getTextLength()).line) { + maxY += editor.getLineHeight(); + } + + Rectangle clip = g.getClipBounds(); + if (clip != null) { + if (clip.y >= maxY || clip.y + clip.height <= start.y) { + return; } - while (startLine > 1 && off < doc.getTextLength() && chars.charAt(off) == '\n'); + maxY = Math.min(maxY, clip.y + clip.height); + } - final VisualPosition startPosition = editor.offsetToVisualPosition(off); - int indentColumn = startPosition.column; + final EditorColorsScheme scheme = editor.getColorsScheme(); + g.setColor(selected ? scheme.getColor(EditorColors.SELECTED_INDENT_GUIDE_COLOR) : scheme.getColor(EditorColors.INDENT_GUIDE_COLOR)); - // It's considered that indent guide can cross not only white space but comments, javadocs etc. Hence, there is a possible - // case that the first indent guide line is, say, single-line comment where comment symbols ('//') are located at the first - // visual column. We need to calculate correct indent guide column then. - int lineShift = 1; - if (indentColumn <= 0 && descriptor != null) { - indentColumn = descriptor.indentLevel; - lineShift = 0; - } - if (indentColumn <= 0) return; - - final FoldingModel foldingModel = editor.getFoldingModel(); - if (foldingModel.isOffsetCollapsed(off)) return; - - final FoldRegion headerRegion = foldingModel.getCollapsedRegionAtOffset(doc.getLineEndOffset(doc.getLineNumber(off))); - final FoldRegion tailRegion = foldingModel.getCollapsedRegionAtOffset(doc.getLineStartOffset(doc.getLineNumber(endOffset))); - - if (tailRegion != null && tailRegion == headerRegion) return; - - final boolean selected; - final IndentGuideDescriptor guide = editor.getIndentsModel().getCaretIndentGuide(); - if (guide != null) { - final CaretModel caretModel = editor.getCaretModel(); - final int caretOffset = caretModel.getOffset(); - selected = - caretOffset >= off && caretOffset < endOffset && caretModel.getLogicalPosition().column == indentColumn; - } - else { - selected = false; - } - - Point start = editor.visualPositionToXY(new VisualPosition(startPosition.line + lineShift, indentColumn)); - final VisualPosition endPosition = editor.offsetToVisualPosition(endOffset); - Point end = editor.visualPositionToXY(new VisualPosition(endPosition.line, endPosition.column)); - int maxY = end.y; - if (endPosition.line == editor.offsetToVisualPosition(doc.getTextLength()).line) { - maxY += editor.getLineHeight(); - } - - Rectangle clip = g.getClipBounds(); - if (clip != null) { - if (clip.y >= maxY || clip.y + clip.height <= start.y) { - return; + // There is a possible case that indent line intersects soft wrap-introduced text. Example: + // this is a long line + // that| is soft-wrapped + // | + // | <- vertical indent + // + // Also it's possible that no additional intersections are added because of soft wrap: + // this is a long line + // | that is soft-wrapped + // | + // | <- vertical indent + // We want to use the following approach then: + // 1. Show only active indent if it crosses soft wrap-introduced text; + // 2. Show indent as is if it doesn't intersect with soft wrap-introduced text; + if (selected) { + g.drawLine(start.x + 2, start.y, start.x + 2, maxY - 1); + } + else { + int y = start.y; + int newY = start.y; + SoftWrapModel softWrapModel = editor.getSoftWrapModel(); + int lineHeight = editor.getLineHeight(); + for (int i = Math.max(0, startLine + lineShift); i < endLine && newY < maxY; i++) { + List softWraps = softWrapModel.getSoftWrapsForLine(i); + int logicalLineHeight = softWraps.size() * lineHeight; + if (i > startLine + lineShift) { + logicalLineHeight += lineHeight; // We assume that initial 'y' value points just below the target line. } - maxY = Math.min(maxY, clip.y + clip.height); - } - - final EditorColorsScheme scheme = editor.getColorsScheme(); - g.setColor(selected ? scheme.getColor(EditorColors.SELECTED_INDENT_GUIDE_COLOR) : scheme.getColor(EditorColors.INDENT_GUIDE_COLOR)); - - // There is a possible case that indent line intersects soft wrap-introduced text. Example: - // this is a long line - // that| is soft-wrapped - // | - // | <- vertical indent - // - // Also it's possible that no additional intersections are added because of soft wrap: - // this is a long line - // | that is soft-wrapped - // | - // | <- vertical indent - // We want to use the following approach then: - // 1. Show only active indent if it crosses soft wrap-introduced text; - // 2. Show indent as is if it doesn't intersect with soft wrap-introduced text; - if (selected) { - g.drawLine(start.x + 2, start.y, start.x + 2, maxY - 1); - } - else { - int y = start.y; - int newY = start.y; - SoftWrapModel softWrapModel = editor.getSoftWrapModel(); - int lineHeight = editor.getLineHeight(); - for (int i = Math.max(0, startLine + lineShift); i < endLine && newY < maxY; i++) { - List softWraps = softWrapModel.getSoftWrapsForLine(i); - int logicalLineHeight = softWraps.size() * lineHeight; - if (i > startLine + lineShift) { - logicalLineHeight += lineHeight; // We assume that initial 'y' value points just below the target line. - } - if (!softWraps.isEmpty() && softWraps.get(0).getIndentInColumns() < indentColumn) { - if (y < newY || i > startLine + lineShift) { // There is a possible case that soft wrap is located on indent start line. - g.drawLine(start.x + 2, y, start.x + 2, newY + lineHeight - 1); - } - newY += logicalLineHeight; - y = newY; - } - else { - newY += logicalLineHeight; - } - - FoldRegion foldRegion = foldingModel.getCollapsedRegionAtOffset(doc.getLineEndOffset(i)); - if (foldRegion != null && foldRegion.getEndOffset() < doc.getTextLength()) { - i = doc.getLineNumber(foldRegion.getEndOffset()); + if (!softWraps.isEmpty() && softWraps.get(0).getIndentInColumns() < indentColumn) { + if (y < newY || i > startLine + lineShift) { // There is a possible case that soft wrap is located on indent start line. + g.drawLine(start.x + 2, y, start.x + 2, newY + lineHeight - 1); } + newY += logicalLineHeight; + y = newY; + } + else { + newY += logicalLineHeight; } - if (y < maxY) { - g.drawLine(start.x + 2, y, start.x + 2, maxY - 1); + FoldRegion foldRegion = foldingModel.getCollapsedRegionAtOffset(doc.getLineEndOffset(i)); + if (foldRegion != null && foldRegion.getEndOffset() < doc.getTextLength()) { + i = doc.getLineNumber(foldRegion.getEndOffset()); } } + + if (y < maxY) { + g.drawLine(start.x + 2, y, start.x + 2, maxY - 1); + } } }; private volatile List myRanges; @@ -216,7 +208,7 @@ public class IndentsPass extends TextEditorHighlightingPass implements DumbAware myDescriptors = buildDescriptors(); - ArrayList ranges = new ArrayList(); + ArrayList ranges = new ArrayList<>(); for (IndentGuideDescriptor descriptor : myDescriptors) { ProgressManager.checkCanceled(); int endOffset = @@ -240,7 +232,7 @@ public class IndentsPass extends TextEditorHighlightingPass implements DumbAware if (stamp != null && stamp.longValue() == nowStamp()) return; List oldHighlighters = myEditor.getUserData(INDENT_HIGHLIGHTERS_IN_EDITOR_KEY); - final List newHighlighters = new ArrayList(); + final List newHighlighters = new ArrayList<>(); final MarkupModel mm = myEditor.getMarkupModel(); int curRange = 0; @@ -294,14 +286,13 @@ public class IndentsPass extends TextEditorHighlightingPass implements DumbAware calculator.calculate(); int[] lineIndents = calculator.lineIndents; - List descriptors = new ArrayList(); - IntStack lines = new IntStack(); IntStack indents = new IntStack(); lines.push(0); indents.push(0); assert myDocument != null; + List descriptors = new ArrayList<>(); for (int line = 1; line < lineIndents.length; line++) { ProgressManager.checkCanceled(); int curIndent = Math.abs(lineIndents[line]); @@ -362,9 +353,9 @@ public class IndentsPass extends TextEditorHighlightingPass implements DumbAware @NotNull public final Map myComments = ContainerUtilRt.newHashMap(); - @NotNull public final int[] lineIndents; // negative value means the line is empty (or contains a comment) and indent + @NotNull final int[] lineIndents; // negative value means the line is empty (or contains a comment) and indent // (denoted by absolute value) was deduced from enclosing non-empty lines - @NotNull public final CharSequence myChars; + @NotNull final CharSequence myChars; IndentsCalculator() { assert myDocument != null; @@ -393,7 +384,7 @@ public class IndentsPass extends TextEditorHighlightingPass implements DumbAware column++; break; case '\t': - column = ((column / tabSize) + 1) * tabSize; + column = (column / tabSize + 1) * tabSize; break; default: break outer; 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 92b6f86e0279..61a068981c78 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 @@ -141,7 +141,7 @@ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass @NotNull final InspectionManager iManager, @NotNull final List toolWrappers) { final ProgressIndicator progress = ProgressManager.getInstance().getProgressIndicator(); - inspect(new ArrayList(toolWrappers), iManager, false, false, progress); + inspect(new ArrayList<>(toolWrappers), iManager, false, false, progress); addDescriptorsFromInjectedResults(iManager, context); List resultList = result.get(getFile()); if (resultList == null) return; @@ -207,9 +207,11 @@ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass myFailFastOnAcquireReadAction = failFastOnAcquireReadAction; if (toolWrappers.isEmpty()) return; - List inside = new ArrayList(); - List outside = new ArrayList(); - Divider.divideInsideAndOutside(getFile(), myRestrictRange.getStartOffset(), myRestrictRange.getEndOffset(), myPriorityRange, inside, new ArrayList(), outside, new ArrayList(), + List inside = new ArrayList<>(); + List outside = new ArrayList<>(); + Divider.divideInsideAndOutside(getFile(), myRestrictRange.getStartOffset(), myRestrictRange.getEndOffset(), myPriorityRange, inside, + new ArrayList<>(), outside, + new ArrayList<>(), true, FILE_FILTER); Set elementDialectIds = InspectionEngine.calcElementDialectIds(inside, outside); @@ -224,7 +226,7 @@ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass progress.checkCanceled(); - myInfos = new ArrayList(); + myInfos = new ArrayList<>(); addHighlightsFromResults(myInfos, progress); } @@ -237,8 +239,8 @@ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass @NotNull final LocalInspectionToolSession session, @NotNull List wrappers, @NotNull final Set elementDialectIds) { - final List init = new ArrayList(); - List>> entries = new ArrayList>>(toolToSpecifiedLanguageIds.entrySet()); + final List init = new ArrayList<>(); + List>> entries = new ArrayList<>(toolToSpecifiedLanguageIds.entrySet()); Processor>> processor = pair -> { @@ -323,21 +325,16 @@ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass @NotNull final InspectionManager iManager, final boolean inVisibleRange, @NotNull final List wrappers) { - final Set injected = new THashSet(); + final Set injected = new THashSet<>(); for (PsiElement element : elements) { - InjectedLanguageUtil.enumerate(element, getFile(), false, new PsiLanguageInjectionHost.InjectedPsiVisitor() { - @Override - public void visit(@NotNull PsiFile injectedPsi, @NotNull List places) { - injected.add(injectedPsi); - } - }); + InjectedLanguageUtil.enumerate(element, getFile(), false, (injectedPsi, places) -> injected.add(injectedPsi)); } if (injected.isEmpty()) return; Processor processor = injectedPsi -> { doInspectInjectedPsi(injectedPsi, onTheFly, indicator, iManager, inVisibleRange, wrappers); return true; }; - if (!JobLauncher.getInstance().invokeConcurrentlyUnderProgress(new ArrayList(injected), indicator, myFailFastOnAcquireReadAction, processor)) { + if (!JobLauncher.getInstance().invokeConcurrentlyUnderProgress(new ArrayList<>(injected), indicator, myFailFastOnAcquireReadAction, processor)) { throw new ProcessCanceledException(); } } @@ -367,15 +364,16 @@ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass return b.create(); } - private final Map ranges2markersCache = new THashMap(); + private final Map ranges2markersCache = new THashMap<>(); private final TransferToEDTQueue> myTransferToEDTQueue - = new TransferToEDTQueue>("Apply inspection results", new Processor>() { + = new TransferToEDTQueue<>("Apply inspection results", new Processor>() { private final InspectionProfile inspectionProfile = InspectionProjectProfileManager.getInstance(myProject).getCurrentProfile(); private final InjectedLanguageManager ilManager = InjectedLanguageManager.getInstance(myProject); - private final List infos = new ArrayList(2); + private final List infos = new ArrayList<>(2); private final PsiDocumentManager documentManager = PsiDocumentManager.getInstance(myProject); + @Override - public boolean process(Trinity trinity) { + public boolean process(Trinity trinity) { ProgressIndicator indicator = trinity.getThird(); if (indicator.isCanceled()) { return false; @@ -394,8 +392,11 @@ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass createHighlightsForDescriptor(infos, emptyActionRegistered, ilManager, file, thisDocument, tool, severity, descriptor, psiElement); for (HighlightInfo info : infos) { final EditorColorsScheme colorsScheme = getColorsScheme(); - UpdateHighlightersUtil.addHighlighterToEditorIncrementally(myProject, myDocument, getFile(), myRestrictRange.getStartOffset(), myRestrictRange.getEndOffset(), - info, colorsScheme, getId(), ranges2markersCache); + UpdateHighlightersUtil.addHighlighterToEditorIncrementally(myProject, myDocument, getFile(), + myRestrictRange.getStartOffset(), + myRestrictRange.getEndOffset(), + info, colorsScheme, getId(), + ranges2markersCache); } return true; @@ -427,7 +428,7 @@ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass private void appendResult(@NotNull PsiFile file, @NotNull InspectionResult result) { List resultList = this.result.get(file); if (resultList == null) { - resultList = ConcurrencyUtil.cacheOrGet(this.result, file, new ArrayList()); + resultList = ConcurrencyUtil.cacheOrGet(this.result, file, new ArrayList<>()); } synchronized (resultList) { resultList.add(result); @@ -443,7 +444,7 @@ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass InspectionProfile inspectionProfile = InspectionProjectProfileManager.getInstance(myProject).getCurrentProfile(); PsiDocumentManager documentManager = PsiDocumentManager.getInstance(myProject); InjectedLanguageManager ilManager = InjectedLanguageManager.getInstance(myProject); - Set> emptyActionRegistered = new THashSet>(); + Set> emptyActionRegistered = new THashSet<>(); for (Map.Entry> entry : result.entrySet()) { indicator.checkCanceled(); @@ -583,7 +584,7 @@ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass if (((ProblemDescriptorBase)descriptor).getEnforcedTextAttributes() != null) { needEmptyAction = false; } - if (needEmptyAction && emptyActionRegistered.add(Pair.create(highlightInfo.getFixTextRange(), tool.getShortName()))) { + if (needEmptyAction && emptyActionRegistered.add(Pair.create(highlightInfo.getFixTextRange(), tool.getShortName()))) { IntentionAction emptyIntentionAction = new EmptyIntentionAction(tool.getDisplayName()); QuickFixAction.registerQuickFixAction(highlightInfo, emptyIntentionAction, key); } @@ -592,7 +593,7 @@ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass @NotNull private static List getElementsFrom(@NotNull PsiFile file) { final FileViewProvider viewProvider = file.getViewProvider(); - final Set result = new LinkedHashSet(); + final Set result = new LinkedHashSet<>(); final PsiElementVisitor visitor = new PsiRecursiveElementVisitor() { @Override public void visitElement(PsiElement element) { ProgressManager.checkCanceled(); @@ -619,15 +620,15 @@ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass psiRoot.accept(visitor); result.add(psiRoot); } - return new ArrayList(result); + return new ArrayList<>(result); } @NotNull List getInspectionTools(@NotNull InspectionProfileWrapper profile) { - List enabled = new ArrayList(); final InspectionToolWrapper[] toolWrappers = profile.getInspectionProfile().getInspectionTools(getFile()); InspectionProfileWrapper.checkInspectionsDuplicates(toolWrappers); + List enabled = new ArrayList<>(); for (InspectionToolWrapper toolWrapper : toolWrappers) { ProgressManager.checkCanceled(); final HighlightDisplayKey key = HighlightDisplayKey.find(toolWrapper.getShortName()); @@ -708,7 +709,7 @@ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass private InspectionResult(@NotNull LocalInspectionToolWrapper tool, @NotNull List foundProblems) { this.tool = tool; - this.foundProblems = new ArrayList(foundProblems); + this.foundProblems = new ArrayList<>(foundProblems); } } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/PassExecutorService.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/PassExecutorService.java index 87c490400fec..7cfd8155452b 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/PassExecutorService.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/PassExecutorService.java @@ -50,7 +50,6 @@ import com.intellij.util.containers.ContainerUtil; import com.intellij.util.containers.MultiMap; import gnu.trove.THashMap; import gnu.trove.TIntObjectHashMap; -import gnu.trove.TIntObjectProcedure; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.TestOnly; @@ -71,7 +70,7 @@ class PassExecutorService implements Disposable { private static final Logger LOG = Logger.getInstance("#com.intellij.codeInsight.daemon.impl.PassExecutorService"); private static final boolean CHECK_CONSISTENCY = ApplicationManager.getApplication().isUnitTestMode(); - private final Map> mySubmittedPasses = new ConcurrentHashMap>(); + private final Map> mySubmittedPasses = new ConcurrentHashMap<>(); private final Project myProject; private volatile boolean isDisposed; private final AtomicInteger nextPassId = new AtomicInteger(100); @@ -99,10 +98,7 @@ class PassExecutorService implements Disposable { catch (ProcessCanceledException ignored) { } - catch (Error e) { - throw e; - } - catch (RuntimeException e) { + catch (Error | RuntimeException e) { throw e; } catch (Throwable throwable) { @@ -119,7 +115,7 @@ class PassExecutorService implements Disposable { MultiMap documentToEditors = MultiMap.createSet(); MultiMap documentBoundPasses = MultiMap.createSmart(); MultiMap editorBoundPasses = MultiMap.createSmart(); - Set vFiles = new HashSet(); + Set vFiles = new HashSet<>(); for (Map.Entry entry : passesMap.entrySet()) { FileEditor fileEditor = entry.getKey(); @@ -157,10 +153,10 @@ class PassExecutorService implements Disposable { } } - List freePasses = new ArrayList(documentToEditors.size()*5); - List dependentPasses = new ArrayList(documentToEditors.size()*10); + List freePasses = new ArrayList<>(documentToEditors.size() * 5); + List dependentPasses = new ArrayList<>(documentToEditors.size() * 10); // (fileEditor, passId) -> created pass - Map, ScheduledPass> toBeSubmitted = new THashMap, ScheduledPass>(passesMap.size()); + Map, ScheduledPass> toBeSubmitted = new THashMap<>(passesMap.size()); final AtomicInteger threadsToStartCountdown = new AtomicInteger(0); for (Map.Entry> entry : documentToEditors.entrySet()) { @@ -181,7 +177,7 @@ class PassExecutorService implements Disposable { FileEditor fileEditor = entry.getKey(); Collection createdEditorBoundPasses = entry.getValue(); List createdDocumentBoundPasses = (List)documentBoundPasses.get(fileEditor); - List allCreatedPasses = new ArrayList(createdDocumentBoundPasses); + List allCreatedPasses = new ArrayList<>(createdDocumentBoundPasses); allCreatedPasses.addAll(createdEditorBoundPasses); for (EditorBoundHighlightingPass pass : createdEditorBoundPasses) { @@ -207,18 +203,15 @@ class PassExecutorService implements Disposable { Map, ScheduledPass> toBeSubmitted, AtomicInteger threadsToStartCountdown) { assert threadsToStartCountdown.get() == toBeSubmitted.size(); - TIntObjectHashMap> id2Visits = new TIntObjectHashMap>(); + TIntObjectHashMap> id2Visits = new TIntObjectHashMap<>(); for (ScheduledPass freePass : freePasses) { id2Visits.put(freePass.myPass.getId(), Pair.create(freePass, 0)); checkConsistency(freePass, id2Visits); } - id2Visits.forEachEntry(new TIntObjectProcedure>() { - @Override - public boolean execute(int id, Pair pair) { - int count = pair.second; - assert count == 0 : id; - return true; - } + id2Visits.forEachEntry((id, pair) -> { + int count = pair.second; + assert count == 0 : id; + return true; }); assert id2Visits.size() == threadsToStartCountdown.get(); } @@ -365,9 +358,7 @@ class PassExecutorService implements Disposable { future.get(); } } - catch (CancellationException ignored) { - } - catch (InterruptedException ignored) { + catch (CancellationException | InterruptedException ignored) { } catch (ExecutionException e) { LOG.error(e.getCause()); @@ -382,8 +373,8 @@ class PassExecutorService implements Disposable { private final TextEditorHighlightingPass myPass; private final AtomicInteger myThreadsToStartCountdown; private final AtomicInteger myRunningPredecessorsCount = new AtomicInteger(0); - private final Collection mySuccessorsOnCompletion = new ArrayList(); - private final Collection mySuccessorsOnSubmit = new ArrayList(); + private final Collection mySuccessorsOnCompletion = new ArrayList<>(); + private final Collection mySuccessorsOnSubmit = new ArrayList<>(); private final DaemonProgressIndicator myUpdateProgress; private ScheduledPass(@NotNull FileEditor fileEditor, @@ -401,11 +392,7 @@ class PassExecutorService implements Disposable { try { doRun(); } - catch (RuntimeException e) { - saveException(e,myUpdateProgress); - throw e; - } - catch (Error e) { + catch (RuntimeException | Error e) { saveException(e,myUpdateProgress); throw e; } @@ -441,12 +428,7 @@ class PassExecutorService implements Disposable { myUpdateProgress.cancel(e); //in case when some smart asses throw PCE just for fun } } - catch (RuntimeException e) { - myUpdateProgress.cancel(e); - LOG.error(e); - throw e; - } - catch (Error e) { + catch (RuntimeException | Error e) { myUpdateProgress.cancel(e); LOG.error(e); throw e; @@ -492,42 +474,39 @@ class PassExecutorService implements Disposable { @NotNull final TextEditorHighlightingPass pass, @NotNull final DaemonProgressIndicator updateProgress, @NotNull final AtomicInteger threadsToStartCountdown) { - ApplicationManager.getApplication().invokeLater(new DumbAwareRunnable() { - @Override - public void run() { - if (isDisposed() || myProject.isDisposed()) { - updateProgress.cancel(); - } - if (updateProgress.isCanceled()) { - log(updateProgress, pass, " is canceled during apply, sorry"); - return; - } - try { - if (fileEditor.getComponent().isDisplayable() || ApplicationManager.getApplication().isUnitTestMode()) { - log(updateProgress, pass, " Applied"); - pass.applyInformationToEditor(); - } - } - catch (ProcessCanceledException e) { - log(updateProgress, pass, "Error " + e); - throw e; - } - catch (RuntimeException e) { - Document document = pass.getDocument(); - VirtualFile file = document == null ? null : FileDocumentManager.getInstance().getFile(document); - FileType fileType = file == null ? null : file.getFileType(); - String message = "Exception while applying information to " + fileEditor + "("+fileType+")"; - log(updateProgress, pass, message + e); - throw new RuntimeException(message, e); - } - if (threadsToStartCountdown.decrementAndGet() == 0) { - log(updateProgress, pass, "Stopping "); - updateProgress.stopIfRunning(); - } - else { - log(updateProgress, pass, "Finished but there are passes in the queue: " + threadsToStartCountdown.get()); + ApplicationManager.getApplication().invokeLater((DumbAwareRunnable)() -> { + if (isDisposed() || myProject.isDisposed()) { + updateProgress.cancel(); + } + if (updateProgress.isCanceled()) { + log(updateProgress, pass, " is canceled during apply, sorry"); + return; + } + try { + if (fileEditor.getComponent().isDisplayable() || ApplicationManager.getApplication().isUnitTestMode()) { + log(updateProgress, pass, " Applied"); + pass.applyInformationToEditor(); } } + catch (ProcessCanceledException e) { + log(updateProgress, pass, "Error " + e); + throw e; + } + catch (RuntimeException e) { + Document document = pass.getDocument(); + VirtualFile file = document == null ? null : FileDocumentManager.getInstance().getFile(document); + FileType fileType = file == null ? null : file.getFileType(); + String message = "Exception while applying information to " + fileEditor + "("+fileType+")"; + log(updateProgress, pass, message + e); + throw new RuntimeException(message, e); + } + if (threadsToStartCountdown.decrementAndGet() == 0) { + log(updateProgress, pass, "Stopping "); + updateProgress.stopIfRunning(); + } + else { + log(updateProgress, pass, "Finished but there are passes in the queue: " + threadsToStartCountdown.get()); + } }, ModalityState.stateForComponent(fileEditor.getComponent())); } @@ -537,7 +516,7 @@ class PassExecutorService implements Disposable { @NotNull List getAllSubmittedPasses() { - List result = new ArrayList(mySubmittedPasses.size()); + List result = new ArrayList<>(mySubmittedPasses.size()); for (ScheduledPass scheduledPass : mySubmittedPasses.keySet()) { if (!scheduledPass.myUpdateProgress.isCanceled()) { result.add(scheduledPass.myPass);