Java Code Examples for org.objectweb.asm.signature.SignatureVisitor#visitClassType()

The following examples show how to use org.objectweb.asm.signature.SignatureVisitor#visitClassType() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SignatureFactory.java    From buck with Apache License 2.0 6 votes vote down vote up
@Override
public Void visitType(TypeElement element, SignatureVisitor visitor) {
  if (!signatureRequired(element)) {
    return null;
  }

  for (TypeParameterElement typeParameterElement : element.getTypeParameters()) {
    typeParameterElement.accept(this, visitor);
  }

  TypeMirror superclass = element.getSuperclass();
  if (superclass.getKind() != TypeKind.NONE) {
    superclass.accept(typeVisitorAdapter, visitor.visitSuperclass());
  } else {
    // Interface type; implicit superclass of Object
    SignatureVisitor superclassVisitor = visitor.visitSuperclass();
    superclassVisitor.visitClassType("java/lang/Object");
    superclassVisitor.visitEnd();
  }

  for (TypeMirror interfaceType : element.getInterfaces()) {
    interfaceType.accept(typeVisitorAdapter, visitor.visitInterface());
  }

  return null;
}
 
Example 2
Source File: SignatureFactory.java    From buck with Apache License 2.0 5 votes vote down vote up
@Override
public Void visitError(ErrorType t, SignatureVisitor visitor) {
  // We don't really know, but if there's an error type the compilation is going to fail
  // anyway, so just pretend it's Object.
  visitor.visitClassType("java/lang/Object");
  visitor.visitEnd();
  return null;
}
 
Example 3
Source File: SignatureFactory.java    From buck with Apache License 2.0 4 votes vote down vote up
@Override
public Void visitDeclared(DeclaredType t, SignatureVisitor visitor) {
  List<DeclaredType> enclosingTypes = findEnclosingTypes(t);

  // Signatures are weird with inner classes. They use $ as the separator until you
  // encounter a class with type arguments, then . as the separator thereafter.
  //
  // What this means for visiting a class type with a SignatureVisitor is that we don't
  // start the visiting (by calling visitClassType) at the top-level class; we start at the
  // outermost class with type arguments. Then we visit the type arguments, and then
  // every inner class from there to the type for which we're generating a signature.
  boolean calledVisitClassType = false;
  int numTypes = enclosingTypes.size();
  for (int i = 0; i < numTypes; i++) {
    DeclaredType type = enclosingTypes.get(i);
    List<? extends TypeMirror> typeArguments;
    try {
      typeArguments = type.getTypeArguments();
    } catch (CannotInferException e) {
      // InferredDeclaredTypes can only be obtained by calling asType on an
      // InferredTypeElement. Types that are used in signature generation are not obtained
      // in this manner, so they should always be StandaloneDeclaredTypes and this exception
      // should never happen.
      throw new AssertionError("Unexpected inferred type.", e);
    }
    if (calledVisitClassType) {
      visitor.visitInnerClassType(type.asElement().getSimpleName().toString());
    } else if (!typeArguments.isEmpty() || i == numTypes - 1) {
      visitor.visitClassType(descriptorFactory.getInternalName(type));
      calledVisitClassType = true;
    } else {
      // Keep looking for the outermost enclosing generic type
      continue;
    }

    for (TypeMirror typeArgument : typeArguments) {
      typeArgument.accept(this, visitor.visitTypeArgument(SignatureVisitor.INSTANCEOF));
    }
  }
  visitor.visitEnd();

  return null;
}