Example usage for org.objectweb.asm Type getDescriptor

List of usage examples for org.objectweb.asm Type getDescriptor

Introduction

In this page you can find the example usage for org.objectweb.asm Type getDescriptor.

Prototype

public static String getDescriptor(final Class<?> clazz) 

Source Link

Document

Returns the descriptor corresponding to the given class.

Usage

From source file:appeng.coremod.asm.ASMIntegration.java

License:Open Source License

private boolean hasAnnotation(final AnnotationNode ann, final Class<?> annotation) {
    return ann.desc.equals(Type.getDescriptor(annotation));
}

From source file:appeng.transformer.asm.ASMIntegration.java

License:Open Source License

private boolean hasAnnotation(AnnotationNode ann, Class<?> annotation) {
    return ann.desc.equals(Type.getDescriptor(annotation));
}

From source file:blue.origami.lang.OClassDeclType.java

License:Apache License

@Override
public void typeDesc(StringBuilder sb, int levelGeneric) {
    if (wrapped != null) {
        sb.append(Type.getDescriptor(unwrap()));
    } else {/*from   ww  w .  j  a  v a 2 s . co m*/
        sb.append("L");
        sb.append(this.getName().replace('.', '/'));
        sb.append(";");
    }
}

From source file:blue.origami.lang.type.OClassType.java

License:Apache License

@Override
public void typeDesc(StringBuilder sb, int levelGeneric) {
    sb.append(Type.getDescriptor(unwrap()));
}

From source file:bluejelly.PrimTransformer.java

License:BSD License

private void generate(PrimInfo pi) {
    for (int i = 0; i < pi.arity; i++) {
        Label start = new Label();
        Label end = new Label();
        String method = getMethodName(pi, i);
        String cont = getContName(pi, i);
        MethodVisitor v = cv.visitMethod(ACC_PUBLIC, method, DESC, null, null);
        generateAnn(v, pi, i);//from   w  w w  .  ja  v a  2  s.  co m
        v.visitCode();
        v.visitLabel(start);
        if (i == 0) {
            v.visitIntInsn(ALOAD, 1);
            pushIntConst(v, pi.arity);
            v.visitMethodInsn(INVOKEVIRTUAL, CTX, "stackCheck", "(I)V");
        }
        v.visitIntInsn(ALOAD, 1);
        pushIntConst(v, i << 1);
        v.visitLdcInsn(cont);
        v.visitMethodInsn(INVOKEVIRTUAL, CTX, "evalVar", "(ILjava/lang/String;)V");
        v.visitLabel(end);
        v.visitInsn(RETURN);
        v.visitLocalVariable("ctx", Type.getDescriptor(ExecutionContext.class), null, start, end, 1);
        v.visitMaxs(3, 2);
        v.visitEnd();
    }
}

From source file:bluejelly.PrimTransformer.java

License:BSD License

private void generateAnn(MethodVisitor v, PrimInfo pi, int i) {
    AnnotationVisitor a = v.visitAnnotation(Type.getDescriptor(JellyCode.class), true);
    if (i == 0)/*  ww w.j av  a2 s  .  c om*/
        a.visit("arity", pi.arity);
    a.visitEnd();
}

From source file:bluejelly.runtime.ModuleLoader.java

License:BSD License

/**
 * Override <code>fastEnter</code> method in class being visited
 * by <code>cw</code>, subclass of <code>superName</code>. Method
 * will call <code>methodName</code>. declared in class 
 * <code>moduleName</code>. So , assuming class generated by
 * <code>cw</code> is named <code>X</code>, we will have:
 * //from  ww w.j  a va  2  s .co m
 * <p>
 * <code>
 * class X extends superName {
 *     public void fastEnter(ExecutionContext ctx) {
 *         ((moduleName)this.module).methodName(ctx);
 *     }
 * }
 * </code>
 * 
 * @param cw            class writer generating class code
 * @param superName     internal name of superclass: Code or Caf
 * @param moduleName    internal name of module class
 * @param methodName    name of method to invoke in module moduleName
 */
private void generateFastEnter(ClassWriter cw, String superName, String moduleName, String methodName) {

    String fieldDesc = Type.getDescriptor(Module.class);
    String methodDesc = "(" + Type.getDescriptor(ExecutionContext.class) + ")V";

    MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "fastEnter", methodDesc, null, null);
    mv.visitCode();
    mv.visitVarInsn(ALOAD, 0);
    mv.visitFieldInsn(GETFIELD, superName, "module", fieldDesc);
    mv.visitTypeInsn(CHECKCAST, moduleName);
    mv.visitVarInsn(ALOAD, 1);
    mv.visitMethodInsn(INVOKEVIRTUAL, moduleName, methodName, methodDesc);
    mv.visitInsn(RETURN);
    mv.visitMaxs(2, 2);
    mv.visitEnd();
}

