misc. bug fixes and annotations

git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@579 f5eafffb-2e1d-0410-98e4-8ec43c5233c4
This commit is contained in:
sjfink 2007-01-15 18:31:55 +00:00
parent 08e6f673ba
commit e2c552a1cb
39 changed files with 380 additions and 398 deletions

View File

@ -18,9 +18,10 @@ import java.util.Iterator;
import com.ibm.wala.util.collections.NonNullSingletonIterator;
import com.ibm.wala.util.debug.Assertions;
import com.ibm.wala.util.debug.UnimplementedError;
/**
*
*
* A module which is a wrapper around a file in the filesystem
*
* @author sfink
@ -37,41 +38,50 @@ public abstract class FileModule implements Module, ModuleEntry {
return file.getAbsolutePath();
}
/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see com.ibm.wala.classLoader.Module#getEntries()
*/
public Iterator<ModuleEntry> getEntries() {
return new NonNullSingletonIterator<ModuleEntry>(this);
}
/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see java.lang.Object#hashCode()
*/
public int hashCode() {
return file.hashCode();
}
/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see com.ibm.wala.classLoader.FileModule#equals(java.lang.Object)
*/
public boolean equals(Object o) {
if (o.getClass().equals(getClass())) {
FileModule other = (FileModule)o;
FileModule other = (FileModule) o;
return getName().equals(other.getName());
} else {
return false;
}
}
/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see com.ibm.wala.classLoader.ModuleEntry#getName()
*/
public String getName() {
return file.getName();
}
/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see com.ibm.wala.classLoader.ModuleEntry#getInputStream()
*/
public InputStream getInputStream() {
@ -84,24 +94,24 @@ public abstract class FileModule implements Module, ModuleEntry {
}
}
/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see com.ibm.wala.classLoader.ModuleEntry#isModuleFile()
*/
public boolean isModuleFile() {
return false;
}
/* (non-Javadoc)
* @see com.ibm.wala.classLoader.ModuleEntry#asModule()
*/
public Module asModule() {
Assertions.UNREACHABLE();
return null;
}
/**
* @return Returns the file.
*/
public File getFile() {
return file;
}
public Module asModule() throws UnimplementedError {
Assertions.UNREACHABLE("implement me");
return null;
}
}

View File

@ -28,11 +28,14 @@ import com.ibm.wala.shrikeBT.Constants;
import com.ibm.wala.shrikeCT.ClassConstants;
import com.ibm.wala.shrikeCT.ClassReader;
import com.ibm.wala.shrikeCT.InvalidClassFileException;
import com.ibm.wala.shrikeCT.RuntimeInvisibleAnnotationsReader;
import com.ibm.wala.shrikeCT.RuntimeInvisibleAnnotationsReader.UnimplementedException;
import com.ibm.wala.types.FieldReference;
import com.ibm.wala.types.MethodReference;
import com.ibm.wala.types.Selector;
import com.ibm.wala.types.TypeName;
import com.ibm.wala.types.TypeReference;
import com.ibm.wala.types.annotations.Annotation;
import com.ibm.wala.util.Atom;
import com.ibm.wala.util.ImmutableByteArray;
import com.ibm.wala.util.ShrikeClassReaderHandle;
@ -838,34 +841,73 @@ public final class ShrikeClass implements IClass {
return result;
}
// private SignatureReader getSignatureReader() throws InvalidClassFileException {
// ClassReader r = reader.get();
// ClassReader.AttrIterator attrs = new ClassReader.AttrIterator();
// r.initClassAttributeIterator(attrs);
//
// // search for the desired attribute
// SignatureReader result = null;
// try {
// for (; attrs.isValid(); attrs.advance()) {
// if (attrs.getName().toString().equals("Signature")) {
// result = new SignatureReader(attrs);
// break;
// }
// }
// } catch (InvalidClassFileException e) {
// Assertions.UNREACHABLE();
// }
// return result;
// }
// public ParameterizedTypeReference getGenericType() throws InvalidClassFileException {
// // TODO: cache this later?
// SignatureReader r = getSignatureReader();
// if (r == null) {
// return ParameterizedTypeReference.makeRaw(getReference());
// } else {
// System.err.println("parse for " + getReference());
// return StringStuff.parseForGenericType(r.getSignature());
// }
// }
public Collection<Annotation> getRuntimeInvisibleAnnotations() throws InvalidClassFileException, UnimplementedException {
RuntimeInvisibleAnnotationsReader r = getRuntimeInvisibleAnnotationsReader();
if (r != null) {
int[] offsets = r.getAnnotationOffsets();
Collection<Annotation> result = HashSetFactory.make();
for (int i : offsets) {
String type = r.getAnnotationType(i);
type = type.replaceAll(";", "");
TypeReference t = TypeReference.findOrCreate(getClassLoader().getReference(), type);
result.add(Annotation.make(t));
}
return result;
} else {
return Collections.emptySet();
}
}
private RuntimeInvisibleAnnotationsReader getRuntimeInvisibleAnnotationsReader() throws InvalidClassFileException {
ClassReader r = reader.get();
ClassReader.AttrIterator attrs = new ClassReader.AttrIterator();
r.initClassAttributeIterator(attrs);
// search for the desired attribute
RuntimeInvisibleAnnotationsReader result = null;
try {
for (; attrs.isValid(); attrs.advance()) {
if (attrs.getName().toString().equals("RuntimeInvisibleAnnotations")) {
result = new RuntimeInvisibleAnnotationsReader(attrs);
break;
}
}
} catch (InvalidClassFileException e) {
Assertions.UNREACHABLE();
}
return result;
}
// private SignatureReader getSignatureReader() throws
// InvalidClassFileException {
// ClassReader r = reader.get();
// ClassReader.AttrIterator attrs = new ClassReader.AttrIterator();
// r.initClassAttributeIterator(attrs);
//
// // search for the desired attribute
// SignatureReader result = null;
// try {
// for (; attrs.isValid(); attrs.advance()) {
// if (attrs.getName().toString().equals("Signature")) {
// result = new SignatureReader(attrs);
// break;
// }
// }
// } catch (InvalidClassFileException e) {
// Assertions.UNREACHABLE();
// }
// return result;
// }
// public ParameterizedTypeReference getGenericType() throws
// InvalidClassFileException {
// // TODO: cache this later?
// SignatureReader r = getSignatureReader();
// if (r == null) {
// return ParameterizedTypeReference.makeRaw(getReference());
// } else {
// System.err.println("parse for " + getReference());
// return StringStuff.parseForGenericType(r.getSignature());
// }
// }
}

