Java Class.isSynthetic Examples

Java Class.isSynthetic - 6 examples found. These are the top rated real world Java examples of Class.isSynthetic extracted from open source projects. You can rate examples to help us improve the quality of examples.
Example #1
0
  protected static SwaggerModelType convertToSwaggerModel(SwaggerModel models, Class<?> type) {
    Map<String, SwaggerModelProperty> mp = new HashMap<String, SwaggerModelProperty>();
    List<String> requiredFields = new ArrayList<String>();
    // AMDATUWEB-24 - use not only field of given type, but also of all its superclasses...
    String typeName = type.getName();
    while (type != null && !Object.class.equals(type)) {
      Field[] fields = type.getDeclaredFields();
      for (Field f : fields) {
        String name = f.getName();
        int modifiers = f.getModifiers();
        Class<?> fieldType = f.getType();

        if (mp.containsKey(name)) {
          // TODO name shadowing is not supported yet...
          continue;
        } else if (Modifier.isStatic(modifiers) || fieldType.isSynthetic()) {
          continue;
        }

        Description description = f.getAnnotation(Description.class);
        DefaultValue defaultValue = f.getAnnotation(DefaultValue.class);

        SwaggerDataType typeInfo = convertToSwaggerType(models, fieldType);

        SwaggerModelProperty smp;
        if (fieldType.isEnum()) {
          smp =
              new SwaggerModelProperty(
                  typeInfo,
                  getDescription(description),
                  getValue(defaultValue),
                  getEnumValues(fieldType));
        } else if (fieldType.isArray() || Collection.class.isAssignableFrom(fieldType)) {
          Boolean uniqueItems = Set.class.isAssignableFrom(fieldType) ? Boolean.TRUE : null;
          smp =
              new SwaggerModelProperty(
                  typeInfo,
                  getDescription(description),
                  getValue(defaultValue),
                  uniqueItems,
                  getContainerType(models, f));
        } else {
          smp =
              new SwaggerModelProperty(
                  typeInfo, getDescription(description), getValue(defaultValue));
        }

        if (Boolean.TRUE.equals(smp.required)) {
          requiredFields.add(name);
        }

        mp.put(name, smp);
      }
      type = type.getSuperclass();
    }
    return new SwaggerModelType(typeName, mp, requiredFields);
  }
Example #2
0
  /**
   * Runs the test using the specified harness.
   *
   * @param harness the test harness (<code>null</code> not permitted).
   */
  public void test(TestHarness harness) {
    // create instance of a class StringIndexOutOfBoundsException
    final Object o =
        new StringIndexOutOfBoundsException("java.lang.StringIndexOutOfBoundsException");

    // get a runtime class of an object "o"
    final Class c = o.getClass();

    harness.check(!c.isSynthetic());
  }
  private static void _assertClassDataCoverage(
      List<AssertionError> assertionErrors, Class<?> clazz, ClassData classData) {

    if (clazz.isInterface() || clazz.isSynthetic()) {
      return;
    }

    if (classData == null) {
      assertionErrors.add(new AssertionError("Class " + clazz.getName() + " has no coverage data"));

      return;
    }

    if ((classData.getBranchCoverageRate() != 1.0) || (classData.getLineCoverageRate() != 1.0)) {

      System.out.printf(
          "%n[Cobertura] %s is not fully covered.%n[Cobertura]Branch "
              + "coverage rate : %.2f, line coverage rate : %.2f.%n"
              + "[Cobertura]Please rerun test with -Djunit.code."
              + "coverage=true to see coverage report.%n",
          classData.getName(), classData.getBranchCoverageRate(), classData.getLineCoverageRate());

      Set<CoverageData> coverageDatas = classData.getLines();

      for (CoverageData coverageData : coverageDatas) {
        if (!(coverageData instanceof LineData)) {
          continue;
        }

        LineData lineData = (LineData) coverageData;

        if (lineData.isCovered()) {
          continue;
        }

        System.out.printf(
            "[Cobertura] %s line %d is not covered %n",
            classData.getName(), lineData.getLineNumber());
      }

      assertionErrors.add(new AssertionError(classData.getName() + " is not fully covered"));

      return;
    }

    System.out.printf("[Cobertura] %s is fully covered.%n", classData.getName());
  }
