Skip to content

Commit

Permalink
Replace constants (static final CONSTANT_CASE) declaration type which…
Browse files Browse the repository at this point in the history
… use the general collection interface (e.g. List) with an immutable type (e.g. ImmutableList).

For constant field declarations, you should use the immutable type (such as ImmutableList) instead of the general collection interface type (such as List). This communicates to your callers important semantic guarantees.

	Change on 2017/04/04 by dorir <dorir@google.com>

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=152162023
  • Loading branch information
dorireuv authored and tomball committed Apr 11, 2017
1 parent 9040e6c commit 771d35e
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 33 deletions.
Expand Up @@ -34,12 +34,26 @@ public class PropertyAnnotation extends Annotation {

private final Set<String> attributes;

private static final List<String> PROPERTY_ATTRIBUTES = ImmutableList.of(
"weak", "readonly", "copy", "assign", "nonatomic",
"getter", "setter", "retain", "unsafe_unretained", "class",
"nonnull", "nullable", "null_resettable", "null_unspecified",
// Default values aren't kept, but may be listed in set when debugging.
"atomic", "readwrite", "strong");
private static final ImmutableList<String> PROPERTY_ATTRIBUTES =
ImmutableList.of(
"weak",
"readonly",
"copy",
"assign",
"nonatomic",
"getter",
"setter",
"retain",
"unsafe_unretained",
"class",
"nonnull",
"nullable",
"null_resettable",
"null_unspecified",
// Default values aren't kept, but may be listed in set when debugging.
"atomic",
"readwrite",
"strong");
private static final Ordering<String> ATTRIBUTE_ORDERING = Ordering.explicit(PROPERTY_ATTRIBUTES);
private static final Comparator<String> ATTRIBUTES_COMPARATOR = new Comparator<String>() {
@Override
Expand Down
Expand Up @@ -134,7 +134,7 @@ public static MethodDeclaration getEnclosingMethod(TreeNode node) {
return getNearestAncestorWithType(MethodDeclaration.class, node);
}

private static final List<Class<?>> EXECUTABLE_DECLARATION_TYPES =
private static final ImmutableList<Class<?>> EXECUTABLE_DECLARATION_TYPES =
ImmutableList.of(MethodDeclaration.class, FunctionDeclaration.class);

public static TypeMirror getOwningReturnType(TreeNode node) {
Expand Down Expand Up @@ -285,8 +285,9 @@ public static List<BodyDeclaration> getEnclosingTypeBodyDeclarations(TreeNode no
return getEnclosingType(node).getBodyDeclarations();
}

private static final List<Class<?>> NODE_TYPES_WITH_ELEMENTS = ImmutableList.of(
AbstractTypeDeclaration.class, MethodDeclaration.class, VariableDeclaration.class);
private static final ImmutableList<Class<?>> NODE_TYPES_WITH_ELEMENTS =
ImmutableList.of(
AbstractTypeDeclaration.class, MethodDeclaration.class, VariableDeclaration.class);

public static Element getEnclosingElement(TreeNode node) {
return getDeclaredElement(getNearestAncestorWithTypeOneOf(NODE_TYPES_WITH_ELEMENTS, node));
Expand Down
Expand Up @@ -32,32 +32,38 @@
public class Mappings {

/**
* We convert all the String constructor invocations to factory method
* invocations because we want to avoid calling [NSString alloc].
* We convert all the String constructor invocations to factory method invocations because we want
* to avoid calling [NSString alloc].
*/
public static final Map<String, String> STRING_CONSTRUCTOR_TO_METHOD_MAPPINGS =
public static final ImmutableMap<String, String> STRING_CONSTRUCTOR_TO_METHOD_MAPPINGS =
ImmutableMap.<String, String>builder()
.put("java.lang.String.<init>()V", "string")
.put("java.lang.String.<init>(Ljava/lang/String;)V", "stringWithString:")
.put("java.lang.String.<init>([B)V", "java_stringWithBytes:")
.put("java.lang.String.<init>([BLjava/lang/String;)V", "java_stringWithBytes:charsetName:")
.put("java.lang.String.<init>([BLjava/nio/charset/Charset;)V",
"java_stringWithBytes:charset:")
.put("java.lang.String.<init>([BI)V", "java_stringWithBytes:hibyte:")
.put("java.lang.String.<init>([BII)V", "java_stringWithBytes:offset:length:")
.put("java.lang.String.<init>([BIII)V", "java_stringWithBytes:hibyte:offset:length:")
.put("java.lang.String.<init>([BIILjava/lang/String;)V",
"java_stringWithBytes:offset:length:charsetName:")
.put("java.lang.String.<init>([BIILjava/nio/charset/Charset;)V",
"java_stringWithBytes:offset:length:charset:")
.put("java.lang.String.<init>([C)V", "java_stringWithCharacters:")
.put("java.lang.String.<init>([CII)V", "java_stringWithCharacters:offset:length:")
.put("java.lang.String.<init>([III)V", "java_stringWithInts:offset:length:")
.put("java.lang.String.<init>(Ljava/lang/StringBuffer;)V",
"java_stringWithJavaLangStringBuffer:")
.put("java.lang.String.<init>(Ljava/lang/StringBuilder;)V",
"java_stringWithJavaLangStringBuilder:")
.build();
.put("java.lang.String.<init>()V", "string")
.put("java.lang.String.<init>(Ljava/lang/String;)V", "stringWithString:")
.put("java.lang.String.<init>([B)V", "java_stringWithBytes:")
.put(
"java.lang.String.<init>([BLjava/lang/String;)V", "java_stringWithBytes:charsetName:")
.put(
"java.lang.String.<init>([BLjava/nio/charset/Charset;)V",
"java_stringWithBytes:charset:")
.put("java.lang.String.<init>([BI)V", "java_stringWithBytes:hibyte:")
.put("java.lang.String.<init>([BII)V", "java_stringWithBytes:offset:length:")
.put("java.lang.String.<init>([BIII)V", "java_stringWithBytes:hibyte:offset:length:")
.put(
"java.lang.String.<init>([BIILjava/lang/String;)V",
"java_stringWithBytes:offset:length:charsetName:")
.put(
"java.lang.String.<init>([BIILjava/nio/charset/Charset;)V",
"java_stringWithBytes:offset:length:charset:")
.put("java.lang.String.<init>([C)V", "java_stringWithCharacters:")
.put("java.lang.String.<init>([CII)V", "java_stringWithCharacters:offset:length:")
.put("java.lang.String.<init>([III)V", "java_stringWithInts:offset:length:")
.put(
"java.lang.String.<init>(Ljava/lang/StringBuffer;)V",
"java_stringWithJavaLangStringBuffer:")
.put(
"java.lang.String.<init>(Ljava/lang/StringBuilder;)V",
"java_stringWithJavaLangStringBuilder:")
.build();

private static final String JRE_MAPPINGS_FILE = "JRE.mappings";

Expand Down

0 comments on commit 771d35e

Please sign in to comment.