Refine search
private void processField(final DeploymentUnit deploymentUnit, final EJBResourceWrapper annotation, final FieldInfo fieldInfo, final EEModuleDescription eeModuleDescription) { final String fieldName = fieldInfo.name(); final String fieldType = fieldInfo.type().name().toString(); final InjectionTarget targetDescription = new FieldInjectionTarget(fieldInfo.declaringClass().name().toString(), fieldName, fieldType); final String localContextName = isEmpty(annotation.name()) ? fieldInfo.declaringClass().name().toString() + "/" + fieldInfo.name() : annotation.name(); final String beanInterfaceType = isEmpty(annotation.beanInterface()) || annotation.beanInterface().equals(Object.class.getName()) ? fieldType : annotation.beanInterface(); process(deploymentUnit, beanInterfaceType, annotation.beanName(), annotation.lookup(), fieldInfo.declaringClass(), targetDescription, localContextName, eeModuleDescription); }
@Override public Collection<Annotation> getAnnotation(Class<?> annotationClass) { List<AnnotationInstance> instances = backingRepository.getAnnotations(DotName.createSimple(annotationClass .getName())); ArrayList<Annotation> annotations = new ArrayList<Annotation>(instances.size()); for (AnnotationInstance instance : instances) { AnnotationTarget target = instance.target(); Annotation annotation = null; if (target instanceof MethodInfo) { MethodInfo m = (MethodInfo) target; List<String> parameterTypes = new ArrayList<String>(m.args().length); for (Type type : m.args()) { parameterTypes.add(type.toString()); String declaringClass = m.declaringClass().name().toString(); annotation = new AnnotationImpl(declaringClass, cl, parameterTypes, m.name(), true, false, annotationClass); String declaringClass = f.declaringClass().name().toString(); annotation = new AnnotationImpl(declaringClass, cl, null, f.name(), false, true, annotationClass); annotation = new AnnotationImpl(c.name().toString(), cl, null, null, false, false, annotationClass);
final AnnotationTarget annotationTarget = annotation.target(); final AnnotationValue nameValue = annotation.value("name"); final String name = (nameValue != null) ? replacer.replaceProperties(nameValue.asString()) : null; final AnnotationValue typeValue = annotation.value("type"); final String type = typeValue != null ? typeValue.asClass().name().toString() : null; if (annotationTarget instanceof FieldInfo) { final FieldInfo fieldInfo = (FieldInfo) annotationTarget; final ClassInfo classInfo = fieldInfo.declaringClass(); EEModuleClassDescription classDescription = eeModuleDescription.addOrGetLocalClassDescription(classInfo.name().toString()); processFieldResource(phaseContext, fieldInfo, name, type, classDescription, annotation, eeModuleDescription, module, applicationClasses, replacer); } else if (annotationTarget instanceof MethodInfo) { final MethodInfo methodInfo = (MethodInfo) annotationTarget; ClassInfo classInfo = methodInfo.declaringClass(); EEModuleClassDescription classDescription = eeModuleDescription.addOrGetLocalClassDescription(classInfo.name().toString()); processMethodResource(phaseContext, methodInfo, name, type, classDescription, annotation, eeModuleDescription, module, applicationClasses, replacer); } else if (annotationTarget instanceof ClassInfo) { final ClassInfo classInfo = (ClassInfo) annotationTarget; EEModuleClassDescription classDescription = eeModuleDescription.addOrGetLocalClassDescription(classInfo.name().toString()); processClassResource(phaseContext, name, type, classDescription, annotation, eeModuleDescription, module, applicationClasses, replacer); final String name = (nameValue != null) ? replacer.replaceProperties(nameValue.asString()) : null; final AnnotationValue typeValue = annotation.value("type"); final String type = (typeValue != null) ? typeValue.asClass().name().toString() : null; EEModuleClassDescription classDescription = eeModuleDescription.addOrGetLocalClassDescription(classInfo.name().toString()); processClassResource(phaseContext, name, type, classDescription, annotation, eeModuleDescription, module, applicationClasses, replacer);
List<AnnotationInstance> instances = index.getAnnotations(typeName); for (AnnotationInstance instance : instances) { AnnotationTarget annotationTarget = instance.target(); if (annotationTarget instanceof ClassInfo) { classes.add((ClassInfo) annotationTarget); } else if (annotationTarget instanceof FieldInfo) { classes.add(((FieldInfo) annotationTarget).declaringClass()); } else if (annotationTarget instanceof MethodInfo) { classes.add(((MethodInfo) annotationTarget).declaringClass()); } else if (annotationTarget instanceof MethodParameterInfo) { classes.add(((MethodParameterInfo) annotationTarget).method().declaringClass()); parentImplementors.addAll(parent.getAllKnownSubclasses(typeName)); for(ClassInfo pc: parentImplementors) { classes.addAll(index.getAllKnownSubclasses(pc.name())); classes.addAll(index.getAllKnownImplementors(pc.name()));
if (simpleAnnotations != null) { for(AnnotationInstance annotation : simpleAnnotations) { annotations.add(new TargetAnnotation(annotation, annotation.target())); final Map<DotName, List<TargetAnnotation>> fieldLevel = new HashMap<DotName, List<TargetAnnotation>>(); for (TargetAnnotation instance : annotations) { final DotName targetClass = getAnnotationClass(instance.target()).name(); if (instance.target() instanceof ClassInfo) { List<TargetAnnotation> data = classLevel.get(targetClass); fieldData = new HashMap<String, List<T>>(); for (TargetAnnotation instance : fieldAnnotations) { final String name = ((FieldInfo) instance.target()).name(); List<T> data = fieldData.get(name); if (data == null) { ret.put(clazz.toString(), information);
stream.writePackedU32(classes.size()); for (ClassInfo clazz: classes) { stream.writePackedU32(positionOf(clazz.name())); stream.writePackedU32(clazz.superName() == null ? 0 : positionOf(clazz.superName())); stream.writeShort(clazz.flags()); stream.writePackedU32(instances.size()); for (AnnotationInstance instance : instances) { AnnotationTarget target = instance.target(); if (target instanceof FieldInfo) { FieldInfo field = (FieldInfo) target; stream.writeByte(FIELD_TAG); stream.writePackedU32(positionOf(field.name())); writeType(stream, field.type()); stream.writeShort(field.flags()); } else if (target instanceof MethodInfo) { MethodInfo method = (MethodInfo) target; stream.writeByte(METHOD_TAG); stream.writePackedU32(positionOf(method.name())); stream.writePackedU32(method.args().length); for (int i = 0; i < method.args().length; i ++) { writeType(stream, method.args()[i]); } else throw new IllegalStateException("Unknown target"); Collection<AnnotationValue> values = instance.values(); writeAnnotationValues(stream, values);
/** * Populates the sets of transient field and method names. */ private void findTransientFieldAndMethodNames() { List<AnnotationInstance> transientMembers = classInfo.annotations().get( JPADotNames.TRANSIENT ); if ( transientMembers == null ) { return; } for ( AnnotationInstance transientMember : transientMembers ) { AnnotationTarget target = transientMember.target(); if ( target instanceof FieldInfo ) { transientFieldNames.add( ( (FieldInfo) target ).name() ); } else { transientMethodNames.add( ( (MethodInfo) target ).name() ); } } }
addClassName(clazz.name()); if (clazz.superName() != null) addClassName(clazz.superName()); for (DotName intf: clazz.interfaces()) AnnotationTarget target = instance.target(); if (target instanceof FieldInfo) { FieldInfo field = (FieldInfo) target; intern(field.name()); addClassName(field.type().name()); intern(method.name()); for (Type type : method.args()) addClassName(type.name()); addClassName(method.returnType().name()); for (AnnotationValue value : instance.values()) buildAValueEntries(index, value);
private boolean hasInjectionPoint(DeploymentUnit depUnit, String anName) { boolean result = false; CompositeIndex compositeIndex = depUnit.getAttachment(Attachments.COMPOSITE_ANNOTATION_INDEX); List<AnnotationInstance> annotationList = compositeIndex.getAnnotations(DotName.createSimple(anName)); for (AnnotationInstance instance : annotationList) { AnnotationTarget target = instance.target(); if (target instanceof FieldInfo) { FieldInfo fieldInfo = (FieldInfo) target; String typeName = fieldInfo.type().toString(); if (typeName.startsWith("org.osgi.framework") || typeName.startsWith("org.osgi.service")) { LOGGER.debugf("OSGi injection point of type '%s' detected: %s", typeName, fieldInfo.declaringClass()); result = true; break; } } } return result; } }
/** * @param t1 can't be null * @param t2 can't be null */ public static boolean targetEquals(AnnotationTarget t1, AnnotationTarget t2) { if ( t1 == t2 ) { return true; } if ( t1 != null && t2 != null ) { if ( t1.getClass() == t2.getClass() ) { if ( t1.getClass() == ClassInfo.class ) { return ( (ClassInfo) t1 ).name().equals( ( (ClassInfo) t2 ).name() ); } else if ( t1.getClass() == MethodInfo.class ) { return ( (MethodInfo) t1 ).name().equals( ( (MethodInfo) t2 ).name() ); } else { return ( (FieldInfo) t1 ).name().equals( ( (FieldInfo) t2 ).name() ); } } } return false; }
@Override public String signature() { String jandexSignature = field.toString(); int typeEndIdx = jandexSignature.indexOf(' '); if (typeEndIdx < 0) { return jandexSignature; } else { if (isEnumConstant()) { // Chop off field type completely for enum constant return jandexSignature.substring(typeEndIdx + 1); } else { // Chop off prefix of the FQ name of the field type return Pattern.compile(field.type().name().toString(), Pattern.LITERAL).matcher(jandexSignature).replaceFirst(Wrappers.simpleName(field.type().name())); } } }
private ClassInfo getAnnotationClass(final AnnotationTarget annotationTarget) { if (annotationTarget instanceof ClassInfo) { return (ClassInfo) annotationTarget; } else if (annotationTarget instanceof MethodInfo) { return ((MethodInfo) annotationTarget).declaringClass(); } else if (annotationTarget instanceof FieldInfo) { return ((FieldInfo) annotationTarget).declaringClass(); } else if (annotationTarget instanceof MethodParameterInfo) { return ((MethodParameterInfo) annotationTarget).method().declaringClass(); } else { throw EeLogger.ROOT_LOGGER.unknownAnnotationTargetType(annotationTarget); } }
public static String getBindingKey(FieldInfo field) { StringBuilder sb = new StringBuilder(); sb.append(getBindingKey(field.declaringClass())); sb.append('.'); sb.append(field.name()); sb.append(')'); sb.append(getGeneralTypeBindingKey(field.type())); return sb.toString(); }
TypeVariable type = types[index].asTypeVariable(); int boundIndex = bound.boundPosition(); if (boundIndex >= type.boundArray().length) { int index = extendsTarget.position(); if (index == 65535) { clazz.setSuperClassType(resolveTypePath(clazz.superClassType(), typeAnnotationState)); } else if (index < clazz.interfaceTypes().size()) { Type[] types = clazz.copyInterfaceTypes(); types[index] = resolveTypePath(types[index], typeAnnotationState); MethodParameterTypeTarget parameter = (MethodParameterTypeTarget) typeTarget; int index = parameter.position(); Type[] types = method.copyParameters(); method.setParameters(intern(types)); } else if (typeTarget.usage() == TypeTarget.Usage.EMPTY && target instanceof FieldInfo) { FieldInfo field = (FieldInfo) target; field.setType(resolveTypePath(field.type(), typeAnnotationState)); } else if (typeTarget.usage() == TypeTarget.Usage.EMPTY && target instanceof MethodInfo) { MethodInfo method = (MethodInfo) target; if (((EmptyTypeTarget) typeTarget).isReceiver()) { method.setReceiverType(resolveTypePath(method.receiverType(), typeAnnotationState)); } else { method.setReturnType(resolveTypePath(method.returnType(), typeAnnotationState));
case EMPTY: { if (enclosingTarget instanceof FieldInfo) { type = ((FieldInfo)enclosingTarget).type(); } else { MethodInfo method = (MethodInfo) enclosingTarget; type = target.asEmpty().isReceiver() ? method.receiverType() : method.returnType(); ClassInfo clazz = (ClassInfo) enclosingTarget; int position = target.asClassExtends().position(); type = position == 65535 ? clazz.superClassType() : clazz.interfaceTypeArray()[position]; break; type = method.methodInternal().parameterArray()[target.asMethodParameterType().position()]; break; TypeParameterBoundTypeTarget boundTarget = target.asTypeParameterBound(); type = getTypeParameters(enclosingTarget)[boundTarget.position()] .asTypeVariable().boundArray()[boundTarget.boundPosition()]; break;
@Override public String getElementName() { return field.name(); }
static AnnotationTarget getTarget(ServiceRegistry serviceRegistry, ClassInfo classInfo, String name, TargetType type) { Class clazz = serviceRegistry.getService( ClassLoaderService.class ).classForName( classInfo.toString() ); switch ( type ) { case FIELD: return FieldInfo.create( classInfo, name, getType( field.getType() ), (short) ( field.getModifiers() ) );
@Override public IJavaType type() { return Wrappers.wrap(field.type()); }
@Override public int getFlags() { return field.flags(); }