Commit da57ab71 authored by Lubomir Bulej's avatar Lubomir Bulej

Constants: provide methods to check whether a method name is a constructor or initializer name.

MethodStaticContext: provide methods to determine whether a method is a constructor or initializer.
*: use the new methods in Constants instead of directly referencing the constructor and initializer names. 
parent 49c13354
......@@ -27,7 +27,7 @@ final class TLVInserter extends ClassVisitor {
String sig, String[] exceptions) {
// add field initialization
if (Constants.CONSTRUCTOR_NAME.equals(name)) {
if (Constants.isConstructorName (name)) {
return new TLVInitializer(super.visitMethod(access, name, desc,
sig, exceptions), access, name, desc);
}
......
......@@ -61,7 +61,7 @@ abstract class AbstractParser {
for (MethodNode method : dislClass.methods) {
// get the code
if (method.name.equals(Constants.STATIC_INIT_NAME)) {
if (Constants.isInitializerName (method.name)) {
cinit = method;
break;
}
......
......@@ -62,12 +62,12 @@ class ProcessorParser extends AbstractParser {
for (MethodNode method : classNode.methods) {
// skip the constructor
if (method.name.equals(Constants.CONSTRUCTOR_NAME)) {
if (Constants.isConstructorName (method.name)) {
continue;
}
// skip static initializer
if (method.name.equals(Constants.STATIC_INIT_NAME)) {
if (Constants.isInitializerName (method.name)) {
continue;
}
......
......@@ -64,12 +64,12 @@ class SnippetParser extends AbstractParser {
for (MethodNode method : classNode.methods) {
// skip the constructor
if (method.name.equals(Constants.CONSTRUCTOR_NAME)) {
if (Constants.isConstructorName (method.name)) {
continue;
}
// skip static initializer
if (method.name.equals(Constants.STATIC_INIT_NAME)) {
if (Constants.isInitializerName (method.name)) {
continue;
}
......
......@@ -65,7 +65,7 @@ public class AfterInitBodyMarker extends AbstractMarker {
//
// Fast path for non-constructor methods.
//
if (!method.name.equals (Constants.CONSTRUCTOR_NAME)) {
if (!Constants.isConstructorName (method.name)) {
return method.instructions.getFirst ();
}
......
......@@ -44,8 +44,7 @@ public class NewObjMarker extends AbstractDWRMarker {
MethodInsnNode min = (MethodInsnNode) instruction;
if (min.name.equals(Constants.CONSTRUCTOR_NAME)) {
if (Constants.isConstructorName (min.name)) {
regions.add(new MarkedRegion(instruction, instruction));
}
}
......
......@@ -213,6 +213,22 @@ public class MethodStaticContext extends AbstractStaticContext {
}
/**
* Returns {@code true} if this method is a constructor.
*/
public boolean isMethodConstructor () {
return Constants.isConstructorName (__methodName ());
}
/**
* Returns {@code true} if this method is a class initializer.
*/
public boolean isMethodInitializer () {
return Constants.isInitializerName (__methodName ());
}
/**
* Returns {@code true} if the instrumented method is a bridge.
*/
......
package ch.usi.dag.disl.util;
public class Constants {
public final class Constants {
final public static String STATIC_CONTEXT_METHOD_DELIM = ".";
......@@ -13,4 +13,13 @@ public class Constants {
final public static String CLASS_DELIM = ".";
final public static String CLASS_EXT = ".class";
public static final boolean isConstructorName (final String name) {
return CONSTRUCTOR_NAME.equals (name);
}
public static final boolean isInitializerName (final String name) {
return STATIC_INIT_NAME.equals (name);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment