Java 类java.lang.Class 实例源码

项目:openjdk-jdk10    文件:XMLFactoryHelper.java   
public static Object instantiateXMLService(String serviceName) throws Exception {
    ClassLoader backup = Thread.currentThread().getContextClassLoader();
    try {
        // set thread context class loader to module class loader
        Thread.currentThread().setContextClassLoader(XMLFactoryHelper.class.getClassLoader());
        if (serviceName.equals("org.xml.sax.XMLReader"))
            return XMLReaderFactory.createXMLReader();
        else if (serviceName.equals("javax.xml.validation.SchemaFactory"))
            return Class.forName(serviceName).getMethod("newInstance", String.class)
                    .invoke(null, W3C_XML_SCHEMA_NS_URI);
        else
            return Class.forName(serviceName).getMethod("newInstance").invoke(null);
    } finally {
        Thread.currentThread().setContextClassLoader(backup);
    }

}
项目:productai-java-sdk    文件:EnumHelper.java   
public static HashMap<Integer, String> toHashMap(Class _enumType) {

        if (!_enumType.isEnum()) {
            throw new IllegalArgumentException("Only support enum type!");
        }
        HashMap<Integer, String> dic = new HashMap<Integer, String>();

        Field[] ps = _enumType.getFields();
        for (Field p : ps) {
            if (!p.getType().equals(_enumType)) {
                continue;
            }
            Enum _enum = Enum.valueOf(_enumType, p.getName());
            EnumDescriptionAttribute att = p.getAnnotation(EnumDescriptionAttribute.class);
            if (att != null) {
                dic.put(_enum.ordinal(), att.Text());
            } else {
                dic.put(_enum.ordinal(), p.getName());
            }
        }
        return dic;
    }
项目:openjdk-jdk10    文件:Basic.java   
public static boolean arePaddedPairwise(Class klass, String field1, String field2) throws Exception {
    Field f1 = klass.getDeclaredField(field1);
    Field f2 = klass.getDeclaredField(field2);

    if (isStatic(f1) != isStatic(f2)) {
        return true; // these guys are in naturally disjoint locations
    }

    int diff = offset(f1) - offset(f2);
    if (diff < 0) {
        // f1 is first
        return (offset(f2) - (offset(f1) + getSize(f1))) > 64;
    } else {
        // f2 is first
        return (offset(f1) - (offset(f2) + getSize(f2))) > 64;
    }
}
项目:openjdk-jdk10    文件:BadClassFiles.java   
private BadClassFiles() throws ClassNotFoundException {
    classes = new Class<?>[] {
        loader.defineClass("EmptyName", EmptyName_bytes),
        loader.defineClass("BadModifiers", BadModifiers_bytes),
        loader.defineClass("BadNameIndex", BadNameIndex_bytes),
        loader.defineClass("NameIndexOutOfBounds", NameIndexOutOfBounds_bytes),
        loader.defineClass("ExtraParams", ExtraParams_bytes),
        loader.defineClass("BadParams", BadParams_bytes),
        // Name with .
        loader.defineClass("BadName1", BadName1_bytes),
        // Name with [
        loader.defineClass("BadName2", BadName2_bytes),
        // Name with ;
        loader.defineClass("BadName3", BadName3_bytes),
        // Name with /
        loader.defineClass("BadName4", BadName4_bytes)
    };
}
项目:jdk8u-jdk    文件:BadClassFiles.java   
private BadClassFiles() throws ClassNotFoundException {
    classes = new Class<?>[] {
        loader.defineClass("EmptyName", EmptyName_bytes),
        loader.defineClass("BadModifiers", BadModifiers_bytes),
        loader.defineClass("BadNameIndex", BadNameIndex_bytes),
        loader.defineClass("NameIndexOutOfBounds", NameIndexOutOfBounds_bytes),
        loader.defineClass("ExtraParams", ExtraParams_bytes),
        // Name with .
        loader.defineClass("BadName1", BadName1_bytes),
        // Name with [
        loader.defineClass("BadName2", BadName2_bytes),
        // Name with ;
        loader.defineClass("BadName3", BadName3_bytes),
        // Name with /
        loader.defineClass("BadName4", BadName4_bytes)
    };
}
项目:GitHub    文件:GlideRequest.java   
/**
 * @see GlideOptions#transform(Class<T>, Transformation<T>)
 */
