Example #1
0
 /** Traverse from all methods starting from a set of types. */
 private void traverseTypes(ControlFlowAnalyzer livenessAnalyzer, List<JClassType> types) {
   for (JClassType type : types) {
     livenessAnalyzer.traverseFromReferenceTo(type);
     for (JMethod method : type.getMethods()) {
       if (method instanceof JConstructor) {
         livenessAnalyzer.traverseFromInstantiationOf(type);
       }
       livenessAnalyzer.traverseFrom(method);
     }
   }
 }
Example #2
0
 /**
  * Returns an instantiation expression for {@code type} using the default constructor, Returns
  * {@code null} if {@code type} does not have a default constructor.
  */
 public static JExpression createDefaultConstructorInstantiation(
     SourceInfo info, JClassType type) {
   /*
    * Find the appropriate (noArg) constructor. In our AST, constructors are
    * instance methods that should be qualified with a new expression.
    */
   JConstructor noArgCtor =
       (JConstructor)
           FluentIterable.from(type.getMethods())
               .firstMatch(
                   new Predicate<JMethod>() {
                     @Override
                     public boolean apply(JMethod method) {
                       return method instanceof JConstructor
                           && method.getOriginalParamTypes().size() == 0;
                     }
                   })
               .orNull();
   if (noArgCtor == null) {
     return null;
   }
   // Call it, using a new expression as a qualifier
   return new JNewInstance(info, noArgCtor);
 }