Skip to content

Commit

Permalink
Use immutable sets and make sure resources are closed when reading re…
Browse files Browse the repository at this point in the history
…served names file.

	Change on 2017/07/13 by kstanger <kstanger@google.com>

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=161825426
  • Loading branch information
kstanger committed Jul 17, 2017
1 parent c2c03ee commit 6f6637e
Showing 1 changed file with 4 additions and 8 deletions.
Expand Up @@ -21,8 +21,6 @@
import com.google.common.base.Splitter;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.google.devtools.j2objc.J2ObjC;
import com.google.devtools.j2objc.Options;
import com.google.devtools.j2objc.ast.CompilationUnit;
Expand All @@ -38,7 +36,6 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.logging.Logger;
import java.util.regex.Pattern;
import javax.lang.model.element.AnnotationMirror;
Expand Down Expand Up @@ -97,10 +94,9 @@ public class NameTable {
private static final ImmutableSet<String> reservedNames = loadReservedNames();

private static ImmutableSet<String> loadReservedNames() {
try {
try (InputStream stream = J2ObjC.class.getResourceAsStream(RESERVED_NAMES_FILE);
BufferedReader lines = new BufferedReader(new InputStreamReader(stream, "UTF-8"))) {
ImmutableSet.Builder<String> builder = ImmutableSet.builder();
InputStream stream = J2ObjC.class.getResourceAsStream(RESERVED_NAMES_FILE);
BufferedReader lines = new BufferedReader(new InputStreamReader(stream, "UTF-8"));
String line;
while ((line = lines.readLine()) != null) {
if (line.startsWith("#")) {
Expand All @@ -114,7 +110,7 @@ private static ImmutableSet<String> loadReservedNames() {
}
}

private static final Set<String> badParameterNames = Sets.newHashSet(
private static final ImmutableSet<String> badParameterNames = ImmutableSet.of(
// Objective-C type qualifier keywords.
"in", "out", "inout", "oneway", "bycopy", "byref");

Expand All @@ -125,7 +121,7 @@ private static ImmutableSet<String> loadReservedNames() {
* "public boolean isEqual(Object o)" would be translated as
* "- (BOOL)isEqualWithObject:(NSObject *)o", not NSObject's "isEqual:".
*/
public static final List<String> nsObjectMessages = Lists.newArrayList(
public static final ImmutableSet<String> nsObjectMessages = ImmutableSet.of(
"alloc", "attributeKeys", "autoContentAccessingProxy", "autorelease",
"classCode", "classDescription", "classForArchiver",
"classForKeyedArchiver", "classFallbacksForKeyedArchiver",
Expand Down

0 comments on commit 6f6637e

Please sign in to comment.