ArrayReferenceImpl

创建于 差异永不过期
21 删除
284 行
87 添加
351 行
/*
/*
* Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
*
* This code is free software; you can redistribute it and/or modify it
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
* by Oracle in the LICENSE file that accompanied this code.
*
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
* accompanied this code).
*
*
* You should have received a copy of the GNU General Public License version
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* or visit www.oracle.com if you need additional information or have any
* questions.
* questions.
*
* Copyright (C) 2019 JetBrains s.r.o.
*
* This program is free software; you can redistribute and/or modify it under
* the terms of the GNU General Public License v2 with Classpath Exception.
* The text of the license is available in the file LICENSE.TXT.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.TXT for more details.
*
* You may contact JetBrains s.r.o. at Na Hřebenech II 1718/10, 140 00 Prague,
* Czech Republic or at legal@jetbrains.com.
*/
*/


package com.sun.tools.jdi;
package com.jetbrains.jdi;

import com.sun.jdi.*;


import java.util.Collections;
import java.util.List;
import java.util.List;
import java.util.ArrayList;
import java.util.concurrent.CompletableFuture;

import com.sun.jdi.ArrayReference;
import com.sun.jdi.ClassNotLoadedException;
import java.util.Arrays;
import com.sun.jdi.InvalidTypeException;
import com.sun.jdi.Method;
import java.util.Iterator;
import com.sun.jdi.Type;
import com.sun.jdi.Value;
import com.sun.jdi.VirtualMachine;


public class ArrayReferenceImpl extends ObjectReferenceImpl
public class ArrayReferenceImpl extends ObjectReferenceImpl
implements ArrayReference
implements ArrayReference
{
{
int length = -1;
private volatile int length = -1;


ArrayReferenceImpl(VirtualMachine aVm,long aRef) {
ArrayReferenceImpl(VirtualMachine aVm, long aRef) {
super(aVm,aRef);
super(aVm, aRef);
}
}


protected ClassTypeImpl invokableReferenceType(Method method) {
protected ClassTypeImpl invokableReferenceType(Method method) {
// The method has to be a method on Object since
// The method has to be a method on Object since
// arrays don't have methods nor any other 'superclasses'
// arrays don't have methods nor any other 'superclasses'
// So, use the ClassTypeImpl for Object instead of
// So, use the ClassTypeImpl for Object instead of
// the ArrayTypeImpl for the array itself.
// the ArrayTypeImpl for the array itself.
return (ClassTypeImpl)method.declaringType();
return (ClassTypeImpl)method.declaringType();
}
}


ArrayTypeImpl arrayType() {
ArrayTypeImpl arrayType() {
return (ArrayTypeImpl)type();
return (ArrayTypeImpl)type();
}
}


/**
/**
* Return array length.
* Return array length.
* Need not be synchronized since it cannot be provably stale.
* Need not be synchronized since it cannot be provably stale.
*/
*/
public int length() {
public int length() {
if(length == -1) {
if(length == -1) {
try {
try {
length = JDWP.ArrayReference.Length.
length = JDWP.ArrayReference.Length.
process(vm, this).arrayLength;
process(vm, this).arrayLength;
} catch (JDWPException exc) {
} catch (JDWPException exc) {
throw exc.toJDIException();
throw exc.toJDIException();
}
}
}
}
return length;
return length;
}
}


public CompletableFuture<Integer> lengthAsync() {
if (length != -1) {
return CompletableFuture.completedFuture(length);
}
return JDWP.ArrayReference.Length.processAsync(vm, this).thenApply(r -> length = r.arrayLength);
}

void setLength(int length) {
this.length = length;