package bluej.debugmgr.inspector;
import bluej.Config;
import bluej.debugger.DebuggerField;
import bluej.debugger.DebuggerObject;
import bluej.debugger.gentype.GenTypeClass;
import bluej.debugger.gentype.GenTypeDeclTpar;
import bluej.debugger.gentype.GenTypeParameter;
import bluej.debugger.gentype.JavaType;
import bluej.debugmgr.ExpressionInformation;
import bluej.pkgmgr.Package;
import bluej.testmgr.record.InvokerRecord;
import bluej.utility.JavaUtils;
import bluej.utility.javafx.FXFormattedPrintWriter;
import bluej.utility.javafx.JavaFXUtil;
import bluej.views.Comment;
import bluej.views.MethodView;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ContextMenu;
import javafx.scene.control.Label;
import javafx.scene.input.Clipboard;
import javafx.scene.input.DataFormat;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.Pane;
import javafx.scene.layout.Region;
import javafx.scene.layout.VBox;
import javafx.scene.text.Text;
import javafx.scene.text.TextFlow;
import javafx.stage.StageStyle;
import threadchecker.OnThread;
import threadchecker.Tag;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
| A window that displays a method return value.
|
| @author Poul Henriksen
|
@OnThread(Tag.FXPlatform)
public class ResultInspector
extends Inspector{
protected final static String resultTitle = Config.getString("debugger.inspector.result.title");
protected final static String returnedString = Config.getString("debugger.inspector.result.returned");
protected DebuggerObject obj;
protected String objName;
private ExpressionInformation expressionInformation;
private JavaType resultType;
private VBox contentPane;
| Note: 'pkg' may be null if 'ir' is null.
|
| @param obj
| The object displayed by this viewer
| @param name
| The name of this object or "null" if the name is unobtainable
|* @param pkg
* The package all this belongs to
* @param ir
* the InvokerRecord explaining how we created this result/object
* if null, the "get" button is permanently disabled
* @param info
* The expression used to create the object (ie. the method call
* information)
* @param parent
* The parent frame of this frame
public ResultInspector(DebuggerObject obj, InspectorManager inspectorManager, String name,
Package pkg, InvokerRecord ir, ExpressionInformation info)
{
super(inspectorManager, pkg, ir, StageStyle.DECORATED);
expressionInformation = info;
this.obj = obj;
this.objName = name;
calcResultType();
makeFrame();
update();
}
| Determine the expected static type of the result.
|
private void calcResultType()
{
GenTypeClass instanceType = expressionInformation.getInstanceType();
MethodView methodView = (MethodView) expressionInformation.getMethodView();
Method m = methodView.getMethod();
JavaType methodReturnType = methodView.getGenericReturnType();
if (methodReturnType instanceof GenTypeParameter) {
Map<String,GenTypeParameter> tparmap;
if (instanceType != null)
tparmap = instanceType.mapToSuper(m.getDeclaringClass().getName()).getMap();
else{ tparmap = new HashMap<String,GenTypeParameter>();
}
if (tparmap == null) {
resultType = JavaUtils.getJavaUtils().getRawReturnType(m);
return;
}
List<GenTypeDeclTpar> tpars = JavaUtils.getJavaUtils().getTypeParams(m);
tparmap.putAll(JavaUtils.TParamsToMap(tpars));
methodReturnType = methodReturnType.mapTparsToTypes(tparmap).getUpperBound();
}
resultType = methodReturnType;
}
@Override
protected boolean shouldAutoUpdate()
{
return false;
}
| Returns a single string representing the return value.
|
@Override
@OnThread(Tag.FXPlatform)
protected List getListData()
{
String fieldString;
DebuggerField resultField = obj.getField(0);
if (!resultType.isPrimitive()) {
DebuggerObject resultObject = resultField.getValueObject(resultType);
if (!resultObject.isNullObject()) {
fieldString = resultObject.getGenType().toString(true);
}
else {
fieldString = resultType.toString(true);
}
}
else {
fieldString = resultField.getType().toString(true);
}
List<FieldInfo> rlist = new ArrayList<FieldInfo>(1);
rlist.add(new FieldInfo(fieldString, resultField.getValueString()));
return rlist;
}
| Build the GUI
|
| @param showAssert
| Indicates if assertions should be shown.
|
protected void makeFrame()
{
setTitle(resultTitle);
Pane header = new VBox();
Comment comment = expressionInformation.getComment();
FXFormattedPrintWriter commentLabelPrintWriter = new FXFormattedPrintWriter();
comment.print(commentLabelPrintWriter);
Node commentLabel = commentLabelPrintWriter.getNode();
header.getChildren().add(commentLabel);
Label sig = new Label(expressionInformation.getSignature());
header.getChildren().add(sig);
JavaFXUtil.addStyleClass(sig, "inspector-header", "inspector-result-header");
BorderPane mainPanel = new BorderPane();
VBox result = new VBox();
JavaFXUtil.addStyleClass(result, "inspector-result-details");
String expressionDisplay = expressionInformation.getExpression();
final Node expression = new TextFlow(new Text(expressionDisplay + " " + returnedString));
JavaFXUtil.addStyleClass(expression, "inspector-result-details-header");
ContextMenu copyPopup = new ContextMenu();
copyPopup.getItems().add(JavaFXUtil.makeMenuItem(Config.getString("editor.copyLabel"),() ->
{
Clipboard.getSystemClipboard().setContent(Collections.singletonMap(DataFormat.PLAIN_TEXT, expressionDisplay));
}
, null));
expression.setOnContextMenuRequested(e -> copyPopup.show(expression, e.getScreenX(), e.getScreenY()));
result.getChildren().add(expression);
result.getChildren().add(fieldList);
|
|
|Box resultPanel = new Box(BoxLayout.Y_AXIS) {} protected void paintComponent(Graphics g)
|
|{}super.paintComponent(g);
|
|Graphics2D g2d = (Graphics2D)g;
|
|int width = getWidth();
|
|int height = getHeight();
|
|Color color1 = new Color(236,235,234);
|
|Color color2 = new Color(220,218,214);
|
|if (!Config.isRaspberryPi()){} g2d.setPaint(new GradientPaint(width/4, 0, color1,
|
|width*3/4, height, color2));
|
|}else{} g2d.setPaint(new Color(228, 227, 224));
|
|}
|
|g2d.fillRect(0, 0, width, height);
|
|}
|
|};
mainPanel.setCenter(result);
mainPanel.setRight(createInspectAndGetButtons());
BorderPane buttonPanel = new BorderPane();
if (inspectorManager != null && inspectorManager.inTestMode()) {
assertPanel = new AssertPanel(resultType);
buttonPanel.setTop(assertPanel);
}
Button button = createCloseButton();
buttonPanel.setRight(button);
|
|
|JPanel contentPane = new JPanel() {} protected void paintComponent(Graphics g)
|
|{}super.paintComponent(g);
|
|Graphics2D g2d = (Graphics2D)g;
|
|int width = getWidth();
|
|int height = getHeight();
|
|Color color1 = new Color(230,229,228);
|
|Color color2 = new Color(191,186,178);
|
|if (!Config.isRaspberryPi()){} g2d.setPaint(new GradientPaint(width/4, 0, color1,
|
|width*3/4, height, color2));
|
|}else{} g2d.setPaint(new Color(214, 217, 223));
|
|}
|
|g2d.fillRect(0, 0, width, height);
|
|}
|
|};
contentPane = new VBox(header, mainPanel, buttonPanel);
JavaFXUtil.addStyleClass(contentPane, "inspector", "inspector-result");
button.setDefaultButton(true);
setScene(new Scene(contentPane));
}
@Override
public Region getContent()
{
return contentPane;
}
| An element in the field list was selected.
|
protected void listElementSelected(int slot)
{
DebuggerField field = obj.getInstanceField(0);
if (field.isReferenceType() && ! field.isNull()) {
setCurrentObj(field.getValueObject(resultType), null, resultType.toString(false));
setButtonsEnabled(true, true);
}
else {
setCurrentObj(null, null, null);
setButtonsEnabled(false, false);
}
}
@Override
protected void doInspect()
{
if (selectedField != null) {
boolean isPublic = !getButton.isDisable();
inspectorManager.getInspectorInstance(selectedField, selectedFieldName, pkg, isPublic ? ir : null, this, null);
}
}
| Remove this inspector.
|
protected void remove()
{
if (inspectorManager != null) {
inspectorManager.removeInspector(obj);
}
}
| Return a String with the result.
|
| @return The Result value
|
public String getResult()
{
DebuggerField resultField = obj.getField(0);
String result = resultField.getType() + " " + resultField.getName() + " = " + resultField.getValueString();
return result;
}
protected int getPreferredRows()
{
return 2;
}
protected void doGet()
{
if (selectedField != null) {
GenTypeClass resultClass = resultType.asClass();
pkg.getEditor().raisePutOnBenchEvent(this, selectedField, resultClass, ir, true, Optional.empty());
}
}
}
top,
use,
map,
class ResultInspector
. ResultInspector
. calcResultType
. shouldAutoUpdate
. getListData
. makeFrame
. getContent
. listElementSelected
. doInspect
. remove
. getResult
. getPreferredRows
. doGet
328 neLoCode
+ 46 LoComm