Example #4
0
 /**
  * Navigate all the fields of the specified object. If a field is null, it does not get visited.
  */
 public void accept(Visitor visitor) {
   TypeInfo objTypeInfo = new TypeInfo(objTypePair.type);
   if (exclusionStrategy.shouldSkipClass(objTypeInfo.getRawClass())) {
     return;
   }
   boolean visitedWithCustomHandler = visitor.visitUsingCustomHandler(objTypePair);
   if (!visitedWithCustomHandler) {
     Object obj = objTypePair.getObject();
     Object objectToVisit = (obj == null) ? visitor.getTarget() : obj;
     if (objectToVisit == null) {
       return;
     }
     objTypePair.setObject(objectToVisit);
     visitor.start(objTypePair);
     try {
       if (objTypeInfo.isArray()) {
         visitor.visitArray(objectToVisit, objTypePair.type);
       } else if (objTypeInfo.getActualType() == Object.class
           && isPrimitiveOrString(objectToVisit)) {
         // TODO(Joel): this is only used for deserialization of "primitives"
         // we should rethink this!!!
         visitor.visitPrimitive(objectToVisit);
         objectToVisit = visitor.getTarget();
       } else {
         visitor.startVisitingObject(objectToVisit);
         ObjectTypePair currObjTypePair = objTypePair.toMoreSpecificType();
         Class<?> topLevelClass = new TypeInfo(currObjTypePair.type).getRawClass();
         for (Class<?> curr = topLevelClass;
             curr != null && !curr.equals(Object.class);
             curr = curr.getSuperclass()) {
           if (!curr.isSynthetic()) {
             navigateClassFields(objectToVisit, curr, visitor);
           }
         }
       }
     } finally {
       visitor.end(objTypePair);
     }
   }
 }
Example #5
0
  private boolean isInstrumentClass(Class c) {

    if (!instrumentation.isModifiableClass(c)) {
      LOG.trace("NO INSTRUMENT: Class " + c.getName() + " is not modifiable");
      return false;
    }
    if (!configuration.isAudit(c.getName())) {
      LOG.trace("NO INSTRUMENT: Class " + c.getName() + " is blacklisted");
      return false;
    }
    if (c.isArray()
        || c.isAnnotation()
        || c.isInterface()
        || c.isPrimitive()
        || c.isSynthetic()
        || c.isEnum()) {
      LOG.trace(
          "NO INSTRUMENT: Class "
              + c.getName()
              + " is an array, primitive, annotation or enum etc");
      return false;
    }
    return true;
  }
Example #6
0
  @BeforeClass
  public static void beforeClass() throws Exception {
    List<Class<?>> analysisClasses = getClassesForPackage("org.apache.lucene.analysis");
    tokenizers = new ArrayList<Constructor<? extends Tokenizer>>();
    tokenfilters = new ArrayList<Constructor<? extends TokenFilter>>();
    charfilters = new ArrayList<Constructor<? extends CharFilter>>();
    for (final Class<?> c : analysisClasses) {
      final int modifiers = c.getModifiers();
      if (
      // don't waste time with abstract classes or deprecated known-buggy ones
      Modifier.isAbstract(modifiers)
          || !Modifier.isPublic(modifiers)
          || c.isSynthetic()
          || c.isAnonymousClass()
          || c.isMemberClass()
          || c.isInterface()
          || c.isAnnotationPresent(Deprecated.class)
          || !(Tokenizer.class.isAssignableFrom(c)
              || TokenFilter.class.isAssignableFrom(c)
              || CharFilter.class.isAssignableFrom(c))) {
        continue;
      }

      for (final Constructor<?> ctor : c.getConstructors()) {
        // don't test synthetic or deprecated ctors, they likely have known bugs:
        if (ctor.isSynthetic()
            || ctor.isAnnotationPresent(Deprecated.class)
            || brokenConstructors.get(ctor) == ALWAYS) {
          continue;
        }
        if (Tokenizer.class.isAssignableFrom(c)) {
          assertTrue(
              ctor.toGenericString() + " has unsupported parameter types",
              allowedTokenizerArgs.containsAll(Arrays.asList(ctor.getParameterTypes())));
          tokenizers.add(castConstructor(Tokenizer.class, ctor));
        } else if (TokenFilter.class.isAssignableFrom(c)) {
          assertTrue(
              ctor.toGenericString() + " has unsupported parameter types",
              allowedTokenFilterArgs.containsAll(Arrays.asList(ctor.getParameterTypes())));
          tokenfilters.add(castConstructor(TokenFilter.class, ctor));
        } else if (CharFilter.class.isAssignableFrom(c)) {
          assertTrue(
              ctor.toGenericString() + " has unsupported parameter types",
              allowedCharFilterArgs.containsAll(Arrays.asList(ctor.getParameterTypes())));
          charfilters.add(castConstructor(CharFilter.class, ctor));
        } else {
          fail("Cannot get here");
        }
      }
    }

    final Comparator<Constructor<?>> ctorComp =
        new Comparator<Constructor<?>>() {
          @Override
          public int compare(Constructor<?> arg0, Constructor<?> arg1) {
            return arg0.toGenericString().compareTo(arg1.toGenericString());
          }
        };
    Collections.sort(tokenizers, ctorComp);
    Collections.sort(tokenfilters, ctorComp);
    Collections.sort(charfilters, ctorComp);
    if (VERBOSE) {
      System.out.println("tokenizers = " + tokenizers);
      System.out.println("tokenfilters = " + tokenfilters);
      System.out.println("charfilters = " + charfilters);
    }
  }