Zelix KlassMaster - Documentation
 

The removeMethodCallsInclude Statement

The ZKM Script removeMethodCallsInclude statement allows you to specify method calls that you want to have removed from your classes by a following removeMethodCalls statement. It is intended to be used for the removal of "optional" method calls which have no effect such as debugging statements. However, Zelix KlassMaster™ will not remove method calls in cases where the method returns an object which is actually used (as opposed to being popped off the stack). Successive removeMethodCallsInclude statements have a cumulative effect. Once a specification has been set its effect can be If there is a removeMethodCallsInclude statement without a removeMethodCallsExclude statement then only the specified method calls will be considered for removal. If there is a removeMethodCallsInclude statement and a removeMethodCallsExclude statement then the removeMethodCallsInclude statement will be applied first against the set of all method calls and then the removeMethodCallsExclude statement will be applied against the set of method calls specified by the removeMethodCallsInclude statement.

The remainder of this page is organized into the following sections.

Examples and Explanation

removeMethodCallsInclude statement parameters must specify methods. They may optionally start with a containedIn clause.

The containedIn clause

The method reference include parameters below can have an initial containedIn clause. The containedIn clause specifies the methods containing the method calls that will removed. Put another way, it specifies the methods which make the method call which you want to have removed. For example you could tell Zelix KlassMaster™ to remove all calls to methods of java.lang.System but only where those calls are contained in methods within your class pack0.Class0.

Put informally (with mandatory components in bold), the syntax of the containedIn clause is:
containedIn{ <methodIncludeParameter> }

Or with the <methodIncludeParameter> expanded:
containedIn{ <classAnnotations> <classModifiers> <packageQualifiers>.<className> <extendsClause> <implementsClause>
    <methodAnnotations> <methodModifiers> <methodName>(<argumentTypes>) <throwsClause> }

So you have a method specification within parentheses preceded by the keyword containedIn. If a removeMethodCallsInclude statement doesn't have a containedIn clause then it is the same as if it has a containedIn clause like the following which specifies ALL methods. Such a containedIn clause is satisfied by all references.

containedIn{*.* *(*)}

For a method containing a reference to be matched by a containedIn clause, all of the following must be true for the clause's <methodIncludeParameter>:
  • Its containing class must match any class include parameter component.
  • Its annotations must match any specified method or method parameter level annotations.
  • Its modifiers (e.g. public native) must match all parameter method modifiers. So if the parameters are public static !synchronized then the method must be public, static and NOT synchronized to be matched.
  • Its name must match the parameter method name.
  • Its argument types (e.g. int[], java.lang.String) must match the parameter argument types if they exist. (A single parameter argument type of "*" matches any method argument types including no arguments.) If the parameter has no argument type then the method must take no arguments.
  • Its throws clause must contain all the classes specified in the include parameter's throw clause. So, if the include parameter's throws clause is throws java.io.IOException then the method must throw java.io.IOException or one of its subclasses to be matched.

Method reference include parameters

Put informally (with mandatory components in bold), the syntax is:
<containedInClause> <classAnnotations> <classModifiers> <packageQualifiers>.<className> <extendsClause> <implementsClause>
    <methodAnnotations> <methodModifiers> <methodName>(<argumentTypes>) <throwsClause> +signatureClasses;

For a method to be matched by the statement, all of the following must be true:
  • The reference must occur in a method which matches the <containedInClause> if it exists.
  • Its containing class must match any class include parameter component.
  • Its annotations must match any specified method or method parameter level annotations.
  • Its modifiers (e.g. public native) must match all parameter method modifiers. So if the parameters are public static !synchronized then the method must be public, static and NOT synchronized to be matched.
  • Its name must match the parameter method name.
  • Its argument types (e.g. int[], java.lang.String) must match the parameter argument types if they exist. (A single parameter argument type of "*" matches any method argument types including no arguments.) If the parameter has no argument type then the method must take no arguments.
  • Its throws clause must contain all the classes specified in the include parameter's throw clause. So, if the include parameter's throws clause is throws java.io.IOException then the method must throw java.io.IOException or one of its subclasses to be matched.
