org.objectweb.asm.signature.SignatureReader Java Examples

The following examples show how to use org.objectweb.asm.signature.SignatureReader. 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: 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 #3
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 #4
Source File: FieldAnalyzeVisitor.java    From meghanada-server with GNU General Public License v3.0 6 votes vote down vote up
FieldAnalyzeVisitor parseSignature() {
  final EntryMessage m = log.traceEntry("fieldSignature={}", fieldSignature);
  boolean isStatic = (Opcodes.ACC_STATIC & this.access) > 0;
  SignatureReader signatureReader = new SignatureReader(this.fieldSignature);
  FieldSignatureVisitor visitor;
  if (isStatic) {
    visitor = new FieldSignatureVisitor(this.name, new ArrayList<>(4));
  } else {
    visitor = new FieldSignatureVisitor(this.name, this.classAnalyzeVisitor.classTypeParameters);
  }
  if (this.typeMap != null) {
    visitor.setTypeMap(this.typeMap);
  }

  this.fieldSignatureVisitor = visitor;
  signatureReader.acceptType(fieldSignatureVisitor);
  return log.traceExit(m, this);
}
 
Example #5
Source File: Textifier.java    From JByteMod-Beta with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void visitLocalVariable(final String name, final String desc, final String signature, final Label start, final Label end, final int index) {
  buf.setLength(0);
  buf.append(tab2).append("LOCALVARIABLE ").append(name).append(' ');
  appendDescriptor(FIELD_DESCRIPTOR, desc);
  buf.append(' ');
  appendLabel(start);
  buf.append(' ');
  appendLabel(end);
  buf.append(' ').append(index).append('\n');

  if (signature != null) {
    buf.append(tab2);
    appendDescriptor(FIELD_SIGNATURE, signature);

    TraceSignatureVisitor sv = new TraceSignatureVisitor(0);
    SignatureReader r = new SignatureReader(signature);
    r.acceptType(sv);
    buf.append(tab2).append("// declaration: ").append(sv.getDeclaration()).append('\n');
  }
  text.add(buf.toString());
}
 
Example #6
Source File: Textifier.java    From JReFrameworker with MIT License 6 votes vote down vote up
/**
 * Appends the Java generic type declaration corresponding to the given signature.
 *
 * @param name a class, field or method name.
 * @param signature a class, field or method signature.
 */
private void appendJavaDeclaration(final String name, final String signature) {
  TraceSignatureVisitor traceSignatureVisitor = new TraceSignatureVisitor(access);
  new SignatureReader(signature).accept(traceSignatureVisitor);
  stringBuilder.append("// declaration: ");
  if (traceSignatureVisitor.getReturnType() != null) {
    stringBuilder.append(traceSignatureVisitor.getReturnType());
    stringBuilder.append(' ');
  }
  stringBuilder.append(name);
  stringBuilder.append(traceSignatureVisitor.getDeclaration());
  if (traceSignatureVisitor.getExceptions() != null) {
    stringBuilder.append(" throws ").append(traceSignatureVisitor.getExceptions());
  }
  stringBuilder.append('\n');
}
 
Example #7
Source File: Textifier.java    From JReFrameworker with MIT License 6 votes vote down vote up
/**
 * Appends the Java generic type declaration corresponding to the given signature.
 *
 * @param name a class, field or method name.
 * @param signature a class, field or method signature.
 */
private void appendJavaDeclaration(final String name, final String signature) {
  TraceSignatureVisitor traceSignatureVisitor = new TraceSignatureVisitor(access);
  new SignatureReader(signature).accept(traceSignatureVisitor);
  stringBuilder.append("// declaration: ");
  if (traceSignatureVisitor.getReturnType() != null) {
    stringBuilder.append(traceSignatureVisitor.getReturnType());
    stringBuilder.append(' ');
  }
  stringBuilder.append(name);
  stringBuilder.append(traceSignatureVisitor.getDeclaration());
  if (traceSignatureVisitor.getExceptions() != null) {
    stringBuilder.append(" throws ").append(traceSignatureVisitor.getExceptions());
  }
  stringBuilder.append('\n');
}
 
Example #8
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 #9
Source File: MixinApplicatorStandard.java    From Mixin with MIT License 6 votes vote down vote up
protected void mergeNewFields(MixinTargetContext mixin) {
    for (FieldNode field : mixin.getFields()) {
        FieldNode target = this.findTargetField(field);
        if (target == null) {
            // This is just a local field, so add it
            this.targetClass.fields.add(field);
            
            if (field.signature != null) {
                if (this.mergeSignatures) {
                    SignatureVisitor sv = mixin.getSignature().getRemapper();
                    new SignatureReader(field.signature).accept(sv);
                    field.signature = sv.toString();
                } else {
                    field.signature = null;
                }
            }
        }
    }
}
 
