use of com.sun.jdi.Value in project che by eclipse.
the class Evaluator method operation.
public ExpressionValue operation(ExpressionValue leftExpression, ExpressionValue rightExpression, int op) {
if (JavaParser.ASSIGN == op) {
leftExpression.setValue(rightExpression.getValue());
return leftExpression;
}
Value leftValue = leftExpression.getValue();
Value rightValue = rightExpression.getValue();
if (leftValue instanceof StringReference || rightValue instanceof StringReference) {
if (JavaParser.PLUS == op) {
return value(valueToString(leftValue) + valueToString(rightValue));
}
}
if (leftValue instanceof ObjectReference || rightValue instanceof ObjectReference) {
switch(op) {
case JavaParser.EQUAL:
return value(leftValue != null ? leftValue.equals(rightValue) : rightValue == null);
case JavaParser.NOT_EQUAL:
return value(!(leftValue != null ? leftValue.equals(rightValue) : rightValue == null));
default:
throw new ExpressionException("Unsupported operation " + JavaParser.tokenNames[op] + " for " + leftValue + " and " + rightValue);
}
}
if (leftValue == null || rightValue == null) {
// Neither one is object and operation is not assignation.
throw new ExpressionException("Unsupported operation " + JavaParser.tokenNames[op] + " for " + leftValue + " and " + rightValue);
}
PrimitiveValue lp = (PrimitiveValue) leftValue;
PrimitiveValue rp = (PrimitiveValue) rightValue;
if (lp instanceof BooleanValue && rp instanceof BooleanValue) {
switch(op) {
case JavaParser.LOGICAL_AND:
return value(lp.booleanValue() && rp.booleanValue());
case JavaParser.LOGICAL_OR:
return value(lp.booleanValue() || rp.booleanValue());
case JavaParser.EQUAL:
return value(lp.booleanValue() == rp.booleanValue());
case JavaParser.NOT_EQUAL:
return value(lp.booleanValue() != rp.booleanValue());
case JavaParser.OR:
return value(lp.booleanValue() | rp.booleanValue());
case JavaParser.XOR:
return value(lp.booleanValue() ^ rp.booleanValue());
case JavaParser.AND:
return value(lp.booleanValue() & rp.booleanValue());
case JavaParser.OR_ASSIGN:
leftExpression.setValue(vm.mirrorOf(lp.booleanValue() | rp.booleanValue()));
return leftExpression;
case JavaParser.XOR_ASSIGN:
leftExpression.setValue(vm.mirrorOf(lp.booleanValue() ^ rp.booleanValue()));
return leftExpression;
case JavaParser.AND_ASSIGN:
leftExpression.setValue(vm.mirrorOf(lp.booleanValue() & rp.booleanValue()));
return leftExpression;
default:
throw new ExpressionException("Unsupported operation " + JavaParser.tokenNames[op] + " for " + leftValue + " and " + rightValue);
}
}
switch(op) {
case JavaParser.EQUAL:
return value(lp.doubleValue() == rp.doubleValue());
case JavaParser.NOT_EQUAL:
return value(lp.doubleValue() != rp.doubleValue());
case JavaParser.GREATER_THAN:
return value(lp.doubleValue() > rp.doubleValue());
case JavaParser.LESS_THAN:
return value(lp.doubleValue() < rp.doubleValue());
case JavaParser.GREATER_OR_EQUAL:
return value(lp.doubleValue() >= rp.doubleValue());
case JavaParser.LESS_OR_EQUAL:
return value(lp.doubleValue() <= rp.doubleValue());
}
if (lp instanceof DoubleValue || rp instanceof DoubleValue) {
switch(op) {
case JavaParser.PLUS:
return value(lp.doubleValue() + rp.doubleValue());
case JavaParser.MINUS:
return value(lp.doubleValue() - rp.doubleValue());
case JavaParser.STAR:
return value(lp.doubleValue() * rp.doubleValue());
case JavaParser.DIV:
return value(lp.doubleValue() / rp.doubleValue());
case JavaParser.MOD:
return value(lp.doubleValue() % rp.doubleValue());
case JavaParser.PLUS_ASSIGN:
leftExpression.setValue(vm.mirrorOf(lp.doubleValue() + rp.doubleValue()));
return leftExpression;
case JavaParser.MINUS_ASSIGN:
leftExpression.setValue(vm.mirrorOf(lp.doubleValue() - rp.doubleValue()));
return leftExpression;
case JavaParser.STAR_ASSIGN:
leftExpression.setValue(vm.mirrorOf(lp.doubleValue() * rp.doubleValue()));
return leftExpression;
case JavaParser.DIV_ASSIGN:
leftExpression.setValue(vm.mirrorOf(lp.doubleValue() / rp.doubleValue()));
return leftExpression;
case JavaParser.MOD_ASSIGN:
leftExpression.setValue(vm.mirrorOf(lp.doubleValue() % rp.doubleValue()));
return leftExpression;
default:
throw new ExpressionException("Unsupported operation " + JavaParser.tokenNames[op] + " for " + leftValue + " and " + rightValue);
}
}
if (lp instanceof FloatValue || rp instanceof FloatValue) {
switch(op) {
case JavaParser.PLUS:
return value(lp.floatValue() + rp.floatValue());
case JavaParser.MINUS:
return value(lp.floatValue() - rp.floatValue());
case JavaParser.STAR:
return value(lp.floatValue() * rp.floatValue());
case JavaParser.DIV:
return value(lp.floatValue() / rp.floatValue());
case JavaParser.MOD:
return value(lp.floatValue() % rp.floatValue());
case JavaParser.PLUS_ASSIGN:
leftExpression.setValue(vm.mirrorOf(lp.floatValue() + rp.floatValue()));
return leftExpression;
case JavaParser.MINUS_ASSIGN:
leftExpression.setValue(vm.mirrorOf(lp.floatValue() - rp.floatValue()));
return leftExpression;
case JavaParser.STAR_ASSIGN:
leftExpression.setValue(vm.mirrorOf(lp.floatValue() * rp.longValue()));
return leftExpression;
case JavaParser.DIV_ASSIGN:
leftExpression.setValue(vm.mirrorOf(lp.floatValue() / rp.floatValue()));
return leftExpression;
case JavaParser.MOD_ASSIGN:
leftExpression.setValue(vm.mirrorOf(lp.floatValue() % rp.floatValue()));
return leftExpression;
default:
throw new ExpressionException("Unsupported operation " + JavaParser.tokenNames[op] + " for " + leftValue + " and " + rightValue);
}
}
if (lp instanceof LongValue || rp instanceof LongValue) {
switch(op) {
case JavaParser.PLUS:
return value(lp.longValue() + rp.longValue());
case JavaParser.MINUS:
return value(lp.longValue() - rp.longValue());
case JavaParser.STAR:
return value(lp.longValue() * rp.longValue());
case JavaParser.DIV:
return value(lp.longValue() / rp.longValue());
case JavaParser.MOD:
return value(lp.longValue() % rp.longValue());
case JavaParser.SHIFT_LEFT:
return value(lp.longValue() << rp.longValue());
case JavaParser.SHIFT_RIGHT:
return value(lp.longValue() >> rp.longValue());
case JavaParser.BIT_SHIFT_RIGHT:
return value(lp.longValue() >>> rp.longValue());
case JavaParser.OR:
return value(lp.longValue() | rp.longValue());
case JavaParser.XOR:
return value(lp.longValue() ^ rp.longValue());
case JavaParser.AND:
return value(lp.longValue() & rp.longValue());
case JavaParser.PLUS_ASSIGN:
leftExpression.setValue(vm.mirrorOf(lp.longValue() + rp.longValue()));
return leftExpression;
case JavaParser.MINUS_ASSIGN:
leftExpression.setValue(vm.mirrorOf(lp.longValue() - rp.longValue()));
return leftExpression;
case JavaParser.STAR_ASSIGN:
leftExpression.setValue(vm.mirrorOf(lp.longValue() * rp.longValue()));
return leftExpression;
case JavaParser.DIV_ASSIGN:
leftExpression.setValue(vm.mirrorOf(lp.longValue() / rp.longValue()));
return leftExpression;
case JavaParser.OR_ASSIGN:
leftExpression.setValue(vm.mirrorOf(lp.longValue() | rp.longValue()));
return leftExpression;
case JavaParser.XOR_ASSIGN:
leftExpression.setValue(vm.mirrorOf(lp.longValue() ^ rp.longValue()));
return leftExpression;
case JavaParser.AND_ASSIGN:
leftExpression.setValue(vm.mirrorOf(lp.longValue() & rp.longValue()));
return leftExpression;
case JavaParser.SHIFT_LEFT_ASSIGN:
leftExpression.setValue(vm.mirrorOf(lp.longValue() << rp.longValue()));
return leftExpression;
case JavaParser.SHIFT_RIGHT_ASSIGN:
leftExpression.setValue(vm.mirrorOf(lp.longValue() >> rp.longValue()));
return leftExpression;
case JavaParser.BIT_SHIFT_RIGHT_ASSIGN:
leftExpression.setValue(vm.mirrorOf(lp.longValue() >>> rp.longValue()));
return leftExpression;
default:
throw new ExpressionException("Unsupported operation " + JavaParser.tokenNames[op] + " for " + leftValue + " and " + rightValue);
}
}
switch(op) {
case JavaParser.PLUS:
return value(lp.intValue() + rp.intValue());
case JavaParser.MINUS:
return value(lp.intValue() - rp.intValue());
case JavaParser.STAR:
return value(lp.intValue() * rp.intValue());
case JavaParser.DIV:
return value(lp.intValue() / rp.intValue());
case JavaParser.MOD:
return value(lp.intValue() % rp.intValue());
case JavaParser.SHIFT_LEFT:
return value(lp.intValue() << rp.intValue());
case JavaParser.SHIFT_RIGHT:
return value(lp.intValue() >> rp.intValue());
case JavaParser.BIT_SHIFT_RIGHT:
return value(lp.intValue() >>> rp.intValue());
case JavaParser.OR:
return value(lp.intValue() | rp.intValue());
case JavaParser.XOR:
return value(lp.intValue() ^ rp.intValue());
case JavaParser.AND:
return value(lp.intValue() & rp.intValue());
case JavaParser.PLUS_ASSIGN:
leftExpression.setValue(vm.mirrorOf(lp.intValue() + rp.intValue()));
return leftExpression;
case JavaParser.MINUS_ASSIGN:
leftExpression.setValue(vm.mirrorOf(lp.intValue() - rp.intValue()));
return leftExpression;
case JavaParser.STAR_ASSIGN:
leftExpression.setValue(vm.mirrorOf(lp.intValue() * rp.intValue()));
return leftExpression;
case JavaParser.DIV_ASSIGN:
leftExpression.setValue(vm.mirrorOf(lp.intValue() / rp.intValue()));
return leftExpression;
case JavaParser.OR_ASSIGN:
leftExpression.setValue(vm.mirrorOf(lp.intValue() | rp.intValue()));
return leftExpression;
case JavaParser.XOR_ASSIGN:
leftExpression.setValue(vm.mirrorOf(lp.intValue() ^ rp.intValue()));
return leftExpression;
case JavaParser.AND_ASSIGN:
leftExpression.setValue(vm.mirrorOf(lp.intValue() & rp.intValue()));
return leftExpression;
case JavaParser.SHIFT_LEFT_ASSIGN:
leftExpression.setValue(vm.mirrorOf(lp.intValue() << rp.intValue()));
return leftExpression;
case JavaParser.SHIFT_RIGHT_ASSIGN:
leftExpression.setValue(vm.mirrorOf(lp.intValue() >> rp.intValue()));
return leftExpression;
case JavaParser.BIT_SHIFT_RIGHT_ASSIGN:
leftExpression.setValue(vm.mirrorOf(lp.intValue() >>> rp.intValue()));
return leftExpression;
default:
throw new ExpressionException("Unsupported operation " + JavaParser.tokenNames[op] + " for " + leftValue + " and " + rightValue);
}
}
use of com.sun.jdi.Value in project gravel by gravel-st.
the class VMTargetRemoteTest method testEvaluate.
@Test
public void testEvaluate() throws Throwable {
ObjectReference promise = remote.evaluateForked("3+4");
ThreadReference thread = ((ThreadReference) remote.invokeMethod(promise, "thread"));
Value result1 = remote.invokeMethod(promise, "result");
Value ex = remote.invokeMethod(promise, "throwable");
printThreadState();
VMTargetStarter.sleep(100);
printThreadState();
boolean isFinished = ((BooleanValue) remote.invokeMethod(promise, "isFinished")).booleanValue();
assertTrue(isFinished);
ObjectReference result = (ObjectReference) remote.invokeMethod(promise, "result");
IntegerValue intValue = (IntegerValue) remote.invokeMethod(result, "intValue");
assertEquals(7, intValue.intValue());
}
use of com.sun.jdi.Value in project gravel by gravel-st.
the class VMRemoteInstance method invoke.
private Value invoke(ObjectReference receiver, Method method, Value... arguments) throws InvalidTypeException, ClassNotLoadedException, IncompatibleThreadStateException, InvocationException {
String args = ArrayExtensions.join_with_(arguments, new Block1<String, Value>() {
@Override
public String value_(Value arg) {
return arg.toString();
}
}, ", ");
System.out.print("" + debugPort() + " Invoking " + receiver + ">>" + method.name() + "(" + args + ")");
List<ThreadReference> suspendedThreads = OrderedCollectionExtensions.select_(receiver.virtualMachine().allThreads(), new Predicate1<ThreadReference>() {
@Override
public boolean value_(ThreadReference arg1) {
return arg1.isSuspended();
}
});
Value result = receiver.invokeMethod(bootThread(), method, Arrays.asList(arguments), 0);
System.out.println(" -> " + result);
List<ThreadReference> allThreads = receiver.virtualMachine().allThreads();
for (ThreadReference threadReference : allThreads) {
if (suspendedThreads.contains(threadReference)) {
System.out.println("- Keep suspended: " + threadReference + " suspendCount: " + threadReference.suspendCount());
} else {
System.out.println("--------- Resume: " + threadReference + " suspendCount: " + threadReference.suspendCount());
threadReference.resume();
}
}
return result;
}
use of com.sun.jdi.Value in project otertool by wuntee.
the class Testing method main.
/**
* @param args
* @throws IllegalConnectorArgumentsException
* @throws IOException
* @throws InterruptedException
* @throws IncompatibleThreadStateException
* @throws AbsentInformationException
*/
@SuppressWarnings("restriction")
public static void main(String[] args) throws IOException, IllegalConnectorArgumentsException, InterruptedException, IncompatibleThreadStateException, AbsentInformationException {
SocketAttachingConnector c = (SocketAttachingConnector) getConnector();
Map<String, Connector.Argument> arguments = c.defaultArguments();
Connector.Argument hostnameArgument = arguments.get("hostname");
hostnameArgument.setValue("127.0.0.1");
Connector.Argument portArgument = arguments.get("port");
portArgument.setValue("8603");
arguments.put("hostname", hostnameArgument);
arguments.put("port", portArgument);
VirtualMachine vm = c.attach(arguments);
EventRequestManager mgr = vm.eventRequestManager();
for (com.sun.jdi.ReferenceType rt : vm.allClasses()) {
if (rt.name().toLowerCase().contains("wuntee")) {
System.out.println(rt.name());
for (Method m : rt.allMethods()) {
System.out.println(" -" + m.name());
if (m.name().contains("cache")) {
addBreakpointToMethod(m, mgr);
}
}
}
}
/* for(Method m : vm.classesByName("android.content.Intent").get(0).methodsByName("<init>")){
System.out.println("Breakpoint: " + m.toString());
Location location = m.location();
BreakpointRequest bpr = mgr.createBreakpointRequest(location);
bpr.enable();
}*/
//addIntentBreakpoints(vm);
com.sun.jdi.event.EventQueue q = vm.eventQueue();
while (true) {
EventSet es = q.remove();
Iterator<com.sun.jdi.event.Event> it = es.iterator();
while (it.hasNext()) {
com.sun.jdi.event.Event e = it.next();
BreakpointEvent bpe = (BreakpointEvent) e;
try {
System.out.println("Method: " + bpe.location().method().toString());
for (StackFrame sf : bpe.thread().frames()) {
System.out.println("Stackframe Method: " + sf.location().method().toString());
System.out.println("Arguments: ");
for (Value lv : sf.getArgumentValues()) {
System.out.println("\t--");
System.out.println("\t" + lv.toString());
}
}
} catch (Exception ex) {
System.out.println("Error: ");
ex.printStackTrace();
}
System.out.println();
vm.resume();
}
}
}
use of com.sun.jdi.Value in project intellij-community by JetBrains.
the class ValueHint method createValueHint.
public static ValueHint createValueHint(Project project, Editor editor, Point point, ValueHintType type) {
Trinity<PsiElement, TextRange, Value> trinity = getSelectedExpression(project, editor, point, type);
final ValueHint hint = new ValueHint(project, editor, point, type, trinity.getFirst(), trinity.getSecond());
hint.myValueToShow = trinity.getThird();
return hint;
}
Aggregations