git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@615 30ef5769-5b8d-40dd-aea6-55b5d6557bb3tags/rel_3_17_1_ga
@@ -283,7 +283,7 @@ see javassist.Dump. | |||
<p>-version 3.16 | |||
<ul> | |||
<li>JIRA JASSIST-126, 127, 144, 145, 146, 147, 149, 150, 153, 155. | |||
<li>JIRA JASSIST-126, 127, 144, 145, 146, 147, 149, 150, 152, 153, 155. | |||
<li><code>javassist.bytecode.analysis.ControlFlow</code> was added. | |||
</ul> | |||
@@ -284,7 +284,7 @@ public abstract class TypeData { | |||
} | |||
} | |||
/* See also NullType.getExpected(). | |||
/* See also {NullType,ArrayElement}.getExpected(). | |||
*/ | |||
public String getExpected() throws BadBytecode { | |||
ArrayList equiv = equivalences; | |||
@@ -410,19 +410,38 @@ public abstract class TypeData { | |||
} | |||
public String getName() throws BadBytecode { | |||
String name = array.getName(); | |||
return getName2(array.getName()); | |||
} | |||
private String getName2(String name) throws BadBytecode { | |||
if (name.length() > 1 && name.charAt(0) == '[') { | |||
char c = name.charAt(1); | |||
if (c == 'L') | |||
return name.substring(2, name.length() - 1).replace('/', '.'); | |||
return name.substring(2, name.length() - 1).replace('/', '.'); | |||
else if (c == '[') | |||
return name.substring(1); | |||
} | |||
throw new BadBytecode("bad array type for AALOAD: " | |||
if (array.isNullType()) | |||
return "java.lang.Object"; | |||
else | |||
throw new BadBytecode("bad array type for AALOAD: " | |||
+ name); | |||
} | |||
public String getExpected() throws BadBytecode { | |||
ArrayList equiv = equivalences; | |||
if (equiv.size() == 1) | |||
return getName2(array.getExpected()); // not getName(); | |||
else { | |||
String en = expectedName; | |||
if (en == null) | |||
return "java.lang.Object"; | |||
else | |||
return en; | |||
} | |||
} | |||
public static String getArrayType(String elementType) { | |||
if (elementType.charAt(0) == '[') | |||
return "[" + elementType; |
@@ -3,6 +3,8 @@ import javassist.ClassPool; | |||
import javassist.CtClass; | |||
import javassist.CtMethod; | |||
import javassist.NotFoundException; | |||
import javassist.expr.ExprEditor; | |||
import javassist.expr.MethodCall; | |||
public class Jassist150 { | |||
public static final String BASE_PATH = "./"; | |||
@@ -77,7 +79,23 @@ public class Jassist150 { | |||
ccGet.setBody(code3); | |||
} | |||
public static void main(String[] args) { | |||
public void testJIRA152() throws Exception { | |||
CtClass cc = ClassPool.getDefault().get("test4.JIRA152"); | |||
CtMethod mth = cc.getDeclaredMethod("buildColumnOverride"); | |||
mth.instrument(new ExprEditor() { | |||
public void edit(MethodCall c) throws CannotCompileException { | |||
c.replace("try{ $_ = $proceed($$); } catch (Throwable t) { throw t; }"); | |||
} | |||
}); | |||
mth.getMethodInfo().rebuildStackMap(ClassPool.getDefault()); | |||
cc.writeFile(); | |||
} | |||
public static void main(String[] args) throws Exception { | |||
new Jassist150().testJIRA152(); | |||
} | |||
public static void main2(String[] args) { | |||
for (int loop = 0; loop < 5; loop++) { | |||
try { | |||
implTestClassTailCache(); |
@@ -85,7 +85,7 @@ public class JvstTest4 extends JvstTestRoot { | |||
} | |||
} | |||
}); | |||
// m3.getMethodInfo2().rebuildStackMapIf6(cc.getClassPool(), cc.getClassFile2()); | |||
m3.getMethodInfo().rebuildStackMapIf6(cc.getClassPool(), cc.getClassFile()); | |||
cc.writeFile(); | |||
Object obj = make(cc.getName()); | |||
@@ -687,4 +687,18 @@ public class JvstTest4 extends JvstTestRoot { | |||
System.out.println("JIRA150b " + size); | |||
assertTrue(size < N - 10); | |||
} | |||
public void testJIRA152() throws Exception { | |||
CtClass cc = sloader.get("test4.JIRA152"); | |||
CtMethod mth = cc.getDeclaredMethod("buildColumnOverride"); | |||
//CtMethod mth = cc.getDeclaredMethod("tested"); | |||
mth.instrument(new ExprEditor() { | |||
public void edit(MethodCall c) throws CannotCompileException { | |||
c.replace("try{ $_ = $proceed($$); } catch (Throwable t) { throw t; }"); | |||
} | |||
}); | |||
cc.writeFile(); | |||
Object obj = make(cc.getName()); | |||
assertEquals(1, invoke(obj, "test")); | |||
} | |||
} |
@@ -0,0 +1,60 @@ | |||
package test4; | |||
import java.util.Map; | |||
import java.util.HashMap; | |||
public class JIRA152 { | |||
public int foo(int i) { return i; } | |||
public int bar(int j) { return j; } | |||
public int tested(int k) { | |||
String[] p; | |||
if (k > 0) | |||
p = new String[1]; | |||
else | |||
p = null; | |||
if (p != null) | |||
while (k < p.length) | |||
k++; | |||
return 0; | |||
} | |||
public String put(String s, Object obj) { | |||
return s; | |||
} | |||
private static Map<String, String[]> buildColumnOverride(JIRA152 element, String path) { | |||
Map<String, String[]> columnOverride = new HashMap<String, String[]>(); | |||
if ( element == null ) return null; | |||
String singleOverride = element.toString(); | |||
String multipleOverrides = element.toString(); | |||
String[] overrides; | |||
if ( singleOverride != null ) { | |||
overrides = new String[] { singleOverride }; | |||
} | |||
/*else if ( multipleOverrides != null ) { | |||
// overrides = columnOverride.get("foo"); | |||
overrides = null; | |||
}*/ | |||
else { | |||
overrides = null; | |||
} | |||
if ( overrides != null ) { | |||
for (String depAttr : overrides) { | |||
columnOverride.put( | |||
element.put(path, depAttr.getClass()), | |||
new String[] { depAttr.toLowerCase() } | |||
); | |||
//columnOverride.put("a", new String[1]); | |||
} | |||
} | |||
return columnOverride; | |||
} | |||
public int test() { | |||
Map<String,String[]> map = buildColumnOverride(this, "foo"); | |||
return map.size(); | |||
} | |||
} |