You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
103 lines
2.1 KiB
103 lines
2.1 KiB
10 years ago
|
/*
|
||
|
* Fernflower - The Analytical Java Decompiler
|
||
|
* http://www.reversed-java.com
|
||
|
*
|
||
|
* (C) 2008 - 2010, Stiver
|
||
|
*
|
||
|
* This software is NEITHER public domain NOR free software
|
||
|
* as per GNU License. See license.txt for more details.
|
||
|
*
|
||
|
* This software is distributed WITHOUT ANY WARRANTY; without
|
||
|
* even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
||
|
* A PARTICULAR PURPOSE.
|
||
|
*/
|
||
|
|
||
10 years ago
|
package org.jetbrains.java.decompiler.struct.gen;
|
||
10 years ago
|
|
||
|
import java.util.ArrayList;
|
||
10 years ago
|
import java.util.Arrays;
|
||
10 years ago
|
import java.util.List;
|
||
|
|
||
|
public class MethodDescriptor {
|
||
|
|
||
|
public VarType[] params;
|
||
|
|
||
|
public VarType ret;
|
||
|
|
||
|
|
||
|
public static MethodDescriptor parseDescriptor(String mdescr) {
|
||
|
|
||
|
MethodDescriptor md = new MethodDescriptor();
|
||
|
|
||
|
List<String> lst = new ArrayList<String>();
|
||
|
String[] pars = mdescr.split("[()]");
|
||
|
|
||
|
String par = pars[1];
|
||
|
|
||
|
int indexFrom = -1, ind,index = 0;
|
||
|
int len = par.length();
|
||
|
|
||
|
for(;index<len;index++) {
|
||
|
|
||
|
switch(par.charAt(index)){
|
||
|
case '[':
|
||
|
if(indexFrom<0){
|
||
|
indexFrom = index;
|
||
|
}
|
||
|
break;
|
||
|
case 'L':
|
||
|
ind = par.indexOf(";", index);
|
||
|
lst.add(par.substring(indexFrom<0?index:indexFrom, ind+1));
|
||
|
index = ind;
|
||
|
indexFrom = -1;
|
||
|
break;
|
||
|
default:
|
||
|
lst.add(par.substring(indexFrom<0?index:indexFrom, index+1));
|
||
|
indexFrom = -1;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
lst.add(pars[2]);
|
||
|
|
||
|
|
||
|
md.params = new VarType[lst.size()-1];
|
||
|
|
||
|
int i = 0;
|
||
|
for(;i<lst.size()-1;i++) {
|
||
|
md.params[i] = new VarType(lst.get(i));
|
||
|
}
|
||
|
md.ret = new VarType(lst.get(i));
|
||
|
|
||
|
return md;
|
||
|
}
|
||
|
|
||
|
public String getDescriptor() {
|
||
|
String res = "(";
|
||
|
|
||
|
for(int j = 0;j<params.length;j++) {
|
||
|
res+=params[j].toString();
|
||
|
}
|
||
|
|
||
|
res+=")"+ret.toString();
|
||
|
|
||
|
return res;
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public boolean equals(Object o) {
|
||
10 years ago
|
if(o == this) return true;
|
||
|
if(o == null || !(o instanceof MethodDescriptor)) return false;
|
||
10 years ago
|
|
||
10 years ago
|
MethodDescriptor md = (MethodDescriptor)o;
|
||
|
return ret.equals(md.ret) && Arrays.equals(params, md.params);
|
||
|
}
|
||
10 years ago
|
|
||
|
@Override
|
||
|
public int hashCode() {
|
||
10 years ago
|
int result = ret.hashCode();
|
||
|
result = 31 * result + params.length;
|
||
|
return result;
|
||
10 years ago
|
}
|
||
10 years ago
|
|
||
10 years ago
|
}
|