Search in sources :

Example 1 with SignatureAttribute

use of javassist.bytecode.SignatureAttribute in project newton by muoncore.

the class EnableNewtonRegistrar method makeRepo.

private Class makeRepo(Class param) {
    ClassPool defaultClassPool = ClassPool.getDefault();
    defaultClassPool.appendClassPath(new LoaderClassPath(param.getClassLoader()));
    defaultClassPool.appendClassPath(new LoaderClassPath(MuonEventSourceRepository.class.getClassLoader()));
    defaultClassPool.appendSystemPath();
    try {
        CtClass superInterface = defaultClassPool.getCtClass(MuonEventSourceRepository.class.getName());
        String repoName = param.getName() + "Repository";
        try {
            return Class.forName(repoName);
        } catch (ClassNotFoundException e) {
            CtClass repositoryInterface = defaultClassPool.makeClass(repoName, superInterface);
            ClassFile classFile = repositoryInterface.getClassFile();
            String sig = "Ljava/lang/Object;Lio/muoncore/newton/eventsource/muon/MuonEventSourceRepository<L" + getSigName(param) + ";>;";
            SignatureAttribute signatureAttribute = new SignatureAttribute(classFile.getConstPool(), sig);
            classFile.addAttribute(signatureAttribute);
            return repositoryInterface.toClass();
        }
    } catch (NotFoundException | CannotCompileException e) {
        log.error("Unable to register a newton repository", e);
    }
    return null;
}
Also used : SignatureAttribute(javassist.bytecode.SignatureAttribute) ClassFile(javassist.bytecode.ClassFile) MuonEventSourceRepository(io.muoncore.newton.eventsource.muon.MuonEventSourceRepository)

Example 2 with SignatureAttribute

use of javassist.bytecode.SignatureAttribute in project fakereplace by fakereplace.

the class FieldReplacementTransformer method copyFieldAttributes.

private static void copyFieldAttributes(FieldInfo oldField, FieldInfo newField) {
    AnnotationsAttribute annotations = (AnnotationsAttribute) oldField.getAttribute(AnnotationsAttribute.visibleTag);
    SignatureAttribute sigAt = (SignatureAttribute) oldField.getAttribute(SignatureAttribute.tag);
    if (annotations != null) {
        AttributeInfo newAnnotations = annotations.copy(newField.getConstPool(), Collections.EMPTY_MAP);
        newField.addAttribute(newAnnotations);
    }
    if (sigAt != null) {
        AttributeInfo newAnnotations = sigAt.copy(newField.getConstPool(), Collections.EMPTY_MAP);
        newField.addAttribute(newAnnotations);
    }
}
Also used : SignatureAttribute(javassist.bytecode.SignatureAttribute) AttributeInfo(javassist.bytecode.AttributeInfo) AnnotationsAttribute(javassist.bytecode.AnnotationsAttribute)

Example 3 with SignatureAttribute

use of javassist.bytecode.SignatureAttribute in project fakereplace by fakereplace.

the class MethodReplacementTransformer method copyMethodAttributes.

public static void copyMethodAttributes(MethodInfo oldMethod, MethodInfo newMethod) {
    AnnotationsAttribute annotations = (AnnotationsAttribute) oldMethod.getAttribute(AnnotationsAttribute.visibleTag);
    ParameterAnnotationsAttribute pannotations = (ParameterAnnotationsAttribute) oldMethod.getAttribute(ParameterAnnotationsAttribute.visibleTag);
    ExceptionsAttribute exAt = (ExceptionsAttribute) oldMethod.getAttribute(ExceptionsAttribute.tag);
    SignatureAttribute sigAt = (SignatureAttribute) oldMethod.getAttribute(SignatureAttribute.tag);
    if (annotations != null) {
        AttributeInfo newAnnotations = annotations.copy(newMethod.getConstPool(), Collections.EMPTY_MAP);
        newMethod.addAttribute(newAnnotations);
    }
    if (pannotations != null) {
        AttributeInfo newAnnotations = pannotations.copy(newMethod.getConstPool(), Collections.EMPTY_MAP);
        newMethod.addAttribute(newAnnotations);
    }
    if (sigAt != null) {
        AttributeInfo newAnnotations = sigAt.copy(newMethod.getConstPool(), Collections.EMPTY_MAP);
        newMethod.addAttribute(newAnnotations);
    }
    if (exAt != null) {
        AttributeInfo newAnnotations = exAt.copy(newMethod.getConstPool(), Collections.EMPTY_MAP);
        newMethod.addAttribute(newAnnotations);
    }
}
Also used : SignatureAttribute(javassist.bytecode.SignatureAttribute) AttributeInfo(javassist.bytecode.AttributeInfo) ExceptionsAttribute(javassist.bytecode.ExceptionsAttribute) ParameterAnnotationsAttribute(javassist.bytecode.ParameterAnnotationsAttribute) ParameterAnnotationsAttribute(javassist.bytecode.ParameterAnnotationsAttribute) AnnotationsAttribute(javassist.bytecode.AnnotationsAttribute)

Aggregations

SignatureAttribute (javassist.bytecode.SignatureAttribute)3 AnnotationsAttribute (javassist.bytecode.AnnotationsAttribute)2 AttributeInfo (javassist.bytecode.AttributeInfo)2 MuonEventSourceRepository (io.muoncore.newton.eventsource.muon.MuonEventSourceRepository)1 ClassFile (javassist.bytecode.ClassFile)1 ExceptionsAttribute (javassist.bytecode.ExceptionsAttribute)1 ParameterAnnotationsAttribute (javassist.bytecode.ParameterAnnotationsAttribute)1