CDIFeatures71

CDI Enhancements Functional Specification

Author: Denis Anisimov
Version: draft 1.0

Umbrella issue: 198916

CDI Errors This feature is about unquestionable errors in CDI based code which will be detected at the runtime. Such errors should be underlined and has an error mark on the editor left bar. Below is the full list of such errors.

  • Classes which could be injected but are not managed beans or superclass for managed bean ( ONLY explicitly annotated with user defined qualifier because ANY java type is a potential injectable via implicit @Default qualifier ):
    • Not a non-static inner class.
  • Unproxyable declared types : classes with normal scope which are declared final.
  • Missed annotations for Qualifier definition : @Target, @Retention and their incorrect values. Qualifier should be defined with @Retention(RUNTIME) and @Target({FIELD, PARAMETER}) or @Target({METHOD, FIELD, PARAMETER, TYPE}). The first possibility is available only for event qualifier but it is impossible to check qualifier element definition what it is intended for use. There will be plain Java error in case of usage qualifier with incorrect Targets.
  • Initialization of field which is injection point.
  • Producer method should not have a parameter with @Observes or @Disposes annotation and should be annotated with @Inject.
  • A producer/disposer/observer non-static method of a session bean class should be a business method of the session bean.
  • A producer/disposer method must be a non-abstract method of a managed bean class or session bean class.
  • A producer method return type shouldn't contain a wildcard type parameter ( If the producer method return type is a parameterized type, it must specify an actual type parameter or type variable for each type parameter ).
  • If the producer method return type is a parameterized type with a type variable, it must have scope @Dependent.
  • A producer method return type shouldn't be a type variable.
  • If a producer method is annotated @Specializes, then it must be non-static and directly override another producer method.
  • Interceptors and decorators may not declare producer/disposer/observer methods.
  • Disposer/Observer methods should have only one parameter annotated by @Dispose/@Observes.
  • Disposer/Observer methods should not have annotation @Produce, @Inject or parameter with @Observes/@Dispose annotation.
  • Explicitly restricted bean type ( see below restrict the bean types of a bean ) should have a restricted bean types which are subset of unrestricted bean types.
  • A scope annotation should be defined as @Target({TYPE, METHOD, FIELD}) and @Retention(RUNTIME).
  • A bean class or producer method or field may specify at most one scope type annotation.
  • If there are two different stereotypes declared by the bean that declare different default scopes, then there is no default scope and the bean must explicitly declare a scope.
  • A stereotype should be defined as @Target({TYPE, METHOD, FIELD}),@Target(TYPE), @Target(METHOD), @Target(FIELD) or @Target({METHOD, FIELD}) and @Retention(RUNTIME).
  • A stereotype should not declare a non-empty @Named annotation.
  • A stereotype may declare at most one scope.
  • Stereotypes declared @Target(TYPE) may not be applied to stereotypes declared @Target({TYPE, METHOD, FIELD}), @Target(METHOD), @Target(FIELD) or @Target({METHOD, FIELD}).
  • A managed bean can't be annotated with both @Interceptor and @Decorator stereotypes.
  • A managed bean with a public field shouldn't declares any scope other than @Dependent.
  • A managed bean with a parameterized bean class shouldn't declares any scope other than @Dependent.
  • A stateless session bean must belong to the @Dependent pseudo-scope.
  • A singleton bean must belong to either the @ApplicationScoped scope or to the @Dependent pseudo-scope.
  • The bean class of a session bean should not be annotated @Interceptor or @Decorator.
  • If a session bean has a parameterized bean class, it must have scope @Dependent.
  • If the bean is a session bean, the producer field must be a static field of the bean class.
  • A producer field type shouldn't contain a wildcard type parameter.
  • If the producer field type is a parameterized type with a type variable, it must have scope @Dependent.
  • A producer field type shouldn't be a type variable.
  • A producer field shouldn't have @Inject annotation.
  • Interceptors and decorators may not declare producer fields.
  • A bean class shouldn't have more than one constructor annotated @Inject.
  • A bean constructor shouldn't have a parameter annotated @Disposes or @Observes.
  • Injection field shouldn't be static or final.
  • A generic method of a bean shouldn't be annotated @Inject.
  • An initializer method shouldn't be annotated @Produces, has a parameter annotated @Disposes, or has a parameter annotated @Observes.
  • An initializer method should be a non-abstract, non-static.
  • If an injection point except injection filed has a @Named annotation it should specify a value member. Only injection field can skip value member specifying.
  • If bean specializes another bean with name then original bean shouldn't declare name explicitly using @Named .
  • If bean specializes another bean then it should have all bean types of specialized bean.
  • A bean that declares any scope other than @Dependent shouldn't have an injection point of type InjectionPoint and qualifier @Default.
  • A decorator must have exactly one delegate injection point.
  • The delegate injection point must be an injected field, initializer method parameter or bean constructor method parameter.
  • A bean class that is not a decorator shouldn't have an injection point annotated @Delegate.
  • The delegate type of a decorator must implement or extend every decorated type of decorator (with exactly the same type parameters).
  • If a decorator matches a managed bean, the managed bean class shouldn't be declared final.
  • If a decorator matches a managed bean with a non-static, non-private, final method, the decorator shouldn't also implement that method.
  • Interceptor binding type should be defined as @Target({TYPE, METHOD}) or @Target(TYPE) and @Retention(RUNTIME).
  • Interceptor binding types declared @Target(TYPE) may not be applied to interceptor binding types declared @Target({TYPE, METHOD}).
  • If a stereotype declares interceptor bindings, it must be defined as @Target(TYPE).
  • An interceptor for lifecycle callbacks may only declare interceptor binding types that are defined as @Target(TYPE).
  • If the bean class of a managed bean declares or inherits a class level interceptor binding or a stereotype with interceptor bindings, it must not be declared final, or have any non-static, non-private, final methods.
  • If a non-static, non-private method of a bean class of a managed bean declares a method level interceptor binding, neither the method nor the bean class may be declared final.
  • This is an error if the set of interceptor bindings of a bean or interceptor, including bindings inherited from stereotypes and other interceptor bindings, has two instances of a certain interceptor binding type and the instances have different values of some annotation member.
  • An injection point type shouldn't be a type variable.
  • In case of CDI code usage there should be beans.xml file which enables CDI.

Other features

Restrict the bean types of a bean The bean type could be restricted via explicit annotation @javax.enterprise.inject.Typed. The current model implementation doesn't care about this requirement. Additional filter should be implemented for the WebBeans model. It relates to type and production elements.

Implement programmatic lookup Add possibility to recognize Instance<?> type of injection point and provide the same UI actions for it as for non-programmatic case.

Warnings

  • Injection point should have exactly one element eligible for injection . This is WARNING not an error for various reasons. F.e. injection could be done via production element. But production element could be defined in the disabled bean. As result disabled production element is not eligible for injection. The latter case is too complicated for static analysis. Exact answer to the question about availability for injection of production element could be detected at runtime only.
  • Classes which could be injected but are not managed beans ( ONLY explicitly annotated with user defined qualifier because ANY java type is a potential injectable via implicit @Default qualifier ). This is warning because such classes could be used as superclasses for a managed bean but it is not required to be managed bean themselves ( f.e. interface is not a managed bean but it can declare qualifiers ).:
    • Classes which don't have a non-private constructor with no parameters and not annotated with @Inject
    • Abstract class ( if it is not @Decorator ).
    • Implements javax.enterprise.inject.spi.Extension.
  • Classes with normal scope which have final methods ( it doesn't apply to classes without any CDI annotation and without explicitly defined scopes, f.e. default @Dependent scope is pseudo-scope not normal. ) This is warning because only "bean type methods" should not be final ( i.e. methods which declared by bean type of injection point ).
  • Interceptor bindings for lifecycle callback methods includes ONLY the interceptor bindings declared or inherited by the bean at the class level. As result there should be a WARNING if lifecycle callback method declares interceptor bindings on the method level ( with @Target({TYPE, METHOD}) ).


Distinguish delegate injection points Injection point with @Delegate annotation defined inside Decorator has special assignability rules. Currently model implementation doesn't distinguish delegate and plain injection points.

Interceptor resolution Provide UI action that allows to find all Interceptors for method with interceptor bindings.

Decorator resolution Provide UI action that allows to find decorator for class. This is similar to Interceptor resolution and inverse operation for find decorated bean type by @Delegate injection point.

Generate interceptor for interceptor binding http://netbeans.org/bugzilla/show_bug.cgi?id=195412

Provide marks for injection points with GoTo/Inspect action. There is a request to show marks like "override" marks in editor. Clicking on the mark could works as GoTo/Inspect action for CDI context.

Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo