[hg] main-silver: #223096: Create an array argument for varargs ...

  • From:
  • To:
  • Subject: [hg] main-silver: #223096: Create an array argument for varargs ...
  • Date: Mon, 03 Dec 2012 18:37:25 -0800

changeset 9df44177bf66 in main-silver ((none))
details: http://hg.netbeans.org/main-silver/rev/9df44177bf66
description:
        #223096: Create an array argument for varargs arguments.

diffstat:

 
debugger.jpda/src/org/netbeans/modules/debugger/jpda/expr/EvaluatorVisitor.java
 |  70 +++++++++-
 1 files changed, 67 insertions(+), 3 deletions(-)

diffs (147 lines):

diff --git 
a/debugger.jpda/src/org/netbeans/modules/debugger/jpda/expr/EvaluatorVisitor.java
 
b/debugger.jpda/src/org/netbeans/modules/debugger/jpda/expr/EvaluatorVisitor.java
--- 
a/debugger.jpda/src/org/netbeans/modules/debugger/jpda/expr/EvaluatorVisitor.java
+++ 
b/debugger.jpda/src/org/netbeans/modules/debugger/jpda/expr/EvaluatorVisitor.java
@@ -177,7 +177,9 @@
 import 
org.netbeans.modules.debugger.jpda.expr.EvaluationContext.VariableInfo;
 import org.netbeans.modules.debugger.jpda.jdi.ArrayTypeWrapper;
 import org.netbeans.modules.debugger.jpda.jdi.InternalExceptionWrapper;
+import org.netbeans.modules.debugger.jpda.jdi.ObjectReferenceWrapper;
 import org.netbeans.modules.debugger.jpda.jdi.VMDisconnectedExceptionWrapper;
+import org.netbeans.modules.debugger.jpda.jdi.ValueWrapper;
 import org.netbeans.modules.debugger.jpda.models.CallStackFrameImpl;
 import org.netbeans.modules.debugger.jpda.models.JPDAThreadImpl;
 import org.netbeans.modules.debugger.jpda.util.JPDAUtils;
@@ -296,6 +298,7 @@
         }
         List<? extends TypeMirror> paramTypes = null;
         String enclosingClass = null;
+        boolean isVarArgs = false;
         if (elm != null) {
             TypeMirror typeMirror = elm.asType();
             TypeKind kind = typeMirror.getKind();
@@ -306,6 +309,7 @@
                     Assert.error(arg0, "noSuchMethod", 
elm.getSimpleName().toString(), 
elm.getEnclosingElement().getSimpleName().toString());
                 }
                 ExecutableElement methodElement = (ExecutableElement) elm;
+                isVarArgs = methodElement.isVarArgs();
                 ExecutableType execTypeMirror = (ExecutableType) typeMirror;
                 paramTypes = execTypeMirror.getParameterTypes();
                 isStatic = 
methodElement.getModifiers().contains(Modifier.STATIC);
@@ -436,9 +440,52 @@
         if (method == null) {
             method = getConcreteMethodAndReportProblems(arg0, type, 
methodName, null, paramTypes, argTypes);
         }
+        if (isVarArgs) {
+            transformVarArgsValues(argVals, paramTypes, evaluationContext);
+        }
         return invokeMethod(arg0, method, isStatic, cType, objectReference, 
argVals, evaluationContext, preferredType != null);
     }
 
