001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019package org.apache.commons.weaver.privilizer; 020 021import org.objectweb.asm.Type; 022 023/** 024 * Models the action of accessing a field by extending {@link Field} with an 025 * accessing type. 026 */ 027public class FieldAccess extends Field { 028 /** 029 * {@link Type} from which field is accessed. 030 */ 031 public final Type owner; 032 033 /** 034 * Create a new {@link FieldAccess}. 035 * @param access operation 036 * @param owner {@link Type} from which field is accessed. 037 * @param name of field 038 * @param type of field 039 */ 040 public FieldAccess(final int access, final Type owner, final String name, final Type type) { 041 super(access, name, type); 042 this.owner = owner; 043 } 044 045 /** 046 * Compare against {@code obj} for equality. 047 * @param obj to compare 048 * @return whether Objects are equal 049 */ 050 @Override 051 public boolean equals(final Object obj) { 052 if (obj == this) { 053 return true; 054 } 055 if (!(obj instanceof FieldAccess)) { 056 return false; 057 } 058 return super.equals(obj) && ((FieldAccess) obj).owner.equals(owner); 059 } 060 061 /** 062 * Generate a hashCode. 063 * @return int 064 */ 065 @Override 066 public int hashCode() { 067 final int result = super.hashCode() << 4; 068 return result | owner.hashCode(); 069 } 070 071}