Skip to content

Commit

Permalink
Enable by default name mappings.
Browse files Browse the repository at this point in the history
	Change on 2018/07/20 by antoniocortes <antoniocortes@google.com>

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=205463134
  • Loading branch information
antonio-cortes-perez authored and Tom Ball committed Jul 31, 2018
1 parent b7c83db commit ea63036
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 22 deletions.
27 changes: 14 additions & 13 deletions translator/src/main/java/com/google/devtools/j2objc/Options.java
Expand Up @@ -66,7 +66,8 @@ public class Options {
private boolean jsniWarnings = true; private boolean jsniWarnings = true;
private boolean buildClosure = false; private boolean buildClosure = false;
private EnumSet<MetadataSupport> includedMetadata = private EnumSet<MetadataSupport> includedMetadata =
EnumSet.of(MetadataSupport.FULL, MetadataSupport.ENUM_CONSTANTS); EnumSet.of(
MetadataSupport.FULL, MetadataSupport.ENUM_CONSTANTS, MetadataSupport.NAME_MAPPING);
private boolean emitWrapperMethods = true; private boolean emitWrapperMethods = true;
private boolean extractUnsequencedModifications = true; private boolean extractUnsequencedModifications = true;
private boolean docCommentsEnabled = false; private boolean docCommentsEnabled = false;
Expand Down Expand Up @@ -208,8 +209,8 @@ public enum MetadataSupport {
// Generate metadata for enum constants. // Generate metadata for enum constants.
ENUM_CONSTANTS, ENUM_CONSTANTS,


// Generate class name mapping. // Generate name mapping.
CLASS_NAMES, NAME_MAPPING,


// Generate all metadata. // Generate all metadata.
FULL; FULL;
Expand Down Expand Up @@ -387,12 +388,12 @@ private void processArg(Iterator<String> args) throws IOException {
includedMetadata.remove(MetadataSupport.ENUM_CONSTANTS); includedMetadata.remove(MetadataSupport.ENUM_CONSTANTS);
break; break;
} }
case "class-names": { case "name-mapping": {
includedMetadata.add(MetadataSupport.CLASS_NAMES); includedMetadata.add(MetadataSupport.NAME_MAPPING);
break; break;
} }
case "-class-names": { case "-name-mapping": {
includedMetadata.remove(MetadataSupport.CLASS_NAMES); includedMetadata.remove(MetadataSupport.NAME_MAPPING);
break; break;
} }
default: { default: {
Expand Down Expand Up @@ -737,7 +738,7 @@ public boolean stripReflection() {
public void setStripReflection(boolean b) { public void setStripReflection(boolean b) {
if (b) { if (b) {
includedMetadata.remove(MetadataSupport.FULL); includedMetadata.remove(MetadataSupport.FULL);
includedMetadata.remove(MetadataSupport.CLASS_NAMES); includedMetadata.remove(MetadataSupport.NAME_MAPPING);
} else { } else {
includedMetadata = EnumSet.allOf(MetadataSupport.class); includedMetadata = EnumSet.allOf(MetadataSupport.class);
} }
Expand All @@ -756,16 +757,16 @@ public void setStripEnumConstants(boolean b) {
} }
} }


public boolean stripClassNameMapping() { public boolean stripNameMapping() {
return !includedMetadata.contains(MetadataSupport.CLASS_NAMES); return !includedMetadata.contains(MetadataSupport.NAME_MAPPING);
} }


@VisibleForTesting @VisibleForTesting
public void setStripClassNameMapping(boolean b) { public void setStripNameMapping(boolean b) {
if (b) { if (b) {
includedMetadata.remove(MetadataSupport.CLASS_NAMES); includedMetadata.remove(MetadataSupport.NAME_MAPPING);
} else { } else {
includedMetadata.add(MetadataSupport.CLASS_NAMES); includedMetadata.add(MetadataSupport.NAME_MAPPING);
} }
} }


Expand Down
Expand Up @@ -230,7 +230,7 @@ private void printTypeLiteralImplementation() {
} }


private void printNameMapping() { private void printNameMapping() {
if (!options.stripClassNameMapping()) { if (!options.stripNameMapping()) {
Optional<String> mapping = nameTable.getNameMapping(typeElement, typeName); Optional<String> mapping = nameTable.getNameMapping(typeElement, typeName);
if (mapping.isPresent()) { if (mapping.isPresent()) {
newline(); newline();
Expand Down
Expand Up @@ -74,7 +74,7 @@ Other options:\n\
\n annotation, unless its value is known to be compatible.\n\ \n annotation, unless its value is known to be compatible.\n\
--strip-reflection Do not generate metadata needed for Java reflection.\n\ --strip-reflection Do not generate metadata needed for Java reflection.\n\
--reflection:{all,none,enum-constants,-enum-constants,\ --reflection:{all,none,enum-constants,-enum-constants,\
class-names,-class-names}\n\ name-mapping,-name-mapping}\n\
\n Generate or exclude specific support needed for Java\n\ \n Generate or exclude specific support needed for Java\n\
\n reflection.\n\ \n reflection.\n\
--no-wrapper-methods Do not generate Objective-C wrapper methods for constructors\ --no-wrapper-methods Do not generate Objective-C wrapper methods for constructors\
Expand Down
Expand Up @@ -684,7 +684,6 @@ public void testPackageInfoDocNoAnnotation() throws IOException {
} }


public void testPackageInfoPrefixAnnotation() throws IOException { public void testPackageInfoPrefixAnnotation() throws IOException {
options.setStripClassNameMapping(false);
addSourcesToSourcepaths(); addSourcesToSourcepaths();
addSourceFile( addSourceFile(
"@ObjectiveCName(\"FBM\")\n" "@ObjectiveCName(\"FBM\")\n"
Expand All @@ -704,7 +703,6 @@ public void testPackageInfoPrefixAnnotation() throws IOException {
} }


public void testPackageInfoPreprocessing() throws IOException { public void testPackageInfoPreprocessing() throws IOException {
options.setStripClassNameMapping(false);
addSourceFile( addSourceFile(
"@ObjectiveCName(\"FBM\")\n" "@ObjectiveCName(\"FBM\")\n"
+ "package foo.bar.mumble;\n" + "package foo.bar.mumble;\n"
Expand All @@ -724,7 +722,6 @@ public void testPackageInfoPreprocessing() throws IOException {
} }


public void testPackageInfoOnClasspath() throws IOException { public void testPackageInfoOnClasspath() throws IOException {
options.setStripClassNameMapping(false);
addSourceFile( addSourceFile(
"@ObjectiveCName(\"FBM\")\n" "@ObjectiveCName(\"FBM\")\n"
+ "package foo.bar.mumble;\n" + "package foo.bar.mumble;\n"
Expand Down Expand Up @@ -833,7 +830,7 @@ public void testForwardDeclarationForPrivateAbstractDeclaration() throws IOExcep
} }


public void testNameMappingStripped() throws IOException { public void testNameMappingStripped() throws IOException {
options.setStripReflection(true); options.setStripNameMapping(true);
String translation = translateSourceFile( String translation = translateSourceFile(
"@com.google.j2objc.annotations.ObjectiveCName(\"NSTest\") public class Test {}", "@com.google.j2objc.annotations.ObjectiveCName(\"NSTest\") public class Test {}",
"Test", "Test.m"); "Test", "Test.m");
Expand All @@ -842,15 +839,14 @@ public void testNameMappingStripped() throws IOException {


public void testNameMappingNotStripped() throws IOException { public void testNameMappingNotStripped() throws IOException {
options.setStripReflection(true); options.setStripReflection(true);
options.setStripClassNameMapping(false); options.setStripNameMapping(false);
String translation = translateSourceFile( String translation = translateSourceFile(
"@com.google.j2objc.annotations.ObjectiveCName(\"NSTest\") public class Test {}", "@com.google.j2objc.annotations.ObjectiveCName(\"NSTest\") public class Test {}",
"Test", "Test.m"); "Test", "Test.m");
assertTranslation(translation, "J2OBJC_NAME_MAPPING(NSTest, \"Test\", \"NSTest\")"); assertTranslation(translation, "J2OBJC_NAME_MAPPING(NSTest, \"Test\", \"NSTest\")");
} }


public void testNameMappingNestedClass() throws IOException { public void testNameMappingNestedClass() throws IOException {
options.setStripClassNameMapping(false);
String hFile = String hFile =
translateSourceFile( translateSourceFile(
"package foo; " "package foo; "
Expand Down Expand Up @@ -879,7 +875,6 @@ public void testNameMappingNestedClass() throws IOException {
* anonymous classes. * anonymous classes.
*/ */
public void testCasesWithoutNameMapping() throws IOException { public void testCasesWithoutNameMapping() throws IOException {
options.setStripClassNameMapping(false);
addSourceFile( addSourceFile(
"@ObjectiveCName(\"FBM\")\n" "@ObjectiveCName(\"FBM\")\n"
+ "package foo.bar.mumble;\n" + "package foo.bar.mumble;\n"
Expand Down

0 comments on commit ea63036

Please sign in to comment.