Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Class JClass<T> #27

Open
nsanitate opened this issue Jul 24, 2017 · 2 comments
Open

Class JClass<T> #27

nsanitate opened this issue Jul 24, 2017 · 2 comments

Comments

@nsanitate
Copy link
Member

nsanitate commented Jul 24, 2017

Implement class JClass<T>, porting of the Java class java.lang.Class<T>.

Instances of the class Class represent classes and interfaces in a running Java application. An enum is a kind of class and an annotation is a kind of interface. Every array also belongs to a class that is reflected as a Class object that is shared by all arrays with the same element type and number of dimensions. The primitive Java types (boolean, byte, char, short, int, long, float, and double), and the keyword void are also represented as Class objects.
T - the type of the class modeled by this Class object.

Expected Behavior

Casts an object to the class or interface represented by this Class object.

  • public method getCanonicalName(): JString

Returns the canonical name of the underlying class as defined by the Java Language Specification.

  • public method getName(): JString

Returns the name of the entity (class, interface, array class, primitive type, or void) represented by this Class object, as a String.

  • public method getSimpleName(): JString

Returns the simple name of the underlying class as given in the source code.

  • public method getTypeName(): JString

Return an informative string for the name of this type.

  • public method isAnnotation(): Jboolean

Returns true if this Class object represents an annotation type.

  • public method isArray(): Jboolean

Determines if this Class object represents an array class.

  • public method isEnum(): Jboolean

Returns true if and only if this class was declared as an enum in the source code.

  • public method isInstance(obj: JObject): Jboolean

Determines if the specified Object is assignment-compatible with the object represented by this Class.

  • public method isInterface(): Jboolean

Determines if the specified Class object represents an interface type.

  • public method newInstance(): T

Creates a new instance of the class represented by this Class object.

  • public method toString(): JString

Converts the object to a string.

Do it later

  • public static method forName(className: JString): JClass<?>
  • public static method forName(name: JString, initialize: Jboolean, loader: JClassLoader)
  • public method asSubclass<U>(clazz: JClass<U>): JClass<? extends U>
  • public method desiredAssertionStatus(): Jboolean
  • public method getAnnotatedInterfaces(): Jarray<JAnnotatedType>
  • public method getAnnotatedSuperclass(): JAnnotatedType
  • public method getAnnotation<A extends JAnnotation>(annotationClass: JClass<A>): A
  • public method getAnnotations(): Jarray<JAnnotation>
  • public method getAnnotationsByType<A extends Annotation>(annotationClass: JClass<A>): Jarray<A>
  • public method getClasses(): Jarray<JClass<?>>
  • public method getClassLoader(): JClassLoader
  • public method getComponentType(): JClass<?>
  • public method getConstructor(...parameterTypes: Jarray<JClass<?>>): JConstructor<T>
  • public method getConstructors(): Jarray<JConstructor<?>>
  • public method getDeclaredAnnotation<A extends JAnnotation>(annotationClass: JClass<A>): A
  • public method getDeclaredAnnotations(): Jarray<JAnnotation>
  • public method getDeclaredAnnotationsByType<A extends JAnnotation>(annotationClass: JClass<A>): Jarray<A>
  • public method getDeclaredClasses(): Jarray<JClass<?>>
  • public method getDeclaredConstructor(...parameterTypes: Jarray<JClass<?>>): JConstructor<T>
  • public method getDeclaredConstructors(): Jarray<JConstructor<?>>
  • public method getDeclaredField(name: JString): JField
  • public method getDeclaredFields(): Jarray<JField>
  • public method getDeclaredMethod(name: JString, ...parameterTypes: Jarray<JClass<?>>): JMethod
  • public method getDeclaredMethods(): Jarray<JMethod>
  • public method getDeclaringClass(): JClass<?>
  • public method getEnclosingClass(): JClass<?>
  • public method getEnclosingConstructor(): JConstructor<?>
  • public method getEnclosingMethod(): JMethod
  • public method getEnumConstants(): Jarray<T>
  • public method getField(name: JString): JField
  • public method getFields(): Jarray<JField>
  • public method getGenericInterfaces(): Jarray<JType>
  • public method getGenericSuperclass(): JType
  • public method getInterfaces(): Jarray<JClass<?>>
  • public method getMethod(name: JString, ...parameterTypes: Jarray<JClass<?>>): JMethod
  • public method getMethods(): Jarray<JMethod>
  • public method getModifiers(): Jint
  • public method getPackage(): JPackage
  • public method getProtectionDomain(): JProtectionDomain
  • public method getResource(name: JString): JURL
  • public method getResourceAsStream(name: JString): JInputStream
  • public method getSigners(): Jarray<JObject>
  • public method getSuperclass(): JClass<? extends T>
  • public method getTypeParameters(): Jarray<JTypeVariable<JClass<T>>>
  • public method isAnnotationPresent(annotationClass: JClass<? extends JAnnotation>): Jboolean
  • public method isAnonymousClass(): Jboolean
  • public method isAssignableFrom(cls: JClass<?>): Jboolean
  • public method isLocalClass(): Jboolean
  • public method isMemberClass(): Jboolean
  • public method isPrimitive(): Jboolean
  • public method isSynthetic(): Jboolean
  • public method toGenericString(): JString
@dammafra
Copy link

dammafra commented Aug 4, 2017

Questions:

  1. Class objects in Java are never instantiated directly, but are instantiated by the JVM Class Loader. Should we emulate its behaviour?
  2. There's a problem of ciruclar dependency between JObject module and JClass module since JClass extends JObject, but JObject returns an instance of JClass in getClass() method. We could have the same problem with JString or other classes in future.
  3. We should find a way for determine the type of an object at runtime. It's not possible with Typescript generics or interfaces (maybe to replace with annotations and abstract classes).

@nsanitate
Copy link
Member Author

  1. Yes, you can build an engine that simulate the JVM Class Loader.
  2. In the future we will have many similar cases. Please find a definitive solution.
  3. You can use Typescript decorators and reflect-metadata library

@nsanitate nsanitate removed the question label Aug 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants