Refine search
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);
/** * Returns true if the passed <code>mdbClass</code> meets the requirements set by the EJB3 spec about bean implementation * classes. The passed <code>mdbClass</code> must not be an interface and must be public and not final and not abstract. If * it passes these requirements then this method returns true. Else it returns false. * * @param mdbClass The MDB class * @return * @throws DeploymentUnitProcessingException */ public static Collection<MdbValidityStatus> assertEjbClassValidity(final ClassInfo mdbClass) throws DeploymentUnitProcessingException { Collection<MdbValidityStatus> mdbComplianceIssueList = new ArrayList<>(MdbValidityStatus.values().length); final String className = mdbClass.name().toString(); verifyModifiers(className, mdbClass.flags(), mdbComplianceIssueList); for (MethodInfo method : mdbClass.methods()) { if ("onMessage".equals(method.name())) { verifyOnMessageMethod(className, method.flags(), mdbComplianceIssueList); } if ("finalize".equals(method.name())) { EjbLogger.DEPLOYMENT_LOGGER.mdbCantHaveFinalizeMethod(className); mdbComplianceIssueList.add(MdbValidityStatus.MDB_SHOULD_NOT_HAVE_FINALIZE_METHOD); } } return mdbComplianceIssueList; }
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()));
private boolean containsAnnotation(ClassInfo classInfo, DotName requiredAnnotationName, Class<? extends Annotation> requiredAnnotation) { if (classInfo.annotations().containsKey(requiredAnnotationName)) { return true; for (DotName annotation : classInfo.annotations().keySet()) { if (annotationClassAnnotationsCache.getValue(annotation).contains(requiredAnnotationName.toString())) { return true; final DotName superName = classInfo.superName(); if (superName != null && !OBJECT_NAME.equals(superName)) { final ClassInfo superClassInfo = index.getClassByName(superName); if (superClassInfo == null) { return Reflections.containsAnnotation(loadClass(superName.toString()), requiredAnnotation); if (method.hasAnnotation(requiredAnnotationName)) { return true; for (AnnotationInstance annotation : method.annotations()) { if (annotationClassAnnotationsCache.getValue(annotation.name()).contains(requiredAnnotationName.toString())) { return true;
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);
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); } }
private boolean hasInjectConstructor() { List<AnnotationInstance> annotationInstances = classInfo.annotations().get(DOT_NAME_INJECT); if (annotationInstances != null) { for (AnnotationInstance instance : annotationInstances) { AnnotationTarget target = instance.target(); if (target instanceof MethodInfo) { MethodInfo methodInfo = (MethodInfo) target; if (methodInfo.name().equals(CONSTRUCTOR_METHOD_NAME)) { return true; } } } } return false; }
private void createDefaultCallback(Class callbackTypeClass, DotName callbackTypeName, String callbackClassName, Map<Class<?>, String> callbacksByClass) { for ( AnnotationInstance callback : getLocalBindingContext().getIndex().getAnnotations( callbackTypeName ) ) { MethodInfo methodInfo = (MethodInfo) callback.target(); validateMethod( methodInfo, callbackTypeClass, callbacksByClass, true ); if ( methodInfo.declaringClass().name().toString().equals( callbackClassName ) ) { if ( methodInfo.args().length != 1 ) { throw new PersistenceException( String.format( "Callback method %s must have exactly one argument defined as either Object or %s in ", methodInfo.name(), getEntityName() ) ); } callbacksByClass.put( callbackTypeClass, methodInfo.name() ); } } }
protected ServerConfiguration fromAnnotation(Module apiModule, AnnotationInstance anno) throws ClassNotFoundException, ModuleLoadException { AnnotationValue marshalValue = anno.value("marshal"); AnnotationValue ignorableValue = anno.value("ignorable"); AnnotationValue extensionValue = anno.value("extension"); AnnotationValue parserFactoryClassNameValue = anno.value("parserFactoryClassName"); AnnotationValue extensionClassNameValue = anno.value("extensionClassName"); Class<? extends Fraction> fractionClass = (Class<? extends Fraction>) mainModule.getClassLoader().loadClass(anno.target().asClass().name().toString()); List<MethodInfo> fractionMethods = anno.target().asClass().methods(); DotName defaultAnno = DotName.createSimple(Default.class.getName()); if (each.hasAnnotation(defaultAnno)) { if (!each.parameters().isEmpty()) { throw new RuntimeException("Method marked @Default must require zero parameters"); if (!Modifier.isStatic(each.flags())) { throw new RuntimeException("Method marked @Default must be static"); serverConfig.defaultFraction(each.name());
private static List<Method> __invoke(Class<?> clazz, Index index, Comparator<Method> comparator) throws NoSuchMethodException { ArrayList methods = new ArrayList(); ClassInfo clazzInfo = index.getClassByName(DotName.createSimple(clazz.getName())); for (MethodInfo method : clazzInfo.methods()) { if (method.hasAnnotation(IndexFactory.SUBRESOURCE_META)) { methods.add(clazz.getMethod(method.name())); } } if (clazzInfo.superName() != null && clazz.getSuperclass() != java.lang.Object.class) { index = IndexFactory.createIndex(clazz.getSuperclass()); return __invoke(clazz.getSuperclass(), index, comparator); } Collections.sort(methods, comparator); return methods; }
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]); writeType(stream, method.returnType()); stream.writeShort(method.flags()); } else if (target instanceof MethodParameterInfo) { MethodParameterInfo param = (MethodParameterInfo) target; MethodInfo method = param.method(); stream.writeByte(METHOD_PARAMATER_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]); writeType(stream, method.returnType());
private void processAroundInvoke(final AnnotationTarget target, final EEModuleDescription eeModuleDescription) { if (!(target instanceof MethodInfo)) { throw EjbLogger.ROOT_LOGGER.annotationApplicableOnlyForMethods(AROUND_TIMEOUT_ANNOTATION_NAME.toString()); } final MethodInfo methodInfo = MethodInfo.class.cast(target); final ClassInfo classInfo = methodInfo.declaringClass(); final EEModuleClassDescription classDescription = eeModuleDescription.addOrGetLocalClassDescription(classInfo.name().toString()); validateArgumentType(classInfo, methodInfo); final InterceptorClassDescription.Builder builder = InterceptorClassDescription.builder(classDescription.getInterceptorClassDescription()); builder.setAroundTimeout(MethodIdentifier.getIdentifier(Object.class, methodInfo.name(), InvocationContext.class)); classDescription.setInterceptorClassDescription(builder.build()); }
/** * 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() ); } } }
Collection<AnnotationInstance> appPathAnnotations = index.getAnnotations(APP_PATH); for (AnnotationInstance annotation : appPathAnnotations) { if (annotation.target().kind() == AnnotationTarget.Kind.CLASS) { appPath = Optional.of(annotation.value().asString()); if (annotation.target().kind() == AnnotationTarget.Kind.CLASS) { ClassInfo classInfo = annotation.target().asClass(); for (MethodInfo methodInfo : classInfo.methods()) { if (methodInfo.hasAnnotation(HEALTH) || methodInfo.hasAnnotation(MP_HEALTH)) { StringBuilder sb = new StringBuilder(); boolean isSecure = false; for (AnnotationInstance classAnnotation : classInfo.classAnnotations()) { if (classAnnotation.name().equals(PATH)) { String methodPathValue = classAnnotation.value().asString(); if (!methodPathValue.equals("/")) { if (methodInfo.hasAnnotation(PATH)) { safeAppend(sb, methodInfo.annotation(PATH).value().asString()); AnnotationInstance healthAnnotation = methodInfo.annotation(HEALTH); if (null == healthAnnotation) { healthAnnotation = methodInfo.annotation(MP_HEALTH);
clazzes = this.input.getIndex().getAllKnownImplementors(DotName.createSimple(Serializable.class.getName())); for ( ClassInfo cl : this.input.getIndex().getKnownClasses() ) { boolean foundDefaultConstructor = false; for ( MethodInfo methodInfo : cl.methods() ) { if ( !"<init>".equals(methodInfo.name()) ) { //$NON-NLS-1$ continue; if ( ( methodInfo.flags() & Modifier.PUBLIC ) == 0 ) { continue; if ( methodInfo.parameters().size() > 0 ) { continue; if ( this.input.getConfig().isWhitelistedClass(ci.name().toString()) ) { continue;
clazz = index.getClassByName(DotName.createSimple(currentType.getCanonicalName())); for (MethodInfo method : clazz.methods()) { if (method.hasAnnotation(IndexFactory.BINDING_META)) { Method target = entity.getClass().getMethod(method.name()); Class<?> propertyType = target.getReturnType(); Object propertyValue = target.invoke(entity); AnnotationInstance ann = method.annotation(DotName.createSimple(ModelNodeBinding.class.getName())); org.jboss.jandex.AnnotationValue annValue = ann.value("detypedName"); String detypedName = annValue.asString(); if (!expr.isEmpty()) { if(expr.keySet().contains(method.name())) { modelNode.get(detypedName).setExpression(expr.get(method.name())); continue; // expressions have precedence over values clazz = index.getClassByName(DotName.createSimple(currentType.getCanonicalName()));
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 " ); Type[] argTypes = methodInfo.args(); if ( isListener ) { if ( argTypes.length != 1 ) { 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( "The argument for callback method " + methodInfo.name() + " must be defined as either Object or " + getEntityName() + " in " ); throw new PersistenceException( "Callback method " + methodInfo.name() + " must have no arguments in " );
/** * @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; }
/** * @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(); }