Skip to content

Commit

Permalink
Automated g4 rollback of changelist 188726817.
Browse files Browse the repository at this point in the history
*** Reason for rollback ***

Client app depends on Iterable.h header.

*** Original change description ***

Declared java.lang.Iterable in Java source, to aid application dead code stripping.

***

	Change on 2018/03/12 by tball <tball@google.com>

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=188741081
  • Loading branch information
tomball committed Mar 13, 2018
1 parent a90653b commit ccf2f27
Show file tree
Hide file tree
Showing 11 changed files with 218 additions and 186 deletions.
4 changes: 0 additions & 4 deletions jre_emul/Classes/J2ObjC_common.h
Expand Up @@ -22,7 +22,6 @@
#import "J2ObjC_types.h" #import "J2ObjC_types.h"


@class IOSClass; @class IOSClass;
@protocol JavaLangIterable;


#ifndef __has_feature #ifndef __has_feature
#define __has_feature(x) 0 // Compatibility with non-clang compilers. #define __has_feature(x) 0 // Compatibility with non-clang compilers.
Expand Down Expand Up @@ -93,9 +92,6 @@ NSString *JreStrcat(const char *types, ...);
jboolean JreAnnotationEquals(id a1, id a2); jboolean JreAnnotationEquals(id a1, id a2);
jint JreAnnotationHashCode(id a); jint JreAnnotationHashCode(id a);


NSUInteger JreDefaultFastEnumeration(
id<JavaLangIterable> obj, NSFastEnumerationState *state, id __unsafe_unretained *stackbuf);

CF_EXTERN_C_END CF_EXTERN_C_END