@CheckResult
public <T> GlideRequest<TranscodeType> transform(@NonNull Class<T> arg0,
    @NonNull Transformation<T> arg1) {
  if (getMutableOptions() instanceof GlideOptions) {
    this.requestOptions = ((GlideOptions) getMutableOptions()).transform(arg0, arg1);
  } else {
    this.requestOptions = new GlideOptions().apply(this.requestOptions).transform(arg0, arg1);
  }
  return this;
}
项目:MaxSim    文件:Basic.java   
public static boolean arePaddedPairwise(Class klass, String field1, String field2) throws Exception {
    Field f1 = klass.getDeclaredField(field1);
    Field f2 = klass.getDeclaredField(field2);

    if (isStatic(f1) != isStatic(f2)) {
        return true; // these guys are in naturally disjoint locations
    }

    int diff = offset(f1) - offset(f2);
    if (diff < 0) {
        // f1 is first
        return (offset(f2) - (offset(f1) + getSize(f1))) > 64;
    } else {
        // f2 is first
        return (offset(f1) - (offset(f2) + getSize(f2))) > 64;
    }
}
项目:GitHub    文件:GlideRequest.java   
/**
 * @see GlideOptions#decode(Class<?>)
 */
@CheckResult
public GlideRequest<TranscodeType> decode(@NonNull Class<?> arg0) {
  if (getMutableOptions() instanceof GlideOptions) {
    this.requestOptions = ((GlideOptions) getMutableOptions()).decode(arg0);
  } else {
    this.requestOptions = new GlideOptions().apply(this.requestOptions).decode(arg0);
  }
  return this;
}
项目:openjdk-jdk10    文件:Inheritance1.java   
public static int getSize(Field field) {
    Class type = field.getType();
    if (type == byte.class)    { return 1; }
    if (type == boolean.class) { return 1; }
    if (type == short.class)   { return 2; }
    if (type == char.class)    { return 2; }
    if (type == int.class)     { return 4; }
    if (type == float.class)   { return 4; }
    if (type == long.class)    { return 8; }
    if (type == double.class)  { return 8; }
    return ADDRESS_SIZE;
}
项目:jdk8u-jdk    文件:BadClassFiles.java   
public void assertBadParameters(Class<?> cls) throws NoSuchMethodException {
    try {
        System.err.println("Trying " + cls);
        final Method method = cls.getMethod("m", int.class, int.class);
        final Parameter[] params = method.getParameters();
        System.err.println("Name " + params[0].getName());
        System.err.println("Did not see expected exception");
        errors++;
    } catch(MalformedParametersException e) {
        System.err.println("Expected exception seen");
    }
}
项目:GitHub    文件:GlideRequest.java   
/**
 * @see GlideOptions#decode(Class<?>)
 */
@CheckResult
public GlideRequest<TranscodeType> decode(@NonNull Class<?> arg0) {
  if (getMutableOptions() instanceof GlideOptions) {
    this.requestOptions = ((GlideOptions) getMutableOptions()).decode(arg0);
  } else {
    this.requestOptions = new GlideOptions().apply(this.requestOptions).decode(arg0);
  }
  return this;
}
项目:GitHub    文件:GlideRequest.java   
/**
 * @see GlideOptions#transform(Class<T>, Transformation<T>)
 */
