private MethodIdentifier getMethodIdentifier(final AnnotationTarget target) { final MethodInfo methodInfo = MethodInfo.class.cast(target); final String[] args = new String[methodInfo.args().length]; for (int i = 0; i < methodInfo.args().length; i++) { args[i] = methodInfo.args()[i].name().toString(); } return MethodIdentifier.getIdentifier(methodInfo.returnType().name().toString(), methodInfo.name(), args); }
@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); if (annotationTarget instanceof ClassInfo) { final ClassInfo classInfo = (ClassInfo) annotationTarget; final AnnotationInstance[] values = outerAnnotation.value("value").asNestedArray(); for (AnnotationInstance annotation : values) { 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; EEModuleClassDescription classDescription = eeModuleDescription.addOrGetLocalClassDescription(classInfo.name().toString());
protected void processFieldResource(final DeploymentPhaseContext phaseContext, final FieldInfo fieldInfo, final String name, final String type, final EEModuleClassDescription classDescription, final AnnotationInstance annotation, final EEModuleDescription eeModuleDescription, final Module module, final EEApplicationClasses applicationClasses, final PropertyReplacer replacer) throws DeploymentUnitProcessingException { final String fieldName = fieldInfo.name(); final String injectionType = isEmpty(type) || type.equals(Object.class.getName()) ? fieldInfo.type().name().toString() : type; final String localContextName = isEmpty(name) ? fieldInfo.declaringClass().name().toString() + "/" + fieldName : name; final InjectionTarget targetDescription = new FieldInjectionTarget(fieldInfo.declaringClass().name().toString(), fieldName, fieldInfo.type().name().toString()); process(phaseContext, classDescription, annotation, injectionType, localContextName, targetDescription, eeModuleDescription, module, applicationClasses, replacer); }
private void processMethod(final DeploymentUnit deploymentUnit, final AnnotationInstance annotation, final MethodInfo methodInfo, final EEModuleClassDescription eeModuleClassDescription) throws DeploymentUnitProcessingException { final String methodName = methodInfo.name(); if (!methodName.startsWith("set") || methodInfo.args().length != 1) { eeModuleClassDescription.setInvalid(JpaLogger.ROOT_LOGGER.setterMethodOnlyAnnotation(annotation.name().toString(), methodInfo)); return; } final String contextNameSuffix = methodName.substring(3, 4).toLowerCase(Locale.ENGLISH) + methodName.substring(4); final AnnotationValue declaredNameValue = annotation.value("name"); final String declaredName = declaredNameValue != null ? declaredNameValue.asString() : null; final String localContextName; if (declaredName == null || declaredName.isEmpty()) { localContextName = methodInfo.declaringClass().name().toString() + "/" + contextNameSuffix; } else { localContextName = declaredName; } final String injectionType = methodInfo.args()[0].name().toString(); final InjectionSource bindingSource = this.getBindingSource(deploymentUnit, annotation, injectionType, eeModuleClassDescription); if (bindingSource != null) { final BindingConfiguration bindingConfiguration = new BindingConfiguration(localContextName, bindingSource); eeModuleClassDescription.getBindingConfigurations().add(bindingConfiguration); // setup the injection configuration final InjectionTarget injectionTarget = new MethodInjectionTarget(methodInfo.declaringClass().name().toString(), methodName, methodInfo.args()[0].name().toString()); // source is always local ENC jndi name final InjectionSource injectionSource = new LookupInjectionSource(localContextName); final ResourceInjectionConfiguration injectionConfiguration = new ResourceInjectionConfiguration(injectionTarget, injectionSource); eeModuleClassDescription.addResourceInjection(injectionConfiguration); } }
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()); intern(param.method().name()); for (Type type : param.method().args()) addClassName(type.name()); addClassName(param.method().returnType().name()); for (AnnotationValue value : instance.values()) buildAValueEntries(index, value);
private void processField(final DeploymentUnit deploymentUnit, final AnnotationInstance annotation, final FieldInfo fieldInfo, final EEModuleClassDescription eeModuleClassDescription) throws DeploymentUnitProcessingException { final String fieldName = fieldInfo.name(); final AnnotationValue declaredNameValue = annotation.value("name"); final String declaredName = declaredNameValue != null ? declaredNameValue.asString() : null; final String localContextName; if (declaredName == null || declaredName.isEmpty()) { localContextName = fieldInfo.declaringClass().name().toString() + "/" + fieldName; } else { localContextName = declaredName; } //final AnnotationValue declaredTypeValue = annotation.value("type"); final DotName declaredTypeDotName = fieldInfo.type().name(); final DotName injectionTypeDotName = declaredTypeDotName == null || declaredTypeDotName.toString().equals(Object.class.getName()) ? fieldInfo.type().name() : declaredTypeDotName; final String injectionType = injectionTypeDotName.toString(); final InjectionSource bindingSource = this.getBindingSource(deploymentUnit, annotation, injectionType, eeModuleClassDescription); if (bindingSource != null) { final BindingConfiguration bindingConfiguration = new BindingConfiguration(localContextName, bindingSource); eeModuleClassDescription.getBindingConfigurations().add(bindingConfiguration); // setup the injection target final InjectionTarget injectionTarget = new FieldInjectionTarget(fieldInfo.declaringClass().name().toString(), fieldName, fieldInfo.type().name().toString()); // source is always local ENC jndi final InjectionSource injectionSource = new LookupInjectionSource(localContextName); final ResourceInjectionConfiguration injectionConfiguration = new ResourceInjectionConfiguration(injectionTarget, injectionSource); eeModuleClassDescription.addResourceInjection(injectionConfiguration); } }
private String getMessageListenerInterface(final CompositeIndex compositeIndex, final AnnotationInstance messageBeanAnnotation) throws DeploymentUnitProcessingException { final AnnotationValue value = messageBeanAnnotation.value("messageListenerInterface"); if (value != null) return value.asClass().name().toString(); final ClassInfo beanClass = (ClassInfo) messageBeanAnnotation.target(); final Set<DotName> interfaces = new HashSet<DotName>(getPotentialViewInterfaces(beanClass)); // check super class(es) of the bean DotName superClassDotName = beanClass.superName(); while (interfaces.isEmpty() && superClassDotName != null && !superClassDotName.toString().equals(Object.class.getName())) { final ClassInfo superClass = compositeIndex.getClassByName(superClassDotName); if (superClass == null) { break; } interfaces.addAll(getPotentialViewInterfaces(superClass)); // move to next super class superClassDotName = superClass.superName(); } if (interfaces.size() != 1) throw EjbLogger.ROOT_LOGGER.mdbDoesNotImplementNorSpecifyMessageListener(beanClass); return interfaces.iterator().next().toString(); }
.getAnnotations( PseudoJpaDotNames.DEFAULT_ENTITY_LISTENERS ); for ( AnnotationInstance annotation : defaultEntityListenerAnnotations ) { for ( Type callbackClass : annotation.value().asClassArray() ) { String callbackClassName = callbackClass.name().toString(); try { processDefaultJpaCallbacks( callbackClassName, callbackClassList ); List<AnnotationInstance> annotationList = getClassInfo().annotations().get( JPADotNames.ENTITY_LISTENERS ); if ( annotationList != null ) { for ( AnnotationInstance annotation : annotationList ) { for ( Type callbackClass : annotation.value().asClassArray() ) { String callbackClassName = callbackClass.name().toString(); try { processJpaCallbacks( callbackClassName, true, callbackClassList ); error.getMessage() + "entity/mapped superclass " + getClassInfo().name().toString() );
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; } }
@Override protected String[] fromAnnotation(final AnnotationInstance annotationInstance, final PropertyReplacer propertyReplacer) { final Type[] classes = annotationInstance.value().asClassArray(); final String[] ret = new String[classes.length]; for(int i = 0; i < classes.length; ++i) { ret[i] = classes[i].name().toString(); } return ret; } }
Map<Class<?>, String> callbacksByClass, boolean isListener) { if ( methodInfo.returnType().kind() != Kind.VOID ) { throw new PersistenceException( "Callback method " + methodInfo.name() + " must have a void return type in " ); if ( Modifier.isStatic( methodInfo.flags() ) || Modifier.isFinal( methodInfo.flags() ) ) { throw new PersistenceException( "Callback method " + methodInfo.name() + " must not be static or final in " ); throw new PersistenceException( "Callback method " + methodInfo.name() + " must have exactly one argument in " ); String argTypeName = argTypes[0].name().toString(); if ( !argTypeName.equals( Object.class.getName() ) && !argTypeName.equals( getName() ) ) { throw new PersistenceException(
/** * @param i * @return * @throws SerianalyzerException */ static String makeSignature ( MethodInfo i, boolean fix ) throws SerianalyzerException { StringBuilder sb = new StringBuilder(); sb.append('('); ClassInfo declaringImpl = i.declaringClass(); if ( fix && "<init>".equals(i.name()) && declaringImpl.nestingType() == NestingType.INNER ) { //$NON-NLS-1$ // there seems to be some sort of bug, missing the the outer instance parameter in the constructor if ( !Modifier.isStatic(declaringImpl.flags()) ) { org.jboss.jandex.Type enclosingClass = org.jboss.jandex.Type.create(declaringImpl.enclosingClass(), Kind.CLASS); org.jboss.jandex.Type firstArg = i.parameters().size() > 0 ? i.parameters().get(0) : null; if ( firstArg instanceof TypeVariable ) { firstArg = firstArg.asTypeVariable().bounds().get(0); } if ( firstArg == null || !firstArg.equals(enclosingClass) ) { sb.append(toString(enclosingClass)); } } } for ( org.jboss.jandex.Type p : i.parameters() ) { sb.append(toString(p)); } sb.append(')'); sb.append(toString(i.returnType())); return sb.toString(); }
private Index readClasses(PackedDataInputStream stream, int annotationsSize, int implementorsSize, int subclassesSize) throws IOException { int classesSize = stream.readPackedU32(); HashMap<DotName, ClassInfo> classes = new HashMap<DotName, ClassInfo>(classesSize); HashMap<DotName, List<ClassInfo>> subclasses = new HashMap<DotName, List<ClassInfo>>(subclassesSize); HashMap<DotName, List<ClassInfo>> implementors = new HashMap<DotName, List<ClassInfo>>(implementorsSize); HashMap<DotName, List<AnnotationInstance>> masterAnnotations = new HashMap<DotName, List<AnnotationInstance>>(annotationsSize); for (int i = 0; i < classesSize; i++) { ClassInfo clazz = readClassEntry(stream, masterAnnotations); addClassToMap(subclasses, clazz.superName(), clazz); for (Type interfaceType : clazz.interfaceTypeArray()) { addClassToMap(implementors, interfaceType.name(), clazz); } classes.put(clazz.name(), clazz); } return new Index(masterAnnotations, subclasses, implementors, classes); }
private void buildAValueEntries(Index index, AnnotationValue value) { intern(value.name()); if (value instanceof AnnotationValue.StringValue) { intern(value.asString()); } else if (value instanceof AnnotationValue.ClassValue) { addClassName(value.asClass().name()); } else if (value instanceof AnnotationValue.EnumValue) { addClassName(value.asEnumType()); intern(value.asEnum()); } else if (value instanceof AnnotationValue.ArrayValue) { for (AnnotationValue entry : value.asArray()) buildAValueEntries(index, entry); } else if (value instanceof AnnotationValue.NestedAnnotation) { AnnotationInstance instance = value.asNested(); Collection<AnnotationValue> values = instance.values(); addClassName(instance.name()); for (AnnotationValue entry : values) { buildAValueEntries(index, entry); } } }
private static <T> T explicitAnnotationParameter(AnnotationValue annotationValue, Class<T> type) { Object returnValue = annotationValue.value(); // if the jandex return type is Type we actually try to retrieve a class parameter // for our purposes we just return the fqcn of the class if ( returnValue instanceof Type ) { returnValue = ( (Type) returnValue ).name().toString(); } // arrays we have to handle explicitly if ( type.isArray() ) { AnnotationValue[] values = (AnnotationValue[]) returnValue; Class<?> componentType = type.getComponentType(); Object[] arr = (Object[]) Array.newInstance( componentType, values.length ); for ( int i = 0; i < values.length; i++ ) { arr[i] = componentType.cast( values[i].value() ); } returnValue = arr; } return type.cast( returnValue ); } }
private void processClassInfo(DataInputStream data) throws IOException { short flags = (short) data.readUnsignedShort(); DotName thisName = decodeClassEntry(data.readUnsignedShort()); int superIndex = data.readUnsignedShort(); DotName superName = (superIndex != 0) ? decodeClassEntry(superIndex) : null; int numInterfaces = data.readUnsignedShort(); List<Type> interfaces = new ArrayList<Type>(numInterfaces); for (int i = 0; i < numInterfaces; i++) { interfaces.add(intern(new ClassType(decodeClassEntry(data.readUnsignedShort())))); } Type[] interfaceTypes = intern(interfaces.toArray(new Type[interfaces.size()])); Type superClassType = superName == null ? null : intern(new ClassType(superName)); this.classAnnotations = new HashMap<DotName, List<AnnotationInstance>>(); this.currentClass = new ClassInfo(thisName, superClassType, flags, interfaceTypes, classAnnotations); if (superName != null) addSubclass(superName, currentClass); for (int i = 0; i < numInterfaces; i++) { addImplementor(interfaces.get(i).name(), currentClass); } classes.put(currentClass.name(), currentClass); }
private static Type getType(Class clazz) { return Type.create( DotName.createSimple( clazz.getName() ), getTypeKind( clazz ) ); }