Java源码示例:org.objectweb.asm.signature.SignatureWriter
示例1
private String translateSignature(final String signature, boolean type) {
if (signature == null) {
return null;
}
SignatureReader r = new SignatureReader(signature);
SignatureWriter w = new SignatureWriter() {
public void visitClassType(final String name) {
String n = translator.getClassMirrorTranslation(name);
super.visitClassType(n);
}
};
if (type) {
r.acceptType(w);
} else {
r.accept(w);
}
return w.toString();
}
示例2
/**
* Returns the given signature, remapped with the {@link SignatureVisitor} returned by {@link
* #createSignatureRemapper(SignatureVisitor)}.
*
* @param signature a <i>JavaTypeSignature</i>, <i>ClassSignature</i> or <i>MethodSignature</i>.
* @param typeSignature whether the given signature is a <i>JavaTypeSignature</i>.
* @return signature the given signature, remapped with the {@link SignatureVisitor} returned by
* {@link #createSignatureRemapper(SignatureVisitor)}.
*/
public String mapSignature(final String signature, final boolean typeSignature) {
if (signature == null) {
return null;
}
SignatureReader signatureReader = new SignatureReader(signature);
SignatureWriter signatureWriter = new SignatureWriter();
SignatureVisitor signatureRemapper = createSignatureRemapper(signatureWriter);
if (typeSignature) {
signatureReader.acceptType(signatureRemapper);
} else {
signatureReader.accept(signatureRemapper);
}
return signatureWriter.toString();
}
示例3
/**
* Returns the given signature, remapped with the {@link SignatureVisitor} returned by {@link
* #createSignatureRemapper(SignatureVisitor)}.
*
* @param signature a <i>JavaTypeSignature</i>, <i>ClassSignature</i> or <i>MethodSignature</i>.
* @param typeSignature whether the given signature is a <i>JavaTypeSignature</i>.
* @return signature the given signature, remapped with the {@link SignatureVisitor} returned by
* {@link #createSignatureRemapper(SignatureVisitor)}.
*/
public String mapSignature(final String signature, final boolean typeSignature) {
if (signature == null) {
return null;
}
SignatureReader signatureReader = new SignatureReader(signature);
SignatureWriter signatureWriter = new SignatureWriter();
SignatureVisitor signatureRemapper = createSignatureRemapper(signatureWriter);
if (typeSignature) {
signatureReader.acceptType(signatureRemapper);
} else {
signatureReader.accept(signatureRemapper);
}
return signatureWriter.toString();
}
示例4
/**
* Returns the given signature, remapped with the {@link SignatureVisitor} returned by {@link
* #createSignatureRemapper(SignatureVisitor)}.
*
* @param signature a <i>JavaTypeSignature</i>, <i>ClassSignature</i> or <i>MethodSignature</i>.
* @param typeSignature whether the given signature is a <i>JavaTypeSignature</i>.
* @return signature the given signature, remapped with the {@link SignatureVisitor} returned by
* {@link #createSignatureRemapper(SignatureVisitor)}.
*/
public String mapSignature(final String signature, final boolean typeSignature) {
if (signature == null) {
return null;
}
SignatureReader signatureReader = new SignatureReader(signature);
SignatureWriter signatureWriter = new SignatureWriter();
SignatureVisitor signatureRemapper = createSignatureRemapper(signatureWriter);
if (typeSignature) {
signatureReader.acceptType(signatureRemapper);
} else {
signatureReader.accept(signatureRemapper);
}
return signatureWriter.toString();
}
示例5
/**
* Returns the given signature, remapped with the {@link SignatureVisitor} returned by {@link
* #createSignatureRemapper(SignatureVisitor)}.
*
* @param signature a <i>JavaTypeSignature</i>, <i>ClassSignature</i> or <i>MethodSignature</i>.
* @param typeSignature whether the given signature is a <i>JavaTypeSignature</i>.
* @return signature the given signature, remapped with the {@link SignatureVisitor} returned by
* {@link #createSignatureRemapper(SignatureVisitor)}.
*/
public String mapSignature(final String signature, final boolean typeSignature) {
if (signature == null) {
return null;
}
SignatureReader signatureReader = new SignatureReader(signature);
SignatureWriter signatureWriter = new SignatureWriter();
SignatureVisitor signatureRemapper = createSignatureRemapper(signatureWriter);
if (typeSignature) {
signatureReader.acceptType(signatureRemapper);
} else {
signatureReader.accept(signatureRemapper);
}
return signatureWriter.toString();
}
示例6
/**
* @param typeSignature true if signature is a FieldTypeSignature, such as the
* signature parameter of the ClassVisitor.visitField or
* MethodVisitor.visitLocalVariable methods
*/
public String mapSignature(String signature, boolean typeSignature) {
if (signature == null) {
return null;
}
SignatureReader r = new SignatureReader(signature);
SignatureWriter w = new SignatureWriter();
SignatureVisitor a = createRemappingSignatureAdapter(w);
if (typeSignature) {
r.acceptType(a);
} else {
r.accept(a);
}
return w.toString();
}
示例7
/**
* {@inheritDoc}
*/
public String getGenericSignature() {
TypeDescription.Generic fieldType = getType();
try {
return fieldType.getSort().isNonGeneric()
? NON_GENERIC_SIGNATURE
: fieldType.accept(new TypeDescription.Generic.Visitor.ForSignatureVisitor(new SignatureWriter())).toString();
} catch (GenericSignatureFormatError ignored) {
return NON_GENERIC_SIGNATURE;
}
}
示例8
/**
* {@inheritDoc}
*/
public String getGenericSignature() {
try {
SignatureWriter signatureWriter = new SignatureWriter();
boolean generic = false;
for (TypeDescription.Generic typeVariable : getTypeVariables()) {
signatureWriter.visitFormalTypeParameter(typeVariable.getSymbol());
boolean classBound = true;
for (TypeDescription.Generic upperBound : typeVariable.getUpperBounds()) {
upperBound.accept(new TypeDescription.Generic.Visitor.ForSignatureVisitor(classBound
? signatureWriter.visitClassBound()
: signatureWriter.visitInterfaceBound()));
classBound = false;
}
generic = true;
}
for (TypeDescription.Generic parameterType : getParameters().asTypeList()) {
parameterType.accept(new TypeDescription.Generic.Visitor.ForSignatureVisitor(signatureWriter.visitParameterType()));
generic = generic || !parameterType.getSort().isNonGeneric();
}
TypeDescription.Generic returnType = getReturnType();
returnType.accept(new TypeDescription.Generic.Visitor.ForSignatureVisitor(signatureWriter.visitReturnType()));
generic = generic || !returnType.getSort().isNonGeneric();
TypeList.Generic exceptionTypes = getExceptionTypes();
if (!exceptionTypes.filter(not(ofSort(TypeDefinition.Sort.NON_GENERIC))).isEmpty()) {
for (TypeDescription.Generic exceptionType : exceptionTypes) {
exceptionType.accept(new TypeDescription.Generic.Visitor.ForSignatureVisitor(signatureWriter.visitExceptionType()));
generic = generic || !exceptionType.getSort().isNonGeneric();
}
}
return generic
? signatureWriter.toString()
: NON_GENERIC_SIGNATURE;
} catch (GenericSignatureFormatError ignored) {
return NON_GENERIC_SIGNATURE;
}
}
示例9
/**
* {@inheritDoc}
*/
public String getGenericSignature() {
TypeDescription.Generic recordComponentType = getType();
try {
return recordComponentType.getSort().isNonGeneric()
? NON_GENERIC_SIGNATURE
: recordComponentType.accept(new TypeDescription.Generic.Visitor.ForSignatureVisitor(new SignatureWriter())).toString();
} catch (GenericSignatureFormatError ignored) {
return NON_GENERIC_SIGNATURE;
}
}
示例10
private String fixupSignature(@PropagatesNullable String signature) {
if (signature == null || compatibilityMode.usesDependencies()) {
return signature;
}
SignatureReader reader = new SignatureReader(signature);
SignatureWriter writer = new SignatureWriter();
reader.accept(new SourceAbiCompatibleSignatureVisitor(writer));
return writer.toString();
}
示例11
/**
* Returns the type signature of the given element. If none is required by the VM spec, returns
* null.
*/
@Nullable
public String getSignature(Element element) {
SignatureWriter writer = new SignatureWriter();
element.accept(elementVisitorAdapter, writer);
String result = writer.toString();
return result.isEmpty() ? null : result;
}
示例12
@Nullable
public String getSignature(TypeMirror type) {
SignatureWriter writer = new SignatureWriter();
type.accept(typeVisitorAdapter, writer);
String result = writer.toString();
return result.isEmpty() ? null : result;
}
示例13
/**
* We can't tell whether an inferred class is a class, interface, annotation, or enum. This is
* problematic for expressing generic type bounds, because the bytecode is different depending on
* whether it is a class or an interface. As it happens, it's safe (from the compiler's
* perspective) to treat everything as an interface. This method is used to rework the "expected"
* signature so that we can use the same test data for testing with and without deps.
*/
private String treatDependencyBoundsAsInterfaces(String signature) {
if (signature == null) {
return null;
}
if (isTestingWithDependencies() || !signature.contains(":Lcom/facebook/foo/Dep")) {
return signature;
}
SignatureWriter writer = new SignatureWriter();
new SignatureReader(signature).accept(new SourceAbiCompatibleSignatureVisitor(writer));
return writer.toString();
}