Path: blob/master/src/jdk.jdi/share/classes/com/sun/tools/jdi/FieldImpl.java
41161 views
/*1* Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package com.sun.tools.jdi;2627import com.sun.jdi.ClassNotLoadedException;28import com.sun.jdi.Field;29import com.sun.jdi.Type;30import com.sun.jdi.VirtualMachine;3132public class FieldImpl extends TypeComponentImpl33implements Field, ValueContainer {3435FieldImpl(VirtualMachine vm, ReferenceTypeImpl declaringType,36long ref, String name, String signature,37String genericSignature, int modifiers) {38super(vm, declaringType, ref, name, signature,39genericSignature, modifiers);40}4142public boolean equals(Object obj) {43if ((obj != null) && (obj instanceof FieldImpl)) {44FieldImpl other = (FieldImpl)obj;45return (declaringType().equals(other.declaringType())) &&46(ref() == other.ref()) &&47super.equals(obj);48} else {49return false;50}51}5253public int hashCode() {54return (int)ref();55}5657public int compareTo(Field field) {58ReferenceTypeImpl declaringType = (ReferenceTypeImpl)declaringType();59int rc = declaringType.compareTo(field.declaringType());60if (rc == 0) {61rc = declaringType.indexOf(this) -62declaringType.indexOf(field);63}64return rc;65}6667public Type type() throws ClassNotLoadedException {68return findType(signature());69}7071public Type findType(String signature) throws ClassNotLoadedException {72ReferenceTypeImpl enclosing = (ReferenceTypeImpl)declaringType();73return enclosing.findType(signature);74}7576/**77* @return a text representation of the declared type78* of this field.79*/80public String typeName() {81JNITypeParser parser = new JNITypeParser(signature());82return parser.typeName();83}8485public boolean isTransient() {86return isModifierSet(VMModifiers.TRANSIENT);87}8889public boolean isVolatile() {90return isModifierSet(VMModifiers.VOLATILE);91}9293public boolean isEnumConstant() {94return isModifierSet(VMModifiers.ENUM_CONSTANT);95}9697public String toString() {98StringBuilder sb = new StringBuilder();99100sb.append(declaringType().name());101sb.append('.');102sb.append(name());103104return sb.toString();105}106}107108109