From source file:ch.raffael.contracts.processor.pmap.ParameterMapAnnotationProcessor.java

License:Apache License

@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE, "Building parameter maps");
    for (Element elem : roundEnv.getRootElements()) {
        if (elem.getKind() == ElementKind.CLASS || elem.getKind() == ElementKind.INTERFACE) {
            // FIXME: enums & enum constants
            try {
                TypeElement typeElem = (TypeElement) elem;
                processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE,
                        "Processing: " + ((TypeElement) elem).getQualifiedName());
                String className = typeElem.getQualifiedName().toString();
                if (className.endsWith(CONTRACTS_CLASS_SUFFIX)) {
                    continue;
                }//from  w  ww.ja v a2  s.  c om
                String ctrClassName = className + CONTRACTS_CLASS_SUFFIX;
                JavaFileObject contractsFile = processingEnv.getFiler().createClassFile(ctrClassName, elem);
                ClassWriter classWriter = new ClassWriter(0);
                classWriter.visit(V1_7, ACC_PUBLIC + ACC_SUPER, toInternalName(ctrClassName), null, null, null);
                MethodVisitor ctor = classWriter.visitMethod(ACC_PRIVATE, "<init>", "()V", null, null);
                ctor.visitCode();
                ctor.visitLabel(new Label());
                ctor.visitEnd();
                //classWriter.visitOuterClass(toInternalName(className), null, null);
                AnnotationVisitor parameterMap = classWriter
                        .visitAnnotation(Type.getDescriptor(ParameterMap.class), false);
                writeType(parameterMap, typeElem, null);
                parameterMap.visitEnd();
                classWriter.visitEnd();
                try (OutputStream output = contractsFile.openOutputStream()) {
                    output.write(classWriter.toByteArray());
                }
            } catch (IOException e) {
                processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, e.getLocalizedMessage());
            }
        }
    }
    return false;
}

From source file:ch.raffael.contracts.processor.pmap.ParameterMapAnnotationProcessor.java

License:Apache License

private void writeType(AnnotationVisitor annotation, TypeElement element, AnnotationVisitor innerClassArray) {
    AnnotationVisitor methodsArray = annotation.visitArray("methods");
    for (Element elem : element.getEnclosedElements()) {
        String methodName;/*from w ww  .jav  a2 s. c  om*/
        if (elem.getKind() == ElementKind.CONSTRUCTOR) {
            methodName = CTOR_NAME;
        } else if (elem.getKind() == ElementKind.METHOD) {
            methodName = elem.getSimpleName().toString();
        } else {
            continue;
        }
        AnnotationVisitor methodAnnotation = methodsArray.visitAnnotation(null,
                Type.getDescriptor(ParameterMap.Method.class));
        methodAnnotation.visit("descriptor", getMethodDescriptor((ExecutableElement) elem));
        AnnotationVisitor paramNames = methodAnnotation.visitArray("parameterNames");
        for (VariableElement param : ((ExecutableElement) elem).getParameters()) {
            paramNames.visit(null, param.getSimpleName().toString());
        }
        paramNames.visitEnd();
        methodAnnotation.visitEnd();
    }
    methodsArray.visitEnd();
    boolean endInnerClassArray = false;
    if (innerClassArray == null) {
        innerClassArray = annotation.visitArray("innerClasses");
        endInnerClassArray = true;
    }
    for (Element innerElem : element.getEnclosedElements()) {
        if (isType(innerElem)) {
            AnnotationVisitor innerClass = innerClassArray.visitAnnotation(null,
                    Type.getDescriptor(ParameterMap.InnerClass.class));
            innerClass.visit("name", toInternalName(
                    processingEnv.getElementUtils().getBinaryName((TypeElement) innerElem).toString()));
            writeType(innerClass, (TypeElement) innerElem, innerClassArray);
            innerClass.visitEnd();
        }
    }
    if (endInnerClassArray) {
        innerClassArray.visitEnd();
    }
}

From source file:cn.annoreg.asm.InnerClassVisitor.java

License:Open Source License

@Override
public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
    if (desc.equals(Type.getDescriptor(SideOnly.class))) {
        //We need to know if it's client only.
        return new AnnotationVisitor(api) {
            @Override//from  www .  j  a  v  a 2  s. c om
            public void visitEnum(String name, String desc, String value) {
                if (value == Side.CLIENT.toString()) {
                    InnerClassVisitor.this.clientOnly = true;
                }
            }
        };
    }
    if (desc.equals(Type.getDescriptor(Registrant.class))) {
        isReg = true;
    }
    return null;
}