use of org.apache.bcel.classfile.ElementValuePair in project fb-contrib by mebigfatguy.
the class UnsynchronizedSingletonFieldWrites method isSingleton.
private boolean isSingleton(JavaClass cls) {
if (cls.isEnum()) {
return true;
}
AnnotationEntry[] annotations = cls.getAnnotationEntries();
if (CollectionUtils.isEmpty(annotations)) {
return false;
}
boolean isSpringBean = false;
for (AnnotationEntry annotation : annotations) {
String type = annotation.getAnnotationType();
if (SPRING_CLASS_ANNOTATIONS.contains(type)) {
isSpringBean = true;
} else if (SPRING_SCOPE_ANNOTATION.equals(type)) {
ElementValuePair[] pairs = annotation.getElementValuePairs();
if (!CollectionUtils.isEmpty(pairs)) {
for (ElementValuePair pair : pairs) {
String propName = pair.getNameString();
if ("value".equals(propName) || "scopeName".equals(propName)) {
ElementValue value = pair.getValue();
return "singleton".equals(value.stringifyValue());
}
}
}
}
}
return isSpringBean;
}
use of org.apache.bcel.classfile.ElementValuePair 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;
}
}
}
use of org.apache.bcel.classfile.ElementValuePair in project fb-contrib by mebigfatguy.
the class JPAIssues method getAnnotatedRollbackExceptions.
/**
* parses an spring-tx @Transactional annotations for rollbackFor/noRollbackfor attributes of a @Transactional annotation.
*
* @param method
* the currently parsed method
*
* @return the exception classes declared in the @Transactional annotation
*
* @throws ClassNotFoundException
* if exception classes are not found
*/
private Set<JavaClass> getAnnotatedRollbackExceptions(Method method) throws ClassNotFoundException {
for (AnnotationEntry annotation : method.getAnnotationEntries()) {
if ("Lorg/springframework/transaction/annotation/Transactional;".equals(annotation.getAnnotationType())) {
if (annotation.getNumElementValuePairs() == 0) {
return Collections.<JavaClass>emptySet();
}
Set<JavaClass> rollbackExceptions = new HashSet<>();
for (ElementValuePair pair : annotation.getElementValuePairs()) {
if ("rollbackFor".equals(pair.getNameString()) || "noRollbackFor".equals(pair.getNameString())) {
String exNames = pair.getValue().stringifyValue();
Matcher m = annotationClassPattern.matcher(exNames);
while (m.find()) {
String exName = m.group(1);
JavaClass exCls = Repository.lookupClass(SignatureUtils.trimSignature(exName));
if (!exCls.instanceOf(runtimeExceptionClass)) {
rollbackExceptions.add(exCls);
}
}
}
}
return rollbackExceptions;
}
}
return Collections.<JavaClass>emptySet();
}
Aggregations