2006-11-22 17:38:46 +00:00
|
|
|
/*******************************************************************************
|
|
|
|
* Copyright (c) 2002 - 2006 IBM Corporation.
|
|
|
|
* All rights reserved. This program and the accompanying materials
|
|
|
|
* are made available under the terms of the Eclipse Public License v1.0
|
|
|
|
* which accompanies this distribution, and is available at
|
|
|
|
* http://www.eclipse.org/legal/epl-v10.html
|
|
|
|
*
|
|
|
|
* Contributors:
|
|
|
|
* IBM Corporation - initial API and implementation
|
|
|
|
*******************************************************************************/
|
|
|
|
package com.ibm.wala.classLoader;
|
|
|
|
|
2007-05-29 13:39:14 +00:00
|
|
|
import java.util.Collection;
|
|
|
|
import java.util.Collections;
|
|
|
|
|
2006-12-21 19:03:50 +00:00
|
|
|
import com.ibm.wala.ipa.cha.ClassHierarchy;
|
2006-11-22 17:38:46 +00:00
|
|
|
import com.ibm.wala.shrikeCT.ClassConstants;
|
|
|
|
import com.ibm.wala.types.FieldReference;
|
|
|
|
import com.ibm.wala.types.TypeReference;
|
2007-05-29 13:39:14 +00:00
|
|
|
import com.ibm.wala.types.annotations.Annotation;
|
2006-11-22 17:38:46 +00:00
|
|
|
import com.ibm.wala.util.Atom;
|
|
|
|
import com.ibm.wala.util.debug.Assertions;
|
|
|
|
|
|
|
|
/**
|
2006-12-21 19:03:50 +00:00
|
|
|
*
|
2006-11-22 17:38:46 +00:00
|
|
|
* Implementation of a canonical field reference. TODO: canonicalize these?
|
|
|
|
* TODO: don't cache fieldType here .. move to class?
|
|
|
|
*
|
|
|
|
* @author sfink
|
|
|
|
*/
|
|
|
|
public final class FieldImpl implements IField {
|
|
|
|
|
|
|
|
private final IClass declaringClass;
|
2006-12-21 19:03:50 +00:00
|
|
|
|
2006-11-22 17:38:46 +00:00
|
|
|
private final FieldReference fieldRef;
|
2006-12-21 19:03:50 +00:00
|
|
|
|
2006-11-22 17:38:46 +00:00
|
|
|
private final int accessFlags;
|
2007-05-29 13:39:14 +00:00
|
|
|
|
|
|
|
private final Collection<Annotation> annotations;
|
2006-11-22 17:38:46 +00:00
|
|
|
|
2007-05-29 13:39:14 +00:00
|
|
|
public FieldImpl(IClass declaringClass, FieldReference canonicalRef, int accessFlags, Collection<Annotation> annotations) {
|
2006-11-22 17:38:46 +00:00
|
|
|
this.declaringClass = declaringClass;
|
|
|
|
this.fieldRef = canonicalRef;
|
|
|
|
this.accessFlags = accessFlags;
|
2007-05-29 13:39:14 +00:00
|
|
|
this.annotations = annotations;
|
2006-11-22 17:38:46 +00:00
|
|
|
if (Assertions.verifyAssertions) {
|
|
|
|
Assertions._assert(declaringClass != null);
|
|
|
|
Assertions._assert(fieldRef != null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* (non-Javadoc)
|
|
|
|
*
|
|
|
|
* @see com.ibm.wala.classLoader.IMember#getDeclaringClass()
|
|
|
|
*/
|
|
|
|
public IClass getDeclaringClass() {
|
|
|
|
return declaringClass;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* (non-Javadoc)
|
|
|
|
*
|
|
|
|
* @see java.lang.Object#equals(java.lang.Object)
|
|
|
|
*/
|
|
|
|
public boolean equals(Object obj) {
|
|
|
|
// instanceof is OK because this class is final
|
|
|
|
if (obj instanceof FieldImpl) {
|
|
|
|
FieldImpl other = (FieldImpl) obj;
|
2006-12-21 19:03:50 +00:00
|
|
|
return fieldRef.equals(other.fieldRef) && declaringClass.equals(other.declaringClass);
|
2006-11-22 17:38:46 +00:00
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* (non-Javadoc)
|
|
|
|
*
|
|
|
|
* @see java.lang.Object#hashCode()
|
|
|
|
*/
|
|
|
|
public int hashCode() {
|
|
|
|
return 87049 * declaringClass.hashCode() + fieldRef.hashCode();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* (non-Javadoc)
|
|
|
|
*
|
|
|
|
* @see java.lang.Object#toString()
|
|
|
|
*/
|
|
|
|
public String toString() {
|
2007-05-14 17:01:14 +00:00
|
|
|
FieldReference fr = getReference();
|
2006-11-22 17:38:46 +00:00
|
|
|
return fr.toString();
|
|
|
|
}
|
|
|
|
|
2007-05-14 17:01:14 +00:00
|
|
|
public FieldReference getReference() {
|
2006-11-22 17:38:46 +00:00
|
|
|
return FieldReference.findOrCreate(getDeclaringClass().getReference(), getName(), getFieldTypeReference());
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* (non-Javadoc)
|
|
|
|
*
|
|
|
|
* @see com.ibm.wala.classLoader.IMember#getName()
|
|
|
|
*/
|
|
|
|
public Atom getName() {
|
|
|
|
return fieldRef.getName();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* (non-Javadoc)
|
|
|
|
*
|
|
|
|
* @see com.ibm.wala.classLoader.IField#getFieldTypeReference()
|
|
|
|
*/
|
|
|
|
public TypeReference getFieldTypeReference() {
|
|
|
|
return fieldRef.getFieldType();
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isStatic() {
|
|
|
|
return ((accessFlags & ClassConstants.ACC_STATIC) != 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isFinal() {
|
|
|
|
return ((accessFlags & ClassConstants.ACC_FINAL) != 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isPrivate() {
|
2006-12-21 19:03:50 +00:00
|
|
|
return ((accessFlags & ClassConstants.ACC_PRIVATE) != 0);
|
2006-11-22 17:38:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isProtected() {
|
2006-12-21 19:03:50 +00:00
|
|
|
return ((accessFlags & ClassConstants.ACC_PROTECTED) != 0);
|
2006-11-22 17:38:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isPublic() {
|
2006-12-21 19:03:50 +00:00
|
|
|
return ((accessFlags & ClassConstants.ACC_PUBLIC) != 0);
|
|
|
|
}
|
2007-01-11 17:51:29 +00:00
|
|
|
|
|
|
|
public boolean isVolatile() {
|
|
|
|
return ((accessFlags & ClassConstants.ACC_VOLATILE) != 0);
|
|
|
|
}
|
2006-12-21 19:03:50 +00:00
|
|
|
|
|
|
|
public ClassHierarchy getClassHierarchy() {
|
|
|
|
return declaringClass.getClassHierarchy();
|
2006-11-22 17:38:46 +00:00
|
|
|
}
|
2007-01-11 17:51:29 +00:00
|
|
|
|
2007-05-29 13:39:14 +00:00
|
|
|
public Collection<Annotation> getAnnotations() {
|
|
|
|
return annotations == null ? null : Collections.unmodifiableCollection(annotations);
|
|
|
|
}
|
|
|
|
|
2007-01-11 17:51:29 +00:00
|
|
|
|
2006-11-22 17:38:46 +00:00
|
|
|
}
|