Skip to content

Commit

Permalink
Removed -use-gc, set default to true for final-methods-as-functions a…
Browse files Browse the repository at this point in the history
…nd hide-private-members flags, adding flags to disable that functionality.

	Change on 2014/11/20 by tball <[email protected]>
-------------
Created by MOE: http://code.google.com/p/moe-java
MOE_MIGRATED_REVID=80410967
  • Loading branch information
tomball committed Nov 20, 2014
1 parent d085c26 commit f9e2ea1
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 47 deletions.
20 changes: 10 additions & 10 deletions doc/man/j2objc.1
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,9 @@ Translate Javadoc comments into Xcode-compatible comments.
.BI \-\-extract\-unsequenced
Rewrite expressions that would produce unsequenced modification errors.
.TP
.BI \-\-final\-methods\-as\-functions
Call final methods as C functions, when possible.
.TP
.BI \-\-no\-class\-methods
Don't emit class methods for static Java methods.
(static methods are converted to functions)
.TP
.BI \-\-generate\-deprecated
Generate deprecated attributes for deprecated methods, classes, and interfaces.
.TP
.BI \-\-generate\-native\-stubs
Generate method bodies for native methods that do not have OCNI native code comments.
.TP
.BI \-\-ignore\-missing\-imports
Continue translation if an imported class is not found on the class or source paths.
.TP
Expand All @@ -94,6 +84,16 @@ Add a method mapping file.
.BI \-\-mem\-debug
Generate code to display memory allocation graphs.
.TP
.BI \-\-no\-class\-methods
Don't emit class methods for static Java methods.
(static methods are converted to functions)
.TP
.BI \-\-no\-final\-methods\-as\-functions
Disable generating functions for final methods.
.TP
.BI \-\-no\-hide\-private\-members
Includes private fields and methods in header file.
.TP
.BI \-\-no\-package\-directories
Generate output files to specified directory, without creating package sub-directories
.TP
Expand Down
17 changes: 7 additions & 10 deletions translator/src/main/java/com/google/devtools/j2objc/Options.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,9 @@ public class Options {
private static boolean stripReflection = false;
private static boolean extractUnsequencedModifications = false;
private static boolean docCommentsEnabled = false;
private static boolean finalMethodsAsFunctions = false;
private static boolean finalMethodsAsFunctions = true;
private static boolean removeClassMethods = false;
// TODO(tball): change default to true once clients had a chance to update their builds.
private static boolean hidePrivateMembers = false;
private static boolean hidePrivateMembers = true;
private static int batchTranslateMaximum = 0;

private static File proGuardUsageFile = null;
Expand Down Expand Up @@ -114,7 +113,7 @@ public class Options {
/**
* Types of memory management to be used by translated code.
*/
public static enum MemoryManagementOption { REFERENCE_COUNTING, GC, ARC }
public static enum MemoryManagementOption { REFERENCE_COUNTING, ARC }
private static final MemoryManagementOption DEFAULT_MEMORY_MANAGEMENT_OPTION =
MemoryManagementOption.REFERENCE_COUNTING;

Expand Down Expand Up @@ -228,8 +227,6 @@ public static String[] load(String[] args) throws IOException {
outputStyle = OutputStyleOption.NONE;
} else if (arg.equals("--preserve-full-paths")) {
outputStyle = OutputStyleOption.SOURCE;
} else if (arg.equals("-use-gc")) {
checkMemoryManagementOption(MemoryManagementOption.GC);
} else if (arg.equals("-use-arc")) {
checkMemoryManagementOption(MemoryManagementOption.ARC);
} else if (arg.equals("-g")) {
Expand Down Expand Up @@ -278,10 +275,14 @@ public static String[] load(String[] args) throws IOException {
} else if (arg.startsWith(BATCH_PROCESSING_MAX_FLAG)) {
batchTranslateMaximum =
Integer.parseInt(arg.substring(BATCH_PROCESSING_MAX_FLAG.length()));
// TODO(tball): remove obsolete flag once projects stop using it.
} else if (arg.equals("--final-methods-as-functions")) {
finalMethodsAsFunctions = true;
} else if (arg.equals("--no-final-methods-functions")) {
finalMethodsAsFunctions = false;
} else if (arg.equals("--no-class-methods")) {
removeClassMethods = true;
// TODO(tball): remove obsolete flag once projects stop using it.
} else if (arg.equals("--hide-private-members")) {
hidePrivateMembers = true;
} else if (arg.equals("--no-hide-private-members")) {
Expand Down Expand Up @@ -472,10 +473,6 @@ public static boolean useReferenceCounting() {
return memoryManagementOption == MemoryManagementOption.REFERENCE_COUNTING;
}

public static boolean useGC() {
return memoryManagementOption == MemoryManagementOption.GC;
}

public static boolean useARC() {
return memoryManagementOption == MemoryManagementOption.ARC;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,7 @@
* @author Tom Ball
*/
public class DestructorGenerator extends TreeVisitor {
private final String destructorName;

public DestructorGenerator() {
destructorName = Options.useGC() ? NameTable.FINALIZE_METHOD : NameTable.DEALLOC_METHOD;
}
private final String destructorName = NameTable.DEALLOC_METHOD;

@Override
public boolean visit(TypeDeclaration node) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,17 @@ Other options:\n\
--doc-comments Translate Javadoc comments into Xcode-compatible comments.\n\
--extract-unsequenced Rewrite expressions that would produce unsequenced\
\n modification errors.\n\
--final-methods-as-functions Call final methods as C functions, when possible.\n\
--no-class-methods Don't emit class methods for static Java methods.\
\n (static methods are converted to functions)\n\
--generate-deprecated Generate deprecated attributes for deprecated methods,\
\n classes and interfaces.\n\
--hide-private-members Removes private fields and methods from header file.\n\
--ignore-missing-imports Continue translation if an imported class is not\
\n found on the class or source paths.\n\
-J<flag> Pass Java <flag>, such as -Xmx1G, to the system runtime.\n\
--mapping <file> Add a method mapping file.\n\
--mem-debug Generate code to display memory allocation graphs.\n\
--no-class-methods Don't emit class methods for static Java methods.\
\n (static methods are always converted to functions)\n\
--no-final-methods-functions Disable generating functions for final methods.\n\
--no-hide-private-members Includes private fields and methods in header file.\n\
--no-package-directories Generate output files to specified directory, without\
\n creating package sub-directories.\n\
-pluginpath <path> Specify where to find plugin class files.\n\
Expand All @@ -74,8 +74,6 @@ Other options:\n\
-t, --timing-info Print time spent in translation steps.\n\
-use-arc Generate Objective-C code to support Automatic\
\n Reference Counting (ARC).\n\
-use-gc Generate Objective-C code to support garbage\
\n collection (requires libjre_emul.a rebuild).\n\
-use-reference-counting Generate Objective-C code to support iOS manual\
\n reference counting (default).\n\
-x <language> Specify what language to output. Possible values\
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,11 @@ public void testFinalParameterAccess() throws IOException {
// Test.foo(): since the bar_ parameter shadows a field, the parameter
// gets renamed to bar_Arg.
assertTranslation(translation, "- (void)fooWithId:(id)bar_Arg {");
assertTranslation(translation, "[self logWithInt:2 withId:bar_Arg];");
assertTranslation(translation, "Test_logWithInt_withId_(self, 2, bar_Arg);");

// Test_$: since bar_ is an unshadowed field, the parameter name is
// unchanged.
assertTranslation(translation, "[this$0_ logWithInt:1 withId:val$bar__];");
assertTranslation(translation, "Test_logWithInt_withId_(this$0_, 1, val$bar__);");
assertTranslation(translation, "Test_$1_set_val$bar__(self, capture$0);");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import com.google.devtools.j2objc.GenerationTest;
import com.google.devtools.j2objc.Options;
import com.google.devtools.j2objc.Options.MemoryManagementOption;

import java.io.IOException;

Expand Down Expand Up @@ -47,19 +46,6 @@ public void testFinalizeMethodRenamed() throws IOException {
assertFalse(translation.contains("- (void)finalize "));
}

public void testFinalizeMethodRenamedWithGC() throws IOException {
Options.setMemoryManagementOption(MemoryManagementOption.GC);
String translation = translateSourceFile(
"public class Test { public void finalize() { " +
" try { super.finalize(); } catch (Throwable t) {} }}", "Test", "Test.h");
assertTranslation(translation, "- (void)finalize;");
assertFalse(translation.contains("dealloc"));
translation = getTranslatedFile("Test.m");
assertTranslation(translation, "- (void)finalize ");
assertTranslation(translation, "[super finalize];");
assertFalse(translation.contains("dealloc"));
}

public void testFinalizeMethodRenamedWithReleasableFields() throws IOException {
String translation = translateSourceFile(
"public class Test {" +
Expand Down

0 comments on commit f9e2ea1

Please sign in to comment.