|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
package jdk.internal.org.objectweb.asm.util; |
|
|
|
import jdk.internal.org.objectweb.asm.Opcodes; |
|
import jdk.internal.org.objectweb.asm.signature.SignatureVisitor; |
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public class CheckSignatureAdapter extends SignatureVisitor { |
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public static final int CLASS_SIGNATURE = 0; |
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public static final int METHOD_SIGNATURE = 1; |
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public static final int TYPE_SIGNATURE = 2; |
|
|
|
private static final int EMPTY = 1; |
|
|
|
private static final int FORMAL = 2; |
|
|
|
private static final int BOUND = 4; |
|
|
|
private static final int SUPER = 8; |
|
|
|
private static final int PARAM = 16; |
|
|
|
private static final int RETURN = 32; |
|
|
|
private static final int SIMPLE_TYPE = 64; |
|
|
|
private static final int CLASS_TYPE = 128; |
|
|
|
private static final int END = 256; |
|
|
|
|
|
|
|
*/ |
|
private final int type; |
|
|
|
|
|
|
|
*/ |
|
private int state; |
|
|
|
|
|
|
|
*/ |
|
private boolean canBeVoid; |
|
|
|
|
|
|
|
|
|
*/ |
|
private final SignatureVisitor sv; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public CheckSignatureAdapter(final int type, final SignatureVisitor sv) { |
|
this(Opcodes.ASM6, type, sv); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
protected CheckSignatureAdapter(final int api, final int type, |
|
final SignatureVisitor sv) { |
|
super(api); |
|
this.type = type; |
|
this.state = EMPTY; |
|
this.sv = sv; |
|
} |
|
|
|
// class and method signatures |
|
|
|
@Override |
|
public void visitFormalTypeParameter(final String name) { |
|
if (type == TYPE_SIGNATURE |
|
|| (state != EMPTY && state != FORMAL && state != BOUND)) { |
|
throw new IllegalStateException(); |
|
} |
|
checkIdentifier(name, "formal type parameter"); |
|
state = FORMAL; |
|
if (sv != null) { |
|
sv.visitFormalTypeParameter(name); |
|
} |
|
} |
|
|
|
@Override |
|
public SignatureVisitor visitClassBound() { |
|
if (state != FORMAL) { |
|
throw new IllegalStateException(); |
|
} |
|
state = BOUND; |
|
SignatureVisitor v = sv == null ? null : sv.visitClassBound(); |
|
return new CheckSignatureAdapter(TYPE_SIGNATURE, v); |
|
} |
|
|
|
@Override |
|
public SignatureVisitor visitInterfaceBound() { |
|
if (state != FORMAL && state != BOUND) { |
|
throw new IllegalArgumentException(); |
|
} |
|
SignatureVisitor v = sv == null ? null : sv.visitInterfaceBound(); |
|
return new CheckSignatureAdapter(TYPE_SIGNATURE, v); |
|
} |
|
|
|
// class signatures |
|
|
|
@Override |
|
public SignatureVisitor visitSuperclass() { |
|
if (type != CLASS_SIGNATURE || (state & (EMPTY | FORMAL | BOUND)) == 0) { |
|
throw new IllegalArgumentException(); |
|
} |
|
state = SUPER; |
|
SignatureVisitor v = sv == null ? null : sv.visitSuperclass(); |
|
return new CheckSignatureAdapter(TYPE_SIGNATURE, v); |
|
} |
|
|
|
@Override |
|
public SignatureVisitor visitInterface() { |
|
if (state != SUPER) { |
|
throw new IllegalStateException(); |
|
} |
|
SignatureVisitor v = sv == null ? null : sv.visitInterface(); |
|
return new CheckSignatureAdapter(TYPE_SIGNATURE, v); |
|
} |
|
|
|
// method signatures |
|
|
|
@Override |
|
public SignatureVisitor visitParameterType() { |
|
if (type != METHOD_SIGNATURE |
|
|| (state & (EMPTY | FORMAL | BOUND | PARAM)) == 0) { |
|
throw new IllegalArgumentException(); |
|
} |
|
state = PARAM; |
|
SignatureVisitor v = sv == null ? null : sv.visitParameterType(); |
|
return new CheckSignatureAdapter(TYPE_SIGNATURE, v); |
|
} |
|
|
|
@Override |
|
public SignatureVisitor visitReturnType() { |
|
if (type != METHOD_SIGNATURE |
|
|| (state & (EMPTY | FORMAL | BOUND | PARAM)) == 0) { |
|
throw new IllegalArgumentException(); |
|
} |
|
state = RETURN; |
|
SignatureVisitor v = sv == null ? null : sv.visitReturnType(); |
|
CheckSignatureAdapter cv = new CheckSignatureAdapter(TYPE_SIGNATURE, v); |
|
cv.canBeVoid = true; |
|
return cv; |
|
} |
|
|
|
@Override |
|
public SignatureVisitor visitExceptionType() { |
|
if (state != RETURN) { |
|
throw new IllegalStateException(); |
|
} |
|
SignatureVisitor v = sv == null ? null : sv.visitExceptionType(); |
|
return new CheckSignatureAdapter(TYPE_SIGNATURE, v); |
|
} |
|
|
|
// type signatures |
|
|
|
@Override |
|
public void visitBaseType(final char descriptor) { |
|
if (type != TYPE_SIGNATURE || state != EMPTY) { |
|
throw new IllegalStateException(); |
|
} |
|
if (descriptor == 'V') { |
|
if (!canBeVoid) { |
|
throw new IllegalArgumentException(); |
|
} |
|
} else { |
|
if ("ZCBSIFJD".indexOf(descriptor) == -1) { |
|
throw new IllegalArgumentException(); |
|
} |
|
} |
|
state = SIMPLE_TYPE; |
|
if (sv != null) { |
|
sv.visitBaseType(descriptor); |
|
} |
|
} |
|
|
|
@Override |
|
public void visitTypeVariable(final String name) { |
|
if (type != TYPE_SIGNATURE || state != EMPTY) { |
|
throw new IllegalStateException(); |
|
} |
|
checkIdentifier(name, "type variable"); |
|
state = SIMPLE_TYPE; |
|
if (sv != null) { |
|
sv.visitTypeVariable(name); |
|
} |
|
} |
|
|
|
@Override |
|
public SignatureVisitor visitArrayType() { |
|
if (type != TYPE_SIGNATURE || state != EMPTY) { |
|
throw new IllegalStateException(); |
|
} |
|
state = SIMPLE_TYPE; |
|
SignatureVisitor v = sv == null ? null : sv.visitArrayType(); |
|
return new CheckSignatureAdapter(TYPE_SIGNATURE, v); |
|
} |
|
|
|
@Override |
|
public void visitClassType(final String name) { |
|
if (type != TYPE_SIGNATURE || state != EMPTY) { |
|
throw new IllegalStateException(); |
|
} |
|
checkClassName(name, "class name"); |
|
state = CLASS_TYPE; |
|
if (sv != null) { |
|
sv.visitClassType(name); |
|
} |
|
} |
|
|
|
@Override |
|
public void visitInnerClassType(final String name) { |
|
if (state != CLASS_TYPE) { |
|
throw new IllegalStateException(); |
|
} |
|
checkIdentifier(name, "inner class name"); |
|
if (sv != null) { |
|
sv.visitInnerClassType(name); |
|
} |
|
} |
|
|
|
@Override |
|
public void visitTypeArgument() { |
|
if (state != CLASS_TYPE) { |
|
throw new IllegalStateException(); |
|
} |
|
if (sv != null) { |
|
sv.visitTypeArgument(); |
|
} |
|
} |
|
|
|
@Override |
|
public SignatureVisitor visitTypeArgument(final char wildcard) { |
|
if (state != CLASS_TYPE) { |
|
throw new IllegalStateException(); |
|
} |
|
if ("+-=".indexOf(wildcard) == -1) { |
|
throw new IllegalArgumentException(); |
|
} |
|
SignatureVisitor v = sv == null ? null : sv.visitTypeArgument(wildcard); |
|
return new CheckSignatureAdapter(TYPE_SIGNATURE, v); |
|
} |
|
|
|
@Override |
|
public void visitEnd() { |
|
if (state != CLASS_TYPE) { |
|
throw new IllegalStateException(); |
|
} |
|
state = END; |
|
if (sv != null) { |
|
sv.visitEnd(); |
|
} |
|
} |
|
|
|
private void checkClassName(final String name, final String msg) { |
|
if (name == null || name.length() == 0) { |
|
throw new IllegalArgumentException("Invalid " + msg |
|
+ " (must not be null or empty)"); |
|
} |
|
for (int i = 0; i < name.length(); ++i) { |
|
if (".;[<>:".indexOf(name.charAt(i)) != -1) { |
|
throw new IllegalArgumentException("Invalid " + msg |
|
+ " (must not contain . ; [ < > or :): " + name); |
|
} |
|
} |
|
} |
|
|
|
private void checkIdentifier(final String name, final String msg) { |
|
if (name == null || name.length() == 0) { |
|
throw new IllegalArgumentException("Invalid " + msg |
|
+ " (must not be null or empty)"); |
|
} |
|
for (int i = 0; i < name.length(); ++i) { |
|
if (".;[/<>:".indexOf(name.charAt(i)) != -1) { |
|
throw new IllegalArgumentException("Invalid " + msg |
|
+ " (must not contain . ; [ / < > or :): " + name); |
|
} |
|
} |
|
} |
|
} |