private Class<?>[] getModulesFor(Class<?> klass) throws InitializationError {
   GuiceModules annotation = klass.getAnnotation(GuiceModules.class);
   if (annotation == null)
     throw new InitializationError(
         "Missing @GuiceModules annotation for unit test '" + klass.getName() + "'");
   return annotation.value();
 }
Example #2
0
 @Override
 public String toString() {
   StringBuilder b = new StringBuilder();
   for (Class<?> ann : annotations) {
     b.append(ann.getSimpleName()).append(' ');
   }
   b.append((type instanceof Class<?>) ? ((Class<?>) type).getSimpleName() : type.toString());
   return b.toString();
 }
Example #3
0
 @Deprecated
 public <T extends Widget> T findchild(Class<T> cl) {
   for (Widget wdg = child; wdg != null; wdg = wdg.next) {
     if (cl.isInstance(wdg)) return (cl.cast(wdg));
     T ret = wdg.findchild(cl);
     if (ret != null) return (ret);
   }
   return (null);
 }
Example #4
0
 private static boolean isTest(Class c) {
   for( Annotation a : c.getAnnotations() )
     if( a instanceof Ignore )
       return false;
   for( Method m : c.getMethods() )
     for( Annotation a : m.getAnnotations() )
       if( a instanceof Test )
         return true;
   return false;
 }
Example #5
0
 static boolean hasInstance(Object[] array, Class<? extends Annotation>... cs) {
   for (Object o : array) {
     for (Class<?> c : cs) {
       if (c.isInstance(o)) {
         return true;
       }
     }
   }
   return false;
 }
Example #6
0
 public <T extends Anim> void clearanims(Class<T> type) {
   for (Iterator<Anim> i = nanims.iterator(); i.hasNext(); ) {
     Anim a = i.next();
     if (type.isInstance(a)) i.remove();
   }
   for (Iterator<Anim> i = anims.iterator(); i.hasNext(); ) {
     Anim a = i.next();
     if (type.isInstance(a)) i.remove();
   }
 }
  public int test(String[] args) throws Exception {
    Class cl =
        Class.forName(
            "org.apache.harmony.vts.test.vm.jvms.classFile.attributes.annotation.annotationDefault.methodinfo13.annotation13");
    Object o = cl.getMethod("value", new Class[] {}).getDefaultValue();

    if ("org.apache.harmony.vts.test.vm.jvms.classFile.attributes.annotation.annotationDefault.methodinfo13.annotation13ann"
        .equals(((Annotation) o).annotationType().getName())) return 104;
    return 105;
  }
 private Field findSqlMapExecutorDelegate(SqlMapClient sqlMapClient) {
   Class<?> searchType = sqlMapClient.getClass();
   while (!Object.class.equals(searchType) && searchType != null) {
     Field[] fields = searchType.getDeclaredFields();
     for (Field field : fields) {
       if (SqlMapExecutorDelegate.class.isAssignableFrom(field.getType())) return field;
     }
     searchType = searchType.getSuperclass();
   }
   return null;
 }
Example #9
0
 private void checkAnnotation(Class<?> c, Class<? extends Annotation> expectedAnnotation)
     throws NoSuchMethodException, NoSuchFieldException {
   Class<? extends Annotation> annotation = c.getAnnotation(expectedAnnotation).annotationType();
   assertEquals(expectedAnnotation, annotation);
   Method m = c.getMethod("testMethod");
   annotation = m.getAnnotation(expectedAnnotation).annotationType();
   assertEquals(expectedAnnotation, annotation);
   Field f = c.getField("testField");
   annotation = f.getAnnotation(expectedAnnotation).annotationType();
   assertEquals(expectedAnnotation, annotation);
 }
  private boolean findAllTestedAndInjectableFieldsInTestClassHierarchy(
      @NotNull Class<?> testClass) {
    Class<?> classWithFields = testClass;

    do {
      Field[] fields = classWithFields.getDeclaredFields();
      findTestedAndInjectableFields(fields);
      classWithFields = classWithFields.getSuperclass();
    } while (classWithFields.getClassLoader() != null);

    return !testedFields.isEmpty();
  }
Example #11
0
 private void makeInterfaceTypes(CompileUnit cu, ClassNode classNode, Class clazz) {
   Type[] interfaceTypes = clazz.getGenericInterfaces();
   if (interfaceTypes.length == 0) {
     classNode.setInterfaces(ClassNode.EMPTY_ARRAY);
   } else {
     Class[] interfaceClasses = clazz.getInterfaces();
     ClassNode[] ret = new ClassNode[interfaceTypes.length];
     for (int i = 0; i < interfaceTypes.length; i++) {
       ret[i] = makeClassNode(cu, interfaceTypes[i], interfaceClasses[i]);
     }
     classNode.setInterfaces(ret);
   }
 }
  public DataConverter(Class<T> clazz)
      throws TooManyPrimaryKeys, NotAnnotatedAsTableClassException, PrimaryKeyIsNotColumnException,
          NoPrimaryKeyException {
    if (clazz.getAnnotation(Table.class) == null) {
      throw new NotAnnotatedAsTableClassException();
    } else {
      if (!clazz.getDeclaredAnnotation(Table.class).name().equals("")) {
        tableName = clazz.getDeclaredAnnotation(Table.class).name();
      } else {
        tableName = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, clazz.getSimpleName());
      }
    }
    fields = new ArrayList<FieldConverter>();
    for (Field field : clazz.getDeclaredFields()) {
      Class<?> type = field.getType();
      Annotation primaryKeyAnnotation = field.getDeclaredAnnotation(PrimaryKey.class),
          columnAnnotation = field.getDeclaredAnnotation(Column.class);

      if (primaryKeyAnnotation != null) {
        if (columnAnnotation == null) {
          throw new PrimaryKeyIsNotColumnException();
        }
        if (primaryKeyField != null) {
          throw new TooManyPrimaryKeys();
        }
        primaryKeyField = field;
      }
      if (columnAnnotation != null) {
        String name = null;
        if (!field.getDeclaredAnnotation(Column.class).name().equals("")) {
          name = field.getDeclaredAnnotation(Column.class).name();
        } else {
          name = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, field.getName());
        }
        FieldConverter currentFieldConverter = new FieldConverter(name, field);
        fields.add(currentFieldConverter);
        if (field.equals(primaryKeyField)) {
          primaryKeyFieldConverter = currentFieldConverter;
        }
      }
      Annotation[] annotations = field.getDeclaredAnnotations();
      for (Annotation annotation : annotations) {
        annotation.getClass();
      }
    }
    if (primaryKeyField == null) {
      throw new NoPrimaryKeyException();
    }
  }
Example #13
0
 static int getArgumentsStackSize(Method method) {
   int total = 0;
   Type[] paramTypes = method.getGenericParameterTypes();
   Annotation[][] anns = method.getParameterAnnotations();
   for (int iArg = 0, nArgs = paramTypes.length; iArg < nArgs; iArg++) {
     Class<?> paramType = getTypeClass(paramTypes[iArg]);
     if (paramType == int.class) {
       total += 4;
     } else if (paramType == long.class) {
       Annotation[] as = anns[iArg];
       if (isAnnotationPresent(Ptr.class, as)
           || isAnnotationPresent(
               org.bridj.ann.CLong.class,
               as)) // if (hasInstance(anns[iArg], Ptr.class, CLong.class))
       {
         total += Pointer.SIZE;
       } else {
         total += 8;
       }
     } else if (paramType == float.class) {
       total += 4;
     } else if (paramType == double.class) {
       total += 8;
     } else if (paramType == byte.class) {
       total += 1;
     } else if (paramType == char.class) {
       total += Platform.WCHAR_T_SIZE;
     } else if (paramType == CLong.class) {
       total += Platform.CLONG_SIZE;
     } else if (paramType == SizeT.class) {
       total += Platform.SIZE_T_SIZE;
     } else if (paramType == TimeT.class) {
       total += Platform.TIME_T_SIZE;
     } else if (paramType == short.class) {
       total += 2;
     } else if (paramType == boolean.class) {
       total += 1;
     } else if (Pointer.class.isAssignableFrom(paramType)) {
       total += Pointer.SIZE;
     } else if (NativeObject.class.isAssignableFrom(paramType)) {
       total += ((CRuntime) BridJ.getRuntime(paramType)).sizeOf(paramTypes[iArg], null);
     } else if (FlagSet.class.isAssignableFrom(paramType)) {
       total += 4; // TODO
     } else {
       throw new RuntimeException("Type not handled : " + paramType.getName());
     }
   }
   return total;
 }
Example #14
0
 private ClassNode configureClass(Class c) {
   if (c.isPrimitive()) {
     return ClassHelper.make(c);
   } else {
     return ClassHelper.makeWithoutCaching(c, false);
   }
 }
Example #15
0
 private void sendResponse(long requestId, Object value, Class<?> declaredType)
     throws IOException {
   DataOutputStream out = newFlusher();
   out.writeByte(RESPONSE);
   out.writeLong(requestId);
   if (value == null) {
     out.writeBoolean(false);
   } else {
     out.writeBoolean(true);
     Class<?> clazz = value.getClass();
     out.writeUTF(clazz.getName());
     Serializer<Object> s = serializerFor(clazz, declaredType);
     s.serialize(out, value);
   }
   out.writeBoolean(false);
   out.flush();
 }
