Search in sources :

Example 1 with FieldOrMethod

use of org.apache.bcel.classfile.FieldOrMethod in project fb-contrib by mebigfatguy.

the class JPAIssues method catalogFieldOrMethod.

/**
 * parses a field or method for spring-tx or jpa annotations
 *
 * @param fm
 *            the currently parsed field or method
 */
private void catalogFieldOrMethod(FieldOrMethod fm) {
    for (AnnotationEntry entry : fm.getAnnotationEntries()) {
        String type = entry.getAnnotationType();
        switch(type) {
            case "Lorg/springframework/transaction/annotation/Transactional;":
                if (fm instanceof Method) {
                    boolean isWrite = true;
                    for (ElementValuePair pair : entry.getElementValuePairs()) {
                        if ("readOnly".equals(pair.getNameString())) {
                            isWrite = "false".equals(pair.getValue().stringifyValue());
                            break;
                        }
                    }
                    transactionalMethods.put(new FQMethod(cls.getClassName(), fm.getName(), fm.getSignature()), isWrite ? TransactionalType.WRITE : TransactionalType.READ);
                }
                break;
            case "Ljavax/persistence/Id;":
                hasId = true;
                break;
            case "Ljavax/persistence/GeneratedValue;":
                hasGeneratedValue = true;
                break;
            case "Ljavax/persistence/OneToMany;":
                for (ElementValuePair pair : entry.getElementValuePairs()) {
                    if ("fetch".equals(pair.getNameString()) && "EAGER".equals(pair.getValue().stringifyValue())) {
                        hasEagerOneToMany = true;
                        break;
                    }
                }
                break;
            case "Lorg/hibernate/annotations/Fetch;":
            case "Lorg/eclipse/persistence/annotations/JoinFetch;":
            case "Lorg/eclipse/persistence/annotations/BatchFetch;":
                hasFetch = true;
                break;
            default:
                break;
        }
    }
}
Also used : AnnotationEntry(org.apache.bcel.classfile.AnnotationEntry) ElementValuePair(org.apache.bcel.classfile.ElementValuePair) FQMethod(com.mebigfatguy.fbcontrib.utils.FQMethod) FieldOrMethod(org.apache.bcel.classfile.FieldOrMethod) Method(org.apache.bcel.classfile.Method) FQMethod(com.mebigfatguy.fbcontrib.utils.FQMethod)

Aggregations

FQMethod (com.mebigfatguy.fbcontrib.utils.FQMethod)1 AnnotationEntry (org.apache.bcel.classfile.AnnotationEntry)1 ElementValuePair (org.apache.bcel.classfile.ElementValuePair)1 FieldOrMethod (org.apache.bcel.classfile.FieldOrMethod)1 Method (org.apache.bcel.classfile.Method)1