removeMethodCallsInclude *.* *(*)           and  //Match references to all methods
                         containedIn{pack0.* *(*)} *.* !static m*() and //Match references to all non-static methods taking no parameters with names matching "m*"
						                        //where the reference occurs in a method within the "pack0" package
                         *.* !static m*()   and  //Match references to all non-static methods taking no parameters with names matching "m*"
                         //Match references to all "native" methods. Also match the containing class.
                         *.*^ native *(*)  and  
                         *.* *(*) throws java.io.IOException and  //Match references to all methods that throw "java.io.IOException". 
                         //Match references to all "abstract" methods that  take a single String.
                         *.* abstract *(java.lang.String) and 
                         //Match references to all methods in pack1.Class1 along with the matching methods' return and parameter types
                         //Match references to all the methods of any class implementing "Serializable" in a package that matches "pack1.*"
                         pack1.* implements java.io.Serializable *(*) and
                         //Match references to all methods annotated with a class matching "*.MyAnnotation0".
                         *.* @*.MyAnnotation0 *(*) and
                         //Match references to all methods in java.lang.System which occur in a method annotated with a class matching "*.MyAnnotation0".
                         containedIn{*.* @*.MyAnnotation0 *(*)} java.lang.System *(*);

Syntax

"removeMethodCallsInclude" includeParameter ("and" includeParameter)* ";"

annotationSpecifier ::= ("@" [packageIncludeParameter] nameSpecifier) | annotationSpecifierAndList

annotationSpecifierAndList ::= ["!"] "(" annotationSpecifierOrList ("&&" annotationSpecifierOrList)* ")"

annotationSpecifierOrList ::= annotationSpecifier ("||" annotationSpecifier)*

classIncludeParameter ::=
   [annotationSpecifier] [["!"] "public" | "package"]
   [["!"] "abstract"] [["!"] "final"] [["!"] "interface"] [["!"] "synthetic"] [["!"] "enum"] [["!"] "annotation"]
   [packageIncludeParameter] nameSpecifier ["^"] ["+"] [extendsClause] [implementsClause]

containedInClause ::= "containedIn" "{" "methodIncludeParameter" "}"

containingClause ::= "containing" "{" "memberAndList" "}"

includeParameter ::= [containedInClause] methodIncludeParameter

extendsClause ::= "extends" [annotationSpecifier] wildcardClassName

fullyQualifiedClassName ::= name ("." name)*

implementsClause ::= "implements" [annotationSpecifier] wildcardClassName ("," [annotationSpecifier] wildcardClassName)*

memberAndList ::= ["!"] "(" memberOrList ("&&" memberOrList)* ")"

memberOrList ::= memberSpecifier ("||" memberSpecifier)*

memberSpecifier ::= methodIncludeParameter

nameAndList ::= ["!"] "(" nameOrList ("&&" nameOrList)* ")"

methodIncludeParameter ::=
   classIncludeParameter [annotationSpecifier] [["!"] "public" | "protected"| "package"| "private"]
   [["!"] "abstract"] [["!"] "static"] [["!"] "final"] [["!"] "native"] [["!"] "synchronized"] [["!"] "synthetic"] [["!"] "bridge"]
   nameSpecifier "(" [ "*" | (parameter ("," parameter)*)] ")" ["throws" wildcardClassName]

name ::= (["0"-"9","a"-"z","A"-"Z","$","_"])+
   i.e. a Java identifer (e.g. a package, class or method name) with no wildcards allowed

nameAndList ::= ["!"] "(" nameOrList ("&&" nameOrList)* ")"

nameOrList ::= nameSpecifier ("||" nameSpecifier)*

nameSpecifier ::= wildcardName | nameAndList

packageIncludeParameter ::= packageName | packageNameAndList

packageName ::= wildcardName ("." wildcardName)* "."
   NB: the final "." is part of the package name

packageNameAndList ::= ["!"] "(" packageNameOrList ("&&" packageNameOrList)* ")"

packageNameOrList ::= packageIncludeParameter ("||" packageIncludeParameter)*

parameter ::= [annotationSpecifier] ("*" | "?" | type)

type ::=
   ("byte" | "short" | "char" | "int" | "long" | "float" | "double"| "boolean" |
   fullyQualifiedClassName) ("[]")*

wildcardClassName ::= wildcardName ("." wildcardName)*

wildcardName ::= (["*","0"-"9","a"-"z","A"-"Z","$","_"])+
   i.e. a Java identifer (e.g. a package, class or method name) with the "*" wildcard allowed
 
ZKM Script trim statement The ZKM Script Language ZKM Script removeMethodCallsInclude statement