Example #16
0
 protected T blankInstance() {
   try {
     return backedType.newInstance();
   } catch (Exception e) {
     throw new RuntimeException(
         "Cannot instantiate " + backedType + ". It must have a default constructor", e);
   }
 }
Example #17
0
    public boolean matchesEnclosingType(Method method) {
      TypeRef et = getEnclosingType();
      if (et == null) {
        return true;
      }

      Annotations annotations = annotations(method);
      Class dc = method.getDeclaringClass();
      do {
        if (et.matches(dc, annotations)) {
          return true;
        }

        dc = dc.getSuperclass();
      } while (dc != null && dc != Object.class);

      return false;
    }
Example #18
0
 private ClassNode makeClassNode(CompileUnit cu, Type t, Class c) {
   ClassNode back = null;
   if (cu != null) back = cu.getClass(c.getName());
   if (back == null) back = ClassHelper.make(c);
   if (!(t instanceof Class)) {
     ClassNode front = configureType(t);
     front.setRedirect(back);
     return front;
   }
   return back;
 }
  private Method findPublicVoidMethod(Class<?> aClass, String methodName) {
    for (Method method : aClass.getDeclaredMethods()) {
      if (isPublic(method.getModifiers())
          && method.getReturnType() == void.class
          && methodName.equals(method.getName())) {
        return method;
      }
    }

    return null;
  }
Example #20
0
  public void printAnnotations() {
    // Get Class object of the AnnotatedClass class
    Class c = ac.getClass();
    // Get all annotations applied to the AnnotatedClass class.
    // Only the annotations with RUNTIME retention are retained during runtime.
    Annotation[] annotations = c.getAnnotations();
    int numberOfAnnotations = annotations.length;
    System.out.println(
        "La Clase " + c.getName() + " tiene " + numberOfAnnotations + " anotaciones");

    for (int i = 0; i < numberOfAnnotations; i++) {
      System.out.println(
          "Anotacion "
              + i
              + ": "
              + annotations[i]
              + ", tipo"
              + annotations[i].annotationType().getName());
    }
  }
Example #21
0
 Method getSetMethod(Class<?> targetClass, Class<?> fieldType, String fieldName) {
   fieldName = fieldName.substring(0, 1).toUpperCase() + fieldName.substring(1);
   String methodname = "set" + fieldName;
   Method method = null;
   try {
     method = targetClass.getMethod(methodname, new Class<?>[] {fieldType});
   } catch (Exception e) {
     playerObjects.getLogFile().WriteLine(Formatting.exceptionToStackTrace(e));
   }
   return method;
 }
Example #22
0
    @Override
    public boolean matches(Type type, Annotations annotations) {
      Class<?> tc = getTypeClass(this.type);
      Class<?> typec = getTypeClass(type);
      if (tc == typec || tc.equals(typec)) {
        return true;
      }

      if ((type == Long.TYPE && Pointer.class.isAssignableFrom(tc))
          || (Pointer.class.isAssignableFrom(typec) && tc == Long.TYPE)) {
        return true;
      }

      return equivalentTypes(
          type,
          typec,
          annotations,
          this.type,
          tc,
          null); // TODO isAssignableFrom or the opposite, depending on context
    }
  static int examine(Class enclosedClass, String constructorSig) {
    Constructor c = enclosedClass.getEnclosingConstructor();
    if (c == null && constructorSig == null) return 0;

    if (c != null && c.getAnnotation(ConstructorDescriptor.class).value().equals(constructorSig))
      return 0; // everything is okay
    else {
      System.err.println(
          "\nUnexpected constructor value; expected:\t" + constructorSig + "\ngot:\t" + c);
      return 1;
    }
  }
 // Ang's suggestion on getting annotation values
 public static String getClassAnnotationValue(
     Class classType, Class annotationType, String attributeName) {
   String value = null;
   Annotation annotation = classType.getAnnotation(annotationType);
   if (annotation != null) {
     try {
       value = (String) annotation.annotationType().getMethod(attributeName).invoke(annotation);
     } catch (Exception ex) {
       System.out.println("Failed loading class annotations");
     }
   }
   return value;
 }
 private QueryMethod chooseQueryMethodStrategy(
     Method method, RepositoryMetadata metadata, Class<?> repositoryInterface) {
   QueryMethod queryMethod;
   boolean paramAnnotation = false;
   if ((paramAnnotation = hasParamAnnotation(method))
       || repositoryInterface.isAnnotationPresent(Namespace.class)
       || method.isAnnotationPresent(Statement.class)) {
     queryMethod = new AnnotationBasedSqlMapQueryMethod(method, metadata, paramAnnotation);
   } else {
     queryMethod = new QueryMethod(method, metadata);
   }
   return queryMethod;
 }