@CheckResult
public <T> GlideRequest<TranscodeType> transform(@NonNull Class<T> arg0,
    @NonNull Transformation<T> arg1) {
  if (getMutableOptions() instanceof GlideOptions) {
    this.requestOptions = ((GlideOptions) getMutableOptions()).transform(arg0, arg1);
  } else {
    this.requestOptions = new GlideOptions().apply(this.requestOptions).transform(arg0, arg1);
  }
  return this;
}
项目:GitHub    文件:GlideRequest.java   
/**
 * @see GlideOptions#optionalTransform(Class<T>, Transformation<T>)
 */
@CheckResult
public <T> GlideRequest<TranscodeType> optionalTransform(@NonNull Class<T> arg0,
    @NonNull Transformation<T> arg1) {
  if (getMutableOptions() instanceof GlideOptions) {
    this.requestOptions = ((GlideOptions) getMutableOptions()).optionalTransform(arg0, arg1);
  } else {
    this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalTransform(arg0, arg1);
  }
  return this;
}
项目:GitHub    文件:GlideRequest.java   
/**
 * @see GlideOptions#transform(Class<T>, Transformation<T>)
 */
@CheckResult
public <T> GlideRequest<TranscodeType> transform(@NonNull Class<T> arg0,
    @NonNull Transformation<T> arg1) {
  if (getMutableOptions() instanceof GlideOptions) {
    this.requestOptions = ((GlideOptions) getMutableOptions()).transform(arg0, arg1);
  } else {
    this.requestOptions = new GlideOptions().apply(this.requestOptions).transform(arg0, arg1);
  }
  return this;
}
项目:GitHub    文件:GlideRequest.java   
/**
 * @see GlideOptions#decode(Class<?>)
 */
@CheckResult
public GlideRequest<TranscodeType> decode(@NonNull Class<?> arg0) {
  if (getMutableOptions() instanceof GlideOptions) {
    this.requestOptions = ((GlideOptions) getMutableOptions()).decode(arg0);
  } else {
    this.requestOptions = new GlideOptions().apply(this.requestOptions).decode(arg0);
  }
  return this;
}
项目:openjdk-jdk10    文件:NoName.java   
public void run() throws NoSuchMethodException {
    final Class<?> cls = noName;
    System.err.println("Trying " + cls);
    final Method method = cls.getMethod("m", int.class, int.class);
    final Parameter[] params = method.getParameters();
    System.err.println("Name " + params[0].getName());
    System.err.println("Name " + params[1].getName());
}
项目:GitHub    文件:GlideRequest.java   
/**
 * @see GlideOptions#optionalTransform(Class<T>, Transformation<T>)
 */
@CheckResult
public <T> GlideRequest<TranscodeType> optionalTransform(@NonNull Class<T> arg0,
    @NonNull Transformation<T> arg1) {
  if (getMutableOptions() instanceof GlideOptions) {
    this.requestOptions = ((GlideOptions) getMutableOptions()).optionalTransform(arg0, arg1);
  } else {
    this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalTransform(arg0, arg1);
  }
  return this;
}
项目:GitHub    文件:GlideRequest.java   
/**
 * @see GlideOptions#transform(Class<T>, Transformation<T>)
 */
@CheckResult
public <T> GlideRequest<TranscodeType> transform(@NonNull Class<T> arg0,
    @NonNull Transformation<T> arg1) {
  if (getMutableOptions() instanceof GlideOptions) {
    this.requestOptions = ((GlideOptions) getMutableOptions()).transform(arg0, arg1);
  } else {
    this.requestOptions = new GlideOptions().apply(this.requestOptions).transform(arg0, arg1);
  }
  return this;
}
项目:MaxSim    文件:Inheritance1.java   
public static boolean arePaddedPairwise(Class klass, String field1, String field2) throws Exception {
    Field f1 = klass.getField(field1);
    Field f2 = klass.getField(field2);

    int diff = offset(f1) - offset(f2);
    if (diff < 0) {
        // f1 is first
        return (offset(f2) - (offset(f1) + getSize(f1))) > 64;
    } else {
        // f2 is first
        return (offset(f1) - (offset(f2) + getSize(f2))) > 64;
    }
}
项目:GitHub    文件:GlideRequest.java   
/**
 * @see GlideOptions#decode(Class<?>)
 */
