Skip to content

Commit

Permalink
Adds the --no-class-methods flag to disable generating class methods …
Browse files Browse the repository at this point in the history
…from static methods.

	Change on 2014/11/06 by kstanger <[email protected]>
-------------
Created by MOE: http://code.google.com/p/moe-java
MOE_MIGRATED_REVID=79347960
  • Loading branch information
kstanger authored and tomball committed Nov 12, 2014
1 parent b9e5640 commit 784886f
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 2 deletions.
4 changes: 4 additions & 0 deletions doc/man/j2objc.1
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ Rewrite expressions that would produce unsequenced modification errors.
.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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public class Options {
private static boolean extractUnsequencedModifications = false;
private static boolean docCommentsEnabled = false;
private static boolean finalMethodsAsFunctions = false;
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 int batchTranslateMaximum = 0;
Expand Down Expand Up @@ -279,6 +280,8 @@ public static String[] load(String[] args) throws IOException {
Integer.parseInt(arg.substring(BATCH_PROCESSING_MAX_FLAG.length()));
} else if (arg.equals("--final-methods-as-functions")) {
finalMethodsAsFunctions = true;
} else if (arg.equals("--no-class-methods")) {
removeClassMethods = true;
} else if (arg.equals("--hide-private-members")) {
hidePrivateMembers = true;
} else if (arg.equals("--no-hide-private-members")) {
Expand Down Expand Up @@ -683,6 +686,10 @@ public static void resetFinalMethodsAsFunctions() {
finalMethodsAsFunctions = false;
}

public static boolean removeClassMethods() {
return removeClassMethods;
}

public static boolean hidePrivateMembers() {
return hidePrivateMembers;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ private void printFinalFunctionDecls(List<AbstractTypeDeclaration> types) {
}
// We expect native functions to be defined externally.
if (!Modifier.isNative(modifiers)) {
print("static ");
print("__attribute__((unused)) static ");
}
println(getFunctionSignature(function) + ";");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,13 @@ public void endVisit(MethodDeclaration node) {
function = makeInstanceFunction(node);
}
if (function != null) {
setFunctionCaller(node, function);
List<BodyDeclaration> declarationList = TreeUtil.asDeclarationSublist(node);
declarationList.add(function);
if (BindingUtil.isStatic(binding) && Options.removeClassMethods()) {
node.remove();
} else {
setFunctionCaller(node, function);
}
ErrorUtil.functionizedMethod();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
import com.google.devtools.j2objc.ast.AnnotationTypeMemberDeclaration;
import com.google.devtools.j2objc.ast.EnumDeclaration;
import com.google.devtools.j2objc.ast.FieldDeclaration;
import com.google.devtools.j2objc.ast.FunctionDeclaration;
import com.google.devtools.j2objc.ast.MethodDeclaration;
import com.google.devtools.j2objc.ast.SingleVariableDeclaration;
import com.google.devtools.j2objc.ast.TreeNode;
import com.google.devtools.j2objc.ast.TreeVisitor;
import com.google.devtools.j2objc.ast.Type;
Expand Down Expand Up @@ -96,6 +98,15 @@ public boolean visit(FieldDeclaration node) {
return true;
}

@Override
public boolean visit(FunctionDeclaration node) {
addForwardDecl(node.getReturnType());
for (SingleVariableDeclaration param : node.getParameters()) {
addForwardDecl(param.getType());
}
return false;
}

@Override
public boolean visit(MethodDeclaration node) {
addForwardDecl(node.getReturnType());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ Other options:\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\
Expand Down

0 comments on commit 784886f

Please sign in to comment.