WALA/com.ibm.wala.cast/source/java/com/ibm/wala/cast/loader/AstDynamicPropertyClass.java

104 lines
3.0 KiB
Java

/******************************************************************************
* 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.cast.loader;
import com.ibm.wala.cast.tree.*;
import com.ibm.wala.cast.types.*;
import com.ibm.wala.classLoader.*;
import com.ibm.wala.ipa.cha.*;
import com.ibm.wala.types.*;
import com.ibm.wala.util.Atom;
import com.ibm.wala.util.collections.*;
import com.ibm.wala.util.debug.Assertions;
import java.util.*;
public abstract class AstDynamicPropertyClass extends AstClass {
private final TypeReference defaultDescriptor;
protected AstDynamicPropertyClass(CAstSourcePositionMap.Position sourcePosition, TypeName typeName, IClassLoader loader, short modifiers, Map declaredMethods, TypeReference defaultDescriptor) {
super(sourcePosition, typeName, loader, modifiers, new HashMap(), declaredMethods);
this.defaultDescriptor = defaultDescriptor;
}
public IField getField(final Atom name) {
try {
if (declaredFields.containsKey(name)) {
return (IField) declaredFields.get(name);
} else if (getSuperclass() != null) {
return getSuperclass().getField(name);
} else {
final boolean isStatic = isStaticField(name);
declaredFields.put(name, new IField() {
public String toString() {
return "<field " + name + ">";
}
public IClass getDeclaringClass() {
return AstDynamicPropertyClass.this;
}
public Atom getName() {
return name;
}
public TypeReference getFieldTypeReference() {
return defaultDescriptor;
}
public FieldReference getFieldReference() {
return FieldReference.findOrCreate(AstDynamicPropertyClass.this.getReference(), name, defaultDescriptor);
}
public boolean isFinal() {
return false;
}
public boolean isPrivate() {
return false;
}
public boolean isProtected() {
return false;
}
public boolean isPublic() {
return false;
}
public boolean isVolatile() {
return false;
}
public boolean isStatic() {
return isStatic;
}
public ClassHierarchy getClassHierarchy() {
return AstDynamicPropertyClass.this.getClassHierarchy();
}
});
return (IField) declaredFields.get(name);
}
} catch (ClassHierarchyException e) {
Assertions.UNREACHABLE();
return null;
}
}
protected boolean isStaticField(Atom name) {
return name.toString().startsWith("global ");
}
}