org.objectweb.asm.signature.SignatureVisitor Java Examples

The following examples show how to use org.objectweb.asm.signature.SignatureVisitor. 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: TraceSignatureVisitor.java    From Concurnas with MIT License 6 votes vote down vote up
@Override
public SignatureVisitor visitTypeArgument(final char tag) {
  if (argumentStack % 2 == 0) {
    ++argumentStack;
    declaration.append('<');
  } else {
    declaration.append(COMMA_SEPARATOR);
  }

  if (tag == EXTENDS) {
    declaration.append("? extends ");
  } else if (tag == SUPER) {
    declaration.append("? super ");
  }

  startType();
  return this;
}
 
Example #2
Source File: TraceSignatureVisitor.java    From JReFrameworker with MIT License 6 votes vote down vote up
@Override
public SignatureVisitor visitTypeArgument(final char tag) {
  if (argumentStack % 2 == 0) {
    ++argumentStack;
    declaration.append('<');
  } else {
    declaration.append(COMMA_SEPARATOR);
  }

  if (tag == EXTENDS) {
    declaration.append("? extends ");
  } else if (tag == SUPER) {
    declaration.append("? super ");
  }

  startType();
  return this;
}
 
Example #3
Source File: SignatureFactory.java    From buck with Apache License 2.0 6 votes vote down vote up
@Override
public Void visitExecutable(ExecutableType t, SignatureVisitor visitor) {
  if (!signatureRequired(t)) {
    return null;
  }

  for (TypeVariable typeVariable : t.getTypeVariables()) {
    typeVariable.asElement().accept(elementVisitorAdapter, visitor);
  }

  for (TypeMirror parameter : t.getParameterTypes()) {
    parameter.accept(this, visitor.visitParameterType());
  }

  t.getReturnType().accept(this, visitor.visitReturnType());

  if (throwsATypeVar(t)) {
    for (TypeMirror thrownType : t.getThrownTypes()) {
      thrownType.accept(typeVisitorAdapter, visitor.visitExceptionType());
    }
  }

  return null;
}
 
Example #4
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 #5
Source File: TraceSignatureVisitor.java    From JByteMod-Beta with GNU General Public License v2.0 5 votes vote down vote up
@Override
public SignatureVisitor visitExceptionType() {
  if (exceptions == null) {
    exceptions = new StringBuilder();
  } else {
    exceptions.append(", ");
  }
  // startType();
  return new TraceSignatureVisitor(exceptions);
}
 
Example #6
Source File: TraceSignatureVisitor.java    From Concurnas with MIT License 5 votes vote down vote up
@Override
public SignatureVisitor visitParameterType() {
  endFormals();
  if (parameterTypeVisited) {
    declaration.append(COMMA_SEPARATOR);
  } else {
    declaration.append('(');
    parameterTypeVisited = true;
  }
  startType();
  return this;
}
 
Example #7
Source File: CheckSignatureAdapter.java    From JByteMod-Beta with GNU General Public License v2.0 5 votes vote down vote up
@Override
public SignatureVisitor visitInterface() {
  if (state != SUPER) {
    throw new IllegalStateException();
  }
  SignatureVisitor v = sv == null ? null : sv.visitInterface();
  return new CheckSignatureAdapter(TYPE_SIGNATURE, v);
}
 
Example #8
Source File: CheckSignatureAdapter.java    From JReFrameworker with MIT License 5 votes vote down vote up
@Override
public SignatureVisitor visitExceptionType() {
  if (type != METHOD_SIGNATURE || !VISIT_EXCEPTION_TYPE_STATES.contains(state)) {
    throw new IllegalStateException();
  }
  return new CheckSignatureAdapter(
      TYPE_SIGNATURE, signatureVisitor == null ? null : signatureVisitor.visitExceptionType());
}
 
Example #9
Source File: CheckSignatureAdapter.java    From JReFrameworker with MIT License 5 votes vote down vote up
@Override
public SignatureVisitor visitInterface() {
  if (type != CLASS_SIGNATURE || !VISIT_INTERFACE_STATES.contains(state)) {
    throw new IllegalStateException();
  }
  return new CheckSignatureAdapter(
      TYPE_SIGNATURE, signatureVisitor == null ? null : signatureVisitor.visitInterface());
}
 
Example #10
Source File: TraceSignatureVisitor.java    From JByteMod-Beta with GNU General Public License v2.0 5 votes vote down vote up
@Override
public SignatureVisitor visitInterface() {
  separator = seenInterface ? ", " : isInterface ? " extends " : " implements ";
  seenInterface = true;
  startType();
  return this;
}
 
Example #11
Source File: TraceSignatureVisitor.java    From Concurnas with MIT License 5 votes vote down vote up
@Override
public SignatureVisitor visitExceptionType() {
  if (exceptions == null) {
    exceptions = new StringBuilder();
  } else {
    exceptions.append(COMMA_SEPARATOR);
  }
  return new TraceSignatureVisitor(exceptions);
}
 
Example #12
Source File: CheckSignatureAdapter.java    From JByteMod-Beta with GNU General Public License v2.0 5 votes vote down vote up
@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);
}
 
Example #13
Source File: SignatureParser.java    From testability-explorer with Apache License 2.0 5 votes vote down vote up
@Override
public SignatureVisitor visitArrayType() {
  return new TypeVisitor(new Setter() {
    public void set(Type type) {
      parameters.add(type.toArray());
    }
  });
}
 
Example #14
Source File: TraceSignatureVisitor.java    From JReFrameworker with MIT License 5 votes vote down vote up
@Override
public SignatureVisitor visitExceptionType() {
  if (exceptions == null) {
    exceptions = new StringBuilder();
  } else {
    exceptions.append(COMMA_SEPARATOR);
  }
  return new TraceSignatureVisitor(exceptions);
}
 
Example #15
Source File: TraceSignatureVisitor.java    From JReFrameworker with MIT License 5 votes vote down vote up
@Override
public SignatureVisitor visitSuperclass() {
  endFormals();
  separator = EXTENDS_SEPARATOR;
  startType();
  return this;
}
 
Example #16
Source File: TraceSignatureVisitor.java    From Concurnas with MIT License 5 votes vote down vote up
@Override
public SignatureVisitor visitInterface() {
  if (interfaceVisited) {
    separator = COMMA_SEPARATOR;
  } else {
    separator = isInterface ? EXTENDS_SEPARATOR : IMPLEMENTS_SEPARATOR;
    interfaceVisited = true;
  }
  startType();
  return this;
}
 
Example #17
Source File: TraceSignatureVisitor.java    From Concurnas with MIT License 5 votes vote down vote up
@Override
public SignatureVisitor visitSuperclass() {
  endFormals();
  separator = EXTENDS_SEPARATOR;
  startType();
  return this;
}
 
Example #18
Source File: CheckSignatureAdapter.java    From JReFrameworker with MIT License 5 votes vote down vote up
@Override
public SignatureVisitor visitSuperclass() {
  if (type != CLASS_SIGNATURE || !VISIT_SUPER_CLASS_STATES.contains(state)) {
    throw new IllegalArgumentException();
  }
  state = State.SUPER;
  return new CheckSignatureAdapter(
      TYPE_SIGNATURE, signatureVisitor == null ? null : signatureVisitor.visitSuperclass());
}
 
Example #19
Source File: JarOptimizer.java    From AVM with MIT License 5 votes vote down vote up
private Set<String> visitClass(String className, Map<String, byte[]> classMap) {

        DependencyCollector dependencyCollector = new DependencyCollector();

        ClassReader reader = new ClassReader(classMap.get(className));

        SignatureVisitor signatureVisitor = new SignatureDependencyVisitor(dependencyCollector);
        ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
        ClassVisitor classVisitor = new ClassDependencyVisitor(signatureVisitor, dependencyCollector, writer, preserveDebugInfo);
        reader.accept(classVisitor, 0);

        classMap.put(className, writer.toByteArray());
        return dependencyCollector.getDependencies();
    }
 
Example #20
Source File: TraceSignatureVisitor.java    From JReFrameworker with MIT License 5 votes vote down vote up
@Override
public SignatureVisitor visitSuperclass() {
  endFormals();
  separator = EXTENDS_SEPARATOR;
  startType();
  return this;
}
 
Example #21
Source File: CheckSignatureAdapter.java    From Concurnas with MIT License 5 votes vote down vote up
@Override
public SignatureVisitor visitTypeArgument(final char wildcard) {
  if (state != State.CLASS_TYPE) {
    throw new IllegalStateException();
  }
  if ("+-=".indexOf(wildcard) == -1) {
    throw new IllegalArgumentException("Wildcard must be one of +-=");
  }
  return new CheckSignatureAdapter(
      TYPE_SIGNATURE,
      signatureVisitor == null ? null : signatureVisitor.visitTypeArgument(wildcard));
}
 
Example #22
Source File: FieldSignatureVisitor.java    From meghanada-server with GNU General Public License v3.0 5 votes vote down vote up
@Override
public SignatureVisitor visitArrayType() {

  final TypeInfo current = this.currentType.peek();
  if (current != null) {
    current.isArray = true;
  } else {
    // on hold array flag
    this.holdArray = true;
  }
  final EntryMessage em =
      log.traceEntry("name={} current={} currentType={}", this.name, current, this.currentType);
  return log.traceExit(em, super.visitArrayType());
}
 
Example #23
Source File: CheckSignatureAdapter.java    From JByteMod-Beta with GNU General Public License v2.0 5 votes vote down vote up
@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);
}
 
Example #24
Source File: CheckSignatureAdapter.java    From JReFrameworker with MIT License 5 votes vote down vote up
@Override
public SignatureVisitor visitClassBound() {
  if (type == TYPE_SIGNATURE || !VISIT_CLASS_BOUND_STATES.contains(state)) {
    throw new IllegalStateException();
  }
  state = State.BOUND;
  return new CheckSignatureAdapter(
      TYPE_SIGNATURE, signatureVisitor == null ? null : signatureVisitor.visitClassBound());
}
 
Example #25
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 #26
Source File: CheckSignatureAdapter.java    From Concurnas with MIT License 5 votes vote down vote up
@Override
public SignatureVisitor visitClassBound() {
  if (type == TYPE_SIGNATURE || !VISIT_CLASS_BOUND_STATES.contains(state)) {
    throw new IllegalStateException();
  }
  state = State.BOUND;
  return new CheckSignatureAdapter(
      TYPE_SIGNATURE, signatureVisitor == null ? null : signatureVisitor.visitClassBound());
}
 
Example #27
Source File: CheckSignatureAdapter.java    From Concurnas with MIT License 5 votes vote down vote up
@Override
public SignatureVisitor visitInterfaceBound() {
  if (type == TYPE_SIGNATURE || !VISIT_INTERFACE_BOUND_STATES.contains(state)) {
    throw new IllegalStateException();
  }
  return new CheckSignatureAdapter(
      TYPE_SIGNATURE, signatureVisitor == null ? null : signatureVisitor.visitInterfaceBound());
}
 
Example #28
Source File: CheckSignatureAdapter.java    From JReFrameworker with MIT License 5 votes vote down vote up
@Override
public SignatureVisitor visitTypeArgument(final char wildcard) {
  if (state != State.CLASS_TYPE) {
    throw new IllegalStateException();
  }
  if ("+-=".indexOf(wildcard) == -1) {
    throw new IllegalArgumentException();
  }
  return new CheckSignatureAdapter(
      TYPE_SIGNATURE,
      signatureVisitor == null ? null : signatureVisitor.visitTypeArgument(wildcard));
}
 
Example #29
Source File: Remapper.java    From JReFrameworker with MIT License 5 votes vote down vote up
/**
 * 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();
}
 
Example #30
Source File: TraceSignatureVisitor.java    From JReFrameworker with MIT License 5 votes vote down vote up
@Override
public SignatureVisitor visitReturnType() {
  endFormals();
  if (parameterTypeVisited) {
    parameterTypeVisited = false;
  } else {
    declaration.append('(');
  }
  declaration.append(')');
  returnType = new StringBuilder();
  return new TraceSignatureVisitor(returnType);
}