add method IClass.isStatic()

git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@2231 f5eafffb-2e1d-0410-98e4-8ec43c5233c4
This commit is contained in:
sjfink 2007-12-21 15:08:16 +00:00
parent 1682fbbf1b
commit 45bd43ebf8
2 changed files with 58 additions and 52 deletions

View File

@ -10,7 +10,6 @@
*****************************************************************************/
package com.ibm.wala.cast.loader;
import java.net.URL;
import java.util.Collection;
import java.util.Iterator;
@ -34,19 +33,19 @@ import com.ibm.wala.util.debug.Assertions;
abstract public class AstClass implements IClass, ClassConstants {
private final CAstSourcePositionMap.Position sourcePosition;
private final TypeName typeName;
private final IClassLoader loader;
private final short modifiers;
protected final Map<Atom, IField> declaredFields;
protected final Map<Selector,IMethod> declaredMethods;
protected AstClass(CAstSourcePositionMap.Position sourcePosition,
TypeName typeName,
IClassLoader loader,
short modifiers,
Map<Atom, IField> declaredFields,
Map<Selector,IMethod> declaredMethods)
{
private final TypeName typeName;
private final IClassLoader loader;
private final short modifiers;
protected final Map<Atom, IField> declaredFields;
protected final Map<Selector, IMethod> declaredMethods;
protected AstClass(CAstSourcePositionMap.Position sourcePosition, TypeName typeName, IClassLoader loader, short modifiers,
Map<Atom, IField> declaredFields, Map<Selector, IMethod> declaredMethods) {
this.sourcePosition = sourcePosition;
this.typeName = typeName;
this.loader = loader;
@ -56,15 +55,19 @@ abstract public class AstClass implements IClass, ClassConstants {
}
public boolean isInterface() {
return (modifiers&ACC_INTERFACE) != 0;
return (modifiers & ACC_INTERFACE) != 0;
}
public boolean isAbstract() {
return (modifiers&ACC_ABSTRACT) != 0;
return (modifiers & ACC_ABSTRACT) != 0;
}
public boolean isPublic() {
return (modifiers&ACC_PUBLIC) != 0;
return (modifiers & ACC_PUBLIC) != 0;
}
public boolean isStatic() {
return (modifiers & ACC_STATIC) != 0;
}
public boolean isReferenceType() {
@ -103,29 +106,28 @@ abstract public class AstClass implements IClass, ClassConstants {
return loader;
}
public abstract IClass getSuperclass() throws ClassHierarchyException;
public abstract IClass getSuperclass() throws ClassHierarchyException;
private Collection<IClass> gatherInterfaces() throws ClassHierarchyException {
Set<IClass> result = HashSetFactory.make();
result.addAll( getDirectInterfaces() );
result.addAll(getDirectInterfaces());
if (getSuperclass() != null)
result.addAll( getSuperclass().getAllImplementedInterfaces() );
result.addAll(getSuperclass().getAllImplementedInterfaces());
return result;
}
public abstract Collection<IClass> getDirectInterfaces() throws ClassHierarchyException;
public Collection<IClass> getAllImplementedInterfaces() throws ClassHierarchyException {
return gatherInterfaces();
}
public IMethod getClassInitializer() {
return getMethod( MethodReference.clinitSelector );
return getMethod(MethodReference.clinitSelector);
}
public IMethod getMethod(Selector selector) {
try {
try {
if (declaredMethods.containsKey(selector)) {
return declaredMethods.get(selector);
} else if (getSuperclass() != null) {
@ -133,25 +135,25 @@ abstract public class AstClass implements IClass, ClassConstants {
} else {
return null;
}
} catch (ClassHierarchyException e) {
Assertions.UNREACHABLE();
return null;
}
} catch (ClassHierarchyException e) {
Assertions.UNREACHABLE();
return null;
}
}
public IField getField(Atom name) {
try {
if (declaredFields.containsKey(name)) {
if (declaredFields.containsKey(name)) {
return declaredFields.get(name);
} else if (getSuperclass() != null) {
return getSuperclass().getField(name);
} else {
return null;
}
} catch (ClassHierarchyException e) {
Assertions.UNREACHABLE();
return null;
}
} catch (ClassHierarchyException e) {
Assertions.UNREACHABLE();
return null;
}
}
public Collection<IMethod> getDeclaredMethods() {
@ -160,33 +162,33 @@ abstract public class AstClass implements IClass, ClassConstants {
public Collection<IField> getDeclaredInstanceFields() {
Set<IField> result = HashSetFactory.make();
for(Iterator<IField> FS = declaredFields.values().iterator(); FS.hasNext();) {
for (Iterator<IField> FS = declaredFields.values().iterator(); FS.hasNext();) {
IField F = FS.next();
if (! F.isStatic()) {
result.add( F );
if (!F.isStatic()) {
result.add(F);
}
}
return result;
}
public Collection<IField> getDeclaredStaticFields() {
Set<IField> result = HashSetFactory.make();
for(Iterator<IField> FS = declaredFields.values().iterator(); FS.hasNext();) {
for (Iterator<IField> FS = declaredFields.values().iterator(); FS.hasNext();) {
IField F = FS.next();
if (F.isStatic()) {
result.add( F );
result.add(F);
}
}
return result;
}
public Collection<IField> getAllInstanceFields() throws ClassHierarchyException {
Collection<IField> result = HashSetFactory.make();
result.addAll( getDeclaredInstanceFields() );
result.addAll(getDeclaredInstanceFields());
if (getSuperclass() != null) {
result.addAll( getSuperclass().getAllInstanceFields() );
result.addAll(getSuperclass().getAllInstanceFields());
}
return result;
@ -194,9 +196,9 @@ abstract public class AstClass implements IClass, ClassConstants {
public Collection<IField> getAllStaticFields() throws ClassHierarchyException {
Collection<IField> result = HashSetFactory.make();
result.addAll( getDeclaredStaticFields() );
result.addAll(getDeclaredStaticFields());
if (getSuperclass() != null) {
result.addAll( getSuperclass().getAllStaticFields() );
result.addAll(getSuperclass().getAllStaticFields());
}
return result;
@ -204,18 +206,18 @@ abstract public class AstClass implements IClass, ClassConstants {
public Collection<IField> getAllFields() throws ClassHierarchyException {
Collection<IField> result = HashSetFactory.make();
result.addAll( getAllInstanceFields() );
result.addAll( getAllStaticFields() );
result.addAll(getAllInstanceFields());
result.addAll(getAllStaticFields());
return result;
}
public Collection<IMethod> getAllMethods() throws ClassHierarchyException {
Collection<IMethod> result = HashSetFactory.make();
for(Iterator<IMethod> ms = getDeclaredMethods().iterator(); ms.hasNext(); ) {
result.add( ms.next() );
for (Iterator<IMethod> ms = getDeclaredMethods().iterator(); ms.hasNext();) {
result.add(ms.next());
}
if (getSuperclass() != null) {
result.addAll( getSuperclass().getAllMethods() );
result.addAll(getSuperclass().getAllMethods());
}
return result;

View File

@ -72,6 +72,10 @@ abstract public class AstFunctionClass implements IClass, ClassConstants {
public boolean isPublic() {
return true;
}
public boolean isStatic() {
return false;
}
public int getModifiers() {
return ACC_PUBLIC;