Java Code Examples for org.objectweb.asm.signature.SignatureReader#accept()

The following examples show how to use org.objectweb.asm.signature.SignatureReader#accept() . 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: Type.java    From spring-graalvm-native with Apache License 2.0 6 votes vote down vote up
/**
 * Compute all the types referenced in the signature of this type.
 *
 * @return
 */
public List<String> getTypesInSignature() {
	if (dimensions > 0) {
		return Collections.emptyList();
	} else if (node.signature == null) {
		// With no generic signature it is just superclass and interfaces
		List<String> ls = new ArrayList<>();
		if (node.superName != null) {
			ls.add(node.superName);
		}
		if (node.interfaces != null) {
			ls.addAll(node.interfaces);
		}
		return ls;
	} else {
		// Pull out all the types from the generic signature
		SignatureReader reader = new SignatureReader(node.signature);
		TypeCollector tc = new TypeCollector();
		reader.accept(tc);
		return tc.getTypes();
	}
}
 
Example 2
Source File: NameTranslatorClassVisitor.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
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();
}
 
Example 3
Source File: MethodSignatureVisitorTest.java    From meghanada-server with GNU General Public License v3.0 6 votes vote down vote up
@Override
public MethodVisitor visitMethod(
    int access, String name, String desc, String signature, String[] exceptions) {

  String target = signature;
  if (target == null) {
    target = desc;
  }
  SignatureReader signatureReader = new SignatureReader(target);
  this.visitor = new MethodSignatureVisitor(name, new ArrayList<>());
  signatureReader.accept(this.visitor);

  System.out.println(name);
  System.out.println(this.visitor.getFormalType());
  System.out.println(this.visitor.getParameterTypes());
  System.out.println(this.visitor.getTypeParameters());
  System.out.println(this.visitor.getReturnType());

  // result.put(name, this.visitor.getFormalType());

  return super.visitMethod(access, name, desc, signature, exceptions);
}
 
Example 4
Source File: MethodAnalyzeVisitor.java    From meghanada-server with GNU General Public License v3.0 6 votes vote down vote up
MethodAnalyzeVisitor parseSignature() {
  final EntryMessage entryMessage =
      log.traceEntry("name={} methodSignature={}", this.name, this.methodSignature);
  final boolean isStatic = (Opcodes.ACC_STATIC & this.access) > 0;
  final SignatureReader signatureReader = new SignatureReader(this.methodSignature);
  MethodSignatureVisitor visitor;
  if (isStatic) {
    visitor = new MethodSignatureVisitor(this.name, new ArrayList<>(4));
  } else {
    visitor = new MethodSignatureVisitor(this.name, this.classAnalyzeVisitor.classTypeParameters);
  }
  if (this.typeMap != null) {
    visitor.setTypeMap(this.typeMap);
  }

  signatureReader.accept(visitor);

  this.formalType = visitor.getFormalType();
  this.parameterTypes = visitor.getParameterTypes();
  this.typeParameters = visitor.getTypeParameters();
  this.returnType = visitor.getReturnType();
  log.traceExit(entryMessage);
  return this;
}
 
Example 5
Source File: Remapper.java    From Concurnas 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 6
Source File: Remapper.java    From JByteMod-Beta with GNU General Public License v2.0 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 7
Source File: ClassAnalyzeVisitor.java    From meghanada-server with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void visit(
    int api, int access, String name, String signature, String superClass, String[] interfaces) {
  // log.debug("Name:{}", name);
  // call class
  final boolean isInterface = (Opcodes.ACC_INTERFACE & access) == Opcodes.ACC_INTERFACE;
  // log.debug("name {} sig {} IF:{}", name, signature, isInterface);
  if (signature != null) {
    // generics
    // log.debug("name {} sig {}", name, signature);
    final SignatureReader signatureReader = new SignatureReader(signature);
    ClassSignatureVisitor classSignatureVisitor =
        new ClassSignatureVisitor(this.className, isInterface);
    signatureReader.accept(classSignatureVisitor);

    this.classTypeParameters = classSignatureVisitor.getTypeParameters();
    this.classIndex = classSignatureVisitor.getClassIndex();
    if (!this.classIndex.getSupers().contains(ClassNameUtils.OBJECT_CLASS)) {
      this.classIndex.addSuper(ClassNameUtils.OBJECT_CLASS);
    }
  } else {
    this.classTypeParameters = new ArrayList<>(4);
    final List<String> supers = new ArrayList<>(4);
    if (superClass != null) {
      final String superClassFQCN = ClassNameUtils.replaceSlash(superClass);
      supers.add(superClassFQCN);
    }
    Arrays.stream(interfaces)
        .forEach(interfaceName -> supers.add(ClassNameUtils.replaceSlash(interfaceName)));
    this.classIndex = new ClassIndex(this.className, new ArrayList<>(4), supers);
    this.classIndex.setInterface(isInterface);
  }
}
 
Example 8
Source File: DependencyAnalyzer.java    From Concurnas with MIT License 5 votes vote down vote up
private void addToDeps(String signature, String desc) {
	if(signature == null) {
		signature = desc;
	}
	final SignatureReader signatureReader = new SignatureReader(signature);
	SignatureVisitor visitor = new MethodSignatureVisitor(this.dependencies);
	signatureReader.accept(visitor);
}
 
Example 9
Source File: ClassSignatureVisitorTest.java    From meghanada-server with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void visit(
    int api, int access, String name, String sig, String superClass, String[] exceptions) {
  System.out.println("NAME:" + name);
  System.out.println("SUPER:" + superClass);
  System.out.println("sig:" + sig);
  if (sig != null) {
    boolean isInterface = (Opcodes.ACC_INTERFACE & access) == Opcodes.ACC_INTERFACE;
    SignatureReader signatureReader = new SignatureReader(sig);
    this.visitor = new ClassSignatureVisitor(this.name, isInterface);
    signatureReader.accept(this.visitor);
  }
}
 
Example 10
Source File: Type.java    From spring-graalvm-native with Apache License 2.0 5 votes vote down vote up
public String findTypeParameterInSupertype(String supertype, int typeParameterNumber) {
	if (node.signature == null) {
		return null;
	}
	SignatureReader reader = new SignatureReader(node.signature);
	TypeParamFinder tpm = new TypeParamFinder(supertype);
	reader.accept(tpm);
	return tpm.getTypeParameter(typeParameterNumber);
}
 
Example 11
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 12
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 13
Source File: Type.java    From spring-boot-graal-feature with Apache License 2.0 5 votes vote down vote up
public List<String> getTypesInSignature() {
	if (node.signature == null) {
		return Collections.emptyList();
	} else {
		SignatureReader reader = new SignatureReader(node.signature);
		TypeCollector tc = new TypeCollector();
		reader.accept(tc);
		return tc.getTypes();
	}
}
 
Example 14
Source File: Remapper.java    From bytecode-viewer with GNU General Public License v3.0 5 votes vote down vote up
/**
 * @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();
}
 
Example 15
Source File: SourceAbiCompatibleVisitor.java    From buck with Apache License 2.0 5 votes vote down vote up
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();
}
 
Example 16
Source File: ClassReferenceTracker.java    From buck with Apache License 2.0 5 votes vote down vote up
private void visitSignature(@Nullable String signature) {
  if (signature == null) {
    return;
  }

  SignatureReader reader = new SignatureReader(signature);
  reader.accept(new TrackingSignatureVisitor(api));
}
 
Example 17
Source File: Textifier.java    From JByteMod-Beta with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void visit(final int version, final int access, final String name, final String signature, final String superName,
    final String[] interfaces) {
  if ((access & Opcodes.ACC_MODULE) != 0) {
    // visitModule will print the module
    return;
  }
  this.access = access;
  int major = version & 0xFFFF;
  int minor = version >>> 16;
  buf.setLength(0);
  buf.append("// class version ").append(major).append('.').append(minor).append(" (").append(version).append(")\n");
  if ((access & Opcodes.ACC_DEPRECATED) != 0) {
    buf.append("// DEPRECATED\n");
  }
  buf.append("// access flags 0x").append(Integer.toHexString(access).toUpperCase()).append('\n');

  appendDescriptor(CLASS_SIGNATURE, signature);
  if (signature != null) {
    TraceSignatureVisitor sv = new TraceSignatureVisitor(access);
    SignatureReader r = new SignatureReader(signature);
    r.accept(sv);
    buf.append("// declaration: ").append(name).append(sv.getDeclaration()).append('\n');
  }

  appendAccess(access & ~(Opcodes.ACC_SUPER | Opcodes.ACC_MODULE));
  if ((access & Opcodes.ACC_ANNOTATION) != 0) {
    buf.append("@interface ");
  } else if ((access & Opcodes.ACC_INTERFACE) != 0) {
    buf.append("interface ");
  } else if ((access & Opcodes.ACC_ENUM) == 0) {
    buf.append("class ");
  }
  appendDescriptor(INTERNAL_NAME, name);

  if (superName != null && !"java/lang/Object".equals(superName)) {
    buf.append(" extends ");
    appendDescriptor(INTERNAL_NAME, superName);
    buf.append(' ');
  }
  if (interfaces != null && interfaces.length > 0) {
    buf.append(" implements ");
    for (int i = 0; i < interfaces.length; ++i) {
      appendDescriptor(INTERNAL_NAME, interfaces[i]);
      buf.append(' ');
    }
  }
  buf.append(" {\n\n");

  text.add(buf.toString());
}
 
Example 18
Source File: Textifier.java    From JByteMod-Beta with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Textifier visitMethod(final int access, final String name, final String desc, final String signature, final String[] exceptions) {
  buf.setLength(0);
  buf.append('\n');
  if ((access & Opcodes.ACC_DEPRECATED) != 0) {
    buf.append(tab).append("// DEPRECATED\n");
  }
  buf.append(tab).append("// access flags 0x").append(Integer.toHexString(access).toUpperCase()).append('\n');

  if (signature != null) {
    buf.append(tab);
    appendDescriptor(METHOD_SIGNATURE, signature);

    TraceSignatureVisitor v = new TraceSignatureVisitor(0);
    SignatureReader r = new SignatureReader(signature);
    r.accept(v);
    String genericDecl = v.getDeclaration();
    String genericReturn = v.getReturnType();
    String genericExceptions = v.getExceptions();

    buf.append(tab).append("// declaration: ").append(genericReturn).append(' ').append(name).append(genericDecl);
    if (genericExceptions != null) {
      buf.append(" throws ").append(genericExceptions);
    }
    buf.append('\n');
  }

  buf.append(tab);
  appendAccess(access & ~(Opcodes.ACC_VOLATILE | Opcodes.ACC_TRANSIENT));
  if ((access & Opcodes.ACC_NATIVE) != 0) {
    buf.append("native ");
  }
  if ((access & Opcodes.ACC_VARARGS) != 0) {
    buf.append("varargs ");
  }
  if ((access & Opcodes.ACC_BRIDGE) != 0) {
    buf.append("bridge ");
  }
  if ((this.access & Opcodes.ACC_INTERFACE) != 0 && (access & Opcodes.ACC_ABSTRACT) == 0 && (access & Opcodes.ACC_STATIC) == 0) {
    buf.append("default ");
  }

  buf.append(name);
  appendDescriptor(METHOD_DESCRIPTOR, desc);
  if (exceptions != null && exceptions.length > 0) {
    buf.append(" throws ");
    for (int i = 0; i < exceptions.length; ++i) {
      appendDescriptor(INTERNAL_NAME, exceptions[i]);
      buf.append(' ');
    }
  }

  buf.append('\n');
  text.add(buf.toString());

  Textifier t = createTextifier();
  text.add(t.getText());
  return t;
}
 
Example 19
Source File: CompatibleDetectingVisitor.java    From dependency-mediator with Apache License 2.0 4 votes vote down vote up
private void processSignature(String signature) {
    if (signature != null) {
        final SignatureReader signatureReader = new SignatureReader(signature);
        signatureReader.accept(signatureVisitor);
    }
}