Esempio n. 1
0
 /** Returns types from typed nodes. */
 public static Iterable<JReferenceType> getExpressionTypes(Iterable<? extends HasType> nodes) {
   if (nodes == null) {
     return Collections.emptyList();
   }
   return FluentIterable.from(nodes)
       .transform(
           new Function<HasType, JReferenceType>() {
             @Override
             public JReferenceType apply(HasType typedNode) {
               return (JReferenceType) typedNode.getType();
             }
           });
 }
Esempio n. 2
0
 public static boolean isRepresentedAsNative(String className) {
   return FluentIterable.from(Arrays.asList(DispatchType.values()))
       .transform(
           new Function<DispatchType, String>() {
             @Override
             public String apply(DispatchType dispatchType) {
               return dispatchType.getclassName();
             }
           })
       .filter(Predicates.notNull())
       .toSet()
       .contains(className);
 }
Esempio n. 3
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);
 }