Skip to content
This repository has been archived by the owner on Feb 17, 2023. It is now read-only.

V1.2 #7

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
  •  
  •  
  •  
16 changes: 16 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
### OS-X ###

.DS_Store
.AppleDouble
.LSOverride
Icon
._*
.Spotlight-V100
.Trashes


### Windows ###
Thumbs.db
ehthumbs.db
Desktop.ini
$RECYCLE.BIN/
7 changes: 4 additions & 3 deletions J2ObjC-Framework.podspec
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@version = "1.0.2.2"
@version = "1.2a"

Pod::Spec.new do |s|
s.name = "J2ObjC-Framework"
Expand All @@ -7,9 +7,10 @@ Pod::Spec.new do |s|
s.homepage = "https://actor.im/"
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.author = { "Actor LLC" => "[email protected]" }
s.source = { :git => "https://github.com/actorapp/J2ObjC-Framework.git", :tag => "v#{s.version}" }
s.source = { :git => "https://github.com/dfsilva/J2ObjC-Framework.git", :tag => "v#{s.version}" }

s.platform = :ios, "8.0"
s.ios.deployment_target = "8.0"
s.osx.deployment_target = "10.11"
s.requires_arc = true

s.frameworks = 'Security'
Expand Down
4 changes: 2 additions & 2 deletions Scripts/Template/Headers/IOSArray.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@
@end

CF_EXTERN_C_BEGIN
void IOSArray_throwOutOfBounds();
void IOSArray_throwOutOfBoundsWithMsg(jint size, jint index);
void IOSArray_throwRangeOutOfBounds(jint size, jint offset, jint length);
CF_EXTERN_C_END

