use of io.flutter.inspector.DiagnosticsNode in project flutter-intellij by flutter.
the class FlutterConsoleLogManager method printDiagnosticsNodeProperty.
private void printDiagnosticsNodeProperty(ConsoleView console, String indent, DiagnosticsNode property, ConsoleViewContentType contentType, boolean isInChild) {
// TODO(devoncarew): Change the error message display in the framework.
if (property.getDescription() != null && property.getLevel() == DiagnosticLevel.info) {
// Elide framework blank styling lines.
if (StringUtil.equals("ErrorSpacer", property.getType())) {
return;
}
}
if (contentType == null) {
contentType = getContentTypeFor(property.getLevel());
}
console.print(indent, contentType);
if (property.getShowName()) {
final String name = property.getName();
console.print(name == null ? "" : name, contentType);
if (property.getShowSeparator()) {
console.print(property.getSeparator() + " ", contentType);
}
}
final String description = property.getDescription() == null ? "" : property.getDescription();
console.print(description + "\n", contentType);
if (property.hasInlineProperties()) {
String childIndent = getChildIndent(indent, property);
if (property.getStyle() == DiagnosticsTreeStyle.shallow && !indent.startsWith("...")) {
// Render properties of shallow nodes as collapesed.
childIndent = "... " + indent;
}
for (DiagnosticsNode childProperty : property.getInlineProperties()) {
printDiagnosticsNodeProperty(console, childIndent, childProperty, contentType, isInChild);
}
}
if (property.hasChildren()) {
final CompletableFuture<ArrayList<DiagnosticsNode>> future = property.getChildren();
final ArrayList<DiagnosticsNode> children = future.getNow(emptyList);
// Don't collapse children if it's just a flat list of children.
if (!isInChild && children.stream().noneMatch(DiagnosticsNode::hasChildren)) {
final String childIndent = getChildIndent(indent, property);
for (DiagnosticsNode child : children) {
printDiagnosticsNodeProperty(console, childIndent, child, contentType, false);
}
} else {
if (property.getStyle() != DiagnosticsTreeStyle.shallow) {
// For deep trees, we show the text as collapsed.
final String childIndent = isInChild ? getChildIndent(indent, property) : "... " + indent;
for (DiagnosticsNode child : children) {
printDiagnosticsNodeProperty(console, childIndent, child, contentType, true);
}
}
}
}
// Print an extra line after the summary.
if (property.getLevel() == DiagnosticLevel.summary) {
console.print("\n", contentType);
}
}
use of io.flutter.inspector.DiagnosticsNode in project flutter-intellij by flutter.
the class FlutterConsoleLogManager method processFlutterErrorEvent.
/**
* Pretty print the error using the available console syling attributes.
*/
private void processFlutterErrorEvent(@NotNull DiagnosticsNode diagnosticsNode) {
final String description = " " + diagnosticsNode.toString() + " ";
final boolean terseError = !isFirstErrorForFrame() && !FlutterSettings.getInstance().isIncludeAllStackTraces();
frameErrorCount++;
final String prefix = "========";
final String suffix = "==";
console.print("\n" + prefix, TITLE_CONTENT_TYPE);
console.print(description, NORMAL_CONTENT_TYPE);
console.print(StringUtil.repeat(errorSeparatorChar, Math.max(errorSeparatorLength - prefix.length() - description.length() - suffix.length(), 0)), TITLE_CONTENT_TYPE);
console.print(suffix + "\n", TITLE_CONTENT_TYPE);
if (terseError) {
for (DiagnosticsNode property : diagnosticsNode.getInlineProperties()) {
printTerseNodeProperty(console, "", property);
}
} else {
DiagnosticLevel lastLevel = null;
String errorSummary = null;
for (DiagnosticsNode property : diagnosticsNode.getInlineProperties()) {
// Add blank line between hint and non-hint properties.
if (lastLevel != property.getLevel()) {
if (lastLevel == DiagnosticLevel.hint || property.getLevel() == DiagnosticLevel.hint) {
console.print("\n", NORMAL_CONTENT_TYPE);
}
}
lastLevel = property.getLevel();
if (StringUtil.equals("ErrorSummary", property.getType())) {
errorSummary = property.getDescription();
} else if (StringUtil.equals("DevToolsDeepLinkProperty", property.getType()) && FlutterSettings.getInstance().isEnableEmbeddedBrowsers() && JxBrowserManager.getInstance().getStatus().equals(JxBrowserStatus.INSTALLED)) {
showDeepLinkNotification(property, errorSummary);
continue;
}
printDiagnosticsNodeProperty(console, "", property, null, false);
}
}
console.print(StringUtil.repeat(errorSeparatorChar, errorSeparatorLength) + "\n", TITLE_CONTENT_TYPE);
}
use of io.flutter.inspector.DiagnosticsNode in project flutter-intellij by flutter.
the class DiagnosticsTreeCellRenderer method customizeCellRenderer.
public void customizeCellRenderer(@NotNull final JTree tree, final Object value, final boolean selected, final boolean expanded, final boolean leaf, final int row, final boolean hasFocus) {
this.tree = tree;
this.selected = selected;
setOpaque(false);
setIconOpaque(false);
setTransparentIconBackground(true);
final Object userObject = ((DefaultMutableTreeNode) value).getUserObject();
if (userObject instanceof String) {
appendText((String) userObject, SimpleTextAttributes.GRAYED_ATTRIBUTES);
return;
}
if (!(userObject instanceof DiagnosticsNode))
return;
final DiagnosticsNode node = (DiagnosticsNode) userObject;
boolean highlight = selected;
boolean isLinkedChild = false;
// show how the trees are linked together.
if (!highlight && panel.isHighlightNodesShownInBothTrees()) {
if (panel.detailsSubtree && panel.isCreatedByLocalProject(node)) {
isLinkedChild = panel.parentTree.hasDiagnosticsValue(node.getValueRef());
} else {
if (panel.subtreePanel != null) {
isLinkedChild = panel.subtreePanel.hasDiagnosticsValue(node.getValueRef());
}
}
}
if (highlight) {
setOpaque(true);
setIconOpaque(false);
setTransparentIconBackground(true);
setBackground(HIGHLIGHT_COLOR);
// TODO(jacobr): consider using UIUtil.getTreeSelectionBackground() instead.
} else if (isLinkedChild || panel.currentShowNode == value) {
setOpaque(true);
setIconOpaque(false);
setTransparentIconBackground(true);
setBackground(panel.currentShowNode == value ? SHOW_MATCH_COLOR : LINKED_COLOR);
}
final String name = node.getName();
SimpleTextAttributes textAttributes = InspectorPanel.textAttributesForLevel(node.getLevel());
if (node.isProperty()) {
// Display of inline properties.
final String propertyType = node.getPropertyType();
final JsonObject properties = node.getValuePropertiesJson();
if (panel.isCreatedByLocalProject(node)) {
textAttributes = textAttributes.derive(SimpleTextAttributes.REGULAR_ITALIC_ATTRIBUTES.getStyle(), null, null, null);
}
if (StringUtils.isNotEmpty(name) && node.getShowName()) {
appendText(name + node.getSeparator() + " ", textAttributes);
}
String description = node.getDescription();
if (propertyType != null && properties != null) {
switch(propertyType) {
case "Color":
{
final int alpha = getIntMember(properties, "alpha");
final int red = getIntMember(properties, "red");
final int green = getIntMember(properties, "green");
final int blue = getIntMember(properties, "blue");
if (alpha == 255) {
description = String.format("#%02x%02x%02x", red, green, blue);
} else {
description = String.format("#%02x%02x%02x%02x", alpha, red, green, blue);
}
// noinspection UseJBColor
final Color color = new Color(red, green, blue, alpha);
this.addIcon(colorIconMaker.getCustomIcon(color));
this.setIconOpaque(false);
this.setTransparentIconBackground(true);
break;
}
case "IconData":
{
final int codePoint = getIntMember(properties, "codePoint");
if (codePoint > 0) {
final Icon icon = FlutterMaterialIcons.getIconForHex(String.format("%1$04x", codePoint));
if (icon != null) {
this.addIcon(icon);
this.setIconOpaque(false);
this.setTransparentIconBackground(true);
}
}
break;
}
}
}
if (SHOW_RENDER_OBJECT_PROPERTIES_AS_LINKS && propertyType.equals("RenderObject")) {
textAttributes = textAttributes.derive(SimpleTextAttributes.LINK_ATTRIBUTES.getStyle(), JBColor.blue, null, null);
}
// TODO(jacobr): custom display for units, iterables, and padding.
appendText(description, textAttributes);
if (node.getLevel().equals(DiagnosticLevel.fine) && node.hasDefaultValue()) {
appendText(" ", textAttributes);
this.addIcon(panel.defaultIcon);
}
} else {
// Non property, regular node case.
if (StringUtils.isNotEmpty(name) && node.getShowName() && !name.equals("child")) {
if (name.startsWith("child ")) {
appendText(name, SimpleTextAttributes.GRAYED_ATTRIBUTES);
} else {
appendText(name, textAttributes);
}
if (node.getShowSeparator()) {
appendText(node.getSeparator(), SimpleTextAttributes.GRAY_ATTRIBUTES);
} else {
appendText(" ", SimpleTextAttributes.GRAY_ATTRIBUTES);
}
}
if (panel.detailsSubtree && panel.isCreatedByLocalProject(node) && !panel.isHighlightNodesShownInBothTrees()) {
textAttributes = textAttributes.derive(SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES.getStyle(), null, null, null);
}
final String description = node.getDescription();
final Matcher match = primaryDescriptionPattern.matcher(description);
if (match.matches()) {
appendText(" ", SimpleTextAttributes.GRAY_ATTRIBUTES);
appendText(match.group(1), textAttributes);
appendText(" ", textAttributes);
appendText(match.group(2), SimpleTextAttributes.GRAYED_ATTRIBUTES);
} else if (!node.getDescription().isEmpty()) {
appendText(" ", SimpleTextAttributes.GRAY_ATTRIBUTES);
appendText(node.getDescription(), textAttributes);
}
// TODO(devoncarew): For widgets that are definied in the current project, we could consider
// appending the relative path to the defining library ('lib/src/foo_page.dart').
final Icon icon = node.getIcon();
if (icon != null) {
setIcon(icon);
}
}
}
use of io.flutter.inspector.DiagnosticsNode in project flutter-intellij by flutter.
the class FlutterConsoleLogManager method printTerseNodeProperty.
private void printTerseNodeProperty(ConsoleView console, String indent, DiagnosticsNode property) {
boolean skip = true;
if (property.getLevel() == DiagnosticLevel.summary) {
skip = false;
} else if (property.hasChildren()) {
final CompletableFuture<ArrayList<DiagnosticsNode>> future = property.getChildren();
final ArrayList<DiagnosticsNode> children = future.getNow(emptyList);
if (children.stream().noneMatch(DiagnosticsNode::hasChildren)) {
skip = false;
}
}
if (skip) {
return;
}
final ConsoleViewContentType contentType = getContentTypeFor(property.getLevel());
console.print(indent, contentType);
if (property.getShowName()) {
console.print(property.getName(), contentType);
if (property.getShowSeparator()) {
console.print(property.getSeparator() + " ", contentType);
}
}
final String description = property.getDescription() == null ? "" : property.getDescription();
console.print(description + "\n", contentType);
final String childIndent = getChildIndent(indent, property);
if (property.hasInlineProperties()) {
for (DiagnosticsNode childProperty : property.getInlineProperties()) {
printDiagnosticsNodeProperty(console, childIndent, childProperty, contentType, false);
}
}
if (property.hasChildren()) {
final CompletableFuture<ArrayList<DiagnosticsNode>> future = property.getChildren();
final ArrayList<DiagnosticsNode> children = future.getNow(emptyList);
for (DiagnosticsNode child : children) {
printDiagnosticsNodeProperty(console, childIndent, child, contentType, false);
}
}
}
use of io.flutter.inspector.DiagnosticsNode in project flutter-intellij by flutter.
the class InspectorTreeMouseListener method mouseMoved.
@Override
public void mouseMoved(MouseEvent event) {
calculateTooltip(event);
final DefaultMutableTreeNode treeNode = getTreeNode(event);
final DiagnosticsNode node = TreeUtils.maybeGetDiagnostic(treeNode);
if (node != null && !node.isProperty()) {
if (panel.detailsSubtree && panel.isCreatedByLocalProject(node)) {
panel.parentTree.highlightShowNode(node.getValueRef());
} else if (panel.subtreePanel != null) {
panel.subtreePanel.highlightShowNode(node.getValueRef());
}
panel.highlightShowNode(treeNode);
}
}
Aggregations