use lambdas

This commit is contained in:
Sergey Ignatov
2018-07-09 17:12:34 +03:00
parent f9d7e75101
commit e67e0f673b
19 changed files with 114 additions and 187 deletions
@@ -13,16 +13,15 @@ import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.util.containers.Queue;
import com.intellij.util.indexing.InvertedIndexUtil;
import com.intellij.util.indexing.StorageException;
import com.intellij.util.indexing.ValueContainer;
import gnu.trove.THashSet;
import gnu.trove.TIntHashSet;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jps.backwardRefs.JavaCompilerBackwardReferenceIndex;
import org.jetbrains.jps.backwardRefs.CompilerRef;
import org.jetbrains.jps.backwardRefs.JavaCompilerBackwardReferenceIndex;
import org.jetbrains.jps.backwardRefs.SignatureData;
import org.jetbrains.jps.backwardRefs.index.JavaCompilerIndices;
import org.jetbrains.jps.backwardRefs.index.CompilerReferenceIndex;
import org.jetbrains.jps.backwardRefs.index.JavaCompilerIndices;
import java.io.File;
import java.io.IOException;
@@ -90,15 +89,12 @@ public class JavaBackwardReferenceIndexReaderFactory implements CompilerReferenc
public TIntHashSet findFileIdsWithImplicitToString(@NotNull CompilerRef ref) throws StorageException {
TIntHashSet result = new TIntHashSet();
myIndex.get(JavaCompilerIndices.IMPLICIT_TO_STRING).getData(ref).forEach(
new ValueContainer.ContainerAction<Void>() {
@Override
public boolean perform(int id, Void value) {
final VirtualFile file = findFile(id);
if (file != null) {
result.add(((VirtualFileWithId)file).getId());
}
return true;
(id, value) -> {
final VirtualFile file = findFile(id);
if (file != null) {
result.add(((VirtualFileWithId)file).getId());
}
return true;
});
return result;
}
@@ -300,19 +296,16 @@ public class JavaBackwardReferenceIndexReaderFactory implements CompilerReferenc
@NotNull
private DefCount getDefinitionCount(CompilerRef.NamedCompilerRef def) throws StorageException {
DefCount[] result = new DefCount[]{DefCount.NONE};
myIndex.get(JavaCompilerIndices.BACK_CLASS_DEF).getData(def).forEach(new ValueContainer.ContainerAction<Void>() {
@Override
public boolean perform(int id, Void value) {
if (result[0] == DefCount.NONE) {
result[0] = DefCount.ONE;
return true;
}
if (result[0] == DefCount.ONE) {
result[0] = DefCount.MANY;
return true;
}
return false;
myIndex.get(JavaCompilerIndices.BACK_CLASS_DEF).getData(def).forEach((id, value) -> {
if (result[0] == DefCount.NONE) {
result[0] = DefCount.ONE;
return true;
}
if (result[0] == DefCount.ONE) {
result[0] = DefCount.MANY;
return true;
}
return false;
});
return result[0];
}
@@ -33,7 +33,6 @@ import org.jetbrains.uast.evaluation.UEvaluationContextKt;
import org.jetbrains.uast.values.*;
import javax.swing.*;
import java.awt.event.MouseEvent;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;
@@ -97,16 +96,11 @@ public class IconLineMarkerProvider extends LineMarkerProviderDescriptor {
final Icon icon = ProjectIconsAccessor.getInstance(project).getIcon(file);
if (icon == null) return null;
final GutterIconNavigationHandler<PsiElement> navHandler = new GutterIconNavigationHandler<PsiElement>() {
@Override
public void navigate(MouseEvent e, PsiElement elt) {
FileEditorManager.getInstance(project).openFile(file, true);
}
};
final GutterIconNavigationHandler<PsiElement> navHandler = (e, elt) -> FileEditorManager.getInstance(project).openFile(file, true);
return new LineMarkerInfo<PsiElement>(bindingElement, bindingElement.getTextRange(), icon,
Pass.LINE_MARKERS, null, navHandler,
GutterIconRenderer.Alignment.LEFT);
return new LineMarkerInfo<>(bindingElement, bindingElement.getTextRange(), icon,
Pass.LINE_MARKERS, null, navHandler,
GutterIconRenderer.Alignment.LEFT);
}
@NotNull
@@ -27,13 +27,8 @@ import java.util.Set;
*/
public abstract class AbstractQualifiedReference<T extends AbstractQualifiedReference<T>> extends ASTWrapperPsiElement
implements PsiPolyVariantReference, PsiQualifiedReferenceElement {
private static final ResolveCache.PolyVariantResolver<AbstractQualifiedReference> MY_RESOLVER = new ResolveCache.PolyVariantResolver<AbstractQualifiedReference>() {
@NotNull
@Override
public ResolveResult[] resolve(@NotNull final AbstractQualifiedReference expression, final boolean incompleteCode) {
return expression.resolveInner();
}
};
private static final ResolveCache.PolyVariantResolver<AbstractQualifiedReference> MY_RESOLVER =
(expression, incompleteCode) -> expression.resolveInner();
protected AbstractQualifiedReference(@NotNull final ASTNode node) {
super(node);
@@ -643,17 +643,14 @@ public class JavaMethodsConflictResolver implements PsiConflictResolver{
return InferenceSession.isMoreSpecific(method2, method1, siteSubstitutor1, ((PsiExpressionList)myArgumentsList).getExpressions(), myArgumentsList, varargsPosition);
}
}
final PsiUtil.ApplicabilityChecker applicabilityChecker = new PsiUtil.ApplicabilityChecker() {
@Override
public boolean isApplicable(PsiType left, PsiType right, boolean allowUncheckedConversion, int argId) {
if (right instanceof PsiClassType) {
final PsiClass rightClass = ((PsiClassType)right).resolve();
if (rightClass instanceof PsiTypeParameter) {
right = new PsiImmediateClassType(rightClass, siteSubstitutor1);
}
final PsiUtil.ApplicabilityChecker applicabilityChecker = (left, right, allowUncheckedConversion, argId) -> {
if (right instanceof PsiClassType) {
final PsiClass rightClass = ((PsiClassType)right).resolve();
if (rightClass instanceof PsiTypeParameter) {
right = new PsiImmediateClassType(rightClass, siteSubstitutor1);
}
return languageLevel.isAtLeast(LanguageLevel.JDK_1_8) ? isTypeMoreSpecific(left, right, argId) : TypeConversionUtil.isAssignable(left, right, allowUncheckedConversion);
}
return languageLevel.isAtLeast(LanguageLevel.JDK_1_8) ? isTypeMoreSpecific(left, right, argId) : TypeConversionUtil.isAssignable(left, right, allowUncheckedConversion);
};
final int applicabilityLevel = PsiUtil.getApplicabilityLevel(method1, methodSubstitutor1, types2AtSite, languageLevel, false, varargsPosition, applicabilityChecker);
return applicabilityLevel > MethodCandidateInfo.ApplicabilityLevel.NOT_APPLICABLE;
@@ -47,34 +47,32 @@ public class SameParameterValueSlashesTest extends LightCodeInsightFixtureTestCa
@Test
public void testSlashes() {
Runnable runnable = new Runnable() {
public void run() {
String specialSymbol = "\\" + symbol;
String ourIntentionName = "Inline value '";
Runnable runnable = () -> {
String specialSymbol = "\\" + symbol;
String ourIntentionName = "Inline value '";
String before = "class C { " +
" void test() {" +
" String s = f(\"" + specialSymbol + "\");" +
" }" +
" String f(String <caret>p) {" +
" return \"123\" + p;" +
" }" +
"}";
myFixture.configureByText("C.java", before);
String before = "class C { " +
" void test() {" +
" String s = f(\"" + specialSymbol + "\");" +
" }" +
" String f(String <caret>p) {" +
" return \"123\" + p;" +
" }" +
"}";
myFixture.configureByText("C.java", before);
final IntentionAction singleIntention = myFixture.findSingleIntention(ourIntentionName);
myFixture.launchAction(singleIntention);
final IntentionAction singleIntention = myFixture.findSingleIntention(ourIntentionName);
myFixture.launchAction(singleIntention);
String after = "class C { " +
" void test() {" +
" String s = f();" +
" }" +
" String f() {" +
" return \"123\" + \"" + specialSymbol + "\";" +
" }" +
"}";
myFixture.checkResult(after);
}
String after = "class C { " +
" void test() {" +
" String s = f();" +
" }" +
" String f() {" +
" return \"123\" + \"" + specialSymbol + "\";" +
" }" +
"}";
myFixture.checkResult(after);
};
doTest(runnable);
}
@@ -25,7 +25,10 @@ import com.intellij.navigation.NavigationItem;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.project.Project;
import com.intellij.psi.*;
import com.intellij.psi.ElementDescriptionUtil;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiReference;
import com.intellij.psi.search.PsiElementProcessor;
import com.intellij.usageView.UsageViewShortNameLocation;
import com.intellij.util.Consumer;
@@ -139,12 +142,9 @@ public class GotoImplementationHandler extends GotoTargetHandler {
ImplementationsUpdaterTask(@NotNull GotoData gotoData, @NotNull Editor editor, int offset, final PsiReference reference) {
super(gotoData.source.getProject(), ImplementationSearcher.SEARCHING_FOR_IMPLEMENTATIONS,
createComparatorWrapper(Comparator.comparing(new Function<PsiElement, Comparable>() {
@Override
public Comparable apply(PsiElement e1) {
return getRenderer(e1, gotoData).getComparingObject(e1);
}
})));
createComparatorWrapper(Comparator.comparing((Function<PsiElement, Comparable>)e1 -> {
return getRenderer(e1, gotoData).getComparingObject(e1);
})));
myEditor = editor;
myOffset = offset;
myGotoData = gotoData;
@@ -20,7 +20,6 @@ import com.intellij.openapi.editor.impl.EditorComponentImpl;
import com.intellij.openapi.editor.impl.EditorImpl;
import com.intellij.openapi.editor.impl.SoftWrapModelImpl;
import com.intellij.openapi.editor.impl.event.MarkupModelListener;
import com.intellij.openapi.editor.impl.softwrap.mapping.SoftWrapApplianceManager;
import com.intellij.openapi.editor.markup.CustomHighlighterRenderer;
import com.intellij.openapi.editor.markup.HighlighterLayer;
import com.intellij.openapi.editor.markup.HighlighterTargetArea;
@@ -236,13 +235,10 @@ public final class LanguageConsoleBuilder {
final ConsoleGutterComponent lineEndGutter = new ConsoleGutterComponent(editor, gutterContentProvider, false);
editor.getSoftWrapModel().forceAdditionalColumnsUsage();
((SoftWrapModelImpl)editor.getSoftWrapModel()).getApplianceManager().setWidthProvider(new SoftWrapApplianceManager.VisibleAreaWidthProvider() {
@Override
public int getVisibleAreaWidth() {
int guttersWidth = lineEndGutter.getPreferredWidth() + lineStartGutter.getPreferredWidth();
EditorEx editor = getHistoryViewer();
return editor.getScrollingModel().getVisibleArea().width - guttersWidth;
}
((SoftWrapModelImpl)editor.getSoftWrapModel()).getApplianceManager().setWidthProvider(() -> {
int guttersWidth = lineEndGutter.getPreferredWidth() + lineStartGutter.getPreferredWidth();
EditorEx editor1 = getHistoryViewer();
return editor1.getScrollingModel().getVisibleArea().width - guttersWidth;
});
editor.setHorizontalScrollbarVisible(true);
@@ -740,12 +740,8 @@ public class Messages {
final int focusedOptionIndex,
Icon icon) {
return showCheckboxMessageDialog(message, title, new String[]{OK_BUTTON, CANCEL_BUTTON}, checkboxText, checked, defaultOptionIndex,
focusedOptionIndex, icon, new PairFunction<Integer, JCheckBox, Integer>() {
@Override
public Integer fun(final Integer exitCode, final JCheckBox cb) {
return exitCode == -1 ? CANCEL : exitCode + (cb.isSelected() ? 1 : 0);
}
});
focusedOptionIndex, icon,
(exitCode, cb) -> exitCode == -1 ? CANCEL : exitCode + (cb.isSelected() ? 1 : 0));
}
public static int showCheckboxMessageDialog(String message,
@@ -15,7 +15,6 @@ import com.intellij.openapi.diff.impl.DiffPanelImpl;
import com.intellij.openapi.diff.impl.DiffUtil;
import com.intellij.openapi.diff.impl.mergeTool.MergeTool;
import com.intellij.openapi.diff.impl.processing.HighlightMode;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.markup.MarkupEditorFilter;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Disposer;
@@ -73,12 +72,7 @@ public class DiffManagerImpl extends DiffManager implements PersistentStateCompo
private final ExternalizablePropertyContainer myProperties;
public static final DiffTool INTERNAL_DIFF = new FrameDiffTool();
private static final MarkupEditorFilter DIFF_EDITOR_FILTER = new MarkupEditorFilter() {
@Override
public boolean avaliableIn(Editor editor) {
return DiffUtil.isDiffEditor(editor);
}
};
private static final MarkupEditorFilter DIFF_EDITOR_FILTER = editor -> DiffUtil.isDiffEditor(editor);
private ComparisonPolicy myComparisonPolicy = ComparisonPolicy.DEFAULT;
private HighlightMode myHighlightMode = HighlightMode.BY_WORD;
@@ -748,29 +748,21 @@ public class ColorThief {
}
}
private static final Comparator<VBox> COMPARATOR_COUNT = new Comparator<VBox>() {
@Override
public int compare(VBox a, VBox b) {
return a.count(false) - b.count(false);
private static final Comparator<VBox> COMPARATOR_COUNT = (a, b) -> a.count(false) - b.count(false);
private static final Comparator<VBox> COMPARATOR_PRODUCT = (a, b) -> {
int aCount = a.count(false);
int bCount = b.count(false);
int aVolume = a.volume(false);
int bVolume = b.volume(false);
// If count is 0 for both (or the same), sort by volume
if (aCount == bCount) {
return aVolume - bVolume;
}
};
private static final Comparator<VBox> COMPARATOR_PRODUCT = new Comparator<VBox>() {
@Override
public int compare(VBox a, VBox b) {
int aCount = a.count(false);
int bCount = b.count(false);
int aVolume = a.volume(false);
int bVolume = b.volume(false);
// If count is 0 for both (or the same), sort by volume
if (aCount == bCount) {
return aVolume - bVolume;
}
// Otherwise sort by products
return Long.compare((long) aCount * aVolume, (long) bCount * bVolume);
}
// Otherwise sort by products
return Long.compare((long) aCount * aVolume, (long) bCount * bVolume);
};
}
@@ -61,12 +61,12 @@ public class OptionalUsedAsFieldOrParameterTypeInspectionTest extends LightInspe
doTest("import java.util.Optional;" +
"import java.util.function.Function;" +
"class X {" +
" Function<Optional<Long>, Long> homebrewOrElseNull = new Function<Optional<Long>, Long>() {" +
" @Override\n" +
" public Long apply(Optional<Long> input) {" +
" return input.isPresent() ? input.get() : null;" +
" }" +
" };" +
"" +
"" +
"" +
"" +
" " +
"Function<Optional<Long>, Long> homebrewOrElseNull = input-> input.isPresent() ? input.get() : null;" +
"}");
}
@@ -32,11 +32,11 @@ public class ThrownCaughtLocallyInspectionTest extends LightInspectionTestCase {
" Runnable runnable = () -> {\n" +
" throw new RuntimeException();\n" +
" };\n" +
" Runnable runnableLambda = new Runnable() {\n" +
" @Override\n" +
" public void run() {\n" +
"" +
" Runnable runnableLambda = ()-> {\n" +
"" +
" throw new RuntimeException();\n" +
" }\n" +
" " +
" };\n" +
" }\n" +
" catch (RuntimeException e){\n" +
@@ -39,13 +39,8 @@ import java.util.List;
*/
public class GrNewExpressionImpl extends GrCallExpressionImpl implements GrNewExpression {
private static final ResolveCache.PolyVariantResolver<MyFakeReference> RESOLVER = new ResolveCache.PolyVariantResolver<MyFakeReference>() {
@NotNull
@Override
public GroovyResolveResult[] resolve(@NotNull MyFakeReference reference, boolean incompleteCode) {
return reference.getElement().resolveImpl(incompleteCode);
}
};
private static final ResolveCache.PolyVariantResolver<MyFakeReference> RESOLVER =
(reference, incompleteCode) -> reference.getElement().resolveImpl(incompleteCode);
private final MyFakeReference myFakeReference = new MyFakeReference();
@@ -78,18 +78,14 @@ public class GrUnaryExpressionImpl extends GrExpressionImpl implements GrUnaryEx
}
};
private static final ResolveCache.PolyVariantResolver<GrUnaryExpressionImpl> OUR_RESOLVER = new ResolveCache.PolyVariantResolver<GrUnaryExpressionImpl>() {
@NotNull
@Override
public GroovyResolveResult[] resolve(@NotNull GrUnaryExpressionImpl unary, boolean incompleteCode) {
final GrExpression operand = unary.getOperand();
if (operand == null) return GroovyResolveResult.EMPTY_ARRAY;
private static final ResolveCache.PolyVariantResolver<GrUnaryExpressionImpl> OUR_RESOLVER = (unary, incompleteCode) -> {
final GrExpression operand = unary.getOperand();
if (operand == null) return GroovyResolveResult.EMPTY_ARRAY;
final PsiType type = operand.getType();
if (type == null) return GroovyResolveResult.EMPTY_ARRAY;
final PsiType type = operand.getType();
if (type == null) return GroovyResolveResult.EMPTY_ARRAY;
return TypesUtil.getOverloadedUnaryOperatorCandidates(type, unary.getOperationTokenType(), operand, PsiType.EMPTY_ARRAY);
}
return TypesUtil.getOverloadedUnaryOperatorCandidates(type, unary.getOperationTokenType(), operand, PsiType.EMPTY_ARRAY);
};
public GrUnaryExpressionImpl(@NotNull ASTNode node) {
@@ -46,12 +46,7 @@ import java.util.List;
public class XsltVariableContext implements VariableContext<XsltVariable> {
public static final XsltVariableContext INSTANCE = new XsltVariableContext();
private final ResolveCache.Resolver RESOLVER = new ResolveCache.Resolver() {
@Nullable
public PsiElement resolve(@NotNull PsiReference psiReference, boolean incompleteCode) {
return resolveInner((XPathVariableReference)psiReference);
}
};
private final ResolveCache.Resolver RESOLVER = (psiReference, incompleteCode) -> resolveInner((XPathVariableReference)psiReference);
@NotNull
public XsltVariable[] getVariablesInScope(XPathElement element) {
@@ -17,7 +17,10 @@ package org.intellij.lang.xpath.xslt.impl.references;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.*;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiPolyVariantReference;
import com.intellij.psi.PsiReference;
import com.intellij.psi.ResolveResult;
import com.intellij.psi.impl.source.resolve.ResolveCache;
import com.intellij.psi.xml.XmlAttribute;
import com.intellij.psi.xml.XmlAttributeValue;
@@ -75,12 +78,8 @@ abstract class SimpleAttributeReference implements PsiReference {
@Nullable
public final PsiElement resolve() {
return ResolveCache.getInstance(myAttribute.getProject()).resolveWithCaching(this, new ResolveCache.Resolver() {
@Nullable
public PsiElement resolve(@NotNull PsiReference psiReference, boolean b) {
return resolveImpl();
}
}, false, false);
return ResolveCache.getInstance(myAttribute.getProject()).resolveWithCaching(this,
(ResolveCache.Resolver)(psiReference, b) -> resolveImpl(), false, false);
}
@Nullable
@@ -8,23 +8,19 @@ import com.intellij.openapi.util.Pair;
import org.jetbrains.annotations.NotNull;
import java.util.Collections;
import java.util.List;
public class PyEduConsoleInputFilterProvider implements ConsoleInputFilterProvider {
@NotNull
@Override
public InputFilter[] getDefaultFilters(@NotNull Project project) {
return new InputFilter[]{new InputFilter() {
@Override
public List<Pair<String, ConsoleViewContentType>> applyFilter(@NotNull String text, @NotNull ConsoleViewContentType outputType) {
if (outputType.equals(ConsoleViewContentType.SYSTEM_OUTPUT) && !text.contains("exit code")) {
return Collections.emptyList();
}
if (text.startsWith("pydev debugger")) {
return Collections.emptyList();
}
return Collections.singletonList(Pair.create(text, outputType));
return new InputFilter[]{(text, outputType) -> {
if (outputType.equals(ConsoleViewContentType.SYSTEM_OUTPUT) && !text.contains("exit code")) {
return Collections.emptyList();
}
if (text.startsWith("pydev debugger")) {
return Collections.emptyList();
}
return Collections.singletonList(Pair.create(text, outputType));
}};
}
}
@@ -16,7 +16,6 @@
package com.jetbrains.python.pyi;
import com.intellij.codeHighlighting.Pass;
import com.intellij.codeInsight.daemon.GutterIconNavigationHandler;
import com.intellij.codeInsight.daemon.RelatedItemLineMarkerInfo;
import com.intellij.codeInsight.daemon.RelatedItemLineMarkerProvider;
import com.intellij.icons.AllIcons;
@@ -33,7 +32,6 @@ import com.jetbrains.python.psi.PyTargetExpression;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
import java.awt.event.MouseEvent;
import java.util.Collection;
import java.util.Collections;
@@ -73,9 +71,7 @@ public class PyiRelatedItemLineMarkerProvider extends RelatedItemLineMarkerProvi
final String stubFileName = relatedElement.getContainingFile().getName();
return new RelatedItemLineMarkerInfo<>(
element, element.getTextRange(), ICON, Pass.LINE_MARKERS,
element1 -> itemTitle + " in " + stubFileName, new GutterIconNavigationHandler<PsiElement>() {
@Override
public void navigate(MouseEvent e, PsiElement elt) {
element1 -> itemTitle + " in " + stubFileName, (e, elt) -> {
final PsiElement restoredRelatedElement = relatedElementPointer.getElement();
if (restoredRelatedElement == null) {
return;
@@ -87,7 +83,6 @@ public class PyiRelatedItemLineMarkerProvider extends RelatedItemLineMarkerProvi
.createNavigatable(restoredRelatedElement.getProject(), virtualFile, offset)
.navigate(true);
}
}
}, GutterIconRenderer.Alignment.RIGHT, GotoRelatedItem.createItems(Collections.singletonList(relatedElement)));
}, GutterIconRenderer.Alignment.RIGHT, GotoRelatedItem.createItems(Collections.singletonList(relatedElement)));
}
}
@@ -73,12 +73,8 @@ public class PySurroundWithTest extends PyTestCase {
}
private void doTestSurroundWithCustomFoldingRegion() {
final Surrounder surrounder = ContainerUtil.find(CustomFoldingSurroundDescriptor.SURROUNDERS, new Condition<Surrounder>() {
@Override
public boolean value(Surrounder surrounder) {
return surrounder.getTemplateDescription().contains("<editor-fold");
}
});
final Surrounder surrounder = ContainerUtil.find(CustomFoldingSurroundDescriptor.SURROUNDERS,
(Condition<Surrounder>)surrounder1 -> surrounder1.getTemplateDescription().contains("<editor-fold"));
assertNotNull(surrounder);
doTest(surrounder);
}