/** Implements the IOSArray |checkIndex| method as a C function. This
Expand All @@ -83,7 +83,7 @@ __attribute__((always_inline)) inline void IOSArray_checkRange(
jint size, jint offset, jint length) {
#if !defined(J2OBJC_DISABLE_ARRAY_BOUND_CHECKS)
if (__builtin_expect(length < 0 || offset < 0 || offset + length > size, 0)) {
IOSArray_throwOutOfBounds();
IOSArray_throwRangeOutOfBounds(size, offset, length);
}
#endif
}
Expand Down
31 changes: 16 additions & 15 deletions Scripts/Template/Headers/IOSClass.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#ifndef _IOSClass_H_
#define _IOSClass_H_

#import "IOSReflection.h"
#import "IOSMetadata.h"
#import "J2ObjC_common.h"
#import "java/io/Serializable.h"
#import "java/lang/reflect/AnnotatedElement.h"
Expand All @@ -34,10 +34,9 @@
@class JavaLangReflectConstructor;
@class JavaLangReflectField;
@class JavaLangReflectMethod;
@protocol JavaLangAnnotationAnnotation;
@class JavaIoInputStream;
@class JavaClassMetadata;
@class JavaNetURL;
@protocol JavaLangAnnotationAnnotation;

/**
* The representation of a Java class, which serves as the starting
Expand All @@ -54,7 +53,7 @@
@property (readonly) Class objcClass;
@property (readonly) Protocol *objcProtocol;

- (instancetype)initWithClass:(Class)cls;
- (instancetype)initWithMetadata:(const J2ObjcClassInfo *)metadata;

// IOSClass Getters.
+ (IOSClass *)classForIosName:(NSString *)iosName;
Expand Down Expand Up @@ -90,7 +89,7 @@
- (NSString *)getCanonicalName;

// Class.getModifiers()
- (int)getModifiers;
- (jint)getModifiers;

// Class.getDeclaredConstructors()
- (IOSObjectArray *)getDeclaredConstructors;
Expand Down Expand Up @@ -154,11 +153,13 @@
- (IOSObjectArray *)getGenericInterfaces;
- (IOSObjectArray *)getTypeParameters;

- (id)getAnnotationWithIOSClass:(IOSClass *)annotationClass;
- (id<JavaLangAnnotationAnnotation>)
getAnnotationWithIOSClass:(IOSClass *)annotationClass;
- (jboolean)isAnnotationPresentWithIOSClass:(IOSClass *)annotationType;
- (IOSObjectArray *)getAnnotations;
- (IOSObjectArray *)getDeclaredAnnotations;

- (id<JavaLangAnnotationAnnotation>)
getDeclaredAnnotationWithIOSClass:(IOSClass *)annotationClass;
- (id)getPackage;
- (id)getClassLoader;

Expand All @@ -185,6 +186,8 @@
- (id)getProtectionDomain;
- (id)getSigners;

- (NSString *)toGenericString;

// Boxing and unboxing (internal)
- (id)__boxValue:(J2ObjcRawValue *)rawValue;
- (jboolean)__unboxValue:(id)value toRawValue:(J2ObjcRawValue *)rawValue;
Expand All @@ -193,19 +196,17 @@
- (jboolean)__convertRawValue:(J2ObjcRawValue *)rawValue toType:(IOSClass *)type;

// Internal methods
- (void)collectMethods:(NSMutableDictionary *)methodMap
publicOnly:(jboolean)publicOnly;
- (JavaLangReflectMethod *)findMethodWithTranslatedName:(NSString *)objcName
checkSupertypes:(jboolean)checkSupertypes;
- (JavaLangReflectConstructor *)findConstructorWithTranslatedName:(NSString *)objcName;
- (JavaLangReflectMethod *)getMethodWithSelector:(const char *)selector;
// Same as getInterfaces, but not a defensive copy.
- (IOSObjectArray *)getInterfacesInternal;
- (JavaClassMetadata *)getMetadata;
- (const J2ObjcClassInfo *)getMetadata;
- (NSString *)objcName;
- (NSString *)binaryName;
- (void)appendMetadataName:(NSMutableString *)str;
// Get the IOSArray subclass that would be used to hold this type.
- (Class)objcArrayClass;
- (size_t)getSizeof;
- (IOSObjectArray *)getEnumConstantsShared;

@end

Expand Down Expand Up @@ -235,8 +236,8 @@ IOSClass *IOSClass_arrayType(IOSClass *componentType, jint dimensions);
#define IOSClass_booleanArray(DIM) IOSClass_arrayType([IOSClass booleanClass], DIM)

// Internal functions
NSString *IOSClass_GetTranslatedMethodName(
IOSClass *cls, NSString *name, IOSObjectArray *paramTypes);
const J2ObjcClassInfo *IOSClass_GetMetadataOrFail(IOSClass *iosClass);
IOSClass *IOSClass_NewProxyClass(Class cls);

// Return value is retained
IOSObjectArray *IOSClass_NewInterfacesFromProtocolList(Protocol **list, unsigned int count);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,21 @@
// limitations under the License.

//
// IOSReflection.h
// IOSMetadata.h
// JreEmulation
//
// Created by Tom Ball on 9/23/13.
//

#ifndef JreEmulation_IOSReflection_h
#define JreEmulation_IOSReflection_h
#ifndef JreEmulation_IOSMetadata_h
#define JreEmulation_IOSMetadata_h

#import "J2ObjC_common.h"
#import "objc/runtime.h"
#import <Foundation/Foundation.h>

@protocol JavaLangReflectType;
@class IOSClass;
#import "J2ObjC_types.h"

// Current metadata structure version
#define J2OBJC_METADATA_VERSION 2
#define J2OBJC_METADATA_VERSION 7

// A raw value is the union of all possible native types.
typedef union {
Expand All @@ -47,67 +45,47 @@ typedef union {
// all information provided by the reflection API is discoverable via the
// Objective-C runtime.

// Use same data types that the translator generates.
typedef union J2ObjcConstantValue {
jboolean boolean;
char byte;
unichar char_;
double double_;
float float_;
int int_;
long long long_;
short short_;
const char *string;
} J2ObjcConstantValue;
typedef int16_t ptr_idx;

typedef struct J2ObjcMethodInfo {
const char *selector;
const char *javaName;
SEL selector;
const char *returnType;
uint16_t modifiers;
const char *exceptions;
const char *genericSignature;
ptr_idx javaNameIdx;
ptr_idx paramsIdx;
ptr_idx exceptionsIdx;
ptr_idx genericSignatureIdx;
ptr_idx annotationsIdx;
ptr_idx paramAnnotationsIdx;
} J2ObjcMethodInfo;

typedef struct J2ObjcFieldInfo {
const char *name;
const char *javaName;
uint16_t modifiers;
const char *type;
const void *staticRef;
const char *genericSignature;
J2ObjcRawValue constantValue;
uint16_t modifiers;
ptr_idx javaNameIdx;
ptr_idx staticRefIdx;
ptr_idx genericSignatureIdx;
ptr_idx annotationsIdx;
} J2ObjcFieldInfo;

typedef struct J2ObjCEnclosingMethodInfo {
const char *typeName;
const char *selector;
} J2ObjCEnclosingMethodInfo;

typedef struct J2ObjcClassInfo {
const unsigned version;
const char *typeName;
const char *packageName;
const char *enclosingName;
const void **ptrTable;
const J2ObjcMethodInfo *methods;
const J2ObjcFieldInfo *fields;
// Pointer types are above version for better packing.
const uint16_t version;
uint16_t modifiers;
uint16_t methodCount;
const J2ObjcMethodInfo *methods;
uint16_t fieldCount;
const J2ObjcFieldInfo *fields;
uint16_t superclassTypeArgsCount;
const char **superclassTypeArgs;
uint16_t innerClassCount;
const char **innerClassnames;
const J2ObjCEnclosingMethodInfo *enclosingMethod;
const char *genericSignature;
ptr_idx enclosingClassIdx;
ptr_idx innerClassesIdx;
ptr_idx enclosingMethodIdx;
ptr_idx genericSignatureIdx;
ptr_idx annotationsIdx;
} J2ObjcClassInfo;

// Autoboxing support.

extern id<JavaLangReflectType> JreTypeForString(const char *typeStr);
extern IOSClass *TypeToClass(id<JavaLangReflectType>);
extern Method JreFindInstanceMethod(Class cls, const char *name);
extern Method JreFindClassMethod(Class cls, const char *name);
extern NSMethodSignature *JreSignatureOrNull(struct objc_method_description *methodDesc);

#endif // JreEmulation_IOSReflection_h
#endif // JreEmulation_IOSMetadata_h
22 changes: 22 additions & 0 deletions Scripts/Template/Headers/J2ObjC_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,18 @@
#define J2OBJC_DISABLE_ARRAY_TYPE_CHECKS 1
#endif

// An empty struct type to declare the capture state in LambdaBase.
// Actual capturing lambdas will be allocated with extra bytes to
// accommodate their captures.
typedef struct LambdaCaptures {
} LambdaCaptures;
// A base type for all lambdas to inherit.
@interface LambdaBase : NSObject {
@public
LambdaCaptures captures_;
}
@end

CF_EXTERN_C_BEGIN

void JreThrowNullPointerException() __attribute__((noreturn));
Expand All @@ -82,6 +94,11 @@ void JreCloneVolatile(volatile_id *pVar, volatile_id *pOther);
void JreCloneVolatileStrong(volatile_id *pVar, volatile_id *pOther);
void JreReleaseVolatile(volatile_id *pVar);

id JreRetainedWithAssign(id parent, __strong id *pIvar, id value);
id JreVolatileRetainedWithAssign(id parent, volatile_id *pIvar, id value);
void JreRetainedWithRelease(id parent, id child);
void JreVolatileRetainedWithRelease(id parent, volatile_id *pVar);

NSString *JreStrcat(const char *types, ...);

#if defined(J2OBJC_COUNT_NIL_CHK) && !defined(J2OBJC_DISABLE_NIL_CHECKS)
Expand Down Expand Up @@ -113,6 +130,11 @@ __attribute__((always_inline)) inline id JreAutoreleasedAssign(
}
#endif

/*!
* Utility macro for passing an argument that contains a comma.
*/
#define J2OBJC_ARG(...) __VA_ARGS__

#define J2OBJC_VOLATILE_ACCESS_DEFN(NAME, TYPE) \
__attribute__((always_inline)) inline TYPE JreLoadVolatile##NAME(volatile_##TYPE *pVar) { \
return __c11_atomic_load(pVar, __ATOMIC_SEQ_CST); \
Expand Down
13 changes: 8 additions & 5 deletions Scripts/Template/Headers/J2ObjC_source.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
#define _J2OBJC_SOURCE_H_

#import "IOSClass.h" // Type literal accessors.
#import "IOSMetadata.h"
#import "IOSObjectArray.h"
#import "IOSPrimitiveArray.h"
#import "IOSReflection.h" // Metadata methods.
#import "J2ObjC_common.h"
#import "JavaObject.h"
#import "NSCopying+JavaCloneable.h"
Expand All @@ -27,6 +27,7 @@
#import "NSObject+JavaObject.h"
#import "NSString+JavaString.h"
#import "jni.h"
#import "objc/runtime.h"

#pragma clang system_header

Expand Down Expand Up @@ -79,6 +80,8 @@ __attribute__((always_inline)) inline void JreCheckFinalize(id self, Class cls)
}
}

FOUNDATION_EXPORT jint JreIndexOfStr(NSString *str, NSString **values, jint size);

/*!
* Macros that simplify the syntax for loading of static fields.
*
Expand Down Expand Up @@ -141,10 +144,10 @@ __attribute__((always_inline)) inline void JreCheckFinalize(id self, Class cls)
#endif

// Defined in J2ObjC_common.m
FOUNDATION_EXPORT id GetNonCapturingLambda(Class clazz, Protocol *protocol,
NSString *blockClassName, SEL methodSelector, id block);
FOUNDATION_EXPORT id GetCapturingLambda(Class clazz, Protocol *protocol,
NSString *blockClassName, SEL methodSelector, id wrapperBlock, id block);
FOUNDATION_EXPORT id CreateNonCapturing(const char *lambdaName, jint numProtocols,
Protocol *protocols[], jint numMethods, SEL selectors[], IMP impls[], const char *signatures[]);
FOUNDATION_EXPORT Class CreatePossiblyCapturingClass(const char *lambdaName, jint numProtocols,
Protocol *protocols[], jint numMethods, SEL selectors[], IMP impls[], const char *signatures[]);

#define J2OBJC_IGNORE_DESIGNATED_BEGIN \
_Pragma("clang diagnostic push") \
Expand Down
4 changes: 3 additions & 1 deletion Scripts/Template/Headers/JavaObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@
#ifndef _JavaObject_H_
#define _JavaObject_H_

#import <Foundation/Foundation.h>

@class IOSClass;

/// A protocol that defines Java Object-compatible methods.
@protocol JavaObject
@protocol JavaObject <NSObject>

// Returns a copy of the object, if it implements java.lang.Cloneable.
- (id)clone;
Expand Down
2 changes: 1 addition & 1 deletion Scripts/Template/Headers/JreEmulation.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
#import "J2ObjC_common.h"
#import "JavaObject.h"
#import "IOSClass.h"
#import "IOSMetadata.h"
#import "IOSObjectArray.h"
#import "IOSPrimitiveArray.h"
#import "IOSReflection.h"
#import "NSCopying+JavaCloneable.h"
#import "NSException+JavaThrowable.h"
#import "NSNumber+JavaNumber.h"
Expand Down
Loading