+    /**
+     * Transform the var-arg arguments to an array.
+     * @param argVals The arguments, where the last items are replaced with 
an array.
+     * @param paramTypes Appropriate parameter types.
+     * @param evaluationContext
+     * @return The created array, with disabled collection, which needs to 
get enabled collection after it's use.
+     */
+    private ArrayReference transformVarArgsValues(List<Value> argVals, 
List<? extends TypeMirror> paramTypes, EvaluationContext evaluationContext) {
+        int varIndex = paramTypes.size() - 1;
+        TypeMirror tm = paramTypes.get(varIndex);
+        if (tm.getKind() != TypeKind.ARRAY) {
+            return null;
+        }
+        VirtualMachine vm = 
evaluationContext.getDebugger().getVirtualMachine();
+        if (vm == null) {
+            return null;
+        }
+        String typeName = getTypeName(((javax.lang.model.type.ArrayType) 
tm).getComponentType());
+        int length = argVals.size() - varIndex;
+        ArrayType at = (ArrayType) getOrLoadClass(vm, typeName+"[]", 
evaluationContext);
+        ArrayReference array = createArrayMirrorWithDisabledCollection(at, 
length, evaluationContext);
+        List<Value> elements = new ArrayList<Value>(length);
+        for (int i = 0; i < length; i++) {
+            elements.add(argVals.get(varIndex + i));
+        }
+        autoboxElements(null, at, elements, evaluationContext);
+        try {
+            array.setValues(elements);
+        } catch (InvalidTypeException ex) {
+            throw new IllegalStateException("ArrayType "+at+" can not have 
"+elements+" elements.");
+        } catch (ClassNotLoadedException ex) {
+            throw new IllegalStateException(ex);
+        }
+        for (int i = argVals.size() - 1; i >= varIndex; i--) {
+            argVals.remove(i);
+        }
+        argVals.add(array);
+        return array;
+    }
+    
     /*private Method getConcreteMethod(ReferenceType type, String 
methodName, List<? extends ExpressionTree> typeArguments) {
         List<Method> methods = type.methodsByName(methodName);
         String signature = createSignature(typeArguments);
@@ -450,7 +497,12 @@
         return null;
     }*/
 
-    private ReferenceType findEnclosingTypeWithMethod(ReferenceType type, 
String enclosingClass, String methodName, List<? extends TypeMirror> 
paramTypes, List<? extends Type> argTypes, Method[] methodPtr) {
+    private ReferenceType findEnclosingTypeWithMethod(ReferenceType type,
+                                                      String enclosingClass,
+                                                      String methodName,
+                                                      List<? extends 
TypeMirror> paramTypes,
+                                                      List<? extends Type> 
argTypes,
+                                                      Method[] methodPtr) {
         ReferenceType etype = findEnclosingType(type, enclosingClass);
         if (etype == null) {
             return null;
@@ -473,7 +525,12 @@
         }
     }
 
-    private static Method getConcreteMethodAndReportProblems(Tree arg0, 
ReferenceType type, String methodName, String firstParamSignature, List<? 
extends TypeMirror> paramTypes, List<? extends Type> argTypes) {
+    private static Method getConcreteMethodAndReportProblems(Tree arg0,
+                                                             ReferenceType 
type,
+                                                             String 
methodName,
+                                                             String 
firstParamSignature,
+                                                             List<? extends 
TypeMirror> paramTypes,
+                                                             List<? extends 
Type> argTypes) {
         Method method;
         try {
             if (paramTypes != null) {
@@ -519,7 +576,9 @@
         return getConcreteMethod(type, methodName, null, typeArguments);
     }
 
-    private static Method getConcreteMethod(ReferenceType type, String 
methodName, String firstParamSignature, List<? extends TypeMirror> 
typeArguments) throws UnsuitableArgumentsException {
+    private static Method getConcreteMethod(ReferenceType type, String 
methodName,
+                                            String firstParamSignature,
+                                            List<? extends TypeMirror> 
typeArguments) throws UnsuitableArgumentsException {
         List<Method> methods = type.methodsByName(methodName);
         String signature = createSignature(firstParamSignature, 
typeArguments);
         boolean constructor = "<init>".equals(methodName);
@@ -2401,6 +2460,7 @@
         }
         TreePath currentPath = getCurrentPath();
         TypeMirror cType;
+        boolean isVarArgs = false;
         if (currentPath != null) {
             TreePath identifierPath = TreePath.getPath(currentPath, arg0);
             if (identifierPath == null) {
@@ -2416,6 +2476,7 @@
                     }
                     ExecutableElement cElem = (ExecutableElement) elm;
                     cType = cElem.asType();
+                    isVarArgs = cElem.isVarArgs();
                 }
             } else {
                 // Unresolved class
@@ -2503,6 +2564,9 @@
             }
             evaluationContext.methodToBeInvoked();
             Method constructorMethod = 
getConcreteMethodAndReportProblems(arg0, classType, "<init>", 
firstParamSignature, paramTypes, argTypes);
+            if (isVarArgs) {
+                transformVarArgsValues(argVals, paramTypes, 
evaluationContext);
+            }
             ObjectReference o = 
classType.newInstance(evaluationContext.getFrame().thread(),
                                                       constructorMethod,
                                                       argVals,

[hg] main-silver: #223096: Create an array argument for varargs ...

mentlicher 12/04/2012

Project Features

About this Project

Debugger was started in November 2009, is owned by tpavek, and has 29 members.
By use of this website, you agree to the NetBeans Policies and Terms of Use (revision 20131025.e7cbc9d). © 2013, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo
 
 
Close
loading
Please Confirm
Close