com.yworks.yshrink.model.MethodDescriptor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of yguard Show documentation
Show all versions of yguard Show documentation
The open-source Java obfuscation tool working with Ant and Gradle by yWorks - the diagramming experts
The newest version!
package com.yworks.yshrink.model;
import com.yworks.yshrink.util.Util;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;
import java.io.File;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import java.util.AbstractMap;
/**
* The type Method descriptor.
*
* @author Michael Schroeder, yWorks GmbH http://www.yworks.com
*/
public class MethodDescriptor extends AbstractDescriptor {
private String name;
private String desc;
private List invocations; // call: [type,methodName,methodDesc]
private List fieldRefs; // fieldRef: [owner,name]
private List> typeInstructions;
private String[] exceptions;
private List localVars;
/**
* Instantiates a new Method descriptor.
*
* @param name the name
* @param access the access
* @param desc the desc
* @param exceptions the exceptions
* @param sourceJar the source jar
*/
protected MethodDescriptor( final String name, final int access, final String desc, final String[] exceptions, File sourceJar ) {
super( access, sourceJar );
this.name = name;
this.desc = desc;
invocations = new ArrayList<>();
fieldRefs = new ArrayList<>();
typeInstructions = new ArrayList<>();
localVars = new ArrayList<>();
this.exceptions = exceptions;
}
/**
* Gets name.
*
* @return the name
*/
public String getName() {
return name;
}
/**
* Gets desc.
*
* @return the desc
*/
public String getDesc() {
return desc;
}
/**
* Get argument types type [ ].
*
* @return the type [ ]
*/
public Type[] getArgumentTypes() {
return Type.getArgumentTypes( desc );
}
/**
* Gets arguments string.
*
* @return the arguments string
*/
public String getArgumentsString() {
StringBuilder buf = new StringBuilder();
Type[] argumentTypes = getArgumentTypes();
for ( Type type : argumentTypes ) {
buf.append( type.getDescriptor() );
}
return buf.toString();
}
/**
* Gets return type.
*
* @return the return type
*/
public Type getReturnType() {
return Type.getReturnType( desc );
}
/**
* Gets invocations.
*
* @return the invocations
*/
public List getInvocations() {
return invocations;
}
/**
* Add invocation.
*
* @param opcode the opcode
* @param type the type
* @param name the name
* @param desc the desc
*/
public void addInvocation( final int opcode, final String type, final String name, final String desc ) {
invocations.add( InvocationFactory.getInstance().getInvocation( opcode, type, name, desc ) );
//invocations.add( new Invocation( opcode, type, name, desc ) );
}
/**
* Gets field refs.
*
* @return the field refs
*/
public List getFieldRefs() {
return fieldRefs;
}
/**
* Add field ref.
*
* @param type the type
* @param name the name
*/
public void addFieldRef( final String type, final String name ) {
fieldRefs.add( new String[]{ type, name } );
}
/**
* Add type instruction.
*
* @param opcode the opcode
* @param desc the desc
*/
public void addTypeInstruction( final int opcode, final String desc ) {
typeInstructions.add( new AbstractMap.SimpleEntry