/*! /*!
Expand Down
38 changes: 4 additions & 34 deletions jre_emul/Classes/J2ObjC_common.m
Expand Up @@ -24,31 +24,30 @@
#import "java/lang/AbstractStringBuilder.h" #import "java/lang/AbstractStringBuilder.h"
#import "java/lang/AssertionError.h" #import "java/lang/AssertionError.h"
#import "java/lang/ClassCastException.h" #import "java/lang/ClassCastException.h"
#import "java/lang/Iterable.h"
#import "java/lang/NullPointerException.h" #import "java/lang/NullPointerException.h"
#import "java/lang/Throwable.h" #import "java/lang/Throwable.h"
#import "java/util/logging/Level.h" #import "java/util/logging/Level.h"
#import "java/util/logging/Logger.h" #import "java/util/logging/Logger.h"
#import "objc/runtime.h" #import "objc/runtime.h"


id JreThrowNullPointerException() { id JreThrowNullPointerException() {
@throw create_JavaLangNullPointerException_init(); // NOLINT @throw create_JavaLangNullPointerException_init();
} }


void JreThrowClassCastException(id obj, Class cls) { void JreThrowClassCastException(id obj, Class cls) {
@throw create_JavaLangClassCastException_initWithNSString_( // NOLINT @throw create_JavaLangClassCastException_initWithNSString_(
[NSString stringWithFormat:@"Cannot cast object of type %@ to %@", [NSString stringWithFormat:@"Cannot cast object of type %@ to %@",
[[obj java_getClass] getName], NSStringFromClass(cls)]); [[obj java_getClass] getName], NSStringFromClass(cls)]);
} }


void JreThrowClassCastExceptionWithIOSClass(id obj, IOSClass *cls) { void JreThrowClassCastExceptionWithIOSClass(id obj, IOSClass *cls) {
@throw create_JavaLangClassCastException_initWithNSString_( // NOLINT @throw create_JavaLangClassCastException_initWithNSString_(
[NSString stringWithFormat:@"Cannot cast object of type %@ to %@", [NSString stringWithFormat:@"Cannot cast object of type %@ to %@",
[[obj java_getClass] getName], [cls getName]]); [[obj java_getClass] getName], [cls getName]]);
} }


void JreThrowAssertionError(id __unsafe_unretained msg) { void JreThrowAssertionError(id __unsafe_unretained msg) {
@throw AUTORELEASE([[JavaLangAssertionError alloc] initWithId:[msg description]]); // NOLINT @throw AUTORELEASE([[JavaLangAssertionError alloc] initWithId:[msg description]]);
} }


void JreFinalize(id self) { void JreFinalize(id self) {
Expand All @@ -74,7 +73,6 @@ id JreStrongAssignAndConsume(__strong id *pIvar, NS_RELEASES_ARGUMENT id value)
// locks for atomic access is consistent with how Apple implements atomic // locks for atomic access is consistent with how Apple implements atomic
// property accessors, and the hashing used here is inspired by Apple's // property accessors, and the hashing used here is inspired by Apple's
// implementation: // implementation:
// NOLINTNEXTLINE
// http://www.opensource.apple.com/source/objc4/objc4-532.2/runtime/Accessors.subproj/objc-accessors.mm // http://www.opensource.apple.com/source/objc4/objc4-532.2/runtime/Accessors.subproj/objc-accessors.mm
// Spin locks are unsafe to use on iOS because of the potential for priority // Spin locks are unsafe to use on iOS because of the potential for priority
// inversion so we use pthread_mutex. // inversion so we use pthread_mutex.
Expand Down Expand Up @@ -415,31 +413,3 @@ FOUNDATION_EXPORT void JreRelease(id obj) {
return [NSString stringWithFormat:@"%@_%d", NSStringFromClass(enumClass.objcClass), ordinal]; return [NSString stringWithFormat:@"%@_%d", NSStringFromClass(enumClass.objcClass), ordinal];
} }
} }

NSUInteger JreDefaultFastEnumeration(
__unsafe_unretained id<JavaLangIterable> obj, NSFastEnumerationState *state,
__unsafe_unretained id *stackbuf) {
SEL hasNextSel = sel_registerName("hasNext");
SEL nextSel = sel_registerName("next");
__unsafe_unretained id iter = (ARCBRIDGE id) (void *) state->extra[0];
if (!iter) {
static unsigned long no_mutation = 1;
state->mutationsPtr = &no_mutation;
// The for/in loop could break early so we have no guarantee of being able
// to release the iterator. As long as the current autorelease pool is not
// cleared within the loop, this should be fine.
iter = nil_chk([obj iterator]);
state->extra[0] = (unsigned long) iter;
state->extra[1] = (unsigned long) [iter methodForSelector:hasNextSel];
state->extra[2] = (unsigned long) [iter methodForSelector:nextSel];
}
jboolean (*hasNextImpl)(id, SEL) = (jboolean (*)(id, SEL)) state->extra[1];
id (*nextImpl)(id, SEL) = (id (*)(id, SEL)) state->extra[2];
NSUInteger objCount = 0;
state->itemsPtr = stackbuf;
if (hasNextImpl(iter, hasNextSel)) {
*stackbuf++ = nextImpl(iter, nextSel);
objCount++;
}
return objCount;
}
59 changes: 59 additions & 0 deletions jre_emul/Classes/java/lang/Iterable.h
@@ -0,0 +1,59 @@
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//
// Iterable.h
// JreEmulation
//
// Created by kstanger on 8/28/13.
//

#ifndef _JavaLangIterable_H_
#define _JavaLangIterable_H_

@protocol JavaUtilIterator;

#include "J2ObjC_header.h"

@protocol JavaUtilFunctionConsumer;
@protocol JavaUtilIterator;
@protocol JavaUtilSpliterator;

/**
* Instances of classes that implement this interface can be used with
* the enhanced for loop.
*/
@protocol JavaLangIterable <NSFastEnumeration, JavaObject>

- (id<JavaUtilIterator>)iterator;

- (void)forEachWithJavaUtilFunctionConsumer:(id<JavaUtilFunctionConsumer>)action;

- (id<JavaUtilSpliterator>)spliterator;

@end

@interface JavaLangIterable : NSObject < JavaLangIterable >
@end

J2OBJC_EMPTY_STATIC_INIT(JavaLangIterable)

J2OBJC_TYPE_LITERAL_HEADER(JavaLangIterable)

FOUNDATION_EXPORT NSUInteger JreDefaultFastEnumeration(
id<JavaLangIterable> obj, NSFastEnumerationState *state, id __unsafe_unretained *stackbuf);

FOUNDATION_EXPORT void JavaLangIterable_forEachWithJavaUtilFunctionConsumer_(id<JavaLangIterable> self, id<JavaUtilFunctionConsumer> action);

FOUNDATION_EXPORT id<JavaUtilSpliterator> JavaLangIterable_spliterator(id<JavaLangIterable> self);

#endif // _JavaLangIterable_H_
104 changes: 104 additions & 0 deletions jre_emul/Classes/java/lang/Iterable.m
@@ -0,0 +1,104 @@
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//
// Iterable.h
// JreEmulation
//
// Created by kstanger on 8/28/13.
//

#include "java/lang/Iterable.h"

#include "J2ObjC_source.h"
#include "java/util/Iterator.h"
#include "java/util/Iterator.h"
#include "java/util/Objects.h"
#include "java/util/Spliterator.h"
#include "java/util/Spliterators.h"
#include "java/util/function/Consumer.h"

#pragma clang diagnostic ignored "-Wprotocol"

@implementation JavaLangIterable

- (void)forEachWithJavaUtilFunctionConsumer:(id<JavaUtilFunctionConsumer>)action {
JavaLangIterable_forEachWithJavaUtilFunctionConsumer_(self, action);
}

- (id<JavaUtilSpliterator>)spliterator {
return JavaLangIterable_spliterator(self);
}

+ (const J2ObjcClassInfo *)__metadata {
static J2ObjcMethodInfo methods[] = {
{ NULL, "LJavaUtilIterator;", 0x401, -1, -1, -1, 0, -1, -1 },
{ NULL, "V", 0x1, 1, 2, -1, 3, -1, -1 },
{ NULL, "LJavaUtilSpliterator;", 0x1, -1, -1, -1, 4, -1, -1 },
};
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wobjc-multiple-method-names"
methods[0].selector = @selector(iterator);
methods[1].selector = @selector(forEachWithJavaUtilFunctionConsumer:);
methods[2].selector = @selector(spliterator);
#pragma clang diagnostic pop
static const void *ptrTable[] = {
"()Ljava/util/Iterator<TT;>;", "forEach", "LJavaUtilFunctionConsumer;",
"(Ljava/util/function/Consumer<-TT;>;)V", "()Ljava/util/Spliterator<TT;>;",
"<T:Ljava/lang/Object;>Ljava/lang/Object;" };
static const J2ObjcClassInfo _JavaLangIterable = {
"Iterable", "java.lang", ptrTable, methods, NULL, 7, 0x609, 3, 0, -1, -1, -1, 5, -1 };
return &_JavaLangIterable;
}

@end

void JavaLangIterable_forEachWithJavaUtilFunctionConsumer_(id<JavaLangIterable> self, id<JavaUtilFunctionConsumer> action) {
JavaUtilObjects_requireNonNullWithId_(action);
for (id __strong t in self) {
[((id<JavaUtilFunctionConsumer>) nil_chk(action)) acceptWithId:t];
}
}

id<JavaUtilSpliterator> JavaLangIterable_spliterator(id<JavaLangIterable> self) {
return JavaUtilSpliterators_spliteratorUnknownSizeWithJavaUtilIterator_withInt_([self iterator], 0);
}

J2OBJC_INTERFACE_TYPE_LITERAL_SOURCE(JavaLangIterable)

NSUInteger JreDefaultFastEnumeration(
__unsafe_unretained id<JavaLangIterable> obj, NSFastEnumerationState *state,
__unsafe_unretained id *stackbuf) {
SEL hasNextSel = @selector(hasNext);
SEL nextSel = @selector(next);
__unsafe_unretained id iter = (ARCBRIDGE id) (void *) state->extra[0];
if (!iter) {
static unsigned long no_mutation = 1;
state->mutationsPtr = &no_mutation;
// The for/in loop could break early so we have no guarantee of being able
// to release the iterator. As long as the current autorelease pool is not
// cleared within the loop, this should be fine.
iter = nil_chk([obj iterator]);
state->extra[0] = (unsigned long) iter;
state->extra[1] = (unsigned long) [iter methodForSelector:hasNextSel];
state->extra[2] = (unsigned long) [iter methodForSelector:nextSel];
}
jboolean (*hasNextImpl)(id, SEL) = (jboolean (*)(id, SEL)) state->extra[1];
id (*nextImpl)(id, SEL) = (id (*)(id, SEL)) state->extra[2];
NSUInteger objCount = 0;
state->itemsPtr = stackbuf;
if (hasNextImpl(iter, hasNextSel)) {
*stackbuf++ = nextImpl(iter, nextSel);
objCount++;
}
return objCount;
}

This file was deleted.

Expand Up @@ -25,9 +25,6 @@
*/ */


package java.lang; package java.lang;

import com.google.j2objc.NSException;

import java.io.*; import java.io.*;
import java.util.*; import java.util.*;


Expand Down

0 comments on commit ccf2f27

Please sign in to comment.