@CheckResult
public GlideRequest<TranscodeType> decode(@NonNull Class<?> arg0) {
  if (getMutableOptions() instanceof GlideOptions) {
    this.requestOptions = ((GlideOptions) getMutableOptions()).decode(arg0);
  } else {
    this.requestOptions = new GlideOptions().apply(this.requestOptions).decode(arg0);
  }
  return this;
}
项目:GitHub    文件:GlideRequest.java   
/**
 * @see GlideOptions#optionalTransform(Class<T>, Transformation<T>)
 */
@CheckResult
public <T> GlideRequest<TranscodeType> optionalTransform(@NonNull Class<T> arg0,
    @NonNull Transformation<T> arg1) {
  if (getMutableOptions() instanceof GlideOptions) {
    this.requestOptions = ((GlideOptions) getMutableOptions()).optionalTransform(arg0, arg1);
  } else {
    this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalTransform(arg0, arg1);
  }
  return this;
}
项目:GitHub    文件:GlideRequest.java   
/**
 * @see GlideOptions#decode(Class<?>)
 */
@CheckResult
public GlideRequest<TranscodeType> decode(@NonNull Class<?> arg0) {
  if (getMutableOptions() instanceof GlideOptions) {
    this.requestOptions = ((GlideOptions) getMutableOptions()).decode(arg0);
  } else {
    this.requestOptions = new GlideOptions().apply(this.requestOptions).decode(arg0);
  }
  return this;
}
项目:GitHub    文件:GlideRequest.java   
/**
 * @see GlideOptions#optionalTransform(Class<T>, Transformation<T>)
 */
@CheckResult
public <T> GlideRequest<TranscodeType> optionalTransform(@NonNull Class<T> arg0,
    @NonNull Transformation<T> arg1) {
  if (getMutableOptions() instanceof GlideOptions) {
    this.requestOptions = ((GlideOptions) getMutableOptions()).optionalTransform(arg0, arg1);
  } else {
    this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalTransform(arg0, arg1);
  }
  return this;
}
项目:MaxSim    文件:Basic.java   
public static int getSize(Field field) {
    Class type = field.getType();
    if (type == byte.class)    { return 1; }
    if (type == boolean.class) { return 1; }
    if (type == short.class)   { return 2; }
    if (type == char.class)    { return 2; }
    if (type == int.class)     { return 4; }
    if (type == float.class)   { return 4; }
    if (type == long.class)    { return 8; }
    if (type == double.class)  { return 8; }
    return ADDRESS_SIZE;
}
项目:GitHub    文件:GlideRequest.java   
/**
 * @see GlideOptions#optionalTransform(Class<T>, Transformation<T>)
 */
@CheckResult
public <T> GlideRequest<TranscodeType> optionalTransform(@NonNull Class<T> arg0,
    @NonNull Transformation<T> arg1) {
  if (getMutableOptions() instanceof GlideOptions) {
    this.requestOptions = ((GlideOptions) getMutableOptions()).optionalTransform(arg0, arg1);
  } else {
    this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalTransform(arg0, arg1);
  }
  return this;
}
项目:GitHub    文件:GlideRequest.java   
/**
 * @see GlideOptions#optionalTransform(Class<T>, Transformation<T>)
 */
@CheckResult
public <T> GlideRequest<TranscodeType> optionalTransform(@NonNull Class<T> arg0,
    @NonNull Transformation<T> arg1) {
  if (getMutableOptions() instanceof GlideOptions) {
    this.requestOptions = ((GlideOptions) getMutableOptions()).optionalTransform(arg0, arg1);
  } else {
    this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalTransform(arg0, arg1);
  }
  return this;
}
项目:GitHub    文件:GlideRequest.java   
/**
 * @see GlideOptions#transform(Class<T>, Transformation<T>)
 */
