Commit 6d2068cf authored by pcregut's avatar pcregut

Patch for issue 316339.

Variation on code by Panxiaobo.
- adds supportCodeItem
to Method.
- use it instead of isInterfaceOrAbstract.
- adds a test case (helloJni.dex) with a
native declaration (sample from the NDK).
parent 4c241242
......@@ -604,7 +604,7 @@ public class ApplicationWriter extends ApplicationVisitor {
*/
private void writeMethodsOfCodeItem(List<Method> methods) {
for (Method method : methods) {
if (!method.isAbstractOrInterface()) {
if (method.supportsCodeItem()) {
out.addPadding();
if (codeItemOffset == 0) {
codeItemOffset = out.getLength();
......@@ -794,7 +794,7 @@ public class ApplicationWriter extends ApplicationVisitor {
for (Method method : constantPool.getMethods()) {
// If the Method is "Unknown" (referred to but not encoded), or is Abstract or Interface
// don't write its Debug Information.
if (!method.isUnknown() && !method.isAbstractOrInterface()) {
if (!method.isUnknown() && method.supportsCodeItem()) {
CodeItem codeItem = method.getCodeItem();
// "Constant Pool" optimization enabled ?
......
......@@ -157,7 +157,7 @@ public class Method implements Comparable<Method>, IAnnotationsHolder {
this.access = access;
this.exceptionNames = exceptionNames;
this.signature = signature;
if (!isUnknown() && (!isAbstractOrInterface())) {
if (!isUnknown() && supportsCodeItem()) {
codeItem = new CodeItem(this, constantPool);
}
......@@ -187,7 +187,7 @@ public class Method implements Comparable<Method>, IAnnotationsHolder {
this.exceptionNames = exceptionNames;
this.signature = signature;
if ((codeItem == null) && (!isUnknown() && (!isAbstractOrInterface()))) { // It SHOULD be Null in all cases.
if ((codeItem == null) && !isUnknown() && supportsCodeItem()) { // It SHOULD be Null in all cases.
codeItem = new CodeItem(this, constantPool);
}
}
......@@ -247,6 +247,14 @@ public class Method implements Comparable<Method>, IAnnotationsHolder {
return ((access & Opcodes.ACC_ABSTRACT) | (access & Opcodes.ACC_INTERFACE)) != 0;
}
/**
* Indicates whether the Method is native.
* @return true if the Method is static.
*/
public boolean isNative() {
return (access & Opcodes.ACC_NATIVE) != 0;
}
/**
* Indicates whether the Method is unknown (referred to, but not yet parsed).
* @return true if the Method is unknown.
......@@ -254,7 +262,15 @@ public class Method implements Comparable<Method>, IAnnotationsHolder {
public boolean isUnknown() {
return (access & Opcodes.ACC_UNKNOWN) != 0;
}
/**
* Indicates whether a method contains java code (a CodeItem).
* @return true if the Method has code.
*/
public boolean supportsCodeItem() {
return (access & (Opcodes.ACC_ABSTRACT | Opcodes.ACC_INTERFACE | Opcodes.ACC_NATIVE)) == 0;
}
/**
* Indicates whether the Method uses the "this" parameter.
* @return true if the Method uses the "this" parameter.
......
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