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 Project: openjdk-8-source   Author: keerath   File: Basic.java    License: 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 #2
Source Project: TencentKona-8   Author: Tencent   File: Basic.java    License: 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 #3
Source Project: gemfirexd-oss   Author: gemxd   File: ClassSize.java    License: 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 #4
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: XMLFactoryHelper.java    License: 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 #5
Source Project: manifold   Author: manifold-systems   File: GqlParentType.java    License: 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 #6
Source Project: hottub   Author: dsrg-uoft   File: BadClassFiles.java    License: 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 Project: hottub   Author: dsrg-uoft   File: Basic.java    License: 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 #8
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: Basic.java    License: 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 #9
Source Project: jdk8u60   Author: chenghanpeng   File: BadClassFiles.java    License: 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 #10
Source Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   File: BadClassFiles.java    License: 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 #11
Source Project: openjdk-8   Author: bpupadhyaya   File: BadClassFiles.java    License: 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 #12
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: BadClassFiles.java    License: 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 Project: squirrelAI   Author: Zhyblx   File: CreateSQLiteService.java    License: 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 #14
Source Project: manifold   Author: manifold-systems   File: GqlParentType.java    License: 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 #15
Source Project: openjdk-8   Author: bpupadhyaya   File: DefaultValue.java    License: 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 #16
Source Project: dragonwell8_jdk   Author: alibaba   File: BadClassFiles.java    License: 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 #17
Source Project: dragonwell8_jdk   Author: alibaba   File: BadClassFiles.java    License: 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 #18
Source Project: TencentKona-8   Author: Tencent   File: DefaultValue.java    License: 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 #19
Source Project: openjdk-8-source   Author: keerath   File: DefaultValue.java    License: 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 #20
Source Project: TencentKona-8   Author: Tencent   File: Inheritance1.java    License: 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 #21
Source Project: manifold   Author: manifold-systems   File: GqlParentType.java    License: Apache License 2.0 5 votes vote down vote up
private SrcType makeSrcType( SrcLinkedClass owner, Type type, boolean typeParam )
{
  SrcType srcType;
  if( type instanceof ListType )
  {
    srcType = new SrcType( "List" );
    srcType.addTypeParam( makeSrcType( owner, ((ListType)type).getType(), true ) );
  }
  else if( type instanceof TypeName )
  {
    String typeName = getJavaClassName( owner, (TypeName)type, typeParam );
    srcType = new SrcType( typeName );
    if( !typeParam )
    {
      Class<?> javaClass = getJavaClass( (TypeName)type, false );
      srcType.setPrimitive( javaClass != null && javaClass.isPrimitive() );
    }
  }
  else if( type instanceof NonNullType )
  {
    Type theType = ((NonNullType)type).getType();
    srcType = makeSrcType( owner, theType, typeParam );
    if( !typeParam && !srcType.isPrimitive() )
    {
      srcType.addAnnotation( new SrcAnnotationExpression( NotNull.class.getSimpleName() ) );
    }
  }
  else
  {
    throw new IllegalStateException( "Unhandled type: " + type.getClass().getTypeName() );
  }
  return srcType;
}
 
Example #22
Source Project: openjdk-8-source   Author: keerath   File: Inheritance1.java    License: 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 #23
Source Project: hottub   Author: dsrg-uoft   File: Inheritance1.java    License: 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 Project: TencentKona-8   Author: Tencent   File: CaptureTest.java    License: 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 #25
Source Project: hottub   Author: dsrg-uoft   File: CaptureTest.java    License: 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;
        }
    };
}
 
Example #26
Source Project: TencentKona-8   Author: Tencent   File: BadClassFiles.java    License: 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 #27
Source Project: native-obfuscator   Author: radioegor146   File: BadClassFiles.java    License: GNU General Public License v3.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 #28
Source Project: openjdk-8   Author: bpupadhyaya   File: CaptureTest.java    License: GNU General Public License v2.0 5 votes vote down vote up
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;
        }
    };
}
 
Example #29
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: CaptureTest.java    License: GNU General Public License v2.0 5 votes vote down vote up
public Tester makeLocal(final String message) {
    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
            };
        }

        public String message() {
            return message;
        }
    }

    return new LocalTester(2);
}
 
Example #30
Source Project: openjdk-8   Author: bpupadhyaya   File: MessageBase.java    License: GNU General Public License v2.0 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;
}