本文整理汇总了Java中org.eclipse.jdt.debug.core.IJavaValue类的典型用法代码示例。如果您正苦于以下问题:Java IJavaValue类的具体用法?Java IJavaValue怎么用?Java IJavaValue使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IJavaValue类属于org.eclipse.jdt.debug.core包,在下文中一共展示了IJavaValue类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getAllReachableObjects
import org.eclipse.jdt.debug.core.IJavaValue; //导入依赖的package包/类
private Set<IJavaObject> getAllReachableObjects(SubMonitor monitor) {
try {
Set<IJavaObject> objs = new HashSet<IJavaObject>();
getReachableObjects(stack.getThis(), objs);
for (IVariable var: stack.getLocalVariables())
getReachableObjects((IJavaValue)var.getValue(), objs);
for (ReferenceType type: getAllLoadedTypes(stack)) {
for (Field field: type.allFields())
if (field.isStatic() && isUsefulStaticDFSField(type.name(), field))
getReachableObjects(JDIValue.createValue((JDIDebugTarget)stack.getDebugTarget(), type.getValue(field)), objs);
monitor.worked(1);
}
return objs;
} catch (DebugException e) {
throw new RuntimeException(e);
}
}
示例2: valueToString
import org.eclipse.jdt.debug.core.IJavaValue; //导入依赖的package包/类
private String valueToString(IJavaValue value) {
if(value instanceof IJavaArray) {
try {
IJavaArray array = (IJavaArray) value;
IJavaValue[] values = array.getValues();
String s = "";
for(int i = 0; i < values.length; i++) {
if(!s.isEmpty())
s += ", ";
s += valueSpecialChars(values[i]);
}
return "{" + s + "}";
}
catch (DebugException e) {
e.printStackTrace();
return null;
}
}
else
return valueSpecialChars(value);
}
示例3: valueSpecialChars
import org.eclipse.jdt.debug.core.IJavaValue; //导入依赖的package包/类
private String valueSpecialChars(IJavaValue value) {
try {
if(value.getReferenceTypeName().equals("char"))
return "'" + value.getValueString() + "'";
if(value.getReferenceTypeName().equals(String.class.getName()))
return "\"" + value.getValueString() + "\"";
if(value instanceof IJavaObject) {
if(((IJavaObject) value).isNull())
return "null";
else
return runtime.getObject((IJavaObject) value, false, null).toString();
}
return value.getValueString();
}
catch (DebugException e) {
e.printStackTrace();
return null;
}
}
示例4: readFImage
import org.eclipse.jdt.debug.core.IJavaValue; //导入依赖的package包/类
FImage readFImage(IJavaObject var) throws DebugException {
int width = ((IJavaPrimitiveValue)var.getField("width", true).getValue()).getIntValue();
int height = ((IJavaPrimitiveValue)var.getField("height", true).getValue()).getIntValue();
IJavaValue[] data = ((IJavaArray)var.getField("pixels", false).getValue()).getValues();
FImage img = new FImage(width, height);
for (int y=0; y<height; y++) {
IJavaValue[] row = ((IJavaArray) data[y]).getValues();
for (int x=0; x<width; x++) {
img.pixels[y][x] = ((IJavaPrimitiveValue) row[x]).getFloatValue();
}
}
return img;
}
示例5: getArrayElement
import org.eclipse.jdt.debug.core.IJavaValue; //导入依赖的package包/类
@Override
protected Integer getArrayElement(int i) {
try {
IJavaValue val = exp.getValue().getValue(i);
if (field == null) {
return ((JDIPrimitiveValue)val).getIntValue();
}
else {
Value fieldVal = ((JDIObjectValue)val).getUnderlyingObject().getValue(field);
return ((PrimitiveValue)fieldVal).intValue();
}
} catch (DebugException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}
}
示例6: displayResult
import org.eclipse.jdt.debug.core.IJavaValue; //导入依赖的package包/类
@Override
protected void displayResult(final IEvaluationResult result) {
final Shell shell = JDIDebugUIPlugin.getShell();
shell.getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
MessageBox mb = new MessageBox(shell, SWT.OK);
mb.setText("Visualize Variable History:");
IJavaValue value = result.getValue();
if (value instanceof IJavaArray) {
ArraysMainController.addExpression(new ArrayExpression(result.getSnippet(), (IJavaArray)value));
}
}
});
}
示例7: cleanupWindows
import org.eclipse.jdt.debug.core.IJavaValue; //导入依赖的package包/类
private void cleanupWindows() {
try {
if (awtWindows != null) {
IJavaValue[] newWindows = getAWTWindows();
for (IJavaValue newWindow: newWindows) {
if (!contains(awtWindows, newWindow)) {
//System.out.println("Killing AWT window " + newWindow);
((IJavaObject)newWindow).sendMessage("dispose", "()V", new IJavaValue[] { }, thread, null);
}
}
}
if (swtShells != null) {
IJavaValue[] newShells = getSWTShells();
for (IJavaValue newShell: newShells) {
if (!contains(swtShells, newShell)) {
//System.out.println("Killing SWT shell " + newShell);
((IJavaObject)newShell).sendMessage("dispose", "()V", new IJavaValue[] { }, thread, null);
// Without the update message the shells won't actually close.
((IJavaObject)swtDefaultDisplay).sendMessage("update", "()V", new IJavaValue[] { }, thread, null);
}
}
}
} catch (DebugException e) {
throw new RuntimeException(e);
}
}
示例8: getNumNulls
import org.eclipse.jdt.debug.core.IJavaValue; //导入依赖的package包/类
/**
* Finds the number of subexpressions of the
* given expression that are known to be null.
* @param expr The expression to search.
* @return The number of subexpressions of the
* given expression known to be null.
*/
private int getNumNulls(Expression expr) {
final int[] numNulls = new int[] { 0 };
expr.accept(new ASTVisitor() {
private Set<Effect> curEffects = Collections.<Effect>emptySet();
@Override
public void postVisit(ASTNode node) {
if (node instanceof Expression) {
if (node instanceof NullLiteral)
numNulls[0]++;
else {
Result result = expressionEvaluator.getResult((Expression)node, curEffects);
if (result == null || result.getValue() == null) // TODO: result is null for method/constructor names or crashed native calls or after side effects during refinement.
return;
IJavaValue value = result.getValue().getValue();
if (value != null && value.isNull())
numNulls[0]++;
curEffects = result.getEffects();
}
}
}
});
return numNulls[0];
}
示例9: getHashCode
import org.eclipse.jdt.debug.core.IJavaValue; //导入依赖的package包/类
protected int getHashCode(IJavaValue value) throws DebugException {
if (value == null || value.isNull())
return -37;
else if (value instanceof IJavaPrimitiveValue)
return ((IJavaPrimitiveValue)value).getIntValue() * 5 + 137; // We add a number to avoid clustering around 0.
else if (value instanceof IJavaArray) { // Heuristically only look at the array's length and its first ten elements.
IJavaArray array = (IJavaArray)value;
int length = array.getLength();
int hashCode = length * 5 + array.getSignature().hashCode() * 7;
for (int i = 0; i < 10 && i < length; i++)
hashCode = 31 * hashCode + getHashCode(array.getValue(i));
return hashCode;
} else if (value instanceof IJavaClassObject)
return ((IJavaClassObject)value).getInstanceType().getName().hashCode() * 11;
else if ("V".equals(value.getSignature()))
return -137;
else {
IJavaObject obj = (IJavaObject)value;
if ("Ljava/lang/String;".equals(obj.getSignature())) // Fast-path Strings
return obj.toString().hashCode();
return ((IJavaPrimitiveValue)obj.sendMessage("hashCode", "()I", new IJavaValue[] { }, thread, null)).getIntValue();
}
}
示例10: getReachableObjects
import org.eclipse.jdt.debug.core.IJavaValue; //导入依赖的package包/类
private void getReachableObjects(IJavaValue value, Set<IJavaObject> objs) throws DebugException {
if (value instanceof IJavaArray) {
IJavaArray arr = (IJavaArray)value;
if (objs.add(arr) && !EclipseUtils.isPrimitive(Signature.getElementType(arr.getSignature())) && !arr.getSignature().equals("[Ljava/lang/String;"))
for (IJavaValue elem: arr.getValues())
getReachableObjects(elem, objs);
} else if (value instanceof IJavaObject) {
IJavaObject obj = (IJavaObject)value;
if (objs.add(obj)) {
// We use the internal API here because the Eclipse one must get each field's value one-by-one and so is much slower.
ObjectReference obj2 = ((JDIObjectValue)obj).getUnderlyingObject();
if (obj2 != null) // null values fail this test
for (Map.Entry<Field, Value> field: obj2.getValues(obj2.referenceType().allFields()).entrySet())
if (isUsefulStaticDFSField(field.getKey().declaringType().name(), field.getKey()))
getReachableObjects(JDIValue.createValue((JDIDebugTarget)stack.getDebugTarget(), field.getValue()), objs);
}
}
}
示例11: fillInstanceof
import org.eclipse.jdt.debug.core.IJavaValue; //导入依赖的package包/类
/**
* Fills instanceof skeleton pieces.
* @param instance The instanceof part of the skeleton.
* @param parentsOfHoles All nodes that are parents of some hole.
* @return The synthesized expressions corresponding to this
* skeleton piece and the type constraint representing their types.
*/
private ExpressionsAndTypeConstraints fillInstanceof(InstanceofExpression instance, Set<ASTNode> parentsOfHoles) {
try {
codehint.ast.Type rightOperand = ASTConverter.copy(instance.getRightOperand());
IJavaType targetType = EclipseUtils.getType(instance.getRightOperand().toString(), stack, target, typeCache);
rightOperand.setStaticType(targetType);
ExpressionsAndTypeConstraints exprResult = fillSkeleton(instance.getLeftOperand(), new SameHierarchy(targetType), parentsOfHoles);
Map<String, ArrayList<codehint.ast.Expression>> resultExprs = new HashMap<String, ArrayList<codehint.ast.Expression>>(exprResult.getExprs().size());
for (Map.Entry<String, ArrayList<codehint.ast.Expression>> res: exprResult.getExprs().entrySet())
for (codehint.ast.Expression expr: res.getValue()) {
IJavaValue exprValue = expressionEvaluator.getValue(expr, Collections.<Effect>emptySet());
Utils.addToListMap(resultExprs, res.getKey(), expressionMaker.makeInstanceOf(expr, rightOperand, booleanType, exprValue == null ? null : valueCache.getBooleanJavaValue(!exprValue.isNull() && subtypeChecker.isSubtypeOf(exprValue.getJavaType(), targetType))));
}
return new ExpressionsAndTypeConstraints(resultExprs, new SupertypeBound(booleanType));
} catch (DebugException e) {
throw new RuntimeException(e);
}
}
示例12: fillNumberLiteral
import org.eclipse.jdt.debug.core.IJavaValue; //导入依赖的package包/类
/**
* Fills number literal skeleton pieces.
* @param node The number literal part of the skeleton.
* @return The synthesized expressions corresponding to this
* skeleton piece and the type constraint representing their types.
*/
private ExpressionsAndTypeConstraints fillNumberLiteral(Expression node) {
String str = ((NumberLiteral)node).getToken();
int lastChar = str.charAt(str.length() - 1);
// Rules taken from: http://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html.
IJavaType resultType = null;
IJavaValue value = null;
if (lastChar == 'l' || lastChar == 'L') {
resultType = EclipseUtils.getFullyQualifiedType("long", stack, target, typeCache);
value = target.newValue(Long.parseLong(str));
} else if (lastChar == 'f' || lastChar == 'f') {
resultType = EclipseUtils.getFullyQualifiedType("float", stack, target, typeCache);
value = target.newValue(Float.parseFloat(str));
} else if (lastChar == 'd' || lastChar == 'd' || str.indexOf('.') != -1) {
resultType = EclipseUtils.getFullyQualifiedType("double", stack, target, typeCache);
value = target.newValue(Double.parseDouble(str));
} else {
resultType = intType;
value = target.newValue(Integer.parseInt(str));
}
return new ExpressionsAndTypeConstraints(expressionMaker.makeNumber(str, value, resultType, thread), new SupertypeBound(resultType));
}
示例13: makeAllCalls
import org.eclipse.jdt.debug.core.IJavaValue; //导入依赖的package包/类
/**
* Creates all possible calls using the given actuals.
* @param method The method being called.
* @param name The method name.
* @param constraintName The name of the return type of the method, which
* is used to store the resulting expressions.
* @param receiver The receiving object.
* @param callNode The node representing the call piece of the skeleton.
* @param returnType The return type of the function.
* @param thisType The type of the this object.
* @param possibleActuals A list of all the possible actuals for each argument.
* @param curActuals The current list of actuals, which is built
* up through recursion.
* @param resultExprs The map that stores the resulting expressions.
* @param monitor The progress monitor.
* @throws DebugException
*/
private void makeAllCalls(Method method, String name, String constraintName, codehint.ast.Expression receiver, Expression callNode, IJavaType returnType, IJavaType thisType, ArrayList<ArrayList<codehint.ast.Expression>> possibleActuals, ArrayList<codehint.ast.Expression> curActuals, Map<String, ArrayList<codehint.ast.Expression>> resultExprs, IProgressMonitor monitor) throws DebugException {
if (monitor.isCanceled())
throw new OperationCanceledException();
if (curActuals.size() == possibleActuals.size()) {
codehint.ast.Expression callExpr = null;
if (callNode instanceof SuperMethodInvocation)
callExpr = expressionMaker.makeSuperCall(name, ASTConverter.copy(((SuperMethodInvocation)callNode).getQualifier()), curActuals, returnType, null, method);
else
callExpr = expressionMaker.makeCall(name, receiver, curActuals, returnType, thisType, method, thread, staticEvaluator);
IJavaValue callValue = expressionEvaluator.getValue(callExpr, Collections.<Effect>emptySet());
if (callValue == null || !"V".equals(callValue.getSignature()))
Utils.addToListMap(resultExprs, constraintName, callExpr);
monitor.worked(1);
} else {
int argNum = curActuals.size();
for (codehint.ast.Expression e : possibleActuals.get(argNum)) {
curActuals.add(e);
makeAllCalls(method, name, constraintName, receiver, callNode, returnType, thisType, possibleActuals, curActuals, resultExprs, monitor);
curActuals.remove(argNum);
}
}
}
示例14: computeInfixOp
import org.eclipse.jdt.debug.core.IJavaValue; //导入依赖的package包/类
Value computeInfixOp(IJavaValue left, InfixExpression.Operator op, IJavaValue right, IJavaType type) throws DebugException {
try {
if (EclipseUtils.isInt(type))
return computeIntInfixOp(left, op, right);
else if (EclipseUtils.isBoolean(type))
return computeBooleanInfixOp(left, op, right);
else if (EclipseUtils.isLong(type))
return computeLongInfixOp(left, op, right);
else if (type instanceof IJavaReferenceType)
return computeRefInfixOp(left, op, right);
else
throw new RuntimeException("Unexpected type: " + type);
} catch (NumberFormatException e) {
return valueCache.voidValue();
}
}
示例15: computeRefInfixOp
import org.eclipse.jdt.debug.core.IJavaValue; //导入依赖的package包/类
private Value computeRefInfixOp(IJavaValue left, InfixExpression.Operator op, IJavaValue right) throws DebugException {
if (left == null || right == null)
return null;
if (!(left instanceof IJavaObject) || !(right instanceof IJavaObject))
return valueCache.voidValue();
IJavaObject l = (IJavaObject)left;
IJavaObject r = (IJavaObject)right;
if (op == InfixExpression.Operator.EQUALS)
return valueCache.getBooleanJavaValue(l.getUniqueId() == r.getUniqueId());
if (op == InfixExpression.Operator.NOT_EQUALS)
return valueCache.getBooleanJavaValue(l.getUniqueId() != r.getUniqueId());
IJavaType lType = l.getJavaType();
IJavaType rType = r.getJavaType();
if (op == InfixExpression.Operator.PLUS && ((lType != null && "java.lang.String".equals(lType.getName())) || (rType != null && "java.lang.String".equals(rType.getName()))))
return valueCache.getStringJavaValue(l.getValueString() + r.getValueString());
throw new RuntimeException("Unknown infix operation: " + op.toString() + " for " + left.toString() + " of type " + lType.toString() + " and " + right.toString() + " of type " + rType.toString());
}