Commit fdd8f208 authored by Egor.Ushakov's avatar Egor.Ushakov
Browse files

cleanup (java8)

parent ef32b8dd
Showing with 66 additions and 109 deletions
+66 -109
...@@ -92,7 +92,7 @@ public class XDebuggerUtilImpl extends XDebuggerUtil { ...@@ -92,7 +92,7 @@ public class XDebuggerUtilImpl extends XDebuggerUtil {
public XLineBreakpointType<?>[] getLineBreakpointTypes() { public XLineBreakpointType<?>[] getLineBreakpointTypes() {
if (myLineBreakpointTypes == null) { if (myLineBreakpointTypes == null) {
XBreakpointType[] types = XBreakpointUtil.getBreakpointTypes(); XBreakpointType[] types = XBreakpointUtil.getBreakpointTypes();
List<XLineBreakpointType<?>> lineBreakpointTypes = new ArrayList<XLineBreakpointType<?>>(); List<XLineBreakpointType<?>> lineBreakpointTypes = new ArrayList<>();
for (XBreakpointType type : types) { for (XBreakpointType type : types) {
if (type instanceof XLineBreakpointType<?>) { if (type instanceof XLineBreakpointType<?>) {
lineBreakpointTypes.add((XLineBreakpointType<?>)type); lineBreakpointTypes.add((XLineBreakpointType<?>)type);
...@@ -159,7 +159,7 @@ public class XDebuggerUtilImpl extends XDebuggerUtil { ...@@ -159,7 +159,7 @@ public class XDebuggerUtilImpl extends XDebuggerUtil {
if (!variants.isEmpty() && editor != null) { if (!variants.isEmpty() && editor != null) {
RelativePoint relativePoint = DebuggerUIUtil.getPositionForPopup(editor, line); RelativePoint relativePoint = DebuggerUIUtil.getPositionForPopup(editor, line);
if (variants.size() > 1 && relativePoint != null) { if (variants.size() > 1 && relativePoint != null) {
final AsyncPromise<XLineBreakpoint> res = new AsyncPromise<XLineBreakpoint>(); final AsyncPromise<XLineBreakpoint> res = new AsyncPromise<>();
class MySelectionListener implements ListSelectionListener { class MySelectionListener implements ListSelectionListener {
RangeHighlighter myHighlighter = null; RangeHighlighter myHighlighter = null;
...@@ -231,12 +231,9 @@ public class XDebuggerUtilImpl extends XDebuggerUtil { ...@@ -231,12 +231,9 @@ public class XDebuggerUtilImpl extends XDebuggerUtil {
@Override @Override
public PopupStep onChosen(final XLineBreakpointType.XLineBreakpointVariant selectedValue, boolean finalChoice) { public PopupStep onChosen(final XLineBreakpointType.XLineBreakpointVariant selectedValue, boolean finalChoice) {
selectionListener.clearHighlighter(); selectionListener.clearHighlighter();
ApplicationManager.getApplication().runWriteAction(new Runnable() { ApplicationManager.getApplication().runWriteAction(() -> {
@Override P properties = (P)selectedValue.createProperties();
public void run() { res.setResult(breakpointManager.addLineBreakpoint(type, file.getUrl(), line, properties, temporary));
P properties = (P)selectedValue.createProperties();
res.setResult(breakpointManager.addLineBreakpoint(type, file.getUrl(), line, properties, temporary));
}
}); });
return FINAL_CHOICE; return FINAL_CHOICE;
} }
...@@ -284,7 +281,7 @@ public class XDebuggerUtilImpl extends XDebuggerUtil { ...@@ -284,7 +281,7 @@ public class XDebuggerUtilImpl extends XDebuggerUtil {
@Override @Override
public <T extends XBreakpointType> T findBreakpointType(@NotNull Class<T> typeClass) { public <T extends XBreakpointType> T findBreakpointType(@NotNull Class<T> typeClass) {
if (myBreakpointTypeByClass == null) { if (myBreakpointTypeByClass == null) {
myBreakpointTypeByClass = new THashMap<Class<? extends XBreakpointType>, XBreakpointType<?, ?>>(); myBreakpointTypeByClass = new THashMap<>();
for (XBreakpointType<?, ?> breakpointType : XBreakpointUtil.getBreakpointTypes()) { for (XBreakpointType<?, ?> breakpointType : XBreakpointUtil.getBreakpointTypes()) {
myBreakpointTypeByClass.put(breakpointType.getClass(), breakpointType); myBreakpointTypeByClass.put(breakpointType.getClass(), breakpointType);
} }
...@@ -341,12 +338,9 @@ public class XDebuggerUtilImpl extends XDebuggerUtil { ...@@ -341,12 +338,9 @@ public class XDebuggerUtilImpl extends XDebuggerUtil {
private XSourcePosition getDelegate() { private XSourcePosition getDelegate() {
if (myDelegate == null) { if (myDelegate == null) {
myDelegate = ApplicationManager.getApplication().runReadAction(new Computable<XSourcePosition>() { myDelegate = ApplicationManager.getApplication().runReadAction((Computable<XSourcePosition>)() -> {
@Override PsiElement elem = pointer.getElement();
public XSourcePosition compute() { return XSourcePositionImpl.createByOffset(pointer.getVirtualFile(), elem != null ? elem.getTextOffset() : -1);
PsiElement elem = pointer.getElement();
return XSourcePositionImpl.createByOffset(pointer.getVirtualFile(), elem != null ? elem.getTextOffset() : -1);
}
}); });
} }
return myDelegate; return myDelegate;
...@@ -386,7 +380,7 @@ public class XDebuggerUtilImpl extends XDebuggerUtil { ...@@ -386,7 +380,7 @@ public class XDebuggerUtilImpl extends XDebuggerUtil {
@Override @Override
public <B extends XLineBreakpoint<?>> XBreakpointGroupingRule<B, ?> getGroupingByFileRule() { public <B extends XLineBreakpoint<?>> XBreakpointGroupingRule<B, ?> getGroupingByFileRule() {
return new XBreakpointFileGroupingRule<B>(); return new XBreakpointFileGroupingRule<>();
} }
@Nullable @Nullable
...@@ -408,7 +402,7 @@ public class XDebuggerUtilImpl extends XDebuggerUtil { ...@@ -408,7 +402,7 @@ public class XDebuggerUtilImpl extends XDebuggerUtil {
} }
VirtualFile file = FileDocumentManager.getInstance().getFile(editor.getDocument()); VirtualFile file = FileDocumentManager.getInstance().getFile(editor.getDocument());
List<XSourcePosition> res = new SmartList<XSourcePosition>(); List<XSourcePosition> res = new SmartList<>();
for (Caret caret : editor.getCaretModel().getAllCarets()) { for (Caret caret : editor.getCaretModel().getAllCarets()) {
XSourcePositionImpl position = XSourcePositionImpl.createByOffset(file, caret.getOffset()); XSourcePositionImpl position = XSourcePositionImpl.createByOffset(file, caret.getOffset());
if (position != null) { if (position != null) {
...@@ -429,23 +423,15 @@ public class XDebuggerUtilImpl extends XDebuggerUtil { ...@@ -429,23 +423,15 @@ public class XDebuggerUtilImpl extends XDebuggerUtil {
@Override @Override
public <B extends XBreakpoint<?>> Comparator<B> getDefaultBreakpointComparator(final XBreakpointType<B, ?> type) { public <B extends XBreakpoint<?>> Comparator<B> getDefaultBreakpointComparator(final XBreakpointType<B, ?> type) {
return new Comparator<B>() { return (o1, o2) -> type.getDisplayText(o1).compareTo(type.getDisplayText(o2));
@Override
public int compare(final B o1, final B o2) {
return type.getDisplayText(o1).compareTo(type.getDisplayText(o2));
}
};
} }
@Override @Override
public <P extends XBreakpointProperties> Comparator<XLineBreakpoint<P>> getDefaultLineBreakpointComparator() { public <P extends XBreakpointProperties> Comparator<XLineBreakpoint<P>> getDefaultLineBreakpointComparator() {
return new Comparator<XLineBreakpoint<P>>() { return (o1, o2) -> {
@Override int fileCompare = o1.getFileUrl().compareTo(o2.getFileUrl());
public int compare(final XLineBreakpoint<P> o1, final XLineBreakpoint<P> o2) { if (fileCompare != 0) return fileCompare;
int fileCompare = o1.getFileUrl().compareTo(o2.getFileUrl()); return o1.getLine() - o2.getLine();
if (fileCompare != 0) return fileCompare;
return o1.getLine() - o2.getLine();
}
}; };
} }
...@@ -503,7 +489,7 @@ public class XDebuggerUtilImpl extends XDebuggerUtil { ...@@ -503,7 +489,7 @@ public class XDebuggerUtilImpl extends XDebuggerUtil {
@Override @Override
public <B extends XLineBreakpoint<?>> List<XBreakpointGroupingRule<B, ?>> getGroupingByFileRuleAsList() { public <B extends XLineBreakpoint<?>> List<XBreakpointGroupingRule<B, ?>> getGroupingByFileRuleAsList() {
return Collections.<XBreakpointGroupingRule<B, ?>>singletonList(this.<B>getGroupingByFileRule()); return Collections.singletonList(this.getGroupingByFileRule());
} }
@Override @Override
......
/* /*
* Copyright 2000-2015 JetBrains s.r.o. * Copyright 2000-2016 JetBrains s.r.o.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -91,8 +91,7 @@ public class XBreakpointManagerImpl implements XBreakpointManager, PersistentSta ...@@ -91,8 +91,7 @@ public class XBreakpointManagerImpl implements XBreakpointManager, PersistentSta
ApplicationManager.getApplication().invokeLater(new Runnable() { ApplicationManager.getApplication().invokeLater(new Runnable() {
@Override @Override
public void run() { public void run() {
XBreakpointBase<?, ?, ?>[] breakpoints = getAllBreakpoints(); for (XBreakpointBase breakpoint : getAllBreakpoints()) {
for (XBreakpointBase<?, ?, ?> breakpoint : breakpoints) {
XSourcePosition position = breakpoint.getSourcePosition(); XSourcePosition position = breakpoint.getSourcePosition();
if (position != null && Comparing.equal(position.getFile(), file)) { if (position != null && Comparing.equal(position.getFile(), file)) {
fireBreakpointChanged(breakpoint); fireBreakpointChanged(breakpoint);
......
...@@ -76,53 +76,50 @@ public abstract class XValueContainerNode<ValueContainer extends XValueContainer ...@@ -76,53 +76,50 @@ public abstract class XValueContainerNode<ValueContainer extends XValueContainer
@Override @Override
public void addChildren(@NotNull final XValueChildrenList children, final boolean last) { public void addChildren(@NotNull final XValueChildrenList children, final boolean last) {
if (myObsolete) return; if (myObsolete) return;
invokeNodeUpdate(new Runnable() { invokeNodeUpdate(() -> {
@Override if (myObsolete) return;
public void run() { List<XValueContainerNode<?>> newChildren;
if (myObsolete) return; if (children.size() > 0) {
List<XValueContainerNode<?>> newChildren; newChildren = new ArrayList<>(children.size());
if (children.size() > 0) { if (myValueChildren == null) {
newChildren = new ArrayList<XValueContainerNode<?>>(children.size()); if (!myAlreadySorted && XDebuggerSettingsManager.getInstance().getDataViewSettings().isSortValues()) {
if (myValueChildren == null) { myValueChildren = new SortedList<>(XValueNodeImpl.COMPARATOR);
if (!myAlreadySorted && XDebuggerSettingsManager.getInstance().getDataViewSettings().isSortValues()) {
myValueChildren = new SortedList<XValueNodeImpl>(XValueNodeImpl.COMPARATOR);
}
else {
myValueChildren = new ArrayList<XValueNodeImpl>(children.size());
}
} }
boolean valuesInline = XDebuggerSettingsManager.getInstance().getDataViewSettings().isShowValuesInline(); else {
InlineDebuggerHelper inlineHelper = getTree().getEditorsProvider().getInlineDebuggerHelper(); myValueChildren = new ArrayList<>(children.size());
for (int i = 0; i < children.size(); i++) {
XValueNodeImpl node = new XValueNodeImpl(myTree, XValueContainerNode.this, children.getName(i), children.getValue(i));
myValueChildren.add(node);
newChildren.add(node);
if (valuesInline && inlineHelper.shouldEvaluateChildrenByDefault(node) && isUseGetChildrenHack(myTree)) { //todo[kb]: try to generify this dirty hack
node.getChildren();
}
} }
} }
else { boolean valuesInline = XDebuggerSettingsManager.getInstance().getDataViewSettings().isShowValuesInline();
newChildren = new SmartList<XValueContainerNode<?>>(); InlineDebuggerHelper inlineHelper = getTree().getEditorsProvider().getInlineDebuggerHelper();
if (myValueChildren == null) { for (int i = 0; i < children.size(); i++) {
myValueChildren = last ? Collections.<XValueNodeImpl>emptyList() : new SmartList<XValueNodeImpl>(); XValueNodeImpl node = new XValueNodeImpl(myTree, this, children.getName(i), children.getValue(i));
myValueChildren.add(node);
newChildren.add(node);
if (valuesInline && inlineHelper.shouldEvaluateChildrenByDefault(node) && isUseGetChildrenHack(myTree)) { //todo[kb]: try to generify this dirty hack
node.getChildren();
} }
} }
}
else {
newChildren = new SmartList<>();
if (myValueChildren == null) {
myValueChildren = last ? Collections.emptyList() : new SmartList<>();
}
}
myTopGroups = createGroupNodes(children.getTopGroups(), myTopGroups, newChildren); myTopGroups = createGroupNodes(children.getTopGroups(), myTopGroups, newChildren);
myBottomGroups = createGroupNodes(children.getBottomGroups(), myBottomGroups, newChildren); myBottomGroups = createGroupNodes(children.getBottomGroups(), myBottomGroups, newChildren);
myCachedAllChildren = null;
fireNodesInserted(newChildren);
if (last && myTemporaryMessageChildren != null) {
final int[] ints = getNodesIndices(myTemporaryMessageChildren);
final TreeNode[] removed = myTemporaryMessageChildren.toArray(new TreeNode[myTemporaryMessageChildren.size()]);
myCachedAllChildren = null; myCachedAllChildren = null;
fireNodesInserted(newChildren); myTemporaryMessageChildren = null;
if (last && myTemporaryMessageChildren != null) { fireNodesRemoved(ints, removed);
final int[] ints = getNodesIndices(myTemporaryMessageChildren);
final TreeNode[] removed = myTemporaryMessageChildren.toArray(new TreeNode[myTemporaryMessageChildren.size()]);
myCachedAllChildren = null;
myTemporaryMessageChildren = null;
fireNodesRemoved(ints, removed);
}
myTree.childrenLoaded(XValueContainerNode.this, newChildren, last);
} }
myTree.childrenLoaded(this, newChildren, last);
}); });
} }
...@@ -136,7 +133,7 @@ public abstract class XValueContainerNode<ValueContainer extends XValueContainer ...@@ -136,7 +133,7 @@ public abstract class XValueContainerNode<ValueContainer extends XValueContainer
List<XValueContainerNode<?>> newChildren) { List<XValueContainerNode<?>> newChildren) {
if (groups.isEmpty()) return prevNodes; if (groups.isEmpty()) return prevNodes;
List<XValueGroupNodeImpl> nodes = prevNodes != null ? prevNodes : new SmartList<XValueGroupNodeImpl>(); List<XValueGroupNodeImpl> nodes = prevNodes != null ? prevNodes : new SmartList<>();
for (XValueGroup group : groups) { for (XValueGroup group : groups) {
XValueGroupNodeImpl node = new XValueGroupNodeImpl(myTree, this, group); XValueGroupNodeImpl node = new XValueGroupNodeImpl(myTree, this, group);
nodes.add(node); nodes.add(node);
...@@ -147,12 +144,7 @@ public abstract class XValueContainerNode<ValueContainer extends XValueContainer ...@@ -147,12 +144,7 @@ public abstract class XValueContainerNode<ValueContainer extends XValueContainer
@Override @Override
public void tooManyChildren(final int remaining) { public void tooManyChildren(final int remaining) {
invokeNodeUpdate(new Runnable() { invokeNodeUpdate(() -> setTemporaryMessageNode(MessageTreeNode.createEllipsisNode(myTree, this, remaining)));
@Override
public void run() {
setTemporaryMessageNode(MessageTreeNode.createEllipsisNode(myTree, XValueContainerNode.this, remaining));
}
});
} }
@Override @Override
...@@ -184,14 +176,7 @@ public abstract class XValueContainerNode<ValueContainer extends XValueContainer ...@@ -184,14 +176,7 @@ public abstract class XValueContainerNode<ValueContainer extends XValueContainer
@Override @Override
public void setMessage(@NotNull final String message, public void setMessage(@NotNull final String message,
final Icon icon, @NotNull final SimpleTextAttributes attributes, @Nullable final XDebuggerTreeNodeHyperlink link) { final Icon icon, @NotNull final SimpleTextAttributes attributes, @Nullable final XDebuggerTreeNodeHyperlink link) {
invokeNodeUpdate(new Runnable() { invokeNodeUpdate(() -> setMessageNodes(MessageTreeNode.createMessages(myTree, this, message, link, icon, attributes), false));
@Override
public void run() {
setMessageNodes(MessageTreeNode.createMessages(myTree, XValueContainerNode.this, message, link,
icon,
attributes), false);
}
});
} }
private void setTemporaryMessageNode(final MessageTreeNode messageNode) { private void setTemporaryMessageNode(final MessageTreeNode messageNode) {
...@@ -200,8 +185,8 @@ public abstract class XValueContainerNode<ValueContainer extends XValueContainer ...@@ -200,8 +185,8 @@ public abstract class XValueContainerNode<ValueContainer extends XValueContainer
private void setMessageNodes(final List<MessageTreeNode> messages, boolean temporary) { private void setMessageNodes(final List<MessageTreeNode> messages, boolean temporary) {
myCachedAllChildren = null; myCachedAllChildren = null;
List<MessageTreeNode> allMessageChildren = ContainerUtil.concat(myMessageChildren != null ? myMessageChildren : Collections.<MessageTreeNode>emptyList(), List<MessageTreeNode> allMessageChildren = ContainerUtil.concat(myMessageChildren != null ? myMessageChildren : Collections.emptyList(),
myTemporaryMessageChildren != null ? myTemporaryMessageChildren : Collections.<MessageTreeNode>emptyList()); myTemporaryMessageChildren != null ? myTemporaryMessageChildren : Collections.emptyList());
final int[] indices = getNodesIndices(allMessageChildren); final int[] indices = getNodesIndices(allMessageChildren);
final TreeNode[] nodes = allMessageChildren.toArray(new TreeNode[allMessageChildren.size()]); final TreeNode[] nodes = allMessageChildren.toArray(new TreeNode[allMessageChildren.size()]);
fireNodesRemoved(indices, nodes); fireNodesRemoved(indices, nodes);
...@@ -223,7 +208,7 @@ public abstract class XValueContainerNode<ValueContainer extends XValueContainer ...@@ -223,7 +208,7 @@ public abstract class XValueContainerNode<ValueContainer extends XValueContainer
loadChildren(); loadChildren();
if (myCachedAllChildren == null) { if (myCachedAllChildren == null) {
myCachedAllChildren = new ArrayList<TreeNode>(); myCachedAllChildren = new ArrayList<>();
if (myMessageChildren != null) { if (myMessageChildren != null) {
myCachedAllChildren.addAll(myMessageChildren); myCachedAllChildren.addAll(myMessageChildren);
} }
......
...@@ -50,12 +50,7 @@ import java.util.Comparator; ...@@ -50,12 +50,7 @@ import java.util.Comparator;
* @author nik * @author nik
*/ */
public class XValueNodeImpl extends XValueContainerNode<XValue> implements XValueNode, XCompositeNode, XValueNodePresentationConfigurator.ConfigurableXValueNode, RestorableStateNode { public class XValueNodeImpl extends XValueContainerNode<XValue> implements XValueNode, XCompositeNode, XValueNodePresentationConfigurator.ConfigurableXValueNode, RestorableStateNode {
public static final Comparator<XValueNodeImpl> COMPARATOR = new Comparator<XValueNodeImpl>() { public static final Comparator<XValueNodeImpl> COMPARATOR = (o1, o2) -> StringUtil.naturalCompare(o1.getName(), o2.getName());
@Override
public int compare(XValueNodeImpl o1, XValueNodeImpl o2) {
return StringUtil.naturalCompare(o1.getName(), o2.getName());
}
};
private static final int MAX_NAME_LENGTH = 100; private static final int MAX_NAME_LENGTH = 100;
...@@ -153,12 +148,7 @@ public class XValueNodeImpl extends XValueContainerNode<XValue> implements XValu ...@@ -153,12 +148,7 @@ public class XValueNodeImpl extends XValueContainerNode<XValue> implements XValu
}; };
if (getValueContainer().computeInlineDebuggerData(callback) == ThreeState.UNSURE) { if (getValueContainer().computeInlineDebuggerData(callback) == ThreeState.UNSURE) {
getValueContainer().computeSourcePosition(new XNavigatable() { getValueContainer().computeSourcePosition(callback::computed);
@Override
public void setSourcePosition(@Nullable XSourcePosition sourcePosition) {
callback.computed(sourcePosition);
}
});
} }
} }
catch (Exception ignore) { catch (Exception ignore) {
...@@ -167,12 +157,9 @@ public class XValueNodeImpl extends XValueContainerNode<XValue> implements XValu ...@@ -167,12 +157,9 @@ public class XValueNodeImpl extends XValueContainerNode<XValue> implements XValu
@Override @Override
public void setFullValueEvaluator(@NotNull final XFullValueEvaluator fullValueEvaluator) { public void setFullValueEvaluator(@NotNull final XFullValueEvaluator fullValueEvaluator) {
invokeNodeUpdate(new Runnable() { invokeNodeUpdate(() -> {
@Override myFullValueEvaluator = fullValueEvaluator;
public void run() { fireNodeChanged();
myFullValueEvaluator = fullValueEvaluator;
fireNodeChanged();
}
}); });
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment