Mercurial > hg > truffle
comparison truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/instrument/impl/DefaultVisualizer.java @ 21951:9c8c0937da41
Moving all sources into truffle subdirectory
author | Jaroslav Tulach <jaroslav.tulach@oracle.com> |
---|---|
date | Wed, 17 Jun 2015 10:58:08 +0200 |
parents | graal/com.oracle.truffle.api/src/com/oracle/truffle/api/instrument/impl/DefaultVisualizer.java@894f82515e38 |
children | dc83cc1f94f2 |
comparison
equal
deleted
inserted
replaced
21950:2a5011c7e641 | 21951:9c8c0937da41 |
---|---|
1 /* | |
2 * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved. | |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. Oracle designates this | |
8 * particular file as subject to the "Classpath" exception as provided | |
9 * by Oracle in the LICENSE file that accompanied this code. | |
10 * | |
11 * This code is distributed in the hope that it will be useful, but WITHOUT | |
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
14 * version 2 for more details (a copy is included in the LICENSE file that | |
15 * accompanied this code). | |
16 * | |
17 * You should have received a copy of the GNU General Public License version | |
18 * 2 along with this work; if not, write to the Free Software Foundation, | |
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
20 * | |
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
22 * or visit www.oracle.com if you need additional information or have any | |
23 * questions. | |
24 */ | |
25 package com.oracle.truffle.api.instrument.impl; | |
26 | |
27 import com.oracle.truffle.api.*; | |
28 import com.oracle.truffle.api.frame.*; | |
29 import com.oracle.truffle.api.instrument.*; | |
30 import com.oracle.truffle.api.nodes.*; | |
31 import com.oracle.truffle.api.source.*; | |
32 | |
33 public class DefaultVisualizer implements Visualizer { | |
34 | |
35 private final ASTPrinter astPrinter; | |
36 | |
37 public DefaultVisualizer() { | |
38 this.astPrinter = new DefaultASTPrinter(); | |
39 } | |
40 | |
41 public ASTPrinter getASTPrinter() { | |
42 return astPrinter; | |
43 } | |
44 | |
45 public String displaySourceLocation(Node node) { | |
46 if (node == null) { | |
47 return "<unknown>"; | |
48 } | |
49 SourceSection section = node.getSourceSection(); | |
50 boolean estimated = false; | |
51 if (section == null) { | |
52 section = node.getEncapsulatingSourceSection(); | |
53 estimated = true; | |
54 } | |
55 if (section == null) { | |
56 return "<error: source location>"; | |
57 } | |
58 return section.getShortDescription() + (estimated ? "~" : ""); | |
59 } | |
60 | |
61 public String displayMethodName(Node node) { | |
62 if (node == null) { | |
63 return null; | |
64 } | |
65 RootNode root = node.getRootNode(); | |
66 if (root == null) { | |
67 return "unknown"; | |
68 } | |
69 return root.getCallTarget().toString(); | |
70 } | |
71 | |
72 public String displayCallTargetName(CallTarget callTarget) { | |
73 return callTarget.toString(); | |
74 } | |
75 | |
76 public String displayValue(Object value, int trim) { | |
77 return trim(value.toString(), trim); | |
78 } | |
79 | |
80 public String displayIdentifier(FrameSlot slot) { | |
81 return slot.getIdentifier().toString(); | |
82 } | |
83 | |
84 /** | |
85 * Trims text if {@code trim > 0} to the shorter of {@code trim} or the length of the first line | |
86 * of test. Identity if {@code trim <= 0}. | |
87 */ | |
88 protected String trim(String text, int trim) { | |
89 if (trim == 0) { | |
90 return text; | |
91 } | |
92 final String[] lines = text.split("\n"); | |
93 String result = lines[0]; | |
94 if (lines.length == 1) { | |
95 if (result.length() <= trim) { | |
96 return result; | |
97 } | |
98 if (trim <= 3) { | |
99 return result.substring(0, Math.min(result.length() - 1, trim - 1)); | |
100 } else { | |
101 return result.substring(0, trim - 4) + "..."; | |
102 } | |
103 } | |
104 return (result.length() < trim - 3 ? result : result.substring(0, trim - 4)) + "..."; | |
105 } | |
106 } |