Example #10
Source File: ClassDependencyVisitor.java    From AVM with MIT License 6 votes vote down vote up
@Override
public MethodVisitor visitMethod(int access, String name, String descriptor, String signature, String[] exceptions) {

    if (signature == null) {
        dependencyCollector.addMethodDescriptor(descriptor);
    } else {
        new SignatureReader(signature).accept(signatureVisitor);
    }

    if (exceptions != null) {
        for (String ex : exceptions)
            dependencyCollector.addType(ex);
    }

    MethodVisitor mv = super.visitMethod(access, name, descriptor, signature, exceptions);
    return new MethodDependencyVisitor(mv, signatureVisitor, dependencyCollector, preserveDebugInfo);
}
 
Example #11
Source File: AsmClassVisitor.java    From jig with Apache License 2.0 6 votes vote down vote up
private List<TypeIdentifier> extractClassTypeFromGenericsSignature(String signature) {
    // ジェネリクスを使用している場合だけsignatureが入る
    List<TypeIdentifier> useTypes = new ArrayList<>();
    if (signature != null) {
        new SignatureReader(signature).accept(
                new SignatureVisitor(this.api) {
                    @Override
                    public void visitClassType(String name) {
                        // 引数と戻り値に登場するクラスを収集
                        useTypes.add(new TypeIdentifier(name));
                    }
                }
        );
    }
    return useTypes;
}
 
Example #12
Source File: AsmClassVisitor.java    From jig with Apache License 2.0 6 votes vote down vote up
private FieldType typeDescriptorToFieldType(String descriptor, String signature) {
    if (signature == null) {
        return typeDescriptorToFieldType(descriptor);
    }

    ArrayList<TypeIdentifier> typeParameters = new ArrayList<>();
    new SignatureReader(signature).accept(
            new SignatureVisitor(this.api) {
                @Override
                public SignatureVisitor visitTypeArgument(char wildcard) {
                    if (wildcard == '=') {
                        return new SignatureVisitor(this.api) {
                            @Override
                            public void visitClassType(String name) {
                                typeParameters.add(new TypeIdentifier(name));
                            }
                        };
                    }
                    return super.visitTypeArgument(wildcard);
                }
            }
    );
    TypeIdentifiers typeIdentifiers = new TypeIdentifiers(typeParameters);
    return new FieldType(typeDescriptorToIdentifier(descriptor), typeIdentifiers);
}
 
Example #13
Source File: Fingerprinter.java    From java-specialagent with Apache License 2.0 6 votes vote down vote up
@Override
public FieldVisitor visitField(final int access, final String name, final String desc, final String signature, final Object value) {
  if (Visibility.get(access) == Visibility.PRIVATE || FingerprintUtil.isSynthetic(access))
    return null;

  final FieldVisitor fieldVisitor = super.visitField(access, name, desc, signature, value);
  final Type type = Type.getType(desc);
  if (filtering)
    return null;

  addClassRef(type);
  final FieldLog log = addFieldRef(Type.getObjectType(className), name);
  if (log == null)
    return null;

  if (signature != null)
    new SignatureReader(signature).accept(signatureVisitor);

  log.resolve(typeToClassName(type, false));
  return fieldVisitor;
}
 
Example #14
Source File: Textifier.java    From Concurnas with MIT License 6 votes vote down vote up
/**
 * Appends the Java generic type declaration corresponding to the given signature.
 *
 * @param name a class, field or method name.
 * @param signature a class, field or method signature.
 */
private void appendJavaDeclaration(final String name, final String signature) {
  TraceSignatureVisitor traceSignatureVisitor = new TraceSignatureVisitor(access);
  new SignatureReader(signature).accept(traceSignatureVisitor);
  stringBuilder.append("// declaration: ");
  if (traceSignatureVisitor.getReturnType() != null) {
    stringBuilder.append(traceSignatureVisitor.getReturnType());
    stringBuilder.append(' ');
  }
  stringBuilder.append(name);
  stringBuilder.append(traceSignatureVisitor.getDeclaration());
  if (traceSignatureVisitor.getExceptions() != null) {
    stringBuilder.append(" throws ").append(traceSignatureVisitor.getExceptions());
  }
  stringBuilder.append('\n');
}
 
Example #15
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 #16
Source File: DependencyVisitor.java    From windup with Eclipse Public License 1.0 5 votes vote down vote up
void addTypeSignature(final String signature)
{
    if (signature != null)
    {
        new SignatureReader(signature).acceptType(new SignatureDependencyVisitor());
    }
}
 
Example #17
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 #18
Source File: DependencyVisitor.java    From windup with Eclipse Public License 1.0 5 votes vote down vote up
private void addSignature(final String signature)
{
    if (signature != null)
    {
        new SignatureReader(signature).accept(new SignatureDependencyVisitor());
    }
}
 
Example #19
Source File: Dependencies.java    From twill with Apache License 2.0 5 votes vote down vote up
@Override
public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
  addClass(name);

  if (signature != null) {
    new SignatureReader(signature).accept(signatureVisitor);
  } else {
    addClass(superName);
    addClasses(interfaces);
  }
}
 
Example #20
Source File: SignatureFactoryTest.java    From buck with Apache License 2.0 5 votes vote down vote up
/**
 * 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();
}
 
Example #21
Source File: JavaUtils.java    From jaxrs-analyzer with Apache License 2.0 5 votes vote down vote up
/**
 * Converts the given type signature to a human readable type string.
 * <p>
 * Example: {@code Ljava/util/Map<Ljava/lang/String;Ljava/lang/String;>; -> java.util.Map<java.lang.String, java.lang.String>}
 */
public static String toReadableType(final String type) {
    final SignatureReader reader = new SignatureReader(type);
    final TraceSignatureVisitor visitor = new TraceSignatureVisitor(0);
    reader.acceptType(visitor);
    return visitor.getDeclaration();
}
 
Example #22
Source File: MemberSignatureParser.java    From groovy with Apache License 2.0 5 votes vote down vote up
static FieldNode createFieldNode(FieldStub field, AsmReferenceResolver resolver, DecompiledClassNode owner) {
    final ClassNode[] type = {resolver.resolveType(Type.getType(field.desc))};
    if (field.signature != null) {
        new SignatureReader(field.signature).accept(new TypeSignatureParser(resolver) {
            @Override
            void finished(ClassNode result) {
                type[0] = applyErasure(result, type[0]);
            }
        });
    }
    ConstantExpression value = field.value == null ? null : new ConstantExpression(field.value);
    return new FieldNode(field.fieldName, field.accessModifiers, type[0], owner, value);
}
 
Example #23
Source File: ExtraTextifier.java    From TickDynamic with MIT License 5 votes vote down vote up
@Override
public void visitLocalVariable(final String name, final String desc,
        final String signature, final Label start, final Label end,
        final int index) {
    buf.setLength(0);
    
    if (signature != null) {
        buf.append(tab2);
        appendDescriptor(FIELD_SIGNATURE, signature);

        TraceSignatureVisitor sv = new TraceSignatureVisitor(0);
        SignatureReader r = new SignatureReader(signature);
        r.acceptType(sv);
        buf.append(tab2).append("// declaration: ")
                .append(sv.getDeclaration()).append('\n');
    }
    
    buf.append(tab2).append("LOCALVARIABLE ").append(name).append(' ');
    appendDescriptor(FIELD_DESCRIPTOR, desc);
    buf.append(' ');
    appendLabel(start);
    buf.append(' ');
    appendLabel(end);
    buf.append(' ').append(index).append('\n');

    text.add(buf.toString());
}
 
Example #24
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 #25
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 #26
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 #27
Source File: ClassSignature.java    From Mixin with MIT License 5 votes vote down vote up
/**
 * Use a {@link SignatureReader} to visit the supplied signature and build
 * the signature model
 * 
 * @param signature signature string to parse
 * @return fluent interface
 */
private ClassSignature read(String signature) {
    if (signature != null) {
        try {
            new SignatureReader(signature).accept(new SignatureParser());
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
    return this;
}
 
Example #28
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 #29
Source File: FieldSignatureVisitorTest.java    From meghanada-server with GNU General Public License v3.0 5 votes vote down vote up
@Override
public FieldVisitor visitField(
    int access, String name, String desc, String signature, Object value) {
  String target = signature;
  if (target == null) {
    target = desc;
  }
  SignatureReader signatureReader = new SignatureReader(target);
  this.visitor = new FieldSignatureVisitor(name, new ArrayList<>());
  signatureReader.acceptType(this.visitor);
  result.put(name, this.visitor.getResult());
  return super.visitField(access, name, desc, signature, value);
}
 
Example #30
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);
}