@CheckResult
public <T> GlideRequest<TranscodeType> transform(@NonNull Class<T> arg0,
    @NonNull Transformation<T> arg1) {
  if (getMutableOptions() instanceof GlideOptions) {
    this.requestOptions = ((GlideOptions) getMutableOptions()).transform(arg0, arg1);
  } else {
    this.requestOptions = new GlideOptions().apply(this.requestOptions).transform(arg0, arg1);
  }
  return this;
}
项目:openjdk-jdk10    文件:CaptureTest.java   
public Tester makeAnonExtendsLocal(final String message) {
    abstract class LocalTester extends Tester {
        public LocalTester(final int localparam) {
            super(localparam);
        }

        protected String[] names() {
            return new String[] {
                "this$1",
                "localparam",
                "val$message"
            };
        }

        protected int[] modifiers() {
            return new int[] {
                Modifier.FINAL | MANDATED,
                Modifier.FINAL,
                Modifier.FINAL | SYNTHETIC
            };
        }

        protected Class[] types() {
            return new Class[] {
                Encloser.class,
                int.class,
                String.class
            };
        }

    }

    return new LocalTester(2) {
        public String message() {
            return message;
        }
    };
}
项目:MaxSim    文件:Inheritance1.java   
public static int getSize(Field field) {
    Class type = field.getType();
    if (type == byte.class)    { return 1; }
    if (type == boolean.class) { return 1; }
    if (type == short.class)   { return 2; }
    if (type == char.class)    { return 2; }
    if (type == int.class)     { return 4; }
    if (type == float.class)   { return 4; }
    if (type == long.class)    { return 8; }
    if (type == double.class)  { return 8; }
    return ADDRESS_SIZE;
}
项目:openjdk-jdk10    文件:BadClassFiles.java   
public void run() throws NoSuchMethodException {
    for (Class<?> cls : classes)
        assertBadParameters(cls);

    if (errors != 0)
        throw new RuntimeException(errors + " errors in test");
}
项目:productai-java-sdk    文件:EnumHelper.java   
public static HashMap<Integer, AIService> toServiceHashMap(Class _enumType){
    if (!_enumType.isEnum()) {
        throw new IllegalArgumentException("Only support enum type!");
    }
    HashMap<Integer, AIService> dic = new HashMap<Integer, AIService>();

    Field[] ps = _enumType.getFields();
    for(Field p : ps){
        if (!p.getType().equals(_enumType)) {
            continue;
        }
        Enum _enum = Enum.valueOf(_enumType, p.getName());
        ServiceDescriptionAttribute att = p.getAnnotation(ServiceDescriptionAttribute.class);
        if (att != null) {
            AIService newService = new AIService();
            newService.setName(att.Name());
            newService.setServiceType(att.ServiceType());
            newService.setServiceId(att.ServiceId());

            dic.put(_enum.ordinal(), newService);
        }
        else {
            throw new IllegalArgumentException(String.format("%s has no ServiceDescriptionAttribute", p.getName()));
        }
    }
    return dic;
}
项目:jdk8u-jdk    文件:BadClassFiles.java   
public void run() throws NoSuchMethodException {
    for (Class<?> cls : classes)
        assertBadParameters(cls);

    if (errors != 0)
        throw new RuntimeException(errors + " errors in test");
}
项目:GitHub    文件:GlideRequest.java   
/**
 * @see GlideOptions#transform(Class<T>, Transformation<T>)
 */
@CheckResult
public <T> GlideRequest<TranscodeType> transform(@NonNull Class<T> arg0,
    @NonNull Transformation<T> arg1) {
  if (getMutableOptions() instanceof GlideOptions) {
    this.requestOptions = ((GlideOptions) getMutableOptions()).transform(arg0, arg1);
  } else {
    this.requestOptions = new GlideOptions().apply(this.requestOptions).transform(arg0, arg1);
  }
  return this;
}
项目:hadoop    文件:TestConfigurationFieldsBase.java   
/**
 * Compares the properties that are in the XML properties file, but not
 * in the Configuration class.
 */
