use of org.apache.bcel.classfile.Field in project jop by jop-devel.
the class ConstantPoolReferenceFinder method findReferencedMembers.
/**
* Find all referenced members in a class.
* @param classInfo the class to search.
* @param checkMembers if false, do not check fields and methods. Else check everything.
* @return a set of class names and class member signatures found in the class.
*/
public static Set<String> findReferencedMembers(ClassInfo classInfo, boolean checkMembers) {
// Else we need to go into details..
Set<String> members = new HashSet<String>();
ClassMemberVisitor visitor = new ClassMemberVisitor(members);
JavaClass javaClass = classInfo.compile();
Set<Integer> ids = findPoolReferences(classInfo, javaClass);
List<InvokeSite> invokes = new ArrayList<InvokeSite>();
if (checkMembers) {
for (Field field : javaClass.getFields()) {
FieldInfo fieldInfo = classInfo.getFieldInfo(field.getName());
// add members found in the field
visitor.visitField(fieldInfo);
// there are no invokesites in a field, only add found ids
ids.addAll(findPoolReferences(fieldInfo, field));
}
for (Method method : javaClass.getMethods()) {
MethodInfo methodInfo = classInfo.getMethodInfo(method.getName() + method.getSignature());
// add members found in the method
visitor.visitMethod(methodInfo);
// add all ids for checking, add all invoke sites
ids.addAll(findPoolReferences(methodInfo, method));
}
}
// fill the members list with all found constantpool references
visitor.visitClass(classInfo);
visitPoolReferences(classInfo, visitor, ids);
return members;
}
use of org.apache.bcel.classfile.Field in project candle-decompiler by bradsdavis.
the class ClassIntermediateVisitor method visitJavaClass.
@Override
public void visitJavaClass(JavaClass obj) {
this.classBlock.setClassName(javaClass.getClassName());
this.classBlock.setPackageName(obj.getPackageName());
this.classBlock.setSuperClassName(obj.getSuperclassName());
// process the pool.
Constant[] pool = obj.getConstantPool().getConstantPool();
for (Constant c : pool) {
if (c == null)
continue;
c.accept(this);
}
Field[] fields = obj.getFields();
for (int i = 0, j = fields.length; i < j; i++) {
fields[i].accept(this);
}
// run through all of the methods
Method[] methods = obj.getMethods();
for (int i = 0, j = methods.length; i < j; i++) {
methods[i].accept(this);
}
}
use of org.apache.bcel.classfile.Field in project candle-decompiler by bradsdavis.
the class MethodIntermediateVisitor method visitPUTSTATIC.
public void visitPUTSTATIC(PUTSTATIC instruction) {
ConstantPoolGen cpg = context.getMethodGen().getConstantPool();
String fieldName = instruction.getFieldName(cpg);
Type fieldType = instruction.getFieldType(cpg);
Expression right = context.getExpressions().pop();
Variable variable = new Variable(context.getCurrentInstruction(), fieldType, fieldName);
Assignment assignment = new Assignment(context.getCurrentInstruction(), variable, right);
if (LOG.isDebugEnabled()) {
for (Field field : context.getJavaClass().getFields()) {
LOG.debug(field);
}
}
StatementIntermediate complete = new StatementIntermediate(context.getCurrentInstruction(), assignment);
context.pushIntermediateToInstruction(complete);
}
use of org.apache.bcel.classfile.Field in project fb-contrib by mebigfatguy.
the class NonFunctionalField method visitClassContext.
/**
* checks to see if the class is Serializable, then looks for fields that are both final and transient
*
* @param classContext
* the context object of the currently parsed class
*/
@Override
public void visitClassContext(ClassContext classContext) {
try {
JavaClass cls = classContext.getJavaClass();
if ((serializableClass != null) && (cls.implementationOf(serializableClass))) {
Field[] fields = cls.getFields();
setupVisitorForClass(cls);
for (Field f : fields) {
if (!f.isStatic() && f.isFinal() && f.isTransient()) {
bugReporter.reportBug(new BugInstance(this, BugType.NFF_NON_FUNCTIONAL_FIELD.name(), Priorities.NORMAL_PRIORITY).addClass(this).addField(cls.getClassName(), f.getName(), f.getSignature(), f.getAccessFlags()));
}
}
}
} catch (ClassNotFoundException cnfe) {
bugReporter.reportMissingClass(cnfe);
}
}
use of org.apache.bcel.classfile.Field in project fb-contrib by mebigfatguy.
the class WiringIssues method visitClassContext.
@edu.umd.cs.findbugs.annotations.SuppressFBWarnings(value = "SF_SWITCH_NO_DEFAULT", justification = "Only a few cases need special handling")
@Override
public void visitClassContext(ClassContext classContext) {
try {
JavaClass cls = classContext.getJavaClass();
Field[] fields = cls.getFields();
if (fields.length > 0) {
Map<WiringType, FieldAnnotation> wiredFields = new HashMap<>();
boolean loadedParents = false;
for (Field field : fields) {
boolean hasAutowired = false;
String qualifier = "";
for (AnnotationEntry entry : field.getAnnotationEntries()) {
switch(entry.getAnnotationType()) {
case SPRING_AUTOWIRED:
if (!loadedParents) {
loadParentAutowireds(cls.getSuperClass(), wiredFields);
loadedParents = true;
}
hasAutowired = true;
break;
case SPRING_QUALIFIER:
qualifier = entry.getElementValuePairs()[0].getValue().stringifyValue();
break;
}
}
if (hasAutowired) {
WiringType wt = new WiringType(field.getSignature(), field.getGenericSignature(), qualifier);
FieldAnnotation existingAnnotation = wiredFields.get(wt);
if (existingAnnotation == null) {
wiredFields.put(wt, FieldAnnotation.fromBCELField(cls.getClassName(), field));
} else {
bugReporter.reportBug(new BugInstance(this, BugType.WI_DUPLICATE_WIRED_TYPES.name(), NORMAL_PRIORITY).addClass(cls).addField(FieldAnnotation.fromBCELField(cls, field)).addField(existingAnnotation));
wiredFields.remove(wt);
}
}
}
}
stack = new OpcodeStack();
super.visitClassContext(classContext);
} catch (ClassNotFoundException e) {
bugReporter.reportMissingClass(e);
} finally {
stack = null;
}
}
Aggregations