java.lang.Class Java Examples

The following examples show how to use java.lang.Class. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CreateSQLiteService.java    From squirrelAI with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {
        try {

            Class.forName("org.sqlite.JDBC");
            connection = DriverManager.getConnection("jdbc:sqlite:SquirrelAI.db");
            statement = connection.createStatement();
//            String sql = "CREATE TABLE message(date varchar(255),name varchar(255),message varchar(512));";
            //UserName、NickName、RemarkName、Province、City
            String sql = "CREATE TABLE user(username varchar(255),nickname varchar(255),remarkname varchar(512),province varchar(512),city varchar(512));";

            statement.executeUpdate(sql);
            statement.close();
            connection.close();
            System.out.println("数据库创建成功!");

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
 
Example #2
Source File: BadClassFiles.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
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)
    };
}
 
Example #3
Source File: GqlParentType.java    From manifold with Apache License 2.0 6 votes vote down vote up
private Class<?> findJsonEquivalent( String scalarName )
{
  switch( scalarName )
  {
    case "Time":
    case "LocalTime":
      return findFormatType( "time" );
    case "Date":
    case "LocalDate":
      return findFormatType( "date" );
    case "DateTime":
    case "LocalDateTime":
      return findFormatType( "date-time" );
    case "Instant":
      return findFormatType( "utc-millisec" );
    case "Base64":
      return findFormatType( "binary" );
    case "Binary":
    case "Octet":
      return findFormatType( "byte" );
  }
  return String.class;
}
 
Example #4
Source File: BadClassFiles.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
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)
    };
}
 
Example #5
Source File: XMLFactoryHelper.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
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);
    }

}
 
Example #6
Source File: BadClassFiles.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
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)
    };
}
 
Example #7
Source File: BadClassFiles.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
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)
    };
}
 
Example #8
Source File: GqlParentType.java    From manifold with Apache License 2.0 6 votes vote down vote up
private void addInnerInterfaceType( InterfaceTypeDefinition type, SrcLinkedClass enclosingType )
{
  String identifier = makeIdentifier( type.getName(), false );
  String fqn = getFqn() + '.' + identifier;
  SrcLinkedClass srcClass = new SrcLinkedClass( fqn, enclosingType, Interface )
    .addInterface( IJsonBindingsBacked.class.getSimpleName() )
    .addAnnotation( new SrcAnnotationExpression( Structural.class.getSimpleName() )
      .addArgument( "factoryClass", Class.class, identifier + ".ProxyFactory.class" ) )
    .modifiers( Modifier.PUBLIC );
  addUnionInterfaces( type, srcClass );
  addActualNameAnnotation( srcClass, type.getName(), false );
  addSourcePositionAnnotation( srcClass, type, srcClass );
  addProxyFactory( srcClass );
  List<FieldDefinition> fieldDefinitions = type.getFieldDefinitions();
  for( FieldDefinition member: fieldDefinitions )
  {
    addMember( srcClass, member, name -> fieldDefinitions.stream().anyMatch( f -> f.getName().equals( name ) ) );
  }
  addInterfaceExtensions( type, srcClass );
  enclosingType.addInnerClass( srcClass );
}
 
Example #9
Source File: ClassSize.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
private static int estimateBaseFromCatalog( Class cls, boolean addToCatalog)
 {
     if( dummyCatalog)
         return 0;
     
     if( SanityManager.DEBUG)
SanityManager.ASSERT( catalog != null, "The class size catalog could not be initialized.");
     
     int[] coeff = (int[]) catalog.get( cls.getName());
     if( coeff == null)
     {
         try
         {
             coeff = getSizeCoefficients( cls);
         }
         catch( Throwable t)
         {
             if( noGuess)
                 return -2;
             coeff = wildGuess;
         }
         if( addToCatalog)
             catalog.put( cls.getName(), coeff);
     }
     return estimateBaseFromCoefficients( coeff);
 }
 
Example #10
Source File: Basic.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
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;
    }
}
 
Example #11
Source File: Basic.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
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;
    }
}
 
Example #12
Source File: BadClassFiles.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
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)
    };
}
 
Example #13
Source File: Basic.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
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;
    }
}
 
Example #14
Source File: Basic.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
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;
    }
}
 
Example #15
Source File: Basic.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public static boolean isPadded(Class klass, String field1) throws Exception {
    Field f1 = klass.getDeclaredField(field1);

    if (isStatic(f1)) {
        return offset(f1) > 128 + 64;
    }

    return offset(f1) > 64;
}
 