Example #26
0
 Method getGetMethod(Class<?> targetClass, Class<?> fieldType, String fieldName) {
   fieldName = fieldName.substring(0, 1).toUpperCase() + fieldName.substring(1);
   String methodname = "get" + fieldName;
   if (fieldType == boolean.class || fieldType == Boolean.class) {
     methodname = "is" + fieldName;
   }
   Method method = null;
   try {
     method = targetClass.getMethod(methodname, new Class<?>[0]);
   } catch (Exception e) {
     playerObjects.getLogFile().WriteLine(Formatting.exceptionToStackTrace(e));
   }
   return method;
 }
Example #27
0
 public static void main(String[] args) {
   try {
     H2O.main(args);
     TestUtil.stall_till_cloudsize(3);
     List<Class> tests = JUnitRunner.all();
     Result r = org.junit.runner.JUnitCore.runClasses(tests.toArray(new Class[0]));
     if( r.getFailureCount() == 0 ) {
       System.out.println("Successfully ran the following tests in " + (r.getRunTime() / 1000) + "s");
       for( Class c : tests )
         System.out.println(c.getName());
     } else {
       for( Failure f : r.getFailures() ) {
         System.err.println(f.getDescription());
         if( f.getException() != null )
           f.getException().printStackTrace();
       }
     }
     System.exit(r.getFailureCount());
   } catch( Throwable t ) {
     t.printStackTrace();
     System.exit(1);
   }
 }
Example #28
0
 public Factory make(Class<?> cl) throws InstantiationException, IllegalAccessException {
   if (Factory.class.isAssignableFrom(cl)) return (cl.asSubclass(Factory.class).newInstance());
   try {
     final Method mkm = cl.getDeclaredMethod("mkwidget", Widget.class, Object[].class);
     int mod = mkm.getModifiers();
     if (Widget.class.isAssignableFrom(mkm.getReturnType())
         && ((mod & Modifier.STATIC) != 0)
         && ((mod & Modifier.PUBLIC) != 0)) {
       return (new Factory() {
         public Widget create(Widget parent, Object[] args) {
           try {
             return ((Widget) mkm.invoke(null, parent, args));
           } catch (Exception e) {
             if (e instanceof RuntimeException) throw ((RuntimeException) e);
             throw (new RuntimeException(e));
           }
         }
       });
     }
   } catch (NoSuchMethodException e) {
   }
   return (null);
 }
Example #29
0
 private void configureAnnotation(AnnotationNode node, Annotation annotation) {
   Class type = annotation.annotationType();
   if (type == Retention.class) {
     Retention r = (Retention) annotation;
     RetentionPolicy value = r.value();
     setRetentionPolicy(value, node);
     node.setMember(
         "value",
         new PropertyExpression(
             new ClassExpression(ClassHelper.makeWithoutCaching(RetentionPolicy.class, false)),
             value.toString()));
   } else if (type == Target.class) {
     Target t = (Target) annotation;
     ElementType[] elements = t.value();
     ListExpression elementExprs = new ListExpression();
     for (ElementType element : elements) {
       elementExprs.addExpression(
           new PropertyExpression(
               new ClassExpression(ClassHelper.ELEMENT_TYPE_TYPE), element.name()));
     }
     node.setMember("value", elementExprs);
   } else {
     Method[] declaredMethods = type.getDeclaredMethods();
     for (int i = 0; i < declaredMethods.length; i++) {
       Method declaredMethod = declaredMethods[i];
       try {
         Object value = declaredMethod.invoke(annotation);
         Expression valueExpression = annotationValueToExpression(value);
         if (valueExpression == null) continue;
         node.setMember(declaredMethod.getName(), valueExpression);
       } catch (IllegalAccessException e) {
       } catch (InvocationTargetException e) {
       }
     }
   }
 }
 <T> Annotation buildAnnotation(Class<T> type, final String args1, final String... args2) {
   Integer hash =
       (type.hashCode() * 31)
           + String.valueOf(args1).hashCode()
           + (31 * Arrays.toString(args2).hashCode());
   Annotation out = annotationHashes.get(hash);
   if (out == null) {
     if (type == Boolean.class || type == boolean.class) {
       out = buildBooleanStringAnnotation(args1 == null ? null : new String[] {args1}, args2);
     } else {
       out = newFormatAnnotation(args1, args2);
     }
     annotationHashes.put(hash, out);
   }
   return out;
 }