cleanup, lambdify

This commit is contained in:
Alexey Kudravtsev
2016-07-25 19:47:36 +03:00
parent 6b92a3aa95
commit 7ea87fc63e
5 changed files with 201 additions and 230 deletions
@@ -76,7 +76,7 @@ public class GeneralHighlightingPass extends ProgressableTextEditorHighlightingP
protected volatile boolean myHasErrorElement;
private volatile boolean myErrorFound;
protected final EditorColorsScheme myGlobalScheme;
private volatile NotNullProducer<HighlightVisitor[]> myHighlightVisitorProducer = () -> cloneHighlightVisitors();
private volatile NotNullProducer<HighlightVisitor[]> myHighlightVisitorProducer = this::cloneHighlightVisitors;
public GeneralHighlightingPass(@NotNull Project project,
@NotNull PsiFile file,
@@ -44,7 +44,7 @@ import java.util.*;
public class ExternalToolPass extends ProgressableTextEditorHighlightingPass {
private final AnnotationHolderImpl myAnnotationHolder;
private final Map<ExternalAnnotator, MyData> myAnnotator2DataMap = new HashMap<ExternalAnnotator, MyData>();
private final Map<ExternalAnnotator, MyData> 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<HighlightInfo> getHighlights() {
List<HighlightInfo> infos = new ArrayList<HighlightInfo>();
List<HighlightInfo> infos = new ArrayList<>(myAnnotationHolder.size());
for (Annotation annotation : myAnnotationHolder) {
infos.add(HighlightInfo.fromAnnotation(annotation));
}
@@ -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 <soft-wrap>
// 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 <soft-wrap>
// | 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<? extends SoftWrap> 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 <soft-wrap>
// 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 <soft-wrap>
// | 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<? extends SoftWrap> 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<TextRange> myRanges;
@@ -216,7 +208,7 @@ public class IndentsPass extends TextEditorHighlightingPass implements DumbAware
myDescriptors = buildDescriptors();
ArrayList<TextRange> ranges = new ArrayList<TextRange>();
ArrayList<TextRange> 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<RangeHighlighter> oldHighlighters = myEditor.getUserData(INDENT_HIGHLIGHTERS_IN_EDITOR_KEY);
final List<RangeHighlighter> newHighlighters = new ArrayList<RangeHighlighter>();
final List<RangeHighlighter> 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<IndentGuideDescriptor> descriptors = new ArrayList<IndentGuideDescriptor>();
IntStack lines = new IntStack();
IntStack indents = new IntStack();
lines.push(0);
indents.push(0);
assert myDocument != null;
List<IndentGuideDescriptor> 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<Language, TokenSet> 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;
@@ -141,7 +141,7 @@ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass
@NotNull final InspectionManager iManager,
@NotNull final List<LocalInspectionToolWrapper> toolWrappers) {
final ProgressIndicator progress = ProgressManager.getInstance().getProgressIndicator();
inspect(new ArrayList<LocalInspectionToolWrapper>(toolWrappers), iManager, false, false, progress);
inspect(new ArrayList<>(toolWrappers), iManager, false, false, progress);
addDescriptorsFromInjectedResults(iManager, context);
List<InspectionResult> resultList = result.get(getFile());
if (resultList == null) return;
@@ -207,9 +207,11 @@ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass
myFailFastOnAcquireReadAction = failFastOnAcquireReadAction;
if (toolWrappers.isEmpty()) return;
List<PsiElement> inside = new ArrayList<PsiElement>();
List<PsiElement> outside = new ArrayList<PsiElement>();
Divider.divideInsideAndOutside(getFile(), myRestrictRange.getStartOffset(), myRestrictRange.getEndOffset(), myPriorityRange, inside, new ArrayList<ProperTextRange>(), outside, new ArrayList<ProperTextRange>(),
List<PsiElement> inside = new ArrayList<>();
List<PsiElement> outside = new ArrayList<>();
Divider.divideInsideAndOutside(getFile(), myRestrictRange.getStartOffset(), myRestrictRange.getEndOffset(), myPriorityRange, inside,
new ArrayList<>(), outside,
new ArrayList<>(),
true, FILE_FILTER);
Set<String> elementDialectIds = InspectionEngine.calcElementDialectIds(inside, outside);
@@ -224,7 +226,7 @@ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass
progress.checkCanceled();
myInfos = new ArrayList<HighlightInfo>();
myInfos = new ArrayList<>();
addHighlightsFromResults(myInfos, progress);
}
@@ -237,8 +239,8 @@ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass
@NotNull final LocalInspectionToolSession session,
@NotNull List<LocalInspectionToolWrapper> wrappers,
@NotNull final Set<String> elementDialectIds) {
final List<InspectionContext> init = new ArrayList<InspectionContext>();
List<Map.Entry<LocalInspectionToolWrapper, Set<String>>> entries = new ArrayList<Map.Entry<LocalInspectionToolWrapper, Set<String>>>(toolToSpecifiedLanguageIds.entrySet());
final List<InspectionContext> init = new ArrayList<>();
List<Map.Entry<LocalInspectionToolWrapper, Set<String>>> entries = new ArrayList<>(toolToSpecifiedLanguageIds.entrySet());
Processor<Map.Entry<LocalInspectionToolWrapper, Set<String>>> processor =
pair -> {
@@ -323,21 +325,16 @@ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass
@NotNull final InspectionManager iManager,
final boolean inVisibleRange,
@NotNull final List<LocalInspectionToolWrapper> wrappers) {
final Set<PsiFile> injected = new THashSet<PsiFile>();
final Set<PsiFile> injected = new THashSet<>();
for (PsiElement element : elements) {
InjectedLanguageUtil.enumerate(element, getFile(), false, new PsiLanguageInjectionHost.InjectedPsiVisitor() {
@Override
public void visit(@NotNull PsiFile injectedPsi, @NotNull List<PsiLanguageInjectionHost.Shred> places) {
injected.add(injectedPsi);
}
});
InjectedLanguageUtil.enumerate(element, getFile(), false, (injectedPsi, places) -> injected.add(injectedPsi));
}
if (injected.isEmpty()) return;
Processor<PsiFile> processor = injectedPsi -> {
doInspectInjectedPsi(injectedPsi, onTheFly, indicator, iManager, inVisibleRange, wrappers);
return true;
};
if (!JobLauncher.getInstance().invokeConcurrentlyUnderProgress(new ArrayList<PsiFile>(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<TextRange, RangeMarker> ranges2markersCache = new THashMap<TextRange, RangeMarker>();
private final Map<TextRange, RangeMarker> ranges2markersCache = new THashMap<>();
private final TransferToEDTQueue<Trinity<ProblemDescriptor, LocalInspectionToolWrapper,ProgressIndicator>> myTransferToEDTQueue
= new TransferToEDTQueue<Trinity<ProblemDescriptor, LocalInspectionToolWrapper,ProgressIndicator>>("Apply inspection results", new Processor<Trinity<ProblemDescriptor, LocalInspectionToolWrapper,ProgressIndicator>>() {
= new TransferToEDTQueue<>("Apply inspection results", new Processor<Trinity<ProblemDescriptor, LocalInspectionToolWrapper, ProgressIndicator>>() {
private final InspectionProfile inspectionProfile = InspectionProjectProfileManager.getInstance(myProject).getCurrentProfile();
private final InjectedLanguageManager ilManager = InjectedLanguageManager.getInstance(myProject);
private final List<HighlightInfo> infos = new ArrayList<HighlightInfo>(2);
private final List<HighlightInfo> infos = new ArrayList<>(2);
private final PsiDocumentManager documentManager = PsiDocumentManager.getInstance(myProject);
@Override
public boolean process(Trinity<ProblemDescriptor, LocalInspectionToolWrapper,ProgressIndicator> trinity) {
public boolean process(Trinity<ProblemDescriptor, LocalInspectionToolWrapper, ProgressIndicator> 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<InspectionResult> resultList = this.result.get(file);
if (resultList == null) {
resultList = ConcurrencyUtil.cacheOrGet(this.result, file, new ArrayList<InspectionResult>());
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<Pair<TextRange, String>> emptyActionRegistered = new THashSet<Pair<TextRange, String>>();
Set<Pair<TextRange, String>> emptyActionRegistered = new THashSet<>();
for (Map.Entry<PsiFile, List<InspectionResult>> 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.<TextRange, String>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<PsiElement> getElementsFrom(@NotNull PsiFile file) {
final FileViewProvider viewProvider = file.getViewProvider();
final Set<PsiElement> result = new LinkedHashSet<PsiElement>();
final Set<PsiElement> 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<PsiElement>(result);
return new ArrayList<>(result);
}
@NotNull
List<LocalInspectionToolWrapper> getInspectionTools(@NotNull InspectionProfileWrapper profile) {
List<LocalInspectionToolWrapper> enabled = new ArrayList<LocalInspectionToolWrapper>();
final InspectionToolWrapper[] toolWrappers = profile.getInspectionProfile().getInspectionTools(getFile());
InspectionProfileWrapper.checkInspectionsDuplicates(toolWrappers);
List<LocalInspectionToolWrapper> 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<ProblemDescriptor> foundProblems) {
this.tool = tool;
this.foundProblems = new ArrayList<ProblemDescriptor>(foundProblems);
this.foundProblems = new ArrayList<>(foundProblems);
}
}
@@ -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<ScheduledPass, Job<Void>> mySubmittedPasses = new ConcurrentHashMap<ScheduledPass, Job<Void>>();
private final Map<ScheduledPass, Job<Void>> 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<Document, FileEditor> documentToEditors = MultiMap.createSet();
MultiMap<FileEditor, TextEditorHighlightingPass> documentBoundPasses = MultiMap.createSmart();
MultiMap<FileEditor, EditorBoundHighlightingPass> editorBoundPasses = MultiMap.createSmart();
Set<VirtualFile> vFiles = new HashSet<VirtualFile>();
Set<VirtualFile> vFiles = new HashSet<>();
for (Map.Entry<FileEditor, HighlightingPass[]> entry : passesMap.entrySet()) {
FileEditor fileEditor = entry.getKey();
@@ -157,10 +153,10 @@ class PassExecutorService implements Disposable {
}
}
List<ScheduledPass> freePasses = new ArrayList<ScheduledPass>(documentToEditors.size()*5);
List<ScheduledPass> dependentPasses = new ArrayList<ScheduledPass>(documentToEditors.size()*10);
List<ScheduledPass> freePasses = new ArrayList<>(documentToEditors.size() * 5);
List<ScheduledPass> dependentPasses = new ArrayList<>(documentToEditors.size() * 10);
// (fileEditor, passId) -> created pass
Map<Pair<FileEditor, Integer>, ScheduledPass> toBeSubmitted = new THashMap<Pair<FileEditor, Integer>, ScheduledPass>(passesMap.size());
Map<Pair<FileEditor, Integer>, ScheduledPass> toBeSubmitted = new THashMap<>(passesMap.size());
final AtomicInteger threadsToStartCountdown = new AtomicInteger(0);
for (Map.Entry<Document, Collection<FileEditor>> entry : documentToEditors.entrySet()) {
@@ -181,7 +177,7 @@ class PassExecutorService implements Disposable {
FileEditor fileEditor = entry.getKey();
Collection<EditorBoundHighlightingPass> createdEditorBoundPasses = entry.getValue();
List<TextEditorHighlightingPass> createdDocumentBoundPasses = (List<TextEditorHighlightingPass>)documentBoundPasses.get(fileEditor);
List<TextEditorHighlightingPass> allCreatedPasses = new ArrayList<TextEditorHighlightingPass>(createdDocumentBoundPasses);
List<TextEditorHighlightingPass> allCreatedPasses = new ArrayList<>(createdDocumentBoundPasses);
allCreatedPasses.addAll(createdEditorBoundPasses);
for (EditorBoundHighlightingPass pass : createdEditorBoundPasses) {
@@ -207,18 +203,15 @@ class PassExecutorService implements Disposable {
Map<Pair<FileEditor, Integer>, ScheduledPass> toBeSubmitted,
AtomicInteger threadsToStartCountdown) {
assert threadsToStartCountdown.get() == toBeSubmitted.size();
TIntObjectHashMap<Pair<ScheduledPass, Integer>> id2Visits = new TIntObjectHashMap<Pair<ScheduledPass, Integer>>();
TIntObjectHashMap<Pair<ScheduledPass, Integer>> id2Visits = new TIntObjectHashMap<>();
for (ScheduledPass freePass : freePasses) {
id2Visits.put(freePass.myPass.getId(), Pair.create(freePass, 0));
checkConsistency(freePass, id2Visits);
}
id2Visits.forEachEntry(new TIntObjectProcedure<Pair<ScheduledPass,Integer>>() {
@Override
public boolean execute(int id, Pair<ScheduledPass, Integer> 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<ScheduledPass> mySuccessorsOnCompletion = new ArrayList<ScheduledPass>();
private final Collection<ScheduledPass> mySuccessorsOnSubmit = new ArrayList<ScheduledPass>();
private final Collection<ScheduledPass> mySuccessorsOnCompletion = new ArrayList<>();
private final Collection<ScheduledPass> 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<TextEditorHighlightingPass> getAllSubmittedPasses() {
List<TextEditorHighlightingPass> result = new ArrayList<TextEditorHighlightingPass>(mySubmittedPasses.size());
List<TextEditorHighlightingPass> result = new ArrayList<>(mySubmittedPasses.size());
for (ScheduledPass scheduledPass : mySubmittedPasses.keySet()) {
if (!scheduledPass.myUpdateProgress.isCanceled()) {
result.add(scheduledPass.myPass);