private FieldInjectionTarget(TargetMember targetMember, CtClass ctClass, CtField ctField) { super(targetMember, ctClass); this.ctField = ctField; if (!Modifier.isStatic(ctField.getModifiers())) { throw new InjectionException( "Field is not static [" + targetMember.getQualifiedName() + "]"); } }
protected BaseInjectionTarget(TargetMember targetMember, CtClass ctClass) { this.targetMember = targetMember; this.ctClass = ctClass; try { classFileLocation = new File(loaderClassPath.find(targetMember.getClassName()).toURI()); } catch (Throwable e) { throw new InjectionException("Unable to resolve class file path", e); } }
private InjectionTarget resolveInjectionTarget(TargetMember targetMember) { try { final CtClass ctClass = classPool.get(targetMember.getClassName()); // see if it is a field... try { CtField field = ctClass.getField(targetMember.getMemberName()); return new FieldInjectionTarget(targetMember, ctClass, field); } catch (NotFoundException ignore) { } // see if it is a method... for (CtMethod method : ctClass.getMethods()) { if (method.getName().equals(targetMember.getMemberName())) { return new MethodInjectionTarget(targetMember, ctClass, method); } } // finally throw an exception throw new InjectionException("Unknown member [" + targetMember.getQualifiedName() + "]"); } catch (Throwable e) { throw new InjectionException( "Unable to resolve class [" + targetMember.getClassName() + "]", e); } }