Clover coverage report - DynamicJava Test Coverage (dynamicjava-20110903-r5436)
Coverage timestamp: Sat Sep 3 2011 03:02:20 CDT
file stats: LOC: 182   Methods: 31
NCLOC: 113   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ClassContext.java 26.9% 45.8% 41.9% 40%
coverage coverage
 1    package edu.rice.cs.dynamicjava.interpreter;
 2   
 3    import java.util.Iterator;
 4    import edu.rice.cs.plt.iter.SequenceIterator;
 5    import edu.rice.cs.plt.iter.IterUtil;
 6    import edu.rice.cs.plt.lambda.LambdaUtil;
 7    import edu.rice.cs.dynamicjava.symbol.*;
 8    import edu.rice.cs.dynamicjava.symbol.type.Type;
 9    import edu.rice.cs.dynamicjava.symbol.type.ClassType;
 10    import edu.rice.cs.dynamicjava.symbol.type.VariableType;
 11   
 12    import static edu.rice.cs.plt.debug.DebugUtil.debug;
 13   
 14    /**
 15    * The context of a class body, including all members of the class (both declared and inherited).
 16    */
 17    public class ClassContext extends DelegatingContext {
 18   
 19    private final DJClass _c;
 20    private final ClassType _thisType;
 21    private final Iterator<Integer> _anonymousCounter;
 22   
 23  267 public ClassContext(TypeContext next, DJClass c) {
 24  267 super(next);
 25  267 _c = c;
 26  267 _thisType = SymbolUtil.thisType(c);
 27  267 _anonymousCounter = new SequenceIterator<Integer>(1, LambdaUtil.INCREMENT_INT);
 28    }
 29   
 30  0 private ClassContext(TypeContext next, DJClass c, Iterator<Integer> anonymousCounter) {
 31  0 super(next);
 32  0 _c = c;
 33  0 _thisType = SymbolUtil.thisType(c);
 34  0 _anonymousCounter = anonymousCounter;
 35    }
 36   
 37  0 protected ClassContext duplicate(TypeContext next) {
 38  0 return new ClassContext(next, _c, _anonymousCounter);
 39    }
 40   
 41    // Class and type variable names:
 42   
 43  3 @Override public boolean typeExists(String name, TypeSystem ts) {
 44  3 return hasMemberClass(name, ts) || super.typeExists(name, ts);
 45    }
 46   
 47  0 @Override public boolean memberClassExists(String name, TypeSystem ts) {
 48  0 return hasMemberClass(name, ts) || super.memberClassExists(name, ts);
 49    }
 50   
 51  6 @Override public ClassType typeContainingMemberClass(String name, TypeSystem ts) throws AmbiguousNameException {
 52  6 debug.logStart(new String[]{"class","name"}, _c, name); try {
 53   
 54  0 if (hasMemberClass(name, ts)) { return _thisType; }
 55  6 else { return super.typeContainingMemberClass(name, ts); }
 56   
 57  6 } finally { debug.logEnd(); }
 58    }
 59   
 60  0 @Override public boolean topLevelClassExists(String name, TypeSystem ts) {
 61  0 return hasMemberClass(name, ts) ? false : super.topLevelClassExists(name, ts);
 62    }
 63   
 64  371 @Override public DJClass getTopLevelClass(String name, TypeSystem ts) throws AmbiguousNameException {
 65  371 return hasMemberClass(name, ts) ? null : super.getTopLevelClass(name, ts);
 66    }
 67   
 68  0 @Override public boolean typeVariableExists(String name, TypeSystem ts) {
 69  0 return hasMemberClass(name, ts) ? false : super.typeVariableExists(name, ts);
 70    }
 71   
 72  144 @Override public VariableType getTypeVariable(String name, TypeSystem ts) {
 73  144 return hasMemberClass(name, ts) ? null : super.getTypeVariable(name, ts);
 74    }
 75   
 76  524 private boolean hasMemberClass(String name, TypeSystem ts) {
 77  524 return ts.containsClass(_thisType, name, accessModule());
 78    }
 79   
 80    // Variable and field names:
 81   
 82  46 @Override public boolean variableExists(String name, TypeSystem ts) {
 83  46 return hasField(name, ts) || super.variableExists(name, ts);
 84    }
 85   
 86  72 @Override public boolean fieldExists(String name, TypeSystem ts) {
 87  72 return hasField(name, ts) || super.fieldExists(name, ts);
 88    }
 89   
 90  69 @Override public ClassType typeContainingField(String name, TypeSystem ts) throws AmbiguousNameException {
 91  69 if (hasField(name, ts)) { return _thisType; }
 92  0 else { return super.typeContainingField(name, ts); }
 93    }
 94   
 95  72 @Override public boolean localVariableExists(String name, TypeSystem ts) {
 96  72 return hasField(name, ts) ? false : super.localVariableExists(name, ts);
 97    }
 98   
 99  0 @Override public LocalVariable getLocalVariable(String name, TypeSystem ts) {
 100  0 return hasField(name, ts) ? null : super.getLocalVariable(name, ts);
 101    }
 102   
 103  259 private boolean hasField(String name, TypeSystem ts) {
 104  259 return ts.containsField(_thisType, name, accessModule());
 105    }
 106   
 107    // Method and local function names:
 108   
 109  0 @Override public boolean functionExists(String name, TypeSystem ts) {
 110  0 return hasMethod(name, ts) || super.functionExists(name, ts);
 111    }
 112   
 113  0 @Override public boolean methodExists(String name, TypeSystem ts) {
 114  0 return hasMethod(name, ts) || super.methodExists(name, ts);
 115    }
 116   
 117  0 @Override public Type typeContainingMethod(String name, TypeSystem ts) {
 118  0 return hasMethod(name, ts) ? _thisType : super.typeContainingMethod(name, ts);
 119    }
 120   
 121  0 @Override public boolean localFunctionExists(String name, TypeSystem ts) {
 122  0 return hasMethod(name, ts) ? false : super.localFunctionExists(name, ts);
 123    }
 124   
 125  0 @Override public Iterable<LocalFunction> getLocalFunctions(String name, TypeSystem ts,
 126    Iterable<LocalFunction> partial) {
 127  0 return !IterUtil.isEmpty(partial) || hasMethod(name, ts) ? partial : super.getLocalFunctions(name, ts, partial);
 128    }
 129   
 130   
 131   
 132   
 133  0 private boolean hasMethod(String name, TypeSystem ts) {
 134  0 return ts.containsMethod(_thisType, name, accessModule());
 135    }
 136   
 137   
 138    /** Return a full name for a class with the given name declared here. */
 139  0 @Override public String makeClassName(String n) {
 140  0 return _c.fullName() + "$" + n;
 141    }
 142   
 143    /** Return a full name for an anonymous class declared here. */
 144  0 @Override public String makeAnonymousClassName() {
 145  0 return makeClassName(_anonymousCounter.next().toString());
 146    }
 147   
 148    /**
 149    * Return the class of {@code this} in the current context, or {@code null}
 150    * if there is no such value (for example, in a static context).
 151    */
 152  69 @Override public DJClass getThis() { return _c; }
 153   
 154    /**
 155    * Return the class of {@code className.this} in the current context, or {@code null}
 156    * if there is no such value (for example, in a static context).
 157    */
 158  0 @Override public DJClass getThis(String className) {
 159  0 if (!_c.isAnonymous() && className.equals(_c.declaredName())) { return _c; }
 160  0 else { return super.getThis(className); }
 161    }
 162   
 163  69 @Override public DJClass getThis(Type expected, TypeSystem ts) {
 164  69 if (ts.isSubtype(_thisType, expected)) { return _c; }
 165  0 else { return super.getThis(expected, ts); }
 166    }
 167   
 168  0 @Override public DJClass initializingClass() { return null; }
 169   
 170    /**
 171    * The expected type of a {@code return} statement in the given context, or {@code null}
 172    * if {@code return} statements should not appear here.
 173    */
 174  0 @Override public Type getReturnType() { return null; }
 175   
 176    /**
 177    * The types that are allowed to be thrown in the current context. If there is no
 178    * such declaration, the list will be empty.
 179    */
 180  0 @Override public Iterable<Type> getDeclaredThrownTypes() { return IterUtil.empty(); }
 181   
 182    }