@Test
public void testCompareXmlAgainstConfigurationClass() {
  // Error if subclass hasn't set class members
  assertTrue(xmlFilename!=null);
  assertTrue(configurationClasses!=null);

  final int missingConfigSize = xmlFieldsMissingInConfiguration.size();

  System.out.println("File " + xmlFilename + " (" + xmlKeyValueMap.size() + " properties)");
  System.out.println();
  StringBuffer configErrorMsg = new StringBuffer();
  configErrorMsg.append(xmlFilename);
  configErrorMsg.append(" has ");
  configErrorMsg.append(missingConfigSize);
  configErrorMsg.append(" properties missing in");
  for (Class c : configurationClasses) {
    configErrorMsg.append("  " + c);
  }
  System.out.println(configErrorMsg.toString());
  System.out.println();
  if (missingConfigSize==0) {
    System.out.println("  (None)");
  } else {
    for (String missingField : xmlFieldsMissingInConfiguration) {
      System.out.println("  " + missingField);
    }
  }
  System.out.println();
  System.out.println("=====");
  System.out.println();
  if ( errorIfMissingConfigProps ) {
    assertTrue(configErrorMsg.toString(), missingConfigSize==0);
  }
}
项目:GitHub    文件:GlideRequest.java   
/**
 * @see GlideOptions#decode(Class<?>)
 */
@CheckResult
public GlideRequest<TranscodeType> decode(@NonNull Class<?> arg0) {
  if (getMutableOptions() instanceof GlideOptions) {
    this.requestOptions = ((GlideOptions) getMutableOptions()).decode(arg0);
  } else {
    this.requestOptions = new GlideOptions().apply(this.requestOptions).decode(arg0);
  }
  return this;
}
项目:openjdk-jdk10    文件:CaptureTest.java   
public Tester makeAnonExtendsInner(final String message) {
    return new InnerTester(2) {
        protected String[] names() {
            return new String[] {
                "this$1",
                "innerparam",
                "val$message"
            };
        }

        protected int[] modifiers() {
            return new int[] {
                Modifier.FINAL | MANDATED,
                Modifier.FINAL,
                Modifier.FINAL | SYNTHETIC
            };
        }

        protected Class[] types() {
            return new Class[] {
                Encloser.class,
                int.class,
                String.class
            };
        }

        public String message() {
            return message;
        }
    };
}
项目:GitHub    文件:GlideRequest.java   
/**
 * @see GlideOptions#decode(Class<?>)
 */
@CheckResult
public GlideRequest<TranscodeType> decode(@NonNull Class<?> arg0) {
  if (getMutableOptions() instanceof GlideOptions) {
    this.requestOptions = ((GlideOptions) getMutableOptions()).decode(arg0);
  } else {
    this.requestOptions = new GlideOptions().apply(this.requestOptions).decode(arg0);
  }
  return this;
}
项目:MaxSim    文件:DefaultValue.java   
public static boolean arePaddedPairwise(Class klass, String field1, String field2) throws Exception {
    Field f1 = klass.getField(field1);
    Field f2 = klass.getField(field2);

    int diff = offset(f1) - offset(f2);
    if (diff < 0) {
        // f1 is first
        return (offset(f2) - (offset(f1) + getSize(f1))) > 64;
    } else {
        // f2 is first
        return (offset(f1) - (offset(f2) + getSize(f2))) > 64;
    }
}
项目:GitHub    文件:GlideRequest.java   
GlideRequest(Class<TranscodeType> transcodeClass, RequestBuilder<?> other) {
  super(transcodeClass, other);
}
项目:GitHub    文件:GlideRequests.java   
@Override
@CheckResult
public <ResourceType> GlideRequest<ResourceType> as(Class<ResourceType> resourceClass) {
  return new GlideRequest<>(glide, this, resourceClass, context);
}