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

View File

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