Example #16
Source File: Basic.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example #17
Source File: Inheritance1.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
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;
    }
}
 
Example #18
Source File: BadClassFiles.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
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");
    }
}
 
Example #19
Source File: ClassApiTest.java    From reflection-no-reflection with Apache License 2.0 5 votes vote down vote up
@Test
public void testClassApi() throws Exception {

    final Class<java.lang.Class> reflectionClass = Class.class;
    final Class<org.reflection_no_reflection.Class> rnrClass = org.reflection_no_reflection.Class.class;

    final long similarityMeasure = getSimilarityMeasure(reflectionClass, rnrClass);
    System.out.println("Api compat score for Class: " + similarityMeasure + "%");
}
 
Example #20
Source File: AnnotationProxyMaker.java    From Mindustry with GNU General Public License v3.0 5 votes vote down vote up
public void visitEnum(Enum var1){
    if(this.returnClass.isEnum()){
        String var2 = var1.value.toString();

        try{
            this.value = java.lang.Enum.valueOf((Class)this.returnClass, var2);
        }catch(IllegalArgumentException var4){
            this.value = proxify(() -> new EnumConstantNotPresentException((Class)this.returnClass, var2));
        }
    }else{
        this.value = null;
    }

}
 
Example #21
Source File: CaptureTest.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public Tester makeAnon(final String message) {
    return new Tester(2) {
        protected String[] names() {
            return new String[] {
                "this$1",
                "param",
                "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;
        }
    };
}
 
Example #22
Source File: BadClassFiles.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
public void run() throws NoSuchMethodException {
    for (Class<?> cls : classes)
        assertBadParameters(cls);

    if (errors != 0)
        throw new RuntimeException(errors + " errors in test");
}
 
Example #23
Source File: DefaultValue.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example #24
Source File: DefaultValue.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example #25
Source File: BagFactory.java    From spork with Apache License 2.0 5 votes vote down vote up
/**
 * Get a reference to the singleton factory.
 * @return BagFactory
 */
public static BagFactory getInstance() {
    if (gSelf == null) {
        String factoryName =
            System.getProperty("pig.data.bag.factory.name");
        String factoryJar =
            System.getProperty("pig.data.bag.factory.jar");
        if (factoryName != null && factoryJar != null) {
            try {
                URL[] urls = new URL[1];
                urls[0] = new URL(factoryJar);
                ClassLoader loader = new URLClassLoader(urls,
                    BagFactory.class.getClassLoader());
                Class c = Class.forName(factoryName, true, loader);
                Object o = c.newInstance();
                if (!(o instanceof BagFactory)) {
                    throw new RuntimeException("Provided factory " +
                        factoryName + " does not extend BagFactory!");
                }
                gSelf = (BagFactory)o;
            } catch (Exception e) {
                if (e instanceof RuntimeException) {
                    // We just threw this
                    RuntimeException re = (RuntimeException)e;
                    throw re;
                }
                throw new RuntimeException("Unable to instantiate "
                    + "bag factory " + factoryName, e);
            }
        } else {
            gSelf = new DefaultBagFactory();
        }
    }
    return gSelf;
}
 
Example #26
Source File: MessageBase.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
static SystemException getSystemException(
    String exClassName, int minorCode, CompletionStatus completionStatus,
    String message, ORBUtilSystemException wrapper)
{
    SystemException sysEx = null;

    try {
        Class<?> clazz =
            SharedSecrets.getJavaCorbaAccess().loadClass(exClassName);
        if (message == null) {
            sysEx = (SystemException) clazz.newInstance();
        } else {
            Class[] types = { String.class };
            Constructor constructor = clazz.getConstructor(types);
            Object[] args = { message };
            sysEx = (SystemException)constructor.newInstance(args);
        }
    } catch (Exception someEx) {
        throw wrapper.badSystemExceptionInReply(
            CompletionStatus.COMPLETED_MAYBE, someEx );
    }

    sysEx.minor = minorCode;
    sysEx.completed = completionStatus;

    return sysEx;
}
 
Example #27
Source File: BadClassFiles.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public void run() throws NoSuchMethodException {
    for (Class<?> cls : classes)
        assertBadParameters(cls);

    if (errors != 0)
        throw new RuntimeException(errors + " errors in test");
}
 
Example #28
Source File: BadClassFiles.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
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");
    }
}
 
Example #29
Source File: NoName.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
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());
}
 
Example #30
Source File: CaptureTest.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
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;
        }
    };
}