View File

@ -10,7 +10,6 @@
*******************************************************************************/
package com.ibm.wala.dataflow.IFDS;
import com.ibm.wala.util.debug.Assertions;
import com.ibm.wala.util.intset.SparseIntSet;
/**
@ -28,9 +27,6 @@ public class VectorGenFlowFunction implements IReversibleFlowFunction {
*/
private VectorGenFlowFunction(SparseIntSet gen) {
this.gen = gen;
if (Assertions.verifyAssertions) {
Assertions._assert(gen.contains(0));
}
}
/*

View File

@ -143,7 +143,10 @@ public abstract class Launcher {
* @param cmd
* @throws WalaException
*/
protected Process spawnProcess(String cmd) throws WalaException {
protected Process spawnProcess(String cmd) throws WalaException, IllegalArgumentException {
if (cmd == null) {
throw new IllegalArgumentException("cmd cannot be null");
}
System.out.println("spawning process " + cmd);
String[] env = getEnv()== null ? null : buildEnv(getEnv());
try {

View File

@ -329,12 +329,6 @@ public class DefaultFixedPointSystem extends AbstractFixedPointSystem {
});
}
public int getNumberOfVariables() {
// TODO Auto-generated method stub
Assertions.UNREACHABLE();
return 0;
}
public int getNumberOfNodes() {
return graph.getNumberOfNodes();
}
@ -348,17 +342,6 @@ public class DefaultFixedPointSystem extends AbstractFixedPointSystem {
return graph.getPredNodeCount(n);
}
/*
* (non-Javadoc)
*
* @see com.ibm.wala.dataflow.fixpoint.DataflowGraph#performVerboseAction()
*/
public void performVerboseAction() {
// TODO Auto-generated method stub
Assertions.UNREACHABLE();
}
/*
* (non-Javadoc)
*

View File

@ -33,15 +33,6 @@ public class Worklist extends Heap {
return (eq1.getOrderNumber() < eq2.getOrderNumber());
}
/* (non-Javadoc)
* @see com.ibm.wala.util.collections.Heap#take()
*/
public Object take() {
Assertions.UNREACHABLE();
return null;
}
public AbstractStatement takeStatement() {
AbstractStatement result = (AbstractStatement)super.take();
contents.remove(result);

View File

@ -384,6 +384,9 @@ public class AnalysisOptions {
this.ssaOptions = ssaOptions;
}
/**
* TODO: what is this and why is it here?
*/
public TypeReference getConstantType(Object S) {
Class<? extends Object> key = (S == null) ? null : S.getClass();
if (Assertions.verifyAssertions && !constantTypes.containsKey(key)) {

View File

@ -1,113 +0,0 @@
/*******************************************************************************
* 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.ipa.callgraph.propagation;
import java.util.Iterator;
import com.ibm.wala.util.debug.Assertions;
import com.ibm.wala.util.graph.NodeManager;
/**
*
* An object that tracks nodes in a graph, where each node is a PointerKey
* represented in the input pointsToSets
*
* @author Julian Dolby
* @author sfink
*/
public class PointerKeyNodeManager implements NodeManager {
/**
* a mapping from PointerKey -> IntSetVariable
*/
private final PointsToMap pointsToMap;
/**
* number of nodes in this graph
*/
private int count = 0;
public PointerKeyNodeManager(PointsToMap pointsToMap) {
this.pointsToMap = pointsToMap;
}
/*
* (non-Javadoc)
*
* @see com.ibm.wala.util.graph.NodeManager#iterateNodes()
*/
public Iterator iterateNodes() {
return pointsToMap.iterateKeys();
}
/*
* (non-Javadoc)
*
* @see com.ibm.wala.util.graph.NodeManager#getNumberOfNodes()
*/
public int getNumberOfNodes() {
if (count == 0) {
countNodes();
}
return count;
}
/**
* Count the number of nodes in this graph
*/
private void countNodes() {
for (Iterator x = iterateNodes(); x.hasNext(); x.next(), count++)
;
}
/*
* (non-Javadoc)
*
* @see com.ibm.wala.util.graph.NodeManager#addNode(java.lang.Object)
*/
public void addNode(Object n) {
Assertions.UNREACHABLE();
}
/*
* (non-Javadoc)
*
* @see com.ibm.wala.util.graph.NodeManager#removeNode(java.lang.Object)
*/
public void removeNode(Object n) {
Assertions.UNREACHABLE();
}
/*
* (non-Javadoc)
*
* @see com.ibm.wala.util.graph.NodeManager#containsNode(java.lang.Object)
*/
public boolean containsNode(Object n) {
return pointsToMap.getPointsToSet((PointerKey) n) != null;
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#toString()
*/
public String toString() {
int n = 0;
StringBuffer s = new StringBuffer("dataflow nodes:\n");
for (Iterator i = iterateNodes(); i.hasNext();)
s.append(n++ + ":\t " + i.next() + "\n");
return s.toString();
}
}

View File

@ -291,15 +291,6 @@ public class PropagationGraph extends AbstractFixedPointSystem {
implicitUnaryCount--;
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#equals(java.lang.Object)
*/
public boolean equals(Object obj) {
Assertions.UNREACHABLE();
return false;
}
@SuppressWarnings("unchecked")
public Iterator<AbstractStatement> getStatements() {
@ -491,16 +482,6 @@ public class PropagationGraph extends AbstractFixedPointSystem {
}
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#hashCode()
*/
public int hashCode() {
Assertions.UNREACHABLE();
return 0;
}
/**
* @param eq
*/

View File

@ -149,9 +149,9 @@ public class SymbolTable {
* @param i
* @return int
*/
public int getParameter(int i) {
if (Assertions.verifyAssertions && parameters.length <= i) {
Assertions.UNREACHABLE("parameters too small for index " + i + ", length = " + parameters.length);
public int getParameter(int i) throws IllegalArgumentException {
if (parameters.length <= i) {
throw new IllegalArgumentException("parameters too small for index " + i + ", length = " + parameters.length);
}
return parameters[i];
}
@ -270,23 +270,26 @@ public class SymbolTable {
return parameters.length;
}
public String getStringValue(int v) {
if (Assertions.verifyAssertions)
Assertions._assert(isStringConstant(v));
public String getStringValue(int v) throws IllegalArgumentException {
if (!isStringConstant(v)) {
throw new IllegalArgumentException("not a string constant: value number " + v);
}
return (String) ((ConstantValue) values[v]).getValue();
}
public double getDoubleValue(int v) {
if (Assertions.verifyAssertions)
Assertions._assert(isNumberConstant(v));
public double getDoubleValue(int v) throws IllegalArgumentException {
if (!isNumberConstant(v)) {
throw new IllegalArgumentException("value number " + v + " is not a numeric constant.");
}
return ((Number) ((ConstantValue) values[v]).getValue()).doubleValue();
}
public Object getConstantValue(int v) {
if (Assertions.verifyAssertions)
Assertions._assert(isConstant(v));
public Object getConstantValue(int v) throws IllegalArgumentException{
if (!isConstant(v)) {
throw new IllegalArgumentException("value number " + v + " is not a constant.");
}
Object value = ((ConstantValue) values[v]).getValue();
if (value == null) {

View File

@ -51,7 +51,7 @@ public final class TypeName {
*/
private final TypeNameKey key;
public static TypeName findOrCreate(ImmutableByteArray name, int start, int length) {
public static TypeName findOrCreate(ImmutableByteArray name, int start, int length) throws IllegalArgumentException {
Atom className = Atom.findOrCreate(StringStuff.parseForClass(name, start, length));
ImmutableByteArray p = StringStuff.parseForPackage(name, start, length);
@ -65,7 +65,7 @@ public final class TypeName {
return findOrCreate(t);
}
public static TypeName findOrCreate(ImmutableByteArray name) {
public static TypeName findOrCreate(ImmutableByteArray name) throws IllegalArgumentException {
return findOrCreate(name, 0, name.length());
}
@ -131,7 +131,7 @@ public final class TypeName {
* a String like Ljava/lang/Object
* @return the corresponding TypeName
*/
public static TypeName string2TypeName(String s) {
public static TypeName string2TypeName(String s) throws IllegalArgumentException {
byte[] val = s.getBytes();
return findOrCreate(new ImmutableByteArray(val));

View File

@ -331,6 +331,9 @@ public final class Atom {
}
public static boolean isArrayDescriptor(ImmutableByteArray b) {
if (b.length() == 0) {
return false;
}
return b.get(0) == '[';
}
}

View File

@ -168,7 +168,7 @@ public class StringStuff {
/**
* Parse method descriptor to obtain descriptions of method's parameters.
*
* @return parameter descriptions, or null if there are no parameters
*/
public static final TypeName[] parseForParameterNames(ImmutableByteArray b) {
@ -302,7 +302,10 @@ public class StringStuff {
* @return an ImmutableByteArray that represents the package, or null if it's
* the unnamed package
*/
public static ImmutableByteArray parseForClass(ImmutableByteArray name, int start, int length) {
public static ImmutableByteArray parseForClass(ImmutableByteArray name, int start, int length) throws IllegalArgumentException {
if (name.length() == 0) {
throw new IllegalArgumentException("invalid class name: zero length");
}
if (parseForPackage(name, start, length) == null) {
while (name.b[start] == '[') {
start++;
@ -403,10 +406,10 @@ public class StringStuff {
String type = methodSig.substring(0, methodSig.lastIndexOf('.'));
type = deployment2CanonicalTypeString(type);
TypeReference t = TypeReference.findOrCreate(ClassLoaderReference.Application, type);
String methodName = methodSig.substring(methodSig.lastIndexOf('.') + 1, methodSig.indexOf('('));
String desc = methodSig.substring(methodSig.indexOf('('));
return MethodReference.findOrCreate(t, methodName, desc);
}
@ -420,7 +423,7 @@ public class StringStuff {
public static String jvmToReadableType(String jvmType) {
StringBuffer readable = new StringBuffer(); // human readable version
int numberOfDimensions = 0; // the number of array dimensions
// cycle through prefixes of '['
char prefix = jvmType.charAt(0);
while (prefix == '[') {
@ -483,15 +486,15 @@ public class StringStuff {
}
return dotForm.toString();
}
/**
* Convert '$' to '.' in names.
*
* @param a
* String object in which dollar signs('$') must be converted to
* dots ('.').
* @return a String object obtained by replacing the dollar signs ('S') in
* the String passed as argument with ('.').
* String object in which dollar signs('$') must be converted to dots
* ('.').
* @return a String object obtained by replacing the dollar signs ('S') in the
* String passed as argument with ('.').
*/
public static String dollarToDot(String path) {
StringBuffer dotForm = new StringBuffer(path);

View File

@ -11,6 +11,7 @@
package com.ibm.wala.util.collections;
import java.util.Iterator;
import java.util.NoSuchElementException;
/**
*
@ -73,14 +74,17 @@ public class ArrayIterator<T> implements Iterator<T> {
/* (non-Javadoc)
* @see java.util.Iterator#next()
*/
public T next() {
public T next() throws NoSuchElementException {
if (_cnt >= _elts.length) {
throw new NoSuchElementException();
}
return _elts[_cnt++];
}
/* (non-Javadoc)
* @see java.util.Iterator#remove()
*/
public void remove() {
public void remove() throws UnsupportedOperationException {
throw new UnsupportedOperationException();
}
}

View File

@ -63,7 +63,7 @@ public abstract class Heap {
/**
* @return the first object in the priority queue
*/
public Object take() {
public Object take() throws NoSuchElementException {
if (numberOfElements == 0) {
throw new NoSuchElementException();
}

View File

@ -10,7 +10,7 @@
*******************************************************************************/
package com.ibm.wala.util.collections;
import com.ibm.wala.util.debug.Assertions;
import java.util.EmptyStackException;
/**
*
@ -45,8 +45,10 @@ public class IntStack {
/**
* @return the int at the top of the stack
*/
public int peek() {
Assertions._assert(! isEmpty());
public int peek() throws EmptyStackException {
if (isEmpty()) {
throw new EmptyStackException();
}
return state[top];
}
@ -54,8 +56,10 @@ public class IntStack {
* pop the stack
* @return the int at the top of the stack
*/
public int pop() {
Assertions._assert(! isEmpty());
public int pop() throws EmptyStackException{
if (isEmpty()) {
throw new EmptyStackException();
}
return state[top--];
}

View File

@ -12,25 +12,28 @@ package com.ibm.wala.util.collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.NoSuchElementException;
import com.ibm.wala.util.debug.Assertions;
import com.ibm.wala.util.debug.UnimplementedError;
import com.ibm.wala.util.intset.OrdinalSet;
import com.ibm.wala.util.intset.OrdinalSetMapping;
/**
*
* A bit set mapping based on an immutable object array.
* This is not terribly efficient, but is useful for prototyping.
*
* A bit set mapping based on an immutable object array. This is not terribly
* efficient, but is useful for prototyping.
*
* @author sfink
*/
public class ObjectArrayMapping<T> implements OrdinalSetMapping<T> {
private T[] array;
/**
* A mapping from object to Integer
*/
private HashMap<T,Integer> map = HashMapFactory.make();
private HashMap<T, Integer> map = HashMapFactory.make();
/**
* Constructor for ObjectArrayMapping.
@ -42,21 +45,22 @@ public class ObjectArrayMapping<T> implements OrdinalSetMapping<T> {
}
}
/* (non-Javadoc)
/*
* (non-Javadoc)
*/
public T getMappedObject(int n) {
public T getMappedObject(int n) throws NoSuchElementException {
if (n >= array.length) {
throw new NoSuchElementException("n too big: " + n);
}
return array[n];
}
/* (non-Javadoc)
/*
* (non-Javadoc)
*/
public int getMappedIndex(Object o) {
if (Assertions.verifyAssertions) {
if (map.get(o) == null) {
Assertions.UNREACHABLE("unmapped object " + o);
}
if (map.get(o) == null) {
return -1;
}
return map.get(o).intValue();
}
@ -65,31 +69,33 @@ public class ObjectArrayMapping<T> implements OrdinalSetMapping<T> {
return map.get(o) != null;
}
/* (non-Javadoc)
/*
* (non-Javadoc)
*/
public int getMappingSize() {
return array.length;
}
/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see com.ibm.wala.util.intset.OrdinalSetMapping#iterator()
*/
public Iterator<T> iterator() {
return map.keySet().iterator();
}
/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see com.ibm.wala.util.intset.OrdinalSetMapping#makeSingleton(int)
*/
public OrdinalSet makeSingleton(int i) {
// TODO Auto-generated method stub
public OrdinalSet makeSingleton(int i) throws UnimplementedError {
Assertions.UNREACHABLE();
return null;
}
public int add(Object o) {
public int add(Object o) throws UnimplementedError {
Assertions.UNREACHABLE();
return 0;
}

View File

@ -15,6 +15,7 @@ import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import com.ibm.wala.annotations.Internal;
import com.ibm.wala.util.debug.Assertions;
/**
@ -24,6 +25,7 @@ import com.ibm.wala.util.debug.Assertions;
*
* @author sfink
*/
@Internal
public class ParanoidHashMap<K,V> extends HashMap<K,V> {
public static final long serialVersionUID = 909018793791787198L;

View File

@ -16,6 +16,7 @@ import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import com.ibm.wala.annotations.Internal;
import com.ibm.wala.util.debug.Assertions;
/**
@ -26,6 +27,7 @@ import com.ibm.wala.util.debug.Assertions;
*
* @author sfink
*/
@Internal
public class ParanoidHashSet<T> extends HashSet<T> {
public static final long serialVersionUID = 30919839181133333L;

View File

@ -14,7 +14,7 @@ import java.util.NoSuchElementException;
/**
* @author unknown
*
*
* TODO: document me!
*/
public class Queue<T> {
@ -64,9 +64,10 @@ public class Queue<T> {
}
@SuppressWarnings("unchecked")
public T dequeue() {
if (isEmpty())
public T dequeue() throws NoSuchElementException {
if (isEmpty()) {
throw new NoSuchElementException();
}
T result = (T) items[first];

View File

@ -17,6 +17,7 @@ import java.util.Map;
import java.util.Set;
import com.ibm.wala.util.debug.Assertions;
import com.ibm.wala.util.debug.UnimplementedError;
/**
*
@ -55,7 +56,10 @@ public class SmallMap<K,V> implements Map<K,V> {
* @param i
* @return the ith key
*/
public Object getKey(int i) {
public Object getKey(int i) throws IllegalStateException {
if (keysAndValues == null) {
throw new IllegalStateException("getKey on empty map");
}
return keysAndValues[i];
}
@ -65,7 +69,10 @@ public class SmallMap<K,V> implements Map<K,V> {
* @param i
* @return the ith key
*/
public Object getValue(int i) {
public Object getValue(int i) throws IllegalStateException{
if (keysAndValues == null) {
throw new IllegalStateException("getValue on empty map");
}
return keysAndValues[size() + i];
}
@ -98,6 +105,9 @@ public class SmallMap<K,V> implements Map<K,V> {
* @see java.util.Map#containsValue(java.lang.Object)
*/
public boolean containsValue(Object value) {
if (keysAndValues == null) {
return false;
}
for (int i = size(); i < keysAndValues.length; i++) {
if (keysAndValues[i].equals(value)) {
return true;
@ -165,9 +175,8 @@ public class SmallMap<K,V> implements Map<K,V> {
*
* @see java.util.Map#remove(java.lang.Object)
*/
public V remove(Object key) {
Assertions.UNREACHABLE();
return null;
public V remove(Object key) throws UnsupportedOperationException {
throw new UnsupportedOperationException();
}
/*
@ -226,7 +235,7 @@ public class SmallMap<K,V> implements Map<K,V> {
*
* @see java.util.Map#entrySet()
*/
public Set<Map.Entry<K,V>> entrySet() {
public Set<Map.Entry<K,V>> entrySet() throws UnimplementedError {
Assertions.UNREACHABLE("must implement entrySet");
return null;
}

View File

@ -14,11 +14,11 @@ import java.io.*;
import java.util.Collection;
import java.util.Iterator;
/**
* Simple utility for printing trace messages.
*
* TODO: should this be nuked and replaced with some java.util.Logging functions?
* TODO: should this be nuked and replaced with some java.util.Logging
* functions?
*
* @author sfink
*
@ -28,6 +28,7 @@ public class Trace {
private static final String TRACEFILE_KEY = "com.ibm.wala.tracefile";
private static String traceFile = null;
private static PrintStream out = null;
public synchronized static void setTraceFile(String fileName) {
@ -104,11 +105,17 @@ public class Trace {
}
public static void flush() {
out.flush();
if (setTraceFile()) {
out.flush();
}
}
public static PrintWriter getTraceWriter() {
return new PrintWriter(out);
if (setTraceFile()) {
return new PrintWriter(out);
} else {
return null;
}
}
/**

View File

@ -15,6 +15,7 @@ import java.util.Iterator;
import com.ibm.wala.util.collections.EmptyIterator;
import com.ibm.wala.util.debug.Assertions;
import com.ibm.wala.util.graph.EdgeManager;
import com.ibm.wala.util.graph.INodeWithNumber;
import com.ibm.wala.util.graph.INodeWithNumberedEdges;
import com.ibm.wala.util.intset.IntIterator;
import com.ibm.wala.util.intset.IntSet;
@ -22,45 +23,51 @@ import com.ibm.wala.util.intset.IntSet;
/**
*
* An object that delegates edge management to the nodes, INodeWithNumberedEdges
*
* @author sfink
*
*
*/
public class DelegatingNumberedEdgeManager implements EdgeManager {
public class DelegatingNumberedEdgeManager<T extends INodeWithNumber> implements EdgeManager<T> {
private final DelegatingNumberedNodeManager<T> nodeManager;
private final DelegatingNumberedNodeManager nodeManager;
/**
*
*/
public DelegatingNumberedEdgeManager(DelegatingNumberedNodeManager nodeManager) {
public DelegatingNumberedEdgeManager(DelegatingNumberedNodeManager<T> nodeManager) {
this.nodeManager = nodeManager;
}
// TODO: optimization is possible
private class IntSetNodeIterator implements Iterator {
private class IntSetNodeIterator implements Iterator<T> {
private final IntIterator delegate;
IntSetNodeIterator(IntIterator delegate) {
this.delegate = delegate;
}
/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see java.util.Iterator#hasNext()
*/
public boolean hasNext() {
return delegate.hasNext();
}
/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see java.util.Iterator#next()
*/
public Object next() {
return nodeManager.getNode(delegate.next());
public T next() {
return nodeManager.getNode(delegate.next());
}
/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see java.util.Iterator#remove()
*/
public void remove() {
@ -68,77 +75,98 @@ public class DelegatingNumberedEdgeManager implements EdgeManager {
Assertions.UNREACHABLE();
}
}
/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see com.ibm.wala.util.graph.EdgeManager#getPredNodes(com.ibm.wala.util.graph.Node)
*/
public Iterator getPredNodes(Object N) {
INodeWithNumberedEdges en = (INodeWithNumberedEdges)N;
public Iterator<T> getPredNodes(T N) {
INodeWithNumberedEdges en = (INodeWithNumberedEdges) N;
IntSet pred = en.getPredNumbers();
return (pred == null) ? (Iterator)EmptyIterator.instance() : (Iterator)new IntSetNodeIterator(pred.intIterator());
Iterator<T> empty = EmptyIterator.instance();
return (pred == null) ? empty : (Iterator<T>) new IntSetNodeIterator(pred.intIterator());
}
/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see com.ibm.wala.util.graph.EdgeManager#getPredNodeCount(com.ibm.wala.util.graph.Node)
*/
public int getPredNodeCount(Object N) {
INodeWithNumberedEdges en = (INodeWithNumberedEdges)N;
public int getPredNodeCount(T N) {
INodeWithNumberedEdges en = (INodeWithNumberedEdges) N;
return en.getPredNumbers().size();
}
/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see com.ibm.wala.util.graph.EdgeManager#getSuccNodes(com.ibm.wala.util.graph.Node)
*/
public Iterator getSuccNodes(Object N) {
INodeWithNumberedEdges en = (INodeWithNumberedEdges)N;
public Iterator<T> getSuccNodes(T N) {
INodeWithNumberedEdges en = (INodeWithNumberedEdges) N;
IntSet succ = en.getSuccNumbers();
return (succ == null) ? (Iterator)EmptyIterator.instance() : (Iterator)new IntSetNodeIterator(succ.intIterator());
Iterator<T> empty = EmptyIterator.instance();
return (succ == null) ? empty: (Iterator<T>) new IntSetNodeIterator(succ.intIterator());
}
/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see com.ibm.wala.util.graph.EdgeManager#getSuccNodeCount(com.ibm.wala.util.graph.Node)
*/
public int getSuccNodeCount(Object N) {
INodeWithNumberedEdges en = (INodeWithNumberedEdges)N;
public int getSuccNodeCount(T N) {
INodeWithNumberedEdges en = (INodeWithNumberedEdges) N;
return en.getSuccNumbers().size();
}
/* (non-Javadoc)
* @see com.ibm.wala.util.graph.EdgeManager#addEdge(com.ibm.wala.util.graph.Node, com.ibm.wala.util.graph.Node)
/*
* (non-Javadoc)
*
* @see com.ibm.wala.util.graph.EdgeManager#addEdge(com.ibm.wala.util.graph.Node,
* com.ibm.wala.util.graph.Node)
*/
public void addEdge(Object src, Object dst) {
Assertions.UNREACHABLE();
}
public void removeEdge(Object src, Object dst) {
public void addEdge(T src, T dst) {
Assertions.UNREACHABLE();
}
/* (non-Javadoc)
public void removeEdge(T src, T dst) {
Assertions.UNREACHABLE();
}
/*
* (non-Javadoc)
*
* @see com.ibm.wala.util.graph.EdgeManager#removeEdges(com.ibm.wala.util.graph.Node)
*/
public void removeAllIncidentEdges(Object node) {
INodeWithNumberedEdges n = (INodeWithNumberedEdges)node;
public void removeAllIncidentEdges(T node) {
INodeWithNumberedEdges n = (INodeWithNumberedEdges) node;
n.removeAllIncidentEdges();
}
/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see com.ibm.wala.util.graph.EdgeManager#removeEdges(com.ibm.wala.util.graph.Node)
*/
public void removeIncomingEdges(Object node) {
INodeWithNumberedEdges n = (INodeWithNumberedEdges)node;
public void removeIncomingEdges(T node) {
INodeWithNumberedEdges n = (INodeWithNumberedEdges) node;
n.removeIncomingEdges();
}
/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see com.ibm.wala.util.graph.EdgeManager#removeEdges(com.ibm.wala.util.graph.Node)
*/
public void removeOutgoingEdges(Object node) {
INodeWithNumberedEdges n = (INodeWithNumberedEdges)node;
public void removeOutgoingEdges(T node) {
INodeWithNumberedEdges n = (INodeWithNumberedEdges) node;
n.removeOutgoingEdges();
}
/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see java.lang.Object#toString()
*/
public String toString() {
@ -147,9 +175,10 @@ public class DelegatingNumberedEdgeManager implements EdgeManager {
return super.toString();
}
/* (non-Javadoc)
/*
* (non-Javadoc)
*/
public boolean hasEdge(Object src, Object dst) {
public boolean hasEdge(T src, T dst) {
Assertions.UNREACHABLE("implement me");
return false;
}

View File

@ -12,28 +12,29 @@ package com.ibm.wala.util.graph.impl;
import com.ibm.wala.util.graph.AbstractNumberedGraph;
import com.ibm.wala.util.graph.EdgeManager;
import com.ibm.wala.util.graph.INodeWithNumber;
import com.ibm.wala.util.graph.NodeManager;
/**
* @author sfink
*/
public class DelegatingNumberedGraph extends AbstractNumberedGraph {
public class DelegatingNumberedGraph<T extends INodeWithNumber> extends AbstractNumberedGraph<T> {
private DelegatingNumberedNodeManager nodeManager = new DelegatingNumberedNodeManager();
private DelegatingNumberedEdgeManager edgeManager = new DelegatingNumberedEdgeManager(nodeManager);
private DelegatingNumberedNodeManager<T> nodeManager = new DelegatingNumberedNodeManager<T>();
private DelegatingNumberedEdgeManager<T> edgeManager = new DelegatingNumberedEdgeManager<T>(nodeManager);
/* (non-Javadoc)
* @see com.ibm.wala.util.graph.AbstractGraph#getNodeManager()
*/
protected NodeManager getNodeManager() {
protected NodeManager<T> getNodeManager() {
return nodeManager;
}
/* (non-Javadoc)
* @see com.ibm.wala.util.graph.AbstractGraph#getEdgeManager()
*/
protected EdgeManager getEdgeManager() {
protected EdgeManager<T> getEdgeManager() {
return edgeManager;
}
}

View File

@ -44,8 +44,9 @@ public class SlowNumberedNodeManager<T> implements NumberedNodeManager<T> {
*
* @see com.ibm.wala.util.graph.NumberedGraph#getNode(int)
*/
public T getNode(int number) {
public T getNode(int number) {
T result = (T) map.getMappedObject(number);
if (Assertions.verifyAssertions) {
Assertions._assert(getNumber(result) == number);
}

View File

@ -247,7 +247,7 @@ public class BimodalMutableIntSet implements MutableIntSet {
*
* @see com.ibm.wala.util.intset.IntSet#max()
*/
public int max() {
public int max() throws IllegalStateException{
return impl.max();
}

View File

@ -32,7 +32,7 @@ public class BimodalMutableIntSetFactory implements MutableIntSetFactory {
/**
* @param string
*/
public MutableIntSet parse(String string) {
public MutableIntSet parse(String string) throws NumberFormatException {
BimodalMutableIntSet result = new BimodalMutableIntSet();
result.impl = factory.parse(string);
return result;

View File

@ -104,10 +104,11 @@ abstract public class BitVectorBase<T extends BitVectorBase>
/**
* Clones the FixedSizeBitVector.
*/
@SuppressWarnings("unchecked")
public Object clone() {
BitVector result = null;
BitVectorBase<T> result = null;
try {
result = (BitVector) super.clone();
result = (BitVectorBase<T>) super.clone();
} catch (CloneNotSupportedException e) {
// this shouldn't happen, since we are Cloneable
throw new InternalError();

View File

@ -42,11 +42,12 @@ public class BitVectorIntSetFactory implements MutableIntSetFactory {
/**
* @param string
*/
public MutableIntSet parse(String string) {
public MutableIntSet parse(String string) throws NumberFormatException {
int[] data = SparseIntSet.parseIntArray(string);
MutableIntSet result = new BitVectorIntSet();
for (int i = 0; i < data.length; i++)
for (int i = 0; i < data.length; i++) {
result.add(data[i]);
}
return result;
}

View File

@ -26,7 +26,7 @@ public class IntSetUtil {
static {
MutableIntSetFactory defaultFactory = new MutableSharedBitVectorIntSetFactory();
if (System.getProperties().containsKey(INT_SET_FACTORY_CONFIG_PROPERTY_NAME)) {
if (System.getProperty(INT_SET_FACTORY_CONFIG_PROPERTY_NAME) != null) {
try {
Class intSetFactoryClass = Class.forName(System.getProperty(INT_SET_FACTORY_CONFIG_PROPERTY_NAME));
MutableIntSetFactory intSetFactory = (MutableIntSetFactory) intSetFactoryClass.newInstance();

View File

@ -37,7 +37,7 @@ public class MutableSharedBitVectorIntSetFactory implements MutableIntSetFactory
*
* @see com.ibm.wala.util.intset.MutableIntSetFactory#parse(java.lang.String)
*/
public MutableIntSet parse(String string) {
public MutableIntSet parse(String string) throws NumberFormatException {
SparseIntSet s = (SparseIntSet) sparseFactory.parse(string);
return new MutableSharedBitVectorIntSet(s);
}

View File

@ -14,52 +14,56 @@ import java.util.Iterator;
import java.util.TreeSet;
/**
*
*
* An object that creates mutable sparse int sets.
*
* @author sfink
*/
public class MutableSparseIntSetFactory implements MutableIntSetFactory {
/**
* @param set
*/
public MutableIntSet make(int[] set) {
if (set.length == 0) {
return new MutableSparseIntSet();
} else {
// XXX not very efficient.
TreeSet<Integer> T = new TreeSet<Integer>();
for (int i = 0; i < set.length; i++) {
T.add(new Integer(set[i]));
}
int[] copy = new int[T.size()];
int i = 0;
for (Iterator<Integer> it = T.iterator(); it.hasNext();) {
Integer I = it.next();
copy[i++] = I.intValue();
}
MutableSparseIntSet result = new MutableSparseIntSet(copy);
return result;
}
}
/**
* @param set
*/
public MutableIntSet make(int[] set) {
if (set.length == 0) {
return new MutableSparseIntSet();
} else {
// XXX not very efficient.
TreeSet<Integer> T = new TreeSet<Integer>();
for (int i = 0; i < set.length; i++) {
T.add(new Integer(set[i]));
}
int[] copy = new int[T.size()];
int i = 0;
for (Iterator<Integer> it = T.iterator(); it.hasNext();) {
Integer I = it.next();
copy[i++] = I.intValue();
}
MutableSparseIntSet result = new MutableSparseIntSet(copy);
return result;
}
}
/**
* @param string
*/
public MutableIntSet parse(String string) {
int[] backingStore = SparseIntSet.parseIntArray(string);
return new MutableSparseIntSet(backingStore);
}
/**
* @param string
*/
public MutableIntSet parse(String string) throws NumberFormatException {
int[] backingStore = SparseIntSet.parseIntArray(string);
return new MutableSparseIntSet(backingStore);
}
/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see com.ibm.wala.util.intset.MutableIntSetFactory#make(com.ibm.wala.util.intset.IntSet)
*/
public MutableIntSet makeCopy(IntSet x) {
return new MutableSparseIntSet(x);
}
/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see com.ibm.wala.util.intset.MutableIntSetFactory#make()
*/
public MutableIntSet make() {

View File

@ -11,6 +11,7 @@
package com.ibm.wala.util.intset;
import com.ibm.wala.util.debug.Assertions;
import com.ibm.wala.util.debug.UnimplementedError;
/**
* A sparse ordered, mutable duplicate-free, fully-encapsulated set of longs.
@ -357,13 +358,8 @@ public final class MutableSparseLongSet extends SparseLongSet implements Mutable
}
/**
* TODO optimize
*
* @param set
*/
public void removeAll(MutableSparseLongSet set) {
Assertions.UNREACHABLE();
public void removeAll(MutableSparseLongSet set) throws UnimplementedError {
Assertions.UNREACHABLE("implement me");
}
}

View File

@ -10,6 +10,8 @@
*******************************************************************************/
package com.ibm.wala.util.intset;
import java.util.NoSuchElementException;
/**
* An object that implements a bijection between whole numbers and
@ -19,9 +21,9 @@ package com.ibm.wala.util.intset;
*/
public interface OrdinalSetMapping<T> extends Iterable<T> {
/**
* @return the object numbered n.
* @return the object numbered n.
*/
public T getMappedObject(int n);
public T getMappedObject(int n) throws NoSuchElementException;
/**
* @return the number of a given object, or -1 if the object is not

View File

@ -314,7 +314,7 @@ public class SemiSparseMutableIntSet implements MutableIntSet {
/**
* @return maximum integer in this set.
*/
public int max() {
public int max() throws IllegalStateException {
if (densePart == null) {
return sparsePart.max();
} else {

View File

@ -11,6 +11,7 @@
package com.ibm.wala.util.intset;
import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.StringTokenizer;
import java.util.TreeSet;
@ -149,9 +150,9 @@ public class SparseIntSet implements IntSet {
/**
* @param idx
*/
public final int elementAt(int idx) {
if (Assertions.verifyAssertions) {
Assertions._assert(idx < size);
public final int elementAt(int idx) throws NoSuchElementException {
if (elements == null || idx >= size) {
throw new NoSuchElementException("Index: " + idx);
}
return elements[idx];
}
@ -351,9 +352,9 @@ public class SparseIntSet implements IntSet {
}
}
public static SparseIntSet pair(int i, int j) {
if (Assertions.verifyAssertions) {
Assertions._assert(i != j);
public static SparseIntSet pair(int i, int j) {
if (i == j) {
return SparseIntSet.singleton(i);
}
if (j > i) {
return new SparseIntSet(new int[] { i, j });
@ -411,7 +412,10 @@ public class SparseIntSet implements IntSet {
/**
* @return the largest element in the set
*/
public final int max() {
public final int max() throws IllegalStateException {
if (elements == null) {
throw new IllegalStateException("Illegal to ask max() on an empty int set");
}
return elements[size - 1];
}

View File

@ -11,6 +11,7 @@
package com.ibm.wala.util.intset;
import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.StringTokenizer;
import java.util.TreeSet;
@ -142,9 +143,9 @@ public class SparseLongSet implements LongSet {
return size == 0;
}
public final long elementAt(int idx) {
if (Assertions.verifyAssertions) {
Assertions._assert(idx < size);
public final long elementAt(int idx) throws NoSuchElementException {
if (idx >= size) {
throw new NoSuchElementException();
}
return elements[idx];
}
@ -319,7 +320,6 @@ public class SparseLongSet implements LongSet {
return result;
}
public static SparseLongSet singleton(int i) {
if (i >= 0 && i < SINGLETON_CACHE_SIZE) {
return singletonCache[i];
@ -355,7 +355,10 @@ public class SparseLongSet implements LongSet {
/**
* @return the largest element in the set
*/
public final long max() {
public final long max() throws IllegalStateException {
if (elements == null) {
throw new IllegalStateException("Illegal to ask max() on an empty int set");
}
return elements[size - 1];
}

View File

@ -132,7 +132,7 @@ public class SparseVector<T> implements IVector<T> {
/**
* @return max i s.t get(i) != null
*/
public int getMaxIndex() {
public int getMaxIndex() throws IllegalStateException {
return indices.max();
}

View File

@ -36,9 +36,9 @@ public class Logs {
/**
* @param x where x == 2^n for some integral n
*/
public static int log2(int x) {
if (Assertions.verifyAssertions) {
Assertions._assert(isPowerOf2(x));
public static int log2(int x) throws IllegalArgumentException {
if (!isPowerOf2(x)) {
throw new IllegalArgumentException();
}
int test = 1;
for (int i =0 ; i<31; i++) {