From 80db47d30278771179259eae24a81984c26ad1f6 Mon Sep 17 00:00:00 2001 From: "Egor.Ushakov" Date: Mon, 27 Jun 2016 18:38:47 +0300 Subject: [PATCH] added generics --- .../debugger/engine/DebugProcessImpl.java | 69 +++++++++---------- .../expression/NewClassInstanceEvaluator.java | 23 ++++--- .../debugger/engine/DebugProcess.java | 10 +-- 3 files changed, 52 insertions(+), 50 deletions(-) diff --git a/java/debugger/impl/src/com/intellij/debugger/engine/DebugProcessImpl.java b/java/debugger/impl/src/com/intellij/debugger/engine/DebugProcessImpl.java index 98fc469477bf..7ee567d0d4df 100644 --- a/java/debugger/impl/src/com/intellij/debugger/engine/DebugProcessImpl.java +++ b/java/debugger/impl/src/com/intellij/debugger/engine/DebugProcessImpl.java @@ -894,23 +894,18 @@ public abstract class DebugProcessImpl extends UserDataHolderBase implements Deb private abstract class InvokeCommand { private final Method myMethod; - private final List myArgs; + private final List myArgs; - protected InvokeCommand(@NotNull Method method, @NotNull List args) { + protected InvokeCommand(@NotNull Method method, @NotNull List args) { myMethod = method; - if (!args.isEmpty()) { - myArgs = new ArrayList(args); - } - else { - myArgs = args; - } + myArgs = new ArrayList<>(args); } public String toString() { return "INVOKE: " + super.toString(); } - protected abstract E invokeMethod(int invokePolicy, Method method, final List args) throws InvocationException, + protected abstract E invokeMethod(int invokePolicy, Method method, List args) throws InvocationException, ClassNotLoadedException, IncompatibleThreadStateException, InvalidTypeException; @@ -1145,7 +1140,10 @@ public abstract class DebugProcessImpl extends UserDataHolderBase implements Deb } @Override - public Value invokeMethod(@NotNull EvaluationContext evaluationContext, @NotNull ObjectReference objRef, @NotNull Method method, final List args) throws EvaluateException { + public Value invokeMethod(@NotNull EvaluationContext evaluationContext, + @NotNull ObjectReference objRef, + @NotNull Method method, + @NotNull List args) throws EvaluateException { return invokeInstanceMethod(evaluationContext, objRef, method, args, 0); } @@ -1153,12 +1151,12 @@ public abstract class DebugProcessImpl extends UserDataHolderBase implements Deb public Value invokeInstanceMethod(@NotNull EvaluationContext evaluationContext, @NotNull final ObjectReference objRef, @NotNull Method method, - @NotNull List args, + @NotNull List args, final int invocationOptions) throws EvaluateException { final ThreadReference thread = getEvaluationThread(evaluationContext); return new InvokeCommand(method, args) { @Override - protected Value invokeMethod(int invokePolicy, Method method, final List args) throws InvocationException, ClassNotLoadedException, IncompatibleThreadStateException, InvalidTypeException { + protected Value invokeMethod(int invokePolicy, Method method, List args) throws InvocationException, ClassNotLoadedException, IncompatibleThreadStateException, InvalidTypeException { if (LOG.isDebugEnabled()) { LOG.debug("Invoking " + objRef.type().name() + "." + method.name()); } @@ -1176,21 +1174,22 @@ public abstract class DebugProcessImpl extends UserDataHolderBase implements Deb } @Override - public Value invokeMethod(final EvaluationContext evaluationContext, final ClassType classType, - final Method method, - final List args) throws EvaluateException { + public Value invokeMethod(EvaluationContext evaluationContext, + ClassType classType, + Method method, + List args) throws EvaluateException { return invokeMethod(evaluationContext, classType, method, args, false); } public Value invokeMethod(@NotNull EvaluationContext evaluationContext, @NotNull final ClassType classType, @NotNull Method method, - @NotNull List args, + @NotNull List args, boolean internalEvaluate) throws EvaluateException { final ThreadReference thread = getEvaluationThread(evaluationContext); return new InvokeCommand(method, args) { @Override - protected Value invokeMethod(int invokePolicy, Method method, List args) throws InvocationException, + protected Value invokeMethod(int invokePolicy, Method method, List args) throws InvocationException, ClassNotLoadedException, IncompatibleThreadStateException, InvalidTypeException { @@ -1207,14 +1206,14 @@ public abstract class DebugProcessImpl extends UserDataHolderBase implements Deb assert Patches.USE_REFLECTION_TO_ACCESS_JDK8; } - public Value invokeMethod(final EvaluationContext evaluationContext, - final InterfaceType interfaceType, - final Method method, - final List args) throws EvaluateException { + public Value invokeMethod(EvaluationContext evaluationContext, + InterfaceType interfaceType, + Method method, + List args) throws EvaluateException { final ThreadReference thread = getEvaluationThread(evaluationContext); return new InvokeCommand(method, args) { @Override - protected Value invokeMethod(int invokePolicy, Method method, List args) throws InvocationException, + protected Value invokeMethod(int invokePolicy, Method method, List args) throws InvocationException, ClassNotLoadedException, IncompatibleThreadStateException, InvalidTypeException { @@ -1257,11 +1256,11 @@ public abstract class DebugProcessImpl extends UserDataHolderBase implements Deb public ObjectReference newInstance(@NotNull final EvaluationContext evaluationContext, @NotNull final ClassType classType, @NotNull Method method, - @NotNull List args) throws EvaluateException { + @NotNull List args) throws EvaluateException { final ThreadReference thread = getEvaluationThread(evaluationContext); InvokeCommand invokeCommand = new InvokeCommand(method, args) { @Override - protected ObjectReference invokeMethod(int invokePolicy, Method method, List args) throws InvocationException, + protected ObjectReference invokeMethod(int invokePolicy, Method method, List args) throws InvocationException, ClassNotLoadedException, IncompatibleThreadStateException, InvalidTypeException { @@ -1395,28 +1394,24 @@ public abstract class DebugProcessImpl extends UserDataHolderBase implements Deb qName = reformatArrayName(qName); ReferenceType refType = null; VirtualMachineProxyImpl virtualMachine = getVirtualMachineProxy(); - final List classClasses = virtualMachine.classesByName("java.lang.Class"); - if (!classClasses.isEmpty()) { - ClassType classClassType = (ClassType)classClasses.get(0); + ClassType classClassType = (ClassType)ContainerUtil.getFirstItem(virtualMachine.classesByName(CommonClassNames.JAVA_LANG_CLASS)); + if (classClassType != null) { final Method forNameMethod; + List args = new ArrayList<>(); // do not use unmodifiable lists because the list is modified by JPDA + args.add(virtualMachine.mirrorOf(qName)); if (classLoader != null) { //forNameMethod = classClassType.concreteMethodByName("forName", "(Ljava/lang/String;ZLjava/lang/ClassLoader;)Ljava/lang/Class;"); forNameMethod = DebuggerUtils.findMethod(classClassType, "forName", "(Ljava/lang/String;ZLjava/lang/ClassLoader;)Ljava/lang/Class;"); + args.add(virtualMachine.mirrorOf(true)); + args.add(classLoader); } else { //forNameMethod = classClassType.concreteMethodByName("forName", "(Ljava/lang/String;)Ljava/lang/Class;"); forNameMethod = DebuggerUtils.findMethod(classClassType, "forName", "(Ljava/lang/String;)Ljava/lang/Class;"); } - final List args = new ArrayList<>(); // do not use unmodifiable lists because the list is modified by JPDA - final StringReference qNameMirror = virtualMachine.mirrorOf(qName); - args.add(qNameMirror); - if (classLoader != null) { - args.add(virtualMachine.mirrorOf(true)); - args.add(classLoader); - } - final Value value = invokeMethod(evaluationContext, classClassType, forNameMethod, args); - if (value instanceof ClassObjectReference) { - refType = ((ClassObjectReference)value).reflectedType(); + Value classReference = invokeMethod(evaluationContext, classClassType, forNameMethod, args); + if (classReference instanceof ClassObjectReference) { + refType = ((ClassObjectReference)classReference).reflectedType(); } } return refType; diff --git a/java/debugger/impl/src/com/intellij/debugger/engine/evaluation/expression/NewClassInstanceEvaluator.java b/java/debugger/impl/src/com/intellij/debugger/engine/evaluation/expression/NewClassInstanceEvaluator.java index c3d501096842..ddbba57f82c7 100644 --- a/java/debugger/impl/src/com/intellij/debugger/engine/evaluation/expression/NewClassInstanceEvaluator.java +++ b/java/debugger/impl/src/com/intellij/debugger/engine/evaluation/expression/NewClassInstanceEvaluator.java @@ -24,20 +24,22 @@ import com.intellij.debugger.engine.JVMNameUtil; import com.intellij.debugger.engine.evaluation.EvaluateException; import com.intellij.debugger.engine.evaluation.EvaluateExceptionUtil; import com.intellij.debugger.engine.evaluation.EvaluationContextImpl; -import com.sun.jdi.ClassType; -import com.sun.jdi.Method; -import com.sun.jdi.ObjectReference; +import com.intellij.openapi.diagnostic.Logger; +import com.intellij.util.ArrayUtil; +import com.sun.jdi.*; import java.util.ArrayList; import java.util.Collections; import java.util.List; class NewClassInstanceEvaluator implements Evaluator { - private final Evaluator myClassTypeEvaluator; + private static final Logger LOG = Logger.getInstance(NewClassInstanceEvaluator.class); + + private final TypeEvaluator myClassTypeEvaluator; private final JVMName myConstructorSignature; private final Evaluator[] myParamsEvaluators; - public NewClassInstanceEvaluator(Evaluator classTypeEvaluator, JVMName constructorSignature, Evaluator[] argumentEvaluators) { + public NewClassInstanceEvaluator(TypeEvaluator classTypeEvaluator, JVMName constructorSignature, Evaluator[] argumentEvaluators) { myClassTypeEvaluator = classTypeEvaluator; myConstructorSignature = constructorSignature; myParamsEvaluators = argumentEvaluators; @@ -57,11 +59,16 @@ class NewClassInstanceEvaluator implements Evaluator { DebuggerBundle.message("evaluation.error.cannot.resolve.constructor", myConstructorSignature.getDisplayName(debugProcess))); } // evaluate arguments - List arguments; - if (myParamsEvaluators != null) { + List arguments; + if (!ArrayUtil.isEmpty(myParamsEvaluators)) { arguments = new ArrayList<>(myParamsEvaluators.length); for (Evaluator evaluator : myParamsEvaluators) { - arguments.add(evaluator.evaluate(context)); + Object res = evaluator.evaluate(context); + if (!(res instanceof Value) && res != null) { + LOG.error("Unable to call newInstance, evaluator " + evaluator + " result is not Value, but " + res); + } + //noinspection ConstantConditions + arguments.add((Value)res); } } else { diff --git a/java/debugger/openapi/src/com/intellij/debugger/engine/DebugProcess.java b/java/debugger/openapi/src/com/intellij/debugger/engine/DebugProcess.java index 4fce97015a48..c672028b6db4 100644 --- a/java/debugger/openapi/src/com/intellij/debugger/engine/DebugProcess.java +++ b/java/debugger/openapi/src/com/intellij/debugger/engine/DebugProcess.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2015 JetBrains s.r.o. + * Copyright 2000-2016 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -74,7 +74,7 @@ public interface DebugProcess { Value invokeMethod(EvaluationContext evaluationContext, ObjectReference objRef, Method method, - List args) throws EvaluateException; + List args) throws EvaluateException; /** * Is equivalent to invokeInstanceMethod(evaluationContext, classType, method, args, 0) @@ -82,12 +82,12 @@ public interface DebugProcess { Value invokeMethod(EvaluationContext evaluationContext, ClassType classType, Method method, - List args) throws EvaluateException; + List args) throws EvaluateException; Value invokeInstanceMethod(EvaluationContext evaluationContext, ObjectReference objRef, Method method, - List args, + List args, int invocationOptions) throws EvaluateException; ReferenceType findClass(EvaluationContext evaluationContext, @@ -100,7 +100,7 @@ public interface DebugProcess { ObjectReference newInstance(EvaluationContext evaluationContext, ClassType classType, Method constructor, - List paramList) throws EvaluateException; + List paramList) throws EvaluateException; boolean isAttached();