use of org.apache.bcel.classfile.AnnotationEntry in project fb-contrib by mebigfatguy.
the class WiringIssues method loadParentAutowireds.
/**
* loads all the types that are injected by @Autowired annotations in super classes
*
* @param cls
* the class who's parents you want to load
* @param wiredFields
* the collected map of autowired types
* @throws ClassNotFoundException
* if a parent class can't be loaded
*/
@edu.umd.cs.findbugs.annotations.SuppressFBWarnings(value = "SF_SWITCH_NO_DEFAULT", justification = "Only a few cases need special handling")
private void loadParentAutowireds(JavaClass cls, Map<WiringType, FieldAnnotation> wiredFields) throws ClassNotFoundException {
if (Values.DOTTED_JAVA_LANG_OBJECT.equals(cls.getClassName())) {
return;
}
loadParentAutowireds(cls.getSuperClass(), wiredFields);
Field[] fields = cls.getFields();
if (fields.length > 0) {
for (Field field : fields) {
boolean hasAutowired = false;
String qualifier = "";
for (AnnotationEntry entry : field.getAnnotationEntries()) {
switch(entry.getAnnotationType()) {
case SPRING_AUTOWIRED:
hasAutowired = true;
break;
case SPRING_QUALIFIER:
qualifier = entry.getElementValuePairs()[0].getValue().stringifyValue();
break;
}
}
if (hasAutowired) {
WiringType wt = new WiringType(field.getSignature(), field.getGenericSignature(), qualifier);
wiredFields.put(wt, FieldAnnotation.fromBCELField(cls.getClassName(), field));
}
}
}
}
use of org.apache.bcel.classfile.AnnotationEntry in project fb-contrib by mebigfatguy.
the class JAXRSIssues method processJAXRSMethod.
private void processJAXRSMethod(Method m, String path, boolean hasConsumes) {
Type[] parmTypes = m.getArgumentTypes();
int numParms = parmTypes.length;
if (numParms > 0) {
boolean sawBareParm = false;
ParameterAnnotationEntry[] pes = m.getParameterAnnotationEntries();
int parmIndex = 0;
for (ParameterAnnotationEntry pe : pes) {
boolean foundParamAnnotation = false;
for (AnnotationEntry a : pe.getAnnotationEntries()) {
String annotationType = a.getAnnotationType();
if (PARAM_ANNOTATIONS.contains(annotationType)) {
foundParamAnnotation = true;
if ((path != null) && "Ljavax/ws/rs/PathParam;".equals(annotationType)) {
String parmPath = getDefaultAnnotationValue(a);
if ((parmPath != null) && (!path.matches(".*\\{" + parmPath + "\\b.*"))) {
bugReporter.reportBug(new BugInstance(this, BugType.JXI_PARM_PARAM_NOT_FOUND_IN_PATH.name(), NORMAL_PRIORITY).addClass(this).addMethod(this).addString("Path param: " + parmPath));
}
} else if ("Ljavax/ws/rs/core/Context;".equals(annotationType)) {
String parmSig = parmTypes[parmIndex].getSignature();
if (!VALID_CONTEXT_TYPES.contains(parmSig)) {
bugReporter.reportBug(new BugInstance(this, BugType.JXI_INVALID_CONTEXT_PARAMETER_TYPE.name(), NORMAL_PRIORITY).addClass(this).addMethod(this).addString("Parameter signature: " + parmSig));
}
}
}
}
if (!foundParamAnnotation) {
if ((!sawBareParm) && (hasConsumes || NATIVE_JAXRS_TYPES.contains(parmTypes[parmIndex].getSignature()))) {
sawBareParm = true;
} else {
bugReporter.reportBug(new BugInstance(this, BugType.JXI_UNDEFINED_PARAMETER_SOURCE_IN_ENDPOINT.name(), NORMAL_PRIORITY).addClass(this).addMethod(this).addString("Parameter " + (parmIndex + 1)));
break;
}
}
parmIndex++;
}
}
}
use of org.apache.bcel.classfile.AnnotationEntry in project fb-contrib by mebigfatguy.
the class JAXRSIssues method visitClassContext.
@Override
public void visitClassContext(ClassContext classContext) {
JavaClass cls = classContext.getJavaClass();
pathOnClass = "";
hasClassConsumes = false;
for (AnnotationEntry entry : cls.getAnnotationEntries()) {
if ("Ljavax/ws/rs/Consumes;".equals(entry.getAnnotationType())) {
hasClassConsumes = true;
} else if ("Ljavax/ws/rs/Path;".equals(entry.getAnnotationType())) {
pathOnClass = getDefaultAnnotationValue(entry);
}
}
cls.accept(this);
}
use of org.apache.bcel.classfile.AnnotationEntry in project fb-contrib by mebigfatguy.
the class JPAIssues method catalogClass.
/**
* parses the current class for spring-tx and jpa annotations, as well as hashCode and equals methods.
*
* @param cls
* the currently parsed class
*/
private void catalogClass(JavaClass cls) {
transactionalMethods = new HashMap<>();
isEntity = false;
hasId = false;
hasGeneratedValue = false;
hasEagerOneToMany = false;
hasHCEquals = false;
for (AnnotationEntry entry : cls.getAnnotationEntries()) {
if ("Ljavax/persistence/Entity;".equals(entry.getAnnotationType())) {
isEntity = true;
break;
}
}
for (Method m : cls.getMethods()) {
catalogFieldOrMethod(m);
if (("equals".equals(m.getName()) && SignatureBuilder.SIG_OBJECT_TO_BOOLEAN.equals(m.getSignature())) || (Values.HASHCODE.equals(m.getName()) && SignatureBuilder.SIG_VOID_TO_INT.equals(m.getSignature()))) {
hasHCEquals = true;
}
}
for (Field f : cls.getFields()) {
catalogFieldOrMethod(f);
}
}
use of org.apache.bcel.classfile.AnnotationEntry in project fb-contrib by mebigfatguy.
the class CollectStatistics method visitClassContext.
/**
* implements the visitor to collect statistics on this class
*
* @param classContext
* the currently class
*/
@Override
public void visitClassContext(ClassContext classContext) {
try {
JavaClass cls = classContext.getJavaClass();
AnnotationEntry[] annotations = cls.getAnnotationEntries();
classHasAnnotation = !CollectionUtils.isEmpty(annotations);
stack = new OpcodeStack();
selfCallTree = new HashMap<>();
super.visitClassContext(classContext);
performModifyStateClosure(classContext.getJavaClass());
} finally {
stack = null;
selfCallTree = null;
curMethod = null;
}
}
Aggregations